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