blob: b34eb82edd983190e0f727b2f4cc04dee6065b16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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>
Frank Pavlicbd389b92005-11-10 13:49:02 +010011#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070044#define QETH_DBF_SETUP_PAGES 8
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070050#define QETH_DBF_MISC_PAGES 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070056#define QETH_DBF_DATA_PAGES 8
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070062#define QETH_DBF_CONTROL_PAGES 8
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070068#define QETH_DBF_TRACE_PAGES 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define QETH_DBF_TRACE_NR_AREAS 2
70#define QETH_DBF_TRACE_LEVEL 3
71extern debug_info_t *qeth_dbf_trace;
72
73#define QETH_DBF_SENSE_NAME "qeth_sense"
74#define QETH_DBF_SENSE_LEN 64
Michael Holzheu66a464d2005-06-25 14:55:33 -070075#define QETH_DBF_SENSE_PAGES 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#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
Michael Holzheu66a464d2005-06-25 14:55:33 -070081#define QETH_DBF_QERR_PAGES 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#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
95DECLARE_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) \
117PRINT_##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)); \
125PRINT_##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
136static inline void
137qeth_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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154/*
155 * Common IO related definitions
156 */
157extern struct device *qeth_root_dev;
158extern struct ccw_driver qeth_ccw_driver;
159extern 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177struct 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;
Frank Pavlic09d2d382006-09-15 16:26:34 +0200211 /* initial values when measuring starts */
212 unsigned long initial_rx_packets;
213 unsigned long initial_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216/* Routing stuff */
217struct qeth_routing_info {
218 enum qeth_routing_types type;
219};
220
221/* IPA stuff */
222struct qeth_ipa_info {
223 __u32 supported_funcs;
224 __u32 enabled_funcs;
225};
226
227static inline int
228qeth_is_ipa_supported(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
229{
230 return (ipa->supported_funcs & func);
231}
232
233static inline int
234qeth_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}, \
Ursula Braun500f83a2005-09-30 10:19:19 +0200276 {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}, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 {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
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200291#define QETH_RCD_TIMEOUT 60 * HZ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#define QETH_HEADER_SIZE 32
293#define MAX_PORTNO 15
Frank Pavlice23dd9c2005-05-12 20:38:11 +0200294#define QETH_FAKE_LL_LEN_ETH ETH_HLEN
295#define QETH_FAKE_LL_LEN_TR (sizeof(struct trh_hdr)-TR_MAXRIFLEN+sizeof(struct trllc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define QETH_FAKE_LL_V6_ADDR_POS 24
297
298/*IPv6 address autoconfiguration stuff*/
299#define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
300#define UNIQUE_ID_NOT_BY_CARD 0x10000
301
302/*****************************************************************************/
303/* QDIO queue and buffer handling */
304/*****************************************************************************/
305#define QETH_MAX_QUEUES 4
306#define QETH_IN_BUF_SIZE_DEFAULT 65536
307#define QETH_IN_BUF_COUNT_DEFAULT 16
308#define QETH_IN_BUF_COUNT_MIN 8
309#define QETH_IN_BUF_COUNT_MAX 128
310#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
311#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
312 ((card)->qdio.in_buf_pool.buf_count / 2)
313
314/* buffers we have to be behind before we get a PCI */
315#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
316/*enqueued free buffers left before we get a PCI*/
317#define QETH_PCI_THRESHOLD_B(card) 0
318/*not used unless the microcode gets patched*/
319#define QETH_PCI_TIMER_VALUE(card) 3
320
321#define QETH_MIN_INPUT_THRESHOLD 1
322#define QETH_MAX_INPUT_THRESHOLD 500
323#define QETH_MIN_OUTPUT_THRESHOLD 1
324#define QETH_MAX_OUTPUT_THRESHOLD 300
325
326/* priority queing */
327#define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
328#define QETH_DEFAULT_QUEUE 2
329#define QETH_NO_PRIO_QUEUEING 0
330#define QETH_PRIO_Q_ING_PREC 1
331#define QETH_PRIO_Q_ING_TOS 2
332#define IP_TOS_LOWDELAY 0x10
333#define IP_TOS_HIGHTHROUGHPUT 0x08
334#define IP_TOS_HIGHRELIABILITY 0x04
335#define IP_TOS_NOTIMPORTANT 0x02
336
337/* Packing */
338#define QETH_LOW_WATERMARK_PACK 2
339#define QETH_HIGH_WATERMARK_PACK 5
340#define QETH_WATERMARK_PACK_FUZZ 1
341
342#define QETH_IP_HEADER_SIZE 40
343
344struct qeth_hdr_layer3 {
345 __u8 id;
346 __u8 flags;
347 __u16 inbound_checksum; /*TSO:__u16 seqno */
348 __u32 token; /*TSO: __u32 reserved */
349 __u16 length;
350 __u8 vlan_prio;
351 __u8 ext_flags;
352 __u16 vlan_id;
353 __u16 frame_offset;
354 __u8 dest_addr[16];
355} __attribute__ ((packed));
356
357struct qeth_hdr_layer2 {
358 __u8 id;
359 __u8 flags[3];
360 __u8 port_no;
361 __u8 hdr_length;
362 __u16 pkt_length;
363 __u16 seq_no;
364 __u16 vlan_id;
365 __u32 reserved;
366 __u8 reserved2[16];
367} __attribute__ ((packed));
368
Ursula Braun500f83a2005-09-30 10:19:19 +0200369struct qeth_hdr_osn {
370 __u8 id;
371 __u8 reserved;
372 __u16 seq_no;
373 __u16 reserved2;
374 __u16 control_flags;
375 __u16 pdu_length;
376 __u8 reserved3[18];
377 __u32 ccid;
378} __attribute__ ((packed));
Jeff Garzike82b0f22006-05-26 21:58:38 -0400379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380struct qeth_hdr {
381 union {
382 struct qeth_hdr_layer2 l2;
383 struct qeth_hdr_layer3 l3;
Ursula Braun500f83a2005-09-30 10:19:19 +0200384 struct qeth_hdr_osn osn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 } hdr;
386} __attribute__ ((packed));
387
Frank Pavlic05e08a22005-05-12 20:39:09 +0200388/*TCP Segmentation Offload header*/
389struct qeth_hdr_ext_tso {
390 __u16 hdr_tot_len;
391 __u8 imb_hdr_no;
392 __u8 reserved;
393 __u8 hdr_type;
394 __u8 hdr_version;
395 __u16 hdr_len;
396 __u32 payload_len;
397 __u16 mss;
398 __u16 dg_hdr_len;
399 __u8 padding[16];
400} __attribute__ ((packed));
401
402struct qeth_hdr_tso {
403 struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
404 struct qeth_hdr_ext_tso ext;
405} __attribute__ ((packed));
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408/* flags for qeth_hdr.flags */
409#define QETH_HDR_PASSTHRU 0x10
410#define QETH_HDR_IPV6 0x80
411#define QETH_HDR_CAST_MASK 0x07
412enum qeth_cast_flags {
413 QETH_CAST_UNICAST = 0x06,
414 QETH_CAST_MULTICAST = 0x04,
415 QETH_CAST_BROADCAST = 0x05,
416 QETH_CAST_ANYCAST = 0x07,
417 QETH_CAST_NOCAST = 0x00,
418};
419
420enum qeth_layer2_frame_flags {
421 QETH_LAYER2_FLAG_MULTICAST = 0x01,
422 QETH_LAYER2_FLAG_BROADCAST = 0x02,
423 QETH_LAYER2_FLAG_UNICAST = 0x04,
424 QETH_LAYER2_FLAG_VLAN = 0x10,
425};
426
427enum qeth_header_ids {
428 QETH_HEADER_TYPE_LAYER3 = 0x01,
429 QETH_HEADER_TYPE_LAYER2 = 0x02,
430 QETH_HEADER_TYPE_TSO = 0x03,
Ursula Braun500f83a2005-09-30 10:19:19 +0200431 QETH_HEADER_TYPE_OSN = 0x04,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432};
433/* flags for qeth_hdr.ext_flags */
434#define QETH_HDR_EXT_VLAN_FRAME 0x01
435#define QETH_HDR_EXT_TOKEN_ID 0x02
436#define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
437#define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
438#define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
439#define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
440#define QETH_HDR_EXT_UDP_TSO 0x40 /*bit off for TCP*/
441
442static inline int
443qeth_is_last_sbale(struct qdio_buffer_element *sbale)
444{
445 return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
446}
447
448enum qeth_qdio_buffer_states {
449 /*
450 * inbound: read out by driver; owned by hardware in order to be filled
451 * outbound: owned by driver in order to be filled
452 */
453 QETH_QDIO_BUF_EMPTY,
454 /*
455 * inbound: filled by hardware; owned by driver in order to be read out
456 * outbound: filled by driver; owned by hardware in order to be sent
457 */
458 QETH_QDIO_BUF_PRIMED,
459};
460
461enum qeth_qdio_info_states {
462 QETH_QDIO_UNINITIALIZED,
463 QETH_QDIO_ALLOCATED,
464 QETH_QDIO_ESTABLISHED,
Frank Pavlicf956b692006-09-15 16:26:52 +0200465 QETH_QDIO_CLEANING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466};
467
468struct qeth_buffer_pool_entry {
469 struct list_head list;
470 struct list_head init_list;
471 void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
472};
473
474struct qeth_qdio_buffer_pool {
475 struct list_head entry_list;
476 int buf_count;
477};
478
479struct qeth_qdio_buffer {
480 struct qdio_buffer *buffer;
481 volatile enum qeth_qdio_buffer_states state;
482 /* the buffer pool entry currently associated to this buffer */
483 struct qeth_buffer_pool_entry *pool_entry;
484};
485
486struct qeth_qdio_q {
487 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
488 struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
489 /*
490 * buf_to_init means "buffer must be initialized by driver and must
491 * be made available for hardware" -> state is set to EMPTY
492 */
493 volatile int next_buf_to_init;
494} __attribute__ ((aligned(256)));
495
496/* possible types of qeth large_send support */
497enum qeth_large_send_types {
498 QETH_LARGE_SEND_NO,
499 QETH_LARGE_SEND_EDDP,
500 QETH_LARGE_SEND_TSO,
501};
502
503struct qeth_qdio_out_buffer {
504 struct qdio_buffer *buffer;
505 atomic_t state;
506 volatile int next_element_to_fill;
507 struct sk_buff_head skb_list;
508 struct list_head ctx_list;
509};
510
511struct qeth_card;
512
513enum qeth_out_q_states {
514 QETH_OUT_Q_UNLOCKED,
515 QETH_OUT_Q_LOCKED,
516 QETH_OUT_Q_LOCKED_FLUSH,
517};
518
519struct qeth_qdio_out_q {
520 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
521 struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
522 int queue_no;
523 struct qeth_card *card;
524 atomic_t state;
525 volatile int do_pack;
526 /*
527 * index of buffer to be filled by driver; state EMPTY or PACKING
528 */
529 volatile int next_buf_to_fill;
530 /*
531 * number of buffers that are currently filled (PRIMED)
532 * -> these buffers are hardware-owned
533 */
534 atomic_t used_buffers;
535 /* indicates whether PCI flag must be set (or if one is outstanding) */
536 atomic_t set_pci_flags_count;
537} __attribute__ ((aligned(256)));
538
539struct qeth_qdio_info {
Frank Pavlicf956b692006-09-15 16:26:52 +0200540 atomic_t state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 /* input */
542 struct qeth_qdio_q *in_q;
543 struct qeth_qdio_buffer_pool in_buf_pool;
544 struct qeth_qdio_buffer_pool init_pool;
545 int in_buf_size;
546
547 /* output */
548 int no_out_queues;
549 struct qeth_qdio_out_q **out_qs;
550
551 /* priority queueing */
552 int do_prio_queueing;
553 int default_out_queue;
554};
555
556enum qeth_send_errors {
557 QETH_SEND_ERROR_NONE,
558 QETH_SEND_ERROR_LINK_FAILURE,
559 QETH_SEND_ERROR_RETRY,
560 QETH_SEND_ERROR_KICK_IT,
561};
562
563#define QETH_ETH_MAC_V4 0x0100 /* like v4 */
564#define QETH_ETH_MAC_V6 0x3333 /* like v6 */
565/* tr mc mac is longer, but that will be enough to detect mc frames */
566#define QETH_TR_MAC_NC 0xc000 /* non-canonical */
567#define QETH_TR_MAC_C 0x0300 /* canonical */
568
569#define DEFAULT_ADD_HHLEN 0
570#define MAX_ADD_HHLEN 1024
571
572/**
573 * buffer stuff for read channel
574 */
575#define QETH_CMD_BUFFER_NO 8
576
577/**
578 * channel state machine
579 */
580enum qeth_channel_states {
581 CH_STATE_UP,
582 CH_STATE_DOWN,
583 CH_STATE_ACTIVATING,
584 CH_STATE_HALTED,
585 CH_STATE_STOPPED,
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200586 CH_STATE_RCD,
587 CH_STATE_RCD_DONE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588};
589/**
590 * card state machine
591 */
592enum qeth_card_states {
593 CARD_STATE_DOWN,
594 CARD_STATE_HARDSETUP,
595 CARD_STATE_SOFTSETUP,
596 CARD_STATE_UP,
597 CARD_STATE_RECOVER,
598};
599
600/**
601 * Protocol versions
602 */
603enum qeth_prot_versions {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 QETH_PROT_IPV4 = 0x0004,
605 QETH_PROT_IPV6 = 0x0006,
606};
607
608enum qeth_ip_types {
609 QETH_IP_TYPE_NORMAL,
610 QETH_IP_TYPE_VIPA,
611 QETH_IP_TYPE_RXIP,
612 QETH_IP_TYPE_DEL_ALL_MC,
613};
614
615enum qeth_cmd_buffer_state {
616 BUF_STATE_FREE,
617 BUF_STATE_LOCKED,
618 BUF_STATE_PROCESSED,
619};
620/**
621 * IP address and multicast list
622 */
623struct qeth_ipaddr {
624 struct list_head entry;
625 enum qeth_ip_types type;
626 enum qeth_ipa_setdelip_flags set_flags;
627 enum qeth_ipa_setdelip_flags del_flags;
628 int is_multicast;
629 volatile int users;
630 enum qeth_prot_versions proto;
631 unsigned char mac[OSA_ADDR_LEN];
632 union {
633 struct {
634 unsigned int addr;
635 unsigned int mask;
636 } a4;
637 struct {
638 struct in6_addr addr;
639 unsigned int pfxlen;
640 } a6;
641 } u;
642};
643
644struct qeth_ipato_entry {
645 struct list_head entry;
646 enum qeth_prot_versions proto;
647 char addr[16];
648 int mask_bits;
649};
650
651struct qeth_ipato {
652 int enabled;
653 int invert4;
654 int invert6;
655 struct list_head entries;
656};
657
658struct qeth_channel;
659
660struct qeth_cmd_buffer {
661 enum qeth_cmd_buffer_state state;
662 struct qeth_channel *channel;
663 unsigned char *data;
664 int rc;
665 void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
666};
667
668
669/**
670 * definition of a qeth channel, used for read and write
671 */
672struct qeth_channel {
673 enum qeth_channel_states state;
674 struct ccw1 ccw;
675 spinlock_t iob_lock;
676 wait_queue_head_t wait_q;
677 struct tasklet_struct irq_tasklet;
678 struct ccw_device *ccwdev;
679/*command buffer for control data*/
680 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
681 atomic_t irq_pending;
682 volatile int io_buf_no;
683 volatile int buf_no;
684};
685
686/**
687 * OSA card related definitions
688 */
689struct qeth_token {
690 __u32 issuer_rm_w;
691 __u32 issuer_rm_r;
692 __u32 cm_filter_w;
693 __u32 cm_filter_r;
694 __u32 cm_connection_w;
695 __u32 cm_connection_r;
696 __u32 ulp_filter_w;
697 __u32 ulp_filter_r;
698 __u32 ulp_connection_w;
699 __u32 ulp_connection_r;
700};
701
702struct qeth_seqno {
703 __u32 trans_hdr;
704 __u32 pdu_hdr;
705 __u32 pdu_hdr_ack;
706 __u16 ipa;
Ursula Braun9123e0d2005-09-30 10:17:24 +0200707 __u32 pkt_seqno;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708};
709
710struct qeth_reply {
711 struct list_head list;
712 wait_queue_head_t wait_q;
713 int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
714 u32 seqno;
715 unsigned long offset;
Frank Blaschkaee2db682007-01-08 17:30:11 +0100716 atomic_t received;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 int rc;
718 void *param;
719 struct qeth_card *card;
720 atomic_t refcnt;
721};
722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724struct qeth_card_blkt {
725 int time_total;
726 int inter_packet;
727 int inter_packet_jumbo;
728};
729
Frank Pavlice08d88c2005-11-10 13:51:17 +0100730#define QETH_BROADCAST_WITH_ECHO 0x01
731#define QETH_BROADCAST_WITHOUT_ECHO 0x02
732#define QETH_LAYER2_MAC_READ 0x01
733#define QETH_LAYER2_MAC_REGISTERED 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734struct qeth_card_info {
735 unsigned short unit_addr2;
736 unsigned short cula;
737 unsigned short chpid;
738 __u16 func_level;
739 char mcl_level[QETH_MCL_LENGTH + 1];
740 int guestlan;
Frank Pavlice08d88c2005-11-10 13:51:17 +0100741 int mac_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 int portname_required;
743 int portno;
744 char portname[9];
745 enum qeth_card_types type;
746 enum qeth_link_types link_type;
747 int is_multicast_different;
748 int initial_mtu;
749 int max_mtu;
750 int broadcast_capable;
751 int unique_id;
752 struct qeth_card_blkt blkt;
753 __u32 csum_mask;
Frank Pavlic6c951b92005-11-10 13:51:25 +0100754 enum qeth_ipa_promisc_modes promisc_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755};
756
757struct qeth_card_options {
758 struct qeth_routing_info route4;
759 struct qeth_ipa_info ipa4;
760 struct qeth_ipa_info adp; /*Adapter parameters*/
761#ifdef CONFIG_QETH_IPV6
762 struct qeth_routing_info route6;
763 struct qeth_ipa_info ipa6;
764#endif /* QETH_IPV6 */
765 enum qeth_checksum_types checksum_type;
766 int broadcast_mode;
767 int macaddr_mode;
768 int fake_broadcast;
769 int add_hhlen;
770 int fake_ll;
771 int layer2;
772 enum qeth_large_send_types large_send;
Frank Pavlic09d2d382006-09-15 16:26:34 +0200773 int performance_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774};
775
776/*
777 * thread bits for qeth_card thread masks
778 */
779enum qeth_threads {
780 QETH_SET_IP_THREAD = 1,
781 QETH_RECOVER_THREAD = 2,
Frank Pavlic6c951b92005-11-10 13:51:25 +0100782 QETH_SET_PROMISC_MODE_THREAD = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783};
784
Ursula Braun500f83a2005-09-30 10:19:19 +0200785struct qeth_osn_info {
786 int (*assist_cb)(struct net_device *dev, void *data);
787 int (*data_cb)(struct sk_buff *skb);
788};
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790struct qeth_card {
791 struct list_head list;
792 enum qeth_card_states state;
793 int lan_online;
794 spinlock_t lock;
795/*hardware and sysfs stuff*/
796 struct ccwgroup_device *gdev;
797 struct qeth_channel read;
798 struct qeth_channel write;
799 struct qeth_channel data;
800
801 struct net_device *dev;
802 struct net_device_stats stats;
803
804 struct qeth_card_info info;
805 struct qeth_token token;
806 struct qeth_seqno seqno;
807 struct qeth_card_options options;
808
809 wait_queue_head_t wait_q;
810#ifdef CONFIG_QETH_VLAN
811 spinlock_t vlanlock;
812 struct vlan_group *vlangrp;
813#endif
814 struct work_struct kernel_thread_starter;
815 spinlock_t thread_mask_lock;
816 volatile unsigned long thread_start_mask;
817 volatile unsigned long thread_allowed_mask;
818 volatile unsigned long thread_running_mask;
819 spinlock_t ip_lock;
820 struct list_head ip_list;
821 struct list_head *ip_tbd_list;
822 struct qeth_ipato ipato;
823 struct list_head cmd_waiter_list;
824 /* QDIO buffer handling */
825 struct qeth_qdio_info qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 struct qeth_perf_stats perf_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 int use_hard_stop;
828 int (*orig_hard_header)(struct sk_buff *,struct net_device *,
829 unsigned short,void *,void *,unsigned);
Jeff Garzike82b0f22006-05-26 21:58:38 -0400830 struct qeth_osn_info osn_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831};
832
833struct qeth_card_list_struct {
834 struct list_head list;
835 rwlock_t rwlock;
836};
837
838extern struct qeth_card_list_struct qeth_card_list;
839
840/*notifier list */
841struct qeth_notify_list_struct {
842 struct list_head list;
843 struct task_struct *task;
844 int signum;
845};
846extern spinlock_t qeth_notify_lock;
847extern struct list_head qeth_notify_list;
848
849/*some helper functions*/
850
851#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
852
Jesper Juhl77933d72005-07-27 11:46:09 -0700853static inline __u8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854qeth_get_ipa_adp_type(enum qeth_link_types link_type)
855{
856 switch (link_type) {
857 case QETH_LINK_TYPE_HSTR:
858 return 2;
859 default:
860 return 1;
861 }
862}
863
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200864static inline struct sk_buff *
865qeth_realloc_headroom(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200867 struct sk_buff *new_skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200869 if (skb_headroom(skb) >= size)
870 return skb;
871 new_skb = skb_realloc_headroom(skb, size);
872 if (!new_skb)
873 PRINT_ERR("Could not realloc headroom for qeth_hdr "
874 "on interface %s", QETH_CARD_IFNAME(card));
875 return new_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
Jesper Juhl77933d72005-07-27 11:46:09 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878static inline struct sk_buff *
Al Viro23f28002007-03-14 09:19:20 +0000879qeth_pskb_unshare(struct sk_buff *skb, gfp_t pri)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
881 struct sk_buff *nskb;
882 if (!skb_cloned(skb))
883 return skb;
884 nskb = skb_copy(skb, pri);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 return nskb;
886}
887
Jesper Juhl77933d72005-07-27 11:46:09 -0700888static inline void *
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200889qeth_push_skb(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 void *hdr;
892
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200893 hdr = (void *) skb_push(skb, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /*
895 * sanity check, the Linux memory allocation scheme should
896 * never present us cases like this one (the qdio header size plus
897 * the first 40 bytes of the paket cross a 4k boundary)
898 */
899 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
900 (((unsigned long) hdr + size +
901 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200902 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 QETH_CARD_IFNAME(card));
904 return NULL;
905 }
906 return hdr;
907}
908
Frank Pavlicd8011452005-05-12 20:37:53 +0200909
Jesper Juhl77933d72005-07-27 11:46:09 -0700910static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911qeth_get_hlen(__u8 link_type)
912{
913#ifdef CONFIG_QETH_IPV6
914 switch (link_type) {
915 case QETH_LINK_TYPE_HSTR:
916 case QETH_LINK_TYPE_LANE_TR:
Frank Pavlic05e08a22005-05-12 20:39:09 +0200917 return sizeof(struct qeth_hdr_tso) + TR_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 default:
919#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200920 return sizeof(struct qeth_hdr_tso) + VLAN_ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200922 return sizeof(struct qeth_hdr_tso) + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923#endif
924 }
925#else /* CONFIG_QETH_IPV6 */
926#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200927 return sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200929 return sizeof(struct qeth_hdr_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930#endif
931#endif /* CONFIG_QETH_IPV6 */
932}
933
Jesper Juhl77933d72005-07-27 11:46:09 -0700934static inline unsigned short
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935qeth_get_netdev_flags(struct qeth_card *card)
936{
Ursula Braun500f83a2005-09-30 10:19:19 +0200937 if (card->options.layer2 &&
938 (card->info.type == QETH_CARD_TYPE_OSAE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return 0;
940 switch (card->info.type) {
941 case QETH_CARD_TYPE_IQD:
Jeff Garzike82b0f22006-05-26 21:58:38 -0400942 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return IFF_NOARP;
944#ifdef CONFIG_QETH_IPV6
945 default:
946 return 0;
947#else
948 default:
949 return IFF_NOARP;
950#endif
951 }
952}
953
Jesper Juhl77933d72005-07-27 11:46:09 -0700954static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955qeth_get_initial_mtu_for_card(struct qeth_card * card)
956{
957 switch (card->info.type) {
958 case QETH_CARD_TYPE_UNKNOWN:
959 return 1500;
960 case QETH_CARD_TYPE_IQD:
961 return card->info.max_mtu;
962 case QETH_CARD_TYPE_OSAE:
963 switch (card->info.link_type) {
964 case QETH_LINK_TYPE_HSTR:
965 case QETH_LINK_TYPE_LANE_TR:
966 return 2000;
967 default:
968 return 1492;
969 }
970 default:
971 return 1500;
972 }
973}
974
Jesper Juhl77933d72005-07-27 11:46:09 -0700975static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976qeth_get_max_mtu_for_card(int cardtype)
977{
978 switch (cardtype) {
Jeff Garzike82b0f22006-05-26 21:58:38 -0400979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 case QETH_CARD_TYPE_UNKNOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +0200982 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return 61440;
984 case QETH_CARD_TYPE_IQD:
985 return 57344;
986 default:
987 return 1500;
988 }
989}
990
Jesper Juhl77933d72005-07-27 11:46:09 -0700991static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992qeth_get_mtu_out_of_mpc(int cardtype)
993{
994 switch (cardtype) {
995 case QETH_CARD_TYPE_IQD:
996 return 1;
997 default:
998 return 0;
999 }
1000}
1001
Jesper Juhl77933d72005-07-27 11:46:09 -07001002static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003qeth_get_mtu_outof_framesize(int framesize)
1004{
1005 switch (framesize) {
1006 case 0x4000:
1007 return 8192;
1008 case 0x6000:
1009 return 16384;
1010 case 0xa000:
1011 return 32768;
1012 case 0xffff:
1013 return 57344;
1014 default:
1015 return 0;
1016 }
1017}
1018
Jesper Juhl77933d72005-07-27 11:46:09 -07001019static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1021{
1022 switch (card->info.type) {
1023 case QETH_CARD_TYPE_OSAE:
1024 return ((mtu >= 576) && (mtu <= 61440));
1025 case QETH_CARD_TYPE_IQD:
1026 return ((mtu >= 576) &&
1027 (mtu <= card->info.max_mtu + 4096 - 32));
Ursula Braun500f83a2005-09-30 10:19:19 +02001028 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 case QETH_CARD_TYPE_UNKNOWN:
1030 default:
1031 return 1;
1032 }
1033}
1034
Jesper Juhl77933d72005-07-27 11:46:09 -07001035static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036qeth_get_arphdr_type(int cardtype, int linktype)
1037{
1038 switch (cardtype) {
1039 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +02001040 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 switch (linktype) {
1042 case QETH_LINK_TYPE_LANE_TR:
1043 case QETH_LINK_TYPE_HSTR:
1044 return ARPHRD_IEEE802_TR;
1045 default:
1046 return ARPHRD_ETHER;
1047 }
1048 case QETH_CARD_TYPE_IQD:
1049 default:
1050 return ARPHRD_ETHER;
1051 }
1052}
1053
Jesper Juhl77933d72005-07-27 11:46:09 -07001054static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055qeth_get_micros(void)
1056{
1057 return (int) (get_clock() >> 12);
1058}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060static inline int
1061qeth_get_qdio_q_format(struct qeth_card *card)
1062{
1063 switch (card->info.type) {
1064 case QETH_CARD_TYPE_IQD:
1065 return 2;
1066 default:
1067 return 0;
1068 }
1069}
1070
Frank Pavlicbd389b92005-11-10 13:49:02 +01001071static inline int
Frank Pavlicbd389b92005-11-10 13:49:02 +01001072qeth_isxdigit(char * buf)
1073{
1074 while (*buf) {
1075 if (!isxdigit(*buf++))
1076 return 0;
1077 }
1078 return 1;
1079}
1080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081static inline void
1082qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
1083{
1084 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
1085}
1086
1087static inline int
1088qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
1089{
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001090 int count = 0, rc = 0;
1091 int in[4];
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001092 char c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001094 rc = sscanf(buf, "%u.%u.%u.%u%c",
1095 &in[0], &in[1], &in[2], &in[3], &c);
1096 if (rc != 4 && (rc != 5 || c != '\n'))
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001097 return -EINVAL;
1098 for (count = 0; count < 4; count++) {
1099 if (in[count] > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001101 addr[count] = in[count];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 return 0;
1104}
1105
1106static inline void
1107qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
1108{
1109 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
1110 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
1111 addr[0], addr[1], addr[2], addr[3],
1112 addr[4], addr[5], addr[6], addr[7],
1113 addr[8], addr[9], addr[10], addr[11],
1114 addr[12], addr[13], addr[14], addr[15]);
1115}
1116
1117static inline int
1118qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1119{
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001120 const char *end, *end_tmp, *start;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001121 __u16 *in;
1122 char num[5];
1123 int num2, cnt, out, found, save_cnt;
1124 unsigned short in_tmp[8] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001126 cnt = out = found = save_cnt = num2 = 0;
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001127 end = start = buf;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001128 in = (__u16 *) addr;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001129 memset(in, 0, 16);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001130 while (*end) {
1131 end = strchr(start,':');
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001132 if (end == NULL) {
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001133 end = buf + strlen(buf);
1134 if ((end_tmp = strchr(start, '\n')) != NULL)
1135 end = end_tmp;
1136 out = 1;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001137 }
Jeff Garzike82b0f22006-05-26 21:58:38 -04001138 if ((end - start)) {
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001139 memset(num, 0, 5);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001140 if ((end - start) > 4)
1141 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001142 memcpy(num, start, end - start);
1143 if (!qeth_isxdigit(num))
1144 return -EINVAL;
1145 sscanf(start, "%x", &num2);
1146 if (found)
1147 in_tmp[save_cnt++] = num2;
1148 else
1149 in[cnt++] = num2;
1150 if (out)
1151 break;
1152 } else {
1153 if (found)
1154 return -EINVAL;
1155 found = 1;
Frank Pavlicbd389b92005-11-10 13:49:02 +01001156 }
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001157 start = ++end;
1158 }
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001159 if (cnt + save_cnt > 8)
1160 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001161 cnt = 7;
1162 while (save_cnt)
1163 in[cnt--] = in_tmp[--save_cnt];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 return 0;
1165}
1166
1167static inline void
1168qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
1169 char *buf)
1170{
1171 if (proto == QETH_PROT_IPV4)
1172 return qeth_ipaddr4_to_string(addr, buf);
1173 else if (proto == QETH_PROT_IPV6)
1174 return qeth_ipaddr6_to_string(addr, buf);
1175}
1176
1177static inline int
1178qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
1179 __u8 *addr)
1180{
1181 if (proto == QETH_PROT_IPV4)
1182 return qeth_string_to_ipaddr4(buf, addr);
1183 else if (proto == QETH_PROT_IPV6)
1184 return qeth_string_to_ipaddr6(buf, addr);
1185 else
1186 return -EINVAL;
1187}
1188
1189extern int
1190qeth_setrouting_v4(struct qeth_card *);
1191extern int
1192qeth_setrouting_v6(struct qeth_card *);
1193
1194extern int
1195qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
1196
1197extern void
1198qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
1199
1200extern int
1201qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1202
1203extern void
1204qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1205
1206extern int
1207qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1208
1209extern void
1210qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1211
1212extern int
1213qeth_notifier_register(struct task_struct *, int );
1214
1215extern int
1216qeth_notifier_unregister(struct task_struct * );
1217
1218extern void
1219qeth_schedule_recovery(struct qeth_card *);
1220
1221extern int
1222qeth_realloc_buffer_pool(struct qeth_card *, int);
1223
1224extern int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02001225qeth_set_large_send(struct qeth_card *, enum qeth_large_send_types);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
1227extern void
1228qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
1229 struct sk_buff *, int, int);
1230extern void
1231qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
1232
Ursula Braun500f83a2005-09-30 10:19:19 +02001233extern int
1234qeth_osn_assist(struct net_device *, void *, int);
1235
1236extern int
1237qeth_osn_register(unsigned char *read_dev_no,
1238 struct net_device **,
1239 int (*assist_cb)(struct net_device *, void *),
1240 int (*data_cb)(struct sk_buff *));
1241
1242extern void
1243qeth_osn_deregister(struct net_device *);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245#endif /* __QETH_H__ */