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