diff options
| author | Justin T. Gibbs <gibbs@FreeBSD.org> | 1994-11-17 20:19:10 +0000 |
|---|---|---|
| committer | Justin T. Gibbs <gibbs@FreeBSD.org> | 1994-11-17 20:19:10 +0000 |
| commit | 0ef8c3017a8f5d67c947fc18677f9010eccaefb9 (patch) | |
| tree | 28001044e7108b7ed14f673b8980c7013b9be4d2 /sys/gnu | |
| parent | 5007f4061c168cdfe3cdec01f566bf7e82ea70c2 (diff) | |
Notes
Diffstat (limited to 'sys/gnu')
| -rw-r--r-- | sys/gnu/misc/aic7770/COPYING | 339 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/COPYRIGHT | 16 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/README | 94 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/README-FIRST | 19 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/aic7770.1 | 54 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/aic7770.c | 584 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7770/aic7770.seq | 1064 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/COPYING | 339 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/COPYRIGHT | 16 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/README | 94 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/README-FIRST | 19 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/aic7xxx.1 | 54 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/aic7xxx.c | 584 | ||||
| -rw-r--r-- | sys/gnu/misc/aic7xxx/aic7xxx.seq | 1064 |
14 files changed, 4340 insertions, 0 deletions
diff --git a/sys/gnu/misc/aic7770/COPYING b/sys/gnu/misc/aic7770/COPYING new file mode 100644 index 0000000000000..a43ea2126fb6b --- /dev/null +++ b/sys/gnu/misc/aic7770/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) 19yy <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/sys/gnu/misc/aic7770/COPYRIGHT b/sys/gnu/misc/aic7770/COPYRIGHT new file mode 100644 index 0000000000000..905285da67595 --- /dev/null +++ b/sys/gnu/misc/aic7770/COPYRIGHT @@ -0,0 +1,16 @@ +Adaptec 274x device driver for Linux. +Copyright (c) 1994 The University of Calgary Department of Computer Science. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/sys/gnu/misc/aic7770/README b/sys/gnu/misc/aic7770/README new file mode 100644 index 0000000000000..1e4e5a011a697 --- /dev/null +++ b/sys/gnu/misc/aic7770/README @@ -0,0 +1,94 @@ +@(#)README 1.16 94/11/09 jda + +AHA274x/284x DRIVER + +*** THIS SHOULD BE CONSIDERED BETA SOFTWARE *** + +BACKGROUND & LIMITATIONS + +For various reasons, we ended up with one of these cards under the +impression that support was soon forthcoming. In mid-May, I asked +Scott Ferris (the official person who's supposed to be writing this +driver) what documentation he used, _finally_ got it from Adaptec, +and started writing this driver. It is now at what I would consider +a stable state - it runs our news server and is battered by SCSI +requests 24 hours a day without dying. There are a few devices it +reportedly doesn't like working with - those are being sorted out. Due +to some unexpected equipment loans, I am able to support this at least +for the time being. + +YOU MUST HAVE THE BIOS ENABLED OR THIS WILL NOT WORK. The BIOS extracts +some configuration information that I cannot get to portably yet, as +well as provides some self-tests which this driver does not attempt to +duplicate. + +Scott's driver development is stalled for now, and after discussions +with him, this is now officially out of "pre-alpha" status and into +beta until the remaining device problems can be resolved. The latest +patches can be obtained via anonymous ftp from ftp.cpsc.ucalgary.ca in +/pub/systems/linux/aha274x. + +It supports both EISA 274x and VL-bus 284x, either single or twin-bus cards +(but not the second SCSI bus of twin cards - see aha274x.c), and supports +disconnection, synchronous SCSI, and scatter-gather. Unlike previous +versions, abort() and reset() are now implemented, and both hosts.c and +aha274x.c should give a clean compile. Code is now present to detect parity +errors, but has not been tested. + +I wrote this using a 1.0.9 kernel. Unfortunately, I'm getting tired of +#ifdef'ing everything to handle two or three different evolutionary steps +in the SCSI kernel code, so I've upgraded my system to 1.1.49, and will +only leave in code to support versions from about 1.1.45 onward. + +Thanks to patches supplied by Mark Olson <molson@tricord.com>, this driver +will now work with the 284x series (the VL-bus version of this card). The +294x (PCI-bus) support is based on patches sent to me by Mark Olson and +Alan Hourihane <alanh@fairlite.demon.co.uk>. + +Under protest, this driver is subject to the GPL - see the file +COPYING for details. + +Thanks to the following people for bug fixes/code improvements (also +thanks to the people who have sent me feedback): + + "David F. Carlson" <dave@ee.rochester.edu> + Jimen Ching <jiching@wiliki.eng.hawaii.edu> + mday@artisoft.com (Matt Day) + "Dean W. Gehnert" <deang@ims.com> + Darcy Grant <darcy@cpsc.ucalgary.ca> + Alan Hourihane <alanh@fairlite.demon.co.uk> + isely@fncrd8.fnal.gov (Mike Isely) + Mike Jerger <jerger@ux1.cso.uiuc.edu> + tm@netcom.com (Toshiyasu Morita) + neal@interact.org (Neal Norwitz) + Mark Olson <molson@tricord.com> + map@europa.ecn.uoknor.edu (Michael A. Parker) + Thomas Scheunemann <thomas@dagobert.uni-duisburg.de> + +Special thanks to Drew Eckhardt <drew@kinglear.cs.Colorado.EDU> for +fielding my questions about synchronous negotiation. Steffen Moeller +<smoe0024@rz.uni-hildesheim.de> sent me installation instructions which +were previously included in this README. + +David Pirie <pirie@cpsc.ucalgary.ca> was nice enough to loan me his +2842 card for a week so I could track down one bug, as well as his +CD-ROM drive later, and also thanks to Doug Fortune at Riley's Data Share +in Calgary, who arranged a long-term loan of a 2842 board for further work. + +Many thanks to the fearless prerelease testers! Dean Gehnert has been +building Slackware boot disks for the driver, which are available from +ftp.cpsc.ucalgary.ca in /pub/systems/linux/aha274x/slackware_boot. + +Carl Riches <cgr@poplar1.cfr.washington.edu> has set up a mailing list +for aic7xxx driver development. To subscribe, send a message to +aic7770-list@poplar1.cfr.washington.edu with a message body of: + + subscribe AIC7770-LIST <your name here, without the angle brackets> + +Please direct questions and discussions to that list instead of me. When +sending bug reports, please include a description of your hardware, the +release numbers displayed by the driver at boot time, and as accurate a +facsimilie of any error message you're mailing about. + +John Aycock +aycock@cpsc.ucalgary.ca diff --git a/sys/gnu/misc/aic7770/README-FIRST b/sys/gnu/misc/aic7770/README-FIRST new file mode 100644 index 0000000000000..056dbc82cd614 --- /dev/null +++ b/sys/gnu/misc/aic7770/README-FIRST @@ -0,0 +1,19 @@ +This is VERY MUCH ALPHA SOFTWARE. You MUST know what you're doing to +use this, or else!!! + +Ok, everything's been renamed to reference an "aic7xxx" driver instead +of "aha274x", and a merger of the two PCI patches I had has been put in, +along with re-doing the detection and configuration routines. To summarize +the status: it compiles cleanly. I don't expect it to work off the bat, +but it's for the 294x development people to synchronize their code +together. + +The file scsi-diffs-1.1.59 is NOT a proper patch file, but some diffs +to kernel files concatenated together. I've sent these off to Drew, +but if you're testing this you'll have to apply them - it allows a +per-driver-instance can_queue variable, which for the aic7xxx driver +is the number of SCBs the card supports. + +Good luck! I await your comments.. Mark, Alan - let me know where I +broke it, please ;-) +:ja diff --git a/sys/gnu/misc/aic7770/aic7770.1 b/sys/gnu/misc/aic7770/aic7770.1 new file mode 100644 index 0000000000000..2009f8c7ad6ec --- /dev/null +++ b/sys/gnu/misc/aic7770/aic7770.1 @@ -0,0 +1,54 @@ +.\" Copyright (c) 1994 +.\" Justin T. Gibbs. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Justin T. Gibbs. +.\" 4. The name of Justin T. Gibbs may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JUSTIN T. GIBBS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)aic7770.1 11/15/94 +.\" +.Dd November 11, 1994 +.Dt AIC7770 1 +.Os BSD 4 +.Sh NAME +.Nm aic7770 +.Nd aic7770 SCSI controller assembler +.Sh SYNOPSIS +.Nm aic7770 +.Op Fl o destination +.Ar source-file +.Sh DESCRIPTION +.Ar Source-file +is a file containing Aic7770 compatible assembly code. The output of the +assembler defaults to +.Ar a.out +but can be optionally redirected to +.Ar destination. +.Pp +.Sh AUTHOR +This aic7770 compiler was written by John Aycock (aycock@cpsc.ucalgary.ca) and +is subject to the GNU Public License. + diff --git a/sys/gnu/misc/aic7770/aic7770.c b/sys/gnu/misc/aic7770/aic7770.c new file mode 100644 index 0000000000000..417a352762d31 --- /dev/null +++ b/sys/gnu/misc/aic7770/aic7770.c @@ -0,0 +1,584 @@ +/* + * Adaptec 274x device driver for Linux. + * Copyright (c) 1994 The University of Calgary Department of Computer Science. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Comments are started by `#' and continue to the end of the line; lines + * may be of the form: + * + * <label>* + * <label>* <undef-sym> = <value> + * <label>* <opcode> <operand>* + * + * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas + * are token separators. + */ + +/* #define _POSIX_SOURCE 1 */ +#define _POSIX_C_SOURCE 2 + +#include <ctype.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#define MEMORY 512 /* 2^9 29-bit words */ +#define MAXLINE 1024 +#define MAXTOKEN 32 +#define ADOTOUT "a.out" +#define NOVALUE -1 + +/* + * AIC-7770 register definitions + */ +#define R_SINDEX 0x65 +#define R_ALLONES 0x69 +#define R_ALLZEROS 0x6a +#define R_NONE 0x6a + +static +char sccsid[] = + "@(#)aic7770.c 1.10 94/07/22 jda"; + +int debug; +int lineno, LC; +char *filename; +FILE *ifp, *ofp; +unsigned char M[MEMORY][4]; + +void error(char *s) +{ + fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno); + exit(EXIT_FAILURE); +} + +void *Malloc(size_t size) +{ + void *p = malloc(size); + if (!p) + error("out of memory"); + return(p); +} + +void *Realloc(void *ptr, size_t size) +{ + void *p = realloc(ptr, size); + if (!p) + error("out of memory"); + return(p); +} + +char *Strdup(char *s) +{ + char *p = (char *)Malloc(strlen(s) + 1); + strcpy(p, s); + return(p); +} + +typedef struct sym_t { + struct sym_t *next; /* MUST BE FIRST */ + char *name; + int value; + int npatch, *patch; +} sym_t; + +sym_t *head; + +void define(char *name, int value) +{ + sym_t *p, *q; + + for (p = head, q = (sym_t *)&head; p; p = p->next) { + if (!strcmp(p->name, name)) + error("redefined symbol"); + q = p; + } + + p = q->next = (sym_t *)Malloc(sizeof(sym_t)); + p->next = NULL; + p->name = Strdup(name); + p->value = value; + p->npatch = 0; + p->patch = NULL; + + if (debug) { + fprintf(stderr, "\"%s\" ", p->name); + if (p->value != NOVALUE) + fprintf(stderr, "defined as 0x%x\n", p->value); + else + fprintf(stderr, "undefined\n"); + } +} + +sym_t *lookup(char *name) +{ + sym_t *p; + + for (p = head; p; p = p->next) + if (!strcmp(p->name, name)) + return(p); + return(NULL); +} + +void patch(sym_t *p, int location) +{ + p->npatch += 1; + p->patch = (int *)Realloc(p->patch, p->npatch * sizeof(int *)); + + p->patch[p->npatch - 1] = location; +} + +void backpatch(void) +{ + int i; + sym_t *p; + + for (p = head; p; p = p->next) { + + if (p->value == NOVALUE) { + fprintf(stderr, + "%s: undefined symbol \"%s\"\n", + filename, p->name); + exit(EXIT_FAILURE); + } + + if (p->npatch) { + if (debug) + fprintf(stderr, + "\"%s\" (0x%x) patched at", + p->name, p->value); + + for (i = 0; i < p->npatch; i++) { + M[p->patch[i]][0] &= ~1; + M[p->patch[i]][0] |= ((p->value >> 8) & 1); + M[p->patch[i]][1] = p->value & 0xff; + + if (debug) + fprintf(stderr, " 0x%x", p->patch[i]); + } + + if (debug) + fputc('\n', stderr); + } + } +} + +/* + * Output words in byte-reversed order (least significant first) + * since the sequencer RAM is loaded that way. + */ +void output(FILE *fp) +{ + int i; + + for (i = 0; i < LC; i++) + fprintf(fp, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", + M[i][3], + M[i][2], + M[i][1], + M[i][0]); +} + +char **getl(int *n) +{ + int i; + char *p; + static char buf[MAXLINE]; + static char *a[MAXTOKEN]; + + i = 0; + + while (fgets(buf, sizeof(buf), ifp)) { + + lineno += 1; + + if (buf[strlen(buf)-1] != '\n') + error("line too long"); + + p = strchr(buf, '#'); + if (p) + *p = '\0'; + + for (p = strtok(buf, ", \t\n"); p; p = strtok(NULL, ", \t\n")) + if (i < MAXTOKEN-1) + a[i++] = p; + else + error("too many tokens"); + if (i) { + *n = i; + return(a); + } + } + return(NULL); +} + +#define A 0x8000 /* `A'ccumulator ok */ +#define I 0x4000 /* use as immediate value */ +#define SL 0x2000 /* shift left */ +#define SR 0x1000 /* shift right */ +#define RL 0x0800 /* rotate left */ +#define RR 0x0400 /* rotate right */ +#define LO 0x8000 /* lookup: ori-{jmp,jc,jnc,call} */ +#define LA 0x4000 /* lookup: and-{jz,jnz} */ +#define LX 0x2000 /* lookup: xor-{je,jne} */ +#define NA -1 /* not applicable */ + +struct { + char *name; + int n; /* number of operands, including opcode */ + unsigned int op; /* immediate or L?|pos_from_0 */ + unsigned int dest; /* NA, pos_from_0, or I|immediate */ + unsigned int src; /* NA, pos_from_0, or I|immediate */ + unsigned int imm; /* pos_from_0, A|pos_from_0, or I|immediate */ + unsigned int addr; /* NA or pos_from_0 */ + int fmt; /* instruction format - 1, 2, or 3 */ +} instr[] = { +/* + * N OP DEST SRC IMM ADDR FMT + */ + "mov", 3, 1, 1, 2, I|0xff, NA, 1, + "mov", 4, LO|2, NA, 1, I|0, 3, 3, + "mvi", 3, 0, 1, I|R_ALLZEROS, A|2, NA, 1, + "mvi", 4, LO|2, NA, I|R_ALLZEROS, 1, 3, 3, + "not", 2, 2, 1, 1, I|0xff, NA, 1, + "not", 3, 2, 1, 2, I|0xff, NA, 1, + "and", 3, 1, 1, 1, A|2, NA, 1, + "and", 4, 1, 1, 3, A|2, NA, 1, + "or", 3, 0, 1, 1, A|2, NA, 1, + "or", 4, 0, 1, 3, A|2, NA, 1, + "or", 5, LO|3, NA, 1, 2, 4, 3, + "xor", 3, 2, 1, 1, A|2, NA, 1, + "xor", 4, 2, 1, 3, A|2, NA, 1, + "nop", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, + "inc", 2, 3, 1, 1, I|1, NA, 1, + "inc", 3, 3, 1, 2, I|1, NA, 1, + "dec", 2, 3, 1, 1, I|0xff, NA, 1, + "dec", 3, 3, 1, 2, I|0xff, NA, 1, + "jmp", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "jc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "jnc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "call", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "test", 5, LA|3, NA, 1, A|2, 4, 3, + "cmp", 5, LX|3, NA, 1, A|2, 4, 3, + "ret", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, + "clc", 1, 3, I|R_NONE, I|R_ALLZEROS, I|1, NA, 1, + "clc", 4, 3, 2, I|R_ALLZEROS, A|3, NA, 1, + "stc", 1, 3, I|R_NONE, I|R_ALLONES, I|1, NA, 1, + "stc", 2, 3, 1, I|R_ALLONES, I|1, NA, 1, + "add", 3, 3, 1, 1, A|2, NA, 1, + "add", 4, 3, 1, 3, A|2, NA, 1, + "adc", 3, 4, 1, 1, A|2, NA, 1, + "adc", 4, 4, 1, 3, A|2, NA, 1, + "shl", 3, 5, 1, 1, SL|2, NA, 2, + "shl", 4, 5, 1, 2, SL|3, NA, 2, + "shr", 3, 5, 1, 1, SR|2, NA, 2, + "shr", 4, 5, 1, 2, SR|3, NA, 2, + "rol", 3, 5, 1, 1, RL|2, NA, 2, + "rol", 4, 5, 1, 2, RL|3, NA, 2, + "ror", 3, 5, 1, 1, RR|2, NA, 2, + "ror", 4, 5, 1, 2, RR|3, NA, 2, + /* + * Extensions (note also that mvi allows A) + */ + "clr", 2, 1, 1, I|R_ALLZEROS, I|0xff, NA, 1, + 0 +}; + +int eval_operand(char **a, int spec) +{ + int i; + unsigned int want = spec & (LO|LA|LX); + + static struct { + unsigned int what; + char *name; + int value; + } jmptab[] = { + LO, "jmp", 8, + LO, "jc", 9, + LO, "jnc", 10, + LO, "call", 11, + LA, "jz", 15, + LA, "jnz", 13, + LX, "je", 14, + LX, "jne", 12, + }; + + spec &= ~(LO|LA|LX); + + for (i = 0; i < sizeof(jmptab)/sizeof(jmptab[0]); i++) + if (jmptab[i].what == want && + !strcmp(jmptab[i].name, a[spec])) + { + return(jmptab[i].value); + } + + if (want) + error("invalid jump"); + + return(spec); /* "case 0" - no flags set */ +} + +int eval_sdi(char **a, int spec) +{ + sym_t *p; + unsigned val; + + if (spec == NA) + return(NA); + + switch (spec & (A|I|SL|SR|RL|RR)) { + case SL: + case SR: + case RL: + case RR: + if (isdigit(*a[spec &~ (SL|SR|RL|RR)])) + val = strtol(a[spec &~ (SL|SR|RL|RR)], NULL, 0); + else { + p = lookup(a[spec &~ (SL|SR|RL|RR)]); + if (!p) + error("undefined symbol used"); + val = p->value; + } + + switch (spec & (SL|SR|RL|RR)) { /* blech */ + case SL: + if (val > 7) + return(0xf0); + return(((val % 8) << 4) | + (val % 8)); + case SR: + if (val > 7) + return(0xf0); + return(((val % 8) << 4) | + (1 << 3) | + ((8 - (val % 8)) % 8)); + case RL: + return(val % 8); + case RR: + return((8 - (val % 8)) % 8); + } + case I: + return(spec &~ I); + case A: + /* + * An immediate field of zero selects + * the accumulator. Vigorously object + * if zero is given otherwise - it's + * most likely an error. + */ + spec &= ~A; + if (!strcmp("A", a[spec])) + return(0); + if (isdigit(*a[spec]) && + strtol(a[spec], NULL, 0) == 0) + { + error("immediate value of zero selects accumulator"); + } + /* falls through */ + case 0: + if (isdigit(*a[spec])) + return(strtol(a[spec], NULL, 0)); + p = lookup(a[spec]); + if (p) + return(p->value); + error("undefined symbol used"); + } + + return(NA); /* shut the compiler up */ +} + +int eval_addr(char **a, int spec) +{ + sym_t *p; + + if (spec == NA) + return(NA); + if (isdigit(*a[spec])) + return(strtol(a[spec], NULL, 0)); + + p = lookup(a[spec]); + + if (p) { + if (p->value != NOVALUE) + return(p->value); + patch(p, LC); + } else { + define(a[spec], NOVALUE); + p = lookup(a[spec]); + patch(p, LC); + } + + return(NA); /* will be patched in later */ +} + +int crack(char **a, int n) +{ + int i; + int I_imm, I_addr; + int I_op, I_dest, I_src, I_ret; + + /* + * Check for "ret" at the end of the line; remove + * it unless it's "ret" alone - we still want to + * look it up in the table. + */ + I_ret = (strcmp(a[n-1], "ret") ? 0 : !0); + if (I_ret && n > 1) + n -= 1; + + for (i = 0; instr[i].name; i++) { + /* + * Look for match in table given constraints, + * currently just the name and the number of + * operands. + */ + if (!strcmp(instr[i].name, *a) && instr[i].n == n) + break; + } + if (!instr[i].name) + error("unknown opcode or wrong number of operands"); + + I_op = eval_operand(a, instr[i].op); + I_src = eval_sdi(a, instr[i].src); + I_imm = eval_sdi(a, instr[i].imm); + I_dest = eval_sdi(a, instr[i].dest); + I_addr = eval_addr(a, instr[i].addr); + + switch (instr[i].fmt) { + case 1: + case 2: + M[LC][0] = (I_op << 1) | I_ret; + M[LC][1] = I_dest; + M[LC][2] = I_src; + M[LC][3] = I_imm; + break; + case 3: + if (I_ret) + error("illegal use of \"ret\""); + M[LC][0] = (I_op << 1) | ((I_addr >> 8) & 1); + M[LC][1] = I_addr & 0xff; + M[LC][2] = I_src; + M[LC][3] = I_imm; + break; + } + + return(1); /* no two-byte instructions yet */ +} + +#undef SL +#undef SR +#undef RL +#undef RR +#undef LX +#undef LA +#undef LO +#undef I +#undef A + +void assemble(void) +{ + int n; + char **a; + sym_t *p; + + while ((a = getl(&n))) { + + while (a[0][strlen(*a)-1] == ':') { + a[0][strlen(*a)-1] = '\0'; + p = lookup(*a); + if (p) + p->value = LC; + else + define(*a, LC); + a += 1; + n -= 1; + } + + if (!n) /* line was all labels */ + continue; + + if (n == 3 && !strcmp("VERSION", *a)) + fprintf(ofp, "#define %s \"%s\"\n", a[1], a[2]); + else { + if (n == 3 && !strcmp("=", a[1])) + define(*a, strtol(a[2], NULL, 0)); + else + LC += crack(a, n); + } + } + + backpatch(); + output(ofp); + + if (debug) + output(stderr); +} + +int main(int argc, char **argv) +{ + int c; + + while ((c = getopt(argc, argv, "dho:")) != EOF) { + switch (c) { + case 'd': + debug = !0; + break; + case 'o': + ofp = fopen(optarg, "w"); + if (!ofp) { + perror(optarg); + exit(EXIT_FAILURE); + } + break; + case 'h': + printf("usage: %s [-d] [-ooutput] input\n", *argv); + exit(EXIT_SUCCESS); + case NULL: + /* + * An impossible option to shut the compiler + * up about sccsid[]. + */ + exit((int)sccsid); + default: + exit(EXIT_FAILURE); + } + } + + if (argc - optind != 1) { + fprintf(stderr, "%s: must have one input file\n", *argv); + exit(EXIT_FAILURE); + } + filename = argv[optind]; + + ifp = fopen(filename, "r"); + if (!ifp) { + perror(filename); + exit(EXIT_FAILURE); + } + + if (!ofp) { + ofp = fopen(ADOTOUT, "w"); + if (!ofp) { + perror(ADOTOUT); + exit(EXIT_FAILURE); + } + } + + assemble(); + exit(EXIT_SUCCESS); +} diff --git a/sys/gnu/misc/aic7770/aic7770.seq b/sys/gnu/misc/aic7770/aic7770.seq new file mode 100644 index 0000000000000..9b83b84f5472d --- /dev/null +++ b/sys/gnu/misc/aic7770/aic7770.seq @@ -0,0 +1,1064 @@ +# @(#)aic7xxx.seq 1.30 94/11/09 jda +# +# Adaptec 274x device driver for Linux. +# Copyright (c) 1994 The University of Calgary Department of Computer Science. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +VERSION AIC7XXX_SEQ_VERSION 1.30 + +MAXSCB-1 = 0xf + +SCSISEQ = 0x00 +SXFRCTL0 = 0x01 +SXFRCTL1 = 0x02 +SCSISIGI = 0x03 +SCSISIGO = 0x03 +SCSIRATE = 0x04 +SCSIID = 0x05 +SCSIDATL = 0x06 +STCNT = 0x08 +STCNT+0 = 0x08 +STCNT+1 = 0x09 +STCNT+2 = 0x0a +SSTAT0 = 0x0b +CLRSINT1 = 0x0c +SSTAT1 = 0x0c +SIMODE1 = 0x11 +SCSIBUSL = 0x12 +SHADDR = 0x14 +SELID = 0x19 +SBLKCTL = 0x1f +SEQCTL = 0x60 +A = 0x64 # == ACCUM +SINDEX = 0x65 +DINDEX = 0x66 +ALLZEROS = 0x6a +NONE = 0x6a +SINDIR = 0x6c +DINDIR = 0x6d +FUNCTION1 = 0x6e +HADDR = 0x88 +HCNT = 0x8c +HCNT+0 = 0x8c +HCNT+1 = 0x8d +HCNT+2 = 0x8e +SCBPTR = 0x90 +INTSTAT = 0x91 +DFCNTRL = 0x93 +DFSTATUS = 0x94 +DFDAT = 0x99 +QINFIFO = 0x9b +QINCNT = 0x9c +QOUTFIFO = 0x9d + +SCSICONF = 0x5a + +# The two reserved bytes at SCBARRAY+1[23] are expected to be set to +# zero, and the reserved bit in SCBARRAY+0 is used as an internal flag +# to indicate whether or not to reload scatter-gather parameters after +# a disconnect. +# +SCBARRAY+0 = 0xa0 +SCBARRAY+1 = 0xa1 +SCBARRAY+2 = 0xa2 +SCBARRAY+3 = 0xa3 +SCBARRAY+7 = 0xa7 +SCBARRAY+11 = 0xab +SCBARRAY+14 = 0xae +SCBARRAY+15 = 0xaf +SCBARRAY+16 = 0xb0 +SCBARRAY+17 = 0xb1 +SCBARRAY+18 = 0xb2 +SCBARRAY+19 = 0xb3 +SCBARRAY+20 = 0xb4 +SCBARRAY+21 = 0xb5 +SCBARRAY+22 = 0xb6 +SCBARRAY+23 = 0xb7 +SCBARRAY+24 = 0xb8 +SCBARRAY+25 = 0xb9 + +SIGNAL_0 = 0x01 # unknown scsi bus phase +SIGNAL_1 = 0x11 # message reject +SIGNAL_2 = 0x21 # no IDENTIFY after reconnect +SIGNAL_3 = 0x31 # no cmd match for reconnect +SIGNAL_4 = 0x41 # SDTR -> SCSIRATE conversion +STATUS_ERROR = 0x51 + +# The host adapter card (at least the BIOS) uses 20-2f for SCSI +# device information, 32-33 and 5a-5f as well. Since we don't support +# wide or twin-bus SCSI, 28-2f can be reclaimed. As it turns out, the +# BIOS trashes 20-27 anyway, writing the synchronous negotiation results +# on top of the BIOS values, so we re-use those for our per-target +# scratchspace (actually a value that can be copied directly into +# SCSIRATE). This implies, since we can't get the BIOS config values, +# that all targets will be negotiated with for synchronous transfer. +# NEEDSDTR has one bit per target indicating if an SDTR message is +# needed for that device - this will be set initially, as well as +# after a bus reset condition. +# +# The high bit of DROPATN is set if ATN should be dropped before the ACK +# when outb is called. REJBYTE contains the first byte of a MESSAGE IN +# message, so the driver can report an intelligible error if a message is +# rejected. +# +# RESELECT's high bit is true if we are currently handling a reselect; +# its next-highest bit is true ONLY IF we've seen an IDENTIFY message +# from the reselecting target. If we haven't had IDENTIFY, then we have +# no idea what the lun is, and we can't select the right SCB register +# bank, so force a kernel panic if the target attempts a data in/out or +# command phase instead of corrupting something. +# +# Note that SG_NEXT occupies four bytes. +# +SYNCNEG = 0x20 +DISC_DSB_A = 0x32 + +DROPATN = 0x30 +REJBYTE = 0x31 +RESELECT = 0x34 + +MSG_FLAGS = 0x35 +MSG_LEN = 0x36 +MSG_START+0 = 0x37 +MSG_START+1 = 0x38 +MSG_START+2 = 0x39 +MSG_START+3 = 0x3a +MSG_START+4 = 0x3b +MSG_START+5 = 0x3c +-MSG_START+0 = 0xc9 # 2's complement of MSG_START+0 + +ARG_1 = 0x4c # sdtr conversion args & return +ARG_2 = 0x4d +RETURN_1 = 0x4c + +SIGSTATE = 0x4e # value written to SCSISIGO +NEEDSDTR = 0x4f # send SDTR message, 1 bit/trgt + +SG_SIZEOF = 0x8 # sizeof(struct scatterlist) +SG_NOLOAD = 0x50 # load SG pointer/length? +SG_COUNT = 0x51 # working value of SG count +SG_NEXT = 0x52 # working value of SG pointer +SG_NEXT+0 = 0x52 +SG_NEXT+1 = 0x53 +SG_NEXT+2 = 0x54 +SG_NEXT+3 = 0x55 + +SCBCOUNT = 0x56 # the actual number of SCBs +ACTIVE_A = 0x57 + +# Poll QINCNT for work - the lower three bits contain +# the number of entries in the Queue In FIFO. +# +start: + test SCSISIGI,0x4 jnz reselect # BSYI + test QINCNT,MAXSCB-1 jz start + +# We have at least one queued SCB now. Set the SCB pointer +# from the FIFO so we see the right bank of SCB registers, +# then set SCSI options and set the initiator and target +# SCSI IDs. +# + mov SCBPTR,QINFIFO + +# See if there is not already an active SCB for this target. This code +# will have to be modified when we add support for dual and wide busses. + + and FUNCTION1,0x70,SCBARRAY+1 + mov A,FUNCTION1 + test ACTIVE_A,A jz active +# Place the currently active back on the queue for later processing + mov QINFIFO, SCBPTR + jmp start + +# Mark the current target as busy and get working on the SCB +active: + or ACTIVE_A,A + mov SCBARRAY+1 call initialize + clr SG_NOLOAD + clr RESELECT + +# As soon as we get a successful selection, the target should go +# into the message out phase since we have ATN asserted. Prepare +# the message to send, locking out the device driver. If the device +# driver hasn't beaten us with an ABORT or RESET message, then tack +# on a SDTR negotation if required. +# +# Messages are stored in scratch RAM starting with a flag byte (high bit +# set means active message), one length byte, and then the message itself. +# + mov SCBARRAY+1 call disconnect # disconnect ok? + + and SINDEX,0x7,SCBARRAY+1 # lun + or SINDEX,A # return value from disconnect + or SINDEX,0x80 call mk_mesg # IDENTIFY message + + mov A,SINDEX + cmp MSG_START+0,A jne !message # did driver beat us? + mvi MSG_START+1 call mk_sdtr # build SDTR message if needed + +!message: + +# Enable selection phase as an initiator, and do automatic ATN +# after the selection. +# + mvi SCSISEQ,0x48 # ENSELO|ENAUTOATNO + +# Wait for successful arbitration. The AIC-7770 documentation says +# that SELINGO indicates successful arbitration, and that it should +# be used to look for SELDO. However, if the sequencer is paused at +# just the right time - a parallel fsck(8) on two drives did it for +# me - then SELINGO can flip back to false before we've seen it. This +# makes the sequencer sit in the arbitration loop forever. This is +# Not Good. +# +# Therefore, I've added a check in the arbitration loop for SELDO +# too. This could arguably be made a critical section by disabling +# pauses, but I don't want to make a potentially infinite loop a CS. +# I suppose you could fold it into the select loop, too, but since +# I've been hunting this bug for four days it's kinda like a trophy. +# +arbitrate: + test SSTAT0,0x40 jnz *select # SELDO + test SSTAT0,0x10 jz arbitrate # SELINGO + +# Wait for a successful selection. If the hardware selection +# timer goes off, then the driver gets the interrupt, so we don't +# need to worry about it. +# +select: + test SSTAT0,0x40 jz select # SELDO + jmp *select + +# Reselection is being initiated by a target - we've seen the BSY +# line driven active, and we didn't do it! Enable the reselection +# hardware, and wait for it to finish. Make a note that we've been +# reselected, but haven't seen an IDENTIFY message from the target +# yet. +# +reselect: + mvi SCSISEQ,0x10 # ENRSELI + +reselect1: + test SSTAT0,0x20 jz reselect1 # SELDI + mov SELID call initialize + + mvi RESELECT,0x80 # reselected, no IDENTIFY + +# After the [re]selection, make sure that the [re]selection enable +# bit is off. This chip is flaky enough without extra things +# turned on. Also clear the BUSFREE bit in SSTAT1 since we'll be +# using it shortly. +# +*select: + clr SCSISEQ + mvi CLRSINT1,0x8 # CLRBUSFREE + +# Main loop for information transfer phases. If BSY is false, then +# we have a bus free condition, expected or not. Otherwise, wait +# for the target to assert REQ before checking MSG, C/D and I/O +# for the bus phase. +# +# We can't simply look at the values of SCSISIGI here (if we want +# to do synchronous data transfer), because the target won't assert +# REQ if it's already sent us some data that we haven't acknowledged +# yet. +# +ITloop: + test SSTAT1,0x8 jnz p_busfree # BUSFREE + test SSTAT1,0x1 jz ITloop # REQINIT + + and A,0xe0,SCSISIGI # CDI|IOI|MSGI + + cmp ALLZEROS,A je p_dataout + cmp A,0x40 je p_datain + cmp A,0x80 je p_command + cmp A,0xc0 je p_status + cmp A,0xa0 je p_mesgout + cmp A,0xe0 je p_mesgin + + mvi INTSTAT,SIGNAL_0 # unknown - signal driver + +p_dataout: + mvi 0 call scsisig # !CDO|!IOO|!MSGO + call assert + call sg_load + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+23 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+23 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+19 call bcopy + + mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN| + # DIRECTION|FIFORESET + +# After a DMA finishes, save the final transfer pointer and count +# back into the SCB, in case a device disconnects in the middle of +# a transfer. Use SHADDR and STCNT instead of HADDR and HCNT, since +# it's a reflection of how many bytes were transferred on the SCSI +# (as opposed to the host) bus. +# + mvi A,3 + mvi DINDEX,SCBARRAY+23 + mvi STCNT call bcopy + + mvi A,4 + mvi DINDEX,SCBARRAY+19 + mvi SHADDR call bcopy + + call sg_advance + mov SCBARRAY+18,SG_COUNT # residual S/G count + + jmp ITloop + +p_datain: + mvi 0x40 call scsisig # !CDO|IOO|!MSGO + call assert + call sg_load + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+23 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+23 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+19 call bcopy + + mvi 0x39 call dma # SCSIEN|SDMAEN|HDMAEN| + # !DIRECTION|FIFORESET + mvi A,3 + mvi DINDEX,SCBARRAY+23 + mvi STCNT call bcopy + + mvi A,4 + mvi DINDEX,SCBARRAY+19 + mvi SHADDR call bcopy + + call sg_advance + mov SCBARRAY+18,SG_COUNT # residual S/G count + + jmp ITloop + +# Command phase. Set up the DMA registers and let 'er rip - the +# two bytes after the SCB SCSI_cmd_length are zeroed by the driver, +# so we can copy those three bytes directly into HCNT. +# +p_command: + mvi 0x80 call scsisig # CDO|!IOO|!MSGO + call assert + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+11 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+11 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+7 call bcopy + + mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN| + # DIRECTION|FIFORESET + jmp ITloop + +# Status phase. Wait for the data byte to appear, then read it +# and store it into the SCB. +# +p_status: + mvi 0xc0 call scsisig # CDO|IOO|!MSGO + + mvi SCBARRAY+14 call inb + jmp ITloop + +# Message out phase. If there is no active message, but the target +# took us into this phase anyway, build a no-op message and send it. +# +p_mesgout: + mvi 0xa0 call scsisig # CDO|!IOO|MSGO + mvi 0x8 call mk_mesg # build NOP message + +# Set up automatic PIO transfer from MSG_START. Bit 3 in +# SXFRCTL0 (SPIOEN) is already on. +# + mvi SINDEX,MSG_START+0 + mov DINDEX,MSG_LEN + clr A + +# When target asks for a byte, drop ATN if it's the last one in +# the message. Otherwise, keep going until the message is exhausted. +# (We can't use outb for this since it wants the input in SINDEX.) +# +# Keep an eye out for a phase change, in case the target issues +# a MESSAGE REJECT. +# +p_mesgout2: + test SSTAT0,0x2 jz p_mesgout2 # SPIORDY + test SSTAT1,0x10 jnz p_mesgout6 # PHASEMIS + + cmp DINDEX,1 jne p_mesgout3 # last byte? + mvi CLRSINT1,0x40 # CLRATNO - drop ATN + +# Write a byte to the SCSI bus. The AIC-7770 refuses to automatically +# send ACKs in automatic PIO or DMA mode unless you make sure that the +# "expected" bus phase in SCSISIGO matches the actual bus phase. This +# behaviour is completely undocumented and caused me several days of +# grief. +# +# After plugging in different drives to test with and using a longer +# SCSI cable, I found that I/O in Automatic PIO mode ceased to function, +# especially when transferring >1 byte. It seems to be much more stable +# if STCNT is set to one before the transfer, and SDONE (in SSTAT0) is +# polled for transfer completion - for both output _and_ input. The +# only theory I have is that SPIORDY doesn't drop right away when SCSIDATL +# is accessed (like the documentation says it does), and that on a longer +# cable run, the sequencer code was fast enough to loop back and see +# an SPIORDY that hadn't dropped yet. +# +p_mesgout3: + call one_stcnt + mov SCSIDATL,SINDIR + +p_mesgout4: + test SSTAT0,0x4 jz p_mesgout4 # SDONE + dec DINDEX + inc A + cmp MSG_LEN,A jne p_mesgout2 + +# If the next bus phase after ATN drops is a message out, it means +# that the target is requesting that the last message(s) be resent. +# +p_mesgout5: + test SSTAT1,0x8 jnz p_mesgout6 # BUSFREE + test SSTAT1,0x1 jz p_mesgout5 # REQINIT + + and A,0xe0,SCSISIGI # CDI|IOI|MSGI + cmp A,0xa0 jne p_mesgout6 + mvi 0x10 call scsisig # ATNO - re-assert ATN + + jmp ITloop + +p_mesgout6: + mvi CLRSINT1,0x40 # CLRATNO - in case of PHASEMIS + clr MSG_FLAGS # no active msg + jmp ITloop + +# Message in phase. Bytes are read using Automatic PIO mode, but not +# using inb. This alleviates a race condition, namely that if ATN had +# to be asserted under Automatic PIO mode, it had to beat the SCSI +# circuitry sending an ACK to the target. This showed up under heavy +# loads and really confused things, since ABORT commands wouldn't be +# seen by the drive after an IDENTIFY message in until it had changed +# to a data I/O phase. +# +p_mesgin: + mvi 0xe0 call scsisig # CDO|IOO|MSGO + mvi A call inb_first # read the 1st message byte + mvi REJBYTE,A # save it for the driver + + cmp ALLZEROS,A jne p_mesgin1 + +# We got a "command complete" message, so put the SCB pointer +# into the Queue Out, and trigger a completion interrupt. +# Check status for non zero return and interrupt driver if needed +# This allows the driver to do a sense command to find out the +# source of error. We don't bother to post to the QOUTFIFO in +# the error case since it would require extra work in the kernel +# driver to ensure that the entry was removed before the command +# complete code tried processing it. + +# First, mark this target as free. + and FUNCTION1,0x70,SCBARRAY+1 + mov A,FUNCTION1 + xor ACTIVE_A,A + + test SCBARRAY+14,0xff jz status_ok # 0 Status? + call inb_last # ack & turn auto PIO back on + mvi INTSTAT,STATUS_ERROR # let driver know + jmp ITloop +status_ok: + mov QOUTFIFO,SCBPTR + mvi INTSTAT,0x2 # CMDCMPLT + jmp p_mesgin_done + +# Is it an extended message? We only support the synchronous data +# transfer request message, which will probably be in response to +# an SDTR message out from us. If it's not an SDTR, reject it - +# apparently this can be done after any message in byte, according +# to the SCSI-2 spec. +# +# XXX - we should really reject this if we didn't initiate the SDTR +# negotiation; this may cause problems with unusual devices. +# +p_mesgin1: + cmp A,1 jne p_mesgin2 # extended message code? + + mvi A call inb_next + cmp A,3 jne p_mesginN # extended mesg length = 3 + mvi A call inb_next + cmp A,1 jne p_mesginN # SDTR code + + mvi ARG_1 call inb_next # xfer period + mvi ARG_2 call inb_next # REQ/ACK offset + mvi INTSTAT,SIGNAL_4 # call driver to convert + + call ndx_sdtr # index sync config for target + mov DINDEX,SINDEX + mov DINDIR,RETURN_1 # save returned value + + not A # turn off "need sdtr" flag + and NEEDSDTR,A + +# Even though the SCSI-2 specification says that a device responding +# to our SDTR message should honor our parameters for transmitting +# to us, it doesn't seem to work too well in real life. In particular, +# a lot of CD-ROM and tape units don't function: try using the SDTR +# parameters the device sent us for both transmitting and receiving. +# + mov SCSIRATE,RETURN_1 + jmp p_mesgin_done + +# Is it a disconnect message? Set a flag in the SCB to remind us +# and await the bus going free. +# +p_mesgin2: + cmp A,4 jne p_mesgin3 # disconnect code? + + or SCBARRAY+0,0x4 # set "disconnected" bit + jmp p_mesgin_done + +# Save data pointers message? Copy working values into the SCB, +# usually in preparation for a disconnect. +# +p_mesgin3: + cmp A,2 jne p_mesgin4 # save data pointers code? + + call sg_ram2scb + jmp p_mesgin_done + +# Restore pointers message? Data pointers are recopied from the +# SCB anyway at the start of any DMA operation, so the only thing +# to copy is the scatter-gather values. +# +p_mesgin4: + cmp A,3 jne p_mesgin5 # restore pointers code? + + call sg_scb2ram + jmp p_mesgin_done + +# Identify message? For a reconnecting target, this tells us the lun +# that the reconnection is for - find the correct SCB and switch to it, +# clearing the "disconnected" bit so we don't "find" it by accident later. +# +p_mesgin5: + test A,0x80 jz p_mesgin6 # identify message? + + test A,0x78 jnz p_mesginN # !DiscPriv|!LUNTAR|!Reserved + + mov A call findSCB # switch to correct SCB + +# If a active message is present after calling findSCB, then either it +# or the driver is trying to abort the command. Either way, something +# untoward has happened and we should just leave it alone. +# + test MSG_FLAGS,0x80 jnz p_mesgin_done + + xor SCBARRAY+0,0x4 # clear disconnect bit in SCB + mvi RESELECT,0xc0 # make note of IDENTIFY + + call sg_scb2ram # implied restore pointers + # required on reselect + jmp p_mesgin_done + +# Message reject? If we have an outstanding SDTR negotiation, assume +# that it's a response from the target selecting asynchronous transfer, +# otherwise just ignore it since we have no clue what it pertains to. +# +# XXX - I don't have a device that responds this way. Does this code +# actually work? +# +p_mesgin6: + cmp A,7 jne p_mesgin7 # message reject code? + + and FUNCTION1,0x70,SCSIID # outstanding SDTR message? + mov A,FUNCTION1 + test NEEDSDTR,A jz p_mesgin_done # no - ignore rejection + + call ndx_sdtr # note use of asynch xfer + mov DINDEX,SINDEX + clr DINDIR + + not A # turn off "active sdtr" flag + and NEEDSDTR,A + + clr SCSIRATE # select asynch xfer + jmp p_mesgin_done + +# [ ADD MORE MESSAGE HANDLING HERE ] +# +p_mesgin7: + +# We have no idea what this message in is, and there's no way +# to pass it up to the kernel, so we issue a message reject and +# hope for the best. Since we're now using manual PIO mode to +# read in the message, there should no longer be a race condition +# present when we assert ATN. In any case, rejection should be a +# rare occurrence - signal the driver when it happens. +# +p_mesginN: + or SINDEX,0x10,SIGSTATE # turn on ATNO + call scsisig + mvi INTSTAT,SIGNAL_1 # let driver know + + mvi 0x7 call mk_mesg # MESSAGE REJECT message + +p_mesgin_done: + call inb_last # ack & turn auto PIO back on + jmp ITloop + +# Bus free phase. It might be useful to interrupt the device +# driver if we aren't expecting this. For now, make sure that +# ATN isn't being asserted and look for a new command. +# +p_busfree: + mvi CLRSINT1,0x40 # CLRATNO + clr SIGSTATE + jmp start + +# Bcopy: number of bytes to transfer should be in A, DINDEX should +# contain the destination address, and SINDEX should contain the +# source address. All input parameters are trashed on return. +# +bcopy: + mov DINDIR,SINDIR + dec A + cmp ALLZEROS,A jne bcopy + ret + +# Locking the driver out, build a one-byte message passed in SINDEX +# if there is no active message already. SINDEX is returned intact. +# +mk_mesg: + mvi SEQCTL,0x40 # PAUSEDIS + test MSG_FLAGS,0x80 jnz mk_mesg1 # active message? + + mvi MSG_FLAGS,0x80 # if not, there is now + mvi MSG_LEN,1 # length = 1 + mov MSG_START+0,SINDEX # 1-byte message + +mk_mesg1: + clr SEQCTL # !PAUSEDIS + ret + +# Input byte in Automatic PIO mode. The address to store the byte +# in should be in SINDEX. DINDEX will be used by this routine. +# +inb: + test SSTAT0,0x2 jz inb # SPIORDY + mov DINDEX,SINDEX + call one_stcnt # xfer one byte + mov DINDIR,SCSIDATL +inb1: + test SSTAT0,0x4 jz inb1 # SDONE - wait to "finish" + ret + +# Carefully read data in Automatic PIO mode. I first tried this using +# Manual PIO mode, but it gave me continual underrun errors, probably +# indicating that I did something wrong, but I feel more secure leaving +# Automatic PIO on all the time. +# +# According to Adaptec's documentation, an ACK is not sent on input from +# the target until SCSIDATL is read from. So we wait until SCSIDATL is +# latched (the usual way), then read the data byte directly off the bus +# using SCSIBUSL. When we have pulled the ATN line, or we just want to +# acknowledge the byte, then we do a dummy read from SCISDATL. The SCSI +# spec guarantees that the target will hold the data byte on the bus until +# we send our ACK. +# +# The assumption here is that these are called in a particular sequence, +# and that REQ is already set when inb_first is called. inb_{first,next} +# use the same calling convention as inb. +# +inb_first: + mov DINDEX,SINDEX + mov DINDIR,SCSIBUSL ret # read byte directly from bus + +inb_next: + mov DINDEX,SINDEX # save SINDEX + + call one_stcnt # xfer one byte + mov NONE,SCSIDATL # dummy read from latch to ACK +inb_next1: + test SSTAT0,0x4 jz inb_next1 # SDONE +inb_next2: + test SSTAT0,0x2 jz inb_next2 # SPIORDY - wait for next byte + mov DINDIR,SCSIBUSL ret # read byte directly from bus + +inb_last: + call one_stcnt # ACK with dummy read + mov NONE,SCSIDATL +inb_last1: + test SSTAT0,0x4 jz inb_last1 # wait for completion + ret + +# Output byte in Automatic PIO mode. The byte to output should be +# in SINDEX. If DROPATN's high bit is set, then ATN will be dropped +# before the byte is output. +# +outb: + test SSTAT0,0x2 jz outb # SPIORDY + call one_stcnt # xfer one byte + + test DROPATN,0x80 jz outb1 + mvi CLRSINT1,0x40 # CLRATNO + clr DROPATN +outb1: + mov SCSIDATL,SINDEX +outb2: + test SSTAT0,0x4 jz outb2 # SDONE + ret + +# Write the value "1" into the STCNT registers, for Automatic PIO +# transfers. +# +one_stcnt: + clr STCNT+2 + clr STCNT+1 + mvi STCNT+0,1 ret + +# DMA data transfer. HADDR and HCNT must be loaded first, and +# SINDEX should contain the value to load DFCNTRL with - 0x3d for +# host->scsi, or 0x39 for scsi->host. The SCSI channel is cleared +# during initialization. +# +dma: + mov DFCNTRL,SINDEX +dma1: +dma2: + test SSTAT0,0x1 jnz dma3 # DMADONE + test SSTAT1,0x10 jz dma1 # PHASEMIS, ie. underrun + +# We will be "done" DMAing when the transfer count goes to zero, or +# the target changes the phase (in light of this, it makes sense that +# the DMA circuitry doesn't ACK when PHASEMIS is active). If we are +# doing a SCSI->Host transfer, flush the data FIFO. +# +dma3: + test SINDEX,0x4 jnz dma5 # DIRECTION + and SINDEX,0xfe # mask out FIFORESET + or DFCNTRL,0x2,SINDEX # FIFOFLUSH +dma4: + test DFCNTRL,0x2 jnz dma4 # FIFOFLUSHACK + +# Now shut the DMA enables off, and copy STCNT (ie. the underrun +# amount, if any) to the SCB registers; SG_COUNT will get copied to +# the SCB's residual S/G count field after sg_advance is called. Make +# sure that the DMA enables are actually off first lest we get an ILLSADDR. +# +dma5: + clr DFCNTRL # disable DMA +dma6: + test DFCNTRL,0x38 jnz dma6 # SCSIENACK|SDMAENACK|HDMAENACK + + mvi A,3 + mvi DINDEX,SCBARRAY+15 + mvi STCNT call bcopy + + ret + +# Common SCSI initialization for selection and reselection. Expects +# the target SCSI ID to be in the upper four bits of SINDEX, and A's +# contents are stomped on return. +# +initialize: + clr SBLKCTL # channel A, !wide + and SCSIID,0xf0,SINDEX # target ID + and A,0x7,SCSICONF # SCSI_ID_A[210] + or SCSIID,A + +# Esundry initialization. +# + clr DROPATN + clr SIGSTATE + +# Turn on Automatic PIO mode now, before we expect to see an REQ +# from the target. It shouldn't hurt anything to leave it on. Set +# CLRCHN here before the target has entered a data transfer mode - +# with synchronous SCSI, if you do it later, you blow away some +# data in the SCSI FIFO that the target has already sent to you. +# + mvi SXFRCTL0,0xa # SPIOEN|CLRCHN + +# Set SCSI bus parity checking and the selection timeout value, +# and enable the hardware selection timer. Set the SELTO interrupt +# to signal the driver. +# + and A,0x38,SCSICONF # PARITY_ENB_A|SEL_TIM_A[10] + or SXFRCTL1,0x4,A # ENSTIMER + mvi SIMODE1,0x84 # ENSELTIMO|ENSCSIPERR + +# Initialize scatter-gather pointers by setting up the working copy +# in scratch RAM. +# + call sg_scb2ram + +# Initialize SCSIRATE with the appropriate value for this target. +# + call ndx_sdtr + mov SCSIRATE,SINDIR + ret + +# Assert that if we've been reselected, then we've seen an IDENTIFY +# message. +# +assert: + test RESELECT,0x80 jz assert1 # reselected? + test RESELECT,0x40 jnz assert1 # seen IDENTIFY? + + mvi INTSTAT,SIGNAL_2 # no - cause a kernel panic + +assert1: + ret + +# Find out if disconnection is ok from the information the BIOS has left +# us. The target ID should be in the upper four bits of SINDEX; A will +# contain either 0x40 (disconnection ok) or 0x00 (diconnection not ok) +# on exit. +# +# This is the only place the target ID is limited to three bits, so we +# can use the FUNCTION1 register. +# +disconnect: + and FUNCTION1,0x70,SINDEX # strip off extra just in case + mov A,FUNCTION1 + test DISC_DSB_A,A jz disconnect1 # bit nonzero if DISabled + + clr A ret +disconnect1: + mvi A,0x40 ret + +# Locate the SCB matching the target ID in SELID and the lun in the lower +# three bits of SINDEX, and switch the SCB to it. Have the kernel print +# a warning message if it can't be found, and generate an ABORT message +# to the target. We keep the value of the t/c/l that we are trying to +# in DINDEX so it is not overwritten during our check to see if we are +# at the last SCB. +# +findSCB: + and A,0x7,SINDEX # lun in lower three bits + or DINDEX,A,SELID # can I do this? + and DINDEX,0xf7 # only channel A implemented + + clr SINDEX + +findSCB1: + mov SCBPTR,SINDEX # switch to new SCB + mov A,DINDEX + cmp SCBARRAY+1,A jne findSCB2 # target ID/channel/lun match? + test SCBARRAY+0,0x4 jz findSCB2 # should be disconnected + + ret + +findSCB2: + inc SINDEX + mov A,SCBCOUNT + cmp SINDEX,A jne findSCB1 + + mvi INTSTAT,SIGNAL_3 # not found - signal kernel + mvi 0x6 call mk_mesg # ABORT message + + or SINDEX,0x10,SIGSTATE # assert ATNO + call scsisig + ret + +# Make a working copy of the scatter-gather parameters in the SCB. +# +sg_scb2ram: + mov SG_COUNT,SCBARRAY+2 + + mvi A,4 + mvi DINDEX,SG_NEXT + mvi SCBARRAY+3 call bcopy + + mvi SG_NOLOAD,0x80 + test SCBARRAY+0,0x10 jnz sg_scb2ram1 # don't reload s/g? + clr SG_NOLOAD + +sg_scb2ram1: + ret + +# Copying RAM values back to SCB, for Save Data Pointers message. +# +sg_ram2scb: + mov SCBARRAY+2,SG_COUNT + + mvi A,4 + mvi DINDEX,SCBARRAY+3 + mvi SG_NEXT call bcopy + + and SCBARRAY+0,0xef,SCBARRAY+0 + test SG_NOLOAD,0x80 jz sg_ram2scb1 # reload s/g? + or SCBARRAY+0,0x10 + +sg_ram2scb1: + ret + +# Load a struct scatter if needed and set up the data address and +# length. If the working value of the SG count is nonzero, then +# we need to load a new set of values. +# +# This, like the above DMA, assumes a little-endian host data storage. +# +sg_load: + test SG_COUNT,0xff jz sg_load3 # SG being used? + test SG_NOLOAD,0x80 jnz sg_load3 # don't reload s/g? + + clr HCNT+2 + clr HCNT+1 + mvi HCNT+0,SG_SIZEOF + + mvi A,4 + mvi DINDEX,HADDR + mvi SG_NEXT call bcopy + + mvi DFCNTRL,0xd # HDMAEN|DIRECTION|FIFORESET + +# Wait for DMA from host memory to data FIFO to complete, then disable +# DMA and wait for it to acknowledge that it's off. +# +sg_load1: + test DFSTATUS,0x8 jz sg_load1 # HDONE + + clr DFCNTRL # disable DMA +sg_load2: + test DFCNTRL,0x8 jnz sg_load2 # HDMAENACK + +# Copy data from FIFO into SCB data pointer and data count. This assumes +# that the struct scatterlist has this structure (this and sizeof(struct +# scatterlist) == 12 are asserted in aic7xxx.c): +# +# struct scatterlist { +# char *address; /* four bytes, little-endian order */ +# ... /* four bytes, ignored */ +# unsigned short length; /* two bytes, little-endian order */ +# } +# + +# Not in FreeBSD. the scatter list is only 8 bytes. +# +# struct ahc_dma_seg { +# physaddr addr; /* four bytes, little-endian order */ +# long len; /* four bytes, little endian order */ +# }; +# + + mov SCBARRAY+19,DFDAT # new data address + mov SCBARRAY+20,DFDAT + mov SCBARRAY+21,DFDAT + mov SCBARRAY+22,DFDAT + + mov SCBARRAY+23,DFDAT + mov SCBARRAY+24,DFDAT + mov SCBARRAY+25,DFDAT + mov NONE,DFDAT #Only support 24 bit length. + +sg_load3: + ret + +# Advance the scatter-gather pointers only IF NEEDED. If SG is enabled, +# and the SCSI transfer count is zero (note that this should be called +# right after a DMA finishes), then move the working copies of the SG +# pointer/length along. If the SCSI transfer count is not zero, then +# presumably the target is disconnecting - do not reload the SG values +# next time. +# +sg_advance: + test SG_COUNT,0xff jz sg_advance2 # s/g enabled? + + test STCNT+0,0xff jnz sg_advance1 # SCSI transfer count nonzero? + test STCNT+1,0xff jnz sg_advance1 + test STCNT+2,0xff jnz sg_advance1 + + clr SG_NOLOAD # reload s/g next time + dec SG_COUNT # one less segment to go + + clr A # add sizeof(struct scatter) + add SG_NEXT+0,SG_SIZEOF,SG_NEXT+0 + adc SG_NEXT+1,A,SG_NEXT+1 + adc SG_NEXT+2,A,SG_NEXT+2 + adc SG_NEXT+3,A,SG_NEXT+3 + + ret + +sg_advance1: + mvi SG_NOLOAD,0x80 # don't reload s/g next time +sg_advance2: + ret + +# Add the array base SYNCNEG to the target offset (the target address +# is in SCSIID), and return the result in SINDEX. The accumulator +# contains the 3->8 decoding of the target ID on return. +# +ndx_sdtr: + shr A,SCSIID,4 + and A,0x7 + add SINDEX,SYNCNEG,A + + and FUNCTION1,0x70,SCSIID # 3-bit target address decode + mov A,FUNCTION1 ret + +# If we need to negotiate transfer parameters, build the SDTR message +# starting at the address passed in SINDEX. DINDEX is modified on return. +# +mk_sdtr: + mov DINDEX,SINDEX # save SINDEX + + call ndx_sdtr + test NEEDSDTR,A jnz mk_sdtr1 # do we need negotiation? + ret + +mk_sdtr1: + mvi DINDIR,1 # extended message + mvi DINDIR,3 # extended message length = 3 + mvi DINDIR,1 # SDTR code + mvi DINDIR,25 # REQ/ACK transfer period + mvi DINDIR,15 # REQ/ACK offset + + add MSG_LEN,-MSG_START+0,DINDEX # update message length + ret + +# Set SCSI bus control signal state. This also saves the last-written +# value into a location where the higher-level driver can read it - if +# it has to send an ABORT or RESET message, then it needs to know this +# so it can assert ATN without upsetting SCSISIGO. The new value is +# expected in SINDEX. Change the actual state last to avoid contention +# from the driver. +# +scsisig: + mov SIGSTATE,SINDEX + mov SCSISIGO,SINDEX ret + diff --git a/sys/gnu/misc/aic7xxx/COPYING b/sys/gnu/misc/aic7xxx/COPYING new file mode 100644 index 0000000000000..a43ea2126fb6b --- /dev/null +++ b/sys/gnu/misc/aic7xxx/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) 19yy <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/sys/gnu/misc/aic7xxx/COPYRIGHT b/sys/gnu/misc/aic7xxx/COPYRIGHT new file mode 100644 index 0000000000000..905285da67595 --- /dev/null +++ b/sys/gnu/misc/aic7xxx/COPYRIGHT @@ -0,0 +1,16 @@ +Adaptec 274x device driver for Linux. +Copyright (c) 1994 The University of Calgary Department of Computer Science. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/sys/gnu/misc/aic7xxx/README b/sys/gnu/misc/aic7xxx/README new file mode 100644 index 0000000000000..1e4e5a011a697 --- /dev/null +++ b/sys/gnu/misc/aic7xxx/README @@ -0,0 +1,94 @@ +@(#)README 1.16 94/11/09 jda + +AHA274x/284x DRIVER + +*** THIS SHOULD BE CONSIDERED BETA SOFTWARE *** + +BACKGROUND & LIMITATIONS + +For various reasons, we ended up with one of these cards under the +impression that support was soon forthcoming. In mid-May, I asked +Scott Ferris (the official person who's supposed to be writing this +driver) what documentation he used, _finally_ got it from Adaptec, +and started writing this driver. It is now at what I would consider +a stable state - it runs our news server and is battered by SCSI +requests 24 hours a day without dying. There are a few devices it +reportedly doesn't like working with - those are being sorted out. Due +to some unexpected equipment loans, I am able to support this at least +for the time being. + +YOU MUST HAVE THE BIOS ENABLED OR THIS WILL NOT WORK. The BIOS extracts +some configuration information that I cannot get to portably yet, as +well as provides some self-tests which this driver does not attempt to +duplicate. + +Scott's driver development is stalled for now, and after discussions +with him, this is now officially out of "pre-alpha" status and into +beta until the remaining device problems can be resolved. The latest +patches can be obtained via anonymous ftp from ftp.cpsc.ucalgary.ca in +/pub/systems/linux/aha274x. + +It supports both EISA 274x and VL-bus 284x, either single or twin-bus cards +(but not the second SCSI bus of twin cards - see aha274x.c), and supports +disconnection, synchronous SCSI, and scatter-gather. Unlike previous +versions, abort() and reset() are now implemented, and both hosts.c and +aha274x.c should give a clean compile. Code is now present to detect parity +errors, but has not been tested. + +I wrote this using a 1.0.9 kernel. Unfortunately, I'm getting tired of +#ifdef'ing everything to handle two or three different evolutionary steps +in the SCSI kernel code, so I've upgraded my system to 1.1.49, and will +only leave in code to support versions from about 1.1.45 onward. + +Thanks to patches supplied by Mark Olson <molson@tricord.com>, this driver +will now work with the 284x series (the VL-bus version of this card). The +294x (PCI-bus) support is based on patches sent to me by Mark Olson and +Alan Hourihane <alanh@fairlite.demon.co.uk>. + +Under protest, this driver is subject to the GPL - see the file +COPYING for details. + +Thanks to the following people for bug fixes/code improvements (also +thanks to the people who have sent me feedback): + + "David F. Carlson" <dave@ee.rochester.edu> + Jimen Ching <jiching@wiliki.eng.hawaii.edu> + mday@artisoft.com (Matt Day) + "Dean W. Gehnert" <deang@ims.com> + Darcy Grant <darcy@cpsc.ucalgary.ca> + Alan Hourihane <alanh@fairlite.demon.co.uk> + isely@fncrd8.fnal.gov (Mike Isely) + Mike Jerger <jerger@ux1.cso.uiuc.edu> + tm@netcom.com (Toshiyasu Morita) + neal@interact.org (Neal Norwitz) + Mark Olson <molson@tricord.com> + map@europa.ecn.uoknor.edu (Michael A. Parker) + Thomas Scheunemann <thomas@dagobert.uni-duisburg.de> + +Special thanks to Drew Eckhardt <drew@kinglear.cs.Colorado.EDU> for +fielding my questions about synchronous negotiation. Steffen Moeller +<smoe0024@rz.uni-hildesheim.de> sent me installation instructions which +were previously included in this README. + +David Pirie <pirie@cpsc.ucalgary.ca> was nice enough to loan me his +2842 card for a week so I could track down one bug, as well as his +CD-ROM drive later, and also thanks to Doug Fortune at Riley's Data Share +in Calgary, who arranged a long-term loan of a 2842 board for further work. + +Many thanks to the fearless prerelease testers! Dean Gehnert has been +building Slackware boot disks for the driver, which are available from +ftp.cpsc.ucalgary.ca in /pub/systems/linux/aha274x/slackware_boot. + +Carl Riches <cgr@poplar1.cfr.washington.edu> has set up a mailing list +for aic7xxx driver development. To subscribe, send a message to +aic7770-list@poplar1.cfr.washington.edu with a message body of: + + subscribe AIC7770-LIST <your name here, without the angle brackets> + +Please direct questions and discussions to that list instead of me. When +sending bug reports, please include a description of your hardware, the +release numbers displayed by the driver at boot time, and as accurate a +facsimilie of any error message you're mailing about. + +John Aycock +aycock@cpsc.ucalgary.ca diff --git a/sys/gnu/misc/aic7xxx/README-FIRST b/sys/gnu/misc/aic7xxx/README-FIRST new file mode 100644 index 0000000000000..056dbc82cd614 --- /dev/null +++ b/sys/gnu/misc/aic7xxx/README-FIRST @@ -0,0 +1,19 @@ +This is VERY MUCH ALPHA SOFTWARE. You MUST know what you're doing to +use this, or else!!! + +Ok, everything's been renamed to reference an "aic7xxx" driver instead +of "aha274x", and a merger of the two PCI patches I had has been put in, +along with re-doing the detection and configuration routines. To summarize +the status: it compiles cleanly. I don't expect it to work off the bat, +but it's for the 294x development people to synchronize their code +together. + +The file scsi-diffs-1.1.59 is NOT a proper patch file, but some diffs +to kernel files concatenated together. I've sent these off to Drew, +but if you're testing this you'll have to apply them - it allows a +per-driver-instance can_queue variable, which for the aic7xxx driver +is the number of SCBs the card supports. + +Good luck! I await your comments.. Mark, Alan - let me know where I +broke it, please ;-) +:ja diff --git a/sys/gnu/misc/aic7xxx/aic7xxx.1 b/sys/gnu/misc/aic7xxx/aic7xxx.1 new file mode 100644 index 0000000000000..2009f8c7ad6ec --- /dev/null +++ b/sys/gnu/misc/aic7xxx/aic7xxx.1 @@ -0,0 +1,54 @@ +.\" Copyright (c) 1994 +.\" Justin T. Gibbs. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Justin T. Gibbs. +.\" 4. The name of Justin T. Gibbs may not be used to endorse or promote +.\" products derived from this software without specific prior written +.\" permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY JUSTIN T. GIBBS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)aic7770.1 11/15/94 +.\" +.Dd November 11, 1994 +.Dt AIC7770 1 +.Os BSD 4 +.Sh NAME +.Nm aic7770 +.Nd aic7770 SCSI controller assembler +.Sh SYNOPSIS +.Nm aic7770 +.Op Fl o destination +.Ar source-file +.Sh DESCRIPTION +.Ar Source-file +is a file containing Aic7770 compatible assembly code. The output of the +assembler defaults to +.Ar a.out +but can be optionally redirected to +.Ar destination. +.Pp +.Sh AUTHOR +This aic7770 compiler was written by John Aycock (aycock@cpsc.ucalgary.ca) and +is subject to the GNU Public License. + diff --git a/sys/gnu/misc/aic7xxx/aic7xxx.c b/sys/gnu/misc/aic7xxx/aic7xxx.c new file mode 100644 index 0000000000000..417a352762d31 --- /dev/null +++ b/sys/gnu/misc/aic7xxx/aic7xxx.c @@ -0,0 +1,584 @@ +/* + * Adaptec 274x device driver for Linux. + * Copyright (c) 1994 The University of Calgary Department of Computer Science. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Comments are started by `#' and continue to the end of the line; lines + * may be of the form: + * + * <label>* + * <label>* <undef-sym> = <value> + * <label>* <opcode> <operand>* + * + * A <label> is an <undef-sym> ending in a colon. Spaces, tabs, and commas + * are token separators. + */ + +/* #define _POSIX_SOURCE 1 */ +#define _POSIX_C_SOURCE 2 + +#include <ctype.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#define MEMORY 512 /* 2^9 29-bit words */ +#define MAXLINE 1024 +#define MAXTOKEN 32 +#define ADOTOUT "a.out" +#define NOVALUE -1 + +/* + * AIC-7770 register definitions + */ +#define R_SINDEX 0x65 +#define R_ALLONES 0x69 +#define R_ALLZEROS 0x6a +#define R_NONE 0x6a + +static +char sccsid[] = + "@(#)aic7770.c 1.10 94/07/22 jda"; + +int debug; +int lineno, LC; +char *filename; +FILE *ifp, *ofp; +unsigned char M[MEMORY][4]; + +void error(char *s) +{ + fprintf(stderr, "%s: %s at line %d\n", filename, s, lineno); + exit(EXIT_FAILURE); +} + +void *Malloc(size_t size) +{ + void *p = malloc(size); + if (!p) + error("out of memory"); + return(p); +} + +void *Realloc(void *ptr, size_t size) +{ + void *p = realloc(ptr, size); + if (!p) + error("out of memory"); + return(p); +} + +char *Strdup(char *s) +{ + char *p = (char *)Malloc(strlen(s) + 1); + strcpy(p, s); + return(p); +} + +typedef struct sym_t { + struct sym_t *next; /* MUST BE FIRST */ + char *name; + int value; + int npatch, *patch; +} sym_t; + +sym_t *head; + +void define(char *name, int value) +{ + sym_t *p, *q; + + for (p = head, q = (sym_t *)&head; p; p = p->next) { + if (!strcmp(p->name, name)) + error("redefined symbol"); + q = p; + } + + p = q->next = (sym_t *)Malloc(sizeof(sym_t)); + p->next = NULL; + p->name = Strdup(name); + p->value = value; + p->npatch = 0; + p->patch = NULL; + + if (debug) { + fprintf(stderr, "\"%s\" ", p->name); + if (p->value != NOVALUE) + fprintf(stderr, "defined as 0x%x\n", p->value); + else + fprintf(stderr, "undefined\n"); + } +} + +sym_t *lookup(char *name) +{ + sym_t *p; + + for (p = head; p; p = p->next) + if (!strcmp(p->name, name)) + return(p); + return(NULL); +} + +void patch(sym_t *p, int location) +{ + p->npatch += 1; + p->patch = (int *)Realloc(p->patch, p->npatch * sizeof(int *)); + + p->patch[p->npatch - 1] = location; +} + +void backpatch(void) +{ + int i; + sym_t *p; + + for (p = head; p; p = p->next) { + + if (p->value == NOVALUE) { + fprintf(stderr, + "%s: undefined symbol \"%s\"\n", + filename, p->name); + exit(EXIT_FAILURE); + } + + if (p->npatch) { + if (debug) + fprintf(stderr, + "\"%s\" (0x%x) patched at", + p->name, p->value); + + for (i = 0; i < p->npatch; i++) { + M[p->patch[i]][0] &= ~1; + M[p->patch[i]][0] |= ((p->value >> 8) & 1); + M[p->patch[i]][1] = p->value & 0xff; + + if (debug) + fprintf(stderr, " 0x%x", p->patch[i]); + } + + if (debug) + fputc('\n', stderr); + } + } +} + +/* + * Output words in byte-reversed order (least significant first) + * since the sequencer RAM is loaded that way. + */ +void output(FILE *fp) +{ + int i; + + for (i = 0; i < LC; i++) + fprintf(fp, "\t0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", + M[i][3], + M[i][2], + M[i][1], + M[i][0]); +} + +char **getl(int *n) +{ + int i; + char *p; + static char buf[MAXLINE]; + static char *a[MAXTOKEN]; + + i = 0; + + while (fgets(buf, sizeof(buf), ifp)) { + + lineno += 1; + + if (buf[strlen(buf)-1] != '\n') + error("line too long"); + + p = strchr(buf, '#'); + if (p) + *p = '\0'; + + for (p = strtok(buf, ", \t\n"); p; p = strtok(NULL, ", \t\n")) + if (i < MAXTOKEN-1) + a[i++] = p; + else + error("too many tokens"); + if (i) { + *n = i; + return(a); + } + } + return(NULL); +} + +#define A 0x8000 /* `A'ccumulator ok */ +#define I 0x4000 /* use as immediate value */ +#define SL 0x2000 /* shift left */ +#define SR 0x1000 /* shift right */ +#define RL 0x0800 /* rotate left */ +#define RR 0x0400 /* rotate right */ +#define LO 0x8000 /* lookup: ori-{jmp,jc,jnc,call} */ +#define LA 0x4000 /* lookup: and-{jz,jnz} */ +#define LX 0x2000 /* lookup: xor-{je,jne} */ +#define NA -1 /* not applicable */ + +struct { + char *name; + int n; /* number of operands, including opcode */ + unsigned int op; /* immediate or L?|pos_from_0 */ + unsigned int dest; /* NA, pos_from_0, or I|immediate */ + unsigned int src; /* NA, pos_from_0, or I|immediate */ + unsigned int imm; /* pos_from_0, A|pos_from_0, or I|immediate */ + unsigned int addr; /* NA or pos_from_0 */ + int fmt; /* instruction format - 1, 2, or 3 */ +} instr[] = { +/* + * N OP DEST SRC IMM ADDR FMT + */ + "mov", 3, 1, 1, 2, I|0xff, NA, 1, + "mov", 4, LO|2, NA, 1, I|0, 3, 3, + "mvi", 3, 0, 1, I|R_ALLZEROS, A|2, NA, 1, + "mvi", 4, LO|2, NA, I|R_ALLZEROS, 1, 3, 3, + "not", 2, 2, 1, 1, I|0xff, NA, 1, + "not", 3, 2, 1, 2, I|0xff, NA, 1, + "and", 3, 1, 1, 1, A|2, NA, 1, + "and", 4, 1, 1, 3, A|2, NA, 1, + "or", 3, 0, 1, 1, A|2, NA, 1, + "or", 4, 0, 1, 3, A|2, NA, 1, + "or", 5, LO|3, NA, 1, 2, 4, 3, + "xor", 3, 2, 1, 1, A|2, NA, 1, + "xor", 4, 2, 1, 3, A|2, NA, 1, + "nop", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, + "inc", 2, 3, 1, 1, I|1, NA, 1, + "inc", 3, 3, 1, 2, I|1, NA, 1, + "dec", 2, 3, 1, 1, I|0xff, NA, 1, + "dec", 3, 3, 1, 2, I|0xff, NA, 1, + "jmp", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "jc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "jnc", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "call", 2, LO|0, NA, I|R_SINDEX, I|0, 1, 3, + "test", 5, LA|3, NA, 1, A|2, 4, 3, + "cmp", 5, LX|3, NA, 1, A|2, 4, 3, + "ret", 1, 1, I|R_NONE, I|R_ALLZEROS, I|0xff, NA, 1, + "clc", 1, 3, I|R_NONE, I|R_ALLZEROS, I|1, NA, 1, + "clc", 4, 3, 2, I|R_ALLZEROS, A|3, NA, 1, + "stc", 1, 3, I|R_NONE, I|R_ALLONES, I|1, NA, 1, + "stc", 2, 3, 1, I|R_ALLONES, I|1, NA, 1, + "add", 3, 3, 1, 1, A|2, NA, 1, + "add", 4, 3, 1, 3, A|2, NA, 1, + "adc", 3, 4, 1, 1, A|2, NA, 1, + "adc", 4, 4, 1, 3, A|2, NA, 1, + "shl", 3, 5, 1, 1, SL|2, NA, 2, + "shl", 4, 5, 1, 2, SL|3, NA, 2, + "shr", 3, 5, 1, 1, SR|2, NA, 2, + "shr", 4, 5, 1, 2, SR|3, NA, 2, + "rol", 3, 5, 1, 1, RL|2, NA, 2, + "rol", 4, 5, 1, 2, RL|3, NA, 2, + "ror", 3, 5, 1, 1, RR|2, NA, 2, + "ror", 4, 5, 1, 2, RR|3, NA, 2, + /* + * Extensions (note also that mvi allows A) + */ + "clr", 2, 1, 1, I|R_ALLZEROS, I|0xff, NA, 1, + 0 +}; + +int eval_operand(char **a, int spec) +{ + int i; + unsigned int want = spec & (LO|LA|LX); + + static struct { + unsigned int what; + char *name; + int value; + } jmptab[] = { + LO, "jmp", 8, + LO, "jc", 9, + LO, "jnc", 10, + LO, "call", 11, + LA, "jz", 15, + LA, "jnz", 13, + LX, "je", 14, + LX, "jne", 12, + }; + + spec &= ~(LO|LA|LX); + + for (i = 0; i < sizeof(jmptab)/sizeof(jmptab[0]); i++) + if (jmptab[i].what == want && + !strcmp(jmptab[i].name, a[spec])) + { + return(jmptab[i].value); + } + + if (want) + error("invalid jump"); + + return(spec); /* "case 0" - no flags set */ +} + +int eval_sdi(char **a, int spec) +{ + sym_t *p; + unsigned val; + + if (spec == NA) + return(NA); + + switch (spec & (A|I|SL|SR|RL|RR)) { + case SL: + case SR: + case RL: + case RR: + if (isdigit(*a[spec &~ (SL|SR|RL|RR)])) + val = strtol(a[spec &~ (SL|SR|RL|RR)], NULL, 0); + else { + p = lookup(a[spec &~ (SL|SR|RL|RR)]); + if (!p) + error("undefined symbol used"); + val = p->value; + } + + switch (spec & (SL|SR|RL|RR)) { /* blech */ + case SL: + if (val > 7) + return(0xf0); + return(((val % 8) << 4) | + (val % 8)); + case SR: + if (val > 7) + return(0xf0); + return(((val % 8) << 4) | + (1 << 3) | + ((8 - (val % 8)) % 8)); + case RL: + return(val % 8); + case RR: + return((8 - (val % 8)) % 8); + } + case I: + return(spec &~ I); + case A: + /* + * An immediate field of zero selects + * the accumulator. Vigorously object + * if zero is given otherwise - it's + * most likely an error. + */ + spec &= ~A; + if (!strcmp("A", a[spec])) + return(0); + if (isdigit(*a[spec]) && + strtol(a[spec], NULL, 0) == 0) + { + error("immediate value of zero selects accumulator"); + } + /* falls through */ + case 0: + if (isdigit(*a[spec])) + return(strtol(a[spec], NULL, 0)); + p = lookup(a[spec]); + if (p) + return(p->value); + error("undefined symbol used"); + } + + return(NA); /* shut the compiler up */ +} + +int eval_addr(char **a, int spec) +{ + sym_t *p; + + if (spec == NA) + return(NA); + if (isdigit(*a[spec])) + return(strtol(a[spec], NULL, 0)); + + p = lookup(a[spec]); + + if (p) { + if (p->value != NOVALUE) + return(p->value); + patch(p, LC); + } else { + define(a[spec], NOVALUE); + p = lookup(a[spec]); + patch(p, LC); + } + + return(NA); /* will be patched in later */ +} + +int crack(char **a, int n) +{ + int i; + int I_imm, I_addr; + int I_op, I_dest, I_src, I_ret; + + /* + * Check for "ret" at the end of the line; remove + * it unless it's "ret" alone - we still want to + * look it up in the table. + */ + I_ret = (strcmp(a[n-1], "ret") ? 0 : !0); + if (I_ret && n > 1) + n -= 1; + + for (i = 0; instr[i].name; i++) { + /* + * Look for match in table given constraints, + * currently just the name and the number of + * operands. + */ + if (!strcmp(instr[i].name, *a) && instr[i].n == n) + break; + } + if (!instr[i].name) + error("unknown opcode or wrong number of operands"); + + I_op = eval_operand(a, instr[i].op); + I_src = eval_sdi(a, instr[i].src); + I_imm = eval_sdi(a, instr[i].imm); + I_dest = eval_sdi(a, instr[i].dest); + I_addr = eval_addr(a, instr[i].addr); + + switch (instr[i].fmt) { + case 1: + case 2: + M[LC][0] = (I_op << 1) | I_ret; + M[LC][1] = I_dest; + M[LC][2] = I_src; + M[LC][3] = I_imm; + break; + case 3: + if (I_ret) + error("illegal use of \"ret\""); + M[LC][0] = (I_op << 1) | ((I_addr >> 8) & 1); + M[LC][1] = I_addr & 0xff; + M[LC][2] = I_src; + M[LC][3] = I_imm; + break; + } + + return(1); /* no two-byte instructions yet */ +} + +#undef SL +#undef SR +#undef RL +#undef RR +#undef LX +#undef LA +#undef LO +#undef I +#undef A + +void assemble(void) +{ + int n; + char **a; + sym_t *p; + + while ((a = getl(&n))) { + + while (a[0][strlen(*a)-1] == ':') { + a[0][strlen(*a)-1] = '\0'; + p = lookup(*a); + if (p) + p->value = LC; + else + define(*a, LC); + a += 1; + n -= 1; + } + + if (!n) /* line was all labels */ + continue; + + if (n == 3 && !strcmp("VERSION", *a)) + fprintf(ofp, "#define %s \"%s\"\n", a[1], a[2]); + else { + if (n == 3 && !strcmp("=", a[1])) + define(*a, strtol(a[2], NULL, 0)); + else + LC += crack(a, n); + } + } + + backpatch(); + output(ofp); + + if (debug) + output(stderr); +} + +int main(int argc, char **argv) +{ + int c; + + while ((c = getopt(argc, argv, "dho:")) != EOF) { + switch (c) { + case 'd': + debug = !0; + break; + case 'o': + ofp = fopen(optarg, "w"); + if (!ofp) { + perror(optarg); + exit(EXIT_FAILURE); + } + break; + case 'h': + printf("usage: %s [-d] [-ooutput] input\n", *argv); + exit(EXIT_SUCCESS); + case NULL: + /* + * An impossible option to shut the compiler + * up about sccsid[]. + */ + exit((int)sccsid); + default: + exit(EXIT_FAILURE); + } + } + + if (argc - optind != 1) { + fprintf(stderr, "%s: must have one input file\n", *argv); + exit(EXIT_FAILURE); + } + filename = argv[optind]; + + ifp = fopen(filename, "r"); + if (!ifp) { + perror(filename); + exit(EXIT_FAILURE); + } + + if (!ofp) { + ofp = fopen(ADOTOUT, "w"); + if (!ofp) { + perror(ADOTOUT); + exit(EXIT_FAILURE); + } + } + + assemble(); + exit(EXIT_SUCCESS); +} diff --git a/sys/gnu/misc/aic7xxx/aic7xxx.seq b/sys/gnu/misc/aic7xxx/aic7xxx.seq new file mode 100644 index 0000000000000..9b83b84f5472d --- /dev/null +++ b/sys/gnu/misc/aic7xxx/aic7xxx.seq @@ -0,0 +1,1064 @@ +# @(#)aic7xxx.seq 1.30 94/11/09 jda +# +# Adaptec 274x device driver for Linux. +# Copyright (c) 1994 The University of Calgary Department of Computer Science. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +VERSION AIC7XXX_SEQ_VERSION 1.30 + +MAXSCB-1 = 0xf + +SCSISEQ = 0x00 +SXFRCTL0 = 0x01 +SXFRCTL1 = 0x02 +SCSISIGI = 0x03 +SCSISIGO = 0x03 +SCSIRATE = 0x04 +SCSIID = 0x05 +SCSIDATL = 0x06 +STCNT = 0x08 +STCNT+0 = 0x08 +STCNT+1 = 0x09 +STCNT+2 = 0x0a +SSTAT0 = 0x0b +CLRSINT1 = 0x0c +SSTAT1 = 0x0c +SIMODE1 = 0x11 +SCSIBUSL = 0x12 +SHADDR = 0x14 +SELID = 0x19 +SBLKCTL = 0x1f +SEQCTL = 0x60 +A = 0x64 # == ACCUM +SINDEX = 0x65 +DINDEX = 0x66 +ALLZEROS = 0x6a +NONE = 0x6a +SINDIR = 0x6c +DINDIR = 0x6d +FUNCTION1 = 0x6e +HADDR = 0x88 +HCNT = 0x8c +HCNT+0 = 0x8c +HCNT+1 = 0x8d +HCNT+2 = 0x8e +SCBPTR = 0x90 +INTSTAT = 0x91 +DFCNTRL = 0x93 +DFSTATUS = 0x94 +DFDAT = 0x99 +QINFIFO = 0x9b +QINCNT = 0x9c +QOUTFIFO = 0x9d + +SCSICONF = 0x5a + +# The two reserved bytes at SCBARRAY+1[23] are expected to be set to +# zero, and the reserved bit in SCBARRAY+0 is used as an internal flag +# to indicate whether or not to reload scatter-gather parameters after +# a disconnect. +# +SCBARRAY+0 = 0xa0 +SCBARRAY+1 = 0xa1 +SCBARRAY+2 = 0xa2 +SCBARRAY+3 = 0xa3 +SCBARRAY+7 = 0xa7 +SCBARRAY+11 = 0xab +SCBARRAY+14 = 0xae +SCBARRAY+15 = 0xaf +SCBARRAY+16 = 0xb0 +SCBARRAY+17 = 0xb1 +SCBARRAY+18 = 0xb2 +SCBARRAY+19 = 0xb3 +SCBARRAY+20 = 0xb4 +SCBARRAY+21 = 0xb5 +SCBARRAY+22 = 0xb6 +SCBARRAY+23 = 0xb7 +SCBARRAY+24 = 0xb8 +SCBARRAY+25 = 0xb9 + +SIGNAL_0 = 0x01 # unknown scsi bus phase +SIGNAL_1 = 0x11 # message reject +SIGNAL_2 = 0x21 # no IDENTIFY after reconnect +SIGNAL_3 = 0x31 # no cmd match for reconnect +SIGNAL_4 = 0x41 # SDTR -> SCSIRATE conversion +STATUS_ERROR = 0x51 + +# The host adapter card (at least the BIOS) uses 20-2f for SCSI +# device information, 32-33 and 5a-5f as well. Since we don't support +# wide or twin-bus SCSI, 28-2f can be reclaimed. As it turns out, the +# BIOS trashes 20-27 anyway, writing the synchronous negotiation results +# on top of the BIOS values, so we re-use those for our per-target +# scratchspace (actually a value that can be copied directly into +# SCSIRATE). This implies, since we can't get the BIOS config values, +# that all targets will be negotiated with for synchronous transfer. +# NEEDSDTR has one bit per target indicating if an SDTR message is +# needed for that device - this will be set initially, as well as +# after a bus reset condition. +# +# The high bit of DROPATN is set if ATN should be dropped before the ACK +# when outb is called. REJBYTE contains the first byte of a MESSAGE IN +# message, so the driver can report an intelligible error if a message is +# rejected. +# +# RESELECT's high bit is true if we are currently handling a reselect; +# its next-highest bit is true ONLY IF we've seen an IDENTIFY message +# from the reselecting target. If we haven't had IDENTIFY, then we have +# no idea what the lun is, and we can't select the right SCB register +# bank, so force a kernel panic if the target attempts a data in/out or +# command phase instead of corrupting something. +# +# Note that SG_NEXT occupies four bytes. +# +SYNCNEG = 0x20 +DISC_DSB_A = 0x32 + +DROPATN = 0x30 +REJBYTE = 0x31 +RESELECT = 0x34 + +MSG_FLAGS = 0x35 +MSG_LEN = 0x36 +MSG_START+0 = 0x37 +MSG_START+1 = 0x38 +MSG_START+2 = 0x39 +MSG_START+3 = 0x3a +MSG_START+4 = 0x3b +MSG_START+5 = 0x3c +-MSG_START+0 = 0xc9 # 2's complement of MSG_START+0 + +ARG_1 = 0x4c # sdtr conversion args & return +ARG_2 = 0x4d +RETURN_1 = 0x4c + +SIGSTATE = 0x4e # value written to SCSISIGO +NEEDSDTR = 0x4f # send SDTR message, 1 bit/trgt + +SG_SIZEOF = 0x8 # sizeof(struct scatterlist) +SG_NOLOAD = 0x50 # load SG pointer/length? +SG_COUNT = 0x51 # working value of SG count +SG_NEXT = 0x52 # working value of SG pointer +SG_NEXT+0 = 0x52 +SG_NEXT+1 = 0x53 +SG_NEXT+2 = 0x54 +SG_NEXT+3 = 0x55 + +SCBCOUNT = 0x56 # the actual number of SCBs +ACTIVE_A = 0x57 + +# Poll QINCNT for work - the lower three bits contain +# the number of entries in the Queue In FIFO. +# +start: + test SCSISIGI,0x4 jnz reselect # BSYI + test QINCNT,MAXSCB-1 jz start + +# We have at least one queued SCB now. Set the SCB pointer +# from the FIFO so we see the right bank of SCB registers, +# then set SCSI options and set the initiator and target +# SCSI IDs. +# + mov SCBPTR,QINFIFO + +# See if there is not already an active SCB for this target. This code +# will have to be modified when we add support for dual and wide busses. + + and FUNCTION1,0x70,SCBARRAY+1 + mov A,FUNCTION1 + test ACTIVE_A,A jz active +# Place the currently active back on the queue for later processing + mov QINFIFO, SCBPTR + jmp start + +# Mark the current target as busy and get working on the SCB +active: + or ACTIVE_A,A + mov SCBARRAY+1 call initialize + clr SG_NOLOAD + clr RESELECT + +# As soon as we get a successful selection, the target should go +# into the message out phase since we have ATN asserted. Prepare +# the message to send, locking out the device driver. If the device +# driver hasn't beaten us with an ABORT or RESET message, then tack +# on a SDTR negotation if required. +# +# Messages are stored in scratch RAM starting with a flag byte (high bit +# set means active message), one length byte, and then the message itself. +# + mov SCBARRAY+1 call disconnect # disconnect ok? + + and SINDEX,0x7,SCBARRAY+1 # lun + or SINDEX,A # return value from disconnect + or SINDEX,0x80 call mk_mesg # IDENTIFY message + + mov A,SINDEX + cmp MSG_START+0,A jne !message # did driver beat us? + mvi MSG_START+1 call mk_sdtr # build SDTR message if needed + +!message: + +# Enable selection phase as an initiator, and do automatic ATN +# after the selection. +# + mvi SCSISEQ,0x48 # ENSELO|ENAUTOATNO + +# Wait for successful arbitration. The AIC-7770 documentation says +# that SELINGO indicates successful arbitration, and that it should +# be used to look for SELDO. However, if the sequencer is paused at +# just the right time - a parallel fsck(8) on two drives did it for +# me - then SELINGO can flip back to false before we've seen it. This +# makes the sequencer sit in the arbitration loop forever. This is +# Not Good. +# +# Therefore, I've added a check in the arbitration loop for SELDO +# too. This could arguably be made a critical section by disabling +# pauses, but I don't want to make a potentially infinite loop a CS. +# I suppose you could fold it into the select loop, too, but since +# I've been hunting this bug for four days it's kinda like a trophy. +# +arbitrate: + test SSTAT0,0x40 jnz *select # SELDO + test SSTAT0,0x10 jz arbitrate # SELINGO + +# Wait for a successful selection. If the hardware selection +# timer goes off, then the driver gets the interrupt, so we don't +# need to worry about it. +# +select: + test SSTAT0,0x40 jz select # SELDO + jmp *select + +# Reselection is being initiated by a target - we've seen the BSY +# line driven active, and we didn't do it! Enable the reselection +# hardware, and wait for it to finish. Make a note that we've been +# reselected, but haven't seen an IDENTIFY message from the target +# yet. +# +reselect: + mvi SCSISEQ,0x10 # ENRSELI + +reselect1: + test SSTAT0,0x20 jz reselect1 # SELDI + mov SELID call initialize + + mvi RESELECT,0x80 # reselected, no IDENTIFY + +# After the [re]selection, make sure that the [re]selection enable +# bit is off. This chip is flaky enough without extra things +# turned on. Also clear the BUSFREE bit in SSTAT1 since we'll be +# using it shortly. +# +*select: + clr SCSISEQ + mvi CLRSINT1,0x8 # CLRBUSFREE + +# Main loop for information transfer phases. If BSY is false, then +# we have a bus free condition, expected or not. Otherwise, wait +# for the target to assert REQ before checking MSG, C/D and I/O +# for the bus phase. +# +# We can't simply look at the values of SCSISIGI here (if we want +# to do synchronous data transfer), because the target won't assert +# REQ if it's already sent us some data that we haven't acknowledged +# yet. +# +ITloop: + test SSTAT1,0x8 jnz p_busfree # BUSFREE + test SSTAT1,0x1 jz ITloop # REQINIT + + and A,0xe0,SCSISIGI # CDI|IOI|MSGI + + cmp ALLZEROS,A je p_dataout + cmp A,0x40 je p_datain + cmp A,0x80 je p_command + cmp A,0xc0 je p_status + cmp A,0xa0 je p_mesgout + cmp A,0xe0 je p_mesgin + + mvi INTSTAT,SIGNAL_0 # unknown - signal driver + +p_dataout: + mvi 0 call scsisig # !CDO|!IOO|!MSGO + call assert + call sg_load + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+23 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+23 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+19 call bcopy + + mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN| + # DIRECTION|FIFORESET + +# After a DMA finishes, save the final transfer pointer and count +# back into the SCB, in case a device disconnects in the middle of +# a transfer. Use SHADDR and STCNT instead of HADDR and HCNT, since +# it's a reflection of how many bytes were transferred on the SCSI +# (as opposed to the host) bus. +# + mvi A,3 + mvi DINDEX,SCBARRAY+23 + mvi STCNT call bcopy + + mvi A,4 + mvi DINDEX,SCBARRAY+19 + mvi SHADDR call bcopy + + call sg_advance + mov SCBARRAY+18,SG_COUNT # residual S/G count + + jmp ITloop + +p_datain: + mvi 0x40 call scsisig # !CDO|IOO|!MSGO + call assert + call sg_load + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+23 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+23 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+19 call bcopy + + mvi 0x39 call dma # SCSIEN|SDMAEN|HDMAEN| + # !DIRECTION|FIFORESET + mvi A,3 + mvi DINDEX,SCBARRAY+23 + mvi STCNT call bcopy + + mvi A,4 + mvi DINDEX,SCBARRAY+19 + mvi SHADDR call bcopy + + call sg_advance + mov SCBARRAY+18,SG_COUNT # residual S/G count + + jmp ITloop + +# Command phase. Set up the DMA registers and let 'er rip - the +# two bytes after the SCB SCSI_cmd_length are zeroed by the driver, +# so we can copy those three bytes directly into HCNT. +# +p_command: + mvi 0x80 call scsisig # CDO|!IOO|!MSGO + call assert + + mvi A,3 + mvi DINDEX,HCNT + mvi SCBARRAY+11 call bcopy + + mvi A,3 + mvi DINDEX,STCNT + mvi SCBARRAY+11 call bcopy + + mvi A,4 + mvi DINDEX,HADDR + mvi SCBARRAY+7 call bcopy + + mvi 0x3d call dma # SCSIEN|SDMAEN|HDMAEN| + # DIRECTION|FIFORESET + jmp ITloop + +# Status phase. Wait for the data byte to appear, then read it +# and store it into the SCB. +# +p_status: + mvi 0xc0 call scsisig # CDO|IOO|!MSGO + + mvi SCBARRAY+14 call inb + jmp ITloop + +# Message out phase. If there is no active message, but the target +# took us into this phase anyway, build a no-op message and send it. +# +p_mesgout: + mvi 0xa0 call scsisig # CDO|!IOO|MSGO + mvi 0x8 call mk_mesg # build NOP message + +# Set up automatic PIO transfer from MSG_START. Bit 3 in +# SXFRCTL0 (SPIOEN) is already on. +# + mvi SINDEX,MSG_START+0 + mov DINDEX,MSG_LEN + clr A + +# When target asks for a byte, drop ATN if it's the last one in +# the message. Otherwise, keep going until the message is exhausted. +# (We can't use outb for this since it wants the input in SINDEX.) +# +# Keep an eye out for a phase change, in case the target issues +# a MESSAGE REJECT. +# +p_mesgout2: + test SSTAT0,0x2 jz p_mesgout2 # SPIORDY + test SSTAT1,0x10 jnz p_mesgout6 # PHASEMIS + + cmp DINDEX,1 jne p_mesgout3 # last byte? + mvi CLRSINT1,0x40 # CLRATNO - drop ATN + +# Write a byte to the SCSI bus. The AIC-7770 refuses to automatically +# send ACKs in automatic PIO or DMA mode unless you make sure that the +# "expected" bus phase in SCSISIGO matches the actual bus phase. This +# behaviour is completely undocumented and caused me several days of +# grief. +# +# After plugging in different drives to test with and using a longer +# SCSI cable, I found that I/O in Automatic PIO mode ceased to function, +# especially when transferring >1 byte. It seems to be much more stable +# if STCNT is set to one before the transfer, and SDONE (in SSTAT0) is +# polled for transfer completion - for both output _and_ input. The +# only theory I have is that SPIORDY doesn't drop right away when SCSIDATL +# is accessed (like the documentation says it does), and that on a longer +# cable run, the sequencer code was fast enough to loop back and see +# an SPIORDY that hadn't dropped yet. +# +p_mesgout3: + call one_stcnt + mov SCSIDATL,SINDIR + +p_mesgout4: + test SSTAT0,0x4 jz p_mesgout4 # SDONE + dec DINDEX + inc A + cmp MSG_LEN,A jne p_mesgout2 + +# If the next bus phase after ATN drops is a message out, it means +# that the target is requesting that the last message(s) be resent. +# +p_mesgout5: + test SSTAT1,0x8 jnz p_mesgout6 # BUSFREE + test SSTAT1,0x1 jz p_mesgout5 # REQINIT + + and A,0xe0,SCSISIGI # CDI|IOI|MSGI + cmp A,0xa0 jne p_mesgout6 + mvi 0x10 call scsisig # ATNO - re-assert ATN + + jmp ITloop + +p_mesgout6: + mvi CLRSINT1,0x40 # CLRATNO - in case of PHASEMIS + clr MSG_FLAGS # no active msg + jmp ITloop + +# Message in phase. Bytes are read using Automatic PIO mode, but not +# using inb. This alleviates a race condition, namely that if ATN had +# to be asserted under Automatic PIO mode, it had to beat the SCSI +# circuitry sending an ACK to the target. This showed up under heavy +# loads and really confused things, since ABORT commands wouldn't be +# seen by the drive after an IDENTIFY message in until it had changed +# to a data I/O phase. +# +p_mesgin: + mvi 0xe0 call scsisig # CDO|IOO|MSGO + mvi A call inb_first # read the 1st message byte + mvi REJBYTE,A # save it for the driver + + cmp ALLZEROS,A jne p_mesgin1 + +# We got a "command complete" message, so put the SCB pointer +# into the Queue Out, and trigger a completion interrupt. +# Check status for non zero return and interrupt driver if needed +# This allows the driver to do a sense command to find out the +# source of error. We don't bother to post to the QOUTFIFO in +# the error case since it would require extra work in the kernel +# driver to ensure that the entry was removed before the command +# complete code tried processing it. + +# First, mark this target as free. + and FUNCTION1,0x70,SCBARRAY+1 + mov A,FUNCTION1 + xor ACTIVE_A,A + + test SCBARRAY+14,0xff jz status_ok # 0 Status? + call inb_last # ack & turn auto PIO back on + mvi INTSTAT,STATUS_ERROR # let driver know + jmp ITloop +status_ok: + mov QOUTFIFO,SCBPTR + mvi INTSTAT,0x2 # CMDCMPLT + jmp p_mesgin_done + +# Is it an extended message? We only support the synchronous data +# transfer request message, which will probably be in response to +# an SDTR message out from us. If it's not an SDTR, reject it - +# apparently this can be done after any message in byte, according +# to the SCSI-2 spec. +# +# XXX - we should really reject this if we didn't initiate the SDTR +# negotiation; this may cause problems with unusual devices. +# +p_mesgin1: + cmp A,1 jne p_mesgin2 # extended message code? + + mvi A call inb_next + cmp A,3 jne p_mesginN # extended mesg length = 3 + mvi A call inb_next + cmp A,1 jne p_mesginN # SDTR code + + mvi ARG_1 call inb_next # xfer period + mvi ARG_2 call inb_next # REQ/ACK offset + mvi INTSTAT,SIGNAL_4 # call driver to convert + + call ndx_sdtr # index sync config for target + mov DINDEX,SINDEX + mov DINDIR,RETURN_1 # save returned value + + not A # turn off "need sdtr" flag + and NEEDSDTR,A + +# Even though the SCSI-2 specification says that a device responding +# to our SDTR message should honor our parameters for transmitting +# to us, it doesn't seem to work too well in real life. In particular, +# a lot of CD-ROM and tape units don't function: try using the SDTR +# parameters the device sent us for both transmitting and receiving. +# + mov SCSIRATE,RETURN_1 + jmp p_mesgin_done + +# Is it a disconnect message? Set a flag in the SCB to remind us +# and await the bus going free. +# +p_mesgin2: + cmp A,4 jne p_mesgin3 # disconnect code? + + or SCBARRAY+0,0x4 # set "disconnected" bit + jmp p_mesgin_done + +# Save data pointers message? Copy working values into the SCB, +# usually in preparation for a disconnect. +# +p_mesgin3: + cmp A,2 jne p_mesgin4 # save data pointers code? + + call sg_ram2scb + jmp p_mesgin_done + +# Restore pointers message? Data pointers are recopied from the +# SCB anyway at the start of any DMA operation, so the only thing +# to copy is the scatter-gather values. +# +p_mesgin4: + cmp A,3 jne p_mesgin5 # restore pointers code? + + call sg_scb2ram + jmp p_mesgin_done + +# Identify message? For a reconnecting target, this tells us the lun +# that the reconnection is for - find the correct SCB and switch to it, +# clearing the "disconnected" bit so we don't "find" it by accident later. +# +p_mesgin5: + test A,0x80 jz p_mesgin6 # identify message? + + test A,0x78 jnz p_mesginN # !DiscPriv|!LUNTAR|!Reserved + + mov A call findSCB # switch to correct SCB + +# If a active message is present after calling findSCB, then either it +# or the driver is trying to abort the command. Either way, something +# untoward has happened and we should just leave it alone. +# + test MSG_FLAGS,0x80 jnz p_mesgin_done + + xor SCBARRAY+0,0x4 # clear disconnect bit in SCB + mvi RESELECT,0xc0 # make note of IDENTIFY + + call sg_scb2ram # implied restore pointers + # required on reselect + jmp p_mesgin_done + +# Message reject? If we have an outstanding SDTR negotiation, assume +# that it's a response from the target selecting asynchronous transfer, +# otherwise just ignore it since we have no clue what it pertains to. +# +# XXX - I don't have a device that responds this way. Does this code +# actually work? +# +p_mesgin6: + cmp A,7 jne p_mesgin7 # message reject code? + + and FUNCTION1,0x70,SCSIID # outstanding SDTR message? + mov A,FUNCTION1 + test NEEDSDTR,A jz p_mesgin_done # no - ignore rejection + + call ndx_sdtr # note use of asynch xfer + mov DINDEX,SINDEX + clr DINDIR + + not A # turn off "active sdtr" flag + and NEEDSDTR,A + + clr SCSIRATE # select asynch xfer + jmp p_mesgin_done + +# [ ADD MORE MESSAGE HANDLING HERE ] +# +p_mesgin7: + +# We have no idea what this message in is, and there's no way +# to pass it up to the kernel, so we issue a message reject and +# hope for the best. Since we're now using manual PIO mode to +# read in the message, there should no longer be a race condition +# present when we assert ATN. In any case, rejection should be a +# rare occurrence - signal the driver when it happens. +# +p_mesginN: + or SINDEX,0x10,SIGSTATE # turn on ATNO + call scsisig + mvi INTSTAT,SIGNAL_1 # let driver know + + mvi 0x7 call mk_mesg # MESSAGE REJECT message + +p_mesgin_done: + call inb_last # ack & turn auto PIO back on + jmp ITloop + +# Bus free phase. It might be useful to interrupt the device +# driver if we aren't expecting this. For now, make sure that +# ATN isn't being asserted and look for a new command. +# +p_busfree: + mvi CLRSINT1,0x40 # CLRATNO + clr SIGSTATE + jmp start + +# Bcopy: number of bytes to transfer should be in A, DINDEX should +# contain the destination address, and SINDEX should contain the +# source address. All input parameters are trashed on return. +# +bcopy: + mov DINDIR,SINDIR + dec A + cmp ALLZEROS,A jne bcopy + ret + +# Locking the driver out, build a one-byte message passed in SINDEX +# if there is no active message already. SINDEX is returned intact. +# +mk_mesg: + mvi SEQCTL,0x40 # PAUSEDIS + test MSG_FLAGS,0x80 jnz mk_mesg1 # active message? + + mvi MSG_FLAGS,0x80 # if not, there is now + mvi MSG_LEN,1 # length = 1 + mov MSG_START+0,SINDEX # 1-byte message + +mk_mesg1: + clr SEQCTL # !PAUSEDIS + ret + +# Input byte in Automatic PIO mode. The address to store the byte +# in should be in SINDEX. DINDEX will be used by this routine. +# +inb: + test SSTAT0,0x2 jz inb # SPIORDY + mov DINDEX,SINDEX + call one_stcnt # xfer one byte + mov DINDIR,SCSIDATL +inb1: + test SSTAT0,0x4 jz inb1 # SDONE - wait to "finish" + ret + +# Carefully read data in Automatic PIO mode. I first tried this using +# Manual PIO mode, but it gave me continual underrun errors, probably +# indicating that I did something wrong, but I feel more secure leaving +# Automatic PIO on all the time. +# +# According to Adaptec's documentation, an ACK is not sent on input from +# the target until SCSIDATL is read from. So we wait until SCSIDATL is +# latched (the usual way), then read the data byte directly off the bus +# using SCSIBUSL. When we have pulled the ATN line, or we just want to +# acknowledge the byte, then we do a dummy read from SCISDATL. The SCSI +# spec guarantees that the target will hold the data byte on the bus until +# we send our ACK. +# +# The assumption here is that these are called in a particular sequence, +# and that REQ is already set when inb_first is called. inb_{first,next} +# use the same calling convention as inb. +# +inb_first: + mov DINDEX,SINDEX + mov DINDIR,SCSIBUSL ret # read byte directly from bus + +inb_next: + mov DINDEX,SINDEX # save SINDEX + + call one_stcnt # xfer one byte + mov NONE,SCSIDATL # dummy read from latch to ACK +inb_next1: + test SSTAT0,0x4 jz inb_next1 # SDONE +inb_next2: + test SSTAT0,0x2 jz inb_next2 # SPIORDY - wait for next byte + mov DINDIR,SCSIBUSL ret # read byte directly from bus + +inb_last: + call one_stcnt # ACK with dummy read + mov NONE,SCSIDATL +inb_last1: + test SSTAT0,0x4 jz inb_last1 # wait for completion + ret + +# Output byte in Automatic PIO mode. The byte to output should be +# in SINDEX. If DROPATN's high bit is set, then ATN will be dropped +# before the byte is output. +# +outb: + test SSTAT0,0x2 jz outb # SPIORDY + call one_stcnt # xfer one byte + + test DROPATN,0x80 jz outb1 + mvi CLRSINT1,0x40 # CLRATNO + clr DROPATN +outb1: + mov SCSIDATL,SINDEX +outb2: + test SSTAT0,0x4 jz outb2 # SDONE + ret + +# Write the value "1" into the STCNT registers, for Automatic PIO +# transfers. +# +one_stcnt: + clr STCNT+2 + clr STCNT+1 + mvi STCNT+0,1 ret + +# DMA data transfer. HADDR and HCNT must be loaded first, and +# SINDEX should contain the value to load DFCNTRL with - 0x3d for +# host->scsi, or 0x39 for scsi->host. The SCSI channel is cleared +# during initialization. +# +dma: + mov DFCNTRL,SINDEX +dma1: +dma2: + test SSTAT0,0x1 jnz dma3 # DMADONE + test SSTAT1,0x10 jz dma1 # PHASEMIS, ie. underrun + +# We will be "done" DMAing when the transfer count goes to zero, or +# the target changes the phase (in light of this, it makes sense that +# the DMA circuitry doesn't ACK when PHASEMIS is active). If we are +# doing a SCSI->Host transfer, flush the data FIFO. +# +dma3: + test SINDEX,0x4 jnz dma5 # DIRECTION + and SINDEX,0xfe # mask out FIFORESET + or DFCNTRL,0x2,SINDEX # FIFOFLUSH +dma4: + test DFCNTRL,0x2 jnz dma4 # FIFOFLUSHACK + +# Now shut the DMA enables off, and copy STCNT (ie. the underrun +# amount, if any) to the SCB registers; SG_COUNT will get copied to +# the SCB's residual S/G count field after sg_advance is called. Make +# sure that the DMA enables are actually off first lest we get an ILLSADDR. +# +dma5: + clr DFCNTRL # disable DMA +dma6: + test DFCNTRL,0x38 jnz dma6 # SCSIENACK|SDMAENACK|HDMAENACK + + mvi A,3 + mvi DINDEX,SCBARRAY+15 + mvi STCNT call bcopy + + ret + +# Common SCSI initialization for selection and reselection. Expects +# the target SCSI ID to be in the upper four bits of SINDEX, and A's +# contents are stomped on return. +# +initialize: + clr SBLKCTL # channel A, !wide + and SCSIID,0xf0,SINDEX # target ID + and A,0x7,SCSICONF # SCSI_ID_A[210] + or SCSIID,A + +# Esundry initialization. +# + clr DROPATN + clr SIGSTATE + +# Turn on Automatic PIO mode now, before we expect to see an REQ +# from the target. It shouldn't hurt anything to leave it on. Set +# CLRCHN here before the target has entered a data transfer mode - +# with synchronous SCSI, if you do it later, you blow away some +# data in the SCSI FIFO that the target has already sent to you. +# + mvi SXFRCTL0,0xa # SPIOEN|CLRCHN + +# Set SCSI bus parity checking and the selection timeout value, +# and enable the hardware selection timer. Set the SELTO interrupt +# to signal the driver. +# + and A,0x38,SCSICONF # PARITY_ENB_A|SEL_TIM_A[10] + or SXFRCTL1,0x4,A # ENSTIMER + mvi SIMODE1,0x84 # ENSELTIMO|ENSCSIPERR + +# Initialize scatter-gather pointers by setting up the working copy +# in scratch RAM. +# + call sg_scb2ram + +# Initialize SCSIRATE with the appropriate value for this target. +# + call ndx_sdtr + mov SCSIRATE,SINDIR + ret + +# Assert that if we've been reselected, then we've seen an IDENTIFY +# message. +# +assert: + test RESELECT,0x80 jz assert1 # reselected? + test RESELECT,0x40 jnz assert1 # seen IDENTIFY? + + mvi INTSTAT,SIGNAL_2 # no - cause a kernel panic + +assert1: + ret + +# Find out if disconnection is ok from the information the BIOS has left +# us. The target ID should be in the upper four bits of SINDEX; A will +# contain either 0x40 (disconnection ok) or 0x00 (diconnection not ok) +# on exit. +# +# This is the only place the target ID is limited to three bits, so we +# can use the FUNCTION1 register. +# +disconnect: + and FUNCTION1,0x70,SINDEX # strip off extra just in case + mov A,FUNCTION1 + test DISC_DSB_A,A jz disconnect1 # bit nonzero if DISabled + + clr A ret +disconnect1: + mvi A,0x40 ret + +# Locate the SCB matching the target ID in SELID and the lun in the lower +# three bits of SINDEX, and switch the SCB to it. Have the kernel print +# a warning message if it can't be found, and generate an ABORT message +# to the target. We keep the value of the t/c/l that we are trying to +# in DINDEX so it is not overwritten during our check to see if we are +# at the last SCB. +# +findSCB: + and A,0x7,SINDEX # lun in lower three bits + or DINDEX,A,SELID # can I do this? + and DINDEX,0xf7 # only channel A implemented + + clr SINDEX + +findSCB1: + mov SCBPTR,SINDEX # switch to new SCB + mov A,DINDEX + cmp SCBARRAY+1,A jne findSCB2 # target ID/channel/lun match? + test SCBARRAY+0,0x4 jz findSCB2 # should be disconnected + + ret + +findSCB2: + inc SINDEX + mov A,SCBCOUNT + cmp SINDEX,A jne findSCB1 + + mvi INTSTAT,SIGNAL_3 # not found - signal kernel + mvi 0x6 call mk_mesg # ABORT message + + or SINDEX,0x10,SIGSTATE # assert ATNO + call scsisig + ret + +# Make a working copy of the scatter-gather parameters in the SCB. +# +sg_scb2ram: + mov SG_COUNT,SCBARRAY+2 + + mvi A,4 + mvi DINDEX,SG_NEXT + mvi SCBARRAY+3 call bcopy + + mvi SG_NOLOAD,0x80 + test SCBARRAY+0,0x10 jnz sg_scb2ram1 # don't reload s/g? + clr SG_NOLOAD + +sg_scb2ram1: + ret + +# Copying RAM values back to SCB, for Save Data Pointers message. +# +sg_ram2scb: + mov SCBARRAY+2,SG_COUNT + + mvi A,4 + mvi DINDEX,SCBARRAY+3 + mvi SG_NEXT call bcopy + + and SCBARRAY+0,0xef,SCBARRAY+0 + test SG_NOLOAD,0x80 jz sg_ram2scb1 # reload s/g? + or SCBARRAY+0,0x10 + +sg_ram2scb1: + ret + +# Load a struct scatter if needed and set up the data address and +# length. If the working value of the SG count is nonzero, then +# we need to load a new set of values. +# +# This, like the above DMA, assumes a little-endian host data storage. +# +sg_load: + test SG_COUNT,0xff jz sg_load3 # SG being used? + test SG_NOLOAD,0x80 jnz sg_load3 # don't reload s/g? + + clr HCNT+2 + clr HCNT+1 + mvi HCNT+0,SG_SIZEOF + + mvi A,4 + mvi DINDEX,HADDR + mvi SG_NEXT call bcopy + + mvi DFCNTRL,0xd # HDMAEN|DIRECTION|FIFORESET + +# Wait for DMA from host memory to data FIFO to complete, then disable +# DMA and wait for it to acknowledge that it's off. +# +sg_load1: + test DFSTATUS,0x8 jz sg_load1 # HDONE + + clr DFCNTRL # disable DMA +sg_load2: + test DFCNTRL,0x8 jnz sg_load2 # HDMAENACK + +# Copy data from FIFO into SCB data pointer and data count. This assumes +# that the struct scatterlist has this structure (this and sizeof(struct +# scatterlist) == 12 are asserted in aic7xxx.c): +# +# struct scatterlist { +# char *address; /* four bytes, little-endian order */ +# ... /* four bytes, ignored */ +# unsigned short length; /* two bytes, little-endian order */ +# } +# + +# Not in FreeBSD. the scatter list is only 8 bytes. +# +# struct ahc_dma_seg { +# physaddr addr; /* four bytes, little-endian order */ +# long len; /* four bytes, little endian order */ +# }; +# + + mov SCBARRAY+19,DFDAT # new data address + mov SCBARRAY+20,DFDAT + mov SCBARRAY+21,DFDAT + mov SCBARRAY+22,DFDAT + + mov SCBARRAY+23,DFDAT + mov SCBARRAY+24,DFDAT + mov SCBARRAY+25,DFDAT + mov NONE,DFDAT #Only support 24 bit length. + +sg_load3: + ret + +# Advance the scatter-gather pointers only IF NEEDED. If SG is enabled, +# and the SCSI transfer count is zero (note that this should be called +# right after a DMA finishes), then move the working copies of the SG +# pointer/length along. If the SCSI transfer count is not zero, then +# presumably the target is disconnecting - do not reload the SG values +# next time. +# +sg_advance: + test SG_COUNT,0xff jz sg_advance2 # s/g enabled? + + test STCNT+0,0xff jnz sg_advance1 # SCSI transfer count nonzero? + test STCNT+1,0xff jnz sg_advance1 + test STCNT+2,0xff jnz sg_advance1 + + clr SG_NOLOAD # reload s/g next time + dec SG_COUNT # one less segment to go + + clr A # add sizeof(struct scatter) + add SG_NEXT+0,SG_SIZEOF,SG_NEXT+0 + adc SG_NEXT+1,A,SG_NEXT+1 + adc SG_NEXT+2,A,SG_NEXT+2 + adc SG_NEXT+3,A,SG_NEXT+3 + + ret + +sg_advance1: + mvi SG_NOLOAD,0x80 # don't reload s/g next time +sg_advance2: + ret + +# Add the array base SYNCNEG to the target offset (the target address +# is in SCSIID), and return the result in SINDEX. The accumulator +# contains the 3->8 decoding of the target ID on return. +# +ndx_sdtr: + shr A,SCSIID,4 + and A,0x7 + add SINDEX,SYNCNEG,A + + and FUNCTION1,0x70,SCSIID # 3-bit target address decode + mov A,FUNCTION1 ret + +# If we need to negotiate transfer parameters, build the SDTR message +# starting at the address passed in SINDEX. DINDEX is modified on return. +# +mk_sdtr: + mov DINDEX,SINDEX # save SINDEX + + call ndx_sdtr + test NEEDSDTR,A jnz mk_sdtr1 # do we need negotiation? + ret + +mk_sdtr1: + mvi DINDIR,1 # extended message + mvi DINDIR,3 # extended message length = 3 + mvi DINDIR,1 # SDTR code + mvi DINDIR,25 # REQ/ACK transfer period + mvi DINDIR,15 # REQ/ACK offset + + add MSG_LEN,-MSG_START+0,DINDEX # update message length + ret + +# Set SCSI bus control signal state. This also saves the last-written +# value into a location where the higher-level driver can read it - if +# it has to send an ABORT or RESET message, then it needs to know this +# so it can assert ATN without upsetting SCSISIGO. The new value is +# expected in SINDEX. Change the actual state last to avoid contention +# from the driver. +# +scsisig: + mov SIGSTATE,SINDEX + mov SCSISIGO,SINDEX ret + |
