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