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