summaryrefslogtreecommitdiffstats
path: root/private/ntos/miniport/trantor/source/cardt128.c
blob: c86faea9846fb8eabda973e682cb11dc9e763b5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
//------------------------------------------------------------------------
//  CARDT128.C 
//
//  T128 Adapter Specific File
//
//  See also cardtxxx.h, cardtxxx.h may redefine some functions with #defines.
//
//  Revisions:
//      09-01-92  KJB   First.
//      01-08-93  KJB   Moved CardPort routines to port.c.
//      02-18-93  KJB   Allowed for data underrun for read & write.
//      02-25-93  KJB   Reorganized routines.
//      03-23-93  KJB   Reorged for functional library interface.
//      03-26-93  JAP   Fixed up typedef and prototype inconsistencies
//      04-05-93  KJB   Fixed definition problem for WINNT.
//                          Involving CardAddressRange...
//      04-26-93  JAP   Added AdapterInterrupts[] and CardGetIRQ().
//      05-05-93  KJB   Fixed CheckAdapter to check timeout condition
//                      So that memory won't seem like an adapter.
//      05-06-93  KJB   Merged some Microsoft code to make CheckAdapter
//                      more stringent.
//      05-12-93  JAP   Altered CardGetShortName() to return only
//                          the type of card.
//      05-14-93  KJB   Removed P3CDoIo, it did not work for scatter gather.
//
//------------------------------------------------------------------------

#include CARDTXXX_H

#ifdef WINNT
//------------------------------------------------------------------------
// The address ranges the card will use.  These are accessed by trantor.c
// to inform NTOS of the resources we are using.
//------------------------------------------------------------------------

const CardAddressRange cardAddressRange [] =
    {
        {0x00,0x2000,TRUE}, 
    };

#endif

//------------------------------------------------------------------------
// The following table specifies the ports to be checked when searching for
// an adapter.  A zero entry terminates the search.
//------------------------------------------------------------------------

#ifdef MODE_32BIT
CONST ULONG AdapterAddresses [] =
        {0XCC000, 0XC8000, 0XDC000, 0XD8000, 0};
#else
CONST ULONG AdapterAddresses [] =
        {0XCC000000, 0XC8000000, 0XDC000000, 0XD8000000, 0};
#endif


//------------------------------------------------------------------------
// The following table specifies the possible interrupts that
//  can be used by the adapter.  A zero entry terminates the search.
//------------------------------------------------------------------------

CONST USHORT AdapterInterrupts [] =
        {3, 5, 7, 10, 12, 14, 15, 0};

//-----------------------------------------------------------------------
//
//  The following routines are stub routines to provide an entry
//  point for the library.  They reference the correct routines for 
//  the appropriate card. Only these routines may be called from outside
//  the library.  See the rouines they reference for a description of
//  the rouines, if the meaning is unclear.
//
//-----------------------------------------------------------------------

//-----------------------------------------------------------------------
// the maximum transfer size
// by decreasinge this we can get better system performace since
// the data transfer occurs with interrupts disabled, this might be
// decreased for our smaller cards
//  Used only by WINNT
//-----------------------------------------------------------------------

ULONG CardMaxTransferSize (VOID)
{
    return 16*1024L;
}


// we use interrupts

BOOLEAN CardSupportsInterrupts (VOID)
{
    return TRUE;
}


// default interrupt number is 5

#define CARD_DEFAULT_INTERRUPT_LEVEL 5

UCHAR CardDefaultInterruptLevel (VOID)
{
    return 5;
}


// the following info is for initialization only
// this card is memory mapped

BOOLEAN CardAddressRangeInIoSpace (VOID)
{
    return FALSE;
}

// we use 0x2000 bytes in memory space

USHORT CardAddressRangeLength (VOID)
{
    return 0x2000;
}


// The following is used along with the constant structure in card.c
// to define the precise i/o addresses a card will use

USHORT CardNumberOfAddressRanges (VOID)
{
    return 1;
}


USHORT CardStartCommandInterrupt (PTSRB t)
{
    return ScsiStartCommandInterrupt (t);
}


USHORT CardDoCommand (PTSRB t)
{
    return ScsiDoCommand (t);
}


USHORT CardFinishCommandInterrupt (PTSRB t)
{
    return ScsiFinishCommandInterrupt (t);
}


BOOLEAN CardInterrupt (PADAPTER_INFO g)
{
    return N5380Interrupt (g);
}


//-----------------------------------------------------------------------
//
//  BOOLEAN CardCheckAdapter
//
//  This routine checks for the presense of the card.
//  Initializes a workspace for the adapter at this address.
//  Returns TRUE if adapter found.
//
//-----------------------------------------------------------------------

