special usb hub handling, IDE disks, and retries all over the place
[linux-2.4.git] / include / asm-s390x / qdio.h
1 /*
2  * linux/include/asm/qdio.h
3  *
4  * Linux for S/390 QDIO base support, Hipersocket base support
5  * version 2
6  *
7  * Copyright 2000,2002 IBM Corporation
8  * Author(s): Utz Bacher <utz.bacher@de.ibm.com>
9  *
10  */
11 #ifndef __QDIO_H__
12 #define __QDIO_H__
13
14 #define VERSION_QDIO_H "$Revision: 1.57.4.4 $"
15
16 /* note, that most of the typedef's are from ingo. */
17
18 #include <linux/interrupt.h>
19 #include <asm/irq.h>
20
21 //#define QDIO_DBF_LIKE_HELL
22
23 #define QDIO_NAME "qdio "
24
25 #define QDIO_VERBOSE_LEVEL 9
26
27 #ifndef CONFIG_ARCH_S390X
28 #define QDIO_32_BIT
29 #endif /* CONFIG_ARCH_S390X */
30
31 #define QDIO_USE_PROCESSING_STATE
32
33 #ifdef CONFIG_QDIO_PERF_STATS
34 #define QDIO_PERFORMANCE_STATS
35 #endif /* CONFIG_QDIO_PERF_STATS */
36
37 /**** CONSTANTS, that are relied on without using these symbols *****/
38 #define QDIO_MAX_QUEUES_PER_IRQ 32 /* used in width of unsigned int */
39 /************************ END of CONSTANTS **************************/
40 #define QDIO_MAX_BUFFERS_PER_Q 128 /* must be a power of 2 (%x=&(x-1)*/
41 #define QDIO_BUF_ORDER 7 /* 2**this == number of pages used for sbals in 1 q */
42 #define QDIO_MAX_ELEMENTS_PER_BUFFER 16
43 #define SBAL_SIZE 256
44
45 /* unfortunately this can't be (QDIO_MAX_BUFFERS_PER_Q*4/3) or so -- as
46  * we never know, whether we'll get initiative again, e.g. to give the
47  * transmit skb's back to the stack, however the stack may be waiting for
48  * them... therefore we define 4 as threshold to start polling (which
49  * will stop as soon as the asynchronous queue catches up)
50  * btw, this only applies to the asynchronous HiperSockets queue */
51 #define IQDIO_FILL_LEVEL_TO_POLL 4
52
53 #define TIQDIO_THININT_ISC 3
54 #define TIQDIO_DELAY_TARGET 0
55 #define QDIO_BUSY_BIT_PATIENCE 100 /* in microsecs */
56 #define QDIO_BUSY_BIT_GIVE_UP 10000000 /* 10 seconds */
57 #define IQDIO_GLOBAL_LAPS 2 /* GLOBAL_LAPS are not used as we */
58 #define IQDIO_GLOBAL_LAPS_INT 1 /* dont global summary */
59 #define IQDIO_LOCAL_LAPS 4
60 #define IQDIO_LOCAL_LAPS_INT 1
61 #define IQDIO_GLOBAL_SUMMARY_CC_MASK 2
62 /*#define IQDIO_IQDC_INT_PARM 0x1234*/
63
64 #define QDIO_Q_LAPS 5
65
66 #define QDIO_STORAGE_ACC_KEY 0
67
68 #define L2_CACHELINE_SIZE 256
69 #define INDICATORS_PER_CACHELINE (L2_CACHELINE_SIZE/sizeof(__u32))
70
71 #define QDIO_PERF "qdio_perf"
72
73 /* must be a power of 2 */
74 /*#define QDIO_STATS_NUMBER 4
75
76 #define QDIO_STATS_CLASSES 2
77 #define QDIO_STATS_COUNT_NEEDED 2*/
78
79 #define QDIO_ACTIVATE_DELAY 5 /* according to brenton belmar and paul
80                                  gioquindo it can take up to 5ms before
81                                  queues are really active */
82
83 #define QDIO_NO_USE_COUNT_TIME 10
84 #define QDIO_NO_USE_COUNT_TIMEOUT 1000 /* wait for 1 sec on each q before
85                                           exiting without having use_count
86                                           of the queue to 0 */
87
88 #define QDIO_ESTABLISH_TIMEOUT 1000
89 #define QDIO_ACTIVATE_TIMEOUT 100
90 #define QDIO_CLEANUP_CLEAR_TIMEOUT 20000
91 #define QDIO_CLEANUP_HALT_TIMEOUT 10000
92
93 #define QDIO_BH AURORA_BH
94
95 #define QDIO_IRQ_BUCKETS 256 /* heavy..., but does only use a few bytes, but
96                               be rather faster in cases of collisions
97                               (if there really is a collision, it is
98                               on every (traditional) interrupt and every
99                               do_QDIO, so we rather are generous */
100 #define QDIO_QETH_QFMT 0
101 #define QDIO_ZFCP_QFMT 1
102 #define QDIO_IQDIO_QFMT 2
103
104 #define QDIO_IRQ_STATE_FRESH 0 /* must be 0 -> memset has set it to 0 */
105 #define QDIO_IRQ_STATE_INACTIVE 1
106 #define QDIO_IRQ_STATE_ESTABLISHED 2
107 #define QDIO_IRQ_STATE_ACTIVE 3
108 #define QDIO_IRQ_STATE_STOPPED 4
109
110 /* used as intparm in do_IO: */
111 #define QDIO_DOING_SENSEID 0
112 #define QDIO_DOING_ESTABLISH 1
113 #define QDIO_DOING_ACTIVATE 2
114 #define QDIO_DOING_CLEANUP 3
115
116 /************************* DEBUG FACILITY STUFF *********************/
117 /* #define QDIO_DBF_LIKE_HELL */
118
119 #define QDIO_DBF_HEX(ex,name,level,addr,len) \
120         do { \
121         if (ex) \
122                 debug_exception(qdio_dbf_##name,level,(void*)(addr),len); \
123         else \
124                 debug_event(qdio_dbf_##name,level,(void*)(addr),len); \
125         } while (0)
126 #define QDIO_DBF_TEXT(ex,name,level,text) \
127         do { \
128         if (ex) \
129                 debug_text_exception(qdio_dbf_##name,level,text); \
130         else \
131                 debug_text_event(qdio_dbf_##name,level,text); \
132         } while (0)
133
134 #define QDIO_DBF_HEX0(ex,name,addr,len) QDIO_DBF_HEX(ex,name,0,addr,len)
135 #define QDIO_DBF_HEX1(ex,name,addr,len) QDIO_DBF_HEX(ex,name,1,addr,len)
136 #define QDIO_DBF_HEX2(ex,name,addr,len) QDIO_DBF_HEX(ex,name,2,addr,len)
137 #define QDIO_DBF_HEX3(ex,name,addr,len) QDIO_DBF_HEX(ex,name,3,addr,len)
138 #define QDIO_DBF_HEX4(ex,name,addr,len) QDIO_DBF_HEX(ex,name,4,addr,len)
139 #define QDIO_DBF_HEX5(ex,name,addr,len) QDIO_DBF_HEX(ex,name,5,addr,len)
140 #define QDIO_DBF_HEX6(ex,name,addr,len) QDIO_DBF_HEX(ex,name,6,addr,len)
141 #ifdef QDIO_DBF_LIKE_HELL
142 #endif /* QDIO_DBF_LIKE_HELL */
143 #if 0
144 #define QDIO_DBF_HEX0(ex,name,addr,len) do {} while (0)
145 #define QDIO_DBF_HEX1(ex,name,addr,len) do {} while (0)
146 #define QDIO_DBF_HEX2(ex,name,addr,len) do {} while (0)
147 #ifndef QDIO_DBF_LIKE_HELL
148 #define QDIO_DBF_HEX3(ex,name,addr,len) do {} while (0)
149 #define QDIO_DBF_HEX4(ex,name,addr,len) do {} while (0)
150 #define QDIO_DBF_HEX5(ex,name,addr,len) do {} while (0)
151 #define QDIO_DBF_HEX6(ex,name,addr,len) do {} while (0)
152 #endif /* QDIO_DBF_LIKE_HELL */
153 #endif /* 0 */
154
155 #define QDIO_DBF_TEXT0(ex,name,text) QDIO_DBF_TEXT(ex,name,0,text)
156 #define QDIO_DBF_TEXT1(ex,name,text) QDIO_DBF_TEXT(ex,name,1,text)
157 #define QDIO_DBF_TEXT2(ex,name,text) QDIO_DBF_TEXT(ex,name,2,text)
158 #define QDIO_DBF_TEXT3(ex,name,text) QDIO_DBF_TEXT(ex,name,3,text)
159 #define QDIO_DBF_TEXT4(ex,name,text) QDIO_DBF_TEXT(ex,name,4,text)
160 #define QDIO_DBF_TEXT5(ex,name,text) QDIO_DBF_TEXT(ex,name,5,text)
161 #define QDIO_DBF_TEXT6(ex,name,text) QDIO_DBF_TEXT(ex,name,6,text)
162 #ifdef QDIO_DBF_LIKE_HELL
163 #endif /* QDIO_DBF_LIKE_HELL */
164 #if 0
165 #define QDIO_DBF_TEXT0(ex,name,text) do {} while (0)
166 #define QDIO_DBF_TEXT1(ex,name,text) do {} while (0)
167 #define QDIO_DBF_TEXT2(ex,name,text) do {} while (0)
168 #ifndef QDIO_DBF_LIKE_HELL
169 #define QDIO_DBF_TEXT3(ex,name,text) do {} while (0)
170 #define QDIO_DBF_TEXT4(ex,name,text) do {} while (0)
171 #define QDIO_DBF_TEXT5(ex,name,text) do {} while (0)
172 #define QDIO_DBF_TEXT6(ex,name,text) do {} while (0)
173 #endif /* QDIO_DBF_LIKE_HELL */
174 #endif /* 0 */
175
176 #define QDIO_DBF_SETUP_NAME "qdio_setup"
177 #define QDIO_DBF_SETUP_LEN 8
178 #define QDIO_DBF_SETUP_INDEX 2
179 #define QDIO_DBF_SETUP_NR_AREAS 1
180 #ifdef QDIO_DBF_LIKE_HELL
181 #define QDIO_DBF_SETUP_LEVEL 6
182 #else /* QDIO_DBF_LIKE_HELL */
183 #define QDIO_DBF_SETUP_LEVEL 2
184 #endif /* QDIO_DBF_LIKE_HELL */
185
186 #define QDIO_DBF_SBAL_NAME "qdio_labs" /* sbal */
187 #define QDIO_DBF_SBAL_LEN 256
188 #define QDIO_DBF_SBAL_INDEX 2
189 #define QDIO_DBF_SBAL_NR_AREAS 2
190 #ifdef QDIO_DBF_LIKE_HELL
191 #define QDIO_DBF_SBAL_LEVEL 6
192 #else /* QDIO_DBF_LIKE_HELL */
193 #define QDIO_DBF_SBAL_LEVEL 2
194 #endif /* QDIO_DBF_LIKE_HELL */
195
196 #define QDIO_DBF_TRACE_NAME "qdio_trace"
197 #define QDIO_DBF_TRACE_LEN 8
198 #define QDIO_DBF_TRACE_NR_AREAS 2
199 #ifdef QDIO_DBF_LIKE_HELL
200 #define QDIO_DBF_TRACE_INDEX 4
201 #define QDIO_DBF_TRACE_LEVEL 4 /* -------- could be even more verbose here */
202 #else /* QDIO_DBF_LIKE_HELL */
203 #define QDIO_DBF_TRACE_INDEX 2
204 #define QDIO_DBF_TRACE_LEVEL 2
205 #endif /* QDIO_DBF_LIKE_HELL */
206
207 #define QDIO_DBF_SENSE_NAME "qdio_sense"
208 #define QDIO_DBF_SENSE_LEN 64
209 #define QDIO_DBF_SENSE_INDEX 1
210 #define QDIO_DBF_SENSE_NR_AREAS 1
211 #ifdef QDIO_DBF_LIKE_HELL
212 #define QDIO_DBF_SENSE_LEVEL 6
213 #else /* QDIO_DBF_LIKE_HELL */
214 #define QDIO_DBF_SENSE_LEVEL 2
215 #endif /* QDIO_DBF_LIKE_HELL */
216
217 #ifdef QDIO_DBF_LIKE_HELL
218 #define QDIO_TRACE_QTYPE QDIO_ZFCP_QFMT
219
220 #define QDIO_DBF_SLSB_OUT_NAME "qdio_slsb_out"
221 #define QDIO_DBF_SLSB_OUT_LEN QDIO_MAX_BUFFERS_PER_Q
222 #define QDIO_DBF_SLSB_OUT_INDEX 8
223 #define QDIO_DBF_SLSB_OUT_NR_AREAS 1
224 #define QDIO_DBF_SLSB_OUT_LEVEL 6
225
226 #define QDIO_DBF_SLSB_IN_NAME "qdio_slsb_in"
227 #define QDIO_DBF_SLSB_IN_LEN QDIO_MAX_BUFFERS_PER_Q
228 #define QDIO_DBF_SLSB_IN_INDEX 8
229 #define QDIO_DBF_SLSB_IN_NR_AREAS 1
230 #define QDIO_DBF_SLSB_IN_LEVEL 6
231 #endif /* QDIO_DBF_LIKE_HELL */
232
233 /****************** END OF DEBUG FACILITY STUFF *********************/
234
235 typedef struct qdio_buffer_element_t {
236         unsigned int flags;
237         unsigned int length;
238 #ifdef QDIO_32_BIT
239         void *reserved;
240 #endif /* QDIO_32_BIT */
241         void *addr;
242 } __attribute__ ((packed,aligned(16))) qdio_buffer_element_t;
243
244 typedef struct qdio_buffer_t {
245         volatile qdio_buffer_element_t element[16];
246 } __attribute__ ((packed,aligned(256))) qdio_buffer_t;
247
248
249 /* params are: irq, status, qdio_error, siga_error,
250    queue_number, first element processed, number of elements processed,
251    int_parm */
252 typedef void qdio_handler_t(int,unsigned int,unsigned int,unsigned int,
253                             unsigned int,int,int,unsigned long);
254
255
256 #define QDIO_STATUS_INBOUND_INT 0x01
257 #define QDIO_STATUS_OUTBOUND_INT 0x02
258 #define QDIO_STATUS_LOOK_FOR_ERROR 0x04
259 #define QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR 0x08
260 #define QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR 0x10
261 #define QDIO_STATUS_ACTIVATE_CHECK_CONDITION 0x20
262
263 #define QDIO_SIGA_ERROR_ACCESS_EXCEPTION 0x10
264 #define QDIO_SIGA_ERROR_B_BIT_SET 0x20
265
266 /* for qdio_initialize */
267 #define QDIO_INBOUND_0COPY_SBALS 0x01
268 #define QDIO_OUTBOUND_0COPY_SBALS 0x02
269 #define QDIO_USE_OUTBOUND_PCIS 0x04
270 #define QDIO_PFIX 0x08
271
272 /* for qdio_cleanup */
273 #define QDIO_FLAG_CLEANUP_USING_CLEAR 0x01
274 #define QDIO_FLAG_CLEANUP_USING_HALT 0x02
275
276 typedef struct qdio_initialize_t {
277         int irq;
278         unsigned char q_format;
279         unsigned char adapter_name[8];
280         unsigned int qib_param_field_format; /*adapter dependent*/
281         /* pointer to 128 bytes or NULL, if no param field */
282         unsigned char *qib_param_field; /* adapter dependent */
283         /* pointer to no_queues*128 words of data or NULL */
284         unsigned long *input_slib_elements;
285         unsigned long *output_slib_elements;
286         unsigned int min_input_threshold;
287         unsigned int max_input_threshold;
288         unsigned int min_output_threshold;
289         unsigned int max_output_threshold;
290         unsigned int no_input_qs;
291         unsigned int no_output_qs;
292         qdio_handler_t *input_handler;
293         qdio_handler_t *output_handler;
294         unsigned long int_parm;
295         unsigned long flags;
296         void **input_sbal_addr_array; /* addr of n*128 void ptrs */
297         void **output_sbal_addr_array; /* addr of n*128 void ptrs */
298 } qdio_initialize_t;
299 extern int qdio_initialize(qdio_initialize_t *init_data);
300
301 extern int qdio_activate(int irq,int flags);
302
303 #define QDIO_STATE_MUST_USE_OUTB_PCI    0x00000001
304 #define QDIO_STATE_INACTIVE             0x00000002 /* after qdio_cleanup */
305 #define QDIO_STATE_ESTABLISHED          0x00000004 /* after qdio_initialize */
306 #define QDIO_STATE_ACTIVE               0x00000008 /* after qdio_activate */
307 #define QDIO_STATE_STOPPED              0x00000010 /* after queues went down */
308 extern unsigned long qdio_get_status(int irq);
309
310
311 #define QDIO_FLAG_SYNC_INPUT     0x01
312 #define QDIO_FLAG_SYNC_OUTPUT    0x02
313 #define QDIO_FLAG_UNDER_INTERRUPT 0x04
314 #define QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT 0x08 /* no effect on
315                                                      adapter interrupts */
316 #define QDIO_FLAG_DONT_SIGA 0x10
317
318 extern int do_QDIO(int irq,unsigned int flags, unsigned int queue_number,
319                    unsigned int qidx,unsigned int count,
320                    qdio_buffer_t *buffers);
321
322 extern int qdio_synchronize(int irq,unsigned int flags,
323                             unsigned int queue_number);
324
325 extern int qdio_cleanup(int irq,int how);
326
327 extern unsigned char qdio_get_slsb_state(int irq,unsigned int flag,
328                                   unsigned int queue_number,
329                                   unsigned int qidx);
330
331 /*
332  * QDIO device commands returned by extended Sense-ID
333  */
334 #define DEFAULT_ESTABLISH_QS_CMD 0x1b
335 #define DEFAULT_ESTABLISH_QS_COUNT 0x1000
336 #define DEFAULT_ACTIVATE_QS_CMD 0x1f
337 #define DEFAULT_ACTIVATE_QS_COUNT 0
338 typedef struct _qdio_cmds {
339         unsigned char rcd;            /* read configuration data */
340         unsigned short count_rcd;
341         unsigned char sii;            /* set interface identifier */
342         unsigned short count_sii;
343         unsigned char rni;            /* read node identifier */
344         unsigned short count_rni;
345         unsigned char eq;             /* establish QDIO queues */
346         unsigned short count_eq;
347         unsigned char aq;             /* activate QDIO queues */
348         unsigned short count_aq;
349 } qdio_cmds_t;
350
351 /*
352  * additional CIWs returned by extended Sense-ID
353  */
354 #define CIW_TYPE_EQUEUE 0x3       /* establish QDIO queues */
355 #define CIW_TYPE_AQUEUE 0x4       /* activate QDIO queues */
356
357 typedef struct _qdesfmt0 {
358 #ifdef QDIO_32_BIT
359         unsigned long res1;             /* reserved */
360 #endif /* QDIO_32_BIT */
361         unsigned long sliba;            /* storage-list-information-block
362                                            address */
363 #ifdef QDIO_32_BIT
364         unsigned long res2;             /* reserved */
365 #endif /* QDIO_32_BIT */
366         unsigned long sla;              /* storage-list address */
367 #ifdef QDIO_32_BIT
368         unsigned long res3;             /* reserved */
369 #endif /* QDIO_32_BIT */
370         unsigned long slsba;            /* storage-list-state-block address */
371         unsigned int  res4;             /* reserved */
372         unsigned int  akey  :  4;       /* access key for DLIB */
373         unsigned int  bkey  :  4;       /* access key for SL */
374         unsigned int  ckey  :  4;       /* access key for SBALs */
375         unsigned int  dkey  :  4;       /* access key for SLSB */
376         unsigned int  res5  : 16;       /* reserved */
377 } __attribute__ ((packed)) qdesfmt0_t;
378
379 /*
380  * Queue-Description record (QDR)
381  */
382 typedef struct _qdr {
383         unsigned int  qfmt    :  8;     /* queue format */
384         unsigned int  pfmt    :  8;     /* impl. dep. parameter format */
385         unsigned int  res1    :  8;     /* reserved */
386         unsigned int  ac      :  8;     /* adapter characteristics */
387         unsigned int  res2    :  8;     /* reserved */
388         unsigned int  iqdcnt  :  8;     /* input-queue-descriptor count */
389         unsigned int  res3    :  8;     /* reserved */
390         unsigned int  oqdcnt  :  8;     /* output-queue-descriptor count */
391         unsigned int  res4    :  8;     /* reserved */
392         unsigned int  iqdsz   :  8;     /* input-queue-descriptor size */
393         unsigned int  res5    :  8;     /* reserved */
394         unsigned int  oqdsz   :  8;     /* output-queue-descriptor size */
395         unsigned int  res6[9];          /* reserved */
396 #ifdef QDIO_32_BIT
397         unsigned long res7;             /* reserved */
398 #endif /* QDIO_32_BIT */
399         unsigned long qiba;             /* queue-information-block address */
400         unsigned int  res8;             /* reserved */
401         unsigned int  qkey    :  4;     /* queue-informatio-block key */
402         unsigned int  res9    : 28;     /* reserved */
403 /*      union _qd {*/ /* why this? */
404                 qdesfmt0_t qdf0[126];
405 /*      } qd;*/
406 } __attribute__ ((packed,aligned(4096))) qdr_t;
407
408
409 /*
410  * queue information block (QIB)
411  */
412 #define QIB_AC_INBOUND_PCI_SUPPORTED 0x80
413 #define QIB_AC_OUTBOUND_PCI_SUPPORTED 0x40
414 typedef struct _qib {
415         unsigned int  qfmt    :  8;     /* queue format */
416         unsigned int  pfmt    :  8;     /* impl. dep. parameter format */
417         unsigned int  res1    :  8;     /* reserved */
418         unsigned int  ac      :  8;     /* adapter characteristics */
419         unsigned int  res2;             /* reserved */
420 #ifdef QDIO_32_BIT
421         unsigned long res3;             /* reserved */
422 #endif /* QDIO_32_BIT */
423         unsigned long isliba;           /* absolute address of 1st
424                                            input SLIB */
425 #ifdef QDIO_32_BIT
426         unsigned long res4;             /* reserved */
427 #endif /* QDIO_32_BIT */
428         unsigned long osliba;           /* absolute address of 1st
429                                            output SLIB */
430         unsigned int  res5;             /* reserved */
431         unsigned int  res6;             /* reserved */
432         unsigned char ebcnam[8];        /* adapter identifier in EBCDIC */
433         unsigned char res7[88];         /* reserved */
434         unsigned char parm[QDIO_MAX_BUFFERS_PER_Q];
435                                         /* implementation dependent
436                                            parameters */
437 } __attribute__ ((packed,aligned(256))) qib_t;
438
439
440 /*
441  * storage-list-information block element (SLIBE)
442  */
443 typedef struct _slibe {
444 #ifdef QDIO_32_BIT
445         unsigned long res;              /* reserved */
446 #endif /* QDIO_32_BIT */
447         unsigned long parms;            /* implementation dependent
448                                            parameters */
449 } slibe_t;
450
451 /*
452  * storage-list-information block (SLIB)
453  */
454 typedef struct _slib {
455 #ifdef QDIO_32_BIT
456         unsigned long res1;             /* reserved */
457 #endif /* QDIO_32_BIT */
458         unsigned long nsliba;           /* next SLIB address (if any) */
459 #ifdef QDIO_32_BIT
460         unsigned long res2;             /* reserved */
461 #endif /* QDIO_32_BIT */
462         unsigned long sla;              /* SL address */
463 #ifdef QDIO_32_BIT
464         unsigned long res3;             /* reserved */
465 #endif /* QDIO_32_BIT */
466         unsigned long slsba;            /* SLSB address */
467         unsigned char res4[1000];       /* reserved */
468         slibe_t       slibe[QDIO_MAX_BUFFERS_PER_Q];    /* SLIB elements */
469 } __attribute__ ((packed,aligned(2048))) slib_t;
470
471 typedef struct _sbal_flags {
472         unsigned char res1  : 1;   /* reserved */
473         unsigned char last  : 1;   /* last entry */
474         unsigned char cont  : 1;   /* contiguous storage */
475         unsigned char res2  : 1;   /* reserved */
476         unsigned char frag  : 2;   /* fragmentation (s.below) */
477         unsigned char res3  : 2;   /* reserved */
478 } __attribute__ ((packed)) sbal_flags_t;
479
480 #define SBAL_FLAGS_FIRST_FRAG        0x04000000UL
481 #define SBAL_FLAGS_MIDDLE_FRAG       0x08000000UL
482 #define SBAL_FLAGS_LAST_FRAG         0x0c000000UL
483 #define SBAL_FLAGS_LAST_ENTRY        0x40000000UL
484 #define SBAL_FLAGS_CONTIGUOUS        0x20000000UL
485
486 #define SBAL_FLAGS0_DATA_CONTINUATION 0x20UL
487
488 /* Awesome FCP extensions */
489 #define SBAL_FLAGS0_TYPE_STATUS       0x00UL
490 #define SBAL_FLAGS0_TYPE_WRITE        0x08UL
491 #define SBAL_FLAGS0_TYPE_READ         0x10UL
492 #define SBAL_FLAGS0_TYPE_WRITE_READ   0x18UL
493 #define SBAL_FLAGS0_MORE_SBALS        0x04UL
494 #define SBAL_FLAGS0_COMMAND           0x02UL
495 #define SBAL_FLAGS0_LAST_SBAL         0x00UL
496 #define SBAL_FLAGS0_ONLY_SBAL         SBAL_FLAGS0_COMMAND
497 #define SBAL_FLAGS0_MIDDLE_SBAL       SBAL_FLAGS0_MORE_SBALS
498 #define SBAL_FLAGS0_FIRST_SBAL        SBAL_FLAGS0_MORE_SBALS | SBAL_FLAGS0_COMMAND
499 /* Naught of interest beyond this point */
500
501 #define SBAL_FLAGS0_PCI         0x40
502 typedef struct _sbal_sbalf_0 {
503         unsigned char res1  : 1;   /* reserved */
504         unsigned char pci   : 1;   /* PCI indicator */
505         unsigned char cont  : 1;   /* data continuation */
506         unsigned char sbtype: 2;   /* storage-block type (FCP) */
507         unsigned char res2  : 3;   /* reserved */
508 } __attribute__ ((packed)) sbal_sbalf_0_t;
509
510 typedef struct _sbal_sbalf_1 {
511         unsigned char res1  : 4;   /* reserved */
512         unsigned char key   : 4;   /* storage key */
513 } __attribute__ ((packed)) sbal_sbalf_1_t;
514
515 typedef struct _sbal_sbalf_14 {
516         unsigned char res1   : 4;  /* reserved */
517         unsigned char erridx : 4;  /* error index */
518 } __attribute__ ((packed)) sbal_sbalf_14_t;
519
520 typedef struct _sbal_sbalf_15 {
521         unsigned char reason;      /* reserved */
522 } __attribute__ ((packed)) sbal_sbalf_15_t;
523
524 typedef union _sbal_sbalf {
525         sbal_sbalf_0_t  i0;
526         sbal_sbalf_1_t  i1;
527         sbal_sbalf_14_t i14;
528         sbal_sbalf_15_t i15;
529         unsigned char value;
530 } sbal_sbalf_t;
531
532 typedef struct _sbale {
533         union {
534                 sbal_flags_t  bits;       /* flags */
535                 unsigned char value;
536         } flags;
537         unsigned int  res1  : 16;   /* reserved */
538         sbal_sbalf_t  sbalf;       /* SBAL flags */
539         unsigned int  res2  : 16;  /* reserved */
540         unsigned int  count : 16;  /* data count */
541 #ifdef QDIO_32_BIT
542         unsigned long res3;        /* reserved */
543 #endif /* QDIO_32_BIT */
544         unsigned long addr;        /* absolute data address */
545 } __attribute__ ((packed,aligned(16))) sbal_element_t;
546
547 /*
548  * strorage-block access-list (SBAL)
549  */
550 typedef struct _sbal {
551         sbal_element_t element[QDIO_MAX_ELEMENTS_PER_BUFFER];
552 } __attribute__ ((packed,aligned(256))) sbal_t;
553
554 /*
555  * storage-list (SL)
556  */
557 typedef struct _sl_element {
558 #ifdef QDIO_32_BIT
559         unsigned long res;     /* reserved */
560 #endif /* QDIO_32_BIT */
561         unsigned long sbal;    /* absolute SBAL address */
562 } __attribute__ ((packed)) sl_element_t;
563
564 typedef struct _sl {
565         sl_element_t element[QDIO_MAX_BUFFERS_PER_Q];
566 } __attribute__ ((packed,aligned(1024))) sl_t;
567
568 /*
569  * storage-list-state block (SLSB)
570  */
571 /*typedef struct _slsb_val {*/
572 /*      unsigned char value;       */ /* SLSB entry as a single byte value */
573 /*} __attribute__ ((packed)) slsb_val_t;*/
574
575 typedef struct _slsb_flags {
576         unsigned char owner  : 2;   /* SBAL owner */
577         unsigned char type   : 1;   /* buffer type */
578         unsigned char state  : 5;   /* processing state */
579 } __attribute__ ((packed)) slsb_flags_t;
580
581
582 typedef struct _slsb {
583         union _acc {
584                 unsigned char val[QDIO_MAX_BUFFERS_PER_Q];
585                 slsb_flags_t flags[QDIO_MAX_BUFFERS_PER_Q];
586         } acc;
587 } __attribute__ ((packed,aligned(256))) slsb_t;
588
589 /*
590  * SLSB values
591  */
592 #define SLSB_OWNER_PROG              1
593 #define SLSB_OWNER_CU                2
594
595 #define SLSB_TYPE_INPUT              0
596 #define SLSB_TYPE_OUTPUT             1
597
598 #define SLSB_STATE_NOT_INIT          0
599 #define SLSB_STATE_EMPTY             1
600 #define SLSB_STATE_PRIMED            2
601 #define SLSB_STATE_HALTED          0xe
602 #define SLSB_STATE_ERROR           0xf
603
604 #define SLSB_P_INPUT_NOT_INIT     0x80
605 #define SLSB_P_INPUT_PROCESSING   0x81
606 #define SLSB_CU_INPUT_EMPTY       0x41
607 #define SLSB_P_INPUT_PRIMED       0x82
608 #define SLSB_P_INPUT_HALTED       0x8E
609 #define SLSB_P_INPUT_ERROR        0x8F
610
611 #define SLSB_P_OUTPUT_NOT_INIT    0xA0
612 #define SLSB_P_OUTPUT_EMPTY       0xA1
613 #define SLSB_CU_OUTPUT_PRIMED     0x62
614 #define SLSB_P_OUTPUT_HALTED      0xAE
615 #define SLSB_P_OUTPUT_ERROR       0xAF
616
617 #define SLSB_ERROR_DURING_LOOKUP  0xFF
618
619 typedef struct qdio_q_t {
620         volatile slsb_t slsb;
621
622         char unused[QDIO_MAX_BUFFERS_PER_Q];
623
624         __u32 * volatile dev_st_chg_ind;
625
626         int is_input_q;
627         int is_0copy_sbals_q;
628
629         unsigned int is_iqdio_q;
630         unsigned int is_thinint_q;
631
632         /* bit 0 means queue 0, bit 1 means queue 1, ... */
633         unsigned int mask;
634         unsigned int q_no;
635
636         qdio_handler_t (*handler);
637
638         /* points to the next buffer to be checked for having
639          * been processed by the card (outbound)
640          * or to the next buffer the program should check for (inbound) */
641         volatile int first_to_check;
642         /* and the last time it was: */
643         volatile int last_move_ftc;
644
645         atomic_t number_of_buffers_used;
646         atomic_t polling;
647
648         unsigned int siga_in;
649         unsigned int siga_out;
650         unsigned int siga_sync;
651         unsigned int siga_sync_done_on_thinints;
652         unsigned int siga_sync_done_on_outb_tis;
653         unsigned int hydra_gives_outbound_pcis;
654
655         /* used to save beginning position when calling dd_handlers */
656         int first_element_to_kick;
657
658         atomic_t use_count;
659         atomic_t is_in_shutdown;
660
661         int irq;
662         void *irq_ptr;
663
664 #ifdef QDIO_USE_TIMERS_FOR_POLLING
665         struct timer_list timer;
666         atomic_t timer_already_set;
667         spinlock_t timer_lock;
668 #else /* QDIO_USE_TIMERS_FOR_POLLING */
669         struct tasklet_struct tasklet;
670 #endif /* QDIO_USE_TIMERS_FOR_POLLING */
671
672         unsigned int state;
673
674         /* used to store the error condition during a data transfer */
675         unsigned int qdio_error;
676         unsigned int siga_error;
677         unsigned int error_status_flags;
678
679         /* list of interesting queues */
680         volatile struct qdio_q_t *list_next;
681         volatile struct qdio_q_t *list_prev;
682
683         slib_t *slib; /* a page is allocated under this pointer,
684                          sl points into this page, offset PAGE_SIZE/2
685                          (after slib) */
686         sl_t *sl;
687         volatile sbal_t *sbal[QDIO_MAX_BUFFERS_PER_Q];
688
689         qdio_buffer_t *qdio_buffers[QDIO_MAX_BUFFERS_PER_Q];
690
691         unsigned long int_parm;
692
693         /*struct {
694                 int in_bh_check_limit;
695                 int threshold;
696         } threshold_classes[QDIO_STATS_CLASSES];*/
697
698         struct {
699                 /* inbound: the time to stop polling
700                    outbound: the time to kick peer */
701                 int threshold; /* the real value */
702
703                 /* outbound: last time of do_QDIO
704                    inbound: last time of noticing incoming data */
705                 /*__u64 last_transfer_times[QDIO_STATS_NUMBER];
706                 int last_transfer_index; */
707
708                 __u64 last_transfer_time;
709                 __u64 busy_start;
710         } timing;
711         atomic_t busy_siga_counter;
712         unsigned int queue_type;
713 } __attribute__ ((aligned(256))) qdio_q_t;
714
715 typedef struct qdio_irq_t {
716         __u32 * volatile dev_st_chg_ind;
717
718         unsigned long int_parm;
719         int irq;
720
721         unsigned int is_iqdio_irq;
722         unsigned int is_thinint_irq;
723         unsigned int hydra_gives_outbound_pcis;
724         unsigned int sync_done_on_outb_pcis;
725
726         unsigned int state;
727         struct semaphore setting_up_lock;
728
729         unsigned int no_input_qs;
730         unsigned int no_output_qs;
731
732         unsigned char qdioac;
733
734         qdio_q_t *input_qs[QDIO_MAX_QUEUES_PER_IRQ];
735         qdio_q_t *output_qs[QDIO_MAX_QUEUES_PER_IRQ];
736
737         ccw1_t ccw;
738         int io_result_cstat;
739         int io_result_dstat;
740         int io_result_flags;
741         atomic_t interrupt_has_arrived;
742         atomic_t interrupt_has_been_cleaned;
743         wait_queue_head_t wait_q;
744
745         qdr_t *qdr;
746
747         qdio_cmds_t commands;
748
749         qib_t qib;
750
751         io_handler_func_t original_int_handler;
752
753         unsigned long other_flags; /* e.g. QDIO_PFIX */
754
755         struct qdio_irq_t *next;
756 } qdio_irq_t;
757
758 #define QDIO_CHSC_RESPONSE_CODE_OK 1
759 /* flags for st qdio sch data */
760 #define CHSC_FLAG_QDIO_CAPABILITY 0x80
761 #define CHSC_FLAG_VALIDITY 0x40
762
763 #define CHSC_FLAG_SIGA_INPUT_NECESSARY 0x40
764 #define CHSC_FLAG_SIGA_OUTPUT_NECESSARY 0x20
765 #define CHSC_FLAG_SIGA_SYNC_NECESSARY 0x10
766 #define CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS 0x08
767 #define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04
768
769 typedef struct qdio_chsc_area_t {
770         struct {
771                 /* word 0 */
772                 __u16 command_code1;
773                 __u16 command_code2;
774                 /* word 1 */
775                 __u16 operation_code;
776                 __u16 first_sch;
777                 /* word 2 */
778                 __u8 reserved1;
779                 __u8 image_id;
780                 __u16 last_sch;
781                 /* word 3 */
782                 __u32 reserved2;
783
784                 /* word 4 */
785                 union {
786                         struct {
787                                 /* word 4&5 */
788                                 __u64 summary_indicator_addr;
789                                 /* word 6&7 */
790                                 __u64 subchannel_indicator_addr;
791                                 /* word 8 */
792                                 int ks:4;
793                                 int kc:4;
794                                 int reserved1:21;
795                                 int isc:3;
796                                 /* word 9&10 */
797                                 __u32 reserved2[2];
798                                 /* word 11 */
799                                 __u32 subsystem_id;
800                                 /* word 12-1015 */
801                                 __u32 reserved3[1004];
802                         } __attribute__ ((packed,aligned(4))) set_chsc;
803                         struct {
804                                 /* word 4&5 */
805                                 __u32 reserved1[2];     
806                                 /* word 6 */
807                                 __u32 delay_target;
808                                 /* word 7-1015 */
809                                 __u32 reserved4[1009];
810                         } __attribute__ ((packed,aligned(4))) set_chsc_fast;
811                         struct {
812                                 /* word 0 */
813                                 __u16 length;
814                                 __u16 response_code;
815                                 /* word 1 */
816                                 __u32 reserved1;
817                                 /* words 2 to 9 for st sch qdio data */
818                                 __u8 flags;
819                                 __u8 reserved2;
820                                 __u16 sch;
821                                 __u8 qfmt;
822                                 __u8 reserved3;
823                                 __u8 qdioac;
824                                 __u8 sch_class;
825                                 __u8 reserved4;
826                                 __u8 icnt;
827                                 __u8 reserved5;
828                                 __u8 ocnt;
829                                 /* plus 5 words of reserved fields */
830                         } __attribute__ ((packed,aligned(8)))
831                         store_qdio_data_response;
832                 } operation_data_area;
833         } __attribute__ ((packed,aligned(8))) request_block;
834         struct {
835                 /* word 0 */
836                 __u16 length;
837                 __u16 response_code;
838                 /* word 1 */
839                 __u32 reserved1;
840         } __attribute__ ((packed,aligned(8))) response_block;
841 } __attribute__ ((packed,aligned(PAGE_SIZE))) qdio_chsc_area_t;
842
843
844 #define QDIO_PRINTK_HEADER QDIO_NAME ": "
845
846 #if QDIO_VERBOSE_LEVEL>8
847 #define QDIO_PRINT_STUPID(x...) printk( KERN_DEBUG QDIO_PRINTK_HEADER x)
848 #else
849 #define QDIO_PRINT_STUPID(x...)
850 #endif
851
852 #if QDIO_VERBOSE_LEVEL>7
853 #define QDIO_PRINT_ALL(x...) printk( QDIO_PRINTK_HEADER x)
854 #else
855 #define QDIO_PRINT_ALL(x...)
856 #endif
857
858 #if QDIO_VERBOSE_LEVEL>6
859 #define QDIO_PRINT_INFO(x...) printk( QDIO_PRINTK_HEADER x)
860 #else
861 #define QDIO_PRINT_INFO(x...)
862 #endif
863
864 #if QDIO_VERBOSE_LEVEL>5
865 #define QDIO_PRINT_WARN(x...) printk( QDIO_PRINTK_HEADER x)
866 #else
867 #define QDIO_PRINT_WARN(x...)
868 #endif
869
870 #if QDIO_VERBOSE_LEVEL>4
871 #define QDIO_PRINT_ERR(x...) printk( QDIO_PRINTK_HEADER x)
872 #else
873 #define QDIO_PRINT_ERR(x...)
874 #endif
875
876 #if QDIO_VERBOSE_LEVEL>3
877 #define QDIO_PRINT_CRIT(x...) printk( QDIO_PRINTK_HEADER x)
878 #else
879 #define QDIO_PRINT_CRIT(x...)
880 #endif
881
882 #if QDIO_VERBOSE_LEVEL>2
883 #define QDIO_PRINT_ALERT(x...) printk( QDIO_PRINTK_HEADER x)
884 #else
885 #define QDIO_PRINT_ALERT(x...)
886 #endif
887
888 #if QDIO_VERBOSE_LEVEL>1
889 #define QDIO_PRINT_EMERG(x...) printk( QDIO_PRINTK_HEADER x)
890 #else
891 #define QDIO_PRINT_EMERG(x...)
892 #endif
893
894 #endif /* __QDIO_H__ */