COMPLETE.TXT
上传用户:jnzhq888
上传日期:2007-01-18
资源大小:51694k
文件大小:2624k
- 09704 #define COPROC_ERR_VECTOR 16 /* coprocessor error */
- 09705
- 09706 /* Descriptor structure offsets. */
- 09707 #define DESC_GRANULARITY 6 /* to granularity byte */
- 09708 #define DESC_BASE_HIGH 7 /* to base_high */
- 09709
- 09710 /* Base and limit sizes and shifts. */
- 09711 #define BASE_HIGH_SHIFT 24 /* shift for base --> base_high */
- 09712 #define BYTE_GRAN_MAX 0xFFFFFL /* maximum size for byte granular segment */
- 09713 #define GRANULARITY_SHIFT 16 /* shift for limit --> granularity */
- 09714 #define OFFSET_HIGH_SHIFT 16 /* shift for (gate) offset --> offset_high */
- 09715 #define PAGE_GRAN_SHIFT 12 /* extra shift for page granular limits */
- 09716
- 09717 /* Type-byte bits. */
- 09718 #define DESC_386_BIT 0x08 /* 386 types are obtained by ORing with this */
- 09719 /* LDT's and TASK_GATE's don't need it */
- 09720
- 09721 /* Granularity byte. */
- 09722 #define GRANULAR 0x80 /* set for 4K granularilty */
- 09723 #define DEFAULT 0x40 /* set for 32-bit defaults (executable seg) */
- 09724 #define BIG 0x40 /* set for "BIG" (expand-down seg) */
- 09725 #define AVL 0x10 /* 0 for available */
- 09726 #define LIMIT_HIGH 0x0F /* mask for high bits of limit */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/proto.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 09800 /* Function prototypes. */
- 09801
- 09802 #ifndef PROTO_H
- 09803 #define PROTO_H
- 09804
- 09805 /* Struct declarations. */
- 09806 struct dpeth;
- 09807 struct proc;
- 09808 struct tty;
- 09809
- 09810 /* at_wini.c, bios_wini.c, esdi_wini.c, ps_wini.c, xt_wini.c, wini.c */
- 09811 _PROTOTYPE( void winchester_task, (void) );
- 09812 _PROTOTYPE( void at_winchester_task, (void) );
- 09813 _PROTOTYPE( void bios_winchester_task, (void) );
- 09814 _PROTOTYPE( void esdi_winchester_task, (void) );
- 09815 _PROTOTYPE( void ps_winchester_task, (void) );
- 09816 _PROTOTYPE( void xt_winchester_task, (void) );
- 09817
- 09818 /* aha_scsi.c */
- 09819 _PROTOTYPE( void aha_scsi_task, (void) );
- 09820
- 09821 /* clock.c */
- 09822 _PROTOTYPE( void clock_task, (void) );
- 09823 _PROTOTYPE( void clock_stop, (void) );
- 09824 _PROTOTYPE( clock_t get_uptime, (void) );
- 09825 _PROTOTYPE( void syn_alrm_task, (void) );
- 09826
- 09827 /* dmp.c */
- 09828 _PROTOTYPE( void map_dmp, (void) );
- 09829 _PROTOTYPE( void p_dmp, (void) );
- 09830 _PROTOTYPE( void reg_dmp, (struct proc *rp) );
- 09831
- 09832 /* dp8390.c */
- 09833 _PROTOTYPE( void dp8390_task, (void) );
- 09834 _PROTOTYPE( void dp_dump, (void) );
- 09835 _PROTOTYPE( void dp8390_stop, (void) );
- 09836
- 09837 /* floppy.c, stfloppy.c */
- 09838 _PROTOTYPE( void floppy_task, (void) );
- 09839 _PROTOTYPE( void floppy_stop, (void) );
- 09840
- 09841 /* main.c, stmain.c */
- 09842 _PROTOTYPE( void main, (void) );
- 09843 _PROTOTYPE( void panic, (const char *s, int n) );
- 09844
- 09845 /* mcd.c */
- 09846 _PROTOTYPE( void mcd_task, (void) );
- 09847
- 09848 /* memory.c */
- 09849 _PROTOTYPE( void mem_task, (void) );
- 09850
- 09851 /* misc.c */
- 09852 _PROTOTYPE( int env_parse, (char *env, char *fmt, int field,
- 09853 long *param, long min, long max) );
- 09854
- 09855 /* printer.c, stprint.c */
- 09856 _PROTOTYPE( void printer_task, (void) );
- 09857
- 09858 /* proc.c */
- 09859 _PROTOTYPE( void interrupt, (int task) );
- 09860 _PROTOTYPE( int lock_mini_send, (struct proc *caller_ptr,
- 09861 int dest, message *m_ptr) );
- 09862 _PROTOTYPE( void lock_pick_proc, (void) );
- 09863 _PROTOTYPE( void lock_ready, (struct proc *rp) );
- 09864 _PROTOTYPE( void lock_sched, (void) );
- 09865 _PROTOTYPE( void lock_unready, (struct proc *rp) );
- 09866 _PROTOTYPE( int sys_call, (int function, int src_dest, message *m_ptr) );
- 09867 _PROTOTYPE( void unhold, (void) );
- 09868
- 09869 /* rs232.c */
- 09870 _PROTOTYPE( void rs_init, (struct tty *tp) );
- 09871
- 09872 /* sb16_dsp.c */
- 09873 _PROTOTYPE( void dsp_task, (void) );
- 09874
- 09875 /* sb16_mixer.c */
- 09876 _PROTOTYPE( void mixer_task, (void) );
- 09877
- 09878 /* system.c */
- 09879 _PROTOTYPE( void cause_sig, (int proc_nr, int sig_nr) );
- 09880 _PROTOTYPE( void inform, (void) );
- 09881 _PROTOTYPE( phys_bytes numap, (int proc_nr, vir_bytes vir_addr,
- 09882 vir_bytes bytes) );
- 09883 _PROTOTYPE( void sys_task, (void) );
- 09884 _PROTOTYPE( phys_bytes umap, (struct proc *rp, int seg, vir_bytes vir_addr,
- 09885 vir_bytes bytes) );
- 09886
- 09887 /* tty.c */
- 09888 _PROTOTYPE( void handle_events, (struct tty *tp) );
- 09889 _PROTOTYPE( void sigchar, (struct tty *tp, int sig) );
- 09890 _PROTOTYPE( void tty_task, (void) );
- 09891 _PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count) );
- 09892 _PROTOTYPE( void out_process, (struct tty *tp, char *bstart, char *bpos,
- 09893 char *bend, int *icount, int *ocount) );
- 09894 _PROTOTYPE( void tty_wakeup, (clock_t now) );
- 09895 _PROTOTYPE( void tty_reply, (int code, int replyee, int proc_nr,
- 09896 int status) );
- 09897 _PROTOTYPE( void tty_devnop, (struct tty *tp) );
- 09898
- 09899 /* library */
- 09900 _PROTOTYPE( void *memcpy, (void *_s1, const void *_s2, size_t _n) );
- 09901
- 09902 #if (CHIP == INTEL)
- 09903
- 09904 /* clock.c */
- 09905 _PROTOTYPE( void milli_start, (struct milli_state *msp) );
- 09906 _PROTOTYPE( unsigned milli_elapsed, (struct milli_state *msp) );
- 09907 _PROTOTYPE( void milli_delay, (unsigned millisec) );
- 09908
- 09909 /* console.c */
- 09910 _PROTOTYPE( void cons_stop, (void) );
- 09911 _PROTOTYPE( void putk, (int c) );
- 09912 _PROTOTYPE( void scr_init, (struct tty *tp) );
- 09913 _PROTOTYPE( void toggle_scroll, (void) );
- 09914 _PROTOTYPE( int con_loadfont, (phys_bytes user_phys) );
- 09915 _PROTOTYPE( void select_console, (int cons_line) );
- 09916
- 09917 /* cstart.c */
- 09918 _PROTOTYPE( void cstart, (U16_t cs, U16_t ds, U16_t mcs, U16_t mds,
- 09919 U16_t parmoff, U16_t parmsize) );
- 09920 _PROTOTYPE( char *k_getenv, (char *name) );
- 09921
- 09922 /* exception.c */
- 09923 _PROTOTYPE( void exception, (unsigned vec_nr) );
- 09924
- 09925 /* i8259.c */
- 09926 _PROTOTYPE( irq_handler_t get_irq_handler, (int irq) );
- 09927 _PROTOTYPE( void put_irq_handler, (int irq, irq_handler_t handler) );
- 09928 _PROTOTYPE( void intr_init, (int mine) );
- 09929
- 09930 /* keyboard.c */
- 09931 _PROTOTYPE( void kb_init, (struct tty *tp) );
- 09932 _PROTOTYPE( int kbd_loadmap, (phys_bytes user_phys) );
- 09933 _PROTOTYPE( void wreboot, (int how) );
- 09934
- 09935 /* klib*.s */
- 09936 _PROTOTYPE( void bios13, (void) );
- 09937 _PROTOTYPE( phys_bytes check_mem, (phys_bytes base, phys_bytes size) );
- 09938 _PROTOTYPE( void cp_mess, (int src,phys_clicks src_clicks,vir_bytes src_offset,
- 09939 phys_clicks dst_clicks, vir_bytes dst_offset) );
- 09940 _PROTOTYPE( int in_byte, (port_t port) );
- 09941 _PROTOTYPE( int in_word, (port_t port) );
- 09942 _PROTOTYPE( void lock, (void) );
- 09943 _PROTOTYPE( void unlock, (void) );
- 09944 _PROTOTYPE( void enable_irq, (unsigned irq) );
- 09945 _PROTOTYPE( int disable_irq, (unsigned irq) );
- 09946 _PROTOTYPE( u16_t mem_rdw, (segm_t segm, vir_bytes offset) );
- 09947 _PROTOTYPE( void out_byte, (port_t port, int value) );
- 09948 _PROTOTYPE( void out_word, (port_t port, int value) );
- 09949 _PROTOTYPE( void phys_copy, (phys_bytes source, phys_bytes dest,
- 09950 phys_bytes count) );
- 09951 _PROTOTYPE( void port_read, (unsigned port, phys_bytes destination,
- 09952 unsigned bytcount) );
- 09953 _PROTOTYPE( void port_read_byte, (unsigned port, phys_bytes destination,
- 09954 unsigned bytcount) );
- 09955 _PROTOTYPE( void port_write, (unsigned port, phys_bytes source,
- 09956 unsigned bytcount) );
- 09957 _PROTOTYPE( void port_write_byte, (unsigned port, phys_bytes source,
- 09958 unsigned bytcount) );
- 09959 _PROTOTYPE( void reset, (void) );
- 09960 _PROTOTYPE( void vid_vid_copy, (unsigned src, unsigned dst, unsigned count));
- 09961 _PROTOTYPE( void mem_vid_copy, (u16_t *src, unsigned dst, unsigned count));
- 09962 _PROTOTYPE( void level0, (void (*func)(void)) );
- 09963 _PROTOTYPE( void monitor, (void) );
- 09964
- 09965 /* misc.c */
- 09966 _PROTOTYPE( void mem_init, (void) );
- 09967
- 09968 /* mpx*.s */
- 09969 _PROTOTYPE( void idle_task, (void) );
- 09970 _PROTOTYPE( void restart, (void) );
- 09971
- 09972 /* The following are never called from C (pure asm procs). */
- 09973
- 09974 /* Exception handlers (real or protected mode), in numerical order. */
- 09975 void _PROTOTYPE( int00, (void) ), _PROTOTYPE( divide_error, (void) );
- 09976 void _PROTOTYPE( int01, (void) ), _PROTOTYPE( single_step_exception, (void) );
- 09977 void _PROTOTYPE( int02, (void) ), _PROTOTYPE( nmi, (void) );
- 09978 void _PROTOTYPE( int03, (void) ), _PROTOTYPE( breakpoint_exception, (void) );
- 09979 void _PROTOTYPE( int04, (void) ), _PROTOTYPE( overflow, (void) );
- 09980 void _PROTOTYPE( int05, (void) ), _PROTOTYPE( bounds_check, (void) );
- 09981 void _PROTOTYPE( int06, (void) ), _PROTOTYPE( inval_opcode, (void) );
- 09982 void _PROTOTYPE( int07, (void) ), _PROTOTYPE( copr_not_available, (void) );
- 09983 void _PROTOTYPE( double_fault, (void) );
- 09984 void _PROTOTYPE( copr_seg_overrun, (void) );
- 09985 void _PROTOTYPE( inval_tss, (void) );
- 09986 void _PROTOTYPE( segment_not_present, (void) );
- 09987 void _PROTOTYPE( stack_exception, (void) );
- 09988 void _PROTOTYPE( general_protection, (void) );
- 09989 void _PROTOTYPE( page_fault, (void) );
- 09990 void _PROTOTYPE( copr_error, (void) );
- 09991
- 09992 /* Hardware interrupt handlers. */
- 09993 _PROTOTYPE( void hwint00, (void) );
- 09994 _PROTOTYPE( void hwint01, (void) );
- 09995 _PROTOTYPE( void hwint02, (void) );
- 09996 _PROTOTYPE( void hwint03, (void) );
- 09997 _PROTOTYPE( void hwint04, (void) );
- 09998 _PROTOTYPE( void hwint05, (void) );
- 09999 _PROTOTYPE( void hwint06, (void) );
- 10000 _PROTOTYPE( void hwint07, (void) );
- 10001 _PROTOTYPE( void hwint08, (void) );
- 10002 _PROTOTYPE( void hwint09, (void) );
- 10003 _PROTOTYPE( void hwint10, (void) );
- 10004 _PROTOTYPE( void hwint11, (void) );
- 10005 _PROTOTYPE( void hwint12, (void) );
- 10006 _PROTOTYPE( void hwint13, (void) );
- 10007 _PROTOTYPE( void hwint14, (void) );
- 10008 _PROTOTYPE( void hwint15, (void) );
- 10009
- 10010 /* Software interrupt handlers, in numerical order. */
- 10011 _PROTOTYPE( void trp, (void) );
- 10012 _PROTOTYPE( void s_call, (void) ), _PROTOTYPE( p_s_call, (void) );
- 10013 _PROTOTYPE( void level0_call, (void) );
- 10014
- 10015 /* ne2000.c */
- 10016 _PROTOTYPE( int ne_probe, (struct dpeth *dep) );
- 10017
- 10018 /* printer.c */
- 10019 _PROTOTYPE( void pr_restart, (void) );
- 10020
- 10021 /* protect.c */
- 10022 _PROTOTYPE( void prot_init, (void) );
- 10023 _PROTOTYPE( void init_codeseg, (struct segdesc_s *segdp, phys_bytes base,
- 10024 phys_bytes size, int privilege) );
- 10025 _PROTOTYPE( void init_dataseg, (struct segdesc_s *segdp, phys_bytes base,
- 10026 phys_bytes size, int privilege) );
- 10027 _PROTOTYPE( phys_bytes seg2phys, (U16_t seg) );
- 10028 _PROTOTYPE( void enable_iop, (struct proc *pp) );
- 10029
- 10030 /* pty.c */
- 10031 _PROTOTYPE( void do_pty, (struct tty *tp, message *m_ptr) );
- 10032 _PROTOTYPE( void pty_init, (struct tty *tp) );
- 10033
- 10034 /* system.c */
- 10035 _PROTOTYPE( void alloc_segments, (struct proc *rp) );
- 10036
- 10037 /* wdeth.c */
- 10038 _PROTOTYPE( int wdeth_probe, (struct dpeth *dep) );
- 10039
- 10040 #endif /* (CHIP == INTEL) */
- 10041
- 10042 #if (CHIP == M68000)
- 10043
- 10044 /* cstart.c */
- 10045 _PROTOTYPE( void cstart, (char *parmoff, size_t parmsize) );
- 10046
- 10047 /* stfloppy.c */
- 10048 _PROTOTYPE( void fd_timer, (void) );
- 10049
- 10050 /* stmain.c */
- 10051 _PROTOTYPE( void none, (void) );
- 10052 _PROTOTYPE( void rupt, (void) );
- 10053 _PROTOTYPE( void trap, (void) );
- 10054 _PROTOTYPE( void checksp, (void) );
- 10055 _PROTOTYPE( void aciaint, (void) );
- 10056 _PROTOTYPE( void fake_int, (const char *s, int t) );
- 10057 _PROTOTYPE( void timint, (int t) );
- 10058 _PROTOTYPE( void mdiint, (void) );
- 10059 _PROTOTYPE( void iob, (int t) );
- 10060 _PROTOTYPE( void idle_task, (void) );
- 10061
- 10062 /* rs232.c */
- 10063 _PROTOTYPE( void siaint, (int type) );
- 10064
- 10065 /* stcon.c */
- 10066 _PROTOTYPE( void func_key, (void) );
- 10067 _PROTOTYPE( void dump, (void) );
- 10068 _PROTOTYPE( void putk, (int c) );
- 10069
- 10070 /* stdma.c */
- 10071 _PROTOTYPE( void dmagrab, (int p, dmaint_t func) );
- 10072 _PROTOTYPE( void dmafree, (int p) );
- 10073 _PROTOTYPE( void dmaint, (void) );
- 10074 _PROTOTYPE( void dmaaddr, (phys_bytes ad) );
- 10075 _PROTOTYPE( int dmardat, (int mode, int delay) );
- 10076 _PROTOTYPE( void dmawdat, (int mode, int data, int delay) );
- 10077 _PROTOTYPE( void dmawcmd, (int data, unsigned mode) );
- 10078 _PROTOTYPE( void dmacomm, (int mode, int data, int delay) );
- 10079 _PROTOTYPE( int dmastat, (int mode, int delay) );
- 10080
- 10081 /* stdskclk.c */
- 10082 _PROTOTYPE( int do_xbms, (phys_bytes address, int count, int rw, int minor) );
- 10083
- 10084 /* stkbd.c */
- 10085 _PROTOTYPE( void kbdint, (void) );
- 10086 _PROTOTYPE( void kb_timer, (void) );
- 10087 _PROTOTYPE( int kb_read, (int minor, char **bufindirect) );
- 10088 _PROTOTYPE( void kb_init, (int minor) );
- 10089
- 10090 /* stshadow.c */
- 10091 _PROTOTYPE( void mkshadow, (struct proc *p, phys_clicks c2) );
- 10092 _PROTOTYPE( void rmshadow, (struct proc *p, phys_clicks *basep,
- 10093 phys_clicks *sizep) );
- 10094 _PROTOTYPE( void unshadow, (struct proc *p) );
- 10095
- 10096 /* stvdu.c */
- 10097 _PROTOTYPE( void flush, (struct tty *tp) );
- 10098 _PROTOTYPE( void console, (struct tty *tp) );
- 10099 _PROTOTYPE( void out_char, (struct tty *tp, int c) );
- 10100 _PROTOTYPE( void scr_init, (int minor) );
- 10101 _PROTOTYPE( void vduswitch, (struct tty *tp) );
- 10102 _PROTOTYPE( void vdusetup, (unsigned int vres, char *vram,
- 10103 unsigned short *vrgb) );
- 10104 _PROTOTYPE( void vbl, (void) );
- 10105 _PROTOTYPE( int vdu_loadfont, (message *m_ptr) );
- 10106
- 10107 /* stwini.c */
- 10108 _PROTOTYPE( int wini_open, (message *mp) );
- 10109 _PROTOTYPE( int wini_rdwt, (message *mp) );
- 10110 _PROTOTYPE( int wini_hvrdwt, (message *mp) );
- 10111 _PROTOTYPE( int wini_transfer, (int rw, int pnr, int minor,
- 10112 long pos, int count, vir_bytes vadr) );
- 10113 _PROTOTYPE( int wini_ioctl, (message *mp) );
- 10114 _PROTOTYPE( int wini_close, (message *mp) );
- 10115
- 10116 /* stacsi.c */
- 10117 _PROTOTYPE( int acsi_cmd, (int drive, unsigned char *cmd, int cmdlen,
- 10118 phys_bytes address, phys_bytes data_len, int rw) );
- 10119
- 10120 /* stscsi.c */
- 10121 _PROTOTYPE( void scsi_task, (void) );
- 10122 _PROTOTYPE( void scsidmaint, (void) );
- 10123 _PROTOTYPE( void scsiint, (void) );
- 10124 _PROTOTYPE( int scsi_cmd, (int drive, unsigned char *cmd, int cmdlen,
- 10125 phys_bytes address, phys_bytes data_len, int rw) );
- 10126
- 10127 /* klib68k.s */
- 10128 _PROTOTYPE( void flipclicks, (phys_clicks c1, phys_clicks c2, phys_clicks n) );
- 10129 _PROTOTYPE( void copyclicks, (phys_clicks src, phys_clicks dest,
- 10130 phys_clicks nclicks) );
- 10131 _PROTOTYPE( void zeroclicks, (phys_clicks dest, phys_clicks nclicks) );
- 10132 _PROTOTYPE( void phys_copy, (phys_bytes src, phys_bytes dest, phys_bytes n) );
- 10133
- 10134 /* stdskclks.s */
- 10135 _PROTOTYPE( int rd1byte, (void) );
- 10136 _PROTOTYPE( int wr1byte, (int) );
- 10137 _PROTOTYPE( long getsupra, (void) );
- 10138 _PROTOTYPE( long geticd, (void) );
- 10139
- 10140 /* mpx.s */
- 10141 _PROTOTYPE( int lock, (void) );
- 10142 _PROTOTYPE( void unlock, (void) );
- 10143 _PROTOTYPE( void restore, (int oldsr) );
- 10144 _PROTOTYPE( void reboot, (void) );
- 10145 _PROTOTYPE( int test_and_set, (char *flag) );
- 10146 _PROTOTYPE( unsigned long get_mem_size, (char *start_addr) );
- 10147
- 10148 /* stprint.c */
- 10149 #ifdef DEBOUT
- 10150 _PROTOTYPE( void prtc, (int c) );
- 10151 #endif
- 10152
- 10153 #ifdef FPP
- 10154 /* fpp.c */
- 10155 _PROTOTYPE( void fppinit, (void) );
- 10156 _PROTOTYPE( void fpp_new_state, (struct proc *rp) );
- 10157 _PROTOTYPE( void fpp_save, (struct proc *rp, struct cpu_state *p) );
- 10158 _PROTOTYPE( struct cpu_state *fpp_restore, (struct proc *rp) );
- 10159
- 10160 /* fpps.s */
- 10161 _PROTOTYPE( void _fppsave, (struct state_frame *p) );
- 10162 _PROTOTYPE( void _fppsavereg, (struct fpp_model *p) );
- 10163 _PROTOTYPE( void _fpprestore, (struct state_frame *p) );
- 10164 _PROTOTYPE( void _fpprestreg, (struct fpp_model *p) );
- 10165 #endif
- 10166
- 10167 #if (SHADOWING == 0)
- 10168 /* pmmu.c */
- 10169 _PROTOTYPE(void pmmuinit , (void) );
- 10170 _PROTOTYPE(void pmmu_init_proc , (struct proc *rp ) );
- 10171 _PROTOTYPE(void pmmu_restore , (struct proc *rp ) );
- 10172 _PROTOTYPE(void pmmu_delete , (struct proc *rp ) );
- 10173 _PROTOTYPE(void pmmu_flush , (struct proc *rp ) );
- 10174 #endif
- 10175
- 10176 #endif /* (CHIP == M68000) */
- 10177
- 10178 #endif /* PROTO_H */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/sb16.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10200 #ifndef SB16_H
- 10201 #define SB16_H
- 10202
- 10203 #define SB_DEBUG 0 /* 1 = print debug info */
- 10204 #define SB_DEBUG_2 0 /* 1 = print more debug info */
- 10205
- 10206 #define SB_TIMEOUT 32000 /* timeout count */
- 10207
- 10208 /* IRQ, base address and DMA channels */
- 10209 #define SB_IRQ 5
- 10210 #define SB_BASE_ADDR 0x220 /* 0x210, 0x220, 0x230, 0x240,
- 10211 * 0x250, 0x260, 0x280
- 10212 */
- 10213 #define SB_DMA_8 1 /* 0, 1, 3 */
- 10214 #define SB_DMA_16 5 /* 5, 6, 7 */
- 10215 #if _WORD_SIZE == 2
- 10216 #define DMA_SIZE 8192 /* Dma buffer MUST BE MULTIPLE OF 2 */
- 10217 #else
- 10218 #define DMA_SIZE 32768 /* Dma buffer MUST BE MULTIPLE OF 2 */
- 10219 #endif
- 10220
- 10221 /* Some defaults for the DSP */
- 10222 #define DEFAULT_SPEED 22050 /* Sample rate */
- 10223 #define DEFAULT_BITS 8 /* Nr. of bits */
- 10224 #define DEFAULT_SIGN 0 /* 0 = unsigned, 1 = signed */
- 10225 #define DEFAULT_STEREO 0 /* 0 = mono, 1 = stereo */
- 10226
- 10227 /* DMA port addresses */
- 10228 #define DMA8_ADDR ((SB_DMA_8 & 3) << 1) + 0x00
- 10229 #define DMA8_COUNT ((SB_DMA_8 & 3) << 1) + 0x01
- 10230 #define DMA8_MASK 0x0A
- 10231 #define DMA8_MODE 0x0B
- 10232 #define DMA8_CLEAR 0x0C
- 10233
- 10234
- 10235 /* If after this preprocessing stuff DMA8_PAGE is not defined
- 10236 * the 8-bit DMA channel specified is not valid
- 10237 */
- 10238 #if SB_DMA_8 == 0
- 10239 # define DMA8_PAGE 0x87
- 10240 #else
- 10241 # if SB_DMA_8 == 1
- 10242 # define DMA8_PAGE 0x83
- 10243 # else
- 10244 # if SB_DMA_8 == 3
- 10245 # define DMA8_PAGE 0x82
- 10246 # endif
- 10247 # endif
- 10248 #endif
- 10249
- 10250
- 10251 #define DMA16_ADDR ((SB_DMA_16 & 3) << 2) + 0xC0
- 10252 #define DMA16_COUNT ((SB_DMA_16 & 3) << 2) + 0xC2
- 10253 #define DMA16_MASK 0xD4
- 10254 #define DMA16_MODE 0xD6
- 10255 #define DMA16_CLEAR 0xD8
- 10256
- 10257
- 10258 /* If after this preprocessing stuff DMA16_PAGE is not defined
- 10259 * the 16-bit DMA channel specified is not valid
- 10260 */
- 10261 #if SB_DMA_16 == 5
- 10262 # define DMA16_PAGE 0x8B
- 10263 #else
- 10264 # if SB_DMA_16 == 6
- 10265 # define DMA16_PAGE 0x89
- 10266 # else
- 10267 # if SB_DMA_16 == 7
- 10268 # define DMA16_PAGE 0x8A
- 10269 # endif
- 10270 # endif
- 10271 #endif
- 10272
- 10273
- 10274 /* DMA modes */
- 10275 #define DMA16_AUTO_PLAY 0x58 + (SB_DMA_16 & 3)
- 10276 #define DMA16_AUTO_REC 0x54 + (SB_DMA_16 & 3)
- 10277 #define DMA8_AUTO_PLAY 0x58 + SB_DMA_8
- 10278 #define DMA8_AUTO_REC 0x54 + SB_DMA_8
- 10279
- 10280
- 10281 /* IO ports for soundblaster */
- 10282 #define DSP_RESET 0x6 + SB_BASE_ADDR
- 10283 #define DSP_READ 0xA + SB_BASE_ADDR
- 10284 #define DSP_WRITE 0xC + SB_BASE_ADDR
- 10285 #define DSP_COMMAND 0xC + SB_BASE_ADDR
- 10286 #define DSP_STATUS 0xC + SB_BASE_ADDR
- 10287 #define DSP_DATA_AVL 0xE + SB_BASE_ADDR
- 10288 #define DSP_DATA16_AVL 0xF + SB_BASE_ADDR
- 10289 #define MIXER_REG 0x4 + SB_BASE_ADDR
- 10290 #define MIXER_DATA 0x5 + SB_BASE_ADDR
- 10291 #define OPL3_LEFT 0x0 + SB_BASE_ADDR
- 10292 #define OPL3_RIGHT 0x2 + SB_BASE_ADDR
- 10293 #define OPL3_BOTH 0x8 + SB_BASE_ADDR
- 10294
- 10295
- 10296 /* DSP Commands */
- 10297 #define DSP_INPUT_RATE 0x42 /* set input sample rate */
- 10298 #define DSP_OUTPUT_RATE 0x41 /* set output sample rate */
- 10299 #define DSP_CMD_SPKON 0xD1 /* set speaker on */
- 10300 #define DSP_CMD_SPKOFF 0xD3 /* set speaker off */
- 10301 #define DSP_CMD_DMA8HALT 0xD0 /* halt DMA 8-bit operation */
- 10302 #define DSP_CMD_DMA8CONT 0xD4 /* continue DMA 8-bit operation */
- 10303 #define DSP_CMD_DMA16HALT 0xD5 /* halt DMA 16-bit operation */
- 10304 #define DSP_CMD_DMA16CONT 0xD6 /* continue DMA 16-bit operation */
- 10305 #define DSP_GET_VERSION 0xE1 /* get version number of DSP */
- 10306 #define DSP_CMD_8BITAUTO_IN 0xCE /* 8 bit auto-initialized input */
- 10307 #define DSP_CMD_8BITAUTO_OUT 0xC6 /* 8 bit auto-initialized output */
- 10308 #define DSP_CMD_16BITAUTO_IN 0xBE /* 16 bit auto-initialized input */
- 10309 #define DSP_CMD_16BITAUTO_OUT 0xB6 /* 16 bit auto-initialized output */
- 10310 #define DSP_CMD_IRQREQ8 0xF2 /* Interrupt request 8 bit */
- 10311 #define DSP_CMD_IRQREQ16 0xF3 /* Interrupt request 16 bit */
- 10312
- 10313
- 10314 /* DSP Modes */
- 10315 #define DSP_MODE_MONO_US 0x00 /* Mono unsigned */
- 10316 #define DSP_MODE_MONO_S 0x10 /* Mono signed */
- 10317 #define DSP_MODE_STEREO_US 0x20 /* Stereo unsigned */
- 10318 #define DSP_MODE_STEREO_S 0x30 /* Stereo signed */
- 10319
- 10320
- 10321 /* MIXER commands */
- 10322 #define MIXER_RESET 0x00 /* Reset */
- 10323 #define MIXER_DAC_LEVEL 0x04 /* Used for detection only */
- 10324 #define MIXER_MASTER_LEFT 0x30 /* Master volume left */
- 10325 #define MIXER_MASTER_RIGHT 0x31 /* Master volume right */
- 10326 #define MIXER_DAC_LEFT 0x32 /* Dac level left */
- 10327 #define MIXER_DAC_RIGHT 0x33 /* Dac level right */
- 10328 #define MIXER_FM_LEFT 0x34 /* Fm level left */
- 10329 #define MIXER_FM_RIGHT 0x35 /* Fm level right */
- 10330 #define MIXER_CD_LEFT 0x36 /* Cd audio level left */
- 10331 #define MIXER_CD_RIGHT 0x37 /* Cd audio level right */
- 10332 #define MIXER_LINE_LEFT 0x38 /* Line in level left */
- 10333 #define MIXER_LINE_RIGHT 0x39 /* Line in level right */
- 10334 #define MIXER_MIC_LEVEL 0x3A /* Microphone level */
- 10335 #define MIXER_PC_LEVEL 0x3B /* Pc speaker level */
- 10336 #define MIXER_OUTPUT_CTRL 0x3C /* Output control */
- 10337 #define MIXER_IN_LEFT 0x3D /* Input control left */
- 10338 #define MIXER_IN_RIGHT 0x3E /* Input control right */
- 10339 #define MIXER_GAIN_IN_LEFT 0x3F /* Input gain control left */
- 10340 #define MIXER_GAIN_IN_RIGHT 0x40 /* Input gain control right */
- 10341 #define MIXER_GAIN_OUT_LEFT 0x41 /* Output gain control left */
- 10342 #define MIXER_GAIN_OUT_RIGHT 0x42 /* Output gain control rigth */
- 10343 #define MIXER_AGC 0x43 /* Automatic gain control */
- 10344 #define MIXER_TREBLE_LEFT 0x44 /* Treble left */
- 10345 #define MIXER_TREBLE_RIGHT 0x45 /* Treble right */
- 10346 #define MIXER_BASS_LEFT 0x46 /* Bass left */
- 10347 #define MIXER_BASS_RIGHT 0x47 /* Bass right */
- 10348 #define MIXER_SET_IRQ 0x80 /* Set irq number */
- 10349 #define MIXER_SET_DMA 0x81 /* Set DMA channels */
- 10350 #define MIXER_IRQ_STATUS 0x82 /* Irq status */
- 10351
- 10352 /* Mixer constants */
- 10353 #define MIC 0x01 /* Microphone */
- 10354 #define CD_RIGHT 0x02
- 10355 #define CD_LEFT 0x04
- 10356 #define LINE_RIGHT 0x08
- 10357 #define LINE_LEFT 0x10
- 10358 #define FM_RIGHT 0x20
- 10359 #define FM_LEFT 0x40
- 10360
- 10361 /* DSP constants */
- 10362 #define DSP_MAX_SPEED 44100 /* Max sample speed in KHz */
- 10363 #define DSP_MIN_SPEED 4000 /* Min sample speed in KHz */
- 10364 #define DSP_MAX_FRAGMENT_SIZE DMA_SIZE /* Maximum fragment size */
- 10365 #define DSP_MIN_FRAGMENT_SIZE 1024 /* Minimum fragment size */
- 10366
- 10367
- 10368 /* Number of bytes you can DMA before hitting a 64K boundary: */
- 10369 #define dma_bytes_left(phys)
- 10370 ((unsigned) (sizeof(int) == 2 ? 0 : 0x10000) - (unsigned) ((phys) & 0xFFFF))
- 10371
- 10372
- 10373 /* Function prototypes used by mixer and dsp */
- 10374 _PROTOTYPE(int mixer_set, (int reg, int data));
- 10375
- 10376 #endif /* SB16_H */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/sconst.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10400 ! Miscellaneous constants used in assembler code.
- 10401 W = _WORD_SIZE ! Machine word size.
- 10402
- 10403 ! Offsets in struct proc. They MUST match proc.h.
- 10404 P_STACKBASE = 0
- 10405 #if _WORD_SIZE == 2
- 10406 ESREG = P_STACKBASE
- 10407 #else
- 10408 GSREG = P_STACKBASE
- 10409 FSREG = GSREG + 2 ! 386 introduces FS and GS segments
- 10410 ESREG = FSREG + 2
- 10411 #endif
- 10412 DSREG = ESREG + 2
- 10413 DIREG = DSREG + 2
- 10414 SIREG = DIREG + W
- 10415 BPREG = SIREG + W
- 10416 STREG = BPREG + W ! hole for another SP
- 10417 BXREG = STREG + W
- 10418 DXREG = BXREG + W
- 10419 CXREG = DXREG + W
- 10420 AXREG = CXREG + W
- 10421 RETADR = AXREG + W ! return address for save() call
- 10422 PCREG = RETADR + W
- 10423 CSREG = PCREG + W
- 10424 PSWREG = CSREG + W
- 10425 SPREG = PSWREG + W
- 10426 SSREG = SPREG + W
- 10427 P_STACKTOP = SSREG + W
- 10428 P_LDT_SEL = P_STACKTOP
- 10429 P_LDT = P_LDT_SEL + W
- 10430
- 10431 #if _WORD_SIZE == 2
- 10432 Msize = 12 ! size of a message in 16-bit words
- 10433 #else
- 10434 Msize = 9 ! size of a message in 32-bit words
- 10435 #endif
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/tty.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10500 /* tty.h - Terminals */
- 10501
- 10502 #define TTY_IN_BYTES 256 /* tty input queue size */
- 10503 #define TAB_SIZE 8 /* distance between tab stops */
- 10504 #define TAB_MASK 7 /* mask to compute a tab stop position */
- 10505
- 10506 #define ESC '33' /* escape */
- 10507
- 10508 #define O_NOCTTY 00400 /* from <fcntl.h>, or cc will choke */
- 10509 #define O_NONBLOCK 04000
- 10510
- 10511 typedef _PROTOTYPE( void (*devfun_t), (struct tty *tp) );
- 10512 typedef _PROTOTYPE( void (*devfunarg_t), (struct tty *tp, int c) );
- 10513
- 10514 typedef struct tty {
- 10515 int tty_events; /* set when TTY should inspect this line */
- 10516
- 10517 /* Input queue. Typed characters are stored here until read by a program. */
- 10518 u16_t *tty_inhead; /* pointer to place where next char goes */
- 10519 u16_t *tty_intail; /* pointer to next char to be given to prog */
- 10520 int tty_incount; /* # chars in the input queue */
- 10521 int tty_eotct; /* number of "line breaks" in input queue */
- 10522 devfun_t tty_devread; /* routine to read from low level buffers */
- 10523 devfun_t tty_icancel; /* cancel any device input */
- 10524 int tty_min; /* minimum requested #chars in input queue */
- 10525 clock_t tty_time; /* time when the input is available */
- 10526 struct tty *tty_timenext; /* for a list of ttys with active timers */
- 10527
- 10528 /* Output section. */
- 10529 devfun_t tty_devwrite; /* routine to start actual device output */
- 10530 devfunarg_t tty_echo; /* routine to echo characters input */
- 10531 devfun_t tty_ocancel; /* cancel any ongoing device output */
- 10532 devfun_t tty_break; /* let the device send a break */
- 10533
- 10534 /* Terminal parameters and status. */
- 10535 int tty_position; /* current position on the screen for echoing */
- 10536 char tty_reprint; /* 1 when echoed input messed up, else 0 */
- 10537 char tty_escaped; /* 1 when LNEXT (^V) just seen, else 0 */
- 10538 char tty_inhibited; /* 1 when STOP (^S) just seen (stops output) */
- 10539 char tty_pgrp; /* slot number of controlling process */
- 10540 char tty_openct; /* count of number of opens of this tty */
- 10541
- 10542 /* Information about incomplete I/O requests is stored here. */
- 10543 char tty_inrepcode; /* reply code, TASK_REPLY or REVIVE */
- 10544 char tty_incaller; /* process that made the call (usually FS) */
- 10545 char tty_inproc; /* process that wants to read from tty */
- 10546 vir_bytes tty_in_vir; /* virtual address where data is to go */
- 10547 int tty_inleft; /* how many chars are still needed */
- 10548 int tty_incum; /* # chars input so far */
- 10549 char tty_outrepcode; /* reply code, TASK_REPLY or REVIVE */
- 10550 char tty_outcaller; /* process that made the call (usually FS) */
- 10551 char tty_outproc; /* process that wants to write to tty */
- 10552 vir_bytes tty_out_vir; /* virtual address where data comes from */
- 10553 int tty_outleft; /* # chars yet to be output */
- 10554 int tty_outcum; /* # chars output so far */
- 10555 char tty_iocaller; /* process that made the call (usually FS) */
- 10556 char tty_ioproc; /* process that wants to do an ioctl */
- 10557 int tty_ioreq; /* ioctl request code */
- 10558 vir_bytes tty_iovir; /* virtual address of ioctl buffer */
- 10559
- 10560 /* Miscellaneous. */
- 10561 devfun_t tty_ioctl; /* set line speed, etc. at the device level */
- 10562 devfun_t tty_close; /* tell the device that the tty is closed */
- 10563 void *tty_priv; /* pointer to per device private data */
- 10564 struct termios tty_termios; /* terminal attributes */
- 10565 struct winsize tty_winsize; /* window size (#lines and #columns) */
- 10566
- 10567 u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
- 10568 } tty_t;
- 10569
- 10570 EXTERN tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
- 10571
- 10572 /* Values for the fields. */
- 10573 #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
- 10574 #define ESCAPED 1 /* previous character was LNEXT (^V) */
- 10575 #define RUNNING 0 /* no STOP (^S) has been typed to stop output */
- 10576 #define STOPPED 1 /* STOP (^S) has been typed to stop output */
- 10577
- 10578 /* Fields and flags on characters in the input queue. */
- 10579 #define IN_CHAR 0x00FF /* low 8 bits are the character itself */
- 10580 #define IN_LEN 0x0F00 /* length of char if it has been echoed */
- 10581 #define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
- 10582 #define IN_EOT 0x1000 /* char is a line break (^D, LF) */
- 10583 #define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
- 10584 #define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
- 10585
- 10586 /* Times and timeouts. */
- 10587 #define TIME_NEVER ((clock_t) -1 < 0 ? (clock_t) LONG_MAX : (clock_t) -1)
- 10588 #define force_timeout() ((void) (tty_timeout = 0))
- 10589
- 10590 EXTERN tty_t *tty_timelist; /* list of ttys with active timers */
- 10591
- 10592 /* Number of elements and limit of a buffer. */
- 10593 #define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
- 10594 #define bufend(buf) ((buf) + buflen(buf))
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/type.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10600 #ifndef TYPE_H
- 10601 #define TYPE_H
- 10602
- 10603 typedef _PROTOTYPE( void task_t, (void) );
- 10604 typedef _PROTOTYPE( int (*rdwt_t), (message *m_ptr) );
- 10605 typedef _PROTOTYPE( void (*watchdog_t), (void) );
- 10606
- 10607 struct tasktab {
- 10608 task_t *initial_pc;
- 10609 int stksize;
- 10610 char name[8];
- 10611 };
- 10612
- 10613 struct memory {
- 10614 phys_clicks base;
- 10615 phys_clicks size;
- 10616 };
- 10617
- 10618 /* Administration for clock polling. */
- 10619 struct milli_state {
- 10620 unsigned long accum_count; /* accumulated clock ticks */
- 10621 unsigned prev_count; /* previous clock value */
- 10622 };
- 10623
- 10624 #if (CHIP == INTEL)
- 10625 typedef unsigned port_t;
- 10626 typedef unsigned segm_t;
- 10627 typedef unsigned reg_t; /* machine register */
- 10628
- 10629 /* The stack frame layout is determined by the software, but for efficiency
- 10630 * it is laid out so the assembly code to use it is as simple as possible.
- 10631 * 80286 protected mode and all real modes use the same frame, built with
- 10632 * 16-bit registers. Real mode lacks an automatic stack switch, so little
- 10633 * is lost by using the 286 frame for it. The 386 frame differs only in
- 10634 * having 32-bit registers and more segment registers. The same names are
- 10635 * used for the larger registers to avoid differences in the code.
- 10636 */
- 10637 struct stackframe_s { /* proc_ptr points here */
- 10638 #if _WORD_SIZE == 4
- 10639 u16_t gs; /* last item pushed by save */
- 10640 u16_t fs; /* ^ */
- 10641 #endif
- 10642 u16_t es; /* | */
- 10643 u16_t ds; /* | */
- 10644 reg_t di; /* di through cx are not accessed in C */
- 10645 reg_t si; /* order is to match pusha/popa */
- 10646 reg_t fp; /* bp */
- 10647 reg_t st; /* hole for another copy of sp */
- 10648 reg_t bx; /* | */
- 10649 reg_t dx; /* | */
- 10650 reg_t cx; /* | */
- 10651 reg_t retreg; /* ax and above are all pushed by save */
- 10652 reg_t retadr; /* return address for assembly code save() */
- 10653 reg_t pc; /* ^ last item pushed by interrupt */
- 10654 reg_t cs; /* | */
- 10655 reg_t psw; /* | */
- 10656 reg_t sp; /* | */
- 10657 reg_t ss; /* these are pushed by CPU during interrupt */
- 10658 };
- 10659
- 10660 struct segdesc_s { /* segment descriptor for protected mode */
- 10661 u16_t limit_low;
- 10662 u16_t base_low;
- 10663 u8_t base_middle;
- 10664 u8_t access; /* |P|DL|1|X|E|R|A| */
- 10665 #if _WORD_SIZE == 4
- 10666 u8_t granularity; /* |G|X|0|A|LIMT| */
- 10667 u8_t base_high;
- 10668 #else
- 10669 u16_t reserved;
- 10670 #endif
- 10671 };
- 10672
- 10673 typedef _PROTOTYPE( int (*irq_handler_t), (int irq) );
- 10674
- 10675 #endif /* (CHIP == INTEL) */
- 10676
- 10677 #if (CHIP == M68000)
- 10678 typedef _PROTOTYPE( void (*dmaint_t), (void) );
- 10679
- 10680 typedef u32_t reg_t; /* machine register */
- 10681
- 10682 /* The name and fields of this struct were chosen for PC compatibility. */
- 10683 struct stackframe_s {
- 10684 reg_t retreg; /* d0 */
- 10685 reg_t d1;
- 10686 reg_t d2;
- 10687 reg_t d3;
- 10688 reg_t d4;
- 10689 reg_t d5;
- 10690 reg_t d6;
- 10691 reg_t d7;
- 10692 reg_t a0;
- 10693 reg_t a1;
- 10694 reg_t a2;
- 10695 reg_t a3;
- 10696 reg_t a4;
- 10697 reg_t a5;
- 10698 reg_t fp; /* also known as a6 */
- 10699 reg_t sp; /* also known as a7 */
- 10700 reg_t pc;
- 10701 u16_t psw;
- 10702 u16_t dummy; /* make size multiple of reg_t for system.c */
- 10703 };
- 10704
- 10705 struct fsave {
- 10706 struct cpu_state {
- 10707 u16_t i_format;
- 10708 u32_t i_addr;
- 10709 u16_t i_state[4];
- 10710 } cpu_state;
- 10711 struct state_frame {
- 10712 u8_t frame_type;
- 10713 u8_t frame_size;
- 10714 u16_t reserved;
- 10715 u8_t frame[212];
- 10716 } state_frame;
- 10717 struct fpp_model {
- 10718 u32_t fpcr;
- 10719 u32_t fpsr;
- 10720 u32_t fpiar;
- 10721 struct fpN {
- 10722 u32_t high;
- 10723 u32_t low;
- 10724 u32_t mid;
- 10725 } fpN[8];
- 10726 } fpp_model;
- 10727 };
- 10728 #endif /* (CHIP == M68000) */
- 10729
- 10730 #endif /* TYPE_H */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/wdeth.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10800 /*
- 10801 wdeth.h
- 10802
- 10803 Created: before Dec 28, 1992 by Philip Homburg
- 10804 */
- 10805
- 10806 #ifndef WDETH_H
- 10807 #define WDETH_H
- 10808
- 10809 /* Western Digital Ethercard Plus, or WD8003E card. */
- 10810
- 10811 #define EPL_REG0 0x0 /* Control(write) and status(read) */
- 10812 #define EPL_REG1 0x1
- 10813 #define EPL_REG2 0x2
- 10814 #define EPL_REG3 0x3
- 10815 #define EPL_REG4 0x4
- 10816 #define EPL_REG5 0x5
- 10817 #define EPL_REG6 0x6
- 10818 #define EPL_REG7 0x7
- 10819 #define EPL_EA0 0x8 /* Most significant eaddr byte */
- 10820 #define EPL_EA1 0x9
- 10821 #define EPL_EA2 0xA
- 10822 #define EPL_EA3 0xB
- 10823 #define EPL_EA4 0xC
- 10824 #define EPL_EA5 0xD /* Least significant eaddr byte */
- 10825 #define EPL_TLB 0xE
- 10826 #define EPL_CHKSUM 0xF /* sum from epl_ea0 upto here is 0xFF */
- 10827 #define EPL_DP8390 0x10 /* NatSemi chip */
- 10828
- 10829 #define EPL_MSR EPL_REG0 /* memory select register */
- 10830 #define EPL_ICR EPL_REG1 /* interface configuration register */
- 10831 #define EPL_IRR EPL_REG4 /* interrupt request register (IRR) */
- 10832 #define EPL_790_HWR EPL_REG4 /* '790 hardware support register */
- 10833 #define EPL_LAAR EPL_REG5 /* LA address register (write only) */
- 10834 #define EPL_790_ICR EPL_REG6 /* '790 interrupt control register */
- 10835 #define EPL_GP2 EPL_REG7 /* general purpose register 2 */
- 10836 #define EPL_790_B EPL_EA3 /* '790 memory register */
- 10837 #define EPL_790_GCR EPL_EA5 /* '790 General Control Register */
- 10838
- 10839 /* Bits in EPL_MSR */
- 10840 #define E_MSR_MEMADDR 0x3F /* Bits SA18-SA13, SA19 implicit 1 */
- 10841 #define E_MSR_MENABLE 0x40 /* Memory Enable */
- 10842 #define E_MSR_RESET 0x80 /* Software Reset */
- 10843
- 10844 /* Bits in EPL_ICR */
- 10845 #define E_ICR_16BIT 0x01 /* 16 bit bus */
- 10846 #define E_ICR_IR2 0x04 /* bit 2 of encoded IRQ */
- 10847 #define E_ICR_MEMBIT 0x08 /* 583 mem size mask */
- 10848
- 10849 /* Bits in EPL_IRR */
- 10850 #define E_IRR_IR0 0x20 /* bit 0 of encoded IRQ */
- 10851 #define E_IRR_IR1 0x40 /* bit 1 of encoded IRQ */
- 10852 #define E_IRR_IEN 0x80 /* enable interrupts */
- 10853
- 10854 /* Bits in EPL_LAAR */
- 10855 #define E_LAAR_A19 0x01 /* address lines for above 1M ram */
- 10856 #define E_LAAR_A20 0x02 /* address lines for above 1M ram */
- 10857 #define E_LAAR_A21 0x04 /* address lines for above 1M ram */
- 10858 #define E_LAAR_A22 0x08 /* address lines for above 1M ram */
- 10859 #define E_LAAR_A23 0x10 /* address lines for above 1M ram */
- 10860 #define E_LAAR_SOFTINT 0x20 /* enable software interrupt */
- 10861 #define E_LAAR_LAN16E 0x40 /* enables 16 bit RAM for LAN */
- 10862 #define E_LAAR_MEM16E 0x80 /* enables 16 bit RAM for host */
- 10863
- 10864 /* Bits and values in EPL_TLB */
- 10865 #define E_TLB_EB 0x05 /* WD8013EB */
- 10866 #define E_TLB_E 0x27 /* WD8013 Elite */
- 10867 #define E_TLB_SMCE 0x29 /* SMC Elite 16 */
- 10868 #define E_TLB_SMC8216C 0x2B /* SMC 8216 C */
- 10869
- 10870 #define E_TLB_REV 0x1F /* revision mask */
- 10871 #define E_TLB_SOFT 0x20 /* soft config */
- 10872 #define E_TLB_RAM 0x40 /* extra ram bit */
- 10873
- 10874 /* Bits in EPL_790_HWR */
- 10875 #define E_790_HWR_SWH 0x80 /* switch register set */
- 10876
- 10877 /* Bits in EPL_790_ICR */
- 10878 #define E_790_ICR_EIL 0x01 /* enable interrupts */
- 10879
- 10880 /* Bits in EPL_790_GCR when E_790_HWR_SWH is set in EPL_790_HWR */
- 10881 #define E_790_GCR_IR0 0x04 /* bit 0 of encoded IRQ */
- 10882 #define E_790_GCR_IR1 0x08 /* bit 1 of encoded IRQ */
- 10883 #define E_790_GCR_IR2 0x40 /* bit 2 of encoded IRQ */
- 10884
- 10885
- 10886 #define inb_we(dep, reg) (in_byte(dep->de_base_port+reg))
- 10887 #define outb_we(dep, reg, data) (out_byte(dep->de_base_port+reg, data))
- 10888
- 10889 #endif /* WDETH_H */
- 10890
- 10891 /*
- 10892 * $PchHeader: /mount/hd2/minix/sys/kernel/ibm/RCS/wdeth.h,v 1.3 1994/10/31 10:36:29 philip Exp $
- 10893 */
-
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/kernel/aha_scsi.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
- 10900 /*
- 10901 * This file contains the device dependent part of an experimental disk
- 10902 * and tape driver for the Adaptec 154x SCSI Host Adapter family, written
- 10903 * by James da Silva (jds@cs.umd.edu).
- 10904 *
- 10905 * I wrote this driver using the technical documentation for the AHA available
- 10906 * from the Adaptec BBS at 1-408-945-7727, and from the SCSI standard drafts
- 10907 * available on NCR's SCSI BBS at 1-316-636-8700. I suggest you get both
- 10908 * these documents if you want to understand and hack this code.
- 10909 *
- 10910 * This code has been extensively modified by Kees J. Bot (kjb@cs.vu.nl) to
- 10911 * a point that James will barely recognize it as his. It is completely
- 10912 * remodeled and doubled in both size and functionality. It is no longer
- 10913 * considered experimental either.
- 10914 *
- 10915 * The supported device numbers are as follows:
- 10916 * # Name Device
- 10917 * 0 sd0 disk 0, entire disk
- 10918 * 1 sd1 disk 0, partition 1
- 10919 * 2 sd2 disk 0, partition 2
- 10920 * 3 sd3 disk 0, partition 3
- 10921 * 4 sd4 disk 0, partition 4
- 10922 * 5 sd5 disk 1, entire disk
- 10923 * 6 sd6 disk 1, partition 1
- 10924 * .. .... ....
- 10925 * 39 sd39 disk 7, partition 4
- 10926 *
- 10927 * 64 nrst0 tape 0, no rewind
- 10928 * 65 rst0 tape 0, rewind
- 10929 * 66 nrst1 tape 1, no rewind
- 10930 * .. .... ....
- 10931 * 79 rst7 tape 7, rewind
- 10932 *
- 10933 * 128 sd1a disk 0, partition 1, subpartition 1
- 10934 * 129 sd1b disk 0, partition 1, subpartition 2
- 10935 * ... .... ....
- 10936 * 255 sd39d disk 7, partition 4, subpartition 4
- 10937 *
- 10938 * The translation of device numbers to targets and logical units is very
- 10939 * simple: The target is the same as the disk or tape number, the logical
- 10940 * unit is always zero. Devices with logical unit numbers other then zero
- 10941 * are virtually extinct. If you happen to have such a dinosaur device,
- 10942 * then you can reprogram (e.g.) sd35 and st7 to target 0, lun 1 from the
- 10943 * Boot Monitor with 'sd35=0,1'.
- 10944 *
- 10945 *
- 10946 * The file contains one entry point:
- 10947 *
- 10948 * aha_scsi_task: main entry when system is brought up
- 10949 *
- 10950 *
- 10951 * Changes:
- 10952 * 5 May 1992 by Kees J. Bot: device dependent/independent split.
- 10953 * 7 Jul 1992 by Kees J. Bot: speedup & features.
- 10954 * 28 Dec 1992 by Kees J. Bot: completely remodeled & virtual memory.
- 10955 * 18 Sep 1994 by Kees J. Bot: removed "send 2 commands at once" junk.
- 10956 */
- 10957 #include "kernel.h"
- 10958 #include "driver.h"
- 10959 #include "drvlib.h"
- 10960 #if ENABLE_ADAPTEC_SCSI
- 10961 #include <fcntl.h>
- 10962 #include <sys/ioctl.h>
- 10963 #include <sys/mtio.h>
- 10964 #include "assert.h"
- 10965 INIT_ASSERT
- 10966
- 10967
- 10968 #ifndef AHA_DEBUG
- 10969 #define AHA_DEBUG 0 /* 1=print all SCSI errors | 2=dump ccb
- 10970 * 4=show request | 8=dump scsi cmd
- 10971 */
- 10972 #endif
- 10973
- 10974 /* AHA-154x port addresses */
- 10975 #define AHA_BASEREG 0x330 /* default base port address of AHA registers */
- 10976 #define AHA_CNTLREG aha_basereg+0 /* Control Register - write only */
- 10977 #define AHA_STATREG aha_basereg+0 /* Status Register - read only */
- 10978 #define AHA_DATAREG aha_basereg+1 /* Data Register - read/write */
- 10979 #define AHA_INTRREG aha_basereg+2 /* Interrupt Flags - read only */
- 10980
- 10981 /* control register bits */
- 10982 #define AHA_HRST 0x80 /* bit 7 - Hard Reset */
- 10983 #define AHA_SRST 0x40 /* bit 6 - Soft Reset */
- 10984 #define AHA_IRST 0x20 /* bit 5 - Interrupt Reset */
- 10985 #define AHA_SCRST 0x10 /* bit 4 - SCSI Bus Reset */
- 10986 /* 0x08 * bit 3 - Reserved (set to 0) */
- 10987 /* 0x04 * bit 2 - Reserved (set to 0) */
- 10988 /* 0x02 * bit 1 - Reserved (set to 0) */
- 10989 /* 0x01 * bit 0 - Reserved (set to 0) */
- 10990
- 10991 /* status register bits */
- 10992 #define AHA_STST 0x80 /* bit 7 - Self Test in Progress */
- 10993 #define AHA_DIAGF 0x40 /* bit 6 - Internal Diagnostic Failure */
- 10994 #define AHA_INIT 0x20 /* bit 5 - Mailbox Initialization Required */
- 10995 #define AHA_IDLE 0x10 /* bit 4 - SCSI Host Adapter Idle */
- 10996 #define AHA_CDF 0x08 /* bit 3 - Command/Data Out Port Full */
- 10997 #define AHA_DF 0x04 /* bit 2 - Data In Port Full */
- 10998 /* 0x02 * bit 1 - Reserved */
- 10999 #define AHA_INVDCMD 0x01 /* bit 0 - Invalid Host Adapter Command */
- 11000
- 11001 /* interrupt flags register bits */
- 11002 #define AHA_ANYINT 0x80 /* bit 7 - Any Interrupt */
- 11003 /* 0x40 * bit 6 - Reserved */
- 11004 /* 0x20 * bit 5 - Reserved */
- 11005 /* 0x10 * bit 4 - Reserved */
- 11006 #define AHA_SCRD 0x08 /* bit 3 - SCSI Reset Detected */
- 11007 #define AHA_HACC 0x04 /* bit 2 - Host Adapter Command Complete */
- 11008 #define AHA_MBOE 0x02 /* bit 1 - Mailbox Out Empty */
- 11009 #define AHA_MBIF 0x01 /* bit 0 - Mailbox In Full */
- 11010
- 11011 /* AHA board models */
- 11012 #define AHA1540 0x30
- 11013 #define AHA1540A 0x41
- 11014 #define AHA1640 0x42
- 11015 #define AHA1740 0x43
- 11016 #define AHA1540C 0x44
- 11017 #define AHA1540CF 0x45
- 11018 #define BT545 0x20 /* BusLogic */
- 11019
- 11020 /* AHA Command Codes */
- 11021 #define AHACOM_INITBOX 0x01 /* Mailbox Initialization */
- 11022 #define AHACOM_STARTSCSI 0x02 /* Start SCSI Command */
- 11023 #define AHACOM_HAINQUIRY 0x04 /* Host Adapter Inquiry */
- 11024 #define AHACOM_SETIMEOUT 0x06 /* Set SCSI selection time out value */
- 11025 #define AHACOM_BUSON 0x07 /* Set DMA bus on time */
- 11026 #define AHACOM_BUSOFF 0x08 /* Set DMA bus off time */
- 11027 #define AHACOM_SPEED 0x09 /* Set DMA transfer speed */
- 11028 #define AHACOM_INSTALLED 0x0A /* Return Installed Devices */
- 11029 #define AHACOM_GETCONFIG 0x0B /* Return Configuration Data */
- 11030 #define AHACOM_GETSETUP 0x0D /* Return Setup Data */
- 11031 #define AHACOM_EXTBIOS 0x28 /* Return Extended BIOS Info */
- 11032 #define AHACOM_MBOX_ENABLE 0x29 /* Enable Mailbox Interface */
- 11033
- 11034 /* AHA Mailbox Out Codes */
- 11035 #define AHA_MBOXFREE 0x00 /* Mailbox is Free */
- 11036 #define AHA_MBOXSTART 0x01 /* Start Command */
- 11037 #define AHA_MBOXABORT 0x02 /* Abort Command */
- 11038 /* AHA Mailbox In Codes */
- 11039 #define AHA_MBOXOK 0x01 /* Command Completed Successfully */
- 11040 #define AHA_MBOXERR 0x04 /* Command Completed with Error */
- 11041
- 11042
- 11043 /* Basic types */
- 11044 typedef unsigned char byte;
- 11045 typedef byte big16[2]; /* 16 bit big-endian values */
- 11046 typedef byte big24[3]; /* AHA uses 24 bit, big-endian values! */
- 11047 typedef byte big32[4]; /* Group 1 SCSI commands use 32 bit big-endian values */
- 11048
- 11049 /* AHA Mailbox structure */
- 11050 typedef struct {
- 11051 byte status; /* Command or Status byte */
- 11052 big24 ccbptr; /* pointer to Command Control Block */
- 11053 } mailbox_t;
- 11054
- 11055 /* SCSI Group 0 Command Descriptor Block structure */
- 11056 typedef union {
- 11057 struct { /* Disk i/o commands */
- 11058 byte d_scsi_op; /* SCSI Operation Code */
- 11059 # define SCSI_UNITRDY 0x00 /* Test Unit Ready */
- 11060 # define SCSI_REWIND 0x01 /* Rewind */
- 11061 # define SCSI_REQSENSE 0x03 /* Request sense */
- 11062 # define SCSI_RDLIMITS 0x05 /* Read Block Limits Opcode */
- 11063 # define SCSI_READ 0x08 /* Group 0 Read Opcode */
- 11064 # define SCSI_WRITE 0x0A /* Group 0 Write Opcode */
- 11065 # define SCSI_WREOF 0x10 /* Write File Marks */
- 11066 # define SCSI_SPACE 0x11 /* Space over filemarks/blocks */
- 11067 # define SCSI_INQUIRY 0x12 /* Group 0 Inquiry Opcode */
- 11068 # define SCSI_MDSELECT 0x15 /* Group 0 Mode Select Opcode */
- 11069 # define SCSI_ERASE 0x19 /* Erase Tape */
- 11070 # define SCSI_MDSENSE 0x1A /* Group 0 Mode Sense Opcode */
- 11071 # define SCSI_STRTSTP 0x1B /* Start/Stop */
- 11072 # define SCSI_LOADUNLD 0x1B /* Load/Unload */
- 11073 big24 d_lba; /* LUN and logical block address */
- 11074 byte d_nblocks; /* Transfer size in blocks */
- 11075 byte d_control; /* Reserved and link bit fields, set to 0 */
- 11076 } d;
- 11077 struct { /* Tape i/o commands */
- 11078 byte t_scsi_op; /* SCSI Operation Code */
- 11079 byte t_fixed; /* Fixed length? */
- 11080 big24 t_trlength; /* Transfer length */
- 11081 byte t_control; /* reserved and link bit fields, set to 0 */
- 11082 } t;
- 11083 } cdb0_t;
- 11084 #define scsi_op d.d_scsi_op
- 11085 #define lba d.d_lba
- 11086 #define nblocks d.d_nblocks
- 11087 #define fixed t.t_fixed
- 11088 #define trlength t.t_trlength
- 11089 #define control d.d_control
- 11090
- 11091 /* SCSI Group 1 Command Descriptor Block structure */
- 11092 typedef union {
- 11093 struct { /* Disk i/o commands */
- 11094 byte d_scsi_op; /* SCSI Operation Code */
- 11095 # define SCSI_CAPACITY 0x25 /* Read Capacity */
- 11096 # define SCSI_READ1 0x28 /* Group 1 Read Opcode */
- 11097 # define SCSI_WRITE1 0x2A /* Group 1 Write Opcode */
- 11098 byte d_lunra; /* LUN etc. */
- 11099 big32 d_lba; /* Logical Block Address */
- 11100 byte reserved;
- 11101 big16 d_nblocks; /* transfer size in blocks */
- 11102 byte d_control; /* reserved and link bit fields, set to 0 */
- 11103 } d;
- 11104 } cdb1_t;
- 11105 #define lunra d.d_lunra
- 11106
- 11107 /* SCSI Request Sense Information */
- 11108 typedef struct {
- 11109 byte errc; /* Error Code, Error Class, and Valid bit */
- 11110 byte segnum; /* Segment Number */
- 11111 byte key; /* Sense Key */
- 11112 # define sense_key(key) (key & 0x0F) /* the key portion */
- 11113 # define sense_ili(key) (key & 0x20) /* illegal block size */
- 11114 # define sense_eom(key) (key & 0x40) /* end-of-media */
- 11115 # define sense_eof(key) (key & 0x80) /* filemark reached */
- 11116 big32 info; /* sense info */
- 11117 byte len; /* additional length */
- 11118 big32 comspec; /* command specific info */
- 11119 byte add_code; /* additional sense code */
- 11120 byte add_qual; /* additional sense code qualifier */
- 11121 } sense_t;
- 11122
- 11123 /* Interesting SCSI sense key types. */
- 11124 #define SENSE_NO_SENSE 0x00
- 11125 #define SENSE_RECOVERED 0x01
- 11126 #define SENSE_NOT_READY 0x02
- 11127 #define SENSE_HARDWARE 0x04
- 11128 #define SENSE_UNIT_ATT 0x06
- 11129 #define SENSE_BLANK_CHECK 0x08
- 11130 #define SENSE_VENDOR 0x09
- 11131 #define SENSE_ABORTED_CMD 0x0B
- 11132
- 11133 /* SCSI Inquiry Information */
- 11134 typedef struct {
- 11135 byte devtype; /* Peripheral Device Type */
- 11136 # define SCSI_DEVDISK 0 /* Direct-access */
- 11137 # define SCSI_DEVTAPE 1 /* Sequential-access */
- 11138 # define SCSI_DEVPRN 2 /* Printer */
- 11139 # define SCSI_DEVCPU 3 /* Processor */
- 11140 # define SCSI_DEVWORM 4 /* Write-Once Read-Multiple device */
- 11141 # define SCSI_DEVCDROM 5 /* Read-Only Direct-access */
- 11142 # define SCSI_DEVSCANNER 6 /* Scanner */
- 11143 # define SCSI_DEVOPTICAL 7 /* Optical Memory */
- 11144 # define SCSI_DEVJUKEBOX 8 /* Medium Changer device */
- 11145 # define SCSI_DEVCOMM 9 /* Communications device */
- 11146 # define SCSI_DEVMAX 9 /* Last device type we know about */
- 11147 # define SCSI_DEVUNKNOWN 10 /* If we do not know or care. */
- 11148 byte devqual; /* Device-Type Qualifier */
- 11149 # define scsi_rmb(d) (((d) & 0x80) != 0) /* Removable? */
- 11150 byte stdver; /* Version of standard compliance */
- 11151 # define scsi_isover(v) (((v) & 0xC0) >> 6) /* ISO version */
- 11152 # define scsi_ecmaver(v) (((v) & 0x38) >> 3) /* ECMA version */
- 11153 # define scsi_ansiver(v) ((v) & 0x07) /* ANSI version */
- 11154 byte format; /* Response data format */
- 11155 byte len; /* length of remaining info */
- 11156 byte reserved[2];
- 11157 byte flags;
- 11158 # define scsi_sync(f) (((f) & 0x10) != 0) /* Sync SCSI? */
- 11159 char vendor[8]; /* Vendor name */
- 11160 char product[16]; /* Product name */
- 11161 char revision[4]; /* Revision level */
- 11162 char extra[20]; /* Vendor specific */
- 11163 } inquiry_t;
- 11164
- 11165 /* AHA Command Control Block structure */
- 11166 typedef struct {
- 11167 byte opcode; /* Operation Code */
- 11168 # define CCB_INIT 0x00 /* SCSI Initiator Command */
- 11169 # define CCB_TARGET 0x01 /* Target Mode Command */
- 11170 # define CCB_SCATTER 0x02 /* Initiator with scatter/gather */
- 11171 byte addrcntl; /* Address and Direction Control: */
- 11172 # define ccb_scid(id) (((id)<<5)&0xE0) /* SCSI ID field */
- 11173 # define CCB_OUTCHECK 0x10 /* Outbound length check */
- 11174 # define CCB_INCHECK 0x08 /* Inbound length check */
- 11175 # define CCB_NOCHECK 0x00 /* No length check */
- 11176 # define ccb_lun(lun) ((lun)&0x07) /* SCSI LUN field */
- 11177 byte cmdlen; /* SCSI Command Length (6 for Group 0) */
- 11178 byte senselen; /* Request/Disable Sense, Allocation Length */
- 11179 # define CCB_SENSEREQ 0x0E /* Request Sense, 14 bytes */
- 11180 # define CCB_SENSEOFF 0x01 /* Disable Request Sense */
- 11181 big24 datalen; /* Data Length: 3 bytes, big endian */
- 11182 big24 dataptr; /* Data Pointer: 3 bytes, big endian */
- 11183 big24 linkptr; /* Link Pointer: 3 bytes, big endian */
- 11184 byte linkid; /* Command Linking Identifier */
- 11185 byte hastat; /* Host Adapter Status */
- 11186 # define HST_TIMEOUT 0x11 /* SCSI selection timeout */
- 11187 byte tarstat; /* Target Device Status */
- 11188 # define TST_CHECK 0x02 /* Check status in sense[] */
- 11189 # define TST_LUNBUSY 0x08 /* Unit is very busy */
- 11190 byte reserved[2]; /* reserved, set to 0 */
- 11191 byte cmd[sizeof(cdb1_t)]; /* SCSI Command Descriptor Block */
- 11192 byte sense[sizeof(sense_t)];/* SCSI Request Sense Information */
- 11193 } ccb_t;
- 11194
- 11195
- 11196 /* End of one chunk must be as "odd" as the start of the next. */
- 11197 #define DMA_CHECK(end, start) ((((int) (end) ^ (int) (start)) & 1) == 0)
- 11198
- 11199 /* Scatter/Gather DMA list */
- 11200 typedef struct {
- 11201 big24 datalen; /* length of a memory segment */
- 11202 big24 dataptr; /* address of a memory segment */
- 11203 } dma_t;
- 11204
- 11205
- 11206 /* Miscellaneous parameters */
- 11207 #define SCSI_TIMEOUT 250 /* SCSI selection timeout (ms), 0 = none */
- 11208 #define AHA_TIMEOUT 500 /* max msec wait for controller reset */
- 11209
- 11210 #define MAX_DEVICES 8 /* 8 devices for the 8 SCSI targets */
- 11211 #define NR_DISKDEVS (MAX_DEVICES * DEV_PER_DRIVE)
- 11212 #define NR_TAPEDEVS (MAX_DEVICES * 2)
- 11213 #define NR_GENDEVS (MAX_DEVICES)
- 11214 #define SUB_PER_DRIVE (NR_PARTITIONS * NR_PARTITIONS)
- 11215 #define NR_SUBDEVS (MAX_DEVICES * SUB_PER_DRIVE)
- 11216 #define MINOR_st0 64
- 11217
- 11218 #define TYPE_SD 0 /* disk device number */
- 11219 #define TYPE_NRST 1 /* non rewind-on-close tape device */
- 11220 #define TYPE_RST 2 /* rewind-on-close tape device */
- 11221
- 11222
- 11223 /* Variables */
- 11224 PRIVATE struct scsi { /* Per-device table */
- 11225 char targ; /* SCSI Target ID */
- 11226 char lun; /* SCSI Logical Unit Number */
- 11227 char state; /* online? */
- 11228 # define S_PRESENT 0x01 /* Device exists */
- 11229 # define S_READY 0x02 /* Device is ready */
- 11230 # define S_RDONLY 0x04 /* Device is read-only */
- 11231 char devtype; /* SCSI_DEVDISK, SCSI_DEVTAPE, ... */
- 11232 unsigned block_size; /* device or media block size */
- 11233 unsigned count_max; /* maximum single read or write */
- 11234 unsigned open_ct; /* number of processes using the device */
- 11235 union {
- 11236 struct { /* Tape data */
- 11237 char open_mode; /* open for reading or writing? */
- 11238 char at_eof; /* got EOF mark */
- 11239 char need_eof; /* need to write an eof mark */
- 11240 char tfixed; /* tape in fixed mode */
- 11241 struct mtget tstat; /* tape status info */
- 11242 struct device dummypart; /* something for s_prepare to return */
- 11243 } tape;
- 11244 struct { /* Disk data */
- 11245 struct device part[DEV_PER_DRIVE]; /* primaries: sd[0-4] */
- 11246 struct device subpart[SUB_PER_DRIVE]; /* subparts: sd[1-4][a-d] */
- 11247 } disk;
- 11248 } u;
- 11249 } scsi[MAX_DEVICES];
- 11250
- 11251 #define open_mode u.tape.open_mode
- 11252 #define at_eof u.tape.at_eof
- 11253 #define need_eof u.tape.need_eof
- 11254 #define tfixed u.tape.tfixed
- 11255 #define tstat u.tape.tstat
- 11256 #define dummypart u.tape.dummypart
- 11257 #define part u.disk.part
- 11258 #define subpart u.disk.subpart
- 11259
- 11260 /* Tape device status (tstat.mt_dsreg). */
- 11261 #define DS_OK 0 /* Device OK */
- 11262 #define DS_ERR 1 /* Error state */
- 11263 #define DS_EOF 2 /* Last read or space hit EOF */
- 11264
- 11265 /* SCSI device types */
- 11266 PRIVATE char *scsi_devstr[SCSI_DEVMAX+1] = {
- 11267 "DISK", "TAPE", "PRINTER", "CPU", "WORM", "CDROM", "SCANNER", "OPTICAL",
- 11268 "JUKEBOX", "COMM"
- 11269 };
- 11270
- 11271 /* SCSI sense key types */
- 11272 PRIVATE char *str_scsi_sense[] = {
- 11273 "NO SENSE INFO", "RECOVERED ERROR", "NOT READY", "MEDIUM ERROR",
- 11274 "HARDWARE ERROR", "ILLEGAL REQUEST", "UNIT ATTENTION", "DATA PROTECT",
- 11275 "BLANK CHECK", "VENDOR UNIQUE ERROR", "COPY ABORTED", "ABORTED COMMAND",
- 11276 "EQUAL", "VOLUME OVERFLOW", "MISCOMPARE", "SENSE RESERVED"
- 11277 };
- 11278
- 11279 /* Some of the above errors must be printed on the console. */
- 11280 #if AHA_DEBUG & 1
- 11281 #define sense_serious(key) ((key) != 0)
- 11282 #else
- 11283 #define sense_serious(key) ((0xFE1C & (1 << (key))) != 0)
- 11284 #endif
- 11285
- 11286 /* Administration for one SCSI request. */
- 11287 typedef struct request {
- 11288 unsigned count; /* number of bytes to transfer */
- 11289 unsigned retry; /* number of tries allowed if retryable */
- 11290 unsigned long pos; /* first byte on the device to transfer */
- 11291 ccb_t ccb; /* Command Control Block */
- 11292 dma_t dmalist[NR_IOREQS]; /* scatter/gather dma list */
- 11293 dma_t *dmaptr; /* to add scatter/gather entries */
- 11294 dma_t *dmalimit; /* adapter model dependent limit to list */
- 11295 struct iorequest_s *iov[NR_IOREQS]; /* affected I/O requests */
- 11296 } request_t;
- 11297
- 11298 PRIVATE request_t request;
- 11299 #define rq (&request) /* current request (there is only one) */
- 11300
- 11301 #define ccb_cmd0(rq) (* (cdb0_t *) (rq)->ccb.cmd)
- 11302 #define ccb_cmd1(rq) (* (cdb1_t *) (rq)->ccb.cmd)
- 11303 #define ccb_sense(rq) (* (sense_t *) ((rq)->ccb.cmd + (rq)->ccb.cmdlen))
- 11304
- 11305 PRIVATE int aha_basereg; /* base I/O register */
- 11306 PRIVATE int aha_model; /* board model */
- 11307 PRIVATE struct scsi *s_sp; /* active SCSI device struct */
- 11308 PRIVATE struct device *s_dv; /* active partition */
- 11309 PRIVATE int s_type; /* sd, rst, nrst? */
- 11310 PRIVATE unsigned long s_nextpos;/* next byte on the device to transfer */
- 11311 PRIVATE unsigned long s_buf_blk;/* disk block currently in tmp_buf */
- 11312 PRIVATE int s_opcode; /* DEV_READ or DEV_WRITE */
- 11313 PRIVATE int s_must; /* must finish the current request? */
- 11314 PRIVATE int aha_irq; /* configured IRQ */
- 11315 PRIVATE mailbox_t mailbox[2]; /* out and in mailboxes */
- 11316 PRIVATE inquiry_t inqdata; /* results of Inquiry command */
- 11317
- 11318
- 11319 /* Functions */
- 11320
- 11321 FORWARD _PROTOTYPE( struct device *s_prepare, (int device) );
- 11322 FORWARD _PROTOTYPE( char *s_name, (void) );
- 11323 FORWARD _PROTOTYPE( int s_do_open, (struct driver *dp, message *m_ptr) );
- 11324 FORWARD _PROTOTYPE( int scsi_probe, (void) );
- 11325 FORWARD _PROTOTYPE( int scsi_sense, (void) );
- 11326 FORWARD _PROTOTYPE( int scsi_inquiry, (void) );
- 11327 FORWARD _PROTOTYPE( int scsi_ndisk, (void) );
- 11328 FORWARD _PROTOTYPE( int scsi_ntape, (void) );
- 11329 FORWARD _PROTOTYPE( int s_schedule, (int proc_nr, struct iorequest_s *iop) );
- 11330 FORWARD _PROTOTYPE( int s_finish, (void) );
- 11331 FORWARD _PROTOTYPE( int s_rdcdrom, (int proc_nr, struct iorequest_s *iop,
- 11332 unsigned long pos, unsigned nbytes, phys_bytes user_phys) );
- 11333 FORWARD _PROTOTYPE( int s_do_close, (struct driver *dp, message *m_ptr) );
- 11334 FORWARD _PROTOTYPE( int s_do_ioctl, (struct driver *dp, message *m_ptr) );
- 11335 FORWARD _PROTOTYPE( int scsi_simple, (int opcode, int count) );
- 11336 FORWARD _PROTOTYPE( void group0, (void) );
- 11337 FORWARD _PROTOTYPE( void group1, (void) );
- 11338 FORWARD _PROTOTYPE( int scsi_command, (phys_bytes data, vir_bytes len) );
- 11339 FORWARD _PROTOTYPE( void aha_command, (int outlen, byte *outptr,
- 11340 int inlen, byte *inptr) );
- 11341 FORWARD _PROTOTYPE( int aha_reset, (void) );
- 11342 FORWARD _PROTOTYPE( int s_handler, (int irq) );
- 11343
- 11344 FORWARD _PROTOTYPE( void h2b16, (big16 b, U16_t l) );
- 11345 FORWARD _PROTOTYPE( void h2b24, (big24 b, u32_t l) );
- 11346 FORWARD _PROTOTYPE( void h2b32, (big32 b, u32_t l) );
- 11347 FORWARD _PROTOTYPE( u16_t b2h16, (big16 b) );
- 11348 FORWARD _PROTOTYPE( u32_t b2h24, (big24 b) );
- 11349 FORWARD _PROTOTYPE( u32_t b2h32, (big32 b) );
- 11350
- 11351
- 11352 #if AHA_DEBUG & 2
- 11353 FORWARD _PROTOTYPE( void errordump, (void) );
- 11354 #else
- 11355 #define errordump()
- 11356 #endif
- 11357
- 11358 #if AHA_DEBUG & 4
- 11359 FORWARD _PROTOTYPE( void show_req, (void) );
- 11360 #else
- 11361 #define show_req()
- 11362 #endif
- 11363
- 11364 #if AHA_DEBUG & 8
- 11365 FORWARD _PROTOTYPE( void dump_scsi_cmd, (void) );
- 11366 #else
- 11367 #define dump_scsi_cmd()
- 11368 #endif
- 11369
- 11370 FORWARD _PROTOTYPE( void s_geometry, (struct partition *entry));
- 11371
- 11372
- 11373 /* Entry points to this driver. */
- 11374 PRIVATE struct driver s_dtab = {
- 11375 s_name, /* current device's name */
- 11376 s_do_open, /* open or mount request, initialize device */
- 11377 s_do_close, /* release device */
- 11378 s_do_ioctl, /* tape and partition ioctls */
- 11379 s_prepare, /* prepare for I/O on a given minor device */
- 11380 s_schedule, /* precompute SCSI transfer parameters, etc. */
- 11381 s_finish, /* do the I/O */
- 11382 nop_cleanup, /* no cleanup needed */
- 11383 s_geometry /* tell the geometry of the disk */
- 11384 };
- 11385
- 11386
- 11387 /*===========================================================================*
- 11388 * aha_scsi_task *
- 11389 *===========================================================================*/
- 11390 PUBLIC void aha_scsi_task()
- 11391 {
- 11392 /* Set target and logical unit numbers, then call the generic main loop. */
- 11393 int i;
- 11394 struct scsi *sp;
- 11395 long v;
- 11396 char *name;
- 11397 static char fmt[] = "d,d";
- 11398
- 11399 for (i = 0; i < MAX_DEVICES; i++) {
- 11400 (void) s_prepare(i * DEV_PER_DRIVE);
- 11401 sp = s_sp;
- 11402
- 11403 /* Look into the environment for special parameters. */
- 11404 name = s_name();
- 11405
- 11406 v = i;
- 11407 (void) env_parse(name, fmt, 0, &v, 0L, 7L);
- 11408 sp->targ = v;
- 11409
- 11410 v = 0;
- 11411 (void) env_parse(name, fmt, 1, &v, 0L, 7L);
- 11412 sp->lun = v;
- 11413 }
- 11414 driver_task(&s_dtab);
- 11415 }
-
-
- 11418 /*===========================================================================*
- 11419 * s_prepare *
- 11420 *===========================================================================*/
- 11421 PRIVATE struct device *s_prepare(device)
- 11422 int device;
- 11423 {
- 11424 /* Prepare for I/O on a device. */
- 11425
- 11426 rq->count = 0; /* no requests as yet */
- 11427 s_must = TRUE; /* the first transfers must be done */
- 11428 s_buf_blk = -1; /* invalidate s_buf_blk */
- 11429
- 11430 if (device < NR_DISKDEVS) { /* sd0, sd1, ... */
- 11431 s_type = TYPE_SD;
- 11432 s_sp = &scsi[device / DEV_PER_DRIVE];
- 11433 s_dv = &s_sp->part[device % DEV_PER_DRIVE];
- 11434 } else
- 11435 if ((unsigned) (device - MINOR_hd1a) < NR_SUBDEVS) { /* sd1a, sd1b, ... */
- 11436 device -= MINOR_hd1a;
- 11437 s_type = TYPE_SD;
- 11438 s_sp = &scsi[device / SUB_PER_DRIVE];
- 11439 s_dv = &s_sp->subpart[device % SUB_PER_DRIVE];
- 11440 } else
- 11441 if ((unsigned) (device - MINOR_st0) < NR_TAPEDEVS) { /* nrst0, rst0, ... */
- 11442 device -= MINOR_st0;
- 11443 s_type = device & 1 ? TYPE_RST : TYPE_NRST;
- 11444 s_sp = &scsi[device >> 1];
- 11445 s_dv = &s_sp->dummypart;
- 11446 } else {
- 11447 return(NIL_DEV);
- 11448 }
- 11449
- 11450 return(s_dv);
- 11451 }
-
-
- 11454 /*===========================================================================*
- 11455 * s_name *
- 11456 *===========================================================================*/
- 11457 PRIVATE char *s_name()
- 11458 {
- 11459 /* Return a name for the current device. */
- 11460 static char name[] = "sd35";
- 11461 int n = (s_sp - scsi);
- 11462
- 11463 switch (s_type) {
- 11464 case TYPE_SD: /* Disk device: sd* */
- 11465 name[1] = 'd';
- 11466 n *= DEV_PER_DRIVE;
- 11467 break;
- 11468 case TYPE_RST: /* Tape device: st* */
- 11469 case TYPE_NRST:
- 11470 name[1] = 't';
- 11471 break;
- 11472 }
- 11473 if (n < 10) {
- 11474 name[2] = '0' + n;
- 11475 name[3] = 0;
- 11476 } else {
- 11477 name[2] = '0' + n / 10;
- 11478 name[3] = '0' + n % 10;
- 11479 }
- 11480 return name;
- 11481 }
-
-
- 11484 /*===========================================================================*
- 11485 * s_do_open *
- 11486 *===========================================================================*/
- 11487 PRIVATE int s_do_open(dp, m_ptr)
- 11488 struct driver *dp;
- 11489 message *m_ptr;
- 11490 {
- 11491 struct scsi *sp;
- 11492 int r;
- 11493
- 11494 if (aha_irq == 0 && !aha_reset()) return(EIO); /* no controller, forget it */
- 11495
- 11496 if (s_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
- 11497 sp = s_sp;
- 11498
- 11499 if ((r = scsi_probe()) != OK) return(r);
- 11500
- 11501 if (sp->state & S_RDONLY && m_ptr->COUNT & W_BIT) return(EACCES);
- 11502
- 11503 switch (sp->devtype) {
- 11504 case SCSI_DEVDISK:
- 11505 case SCSI_DEVWORM:
- 11506 case SCSI_DEVCDROM:
- 11507 case SCSI_DEVOPTICAL:
- 11508 /* Read partition tables on first open. */
- 11509 if (sp->open_ct == 0) {
- 11510 partition(&s_dtab, (int) (sp-scsi) * DEV_PER_DRIVE, P_PRIMARY);
- 11511 }
- 11512 break;
- 11513 case SCSI_DEVTAPE:
- 11514 /* Make sure tape is not already open. */
- 11515 if (sp->open_ct > 0) return(EBUSY);
- 11516
- 11517 sp->open_mode = m_ptr->COUNT;
- 11518 /* If open(..., O_WRONLY) then write a filemark on close even if no
- 11519 * write is done.
- 11520 */
- 11521 sp->need_eof = ((sp->open_mode & (R_BIT|W_BIT)) == W_BIT);
- 11522 break;
- 11523 }
- 11524 sp->open_ct++;
- 11525 return(OK);
- 11526 }
-
-
- 11529 /*===========================================================================*
- 11530 * scsi_probe *
- 11531 *===========================================================================*/
- 11532 PRIVATE int scsi_probe()
- 11533 {
- 11534 /* See if a device exists and if it is ready. */
- 11535 struct scsi *sp = s_sp;
- 11536 sense_t *sense;
- 11537 int r, key;
- 11538
- 11539 /* Something out there? */
- 11540 if ((r = scsi_sense()) != OK) {
- 11541 if (sp->state & S_PRESENT) {
- 11542 printf("%s: offlinen", s_name());
- 11543 sp->state = 0;
- 11544 }
- 11545 return(r);
- 11546 }
- 11547
- 11548 if (!(sp->state & S_PRESENT)) {
- 11549 /* First contact with a new device, what type is it? */
- 11550
- 11551 if ((r = scsi_inquiry()) != OK) return(r);
- 11552
- 11553 sp->devtype = inqdata.devtype;
- 11554 }
- 11555
- 11556 if (!(sp->state & S_READY)) {
- 11557 /* If it's a disk: start it, if it's a tape: load it. */
- 11558 (void) scsi_simple(SCSI_STRTSTP, 1);
- 11559 }
- 11560
- 11561 /* See if the unit is ready for I/O. A disk may be spinning up, a
- 11562 * floppy or tape drive may be empty.
- 11563 */
- 11564 while ((key = scsi_simple(SCSI_UNITRDY, 0)) != SENSE_NO_SENSE) {
- 11565 /* Not ready, why? */
- 11566
- 11567 sp->state &= ~S_READY;
- 11568
- 11569 switch (key) {
- 11570 case SENSE_UNIT_ATT:
- 11571 /* A media change or something, try again. */
- 11572 break;
- 11573 case SENSE_NOT_READY:
- 11574 /* Look at the additional sense data to see why it isn't
- 11575 * ready.
- 11576 */
- 11577 sense = &ccb_sense(rq);
- 11578 switch ((sense->add_code << 8) | sense->add_qual) {
- 11579 case 0x0401:
- 11580 /* "It is becoming ready." Fine, we wait. */
- 11581 milli_delay(1000);
- 11582 break;
- 11583 case 0x0402:
- 11584 /* "Initialization command required." So we tell it
- 11585 * to spin up.
- 11586 */
- 11587 if (scsi_simple(SCSI_STRTSTP, 1) != SENSE_NO_SENSE)
- 11588 return(EIO);
- 11589 break;
- 11590 case 0x0403:
- 11591 /* "Manual intervention required." */
- 11592 case 0x3A00:
- 11593 /* "No media present." */
- 11594 printf("%s: no media loadedn", s_name());
- 11595 return(EIO);
- 11596 default:
- 11597 /* For some reason it is not usable. */
- 11598 printf("%s: not readyn", s_name());
- 11599 return(EIO);
- 11600 }
- 11601 break;
- 11602 default:
- 11603 /* The device is in some odd state. */
- 11604 if (key != SENSE_NOT_READY) {
- 11605 printf("%s: hardware errorn", s_name());
- 11606 return(EIO);
- 11607 }
- 11608 }
- 11609 }
- 11610
- 11611 if (!(sp->state & S_PRESENT)) {
- 11612 /* Do the inquiry again, the message may have changed. */
- 11613 if (scsi_inquiry() != OK) return(EIO);
- 11614
- 11615 /* Tell what kind of device it is we have found. */
- 11616
- 11617 printf("%s: %-7s %.48sn",
- 11618 s_name(),
- 11619 inqdata.devtype > SCSI_DEVMAX ? "UNKNOWN"
- 11620 : scsi_devstr[inqdata.devtype],
- 11621 inqdata.vendor /* + product + revision + extra */);
- 11622 }
- 11623
- 11624 if (!(sp->state & S_READY)) {
- 11625 /* Get the geometry, limits, etc. */
- 11626
- 11627 switch (sp->devtype) {
- 11628 case SCSI_DEVDISK:
- 11629 case SCSI_DEVWORM:
- 11630 case SCSI_DEVCDROM:
- 11631 case SCSI_DEVOPTICAL:
- 11632 if (scsi_ndisk() != OK) return(EIO);
- 11633 break;
- 11634 case SCSI_DEVTAPE:
- 11635 if (scsi_ntape() != OK) return(EIO);
- 11636 break;
- 11637 default:
- 11638 printf("%s: unsupportedn", s_name());
- 11639 return(EIO);
- 11640 }
- 11641 }
- 11642 return(OK);
- 11643 }
-
-
- 11646 /*===========================================================================*
- 11647 * scsi_sense *
- 11648 *===========================================================================*/
- 11649 PRIVATE int scsi_sense()
- 11650 {
- 11651 int key;
- 11652 sense_t *sense = (sense_t *) tmp_buf;
- 11653
- 11654 /* Do a request sense to find out if a target exists or to check out
- 11655 * a unit attention condition.
- 11656 */
- 11657 key = scsi_simple(SCSI_REQSENSE, sizeof(sense_t));
- 11658
- 11659 if (rq->ccb.hastat == HST_TIMEOUT) return(ENXIO); /* nothing there */
- 11660 if (rq->ccb.hastat != 0) return(EIO); /* something very bad */
- 11661
- 11662 /* There is something out there for sure. */
- 11663 if (key == SENSE_UNIT_ATT || sense_key(sense->key) == SENSE_UNIT_ATT) {
- 11664 /* Device is in a "look at me" state, probably changed media. */
- 11665 s_sp->state &= ~S_READY;
- 11666 }
- 11667 return(OK);
- 11668 }
-
-
- 11671 /*===========================================================================*
- 11672 * scsi_inquiry *
- 11673 *===========================================================================*/
- 11674 PRIVATE int scsi_inquiry()
- 11675 {
- 11676 /* Prefill with nulls. */
- 11677 memset(tmp_buf, ' ', sizeof(inquiry_t));
- 11678
- 11679 /* Do a SCSI inquiry. */
- 11680 if (scsi_simple(SCSI_INQUIRY, sizeof(inquiry_t)) != SENSE_NO_SENSE)
- 11681 return(EIO);
- 11682 inqdata = * (inquiry_t *) tmp_buf;
- 11683
- 11684 if (inqdata.len == 0) {
- 11685 /* The device doesn't return meaningful text fields. */
- 11686 strcpy(inqdata.vendor, "(unknown)");
- 11687 }
- 11688
- 11689 /* The top three bits of devtype must be zero for the lun to exist. */
- 11690 if ((inqdata.devtype & 0xE0) != 0) return(ENXIO);
- 11691
- 11692 return(OK);
- 11693 }
-
-
- 11696 /*===========================================================================*
- 11697 * scsi_ndisk *
- 11698 *===========================================================================*/
- 11699 PRIVATE int scsi_ndisk()
- 11700 {
- 11701 /* Gather disk data, capacity and block size. */
- 11702
- 11703 struct scsi *sp = s_sp;
- 11704 unsigned long capacity = -1, block_size = SECTOR_SIZE;
- 11705 byte *buf = tmp_buf;
- 11706
- 11707 /* Minor device type must be for a disk. */
- 11708 if (s_type != TYPE_SD) return(EIO);
- 11709
- 11710 if (sp->devtype == SCSI_DEVCDROM) {
- 11711 /* Read-only by definition. */
- 11712 sp->state |= S_RDONLY;
- 11713 } else {
- 11714 /* SCSI modesense to find out if the disk is write protected. */
- 11715 if (scsi_simple(SCSI_MDSENSE, 255) != SENSE_NO_SENSE) return(EIO);
- 11716
- 11717 /* Write protected? */
- 11718 sp->state &= ~S_RDONLY;
- 11719 if (buf[2] & 0x80) sp->state |= S_RDONLY;
- 11720
- 11721 /* Don't write a worm disk, not wise at the moment. */
- 11722 if (sp->devtype == SCSI_DEVWORM) sp->state |= S_RDONLY;
- 11723 }
- 11724
- 11725 /* Get drive capacity and block size. */
- 11726 group1();
- 11727 rq->ccb.opcode = CCB_INIT;
- 11728 ccb_cmd1(rq).scsi_op = SCSI_CAPACITY;
- 11729
- 11730 if (scsi_command(tmp_phys, 8) == SENSE_NO_SENSE) {
- 11731 capacity = b2h32(buf + 0) + 1;
- 11732 block_size = b2h32(buf + 4);
- 11733 printf("%s: capacity %lu x %lu bytesn",
- 11734 s_name(), capacity, block_size);
- 11735 } else {
- 11736 printf("%s: unknown capacityn", s_name());
- 11737 }
- 11738
- 11739 /* We do not believe block sizes over 4 kb. */
- 11740 if (block_size > 4096) {
- 11741 printf("%s: can't handle %lu byte blocksn", s_name(), block_size);
- 11742 return(EIO);
- 11743 }
- 11744
- 11745 sp->block_size = block_size;
- 11746 #if _WORD_SIZE > 2
- 11747 /* Keep it within reach of a group 0 command. */
- 11748 sp->count_max = 0x100 * block_size;
- 11749 #else
- 11750 sp->count_max = block_size > UINT_MAX/0x100 ? UINT_MAX : 0x100 * block_size;
- 11751 #endif
- 11752
- 11753 /* The fun ends at 4GB. */
- 11754 if (capacity > ((unsigned long) -1) / block_size)
- 11755 sp->part[0].dv_size = -1;
- 11756 else
- 11757 sp->part[0].dv_size = capacity * block_size;
- 11758
- 11759 /* Finally we recognize its existence. */
- 11760 sp->state |= S_PRESENT|S_READY;
- 11761
- 11762 return(OK);
- 11763 }
-
-
- 11766 /*===========================================================================*
- 11767 * scsi_ntape *
- 11768 *===========================================================================*/
- 11769 PRIVATE int scsi_ntape()
- 11770 {
- 11771 /* Gather tape data, block limits, fixed block size or not. */
- 11772 struct scsi *sp = s_sp;
- 11773 unsigned minblk;
- 11774 unsigned long maxblk;
- 11775 byte *buf = tmp_buf;
- 11776
- 11777 /* Minor device type must be for a tape. */
- 11778 if (s_type != TYPE_RST && s_type != TYPE_NRST) return(EIO);
- 11779
- 11780 /* Read limits. */
- 11781 if (scsi_simple(SCSI_RDLIMITS, 6) != SENSE_NO_SENSE) return(EIO);
- 11782 minblk = b2h16(buf + 4);
- 11783 maxblk = b2h24(buf + 1);
- 11784
- 11785 printf("%s: limits: min block len %u, max block len %lun",
- 11786 s_name(), minblk, maxblk);
- 11787
- 11788 if (sp->state & S_PRESENT) {
- 11789 /* Keep the current block size. */
- 11790 if (sp->tfixed) minblk= maxblk= sp->block_size;
- 11791 }
- 11792
- 11793 sp->tstat.mt_dsreg = DS_OK;
- 11794 sp->tstat.mt_erreg = 0;
- 11795 sp->tstat.mt_fileno = 0;
- 11796 sp->tstat.mt_blkno = 0;
- 11797 sp->tstat.mt_resid = 0;
- 11798
- 11799 if (minblk == maxblk) {
- 11800 /* Fixed block length. */
- 11801 sp->tfixed = TRUE;
- 11802 sp->block_size = minblk;
- 11803 sp->tstat.mt_blksize = minblk;
- 11804 sp->count_max = UINT_MAX;
- 11805 } else {
- 11806 /* Variable block length. */
- 11807 sp->tfixed = FALSE;
- 11808 sp->block_size = 1;
- 11809 sp->tstat.mt_blksize = 0;
- 11810 sp->count_max = maxblk == 0 ? UINT_MAX : maxblk;
- 11811 }
- 11812
- 11813 /* SCSI modesense. */
- 11814 if (scsi_simple(SCSI_MDSENSE, 255) != SENSE_NO_SENSE) return(EIO);
- 11815
- 11816 /* Write protected? */
- 11817 sp->state &= ~S_RDONLY;
- 11818 if (buf[2] & 0x80) sp->state |= S_RDONLY;
- 11819
- 11820 /* Density and block size. */
- 11821 if (buf[3] >= 8) {
- 11822 printf("%s: density 0x%02x, nblocks %lu, block len ",
- 11823 s_name(),
- 11824 buf[4],
- 11825 b2h24(buf + 4 + 1));
- 11826 printf(sp->tfixed ? "%lun" : "variablen", b2h24(buf + 4 + 5));
- 11827 }
- 11828
- 11829 sp->state |= S_PRESENT|S_READY;
- 11830 return(OK);
- 11831 }
-
-
- 11834 /*===========================================================================*
- 11835 * s_schedule *
- 11836 *===========================================================================*/
- 11837 PRIVATE int s_schedule(proc_nr, iop)
- 11838 int proc_nr; /* process doing the request */
- 11839 struct iorequest_s *iop; /* pointer to read or write request */
- 11840 {
- 11841 /* Gather I/O requests on consecutive blocks so they may be read/written
- 11842 * in one SCSI command using scatter/gather DMA.
- 11843 */
- 11844 struct scsi *sp = s_sp;
- 11845 int r, opcode, spanning;
- 11846 unsigned nbytes, count;
- 11847 unsigned long pos;
- 11848 phys_bytes user_phys, dma_phys;
- 11849 static unsigned dma_count;
- 11850 static struct iorequest_s **iopp; /* to add I/O request pointers */
- 11851 static phys_bytes dma_last; /* address of end of the last added entry */
- 11852
- 11853 /* This many bytes to read/write */
- 11854 nbytes = iop->io_nbytes;
- 11855
- 11856 /* From/to this position on the device */
- 11857 pos = iop->io_position;
- 11858
- 11859 /* To/from this user address */
- 11860 user_phys = numap(proc_nr, (vir_bytes) iop->io_buf, nbytes);
- 11861 if (user_phys == 0) return(iop->io_nbytes = EINVAL);
- 11862
- 11863 /* Read or write? */
- 11864 opcode = iop->io_request & ~OPTIONAL_IO;
- 11865
- 11866 switch (sp->devtype) {
- 11867 case SCSI_DEVCDROM:
- 11868 case SCSI_DEVWORM:
- 11869 case SCSI_DEVDISK:
- 11870 case SCSI_DEVOPTICAL:
- 11871 /* Which block on disk and how close to EOF? */
- 11872 if (pos >= s_dv->dv_size) return(OK); /* At EOF */
- 11873 if (pos + nbytes > s_dv->dv_size) nbytes = s_dv->dv_size - pos;
- 11874 pos += s_dv->dv_base;
- 11875
- 11876 if ((nbytes % sp->block_size) != 0 || (pos % sp->block_size) != 0) {
- 11877 /* Not on a device block boundary. CD-ROM? */
- 11878 return(s_rdcdrom(proc_nr, iop, pos, nbytes, user_phys));
- 11879 }
- 11880 break;
- 11881
- 11882 case SCSI_DEVTAPE:
- 11883 if ((nbytes % sp->block_size) != 0)
- 11884 return(iop->io_nbytes = EINVAL);
- 11885
- 11886 /* Old error condition? */
- 11887 if (sp->tstat.mt_dsreg == DS_ERR) return(iop->io_nbytes = EIO);
- 11888
- 11889 if (opcode == DEV_READ && sp->at_eof) return(OK);
- 11890
- 11891 s_nextpos = pos = 0; /* pos is ignored */
- 11892 break;
- 11893
- 11894 default:
- 11895 return(iop->io_nbytes = EIO);
- 11896 }
- 11897
- 11898 /* Probe a device that isn't ready. */
- 11899 if (!(sp->state & S_READY) && scsi_probe() != OK) return(EIO);
- 11900
- 11901 if (rq->count > 0 && pos != s_nextpos) {
- 11902 /* This new request can't be chained to the job being built. */
- 11903 if ((r = s_finish()) != OK) return(r);
- 11904 }
- 11905
- 11906 /* The next consecutive block starts at byte position... */
- 11907 s_nextpos = pos + nbytes;
- 11908
- 11909 spanning = FALSE; /* set if a request spans several DMA vectors */
- 11910
- 11911 /* While there are "unscheduled" bytes in the request: */
- 11912 do {
- 11913 dma_phys = user_phys;
- 11914
- 11915 if (rq->count > 0 && (
- 11916 rq->count == sp->count_max
- 11917 || rq->dmaptr == rq->dmalimit
- 11918 || !DMA_CHECK(dma_last, dma_phys)
- 11919 )) {
- 11920 /* This request can not be added to the scatter/gather list. */
- 11921 if ((r = s_finish()) != OK) return(r);
- 11922 s_must = spanning;
- 11923
- 11924 continue; /* try again */
- 11925 }
- 11926
- 11927 if (rq->count == 0) {
- 11928 /* The first request in a row, initialize. */
- 11929 rq->pos = pos;
- 11930 s_opcode = opcode;
- 11931 iopp = rq->iov;
- 11932 rq->dmaptr = rq->dmalist;
- 11933 rq->retry = 2;
- 11934 }
- 11935
- 11936 count = nbytes;
- 11937
- 11938 /* Don't exceed the maximum transfer count. */
- 11939 if (rq->count + count > sp->count_max)
- 11940 count = sp->count_max - rq->count;
- 11941
- 11942 /* New scatter/gather entry. */
- 11943 h2b24(rq->dmaptr->dataptr, dma_phys);
- 11944 h2b24(rq->dmaptr->datalen, (u32_t) (dma_count = count));
- 11945 rq->dmaptr++;
- 11946 dma_last = dma_phys + count;
- 11947
- 11948 /* Which I/O request? */
- 11949 *iopp++ = iop;
- 11950
- 11951 /* Update counters. */
- 11952 rq->count += count;
- 11953 pos += count;
- 11954 user_phys += count;
- 11955 nbytes -= count;
- 11956 if (!(iop->io_request & OPTIONAL_IO)) s_must = TRUE;
- 11957
- 11958 spanning = TRUE; /* the rest of the request must be done */
- 11959 } while (nbytes > 0);
- 11960
- 11961 return(OK);
- 11962 }
-
-
- 11965 /*===========================================================================*
- 11966 * s_finish *
- 11967 *===========================================================================*/
- 11968 PRIVATE int s_finish()
- 11969 {
- 11970 /* Send the I/O requests gathered in *rq to the host adapter. */
- 11971
- 11972 struct scsi *sp = s_sp;
- 11973 unsigned long block;
- 11974 struct iorequest_s **iopp, *iop;
- 11975 int key;
- 11976
- 11977 if (rq->count == 0) return(OK); /* spurious finish */
- 11978
- 11979 show_req();
- 11980
- 11981 /* If all the requests are optional then don't do just a few. */
- 11982 if (!s_must && rq->count < 0x2000) {
- 11983 rq->count = 0;
- 11984 return(OK);
- 11985 }
- 11986
- 11987 iopp = rq->iov;
- 11988 iop = *iopp++;
- 11989
- 11990 retry:
- 11991 switch (sp->devtype) {
- 11992 case SCSI_DEVCDROM:
- 11993 case SCSI_DEVWORM:
- 11994 case SCSI_DEVDISK:
- 11995 case SCSI_DEVOPTICAL:
- 11996 /* A read or write SCSI command for a random access device. */
- 11997 block = rq->pos / sp->block_size;
- 11998
- 11999 if (block < (1L << 21)) {
- 12000 /* We can use a group 0 command for small disks. */
- 12001 group0();
- 12002 rq->ccb.opcode = CCB_SCATTER;
- 12003 ccb_cmd0(rq).scsi_op =
- 12004 s_opcode == DEV_WRITE ? SCSI_WRITE : SCSI_READ;
- 12005 h2b24(ccb_cmd0(rq).lba, block);
- 12006 ccb_cmd0(rq).nblocks = rq->count / sp->block_size;
- 12007 } else {
- 12008 /* Large disks require a group 1 command. */
- 12009 group1();
- 12010 rq->ccb.opcode = CCB_SCATTER;
- 12011 ccb_cmd1(rq).scsi_op =
- 12012 s_opcode == DEV_WRITE ? SCSI_WRITE1 : SCSI_READ1;
- 12013 h2b32(ccb_cmd1(rq).lba, block);
- 12014 h2b16(ccb_cmd1(rq).nblocks, rq->count / sp->block_size);
- 12015 }
- 12016
- 12017 key = scsi_command(0L, 0);
- 12018
- 12019 if (key == SENSE_NO_SENSE) {
- 12020 /* fine */;
- 12021 } else
- 12022 if (key == SENSE_UNIT_ATT || key == SENSE_ABORTED_CMD) {
- 12023 /* Check condition? Bus reset most likely. */
- 12024 /* Aborted command? Maybe retrying will help. */
- 12025 if (--rq->retry > 0) goto retry;
- 12026 return(iop->io_nbytes = EIO);
- 12027 } else
- 12028 if (key == SENSE_RECOVERED) {
- 12029 /* Disk drive managed to recover from a read error. */
- 12030 printf("%s: soft read error at block %lu (recovered)n",
- 12031 s_name(), b2h32(ccb_sense(rq).info));
- 12032 key = SENSE_NO_SENSE;
- 12033 break;
- 12034 } else {
- 12035 /* A fatal error occurred, bail out. */
- 12036 return(iop->io_nbytes = EIO);
- 12037 }
- 12038 break;
- 12039
- 12040 case SCSI_DEVTAPE:
- 12041 /* A read or write SCSI command for a sequential access device. */
- 12042 group0();
- 12043 rq->ccb.opcode = CCB_SCATTER;
- 12044 ccb_cmd0(rq).scsi_op = s_opcode == DEV_WRITE ? SCSI_WRITE : SCSI_READ;
- 12045 ccb_cmd0(rq).fixed = sp->tfixed;
- 12046 h2b24(ccb_cmd0(rq).trlength, rq->count / sp->block_size);
- 12047
- 12048 key = scsi_command(0L, 0);
- 12049
- 12050 if (key != SENSE_NO_SENSE) {
- 12051 /* Either at EOF or EOM, or an I/O error. */
- 12052
- 12053 if (sense_eof(key) || sense_eom(key)) {
- 12054 /* Not an error, but EOF or EOM. */
- 12055 sp->at_eof = TRUE;
- 12056 sp->tstat.mt_dsreg = DS_EOF;
- 12057
- 12058 /* The residual tells how much has not been read. */
- 12059 rq->count -= sp->tstat.mt_resid * sp->block_size;
- 12060
- 12061 if (sense_eof(key)) {
- 12062 /* Went over a filemark. */
- 12063 sp->tstat.mt_blkno = !sp->tfixed ? -1 :
- 12064 - (int) (rq->count / sp->block_size);
- 12065 sp->tstat.mt_fileno++;
- 12066 }
- 12067 }
- 12068 if (sense_ili(key)) {
- 12069 /* Incorrect length on a variable block length tape. */
- 12070
- 12071 if (sp->tstat.mt_resid <= 0) {
- 12072 /* Large block could not be read. */
- 12073 return(iop->io_nbytes = EIO);
- 12074 }
- 12075 /* Small block read, this is ok. */
- 12076 rq->count -= sp->tstat.mt_resid;
- 12077 sp->tstat.mt_dsreg = DS_OK;
- 12078 }
- 12079 if (key == SENSE_RECOVERED) {
- 12080 /* Tape drive managed to recover from an error. */
- 12081 printf("%s: soft %s error (recovered)n",
- 12082 s_name(),
- 12083 s_opcode == DEV_READ ? "read" : "write");
- 12084 key = SENSE_NO_SENSE;
- 12085 sp->tstat.mt_dsreg = DS_OK;
- 12086 }
- 12087 if (sp->tstat.mt_dsreg == DS_ERR) {
- 12088 /* Error was fatal. */
- 12089 return(iop->io_nbytes = EIO);
- 12090 }
- 12091 } else {
- 12092 sp->tstat.mt_dsreg = DS_OK;
- 12093 }
- 12094 if (!sp->tfixed) {
- 12095 /* Variable block length tape reads record by record. */
- 12096 sp->tstat.mt_blkno++;
- 12097 } else {
- 12098 /* Fixed length tape, multiple blocks transferred. */
- 12099 sp->tstat.mt_blkno += rq->count / sp->block_size;
- 12100 }
- 12101 sp->need_eof = (s_opcode == DEV_WRITE);
- 12102 break;
- 12103
- 12104 default:
- 12105 assert(0);
- 12106 }
- 12107
- 12108 /* Remove bytes transferred from the I/O requests. */
- 12109 for (;;) {
- 12110 if (rq->count > iop->io_nbytes) {
- 12111 rq->count -= iop->io_nbytes;
- 12112 iop->io_nbytes = 0;
- 12113 } else {
- 12114 iop->io_nbytes -= rq->count;
- 12115 rq->count = 0;
- 12116 break;
- 12117 }
- 12118 iop = *iopp++;
- 12119 }
- 12120 return(key == SENSE_NO_SENSE ? OK : EIO); /* may return EIO for EOF */
- 12121 }
-
-
- 12124 /*===========================================================================*
- 12125 * s_rdcdrom *
- 12126 *===========================================================================*/
- 12127 PRIVATE int s_rdcdrom(proc_nr, iop, pos, nbytes, user_phys)
- 12128 int proc_nr; /* process doing the request */
- 12129 struct iorequest_s *iop; /* pointer to read or write request */
- 12130 unsigned long pos; /* byte position */
- 12131 unsigned nbytes; /* number of bytes */
- 12132 phys_bytes user_phys; /* user address */
- 12133 {
- 12134 /* CD-ROM's have a basic block size of 2k. We could try to set a smaller
- 12135 * virtual block size, but many don't support it. So we use this function.
- 12136 */
- 12137 struct scsi *sp = s_sp;
- 12138 int r, key;
- 12139 unsigned offset, count;
- 12140 unsigned long block;
- 12141
- 12142 /* Only do reads. */
- 12143 if ((iop->io_request & ~OPTIONAL_IO) != DEV_READ)
- 12144 return(iop->io_nbytes = EINVAL);
- 12145
- 12146 /* Finish any outstanding I/O. */
- 12147 if ((r = s_finish()) != OK) return(r);
- 12148
- 12149 do {
- 12150 /* Probe a device that isn't ready. */
- 12151 if (!(sp->state & S_READY) && scsi_probe() != OK) return(EIO);
- 12152
- 12153 block = pos / sp->block_size;
- 12154 if (block == s_buf_blk) {
- 12155 /* Some of the requested bytes are in the buffer. */
- 12156 offset = pos % sp->block_size;
- 12157 count = sp->block_size - offset;
- 12158 if (count > nbytes) count = nbytes;
- 12159 phys_copy(tmp_phys + offset, user_phys, (phys_bytes) count);
- 12160 pos += count;
- 12161 user_phys += count;
- 12162 nbytes -= count;
- 12163 iop->io_nbytes -= count;
- 12164 } else {
- 12165 /* Read a block that contains (some of) the bytes wanted. */
- 12166 rq->retry = 2;
- 12167 do {
- 12168 group1();
- 12169 rq->ccb.opcode = CCB_INIT;
- 12170 ccb_cmd1(rq).scsi_op = SCSI_READ1;
- 12171 h2b32(ccb_cmd1(rq).lba, block);
- 12172 h2b16(ccb_cmd1(rq).nblocks, 1);
- 12173 key = scsi_command(tmp_phys, sp->block_size);
- 12174 } while (key == SENSE_UNIT_ATT && --rq->retry > 0);
- 12175
- 12176 if (key != SENSE_NO_SENSE) return(iop->io_nbytes = EIO);
- 12177
- 12178 s_buf_blk = block; /* remember block in buffer */
- 12179 }
- 12180 } while (nbytes > 0);
- 12181 return(OK);
- 12182 }
-
-
- 12185 /*===========================================================================*
- 12186 * s_do_close *
- 12187 *===========================================================================*/
- 12188 PRIVATE int s_do_close(dp, m_ptr)
- 12189 struct driver *dp;
- 12190 message *m_ptr;
- 12191 {
- 12192 struct scsi *sp;
- 12193
- 12194 if (s_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
- 12195 sp = s_sp;
- 12196
- 12197 sp->open_ct--;
- 12198
- 12199 /* Disks and such don't make trouble. */
- 12200 if (sp->devtype != SCSI_DEVTAPE) return(OK);
- 12201
- 12202 sp->at_eof = FALSE;
- 12203
- 12204 /* Write filemark if writes have been done. */
- 12205 if (sp->need_eof && sp->tstat.mt_dsreg != DS_ERR) {
- 12206 if (scsi_simple(SCSI_WREOF, 1) != SENSE_NO_SENSE) {
- 12207 printf("%s: failed to add filemarkn", s_name());
- 12208 } else {
- 12209 sp->tstat.mt_dsreg = DS_OK;
- 12210 sp->tstat.mt_blkno = 0;
- 12211 sp->tstat.mt_fileno++;
- 12212 }
- 12213 }
- 12214
- 12215 /* Rewind if rewind device. */
- 12216 if (s_type == TYPE_RST) {
- 12217 if (scsi_simple(SCSI_REWIND, 1) != SENSE_NO_SENSE) {
- 12218 printf("%s: failed to rewindn", s_name());
- 12219 } else {
- 12220 sp->tstat.mt_dsreg = DS_OK;
- 12221 sp->tstat.mt_blkno = 0;
- 12222 sp->tstat.mt_fileno = 0;
- 12223 }
- 12224 }
- 12225 return(OK);
- 12226 }
-
-
- 12229 /*===========================================================================*
- 12230 * s_do_ioctl *
- 12231 *===========================================================================*/
- 12232 PRIVATE int s_do_ioctl(dp, m_ptr)
- 12233 struct driver *dp;
- 12234 message *m_ptr;
- 12235 {
- 12236 struct scsi *sp;
- 12237
- 12238 if (s_prepare(m_ptr->DEVICE) == NIL_DEV) return(ENXIO);
- 12239 sp = s_sp;
- 12240
- 12241 /* Ioctls are device specific. */
- 12242 switch (sp->devtype) {
- 12243 case SCSI_DEVDISK:
- 12244 case SCSI_DEVWORM:
- 12245 case SCSI_DEVCDROM:
- 12246 case SCSI_DEVOPTICAL:
- 12247 if (m_ptr->REQUEST == DIOCEJECT) {
- 12248 /* Eject disk. */
- 12249 if (sp->open_ct > 1) return(EBUSY);
- 12250
- 12251 /* Send a start/stop command with code 2: stop and eject. */
- 12252 if (scsi_simple(SCSI_STRTSTP, 2) != SENSE_NO_SENSE)
- 12253 return(EIO);
- 12254 return(OK);
- 12255 }
- 12256 /* Call the common code for disks and disk like devices. */
- 12257 return(do_diocntl(dp, m_ptr));
- 12258
- 12259 default:
- 12260 return(ENOTTY);
- 12261
- 12262 case SCSI_DEVTAPE:
- 12263 break;
- 12264 }
- 12265 /* Further ioctls are for tapes. */
- 12266
- 12267 if (m_ptr->REQUEST == MTIOCTOP) {
- 12268 struct mtop op;
- 12269 phys_bytes op_phys;
- 12270 long delta;
- 12271 int key;
- 12272 byte *buf = tmp_buf;
- 12273
- 12274 /* Basic tape commands: rewind, space, write eof marks, ... */
- 12275 op_phys = numap(m_ptr->PROC_NR, (vir_bytes) m_ptr->ADDRESS, sizeof(op));
- 12276 if (op_phys == 0) return(EINVAL);
- 12277 phys_copy(op_phys, vir2phys(&op), (phys_bytes) sizeof(op));
- 12278
- 12279 switch(op.mt_op) {
- 12280 case MTREW:
- 12281 case MTOFFL:
- 12282 case MTRETEN:
- 12283 case MTFSF:
- 12284 case MTFSR:
- 12285 case MTBSF:
- 12286 case MTBSR:
- 12287 case MTEOM:
- 12288 /* Write an EOF mark before spacing. */
- 12289 if (sp->need_eof && sp->tstat.mt_dsreg != DS_ERR) {
- 12290 if (scsi_simple(SCSI_WREOF, 1) != SENSE_NO_SENSE)
- 12291 return(EIO);
- 12292 sp->tstat.mt_blkno = 0;
- 12293 sp->tstat.mt_fileno++;
- 12294 sp->need_eof = FALSE;
- 12295 }
- 12296 sp->at_eof = FALSE;
- 12297 }
- 12298
- 12299 switch(op.mt_op) {
- 12300 case MTREW:
- 12301 case MTOFFL:
- 12302 case MTRETEN:
- 12303 case MTERASE:
- 12304 /* Rewind, Offline, Retension, Erase. */
- 12305 switch(op.mt_op) {
- 12306 case MTOFFL:
- 12307 if (scsi_simple(SCSI_LOADUNLD, 0) != SENSE_NO_SENSE)
- 12308 return(EIO);
- 12309 sp->state &= ~S_READY;
- 12310 break;
- 12311 case MTRETEN:
- 12312 if (scsi_simple(SCSI_LOADUNLD, 3) != SENSE_NO_SENSE)
- 12313 return(EIO);
- 12314 break;
- 12315 case MTERASE:
- 12316 if (scsi_simple(SCSI_REWIND, 0) != SENSE_NO_SENSE)
- 12317 return(EIO);
- 12318 if (scsi_simple(SCSI_ERASE, 1) != SENSE_NO_SENSE)
- 12319 return(EIO);
- 12320 /* Rewind once more. */
- 12321 /*FALL THROUGH*/
- 12322 case MTREW:
- 12323 if (scsi_simple(SCSI_REWIND, 0) != SENSE_NO_SENSE)
- 12324 return(EIO);
- 12325 }
- 12326 sp->tstat.mt_dsreg = DS_OK;
- 12327 sp->tstat.mt_blkno = 0;
- 12328 sp->tstat.mt_fileno = 0;
- 12329 break;
- 12330 case MTFSF:
- 12331 case MTFSR:
- 12332 case MTBSF:
- 12333 case MTBSR:
- 12334 if (sp->tstat.mt_dsreg == DS_ERR) return(EIO);
- 12335 group0();
- 12336 rq->ccb.opcode = CCB_INIT;
- 12337 ccb_cmd0(rq).scsi_op = SCSI_SPACE;
- 12338 delta = op.mt_count;
- 12339 if (op.mt_op == MTBSR) delta = -delta;
- 12340 if (op.mt_op == MTBSF) delta = -delta - 1;
- 12341 h2b24(ccb_cmd0(rq).trlength, delta);
- 12342 ccb_cmd0(rq).fixed =
- 12343 op.mt_op == MTFSR || op.mt_op == MTBSR ? 0 : 1;
- 12344 if ((key = scsi_command(0L, 0)) != SENSE_NO_SENSE) {
- 12345 if (sense_key(key) != SENSE_NO_SENSE) return(EIO);
- 12346
- 12347 if (sense_eom(key)) {
- 12348 /* Banging into end of tape. */
- 12349 if (op.mt_op == MTBSF || op.mt_op == MTBSR) {
- 12350 /* Backspacing to start of tape. */
- 12351 sp->tstat.mt_dsreg = DS_EOF;
- 12352 sp->tstat.mt_blkno = 0;
- 12353 sp->tstat.mt_fileno = 0;
- 12354 } else {
- 12355 /* Not forwards please! */
- 12356 return(EIO);
- 12357 }
- 12358 }
- 12359 if (sense_eof(key)) {
- 12360 /* Reaching a filemark. */
- 12361 sp->tstat.mt_dsreg = DS_EOF;
- 12362 sp->at_eof = TRUE;
- 12363 if (op.mt_op == MTFSR) {
- 12364 /* Forwards. */
- 12365 sp->tstat.mt_blkno = 0;
- 12366 sp->tstat.mt_fileno++;
- 12367 } else {
- 12368 /* Backwards (bad idea!) */
- 12369 sp->tstat.mt_blkno = -1;
- 12370 sp->tstat.mt_fileno--;
- 12371 }
- 12372 }
- 12373 } else {
- 12374 if (op.mt_op == MTFSR || op.mt_op == MTBSR) {
- 12375 sp->tstat.mt_blkno += delta;
- 12376 } else {
- 12377 sp->tstat.mt_blkno = 0;
- 12378 sp->tstat.mt_fileno += delta;
- 12379 }
- 12380 if (op.mt_op == MTBSF) {
- 12381 /* n+1 backwards, and 1 forward. */
- 12382 group0();
- 12383 rq->ccb.opcode = CCB_INIT;
- 12384 ccb_cmd0(rq).scsi_op = SCSI_SPACE;
- 12385 h2b24(ccb_cmd0(rq).trlength, 1L);
- 12386 ccb_cmd0(rq).fixed = 1;
- 12387 if (scsi_command(0L, 0) != SENSE_NO_SENSE)
- 12388 return(EIO);
- 12389 sp->tstat.mt_fileno++;
- 12390 }
- 12391 sp->tstat.mt_dsreg = DS_OK;
- 12392 }
- 12393 break;
- 12394 case MTWEOF:
- 12395 /* Write EOF marks. */
- 12396 if (sp->tstat.mt_dsreg == DS_ERR) return(EIO);
- 12397 if (op.mt_count < 0) return(EIO);
- 12398 if (op.mt_count == 0) return(OK);
- 12399 group0();
- 12400 rq->ccb.opcode = CCB_INIT;
- 12401 ccb_cmd0(rq).scsi_op = SCSI_WREOF;
- 12402 h2b24(ccb_cmd0(rq).trlength, op.mt_count);
- 12403 if (scsi_command(0L, 0) != SENSE_NO_SENSE) return(EIO);
- 12404 sp->tstat.mt_dsreg = DS_OK;
- 12405 sp->tstat.mt_blkno = 0;
- 12406 sp->tstat.mt_fileno += op.mt_count;
- 12407 sp->need_eof = FALSE;
- 12408 break;
- 12409 case MTEOM:
- 12410 /* Forward space to end of media. */
- 12411 if (sp->tstat.mt_dsreg == DS_ERR) return(EIO);
- 12412 do {
- 12413 group0();
- 12414 rq->ccb.opcode = CCB_INIT;
- 12415 ccb_cmd0(rq).scsi_op = SCSI_SPACE;
- 12416 h2b24(ccb_cmd0(rq).trlength, 0x7FFFFF);
- 12417 ccb_cmd0(rq).fixed = 1;
- 12418 key = scsi_command(0L, 0);
- 12419 sp->tstat.mt_blkno = 0;
- 12420 sp->tstat.mt_fileno += 0x7FFFFF;
- 12421 if (key != SENSE_NO_SENSE) {
- 12422 if (key != SENSE_BLANK_CHECK) return(EIO);
- 12423 sp->tstat.mt_fileno -= sp->tstat.mt_resid;
- 12424 }
- 12425 } while (key == SENSE_NO_SENSE);
- 12426 sp->tstat.mt_dsreg = DS_OK;
- 12427 break;
- 12428 case MTBLKZ:
- 12429 case MTMODE:
- 12430 /* Select tape block size or tape density. */
- 12431
- 12432 /* Rewind tape. */
- 12433 if (scsi_simple(SCSI_REWIND, 0) != SENSE_NO_SENSE)
- 12434 return(EIO);
- 12435
- 12436 sp->tstat.mt_dsreg = DS_OK;
- 12437 sp->tstat.mt_blkno = 0;
- 12438 sp->tstat.mt_fileno = 0;
- 12439
- 12440 if (op.mt_op == MTBLKZ && op.mt_count == 0) {
- 12441 /* Request for variable block size mode. */
- 12442 sp->tfixed = FALSE;
- 12443 sp->block_size = 1;
- 12444 } else {
- 12445 /* First a modesense to get the current values. */
- 12446 if (scsi_simple(SCSI_MDSENSE, 255) != SENSE_NO_SENSE)
- 12447 return(EIO);
- 12448
- 12449 /* Must at least have one block descriptor. */
- 12450 if (buf[3] < 8) return(EIO);
- 12451 buf[0] = 0;
- 12452 buf[1] = 0;
- 12453 /* buf[2]: buffered mode & speed */
- 12454 buf[3] = 8;
- 12455 if (op.mt_op == MTMODE) /* New density */
- 12456 buf[4 + 0] = op.mt_count;
- 12457 /* buf[4 + 1]: number of blocks */
- 12458 buf[4 + 4] = 0;
- 12459 if (op.mt_op == MTBLKZ) /* New block size */
- 12460 h2b24(buf + 4 + 5, (long) op.mt_count);
- 12461
- 12462 /* Set the new density/blocksize. */
- 12463 if (scsi_simple(SCSI_MDSELECT, 4+8) != SENSE_NO_SENSE)
- 12464 return(EIO);
- 12465 if (op.mt_op == MTBLKZ) {
- 12466 sp->tfixed = TRUE;
- 12467 sp->block_size= op.mt_count;
- 12468 }
- 12469 }
- 12470 sp->state &= ~S_READY;
- 12471 if (scsi_probe() != OK) return(EIO);
- 12472 break;
- 12473 default:
- 12474 /* Not implemented. */
- 12475 return(ENOTTY);
- 12476 }
- 12477 } else
- 12478 if (m_ptr->REQUEST == MTIOCGET) {
- 12479 /* Request tape status. */
- 12480 phys_bytes get_phys;
- 12481
- 12482 get_phys = numap(m_ptr->PROC_NR, (vir_bytes) m_ptr->ADDRESS,
- 12483 sizeof(sp->tstat));
- 12484 if (get_phys == 0) return(EINVAL);
- 12485
- 12486 if (sp->tstat.mt_dsreg == DS_OK) {
- 12487 /* Old error data is never cleared (until now). */
- 12488 sp->tstat.mt_erreg = 0;
- 12489 sp->tstat.mt_resid = 0;
- 12490 }
- 12491 phys_copy(vir2phys(&sp->tstat), get_phys,
- 12492 (phys_bytes) sizeof(sp->tstat));
- 12493 } else {
- 12494 /* Not implemented. */
- 12495 return(ENOTTY);
- 12496 }
- 12497 return(OK);
- 12498 }
-
-
- 12501 /*===========================================================================*
- 12502 * scsi_simple *
- 12503 *===========================================================================*/
- 12504 PRIVATE int scsi_simple(opcode, count)
- 12505 int opcode; /* SCSI opcode */
- 12506 int count; /* count or flag */
- 12507 {
- 12508 /* The average group 0 SCSI command with just a simple flag or count. */
- 12509
- 12510 vir_bytes len = 0; /* Sometimes a buffer is used. */
- 12511
- 12512 group0();
- 12513 rq->ccb.opcode = CCB_INIT;
- 12514 ccb_cmd0(rq).scsi_op = opcode;
- 12515
- 12516 /* Fill in the count argument at the proper place. */
- 12517 switch (opcode) {
- 12518 case SCSI_REQSENSE:
- 12519 case SCSI_INQUIRY:
- 12520 case SCSI_MDSENSE:
- 12521 case SCSI_MDSELECT:
- 12522 ccb_cmd0(rq).nblocks = count;
- 12523 len = count;
- 12524 break;
- 12525
- 12526 case SCSI_STRTSTP:
- 12527 /* SCSI_LOADUNLD: (synonym) */
- 12528 ccb_cmd0(rq).nblocks = count;
- 12529 break;
- 12530
- 12531 case SCSI_RDLIMITS:
- 12532 len = count;
- 12533 break;
- 12534
- 12535 case SCSI_WREOF:
- 12536 h2b24(ccb_cmd0(rq).trlength, (long) count);
- 12537 break;
- 12538
- 12539 case SCSI_REWIND:
- 12540 case SCSI_ERASE:
- 12541 ccb_cmd0(rq).fixed = count;
- 12542 break;
- 12543 }
- 12544 return(scsi_command(tmp_phys, len));
- 12545 }
-
-
- 12548 /*===========================================================================*
- 12549 * group0 *
- 12550 *===========================================================================*/
- 12551 PRIVATE void group0()
- 12552 {
- 12553 /* Prepare the ccb for a group 0 SCSI command. */
- 12554
- 12555 rq->ccb.cmdlen = sizeof(cdb0_t);
- 12556
- 12557 /* Clear cdb to zeros the ugly way. */
- 12558 * (u32_t *) (rq->ccb.cmd + 0) = 0;
- 12559 * (u16_t *) (rq->ccb.cmd + 4) = 0;
- 12560 }
-
-
- 12563 /*===========================================================================*
- 12564 * group1 *
- 12565 *===========================================================================*/
- 12566 PRIVATE void group1()
- 12567 {
- 12568 rq->ccb.cmdlen = sizeof(cdb1_t);
- 12569 * (u32_t *) (rq->ccb.cmd + 0) = 0;
- 12570 * (u32_t *) (rq->ccb.cmd + 4) = 0;
- 12571 * (u16_t *) (rq->ccb.cmd + 8) = 0;
- 12572 }
-
-
- 12575 /*===========================================================================*
- 12576 * scsi_command *
- 12577 *===========================================================================*/
- 12578 PRIVATE int scsi_command(data, len)
- 12579 phys_bytes data;
- 12580 vir_bytes len;
- 12581 {
- 12582 /* Execute a SCSI command and return the results. Unlike most other routines,
- 12583 * this routine returns the sense key of a SCSI command instead of OK or EIO.
- 12584 */
- 12585 struct scsi *sp = s_sp;
- 12586 int key;
- 12587 message intr_mess;
- 12588
- 12589 rq->ccb.addrcntl = ccb_scid(s_sp->targ) | ccb_lun(s_sp->lun);
- 12590
- 12591 if (rq->ccb.opcode == CCB_SCATTER) {
- 12592 /* Device read/write; add checks and use scatter/gather vector. */
- 12593 rq->ccb.addrcntl |= s_opcode == DEV_READ ? CCB_INCHECK : CCB_OUTCHECK;
- 12594 data = vir2phys(rq->dmalist);
- 12595 len = (byte *) rq->dmaptr - (byte *) rq->dmalist;
- 12596 if (aha_model == AHA1540) {
- 12597 /* A plain 1540 can't do s/g. */
- 12598 rq->ccb.opcode = CCB_INIT;
- 12599 data = b2h24(rq->dmalist[0].dataptr);
- 12600 len = b2h24(rq->dmalist[0].datalen);
- 12601 }
- 12602 }
- 12603 h2b24(rq->ccb.datalen, (u32_t) len);
- 12604 h2b24(rq->ccb.dataptr, data);
- 12605 dump_scsi_cmd();
- 12606
- 12607 mailbox[0].status = AHA_MBOXSTART;
- 12608
- 12609 out_byte(AHA_DATAREG, AHACOM_STARTSCSI); /* hey, you've got mail! */
- 12610
- 12611 /* Wait for the SCSI command to complete. */
- 12612 while (mailbox[1].status == AHA_MBOXFREE) {
- 12613 /* No mail yet, wait for an interrupt. */
- 12614 receive(HARDWARE, &intr_mess);
- 12615 }
- 12616 mailbox[1].status = AHA_MBOXFREE; /* free up inbox */
- 12617
- 12618 /* Check the results of the operation. */
- 12619 if (rq->ccb.hastat != 0) {
- 12620 /* Weird host adapter status. */
- 12621 printf("%s: host adapter error 0x%02x%sn", s_name(), rq->ccb.hastat,
- 12622 rq->ccb.hastat == HST_TIMEOUT ? " (Selection timeout)" : "");
- 12623 errordump();
- 12624 if (sp->devtype == SCSI_DEVTAPE) sp->tstat.mt_dsreg = DS_ERR;
- 12625 memset((void *) &ccb_sense(rq), 0, sizeof(sense_t));
- 12626 return(SENSE_HARDWARE);
- 12627 }
- 12628
- 12629 if (rq->ccb.tarstat != 0) {
- 12630 /* A SCSI error has occurred. */
- 12631 sense_t *sense = &ccb_sense(rq);
- 12632
- 12633 if (sense->len < 2) {
- 12634 /* No additional code and qualifier, zero them. */
- 12635 sense->add_code = sense->add_qual = 0;
- 12636 }
- 12637
- 12638 /* Check sense data, report error if interesting. */
- 12639 if (rq->ccb.tarstat == TST_CHECK) {
- 12640 if ((sense->errc & 0x7E) == 0x70) {
- 12641 /* Standard SCSI error. */
- 12642 key = sense->key;
- 12643 } else {
- 12644 /* Blame the vendor for any other nonsense. */
- 12645 key = SENSE_VENDOR;
- 12646 }
- 12647 } else {
- 12648 if (rq->ccb.tarstat == TST_LUNBUSY) {
- 12649 /* Logical unit is too busy to react... */
- 12650 key = SENSE_NOT_READY;
- 12651 } else {
- 12652 /* The adapter shoudn't do this... */
- 12653 key = SENSE_HARDWARE;
- 12654 }
- 12655 memset((void *) sense, 0, sizeof(sense_t));
- 12656 }
- 12657
- 12658 if (sense_serious(sense_key(key))) {
- 12659 /* Something bad happened. */
- 12660 printf("%s: error on command 0x%02x, ", s_name(),
- 12661 rq->ccb.cmd[0]);
- 12662 if (rq->ccb.tarstat != TST_CHECK) {
- 12663 printf("target status 0x%02xn", rq->ccb.tarstat);
- 12664 } else {
- 12665 printf("sense key 0x%02x (%s), additional 0x%02x%02xn",
- 12666 sense->key,
- 12667 str_scsi_sense[sense_key(key)],
- 12668 sense->add_code, sense->add_qual);
- 12669 }
- 12670 errordump();
- 12671 }
- 12672
- 12673 if (sp->devtype == SCSI_DEVTAPE) {
- 12674 /* Store details of tape error. */
- 12675 sp->tstat.mt_dsreg = DS_ERR;
- 12676 sp->tstat.mt_erreg = key;
- 12677 sp->tstat.mt_resid = b2h32(sense->info);
- 12678 }
- 12679
- 12680 /* Keep only the ILI, EOM and EOF bits of key 0. */
- 12681 if (sense_key(key) != SENSE_NO_SENSE) key = sense_key(key);
- 12682
- 12683 return(key);
- 12684 }
- 12685 return(SENSE_NO_SENSE);
- 12686 }
-
-
- 12689 /*===========================================================================*
- 12690 * aha_command *
- 12691 *===========================================================================*/
- 12692 PRIVATE void aha_command(outlen, outptr, inlen, inptr)
- 12693 int outlen, inlen;
- 12694 byte *outptr, *inptr;
- 12695 {
- 12696 /* Send a low level command to the host adapter. */
- 12697 int i;
- 12698
- 12699 /* Send command bytes. */
- 12700 for (i = 0; i < outlen; i++) {
- 12701 while (in_byte(AHA_STATREG) & AHA_CDF) {} /* !! timeout */
- 12702 out_byte(AHA_DATAREG, *outptr++);
- 12703 }
- 12704
- 12705 /* Receive data bytes. */
- 12706 for (i = 0; i < inlen; i++) {
- 12707 while (!(in_byte(AHA_STATREG) & AHA_DF)
- 12708 && !(in_byte(AHA_INTRREG) & AHA_HACC)) {} /* !! timeout */
- 12709 *inptr++ = in_byte(AHA_DATAREG);
- 12710 }
- 12711
- 12712 /* Wait for command completion. */
- 12713 while (!(in_byte(AHA_INTRREG) & AHA_HACC)) {} /* !! timeout */
- 12714 out_byte(AHA_CNTLREG, AHA_IRST); /* clear interrupt */
- 12715 if (aha_irq != 0) enable_irq(aha_irq);
- 12716
- 12717 /* !! should check status register here for invalid command */
- 12718 }
-
-
- 12721 /*===========================================================================*
- 12722 * aha_reset *
- 12723 *===========================================================================*/
- 12724 PRIVATE int aha_reset()
- 12725 {
- 12726 int stat;
- 12727 int irq, bus_on, bus_off, tr_speed;
- 12728 unsigned sg_max;
- 12729 long v;
- 12730 static char aha0_env[] = "AHA0", aha_fmt[] = "x:d:d:x";
- 12731 byte cmd[5], haidata[4], getcdata[3], extbios[2];
- 12732 struct milli_state ms;
- 12733
- 12734 /* Get the configuration info from the environment. */
- 12735 v = AHA_BASEREG;
- 12736 if (env_parse(aha0_env, aha_fmt, 0, &v, 0x000L, 0x3FFL) == EP_OFF) return 0;
- 12737 aha_basereg = v;
- 12738
- 12739 v = 15;
- 12740 (void) env_parse(aha0_env, aha_fmt, 1, &v, 2L, 15L);
- 12741 bus_on = v;
- 12742
- 12743 v = 1;
- 12744 (void) env_parse(aha0_env, aha_fmt, 2, &v, 1L, 64L);
- 12745 bus_off = v;
- 12746
- 12747 v = 0x00;
- 12748 (void) env_parse(aha0_env, aha_fmt, 3, &v, 0x00L, 0xFFL);
- 12749 tr_speed = v;
- 12750
- 12751 /* Reset controller, wait for self test to complete. */
- 12752 out_byte(AHA_CNTLREG, AHA_HRST);
- 12753 milli_start(&ms);
- 12754 while ((stat = in_byte(AHA_STATREG)) & AHA_STST) {
- 12755 if (milli_elapsed(&ms) >= AHA_TIMEOUT) {
- 12756 printf("aha0: AHA154x controller not respondingn");
- 12757 return(0);
- 12758 }
- 12759 }
- 12760
- 12761 /* Check for self-test failure. */
- 12762 if ((stat & (AHA_DIAGF | AHA_INIT | AHA_IDLE | AHA_CDF | AHA_DF))
- 12763 != (AHA_INIT | AHA_IDLE)) {
- 12764 printf("aha0: AHA154x controller failed self-testn");
- 12765 return(0);
- 12766 }
- 12767
- 12768 /* !! maybe a santity check here: make sure IDLE and INIT are set? */
- 12769
- 12770 /* Get information about controller type and configuration. */
- 12771 cmd[0] = AHACOM_HAINQUIRY;
- 12772 aha_command(1, cmd, 4, haidata);
- 12773
- 12774 cmd[0] = AHACOM_GETCONFIG;
- 12775 aha_command(1, cmd, 3, getcdata);
- 12776
- 12777 /* First inquiry byte tells what type of board. */
- 12778 aha_model = haidata[0];
- 12779
- 12780 /* Unlock the 1540C or 1540CF's mailbox interface. (This is to keep old
- 12781 * drivers from using the adapter if extended features are enabled.)
- 12782 */
- 12783 if (aha_model >= AHA1540C) {
- 12784 cmd[0] = AHACOM_EXTBIOS; /* get extended BIOS information */
- 12785 aha_command(1, cmd, 2, extbios);
- 12786 if (extbios[1] != 0) {
- 12787 /* Mailbox interface is locked, so unlock it. */
- 12788 cmd[0] = AHACOM_MBOX_ENABLE;
- 12789 cmd[1] = 0; /* bit 0 = 0 (enable mailbox) */
- 12790 cmd[2] = extbios[1]; /* lock code to unlock mailbox */
- 12791 aha_command(3, cmd, 0, 0);
- 12792 }
- 12793 }
- 12794
- 12795 /* The maximum scatter/gather DMA list length depends on the board model. */
- 12796 sg_max = 16;
- 12797 if (aha_model == AHA1540) sg_max = 1; /* 1540 has no s/g */
- 12798 if (aha_model >= AHA1540C) sg_max = 255; /* 1540C has plenty */
- 12799
- 12800 /* Set up the DMA channel. */
- 12801 switch (getcdata[0]) {
- 12802 case 0x80: /* channel 7 */
- 12803 out_byte(0xD6, 0xC3);
- 12804 out_byte(0xD4, 0x03);
- 12805 break;
- 12806 case 0x40: /* channel 6 */
- 12807 out_byte(0xD6, 0xC2);
- 12808 out_byte(0xD4, 0x02);
- 12809 break;
- 12810 case 0x20: /* channel 5 */
- 12811 out_byte(0xD6, 0xC1);
- 12812 out_byte(0xD4, 0x01);
- 12813 break;
- 12814 case 0x01: /* channel 0 */
- 12815 out_byte(0x0B, 0x0C);
- 12816 out_byte(0x0A, 0x00);
- 12817 break;