BOOLEAN CardCheckAdapter (PWORKSPACE w, PINIT init)
{
    PADAPTER_INFO g = (PADAPTER_INFO) w;
    UCHAR tmp0,tmp1,tmp2;
    UCHAR tmp;
    UCHAR rval;
    ULONG index;

    //
    //  Initialize workspace and takes card specific parameter information
    //  Just the BaseIoAddress for the t13b.
    //

    g->BaseIoAddress = init->BaseIoAddress;

    // save old values of control and status

    T128PortGet(g,T128_CONTROL,&tmp0);
    T128PortGet(g,T128_STATUS,&tmp1);

    // check the timeout bit of the t128

    // this should set the timeout bit

    T128PortGet(g,T128_DATA,&tmp2);
    
    if (!T128PortTest(g,T128_STATUS,SR_TIMEOUT)) {

        // this is not a t128, restore registers

        T128PortPut(g,T128_CONTROL,tmp0);
        T128PortPut(g,T128_STATUS,tmp1);

        return FALSE;
    }

    // clear timeout condition

    T128PortPut(g,T128_CONTROL,CR_TIMEOUT);
    T128PortPut(g,T128_CONTROL,0);

    //
    // The t128 has a 32 byte stride on the access to the 5380 registers.
    // Taking advantage of this stride a check is first made that each of
    // the location in the stride have the same value.  After this is
    // complete, the same destructive scan is made for the data value as
    // for other 5380 based adapters.
    //
    
    N5380PortGet (g, N5380_CURRENT_DATA, &tmp);
    
    for (index = 0; index < 0x20; index++) {
        T128PortGet (g,
                     T128_5380+(N5380_CURRENT_DATA*0x20)+index,
                     &rval);
        if (rval != tmp) {
            return FALSE;
        }
    }
    
    N5380PortGet (g, N5380_INITIATOR_COMMAND, &tmp);
    
    for (index = 0; index < 0x20; index++) {
        T128PortGet (g,
                     T128_5380+(N5380_INITIATOR_COMMAND*0x20)+index,
                     &rval);
        if (rval != tmp) {
            return FALSE;
        }
    }
    
    N5380PortGet (g, N5380_CURRENT_STATUS, &tmp);
    
    for (index = 0; index < 0x20; index++) {
        T128PortGet (g,
                     T128_5380+(N5380_CURRENT_STATUS*0x20)+index,
                     &rval);
        if (rval != tmp) {
            return FALSE;
        }
    }
    
    //
    // The non-destructive portion of this has passed.
    // NOTE: May want to reset the bus or the adapter at some point
    //
    // CardResetBus(g);

    // set the phase to NULL 

    if (rval = (UCHAR) N5380SetPhase (g,PHASE_NULL)) {
        return FALSE;
    }

    //      check to see that the 5380 data register behaves as expected

    N5380PortPut (g, N5380_INITIATOR_COMMAND, IC_DATA_BUS);

    // check for 0x55 write/read in data register stride

    N5380PortPut (g, N5380_OUTPUT_DATA, 0x55);
    ScsiPortStallExecution (1);
    for (index = 0; index < 0x20; index++) {
        T128PortGet (g,
                     T128_5380+(N5380_CURRENT_DATA*0x20)+index,
                     &rval);
        if (rval != 0x55) {
            return FALSE;
        }
    }
    
    // check for 0xaa write/read in data register stride

    N5380PortPut (g, N5380_OUTPUT_DATA, 0xaa);
    ScsiPortStallExecution (1);
    for (index = 0; index < 0x20; index++) {
        T128PortGet (g,
                     T128_5380+(N5380_CURRENT_DATA*0x20)+index,
                     &rval);
        if (rval != 0xaa) {
            return FALSE;
        }
    }
    
    //
    // It is pretty clear this is a 128, but do one last check for
    // the 5380.
    //

    N5380PortPut (g, N5380_INITIATOR_COMMAND, 0);
    ScsiPortStallExecution (1);
    N5380PortGet (g, N5380_CURRENT_DATA, &tmp);

    // data now should not match ....

    if (tmp == 0xaa) { 
        return FALSE;
    }

    return TRUE;
}

//
//  CardParseCommandString(PINIT p, PCHAR str)
//
//  Parses the command string to get all card specific parameters.
//  Will fill in defaults where no parameters are supplied, or
//  if the str pointer is NULL.
//
//  Returns false if it could not parse the string given.
//
//  Can be used to parse the string piece by piece, by sending
//  the same INIT structure each time.  Send NULL as the string
//  first time to initialize the PINIT structure to the standard defaults.
//
//  BaseIoAddress will be set to NULL by default, and the program can
//  detect that it has changed during parsing and just search for the
//  card as specified by the command line argument if it has changed. If
//  it does not change, the program should cycle through all valid addresses.
//
BOOLEAN CardParseCommandString(PINIT init, PCHAR str)
{
    // for now, just fill in some defaults

    init->BaseIoAddress = NULL;

    return TRUE;
}


void CardSetInterruptLevel (PADAPTER_INFO g, UCHAR level)
{
    return;
}


PUCHAR CardGetName (VOID)
{
    return "T128 SCSI Host Adapter";
}


PUCHAR CardGetShortName (VOID) 
{
    return "T128";
}


UCHAR CardGetType (VOID) 
{
    return CARDTYPE_T120;
}


VOID CardDisableInterrupt (PADAPTER_INFO g)
{
    T128DisableInterrupt(g);
}


VOID CardEnableInterrupt (PADAPTER_INFO g)
{
    T128EnableInterrupt (g);
}


VOID CardResetBus (PADAPTER_INFO g)
{
    T128ResetBus (g);
}