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