Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / drivers / s390 / net / qeth_core.h
1 /*
2  *  drivers/s390/net/qeth_core.h
3  *
4  *    Copyright IBM Corp. 2007
5  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6  *               Frank Pavlic <fpavlic@de.ibm.com>,
7  *               Thomas Spatzier <tspat@de.ibm.com>,
8  *               Frank Blaschka <frank.blaschka@de.ibm.com>
9  */
10
11 #ifndef __QETH_CORE_H__
12 #define __QETH_CORE_H__
13
14 #include <linux/if.h>
15 #include <linux/if_arp.h>
16 #include <linux/if_tr.h>
17 #include <linux/trdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/if_vlan.h>
20 #include <linux/ctype.h>
21 #include <linux/in6.h>
22 #include <linux/bitops.h>
23 #include <linux/seq_file.h>
24 #include <linux/ethtool.h>
25
26 #include <net/ipv6.h>
27 #include <net/if_inet6.h>
28 #include <net/addrconf.h>
29
30 #include <asm/debug.h>
31 #include <asm/qdio.h>
32 #include <asm/ccwdev.h>
33 #include <asm/ccwgroup.h>
34
35 #include "qeth_core_mpc.h"
36
37 /**
38  * Debug Facility stuff
39  */
40 #define QETH_DBF_SETUP_NAME "qeth_setup"
41 #define QETH_DBF_SETUP_LEN 8
42 #define QETH_DBF_SETUP_PAGES 8
43 #define QETH_DBF_SETUP_NR_AREAS 1
44 #define QETH_DBF_SETUP_LEVEL 5
45
46 #define QETH_DBF_MISC_NAME "qeth_misc"
47 #define QETH_DBF_MISC_LEN 128
48 #define QETH_DBF_MISC_PAGES 2
49 #define QETH_DBF_MISC_NR_AREAS 1
50 #define QETH_DBF_MISC_LEVEL 2
51
52 #define QETH_DBF_DATA_NAME "qeth_data"
53 #define QETH_DBF_DATA_LEN 96
54 #define QETH_DBF_DATA_PAGES 8
55 #define QETH_DBF_DATA_NR_AREAS 1
56 #define QETH_DBF_DATA_LEVEL 2
57
58 #define QETH_DBF_CONTROL_NAME "qeth_control"
59 #define QETH_DBF_CONTROL_LEN 256
60 #define QETH_DBF_CONTROL_PAGES 8
61 #define QETH_DBF_CONTROL_NR_AREAS 1
62 #define QETH_DBF_CONTROL_LEVEL 5
63
64 #define QETH_DBF_TRACE_NAME "qeth_trace"
65 #define QETH_DBF_TRACE_LEN 8
66 #define QETH_DBF_TRACE_PAGES 4
67 #define QETH_DBF_TRACE_NR_AREAS 1
68 #define QETH_DBF_TRACE_LEVEL 3
69
70 #define QETH_DBF_SENSE_NAME "qeth_sense"
71 #define QETH_DBF_SENSE_LEN 64
72 #define QETH_DBF_SENSE_PAGES 2
73 #define QETH_DBF_SENSE_NR_AREAS 1
74 #define QETH_DBF_SENSE_LEVEL 2
75
76 #define QETH_DBF_QERR_NAME "qeth_qerr"
77 #define QETH_DBF_QERR_LEN 8
78 #define QETH_DBF_QERR_PAGES 2
79 #define QETH_DBF_QERR_NR_AREAS 1
80 #define QETH_DBF_QERR_LEVEL 2
81
82 #define QETH_DBF_TEXT(name, level, text) \
83         do { \
84                 debug_text_event(qeth_dbf_##name, level, text); \
85         } while (0)
86
87 #define QETH_DBF_HEX(name, level, addr, len) \
88         do { \
89                 debug_event(qeth_dbf_##name, level, (void *)(addr), len); \
90         } while (0)
91
92 /* Allow to sort out low debug levels early to avoid wasted sprints */
93 static inline int qeth_dbf_passes(debug_info_t *dbf_grp, int level)
94 {
95         return (level <= dbf_grp->level);
96 }
97
98 /**
99  * some more debug stuff
100  */
101 #define PRINTK_HEADER   "qeth: "
102
103 #define SENSE_COMMAND_REJECT_BYTE 0
104 #define SENSE_COMMAND_REJECT_FLAG 0x80
105 #define SENSE_RESETTING_EVENT_BYTE 1
106 #define SENSE_RESETTING_EVENT_FLAG 0x80
107
108 /*
109  * Common IO related definitions
110  */
111 #define CARD_RDEV(card) card->read.ccwdev
112 #define CARD_WDEV(card) card->write.ccwdev
113 #define CARD_DDEV(card) card->data.ccwdev
114 #define CARD_BUS_ID(card) card->gdev->dev.bus_id
115 #define CARD_RDEV_ID(card) card->read.ccwdev->dev.bus_id
116 #define CARD_WDEV_ID(card) card->write.ccwdev->dev.bus_id
117 #define CARD_DDEV_ID(card) card->data.ccwdev->dev.bus_id
118 #define CHANNEL_ID(channel) channel->ccwdev->dev.bus_id
119
120 /**
121  * card stuff
122  */
123 struct qeth_perf_stats {
124         unsigned int bufs_rec;
125         unsigned int bufs_sent;
126
127         unsigned int skbs_sent_pack;
128         unsigned int bufs_sent_pack;
129
130         unsigned int sc_dp_p;
131         unsigned int sc_p_dp;
132         /* qdio_input_handler: number of times called, time spent in */
133         __u64 inbound_start_time;
134         unsigned int inbound_cnt;
135         unsigned int inbound_time;
136         /* qeth_send_packet: number of times called, time spent in */
137         __u64 outbound_start_time;
138         unsigned int outbound_cnt;
139         unsigned int outbound_time;
140         /* qdio_output_handler: number of times called, time spent in */
141         __u64 outbound_handler_start_time;
142         unsigned int outbound_handler_cnt;
143         unsigned int outbound_handler_time;
144         /* number of calls to and time spent in do_QDIO for inbound queue */
145         __u64 inbound_do_qdio_start_time;
146         unsigned int inbound_do_qdio_cnt;
147         unsigned int inbound_do_qdio_time;
148         /* number of calls to and time spent in do_QDIO for outbound queues */
149         __u64 outbound_do_qdio_start_time;
150         unsigned int outbound_do_qdio_cnt;
151         unsigned int outbound_do_qdio_time;
152         /* eddp data */
153         unsigned int large_send_bytes;
154         unsigned int large_send_cnt;
155         unsigned int sg_skbs_sent;
156         unsigned int sg_frags_sent;
157         /* initial values when measuring starts */
158         unsigned long initial_rx_packets;
159         unsigned long initial_tx_packets;
160         /* inbound scatter gather data */
161         unsigned int sg_skbs_rx;
162         unsigned int sg_frags_rx;
163         unsigned int sg_alloc_page_rx;
164 };
165
166 /* Routing stuff */
167 struct qeth_routing_info {
168         enum qeth_routing_types type;
169 };
170
171 /* IPA stuff */
172 struct qeth_ipa_info {
173         __u32 supported_funcs;
174         __u32 enabled_funcs;
175 };
176
177 static inline int qeth_is_ipa_supported(struct qeth_ipa_info *ipa,
178                 enum qeth_ipa_funcs func)
179 {
180         return (ipa->supported_funcs & func);
181 }
182
183 static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
184                 enum qeth_ipa_funcs func)
185 {
186         return (ipa->supported_funcs & ipa->enabled_funcs & func);
187 }
188
189 #define qeth_adp_supported(c, f) \
190         qeth_is_ipa_supported(&c->options.adp, f)
191 #define qeth_adp_enabled(c, f) \
192         qeth_is_ipa_enabled(&c->options.adp, f)
193 #define qeth_is_supported(c, f) \
194         qeth_is_ipa_supported(&c->options.ipa4, f)
195 #define qeth_is_enabled(c, f) \
196         qeth_is_ipa_enabled(&c->options.ipa4, f)
197 #define qeth_is_supported6(c, f) \
198         qeth_is_ipa_supported(&c->options.ipa6, f)
199 #define qeth_is_enabled6(c, f) \
200         qeth_is_ipa_enabled(&c->options.ipa6, f)
201 #define qeth_is_ipafunc_supported(c, prot, f) \
202          ((prot == QETH_PROT_IPV6) ? \
203                 qeth_is_supported6(c, f) : qeth_is_supported(c, f))
204 #define qeth_is_ipafunc_enabled(c, prot, f) \
205          ((prot == QETH_PROT_IPV6) ? \
206                 qeth_is_enabled6(c, f) : qeth_is_enabled(c, f))
207
208 #define QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT 0x0101
209 #define QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT 0x0101
210 #define QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT 0x4108
211 #define QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT 0x5108
212
213 #define QETH_MODELLIST_ARRAY \
214         {{0x1731, 0x01, 0x1732, 0x01, QETH_CARD_TYPE_OSAE, 1, \
215         QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
216         QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
217         QETH_MAX_QUEUES, 0}, \
218         {0x1731, 0x05, 0x1732, 0x05, QETH_CARD_TYPE_IQD, 0, \
219         QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
220         QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
221         QETH_MAX_QUEUES, 0x103}, \
222         {0x1731, 0x06, 0x1732, 0x06, QETH_CARD_TYPE_OSN, 0, \
223         QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
224         QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
225         QETH_MAX_QUEUES, 0}, \
226         {0, 0, 0, 0, 0, 0, 0, 0, 0} }
227
228 #define QETH_REAL_CARD          1
229 #define QETH_VLAN_CARD          2
230 #define QETH_BUFSIZE            4096
231
232 /**
233  * some more defs
234  */
235 #define QETH_TX_TIMEOUT         100 * HZ
236 #define QETH_RCD_TIMEOUT        60 * HZ
237 #define QETH_HEADER_SIZE        32
238 #define QETH_MAX_PORTNO         15
239
240 /*IPv6 address autoconfiguration stuff*/
241 #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
242 #define UNIQUE_ID_NOT_BY_CARD           0x10000
243
244 /*****************************************************************************/
245 /* QDIO queue and buffer handling                                            */
246 /*****************************************************************************/
247 #define QETH_MAX_QUEUES 4
248 #define QETH_IN_BUF_SIZE_DEFAULT 65536
249 #define QETH_IN_BUF_COUNT_DEFAULT 16
250 #define QETH_IN_BUF_COUNT_MIN 8
251 #define QETH_IN_BUF_COUNT_MAX 128
252 #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
253 #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
254                 ((card)->qdio.in_buf_pool.buf_count / 2)
255
256 /* buffers we have to be behind before we get a PCI */
257 #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
258 /*enqueued free buffers left before we get a PCI*/
259 #define QETH_PCI_THRESHOLD_B(card) 0
260 /*not used unless the microcode gets patched*/
261 #define QETH_PCI_TIMER_VALUE(card) 3
262
263 #define QETH_MIN_INPUT_THRESHOLD 1
264 #define QETH_MAX_INPUT_THRESHOLD 500
265 #define QETH_MIN_OUTPUT_THRESHOLD 1
266 #define QETH_MAX_OUTPUT_THRESHOLD 300
267
268 /* priority queing */
269 #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
270 #define QETH_DEFAULT_QUEUE    2
271 #define QETH_NO_PRIO_QUEUEING 0
272 #define QETH_PRIO_Q_ING_PREC  1
273 #define QETH_PRIO_Q_ING_TOS   2
274 #define IP_TOS_LOWDELAY 0x10
275 #define IP_TOS_HIGHTHROUGHPUT 0x08
276 #define IP_TOS_HIGHRELIABILITY 0x04
277 #define IP_TOS_NOTIMPORTANT 0x02
278
279 /* Packing */
280 #define QETH_LOW_WATERMARK_PACK  2
281 #define QETH_HIGH_WATERMARK_PACK 5
282 #define QETH_WATERMARK_PACK_FUZZ 1
283
284 #define QETH_IP_HEADER_SIZE 40
285
286 /* large receive scatter gather copy break */
287 #define QETH_RX_SG_CB (PAGE_SIZE >> 1)
288
289 struct qeth_hdr_layer3 {
290         __u8  id;
291         __u8  flags;
292         __u16 inbound_checksum; /*TSO:__u16 seqno */
293         __u32 token;            /*TSO: __u32 reserved */
294         __u16 length;
295         __u8  vlan_prio;
296         __u8  ext_flags;
297         __u16 vlan_id;
298         __u16 frame_offset;
299         __u8  dest_addr[16];
300 } __attribute__ ((packed));
301
302 struct qeth_hdr_layer2 {
303         __u8 id;
304         __u8 flags[3];
305         __u8 port_no;
306         __u8 hdr_length;
307         __u16 pkt_length;
308         __u16 seq_no;
309         __u16 vlan_id;
310         __u32 reserved;
311         __u8 reserved2[16];
312 } __attribute__ ((packed));
313
314 struct qeth_hdr_osn {
315         __u8 id;
316         __u8 reserved;
317         __u16 seq_no;
318         __u16 reserved2;
319         __u16 control_flags;
320         __u16 pdu_length;
321         __u8 reserved3[18];
322         __u32 ccid;
323 } __attribute__ ((packed));
324
325 struct qeth_hdr {
326         union {
327                 struct qeth_hdr_layer2 l2;
328                 struct qeth_hdr_layer3 l3;
329                 struct qeth_hdr_osn    osn;
330         } hdr;
331 } __attribute__ ((packed));
332
333 /*TCP Segmentation Offload header*/
334 struct qeth_hdr_ext_tso {
335         __u16 hdr_tot_len;
336         __u8  imb_hdr_no;
337         __u8  reserved;
338         __u8  hdr_type;
339         __u8  hdr_version;
340         __u16 hdr_len;
341         __u32 payload_len;
342         __u16 mss;
343         __u16 dg_hdr_len;
344         __u8  padding[16];
345 } __attribute__ ((packed));
346
347 struct qeth_hdr_tso {
348         struct qeth_hdr hdr;    /*hdr->hdr.l3.xxx*/
349         struct qeth_hdr_ext_tso ext;
350 } __attribute__ ((packed));
351
352
353 /* flags for qeth_hdr.flags */
354 #define QETH_HDR_PASSTHRU 0x10
355 #define QETH_HDR_IPV6     0x80
356 #define QETH_HDR_CAST_MASK 0x07
357 enum qeth_cast_flags {
358         QETH_CAST_UNICAST   = 0x06,
359         QETH_CAST_MULTICAST = 0x04,
360         QETH_CAST_BROADCAST = 0x05,
361         QETH_CAST_ANYCAST   = 0x07,
362         QETH_CAST_NOCAST    = 0x00,
363 };
364
365 enum qeth_layer2_frame_flags {
366         QETH_LAYER2_FLAG_MULTICAST = 0x01,
367         QETH_LAYER2_FLAG_BROADCAST = 0x02,
368         QETH_LAYER2_FLAG_UNICAST   = 0x04,
369         QETH_LAYER2_FLAG_VLAN      = 0x10,
370 };
371
372 enum qeth_header_ids {
373         QETH_HEADER_TYPE_LAYER3 = 0x01,
374         QETH_HEADER_TYPE_LAYER2 = 0x02,
375         QETH_HEADER_TYPE_TSO    = 0x03,
376         QETH_HEADER_TYPE_OSN    = 0x04,
377 };
378 /* flags for qeth_hdr.ext_flags */
379 #define QETH_HDR_EXT_VLAN_FRAME       0x01
380 #define QETH_HDR_EXT_TOKEN_ID         0x02
381 #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
382 #define QETH_HDR_EXT_SRC_MAC_ADDR     0x08
383 #define QETH_HDR_EXT_CSUM_HDR_REQ     0x10
384 #define QETH_HDR_EXT_CSUM_TRANSP_REQ  0x20
385 #define QETH_HDR_EXT_UDP_TSO          0x40 /*bit off for TCP*/
386
387 static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
388 {
389         return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
390 }
391
392 enum qeth_qdio_buffer_states {
393         /*
394          * inbound: read out by driver; owned by hardware in order to be filled
395          * outbound: owned by driver in order to be filled
396          */
397         QETH_QDIO_BUF_EMPTY,
398         /*
399          * inbound: filled by hardware; owned by driver in order to be read out
400          * outbound: filled by driver; owned by hardware in order to be sent
401          */
402         QETH_QDIO_BUF_PRIMED,
403 };
404
405 enum qeth_qdio_info_states {
406         QETH_QDIO_UNINITIALIZED,
407         QETH_QDIO_ALLOCATED,
408         QETH_QDIO_ESTABLISHED,
409         QETH_QDIO_CLEANING
410 };
411
412 struct qeth_buffer_pool_entry {
413         struct list_head list;
414         struct list_head init_list;
415         void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
416 };
417
418 struct qeth_qdio_buffer_pool {
419         struct list_head entry_list;
420         int buf_count;
421 };
422
423 struct qeth_qdio_buffer {
424         struct qdio_buffer *buffer;
425         /* the buffer pool entry currently associated to this buffer */
426         struct qeth_buffer_pool_entry *pool_entry;
427 };
428
429 struct qeth_qdio_q {
430         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
431         struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
432         int next_buf_to_init;
433 } __attribute__ ((aligned(256)));
434
435 /* possible types of qeth large_send support */
436 enum qeth_large_send_types {
437         QETH_LARGE_SEND_NO,
438         QETH_LARGE_SEND_EDDP,
439         QETH_LARGE_SEND_TSO,
440 };
441
442 struct qeth_qdio_out_buffer {
443         struct qdio_buffer *buffer;
444         atomic_t state;
445         int next_element_to_fill;
446         struct sk_buff_head skb_list;
447         struct list_head ctx_list;
448 };
449
450 struct qeth_card;
451
452 enum qeth_out_q_states {
453        QETH_OUT_Q_UNLOCKED,
454        QETH_OUT_Q_LOCKED,
455        QETH_OUT_Q_LOCKED_FLUSH,
456 };
457
458 struct qeth_qdio_out_q {
459         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
460         struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
461         int queue_no;
462         struct qeth_card *card;
463         atomic_t state;
464         int do_pack;
465         /*
466          * index of buffer to be filled by driver; state EMPTY or PACKING
467          */
468         int next_buf_to_fill;
469         /*
470          * number of buffers that are currently filled (PRIMED)
471          * -> these buffers are hardware-owned
472          */
473         atomic_t used_buffers;
474         /* indicates whether PCI flag must be set (or if one is outstanding) */
475         atomic_t set_pci_flags_count;
476 } __attribute__ ((aligned(256)));
477
478 struct qeth_qdio_info {
479         atomic_t state;
480         /* input */
481         struct qeth_qdio_q *in_q;
482         struct qeth_qdio_buffer_pool in_buf_pool;
483         struct qeth_qdio_buffer_pool init_pool;
484         int in_buf_size;
485
486         /* output */
487         int no_out_queues;
488         struct qeth_qdio_out_q **out_qs;
489
490         /* priority queueing */
491         int do_prio_queueing;
492         int default_out_queue;
493 };
494
495 enum qeth_send_errors {
496         QETH_SEND_ERROR_NONE,
497         QETH_SEND_ERROR_LINK_FAILURE,
498         QETH_SEND_ERROR_RETRY,
499         QETH_SEND_ERROR_KICK_IT,
500 };
501
502 #define QETH_ETH_MAC_V4      0x0100 /* like v4 */
503 #define QETH_ETH_MAC_V6      0x3333 /* like v6 */
504 /* tr mc mac is longer, but that will be enough to detect mc frames */
505 #define QETH_TR_MAC_NC       0xc000 /* non-canonical */
506 #define QETH_TR_MAC_C        0x0300 /* canonical */
507
508 #define DEFAULT_ADD_HHLEN 0
509 #define MAX_ADD_HHLEN 1024
510
511 /**
512  * buffer stuff for read channel
513  */
514 #define QETH_CMD_BUFFER_NO      8
515
516 /**
517  *  channel state machine
518  */
519 enum qeth_channel_states {
520         CH_STATE_UP,
521         CH_STATE_DOWN,
522         CH_STATE_ACTIVATING,
523         CH_STATE_HALTED,
524         CH_STATE_STOPPED,
525         CH_STATE_RCD,
526         CH_STATE_RCD_DONE,
527 };
528 /**
529  * card state machine
530  */
531 enum qeth_card_states {
532         CARD_STATE_DOWN,
533         CARD_STATE_HARDSETUP,
534         CARD_STATE_SOFTSETUP,
535         CARD_STATE_UP,
536         CARD_STATE_RECOVER,
537 };
538
539 /**
540  * Protocol versions
541  */
542 enum qeth_prot_versions {
543         QETH_PROT_IPV4 = 0x0004,
544         QETH_PROT_IPV6 = 0x0006,
545 };
546
547 enum qeth_ip_types {
548         QETH_IP_TYPE_NORMAL,
549         QETH_IP_TYPE_VIPA,
550         QETH_IP_TYPE_RXIP,
551         QETH_IP_TYPE_DEL_ALL_MC,
552 };
553
554 enum qeth_cmd_buffer_state {
555         BUF_STATE_FREE,
556         BUF_STATE_LOCKED,
557         BUF_STATE_PROCESSED,
558 };
559
560 struct qeth_ipato {
561         int enabled;
562         int invert4;
563         int invert6;
564         struct list_head entries;
565 };
566
567 struct qeth_channel;
568
569 struct qeth_cmd_buffer {
570         enum qeth_cmd_buffer_state state;
571         struct qeth_channel *channel;
572         unsigned char *data;
573         int rc;
574         void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
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         int io_buf_no;
591         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         __u16 ipa;
615         __u32 pkt_seqno;
616 };
617
618 struct qeth_reply {
619         struct list_head list;
620         wait_queue_head_t wait_q;
621         int (*callback)(struct qeth_card *, struct qeth_reply *,
622                 unsigned long);
623         u32 seqno;
624         unsigned long offset;
625         atomic_t received;
626         int rc;
627         void *param;
628         struct qeth_card *card;
629         atomic_t refcnt;
630 };
631
632
633 struct qeth_card_blkt {
634         int time_total;
635         int inter_packet;
636         int inter_packet_jumbo;
637 };
638
639 #define QETH_BROADCAST_WITH_ECHO    0x01
640 #define QETH_BROADCAST_WITHOUT_ECHO 0x02
641 #define QETH_LAYER2_MAC_READ        0x01
642 #define QETH_LAYER2_MAC_REGISTERED  0x02
643 struct qeth_card_info {
644         unsigned short unit_addr2;
645         unsigned short cula;
646         unsigned short chpid;
647         __u16 func_level;
648         char mcl_level[QETH_MCL_LENGTH + 1];
649         int guestlan;
650         int mac_bits;
651         int portname_required;
652         int portno;
653         char portname[9];
654         enum qeth_card_types type;
655         enum qeth_link_types link_type;
656         int is_multicast_different;
657         int initial_mtu;
658         int max_mtu;
659         int broadcast_capable;
660         int unique_id;
661         struct qeth_card_blkt blkt;
662         __u32 csum_mask;
663         enum qeth_ipa_promisc_modes promisc_mode;
664 };
665
666 struct qeth_card_options {
667         struct qeth_routing_info route4;
668         struct qeth_ipa_info ipa4;
669         struct qeth_ipa_info adp; /*Adapter parameters*/
670         struct qeth_routing_info route6;
671         struct qeth_ipa_info ipa6;
672         enum qeth_checksum_types checksum_type;
673         int broadcast_mode;
674         int macaddr_mode;
675         int fake_broadcast;
676         int add_hhlen;
677         int fake_ll;
678         int layer2;
679         enum qeth_large_send_types large_send;
680         int performance_stats;
681         int rx_sg_cb;
682 };
683
684 /*
685  * thread bits for qeth_card thread masks
686  */
687 enum qeth_threads {
688         QETH_RECOVER_THREAD = 1,
689 };
690
691 struct qeth_osn_info {
692         int (*assist_cb)(struct net_device *dev, void *data);
693         int (*data_cb)(struct sk_buff *skb);
694 };
695
696 enum qeth_discipline_id {
697         QETH_DISCIPLINE_LAYER3 = 0,
698         QETH_DISCIPLINE_LAYER2 = 1,
699 };
700
701 struct qeth_discipline {
702         qdio_handler_t *input_handler;
703         qdio_handler_t *output_handler;
704         int (*recover)(void *ptr);
705         struct ccwgroup_driver *ccwgdriver;
706 };
707
708 struct qeth_vlan_vid {
709         struct list_head list;
710         unsigned short vid;
711 };
712
713 struct qeth_mc_mac {
714         struct list_head list;
715         __u8 mc_addr[MAX_ADDR_LEN];
716         unsigned char mc_addrlen;
717 };
718
719 struct qeth_card {
720         struct list_head list;
721         enum qeth_card_states state;
722         int lan_online;
723         spinlock_t lock;
724         struct ccwgroup_device *gdev;
725         struct qeth_channel read;
726         struct qeth_channel write;
727         struct qeth_channel data;
728
729         struct net_device *dev;
730         struct net_device_stats stats;
731
732         struct qeth_card_info info;
733         struct qeth_token token;
734         struct qeth_seqno seqno;
735         struct qeth_card_options options;
736
737         wait_queue_head_t wait_q;
738         spinlock_t vlanlock;
739         spinlock_t mclock;
740         struct vlan_group *vlangrp;
741         struct list_head vid_list;
742         struct list_head mc_list;
743         struct work_struct kernel_thread_starter;
744         spinlock_t thread_mask_lock;
745         unsigned long thread_start_mask;
746         unsigned long thread_allowed_mask;
747         unsigned long thread_running_mask;
748         spinlock_t ip_lock;
749         struct list_head ip_list;
750         struct list_head *ip_tbd_list;
751         struct qeth_ipato ipato;
752         struct list_head cmd_waiter_list;
753         /* QDIO buffer handling */
754         struct qeth_qdio_info qdio;
755         struct qeth_perf_stats perf_stats;
756         int use_hard_stop;
757         struct qeth_osn_info osn_info;
758         struct qeth_discipline discipline;
759         atomic_t force_alloc_skb;
760 };
761
762 struct qeth_card_list_struct {
763         struct list_head list;
764         rwlock_t rwlock;
765 };
766
767 /*some helper functions*/
768 #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
769
770 static inline struct qeth_card *CARD_FROM_CDEV(struct ccw_device *cdev)
771 {
772         struct qeth_card *card = dev_get_drvdata(&((struct ccwgroup_device *)
773                 dev_get_drvdata(&cdev->dev))->dev);
774         return card;
775 }
776
777 static inline int qeth_get_micros(void)
778 {
779         return (int) (get_clock() >> 12);
780 }
781
782 static inline void *qeth_push_skb(struct qeth_card *card, struct sk_buff *skb,
783                 int size)
784 {
785         void *hdr;
786
787         hdr = (void *) skb_push(skb, size);
788         /*
789          * sanity check, the Linux memory allocation scheme should
790          * never present us cases like this one (the qdio header size plus
791          * the first 40 bytes of the paket cross a 4k boundary)
792          */
793         if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
794             (((unsigned long) hdr + size +
795             QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
796                 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
797                         QETH_CARD_IFNAME(card));
798                 return NULL;
799         }
800         return hdr;
801 }
802
803 static inline int qeth_get_ip_version(struct sk_buff *skb)
804 {
805         switch (skb->protocol) {
806         case ETH_P_IPV6:
807                 return 6;
808         case ETH_P_IP:
809                 return 4;
810         default:
811                 return 0;
812         }
813 }
814
815 struct qeth_eddp_context;
816 extern struct ccwgroup_driver qeth_l2_ccwgroup_driver;
817 extern struct ccwgroup_driver qeth_l3_ccwgroup_driver;
818 const char *qeth_get_cardname_short(struct qeth_card *);
819 int qeth_realloc_buffer_pool(struct qeth_card *, int);
820 int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
821 void qeth_core_free_discipline(struct qeth_card *);
822 int qeth_core_create_device_attributes(struct device *);
823 void qeth_core_remove_device_attributes(struct device *);
824 int qeth_core_create_osn_attributes(struct device *);
825 void qeth_core_remove_osn_attributes(struct device *);
826
827 /* exports for qeth discipline device drivers */
828 extern struct qeth_card_list_struct qeth_core_card_list;
829 extern debug_info_t *qeth_dbf_setup;
830 extern debug_info_t *qeth_dbf_data;
831 extern debug_info_t *qeth_dbf_misc;
832 extern debug_info_t *qeth_dbf_control;
833 extern debug_info_t *qeth_dbf_trace;
834 extern debug_info_t *qeth_dbf_sense;
835 extern debug_info_t *qeth_dbf_qerr;
836
837 void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
838 int qeth_threads_running(struct qeth_card *, unsigned long);
839 int qeth_wait_for_threads(struct qeth_card *, unsigned long);
840 int qeth_do_run_thread(struct qeth_card *, unsigned long);
841 void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
842 void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
843 int qeth_core_hardsetup_card(struct qeth_card *);
844 void qeth_print_status_message(struct qeth_card *);
845 int qeth_init_qdio_queues(struct qeth_card *);
846 int qeth_send_startlan(struct qeth_card *);
847 int qeth_send_stoplan(struct qeth_card *);
848 int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
849                   int (*reply_cb)
850                   (struct qeth_card *, struct qeth_reply *, unsigned long),
851                   void *);
852 struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *,
853                         enum qeth_ipa_cmds, enum qeth_prot_versions);
854 int qeth_query_setadapterparms(struct qeth_card *);
855 int qeth_check_qdio_errors(struct qdio_buffer *, unsigned int,
856                        unsigned int, const char *);
857 void qeth_put_buffer_pool_entry(struct qeth_card *,
858                            struct qeth_buffer_pool_entry *);
859 void qeth_queue_input_buffer(struct qeth_card *, int);
860 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
861                 struct qdio_buffer *, struct qdio_buffer_element **, int *,
862                 struct qeth_hdr **);
863 void qeth_schedule_recovery(struct qeth_card *);
864 void qeth_qdio_output_handler(struct ccw_device *, unsigned int,
865                         unsigned int, unsigned int,
866                         unsigned int, int, int,
867                         unsigned long);
868 void qeth_clear_ipacmd_list(struct qeth_card *);
869 int qeth_qdio_clear_card(struct qeth_card *, int);
870 void qeth_clear_working_pool_list(struct qeth_card *);
871 void qeth_clear_cmd_buffers(struct qeth_channel *);
872 void qeth_clear_qdio_buffers(struct qeth_card *);
873 void qeth_setadp_promisc_mode(struct qeth_card *);
874 struct net_device_stats *qeth_get_stats(struct net_device *);
875 int qeth_change_mtu(struct net_device *, int);
876 int qeth_setadpparms_change_macaddr(struct qeth_card *);
877 void qeth_tx_timeout(struct net_device *);
878 void qeth_prepare_control_data(struct qeth_card *, int,
879                                 struct qeth_cmd_buffer *);
880 void qeth_release_buffer(struct qeth_channel *, struct qeth_cmd_buffer *);
881 void qeth_prepare_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *, char);
882 struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *);
883 int qeth_mdio_read(struct net_device *, int, int);
884 int qeth_snmp_command(struct qeth_card *, char __user *);
885 int qeth_set_large_send(struct qeth_card *, enum qeth_large_send_types);
886 struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *, __u32, __u32);
887 int qeth_default_setadapterparms_cb(struct qeth_card *, struct qeth_reply *,
888                                         unsigned long);
889 int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
890         int (*reply_cb)(struct qeth_card *, struct qeth_reply*, unsigned long),
891         void *reply_param);
892 int qeth_get_cast_type(struct qeth_card *, struct sk_buff *);
893 int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int);
894 struct sk_buff *qeth_prepare_skb(struct qeth_card *, struct sk_buff *,
895                  struct qeth_hdr **);
896 int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int);
897 int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *,
898                         struct sk_buff *, struct qeth_hdr *, int,
899                         struct qeth_eddp_context *);
900 int qeth_do_send_packet(struct qeth_card *, struct qeth_qdio_out_q *,
901                     struct sk_buff *, struct qeth_hdr *,
902                     int, struct qeth_eddp_context *);
903 int qeth_core_get_stats_count(struct net_device *);
904 void qeth_core_get_ethtool_stats(struct net_device *,
905                                 struct ethtool_stats *, u64 *);
906 void qeth_core_get_strings(struct net_device *, u32, u8 *);
907 void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
908
909 /* exports for OSN */
910 int qeth_osn_assist(struct net_device *, void *, int);
911 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
912                 int (*assist_cb)(struct net_device *, void *),
913                 int (*data_cb)(struct sk_buff *));
914 void qeth_osn_deregister(struct net_device *);
915
916 #endif /* __QETH_CORE_H__ */