blob: 8c6b72d05b1d63e9655bf19223704182f74a18f7 [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;
Frank Blaschkaaa617aa2007-07-12 12:51:34 +0200214 /* inbound scatter gather data */
215 unsigned int sg_skbs_rx;
216 unsigned int sg_frags_rx;
217 unsigned int sg_alloc_page_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/* Routing stuff */
221struct qeth_routing_info {
222 enum qeth_routing_types type;
223};
224
225/* IPA stuff */
226struct qeth_ipa_info {
227 __u32 supported_funcs;
228 __u32 enabled_funcs;
229};
230
231static inline int
232qeth_is_ipa_supported(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
233{
234 return (ipa->supported_funcs & func);
235}
236
237static inline int
238qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
239{
240 return (ipa->supported_funcs & ipa->enabled_funcs & func);
241}
242
243#define qeth_adp_supported(c,f) \
244 qeth_is_ipa_supported(&c->options.adp, f)
245#define qeth_adp_enabled(c,f) \
246 qeth_is_ipa_enabled(&c->options.adp, f)
247#define qeth_is_supported(c,f) \
248 qeth_is_ipa_supported(&c->options.ipa4, f)
249#define qeth_is_enabled(c,f) \
250 qeth_is_ipa_enabled(&c->options.ipa4, f)
251#ifdef CONFIG_QETH_IPV6
252#define qeth_is_supported6(c,f) \
253 qeth_is_ipa_supported(&c->options.ipa6, f)
254#define qeth_is_enabled6(c,f) \
255 qeth_is_ipa_enabled(&c->options.ipa6, f)
256#else /* CONFIG_QETH_IPV6 */
257#define qeth_is_supported6(c,f) 0
258#define qeth_is_enabled6(c,f) 0
259#endif /* CONFIG_QETH_IPV6 */
260#define qeth_is_ipafunc_supported(c,prot,f) \
261 (prot==QETH_PROT_IPV6)? qeth_is_supported6(c,f):qeth_is_supported(c,f)
262#define qeth_is_ipafunc_enabled(c,prot,f) \
263 (prot==QETH_PROT_IPV6)? qeth_is_enabled6(c,f):qeth_is_enabled(c,f)
264
265
266#define QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT 0x0101
267#define QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT 0x0101
268#define QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT 0x4108
269#define QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT 0x5108
270
271#define QETH_MODELLIST_ARRAY \
272 {{0x1731,0x01,0x1732,0x01,QETH_CARD_TYPE_OSAE,1, \
273 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
274 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
275 QETH_MAX_QUEUES,0}, \
276 {0x1731,0x05,0x1732,0x05,QETH_CARD_TYPE_IQD,0, \
277 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
278 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
279 QETH_MAX_QUEUES,0x103}, \
Ursula Braun500f83a2005-09-30 10:19:19 +0200280 {0x1731,0x06,0x1732,0x06,QETH_CARD_TYPE_OSN,0, \
281 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
282 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
283 QETH_MAX_QUEUES,0}, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 {0,0,0,0,0,0,0,0,0}}
285
286#define QETH_REAL_CARD 1
287#define QETH_VLAN_CARD 2
288#define QETH_BUFSIZE 4096
289
290/**
291 * some more defs
292 */
293#define IF_NAME_LEN 16
294#define QETH_TX_TIMEOUT 100 * HZ
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200295#define QETH_RCD_TIMEOUT 60 * HZ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296#define QETH_HEADER_SIZE 32
297#define MAX_PORTNO 15
Frank Pavlice23dd9c2005-05-12 20:38:11 +0200298#define QETH_FAKE_LL_LEN_ETH ETH_HLEN
299#define QETH_FAKE_LL_LEN_TR (sizeof(struct trh_hdr)-TR_MAXRIFLEN+sizeof(struct trllc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300#define QETH_FAKE_LL_V6_ADDR_POS 24
301
302/*IPv6 address autoconfiguration stuff*/
303#define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
304#define UNIQUE_ID_NOT_BY_CARD 0x10000
305
306/*****************************************************************************/
307/* QDIO queue and buffer handling */
308/*****************************************************************************/
309#define QETH_MAX_QUEUES 4
310#define QETH_IN_BUF_SIZE_DEFAULT 65536
311#define QETH_IN_BUF_COUNT_DEFAULT 16
312#define QETH_IN_BUF_COUNT_MIN 8
313#define QETH_IN_BUF_COUNT_MAX 128
314#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
315#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
316 ((card)->qdio.in_buf_pool.buf_count / 2)
317
318/* buffers we have to be behind before we get a PCI */
319#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
320/*enqueued free buffers left before we get a PCI*/
321#define QETH_PCI_THRESHOLD_B(card) 0
322/*not used unless the microcode gets patched*/
323#define QETH_PCI_TIMER_VALUE(card) 3
324
325#define QETH_MIN_INPUT_THRESHOLD 1
326#define QETH_MAX_INPUT_THRESHOLD 500
327#define QETH_MIN_OUTPUT_THRESHOLD 1
328#define QETH_MAX_OUTPUT_THRESHOLD 300
329
330/* priority queing */
331#define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
332#define QETH_DEFAULT_QUEUE 2
333#define QETH_NO_PRIO_QUEUEING 0
334#define QETH_PRIO_Q_ING_PREC 1
335#define QETH_PRIO_Q_ING_TOS 2
336#define IP_TOS_LOWDELAY 0x10
337#define IP_TOS_HIGHTHROUGHPUT 0x08
338#define IP_TOS_HIGHRELIABILITY 0x04
339#define IP_TOS_NOTIMPORTANT 0x02
340
341/* Packing */
342#define QETH_LOW_WATERMARK_PACK 2
343#define QETH_HIGH_WATERMARK_PACK 5
344#define QETH_WATERMARK_PACK_FUZZ 1
345
346#define QETH_IP_HEADER_SIZE 40
347
Frank Blaschkaaa617aa2007-07-12 12:51:34 +0200348/* large receive scatter gather copy break */
349#define QETH_RX_SG_CB (PAGE_SIZE >> 1)
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351struct qeth_hdr_layer3 {
352 __u8 id;
353 __u8 flags;
354 __u16 inbound_checksum; /*TSO:__u16 seqno */
355 __u32 token; /*TSO: __u32 reserved */
356 __u16 length;
357 __u8 vlan_prio;
358 __u8 ext_flags;
359 __u16 vlan_id;
360 __u16 frame_offset;
361 __u8 dest_addr[16];
362} __attribute__ ((packed));
363
364struct qeth_hdr_layer2 {
365 __u8 id;
366 __u8 flags[3];
367 __u8 port_no;
368 __u8 hdr_length;
369 __u16 pkt_length;
370 __u16 seq_no;
371 __u16 vlan_id;
372 __u32 reserved;
373 __u8 reserved2[16];
374} __attribute__ ((packed));
375
Ursula Braun500f83a2005-09-30 10:19:19 +0200376struct qeth_hdr_osn {
377 __u8 id;
378 __u8 reserved;
379 __u16 seq_no;
380 __u16 reserved2;
381 __u16 control_flags;
382 __u16 pdu_length;
383 __u8 reserved3[18];
384 __u32 ccid;
385} __attribute__ ((packed));
Jeff Garzike82b0f22006-05-26 21:58:38 -0400386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387struct qeth_hdr {
388 union {
389 struct qeth_hdr_layer2 l2;
390 struct qeth_hdr_layer3 l3;
Ursula Braun500f83a2005-09-30 10:19:19 +0200391 struct qeth_hdr_osn osn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 } hdr;
393} __attribute__ ((packed));
394
Frank Pavlic05e08a22005-05-12 20:39:09 +0200395/*TCP Segmentation Offload header*/
396struct qeth_hdr_ext_tso {
397 __u16 hdr_tot_len;
398 __u8 imb_hdr_no;
399 __u8 reserved;
400 __u8 hdr_type;
401 __u8 hdr_version;
402 __u16 hdr_len;
403 __u32 payload_len;
404 __u16 mss;
405 __u16 dg_hdr_len;
406 __u8 padding[16];
407} __attribute__ ((packed));
408
409struct qeth_hdr_tso {
410 struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
411 struct qeth_hdr_ext_tso ext;
412} __attribute__ ((packed));
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415/* flags for qeth_hdr.flags */
416#define QETH_HDR_PASSTHRU 0x10
417#define QETH_HDR_IPV6 0x80
418#define QETH_HDR_CAST_MASK 0x07
419enum qeth_cast_flags {
420 QETH_CAST_UNICAST = 0x06,
421 QETH_CAST_MULTICAST = 0x04,
422 QETH_CAST_BROADCAST = 0x05,
423 QETH_CAST_ANYCAST = 0x07,
424 QETH_CAST_NOCAST = 0x00,
425};
426
427enum qeth_layer2_frame_flags {
428 QETH_LAYER2_FLAG_MULTICAST = 0x01,
429 QETH_LAYER2_FLAG_BROADCAST = 0x02,
430 QETH_LAYER2_FLAG_UNICAST = 0x04,
431 QETH_LAYER2_FLAG_VLAN = 0x10,
432};
433
434enum qeth_header_ids {
435 QETH_HEADER_TYPE_LAYER3 = 0x01,
436 QETH_HEADER_TYPE_LAYER2 = 0x02,
437 QETH_HEADER_TYPE_TSO = 0x03,
Ursula Braun500f83a2005-09-30 10:19:19 +0200438 QETH_HEADER_TYPE_OSN = 0x04,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439};
440/* flags for qeth_hdr.ext_flags */
441#define QETH_HDR_EXT_VLAN_FRAME 0x01
442#define QETH_HDR_EXT_TOKEN_ID 0x02
443#define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
444#define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
445#define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
446#define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
447#define QETH_HDR_EXT_UDP_TSO 0x40 /*bit off for TCP*/
448
449static inline int
450qeth_is_last_sbale(struct qdio_buffer_element *sbale)
451{
452 return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
453}
454
455enum qeth_qdio_buffer_states {
456 /*
457 * inbound: read out by driver; owned by hardware in order to be filled
458 * outbound: owned by driver in order to be filled
459 */
460 QETH_QDIO_BUF_EMPTY,
461 /*
462 * inbound: filled by hardware; owned by driver in order to be read out
463 * outbound: filled by driver; owned by hardware in order to be sent
464 */
465 QETH_QDIO_BUF_PRIMED,
466};
467
468enum qeth_qdio_info_states {
469 QETH_QDIO_UNINITIALIZED,
470 QETH_QDIO_ALLOCATED,
471 QETH_QDIO_ESTABLISHED,
Frank Pavlicf956b692006-09-15 16:26:52 +0200472 QETH_QDIO_CLEANING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473};
474
475struct qeth_buffer_pool_entry {
476 struct list_head list;
477 struct list_head init_list;
478 void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
479};
480
481struct qeth_qdio_buffer_pool {
482 struct list_head entry_list;
483 int buf_count;
484};
485
486struct qeth_qdio_buffer {
487 struct qdio_buffer *buffer;
488 volatile enum qeth_qdio_buffer_states state;
489 /* the buffer pool entry currently associated to this buffer */
490 struct qeth_buffer_pool_entry *pool_entry;
491};
492
493struct qeth_qdio_q {
494 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
495 struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
496 /*
497 * buf_to_init means "buffer must be initialized by driver and must
498 * be made available for hardware" -> state is set to EMPTY
499 */
500 volatile int next_buf_to_init;
501} __attribute__ ((aligned(256)));
502
503/* possible types of qeth large_send support */
504enum qeth_large_send_types {
505 QETH_LARGE_SEND_NO,
506 QETH_LARGE_SEND_EDDP,
507 QETH_LARGE_SEND_TSO,
508};
509
510struct qeth_qdio_out_buffer {
511 struct qdio_buffer *buffer;
512 atomic_t state;
513 volatile int next_element_to_fill;
514 struct sk_buff_head skb_list;
515 struct list_head ctx_list;
516};
517
518struct qeth_card;
519
520enum qeth_out_q_states {
521 QETH_OUT_Q_UNLOCKED,
522 QETH_OUT_Q_LOCKED,
523 QETH_OUT_Q_LOCKED_FLUSH,
524};
525
526struct qeth_qdio_out_q {
527 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
528 struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
529 int queue_no;
530 struct qeth_card *card;
531 atomic_t state;
532 volatile int do_pack;
533 /*
534 * index of buffer to be filled by driver; state EMPTY or PACKING
535 */
536 volatile int next_buf_to_fill;
537 /*
538 * number of buffers that are currently filled (PRIMED)
539 * -> these buffers are hardware-owned
540 */
541 atomic_t used_buffers;
542 /* indicates whether PCI flag must be set (or if one is outstanding) */
543 atomic_t set_pci_flags_count;
544} __attribute__ ((aligned(256)));
545
546struct qeth_qdio_info {
Frank Pavlicf956b692006-09-15 16:26:52 +0200547 atomic_t state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 /* input */
549 struct qeth_qdio_q *in_q;
550 struct qeth_qdio_buffer_pool in_buf_pool;
551 struct qeth_qdio_buffer_pool init_pool;
552 int in_buf_size;
553
554 /* output */
555 int no_out_queues;
556 struct qeth_qdio_out_q **out_qs;
557
558 /* priority queueing */
559 int do_prio_queueing;
560 int default_out_queue;
561};
562
563enum qeth_send_errors {
564 QETH_SEND_ERROR_NONE,
565 QETH_SEND_ERROR_LINK_FAILURE,
566 QETH_SEND_ERROR_RETRY,
567 QETH_SEND_ERROR_KICK_IT,
568};
569
570#define QETH_ETH_MAC_V4 0x0100 /* like v4 */
571#define QETH_ETH_MAC_V6 0x3333 /* like v6 */
572/* tr mc mac is longer, but that will be enough to detect mc frames */
573#define QETH_TR_MAC_NC 0xc000 /* non-canonical */
574#define QETH_TR_MAC_C 0x0300 /* canonical */
575
576#define DEFAULT_ADD_HHLEN 0
577#define MAX_ADD_HHLEN 1024
578
579/**
580 * buffer stuff for read channel
581 */
582#define QETH_CMD_BUFFER_NO 8
583
584/**
585 * channel state machine
586 */
587enum qeth_channel_states {
588 CH_STATE_UP,
589 CH_STATE_DOWN,
590 CH_STATE_ACTIVATING,
591 CH_STATE_HALTED,
592 CH_STATE_STOPPED,
Cornelia Huck6c82a8a2007-05-04 18:47:52 +0200593 CH_STATE_RCD,
594 CH_STATE_RCD_DONE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595};
596/**
597 * card state machine
598 */
599enum qeth_card_states {
600 CARD_STATE_DOWN,
601 CARD_STATE_HARDSETUP,
602 CARD_STATE_SOFTSETUP,
603 CARD_STATE_UP,
604 CARD_STATE_RECOVER,
605};
606
607/**
608 * Protocol versions
609 */
610enum qeth_prot_versions {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 QETH_PROT_IPV4 = 0x0004,
612 QETH_PROT_IPV6 = 0x0006,
613};
614
615enum qeth_ip_types {
616 QETH_IP_TYPE_NORMAL,
617 QETH_IP_TYPE_VIPA,
618 QETH_IP_TYPE_RXIP,
619 QETH_IP_TYPE_DEL_ALL_MC,
620};
621
622enum qeth_cmd_buffer_state {
623 BUF_STATE_FREE,
624 BUF_STATE_LOCKED,
625 BUF_STATE_PROCESSED,
626};
627/**
628 * IP address and multicast list
629 */
630struct qeth_ipaddr {
631 struct list_head entry;
632 enum qeth_ip_types type;
633 enum qeth_ipa_setdelip_flags set_flags;
634 enum qeth_ipa_setdelip_flags del_flags;
635 int is_multicast;
636 volatile int users;
637 enum qeth_prot_versions proto;
638 unsigned char mac[OSA_ADDR_LEN];
639 union {
640 struct {
641 unsigned int addr;
642 unsigned int mask;
643 } a4;
644 struct {
645 struct in6_addr addr;
646 unsigned int pfxlen;
647 } a6;
648 } u;
649};
650
651struct qeth_ipato_entry {
652 struct list_head entry;
653 enum qeth_prot_versions proto;
654 char addr[16];
655 int mask_bits;
656};
657
658struct qeth_ipato {
659 int enabled;
660 int invert4;
661 int invert6;
662 struct list_head entries;
663};
664
665struct qeth_channel;
666
667struct qeth_cmd_buffer {
668 enum qeth_cmd_buffer_state state;
669 struct qeth_channel *channel;
670 unsigned char *data;
671 int rc;
672 void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
673};
674
675
676/**
677 * definition of a qeth channel, used for read and write
678 */
679struct qeth_channel {
680 enum qeth_channel_states state;
681 struct ccw1 ccw;
682 spinlock_t iob_lock;
683 wait_queue_head_t wait_q;
684 struct tasklet_struct irq_tasklet;
685 struct ccw_device *ccwdev;
686/*command buffer for control data*/
687 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
688 atomic_t irq_pending;
689 volatile int io_buf_no;
690 volatile int buf_no;
691};
692
693/**
694 * OSA card related definitions
695 */
696struct qeth_token {
697 __u32 issuer_rm_w;
698 __u32 issuer_rm_r;
699 __u32 cm_filter_w;
700 __u32 cm_filter_r;
701 __u32 cm_connection_w;
702 __u32 cm_connection_r;
703 __u32 ulp_filter_w;
704 __u32 ulp_filter_r;
705 __u32 ulp_connection_w;
706 __u32 ulp_connection_r;
707};
708
709struct qeth_seqno {
710 __u32 trans_hdr;
711 __u32 pdu_hdr;
712 __u32 pdu_hdr_ack;
713 __u16 ipa;
Ursula Braun9123e0d2005-09-30 10:17:24 +0200714 __u32 pkt_seqno;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715};
716
717struct qeth_reply {
718 struct list_head list;
719 wait_queue_head_t wait_q;
720 int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
721 u32 seqno;
722 unsigned long offset;
Frank Blaschkaee2db682007-01-08 17:30:11 +0100723 atomic_t received;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 int rc;
725 void *param;
726 struct qeth_card *card;
727 atomic_t refcnt;
728};
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731struct qeth_card_blkt {
732 int time_total;
733 int inter_packet;
734 int inter_packet_jumbo;
735};
736
Frank Pavlice08d88c2005-11-10 13:51:17 +0100737#define QETH_BROADCAST_WITH_ECHO 0x01
738#define QETH_BROADCAST_WITHOUT_ECHO 0x02
739#define QETH_LAYER2_MAC_READ 0x01
740#define QETH_LAYER2_MAC_REGISTERED 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741struct qeth_card_info {
742 unsigned short unit_addr2;
743 unsigned short cula;
744 unsigned short chpid;
745 __u16 func_level;
746 char mcl_level[QETH_MCL_LENGTH + 1];
747 int guestlan;
Frank Pavlice08d88c2005-11-10 13:51:17 +0100748 int mac_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 int portname_required;
750 int portno;
751 char portname[9];
752 enum qeth_card_types type;
753 enum qeth_link_types link_type;
754 int is_multicast_different;
755 int initial_mtu;
756 int max_mtu;
757 int broadcast_capable;
758 int unique_id;
759 struct qeth_card_blkt blkt;
760 __u32 csum_mask;
Frank Pavlic6c951b92005-11-10 13:51:25 +0100761 enum qeth_ipa_promisc_modes promisc_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762};
763
764struct qeth_card_options {
765 struct qeth_routing_info route4;
766 struct qeth_ipa_info ipa4;
767 struct qeth_ipa_info adp; /*Adapter parameters*/
768#ifdef CONFIG_QETH_IPV6
769 struct qeth_routing_info route6;
770 struct qeth_ipa_info ipa6;
771#endif /* QETH_IPV6 */
772 enum qeth_checksum_types checksum_type;
773 int broadcast_mode;
774 int macaddr_mode;
775 int fake_broadcast;
776 int add_hhlen;
777 int fake_ll;
778 int layer2;
779 enum qeth_large_send_types large_send;
Frank Pavlic09d2d382006-09-15 16:26:34 +0200780 int performance_stats;
Frank Blaschkaaa617aa2007-07-12 12:51:34 +0200781 int rx_sg_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782};
783
784/*
785 * thread bits for qeth_card thread masks
786 */
787enum qeth_threads {
788 QETH_SET_IP_THREAD = 1,
789 QETH_RECOVER_THREAD = 2,
Frank Pavlic6c951b92005-11-10 13:51:25 +0100790 QETH_SET_PROMISC_MODE_THREAD = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791};
792
Ursula Braun500f83a2005-09-30 10:19:19 +0200793struct qeth_osn_info {
794 int (*assist_cb)(struct net_device *dev, void *data);
795 int (*data_cb)(struct sk_buff *skb);
796};
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798struct qeth_card {
799 struct list_head list;
800 enum qeth_card_states state;
801 int lan_online;
802 spinlock_t lock;
803/*hardware and sysfs stuff*/
804 struct ccwgroup_device *gdev;
805 struct qeth_channel read;
806 struct qeth_channel write;
807 struct qeth_channel data;
808
809 struct net_device *dev;
810 struct net_device_stats stats;
811
812 struct qeth_card_info info;
813 struct qeth_token token;
814 struct qeth_seqno seqno;
815 struct qeth_card_options options;
816
817 wait_queue_head_t wait_q;
818#ifdef CONFIG_QETH_VLAN
819 spinlock_t vlanlock;
820 struct vlan_group *vlangrp;
821#endif
822 struct work_struct kernel_thread_starter;
823 spinlock_t thread_mask_lock;
824 volatile unsigned long thread_start_mask;
825 volatile unsigned long thread_allowed_mask;
826 volatile unsigned long thread_running_mask;
827 spinlock_t ip_lock;
828 struct list_head ip_list;
829 struct list_head *ip_tbd_list;
830 struct qeth_ipato ipato;
831 struct list_head cmd_waiter_list;
832 /* QDIO buffer handling */
833 struct qeth_qdio_info qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 struct qeth_perf_stats perf_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 int use_hard_stop;
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700836 const struct header_ops *orig_header_ops;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400837 struct qeth_osn_info osn_info;
Frank Blaschkaaa617aa2007-07-12 12:51:34 +0200838 atomic_t force_alloc_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839};
840
841struct qeth_card_list_struct {
842 struct list_head list;
843 rwlock_t rwlock;
844};
845
846extern struct qeth_card_list_struct qeth_card_list;
847
848/*notifier list */
849struct qeth_notify_list_struct {
850 struct list_head list;
851 struct task_struct *task;
852 int signum;
853};
854extern spinlock_t qeth_notify_lock;
855extern struct list_head qeth_notify_list;
856
857/*some helper functions*/
858
859#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
860
Jesper Juhl77933d72005-07-27 11:46:09 -0700861static inline __u8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862qeth_get_ipa_adp_type(enum qeth_link_types link_type)
863{
864 switch (link_type) {
865 case QETH_LINK_TYPE_HSTR:
866 return 2;
867 default:
868 return 1;
869 }
870}
871
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200872static inline struct sk_buff *
873qeth_realloc_headroom(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200875 struct sk_buff *new_skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200877 if (skb_headroom(skb) >= size)
878 return skb;
879 new_skb = skb_realloc_headroom(skb, size);
880 if (!new_skb)
881 PRINT_ERR("Could not realloc headroom for qeth_hdr "
882 "on interface %s", QETH_CARD_IFNAME(card));
883 return new_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
Jesper Juhl77933d72005-07-27 11:46:09 -0700885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886static inline struct sk_buff *
Al Viro23f28002007-03-14 09:19:20 +0000887qeth_pskb_unshare(struct sk_buff *skb, gfp_t pri)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
889 struct sk_buff *nskb;
890 if (!skb_cloned(skb))
891 return skb;
892 nskb = skb_copy(skb, pri);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 return nskb;
894}
895
Jesper Juhl77933d72005-07-27 11:46:09 -0700896static inline void *
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200897qeth_push_skb(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 void *hdr;
900
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200901 hdr = (void *) skb_push(skb, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /*
903 * sanity check, the Linux memory allocation scheme should
904 * never present us cases like this one (the qdio header size plus
905 * the first 40 bytes of the paket cross a 4k boundary)
906 */
907 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
908 (((unsigned long) hdr + size +
909 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200910 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 QETH_CARD_IFNAME(card));
912 return NULL;
913 }
914 return hdr;
915}
916
Frank Pavlicd8011452005-05-12 20:37:53 +0200917
Jesper Juhl77933d72005-07-27 11:46:09 -0700918static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919qeth_get_hlen(__u8 link_type)
920{
921#ifdef CONFIG_QETH_IPV6
922 switch (link_type) {
923 case QETH_LINK_TYPE_HSTR:
924 case QETH_LINK_TYPE_LANE_TR:
Frank Pavlic05e08a22005-05-12 20:39:09 +0200925 return sizeof(struct qeth_hdr_tso) + TR_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 default:
927#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200928 return sizeof(struct qeth_hdr_tso) + VLAN_ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200930 return sizeof(struct qeth_hdr_tso) + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931#endif
932 }
933#else /* CONFIG_QETH_IPV6 */
934#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200935 return sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200937 return sizeof(struct qeth_hdr_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938#endif
939#endif /* CONFIG_QETH_IPV6 */
940}
941
Jesper Juhl77933d72005-07-27 11:46:09 -0700942static inline unsigned short
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943qeth_get_netdev_flags(struct qeth_card *card)
944{
Ursula Braun500f83a2005-09-30 10:19:19 +0200945 if (card->options.layer2 &&
946 (card->info.type == QETH_CARD_TYPE_OSAE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 return 0;
948 switch (card->info.type) {
949 case QETH_CARD_TYPE_IQD:
Jeff Garzike82b0f22006-05-26 21:58:38 -0400950 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 return IFF_NOARP;
952#ifdef CONFIG_QETH_IPV6
953 default:
954 return 0;
955#else
956 default:
957 return IFF_NOARP;
958#endif
959 }
960}
961
Jesper Juhl77933d72005-07-27 11:46:09 -0700962static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963qeth_get_initial_mtu_for_card(struct qeth_card * card)
964{
965 switch (card->info.type) {
966 case QETH_CARD_TYPE_UNKNOWN:
967 return 1500;
968 case QETH_CARD_TYPE_IQD:
969 return card->info.max_mtu;
970 case QETH_CARD_TYPE_OSAE:
971 switch (card->info.link_type) {
972 case QETH_LINK_TYPE_HSTR:
973 case QETH_LINK_TYPE_LANE_TR:
974 return 2000;
975 default:
976 return 1492;
977 }
978 default:
979 return 1500;
980 }
981}
982
Jesper Juhl77933d72005-07-27 11:46:09 -0700983static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984qeth_get_max_mtu_for_card(int cardtype)
985{
986 switch (cardtype) {
Jeff Garzike82b0f22006-05-26 21:58:38 -0400987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 case QETH_CARD_TYPE_UNKNOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +0200990 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return 61440;
992 case QETH_CARD_TYPE_IQD:
993 return 57344;
994 default:
995 return 1500;
996 }
997}
998
Jesper Juhl77933d72005-07-27 11:46:09 -0700999static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000qeth_get_mtu_out_of_mpc(int cardtype)
1001{
1002 switch (cardtype) {
1003 case QETH_CARD_TYPE_IQD:
1004 return 1;
1005 default:
1006 return 0;
1007 }
1008}
1009
Jesper Juhl77933d72005-07-27 11:46:09 -07001010static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011qeth_get_mtu_outof_framesize(int framesize)
1012{
1013 switch (framesize) {
1014 case 0x4000:
1015 return 8192;
1016 case 0x6000:
1017 return 16384;
1018 case 0xa000:
1019 return 32768;
1020 case 0xffff:
1021 return 57344;
1022 default:
1023 return 0;
1024 }
1025}
1026
Jesper Juhl77933d72005-07-27 11:46:09 -07001027static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1029{
1030 switch (card->info.type) {
1031 case QETH_CARD_TYPE_OSAE:
1032 return ((mtu >= 576) && (mtu <= 61440));
1033 case QETH_CARD_TYPE_IQD:
1034 return ((mtu >= 576) &&
1035 (mtu <= card->info.max_mtu + 4096 - 32));
Ursula Braun500f83a2005-09-30 10:19:19 +02001036 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 case QETH_CARD_TYPE_UNKNOWN:
1038 default:
1039 return 1;
1040 }
1041}
1042
Jesper Juhl77933d72005-07-27 11:46:09 -07001043static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044qeth_get_arphdr_type(int cardtype, int linktype)
1045{
1046 switch (cardtype) {
1047 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +02001048 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 switch (linktype) {
1050 case QETH_LINK_TYPE_LANE_TR:
1051 case QETH_LINK_TYPE_HSTR:
1052 return ARPHRD_IEEE802_TR;
1053 default:
1054 return ARPHRD_ETHER;
1055 }
1056 case QETH_CARD_TYPE_IQD:
1057 default:
1058 return ARPHRD_ETHER;
1059 }
1060}
1061
Jesper Juhl77933d72005-07-27 11:46:09 -07001062static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063qeth_get_micros(void)
1064{
1065 return (int) (get_clock() >> 12);
1066}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068static inline int
1069qeth_get_qdio_q_format(struct qeth_card *card)
1070{
1071 switch (card->info.type) {
1072 case QETH_CARD_TYPE_IQD:
1073 return 2;
1074 default:
1075 return 0;
1076 }
1077}
1078
Frank Pavlicbd389b92005-11-10 13:49:02 +01001079static inline int
Frank Pavlicbd389b92005-11-10 13:49:02 +01001080qeth_isxdigit(char * buf)
1081{
1082 while (*buf) {
1083 if (!isxdigit(*buf++))
1084 return 0;
1085 }
1086 return 1;
1087}
1088
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089static inline void
1090qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
1091{
1092 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
1093}
1094
1095static inline int
1096qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
1097{
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001098 int count = 0, rc = 0;
1099 int in[4];
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001100 char c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001102 rc = sscanf(buf, "%u.%u.%u.%u%c",
1103 &in[0], &in[1], &in[2], &in[3], &c);
1104 if (rc != 4 && (rc != 5 || c != '\n'))
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001105 return -EINVAL;
1106 for (count = 0; count < 4; count++) {
1107 if (in[count] > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001109 addr[count] = in[count];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 return 0;
1112}
1113
1114static inline void
1115qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
1116{
1117 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
1118 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
1119 addr[0], addr[1], addr[2], addr[3],
1120 addr[4], addr[5], addr[6], addr[7],
1121 addr[8], addr[9], addr[10], addr[11],
1122 addr[12], addr[13], addr[14], addr[15]);
1123}
1124
1125static inline int
1126qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1127{
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001128 const char *end, *end_tmp, *start;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001129 __u16 *in;
1130 char num[5];
1131 int num2, cnt, out, found, save_cnt;
1132 unsigned short in_tmp[8] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001134 cnt = out = found = save_cnt = num2 = 0;
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001135 end = start = buf;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001136 in = (__u16 *) addr;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001137 memset(in, 0, 16);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001138 while (*end) {
1139 end = strchr(start,':');
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001140 if (end == NULL) {
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001141 end = buf + strlen(buf);
1142 if ((end_tmp = strchr(start, '\n')) != NULL)
1143 end = end_tmp;
1144 out = 1;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001145 }
Jeff Garzike82b0f22006-05-26 21:58:38 -04001146 if ((end - start)) {
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001147 memset(num, 0, 5);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001148 if ((end - start) > 4)
1149 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001150 memcpy(num, start, end - start);
1151 if (!qeth_isxdigit(num))
1152 return -EINVAL;
1153 sscanf(start, "%x", &num2);
1154 if (found)
1155 in_tmp[save_cnt++] = num2;
1156 else
1157 in[cnt++] = num2;
1158 if (out)
1159 break;
1160 } else {
1161 if (found)
1162 return -EINVAL;
1163 found = 1;
Frank Pavlicbd389b92005-11-10 13:49:02 +01001164 }
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001165 start = ++end;
1166 }
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001167 if (cnt + save_cnt > 8)
1168 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001169 cnt = 7;
1170 while (save_cnt)
1171 in[cnt--] = in_tmp[--save_cnt];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return 0;
1173}
1174
1175static inline void
1176qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
1177 char *buf)
1178{
1179 if (proto == QETH_PROT_IPV4)
Heiko Carstensecee51b2007-08-29 11:26:54 +02001180 qeth_ipaddr4_to_string(addr, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 else if (proto == QETH_PROT_IPV6)
Heiko Carstensecee51b2007-08-29 11:26:54 +02001182 qeth_ipaddr6_to_string(addr, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
1185static inline int
1186qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
1187 __u8 *addr)
1188{
1189 if (proto == QETH_PROT_IPV4)
1190 return qeth_string_to_ipaddr4(buf, addr);
1191 else if (proto == QETH_PROT_IPV6)
1192 return qeth_string_to_ipaddr6(buf, addr);
1193 else
1194 return -EINVAL;
1195}
1196
1197extern int
1198qeth_setrouting_v4(struct qeth_card *);
1199extern int
1200qeth_setrouting_v6(struct qeth_card *);
1201
1202extern int
1203qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
1204
1205extern void
1206qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
1207
1208extern int
1209qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1210
1211extern void
1212qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1213
1214extern int
1215qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1216
1217extern void
1218qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1219
1220extern int
1221qeth_notifier_register(struct task_struct *, int );
1222
1223extern int
1224qeth_notifier_unregister(struct task_struct * );
1225
1226extern void
1227qeth_schedule_recovery(struct qeth_card *);
1228
1229extern int
1230qeth_realloc_buffer_pool(struct qeth_card *, int);
1231
1232extern int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02001233qeth_set_large_send(struct qeth_card *, enum qeth_large_send_types);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235extern void
1236qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
1237 struct sk_buff *, int, int);
1238extern void
1239qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
1240
Ursula Braun500f83a2005-09-30 10:19:19 +02001241extern int
1242qeth_osn_assist(struct net_device *, void *, int);
1243
1244extern int
1245qeth_osn_register(unsigned char *read_dev_no,
1246 struct net_device **,
1247 int (*assist_cb)(struct net_device *, void *),
1248 int (*data_cb)(struct sk_buff *));
1249
1250extern void
1251qeth_osn_deregister(struct net_device *);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253#endif /* __QETH_H__ */