This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / scsi / advansys.c
1 #define ASC_VERSION "3.3GJ"    /* 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  * There is an AdvanSys Linux WWW page at:
19  *  http://www.connectcom.net/downloads/software/os/linux.html
20  *  http://www.advansys.com/linux.html
21  *
22  * The latest released version of the AdvanSys driver is available at:
23  *  ftp://ftp.advansys.com/pub/linux/linux.tgz
24  *  ftp://ftp.connectcom.net/pub/linux/linux.tgz
25  *
26  * Please send questions, comments, bug reports to:
27  *  support@connectcom.net
28  */
29
30 /*
31
32   Documentation for the AdvanSys Driver
33
34   A. Linux Kernels Supported by this Driver
35   B. Adapters Supported by this Driver
36   C. Linux source files modified by AdvanSys Driver
37   D. Source Comments
38   E. Driver Compile Time Options and Debugging
39   F. Driver LILO Option
40   G. Tests to run before releasing new driver
41   H. Release History
42   I. Known Problems/Fix List
43   J. Credits (Chronological Order)
44   K. ConnectCom (AdvanSys) Contact Information
45
46   A. Linux Kernels Supported by this Driver
47
48      This driver has been tested in the following Linux kernels: v2.2.18
49      v2.4.0. The driver is supported on v2.2 and v2.4 kernels and on x86,
50      alpha, and PowerPC platforms.
51
52   B. Adapters Supported by this Driver
53
54      AdvanSys (Advanced System Products, Inc.) manufactures the following
55      RISC-based, Bus-Mastering, Fast (10 Mhz) and Ultra (20 Mhz) Narrow
56      (8-bit transfer) SCSI Host Adapters for the ISA, EISA, VL, and PCI
57      buses and RISC-based, Bus-Mastering, Ultra (20 Mhz) Wide (16-bit
58      transfer) SCSI Host Adapters for the PCI bus.
59
60      The CDB counts below indicate the number of SCSI CDB (Command
61      Descriptor Block) requests that can be stored in the RISC chip
62      cache and board LRAM. A CDB is a single SCSI command. The driver
63      detect routine will display the number of CDBs available for each
64      adapter detected. The number of CDBs used by the driver can be
65      lowered in the BIOS by changing the 'Host Queue Size' adapter setting.
66
67      Laptop Products:
68         ABP-480 - Bus-Master CardBus (16 CDB) (2.4 kernel and greater)
69
70      Connectivity Products:
71         ABP510/5150 - Bus-Master ISA (240 CDB)
72         ABP5140 - Bus-Master ISA PnP (16 CDB)
73         ABP5142 - Bus-Master ISA PnP with floppy (16 CDB)
74         ABP902/3902 - Bus-Master PCI (16 CDB)
75         ABP3905 - Bus-Master PCI (16 CDB)
76         ABP915 - Bus-Master PCI (16 CDB)
77         ABP920 - Bus-Master PCI (16 CDB)
78         ABP3922 - Bus-Master PCI (16 CDB)
79         ABP3925 - Bus-Master PCI (16 CDB)
80         ABP930 - Bus-Master PCI (16 CDB)
81         ABP930U - Bus-Master PCI Ultra (16 CDB)
82         ABP930UA - Bus-Master PCI Ultra (16 CDB)
83         ABP960 - Bus-Master PCI MAC/PC (16 CDB)
84         ABP960U - Bus-Master PCI MAC/PC Ultra (16 CDB)
85
86      Single Channel Products:
87         ABP542 - Bus-Master ISA with floppy (240 CDB)
88         ABP742 - Bus-Master EISA (240 CDB)
89         ABP842 - Bus-Master VL (240 CDB)
90         ABP940 - Bus-Master PCI (240 CDB)
91         ABP940U - Bus-Master PCI Ultra (240 CDB)
92         ABP940UA/3940UA - Bus-Master PCI Ultra (240 CDB)
93         ABP970 - Bus-Master PCI MAC/PC (240 CDB)
94         ABP970U - Bus-Master PCI MAC/PC Ultra (240 CDB)
95         ABP3960UA - Bus-Master PCI MAC/PC Ultra (240 CDB)
96         ABP940UW/3940UW - Bus-Master PCI Ultra-Wide (253 CDB)
97         ABP970UW - Bus-Master PCI MAC/PC Ultra-Wide (253 CDB)
98         ABP3940U2W - Bus-Master PCI LVD/Ultra2-Wide (253 CDB)
99
100      Multi-Channel Products:
101         ABP752 - Dual Channel Bus-Master EISA (240 CDB Per Channel)
102         ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
103         ABP950 - Dual Channel Bus-Master PCI (240 CDB Per Channel)
104         ABP950UW - Dual Channel Bus-Master PCI Ultra-Wide (253 CDB Per Channel)
105         ABP980 - Four Channel Bus-Master PCI (240 CDB Per Channel)
106         ABP980U - Four Channel Bus-Master PCI Ultra (240 CDB Per Channel)
107         ABP980UA/3980UA - Four Channel Bus-Master PCI Ultra (16 CDB Per Chan.)
108         ABP3950U2W - Bus-Master PCI LVD/Ultra2-Wide and Ultra-Wide (253 CDB)
109         ABP3950U3W - Bus-Master PCI Dual LVD2/Ultra3-Wide (253 CDB)
110
111   C. Linux source files modified by AdvanSys Driver
112
113      This section for historical purposes documents the changes
114      originally made to the Linux kernel source to add the advansys
115      driver. As Linux has changed some of these files have also
116      been modified.
117
118      1. linux/arch/i386/config.in:
119
120           bool 'AdvanSys SCSI support' CONFIG_SCSI_ADVANSYS y
121
122      2. linux/drivers/scsi/hosts.c:
123
124           #ifdef CONFIG_SCSI_ADVANSYS
125           #include "advansys.h"
126           #endif
127
128         and after "static Scsi_Host_Template builtin_scsi_hosts[] =":
129
130           #ifdef CONFIG_SCSI_ADVANSYS
131           ADVANSYS,
132           #endif
133
134      3. linux/drivers/scsi/Makefile:
135
136           ifdef CONFIG_SCSI_ADVANSYS
137           SCSI_SRCS := $(SCSI_SRCS) advansys.c
138           SCSI_OBJS := $(SCSI_OBJS) advansys.o
139           else
140           SCSI_MODULE_OBJS := $(SCSI_MODULE_OBJS) advansys.o
141           endif
142
143      4. linux/init/main.c:
144
145           extern void advansys_setup(char *str, int *ints);
146
147         and add the following lines to the bootsetups[] array.
148
149           #ifdef CONFIG_SCSI_ADVANSYS
150              { "advansys=", advansys_setup },
151           #endif
152
153   D. Source Comments
154
155      1. Use tab stops set to 4 for the source files. For vi use 'se tabstops=4'.
156
157      2. This driver should be maintained in multiple files. But to make
158         it easier to include with Linux and to follow Linux conventions,
159         the whole driver is maintained in the source files advansys.h and
160         advansys.c. In this file logical sections of the driver begin with
161         a comment that contains '---'. The following are the logical sections
162         of the driver below.
163
164            --- Linux Version
165            --- Linux Include File
166            --- Driver Options
167            --- Debugging Header
168            --- Asc Library Constants and Macros
169            --- Adv Library Constants and Macros
170            --- Driver Constants and Macros
171            --- Driver Structures
172            --- Driver Data
173            --- Driver Function Prototypes
174            --- Linux 'Scsi_Host_Template' and advansys_setup() Functions
175            --- Loadable Driver Support
176            --- Miscellaneous Driver Functions
177            --- Functions Required by the Asc Library
178            --- Functions Required by the Adv Library
179            --- Tracing and Debugging Functions
180            --- Asc Library Functions
181            --- Adv Library Functions
182
183      3. The string 'XXX' is used to flag code that needs to be re-written
184         or that contains a problem that needs to be addressed.
185
186      4. I have stripped comments from and reformatted the source for the
187         Asc Library and Adv Library to reduce the size of this file. This
188         source can be found under the following headings. The Asc Library
189         is used to support Narrow Boards. The Adv Library is used to
190         support Wide Boards.
191
192            --- Asc Library Constants and Macros
193            --- Adv Library Constants and Macros
194            --- Asc Library Functions
195            --- Adv Library Functions
196
197   E. Driver Compile Time Options and Debugging
198
199      In this source file the following constants can be defined. They are
200      defined in the source below. Both of these options are enabled by
201      default.
202
203      1. ADVANSYS_ASSERT - Enable driver assertions (Def: Enabled)
204
205         Enabling this option adds assertion logic statements to the
206         driver. If an assertion fails a message will be displayed to
207         the console, but the system will continue to operate. Any
208         assertions encountered should be reported to the person
209         responsible for the driver. Assertion statements may proactively
210         detect problems with the driver and facilitate fixing these
211         problems. Enabling assertions will add a small overhead to the
212         execution of the driver.
213
214      2. ADVANSYS_DEBUG - Enable driver debugging (Def: Disabled)
215
216         Enabling this option adds tracing functions to the driver and
217         the ability to set a driver tracing level at boot time. This
218         option will also export symbols not required outside the driver to
219         the kernel name space. This option is very useful for debugging
220         the driver, but it will add to the size of the driver execution
221         image and add overhead to the execution of the driver.
222
223         The amount of debugging output can be controlled with the global
224         variable 'asc_dbglvl'. The higher the number the more output. By
225         default the debug level is 0.
226
227         If the driver is loaded at boot time and the LILO Driver Option
228         is included in the system, the debug level can be changed by
229         specifying a 5th (ASC_NUM_IOPORT_PROBE + 1) I/O Port. The
230         first three hex digits of the pseudo I/O Port must be set to
231         'deb' and the fourth hex digit specifies the debug level: 0 - F.
232         The following command line will look for an adapter at 0x330
233         and set the debug level to 2.
234
235            linux advansys=0x330,0,0,0,0xdeb2
236
237         If the driver is built as a loadable module this variable can be
238         defined when the driver is loaded. The following insmod command
239         will set the debug level to one.
240
241            insmod advansys.o asc_dbglvl=1
242
243         Debugging Message Levels:
244            0: Errors Only
245            1: High-Level Tracing
246            2-N: Verbose Tracing
247
248         To enable debug output to console, please make sure that:
249
250         a. System and kernel logging is enabled (syslogd, klogd running).
251         b. Kernel messages are routed to console output. Check
252            /etc/syslog.conf for an entry similar to this:
253
254                 kern.*                  /dev/console
255
256         c. klogd is started with the appropriate -c parameter
257            (e.g. klogd -c 8)
258
259         This will cause printk() messages to be be displayed on the
260         current console. Refer to the klogd(8) and syslogd(8) man pages
261         for details.
262
263         Alternatively you can enable printk() to console with this
264         program. However, this is not the 'official' way to do this.
265         Debug output is logged in /var/log/messages.
266
267           main()
268           {
269                   syscall(103, 7, 0, 0);
270           }
271
272         Increasing LOG_BUF_LEN in kernel/printk.c to something like
273         40960 allows more debug messages to be buffered in the kernel
274         and written to the console or log file.
275
276      3. ADVANSYS_STATS - Enable statistics (Def: Enabled >= v1.3.0)
277
278         Enabling this option adds statistics collection and display
279         through /proc to the driver. The information is useful for
280         monitoring driver and device performance. It will add to the
281         size of the driver execution image and add minor overhead to
282         the execution of the driver.
283
284         Statistics are maintained on a per adapter basis. Driver entry
285         point call counts and transfer size counts are maintained.
286         Statistics are only available for kernels greater than or equal
287         to v1.3.0 with the CONFIG_PROC_FS (/proc) file system configured.
288
289         AdvanSys SCSI adapter files have the following path name format:
290
291            /proc/scsi/advansys/[0-(ASC_NUM_BOARD_SUPPORTED-1)]
292
293         This information can be displayed with cat. For example:
294
295            cat /proc/scsi/advansys/0
296
297         When ADVANSYS_STATS is not defined the AdvanSys /proc files only
298         contain adapter and device configuration information.
299
300   F. Driver LILO Option
301
302      If init/main.c is modified as described in the 'Directions for Adding
303      the AdvanSys Driver to Linux' section (B.4.) above, the driver will
304      recognize the 'advansys' LILO command line and /etc/lilo.conf option.
305      This option can be used to either disable I/O port scanning or to limit
306      scanning to 1 - 4 I/O ports. Regardless of the option setting EISA and
307      PCI boards will still be searched for and detected. This option only
308      affects searching for ISA and VL boards.
309
310      Examples:
311        1. Eliminate I/O port scanning:
312             boot: linux advansys=
313               or
314             boot: linux advansys=0x0
315        2. Limit I/O port scanning to one I/O port:
316             boot: linux advansys=0x110
317        3. Limit I/O port scanning to four I/O ports:
318             boot: linux advansys=0x110,0x210,0x230,0x330
319
320      For a loadable module the same effect can be achieved by setting
321      the 'asc_iopflag' variable and 'asc_ioport' array when loading
322      the driver, e.g.
323
324            insmod advansys.o asc_iopflag=1 asc_ioport=0x110,0x330
325
326      If ADVANSYS_DEBUG is defined a 5th (ASC_NUM_IOPORT_PROBE + 1)
327      I/O Port may be added to specify the driver debug level. Refer to
328      the 'Driver Compile Time Options and Debugging' section above for
329      more information.
330
331   G. Tests to run before releasing new driver
332
333      1. In the supported kernels verify there are no warning or compile
334         errors when the kernel is built as both a driver and as a module
335         and with the following options:
336
337         ADVANSYS_DEBUG - enabled and disabled
338         CONFIG_SMP - enabled and disabled
339         CONFIG_PROC_FS - enabled and disabled
340
341      2. Run tests on an x86, alpha, and PowerPC with at least one narrow
342         card and one wide card attached to a hard disk and CD-ROM drive:
343         fdisk, mkfs, fsck, bonnie, copy/compare test from the
344         CD-ROM to the hard drive.
345
346   H. Release History
347
348      BETA-1.0 (12/23/95):
349          First Release
350
351      BETA-1.1 (12/28/95):
352          1. Prevent advansys_detect() from being called twice.
353          2. Add LILO 0xdeb[0-f] option to set 'asc_dbglvl'.
354
355      1.2 (1/12/96):
356          1. Prevent re-entrancy in the interrupt handler which
357             resulted in the driver hanging Linux.
358          2. Fix problem that prevented ABP-940 cards from being
359             recognized on some PCI motherboards.
360          3. Add support for the ABP-5140 PnP ISA card.
361          4. Fix check condition return status.
362          5. Add conditionally compiled code for Linux v1.3.X.
363
364      1.3 (2/23/96):
365          1. Fix problem in advansys_biosparam() that resulted in the
366             wrong drive geometry being returned for drives > 1GB with
367             extended translation enabled.
368          2. Add additional tracing during device initialization.
369          3. Change code that only applies to ISA PnP adapter.
370          4. Eliminate 'make dep' warning.
371          5. Try to fix problem with handling resets by increasing their
372             timeout value.
373
374      1.4 (5/8/96):
375          1. Change definitions to eliminate conflicts with other subsystems.
376          2. Add versioning code for the shared interrupt changes.
377          3. Eliminate problem in asc_rmqueue() with iterating after removing
378             a request.
379          4. Remove reset request loop problem from the "Known Problems or
380             Issues" section. This problem was isolated and fixed in the
381             mid-level SCSI driver.
382
383      1.5 (8/8/96):
384          1. Add support for ABP-940U (PCI Ultra) adapter.
385          2. Add support for IRQ sharing by setting the SA_SHIRQ flag for
386             request_irq and supplying a dev_id pointer to both request_irq()
387             and free_irq().
388          3. In AscSearchIOPortAddr11() restore a call to check_region() which
389             should be used before I/O port probing.
390          4. Fix bug in asc_prt_hex() which resulted in the displaying
391             the wrong data.
392          5. Incorporate miscellaneous Asc Library bug fixes and new microcode.
393          6. Change driver versioning to be specific to each Linux sub-level.
394          7. Change statistics gathering to be per adapter instead of global
395             to the driver.
396          8. Add more information and statistics to the adapter /proc file:
397             /proc/scsi/advansys[0...].
398          9. Remove 'cmd_per_lun' from the "Known Problems or Issues" list.
399             This problem has been addressed with the SCSI mid-level changes
400             made in v1.3.89. The advansys_select_queue_depths() function
401             was added for the v1.3.89 changes.
402
403      1.6 (9/10/96):
404          1. Incorporate miscellaneous Asc Library bug fixes and new microcode.
405
406      1.7 (9/25/96):
407          1. Enable clustering and optimize the setting of the maximum number
408             of scatter gather elements for any particular board. Clustering
409             increases CPU utilization, but results in a relatively larger
410             increase in I/O throughput.
411          2. Improve the performance of the request queuing functions by
412             adding a last pointer to the queue structure.
413          3. Correct problems with reset and abort request handling that
414             could have hung or crashed Linux.
415          4. Add more information to the adapter /proc file:
416             /proc/scsi/advansys[0...].
417          5. Remove the request timeout issue form the driver issues list.
418          6. Miscellaneous documentation additions and changes.
419
420      1.8 (10/4/96):
421          1. Make changes to handle the new v2.1.0 kernel memory mapping
422             in which a kernel virtual address may not be equivalent to its
423             bus or DMA memory address.
424          2. Change abort and reset request handling to make it yet even
425             more robust.
426          3. Try to mitigate request starvation by sending ordered requests
427             to heavily loaded, tag queuing enabled devices.
428          4. Maintain statistics on request response time.
429          5. Add request response time statistics and other information to
430             the adapter /proc file: /proc/scsi/advansys[0...].
431
432      1.9 (10/21/96):
433          1. Add conditionally compiled code (ASC_QUEUE_FLOW_CONTROL) to
434             make use of mid-level SCSI driver device queue depth flow
435             control mechanism. This will eliminate aborts caused by a
436             device being unable to keep up with requests and eliminate
437             repeat busy or QUEUE FULL status returned by a device.
438          2. Incorporate miscellaneous Asc Library bug fixes.
439          3. To allow the driver to work in kernels with broken module
440             support set 'cmd_per_lun' if the driver is compiled as a
441             module. This change affects kernels v1.3.89 to present.
442          4. Remove PCI BIOS address from the driver banner. The PCI BIOS
443             is relocated by the motherboard BIOS and its new address can
444             not be determined by the driver.
445          5. Add mid-level SCSI queue depth information to the adapter
446             /proc file: /proc/scsi/advansys[0...].
447
448      2.0 (11/14/96):
449          1. Change allocation of global structures used for device
450             initialization to guarantee they are in DMA-able memory.
451             Previously when the driver was loaded as a module these
452             structures might not have been in DMA-able memory, causing
453             device initialization to fail.
454
455      2.1 (12/30/96):
456          1. In advansys_reset(), if the request is a synchronous reset
457             request, even if the request serial number has changed, then
458             complete the request.
459          2. Add Asc Library bug fixes including new microcode.
460          3. Clear inquiry buffer before using it.
461          4. Correct ifdef typo.
462
463      2.2 (1/15/97):
464          1. Add Asc Library bug fixes including new microcode.
465          2. Add synchronous data transfer rate information to the
466             adapter /proc file: /proc/scsi/advansys[0...].
467          3. Change ADVANSYS_DEBUG to be disabled by default. This
468             will reduce the size of the driver image, eliminate execution
469             overhead, and remove unneeded symbols from the kernel symbol
470             space that were previously added by the driver.
471          4. Add new compile-time option ADVANSYS_ASSERT for assertion
472             code that used to be defined within ADVANSYS_DEBUG. This
473             option is enabled by default.
474
475      2.8 (5/26/97):
476          1. Change version number to 2.8 to synchronize the Linux driver
477             version numbering with other AdvanSys drivers.
478          2. Reformat source files without tabs to present the same view
479             of the file to everyone regardless of the editor tab setting
480             being used.
481          3. Add Asc Library bug fixes.
482
483      3.1A (1/8/98):
484          1. Change version number to 3.1 to indicate that support for
485             Ultra-Wide adapters (ABP-940UW) is included in this release.
486          2. Add Asc Library (Narrow Board) bug fixes.
487          3. Report an underrun condition with the host status byte set
488             to DID_UNDERRUN. Currently DID_UNDERRUN is defined to 0 which
489             causes the underrun condition to be ignored. When Linux defines
490             its own DID_UNDERRUN the constant defined in this file can be
491             removed.
492          4. Add patch to AscWaitTixISRDone().
493          5. Add support for up to 16 different AdvanSys host adapter SCSI
494             channels in one system. This allows four cards with four channels
495             to be used in one system.
496
497      3.1B (1/9/98):
498          1. Handle that PCI register base addresses are not always page
499             aligned even though ioremap() requires that the address argument
500             be page aligned.
501
502      3.1C (1/10/98):
503          1. Update latest BIOS version checked for from the /proc file.
504          2. Don't set microcode SDTR variable at initialization. Instead
505             wait until device capabilities have been detected from an Inquiry
506             command.
507
508      3.1D (1/21/98):
509          1. Improve performance when the driver is compiled as module by
510             allowing up to 64 scatter-gather elements instead of 8.
511
512      3.1E (5/1/98):
513          1. Set time delay in AscWaitTixISRDone() to 1000 ms.
514          2. Include SMP locking changes.
515          3. For v2.1.93 and newer kernels use CONFIG_PCI and new PCI BIOS
516             access functions.
517          4. Update board serial number printing.
518          5. Try allocating an IRQ both with and without the SA_INTERRUPT
519             flag set to allow IRQ sharing with drivers that do not set
520             the SA_INTERRUPT flag. Also display a more descriptive error
521             message if request_irq() fails.
522          6. Update to latest Asc and Adv Libraries.
523
524      3.2A (7/22/99):
525          1. Update Adv Library to 4.16 which includes support for
526             the ASC38C0800 (Ultra2/LVD) IC.
527
528      3.2B (8/23/99):
529          1. Correct PCI compile time option for v2.1.93 and greater
530             kernels, advansys_info() string, and debug compile time
531             option.
532          2. Correct DvcSleepMilliSecond() for v2.1.0 and greater
533             kernels. This caused an LVD detection/BIST problem problem
534             among other things.
535          3. Sort PCI cards by PCI Bus, Slot, Function ascending order
536             to be consistent with the BIOS.
537          4. Update to Asc Library S121 and Adv Library 5.2.
538
539      3.2C (8/24/99):
540          1. Correct PCI card detection bug introduced in 3.2B that
541             prevented PCI cards from being detected in kernels older
542             than v2.1.93.
543
544      3.2D (8/26/99):
545          1. Correct /proc device synchronous speed information display.
546             Also when re-negotiation is pending for a target device
547             note this condition with an * and footnote.
548          2. Correct initialization problem with Ultra-Wide cards that
549             have a pre-3.2 BIOS. A microcode variable changed locations
550             in 3.2 and greater BIOSes which caused WDTR to be attempted
551             erroneously with drives that don't support WDTR.
552
553      3.2E (8/30/99):
554          1. Fix compile error caused by v2.3.13 PCI structure change.
555          2. Remove field from ASCEEP_CONFIG that resulted in an EEPROM
556             checksum error for ISA cards.
557          3. Remove ASC_QUEUE_FLOW_CONTROL conditional code. The mid-level
558             SCSI changes that it depended on were never included in Linux.
559
560      3.2F (9/3/99):
561          1. Handle new initial function code added in v2.3.16 for all
562             driver versions.
563
564      3.2G (9/8/99):
565          1. Fix PCI board detection in v2.3.13 and greater kernels.
566          2. Fix comiple errors in v2.3.X with debugging enabled.
567
568      3.2H (9/13/99):
569          1. Add 64-bit address, long support for Alpha and UltraSPARC.
570             The driver has been verified to work on an Alpha system.
571          2. Add partial byte order handling support for Power PC and
572             other big-endian platforms. This support has not yet been
573             completed or verified.
574          3. For wide boards replace block zeroing of request and
575             scatter-gather structures with individual field initialization
576             to improve performance.
577          4. Correct and clarify ROM BIOS version detection.
578
579      3.2I (10/8/99):
580          1. Update to Adv Library 5.4.
581          2. Add v2.3.19 underrun reporting to asc_isr_callback() and
582             adv_isr_callback().  Remove DID_UNDERRUN constant and other
583             no longer needed code that previously documented the lack
584             of underrun handling.
585
586      3.2J (10/14/99):
587          1. Eliminate compile errors for v2.0 and earlier kernels.
588
589      3.2K (11/15/99):
590          1. Correct debug compile error in asc_prt_adv_scsi_req_q().
591          2. Update Adv Library to 5.5.
592          3. Add ifdef handling for /proc changes added in v2.3.28.
593          4. Increase Wide board scatter-gather list maximum length to
594             255 when the driver is compiled into the kernel.
595
596      3.2L (11/18/99):
597          1. Fix bug in adv_get_sglist() that caused an assertion failure
598             at line 7475. The reqp->sgblkp pointer must be initialized
599             to NULL in adv_get_sglist().
600
601      3.2M (11/29/99):
602          1. Really fix bug in adv_get_sglist().
603          2. Incorporate v2.3.29 changes into driver.
604
605      3.2N (4/1/00):
606          1. Add CONFIG_ISA ifdef code.
607          2. Include advansys_interrupts_enabled name change patch.
608          3. For >= v2.3.28 use new SCSI error handling with new function
609             advansys_eh_bus_reset(). Don't include an abort function
610             because of base library limitations.
611          4. For >= v2.3.28 use per board lock instead of io_request_lock.
612          5. For >= v2.3.28 eliminate advansys_command() and
613             advansys_command_done().
614          6. Add some changes for PowerPC (Big Endian) support, but it isn't
615             working yet.
616          7. Fix "nonexistent resource free" problem that occurred on a module
617             unload for boards with an I/O space >= 255. The 'n_io_port' field
618             is only one byte and can not be used to hold an ioport length more
619             than 255.
620
621      3.3A (4/4/00):
622          1. Update to Adv Library 5.8.
623          2. For wide cards add support for CDBs up to 16 bytes.
624          3. Eliminate warnings when CONFIG_PROC_FS is not defined.
625
626      3.3B (5/1/00):
627          1. Support for PowerPC (Big Endian) wide cards. Narrow cards
628             still need work.
629          2. Change bitfields to shift and mask access for endian
630             portability.
631
632      3.3C (10/13/00):
633          1. Update for latest 2.4 kernel.
634          2. Test ABP-480 CardBus support in 2.4 kernel - works!
635          3. Update to Asc Library S123.
636          4. Update to Adv Library 5.12.
637
638      3.3D (11/22/00):
639          1. Update for latest 2.4 kernel.
640          2. Create patches for 2.2 and 2.4 kernels.
641
642      3.3E (1/9/01):
643          1. Now that 2.4 is released remove ifdef code for kernel versions
644             less than 2.2. The driver is now only supported in kernels 2.2,
645             2.4, and greater.
646          2. Add code to release and acquire the io_request_lock in
647             the driver entrypoint functions: advansys_detect and
648             advansys_queuecommand. In kernel 2.4 the SCSI mid-level driver
649             still holds the io_request_lock on entry to SCSI low-level drivers.
650             This was supposed to be removed before 2.4 was released but never
651             happened. When the mid-level SCSI driver is changed all references
652             to the io_request_lock should be removed from the driver.
653          3. Simplify error handling by removing advansys_abort(),
654             AscAbortSRB(), AscResetDevice(). SCSI bus reset requests are
655             now handled by resetting the SCSI bus and fully re-initializing
656             the chip. This simple method of error recovery has proven to work
657             most reliably after attempts at different methods. Also now only
658             support the "new" error handling method and remove the obsolete
659             error handling interface.
660          4. Fix debug build errors.
661
662      3.3F (1/24/01):
663          1. Merge with ConnectCom version from Andy Kellner which
664             updates Adv Library to 5.14.
665          2. Make PowerPC (Big Endian) work for narrow cards and
666             fix problems writing EEPROM for wide cards.
667          3. Remove interrupts_enabled assertion function.
668
669      3.3G (2/16/01):
670          1. Return an error from narrow boards if passed a 16 byte
671             CDB. The wide board can already handle 16 byte CDBs.
672
673      3.3GJ (4/15/02):
674          1. hacks for lk 2.5 series (D. Gilbert)
675
676      3.3GJD (10/14/02):
677          1. change select_queue_depths to slave_configure
678          2. make cmd_per_lun be sane again
679
680   I. Known Problems/Fix List (XXX)
681
682      1. Need to add memory mapping workaround. Test the memory mapping.
683         If it doesn't work revert to I/O port access. Can a test be done
684         safely?
685      2. Handle an interrupt not working. Keep an interrupt counter in
686         the interrupt handler. In the timeout function if the interrupt
687         has not occurred then print a message and run in polled mode.
688      3. Allow bus type scanning order to be changed.
689      4. Need to add support for target mode commands, cf. CAM XPT.
690
691   J. Credits (Chronological Order)
692
693      Bob Frey <bfrey@turbolinux.com.cn> wrote the AdvanSys SCSI driver
694      and maintained it up to 3.3F. He continues to answer questions
695      and help maintain the driver.
696
697      Nathan Hartwell <mage@cdc3.cdc.net> provided the directions and
698      basis for the Linux v1.3.X changes which were included in the
699      1.2 release.
700
701      Thomas E Zerucha <zerucha@shell.portal.com> pointed out a bug
702      in advansys_biosparam() which was fixed in the 1.3 release.
703
704      Erik Ratcliffe <erik@caldera.com> has done testing of the
705      AdvanSys driver in the Caldera releases.
706
707      Rik van Riel <H.H.vanRiel@fys.ruu.nl> provided a patch to
708      AscWaitTixISRDone() which he found necessary to make the
709      driver work with a SCSI-1 disk.
710
711      Mark Moran <mmoran@mmoran.com> has helped test Ultra-Wide
712      support in the 3.1A driver.
713
714      Doug Gilbert <dgilbert@interlog.com> has made changes and
715      suggestions to improve the driver and done a lot of testing.
716
717      Ken Mort <ken@mort.net> reported a DEBUG compile bug fixed
718      in 3.2K.
719
720      Tom Rini <trini@kernel.crashing.org> provided the CONFIG_ISA
721      patch and helped with PowerPC wide and narrow board support.
722
723      Philip Blundell <philip.blundell@pobox.com> provided an
724      advansys_interrupts_enabled patch.
725
726      Dave Jones <dave@denial.force9.co.uk> reported the compiler
727      warnings generated when CONFIG_PROC_FS was not defined in
728      the 3.2M driver.
729
730      Jerry Quinn <jlquinn@us.ibm.com> fixed PowerPC support (endian
731      problems) for wide cards.
732
733      Bryan Henderson <bryanh@giraffe-data.com> helped debug narrow
734      card error handling.
735
736      Manuel Veloso <veloso@pobox.com> worked hard on PowerPC narrow
737      board support and fixed a bug in AscGetEEPConfig().
738
739      Arnaldo Carvalho de Melo <acme@conectiva.com.br> made
740      save_flags/restore_flags changes.
741
742      Andy Kellner <AKellner@connectcom.net> continues the Advansys SCSI
743      driver development for ConnectCom (Version > 3.3F).
744
745   K. ConnectCom (AdvanSys) Contact Information
746
747      Mail:                   ConnectCom Solutions, Inc.
748                              1150 Ringwood Court
749                              San Jose, CA 95131
750      Operator/Sales:         1-408-383-9400
751      FAX:                    1-408-383-9612
752      Tech Support:           1-408-467-2930
753      Tech Support E-Mail:    linux@connectcom.net
754      FTP Site:               ftp.connectcom.net (login: anonymous)
755      Web Site:               http://www.connectcom.net
756
757 */
758
759 /*
760  * --- Linux Include Files
761  */
762
763 #include <linux/config.h>
764 #include <linux/module.h>
765
766 #if defined(CONFIG_X86) && !defined(CONFIG_ISA)
767 #define CONFIG_ISA
768 #endif /* CONFIG_X86 && !CONFIG_ISA */
769
770 #include <linux/string.h>
771 #include <linux/kernel.h>
772 #include <linux/types.h>
773 #include <linux/ioport.h>
774 #include <linux/interrupt.h>
775 #include <linux/delay.h>
776 #include <linux/slab.h>
777 #include <linux/mm.h>
778 #include <linux/proc_fs.h>
779 #include <linux/init.h>
780 #include <linux/blkdev.h>
781 #include <linux/stat.h>
782 #include <linux/spinlock.h>
783 #include <linux/dma-mapping.h>
784
785 #include <asm/io.h>
786 #include <asm/system.h>
787 #include <asm/dma.h>
788
789 #include "scsi.h"
790 #include <scsi/scsi_host.h>
791 #include "advansys.h"
792 #ifdef CONFIG_PCI
793 #include <linux/pci.h>
794 #endif /* CONFIG_PCI */
795
796
797 /*
798  * --- Driver Options
799  */
800
801 /* Enable driver assertions. */
802 #define ADVANSYS_ASSERT
803
804 /* Enable driver /proc statistics. */
805 #define ADVANSYS_STATS
806
807 /* Enable driver tracing. */
808 /* #define ADVANSYS_DEBUG */
809
810
811 /*
812  * --- Debugging Header
813  */
814
815 #ifdef ADVANSYS_DEBUG
816 #define STATIC
817 #else /* ADVANSYS_DEBUG */
818 #define STATIC static
819 #endif /* ADVANSYS_DEBUG */
820
821
822 /*
823  * --- Asc Library Constants and Macros
824  */
825
826 #define ASC_LIB_VERSION_MAJOR  1
827 #define ASC_LIB_VERSION_MINOR  24
828 #define ASC_LIB_SERIAL_NUMBER  123
829
830 /*
831  * Portable Data Types
832  *
833  * Any instance where a 32-bit long or pointer type is assumed
834  * for precision or HW defined structures, the following define
835  * types must be used. In Linux the char, short, and int types
836  * are all consistent at 8, 16, and 32 bits respectively. Pointers
837  * and long types are 64 bits on Alpha and UltraSPARC.
838  */
839 #define ASC_PADDR __u32         /* Physical/Bus address data type. */
840 #define ASC_VADDR __u32         /* Virtual address data type. */
841 #define ASC_DCNT  __u32         /* Unsigned Data count type. */
842 #define ASC_SDCNT __s32         /* Signed Data count type. */
843
844 /*
845  * These macros are used to convert a virtual address to a
846  * 32-bit value. This currently can be used on Linux Alpha
847  * which uses 64-bit virtual address but a 32-bit bus address.
848  * This is likely to break in the future, but doing this now
849  * will give us time to change the HW and FW to handle 64-bit
850  * addresses.
851  */
852 #define ASC_VADDR_TO_U32   virt_to_bus
853 #define ASC_U32_TO_VADDR   bus_to_virt
854
855 typedef unsigned char uchar;
856
857 #ifndef TRUE
858 #define TRUE     (1)
859 #endif
860 #ifndef FALSE
861 #define FALSE    (0)
862 #endif
863
864 #define EOF      (-1)
865 #define ERR      (-1)
866 #define UW_ERR   (uint)(0xFFFF)
867 #define isodd_word(val)   ((((uint)val) & (uint)0x0001) != 0)
868 #define AscPCIConfigVendorIDRegister      0x0000
869 #define AscPCIConfigDeviceIDRegister      0x0002
870 #define AscPCIConfigCommandRegister       0x0004
871 #define AscPCIConfigStatusRegister        0x0006
872 #define AscPCIConfigRevisionIDRegister    0x0008
873 #define AscPCIConfigCacheSize             0x000C
874 #define AscPCIConfigLatencyTimer          0x000D
875 #define AscPCIIOBaseRegister              0x0010
876 #define AscPCICmdRegBits_IOMemBusMaster   0x0007
877 #define ASC_PCI_ID2BUS(id)    ((id) & 0xFF)
878 #define ASC_PCI_ID2DEV(id)    (((id) >> 11) & 0x1F)
879 #define ASC_PCI_ID2FUNC(id)   (((id) >> 8) & 0x7)
880 #define ASC_PCI_MKID(bus, dev, func) ((((dev) & 0x1F) << 11) | (((func) & 0x7) << 8) | ((bus) & 0xFF))
881 #define ASC_PCI_VENDORID                  0x10CD
882 #define ASC_PCI_DEVICEID_1200A            0x1100
883 #define ASC_PCI_DEVICEID_1200B            0x1200
884 #define ASC_PCI_DEVICEID_ULTRA            0x1300
885 #define ASC_PCI_REVISION_3150             0x02
886 #define ASC_PCI_REVISION_3050             0x03
887
888 #define  ASC_DVCLIB_CALL_DONE     (1)
889 #define  ASC_DVCLIB_CALL_FAILED   (0)
890 #define  ASC_DVCLIB_CALL_ERROR    (-1)
891
892 /*
893  * Enable CC_VERY_LONG_SG_LIST to support up to 64K element SG lists.
894  * The SRB structure will have to be changed and the ASC_SRB2SCSIQ()
895  * macro re-defined to be able to obtain a ASC_SCSI_Q pointer from the
896  * SRB structure.
897  */
898 #define CC_VERY_LONG_SG_LIST 0
899 #define ASC_SRB2SCSIQ(srb_ptr)  (srb_ptr)
900
901 #define PortAddr                 unsigned short    /* port address size  */
902 #define inp(port)                inb(port)
903 #define outp(port, byte)         outb((byte), (port))
904
905 #define inpw(port)               inw(port)
906 #define outpw(port, word)        outw((word), (port))
907
908 #define ASC_MAX_SG_QUEUE    7
909 #define ASC_MAX_SG_LIST     255
910
911 #define ASC_CS_TYPE  unsigned short
912
913 #define ASC_IS_ISA          (0x0001)
914 #define ASC_IS_ISAPNP       (0x0081)
915 #define ASC_IS_EISA         (0x0002)
916 #define ASC_IS_PCI          (0x0004)
917 #define ASC_IS_PCI_ULTRA    (0x0104)
918 #define ASC_IS_PCMCIA       (0x0008)
919 #define ASC_IS_MCA          (0x0020)
920 #define ASC_IS_VL           (0x0040)
921 #define ASC_ISA_PNP_PORT_ADDR  (0x279)
922 #define ASC_ISA_PNP_PORT_WRITE (ASC_ISA_PNP_PORT_ADDR+0x800)
923 #define ASC_IS_WIDESCSI_16  (0x0100)
924 #define ASC_IS_WIDESCSI_32  (0x0200)
925 #define ASC_IS_BIG_ENDIAN   (0x8000)
926 #define ASC_CHIP_MIN_VER_VL      (0x01)
927 #define ASC_CHIP_MAX_VER_VL      (0x07)
928 #define ASC_CHIP_MIN_VER_PCI     (0x09)
929 #define ASC_CHIP_MAX_VER_PCI     (0x0F)
930 #define ASC_CHIP_VER_PCI_BIT     (0x08)
931 #define ASC_CHIP_MIN_VER_ISA     (0x11)
932 #define ASC_CHIP_MIN_VER_ISA_PNP (0x21)
933 #define ASC_CHIP_MAX_VER_ISA     (0x27)
934 #define ASC_CHIP_VER_ISA_BIT     (0x30)
935 #define ASC_CHIP_VER_ISAPNP_BIT  (0x20)
936 #define ASC_CHIP_VER_ASYN_BUG    (0x21)
937 #define ASC_CHIP_VER_PCI             0x08
938 #define ASC_CHIP_VER_PCI_ULTRA_3150  (ASC_CHIP_VER_PCI | 0x02)
939 #define ASC_CHIP_VER_PCI_ULTRA_3050  (ASC_CHIP_VER_PCI | 0x03)
940 #define ASC_CHIP_MIN_VER_EISA (0x41)
941 #define ASC_CHIP_MAX_VER_EISA (0x47)
942 #define ASC_CHIP_VER_EISA_BIT (0x40)
943 #define ASC_CHIP_LATEST_VER_EISA   ((ASC_CHIP_MIN_VER_EISA - 1) + 3)
944 #define ASC_MAX_LIB_SUPPORTED_ISA_CHIP_VER   0x21
945 #define ASC_MAX_LIB_SUPPORTED_PCI_CHIP_VER   0x0A
946 #define ASC_MAX_VL_DMA_ADDR     (0x07FFFFFFL)
947 #define ASC_MAX_VL_DMA_COUNT    (0x07FFFFFFL)
948 #define ASC_MAX_PCI_DMA_ADDR    (0xFFFFFFFFL)
949 #define ASC_MAX_PCI_DMA_COUNT   (0xFFFFFFFFL)
950 #define ASC_MAX_ISA_DMA_ADDR    (0x00FFFFFFL)
951 #define ASC_MAX_ISA_DMA_COUNT   (0x00FFFFFFL)
952 #define ASC_MAX_EISA_DMA_ADDR   (0x07FFFFFFL)
953 #define ASC_MAX_EISA_DMA_COUNT  (0x07FFFFFFL)
954
955 #define ASC_SCSI_ID_BITS  3
956 #define ASC_SCSI_TIX_TYPE     uchar
957 #define ASC_ALL_DEVICE_BIT_SET  0xFF
958 #define ASC_SCSI_BIT_ID_TYPE  uchar
959 #define ASC_MAX_TID       7
960 #define ASC_MAX_LUN       7
961 #define ASC_SCSI_WIDTH_BIT_SET  0xFF
962 #define ASC_MAX_SENSE_LEN   32
963 #define ASC_MIN_SENSE_LEN   14
964 #define ASC_MAX_CDB_LEN     12
965 #define ASC_SCSI_RESET_HOLD_TIME_US  60
966
967 #define ADV_INQ_CLOCKING_ST_ONLY    0x0
968 #define ADV_INQ_CLOCKING_DT_ONLY    0x1
969 #define ADV_INQ_CLOCKING_ST_AND_DT  0x3
970
971 /*
972  * Inquiry SPC-2 SPI Byte 1 EVPD (Enable Vital Product Data)
973  * and CmdDt (Command Support Data) field bit definitions.
974  */
975 #define ADV_INQ_RTN_VPD_AND_CMDDT           0x3
976 #define ADV_INQ_RTN_CMDDT_FOR_OP_CODE       0x2
977 #define ADV_INQ_RTN_VPD_FOR_PG_CODE         0x1
978 #define ADV_INQ_RTN_STD_INQUIRY_DATA        0x0
979
980 #define ASC_SCSIDIR_NOCHK    0x00
981 #define ASC_SCSIDIR_T2H      0x08
982 #define ASC_SCSIDIR_H2T      0x10
983 #define ASC_SCSIDIR_NODATA   0x18
984 #define SCSI_ASC_NOMEDIA          0x3A
985 #define ASC_SRB_HOST(x)  ((uchar)((uchar)(x) >> 4))
986 #define ASC_SRB_TID(x)   ((uchar)((uchar)(x) & (uchar)0x0F))
987 #define ASC_SRB_LUN(x)   ((uchar)((uint)(x) >> 13))
988 #define PUT_CDB1(x)   ((uchar)((uint)(x) >> 8))
989 #define MS_CMD_DONE    0x00
990 #define MS_EXTEND      0x01
991 #define MS_SDTR_LEN    0x03
992 #define MS_SDTR_CODE   0x01
993 #define MS_WDTR_LEN    0x02
994 #define MS_WDTR_CODE   0x03
995 #define MS_MDP_LEN    0x05
996 #define MS_MDP_CODE   0x00
997
998 /*
999  * Inquiry data structure and bitfield macros
1000  *
1001  * Only quantities of more than 1 bit are shifted, since the others are
1002  * just tested for true or false. C bitfields aren't portable between big
1003  * and little-endian platforms so they are not used.
1004  */
1005
1006 #define ASC_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
1007 #define ASC_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
1008 #define ASC_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
1009 #define ASC_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
1010 #define ASC_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
1011 #define ASC_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
1012 #define ASC_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
1013 #define ASC_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
1014 #define ASC_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
1015 #define ASC_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
1016 #define ASC_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
1017 #define ASC_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
1018 #define ASC_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
1019 #define ASC_INQ_SYNC(inq)           ((inq)->flags & 0x10)
1020 #define ASC_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
1021 #define ASC_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
1022 #define ASC_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
1023 #define ASC_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
1024 #define ASC_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
1025 #define ASC_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
1026
1027 typedef struct {
1028     uchar               periph;
1029     uchar               devtype;
1030     uchar               ver;
1031     uchar               byte3;
1032     uchar               add_len;
1033     uchar               res1;
1034     uchar               res2;
1035     uchar               flags;
1036     uchar               vendor_id[8];
1037     uchar               product_id[16];
1038     uchar               product_rev_level[4];
1039 } ASC_SCSI_INQUIRY;
1040
1041 #define ASC_SG_LIST_PER_Q   7
1042 #define QS_FREE        0x00
1043 #define QS_READY       0x01
1044 #define QS_DISC1       0x02
1045 #define QS_DISC2       0x04
1046 #define QS_BUSY        0x08
1047 #define QS_ABORTED     0x40
1048 #define QS_DONE        0x80
1049 #define QC_NO_CALLBACK   0x01
1050 #define QC_SG_SWAP_QUEUE 0x02
1051 #define QC_SG_HEAD       0x04
1052 #define QC_DATA_IN       0x08
1053 #define QC_DATA_OUT      0x10
1054 #define QC_URGENT        0x20
1055 #define QC_MSG_OUT       0x40
1056 #define QC_REQ_SENSE     0x80
1057 #define QCSG_SG_XFER_LIST  0x02
1058 #define QCSG_SG_XFER_MORE  0x04
1059 #define QCSG_SG_XFER_END   0x08
1060 #define QD_IN_PROGRESS       0x00
1061 #define QD_NO_ERROR          0x01
1062 #define QD_ABORTED_BY_HOST   0x02
1063 #define QD_WITH_ERROR        0x04
1064 #define QD_INVALID_REQUEST   0x80
1065 #define QD_INVALID_HOST_NUM  0x81
1066 #define QD_INVALID_DEVICE    0x82
1067 #define QD_ERR_INTERNAL      0xFF
1068 #define QHSTA_NO_ERROR               0x00
1069 #define QHSTA_M_SEL_TIMEOUT          0x11
1070 #define QHSTA_M_DATA_OVER_RUN        0x12
1071 #define QHSTA_M_DATA_UNDER_RUN       0x12
1072 #define QHSTA_M_UNEXPECTED_BUS_FREE  0x13
1073 #define QHSTA_M_BAD_BUS_PHASE_SEQ    0x14
1074 #define QHSTA_D_QDONE_SG_LIST_CORRUPTED 0x21
1075 #define QHSTA_D_ASC_DVC_ERROR_CODE_SET  0x22
1076 #define QHSTA_D_HOST_ABORT_FAILED       0x23
1077 #define QHSTA_D_EXE_SCSI_Q_FAILED       0x24
1078 #define QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT 0x25
1079 #define QHSTA_D_ASPI_NO_BUF_POOL        0x26
1080 #define QHSTA_M_WTM_TIMEOUT         0x41
1081 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
1082 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
1083 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
1084 #define QHSTA_M_TARGET_STATUS_BUSY  0x45
1085 #define QHSTA_M_BAD_TAG_CODE        0x46
1086 #define QHSTA_M_BAD_QUEUE_FULL_OR_BUSY  0x47
1087 #define QHSTA_M_HUNG_REQ_SCSI_BUS_RESET 0x48
1088 #define QHSTA_D_LRAM_CMP_ERROR        0x81
1089 #define QHSTA_M_MICRO_CODE_ERROR_HALT 0xA1
1090 #define ASC_FLAG_SCSIQ_REQ        0x01
1091 #define ASC_FLAG_BIOS_SCSIQ_REQ   0x02
1092 #define ASC_FLAG_BIOS_ASYNC_IO    0x04
1093 #define ASC_FLAG_SRB_LINEAR_ADDR  0x08
1094 #define ASC_FLAG_WIN16            0x10
1095 #define ASC_FLAG_WIN32            0x20
1096 #define ASC_FLAG_ISA_OVER_16MB    0x40
1097 #define ASC_FLAG_DOS_VM_CALLBACK  0x80
1098 #define ASC_TAG_FLAG_EXTRA_BYTES               0x10
1099 #define ASC_TAG_FLAG_DISABLE_DISCONNECT        0x04
1100 #define ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX  0x08
1101 #define ASC_TAG_FLAG_DISABLE_CHK_COND_INT_HOST 0x40
1102 #define ASC_SCSIQ_CPY_BEG              4
1103 #define ASC_SCSIQ_SGHD_CPY_BEG         2
1104 #define ASC_SCSIQ_B_FWD                0
1105 #define ASC_SCSIQ_B_BWD                1
1106 #define ASC_SCSIQ_B_STATUS             2
1107 #define ASC_SCSIQ_B_QNO                3
1108 #define ASC_SCSIQ_B_CNTL               4
1109 #define ASC_SCSIQ_B_SG_QUEUE_CNT       5
1110 #define ASC_SCSIQ_D_DATA_ADDR          8
1111 #define ASC_SCSIQ_D_DATA_CNT          12
1112 #define ASC_SCSIQ_B_SENSE_LEN         20
1113 #define ASC_SCSIQ_DONE_INFO_BEG       22
1114 #define ASC_SCSIQ_D_SRBPTR            22
1115 #define ASC_SCSIQ_B_TARGET_IX         26
1116 #define ASC_SCSIQ_B_CDB_LEN           28
1117 #define ASC_SCSIQ_B_TAG_CODE          29
1118 #define ASC_SCSIQ_W_VM_ID             30
1119 #define ASC_SCSIQ_DONE_STATUS         32
1120 #define ASC_SCSIQ_HOST_STATUS         33
1121 #define ASC_SCSIQ_SCSI_STATUS         34
1122 #define ASC_SCSIQ_CDB_BEG             36
1123 #define ASC_SCSIQ_DW_REMAIN_XFER_ADDR 56
1124 #define ASC_SCSIQ_DW_REMAIN_XFER_CNT  60
1125 #define ASC_SCSIQ_B_FIRST_SG_WK_QP    48
1126 #define ASC_SCSIQ_B_SG_WK_QP          49
1127 #define ASC_SCSIQ_B_SG_WK_IX          50
1128 #define ASC_SCSIQ_W_ALT_DC1           52
1129 #define ASC_SCSIQ_B_LIST_CNT          6
1130 #define ASC_SCSIQ_B_CUR_LIST_CNT      7
1131 #define ASC_SGQ_B_SG_CNTL             4
1132 #define ASC_SGQ_B_SG_HEAD_QP          5
1133 #define ASC_SGQ_B_SG_LIST_CNT         6
1134 #define ASC_SGQ_B_SG_CUR_LIST_CNT     7
1135 #define ASC_SGQ_LIST_BEG              8
1136 #define ASC_DEF_SCSI1_QNG    4
1137 #define ASC_MAX_SCSI1_QNG    4
1138 #define ASC_DEF_SCSI2_QNG    16
1139 #define ASC_MAX_SCSI2_QNG    32
1140 #define ASC_TAG_CODE_MASK    0x23
1141 #define ASC_STOP_REQ_RISC_STOP      0x01
1142 #define ASC_STOP_ACK_RISC_STOP      0x03
1143 #define ASC_STOP_CLEAN_UP_BUSY_Q    0x10
1144 #define ASC_STOP_CLEAN_UP_DISC_Q    0x20
1145 #define ASC_STOP_HOST_REQ_RISC_HALT 0x40
1146 #define ASC_TIDLUN_TO_IX(tid, lun)  (ASC_SCSI_TIX_TYPE)((tid) + ((lun)<<ASC_SCSI_ID_BITS))
1147 #define ASC_TID_TO_TARGET_ID(tid)   (ASC_SCSI_BIT_ID_TYPE)(0x01 << (tid))
1148 #define ASC_TIX_TO_TARGET_ID(tix)   (0x01 << ((tix) & ASC_MAX_TID))
1149 #define ASC_TIX_TO_TID(tix)         ((tix) & ASC_MAX_TID)
1150 #define ASC_TID_TO_TIX(tid)         ((tid) & ASC_MAX_TID)
1151 #define ASC_TIX_TO_LUN(tix)         (((tix) >> ASC_SCSI_ID_BITS) & ASC_MAX_LUN)
1152 #define ASC_QNO_TO_QADDR(q_no)      ((ASC_QADR_BEG)+((int)(q_no) << 6))
1153
1154 typedef struct asc_scsiq_1 {
1155     uchar               status;
1156     uchar               q_no;
1157     uchar               cntl;
1158     uchar               sg_queue_cnt;
1159     uchar               target_id;
1160     uchar               target_lun;
1161     ASC_PADDR           data_addr;
1162     ASC_DCNT            data_cnt;
1163     ASC_PADDR           sense_addr;
1164     uchar               sense_len;
1165     uchar               extra_bytes;
1166 } ASC_SCSIQ_1;
1167
1168 typedef struct asc_scsiq_2 {
1169     ASC_VADDR           srb_ptr;
1170     uchar               target_ix;
1171     uchar               flag;
1172     uchar               cdb_len;
1173     uchar               tag_code;
1174     ushort              vm_id;
1175 } ASC_SCSIQ_2;
1176
1177 typedef struct asc_scsiq_3 {
1178     uchar               done_stat;
1179     uchar               host_stat;
1180     uchar               scsi_stat;
1181     uchar               scsi_msg;
1182 } ASC_SCSIQ_3;
1183
1184 typedef struct asc_scsiq_4 {
1185     uchar               cdb[ASC_MAX_CDB_LEN];
1186     uchar               y_first_sg_list_qp;
1187     uchar               y_working_sg_qp;
1188     uchar               y_working_sg_ix;
1189     uchar               y_res;
1190     ushort              x_req_count;
1191     ushort              x_reconnect_rtn;
1192     ASC_PADDR           x_saved_data_addr;
1193     ASC_DCNT            x_saved_data_cnt;
1194 } ASC_SCSIQ_4;
1195
1196 typedef struct asc_q_done_info {
1197     ASC_SCSIQ_2         d2;
1198     ASC_SCSIQ_3         d3;
1199     uchar               q_status;
1200     uchar               q_no;
1201     uchar               cntl;
1202     uchar               sense_len;
1203     uchar               extra_bytes;
1204     uchar               res;
1205     ASC_DCNT            remain_bytes;
1206 } ASC_QDONE_INFO;
1207
1208 typedef struct asc_sg_list {
1209     ASC_PADDR           addr;
1210     ASC_DCNT            bytes;
1211 } ASC_SG_LIST;
1212
1213 typedef struct asc_sg_head {
1214     ushort              entry_cnt;
1215     ushort              queue_cnt;
1216     ushort              entry_to_copy;
1217     ushort              res;
1218     ASC_SG_LIST         sg_list[ASC_MAX_SG_LIST];
1219 } ASC_SG_HEAD;
1220
1221 #define ASC_MIN_SG_LIST   2
1222
1223 typedef struct asc_min_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_MIN_SG_LIST];
1229 } ASC_MIN_SG_HEAD;
1230
1231 #define QCX_SORT        (0x0001)
1232 #define QCX_COALEASE    (0x0002)
1233
1234 typedef struct asc_scsi_q {
1235     ASC_SCSIQ_1         q1;
1236     ASC_SCSIQ_2         q2;
1237     uchar               *cdbptr;
1238     ASC_SG_HEAD         *sg_head;
1239     ushort              remain_sg_entry_cnt;
1240     ushort              next_sg_index;
1241 } ASC_SCSI_Q;
1242
1243 typedef struct asc_scsi_req_q {
1244     ASC_SCSIQ_1         r1;
1245     ASC_SCSIQ_2         r2;
1246     uchar               *cdbptr;
1247     ASC_SG_HEAD         *sg_head;
1248     uchar               *sense_ptr;
1249     ASC_SCSIQ_3         r3;
1250     uchar               cdb[ASC_MAX_CDB_LEN];
1251     uchar               sense[ASC_MIN_SENSE_LEN];
1252 } ASC_SCSI_REQ_Q;
1253
1254 typedef struct asc_scsi_bios_req_q {
1255     ASC_SCSIQ_1         r1;
1256     ASC_SCSIQ_2         r2;
1257     uchar               *cdbptr;
1258     ASC_SG_HEAD         *sg_head;
1259     uchar               *sense_ptr;
1260     ASC_SCSIQ_3         r3;
1261     uchar               cdb[ASC_MAX_CDB_LEN];
1262     uchar               sense[ASC_MIN_SENSE_LEN];
1263 } ASC_SCSI_BIOS_REQ_Q;
1264
1265 typedef struct asc_risc_q {
1266     uchar               fwd;
1267     uchar               bwd;
1268     ASC_SCSIQ_1         i1;
1269     ASC_SCSIQ_2         i2;
1270     ASC_SCSIQ_3         i3;
1271     ASC_SCSIQ_4         i4;
1272 } ASC_RISC_Q;
1273
1274 typedef struct asc_sg_list_q {
1275     uchar               seq_no;
1276     uchar               q_no;
1277     uchar               cntl;
1278     uchar               sg_head_qp;
1279     uchar               sg_list_cnt;
1280     uchar               sg_cur_list_cnt;
1281 } ASC_SG_LIST_Q;
1282
1283 typedef struct asc_risc_sg_list_q {
1284     uchar               fwd;
1285     uchar               bwd;
1286     ASC_SG_LIST_Q       sg;
1287     ASC_SG_LIST         sg_list[7];
1288 } ASC_RISC_SG_LIST_Q;
1289
1290 #define ASC_EXE_SCSI_IO_MAX_IDLE_LOOP  0x1000000UL
1291 #define ASC_EXE_SCSI_IO_MAX_WAIT_LOOP  1024
1292 #define ASCQ_ERR_NO_ERROR             0
1293 #define ASCQ_ERR_IO_NOT_FOUND         1
1294 #define ASCQ_ERR_LOCAL_MEM            2
1295 #define ASCQ_ERR_CHKSUM               3
1296 #define ASCQ_ERR_START_CHIP           4
1297 #define ASCQ_ERR_INT_TARGET_ID        5
1298 #define ASCQ_ERR_INT_LOCAL_MEM        6
1299 #define ASCQ_ERR_HALT_RISC            7
1300 #define ASCQ_ERR_GET_ASPI_ENTRY       8
1301 #define ASCQ_ERR_CLOSE_ASPI           9
1302 #define ASCQ_ERR_HOST_INQUIRY         0x0A
1303 #define ASCQ_ERR_SAVED_SRB_BAD        0x0B
1304 #define ASCQ_ERR_QCNTL_SG_LIST        0x0C
1305 #define ASCQ_ERR_Q_STATUS             0x0D
1306 #define ASCQ_ERR_WR_SCSIQ             0x0E
1307 #define ASCQ_ERR_PC_ADDR              0x0F
1308 #define ASCQ_ERR_SYN_OFFSET           0x10
1309 #define ASCQ_ERR_SYN_XFER_TIME        0x11
1310 #define ASCQ_ERR_LOCK_DMA             0x12
1311 #define ASCQ_ERR_UNLOCK_DMA           0x13
1312 #define ASCQ_ERR_VDS_CHK_INSTALL      0x14
1313 #define ASCQ_ERR_MICRO_CODE_HALT      0x15
1314 #define ASCQ_ERR_SET_LRAM_ADDR        0x16
1315 #define ASCQ_ERR_CUR_QNG              0x17
1316 #define ASCQ_ERR_SG_Q_LINKS           0x18
1317 #define ASCQ_ERR_SCSIQ_PTR            0x19
1318 #define ASCQ_ERR_ISR_RE_ENTRY         0x1A
1319 #define ASCQ_ERR_CRITICAL_RE_ENTRY    0x1B
1320 #define ASCQ_ERR_ISR_ON_CRITICAL      0x1C
1321 #define ASCQ_ERR_SG_LIST_ODD_ADDRESS  0x1D
1322 #define ASCQ_ERR_XFER_ADDRESS_TOO_BIG 0x1E
1323 #define ASCQ_ERR_SCSIQ_NULL_PTR       0x1F
1324 #define ASCQ_ERR_SCSIQ_BAD_NEXT_PTR   0x20
1325 #define ASCQ_ERR_GET_NUM_OF_FREE_Q    0x21
1326 #define ASCQ_ERR_SEND_SCSI_Q          0x22
1327 #define ASCQ_ERR_HOST_REQ_RISC_HALT   0x23
1328 #define ASCQ_ERR_RESET_SDTR           0x24
1329
1330 /*
1331  * Warning code values are set in ASC_DVC_VAR  'warn_code'.
1332  */
1333 #define ASC_WARN_NO_ERROR             0x0000
1334 #define ASC_WARN_IO_PORT_ROTATE       0x0001
1335 #define ASC_WARN_EEPROM_CHKSUM        0x0002
1336 #define ASC_WARN_IRQ_MODIFIED         0x0004
1337 #define ASC_WARN_AUTO_CONFIG          0x0008
1338 #define ASC_WARN_CMD_QNG_CONFLICT     0x0010
1339 #define ASC_WARN_EEPROM_RECOVER       0x0020
1340 #define ASC_WARN_CFG_MSW_RECOVER      0x0040
1341 #define ASC_WARN_SET_PCI_CONFIG_SPACE 0x0080
1342
1343 /*
1344  * Error code values are set in ASC_DVC_VAR  'err_code'.
1345  */
1346 #define ASC_IERR_WRITE_EEPROM         0x0001
1347 #define ASC_IERR_MCODE_CHKSUM         0x0002
1348 #define ASC_IERR_SET_PC_ADDR          0x0004
1349 #define ASC_IERR_START_STOP_CHIP      0x0008
1350 #define ASC_IERR_IRQ_NO               0x0010
1351 #define ASC_IERR_SET_IRQ_NO           0x0020
1352 #define ASC_IERR_CHIP_VERSION         0x0040
1353 #define ASC_IERR_SET_SCSI_ID          0x0080
1354 #define ASC_IERR_GET_PHY_ADDR         0x0100
1355 #define ASC_IERR_BAD_SIGNATURE        0x0200
1356 #define ASC_IERR_NO_BUS_TYPE          0x0400
1357 #define ASC_IERR_SCAM                 0x0800
1358 #define ASC_IERR_SET_SDTR             0x1000
1359 #define ASC_IERR_RW_LRAM              0x8000
1360
1361 #define ASC_DEF_IRQ_NO  10
1362 #define ASC_MAX_IRQ_NO  15
1363 #define ASC_MIN_IRQ_NO  10
1364 #define ASC_MIN_REMAIN_Q        (0x02)
1365 #define ASC_DEF_MAX_TOTAL_QNG   (0xF0)
1366 #define ASC_MIN_TAG_Q_PER_DVC   (0x04)
1367 #define ASC_DEF_TAG_Q_PER_DVC   (0x04)
1368 #define ASC_MIN_FREE_Q        ASC_MIN_REMAIN_Q
1369 #define ASC_MIN_TOTAL_QNG     ((ASC_MAX_SG_QUEUE)+(ASC_MIN_FREE_Q))
1370 #define ASC_MAX_TOTAL_QNG 240
1371 #define ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG 16
1372 #define ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG   8
1373 #define ASC_MAX_PCI_INRAM_TOTAL_QNG  20
1374 #define ASC_MAX_INRAM_TAG_QNG   16
1375 #define ASC_IOADR_TABLE_MAX_IX  11
1376 #define ASC_IOADR_GAP   0x10
1377 #define ASC_SEARCH_IOP_GAP 0x10
1378 #define ASC_MIN_IOP_ADDR   (PortAddr)0x0100
1379 #define ASC_MAX_IOP_ADDR   (PortAddr)0x3F0
1380 #define ASC_IOADR_1     (PortAddr)0x0110
1381 #define ASC_IOADR_2     (PortAddr)0x0130
1382 #define ASC_IOADR_3     (PortAddr)0x0150
1383 #define ASC_IOADR_4     (PortAddr)0x0190
1384 #define ASC_IOADR_5     (PortAddr)0x0210
1385 #define ASC_IOADR_6     (PortAddr)0x0230
1386 #define ASC_IOADR_7     (PortAddr)0x0250
1387 #define ASC_IOADR_8     (PortAddr)0x0330
1388 #define ASC_IOADR_DEF   ASC_IOADR_8
1389 #define ASC_LIB_SCSIQ_WK_SP        256
1390 #define ASC_MAX_SYN_XFER_NO        16
1391 #define ASC_SYN_MAX_OFFSET         0x0F
1392 #define ASC_DEF_SDTR_OFFSET        0x0F
1393 #define ASC_DEF_SDTR_INDEX         0x00
1394 #define ASC_SDTR_ULTRA_PCI_10MB_INDEX  0x02
1395 #define SYN_XFER_NS_0  25
1396 #define SYN_XFER_NS_1  30
1397 #define SYN_XFER_NS_2  35
1398 #define SYN_XFER_NS_3  40
1399 #define SYN_XFER_NS_4  50
1400 #define SYN_XFER_NS_5  60
1401 #define SYN_XFER_NS_6  70
1402 #define SYN_XFER_NS_7  85
1403 #define SYN_ULTRA_XFER_NS_0    12
1404 #define SYN_ULTRA_XFER_NS_1    19
1405 #define SYN_ULTRA_XFER_NS_2    25
1406 #define SYN_ULTRA_XFER_NS_3    32
1407 #define SYN_ULTRA_XFER_NS_4    38
1408 #define SYN_ULTRA_XFER_NS_5    44
1409 #define SYN_ULTRA_XFER_NS_6    50
1410 #define SYN_ULTRA_XFER_NS_7    57
1411 #define SYN_ULTRA_XFER_NS_8    63
1412 #define SYN_ULTRA_XFER_NS_9    69
1413 #define SYN_ULTRA_XFER_NS_10   75
1414 #define SYN_ULTRA_XFER_NS_11   82
1415 #define SYN_ULTRA_XFER_NS_12   88
1416 #define SYN_ULTRA_XFER_NS_13   94
1417 #define SYN_ULTRA_XFER_NS_14  100
1418 #define SYN_ULTRA_XFER_NS_15  107
1419
1420 typedef struct ext_msg {
1421     uchar               msg_type;
1422     uchar               msg_len;
1423     uchar               msg_req;
1424     union {
1425         struct {
1426             uchar               sdtr_xfer_period;
1427             uchar               sdtr_req_ack_offset;
1428         } sdtr;
1429         struct {
1430             uchar               wdtr_width;
1431         } wdtr;
1432         struct {
1433             uchar               mdp_b3;
1434             uchar               mdp_b2;
1435             uchar               mdp_b1;
1436             uchar               mdp_b0;
1437         } mdp;
1438     } u_ext_msg;
1439     uchar               res;
1440 } EXT_MSG;
1441
1442 #define xfer_period     u_ext_msg.sdtr.sdtr_xfer_period
1443 #define req_ack_offset  u_ext_msg.sdtr.sdtr_req_ack_offset
1444 #define wdtr_width      u_ext_msg.wdtr.wdtr_width
1445 #define mdp_b3          u_ext_msg.mdp_b3
1446 #define mdp_b2          u_ext_msg.mdp_b2
1447 #define mdp_b1          u_ext_msg.mdp_b1
1448 #define mdp_b0          u_ext_msg.mdp_b0
1449
1450 typedef struct asc_dvc_cfg {
1451     ASC_SCSI_BIT_ID_TYPE can_tagged_qng;
1452     ASC_SCSI_BIT_ID_TYPE cmd_qng_enabled;
1453     ASC_SCSI_BIT_ID_TYPE disc_enable;
1454     ASC_SCSI_BIT_ID_TYPE sdtr_enable;
1455     uchar               chip_scsi_id;
1456     uchar               isa_dma_speed;
1457     uchar               isa_dma_channel;
1458     uchar               chip_version;
1459     ushort              lib_serial_no;
1460     ushort              lib_version;
1461     ushort              mcode_date;
1462     ushort              mcode_version;
1463     uchar               max_tag_qng[ASC_MAX_TID + 1];
1464     uchar               *overrun_buf;
1465     uchar               sdtr_period_offset[ASC_MAX_TID + 1];
1466     ushort              pci_slot_info;
1467     uchar               adapter_info[6];
1468     struct device       *dev;
1469 } ASC_DVC_CFG;
1470
1471 #define ASC_DEF_DVC_CNTL       0xFFFF
1472 #define ASC_DEF_CHIP_SCSI_ID   7
1473 #define ASC_DEF_ISA_DMA_SPEED  4
1474 #define ASC_INIT_STATE_NULL          0x0000
1475 #define ASC_INIT_STATE_BEG_GET_CFG   0x0001
1476 #define ASC_INIT_STATE_END_GET_CFG   0x0002
1477 #define ASC_INIT_STATE_BEG_SET_CFG   0x0004
1478 #define ASC_INIT_STATE_END_SET_CFG   0x0008
1479 #define ASC_INIT_STATE_BEG_LOAD_MC   0x0010
1480 #define ASC_INIT_STATE_END_LOAD_MC   0x0020
1481 #define ASC_INIT_STATE_BEG_INQUIRY   0x0040
1482 #define ASC_INIT_STATE_END_INQUIRY   0x0080
1483 #define ASC_INIT_RESET_SCSI_DONE     0x0100
1484 #define ASC_INIT_STATE_WITHOUT_EEP   0x8000
1485 #define ASC_PCI_DEVICE_ID_REV_A      0x1100
1486 #define ASC_PCI_DEVICE_ID_REV_B      0x1200
1487 #define ASC_BUG_FIX_IF_NOT_DWB       0x0001
1488 #define ASC_BUG_FIX_ASYN_USE_SYN     0x0002
1489 #define ASYN_SDTR_DATA_FIX_PCI_REV_AB 0x41
1490 #define ASC_MIN_TAGGED_CMD  7
1491 #define ASC_MAX_SCSI_RESET_WAIT      30
1492
1493 struct asc_dvc_var;     /* Forward Declaration. */
1494
1495 typedef void (* ASC_ISR_CALLBACK)(struct asc_dvc_var *, ASC_QDONE_INFO *);
1496 typedef int (* ASC_EXE_CALLBACK)(struct asc_dvc_var *, ASC_SCSI_Q *);
1497
1498 typedef struct asc_dvc_var {
1499     PortAddr            iop_base;
1500     ushort              err_code;
1501     ushort              dvc_cntl;
1502     ushort              bug_fix_cntl;
1503     ushort              bus_type;
1504     ASC_ISR_CALLBACK    isr_callback;
1505     ASC_EXE_CALLBACK    exe_callback;
1506     ASC_SCSI_BIT_ID_TYPE init_sdtr;
1507     ASC_SCSI_BIT_ID_TYPE sdtr_done;
1508     ASC_SCSI_BIT_ID_TYPE use_tagged_qng;
1509     ASC_SCSI_BIT_ID_TYPE unit_not_ready;
1510     ASC_SCSI_BIT_ID_TYPE queue_full_or_busy;
1511     ASC_SCSI_BIT_ID_TYPE start_motor;
1512     uchar               scsi_reset_wait;
1513     uchar               chip_no;
1514     char                is_in_int;
1515     uchar               max_total_qng;
1516     uchar               cur_total_qng;
1517     uchar               in_critical_cnt;
1518     uchar               irq_no;
1519     uchar               last_q_shortage;
1520     ushort              init_state;
1521     uchar               cur_dvc_qng[ASC_MAX_TID + 1];
1522     uchar               max_dvc_qng[ASC_MAX_TID + 1];
1523     ASC_SCSI_Q  *scsiq_busy_head[ASC_MAX_TID + 1];
1524     ASC_SCSI_Q  *scsiq_busy_tail[ASC_MAX_TID + 1];
1525     uchar               sdtr_period_tbl[ASC_MAX_SYN_XFER_NO];
1526     ASC_DVC_CFG *cfg;
1527     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer_always;
1528     char                redo_scam;
1529     ushort              res2;
1530     uchar               dos_int13_table[ASC_MAX_TID + 1];
1531     ASC_DCNT            max_dma_count;
1532     ASC_SCSI_BIT_ID_TYPE no_scam;
1533     ASC_SCSI_BIT_ID_TYPE pci_fix_asyn_xfer;
1534     uchar               max_sdtr_index;
1535     uchar               host_init_sdtr_index;
1536     struct asc_board    *drv_ptr;
1537     ASC_DCNT            uc_break;
1538 } ASC_DVC_VAR;
1539
1540 typedef struct asc_dvc_inq_info {
1541     uchar               type[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1542 } ASC_DVC_INQ_INFO;
1543
1544 typedef struct asc_cap_info {
1545     ASC_DCNT            lba;
1546     ASC_DCNT            blk_size;
1547 } ASC_CAP_INFO;
1548
1549 typedef struct asc_cap_info_array {
1550     ASC_CAP_INFO        cap_info[ASC_MAX_TID + 1][ASC_MAX_LUN + 1];
1551 } ASC_CAP_INFO_ARRAY;
1552
1553 #define ASC_MCNTL_NO_SEL_TIMEOUT  (ushort)0x0001
1554 #define ASC_MCNTL_NULL_TARGET     (ushort)0x0002
1555 #define ASC_CNTL_INITIATOR         (ushort)0x0001
1556 #define ASC_CNTL_BIOS_GT_1GB       (ushort)0x0002
1557 #define ASC_CNTL_BIOS_GT_2_DISK    (ushort)0x0004
1558 #define ASC_CNTL_BIOS_REMOVABLE    (ushort)0x0008
1559 #define ASC_CNTL_NO_SCAM           (ushort)0x0010
1560 #define ASC_CNTL_INT_MULTI_Q       (ushort)0x0080
1561 #define ASC_CNTL_NO_LUN_SUPPORT    (ushort)0x0040
1562 #define ASC_CNTL_NO_VERIFY_COPY    (ushort)0x0100
1563 #define ASC_CNTL_RESET_SCSI        (ushort)0x0200
1564 #define ASC_CNTL_INIT_INQUIRY      (ushort)0x0400
1565 #define ASC_CNTL_INIT_VERBOSE      (ushort)0x0800
1566 #define ASC_CNTL_SCSI_PARITY       (ushort)0x1000
1567 #define ASC_CNTL_BURST_MODE        (ushort)0x2000
1568 #define ASC_CNTL_SDTR_ENABLE_ULTRA (ushort)0x4000
1569 #define ASC_EEP_DVC_CFG_BEG_VL    2
1570 #define ASC_EEP_MAX_DVC_ADDR_VL   15
1571 #define ASC_EEP_DVC_CFG_BEG      32
1572 #define ASC_EEP_MAX_DVC_ADDR     45
1573 #define ASC_EEP_DEFINED_WORDS    10
1574 #define ASC_EEP_MAX_ADDR         63
1575 #define ASC_EEP_RES_WORDS         0
1576 #define ASC_EEP_MAX_RETRY        20
1577 #define ASC_MAX_INIT_BUSY_RETRY   8
1578 #define ASC_EEP_ISA_PNP_WSIZE    16
1579
1580 /*
1581  * These macros keep the chip SCSI id and ISA DMA speed
1582  * bitfields in board order. C bitfields aren't portable
1583  * between big and little-endian platforms so they are
1584  * not used.
1585  */
1586
1587 #define ASC_EEP_GET_CHIP_ID(cfg)    ((cfg)->id_speed & 0x0f)
1588 #define ASC_EEP_GET_DMA_SPD(cfg)    (((cfg)->id_speed & 0xf0) >> 4)
1589 #define ASC_EEP_SET_CHIP_ID(cfg, sid) \
1590    ((cfg)->id_speed = ((cfg)->id_speed & 0xf0) | ((sid) & ASC_MAX_TID))
1591 #define ASC_EEP_SET_DMA_SPD(cfg, spd) \
1592    ((cfg)->id_speed = ((cfg)->id_speed & 0x0f) | ((spd) & 0x0f) << 4)
1593
1594 typedef struct asceep_config {
1595     ushort              cfg_lsw;
1596     ushort              cfg_msw;
1597     uchar               init_sdtr;
1598     uchar               disc_enable;
1599     uchar               use_cmd_qng;
1600     uchar               start_motor;
1601     uchar               max_total_qng;
1602     uchar               max_tag_qng;
1603     uchar               bios_scan;
1604     uchar               power_up_wait;
1605     uchar               no_scam;
1606     uchar               id_speed; /* low order 4 bits is chip scsi id */
1607                                   /* high order 4 bits is isa dma speed */
1608     uchar               dos_int13_table[ASC_MAX_TID + 1];
1609     uchar               adapter_info[6];
1610     ushort              cntl;
1611     ushort              chksum;
1612 } ASCEEP_CONFIG;
1613
1614 #define ASC_PCI_CFG_LSW_SCSI_PARITY  0x0800
1615 #define ASC_PCI_CFG_LSW_BURST_MODE   0x0080
1616 #define ASC_PCI_CFG_LSW_INTR_ABLE    0x0020
1617
1618 #define ASC_EEP_CMD_READ          0x80
1619 #define ASC_EEP_CMD_WRITE         0x40
1620 #define ASC_EEP_CMD_WRITE_ABLE    0x30
1621 #define ASC_EEP_CMD_WRITE_DISABLE 0x00
1622 #define ASC_OVERRUN_BSIZE  0x00000048UL
1623 #define ASC_CTRL_BREAK_ONCE        0x0001
1624 #define ASC_CTRL_BREAK_STAY_IDLE   0x0002
1625 #define ASCV_MSGOUT_BEG         0x0000
1626 #define ASCV_MSGOUT_SDTR_PERIOD (ASCV_MSGOUT_BEG+3)
1627 #define ASCV_MSGOUT_SDTR_OFFSET (ASCV_MSGOUT_BEG+4)
1628 #define ASCV_BREAK_SAVED_CODE   (ushort)0x0006
1629 #define ASCV_MSGIN_BEG          (ASCV_MSGOUT_BEG+8)
1630 #define ASCV_MSGIN_SDTR_PERIOD  (ASCV_MSGIN_BEG+3)
1631 #define ASCV_MSGIN_SDTR_OFFSET  (ASCV_MSGIN_BEG+4)
1632 #define ASCV_SDTR_DATA_BEG      (ASCV_MSGIN_BEG+8)
1633 #define ASCV_SDTR_DONE_BEG      (ASCV_SDTR_DATA_BEG+8)
1634 #define ASCV_MAX_DVC_QNG_BEG    (ushort)0x0020
1635 #define ASCV_BREAK_ADDR           (ushort)0x0028
1636 #define ASCV_BREAK_NOTIFY_COUNT   (ushort)0x002A
1637 #define ASCV_BREAK_CONTROL        (ushort)0x002C
1638 #define ASCV_BREAK_HIT_COUNT      (ushort)0x002E
1639
1640 #define ASCV_ASCDVC_ERR_CODE_W  (ushort)0x0030
1641 #define ASCV_MCODE_CHKSUM_W   (ushort)0x0032
1642 #define ASCV_MCODE_SIZE_W     (ushort)0x0034
1643 #define ASCV_STOP_CODE_B      (ushort)0x0036
1644 #define ASCV_DVC_ERR_CODE_B   (ushort)0x0037
1645 #define ASCV_OVERRUN_PADDR_D  (ushort)0x0038
1646 #define ASCV_OVERRUN_BSIZE_D  (ushort)0x003C
1647 #define ASCV_HALTCODE_W       (ushort)0x0040
1648 #define ASCV_CHKSUM_W         (ushort)0x0042
1649 #define ASCV_MC_DATE_W        (ushort)0x0044
1650 #define ASCV_MC_VER_W         (ushort)0x0046
1651 #define ASCV_NEXTRDY_B        (ushort)0x0048
1652 #define ASCV_DONENEXT_B       (ushort)0x0049
1653 #define ASCV_USE_TAGGED_QNG_B (ushort)0x004A
1654 #define ASCV_SCSIBUSY_B       (ushort)0x004B
1655 #define ASCV_Q_DONE_IN_PROGRESS_B  (ushort)0x004C
1656 #define ASCV_CURCDB_B         (ushort)0x004D
1657 #define ASCV_RCLUN_B          (ushort)0x004E
1658 #define ASCV_BUSY_QHEAD_B     (ushort)0x004F
1659 #define ASCV_DISC1_QHEAD_B    (ushort)0x0050
1660 #define ASCV_DISC_ENABLE_B    (ushort)0x0052
1661 #define ASCV_CAN_TAGGED_QNG_B (ushort)0x0053
1662 #define ASCV_HOSTSCSI_ID_B    (ushort)0x0055
1663 #define ASCV_MCODE_CNTL_B     (ushort)0x0056
1664 #define ASCV_NULL_TARGET_B    (ushort)0x0057
1665 #define ASCV_FREE_Q_HEAD_W    (ushort)0x0058
1666 #define ASCV_DONE_Q_TAIL_W    (ushort)0x005A
1667 #define ASCV_FREE_Q_HEAD_B    (ushort)(ASCV_FREE_Q_HEAD_W+1)
1668 #define ASCV_DONE_Q_TAIL_B    (ushort)(ASCV_DONE_Q_TAIL_W+1)
1669 #define ASCV_HOST_FLAG_B      (ushort)0x005D
1670 #define ASCV_TOTAL_READY_Q_B  (ushort)0x0064
1671 #define ASCV_VER_SERIAL_B     (ushort)0x0065
1672 #define ASCV_HALTCODE_SAVED_W (ushort)0x0066
1673 #define ASCV_WTM_FLAG_B       (ushort)0x0068
1674 #define ASCV_RISC_FLAG_B      (ushort)0x006A
1675 #define ASCV_REQ_SG_LIST_QP   (ushort)0x006B
1676 #define ASC_HOST_FLAG_IN_ISR        0x01
1677 #define ASC_HOST_FLAG_ACK_INT       0x02
1678 #define ASC_RISC_FLAG_GEN_INT      0x01
1679 #define ASC_RISC_FLAG_REQ_SG_LIST  0x02
1680 #define IOP_CTRL         (0x0F)
1681 #define IOP_STATUS       (0x0E)
1682 #define IOP_INT_ACK      IOP_STATUS
1683 #define IOP_REG_IFC      (0x0D)
1684 #define IOP_SYN_OFFSET    (0x0B)
1685 #define IOP_EXTRA_CONTROL (0x0D)
1686 #define IOP_REG_PC        (0x0C)
1687 #define IOP_RAM_ADDR      (0x0A)
1688 #define IOP_RAM_DATA      (0x08)
1689 #define IOP_EEP_DATA      (0x06)
1690 #define IOP_EEP_CMD       (0x07)
1691 #define IOP_VERSION       (0x03)
1692 #define IOP_CONFIG_HIGH   (0x04)
1693 #define IOP_CONFIG_LOW    (0x02)
1694 #define IOP_SIG_BYTE      (0x01)
1695 #define IOP_SIG_WORD      (0x00)
1696 #define IOP_REG_DC1      (0x0E)
1697 #define IOP_REG_DC0      (0x0C)
1698 #define IOP_REG_SB       (0x0B)
1699 #define IOP_REG_DA1      (0x0A)
1700 #define IOP_REG_DA0      (0x08)
1701 #define IOP_REG_SC       (0x09)
1702 #define IOP_DMA_SPEED    (0x07)
1703 #define IOP_REG_FLAG     (0x07)
1704 #define IOP_FIFO_H       (0x06)
1705 #define IOP_FIFO_L       (0x04)
1706 #define IOP_REG_ID       (0x05)
1707 #define IOP_REG_QP       (0x03)
1708 #define IOP_REG_IH       (0x02)
1709 #define IOP_REG_IX       (0x01)
1710 #define IOP_REG_AX       (0x00)
1711 #define IFC_REG_LOCK      (0x00)
1712 #define IFC_REG_UNLOCK    (0x09)
1713 #define IFC_WR_EN_FILTER  (0x10)
1714 #define IFC_RD_NO_EEPROM  (0x10)
1715 #define IFC_SLEW_RATE     (0x20)
1716 #define IFC_ACT_NEG       (0x40)
1717 #define IFC_INP_FILTER    (0x80)
1718 #define IFC_INIT_DEFAULT  (IFC_ACT_NEG | IFC_REG_UNLOCK)
1719 #define SC_SEL   (uchar)(0x80)
1720 #define SC_BSY   (uchar)(0x40)
1721 #define SC_ACK   (uchar)(0x20)
1722 #define SC_REQ   (uchar)(0x10)
1723 #define SC_ATN   (uchar)(0x08)
1724 #define SC_IO    (uchar)(0x04)
1725 #define SC_CD    (uchar)(0x02)
1726 #define SC_MSG   (uchar)(0x01)
1727 #define SEC_SCSI_CTL         (uchar)(0x80)
1728 #define SEC_ACTIVE_NEGATE    (uchar)(0x40)
1729 #define SEC_SLEW_RATE        (uchar)(0x20)
1730 #define SEC_ENABLE_FILTER    (uchar)(0x10)
1731 #define ASC_HALT_EXTMSG_IN     (ushort)0x8000
1732 #define ASC_HALT_CHK_CONDITION (ushort)0x8100
1733 #define ASC_HALT_SS_QUEUE_FULL (ushort)0x8200
1734 #define ASC_HALT_DISABLE_ASYN_USE_SYN_FIX  (ushort)0x8300
1735 #define ASC_HALT_ENABLE_ASYN_USE_SYN_FIX   (ushort)0x8400
1736 #define ASC_HALT_SDTR_REJECTED (ushort)0x4000
1737 #define ASC_HALT_HOST_COPY_SG_LIST_TO_RISC ( ushort )0x2000
1738 #define ASC_MAX_QNO        0xF8
1739 #define ASC_DATA_SEC_BEG   (ushort)0x0080
1740 #define ASC_DATA_SEC_END   (ushort)0x0080
1741 #define ASC_CODE_SEC_BEG   (ushort)0x0080
1742 #define ASC_CODE_SEC_END   (ushort)0x0080
1743 #define ASC_QADR_BEG       (0x4000)
1744 #define ASC_QADR_USED      (ushort)(ASC_MAX_QNO * 64)
1745 #define ASC_QADR_END       (ushort)0x7FFF
1746 #define ASC_QLAST_ADR      (ushort)0x7FC0
1747 #define ASC_QBLK_SIZE      0x40
1748 #define ASC_BIOS_DATA_QBEG 0xF8
1749 #define ASC_MIN_ACTIVE_QNO 0x01
1750 #define ASC_QLINK_END      0xFF
1751 #define ASC_EEPROM_WORDS   0x10
1752 #define ASC_MAX_MGS_LEN    0x10
1753 #define ASC_BIOS_ADDR_DEF  0xDC00
1754 #define ASC_BIOS_SIZE      0x3800
1755 #define ASC_BIOS_RAM_OFF   0x3800
1756 #define ASC_BIOS_RAM_SIZE  0x800
1757 #define ASC_BIOS_MIN_ADDR  0xC000
1758 #define ASC_BIOS_MAX_ADDR  0xEC00
1759 #define ASC_BIOS_BANK_SIZE 0x0400
1760 #define ASC_MCODE_START_ADDR  0x0080
1761 #define ASC_CFG0_HOST_INT_ON    0x0020
1762 #define ASC_CFG0_BIOS_ON        0x0040
1763 #define ASC_CFG0_VERA_BURST_ON  0x0080
1764 #define ASC_CFG0_SCSI_PARITY_ON 0x0800
1765 #define ASC_CFG1_SCSI_TARGET_ON 0x0080
1766 #define ASC_CFG1_LRAM_8BITS_ON  0x0800
1767 #define ASC_CFG_MSW_CLR_MASK    0x3080
1768 #define CSW_TEST1             (ASC_CS_TYPE)0x8000
1769 #define CSW_AUTO_CONFIG       (ASC_CS_TYPE)0x4000
1770 #define CSW_RESERVED1         (ASC_CS_TYPE)0x2000
1771 #define CSW_IRQ_WRITTEN       (ASC_CS_TYPE)0x1000
1772 #define CSW_33MHZ_SELECTED    (ASC_CS_TYPE)0x0800
1773 #define CSW_TEST2             (ASC_CS_TYPE)0x0400
1774 #define CSW_TEST3             (ASC_CS_TYPE)0x0200
1775 #define CSW_RESERVED2         (ASC_CS_TYPE)0x0100
1776 #define CSW_DMA_DONE          (ASC_CS_TYPE)0x0080
1777 #define CSW_FIFO_RDY          (ASC_CS_TYPE)0x0040
1778 #define CSW_EEP_READ_DONE     (ASC_CS_TYPE)0x0020
1779 #define CSW_HALTED            (ASC_CS_TYPE)0x0010
1780 #define CSW_SCSI_RESET_ACTIVE (ASC_CS_TYPE)0x0008
1781 #define CSW_PARITY_ERR        (ASC_CS_TYPE)0x0004
1782 #define CSW_SCSI_RESET_LATCH  (ASC_CS_TYPE)0x0002
1783 #define CSW_INT_PENDING       (ASC_CS_TYPE)0x0001
1784 #define CIW_CLR_SCSI_RESET_INT (ASC_CS_TYPE)0x1000
1785 #define CIW_INT_ACK      (ASC_CS_TYPE)0x0100
1786 #define CIW_TEST1        (ASC_CS_TYPE)0x0200
1787 #define CIW_TEST2        (ASC_CS_TYPE)0x0400
1788 #define CIW_SEL_33MHZ    (ASC_CS_TYPE)0x0800
1789 #define CIW_IRQ_ACT      (ASC_CS_TYPE)0x1000
1790 #define CC_CHIP_RESET   (uchar)0x80
1791 #define CC_SCSI_RESET   (uchar)0x40
1792 #define CC_HALT         (uchar)0x20
1793 #define CC_SINGLE_STEP  (uchar)0x10
1794 #define CC_DMA_ABLE     (uchar)0x08
1795 #define CC_TEST         (uchar)0x04
1796 #define CC_BANK_ONE     (uchar)0x02
1797 #define CC_DIAG         (uchar)0x01
1798 #define ASC_1000_ID0W      0x04C1
1799 #define ASC_1000_ID0W_FIX  0x00C1
1800 #define ASC_1000_ID1B      0x25
1801 #define ASC_EISA_BIG_IOP_GAP   (0x1C30-0x0C50)
1802 #define ASC_EISA_SMALL_IOP_GAP (0x0020)
1803 #define ASC_EISA_MIN_IOP_ADDR  (0x0C30)
1804 #define ASC_EISA_MAX_IOP_ADDR  (0xFC50)
1805 #define ASC_EISA_REV_IOP_MASK  (0x0C83)
1806 #define ASC_EISA_PID_IOP_MASK  (0x0C80)
1807 #define ASC_EISA_CFG_IOP_MASK  (0x0C86)
1808 #define ASC_GET_EISA_SLOT(iop)  (PortAddr)((iop) & 0xF000)
1809 #define ASC_EISA_ID_740    0x01745004UL
1810 #define ASC_EISA_ID_750    0x01755004UL
1811 #define INS_HALTINT        (ushort)0x6281
1812 #define INS_HALT           (ushort)0x6280
1813 #define INS_SINT           (ushort)0x6200
1814 #define INS_RFLAG_WTM      (ushort)0x7380
1815 #define ASC_MC_SAVE_CODE_WSIZE  0x500
1816 #define ASC_MC_SAVE_DATA_WSIZE  0x40
1817
1818 typedef struct asc_mc_saved {
1819     ushort              data[ASC_MC_SAVE_DATA_WSIZE];
1820     ushort              code[ASC_MC_SAVE_CODE_WSIZE];
1821 } ASC_MC_SAVED;
1822
1823 #define AscGetQDoneInProgress(port)         AscReadLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B)
1824 #define AscPutQDoneInProgress(port, val)    AscWriteLramByte((port), ASCV_Q_DONE_IN_PROGRESS_B, val)
1825 #define AscGetVarFreeQHead(port)            AscReadLramWord((port), ASCV_FREE_Q_HEAD_W)
1826 #define AscGetVarDoneQTail(port)            AscReadLramWord((port), ASCV_DONE_Q_TAIL_W)
1827 #define AscPutVarFreeQHead(port, val)       AscWriteLramWord((port), ASCV_FREE_Q_HEAD_W, val)
1828 #define AscPutVarDoneQTail(port, val)       AscWriteLramWord((port), ASCV_DONE_Q_TAIL_W, val)
1829 #define AscGetRiscVarFreeQHead(port)        AscReadLramByte((port), ASCV_NEXTRDY_B)
1830 #define AscGetRiscVarDoneQTail(port)        AscReadLramByte((port), ASCV_DONENEXT_B)
1831 #define AscPutRiscVarFreeQHead(port, val)   AscWriteLramByte((port), ASCV_NEXTRDY_B, val)
1832 #define AscPutRiscVarDoneQTail(port, val)   AscWriteLramByte((port), ASCV_DONENEXT_B, val)
1833 #define AscPutMCodeSDTRDoneAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id), (data));
1834 #define AscGetMCodeSDTRDoneAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DONE_BEG+(ushort)id));
1835 #define AscPutMCodeInitSDTRAtID(port, id, data)  AscWriteLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id), data);
1836 #define AscGetMCodeInitSDTRAtID(port, id)        AscReadLramByte((port), (ushort)((ushort)ASCV_SDTR_DATA_BEG+(ushort)id));
1837 #define AscSynIndexToPeriod(index)        (uchar)(asc_dvc->sdtr_period_tbl[ (index) ])
1838 #define AscGetChipSignatureByte(port)     (uchar)inp((port)+IOP_SIG_BYTE)
1839 #define AscGetChipSignatureWord(port)     (ushort)inpw((port)+IOP_SIG_WORD)
1840 #define AscGetChipVerNo(port)             (uchar)inp((port)+IOP_VERSION)
1841 #define AscGetChipCfgLsw(port)            (ushort)inpw((port)+IOP_CONFIG_LOW)
1842 #define AscGetChipCfgMsw(port)            (ushort)inpw((port)+IOP_CONFIG_HIGH)
1843 #define AscSetChipCfgLsw(port, data)      outpw((port)+IOP_CONFIG_LOW, data)
1844 #define AscSetChipCfgMsw(port, data)      outpw((port)+IOP_CONFIG_HIGH, data)
1845 #define AscGetChipEEPCmd(port)            (uchar)inp((port)+IOP_EEP_CMD)
1846 #define AscSetChipEEPCmd(port, data)      outp((port)+IOP_EEP_CMD, data)
1847 #define AscGetChipEEPData(port)           (ushort)inpw((port)+IOP_EEP_DATA)
1848 #define AscSetChipEEPData(port, data)     outpw((port)+IOP_EEP_DATA, data)
1849 #define AscGetChipLramAddr(port)          (ushort)inpw((PortAddr)((port)+IOP_RAM_ADDR))
1850 #define AscSetChipLramAddr(port, addr)    outpw((PortAddr)((port)+IOP_RAM_ADDR), addr)
1851 #define AscGetChipLramData(port)          (ushort)inpw((port)+IOP_RAM_DATA)
1852 #define AscSetChipLramData(port, data)    outpw((port)+IOP_RAM_DATA, data)
1853 #define AscGetChipIFC(port)               (uchar)inp((port)+IOP_REG_IFC)
1854 #define AscSetChipIFC(port, data)          outp((port)+IOP_REG_IFC, data)
1855 #define AscGetChipStatus(port)            (ASC_CS_TYPE)inpw((port)+IOP_STATUS)
1856 #define AscSetChipStatus(port, cs_val)    outpw((port)+IOP_STATUS, cs_val)
1857 #define AscGetChipControl(port)           (uchar)inp((port)+IOP_CTRL)
1858 #define AscSetChipControl(port, cc_val)   outp((port)+IOP_CTRL, cc_val)
1859 #define AscGetChipSyn(port)               (uchar)inp((port)+IOP_SYN_OFFSET)
1860 #define AscSetChipSyn(port, data)         outp((port)+IOP_SYN_OFFSET, data)
1861 #define AscSetPCAddr(port, data)          outpw((port)+IOP_REG_PC, data)
1862 #define AscGetPCAddr(port)                (ushort)inpw((port)+IOP_REG_PC)
1863 #define AscIsIntPending(port)             (AscGetChipStatus(port) & (CSW_INT_PENDING | CSW_SCSI_RESET_LATCH))
1864 #define AscGetChipScsiID(port)            ((AscGetChipCfgLsw(port) >> 8) & ASC_MAX_TID)
1865 #define AscGetExtraControl(port)          (uchar)inp((port)+IOP_EXTRA_CONTROL)
1866 #define AscSetExtraControl(port, data)    outp((port)+IOP_EXTRA_CONTROL, data)
1867 #define AscReadChipAX(port)               (ushort)inpw((port)+IOP_REG_AX)
1868 #define AscWriteChipAX(port, data)        outpw((port)+IOP_REG_AX, data)
1869 #define AscReadChipIX(port)               (uchar)inp((port)+IOP_REG_IX)
1870 #define AscWriteChipIX(port, data)        outp((port)+IOP_REG_IX, data)
1871 #define AscReadChipIH(port)               (ushort)inpw((port)+IOP_REG_IH)
1872 #define AscWriteChipIH(port, data)        outpw((port)+IOP_REG_IH, data)
1873 #define AscReadChipQP(port)               (uchar)inp((port)+IOP_REG_QP)
1874 #define AscWriteChipQP(port, data)        outp((port)+IOP_REG_QP, data)
1875 #define AscReadChipFIFO_L(port)           (ushort)inpw((port)+IOP_REG_FIFO_L)
1876 #define AscWriteChipFIFO_L(port, data)    outpw((port)+IOP_REG_FIFO_L, data)
1877 #define AscReadChipFIFO_H(port)           (ushort)inpw((port)+IOP_REG_FIFO_H)
1878 #define AscWriteChipFIFO_H(port, data)    outpw((port)+IOP_REG_FIFO_H, data)
1879 #define AscReadChipDmaSpeed(port)         (uchar)inp((port)+IOP_DMA_SPEED)
1880 #define AscWriteChipDmaSpeed(port, data)  outp((port)+IOP_DMA_SPEED, data)
1881 #define AscReadChipDA0(port)              (ushort)inpw((port)+IOP_REG_DA0)
1882 #define AscWriteChipDA0(port)             outpw((port)+IOP_REG_DA0, data)
1883 #define AscReadChipDA1(port)              (ushort)inpw((port)+IOP_REG_DA1)
1884 #define AscWriteChipDA1(port)             outpw((port)+IOP_REG_DA1, data)
1885 #define AscReadChipDC0(port)              (ushort)inpw((port)+IOP_REG_DC0)
1886 #define AscWriteChipDC0(port)             outpw((port)+IOP_REG_DC0, data)
1887 #define AscReadChipDC1(port)              (ushort)inpw((port)+IOP_REG_DC1)
1888 #define AscWriteChipDC1(port)             outpw((port)+IOP_REG_DC1, data)
1889 #define AscReadChipDvcID(port)            (uchar)inp((port)+IOP_REG_ID)
1890 #define AscWriteChipDvcID(port, data)     outp((port)+IOP_REG_ID, data)
1891
1892 STATIC int       AscWriteEEPCmdReg(PortAddr iop_base, uchar cmd_reg);
1893 STATIC int       AscWriteEEPDataReg(PortAddr iop_base, ushort data_reg);
1894 STATIC void      AscWaitEEPRead(void);
1895 STATIC void      AscWaitEEPWrite(void);
1896 STATIC ushort    AscReadEEPWord(PortAddr, uchar);
1897 STATIC ushort    AscWriteEEPWord(PortAddr, uchar, ushort);
1898 STATIC ushort    AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1899 STATIC int       AscSetEEPConfigOnce(PortAddr, ASCEEP_CONFIG *, ushort);
1900 STATIC int       AscSetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
1901 STATIC int       AscStartChip(PortAddr);
1902 STATIC int       AscStopChip(PortAddr);
1903 STATIC void      AscSetChipIH(PortAddr, ushort);
1904 STATIC int       AscIsChipHalted(PortAddr);
1905 STATIC void      AscAckInterrupt(PortAddr);
1906 STATIC void      AscDisableInterrupt(PortAddr);
1907 STATIC void      AscEnableInterrupt(PortAddr);
1908 STATIC void      AscSetBank(PortAddr, uchar);
1909 STATIC int       AscResetChipAndScsiBus(ASC_DVC_VAR *);
1910 #ifdef CONFIG_ISA
1911 STATIC ushort    AscGetIsaDmaChannel(PortAddr);
1912 STATIC ushort    AscSetIsaDmaChannel(PortAddr, ushort);
1913 STATIC uchar     AscSetIsaDmaSpeed(PortAddr, uchar);
1914 STATIC uchar     AscGetIsaDmaSpeed(PortAddr);
1915 #endif /* CONFIG_ISA */
1916 STATIC uchar     AscReadLramByte(PortAddr, ushort);
1917 STATIC ushort    AscReadLramWord(PortAddr, ushort);
1918 #if CC_VERY_LONG_SG_LIST
1919 STATIC ASC_DCNT  AscReadLramDWord(PortAddr, ushort);
1920 #endif /* CC_VERY_LONG_SG_LIST */
1921 STATIC void      AscWriteLramWord(PortAddr, ushort, ushort);
1922 STATIC void      AscWriteLramByte(PortAddr, ushort, uchar);
1923 STATIC ASC_DCNT  AscMemSumLramWord(PortAddr, ushort, int);
1924 STATIC void      AscMemWordSetLram(PortAddr, ushort, ushort, int);
1925 STATIC void      AscMemWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1926 STATIC void      AscMemDWordCopyPtrToLram(PortAddr, ushort, uchar *, int);
1927 STATIC void      AscMemWordCopyPtrFromLram(PortAddr, ushort, uchar *, int);
1928 STATIC ushort    AscInitAscDvcVar(ASC_DVC_VAR *);
1929 STATIC ushort    AscInitFromEEP(ASC_DVC_VAR *);
1930 STATIC ushort    AscInitFromAscDvcVar(ASC_DVC_VAR *);
1931 STATIC ushort    AscInitMicroCodeVar(ASC_DVC_VAR *);
1932 STATIC int       AscTestExternalLram(ASC_DVC_VAR *);
1933 STATIC uchar     AscMsgOutSDTR(ASC_DVC_VAR *, uchar, uchar);
1934 STATIC uchar     AscCalSDTRData(ASC_DVC_VAR *, uchar, uchar);
1935 STATIC void      AscSetChipSDTR(PortAddr, uchar, uchar);
1936 STATIC uchar     AscGetSynPeriodIndex(ASC_DVC_VAR *, uchar);
1937 STATIC uchar     AscAllocFreeQueue(PortAddr, uchar);
1938 STATIC uchar     AscAllocMultipleFreeQueue(PortAddr, uchar, uchar);
1939 STATIC int       AscHostReqRiscHalt(PortAddr);
1940 STATIC int       AscStopQueueExe(PortAddr);
1941 STATIC int       AscSendScsiQueue(ASC_DVC_VAR *,
1942                     ASC_SCSI_Q * scsiq,
1943                     uchar n_q_required);
1944 STATIC int       AscPutReadyQueue(ASC_DVC_VAR *,
1945                     ASC_SCSI_Q *, uchar);
1946 STATIC int       AscPutReadySgListQueue(ASC_DVC_VAR *,
1947                     ASC_SCSI_Q *, uchar);
1948 STATIC int       AscSetChipSynRegAtID(PortAddr, uchar, uchar);
1949 STATIC int       AscSetRunChipSynRegAtID(PortAddr, uchar, uchar);
1950 STATIC ushort    AscInitLram(ASC_DVC_VAR *);
1951 STATIC ushort    AscInitQLinkVar(ASC_DVC_VAR *);
1952 STATIC int       AscSetLibErrorCode(ASC_DVC_VAR *, ushort);
1953 STATIC int       AscIsrChipHalted(ASC_DVC_VAR *);
1954 STATIC uchar     _AscCopyLramScsiDoneQ(PortAddr, ushort,
1955                     ASC_QDONE_INFO *, ASC_DCNT);
1956 STATIC int       AscIsrQDone(ASC_DVC_VAR *);
1957 STATIC int       AscCompareString(uchar *, uchar *, int);
1958 #ifdef CONFIG_ISA
1959 STATIC ushort    AscGetEisaChipCfg(PortAddr);
1960 STATIC ASC_DCNT  AscGetEisaProductID(PortAddr);
1961 STATIC PortAddr  AscSearchIOPortAddrEISA(PortAddr);
1962 STATIC PortAddr  AscSearchIOPortAddr11(PortAddr);
1963 STATIC PortAddr  AscSearchIOPortAddr(PortAddr, ushort);
1964 STATIC void      AscSetISAPNPWaitForKey(void);
1965 #endif /* CONFIG_ISA */
1966 STATIC uchar     AscGetChipScsiCtrl(PortAddr);
1967 STATIC uchar     AscSetChipScsiID(PortAddr, uchar);
1968 STATIC uchar     AscGetChipVersion(PortAddr, ushort);
1969 STATIC ushort    AscGetChipBusType(PortAddr);
1970 STATIC ASC_DCNT  AscLoadMicroCode(PortAddr, ushort, uchar *, ushort);
1971 STATIC int       AscFindSignature(PortAddr);
1972 STATIC void      AscToggleIRQAct(PortAddr);
1973 STATIC uchar     AscGetChipIRQ(PortAddr, ushort);
1974 STATIC uchar     AscSetChipIRQ(PortAddr, uchar, ushort);
1975 STATIC ushort    AscGetChipBiosAddress(PortAddr, ushort);
1976 STATIC inline ulong DvcEnterCritical(void);
1977 STATIC inline void DvcLeaveCritical(ulong);
1978 #ifdef CONFIG_PCI
1979 STATIC uchar     DvcReadPCIConfigByte(ASC_DVC_VAR *, ushort);
1980 STATIC void      DvcWritePCIConfigByte(ASC_DVC_VAR *,
1981                     ushort, uchar);
1982 #endif /* CONFIG_PCI */
1983 STATIC ushort      AscGetChipBiosAddress(PortAddr, ushort);
1984 STATIC void      DvcSleepMilliSecond(ASC_DCNT);
1985 STATIC void      DvcDelayNanoSecond(ASC_DVC_VAR *, ASC_DCNT);
1986 STATIC void      DvcPutScsiQ(PortAddr, ushort, uchar *, int);
1987 STATIC void      DvcGetQinfo(PortAddr, ushort, uchar *, int);
1988 STATIC ushort    AscInitGetConfig(ASC_DVC_VAR *);
1989 STATIC ushort    AscInitSetConfig(ASC_DVC_VAR *);
1990 STATIC ushort    AscInitAsc1000Driver(ASC_DVC_VAR *);
1991 STATIC void      AscAsyncFix(ASC_DVC_VAR *, uchar,
1992                     ASC_SCSI_INQUIRY *);
1993 STATIC int       AscTagQueuingSafe(ASC_SCSI_INQUIRY *);
1994 STATIC void      AscInquiryHandling(ASC_DVC_VAR *,
1995                     uchar, ASC_SCSI_INQUIRY *);
1996 STATIC int       AscExeScsiQueue(ASC_DVC_VAR *, ASC_SCSI_Q *);
1997 STATIC int       AscISR(ASC_DVC_VAR *);
1998 STATIC uint      AscGetNumOfFreeQueue(ASC_DVC_VAR *, uchar,
1999                     uchar);
2000 STATIC int       AscSgListToQueue(int);
2001 #ifdef CONFIG_ISA
2002 STATIC void      AscEnableIsaDma(uchar);
2003 #endif /* CONFIG_ISA */
2004 STATIC ASC_DCNT  AscGetMaxDmaCount(ushort);
2005
2006
2007 /*
2008  * --- Adv Library Constants and Macros
2009  */
2010
2011 #define ADV_LIB_VERSION_MAJOR  5
2012 #define ADV_LIB_VERSION_MINOR  14
2013
2014 /* d_os_dep.h */
2015 #define ADV_OS_LINUX
2016
2017 /*
2018  * Define Adv Library required special types.
2019  */
2020
2021 /*
2022  * Portable Data Types
2023  *
2024  * Any instance where a 32-bit long or pointer type is assumed
2025  * for precision or HW defined structures, the following define
2026  * types must be used. In Linux the char, short, and int types
2027  * are all consistent at 8, 16, and 32 bits respectively. Pointers
2028  * and long types are 64 bits on Alpha and UltraSPARC.
2029  */
2030 #define ADV_PADDR __u32         /* Physical address data type. */
2031 #define ADV_VADDR __u32         /* Virtual address data type. */
2032 #define ADV_DCNT  __u32         /* Unsigned Data count type. */
2033 #define ADV_SDCNT __s32         /* Signed Data count type. */
2034
2035 /*
2036  * These macros are used to convert a virtual address to a
2037  * 32-bit value. This currently can be used on Linux Alpha
2038  * which uses 64-bit virtual address but a 32-bit bus address.
2039  * This is likely to break in the future, but doing this now
2040  * will give us time to change the HW and FW to handle 64-bit
2041  * addresses.
2042  */
2043 #define ADV_VADDR_TO_U32   virt_to_bus
2044 #define ADV_U32_TO_VADDR   bus_to_virt
2045
2046 #define AdvPortAddr  ulong              /* Virtual memory address size */
2047
2048 /*
2049  * Define Adv Library required memory access macros.
2050  */
2051 #define ADV_MEM_READB(addr) readb(addr)
2052 #define ADV_MEM_READW(addr) readw(addr)
2053 #define ADV_MEM_WRITEB(addr, byte) writeb(byte, addr)
2054 #define ADV_MEM_WRITEW(addr, word) writew(word, addr)
2055 #define ADV_MEM_WRITEDW(addr, dword) writel(dword, addr)
2056
2057 #define ADV_CARRIER_COUNT (ASC_DEF_MAX_HOST_QNG + 15)
2058
2059 /*
2060  * For wide  boards a CDB length maximum of 16 bytes
2061  * is supported.
2062  */
2063 #define ADV_MAX_CDB_LEN     16
2064
2065 /*
2066  * Define total number of simultaneous maximum element scatter-gather
2067  * request blocks per wide adapter. ASC_DEF_MAX_HOST_QNG (253) is the
2068  * maximum number of outstanding commands per wide host adapter. Each
2069  * command uses one or more ADV_SG_BLOCK each with 15 scatter-gather
2070  * elements. Allow each command to have at least one ADV_SG_BLOCK structure.
2071  * This allows about 15 commands to have the maximum 17 ADV_SG_BLOCK
2072  * structures or 255 scatter-gather elements.
2073  *
2074  */
2075 #define ADV_TOT_SG_BLOCK        ASC_DEF_MAX_HOST_QNG
2076
2077 /*
2078  * Define Adv Library required maximum number of scatter-gather
2079  * elements per request.
2080  */
2081 #define ADV_MAX_SG_LIST         255
2082
2083 /* Number of SG blocks needed. */
2084 #define ADV_NUM_SG_BLOCK \
2085     ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK)
2086
2087 /* Total contiguous memory needed for SG blocks. */
2088 #define ADV_SG_TOTAL_MEM_SIZE \
2089     (sizeof(ADV_SG_BLOCK) *  ADV_NUM_SG_BLOCK)
2090
2091 #define ADV_PAGE_SIZE PAGE_SIZE
2092
2093 #define ADV_NUM_PAGE_CROSSING \
2094     ((ADV_SG_TOTAL_MEM_SIZE + (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2095
2096 /* a_condor.h */
2097 #define ADV_PCI_VENDOR_ID               0x10CD
2098 #define ADV_PCI_DEVICE_ID_REV_A         0x2300
2099 #define ADV_PCI_DEVID_38C0800_REV1      0x2500
2100 #define ADV_PCI_DEVID_38C1600_REV1      0x2700
2101
2102 #define ADV_EEP_DVC_CFG_BEGIN           (0x00)
2103 #define ADV_EEP_DVC_CFG_END             (0x15)
2104 #define ADV_EEP_DVC_CTL_BEGIN           (0x16)  /* location of OEM name */
2105 #define ADV_EEP_MAX_WORD_ADDR           (0x1E)
2106
2107 #define ADV_EEP_DELAY_MS                100
2108
2109 #define ADV_EEPROM_BIG_ENDIAN          0x8000   /* EEPROM Bit 15 */
2110 #define ADV_EEPROM_BIOS_ENABLE         0x4000   /* EEPROM Bit 14 */
2111 /*
2112  * For the ASC3550 Bit 13 is Termination Polarity control bit.
2113  * For later ICs Bit 13 controls whether the CIS (Card Information
2114  * Service Section) is loaded from EEPROM.
2115  */
2116 #define ADV_EEPROM_TERM_POL            0x2000   /* EEPROM Bit 13 */
2117 #define ADV_EEPROM_CIS_LD              0x2000   /* EEPROM Bit 13 */
2118 /*
2119  * ASC38C1600 Bit 11
2120  *
2121  * If EEPROM Bit 11 is 0 for Function 0, then Function 0 will specify
2122  * INT A in the PCI Configuration Space Int Pin field. If it is 1, then
2123  * Function 0 will specify INT B.
2124  *
2125  * If EEPROM Bit 11 is 0 for Function 1, then Function 1 will specify
2126  * INT B in the PCI Configuration Space Int Pin field. If it is 1, then
2127  * Function 1 will specify INT A.
2128  */
2129 #define ADV_EEPROM_INTAB               0x0800   /* EEPROM Bit 11 */
2130
2131 typedef struct adveep_3550_config
2132 {
2133                                 /* Word Offset, Description */
2134
2135   ushort cfg_lsw;               /* 00 power up initialization */
2136                                 /*  bit 13 set - Term Polarity Control */
2137                                 /*  bit 14 set - BIOS Enable */
2138                                 /*  bit 15 set - Big Endian Mode */
2139   ushort cfg_msw;               /* 01 unused      */
2140   ushort disc_enable;           /* 02 disconnect enable */
2141   ushort wdtr_able;             /* 03 Wide DTR able */
2142   ushort sdtr_able;             /* 04 Synchronous DTR able */
2143   ushort start_motor;           /* 05 send start up motor */
2144   ushort tagqng_able;           /* 06 tag queuing able */
2145   ushort bios_scan;             /* 07 BIOS device control */
2146   ushort scam_tolerant;         /* 08 no scam */
2147
2148   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2149   uchar  bios_boot_delay;       /*    power up wait */
2150
2151   uchar  scsi_reset_delay;      /* 10 reset delay */
2152   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2153                                 /*    high nibble is lun */
2154                                 /*    low nibble is scsi id */
2155
2156   uchar  termination;           /* 11 0 - automatic */
2157                                 /*    1 - low off / high off */
2158                                 /*    2 - low off / high on */
2159                                 /*    3 - low on  / high on */
2160                                 /*    There is no low on  / high off */
2161
2162   uchar  reserved1;             /*    reserved byte (not used) */
2163
2164   ushort bios_ctrl;             /* 12 BIOS control bits */
2165                                 /*  bit 0  BIOS don't act as initiator. */
2166                                 /*  bit 1  BIOS > 1 GB support */
2167                                 /*  bit 2  BIOS > 2 Disk Support */
2168                                 /*  bit 3  BIOS don't support removables */
2169                                 /*  bit 4  BIOS support bootable CD */
2170                                 /*  bit 5  BIOS scan enabled */
2171                                 /*  bit 6  BIOS support multiple LUNs */
2172                                 /*  bit 7  BIOS display of message */
2173                                 /*  bit 8  SCAM disabled */
2174                                 /*  bit 9  Reset SCSI bus during init. */
2175                                 /*  bit 10 */
2176                                 /*  bit 11 No verbose initialization. */
2177                                 /*  bit 12 SCSI parity enabled */
2178                                 /*  bit 13 */
2179                                 /*  bit 14 */
2180                                 /*  bit 15 */
2181   ushort  ultra_able;           /* 13 ULTRA speed able */
2182   ushort  reserved2;            /* 14 reserved */
2183   uchar   max_host_qng;         /* 15 maximum host queuing */
2184   uchar   max_dvc_qng;          /*    maximum per device queuing */
2185   ushort  dvc_cntl;             /* 16 control bit for driver */
2186   ushort  bug_fix;              /* 17 control bit for bug fix */
2187   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2188   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2189   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2190   ushort  check_sum;            /* 21 EEP check sum */
2191   uchar   oem_name[16];         /* 22 OEM name */
2192   ushort  dvc_err_code;         /* 30 last device driver error code */
2193   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2194   ushort  adv_err_addr;         /* 32 last uc error address */
2195   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2196   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2197   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2198   ushort  num_of_err;           /* 36 number of error */
2199 } ADVEEP_3550_CONFIG;
2200
2201 typedef struct adveep_38C0800_config
2202 {
2203                                 /* Word Offset, Description */
2204
2205   ushort cfg_lsw;               /* 00 power up initialization */
2206                                 /*  bit 13 set - Load CIS */
2207                                 /*  bit 14 set - BIOS Enable */
2208                                 /*  bit 15 set - Big Endian Mode */
2209   ushort cfg_msw;               /* 01 unused      */
2210   ushort disc_enable;           /* 02 disconnect enable */
2211   ushort wdtr_able;             /* 03 Wide DTR able */
2212   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2213   ushort start_motor;           /* 05 send start up motor */
2214   ushort tagqng_able;           /* 06 tag queuing able */
2215   ushort bios_scan;             /* 07 BIOS device control */
2216   ushort scam_tolerant;         /* 08 no scam */
2217
2218   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2219   uchar  bios_boot_delay;       /*    power up wait */
2220
2221   uchar  scsi_reset_delay;      /* 10 reset delay */
2222   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2223                                 /*    high nibble is lun */
2224                                 /*    low nibble is scsi id */
2225
2226   uchar  termination_se;        /* 11 0 - automatic */
2227                                 /*    1 - low off / high off */
2228                                 /*    2 - low off / high on */
2229                                 /*    3 - low on  / high on */
2230                                 /*    There is no low on  / high off */
2231
2232   uchar  termination_lvd;       /* 11 0 - automatic */
2233                                 /*    1 - low off / high off */
2234                                 /*    2 - low off / high on */
2235                                 /*    3 - low on  / high on */
2236                                 /*    There is no low on  / high off */
2237
2238   ushort bios_ctrl;             /* 12 BIOS control bits */
2239                                 /*  bit 0  BIOS don't act as initiator. */
2240                                 /*  bit 1  BIOS > 1 GB support */
2241                                 /*  bit 2  BIOS > 2 Disk Support */
2242                                 /*  bit 3  BIOS don't support removables */
2243                                 /*  bit 4  BIOS support bootable CD */
2244                                 /*  bit 5  BIOS scan enabled */
2245                                 /*  bit 6  BIOS support multiple LUNs */
2246                                 /*  bit 7  BIOS display of message */
2247                                 /*  bit 8  SCAM disabled */
2248                                 /*  bit 9  Reset SCSI bus during init. */
2249                                 /*  bit 10 */
2250                                 /*  bit 11 No verbose initialization. */
2251                                 /*  bit 12 SCSI parity enabled */
2252                                 /*  bit 13 */
2253                                 /*  bit 14 */
2254                                 /*  bit 15 */
2255   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2256   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2257   uchar   max_host_qng;         /* 15 maximum host queueing */
2258   uchar   max_dvc_qng;          /*    maximum per device queuing */
2259   ushort  dvc_cntl;             /* 16 control bit for driver */
2260   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2261   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2262   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2263   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2264   ushort  check_sum;            /* 21 EEP check sum */
2265   uchar   oem_name[16];         /* 22 OEM name */
2266   ushort  dvc_err_code;         /* 30 last device driver error code */
2267   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2268   ushort  adv_err_addr;         /* 32 last uc error address */
2269   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2270   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2271   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2272   ushort  reserved36;           /* 36 reserved */
2273   ushort  reserved37;           /* 37 reserved */
2274   ushort  reserved38;           /* 38 reserved */
2275   ushort  reserved39;           /* 39 reserved */
2276   ushort  reserved40;           /* 40 reserved */
2277   ushort  reserved41;           /* 41 reserved */
2278   ushort  reserved42;           /* 42 reserved */
2279   ushort  reserved43;           /* 43 reserved */
2280   ushort  reserved44;           /* 44 reserved */
2281   ushort  reserved45;           /* 45 reserved */
2282   ushort  reserved46;           /* 46 reserved */
2283   ushort  reserved47;           /* 47 reserved */
2284   ushort  reserved48;           /* 48 reserved */
2285   ushort  reserved49;           /* 49 reserved */
2286   ushort  reserved50;           /* 50 reserved */
2287   ushort  reserved51;           /* 51 reserved */
2288   ushort  reserved52;           /* 52 reserved */
2289   ushort  reserved53;           /* 53 reserved */
2290   ushort  reserved54;           /* 54 reserved */
2291   ushort  reserved55;           /* 55 reserved */
2292   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2293   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2294   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2295   ushort  subsysid;             /* 59 SubSystem ID */
2296   ushort  reserved60;           /* 60 reserved */
2297   ushort  reserved61;           /* 61 reserved */
2298   ushort  reserved62;           /* 62 reserved */
2299   ushort  reserved63;           /* 63 reserved */
2300 } ADVEEP_38C0800_CONFIG;
2301
2302 typedef struct adveep_38C1600_config
2303 {
2304                                 /* Word Offset, Description */
2305
2306   ushort cfg_lsw;               /* 00 power up initialization */
2307                                 /*  bit 11 set - Func. 0 INTB, Func. 1 INTA */
2308                                 /*       clear - Func. 0 INTA, Func. 1 INTB */
2309                                 /*  bit 13 set - Load CIS */
2310                                 /*  bit 14 set - BIOS Enable */
2311                                 /*  bit 15 set - Big Endian Mode */
2312   ushort cfg_msw;               /* 01 unused */
2313   ushort disc_enable;           /* 02 disconnect enable */
2314   ushort wdtr_able;             /* 03 Wide DTR able */
2315   ushort sdtr_speed1;           /* 04 SDTR Speed TID 0-3 */
2316   ushort start_motor;           /* 05 send start up motor */
2317   ushort tagqng_able;           /* 06 tag queuing able */
2318   ushort bios_scan;             /* 07 BIOS device control */
2319   ushort scam_tolerant;         /* 08 no scam */
2320
2321   uchar  adapter_scsi_id;       /* 09 Host Adapter ID */
2322   uchar  bios_boot_delay;       /*    power up wait */
2323
2324   uchar  scsi_reset_delay;      /* 10 reset delay */
2325   uchar  bios_id_lun;           /*    first boot device scsi id & lun */
2326                                 /*    high nibble is lun */
2327                                 /*    low nibble is scsi id */
2328
2329   uchar  termination_se;        /* 11 0 - automatic */
2330                                 /*    1 - low off / high off */
2331                                 /*    2 - low off / high on */
2332                                 /*    3 - low on  / high on */
2333                                 /*    There is no low on  / high off */
2334
2335   uchar  termination_lvd;       /* 11 0 - automatic */
2336                                 /*    1 - low off / high off */
2337                                 /*    2 - low off / high on */
2338                                 /*    3 - low on  / high on */
2339                                 /*    There is no low on  / high off */
2340
2341   ushort bios_ctrl;             /* 12 BIOS control bits */
2342                                 /*  bit 0  BIOS don't act as initiator. */
2343                                 /*  bit 1  BIOS > 1 GB support */
2344                                 /*  bit 2  BIOS > 2 Disk Support */
2345                                 /*  bit 3  BIOS don't support removables */
2346                                 /*  bit 4  BIOS support bootable CD */
2347                                 /*  bit 5  BIOS scan enabled */
2348                                 /*  bit 6  BIOS support multiple LUNs */
2349                                 /*  bit 7  BIOS display of message */
2350                                 /*  bit 8  SCAM disabled */
2351                                 /*  bit 9  Reset SCSI bus during init. */
2352                                 /*  bit 10 Basic Integrity Checking disabled */
2353                                 /*  bit 11 No verbose initialization. */
2354                                 /*  bit 12 SCSI parity enabled */
2355                                 /*  bit 13 AIPP (Asyn. Info. Ph. Prot.) dis. */
2356                                 /*  bit 14 */
2357                                 /*  bit 15 */
2358   ushort  sdtr_speed2;          /* 13 SDTR speed TID 4-7 */
2359   ushort  sdtr_speed3;          /* 14 SDTR speed TID 8-11 */
2360   uchar   max_host_qng;         /* 15 maximum host queueing */
2361   uchar   max_dvc_qng;          /*    maximum per device queuing */
2362   ushort  dvc_cntl;             /* 16 control bit for driver */
2363   ushort  sdtr_speed4;          /* 17 SDTR speed 4 TID 12-15 */
2364   ushort  serial_number_word1;  /* 18 Board serial number word 1 */
2365   ushort  serial_number_word2;  /* 19 Board serial number word 2 */
2366   ushort  serial_number_word3;  /* 20 Board serial number word 3 */
2367   ushort  check_sum;            /* 21 EEP check sum */
2368   uchar   oem_name[16];         /* 22 OEM name */
2369   ushort  dvc_err_code;         /* 30 last device driver error code */
2370   ushort  adv_err_code;         /* 31 last uc and Adv Lib error code */
2371   ushort  adv_err_addr;         /* 32 last uc error address */
2372   ushort  saved_dvc_err_code;   /* 33 saved last dev. driver error code   */
2373   ushort  saved_adv_err_code;   /* 34 saved last uc and Adv Lib error code */
2374   ushort  saved_adv_err_addr;   /* 35 saved last uc error address         */
2375   ushort  reserved36;           /* 36 reserved */
2376   ushort  reserved37;           /* 37 reserved */
2377   ushort  reserved38;           /* 38 reserved */
2378   ushort  reserved39;           /* 39 reserved */
2379   ushort  reserved40;           /* 40 reserved */
2380   ushort  reserved41;           /* 41 reserved */
2381   ushort  reserved42;           /* 42 reserved */
2382   ushort  reserved43;           /* 43 reserved */
2383   ushort  reserved44;           /* 44 reserved */
2384   ushort  reserved45;           /* 45 reserved */
2385   ushort  reserved46;           /* 46 reserved */
2386   ushort  reserved47;           /* 47 reserved */
2387   ushort  reserved48;           /* 48 reserved */
2388   ushort  reserved49;           /* 49 reserved */
2389   ushort  reserved50;           /* 50 reserved */
2390   ushort  reserved51;           /* 51 reserved */
2391   ushort  reserved52;           /* 52 reserved */
2392   ushort  reserved53;           /* 53 reserved */
2393   ushort  reserved54;           /* 54 reserved */
2394   ushort  reserved55;           /* 55 reserved */
2395   ushort  cisptr_lsw;           /* 56 CIS PTR LSW */
2396   ushort  cisprt_msw;           /* 57 CIS PTR MSW */
2397   ushort  subsysvid;            /* 58 SubSystem Vendor ID */
2398   ushort  subsysid;             /* 59 SubSystem ID */
2399   ushort  reserved60;           /* 60 reserved */
2400   ushort  reserved61;           /* 61 reserved */
2401   ushort  reserved62;           /* 62 reserved */
2402   ushort  reserved63;           /* 63 reserved */
2403 } ADVEEP_38C1600_CONFIG;
2404
2405 /*
2406  * EEPROM Commands
2407  */
2408 #define ASC_EEP_CMD_DONE             0x0200
2409 #define ASC_EEP_CMD_DONE_ERR         0x0001
2410
2411 /* cfg_word */
2412 #define EEP_CFG_WORD_BIG_ENDIAN      0x8000
2413
2414 /* bios_ctrl */
2415 #define BIOS_CTRL_BIOS               0x0001
2416 #define BIOS_CTRL_EXTENDED_XLAT      0x0002
2417 #define BIOS_CTRL_GT_2_DISK          0x0004
2418 #define BIOS_CTRL_BIOS_REMOVABLE     0x0008
2419 #define BIOS_CTRL_BOOTABLE_CD        0x0010
2420 #define BIOS_CTRL_MULTIPLE_LUN       0x0040
2421 #define BIOS_CTRL_DISPLAY_MSG        0x0080
2422 #define BIOS_CTRL_NO_SCAM            0x0100
2423 #define BIOS_CTRL_RESET_SCSI_BUS     0x0200
2424 #define BIOS_CTRL_INIT_VERBOSE       0x0800
2425 #define BIOS_CTRL_SCSI_PARITY        0x1000
2426 #define BIOS_CTRL_AIPP_DIS           0x2000
2427
2428 #define ADV_3550_MEMSIZE   0x2000       /* 8 KB Internal Memory */
2429 #define ADV_3550_IOLEN     0x40         /* I/O Port Range in bytes */
2430
2431 #define ADV_38C0800_MEMSIZE  0x4000     /* 16 KB Internal Memory */
2432 #define ADV_38C0800_IOLEN    0x100      /* I/O Port Range in bytes */
2433
2434 /*
2435  * XXX - Since ASC38C1600 Rev.3 has a local RAM failure issue, there is
2436  * a special 16K Adv Library and Microcode version. After the issue is
2437  * resolved, should restore 32K support.
2438  *
2439  * #define ADV_38C1600_MEMSIZE  0x8000L   * 32 KB Internal Memory *
2440  */
2441 #define ADV_38C1600_MEMSIZE  0x4000   /* 16 KB Internal Memory */
2442 #define ADV_38C1600_IOLEN    0x100     /* I/O Port Range 256 bytes */
2443 #define ADV_38C1600_MEMLEN   0x1000    /* Memory Range 4KB bytes */
2444
2445 /*
2446  * Byte I/O register address from base of 'iop_base'.
2447  */
2448 #define IOPB_INTR_STATUS_REG    0x00
2449 #define IOPB_CHIP_ID_1          0x01
2450 #define IOPB_INTR_ENABLES       0x02
2451 #define IOPB_CHIP_TYPE_REV      0x03
2452 #define IOPB_RES_ADDR_4         0x04
2453 #define IOPB_RES_ADDR_5         0x05
2454 #define IOPB_RAM_DATA           0x06
2455 #define IOPB_RES_ADDR_7         0x07
2456 #define IOPB_FLAG_REG           0x08
2457 #define IOPB_RES_ADDR_9         0x09
2458 #define IOPB_RISC_CSR           0x0A
2459 #define IOPB_RES_ADDR_B         0x0B
2460 #define IOPB_RES_ADDR_C         0x0C
2461 #define IOPB_RES_ADDR_D         0x0D
2462 #define IOPB_SOFT_OVER_WR       0x0E
2463 #define IOPB_RES_ADDR_F         0x0F
2464 #define IOPB_MEM_CFG            0x10
2465 #define IOPB_RES_ADDR_11        0x11
2466 #define IOPB_GPIO_DATA          0x12
2467 #define IOPB_RES_ADDR_13        0x13
2468 #define IOPB_FLASH_PAGE         0x14
2469 #define IOPB_RES_ADDR_15        0x15
2470 #define IOPB_GPIO_CNTL          0x16
2471 #define IOPB_RES_ADDR_17        0x17
2472 #define IOPB_FLASH_DATA         0x18
2473 #define IOPB_RES_ADDR_19        0x19
2474 #define IOPB_RES_ADDR_1A        0x1A
2475 #define IOPB_RES_ADDR_1B        0x1B
2476 #define IOPB_RES_ADDR_1C        0x1C
2477 #define IOPB_RES_ADDR_1D        0x1D
2478 #define IOPB_RES_ADDR_1E        0x1E
2479 #define IOPB_RES_ADDR_1F        0x1F
2480 #define IOPB_DMA_CFG0           0x20
2481 #define IOPB_DMA_CFG1           0x21
2482 #define IOPB_TICKLE             0x22
2483 #define IOPB_DMA_REG_WR         0x23
2484 #define IOPB_SDMA_STATUS        0x24
2485 #define IOPB_SCSI_BYTE_CNT      0x25
2486 #define IOPB_HOST_BYTE_CNT      0x26
2487 #define IOPB_BYTE_LEFT_TO_XFER  0x27
2488 #define IOPB_BYTE_TO_XFER_0     0x28
2489 #define IOPB_BYTE_TO_XFER_1     0x29
2490 #define IOPB_BYTE_TO_XFER_2     0x2A
2491 #define IOPB_BYTE_TO_XFER_3     0x2B
2492 #define IOPB_ACC_GRP            0x2C
2493 #define IOPB_RES_ADDR_2D        0x2D
2494 #define IOPB_DEV_ID             0x2E
2495 #define IOPB_RES_ADDR_2F        0x2F
2496 #define IOPB_SCSI_DATA          0x30
2497 #define IOPB_RES_ADDR_31        0x31
2498 #define IOPB_RES_ADDR_32        0x32
2499 #define IOPB_SCSI_DATA_HSHK     0x33
2500 #define IOPB_SCSI_CTRL          0x34
2501 #define IOPB_RES_ADDR_35        0x35
2502 #define IOPB_RES_ADDR_36        0x36
2503 #define IOPB_RES_ADDR_37        0x37
2504 #define IOPB_RAM_BIST           0x38
2505 #define IOPB_PLL_TEST           0x39
2506 #define IOPB_PCI_INT_CFG        0x3A
2507 #define IOPB_RES_ADDR_3B        0x3B
2508 #define IOPB_RFIFO_CNT          0x3C
2509 #define IOPB_RES_ADDR_3D        0x3D
2510 #define IOPB_RES_ADDR_3E        0x3E
2511 #define IOPB_RES_ADDR_3F        0x3F
2512
2513 /*
2514  * Word I/O register address from base of 'iop_base'.
2515  */
2516 #define IOPW_CHIP_ID_0          0x00  /* CID0  */
2517 #define IOPW_CTRL_REG           0x02  /* CC    */
2518 #define IOPW_RAM_ADDR           0x04  /* LA    */
2519 #define IOPW_RAM_DATA           0x06  /* LD    */
2520 #define IOPW_RES_ADDR_08        0x08
2521 #define IOPW_RISC_CSR           0x0A  /* CSR   */
2522 #define IOPW_SCSI_CFG0          0x0C  /* CFG0  */
2523 #define IOPW_SCSI_CFG1          0x0E  /* CFG1  */
2524 #define IOPW_RES_ADDR_10        0x10
2525 #define IOPW_SEL_MASK           0x12  /* SM    */
2526 #define IOPW_RES_ADDR_14        0x14
2527 #define IOPW_FLASH_ADDR         0x16  /* FA    */
2528 #define IOPW_RES_ADDR_18        0x18
2529 #define IOPW_EE_CMD             0x1A  /* EC    */
2530 #define IOPW_EE_DATA            0x1C  /* ED    */
2531 #define IOPW_SFIFO_CNT          0x1E  /* SFC   */
2532 #define IOPW_RES_ADDR_20        0x20
2533 #define IOPW_Q_BASE             0x22  /* QB    */
2534 #define IOPW_QP                 0x24  /* QP    */
2535 #define IOPW_IX                 0x26  /* IX    */
2536 #define IOPW_SP                 0x28  /* SP    */
2537 #define IOPW_PC                 0x2A  /* PC    */
2538 #define IOPW_RES_ADDR_2C        0x2C
2539 #define IOPW_RES_ADDR_2E        0x2E
2540 #define IOPW_SCSI_DATA          0x30  /* SD    */
2541 #define IOPW_SCSI_DATA_HSHK     0x32  /* SDH   */
2542 #define IOPW_SCSI_CTRL          0x34  /* SC    */
2543 #define IOPW_HSHK_CFG           0x36  /* HCFG  */
2544 #define IOPW_SXFR_STATUS        0x36  /* SXS   */
2545 #define IOPW_SXFR_CNTL          0x38  /* SXL   */
2546 #define IOPW_SXFR_CNTH          0x3A  /* SXH   */
2547 #define IOPW_RES_ADDR_3C        0x3C
2548 #define IOPW_RFIFO_DATA         0x3E  /* RFD   */
2549
2550 /*
2551  * Doubleword I/O register address from base of 'iop_base'.
2552  */
2553 #define IOPDW_RES_ADDR_0         0x00
2554 #define IOPDW_RAM_DATA           0x04
2555 #define IOPDW_RES_ADDR_8         0x08
2556 #define IOPDW_RES_ADDR_C         0x0C
2557 #define IOPDW_RES_ADDR_10        0x10
2558 #define IOPDW_COMMA              0x14
2559 #define IOPDW_COMMB              0x18
2560 #define IOPDW_RES_ADDR_1C        0x1C
2561 #define IOPDW_SDMA_ADDR0         0x20
2562 #define IOPDW_SDMA_ADDR1         0x24
2563 #define IOPDW_SDMA_COUNT         0x28
2564 #define IOPDW_SDMA_ERROR         0x2C
2565 #define IOPDW_RDMA_ADDR0         0x30
2566 #define IOPDW_RDMA_ADDR1         0x34
2567 #define IOPDW_RDMA_COUNT         0x38
2568 #define IOPDW_RDMA_ERROR         0x3C
2569
2570 #define ADV_CHIP_ID_BYTE         0x25
2571 #define ADV_CHIP_ID_WORD         0x04C1
2572
2573 #define ADV_SC_SCSI_BUS_RESET    0x2000
2574
2575 #define ADV_INTR_ENABLE_HOST_INTR                   0x01
2576 #define ADV_INTR_ENABLE_SEL_INTR                    0x02
2577 #define ADV_INTR_ENABLE_DPR_INTR                    0x04
2578 #define ADV_INTR_ENABLE_RTA_INTR                    0x08
2579 #define ADV_INTR_ENABLE_RMA_INTR                    0x10
2580 #define ADV_INTR_ENABLE_RST_INTR                    0x20
2581 #define ADV_INTR_ENABLE_DPE_INTR                    0x40
2582 #define ADV_INTR_ENABLE_GLOBAL_INTR                 0x80
2583
2584 #define ADV_INTR_STATUS_INTRA            0x01
2585 #define ADV_INTR_STATUS_INTRB            0x02
2586 #define ADV_INTR_STATUS_INTRC            0x04
2587
2588 #define ADV_RISC_CSR_STOP           (0x0000)
2589 #define ADV_RISC_TEST_COND          (0x2000)
2590 #define ADV_RISC_CSR_RUN            (0x4000)
2591 #define ADV_RISC_CSR_SINGLE_STEP    (0x8000)
2592
2593 #define ADV_CTRL_REG_HOST_INTR      0x0100
2594 #define ADV_CTRL_REG_SEL_INTR       0x0200
2595 #define ADV_CTRL_REG_DPR_INTR       0x0400
2596 #define ADV_CTRL_REG_RTA_INTR       0x0800
2597 #define ADV_CTRL_REG_RMA_INTR       0x1000
2598 #define ADV_CTRL_REG_RES_BIT14      0x2000
2599 #define ADV_CTRL_REG_DPE_INTR       0x4000
2600 #define ADV_CTRL_REG_POWER_DONE     0x8000
2601 #define ADV_CTRL_REG_ANY_INTR       0xFF00
2602
2603 #define ADV_CTRL_REG_CMD_RESET             0x00C6
2604 #define ADV_CTRL_REG_CMD_WR_IO_REG         0x00C5
2605 #define ADV_CTRL_REG_CMD_RD_IO_REG         0x00C4
2606 #define ADV_CTRL_REG_CMD_WR_PCI_CFG_SPACE  0x00C3
2607 #define ADV_CTRL_REG_CMD_RD_PCI_CFG_SPACE  0x00C2
2608
2609 #define ADV_TICKLE_NOP                      0x00
2610 #define ADV_TICKLE_A                        0x01
2611 #define ADV_TICKLE_B                        0x02
2612 #define ADV_TICKLE_C                        0x03
2613
2614 #define ADV_SCSI_CTRL_RSTOUT        0x2000
2615
2616 #define AdvIsIntPending(port) \
2617     (AdvReadWordRegister(port, IOPW_CTRL_REG) & ADV_CTRL_REG_HOST_INTR)
2618
2619 /*
2620  * SCSI_CFG0 Register bit definitions
2621  */
2622 #define TIMER_MODEAB    0xC000  /* Watchdog, Second, and Select. Timer Ctrl. */
2623 #define PARITY_EN       0x2000  /* Enable SCSI Parity Error detection */
2624 #define EVEN_PARITY     0x1000  /* Select Even Parity */
2625 #define WD_LONG         0x0800  /* Watchdog Interval, 1: 57 min, 0: 13 sec */
2626 #define QUEUE_128       0x0400  /* Queue Size, 1: 128 byte, 0: 64 byte */
2627 #define PRIM_MODE       0x0100  /* Primitive SCSI mode */
2628 #define SCAM_EN         0x0080  /* Enable SCAM selection */
2629 #define SEL_TMO_LONG    0x0040  /* Sel/Resel Timeout, 1: 400 ms, 0: 1.6 ms */
2630 #define CFRM_ID         0x0020  /* SCAM id sel. confirm., 1: fast, 0: 6.4 ms */
2631 #define OUR_ID_EN       0x0010  /* Enable OUR_ID bits */
2632 #define OUR_ID          0x000F  /* SCSI ID */
2633
2634 /*
2635  * SCSI_CFG1 Register bit definitions
2636  */
2637 #define BIG_ENDIAN      0x8000  /* Enable Big Endian Mode MIO:15, EEP:15 */
2638 #define TERM_POL        0x2000  /* Terminator Polarity Ctrl. MIO:13, EEP:13 */
2639 #define SLEW_RATE       0x1000  /* SCSI output buffer slew rate */
2640 #define FILTER_SEL      0x0C00  /* Filter Period Selection */
2641 #define  FLTR_DISABLE    0x0000  /* Input Filtering Disabled */
2642 #define  FLTR_11_TO_20NS 0x0800  /* Input Filtering 11ns to 20ns */
2643 #define  FLTR_21_TO_39NS 0x0C00  /* Input Filtering 21ns to 39ns */
2644 #define ACTIVE_DBL      0x0200  /* Disable Active Negation */
2645 #define DIFF_MODE       0x0100  /* SCSI differential Mode (Read-Only) */
2646 #define DIFF_SENSE      0x0080  /* 1: No SE cables, 0: SE cable (Read-Only) */
2647 #define TERM_CTL_SEL    0x0040  /* Enable TERM_CTL_H and TERM_CTL_L */
2648 #define TERM_CTL        0x0030  /* External SCSI Termination Bits */
2649 #define  TERM_CTL_H      0x0020  /* Enable External SCSI Upper Termination */
2650 #define  TERM_CTL_L      0x0010  /* Enable External SCSI Lower Termination */
2651 #define CABLE_DETECT    0x000F  /* External SCSI Cable Connection Status */
2652
2653 /*
2654  * Addendum for ASC-38C0800 Chip
2655  *
2656  * The ASC-38C1600 Chip uses the same definitions except that the
2657  * bus mode override bits [12:10] have been moved to byte register
2658  * offset 0xE (IOPB_SOFT_OVER_WR) bits [12:10]. The [12:10] bits in
2659  * SCSI_CFG1 are read-only and always available. Bit 14 (DIS_TERM_DRV)
2660  * is not needed. The [12:10] bits in IOPB_SOFT_OVER_WR are write-only.
2661  * Also each ASC-38C1600 function or channel uses only cable bits [5:4]
2662  * and [1:0]. Bits [14], [7:6], [3:2] are unused.
2663  */
2664 #define DIS_TERM_DRV    0x4000  /* 1: Read c_det[3:0], 0: cannot read */
2665 #define HVD_LVD_SE      0x1C00  /* Device Detect Bits */
2666 #define  HVD             0x1000  /* HVD Device Detect */
2667 #define  LVD             0x0800  /* LVD Device Detect */
2668 #define  SE              0x0400  /* SE Device Detect */
2669 #define TERM_LVD        0x00C0  /* LVD Termination Bits */
2670 #define  TERM_LVD_HI     0x0080  /* Enable LVD Upper Termination */
2671 #define  TERM_LVD_LO     0x0040  /* Enable LVD Lower Termination */
2672 #define TERM_SE         0x0030  /* SE Termination Bits */
2673 #define  TERM_SE_HI      0x0020  /* Enable SE Upper Termination */
2674 #define  TERM_SE_LO      0x0010  /* Enable SE Lower Termination */
2675 #define C_DET_LVD       0x000C  /* LVD Cable Detect Bits */
2676 #define  C_DET3          0x0008  /* Cable Detect for LVD External Wide */
2677 #define  C_DET2          0x0004  /* Cable Detect for LVD Internal Wide */
2678 #define C_DET_SE        0x0003  /* SE Cable Detect Bits */
2679 #define  C_DET1          0x0002  /* Cable Detect for SE Internal Wide */
2680 #define  C_DET0          0x0001  /* Cable Detect for SE Internal Narrow */
2681
2682
2683 #define CABLE_ILLEGAL_A 0x7
2684     /* x 0 0 0  | on  on | Illegal (all 3 connectors are used) */
2685
2686 #define CABLE_ILLEGAL_B 0xB
2687     /* 0 x 0 0  | on  on | Illegal (all 3 connectors are used) */
2688
2689 /*
2690  * MEM_CFG Register bit definitions
2691  */
2692 #define BIOS_EN         0x40    /* BIOS Enable MIO:14,EEP:14 */
2693 #define FAST_EE_CLK     0x20    /* Diagnostic Bit */
2694 #define RAM_SZ          0x1C    /* Specify size of RAM to RISC */
2695 #define  RAM_SZ_2KB      0x00    /* 2 KB */
2696 #define  RAM_SZ_4KB      0x04    /* 4 KB */
2697 #define  RAM_SZ_8KB      0x08    /* 8 KB */
2698 #define  RAM_SZ_16KB     0x0C    /* 16 KB */
2699 #define  RAM_SZ_32KB     0x10    /* 32 KB */
2700 #define  RAM_SZ_64KB     0x14    /* 64 KB */
2701
2702 /*
2703  * DMA_CFG0 Register bit definitions
2704  *
2705  * This register is only accessible to the host.
2706  */
2707 #define BC_THRESH_ENB   0x80    /* PCI DMA Start Conditions */
2708 #define FIFO_THRESH     0x70    /* PCI DMA FIFO Threshold */
2709 #define  FIFO_THRESH_16B  0x00   /* 16 bytes */
2710 #define  FIFO_THRESH_32B  0x20   /* 32 bytes */
2711 #define  FIFO_THRESH_48B  0x30   /* 48 bytes */
2712 #define  FIFO_THRESH_64B  0x40   /* 64 bytes */
2713 #define  FIFO_THRESH_80B  0x50   /* 80 bytes (default) */
2714 #define  FIFO_THRESH_96B  0x60   /* 96 bytes */
2715 #define  FIFO_THRESH_112B 0x70   /* 112 bytes */
2716 #define START_CTL       0x0C    /* DMA start conditions */
2717 #define  START_CTL_TH    0x00    /* Wait threshold level (default) */
2718 #define  START_CTL_ID    0x04    /* Wait SDMA/SBUS idle */
2719 #define  START_CTL_THID  0x08    /* Wait threshold and SDMA/SBUS idle */
2720 #define  START_CTL_EMFU  0x0C    /* Wait SDMA FIFO empty/full */
2721 #define READ_CMD        0x03    /* Memory Read Method */
2722 #define  READ_CMD_MR     0x00    /* Memory Read */
2723 #define  READ_CMD_MRL    0x02    /* Memory Read Long */
2724 #define  READ_CMD_MRM    0x03    /* Memory Read Multiple (default) */
2725
2726 /*
2727  * ASC-38C0800 RAM BIST Register bit definitions
2728  */
2729 #define RAM_TEST_MODE         0x80
2730 #define PRE_TEST_MODE         0x40
2731 #define NORMAL_MODE           0x00
2732 #define RAM_TEST_DONE         0x10
2733 #define RAM_TEST_STATUS       0x0F
2734 #define  RAM_TEST_HOST_ERROR   0x08
2735 #define  RAM_TEST_INTRAM_ERROR 0x04
2736 #define  RAM_TEST_RISC_ERROR   0x02
2737 #define  RAM_TEST_SCSI_ERROR   0x01
2738 #define  RAM_TEST_SUCCESS      0x00
2739 #define PRE_TEST_VALUE        0x05
2740 #define NORMAL_VALUE          0x00
2741
2742 /*
2743  * ASC38C1600 Definitions
2744  *
2745  * IOPB_PCI_INT_CFG Bit Field Definitions
2746  */
2747
2748 #define INTAB_LD        0x80    /* Value loaded from EEPROM Bit 11. */
2749
2750 /*
2751  * Bit 1 can be set to change the interrupt for the Function to operate in
2752  * Totem Pole mode. By default Bit 1 is 0 and the interrupt operates in
2753  * Open Drain mode. Both functions of the ASC38C1600 must be set to the same
2754  * mode, otherwise the operating mode is undefined.
2755  */
2756 #define TOTEMPOLE       0x02
2757
2758 /*
2759  * Bit 0 can be used to change the Int Pin for the Function. The value is
2760  * 0 by default for both Functions with Function 0 using INT A and Function
2761  * B using INT B. For Function 0 if set, INT B is used. For Function 1 if set,
2762  * INT A is used.
2763  *
2764  * EEPROM Word 0 Bit 11 for each Function may change the initial Int Pin
2765  * value specified in the PCI Configuration Space.
2766  */
2767 #define INTAB           0x01
2768
2769 /* a_advlib.h */
2770
2771 /*
2772  * Adv Library Status Definitions
2773  */
2774 #define ADV_TRUE        1
2775 #define ADV_FALSE       0
2776 #define ADV_NOERROR     1
2777 #define ADV_SUCCESS     1
2778 #define ADV_BUSY        0
2779 #define ADV_ERROR       (-1)
2780
2781
2782 /*
2783  * ADV_DVC_VAR 'warn_code' values
2784  */
2785 #define ASC_WARN_BUSRESET_ERROR         0x0001 /* SCSI Bus Reset error */
2786 #define ASC_WARN_EEPROM_CHKSUM          0x0002 /* EEP check sum error */
2787 #define ASC_WARN_EEPROM_TERMINATION     0x0004 /* EEP termination bad field */
2788 #define ASC_WARN_SET_PCI_CONFIG_SPACE   0x0080 /* PCI config space set error */
2789 #define ASC_WARN_ERROR                  0xFFFF /* ADV_ERROR return */
2790
2791 #define ADV_MAX_TID                     15 /* max. target identifier */
2792 #define ADV_MAX_LUN                     7  /* max. logical unit number */
2793
2794 /*
2795  * Error code values are set in ADV_DVC_VAR 'err_code'.
2796  */
2797 #define ASC_IERR_WRITE_EEPROM       0x0001 /* write EEPROM error */
2798 #define ASC_IERR_MCODE_CHKSUM       0x0002 /* micro code check sum error */
2799 #define ASC_IERR_NO_CARRIER         0x0004 /* No more carrier memory. */
2800 #define ASC_IERR_START_STOP_CHIP    0x0008 /* start/stop chip failed */
2801 #define ASC_IERR_CHIP_VERSION       0x0040 /* wrong chip version */
2802 #define ASC_IERR_SET_SCSI_ID        0x0080 /* set SCSI ID failed */
2803 #define ASC_IERR_HVD_DEVICE         0x0100 /* HVD attached to LVD connector. */
2804 #define ASC_IERR_BAD_SIGNATURE      0x0200 /* signature not found */
2805 #define ASC_IERR_ILLEGAL_CONNECTION 0x0400 /* Illegal cable connection */
2806 #define ASC_IERR_SINGLE_END_DEVICE  0x0800 /* Single-end used w/differential */
2807 #define ASC_IERR_REVERSED_CABLE     0x1000 /* Narrow flat cable reversed */
2808 #define ASC_IERR_BIST_PRE_TEST      0x2000 /* BIST pre-test error */
2809 #define ASC_IERR_BIST_RAM_TEST      0x4000 /* BIST RAM test error */
2810 #define ASC_IERR_BAD_CHIPTYPE       0x8000 /* Invalid 'chip_type' setting. */
2811
2812 /*
2813  * Fixed locations of microcode operating variables.
2814  */
2815 #define ASC_MC_CODE_BEGIN_ADDR          0x0028 /* microcode start address */
2816 #define ASC_MC_CODE_END_ADDR            0x002A /* microcode end address */
2817 #define ASC_MC_CODE_CHK_SUM             0x002C /* microcode code checksum */
2818 #define ASC_MC_VERSION_DATE             0x0038 /* microcode version */
2819 #define ASC_MC_VERSION_NUM              0x003A /* microcode number */
2820 #define ASC_MC_BIOSMEM                  0x0040 /* BIOS RISC Memory Start */
2821 #define ASC_MC_BIOSLEN                  0x0050 /* BIOS RISC Memory Length */
2822 #define ASC_MC_BIOS_SIGNATURE           0x0058 /* BIOS Signature 0x55AA */
2823 #define ASC_MC_BIOS_VERSION             0x005A /* BIOS Version (2 bytes) */
2824 #define ASC_MC_SDTR_SPEED1              0x0090 /* SDTR Speed for TID 0-3 */
2825 #define ASC_MC_SDTR_SPEED2              0x0092 /* SDTR Speed for TID 4-7 */
2826 #define ASC_MC_SDTR_SPEED3              0x0094 /* SDTR Speed for TID 8-11 */
2827 #define ASC_MC_SDTR_SPEED4              0x0096 /* SDTR Speed for TID 12-15 */
2828 #define ASC_MC_CHIP_TYPE                0x009A
2829 #define ASC_MC_INTRB_CODE               0x009B
2830 #define ASC_MC_WDTR_ABLE                0x009C
2831 #define ASC_MC_SDTR_ABLE                0x009E
2832 #define ASC_MC_TAGQNG_ABLE              0x00A0
2833 #define ASC_MC_DISC_ENABLE              0x00A2
2834 #define ASC_MC_IDLE_CMD_STATUS          0x00A4
2835 #define ASC_MC_IDLE_CMD                 0x00A6
2836 #define ASC_MC_IDLE_CMD_PARAMETER       0x00A8
2837 #define ASC_MC_DEFAULT_SCSI_CFG0        0x00AC
2838 #define ASC_MC_DEFAULT_SCSI_CFG1        0x00AE
2839 #define ASC_MC_DEFAULT_MEM_CFG          0x00B0
2840 #define ASC_MC_DEFAULT_SEL_MASK         0x00B2
2841 #define ASC_MC_SDTR_DONE                0x00B6
2842 #define ASC_MC_NUMBER_OF_QUEUED_CMD     0x00C0
2843 #define ASC_MC_NUMBER_OF_MAX_CMD        0x00D0
2844 #define ASC_MC_DEVICE_HSHK_CFG_TABLE    0x0100
2845 #define ASC_MC_CONTROL_FLAG             0x0122 /* Microcode control flag. */
2846 #define ASC_MC_WDTR_DONE                0x0124
2847 #define ASC_MC_CAM_MODE_MASK            0x015E /* CAM mode TID bitmask. */
2848 #define ASC_MC_ICQ                      0x0160
2849 #define ASC_MC_IRQ                      0x0164
2850 #define ASC_MC_PPR_ABLE                 0x017A
2851
2852 /*
2853  * BIOS LRAM variable absolute offsets.
2854  */
2855 #define BIOS_CODESEG    0x54
2856 #define BIOS_CODELEN    0x56
2857 #define BIOS_SIGNATURE  0x58
2858 #define BIOS_VERSION    0x5A
2859
2860 /*
2861  * Microcode Control Flags
2862  *
2863  * Flags set by the Adv Library in RISC variable 'control_flag' (0x122)
2864  * and handled by the microcode.
2865  */
2866 #define CONTROL_FLAG_IGNORE_PERR        0x0001 /* Ignore DMA Parity Errors */
2867 #define CONTROL_FLAG_ENABLE_AIPP        0x0002 /* Enabled AIPP checking. */
2868
2869 /*
2870  * ASC_MC_DEVICE_HSHK_CFG_TABLE microcode table or HSHK_CFG register format
2871  */
2872 #define HSHK_CFG_WIDE_XFR       0x8000
2873 #define HSHK_CFG_RATE           0x0F00
2874 #define HSHK_CFG_OFFSET         0x001F
2875
2876 #define ASC_DEF_MAX_HOST_QNG    0xFD /* Max. number of host commands (253) */
2877 #define ASC_DEF_MIN_HOST_QNG    0x10 /* Min. number of host commands (16) */
2878 #define ASC_DEF_MAX_DVC_QNG     0x3F /* Max. number commands per device (63) */
2879 #define ASC_DEF_MIN_DVC_QNG     0x04 /* Min. number commands per device (4) */
2880
2881 #define ASC_QC_DATA_CHECK  0x01 /* Require ASC_QC_DATA_OUT set or clear. */
2882 #define ASC_QC_DATA_OUT    0x02 /* Data out DMA transfer. */
2883 #define ASC_QC_START_MOTOR 0x04 /* Send auto-start motor before request. */
2884 #define ASC_QC_NO_OVERRUN  0x08 /* Don't report overrun. */
2885 #define ASC_QC_FREEZE_TIDQ 0x10 /* Freeze TID queue after request. XXX TBD */
2886
2887 #define ASC_QSC_NO_DISC     0x01 /* Don't allow disconnect for request. */
2888 #define ASC_QSC_NO_TAGMSG   0x02 /* Don't allow tag queuing for request. */
2889 #define ASC_QSC_NO_SYNC     0x04 /* Don't use Synch. transfer on request. */
2890 #define ASC_QSC_NO_WIDE     0x08 /* Don't use Wide transfer on request. */
2891 #define ASC_QSC_REDO_DTR    0x10 /* Renegotiate WDTR/SDTR before request. */
2892 /*
2893  * Note: If a Tag Message is to be sent and neither ASC_QSC_HEAD_TAG or
2894  * ASC_QSC_ORDERED_TAG is set, then a Simple Tag Message (0x20) is used.
2895  */
2896 #define ASC_QSC_HEAD_TAG    0x40 /* Use Head Tag Message (0x21). */
2897 #define ASC_QSC_ORDERED_TAG 0x80 /* Use Ordered Tag Message (0x22). */
2898
2899 /*
2900  * All fields here are accessed by the board microcode and need to be
2901  * little-endian.
2902  */
2903 typedef struct adv_carr_t
2904 {
2905     ADV_VADDR   carr_va;       /* Carrier Virtual Address */
2906     ADV_PADDR   carr_pa;       /* Carrier Physical Address */
2907     ADV_VADDR   areq_vpa;      /* ASC_SCSI_REQ_Q Virtual or Physical Address */
2908     /*
2909      * next_vpa [31:4]            Carrier Virtual or Physical Next Pointer
2910      *
2911      * next_vpa [3:1]             Reserved Bits
2912      * next_vpa [0]               Done Flag set in Response Queue.
2913      */
2914     ADV_VADDR   next_vpa;
2915 } ADV_CARR_T;
2916
2917 /*
2918  * Mask used to eliminate low 4 bits of carrier 'next_vpa' field.
2919  */
2920 #define ASC_NEXT_VPA_MASK       0xFFFFFFF0
2921
2922 #define ASC_RQ_DONE             0x00000001
2923 #define ASC_RQ_GOOD             0x00000002
2924 #define ASC_CQ_STOPPER          0x00000000
2925
2926 #define ASC_GET_CARRP(carrp) ((carrp) & ASC_NEXT_VPA_MASK)
2927
2928 #define ADV_CARRIER_NUM_PAGE_CROSSING \
2929     (((ADV_CARRIER_COUNT * sizeof(ADV_CARR_T)) + \
2930         (ADV_PAGE_SIZE - 1))/ADV_PAGE_SIZE)
2931
2932 #define ADV_CARRIER_BUFSIZE \
2933     ((ADV_CARRIER_COUNT + ADV_CARRIER_NUM_PAGE_CROSSING) * sizeof(ADV_CARR_T))
2934
2935 /*
2936  * ASC_SCSI_REQ_Q 'a_flag' definitions
2937  *
2938  * The Adv Library should limit use to the lower nibble (4 bits) of
2939  * a_flag. Drivers are free to use the upper nibble (4 bits) of a_flag.
2940  */
2941 #define ADV_POLL_REQUEST                0x01   /* poll for request completion */
2942 #define ADV_SCSIQ_DONE                  0x02   /* request done */
2943 #define ADV_DONT_RETRY                  0x08   /* don't do retry */
2944
2945 #define ADV_CHIP_ASC3550          0x01   /* Ultra-Wide IC */
2946 #define ADV_CHIP_ASC38C0800       0x02   /* Ultra2-Wide/LVD IC */
2947 #define ADV_CHIP_ASC38C1600       0x03   /* Ultra3-Wide/LVD2 IC */
2948
2949 /*
2950  * Adapter temporary configuration structure
2951  *
2952  * This structure can be discarded after initialization. Don't add
2953  * fields here needed after initialization.
2954  *
2955  * Field naming convention:
2956  *
2957  *  *_enable indicates the field enables or disables a feature. The
2958  *  value of the field is never reset.
2959  */
2960 typedef struct adv_dvc_cfg {
2961   ushort disc_enable;       /* enable disconnection */
2962   uchar  chip_version;      /* chip version */
2963   uchar  termination;       /* Term. Ctrl. bits 6-5 of SCSI_CFG1 register */
2964   ushort lib_version;       /* Adv Library version number */
2965   ushort control_flag;      /* Microcode Control Flag */
2966   ushort mcode_date;        /* Microcode date */
2967   ushort mcode_version;     /* Microcode version */
2968   ushort pci_slot_info;     /* high byte device/function number */
2969                             /* bits 7-3 device num., bits 2-0 function num. */
2970                             /* low byte bus num. */
2971   ushort serial1;           /* EEPROM serial number word 1 */
2972   ushort serial2;           /* EEPROM serial number word 2 */
2973   ushort serial3;           /* EEPROM serial number word 3 */
2974   struct device *dev;  /* pointer to the pci dev structure for this board */
2975 } ADV_DVC_CFG;
2976
2977 struct adv_dvc_var;
2978 struct adv_scsi_req_q;
2979
2980 typedef void (* ADV_ISR_CALLBACK)
2981     (struct adv_dvc_var *, struct adv_scsi_req_q *);
2982
2983 typedef void (* ADV_ASYNC_CALLBACK)
2984     (struct adv_dvc_var *, uchar);
2985
2986 /*
2987  * Adapter operation variable structure.
2988  *
2989  * One structure is required per host adapter.
2990  *
2991  * Field naming convention:
2992  *
2993  *  *_able indicates both whether a feature should be enabled or disabled
2994  *  and whether a device isi capable of the feature. At initialization
2995  *  this field may be set, but later if a device is found to be incapable
2996  *  of the feature, the field is cleared.
2997  */
2998 typedef struct adv_dvc_var {
2999   AdvPortAddr iop_base;   /* I/O port address */
3000   ushort err_code;        /* fatal error code */
3001   ushort bios_ctrl;       /* BIOS control word, EEPROM word 12 */
3002   ADV_ISR_CALLBACK isr_callback;
3003   ADV_ASYNC_CALLBACK async_callback;
3004   ushort wdtr_able;       /* try WDTR for a device */
3005   ushort sdtr_able;       /* try SDTR for a device */
3006   ushort ultra_able;      /* try SDTR Ultra speed for a device */
3007   ushort sdtr_speed1;     /* EEPROM SDTR Speed for TID 0-3   */
3008   ushort sdtr_speed2;     /* EEPROM SDTR Speed for TID 4-7   */
3009   ushort sdtr_speed3;     /* EEPROM SDTR Speed for TID 8-11  */
3010   ushort sdtr_speed4;     /* EEPROM SDTR Speed for TID 12-15 */
3011   ushort tagqng_able;     /* try tagged queuing with a device */
3012   ushort ppr_able;        /* PPR message capable per TID bitmask. */
3013   uchar  max_dvc_qng;     /* maximum number of tagged commands per device */
3014   ushort start_motor;     /* start motor command allowed */
3015   uchar  scsi_reset_wait; /* delay in seconds after scsi bus reset */
3016   uchar  chip_no;         /* should be assigned by caller */
3017   uchar  max_host_qng;    /* maximum number of Q'ed command allowed */
3018   uchar  irq_no;          /* IRQ number */
3019   ushort no_scam;         /* scam_tolerant of EEPROM */
3020   struct asc_board *drv_ptr; /* driver pointer to private structure */
3021   uchar  chip_scsi_id;    /* chip SCSI target ID */
3022   uchar  chip_type;
3023   uchar  bist_err_code;
3024   ADV_CARR_T *carrier_buf;
3025   ADV_CARR_T *carr_freelist; /* Carrier free list. */
3026   ADV_CARR_T *icq_sp;  /* Initiator command queue stopper pointer. */
3027   ADV_CARR_T *irq_sp;  /* Initiator response queue stopper pointer. */
3028   ushort carr_pending_cnt;    /* Count of pending carriers. */
3029  /*
3030   * Note: The following fields will not be used after initialization. The
3031   * driver may discard the buffer after initialization is done.
3032   */
3033   ADV_DVC_CFG *cfg; /* temporary configuration structure  */
3034 } ADV_DVC_VAR;
3035
3036 #define NO_OF_SG_PER_BLOCK              15
3037
3038 typedef struct asc_sg_block {
3039     uchar reserved1;
3040     uchar reserved2;
3041     uchar reserved3;
3042     uchar sg_cnt;                     /* Valid entries in block. */
3043     ADV_PADDR sg_ptr;                 /* Pointer to next sg block. */
3044     struct  {
3045         ADV_PADDR sg_addr;                  /* SG element address. */
3046         ADV_DCNT  sg_count;                 /* SG element count. */
3047     } sg_list[NO_OF_SG_PER_BLOCK];
3048 } ADV_SG_BLOCK;
3049
3050 /*
3051  * ADV_SCSI_REQ_Q - microcode request structure
3052  *
3053  * All fields in this structure up to byte 60 are used by the microcode.
3054  * The microcode makes assumptions about the size and ordering of fields
3055  * in this structure. Do not change the structure definition here without
3056  * coordinating the change with the microcode.
3057  *
3058  * All fields accessed by microcode must be maintained in little_endian
3059  * order.
3060  */
3061 typedef struct adv_scsi_req_q {
3062     uchar       cntl;           /* Ucode flags and state (ASC_MC_QC_*). */
3063     uchar       target_cmd;
3064     uchar       target_id;      /* Device target identifier. */
3065     uchar       target_lun;     /* Device target logical unit number. */
3066     ADV_PADDR   data_addr;      /* Data buffer physical address. */
3067     ADV_DCNT    data_cnt;       /* Data count. Ucode sets to residual. */
3068     ADV_PADDR   sense_addr;
3069     ADV_PADDR   carr_pa;
3070     uchar       mflag;
3071     uchar       sense_len;
3072     uchar       cdb_len;        /* SCSI CDB length. Must <= 16 bytes. */
3073     uchar       scsi_cntl;
3074     uchar       done_status;    /* Completion status. */
3075     uchar       scsi_status;    /* SCSI status byte. */
3076     uchar       host_status;    /* Ucode host status. */
3077     uchar       sg_working_ix;
3078     uchar       cdb[12];        /* SCSI CDB bytes 0-11. */
3079     ADV_PADDR   sg_real_addr;   /* SG list physical address. */
3080     ADV_PADDR   scsiq_rptr;
3081     uchar       cdb16[4];       /* SCSI CDB bytes 12-15. */
3082     ADV_VADDR   scsiq_ptr;
3083     ADV_VADDR   carr_va;
3084     /*
3085      * End of microcode structure - 60 bytes. The rest of the structure
3086      * is used by the Adv Library and ignored by the microcode.
3087      */
3088     ADV_VADDR   srb_ptr;
3089     ADV_SG_BLOCK *sg_list_ptr; /* SG list virtual address. */
3090     char        *vdata_addr;   /* Data buffer virtual address. */
3091     uchar       a_flag;
3092     uchar       pad[2];        /* Pad out to a word boundary. */
3093 } ADV_SCSI_REQ_Q;
3094
3095 /*
3096  * Microcode idle loop commands
3097  */
3098 #define IDLE_CMD_COMPLETED           0
3099 #define IDLE_CMD_STOP_CHIP           0x0001
3100 #define IDLE_CMD_STOP_CHIP_SEND_INT  0x0002
3101 #define IDLE_CMD_SEND_INT            0x0004
3102 #define IDLE_CMD_ABORT               0x0008
3103 #define IDLE_CMD_DEVICE_RESET        0x0010
3104 #define IDLE_CMD_SCSI_RESET_START    0x0020 /* Assert SCSI Bus Reset */
3105 #define IDLE_CMD_SCSI_RESET_END      0x0040 /* Deassert SCSI Bus Reset */
3106 #define IDLE_CMD_SCSIREQ             0x0080
3107
3108 #define IDLE_CMD_STATUS_SUCCESS      0x0001
3109 #define IDLE_CMD_STATUS_FAILURE      0x0002
3110
3111 /*
3112  * AdvSendIdleCmd() flag definitions.
3113  */
3114 #define ADV_NOWAIT     0x01
3115
3116 /*
3117  * Wait loop time out values.
3118  */
3119 #define SCSI_WAIT_10_SEC             10UL    /* 10 seconds */
3120 #define SCSI_WAIT_100_MSEC           100UL   /* 100 milliseconds */
3121 #define SCSI_US_PER_MSEC             1000    /* microseconds per millisecond */
3122 #define SCSI_MS_PER_SEC              1000UL  /* milliseconds per second */
3123 #define SCSI_MAX_RETRY               10      /* retry count */
3124
3125 #define ADV_ASYNC_RDMA_FAILURE          0x01 /* Fatal RDMA failure. */
3126 #define ADV_ASYNC_SCSI_BUS_RESET_DET    0x02 /* Detected SCSI Bus Reset. */
3127 #define ADV_ASYNC_CARRIER_READY_FAILURE 0x03 /* Carrier Ready failure. */
3128 #define ADV_RDMA_IN_CARR_AND_Q_INVALID  0x04 /* RDMAed-in data invalid. */
3129
3130
3131 #define ADV_HOST_SCSI_BUS_RESET      0x80 /* Host Initiated SCSI Bus Reset. */
3132
3133 /*
3134  * Device drivers must define the following functions.
3135  */
3136 STATIC inline ulong DvcEnterCritical(void);
3137 STATIC inline void  DvcLeaveCritical(ulong);
3138 STATIC void  DvcSleepMilliSecond(ADV_DCNT);
3139 STATIC uchar DvcAdvReadPCIConfigByte(ADV_DVC_VAR *, ushort);
3140 STATIC void  DvcAdvWritePCIConfigByte(ADV_DVC_VAR *, ushort, uchar);
3141 STATIC ADV_PADDR DvcGetPhyAddr(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *,
3142                 uchar *, ASC_SDCNT *, int);
3143 STATIC void  DvcDelayMicroSecond(ADV_DVC_VAR *, ushort);
3144
3145 /*
3146  * Adv Library functions available to drivers.
3147  */
3148 STATIC int     AdvExeScsiQueue(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3149 STATIC int     AdvISR(ADV_DVC_VAR *);
3150 STATIC int     AdvInitGetConfig(ADV_DVC_VAR *);
3151 STATIC int     AdvInitAsc3550Driver(ADV_DVC_VAR *);
3152 STATIC int     AdvInitAsc38C0800Driver(ADV_DVC_VAR *);
3153 STATIC int     AdvInitAsc38C1600Driver(ADV_DVC_VAR *);
3154 STATIC int     AdvResetChipAndSB(ADV_DVC_VAR *);
3155 STATIC int     AdvResetSB(ADV_DVC_VAR *asc_dvc);
3156
3157 /*
3158  * Internal Adv Library functions.
3159  */
3160 STATIC int    AdvSendIdleCmd(ADV_DVC_VAR *, ushort, ADV_DCNT);
3161 STATIC void   AdvInquiryHandling(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
3162 STATIC int    AdvInitFrom3550EEP(ADV_DVC_VAR *);
3163 STATIC int    AdvInitFrom38C0800EEP(ADV_DVC_VAR *);
3164 STATIC int    AdvInitFrom38C1600EEP(ADV_DVC_VAR *);
3165 STATIC ushort AdvGet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3166 STATIC void   AdvSet3550EEPConfig(AdvPortAddr, ADVEEP_3550_CONFIG *);
3167 STATIC ushort AdvGet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3168 STATIC void   AdvSet38C0800EEPConfig(AdvPortAddr, ADVEEP_38C0800_CONFIG *);
3169 STATIC ushort AdvGet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3170 STATIC void   AdvSet38C1600EEPConfig(AdvPortAddr, ADVEEP_38C1600_CONFIG *);
3171 STATIC void   AdvWaitEEPCmd(AdvPortAddr);
3172 STATIC ushort AdvReadEEPWord(AdvPortAddr, int);
3173
3174 /*
3175  * PCI Bus Definitions
3176  */
3177 #define AscPCICmdRegBits_BusMastering     0x0007
3178 #define AscPCICmdRegBits_ParErrRespCtrl   0x0040
3179
3180 /* Read byte from a register. */
3181 #define AdvReadByteRegister(iop_base, reg_off) \
3182      (ADV_MEM_READB((iop_base) + (reg_off)))
3183
3184 /* Write byte to a register. */
3185 #define AdvWriteByteRegister(iop_base, reg_off, byte) \
3186      (ADV_MEM_WRITEB((iop_base) + (reg_off), (byte)))
3187
3188 /* Read word (2 bytes) from a register. */
3189 #define AdvReadWordRegister(iop_base, reg_off) \
3190      (ADV_MEM_READW((iop_base) + (reg_off)))
3191
3192 /* Write word (2 bytes) to a register. */
3193 #define AdvWriteWordRegister(iop_base, reg_off, word) \
3194      (ADV_MEM_WRITEW((iop_base) + (reg_off), (word)))
3195
3196 /* Write dword (4 bytes) to a register. */
3197 #define AdvWriteDWordRegister(iop_base, reg_off, dword) \
3198      (ADV_MEM_WRITEDW((iop_base) + (reg_off), (dword)))
3199
3200 /* Read byte from LRAM. */
3201 #define AdvReadByteLram(iop_base, addr, byte) \
3202 do { \
3203     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3204     (byte) = ADV_MEM_READB((iop_base) + IOPB_RAM_DATA); \
3205 } while (0)
3206
3207 /* Write byte to LRAM. */
3208 #define AdvWriteByteLram(iop_base, addr, byte) \
3209     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3210      ADV_MEM_WRITEB((iop_base) + IOPB_RAM_DATA, (byte)))
3211
3212 /* Read word (2 bytes) from LRAM. */
3213 #define AdvReadWordLram(iop_base, addr, word) \
3214 do { \
3215     ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)); \
3216     (word) = (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA)); \
3217 } while (0)
3218
3219 /* Write word (2 bytes) to LRAM. */
3220 #define AdvWriteWordLram(iop_base, addr, word) \
3221     (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3222      ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3223
3224 /* Write little-endian double word (4 bytes) to LRAM */
3225 /* Because of unspecified C language ordering don't use auto-increment. */
3226 #define AdvWriteDWordLramNoSwap(iop_base, addr, dword) \
3227     ((ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr)), \
3228       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3229                      cpu_to_le16((ushort) ((dword) & 0xFFFF)))), \
3230      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_ADDR, (addr) + 2), \
3231       ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, \
3232                      cpu_to_le16((ushort) ((dword >> 16) & 0xFFFF)))))
3233
3234 /* Read word (2 bytes) from LRAM assuming that the address is already set. */
3235 #define AdvReadWordAutoIncLram(iop_base) \
3236      (ADV_MEM_READW((iop_base) + IOPW_RAM_DATA))
3237
3238 /* Write word (2 bytes) to LRAM assuming that the address is already set. */
3239 #define AdvWriteWordAutoIncLram(iop_base, word) \
3240      (ADV_MEM_WRITEW((iop_base) + IOPW_RAM_DATA, (word)))
3241
3242
3243 /*
3244  * Define macro to check for Condor signature.
3245  *
3246  * Evaluate to ADV_TRUE if a Condor chip is found the specified port
3247  * address 'iop_base'. Otherwise evalue to ADV_FALSE.
3248  */
3249 #define AdvFindSignature(iop_base) \
3250     (((AdvReadByteRegister((iop_base), IOPB_CHIP_ID_1) == \
3251     ADV_CHIP_ID_BYTE) && \
3252      (AdvReadWordRegister((iop_base), IOPW_CHIP_ID_0) == \
3253     ADV_CHIP_ID_WORD)) ?  ADV_TRUE : ADV_FALSE)
3254
3255 /*
3256  * Define macro to Return the version number of the chip at 'iop_base'.
3257  *
3258  * The second parameter 'bus_type' is currently unused.
3259  */
3260 #define AdvGetChipVersion(iop_base, bus_type) \
3261     AdvReadByteRegister((iop_base), IOPB_CHIP_TYPE_REV)
3262
3263 /*
3264  * Abort an SRB in the chip's RISC Memory. The 'srb_ptr' argument must
3265  * match the ASC_SCSI_REQ_Q 'srb_ptr' field.
3266  *
3267  * If the request has not yet been sent to the device it will simply be
3268  * aborted from RISC memory. If the request is disconnected it will be
3269  * aborted on reselection by sending an Abort Message to the target ID.
3270  *
3271  * Return value:
3272  *      ADV_TRUE(1) - Queue was successfully aborted.
3273  *      ADV_FALSE(0) - Queue was not found on the active queue list.
3274  */
3275 #define AdvAbortQueue(asc_dvc, scsiq) \
3276         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_ABORT, \
3277                        (ADV_DCNT) (scsiq))
3278
3279 /*
3280  * Send a Bus Device Reset Message to the specified target ID.
3281  *
3282  * All outstanding commands will be purged if sending the
3283  * Bus Device Reset Message is successful.
3284  *
3285  * Return Value:
3286  *      ADV_TRUE(1) - All requests on the target are purged.
3287  *      ADV_FALSE(0) - Couldn't issue Bus Device Reset Message; Requests
3288  *                     are not purged.
3289  */
3290 #define AdvResetDevice(asc_dvc, target_id) \
3291         AdvSendIdleCmd((asc_dvc), (ushort) IDLE_CMD_DEVICE_RESET, \
3292                     (ADV_DCNT) (target_id))
3293
3294 /*
3295  * SCSI Wide Type definition.
3296  */
3297 #define ADV_SCSI_BIT_ID_TYPE   ushort
3298
3299 /*
3300  * AdvInitScsiTarget() 'cntl_flag' options.
3301  */
3302 #define ADV_SCAN_LUN           0x01
3303 #define ADV_CAPINFO_NOLUN      0x02
3304
3305 /*
3306  * Convert target id to target id bit mask.
3307  */
3308 #define ADV_TID_TO_TIDMASK(tid)   (0x01 << ((tid) & ADV_MAX_TID))
3309
3310 /*
3311  * ASC_SCSI_REQ_Q 'done_status' and 'host_status' return values.
3312  */
3313
3314 #define QD_NO_STATUS         0x00       /* Request not completed yet. */
3315 #define QD_NO_ERROR          0x01
3316 #define QD_ABORTED_BY_HOST   0x02
3317 #define QD_WITH_ERROR        0x04
3318
3319 #define QHSTA_NO_ERROR              0x00
3320 #define QHSTA_M_SEL_TIMEOUT         0x11
3321 #define QHSTA_M_DATA_OVER_RUN       0x12
3322 #define QHSTA_M_UNEXPECTED_BUS_FREE 0x13
3323 #define QHSTA_M_QUEUE_ABORTED       0x15
3324 #define QHSTA_M_SXFR_SDMA_ERR       0x16 /* SXFR_STATUS SCSI DMA Error */
3325 #define QHSTA_M_SXFR_SXFR_PERR      0x17 /* SXFR_STATUS SCSI Bus Parity Error */
3326 #define QHSTA_M_RDMA_PERR           0x18 /* RISC PCI DMA parity error */
3327 #define QHSTA_M_SXFR_OFF_UFLW       0x19 /* SXFR_STATUS Offset Underflow */
3328 #define QHSTA_M_SXFR_OFF_OFLW       0x20 /* SXFR_STATUS Offset Overflow */
3329 #define QHSTA_M_SXFR_WD_TMO         0x21 /* SXFR_STATUS Watchdog Timeout */
3330 #define QHSTA_M_SXFR_DESELECTED     0x22 /* SXFR_STATUS Deselected */
3331 /* Note: QHSTA_M_SXFR_XFR_OFLW is identical to QHSTA_M_DATA_OVER_RUN. */
3332 #define QHSTA_M_SXFR_XFR_OFLW       0x12 /* SXFR_STATUS Transfer Overflow */
3333 #define QHSTA_M_SXFR_XFR_PH_ERR     0x24 /* SXFR_STATUS Transfer Phase Error */
3334 #define QHSTA_M_SXFR_UNKNOWN_ERROR  0x25 /* SXFR_STATUS Unknown Error */
3335 #define QHSTA_M_SCSI_BUS_RESET      0x30 /* Request aborted from SBR */
3336 #define QHSTA_M_SCSI_BUS_RESET_UNSOL 0x31 /* Request aborted from unsol. SBR */
3337 #define QHSTA_M_BUS_DEVICE_RESET    0x32 /* Request aborted from BDR */
3338 #define QHSTA_M_DIRECTION_ERR       0x35 /* Data Phase mismatch */
3339 #define QHSTA_M_DIRECTION_ERR_HUNG  0x36 /* Data Phase mismatch and bus hang */
3340 #define QHSTA_M_WTM_TIMEOUT         0x41
3341 #define QHSTA_M_BAD_CMPL_STATUS_IN  0x42
3342 #define QHSTA_M_NO_AUTO_REQ_SENSE   0x43
3343 #define QHSTA_M_AUTO_REQ_SENSE_FAIL 0x44
3344 #define QHSTA_M_INVALID_DEVICE      0x45 /* Bad target ID */
3345 #define QHSTA_M_FROZEN_TIDQ         0x46 /* TID Queue frozen. */
3346 #define QHSTA_M_SGBACKUP_ERROR      0x47 /* Scatter-Gather backup error */
3347
3348
3349 /*
3350  * Default EEPROM Configuration structure defined in a_init.c.
3351  */
3352 extern ADVEEP_3550_CONFIG Default_3550_EEPROM_Config;
3353 extern ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config;
3354 extern ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config;
3355
3356 /*
3357  * DvcGetPhyAddr() flag arguments
3358  */
3359 #define ADV_IS_SCSIQ_FLAG       0x01 /* 'addr' is ASC_SCSI_REQ_Q pointer */
3360 #define ADV_ASCGETSGLIST_VADDR  0x02 /* 'addr' is AscGetSGList() virtual addr */
3361 #define ADV_IS_SENSE_FLAG       0x04 /* 'addr' is sense virtual pointer */
3362 #define ADV_IS_DATA_FLAG        0x08 /* 'addr' is data virtual pointer */
3363 #define ADV_IS_SGLIST_FLAG      0x10 /* 'addr' is sglist virtual pointer */
3364 #define ADV_IS_CARRIER_FLAG     0x20 /* 'addr' is ADV_CARR_T pointer */
3365
3366 /* Return the address that is aligned at the next doubleword >= to 'addr'. */
3367 #define ADV_8BALIGN(addr)      (((ulong) (addr) + 0x7) & ~0x7)
3368 #define ADV_16BALIGN(addr)     (((ulong) (addr) + 0xF) & ~0xF)
3369 #define ADV_32BALIGN(addr)     (((ulong) (addr) + 0x1F) & ~0x1F)
3370
3371 /*
3372  * Total contiguous memory needed for driver SG blocks.
3373  *
3374  * ADV_MAX_SG_LIST must be defined by a driver. It is the maximum
3375  * number of scatter-gather elements the driver supports in a
3376  * single request.
3377  */
3378
3379 #define ADV_SG_LIST_MAX_BYTE_SIZE \
3380          (sizeof(ADV_SG_BLOCK) * \
3381           ((ADV_MAX_SG_LIST + (NO_OF_SG_PER_BLOCK - 1))/NO_OF_SG_PER_BLOCK))
3382
3383 /*
3384  * Inquiry data structure and bitfield macros
3385  *
3386  * Using bitfields to access the subchar data isn't portable across
3387  * endianness, so instead mask and shift. Only quantities of more
3388  * than 1 bit are shifted, since the others are just tested for true
3389  * or false.
3390  */
3391
3392 #define ADV_INQ_DVC_TYPE(inq)       ((inq)->periph & 0x1f)
3393 #define ADV_INQ_QUALIFIER(inq)      (((inq)->periph & 0xe0) >> 5)
3394 #define ADV_INQ_DVC_TYPE_MOD(inq)   ((inq)->devtype & 0x7f)
3395 #define ADV_INQ_REMOVABLE(inq)      ((inq)->devtype & 0x80)
3396 #define ADV_INQ_ANSI_VER(inq)       ((inq)->ver & 0x07)
3397 #define ADV_INQ_ECMA_VER(inq)       (((inq)->ver & 0x38) >> 3)
3398 #define ADV_INQ_ISO_VER(inq)        (((inq)->ver & 0xc0) >> 6)
3399 #define ADV_INQ_RESPONSE_FMT(inq)   ((inq)->byte3 & 0x0f)
3400 #define ADV_INQ_TERM_IO(inq)        ((inq)->byte3 & 0x40)
3401 #define ADV_INQ_ASYNC_NOTIF(inq)    ((inq)->byte3 & 0x80)
3402 #define ADV_INQ_SOFT_RESET(inq)     ((inq)->flags & 0x01)
3403 #define ADV_INQ_CMD_QUEUE(inq)      ((inq)->flags & 0x02)
3404 #define ADV_INQ_LINK_CMD(inq)       ((inq)->flags & 0x08)
3405 #define ADV_INQ_SYNC(inq)           ((inq)->flags & 0x10)
3406 #define ADV_INQ_WIDE16(inq)         ((inq)->flags & 0x20)
3407 #define ADV_INQ_WIDE32(inq)         ((inq)->flags & 0x40)
3408 #define ADV_INQ_REL_ADDR(inq)       ((inq)->flags & 0x80)
3409 #define ADV_INQ_INFO_UNIT(inq)      ((inq)->info & 0x01)
3410 #define ADV_INQ_QUICK_ARB(inq)      ((inq)->info & 0x02)
3411 #define ADV_INQ_CLOCKING(inq)       (((inq)->info & 0x0c) >> 2)
3412
3413 typedef struct {
3414   uchar periph;                 /* peripheral device type [0:4] */
3415                                 /* peripheral qualifier [5:7] */
3416   uchar devtype;                /* device type modifier (for SCSI I) [0:6] */
3417                                 /* RMB - removable medium bit [7] */
3418   uchar ver;                    /* ANSI approved version [0:2] */
3419                                 /* ECMA version [3:5] */
3420                                 /* ISO version [6:7] */
3421   uchar byte3;                  /* response data format [0:3] */
3422                                 /* 0 SCSI 1 */
3423                                 /* 1 CCS */
3424                                 /* 2 SCSI-2 */
3425                                 /* 3-F reserved */
3426                                 /* reserved [4:5] */
3427                                 /* terminate I/O process bit (see 5.6.22) [6] */
3428                                 /* asynch. event notification (processor) [7] */
3429   uchar add_len;                /* additional length */
3430   uchar res1;                   /* reserved */
3431   uchar res2;                   /* reserved */
3432   uchar flags;                  /* soft reset implemented [0] */
3433                                 /* command queuing [1] */
3434                                 /* reserved [2] */
3435                                 /* linked command for this logical unit [3] */
3436                                 /* synchronous data transfer [4] */
3437                                 /* wide bus 16 bit data transfer [5] */
3438                                 /* wide bus 32 bit data transfer [6] */
3439                                 /* relative addressing mode [7] */
3440   uchar vendor_id[8];           /* vendor identification */
3441   uchar product_id[16];         /* product identification */
3442   uchar product_rev_level[4];   /* product revision level */
3443   uchar vendor_specific[20];    /* vendor specific */
3444   uchar info;                   /* information unit supported [0] */
3445                                 /* quick arbitrate supported [1] */
3446                                 /* clocking field [2:3] */
3447                                 /* reserved [4:7] */
3448   uchar res3;                   /* reserved */
3449 } ADV_SCSI_INQUIRY; /* 58 bytes */
3450
3451
3452 /*
3453  * --- Driver Constants and Macros
3454  */
3455
3456 #define ASC_NUM_BOARD_SUPPORTED 16
3457 #define ASC_NUM_IOPORT_PROBE    4
3458 #define ASC_NUM_BUS             4
3459
3460 /* Reference Scsi_Host hostdata */
3461 #define ASC_BOARDP(host) ((asc_board_t *) &((host)->hostdata))
3462
3463 /* asc_board_t flags */
3464 #define ASC_HOST_IN_RESET       0x01
3465 #define ASC_IS_WIDE_BOARD       0x04    /* AdvanSys Wide Board */
3466 #define ASC_SELECT_QUEUE_DEPTHS 0x08
3467
3468 #define ASC_NARROW_BOARD(boardp) (((boardp)->flags & ASC_IS_WIDE_BOARD) == 0)
3469 #define ASC_WIDE_BOARD(boardp)   ((boardp)->flags & ASC_IS_WIDE_BOARD)
3470
3471 #define NO_ISA_DMA              0xff        /* No ISA DMA Channel Used */
3472
3473 #define ASC_INFO_SIZE           128            /* advansys_info() line size */
3474
3475 #ifdef CONFIG_PROC_FS
3476 /* /proc/scsi/advansys/[0...] related definitions */
3477 #define ASC_PRTBUF_SIZE         2048
3478 #define ASC_PRTLINE_SIZE        160
3479
3480 #define ASC_PRT_NEXT() \
3481     if (cp) { \
3482         totlen += len; \
3483         leftlen -= len; \
3484         if (leftlen == 0) { \
3485             return totlen; \
3486         } \
3487         cp += len; \
3488     }
3489 #endif /* CONFIG_PROC_FS */
3490
3491 /* Asc Library return codes */
3492 #define ASC_TRUE        1
3493 #define ASC_FALSE       0
3494 #define ASC_NOERROR     1
3495 #define ASC_BUSY        0
3496 #define ASC_ERROR       (-1)
3497
3498 /* Scsi_Cmnd function return codes */
3499 #define STATUS_BYTE(byte)   (byte)
3500 #define MSG_BYTE(byte)      ((byte) << 8)
3501 #define HOST_BYTE(byte)     ((byte) << 16)
3502 #define DRIVER_BYTE(byte)   ((byte) << 24)
3503
3504 /*
3505  * The following definitions and macros are OS independent interfaces to
3506  * the queue functions:
3507  *  REQ - SCSI request structure
3508  *  REQP - pointer to SCSI request structure
3509  *  REQPTID(reqp) - reqp's target id
3510  *  REQPNEXT(reqp) - reqp's next pointer
3511  *  REQPNEXTP(reqp) - pointer to reqp's next pointer
3512  *  REQPTIME(reqp) - reqp's time stamp value
3513  *  REQTIMESTAMP() - system time stamp value
3514  */
3515 typedef Scsi_Cmnd            REQ, *REQP;
3516 #define REQPNEXT(reqp)       ((REQP) ((reqp)->host_scribble))
3517 #define REQPNEXTP(reqp)      ((REQP *) &((reqp)->host_scribble))
3518 #define REQPTID(reqp)        ((reqp)->device->id)
3519 #define REQPTIME(reqp)       ((reqp)->SCp.this_residual)
3520 #define REQTIMESTAMP()       (jiffies)
3521
3522 #define REQTIMESTAT(function, ascq, reqp, tid) \
3523 { \
3524     /*
3525      * If the request time stamp is less than the system time stamp, then \
3526      * maybe the system time stamp wrapped. Set the request time to zero.\
3527      */ \
3528     if (REQPTIME(reqp) <= REQTIMESTAMP()) { \
3529         REQPTIME(reqp) = REQTIMESTAMP() - REQPTIME(reqp); \
3530     } else { \
3531         /* Indicate an error occurred with the assertion. */ \
3532         ASC_ASSERT(REQPTIME(reqp) <= REQTIMESTAMP()); \
3533         REQPTIME(reqp) = 0; \
3534     } \
3535     /* Handle first minimum time case without external initialization. */ \
3536     if (((ascq)->q_tot_cnt[tid] == 1) ||  \
3537         (REQPTIME(reqp) < (ascq)->q_min_tim[tid])) { \
3538             (ascq)->q_min_tim[tid] = REQPTIME(reqp); \
3539             ASC_DBG3(1, "%s: new q_min_tim[%d] %u\n", \
3540                 (function), (tid), (ascq)->q_min_tim[tid]); \
3541         } \
3542     if (REQPTIME(reqp) > (ascq)->q_max_tim[tid]) { \
3543         (ascq)->q_max_tim[tid] = REQPTIME(reqp); \
3544         ASC_DBG3(1, "%s: new q_max_tim[%d] %u\n", \
3545             (function), tid, (ascq)->q_max_tim[tid]); \
3546     } \
3547     (ascq)->q_tot_tim[tid] += REQPTIME(reqp); \
3548     /* Reset the time stamp field. */ \
3549     REQPTIME(reqp) = 0; \
3550 }
3551
3552 /* asc_enqueue() flags */
3553 #define ASC_FRONT       1
3554 #define ASC_BACK        2
3555
3556 /* asc_dequeue_list() argument */
3557 #define ASC_TID_ALL        (-1)
3558
3559 /* Return non-zero, if the queue is empty. */
3560 #define ASC_QUEUE_EMPTY(ascq)    ((ascq)->q_tidmask == 0)
3561
3562 #define PCI_MAX_SLOT            0x1F
3563 #define PCI_MAX_BUS             0xFF
3564 #define PCI_IOADDRESS_MASK      0xFFFE
3565 #define ASC_PCI_VENDORID        0x10CD
3566 #define ASC_PCI_DEVICE_ID_CNT   6       /* PCI Device ID count. */
3567 #define ASC_PCI_DEVICE_ID_1100  0x1100
3568 #define ASC_PCI_DEVICE_ID_1200  0x1200
3569 #define ASC_PCI_DEVICE_ID_1300  0x1300
3570 #define ASC_PCI_DEVICE_ID_2300  0x2300  /* ASC-3550 */
3571 #define ASC_PCI_DEVICE_ID_2500  0x2500  /* ASC-38C0800 */
3572 #define ASC_PCI_DEVICE_ID_2700  0x2700  /* ASC-38C1600 */
3573
3574 #ifndef ADVANSYS_STATS
3575 #define ASC_STATS(shp, counter)
3576 #define ASC_STATS_ADD(shp, counter, count)
3577 #else /* ADVANSYS_STATS */
3578 #define ASC_STATS(shp, counter) \
3579     (ASC_BOARDP(shp)->asc_stats.counter++)
3580
3581 #define ASC_STATS_ADD(shp, counter, count) \
3582     (ASC_BOARDP(shp)->asc_stats.counter += (count))
3583 #endif /* ADVANSYS_STATS */
3584
3585 #define ASC_CEILING(val, unit) (((val) + ((unit) - 1))/(unit))
3586
3587 /* If the result wraps when calculating tenths, return 0. */
3588 #define ASC_TENTHS(num, den) \
3589     (((10 * ((num)/(den))) > (((num) * 10)/(den))) ? \
3590     0 : ((((num) * 10)/(den)) - (10 * ((num)/(den)))))
3591
3592 /*
3593  * Display a message to the console.
3594  */
3595 #define ASC_PRINT(s) \
3596     { \
3597         printk("advansys: "); \
3598         printk(s); \
3599     }
3600
3601 #define ASC_PRINT1(s, a1) \
3602     { \
3603         printk("advansys: "); \
3604         printk((s), (a1)); \
3605     }
3606
3607 #define ASC_PRINT2(s, a1, a2) \
3608     { \
3609         printk("advansys: "); \
3610         printk((s), (a1), (a2)); \
3611     }
3612
3613 #define ASC_PRINT3(s, a1, a2, a3) \
3614     { \
3615         printk("advansys: "); \
3616         printk((s), (a1), (a2), (a3)); \
3617     }
3618
3619 #define ASC_PRINT4(s, a1, a2, a3, a4) \
3620     { \
3621         printk("advansys: "); \
3622         printk((s), (a1), (a2), (a3), (a4)); \
3623     }
3624
3625
3626 #ifndef ADVANSYS_DEBUG
3627
3628 #define ASC_DBG(lvl, s)
3629 #define ASC_DBG1(lvl, s, a1)
3630 #define ASC_DBG2(lvl, s, a1, a2)
3631 #define ASC_DBG3(lvl, s, a1, a2, a3)
3632 #define ASC_DBG4(lvl, s, a1, a2, a3, a4)
3633 #define ASC_DBG_PRT_SCSI_HOST(lvl, s)
3634 #define ASC_DBG_PRT_SCSI_CMND(lvl, s)
3635 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp)
3636 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3637 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone)
3638 #define ADV_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp)
3639 #define ASC_DBG_PRT_HEX(lvl, name, start, length)
3640 #define ASC_DBG_PRT_CDB(lvl, cdb, len)
3641 #define ASC_DBG_PRT_SENSE(lvl, sense, len)
3642 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len)
3643
3644 #else /* ADVANSYS_DEBUG */
3645
3646 /*
3647  * Debugging Message Levels:
3648  * 0: Errors Only
3649  * 1: High-Level Tracing
3650  * 2-N: Verbose Tracing
3651  */
3652
3653 #define ASC_DBG(lvl, s) \
3654     { \
3655         if (asc_dbglvl >= (lvl)) { \
3656             printk(s); \
3657         } \
3658     }
3659
3660 #define ASC_DBG1(lvl, s, a1) \
3661     { \
3662         if (asc_dbglvl >= (lvl)) { \
3663             printk((s), (a1)); \
3664         } \
3665     }
3666
3667 #define ASC_DBG2(lvl, s, a1, a2) \
3668     { \
3669         if (asc_dbglvl >= (lvl)) { \
3670             printk((s), (a1), (a2)); \
3671         } \
3672     }
3673
3674 #define ASC_DBG3(lvl, s, a1, a2, a3) \
3675     { \
3676         if (asc_dbglvl >= (lvl)) { \
3677             printk((s), (a1), (a2), (a3)); \
3678         } \
3679     }
3680
3681 #define ASC_DBG4(lvl, s, a1, a2, a3, a4) \
3682     { \
3683         if (asc_dbglvl >= (lvl)) { \
3684             printk((s), (a1), (a2), (a3), (a4)); \
3685         } \
3686     }
3687
3688 #define ASC_DBG_PRT_SCSI_HOST(lvl, s) \
3689     { \
3690         if (asc_dbglvl >= (lvl)) { \
3691             asc_prt_scsi_host(s); \
3692         } \
3693     }
3694
3695 #define ASC_DBG_PRT_SCSI_CMND(lvl, s) \
3696     { \
3697         if (asc_dbglvl >= (lvl)) { \
3698             asc_prt_scsi_cmnd(s); \
3699         } \
3700     }
3701
3702 #define ASC_DBG_PRT_ASC_SCSI_Q(lvl, scsiqp) \
3703     { \
3704         if (asc_dbglvl >= (lvl)) { \
3705             asc_prt_asc_scsi_q(scsiqp); \
3706         } \
3707     }
3708
3709 #define ASC_DBG_PRT_ASC_QDONE_INFO(lvl, qdone) \
3710     { \
3711         if (asc_dbglvl >= (lvl)) { \
3712             asc_prt_asc_qdone_info(qdone); \
3713         } \
3714     }
3715
3716 #define ASC_DBG_PRT_ADV_SCSI_REQ_Q(lvl, scsiqp) \
3717     { \
3718         if (asc_dbglvl >= (lvl)) { \
3719             asc_prt_adv_scsi_req_q(scsiqp); \
3720         } \
3721     }
3722
3723 #define ASC_DBG_PRT_HEX(lvl, name, start, length) \
3724     { \
3725         if (asc_dbglvl >= (lvl)) { \
3726             asc_prt_hex((name), (start), (length)); \
3727         } \
3728     }
3729
3730 #define ASC_DBG_PRT_CDB(lvl, cdb, len) \
3731         ASC_DBG_PRT_HEX((lvl), "CDB", (uchar *) (cdb), (len));
3732
3733 #define ASC_DBG_PRT_SENSE(lvl, sense, len) \
3734         ASC_DBG_PRT_HEX((lvl), "SENSE", (uchar *) (sense), (len));
3735
3736 #define ASC_DBG_PRT_INQUIRY(lvl, inq, len) \
3737         ASC_DBG_PRT_HEX((lvl), "INQUIRY", (uchar *) (inq), (len));
3738 #endif /* ADVANSYS_DEBUG */
3739
3740 #ifndef ADVANSYS_ASSERT
3741 #define ASC_ASSERT(a)
3742 #else /* ADVANSYS_ASSERT */
3743
3744 #define ASC_ASSERT(a) \
3745     { \
3746         if (!(a)) { \
3747             printk("ASC_ASSERT() Failure: file %s, line %d\n", \
3748                 __FILE__, __LINE__); \
3749         } \
3750     }
3751
3752 #endif /* ADVANSYS_ASSERT */
3753
3754
3755 /*
3756  * --- Driver Structures
3757  */
3758
3759 #ifdef ADVANSYS_STATS
3760
3761 /* Per board statistics structure */
3762 struct asc_stats {
3763     /* Driver Entrypoint Statistics */
3764     ADV_DCNT queuecommand;    /* # calls to advansys_queuecommand() */
3765     ADV_DCNT reset;           /* # calls to advansys_eh_bus_reset() */
3766     ADV_DCNT biosparam;       /* # calls to advansys_biosparam() */
3767     ADV_DCNT interrupt;       /* # advansys_interrupt() calls */
3768     ADV_DCNT callback;        /* # calls to asc/adv_isr_callback() */
3769     ADV_DCNT done;            /* # calls to request's scsi_done function */
3770     ADV_DCNT build_error;     /* # asc/adv_build_req() ASC_ERROR returns. */
3771     ADV_DCNT adv_build_noreq; /* # adv_build_req() adv_req_t alloc. fail. */
3772     ADV_DCNT adv_build_nosg;  /* # adv_build_req() adv_sgblk_t alloc. fail. */
3773     /* AscExeScsiQueue()/AdvExeScsiQueue() Statistics */
3774     ADV_DCNT exe_noerror;     /* # ASC_NOERROR returns. */
3775     ADV_DCNT exe_busy;        /* # ASC_BUSY returns. */
3776     ADV_DCNT exe_error;       /* # ASC_ERROR returns. */
3777     ADV_DCNT exe_unknown;     /* # unknown returns. */
3778     /* Data Transfer Statistics */
3779     ADV_DCNT cont_cnt;        /* # non-scatter-gather I/O requests received */
3780     ADV_DCNT cont_xfer;       /* # contiguous transfer 512-bytes */
3781     ADV_DCNT sg_cnt;          /* # scatter-gather I/O requests received */
3782     ADV_DCNT sg_elem;         /* # scatter-gather elements */
3783     ADV_DCNT sg_xfer;         /* # scatter-gather transfer 512-bytes */
3784 };
3785 #endif /* ADVANSYS_STATS */
3786
3787 /*
3788  * Request queuing structure
3789  */
3790 typedef struct asc_queue {
3791     ADV_SCSI_BIT_ID_TYPE  q_tidmask;                /* queue mask */
3792     REQP                  q_first[ADV_MAX_TID+1];   /* first queued request */
3793     REQP                  q_last[ADV_MAX_TID+1];    /* last queued request */
3794 #ifdef ADVANSYS_STATS
3795     short                 q_cur_cnt[ADV_MAX_TID+1]; /* current queue count */
3796     short                 q_max_cnt[ADV_MAX_TID+1]; /* maximum queue count */
3797     ADV_DCNT              q_tot_cnt[ADV_MAX_TID+1]; /* total enqueue count */
3798     ADV_DCNT              q_tot_tim[ADV_MAX_TID+1]; /* total time queued */
3799     ushort                q_max_tim[ADV_MAX_TID+1]; /* maximum time queued */
3800     ushort                q_min_tim[ADV_MAX_TID+1]; /* minimum time queued */
3801 #endif /* ADVANSYS_STATS */
3802 } asc_queue_t;
3803
3804 /*
3805  * Adv Library Request Structures
3806  *
3807  * The following two structures are used to process Wide Board requests.
3808  *
3809  * The ADV_SCSI_REQ_Q structure in adv_req_t is passed to the Adv Library
3810  * and microcode with the ADV_SCSI_REQ_Q field 'srb_ptr' pointing to the
3811  * adv_req_t. The adv_req_t structure 'cmndp' field in turn points to the
3812  * Mid-Level SCSI request structure.
3813  *
3814  * Zero or more ADV_SG_BLOCK are used with each ADV_SCSI_REQ_Q. Each
3815  * ADV_SG_BLOCK structure holds 15 scatter-gather elements. Under Linux
3816  * up to 255 scatter-gather elements may be used per request or
3817  * ADV_SCSI_REQ_Q.
3818  *
3819  * Both structures must be 32 byte aligned.
3820  */
3821 typedef struct adv_sgblk {
3822     ADV_SG_BLOCK        sg_block;     /* Sgblock structure. */
3823     uchar               align[32];    /* Sgblock structure padding. */
3824     struct adv_sgblk    *next_sgblkp; /* Next scatter-gather structure. */
3825 } adv_sgblk_t;
3826
3827 typedef struct adv_req {
3828     ADV_SCSI_REQ_Q      scsi_req_q;   /* Adv Library request structure. */
3829     uchar               align[32];    /* Request structure padding. */
3830     Scsi_Cmnd           *cmndp;       /* Mid-Level SCSI command pointer. */
3831     adv_sgblk_t         *sgblkp;      /* Adv Library scatter-gather pointer. */
3832     struct adv_req      *next_reqp;   /* Next Request Structure. */
3833 } adv_req_t;
3834
3835 /*
3836  * Structure allocated for each board.
3837  *
3838  * This structure is allocated by scsi_register() at the end
3839  * of the 'Scsi_Host' structure starting at the 'hostdata'
3840  * field. It is guaranteed to be allocated from DMA-able memory.
3841  */
3842 typedef struct asc_board {
3843     int                  id;                    /* Board Id */
3844     uint                 flags;                 /* Board flags */
3845     union {
3846         ASC_DVC_VAR      asc_dvc_var;           /* Narrow board */
3847         ADV_DVC_VAR      adv_dvc_var;           /* Wide board */
3848     } dvc_var;
3849     union {
3850         ASC_DVC_CFG      asc_dvc_cfg;           /* Narrow board */
3851         ADV_DVC_CFG      adv_dvc_cfg;           /* Wide board */
3852     } dvc_cfg;
3853     ushort               asc_n_io_port;         /* Number I/O ports. */
3854     asc_queue_t          active;                /* Active command queue */
3855     asc_queue_t          waiting;               /* Waiting command queue */
3856     asc_queue_t          done;                  /* Done command queue */
3857     ADV_SCSI_BIT_ID_TYPE init_tidmask;          /* Target init./valid mask */
3858     Scsi_Device          *device[ADV_MAX_TID+1]; /* Mid-Level Scsi Device */
3859     ushort               reqcnt[ADV_MAX_TID+1]; /* Starvation request count */
3860     ADV_SCSI_BIT_ID_TYPE queue_full;            /* Queue full mask */
3861     ushort               queue_full_cnt[ADV_MAX_TID+1]; /* Queue full count */
3862     union {
3863         ASCEEP_CONFIG         asc_eep;          /* Narrow EEPROM config. */
3864         ADVEEP_3550_CONFIG    adv_3550_eep;     /* 3550 EEPROM config. */
3865         ADVEEP_38C0800_CONFIG adv_38C0800_eep;  /* 38C0800 EEPROM config. */
3866         ADVEEP_38C1600_CONFIG adv_38C1600_eep;  /* 38C1600 EEPROM config. */
3867     } eep_config;
3868     ulong                last_reset;            /* Saved last reset time */
3869     spinlock_t lock;                            /* Board spinlock */
3870 #ifdef CONFIG_PROC_FS
3871     /* /proc/scsi/advansys/[0...] */
3872     char                 *prtbuf;               /* /proc print buffer */
3873 #endif /* CONFIG_PROC_FS */
3874 #ifdef ADVANSYS_STATS
3875     struct asc_stats     asc_stats;             /* Board statistics */
3876 #endif /* ADVANSYS_STATS */
3877     /*
3878      * The following fields are used only for Narrow Boards.
3879      */
3880     /* The following three structures must be in DMA-able memory. */
3881     ASC_SCSI_REQ_Q       scsireqq;
3882     ASC_CAP_INFO         cap_info;
3883     ASC_SCSI_INQUIRY     inquiry;
3884     uchar                sdtr_data[ASC_MAX_TID+1]; /* SDTR information */
3885     /*
3886      * The following fields are used only for Wide Boards.
3887      */
3888     void                 *ioremap_addr;         /* I/O Memory remap address. */
3889     ushort               ioport;                /* I/O Port address. */
3890     ADV_CARR_T           *orig_carrp;           /* ADV_CARR_T memory block. */
3891     adv_req_t            *orig_reqp;            /* adv_req_t memory block. */
3892     adv_req_t            *adv_reqp;             /* Request structures. */
3893     adv_sgblk_t          *adv_sgblkp;           /* Scatter-gather structures. */
3894     ushort               bios_signature;        /* BIOS Signature. */
3895     ushort               bios_version;          /* BIOS Version. */
3896     ushort               bios_codeseg;          /* BIOS Code Segment. */
3897     ushort               bios_codelen;          /* BIOS Code Segment Length. */
3898 } asc_board_t;
3899
3900 /*
3901  * PCI configuration structures
3902  */
3903 typedef struct _PCI_DATA_
3904 {
3905     uchar    type;
3906     uchar    bus;
3907     uchar    slot;
3908     uchar    func;
3909     uchar    offset;
3910 } PCI_DATA;
3911
3912 typedef struct _PCI_DEVICE_
3913 {
3914     ushort   vendorID;
3915     ushort   deviceID;
3916     ushort   slotNumber;
3917     ushort   slotFound;
3918     uchar    busNumber;
3919     uchar    maxBusNumber;
3920     uchar    devFunc;
3921     ushort   startSlot;
3922     ushort   endSlot;
3923     uchar    bridge;
3924     uchar    type;
3925 } PCI_DEVICE;
3926
3927 typedef struct _PCI_CONFIG_SPACE_
3928 {
3929     ushort   vendorID;
3930     ushort   deviceID;
3931     ushort   command;
3932     ushort   status;
3933     uchar    revision;
3934     uchar    classCode[3];
3935     uchar    cacheSize;
3936     uchar    latencyTimer;
3937     uchar    headerType;
3938     uchar    bist;
3939     ADV_PADDR baseAddress[6];
3940     ushort   reserved[4];
3941     ADV_PADDR optionRomAddr;
3942     ushort   reserved2[4];
3943     uchar    irqLine;
3944     uchar    irqPin;
3945     uchar    minGnt;
3946     uchar    maxLatency;
3947 } PCI_CONFIG_SPACE;
3948
3949
3950 /*
3951  * --- Driver Data
3952  */
3953
3954 /* Note: All driver global data should be initialized. */
3955
3956 /* Number of boards detected in system. */
3957 STATIC int asc_board_count = 0;
3958 STATIC struct Scsi_Host    *asc_host[ASC_NUM_BOARD_SUPPORTED] = { 0 };
3959
3960 /* Overrun buffer used by all narrow boards. */
3961 STATIC uchar overrun_buf[ASC_OVERRUN_BSIZE] = { 0 };
3962
3963 /*
3964  * Global structures required to issue a command.
3965  */
3966 STATIC ASC_SCSI_Q asc_scsi_q = { { 0 } };
3967 STATIC ASC_SG_HEAD asc_sg_head = { 0 };
3968
3969 /* List of supported bus types. */
3970 STATIC ushort asc_bus[ASC_NUM_BUS] __initdata = {
3971     ASC_IS_ISA,
3972     ASC_IS_VL,
3973     ASC_IS_EISA,
3974     ASC_IS_PCI,
3975 };
3976
3977 /*
3978  * Used with the LILO 'advansys' option to eliminate or
3979  * limit I/O port probing at boot time, cf. advansys_setup().
3980  */
3981 STATIC int asc_iopflag = ASC_FALSE;
3982 STATIC int asc_ioport[ASC_NUM_IOPORT_PROBE] = { 0, 0, 0, 0 };
3983
3984 #ifdef ADVANSYS_DEBUG
3985 STATIC char *
3986 asc_bus_name[ASC_NUM_BUS] = {
3987     "ASC_IS_ISA",
3988     "ASC_IS_VL",
3989     "ASC_IS_EISA",
3990     "ASC_IS_PCI",
3991 };
3992
3993 STATIC int          asc_dbglvl = 3;
3994 #endif /* ADVANSYS_DEBUG */
3995
3996 /* Declaration for Asc Library internal data referenced by driver. */
3997 STATIC PortAddr     _asc_def_iop_base[];
3998
3999
4000 /*
4001  * --- Driver Function Prototypes
4002  *
4003  * advansys.h contains function prototypes for functions global to Linux.
4004  */
4005
4006 STATIC irqreturn_t advansys_interrupt(int, void *, struct pt_regs *);
4007 STATIC int        advansys_slave_configure(Scsi_Device *);
4008 STATIC void       asc_scsi_done_list(Scsi_Cmnd *);
4009 STATIC int        asc_execute_scsi_cmnd(Scsi_Cmnd *);
4010 STATIC int        asc_build_req(asc_board_t *, Scsi_Cmnd *);
4011 STATIC int        adv_build_req(asc_board_t *, Scsi_Cmnd *, ADV_SCSI_REQ_Q **);
4012 STATIC int        adv_get_sglist(asc_board_t *, adv_req_t *, Scsi_Cmnd *, int);
4013 STATIC void       asc_isr_callback(ASC_DVC_VAR *, ASC_QDONE_INFO *);
4014 STATIC void       adv_isr_callback(ADV_DVC_VAR *, ADV_SCSI_REQ_Q *);
4015 STATIC void       adv_async_callback(ADV_DVC_VAR *, uchar);
4016 STATIC void       asc_enqueue(asc_queue_t *, REQP, int);
4017 STATIC REQP       asc_dequeue(asc_queue_t *, int);
4018 STATIC REQP       asc_dequeue_list(asc_queue_t *, REQP *, int);
4019 STATIC int        asc_rmqueue(asc_queue_t *, REQP);
4020 STATIC void       asc_execute_queue(asc_queue_t *);
4021 #ifdef CONFIG_PROC_FS
4022 STATIC int        asc_proc_copy(off_t, off_t, char *, int , char *, int);
4023 STATIC int        asc_prt_board_devices(struct Scsi_Host *, char *, int);
4024 STATIC int        asc_prt_adv_bios(struct Scsi_Host *, char *, int);
4025 STATIC int        asc_get_eeprom_string(ushort *serialnum, uchar *cp);
4026 STATIC int        asc_prt_asc_board_eeprom(struct Scsi_Host *, char *, int);
4027 STATIC int        asc_prt_adv_board_eeprom(struct Scsi_Host *, char *, int);
4028 STATIC int        asc_prt_driver_conf(struct Scsi_Host *, char *, int);
4029 STATIC int        asc_prt_asc_board_info(struct Scsi_Host *, char *, int);
4030 STATIC int        asc_prt_adv_board_info(struct Scsi_Host *, char *, int);
4031 STATIC int        asc_prt_line(char *, int, char *fmt, ...);
4032 #endif /* CONFIG_PROC_FS */
4033
4034 /* Declaration for Asc Library internal functions referenced by driver. */
4035 STATIC int          AscFindSignature(PortAddr);
4036 STATIC ushort       AscGetEEPConfig(PortAddr, ASCEEP_CONFIG *, ushort);
4037
4038 /* Statistics function prototypes. */
4039 #ifdef ADVANSYS_STATS
4040 #ifdef CONFIG_PROC_FS
4041 STATIC int          asc_prt_board_stats(struct Scsi_Host *, char *, int);
4042 STATIC int          asc_prt_target_stats(struct Scsi_Host *, int, char *, int);
4043 #endif /* CONFIG_PROC_FS */
4044 #endif /* ADVANSYS_STATS */
4045
4046 /* Debug function prototypes. */
4047 #ifdef ADVANSYS_DEBUG
4048 STATIC void         asc_prt_scsi_host(struct Scsi_Host *);
4049 STATIC void         asc_prt_scsi_cmnd(Scsi_Cmnd *);
4050 STATIC void         asc_prt_asc_dvc_cfg(ASC_DVC_CFG *);
4051 STATIC void         asc_prt_asc_dvc_var(ASC_DVC_VAR *);
4052 STATIC void         asc_prt_asc_scsi_q(ASC_SCSI_Q *);
4053 STATIC void         asc_prt_asc_qdone_info(ASC_QDONE_INFO *);
4054 STATIC void         asc_prt_adv_dvc_cfg(ADV_DVC_CFG *);
4055 STATIC void         asc_prt_adv_dvc_var(ADV_DVC_VAR *);
4056 STATIC void         asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *);
4057 STATIC void         asc_prt_adv_sgblock(int, ADV_SG_BLOCK *);
4058 STATIC void         asc_prt_hex(char *f, uchar *, int);
4059 #endif /* ADVANSYS_DEBUG */
4060
4061
4062 /*
4063  * --- Linux 'Scsi_Host_Template' and advansys_setup() Functions
4064  */
4065
4066 #ifdef CONFIG_PROC_FS
4067 /*
4068  * advansys_proc_info() - /proc/scsi/advansys/[0-(ASC_NUM_BOARD_SUPPORTED-1)]
4069  *
4070  * *buffer: I/O buffer
4071  * **start: if inout == FALSE pointer into buffer where user read should start
4072  * offset: current offset into a /proc/scsi/advansys/[0...] file
4073  * length: length of buffer
4074  * hostno: Scsi_Host host_no
4075  * inout: TRUE - user is writing; FALSE - user is reading
4076  *
4077  * Return the number of bytes read from or written to a
4078  * /proc/scsi/advansys/[0...] file.
4079  *
4080  * Note: This function uses the per board buffer 'prtbuf' which is
4081  * allocated when the board is initialized in advansys_detect(). The
4082  * buffer is ASC_PRTBUF_SIZE bytes. The function asc_proc_copy() is
4083  * used to write to the buffer. The way asc_proc_copy() is written
4084  * if 'prtbuf' is too small it will not be overwritten. Instead the
4085  * user just won't get all the available statistics.
4086  */
4087 int
4088 advansys_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
4089                 off_t offset, int length, int inout)
4090 {
4091     struct Scsi_Host    *shp;
4092     asc_board_t         *boardp;
4093     int                 i;
4094     char                *cp;
4095     int                 cplen;
4096     int                 cnt;
4097     int                 totcnt;
4098     int                 leftlen;
4099     char                *curbuf;
4100     off_t               advoffset;
4101 #ifdef ADVANSYS_STATS
4102     int                 tgt_id;
4103 #endif /* ADVANSYS_STATS */
4104
4105     ASC_DBG(1, "advansys_proc_info: begin\n");
4106
4107     /*
4108      * User write not supported.
4109      */
4110     if (inout == TRUE) {
4111         return(-ENOSYS);
4112     }
4113
4114     /*
4115      * User read of /proc/scsi/advansys/[0...] file.
4116      */
4117
4118     /* Find the specified board. */
4119     for (i = 0; i < asc_board_count; i++) {
4120         if (asc_host[i]->host_no == shost->host_no) {
4121             break;
4122         }
4123     }
4124     if (i == asc_board_count) {
4125         return(-ENOENT);
4126     }
4127
4128     shp = asc_host[i];
4129     boardp = ASC_BOARDP(shp);
4130
4131     /* Copy read data starting at the beginning of the buffer. */
4132     *start = buffer;
4133     curbuf = buffer;
4134     advoffset = 0;
4135     totcnt = 0;
4136     leftlen = length;
4137
4138     /*
4139      * Get board configuration information.
4140      *
4141      * advansys_info() returns the board string from its own static buffer.
4142      */
4143     cp = (char *) advansys_info(shp);
4144     strcat(cp, "\n");
4145     cplen = strlen(cp);
4146     /* Copy board information. */
4147     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4148     totcnt += cnt;
4149     leftlen -= cnt;
4150     if (leftlen == 0) {
4151         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4152         return totcnt;
4153     }
4154     advoffset += cplen;
4155     curbuf += cnt;
4156
4157     /*
4158      * Display Wide Board BIOS Information.
4159      */
4160     if (ASC_WIDE_BOARD(boardp)) {
4161         cp = boardp->prtbuf;
4162         cplen = asc_prt_adv_bios(shp, cp, ASC_PRTBUF_SIZE);
4163         ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4164         cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4165         totcnt += cnt;
4166         leftlen -= cnt;
4167         if (leftlen == 0) {
4168             ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4169             return totcnt;
4170         }
4171         advoffset += cplen;
4172         curbuf += cnt;
4173     }
4174
4175     /*
4176      * Display driver information for each device attached to the board.
4177      */
4178     cp = boardp->prtbuf;
4179     cplen = asc_prt_board_devices(shp, cp, ASC_PRTBUF_SIZE);
4180     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4181     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4182     totcnt += cnt;
4183     leftlen -= cnt;
4184     if (leftlen == 0) {
4185         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4186         return totcnt;
4187     }
4188     advoffset += cplen;
4189     curbuf += cnt;
4190
4191     /*
4192      * Display EEPROM configuration for the board.
4193      */
4194     cp = boardp->prtbuf;
4195     if (ASC_NARROW_BOARD(boardp)) {
4196         cplen = asc_prt_asc_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4197     } else {
4198         cplen = asc_prt_adv_board_eeprom(shp, cp, ASC_PRTBUF_SIZE);
4199     }
4200     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4201     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4202     totcnt += cnt;
4203     leftlen -= cnt;
4204     if (leftlen == 0) {
4205         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4206         return totcnt;
4207     }
4208     advoffset += cplen;
4209     curbuf += cnt;
4210
4211     /*
4212      * Display driver configuration and information for the board.
4213      */
4214     cp = boardp->prtbuf;
4215     cplen = asc_prt_driver_conf(shp, cp, ASC_PRTBUF_SIZE);
4216     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4217     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4218     totcnt += cnt;
4219     leftlen -= cnt;
4220     if (leftlen == 0) {
4221         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4222         return totcnt;
4223     }
4224     advoffset += cplen;
4225     curbuf += cnt;
4226
4227 #ifdef ADVANSYS_STATS
4228     /*
4229      * Display driver statistics for the board.
4230      */
4231     cp = boardp->prtbuf;
4232     cplen = asc_prt_board_stats(shp, cp, ASC_PRTBUF_SIZE);
4233     ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4234     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4235     totcnt += cnt;
4236     leftlen -= cnt;
4237     if (leftlen == 0) {
4238         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4239         return totcnt;
4240     }
4241     advoffset += cplen;
4242     curbuf += cnt;
4243
4244     /*
4245      * Display driver statistics for each target.
4246      */
4247     for (tgt_id = 0; tgt_id <= ADV_MAX_TID; tgt_id++) {
4248       cp = boardp->prtbuf;
4249       cplen = asc_prt_target_stats(shp, tgt_id, cp, ASC_PRTBUF_SIZE);
4250       ASC_ASSERT(cplen <= ASC_PRTBUF_SIZE);
4251       cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4252       totcnt += cnt;
4253       leftlen -= cnt;
4254       if (leftlen == 0) {
4255         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4256         return totcnt;
4257       }
4258       advoffset += cplen;
4259       curbuf += cnt;
4260     }
4261 #endif /* ADVANSYS_STATS */
4262
4263     /*
4264      * Display Asc Library dynamic configuration information
4265      * for the board.
4266      */
4267     cp = boardp->prtbuf;
4268     if (ASC_NARROW_BOARD(boardp)) {
4269         cplen = asc_prt_asc_board_info(shp, cp, ASC_PRTBUF_SIZE);
4270     } else {
4271         cplen = asc_prt_adv_board_info(shp, cp, ASC_PRTBUF_SIZE);
4272     }
4273     ASC_ASSERT(cplen < ASC_PRTBUF_SIZE);
4274     cnt = asc_proc_copy(advoffset, offset, curbuf, leftlen, cp, cplen);
4275     totcnt += cnt;
4276     leftlen -= cnt;
4277     if (leftlen == 0) {
4278         ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4279         return totcnt;
4280     }
4281     advoffset += cplen;
4282     curbuf += cnt;
4283
4284     ASC_DBG1(1, "advansys_proc_info: totcnt %d\n", totcnt);
4285
4286     return totcnt;
4287 }
4288 #endif /* CONFIG_PROC_FS */
4289
4290 /*
4291  * advansys_detect()
4292  *
4293  * Detect function for AdvanSys adapters.
4294  *
4295  * Argument is a pointer to the host driver's scsi_hosts entry.
4296  *
4297  * Return number of adapters found.
4298  *
4299  * Note: Because this function is called during system initialization
4300  * it must not call SCSI mid-level functions including scsi_malloc()
4301  * and scsi_free().
4302  */
4303 int __init
4304 advansys_detect(Scsi_Host_Template *tpnt)
4305 {
4306     static int          detect_called = ASC_FALSE;
4307     int                 iop;
4308     int                 bus;
4309     struct Scsi_Host    *shp = NULL;
4310     asc_board_t         *boardp = NULL;
4311     ASC_DVC_VAR         *asc_dvc_varp = NULL;
4312     ADV_DVC_VAR         *adv_dvc_varp = NULL;
4313     adv_sgblk_t         *sgp = NULL;
4314     int                 ioport = 0;
4315     int                 share_irq = FALSE;
4316     int                 iolen = 0;
4317 #ifdef CONFIG_PCI
4318     int                 pci_init_search = 0;
4319     struct pci_dev      *pci_devicep[ASC_NUM_BOARD_SUPPORTED];
4320     int                 pci_card_cnt_max = 0;
4321     int                 pci_card_cnt = 0;
4322     struct device       *dev = NULL;
4323     struct pci_dev      *pci_devp = NULL;
4324     int                 pci_device_id_cnt = 0;
4325     unsigned int        pci_device_id[ASC_PCI_DEVICE_ID_CNT] = {
4326                                     ASC_PCI_DEVICE_ID_1100,
4327                                     ASC_PCI_DEVICE_ID_1200,
4328                                     ASC_PCI_DEVICE_ID_1300,
4329                                     ASC_PCI_DEVICE_ID_2300,
4330                                     ASC_PCI_DEVICE_ID_2500,
4331                                     ASC_PCI_DEVICE_ID_2700
4332                         };
4333     ADV_PADDR           pci_memory_address;
4334 #endif /* CONFIG_PCI */
4335     int                 warn_code, err_code;
4336     int                 ret;
4337
4338     if (detect_called == ASC_FALSE) {
4339         detect_called = ASC_TRUE;
4340     } else {
4341         printk("AdvanSys SCSI: advansys_detect() multiple calls ignored\n");
4342         return 0;
4343     }
4344
4345     ASC_DBG(1, "advansys_detect: begin\n");
4346
4347     asc_board_count = 0;
4348
4349     /*
4350      * If I/O port probing has been modified, then verify and
4351      * clean-up the 'asc_ioport' list.
4352      */
4353     if (asc_iopflag == ASC_TRUE) {
4354         for (ioport = 0; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4355             ASC_DBG2(1, "advansys_detect: asc_ioport[%d] 0x%x\n",
4356                 ioport, asc_ioport[ioport]);
4357             if (asc_ioport[ioport] != 0) {
4358                 for (iop = 0; iop < ASC_IOADR_TABLE_MAX_IX; iop++) {
4359                     if (_asc_def_iop_base[iop] == asc_ioport[ioport]) {
4360                         break;
4361                     }
4362                 }
4363                 if (iop == ASC_IOADR_TABLE_MAX_IX) {
4364                     printk(
4365 "AdvanSys SCSI: specified I/O Port 0x%X is invalid\n",
4366                         asc_ioport[ioport]);
4367                     asc_ioport[ioport] = 0;
4368                 }
4369             }
4370         }
4371         ioport = 0;
4372     }
4373
4374     for (bus = 0; bus < ASC_NUM_BUS; bus++) {
4375
4376         ASC_DBG2(1, "advansys_detect: bus search type %d (%s)\n",
4377             bus, asc_bus_name[bus]);
4378         iop = 0;
4379
4380         while (asc_board_count < ASC_NUM_BOARD_SUPPORTED) {
4381
4382             ASC_DBG1(2, "advansys_detect: asc_board_count %d\n",
4383                 asc_board_count);
4384
4385             switch (asc_bus[bus]) {
4386             case ASC_IS_ISA:
4387             case ASC_IS_VL:
4388 #ifdef CONFIG_ISA
4389                 if (asc_iopflag == ASC_FALSE) {
4390                     iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4391                 } else {
4392                     /*
4393                      * ISA and VL I/O port scanning has either been
4394                      * eliminated or limited to selected ports on
4395                      * the LILO command line, /etc/lilo.conf, or
4396                      * by setting variables when the module was loaded.
4397                      */
4398                     ASC_DBG(1, "advansys_detect: I/O port scanning modified\n");
4399                 ioport_try_again:
4400                     iop = 0;
4401                     for (; ioport < ASC_NUM_IOPORT_PROBE; ioport++) {
4402                         if ((iop = asc_ioport[ioport]) != 0) {
4403                             break;
4404                         }
4405                     }
4406                     if (iop) {
4407                         ASC_DBG1(1,
4408                                 "advansys_detect: probing I/O port 0x%x...\n",
4409                             iop);
4410                         if (check_region(iop, ASC_IOADR_GAP) != 0) {
4411                             printk(
4412 "AdvanSys SCSI: specified I/O Port 0x%X is busy\n", iop);
4413                             /* Don't try this I/O port twice. */
4414                             asc_ioport[ioport] = 0;
4415                             goto ioport_try_again;
4416                         } else if (AscFindSignature(iop) == ASC_FALSE) {
4417                             printk(
4418 "AdvanSys SCSI: specified I/O Port 0x%X has no adapter\n", iop);
4419                             /* Don't try this I/O port twice. */
4420                             asc_ioport[ioport] = 0;
4421                             goto ioport_try_again;
4422                         } else {
4423                             /*
4424                              * If this isn't an ISA board, then it must be
4425                              * a VL board. If currently looking an ISA
4426                              * board is being looked for then try for
4427                              * another ISA board in 'asc_ioport'.
4428                              */
4429                             if (asc_bus[bus] == ASC_IS_ISA &&
4430                                 (AscGetChipVersion(iop, ASC_IS_ISA) &
4431                                  ASC_CHIP_VER_ISA_BIT) == 0) {
4432                                  /*
4433                                   * Don't clear 'asc_ioport[ioport]'. Try
4434                                   * this board again for VL. Increment
4435                                   * 'ioport' past this board.
4436                                   */
4437                                  ioport++;
4438                                  goto ioport_try_again;
4439                             }
4440                         }
4441                         /*
4442                          * This board appears good, don't try the I/O port
4443                          * again by clearing its value. Increment 'ioport'
4444                          * for the next iteration.
4445                          */
4446                         asc_ioport[ioport++] = 0;
4447                     }
4448                 }
4449 #endif /* CONFIG_ISA */
4450                 break;
4451
4452             case ASC_IS_EISA:
4453 #ifdef CONFIG_ISA
4454                 iop = AscSearchIOPortAddr(iop, asc_bus[bus]);
4455 #endif /* CONFIG_ISA */
4456                 break;
4457
4458             case ASC_IS_PCI:
4459 #ifdef CONFIG_PCI
4460                 if (pci_init_search == 0) {
4461                     int i, j;
4462
4463                     pci_init_search = 1;
4464
4465                     /* Find all PCI cards. */
4466                     while (pci_device_id_cnt < ASC_PCI_DEVICE_ID_CNT) {
4467                         if ((pci_devp = pci_find_device(ASC_PCI_VENDORID,
4468                             pci_device_id[pci_device_id_cnt], pci_devp)) ==
4469                             NULL) {
4470                             pci_device_id_cnt++;
4471                         } else {
4472                             if (pci_enable_device(pci_devp) == 0) {
4473                                 pci_devicep[pci_card_cnt_max++] = pci_devp;
4474                             }
4475                         }
4476                     }
4477
4478                     /*
4479                      * Sort PCI cards in ascending order by PCI Bus, Slot,
4480                      * and Device Number.
4481                      */
4482                     for (i = 0; i < pci_card_cnt_max - 1; i++)
4483                     {
4484                         for (j = i + 1; j < pci_card_cnt_max; j++) {
4485                             if ((pci_devicep[j]->bus->number <
4486                                  pci_devicep[i]->bus->number) ||
4487                                 ((pci_devicep[j]->bus->number ==
4488                                   pci_devicep[i]->bus->number) &&
4489                                   (pci_devicep[j]->devfn <
4490                                    pci_devicep[i]->devfn))) {
4491                                 pci_devp = pci_devicep[i];
4492                                 pci_devicep[i] = pci_devicep[j];
4493                                 pci_devicep[j] = pci_devp;
4494                             }
4495                         }
4496                     }
4497
4498                     pci_card_cnt = 0;
4499                 } else {
4500                     pci_card_cnt++;
4501                 }
4502
4503                 if (pci_card_cnt == pci_card_cnt_max) {
4504                     iop = 0;
4505                 } else {
4506                     pci_devp = pci_devicep[pci_card_cnt];
4507
4508                     ASC_DBG2(2,
4509                         "advansys_detect: devfn %d, bus number %d\n",
4510                         pci_devp->devfn, pci_devp->bus->number);
4511                     iop = pci_resource_start(pci_devp, 0);
4512                     ASC_DBG2(1,
4513                         "advansys_detect: vendorID %X, deviceID %X\n",
4514                         pci_devp->vendor, pci_devp->device);
4515                     ASC_DBG2(2, "advansys_detect: iop %X, irqLine %d\n",
4516                         iop, pci_devp->irq);
4517                 }
4518                 if(pci_devp)
4519                     dev = &pci_devp->dev;
4520
4521 #endif /* CONFIG_PCI */
4522                 break;
4523
4524             default:
4525                 ASC_PRINT1("advansys_detect: unknown bus type: %d\n",
4526                     asc_bus[bus]);
4527                 break;
4528             }
4529             ASC_DBG1(1, "advansys_detect: iop 0x%x\n", iop);
4530
4531             /*
4532              * Adapter not found, try next bus type.
4533              */
4534             if (iop == 0) {
4535                 break;
4536             }
4537
4538             /*
4539              * Adapter found.
4540              *
4541              * Register the adapter, get its configuration, and
4542              * initialize it.
4543              */
4544             ASC_DBG(2, "advansys_detect: scsi_register()\n");
4545             shp = scsi_register(tpnt, sizeof(asc_board_t));
4546
4547             if (shp == NULL) {
4548                 continue;
4549             }
4550
4551             scsi_set_device(shp, dev);
4552
4553             /* Save a pointer to the Scsi_Host of each board found. */
4554             asc_host[asc_board_count++] = shp;
4555
4556             /* Initialize private per board data */
4557             boardp = ASC_BOARDP(shp);
4558             memset(boardp, 0, sizeof(asc_board_t));
4559             boardp->id = asc_board_count - 1;
4560
4561             /* Initialize spinlock. */
4562             boardp->lock = SPIN_LOCK_UNLOCKED;
4563
4564             /*
4565              * Handle both narrow and wide boards.
4566              *
4567              * If a Wide board was detected, set the board structure
4568              * wide board flag. Set-up the board structure based on
4569              * the board type.
4570              */
4571 #ifdef CONFIG_PCI
4572             if (asc_bus[bus] == ASC_IS_PCI &&
4573                 (pci_devp->device == ASC_PCI_DEVICE_ID_2300 ||
4574                  pci_devp->device == ASC_PCI_DEVICE_ID_2500 ||
4575                  pci_devp->device == ASC_PCI_DEVICE_ID_2700))
4576             {
4577                 boardp->flags |= ASC_IS_WIDE_BOARD;
4578             }
4579 #endif /* CONFIG_PCI */
4580
4581             if (ASC_NARROW_BOARD(boardp)) {
4582                 ASC_DBG(1, "advansys_detect: narrow board\n");
4583                 asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
4584                 asc_dvc_varp->bus_type = asc_bus[bus];
4585                 asc_dvc_varp->drv_ptr = boardp;
4586                 asc_dvc_varp->cfg = &boardp->dvc_cfg.asc_dvc_cfg;
4587                 asc_dvc_varp->cfg->overrun_buf = &overrun_buf[0];
4588                 asc_dvc_varp->iop_base = iop;
4589                 asc_dvc_varp->isr_callback = asc_isr_callback;
4590             } else {
4591                 ASC_DBG(1, "advansys_detect: wide board\n");
4592                 adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
4593                 adv_dvc_varp->drv_ptr = boardp;
4594                 adv_dvc_varp->cfg = &boardp->dvc_cfg.adv_dvc_cfg;
4595                 adv_dvc_varp->isr_callback = adv_isr_callback;
4596                 adv_dvc_varp->async_callback = adv_async_callback;
4597 #ifdef CONFIG_PCI
4598                 if (pci_devp->device == ASC_PCI_DEVICE_ID_2300)
4599                 {
4600                     ASC_DBG(1, "advansys_detect: ASC-3550\n");
4601                     adv_dvc_varp->chip_type = ADV_CHIP_ASC3550;
4602                 } else if (pci_devp->device == ASC_PCI_DEVICE_ID_2500)
4603                 {
4604                     ASC_DBG(1, "advansys_detect: ASC-38C0800\n");
4605                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C0800;
4606                 } else
4607                 {
4608                     ASC_DBG(1, "advansys_detect: ASC-38C1600\n");
4609                     adv_dvc_varp->chip_type = ADV_CHIP_ASC38C1600;
4610                 }
4611 #endif /* CONFIG_PCI */
4612
4613                 /*
4614                  * Map the board's registers into virtual memory for
4615                  * PCI slave access. Only memory accesses are used to
4616                  * access the board's registers.
4617                  *
4618                  * Note: The PCI register base address is not always
4619                  * page aligned, but the address passed to ioremap()
4620                  * must be page aligned. It is guaranteed that the
4621                  * PCI register base address will not cross a page
4622                  * boundary.
4623                  */
4624                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4625                 {
4626                     iolen = ADV_3550_IOLEN;
4627                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4628                 {
4629                     iolen = ADV_38C0800_IOLEN;
4630                 } else
4631                 {
4632                     iolen = ADV_38C1600_IOLEN;
4633                 }
4634 #ifdef CONFIG_PCI
4635                 pci_memory_address = pci_resource_start(pci_devp, 1);
4636                 ASC_DBG1(1, "advansys_detect: pci_memory_address: 0x%lx\n",
4637                     (ulong) pci_memory_address);
4638                 if ((boardp->ioremap_addr =
4639                     ioremap(pci_memory_address & PAGE_MASK,
4640                          PAGE_SIZE)) == 0) {
4641                    ASC_PRINT3(
4642 "advansys_detect: board %d: ioremap(%x, %d) returned NULL\n",
4643                        boardp->id, pci_memory_address, iolen);
4644                    scsi_unregister(shp);
4645                    asc_board_count--;
4646                    continue;
4647                 }
4648                 ASC_DBG1(1, "advansys_detect: ioremap_addr: 0x%lx\n",
4649                     (ulong) boardp->ioremap_addr);
4650                 adv_dvc_varp->iop_base = (AdvPortAddr)
4651                     (boardp->ioremap_addr +
4652                      (pci_memory_address - (pci_memory_address & PAGE_MASK)));
4653                 ASC_DBG1(1, "advansys_detect: iop_base: 0x%lx\n",
4654                     adv_dvc_varp->iop_base);
4655 #endif /* CONFIG_PCI */
4656
4657                 /*
4658                  * Even though it isn't used to access wide boards, other
4659                  * than for the debug line below, save I/O Port address so
4660                  * that it can be reported.
4661                  */
4662                 boardp->ioport = iop;
4663
4664                 ASC_DBG2(1,
4665 "advansys_detect: iopb_chip_id_1 0x%x, iopw_chip_id_0 0x%x\n",
4666                     (ushort) inp(iop + 1), (ushort) inpw(iop));
4667             }
4668
4669 #ifdef CONFIG_PROC_FS
4670             /*
4671              * Allocate buffer for printing information from
4672              * /proc/scsi/advansys/[0...].
4673              */
4674             if ((boardp->prtbuf =
4675                 kmalloc(ASC_PRTBUF_SIZE, GFP_ATOMIC)) == NULL) {
4676                 ASC_PRINT3(
4677 "advansys_detect: board %d: kmalloc(%d, %d) returned NULL\n",
4678                     boardp->id, ASC_PRTBUF_SIZE, GFP_ATOMIC);
4679                 scsi_unregister(shp);
4680                 asc_board_count--;
4681                 continue;
4682             }
4683 #endif /* CONFIG_PROC_FS */
4684
4685             if (ASC_NARROW_BOARD(boardp)) {
4686                 asc_dvc_varp->cfg->dev = dev;
4687                 /*
4688                  * Set the board bus type and PCI IRQ before
4689                  * calling AscInitGetConfig().
4690                  */
4691                 switch (asc_dvc_varp->bus_type) {
4692 #ifdef CONFIG_ISA
4693                 case ASC_IS_ISA:
4694                     shp->unchecked_isa_dma = TRUE;
4695                     share_irq = FALSE;
4696                     break;
4697                 case ASC_IS_VL:
4698                     shp->unchecked_isa_dma = FALSE;
4699                     share_irq = FALSE;
4700                     break;
4701                 case ASC_IS_EISA:
4702                     shp->unchecked_isa_dma = FALSE;
4703                     share_irq = TRUE;
4704                     break;
4705 #endif /* CONFIG_ISA */
4706 #ifdef CONFIG_PCI
4707                 case ASC_IS_PCI:
4708                     shp->irq = asc_dvc_varp->irq_no = pci_devp->irq;
4709                     asc_dvc_varp->cfg->pci_slot_info =
4710                         ASC_PCI_MKID(pci_devp->bus->number,
4711                             PCI_SLOT(pci_devp->devfn),
4712                             PCI_FUNC(pci_devp->devfn));
4713                     shp->unchecked_isa_dma = FALSE;
4714                     share_irq = TRUE;
4715                     break;
4716 #endif /* CONFIG_PCI */
4717                 default:
4718                     ASC_PRINT2(
4719 "advansys_detect: board %d: unknown adapter type: %d\n",
4720                         boardp->id, asc_dvc_varp->bus_type);
4721                     shp->unchecked_isa_dma = TRUE;
4722                     share_irq = FALSE;
4723                     break;
4724                 }
4725             } else {
4726                 adv_dvc_varp->cfg->dev = dev;
4727                 /*
4728                  * For Wide boards set PCI information before calling
4729                  * AdvInitGetConfig().
4730                  */
4731 #ifdef CONFIG_PCI
4732                 shp->irq = adv_dvc_varp->irq_no = pci_devp->irq;
4733                 adv_dvc_varp->cfg->pci_slot_info =
4734                     ASC_PCI_MKID(pci_devp->bus->number,
4735                         PCI_SLOT(pci_devp->devfn),
4736                         PCI_FUNC(pci_devp->devfn));
4737                 shp->unchecked_isa_dma = FALSE;
4738                 share_irq = TRUE;
4739 #endif /* CONFIG_PCI */
4740             }
4741
4742             /*
4743              * Read the board configuration.
4744              */
4745             if (ASC_NARROW_BOARD(boardp)) {
4746                  /*
4747                   * NOTE: AscInitGetConfig() may change the board's
4748                   * bus_type value. The asc_bus[bus] value should no
4749                   * longer be used. If the bus_type field must be
4750                   * referenced only use the bit-wise AND operator "&".
4751                   */
4752                 ASC_DBG(2, "advansys_detect: AscInitGetConfig()\n");
4753                 switch(ret = AscInitGetConfig(asc_dvc_varp)) {
4754                 case 0:    /* No error */
4755                     break;
4756                 case ASC_WARN_IO_PORT_ROTATE:
4757                     ASC_PRINT1(
4758 "AscInitGetConfig: board %d: I/O port address modified\n",
4759                         boardp->id);
4760                     break;
4761                 case ASC_WARN_AUTO_CONFIG:
4762                     ASC_PRINT1(
4763 "AscInitGetConfig: board %d: I/O port increment switch enabled\n",
4764                         boardp->id);
4765                     break;
4766                 case ASC_WARN_EEPROM_CHKSUM:
4767                     ASC_PRINT1(
4768 "AscInitGetConfig: board %d: EEPROM checksum error\n",
4769                         boardp->id);
4770                     break;
4771                 case ASC_WARN_IRQ_MODIFIED:
4772                     ASC_PRINT1(
4773 "AscInitGetConfig: board %d: IRQ modified\n",
4774                         boardp->id);
4775                     break;
4776                 case ASC_WARN_CMD_QNG_CONFLICT:
4777                     ASC_PRINT1(
4778 "AscInitGetConfig: board %d: tag queuing enabled w/o disconnects\n",
4779                         boardp->id);
4780                     break;
4781                 default:
4782                     ASC_PRINT2(
4783 "AscInitGetConfig: board %d: unknown warning: 0x%x\n",
4784                         boardp->id, ret);
4785                     break;
4786                 }
4787                 if ((err_code = asc_dvc_varp->err_code) != 0) {
4788                     ASC_PRINT3(
4789 "AscInitGetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4790                         boardp->id, asc_dvc_varp->init_state,
4791                         asc_dvc_varp->err_code);
4792                 }
4793             } else {
4794                 ASC_DBG(2, "advansys_detect: AdvInitGetConfig()\n");
4795                 if ((ret = AdvInitGetConfig(adv_dvc_varp)) != 0) {
4796                     ASC_PRINT2("AdvInitGetConfig: board %d: warning: 0x%x\n",
4797                         boardp->id, ret);
4798                 }
4799                 if ((err_code = adv_dvc_varp->err_code) != 0) {
4800                     ASC_PRINT2(
4801 "AdvInitGetConfig: board %d error: err_code 0x%x\n",
4802                         boardp->id, adv_dvc_varp->err_code);
4803                 }
4804             }
4805
4806             if (err_code != 0) {
4807 #ifdef CONFIG_PROC_FS
4808                 kfree(boardp->prtbuf);
4809 #endif /* CONFIG_PROC_FS */
4810                 scsi_unregister(shp);
4811                 asc_board_count--;
4812                 continue;
4813             }
4814
4815             /*
4816              * Save the EEPROM configuration so that it can be displayed
4817              * from /proc/scsi/advansys/[0...].
4818              */
4819             if (ASC_NARROW_BOARD(boardp)) {
4820
4821                 ASCEEP_CONFIG *ep;
4822
4823                 /*
4824                  * Set the adapter's target id bit in the 'init_tidmask' field.
4825                  */
4826                 boardp->init_tidmask |=
4827                     ADV_TID_TO_TIDMASK(asc_dvc_varp->cfg->chip_scsi_id);
4828
4829                 /*
4830                  * Save EEPROM settings for the board.
4831                  */
4832                 ep = &boardp->eep_config.asc_eep;
4833
4834                 ep->init_sdtr = asc_dvc_varp->cfg->sdtr_enable;
4835                 ep->disc_enable = asc_dvc_varp->cfg->disc_enable;
4836                 ep->use_cmd_qng = asc_dvc_varp->cfg->cmd_qng_enabled;
4837                 ASC_EEP_SET_DMA_SPD(ep, asc_dvc_varp->cfg->isa_dma_speed);
4838                 ep->start_motor = asc_dvc_varp->start_motor;
4839                 ep->cntl = asc_dvc_varp->dvc_cntl;
4840                 ep->no_scam = asc_dvc_varp->no_scam;
4841                 ep->max_total_qng = asc_dvc_varp->max_total_qng;
4842                 ASC_EEP_SET_CHIP_ID(ep, asc_dvc_varp->cfg->chip_scsi_id);
4843                 /* 'max_tag_qng' is set to the same value for every device. */
4844                 ep->max_tag_qng = asc_dvc_varp->cfg->max_tag_qng[0];
4845                 ep->adapter_info[0] = asc_dvc_varp->cfg->adapter_info[0];
4846                 ep->adapter_info[1] = asc_dvc_varp->cfg->adapter_info[1];
4847                 ep->adapter_info[2] = asc_dvc_varp->cfg->adapter_info[2];
4848                 ep->adapter_info[3] = asc_dvc_varp->cfg->adapter_info[3];
4849                 ep->adapter_info[4] = asc_dvc_varp->cfg->adapter_info[4];
4850                 ep->adapter_info[5] = asc_dvc_varp->cfg->adapter_info[5];
4851
4852                /*
4853                 * Modify board configuration.
4854                 */
4855                 ASC_DBG(2, "advansys_detect: AscInitSetConfig()\n");
4856                 switch (ret = AscInitSetConfig(asc_dvc_varp)) {
4857                 case 0:    /* No error. */
4858                     break;
4859                 case ASC_WARN_IO_PORT_ROTATE:
4860                     ASC_PRINT1(
4861 "AscInitSetConfig: board %d: I/O port address modified\n",
4862                         boardp->id);
4863                     break;
4864                 case ASC_WARN_AUTO_CONFIG:
4865                     ASC_PRINT1(
4866 "AscInitSetConfig: board %d: I/O port increment switch enabled\n",
4867                         boardp->id);
4868                     break;
4869                 case ASC_WARN_EEPROM_CHKSUM:
4870                     ASC_PRINT1(
4871 "AscInitSetConfig: board %d: EEPROM checksum error\n",
4872                         boardp->id);
4873                     break;
4874                 case ASC_WARN_IRQ_MODIFIED:
4875                     ASC_PRINT1(
4876 "AscInitSetConfig: board %d: IRQ modified\n",
4877                         boardp->id);
4878                     break;
4879                 case ASC_WARN_CMD_QNG_CONFLICT:
4880                     ASC_PRINT1(
4881 "AscInitSetConfig: board %d: tag queuing w/o disconnects\n",
4882                         boardp->id);
4883                     break;
4884                 default:
4885                     ASC_PRINT2(
4886 "AscInitSetConfig: board %d: unknown warning: 0x%x\n",
4887                         boardp->id, ret);
4888                     break;
4889                 }
4890                 if (asc_dvc_varp->err_code != 0) {
4891                     ASC_PRINT3(
4892 "AscInitSetConfig: board %d error: init_state 0x%x, err_code 0x%x\n",
4893                         boardp->id, asc_dvc_varp->init_state,
4894                         asc_dvc_varp->err_code);
4895 #ifdef CONFIG_PROC_FS
4896                     kfree(boardp->prtbuf);
4897 #endif /* CONFIG_PROC_FS */
4898                     scsi_unregister(shp);
4899                     asc_board_count--;
4900                     continue;
4901                 }
4902
4903                 /*
4904                  * Finish initializing the 'Scsi_Host' structure.
4905                  */
4906                 /* AscInitSetConfig() will set the IRQ for non-PCI boards. */
4907                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI) == 0) {
4908                     shp->irq = asc_dvc_varp->irq_no;
4909                 }
4910             } else {
4911                 ADVEEP_3550_CONFIG      *ep_3550;
4912                 ADVEEP_38C0800_CONFIG   *ep_38C0800;
4913                 ADVEEP_38C1600_CONFIG   *ep_38C1600;
4914
4915                 /*
4916                  * Save Wide EEP Configuration Information.
4917                  */
4918                 if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
4919                 {
4920                     ep_3550 = &boardp->eep_config.adv_3550_eep;
4921
4922                     ep_3550->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4923                     ep_3550->max_host_qng = adv_dvc_varp->max_host_qng;
4924                     ep_3550->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4925                     ep_3550->termination = adv_dvc_varp->cfg->termination;
4926                     ep_3550->disc_enable = adv_dvc_varp->cfg->disc_enable;
4927                     ep_3550->bios_ctrl = adv_dvc_varp->bios_ctrl;
4928                     ep_3550->wdtr_able = adv_dvc_varp->wdtr_able;
4929                     ep_3550->sdtr_able = adv_dvc_varp->sdtr_able;
4930                     ep_3550->ultra_able = adv_dvc_varp->ultra_able;
4931                     ep_3550->tagqng_able = adv_dvc_varp->tagqng_able;
4932                     ep_3550->start_motor = adv_dvc_varp->start_motor;
4933                     ep_3550->scsi_reset_delay = adv_dvc_varp->scsi_reset_wait;
4934                     ep_3550->serial_number_word1 =
4935                         adv_dvc_varp->cfg->serial1;
4936                     ep_3550->serial_number_word2 =
4937                         adv_dvc_varp->cfg->serial2;
4938                     ep_3550->serial_number_word3 =
4939                         adv_dvc_varp->cfg->serial3;
4940                 } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
4941                 {
4942                     ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
4943
4944                     ep_38C0800->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4945                     ep_38C0800->max_host_qng = adv_dvc_varp->max_host_qng;
4946                     ep_38C0800->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4947                     ep_38C0800->termination_lvd =
4948                         adv_dvc_varp->cfg->termination;
4949                     ep_38C0800->disc_enable = adv_dvc_varp->cfg->disc_enable;
4950                     ep_38C0800->bios_ctrl = adv_dvc_varp->bios_ctrl;
4951                     ep_38C0800->wdtr_able = adv_dvc_varp->wdtr_able;
4952                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4953                     ep_38C0800->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4954                     ep_38C0800->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4955                     ep_38C0800->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4956                     ep_38C0800->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4957                     ep_38C0800->tagqng_able = adv_dvc_varp->tagqng_able;
4958                     ep_38C0800->start_motor = adv_dvc_varp->start_motor;
4959                     ep_38C0800->scsi_reset_delay =
4960                         adv_dvc_varp->scsi_reset_wait;
4961                     ep_38C0800->serial_number_word1 =
4962                         adv_dvc_varp->cfg->serial1;
4963                     ep_38C0800->serial_number_word2 =
4964                         adv_dvc_varp->cfg->serial2;
4965                     ep_38C0800->serial_number_word3 =
4966                         adv_dvc_varp->cfg->serial3;
4967                 } else
4968                 {
4969                     ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
4970
4971                     ep_38C1600->adapter_scsi_id = adv_dvc_varp->chip_scsi_id;
4972                     ep_38C1600->max_host_qng = adv_dvc_varp->max_host_qng;
4973                     ep_38C1600->max_dvc_qng = adv_dvc_varp->max_dvc_qng;
4974                     ep_38C1600->termination_lvd =
4975                         adv_dvc_varp->cfg->termination;
4976                     ep_38C1600->disc_enable = adv_dvc_varp->cfg->disc_enable;
4977                     ep_38C1600->bios_ctrl = adv_dvc_varp->bios_ctrl;
4978                     ep_38C1600->wdtr_able = adv_dvc_varp->wdtr_able;
4979                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4980                     ep_38C1600->sdtr_speed1 = adv_dvc_varp->sdtr_speed1;
4981                     ep_38C1600->sdtr_speed2 = adv_dvc_varp->sdtr_speed2;
4982                     ep_38C1600->sdtr_speed3 = adv_dvc_varp->sdtr_speed3;
4983                     ep_38C1600->sdtr_speed4 = adv_dvc_varp->sdtr_speed4;
4984                     ep_38C1600->tagqng_able = adv_dvc_varp->tagqng_able;
4985                     ep_38C1600->start_motor = adv_dvc_varp->start_motor;
4986                     ep_38C1600->scsi_reset_delay =
4987                         adv_dvc_varp->scsi_reset_wait;
4988                     ep_38C1600->serial_number_word1 =
4989                         adv_dvc_varp->cfg->serial1;
4990                     ep_38C1600->serial_number_word2 =
4991                         adv_dvc_varp->cfg->serial2;
4992                     ep_38C1600->serial_number_word3 =
4993                         adv_dvc_varp->cfg->serial3;
4994                 }
4995
4996                 /*
4997                  * Set the adapter's target id bit in the 'init_tidmask' field.
4998                  */
4999                 boardp->init_tidmask |=
5000                     ADV_TID_TO_TIDMASK(adv_dvc_varp->chip_scsi_id);
5001
5002                 /*
5003                  * Finish initializing the 'Scsi_Host' structure.
5004                  */
5005                 shp->irq = adv_dvc_varp->irq_no;
5006             }
5007
5008             /*
5009              * Channels are numbered beginning with 0. For AdvanSys one host
5010              * structure supports one channel. Multi-channel boards have a
5011              * separate host structure for each channel.
5012              */
5013             shp->max_channel = 0;
5014             if (ASC_NARROW_BOARD(boardp)) {
5015                 shp->max_id = ASC_MAX_TID + 1;
5016                 shp->max_lun = ASC_MAX_LUN + 1;
5017
5018                 shp->io_port = asc_dvc_varp->iop_base;
5019                 boardp->asc_n_io_port = ASC_IOADR_GAP;
5020                 shp->this_id = asc_dvc_varp->cfg->chip_scsi_id;
5021
5022                 /* Set maximum number of queues the adapter can handle. */
5023                 shp->can_queue = asc_dvc_varp->max_total_qng;
5024             } else {
5025                 shp->max_id = ADV_MAX_TID + 1;
5026                 shp->max_lun = ADV_MAX_LUN + 1;
5027
5028                 /*
5029                  * Save the I/O Port address and length even though
5030                  * I/O ports are not used to access Wide boards.
5031                  * Instead the Wide boards are accessed with
5032                  * PCI Memory Mapped I/O.
5033                  */
5034                 shp->io_port = iop;
5035                 boardp->asc_n_io_port = iolen;
5036
5037                 shp->this_id = adv_dvc_varp->chip_scsi_id;
5038
5039                 /* Set maximum number of queues the adapter can handle. */
5040                 shp->can_queue = adv_dvc_varp->max_host_qng;
5041             }
5042
5043             /*
5044              * 'n_io_port' currently is one byte.
5045              *
5046              * Set a value to 'n_io_port', but never referenced it because
5047              * it may be truncated.
5048              */
5049             shp->n_io_port = boardp->asc_n_io_port <= 255 ?
5050                 boardp->asc_n_io_port : 255;
5051
5052             /*
5053              * Following v1.3.89, 'cmd_per_lun' is no longer needed
5054              * and should be set to zero.
5055              *
5056              * But because of a bug introduced in v1.3.89 if the driver is
5057              * compiled as a module and 'cmd_per_lun' is zero, the Mid-Level
5058              * SCSI function 'allocate_device' will panic. To allow the driver
5059              * to work as a module in these kernels set 'cmd_per_lun' to 1.
5060              *
5061              * Note: This is wrong.  cmd_per_lun should be set to the depth
5062              * you want on untagged devices always.
5063 #ifdef MODULE
5064              */
5065             shp->cmd_per_lun = 1;
5066 /* #else
5067             shp->cmd_per_lun = 0;
5068 #endif */
5069
5070             /*
5071              * Set the maximum number of scatter-gather elements the
5072              * adapter can handle.
5073              */
5074             if (ASC_NARROW_BOARD(boardp)) {
5075                 /*
5076                  * Allow two commands with 'sg_tablesize' scatter-gather
5077                  * elements to be executed simultaneously. This value is
5078                  * the theoretical hardware limit. It may be decreased
5079                  * below.
5080                  */
5081                 shp->sg_tablesize =
5082                     (((asc_dvc_varp->max_total_qng - 2) / 2) *
5083                     ASC_SG_LIST_PER_Q) + 1;
5084             } else {
5085                 shp->sg_tablesize = ADV_MAX_SG_LIST;
5086             }
5087
5088             /*
5089              * The value of 'sg_tablesize' can not exceed the SCSI
5090              * mid-level driver definition of SG_ALL. SG_ALL also
5091              * must not be exceeded, because it is used to define the
5092              * size of the scatter-gather table in 'struct asc_sg_head'.
5093              */
5094             if (shp->sg_tablesize > SG_ALL) {
5095                 shp->sg_tablesize = SG_ALL;
5096             }
5097
5098             ASC_DBG1(1, "advansys_detect: sg_tablesize: %d\n",
5099                 shp->sg_tablesize);
5100
5101             /* BIOS start address. */
5102             if (ASC_NARROW_BOARD(boardp)) {
5103                 shp->base =
5104                         ((ulong) AscGetChipBiosAddress(
5105                             asc_dvc_varp->iop_base,
5106                             asc_dvc_varp->bus_type));
5107             } else {
5108                 /*
5109                  * Fill-in BIOS board variables. The Wide BIOS saves
5110                  * information in LRAM that is used by the driver.
5111                  */
5112                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_SIGNATURE,
5113                     boardp->bios_signature);
5114                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_VERSION,
5115                     boardp->bios_version);
5116                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODESEG,
5117                     boardp->bios_codeseg);
5118                 AdvReadWordLram(adv_dvc_varp->iop_base, BIOS_CODELEN,
5119                     boardp->bios_codelen);
5120
5121                 ASC_DBG2(1,
5122                     "advansys_detect: bios_signature 0x%x, bios_version 0x%x\n",
5123                     boardp->bios_signature, boardp->bios_version);
5124
5125                 ASC_DBG2(1,
5126                     "advansys_detect: bios_codeseg 0x%x, bios_codelen 0x%x\n",
5127                     boardp->bios_codeseg, boardp->bios_codelen);
5128
5129                 /*
5130                  * If the BIOS saved a valid signature, then fill in
5131                  * the BIOS code segment base address.
5132                  */
5133                 if (boardp->bios_signature == 0x55AA) {
5134                     /*
5135                      * Convert x86 realmode code segment to a linear
5136                      * address by shifting left 4.
5137                      */
5138                     shp->base = ((ulong) boardp->bios_codeseg << 4);
5139                 } else {
5140                     shp->base = 0;
5141                 }
5142             }
5143
5144             /*
5145              * Register Board Resources - I/O Port, DMA, IRQ
5146              */
5147
5148             /*
5149              * Register I/O port range.
5150              *
5151              * For Wide boards the I/O ports are not used to access
5152              * the board, but request the region anyway.
5153              *
5154              * 'shp->n_io_port' is not referenced, because it may be truncated.
5155              */
5156             ASC_DBG2(2,
5157                 "advansys_detect: request_region port 0x%lx, len 0x%x\n",
5158                 (ulong) shp->io_port, boardp->asc_n_io_port);
5159             if (request_region(shp->io_port, boardp->asc_n_io_port,
5160                                "advansys") == NULL) {
5161                 ASC_PRINT3(
5162 "advansys_detect: board %d: request_region() failed, port 0x%lx, len 0x%x\n",
5163                     boardp->id, (ulong) shp->io_port, boardp->asc_n_io_port);
5164 #ifdef CONFIG_PROC_FS
5165                 kfree(boardp->prtbuf);
5166 #endif /* CONFIG_PROC_FS */
5167                 scsi_unregister(shp);
5168                 asc_board_count--;
5169                 continue;
5170             }
5171
5172             /* Register DMA Channel for Narrow boards. */
5173             shp->dma_channel = NO_ISA_DMA; /* Default to no ISA DMA. */
5174 #ifdef CONFIG_ISA
5175             if (ASC_NARROW_BOARD(boardp)) {
5176                 /* Register DMA channel for ISA bus. */
5177                 if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5178                     shp->dma_channel = asc_dvc_varp->cfg->isa_dma_channel;
5179                     if ((ret =
5180                          request_dma(shp->dma_channel, "advansys")) != 0) {
5181                         ASC_PRINT3(
5182 "advansys_detect: board %d: request_dma() %d failed %d\n",
5183                             boardp->id, shp->dma_channel, ret);
5184                         release_region(shp->io_port, boardp->asc_n_io_port);
5185 #ifdef CONFIG_PROC_FS
5186                         kfree(boardp->prtbuf);
5187 #endif /* CONFIG_PROC_FS */
5188                         scsi_unregister(shp);
5189                         asc_board_count--;
5190                         continue;
5191                     }
5192                     AscEnableIsaDma(shp->dma_channel);
5193                 }
5194             }
5195 #endif /* CONFIG_ISA */
5196
5197             /* Register IRQ Number. */
5198             ASC_DBG1(2, "advansys_detect: request_irq() %d\n", shp->irq);
5199            /*
5200             * If request_irq() fails with the SA_INTERRUPT flag set,
5201             * then try again without the SA_INTERRUPT flag set. This
5202             * allows IRQ sharing to work even with other drivers that
5203             * do not set the SA_INTERRUPT flag.
5204             *
5205             * If SA_INTERRUPT is not set, then interrupts are enabled
5206             * before the driver interrupt function is called.
5207             */
5208             if (((ret = request_irq(shp->irq, advansys_interrupt,
5209                             SA_INTERRUPT | (share_irq == TRUE ? SA_SHIRQ : 0),
5210                             "advansys", boardp)) != 0) &&
5211                 ((ret = request_irq(shp->irq, advansys_interrupt,
5212                             (share_irq == TRUE ? SA_SHIRQ : 0),
5213                             "advansys", boardp)) != 0))
5214             {
5215                 if (ret == -EBUSY) {
5216                     ASC_PRINT2(
5217 "advansys_detect: board %d: request_irq(): IRQ 0x%x already in use.\n",
5218                         boardp->id, shp->irq);
5219                 } else if (ret == -EINVAL) {
5220                     ASC_PRINT2(
5221 "advansys_detect: board %d: request_irq(): IRQ 0x%x not valid.\n",
5222                         boardp->id, shp->irq);
5223                 } else {
5224                     ASC_PRINT3(
5225 "advansys_detect: board %d: request_irq(): IRQ 0x%x failed with %d\n",
5226                         boardp->id, shp->irq, ret);
5227                 }
5228                 release_region(shp->io_port, boardp->asc_n_io_port);
5229                 iounmap(boardp->ioremap_addr);
5230                 if (shp->dma_channel != NO_ISA_DMA) {
5231                     free_dma(shp->dma_channel);
5232                 }
5233 #ifdef CONFIG_PROC_FS
5234                 kfree(boardp->prtbuf);
5235 #endif /* CONFIG_PROC_FS */
5236                 scsi_unregister(shp);
5237                 asc_board_count--;
5238                 continue;
5239             }
5240
5241             /*
5242              * Initialize board RISC chip and enable interrupts.
5243              */
5244             if (ASC_NARROW_BOARD(boardp)) {
5245                 ASC_DBG(2, "advansys_detect: AscInitAsc1000Driver()\n");
5246                 warn_code = AscInitAsc1000Driver(asc_dvc_varp);
5247                 err_code = asc_dvc_varp->err_code;
5248
5249                 if (warn_code || err_code) {
5250                     ASC_PRINT4(
5251 "advansys_detect: board %d error: init_state 0x%x, warn 0x%x, error 0x%x\n",
5252                         boardp->id, asc_dvc_varp->init_state,
5253                         warn_code, err_code);
5254                 }
5255             } else {
5256                 ADV_CARR_T      *carrp;
5257                 int             req_cnt = 0;
5258                 adv_req_t       *reqp = NULL;
5259                 int             sg_cnt = 0;
5260
5261                 /*
5262                  * Allocate buffer carrier structures. The total size
5263                  * is about 4 KB, so allocate all at once.
5264                  */
5265                 carrp =
5266                     (ADV_CARR_T *) kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
5267                 ASC_DBG1(1, "advansys_detect: carrp 0x%lx\n", (ulong) carrp);
5268
5269                 if (carrp == NULL) {
5270                     goto kmalloc_error;
5271                 }
5272
5273                 /*
5274                  * Allocate up to 'max_host_qng' request structures for
5275                  * the Wide board. The total size is about 16 KB, so
5276                  * allocate all at once. If the allocation fails decrement
5277                  * and try again.
5278                  */
5279                 for (req_cnt = adv_dvc_varp->max_host_qng;
5280                     req_cnt > 0; req_cnt--) {
5281
5282                     reqp = (adv_req_t *)
5283                         kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
5284
5285                     ASC_DBG3(1,
5286                         "advansys_detect: reqp 0x%lx, req_cnt %d, bytes %lu\n",
5287                         (ulong) reqp, req_cnt,
5288                         (ulong) sizeof(adv_req_t) * req_cnt);
5289
5290                     if (reqp != NULL) {
5291                         break;
5292                     }
5293                 }
5294                 if (reqp == NULL)
5295                 {
5296                     goto kmalloc_error;
5297                 }
5298
5299                 /*
5300                  * Allocate up to ADV_TOT_SG_BLOCK request structures for
5301                  * the Wide board. Each structure is about 136 bytes.
5302                  */
5303                 boardp->adv_sgblkp = NULL;
5304                 for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
5305
5306                     sgp = (adv_sgblk_t *)
5307                         kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
5308
5309                     if (sgp == NULL) {
5310                         break;
5311                     }
5312
5313                     sgp->next_sgblkp = boardp->adv_sgblkp;
5314                     boardp->adv_sgblkp = sgp;
5315
5316                 }
5317                 ASC_DBG3(1,
5318                     "advansys_detect: sg_cnt %d * %u = %u bytes\n",
5319                     sg_cnt, sizeof(adv_sgblk_t),
5320                     (unsigned) (sizeof(adv_sgblk_t) * sg_cnt));
5321
5322                 /*
5323                  * If no request structures or scatter-gather structures could
5324                  * be allocated, then return an error. Otherwise continue with
5325                  * initialization.
5326                  */
5327     kmalloc_error:
5328                 if (carrp == NULL)
5329                 {
5330                     ASC_PRINT1(
5331 "advansys_detect: board %d error: failed to kmalloc() carrier buffer.\n",
5332                         boardp->id);
5333                     err_code = ADV_ERROR;
5334                 } else if (reqp == NULL) {
5335                     kfree(carrp);
5336                     ASC_PRINT1(
5337 "advansys_detect: board %d error: failed to kmalloc() adv_req_t buffer.\n",
5338                         boardp->id);
5339                     err_code = ADV_ERROR;
5340                 } else if (boardp->adv_sgblkp == NULL) {
5341                     kfree(carrp);
5342                     kfree(reqp);
5343                     ASC_PRINT1(
5344 "advansys_detect: board %d error: failed to kmalloc() adv_sgblk_t buffers.\n",
5345                         boardp->id);
5346                     err_code = ADV_ERROR;
5347                 } else {
5348
5349                     /* Save carrier buffer pointer. */
5350                     boardp->orig_carrp = carrp;
5351
5352                     /*
5353                      * Save original pointer for kfree() in case the
5354                      * driver is built as a module and can be unloaded.
5355                      */
5356                     boardp->orig_reqp = reqp;
5357
5358                     adv_dvc_varp->carrier_buf = carrp;
5359
5360                     /*
5361                      * Point 'adv_reqp' to the request structures and
5362                      * link them together.
5363                      */
5364                     req_cnt--;
5365                     reqp[req_cnt].next_reqp = NULL;
5366                     for (; req_cnt > 0; req_cnt--) {
5367                         reqp[req_cnt - 1].next_reqp = &reqp[req_cnt];
5368                     }
5369                     boardp->adv_reqp = &reqp[0];
5370
5371                     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5372                     {
5373                         ASC_DBG(2,
5374                             "advansys_detect: AdvInitAsc3550Driver()\n");
5375                         warn_code = AdvInitAsc3550Driver(adv_dvc_varp);
5376                     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800) {
5377                         ASC_DBG(2,
5378                             "advansys_detect: AdvInitAsc38C0800Driver()\n");
5379                         warn_code = AdvInitAsc38C0800Driver(adv_dvc_varp);
5380                     } else {
5381                         ASC_DBG(2,
5382                             "advansys_detect: AdvInitAsc38C1600Driver()\n");
5383                         warn_code = AdvInitAsc38C1600Driver(adv_dvc_varp);
5384                     }
5385                     err_code = adv_dvc_varp->err_code;
5386
5387                     if (warn_code || err_code) {
5388                         ASC_PRINT3(
5389 "advansys_detect: board %d error: warn 0x%x, error 0x%x\n",
5390                             boardp->id, warn_code, err_code);
5391                     }
5392                 }
5393             }
5394
5395             if (err_code != 0) {
5396                 release_region(shp->io_port, boardp->asc_n_io_port);
5397                 if (ASC_WIDE_BOARD(boardp)) {
5398                     iounmap(boardp->ioremap_addr);
5399                     if (boardp->orig_carrp) {
5400                         kfree(boardp->orig_carrp);
5401                         boardp->orig_carrp = NULL;
5402                     }
5403                     if (boardp->orig_reqp) {
5404                         kfree(boardp->orig_reqp);
5405                         boardp->orig_reqp = boardp->adv_reqp = NULL;
5406                     }
5407                     while ((sgp = boardp->adv_sgblkp) != NULL)
5408                     {
5409                         boardp->adv_sgblkp = sgp->next_sgblkp;
5410                         kfree(sgp);
5411                     }
5412                 }
5413                 if (shp->dma_channel != NO_ISA_DMA) {
5414                     free_dma(shp->dma_channel);
5415                 }
5416 #ifdef CONFIG_PROC_FS
5417                 kfree(boardp->prtbuf);
5418 #endif /* CONFIG_PROC_FS */
5419                 free_irq(shp->irq, boardp);
5420                 scsi_unregister(shp);
5421                 asc_board_count--;
5422                 continue;
5423             }
5424             ASC_DBG_PRT_SCSI_HOST(2, shp);
5425         }
5426     }
5427
5428     ASC_DBG1(1, "advansys_detect: done: asc_board_count %d\n", asc_board_count);
5429     return asc_board_count;
5430 }
5431
5432 /*
5433  * advansys_release()
5434  *
5435  * Release resources allocated for a single AdvanSys adapter.
5436  */
5437 int
5438 advansys_release(struct Scsi_Host *shp)
5439 {
5440     asc_board_t    *boardp;
5441
5442     ASC_DBG(1, "advansys_release: begin\n");
5443     boardp = ASC_BOARDP(shp);
5444     free_irq(shp->irq, boardp);
5445     if (shp->dma_channel != NO_ISA_DMA) {
5446         ASC_DBG(1, "advansys_release: free_dma()\n");
5447         free_dma(shp->dma_channel);
5448     }
5449     release_region(shp->io_port, boardp->asc_n_io_port);
5450     if (ASC_WIDE_BOARD(boardp)) {
5451         adv_sgblk_t    *sgp = NULL;
5452
5453         iounmap(boardp->ioremap_addr);
5454         if (boardp->orig_carrp) {
5455             kfree(boardp->orig_carrp);
5456             boardp->orig_carrp = NULL;
5457         }
5458         if (boardp->orig_reqp) {
5459             kfree(boardp->orig_reqp);
5460             boardp->orig_reqp = boardp->adv_reqp = NULL;
5461         }
5462         while ((sgp = boardp->adv_sgblkp) != NULL)
5463         {
5464             boardp->adv_sgblkp = sgp->next_sgblkp;
5465             kfree(sgp);
5466         }
5467     }
5468 #ifdef CONFIG_PROC_FS
5469     ASC_ASSERT(boardp->prtbuf != NULL);
5470     kfree(boardp->prtbuf);
5471 #endif /* CONFIG_PROC_FS */
5472     scsi_unregister(shp);
5473     ASC_DBG(1, "advansys_release: end\n");
5474     return 0;
5475 }
5476
5477 /*
5478  * advansys_info()
5479  *
5480  * Return suitable for printing on the console with the argument
5481  * adapter's configuration information.
5482  *
5483  * Note: The information line should not exceed ASC_INFO_SIZE bytes,
5484  * otherwise the static 'info' array will be overrun.
5485  */
5486 const char *
5487 advansys_info(struct Scsi_Host *shp)
5488 {
5489     static char     info[ASC_INFO_SIZE];
5490     asc_board_t     *boardp;
5491     ASC_DVC_VAR     *asc_dvc_varp;
5492     ADV_DVC_VAR     *adv_dvc_varp;
5493     char            *busname;
5494     int             iolen;
5495     char            *widename = NULL;
5496
5497     boardp = ASC_BOARDP(shp);
5498     if (ASC_NARROW_BOARD(boardp)) {
5499         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5500         ASC_DBG(1, "advansys_info: begin\n");
5501         if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
5502             if ((asc_dvc_varp->bus_type & ASC_IS_ISAPNP) == ASC_IS_ISAPNP) {
5503                 busname = "ISA PnP";
5504             } else {
5505                 busname = "ISA";
5506             }
5507             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5508             sprintf(info,
5509 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X, DMA 0x%X",
5510                 ASC_VERSION, busname,
5511                 (ulong) shp->io_port,
5512                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5513                 shp->irq, shp->dma_channel);
5514         } else {
5515             if (asc_dvc_varp->bus_type & ASC_IS_VL) {
5516                 busname = "VL";
5517             } else if (asc_dvc_varp->bus_type & ASC_IS_EISA) {
5518                 busname = "EISA";
5519             } else if (asc_dvc_varp->bus_type & ASC_IS_PCI) {
5520                 if ((asc_dvc_varp->bus_type & ASC_IS_PCI_ULTRA)
5521                     == ASC_IS_PCI_ULTRA) {
5522                     busname = "PCI Ultra";
5523                 } else {
5524                     busname = "PCI";
5525                 }
5526             } else {
5527                 busname = "?";
5528                 ASC_PRINT2( "advansys_info: board %d: unknown bus type %d\n",
5529                     boardp->id, asc_dvc_varp->bus_type);
5530             }
5531             /* Don't reference 'shp->n_io_port'; It may be truncated. */
5532             sprintf(info,
5533                 "AdvanSys SCSI %s: %s: IO 0x%lX-0x%lX, IRQ 0x%X",
5534                 ASC_VERSION, busname,
5535                 (ulong) shp->io_port,
5536                 (ulong) shp->io_port + boardp->asc_n_io_port - 1,
5537                 shp->irq);
5538         }
5539     } else {
5540         /*
5541          * Wide Adapter Information
5542          *
5543          * Memory-mapped I/O is used instead of I/O space to access
5544          * the adapter, but display the I/O Port range. The Memory
5545          * I/O address is displayed through the driver /proc file.
5546          */
5547         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5548         if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
5549         {
5550             iolen = ADV_3550_IOLEN;
5551             widename = "Ultra-Wide";
5552         } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
5553         {
5554             iolen = ADV_38C0800_IOLEN;
5555             widename = "Ultra2-Wide";
5556         } else
5557         {
5558             iolen = ADV_38C1600_IOLEN;
5559             widename = "Ultra3-Wide";
5560         }
5561         sprintf(info, "AdvanSys SCSI %s: PCI %s: PCIMEM 0x%lX-0x%lX, IRQ 0x%X",
5562             ASC_VERSION,
5563             widename,
5564             (ulong) adv_dvc_varp->iop_base,
5565             (ulong) adv_dvc_varp->iop_base + iolen - 1,
5566             shp->irq);
5567     }
5568     ASC_ASSERT(strlen(info) < ASC_INFO_SIZE);
5569     ASC_DBG(1, "advansys_info: end\n");
5570     return info;
5571 }
5572
5573 /*
5574  * advansys_queuecommand() - interrupt-driven I/O entrypoint.
5575  *
5576  * This function always returns 0. Command return status is saved
5577  * in the 'scp' result field.
5578  */
5579 int
5580 advansys_queuecommand(Scsi_Cmnd *scp, void (*done)(Scsi_Cmnd *))
5581 {
5582     struct Scsi_Host    *shp;
5583     asc_board_t         *boardp;
5584     ulong               flags;
5585     Scsi_Cmnd           *done_scp;
5586
5587     shp = scp->device->host;
5588     boardp = ASC_BOARDP(shp);
5589     ASC_STATS(shp, queuecommand);
5590
5591     /* host_lock taken by mid-level prior to call but need to protect */
5592     /* against own ISR */
5593     spin_lock_irqsave(&boardp->lock, flags);
5594
5595     /*
5596      * Block new commands while handling a reset or abort request.
5597      */
5598     if (boardp->flags & ASC_HOST_IN_RESET) {
5599         ASC_DBG1(1,
5600             "advansys_queuecommand: scp 0x%lx blocked for reset request\n",
5601             (ulong) scp);
5602         scp->result = HOST_BYTE(DID_RESET);
5603
5604         /*
5605          * Add blocked requests to the board's 'done' queue. The queued
5606          * requests will be completed at the end of the abort or reset
5607          * handling.
5608          */
5609         asc_enqueue(&boardp->done, scp, ASC_BACK);
5610         spin_unlock_irqrestore(&boardp->lock, flags);
5611         return 0;
5612     }
5613
5614     /*
5615      * Attempt to execute any waiting commands for the board.
5616      */
5617     if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
5618         ASC_DBG(1,
5619             "advansys_queuecommand: before asc_execute_queue() waiting\n");
5620         asc_execute_queue(&boardp->waiting);
5621     }
5622
5623     /*
5624      * Save the function pointer to Linux mid-level 'done' function
5625      * and attempt to execute the command.
5626      *
5627      * If ASC_NOERROR is returned the request has been added to the
5628      * board's 'active' queue and will be completed by the interrupt
5629      * handler.
5630      *
5631      * If ASC_BUSY is returned add the request to the board's per
5632      * target waiting list. This is the first time the request has
5633      * been tried. Add it to the back of the waiting list. It will be
5634      * retried later.
5635      *
5636      * If an error occurred, the request will have been placed on the
5637      * board's 'done' queue and must be completed before returning.
5638      */
5639     scp->scsi_done = done;
5640     switch (asc_execute_scsi_cmnd(scp)) {
5641     case ASC_NOERROR:
5642         break;
5643     case ASC_BUSY:
5644         asc_enqueue(&boardp->waiting, scp, ASC_BACK);
5645         break;
5646     case ASC_ERROR:
5647     default:
5648         done_scp = asc_dequeue_list(&boardp->done, NULL, ASC_TID_ALL);
5649         /* Interrupts could be enabled here. */
5650         asc_scsi_done_list(done_scp);
5651         break;
5652     }
5653     spin_unlock_irqrestore(&boardp->lock, flags);
5654
5655     return 0;
5656 }
5657
5658 /*
5659  * advansys_reset()
5660  *
5661  * Reset the bus associated with the command 'scp'.
5662  *
5663  * This function runs its own thread. Interrupts must be blocked but
5664  * sleeping is allowed and no locking other than for host structures is
5665  * required. Returns SUCCESS or FAILED.
5666  */
5667 int
5668 advansys_reset(Scsi_Cmnd *scp)
5669 {
5670     struct Scsi_Host     *shp;
5671     asc_board_t          *boardp;
5672     ASC_DVC_VAR          *asc_dvc_varp;
5673     ADV_DVC_VAR          *adv_dvc_varp;
5674     ulong                flags;
5675     Scsi_Cmnd            *done_scp = NULL, *last_scp = NULL;
5676     Scsi_Cmnd            *tscp, *new_last_scp;
5677     int                  status;
5678     int                  ret = SUCCESS;
5679
5680     ASC_DBG1(1, "advansys_reset: 0x%lx\n", (ulong) scp);
5681
5682 #ifdef ADVANSYS_STATS
5683     if (scp->device->host != NULL) {
5684         ASC_STATS(scp->device->host, reset);
5685     }
5686 #endif /* ADVANSYS_STATS */
5687
5688     if ((shp = scp->device->host) == NULL) {
5689         scp->result = HOST_BYTE(DID_ERROR);
5690         return FAILED;
5691     }
5692
5693     boardp = ASC_BOARDP(shp);
5694
5695     ASC_PRINT1("advansys_reset: board %d: SCSI bus reset started...\n",
5696         boardp->id);
5697     /*
5698      * Check for re-entrancy.
5699      */
5700     spin_lock_irqsave(&boardp->lock, flags);
5701     if (boardp->flags & ASC_HOST_IN_RESET) {
5702         spin_unlock_irqrestore(&boardp->lock, flags);
5703         return FAILED;
5704     }
5705     boardp->flags |= ASC_HOST_IN_RESET;
5706     spin_unlock_irqrestore(&boardp->lock, flags);
5707
5708     if (ASC_NARROW_BOARD(boardp)) {
5709         /*
5710          * Narrow Board
5711          */
5712         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
5713
5714         /*
5715          * Reset the chip and SCSI bus.
5716          */
5717         ASC_DBG(1, "advansys_reset: before AscInitAsc1000Driver()\n");
5718         status = AscInitAsc1000Driver(asc_dvc_varp);
5719
5720         /* Refer to ASC_IERR_* defintions for meaning of 'err_code'. */
5721         if (asc_dvc_varp->err_code) {
5722             ASC_PRINT2(
5723                 "advansys_reset: board %d: SCSI bus reset error: 0x%x\n",
5724                 boardp->id, asc_dvc_varp->err_code);
5725             ret = FAILED;
5726         } else if (status) {
5727             ASC_PRINT2(
5728                 "advansys_reset: board %d: SCSI bus reset warning: 0x%x\n",
5729                 boardp->id, status);
5730         } else {
5731             ASC_PRINT1(
5732                 "advansys_reset: board %d: SCSI bus reset successful.\n",
5733                 boardp->id);
5734         }
5735
5736         ASC_DBG(1, "advansys_reset: after AscInitAsc1000Driver()\n");
5737         spin_lock_irqsave(&boardp->lock, flags);
5738
5739     } else {
5740         /*
5741          * Wide Board
5742          *
5743          * If the suggest reset bus flags are set, then reset the bus.
5744          * Otherwise only reset the device.
5745          */
5746         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
5747
5748         /*
5749          * Reset the target's SCSI bus.
5750          */
5751         ASC_DBG(1, "advansys_reset: before AdvResetChipAndSB()\n");
5752         switch (AdvResetChipAndSB(adv_dvc_varp)) {
5753         case ASC_TRUE:
5754             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset successful.\n",
5755                 boardp->id);
5756             break;
5757         case ASC_FALSE:
5758         default:
5759             ASC_PRINT1("advansys_reset: board %d: SCSI bus reset error.\n",
5760                 boardp->id);
5761             ret = FAILED;
5762             break;
5763         }
5764         spin_lock_irqsave(&boardp->lock, flags);
5765         (void) AdvISR(adv_dvc_varp);
5766     }
5767     /* Board lock is held. */
5768
5769     /*
5770      * Dequeue all board 'done' requests. A pointer to the last request
5771      * is returned in 'last_scp'.
5772      */
5773     done_scp = asc_dequeue_list(&boardp->done, &last_scp, ASC_TID_ALL);
5774
5775     /*
5776      * Dequeue all board 'active' requests for all devices and set
5777      * the request status to DID_RESET. A pointer to the last request
5778      * is returned in 'last_scp'.
5779      */
5780     if (done_scp == NULL) {
5781         done_scp = asc_dequeue_list(&boardp->active, &last_scp, ASC_TID_ALL);
5782         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5783             tscp->result = HOST_BYTE(DID_RESET);
5784         }
5785     } else {
5786         /* Append to 'done_scp' at the end with 'last_scp'. */
5787         ASC_ASSERT(last_scp != NULL);
5788         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5789                         &boardp->active, &new_last_scp, ASC_TID_ALL);
5790         if (new_last_scp != NULL) {
5791             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5792             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5793                 tscp->result = HOST_BYTE(DID_RESET);
5794             }
5795             last_scp = new_last_scp;
5796         }
5797     }
5798
5799     /*
5800      * Dequeue all 'waiting' requests and set the request status
5801      * to DID_RESET.
5802      */
5803     if (done_scp == NULL) {
5804         done_scp = asc_dequeue_list(&boardp->waiting, &last_scp, ASC_TID_ALL);
5805         for (tscp = done_scp; tscp; tscp = REQPNEXT(tscp)) {
5806             tscp->result = HOST_BYTE(DID_RESET);
5807         }
5808     } else {
5809         /* Append to 'done_scp' at the end with 'last_scp'. */
5810         ASC_ASSERT(last_scp != NULL);
5811         last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
5812                         &boardp->waiting, &new_last_scp, ASC_TID_ALL);
5813         if (new_last_scp != NULL) {
5814             ASC_ASSERT(REQPNEXT(last_scp) != NULL);
5815             for (tscp = REQPNEXT(last_scp); tscp; tscp = REQPNEXT(tscp)) {
5816                 tscp->result = HOST_BYTE(DID_RESET);
5817             }
5818             last_scp = new_last_scp;
5819         }
5820     }
5821
5822     /* Save the time of the most recently completed reset. */
5823     boardp->last_reset = jiffies;
5824
5825     /* Clear reset flag. */
5826     boardp->flags &= ~ASC_HOST_IN_RESET;
5827     spin_unlock_irqrestore(&boardp->lock, flags);
5828
5829     /*
5830      * Complete all the 'done_scp' requests.
5831      */
5832     if (done_scp != NULL) {
5833         asc_scsi_done_list(done_scp);
5834     }
5835
5836     ASC_DBG1(1, "advansys_reset: ret %d\n", ret);
5837
5838     return ret;
5839 }
5840
5841 /*
5842  * advansys_biosparam()
5843  *
5844  * Translate disk drive geometry if the "BIOS greater than 1 GB"
5845  * support is enabled for a drive.
5846  *
5847  * ip (information pointer) is an int array with the following definition:
5848  * ip[0]: heads
5849  * ip[1]: sectors
5850  * ip[2]: cylinders
5851  */
5852 int
5853 advansys_biosparam(struct scsi_device *sdev, struct block_device *bdev,
5854                 sector_t capacity, int ip[])
5855 {
5856     asc_board_t     *boardp;
5857
5858     ASC_DBG(1, "advansys_biosparam: begin\n");
5859     ASC_STATS(sdev->host, biosparam);
5860     boardp = ASC_BOARDP(sdev->host);
5861     if (ASC_NARROW_BOARD(boardp)) {
5862         if ((boardp->dvc_var.asc_dvc_var.dvc_cntl &
5863              ASC_CNTL_BIOS_GT_1GB) && capacity > 0x200000) {
5864                 ip[0] = 255;
5865                 ip[1] = 63;
5866         } else {
5867                 ip[0] = 64;
5868                 ip[1] = 32;
5869         }
5870     } else {
5871         if ((boardp->dvc_var.adv_dvc_var.bios_ctrl &
5872              BIOS_CTRL_EXTENDED_XLAT) && capacity > 0x200000) {
5873                 ip[0] = 255;
5874                 ip[1] = 63;
5875         } else {
5876                 ip[0] = 64;
5877                 ip[1] = 32;
5878         }
5879     }
5880     ip[2] = (unsigned long)capacity / (ip[0] * ip[1]);
5881     ASC_DBG(1, "advansys_biosparam: end\n");
5882     return 0;
5883 }
5884
5885 /*
5886  * advansys_setup()
5887  *
5888  * This function is called from init/main.c at boot time.
5889  * It it passed LILO parameters that can be set from the
5890  * LILO command line or in /etc/lilo.conf.
5891  *
5892  * It is used by the AdvanSys driver to either disable I/O
5893  * port scanning or to limit scanning to 1 - 4 I/O ports.
5894  * Regardless of the option setting EISA and PCI boards
5895  * will still be searched for and detected. This option
5896  * only affects searching for ISA and VL boards.
5897  *
5898  * If ADVANSYS_DEBUG is defined the driver debug level may
5899  * be set using the 5th (ASC_NUM_IOPORT_PROBE + 1) I/O Port.
5900  *
5901  * Examples:
5902  * 1. Eliminate I/O port scanning:
5903  *         boot: linux advansys=
5904  *       or
5905  *         boot: linux advansys=0x0
5906  * 2. Limit I/O port scanning to one I/O port:
5907  *        boot: linux advansys=0x110
5908  * 3. Limit I/O port scanning to four I/O ports:
5909  *        boot: linux advansys=0x110,0x210,0x230,0x330
5910  * 4. If ADVANSYS_DEBUG, limit I/O port scanning to four I/O ports and
5911  *    set the driver debug level to 2.
5912  *        boot: linux advansys=0x110,0x210,0x230,0x330,0xdeb2
5913  *
5914  * ints[0] - number of arguments
5915  * ints[1] - first argument
5916  * ints[2] - second argument
5917  * ...
5918  */
5919 void __init
5920 advansys_setup(char *str, int *ints)
5921 {
5922     int    i;
5923
5924     if (asc_iopflag == ASC_TRUE) {
5925         printk("AdvanSys SCSI: 'advansys' LILO option may appear only once\n");
5926         return;
5927     }
5928
5929     asc_iopflag = ASC_TRUE;
5930
5931     if (ints[0] > ASC_NUM_IOPORT_PROBE) {
5932 #ifdef ADVANSYS_DEBUG
5933         if ((ints[0] == ASC_NUM_IOPORT_PROBE + 1) &&
5934             (ints[ASC_NUM_IOPORT_PROBE + 1] >> 4 == 0xdeb)) {
5935             asc_dbglvl = ints[ASC_NUM_IOPORT_PROBE + 1] & 0xf;
5936         } else {
5937 #endif /* ADVANSYS_DEBUG */
5938             printk("AdvanSys SCSI: only %d I/O ports accepted\n",
5939                 ASC_NUM_IOPORT_PROBE);
5940 #ifdef ADVANSYS_DEBUG
5941         }
5942 #endif /* ADVANSYS_DEBUG */
5943     }
5944
5945 #ifdef ADVANSYS_DEBUG
5946     ASC_DBG1(1, "advansys_setup: ints[0] %d\n", ints[0]);
5947     for (i = 1; i < ints[0]; i++) {
5948         ASC_DBG2(1, " ints[%d] 0x%x", i, ints[i]);
5949     }
5950     ASC_DBG(1, "\n");
5951 #endif /* ADVANSYS_DEBUG */
5952
5953     for (i = 1; i <= ints[0] && i <= ASC_NUM_IOPORT_PROBE; i++) {
5954         asc_ioport[i-1] = ints[i];
5955         ASC_DBG2(1, "advansys_setup: asc_ioport[%d] 0x%x\n",
5956             i - 1, asc_ioport[i-1]);
5957     }
5958 }
5959
5960
5961 /*
5962  * --- Loadable Driver Support
5963  */
5964
5965 static Scsi_Host_Template driver_template = {
5966     .proc_name                  = "advansys",
5967 #ifdef CONFIG_PROC_FS
5968     .proc_info                  = advansys_proc_info,
5969 #endif
5970     .name                       = "advansys",
5971     .detect                     = advansys_detect, 
5972     .release                    = advansys_release,
5973     .info                       = advansys_info,
5974     .queuecommand               = advansys_queuecommand,
5975     .eh_bus_reset_handler       = advansys_reset,
5976     .bios_param                 = advansys_biosparam,
5977     .slave_configure            = advansys_slave_configure,
5978     /*
5979      * Because the driver may control an ISA adapter 'unchecked_isa_dma'
5980      * must be set. The flag will be cleared in advansys_detect for non-ISA
5981      * adapters. Refer to the comment in scsi_module.c for more information.
5982      */
5983     .unchecked_isa_dma          = 1,
5984     /*
5985      * All adapters controlled by this driver are capable of large
5986      * scatter-gather lists. According to the mid-level SCSI documentation
5987      * this obviates any performance gain provided by setting
5988      * 'use_clustering'. But empirically while CPU utilization is increased
5989      * by enabling clustering, I/O throughput increases as well.
5990      */
5991     .use_clustering             = ENABLE_CLUSTERING,
5992 };
5993 #include "scsi_module.c"
5994
5995
5996 /*
5997  * --- Miscellaneous Driver Functions
5998  */
5999
6000 /*
6001  * First-level interrupt handler.
6002  *
6003  * 'dev_id' is a pointer to the interrupting adapter's asc_board_t. Because
6004  * all boards are currently checked for interrupts on each interrupt, 'dev_id'
6005  * is not referenced. 'dev_id' could be used to identify an interrupt passed
6006  * to the AdvanSys driver which is for a device sharing an interrupt with
6007  * an AdvanSys adapter.
6008  */
6009 STATIC irqreturn_t
6010 advansys_interrupt(int irq, void *dev_id, struct pt_regs *regs)
6011 {
6012     ulong           flags;
6013     int             i;
6014     asc_board_t     *boardp;
6015     Scsi_Cmnd       *done_scp = NULL, *last_scp = NULL;
6016     Scsi_Cmnd       *new_last_scp;
6017     struct Scsi_Host *shp;
6018
6019     ASC_DBG(1, "advansys_interrupt: begin\n");
6020
6021     /*
6022      * Check for interrupts on all boards.
6023      * AscISR() will call asc_isr_callback().
6024      */
6025     for (i = 0; i < asc_board_count; i++) {
6026         shp = asc_host[i];
6027         boardp = ASC_BOARDP(shp);
6028         ASC_DBG2(2, "advansys_interrupt: i %d, boardp 0x%lx\n",
6029             i, (ulong) boardp);
6030         spin_lock_irqsave(&boardp->lock, flags);
6031         if (ASC_NARROW_BOARD(boardp)) {
6032             /*
6033              * Narrow Board
6034              */
6035             if (AscIsIntPending(shp->io_port)) {
6036                 ASC_STATS(shp, interrupt);
6037                 ASC_DBG(1, "advansys_interrupt: before AscISR()\n");
6038                 AscISR(&boardp->dvc_var.asc_dvc_var);
6039             }
6040         } else {
6041             /*
6042              * Wide Board
6043              */
6044             ASC_DBG(1, "advansys_interrupt: before AdvISR()\n");
6045             if (AdvISR(&boardp->dvc_var.adv_dvc_var)) {
6046                 ASC_STATS(shp, interrupt);
6047             }
6048         }
6049
6050         /*
6051          * Start waiting requests and create a list of completed requests.
6052          *
6053          * If a reset request is being performed for the board, the reset
6054          * handler will complete pending requests after it has completed.
6055          */
6056         if ((boardp->flags & ASC_HOST_IN_RESET) == 0) {
6057             ASC_DBG2(1, "advansys_interrupt: done_scp 0x%lx, last_scp 0x%lx\n",
6058                 (ulong) done_scp, (ulong) last_scp);
6059
6060             /* Start any waiting commands for the board. */
6061             if (!ASC_QUEUE_EMPTY(&boardp->waiting)) {
6062                 ASC_DBG(1, "advansys_interrupt: before asc_execute_queue()\n");
6063                 asc_execute_queue(&boardp->waiting);
6064             }
6065
6066              /*
6067               * Add to the list of requests that must be completed.
6068               *
6069               * 'done_scp' will always be NULL on the first iteration
6070               * of this loop. 'last_scp' is set at the same time as
6071               * 'done_scp'.
6072               */
6073             if (done_scp == NULL) {
6074                 done_scp = asc_dequeue_list(&boardp->done, &last_scp,
6075                     ASC_TID_ALL);
6076             } else {
6077                 ASC_ASSERT(last_scp != NULL);
6078                 last_scp->host_scribble = (unsigned char *)asc_dequeue_list(
6079                         &boardp->done, &new_last_scp, ASC_TID_ALL);
6080                 if (new_last_scp != NULL) {
6081                     ASC_ASSERT(REQPNEXT(last_scp) != NULL);
6082                     last_scp = new_last_scp;
6083                 }
6084             }
6085         }
6086         spin_unlock_irqrestore(&boardp->lock, flags);
6087     }
6088
6089     /*
6090      * If interrupts were enabled on entry, then they
6091      * are now enabled here.
6092      *
6093      * Complete all requests on the done list.
6094      */
6095
6096     asc_scsi_done_list(done_scp);
6097
6098     ASC_DBG(1, "advansys_interrupt: end\n");
6099     return IRQ_HANDLED;
6100 }
6101
6102 /*
6103  * Set the number of commands to queue per device for the
6104  * specified host adapter.
6105  */
6106 STATIC int
6107 advansys_slave_configure(Scsi_Device *device)
6108 {
6109     asc_board_t        *boardp;
6110
6111     boardp = ASC_BOARDP(device->host);
6112     boardp->flags |= ASC_SELECT_QUEUE_DEPTHS;
6113     /*
6114      * Save a pointer to the device and set its initial/maximum
6115      * queue depth.  Only save the pointer for a lun0 dev though.
6116      */
6117     if(device->lun == 0)
6118         boardp->device[device->id] = device;
6119     if(device->tagged_supported) {
6120         if (ASC_NARROW_BOARD(boardp)) {
6121             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6122                 boardp->dvc_var.asc_dvc_var.max_dvc_qng[device->id]);
6123         } else {
6124             scsi_adjust_queue_depth(device, MSG_ORDERED_TAG,
6125                 boardp->dvc_var.adv_dvc_var.max_dvc_qng);
6126         }
6127     } else {
6128         scsi_adjust_queue_depth(device, 0, device->host->cmd_per_lun);
6129     }
6130     ASC_DBG4(1, "advansys_slave_configure: device 0x%lx, boardp 0x%lx, id %d, depth %d\n",
6131             (ulong) device, (ulong) boardp, device->id, device->queue_depth);
6132     return 0;
6133 }
6134
6135 /*
6136  * Complete all requests on the singly linked list pointed
6137  * to by 'scp'.
6138  *
6139  * Interrupts can be enabled on entry.
6140  */
6141 STATIC void
6142 asc_scsi_done_list(Scsi_Cmnd *scp)
6143 {
6144     Scsi_Cmnd    *tscp;
6145
6146     ASC_DBG(2, "asc_scsi_done_list: begin\n");
6147     while (scp != NULL) {
6148         asc_board_t *boardp;
6149         struct device *dev;
6150
6151         ASC_DBG1(3, "asc_scsi_done_list: scp 0x%lx\n", (ulong) scp);
6152         tscp = REQPNEXT(scp);
6153         scp->host_scribble = NULL;
6154
6155         boardp = ASC_BOARDP(scp->device->host);
6156
6157         if (ASC_NARROW_BOARD(boardp))
6158             dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6159         else
6160             dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6161
6162         if (scp->use_sg)
6163             dma_unmap_sg(dev, (struct scatterlist *)scp->request_buffer,
6164                          scp->use_sg, scp->sc_data_direction);
6165         else if (scp->request_bufflen)
6166             dma_unmap_single(dev, scp->SCp.dma_handle,
6167                              scp->request_bufflen, scp->sc_data_direction);
6168
6169         ASC_STATS(scp->device->host, done);
6170         ASC_ASSERT(scp->scsi_done != NULL);
6171
6172         scp->scsi_done(scp);
6173
6174         scp = tscp;
6175     }
6176     ASC_DBG(2, "asc_scsi_done_list: done\n");
6177     return;
6178 }
6179
6180 /*
6181  * Execute a single 'Scsi_Cmnd'.
6182  *
6183  * The function 'done' is called when the request has been completed.
6184  *
6185  * Scsi_Cmnd:
6186  *
6187  *  host - board controlling device
6188  *  device - device to send command
6189  *  target - target of device
6190  *  lun - lun of device
6191  *  cmd_len - length of SCSI CDB
6192  *  cmnd - buffer for SCSI 8, 10, or 12 byte CDB
6193  *  use_sg - if non-zero indicates scatter-gather request with use_sg elements
6194  *
6195  *  if (use_sg == 0) {
6196  *    request_buffer - buffer address for request
6197  *    request_bufflen - length of request buffer
6198  *  } else {
6199  *    request_buffer - pointer to scatterlist structure
6200  *  }
6201  *
6202  *  sense_buffer - sense command buffer
6203  *
6204  *  result (4 bytes of an int):
6205  *    Byte Meaning
6206  *    0 SCSI Status Byte Code
6207  *    1 SCSI One Byte Message Code
6208  *    2 Host Error Code
6209  *    3 Mid-Level Error Code
6210  *
6211  *  host driver fields:
6212  *    SCp - Scsi_Pointer used for command processing status
6213  *    scsi_done - used to save caller's done function
6214  *    host_scribble - used for pointer to another Scsi_Cmnd
6215  *
6216  * If this function returns ASC_NOERROR the request has been enqueued
6217  * on the board's 'active' queue and will be completed from the
6218  * interrupt handler.
6219  *
6220  * If this function returns ASC_NOERROR the request has been enqueued
6221  * on the board's 'done' queue and must be completed by the caller.
6222  *
6223  * If ASC_BUSY is returned the request will be enqueued by the
6224  * caller on the target's waiting queue and re-tried later.
6225  */
6226 STATIC int
6227 asc_execute_scsi_cmnd(Scsi_Cmnd *scp)
6228 {
6229     asc_board_t        *boardp;
6230     ASC_DVC_VAR        *asc_dvc_varp;
6231     ADV_DVC_VAR        *adv_dvc_varp;
6232     ADV_SCSI_REQ_Q     *adv_scsiqp;
6233     Scsi_Device        *device;
6234     int                ret;
6235
6236     ASC_DBG2(1, "asc_execute_scsi_cmnd: scp 0x%lx, done 0x%lx\n",
6237         (ulong) scp, (ulong) scp->scsi_done);
6238
6239     boardp = ASC_BOARDP(scp->device->host);
6240     device = boardp->device[scp->device->id];
6241
6242     if (ASC_NARROW_BOARD(boardp)) {
6243         /*
6244          * Build and execute Narrow Board request.
6245          */
6246
6247         asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
6248
6249         /*
6250          * Build Asc Library request structure using the
6251          * global structures 'asc_scsi_req' and 'asc_sg_head'.
6252          *
6253          * If an error is returned, then the request has been
6254          * queued on the board done queue. It will be completed
6255          * by the caller.
6256          *
6257          * asc_build_req() can not return ASC_BUSY.
6258          */
6259         if (asc_build_req(boardp, scp) == ASC_ERROR) {
6260             ASC_STATS(scp->device->host, build_error);
6261             return ASC_ERROR;
6262         }
6263
6264         /*
6265          * Execute the command. If there is no error, add the command
6266          * to the active queue.
6267          */
6268         switch (ret = AscExeScsiQueue(asc_dvc_varp, &asc_scsi_q)) {
6269         case ASC_NOERROR:
6270             ASC_STATS(scp->device->host, exe_noerror);
6271             /*
6272              * Increment monotonically increasing per device successful
6273              * request counter. Wrapping doesn't matter.
6274              */
6275             boardp->reqcnt[scp->device->id]++;
6276             asc_enqueue(&boardp->active, scp, ASC_BACK);
6277             ASC_DBG(1,
6278                 "asc_execute_scsi_cmnd: AscExeScsiQueue(), ASC_NOERROR\n");
6279             break;
6280         case ASC_BUSY:
6281             /*
6282              * Caller will enqueue request on the target's waiting queue
6283              * and retry later.
6284              */
6285             ASC_STATS(scp->device->host, exe_busy);
6286             break;
6287         case ASC_ERROR:
6288             ASC_PRINT2(
6289 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6290                 boardp->id, asc_dvc_varp->err_code);
6291             ASC_STATS(scp->device->host, exe_error);
6292             scp->result = HOST_BYTE(DID_ERROR);
6293             asc_enqueue(&boardp->done, scp, ASC_BACK);
6294             break;
6295         default:
6296             ASC_PRINT2(
6297 "asc_execute_scsi_cmnd: board %d: AscExeScsiQueue() unknown, err_code 0x%x\n",
6298                 boardp->id, asc_dvc_varp->err_code);
6299             ASC_STATS(scp->device->host, exe_unknown);
6300             scp->result = HOST_BYTE(DID_ERROR);
6301             asc_enqueue(&boardp->done, scp, ASC_BACK);
6302             break;
6303         }
6304     } else {
6305         /*
6306          * Build and execute Wide Board request.
6307          */
6308         adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
6309
6310         /*
6311          * Build and get a pointer to an Adv Library request structure.
6312          *
6313          * If the request is successfully built then send it below,
6314          * otherwise return with an error.
6315          */
6316         switch (adv_build_req(boardp, scp, &adv_scsiqp)) {
6317         case ASC_NOERROR:
6318             ASC_DBG(3, "asc_execute_scsi_cmnd: adv_build_req ASC_NOERROR\n");
6319             break;
6320         case ASC_BUSY:
6321             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_BUSY\n");
6322             /*
6323              * If busy is returned the request has not been enqueued.
6324              * It will be enqueued by the caller on the target's waiting
6325              * queue and retried later.
6326              *
6327              * The asc_stats fields 'adv_build_noreq' and 'adv_build_nosg'
6328              * count wide board busy conditions. They are updated in
6329              * adv_build_req and adv_get_sglist, respectively.
6330              */
6331             return ASC_BUSY;
6332         case ASC_ERROR:
6333              /* 
6334               * If an error is returned, then the request has been
6335               * queued on the board done queue. It will be completed
6336               * by the caller.
6337               */
6338         default:
6339             ASC_DBG(1, "asc_execute_scsi_cmnd: adv_build_req ASC_ERROR\n");
6340             ASC_STATS(scp->device->host, build_error);
6341             return ASC_ERROR;
6342         }
6343
6344         /*
6345          * Execute the command. If there is no error, add the command
6346          * to the active queue.
6347          */
6348         switch (ret = AdvExeScsiQueue(adv_dvc_varp, adv_scsiqp)) {
6349         case ASC_NOERROR:
6350             ASC_STATS(scp->device->host, exe_noerror);
6351             /*
6352              * Increment monotonically increasing per device successful
6353              * request counter. Wrapping doesn't matter.
6354              */
6355             boardp->reqcnt[scp->device->id]++;
6356             asc_enqueue(&boardp->active, scp, ASC_BACK);
6357             ASC_DBG(1,
6358                 "asc_execute_scsi_cmnd: AdvExeScsiQueue(), ASC_NOERROR\n");
6359             break;
6360         case ASC_BUSY:
6361             /*
6362              * Caller will enqueue request on the target's waiting queue
6363              * and retry later.
6364              */
6365             ASC_STATS(scp->device->host, exe_busy);
6366             break;
6367         case ASC_ERROR:
6368             ASC_PRINT2(
6369 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() ASC_ERROR, err_code 0x%x\n",
6370                 boardp->id, adv_dvc_varp->err_code);
6371             ASC_STATS(scp->device->host, exe_error);
6372             scp->result = HOST_BYTE(DID_ERROR);
6373             asc_enqueue(&boardp->done, scp, ASC_BACK);
6374             break;
6375         default:
6376             ASC_PRINT2(
6377 "asc_execute_scsi_cmnd: board %d: AdvExeScsiQueue() unknown, err_code 0x%x\n",
6378                 boardp->id, adv_dvc_varp->err_code);
6379             ASC_STATS(scp->device->host, exe_unknown);
6380             scp->result = HOST_BYTE(DID_ERROR);
6381             asc_enqueue(&boardp->done, scp, ASC_BACK);
6382             break;
6383         }
6384     }
6385
6386     ASC_DBG(1, "asc_execute_scsi_cmnd: end\n");
6387     return ret;
6388 }
6389
6390 /*
6391  * Build a request structure for the Asc Library (Narrow Board).
6392  *
6393  * The global structures 'asc_scsi_q' and 'asc_sg_head' are
6394  * used to build the request.
6395  *
6396  * If an error occurs, then queue the request on the board done
6397  * queue and return ASC_ERROR.
6398  */
6399 STATIC int
6400 asc_build_req(asc_board_t *boardp, Scsi_Cmnd *scp)
6401 {
6402     struct device *dev = boardp->dvc_cfg.asc_dvc_cfg.dev;
6403
6404     /*
6405      * Mutually exclusive access is required to 'asc_scsi_q' and
6406      * 'asc_sg_head' until after the request is started.
6407      */
6408     memset(&asc_scsi_q, 0, sizeof(ASC_SCSI_Q));
6409
6410     /*
6411      * Point the ASC_SCSI_Q to the 'Scsi_Cmnd'.
6412      */
6413     asc_scsi_q.q2.srb_ptr = ASC_VADDR_TO_U32(scp);
6414
6415     /*
6416      * Build the ASC_SCSI_Q request.
6417      *
6418      * For narrow boards a CDB length maximum of 12 bytes
6419      * is supported.
6420      */
6421     if (scp->cmd_len > ASC_MAX_CDB_LEN) {
6422         ASC_PRINT3(
6423 "asc_build_req: board %d: cmd_len %d > ASC_MAX_CDB_LEN  %d\n",
6424             boardp->id, scp->cmd_len, ASC_MAX_CDB_LEN);
6425         scp->result = HOST_BYTE(DID_ERROR);
6426         asc_enqueue(&boardp->done, scp, ASC_BACK);
6427         return ASC_ERROR;
6428     }
6429     asc_scsi_q.cdbptr = &scp->cmnd[0];
6430     asc_scsi_q.q2.cdb_len = scp->cmd_len;
6431     asc_scsi_q.q1.target_id = ASC_TID_TO_TARGET_ID(scp->device->id);
6432     asc_scsi_q.q1.target_lun = scp->device->lun;
6433     asc_scsi_q.q2.target_ix = ASC_TIDLUN_TO_IX(scp->device->id, scp->device->lun);
6434     asc_scsi_q.q1.sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6435     asc_scsi_q.q1.sense_len = sizeof(scp->sense_buffer);
6436
6437     /*
6438      * If there are any outstanding requests for the current target,
6439      * then every 255th request send an ORDERED request. This heuristic
6440      * tries to retain the benefit of request sorting while preventing
6441      * request starvation. 255 is the max number of tags or pending commands
6442      * a device may have outstanding.
6443      *
6444      * The request count is incremented below for every successfully
6445      * started request.
6446      *
6447      */
6448     if ((boardp->dvc_var.asc_dvc_var.cur_dvc_qng[scp->device->id] > 0) &&
6449         (boardp->reqcnt[scp->device->id] % 255) == 0) {
6450         asc_scsi_q.q2.tag_code = MSG_ORDERED_TAG;
6451     } else {
6452         asc_scsi_q.q2.tag_code = MSG_SIMPLE_TAG;
6453     }
6454
6455     /*
6456      * Build ASC_SCSI_Q for a contiguous buffer or a scatter-gather
6457      * buffer command.
6458      */
6459     if (scp->use_sg == 0) {
6460         /*
6461          * CDB request of single contiguous buffer.
6462          */
6463         ASC_STATS(scp->device->host, cont_cnt);
6464         scp->SCp.dma_handle = scp->request_bufflen ?
6465             dma_map_single(dev, scp->request_buffer,
6466                            scp->request_bufflen, scp->sc_data_direction) : 0;
6467         asc_scsi_q.q1.data_addr = cpu_to_le32(scp->SCp.dma_handle);
6468         asc_scsi_q.q1.data_cnt = cpu_to_le32(scp->request_bufflen);
6469         ASC_STATS_ADD(scp->device->host, cont_xfer,
6470                       ASC_CEILING(scp->request_bufflen, 512));
6471         asc_scsi_q.q1.sg_queue_cnt = 0;
6472         asc_scsi_q.sg_head = NULL;
6473     } else {
6474         /*
6475          * CDB scatter-gather request list.
6476          */
6477         int                     sgcnt;
6478         int                     use_sg;
6479         struct scatterlist      *slp;
6480
6481         slp = (struct scatterlist *)scp->request_buffer;
6482         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6483
6484         if (use_sg > scp->device->host->sg_tablesize) {
6485             ASC_PRINT3(
6486 "asc_build_req: board %d: use_sg %d > sg_tablesize %d\n",
6487                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6488             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6489             scp->result = HOST_BYTE(DID_ERROR);
6490             asc_enqueue(&boardp->done, scp, ASC_BACK);
6491             return ASC_ERROR;
6492         }
6493
6494         ASC_STATS(scp->device->host, sg_cnt);
6495
6496         /*
6497          * Use global ASC_SG_HEAD structure and set the ASC_SCSI_Q
6498          * structure to point to it.
6499          */
6500         memset(&asc_sg_head, 0, sizeof(ASC_SG_HEAD));
6501
6502         asc_scsi_q.q1.cntl |= QC_SG_HEAD;
6503         asc_scsi_q.sg_head = &asc_sg_head;
6504         asc_scsi_q.q1.data_cnt = 0;
6505         asc_scsi_q.q1.data_addr = 0;
6506         /* This is a byte value, otherwise it would need to be swapped. */
6507         asc_sg_head.entry_cnt = asc_scsi_q.q1.sg_queue_cnt = use_sg;
6508         ASC_STATS_ADD(scp->device->host, sg_elem, asc_sg_head.entry_cnt);
6509
6510         /*
6511          * Convert scatter-gather list into ASC_SG_HEAD list.
6512          */
6513         for (sgcnt = 0; sgcnt < use_sg; sgcnt++, slp++) {
6514             asc_sg_head.sg_list[sgcnt].addr = cpu_to_le32(sg_dma_address(slp));
6515             asc_sg_head.sg_list[sgcnt].bytes = cpu_to_le32(sg_dma_len(slp));
6516             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6517         }
6518     }
6519
6520     ASC_DBG_PRT_ASC_SCSI_Q(2, &asc_scsi_q);
6521     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6522
6523     return ASC_NOERROR;
6524 }
6525
6526 /*
6527  * Build a request structure for the Adv Library (Wide Board).
6528  *
6529  * If an adv_req_t can not be allocated to issue the request,
6530  * then return ASC_BUSY. If an error occurs, then return ASC_ERROR.
6531  *
6532  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the
6533  * microcode for DMA addresses or math operations are byte swapped
6534  * to little-endian order.
6535  */
6536 STATIC int
6537 adv_build_req(asc_board_t *boardp, Scsi_Cmnd *scp,
6538     ADV_SCSI_REQ_Q **adv_scsiqpp)
6539 {
6540     adv_req_t           *reqp;
6541     ADV_SCSI_REQ_Q      *scsiqp;
6542     int                 i;
6543     int                 ret;
6544     struct device       *dev = boardp->dvc_cfg.adv_dvc_cfg.dev;
6545
6546     /*
6547      * Allocate an adv_req_t structure from the board to execute
6548      * the command.
6549      */
6550     if (boardp->adv_reqp == NULL) {
6551         ASC_DBG(1, "adv_build_req: no free adv_req_t\n");
6552         ASC_STATS(scp->device->host, adv_build_noreq);
6553         return ASC_BUSY;
6554     } else {
6555         reqp = boardp->adv_reqp;
6556         boardp->adv_reqp = reqp->next_reqp;
6557         reqp->next_reqp = NULL;
6558     }
6559
6560     /*
6561      * Get 32-byte aligned ADV_SCSI_REQ_Q and ADV_SG_BLOCK pointers.
6562      */
6563     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6564
6565     /*
6566      * Initialize the structure.
6567      */
6568     scsiqp->cntl = scsiqp->scsi_cntl = scsiqp->done_status = 0;
6569
6570     /*
6571      * Set the ADV_SCSI_REQ_Q 'srb_ptr' to point to the adv_req_t structure.
6572      */
6573     scsiqp->srb_ptr = ASC_VADDR_TO_U32(reqp);
6574
6575     /*
6576      * Set the adv_req_t 'cmndp' to point to the Scsi_Cmnd structure.
6577      */
6578     reqp->cmndp = scp;
6579
6580     /*
6581      * Build the ADV_SCSI_REQ_Q request.
6582      */
6583
6584     /*
6585      * Set CDB length and copy it to the request structure.
6586      * For wide  boards a CDB length maximum of 16 bytes
6587      * is supported.
6588      */
6589     if (scp->cmd_len > ADV_MAX_CDB_LEN) {
6590         ASC_PRINT3(
6591 "adv_build_req: board %d: cmd_len %d > ADV_MAX_CDB_LEN  %d\n",
6592             boardp->id, scp->cmd_len, ADV_MAX_CDB_LEN);
6593         scp->result = HOST_BYTE(DID_ERROR);
6594         asc_enqueue(&boardp->done, scp, ASC_BACK);
6595         return ASC_ERROR;
6596     }
6597     scsiqp->cdb_len = scp->cmd_len;
6598     /* Copy first 12 CDB bytes to cdb[]. */
6599     for (i = 0; i < scp->cmd_len && i < 12; i++) {
6600         scsiqp->cdb[i] = scp->cmnd[i];
6601     }
6602     /* Copy last 4 CDB bytes, if present, to cdb16[]. */
6603     for (; i < scp->cmd_len; i++) {
6604         scsiqp->cdb16[i - 12] = scp->cmnd[i];
6605     }
6606
6607     scsiqp->target_id = scp->device->id;
6608     scsiqp->target_lun = scp->device->lun;
6609
6610     scsiqp->sense_addr = cpu_to_le32(virt_to_bus(&scp->sense_buffer[0]));
6611     scsiqp->sense_len = sizeof(scp->sense_buffer);
6612
6613     /*
6614      * Build ADV_SCSI_REQ_Q for a contiguous buffer or a scatter-gather
6615      * buffer command.
6616      */
6617
6618     if (scp->use_sg == 0) {
6619         /*
6620          * CDB request of single contiguous buffer.
6621          */
6622         reqp->sgblkp = NULL;
6623         scsiqp->data_cnt = cpu_to_le32(scp->request_bufflen);
6624         if (scp->request_bufflen) {
6625             scsiqp->vdata_addr = scp->request_buffer;
6626             scp->SCp.dma_handle =
6627                 dma_map_single(dev, scp->request_buffer,
6628                                scp->request_bufflen, scp->sc_data_direction);
6629         } else {
6630             scsiqp->vdata_addr = 0;
6631             scp->SCp.dma_handle = 0;
6632         }
6633         scsiqp->data_addr = cpu_to_le32(scp->SCp.dma_handle);
6634         scsiqp->sg_list_ptr = NULL;
6635         scsiqp->sg_real_addr = 0;
6636         ASC_STATS(scp->device->host, cont_cnt);
6637         ASC_STATS_ADD(scp->device->host, cont_xfer,
6638                       ASC_CEILING(scp->request_bufflen, 512));
6639     } else {
6640         /*
6641          * CDB scatter-gather request list.
6642          */
6643         struct scatterlist *slp;
6644         int use_sg;
6645
6646         scsiqp->data_cnt = 0;
6647         scsiqp->vdata_addr = 0;
6648         scsiqp->data_addr = 0;
6649
6650         slp = (struct scatterlist *)scp->request_buffer;
6651         use_sg = dma_map_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6652
6653         if (use_sg > ADV_MAX_SG_LIST) {
6654             ASC_PRINT3(
6655 "adv_build_req: board %d: use_sg %d > ADV_MAX_SG_LIST %d\n",
6656                 boardp->id, use_sg, scp->device->host->sg_tablesize);
6657             dma_unmap_sg(dev, slp, scp->use_sg, scp->sc_data_direction);
6658             scp->result = HOST_BYTE(DID_ERROR);
6659             asc_enqueue(&boardp->done, scp, ASC_BACK);
6660
6661             /*
6662              * Free the 'adv_req_t' structure by adding it back to the
6663              * board free list.
6664              */
6665             reqp->next_reqp = boardp->adv_reqp;
6666             boardp->adv_reqp = reqp;
6667
6668             return ASC_ERROR;
6669         }
6670
6671         if ((ret = adv_get_sglist(boardp, reqp, scp, use_sg)) != ADV_SUCCESS) {
6672             /*
6673              * Free the adv_req_t structure by adding it back to the
6674              * board free list.
6675              */
6676             reqp->next_reqp = boardp->adv_reqp;
6677             boardp->adv_reqp = reqp;
6678
6679             return ret;
6680         }
6681
6682         ASC_STATS(scp->device->host, sg_cnt);
6683         ASC_STATS_ADD(scp->device->host, sg_elem, use_sg);
6684     }
6685
6686     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6687     ASC_DBG_PRT_CDB(1, scp->cmnd, scp->cmd_len);
6688
6689     *adv_scsiqpp = scsiqp;
6690
6691     return ASC_NOERROR;
6692 }
6693
6694 /*
6695  * Build scatter-gather list for Adv Library (Wide Board).
6696  *
6697  * Additional ADV_SG_BLOCK structures will need to be allocated
6698  * if the total number of scatter-gather elements exceeds
6699  * NO_OF_SG_PER_BLOCK (15). The ADV_SG_BLOCK structures are
6700  * assumed to be physically contiguous.
6701  *
6702  * Return:
6703  *      ADV_SUCCESS(1) - SG List successfully created
6704  *      ADV_ERROR(-1) - SG List creation failed
6705  */
6706 STATIC int
6707 adv_get_sglist(asc_board_t *boardp, adv_req_t *reqp, Scsi_Cmnd *scp, int use_sg)
6708 {
6709     adv_sgblk_t         *sgblkp;
6710     ADV_SCSI_REQ_Q      *scsiqp;
6711     struct scatterlist  *slp;
6712     int                 sg_elem_cnt;
6713     ADV_SG_BLOCK        *sg_block, *prev_sg_block;
6714     ADV_PADDR           sg_block_paddr;
6715     int                 i;
6716
6717     scsiqp = (ADV_SCSI_REQ_Q *) ADV_32BALIGN(&reqp->scsi_req_q);
6718     slp = (struct scatterlist *) scp->request_buffer;
6719     sg_elem_cnt = use_sg;
6720     prev_sg_block = NULL;
6721     reqp->sgblkp = NULL;
6722
6723     do
6724     {
6725         /*
6726          * Allocate a 'adv_sgblk_t' structure from the board free
6727          * list. One 'adv_sgblk_t' structure holds NO_OF_SG_PER_BLOCK
6728          * (15) scatter-gather elements.
6729          */
6730         if ((sgblkp = boardp->adv_sgblkp) == NULL) {
6731             ASC_DBG(1, "adv_get_sglist: no free adv_sgblk_t\n");
6732             ASC_STATS(scp->device->host, adv_build_nosg);
6733
6734             /*
6735              * Allocation failed. Free 'adv_sgblk_t' structures already
6736              * allocated for the request.
6737              */
6738             while ((sgblkp = reqp->sgblkp) != NULL)
6739             {
6740                 /* Remove 'sgblkp' from the request list. */
6741                 reqp->sgblkp = sgblkp->next_sgblkp;
6742
6743                 /* Add 'sgblkp' to the board free list. */
6744                 sgblkp->next_sgblkp = boardp->adv_sgblkp;
6745                 boardp->adv_sgblkp = sgblkp;
6746             }
6747             return ASC_BUSY;
6748         } else {
6749             /* Complete 'adv_sgblk_t' board allocation. */
6750             boardp->adv_sgblkp = sgblkp->next_sgblkp;
6751             sgblkp->next_sgblkp = NULL;
6752
6753             /*
6754              * Get 8 byte aligned virtual and physical addresses for
6755              * the allocated ADV_SG_BLOCK structure.
6756              */
6757             sg_block = (ADV_SG_BLOCK *) ADV_8BALIGN(&sgblkp->sg_block);
6758             sg_block_paddr = virt_to_bus(sg_block);
6759
6760             /*
6761              * Check if this is the first 'adv_sgblk_t' for the request.
6762              */
6763             if (reqp->sgblkp == NULL)
6764             {
6765                 /* Request's first scatter-gather block. */
6766                 reqp->sgblkp = sgblkp;
6767
6768                 /*
6769                  * Set ADV_SCSI_REQ_T ADV_SG_BLOCK virtual and physical
6770                  * address pointers.
6771                  */
6772                 scsiqp->sg_list_ptr = sg_block;
6773                 scsiqp->sg_real_addr = cpu_to_le32(sg_block_paddr);
6774             } else
6775             {
6776                 /* Request's second or later scatter-gather block. */
6777                 sgblkp->next_sgblkp = reqp->sgblkp;
6778                 reqp->sgblkp = sgblkp;
6779
6780                 /*
6781                  * Point the previous ADV_SG_BLOCK structure to
6782                  * the newly allocated ADV_SG_BLOCK structure.
6783                  */
6784                 ASC_ASSERT(prev_sg_block != NULL);
6785                 prev_sg_block->sg_ptr = cpu_to_le32(sg_block_paddr);
6786             }
6787         }
6788
6789         for (i = 0; i < NO_OF_SG_PER_BLOCK; i++)
6790         {
6791             sg_block->sg_list[i].sg_addr = cpu_to_le32(sg_dma_address(slp));
6792             sg_block->sg_list[i].sg_count = cpu_to_le32(sg_dma_len(slp));
6793             ASC_STATS_ADD(scp->device->host, sg_xfer, ASC_CEILING(sg_dma_len(slp), 512));
6794
6795             if (--sg_elem_cnt == 0)
6796             {   /* Last ADV_SG_BLOCK and scatter-gather entry. */
6797                 sg_block->sg_cnt = i + 1;
6798                 sg_block->sg_ptr = 0L;    /* Last ADV_SG_BLOCK in list. */
6799                 return ADV_SUCCESS;
6800             }
6801             slp++;
6802         }
6803         sg_block->sg_cnt = NO_OF_SG_PER_BLOCK;
6804         prev_sg_block = sg_block;
6805     }
6806     while (1);
6807     /* NOTREACHED */
6808 }
6809
6810 /*
6811  * asc_isr_callback() - Second Level Interrupt Handler called by AscISR().
6812  *
6813  * Interrupt callback function for the Narrow SCSI Asc Library.
6814  */
6815 STATIC void
6816 asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
6817 {
6818     asc_board_t         *boardp;
6819     Scsi_Cmnd           *scp;
6820     struct Scsi_Host    *shp;
6821     int                 i;
6822
6823     ASC_DBG2(1, "asc_isr_callback: asc_dvc_varp 0x%lx, qdonep 0x%lx\n",
6824         (ulong) asc_dvc_varp, (ulong) qdonep);
6825     ASC_DBG_PRT_ASC_QDONE_INFO(2, qdonep);
6826
6827     /*
6828      * Get the Scsi_Cmnd structure and Scsi_Host structure for the
6829      * command that has been completed.
6830      */
6831     scp = (Scsi_Cmnd *) ASC_U32_TO_VADDR(qdonep->d2.srb_ptr);
6832     ASC_DBG1(1, "asc_isr_callback: scp 0x%lx\n", (ulong) scp);
6833
6834     if (scp == NULL) {
6835         ASC_PRINT("asc_isr_callback: scp is NULL\n");
6836         return;
6837     }
6838     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
6839
6840     /*
6841      * If the request's host pointer is not valid, display a
6842      * message and return.
6843      */
6844     shp = scp->device->host;
6845     for (i = 0; i < asc_board_count; i++) {
6846         if (asc_host[i] == shp) {
6847             break;
6848         }
6849     }
6850     if (i == asc_board_count) {
6851         ASC_PRINT2(
6852             "asc_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
6853             (ulong) scp, (ulong) shp);
6854         return;
6855     }
6856
6857     ASC_STATS(shp, callback);
6858     ASC_DBG1(1, "asc_isr_callback: shp 0x%lx\n", (ulong) shp);
6859
6860     /*
6861      * If the request isn't found on the active queue, it may
6862      * have been removed to handle a reset request.
6863      * Display a message and return.
6864      */
6865     boardp = ASC_BOARDP(shp);
6866     ASC_ASSERT(asc_dvc_varp == &boardp->dvc_var.asc_dvc_var);
6867     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
6868         ASC_PRINT2(
6869             "asc_isr_callback: board %d: scp 0x%lx not on active queue\n",
6870             boardp->id, (ulong) scp);
6871         return;
6872     }
6873
6874     /*
6875      * 'qdonep' contains the command's ending status.
6876      */
6877     switch (qdonep->d3.done_stat) {
6878     case QD_NO_ERROR:
6879         ASC_DBG(2, "asc_isr_callback: QD_NO_ERROR\n");
6880         scp->result = 0;
6881
6882         /*
6883          * If an INQUIRY command completed successfully, then call
6884          * the AscInquiryHandling() function to set-up the device.
6885          */
6886         if (scp->cmnd[0] == INQUIRY && scp->device->lun == 0 &&
6887             (scp->request_bufflen - qdonep->remain_bytes) >= 8)
6888         {
6889             AscInquiryHandling(asc_dvc_varp, scp->device->id & 0x7,
6890                 (ASC_SCSI_INQUIRY *) scp->request_buffer);
6891         }
6892
6893         /*
6894          * Check for an underrun condition.
6895          *
6896          * If there was no error and an underrun condition, then
6897          * then return the number of underrun bytes.
6898          */
6899         if (scp->request_bufflen != 0 && qdonep->remain_bytes != 0 &&
6900             qdonep->remain_bytes <= scp->request_bufflen) {
6901             ASC_DBG1(1, "asc_isr_callback: underrun condition %u bytes\n",
6902             (unsigned) qdonep->remain_bytes);
6903             scp->resid = qdonep->remain_bytes;
6904         }
6905         break;
6906
6907     case QD_WITH_ERROR:
6908         ASC_DBG(2, "asc_isr_callback: QD_WITH_ERROR\n");
6909         switch (qdonep->d3.host_stat) {
6910         case QHSTA_NO_ERROR:
6911             if (qdonep->d3.scsi_stat == SAM_STAT_CHECK_CONDITION) {
6912                 ASC_DBG(2, "asc_isr_callback: SAM_STAT_CHECK_CONDITION\n");
6913                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
6914                     sizeof(scp->sense_buffer));
6915                 /*
6916                  * Note: The 'status_byte()' macro used by target drivers
6917                  * defined in scsi.h shifts the status byte returned by
6918                  * host drivers right by 1 bit. This is why target drivers
6919                  * also use right shifted status byte definitions. For
6920                  * instance target drivers use CHECK_CONDITION, defined to
6921                  * 0x1, instead of the SCSI defined check condition value
6922                  * of 0x2. Host drivers are supposed to return the status
6923                  * byte as it is defined by SCSI.
6924                  */
6925                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
6926                     STATUS_BYTE(qdonep->d3.scsi_stat);
6927             } else {
6928                 scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
6929             }
6930             break;
6931
6932         default:
6933             /* QHSTA error occurred */
6934             ASC_DBG1(1, "asc_isr_callback: host_stat 0x%x\n",
6935                 qdonep->d3.host_stat);
6936             scp->result = HOST_BYTE(DID_BAD_TARGET);
6937             break;
6938         }
6939         break;
6940
6941     case QD_ABORTED_BY_HOST:
6942         ASC_DBG(1, "asc_isr_callback: QD_ABORTED_BY_HOST\n");
6943         scp->result = HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.scsi_msg) |
6944                 STATUS_BYTE(qdonep->d3.scsi_stat);
6945         break;
6946
6947     default:
6948         ASC_DBG1(1, "asc_isr_callback: done_stat 0x%x\n", qdonep->d3.done_stat);
6949         scp->result = HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.scsi_msg) |
6950                 STATUS_BYTE(qdonep->d3.scsi_stat);
6951         break;
6952     }
6953
6954     /*
6955      * If the 'init_tidmask' bit isn't already set for the target and the
6956      * current request finished normally, then set the bit for the target
6957      * to indicate that a device is present.
6958      */
6959     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
6960         qdonep->d3.done_stat == QD_NO_ERROR &&
6961         qdonep->d3.host_stat == QHSTA_NO_ERROR) {
6962         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
6963     }
6964
6965     /*
6966      * Because interrupts may be enabled by the 'Scsi_Cmnd' done
6967      * function, add the command to the end of the board's done queue.
6968      * The done function for the command will be called from
6969      * advansys_interrupt().
6970      */
6971     asc_enqueue(&boardp->done, scp, ASC_BACK);
6972
6973     return;
6974 }
6975
6976 /*
6977  * adv_isr_callback() - Second Level Interrupt Handler called by AdvISR().
6978  *
6979  * Callback function for the Wide SCSI Adv Library.
6980  */
6981 STATIC void
6982 adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
6983 {
6984     asc_board_t         *boardp;
6985     adv_req_t           *reqp;
6986     adv_sgblk_t         *sgblkp;
6987     Scsi_Cmnd           *scp;
6988     struct Scsi_Host    *shp;
6989     int                 i;
6990     ADV_DCNT            resid_cnt;
6991
6992
6993     ASC_DBG2(1, "adv_isr_callback: adv_dvc_varp 0x%lx, scsiqp 0x%lx\n",
6994         (ulong) adv_dvc_varp, (ulong) scsiqp);
6995     ASC_DBG_PRT_ADV_SCSI_REQ_Q(2, scsiqp);
6996
6997     /*
6998      * Get the adv_req_t structure for the command that has been
6999      * completed. The adv_req_t structure actually contains the
7000      * completed ADV_SCSI_REQ_Q structure.
7001      */
7002     reqp = (adv_req_t *) ADV_U32_TO_VADDR(scsiqp->srb_ptr);
7003     ASC_DBG1(1, "adv_isr_callback: reqp 0x%lx\n", (ulong) reqp);
7004     if (reqp == NULL) {
7005         ASC_PRINT("adv_isr_callback: reqp is NULL\n");
7006         return;
7007     }
7008
7009     /*
7010      * Get the Scsi_Cmnd structure and Scsi_Host structure for the
7011      * command that has been completed.
7012      *
7013      * Note: The adv_req_t request structure and adv_sgblk_t structure,
7014      * if any, are dropped, because a board structure pointer can not be
7015      * determined.
7016      */
7017     scp = reqp->cmndp;
7018     ASC_DBG1(1, "adv_isr_callback: scp 0x%lx\n", (ulong) scp);
7019     if (scp == NULL) {
7020         ASC_PRINT("adv_isr_callback: scp is NULL; adv_req_t dropped.\n");
7021         return;
7022     }
7023     ASC_DBG_PRT_CDB(2, scp->cmnd, scp->cmd_len);
7024
7025     /*
7026      * If the request's host pointer is not valid, display a message
7027      * and return.
7028      */
7029     shp = scp->device->host;
7030     for (i = 0; i < asc_board_count; i++) {
7031         if (asc_host[i] == shp) {
7032             break;
7033         }
7034     }
7035     /*
7036      * Note: If the host structure is not found, the adv_req_t request
7037      * structure and adv_sgblk_t structure, if any, is dropped.
7038      */
7039     if (i == asc_board_count) {
7040         ASC_PRINT2(
7041             "adv_isr_callback: scp 0x%lx has bad host pointer, host 0x%lx\n",
7042             (ulong) scp, (ulong) shp);
7043         return;
7044     }
7045
7046     ASC_STATS(shp, callback);
7047     ASC_DBG1(1, "adv_isr_callback: shp 0x%lx\n", (ulong) shp);
7048
7049     /*
7050      * If the request isn't found on the active queue, it may have been
7051      * removed to handle a reset request. Display a message and return.
7052      *
7053      * Note: Because the structure may still be in use don't attempt
7054      * to free the adv_req_t and adv_sgblk_t, if any, structures.
7055      */
7056     boardp = ASC_BOARDP(shp);
7057     ASC_ASSERT(adv_dvc_varp == &boardp->dvc_var.adv_dvc_var);
7058     if (asc_rmqueue(&boardp->active, scp) == ASC_FALSE) {
7059         ASC_PRINT2(
7060             "adv_isr_callback: board %d: scp 0x%lx not on active queue\n",
7061             boardp->id, (ulong) scp);
7062         return;
7063     }
7064
7065     /*
7066      * 'done_status' contains the command's ending status.
7067      */
7068     switch (scsiqp->done_status) {
7069     case QD_NO_ERROR:
7070         ASC_DBG(2, "adv_isr_callback: QD_NO_ERROR\n");
7071         scp->result = 0;
7072
7073         /*
7074          * Check for an underrun condition.
7075          *
7076          * If there was no error and an underrun condition, then
7077          * then return the number of underrun bytes.
7078          */
7079         resid_cnt = le32_to_cpu(scsiqp->data_cnt);
7080         if (scp->request_bufflen != 0 && resid_cnt != 0 &&
7081             resid_cnt <= scp->request_bufflen) {
7082             ASC_DBG1(1, "adv_isr_callback: underrun condition %lu bytes\n",
7083                 (ulong) resid_cnt);
7084             scp->resid = resid_cnt;
7085         }
7086         break;
7087
7088     case QD_WITH_ERROR:
7089         ASC_DBG(2, "adv_isr_callback: QD_WITH_ERROR\n");
7090         switch (scsiqp->host_status) {
7091         case QHSTA_NO_ERROR:
7092             if (scsiqp->scsi_status == SAM_STAT_CHECK_CONDITION) {
7093                 ASC_DBG(2, "adv_isr_callback: SAM_STAT_CHECK_CONDITION\n");
7094                 ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
7095                     sizeof(scp->sense_buffer));
7096                 /*
7097                  * Note: The 'status_byte()' macro used by target drivers
7098                  * defined in scsi.h shifts the status byte returned by
7099                  * host drivers right by 1 bit. This is why target drivers
7100                  * also use right shifted status byte definitions. For
7101                  * instance target drivers use CHECK_CONDITION, defined to
7102                  * 0x1, instead of the SCSI defined check condition value
7103                  * of 0x2. Host drivers are supposed to return the status
7104                  * byte as it is defined by SCSI.
7105                  */
7106                 scp->result = DRIVER_BYTE(DRIVER_SENSE) |
7107                     STATUS_BYTE(scsiqp->scsi_status);
7108             } else {
7109                 scp->result = STATUS_BYTE(scsiqp->scsi_status);
7110             }
7111             break;
7112
7113         default:
7114             /* Some other QHSTA error occurred. */
7115             ASC_DBG1(1, "adv_isr_callback: host_status 0x%x\n",
7116                 scsiqp->host_status);
7117             scp->result = HOST_BYTE(DID_BAD_TARGET);
7118             break;
7119         }
7120         break;
7121
7122     case QD_ABORTED_BY_HOST:
7123         ASC_DBG(1, "adv_isr_callback: QD_ABORTED_BY_HOST\n");
7124         scp->result = HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
7125         break;
7126
7127     default:
7128         ASC_DBG1(1, "adv_isr_callback: done_status 0x%x\n", scsiqp->done_status);
7129         scp->result = HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
7130         break;
7131     }
7132
7133     /*
7134      * If the 'init_tidmask' bit isn't already set for the target and the
7135      * current request finished normally, then set the bit for the target
7136      * to indicate that a device is present.
7137      */
7138     if ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(scp->device->id)) == 0 &&
7139         scsiqp->done_status == QD_NO_ERROR &&
7140         scsiqp->host_status == QHSTA_NO_ERROR) {
7141         boardp->init_tidmask |= ADV_TID_TO_TIDMASK(scp->device->id);
7142     }
7143
7144     /*
7145      * Because interrupts may be enabled by the 'Scsi_Cmnd' done
7146      * function, add the command to the end of the board's done queue.
7147      * The done function for the command will be called from
7148      * advansys_interrupt().
7149      */
7150     asc_enqueue(&boardp->done, scp, ASC_BACK);
7151
7152     /*
7153      * Free all 'adv_sgblk_t' structures allocated for the request.
7154      */
7155     while ((sgblkp = reqp->sgblkp) != NULL)
7156     {
7157         /* Remove 'sgblkp' from the request list. */
7158         reqp->sgblkp = sgblkp->next_sgblkp;
7159
7160         /* Add 'sgblkp' to the board free list. */
7161         sgblkp->next_sgblkp = boardp->adv_sgblkp;
7162         boardp->adv_sgblkp = sgblkp;
7163     }
7164
7165     /*
7166      * Free the adv_req_t structure used with the command by adding
7167      * it back to the board free list.
7168      */
7169     reqp->next_reqp = boardp->adv_reqp;
7170     boardp->adv_reqp = reqp;
7171
7172     ASC_DBG(1, "adv_isr_callback: done\n");
7173
7174     return;
7175 }
7176
7177 /*
7178  * adv_async_callback() - Adv Library asynchronous event callback function.
7179  */
7180 STATIC void
7181 adv_async_callback(ADV_DVC_VAR *adv_dvc_varp, uchar code)
7182 {
7183     switch (code)
7184     {
7185     case ADV_ASYNC_SCSI_BUS_RESET_DET:
7186         /*
7187          * The firmware detected a SCSI Bus reset.
7188          */
7189         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_SCSI_BUS_RESET_DET\n");
7190         break;
7191
7192     case ADV_ASYNC_RDMA_FAILURE:
7193         /*
7194          * Handle RDMA failure by resetting the SCSI Bus and
7195          * possibly the chip if it is unresponsive. Log the error
7196          * with a unique code.
7197          */
7198         ASC_DBG(0, "adv_async_callback: ADV_ASYNC_RDMA_FAILURE\n");
7199         AdvResetChipAndSB(adv_dvc_varp);
7200         break;
7201
7202     case ADV_HOST_SCSI_BUS_RESET:
7203         /*
7204          * Host generated SCSI bus reset occurred.
7205          */
7206         ASC_DBG(0, "adv_async_callback: ADV_HOST_SCSI_BUS_RESET\n");
7207         break;
7208
7209     default:
7210         ASC_DBG1(0, "DvcAsyncCallBack: unknown code 0x%x\n", code);
7211         break;
7212     }
7213 }
7214
7215 /*
7216  * Add a 'REQP' to the end of specified queue. Set 'tidmask'
7217  * to indicate a command is queued for the device.
7218  *
7219  * 'flag' may be either ASC_FRONT or ASC_BACK.
7220  *
7221  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7222  */
7223 STATIC void
7224 asc_enqueue(asc_queue_t *ascq, REQP reqp, int flag)
7225 {
7226     int        tid;
7227
7228     ASC_DBG3(3, "asc_enqueue: ascq 0x%lx, reqp 0x%lx, flag %d\n",
7229         (ulong) ascq, (ulong) reqp, flag);
7230     ASC_ASSERT(reqp != NULL);
7231     ASC_ASSERT(flag == ASC_FRONT || flag == ASC_BACK);
7232     tid = REQPTID(reqp);
7233     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7234     if (flag == ASC_FRONT) {
7235         reqp->host_scribble = (unsigned char *)ascq->q_first[tid];
7236         ascq->q_first[tid] = reqp;
7237         /* If the queue was empty, set the last pointer. */
7238         if (ascq->q_last[tid] == NULL) {
7239             ascq->q_last[tid] = reqp;
7240         }
7241     } else { /* ASC_BACK */
7242         if (ascq->q_last[tid] != NULL) {
7243             ascq->q_last[tid]->host_scribble = (unsigned char *)reqp;
7244         }
7245         ascq->q_last[tid] = reqp;
7246         reqp->host_scribble = NULL;
7247         /* If the queue was empty, set the first pointer. */
7248         if (ascq->q_first[tid] == NULL) {
7249             ascq->q_first[tid] = reqp;
7250         }
7251     }
7252     /* The queue has at least one entry, set its bit. */
7253     ascq->q_tidmask |= ADV_TID_TO_TIDMASK(tid);
7254 #ifdef ADVANSYS_STATS
7255     /* Maintain request queue statistics. */
7256     ascq->q_tot_cnt[tid]++;
7257     ascq->q_cur_cnt[tid]++;
7258     if (ascq->q_cur_cnt[tid] > ascq->q_max_cnt[tid]) {
7259         ascq->q_max_cnt[tid] = ascq->q_cur_cnt[tid];
7260         ASC_DBG2(2, "asc_enqueue: new q_max_cnt[%d] %d\n",
7261             tid, ascq->q_max_cnt[tid]);
7262     }
7263     REQPTIME(reqp) = REQTIMESTAMP();
7264 #endif /* ADVANSYS_STATS */
7265     ASC_DBG1(3, "asc_enqueue: reqp 0x%lx\n", (ulong) reqp);
7266     return;
7267 }
7268
7269 /*
7270  * Return first queued 'REQP' on the specified queue for
7271  * the specified target device. Clear the 'tidmask' bit for
7272  * the device if no more commands are left queued for it.
7273  *
7274  * 'REQPNEXT(reqp)' returns reqp's next pointer.
7275  */
7276 STATIC REQP
7277 asc_dequeue(asc_queue_t *ascq, int tid)
7278 {
7279     REQP    reqp;
7280
7281     ASC_DBG2(3, "asc_dequeue: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7282     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7283     if ((reqp = ascq->q_first[tid]) != NULL) {
7284         ASC_ASSERT(ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid));
7285         ascq->q_first[tid] = REQPNEXT(reqp);
7286         /* If the queue is empty, clear its bit and the last pointer. */
7287         if (ascq->q_first[tid] == NULL) {
7288             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7289             ASC_ASSERT(ascq->q_last[tid] == reqp);
7290             ascq->q_last[tid] = NULL;
7291         }
7292 #ifdef ADVANSYS_STATS
7293         /* Maintain request queue statistics. */
7294         ascq->q_cur_cnt[tid]--;
7295         ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7296         REQTIMESTAT("asc_dequeue", ascq, reqp, tid);
7297 #endif /* ADVANSYS_STATS */
7298     }
7299     ASC_DBG1(3, "asc_dequeue: reqp 0x%lx\n", (ulong) reqp);
7300     return reqp;
7301 }
7302
7303 /*
7304  * Return a pointer to a singly linked list of all the requests queued
7305  * for 'tid' on the 'asc_queue_t' pointed to by 'ascq'.
7306  *
7307  * If 'lastpp' is not NULL, '*lastpp' will be set to point to the
7308  * the last request returned in the singly linked list.
7309  *
7310  * 'tid' should either be a valid target id or if it is ASC_TID_ALL,
7311  * then all queued requests are concatenated into one list and
7312  * returned.
7313  *
7314  * Note: If 'lastpp' is used to append a new list to the end of
7315  * an old list, only change the old list last pointer if '*lastpp'
7316  * (or the function return value) is not NULL, i.e. use a temporary
7317  * variable for 'lastpp' and check its value after the function return
7318  * before assigning it to the list last pointer.
7319  *
7320  * Unfortunately collecting queuing time statistics adds overhead to
7321  * the function that isn't inherent to the function's algorithm.
7322  */
7323 STATIC REQP
7324 asc_dequeue_list(asc_queue_t *ascq, REQP *lastpp, int tid)
7325 {
7326     REQP    firstp, lastp;
7327     int     i;
7328
7329     ASC_DBG2(3, "asc_dequeue_list: ascq 0x%lx, tid %d\n", (ulong) ascq, tid);
7330     ASC_ASSERT((tid == ASC_TID_ALL) || (tid >= 0 && tid <= ADV_MAX_TID));
7331
7332     /*
7333      * If 'tid' is not ASC_TID_ALL, return requests only for
7334      * the specified 'tid'. If 'tid' is ASC_TID_ALL, return all
7335      * requests for all tids.
7336      */
7337     if (tid != ASC_TID_ALL) {
7338         /* Return all requests for the specified 'tid'. */
7339         if ((ascq->q_tidmask & ADV_TID_TO_TIDMASK(tid)) == 0) {
7340             /* List is empty; Set first and last return pointers to NULL. */
7341             firstp = lastp = NULL;
7342         } else {
7343             firstp = ascq->q_first[tid];
7344             lastp = ascq->q_last[tid];
7345             ascq->q_first[tid] = ascq->q_last[tid] = NULL;
7346             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7347 #ifdef ADVANSYS_STATS
7348             {
7349                 REQP reqp;
7350                 ascq->q_cur_cnt[tid] = 0;
7351                 for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7352                     REQTIMESTAT("asc_dequeue_list", ascq, reqp, tid);
7353                 }
7354             }
7355 #endif /* ADVANSYS_STATS */
7356         }
7357     } else {
7358         /* Return all requests for all tids. */
7359         firstp = lastp = NULL;
7360         for (i = 0; i <= ADV_MAX_TID; i++) {
7361             if (ascq->q_tidmask & ADV_TID_TO_TIDMASK(i)) {
7362                 if (firstp == NULL) {
7363                     firstp = ascq->q_first[i];
7364                     lastp = ascq->q_last[i];
7365                 } else {
7366                     ASC_ASSERT(lastp != NULL);
7367                     lastp->host_scribble = (unsigned char *)ascq->q_first[i];
7368                     lastp = ascq->q_last[i];
7369                 }
7370                 ascq->q_first[i] = ascq->q_last[i] = NULL;
7371                 ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7372 #ifdef ADVANSYS_STATS
7373                 ascq->q_cur_cnt[i] = 0;
7374 #endif /* ADVANSYS_STATS */
7375             }
7376         }
7377 #ifdef ADVANSYS_STATS
7378         {
7379             REQP reqp;
7380             for (reqp = firstp; reqp; reqp = REQPNEXT(reqp)) {
7381                 REQTIMESTAT("asc_dequeue_list", ascq, reqp, reqp->device->id);
7382             }
7383         }
7384 #endif /* ADVANSYS_STATS */
7385     }
7386     if (lastpp) {
7387         *lastpp = lastp;
7388     }
7389     ASC_DBG1(3, "asc_dequeue_list: firstp 0x%lx\n", (ulong) firstp);
7390     return firstp;
7391 }
7392
7393 /*
7394  * Remove the specified 'REQP' from the specified queue for
7395  * the specified target device. Clear the 'tidmask' bit for the
7396  * device if no more commands are left queued for it.
7397  *
7398  * 'REQPNEXT(reqp)' returns reqp's the next pointer.
7399  *
7400  * Return ASC_TRUE if the command was found and removed,
7401  * otherwise return ASC_FALSE.
7402  */
7403 STATIC int
7404 asc_rmqueue(asc_queue_t *ascq, REQP reqp)
7405 {
7406     REQP        currp, prevp;
7407     int         tid;
7408     int         ret = ASC_FALSE;
7409
7410     ASC_DBG2(3, "asc_rmqueue: ascq 0x%lx, reqp 0x%lx\n",
7411         (ulong) ascq, (ulong) reqp);
7412     ASC_ASSERT(reqp != NULL);
7413
7414     tid = REQPTID(reqp);
7415     ASC_ASSERT(tid >= 0 && tid <= ADV_MAX_TID);
7416
7417     /*
7418      * Handle the common case of 'reqp' being the first
7419      * entry on the queue.
7420      */
7421     if (reqp == ascq->q_first[tid]) {
7422         ret = ASC_TRUE;
7423         ascq->q_first[tid] = REQPNEXT(reqp);
7424         /* If the queue is now empty, clear its bit and the last pointer. */
7425         if (ascq->q_first[tid] == NULL) {
7426             ascq->q_tidmask &= ~ADV_TID_TO_TIDMASK(tid);
7427             ASC_ASSERT(ascq->q_last[tid] == reqp);
7428             ascq->q_last[tid] = NULL;
7429         }
7430     } else if (ascq->q_first[tid] != NULL) {
7431         ASC_ASSERT(ascq->q_last[tid] != NULL);
7432         /*
7433          * Because the case of 'reqp' being the first entry has been
7434          * handled above and it is known the queue is not empty, if
7435          * 'reqp' is found on the queue it is guaranteed the queue will
7436          * not become empty and that 'q_first[tid]' will not be changed.
7437          *
7438          * Set 'prevp' to the first entry, 'currp' to the second entry,
7439          * and search for 'reqp'.
7440          */
7441         for (prevp = ascq->q_first[tid], currp = REQPNEXT(prevp);
7442              currp; prevp = currp, currp = REQPNEXT(currp)) {
7443             if (currp == reqp) {
7444                 ret = ASC_TRUE;
7445                 prevp->host_scribble = (unsigned char *)REQPNEXT(currp);
7446                 reqp->host_scribble = NULL;
7447                 if (ascq->q_last[tid] == reqp) {
7448                     ascq->q_last[tid] = prevp;
7449                 }
7450                 break;
7451             }
7452         }
7453     }
7454 #ifdef ADVANSYS_STATS
7455     /* Maintain request queue statistics. */
7456     if (ret == ASC_TRUE) {
7457         ascq->q_cur_cnt[tid]--;
7458         REQTIMESTAT("asc_rmqueue", ascq, reqp, tid);
7459     }
7460     ASC_ASSERT(ascq->q_cur_cnt[tid] >= 0);
7461 #endif /* ADVANSYS_STATS */
7462     ASC_DBG2(3, "asc_rmqueue: reqp 0x%lx, ret %d\n", (ulong) reqp, ret);
7463     return ret;
7464 }
7465
7466 /*
7467  * Execute as many queued requests as possible for the specified queue.
7468  *
7469  * Calls asc_execute_scsi_cmnd() to execute a REQP/Scsi_Cmnd.
7470  */
7471 STATIC void
7472 asc_execute_queue(asc_queue_t *ascq)
7473 {
7474     ADV_SCSI_BIT_ID_TYPE    scan_tidmask;
7475     REQP                    reqp;
7476     int                     i;
7477
7478     ASC_DBG1(1, "asc_execute_queue: ascq 0x%lx\n", (ulong) ascq);
7479     /*
7480      * Execute queued commands for devices attached to
7481      * the current board in round-robin fashion.
7482      */
7483     scan_tidmask = ascq->q_tidmask;
7484     do {
7485         for (i = 0; i <= ADV_MAX_TID; i++) {
7486             if (scan_tidmask & ADV_TID_TO_TIDMASK(i)) {
7487                 if ((reqp = asc_dequeue(ascq, i)) == NULL) {
7488                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7489                 } else if (asc_execute_scsi_cmnd((Scsi_Cmnd *) reqp)
7490                             == ASC_BUSY) {
7491                     scan_tidmask &= ~ADV_TID_TO_TIDMASK(i);
7492                     /*
7493                      * The request returned ASC_BUSY. Enqueue at the front of
7494                      * target's waiting list to maintain correct ordering.
7495                      */
7496                     asc_enqueue(ascq, reqp, ASC_FRONT);
7497                 }
7498             }
7499         }
7500     } while (scan_tidmask);
7501     return;
7502 }
7503
7504 #ifdef CONFIG_PROC_FS
7505 /*
7506  * asc_prt_board_devices()
7507  *
7508  * Print driver information for devices attached to the board.
7509  *
7510  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7511  * cf. asc_prt_line().
7512  *
7513  * Return the number of characters copied into 'cp'. No more than
7514  * 'cplen' characters will be copied to 'cp'.
7515  */
7516 STATIC int
7517 asc_prt_board_devices(struct Scsi_Host *shp, char *cp, int cplen)
7518 {
7519     asc_board_t        *boardp;
7520     int                leftlen;
7521     int                totlen;
7522     int                len;
7523     int                chip_scsi_id;
7524     int                i;
7525
7526     boardp = ASC_BOARDP(shp);
7527     leftlen = cplen;
7528     totlen = len = 0;
7529
7530     len = asc_prt_line(cp, leftlen,
7531 "\nDevice Information for AdvanSys SCSI Host %d:\n", shp->host_no);
7532     ASC_PRT_NEXT();
7533
7534     if (ASC_NARROW_BOARD(boardp)) {
7535         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
7536     } else {
7537         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
7538     }
7539
7540     len = asc_prt_line(cp, leftlen, "Target IDs Detected:");
7541     ASC_PRT_NEXT();
7542     for (i = 0; i <= ADV_MAX_TID; i++) {
7543         if (boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) {
7544             len = asc_prt_line(cp, leftlen, " %X,", i);
7545             ASC_PRT_NEXT();
7546         }
7547     }
7548     len = asc_prt_line(cp, leftlen, " (%X=Host Adapter)\n", chip_scsi_id);
7549     ASC_PRT_NEXT();
7550
7551     return totlen;
7552 }
7553
7554 /*
7555  * Display Wide Board BIOS Information.
7556  */
7557 STATIC int
7558 asc_prt_adv_bios(struct Scsi_Host *shp, char *cp, int cplen)
7559 {
7560     asc_board_t        *boardp;
7561     int                leftlen;
7562     int                totlen;
7563     int                len;
7564     ushort             major, minor, letter;
7565
7566     boardp = ASC_BOARDP(shp);
7567     leftlen = cplen;
7568     totlen = len = 0;
7569
7570     len = asc_prt_line(cp, leftlen, "\nROM BIOS Version: ");
7571     ASC_PRT_NEXT();
7572
7573     /*
7574      * If the BIOS saved a valid signature, then fill in
7575      * the BIOS code segment base address.
7576      */
7577     if (boardp->bios_signature != 0x55AA) {
7578         len = asc_prt_line(cp, leftlen, "Disabled or Pre-3.1\n");
7579         ASC_PRT_NEXT();
7580         len = asc_prt_line(cp, leftlen,
7581 "BIOS either disabled or Pre-3.1. If it is pre-3.1, then a newer version\n");
7582         ASC_PRT_NEXT();
7583         len = asc_prt_line(cp, leftlen,
7584 "can be found at the ConnectCom FTP site: ftp://ftp.connectcom.net/pub\n");
7585         ASC_PRT_NEXT();
7586     } else {
7587         major = (boardp->bios_version >> 12) & 0xF;
7588         minor = (boardp->bios_version >> 8) & 0xF;
7589         letter = (boardp->bios_version & 0xFF);
7590
7591         len = asc_prt_line(cp, leftlen, "%d.%d%c\n",
7592             major, minor, letter >= 26 ? '?' : letter + 'A');
7593         ASC_PRT_NEXT();
7594
7595         /*
7596          * Current available ROM BIOS release is 3.1I for UW
7597          * and 3.2I for U2W. This code doesn't differentiate
7598          * UW and U2W boards.
7599          */
7600         if (major < 3 || (major <= 3 && minor < 1) ||
7601             (major <= 3 && minor <= 1 && letter < ('I'- 'A'))) {
7602             len = asc_prt_line(cp, leftlen,
7603 "Newer version of ROM BIOS is available at the ConnectCom FTP site:\n");
7604             ASC_PRT_NEXT();
7605             len = asc_prt_line(cp, leftlen,
7606 "ftp://ftp.connectcom.net/pub\n");
7607             ASC_PRT_NEXT();
7608         }
7609     }
7610
7611     return totlen;
7612 }
7613
7614 /*
7615  * Add serial number to information bar if signature AAh
7616  * is found in at bit 15-9 (7 bits) of word 1.
7617  *
7618  * Serial Number consists fo 12 alpha-numeric digits.
7619  *
7620  *       1 - Product type (A,B,C,D..)  Word0: 15-13 (3 bits)
7621  *       2 - MFG Location (A,B,C,D..)  Word0: 12-10 (3 bits)
7622  *     3-4 - Product ID (0-99)         Word0: 9-0 (10 bits)
7623  *       5 - Product revision (A-J)    Word0:  "         "
7624  *
7625  *           Signature                 Word1: 15-9 (7 bits)
7626  *       6 - Year (0-9)                Word1: 8-6 (3 bits) & Word2: 15 (1 bit)
7627  *     7-8 - Week of the year (1-52)   Word1: 5-0 (6 bits)
7628  *
7629  *    9-12 - Serial Number (A001-Z999) Word2: 14-0 (15 bits)
7630  *
7631  * Note 1: Only production cards will have a serial number.
7632  *
7633  * Note 2: Signature is most significant 7 bits (0xFE).
7634  *
7635  * Returns ASC_TRUE if serial number found, otherwise returns ASC_FALSE.
7636  */
7637 STATIC int
7638 asc_get_eeprom_string(ushort *serialnum, uchar *cp)
7639 {
7640     ushort      w, num;
7641
7642     if ((serialnum[1] & 0xFE00) != ((ushort) 0xAA << 8)) {
7643         return ASC_FALSE;
7644     } else {
7645         /*
7646          * First word - 6 digits.
7647          */
7648         w = serialnum[0];
7649
7650         /* Product type - 1st digit. */
7651         if ((*cp = 'A' + ((w & 0xE000) >> 13)) == 'H') {
7652             /* Product type is P=Prototype */
7653             *cp += 0x8;
7654         }
7655         cp++;
7656
7657         /* Manufacturing location - 2nd digit. */
7658         *cp++ = 'A' + ((w & 0x1C00) >> 10);
7659
7660         /* Product ID - 3rd, 4th digits. */
7661         num = w & 0x3FF;
7662         *cp++ = '0' + (num / 100);
7663         num %= 100;
7664         *cp++ = '0' + (num / 10);
7665
7666         /* Product revision - 5th digit. */
7667         *cp++ = 'A' + (num % 10);
7668
7669         /*
7670          * Second word
7671          */
7672         w = serialnum[1];
7673
7674         /*
7675          * Year - 6th digit.
7676          *
7677          * If bit 15 of third word is set, then the
7678          * last digit of the year is greater than 7.
7679          */
7680         if (serialnum[2] & 0x8000) {
7681             *cp++ = '8' + ((w & 0x1C0) >> 6);
7682         } else {
7683             *cp++ = '0' + ((w & 0x1C0) >> 6);
7684         }
7685
7686         /* Week of year - 7th, 8th digits. */
7687         num = w & 0x003F;
7688         *cp++ = '0' + num / 10;
7689         num %= 10;
7690         *cp++ = '0' + num;
7691
7692         /*
7693          * Third word
7694          */
7695         w = serialnum[2] & 0x7FFF;
7696
7697         /* Serial number - 9th digit. */
7698         *cp++ = 'A' + (w / 1000);
7699
7700         /* 10th, 11th, 12th digits. */
7701         num = w % 1000;
7702         *cp++ = '0' + num / 100;
7703         num %= 100;
7704         *cp++ = '0' + num / 10;
7705         num %= 10;
7706         *cp++ = '0' + num;
7707
7708         *cp = '\0';     /* Null Terminate the string. */
7709         return ASC_TRUE;
7710     }
7711 }
7712
7713 /*
7714  * asc_prt_asc_board_eeprom()
7715  *
7716  * Print board EEPROM configuration.
7717  *
7718  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7719  * cf. asc_prt_line().
7720  *
7721  * Return the number of characters copied into 'cp'. No more than
7722  * 'cplen' characters will be copied to 'cp'.
7723  */
7724 STATIC int
7725 asc_prt_asc_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7726 {
7727     asc_board_t        *boardp;
7728     ASC_DVC_VAR        *asc_dvc_varp;
7729     int                leftlen;
7730     int                totlen;
7731     int                len;
7732     ASCEEP_CONFIG      *ep;
7733     int                i;
7734 #ifdef CONFIG_ISA
7735     int                isa_dma_speed[] = { 10, 8, 7, 6, 5, 4, 3, 2 };
7736 #endif /* CONFIG_ISA */
7737     uchar              serialstr[13];
7738
7739     boardp = ASC_BOARDP(shp);
7740     asc_dvc_varp = &boardp->dvc_var.asc_dvc_var;
7741     ep = &boardp->eep_config.asc_eep;
7742
7743     leftlen = cplen;
7744     totlen = len = 0;
7745
7746     len = asc_prt_line(cp, leftlen,
7747 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7748     ASC_PRT_NEXT();
7749
7750     if (asc_get_eeprom_string((ushort *) &ep->adapter_info[0], serialstr) ==
7751         ASC_TRUE) {
7752         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7753         ASC_PRT_NEXT();
7754     } else {
7755         if (ep->adapter_info[5] == 0xBB) {
7756             len = asc_prt_line(cp, leftlen,
7757                 " Default Settings Used for EEPROM-less Adapter.\n");
7758             ASC_PRT_NEXT();
7759         } else {
7760             len = asc_prt_line(cp, leftlen,
7761                 " Serial Number Signature Not Present.\n");
7762             ASC_PRT_NEXT();
7763         }
7764     }
7765
7766     len = asc_prt_line(cp, leftlen,
7767 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7768         ASC_EEP_GET_CHIP_ID(ep), ep->max_total_qng, ep->max_tag_qng);
7769     ASC_PRT_NEXT();
7770
7771     len = asc_prt_line(cp, leftlen,
7772 " cntl 0x%x, no_scam 0x%x\n",
7773         ep->cntl, ep->no_scam);
7774     ASC_PRT_NEXT();
7775
7776     len = asc_prt_line(cp, leftlen,
7777 " Target ID:           ");
7778     ASC_PRT_NEXT();
7779     for (i = 0; i <= ASC_MAX_TID; i++) {
7780         len = asc_prt_line(cp, leftlen, " %d", i);
7781         ASC_PRT_NEXT();
7782     }
7783     len = asc_prt_line(cp, leftlen, "\n");
7784     ASC_PRT_NEXT();
7785
7786     len = asc_prt_line(cp, leftlen,
7787 " Disconnects:         ");
7788     ASC_PRT_NEXT();
7789     for (i = 0; i <= ASC_MAX_TID; i++) {
7790         len = asc_prt_line(cp, leftlen, " %c",
7791             (ep->disc_enable & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7792         ASC_PRT_NEXT();
7793     }
7794     len = asc_prt_line(cp, leftlen, "\n");
7795     ASC_PRT_NEXT();
7796
7797     len = asc_prt_line(cp, leftlen,
7798 " Command Queuing:     ");
7799     ASC_PRT_NEXT();
7800     for (i = 0; i <= ASC_MAX_TID; i++) {
7801         len = asc_prt_line(cp, leftlen, " %c",
7802             (ep->use_cmd_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7803         ASC_PRT_NEXT();
7804     }
7805     len = asc_prt_line(cp, leftlen, "\n");
7806     ASC_PRT_NEXT();
7807
7808     len = asc_prt_line(cp, leftlen,
7809 " Start Motor:         ");
7810     ASC_PRT_NEXT();
7811     for (i = 0; i <= ASC_MAX_TID; i++) {
7812         len = asc_prt_line(cp, leftlen, " %c",
7813             (ep->start_motor & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7814         ASC_PRT_NEXT();
7815     }
7816     len = asc_prt_line(cp, leftlen, "\n");
7817     ASC_PRT_NEXT();
7818
7819     len = asc_prt_line(cp, leftlen,
7820 " Synchronous Transfer:");
7821     ASC_PRT_NEXT();
7822     for (i = 0; i <= ASC_MAX_TID; i++) {
7823         len = asc_prt_line(cp, leftlen, " %c",
7824             (ep->init_sdtr & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
7825         ASC_PRT_NEXT();
7826     }
7827     len = asc_prt_line(cp, leftlen, "\n");
7828     ASC_PRT_NEXT();
7829
7830 #ifdef CONFIG_ISA
7831     if (asc_dvc_varp->bus_type & ASC_IS_ISA) {
7832         len = asc_prt_line(cp, leftlen,
7833 " Host ISA DMA speed:   %d MB/S\n",
7834             isa_dma_speed[ASC_EEP_GET_DMA_SPD(ep)]);
7835         ASC_PRT_NEXT();
7836     }
7837 #endif /* CONFIG_ISA */
7838
7839      return totlen;
7840 }
7841
7842 /*
7843  * asc_prt_adv_board_eeprom()
7844  *
7845  * Print board EEPROM configuration.
7846  *
7847  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
7848  * cf. asc_prt_line().
7849  *
7850  * Return the number of characters copied into 'cp'. No more than
7851  * 'cplen' characters will be copied to 'cp'.
7852  */
7853 STATIC int
7854 asc_prt_adv_board_eeprom(struct Scsi_Host *shp, char *cp, int cplen)
7855 {
7856     asc_board_t                 *boardp;
7857     ADV_DVC_VAR                 *adv_dvc_varp;
7858     int                         leftlen;
7859     int                         totlen;
7860     int                         len;
7861     int                         i;
7862     char                        *termstr;
7863     uchar                       serialstr[13];
7864     ADVEEP_3550_CONFIG          *ep_3550 = NULL;
7865     ADVEEP_38C0800_CONFIG       *ep_38C0800 = NULL;
7866     ADVEEP_38C1600_CONFIG       *ep_38C1600 = NULL;
7867     ushort                      word;
7868     ushort                      *wordp;
7869     ushort                      sdtr_speed = 0;
7870
7871     boardp = ASC_BOARDP(shp);
7872     adv_dvc_varp = &boardp->dvc_var.adv_dvc_var;
7873     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7874     {
7875         ep_3550 = &boardp->eep_config.adv_3550_eep;
7876     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7877     {
7878         ep_38C0800 = &boardp->eep_config.adv_38C0800_eep;
7879     } else
7880     {
7881         ep_38C1600 = &boardp->eep_config.adv_38C1600_eep;
7882     }
7883
7884     leftlen = cplen;
7885     totlen = len = 0;
7886
7887     len = asc_prt_line(cp, leftlen,
7888 "\nEEPROM Settings for AdvanSys SCSI Host %d:\n", shp->host_no);
7889     ASC_PRT_NEXT();
7890
7891     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7892     {
7893         wordp = &ep_3550->serial_number_word1;
7894     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7895     {
7896         wordp = &ep_38C0800->serial_number_word1;
7897     } else
7898     {
7899         wordp = &ep_38C1600->serial_number_word1;
7900     }
7901
7902     if (asc_get_eeprom_string(wordp, serialstr) == ASC_TRUE) {
7903         len = asc_prt_line(cp, leftlen, " Serial Number: %s\n", serialstr);
7904         ASC_PRT_NEXT();
7905     } else {
7906         len = asc_prt_line(cp, leftlen,
7907             " Serial Number Signature Not Present.\n");
7908         ASC_PRT_NEXT();
7909     }
7910
7911     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7912     {
7913         len = asc_prt_line(cp, leftlen,
7914 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7915             ep_3550->adapter_scsi_id, ep_3550->max_host_qng,
7916             ep_3550->max_dvc_qng);
7917         ASC_PRT_NEXT();
7918     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7919     {
7920         len = asc_prt_line(cp, leftlen,
7921 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7922             ep_38C0800->adapter_scsi_id, ep_38C0800->max_host_qng,
7923             ep_38C0800->max_dvc_qng);
7924         ASC_PRT_NEXT();
7925     } else
7926     {
7927         len = asc_prt_line(cp, leftlen,
7928 " Host SCSI ID: %u, Host Queue Size: %u, Device Queue Size: %u\n",
7929             ep_38C1600->adapter_scsi_id, ep_38C1600->max_host_qng,
7930             ep_38C1600->max_dvc_qng);
7931         ASC_PRT_NEXT();
7932     }
7933     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7934     {
7935         word = ep_3550->termination;
7936     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7937     {
7938         word = ep_38C0800->termination_lvd;
7939     } else
7940     {
7941         word = ep_38C1600->termination_lvd;
7942     }
7943     switch (word) {
7944         case 1:
7945             termstr = "Low Off/High Off";
7946             break;
7947         case 2:
7948             termstr = "Low Off/High On";
7949             break;
7950         case 3:
7951             termstr = "Low On/High On";
7952             break;
7953         default:
7954         case 0:
7955             termstr = "Automatic";
7956             break;
7957     }
7958
7959     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7960     {
7961         len = asc_prt_line(cp, leftlen,
7962 " termination: %u (%s), bios_ctrl: 0x%x\n",
7963             ep_3550->termination, termstr, ep_3550->bios_ctrl);
7964         ASC_PRT_NEXT();
7965     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7966     {
7967         len = asc_prt_line(cp, leftlen,
7968 " termination: %u (%s), bios_ctrl: 0x%x\n",
7969             ep_38C0800->termination_lvd, termstr, ep_38C0800->bios_ctrl);
7970         ASC_PRT_NEXT();
7971     } else
7972     {
7973         len = asc_prt_line(cp, leftlen,
7974 " termination: %u (%s), bios_ctrl: 0x%x\n",
7975             ep_38C1600->termination_lvd, termstr, ep_38C1600->bios_ctrl);
7976         ASC_PRT_NEXT();
7977     }
7978
7979     len = asc_prt_line(cp, leftlen,
7980 " Target ID:           ");
7981     ASC_PRT_NEXT();
7982     for (i = 0; i <= ADV_MAX_TID; i++) {
7983         len = asc_prt_line(cp, leftlen, " %X", i);
7984         ASC_PRT_NEXT();
7985     }
7986     len = asc_prt_line(cp, leftlen, "\n");
7987     ASC_PRT_NEXT();
7988
7989     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
7990     {
7991         word = ep_3550->disc_enable;
7992     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
7993     {
7994         word = ep_38C0800->disc_enable;
7995     } else
7996     {
7997         word = ep_38C1600->disc_enable;
7998     }
7999     len = asc_prt_line(cp, leftlen,
8000 " Disconnects:         ");
8001     ASC_PRT_NEXT();
8002     for (i = 0; i <= ADV_MAX_TID; i++) {
8003         len = asc_prt_line(cp, leftlen, " %c",
8004             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8005         ASC_PRT_NEXT();
8006     }
8007     len = asc_prt_line(cp, leftlen, "\n");
8008     ASC_PRT_NEXT();
8009
8010     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8011     {
8012         word = ep_3550->tagqng_able;
8013     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8014     {
8015         word = ep_38C0800->tagqng_able;
8016     } else
8017     {
8018         word = ep_38C1600->tagqng_able;
8019     }
8020     len = asc_prt_line(cp, leftlen,
8021 " Command Queuing:     ");
8022     ASC_PRT_NEXT();
8023     for (i = 0; i <= ADV_MAX_TID; i++) {
8024         len = asc_prt_line(cp, leftlen, " %c",
8025             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8026         ASC_PRT_NEXT();
8027     }
8028     len = asc_prt_line(cp, leftlen, "\n");
8029     ASC_PRT_NEXT();
8030
8031     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8032     {
8033         word = ep_3550->start_motor;
8034     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8035     {
8036         word = ep_38C0800->start_motor;
8037     } else
8038     {
8039         word = ep_38C1600->start_motor;
8040     }
8041     len = asc_prt_line(cp, leftlen,
8042 " Start Motor:         ");
8043     ASC_PRT_NEXT();
8044     for (i = 0; i <= ADV_MAX_TID; i++) {
8045         len = asc_prt_line(cp, leftlen, " %c",
8046             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8047         ASC_PRT_NEXT();
8048     }
8049     len = asc_prt_line(cp, leftlen, "\n");
8050     ASC_PRT_NEXT();
8051
8052     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8053     {
8054         len = asc_prt_line(cp, leftlen,
8055 " Synchronous Transfer:");
8056         ASC_PRT_NEXT();
8057         for (i = 0; i <= ADV_MAX_TID; i++) {
8058             len = asc_prt_line(cp, leftlen, " %c",
8059                 (ep_3550->sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8060             ASC_PRT_NEXT();
8061         }
8062         len = asc_prt_line(cp, leftlen, "\n");
8063         ASC_PRT_NEXT();
8064     }
8065
8066     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8067     {
8068         len = asc_prt_line(cp, leftlen,
8069 " Ultra Transfer:      ");
8070     ASC_PRT_NEXT();
8071         for (i = 0; i <= ADV_MAX_TID; i++) {
8072             len = asc_prt_line(cp, leftlen, " %c",
8073                 (ep_3550->ultra_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8074             ASC_PRT_NEXT();
8075         }
8076         len = asc_prt_line(cp, leftlen, "\n");
8077         ASC_PRT_NEXT();
8078     }
8079
8080     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC3550)
8081     {
8082         word = ep_3550->wdtr_able;
8083     } else if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800)
8084     {
8085         word = ep_38C0800->wdtr_able;
8086     } else
8087     {
8088         word = ep_38C1600->wdtr_able;
8089     }
8090     len = asc_prt_line(cp, leftlen,
8091 " Wide Transfer:       ");
8092     ASC_PRT_NEXT();
8093     for (i = 0; i <= ADV_MAX_TID; i++) {
8094         len = asc_prt_line(cp, leftlen, " %c",
8095             (word & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8096         ASC_PRT_NEXT();
8097     }
8098     len = asc_prt_line(cp, leftlen, "\n");
8099     ASC_PRT_NEXT();
8100
8101     if (adv_dvc_varp->chip_type == ADV_CHIP_ASC38C0800 ||
8102         adv_dvc_varp->chip_type == ADV_CHIP_ASC38C1600)
8103     {
8104         len = asc_prt_line(cp, leftlen,
8105 " Synchronous Transfer Speed (Mhz):\n  ");
8106         ASC_PRT_NEXT();
8107         for (i = 0; i <= ADV_MAX_TID; i++) {
8108             char *speed_str;
8109
8110             if (i == 0)
8111             {
8112                 sdtr_speed = adv_dvc_varp->sdtr_speed1;
8113             } else if (i == 4)
8114             {
8115                 sdtr_speed = adv_dvc_varp->sdtr_speed2;
8116             } else if (i == 8)
8117             {
8118                 sdtr_speed = adv_dvc_varp->sdtr_speed3;
8119             } else if (i == 12)
8120             {
8121                 sdtr_speed = adv_dvc_varp->sdtr_speed4;
8122             }
8123             switch (sdtr_speed & ADV_MAX_TID)
8124             {
8125                 case 0:  speed_str = "Off"; break;
8126                 case 1:  speed_str = "  5"; break;
8127                 case 2:  speed_str = " 10"; break;
8128                 case 3:  speed_str = " 20"; break;
8129                 case 4:  speed_str = " 40"; break;
8130                 case 5:  speed_str = " 80"; break;
8131                 default: speed_str = "Unk"; break;
8132             }
8133             len = asc_prt_line(cp, leftlen, "%X:%s ", i, speed_str);
8134             ASC_PRT_NEXT();
8135             if (i == 7)
8136             {
8137                 len = asc_prt_line(cp, leftlen, "\n  ");
8138                 ASC_PRT_NEXT();
8139             }
8140             sdtr_speed >>= 4;
8141         }
8142         len = asc_prt_line(cp, leftlen, "\n");
8143         ASC_PRT_NEXT();
8144     }
8145
8146     return totlen;
8147 }
8148
8149 /*
8150  * asc_prt_driver_conf()
8151  *
8152  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8153  * cf. asc_prt_line().
8154  *
8155  * Return the number of characters copied into 'cp'. No more than
8156  * 'cplen' characters will be copied to 'cp'.
8157  */
8158 STATIC int
8159 asc_prt_driver_conf(struct Scsi_Host *shp, char *cp, int cplen)
8160 {
8161     asc_board_t            *boardp;
8162     int                    leftlen;
8163     int                    totlen;
8164     int                    len;
8165     int                    chip_scsi_id;
8166
8167     boardp = ASC_BOARDP(shp);
8168
8169     leftlen = cplen;
8170     totlen = len = 0;
8171
8172     len = asc_prt_line(cp, leftlen,
8173 "\nLinux Driver Configuration and Information for AdvanSys SCSI Host %d:\n",
8174         shp->host_no);
8175     ASC_PRT_NEXT();
8176
8177     len = asc_prt_line(cp, leftlen,
8178 " host_busy %u, last_reset %u, max_id %u, max_lun %u, max_channel %u\n",
8179         shp->host_busy, shp->last_reset, shp->max_id, shp->max_lun,
8180         shp->max_channel);
8181     ASC_PRT_NEXT();
8182
8183     len = asc_prt_line(cp, leftlen,
8184 " unique_id %d, can_queue %d, this_id %d, sg_tablesize %u, cmd_per_lun %u\n",
8185         shp->unique_id, shp->can_queue, shp->this_id, shp->sg_tablesize,
8186         shp->cmd_per_lun);
8187     ASC_PRT_NEXT();
8188
8189     len = asc_prt_line(cp, leftlen,
8190 " unchecked_isa_dma %d, use_clustering %d\n",
8191         shp->unchecked_isa_dma, shp->use_clustering);
8192     ASC_PRT_NEXT();
8193
8194     len = asc_prt_line(cp, leftlen,
8195 " flags 0x%x, last_reset 0x%x, jiffies 0x%x, asc_n_io_port 0x%x\n",
8196         boardp->flags, boardp->last_reset, jiffies, boardp->asc_n_io_port);
8197     ASC_PRT_NEXT();
8198
8199      /* 'shp->n_io_port' may be truncated because it is only one byte. */
8200     len = asc_prt_line(cp, leftlen,
8201 " io_port 0x%x, n_io_port 0x%x\n",
8202         shp->io_port, shp->n_io_port);
8203     ASC_PRT_NEXT();
8204
8205     if (ASC_NARROW_BOARD(boardp)) {
8206         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
8207     } else {
8208         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
8209     }
8210
8211     return totlen;
8212 }
8213
8214 /*
8215  * asc_prt_asc_board_info()
8216  *
8217  * Print dynamic board configuration information.
8218  *
8219  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8220  * cf. asc_prt_line().
8221  *
8222  * Return the number of characters copied into 'cp'. No more than
8223  * 'cplen' characters will be copied to 'cp'.
8224  */
8225 STATIC int
8226 asc_prt_asc_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8227 {
8228     asc_board_t            *boardp;
8229     int                    chip_scsi_id;
8230     int                    leftlen;
8231     int                    totlen;
8232     int                    len;
8233     ASC_DVC_VAR            *v;
8234     ASC_DVC_CFG            *c;
8235     int                    i;
8236     int                    renegotiate = 0;
8237
8238     boardp = ASC_BOARDP(shp);
8239     v = &boardp->dvc_var.asc_dvc_var;
8240     c = &boardp->dvc_cfg.asc_dvc_cfg;
8241     chip_scsi_id = c->chip_scsi_id;
8242
8243     leftlen = cplen;
8244     totlen = len = 0;
8245
8246     len = asc_prt_line(cp, leftlen,
8247 "\nAsc Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8248     shp->host_no);
8249     ASC_PRT_NEXT();
8250
8251     len = asc_prt_line(cp, leftlen,
8252 " chip_version %u, lib_version 0x%x, lib_serial_no %u, mcode_date 0x%x\n",
8253         c->chip_version, c->lib_version, c->lib_serial_no, c->mcode_date);
8254     ASC_PRT_NEXT();
8255
8256     len = asc_prt_line(cp, leftlen,
8257 " mcode_version 0x%x, err_code %u\n",
8258          c->mcode_version, v->err_code);
8259     ASC_PRT_NEXT();
8260
8261     /* Current number of commands waiting for the host. */
8262     len = asc_prt_line(cp, leftlen,
8263 " Total Command Pending: %d\n", v->cur_total_qng);
8264     ASC_PRT_NEXT();
8265
8266     len = asc_prt_line(cp, leftlen,
8267 " Command Queuing:");
8268     ASC_PRT_NEXT();
8269     for (i = 0; i <= ASC_MAX_TID; i++) {
8270         if ((chip_scsi_id == i) ||
8271             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8272             continue;
8273         }
8274         len = asc_prt_line(cp, leftlen, " %X:%c",
8275             i, (v->use_tagged_qng & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8276         ASC_PRT_NEXT();
8277     }
8278     len = asc_prt_line(cp, leftlen, "\n");
8279     ASC_PRT_NEXT();
8280
8281     /* Current number of commands waiting for a device. */
8282     len = asc_prt_line(cp, leftlen,
8283 " Command Queue Pending:");
8284     ASC_PRT_NEXT();
8285     for (i = 0; i <= ASC_MAX_TID; i++) {
8286         if ((chip_scsi_id == i) ||
8287             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8288             continue;
8289         }
8290         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->cur_dvc_qng[i]);
8291         ASC_PRT_NEXT();
8292     }
8293     len = asc_prt_line(cp, leftlen, "\n");
8294     ASC_PRT_NEXT();
8295
8296     /* Current limit on number of commands that can be sent to a device. */
8297     len = asc_prt_line(cp, leftlen,
8298 " Command Queue Limit:");
8299     ASC_PRT_NEXT();
8300     for (i = 0; i <= ASC_MAX_TID; i++) {
8301         if ((chip_scsi_id == i) ||
8302             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8303             continue;
8304         }
8305         len = asc_prt_line(cp, leftlen, " %X:%u", i, v->max_dvc_qng[i]);
8306         ASC_PRT_NEXT();
8307     }
8308     len = asc_prt_line(cp, leftlen, "\n");
8309     ASC_PRT_NEXT();
8310
8311     /* Indicate whether the device has returned queue full status. */
8312     len = asc_prt_line(cp, leftlen,
8313 " Command Queue Full:");
8314     ASC_PRT_NEXT();
8315     for (i = 0; i <= ASC_MAX_TID; i++) {
8316         if ((chip_scsi_id == i) ||
8317             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8318             continue;
8319         }
8320         if (boardp->queue_full & ADV_TID_TO_TIDMASK(i)) {
8321             len = asc_prt_line(cp, leftlen, " %X:Y-%d",
8322                 i, boardp->queue_full_cnt[i]);
8323         } else {
8324             len = asc_prt_line(cp, leftlen, " %X:N", i);
8325         }
8326         ASC_PRT_NEXT();
8327     }
8328     len = asc_prt_line(cp, leftlen, "\n");
8329     ASC_PRT_NEXT();
8330
8331     len = asc_prt_line(cp, leftlen,
8332 " Synchronous Transfer:");
8333     ASC_PRT_NEXT();
8334     for (i = 0; i <= ASC_MAX_TID; i++) {
8335         if ((chip_scsi_id == i) ||
8336             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8337             continue;
8338         }
8339         len = asc_prt_line(cp, leftlen, " %X:%c",
8340             i, (v->sdtr_done & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8341         ASC_PRT_NEXT();
8342     }
8343     len = asc_prt_line(cp, leftlen, "\n");
8344     ASC_PRT_NEXT();
8345
8346     for (i = 0; i <= ASC_MAX_TID; i++) {
8347         uchar syn_period_ix;
8348
8349         if ((chip_scsi_id == i) ||
8350             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8351             ((v->init_sdtr & ADV_TID_TO_TIDMASK(i)) == 0)) {
8352             continue;
8353         }
8354
8355         len = asc_prt_line(cp, leftlen, "  %X:", i);
8356         ASC_PRT_NEXT();
8357
8358         if ((boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET) == 0)
8359         {
8360             len = asc_prt_line(cp, leftlen, " Asynchronous");
8361             ASC_PRT_NEXT();
8362         } else
8363         {
8364             syn_period_ix =
8365                 (boardp->sdtr_data[i] >> 4) & (v->max_sdtr_index - 1);
8366
8367             len = asc_prt_line(cp, leftlen,
8368                 " Transfer Period Factor: %d (%d.%d Mhz),",
8369                 v->sdtr_period_tbl[syn_period_ix],
8370                 250 / v->sdtr_period_tbl[syn_period_ix],
8371                 ASC_TENTHS(250, v->sdtr_period_tbl[syn_period_ix]));
8372             ASC_PRT_NEXT();
8373
8374             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8375                 boardp->sdtr_data[i] & ASC_SYN_MAX_OFFSET);
8376             ASC_PRT_NEXT();
8377         }
8378
8379         if ((v->sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8380             len = asc_prt_line(cp, leftlen, "*\n");
8381             renegotiate = 1;
8382         } else
8383         {
8384             len = asc_prt_line(cp, leftlen, "\n");
8385         }
8386         ASC_PRT_NEXT();
8387     }
8388
8389     if (renegotiate)
8390     {
8391         len = asc_prt_line(cp, leftlen,
8392             " * = Re-negotiation pending before next command.\n");
8393         ASC_PRT_NEXT();
8394     }
8395
8396     return totlen;
8397 }
8398
8399 /*
8400  * asc_prt_adv_board_info()
8401  *
8402  * Print dynamic board configuration information.
8403  *
8404  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8405  * cf. asc_prt_line().
8406  *
8407  * Return the number of characters copied into 'cp'. No more than
8408  * 'cplen' characters will be copied to 'cp'.
8409  */
8410 STATIC int
8411 asc_prt_adv_board_info(struct Scsi_Host *shp, char *cp, int cplen)
8412 {
8413     asc_board_t            *boardp;
8414     int                    leftlen;
8415     int                    totlen;
8416     int                    len;
8417     int                    i;
8418     ADV_DVC_VAR            *v;
8419     ADV_DVC_CFG            *c;
8420     AdvPortAddr            iop_base;
8421     ushort                 chip_scsi_id;
8422     ushort                 lramword;
8423     uchar                  lrambyte;
8424     ushort                 tagqng_able;
8425     ushort                 sdtr_able, wdtr_able;
8426     ushort                 wdtr_done, sdtr_done;
8427     ushort                 period = 0;
8428     int                    renegotiate = 0;
8429
8430     boardp = ASC_BOARDP(shp);
8431     v = &boardp->dvc_var.adv_dvc_var;
8432     c = &boardp->dvc_cfg.adv_dvc_cfg;
8433     iop_base = v->iop_base;
8434     chip_scsi_id = v->chip_scsi_id;
8435
8436     leftlen = cplen;
8437     totlen = len = 0;
8438
8439     len = asc_prt_line(cp, leftlen,
8440 "\nAdv Library Configuration and Statistics for AdvanSys SCSI Host %d:\n",
8441     shp->host_no);
8442     ASC_PRT_NEXT();
8443
8444     len = asc_prt_line(cp, leftlen,
8445 " iop_base 0x%lx, cable_detect: %X, err_code %u\n",
8446          v->iop_base,
8447          AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1) & CABLE_DETECT,
8448          v->err_code);
8449     ASC_PRT_NEXT();
8450
8451     len = asc_prt_line(cp, leftlen,
8452 " chip_version %u, lib_version 0x%x, mcode_date 0x%x, mcode_version 0x%x\n",
8453         c->chip_version, c->lib_version, c->mcode_date, c->mcode_version);
8454     ASC_PRT_NEXT();
8455
8456     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
8457     len = asc_prt_line(cp, leftlen,
8458 " Queuing Enabled:");
8459     ASC_PRT_NEXT();
8460     for (i = 0; i <= ADV_MAX_TID; i++) {
8461         if ((chip_scsi_id == i) ||
8462             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8463             continue;
8464         }
8465
8466         len = asc_prt_line(cp, leftlen, " %X:%c",
8467             i, (tagqng_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8468         ASC_PRT_NEXT();
8469     }
8470     len = asc_prt_line(cp, leftlen, "\n");
8471     ASC_PRT_NEXT();
8472
8473     len = asc_prt_line(cp, leftlen,
8474 " Queue Limit:");
8475     ASC_PRT_NEXT();
8476     for (i = 0; i <= ADV_MAX_TID; i++) {
8477         if ((chip_scsi_id == i) ||
8478             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8479             continue;
8480         }
8481
8482         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + i, lrambyte);
8483
8484         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8485         ASC_PRT_NEXT();
8486     }
8487     len = asc_prt_line(cp, leftlen, "\n");
8488     ASC_PRT_NEXT();
8489
8490     len = asc_prt_line(cp, leftlen,
8491 " Command Pending:");
8492     ASC_PRT_NEXT();
8493     for (i = 0; i <= ADV_MAX_TID; i++) {
8494         if ((chip_scsi_id == i) ||
8495             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8496             continue;
8497         }
8498
8499         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_QUEUED_CMD + i, lrambyte);
8500
8501         len = asc_prt_line(cp, leftlen, " %X:%d", i, lrambyte);
8502         ASC_PRT_NEXT();
8503     }
8504     len = asc_prt_line(cp, leftlen, "\n");
8505     ASC_PRT_NEXT();
8506
8507     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
8508     len = asc_prt_line(cp, leftlen,
8509 " Wide Enabled:");
8510     ASC_PRT_NEXT();
8511     for (i = 0; i <= ADV_MAX_TID; i++) {
8512         if ((chip_scsi_id == i) ||
8513             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8514             continue;
8515         }
8516
8517         len = asc_prt_line(cp, leftlen, " %X:%c",
8518             i, (wdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8519         ASC_PRT_NEXT();
8520     }
8521     len = asc_prt_line(cp, leftlen, "\n");
8522     ASC_PRT_NEXT();
8523
8524     AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, wdtr_done);
8525     len = asc_prt_line(cp, leftlen,
8526 " Transfer Bit Width:");
8527     ASC_PRT_NEXT();
8528     for (i = 0; i <= ADV_MAX_TID; i++) {
8529         if ((chip_scsi_id == i) ||
8530             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8531             continue;
8532         }
8533
8534         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8535             lramword);
8536
8537         len = asc_prt_line(cp, leftlen, " %X:%d",
8538             i, (lramword & 0x8000) ? 16 : 8);
8539         ASC_PRT_NEXT();
8540
8541         if ((wdtr_able & ADV_TID_TO_TIDMASK(i)) &&
8542             (wdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8543             len = asc_prt_line(cp, leftlen, "*");
8544             ASC_PRT_NEXT();
8545             renegotiate = 1;
8546         }
8547     }
8548     len = asc_prt_line(cp, leftlen, "\n");
8549     ASC_PRT_NEXT();
8550
8551     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
8552     len = asc_prt_line(cp, leftlen,
8553 " Synchronous Enabled:");
8554     ASC_PRT_NEXT();
8555     for (i = 0; i <= ADV_MAX_TID; i++) {
8556         if ((chip_scsi_id == i) ||
8557             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0)) {
8558             continue;
8559         }
8560
8561         len = asc_prt_line(cp, leftlen, " %X:%c",
8562             i, (sdtr_able & ADV_TID_TO_TIDMASK(i)) ? 'Y' : 'N');
8563         ASC_PRT_NEXT();
8564     }
8565     len = asc_prt_line(cp, leftlen, "\n");
8566     ASC_PRT_NEXT();
8567
8568     AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, sdtr_done);
8569     for (i = 0; i <= ADV_MAX_TID; i++) {
8570
8571         AdvReadWordLram(iop_base, ASC_MC_DEVICE_HSHK_CFG_TABLE + (2 * i),
8572             lramword);
8573         lramword &= ~0x8000;
8574
8575         if ((chip_scsi_id == i) ||
8576             ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(i)) == 0) ||
8577             ((sdtr_able & ADV_TID_TO_TIDMASK(i)) == 0)) {
8578             continue;
8579         }
8580
8581         len = asc_prt_line(cp, leftlen, "  %X:", i);
8582         ASC_PRT_NEXT();
8583
8584         if ((lramword & 0x1F) == 0) /* Check for REQ/ACK Offset 0. */
8585         {
8586             len = asc_prt_line(cp, leftlen, " Asynchronous");
8587             ASC_PRT_NEXT();
8588         } else
8589         {
8590             len = asc_prt_line(cp, leftlen, " Transfer Period Factor: ");
8591             ASC_PRT_NEXT();
8592
8593             if ((lramword & 0x1F00) == 0x1100) /* 80 Mhz */
8594             {
8595                 len = asc_prt_line(cp, leftlen, "9 (80.0 Mhz),");
8596                 ASC_PRT_NEXT();
8597             } else if ((lramword & 0x1F00) == 0x1000) /* 40 Mhz */
8598             {
8599                 len = asc_prt_line(cp, leftlen, "10 (40.0 Mhz),");
8600                 ASC_PRT_NEXT();
8601             } else /* 20 Mhz or below. */
8602             {
8603                 period = (((lramword >> 8) * 25) + 50)/4;
8604
8605                 if (period == 0) /* Should never happen. */
8606                 {
8607                     len = asc_prt_line(cp, leftlen, "%d (? Mhz), ");
8608                     ASC_PRT_NEXT();
8609                 } else
8610                 {
8611                     len = asc_prt_line(cp, leftlen,
8612                         "%d (%d.%d Mhz),",
8613                         period, 250/period, ASC_TENTHS(250, period));
8614                     ASC_PRT_NEXT();
8615                 }
8616             }
8617
8618             len = asc_prt_line(cp, leftlen, " REQ/ACK Offset: %d",
8619                 lramword & 0x1F);
8620             ASC_PRT_NEXT();
8621         }
8622
8623         if ((sdtr_done & ADV_TID_TO_TIDMASK(i)) == 0) {
8624             len = asc_prt_line(cp, leftlen, "*\n");
8625             renegotiate = 1;
8626         } else
8627         {
8628             len = asc_prt_line(cp, leftlen, "\n");
8629         }
8630         ASC_PRT_NEXT();
8631     }
8632
8633     if (renegotiate)
8634     {
8635         len = asc_prt_line(cp, leftlen,
8636             " * = Re-negotiation pending before next command.\n");
8637         ASC_PRT_NEXT();
8638     }
8639
8640     return totlen;
8641 }
8642
8643 /*
8644  * asc_proc_copy()
8645  *
8646  * Copy proc information to a read buffer taking into account the current
8647  * read offset in the file and the remaining space in the read buffer.
8648  */
8649 STATIC int
8650 asc_proc_copy(off_t advoffset, off_t offset, char *curbuf, int leftlen,
8651               char *cp, int cplen)
8652 {
8653     int cnt = 0;
8654
8655     ASC_DBG3(2, "asc_proc_copy: offset %d, advoffset %d, cplen %d\n",
8656             (unsigned) offset, (unsigned) advoffset, cplen);
8657     if (offset <= advoffset) {
8658         /* Read offset below current offset, copy everything. */
8659         cnt = min(cplen, leftlen);
8660         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8661                 (ulong) curbuf, (ulong) cp, cnt);
8662         memcpy(curbuf, cp, cnt);
8663     } else if (offset < advoffset + cplen) {
8664         /* Read offset within current range, partial copy. */
8665         cnt = (advoffset + cplen) - offset;
8666         cp = (cp + cplen) - cnt;
8667         cnt = min(cnt, leftlen);
8668         ASC_DBG3(2, "asc_proc_copy: curbuf 0x%lx, cp 0x%lx, cnt %d\n",
8669                 (ulong) curbuf, (ulong) cp, cnt);
8670         memcpy(curbuf, cp, cnt);
8671     }
8672     return cnt;
8673 }
8674
8675 /*
8676  * asc_prt_line()
8677  *
8678  * If 'cp' is NULL print to the console, otherwise print to a buffer.
8679  *
8680  * Return 0 if printing to the console, otherwise return the number of
8681  * bytes written to the buffer.
8682  *
8683  * Note: If any single line is greater than ASC_PRTLINE_SIZE bytes the stack
8684  * will be corrupted. 's[]' is defined to be ASC_PRTLINE_SIZE bytes.
8685  */
8686 STATIC int
8687 asc_prt_line(char *buf, int buflen, char *fmt, ...)
8688 {
8689     va_list        args;
8690     int            ret;
8691     char           s[ASC_PRTLINE_SIZE];
8692
8693     va_start(args, fmt);
8694     ret = vsprintf(s, fmt, args);
8695     ASC_ASSERT(ret < ASC_PRTLINE_SIZE);
8696     if (buf == NULL) {
8697         (void) printk(s);
8698         ret = 0;
8699     } else {
8700         ret = min(buflen, ret);
8701         memcpy(buf, s, ret);
8702     }
8703     va_end(args);
8704     return ret;
8705 }
8706 #endif /* CONFIG_PROC_FS */
8707
8708
8709 /*
8710  * --- Functions Required by the Asc Library
8711  */
8712
8713 /*
8714  * Delay for 'n' milliseconds. Don't use the 'jiffies'
8715  * global variable which is incremented once every 5 ms
8716  * from a timer interrupt, because this function may be
8717  * called when interrupts are disabled.
8718  */
8719 STATIC void
8720 DvcSleepMilliSecond(ADV_DCNT n)
8721 {
8722     ASC_DBG1(4, "DvcSleepMilliSecond: %lu\n", (ulong) n);
8723     mdelay(n);
8724 }
8725
8726 /*
8727  * Currently and inline noop but leave as a placeholder.
8728  * Leave DvcEnterCritical() as a noop placeholder.
8729  */
8730 STATIC inline ulong
8731 DvcEnterCritical(void)
8732 {
8733     return 0;
8734 }
8735
8736 /*
8737  * Critical sections are all protected by the board spinlock.
8738  * Leave DvcLeaveCritical() as a noop placeholder.
8739  */
8740 STATIC inline void
8741 DvcLeaveCritical(ulong flags)
8742 {
8743     return;
8744 }
8745
8746 /*
8747  * void
8748  * DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8749  *
8750  * Calling/Exit State:
8751  *    none
8752  *
8753  * Description:
8754  *     Output an ASC_SCSI_Q structure to the chip
8755  */
8756 STATIC void
8757 DvcPutScsiQ(PortAddr iop_base, ushort s_addr, uchar *outbuf, int words)
8758 {
8759     int    i;
8760
8761     ASC_DBG_PRT_HEX(2, "DvcPutScsiQ", outbuf, 2 * words);
8762     AscSetChipLramAddr(iop_base, s_addr);
8763     for (i = 0; i < 2 * words; i += 2) {
8764         if (i == 4 || i == 20) {
8765             continue;
8766         }
8767         outpw(iop_base + IOP_RAM_DATA,
8768             ((ushort) outbuf[i + 1] << 8) | outbuf[i]);
8769     }
8770 }
8771
8772 /*
8773  * void
8774  * DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8775  *
8776  * Calling/Exit State:
8777  *    none
8778  *
8779  * Description:
8780  *     Input an ASC_QDONE_INFO structure from the chip
8781  */
8782 STATIC void
8783 DvcGetQinfo(PortAddr iop_base, ushort s_addr, uchar *inbuf, int words)
8784 {
8785     int    i;
8786     ushort word;
8787
8788     AscSetChipLramAddr(iop_base, s_addr);
8789     for (i = 0; i < 2 * words; i += 2) {
8790         if (i == 10) {
8791             continue;
8792         }
8793         word = inpw(iop_base + IOP_RAM_DATA);
8794         inbuf[i] = word & 0xff;
8795         inbuf[i + 1] = (word >> 8) & 0xff;
8796     }
8797     ASC_DBG_PRT_HEX(2, "DvcGetQinfo", inbuf, 2 * words);
8798 }
8799
8800 /*
8801  * Read a PCI configuration byte.
8802  */
8803 STATIC uchar __init
8804 DvcReadPCIConfigByte(
8805         ASC_DVC_VAR *asc_dvc,
8806         ushort offset)
8807 {
8808 #ifdef CONFIG_PCI
8809     uchar byte_data;
8810     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8811     return byte_data;
8812 #else /* !defined(CONFIG_PCI) */
8813     return 0;
8814 #endif /* !defined(CONFIG_PCI) */
8815 }
8816
8817 /*
8818  * Write a PCI configuration byte.
8819  */
8820 STATIC void __init
8821 DvcWritePCIConfigByte(
8822         ASC_DVC_VAR *asc_dvc,
8823         ushort offset,
8824         uchar  byte_data)
8825 {
8826 #ifdef CONFIG_PCI
8827     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8828 #endif /* CONFIG_PCI */
8829 }
8830
8831 /*
8832  * Return the BIOS address of the adapter at the specified
8833  * I/O port and with the specified bus type.
8834  */
8835 STATIC ushort __init
8836 AscGetChipBiosAddress(
8837         PortAddr iop_base,
8838         ushort bus_type)
8839 {
8840     ushort  cfg_lsw;
8841     ushort  bios_addr;
8842
8843     /*
8844      * The PCI BIOS is re-located by the motherboard BIOS. Because
8845      * of this the driver can not determine where a PCI BIOS is
8846      * loaded and executes.
8847      */
8848     if (bus_type & ASC_IS_PCI)
8849     {
8850         return(0);
8851     }
8852
8853 #ifdef CONFIG_ISA
8854     if((bus_type & ASC_IS_EISA) != 0)
8855     {
8856         cfg_lsw = AscGetEisaChipCfg(iop_base);
8857         cfg_lsw &= 0x000F;
8858         bios_addr = (ushort)(ASC_BIOS_MIN_ADDR  +
8859                                 (cfg_lsw * ASC_BIOS_BANK_SIZE));
8860         return(bios_addr);
8861     }/* if */
8862 #endif /* CONFIG_ISA */
8863
8864     cfg_lsw = AscGetChipCfgLsw(iop_base);
8865
8866     /*
8867     *  ISA PnP uses the top bit as the 32K BIOS flag
8868     */
8869     if (bus_type == ASC_IS_ISAPNP)
8870     {
8871         cfg_lsw &= 0x7FFF;
8872     }/* if */
8873
8874     bios_addr = (ushort)(((cfg_lsw >> 12) * ASC_BIOS_BANK_SIZE) +
8875             ASC_BIOS_MIN_ADDR);
8876     return(bios_addr);
8877 }
8878
8879
8880 /*
8881  * --- Functions Required by the Adv Library
8882  */
8883
8884 /*
8885  * DvcGetPhyAddr()
8886  *
8887  * Return the physical address of 'vaddr' and set '*lenp' to the
8888  * number of physically contiguous bytes that follow 'vaddr'.
8889  * 'flag' indicates the type of structure whose physical address
8890  * is being translated.
8891  *
8892  * Note: Because Linux currently doesn't page the kernel and all
8893  * kernel buffers are physically contiguous, leave '*lenp' unchanged.
8894  */
8895 ADV_PADDR
8896 DvcGetPhyAddr(ADV_DVC_VAR *asc_dvc, ADV_SCSI_REQ_Q *scsiq,
8897         uchar *vaddr, ADV_SDCNT *lenp, int flag)
8898 {
8899     ADV_PADDR           paddr;
8900
8901     paddr = virt_to_bus(vaddr);
8902
8903     ASC_DBG4(4,
8904         "DvcGetPhyAddr: vaddr 0x%lx, lenp 0x%lx *lenp %lu, paddr 0x%lx\n",
8905         (ulong) vaddr, (ulong) lenp, (ulong) *((ulong *) lenp), (ulong) paddr);
8906
8907     return paddr;
8908 }
8909
8910 /*
8911  * Read a PCI configuration byte.
8912  */
8913 STATIC uchar __init
8914 DvcAdvReadPCIConfigByte(
8915         ADV_DVC_VAR *asc_dvc,
8916         ushort offset)
8917 {
8918 #ifdef CONFIG_PCI
8919     uchar byte_data;
8920     pci_read_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, &byte_data);
8921     return byte_data;
8922 #else /* CONFIG_PCI */
8923     return 0;
8924 #endif /* CONFIG_PCI */
8925 }
8926
8927 /*
8928  * Write a PCI configuration byte.
8929  */
8930 STATIC void __init
8931 DvcAdvWritePCIConfigByte(
8932         ADV_DVC_VAR *asc_dvc,
8933         ushort offset,
8934         uchar  byte_data)
8935 {
8936 #ifdef CONFIG_PCI
8937     pci_write_config_byte(to_pci_dev(asc_dvc->cfg->dev), offset, byte_data);
8938 #else /* CONFIG_PCI */
8939     return 0;
8940 #endif /* CONFIG_PCI */
8941 }
8942
8943 /*
8944  * --- Tracing and Debugging Functions
8945  */
8946
8947 #ifdef ADVANSYS_STATS
8948 #ifdef CONFIG_PROC_FS
8949 /*
8950  * asc_prt_board_stats()
8951  *
8952  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
8953  * cf. asc_prt_line().
8954  *
8955  * Return the number of characters copied into 'cp'. No more than
8956  * 'cplen' characters will be copied to 'cp'.
8957  */
8958 STATIC int
8959 asc_prt_board_stats(struct Scsi_Host *shp, char *cp, int cplen)
8960 {
8961     int                    leftlen;
8962     int                    totlen;
8963     int                    len;
8964     struct asc_stats       *s;
8965     asc_board_t            *boardp;
8966
8967     leftlen = cplen;
8968     totlen = len = 0;
8969
8970     boardp = ASC_BOARDP(shp);
8971     s = &boardp->asc_stats;
8972
8973     len = asc_prt_line(cp, leftlen,
8974 "\nLinux Driver Statistics for AdvanSys SCSI Host %d:\n", shp->host_no);
8975     ASC_PRT_NEXT();
8976
8977     len = asc_prt_line(cp, leftlen,
8978 " queuecommand %lu, reset %lu, biosparam %lu, interrupt %lu\n",
8979         s->queuecommand, s->reset, s->biosparam, s->interrupt);
8980     ASC_PRT_NEXT();
8981
8982     len = asc_prt_line(cp, leftlen,
8983 " callback %lu, done %lu, build_error %lu, build_noreq %lu, build_nosg %lu\n",
8984         s->callback, s->done, s->build_error, s->adv_build_noreq,
8985         s->adv_build_nosg);
8986     ASC_PRT_NEXT();
8987
8988     len = asc_prt_line(cp, leftlen,
8989 " exe_noerror %lu, exe_busy %lu, exe_error %lu, exe_unknown %lu\n",
8990         s->exe_noerror, s->exe_busy, s->exe_error, s->exe_unknown);
8991     ASC_PRT_NEXT();
8992
8993     /*
8994      * Display data transfer statistics.
8995      */
8996     if (s->cont_cnt > 0) {
8997         len = asc_prt_line(cp, leftlen, " cont_cnt %lu, ", s->cont_cnt);
8998         ASC_PRT_NEXT();
8999
9000         len = asc_prt_line(cp, leftlen, "cont_xfer %lu.%01lu kb ",
9001                     s->cont_xfer/2,
9002                     ASC_TENTHS(s->cont_xfer, 2));
9003         ASC_PRT_NEXT();
9004
9005         /* Contiguous transfer average size */
9006         len = asc_prt_line(cp, leftlen, "avg_xfer %lu.%01lu kb\n",
9007                     (s->cont_xfer/2)/s->cont_cnt,
9008                     ASC_TENTHS((s->cont_xfer/2), s->cont_cnt));
9009         ASC_PRT_NEXT();
9010     }
9011
9012     if (s->sg_cnt > 0) {
9013
9014         len = asc_prt_line(cp, leftlen, " sg_cnt %lu, sg_elem %lu, ",
9015                     s->sg_cnt, s->sg_elem);
9016         ASC_PRT_NEXT();
9017
9018         len = asc_prt_line(cp, leftlen, "sg_xfer %lu.%01lu kb\n",
9019                     s->sg_xfer/2,
9020                     ASC_TENTHS(s->sg_xfer, 2));
9021         ASC_PRT_NEXT();
9022
9023         /* Scatter gather transfer statistics */
9024         len = asc_prt_line(cp, leftlen, " avg_num_elem %lu.%01lu, ",
9025                     s->sg_elem/s->sg_cnt,
9026                     ASC_TENTHS(s->sg_elem, s->sg_cnt));
9027         ASC_PRT_NEXT();
9028
9029         len = asc_prt_line(cp, leftlen, "avg_elem_size %lu.%01lu kb, ",
9030                     (s->sg_xfer/2)/s->sg_elem,
9031                     ASC_TENTHS((s->sg_xfer/2), s->sg_elem));
9032         ASC_PRT_NEXT();
9033
9034         len = asc_prt_line(cp, leftlen, "avg_xfer_size %lu.%01lu kb\n",
9035                     (s->sg_xfer/2)/s->sg_cnt,
9036                     ASC_TENTHS((s->sg_xfer/2), s->sg_cnt));
9037         ASC_PRT_NEXT();
9038     }
9039
9040     /*
9041      * Display request queuing statistics.
9042      */
9043     len = asc_prt_line(cp, leftlen,
9044 " Active and Waiting Request Queues (Time Unit: %d HZ):\n", HZ);
9045     ASC_PRT_NEXT();
9046
9047
9048      return totlen;
9049 }
9050
9051 /*
9052  * asc_prt_target_stats()
9053  *
9054  * Note: no single line should be greater than ASC_PRTLINE_SIZE,
9055  * cf. asc_prt_line().
9056  *
9057  * This is separated from asc_prt_board_stats because a full set
9058  * of targets will overflow ASC_PRTBUF_SIZE.
9059  *
9060  * Return the number of characters copied into 'cp'. No more than
9061  * 'cplen' characters will be copied to 'cp'.
9062  */
9063 STATIC int
9064 asc_prt_target_stats(struct Scsi_Host *shp, int tgt_id, char *cp, int cplen)
9065 {
9066     int                    leftlen;
9067     int                    totlen;
9068     int                    len;
9069     struct asc_stats       *s;
9070     ushort                 chip_scsi_id;
9071     asc_board_t            *boardp;
9072     asc_queue_t            *active;
9073     asc_queue_t            *waiting;
9074
9075     leftlen = cplen;
9076     totlen = len = 0;
9077
9078     boardp = ASC_BOARDP(shp);
9079     s = &boardp->asc_stats;
9080
9081     active = &ASC_BOARDP(shp)->active;
9082     waiting = &ASC_BOARDP(shp)->waiting;
9083
9084     if (ASC_NARROW_BOARD(boardp)) {
9085         chip_scsi_id = boardp->dvc_cfg.asc_dvc_cfg.chip_scsi_id;
9086     } else {
9087         chip_scsi_id = boardp->dvc_var.adv_dvc_var.chip_scsi_id;
9088     }
9089
9090     if ((chip_scsi_id == tgt_id) ||
9091         ((boardp->init_tidmask & ADV_TID_TO_TIDMASK(tgt_id)) == 0)) {
9092         return 0;
9093     }
9094
9095     do {
9096         if (active->q_tot_cnt[tgt_id] > 0 || waiting->q_tot_cnt[tgt_id] > 0) {
9097             len = asc_prt_line(cp, leftlen, " target %d\n", tgt_id);
9098             ASC_PRT_NEXT();
9099
9100             len = asc_prt_line(cp, leftlen,
9101 "   active: cnt [cur %d, max %d, tot %u], time [min %d, max %d, avg %lu.%01lu]\n",
9102                 active->q_cur_cnt[tgt_id], active->q_max_cnt[tgt_id],
9103                 active->q_tot_cnt[tgt_id],
9104                 active->q_min_tim[tgt_id], active->q_max_tim[tgt_id],
9105                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9106                 (active->q_tot_tim[tgt_id]/active->q_tot_cnt[tgt_id]),
9107                 (active->q_tot_cnt[tgt_id] == 0) ? 0 :
9108                 ASC_TENTHS(active->q_tot_tim[tgt_id],
9109                 active->q_tot_cnt[tgt_id]));
9110              ASC_PRT_NEXT();
9111
9112              len = asc_prt_line(cp, leftlen,
9113 "   waiting: cnt [cur %d, max %d, tot %u], time [min %u, max %u, avg %lu.%01lu]\n",
9114                 waiting->q_cur_cnt[tgt_id], waiting->q_max_cnt[tgt_id],
9115                 waiting->q_tot_cnt[tgt_id],
9116                 waiting->q_min_tim[tgt_id], waiting->q_max_tim[tgt_id],
9117                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9118                 (waiting->q_tot_tim[tgt_id]/waiting->q_tot_cnt[tgt_id]),
9119                 (waiting->q_tot_cnt[tgt_id] == 0) ? 0 :
9120                 ASC_TENTHS(waiting->q_tot_tim[tgt_id],
9121                 waiting->q_tot_cnt[tgt_id]));
9122              ASC_PRT_NEXT();
9123         }
9124     } while (0);
9125
9126      return totlen;
9127 }
9128 #endif /* CONFIG_PROC_FS */
9129 #endif /* ADVANSYS_STATS */
9130
9131 #ifdef ADVANSYS_DEBUG
9132 /*
9133  * asc_prt_scsi_host()
9134  */
9135 STATIC void
9136 asc_prt_scsi_host(struct Scsi_Host *s)
9137 {
9138     asc_board_t         *boardp;
9139
9140     boardp = ASC_BOARDP(s);
9141
9142     printk("Scsi_Host at addr 0x%lx\n", (ulong) s);
9143     printk(
9144 " host_busy %u, host_no %d, last_reset %d,\n",
9145         s->host_busy, s->host_no,
9146         (unsigned) s->last_reset);
9147
9148     printk(
9149 " base 0x%lx, io_port 0x%lx, n_io_port %u, irq 0x%x,\n",
9150         (ulong) s->base, (ulong) s->io_port, s->n_io_port, s->irq);
9151
9152     printk(
9153 " dma_channel %d, this_id %d, can_queue %d,\n",
9154         s->dma_channel, s->this_id, s->can_queue);
9155
9156     printk(
9157 " cmd_per_lun %d, sg_tablesize %d, unchecked_isa_dma %d\n",
9158         s->cmd_per_lun, s->sg_tablesize, s->unchecked_isa_dma);
9159
9160     if (ASC_NARROW_BOARD(boardp)) {
9161         asc_prt_asc_dvc_var(&ASC_BOARDP(s)->dvc_var.asc_dvc_var);
9162         asc_prt_asc_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.asc_dvc_cfg);
9163     } else {
9164         asc_prt_adv_dvc_var(&ASC_BOARDP(s)->dvc_var.adv_dvc_var);
9165         asc_prt_adv_dvc_cfg(&ASC_BOARDP(s)->dvc_cfg.adv_dvc_cfg);
9166     }
9167 }
9168
9169 /*
9170  * asc_prt_scsi_cmnd()
9171  */
9172 STATIC void
9173 asc_prt_scsi_cmnd(Scsi_Cmnd *s)
9174 {
9175     printk("Scsi_Cmnd at addr 0x%lx\n", (ulong) s);
9176
9177     printk(
9178 " host 0x%lx, device 0x%lx, target %u, lun %u, channel %u,\n",
9179         (ulong) s->device->host, (ulong) s->device, s->device->id, s->device->lun,
9180         s->device->channel);
9181
9182     asc_prt_hex(" CDB", s->cmnd, s->cmd_len);
9183
9184     printk (
9185 "sc_data_direction %u, resid %d\n",
9186         s->sc_data_direction, s->resid);
9187
9188     printk(
9189 " use_sg %u, sglist_len %u, abort_reason 0x%x\n",
9190         s->use_sg, s->sglist_len, s->abort_reason);
9191
9192     printk(
9193 " serial_number 0x%x, serial_number_at_timeout 0x%x, retries %d, allowed %d\n",
9194         (unsigned) s->serial_number, (unsigned) s->serial_number_at_timeout,
9195          s->retries, s->allowed);
9196
9197     printk(
9198 " timeout_per_command %d, timeout_total %d, timeout %d\n",
9199         s->timeout_per_command, s->timeout_total, s->timeout);
9200
9201     printk(
9202 " internal_timeout %u, flags %u\n",
9203         s->internal_timeout, s->flags);
9204
9205     printk(
9206 " scsi_done 0x%lx, done 0x%lx, host_scribble 0x%lx, result 0x%x\n",
9207         (ulong) s->scsi_done, (ulong) s->done,
9208         (ulong) s->host_scribble, s->result);
9209
9210     printk(
9211 " tag %u, pid %u\n",
9212         (unsigned) s->tag, (unsigned) s->pid);
9213 }
9214
9215 /*
9216  * asc_prt_asc_dvc_var()
9217  */
9218 STATIC void
9219 asc_prt_asc_dvc_var(ASC_DVC_VAR *h)
9220 {
9221     printk("ASC_DVC_VAR at addr 0x%lx\n", (ulong) h);
9222
9223     printk(
9224 " iop_base 0x%x, err_code 0x%x, dvc_cntl 0x%x, bug_fix_cntl %d,\n",
9225         h->iop_base, h->err_code, h->dvc_cntl, h->bug_fix_cntl);
9226
9227     printk(
9228 " bus_type %d, isr_callback 0x%lx, exe_callback 0x%lx, init_sdtr 0x%x,\n",
9229         h->bus_type, (ulong) h->isr_callback, (ulong) h->exe_callback,
9230         (unsigned) h->init_sdtr);
9231
9232     printk(
9233 " sdtr_done 0x%x, use_tagged_qng 0x%x, unit_not_ready 0x%x, chip_no 0x%x,\n",
9234         (unsigned) h->sdtr_done, (unsigned) h->use_tagged_qng,
9235         (unsigned) h->unit_not_ready, (unsigned) h->chip_no);
9236
9237     printk(
9238 " queue_full_or_busy 0x%x, start_motor 0x%x, scsi_reset_wait %u,\n",
9239         (unsigned) h->queue_full_or_busy, (unsigned) h->start_motor,
9240         (unsigned) h->scsi_reset_wait);
9241
9242     printk(
9243 " is_in_int %u, max_total_qng %u, cur_total_qng %u, in_critical_cnt %u,\n",
9244         (unsigned) h->is_in_int, (unsigned) h->max_total_qng,
9245         (unsigned) h->cur_total_qng, (unsigned) h->in_critical_cnt);
9246
9247     printk(
9248 " last_q_shortage %u, init_state 0x%x, no_scam 0x%x, pci_fix_asyn_xfer 0x%x,\n",
9249         (unsigned) h->last_q_shortage, (unsigned) h->init_state,
9250         (unsigned) h->no_scam, (unsigned) h->pci_fix_asyn_xfer);
9251
9252     printk(
9253 " cfg 0x%lx, irq_no 0x%x\n",
9254         (ulong) h->cfg, (unsigned) h->irq_no);
9255 }
9256
9257 /*
9258  * asc_prt_asc_dvc_cfg()
9259  */
9260 STATIC void
9261 asc_prt_asc_dvc_cfg(ASC_DVC_CFG *h)
9262 {
9263     printk("ASC_DVC_CFG at addr 0x%lx\n", (ulong) h);
9264
9265     printk(
9266 " can_tagged_qng 0x%x, cmd_qng_enabled 0x%x,\n",
9267             h->can_tagged_qng, h->cmd_qng_enabled);
9268     printk(
9269 " disc_enable 0x%x, sdtr_enable 0x%x,\n",
9270             h->disc_enable, h->sdtr_enable);
9271
9272     printk(
9273 " chip_scsi_id %d, isa_dma_speed %d, isa_dma_channel %d, chip_version %d,\n",
9274              h->chip_scsi_id, h->isa_dma_speed, h->isa_dma_channel,
9275              h->chip_version);
9276
9277     printk(
9278 " pci_device_id %d, lib_serial_no %u, lib_version %u, mcode_date 0x%x,\n",
9279            to_pci_dev(h->dev)->device, h->lib_serial_no, h->lib_version,
9280            h->mcode_date);
9281
9282     printk(
9283 " mcode_version %d, overrun_buf 0x%lx\n",
9284             h->mcode_version, (ulong) h->overrun_buf);
9285 }
9286
9287 /*
9288  * asc_prt_asc_scsi_q()
9289  */
9290 STATIC void
9291 asc_prt_asc_scsi_q(ASC_SCSI_Q *q)
9292 {
9293     ASC_SG_HEAD    *sgp;
9294     int i;
9295
9296     printk("ASC_SCSI_Q at addr 0x%lx\n", (ulong) q);
9297
9298     printk(
9299 " target_ix 0x%x, target_lun %u, srb_ptr 0x%lx, tag_code 0x%x,\n",
9300             q->q2.target_ix, q->q1.target_lun,
9301             (ulong) q->q2.srb_ptr, q->q2.tag_code);
9302
9303     printk(
9304 " data_addr 0x%lx, data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9305             (ulong) le32_to_cpu(q->q1.data_addr),
9306             (ulong) le32_to_cpu(q->q1.data_cnt),
9307             (ulong) le32_to_cpu(q->q1.sense_addr), q->q1.sense_len);
9308
9309     printk(
9310 " cdbptr 0x%lx, cdb_len %u, sg_head 0x%lx, sg_queue_cnt %u\n",
9311             (ulong) q->cdbptr, q->q2.cdb_len,
9312             (ulong) q->sg_head, q->q1.sg_queue_cnt);
9313
9314     if (q->sg_head) {
9315         sgp = q->sg_head;
9316         printk("ASC_SG_HEAD at addr 0x%lx\n", (ulong) sgp);
9317         printk(" entry_cnt %u, queue_cnt %u\n", sgp->entry_cnt, sgp->queue_cnt);
9318         for (i = 0; i < sgp->entry_cnt; i++) {
9319             printk(" [%u]: addr 0x%lx, bytes %lu\n",
9320                 i, (ulong) le32_to_cpu(sgp->sg_list[i].addr),
9321                 (ulong) le32_to_cpu(sgp->sg_list[i].bytes));
9322         }
9323
9324     }
9325 }
9326
9327 /*
9328  * asc_prt_asc_qdone_info()
9329  */
9330 STATIC void
9331 asc_prt_asc_qdone_info(ASC_QDONE_INFO *q)
9332 {
9333     printk("ASC_QDONE_INFO at addr 0x%lx\n", (ulong) q);
9334     printk(
9335 " srb_ptr 0x%lx, target_ix %u, cdb_len %u, tag_code %u,\n",
9336             (ulong) q->d2.srb_ptr, q->d2.target_ix, q->d2.cdb_len,
9337             q->d2.tag_code);
9338     printk(
9339 " done_stat 0x%x, host_stat 0x%x, scsi_stat 0x%x, scsi_msg 0x%x\n",
9340             q->d3.done_stat, q->d3.host_stat, q->d3.scsi_stat, q->d3.scsi_msg);
9341 }
9342
9343 /*
9344  * asc_prt_adv_dvc_var()
9345  *
9346  * Display an ADV_DVC_VAR structure.
9347  */
9348 STATIC void
9349 asc_prt_adv_dvc_var(ADV_DVC_VAR *h)
9350 {
9351     printk(" ADV_DVC_VAR at addr 0x%lx\n", (ulong) h);
9352
9353     printk(
9354 "  iop_base 0x%lx, err_code 0x%x, ultra_able 0x%x\n",
9355         (ulong) h->iop_base, h->err_code, (unsigned) h->ultra_able);
9356
9357     printk(
9358 "  isr_callback 0x%lx, sdtr_able 0x%x, wdtr_able 0x%x\n",
9359         (ulong) h->isr_callback, (unsigned) h->sdtr_able,
9360         (unsigned) h->wdtr_able);
9361
9362     printk(
9363 "  start_motor 0x%x, scsi_reset_wait 0x%x, irq_no 0x%x,\n",
9364         (unsigned) h->start_motor,
9365         (unsigned) h->scsi_reset_wait, (unsigned) h->irq_no);
9366
9367     printk(
9368 "  max_host_qng %u, max_dvc_qng %u, carr_freelist 0x%lxn\n",
9369         (unsigned) h->max_host_qng, (unsigned) h->max_dvc_qng,
9370         (ulong) h->carr_freelist);
9371
9372     printk(
9373 "  icq_sp 0x%lx, irq_sp 0x%lx\n",
9374         (ulong) h->icq_sp, (ulong) h->irq_sp);
9375
9376     printk(
9377 "  no_scam 0x%x, tagqng_able 0x%x\n",
9378         (unsigned) h->no_scam, (unsigned) h->tagqng_able);
9379
9380     printk(
9381 "  chip_scsi_id 0x%x, cfg 0x%lx\n",
9382         (unsigned) h->chip_scsi_id, (ulong) h->cfg);
9383 }
9384
9385 /*
9386  * asc_prt_adv_dvc_cfg()
9387  *
9388  * Display an ADV_DVC_CFG structure.
9389  */
9390 STATIC void
9391 asc_prt_adv_dvc_cfg(ADV_DVC_CFG *h)
9392 {
9393     printk(" ADV_DVC_CFG at addr 0x%lx\n", (ulong) h);
9394
9395     printk(
9396 "  disc_enable 0x%x, termination 0x%x\n",
9397         h->disc_enable, h->termination);
9398
9399     printk(
9400 "  chip_version 0x%x, mcode_date 0x%x\n",
9401         h->chip_version, h->mcode_date);
9402
9403     printk(
9404 "  mcode_version 0x%x, pci_device_id 0x%x, lib_version %u\n",
9405        h->mcode_version, to_pci_dev(h->dev)->device, h->lib_version);
9406
9407     printk(
9408 "  control_flag 0x%x, pci_slot_info 0x%x\n",
9409        h->control_flag, h->pci_slot_info);
9410 }
9411
9412 /*
9413  * asc_prt_adv_scsi_req_q()
9414  *
9415  * Display an ADV_SCSI_REQ_Q structure.
9416  */
9417 STATIC void
9418 asc_prt_adv_scsi_req_q(ADV_SCSI_REQ_Q *q)
9419 {
9420     int                 sg_blk_cnt;
9421     struct asc_sg_block *sg_ptr;
9422
9423     printk("ADV_SCSI_REQ_Q at addr 0x%lx\n", (ulong) q);
9424
9425     printk(
9426 "  target_id %u, target_lun %u, srb_ptr 0x%lx, a_flag 0x%x\n",
9427             q->target_id, q->target_lun, (ulong) q->srb_ptr, q->a_flag);
9428
9429     printk("  cntl 0x%x, data_addr 0x%lx, vdata_addr 0x%lx\n",
9430             q->cntl, (ulong) le32_to_cpu(q->data_addr), (ulong) q->vdata_addr);
9431
9432     printk(
9433 "  data_cnt %lu, sense_addr 0x%lx, sense_len %u,\n",
9434             (ulong) le32_to_cpu(q->data_cnt),
9435             (ulong) le32_to_cpu(q->sense_addr), q->sense_len);
9436
9437     printk(
9438 "  cdb_len %u, done_status 0x%x, host_status 0x%x, scsi_status 0x%x\n",
9439             q->cdb_len, q->done_status, q->host_status, q->scsi_status);
9440
9441     printk(
9442 "  sg_working_ix 0x%x, target_cmd %u\n",
9443             q->sg_working_ix, q->target_cmd);
9444
9445     printk(
9446 "  scsiq_rptr 0x%lx, sg_real_addr 0x%lx, sg_list_ptr 0x%lx\n",
9447             (ulong) le32_to_cpu(q->scsiq_rptr),
9448             (ulong) le32_to_cpu(q->sg_real_addr), (ulong) q->sg_list_ptr);
9449
9450     /* Display the request's ADV_SG_BLOCK structures. */
9451     if (q->sg_list_ptr != NULL)
9452     {
9453         sg_blk_cnt = 0;
9454         while (1) {
9455             /*
9456              * 'sg_ptr' is a physical address. Convert it to a virtual
9457              * address by indexing 'sg_blk_cnt' into the virtual address
9458              * array 'sg_list_ptr'.
9459              *
9460              * XXX - Assumes all SG physical blocks are virtually contiguous.
9461              */
9462             sg_ptr = &(((ADV_SG_BLOCK *) (q->sg_list_ptr))[sg_blk_cnt]);
9463             asc_prt_adv_sgblock(sg_blk_cnt, sg_ptr);
9464             if (sg_ptr->sg_ptr == 0)
9465             {
9466                 break;
9467             }
9468             sg_blk_cnt++;
9469         }
9470     }
9471 }
9472
9473 /*
9474  * asc_prt_adv_sgblock()
9475  *
9476  * Display an ADV_SG_BLOCK structure.
9477  */
9478 STATIC void
9479 asc_prt_adv_sgblock(int sgblockno, ADV_SG_BLOCK *b)
9480 {
9481     int i;
9482
9483     printk(" ASC_SG_BLOCK at addr 0x%lx (sgblockno %d)\n",
9484         (ulong) b, sgblockno);
9485     printk("  sg_cnt %u, sg_ptr 0x%lx\n",
9486         b->sg_cnt, (ulong) le32_to_cpu(b->sg_ptr));
9487     ASC_ASSERT(b->sg_cnt <= NO_OF_SG_PER_BLOCK);
9488     if (b->sg_ptr != 0)
9489     {
9490         ASC_ASSERT(b->sg_cnt == NO_OF_SG_PER_BLOCK);
9491     }
9492     for (i = 0; i < b->sg_cnt; i++) {
9493         printk("  [%u]: sg_addr 0x%lx, sg_count 0x%lx\n",
9494             i, (ulong) b->sg_list[i].sg_addr, (ulong) b->sg_list[i].sg_count);
9495     }
9496 }
9497
9498 /*
9499  * asc_prt_hex()
9500  *
9501  * Print hexadecimal output in 4 byte groupings 32 bytes
9502  * or 8 double-words per line.
9503  */
9504 STATIC void
9505 asc_prt_hex(char *f, uchar *s, int l)
9506 {
9507     int            i;
9508     int            j;
9509     int            k;
9510     int            m;
9511
9512     printk("%s: (%d bytes)\n", f, l);
9513
9514     for (i = 0; i < l; i += 32) {
9515
9516         /* Display a maximum of 8 double-words per line. */
9517         if ((k = (l - i) / 4) >= 8) {
9518             k = 8;
9519             m = 0;
9520         } else {
9521             m = (l - i) % 4;
9522         }
9523
9524         for (j = 0; j < k; j++) {
9525             printk(" %2.2X%2.2X%2.2X%2.2X",
9526                 (unsigned) s[i+(j*4)], (unsigned) s[i+(j*4)+1],
9527                 (unsigned) s[i+(j*4)+2], (unsigned) s[i+(j*4)+3]);
9528         }
9529
9530         switch (m) {
9531         case 0:
9532         default:
9533             break;
9534         case 1:
9535             printk(" %2.2X",
9536                 (unsigned) s[i+(j*4)]);
9537             break;
9538         case 2:
9539             printk(" %2.2X%2.2X",
9540                 (unsigned) s[i+(j*4)],
9541                 (unsigned) s[i+(j*4)+1]);
9542             break;
9543         case 3:
9544             printk(" %2.2X%2.2X%2.2X",
9545                 (unsigned) s[i+(j*4)+1],
9546                 (unsigned) s[i+(j*4)+2],
9547                 (unsigned) s[i+(j*4)+3]);
9548             break;
9549         }
9550
9551         printk("\n");
9552     }
9553 }
9554 #endif /* ADVANSYS_DEBUG */
9555
9556 /*
9557  * --- Asc Library Functions
9558  */
9559
9560 STATIC ushort __init
9561 AscGetEisaChipCfg(
9562                      PortAddr iop_base)
9563 {
9564     PortAddr            eisa_cfg_iop;
9565
9566     eisa_cfg_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9567       (PortAddr) (ASC_EISA_CFG_IOP_MASK);
9568     return (inpw(eisa_cfg_iop));
9569 }
9570
9571 STATIC uchar __init
9572 AscSetChipScsiID(
9573                     PortAddr iop_base,
9574                     uchar new_host_id
9575 )
9576 {
9577     ushort              cfg_lsw;
9578
9579     if (AscGetChipScsiID(iop_base) == new_host_id) {
9580         return (new_host_id);
9581     }
9582     cfg_lsw = AscGetChipCfgLsw(iop_base);
9583     cfg_lsw &= 0xF8FF;
9584     cfg_lsw |= (ushort) ((new_host_id & ASC_MAX_TID) << 8);
9585     AscSetChipCfgLsw(iop_base, cfg_lsw);
9586     return (AscGetChipScsiID(iop_base));
9587 }
9588
9589 STATIC uchar __init
9590 AscGetChipScsiCtrl(
9591                 PortAddr iop_base)
9592 {
9593     uchar               sc;
9594
9595     AscSetBank(iop_base, 1);
9596     sc = inp(iop_base + IOP_REG_SC);
9597     AscSetBank(iop_base, 0);
9598     return (sc);
9599 }
9600
9601 STATIC uchar __init
9602 AscGetChipVersion(
9603                      PortAddr iop_base,
9604                      ushort bus_type
9605 )
9606 {
9607     if ((bus_type & ASC_IS_EISA) != 0) {
9608         PortAddr            eisa_iop;
9609         uchar               revision;
9610         eisa_iop = (PortAddr) ASC_GET_EISA_SLOT(iop_base) |
9611           (PortAddr) ASC_EISA_REV_IOP_MASK;
9612         revision = inp(eisa_iop);
9613         return ((uchar) ((ASC_CHIP_MIN_VER_EISA - 1) + revision));
9614     }
9615     return (AscGetChipVerNo(iop_base));
9616 }
9617
9618 STATIC ushort __init
9619 AscGetChipBusType(
9620                      PortAddr iop_base)
9621 {
9622     ushort              chip_ver;
9623
9624     chip_ver = AscGetChipVerNo(iop_base);
9625     if (
9626            (chip_ver >= ASC_CHIP_MIN_VER_VL)
9627            && (chip_ver <= ASC_CHIP_MAX_VER_VL)
9628 ) {
9629         if (
9630                ((iop_base & 0x0C30) == 0x0C30)
9631                || ((iop_base & 0x0C50) == 0x0C50)
9632 ) {
9633             return (ASC_IS_EISA);
9634         }
9635         return (ASC_IS_VL);
9636     }
9637     if ((chip_ver >= ASC_CHIP_MIN_VER_ISA) &&
9638         (chip_ver <= ASC_CHIP_MAX_VER_ISA)) {
9639         if (chip_ver >= ASC_CHIP_MIN_VER_ISA_PNP) {
9640             return (ASC_IS_ISAPNP);
9641         }
9642         return (ASC_IS_ISA);
9643     } else if ((chip_ver >= ASC_CHIP_MIN_VER_PCI) &&
9644                (chip_ver <= ASC_CHIP_MAX_VER_PCI)) {
9645         return (ASC_IS_PCI);
9646     }
9647     return (0);
9648 }
9649
9650 STATIC ASC_DCNT
9651 AscLoadMicroCode(
9652                     PortAddr iop_base,
9653                     ushort s_addr,
9654                     uchar *mcode_buf,
9655                     ushort mcode_size
9656 )
9657 {
9658     ASC_DCNT            chksum;
9659     ushort              mcode_word_size;
9660     ushort              mcode_chksum;
9661
9662     /* Write the microcode buffer starting at LRAM address 0. */
9663     mcode_word_size = (ushort) (mcode_size >> 1);
9664     AscMemWordSetLram(iop_base, s_addr, 0, mcode_word_size);
9665     AscMemWordCopyPtrToLram(iop_base, s_addr, mcode_buf, mcode_word_size);
9666
9667     chksum = AscMemSumLramWord(iop_base, s_addr, mcode_word_size);
9668     ASC_DBG1(1, "AscLoadMicroCode: chksum 0x%lx\n", (ulong) chksum);
9669     mcode_chksum = (ushort) AscMemSumLramWord(iop_base,
9670           (ushort) ASC_CODE_SEC_BEG,
9671           (ushort) ((mcode_size - s_addr - (ushort) ASC_CODE_SEC_BEG) / 2));
9672     ASC_DBG1(1, "AscLoadMicroCode: mcode_chksum 0x%lx\n",
9673         (ulong) mcode_chksum);
9674     AscWriteLramWord(iop_base, ASCV_MCODE_CHKSUM_W, mcode_chksum);
9675     AscWriteLramWord(iop_base, ASCV_MCODE_SIZE_W, mcode_size);
9676     return (chksum);
9677 }
9678
9679 STATIC int
9680 AscFindSignature(
9681                     PortAddr iop_base
9682 )
9683 {
9684     ushort              sig_word;
9685
9686     ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureByte(0x%x) 0x%x\n",
9687         iop_base, AscGetChipSignatureByte(iop_base));
9688     if (AscGetChipSignatureByte(iop_base) == (uchar) ASC_1000_ID1B) {
9689         ASC_DBG2(1, "AscFindSignature: AscGetChipSignatureWord(0x%x) 0x%x\n",
9690             iop_base, AscGetChipSignatureWord(iop_base));
9691         sig_word = AscGetChipSignatureWord(iop_base);
9692         if ((sig_word == (ushort) ASC_1000_ID0W) ||
9693             (sig_word == (ushort) ASC_1000_ID0W_FIX)) {
9694             return (1);
9695         }
9696     }
9697     return (0);
9698 }
9699
9700 STATIC PortAddr _asc_def_iop_base[ASC_IOADR_TABLE_MAX_IX] __initdata =
9701 {
9702     0x100, ASC_IOADR_1, 0x120, ASC_IOADR_2, 0x140, ASC_IOADR_3, ASC_IOADR_4,
9703     ASC_IOADR_5, ASC_IOADR_6, ASC_IOADR_7, ASC_IOADR_8
9704 };
9705
9706 #ifdef CONFIG_ISA
9707 STATIC uchar _isa_pnp_inited __initdata = 0;
9708
9709 STATIC PortAddr __init
9710 AscSearchIOPortAddr(
9711                        PortAddr iop_beg,
9712                        ushort bus_type)
9713 {
9714     if (bus_type & ASC_IS_VL) {
9715         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9716             if (AscGetChipVersion(iop_beg, bus_type) <= ASC_CHIP_MAX_VER_VL) {
9717                 return (iop_beg);
9718             }
9719         }
9720         return (0);
9721     }
9722     if (bus_type & ASC_IS_ISA) {
9723         if (_isa_pnp_inited == 0) {
9724             AscSetISAPNPWaitForKey();
9725             _isa_pnp_inited++;
9726         }
9727         while ((iop_beg = AscSearchIOPortAddr11(iop_beg)) != 0) {
9728             if ((AscGetChipVersion(iop_beg, bus_type) & ASC_CHIP_VER_ISA_BIT) != 0) {
9729                 return (iop_beg);
9730             }
9731         }
9732         return (0);
9733     }
9734     if (bus_type & ASC_IS_EISA) {
9735         if ((iop_beg = AscSearchIOPortAddrEISA(iop_beg)) != 0) {
9736             return (iop_beg);
9737         }
9738         return (0);
9739     }
9740     return (0);
9741 }
9742
9743 STATIC PortAddr __init
9744 AscSearchIOPortAddr11(
9745                          PortAddr s_addr
9746 )
9747 {
9748     int                 i;
9749     PortAddr            iop_base;
9750
9751     for (i = 0; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9752         if (_asc_def_iop_base[i] > s_addr) {
9753             break;
9754         }
9755     }
9756     for (; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9757         iop_base = _asc_def_iop_base[i];
9758         if (check_region(iop_base, ASC_IOADR_GAP) != 0) {
9759             ASC_DBG1(1,
9760                "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n",
9761                      iop_base);
9762             continue;
9763         }
9764         ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n", iop_base);
9765         if (AscFindSignature(iop_base)) {
9766             return (iop_base);
9767         }
9768     }
9769     return (0);
9770 }
9771
9772 STATIC void __init
9773 AscSetISAPNPWaitForKey(void)
9774 {
9775     outp(ASC_ISA_PNP_PORT_ADDR, 0x02);
9776     outp(ASC_ISA_PNP_PORT_WRITE, 0x02);
9777     return;
9778 }
9779 #endif /* CONFIG_ISA */
9780
9781 STATIC void __init
9782 AscToggleIRQAct(
9783                    PortAddr iop_base
9784 )
9785 {
9786     AscSetChipStatus(iop_base, CIW_IRQ_ACT);
9787     AscSetChipStatus(iop_base, 0);
9788     return;
9789 }
9790
9791 STATIC uchar __init
9792 AscGetChipIRQ(
9793                  PortAddr iop_base,
9794                  ushort bus_type)
9795 {
9796     ushort              cfg_lsw;
9797     uchar               chip_irq;
9798
9799     if ((bus_type & ASC_IS_EISA) != 0) {
9800         cfg_lsw = AscGetEisaChipCfg(iop_base);
9801         chip_irq = (uchar) (((cfg_lsw >> 8) & 0x07) + 10);
9802         if ((chip_irq == 13) || (chip_irq > 15)) {
9803             return (0);
9804         }
9805         return (chip_irq);
9806     }
9807     if ((bus_type & ASC_IS_VL) != 0) {
9808         cfg_lsw = AscGetChipCfgLsw(iop_base);
9809         chip_irq = (uchar) (((cfg_lsw >> 2) & 0x07));
9810         if ((chip_irq == 0) ||
9811             (chip_irq == 4) ||
9812             (chip_irq == 7)) {
9813             return (0);
9814         }
9815         return ((uchar) (chip_irq + (ASC_MIN_IRQ_NO - 1)));
9816     }
9817     cfg_lsw = AscGetChipCfgLsw(iop_base);
9818     chip_irq = (uchar) (((cfg_lsw >> 2) & 0x03));
9819     if (chip_irq == 3)
9820         chip_irq += (uchar) 2;
9821     return ((uchar) (chip_irq + ASC_MIN_IRQ_NO));
9822 }
9823
9824 STATIC uchar __init
9825 AscSetChipIRQ(
9826                  PortAddr iop_base,
9827                  uchar irq_no,
9828                  ushort bus_type)
9829 {
9830     ushort              cfg_lsw;
9831
9832     if ((bus_type & ASC_IS_VL) != 0) {
9833         if (irq_no != 0) {
9834             if ((irq_no < ASC_MIN_IRQ_NO) || (irq_no > ASC_MAX_IRQ_NO)) {
9835                 irq_no = 0;
9836             } else {
9837                 irq_no -= (uchar) ((ASC_MIN_IRQ_NO - 1));
9838             }
9839         }
9840         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE3);
9841         cfg_lsw |= (ushort) 0x0010;
9842         AscSetChipCfgLsw(iop_base, cfg_lsw);
9843         AscToggleIRQAct(iop_base);
9844         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFE0);
9845         cfg_lsw |= (ushort) ((irq_no & 0x07) << 2);
9846         AscSetChipCfgLsw(iop_base, cfg_lsw);
9847         AscToggleIRQAct(iop_base);
9848         return (AscGetChipIRQ(iop_base, bus_type));
9849     }
9850     if ((bus_type & (ASC_IS_ISA)) != 0) {
9851         if (irq_no == 15)
9852             irq_no -= (uchar) 2;
9853         irq_no -= (uchar) ASC_MIN_IRQ_NO;
9854         cfg_lsw = (ushort) (AscGetChipCfgLsw(iop_base) & 0xFFF3);
9855         cfg_lsw |= (ushort) ((irq_no & 0x03) << 2);
9856         AscSetChipCfgLsw(iop_base, cfg_lsw);
9857         return (AscGetChipIRQ(iop_base, bus_type));
9858     }
9859     return (0);
9860 }
9861
9862 #ifdef CONFIG_ISA
9863 STATIC void __init
9864 AscEnableIsaDma(
9865                    uchar dma_channel)
9866 {
9867     if (dma_channel < 4) {
9868         outp(0x000B, (ushort) (0xC0 | dma_channel));
9869         outp(0x000A, dma_channel);
9870     } else if (dma_channel < 8) {
9871         outp(0x00D6, (ushort) (0xC0 | (dma_channel - 4)));
9872         outp(0x00D4, (ushort) (dma_channel - 4));
9873     }
9874     return;
9875 }
9876 #endif /* CONFIG_ISA */
9877
9878 STATIC int
9879 AscIsrChipHalted(
9880                     ASC_DVC_VAR *asc_dvc
9881 )
9882 {
9883     EXT_MSG             ext_msg;
9884     EXT_MSG             out_msg;
9885     ushort              halt_q_addr;
9886     int                 sdtr_accept;
9887     ushort              int_halt_code;
9888     ASC_SCSI_BIT_ID_TYPE scsi_busy;
9889     ASC_SCSI_BIT_ID_TYPE target_id;
9890     PortAddr            iop_base;
9891     uchar               tag_code;
9892     uchar               q_status;
9893     uchar               halt_qp;
9894     uchar               sdtr_data;
9895     uchar               target_ix;
9896     uchar               q_cntl, tid_no;
9897     uchar               cur_dvc_qng;
9898     uchar               asyn_sdtr;
9899     uchar               scsi_status;
9900     asc_board_t         *boardp;
9901
9902     ASC_ASSERT(asc_dvc->drv_ptr != NULL);
9903     boardp = asc_dvc->drv_ptr;
9904
9905     iop_base = asc_dvc->iop_base;
9906     int_halt_code = AscReadLramWord(iop_base, ASCV_HALTCODE_W);
9907
9908     halt_qp = AscReadLramByte(iop_base, ASCV_CURCDB_B);
9909     halt_q_addr = ASC_QNO_TO_QADDR(halt_qp);
9910     target_ix = AscReadLramByte(iop_base,
9911                    (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TARGET_IX));
9912     q_cntl = AscReadLramByte(iop_base,
9913                         (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL));
9914     tid_no = ASC_TIX_TO_TID(target_ix);
9915     target_id = (uchar) ASC_TID_TO_TARGET_ID(tid_no);
9916     if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9917         asyn_sdtr = ASYN_SDTR_DATA_FIX_PCI_REV_AB;
9918     } else {
9919         asyn_sdtr = 0;
9920     }
9921     if (int_halt_code == ASC_HALT_DISABLE_ASYN_USE_SYN_FIX) {
9922         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9923             AscSetChipSDTR(iop_base, 0, tid_no);
9924             boardp->sdtr_data[tid_no] = 0;
9925         }
9926         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9927         return (0);
9928     } else if (int_halt_code == ASC_HALT_ENABLE_ASYN_USE_SYN_FIX) {
9929         if (asc_dvc->pci_fix_asyn_xfer & target_id) {
9930             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9931             boardp->sdtr_data[tid_no] = asyn_sdtr;
9932         }
9933         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
9934         return (0);
9935     } else if (int_halt_code == ASC_HALT_EXTMSG_IN) {
9936
9937         AscMemWordCopyPtrFromLram(iop_base,
9938                                ASCV_MSGIN_BEG,
9939                                (uchar *) &ext_msg,
9940                                sizeof(EXT_MSG) >> 1);
9941
9942         if (ext_msg.msg_type == MS_EXTEND &&
9943             ext_msg.msg_req == MS_SDTR_CODE &&
9944             ext_msg.msg_len == MS_SDTR_LEN) {
9945             sdtr_accept = TRUE;
9946             if ((ext_msg.req_ack_offset > ASC_SYN_MAX_OFFSET)) {
9947
9948                 sdtr_accept = FALSE;
9949                 ext_msg.req_ack_offset = ASC_SYN_MAX_OFFSET;
9950             }
9951             if ((ext_msg.xfer_period <
9952                  asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index]) ||
9953                 (ext_msg.xfer_period >
9954                  asc_dvc->sdtr_period_tbl[asc_dvc->max_sdtr_index])) {
9955                 sdtr_accept = FALSE;
9956                 ext_msg.xfer_period =
9957                     asc_dvc->sdtr_period_tbl[asc_dvc->host_init_sdtr_index];
9958             }
9959             if (sdtr_accept) {
9960                 sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9961                                            ext_msg.req_ack_offset);
9962                 if ((sdtr_data == 0xFF)) {
9963
9964                     q_cntl |= QC_MSG_OUT;
9965                     asc_dvc->init_sdtr &= ~target_id;
9966                     asc_dvc->sdtr_done &= ~target_id;
9967                     AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9968                     boardp->sdtr_data[tid_no] = asyn_sdtr;
9969                 }
9970             }
9971             if (ext_msg.req_ack_offset == 0) {
9972
9973                 q_cntl &= ~QC_MSG_OUT;
9974                 asc_dvc->init_sdtr &= ~target_id;
9975                 asc_dvc->sdtr_done &= ~target_id;
9976                 AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
9977             } else {
9978                 if (sdtr_accept && (q_cntl & QC_MSG_OUT)) {
9979
9980                     q_cntl &= ~QC_MSG_OUT;
9981                     asc_dvc->sdtr_done |= target_id;
9982                     asc_dvc->init_sdtr |= target_id;
9983                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
9984                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9985                                                ext_msg.req_ack_offset);
9986                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
9987                     boardp->sdtr_data[tid_no] = sdtr_data;
9988                 } else {
9989
9990                     q_cntl |= QC_MSG_OUT;
9991                     AscMsgOutSDTR(asc_dvc,
9992                                   ext_msg.xfer_period,
9993                                   ext_msg.req_ack_offset);
9994                     asc_dvc->pci_fix_asyn_xfer &= ~target_id;
9995                     sdtr_data = AscCalSDTRData(asc_dvc, ext_msg.xfer_period,
9996                                                ext_msg.req_ack_offset);
9997                     AscSetChipSDTR(iop_base, sdtr_data, tid_no);
9998                     boardp->sdtr_data[tid_no] = sdtr_data;
9999                     asc_dvc->sdtr_done |= target_id;
10000                     asc_dvc->init_sdtr |= target_id;
10001                 }
10002             }
10003
10004             AscWriteLramByte(iop_base,
10005                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10006                              q_cntl);
10007             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10008             return (0);
10009         } else if (ext_msg.msg_type == MS_EXTEND &&
10010                    ext_msg.msg_req == MS_WDTR_CODE &&
10011                    ext_msg.msg_len == MS_WDTR_LEN) {
10012
10013             ext_msg.wdtr_width = 0;
10014             AscMemWordCopyPtrToLram(iop_base,
10015                                  ASCV_MSGOUT_BEG,
10016                                  (uchar *) &ext_msg,
10017                                  sizeof(EXT_MSG) >> 1);
10018             q_cntl |= QC_MSG_OUT;
10019             AscWriteLramByte(iop_base,
10020                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10021                              q_cntl);
10022             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10023             return (0);
10024         } else {
10025
10026             ext_msg.msg_type = MESSAGE_REJECT;
10027             AscMemWordCopyPtrToLram(iop_base,
10028                                  ASCV_MSGOUT_BEG,
10029                                  (uchar *) &ext_msg,
10030                                  sizeof(EXT_MSG) >> 1);
10031             q_cntl |= QC_MSG_OUT;
10032             AscWriteLramByte(iop_base,
10033                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10034                              q_cntl);
10035             AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10036             return (0);
10037         }
10038     } else if (int_halt_code == ASC_HALT_CHK_CONDITION) {
10039
10040         q_cntl |= QC_REQ_SENSE;
10041
10042         if ((asc_dvc->init_sdtr & target_id) != 0) {
10043
10044             asc_dvc->sdtr_done &= ~target_id;
10045
10046             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10047             q_cntl |= QC_MSG_OUT;
10048             AscMsgOutSDTR(asc_dvc,
10049                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10050                            (uchar) (asc_dvc->max_sdtr_index - 1)],
10051                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10052         }
10053
10054         AscWriteLramByte(iop_base,
10055                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10056                          q_cntl);
10057
10058         tag_code = AscReadLramByte(iop_base,
10059                     (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE));
10060         tag_code &= 0xDC;
10061         if (
10062                (asc_dvc->pci_fix_asyn_xfer & target_id)
10063                && !(asc_dvc->pci_fix_asyn_xfer_always & target_id)
10064 ) {
10065
10066             tag_code |= (ASC_TAG_FLAG_DISABLE_DISCONNECT
10067                          | ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX);
10068
10069         }
10070         AscWriteLramByte(iop_base,
10071                      (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_TAG_CODE),
10072                          tag_code);
10073
10074         q_status = AscReadLramByte(iop_base,
10075                       (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10076         q_status |= (QS_READY | QS_BUSY);
10077         AscWriteLramByte(iop_base,
10078                        (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10079                          q_status);
10080
10081         scsi_busy = AscReadLramByte(iop_base,
10082                                     (ushort) ASCV_SCSIBUSY_B);
10083         scsi_busy &= ~target_id;
10084         AscWriteLramByte(iop_base, (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10085
10086         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10087         return (0);
10088     } else if (int_halt_code == ASC_HALT_SDTR_REJECTED) {
10089
10090         AscMemWordCopyPtrFromLram(iop_base,
10091                                ASCV_MSGOUT_BEG,
10092                                (uchar *) &out_msg,
10093                                sizeof(EXT_MSG) >> 1);
10094
10095         if ((out_msg.msg_type == MS_EXTEND) &&
10096             (out_msg.msg_len == MS_SDTR_LEN) &&
10097             (out_msg.msg_req == MS_SDTR_CODE)) {
10098
10099             asc_dvc->init_sdtr &= ~target_id;
10100             asc_dvc->sdtr_done &= ~target_id;
10101             AscSetChipSDTR(iop_base, asyn_sdtr, tid_no);
10102             boardp->sdtr_data[tid_no] = asyn_sdtr;
10103         }
10104         q_cntl &= ~QC_MSG_OUT;
10105         AscWriteLramByte(iop_base,
10106                          (ushort) (halt_q_addr + (ushort) ASC_SCSIQ_B_CNTL),
10107                          q_cntl);
10108         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10109         return (0);
10110     } else if (int_halt_code == ASC_HALT_SS_QUEUE_FULL) {
10111
10112         scsi_status = AscReadLramByte(iop_base,
10113           (ushort) ((ushort) halt_q_addr + (ushort) ASC_SCSIQ_SCSI_STATUS));
10114         cur_dvc_qng = AscReadLramByte(iop_base,
10115                      (ushort) ((ushort) ASC_QADR_BEG + (ushort) target_ix));
10116         if ((cur_dvc_qng > 0) &&
10117             (asc_dvc->cur_dvc_qng[tid_no] > 0)) {
10118
10119             scsi_busy = AscReadLramByte(iop_base,
10120                                         (ushort) ASCV_SCSIBUSY_B);
10121             scsi_busy |= target_id;
10122             AscWriteLramByte(iop_base,
10123                              (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10124             asc_dvc->queue_full_or_busy |= target_id;
10125
10126             if (scsi_status == SAM_STAT_TASK_SET_FULL) {
10127                 if (cur_dvc_qng > ASC_MIN_TAGGED_CMD) {
10128                     cur_dvc_qng -= 1;
10129                     asc_dvc->max_dvc_qng[tid_no] = cur_dvc_qng;
10130
10131                     AscWriteLramByte(iop_base,
10132                           (ushort) ((ushort) ASCV_MAX_DVC_QNG_BEG +
10133                            (ushort) tid_no),
10134                           cur_dvc_qng);
10135
10136                     /*
10137                      * Set the device queue depth to the number of
10138                      * active requests when the QUEUE FULL condition
10139                      * was encountered.
10140                      */
10141                     boardp->queue_full |= target_id;
10142                     boardp->queue_full_cnt[tid_no] = cur_dvc_qng;
10143                 }
10144             }
10145         }
10146         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10147         return (0);
10148     }
10149 #if CC_VERY_LONG_SG_LIST
10150     else if (int_halt_code == ASC_HALT_HOST_COPY_SG_LIST_TO_RISC)
10151     {
10152         uchar              q_no;
10153         ushort             q_addr;
10154         uchar              sg_wk_q_no;
10155         uchar              first_sg_wk_q_no;
10156         ASC_SCSI_Q         *scsiq; /* Ptr to driver request. */
10157         ASC_SG_HEAD        *sg_head; /* Ptr to driver SG request. */
10158         ASC_SG_LIST_Q      scsi_sg_q; /* Structure written to queue. */
10159         ushort             sg_list_dwords;
10160         ushort             sg_entry_cnt;
10161         uchar              next_qp;
10162         int                i;
10163
10164         q_no = AscReadLramByte(iop_base, (ushort) ASCV_REQ_SG_LIST_QP);
10165         if (q_no == ASC_QLINK_END)
10166         {
10167             return(0);
10168         }
10169
10170         q_addr = ASC_QNO_TO_QADDR(q_no);
10171
10172         /*
10173          * Convert the request's SRB pointer to a host ASC_SCSI_REQ
10174          * structure pointer using a macro provided by the driver.
10175          * The ASC_SCSI_REQ pointer provides a pointer to the
10176          * host ASC_SG_HEAD structure.
10177          */
10178         /* Read request's SRB pointer. */
10179         scsiq = (ASC_SCSI_Q *)
10180            ASC_SRB2SCSIQ(
10181                ASC_U32_TO_VADDR(AscReadLramDWord(iop_base,
10182                (ushort) (q_addr + ASC_SCSIQ_D_SRBPTR))));
10183
10184         /*
10185          * Get request's first and working SG queue.
10186          */
10187         sg_wk_q_no = AscReadLramByte(iop_base,
10188             (ushort) (q_addr + ASC_SCSIQ_B_SG_WK_QP));
10189
10190         first_sg_wk_q_no = AscReadLramByte(iop_base,
10191             (ushort) (q_addr + ASC_SCSIQ_B_FIRST_SG_WK_QP));
10192
10193         /*
10194          * Reset request's working SG queue back to the
10195          * first SG queue.
10196          */
10197         AscWriteLramByte(iop_base,
10198             (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SG_WK_QP),
10199             first_sg_wk_q_no);
10200
10201         sg_head = scsiq->sg_head;
10202
10203         /*
10204          * Set sg_entry_cnt to the number of SG elements
10205          * that will be completed on this interrupt.
10206          *
10207          * Note: The allocated SG queues contain ASC_MAX_SG_LIST - 1
10208          * SG elements. The data_cnt and data_addr fields which
10209          * add 1 to the SG element capacity are not used when
10210          * restarting SG handling after a halt.
10211          */
10212         if (scsiq->remain_sg_entry_cnt > (ASC_MAX_SG_LIST - 1))
10213         {
10214              sg_entry_cnt = ASC_MAX_SG_LIST - 1;
10215
10216              /*
10217               * Keep track of remaining number of SG elements that will
10218               * need to be handled on the next interrupt.
10219               */
10220              scsiq->remain_sg_entry_cnt -= (ASC_MAX_SG_LIST - 1);
10221         } else
10222         {
10223              sg_entry_cnt = scsiq->remain_sg_entry_cnt;
10224              scsiq->remain_sg_entry_cnt = 0;
10225         }
10226
10227         /*
10228          * Copy SG elements into the list of allocated SG queues.
10229          *
10230          * Last index completed is saved in scsiq->next_sg_index.
10231          */
10232         next_qp = first_sg_wk_q_no;
10233         q_addr = ASC_QNO_TO_QADDR(next_qp);
10234         scsi_sg_q.sg_head_qp = q_no;
10235         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
10236         for( i = 0; i < sg_head->queue_cnt; i++)
10237         {
10238              scsi_sg_q.seq_no = i + 1;
10239              if (sg_entry_cnt > ASC_SG_LIST_PER_Q)
10240              {
10241                  sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
10242                  sg_entry_cnt -= ASC_SG_LIST_PER_Q;
10243                  /*
10244                   * After very first SG queue RISC FW uses next
10245                   * SG queue first element then checks sg_list_cnt
10246                   * against zero and then decrements, so set
10247                   * sg_list_cnt 1 less than number of SG elements
10248                   * in each SG queue.
10249                   */
10250                  scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
10251                  scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
10252              } else {
10253                  /*
10254                   * This is the last SG queue in the list of
10255                   * allocated SG queues. If there are more
10256                   * SG elements than will fit in the allocated
10257                   * queues, then set the QCSG_SG_XFER_MORE flag.
10258                   */
10259                  if (scsiq->remain_sg_entry_cnt != 0)
10260                  {
10261                      scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
10262                  } else
10263                  {
10264                      scsi_sg_q.cntl |= QCSG_SG_XFER_END;
10265                  }
10266                  /* equals sg_entry_cnt * 2 */
10267                  sg_list_dwords = sg_entry_cnt << 1;
10268                  scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
10269                  scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
10270                  sg_entry_cnt = 0;
10271              }
10272
10273              scsi_sg_q.q_no = next_qp;
10274              AscMemWordCopyPtrToLram(iop_base,
10275                           q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
10276                           (uchar *) &scsi_sg_q,
10277                           sizeof(ASC_SG_LIST_Q) >> 1);
10278
10279              AscMemDWordCopyPtrToLram(iop_base,
10280                           q_addr + ASC_SGQ_LIST_BEG,
10281                           (uchar *) &sg_head->sg_list[scsiq->next_sg_index],
10282                           sg_list_dwords);
10283
10284              scsiq->next_sg_index += ASC_SG_LIST_PER_Q;
10285
10286              /*
10287               * If the just completed SG queue contained the
10288               * last SG element, then no more SG queues need
10289               * to be written.
10290               */
10291              if (scsi_sg_q.cntl & QCSG_SG_XFER_END)
10292              {
10293                  break;
10294              }
10295
10296              next_qp = AscReadLramByte( iop_base,
10297                           ( ushort )( q_addr+ASC_SCSIQ_B_FWD ) );
10298              q_addr = ASC_QNO_TO_QADDR( next_qp );
10299         }
10300
10301         /*
10302          * Clear the halt condition so the RISC will be restarted
10303          * after the return.
10304          */
10305         AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
10306         return(0);
10307     }
10308 #endif /* CC_VERY_LONG_SG_LIST */
10309     return (0);
10310 }
10311
10312 STATIC uchar
10313 _AscCopyLramScsiDoneQ(
10314                          PortAddr iop_base,
10315                          ushort q_addr,
10316                          ASC_QDONE_INFO * scsiq,
10317                          ASC_DCNT max_dma_count
10318 )
10319 {
10320     ushort              _val;
10321     uchar               sg_queue_cnt;
10322
10323     DvcGetQinfo(iop_base,
10324                 q_addr + ASC_SCSIQ_DONE_INFO_BEG,
10325                 (uchar *) scsiq,
10326                 (sizeof (ASC_SCSIQ_2) + sizeof (ASC_SCSIQ_3)) / 2);
10327
10328     _val = AscReadLramWord(iop_base,
10329                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS));
10330     scsiq->q_status = (uchar) _val;
10331     scsiq->q_no = (uchar) (_val >> 8);
10332     _val = AscReadLramWord(iop_base,
10333                            (ushort) (q_addr + (ushort) ASC_SCSIQ_B_CNTL));
10334     scsiq->cntl = (uchar) _val;
10335     sg_queue_cnt = (uchar) (_val >> 8);
10336     _val = AscReadLramWord(iop_base,
10337                         (ushort) (q_addr + (ushort) ASC_SCSIQ_B_SENSE_LEN));
10338     scsiq->sense_len = (uchar) _val;
10339     scsiq->extra_bytes = (uchar) (_val >> 8);
10340
10341     /*
10342      * Read high word of remain bytes from alternate location.
10343      */
10344     scsiq->remain_bytes = (((ADV_DCNT) AscReadLramWord( iop_base,
10345                       (ushort) (q_addr+ (ushort) ASC_SCSIQ_W_ALT_DC1))) << 16);
10346     /*
10347      * Read low word of remain bytes from original location.
10348      */
10349     scsiq->remain_bytes += AscReadLramWord(iop_base,
10350         (ushort) (q_addr+ (ushort) ASC_SCSIQ_DW_REMAIN_XFER_CNT));
10351
10352     scsiq->remain_bytes &= max_dma_count;
10353     return (sg_queue_cnt);
10354 }
10355
10356 STATIC int
10357 AscIsrQDone(
10358                ASC_DVC_VAR *asc_dvc
10359 )
10360 {
10361     uchar               next_qp;
10362     uchar               n_q_used;
10363     uchar               sg_list_qp;
10364     uchar               sg_queue_cnt;
10365     uchar               q_cnt;
10366     uchar               done_q_tail;
10367     uchar               tid_no;
10368     ASC_SCSI_BIT_ID_TYPE scsi_busy;
10369     ASC_SCSI_BIT_ID_TYPE target_id;
10370     PortAddr            iop_base;
10371     ushort              q_addr;
10372     ushort              sg_q_addr;
10373     uchar               cur_target_qng;
10374     ASC_QDONE_INFO      scsiq_buf;
10375     ASC_QDONE_INFO *scsiq;
10376     int                 false_overrun;
10377     ASC_ISR_CALLBACK    asc_isr_callback;
10378
10379     iop_base = asc_dvc->iop_base;
10380     asc_isr_callback = asc_dvc->isr_callback;
10381     n_q_used = 1;
10382     scsiq = (ASC_QDONE_INFO *) & scsiq_buf;
10383     done_q_tail = (uchar) AscGetVarDoneQTail(iop_base);
10384     q_addr = ASC_QNO_TO_QADDR(done_q_tail);
10385     next_qp = AscReadLramByte(iop_base,
10386                               (ushort) (q_addr + (ushort) ASC_SCSIQ_B_FWD));
10387     if (next_qp != ASC_QLINK_END) {
10388         AscPutVarDoneQTail(iop_base, next_qp);
10389         q_addr = ASC_QNO_TO_QADDR(next_qp);
10390         sg_queue_cnt = _AscCopyLramScsiDoneQ(iop_base, q_addr, scsiq,
10391             asc_dvc->max_dma_count);
10392         AscWriteLramByte(iop_base,
10393                          (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10394              (uchar) (scsiq->q_status & (uchar) ~ (QS_READY | QS_ABORTED)));
10395         tid_no = ASC_TIX_TO_TID(scsiq->d2.target_ix);
10396         target_id = ASC_TIX_TO_TARGET_ID(scsiq->d2.target_ix);
10397         if ((scsiq->cntl & QC_SG_HEAD) != 0) {
10398             sg_q_addr = q_addr;
10399             sg_list_qp = next_qp;
10400             for (q_cnt = 0; q_cnt < sg_queue_cnt; q_cnt++) {
10401                 sg_list_qp = AscReadLramByte(iop_base,
10402                            (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_FWD));
10403                 sg_q_addr = ASC_QNO_TO_QADDR(sg_list_qp);
10404                 if (sg_list_qp == ASC_QLINK_END) {
10405                     AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SG_Q_LINKS);
10406                     scsiq->d3.done_stat = QD_WITH_ERROR;
10407                     scsiq->d3.host_stat = QHSTA_D_QDONE_SG_LIST_CORRUPTED;
10408                     goto FATAL_ERR_QDONE;
10409                 }
10410                 AscWriteLramByte(iop_base,
10411                          (ushort) (sg_q_addr + (ushort) ASC_SCSIQ_B_STATUS),
10412                                  QS_FREE);
10413             }
10414             n_q_used = sg_queue_cnt + 1;
10415             AscPutVarDoneQTail(iop_base, sg_list_qp);
10416         }
10417         if (asc_dvc->queue_full_or_busy & target_id) {
10418             cur_target_qng = AscReadLramByte(iop_base,
10419             (ushort) ((ushort) ASC_QADR_BEG + (ushort) scsiq->d2.target_ix));
10420             if (cur_target_qng < asc_dvc->max_dvc_qng[tid_no]) {
10421                 scsi_busy = AscReadLramByte(iop_base,
10422                                             (ushort) ASCV_SCSIBUSY_B);
10423                 scsi_busy &= ~target_id;
10424                 AscWriteLramByte(iop_base,
10425                                  (ushort) ASCV_SCSIBUSY_B, scsi_busy);
10426                 asc_dvc->queue_full_or_busy &= ~target_id;
10427             }
10428         }
10429         if (asc_dvc->cur_total_qng >= n_q_used) {
10430             asc_dvc->cur_total_qng -= n_q_used;
10431             if (asc_dvc->cur_dvc_qng[tid_no] != 0) {
10432                 asc_dvc->cur_dvc_qng[tid_no]--;
10433             }
10434         } else {
10435             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CUR_QNG);
10436             scsiq->d3.done_stat = QD_WITH_ERROR;
10437             goto FATAL_ERR_QDONE;
10438         }
10439         if ((scsiq->d2.srb_ptr == 0UL) ||
10440             ((scsiq->q_status & QS_ABORTED) != 0)) {
10441             return (0x11);
10442         } else if (scsiq->q_status == QS_DONE) {
10443             false_overrun = FALSE;
10444             if (scsiq->extra_bytes != 0) {
10445                 scsiq->remain_bytes += (ADV_DCNT) scsiq->extra_bytes;
10446             }
10447             if (scsiq->d3.done_stat == QD_WITH_ERROR) {
10448                 if (scsiq->d3.host_stat == QHSTA_M_DATA_OVER_RUN) {
10449                     if ((scsiq->cntl & (QC_DATA_IN | QC_DATA_OUT)) == 0) {
10450                         scsiq->d3.done_stat = QD_NO_ERROR;
10451                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10452                     } else if (false_overrun) {
10453                         scsiq->d3.done_stat = QD_NO_ERROR;
10454                         scsiq->d3.host_stat = QHSTA_NO_ERROR;
10455                     }
10456                 } else if (scsiq->d3.host_stat ==
10457                            QHSTA_M_HUNG_REQ_SCSI_BUS_RESET) {
10458                     AscStopChip(iop_base);
10459                     AscSetChipControl(iop_base,
10460                         (uchar) (CC_SCSI_RESET | CC_HALT));
10461                     DvcDelayNanoSecond(asc_dvc, 60000);
10462                     AscSetChipControl(iop_base, CC_HALT);
10463                     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10464                     AscSetChipStatus(iop_base, 0);
10465                     AscSetChipControl(iop_base, 0);
10466                 }
10467             }
10468             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10469                 (*asc_isr_callback) (asc_dvc, scsiq);
10470             } else {
10471                 if ((AscReadLramByte(iop_base,
10472                           (ushort) (q_addr + (ushort) ASC_SCSIQ_CDB_BEG)) ==
10473                      START_STOP)) {
10474                     asc_dvc->unit_not_ready &= ~target_id;
10475                     if (scsiq->d3.done_stat != QD_NO_ERROR) {
10476                         asc_dvc->start_motor &= ~target_id;
10477                     }
10478                 }
10479             }
10480             return (1);
10481         } else {
10482             AscSetLibErrorCode(asc_dvc, ASCQ_ERR_Q_STATUS);
10483           FATAL_ERR_QDONE:
10484             if ((scsiq->cntl & QC_NO_CALLBACK) == 0) {
10485                 (*asc_isr_callback) (asc_dvc, scsiq);
10486             }
10487             return (0x80);
10488         }
10489     }
10490     return (0);
10491 }
10492
10493 STATIC int
10494 AscISR(
10495           ASC_DVC_VAR *asc_dvc
10496 )
10497 {
10498     ASC_CS_TYPE         chipstat;
10499     PortAddr            iop_base;
10500     ushort              saved_ram_addr;
10501     uchar               ctrl_reg;
10502     uchar               saved_ctrl_reg;
10503     int                 int_pending;
10504     int                 status;
10505     uchar               host_flag;
10506
10507     iop_base = asc_dvc->iop_base;
10508     int_pending = FALSE;
10509
10510     if (AscIsIntPending(iop_base) == 0)
10511     {
10512         return int_pending;
10513     }
10514
10515     if (((asc_dvc->init_state & ASC_INIT_STATE_END_LOAD_MC) == 0)
10516         || (asc_dvc->isr_callback == 0)
10517 ) {
10518         return (ERR);
10519     }
10520     if (asc_dvc->in_critical_cnt != 0) {
10521         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_ON_CRITICAL);
10522         return (ERR);
10523     }
10524     if (asc_dvc->is_in_int) {
10525         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_ISR_RE_ENTRY);
10526         return (ERR);
10527     }
10528     asc_dvc->is_in_int = TRUE;
10529     ctrl_reg = AscGetChipControl(iop_base);
10530     saved_ctrl_reg = ctrl_reg & (~(CC_SCSI_RESET | CC_CHIP_RESET |
10531                                    CC_SINGLE_STEP | CC_DIAG | CC_TEST));
10532     chipstat = AscGetChipStatus(iop_base);
10533     if (chipstat & CSW_SCSI_RESET_LATCH) {
10534         if (!(asc_dvc->bus_type & (ASC_IS_VL | ASC_IS_EISA))) {
10535             int i = 10;
10536             int_pending = TRUE;
10537             asc_dvc->sdtr_done = 0;
10538             saved_ctrl_reg &= (uchar) (~CC_HALT);
10539             while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) &&
10540                    (i-- > 0))
10541             {
10542                   DvcSleepMilliSecond(100);
10543             }
10544             AscSetChipControl(iop_base, (CC_CHIP_RESET | CC_HALT));
10545             AscSetChipControl(iop_base, CC_HALT);
10546             AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
10547             AscSetChipStatus(iop_base, 0);
10548             chipstat = AscGetChipStatus(iop_base);
10549         }
10550     }
10551     saved_ram_addr = AscGetChipLramAddr(iop_base);
10552     host_flag = AscReadLramByte(iop_base,
10553         ASCV_HOST_FLAG_B) & (uchar) (~ASC_HOST_FLAG_IN_ISR);
10554     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
10555                      (uchar) (host_flag | (uchar) ASC_HOST_FLAG_IN_ISR));
10556     if ((chipstat & CSW_INT_PENDING)
10557         || (int_pending)
10558 ) {
10559         AscAckInterrupt(iop_base);
10560         int_pending = TRUE;
10561         if ((chipstat & CSW_HALTED) &&
10562             (ctrl_reg & CC_SINGLE_STEP)) {
10563             if (AscIsrChipHalted(asc_dvc) == ERR) {
10564                 goto ISR_REPORT_QDONE_FATAL_ERROR;
10565             } else {
10566                 saved_ctrl_reg &= (uchar) (~CC_HALT);
10567             }
10568         } else {
10569           ISR_REPORT_QDONE_FATAL_ERROR:
10570             if ((asc_dvc->dvc_cntl & ASC_CNTL_INT_MULTI_Q) != 0) {
10571                 while (((status = AscIsrQDone(asc_dvc)) & 0x01) != 0) {
10572                 }
10573             } else {
10574                 do {
10575                     if ((status = AscIsrQDone(asc_dvc)) == 1) {
10576                         break;
10577                     }
10578                 } while (status == 0x11);
10579             }
10580             if ((status & 0x80) != 0)
10581                 int_pending = ERR;
10582         }
10583     }
10584     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
10585     AscSetChipLramAddr(iop_base, saved_ram_addr);
10586     AscSetChipControl(iop_base, saved_ctrl_reg);
10587     asc_dvc->is_in_int = FALSE;
10588     return (int_pending);
10589 }
10590
10591 /* Microcode buffer is kept after initialization for error recovery. */
10592 STATIC uchar _asc_mcode_buf[] =
10593 {
10594   0x01,  0x03,  0x01,  0x19,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10595   0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x0F,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10596   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10597   0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10598   0x00,  0x00,  0x00,  0x00,  0xC3,  0x12,  0x0D,  0x05,  0x01,  0x00,  0x00,  0x00,  0x00,  0xFF,  0x00,  0x00,
10599   0x00,  0x00,  0x00,  0x00,  0xFF,  0x80,  0xFF,  0xFF,  0x01,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
10600   0x00,  0x00,  0x00,  0x23,  0x00,  0x00,  0x00,  0x00,  0x00,  0x07,  0x00,  0xFF,  0x00,  0x00,  0x00,  0x00,
10601   0xFF,  0xFF,  0xFF,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0xE4,  0x88,  0x00,  0x00,  0x00,  0x00,
10602   0x80,  0x73,  0x48,  0x04,  0x36,  0x00,  0x00,  0xA2,  0xC2,  0x00,  0x80,  0x73,  0x03,  0x23,  0x36,  0x40,
10603   0xB6,  0x00,  0x36,  0x00,  0x05,  0xD6,  0x0C,  0xD2,  0x12,  0xDA,  0x00,  0xA2,  0xC2,  0x00,  0x92,  0x80,
10604   0x1E,  0x98,  0x50,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xDF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,
10605   0x4F,  0x00,  0xF5,  0x00,  0x48,  0x98,  0xEF,  0x23,  0x36,  0x60,  0xB6,  0x00,  0x92,  0x80,  0x80,  0x62,
10606   0x92,  0x80,  0x00,  0x46,  0x15,  0xEE,  0x13,  0xEA,  0x02,  0x01,  0x09,  0xD8,  0xCD,  0x04,  0x4D,  0x00,
10607   0x00,  0xA3,  0xD6,  0x00,  0xA6,  0x97,  0x7F,  0x23,  0x04,  0x61,  0x84,  0x01,  0xE6,  0x84,  0xD2,  0xC1,
10608   0x80,  0x73,  0xCD,  0x04,  0x4D,  0x00,  0x00,  0xA3,  0xDA,  0x01,  0xA6,  0x97,  0xC6,  0x81,  0xC2,  0x88,
10609   0x80,  0x73,  0x80,  0x77,  0x00,  0x01,  0x01,  0xA1,  0xFE,  0x00,  0x4F,  0x00,  0x84,  0x97,  0x07,  0xA6,
10610   0x08,  0x01,  0x00,  0x33,  0x03,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x01,  0xDE,  0xC2,  0x88,  0xCE,  0x00,
10611   0x69,  0x60,  0xCE,  0x00,  0x02,  0x03,  0x4A,  0x60,  0x00,  0xA2,  0x78,  0x01,  0x80,  0x63,  0x07,  0xA6,
10612   0x24,  0x01,  0x78,  0x81,  0x03,  0x03,  0x80,  0x63,  0xE2,  0x00,  0x07,  0xA6,  0x34,  0x01,  0x00,  0x33,
10613   0x04,  0x00,  0xC2,  0x88,  0x03,  0x07,  0x02,  0x01,  0x04,  0xCA,  0x0D,  0x23,  0x68,  0x98,  0x4D,  0x04,
10614   0x04,  0x85,  0x05,  0xD8,  0x0D,  0x23,  0x68,  0x98,  0xCD,  0x04,  0x15,  0x23,  0xF8,  0x88,  0xFB,  0x23,
10615   0x02,  0x61,  0x82,  0x01,  0x80,  0x63,  0x02,  0x03,  0x06,  0xA3,  0x62,  0x01,  0x00,  0x33,  0x0A,  0x00,
10616   0xC2,  0x88,  0x4E,  0x00,  0x07,  0xA3,  0x6E,  0x01,  0x00,  0x33,  0x0B,  0x00,  0xC2,  0x88,  0xCD,  0x04,
10617   0x36,  0x2D,  0x00,  0x33,  0x1A,  0x00,  0xC2,  0x88,  0x50,  0x04,  0x88,  0x81,  0x06,  0xAB,  0x82,  0x01,
10618   0x88,  0x81,  0x4E,  0x00,  0x07,  0xA3,  0x92,  0x01,  0x50,  0x00,  0x00,  0xA3,  0x3C,  0x01,  0x00,  0x05,
10619   0x7C,  0x81,  0x46,  0x97,  0x02,  0x01,  0x05,  0xC6,  0x04,  0x23,  0xA0,  0x01,  0x15,  0x23,  0xA1,  0x01,
10620   0xBE,  0x81,  0xFD,  0x23,  0x02,  0x61,  0x82,  0x01,  0x0A,  0xDA,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,
10621   0xB4,  0x01,  0x80,  0x63,  0xCD,  0x04,  0x36,  0x2D,  0x00,  0x33,  0x1B,  0x00,  0xC2,  0x88,  0x06,  0x23,
10622   0x68,  0x98,  0xCD,  0x04,  0xE6,  0x84,  0x06,  0x01,  0x00,  0xA2,  0xD4,  0x01,  0x57,  0x60,  0x00,  0xA0,
10623   0xDA,  0x01,  0xE6,  0x84,  0x80,  0x23,  0xA0,  0x01,  0xE6,  0x84,  0x80,  0x73,  0x4B,  0x00,  0x06,  0x61,
10624   0x00,  0xA2,  0x00,  0x02,  0x04,  0x01,  0x0C,  0xDE,  0x02,  0x01,  0x03,  0xCC,  0x4F,  0x00,  0x84,  0x97,
10625   0xFC,  0x81,  0x08,  0x23,  0x02,  0x41,  0x82,  0x01,  0x4F,  0x00,  0x62,  0x97,  0x48,  0x04,  0x84,  0x80,
10626   0xF0,  0x97,  0x00,  0x46,  0x56,  0x00,  0x03,  0xC0,  0x01,  0x23,  0xE8,  0x00,  0x81,  0x73,  0x06,  0x29,
10627   0x03,  0x42,  0x06,  0xE2,  0x03,  0xEE,  0x6B,  0xEB,  0x11,  0x23,  0xF8,  0x88,  0x04,  0x98,  0xF0,  0x80,
10628   0x80,  0x73,  0x80,  0x77,  0x07,  0xA4,  0x2A,  0x02,  0x7C,  0x95,  0x06,  0xA6,  0x34,  0x02,  0x03,  0xA6,
10629   0x4C,  0x04,  0x46,  0x82,  0x04,  0x01,  0x03,  0xD8,  0xB4,  0x98,  0x6A,  0x96,  0x46,  0x82,  0xFE,  0x95,
10630   0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0xB6,  0x2D,  0x02,  0xA6,  0x6C,  0x02,  0x07,  0xA6,  0x5A,  0x02,
10631   0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x62,  0x02,  0xC2,  0x88,  0x7C,  0x95,  0x48,  0x82,  0x60,  0x96,
10632   0x48,  0x82,  0x04,  0x23,  0xA0,  0x01,  0x14,  0x23,  0xA1,  0x01,  0x3C,  0x84,  0x04,  0x01,  0x0C,  0xDC,
10633   0xE0,  0x23,  0x25,  0x61,  0xEF,  0x00,  0x14,  0x01,  0x4F,  0x04,  0xA8,  0x01,  0x6F,  0x00,  0xA5,  0x01,
10634   0x03,  0x23,  0xA4,  0x01,  0x06,  0x23,  0x9C,  0x01,  0x24,  0x2B,  0x1C,  0x01,  0x02,  0xA6,  0xAA,  0x02,
10635   0x07,  0xA6,  0x5A,  0x02,  0x06,  0xA6,  0x5E,  0x02,  0x03,  0xA6,  0x20,  0x04,  0x01,  0xA6,  0xB4,  0x02,
10636   0x00,  0xA6,  0xB4,  0x02,  0x00,  0x33,  0x12,  0x00,  0xC2,  0x88,  0x00,  0x0E,  0x80,  0x63,  0x00,  0x43,
10637   0x00,  0xA0,  0x8C,  0x02,  0x4D,  0x04,  0x04,  0x01,  0x0B,  0xDC,  0xE7,  0x23,  0x04,  0x61,  0x84,  0x01,
10638   0x10,  0x31,  0x12,  0x35,  0x14,  0x01,  0xEC,  0x00,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0xEA,  0x82,
10639   0x18,  0x23,  0x04,  0x61,  0x18,  0xA0,  0xE2,  0x02,  0x04,  0x01,  0xA2,  0xC8,  0x00,  0x33,  0x1F,  0x00,
10640   0xC2,  0x88,  0x08,  0x31,  0x0A,  0x35,  0x0C,  0x39,  0x0E,  0x3D,  0x7E,  0x98,  0xB6,  0x2D,  0x01,  0xA6,
10641   0x14,  0x03,  0x00,  0xA6,  0x14,  0x03,  0x07,  0xA6,  0x0C,  0x03,  0x06,  0xA6,  0x10,  0x03,  0x03,  0xA6,
10642   0x20,  0x04,  0x02,  0xA6,  0x6C,  0x02,  0x00,  0x33,  0x33,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xEE,  0x82,
10643   0x60,  0x96,  0xEE,  0x82,  0x82,  0x98,  0x80,  0x42,  0x7E,  0x98,  0x64,  0xE4,  0x04,  0x01,  0x2D,  0xC8,
10644   0x31,  0x05,  0x07,  0x01,  0x00,  0xA2,  0x54,  0x03,  0x00,  0x43,  0x87,  0x01,  0x05,  0x05,  0x86,  0x98,
10645   0x7E,  0x98,  0x00,  0xA6,  0x16,  0x03,  0x07,  0xA6,  0x4C,  0x03,  0x03,  0xA6,  0x3C,  0x04,  0x06,  0xA6,
10646   0x50,  0x03,  0x01,  0xA6,  0x16,  0x03,  0x00,  0x33,  0x25,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x32,  0x83,
10647   0x60,  0x96,  0x32,  0x83,  0x04,  0x01,  0x10,  0xCE,  0x07,  0xC8,  0x05,  0x05,  0xEB,  0x04,  0x00,  0x33,
10648   0x00,  0x20,  0xC0,  0x20,  0x81,  0x62,  0x72,  0x83,  0x00,  0x01,  0x05,  0x05,  0xFF,  0xA2,  0x7A,  0x03,
10649   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x2E,  0x83,  0x05,  0x05,  0x15,  0x01,  0x00,  0xA2,  0x9A,  0x03,
10650   0xEC,  0x00,  0x6E,  0x00,  0x95,  0x01,  0x6C,  0x38,  0x00,  0x3F,  0x00,  0x00,  0x01,  0xA6,  0x96,  0x03,
10651   0x00,  0xA6,  0x96,  0x03,  0x10,  0x84,  0x80,  0x42,  0x7E,  0x98,  0x01,  0xA6,  0xA4,  0x03,  0x00,  0xA6,
10652   0xBC,  0x03,  0x10,  0x84,  0xA8,  0x98,  0x80,  0x42,  0x01,  0xA6,  0xA4,  0x03,  0x07,  0xA6,  0xB2,  0x03,
10653   0xD4,  0x83,  0x7C,  0x95,  0xA8,  0x83,  0x00,  0x33,  0x2F,  0x00,  0xC2,  0x88,  0xA8,  0x98,  0x80,  0x42,
10654   0x00,  0xA6,  0xBC,  0x03,  0x07,  0xA6,  0xCA,  0x03,  0xD4,  0x83,  0x7C,  0x95,  0xC0,  0x83,  0x00,  0x33,
10655   0x26,  0x00,  0xC2,  0x88,  0x38,  0x2B,  0x80,  0x32,  0x80,  0x36,  0x04,  0x23,  0xA0,  0x01,  0x12,  0x23,
10656   0xA1,  0x01,  0x10,  0x84,  0x07,  0xF0,  0x06,  0xA4,  0xF4,  0x03,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,
10657   0x83,  0x03,  0x80,  0x63,  0x03,  0xA6,  0x0E,  0x04,  0x07,  0xA6,  0x06,  0x04,  0x06,  0xA6,  0x0A,  0x04,
10658   0x00,  0x33,  0x17,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0xF4,  0x83,  0x60,  0x96,  0xF4,  0x83,  0x20,  0x84,
10659   0x07,  0xF0,  0x06,  0xA4,  0x20,  0x04,  0x80,  0x6B,  0x80,  0x67,  0x05,  0x23,  0x83,  0x03,  0x80,  0x63,
10660   0xB6,  0x2D,  0x03,  0xA6,  0x3C,  0x04,  0x07,  0xA6,  0x34,  0x04,  0x06,  0xA6,  0x38,  0x04,  0x00,  0x33,
10661   0x30,  0x00,  0xC2,  0x88,  0x7C,  0x95,  0x20,  0x84,  0x60,  0x96,  0x20,  0x84,  0x1D,  0x01,  0x06,  0xCC,
10662   0x00,  0x33,  0x00,  0x84,  0xC0,  0x20,  0x00,  0x23,  0xEA,  0x00,  0x81,  0x62,  0xA2,  0x0D,  0x80,  0x63,
10663   0x07,  0xA6,  0x5A,  0x04,  0x00,  0x33,  0x18,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0xA3,  0x01,
10664   0x07,  0xA4,  0x64,  0x04,  0x23,  0x01,  0x00,  0xA2,  0x86,  0x04,  0x0A,  0xA0,  0x76,  0x04,  0xE0,  0x00,
10665   0x00,  0x33,  0x1D,  0x00,  0xC2,  0x88,  0x0B,  0xA0,  0x82,  0x04,  0xE0,  0x00,  0x00,  0x33,  0x1E,  0x00,
10666   0xC2,  0x88,  0x42,  0x23,  0xF8,  0x88,  0x00,  0x23,  0x22,  0xA3,  0xE6,  0x04,  0x08,  0x23,  0x22,  0xA3,
10667   0xA2,  0x04,  0x28,  0x23,  0x22,  0xA3,  0xAE,  0x04,  0x02,  0x23,  0x22,  0xA3,  0xC4,  0x04,  0x42,  0x23,
10668   0xF8,  0x88,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA0,  0xAE,  0x04,  0x45,  0x23,  0xF8,  0x88,  0x04,  0x98,
10669   0x00,  0xA2,  0xC0,  0x04,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x82,  0xC0,  0x20,  0x81,  0x62,  0xE8,  0x81,
10670   0x47,  0x23,  0xF8,  0x88,  0x04,  0x01,  0x0B,  0xDE,  0x04,  0x98,  0xB4,  0x98,  0x00,  0x33,  0x00,  0x81,
10671   0xC0,  0x20,  0x81,  0x62,  0x14,  0x01,  0x00,  0xA0,  0x00,  0x02,  0x43,  0x23,  0xF8,  0x88,  0x04,  0x23,
10672   0xA0,  0x01,  0x44,  0x23,  0xA1,  0x01,  0x80,  0x73,  0x4D,  0x00,  0x03,  0xA3,  0xF4,  0x04,  0x00,  0x33,
10673   0x27,  0x00,  0xC2,  0x88,  0x04,  0x01,  0x04,  0xDC,  0x02,  0x23,  0xA2,  0x01,  0x04,  0x23,  0xA0,  0x01,
10674   0x04,  0x98,  0x26,  0x95,  0x4B,  0x00,  0xF6,  0x00,  0x4F,  0x04,  0x4F,  0x00,  0x00,  0xA3,  0x22,  0x05,
10675   0x00,  0x05,  0x76,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x1C,  0x05,  0x0A,  0x85,  0x46,  0x97,  0xCD,  0x04,
10676   0x24,  0x85,  0x48,  0x04,  0x84,  0x80,  0x02,  0x01,  0x03,  0xDA,  0x80,  0x23,  0x82,  0x01,  0x34,  0x85,
10677   0x02,  0x23,  0xA0,  0x01,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0x40,  0x05,  0x1D,  0x01,  0x04,  0xD6,
10678   0xFF,  0x23,  0x86,  0x41,  0x4B,  0x60,  0xCB,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x49,  0x00,  0x81,  0x01,
10679   0x04,  0x01,  0x02,  0xC8,  0x30,  0x01,  0x80,  0x01,  0xF7,  0x04,  0x03,  0x01,  0x49,  0x04,  0x80,  0x01,
10680   0xC9,  0x00,  0x00,  0x05,  0x00,  0x01,  0xFF,  0xA0,  0x60,  0x05,  0x77,  0x04,  0x01,  0x23,  0xEA,  0x00,
10681   0x5D,  0x00,  0xFE,  0xC7,  0x00,  0x62,  0x00,  0x23,  0xEA,  0x00,  0x00,  0x63,  0x07,  0xA4,  0xF8,  0x05,
10682   0x03,  0x03,  0x02,  0xA0,  0x8E,  0x05,  0xF4,  0x85,  0x00,  0x33,  0x2D,  0x00,  0xC2,  0x88,  0x04,  0xA0,
10683   0xB8,  0x05,  0x80,  0x63,  0x00,  0x23,  0xDF,  0x00,  0x4A,  0x00,  0x06,  0x61,  0x00,  0xA2,  0xA4,  0x05,
10684   0x1D,  0x01,  0x06,  0xD6,  0x02,  0x23,  0x02,  0x41,  0x82,  0x01,  0x50,  0x00,  0x62,  0x97,  0x04,  0x85,
10685   0x04,  0x23,  0x02,  0x41,  0x82,  0x01,  0x04,  0x85,  0x08,  0xA0,  0xBE,  0x05,  0xF4,  0x85,  0x03,  0xA0,
10686   0xC4,  0x05,  0xF4,  0x85,  0x01,  0xA0,  0xCE,  0x05,  0x88,  0x00,  0x80,  0x63,  0xCC,  0x86,  0x07,  0xA0,
10687   0xEE,  0x05,  0x5F,  0x00,  0x00,  0x2B,  0xDF,  0x08,  0x00,  0xA2,  0xE6,  0x05,  0x80,  0x67,  0x80,  0x63,
10688   0x01,  0xA2,  0x7A,  0x06,  0x7C,  0x85,  0x06,  0x23,  0x68,  0x98,  0x48,  0x23,  0xF8,  0x88,  0x07,  0x23,
10689   0x80,  0x00,  0x06,  0x87,  0x80,  0x63,  0x7C,  0x85,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x4A,  0x00,
10690   0x06,  0x61,  0x00,  0xA2,  0x36,  0x06,  0x1D,  0x01,  0x16,  0xD4,  0xC0,  0x23,  0x07,  0x41,  0x83,  0x03,
10691   0x80,  0x63,  0x06,  0xA6,  0x1C,  0x06,  0x00,  0x33,  0x37,  0x00,  0xC2,  0x88,  0x1D,  0x01,  0x01,  0xD6,
10692   0x20,  0x23,  0x63,  0x60,  0x83,  0x03,  0x80,  0x63,  0x02,  0x23,  0xDF,  0x00,  0x07,  0xA6,  0x7C,  0x05,
10693   0xEF,  0x04,  0x6F,  0x00,  0x00,  0x63,  0x4B,  0x00,  0x06,  0x41,  0xCB,  0x00,  0x52,  0x00,  0x06,  0x61,
10694   0x00,  0xA2,  0x4E,  0x06,  0x1D,  0x01,  0x03,  0xCA,  0xC0,  0x23,  0x07,  0x41,  0x00,  0x63,  0x1D,  0x01,
10695   0x04,  0xCC,  0x00,  0x33,  0x00,  0x83,  0xC0,  0x20,  0x81,  0x62,  0x80,  0x23,  0x07,  0x41,  0x00,  0x63,
10696   0x80,  0x67,  0x08,  0x23,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x01,  0x23,  0xDF,  0x00,  0x06,  0xA6,
10697   0x84,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x80,  0x63,  0x00,  0x33,  0x00,  0x40,  0xC0,  0x20,
10698   0x81,  0x62,  0x00,  0x63,  0x00,  0x00,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,  0x94,  0x06,
10699   0x07,  0xA6,  0x7C,  0x05,  0x00,  0x00,  0x01,  0xA0,  0x14,  0x07,  0x00,  0x2B,  0x40,  0x0E,  0x80,  0x63,
10700   0x01,  0x00,  0x06,  0xA6,  0xAA,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x40,  0x0E,  0x80,  0x63,  0x00,  0x43,
10701   0x00,  0xA0,  0xA2,  0x06,  0x06,  0xA6,  0xBC,  0x06,  0x07,  0xA6,  0x7C,  0x05,  0x80,  0x67,  0x40,  0x0E,
10702   0x80,  0x63,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x23,  0xDF,  0x00,  0x00,  0x63,  0x07,  0xA6,  0xD6,  0x06,
10703   0x00,  0x33,  0x2A,  0x00,  0xC2,  0x88,  0x03,  0x03,  0x80,  0x63,  0x89,  0x00,  0x0A,  0x2B,  0x07,  0xA6,
10704   0xE8,  0x06,  0x00,  0x33,  0x29,  0x00,  0xC2,  0x88,  0x00,  0x43,  0x00,  0xA2,  0xF4,  0x06,  0xC0,  0x0E,
10705   0x80,  0x63,  0xDE,  0x86,  0xC0,  0x0E,  0x00,  0x33,  0x00,  0x80,  0xC0,  0x20,  0x81,  0x62,  0x04,  0x01,
10706   0x02,  0xDA,  0x80,  0x63,  0x7C,  0x85,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x8C,  0x06,  0x00,  0x33,
10707   0x2C,  0x00,  0xC2,  0x88,  0x0C,  0xA2,  0x2E,  0x07,  0xFE,  0x95,  0x83,  0x03,  0x80,  0x63,  0x06,  0xA6,
10708   0x2C,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0x00,  0x33,  0x3D,  0x00,  0xC2,  0x88,  0x00,  0x00,  0x80,  0x67,
10709   0x83,  0x03,  0x80,  0x63,  0x0C,  0xA0,  0x44,  0x07,  0x07,  0xA6,  0x7C,  0x05,  0xBF,  0x23,  0x04,  0x61,
10710   0x84,  0x01,  0xE6,  0x84,  0x00,  0x63,  0xF0,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x00,  0x01,  0xF2,  0x00,
10711   0x01,  0x05,  0x80,  0x01,  0x72,  0x04,  0x71,  0x00,  0x81,  0x01,  0x70,  0x04,  0x80,  0x05,  0x81,  0x05,
10712   0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x01,  0x01,  0xF1,  0x00,  0x70,  0x00,  0x81,  0x01,
10713   0x70,  0x04,  0x71,  0x00,  0x81,  0x01,  0x72,  0x00,  0x80,  0x01,  0x71,  0x04,  0x70,  0x00,  0x80,  0x01,
10714   0x70,  0x04,  0x00,  0x63,  0xF0,  0x04,  0xF2,  0x00,  0x72,  0x04,  0x00,  0x01,  0xF1,  0x00,  0x70,  0x00,
10715   0x80,  0x01,  0x70,  0x04,  0x71,  0x00,  0x80,  0x01,  0x72,  0x00,  0x81,  0x01,  0x71,  0x04,  0x70,  0x00,
10716   0x81,  0x01,  0x70,  0x04,  0x00,  0x63,  0x00,  0x23,  0xB3,  0x01,  0x83,  0x05,  0xA3,  0x01,  0xA2,  0x01,
10717   0xA1,  0x01,  0x01,  0x23,  0xA0,  0x01,  0x00,  0x01,  0xC8,  0x00,  0x03,  0xA1,  0xC4,  0x07,  0x00,  0x33,
10718   0x07,  0x00,  0xC2,  0x88,  0x80,  0x05,  0x81,  0x05,  0x04,  0x01,  0x11,  0xC8,  0x48,  0x00,  0xB0,  0x01,
10719   0xB1,  0x01,  0x08,  0x23,  0xB2,  0x01,  0x05,  0x01,  0x48,  0x04,  0x00,  0x43,  0x00,  0xA2,  0xE4,  0x07,
10720   0x00,  0x05,  0xDA,  0x87,  0x00,  0x01,  0xC8,  0x00,  0xFF,  0x23,  0x80,  0x01,  0x05,  0x05,  0x00,  0x63,
10721   0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x80,  0x43,  0x76,  0x08,  0x80,  0x02,
10722   0x77,  0x04,  0x00,  0x63,  0xF7,  0x04,  0x1A,  0x09,  0xF6,  0x08,  0x6E,  0x04,  0x00,  0x02,  0x00,  0xA0,
10723   0x14,  0x08,  0x16,  0x88,  0x00,  0x43,  0x76,  0x08,  0x80,  0x02,  0x77,  0x04,  0x00,  0x63,  0xF3,  0x04,
10724   0x00,  0x23,  0xF4,  0x00,  0x74,  0x00,  0x80,  0x43,  0xF4,  0x00,  0xCF,  0x40,  0x00,  0xA2,  0x44,  0x08,
10725   0x74,  0x04,  0x02,  0x01,  0xF7,  0xC9,  0xF6,  0xD9,  0x00,  0x01,  0x01,  0xA1,  0x24,  0x08,  0x04,  0x98,
10726   0x26,  0x95,  0x24,  0x88,  0x73,  0x04,  0x00,  0x63,  0xF3,  0x04,  0x75,  0x04,  0x5A,  0x88,  0x02,  0x01,
10727   0x04,  0xD8,  0x46,  0x97,  0x04,  0x98,  0x26,  0x95,  0x4A,  0x88,  0x75,  0x00,  0x00,  0xA3,  0x64,  0x08,
10728   0x00,  0x05,  0x4E,  0x88,  0x73,  0x04,  0x00,  0x63,  0x80,  0x7B,  0x80,  0x63,  0x06,  0xA6,  0x76,  0x08,
10729   0x00,  0x33,  0x3E,  0x00,  0xC2,  0x88,  0x80,  0x67,  0x83,  0x03,  0x80,  0x63,  0x00,  0x63,  0x38,  0x2B,
10730   0x9C,  0x88,  0x38,  0x2B,  0x92,  0x88,  0x32,  0x09,  0x31,  0x05,  0x92,  0x98,  0x05,  0x05,  0xB2,  0x09,
10731   0x00,  0x63,  0x00,  0x32,  0x00,  0x36,  0x00,  0x3A,  0x00,  0x3E,  0x00,  0x63,  0x80,  0x32,  0x80,  0x36,
10732   0x80,  0x3A,  0x80,  0x3E,  0xB4,  0x3D,  0x00,  0x63,  0x38,  0x2B,  0x40,  0x32,  0x40,  0x36,  0x40,  0x3A,
10733   0x40,  0x3E,  0x00,  0x63,  0x5A,  0x20,  0xC9,  0x40,  0x00,  0xA0,  0xB4,  0x08,  0x5D,  0x00,  0xFE,  0xC3,
10734   0x00,  0x63,  0x80,  0x73,  0xE6,  0x20,  0x02,  0x23,  0xE8,  0x00,  0x82,  0x73,  0xFF,  0xFD,  0x80,  0x73,
10735   0x13,  0x23,  0xF8,  0x88,  0x66,  0x20,  0xC0,  0x20,  0x04,  0x23,  0xA0,  0x01,  0xA1,  0x23,  0xA1,  0x01,
10736   0x81,  0x62,  0xE2,  0x88,  0x80,  0x73,  0x80,  0x77,  0x68,  0x00,  0x00,  0xA2,  0x80,  0x00,  0x03,  0xC2,
10737   0xF1,  0xC7,  0x41,  0x23,  0xF8,  0x88,  0x11,  0x23,  0xA1,  0x01,  0x04,  0x23,  0xA0,  0x01,  0xE6,  0x84,
10738 };
10739
10740 STATIC ushort _asc_mcode_size = sizeof(_asc_mcode_buf);
10741 STATIC ADV_DCNT _asc_mcode_chksum = 0x012C453FUL;
10742
10743 #define ASC_SYN_OFFSET_ONE_DISABLE_LIST  16
10744 STATIC uchar _syn_offset_one_disable_cmd[ASC_SYN_OFFSET_ONE_DISABLE_LIST] =
10745 {
10746     INQUIRY,
10747     REQUEST_SENSE,
10748     READ_CAPACITY,
10749     READ_TOC,
10750     MODE_SELECT,
10751     MODE_SENSE,
10752     MODE_SELECT_10,
10753     MODE_SENSE_10,
10754     0xFF,
10755     0xFF,
10756     0xFF,
10757     0xFF,
10758     0xFF,
10759     0xFF,
10760     0xFF,
10761     0xFF
10762 };
10763
10764 STATIC int
10765 AscExeScsiQueue(
10766                    ASC_DVC_VAR *asc_dvc,
10767                    ASC_SCSI_Q *scsiq
10768 )
10769 {
10770     PortAddr            iop_base;
10771     ulong               last_int_level;
10772     int                 sta;
10773     int                 n_q_required;
10774     int                 disable_syn_offset_one_fix;
10775     int                 i;
10776     ASC_PADDR           addr;
10777     ASC_EXE_CALLBACK    asc_exe_callback;
10778     ushort              sg_entry_cnt = 0;
10779     ushort              sg_entry_cnt_minus_one = 0;
10780     uchar               target_ix;
10781     uchar               tid_no;
10782     uchar               sdtr_data;
10783     uchar               extra_bytes;
10784     uchar               scsi_cmd;
10785     uchar               disable_cmd;
10786     ASC_SG_HEAD         *sg_head;
10787     ASC_DCNT            data_cnt;
10788
10789     iop_base = asc_dvc->iop_base;
10790     sg_head = scsiq->sg_head;
10791     asc_exe_callback = asc_dvc->exe_callback;
10792     if (asc_dvc->err_code != 0)
10793         return (ERR);
10794     if (scsiq == (ASC_SCSI_Q *) 0L) {
10795         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_SCSIQ_NULL_PTR);
10796         return (ERR);
10797     }
10798     scsiq->q1.q_no = 0;
10799     if ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES) == 0) {
10800         scsiq->q1.extra_bytes = 0;
10801     }
10802     sta = 0;
10803     target_ix = scsiq->q2.target_ix;
10804     tid_no = ASC_TIX_TO_TID(target_ix);
10805     n_q_required = 1;
10806     if (scsiq->cdbptr[0] == REQUEST_SENSE) {
10807         if ((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) {
10808             asc_dvc->sdtr_done &= ~scsiq->q1.target_id;
10809             sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
10810             AscMsgOutSDTR(asc_dvc,
10811                           asc_dvc->sdtr_period_tbl[(sdtr_data >> 4) &
10812                           (uchar) (asc_dvc->max_sdtr_index - 1)],
10813                           (uchar) (sdtr_data & (uchar) ASC_SYN_MAX_OFFSET));
10814             scsiq->q1.cntl |= (QC_MSG_OUT | QC_URGENT);
10815         }
10816     }
10817     last_int_level = DvcEnterCritical();
10818     if (asc_dvc->in_critical_cnt != 0) {
10819         DvcLeaveCritical(last_int_level);
10820         AscSetLibErrorCode(asc_dvc, ASCQ_ERR_CRITICAL_RE_ENTRY);
10821         return (ERR);
10822     }
10823     asc_dvc->in_critical_cnt++;
10824     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10825         if ((sg_entry_cnt = sg_head->entry_cnt) == 0) {
10826             asc_dvc->in_critical_cnt--;
10827             DvcLeaveCritical(last_int_level);
10828             return (ERR);
10829         }
10830 #if !CC_VERY_LONG_SG_LIST
10831         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10832         {
10833             asc_dvc->in_critical_cnt--;
10834             DvcLeaveCritical(last_int_level);
10835             return(ERR);
10836         }
10837 #endif /* !CC_VERY_LONG_SG_LIST */
10838         if (sg_entry_cnt == 1) {
10839             scsiq->q1.data_addr = (ADV_PADDR) sg_head->sg_list[0].addr;
10840             scsiq->q1.data_cnt = (ADV_DCNT) sg_head->sg_list[0].bytes;
10841             scsiq->q1.cntl &= ~(QC_SG_HEAD | QC_SG_SWAP_QUEUE);
10842         }
10843         sg_entry_cnt_minus_one = sg_entry_cnt - 1;
10844     }
10845     scsi_cmd = scsiq->cdbptr[0];
10846     disable_syn_offset_one_fix = FALSE;
10847     if ((asc_dvc->pci_fix_asyn_xfer & scsiq->q1.target_id) &&
10848         !(asc_dvc->pci_fix_asyn_xfer_always & scsiq->q1.target_id)) {
10849         if (scsiq->q1.cntl & QC_SG_HEAD) {
10850             data_cnt = 0;
10851             for (i = 0; i < sg_entry_cnt; i++) {
10852                 data_cnt += (ADV_DCNT) le32_to_cpu(sg_head->sg_list[i].bytes);
10853             }
10854         } else {
10855             data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10856         }
10857         if (data_cnt != 0UL) {
10858             if (data_cnt < 512UL) {
10859                 disable_syn_offset_one_fix = TRUE;
10860             } else {
10861                 for (i = 0; i < ASC_SYN_OFFSET_ONE_DISABLE_LIST; i++) {
10862                     disable_cmd = _syn_offset_one_disable_cmd[i];
10863                     if (disable_cmd == 0xFF) {
10864                         break;
10865                     }
10866                     if (scsi_cmd == disable_cmd) {
10867                         disable_syn_offset_one_fix = TRUE;
10868                         break;
10869                     }
10870                 }
10871             }
10872         }
10873     }
10874     if (disable_syn_offset_one_fix) {
10875         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG;
10876         scsiq->q2.tag_code |= (ASC_TAG_FLAG_DISABLE_ASYN_USE_SYN_FIX |
10877                                ASC_TAG_FLAG_DISABLE_DISCONNECT);
10878     } else {
10879         scsiq->q2.tag_code &= 0x27;
10880     }
10881     if ((scsiq->q1.cntl & QC_SG_HEAD) != 0) {
10882         if (asc_dvc->bug_fix_cntl) {
10883             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10884                 if ((scsi_cmd == READ_6) ||
10885                     (scsi_cmd == READ_10)) {
10886                     addr =
10887                         (ADV_PADDR) le32_to_cpu(
10888                             sg_head->sg_list[sg_entry_cnt_minus_one].addr) +
10889                         (ADV_DCNT) le32_to_cpu(
10890                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10891                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10892                     if ((extra_bytes != 0) &&
10893                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10894                          == 0)) {
10895                         scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10896                         scsiq->q1.extra_bytes = extra_bytes;
10897                         data_cnt = le32_to_cpu(
10898                             sg_head->sg_list[sg_entry_cnt_minus_one].bytes);
10899                         data_cnt -= (ASC_DCNT) extra_bytes;
10900                         sg_head->sg_list[sg_entry_cnt_minus_one].bytes =
10901                             cpu_to_le32(data_cnt);
10902                     }
10903                 }
10904             }
10905         }
10906         sg_head->entry_to_copy = sg_head->entry_cnt;
10907 #if CC_VERY_LONG_SG_LIST
10908         /*
10909          * Set the sg_entry_cnt to the maximum possible. The rest of
10910          * the SG elements will be copied when the RISC completes the
10911          * SG elements that fit and halts.
10912          */
10913         if (sg_entry_cnt > ASC_MAX_SG_LIST)
10914         {
10915              sg_entry_cnt = ASC_MAX_SG_LIST;
10916         }
10917 #endif /* CC_VERY_LONG_SG_LIST */
10918         n_q_required = AscSgListToQueue(sg_entry_cnt);
10919         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, n_q_required) >=
10920             (uint) n_q_required) || ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10921             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10922                                         n_q_required)) == 1) {
10923                 asc_dvc->in_critical_cnt--;
10924                 if (asc_exe_callback != 0) {
10925                     (*asc_exe_callback) (asc_dvc, scsiq);
10926                 }
10927                 DvcLeaveCritical(last_int_level);
10928                 return (sta);
10929             }
10930         }
10931     } else {
10932         if (asc_dvc->bug_fix_cntl) {
10933             if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_IF_NOT_DWB) {
10934                 if ((scsi_cmd == READ_6) ||
10935                     (scsi_cmd == READ_10)) {
10936                     addr = le32_to_cpu(scsiq->q1.data_addr) +
10937                         le32_to_cpu(scsiq->q1.data_cnt);
10938                     extra_bytes = (uchar) ((ushort) addr & 0x0003);
10939                     if ((extra_bytes != 0) &&
10940                         ((scsiq->q2.tag_code & ASC_TAG_FLAG_EXTRA_BYTES)
10941                           == 0)) {
10942                         data_cnt = le32_to_cpu(scsiq->q1.data_cnt);
10943                         if (((ushort) data_cnt & 0x01FF) == 0) {
10944                             scsiq->q2.tag_code |= ASC_TAG_FLAG_EXTRA_BYTES;
10945                             data_cnt -= (ASC_DCNT) extra_bytes;
10946                             scsiq->q1.data_cnt = cpu_to_le32(data_cnt);
10947                             scsiq->q1.extra_bytes = extra_bytes;
10948                         }
10949                     }
10950                 }
10951             }
10952         }
10953         n_q_required = 1;
10954         if ((AscGetNumOfFreeQueue(asc_dvc, target_ix, 1) >= 1) ||
10955             ((scsiq->q1.cntl & QC_URGENT) != 0)) {
10956             if ((sta = AscSendScsiQueue(asc_dvc, scsiq,
10957                                         n_q_required)) == 1) {
10958                 asc_dvc->in_critical_cnt--;
10959                 if (asc_exe_callback != 0) {
10960                     (*asc_exe_callback) (asc_dvc, scsiq);
10961                 }
10962                 DvcLeaveCritical(last_int_level);
10963                 return (sta);
10964             }
10965         }
10966     }
10967     asc_dvc->in_critical_cnt--;
10968     DvcLeaveCritical(last_int_level);
10969     return (sta);
10970 }
10971
10972 STATIC int
10973 AscSendScsiQueue(
10974                     ASC_DVC_VAR *asc_dvc,
10975                     ASC_SCSI_Q *scsiq,
10976                     uchar n_q_required
10977 )
10978 {
10979     PortAddr            iop_base;
10980     uchar               free_q_head;
10981     uchar               next_qp;
10982     uchar               tid_no;
10983     uchar               target_ix;
10984     int                 sta;
10985
10986     iop_base = asc_dvc->iop_base;
10987     target_ix = scsiq->q2.target_ix;
10988     tid_no = ASC_TIX_TO_TID(target_ix);
10989     sta = 0;
10990     free_q_head = (uchar) AscGetVarFreeQHead(iop_base);
10991     if (n_q_required > 1) {
10992         if ((next_qp = AscAllocMultipleFreeQueue(iop_base,
10993                                        free_q_head, (uchar) (n_q_required)))
10994             != (uchar) ASC_QLINK_END) {
10995             asc_dvc->last_q_shortage = 0;
10996             scsiq->sg_head->queue_cnt = n_q_required - 1;
10997             scsiq->q1.q_no = free_q_head;
10998             if ((sta = AscPutReadySgListQueue(asc_dvc, scsiq,
10999                                               free_q_head)) == 1) {
11000                 AscPutVarFreeQHead(iop_base, next_qp);
11001                 asc_dvc->cur_total_qng += (uchar) (n_q_required);
11002                 asc_dvc->cur_dvc_qng[tid_no]++;
11003             }
11004             return (sta);
11005         }
11006     } else if (n_q_required == 1) {
11007         if ((next_qp = AscAllocFreeQueue(iop_base,
11008                                          free_q_head)) != ASC_QLINK_END) {
11009             scsiq->q1.q_no = free_q_head;
11010             if ((sta = AscPutReadyQueue(asc_dvc, scsiq,
11011                                         free_q_head)) == 1) {
11012                 AscPutVarFreeQHead(iop_base, next_qp);
11013                 asc_dvc->cur_total_qng++;
11014                 asc_dvc->cur_dvc_qng[tid_no]++;
11015             }
11016             return (sta);
11017         }
11018     }
11019     return (sta);
11020 }
11021
11022 STATIC int
11023 AscSgListToQueue(
11024                     int sg_list
11025 )
11026 {
11027     int                 n_sg_list_qs;
11028
11029     n_sg_list_qs = ((sg_list - 1) / ASC_SG_LIST_PER_Q);
11030     if (((sg_list - 1) % ASC_SG_LIST_PER_Q) != 0)
11031         n_sg_list_qs++;
11032     return (n_sg_list_qs + 1);
11033 }
11034
11035
11036 STATIC uint
11037 AscGetNumOfFreeQueue(
11038                         ASC_DVC_VAR *asc_dvc,
11039                         uchar target_ix,
11040                         uchar n_qs
11041 )
11042 {
11043     uint                cur_used_qs;
11044     uint                cur_free_qs;
11045     ASC_SCSI_BIT_ID_TYPE target_id;
11046     uchar               tid_no;
11047
11048     target_id = ASC_TIX_TO_TARGET_ID(target_ix);
11049     tid_no = ASC_TIX_TO_TID(target_ix);
11050     if ((asc_dvc->unit_not_ready & target_id) ||
11051         (asc_dvc->queue_full_or_busy & target_id)) {
11052         return (0);
11053     }
11054     if (n_qs == 1) {
11055         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11056           (uint) asc_dvc->last_q_shortage +
11057           (uint) ASC_MIN_FREE_Q;
11058     } else {
11059         cur_used_qs = (uint) asc_dvc->cur_total_qng +
11060           (uint) ASC_MIN_FREE_Q;
11061     }
11062     if ((uint) (cur_used_qs + n_qs) <= (uint) asc_dvc->max_total_qng) {
11063         cur_free_qs = (uint) asc_dvc->max_total_qng - cur_used_qs;
11064         if (asc_dvc->cur_dvc_qng[tid_no] >=
11065             asc_dvc->max_dvc_qng[tid_no]) {
11066             return (0);
11067         }
11068         return (cur_free_qs);
11069     }
11070     if (n_qs > 1) {
11071         if ((n_qs > asc_dvc->last_q_shortage) && (n_qs <= (asc_dvc->max_total_qng - ASC_MIN_FREE_Q))) {
11072             asc_dvc->last_q_shortage = n_qs;
11073         }
11074     }
11075     return (0);
11076 }
11077
11078 STATIC int
11079 AscPutReadyQueue(
11080                     ASC_DVC_VAR *asc_dvc,
11081                     ASC_SCSI_Q *scsiq,
11082                     uchar q_no
11083 )
11084 {
11085     ushort              q_addr;
11086     uchar               tid_no;
11087     uchar               sdtr_data;
11088     uchar               syn_period_ix;
11089     uchar               syn_offset;
11090     PortAddr            iop_base;
11091
11092     iop_base = asc_dvc->iop_base;
11093     if (((asc_dvc->init_sdtr & scsiq->q1.target_id) != 0) &&
11094         ((asc_dvc->sdtr_done & scsiq->q1.target_id) == 0)) {
11095         tid_no = ASC_TIX_TO_TID(scsiq->q2.target_ix);
11096         sdtr_data = AscGetMCodeInitSDTRAtID(iop_base, tid_no);
11097         syn_period_ix = (sdtr_data >> 4) & (asc_dvc->max_sdtr_index - 1);
11098         syn_offset = sdtr_data & ASC_SYN_MAX_OFFSET;
11099         AscMsgOutSDTR(asc_dvc,
11100                       asc_dvc->sdtr_period_tbl[syn_period_ix],
11101                       syn_offset);
11102         scsiq->q1.cntl |= QC_MSG_OUT;
11103     }
11104     q_addr = ASC_QNO_TO_QADDR(q_no);
11105     if ((scsiq->q1.target_id & asc_dvc->use_tagged_qng) == 0) {
11106         scsiq->q2.tag_code &= ~MSG_SIMPLE_TAG ;
11107     }
11108     scsiq->q1.status = QS_FREE;
11109     AscMemWordCopyPtrToLram(iop_base,
11110                          q_addr + ASC_SCSIQ_CDB_BEG,
11111                          (uchar *) scsiq->cdbptr,
11112                          scsiq->q2.cdb_len >> 1);
11113
11114     DvcPutScsiQ(iop_base,
11115                 q_addr + ASC_SCSIQ_CPY_BEG,
11116                 (uchar *) &scsiq->q1.cntl,
11117                 ((sizeof(ASC_SCSIQ_1) + sizeof(ASC_SCSIQ_2)) / 2) - 1);
11118     AscWriteLramWord(iop_base,
11119                      (ushort) (q_addr + (ushort) ASC_SCSIQ_B_STATUS),
11120              (ushort) (((ushort) scsiq->q1.q_no << 8) | (ushort) QS_READY));
11121     return (1);
11122 }
11123
11124 STATIC int
11125 AscPutReadySgListQueue(
11126                           ASC_DVC_VAR *asc_dvc,
11127                           ASC_SCSI_Q *scsiq,
11128                           uchar q_no
11129 )
11130 {
11131     int                 sta;
11132     int                 i;
11133     ASC_SG_HEAD *sg_head;
11134     ASC_SG_LIST_Q       scsi_sg_q;
11135     ASC_DCNT            saved_data_addr;
11136     ASC_DCNT            saved_data_cnt;
11137     PortAddr            iop_base;
11138     ushort              sg_list_dwords;
11139     ushort              sg_index;
11140     ushort              sg_entry_cnt;
11141     ushort              q_addr;
11142     uchar               next_qp;
11143
11144     iop_base = asc_dvc->iop_base;
11145     sg_head = scsiq->sg_head;
11146     saved_data_addr = scsiq->q1.data_addr;
11147     saved_data_cnt = scsiq->q1.data_cnt;
11148     scsiq->q1.data_addr = (ASC_PADDR) sg_head->sg_list[0].addr;
11149     scsiq->q1.data_cnt = (ASC_DCNT) sg_head->sg_list[0].bytes;
11150 #if CC_VERY_LONG_SG_LIST
11151     /*
11152      * If sg_head->entry_cnt is greater than ASC_MAX_SG_LIST
11153      * then not all SG elements will fit in the allocated queues.
11154      * The rest of the SG elements will be copied when the RISC
11155      * completes the SG elements that fit and halts.
11156      */
11157     if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11158     {
11159          /*
11160           * Set sg_entry_cnt to be the number of SG elements that
11161           * will fit in the allocated SG queues. It is minus 1, because
11162           * the first SG element is handled above. ASC_MAX_SG_LIST is
11163           * already inflated by 1 to account for this. For example it
11164           * may be 50 which is 1 + 7 queues * 7 SG elements.
11165           */
11166          sg_entry_cnt = ASC_MAX_SG_LIST - 1;
11167
11168          /*
11169           * Keep track of remaining number of SG elements that will
11170           * need to be handled from a_isr.c.
11171           */
11172          scsiq->remain_sg_entry_cnt = sg_head->entry_cnt - ASC_MAX_SG_LIST;
11173     } else
11174     {
11175 #endif /* CC_VERY_LONG_SG_LIST */
11176          /*
11177           * Set sg_entry_cnt to be the number of SG elements that
11178           * will fit in the allocated SG queues. It is minus 1, because
11179           * the first SG element is handled above.
11180           */
11181          sg_entry_cnt = sg_head->entry_cnt - 1;
11182 #if CC_VERY_LONG_SG_LIST
11183     }
11184 #endif /* CC_VERY_LONG_SG_LIST */
11185     if (sg_entry_cnt != 0) {
11186         scsiq->q1.cntl |= QC_SG_HEAD;
11187         q_addr = ASC_QNO_TO_QADDR(q_no);
11188         sg_index = 1;
11189         scsiq->q1.sg_queue_cnt = sg_head->queue_cnt;
11190         scsi_sg_q.sg_head_qp = q_no;
11191         scsi_sg_q.cntl = QCSG_SG_XFER_LIST;
11192         for (i = 0; i < sg_head->queue_cnt; i++) {
11193             scsi_sg_q.seq_no = i + 1;
11194             if (sg_entry_cnt > ASC_SG_LIST_PER_Q) {
11195                 sg_list_dwords = (uchar) (ASC_SG_LIST_PER_Q * 2);
11196                 sg_entry_cnt -= ASC_SG_LIST_PER_Q;
11197                 if (i == 0) {
11198                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q;
11199                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q;
11200                 } else {
11201                     scsi_sg_q.sg_list_cnt = ASC_SG_LIST_PER_Q - 1;
11202                     scsi_sg_q.sg_cur_list_cnt = ASC_SG_LIST_PER_Q - 1;
11203                 }
11204             } else {
11205 #if CC_VERY_LONG_SG_LIST
11206                 /*
11207                  * This is the last SG queue in the list of
11208                  * allocated SG queues. If there are more
11209                  * SG elements than will fit in the allocated
11210                  * queues, then set the QCSG_SG_XFER_MORE flag.
11211                  */
11212                 if (sg_head->entry_cnt > ASC_MAX_SG_LIST)
11213                 {
11214                     scsi_sg_q.cntl |= QCSG_SG_XFER_MORE;
11215                 } else
11216                 {
11217 #endif /* CC_VERY_LONG_SG_LIST */
11218                     scsi_sg_q.cntl |= QCSG_SG_XFER_END;
11219 #if CC_VERY_LONG_SG_LIST
11220                 }
11221 #endif /* CC_VERY_LONG_SG_LIST */
11222                 sg_list_dwords = sg_entry_cnt << 1;
11223                 if (i == 0) {
11224                     scsi_sg_q.sg_list_cnt = sg_entry_cnt;
11225                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt;
11226                 } else {
11227                     scsi_sg_q.sg_list_cnt = sg_entry_cnt - 1;
11228                     scsi_sg_q.sg_cur_list_cnt = sg_entry_cnt - 1;
11229                 }
11230                 sg_entry_cnt = 0;
11231             }
11232             next_qp = AscReadLramByte(iop_base,
11233                                       (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11234             scsi_sg_q.q_no = next_qp;
11235             q_addr = ASC_QNO_TO_QADDR(next_qp);
11236             AscMemWordCopyPtrToLram(iop_base,
11237                                 q_addr + ASC_SCSIQ_SGHD_CPY_BEG,
11238                                 (uchar *) &scsi_sg_q,
11239                                 sizeof(ASC_SG_LIST_Q) >> 1);
11240             AscMemDWordCopyPtrToLram(iop_base,
11241                                 q_addr + ASC_SGQ_LIST_BEG,
11242                                 (uchar *) &sg_head->sg_list[sg_index],
11243                                 sg_list_dwords);
11244             sg_index += ASC_SG_LIST_PER_Q;
11245             scsiq->next_sg_index = sg_index;
11246         }
11247     } else {
11248         scsiq->q1.cntl &= ~QC_SG_HEAD;
11249     }
11250     sta = AscPutReadyQueue(asc_dvc, scsiq, q_no);
11251     scsiq->q1.data_addr = saved_data_addr;
11252     scsiq->q1.data_cnt = saved_data_cnt;
11253     return (sta);
11254 }
11255
11256 STATIC int
11257 AscSetRunChipSynRegAtID(
11258                            PortAddr iop_base,
11259                            uchar tid_no,
11260                            uchar sdtr_data
11261 )
11262 {
11263     int                 sta = FALSE;
11264
11265     if (AscHostReqRiscHalt(iop_base)) {
11266         sta = AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11267         AscStartChip(iop_base);
11268         return (sta);
11269     }
11270     return (sta);
11271 }
11272
11273 STATIC int
11274 AscSetChipSynRegAtID(
11275                         PortAddr iop_base,
11276                         uchar id,
11277                         uchar sdtr_data
11278 )
11279 {
11280     ASC_SCSI_BIT_ID_TYPE org_id;
11281     int                 i;
11282     int                 sta = TRUE;
11283
11284     AscSetBank(iop_base, 1);
11285     org_id = AscReadChipDvcID(iop_base);
11286     for (i = 0; i <= ASC_MAX_TID; i++) {
11287         if (org_id == (0x01 << i))
11288             break;
11289     }
11290     org_id = (ASC_SCSI_BIT_ID_TYPE) i;
11291     AscWriteChipDvcID(iop_base, id);
11292     if (AscReadChipDvcID(iop_base) == (0x01 << id)) {
11293         AscSetBank(iop_base, 0);
11294         AscSetChipSyn(iop_base, sdtr_data);
11295         if (AscGetChipSyn(iop_base) != sdtr_data) {
11296             sta = FALSE;
11297         }
11298     } else {
11299         sta = FALSE;
11300     }
11301     AscSetBank(iop_base, 1);
11302     AscWriteChipDvcID(iop_base, org_id);
11303     AscSetBank(iop_base, 0);
11304     return (sta);
11305 }
11306
11307 STATIC ushort
11308 AscInitLram(
11309                ASC_DVC_VAR *asc_dvc
11310 )
11311 {
11312     uchar               i;
11313     ushort              s_addr;
11314     PortAddr            iop_base;
11315     ushort              warn_code;
11316
11317     iop_base = asc_dvc->iop_base;
11318     warn_code = 0;
11319     AscMemWordSetLram(iop_base, ASC_QADR_BEG, 0,
11320                (ushort) (((int) (asc_dvc->max_total_qng + 2 + 1) * 64) >> 1)
11321 );
11322     i = ASC_MIN_ACTIVE_QNO;
11323     s_addr = ASC_QADR_BEG + ASC_QBLK_SIZE;
11324     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11325                      (uchar) (i + 1));
11326     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11327                      (uchar) (asc_dvc->max_total_qng));
11328     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11329                      (uchar) i);
11330     i++;
11331     s_addr += ASC_QBLK_SIZE;
11332     for (; i < asc_dvc->max_total_qng; i++, s_addr += ASC_QBLK_SIZE) {
11333         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11334                          (uchar) (i + 1));
11335         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11336                          (uchar) (i - 1));
11337         AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11338                          (uchar) i);
11339     }
11340     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_FWD),
11341                      (uchar) ASC_QLINK_END);
11342     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_BWD),
11343                      (uchar) (asc_dvc->max_total_qng - 1));
11344     AscWriteLramByte(iop_base, (ushort) (s_addr + ASC_SCSIQ_B_QNO),
11345                      (uchar) asc_dvc->max_total_qng);
11346     i++;
11347     s_addr += ASC_QBLK_SIZE;
11348     for (; i <= (uchar) (asc_dvc->max_total_qng + 3);
11349          i++, s_addr += ASC_QBLK_SIZE) {
11350         AscWriteLramByte(iop_base,
11351                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_FWD), i);
11352         AscWriteLramByte(iop_base,
11353                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_BWD), i);
11354         AscWriteLramByte(iop_base,
11355                          (ushort) (s_addr + (ushort) ASC_SCSIQ_B_QNO), i);
11356     }
11357     return (warn_code);
11358 }
11359
11360 STATIC ushort
11361 AscInitQLinkVar(
11362                    ASC_DVC_VAR *asc_dvc
11363 )
11364 {
11365     PortAddr            iop_base;
11366     int                 i;
11367     ushort              lram_addr;
11368
11369     iop_base = asc_dvc->iop_base;
11370     AscPutRiscVarFreeQHead(iop_base, 1);
11371     AscPutRiscVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11372     AscPutVarFreeQHead(iop_base, 1);
11373     AscPutVarDoneQTail(iop_base, asc_dvc->max_total_qng);
11374     AscWriteLramByte(iop_base, ASCV_BUSY_QHEAD_B,
11375                      (uchar) ((int) asc_dvc->max_total_qng + 1));
11376     AscWriteLramByte(iop_base, ASCV_DISC1_QHEAD_B,
11377                      (uchar) ((int) asc_dvc->max_total_qng + 2));
11378     AscWriteLramByte(iop_base, (ushort) ASCV_TOTAL_READY_Q_B,
11379                      asc_dvc->max_total_qng);
11380     AscWriteLramWord(iop_base, ASCV_ASCDVC_ERR_CODE_W, 0);
11381     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0);
11382     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, 0);
11383     AscWriteLramByte(iop_base, ASCV_SCSIBUSY_B, 0);
11384     AscWriteLramByte(iop_base, ASCV_WTM_FLAG_B, 0);
11385     AscPutQDoneInProgress(iop_base, 0);
11386     lram_addr = ASC_QADR_BEG;
11387     for (i = 0; i < 32; i++, lram_addr += 2) {
11388         AscWriteLramWord(iop_base, lram_addr, 0);
11389     }
11390     return (0);
11391 }
11392
11393 STATIC int
11394 AscSetLibErrorCode(
11395                       ASC_DVC_VAR *asc_dvc,
11396                       ushort err_code
11397 )
11398 {
11399     if (asc_dvc->err_code == 0) {
11400         asc_dvc->err_code = err_code;
11401         AscWriteLramWord(asc_dvc->iop_base, ASCV_ASCDVC_ERR_CODE_W,
11402                          err_code);
11403     }
11404     return (err_code);
11405 }
11406
11407
11408 STATIC uchar
11409 AscMsgOutSDTR(
11410                  ASC_DVC_VAR *asc_dvc,
11411                  uchar sdtr_period,
11412                  uchar sdtr_offset
11413 )
11414 {
11415     EXT_MSG             sdtr_buf;
11416     uchar               sdtr_period_index;
11417     PortAddr            iop_base;
11418
11419     iop_base = asc_dvc->iop_base;
11420     sdtr_buf.msg_type = MS_EXTEND;
11421     sdtr_buf.msg_len = MS_SDTR_LEN;
11422     sdtr_buf.msg_req = MS_SDTR_CODE;
11423     sdtr_buf.xfer_period = sdtr_period;
11424     sdtr_offset &= ASC_SYN_MAX_OFFSET;
11425     sdtr_buf.req_ack_offset = sdtr_offset;
11426     if ((sdtr_period_index =
11427          AscGetSynPeriodIndex(asc_dvc, sdtr_period)) <=
11428         asc_dvc->max_sdtr_index) {
11429         AscMemWordCopyPtrToLram(iop_base,
11430                              ASCV_MSGOUT_BEG,
11431                              (uchar *) &sdtr_buf,
11432                              sizeof (EXT_MSG) >> 1);
11433         return ((sdtr_period_index << 4) | sdtr_offset);
11434     } else {
11435
11436         sdtr_buf.req_ack_offset = 0;
11437         AscMemWordCopyPtrToLram(iop_base,
11438                              ASCV_MSGOUT_BEG,
11439                              (uchar *) &sdtr_buf,
11440                              sizeof (EXT_MSG) >> 1);
11441         return (0);
11442     }
11443 }
11444
11445 STATIC uchar
11446 AscCalSDTRData(
11447                   ASC_DVC_VAR *asc_dvc,
11448                   uchar sdtr_period,
11449                   uchar syn_offset
11450 )
11451 {
11452     uchar               byte;
11453     uchar               sdtr_period_ix;
11454
11455     sdtr_period_ix = AscGetSynPeriodIndex(asc_dvc, sdtr_period);
11456     if (
11457            (sdtr_period_ix > asc_dvc->max_sdtr_index)
11458 ) {
11459         return (0xFF);
11460     }
11461     byte = (sdtr_period_ix << 4) | (syn_offset & ASC_SYN_MAX_OFFSET);
11462     return (byte);
11463 }
11464
11465 STATIC void
11466 AscSetChipSDTR(
11467                   PortAddr iop_base,
11468                   uchar sdtr_data,
11469                   uchar tid_no
11470 )
11471 {
11472     AscSetChipSynRegAtID(iop_base, tid_no, sdtr_data);
11473     AscPutMCodeSDTRDoneAtID(iop_base, tid_no, sdtr_data);
11474     return;
11475 }
11476
11477 STATIC uchar
11478 AscGetSynPeriodIndex(
11479                         ASC_DVC_VAR *asc_dvc,
11480                         uchar syn_time
11481 )
11482 {
11483     uchar             *period_table;
11484     int                 max_index;
11485     int                 min_index;
11486     int                 i;
11487
11488     period_table = asc_dvc->sdtr_period_tbl;
11489     max_index = (int) asc_dvc->max_sdtr_index;
11490     min_index = (int)asc_dvc->host_init_sdtr_index;
11491     if ((syn_time <= period_table[max_index])) {
11492         for (i = min_index; i < (max_index - 1); i++) {
11493             if (syn_time <= period_table[i]) {
11494                 return ((uchar) i);
11495             }
11496         }
11497         return ((uchar) max_index);
11498     } else {
11499         return ((uchar) (max_index + 1));
11500     }
11501 }
11502
11503 STATIC uchar
11504 AscAllocFreeQueue(
11505                      PortAddr iop_base,
11506                      uchar free_q_head
11507 )
11508 {
11509     ushort              q_addr;
11510     uchar               next_qp;
11511     uchar               q_status;
11512
11513     q_addr = ASC_QNO_TO_QADDR(free_q_head);
11514     q_status = (uchar) AscReadLramByte(iop_base,
11515                                     (ushort) (q_addr + ASC_SCSIQ_B_STATUS));
11516     next_qp = AscReadLramByte(iop_base,
11517                               (ushort) (q_addr + ASC_SCSIQ_B_FWD));
11518     if (((q_status & QS_READY) == 0) && (next_qp != ASC_QLINK_END)) {
11519         return (next_qp);
11520     }
11521     return (ASC_QLINK_END);
11522 }
11523
11524 STATIC uchar
11525 AscAllocMultipleFreeQueue(
11526                              PortAddr iop_base,
11527                              uchar free_q_head,
11528                              uchar n_free_q
11529 )
11530 {
11531     uchar               i;
11532
11533     for (i = 0; i < n_free_q; i++) {
11534         if ((free_q_head = AscAllocFreeQueue(iop_base, free_q_head))
11535             == ASC_QLINK_END) {
11536             return (ASC_QLINK_END);
11537         }
11538     }
11539     return (free_q_head);
11540 }
11541
11542 STATIC int
11543 AscHostReqRiscHalt(
11544                       PortAddr iop_base
11545 )
11546 {
11547     int                 count = 0;
11548     int                 sta = 0;
11549     uchar               saved_stop_code;
11550
11551     if (AscIsChipHalted(iop_base))
11552         return (1);
11553     saved_stop_code = AscReadLramByte(iop_base, ASCV_STOP_CODE_B);
11554     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11555                      ASC_STOP_HOST_REQ_RISC_HALT | ASC_STOP_REQ_RISC_STOP
11556 );
11557     do {
11558         if (AscIsChipHalted(iop_base)) {
11559             sta = 1;
11560             break;
11561         }
11562         DvcSleepMilliSecond(100);
11563     } while (count++ < 20);
11564     AscWriteLramByte(iop_base, ASCV_STOP_CODE_B, saved_stop_code);
11565     return (sta);
11566 }
11567
11568 STATIC int
11569 AscStopQueueExe(
11570                    PortAddr iop_base
11571 )
11572 {
11573     int                 count = 0;
11574
11575     if (AscReadLramByte(iop_base, ASCV_STOP_CODE_B) == 0) {
11576         AscWriteLramByte(iop_base, ASCV_STOP_CODE_B,
11577                          ASC_STOP_REQ_RISC_STOP);
11578         do {
11579             if (
11580                    AscReadLramByte(iop_base, ASCV_STOP_CODE_B) &
11581                    ASC_STOP_ACK_RISC_STOP) {
11582                 return (1);
11583             }
11584             DvcSleepMilliSecond(100);
11585         } while (count++ < 20);
11586     }
11587     return (0);
11588 }
11589
11590 STATIC void
11591 DvcDelayMicroSecond(ADV_DVC_VAR *asc_dvc, ushort micro_sec)
11592 {
11593     udelay(micro_sec);
11594 }
11595
11596 STATIC void
11597 DvcDelayNanoSecond(ASC_DVC_VAR *asc_dvc, ASC_DCNT nano_sec)
11598 {
11599     udelay((nano_sec + 999)/1000);
11600 }
11601
11602 #ifdef CONFIG_ISA
11603 STATIC ASC_DCNT __init
11604 AscGetEisaProductID(
11605                        PortAddr iop_base)
11606 {
11607     PortAddr            eisa_iop;
11608     ushort              product_id_high, product_id_low;
11609     ASC_DCNT            product_id;
11610
11611     eisa_iop = ASC_GET_EISA_SLOT(iop_base) | ASC_EISA_PID_IOP_MASK;
11612     product_id_low = inpw(eisa_iop);
11613     product_id_high = inpw(eisa_iop + 2);
11614     product_id = ((ASC_DCNT) product_id_high << 16) |
11615         (ASC_DCNT) product_id_low;
11616     return (product_id);
11617 }
11618
11619 STATIC PortAddr __init
11620 AscSearchIOPortAddrEISA(
11621                            PortAddr iop_base)
11622 {
11623     ASC_DCNT            eisa_product_id;
11624
11625     if (iop_base == 0) {
11626         iop_base = ASC_EISA_MIN_IOP_ADDR;
11627     } else {
11628         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11629             return (0);
11630         if ((iop_base & 0x0050) == 0x0050) {
11631             iop_base += ASC_EISA_BIG_IOP_GAP;
11632         } else {
11633             iop_base += ASC_EISA_SMALL_IOP_GAP;
11634         }
11635     }
11636     while (iop_base <= ASC_EISA_MAX_IOP_ADDR) {
11637         eisa_product_id = AscGetEisaProductID(iop_base);
11638         if ((eisa_product_id == ASC_EISA_ID_740) ||
11639             (eisa_product_id == ASC_EISA_ID_750)) {
11640             if (AscFindSignature(iop_base)) {
11641                 inpw(iop_base + 4);
11642                 return (iop_base);
11643             }
11644         }
11645         if (iop_base == ASC_EISA_MAX_IOP_ADDR)
11646             return (0);
11647         if ((iop_base & 0x0050) == 0x0050) {
11648             iop_base += ASC_EISA_BIG_IOP_GAP;
11649         } else {
11650             iop_base += ASC_EISA_SMALL_IOP_GAP;
11651         }
11652     }
11653     return (0);
11654 }
11655 #endif /* CONFIG_ISA */
11656
11657 STATIC int
11658 AscStartChip(
11659                 PortAddr iop_base
11660 )
11661 {
11662     AscSetChipControl(iop_base, 0);
11663     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11664         return (0);
11665     }
11666     return (1);
11667 }
11668
11669 STATIC int
11670 AscStopChip(
11671                PortAddr iop_base
11672 )
11673 {
11674     uchar               cc_val;
11675
11676     cc_val = AscGetChipControl(iop_base) & (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG));
11677     AscSetChipControl(iop_base, (uchar) (cc_val | CC_HALT));
11678     AscSetChipIH(iop_base, INS_HALT);
11679     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11680     if ((AscGetChipStatus(iop_base) & CSW_HALTED) == 0) {
11681         return (0);
11682     }
11683     return (1);
11684 }
11685
11686 STATIC int
11687 AscIsChipHalted(
11688                    PortAddr iop_base
11689 )
11690 {
11691     if ((AscGetChipStatus(iop_base) & CSW_HALTED) != 0) {
11692         if ((AscGetChipControl(iop_base) & CC_HALT) != 0) {
11693             return (1);
11694         }
11695     }
11696     return (0);
11697 }
11698
11699 STATIC void
11700 AscSetChipIH(
11701                 PortAddr iop_base,
11702                 ushort ins_code
11703 )
11704 {
11705     AscSetBank(iop_base, 1);
11706     AscWriteChipIH(iop_base, ins_code);
11707     AscSetBank(iop_base, 0);
11708     return;
11709 }
11710
11711 STATIC void
11712 AscAckInterrupt(
11713                    PortAddr iop_base
11714 )
11715 {
11716     uchar               host_flag;
11717     uchar               risc_flag;
11718     ushort              loop;
11719
11720     loop = 0;
11721     do {
11722         risc_flag = AscReadLramByte(iop_base, ASCV_RISC_FLAG_B);
11723         if (loop++ > 0x7FFF) {
11724             break;
11725         }
11726     } while ((risc_flag & ASC_RISC_FLAG_GEN_INT) != 0);
11727     host_flag = AscReadLramByte(iop_base, ASCV_HOST_FLAG_B) & (~ASC_HOST_FLAG_ACK_INT);
11728     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B,
11729                      (uchar) (host_flag | ASC_HOST_FLAG_ACK_INT));
11730     AscSetChipStatus(iop_base, CIW_INT_ACK);
11731     loop = 0;
11732     while (AscGetChipStatus(iop_base) & CSW_INT_PENDING) {
11733         AscSetChipStatus(iop_base, CIW_INT_ACK);
11734         if (loop++ > 3) {
11735             break;
11736         }
11737     }
11738     AscWriteLramByte(iop_base, ASCV_HOST_FLAG_B, host_flag);
11739     return;
11740 }
11741
11742 STATIC void
11743 AscDisableInterrupt(
11744                        PortAddr iop_base
11745 )
11746 {
11747     ushort              cfg;
11748
11749     cfg = AscGetChipCfgLsw(iop_base);
11750     AscSetChipCfgLsw(iop_base, cfg & (~ASC_CFG0_HOST_INT_ON));
11751     return;
11752 }
11753
11754 STATIC void
11755 AscEnableInterrupt(
11756                       PortAddr iop_base
11757 )
11758 {
11759     ushort              cfg;
11760
11761     cfg = AscGetChipCfgLsw(iop_base);
11762     AscSetChipCfgLsw(iop_base, cfg | ASC_CFG0_HOST_INT_ON);
11763     return;
11764 }
11765
11766
11767
11768 STATIC void
11769 AscSetBank(
11770               PortAddr iop_base,
11771               uchar bank
11772 )
11773 {
11774     uchar               val;
11775
11776     val = AscGetChipControl(iop_base) &
11777       (~(CC_SINGLE_STEP | CC_TEST | CC_DIAG | CC_SCSI_RESET | CC_CHIP_RESET));
11778     if (bank == 1) {
11779         val |= CC_BANK_ONE;
11780     } else if (bank == 2) {
11781         val |= CC_DIAG | CC_BANK_ONE;
11782     } else {
11783         val &= ~CC_BANK_ONE;
11784     }
11785     AscSetChipControl(iop_base, val);
11786     return;
11787 }
11788
11789 STATIC int
11790 AscResetChipAndScsiBus(
11791                           ASC_DVC_VAR *asc_dvc
11792 )
11793 {
11794     PortAddr    iop_base;
11795     int         i = 10;
11796
11797     iop_base = asc_dvc->iop_base;
11798     while ((AscGetChipStatus(iop_base) & CSW_SCSI_RESET_ACTIVE) && (i-- > 0))
11799     {
11800           DvcSleepMilliSecond(100);
11801     }
11802     AscStopChip(iop_base);
11803     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_SCSI_RESET | CC_HALT);
11804     DvcDelayNanoSecond(asc_dvc, 60000);
11805     AscSetChipIH(iop_base, INS_RFLAG_WTM);
11806     AscSetChipIH(iop_base, INS_HALT);
11807     AscSetChipControl(iop_base, CC_CHIP_RESET | CC_HALT);
11808     AscSetChipControl(iop_base, CC_HALT);
11809     DvcSleepMilliSecond(200);
11810     AscSetChipStatus(iop_base, CIW_CLR_SCSI_RESET_INT);
11811     AscSetChipStatus(iop_base, 0);
11812     return (AscIsChipHalted(iop_base));
11813 }
11814
11815 STATIC ASC_DCNT __init
11816 AscGetMaxDmaCount(
11817                      ushort bus_type)
11818 {
11819     if (bus_type & ASC_IS_ISA)
11820         return (ASC_MAX_ISA_DMA_COUNT);
11821     else if (bus_type & (ASC_IS_EISA | ASC_IS_VL))
11822         return (ASC_MAX_VL_DMA_COUNT);
11823     return (ASC_MAX_PCI_DMA_COUNT);
11824 }
11825
11826 #ifdef CONFIG_ISA
11827 STATIC ushort __init
11828 AscGetIsaDmaChannel(
11829                        PortAddr iop_base)
11830 {
11831     ushort              channel;
11832
11833     channel = AscGetChipCfgLsw(iop_base) & 0x0003;
11834     if (channel == 0x03)
11835         return (0);
11836     else if (channel == 0x00)
11837         return (7);
11838     return (channel + 4);
11839 }
11840
11841 STATIC ushort __init
11842 AscSetIsaDmaChannel(
11843                        PortAddr iop_base,
11844                        ushort dma_channel)
11845 {
11846     ushort              cfg_lsw;
11847     uchar               value;
11848
11849     if ((dma_channel >= 5) && (dma_channel <= 7)) {
11850         if (dma_channel == 7)
11851             value = 0x00;
11852         else
11853             value = dma_channel - 4;
11854         cfg_lsw = AscGetChipCfgLsw(iop_base) & 0xFFFC;
11855         cfg_lsw |= value;
11856         AscSetChipCfgLsw(iop_base, cfg_lsw);
11857         return (AscGetIsaDmaChannel(iop_base));
11858     }
11859     return (0);
11860 }
11861
11862 STATIC uchar __init
11863 AscSetIsaDmaSpeed(
11864                      PortAddr iop_base,
11865                      uchar speed_value)
11866 {
11867     speed_value &= 0x07;
11868     AscSetBank(iop_base, 1);
11869     AscWriteChipDmaSpeed(iop_base, speed_value);
11870     AscSetBank(iop_base, 0);
11871     return (AscGetIsaDmaSpeed(iop_base));
11872 }
11873
11874 STATIC uchar __init
11875 AscGetIsaDmaSpeed(
11876                      PortAddr iop_base
11877 )
11878 {
11879     uchar               speed_value;
11880
11881     AscSetBank(iop_base, 1);
11882     speed_value = AscReadChipDmaSpeed(iop_base);
11883     speed_value &= 0x07;
11884     AscSetBank(iop_base, 0);
11885     return (speed_value);
11886 }
11887 #endif /* CONFIG_ISA */
11888
11889 STATIC ushort __init
11890 AscReadPCIConfigWord(
11891     ASC_DVC_VAR *asc_dvc,
11892     ushort pci_config_offset)
11893 {
11894     uchar       lsb, msb;
11895
11896     lsb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset);
11897     msb = DvcReadPCIConfigByte(asc_dvc, pci_config_offset + 1);
11898     return ((ushort) ((msb << 8) | lsb));
11899 }
11900
11901 STATIC ushort __init
11902 AscInitGetConfig(
11903         ASC_DVC_VAR *asc_dvc
11904 )
11905 {
11906     ushort              warn_code;
11907     PortAddr            iop_base;
11908     ushort              PCIDeviceID;
11909     ushort              PCIVendorID;
11910     uchar               PCIRevisionID;
11911     uchar               prevCmdRegBits;
11912
11913     warn_code = 0;
11914     iop_base = asc_dvc->iop_base;
11915     asc_dvc->init_state = ASC_INIT_STATE_BEG_GET_CFG;
11916     if (asc_dvc->err_code != 0) {
11917         return (UW_ERR);
11918     }
11919     if (asc_dvc->bus_type == ASC_IS_PCI) {
11920         PCIVendorID = AscReadPCIConfigWord(asc_dvc,
11921                                     AscPCIConfigVendorIDRegister);
11922
11923         PCIDeviceID = AscReadPCIConfigWord(asc_dvc,
11924                                     AscPCIConfigDeviceIDRegister);
11925
11926         PCIRevisionID = DvcReadPCIConfigByte(asc_dvc,
11927                                     AscPCIConfigRevisionIDRegister);
11928
11929         if (PCIVendorID != ASC_PCI_VENDORID) {
11930             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11931         }
11932         prevCmdRegBits = DvcReadPCIConfigByte(asc_dvc,
11933                                     AscPCIConfigCommandRegister);
11934
11935         if ((prevCmdRegBits & AscPCICmdRegBits_IOMemBusMaster) !=
11936             AscPCICmdRegBits_IOMemBusMaster) {
11937             DvcWritePCIConfigByte(asc_dvc,
11938                             AscPCIConfigCommandRegister,
11939                             (prevCmdRegBits |
11940                              AscPCICmdRegBits_IOMemBusMaster));
11941
11942             if ((DvcReadPCIConfigByte(asc_dvc,
11943                                 AscPCIConfigCommandRegister)
11944                  & AscPCICmdRegBits_IOMemBusMaster)
11945                 != AscPCICmdRegBits_IOMemBusMaster) {
11946                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11947             }
11948         }
11949         if ((PCIDeviceID == ASC_PCI_DEVICEID_1200A) ||
11950             (PCIDeviceID == ASC_PCI_DEVICEID_1200B)) {
11951             DvcWritePCIConfigByte(asc_dvc,
11952                             AscPCIConfigLatencyTimer, 0x00);
11953             if (DvcReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer)
11954                 != 0x00) {
11955                 warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11956             }
11957         } else if (PCIDeviceID == ASC_PCI_DEVICEID_ULTRA) {
11958             if (DvcReadPCIConfigByte(asc_dvc,
11959                                 AscPCIConfigLatencyTimer) < 0x20) {
11960                 DvcWritePCIConfigByte(asc_dvc,
11961                                     AscPCIConfigLatencyTimer, 0x20);
11962
11963                 if (DvcReadPCIConfigByte(asc_dvc,
11964                                     AscPCIConfigLatencyTimer) < 0x20) {
11965                     warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
11966                 }
11967             }
11968         }
11969     }
11970
11971     if (AscFindSignature(iop_base)) {
11972         warn_code |= AscInitAscDvcVar(asc_dvc);
11973         warn_code |= AscInitFromEEP(asc_dvc);
11974         asc_dvc->init_state |= ASC_INIT_STATE_END_GET_CFG;
11975         if (asc_dvc->scsi_reset_wait > ASC_MAX_SCSI_RESET_WAIT) {
11976             asc_dvc->scsi_reset_wait = ASC_MAX_SCSI_RESET_WAIT;
11977         }
11978     } else {
11979         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11980     }
11981     return(warn_code);
11982 }
11983
11984 STATIC ushort __init
11985 AscInitSetConfig(
11986                     ASC_DVC_VAR *asc_dvc
11987 )
11988 {
11989     ushort              warn_code = 0;
11990
11991     asc_dvc->init_state |= ASC_INIT_STATE_BEG_SET_CFG;
11992     if (asc_dvc->err_code != 0)
11993         return (UW_ERR);
11994     if (AscFindSignature(asc_dvc->iop_base)) {
11995         warn_code |= AscInitFromAscDvcVar(asc_dvc);
11996         asc_dvc->init_state |= ASC_INIT_STATE_END_SET_CFG;
11997     } else {
11998         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
11999     }
12000     return (warn_code);
12001 }
12002
12003 STATIC ushort __init
12004 AscInitFromAscDvcVar(
12005                         ASC_DVC_VAR *asc_dvc
12006 )
12007 {
12008     PortAddr            iop_base;
12009     ushort              cfg_msw;
12010     ushort              warn_code;
12011     ushort              pci_device_id;
12012
12013     iop_base = asc_dvc->iop_base;
12014     pci_device_id = to_pci_dev(asc_dvc->cfg->dev)->device;
12015     warn_code = 0;
12016     cfg_msw = AscGetChipCfgMsw(iop_base);
12017     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12018         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12019         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12020         AscSetChipCfgMsw(iop_base, cfg_msw);
12021     }
12022     if ((asc_dvc->cfg->cmd_qng_enabled & asc_dvc->cfg->disc_enable) !=
12023         asc_dvc->cfg->cmd_qng_enabled) {
12024         asc_dvc->cfg->disc_enable = asc_dvc->cfg->cmd_qng_enabled;
12025         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12026     }
12027     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12028         warn_code |= ASC_WARN_AUTO_CONFIG;
12029     }
12030     if ((asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL)) != 0) {
12031         if (AscSetChipIRQ(iop_base, asc_dvc->irq_no, asc_dvc->bus_type)
12032             != asc_dvc->irq_no) {
12033             asc_dvc->err_code |= ASC_IERR_SET_IRQ_NO;
12034         }
12035     }
12036     if (asc_dvc->bus_type & ASC_IS_PCI) {
12037         cfg_msw &= 0xFFC0;
12038         AscSetChipCfgMsw(iop_base, cfg_msw);
12039         if ((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) {
12040         } else {
12041             if ((pci_device_id == ASC_PCI_DEVICE_ID_REV_A) ||
12042                 (pci_device_id == ASC_PCI_DEVICE_ID_REV_B)) {
12043                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_IF_NOT_DWB;
12044                 asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12045             }
12046         }
12047     } else if (asc_dvc->bus_type == ASC_IS_ISAPNP) {
12048         if (AscGetChipVersion(iop_base, asc_dvc->bus_type)
12049             == ASC_CHIP_VER_ASYN_BUG) {
12050             asc_dvc->bug_fix_cntl |= ASC_BUG_FIX_ASYN_USE_SYN;
12051         }
12052     }
12053     if (AscSetChipScsiID(iop_base, asc_dvc->cfg->chip_scsi_id) !=
12054         asc_dvc->cfg->chip_scsi_id) {
12055         asc_dvc->err_code |= ASC_IERR_SET_SCSI_ID;
12056     }
12057 #ifdef CONFIG_ISA
12058     if (asc_dvc->bus_type & ASC_IS_ISA) {
12059         AscSetIsaDmaChannel(iop_base, asc_dvc->cfg->isa_dma_channel);
12060         AscSetIsaDmaSpeed(iop_base, asc_dvc->cfg->isa_dma_speed);
12061     }
12062 #endif /* CONFIG_ISA */
12063     return (warn_code);
12064 }
12065
12066 STATIC ushort
12067 AscInitAsc1000Driver(
12068                         ASC_DVC_VAR *asc_dvc
12069 )
12070 {
12071     ushort              warn_code;
12072     PortAddr            iop_base;
12073
12074     iop_base = asc_dvc->iop_base;
12075     warn_code = 0;
12076     if ((asc_dvc->dvc_cntl & ASC_CNTL_RESET_SCSI) &&
12077         !(asc_dvc->init_state & ASC_INIT_RESET_SCSI_DONE)) {
12078         AscResetChipAndScsiBus(asc_dvc);
12079         DvcSleepMilliSecond((ASC_DCNT)
12080             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12081     }
12082     asc_dvc->init_state |= ASC_INIT_STATE_BEG_LOAD_MC;
12083     if (asc_dvc->err_code != 0)
12084         return (UW_ERR);
12085     if (!AscFindSignature(asc_dvc->iop_base)) {
12086         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
12087         return (warn_code);
12088     }
12089     AscDisableInterrupt(iop_base);
12090     warn_code |= AscInitLram(asc_dvc);
12091     if (asc_dvc->err_code != 0)
12092         return (UW_ERR);
12093     ASC_DBG1(1, "AscInitAsc1000Driver: _asc_mcode_chksum 0x%lx\n",
12094         (ulong) _asc_mcode_chksum);
12095     if (AscLoadMicroCode(iop_base, 0, _asc_mcode_buf,
12096                          _asc_mcode_size) != _asc_mcode_chksum) {
12097         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
12098         return (warn_code);
12099     }
12100     warn_code |= AscInitMicroCodeVar(asc_dvc);
12101     asc_dvc->init_state |= ASC_INIT_STATE_END_LOAD_MC;
12102     AscEnableInterrupt(iop_base);
12103     return (warn_code);
12104 }
12105
12106 STATIC ushort __init
12107 AscInitAscDvcVar(
12108                     ASC_DVC_VAR *asc_dvc)
12109 {
12110     int                 i;
12111     PortAddr            iop_base;
12112     ushort              warn_code;
12113     uchar               chip_version;
12114
12115     iop_base = asc_dvc->iop_base;
12116     warn_code = 0;
12117     asc_dvc->err_code = 0;
12118     if ((asc_dvc->bus_type &
12119          (ASC_IS_ISA | ASC_IS_PCI | ASC_IS_EISA | ASC_IS_VL)) == 0) {
12120         asc_dvc->err_code |= ASC_IERR_NO_BUS_TYPE;
12121     }
12122     AscSetChipControl(iop_base, CC_HALT);
12123     AscSetChipStatus(iop_base, 0);
12124     asc_dvc->bug_fix_cntl = 0;
12125     asc_dvc->pci_fix_asyn_xfer = 0;
12126     asc_dvc->pci_fix_asyn_xfer_always = 0;
12127     /* asc_dvc->init_state initalized in AscInitGetConfig(). */
12128     asc_dvc->sdtr_done = 0;
12129     asc_dvc->cur_total_qng = 0;
12130     asc_dvc->is_in_int = 0;
12131     asc_dvc->in_critical_cnt = 0;
12132     asc_dvc->last_q_shortage = 0;
12133     asc_dvc->use_tagged_qng = 0;
12134     asc_dvc->no_scam = 0;
12135     asc_dvc->unit_not_ready = 0;
12136     asc_dvc->queue_full_or_busy = 0;
12137     asc_dvc->redo_scam = 0;
12138     asc_dvc->res2 = 0;
12139     asc_dvc->host_init_sdtr_index = 0;
12140     asc_dvc->cfg->can_tagged_qng = 0;
12141     asc_dvc->cfg->cmd_qng_enabled = 0;
12142     asc_dvc->dvc_cntl = ASC_DEF_DVC_CNTL;
12143     asc_dvc->init_sdtr = 0;
12144     asc_dvc->max_total_qng = ASC_DEF_MAX_TOTAL_QNG;
12145     asc_dvc->scsi_reset_wait = 3;
12146     asc_dvc->start_motor = ASC_SCSI_WIDTH_BIT_SET;
12147     asc_dvc->max_dma_count = AscGetMaxDmaCount(asc_dvc->bus_type);
12148     asc_dvc->cfg->sdtr_enable = ASC_SCSI_WIDTH_BIT_SET;
12149     asc_dvc->cfg->disc_enable = ASC_SCSI_WIDTH_BIT_SET;
12150     asc_dvc->cfg->chip_scsi_id = ASC_DEF_CHIP_SCSI_ID;
12151     asc_dvc->cfg->lib_serial_no = ASC_LIB_SERIAL_NUMBER;
12152     asc_dvc->cfg->lib_version = (ASC_LIB_VERSION_MAJOR << 8) |
12153       ASC_LIB_VERSION_MINOR;
12154     chip_version = AscGetChipVersion(iop_base, asc_dvc->bus_type);
12155     asc_dvc->cfg->chip_version = chip_version;
12156     asc_dvc->sdtr_period_tbl[0] = SYN_XFER_NS_0;
12157     asc_dvc->sdtr_period_tbl[1] = SYN_XFER_NS_1;
12158     asc_dvc->sdtr_period_tbl[2] = SYN_XFER_NS_2;
12159     asc_dvc->sdtr_period_tbl[3] = SYN_XFER_NS_3;
12160     asc_dvc->sdtr_period_tbl[4] = SYN_XFER_NS_4;
12161     asc_dvc->sdtr_period_tbl[5] = SYN_XFER_NS_5;
12162     asc_dvc->sdtr_period_tbl[6] = SYN_XFER_NS_6;
12163     asc_dvc->sdtr_period_tbl[7] = SYN_XFER_NS_7;
12164     asc_dvc->max_sdtr_index = 7;
12165     if ((asc_dvc->bus_type & ASC_IS_PCI) &&
12166         (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3150)) {
12167         asc_dvc->bus_type = ASC_IS_PCI_ULTRA;
12168         asc_dvc->sdtr_period_tbl[0] = SYN_ULTRA_XFER_NS_0;
12169         asc_dvc->sdtr_period_tbl[1] = SYN_ULTRA_XFER_NS_1;
12170         asc_dvc->sdtr_period_tbl[2] = SYN_ULTRA_XFER_NS_2;
12171         asc_dvc->sdtr_period_tbl[3] = SYN_ULTRA_XFER_NS_3;
12172         asc_dvc->sdtr_period_tbl[4] = SYN_ULTRA_XFER_NS_4;
12173         asc_dvc->sdtr_period_tbl[5] = SYN_ULTRA_XFER_NS_5;
12174         asc_dvc->sdtr_period_tbl[6] = SYN_ULTRA_XFER_NS_6;
12175         asc_dvc->sdtr_period_tbl[7] = SYN_ULTRA_XFER_NS_7;
12176         asc_dvc->sdtr_period_tbl[8] = SYN_ULTRA_XFER_NS_8;
12177         asc_dvc->sdtr_period_tbl[9] = SYN_ULTRA_XFER_NS_9;
12178         asc_dvc->sdtr_period_tbl[10] = SYN_ULTRA_XFER_NS_10;
12179         asc_dvc->sdtr_period_tbl[11] = SYN_ULTRA_XFER_NS_11;
12180         asc_dvc->sdtr_period_tbl[12] = SYN_ULTRA_XFER_NS_12;
12181         asc_dvc->sdtr_period_tbl[13] = SYN_ULTRA_XFER_NS_13;
12182         asc_dvc->sdtr_period_tbl[14] = SYN_ULTRA_XFER_NS_14;
12183         asc_dvc->sdtr_period_tbl[15] = SYN_ULTRA_XFER_NS_15;
12184         asc_dvc->max_sdtr_index = 15;
12185         if (chip_version == ASC_CHIP_VER_PCI_ULTRA_3150)
12186         {
12187             AscSetExtraControl(iop_base,
12188                 (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12189         } else if (chip_version >= ASC_CHIP_VER_PCI_ULTRA_3050) {
12190             AscSetExtraControl(iop_base,
12191                 (SEC_ACTIVE_NEGATE | SEC_ENABLE_FILTER));
12192         }
12193     }
12194     if (asc_dvc->bus_type == ASC_IS_PCI) {
12195            AscSetExtraControl(iop_base, (SEC_ACTIVE_NEGATE | SEC_SLEW_RATE));
12196     }
12197
12198     asc_dvc->cfg->isa_dma_speed = ASC_DEF_ISA_DMA_SPEED;
12199     if (AscGetChipBusType(iop_base) == ASC_IS_ISAPNP) {
12200         AscSetChipIFC(iop_base, IFC_INIT_DEFAULT);
12201         asc_dvc->bus_type = ASC_IS_ISAPNP;
12202     }
12203 #ifdef CONFIG_ISA
12204     if ((asc_dvc->bus_type & ASC_IS_ISA) != 0) {
12205         asc_dvc->cfg->isa_dma_channel = (uchar) AscGetIsaDmaChannel(iop_base);
12206     }
12207 #endif /* CONFIG_ISA */
12208     for (i = 0; i <= ASC_MAX_TID; i++) {
12209         asc_dvc->cur_dvc_qng[i] = 0;
12210         asc_dvc->max_dvc_qng[i] = ASC_MAX_SCSI1_QNG;
12211         asc_dvc->scsiq_busy_head[i] = (ASC_SCSI_Q *) 0L;
12212         asc_dvc->scsiq_busy_tail[i] = (ASC_SCSI_Q *) 0L;
12213         asc_dvc->cfg->max_tag_qng[i] = ASC_MAX_INRAM_TAG_QNG;
12214     }
12215     return (warn_code);
12216 }
12217
12218 STATIC ushort __init
12219 AscInitFromEEP(ASC_DVC_VAR *asc_dvc)
12220 {
12221     ASCEEP_CONFIG       eep_config_buf;
12222     ASCEEP_CONFIG       *eep_config;
12223     PortAddr            iop_base;
12224     ushort              chksum;
12225     ushort              warn_code;
12226     ushort              cfg_msw, cfg_lsw;
12227     int                 i;
12228     int                 write_eep = 0;
12229
12230     iop_base = asc_dvc->iop_base;
12231     warn_code = 0;
12232     AscWriteLramWord(iop_base, ASCV_HALTCODE_W, 0x00FE);
12233     AscStopQueueExe(iop_base);
12234     if ((AscStopChip(iop_base) == FALSE) ||
12235         (AscGetChipScsiCtrl(iop_base) != 0)) {
12236         asc_dvc->init_state |= ASC_INIT_RESET_SCSI_DONE;
12237         AscResetChipAndScsiBus(asc_dvc);
12238         DvcSleepMilliSecond((ASC_DCNT)
12239             ((ushort) asc_dvc->scsi_reset_wait * 1000));
12240     }
12241     if (AscIsChipHalted(iop_base) == FALSE) {
12242         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12243         return (warn_code);
12244     }
12245     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12246     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12247         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12248         return (warn_code);
12249     }
12250     eep_config = (ASCEEP_CONFIG *) &eep_config_buf;
12251     cfg_msw = AscGetChipCfgMsw(iop_base);
12252     cfg_lsw = AscGetChipCfgLsw(iop_base);
12253     if ((cfg_msw & ASC_CFG_MSW_CLR_MASK) != 0) {
12254         cfg_msw &= (~(ASC_CFG_MSW_CLR_MASK));
12255         warn_code |= ASC_WARN_CFG_MSW_RECOVER;
12256         AscSetChipCfgMsw(iop_base, cfg_msw);
12257     }
12258     chksum = AscGetEEPConfig(iop_base, eep_config, asc_dvc->bus_type);
12259     ASC_DBG1(1, "AscInitFromEEP: chksum 0x%x\n", chksum);
12260     if (chksum == 0) {
12261         chksum = 0xaa55;
12262     }
12263     if (AscGetChipStatus(iop_base) & CSW_AUTO_CONFIG) {
12264         warn_code |= ASC_WARN_AUTO_CONFIG;
12265         if (asc_dvc->cfg->chip_version == 3) {
12266             if (eep_config->cfg_lsw != cfg_lsw) {
12267                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12268                 eep_config->cfg_lsw = AscGetChipCfgLsw(iop_base);
12269             }
12270             if (eep_config->cfg_msw != cfg_msw) {
12271                 warn_code |= ASC_WARN_EEPROM_RECOVER;
12272                 eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12273             }
12274         }
12275     }
12276     eep_config->cfg_msw &= ~ASC_CFG_MSW_CLR_MASK;
12277     eep_config->cfg_lsw |= ASC_CFG0_HOST_INT_ON;
12278     ASC_DBG1(1, "AscInitFromEEP: eep_config->chksum 0x%x\n",
12279         eep_config->chksum);
12280     if (chksum != eep_config->chksum) {
12281             if (AscGetChipVersion(iop_base, asc_dvc->bus_type) ==
12282                     ASC_CHIP_VER_PCI_ULTRA_3050 )
12283             {
12284                 ASC_DBG(1,
12285 "AscInitFromEEP: chksum error ignored; EEPROM-less board\n");
12286                 eep_config->init_sdtr = 0xFF;
12287                 eep_config->disc_enable = 0xFF;
12288                 eep_config->start_motor = 0xFF;
12289                 eep_config->use_cmd_qng = 0;
12290                 eep_config->max_total_qng = 0xF0;
12291                 eep_config->max_tag_qng = 0x20;
12292                 eep_config->cntl = 0xBFFF;
12293                 ASC_EEP_SET_CHIP_ID(eep_config, 7);
12294                 eep_config->no_scam = 0;
12295                 eep_config->adapter_info[0] = 0;
12296                 eep_config->adapter_info[1] = 0;
12297                 eep_config->adapter_info[2] = 0;
12298                 eep_config->adapter_info[3] = 0;
12299                 eep_config->adapter_info[4] = 0;
12300                 /* Indicate EEPROM-less board. */
12301                 eep_config->adapter_info[5] = 0xBB;
12302             } else {
12303                 ASC_PRINT(
12304 "AscInitFromEEP: EEPROM checksum error; Will try to re-write EEPROM.\n");
12305                 write_eep = 1;
12306                 warn_code |= ASC_WARN_EEPROM_CHKSUM;
12307             }
12308     }
12309     asc_dvc->cfg->sdtr_enable = eep_config->init_sdtr;
12310     asc_dvc->cfg->disc_enable = eep_config->disc_enable;
12311     asc_dvc->cfg->cmd_qng_enabled = eep_config->use_cmd_qng;
12312     asc_dvc->cfg->isa_dma_speed = ASC_EEP_GET_DMA_SPD(eep_config);
12313     asc_dvc->start_motor = eep_config->start_motor;
12314     asc_dvc->dvc_cntl = eep_config->cntl;
12315     asc_dvc->no_scam = eep_config->no_scam;
12316     asc_dvc->cfg->adapter_info[0] = eep_config->adapter_info[0];
12317     asc_dvc->cfg->adapter_info[1] = eep_config->adapter_info[1];
12318     asc_dvc->cfg->adapter_info[2] = eep_config->adapter_info[2];
12319     asc_dvc->cfg->adapter_info[3] = eep_config->adapter_info[3];
12320     asc_dvc->cfg->adapter_info[4] = eep_config->adapter_info[4];
12321     asc_dvc->cfg->adapter_info[5] = eep_config->adapter_info[5];
12322     if (!AscTestExternalLram(asc_dvc)) {
12323         if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA)) {
12324             eep_config->max_total_qng = ASC_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
12325             eep_config->max_tag_qng = ASC_MAX_PCI_ULTRA_INRAM_TAG_QNG;
12326         } else {
12327             eep_config->cfg_msw |= 0x0800;
12328             cfg_msw |= 0x0800;
12329             AscSetChipCfgMsw(iop_base, cfg_msw);
12330             eep_config->max_total_qng = ASC_MAX_PCI_INRAM_TOTAL_QNG;
12331             eep_config->max_tag_qng = ASC_MAX_INRAM_TAG_QNG;
12332         }
12333     } else {
12334     }
12335     if (eep_config->max_total_qng < ASC_MIN_TOTAL_QNG) {
12336         eep_config->max_total_qng = ASC_MIN_TOTAL_QNG;
12337     }
12338     if (eep_config->max_total_qng > ASC_MAX_TOTAL_QNG) {
12339         eep_config->max_total_qng = ASC_MAX_TOTAL_QNG;
12340     }
12341     if (eep_config->max_tag_qng > eep_config->max_total_qng) {
12342         eep_config->max_tag_qng = eep_config->max_total_qng;
12343     }
12344     if (eep_config->max_tag_qng < ASC_MIN_TAG_Q_PER_DVC) {
12345         eep_config->max_tag_qng = ASC_MIN_TAG_Q_PER_DVC;
12346     }
12347     asc_dvc->max_total_qng = eep_config->max_total_qng;
12348     if ((eep_config->use_cmd_qng & eep_config->disc_enable) !=
12349         eep_config->use_cmd_qng) {
12350         eep_config->disc_enable = eep_config->use_cmd_qng;
12351         warn_code |= ASC_WARN_CMD_QNG_CONFLICT;
12352     }
12353     if (asc_dvc->bus_type & (ASC_IS_ISA | ASC_IS_VL | ASC_IS_EISA)) {
12354         asc_dvc->irq_no = AscGetChipIRQ(iop_base, asc_dvc->bus_type);
12355     }
12356     ASC_EEP_SET_CHIP_ID(eep_config, ASC_EEP_GET_CHIP_ID(eep_config) & ASC_MAX_TID);
12357     asc_dvc->cfg->chip_scsi_id = ASC_EEP_GET_CHIP_ID(eep_config);
12358     if (((asc_dvc->bus_type & ASC_IS_PCI_ULTRA) == ASC_IS_PCI_ULTRA) &&
12359         !(asc_dvc->dvc_cntl & ASC_CNTL_SDTR_ENABLE_ULTRA)) {
12360         asc_dvc->host_init_sdtr_index = ASC_SDTR_ULTRA_PCI_10MB_INDEX;
12361     }
12362
12363     for (i = 0; i <= ASC_MAX_TID; i++) {
12364         asc_dvc->dos_int13_table[i] = eep_config->dos_int13_table[i];
12365         asc_dvc->cfg->max_tag_qng[i] = eep_config->max_tag_qng;
12366         asc_dvc->cfg->sdtr_period_offset[i] =
12367             (uchar) (ASC_DEF_SDTR_OFFSET |
12368                      (asc_dvc->host_init_sdtr_index << 4));
12369     }
12370     eep_config->cfg_msw = AscGetChipCfgMsw(iop_base);
12371     if (write_eep) {
12372         if ((i = AscSetEEPConfig(iop_base, eep_config, asc_dvc->bus_type)) !=
12373              0) {
12374                 ASC_PRINT1(
12375 "AscInitFromEEP: Failed to re-write EEPROM with %d errors.\n", i);
12376         } else {
12377                 ASC_PRINT("AscInitFromEEP: Succesfully re-wrote EEPROM.");
12378         }
12379     }
12380     return (warn_code);
12381 }
12382
12383 STATIC ushort
12384 AscInitMicroCodeVar(
12385                        ASC_DVC_VAR *asc_dvc
12386 )
12387 {
12388     int                 i;
12389     ushort              warn_code;
12390     PortAddr            iop_base;
12391     ASC_PADDR           phy_addr;
12392     ASC_DCNT            phy_size;
12393
12394     iop_base = asc_dvc->iop_base;
12395     warn_code = 0;
12396     for (i = 0; i <= ASC_MAX_TID; i++) {
12397         AscPutMCodeInitSDTRAtID(iop_base, i,
12398                                 asc_dvc->cfg->sdtr_period_offset[i]
12399 );
12400     }
12401
12402     AscInitQLinkVar(asc_dvc);
12403     AscWriteLramByte(iop_base, ASCV_DISC_ENABLE_B,
12404                      asc_dvc->cfg->disc_enable);
12405     AscWriteLramByte(iop_base, ASCV_HOSTSCSI_ID_B,
12406                      ASC_TID_TO_TARGET_ID(asc_dvc->cfg->chip_scsi_id));
12407
12408     /* Align overrun buffer on an 8 byte boundary. */
12409     phy_addr = virt_to_bus(asc_dvc->cfg->overrun_buf);
12410     phy_addr = cpu_to_le32((phy_addr + 7) & ~0x7);
12411     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_PADDR_D,
12412         (uchar *) &phy_addr, 1);
12413     phy_size = cpu_to_le32(ASC_OVERRUN_BSIZE - 8);
12414     AscMemDWordCopyPtrToLram(iop_base, ASCV_OVERRUN_BSIZE_D,
12415         (uchar *) &phy_size, 1);
12416
12417     asc_dvc->cfg->mcode_date =
12418         AscReadLramWord(iop_base, (ushort) ASCV_MC_DATE_W);
12419     asc_dvc->cfg->mcode_version =
12420         AscReadLramWord(iop_base, (ushort) ASCV_MC_VER_W);
12421
12422     AscSetPCAddr(iop_base, ASC_MCODE_START_ADDR);
12423     if (AscGetPCAddr(iop_base) != ASC_MCODE_START_ADDR) {
12424         asc_dvc->err_code |= ASC_IERR_SET_PC_ADDR;
12425         return (warn_code);
12426     }
12427     if (AscStartChip(iop_base) != 1) {
12428         asc_dvc->err_code |= ASC_IERR_START_STOP_CHIP;
12429         return (warn_code);
12430     }
12431
12432     return (warn_code);
12433 }
12434
12435 STATIC int __init
12436 AscTestExternalLram(
12437                        ASC_DVC_VAR *asc_dvc)
12438 {
12439     PortAddr            iop_base;
12440     ushort              q_addr;
12441     ushort              saved_word;
12442     int                 sta;
12443
12444     iop_base = asc_dvc->iop_base;
12445     sta = 0;
12446     q_addr = ASC_QNO_TO_QADDR(241);
12447     saved_word = AscReadLramWord(iop_base, q_addr);
12448     AscSetChipLramAddr(iop_base, q_addr);
12449     AscSetChipLramData(iop_base, 0x55AA);
12450     DvcSleepMilliSecond(10);
12451     AscSetChipLramAddr(iop_base, q_addr);
12452     if (AscGetChipLramData(iop_base) == 0x55AA) {
12453         sta = 1;
12454         AscWriteLramWord(iop_base, q_addr, saved_word);
12455     }
12456     return (sta);
12457 }
12458
12459 STATIC int __init
12460 AscWriteEEPCmdReg(
12461                      PortAddr iop_base,
12462                      uchar cmd_reg
12463 )
12464 {
12465     uchar               read_back;
12466     int                 retry;
12467
12468     retry = 0;
12469     while (TRUE) {
12470         AscSetChipEEPCmd(iop_base, cmd_reg);
12471         DvcSleepMilliSecond(1);
12472         read_back = AscGetChipEEPCmd(iop_base);
12473         if (read_back == cmd_reg) {
12474             return (1);
12475         }
12476         if (retry++ > ASC_EEP_MAX_RETRY) {
12477             return (0);
12478         }
12479     }
12480 }
12481
12482 STATIC int __init
12483 AscWriteEEPDataReg(
12484                       PortAddr iop_base,
12485                       ushort data_reg
12486 )
12487 {
12488     ushort              read_back;
12489     int                 retry;
12490
12491     retry = 0;
12492     while (TRUE) {
12493         AscSetChipEEPData(iop_base, data_reg);
12494         DvcSleepMilliSecond(1);
12495         read_back = AscGetChipEEPData(iop_base);
12496         if (read_back == data_reg) {
12497             return (1);
12498         }
12499         if (retry++ > ASC_EEP_MAX_RETRY) {
12500             return (0);
12501         }
12502     }
12503 }
12504
12505 STATIC void __init
12506 AscWaitEEPRead(void)
12507 {
12508     DvcSleepMilliSecond(1);
12509     return;
12510 }
12511
12512 STATIC void __init
12513 AscWaitEEPWrite(void)
12514 {
12515     DvcSleepMilliSecond(20);
12516     return;
12517 }
12518
12519 STATIC ushort __init
12520 AscReadEEPWord(
12521                   PortAddr iop_base,
12522                   uchar addr)
12523 {
12524     ushort              read_wval;
12525     uchar               cmd_reg;
12526
12527     AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12528     AscWaitEEPRead();
12529     cmd_reg = addr | ASC_EEP_CMD_READ;
12530     AscWriteEEPCmdReg(iop_base, cmd_reg);
12531     AscWaitEEPRead();
12532     read_wval = AscGetChipEEPData(iop_base);
12533     AscWaitEEPRead();
12534     return (read_wval);
12535 }
12536
12537 STATIC ushort __init
12538 AscWriteEEPWord(
12539                    PortAddr iop_base,
12540                    uchar addr,
12541                    ushort word_val)
12542 {
12543     ushort              read_wval;
12544
12545     read_wval = AscReadEEPWord(iop_base, addr);
12546     if (read_wval != word_val) {
12547         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_ABLE);
12548         AscWaitEEPRead();
12549         AscWriteEEPDataReg(iop_base, word_val);
12550         AscWaitEEPRead();
12551         AscWriteEEPCmdReg(iop_base,
12552                           (uchar) ((uchar) ASC_EEP_CMD_WRITE | addr));
12553         AscWaitEEPWrite();
12554         AscWriteEEPCmdReg(iop_base, ASC_EEP_CMD_WRITE_DISABLE);
12555         AscWaitEEPRead();
12556         return (AscReadEEPWord(iop_base, addr));
12557     }
12558     return (read_wval);
12559 }
12560
12561 STATIC ushort __init
12562 AscGetEEPConfig(
12563                    PortAddr iop_base,
12564                    ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12565 {
12566     ushort              wval;
12567     ushort              sum;
12568     ushort              *wbuf;
12569     int                 cfg_beg;
12570     int                 cfg_end;
12571     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12572     int                 s_addr;
12573
12574     wbuf = (ushort *) cfg_buf;
12575     sum = 0;
12576     /* Read two config words; Byte-swapping done by AscReadEEPWord(). */
12577     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12578         *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12579         sum += *wbuf;
12580     }
12581     if (bus_type & ASC_IS_VL) {
12582         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12583         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12584     } else {
12585         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12586         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12587     }
12588     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12589         wval = AscReadEEPWord( iop_base, ( uchar )s_addr ) ;
12590         if (s_addr <= uchar_end_in_config) {
12591             /*
12592              * Swap all char fields - must unswap bytes already swapped
12593              * by AscReadEEPWord().
12594              */
12595             *wbuf = le16_to_cpu(wval);
12596         } else {
12597             /* Don't swap word field at the end - cntl field. */
12598             *wbuf = wval;
12599         }
12600         sum += wval; /* Checksum treats all EEPROM data as words. */
12601     }
12602     /*
12603      * Read the checksum word which will be compared against 'sum'
12604      * by the caller. Word field already swapped.
12605      */
12606     *wbuf = AscReadEEPWord(iop_base, (uchar) s_addr);
12607     return (sum);
12608 }
12609
12610 STATIC int __init
12611 AscSetEEPConfigOnce(
12612                        PortAddr iop_base,
12613                        ASCEEP_CONFIG * cfg_buf, ushort bus_type)
12614 {
12615     int                 n_error;
12616     ushort              *wbuf;
12617     ushort              word;
12618     ushort              sum;
12619     int                 s_addr;
12620     int                 cfg_beg;
12621     int                 cfg_end;
12622     int                 uchar_end_in_config = ASC_EEP_MAX_DVC_ADDR - 2;
12623
12624
12625     wbuf = (ushort *) cfg_buf;
12626     n_error = 0;
12627     sum = 0;
12628     /* Write two config words; AscWriteEEPWord() will swap bytes. */
12629     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12630         sum += *wbuf;
12631         if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12632             n_error++;
12633         }
12634     }
12635     if (bus_type & ASC_IS_VL) {
12636         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12637         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12638     } else {
12639         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12640         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12641     }
12642     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12643         if (s_addr <= uchar_end_in_config) {
12644             /*
12645              * This is a char field. Swap char fields before they are
12646              * swapped again by AscWriteEEPWord().
12647              */
12648             word = cpu_to_le16(*wbuf);
12649             if (word != AscWriteEEPWord( iop_base, (uchar) s_addr, word)) {
12650                 n_error++;
12651             }
12652         } else {
12653             /* Don't swap word field at the end - cntl field. */
12654             if (*wbuf != AscWriteEEPWord(iop_base, (uchar) s_addr, *wbuf)) {
12655                 n_error++;
12656             }
12657         }
12658         sum += *wbuf; /* Checksum calculated from word values. */
12659     }
12660     /* Write checksum word. It will be swapped by AscWriteEEPWord(). */
12661     *wbuf = sum;
12662     if (sum != AscWriteEEPWord(iop_base, (uchar) s_addr, sum)) {
12663         n_error++;
12664     }
12665
12666     /* Read EEPROM back again. */
12667     wbuf = (ushort *) cfg_buf;
12668     /*
12669      * Read two config words; Byte-swapping done by AscReadEEPWord().
12670      */
12671     for (s_addr = 0; s_addr < 2; s_addr++, wbuf++) {
12672         if (*wbuf != AscReadEEPWord(iop_base, (uchar) s_addr)) {
12673             n_error++;
12674         }
12675     }
12676     if (bus_type & ASC_IS_VL) {
12677         cfg_beg = ASC_EEP_DVC_CFG_BEG_VL;
12678         cfg_end = ASC_EEP_MAX_DVC_ADDR_VL;
12679     } else {
12680         cfg_beg = ASC_EEP_DVC_CFG_BEG;
12681         cfg_end = ASC_EEP_MAX_DVC_ADDR;
12682     }
12683     for (s_addr = cfg_beg; s_addr <= (cfg_end - 1); s_addr++, wbuf++) {
12684         if (s_addr <= uchar_end_in_config) {
12685             /*
12686              * Swap all char fields. Must unswap bytes already swapped
12687              * by AscReadEEPWord().
12688              */
12689             word = le16_to_cpu(AscReadEEPWord(iop_base, (uchar) s_addr));
12690         } else {
12691             /* Don't swap word field at the end - cntl field. */
12692             word = AscReadEEPWord(iop_base, (uchar) s_addr);
12693         }
12694         if (*wbuf != word) {
12695             n_error++;
12696         }
12697     }
12698     /* Read checksum; Byte swapping not needed. */
12699     if (AscReadEEPWord(iop_base, (uchar) s_addr) != sum) {
12700         n_error++;
12701     }
12702     return (n_error);
12703 }
12704
12705 STATIC int __init
12706 AscSetEEPConfig(
12707                    PortAddr iop_base,
12708                    ASCEEP_CONFIG * cfg_buf, ushort bus_type
12709 )
12710 {
12711     int            retry;
12712     int            n_error;
12713
12714     retry = 0;
12715     while (TRUE) {
12716         if ((n_error = AscSetEEPConfigOnce(iop_base, cfg_buf,
12717                                            bus_type)) == 0) {
12718             break;
12719         }
12720         if (++retry > ASC_EEP_MAX_RETRY) {
12721             break;
12722         }
12723     }
12724     return (n_error);
12725 }
12726
12727 STATIC void
12728 AscAsyncFix(
12729                ASC_DVC_VAR *asc_dvc,
12730                uchar tid_no,
12731                ASC_SCSI_INQUIRY *inq)
12732 {
12733     uchar                       dvc_type;
12734     ASC_SCSI_BIT_ID_TYPE        tid_bits;
12735
12736     dvc_type = ASC_INQ_DVC_TYPE(inq);
12737     tid_bits = ASC_TIX_TO_TARGET_ID(tid_no);
12738
12739     if (asc_dvc->bug_fix_cntl & ASC_BUG_FIX_ASYN_USE_SYN)
12740     {
12741         if (!(asc_dvc->init_sdtr & tid_bits))
12742         {
12743             if ((dvc_type == TYPE_ROM) &&
12744                 (AscCompareString((uchar *) inq->vendor_id,
12745                     (uchar *) "HP ", 3) == 0))
12746             {
12747                 asc_dvc->pci_fix_asyn_xfer_always |= tid_bits;
12748             }
12749             asc_dvc->pci_fix_asyn_xfer |= tid_bits;
12750             if ((dvc_type == TYPE_PROCESSOR) ||
12751                 (dvc_type == TYPE_SCANNER) ||
12752                 (dvc_type == TYPE_ROM) ||
12753                 (dvc_type == TYPE_TAPE))
12754             {
12755                 asc_dvc->pci_fix_asyn_xfer &= ~tid_bits;
12756             }
12757
12758             if (asc_dvc->pci_fix_asyn_xfer & tid_bits)
12759             {
12760                 AscSetRunChipSynRegAtID(asc_dvc->iop_base, tid_no,
12761                     ASYN_SDTR_DATA_FIX_PCI_REV_AB);
12762             }
12763         }
12764     }
12765     return;
12766 }
12767
12768 STATIC int
12769 AscTagQueuingSafe(ASC_SCSI_INQUIRY *inq)
12770 {
12771     if ((inq->add_len >= 32) &&
12772         (AscCompareString((uchar *) inq->vendor_id,
12773             (uchar *) "QUANTUM XP34301", 15) == 0) &&
12774         (AscCompareString((uchar *) inq->product_rev_level,
12775             (uchar *) "1071", 4) == 0))
12776     {
12777         return 0;
12778     }
12779     return 1;
12780 }
12781
12782 STATIC void
12783 AscInquiryHandling(ASC_DVC_VAR *asc_dvc,
12784                    uchar tid_no, ASC_SCSI_INQUIRY *inq)
12785 {
12786     ASC_SCSI_BIT_ID_TYPE tid_bit = ASC_TIX_TO_TARGET_ID(tid_no);
12787     ASC_SCSI_BIT_ID_TYPE orig_init_sdtr, orig_use_tagged_qng;
12788
12789     orig_init_sdtr = asc_dvc->init_sdtr;
12790     orig_use_tagged_qng = asc_dvc->use_tagged_qng;
12791
12792     asc_dvc->init_sdtr &= ~tid_bit;
12793     asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
12794     asc_dvc->use_tagged_qng &= ~tid_bit;
12795
12796     if (ASC_INQ_RESPONSE_FMT(inq) >= 2 || ASC_INQ_ANSI_VER(inq) >= 2) {
12797         if ((asc_dvc->cfg->sdtr_enable & tid_bit) && ASC_INQ_SYNC(inq)) {
12798             asc_dvc->init_sdtr |= tid_bit;
12799         }
12800         if ((asc_dvc->cfg->cmd_qng_enabled & tid_bit) &&
12801              ASC_INQ_CMD_QUEUE(inq)) {
12802             if (AscTagQueuingSafe(inq)) {
12803                 asc_dvc->use_tagged_qng |= tid_bit;
12804                 asc_dvc->cfg->can_tagged_qng |= tid_bit;
12805             }
12806         }
12807     }
12808     if (orig_use_tagged_qng != asc_dvc->use_tagged_qng) {
12809         AscWriteLramByte(asc_dvc->iop_base, ASCV_DISC_ENABLE_B,
12810                          asc_dvc->cfg->disc_enable);
12811         AscWriteLramByte(asc_dvc->iop_base, ASCV_USE_TAGGED_QNG_B,
12812                          asc_dvc->use_tagged_qng);
12813         AscWriteLramByte(asc_dvc->iop_base, ASCV_CAN_TAGGED_QNG_B,
12814                          asc_dvc->cfg->can_tagged_qng);
12815
12816         asc_dvc->max_dvc_qng[tid_no] =
12817           asc_dvc->cfg->max_tag_qng[tid_no];
12818         AscWriteLramByte(asc_dvc->iop_base,
12819                          (ushort) (ASCV_MAX_DVC_QNG_BEG + tid_no),
12820                          asc_dvc->max_dvc_qng[tid_no]);
12821     }
12822     if (orig_init_sdtr != asc_dvc->init_sdtr) {
12823         AscAsyncFix(asc_dvc, tid_no, inq);
12824     }
12825     return;
12826 }
12827
12828 STATIC int
12829 AscCompareString(
12830                     uchar *str1,
12831                     uchar *str2,
12832                     int len
12833 )
12834 {
12835     int                 i;
12836     int                 diff;
12837
12838     for (i = 0; i < len; i++) {
12839         diff = (int) (str1[i] - str2[i]);
12840         if (diff != 0)
12841             return (diff);
12842     }
12843     return (0);
12844 }
12845
12846 STATIC uchar
12847 AscReadLramByte(
12848                    PortAddr iop_base,
12849                    ushort addr
12850 )
12851 {
12852     uchar               byte_data;
12853     ushort              word_data;
12854
12855     if (isodd_word(addr)) {
12856         AscSetChipLramAddr(iop_base, addr - 1);
12857         word_data = AscGetChipLramData(iop_base);
12858         byte_data = (uchar) ((word_data >> 8) & 0xFF);
12859     } else {
12860         AscSetChipLramAddr(iop_base, addr);
12861         word_data = AscGetChipLramData(iop_base);
12862         byte_data = (uchar) (word_data & 0xFF);
12863     }
12864     return (byte_data);
12865 }
12866 STATIC ushort
12867 AscReadLramWord(
12868                    PortAddr iop_base,
12869                    ushort addr
12870 )
12871 {
12872     ushort              word_data;
12873
12874     AscSetChipLramAddr(iop_base, addr);
12875     word_data = AscGetChipLramData(iop_base);
12876     return (word_data);
12877 }
12878
12879 #if CC_VERY_LONG_SG_LIST
12880 STATIC ASC_DCNT
12881 AscReadLramDWord(
12882                     PortAddr iop_base,
12883                     ushort addr
12884 )
12885 {
12886     ushort              val_low, val_high;
12887     ASC_DCNT            dword_data;
12888
12889     AscSetChipLramAddr(iop_base, addr);
12890     val_low = AscGetChipLramData(iop_base);
12891     val_high = AscGetChipLramData(iop_base);
12892     dword_data = ((ASC_DCNT) val_high << 16) | (ASC_DCNT) val_low;
12893     return (dword_data);
12894 }
12895 #endif /* CC_VERY_LONG_SG_LIST */
12896
12897 STATIC void
12898 AscWriteLramWord(
12899                     PortAddr iop_base,
12900                     ushort addr,
12901                     ushort word_val
12902 )
12903 {
12904     AscSetChipLramAddr(iop_base, addr);
12905     AscSetChipLramData(iop_base, word_val);
12906     return;
12907 }
12908
12909 STATIC void
12910 AscWriteLramByte(
12911                     PortAddr iop_base,
12912                     ushort addr,
12913                     uchar byte_val
12914 )
12915 {
12916     ushort              word_data;
12917
12918     if (isodd_word(addr)) {
12919         addr--;
12920         word_data = AscReadLramWord(iop_base, addr);
12921         word_data &= 0x00FF;
12922         word_data |= (((ushort) byte_val << 8) & 0xFF00);
12923     } else {
12924         word_data = AscReadLramWord(iop_base, addr);
12925         word_data &= 0xFF00;
12926         word_data |= ((ushort) byte_val & 0x00FF);
12927     }
12928     AscWriteLramWord(iop_base, addr, word_data);
12929     return;
12930 }
12931
12932 /*
12933  * Copy 2 bytes to LRAM.
12934  *
12935  * The source data is assumed to be in little-endian order in memory
12936  * and is maintained in little-endian order when written to LRAM.
12937  */
12938 STATIC void
12939 AscMemWordCopyPtrToLram(
12940                         PortAddr iop_base,
12941                         ushort s_addr,
12942                         uchar *s_buffer,
12943                         int words
12944 )
12945 {
12946     int    i;
12947
12948     AscSetChipLramAddr(iop_base, s_addr);
12949     for (i = 0; i < 2 * words; i += 2) {
12950         /*
12951          * On a little-endian system the second argument below
12952          * produces a little-endian ushort which is written to
12953          * LRAM in little-endian order. On a big-endian system
12954          * the second argument produces a big-endian ushort which
12955          * is "transparently" byte-swapped by outpw() and written
12956          * in little-endian order to LRAM.
12957          */
12958         outpw(iop_base + IOP_RAM_DATA,
12959             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]);
12960     }
12961     return;
12962 }
12963
12964 /*
12965  * Copy 4 bytes to LRAM.
12966  *
12967  * The source data is assumed to be in little-endian order in memory
12968  * and is maintained in little-endian order when writen to LRAM.
12969  */
12970 STATIC void
12971 AscMemDWordCopyPtrToLram(
12972                          PortAddr iop_base,
12973                          ushort s_addr,
12974                          uchar *s_buffer,
12975                          int dwords
12976 )
12977 {
12978     int       i;
12979
12980     AscSetChipLramAddr(iop_base, s_addr);
12981     for (i = 0; i < 4 * dwords; i += 4) {
12982         outpw(iop_base + IOP_RAM_DATA,
12983             ((ushort) s_buffer[i + 1] << 8) | s_buffer[i]); /* LSW */
12984         outpw(iop_base + IOP_RAM_DATA,
12985             ((ushort) s_buffer[i + 3] << 8) | s_buffer[i + 2]); /* MSW */
12986     }
12987     return;
12988 }
12989
12990 /*
12991  * Copy 2 bytes from LRAM.
12992  *
12993  * The source data is assumed to be in little-endian order in LRAM
12994  * and is maintained in little-endian order when written to memory.
12995  */
12996 STATIC void
12997 AscMemWordCopyPtrFromLram(
12998                           PortAddr iop_base,
12999                           ushort s_addr,
13000                           uchar *d_buffer,
13001                           int words
13002 )
13003 {
13004     int i;
13005     ushort word;
13006
13007     AscSetChipLramAddr(iop_base, s_addr);
13008     for (i = 0; i < 2 * words; i += 2) {
13009         word = inpw(iop_base + IOP_RAM_DATA);
13010         d_buffer[i] = word & 0xff;
13011         d_buffer[i + 1] = (word >> 8) & 0xff;
13012     }
13013     return;
13014 }
13015
13016 STATIC ASC_DCNT
13017 AscMemSumLramWord(
13018                      PortAddr iop_base,
13019                      ushort s_addr,
13020                      int words
13021 )
13022 {
13023     ASC_DCNT         sum;
13024     int              i;
13025
13026     sum = 0L;
13027     for (i = 0; i < words; i++, s_addr += 2) {
13028         sum += AscReadLramWord(iop_base, s_addr);
13029     }
13030     return (sum);
13031 }
13032
13033 STATIC void
13034 AscMemWordSetLram(
13035                      PortAddr iop_base,
13036                      ushort s_addr,
13037                      ushort set_wval,
13038                      int words
13039 )
13040 {
13041     int             i;
13042
13043     AscSetChipLramAddr(iop_base, s_addr);
13044     for (i = 0; i < words; i++) {
13045         AscSetChipLramData(iop_base, set_wval);
13046     }
13047     return;
13048 }
13049
13050
13051 /*
13052  * --- Adv Library Functions
13053  */
13054
13055 /* a_mcode.h */
13056
13057 /* Microcode buffer is kept after initialization for error recovery. */
13058 STATIC unsigned char _adv_asc3550_buf[] = {
13059   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0x16,  0x18,  0xe4,  0x00,  0xfc,  0x01,  0x00,  0x48,  0xe4,
13060   0xbe,  0x18,  0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0x00,  0xfa,  0xff,  0xff,  0x28,  0x0e,  0x9e,  0xe7,
13061   0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x00,  0xf6,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,  0x01,  0xf6,
13062   0x01,  0xfa,  0x08,  0x00,  0x03,  0x00,  0x04,  0x00,  0x18,  0xf4,  0x10,  0x00,  0x00,  0xec,  0x85,  0xf0,
13063   0xbc,  0x00,  0xd5,  0xf0,  0x8e,  0x0c,  0x38,  0x54,  0x00,  0xe6,  0x1e,  0xf0,  0x86,  0xf0,  0xb4,  0x00,
13064   0x98,  0x57,  0xd0,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x0c,  0x00,  0xbb,  0x00,  0xaa,  0x18,  0x02,  0x80,
13065   0x32,  0xf0,  0x01,  0xfc,  0x88,  0x0c,  0xc6,  0x12,  0x02,  0x13,  0x18,  0x40,  0x00,  0x57,  0x01,  0xea,
13066   0x3c,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,
13067   0xc0,  0x00,  0x01,  0x01,  0x3e,  0x01,  0xda,  0x0f,  0x22,  0x10,  0x08,  0x12,  0x02,  0x4a,  0xb9,  0x54,
13068   0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x20,  0x00,  0x32,  0x00,  0x3e,  0x00,  0x80,  0x00,
13069   0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,
13070   0x78,  0x01,  0x62,  0x0a,  0x92,  0x0c,  0x2c,  0x10,  0x2e,  0x10,  0x06,  0x13,  0x4c,  0x1c,  0xbb,  0x55,
13071   0x3c,  0x56,  0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0xb1,  0xf0,  0x03,  0xf7,  0x06,  0xf7,
13072   0x03,  0xfc,  0x0f,  0x00,  0x40,  0x00,  0xbe,  0x00,  0x00,  0x01,  0xb0,  0x08,  0x30,  0x13,  0x64,  0x15,
13073   0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,  0x02,  0x48,  0x00,  0x4c,  0x04,  0xea,  0x5d,  0xf0,
13074   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x34,  0x00,  0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,
13075   0x4e,  0x01,  0x4e,  0x0b,  0x1e,  0x0e,  0x0c,  0x10,  0x0a,  0x12,  0x04,  0x13,  0x40,  0x13,  0x30,  0x1c,
13076   0x00,  0x4e,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xa7,  0xf0,
13077   0xb8,  0xf0,  0x0e,  0xf7,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,  0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,
13078   0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xde,  0x03,  0x56,  0x0a,  0x14,  0x0e,  0x02,  0x10,
13079   0x04,  0x10,  0x0a,  0x10,  0x36,  0x10,  0x0a,  0x13,  0x12,  0x13,  0x52,  0x13,  0x10,  0x15,  0x14,  0x15,
13080   0xac,  0x16,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,  0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,
13081   0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x83,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,
13082   0x0b,  0xf0,  0x0c,  0xf0,  0x5c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,  0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,
13083   0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0x0a,  0x00,  0x0d,  0x00,  0x1c,  0x00,  0x9e,  0x00,  0xa8,  0x00,
13084   0xaa,  0x00,  0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7a,  0x01,  0xc0,  0x01,
13085   0xc2,  0x01,  0x7c,  0x02,  0x5a,  0x03,  0xea,  0x04,  0xe8,  0x07,  0x68,  0x08,  0x69,  0x08,  0xba,  0x08,
13086   0xe9,  0x09,  0x06,  0x0b,  0x3a,  0x0e,  0x00,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,  0x06,  0x12,
13087   0x0c,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x82,  0x13,  0x42,  0x14,  0xd6,  0x14,  0x8a,  0x15,  0xc6,  0x17,
13088   0xd2,  0x17,  0x6b,  0x18,  0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0x48,  0x47,
13089   0x41,  0x48,  0x89,  0x48,  0x80,  0x4c,  0x00,  0x54,  0x44,  0x55,  0xe5,  0x55,  0x14,  0x56,  0x77,  0x57,
13090   0xbf,  0x57,  0x40,  0x5c,  0x06,  0x80,  0x08,  0x90,  0x03,  0xa1,  0xfe,  0x9c,  0xf0,  0x29,  0x02,  0xfe,
13091   0xb8,  0x0c,  0xff,  0x10,  0x00,  0x00,  0xd0,  0xfe,  0xcc,  0x18,  0x00,  0xcf,  0xfe,  0x80,  0x01,  0xff,
13092   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13093   0x00,  0xfe,  0x48,  0x00,  0x4f,  0xff,  0x04,  0x00,  0x00,  0x10,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13094   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x0f,
13095   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xcf,
13096   0x2a,  0x67,  0x0b,  0x01,  0xfe,  0xce,  0x0e,  0xfe,  0x04,  0xf7,  0xcf,  0x67,  0x0b,  0x3c,  0x2a,  0xfe,
13097   0x3d,  0xf0,  0xfe,  0x02,  0x02,  0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x91,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,
13098   0x90,  0xf0,  0xfe,  0xf0,  0x01,  0xfe,  0x8f,  0xf0,  0x9c,  0x05,  0x51,  0x3b,  0x02,  0xfe,  0xd4,  0x0c,
13099   0x01,  0xfe,  0x44,  0x0d,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x05,  0xfe,  0xa6,
13100   0x00,  0xfe,  0xd3,  0x12,  0x47,  0x18,  0xfe,  0xa6,  0x00,  0xb5,  0xfe,  0x48,  0xf0,  0xfe,  0x86,  0x02,
13101   0xfe,  0x49,  0xf0,  0xfe,  0xa0,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xbe,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13102   0x50,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x56,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x44,  0x02,  0xfe,  0x44,
13103   0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x4c,  0x02,  0x17,  0x0b,  0xa0,  0x17,  0x06,  0x18,
13104   0x96,  0x02,  0x29,  0xfe,  0x00,  0x1c,  0xde,  0xfe,  0x02,  0x1c,  0xdd,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13105   0x10,  0x01,  0xfe,  0x20,  0x17,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xc7,  0x0a,  0x6b,  0x01,  0x9e,
13106   0x02,  0x29,  0x14,  0x4d,  0x37,  0x97,  0x01,  0xfe,  0x64,  0x0f,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xbd,
13107   0x10,  0x0a,  0x6b,  0x01,  0x82,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x17,  0x06,
13108   0x18,  0x96,  0x2a,  0x25,  0x29,  0xfe,  0x3d,  0xf0,  0xfe,  0x02,  0x02,  0x21,  0xfe,  0x94,  0x02,  0xfe,
13109   0x5a,  0x1c,  0xea,  0xfe,  0x14,  0x1c,  0x14,  0xfe,  0x30,  0x00,  0x37,  0x97,  0x01,  0xfe,  0x54,  0x0f,
13110   0x17,  0x06,  0x18,  0x96,  0x02,  0xd0,  0x1e,  0x20,  0x07,  0x10,  0x34,  0xfe,  0x69,  0x10,  0x17,  0x06,
13111   0x18,  0x96,  0xfe,  0x04,  0xec,  0x20,  0x46,  0x3d,  0x12,  0x20,  0xfe,  0x05,  0xf6,  0xc7,  0x01,  0xfe,
13112   0x52,  0x16,  0x09,  0x4a,  0x4c,  0x35,  0x11,  0x2d,  0x3c,  0x8a,  0x01,  0xe6,  0x02,  0x29,  0x0a,  0x40,
13113   0x01,  0x0e,  0x07,  0x00,  0x5d,  0x01,  0x6f,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,
13114   0x0e,  0xfe,  0xc8,  0x54,  0x64,  0xfe,  0x0c,  0x03,  0x01,  0xe6,  0x02,  0x29,  0x2a,  0x46,  0xfe,  0x02,
13115   0xe8,  0x27,  0xf8,  0xfe,  0x9e,  0x43,  0xf7,  0xfe,  0x27,  0xf0,  0xfe,  0xdc,  0x01,  0xfe,  0x07,  0x4b,
13116   0xfe,  0x20,  0xf0,  0x9c,  0xfe,  0x40,  0x1c,  0x25,  0xd2,  0xfe,  0x26,  0xf0,  0xfe,  0x56,  0x03,  0xfe,
13117   0xa0,  0xf0,  0xfe,  0x44,  0x03,  0xfe,  0x11,  0xf0,  0x9c,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,
13118   0x64,  0x03,  0xeb,  0x0f,  0xfe,  0x11,  0x00,  0x02,  0x5a,  0x2a,  0xfe,  0x48,  0x1c,  0xeb,  0x09,  0x04,
13119   0x1d,  0xfe,  0x18,  0x13,  0x23,  0x1e,  0x98,  0xac,  0x12,  0x98,  0x0a,  0x40,  0x01,  0x0e,  0xac,  0x75,
13120   0x01,  0xfe,  0xbc,  0x15,  0x11,  0xca,  0x25,  0xd2,  0xfe,  0x01,  0xf0,  0xd2,  0xfe,  0x82,  0xf0,  0xfe,
13121   0x92,  0x03,  0xec,  0x11,  0xfe,  0xe4,  0x00,  0x65,  0xfe,  0xa4,  0x03,  0x25,  0x32,  0x1f,  0xfe,  0xb4,
13122   0x03,  0x01,  0x43,  0xfe,  0x06,  0xf0,  0xfe,  0xc4,  0x03,  0x8d,  0x81,  0xfe,  0x0a,  0xf0,  0xfe,  0x7a,
13123   0x06,  0x02,  0x22,  0x05,  0x6b,  0x28,  0x16,  0xfe,  0xf6,  0x04,  0x14,  0x2c,  0x01,  0x33,  0x8f,  0xfe,
13124   0x66,  0x02,  0x02,  0xd1,  0xeb,  0x2a,  0x67,  0x1a,  0xfe,  0x67,  0x1b,  0xf8,  0xf7,  0xfe,  0x48,  0x1c,
13125   0x70,  0x01,  0x6e,  0x87,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x16,  0xd3,  0x0a,  0xca,  0x01,  0x0e,
13126   0x74,  0x60,  0x59,  0x76,  0x27,  0x05,  0x6b,  0x28,  0xfe,  0x10,  0x12,  0x14,  0x2c,  0x01,  0x33,  0x8f,
13127   0xfe,  0x66,  0x02,  0x02,  0xd1,  0xbc,  0x7d,  0xbd,  0x7f,  0x25,  0x22,  0x65,  0xfe,  0x3c,  0x04,  0x1f,
13128   0xfe,  0x38,  0x04,  0x68,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2b,  0xff,  0x02,
13129   0x00,  0x10,  0x01,  0x08,  0x1f,  0xfe,  0xe0,  0x04,  0x2b,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd5,
13130   0xfe,  0x4c,  0x44,  0xfe,  0x4c,  0x12,  0x60,  0xfe,  0x44,  0x48,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,
13131   0xd3,  0x46,  0x76,  0x27,  0xfa,  0xef,  0xfe,  0x62,  0x13,  0x09,  0x04,  0x1d,  0xfe,  0x2a,  0x13,  0x2f,
13132   0x07,  0x7e,  0xa5,  0xfe,  0x20,  0x10,  0x13,  0x2c,  0xfe,  0x4c,  0x54,  0x64,  0xd3,  0xfa,  0xef,  0x86,
13133   0x09,  0x04,  0x1d,  0xfe,  0x08,  0x13,  0x2f,  0x07,  0x7e,  0x6e,  0x09,  0x04,  0x1d,  0xfe,  0x1c,  0x12,
13134   0x14,  0x92,  0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,
13135   0x2b,  0x11,  0xfe,  0xe6,  0x00,  0xfe,  0x1c,  0x90,  0xf9,  0x03,  0x14,  0x92,  0x01,  0x33,  0x02,  0x29,
13136   0xfe,  0x42,  0x5b,  0x67,  0x1a,  0xfe,  0x46,  0x59,  0xf8,  0xf7,  0xfe,  0x87,  0x80,  0xfe,  0x31,  0xe4,
13137   0x4f,  0x09,  0x04,  0x0b,  0xfe,  0x78,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x1a,  0xfe,  0x70,  0x12,  0x49,
13138   0x04,  0x06,  0xfe,  0x60,  0x13,  0x05,  0xfe,  0xa2,  0x00,  0x28,  0x16,  0xfe,  0x80,  0x05,  0xfe,  0x31,
13139   0xe4,  0x6a,  0x49,  0x04,  0x0b,  0xfe,  0x4a,  0x13,  0x05,  0xfe,  0xa0,  0x00,  0x28,  0xfe,  0x42,  0x12,
13140   0x5e,  0x01,  0x08,  0x25,  0x32,  0xf1,  0x01,  0x08,  0x26,  0xfe,  0x98,  0x05,  0x11,  0xfe,  0xe3,  0x00,
13141   0x23,  0x49,  0xfe,  0x4a,  0xf0,  0xfe,  0x6a,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x64,  0x05,  0x83,  0x24,
13142   0xfe,  0x21,  0x00,  0xa1,  0x24,  0xfe,  0x22,  0x00,  0xa0,  0x24,  0x4c,  0xfe,  0x09,  0x48,  0x01,  0x08,
13143   0x26,  0xfe,  0x98,  0x05,  0xfe,  0xe2,  0x08,  0x49,  0x04,  0xc5,  0x3b,  0x01,  0x86,  0x24,  0x06,  0x12,
13144   0xcc,  0x37,  0xfe,  0x27,  0x01,  0x09,  0x04,  0x1d,  0xfe,  0x22,  0x12,  0x47,  0x01,  0xa7,  0x14,  0x92,
13145   0x09,  0x04,  0x06,  0x3b,  0x14,  0xc4,  0x01,  0x33,  0x8f,  0xfe,  0x70,  0x0c,  0x02,  0x22,  0x05,  0xfe,
13146   0x9c,  0x00,  0x28,  0xfe,  0x3e,  0x12,  0x05,  0x50,  0x28,  0xfe,  0x36,  0x13,  0x47,  0x01,  0xa7,  0x26,
13147   0xfe,  0x08,  0x06,  0x0a,  0x06,  0x49,  0x04,  0x19,  0xfe,  0x02,  0x12,  0x5f,  0x01,  0xfe,  0xaa,  0x14,
13148   0x1f,  0xfe,  0xfe,  0x05,  0x11,  0x9a,  0x01,  0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x50,  0xb4,  0x0c,
13149   0x50,  0x05,  0xc6,  0x28,  0xfe,  0x62,  0x12,  0x05,  0x3f,  0x28,  0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x14,
13150   0x18,  0x01,  0xfe,  0x66,  0x18,  0xfe,  0x43,  0x48,  0xb7,  0x19,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,
13151   0x48,  0x8b,  0x1c,  0x3d,  0x85,  0xb7,  0x69,  0x47,  0x01,  0xa7,  0x26,  0xfe,  0x72,  0x06,  0x49,  0x04,
13152   0x1b,  0xdf,  0x89,  0x0a,  0x4d,  0x01,  0xfe,  0xd8,  0x14,  0x1f,  0xfe,  0x68,  0x06,  0x11,  0x9a,  0x01,
13153   0x43,  0x11,  0xfe,  0xe5,  0x00,  0x05,  0x3f,  0xb4,  0x0c,  0x3f,  0x17,  0x06,  0x01,  0xa7,  0xec,  0x72,
13154   0x70,  0x01,  0x6e,  0x87,  0x11,  0xfe,  0xe2,  0x00,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,
13155   0xa6,  0x06,  0x8c,  0xfe,  0x5c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,  0x64,  0x07,  0x8d,  0x81,  0x02,  0x22,
13156   0x09,  0x04,  0x0b,  0xfe,  0x2e,  0x12,  0x15,  0x1a,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,
13157   0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x15,  0x00,  0x02,  0xfe,  0x32,
13158   0x08,  0x61,  0x04,  0x1b,  0xfe,  0x38,  0x12,  0x09,  0x04,  0x1b,  0x6e,  0x15,  0xfe,  0x1b,  0x00,  0x01,
13159   0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x00,  0x01,  0x08,  0x15,  0x06,  0x01,
13160   0x08,  0x15,  0x00,  0x02,  0xd9,  0x66,  0x4c,  0xfe,  0x3a,  0x55,  0x5f,  0xfe,  0x9a,  0x81,  0x4b,  0x1d,
13161   0xba,  0xfe,  0x32,  0x07,  0x0a,  0x1d,  0xfe,  0x09,  0x6f,  0xaf,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,
13162   0x62,  0x2c,  0x85,  0x66,  0x7b,  0x01,  0x08,  0x25,  0x32,  0xfe,  0x0a,  0xf0,  0xfe,  0x32,  0x07,  0x8d,
13163   0x81,  0x8c,  0xfe,  0x5c,  0x07,  0x02,  0x22,  0x01,  0x43,  0x02,  0xfe,  0x8a,  0x06,  0x15,  0x19,  0x02,
13164   0xfe,  0x8a,  0x06,  0xfe,  0x9c,  0xf7,  0xd4,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x77,  0xfe,  0xca,
13165   0x07,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x4a,  0x6a,  0x35,  0x1e,  0x20,  0x07,  0x10,  0xfe,  0x0e,  0x12,
13166   0x74,  0xfe,  0x80,  0x80,  0x37,  0x20,  0x63,  0x27,  0xfe,  0x06,  0x10,  0xfe,  0x83,  0xe7,  0xc4,  0xa1,
13167   0xfe,  0x03,  0x40,  0x09,  0x4a,  0x4f,  0x35,  0x01,  0xa8,  0xad,  0xfe,  0x1f,  0x40,  0x12,  0x58,  0x01,
13168   0xa5,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0x83,  0xfb,  0xfe,
13169   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x0c,  0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,
13170   0xc2,  0x50,  0x0c,  0x39,  0x18,  0x3a,  0xfe,  0x4a,  0x10,  0x09,  0x04,  0x6a,  0xfe,  0x2a,  0x12,  0xfe,
13171   0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x54,  0x18,  0x55,  0x09,  0x04,  0x4f,  0x85,  0x01,  0xa8,  0xfe,
13172   0x1f,  0x80,  0x12,  0x58,  0xfe,  0x44,  0x90,  0xfe,  0xc6,  0x90,  0x0c,  0x56,  0x18,  0x57,  0xfb,  0xfe,
13173   0x8a,  0x90,  0x0c,  0x52,  0x18,  0x53,  0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x39,  0x18,  0x3a,
13174   0x0c,  0x38,  0x18,  0x4e,  0x09,  0x4a,  0x19,  0x35,  0x2a,  0x13,  0xfe,  0x4e,  0x11,  0x65,  0xfe,  0x48,
13175   0x08,  0xfe,  0x9e,  0xf0,  0xfe,  0x5c,  0x08,  0xb1,  0x16,  0x32,  0x2a,  0x73,  0xdd,  0xb8,  0xfe,  0x80,
13176   0x08,  0xb9,  0xfe,  0x9e,  0x08,  0x8c,  0xfe,  0x74,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x7a,  0x08,  0x8d,
13177   0x81,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xc9,  0x10,  0x15,  0x19,  0xfe,  0xc9,  0x10,  0x61,  0x04,  0x06,
13178   0xfe,  0x10,  0x12,  0x61,  0x04,  0x0b,  0x45,  0x09,  0x04,  0x0b,  0xfe,  0x68,  0x12,  0xfe,  0x2e,  0x1c,
13179   0x02,  0xfe,  0x24,  0x0a,  0x61,  0x04,  0x06,  0x45,  0x61,  0x04,  0x0b,  0xfe,  0x52,  0x12,  0xfe,  0x2c,
13180   0x1c,  0xfe,  0xaa,  0xf0,  0xfe,  0x1e,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0xbe,  0x08,  0xfe,  0x8a,  0x10,
13181   0xaa,  0xfe,  0xf3,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0xca,  0x08,  0x02,  0xfe,  0x24,  0x0a,  0xab,  0xfe,
13182   0xe7,  0x10,  0xfe,  0x2b,  0xf0,  0x9d,  0xe9,  0x1c,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xb5,  0xfe,
13183   0xd2,  0xf0,  0x9d,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x16,  0x9d,  0x05,  0xcb,  0x1c,  0x06,  0x16,  0x9d,
13184   0xb8,  0x6d,  0xb9,  0x6d,  0xaa,  0xab,  0xfe,  0xb1,  0x10,  0x70,  0x5e,  0x2b,  0x14,  0x92,  0x01,  0x33,
13185   0x0f,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x5a,  0x0f,  0x7c,  0x02,  0x5a,  0xfe,  0x74,  0x18,  0x1c,
13186   0xfe,  0x00,  0xf8,  0x16,  0x6d,  0x67,  0x1b,  0x01,  0xfe,  0x44,  0x0d,  0x3b,  0x01,  0xe6,  0x1e,  0x27,
13187   0x74,  0x67,  0x1a,  0x02,  0x6d,  0x09,  0x04,  0x0b,  0x21,  0xfe,  0x06,  0x0a,  0x09,  0x04,  0x6a,  0xfe,
13188   0x82,  0x12,  0x09,  0x04,  0x19,  0xfe,  0x66,  0x13,  0x1e,  0x58,  0xac,  0xfc,  0xfe,  0x83,  0x80,  0xfe,
13189   0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x63,  0x27,  0xfe,  0x40,  0x59,
13190   0xfe,  0xc1,  0x59,  0x77,  0xd7,  0x05,  0x54,  0x31,  0x55,  0x0c,  0x7b,  0x18,  0x7c,  0xbe,  0x54,  0xbf,
13191   0x55,  0x01,  0xa8,  0xad,  0x63,  0x27,  0x12,  0x58,  0xc0,  0x38,  0xc1,  0x4e,  0x79,  0x56,  0x68,  0x57,
13192   0xf4,  0xf5,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0x01,  0xa5,  0xa2,  0x23,  0x0c,  0x7b,
13193   0x0c,  0x7c,  0x79,  0x56,  0x68,  0x57,  0xfe,  0x12,  0x10,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x79,  0x39,
13194   0x68,  0x3a,  0x09,  0x04,  0xfe,  0xf7,  0x00,  0x35,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x10,  0x58,  0xfe,
13195   0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x02,  0x6d,  0x09,  0x04,  0x19,  0x16,  0xd7,  0x09,
13196   0x04,  0xfe,  0xf7,  0x00,  0x35,  0xfe,  0x3a,  0x55,  0xfe,  0x19,  0x81,  0x5f,  0xfe,  0x10,  0x90,  0xfe,
13197   0x92,  0x90,  0xfe,  0xd7,  0x10,  0x2f,  0x07,  0x9b,  0x16,  0xfe,  0xc6,  0x08,  0x11,  0x9b,  0x09,  0x04,
13198   0x0b,  0xfe,  0x14,  0x13,  0x05,  0x39,  0x31,  0x3a,  0x77,  0xfe,  0xc6,  0x08,  0xfe,  0x0c,  0x58,  0xfe,
13199   0x8d,  0x58,  0x02,  0x6d,  0x23,  0x47,  0xfe,  0x19,  0x80,  0xde,  0x09,  0x04,  0x0b,  0xfe,  0x1a,  0x12,
13200   0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xe9,  0xb5,  0xfe,  0xd1,  0xf0,  0xd9,  0x14,  0x7a,  0x01,  0x33,
13201   0x0f,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0xbe,  0x39,  0xfe,  0xed,  0x19,  0xbf,
13202   0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xe9,  0x1c,  0xfe,  0x00,  0xff,  0x34,  0xfe,  0x74,  0x10,
13203   0xb5,  0xfe,  0xd2,  0xf0,  0xfe,  0xb2,  0x0a,  0xfe,  0x76,  0x18,  0x1c,  0x1a,  0x84,  0x05,  0xcb,  0x1c,
13204   0x06,  0xfe,  0x08,  0x13,  0x0f,  0xfe,  0x16,  0x00,  0x02,  0x5a,  0xfe,  0xd1,  0xf0,  0xfe,  0xc4,  0x0a,
13205   0x14,  0x7a,  0x01,  0x33,  0x0f,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,  0xfe,  0xca,
13206   0x0a,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xd6,  0x0a,  0x0f,  0xfe,  0x22,  0x00,  0x02,  0x5a,
13207   0xfe,  0xcb,  0xf0,  0xfe,  0xe2,  0x0a,  0x0f,  0xfe,  0x24,  0x00,  0x02,  0x5a,  0xfe,  0xd0,  0xf0,  0xfe,
13208   0xec,  0x0a,  0x0f,  0x93,  0xdc,  0xfe,  0xcf,  0xf0,  0xfe,  0xf6,  0x0a,  0x0f,  0x4c,  0xfe,  0x10,  0x10,
13209   0xfe,  0xcc,  0xf0,  0xd9,  0x61,  0x04,  0x19,  0x3b,  0x0f,  0xfe,  0x12,  0x00,  0x2a,  0x13,  0xfe,  0x4e,
13210   0x11,  0x65,  0xfe,  0x0c,  0x0b,  0xfe,  0x9e,  0xf0,  0xfe,  0x20,  0x0b,  0xb1,  0x16,  0x32,  0x2a,  0x73,
13211   0xdd,  0xb8,  0x22,  0xb9,  0x22,  0x2a,  0xec,  0x65,  0xfe,  0x2c,  0x0b,  0x25,  0x32,  0x8c,  0xfe,  0x48,
13212   0x0b,  0x8d,  0x81,  0xb8,  0xd4,  0xb9,  0xd4,  0x02,  0x22,  0x01,  0x43,  0xfe,  0xdb,  0x10,  0x11,  0xfe,
13213   0xe8,  0x00,  0xaa,  0xab,  0x70,  0xbc,  0x7d,  0xbd,  0x7f,  0xfe,  0x89,  0xf0,  0x22,  0x30,  0x2e,  0xd8,
13214   0xbc,  0x7d,  0xbd,  0x7f,  0x01,  0x08,  0x1f,  0x22,  0x30,  0x2e,  0xd6,  0xb1,  0x45,  0x0f,  0xfe,  0x42,
13215   0x00,  0x02,  0x5a,  0x78,  0x06,  0xfe,  0x81,  0x49,  0x16,  0xfe,  0x38,  0x0c,  0x09,  0x04,  0x0b,  0xfe,
13216   0x44,  0x13,  0x0f,  0x00,  0x4b,  0x0b,  0xfe,  0x54,  0x12,  0x4b,  0xfe,  0x28,  0x00,  0x21,  0xfe,  0xa6,
13217   0x0c,  0x0a,  0x40,  0x01,  0x0e,  0x07,  0x00,  0x5d,  0x3e,  0xfe,  0x28,  0x00,  0xfe,  0xe2,  0x10,  0x01,
13218   0xe7,  0x01,  0xe8,  0x0a,  0x99,  0x01,  0xfe,  0x32,  0x0e,  0x59,  0x11,  0x2d,  0x01,  0x6f,  0x02,  0x29,
13219   0x0f,  0xfe,  0x44,  0x00,  0x4b,  0x0b,  0xdf,  0x3e,  0x0b,  0xfe,  0xb4,  0x10,  0x01,  0x86,  0x3e,  0x0b,
13220   0xfe,  0xaa,  0x10,  0x01,  0x86,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xa3,  0x3e,  0x0b,  0x0f,  0xfe,
13221   0x43,  0x00,  0xfe,  0x96,  0x10,  0x09,  0x4a,  0x0b,  0x35,  0x01,  0xe7,  0x01,  0xe8,  0x59,  0x11,  0x2d,
13222   0x01,  0x6f,  0x67,  0x0b,  0x59,  0x3c,  0x8a,  0x02,  0xfe,  0x2a,  0x03,  0x09,  0x04,  0x0b,  0x84,  0x3e,
13223   0x0b,  0x0f,  0x00,  0xfe,  0x5c,  0x10,  0x61,  0x04,  0x1b,  0xfe,  0x58,  0x12,  0x09,  0x04,  0x1b,  0xfe,
13224   0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x5c,  0x0c,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,
13225   0xf0,  0xfe,  0x62,  0x0c,  0x09,  0x4a,  0x1b,  0x35,  0xfe,  0xa9,  0x10,  0x0f,  0xfe,  0x15,  0x00,  0xfe,
13226   0x04,  0xe6,  0x0b,  0x5f,  0x5c,  0x0f,  0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x0f,  0xfe,  0x47,  0x00,
13227   0xa1,  0x0f,  0xfe,  0x41,  0x00,  0xa0,  0x0f,  0xfe,  0x24,  0x00,  0x87,  0xaa,  0xab,  0x70,  0x05,  0x6b,
13228   0x28,  0x21,  0xd1,  0x5f,  0xfe,  0x04,  0xe6,  0x1b,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x59,  0x01,
13229   0xda,  0x02,  0x29,  0xea,  0x14,  0x0b,  0x37,  0x95,  0xa9,  0x14,  0xfe,  0x31,  0x00,  0x37,  0x97,  0x01,
13230   0xfe,  0x54,  0x0f,  0x02,  0xd0,  0x3c,  0xfe,  0x06,  0xec,  0xc9,  0xee,  0x3e,  0x1d,  0xfe,  0xce,  0x45,
13231   0x34,  0x3c,  0xfe,  0x06,  0xea,  0xc9,  0xfe,  0x47,  0x4b,  0x89,  0xfe,  0x75,  0x57,  0x05,  0x51,  0xfe,
13232   0x98,  0x56,  0xfe,  0x38,  0x12,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x44,  0x48,  0x46,  0x09,  0x04,  0x1d,
13233   0xfe,  0x1a,  0x13,  0x0a,  0x40,  0x01,  0x0e,  0x47,  0xfe,  0x41,  0x58,  0x0a,  0x99,  0x01,  0x0e,  0xfe,
13234   0x49,  0x54,  0x8e,  0xfe,  0x2a,  0x0d,  0x02,  0xfe,  0x2a,  0x03,  0x0a,  0x51,  0xfe,  0xee,  0x14,  0xee,
13235   0x3e,  0x1d,  0xfe,  0xce,  0x45,  0x34,  0x3c,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x02,  0x29,  0x1e,
13236   0x20,  0x07,  0x10,  0xfe,  0x9e,  0x12,  0x23,  0x12,  0x4d,  0x12,  0x94,  0x12,  0xce,  0x1e,  0x2d,  0x47,
13237   0x37,  0x2d,  0xb1,  0xe0,  0xfe,  0xbc,  0xf0,  0xfe,  0xec,  0x0d,  0x13,  0x06,  0x12,  0x4d,  0x01,  0xfe,
13238   0xe2,  0x15,  0x05,  0xfe,  0x38,  0x01,  0x31,  0xfe,  0x3a,  0x01,  0x77,  0xfe,  0xf0,  0x0d,  0xfe,  0x02,
13239   0xec,  0xce,  0x62,  0x00,  0x5d,  0xfe,  0x04,  0xec,  0x20,  0x46,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,
13240   0x01,  0xfe,  0x52,  0x16,  0xfb,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,  0x18,  0x13,  0xaf,  0xfe,  0x02,  0xea,
13241   0xce,  0x62,  0x7a,  0xfe,  0xc5,  0x13,  0x14,  0x1b,  0x37,  0x95,  0xa9,  0x5c,  0x05,  0xfe,  0x38,  0x01,
13242   0x1c,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,  0x05,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,
13243   0x3d,  0x12,  0x20,  0x24,  0x06,  0x12,  0x2d,  0x11,  0x2d,  0x8a,  0x13,  0x06,  0x03,  0x23,  0x03,  0x1e,
13244   0x4d,  0xfe,  0xf7,  0x12,  0x1e,  0x94,  0xac,  0x12,  0x94,  0x07,  0x7a,  0xfe,  0x71,  0x13,  0xfe,  0x24,
13245   0x1c,  0x14,  0x1a,  0x37,  0x95,  0xa9,  0xfe,  0xd9,  0x10,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,
13246   0xfe,  0x80,  0x5d,  0x03,  0xb6,  0xfe,  0x03,  0xdc,  0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x03,  0xfe,
13247   0x03,  0x57,  0xb6,  0x23,  0xfe,  0x00,  0xcc,  0x03,  0xfe,  0x03,  0x57,  0xb6,  0x75,  0x03,  0x09,  0x04,
13248   0x4c,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,  0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xe1,
13249   0xfe,  0x1d,  0x80,  0xa4,  0xfe,  0x0c,  0x90,  0xfe,  0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xa3,  0xfe,  0x3c,
13250   0x90,  0xfe,  0x30,  0xf4,  0x0b,  0xfe,  0x3c,  0x50,  0xa0,  0x01,  0xfe,  0x82,  0x16,  0x2f,  0x07,  0x2d,
13251   0xe0,  0x01,  0xfe,  0xbc,  0x15,  0x09,  0x04,  0x1d,  0x45,  0x01,  0xe7,  0x01,  0xe8,  0x11,  0xfe,  0xe9,
13252   0x00,  0x09,  0x04,  0x4c,  0xfe,  0x2c,  0x13,  0x01,  0xfe,  0x14,  0x16,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,
13253   0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,  0x18,  0xfe,  0x66,  0x01,  0x09,  0x04,  0x4f,  0xfe,
13254   0x12,  0x12,  0xfe,  0x03,  0x80,  0x74,  0xfe,  0x01,  0xec,  0x20,  0xfe,  0x80,  0x40,  0x12,  0x20,  0x63,
13255   0x27,  0x11,  0xc8,  0x59,  0x1e,  0x20,  0xed,  0x76,  0x20,  0x03,  0xfe,  0x08,  0x1c,  0x05,  0xfe,  0xac,
13256   0x00,  0xfe,  0x06,  0x58,  0x05,  0xfe,  0xae,  0x00,  0xfe,  0x07,  0x58,  0x05,  0xfe,  0xb0,  0x00,  0xfe,
13257   0x08,  0x58,  0x05,  0xfe,  0xb2,  0x00,  0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x24,  0x69,  0x12,  0xc9,
13258   0x23,  0x0c,  0x50,  0x0c,  0x3f,  0x13,  0x40,  0x48,  0x5f,  0x17,  0x1d,  0xfe,  0x90,  0x4d,  0xfe,  0x91,
13259   0x54,  0x21,  0xfe,  0x08,  0x0f,  0x3e,  0x10,  0x13,  0x42,  0x48,  0x17,  0x4c,  0xfe,  0x90,  0x4d,  0xfe,
13260   0x91,  0x54,  0x21,  0xfe,  0x1e,  0x0f,  0x24,  0x10,  0x12,  0x20,  0x78,  0x2c,  0x46,  0x1e,  0x20,  0xed,
13261   0x76,  0x20,  0x11,  0xc8,  0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x32,  0x0f,  0xea,  0x70,  0xfe,  0x14,  0x1c,
13262   0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x03,  0x3c,  0xfe,  0x0c,  0x14,  0xee,  0xfe,  0x07,  0xe6,  0x1d,
13263   0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x03,  0x01,  0x86,  0x78,  0x2c,  0x46,  0xfa,  0xef,  0xfe,  0x42,
13264   0x13,  0x2f,  0x07,  0x2d,  0xfe,  0x34,  0x13,  0x0a,  0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x36,  0x12,  0xf0,
13265   0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,  0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,
13266   0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x6f,  0xfe,  0x0e,  0x10,  0x07,  0x7e,  0x45,
13267   0xf6,  0xfe,  0xd6,  0xf0,  0xfe,  0x6c,  0x0f,  0x03,  0xfe,  0x44,  0x58,  0x74,  0xfe,  0x01,  0xec,  0x97,
13268   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1b,  0x76,  0x27,  0x01,  0xda,  0xfe,
13269   0xdd,  0x10,  0x2a,  0xbc,  0x7d,  0xbd,  0x7f,  0x30,  0x2e,  0xd5,  0x07,  0x1b,  0xfe,  0x48,  0x12,  0x07,
13270   0x0b,  0xfe,  0x56,  0x12,  0x07,  0x1a,  0xfe,  0x30,  0x12,  0x07,  0xc2,  0x16,  0xfe,  0x3e,  0x11,  0x07,
13271   0xfe,  0x23,  0x00,  0x16,  0xfe,  0x4a,  0x11,  0x07,  0x06,  0x16,  0xfe,  0xa8,  0x11,  0x07,  0x19,  0xfe,
13272   0x12,  0x12,  0x07,  0x00,  0x16,  0x22,  0x14,  0xc2,  0x01,  0x33,  0x9f,  0x2b,  0x01,  0x08,  0x8c,  0x43,
13273   0x03,  0x2b,  0xfe,  0x62,  0x08,  0x0a,  0xca,  0x01,  0xfe,  0x32,  0x0e,  0x11,  0x7e,  0x02,  0x29,  0x2b,
13274   0x2f,  0x07,  0x9b,  0xfe,  0xd9,  0x13,  0x79,  0x39,  0x68,  0x3a,  0x77,  0xfe,  0xfc,  0x10,  0x09,  0x04,
13275   0x6a,  0xfe,  0x72,  0x12,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x8e,  0xfe,  0xc6,  0x10,  0x1e,  0x58,
13276   0xfe,  0x26,  0x13,  0x05,  0x7b,  0x31,  0x7c,  0x77,  0xfe,  0x82,  0x0c,  0x0c,  0x54,  0x18,  0x55,  0x23,
13277   0x0c,  0x7b,  0x0c,  0x7c,  0x01,  0xa8,  0x24,  0x69,  0x73,  0x12,  0x58,  0x01,  0xa5,  0xc0,  0x38,  0xc1,
13278   0x4e,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x38,  0xfe,  0x05,  0xfa,  0x4e,  0xfe,
13279   0x91,  0x10,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x56,  0x18,  0x57,
13280   0x83,  0xc0,  0x38,  0xc1,  0x4e,  0xf4,  0xf5,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x00,  0x56,  0xfe,  0xa1,
13281   0x56,  0x0c,  0x52,  0x18,  0x53,  0x09,  0x04,  0x6a,  0xfe,  0x1e,  0x12,  0x1e,  0x58,  0xfe,  0x1f,  0x40,
13282   0x05,  0x54,  0x31,  0x55,  0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x05,  0x56,  0x31,  0x57,  0xfe,  0x44,
13283   0x50,  0xfe,  0xc6,  0x50,  0x05,  0x52,  0x31,  0x53,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x05,  0x39,
13284   0x31,  0x3a,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x02,  0x5c,  0x24,  0x06,  0x12,  0xcd,  0x02,  0x5b,
13285   0x2b,  0x01,  0x08,  0x1f,  0x44,  0x30,  0x2e,  0xd5,  0x07,  0x06,  0x21,  0x44,  0x2f,  0x07,  0x9b,  0x21,
13286   0x5b,  0x01,  0x6e,  0x1c,  0x3d,  0x16,  0x44,  0x09,  0x04,  0x0b,  0xe2,  0x79,  0x39,  0x68,  0x3a,  0xfe,
13287   0x0a,  0x55,  0x34,  0xfe,  0x8b,  0x55,  0xbe,  0x39,  0xbf,  0x3a,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,
13288   0x02,  0x5b,  0xfe,  0x19,  0x81,  0xaf,  0xfe,  0x19,  0x41,  0x02,  0x5b,  0x2b,  0x01,  0x08,  0x25,  0x32,
13289   0x1f,  0xa2,  0x30,  0x2e,  0xd8,  0x4b,  0x1a,  0xfe,  0xa6,  0x12,  0x4b,  0x0b,  0x3b,  0x02,  0x44,  0x01,
13290   0x08,  0x25,  0x32,  0x1f,  0xa2,  0x30,  0x2e,  0xd6,  0x07,  0x1a,  0x21,  0x44,  0x01,  0x08,  0x1f,  0xa2,
13291   0x30,  0x2e,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x60,  0x05,  0xfe,  0x9c,  0x00,  0x28,  0x84,  0x49,
13292   0x04,  0x19,  0x34,  0x9f,  0xfe,  0xbb,  0x45,  0x4b,  0x00,  0x45,  0x3e,  0x06,  0x78,  0x3d,  0xfe,  0xda,
13293   0x14,  0x01,  0x6e,  0x87,  0xfe,  0x4b,  0x45,  0xe2,  0x2f,  0x07,  0x9a,  0xe1,  0x05,  0xc6,  0x28,  0x84,
13294   0x05,  0x3f,  0x28,  0x34,  0x5e,  0x02,  0x5b,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,
13295   0x05,  0x50,  0xb4,  0x0c,  0x50,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xaa,  0x14,  0x02,
13296   0x5c,  0x01,  0x08,  0x25,  0x32,  0x1f,  0x44,  0x30,  0x2e,  0xd6,  0x07,  0x06,  0x21,  0x44,  0x01,  0xfe,
13297   0x8e,  0x13,  0xfe,  0x42,  0x58,  0xfe,  0x82,  0x14,  0xfe,  0xa4,  0x14,  0x87,  0xfe,  0x4a,  0xf4,  0x0b,
13298   0x16,  0x44,  0xfe,  0x4a,  0xf4,  0x06,  0xfe,  0x0c,  0x12,  0x2f,  0x07,  0x9a,  0x85,  0x02,  0x5b,  0x05,
13299   0x3f,  0xb4,  0x0c,  0x3f,  0x5e,  0x2b,  0x01,  0x08,  0x26,  0x5c,  0x01,  0xfe,  0xd8,  0x14,  0x02,  0x5c,
13300   0x13,  0x06,  0x65,  0xfe,  0xca,  0x12,  0x26,  0xfe,  0xe0,  0x12,  0x72,  0xf1,  0x01,  0x08,  0x23,  0x72,
13301   0x03,  0x8f,  0xfe,  0xdc,  0x12,  0x25,  0xfe,  0xdc,  0x12,  0x1f,  0xfe,  0xca,  0x12,  0x5e,  0x2b,  0x01,
13302   0x08,  0xfe,  0xd5,  0x10,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,  0xfe,  0xff,  0x7f,
13303   0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0x1c,
13304   0x3d,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,
13305   0x03,  0x13,  0x6c,  0xff,  0x02,  0x00,  0x57,  0x48,  0x8b,  0xfe,  0x0b,  0x58,  0x03,  0x0a,  0x50,  0x01,
13306   0x82,  0x0a,  0x3f,  0x01,  0x82,  0x03,  0xfc,  0x1c,  0x10,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,
13307   0x19,  0x48,  0xfe,  0x00,  0x7d,  0xfe,  0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x63,  0x27,
13308   0x0c,  0x52,  0x18,  0x53,  0xbe,  0x56,  0xbf,  0x57,  0x03,  0xfe,  0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,
13309   0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x74,  0x03,  0x01,  0xfe,  0x14,  0x18,  0xfe,  0x42,  0x48,  0x5f,  0x60,
13310   0x89,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,  0x30,  0x2e,  0xd8,  0x01,  0x08,  0x1f,  0xfe,  0xa2,  0x14,
13311   0x30,  0x2e,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x05,  0xc6,  0x28,  0xfe,  0xcc,  0x12,  0x49,  0x04,
13312   0x1b,  0xfe,  0xc4,  0x13,  0x23,  0x62,  0x1b,  0xe2,  0x4b,  0xc3,  0x64,  0xfe,  0xe8,  0x13,  0x3b,  0x13,
13313   0x06,  0x17,  0xc3,  0x78,  0xdb,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xa1,  0xff,  0x02,  0x83,
13314   0x55,  0x62,  0x1a,  0xa4,  0xbb,  0xfe,  0x30,  0x00,  0x8e,  0xe4,  0x17,  0x2c,  0x13,  0x06,  0xfe,  0x56,
13315   0x10,  0x62,  0x0b,  0xe1,  0xbb,  0xfe,  0x64,  0x00,  0x8e,  0xe4,  0x0a,  0xfe,  0x64,  0x00,  0x17,  0x93,
13316   0x13,  0x06,  0xfe,  0x28,  0x10,  0x62,  0x06,  0xfe,  0x60,  0x13,  0xbb,  0xfe,  0xc8,  0x00,  0x8e,  0xe4,
13317   0x0a,  0xfe,  0xc8,  0x00,  0x17,  0x4d,  0x13,  0x06,  0x83,  0xbb,  0xfe,  0x90,  0x01,  0xba,  0xfe,  0x4e,
13318   0x14,  0x89,  0xfe,  0x12,  0x10,  0xfe,  0x43,  0xf4,  0x94,  0xfe,  0x56,  0xf0,  0xfe,  0x60,  0x14,  0xfe,
13319   0x04,  0xf4,  0x6c,  0xfe,  0x43,  0xf4,  0x93,  0xfe,  0xf3,  0x10,  0xf9,  0x01,  0xfe,  0x22,  0x13,  0x1c,
13320   0x3d,  0xfe,  0x10,  0x13,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x69,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13321   0x69,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,  0x19,  0xba,  0xfe,  0x9c,  0x14,  0xb7,
13322   0x19,  0x83,  0x60,  0x23,  0xfe,  0x4d,  0xf4,  0x00,  0xdf,  0x89,  0x13,  0x06,  0xfe,  0xb4,  0x56,  0xfe,
13323   0xc3,  0x58,  0x03,  0x60,  0x13,  0x0b,  0x03,  0x15,  0x06,  0x01,  0x08,  0x26,  0xe5,  0x15,  0x0b,  0x01,
13324   0x08,  0x26,  0xe5,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xe5,  0x72,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x03,
13325   0x15,  0x06,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x1a,  0x01,  0x08,  0x26,  0xa6,  0x15,  0x06,  0x01,  0x08,
13326   0x26,  0xa6,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x26,  0xa6,  0x72,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x03,
13327   0x60,  0x03,  0x1e,  0xcc,  0x07,  0x06,  0xfe,  0x44,  0x13,  0xad,  0x12,  0xcc,  0xfe,  0x49,  0xf4,  0x00,
13328   0x3b,  0x72,  0x9f,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xf1,  0x01,  0x08,  0x2f,  0x07,  0xfe,
13329   0xe3,  0x00,  0xfe,  0x20,  0x13,  0x1f,  0xfe,  0x5a,  0x15,  0x23,  0x12,  0xcd,  0x01,  0x43,  0x1e,  0xcd,
13330   0x07,  0x06,  0x45,  0x09,  0x4a,  0x06,  0x35,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xed,  0x88,  0x07,  0x10,
13331   0xa4,  0x0a,  0x80,  0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x80,  0x01,  0x0e,  0x88,
13332   0xfe,  0x80,  0xe7,  0x10,  0x07,  0x10,  0x84,  0xfe,  0x45,  0x58,  0x01,  0xe3,  0x88,  0x03,  0x0a,  0x42,
13333   0x01,  0x0e,  0x88,  0x0a,  0x51,  0x01,  0x9e,  0x03,  0x0a,  0x42,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xf2,
13334   0xfe,  0x49,  0xe4,  0x10,  0xa4,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x0a,  0x51,  0x01,  0x82,  0x03,  0x17,
13335   0x10,  0x71,  0x66,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,  0x1c,  0xfe,
13336   0x1d,  0xf7,  0x1d,  0x90,  0xfe,  0xf6,  0x15,  0x01,  0xfe,  0xfc,  0x16,  0xe0,  0x91,  0x1d,  0x66,  0xfe,
13337   0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x03,  0xae,  0x21,  0xfe,  0xe6,  0x15,  0xfe,  0xda,  0x10,  0x17,  0x10,
13338   0x71,  0x05,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x19,  0xfe,  0x18,  0x58,  0x05,  0xfe,  0x66,  0x01,
13339   0xfe,  0x19,  0x58,  0x91,  0x19,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,  0x50,  0x66,
13340   0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x19,  0x90,  0xfe,  0x40,  0x16,  0xfe,  0xb6,
13341   0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x18,  0x16,  0xfe,  0x9c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x83,
13342   0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x38,  0x90,  0xfe,  0x62,  0x16,  0xfe,
13343   0x94,  0x14,  0xfe,  0x10,  0x13,  0x91,  0x38,  0x66,  0x1b,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13344   0x03,  0xae,  0x21,  0xfe,  0x56,  0x16,  0xfe,  0x6c,  0x10,  0x17,  0x10,  0x71,  0xfe,  0x30,  0xbc,  0xfe,
13345   0xb2,  0xbc,  0x91,  0xc5,  0x66,  0x1b,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xc5,  0x90,  0xfe,  0x9a,
13346   0x16,  0xfe,  0x5c,  0x14,  0x34,  0x03,  0xae,  0x21,  0xfe,  0x86,  0x16,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13347   0xf6,  0x10,  0x71,  0xfe,  0x18,  0xfe,  0x54,  0xfe,  0x19,  0xfe,  0x55,  0xfc,  0xfe,  0x1d,  0xf7,  0x4f,
13348   0x90,  0xfe,  0xc0,  0x16,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x91,  0x4f,  0x47,  0xfe,  0x83,  0x58,
13349   0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x10,  0xfe,  0x81,  0xe7,  0x10,  0x11,  0xfe,  0xdd,  0x00,  0x63,
13350   0x27,  0x03,  0x63,  0x27,  0xfe,  0x12,  0x45,  0x21,  0xfe,  0xb0,  0x16,  0x14,  0x06,  0x37,  0x95,  0xa9,
13351   0x02,  0x29,  0xfe,  0x39,  0xf0,  0xfe,  0x04,  0x17,  0x23,  0x03,  0xfe,  0x7e,  0x18,  0x1c,  0x1a,  0x5d,
13352   0x13,  0x0d,  0x03,  0x71,  0x05,  0xcb,  0x1c,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,  0x78,  0x2c,
13353   0x46,  0x2f,  0x07,  0x2d,  0xfe,  0x3c,  0x13,  0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x3c,  0x8a,  0x0a,
13354   0x42,  0x01,  0x0e,  0xb0,  0xfe,  0x3e,  0x12,  0xf0,  0xfe,  0x45,  0x48,  0x01,  0xe3,  0xfe,  0x00,  0xcc,
13355   0xb0,  0xfe,  0xf3,  0x13,  0x3d,  0x75,  0x07,  0x10,  0xa3,  0x0a,  0x80,  0x01,  0x0e,  0xf2,  0x01,  0x6f,
13356   0xfe,  0x16,  0x10,  0x07,  0x7e,  0x85,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xf6,  0xfe,  0xd6,  0xf0,
13357   0xfe,  0x24,  0x17,  0x17,  0x0b,  0x03,  0xfe,  0x9c,  0xe7,  0x0b,  0x0f,  0xfe,  0x15,  0x00,  0x59,  0x76,
13358   0x27,  0x01,  0xda,  0x17,  0x06,  0x03,  0x3c,  0x8a,  0x09,  0x4a,  0x1d,  0x35,  0x11,  0x2d,  0x01,  0x6f,
13359   0x17,  0x06,  0x03,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x79,  0xc7,  0x68,  0xc8,  0xfe,  0x48,  0x55,
13360   0x34,  0xfe,  0xc9,  0x55,  0x03,  0x1e,  0x98,  0x73,  0x12,  0x98,  0x03,  0x0a,  0x99,  0x01,  0x0e,  0xf0,
13361   0x0a,  0x40,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x16,  0xfe,  0xf0,  0x17,  0x73,  0x75,  0x03,  0x0a,  0x42,
13362   0x01,  0x0e,  0x07,  0x10,  0x45,  0x0a,  0x51,  0x01,  0x9e,  0x0a,  0x40,  0x01,  0x0e,  0x73,  0x75,  0x03,
13363   0xfe,  0x4e,  0xe4,  0x1a,  0x64,  0xfe,  0x24,  0x18,  0x05,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0x5b,
13364   0xfe,  0x4e,  0xe4,  0xc2,  0x64,  0xfe,  0x36,  0x18,  0x05,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1b,
13365   0xdc,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x64,  0xfe,  0x48,  0x18,  0x05,  0xfe,  0x94,  0x00,  0xfe,
13366   0x02,  0xe6,  0x19,  0xfe,  0x08,  0x10,  0x05,  0xfe,  0x96,  0x00,  0xfe,  0x02,  0xe6,  0x2c,  0xfe,  0x4e,
13367   0x45,  0xfe,  0x0c,  0x12,  0xaf,  0xff,  0x04,  0x68,  0x54,  0xde,  0x1c,  0x69,  0x03,  0x07,  0x7a,  0xfe,
13368   0x5a,  0xf0,  0xfe,  0x74,  0x18,  0x24,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1b,  0xfe,  0x5a,
13369   0xf0,  0xfe,  0x82,  0x18,  0x24,  0xc3,  0xfe,  0x26,  0x10,  0x07,  0x1a,  0x5d,  0x24,  0x2c,  0xdc,  0x07,
13370   0x0b,  0x5d,  0x24,  0x93,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x5d,  0x24,  0x4d,  0x9f,  0xad,  0x03,  0x14,
13371   0xfe,  0x09,  0x00,  0x01,  0x33,  0xfe,  0x04,  0xfe,  0x7d,  0x05,  0x7f,  0xf9,  0x03,  0x25,  0xfe,  0xca,
13372   0x18,  0xfe,  0x14,  0xf0,  0x08,  0x65,  0xfe,  0xc6,  0x18,  0x03,  0xff,  0x1a,  0x00,  0x00,
13373 };
13374
13375 STATIC unsigned short _adv_asc3550_size =
13376         sizeof(_adv_asc3550_buf); /* 0x13AD */
13377 STATIC ADV_DCNT _adv_asc3550_chksum =
13378         0x04D52DDDUL; /* Expanded little-endian checksum. */
13379
13380 /* Microcode buffer is kept after initialization for error recovery. */
13381 STATIC unsigned char _adv_asc38C0800_buf[] = {
13382   0x00,  0x00,  0x00,  0xf2,  0x00,  0xf0,  0x00,  0xfc,  0x00,  0x16,  0x18,  0xe4,  0x01,  0x00,  0x48,  0xe4,
13383   0x18,  0x80,  0x03,  0xf6,  0x02,  0x00,  0xce,  0x19,  0x00,  0xfa,  0xff,  0xff,  0x1c,  0x0f,  0x00,  0xf6,
13384   0x9e,  0xe7,  0xff,  0x00,  0x82,  0xe7,  0x00,  0xea,  0x01,  0xfa,  0x01,  0xe6,  0x09,  0xe7,  0x55,  0xf0,
13385   0x01,  0xf6,  0x03,  0x00,  0x04,  0x00,  0x10,  0x00,  0x1e,  0xf0,  0x85,  0xf0,  0x18,  0xf4,  0x08,  0x00,
13386   0xbc,  0x00,  0x38,  0x54,  0x00,  0xec,  0xd5,  0xf0,  0x82,  0x0d,  0x00,  0xe6,  0x86,  0xf0,  0xb1,  0xf0,
13387   0x98,  0x57,  0x01,  0xfc,  0xb4,  0x00,  0xd4,  0x01,  0x0c,  0x1c,  0x3e,  0x1c,  0x3c,  0x00,  0xbb,  0x00,
13388   0x00,  0x10,  0xba,  0x19,  0x02,  0x80,  0x32,  0xf0,  0x7c,  0x0d,  0x02,  0x13,  0xba,  0x13,  0x18,  0x40,
13389   0x00,  0x57,  0x01,  0xea,  0x02,  0xfc,  0x03,  0xfc,  0x3e,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x74,  0x01,
13390   0x76,  0x01,  0xb9,  0x54,  0x3e,  0x57,  0x00,  0x80,  0x03,  0xe6,  0xb6,  0x00,  0xc0,  0x00,  0x01,  0x01,
13391   0x3e,  0x01,  0x7a,  0x01,  0xca,  0x08,  0xce,  0x10,  0x16,  0x11,  0x04,  0x12,  0x08,  0x12,  0x02,  0x4a,
13392   0xbb,  0x55,  0x3c,  0x56,  0x03,  0x58,  0x1b,  0x80,  0x30,  0xe4,  0x4b,  0xe4,  0x5d,  0xf0,  0x02,  0xfa,
13393   0x20,  0x00,  0x32,  0x00,  0x40,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,  0x68,  0x01,  0x6a,  0x01,
13394   0x70,  0x01,  0x72,  0x01,  0x78,  0x01,  0x7c,  0x01,  0x62,  0x0a,  0x86,  0x0d,  0x06,  0x13,  0x4c,  0x1c,
13395   0x04,  0x80,  0x4a,  0xe4,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x0c,  0x00,  0x0f,  0x00,  0x47,  0x00,
13396   0xbe,  0x00,  0x00,  0x01,  0x20,  0x11,  0x5c,  0x16,  0x32,  0x1c,  0x38,  0x1c,  0x4e,  0x1c,  0x10,  0x44,
13397   0x00,  0x4c,  0x04,  0xea,  0x5c,  0xf0,  0xa7,  0xf0,  0x04,  0xf6,  0x03,  0xfa,  0x05,  0x00,  0x34,  0x00,
13398   0x36,  0x00,  0x98,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x4a,  0x0b,  0x42,  0x0c,  0x12,  0x0f,
13399   0x0c,  0x10,  0x22,  0x11,  0x0a,  0x12,  0x04,  0x13,  0x30,  0x1c,  0x02,  0x48,  0x00,  0x4e,  0x42,  0x54,
13400   0x44,  0x55,  0xbd,  0x56,  0x06,  0x83,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,  0x59,  0xf0,  0xb8,  0xf0,
13401   0x4b,  0xf4,  0x06,  0xf7,  0x0e,  0xf7,  0x04,  0xfc,  0x05,  0xfc,  0x06,  0x00,  0x19,  0x00,  0x33,  0x00,
13402   0x9b,  0x00,  0xa4,  0x00,  0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe1,  0x00,  0xe7,  0x00,  0xe2,  0x03,
13403   0x08,  0x0f,  0x02,  0x10,  0x04,  0x10,  0x0a,  0x10,  0x0a,  0x13,  0x0c,  0x13,  0x12,  0x13,  0x24,  0x14,
13404   0x34,  0x14,  0x04,  0x16,  0x08,  0x16,  0xa4,  0x17,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x08,  0x44,
13405   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x01,  0x48,  0x68,  0x54,  0x3a,  0x55,  0x83,  0x55,
13406   0xe5,  0x55,  0xb0,  0x57,  0x01,  0x58,  0x83,  0x59,  0x05,  0xe6,  0x0b,  0xf0,  0x0c,  0xf0,  0x04,  0xf8,
13407   0x05,  0xf8,  0x07,  0x00,  0x0a,  0x00,  0x1c,  0x00,  0x1e,  0x00,  0x9e,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13408   0xb9,  0x00,  0xe0,  0x00,  0x22,  0x01,  0x26,  0x01,  0x79,  0x01,  0x7e,  0x01,  0xc4,  0x01,  0xc6,  0x01,
13409   0x80,  0x02,  0x5e,  0x03,  0xee,  0x04,  0x9a,  0x06,  0xf8,  0x07,  0x62,  0x08,  0x68,  0x08,  0x69,  0x08,
13410   0xd6,  0x08,  0xe9,  0x09,  0xfa,  0x0b,  0x2e,  0x0f,  0x12,  0x10,  0x1a,  0x10,  0xed,  0x10,  0xf1,  0x10,
13411   0x2a,  0x11,  0x06,  0x12,  0x0c,  0x12,  0x3e,  0x12,  0x10,  0x13,  0x16,  0x13,  0x1e,  0x13,  0x46,  0x14,
13412   0x76,  0x14,  0x82,  0x14,  0x36,  0x15,  0xca,  0x15,  0x6b,  0x18,  0xbe,  0x18,  0xca,  0x18,  0xe6,  0x19,
13413   0x12,  0x1c,  0x46,  0x1c,  0x9c,  0x32,  0x00,  0x40,  0x0e,  0x47,  0xfe,  0x9c,  0xf0,  0x2b,  0x02,  0xfe,
13414   0xac,  0x0d,  0xff,  0x10,  0x00,  0x00,  0xd7,  0xfe,  0xe8,  0x19,  0x00,  0xd6,  0xfe,  0x84,  0x01,  0xff,
13415   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13416   0x00,  0xfe,  0x4c,  0x00,  0x5b,  0xff,  0x04,  0x00,  0x00,  0x11,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13417   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x11,
13418   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xd6,
13419   0x2c,  0x99,  0x0a,  0x01,  0xfe,  0xc2,  0x0f,  0xfe,  0x04,  0xf7,  0xd6,  0x99,  0x0a,  0x42,  0x2c,  0xfe,
13420   0x3d,  0xf0,  0xfe,  0x06,  0x02,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x91,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,
13421   0x90,  0xf0,  0xfe,  0xf4,  0x01,  0xfe,  0x8f,  0xf0,  0xa7,  0x03,  0x5d,  0x4d,  0x02,  0xfe,  0xc8,  0x0d,
13422   0x01,  0xfe,  0x38,  0x0e,  0xfe,  0xdd,  0x12,  0xfe,  0xfc,  0x10,  0xfe,  0x28,  0x1c,  0x03,  0xfe,  0xa6,
13423   0x00,  0xfe,  0xd3,  0x12,  0x41,  0x14,  0xfe,  0xa6,  0x00,  0xc2,  0xfe,  0x48,  0xf0,  0xfe,  0x8a,  0x02,
13424   0xfe,  0x49,  0xf0,  0xfe,  0xa4,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc2,  0x02,  0xfe,  0x46,  0xf0,  0xfe,
13425   0x54,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x5a,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x48,  0x02,  0xfe,  0x44,
13426   0xf0,  0xfe,  0x4c,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x50,  0x02,  0x18,  0x0a,  0xaa,  0x18,  0x06,  0x14,
13427   0xa1,  0x02,  0x2b,  0xfe,  0x00,  0x1c,  0xe7,  0xfe,  0x02,  0x1c,  0xe6,  0xfe,  0x1e,  0x1c,  0xfe,  0xe9,
13428   0x10,  0x01,  0xfe,  0x18,  0x18,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xce,  0x09,  0x70,  0x01,  0xa8,
13429   0x02,  0x2b,  0x15,  0x59,  0x39,  0xa2,  0x01,  0xfe,  0x58,  0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xbd,
13430   0x10,  0x09,  0x70,  0x01,  0x87,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x18,  0x06,
13431   0x14,  0xa1,  0x2c,  0x1c,  0x2b,  0xfe,  0x3d,  0xf0,  0xfe,  0x06,  0x02,  0x23,  0xfe,  0x98,  0x02,  0xfe,
13432   0x5a,  0x1c,  0xf8,  0xfe,  0x14,  0x1c,  0x15,  0xfe,  0x30,  0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,
13433   0x18,  0x06,  0x14,  0xa1,  0x02,  0xd7,  0x22,  0x20,  0x07,  0x11,  0x35,  0xfe,  0x69,  0x10,  0x18,  0x06,
13434   0x14,  0xa1,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0x43,  0x13,  0x20,  0xfe,  0x05,  0xf6,  0xce,  0x01,  0xfe,
13435   0x4a,  0x17,  0x08,  0x54,  0x58,  0x37,  0x12,  0x2f,  0x42,  0x92,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13436   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x01,  0x73,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x09,
13437   0xa4,  0x01,  0x0e,  0xfe,  0xc8,  0x54,  0x6b,  0xfe,  0x10,  0x03,  0x01,  0xfe,  0x82,  0x16,  0x02,  0x2b,
13438   0x2c,  0x4f,  0xfe,  0x02,  0xe8,  0x2a,  0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,
13439   0x27,  0xf0,  0xfe,  0xe0,  0x01,  0xfe,  0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xa7,  0xfe,  0x40,  0x1c,  0x1c,
13440   0xd9,  0xfe,  0x26,  0xf0,  0xfe,  0x5a,  0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x48,  0x03,  0xfe,  0x11,  0xf0,
13441   0xa7,  0xfe,  0xef,  0x10,  0xfe,  0x9f,  0xf0,  0xfe,  0x68,  0x03,  0xf9,  0x10,  0xfe,  0x11,  0x00,  0x02,
13442   0x65,  0x2c,  0xfe,  0x48,  0x1c,  0xf9,  0x08,  0x05,  0x1b,  0xfe,  0x18,  0x13,  0x21,  0x22,  0xa3,  0xb7,
13443   0x13,  0xa3,  0x09,  0x46,  0x01,  0x0e,  0xb7,  0x78,  0x01,  0xfe,  0xb4,  0x16,  0x12,  0xd1,  0x1c,  0xd9,
13444   0xfe,  0x01,  0xf0,  0xd9,  0xfe,  0x82,  0xf0,  0xfe,  0x96,  0x03,  0xfa,  0x12,  0xfe,  0xe4,  0x00,  0x27,
13445   0xfe,  0xa8,  0x03,  0x1c,  0x34,  0x1d,  0xfe,  0xb8,  0x03,  0x01,  0x4b,  0xfe,  0x06,  0xf0,  0xfe,  0xc8,
13446   0x03,  0x95,  0x86,  0xfe,  0x0a,  0xf0,  0xfe,  0x8a,  0x06,  0x02,  0x24,  0x03,  0x70,  0x28,  0x17,  0xfe,
13447   0xfa,  0x04,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,  0xd8,  0xf9,  0x2c,  0x99,  0x19,
13448   0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x74,  0x01,  0xaf,  0x8c,
13449   0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x17,  0xda,  0x09,  0xd1,  0x01,  0x0e,  0x8d,  0x51,  0x64,  0x79,
13450   0x2a,  0x03,  0x70,  0x28,  0xfe,  0x10,  0x12,  0x15,  0x6d,  0x01,  0x36,  0x7b,  0xfe,  0x6a,  0x02,  0x02,
13451   0xd8,  0xc7,  0x81,  0xc8,  0x83,  0x1c,  0x24,  0x27,  0xfe,  0x40,  0x04,  0x1d,  0xfe,  0x3c,  0x04,  0x3b,
13452   0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x4e,  0x12,  0x2d,  0xff,  0x02,  0x00,  0x10,  0x01,  0x0b,
13453   0x1d,  0xfe,  0xe4,  0x04,  0x2d,  0x01,  0x0b,  0x1d,  0x24,  0x33,  0x31,  0xde,  0xfe,  0x4c,  0x44,  0xfe,
13454   0x4c,  0x12,  0x51,  0xfe,  0x44,  0x48,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0x4f,  0x79,  0x2a,
13455   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x62,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x2a,  0x13,  0x32,
13456   0x07,  0x82,  0xfe,  0x52,  0x13,  0xfe,  0x20,  0x10,  0x0f,  0x6f,  0xfe,  0x4c,  0x54,  0x6b,  0xda,  0xfe,
13457   0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x40,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x08,  0x13,  0x32,  0x07,
13458   0x82,  0xfe,  0x30,  0x13,  0x08,  0x05,  0x1b,  0xfe,  0x1c,  0x12,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,
13459   0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,  0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x2d,  0x12,  0xfe,  0xe6,
13460   0x00,  0xfe,  0x1c,  0x90,  0xfe,  0x40,  0x5c,  0x04,  0x15,  0x9d,  0x01,  0x36,  0x02,  0x2b,  0xfe,  0x42,
13461   0x5b,  0x99,  0x19,  0xfe,  0x46,  0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x87,  0x80,  0xfe,
13462   0x31,  0xe4,  0x5b,  0x08,  0x05,  0x0a,  0xfe,  0x84,  0x13,  0xfe,  0x20,  0x80,  0x07,  0x19,  0xfe,  0x7c,
13463   0x12,  0x53,  0x05,  0x06,  0xfe,  0x6c,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x28,  0x17,  0xfe,  0x90,  0x05,
13464   0xfe,  0x31,  0xe4,  0x5a,  0x53,  0x05,  0x0a,  0xfe,  0x56,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x28,  0xfe,
13465   0x4e,  0x12,  0x67,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x48,  0x05,  0x1c,  0x34,  0xfe,  0x89,  0x48,
13466   0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x56,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0x12,  0xfe,  0xe3,  0x00,
13467   0x21,  0x53,  0xfe,  0x4a,  0xf0,  0xfe,  0x76,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0x70,  0x05,  0x88,  0x25,
13468   0xfe,  0x21,  0x00,  0xab,  0x25,  0xfe,  0x22,  0x00,  0xaa,  0x25,  0x58,  0xfe,  0x09,  0x48,  0xff,  0x02,
13469   0x00,  0x10,  0x27,  0xfe,  0x86,  0x05,  0x26,  0xfe,  0xa8,  0x05,  0xfe,  0xe2,  0x08,  0x53,  0x05,  0xcb,
13470   0x4d,  0x01,  0xb0,  0x25,  0x06,  0x13,  0xd3,  0x39,  0xfe,  0x27,  0x01,  0x08,  0x05,  0x1b,  0xfe,  0x22,
13471   0x12,  0x41,  0x01,  0xb2,  0x15,  0x9d,  0x08,  0x05,  0x06,  0x4d,  0x15,  0xfe,  0x0d,  0x00,  0x01,  0x36,
13472   0x7b,  0xfe,  0x64,  0x0d,  0x02,  0x24,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0xeb,  0x03,  0x5c,  0x28,  0xfe,
13473   0x36,  0x13,  0x41,  0x01,  0xb2,  0x26,  0xfe,  0x18,  0x06,  0x09,  0x06,  0x53,  0x05,  0x1f,  0xfe,  0x02,
13474   0x12,  0x50,  0x01,  0xfe,  0x9e,  0x15,  0x1d,  0xfe,  0x0e,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,
13475   0xe5,  0x00,  0x03,  0x5c,  0xc1,  0x0c,  0x5c,  0x03,  0xcd,  0x28,  0xfe,  0x62,  0x12,  0x03,  0x45,  0x28,
13476   0xfe,  0x5a,  0x13,  0x01,  0xfe,  0x0c,  0x19,  0x01,  0xfe,  0x76,  0x19,  0xfe,  0x43,  0x48,  0xc4,  0xcc,
13477   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0x8b,  0xc4,  0x6e,  0x41,  0x01,  0xb2,
13478   0x26,  0xfe,  0x82,  0x06,  0x53,  0x05,  0x1a,  0xe9,  0x91,  0x09,  0x59,  0x01,  0xfe,  0xcc,  0x15,  0x1d,
13479   0xfe,  0x78,  0x06,  0x12,  0xa5,  0x01,  0x4b,  0x12,  0xfe,  0xe5,  0x00,  0x03,  0x45,  0xc1,  0x0c,  0x45,
13480   0x18,  0x06,  0x01,  0xb2,  0xfa,  0x76,  0x74,  0x01,  0xaf,  0x8c,  0x12,  0xfe,  0xe2,  0x00,  0x27,  0xdb,
13481   0x1c,  0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0xb6,  0x06,  0x94,  0xfe,  0x6c,  0x07,  0xfe,  0x06,  0xf0,  0xfe,
13482   0x74,  0x07,  0x95,  0x86,  0x02,  0x24,  0x08,  0x05,  0x0a,  0xfe,  0x2e,  0x12,  0x16,  0x19,  0x01,  0x0b,
13483   0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0xfe,  0x99,  0xa4,  0x01,
13484   0x0b,  0x16,  0x00,  0x02,  0xfe,  0x42,  0x08,  0x68,  0x05,  0x1a,  0xfe,  0x38,  0x12,  0x08,  0x05,  0x1a,
13485   0xfe,  0x30,  0x13,  0x16,  0xfe,  0x1b,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x00,  0x01,
13486   0x0b,  0x16,  0x00,  0x01,  0x0b,  0x16,  0x06,  0x01,  0x0b,  0x16,  0x00,  0x02,  0xe2,  0x6c,  0x58,  0xbe,
13487   0x50,  0xfe,  0x9a,  0x81,  0x55,  0x1b,  0x7a,  0xfe,  0x42,  0x07,  0x09,  0x1b,  0xfe,  0x09,  0x6f,  0xba,
13488   0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x69,  0x6d,  0x8b,  0x6c,  0x7f,  0x27,  0xfe,  0x54,  0x07,  0x1c,
13489   0x34,  0xfe,  0x0a,  0xf0,  0xfe,  0x42,  0x07,  0x95,  0x86,  0x94,  0xfe,  0x6c,  0x07,  0x02,  0x24,  0x01,
13490   0x4b,  0x02,  0xdb,  0x16,  0x1f,  0x02,  0xdb,  0xfe,  0x9c,  0xf7,  0xdc,  0xfe,  0x2c,  0x90,  0xfe,  0xae,
13491   0x90,  0x56,  0xfe,  0xda,  0x07,  0x0c,  0x60,  0x14,  0x61,  0x08,  0x54,  0x5a,  0x37,  0x22,  0x20,  0x07,
13492   0x11,  0xfe,  0x0e,  0x12,  0x8d,  0xfe,  0x80,  0x80,  0x39,  0x20,  0x6a,  0x2a,  0xfe,  0x06,  0x10,  0xfe,
13493   0x83,  0xe7,  0xfe,  0x48,  0x00,  0xab,  0xfe,  0x03,  0x40,  0x08,  0x54,  0x5b,  0x37,  0x01,  0xb3,  0xb8,
13494   0xfe,  0x1f,  0x40,  0x13,  0x62,  0x01,  0xef,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,
13495   0xfe,  0xc6,  0x51,  0x88,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,  0xfe,  0x0c,
13496   0x90,  0xfe,  0x8e,  0x90,  0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x0c,  0x3d,  0x14,  0x3e,  0xfe,  0x4a,
13497   0x10,  0x08,  0x05,  0x5a,  0xfe,  0x2a,  0x12,  0xfe,  0x2c,  0x90,  0xfe,  0xae,  0x90,  0x0c,  0x60,  0x14,
13498   0x61,  0x08,  0x05,  0x5b,  0x8b,  0x01,  0xb3,  0xfe,  0x1f,  0x80,  0x13,  0x62,  0xfe,  0x44,  0x90,  0xfe,
13499   0xc6,  0x90,  0x0c,  0x3f,  0x14,  0x40,  0xfe,  0x08,  0x90,  0xfe,  0x8a,  0x90,  0x0c,  0x5e,  0x14,  0x5f,
13500   0xfe,  0x40,  0x90,  0xfe,  0xc2,  0x90,  0x0c,  0x3d,  0x14,  0x3e,  0x0c,  0x2e,  0x14,  0x3c,  0x21,  0x0c,
13501   0x49,  0x0c,  0x63,  0x08,  0x54,  0x1f,  0x37,  0x2c,  0x0f,  0xfe,  0x4e,  0x11,  0x27,  0xdd,  0xfe,  0x9e,
13502   0xf0,  0xfe,  0x76,  0x08,  0xbc,  0x17,  0x34,  0x2c,  0x77,  0xe6,  0xc5,  0xfe,  0x9a,  0x08,  0xc6,  0xfe,
13503   0xb8,  0x08,  0x94,  0xfe,  0x8e,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x94,  0x08,  0x95,  0x86,  0x02,  0x24,
13504   0x01,  0x4b,  0xfe,  0xc9,  0x10,  0x16,  0x1f,  0xfe,  0xc9,  0x10,  0x68,  0x05,  0x06,  0xfe,  0x10,  0x12,
13505   0x68,  0x05,  0x0a,  0x4e,  0x08,  0x05,  0x0a,  0xfe,  0x90,  0x12,  0xfe,  0x2e,  0x1c,  0x02,  0xfe,  0x18,
13506   0x0b,  0x68,  0x05,  0x06,  0x4e,  0x68,  0x05,  0x0a,  0xfe,  0x7a,  0x12,  0xfe,  0x2c,  0x1c,  0xfe,  0xaa,
13507   0xf0,  0xfe,  0xd2,  0x09,  0xfe,  0xac,  0xf0,  0xfe,  0x00,  0x09,  0x02,  0xfe,  0xde,  0x09,  0xfe,  0xb7,
13508   0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0x02,  0xf6,  0x1a,  0x50,  0xfe,  0x70,  0x18,  0xfe,  0xf1,  0x18,  0xfe,
13509   0x40,  0x55,  0xfe,  0xe1,  0x55,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0xfe,  0x14,  0x59,  0xfe,  0x95,
13510   0x59,  0x1c,  0x85,  0xfe,  0x8c,  0xf0,  0xfe,  0xfc,  0x08,  0xfe,  0xac,  0xf0,  0xfe,  0xf0,  0x08,  0xb5,
13511   0xfe,  0xcb,  0x10,  0xfe,  0xad,  0xf0,  0xfe,  0x0c,  0x09,  0x02,  0xfe,  0x18,  0x0b,  0xb6,  0xfe,  0xbf,
13512   0x10,  0xfe,  0x2b,  0xf0,  0x85,  0xf4,  0x1e,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xc2,  0xfe,  0xd2,
13513   0xf0,  0x85,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x17,  0x85,  0x03,  0xd2,  0x1e,  0x06,  0x17,  0x85,  0xc5,
13514   0x4a,  0xc6,  0x4a,  0xb5,  0xb6,  0xfe,  0x89,  0x10,  0x74,  0x67,  0x2d,  0x15,  0x9d,  0x01,  0x36,  0x10,
13515   0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x65,  0x10,  0x80,  0x02,  0x65,  0xfe,  0x98,  0x80,  0xfe,  0x19,
13516   0xe4,  0x0a,  0xfe,  0x1a,  0x12,  0x51,  0xfe,  0x19,  0x82,  0xfe,  0x6c,  0x18,  0xfe,  0x44,  0x54,  0xbe,
13517   0xfe,  0x19,  0x81,  0xfe,  0x74,  0x18,  0x8f,  0x90,  0x17,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0x08,  0x05,
13518   0x5a,  0xec,  0x03,  0x2e,  0x29,  0x3c,  0x0c,  0x3f,  0x14,  0x40,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x6c,
13519   0x18,  0xfe,  0xed,  0x18,  0xfe,  0x44,  0x54,  0xfe,  0xe5,  0x54,  0x3a,  0x3f,  0x3b,  0x40,  0x03,  0x49,
13520   0x29,  0x63,  0x8f,  0xfe,  0xe3,  0x54,  0xfe,  0x74,  0x18,  0xfe,  0xf5,  0x18,  0x8f,  0xfe,  0xe3,  0x54,
13521   0x90,  0xc0,  0x56,  0xfe,  0xce,  0x08,  0x02,  0x4a,  0xfe,  0x37,  0xf0,  0xfe,  0xda,  0x09,  0xfe,  0x8b,
13522   0xf0,  0xfe,  0x60,  0x09,  0x02,  0x4a,  0x08,  0x05,  0x0a,  0x23,  0xfe,  0xfa,  0x0a,  0x3a,  0x49,  0x3b,
13523   0x63,  0x56,  0xfe,  0x3e,  0x0a,  0x0f,  0xfe,  0xc0,  0x07,  0x41,  0x98,  0x00,  0xad,  0xfe,  0x01,  0x59,
13524   0xfe,  0x52,  0xf0,  0xfe,  0x0c,  0x0a,  0x8f,  0x7a,  0xfe,  0x24,  0x0a,  0x3a,  0x49,  0x8f,  0xfe,  0xe3,
13525   0x54,  0x57,  0x49,  0x7d,  0x63,  0xfe,  0x14,  0x58,  0xfe,  0x95,  0x58,  0x02,  0x4a,  0x3a,  0x49,  0x3b,
13526   0x63,  0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0xbe,  0x57,  0x49,  0x57,  0x63,  0x02,  0x4a,  0x08,  0x05,
13527   0x5a,  0xfe,  0x82,  0x12,  0x08,  0x05,  0x1f,  0xfe,  0x66,  0x13,  0x22,  0x62,  0xb7,  0xfe,  0x03,  0xa1,
13528   0xfe,  0x83,  0x80,  0xfe,  0xc8,  0x44,  0xfe,  0x2e,  0x13,  0xfe,  0x04,  0x91,  0xfe,  0x86,  0x91,  0x6a,
13529   0x2a,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x56,  0xe0,  0x03,  0x60,  0x29,  0x61,  0x0c,  0x7f,  0x14,
13530   0x80,  0x57,  0x60,  0x7d,  0x61,  0x01,  0xb3,  0xb8,  0x6a,  0x2a,  0x13,  0x62,  0x9b,  0x2e,  0x9c,  0x3c,
13531   0x3a,  0x3f,  0x3b,  0x40,  0x90,  0xc0,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0x01,  0xef,
13532   0xfe,  0x36,  0x10,  0x21,  0x0c,  0x7f,  0x0c,  0x80,  0x3a,  0x3f,  0x3b,  0x40,  0xe4,  0x08,  0x05,  0x1f,
13533   0x17,  0xe0,  0x3a,  0x3d,  0x3b,  0x3e,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0x03,  0x5e,  0x29,  0x5f,
13534   0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,  0x57,  0x49,  0x7d,  0x63,  0x02,  0xfe,  0xf4,  0x09,  0x08,  0x05,
13535   0x1f,  0x17,  0xe0,  0x08,  0x05,  0xfe,  0xf7,  0x00,  0x37,  0xbe,  0xfe,  0x19,  0x81,  0x50,  0xfe,  0x10,
13536   0x90,  0xfe,  0x92,  0x90,  0xfe,  0xd3,  0x10,  0x32,  0x07,  0xa6,  0x17,  0xfe,  0x08,  0x09,  0x12,  0xa6,
13537   0x08,  0x05,  0x0a,  0xfe,  0x14,  0x13,  0x03,  0x3d,  0x29,  0x3e,  0x56,  0xfe,  0x08,  0x09,  0xfe,  0x0c,
13538   0x58,  0xfe,  0x8d,  0x58,  0x02,  0x4a,  0x21,  0x41,  0xfe,  0x19,  0x80,  0xe7,  0x08,  0x05,  0x0a,  0xfe,
13539   0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,  0xf4,  0xc2,  0xfe,  0xd1,  0xf0,  0xe2,  0x15,  0x7e,
13540   0x01,  0x36,  0x10,  0xfe,  0x44,  0x00,  0xfe,  0x8e,  0x10,  0xfe,  0x6c,  0x19,  0x57,  0x3d,  0xfe,  0xed,
13541   0x19,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0xf4,  0x1e,  0xfe,  0x00,  0xff,  0x35,  0xfe,
13542   0x74,  0x10,  0xc2,  0xfe,  0xd2,  0xf0,  0xfe,  0xa6,  0x0b,  0xfe,  0x76,  0x18,  0x1e,  0x19,  0x8a,  0x03,
13543   0xd2,  0x1e,  0x06,  0xfe,  0x08,  0x13,  0x10,  0xfe,  0x16,  0x00,  0x02,  0x65,  0xfe,  0xd1,  0xf0,  0xfe,
13544   0xb8,  0x0b,  0x15,  0x7e,  0x01,  0x36,  0x10,  0xfe,  0x17,  0x00,  0xfe,  0x42,  0x10,  0xfe,  0xce,  0xf0,
13545   0xfe,  0xbe,  0x0b,  0xfe,  0x3c,  0x10,  0xfe,  0xcd,  0xf0,  0xfe,  0xca,  0x0b,  0x10,  0xfe,  0x22,  0x00,
13546   0x02,  0x65,  0xfe,  0xcb,  0xf0,  0xfe,  0xd6,  0x0b,  0x10,  0xfe,  0x24,  0x00,  0x02,  0x65,  0xfe,  0xd0,
13547   0xf0,  0xfe,  0xe0,  0x0b,  0x10,  0x9e,  0xe5,  0xfe,  0xcf,  0xf0,  0xfe,  0xea,  0x0b,  0x10,  0x58,  0xfe,
13548   0x10,  0x10,  0xfe,  0xcc,  0xf0,  0xe2,  0x68,  0x05,  0x1f,  0x4d,  0x10,  0xfe,  0x12,  0x00,  0x2c,  0x0f,
13549   0xfe,  0x4e,  0x11,  0x27,  0xfe,  0x00,  0x0c,  0xfe,  0x9e,  0xf0,  0xfe,  0x14,  0x0c,  0xbc,  0x17,  0x34,
13550   0x2c,  0x77,  0xe6,  0xc5,  0x24,  0xc6,  0x24,  0x2c,  0xfa,  0x27,  0xfe,  0x20,  0x0c,  0x1c,  0x34,  0x94,
13551   0xfe,  0x3c,  0x0c,  0x95,  0x86,  0xc5,  0xdc,  0xc6,  0xdc,  0x02,  0x24,  0x01,  0x4b,  0xfe,  0xdb,  0x10,
13552   0x12,  0xfe,  0xe8,  0x00,  0xb5,  0xb6,  0x74,  0xc7,  0x81,  0xc8,  0x83,  0xfe,  0x89,  0xf0,  0x24,  0x33,
13553   0x31,  0xe1,  0xc7,  0x81,  0xc8,  0x83,  0x27,  0xfe,  0x66,  0x0c,  0x1d,  0x24,  0x33,  0x31,  0xdf,  0xbc,
13554   0x4e,  0x10,  0xfe,  0x42,  0x00,  0x02,  0x65,  0x7c,  0x06,  0xfe,  0x81,  0x49,  0x17,  0xfe,  0x2c,  0x0d,
13555   0x08,  0x05,  0x0a,  0xfe,  0x44,  0x13,  0x10,  0x00,  0x55,  0x0a,  0xfe,  0x54,  0x12,  0x55,  0xfe,  0x28,
13556   0x00,  0x23,  0xfe,  0x9a,  0x0d,  0x09,  0x46,  0x01,  0x0e,  0x07,  0x00,  0x66,  0x44,  0xfe,  0x28,  0x00,
13557   0xfe,  0xe2,  0x10,  0x01,  0xf5,  0x01,  0xf6,  0x09,  0xa4,  0x01,  0xfe,  0x26,  0x0f,  0x64,  0x12,  0x2f,
13558   0x01,  0x73,  0x02,  0x2b,  0x10,  0xfe,  0x44,  0x00,  0x55,  0x0a,  0xe9,  0x44,  0x0a,  0xfe,  0xb4,  0x10,
13559   0x01,  0xb0,  0x44,  0x0a,  0xfe,  0xaa,  0x10,  0x01,  0xb0,  0xfe,  0x19,  0x82,  0xfe,  0x34,  0x46,  0xac,
13560   0x44,  0x0a,  0x10,  0xfe,  0x43,  0x00,  0xfe,  0x96,  0x10,  0x08,  0x54,  0x0a,  0x37,  0x01,  0xf5,  0x01,
13561   0xf6,  0x64,  0x12,  0x2f,  0x01,  0x73,  0x99,  0x0a,  0x64,  0x42,  0x92,  0x02,  0xfe,  0x2e,  0x03,  0x08,
13562   0x05,  0x0a,  0x8a,  0x44,  0x0a,  0x10,  0x00,  0xfe,  0x5c,  0x10,  0x68,  0x05,  0x1a,  0xfe,  0x58,  0x12,
13563   0x08,  0x05,  0x1a,  0xfe,  0x50,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x50,  0x0d,  0xfe,
13564   0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x56,  0x0d,  0x08,  0x54,  0x1a,  0x37,  0xfe,  0xa9,  0x10,  0x10,
13565   0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0a,  0x50,  0xfe,  0x2e,  0x10,  0x10,  0xfe,  0x13,  0x00,  0xfe,
13566   0x10,  0x10,  0x10,  0x6f,  0xab,  0x10,  0xfe,  0x41,  0x00,  0xaa,  0x10,  0xfe,  0x24,  0x00,  0x8c,  0xb5,
13567   0xb6,  0x74,  0x03,  0x70,  0x28,  0x23,  0xd8,  0x50,  0xfe,  0x04,  0xe6,  0x1a,  0xfe,  0x9d,  0x41,  0xfe,
13568   0x1c,  0x42,  0x64,  0x01,  0xe3,  0x02,  0x2b,  0xf8,  0x15,  0x0a,  0x39,  0xa0,  0xb4,  0x15,  0xfe,  0x31,
13569   0x00,  0x39,  0xa2,  0x01,  0xfe,  0x48,  0x10,  0x02,  0xd7,  0x42,  0xfe,  0x06,  0xec,  0xd0,  0xfc,  0x44,
13570   0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0x06,  0xea,  0xd0,  0xfe,  0x47,  0x4b,  0x91,  0xfe,  0x75,
13571   0x57,  0x03,  0x5d,  0xfe,  0x98,  0x56,  0xfe,  0x38,  0x12,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x44,  0x48,
13572   0x4f,  0x08,  0x05,  0x1b,  0xfe,  0x1a,  0x13,  0x09,  0x46,  0x01,  0x0e,  0x41,  0xfe,  0x41,  0x58,  0x09,
13573   0xa4,  0x01,  0x0e,  0xfe,  0x49,  0x54,  0x96,  0xfe,  0x1e,  0x0e,  0x02,  0xfe,  0x2e,  0x03,  0x09,  0x5d,
13574   0xfe,  0xee,  0x14,  0xfc,  0x44,  0x1b,  0xfe,  0xce,  0x45,  0x35,  0x42,  0xfe,  0xce,  0x47,  0xfe,  0xad,
13575   0x13,  0x02,  0x2b,  0x22,  0x20,  0x07,  0x11,  0xfe,  0x9e,  0x12,  0x21,  0x13,  0x59,  0x13,  0x9f,  0x13,
13576   0xd5,  0x22,  0x2f,  0x41,  0x39,  0x2f,  0xbc,  0xad,  0xfe,  0xbc,  0xf0,  0xfe,  0xe0,  0x0e,  0x0f,  0x06,
13577   0x13,  0x59,  0x01,  0xfe,  0xda,  0x16,  0x03,  0xfe,  0x38,  0x01,  0x29,  0xfe,  0x3a,  0x01,  0x56,  0xfe,
13578   0xe4,  0x0e,  0xfe,  0x02,  0xec,  0xd5,  0x69,  0x00,  0x66,  0xfe,  0x04,  0xec,  0x20,  0x4f,  0xfe,  0x05,
13579   0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x4a,  0x17,  0xfe,  0x08,  0x90,  0xfe,  0x48,  0xf4,  0x0d,  0xfe,
13580   0x18,  0x13,  0xba,  0xfe,  0x02,  0xea,  0xd5,  0x69,  0x7e,  0xfe,  0xc5,  0x13,  0x15,  0x1a,  0x39,  0xa0,
13581   0xb4,  0xfe,  0x2e,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x1e,  0xfe,  0xf0,  0xff,  0x0c,  0xfe,  0x60,  0x01,
13582   0x03,  0xfe,  0x3a,  0x01,  0x0c,  0xfe,  0x62,  0x01,  0x43,  0x13,  0x20,  0x25,  0x06,  0x13,  0x2f,  0x12,
13583   0x2f,  0x92,  0x0f,  0x06,  0x04,  0x21,  0x04,  0x22,  0x59,  0xfe,  0xf7,  0x12,  0x22,  0x9f,  0xb7,  0x13,
13584   0x9f,  0x07,  0x7e,  0xfe,  0x71,  0x13,  0xfe,  0x24,  0x1c,  0x15,  0x19,  0x39,  0xa0,  0xb4,  0xfe,  0xd9,
13585   0x10,  0xc3,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xc3,  0xfe,  0x03,  0xdc,
13586   0xfe,  0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x04,  0xfe,  0x03,  0x57,  0xc3,  0x21,  0xfe,  0x00,  0xcc,  0x04,
13587   0xfe,  0x03,  0x57,  0xc3,  0x78,  0x04,  0x08,  0x05,  0x58,  0xfe,  0x22,  0x13,  0xfe,  0x1c,  0x80,  0x07,
13588   0x06,  0xfe,  0x1a,  0x13,  0xfe,  0x1e,  0x80,  0xed,  0xfe,  0x1d,  0x80,  0xae,  0xfe,  0x0c,  0x90,  0xfe,
13589   0x0e,  0x13,  0xfe,  0x0e,  0x90,  0xac,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x0a,  0xfe,  0x3c,  0x50,
13590   0xaa,  0x01,  0xfe,  0x7a,  0x17,  0x32,  0x07,  0x2f,  0xad,  0x01,  0xfe,  0xb4,  0x16,  0x08,  0x05,  0x1b,
13591   0x4e,  0x01,  0xf5,  0x01,  0xf6,  0x12,  0xfe,  0xe9,  0x00,  0x08,  0x05,  0x58,  0xfe,  0x2c,  0x13,  0x01,
13592   0xfe,  0x0c,  0x17,  0xfe,  0x1e,  0x1c,  0xfe,  0x14,  0x90,  0xfe,  0x96,  0x90,  0x0c,  0xfe,  0x64,  0x01,
13593   0x14,  0xfe,  0x66,  0x01,  0x08,  0x05,  0x5b,  0xfe,  0x12,  0x12,  0xfe,  0x03,  0x80,  0x8d,  0xfe,  0x01,
13594   0xec,  0x20,  0xfe,  0x80,  0x40,  0x13,  0x20,  0x6a,  0x2a,  0x12,  0xcf,  0x64,  0x22,  0x20,  0xfb,  0x79,
13595   0x20,  0x04,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,  0xae,  0x00,
13596
13597   0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,  0xfe,  0x09,
13598   0x58,  0xfe,  0x0a,  0x1c,  0x25,  0x6e,  0x13,  0xd0,  0x21,  0x0c,  0x5c,  0x0c,  0x45,  0x0f,  0x46,  0x52,
13599   0x50,  0x18,  0x1b,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xfe,  0xfc,  0x0f,  0x44,  0x11,  0x0f,
13600   0x48,  0x52,  0x18,  0x58,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x23,  0xe4,  0x25,  0x11,  0x13,  0x20,
13601   0x7c,  0x6f,  0x4f,  0x22,  0x20,  0xfb,  0x79,  0x20,  0x12,  0xcf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,
13602   0xfe,  0x26,  0x10,  0xf8,  0x74,  0xfe,  0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x04,  0x42,
13603   0xfe,  0x0c,  0x14,  0xfc,  0xfe,  0x07,  0xe6,  0x1b,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x04,  0x01,
13604   0xb0,  0x7c,  0x6f,  0x4f,  0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0x32,  0x07,  0x2f,
13605   0xfe,  0x34,  0x13,  0x09,  0x48,  0x01,  0x0e,  0xbb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,
13606   0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,  0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,
13607   0x84,  0x01,  0x0e,  0xfe,  0x80,  0x5c,  0x01,  0x73,  0xfe,  0x0e,  0x10,  0x07,  0x82,  0x4e,  0xfe,  0x14,
13608   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x60,  0x10,  0x04,  0xfe,  0x44,  0x58,  0x8d,  0xfe,  0x01,  0xec,  0xa2,
13609   0xfe,  0x9e,  0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x1a,  0x79,  0x2a,  0x01,  0xe3,  0xfe,
13610   0xdd,  0x10,  0x2c,  0xc7,  0x81,  0xc8,  0x83,  0x33,  0x31,  0xde,  0x07,  0x1a,  0xfe,  0x48,  0x12,  0x07,
13611   0x0a,  0xfe,  0x56,  0x12,  0x07,  0x19,  0xfe,  0x30,  0x12,  0x07,  0xc9,  0x17,  0xfe,  0x32,  0x12,  0x07,
13612   0xfe,  0x23,  0x00,  0x17,  0xeb,  0x07,  0x06,  0x17,  0xfe,  0x9c,  0x12,  0x07,  0x1f,  0xfe,  0x12,  0x12,
13613   0x07,  0x00,  0x17,  0x24,  0x15,  0xc9,  0x01,  0x36,  0xa9,  0x2d,  0x01,  0x0b,  0x94,  0x4b,  0x04,  0x2d,
13614   0xdd,  0x09,  0xd1,  0x01,  0xfe,  0x26,  0x0f,  0x12,  0x82,  0x02,  0x2b,  0x2d,  0x32,  0x07,  0xa6,  0xfe,
13615   0xd9,  0x13,  0x3a,  0x3d,  0x3b,  0x3e,  0x56,  0xfe,  0xf0,  0x11,  0x08,  0x05,  0x5a,  0xfe,  0x72,  0x12,
13616   0x9b,  0x2e,  0x9c,  0x3c,  0x90,  0xc0,  0x96,  0xfe,  0xba,  0x11,  0x22,  0x62,  0xfe,  0x26,  0x13,  0x03,
13617   0x7f,  0x29,  0x80,  0x56,  0xfe,  0x76,  0x0d,  0x0c,  0x60,  0x14,  0x61,  0x21,  0x0c,  0x7f,  0x0c,  0x80,
13618   0x01,  0xb3,  0x25,  0x6e,  0x77,  0x13,  0x62,  0x01,  0xef,  0x9b,  0x2e,  0x9c,  0x3c,  0xfe,  0x04,  0x55,
13619   0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,  0x2e,  0xfe,  0x05,  0xfa,  0x3c,  0xfe,  0x91,  0x10,  0x03,  0x3f,
13620   0x29,  0x40,  0xfe,  0x40,  0x56,  0xfe,  0xe1,  0x56,  0x0c,  0x3f,  0x14,  0x40,  0x88,  0x9b,  0x2e,  0x9c,
13621   0x3c,  0x90,  0xc0,  0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x0c,  0x5e,  0x14,
13622   0x5f,  0x08,  0x05,  0x5a,  0xfe,  0x1e,  0x12,  0x22,  0x62,  0xfe,  0x1f,  0x40,  0x03,  0x60,  0x29,  0x61,
13623   0xfe,  0x2c,  0x50,  0xfe,  0xae,  0x50,  0x03,  0x3f,  0x29,  0x40,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,
13624   0x03,  0x5e,  0x29,  0x5f,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x3d,  0x29,  0x3e,  0xfe,  0x40,
13625   0x50,  0xfe,  0xc2,  0x50,  0x02,  0x89,  0x25,  0x06,  0x13,  0xd4,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1d,
13626   0x4c,  0x33,  0x31,  0xde,  0x07,  0x06,  0x23,  0x4c,  0x32,  0x07,  0xa6,  0x23,  0x72,  0x01,  0xaf,  0x1e,
13627   0x43,  0x17,  0x4c,  0x08,  0x05,  0x0a,  0xee,  0x3a,  0x3d,  0x3b,  0x3e,  0xfe,  0x0a,  0x55,  0x35,  0xfe,
13628   0x8b,  0x55,  0x57,  0x3d,  0x7d,  0x3e,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x02,  0x72,  0xfe,  0x19,
13629   0x81,  0xba,  0xfe,  0x19,  0x41,  0x02,  0x72,  0x2d,  0x01,  0x0b,  0x1c,  0x34,  0x1d,  0xe8,  0x33,  0x31,
13630   0xe1,  0x55,  0x19,  0xfe,  0xa6,  0x12,  0x55,  0x0a,  0x4d,  0x02,  0x4c,  0x01,  0x0b,  0x1c,  0x34,  0x1d,
13631   0xe8,  0x33,  0x31,  0xdf,  0x07,  0x19,  0x23,  0x4c,  0x01,  0x0b,  0x1d,  0xe8,  0x33,  0x31,  0xfe,  0xe8,
13632   0x09,  0xfe,  0xc2,  0x49,  0x51,  0x03,  0xfe,  0x9c,  0x00,  0x28,  0x8a,  0x53,  0x05,  0x1f,  0x35,  0xa9,
13633   0xfe,  0xbb,  0x45,  0x55,  0x00,  0x4e,  0x44,  0x06,  0x7c,  0x43,  0xfe,  0xda,  0x14,  0x01,  0xaf,  0x8c,
13634   0xfe,  0x4b,  0x45,  0xee,  0x32,  0x07,  0xa5,  0xed,  0x03,  0xcd,  0x28,  0x8a,  0x03,  0x45,  0x28,  0x35,
13635   0x67,  0x02,  0x72,  0xfe,  0xc0,  0x5d,  0xfe,  0xf8,  0x14,  0xfe,  0x03,  0x17,  0x03,  0x5c,  0xc1,  0x0c,
13636   0x5c,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,  0x01,  0xfe,  0x9e,  0x15,  0x02,  0x89,  0x01,  0x0b,  0x1c,
13637   0x34,  0x1d,  0x4c,  0x33,  0x31,  0xdf,  0x07,  0x06,  0x23,  0x4c,  0x01,  0xf1,  0xfe,  0x42,  0x58,  0xf1,
13638   0xfe,  0xa4,  0x14,  0x8c,  0xfe,  0x4a,  0xf4,  0x0a,  0x17,  0x4c,  0xfe,  0x4a,  0xf4,  0x06,  0xea,  0x32,
13639   0x07,  0xa5,  0x8b,  0x02,  0x72,  0x03,  0x45,  0xc1,  0x0c,  0x45,  0x67,  0x2d,  0x01,  0x0b,  0x26,  0x89,
13640   0x01,  0xfe,  0xcc,  0x15,  0x02,  0x89,  0x0f,  0x06,  0x27,  0xfe,  0xbe,  0x13,  0x26,  0xfe,  0xd4,  0x13,
13641   0x76,  0xfe,  0x89,  0x48,  0x01,  0x0b,  0x21,  0x76,  0x04,  0x7b,  0xfe,  0xd0,  0x13,  0x1c,  0xfe,  0xd0,
13642   0x13,  0x1d,  0xfe,  0xbe,  0x13,  0x67,  0x2d,  0x01,  0x0b,  0xfe,  0xd5,  0x10,  0x0f,  0x71,  0xff,  0x02,
13643   0x00,  0x57,  0x52,  0x93,  0x1e,  0xfe,  0xff,  0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,  0x0f,
13644   0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x1e,  0x43,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x04,
13645   0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,  0x93,  0x04,  0x0f,  0x71,  0xff,  0x02,  0x00,  0x57,  0x52,
13646   0x93,  0xfe,  0x0b,  0x58,  0x04,  0x09,  0x5c,  0x01,  0x87,  0x09,  0x45,  0x01,  0x87,  0x04,  0xfe,  0x03,
13647   0xa1,  0x1e,  0x11,  0xff,  0x03,  0x00,  0x54,  0xfe,  0x00,  0xf4,  0x1f,  0x52,  0xfe,  0x00,  0x7d,  0xfe,
13648   0x01,  0x7d,  0xfe,  0x02,  0x7d,  0xfe,  0x03,  0x7c,  0x6a,  0x2a,  0x0c,  0x5e,  0x14,  0x5f,  0x57,  0x3f,
13649   0x7d,  0x40,  0x04,  0xdd,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x8d,  0x04,  0x01,
13650   0xfe,  0x0c,  0x19,  0xfe,  0x42,  0x48,  0x50,  0x51,  0x91,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,
13651   0x31,  0xe1,  0x01,  0x0b,  0x1d,  0xfe,  0x96,  0x15,  0x33,  0x31,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,
13652   0x03,  0xcd,  0x28,  0xfe,  0xcc,  0x12,  0x53,  0x05,  0x1a,  0xfe,  0xc4,  0x13,  0x21,  0x69,  0x1a,  0xee,
13653   0x55,  0xca,  0x6b,  0xfe,  0xdc,  0x14,  0x4d,  0x0f,  0x06,  0x18,  0xca,  0x7c,  0x30,  0xfe,  0x78,  0x10,
13654   0xff,  0x02,  0x83,  0x55,  0xab,  0xff,  0x02,  0x83,  0x55,  0x69,  0x19,  0xae,  0x98,  0xfe,  0x30,  0x00,
13655   0x96,  0xf2,  0x18,  0x6d,  0x0f,  0x06,  0xfe,  0x56,  0x10,  0x69,  0x0a,  0xed,  0x98,  0xfe,  0x64,  0x00,
13656   0x96,  0xf2,  0x09,  0xfe,  0x64,  0x00,  0x18,  0x9e,  0x0f,  0x06,  0xfe,  0x28,  0x10,  0x69,  0x06,  0xfe,
13657   0x60,  0x13,  0x98,  0xfe,  0xc8,  0x00,  0x96,  0xf2,  0x09,  0xfe,  0xc8,  0x00,  0x18,  0x59,  0x0f,  0x06,
13658   0x88,  0x98,  0xfe,  0x90,  0x01,  0x7a,  0xfe,  0x42,  0x15,  0x91,  0xe4,  0xfe,  0x43,  0xf4,  0x9f,  0xfe,
13659   0x56,  0xf0,  0xfe,  0x54,  0x15,  0xfe,  0x04,  0xf4,  0x71,  0xfe,  0x43,  0xf4,  0x9e,  0xfe,  0xf3,  0x10,
13660   0xfe,  0x40,  0x5c,  0x01,  0xfe,  0x16,  0x14,  0x1e,  0x43,  0xec,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13661   0x6e,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0x6e,  0xfe,  0x1c,  0x10,  0xfe,  0x00,  0x17,  0xfe,  0x4d,  0xe4,
13662   0xcc,  0x7a,  0xfe,  0x90,  0x15,  0xc4,  0xcc,  0x88,  0x51,  0x21,  0xfe,  0x4d,  0xf4,  0x00,  0xe9,  0x91,
13663   0x0f,  0x06,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x04,  0x51,  0x0f,  0x0a,  0x04,  0x16,  0x06,  0x01,
13664   0x0b,  0x26,  0xf3,  0x16,  0x0a,  0x01,  0x0b,  0x26,  0xf3,  0x16,  0x19,  0x01,  0x0b,  0x26,  0xf3,  0x76,
13665   0xfe,  0x89,  0x49,  0x01,  0x0b,  0x04,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0x16,  0x19,  0x01,  0x0b,
13666   0x26,  0xb1,  0x16,  0x06,  0x01,  0x0b,  0x26,  0xb1,  0xfe,  0x89,  0x49,  0x01,  0x0b,  0x26,  0xb1,  0x76,
13667   0xfe,  0x89,  0x4a,  0x01,  0x0b,  0x04,  0x51,  0x04,  0x22,  0xd3,  0x07,  0x06,  0xfe,  0x48,  0x13,  0xb8,
13668   0x13,  0xd3,  0xfe,  0x49,  0xf4,  0x00,  0x4d,  0x76,  0xa9,  0x67,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,
13669   0xfe,  0x89,  0x48,  0xff,  0x02,  0x00,  0x10,  0x27,  0xfe,  0x2e,  0x16,  0x32,  0x07,  0xfe,  0xe3,  0x00,
13670   0xfe,  0x20,  0x13,  0x1d,  0xfe,  0x52,  0x16,  0x21,  0x13,  0xd4,  0x01,  0x4b,  0x22,  0xd4,  0x07,  0x06,
13671   0x4e,  0x08,  0x54,  0x06,  0x37,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfb,  0x8e,  0x07,  0x11,  0xae,  0x09,
13672   0x84,  0x01,  0x0e,  0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x84,  0x01,  0x0e,  0x8e,  0xfe,  0x80,
13673   0xe7,  0x11,  0x07,  0x11,  0x8a,  0xfe,  0x45,  0x58,  0x01,  0xf0,  0x8e,  0x04,  0x09,  0x48,  0x01,  0x0e,
13674   0x8e,  0x09,  0x5d,  0x01,  0xa8,  0x04,  0x09,  0x48,  0x01,  0x0e,  0xfe,  0x80,  0x80,  0xfe,  0x80,  0x4c,
13675   0xfe,  0x49,  0xe4,  0x11,  0xae,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,  0x09,  0x5d,  0x01,  0x87,
13676   0x04,  0x18,  0x11,  0x75,  0x6c,  0xfe,  0x60,  0x01,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x24,
13677   0x1c,  0xfe,  0x1d,  0xf7,  0x1b,  0x97,  0xfe,  0xee,  0x16,  0x01,  0xfe,  0xf4,  0x17,  0xad,  0x9a,  0x1b,
13678   0x6c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x04,  0xb9,  0x23,  0xfe,  0xde,  0x16,  0xfe,  0xda,  0x10,
13679   0x18,  0x11,  0x75,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x1f,  0xfe,  0x18,  0x58,  0x03,  0xfe,
13680   0x66,  0x01,  0xfe,  0x19,  0x58,  0x9a,  0x1f,  0xfe,  0x3c,  0x90,  0xfe,  0x30,  0xf4,  0x06,  0xfe,  0x3c,
13681   0x50,  0x6c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x1f,  0x97,  0xfe,  0x38,  0x17,
13682   0xfe,  0xb6,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x10,  0x17,  0xfe,  0x9c,  0x10,  0x18,  0x11,  0x75,
13683   0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x2e,  0x97,  0xfe,  0x5a,
13684   0x17,  0xfe,  0x94,  0x14,  0xec,  0x9a,  0x2e,  0x6c,  0x1a,  0xfe,  0xaf,  0x19,  0xfe,  0x98,  0xe7,  0x00,
13685   0x04,  0xb9,  0x23,  0xfe,  0x4e,  0x17,  0xfe,  0x6c,  0x10,  0x18,  0x11,  0x75,  0xfe,  0x30,  0xbc,  0xfe,
13686   0xb2,  0xbc,  0x9a,  0xcb,  0x6c,  0x1a,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0xcb,  0x97,  0xfe,  0x92,
13687   0x17,  0xfe,  0x5c,  0x14,  0x35,  0x04,  0xb9,  0x23,  0xfe,  0x7e,  0x17,  0xfe,  0x42,  0x10,  0xfe,  0x02,
13688   0xf6,  0x11,  0x75,  0xfe,  0x18,  0xfe,  0x60,  0xfe,  0x19,  0xfe,  0x61,  0xfe,  0x03,  0xa1,  0xfe,  0x1d,
13689   0xf7,  0x5b,  0x97,  0xfe,  0xb8,  0x17,  0xfe,  0x36,  0x14,  0xfe,  0x1c,  0x13,  0x9a,  0x5b,  0x41,  0xfe,
13690   0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x11,  0xfe,  0x81,  0xe7,  0x11,  0x12,  0xfe,  0xdd,
13691   0x00,  0x6a,  0x2a,  0x04,  0x6a,  0x2a,  0xfe,  0x12,  0x45,  0x23,  0xfe,  0xa8,  0x17,  0x15,  0x06,  0x39,
13692   0xa0,  0xb4,  0x02,  0x2b,  0xfe,  0x39,  0xf0,  0xfe,  0xfc,  0x17,  0x21,  0x04,  0xfe,  0x7e,  0x18,  0x1e,
13693   0x19,  0x66,  0x0f,  0x0d,  0x04,  0x75,  0x03,  0xd2,  0x1e,  0x06,  0xfe,  0xef,  0x12,  0xfe,  0xe1,  0x10,
13694   0x7c,  0x6f,  0x4f,  0x32,  0x07,  0x2f,  0xfe,  0x3c,  0x13,  0xf1,  0xfe,  0x42,  0x13,  0x42,  0x92,  0x09,
13695   0x48,  0x01,  0x0e,  0xbb,  0xeb,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xf0,  0xfe,  0x00,  0xcc,
13696   0xbb,  0xfe,  0xf3,  0x13,  0x43,  0x78,  0x07,  0x11,  0xac,  0x09,  0x84,  0x01,  0x0e,  0xfe,  0x80,  0x4c,
13697   0x01,  0x73,  0xfe,  0x16,  0x10,  0x07,  0x82,  0x8b,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,
13698   0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0x1c,  0x18,  0x18,  0x0a,  0x04,  0xfe,  0x9c,  0xe7,  0x0a,  0x10,  0xfe,
13699   0x15,  0x00,  0x64,  0x79,  0x2a,  0x01,  0xe3,  0x18,  0x06,  0x04,  0x42,  0x92,  0x08,  0x54,  0x1b,  0x37,
13700   0x12,  0x2f,  0x01,  0x73,  0x18,  0x06,  0x04,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,  0x3a,  0xce,  0x3b,
13701   0xcf,  0xfe,  0x48,  0x55,  0x35,  0xfe,  0xc9,  0x55,  0x04,  0x22,  0xa3,  0x77,  0x13,  0xa3,  0x04,  0x09,
13702   0xa4,  0x01,  0x0e,  0xfe,  0x41,  0x48,  0x09,  0x46,  0x01,  0x0e,  0xfe,  0x49,  0x44,  0x17,  0xfe,  0xe8,
13703   0x18,  0x77,  0x78,  0x04,  0x09,  0x48,  0x01,  0x0e,  0x07,  0x11,  0x4e,  0x09,  0x5d,  0x01,  0xa8,  0x09,
13704   0x46,  0x01,  0x0e,  0x77,  0x78,  0x04,  0xfe,  0x4e,  0xe4,  0x19,  0x6b,  0xfe,  0x1c,  0x19,  0x03,  0xfe,
13705   0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xc9,  0x6b,  0xfe,  0x2e,  0x19,
13706   0x03,  0xfe,  0x92,  0x00,  0xfe,  0x02,  0xe6,  0x1a,  0xe5,  0xfe,  0x4e,  0xe4,  0xfe,  0x0b,  0x00,  0x6b,
13707   0xfe,  0x40,  0x19,  0x03,  0xfe,  0x94,  0x00,  0xfe,  0x02,  0xe6,  0x1f,  0xfe,  0x08,  0x10,  0x03,  0xfe,
13708   0x96,  0x00,  0xfe,  0x02,  0xe6,  0x6d,  0xfe,  0x4e,  0x45,  0xea,  0xba,  0xff,  0x04,  0x68,  0x54,  0xe7,
13709   0x1e,  0x6e,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,  0x00,
13710   0x04,  0xea,  0xfe,  0x48,  0xf4,  0x19,  0x7a,  0xfe,  0x74,  0x19,  0x0f,  0x19,  0x04,  0x07,  0x7e,  0xfe,
13711   0x5a,  0xf0,  0xfe,  0x84,  0x19,  0x25,  0xfe,  0x09,  0x00,  0xfe,  0x34,  0x10,  0x07,  0x1a,  0xfe,  0x5a,
13712   0xf0,  0xfe,  0x92,  0x19,  0x25,  0xca,  0xfe,  0x26,  0x10,  0x07,  0x19,  0x66,  0x25,  0x6d,  0xe5,  0x07,
13713   0x0a,  0x66,  0x25,  0x9e,  0xfe,  0x0e,  0x10,  0x07,  0x06,  0x66,  0x25,  0x59,  0xa9,  0xb8,  0x04,  0x15,
13714   0xfe,  0x09,  0x00,  0x01,  0x36,  0xfe,  0x04,  0xfe,  0x81,  0x03,  0x83,  0xfe,  0x40,  0x5c,  0x04,  0x1c,
13715   0xf7,  0xfe,  0x14,  0xf0,  0x0b,  0x27,  0xfe,  0xd6,  0x19,  0x1c,  0xf7,  0x7b,  0xf7,  0xfe,  0x82,  0xf0,
13716   0xfe,  0xda,  0x19,  0x04,  0xff,  0xcc,  0x00,  0x00,
13717 };
13718
13719 STATIC unsigned short _adv_asc38C0800_size =
13720         sizeof(_adv_asc38C0800_buf); /* 0x14E1 */
13721 STATIC ADV_DCNT _adv_asc38C0800_chksum =
13722         0x050D3FD8UL; /* Expanded little-endian checksum. */
13723
13724 /* Microcode buffer is kept after initialization for error recovery. */
13725 STATIC unsigned char _adv_asc38C1600_buf[] = {
13726   0x00,  0x00,  0x00,  0xf2,  0x00,  0x16,  0x00,  0xfc,  0x00,  0x10,  0x00,  0xf0,  0x18,  0xe4,  0x01,  0x00,
13727   0x04,  0x1e,  0x48,  0xe4,  0x03,  0xf6,  0xf7,  0x13,  0x2e,  0x1e,  0x02,  0x00,  0x07,  0x17,  0xc0,  0x5f,
13728   0x00,  0xfa,  0xff,  0xff,  0x04,  0x00,  0x00,  0xf6,  0x09,  0xe7,  0x82,  0xe7,  0x85,  0xf0,  0x86,  0xf0,
13729   0x4e,  0x10,  0x9e,  0xe7,  0xff,  0x00,  0x55,  0xf0,  0x01,  0xf6,  0x03,  0x00,  0x98,  0x57,  0x01,  0xe6,
13730   0x00,  0xea,  0x00,  0xec,  0x01,  0xfa,  0x18,  0xf4,  0x08,  0x00,  0xf0,  0x1d,  0x38,  0x54,  0x32,  0xf0,
13731   0x10,  0x00,  0xc2,  0x0e,  0x1e,  0xf0,  0xd5,  0xf0,  0xbc,  0x00,  0x4b,  0xe4,  0x00,  0xe6,  0xb1,  0xf0,
13732   0xb4,  0x00,  0x02,  0x13,  0x3e,  0x1c,  0xc8,  0x47,  0x3e,  0x00,  0xd8,  0x01,  0x06,  0x13,  0x0c,  0x1c,
13733   0x5e,  0x1e,  0x00,  0x57,  0xc8,  0x57,  0x01,  0xfc,  0xbc,  0x0e,  0xa2,  0x12,  0xb9,  0x54,  0x00,  0x80,
13734   0x62,  0x0a,  0x5a,  0x12,  0xc8,  0x15,  0x3e,  0x1e,  0x18,  0x40,  0xbd,  0x56,  0x03,  0xe6,  0x01,  0xea,
13735   0x5c,  0xf0,  0x0f,  0x00,  0x20,  0x00,  0x6c,  0x01,  0x6e,  0x01,  0x04,  0x12,  0x04,  0x13,  0xbb,  0x55,
13736   0x3c,  0x56,  0x3e,  0x57,  0x03,  0x58,  0x4a,  0xe4,  0x40,  0x00,  0xb6,  0x00,  0xbb,  0x00,  0xc0,  0x00,
13737   0x00,  0x01,  0x01,  0x01,  0x3e,  0x01,  0x58,  0x0a,  0x44,  0x10,  0x0a,  0x12,  0x4c,  0x1c,  0x4e,  0x1c,
13738   0x02,  0x4a,  0x30,  0xe4,  0x05,  0xe6,  0x0c,  0x00,  0x3c,  0x00,  0x80,  0x00,  0x24,  0x01,  0x3c,  0x01,
13739   0x68,  0x01,  0x6a,  0x01,  0x70,  0x01,  0x72,  0x01,  0x74,  0x01,  0x76,  0x01,  0x78,  0x01,  0x7c,  0x01,
13740   0xc6,  0x0e,  0x0c,  0x10,  0xac,  0x12,  0xae,  0x12,  0x16,  0x1a,  0x32,  0x1c,  0x6e,  0x1e,  0x02,  0x48,
13741   0x3a,  0x55,  0xc9,  0x57,  0x02,  0xee,  0x5b,  0xf0,  0x03,  0xf7,  0x06,  0xf7,  0x03,  0xfc,  0x06,  0x00,
13742   0x1e,  0x00,  0xbe,  0x00,  0xe1,  0x00,  0x0c,  0x12,  0x18,  0x1a,  0x70,  0x1a,  0x30,  0x1c,  0x38,  0x1c,
13743   0x10,  0x44,  0x00,  0x4c,  0xb0,  0x57,  0x40,  0x5c,  0x4d,  0xe4,  0x04,  0xea,  0x5d,  0xf0,  0xa7,  0xf0,
13744   0x04,  0xf6,  0x02,  0xfc,  0x05,  0x00,  0x09,  0x00,  0x19,  0x00,  0x32,  0x00,  0x33,  0x00,  0x34,  0x00,
13745   0x36,  0x00,  0x98,  0x00,  0x9e,  0x00,  0xcc,  0x00,  0x20,  0x01,  0x4e,  0x01,  0x79,  0x01,  0x3c,  0x09,
13746   0x68,  0x0d,  0x02,  0x10,  0x04,  0x10,  0x3a,  0x10,  0x08,  0x12,  0x0a,  0x13,  0x40,  0x16,  0x50,  0x16,
13747   0x00,  0x17,  0x4a,  0x19,  0x00,  0x4e,  0x00,  0x54,  0x01,  0x58,  0x00,  0xdc,  0x05,  0xf0,  0x09,  0xf0,
13748   0x59,  0xf0,  0xb8,  0xf0,  0x48,  0xf4,  0x0e,  0xf7,  0x0a,  0x00,  0x9b,  0x00,  0x9c,  0x00,  0xa4,  0x00,
13749   0xb5,  0x00,  0xba,  0x00,  0xd0,  0x00,  0xe7,  0x00,  0xf0,  0x03,  0x69,  0x08,  0xe9,  0x09,  0x5c,  0x0c,
13750   0xb6,  0x12,  0xbc,  0x19,  0xd8,  0x1b,  0x20,  0x1c,  0x34,  0x1c,  0x36,  0x1c,  0x42,  0x1d,  0x08,  0x44,
13751   0x38,  0x44,  0x91,  0x44,  0x0a,  0x45,  0x48,  0x46,  0x89,  0x48,  0x68,  0x54,  0x83,  0x55,  0x83,  0x59,
13752   0x31,  0xe4,  0x02,  0xe6,  0x07,  0xf0,  0x08,  0xf0,  0x0b,  0xf0,  0x0c,  0xf0,  0x4b,  0xf4,  0x04,  0xf8,
13753   0x05,  0xf8,  0x02,  0xfa,  0x03,  0xfa,  0x04,  0xfc,  0x05,  0xfc,  0x07,  0x00,  0xa8,  0x00,  0xaa,  0x00,
13754   0xb9,  0x00,  0xe0,  0x00,  0xe5,  0x00,  0x22,  0x01,  0x26,  0x01,  0x60,  0x01,  0x7a,  0x01,  0x82,  0x01,
13755   0xc8,  0x01,  0xca,  0x01,  0x86,  0x02,  0x6a,  0x03,  0x18,  0x05,  0xb2,  0x07,  0x68,  0x08,  0x10,  0x0d,
13756   0x06,  0x10,  0x0a,  0x10,  0x0e,  0x10,  0x12,  0x10,  0x60,  0x10,  0xed,  0x10,  0xf3,  0x10,  0x06,  0x12,
13757   0x10,  0x12,  0x1e,  0x12,  0x0c,  0x13,  0x0e,  0x13,  0x10,  0x13,  0xfe,  0x9c,  0xf0,  0x35,  0x05,  0xfe,
13758   0xec,  0x0e,  0xff,  0x10,  0x00,  0x00,  0xe9,  0xfe,  0x34,  0x1f,  0x00,  0xe8,  0xfe,  0x88,  0x01,  0xff,
13759   0x03,  0x00,  0x00,  0xfe,  0x93,  0x15,  0xfe,  0x0f,  0x05,  0xff,  0x38,  0x00,  0x00,  0xfe,  0x57,  0x24,
13760   0x00,  0xfe,  0x4c,  0x00,  0x65,  0xff,  0x04,  0x00,  0x00,  0x1a,  0xff,  0x09,  0x00,  0x00,  0xff,  0x08,
13761   0x01,  0x01,  0xff,  0x08,  0xff,  0xff,  0xff,  0x27,  0x00,  0x00,  0xff,  0x10,  0xff,  0xff,  0xff,  0x13,
13762   0x00,  0x00,  0xfe,  0x78,  0x56,  0xfe,  0x34,  0x12,  0xff,  0x21,  0x00,  0x00,  0xfe,  0x04,  0xf7,  0xe8,
13763   0x37,  0x7d,  0x0d,  0x01,  0xfe,  0x4a,  0x11,  0xfe,  0x04,  0xf7,  0xe8,  0x7d,  0x0d,  0x51,  0x37,  0xfe,
13764   0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x91,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,
13765   0x90,  0xf0,  0xfe,  0xf8,  0x01,  0xfe,  0x8f,  0xf0,  0xbc,  0x03,  0x67,  0x4d,  0x05,  0xfe,  0x08,  0x0f,
13766   0x01,  0xfe,  0x78,  0x0f,  0xfe,  0xdd,  0x12,  0x05,  0xfe,  0x0e,  0x03,  0xfe,  0x28,  0x1c,  0x03,  0xfe,
13767   0xa6,  0x00,  0xfe,  0xd1,  0x12,  0x3e,  0x22,  0xfe,  0xa6,  0x00,  0xac,  0xfe,  0x48,  0xf0,  0xfe,  0x90,
13768   0x02,  0xfe,  0x49,  0xf0,  0xfe,  0xaa,  0x02,  0xfe,  0x4a,  0xf0,  0xfe,  0xc8,  0x02,  0xfe,  0x46,  0xf0,
13769   0xfe,  0x5a,  0x02,  0xfe,  0x47,  0xf0,  0xfe,  0x60,  0x02,  0xfe,  0x43,  0xf0,  0xfe,  0x4e,  0x02,  0xfe,
13770   0x44,  0xf0,  0xfe,  0x52,  0x02,  0xfe,  0x45,  0xf0,  0xfe,  0x56,  0x02,  0x1c,  0x0d,  0xa2,  0x1c,  0x07,
13771   0x22,  0xb7,  0x05,  0x35,  0xfe,  0x00,  0x1c,  0xfe,  0xf1,  0x10,  0xfe,  0x02,  0x1c,  0xf5,  0xfe,  0x1e,
13772   0x1c,  0xfe,  0xe9,  0x10,  0x01,  0x5f,  0xfe,  0xe7,  0x10,  0xfe,  0x06,  0xfc,  0xde,  0x0a,  0x81,  0x01,
13773   0xa3,  0x05,  0x35,  0x1f,  0x95,  0x47,  0xb8,  0x01,  0xfe,  0xe4,  0x11,  0x0a,  0x81,  0x01,  0x5c,  0xfe,
13774   0xbd,  0x10,  0x0a,  0x81,  0x01,  0x5c,  0xfe,  0xad,  0x10,  0xfe,  0x16,  0x1c,  0xfe,  0x58,  0x1c,  0x1c,
13775   0x07,  0x22,  0xb7,  0x37,  0x2a,  0x35,  0xfe,  0x3d,  0xf0,  0xfe,  0x0c,  0x02,  0x2b,  0xfe,  0x9e,  0x02,
13776   0xfe,  0x5a,  0x1c,  0xfe,  0x12,  0x1c,  0xfe,  0x14,  0x1c,  0x1f,  0xfe,  0x30,  0x00,  0x47,  0xb8,  0x01,
13777   0xfe,  0xd4,  0x11,  0x1c,  0x07,  0x22,  0xb7,  0x05,  0xe9,  0x21,  0x2c,  0x09,  0x1a,  0x31,  0xfe,  0x69,
13778   0x10,  0x1c,  0x07,  0x22,  0xb7,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0x01,  0xfe,  0x1e,  0x1e,  0x20,  0x2c,
13779   0xfe,  0x05,  0xf6,  0xde,  0x01,  0xfe,  0x62,  0x1b,  0x01,  0x0c,  0x61,  0x4a,  0x44,  0x15,  0x56,  0x51,
13780   0x01,  0xfe,  0x9e,  0x1e,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,
13781   0x36,  0x01,  0x85,  0xfe,  0x18,  0x10,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0xc8,  0x54,
13782   0x7b,  0xfe,  0x1c,  0x03,  0x01,  0xfe,  0x96,  0x1a,  0x05,  0x35,  0x37,  0x60,  0xfe,  0x02,  0xe8,  0x30,
13783   0xfe,  0xbf,  0x57,  0xfe,  0x9e,  0x43,  0xfe,  0x77,  0x57,  0xfe,  0x27,  0xf0,  0xfe,  0xe4,  0x01,  0xfe,
13784   0x07,  0x4b,  0xfe,  0x20,  0xf0,  0xbc,  0xfe,  0x40,  0x1c,  0x2a,  0xeb,  0xfe,  0x26,  0xf0,  0xfe,  0x66,
13785   0x03,  0xfe,  0xa0,  0xf0,  0xfe,  0x54,  0x03,  0xfe,  0x11,  0xf0,  0xbc,  0xfe,  0xef,  0x10,  0xfe,  0x9f,
13786   0xf0,  0xfe,  0x74,  0x03,  0xfe,  0x46,  0x1c,  0x19,  0xfe,  0x11,  0x00,  0x05,  0x70,  0x37,  0xfe,  0x48,
13787   0x1c,  0xfe,  0x46,  0x1c,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x18,  0x13,  0x26,  0x21,  0xb9,  0xc7,  0x20,
13788   0xb9,  0x0a,  0x57,  0x01,  0x18,  0xc7,  0x89,  0x01,  0xfe,  0xc8,  0x1a,  0x15,  0xe1,  0x2a,  0xeb,  0xfe,
13789   0x01,  0xf0,  0xeb,  0xfe,  0x82,  0xf0,  0xfe,  0xa4,  0x03,  0xfe,  0x9c,  0x32,  0x15,  0xfe,  0xe4,  0x00,
13790   0x2f,  0xfe,  0xb6,  0x03,  0x2a,  0x3c,  0x16,  0xfe,  0xc6,  0x03,  0x01,  0x41,  0xfe,  0x06,  0xf0,  0xfe,
13791   0xd6,  0x03,  0xaf,  0xa0,  0xfe,  0x0a,  0xf0,  0xfe,  0xa2,  0x07,  0x05,  0x29,  0x03,  0x81,  0x1e,  0x1b,
13792   0xfe,  0x24,  0x05,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,  0x05,  0xea,  0xfe,  0x46,  0x1c,
13793   0x37,  0x7d,  0x1d,  0xfe,  0x67,  0x1b,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0xfe,  0x48,  0x1c,  0x75,
13794   0x01,  0xa6,  0x86,  0x0a,  0x57,  0x01,  0x18,  0x09,  0x00,  0x1b,  0xec,  0x0a,  0xe1,  0x01,  0x18,  0x77,
13795   0x50,  0x40,  0x8d,  0x30,  0x03,  0x81,  0x1e,  0xf8,  0x1f,  0x63,  0x01,  0x42,  0x8f,  0xfe,  0x70,  0x02,
13796   0x05,  0xea,  0xd7,  0x99,  0xd8,  0x9c,  0x2a,  0x29,  0x2f,  0xfe,  0x4e,  0x04,  0x16,  0xfe,  0x4a,  0x04,
13797   0x7e,  0xfe,  0xa0,  0x00,  0xfe,  0x9b,  0x57,  0xfe,  0x54,  0x12,  0x32,  0xff,  0x02,  0x00,  0x10,  0x01,
13798   0x08,  0x16,  0xfe,  0x02,  0x05,  0x32,  0x01,  0x08,  0x16,  0x29,  0x27,  0x25,  0xee,  0xfe,  0x4c,  0x44,
13799   0xfe,  0x58,  0x12,  0x50,  0xfe,  0x44,  0x48,  0x13,  0x34,  0xfe,  0x4c,  0x54,  0x7b,  0xec,  0x60,  0x8d,
13800   0x30,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x7c,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13801   0x32,  0x13,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x68,  0x13,  0xfe,  0x26,  0x10,  0x13,  0x34,  0xfe,  0x4c,
13802   0x54,  0x7b,  0xec,  0x01,  0xfe,  0x4e,  0x1e,  0xfe,  0x48,  0x47,  0xfe,  0x54,  0x13,  0x01,  0x0c,  0x06,
13803   0x28,  0xa5,  0x01,  0x43,  0x09,  0x9b,  0xfe,  0x40,  0x13,  0x01,  0x0c,  0x06,  0x28,  0xf9,  0x1f,  0x7f,
13804   0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,  0x8f,  0xfe,  0xa4,  0x0e,  0x05,
13805   0x29,  0x32,  0x15,  0xfe,  0xe6,  0x00,  0x0f,  0xfe,  0x1c,  0x90,  0x04,  0xfe,  0x9c,  0x93,  0x3a,  0x0b,
13806   0x0e,  0x8b,  0x02,  0x1f,  0x7f,  0x01,  0x42,  0x05,  0x35,  0xfe,  0x42,  0x5b,  0x7d,  0x1d,  0xfe,  0x46,
13807   0x59,  0xfe,  0xbf,  0x57,  0xfe,  0x77,  0x57,  0x0f,  0xfe,  0x87,  0x80,  0x04,  0xfe,  0x87,  0x83,  0xfe,
13808   0xc9,  0x47,  0x0b,  0x0e,  0xd0,  0x65,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x98,  0x13,  0x0f,  0xfe,  0x20,
13809   0x80,  0x04,  0xfe,  0xa0,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x1d,  0xfe,  0x84,  0x12,  0x01,  0x38,  0x06,
13810   0x07,  0xfe,  0x70,  0x13,  0x03,  0xfe,  0xa2,  0x00,  0x1e,  0x1b,  0xfe,  0xda,  0x05,  0xd0,  0x54,  0x01,
13811   0x38,  0x06,  0x0d,  0xfe,  0x58,  0x13,  0x03,  0xfe,  0xa0,  0x00,  0x1e,  0xfe,  0x50,  0x12,  0x5e,  0xff,
13812   0x02,  0x00,  0x10,  0x2f,  0xfe,  0x90,  0x05,  0x2a,  0x3c,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,
13813   0x9e,  0x05,  0x17,  0xfe,  0xf4,  0x05,  0x15,  0xfe,  0xe3,  0x00,  0x26,  0x01,  0x38,  0xfe,  0x4a,  0xf0,
13814   0xfe,  0xc0,  0x05,  0xfe,  0x49,  0xf0,  0xfe,  0xba,  0x05,  0x71,  0x2e,  0xfe,  0x21,  0x00,  0xf1,  0x2e,
13815   0xfe,  0x22,  0x00,  0xa2,  0x2e,  0x4a,  0xfe,  0x09,  0x48,  0xff,  0x02,  0x00,  0x10,  0x2f,  0xfe,  0xd0,
13816   0x05,  0x17,  0xfe,  0xf4,  0x05,  0xfe,  0xe2,  0x08,  0x01,  0x38,  0x06,  0xfe,  0x1c,  0x00,  0x4d,  0x01,
13817   0xa7,  0x2e,  0x07,  0x20,  0xe4,  0x47,  0xfe,  0x27,  0x01,  0x01,  0x0c,  0x06,  0x28,  0xfe,  0x24,  0x12,
13818   0x3e,  0x01,  0x84,  0x1f,  0x7f,  0x01,  0x0c,  0x06,  0x07,  0x4d,  0x1f,  0xfe,  0x0d,  0x00,  0x01,  0x42,
13819   0x8f,  0xfe,  0xa4,  0x0e,  0x05,  0x29,  0x03,  0xe6,  0x1e,  0xfe,  0xca,  0x13,  0x03,  0xb6,  0x1e,  0xfe,
13820   0x40,  0x12,  0x03,  0x66,  0x1e,  0xfe,  0x38,  0x13,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0x72,  0x06,  0x0a,
13821   0x07,  0x01,  0x38,  0x06,  0x24,  0xfe,  0x02,  0x12,  0x4f,  0x01,  0xfe,  0x56,  0x19,  0x16,  0xfe,  0x68,
13822   0x06,  0x15,  0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x03,  0x9a,  0x1e,  0xfe,
13823   0x70,  0x12,  0x03,  0x55,  0x1e,  0xfe,  0x68,  0x13,  0x01,  0xc6,  0x09,  0x12,  0x48,  0xfe,  0x92,  0x06,
13824   0x2e,  0x12,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,  0x13,  0x58,  0xff,  0x02,  0x00,
13825   0x57,  0x52,  0xad,  0x23,  0x3f,  0x4e,  0x62,  0x49,  0x3e,  0x01,  0x84,  0x17,  0xfe,  0xea,  0x06,  0x01,
13826   0x38,  0x06,  0x12,  0xf7,  0x45,  0x0a,  0x95,  0x01,  0xfe,  0x84,  0x19,  0x16,  0xfe,  0xe0,  0x06,  0x15,
13827   0x82,  0x01,  0x41,  0x15,  0xe2,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0xae,
13828   0x10,  0x03,  0x6f,  0x1e,  0xfe,  0x9e,  0x13,  0x3e,  0x01,  0x84,  0x03,  0x9a,  0x1e,  0xfe,  0x1a,  0x12,
13829   0x01,  0x38,  0x06,  0x12,  0xfc,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,  0x43,  0x48,  0x62,  0x80,
13830   0xf0,  0x45,  0x0a,  0x95,  0x03,  0xb6,  0x1e,  0xf8,  0x01,  0x38,  0x06,  0x24,  0x36,  0xfe,  0x02,  0xf6,
13831   0x07,  0x71,  0x78,  0x8c,  0x00,  0x4d,  0x62,  0x49,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x17,  0xfe,
13832   0x9a,  0x07,  0x01,  0xfe,  0xc0,  0x19,  0x16,  0xfe,  0x90,  0x07,  0x26,  0x20,  0x9e,  0x15,  0x82,  0x01,
13833   0x41,  0x15,  0xe2,  0x21,  0x9e,  0x09,  0x07,  0xfb,  0x03,  0xe6,  0xfe,  0x58,  0x57,  0x10,  0xe6,  0x05,
13834   0xfe,  0x2a,  0x06,  0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x1c,  0x07,  0x01,  0x84,  0xfe,  0x9c,  0x32,  0x5f,
13835   0x75,  0x01,  0xa6,  0x86,  0x15,  0xfe,  0xe2,  0x00,  0x2f,  0xed,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,
13836   0xce,  0x07,  0xae,  0xfe,  0x96,  0x08,  0xfe,  0x06,  0xf0,  0xfe,  0x9e,  0x08,  0xaf,  0xa0,  0x05,  0x29,
13837   0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x2e,  0x12,  0x14,  0x1d,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,
13838   0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0xfe,  0x99,  0xa4,  0x01,  0x08,  0x14,  0x00,  0x05,  0xfe,
13839   0xc6,  0x09,  0x01,  0x76,  0x06,  0x12,  0xfe,  0x3a,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x30,  0x13,
13840   0x14,  0xfe,  0x1b,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,  0x01,  0x08,  0x14,  0x00,
13841   0x01,  0x08,  0x14,  0x07,  0x01,  0x08,  0x14,  0x00,  0x05,  0xef,  0x7c,  0x4a,  0x78,  0x4f,  0x0f,  0xfe,
13842   0x9a,  0x81,  0x04,  0xfe,  0x9a,  0x83,  0xfe,  0xcb,  0x47,  0x0b,  0x0e,  0x2d,  0x28,  0x48,  0xfe,  0x6c,
13843   0x08,  0x0a,  0x28,  0xfe,  0x09,  0x6f,  0xca,  0xfe,  0xca,  0x45,  0xfe,  0x32,  0x12,  0x53,  0x63,  0x4e,
13844   0x7c,  0x97,  0x2f,  0xfe,  0x7e,  0x08,  0x2a,  0x3c,  0xfe,  0x0a,  0xf0,  0xfe,  0x6c,  0x08,  0xaf,  0xa0,
13845   0xae,  0xfe,  0x96,  0x08,  0x05,  0x29,  0x01,  0x41,  0x05,  0xed,  0x14,  0x24,  0x05,  0xed,  0xfe,  0x9c,
13846   0xf7,  0x9f,  0x01,  0xfe,  0xae,  0x1e,  0xfe,  0x18,  0x58,  0x01,  0xfe,  0xbe,  0x1e,  0xfe,  0x99,  0x58,
13847   0xfe,  0x78,  0x18,  0xfe,  0xf9,  0x18,  0x8e,  0xfe,  0x16,  0x09,  0x10,  0x6a,  0x22,  0x6b,  0x01,  0x0c,
13848   0x61,  0x54,  0x44,  0x21,  0x2c,  0x09,  0x1a,  0xf8,  0x77,  0x01,  0xfe,  0x7e,  0x1e,  0x47,  0x2c,  0x7a,
13849   0x30,  0xf0,  0xfe,  0x83,  0xe7,  0xfe,  0x3f,  0x00,  0x71,  0xfe,  0x03,  0x40,  0x01,  0x0c,  0x61,  0x65,
13850   0x44,  0x01,  0xc2,  0xc8,  0xfe,  0x1f,  0x40,  0x20,  0x6e,  0x01,  0xfe,  0x6a,  0x16,  0xfe,  0x08,  0x50,
13851   0xfe,  0x8a,  0x50,  0xfe,  0x44,  0x51,  0xfe,  0xc6,  0x51,  0xfe,  0x10,  0x10,  0x01,  0xfe,  0xce,  0x1e,
13852   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x01,  0xfe,  0xee,  0x1e,  0x01,  0xfe,  0xfe,  0x1e,
13853   0xfe,  0x40,  0x50,  0xfe,  0xc2,  0x50,  0x10,  0x4b,  0x22,  0x4c,  0xfe,  0x8a,  0x10,  0x01,  0x0c,  0x06,
13854   0x54,  0xfe,  0x50,  0x12,  0x01,  0xfe,  0xae,  0x1e,  0x01,  0xfe,  0xbe,  0x1e,  0x10,  0x6a,  0x22,  0x6b,
13855   0x01,  0x0c,  0x06,  0x65,  0x4e,  0x01,  0xc2,  0x0f,  0xfe,  0x1f,  0x80,  0x04,  0xfe,  0x9f,  0x83,  0x33,
13856   0x0b,  0x0e,  0x20,  0x6e,  0x0f,  0xfe,  0x44,  0x90,  0x04,  0xfe,  0xc4,  0x93,  0x3a,  0x0b,  0xfe,  0xc6,
13857   0x90,  0x04,  0xfe,  0xc6,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x6c,  0x22,  0x6d,  0x01,  0xfe,  0xce,  0x1e,
13858   0x01,  0xfe,  0xde,  0x1e,  0x10,  0x68,  0x22,  0x69,  0x0f,  0xfe,  0x40,  0x90,  0x04,  0xfe,  0xc0,  0x93,
13859   0x3a,  0x0b,  0xfe,  0xc2,  0x90,  0x04,  0xfe,  0xc2,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0x4b,  0x22,  0x4c,
13860   0x10,  0x64,  0x22,  0x34,  0x01,  0x0c,  0x61,  0x24,  0x44,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13861   0xde,  0x09,  0xfe,  0x9e,  0xf0,  0xfe,  0xf2,  0x09,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13862   0xd4,  0xfe,  0x1e,  0x0a,  0xd5,  0xfe,  0x42,  0x0a,  0xd2,  0xfe,  0x1e,  0x0a,  0xd3,  0xfe,  0x42,  0x0a,
13863   0xae,  0xfe,  0x12,  0x0a,  0xfe,  0x06,  0xf0,  0xfe,  0x18,  0x0a,  0xaf,  0xa0,  0x05,  0x29,  0x01,  0x41,
13864   0xfe,  0xc1,  0x10,  0x14,  0x24,  0xfe,  0xc1,  0x10,  0x01,  0x76,  0x06,  0x07,  0xfe,  0x14,  0x12,  0x01,
13865   0x76,  0x06,  0x0d,  0x5d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x74,  0x12,  0xfe,  0x2e,  0x1c,  0x05,  0xfe,
13866   0x1a,  0x0c,  0x01,  0x76,  0x06,  0x07,  0x5d,  0x01,  0x76,  0x06,  0x0d,  0x41,  0xfe,  0x2c,  0x1c,  0xfe,
13867   0xaa,  0xf0,  0xfe,  0xce,  0x0a,  0xfe,  0xac,  0xf0,  0xfe,  0x66,  0x0a,  0xfe,  0x92,  0x10,  0xc4,  0xf6,
13868   0xfe,  0xad,  0xf0,  0xfe,  0x72,  0x0a,  0x05,  0xfe,  0x1a,  0x0c,  0xc5,  0xfe,  0xe7,  0x10,  0xfe,  0x2b,
13869   0xf0,  0xbf,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xfe,  0xfe,  0x1c,  0x12,  0xac,  0xfe,  0xd2,  0xf0,
13870   0xbf,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x1b,  0xbf,  0x03,  0xe3,  0x23,  0x07,  0x1b,  0xbf,  0xd4,  0x5b,
13871   0xd5,  0x5b,  0xd2,  0x5b,  0xd3,  0x5b,  0xc4,  0xc5,  0xfe,  0xa9,  0x10,  0x75,  0x5e,  0x32,  0x1f,  0x7f,
13872   0x01,  0x42,  0x19,  0xfe,  0x35,  0x00,  0xfe,  0x01,  0xf0,  0x70,  0x19,  0x98,  0x05,  0x70,  0xfe,  0x74,
13873   0x18,  0x23,  0xfe,  0x00,  0xf8,  0x1b,  0x5b,  0x7d,  0x12,  0x01,  0xfe,  0x78,  0x0f,  0x4d,  0x01,  0xfe,
13874   0x96,  0x1a,  0x21,  0x30,  0x77,  0x7d,  0x1d,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x0d,  0x2b,  0xfe,  0xe2,
13875   0x0b,  0x01,  0x0c,  0x06,  0x54,  0xfe,  0xa6,  0x12,  0x01,  0x0c,  0x06,  0x24,  0xfe,  0x88,  0x13,  0x21,
13876   0x6e,  0xc7,  0x01,  0xfe,  0x1e,  0x1f,  0x0f,  0xfe,  0x83,  0x80,  0x04,  0xfe,  0x83,  0x83,  0xfe,  0xc9,
13877   0x47,  0x0b,  0x0e,  0xfe,  0xc8,  0x44,  0xfe,  0x42,  0x13,  0x0f,  0xfe,  0x04,  0x91,  0x04,  0xfe,  0x84,
13878   0x93,  0xfe,  0xca,  0x57,  0x0b,  0xfe,  0x86,  0x91,  0x04,  0xfe,  0x86,  0x93,  0xfe,  0xcb,  0x57,  0x0b,
13879   0x0e,  0x7a,  0x30,  0xfe,  0x40,  0x59,  0xfe,  0xc1,  0x59,  0x8e,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0x10,
13880   0x97,  0x22,  0x98,  0xd9,  0x6a,  0xda,  0x6b,  0x01,  0xc2,  0xc8,  0x7a,  0x30,  0x20,  0x6e,  0xdb,  0x64,
13881   0xdc,  0x34,  0x91,  0x6c,  0x7e,  0x6d,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xfe,  0x04,  0xfa,  0x64,
13882   0xfe,  0x05,  0xfa,  0x34,  0x01,  0xfe,  0x6a,  0x16,  0xa3,  0x26,  0x10,  0x97,  0x10,  0x98,  0x91,  0x6c,
13883   0x7e,  0x6d,  0xfe,  0x14,  0x10,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x91,  0x4b,  0x7e,  0x4c,  0x01,
13884   0x0c,  0x06,  0xfe,  0xf7,  0x00,  0x44,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x10,  0x58,  0xfe,  0x91,  0x58,
13885   0xfe,  0x14,  0x59,  0xfe,  0x95,  0x59,  0x05,  0x5b,  0x01,  0x0c,  0x06,  0x24,  0x1b,  0x40,  0x01,  0x0c,
13886   0x06,  0xfe,  0xf7,  0x00,  0x44,  0x78,  0x01,  0xfe,  0x8e,  0x1e,  0x4f,  0x0f,  0xfe,  0x10,  0x90,  0x04,
13887   0xfe,  0x90,  0x93,  0x3a,  0x0b,  0xfe,  0x92,  0x90,  0x04,  0xfe,  0x92,  0x93,  0x79,  0x0b,  0x0e,  0xfe,
13888   0xbd,  0x10,  0x01,  0x43,  0x09,  0xbb,  0x1b,  0xfe,  0x6e,  0x0a,  0x15,  0xbb,  0x01,  0x0c,  0x06,  0x0d,
13889   0xfe,  0x14,  0x13,  0x03,  0x4b,  0x3b,  0x4c,  0x8e,  0xfe,  0x6e,  0x0a,  0xfe,  0x0c,  0x58,  0xfe,  0x8d,
13890   0x58,  0x05,  0x5b,  0x26,  0x3e,  0x0f,  0xfe,  0x19,  0x80,  0x04,  0xfe,  0x99,  0x83,  0x33,  0x0b,  0x0e,
13891   0xfe,  0xe5,  0x10,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1a,  0x12,  0xfe,  0x6c,  0x19,  0xfe,  0x19,  0x41,
13892   0xfe,  0x6b,  0x18,  0xac,  0xfe,  0xd1,  0xf0,  0xef,  0x1f,  0x92,  0x01,  0x42,  0x19,  0xfe,  0x44,  0x00,
13893   0xfe,  0x90,  0x10,  0xfe,  0x6c,  0x19,  0xd9,  0x4b,  0xfe,  0xed,  0x19,  0xda,  0x4c,  0xfe,  0x0c,  0x51,
13894   0xfe,  0x8e,  0x51,  0xfe,  0x6b,  0x18,  0x23,  0xfe,  0x00,  0xff,  0x31,  0xfe,  0x76,  0x10,  0xac,  0xfe,
13895   0xd2,  0xf0,  0xfe,  0xba,  0x0c,  0xfe,  0x76,  0x18,  0x23,  0x1d,  0x5d,  0x03,  0xe3,  0x23,  0x07,  0xfe,
13896   0x08,  0x13,  0x19,  0xfe,  0x16,  0x00,  0x05,  0x70,  0xfe,  0xd1,  0xf0,  0xfe,  0xcc,  0x0c,  0x1f,  0x92,
13897   0x01,  0x42,  0x19,  0xfe,  0x17,  0x00,  0x5c,  0xfe,  0xce,  0xf0,  0xfe,  0xd2,  0x0c,  0xfe,  0x3e,  0x10,
13898   0xfe,  0xcd,  0xf0,  0xfe,  0xde,  0x0c,  0x19,  0xfe,  0x22,  0x00,  0x05,  0x70,  0xfe,  0xcb,  0xf0,  0xfe,
13899   0xea,  0x0c,  0x19,  0xfe,  0x24,  0x00,  0x05,  0x70,  0xfe,  0xd0,  0xf0,  0xfe,  0xf4,  0x0c,  0x19,  0x94,
13900   0xfe,  0x1c,  0x10,  0xfe,  0xcf,  0xf0,  0xfe,  0xfe,  0x0c,  0x19,  0x4a,  0xf3,  0xfe,  0xcc,  0xf0,  0xef,
13901   0x01,  0x76,  0x06,  0x24,  0x4d,  0x19,  0xfe,  0x12,  0x00,  0x37,  0x13,  0xfe,  0x4e,  0x11,  0x2f,  0xfe,
13902   0x16,  0x0d,  0xfe,  0x9e,  0xf0,  0xfe,  0x2a,  0x0d,  0xfe,  0x01,  0x48,  0x1b,  0x3c,  0x37,  0x88,  0xf5,
13903   0xd4,  0x29,  0xd5,  0x29,  0xd2,  0x29,  0xd3,  0x29,  0x37,  0xfe,  0x9c,  0x32,  0x2f,  0xfe,  0x3e,  0x0d,
13904   0x2a,  0x3c,  0xae,  0xfe,  0x62,  0x0d,  0xaf,  0xa0,  0xd4,  0x9f,  0xd5,  0x9f,  0xd2,  0x9f,  0xd3,  0x9f,
13905   0x05,  0x29,  0x01,  0x41,  0xfe,  0xd3,  0x10,  0x15,  0xfe,  0xe8,  0x00,  0xc4,  0xc5,  0x75,  0xd7,  0x99,
13906   0xd8,  0x9c,  0xfe,  0x89,  0xf0,  0x29,  0x27,  0x25,  0xbe,  0xd7,  0x99,  0xd8,  0x9c,  0x2f,  0xfe,  0x8c,
13907   0x0d,  0x16,  0x29,  0x27,  0x25,  0xbd,  0xfe,  0x01,  0x48,  0xa4,  0x19,  0xfe,  0x42,  0x00,  0x05,  0x70,
13908   0x90,  0x07,  0xfe,  0x81,  0x49,  0x1b,  0xfe,  0x64,  0x0e,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x44,  0x13,
13909   0x19,  0x00,  0x2d,  0x0d,  0xfe,  0x54,  0x12,  0x2d,  0xfe,  0x28,  0x00,  0x2b,  0xfe,  0xda,  0x0e,  0x0a,
13910   0x57,  0x01,  0x18,  0x09,  0x00,  0x36,  0x46,  0xfe,  0x28,  0x00,  0xfe,  0xfa,  0x10,  0x01,  0xfe,  0xf4,
13911   0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x0a,  0xba,  0x01,  0xfe,  0x58,  0x10,  0x40,  0x15,  0x56,  0x01,  0x85,
13912   0x05,  0x35,  0x19,  0xfe,  0x44,  0x00,  0x2d,  0x0d,  0xf7,  0x46,  0x0d,  0xfe,  0xcc,  0x10,  0x01,  0xa7,
13913   0x46,  0x0d,  0xfe,  0xc2,  0x10,  0x01,  0xa7,  0x0f,  0xfe,  0x19,  0x82,  0x04,  0xfe,  0x99,  0x83,  0xfe,
13914   0xcc,  0x47,  0x0b,  0x0e,  0xfe,  0x34,  0x46,  0xa5,  0x46,  0x0d,  0x19,  0xfe,  0x43,  0x00,  0xfe,  0xa2,
13915   0x10,  0x01,  0x0c,  0x61,  0x0d,  0x44,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x40,  0x15,
13916   0x56,  0x01,  0x85,  0x7d,  0x0d,  0x40,  0x51,  0x01,  0xfe,  0x9e,  0x1e,  0x05,  0xfe,  0x3a,  0x03,  0x01,
13917   0x0c,  0x06,  0x0d,  0x5d,  0x46,  0x0d,  0x19,  0x00,  0xfe,  0x62,  0x10,  0x01,  0x76,  0x06,  0x12,  0xfe,
13918   0x5c,  0x12,  0x01,  0x0c,  0x06,  0x12,  0xfe,  0x52,  0x13,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,
13919   0x8e,  0x0e,  0xfe,  0x1c,  0x1c,  0xfe,  0x9d,  0xf0,  0xfe,  0x94,  0x0e,  0x01,  0x0c,  0x61,  0x12,  0x44,
13920   0xfe,  0x9f,  0x10,  0x19,  0xfe,  0x15,  0x00,  0xfe,  0x04,  0xe6,  0x0d,  0x4f,  0xfe,  0x2e,  0x10,  0x19,
13921   0xfe,  0x13,  0x00,  0xfe,  0x10,  0x10,  0x19,  0xfe,  0x47,  0x00,  0xf1,  0x19,  0xfe,  0x41,  0x00,  0xa2,
13922   0x19,  0xfe,  0x24,  0x00,  0x86,  0xc4,  0xc5,  0x75,  0x03,  0x81,  0x1e,  0x2b,  0xea,  0x4f,  0xfe,  0x04,
13923   0xe6,  0x12,  0xfe,  0x9d,  0x41,  0xfe,  0x1c,  0x42,  0x40,  0x01,  0xf4,  0x05,  0x35,  0xfe,  0x12,  0x1c,
13924   0x1f,  0x0d,  0x47,  0xb5,  0xc3,  0x1f,  0xfe,  0x31,  0x00,  0x47,  0xb8,  0x01,  0xfe,  0xd4,  0x11,  0x05,
13925   0xe9,  0x51,  0xfe,  0x06,  0xec,  0xe0,  0xfe,  0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,
13926   0xfe,  0x06,  0xea,  0xe0,  0xfe,  0x47,  0x4b,  0x45,  0xfe,  0x75,  0x57,  0x03,  0x67,  0xfe,  0x98,  0x56,
13927   0xfe,  0x38,  0x12,  0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x44,  0x48,  0x60,  0x01,  0x0c,  0x06,  0x28,  0xfe,
13928   0x18,  0x13,  0x0a,  0x57,  0x01,  0x18,  0x3e,  0xfe,  0x41,  0x58,  0x0a,  0xba,  0xfe,  0xfa,  0x14,  0xfe,
13929   0x49,  0x54,  0xb0,  0xfe,  0x5e,  0x0f,  0x05,  0xfe,  0x3a,  0x03,  0x0a,  0x67,  0xfe,  0xe0,  0x14,  0xfe,
13930   0x0e,  0x47,  0x46,  0x28,  0xfe,  0xce,  0x45,  0x31,  0x51,  0xfe,  0xce,  0x47,  0xfe,  0xad,  0x13,  0x05,
13931   0x35,  0x21,  0x2c,  0x09,  0x1a,  0xfe,  0x98,  0x12,  0x26,  0x20,  0x96,  0x20,  0xe7,  0xfe,  0x08,  0x1c,
13932   0xfe,  0x7c,  0x19,  0xfe,  0xfd,  0x19,  0xfe,  0x0a,  0x1c,  0x03,  0xe5,  0xfe,  0x48,  0x55,  0xa5,  0x3b,
13933   0xfe,  0x62,  0x01,  0xfe,  0xc9,  0x55,  0x31,  0xfe,  0x74,  0x10,  0x01,  0xfe,  0xf0,  0x1a,  0x03,  0xfe,
13934   0x38,  0x01,  0x3b,  0xfe,  0x3a,  0x01,  0x8e,  0xfe,  0x1e,  0x10,  0xfe,  0x02,  0xec,  0xe7,  0x53,  0x00,
13935   0x36,  0xfe,  0x04,  0xec,  0x2c,  0x60,  0xfe,  0x05,  0xf6,  0xfe,  0x34,  0x01,  0x01,  0xfe,  0x62,  0x1b,
13936   0x01,  0xfe,  0xce,  0x1e,  0xb2,  0x11,  0xfe,  0x18,  0x13,  0xca,  0xfe,  0x02,  0xea,  0xe7,  0x53,  0x92,
13937   0xfe,  0xc3,  0x13,  0x1f,  0x12,  0x47,  0xb5,  0xc3,  0xfe,  0x2a,  0x10,  0x03,  0xfe,  0x38,  0x01,  0x23,
13938   0xfe,  0xf0,  0xff,  0x10,  0xe5,  0x03,  0xfe,  0x3a,  0x01,  0x10,  0xfe,  0x62,  0x01,  0x01,  0xfe,  0x1e,
13939   0x1e,  0x20,  0x2c,  0x15,  0x56,  0x01,  0xfe,  0x9e,  0x1e,  0x13,  0x07,  0x02,  0x26,  0x02,  0x21,  0x96,
13940   0xc7,  0x20,  0x96,  0x09,  0x92,  0xfe,  0x79,  0x13,  0x1f,  0x1d,  0x47,  0xb5,  0xc3,  0xfe,  0xe1,  0x10,
13941   0xcf,  0xfe,  0x03,  0xdc,  0xfe,  0x73,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xcf,  0xfe,  0x03,  0xdc,  0xfe,
13942   0x5b,  0x57,  0xfe,  0x80,  0x5d,  0x02,  0xfe,  0x03,  0x57,  0xcf,  0x26,  0xfe,  0x00,  0xcc,  0x02,  0xfe,
13943   0x03,  0x57,  0xcf,  0x89,  0x02,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x0f,  0xfe,  0x1c,  0x80,
13944   0x04,  0xfe,  0x9c,  0x83,  0x33,  0x0b,  0x0e,  0x09,  0x07,  0xfe,  0x3a,  0x13,  0x0f,  0xfe,  0x1e,  0x80,
13945   0x04,  0xfe,  0x9e,  0x83,  0x33,  0x0b,  0x0e,  0xfe,  0x2a,  0x13,  0x0f,  0xfe,  0x1d,  0x80,  0x04,  0xfe,
13946   0x9d,  0x83,  0xfe,  0xf9,  0x13,  0x0e,  0xfe,  0x1c,  0x13,  0x01,  0xfe,  0xee,  0x1e,  0xac,  0xfe,  0x14,
13947   0x13,  0x01,  0xfe,  0xfe,  0x1e,  0xfe,  0x81,  0x58,  0xfa,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,
13948   0x0d,  0xfe,  0x3c,  0x50,  0xa2,  0x01,  0xfe,  0x92,  0x1b,  0x01,  0x43,  0x09,  0x56,  0xfb,  0x01,  0xfe,
13949   0xc8,  0x1a,  0x01,  0x0c,  0x06,  0x28,  0xa4,  0x01,  0xfe,  0xf4,  0x1c,  0x01,  0xfe,  0x00,  0x1d,  0x15,
13950   0xfe,  0xe9,  0x00,  0x01,  0x0c,  0x06,  0x4a,  0xfe,  0x4e,  0x13,  0x01,  0xfe,  0x22,  0x1b,  0xfe,  0x1e,
13951   0x1c,  0x0f,  0xfe,  0x14,  0x90,  0x04,  0xfe,  0x94,  0x93,  0x3a,  0x0b,  0xfe,  0x96,  0x90,  0x04,  0xfe,
13952   0x96,  0x93,  0x79,  0x0b,  0x0e,  0x10,  0xfe,  0x64,  0x01,  0x22,  0xfe,  0x66,  0x01,  0x01,  0x0c,  0x06,
13953   0x65,  0xf9,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,  0x33,  0x0b,  0x0e,  0x77,  0xfe,  0x01,
13954   0xec,  0x2c,  0xfe,  0x80,  0x40,  0x20,  0x2c,  0x7a,  0x30,  0x15,  0xdf,  0x40,  0x21,  0x2c,  0xfe,  0x00,
13955   0x40,  0x8d,  0x2c,  0x02,  0xfe,  0x08,  0x1c,  0x03,  0xfe,  0xac,  0x00,  0xfe,  0x06,  0x58,  0x03,  0xfe,
13956   0xae,  0x00,  0xfe,  0x07,  0x58,  0x03,  0xfe,  0xb0,  0x00,  0xfe,  0x08,  0x58,  0x03,  0xfe,  0xb2,  0x00,
13957   0xfe,  0x09,  0x58,  0xfe,  0x0a,  0x1c,  0x2e,  0x49,  0x20,  0xe0,  0x26,  0x10,  0x66,  0x10,  0x55,  0x10,
13958   0x6f,  0x13,  0x57,  0x52,  0x4f,  0x1c,  0x28,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,  0x88,
13959   0x11,  0x46,  0x1a,  0x13,  0x5a,  0x52,  0x1c,  0x4a,  0xfe,  0x90,  0x4d,  0xfe,  0x91,  0x54,  0x2b,  0xfe,
13960   0x9e,  0x11,  0x2e,  0x1a,  0x20,  0x2c,  0x90,  0x34,  0x60,  0x21,  0x2c,  0xfe,  0x00,  0x40,  0x8d,  0x2c,
13961   0x15,  0xdf,  0xfe,  0x14,  0x56,  0xfe,  0xd6,  0xf0,  0xfe,  0xb2,  0x11,  0xfe,  0x12,  0x1c,  0x75,  0xfe,
13962   0x14,  0x1c,  0xfe,  0x10,  0x1c,  0xfe,  0x18,  0x1c,  0x02,  0x51,  0xfe,  0x0c,  0x14,  0xfe,  0x0e,  0x47,
13963   0xfe,  0x07,  0xe6,  0x28,  0xfe,  0xce,  0x47,  0xfe,  0xf5,  0x13,  0x02,  0x01,  0xa7,  0x90,  0x34,  0x60,
13964   0xfe,  0x06,  0x80,  0xfe,  0x48,  0x47,  0xfe,  0x42,  0x13,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x34,
13965   0x13,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,  0x36,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,
13966   0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,  0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,
13967   0x9d,  0x01,  0x18,  0xfe,  0x80,  0x5c,  0x01,  0x85,  0xf2,  0x09,  0x9b,  0xa4,  0xfe,  0x14,  0x56,  0xfe,
13968   0xd6,  0xf0,  0xfe,  0xec,  0x11,  0x02,  0xfe,  0x44,  0x58,  0x77,  0xfe,  0x01,  0xec,  0xb8,  0xfe,  0x9e,
13969   0x40,  0xfe,  0x9d,  0xe7,  0x00,  0xfe,  0x9c,  0xe7,  0x12,  0x8d,  0x30,  0x01,  0xf4,  0xfe,  0xdd,  0x10,
13970   0x37,  0xd7,  0x99,  0xd8,  0x9c,  0x27,  0x25,  0xee,  0x09,  0x12,  0xfe,  0x48,  0x12,  0x09,  0x0d,  0xfe,
13971   0x56,  0x12,  0x09,  0x1d,  0xfe,  0x30,  0x12,  0x09,  0xdd,  0x1b,  0xfe,  0xc4,  0x13,  0x09,  0xfe,  0x23,
13972   0x00,  0x1b,  0xfe,  0xd0,  0x13,  0x09,  0x07,  0x1b,  0xfe,  0x34,  0x14,  0x09,  0x24,  0xfe,  0x12,  0x12,
13973   0x09,  0x00,  0x1b,  0x29,  0x1f,  0xdd,  0x01,  0x42,  0xa1,  0x32,  0x01,  0x08,  0xae,  0x41,  0x02,  0x32,
13974   0xfe,  0x62,  0x08,  0x0a,  0xe1,  0x01,  0xfe,  0x58,  0x10,  0x15,  0x9b,  0x05,  0x35,  0x32,  0x01,  0x43,
13975   0x09,  0xbb,  0xfe,  0xd7,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0x8e,  0xfe,  0x80,  0x13,  0x01,  0x0c,  0x06,
13976   0x54,  0xfe,  0x72,  0x12,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,  0x55,  0xb0,  0xfe,
13977   0x4a,  0x13,  0x21,  0x6e,  0xfe,  0x26,  0x13,  0x03,  0x97,  0x3b,  0x98,  0x8e,  0xfe,  0xb6,  0x0e,  0x10,
13978   0x6a,  0x22,  0x6b,  0x26,  0x10,  0x97,  0x10,  0x98,  0x01,  0xc2,  0x2e,  0x49,  0x88,  0x20,  0x6e,  0x01,
13979   0xfe,  0x6a,  0x16,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x04,  0x55,  0xfe,  0xa5,  0x55,  0xfe,  0x04,  0xfa,
13980   0x64,  0xfe,  0x05,  0xfa,  0x34,  0xfe,  0x8f,  0x10,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x40,  0x56,  0xfe,
13981   0xe1,  0x56,  0x10,  0x6c,  0x22,  0x6d,  0x71,  0xdb,  0x64,  0xdc,  0x34,  0xfe,  0x44,  0x55,  0xfe,  0xe5,
13982   0x55,  0x03,  0x68,  0x3b,  0x69,  0xfe,  0x00,  0x56,  0xfe,  0xa1,  0x56,  0x10,  0x68,  0x22,  0x69,  0x01,
13983   0x0c,  0x06,  0x54,  0xf9,  0x21,  0x6e,  0xfe,  0x1f,  0x40,  0x03,  0x6a,  0x3b,  0x6b,  0xfe,  0x2c,  0x50,
13984   0xfe,  0xae,  0x50,  0x03,  0x6c,  0x3b,  0x6d,  0xfe,  0x44,  0x50,  0xfe,  0xc6,  0x50,  0x03,  0x68,  0x3b,
13985   0x69,  0xfe,  0x08,  0x50,  0xfe,  0x8a,  0x50,  0x03,  0x4b,  0x3b,  0x4c,  0xfe,  0x40,  0x50,  0xfe,  0xc2,
13986   0x50,  0x05,  0x73,  0x2e,  0x07,  0x20,  0x9e,  0x05,  0x72,  0x32,  0x01,  0x08,  0x16,  0x3d,  0x27,  0x25,
13987   0xee,  0x09,  0x07,  0x2b,  0x3d,  0x01,  0x43,  0x09,  0xbb,  0x2b,  0x72,  0x01,  0xa6,  0x23,  0x3f,  0x1b,
13988   0x3d,  0x01,  0x0c,  0x06,  0x0d,  0xfe,  0x1e,  0x13,  0x91,  0x4b,  0x7e,  0x4c,  0xfe,  0x0a,  0x55,  0x31,
13989   0xfe,  0x8b,  0x55,  0xd9,  0x4b,  0xda,  0x4c,  0xfe,  0x0c,  0x51,  0xfe,  0x8e,  0x51,  0x05,  0x72,  0x01,
13990   0xfe,  0x8e,  0x1e,  0xca,  0xfe,  0x19,  0x41,  0x05,  0x72,  0x32,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,
13991   0x27,  0x25,  0xbe,  0x2d,  0x1d,  0xc0,  0x2d,  0x0d,  0x83,  0x2d,  0x7f,  0x1b,  0xfe,  0x66,  0x15,  0x05,
13992   0x3d,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0xc0,  0x27,  0x25,  0xbd,  0x09,  0x1d,  0x2b,  0x3d,  0x01,  0x08,
13993   0x16,  0xc0,  0x27,  0x25,  0xfe,  0xe8,  0x09,  0xfe,  0xc2,  0x49,  0x50,  0x03,  0xb6,  0x1e,  0x83,  0x01,
13994   0x38,  0x06,  0x24,  0x31,  0xa1,  0xfe,  0xbb,  0x45,  0x2d,  0x00,  0xa4,  0x46,  0x07,  0x90,  0x3f,  0x01,
13995   0xfe,  0xf8,  0x15,  0x01,  0xa6,  0x86,  0xfe,  0x4b,  0x45,  0xfe,  0x20,  0x13,  0x01,  0x43,  0x09,  0x82,
13996   0xfe,  0x16,  0x13,  0x03,  0x9a,  0x1e,  0x5d,  0x03,  0x55,  0x1e,  0x31,  0x5e,  0x05,  0x72,  0xfe,  0xc0,
13997   0x5d,  0x01,  0xa7,  0xfe,  0x03,  0x17,  0x03,  0x66,  0x8a,  0x10,  0x66,  0x5e,  0x32,  0x01,  0x08,  0x17,
13998   0x73,  0x01,  0xfe,  0x56,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,
13999   0x09,  0x07,  0x2b,  0x3d,  0x01,  0xfe,  0xbe,  0x16,  0xfe,  0x42,  0x58,  0xfe,  0xe8,  0x14,  0x01,  0xa6,
14000   0x86,  0xfe,  0x4a,  0xf4,  0x0d,  0x1b,  0x3d,  0xfe,  0x4a,  0xf4,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,
14001   0x09,  0x82,  0x4e,  0x05,  0x72,  0x03,  0x55,  0x8a,  0x10,  0x55,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,
14002   0x01,  0xfe,  0x84,  0x19,  0x05,  0x73,  0x01,  0x08,  0x2a,  0x3c,  0x16,  0x3d,  0x27,  0x25,  0xbd,  0x09,
14003   0x12,  0x2b,  0x3d,  0x01,  0xfe,  0xe8,  0x17,  0x8b,  0xfe,  0xaa,  0x14,  0xfe,  0xb6,  0x14,  0x86,  0xa8,
14004   0xb2,  0x0d,  0x1b,  0x3d,  0xb2,  0x07,  0xfe,  0x0e,  0x12,  0x01,  0x43,  0x09,  0x82,  0x4e,  0x05,  0x72,
14005   0x03,  0x6f,  0x8a,  0x10,  0x6f,  0x5e,  0x32,  0x01,  0x08,  0x17,  0x73,  0x01,  0xfe,  0xc0,  0x19,  0x05,
14006   0x73,  0x13,  0x07,  0x2f,  0xfe,  0xcc,  0x15,  0x17,  0xfe,  0xe2,  0x15,  0x5f,  0xcc,  0x01,  0x08,  0x26,
14007   0x5f,  0x02,  0x8f,  0xfe,  0xde,  0x15,  0x2a,  0xfe,  0xde,  0x15,  0x16,  0xfe,  0xcc,  0x15,  0x5e,  0x32,
14008   0x01,  0x08,  0xfe,  0xd5,  0x10,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,  0x23,  0xfe,  0xff,
14009   0x7f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xad,
14010   0x23,  0x3f,  0xfe,  0x30,  0x56,  0xfe,  0x00,  0x5c,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,
14011   0xad,  0x02,  0x13,  0x58,  0xff,  0x02,  0x00,  0x57,  0x52,  0xfe,  0x00,  0x5e,  0x02,  0x13,  0x58,  0xff,
14012   0x02,  0x00,  0x57,  0x52,  0xad,  0xfe,  0x0b,  0x58,  0x02,  0x0a,  0x66,  0x01,  0x5c,  0x0a,  0x55,  0x01,
14013   0x5c,  0x0a,  0x6f,  0x01,  0x5c,  0x02,  0x01,  0xfe,  0x1e,  0x1f,  0x23,  0x1a,  0xff,  0x03,  0x00,  0x54,
14014   0xfe,  0x00,  0xf4,  0x24,  0x52,  0x0f,  0xfe,  0x00,  0x7c,  0x04,  0xfe,  0x07,  0x7c,  0x3a,  0x0b,  0x0e,
14015   0xfe,  0x00,  0x71,  0xfe,  0xf9,  0x18,  0xfe,  0x7a,  0x19,  0xfe,  0xfb,  0x19,  0xfe,  0x1a,  0xf7,  0x00,
14016   0xfe,  0x1b,  0xf7,  0x00,  0x7a,  0x30,  0x10,  0x68,  0x22,  0x69,  0xd9,  0x6c,  0xda,  0x6d,  0x02,  0xfe,
14017   0x62,  0x08,  0xfe,  0x82,  0x4a,  0xfe,  0xe1,  0x1a,  0xfe,  0x83,  0x5a,  0x77,  0x02,  0x01,  0xc6,  0xfe,
14018   0x42,  0x48,  0x4f,  0x50,  0x45,  0x01,  0x08,  0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xbe,  0x01,  0x08,
14019   0x16,  0xfe,  0xe0,  0x17,  0x27,  0x25,  0xfe,  0xe8,  0x0a,  0xfe,  0xc1,  0x59,  0x03,  0x9a,  0x1e,  0xfe,
14020   0xda,  0x12,  0x01,  0x38,  0x06,  0x12,  0xfe,  0xd0,  0x13,  0x26,  0x53,  0x12,  0x48,  0xfe,  0x08,  0x17,
14021   0xd1,  0x12,  0x53,  0x12,  0xfe,  0x1e,  0x13,  0x2d,  0xb4,  0x7b,  0xfe,  0x26,  0x17,  0x4d,  0x13,  0x07,
14022   0x1c,  0xb4,  0x90,  0x04,  0xfe,  0x78,  0x10,  0xff,  0x02,  0x83,  0x55,  0xf1,  0xff,  0x02,  0x83,  0x55,
14023   0x53,  0x1d,  0xfe,  0x12,  0x13,  0xd6,  0xfe,  0x30,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x1c,  0x63,  0x13,
14024   0x07,  0xfe,  0x56,  0x10,  0x53,  0x0d,  0xfe,  0x16,  0x13,  0xd6,  0xfe,  0x64,  0x00,  0xb0,  0xfe,  0x80,
14025   0x17,  0x0a,  0xfe,  0x64,  0x00,  0x1c,  0x94,  0x13,  0x07,  0xfe,  0x28,  0x10,  0x53,  0x07,  0xfe,  0x60,
14026   0x13,  0xd6,  0xfe,  0xc8,  0x00,  0xb0,  0xfe,  0x80,  0x17,  0x0a,  0xfe,  0xc8,  0x00,  0x1c,  0x95,  0x13,
14027   0x07,  0x71,  0xd6,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0x8c,  0x17,  0x45,  0xf3,  0xfe,  0x43,  0xf4,  0x96,
14028   0xfe,  0x56,  0xf0,  0xfe,  0x9e,  0x17,  0xfe,  0x04,  0xf4,  0x58,  0xfe,  0x43,  0xf4,  0x94,  0xf6,  0x8b,
14029   0x01,  0xfe,  0x24,  0x16,  0x23,  0x3f,  0xfc,  0xa8,  0x8c,  0x49,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x49,
14030   0xfe,  0x1c,  0x10,  0xa8,  0x8c,  0x80,  0x48,  0xfe,  0xda,  0x17,  0x62,  0x80,  0x71,  0x50,  0x26,  0xfe,
14031   0x4d,  0xf4,  0x00,  0xf7,  0x45,  0x13,  0x07,  0xfe,  0xb4,  0x56,  0xfe,  0xc3,  0x58,  0x02,  0x50,  0x13,
14032   0x0d,  0x02,  0x50,  0x3e,  0x78,  0x4f,  0x45,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xbe,  0xfe,  0x03,
14033   0xea,  0xfe,  0x7e,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0x01,  0x08,  0x16,
14034   0xa9,  0x27,  0x25,  0xfe,  0xe9,  0x0a,  0xfe,  0x05,  0xea,  0xfe,  0x7f,  0x01,  0x01,  0x08,  0x16,  0xa9,
14035   0x27,  0x25,  0xfe,  0x69,  0x09,  0xfe,  0x02,  0xea,  0xfe,  0x80,  0x01,  0x01,  0x08,  0x16,  0xa9,  0x27,
14036   0x25,  0xfe,  0xe8,  0x08,  0x47,  0xfe,  0x81,  0x01,  0x03,  0xb6,  0x1e,  0x83,  0x01,  0x38,  0x06,  0x24,
14037   0x31,  0xa2,  0x78,  0xf2,  0x53,  0x07,  0x36,  0xfe,  0x34,  0xf4,  0x3f,  0xa1,  0x78,  0x03,  0x9a,  0x1e,
14038   0x83,  0x01,  0x38,  0x06,  0x12,  0x31,  0xf0,  0x4f,  0x45,  0xfe,  0x90,  0x10,  0xfe,  0x40,  0x5a,  0x23,
14039   0x3f,  0xfb,  0x8c,  0x49,  0x48,  0xfe,  0xaa,  0x18,  0x62,  0x49,  0x71,  0x8c,  0x80,  0x48,  0xfe,  0xaa,
14040   0x18,  0x62,  0x80,  0xfe,  0xb4,  0x56,  0xfe,  0x40,  0x5d,  0x01,  0xc6,  0x01,  0xfe,  0xac,  0x1d,  0xfe,
14041   0x02,  0x17,  0xfe,  0xc8,  0x45,  0xfe,  0x5a,  0xf0,  0xfe,  0xc0,  0x18,  0xfe,  0x43,  0x48,  0x2d,  0x93,
14042   0x36,  0xfe,  0x34,  0xf4,  0xfe,  0x00,  0x11,  0xfe,  0x40,  0x10,  0x2d,  0xb4,  0x36,  0xfe,  0x34,  0xf4,
14043   0x04,  0xfe,  0x34,  0x10,  0x2d,  0xfe,  0x0b,  0x00,  0x36,  0x46,  0x63,  0xfe,  0x28,  0x10,  0xfe,  0xc0,
14044   0x49,  0xff,  0x02,  0x00,  0x54,  0xb2,  0xfe,  0x90,  0x01,  0x48,  0xfe,  0xfa,  0x18,  0x45,  0xfe,  0x1c,
14045   0xf4,  0x3f,  0xf3,  0xfe,  0x40,  0xf4,  0x96,  0xfe,  0x56,  0xf0,  0xfe,  0x0c,  0x19,  0xfe,  0x04,  0xf4,
14046   0x58,  0xfe,  0x40,  0xf4,  0x94,  0xf6,  0x3e,  0x2d,  0x93,  0x4e,  0xd0,  0x0d,  0x21,  0xfe,  0x7f,  0x01,
14047   0xfe,  0xc8,  0x46,  0xfe,  0x24,  0x13,  0x8c,  0x00,  0x5d,  0x26,  0x21,  0xfe,  0x7e,  0x01,  0xfe,  0xc8,
14048   0x45,  0xfe,  0x14,  0x13,  0x21,  0xfe,  0x80,  0x01,  0xfe,  0x48,  0x45,  0xfa,  0x21,  0xfe,  0x81,  0x01,
14049   0xfe,  0xc8,  0x44,  0x4e,  0x26,  0x02,  0x13,  0x07,  0x02,  0x78,  0x45,  0x50,  0x13,  0x0d,  0x02,  0x14,
14050   0x07,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,  0x0d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x14,
14051   0x1d,  0x01,  0x08,  0x17,  0xfe,  0x82,  0x19,  0x5f,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x02,  0x14,  0x07,
14052   0x01,  0x08,  0x17,  0xc1,  0x14,  0x1d,  0x01,  0x08,  0x17,  0xc1,  0x14,  0x07,  0x01,  0x08,  0x17,  0xc1,
14053   0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0xc1,  0x5f,  0xfe,  0x89,  0x4a,  0x01,  0x08,  0x02,  0x50,  0x02,
14054   0x14,  0x07,  0x01,  0x08,  0x17,  0x74,  0x14,  0x7f,  0x01,  0x08,  0x17,  0x74,  0x14,  0x12,  0x01,  0x08,
14055   0x17,  0x74,  0xfe,  0x89,  0x49,  0x01,  0x08,  0x17,  0x74,  0x14,  0x00,  0x01,  0x08,  0x17,  0x74,  0xfe,
14056   0x89,  0x4a,  0x01,  0x08,  0x17,  0x74,  0xfe,  0x09,  0x49,  0x01,  0x08,  0x17,  0x74,  0x5f,  0xcc,  0x01,
14057   0x08,  0x02,  0x21,  0xe4,  0x09,  0x07,  0xfe,  0x4c,  0x13,  0xc8,  0x20,  0xe4,  0xfe,  0x49,  0xf4,  0x00,
14058   0x4d,  0x5f,  0xa1,  0x5e,  0xfe,  0x01,  0xec,  0xfe,  0x27,  0x01,  0xcc,  0xff,  0x02,  0x00,  0x10,  0x2f,
14059   0xfe,  0x3e,  0x1a,  0x01,  0x43,  0x09,  0xfe,  0xe3,  0x00,  0xfe,  0x22,  0x13,  0x16,  0xfe,  0x64,  0x1a,
14060   0x26,  0x20,  0x9e,  0x01,  0x41,  0x21,  0x9e,  0x09,  0x07,  0x5d,  0x01,  0x0c,  0x61,  0x07,  0x44,  0x02,
14061   0x0a,  0x5a,  0x01,  0x18,  0xfe,  0x00,  0x40,  0xaa,  0x09,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,
14062   0x18,  0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x9d,  0x01,  0x18,  0xaa,  0xfe,  0x80,  0xe7,  0x1a,
14063   0x09,  0x1a,  0x5d,  0xfe,  0x45,  0x58,  0x01,  0xfe,  0xb2,  0x16,  0xaa,  0x02,  0x0a,  0x5a,  0x01,  0x18,
14064   0xaa,  0x0a,  0x67,  0x01,  0xa3,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x01,  0xfe,  0x7e,  0x1e,  0xfe,  0x80,
14065   0x4c,  0xfe,  0x49,  0xe4,  0x1a,  0xfe,  0x12,  0x13,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x0a,
14066   0x67,  0x01,  0x5c,  0x02,  0x1c,  0x1a,  0x87,  0x7c,  0xe5,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,
14067   0x24,  0x1c,  0xfe,  0x1d,  0xf7,  0x28,  0xb1,  0xfe,  0x04,  0x1b,  0x01,  0xfe,  0x2a,  0x1c,  0xfa,  0xb3,
14068   0x28,  0x7c,  0xfe,  0x2c,  0x01,  0xfe,  0x2f,  0x19,  0x02,  0xc9,  0x2b,  0xfe,  0xf4,  0x1a,  0xfe,  0xfa,
14069   0x10,  0x1c,  0x1a,  0x87,  0x03,  0xfe,  0x64,  0x01,  0xfe,  0x00,  0xf4,  0x24,  0xfe,  0x18,  0x58,  0x03,
14070   0xfe,  0x66,  0x01,  0xfe,  0x19,  0x58,  0xb3,  0x24,  0x01,  0xfe,  0x0e,  0x1f,  0xfe,  0x30,  0xf4,  0x07,
14071   0xfe,  0x3c,  0x50,  0x7c,  0xfe,  0x38,  0x00,  0xfe,  0x0f,  0x79,  0xfe,  0x1c,  0xf7,  0x24,  0xb1,  0xfe,
14072   0x50,  0x1b,  0xfe,  0xd4,  0x14,  0x31,  0x02,  0xc9,  0x2b,  0xfe,  0x26,  0x1b,  0xfe,  0xba,  0x10,  0x1c,
14073   0x1a,  0x87,  0xfe,  0x83,  0x5a,  0xfe,  0x18,  0xdf,  0xfe,  0x19,  0xde,  0xfe,  0x1d,  0xf7,  0x54,  0xb1,
14074   0xfe,  0x72,  0x1b,  0xfe,  0xb2,  0x14,  0xfc,  0xb3,  0x54,  0x7c,  0x12,  0xfe,  0xaf,  0x19,  0xfe,  0x98,
14075   0xe7,  0x00,  0x02,  0xc9,  0x2b,  0xfe,  0x66,  0x1b,  0xfe,  0x8a,  0x10,  0x1c,  0x1a,  0x87,  0x8b,  0x0f,
14076   0xfe,  0x30,  0x90,  0x04,  0xfe,  0xb0,  0x93,  0x3a,  0x0b,  0xfe,  0x18,  0x58,  0xfe,  0x32,  0x90,  0x04,
14077   0xfe,  0xb2,  0x93,  0x3a,  0x0b,  0xfe,  0x19,  0x58,  0x0e,  0xa8,  0xb3,  0x4a,  0x7c,  0x12,  0xfe,  0x0f,
14078   0x79,  0xfe,  0x1c,  0xf7,  0x4a,  0xb1,  0xfe,  0xc6,  0x1b,  0xfe,  0x5e,  0x14,  0x31,  0x02,  0xc9,  0x2b,
14079   0xfe,  0x96,  0x1b,  0x5c,  0xfe,  0x02,  0xf6,  0x1a,  0x87,  0xfe,  0x18,  0xfe,  0x6a,  0xfe,  0x19,  0xfe,
14080   0x6b,  0x01,  0xfe,  0x1e,  0x1f,  0xfe,  0x1d,  0xf7,  0x65,  0xb1,  0xfe,  0xee,  0x1b,  0xfe,  0x36,  0x14,
14081   0xfe,  0x1c,  0x13,  0xb3,  0x65,  0x3e,  0xfe,  0x83,  0x58,  0xfe,  0xaf,  0x19,  0xfe,  0x80,  0xe7,  0x1a,
14082   0xfe,  0x81,  0xe7,  0x1a,  0x15,  0xfe,  0xdd,  0x00,  0x7a,  0x30,  0x02,  0x7a,  0x30,  0xfe,  0x12,  0x45,
14083   0x2b,  0xfe,  0xdc,  0x1b,  0x1f,  0x07,  0x47,  0xb5,  0xc3,  0x05,  0x35,  0xfe,  0x39,  0xf0,  0x75,  0x26,
14084   0x02,  0xfe,  0x7e,  0x18,  0x23,  0x1d,  0x36,  0x13,  0x11,  0x02,  0x87,  0x03,  0xe3,  0x23,  0x07,  0xfe,
14085   0xef,  0x12,  0xfe,  0xe1,  0x10,  0x90,  0x34,  0x60,  0xfe,  0x02,  0x80,  0x09,  0x56,  0xfe,  0x3c,  0x13,
14086   0xfe,  0x82,  0x14,  0xfe,  0x42,  0x13,  0x51,  0xfe,  0x06,  0x83,  0x0a,  0x5a,  0x01,  0x18,  0xcb,  0xfe,
14087   0x3e,  0x12,  0xfe,  0x41,  0x48,  0xfe,  0x45,  0x48,  0x01,  0xfe,  0xb2,  0x16,  0xfe,  0x00,  0xcc,  0xcb,
14088   0xfe,  0xf3,  0x13,  0x3f,  0x89,  0x09,  0x1a,  0xa5,  0x0a,  0x9d,  0x01,  0x18,  0xfe,  0x80,  0x4c,  0x01,
14089   0x85,  0xfe,  0x16,  0x10,  0x09,  0x9b,  0x4e,  0xfe,  0x40,  0x14,  0xfe,  0x24,  0x12,  0xfe,  0x14,  0x56,
14090   0xfe,  0xd6,  0xf0,  0xfe,  0x52,  0x1c,  0x1c,  0x0d,  0x02,  0xfe,  0x9c,  0xe7,  0x0d,  0x19,  0xfe,  0x15,
14091   0x00,  0x40,  0x8d,  0x30,  0x01,  0xf4,  0x1c,  0x07,  0x02,  0x51,  0xfe,  0x06,  0x83,  0xfe,  0x18,  0x80,
14092   0x61,  0x28,  0x44,  0x15,  0x56,  0x01,  0x85,  0x1c,  0x07,  0x02,  0xfe,  0x38,  0x90,  0xfe,  0xba,  0x90,
14093   0x91,  0xde,  0x7e,  0xdf,  0xfe,  0x48,  0x55,  0x31,  0xfe,  0xc9,  0x55,  0x02,  0x21,  0xb9,  0x88,  0x20,
14094   0xb9,  0x02,  0x0a,  0xba,  0x01,  0x18,  0xfe,  0x41,  0x48,  0x0a,  0x57,  0x01,  0x18,  0xfe,  0x49,  0x44,
14095   0x1b,  0xfe,  0x1e,  0x1d,  0x88,  0x89,  0x02,  0x0a,  0x5a,  0x01,  0x18,  0x09,  0x1a,  0xa4,  0x0a,  0x67,
14096   0x01,  0xa3,  0x0a,  0x57,  0x01,  0x18,  0x88,  0x89,  0x02,  0xfe,  0x4e,  0xe4,  0x1d,  0x7b,  0xfe,  0x52,
14097   0x1d,  0x03,  0xfe,  0x90,  0x00,  0xfe,  0x3a,  0x45,  0xfe,  0x2c,  0x10,  0xfe,  0x4e,  0xe4,  0xdd,  0x7b,
14098   0xfe,  0x64,  0x1d,  0x03,  0xfe,  0x92,  0x00,  0xd1,  0x12,  0xfe,  0x1a,  0x10,  0xfe,  0x4e,  0xe4,  0xfe,
14099   0x0b,  0x00,  0x7b,  0xfe,  0x76,  0x1d,  0x03,  0xfe,  0x94,  0x00,  0xd1,  0x24,  0xfe,  0x08,  0x10,  0x03,
14100   0xfe,  0x96,  0x00,  0xd1,  0x63,  0xfe,  0x4e,  0x45,  0x83,  0xca,  0xff,  0x04,  0x68,  0x54,  0xfe,  0xf1,
14101   0x10,  0x23,  0x49,  0xfe,  0x08,  0x1c,  0xfe,  0x67,  0x19,  0xfe,  0x0a,  0x1c,  0xfe,  0x1a,  0xf4,  0xfe,
14102   0x00,  0x04,  0x83,  0xb2,  0x1d,  0x48,  0xfe,  0xaa,  0x1d,  0x13,  0x1d,  0x02,  0x09,  0x92,  0xfe,  0x5a,
14103   0xf0,  0xfe,  0xba,  0x1d,  0x2e,  0x93,  0xfe,  0x34,  0x10,  0x09,  0x12,  0xfe,  0x5a,  0xf0,  0xfe,  0xc8,
14104   0x1d,  0x2e,  0xb4,  0xfe,  0x26,  0x10,  0x09,  0x1d,  0x36,  0x2e,  0x63,  0xfe,  0x1a,  0x10,  0x09,  0x0d,
14105   0x36,  0x2e,  0x94,  0xf2,  0x09,  0x07,  0x36,  0x2e,  0x95,  0xa1,  0xc8,  0x02,  0x1f,  0x93,  0x01,  0x42,
14106   0xfe,  0x04,  0xfe,  0x99,  0x03,  0x9c,  0x8b,  0x02,  0x2a,  0xfe,  0x1c,  0x1e,  0xfe,  0x14,  0xf0,  0x08,
14107   0x2f,  0xfe,  0x0c,  0x1e,  0x2a,  0xfe,  0x1c,  0x1e,  0x8f,  0xfe,  0x1c,  0x1e,  0xfe,  0x82,  0xf0,  0xfe,
14108   0x10,  0x1e,  0x02,  0x0f,  0x3f,  0x04,  0xfe,  0x80,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x18,
14109   0x80,  0x04,  0xfe,  0x98,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x02,  0x80,  0x04,  0xfe,  0x82,
14110   0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x80,  0x04,  0xfe,  0x86,  0x83,  0x33,  0x0b,  0x0e,
14111   0x02,  0x0f,  0xfe,  0x1b,  0x80,  0x04,  0xfe,  0x9b,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x04,
14112   0x80,  0x04,  0xfe,  0x84,  0x83,  0x33,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x80,  0x80,  0x04,  0xfe,  0x80,
14113   0x83,  0xfe,  0xc9,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x19,  0x81,  0x04,  0xfe,  0x99,  0x83,  0xfe,
14114   0xca,  0x47,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x06,  0x83,  0x04,  0xfe,  0x86,  0x83,  0xfe,  0xce,  0x47,
14115   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x2c,  0x90,  0x04,  0xfe,  0xac,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14116   0xfe,  0xae,  0x90,  0x04,  0xfe,  0xae,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x08,  0x90,  0x04,
14117   0xfe,  0x88,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x8a,  0x90,  0x04,  0xfe,  0x8a,  0x93,  0x79,
14118   0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x0c,  0x90,  0x04,  0xfe,  0x8c,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x0f,
14119   0xfe,  0x8e,  0x90,  0x04,  0xfe,  0x8e,  0x93,  0x79,  0x0b,  0x0e,  0x02,  0x0f,  0xfe,  0x3c,  0x90,  0x04,
14120   0xfe,  0xbc,  0x93,  0x3a,  0x0b,  0x0e,  0x02,  0x8b,  0x0f,  0xfe,  0x03,  0x80,  0x04,  0xfe,  0x83,  0x83,
14121   0x33,  0x0b,  0x77,  0x0e,  0xa8,  0x02,  0xff,  0x66,  0x00,  0x00,
14122 };
14123
14124 STATIC unsigned short _adv_asc38C1600_size =
14125         sizeof(_adv_asc38C1600_buf); /* 0x1673 */
14126 STATIC ADV_DCNT _adv_asc38C1600_chksum =
14127         0x0604EF77UL; /* Expanded little-endian checksum. */
14128
14129 /* a_init.c */
14130 /*
14131  * EEPROM Configuration.
14132  *
14133  * All drivers should use this structure to set the default EEPROM
14134  * configuration. The BIOS now uses this structure when it is built.
14135  * Additional structure information can be found in a_condor.h where
14136  * the structure is defined.
14137  *
14138  * The *_Field_IsChar structs are needed to correct for endianness.
14139  * These values are read from the board 16 bits at a time directly
14140  * into the structs. Because some fields are char, the values will be
14141  * in the wrong order. The *_Field_IsChar tells when to flip the
14142  * bytes. Data read and written to PCI memory is automatically swapped
14143  * on big-endian platforms so char fields read as words are actually being
14144  * unswapped on big-endian platforms.
14145  */
14146 STATIC ADVEEP_3550_CONFIG
14147 Default_3550_EEPROM_Config __initdata = {
14148     ADV_EEPROM_BIOS_ENABLE,     /* cfg_lsw */
14149     0x0000,                     /* cfg_msw */
14150     0xFFFF,                     /* disc_enable */
14151     0xFFFF,                     /* wdtr_able */
14152     0xFFFF,                     /* sdtr_able */
14153     0xFFFF,                     /* start_motor */
14154     0xFFFF,                     /* tagqng_able */
14155     0xFFFF,                     /* bios_scan */
14156     0,                          /* scam_tolerant */
14157     7,                          /* adapter_scsi_id */
14158     0,                          /* bios_boot_delay */
14159     3,                          /* scsi_reset_delay */
14160     0,                          /* bios_id_lun */
14161     0,                          /* termination */
14162     0,                          /* reserved1 */
14163     0xFFE7,                     /* bios_ctrl */
14164     0xFFFF,                     /* ultra_able */
14165     0,                          /* reserved2 */
14166     ASC_DEF_MAX_HOST_QNG,       /* max_host_qng */
14167     ASC_DEF_MAX_DVC_QNG,        /* max_dvc_qng */
14168     0,                          /* dvc_cntl */
14169     0,                          /* bug_fix */
14170     0,                          /* serial_number_word1 */
14171     0,                          /* serial_number_word2 */
14172     0,                          /* serial_number_word3 */
14173     0,                          /* check_sum */
14174     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* oem_name[16] */
14175     0,                          /* dvc_err_code */
14176     0,                          /* adv_err_code */
14177     0,                          /* adv_err_addr */
14178     0,                          /* saved_dvc_err_code */
14179     0,                          /* saved_adv_err_code */
14180     0,                          /* saved_adv_err_addr */
14181     0                           /* num_of_err */
14182 };
14183
14184 STATIC ADVEEP_3550_CONFIG
14185 ADVEEP_3550_Config_Field_IsChar __initdata = {
14186     0,                          /* cfg_lsw */
14187     0,                          /* cfg_msw */
14188     0,                          /* -disc_enable */
14189     0,                          /* wdtr_able */
14190     0,                          /* sdtr_able */
14191     0,                          /* start_motor */
14192     0,                          /* tagqng_able */
14193     0,                          /* bios_scan */
14194     0,                          /* scam_tolerant */
14195     1,                          /* adapter_scsi_id */
14196     1,                          /* bios_boot_delay */
14197     1,                          /* scsi_reset_delay */
14198     1,                          /* bios_id_lun */
14199     1,                          /* termination */
14200     1,                          /* reserved1 */
14201     0,                          /* bios_ctrl */
14202     0,                          /* ultra_able */
14203     0,                          /* reserved2 */
14204     1,                          /* max_host_qng */
14205     1,                          /* max_dvc_qng */
14206     0,                          /* dvc_cntl */
14207     0,                          /* bug_fix */
14208     0,                          /* serial_number_word1 */
14209     0,                          /* serial_number_word2 */
14210     0,                          /* serial_number_word3 */
14211     0,                          /* check_sum */
14212     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* oem_name[16] */
14213     0,                          /* dvc_err_code */
14214     0,                          /* adv_err_code */
14215     0,                          /* adv_err_addr */
14216     0,                          /* saved_dvc_err_code */
14217     0,                          /* saved_adv_err_code */
14218     0,                          /* saved_adv_err_addr */
14219     0                           /* num_of_err */
14220 };
14221
14222 STATIC ADVEEP_38C0800_CONFIG
14223 Default_38C0800_EEPROM_Config __initdata = {
14224     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14225     0x0000,                     /* 01 cfg_msw */
14226     0xFFFF,                     /* 02 disc_enable */
14227     0xFFFF,                     /* 03 wdtr_able */
14228     0x4444,                     /* 04 sdtr_speed1 */
14229     0xFFFF,                     /* 05 start_motor */
14230     0xFFFF,                     /* 06 tagqng_able */
14231     0xFFFF,                     /* 07 bios_scan */
14232     0,                          /* 08 scam_tolerant */
14233     7,                          /* 09 adapter_scsi_id */
14234     0,                          /*    bios_boot_delay */
14235     3,                          /* 10 scsi_reset_delay */
14236     0,                          /*    bios_id_lun */
14237     0,                          /* 11 termination_se */
14238     0,                          /*    termination_lvd */
14239     0xFFE7,                     /* 12 bios_ctrl */
14240     0x4444,                     /* 13 sdtr_speed2 */
14241     0x4444,                     /* 14 sdtr_speed3 */
14242     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14243     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14244     0,                          /* 16 dvc_cntl */
14245     0x4444,                     /* 17 sdtr_speed4 */
14246     0,                          /* 18 serial_number_word1 */
14247     0,                          /* 19 serial_number_word2 */
14248     0,                          /* 20 serial_number_word3 */
14249     0,                          /* 21 check_sum */
14250     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14251     0,                          /* 30 dvc_err_code */
14252     0,                          /* 31 adv_err_code */
14253     0,                          /* 32 adv_err_addr */
14254     0,                          /* 33 saved_dvc_err_code */
14255     0,                          /* 34 saved_adv_err_code */
14256     0,                          /* 35 saved_adv_err_addr */
14257     0,                          /* 36 reserved */
14258     0,                          /* 37 reserved */
14259     0,                          /* 38 reserved */
14260     0,                          /* 39 reserved */
14261     0,                          /* 40 reserved */
14262     0,                          /* 41 reserved */
14263     0,                          /* 42 reserved */
14264     0,                          /* 43 reserved */
14265     0,                          /* 44 reserved */
14266     0,                          /* 45 reserved */
14267     0,                          /* 46 reserved */
14268     0,                          /* 47 reserved */
14269     0,                          /* 48 reserved */
14270     0,                          /* 49 reserved */
14271     0,                          /* 50 reserved */
14272     0,                          /* 51 reserved */
14273     0,                          /* 52 reserved */
14274     0,                          /* 53 reserved */
14275     0,                          /* 54 reserved */
14276     0,                          /* 55 reserved */
14277     0,                          /* 56 cisptr_lsw */
14278     0,                          /* 57 cisprt_msw */
14279     ADV_PCI_VENDOR_ID,          /* 58 subsysvid */
14280     ADV_PCI_DEVID_38C0800_REV1, /* 59 subsysid */
14281     0,                          /* 60 reserved */
14282     0,                          /* 61 reserved */
14283     0,                          /* 62 reserved */
14284     0                           /* 63 reserved */
14285 };
14286
14287 STATIC ADVEEP_38C0800_CONFIG
14288 ADVEEP_38C0800_Config_Field_IsChar __initdata = {
14289     0,                          /* 00 cfg_lsw */
14290     0,                          /* 01 cfg_msw */
14291     0,                          /* 02 disc_enable */
14292     0,                          /* 03 wdtr_able */
14293     0,                          /* 04 sdtr_speed1 */
14294     0,                          /* 05 start_motor */
14295     0,                          /* 06 tagqng_able */
14296     0,                          /* 07 bios_scan */
14297     0,                          /* 08 scam_tolerant */
14298     1,                          /* 09 adapter_scsi_id */
14299     1,                          /*    bios_boot_delay */
14300     1,                          /* 10 scsi_reset_delay */
14301     1,                          /*    bios_id_lun */
14302     1,                          /* 11 termination_se */
14303     1,                          /*    termination_lvd */
14304     0,                          /* 12 bios_ctrl */
14305     0,                          /* 13 sdtr_speed2 */
14306     0,                          /* 14 sdtr_speed3 */
14307     1,                          /* 15 max_host_qng */
14308     1,                          /*    max_dvc_qng */
14309     0,                          /* 16 dvc_cntl */
14310     0,                          /* 17 sdtr_speed4 */
14311     0,                          /* 18 serial_number_word1 */
14312     0,                          /* 19 serial_number_word2 */
14313     0,                          /* 20 serial_number_word3 */
14314     0,                          /* 21 check_sum */
14315     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14316     0,                          /* 30 dvc_err_code */
14317     0,                          /* 31 adv_err_code */
14318     0,                          /* 32 adv_err_addr */
14319     0,                          /* 33 saved_dvc_err_code */
14320     0,                          /* 34 saved_adv_err_code */
14321     0,                          /* 35 saved_adv_err_addr */
14322     0,                          /* 36 reserved */
14323     0,                          /* 37 reserved */
14324     0,                          /* 38 reserved */
14325     0,                          /* 39 reserved */
14326     0,                          /* 40 reserved */
14327     0,                          /* 41 reserved */
14328     0,                          /* 42 reserved */
14329     0,                          /* 43 reserved */
14330     0,                          /* 44 reserved */
14331     0,                          /* 45 reserved */
14332     0,                          /* 46 reserved */
14333     0,                          /* 47 reserved */
14334     0,                          /* 48 reserved */
14335     0,                          /* 49 reserved */
14336     0,                          /* 50 reserved */
14337     0,                          /* 51 reserved */
14338     0,                          /* 52 reserved */
14339     0,                          /* 53 reserved */
14340     0,                          /* 54 reserved */
14341     0,                          /* 55 reserved */
14342     0,                          /* 56 cisptr_lsw */
14343     0,                          /* 57 cisprt_msw */
14344     0,                          /* 58 subsysvid */
14345     0,                          /* 59 subsysid */
14346     0,                          /* 60 reserved */
14347     0,                          /* 61 reserved */
14348     0,                          /* 62 reserved */
14349     0                           /* 63 reserved */
14350 };
14351
14352 STATIC ADVEEP_38C1600_CONFIG
14353 Default_38C1600_EEPROM_Config __initdata = {
14354     ADV_EEPROM_BIOS_ENABLE,     /* 00 cfg_lsw */
14355     0x0000,                     /* 01 cfg_msw */
14356     0xFFFF,                     /* 02 disc_enable */
14357     0xFFFF,                     /* 03 wdtr_able */
14358     0x5555,                     /* 04 sdtr_speed1 */
14359     0xFFFF,                     /* 05 start_motor */
14360     0xFFFF,                     /* 06 tagqng_able */
14361     0xFFFF,                     /* 07 bios_scan */
14362     0,                          /* 08 scam_tolerant */
14363     7,                          /* 09 adapter_scsi_id */
14364     0,                          /*    bios_boot_delay */
14365     3,                          /* 10 scsi_reset_delay */
14366     0,                          /*    bios_id_lun */
14367     0,                          /* 11 termination_se */
14368     0,                          /*    termination_lvd */
14369     0xFFE7,                     /* 12 bios_ctrl */
14370     0x5555,                     /* 13 sdtr_speed2 */
14371     0x5555,                     /* 14 sdtr_speed3 */
14372     ASC_DEF_MAX_HOST_QNG,       /* 15 max_host_qng */
14373     ASC_DEF_MAX_DVC_QNG,        /*    max_dvc_qng */
14374     0,                          /* 16 dvc_cntl */
14375     0x5555,                     /* 17 sdtr_speed4 */
14376     0,                          /* 18 serial_number_word1 */
14377     0,                          /* 19 serial_number_word2 */
14378     0,                          /* 20 serial_number_word3 */
14379     0,                          /* 21 check_sum */
14380     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* 22-29 oem_name[16] */
14381     0,                          /* 30 dvc_err_code */
14382     0,                          /* 31 adv_err_code */
14383     0,                          /* 32 adv_err_addr */
14384     0,                          /* 33 saved_dvc_err_code */
14385     0,                          /* 34 saved_adv_err_code */
14386     0,                          /* 35 saved_adv_err_addr */
14387     0,                          /* 36 reserved */
14388     0,                          /* 37 reserved */
14389     0,                          /* 38 reserved */
14390     0,                          /* 39 reserved */
14391     0,                          /* 40 reserved */
14392     0,                          /* 41 reserved */
14393     0,                          /* 42 reserved */
14394     0,                          /* 43 reserved */
14395     0,                          /* 44 reserved */
14396     0,                          /* 45 reserved */
14397     0,                          /* 46 reserved */
14398     0,                          /* 47 reserved */
14399     0,                          /* 48 reserved */
14400     0,                          /* 49 reserved */
14401     0,                          /* 50 reserved */
14402     0,                          /* 51 reserved */
14403     0,                          /* 52 reserved */
14404     0,                          /* 53 reserved */
14405     0,                          /* 54 reserved */
14406     0,                          /* 55 reserved */
14407     0,                          /* 56 cisptr_lsw */
14408     0,                          /* 57 cisprt_msw */
14409     ADV_PCI_VENDOR_ID,          /* 58 subsysvid */
14410     ADV_PCI_DEVID_38C1600_REV1, /* 59 subsysid */
14411     0,                          /* 60 reserved */
14412     0,                          /* 61 reserved */
14413     0,                          /* 62 reserved */
14414     0                           /* 63 reserved */
14415 };
14416
14417 STATIC ADVEEP_38C1600_CONFIG
14418 ADVEEP_38C1600_Config_Field_IsChar __initdata = {
14419     0,                          /* 00 cfg_lsw */
14420     0,                          /* 01 cfg_msw */
14421     0,                          /* 02 disc_enable */
14422     0,                          /* 03 wdtr_able */
14423     0,                          /* 04 sdtr_speed1 */
14424     0,                          /* 05 start_motor */
14425     0,                          /* 06 tagqng_able */
14426     0,                          /* 07 bios_scan */
14427     0,                          /* 08 scam_tolerant */
14428     1,                          /* 09 adapter_scsi_id */
14429     1,                          /*    bios_boot_delay */
14430     1,                          /* 10 scsi_reset_delay */
14431     1,                          /*    bios_id_lun */
14432     1,                          /* 11 termination_se */
14433     1,                          /*    termination_lvd */
14434     0,                          /* 12 bios_ctrl */
14435     0,                          /* 13 sdtr_speed2 */
14436     0,                          /* 14 sdtr_speed3 */
14437     1,                          /* 15 max_host_qng */
14438     1,                          /*    max_dvc_qng */
14439     0,                          /* 16 dvc_cntl */
14440     0,                          /* 17 sdtr_speed4 */
14441     0,                          /* 18 serial_number_word1 */
14442     0,                          /* 19 serial_number_word2 */
14443     0,                          /* 20 serial_number_word3 */
14444     0,                          /* 21 check_sum */
14445     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }, /* 22-29 oem_name[16] */
14446     0,                          /* 30 dvc_err_code */
14447     0,                          /* 31 adv_err_code */
14448     0,                          /* 32 adv_err_addr */
14449     0,                          /* 33 saved_dvc_err_code */
14450     0,                          /* 34 saved_adv_err_code */
14451     0,                          /* 35 saved_adv_err_addr */
14452     0,                          /* 36 reserved */
14453     0,                          /* 37 reserved */
14454     0,                          /* 38 reserved */
14455     0,                          /* 39 reserved */
14456     0,                          /* 40 reserved */
14457     0,                          /* 41 reserved */
14458     0,                          /* 42 reserved */
14459     0,                          /* 43 reserved */
14460     0,                          /* 44 reserved */
14461     0,                          /* 45 reserved */
14462     0,                          /* 46 reserved */
14463     0,                          /* 47 reserved */
14464     0,                          /* 48 reserved */
14465     0,                          /* 49 reserved */
14466     0,                          /* 50 reserved */
14467     0,                          /* 51 reserved */
14468     0,                          /* 52 reserved */
14469     0,                          /* 53 reserved */
14470     0,                          /* 54 reserved */
14471     0,                          /* 55 reserved */
14472     0,                          /* 56 cisptr_lsw */
14473     0,                          /* 57 cisprt_msw */
14474     0,                          /* 58 subsysvid */
14475     0,                          /* 59 subsysid */
14476     0,                          /* 60 reserved */
14477     0,                          /* 61 reserved */
14478     0,                          /* 62 reserved */
14479     0                           /* 63 reserved */
14480 };
14481
14482 /*
14483  * Initialize the ADV_DVC_VAR structure.
14484  *
14485  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14486  *
14487  * For a non-fatal error return a warning code. If there are no warnings
14488  * then 0 is returned.
14489  */
14490 STATIC int __init
14491 AdvInitGetConfig(ADV_DVC_VAR *asc_dvc)
14492 {
14493     ushort      warn_code;
14494     AdvPortAddr iop_base;
14495     uchar       pci_cmd_reg;
14496     int         status;
14497
14498     warn_code = 0;
14499     asc_dvc->err_code = 0;
14500     iop_base = asc_dvc->iop_base;
14501
14502     /*
14503      * PCI Command Register
14504      *
14505      * Note: AscPCICmdRegBits_BusMastering definition (0x0007) includes
14506      * I/O Space Control, Memory Space Control and Bus Master Control bits.
14507      */
14508
14509     if (((pci_cmd_reg = DvcAdvReadPCIConfigByte(asc_dvc,
14510                             AscPCIConfigCommandRegister))
14511          & AscPCICmdRegBits_BusMastering)
14512         != AscPCICmdRegBits_BusMastering)
14513     {
14514         pci_cmd_reg |= AscPCICmdRegBits_BusMastering;
14515
14516         DvcAdvWritePCIConfigByte(asc_dvc,
14517                 AscPCIConfigCommandRegister, pci_cmd_reg);
14518
14519         if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister))
14520              & AscPCICmdRegBits_BusMastering)
14521             != AscPCICmdRegBits_BusMastering)
14522         {
14523             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14524         }
14525     }
14526
14527     /*
14528      * PCI Latency Timer
14529      *
14530      * If the "latency timer" register is 0x20 or above, then we don't need
14531      * to change it.  Otherwise, set it to 0x20 (i.e. set it to 0x20 if it
14532      * comes up less than 0x20).
14533      */
14534     if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20) {
14535         DvcAdvWritePCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer, 0x20);
14536         if (DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigLatencyTimer) < 0x20)
14537         {
14538             warn_code |= ASC_WARN_SET_PCI_CONFIG_SPACE;
14539         }
14540     }
14541
14542     /*
14543      * Save the state of the PCI Configuration Command Register
14544      * "Parity Error Response Control" Bit. If the bit is clear (0),
14545      * in AdvInitAsc3550/38C0800Driver() tell the microcode to ignore
14546      * DMA parity errors.
14547      */
14548     asc_dvc->cfg->control_flag = 0;
14549     if (((DvcAdvReadPCIConfigByte(asc_dvc, AscPCIConfigCommandRegister)
14550          & AscPCICmdRegBits_ParErrRespCtrl)) == 0)
14551     {
14552         asc_dvc->cfg->control_flag |= CONTROL_FLAG_IGNORE_PERR;
14553     }
14554
14555     asc_dvc->cfg->lib_version = (ADV_LIB_VERSION_MAJOR << 8) |
14556       ADV_LIB_VERSION_MINOR;
14557     asc_dvc->cfg->chip_version =
14558       AdvGetChipVersion(iop_base, asc_dvc->bus_type);
14559
14560     ASC_DBG2(1, "AdvInitGetConfig: iopb_chip_id_1: 0x%x 0x%x\n",
14561         (ushort) AdvReadByteRegister(iop_base, IOPB_CHIP_ID_1),
14562         (ushort) ADV_CHIP_ID_BYTE);
14563
14564     ASC_DBG2(1, "AdvInitGetConfig: iopw_chip_id_0: 0x%x 0x%x\n",
14565         (ushort) AdvReadWordRegister(iop_base, IOPW_CHIP_ID_0),
14566         (ushort) ADV_CHIP_ID_WORD);
14567
14568     /*
14569      * Reset the chip to start and allow register writes.
14570      */
14571     if (AdvFindSignature(iop_base) == 0)
14572     {
14573         asc_dvc->err_code = ASC_IERR_BAD_SIGNATURE;
14574         return ADV_ERROR;
14575     }
14576     else {
14577         /*
14578          * The caller must set 'chip_type' to a valid setting.
14579          */
14580         if (asc_dvc->chip_type != ADV_CHIP_ASC3550 &&
14581             asc_dvc->chip_type != ADV_CHIP_ASC38C0800 &&
14582             asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
14583         {
14584             asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14585             return ADV_ERROR;
14586         }
14587
14588         /*
14589          * Reset Chip.
14590          */
14591         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14592             ADV_CTRL_REG_CMD_RESET);
14593         DvcSleepMilliSecond(100);
14594         AdvWriteWordRegister(iop_base, IOPW_CTRL_REG,
14595             ADV_CTRL_REG_CMD_WR_IO_REG);
14596
14597         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
14598         {
14599             if ((status = AdvInitFrom38C1600EEP(asc_dvc)) == ADV_ERROR)
14600             {
14601                 return ADV_ERROR;
14602             }
14603         } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
14604         {
14605             if ((status = AdvInitFrom38C0800EEP(asc_dvc)) == ADV_ERROR)
14606             {
14607                 return ADV_ERROR;
14608             }
14609         } else
14610         {
14611             if ((status = AdvInitFrom3550EEP(asc_dvc)) == ADV_ERROR)
14612             {
14613                 return ADV_ERROR;
14614             }
14615         }
14616         warn_code |= status;
14617     }
14618
14619     return warn_code;
14620 }
14621
14622 /*
14623  * Initialize the ASC-3550.
14624  *
14625  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
14626  *
14627  * For a non-fatal error return a warning code. If there are no warnings
14628  * then 0 is returned.
14629  *
14630  * Needed after initialization for error recovery.
14631  */
14632 STATIC int
14633 AdvInitAsc3550Driver(ADV_DVC_VAR *asc_dvc)
14634 {
14635     AdvPortAddr iop_base;
14636     ushort      warn_code;
14637     ADV_DCNT    sum;
14638     int         begin_addr;
14639     int         end_addr;
14640     ushort      code_sum;
14641     int         word;
14642     int         j;
14643     int         adv_asc3550_expanded_size;
14644     ADV_CARR_T  *carrp;
14645     ADV_DCNT    contig_len;
14646     ADV_SDCNT   buf_size;
14647     ADV_PADDR   carr_paddr;
14648     int         i;
14649     ushort      scsi_cfg1;
14650     uchar       tid;
14651     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
14652     ushort      wdtr_able = 0, sdtr_able, tagqng_able;
14653     uchar       max_cmd[ADV_MAX_TID + 1];
14654
14655     /* If there is already an error, don't continue. */
14656     if (asc_dvc->err_code != 0)
14657     {
14658         return ADV_ERROR;
14659     }
14660
14661     /*
14662      * The caller must set 'chip_type' to ADV_CHIP_ASC3550.
14663      */
14664     if (asc_dvc->chip_type != ADV_CHIP_ASC3550)
14665     {
14666         asc_dvc->err_code |= ASC_IERR_BAD_CHIPTYPE;
14667         return ADV_ERROR;
14668     }
14669
14670     warn_code = 0;
14671     iop_base = asc_dvc->iop_base;
14672
14673     /*
14674      * Save the RISC memory BIOS region before writing the microcode.
14675      * The BIOS may already be loaded and using its RISC LRAM region
14676      * so its region must be saved and restored.
14677      *
14678      * Note: This code makes the assumption, which is currently true,
14679      * that a chip reset does not clear RISC LRAM.
14680      */
14681     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14682     {
14683         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14684     }
14685
14686     /*
14687      * Save current per TID negotiated values.
14688      */
14689     if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
14690     {
14691         ushort  bios_version, major, minor;
14692
14693         bios_version = bios_mem[(ASC_MC_BIOS_VERSION - ASC_MC_BIOSMEM)/2];
14694         major = (bios_version  >> 12) & 0xF;
14695         minor = (bios_version  >> 8) & 0xF;
14696         if (major < 3 || (major == 3 && minor == 1))
14697         {
14698             /* BIOS 3.1 and earlier location of 'wdtr_able' variable. */
14699             AdvReadWordLram(iop_base, 0x120, wdtr_able);
14700         } else
14701         {
14702             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
14703         }
14704     }
14705     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
14706     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
14707     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14708     {
14709         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
14710             max_cmd[tid]);
14711     }
14712
14713     /*
14714      * Load the Microcode
14715      *
14716      * Write the microcode image to RISC memory starting at address 0.
14717      */
14718     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14719     /* Assume the following compressed format of the microcode buffer:
14720      *
14721      *  254 word (508 byte) table indexed by byte code followed
14722      *  by the following byte codes:
14723      *
14724      *    1-Byte Code:
14725      *      00: Emit word 0 in table.
14726      *      01: Emit word 1 in table.
14727      *      .
14728      *      FD: Emit word 253 in table.
14729      *
14730      *    Multi-Byte Code:
14731      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
14732      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
14733      */
14734     word = 0;
14735     for (i = 253 * 2; i < _adv_asc3550_size; i++)
14736     {
14737         if (_adv_asc3550_buf[i] == 0xff)
14738         {
14739             for (j = 0; j < _adv_asc3550_buf[i + 1]; j++)
14740             {
14741                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
14742                     _adv_asc3550_buf[i + 3] << 8) |
14743                 _adv_asc3550_buf[i + 2]));
14744                 word++;
14745             }
14746             i += 3;
14747         } else if (_adv_asc3550_buf[i] == 0xfe)
14748         {
14749             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14750                 _adv_asc3550_buf[i + 2] << 8) |
14751                 _adv_asc3550_buf[i + 1]));
14752             i += 2;
14753             word++;
14754         } else
14755         {
14756             AdvWriteWordAutoIncLram(iop_base, (((ushort)
14757                 _adv_asc3550_buf[(_adv_asc3550_buf[i] * 2) + 1] << 8) |
14758                 _adv_asc3550_buf[_adv_asc3550_buf[i] * 2]));
14759             word++;
14760         }
14761     }
14762
14763     /*
14764      * Set 'word' for later use to clear the rest of memory and save
14765      * the expanded mcode size.
14766      */
14767     word *= 2;
14768     adv_asc3550_expanded_size = word;
14769
14770     /*
14771      * Clear the rest of ASC-3550 Internal RAM (8KB).
14772      */
14773     for (; word < ADV_3550_MEMSIZE; word += 2)
14774     {
14775         AdvWriteWordAutoIncLram(iop_base, 0);
14776     }
14777
14778     /*
14779      * Verify the microcode checksum.
14780      */
14781     sum = 0;
14782     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
14783
14784     for (word = 0; word < adv_asc3550_expanded_size; word += 2)
14785     {
14786         sum += AdvReadWordAutoIncLram(iop_base);
14787     }
14788
14789     if (sum != _adv_asc3550_chksum)
14790     {
14791         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
14792         return ADV_ERROR;
14793     }
14794
14795     /*
14796      * Restore the RISC memory BIOS region.
14797      */
14798     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
14799     {
14800         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
14801     }
14802
14803     /*
14804      * Calculate and write the microcode code checksum to the microcode
14805      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
14806      */
14807     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
14808     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
14809     code_sum = 0;
14810     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
14811     for (word = begin_addr; word < end_addr; word += 2)
14812     {
14813         code_sum += AdvReadWordAutoIncLram(iop_base);
14814     }
14815     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
14816
14817     /*
14818      * Read and save microcode version and date.
14819      */
14820     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
14821     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
14822
14823     /*
14824      * Set the chip type to indicate the ASC3550.
14825      */
14826     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC3550);
14827
14828     /*
14829      * If the PCI Configuration Command Register "Parity Error Response
14830      * Control" Bit was clear (0), then set the microcode variable
14831      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
14832      * to ignore DMA parity errors.
14833      */
14834     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
14835     {
14836         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14837         word |= CONTROL_FLAG_IGNORE_PERR;
14838         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
14839     }
14840
14841     /*
14842      * For ASC-3550, setting the START_CTL_EMFU [3:2] bits sets a FIFO
14843      * threshold of 128 bytes. This register is only accessible to the host.
14844      */
14845     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
14846         START_CTL_EMFU | READ_CMD_MRM);
14847
14848     /*
14849      * Microcode operating variables for WDTR, SDTR, and command tag
14850      * queuing will be set in AdvInquiryHandling() based on what a
14851      * device reports it is capable of in Inquiry byte 7.
14852      *
14853      * If SCSI Bus Resets have been disabled, then directly set
14854      * SDTR and WDTR from the EEPROM configuration. This will allow
14855      * the BIOS and warm boot to work without a SCSI bus hang on
14856      * the Inquiry caused by host and target mismatched DTR values.
14857      * Without the SCSI Bus Reset, before an Inquiry a device can't
14858      * be assumed to be in Asynchronous, Narrow mode.
14859      */
14860     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
14861     {
14862         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
14863         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
14864     }
14865
14866     /*
14867      * Set microcode operating variables for SDTR_SPEED1, SDTR_SPEED2,
14868      * SDTR_SPEED3, and SDTR_SPEED4 based on the ULTRA EEPROM per TID
14869      * bitmask. These values determine the maximum SDTR speed negotiated
14870      * with a device.
14871      *
14872      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
14873      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
14874      * without determining here whether the device supports SDTR.
14875      *
14876      * 4-bit speed  SDTR speed name
14877      * ===========  ===============
14878      * 0000b (0x0)  SDTR disabled
14879      * 0001b (0x1)  5 Mhz
14880      * 0010b (0x2)  10 Mhz
14881      * 0011b (0x3)  20 Mhz (Ultra)
14882      * 0100b (0x4)  40 Mhz (LVD/Ultra2)
14883      * 0101b (0x5)  80 Mhz (LVD2/Ultra3)
14884      * 0110b (0x6)  Undefined
14885      * .
14886      * 1111b (0xF)  Undefined
14887      */
14888     word = 0;
14889     for (tid = 0; tid <= ADV_MAX_TID; tid++)
14890     {
14891         if (ADV_TID_TO_TIDMASK(tid) & asc_dvc->ultra_able)
14892         {
14893             /* Set Ultra speed for TID 'tid'. */
14894             word |= (0x3 << (4 * (tid % 4)));
14895         } else
14896         {
14897             /* Set Fast speed for TID 'tid'. */
14898             word |= (0x2 << (4 * (tid % 4)));
14899         }
14900         if (tid == 3) /* Check if done with sdtr_speed1. */
14901         {
14902             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, word);
14903             word = 0;
14904         } else if (tid == 7) /* Check if done with sdtr_speed2. */
14905         {
14906             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, word);
14907             word = 0;
14908         } else if (tid == 11) /* Check if done with sdtr_speed3. */
14909         {
14910             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, word);
14911             word = 0;
14912         } else if (tid == 15) /* Check if done with sdtr_speed4. */
14913         {
14914             AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, word);
14915             /* End of loop. */
14916         }
14917     }
14918
14919     /*
14920      * Set microcode operating variable for the disconnect per TID bitmask.
14921      */
14922     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
14923
14924     /*
14925      * Set SCSI_CFG0 Microcode Default Value.
14926      *
14927      * The microcode will set the SCSI_CFG0 register using this value
14928      * after it is started below.
14929      */
14930     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
14931         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
14932         asc_dvc->chip_scsi_id);
14933
14934     /*
14935      * Determine SCSI_CFG1 Microcode Default Value.
14936      *
14937      * The microcode will set the SCSI_CFG1 register using this value
14938      * after it is started below.
14939      */
14940
14941     /* Read current SCSI_CFG1 Register value. */
14942     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
14943
14944     /*
14945      * If all three connectors are in use, return an error.
14946      */
14947     if ((scsi_cfg1 & CABLE_ILLEGAL_A) == 0 ||
14948         (scsi_cfg1 & CABLE_ILLEGAL_B) == 0)
14949     {
14950             asc_dvc->err_code |= ASC_IERR_ILLEGAL_CONNECTION;
14951             return ADV_ERROR;
14952     }
14953
14954     /*
14955      * If the internal narrow cable is reversed all of the SCSI_CTRL
14956      * register signals will be set. Check for and return an error if
14957      * this condition is found.
14958      */
14959     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
14960     {
14961         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
14962         return ADV_ERROR;
14963     }
14964
14965     /*
14966      * If this is a differential board and a single-ended device
14967      * is attached to one of the connectors, return an error.
14968      */
14969     if ((scsi_cfg1 & DIFF_MODE) && (scsi_cfg1 & DIFF_SENSE) == 0)
14970     {
14971         asc_dvc->err_code |= ASC_IERR_SINGLE_END_DEVICE;
14972         return ADV_ERROR;
14973     }
14974
14975     /*
14976      * If automatic termination control is enabled, then set the
14977      * termination value based on a table listed in a_condor.h.
14978      *
14979      * If manual termination was specified with an EEPROM setting
14980      * then 'termination' was set-up in AdvInitFrom3550EEPROM() and
14981      * is ready to be 'ored' into SCSI_CFG1.
14982      */
14983     if (asc_dvc->cfg->termination == 0)
14984     {
14985         /*
14986          * The software always controls termination by setting TERM_CTL_SEL.
14987          * If TERM_CTL_SEL were set to 0, the hardware would set termination.
14988          */
14989         asc_dvc->cfg->termination |= TERM_CTL_SEL;
14990
14991         switch(scsi_cfg1 & CABLE_DETECT)
14992         {
14993             /* TERM_CTL_H: on, TERM_CTL_L: on */
14994             case 0x3: case 0x7: case 0xB: case 0xD: case 0xE: case 0xF:
14995                 asc_dvc->cfg->termination |= (TERM_CTL_H | TERM_CTL_L);
14996                 break;
14997
14998             /* TERM_CTL_H: on, TERM_CTL_L: off */
14999             case 0x1: case 0x5: case 0x9: case 0xA: case 0xC:
15000                 asc_dvc->cfg->termination |= TERM_CTL_H;
15001                 break;
15002
15003             /* TERM_CTL_H: off, TERM_CTL_L: off */
15004             case 0x2: case 0x6:
15005                 break;
15006         }
15007     }
15008
15009     /*
15010      * Clear any set TERM_CTL_H and TERM_CTL_L bits.
15011      */
15012     scsi_cfg1 &= ~TERM_CTL;
15013
15014     /*
15015      * Invert the TERM_CTL_H and TERM_CTL_L bits and then
15016      * set 'scsi_cfg1'. The TERM_POL bit does not need to be
15017      * referenced, because the hardware internally inverts
15018      * the Termination High and Low bits if TERM_POL is set.
15019      */
15020     scsi_cfg1 |= (TERM_CTL_SEL | (~asc_dvc->cfg->termination & TERM_CTL));
15021
15022     /*
15023      * Set SCSI_CFG1 Microcode Default Value
15024      *
15025      * Set filter value and possibly modified termination control
15026      * bits in the Microcode SCSI_CFG1 Register Value.
15027      *
15028      * The microcode will set the SCSI_CFG1 register using this value
15029      * after it is started below.
15030      */
15031     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1,
15032         FLTR_DISABLE | scsi_cfg1);
15033
15034     /*
15035      * Set MEM_CFG Microcode Default Value
15036      *
15037      * The microcode will set the MEM_CFG register using this value
15038      * after it is started below.
15039      *
15040      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15041      * are defined.
15042      *
15043      * ASC-3550 has 8KB internal memory.
15044      */
15045     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15046         BIOS_EN | RAM_SZ_8KB);
15047
15048     /*
15049      * Set SEL_MASK Microcode Default Value
15050      *
15051      * The microcode will set the SEL_MASK register using this value
15052      * after it is started below.
15053      */
15054     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15055         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15056
15057     /*
15058      * Build carrier freelist.
15059      *
15060      * Driver must have already allocated memory and set 'carrier_buf'.
15061      */
15062     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15063
15064     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15065     asc_dvc->carr_freelist = NULL;
15066     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15067     {
15068         buf_size = ADV_CARRIER_BUFSIZE;
15069     } else
15070     {
15071         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15072     }
15073
15074     do {
15075         /*
15076          * Get physical address of the carrier 'carrp'.
15077          */
15078         contig_len = sizeof(ADV_CARR_T);
15079         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15080             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15081
15082         buf_size -= sizeof(ADV_CARR_T);
15083
15084         /*
15085          * If the current carrier is not physically contiguous, then
15086          * maybe there was a page crossing. Try the next carrier aligned
15087          * start address.
15088          */
15089         if (contig_len < sizeof(ADV_CARR_T))
15090         {
15091             carrp++;
15092             continue;
15093         }
15094
15095         carrp->carr_pa = carr_paddr;
15096         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15097
15098         /*
15099          * Insert the carrier at the beginning of the freelist.
15100          */
15101         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15102         asc_dvc->carr_freelist = carrp;
15103
15104         carrp++;
15105     }
15106     while (buf_size > 0);
15107
15108     /*
15109      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15110      */
15111
15112     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15113     {
15114         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15115         return ADV_ERROR;
15116     }
15117     asc_dvc->carr_freelist = (ADV_CARR_T *)
15118         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15119
15120     /*
15121      * The first command issued will be placed in the stopper carrier.
15122      */
15123     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15124
15125     /*
15126      * Set RISC ICQ physical address start value.
15127      */
15128     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15129
15130     /*
15131      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15132      */
15133     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15134     {
15135         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15136         return ADV_ERROR;
15137     }
15138     asc_dvc->carr_freelist = (ADV_CARR_T *)
15139          ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15140
15141     /*
15142      * The first command completed by the RISC will be placed in
15143      * the stopper.
15144      *
15145      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15146      * completed the RISC will set the ASC_RQ_STOPPER bit.
15147      */
15148     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15149
15150     /*
15151      * Set RISC IRQ physical address start value.
15152      */
15153     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15154     asc_dvc->carr_pending_cnt = 0;
15155
15156     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15157         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15158
15159     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15160     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15161
15162     /* finally, finally, gentlemen, start your engine */
15163     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15164
15165     /*
15166      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15167      * Resets should be performed. The RISC has to be running
15168      * to issue a SCSI Bus Reset.
15169      */
15170     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15171     {
15172         /*
15173          * If the BIOS Signature is present in memory, restore the
15174          * BIOS Handshake Configuration Table and do not perform
15175          * a SCSI Bus Reset.
15176          */
15177         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15178         {
15179             /*
15180              * Restore per TID negotiated values.
15181              */
15182             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15183             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15184             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15185             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15186             {
15187                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15188                     max_cmd[tid]);
15189             }
15190         } else
15191         {
15192             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15193             {
15194                 warn_code = ASC_WARN_BUSRESET_ERROR;
15195             }
15196         }
15197     }
15198
15199     return warn_code;
15200 }
15201
15202 /*
15203  * Initialize the ASC-38C0800.
15204  *
15205  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
15206  *
15207  * For a non-fatal error return a warning code. If there are no warnings
15208  * then 0 is returned.
15209  *
15210  * Needed after initialization for error recovery.
15211  */
15212 STATIC int
15213 AdvInitAsc38C0800Driver(ADV_DVC_VAR *asc_dvc)
15214 {
15215     AdvPortAddr iop_base;
15216     ushort      warn_code;
15217     ADV_DCNT    sum;
15218     int         begin_addr;
15219     int         end_addr;
15220     ushort      code_sum;
15221     int         word;
15222     int         j;
15223     int         adv_asc38C0800_expanded_size;
15224     ADV_CARR_T  *carrp;
15225     ADV_DCNT    contig_len;
15226     ADV_SDCNT   buf_size;
15227     ADV_PADDR   carr_paddr;
15228     int         i;
15229     ushort      scsi_cfg1;
15230     uchar       byte;
15231     uchar       tid;
15232     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15233     ushort      wdtr_able, sdtr_able, tagqng_able;
15234     uchar       max_cmd[ADV_MAX_TID + 1];
15235
15236     /* If there is already an error, don't continue. */
15237     if (asc_dvc->err_code != 0)
15238     {
15239         return ADV_ERROR;
15240     }
15241
15242     /*
15243      * The caller must set 'chip_type' to ADV_CHIP_ASC38C0800.
15244      */
15245     if (asc_dvc->chip_type != ADV_CHIP_ASC38C0800)
15246     {
15247         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15248         return ADV_ERROR;
15249     }
15250
15251     warn_code = 0;
15252     iop_base = asc_dvc->iop_base;
15253
15254     /*
15255      * Save the RISC memory BIOS region before writing the microcode.
15256      * The BIOS may already be loaded and using its RISC LRAM region
15257      * so its region must be saved and restored.
15258      *
15259      * Note: This code makes the assumption, which is currently true,
15260      * that a chip reset does not clear RISC LRAM.
15261      */
15262     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15263     {
15264         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15265     }
15266
15267     /*
15268      * Save current per TID negotiated values.
15269      */
15270     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15271     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15272     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15273     for (tid = 0; tid <= ADV_MAX_TID; tid++)
15274     {
15275         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15276             max_cmd[tid]);
15277     }
15278
15279     /*
15280      * RAM BIST (RAM Built-In Self Test)
15281      *
15282      * Address : I/O base + offset 0x38h register (byte).
15283      * Function: Bit 7-6(RW) : RAM mode
15284      *                          Normal Mode   : 0x00
15285      *                          Pre-test Mode : 0x40
15286      *                          RAM Test Mode : 0x80
15287      *           Bit 5       : unused
15288      *           Bit 4(RO)   : Done bit
15289      *           Bit 3-0(RO) : Status
15290      *                          Host Error    : 0x08
15291      *                          Int_RAM Error : 0x04
15292      *                          RISC Error    : 0x02
15293      *                          SCSI Error    : 0x01
15294      *                          No Error      : 0x00
15295      *
15296      * Note: RAM BIST code should be put right here, before loading the
15297      * microcode and after saving the RISC memory BIOS region.
15298      */
15299
15300     /*
15301      * LRAM Pre-test
15302      *
15303      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15304      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15305      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15306      * to NORMAL_MODE, return an error too.
15307      */
15308     for (i = 0; i < 2; i++)
15309     {
15310         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15311         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15312         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15313         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15314         {
15315             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15316             return ADV_ERROR;
15317         }
15318
15319         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15320         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15321         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15322             != NORMAL_VALUE)
15323         {
15324             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15325             return ADV_ERROR;
15326         }
15327     }
15328
15329     /*
15330      * LRAM Test - It takes about 1.5 ms to run through the test.
15331      *
15332      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15333      * If Done bit not set or Status not 0, save register byte, set the
15334      * err_code, and return an error.
15335      */
15336     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15337     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15338
15339     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15340     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15341     {
15342         /* Get here if Done bit not set or Status not 0. */
15343         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15344         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15345         return ADV_ERROR;
15346     }
15347
15348     /* We need to reset back to normal mode after LRAM test passes. */
15349     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15350
15351     /*
15352      * Load the Microcode
15353      *
15354      * Write the microcode image to RISC memory starting at address 0.
15355      *
15356      */
15357     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15358
15359     /* Assume the following compressed format of the microcode buffer:
15360      *
15361      *  254 word (508 byte) table indexed by byte code followed
15362      *  by the following byte codes:
15363      *
15364      *    1-Byte Code:
15365      *      00: Emit word 0 in table.
15366      *      01: Emit word 1 in table.
15367      *      .
15368      *      FD: Emit word 253 in table.
15369      *
15370      *    Multi-Byte Code:
15371      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
15372      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
15373      */
15374     word = 0;
15375     for (i = 253 * 2; i < _adv_asc38C0800_size; i++)
15376     {
15377         if (_adv_asc38C0800_buf[i] == 0xff)
15378         {
15379             for (j = 0; j < _adv_asc38C0800_buf[i + 1]; j++)
15380             {
15381                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
15382                     _adv_asc38C0800_buf[i + 3] << 8) |
15383                     _adv_asc38C0800_buf[i + 2]));
15384                 word++;
15385             }
15386             i += 3;
15387         } else if (_adv_asc38C0800_buf[i] == 0xfe)
15388         {
15389             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15390                 _adv_asc38C0800_buf[i + 2] << 8) |
15391                 _adv_asc38C0800_buf[i + 1]));
15392             i += 2;
15393             word++;
15394         } else
15395         {
15396             AdvWriteWordAutoIncLram(iop_base, (((ushort)
15397                 _adv_asc38C0800_buf[(_adv_asc38C0800_buf[i] * 2) + 1] << 8) |
15398                 _adv_asc38C0800_buf[_adv_asc38C0800_buf[i] * 2]));
15399             word++;
15400         }
15401     }
15402
15403     /*
15404      * Set 'word' for later use to clear the rest of memory and save
15405      * the expanded mcode size.
15406      */
15407     word *= 2;
15408     adv_asc38C0800_expanded_size = word;
15409
15410     /*
15411      * Clear the rest of ASC-38C0800 Internal RAM (16KB).
15412      */
15413     for (; word < ADV_38C0800_MEMSIZE; word += 2)
15414     {
15415         AdvWriteWordAutoIncLram(iop_base, 0);
15416     }
15417
15418     /*
15419      * Verify the microcode checksum.
15420      */
15421     sum = 0;
15422     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15423
15424     for (word = 0; word < adv_asc38C0800_expanded_size; word += 2)
15425     {
15426         sum += AdvReadWordAutoIncLram(iop_base);
15427     }
15428     ASC_DBG2(1, "AdvInitAsc38C0800Driver: word %d, i %d\n", word, i);
15429
15430     ASC_DBG2(1,
15431         "AdvInitAsc38C0800Driver: sum 0x%lx, _adv_asc38C0800_chksum 0x%lx\n",
15432         (ulong) sum, (ulong) _adv_asc38C0800_chksum);
15433
15434     if (sum != _adv_asc38C0800_chksum)
15435     {
15436         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
15437         return ADV_ERROR;
15438     }
15439
15440     /*
15441      * Restore the RISC memory BIOS region.
15442      */
15443     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15444     {
15445         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15446     }
15447
15448     /*
15449      * Calculate and write the microcode code checksum to the microcode
15450      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
15451      */
15452     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
15453     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
15454     code_sum = 0;
15455     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
15456     for (word = begin_addr; word < end_addr; word += 2)
15457     {
15458         code_sum += AdvReadWordAutoIncLram(iop_base);
15459     }
15460     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
15461
15462     /*
15463      * Read microcode version and date.
15464      */
15465     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
15466     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
15467
15468     /*
15469      * Set the chip type to indicate the ASC38C0800.
15470      */
15471     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C0800);
15472
15473     /*
15474      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
15475      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
15476      * cable detection and then we are able to read C_DET[3:0].
15477      *
15478      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
15479      * Microcode Default Value' section below.
15480      */
15481     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15482     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
15483
15484     /*
15485      * If the PCI Configuration Command Register "Parity Error Response
15486      * Control" Bit was clear (0), then set the microcode variable
15487      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
15488      * to ignore DMA parity errors.
15489      */
15490     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
15491     {
15492         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15493         word |= CONTROL_FLAG_IGNORE_PERR;
15494         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
15495     }
15496
15497     /*
15498      * For ASC-38C0800, set FIFO_THRESH_80B [6:4] bits and START_CTL_TH [3:2]
15499      * bits for the default FIFO threshold.
15500      *
15501      * Note: ASC-38C0800 FIFO threshold has been changed to 256 bytes.
15502      *
15503      * For DMA Errata #4 set the BC_THRESH_ENB bit.
15504      */
15505     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
15506         BC_THRESH_ENB | FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
15507
15508     /*
15509      * Microcode operating variables for WDTR, SDTR, and command tag
15510      * queuing will be set in AdvInquiryHandling() based on what a
15511      * device reports it is capable of in Inquiry byte 7.
15512      *
15513      * If SCSI Bus Resets have been disabled, then directly set
15514      * SDTR and WDTR from the EEPROM configuration. This will allow
15515      * the BIOS and warm boot to work without a SCSI bus hang on
15516      * the Inquiry caused by host and target mismatched DTR values.
15517      * Without the SCSI Bus Reset, before an Inquiry a device can't
15518      * be assumed to be in Asynchronous, Narrow mode.
15519      */
15520     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
15521     {
15522         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
15523         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
15524     }
15525
15526     /*
15527      * Set microcode operating variables for DISC and SDTR_SPEED1,
15528      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
15529      * configuration values.
15530      *
15531      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
15532      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
15533      * without determining here whether the device supports SDTR.
15534      */
15535     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
15536     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
15537     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
15538     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
15539     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
15540
15541     /*
15542      * Set SCSI_CFG0 Microcode Default Value.
15543      *
15544      * The microcode will set the SCSI_CFG0 register using this value
15545      * after it is started below.
15546      */
15547     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
15548         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
15549         asc_dvc->chip_scsi_id);
15550
15551     /*
15552      * Determine SCSI_CFG1 Microcode Default Value.
15553      *
15554      * The microcode will set the SCSI_CFG1 register using this value
15555      * after it is started below.
15556      */
15557
15558     /* Read current SCSI_CFG1 Register value. */
15559     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
15560
15561     /*
15562      * If the internal narrow cable is reversed all of the SCSI_CTRL
15563      * register signals will be set. Check for and return an error if
15564      * this condition is found.
15565      */
15566     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
15567     {
15568         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
15569         return ADV_ERROR;
15570     }
15571
15572     /*
15573      * All kind of combinations of devices attached to one of four connectors
15574      * are acceptable except HVD device attached. For example, LVD device can
15575      * be attached to SE connector while SE device attached to LVD connector.
15576      * If LVD device attached to SE connector, it only runs up to Ultra speed.
15577      *
15578      * If an HVD device is attached to one of LVD connectors, return an error.
15579      * However, there is no way to detect HVD device attached to SE connectors.
15580      */
15581     if (scsi_cfg1 & HVD)
15582     {
15583         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
15584         return ADV_ERROR;
15585     }
15586
15587     /*
15588      * If either SE or LVD automatic termination control is enabled, then
15589      * set the termination value based on a table listed in a_condor.h.
15590      *
15591      * If manual termination was specified with an EEPROM setting then
15592      * 'termination' was set-up in AdvInitFrom38C0800EEPROM() and is ready to
15593      * be 'ored' into SCSI_CFG1.
15594      */
15595     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
15596     {
15597         /* SE automatic termination control is enabled. */
15598         switch(scsi_cfg1 & C_DET_SE)
15599         {
15600             /* TERM_SE_HI: on, TERM_SE_LO: on */
15601             case 0x1: case 0x2: case 0x3:
15602                 asc_dvc->cfg->termination |= TERM_SE;
15603                 break;
15604
15605             /* TERM_SE_HI: on, TERM_SE_LO: off */
15606             case 0x0:
15607                 asc_dvc->cfg->termination |= TERM_SE_HI;
15608                 break;
15609         }
15610     }
15611
15612     if ((asc_dvc->cfg->termination & TERM_LVD) == 0)
15613     {
15614         /* LVD automatic termination control is enabled. */
15615         switch(scsi_cfg1 & C_DET_LVD)
15616         {
15617             /* TERM_LVD_HI: on, TERM_LVD_LO: on */
15618             case 0x4: case 0x8: case 0xC:
15619                 asc_dvc->cfg->termination |= TERM_LVD;
15620                 break;
15621
15622             /* TERM_LVD_HI: off, TERM_LVD_LO: off */
15623             case 0x0:
15624                 break;
15625         }
15626     }
15627
15628     /*
15629      * Clear any set TERM_SE and TERM_LVD bits.
15630      */
15631     scsi_cfg1 &= (~TERM_SE & ~TERM_LVD);
15632
15633     /*
15634      * Invert the TERM_SE and TERM_LVD bits and then set 'scsi_cfg1'.
15635      */
15636     scsi_cfg1 |= (~asc_dvc->cfg->termination & 0xF0);
15637
15638     /*
15639      * Clear BIG_ENDIAN, DIS_TERM_DRV, Terminator Polarity and HVD/LVD/SE bits
15640      * and set possibly modified termination control bits in the Microcode
15641      * SCSI_CFG1 Register Value.
15642      */
15643     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL & ~HVD_LVD_SE);
15644
15645     /*
15646      * Set SCSI_CFG1 Microcode Default Value
15647      *
15648      * Set possibly modified termination control and reset DIS_TERM_DRV
15649      * bits in the Microcode SCSI_CFG1 Register Value.
15650      *
15651      * The microcode will set the SCSI_CFG1 register using this value
15652      * after it is started below.
15653      */
15654     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
15655
15656     /*
15657      * Set MEM_CFG Microcode Default Value
15658      *
15659      * The microcode will set the MEM_CFG register using this value
15660      * after it is started below.
15661      *
15662      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
15663      * are defined.
15664      *
15665      * ASC-38C0800 has 16KB internal memory.
15666      */
15667     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
15668         BIOS_EN | RAM_SZ_16KB);
15669
15670     /*
15671      * Set SEL_MASK Microcode Default Value
15672      *
15673      * The microcode will set the SEL_MASK register using this value
15674      * after it is started below.
15675      */
15676     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
15677         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
15678
15679     /*
15680      * Build the carrier freelist.
15681      *
15682      * Driver must have already allocated memory and set 'carrier_buf'.
15683      */
15684     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
15685
15686     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
15687     asc_dvc->carr_freelist = NULL;
15688     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
15689     {
15690         buf_size = ADV_CARRIER_BUFSIZE;
15691     } else
15692     {
15693         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
15694     }
15695
15696     do {
15697         /*
15698          * Get physical address for the carrier 'carrp'.
15699          */
15700         contig_len = sizeof(ADV_CARR_T);
15701         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
15702             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
15703
15704         buf_size -= sizeof(ADV_CARR_T);
15705
15706         /*
15707          * If the current carrier is not physically contiguous, then
15708          * maybe there was a page crossing. Try the next carrier aligned
15709          * start address.
15710          */
15711         if (contig_len < sizeof(ADV_CARR_T))
15712         {
15713             carrp++;
15714             continue;
15715         }
15716
15717         carrp->carr_pa = carr_paddr;
15718         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
15719
15720         /*
15721          * Insert the carrier at the beginning of the freelist.
15722          */
15723         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
15724         asc_dvc->carr_freelist = carrp;
15725
15726         carrp++;
15727     }
15728     while (buf_size > 0);
15729
15730     /*
15731      * Set-up the Host->RISC Initiator Command Queue (ICQ).
15732      */
15733
15734     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
15735     {
15736         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15737         return ADV_ERROR;
15738     }
15739     asc_dvc->carr_freelist = (ADV_CARR_T *)
15740         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
15741
15742     /*
15743      * The first command issued will be placed in the stopper carrier.
15744      */
15745     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15746
15747     /*
15748      * Set RISC ICQ physical address start value.
15749      * carr_pa is LE, must be native before write
15750      */
15751     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
15752
15753     /*
15754      * Set-up the RISC->Host Initiator Response Queue (IRQ).
15755      */
15756     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
15757     {
15758         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
15759         return ADV_ERROR;
15760     }
15761     asc_dvc->carr_freelist = (ADV_CARR_T *)
15762         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
15763
15764     /*
15765      * The first command completed by the RISC will be placed in
15766      * the stopper.
15767      *
15768      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
15769      * completed the RISC will set the ASC_RQ_STOPPER bit.
15770      */
15771     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
15772
15773     /*
15774      * Set RISC IRQ physical address start value.
15775      *
15776      * carr_pa is LE, must be native before write *
15777      */
15778     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
15779     asc_dvc->carr_pending_cnt = 0;
15780
15781     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
15782         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
15783
15784     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
15785     AdvWriteWordRegister(iop_base, IOPW_PC, word);
15786
15787     /* finally, finally, gentlemen, start your engine */
15788     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
15789
15790     /*
15791      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
15792      * Resets should be performed. The RISC has to be running
15793      * to issue a SCSI Bus Reset.
15794      */
15795     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
15796     {
15797         /*
15798          * If the BIOS Signature is present in memory, restore the
15799          * BIOS Handshake Configuration Table and do not perform
15800          * a SCSI Bus Reset.
15801          */
15802         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
15803         {
15804             /*
15805              * Restore per TID negotiated values.
15806              */
15807             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15808             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15809             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15810             for (tid = 0; tid <= ADV_MAX_TID; tid++)
15811             {
15812                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15813                     max_cmd[tid]);
15814             }
15815         } else
15816         {
15817             if (AdvResetSB(asc_dvc) != ADV_TRUE)
15818             {
15819                 warn_code = ASC_WARN_BUSRESET_ERROR;
15820             }
15821         }
15822     }
15823
15824     return warn_code;
15825 }
15826
15827 /*
15828  * Initialize the ASC-38C1600.
15829  *
15830  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
15831  *
15832  * For a non-fatal error return a warning code. If there are no warnings
15833  * then 0 is returned.
15834  *
15835  * Needed after initialization for error recovery.
15836  */
15837 STATIC int
15838 AdvInitAsc38C1600Driver(ADV_DVC_VAR *asc_dvc)
15839 {
15840     AdvPortAddr iop_base;
15841     ushort      warn_code;
15842     ADV_DCNT    sum;
15843     int         begin_addr;
15844     int         end_addr;
15845     ushort      code_sum;
15846     long        word;
15847     int         j;
15848     int         adv_asc38C1600_expanded_size;
15849     ADV_CARR_T  *carrp;
15850     ADV_DCNT    contig_len;
15851     ADV_SDCNT   buf_size;
15852     ADV_PADDR   carr_paddr;
15853     int         i;
15854     ushort      scsi_cfg1;
15855     uchar       byte;
15856     uchar       tid;
15857     ushort      bios_mem[ASC_MC_BIOSLEN/2]; /* BIOS RISC Memory 0x40-0x8F. */
15858     ushort      wdtr_able, sdtr_able, ppr_able, tagqng_able;
15859     uchar       max_cmd[ASC_MAX_TID + 1];
15860
15861     /* If there is already an error, don't continue. */
15862     if (asc_dvc->err_code != 0)
15863     {
15864         return ADV_ERROR;
15865     }
15866
15867     /*
15868      * The caller must set 'chip_type' to ADV_CHIP_ASC38C1600.
15869      */
15870     if (asc_dvc->chip_type != ADV_CHIP_ASC38C1600)
15871     {
15872         asc_dvc->err_code = ASC_IERR_BAD_CHIPTYPE;
15873         return ADV_ERROR;
15874     }
15875
15876     warn_code = 0;
15877     iop_base = asc_dvc->iop_base;
15878
15879     /*
15880      * Save the RISC memory BIOS region before writing the microcode.
15881      * The BIOS may already be loaded and using its RISC LRAM region
15882      * so its region must be saved and restored.
15883      *
15884      * Note: This code makes the assumption, which is currently true,
15885      * that a chip reset does not clear RISC LRAM.
15886      */
15887     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
15888     {
15889         AdvReadWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
15890     }
15891
15892     /*
15893      * Save current per TID negotiated values.
15894      */
15895     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
15896     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
15897     AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
15898     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
15899     for (tid = 0; tid <= ASC_MAX_TID; tid++)
15900     {
15901         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
15902             max_cmd[tid]);
15903     }
15904
15905     /*
15906      * RAM BIST (Built-In Self Test)
15907      *
15908      * Address : I/O base + offset 0x38h register (byte).
15909      * Function: Bit 7-6(RW) : RAM mode
15910      *                          Normal Mode   : 0x00
15911      *                          Pre-test Mode : 0x40
15912      *                          RAM Test Mode : 0x80
15913      *           Bit 5       : unused
15914      *           Bit 4(RO)   : Done bit
15915      *           Bit 3-0(RO) : Status
15916      *                          Host Error    : 0x08
15917      *                          Int_RAM Error : 0x04
15918      *                          RISC Error    : 0x02
15919      *                          SCSI Error    : 0x01
15920      *                          No Error      : 0x00
15921      *
15922      * Note: RAM BIST code should be put right here, before loading the
15923      * microcode and after saving the RISC memory BIOS region.
15924      */
15925
15926     /*
15927      * LRAM Pre-test
15928      *
15929      * Write PRE_TEST_MODE (0x40) to register and wait for 10 milliseconds.
15930      * If Done bit not set or low nibble not PRE_TEST_VALUE (0x05), return
15931      * an error. Reset to NORMAL_MODE (0x00) and do again. If cannot reset
15932      * to NORMAL_MODE, return an error too.
15933      */
15934     for (i = 0; i < 2; i++)
15935     {
15936         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, PRE_TEST_MODE);
15937         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15938         byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15939         if ((byte & RAM_TEST_DONE) == 0 || (byte & 0x0F) != PRE_TEST_VALUE)
15940         {
15941             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15942             return ADV_ERROR;
15943         }
15944
15945         AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15946         DvcSleepMilliSecond(10);  /* Wait for 10ms before reading back. */
15947         if (AdvReadByteRegister(iop_base, IOPB_RAM_BIST)
15948             != NORMAL_VALUE)
15949         {
15950             asc_dvc->err_code |= ASC_IERR_BIST_PRE_TEST;
15951             return ADV_ERROR;
15952         }
15953     }
15954
15955     /*
15956      * LRAM Test - It takes about 1.5 ms to run through the test.
15957      *
15958      * Write RAM_TEST_MODE (0x80) to register and wait for 10 milliseconds.
15959      * If Done bit not set or Status not 0, save register byte, set the
15960      * err_code, and return an error.
15961      */
15962     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, RAM_TEST_MODE);
15963     DvcSleepMilliSecond(10);  /* Wait for 10ms before checking status. */
15964
15965     byte = AdvReadByteRegister(iop_base, IOPB_RAM_BIST);
15966     if ((byte & RAM_TEST_DONE) == 0 || (byte & RAM_TEST_STATUS) != 0)
15967     {
15968         /* Get here if Done bit not set or Status not 0. */
15969         asc_dvc->bist_err_code = byte;  /* for BIOS display message */
15970         asc_dvc->err_code |= ASC_IERR_BIST_RAM_TEST;
15971         return ADV_ERROR;
15972     }
15973
15974     /* We need to reset back to normal mode after LRAM test passes. */
15975     AdvWriteByteRegister(iop_base, IOPB_RAM_BIST, NORMAL_MODE);
15976
15977     /*
15978      * Load the Microcode
15979      *
15980      * Write the microcode image to RISC memory starting at address 0.
15981      *
15982      */
15983     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
15984
15985     /*
15986      * Assume the following compressed format of the microcode buffer:
15987      *
15988      *  254 word (508 byte) table indexed by byte code followed
15989      *  by the following byte codes:
15990      *
15991      *    1-Byte Code:
15992      *      00: Emit word 0 in table.
15993      *      01: Emit word 1 in table.
15994      *      .
15995      *      FD: Emit word 253 in table.
15996      *
15997      *    Multi-Byte Code:
15998      *      FE WW WW: (3 byte code) Word to emit is the next word WW WW.
15999      *      FF BB WW WW: (4 byte code) Emit BB count times next word WW WW.
16000      */
16001     word = 0;
16002     for (i = 253 * 2; i < _adv_asc38C1600_size; i++)
16003     {
16004         if (_adv_asc38C1600_buf[i] == 0xff)
16005         {
16006             for (j = 0; j < _adv_asc38C1600_buf[i + 1]; j++)
16007             {
16008                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
16009                      _adv_asc38C1600_buf[i + 3] << 8) |
16010                      _adv_asc38C1600_buf[i + 2]));
16011                 word++;
16012             }
16013            i += 3;
16014         } else if (_adv_asc38C1600_buf[i] == 0xfe)
16015         {
16016                 AdvWriteWordAutoIncLram(iop_base, (((ushort)
16017                      _adv_asc38C1600_buf[i + 2] << 8) |
16018                      _adv_asc38C1600_buf[i + 1]));
16019             i += 2;
16020             word++;
16021         } else
16022         {
16023             AdvWriteWordAutoIncLram(iop_base, (((ushort)
16024                  _adv_asc38C1600_buf[(_adv_asc38C1600_buf[i] * 2) + 1] << 8) |
16025                  _adv_asc38C1600_buf[_adv_asc38C1600_buf[i] * 2]));
16026             word++;
16027         }
16028     }
16029
16030     /*
16031      * Set 'word' for later use to clear the rest of memory and save
16032      * the expanded mcode size.
16033      */
16034     word *= 2;
16035     adv_asc38C1600_expanded_size = word;
16036
16037     /*
16038      * Clear the rest of ASC-38C1600 Internal RAM (32KB).
16039      */
16040     for (; word < ADV_38C1600_MEMSIZE; word += 2)
16041     {
16042         AdvWriteWordAutoIncLram(iop_base, 0);
16043     }
16044
16045     /*
16046      * Verify the microcode checksum.
16047      */
16048     sum = 0;
16049     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, 0);
16050
16051     for (word = 0; word < adv_asc38C1600_expanded_size; word += 2)
16052     {
16053         sum += AdvReadWordAutoIncLram(iop_base);
16054     }
16055
16056     if (sum != _adv_asc38C1600_chksum)
16057     {
16058         asc_dvc->err_code |= ASC_IERR_MCODE_CHKSUM;
16059         return ADV_ERROR;
16060     }
16061
16062     /*
16063      * Restore the RISC memory BIOS region.
16064      */
16065     for (i = 0; i < ASC_MC_BIOSLEN/2; i++)
16066     {
16067         AdvWriteWordLram(iop_base, ASC_MC_BIOSMEM + (2 * i), bios_mem[i]);
16068     }
16069
16070     /*
16071      * Calculate and write the microcode code checksum to the microcode
16072      * code checksum location ASC_MC_CODE_CHK_SUM (0x2C).
16073      */
16074     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, begin_addr);
16075     AdvReadWordLram(iop_base, ASC_MC_CODE_END_ADDR, end_addr);
16076     code_sum = 0;
16077     AdvWriteWordRegister(iop_base, IOPW_RAM_ADDR, begin_addr);
16078     for (word = begin_addr; word < end_addr; word += 2)
16079     {
16080         code_sum += AdvReadWordAutoIncLram(iop_base);
16081     }
16082     AdvWriteWordLram(iop_base, ASC_MC_CODE_CHK_SUM, code_sum);
16083
16084     /*
16085      * Read microcode version and date.
16086      */
16087     AdvReadWordLram(iop_base, ASC_MC_VERSION_DATE, asc_dvc->cfg->mcode_date);
16088     AdvReadWordLram(iop_base, ASC_MC_VERSION_NUM, asc_dvc->cfg->mcode_version);
16089
16090     /*
16091      * Set the chip type to indicate the ASC38C1600.
16092      */
16093     AdvWriteWordLram(iop_base, ASC_MC_CHIP_TYPE, ADV_CHIP_ASC38C1600);
16094
16095     /*
16096      * Write 1 to bit 14 'DIS_TERM_DRV' in the SCSI_CFG1 register.
16097      * When DIS_TERM_DRV set to 1, C_DET[3:0] will reflect current
16098      * cable detection and then we are able to read C_DET[3:0].
16099      *
16100      * Note: We will reset DIS_TERM_DRV to 0 in the 'Set SCSI_CFG1
16101      * Microcode Default Value' section below.
16102      */
16103     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16104     AdvWriteWordRegister(iop_base, IOPW_SCSI_CFG1, scsi_cfg1 | DIS_TERM_DRV);
16105
16106     /*
16107      * If the PCI Configuration Command Register "Parity Error Response
16108      * Control" Bit was clear (0), then set the microcode variable
16109      * 'control_flag' CONTROL_FLAG_IGNORE_PERR flag to tell the microcode
16110      * to ignore DMA parity errors.
16111      */
16112     if (asc_dvc->cfg->control_flag & CONTROL_FLAG_IGNORE_PERR)
16113     {
16114         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16115         word |= CONTROL_FLAG_IGNORE_PERR;
16116         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16117     }
16118
16119     /*
16120      * If the BIOS control flag AIPP (Asynchronous Information
16121      * Phase Protection) disable bit is not set, then set the firmware
16122      * 'control_flag' CONTROL_FLAG_ENABLE_AIPP bit to enable
16123      * AIPP checking and encoding.
16124      */
16125     if ((asc_dvc->bios_ctrl & BIOS_CTRL_AIPP_DIS) == 0)
16126     {
16127         AdvReadWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16128         word |= CONTROL_FLAG_ENABLE_AIPP;
16129         AdvWriteWordLram(iop_base, ASC_MC_CONTROL_FLAG, word);
16130     }
16131
16132     /*
16133      * For ASC-38C1600 use DMA_CFG0 default values: FIFO_THRESH_80B [6:4],
16134      * and START_CTL_TH [3:2].
16135      */
16136     AdvWriteByteRegister(iop_base, IOPB_DMA_CFG0,
16137         FIFO_THRESH_80B | START_CTL_TH | READ_CMD_MRM);
16138
16139     /*
16140      * Microcode operating variables for WDTR, SDTR, and command tag
16141      * queuing will be set in AdvInquiryHandling() based on what a
16142      * device reports it is capable of in Inquiry byte 7.
16143      *
16144      * If SCSI Bus Resets have been disabled, then directly set
16145      * SDTR and WDTR from the EEPROM configuration. This will allow
16146      * the BIOS and warm boot to work without a SCSI bus hang on
16147      * the Inquiry caused by host and target mismatched DTR values.
16148      * Without the SCSI Bus Reset, before an Inquiry a device can't
16149      * be assumed to be in Asynchronous, Narrow mode.
16150      */
16151     if ((asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS) == 0)
16152     {
16153         AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, asc_dvc->wdtr_able);
16154         AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, asc_dvc->sdtr_able);
16155     }
16156
16157     /*
16158      * Set microcode operating variables for DISC and SDTR_SPEED1,
16159      * SDTR_SPEED2, SDTR_SPEED3, and SDTR_SPEED4 based on the EEPROM
16160      * configuration values.
16161      *
16162      * The SDTR per TID bitmask overrides the SDTR_SPEED1, SDTR_SPEED2,
16163      * SDTR_SPEED3, and SDTR_SPEED4 values so it is safe to set them
16164      * without determining here whether the device supports SDTR.
16165      */
16166     AdvWriteWordLram(iop_base, ASC_MC_DISC_ENABLE, asc_dvc->cfg->disc_enable);
16167     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED1, asc_dvc->sdtr_speed1);
16168     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED2, asc_dvc->sdtr_speed2);
16169     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED3, asc_dvc->sdtr_speed3);
16170     AdvWriteWordLram(iop_base, ASC_MC_SDTR_SPEED4, asc_dvc->sdtr_speed4);
16171
16172     /*
16173      * Set SCSI_CFG0 Microcode Default Value.
16174      *
16175      * The microcode will set the SCSI_CFG0 register using this value
16176      * after it is started below.
16177      */
16178     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG0,
16179         PARITY_EN | QUEUE_128 | SEL_TMO_LONG | OUR_ID_EN |
16180         asc_dvc->chip_scsi_id);
16181
16182     /*
16183      * Calculate SCSI_CFG1 Microcode Default Value.
16184      *
16185      * The microcode will set the SCSI_CFG1 register using this value
16186      * after it is started below.
16187      *
16188      * Each ASC-38C1600 function has only two cable detect bits.
16189      * The bus mode override bits are in IOPB_SOFT_OVER_WR.
16190      */
16191     scsi_cfg1 = AdvReadWordRegister(iop_base, IOPW_SCSI_CFG1);
16192
16193     /*
16194      * If the cable is reversed all of the SCSI_CTRL register signals
16195      * will be set. Check for and return an error if this condition is
16196      * found.
16197      */
16198     if ((AdvReadWordRegister(iop_base, IOPW_SCSI_CTRL) & 0x3F07) == 0x3F07)
16199     {
16200         asc_dvc->err_code |= ASC_IERR_REVERSED_CABLE;
16201         return ADV_ERROR;
16202     }
16203
16204     /*
16205      * Each ASC-38C1600 function has two connectors. Only an HVD device
16206      * can not be connected to either connector. An LVD device or SE device
16207      * may be connected to either connecor. If an SE device is connected,
16208      * then at most Ultra speed (20 Mhz) can be used on both connectors.
16209      *
16210      * If an HVD device is attached, return an error.
16211      */
16212     if (scsi_cfg1 & HVD)
16213     {
16214         asc_dvc->err_code |= ASC_IERR_HVD_DEVICE;
16215         return ADV_ERROR;
16216     }
16217
16218     /*
16219      * Each function in the ASC-38C1600 uses only the SE cable detect and
16220      * termination because there are two connectors for each function. Each
16221      * function may use either LVD or SE mode. Corresponding the SE automatic
16222      * termination control EEPROM bits are used for each function. Each
16223      * function has its own EEPROM. If SE automatic control is enabled for
16224      * the function, then set the termination value based on a table listed
16225      * in a_condor.h.
16226      *
16227      * If manual termination is specified in the EEPROM for the function,
16228      * then 'termination' was set-up in AscInitFrom38C1600EEPROM() and is
16229      * ready to be 'ored' into SCSI_CFG1.
16230      */
16231     if ((asc_dvc->cfg->termination & TERM_SE) == 0)
16232     {
16233         /* SE automatic termination control is enabled. */
16234         switch(scsi_cfg1 & C_DET_SE)
16235         {
16236             /* TERM_SE_HI: on, TERM_SE_LO: on */
16237             case 0x1: case 0x2: case 0x3:
16238                 asc_dvc->cfg->termination |= TERM_SE;
16239                 break;
16240
16241             case 0x0:
16242                 if (ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) == 0)
16243                 {
16244                     /* Function 0 - TERM_SE_HI: off, TERM_SE_LO: off */
16245                 }
16246                 else
16247                 {
16248                     /* Function 1 - TERM_SE_HI: on, TERM_SE_LO: off */
16249                     asc_dvc->cfg->termination |= TERM_SE_HI;
16250                 }
16251                 break;
16252         }
16253     }
16254
16255     /*
16256      * Clear any set TERM_SE bits.
16257      */
16258     scsi_cfg1 &= ~TERM_SE;
16259
16260     /*
16261      * Invert the TERM_SE bits and then set 'scsi_cfg1'.
16262      */
16263     scsi_cfg1 |= (~asc_dvc->cfg->termination & TERM_SE);
16264
16265     /*
16266      * Clear Big Endian and Terminator Polarity bits and set possibly
16267      * modified termination control bits in the Microcode SCSI_CFG1
16268      * Register Value.
16269      *
16270      * Big Endian bit is not used even on big endian machines.
16271      */
16272     scsi_cfg1 &= (~BIG_ENDIAN & ~DIS_TERM_DRV & ~TERM_POL);
16273
16274     /*
16275      * Set SCSI_CFG1 Microcode Default Value
16276      *
16277      * Set possibly modified termination control bits in the Microcode
16278      * SCSI_CFG1 Register Value.
16279      *
16280      * The microcode will set the SCSI_CFG1 register using this value
16281      * after it is started below.
16282      */
16283     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SCSI_CFG1, scsi_cfg1);
16284
16285     /*
16286      * Set MEM_CFG Microcode Default Value
16287      *
16288      * The microcode will set the MEM_CFG register using this value
16289      * after it is started below.
16290      *
16291      * MEM_CFG may be accessed as a word or byte, but only bits 0-7
16292      * are defined.
16293      *
16294      * ASC-38C1600 has 32KB internal memory.
16295      *
16296      * XXX - Since ASC38C1600 Rev.3 has a Local RAM failure issue, we come
16297      * out a special 16K Adv Library and Microcode version. After the issue
16298      * resolved, we should turn back to the 32K support. Both a_condor.h and
16299      * mcode.sas files also need to be updated.
16300      *
16301      * AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG,
16302      *  BIOS_EN | RAM_SZ_32KB);
16303      */
16304      AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_MEM_CFG, BIOS_EN | RAM_SZ_16KB);
16305
16306     /*
16307      * Set SEL_MASK Microcode Default Value
16308      *
16309      * The microcode will set the SEL_MASK register using this value
16310      * after it is started below.
16311      */
16312     AdvWriteWordLram(iop_base, ASC_MC_DEFAULT_SEL_MASK,
16313         ADV_TID_TO_TIDMASK(asc_dvc->chip_scsi_id));
16314
16315     /*
16316      * Build the carrier freelist.
16317      *
16318      * Driver must have already allocated memory and set 'carrier_buf'.
16319      */
16320
16321     ASC_ASSERT(asc_dvc->carrier_buf != NULL);
16322
16323     carrp = (ADV_CARR_T *) ADV_16BALIGN(asc_dvc->carrier_buf);
16324     asc_dvc->carr_freelist = NULL;
16325     if (carrp == (ADV_CARR_T *) asc_dvc->carrier_buf)
16326     {
16327         buf_size = ADV_CARRIER_BUFSIZE;
16328     } else
16329     {
16330         buf_size = ADV_CARRIER_BUFSIZE - sizeof(ADV_CARR_T);
16331     }
16332
16333     do {
16334         /*
16335          * Get physical address for the carrier 'carrp'.
16336          */
16337         contig_len = sizeof(ADV_CARR_T);
16338         carr_paddr = cpu_to_le32(DvcGetPhyAddr(asc_dvc, NULL, (uchar *) carrp,
16339             (ADV_SDCNT *) &contig_len, ADV_IS_CARRIER_FLAG));
16340
16341         buf_size -= sizeof(ADV_CARR_T);
16342
16343         /*
16344          * If the current carrier is not physically contiguous, then
16345          * maybe there was a page crossing. Try the next carrier aligned
16346          * start address.
16347          */
16348         if (contig_len < sizeof(ADV_CARR_T))
16349         {
16350             carrp++;
16351             continue;
16352         }
16353
16354         carrp->carr_pa = carr_paddr;
16355         carrp->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(carrp));
16356
16357         /*
16358          * Insert the carrier at the beginning of the freelist.
16359          */
16360         carrp->next_vpa = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
16361         asc_dvc->carr_freelist = carrp;
16362
16363         carrp++;
16364     }
16365     while (buf_size > 0);
16366
16367     /*
16368      * Set-up the Host->RISC Initiator Command Queue (ICQ).
16369      */
16370     if ((asc_dvc->icq_sp = asc_dvc->carr_freelist) == NULL)
16371     {
16372         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16373         return ADV_ERROR;
16374     }
16375     asc_dvc->carr_freelist = (ADV_CARR_T *)
16376         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->icq_sp->next_vpa));
16377
16378     /*
16379      * The first command issued will be placed in the stopper carrier.
16380      */
16381     asc_dvc->icq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16382
16383     /*
16384      * Set RISC ICQ physical address start value. Initialize the
16385      * COMMA register to the same value otherwise the RISC will
16386      * prematurely detect a command is available.
16387      */
16388     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_ICQ, asc_dvc->icq_sp->carr_pa);
16389     AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
16390         le32_to_cpu(asc_dvc->icq_sp->carr_pa));
16391
16392     /*
16393      * Set-up the RISC->Host Initiator Response Queue (IRQ).
16394      */
16395     if ((asc_dvc->irq_sp = asc_dvc->carr_freelist) == NULL)
16396     {
16397         asc_dvc->err_code |= ASC_IERR_NO_CARRIER;
16398         return ADV_ERROR;
16399     }
16400     asc_dvc->carr_freelist = (ADV_CARR_T *)
16401         ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->next_vpa));
16402
16403     /*
16404      * The first command completed by the RISC will be placed in
16405      * the stopper.
16406      *
16407      * Note: Set 'next_vpa' to ASC_CQ_STOPPER. When the request is
16408      * completed the RISC will set the ASC_RQ_STOPPER bit.
16409      */
16410     asc_dvc->irq_sp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
16411
16412     /*
16413      * Set RISC IRQ physical address start value.
16414      */
16415     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IRQ, asc_dvc->irq_sp->carr_pa);
16416     asc_dvc->carr_pending_cnt = 0;
16417
16418     AdvWriteByteRegister(iop_base, IOPB_INTR_ENABLES,
16419         (ADV_INTR_ENABLE_HOST_INTR | ADV_INTR_ENABLE_GLOBAL_INTR));
16420     AdvReadWordLram(iop_base, ASC_MC_CODE_BEGIN_ADDR, word);
16421     AdvWriteWordRegister(iop_base, IOPW_PC, word);
16422
16423     /* finally, finally, gentlemen, start your engine */
16424     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_RUN);
16425
16426     /*
16427      * Reset the SCSI Bus if the EEPROM indicates that SCSI Bus
16428      * Resets should be performed. The RISC has to be running
16429      * to issue a SCSI Bus Reset.
16430      */
16431     if (asc_dvc->bios_ctrl & BIOS_CTRL_RESET_SCSI_BUS)
16432     {
16433         /*
16434          * If the BIOS Signature is present in memory, restore the
16435          * per TID microcode operating variables.
16436          */
16437         if (bios_mem[(ASC_MC_BIOS_SIGNATURE - ASC_MC_BIOSMEM)/2] == 0x55AA)
16438         {
16439             /*
16440              * Restore per TID negotiated values.
16441              */
16442             AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
16443             AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
16444             AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
16445             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
16446             for (tid = 0; tid <= ASC_MAX_TID; tid++)
16447             {
16448                 AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
16449                     max_cmd[tid]);
16450             }
16451         } else
16452         {
16453             if (AdvResetSB(asc_dvc) != ADV_TRUE)
16454             {
16455                 warn_code = ASC_WARN_BUSRESET_ERROR;
16456             }
16457         }
16458     }
16459
16460     return warn_code;
16461 }
16462
16463 /*
16464  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16465  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16466  * all of this is done.
16467  *
16468  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16469  *
16470  * For a non-fatal error return a warning code. If there are no warnings
16471  * then 0 is returned.
16472  *
16473  * Note: Chip is stopped on entry.
16474  */
16475 STATIC int __init
16476 AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
16477 {
16478     AdvPortAddr         iop_base;
16479     ushort              warn_code;
16480     ADVEEP_3550_CONFIG  eep_config;
16481     int                 i;
16482
16483     iop_base = asc_dvc->iop_base;
16484
16485     warn_code = 0;
16486
16487     /*
16488      * Read the board's EEPROM configuration.
16489      *
16490      * Set default values if a bad checksum is found.
16491      */
16492     if (AdvGet3550EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16493     {
16494         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16495
16496         /*
16497          * Set EEPROM default values.
16498          */
16499         for (i = 0; i < sizeof(ADVEEP_3550_CONFIG); i++)
16500         {
16501             *((uchar *) &eep_config + i) =
16502                 *((uchar *) &Default_3550_EEPROM_Config + i);
16503         }
16504
16505         /*
16506          * Assume the 6 byte board serial number that was read
16507          * from EEPROM is correct even if the EEPROM checksum
16508          * failed.
16509          */
16510         eep_config.serial_number_word3 =
16511             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16512
16513         eep_config.serial_number_word2 =
16514             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16515
16516         eep_config.serial_number_word1 =
16517             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16518
16519         AdvSet3550EEPConfig(iop_base, &eep_config);
16520     }
16521     /*
16522      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16523      * EEPROM configuration that was read.
16524      *
16525      * This is the mapping of EEPROM fields to Adv Library fields.
16526      */
16527     asc_dvc->wdtr_able = eep_config.wdtr_able;
16528     asc_dvc->sdtr_able = eep_config.sdtr_able;
16529     asc_dvc->ultra_able = eep_config.ultra_able;
16530     asc_dvc->tagqng_able = eep_config.tagqng_able;
16531     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16532     asc_dvc->max_host_qng = eep_config.max_host_qng;
16533     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16534     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16535     asc_dvc->start_motor = eep_config.start_motor;
16536     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16537     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16538     asc_dvc->no_scam = eep_config.scam_tolerant;
16539     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16540     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16541     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16542
16543     /*
16544      * Set the host maximum queuing (max. 253, min. 16) and the per device
16545      * maximum queuing (max. 63, min. 4).
16546      */
16547     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16548     {
16549         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16550     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16551     {
16552         /* If the value is zero, assume it is uninitialized. */
16553         if (eep_config.max_host_qng == 0)
16554         {
16555             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16556         } else
16557         {
16558             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16559         }
16560     }
16561
16562     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16563     {
16564         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16565     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16566     {
16567         /* If the value is zero, assume it is uninitialized. */
16568         if (eep_config.max_dvc_qng == 0)
16569         {
16570             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16571         } else
16572         {
16573             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16574         }
16575     }
16576
16577     /*
16578      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16579      * set 'max_dvc_qng' to 'max_host_qng'.
16580      */
16581     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16582     {
16583         eep_config.max_dvc_qng = eep_config.max_host_qng;
16584     }
16585
16586     /*
16587      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16588      * values based on possibly adjusted EEPROM values.
16589      */
16590     asc_dvc->max_host_qng = eep_config.max_host_qng;
16591     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16592
16593
16594     /*
16595      * If the EEPROM 'termination' field is set to automatic (0), then set
16596      * the ADV_DVC_CFG 'termination' field to automatic also.
16597      *
16598      * If the termination is specified with a non-zero 'termination'
16599      * value check that a legal value is set and set the ADV_DVC_CFG
16600      * 'termination' field appropriately.
16601      */
16602     if (eep_config.termination == 0)
16603     {
16604         asc_dvc->cfg->termination = 0;    /* auto termination */
16605     } else
16606     {
16607         /* Enable manual control with low off / high off. */
16608         if (eep_config.termination == 1)
16609         {
16610             asc_dvc->cfg->termination = TERM_CTL_SEL;
16611
16612         /* Enable manual control with low off / high on. */
16613         } else if (eep_config.termination == 2)
16614         {
16615             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H;
16616
16617         /* Enable manual control with low on / high on. */
16618         } else if (eep_config.termination == 3)
16619         {
16620             asc_dvc->cfg->termination = TERM_CTL_SEL | TERM_CTL_H | TERM_CTL_L;
16621         } else
16622         {
16623             /*
16624              * The EEPROM 'termination' field contains a bad value. Use
16625              * automatic termination instead.
16626              */
16627             asc_dvc->cfg->termination = 0;
16628             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16629         }
16630     }
16631
16632     return warn_code;
16633 }
16634
16635 /*
16636  * Read the board's EEPROM configuration. Set fields in ADV_DVC_VAR and
16637  * ADV_DVC_CFG based on the EEPROM settings. The chip is stopped while
16638  * all of this is done.
16639  *
16640  * On failure set the ADV_DVC_VAR field 'err_code' and return ADV_ERROR.
16641  *
16642  * For a non-fatal error return a warning code. If there are no warnings
16643  * then 0 is returned.
16644  *
16645  * Note: Chip is stopped on entry.
16646  */
16647 STATIC int __init
16648 AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
16649 {
16650     AdvPortAddr              iop_base;
16651     ushort                   warn_code;
16652     ADVEEP_38C0800_CONFIG    eep_config;
16653     int                      i;
16654     uchar                    tid, termination;
16655     ushort                   sdtr_speed = 0;
16656
16657     iop_base = asc_dvc->iop_base;
16658
16659     warn_code = 0;
16660
16661     /*
16662      * Read the board's EEPROM configuration.
16663      *
16664      * Set default values if a bad checksum is found.
16665      */
16666     if (AdvGet38C0800EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16667     {
16668         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16669
16670         /*
16671          * Set EEPROM default values.
16672          */
16673         for (i = 0; i < sizeof(ADVEEP_38C0800_CONFIG); i++)
16674         {
16675             *((uchar *) &eep_config + i) =
16676                 *((uchar *) &Default_38C0800_EEPROM_Config + i);
16677         }
16678
16679         /*
16680          * Assume the 6 byte board serial number that was read
16681          * from EEPROM is correct even if the EEPROM checksum
16682          * failed.
16683          */
16684         eep_config.serial_number_word3 =
16685             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16686
16687         eep_config.serial_number_word2 =
16688             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16689
16690         eep_config.serial_number_word1 =
16691             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16692
16693         AdvSet38C0800EEPConfig(iop_base, &eep_config);
16694     }
16695     /*
16696      * Set ADV_DVC_VAR and ADV_DVC_CFG variables from the
16697      * EEPROM configuration that was read.
16698      *
16699      * This is the mapping of EEPROM fields to Adv Library fields.
16700      */
16701     asc_dvc->wdtr_able = eep_config.wdtr_able;
16702     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16703     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16704     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16705     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16706     asc_dvc->tagqng_able = eep_config.tagqng_able;
16707     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16708     asc_dvc->max_host_qng = eep_config.max_host_qng;
16709     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16710     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ADV_MAX_TID);
16711     asc_dvc->start_motor = eep_config.start_motor;
16712     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16713     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16714     asc_dvc->no_scam = eep_config.scam_tolerant;
16715     asc_dvc->cfg->serial1 = eep_config.serial_number_word1;
16716     asc_dvc->cfg->serial2 = eep_config.serial_number_word2;
16717     asc_dvc->cfg->serial3 = eep_config.serial_number_word3;
16718
16719     /*
16720      * For every Target ID if any of its 'sdtr_speed[1234]' bits
16721      * are set, then set an 'sdtr_able' bit for it.
16722      */
16723     asc_dvc->sdtr_able = 0;
16724     for (tid = 0; tid <= ADV_MAX_TID; tid++)
16725     {
16726         if (tid == 0)
16727         {
16728             sdtr_speed = asc_dvc->sdtr_speed1;
16729         } else if (tid == 4)
16730         {
16731             sdtr_speed = asc_dvc->sdtr_speed2;
16732         } else if (tid == 8)
16733         {
16734             sdtr_speed = asc_dvc->sdtr_speed3;
16735         } else if (tid == 12)
16736         {
16737             sdtr_speed = asc_dvc->sdtr_speed4;
16738         }
16739         if (sdtr_speed & ADV_MAX_TID)
16740         {
16741             asc_dvc->sdtr_able |= (1 << tid);
16742         }
16743         sdtr_speed >>= 4;
16744     }
16745
16746     /*
16747      * Set the host maximum queuing (max. 253, min. 16) and the per device
16748      * maximum queuing (max. 63, min. 4).
16749      */
16750     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
16751     {
16752         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16753     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
16754     {
16755         /* If the value is zero, assume it is uninitialized. */
16756         if (eep_config.max_host_qng == 0)
16757         {
16758             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
16759         } else
16760         {
16761             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
16762         }
16763     }
16764
16765     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
16766     {
16767         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16768     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
16769     {
16770         /* If the value is zero, assume it is uninitialized. */
16771         if (eep_config.max_dvc_qng == 0)
16772         {
16773             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
16774         } else
16775         {
16776             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
16777         }
16778     }
16779
16780     /*
16781      * If 'max_dvc_qng' is greater than 'max_host_qng', then
16782      * set 'max_dvc_qng' to 'max_host_qng'.
16783      */
16784     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
16785     {
16786         eep_config.max_dvc_qng = eep_config.max_host_qng;
16787     }
16788
16789     /*
16790      * Set ADV_DVC_VAR 'max_host_qng' and ADV_DVC_VAR 'max_dvc_qng'
16791      * values based on possibly adjusted EEPROM values.
16792      */
16793     asc_dvc->max_host_qng = eep_config.max_host_qng;
16794     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16795
16796     /*
16797      * If the EEPROM 'termination' field is set to automatic (0), then set
16798      * the ADV_DVC_CFG 'termination' field to automatic also.
16799      *
16800      * If the termination is specified with a non-zero 'termination'
16801      * value check that a legal value is set and set the ADV_DVC_CFG
16802      * 'termination' field appropriately.
16803      */
16804     if (eep_config.termination_se == 0)
16805     {
16806         termination = 0;                         /* auto termination for SE */
16807     } else
16808     {
16809         /* Enable manual control with low off / high off. */
16810         if (eep_config.termination_se == 1)
16811         {
16812             termination = 0;
16813
16814         /* Enable manual control with low off / high on. */
16815         } else if (eep_config.termination_se == 2)
16816         {
16817             termination = TERM_SE_HI;
16818
16819         /* Enable manual control with low on / high on. */
16820         } else if (eep_config.termination_se == 3)
16821         {
16822             termination = TERM_SE;
16823         } else
16824         {
16825             /*
16826              * The EEPROM 'termination_se' field contains a bad value.
16827              * Use automatic termination instead.
16828              */
16829             termination = 0;
16830             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16831         }
16832     }
16833
16834     if (eep_config.termination_lvd == 0)
16835     {
16836         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
16837     } else
16838     {
16839         /* Enable manual control with low off / high off. */
16840         if (eep_config.termination_lvd == 1)
16841         {
16842             asc_dvc->cfg->termination = termination;
16843
16844         /* Enable manual control with low off / high on. */
16845         } else if (eep_config.termination_lvd == 2)
16846         {
16847             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
16848
16849         /* Enable manual control with low on / high on. */
16850         } else if (eep_config.termination_lvd == 3)
16851         {
16852             asc_dvc->cfg->termination =
16853                 termination | TERM_LVD;
16854         } else
16855         {
16856             /*
16857              * The EEPROM 'termination_lvd' field contains a bad value.
16858              * Use automatic termination instead.
16859              */
16860             asc_dvc->cfg->termination = termination;
16861             warn_code |= ASC_WARN_EEPROM_TERMINATION;
16862         }
16863     }
16864
16865     return warn_code;
16866 }
16867
16868 /*
16869  * Read the board's EEPROM configuration. Set fields in ASC_DVC_VAR and
16870  * ASC_DVC_CFG based on the EEPROM settings. The chip is stopped while
16871  * all of this is done.
16872  *
16873  * On failure set the ASC_DVC_VAR field 'err_code' and return ADV_ERROR.
16874  *
16875  * For a non-fatal error return a warning code. If there are no warnings
16876  * then 0 is returned.
16877  *
16878  * Note: Chip is stopped on entry.
16879  */
16880 STATIC int __init
16881 AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
16882 {
16883     AdvPortAddr              iop_base;
16884     ushort                   warn_code;
16885     ADVEEP_38C1600_CONFIG    eep_config;
16886     int                      i;
16887     uchar                    tid, termination;
16888     ushort                   sdtr_speed = 0;
16889
16890     iop_base = asc_dvc->iop_base;
16891
16892     warn_code = 0;
16893
16894     /*
16895      * Read the board's EEPROM configuration.
16896      *
16897      * Set default values if a bad checksum is found.
16898      */
16899     if (AdvGet38C1600EEPConfig(iop_base, &eep_config) != eep_config.check_sum)
16900     {
16901         warn_code |= ASC_WARN_EEPROM_CHKSUM;
16902
16903         /*
16904          * Set EEPROM default values.
16905          */
16906         for (i = 0; i < sizeof(ADVEEP_38C1600_CONFIG); i++)
16907         {
16908             if (i == 1 && ASC_PCI_ID2FUNC(asc_dvc->cfg->pci_slot_info) != 0)
16909             {
16910                 /*
16911                  * Set Function 1 EEPROM Word 0 MSB
16912                  *
16913                  * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
16914                  * EEPROM bits.
16915                  *
16916                  * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
16917                  * old Mac system booting problem. The Expansion ROM must
16918                  * be disabled in Function 1 for these systems.
16919                  *
16920                  */
16921                 *((uchar *) &eep_config + i) =
16922                 ((*((uchar *) &Default_38C1600_EEPROM_Config + i)) &
16923                     (~(((ADV_EEPROM_BIOS_ENABLE | ADV_EEPROM_INTAB) >> 8) &
16924                      0xFF)));
16925
16926                 /*
16927                  * Set the INTAB (bit 11) if the GPIO 0 input indicates
16928                  * the Function 1 interrupt line is wired to INTA.
16929                  *
16930                  * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
16931                  *   1 - Function 1 interrupt line wired to INT A.
16932                  *   0 - Function 1 interrupt line wired to INT B.
16933                  *
16934                  * Note: Adapter boards always have Function 0 wired to INTA.
16935                  * Put all 5 GPIO bits in input mode and then read
16936                  * their input values.
16937                  */
16938                 AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
16939                 if (AdvReadByteRegister(iop_base, IOPB_GPIO_DATA) & 0x01)
16940                 {
16941                     /* Function 1 interrupt wired to INTA; Set EEPROM bit. */
16942                 *((uchar *) &eep_config + i) |=
16943                     ((ADV_EEPROM_INTAB >> 8) & 0xFF);
16944                 }
16945             }
16946             else
16947             {
16948                 *((uchar *) &eep_config + i) =
16949                 *((uchar *) &Default_38C1600_EEPROM_Config + i);
16950             }
16951         }
16952
16953         /*
16954          * Assume the 6 byte board serial number that was read
16955          * from EEPROM is correct even if the EEPROM checksum
16956          * failed.
16957          */
16958         eep_config.serial_number_word3 =
16959             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
16960
16961         eep_config.serial_number_word2 =
16962             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
16963
16964         eep_config.serial_number_word1 =
16965             AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
16966
16967         AdvSet38C1600EEPConfig(iop_base, &eep_config);
16968     }
16969
16970     /*
16971      * Set ASC_DVC_VAR and ASC_DVC_CFG variables from the
16972      * EEPROM configuration that was read.
16973      *
16974      * This is the mapping of EEPROM fields to Adv Library fields.
16975      */
16976     asc_dvc->wdtr_able = eep_config.wdtr_able;
16977     asc_dvc->sdtr_speed1 = eep_config.sdtr_speed1;
16978     asc_dvc->sdtr_speed2 = eep_config.sdtr_speed2;
16979     asc_dvc->sdtr_speed3 = eep_config.sdtr_speed3;
16980     asc_dvc->sdtr_speed4 = eep_config.sdtr_speed4;
16981     asc_dvc->ppr_able = 0;
16982     asc_dvc->tagqng_able = eep_config.tagqng_able;
16983     asc_dvc->cfg->disc_enable = eep_config.disc_enable;
16984     asc_dvc->max_host_qng = eep_config.max_host_qng;
16985     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
16986     asc_dvc->chip_scsi_id = (eep_config.adapter_scsi_id & ASC_MAX_TID);
16987     asc_dvc->start_motor = eep_config.start_motor;
16988     asc_dvc->scsi_reset_wait = eep_config.scsi_reset_delay;
16989     asc_dvc->bios_ctrl = eep_config.bios_ctrl;
16990     asc_dvc->no_scam = eep_config.scam_tolerant;
16991
16992     /*
16993      * For every Target ID if any of its 'sdtr_speed[1234]' bits
16994      * are set, then set an 'sdtr_able' bit for it.
16995      */
16996     asc_dvc->sdtr_able = 0;
16997     for (tid = 0; tid <= ASC_MAX_TID; tid++)
16998     {
16999         if (tid == 0)
17000         {
17001             sdtr_speed = asc_dvc->sdtr_speed1;
17002         } else if (tid == 4)
17003         {
17004             sdtr_speed = asc_dvc->sdtr_speed2;
17005         } else if (tid == 8)
17006         {
17007             sdtr_speed = asc_dvc->sdtr_speed3;
17008         } else if (tid == 12)
17009         {
17010             sdtr_speed = asc_dvc->sdtr_speed4;
17011         }
17012         if (sdtr_speed & ASC_MAX_TID)
17013         {
17014             asc_dvc->sdtr_able |= (1 << tid);
17015         }
17016         sdtr_speed >>= 4;
17017     }
17018
17019     /*
17020      * Set the host maximum queuing (max. 253, min. 16) and the per device
17021      * maximum queuing (max. 63, min. 4).
17022      */
17023     if (eep_config.max_host_qng > ASC_DEF_MAX_HOST_QNG)
17024     {
17025         eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17026     } else if (eep_config.max_host_qng < ASC_DEF_MIN_HOST_QNG)
17027     {
17028         /* If the value is zero, assume it is uninitialized. */
17029         if (eep_config.max_host_qng == 0)
17030         {
17031             eep_config.max_host_qng = ASC_DEF_MAX_HOST_QNG;
17032         } else
17033         {
17034             eep_config.max_host_qng = ASC_DEF_MIN_HOST_QNG;
17035         }
17036     }
17037
17038     if (eep_config.max_dvc_qng > ASC_DEF_MAX_DVC_QNG)
17039     {
17040         eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17041     } else if (eep_config.max_dvc_qng < ASC_DEF_MIN_DVC_QNG)
17042     {
17043         /* If the value is zero, assume it is uninitialized. */
17044         if (eep_config.max_dvc_qng == 0)
17045         {
17046             eep_config.max_dvc_qng = ASC_DEF_MAX_DVC_QNG;
17047         } else
17048         {
17049             eep_config.max_dvc_qng = ASC_DEF_MIN_DVC_QNG;
17050         }
17051     }
17052
17053     /*
17054      * If 'max_dvc_qng' is greater than 'max_host_qng', then
17055      * set 'max_dvc_qng' to 'max_host_qng'.
17056      */
17057     if (eep_config.max_dvc_qng > eep_config.max_host_qng)
17058     {
17059         eep_config.max_dvc_qng = eep_config.max_host_qng;
17060     }
17061
17062     /*
17063      * Set ASC_DVC_VAR 'max_host_qng' and ASC_DVC_VAR 'max_dvc_qng'
17064      * values based on possibly adjusted EEPROM values.
17065      */
17066     asc_dvc->max_host_qng = eep_config.max_host_qng;
17067     asc_dvc->max_dvc_qng = eep_config.max_dvc_qng;
17068
17069     /*
17070      * If the EEPROM 'termination' field is set to automatic (0), then set
17071      * the ASC_DVC_CFG 'termination' field to automatic also.
17072      *
17073      * If the termination is specified with a non-zero 'termination'
17074      * value check that a legal value is set and set the ASC_DVC_CFG
17075      * 'termination' field appropriately.
17076      */
17077     if (eep_config.termination_se == 0)
17078     {
17079         termination = 0;                         /* auto termination for SE */
17080     } else
17081     {
17082         /* Enable manual control with low off / high off. */
17083         if (eep_config.termination_se == 1)
17084         {
17085             termination = 0;
17086
17087         /* Enable manual control with low off / high on. */
17088         } else if (eep_config.termination_se == 2)
17089         {
17090             termination = TERM_SE_HI;
17091
17092         /* Enable manual control with low on / high on. */
17093         } else if (eep_config.termination_se == 3)
17094         {
17095             termination = TERM_SE;
17096         } else
17097         {
17098             /*
17099              * The EEPROM 'termination_se' field contains a bad value.
17100              * Use automatic termination instead.
17101              */
17102             termination = 0;
17103             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17104         }
17105     }
17106
17107     if (eep_config.termination_lvd == 0)
17108     {
17109         asc_dvc->cfg->termination = termination; /* auto termination for LVD */
17110     } else
17111     {
17112         /* Enable manual control with low off / high off. */
17113         if (eep_config.termination_lvd == 1)
17114         {
17115             asc_dvc->cfg->termination = termination;
17116
17117         /* Enable manual control with low off / high on. */
17118         } else if (eep_config.termination_lvd == 2)
17119         {
17120             asc_dvc->cfg->termination = termination | TERM_LVD_HI;
17121
17122         /* Enable manual control with low on / high on. */
17123         } else if (eep_config.termination_lvd == 3)
17124         {
17125             asc_dvc->cfg->termination =
17126                 termination | TERM_LVD;
17127         } else
17128         {
17129             /*
17130              * The EEPROM 'termination_lvd' field contains a bad value.
17131              * Use automatic termination instead.
17132              */
17133             asc_dvc->cfg->termination = termination;
17134             warn_code |= ASC_WARN_EEPROM_TERMINATION;
17135         }
17136     }
17137
17138     return warn_code;
17139 }
17140
17141 /*
17142  * Read EEPROM configuration into the specified buffer.
17143  *
17144  * Return a checksum based on the EEPROM configuration read.
17145  */
17146 STATIC ushort __init
17147 AdvGet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17148 {
17149     ushort              wval, chksum;
17150     ushort              *wbuf;
17151     int                 eep_addr;
17152     ushort              *charfields;
17153
17154     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17155     wbuf = (ushort *) cfg_buf;
17156     chksum = 0;
17157
17158     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17159          eep_addr < ADV_EEP_DVC_CFG_END;
17160          eep_addr++, wbuf++)
17161     {
17162         wval = AdvReadEEPWord(iop_base, eep_addr);
17163         chksum += wval; /* Checksum is calculated from word values. */
17164         if (*charfields++) {
17165             *wbuf = le16_to_cpu(wval);
17166         } else {
17167             *wbuf = wval;
17168         }
17169     }
17170     /* Read checksum word. */
17171     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17172     wbuf++; charfields++;
17173
17174     /* Read rest of EEPROM not covered by the checksum. */
17175     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17176          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17177          eep_addr++, wbuf++)
17178     {
17179         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17180         if (*charfields++) {
17181             *wbuf = le16_to_cpu(*wbuf);
17182         }
17183     }
17184     return chksum;
17185 }
17186
17187 /*
17188  * Read EEPROM configuration into the specified buffer.
17189  *
17190  * Return a checksum based on the EEPROM configuration read.
17191  */
17192 STATIC ushort __init
17193 AdvGet38C0800EEPConfig(AdvPortAddr iop_base,
17194                        ADVEEP_38C0800_CONFIG *cfg_buf)
17195 {
17196     ushort              wval, chksum;
17197     ushort              *wbuf;
17198     int                 eep_addr;
17199     ushort              *charfields;
17200
17201     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17202     wbuf = (ushort *) cfg_buf;
17203     chksum = 0;
17204
17205     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17206          eep_addr < ADV_EEP_DVC_CFG_END;
17207          eep_addr++, wbuf++)
17208     {
17209         wval = AdvReadEEPWord(iop_base, eep_addr);
17210         chksum += wval; /* Checksum is calculated from word values. */
17211         if (*charfields++) {
17212             *wbuf = le16_to_cpu(wval);
17213         } else {
17214             *wbuf = wval;
17215         }
17216     }
17217     /* Read checksum word. */
17218     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17219     wbuf++; charfields++;
17220
17221     /* Read rest of EEPROM not covered by the checksum. */
17222     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17223          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17224          eep_addr++, wbuf++)
17225     {
17226         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17227         if (*charfields++) {
17228             *wbuf = le16_to_cpu(*wbuf);
17229         }
17230     }
17231     return chksum;
17232 }
17233
17234 /*
17235  * Read EEPROM configuration into the specified buffer.
17236  *
17237  * Return a checksum based on the EEPROM configuration read.
17238  */
17239 STATIC ushort __init
17240 AdvGet38C1600EEPConfig(AdvPortAddr iop_base,
17241                        ADVEEP_38C1600_CONFIG *cfg_buf)
17242 {
17243     ushort              wval, chksum;
17244     ushort              *wbuf;
17245     int                 eep_addr;
17246     ushort              *charfields;
17247
17248     charfields = (ushort*) &ADVEEP_38C1600_Config_Field_IsChar;
17249     wbuf = (ushort *) cfg_buf;
17250     chksum = 0;
17251
17252     for (eep_addr = ADV_EEP_DVC_CFG_BEGIN;
17253          eep_addr < ADV_EEP_DVC_CFG_END;
17254          eep_addr++, wbuf++)
17255     {
17256         wval = AdvReadEEPWord(iop_base, eep_addr);
17257         chksum += wval; /* Checksum is calculated from word values. */
17258         if (*charfields++) {
17259             *wbuf = le16_to_cpu(wval);
17260         } else {
17261             *wbuf = wval;
17262         }
17263     }
17264     /* Read checksum word. */
17265     *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17266     wbuf++; charfields++;
17267
17268     /* Read rest of EEPROM not covered by the checksum. */
17269     for (eep_addr = ADV_EEP_DVC_CTL_BEGIN;
17270          eep_addr < ADV_EEP_MAX_WORD_ADDR;
17271          eep_addr++, wbuf++)
17272     {
17273         *wbuf = AdvReadEEPWord(iop_base, eep_addr);
17274         if (*charfields++) {
17275             *wbuf = le16_to_cpu(*wbuf);
17276         }
17277     }
17278     return chksum;
17279 }
17280
17281 /*
17282  * Read the EEPROM from specified location
17283  */
17284 STATIC ushort __init
17285 AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
17286 {
17287     AdvWriteWordRegister(iop_base, IOPW_EE_CMD,
17288         ASC_EEP_CMD_READ | eep_word_addr);
17289     AdvWaitEEPCmd(iop_base);
17290     return AdvReadWordRegister(iop_base, IOPW_EE_DATA);
17291 }
17292
17293 /*
17294  * Wait for EEPROM command to complete
17295  */
17296 STATIC void __init
17297 AdvWaitEEPCmd(AdvPortAddr iop_base)
17298 {
17299     int eep_delay_ms;
17300
17301     for (eep_delay_ms = 0; eep_delay_ms < ADV_EEP_DELAY_MS; eep_delay_ms++)
17302     {
17303         if (AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE)
17304         {
17305             break;
17306         }
17307         DvcSleepMilliSecond(1);
17308     }
17309     if ((AdvReadWordRegister(iop_base, IOPW_EE_CMD) & ASC_EEP_CMD_DONE) == 0)
17310     {
17311         ASC_ASSERT(0);
17312     }
17313     return;
17314 }
17315
17316 /*
17317  * Write the EEPROM from 'cfg_buf'.
17318  */
17319 void
17320 AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
17321 {
17322     ushort *wbuf;
17323     ushort addr, chksum;
17324     ushort *charfields;
17325
17326     wbuf = (ushort *) cfg_buf;
17327     charfields = (ushort *) &ADVEEP_3550_Config_Field_IsChar;
17328     chksum = 0;
17329
17330     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17331     AdvWaitEEPCmd(iop_base);
17332
17333     /*
17334      * Write EEPROM from word 0 to word 20.
17335      */
17336     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17337          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17338     {
17339         ushort word;
17340
17341         if (*charfields++) {
17342             word = cpu_to_le16(*wbuf);
17343         } else {
17344             word = *wbuf;
17345         }
17346         chksum += *wbuf; /* Checksum is calculated from word values. */
17347         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17348         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17349         AdvWaitEEPCmd(iop_base);
17350         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17351     }
17352
17353     /*
17354      * Write EEPROM checksum at word 21.
17355      */
17356     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17357     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17358     AdvWaitEEPCmd(iop_base);
17359     wbuf++; charfields++;
17360
17361     /*
17362      * Write EEPROM OEM name at words 22 to 29.
17363      */
17364     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17365          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17366     {
17367         ushort word;
17368
17369         if (*charfields++) {
17370             word = cpu_to_le16(*wbuf);
17371         } else {
17372             word = *wbuf;
17373         }
17374         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17375         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17376         AdvWaitEEPCmd(iop_base);
17377     }
17378     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17379     AdvWaitEEPCmd(iop_base);
17380     return;
17381 }
17382
17383 /*
17384  * Write the EEPROM from 'cfg_buf'.
17385  */
17386 void
17387 AdvSet38C0800EEPConfig(AdvPortAddr iop_base,
17388                        ADVEEP_38C0800_CONFIG *cfg_buf)
17389 {
17390     ushort *wbuf;
17391     ushort *charfields;
17392     ushort addr, chksum;
17393
17394     wbuf = (ushort *) cfg_buf;
17395     charfields = (ushort *) &ADVEEP_38C0800_Config_Field_IsChar;
17396     chksum = 0;
17397
17398     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17399     AdvWaitEEPCmd(iop_base);
17400
17401     /*
17402      * Write EEPROM from word 0 to word 20.
17403      */
17404     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17405          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17406     {
17407         ushort word;
17408
17409         if (*charfields++) {
17410             word = cpu_to_le16(*wbuf);
17411         } else {
17412             word = *wbuf;
17413         }
17414         chksum += *wbuf; /* Checksum is calculated from word values. */
17415         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17416         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17417         AdvWaitEEPCmd(iop_base);
17418         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17419     }
17420
17421     /*
17422      * Write EEPROM checksum at word 21.
17423      */
17424     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17425     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17426     AdvWaitEEPCmd(iop_base);
17427     wbuf++; charfields++;
17428
17429     /*
17430      * Write EEPROM OEM name at words 22 to 29.
17431      */
17432     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17433          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17434     {
17435         ushort word;
17436
17437         if (*charfields++) {
17438             word = cpu_to_le16(*wbuf);
17439         } else {
17440             word = *wbuf;
17441         }
17442         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17443         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17444         AdvWaitEEPCmd(iop_base);
17445     }
17446     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17447     AdvWaitEEPCmd(iop_base);
17448     return;
17449 }
17450
17451 /*
17452  * Write the EEPROM from 'cfg_buf'.
17453  */
17454 void
17455 AdvSet38C1600EEPConfig(AdvPortAddr iop_base,
17456                        ADVEEP_38C1600_CONFIG *cfg_buf)
17457 {
17458     ushort              *wbuf;
17459     ushort              *charfields;
17460     ushort              addr, chksum;
17461
17462     wbuf = (ushort *) cfg_buf;
17463     charfields = (ushort *) &ADVEEP_38C1600_Config_Field_IsChar;
17464     chksum = 0;
17465
17466     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_ABLE);
17467     AdvWaitEEPCmd(iop_base);
17468
17469     /*
17470      * Write EEPROM from word 0 to word 20.
17471      */
17472     for (addr = ADV_EEP_DVC_CFG_BEGIN;
17473          addr < ADV_EEP_DVC_CFG_END; addr++, wbuf++)
17474     {
17475         ushort word;
17476
17477         if (*charfields++) {
17478             word = cpu_to_le16(*wbuf);
17479         } else {
17480             word = *wbuf;
17481         }
17482         chksum += *wbuf; /* Checksum is calculated from word values. */
17483         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17484         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17485         AdvWaitEEPCmd(iop_base);
17486         DvcSleepMilliSecond(ADV_EEP_DELAY_MS);
17487     }
17488
17489     /*
17490      * Write EEPROM checksum at word 21.
17491      */
17492     AdvWriteWordRegister(iop_base, IOPW_EE_DATA, chksum);
17493     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17494     AdvWaitEEPCmd(iop_base);
17495     wbuf++; charfields++;
17496
17497     /*
17498      * Write EEPROM OEM name at words 22 to 29.
17499      */
17500     for (addr = ADV_EEP_DVC_CTL_BEGIN;
17501          addr < ADV_EEP_MAX_WORD_ADDR; addr++, wbuf++)
17502     {
17503         ushort word;
17504
17505         if (*charfields++) {
17506             word = cpu_to_le16(*wbuf);
17507         } else {
17508             word = *wbuf;
17509         }
17510         AdvWriteWordRegister(iop_base, IOPW_EE_DATA, word);
17511         AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE | addr);
17512         AdvWaitEEPCmd(iop_base);
17513     }
17514     AdvWriteWordRegister(iop_base, IOPW_EE_CMD, ASC_EEP_CMD_WRITE_DISABLE);
17515     AdvWaitEEPCmd(iop_base);
17516     return;
17517 }
17518
17519 /* a_advlib.c */
17520 /*
17521  * AdvExeScsiQueue() - Send a request to the RISC microcode program.
17522  *
17523  *   Allocate a carrier structure, point the carrier to the ADV_SCSI_REQ_Q,
17524  *   add the carrier to the ICQ (Initiator Command Queue), and tickle the
17525  *   RISC to notify it a new command is ready to be executed.
17526  *
17527  * If 'done_status' is not set to QD_DO_RETRY, then 'error_retry' will be
17528  * set to SCSI_MAX_RETRY.
17529  *
17530  * Multi-byte fields in the ASC_SCSI_REQ_Q that are used by the microcode
17531  * for DMA addresses or math operations are byte swapped to little-endian
17532  * order.
17533  *
17534  * Return:
17535  *      ADV_SUCCESS(1) - The request was successfully queued.
17536  *      ADV_BUSY(0) -    Resource unavailable; Retry again after pending
17537  *                       request completes.
17538  *      ADV_ERROR(-1) -  Invalid ADV_SCSI_REQ_Q request structure
17539  *                       host IC error.
17540  */
17541 STATIC int
17542 AdvExeScsiQueue(ADV_DVC_VAR *asc_dvc,
17543                 ADV_SCSI_REQ_Q *scsiq)
17544 {
17545     ulong                  last_int_level;
17546     AdvPortAddr            iop_base;
17547     ADV_DCNT               req_size;
17548     ADV_PADDR              req_paddr;
17549     ADV_CARR_T             *new_carrp;
17550
17551     ASC_ASSERT(scsiq != NULL); /* 'scsiq' should never be NULL. */
17552
17553     /*
17554      * The ADV_SCSI_REQ_Q 'target_id' field should never exceed ADV_MAX_TID.
17555      */
17556     if (scsiq->target_id > ADV_MAX_TID)
17557     {
17558         scsiq->host_status = QHSTA_M_INVALID_DEVICE;
17559         scsiq->done_status = QD_WITH_ERROR;
17560         return ADV_ERROR;
17561     }
17562
17563     iop_base = asc_dvc->iop_base;
17564
17565     last_int_level = DvcEnterCritical();
17566
17567     /*
17568      * Allocate a carrier ensuring at least one carrier always
17569      * remains on the freelist and initialize fields.
17570      */
17571     if ((new_carrp = asc_dvc->carr_freelist) == NULL)
17572     {
17573        DvcLeaveCritical(last_int_level);
17574        return ADV_BUSY;
17575     }
17576     asc_dvc->carr_freelist = (ADV_CARR_T *)
17577         ADV_U32_TO_VADDR(le32_to_cpu(new_carrp->next_vpa));
17578     asc_dvc->carr_pending_cnt++;
17579
17580     /*
17581      * Set the carrier to be a stopper by setting 'next_vpa'
17582      * to the stopper value. The current stopper will be changed
17583      * below to point to the new stopper.
17584      */
17585     new_carrp->next_vpa = cpu_to_le32(ASC_CQ_STOPPER);
17586
17587     /*
17588      * Clear the ADV_SCSI_REQ_Q done flag.
17589      */
17590     scsiq->a_flag &= ~ADV_SCSIQ_DONE;
17591
17592     req_size = sizeof(ADV_SCSI_REQ_Q);
17593     req_paddr = DvcGetPhyAddr(asc_dvc, scsiq, (uchar *) scsiq,
17594         (ADV_SDCNT *) &req_size, ADV_IS_SCSIQ_FLAG);
17595
17596     ASC_ASSERT(ADV_32BALIGN(req_paddr) == req_paddr);
17597     ASC_ASSERT(req_size >= sizeof(ADV_SCSI_REQ_Q));
17598
17599     /* Wait for assertion before making little-endian */
17600     req_paddr = cpu_to_le32(req_paddr);
17601
17602     /* Save virtual and physical address of ADV_SCSI_REQ_Q and carrier. */
17603     scsiq->scsiq_ptr = cpu_to_le32(ADV_VADDR_TO_U32(scsiq));
17604     scsiq->scsiq_rptr = req_paddr;
17605
17606     scsiq->carr_va = cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->icq_sp));
17607     /*
17608      * Every ADV_CARR_T.carr_pa is byte swapped to little-endian
17609      * order during initialization.
17610      */
17611     scsiq->carr_pa = asc_dvc->icq_sp->carr_pa;
17612
17613    /*
17614     * Use the current stopper to send the ADV_SCSI_REQ_Q command to
17615     * the microcode. The newly allocated stopper will become the new
17616     * stopper.
17617     */
17618     asc_dvc->icq_sp->areq_vpa = req_paddr;
17619
17620     /*
17621      * Set the 'next_vpa' pointer for the old stopper to be the
17622      * physical address of the new stopper. The RISC can only
17623      * follow physical addresses.
17624      */
17625     asc_dvc->icq_sp->next_vpa = new_carrp->carr_pa;
17626
17627     /*
17628      * Set the host adapter stopper pointer to point to the new carrier.
17629      */
17630     asc_dvc->icq_sp = new_carrp;
17631
17632     if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17633         asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17634     {
17635         /*
17636          * Tickle the RISC to tell it to read its Command Queue Head pointer.
17637          */
17638         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17639         if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17640         {
17641             /*
17642              * Clear the tickle value. In the ASC-3550 the RISC flag
17643              * command 'clr_tickle_a' does not work unless the host
17644              * value is cleared.
17645              */
17646             AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17647         }
17648     } else if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17649     {
17650         /*
17651          * Notify the RISC a carrier is ready by writing the physical
17652          * address of the new carrier stopper to the COMMA register.
17653          */
17654         AdvWriteDWordRegister(iop_base, IOPDW_COMMA,
17655                 le32_to_cpu(new_carrp->carr_pa));
17656     }
17657
17658     DvcLeaveCritical(last_int_level);
17659
17660     return ADV_SUCCESS;
17661 }
17662
17663 /*
17664  * Reset SCSI Bus and purge all outstanding requests.
17665  *
17666  * Return Value:
17667  *      ADV_TRUE(1) -   All requests are purged and SCSI Bus is reset.
17668  *      ADV_FALSE(0) -  Microcode command failed.
17669  *      ADV_ERROR(-1) - Microcode command timed-out. Microcode or IC
17670  *                      may be hung which requires driver recovery.
17671  */
17672 STATIC int
17673 AdvResetSB(ADV_DVC_VAR *asc_dvc)
17674 {
17675     int         status;
17676
17677     /*
17678      * Send the SCSI Bus Reset idle start idle command which asserts
17679      * the SCSI Bus Reset signal.
17680      */
17681     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_START, 0L);
17682     if (status != ADV_TRUE)
17683     {
17684         return status;
17685     }
17686
17687     /*
17688      * Delay for the specified SCSI Bus Reset hold time.
17689      *
17690      * The hold time delay is done on the host because the RISC has no
17691      * microsecond accurate timer.
17692      */
17693     DvcDelayMicroSecond(asc_dvc, (ushort) ASC_SCSI_RESET_HOLD_TIME_US);
17694
17695     /*
17696      * Send the SCSI Bus Reset end idle command which de-asserts
17697      * the SCSI Bus Reset signal and purges any pending requests.
17698      */
17699     status = AdvSendIdleCmd(asc_dvc, (ushort) IDLE_CMD_SCSI_RESET_END, 0L);
17700     if (status != ADV_TRUE)
17701     {
17702         return status;
17703     }
17704
17705     DvcSleepMilliSecond((ADV_DCNT) asc_dvc->scsi_reset_wait * 1000);
17706
17707     return status;
17708 }
17709
17710 /*
17711  * Reset chip and SCSI Bus.
17712  *
17713  * Return Value:
17714  *      ADV_TRUE(1) -   Chip re-initialization and SCSI Bus Reset successful.
17715  *      ADV_FALSE(0) -  Chip re-initialization and SCSI Bus Reset failure.
17716  */
17717 STATIC int
17718 AdvResetChipAndSB(ADV_DVC_VAR *asc_dvc)
17719 {
17720     int         status;
17721     ushort      wdtr_able, sdtr_able, tagqng_able;
17722     ushort      ppr_able = 0;
17723     uchar       tid, max_cmd[ADV_MAX_TID + 1];
17724     AdvPortAddr iop_base;
17725     ushort      bios_sig;
17726
17727     iop_base = asc_dvc->iop_base;
17728
17729     /*
17730      * Save current per TID negotiated values.
17731      */
17732     AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17733     AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17734     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17735     {
17736         AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17737     }
17738     AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17739     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17740     {
17741         AdvReadByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17742             max_cmd[tid]);
17743     }
17744
17745     /*
17746      * Force the AdvInitAsc3550/38C0800Driver() function to
17747      * perform a SCSI Bus Reset by clearing the BIOS signature word.
17748      * The initialization functions assumes a SCSI Bus Reset is not
17749      * needed if the BIOS signature word is present.
17750      */
17751     AdvReadWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17752     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, 0);
17753
17754     /*
17755      * Stop chip and reset it.
17756      */
17757     AdvWriteWordRegister(iop_base, IOPW_RISC_CSR, ADV_RISC_CSR_STOP);
17758     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_RESET);
17759     DvcSleepMilliSecond(100);
17760     AdvWriteWordRegister(iop_base, IOPW_CTRL_REG, ADV_CTRL_REG_CMD_WR_IO_REG);
17761
17762     /*
17763      * Reset Adv Library error code, if any, and try
17764      * re-initializing the chip.
17765      */
17766     asc_dvc->err_code = 0;
17767     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17768     {
17769         status = AdvInitAsc38C1600Driver(asc_dvc);
17770     }
17771     else if (asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17772     {
17773         status = AdvInitAsc38C0800Driver(asc_dvc);
17774     } else
17775     {
17776         status = AdvInitAsc3550Driver(asc_dvc);
17777     }
17778
17779     /* Translate initialization return value to status value. */
17780     if (status == 0)
17781     {
17782         status = ADV_TRUE;
17783     } else
17784     {
17785         status = ADV_FALSE;
17786     }
17787
17788     /*
17789      * Restore the BIOS signature word.
17790      */
17791     AdvWriteWordLram(iop_base, ASC_MC_BIOS_SIGNATURE, bios_sig);
17792
17793     /*
17794      * Restore per TID negotiated values.
17795      */
17796     AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, wdtr_able);
17797     AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, sdtr_able);
17798     if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600)
17799     {
17800         AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, ppr_able);
17801     }
17802     AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, tagqng_able);
17803     for (tid = 0; tid <= ADV_MAX_TID; tid++)
17804     {
17805         AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
17806             max_cmd[tid]);
17807     }
17808
17809     return status;
17810 }
17811
17812 /*
17813  * Adv Library Interrupt Service Routine
17814  *
17815  *  This function is called by a driver's interrupt service routine.
17816  *  The function disables and re-enables interrupts.
17817  *
17818  *  When a microcode idle command is completed, the ADV_DVC_VAR
17819  *  'idle_cmd_done' field is set to ADV_TRUE.
17820  *
17821  *  Note: AdvISR() can be called when interrupts are disabled or even
17822  *  when there is no hardware interrupt condition present. It will
17823  *  always check for completed idle commands and microcode requests.
17824  *  This is an important feature that shouldn't be changed because it
17825  *  allows commands to be completed from polling mode loops.
17826  *
17827  * Return:
17828  *   ADV_TRUE(1) - interrupt was pending
17829  *   ADV_FALSE(0) - no interrupt was pending
17830  */
17831 STATIC int
17832 AdvISR(ADV_DVC_VAR *asc_dvc)
17833 {
17834     AdvPortAddr                 iop_base;
17835     uchar                       int_stat;
17836     ushort                      target_bit;
17837     ADV_CARR_T                  *free_carrp;
17838     ADV_VADDR                   irq_next_vpa;
17839     int                         flags;
17840     ADV_SCSI_REQ_Q              *scsiq;
17841
17842     flags = DvcEnterCritical();
17843
17844     iop_base = asc_dvc->iop_base;
17845
17846     /* Reading the register clears the interrupt. */
17847     int_stat = AdvReadByteRegister(iop_base, IOPB_INTR_STATUS_REG);
17848
17849     if ((int_stat & (ADV_INTR_STATUS_INTRA | ADV_INTR_STATUS_INTRB |
17850          ADV_INTR_STATUS_INTRC)) == 0)
17851     {
17852         DvcLeaveCritical(flags);
17853         return ADV_FALSE;
17854     }
17855
17856     /*
17857      * Notify the driver of an asynchronous microcode condition by
17858      * calling the ADV_DVC_VAR.async_callback function. The function
17859      * is passed the microcode ASC_MC_INTRB_CODE byte value.
17860      */
17861     if (int_stat & ADV_INTR_STATUS_INTRB)
17862     {
17863         uchar intrb_code;
17864
17865         AdvReadByteLram(iop_base, ASC_MC_INTRB_CODE, intrb_code);
17866
17867         if (asc_dvc->chip_type == ADV_CHIP_ASC3550 ||
17868             asc_dvc->chip_type == ADV_CHIP_ASC38C0800)
17869         {
17870             if (intrb_code == ADV_ASYNC_CARRIER_READY_FAILURE &&
17871                 asc_dvc->carr_pending_cnt != 0)
17872             {
17873                 AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_A);
17874                 if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
17875                 {
17876                     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
17877                 }
17878             }
17879         }
17880
17881         if (asc_dvc->async_callback != 0)
17882         {
17883             (*asc_dvc->async_callback)(asc_dvc, intrb_code);
17884         }
17885     }
17886
17887     /*
17888      * Check if the IRQ stopper carrier contains a completed request.
17889      */
17890     while (((irq_next_vpa =
17891              le32_to_cpu(asc_dvc->irq_sp->next_vpa)) & ASC_RQ_DONE) != 0)
17892     {
17893         /*
17894          * Get a pointer to the newly completed ADV_SCSI_REQ_Q structure.
17895          * The RISC will have set 'areq_vpa' to a virtual address.
17896          *
17897          * The firmware will have copied the ASC_SCSI_REQ_Q.scsiq_ptr
17898          * field to the carrier ADV_CARR_T.areq_vpa field. The conversion
17899          * below complements the conversion of ASC_SCSI_REQ_Q.scsiq_ptr'
17900          * in AdvExeScsiQueue().
17901          */
17902         scsiq = (ADV_SCSI_REQ_Q *)
17903             ADV_U32_TO_VADDR(le32_to_cpu(asc_dvc->irq_sp->areq_vpa));
17904
17905         /*
17906          * Request finished with good status and the queue was not
17907          * DMAed to host memory by the firmware. Set all status fields
17908          * to indicate good status.
17909          */
17910         if ((irq_next_vpa & ASC_RQ_GOOD) != 0)
17911         {
17912             scsiq->done_status = QD_NO_ERROR;
17913             scsiq->host_status = scsiq->scsi_status = 0;
17914             scsiq->data_cnt = 0L;
17915         }
17916
17917         /*
17918          * Advance the stopper pointer to the next carrier
17919          * ignoring the lower four bits. Free the previous
17920          * stopper carrier.
17921          */
17922         free_carrp = asc_dvc->irq_sp;
17923         asc_dvc->irq_sp = (ADV_CARR_T *)
17924             ADV_U32_TO_VADDR(ASC_GET_CARRP(irq_next_vpa));
17925
17926         free_carrp->next_vpa =
17927                 cpu_to_le32(ADV_VADDR_TO_U32(asc_dvc->carr_freelist));
17928         asc_dvc->carr_freelist = free_carrp;
17929         asc_dvc->carr_pending_cnt--;
17930
17931         ASC_ASSERT(scsiq != NULL);
17932         target_bit = ADV_TID_TO_TIDMASK(scsiq->target_id);
17933
17934         /*
17935          * Clear request microcode control flag.
17936          */
17937         scsiq->cntl = 0;
17938
17939         /*
17940          * If the command that completed was a SCSI INQUIRY and
17941          * LUN 0 was sent the command, then process the INQUIRY
17942          * command information for the device.
17943          *
17944          * Note: If data returned were either VPD or CmdDt data,
17945          * don't process the INQUIRY command information for
17946          * the device, otherwise may erroneously set *_able bits.
17947          */
17948         if (scsiq->done_status == QD_NO_ERROR &&
17949             scsiq->cdb[0] == INQUIRY &&
17950             scsiq->target_lun == 0 &&
17951             (scsiq->cdb[1] & ADV_INQ_RTN_VPD_AND_CMDDT)
17952                 == ADV_INQ_RTN_STD_INQUIRY_DATA)
17953         {
17954             AdvInquiryHandling(asc_dvc, scsiq);
17955         }
17956
17957         /*
17958          * Notify the driver of the completed request by passing
17959          * the ADV_SCSI_REQ_Q pointer to its callback function.
17960          */
17961         scsiq->a_flag |= ADV_SCSIQ_DONE;
17962         (*asc_dvc->isr_callback)(asc_dvc, scsiq);
17963         /*
17964          * Note: After the driver callback function is called, 'scsiq'
17965          * can no longer be referenced.
17966          *
17967          * Fall through and continue processing other completed
17968          * requests...
17969          */
17970
17971         /*
17972          * Disable interrupts again in case the driver inadvertently
17973          * enabled interrupts in its callback function.
17974          *
17975          * The DvcEnterCritical() return value is ignored, because
17976          * the 'flags' saved when AdvISR() was first entered will be
17977          * used to restore the interrupt flag on exit.
17978          */
17979         (void) DvcEnterCritical();
17980     }
17981     DvcLeaveCritical(flags);
17982     return ADV_TRUE;
17983 }
17984
17985 /*
17986  * Send an idle command to the chip and wait for completion.
17987  *
17988  * Command completion is polled for once per microsecond.
17989  *
17990  * The function can be called from anywhere including an interrupt handler.
17991  * But the function is not re-entrant, so it uses the DvcEnter/LeaveCritical()
17992  * functions to prevent reentrancy.
17993  *
17994  * Return Values:
17995  *   ADV_TRUE - command completed successfully
17996  *   ADV_FALSE - command failed
17997  *   ADV_ERROR - command timed out
17998  */
17999 STATIC int
18000 AdvSendIdleCmd(ADV_DVC_VAR *asc_dvc,
18001                ushort idle_cmd,
18002                ADV_DCNT idle_cmd_parameter)
18003 {
18004     ulong       last_int_level;
18005     int         result;
18006     ADV_DCNT    i, j;
18007     AdvPortAddr iop_base;
18008
18009     last_int_level = DvcEnterCritical();
18010
18011     iop_base = asc_dvc->iop_base;
18012
18013     /*
18014      * Clear the idle command status which is set by the microcode
18015      * to a non-zero value to indicate when the command is completed.
18016      * The non-zero result is one of the IDLE_CMD_STATUS_* values
18017      * defined in a_advlib.h.
18018      */
18019     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, (ushort) 0);
18020
18021     /*
18022      * Write the idle command value after the idle command parameter
18023      * has been written to avoid a race condition. If the order is not
18024      * followed, the microcode may process the idle command before the
18025      * parameters have been written to LRAM.
18026      */
18027     AdvWriteDWordLramNoSwap(iop_base, ASC_MC_IDLE_CMD_PARAMETER,
18028         cpu_to_le32(idle_cmd_parameter));
18029     AdvWriteWordLram(iop_base, ASC_MC_IDLE_CMD, idle_cmd);
18030
18031     /*
18032      * Tickle the RISC to tell it to process the idle command.
18033      */
18034     AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_B);
18035     if (asc_dvc->chip_type == ADV_CHIP_ASC3550)
18036     {
18037         /*
18038          * Clear the tickle value. In the ASC-3550 the RISC flag
18039          * command 'clr_tickle_b' does not work unless the host
18040          * value is cleared.
18041          */
18042         AdvWriteByteRegister(iop_base, IOPB_TICKLE, ADV_TICKLE_NOP);
18043     }
18044
18045     /* Wait for up to 100 millisecond for the idle command to timeout. */
18046     for (i = 0; i < SCSI_WAIT_100_MSEC; i++)
18047     {
18048         /* Poll once each microsecond for command completion. */
18049         for (j = 0; j < SCSI_US_PER_MSEC; j++)
18050         {
18051             AdvReadWordLram(iop_base, ASC_MC_IDLE_CMD_STATUS, result);
18052             if (result != 0)
18053             {
18054                 DvcLeaveCritical(last_int_level);
18055                 return result;
18056             }
18057             DvcDelayMicroSecond(asc_dvc, (ushort) 1);
18058         }
18059     }
18060
18061     ASC_ASSERT(0); /* The idle command should never timeout. */
18062     DvcLeaveCritical(last_int_level);
18063     return ADV_ERROR;
18064 }
18065
18066 /*
18067  * Inquiry Information Byte 7 Handling
18068  *
18069  * Handle SCSI Inquiry Command information for a device by setting
18070  * microcode operating variables that affect WDTR, SDTR, and Tag
18071  * Queuing.
18072  */
18073 STATIC void
18074 AdvInquiryHandling(
18075     ADV_DVC_VAR                 *asc_dvc,
18076     ADV_SCSI_REQ_Q              *scsiq)
18077 {
18078     AdvPortAddr                 iop_base;
18079     uchar                       tid;
18080     ADV_SCSI_INQUIRY            *inq;
18081     ushort                      tidmask;
18082     ushort                      cfg_word;
18083
18084     /*
18085      * AdvInquiryHandling() requires up to INQUIRY information Byte 7
18086      * to be available.
18087      *
18088      * If less than 8 bytes of INQUIRY information were requested or less
18089      * than 8 bytes were transferred, then return. cdb[4] is the request
18090      * length and the ADV_SCSI_REQ_Q 'data_cnt' field is set by the
18091      * microcode to the transfer residual count.
18092      */
18093
18094     if (scsiq->cdb[4] < 8 ||
18095         (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) < 8)
18096     {
18097         return;
18098     }
18099
18100     iop_base = asc_dvc->iop_base;
18101     tid = scsiq->target_id;
18102
18103     inq = (ADV_SCSI_INQUIRY *) scsiq->vdata_addr;
18104
18105     /*
18106      * WDTR, SDTR, and Tag Queuing cannot be enabled for old devices.
18107      */
18108     if (ADV_INQ_RESPONSE_FMT(inq) < 2 && ADV_INQ_ANSI_VER(inq) < 2)
18109     {
18110         return;
18111     } else
18112     {
18113         /*
18114          * INQUIRY Byte 7 Handling
18115          *
18116          * Use a device's INQUIRY byte 7 to determine whether it
18117          * supports WDTR, SDTR, and Tag Queuing. If the feature
18118          * is enabled in the EEPROM and the device supports the
18119          * feature, then enable it in the microcode.
18120          */
18121
18122         tidmask = ADV_TID_TO_TIDMASK(tid);
18123
18124         /*
18125          * Wide Transfers
18126          *
18127          * If the EEPROM enabled WDTR for the device and the device
18128          * supports wide bus (16 bit) transfers, then turn on the
18129          * device's 'wdtr_able' bit and write the new value to the
18130          * microcode.
18131          */
18132         if ((asc_dvc->wdtr_able & tidmask) && ADV_INQ_WIDE16(inq))
18133         {
18134             AdvReadWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18135             if ((cfg_word & tidmask) == 0)
18136             {
18137                 cfg_word |= tidmask;
18138                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_ABLE, cfg_word);
18139
18140                 /*
18141                  * Clear the microcode "SDTR negotiation" and "WDTR
18142                  * negotiation" done indicators for the target to cause
18143                  * it to negotiate with the new setting set above.
18144                  * WDTR when accepted causes the target to enter
18145                  * asynchronous mode, so SDTR must be negotiated.
18146                  */
18147                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18148                 cfg_word &= ~tidmask;
18149                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18150                 AdvReadWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18151                 cfg_word &= ~tidmask;
18152                 AdvWriteWordLram(iop_base, ASC_MC_WDTR_DONE, cfg_word);
18153             }
18154         }
18155
18156         /*
18157          * Synchronous Transfers
18158          *
18159          * If the EEPROM enabled SDTR for the device and the device
18160          * supports synchronous transfers, then turn on the device's
18161          * 'sdtr_able' bit. Write the new value to the microcode.
18162          */
18163         if ((asc_dvc->sdtr_able & tidmask) && ADV_INQ_SYNC(inq))
18164         {
18165             AdvReadWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18166             if ((cfg_word & tidmask) == 0)
18167             {
18168                 cfg_word |= tidmask;
18169                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_ABLE, cfg_word);
18170
18171                 /*
18172                  * Clear the microcode "SDTR negotiation" done indicator
18173                  * for the target to cause it to negotiate with the new
18174                  * setting set above.
18175                  */
18176                 AdvReadWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18177                 cfg_word &= ~tidmask;
18178                 AdvWriteWordLram(iop_base, ASC_MC_SDTR_DONE, cfg_word);
18179             }
18180         }
18181         /*
18182          * If the Inquiry data included enough space for the SPI-3
18183          * Clocking field, then check if DT mode is supported.
18184          */
18185         if (asc_dvc->chip_type == ADV_CHIP_ASC38C1600 &&
18186             (scsiq->cdb[4] >= 57 ||
18187             (scsiq->cdb[4] - le32_to_cpu(scsiq->data_cnt)) >= 57))
18188         {
18189             /*
18190              * PPR (Parallel Protocol Request) Capable
18191              *
18192              * If the device supports DT mode, then it must be PPR capable.
18193              * The PPR message will be used in place of the SDTR and WDTR
18194              * messages to negotiate synchronous speed and offset, transfer
18195              * width, and protocol options.
18196              */
18197             if (ADV_INQ_CLOCKING(inq) & ADV_INQ_CLOCKING_DT_ONLY)
18198             {
18199                 AdvReadWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18200                 asc_dvc->ppr_able |= tidmask;
18201                 AdvWriteWordLram(iop_base, ASC_MC_PPR_ABLE, asc_dvc->ppr_able);
18202             }
18203         }
18204
18205         /*
18206          * If the EEPROM enabled Tag Queuing for the device and the
18207          * device supports Tag Queueing, then turn on the device's
18208          * 'tagqng_enable' bit in the microcode and set the microcode
18209          * maximum command count to the ADV_DVC_VAR 'max_dvc_qng'
18210          * value.
18211          *
18212          * Tag Queuing is disabled for the BIOS which runs in polled
18213          * mode and would see no benefit from Tag Queuing. Also by
18214          * disabling Tag Queuing in the BIOS devices with Tag Queuing
18215          * bugs will at least work with the BIOS.
18216          */
18217         if ((asc_dvc->tagqng_able & tidmask) && ADV_INQ_CMD_QUEUE(inq))
18218         {
18219             AdvReadWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18220             cfg_word |= tidmask;
18221             AdvWriteWordLram(iop_base, ASC_MC_TAGQNG_ABLE, cfg_word);
18222
18223             AdvWriteByteLram(iop_base, ASC_MC_NUMBER_OF_MAX_CMD + tid,
18224                 asc_dvc->max_dvc_qng);
18225         }
18226     }
18227 }
18228 MODULE_LICENSE("Dual BSD/GPL");