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