VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / s390 / net / qeth.h
1 #ifndef __QETH_H__
2 #define __QETH_H__
3
4 #include <linux/if.h>
5 #include <linux/if_arp.h>
6
7 #include <linux/if_tr.h>
8 #include <linux/trdevice.h>
9 #include <linux/etherdevice.h>
10 #include <linux/if_vlan.h>
11
12 #include <net/ipv6.h>
13 #include <linux/in6.h>
14 #include <net/if_inet6.h>
15 #include <net/addrconf.h>
16
17
18 #include <asm/bitops.h>
19 #include <asm/debug.h>
20 #include <asm/qdio.h>
21 #include <asm/ccwdev.h>
22 #include <asm/ccwgroup.h>
23
24 #include "qeth_mpc.h"
25
26 #define VERSION_QETH_H          "$Revision: 1.113 $"
27
28 #ifdef CONFIG_QETH_IPV6
29 #define QETH_VERSION_IPV6       ":IPv6"
30 #else
31 #define QETH_VERSION_IPV6       ""
32 #endif
33 #ifdef CONFIG_QETH_VLAN
34 #define QETH_VERSION_VLAN       ":VLAN"
35 #else
36 #define QETH_VERSION_VLAN       ""
37 #endif
38
39 /**
40  * Debug Facility stuff
41  */
42 #define QETH_DBF_SETUP_NAME "qeth_setup"
43 #define QETH_DBF_SETUP_LEN 8
44 #define QETH_DBF_SETUP_INDEX 3
45 #define QETH_DBF_SETUP_NR_AREAS 1
46 #define QETH_DBF_SETUP_LEVEL 3
47
48 #define QETH_DBF_MISC_NAME "qeth_misc"
49 #define QETH_DBF_MISC_LEN 128
50 #define QETH_DBF_MISC_INDEX 1
51 #define QETH_DBF_MISC_NR_AREAS 1
52 #define QETH_DBF_MISC_LEVEL 2
53
54 #define QETH_DBF_DATA_NAME "qeth_data"
55 #define QETH_DBF_DATA_LEN 96
56 #define QETH_DBF_DATA_INDEX 3
57 #define QETH_DBF_DATA_NR_AREAS 1
58 #define QETH_DBF_DATA_LEVEL 2
59
60 #define QETH_DBF_CONTROL_NAME "qeth_control"
61 #define QETH_DBF_CONTROL_LEN 256
62 #define QETH_DBF_CONTROL_INDEX 3
63 #define QETH_DBF_CONTROL_NR_AREAS 2
64 #define QETH_DBF_CONTROL_LEVEL 2
65
66 #define QETH_DBF_TRACE_NAME "qeth_trace"
67 #define QETH_DBF_TRACE_LEN 8
68 #define QETH_DBF_TRACE_INDEX 2
69 #define QETH_DBF_TRACE_NR_AREAS 2
70 #define QETH_DBF_TRACE_LEVEL 3
71
72 #define QETH_DBF_SENSE_NAME "qeth_sense"
73 #define QETH_DBF_SENSE_LEN 64
74 #define QETH_DBF_SENSE_INDEX 1
75 #define QETH_DBF_SENSE_NR_AREAS 1
76 #define QETH_DBF_SENSE_LEVEL 2
77
78 #define QETH_DBF_QERR_NAME "qeth_qerr"
79 #define QETH_DBF_QERR_LEN 8
80 #define QETH_DBF_QERR_INDEX 1
81 #define QETH_DBF_QERR_NR_AREAS 2
82 #define QETH_DBF_QERR_LEVEL 2
83
84 #define QETH_DBF_TEXT(name,level,text) \
85         do { \
86                 debug_text_event(qeth_dbf_##name,level,text); \
87         } while (0)
88
89 #define QETH_DBF_HEX(name,level,addr,len) \
90         do { \
91                 debug_event(qeth_dbf_##name,level,(void*)(addr),len); \
92         } while (0)
93
94 extern DEFINE_PER_CPU(char[256], qeth_dbf_txt_buf);
95
96 #define QETH_DBF_TEXT_(name,level,text...)                              \
97         do {                                                            \
98                 char* dbf_txt_buf = get_cpu_var(qeth_dbf_txt_buf);      \
99                 sprintf(dbf_txt_buf, text);                             \
100                 debug_text_event(qeth_dbf_##name,level,dbf_txt_buf);    \
101                 put_cpu_var(qeth_dbf_txt_buf);                          \
102         } while (0)
103
104 #define QETH_DBF_SPRINTF(name,level,text...) \
105         do { \
106                 debug_sprintf_event(qeth_dbf_trace, level, ##text ); \
107                 debug_sprintf_event(qeth_dbf_trace, level, text ); \
108         } while (0)
109
110 /**
111  * some more debug stuff
112  */
113 #define PRINTK_HEADER   "qeth: "
114
115 #define HEXDUMP16(importance,header,ptr) \
116 PRINT_##importance(header "%02x %02x %02x %02x  %02x %02x %02x %02x  " \
117                    "%02x %02x %02x %02x  %02x %02x %02x %02x\n", \
118                    *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \
119                    *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \
120                    *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \
121                    *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \
122                    *(((char*)ptr)+12),*(((char*)ptr)+13), \
123                    *(((char*)ptr)+14),*(((char*)ptr)+15)); \
124 PRINT_##importance(header "%02x %02x %02x %02x  %02x %02x %02x %02x  " \
125                    "%02x %02x %02x %02x  %02x %02x %02x %02x\n", \
126                    *(((char*)ptr)+16),*(((char*)ptr)+17), \
127                    *(((char*)ptr)+18),*(((char*)ptr)+19), \
128                    *(((char*)ptr)+20),*(((char*)ptr)+21), \
129                    *(((char*)ptr)+22),*(((char*)ptr)+23), \
130                    *(((char*)ptr)+24),*(((char*)ptr)+25), \
131                    *(((char*)ptr)+26),*(((char*)ptr)+27), \
132                    *(((char*)ptr)+28),*(((char*)ptr)+29), \
133                    *(((char*)ptr)+30),*(((char*)ptr)+31));
134
135 static inline void
136 qeth_hex_dump(unsigned char *buf, size_t len)
137 {
138         size_t i;
139
140         for (i = 0; i < len; i++) {
141                 if (i && !(i % 16))
142                         printk("\n");
143                 printk("%02x ", *(buf + i));
144         }
145         printk("\n");
146 }
147
148 #define SENSE_COMMAND_REJECT_BYTE 0
149 #define SENSE_COMMAND_REJECT_FLAG 0x80
150 #define SENSE_RESETTING_EVENT_BYTE 1
151 #define SENSE_RESETTING_EVENT_FLAG 0x80
152
153 #define atomic_swap(a,b) xchg((int *)a.counter, b)
154
155 /*
156  * Common IO related definitions
157  */
158 extern struct device *qeth_root_dev;
159 extern struct ccw_driver qeth_ccw_driver;
160 extern struct ccwgroup_driver qeth_ccwgroup_driver;
161
162 #define CARD_RDEV(card) card->read.ccwdev
163 #define CARD_WDEV(card) card->write.ccwdev
164 #define CARD_DDEV(card) card->data.ccwdev
165 #define CARD_BUS_ID(card) card->gdev->dev.bus_id
166 #define CARD_RDEV_ID(card) card->read.ccwdev->dev.bus_id
167 #define CARD_WDEV_ID(card) card->write.ccwdev->dev.bus_id
168 #define CARD_DDEV_ID(card) card->data.ccwdev->dev.bus_id
169 #define CHANNEL_ID(channel) channel->ccwdev->dev.bus_id
170
171 #define CARD_FROM_CDEV(cdev) (struct qeth_card *) \
172                 ((struct ccwgroup_device *)cdev->dev.driver_data)\
173                 ->dev.driver_data;
174
175 /**
176  * card stuff
177  */
178 #ifdef CONFIG_QETH_PERF_STATS
179 struct qeth_perf_stats {
180         unsigned int bufs_rec;
181         unsigned int bufs_sent;
182
183         unsigned int skbs_sent_pack;
184         unsigned int bufs_sent_pack;
185
186         unsigned int sc_dp_p;
187         unsigned int sc_p_dp;
188         /* qdio_input_handler: number of times called, time spent in */
189         __u64 inbound_start_time;
190         unsigned int inbound_cnt;
191         unsigned int inbound_time;
192         /* qeth_send_packet: number of times called, time spent in */
193         __u64 outbound_start_time;
194         unsigned int outbound_cnt;
195         unsigned int outbound_time;
196         /* qdio_output_handler: number of times called, time spent in */
197         __u64 outbound_handler_start_time;
198         unsigned int outbound_handler_cnt;
199         unsigned int outbound_handler_time;
200         /* number of calls to and time spent in do_QDIO for inbound queue */
201         __u64 inbound_do_qdio_start_time;
202         unsigned int inbound_do_qdio_cnt;
203         unsigned int inbound_do_qdio_time;
204         /* number of calls to and time spent in do_QDIO for outbound queues */
205         __u64 outbound_do_qdio_start_time;
206         unsigned int outbound_do_qdio_cnt;
207         unsigned int outbound_do_qdio_time;
208 };
209 #endif /* CONFIG_QETH_PERF_STATS */
210
211 /* Routing stuff */
212 struct qeth_routing_info {
213         enum qeth_routing_types type;
214 };
215
216 /* IPA stuff */
217 struct qeth_ipa_info {
218         __u32 supported_funcs;
219         __u32 enabled_funcs;
220 };
221
222 static inline int
223 qeth_is_ipa_supported(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
224 {
225         return (ipa->supported_funcs & func);
226 }
227
228 static inline int
229 qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
230 {
231         return (ipa->supported_funcs & ipa->enabled_funcs & func);
232 }
233
234 #define qeth_adp_supported(c,f) \
235         qeth_is_ipa_supported(&c->options.adp, f)
236 #define qeth_adp_enabled(c,f) \
237         qeth_is_ipa_enabled(&c->options.adp, f)
238 #define qeth_is_supported(c,f) \
239         qeth_is_ipa_supported(&c->options.ipa4, f)
240 #define qeth_is_enabled(c,f) \
241         qeth_is_ipa_enabled(&c->options.ipa4, f)
242 #ifdef CONFIG_QETH_IPV6
243 #define qeth_is_supported6(c,f) \
244         qeth_is_ipa_supported(&c->options.ipa6, f)
245 #define qeth_is_enabled6(c,f) \
246         qeth_is_ipa_enabled(&c->options.ipa6, f)
247 #else /* CONFIG_QETH_IPV6 */
248 #define qeth_is_supported6(c,f) 0
249 #define qeth_is_enabled6(c,f) 0
250 #endif /* CONFIG_QETH_IPV6 */
251 #define qeth_is_ipafunc_supported(c,prot,f) \
252          (prot==QETH_PROT_IPV6)? qeth_is_supported6(c,f):qeth_is_supported(c,f)
253 #define qeth_is_ipafunc_enabled(c,prot,f) \
254          (prot==QETH_PROT_IPV6)? qeth_is_enabled6(c,f):qeth_is_enabled(c,f)
255
256
257 #define QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT 0x0101
258 #define QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT 0x0101
259 #define QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT 0x4108
260 #define QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT 0x5108
261
262 #define QETH_MODELLIST_ARRAY \
263         {{0x1731,0x01,0x1732,0x01,QETH_CARD_TYPE_OSAE,1, \
264         QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
265         QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
266         QETH_MAX_QUEUES,0}, \
267         {0x1731,0x05,0x1732,0x05,QETH_CARD_TYPE_IQD,0, \
268         QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
269         QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
270         QETH_MAX_QUEUES,0x103}, \
271         {0,0,0,0,0,0,0,0,0}}
272
273 #define QETH_REAL_CARD          1
274 #define QETH_VLAN_CARD          2
275 #define QETH_BUFSIZE            4096
276
277 /**
278  * some more defs
279  */
280 #define IF_NAME_LEN             16
281 #define QETH_TX_TIMEOUT         100 * HZ
282 #define QETH_HEADER_SIZE        32
283 #define MAX_PORTNO              15
284 #define QETH_FAKE_LL_LEN        ETH_HLEN
285 #define QETH_FAKE_LL_V6_ADDR_POS 24
286
287 /*IPv6 address autoconfiguration stuff*/
288 #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
289 #define UNIQUE_ID_NOT_BY_CARD           0x10000
290
291 /*****************************************************************************/
292 /* QDIO queue and buffer handling                                            */
293 /*****************************************************************************/
294 #define QETH_MAX_QUEUES 4
295 #define QETH_IN_BUF_SIZE_DEFAULT 65536
296 #define QETH_IN_BUF_COUNT_DEFAULT 16
297 #define QETH_IN_BUF_COUNT_MIN 8
298 #define QETH_IN_BUF_COUNT_MAX 128
299 #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
300 #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
301                 ((card)->qdio.in_buf_pool.buf_count / 2)
302
303 /* buffers we have to be behind before we get a PCI */
304 #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
305 /*enqueued free buffers left before we get a PCI*/
306 #define QETH_PCI_THRESHOLD_B(card) 0
307 /*not used unless the microcode gets patched*/
308 #define QETH_PCI_TIMER_VALUE(card) 3
309
310 #define QETH_MIN_INPUT_THRESHOLD 1
311 #define QETH_MAX_INPUT_THRESHOLD 500
312 #define QETH_MIN_OUTPUT_THRESHOLD 1
313 #define QETH_MAX_OUTPUT_THRESHOLD 300
314
315 /* priority queing */
316 #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
317 #define QETH_DEFAULT_QUEUE    2
318 #define QETH_NO_PRIO_QUEUEING 0
319 #define QETH_PRIO_Q_ING_PREC  1
320 #define QETH_PRIO_Q_ING_TOS   2
321 #define IP_TOS_LOWDELAY 0x10
322 #define IP_TOS_HIGHTHROUGHPUT 0x08
323 #define IP_TOS_HIGHRELIABILITY 0x04
324 #define IP_TOS_NOTIMPORTANT 0x02
325
326 /* Packing */
327 #define QETH_LOW_WATERMARK_PACK  2
328 #define QETH_HIGH_WATERMARK_PACK 5
329 #define QETH_WATERMARK_PACK_FUZZ 1
330
331 #define QETH_IP_HEADER_SIZE 40
332 /* VLAN defines */
333 #define QETH_EXT_HDR_VLAN_FRAME        0x01
334 #define QETH_EXT_HDR_TOKEN_ID          0x02
335 #define QETH_EXT_HDR_INCLUDE_VLAN_TAG  0x04
336
337 struct qeth_hdr {
338         __u8  id;
339         __u8  flags;
340         __u16 inbound_checksum;
341         __u32 token;
342         __u16 length;
343         __u8  vlan_prio;
344         __u8  ext_flags;
345         __u16 vlan_id;
346         __u16 frame_offset;
347         __u8  dest_addr[16];
348 } __attribute__ ((packed));
349
350 /* flags for qeth_hdr.flags */
351 #define QETH_HDR_PASSTHRU 0x10
352 #define QETH_HDR_IPV6     0x80
353 #define QETH_HDR_CAST_MASK 0x07
354 enum qeth_cast_flags {
355         QETH_CAST_UNICAST   = 0x06,
356         QETH_CAST_MULTICAST = 0x04,
357         QETH_CAST_BROADCAST = 0x05,
358         QETH_CAST_ANYCAST   = 0x07,
359         QETH_CAST_NOCAST    = 0x00,
360 };
361
362 /* flags for qeth_hdr.ext_flags */
363 #define QETH_HDR_EXT_VLAN_FRAME      0x01
364 #define QETH_HDR_EXT_CSUM_HDR_REQ    0x10
365 #define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
366 #define QETH_HDR_EXT_SRC_MAC_ADDR    0x08
367
368 static inline int
369 qeth_is_last_sbale(struct qdio_buffer_element *sbale)
370 {
371         return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
372 }
373
374 enum qeth_qdio_buffer_states {
375         /*
376          * inbound: read out by driver; owned by hardware in order to be filled
377          * outbound: owned by driver in order to be filled
378          */
379         QETH_QDIO_BUF_EMPTY,
380         /*
381          * inbound: filled by hardware; owned by driver in order to be read out
382          * outbound: filled by driver; owned by hardware in order to be sent
383          */
384         QETH_QDIO_BUF_PRIMED,
385 };
386
387 enum qeth_qdio_info_states {
388         QETH_QDIO_UNINITIALIZED,
389         QETH_QDIO_ALLOCATED,
390         QETH_QDIO_ESTABLISHED,
391 };
392
393 struct qeth_buffer_pool_entry {
394         struct list_head list;
395         struct list_head init_list;
396         void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
397 };
398
399 struct qeth_qdio_buffer_pool {
400         struct list_head entry_list;
401         int buf_count;
402 };
403
404 struct qeth_qdio_buffer {
405         struct qdio_buffer *buffer;
406         volatile enum qeth_qdio_buffer_states state;
407         /* the buffer pool entry currently associated to this buffer */
408         struct qeth_buffer_pool_entry *pool_entry;
409 };
410
411 struct qeth_qdio_q {
412         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
413         struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
414         /*
415          * buf_to_init means "buffer must be initialized by driver and must
416          * be made available for hardware" -> state is set to EMPTY
417          */
418         volatile int next_buf_to_init;
419 } __attribute__ ((aligned(256)));
420
421 struct qeth_qdio_out_buffer {
422         struct qdio_buffer *buffer;
423         atomic_t state;
424         volatile int next_element_to_fill;
425         struct sk_buff_head skb_list;
426 };
427
428 struct qeth_card;
429
430 enum qeth_out_q_states {
431        QETH_OUT_Q_UNLOCKED,
432        QETH_OUT_Q_LOCKED,
433        QETH_OUT_Q_LOCKED_FLUSH,
434 };
435
436 struct qeth_qdio_out_q {
437         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
438         struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
439         int queue_no;
440         struct qeth_card *card;
441         atomic_t state;
442         volatile int do_pack;
443         /*
444          * index of buffer to be filled by driver; state EMPTY or PACKING
445          */
446         volatile int next_buf_to_fill;
447         /*
448          * number of buffers that are currently filled (PRIMED)
449          * -> these buffers are hardware-owned
450          */
451         atomic_t used_buffers;
452         /* indicates whether PCI flag must be set (or if one is outstanding) */
453         atomic_t set_pci_flags_count;
454 } __attribute__ ((aligned(256)));
455
456 struct qeth_qdio_info {
457         volatile enum qeth_qdio_info_states state;
458         /* input */
459         struct qeth_qdio_q *in_q;
460         struct qeth_qdio_buffer_pool in_buf_pool;
461         struct qeth_qdio_buffer_pool init_pool;
462         int in_buf_size;
463
464         /* output */
465         int no_out_queues;
466         struct qeth_qdio_out_q **out_qs;
467
468         /* priority queueing */
469         int do_prio_queueing;
470         int default_out_queue;
471 };
472
473 enum qeth_send_errors {
474         QETH_SEND_ERROR_NONE,
475         QETH_SEND_ERROR_LINK_FAILURE,
476         QETH_SEND_ERROR_RETRY,
477         QETH_SEND_ERROR_KICK_IT,
478 };
479
480 #define QETH_ETH_MAC_V4      0x0100 /* like v4 */
481 #define QETH_ETH_MAC_V6      0x3333 /* like v6 */
482 /* tr mc mac is longer, but that will be enough to detect mc frames */
483 #define QETH_TR_MAC_NC       0xc000 /* non-canonical */
484 #define QETH_TR_MAC_C        0x0300 /* canonical */
485
486 #define DEFAULT_ADD_HHLEN 0
487 #define MAX_ADD_HHLEN 1024
488
489 /**
490  * buffer stuff for read channel
491  */
492 #define QETH_CMD_BUFFER_NO      8
493
494 /**
495  *  channel state machine
496  */
497 enum qeth_channel_states {
498         CH_STATE_UP,
499         CH_STATE_DOWN,
500         CH_STATE_ACTIVATING,
501         CH_STATE_HALTED,
502         CH_STATE_STOPPED,
503 };
504 /**
505  * card state machine
506  */
507 enum qeth_card_states {
508         CARD_STATE_DOWN,
509         CARD_STATE_HARDSETUP,
510         CARD_STATE_SOFTSETUP,
511         CARD_STATE_UP,
512         CARD_STATE_RECOVER,
513 };
514
515 /**
516  * Protocol versions
517  */
518 enum qeth_prot_versions {
519         QETH_PROT_SNA  = 0x0001,
520         QETH_PROT_IPV4 = 0x0004,
521         QETH_PROT_IPV6 = 0x0006,
522 };
523
524 enum qeth_ip_types {
525         QETH_IP_TYPE_NORMAL,
526         QETH_IP_TYPE_VIPA,
527         QETH_IP_TYPE_RXIP,
528 };
529
530 enum qeth_cmd_buffer_state {
531         BUF_STATE_FREE,
532         BUF_STATE_LOCKED,
533         BUF_STATE_PROCESSED,
534 };
535 /**
536  * IP address and multicast list
537  */
538 struct qeth_ipaddr {
539         struct list_head entry;
540         enum qeth_ip_types type;
541         enum qeth_ipa_setdelip_flags set_flags;
542         enum qeth_ipa_setdelip_flags del_flags;
543         int is_multicast;
544         volatile int users;
545         enum qeth_prot_versions proto;
546         unsigned char mac[OSA_ADDR_LEN];
547         union {
548                 struct {
549                         unsigned int addr;
550                         unsigned int mask;
551                 } a4;
552                 struct {
553                         struct in6_addr addr;
554                         unsigned int pfxlen;
555                 } a6;
556         } u;
557 };
558
559 struct qeth_ipato_entry {
560         struct list_head entry;
561         enum qeth_prot_versions proto;
562         char addr[16];
563         int mask_bits;
564 };
565
566 struct qeth_ipato {
567         int enabled;
568         int invert4;
569         int invert6;
570         struct list_head entries;
571 };
572
573 struct qeth_channel;
574
575 struct qeth_cmd_buffer {
576         enum qeth_cmd_buffer_state state;
577         struct qeth_channel *channel;
578         unsigned char *data;
579         int rc;
580         void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
581 };
582
583
584 /**
585  * definition of a qeth channel, used for read and write
586  */
587 struct qeth_channel {
588         enum qeth_channel_states state;
589         struct ccw1 ccw;
590         spinlock_t iob_lock;
591         wait_queue_head_t wait_q;
592         struct tasklet_struct irq_tasklet;
593         struct ccw_device *ccwdev;
594 /*command buffer for control data*/
595         struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
596         atomic_t irq_pending;
597         volatile int io_buf_no;
598         volatile int buf_no;
599 };
600
601 /**
602  *  OSA card related definitions
603  */
604 struct qeth_token {
605         __u32 issuer_rm_w;
606         __u32 issuer_rm_r;
607         __u32 cm_filter_w;
608         __u32 cm_filter_r;
609         __u32 cm_connection_w;
610         __u32 cm_connection_r;
611         __u32 ulp_filter_w;
612         __u32 ulp_filter_r;
613         __u32 ulp_connection_w;
614         __u32 ulp_connection_r;
615 };
616
617 struct qeth_seqno {
618         __u32 trans_hdr;
619         __u32 pdu_hdr;
620         __u32 pdu_hdr_ack;
621         __u16 ipa;
622 };
623
624 struct qeth_reply {
625         struct list_head list;
626         wait_queue_head_t wait_q;
627         int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
628         u32 seqno;
629         unsigned long offset;
630         int received;
631         int rc;
632         void *param;
633         struct qeth_card *card;
634         atomic_t refcnt;
635 };
636
637 #define QETH_BROADCAST_WITH_ECHO    1
638 #define QETH_BROADCAST_WITHOUT_ECHO 2
639
640 struct qeth_card_info {
641         char if_name[IF_NAME_LEN];
642         unsigned short unit_addr2;
643         unsigned short cula;
644         unsigned short chpid;
645         __u16 func_level;
646         char mcl_level[QETH_MCL_LENGTH + 1];
647         int guestlan;
648         int portname_required;
649         int portno;
650         char portname[9];
651         enum qeth_card_types type;
652         enum qeth_link_types link_type;
653         int is_multicast_different;
654         int initial_mtu;
655         int max_mtu;
656         int broadcast_capable;
657         int unique_id;
658         __u32 csum_mask;
659 };
660
661 struct qeth_card_options {
662         struct qeth_routing_info route4;
663         struct qeth_ipa_info ipa4;
664         struct qeth_ipa_info adp; /*Adapter parameters*/
665 #ifdef CONFIG_QETH_IPV6
666         struct qeth_routing_info route6;
667         struct qeth_ipa_info ipa6;
668 #endif /* QETH_IPV6 */
669         enum qeth_checksum_types checksum_type;
670         int broadcast_mode;
671         int macaddr_mode;
672         int fake_broadcast;
673         int add_hhlen;
674         int fake_ll;
675 };
676
677 /*
678  * thread bits for qeth_card thread masks
679  */
680 enum qeth_threads {
681         QETH_SET_IP_THREAD  = 1,
682         QETH_SET_MC_THREAD  = 2,
683         QETH_RECOVER_THREAD = 4,
684 };
685
686 struct qeth_card {
687         struct list_head list;
688         enum qeth_card_states state;
689         int lan_online;
690         spinlock_t lock;
691 /*hardware and sysfs stuff*/
692         struct ccwgroup_device *gdev;
693         struct qeth_channel read;
694         struct qeth_channel write;
695         struct qeth_channel data;
696
697         struct net_device *dev;
698         struct net_device_stats stats;
699
700         struct qeth_card_info info;
701         struct qeth_token token;
702         struct qeth_seqno seqno;
703         struct qeth_card_options options;
704
705         wait_queue_head_t wait_q;
706 #ifdef CONFIG_QETH_VLAN
707         spinlock_t vlanlock;
708         struct vlan_group *vlangrp;
709 #endif
710         struct work_struct kernel_thread_starter;
711         spinlock_t thread_mask_lock;
712         volatile unsigned long thread_start_mask;
713         volatile unsigned long thread_allowed_mask;
714         volatile unsigned long thread_running_mask;
715         spinlock_t ip_lock;
716         struct list_head ip_list;
717         struct list_head ip_tbd_list;
718         struct qeth_ipato ipato;
719         struct list_head cmd_waiter_list;
720         /* QDIO buffer handling */
721         struct qeth_qdio_info qdio;
722 #ifdef CONFIG_QETH_PERF_STATS
723         struct qeth_perf_stats perf_stats;
724 #endif /* CONFIG_QETH_PERF_STATS */
725         int use_hard_stop;
726 };
727
728 struct qeth_card_list_struct {
729         struct list_head list;
730         rwlock_t rwlock;
731 };
732
733 extern struct qeth_card_list_struct qeth_card_list;
734
735 /*notifier list */
736 struct qeth_notify_list_struct {
737         struct list_head list;
738         struct task_struct *task;
739         int signum;
740 };
741 extern spinlock_t qeth_notify_lock;
742 extern struct list_head qeth_notify_list;
743
744 /*some helper functions*/
745
746 inline static __u8
747 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
748 {
749         switch (link_type) {
750         case QETH_LINK_TYPE_HSTR:
751                 return 2;
752         default:
753                 return 1;
754         }
755 }
756
757 inline static int
758 qeth_get_hlen(__u8 link_type)
759 {
760 #ifdef CONFIG_QETH_IPV6
761         switch (link_type) {
762         case QETH_LINK_TYPE_HSTR:
763         case QETH_LINK_TYPE_LANE_TR:
764                 return sizeof(struct qeth_hdr) + TR_HLEN;
765         default:
766 #ifdef CONFIG_QETH_VLAN
767                 return sizeof(struct qeth_hdr) + VLAN_ETH_HLEN;
768 #else
769                 return sizeof(struct qeth_hdr) + ETH_HLEN;
770 #endif
771         }
772 #else  /* CONFIG_QETH_IPV6 */
773 #ifdef CONFIG_QETH_VLAN
774         return sizeof(struct qeth_hdr) + VLAN_HLEN;
775 #else
776         return sizeof(struct qeth_hdr);
777 #endif
778 #endif /* CONFIG_QETH_IPV6 */
779 }
780
781 inline static unsigned short
782 qeth_get_netdev_flags(int cardtype)
783 {
784         switch (cardtype) {
785         case QETH_CARD_TYPE_IQD:
786                 return IFF_NOARP;
787 #ifdef CONFIG_QETH_IPV6
788         default:
789                 return 0;
790 #else
791         default:
792                 return IFF_NOARP;
793 #endif
794         }
795 }
796
797 inline static int
798 qeth_get_initial_mtu_for_card(struct qeth_card * card)
799 {
800         switch (card->info.type) {
801         case QETH_CARD_TYPE_UNKNOWN:
802                 return 1500;
803         case QETH_CARD_TYPE_IQD:
804                 return card->info.max_mtu;
805         case QETH_CARD_TYPE_OSAE:
806                 switch (card->info.link_type) {
807                 case QETH_LINK_TYPE_HSTR:
808                 case QETH_LINK_TYPE_LANE_TR:
809                         return 2000;
810                 default:
811                         return 1492;
812                 }
813         default:
814                 return 1500;
815         }
816 }
817
818 inline static int
819 qeth_get_max_mtu_for_card(int cardtype)
820 {
821         switch (cardtype) {
822         case QETH_CARD_TYPE_UNKNOWN:
823                 return 61440;
824         case QETH_CARD_TYPE_OSAE:
825                 return 61440;
826         case QETH_CARD_TYPE_IQD:
827                 return 57344;
828         default:
829                 return 1500;
830         }
831 }
832
833 inline static int
834 qeth_get_mtu_out_of_mpc(int cardtype)
835 {
836         switch (cardtype) {
837         case QETH_CARD_TYPE_IQD:
838                 return 1;
839         default:
840                 return 0;
841         }
842 }
843
844 inline static int
845 qeth_get_mtu_outof_framesize(int framesize)
846 {
847         switch (framesize) {
848         case 0x4000:
849                 return 8192;
850         case 0x6000:
851                 return 16384;
852         case 0xa000:
853                 return 32768;
854         case 0xffff:
855                 return 57344;
856         default:
857                 return 0;
858         }
859 }
860
861 inline static int
862 qeth_mtu_is_valid(struct qeth_card * card, int mtu)
863 {
864         switch (card->info.type) {
865         case QETH_CARD_TYPE_OSAE:
866                 return ((mtu >= 576) && (mtu <= 61440));
867         case QETH_CARD_TYPE_IQD:
868                 return ((mtu >= 576) &&
869                         (mtu <= card->info.max_mtu + 4096 - 32));
870         case QETH_CARD_TYPE_UNKNOWN:
871         default:
872                 return 1;
873         }
874 }
875
876 inline static int
877 qeth_get_arphdr_type(int cardtype, int linktype)
878 {
879         switch (cardtype) {
880         case QETH_CARD_TYPE_OSAE:
881                 switch (linktype) {
882                 case QETH_LINK_TYPE_LANE_TR:
883                 case QETH_LINK_TYPE_HSTR:
884                         return ARPHRD_IEEE802_TR;
885                 default:
886                         return ARPHRD_ETHER;
887                 }
888         case QETH_CARD_TYPE_IQD:
889         default:
890                 return ARPHRD_ETHER;
891         }
892 }
893
894 #ifdef CONFIG_QETH_PERF_STATS
895 inline static int
896 qeth_get_micros(void)
897 {
898         return (int) (get_clock() >> 12);
899 }
900 #endif
901
902 static inline int
903 qeth_get_qdio_q_format(struct qeth_card *card)
904 {
905         switch (card->info.type) {
906         case QETH_CARD_TYPE_IQD:
907                 return 2;
908         default:
909                 return 0;
910         }
911 }
912
913 static inline void
914 qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
915 {
916         sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
917 }
918
919 static inline int
920 qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
921 {
922         const char *start, *end;
923         char abuf[4];
924         char *tmp;
925         int len;
926         int i;
927
928         start = buf;
929         for (i = 0; i < 3; i++) {
930                 if (!(end = strchr(start, '.')))
931                         return -EINVAL;
932                 len = end - start;
933                 memset(abuf, 0, 4);
934                 strncpy(abuf, start, len);
935                 addr[i] = simple_strtoul(abuf, &tmp, 10);
936                 start = end + 1;
937         }
938         memset(abuf, 0, 4);
939         strcpy(abuf, start);
940         addr[3] = simple_strtoul(abuf, &tmp, 10);
941         return 0;
942 }
943
944 static inline void
945 qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
946 {
947         sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
948                      ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
949                      addr[0], addr[1], addr[2], addr[3],
950                      addr[4], addr[5], addr[6], addr[7],
951                      addr[8], addr[9], addr[10], addr[11],
952                      addr[12], addr[13], addr[14], addr[15]);
953 }
954
955 static inline int
956 qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
957 {
958         const char *start, *end;
959         u16 *tmp_addr;
960         char abuf[5];
961         char *tmp;
962         int len;
963         int i;
964
965         tmp_addr = (u16 *)addr;
966         start = buf;
967         for (i = 0; i < 7; i++) {
968                 if (!(end = strchr(start, ':')))
969                         return -EINVAL;
970                 len = end - start;
971                 memset(abuf, 0, 5);
972                 strncpy(abuf, start, len);
973                 tmp_addr[i] = simple_strtoul(abuf, &tmp, 16);
974                 start = end + 1;
975         }
976         memset(abuf, 0, 5);
977         strcpy(abuf, start);
978         tmp_addr[7] = simple_strtoul(abuf, &tmp, 16);
979         return 0;
980 }
981
982 static inline void
983 qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
984                       char *buf)
985 {
986         if (proto == QETH_PROT_IPV4)
987                 return qeth_ipaddr4_to_string(addr, buf);
988         else if (proto == QETH_PROT_IPV6)
989                 return qeth_ipaddr6_to_string(addr, buf);
990 }
991
992 static inline int
993 qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
994                       __u8 *addr)
995 {
996         if (proto == QETH_PROT_IPV4)
997                 return qeth_string_to_ipaddr4(buf, addr);
998         else if (proto == QETH_PROT_IPV6)
999                 return qeth_string_to_ipaddr6(buf, addr);
1000         else
1001                 return -EINVAL;
1002 }
1003
1004 extern int
1005 qeth_setrouting_v4(struct qeth_card *);
1006 extern int
1007 qeth_setrouting_v6(struct qeth_card *);
1008
1009 extern int
1010 qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
1011
1012 extern void
1013 qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
1014
1015 extern int
1016 qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1017
1018 extern void
1019 qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1020
1021 extern int
1022 qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1023
1024 extern void
1025 qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1026
1027 extern int
1028 qeth_notifier_register(struct task_struct *, int );
1029
1030 extern int
1031 qeth_notifier_unregister(struct task_struct * );
1032
1033 extern void
1034 qeth_schedule_recovery(struct qeth_card *);
1035
1036 extern int
1037 qeth_realloc_buffer_pool(struct qeth_card *, int);
1038 #endif /* __QETH_H__ */