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