]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/s390/net/qeth.h
Merge from Linus' tree
[karo-tx-linux.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.142 $"
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_PAGES 8
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_PAGES 2
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_PAGES 8
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_PAGES 8
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_PAGES 4
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_PAGES 2
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_PAGES 2
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 /*TCP Segmentation Offload header*/
374 struct qeth_hdr_ext_tso {
375         __u16 hdr_tot_len;
376         __u8  imb_hdr_no;
377         __u8  reserved;
378         __u8  hdr_type;
379         __u8  hdr_version;
380         __u16 hdr_len;
381         __u32 payload_len;
382         __u16 mss;
383         __u16 dg_hdr_len;
384         __u8  padding[16];
385 } __attribute__ ((packed));
386
387 struct qeth_hdr_tso {
388         struct qeth_hdr hdr;    /*hdr->hdr.l3.xxx*/
389         struct qeth_hdr_ext_tso ext;
390 } __attribute__ ((packed));
391
392
393 /* flags for qeth_hdr.flags */
394 #define QETH_HDR_PASSTHRU 0x10
395 #define QETH_HDR_IPV6     0x80
396 #define QETH_HDR_CAST_MASK 0x07
397 enum qeth_cast_flags {
398         QETH_CAST_UNICAST   = 0x06,
399         QETH_CAST_MULTICAST = 0x04,
400         QETH_CAST_BROADCAST = 0x05,
401         QETH_CAST_ANYCAST   = 0x07,
402         QETH_CAST_NOCAST    = 0x00,
403 };
404
405 enum qeth_layer2_frame_flags {
406         QETH_LAYER2_FLAG_MULTICAST = 0x01,
407         QETH_LAYER2_FLAG_BROADCAST = 0x02,
408         QETH_LAYER2_FLAG_UNICAST   = 0x04,
409         QETH_LAYER2_FLAG_VLAN      = 0x10,
410 };
411
412 enum qeth_header_ids {
413         QETH_HEADER_TYPE_LAYER3 = 0x01,
414         QETH_HEADER_TYPE_LAYER2 = 0x02,
415         QETH_HEADER_TYPE_TSO    = 0x03,
416 };
417 /* flags for qeth_hdr.ext_flags */
418 #define QETH_HDR_EXT_VLAN_FRAME       0x01
419 #define QETH_HDR_EXT_TOKEN_ID         0x02
420 #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
421 #define QETH_HDR_EXT_SRC_MAC_ADDR     0x08
422 #define QETH_HDR_EXT_CSUM_HDR_REQ     0x10
423 #define QETH_HDR_EXT_CSUM_TRANSP_REQ  0x20
424 #define QETH_HDR_EXT_UDP_TSO          0x40 /*bit off for TCP*/
425
426 static inline int
427 qeth_is_last_sbale(struct qdio_buffer_element *sbale)
428 {
429         return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
430 }
431
432 enum qeth_qdio_buffer_states {
433         /*
434          * inbound: read out by driver; owned by hardware in order to be filled
435          * outbound: owned by driver in order to be filled
436          */
437         QETH_QDIO_BUF_EMPTY,
438         /*
439          * inbound: filled by hardware; owned by driver in order to be read out
440          * outbound: filled by driver; owned by hardware in order to be sent
441          */
442         QETH_QDIO_BUF_PRIMED,
443 };
444
445 enum qeth_qdio_info_states {
446         QETH_QDIO_UNINITIALIZED,
447         QETH_QDIO_ALLOCATED,
448         QETH_QDIO_ESTABLISHED,
449 };
450
451 struct qeth_buffer_pool_entry {
452         struct list_head list;
453         struct list_head init_list;
454         void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
455 };
456
457 struct qeth_qdio_buffer_pool {
458         struct list_head entry_list;
459         int buf_count;
460 };
461
462 struct qeth_qdio_buffer {
463         struct qdio_buffer *buffer;
464         volatile enum qeth_qdio_buffer_states state;
465         /* the buffer pool entry currently associated to this buffer */
466         struct qeth_buffer_pool_entry *pool_entry;
467 };
468
469 struct qeth_qdio_q {
470         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
471         struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
472         /*
473          * buf_to_init means "buffer must be initialized by driver and must
474          * be made available for hardware" -> state is set to EMPTY
475          */
476         volatile int next_buf_to_init;
477 } __attribute__ ((aligned(256)));
478
479 /* possible types of qeth large_send support */
480 enum qeth_large_send_types {
481         QETH_LARGE_SEND_NO,
482         QETH_LARGE_SEND_EDDP,
483         QETH_LARGE_SEND_TSO,
484 };
485
486 struct qeth_qdio_out_buffer {
487         struct qdio_buffer *buffer;
488         atomic_t state;
489         volatile int next_element_to_fill;
490         struct sk_buff_head skb_list;
491         struct list_head ctx_list;
492 };
493
494 struct qeth_card;
495
496 enum qeth_out_q_states {
497        QETH_OUT_Q_UNLOCKED,
498        QETH_OUT_Q_LOCKED,
499        QETH_OUT_Q_LOCKED_FLUSH,
500 };
501
502 struct qeth_qdio_out_q {
503         struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
504         struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
505         int queue_no;
506         struct qeth_card *card;
507         atomic_t state;
508         volatile int do_pack;
509         /*
510          * index of buffer to be filled by driver; state EMPTY or PACKING
511          */
512         volatile int next_buf_to_fill;
513         /*
514          * number of buffers that are currently filled (PRIMED)
515          * -> these buffers are hardware-owned
516          */
517         atomic_t used_buffers;
518         /* indicates whether PCI flag must be set (or if one is outstanding) */
519         atomic_t set_pci_flags_count;
520 } __attribute__ ((aligned(256)));
521
522 struct qeth_qdio_info {
523         volatile enum qeth_qdio_info_states state;
524         /* input */
525         struct qeth_qdio_q *in_q;
526         struct qeth_qdio_buffer_pool in_buf_pool;
527         struct qeth_qdio_buffer_pool init_pool;
528         int in_buf_size;
529
530         /* output */
531         int no_out_queues;
532         struct qeth_qdio_out_q **out_qs;
533
534         /* priority queueing */
535         int do_prio_queueing;
536         int default_out_queue;
537 };
538
539 enum qeth_send_errors {
540         QETH_SEND_ERROR_NONE,
541         QETH_SEND_ERROR_LINK_FAILURE,
542         QETH_SEND_ERROR_RETRY,
543         QETH_SEND_ERROR_KICK_IT,
544 };
545
546 #define QETH_ETH_MAC_V4      0x0100 /* like v4 */
547 #define QETH_ETH_MAC_V6      0x3333 /* like v6 */
548 /* tr mc mac is longer, but that will be enough to detect mc frames */
549 #define QETH_TR_MAC_NC       0xc000 /* non-canonical */
550 #define QETH_TR_MAC_C        0x0300 /* canonical */
551
552 #define DEFAULT_ADD_HHLEN 0
553 #define MAX_ADD_HHLEN 1024
554
555 /**
556  * buffer stuff for read channel
557  */
558 #define QETH_CMD_BUFFER_NO      8
559
560 /**
561  *  channel state machine
562  */
563 enum qeth_channel_states {
564         CH_STATE_UP,
565         CH_STATE_DOWN,
566         CH_STATE_ACTIVATING,
567         CH_STATE_HALTED,
568         CH_STATE_STOPPED,
569 };
570 /**
571  * card state machine
572  */
573 enum qeth_card_states {
574         CARD_STATE_DOWN,
575         CARD_STATE_HARDSETUP,
576         CARD_STATE_SOFTSETUP,
577         CARD_STATE_UP,
578         CARD_STATE_RECOVER,
579 };
580
581 /**
582  * Protocol versions
583  */
584 enum qeth_prot_versions {
585         QETH_PROT_SNA  = 0x0001,
586         QETH_PROT_IPV4 = 0x0004,
587         QETH_PROT_IPV6 = 0x0006,
588 };
589
590 enum qeth_ip_types {
591         QETH_IP_TYPE_NORMAL,
592         QETH_IP_TYPE_VIPA,
593         QETH_IP_TYPE_RXIP,
594         QETH_IP_TYPE_DEL_ALL_MC,
595 };
596
597 enum qeth_cmd_buffer_state {
598         BUF_STATE_FREE,
599         BUF_STATE_LOCKED,
600         BUF_STATE_PROCESSED,
601 };
602 /**
603  * IP address and multicast list
604  */
605 struct qeth_ipaddr {
606         struct list_head entry;
607         enum qeth_ip_types type;
608         enum qeth_ipa_setdelip_flags set_flags;
609         enum qeth_ipa_setdelip_flags del_flags;
610         int is_multicast;
611         volatile int users;
612         enum qeth_prot_versions proto;
613         unsigned char mac[OSA_ADDR_LEN];
614         union {
615                 struct {
616                         unsigned int addr;
617                         unsigned int mask;
618                 } a4;
619                 struct {
620                         struct in6_addr addr;
621                         unsigned int pfxlen;
622                 } a6;
623         } u;
624 };
625
626 struct qeth_ipato_entry {
627         struct list_head entry;
628         enum qeth_prot_versions proto;
629         char addr[16];
630         int mask_bits;
631 };
632
633 struct qeth_ipato {
634         int enabled;
635         int invert4;
636         int invert6;
637         struct list_head entries;
638 };
639
640 struct qeth_channel;
641
642 struct qeth_cmd_buffer {
643         enum qeth_cmd_buffer_state state;
644         struct qeth_channel *channel;
645         unsigned char *data;
646         int rc;
647         void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
648 };
649
650
651 /**
652  * definition of a qeth channel, used for read and write
653  */
654 struct qeth_channel {
655         enum qeth_channel_states state;
656         struct ccw1 ccw;
657         spinlock_t iob_lock;
658         wait_queue_head_t wait_q;
659         struct tasklet_struct irq_tasklet;
660         struct ccw_device *ccwdev;
661 /*command buffer for control data*/
662         struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
663         atomic_t irq_pending;
664         volatile int io_buf_no;
665         volatile int buf_no;
666 };
667
668 /**
669  *  OSA card related definitions
670  */
671 struct qeth_token {
672         __u32 issuer_rm_w;
673         __u32 issuer_rm_r;
674         __u32 cm_filter_w;
675         __u32 cm_filter_r;
676         __u32 cm_connection_w;
677         __u32 cm_connection_r;
678         __u32 ulp_filter_w;
679         __u32 ulp_filter_r;
680         __u32 ulp_connection_w;
681         __u32 ulp_connection_r;
682 };
683
684 struct qeth_seqno {
685         __u32 trans_hdr;
686         __u32 pdu_hdr;
687         __u32 pdu_hdr_ack;
688         __u16 ipa;
689         __u32 pkt_seqno;
690 };
691
692 struct qeth_reply {
693         struct list_head list;
694         wait_queue_head_t wait_q;
695         int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
696         u32 seqno;
697         unsigned long offset;
698         int received;
699         int rc;
700         void *param;
701         struct qeth_card *card;
702         atomic_t refcnt;
703 };
704
705 #define QETH_BROADCAST_WITH_ECHO    1
706 #define QETH_BROADCAST_WITHOUT_ECHO 2
707
708 struct qeth_card_blkt {
709         int time_total;
710         int inter_packet;
711         int inter_packet_jumbo;
712 };
713
714
715
716 struct qeth_card_info {
717         unsigned short unit_addr2;
718         unsigned short cula;
719         unsigned short chpid;
720         __u16 func_level;
721         char mcl_level[QETH_MCL_LENGTH + 1];
722         int guestlan;
723         int layer2_mac_registered;
724         int portname_required;
725         int portno;
726         char portname[9];
727         enum qeth_card_types type;
728         enum qeth_link_types link_type;
729         int is_multicast_different;
730         int initial_mtu;
731         int max_mtu;
732         int broadcast_capable;
733         int unique_id;
734         struct qeth_card_blkt blkt;
735         __u32 csum_mask;
736 };
737
738 struct qeth_card_options {
739         struct qeth_routing_info route4;
740         struct qeth_ipa_info ipa4;
741         struct qeth_ipa_info adp; /*Adapter parameters*/
742 #ifdef CONFIG_QETH_IPV6
743         struct qeth_routing_info route6;
744         struct qeth_ipa_info ipa6;
745 #endif /* QETH_IPV6 */
746         enum qeth_checksum_types checksum_type;
747         int broadcast_mode;
748         int macaddr_mode;
749         int fake_broadcast;
750         int add_hhlen;
751         int fake_ll;
752         int layer2;
753         enum qeth_large_send_types large_send;
754 };
755
756 /*
757  * thread bits for qeth_card thread masks
758  */
759 enum qeth_threads {
760         QETH_SET_IP_THREAD  = 1,
761         QETH_RECOVER_THREAD = 2,
762 };
763
764 struct qeth_card {
765         struct list_head list;
766         enum qeth_card_states state;
767         int lan_online;
768         spinlock_t lock;
769 /*hardware and sysfs stuff*/
770         struct ccwgroup_device *gdev;
771         struct qeth_channel read;
772         struct qeth_channel write;
773         struct qeth_channel data;
774
775         struct net_device *dev;
776         struct net_device_stats stats;
777
778         struct qeth_card_info info;
779         struct qeth_token token;
780         struct qeth_seqno seqno;
781         struct qeth_card_options options;
782
783         wait_queue_head_t wait_q;
784 #ifdef CONFIG_QETH_VLAN
785         spinlock_t vlanlock;
786         struct vlan_group *vlangrp;
787 #endif
788         struct work_struct kernel_thread_starter;
789         spinlock_t thread_mask_lock;
790         volatile unsigned long thread_start_mask;
791         volatile unsigned long thread_allowed_mask;
792         volatile unsigned long thread_running_mask;
793         spinlock_t ip_lock;
794         struct list_head ip_list;
795         struct list_head *ip_tbd_list;
796         struct qeth_ipato ipato;
797         struct list_head cmd_waiter_list;
798         /* QDIO buffer handling */
799         struct qeth_qdio_info qdio;
800 #ifdef CONFIG_QETH_PERF_STATS
801         struct qeth_perf_stats perf_stats;
802 #endif /* CONFIG_QETH_PERF_STATS */
803         int use_hard_stop;
804         int (*orig_hard_header)(struct sk_buff *,struct net_device *,
805                                 unsigned short,void *,void *,unsigned);
806 };
807
808 struct qeth_card_list_struct {
809         struct list_head list;
810         rwlock_t rwlock;
811 };
812
813 extern struct qeth_card_list_struct qeth_card_list;
814
815 /*notifier list */
816 struct qeth_notify_list_struct {
817         struct list_head list;
818         struct task_struct *task;
819         int signum;
820 };
821 extern spinlock_t qeth_notify_lock;
822 extern struct list_head qeth_notify_list;
823
824 /*some helper functions*/
825
826 #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
827
828 static inline __u8
829 qeth_get_ipa_adp_type(enum qeth_link_types link_type)
830 {
831         switch (link_type) {
832         case QETH_LINK_TYPE_HSTR:
833                 return 2;
834         default:
835                 return 1;
836         }
837 }
838
839 static inline int
840 qeth_realloc_headroom(struct qeth_card *card, struct sk_buff **skb, int size)
841 {
842         struct sk_buff *new_skb = NULL;
843
844         if (skb_headroom(*skb) < size){
845                 new_skb = skb_realloc_headroom(*skb, size);
846                 if (!new_skb) {
847                         PRINT_ERR("qeth_prepare_skb: could "
848                                   "not realloc headroom for qeth_hdr "
849                                   "on interface %s", QETH_CARD_IFNAME(card));
850                         return -ENOMEM;
851                 }
852                 kfree_skb(*skb);
853                 *skb = new_skb;
854         }
855         return 0;
856 }
857
858 static inline struct sk_buff *
859 qeth_pskb_unshare(struct sk_buff *skb, int pri)
860 {
861         struct sk_buff *nskb;
862         if (!skb_cloned(skb))
863                 return skb;
864         nskb = skb_copy(skb, pri);
865         kfree_skb(skb); /* free our shared copy */
866         return nskb;
867 }
868
869 static inline void *
870 qeth_push_skb(struct qeth_card *card, struct sk_buff **skb, int size)
871 {
872         void *hdr;
873
874         hdr = (void *) skb_push(*skb, size);
875         /*
876          * sanity check, the Linux memory allocation scheme should
877          * never present us cases like this one (the qdio header size plus
878          * the first 40 bytes of the paket cross a 4k boundary)
879          */
880         if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
881             (((unsigned long) hdr + size +
882               QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
883                 PRINT_ERR("qeth_prepare_skb: misaligned "
884                           "packet on interface %s. Discarded.",
885                           QETH_CARD_IFNAME(card));
886                 return NULL;
887         }
888         return hdr;
889 }
890
891
892 static inline int
893 qeth_get_hlen(__u8 link_type)
894 {
895 #ifdef CONFIG_QETH_IPV6
896         switch (link_type) {
897         case QETH_LINK_TYPE_HSTR:
898         case QETH_LINK_TYPE_LANE_TR:
899                 return sizeof(struct qeth_hdr_tso) + TR_HLEN;
900         default:
901 #ifdef CONFIG_QETH_VLAN
902                 return sizeof(struct qeth_hdr_tso) + VLAN_ETH_HLEN;
903 #else
904                 return sizeof(struct qeth_hdr_tso) + ETH_HLEN;
905 #endif
906         }
907 #else  /* CONFIG_QETH_IPV6 */
908 #ifdef CONFIG_QETH_VLAN
909         return sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
910 #else
911         return sizeof(struct qeth_hdr_tso);
912 #endif
913 #endif /* CONFIG_QETH_IPV6 */
914 }
915
916 static inline unsigned short
917 qeth_get_netdev_flags(struct qeth_card *card)
918 {
919         if (card->options.layer2)
920                 return 0;
921         switch (card->info.type) {
922         case QETH_CARD_TYPE_IQD:
923                 return IFF_NOARP;
924 #ifdef CONFIG_QETH_IPV6
925         default:
926                 return 0;
927 #else
928         default:
929                 return IFF_NOARP;
930 #endif
931         }
932 }
933
934 static inline int
935 qeth_get_initial_mtu_for_card(struct qeth_card * card)
936 {
937         switch (card->info.type) {
938         case QETH_CARD_TYPE_UNKNOWN:
939                 return 1500;
940         case QETH_CARD_TYPE_IQD:
941                 return card->info.max_mtu;
942         case QETH_CARD_TYPE_OSAE:
943                 switch (card->info.link_type) {
944                 case QETH_LINK_TYPE_HSTR:
945                 case QETH_LINK_TYPE_LANE_TR:
946                         return 2000;
947                 default:
948                         return 1492;
949                 }
950         default:
951                 return 1500;
952         }
953 }
954
955 static inline int
956 qeth_get_max_mtu_for_card(int cardtype)
957 {
958         switch (cardtype) {
959         case QETH_CARD_TYPE_UNKNOWN:
960                 return 61440;
961         case QETH_CARD_TYPE_OSAE:
962                 return 61440;
963         case QETH_CARD_TYPE_IQD:
964                 return 57344;
965         default:
966                 return 1500;
967         }
968 }
969
970 static inline int
971 qeth_get_mtu_out_of_mpc(int cardtype)
972 {
973         switch (cardtype) {
974         case QETH_CARD_TYPE_IQD:
975                 return 1;
976         default:
977                 return 0;
978         }
979 }
980
981 static inline int
982 qeth_get_mtu_outof_framesize(int framesize)
983 {
984         switch (framesize) {
985         case 0x4000:
986                 return 8192;
987         case 0x6000:
988                 return 16384;
989         case 0xa000:
990                 return 32768;
991         case 0xffff:
992                 return 57344;
993         default:
994                 return 0;
995         }
996 }
997
998 static inline int
999 qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1000 {
1001         switch (card->info.type) {
1002         case QETH_CARD_TYPE_OSAE:
1003                 return ((mtu >= 576) && (mtu <= 61440));
1004         case QETH_CARD_TYPE_IQD:
1005                 return ((mtu >= 576) &&
1006                         (mtu <= card->info.max_mtu + 4096 - 32));
1007         case QETH_CARD_TYPE_UNKNOWN:
1008         default:
1009                 return 1;
1010         }
1011 }
1012
1013 static inline int
1014 qeth_get_arphdr_type(int cardtype, int linktype)
1015 {
1016         switch (cardtype) {
1017         case QETH_CARD_TYPE_OSAE:
1018                 switch (linktype) {
1019                 case QETH_LINK_TYPE_LANE_TR:
1020                 case QETH_LINK_TYPE_HSTR:
1021                         return ARPHRD_IEEE802_TR;
1022                 default:
1023                         return ARPHRD_ETHER;
1024                 }
1025         case QETH_CARD_TYPE_IQD:
1026         default:
1027                 return ARPHRD_ETHER;
1028         }
1029 }
1030
1031 #ifdef CONFIG_QETH_PERF_STATS
1032 static inline int
1033 qeth_get_micros(void)
1034 {
1035         return (int) (get_clock() >> 12);
1036 }
1037 #endif
1038
1039 static inline int
1040 qeth_get_qdio_q_format(struct qeth_card *card)
1041 {
1042         switch (card->info.type) {
1043         case QETH_CARD_TYPE_IQD:
1044                 return 2;
1045         default:
1046                 return 0;
1047         }
1048 }
1049
1050 static inline void
1051 qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
1052 {
1053         sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
1054 }
1055
1056 static inline int
1057 qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
1058 {
1059         const char *start, *end;
1060         char abuf[4];
1061         char *tmp;
1062         int len;
1063         int i;
1064
1065         start = buf;
1066         for (i = 0; i < 3; i++) {
1067                 if (!(end = strchr(start, '.')))
1068                         return -EINVAL;
1069                 len = end - start;
1070                 memset(abuf, 0, 4);
1071                 strncpy(abuf, start, len);
1072                 addr[i] = simple_strtoul(abuf, &tmp, 10);
1073                 start = end + 1;
1074         }
1075         memset(abuf, 0, 4);
1076         strcpy(abuf, start);
1077         addr[3] = simple_strtoul(abuf, &tmp, 10);
1078         return 0;
1079 }
1080
1081 static inline void
1082 qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
1083 {
1084         sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
1085                      ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
1086                      addr[0], addr[1], addr[2], addr[3],
1087                      addr[4], addr[5], addr[6], addr[7],
1088                      addr[8], addr[9], addr[10], addr[11],
1089                      addr[12], addr[13], addr[14], addr[15]);
1090 }
1091
1092 static inline int
1093 qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1094 {
1095         const char *start, *end;
1096         u16 *tmp_addr;
1097         char abuf[5];
1098         char *tmp;
1099         int len;
1100         int i;
1101
1102         tmp_addr = (u16 *)addr;
1103         start = buf;
1104         for (i = 0; i < 7; i++) {
1105                 if (!(end = strchr(start, ':')))
1106                         return -EINVAL;
1107                 len = end - start;
1108                 memset(abuf, 0, 5);
1109                 strncpy(abuf, start, len);
1110                 tmp_addr[i] = simple_strtoul(abuf, &tmp, 16);
1111                 start = end + 1;
1112         }
1113         memset(abuf, 0, 5);
1114         strcpy(abuf, start);
1115         tmp_addr[7] = simple_strtoul(abuf, &tmp, 16);
1116         return 0;
1117 }
1118
1119 static inline void
1120 qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
1121                       char *buf)
1122 {
1123         if (proto == QETH_PROT_IPV4)
1124                 return qeth_ipaddr4_to_string(addr, buf);
1125         else if (proto == QETH_PROT_IPV6)
1126                 return qeth_ipaddr6_to_string(addr, buf);
1127 }
1128
1129 static inline int
1130 qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
1131                       __u8 *addr)
1132 {
1133         if (proto == QETH_PROT_IPV4)
1134                 return qeth_string_to_ipaddr4(buf, addr);
1135         else if (proto == QETH_PROT_IPV6)
1136                 return qeth_string_to_ipaddr6(buf, addr);
1137         else
1138                 return -EINVAL;
1139 }
1140
1141 extern int
1142 qeth_setrouting_v4(struct qeth_card *);
1143 extern int
1144 qeth_setrouting_v6(struct qeth_card *);
1145
1146 extern int
1147 qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
1148
1149 extern void
1150 qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
1151
1152 extern int
1153 qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1154
1155 extern void
1156 qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1157
1158 extern int
1159 qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1160
1161 extern void
1162 qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1163
1164 extern int
1165 qeth_notifier_register(struct task_struct *, int );
1166
1167 extern int
1168 qeth_notifier_unregister(struct task_struct * );
1169
1170 extern void
1171 qeth_schedule_recovery(struct qeth_card *);
1172
1173 extern int
1174 qeth_realloc_buffer_pool(struct qeth_card *, int);
1175
1176 extern int
1177 qeth_set_large_send(struct qeth_card *, enum qeth_large_send_types);
1178
1179 extern void
1180 qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
1181                  struct sk_buff *, int, int);
1182 extern void
1183 qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
1184
1185 #endif /* __QETH_H__ */