blob: 821383d8cbe7f5828630d9c21935c53fe27108f1 [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
154#define atomic_swap(a,b) xchg((int *)a.counter, b)
155
156/*
157 * Common IO related definitions
158 */
159extern struct device *qeth_root_dev;
160extern struct ccw_driver qeth_ccw_driver;
161extern struct ccwgroup_driver qeth_ccwgroup_driver;
162
163#define CARD_RDEV(card) card->read.ccwdev
164#define CARD_WDEV(card) card->write.ccwdev
165#define CARD_DDEV(card) card->data.ccwdev
166#define CARD_BUS_ID(card) card->gdev->dev.bus_id
167#define CARD_RDEV_ID(card) card->read.ccwdev->dev.bus_id
168#define CARD_WDEV_ID(card) card->write.ccwdev->dev.bus_id
169#define CARD_DDEV_ID(card) card->data.ccwdev->dev.bus_id
170#define CHANNEL_ID(channel) channel->ccwdev->dev.bus_id
171
172#define CARD_FROM_CDEV(cdev) (struct qeth_card *) \
173 ((struct ccwgroup_device *)cdev->dev.driver_data)\
174 ->dev.driver_data;
175
176/**
177 * card stuff
178 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179struct qeth_perf_stats {
180 unsigned int bufs_rec;
181 unsigned int bufs_sent;
182
183 unsigned int skbs_sent_pack;
184 unsigned int bufs_sent_pack;
185
186 unsigned int sc_dp_p;
187 unsigned int sc_p_dp;
188 /* qdio_input_handler: number of times called, time spent in */
189 __u64 inbound_start_time;
190 unsigned int inbound_cnt;
191 unsigned int inbound_time;
192 /* qeth_send_packet: number of times called, time spent in */
193 __u64 outbound_start_time;
194 unsigned int outbound_cnt;
195 unsigned int outbound_time;
196 /* qdio_output_handler: number of times called, time spent in */
197 __u64 outbound_handler_start_time;
198 unsigned int outbound_handler_cnt;
199 unsigned int outbound_handler_time;
200 /* number of calls to and time spent in do_QDIO for inbound queue */
201 __u64 inbound_do_qdio_start_time;
202 unsigned int inbound_do_qdio_cnt;
203 unsigned int inbound_do_qdio_time;
204 /* number of calls to and time spent in do_QDIO for outbound queues */
205 __u64 outbound_do_qdio_start_time;
206 unsigned int outbound_do_qdio_cnt;
207 unsigned int outbound_do_qdio_time;
208 /* eddp data */
209 unsigned int large_send_bytes;
210 unsigned int large_send_cnt;
211 unsigned int sg_skbs_sent;
212 unsigned int sg_frags_sent;
Frank Pavlic09d2d382006-09-15 16:26:34 +0200213 /* initial values when measuring starts */
214 unsigned long initial_rx_packets;
215 unsigned long initial_tx_packets;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218/* Routing stuff */
219struct qeth_routing_info {
220 enum qeth_routing_types type;
221};
222
223/* IPA stuff */
224struct qeth_ipa_info {
225 __u32 supported_funcs;
226 __u32 enabled_funcs;
227};
228
229static inline int
230qeth_is_ipa_supported(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
231{
232 return (ipa->supported_funcs & func);
233}
234
235static inline int
236qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, enum qeth_ipa_funcs func)
237{
238 return (ipa->supported_funcs & ipa->enabled_funcs & func);
239}
240
241#define qeth_adp_supported(c,f) \
242 qeth_is_ipa_supported(&c->options.adp, f)
243#define qeth_adp_enabled(c,f) \
244 qeth_is_ipa_enabled(&c->options.adp, f)
245#define qeth_is_supported(c,f) \
246 qeth_is_ipa_supported(&c->options.ipa4, f)
247#define qeth_is_enabled(c,f) \
248 qeth_is_ipa_enabled(&c->options.ipa4, f)
249#ifdef CONFIG_QETH_IPV6
250#define qeth_is_supported6(c,f) \
251 qeth_is_ipa_supported(&c->options.ipa6, f)
252#define qeth_is_enabled6(c,f) \
253 qeth_is_ipa_enabled(&c->options.ipa6, f)
254#else /* CONFIG_QETH_IPV6 */
255#define qeth_is_supported6(c,f) 0
256#define qeth_is_enabled6(c,f) 0
257#endif /* CONFIG_QETH_IPV6 */
258#define qeth_is_ipafunc_supported(c,prot,f) \
259 (prot==QETH_PROT_IPV6)? qeth_is_supported6(c,f):qeth_is_supported(c,f)
260#define qeth_is_ipafunc_enabled(c,prot,f) \
261 (prot==QETH_PROT_IPV6)? qeth_is_enabled6(c,f):qeth_is_enabled(c,f)
262
263
264#define QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT 0x0101
265#define QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT 0x0101
266#define QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT 0x4108
267#define QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT 0x5108
268
269#define QETH_MODELLIST_ARRAY \
270 {{0x1731,0x01,0x1732,0x01,QETH_CARD_TYPE_OSAE,1, \
271 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
272 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
273 QETH_MAX_QUEUES,0}, \
274 {0x1731,0x05,0x1732,0x05,QETH_CARD_TYPE_IQD,0, \
275 QETH_IDX_FUNC_LEVEL_IQD_ENA_IPAT, \
276 QETH_IDX_FUNC_LEVEL_IQD_DIS_IPAT, \
277 QETH_MAX_QUEUES,0x103}, \
Ursula Braun500f83a2005-09-30 10:19:19 +0200278 {0x1731,0x06,0x1732,0x06,QETH_CARD_TYPE_OSN,0, \
279 QETH_IDX_FUNC_LEVEL_OSAE_ENA_IPAT, \
280 QETH_IDX_FUNC_LEVEL_OSAE_DIS_IPAT, \
281 QETH_MAX_QUEUES,0}, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 {0,0,0,0,0,0,0,0,0}}
283
284#define QETH_REAL_CARD 1
285#define QETH_VLAN_CARD 2
286#define QETH_BUFSIZE 4096
287
288/**
289 * some more defs
290 */
291#define IF_NAME_LEN 16
292#define QETH_TX_TIMEOUT 100 * HZ
293#define QETH_HEADER_SIZE 32
294#define MAX_PORTNO 15
Frank Pavlice23dd9c2005-05-12 20:38:11 +0200295#define QETH_FAKE_LL_LEN_ETH ETH_HLEN
296#define QETH_FAKE_LL_LEN_TR (sizeof(struct trh_hdr)-TR_MAXRIFLEN+sizeof(struct trllc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297#define QETH_FAKE_LL_V6_ADDR_POS 24
298
299/*IPv6 address autoconfiguration stuff*/
300#define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
301#define UNIQUE_ID_NOT_BY_CARD 0x10000
302
303/*****************************************************************************/
304/* QDIO queue and buffer handling */
305/*****************************************************************************/
306#define QETH_MAX_QUEUES 4
307#define QETH_IN_BUF_SIZE_DEFAULT 65536
308#define QETH_IN_BUF_COUNT_DEFAULT 16
309#define QETH_IN_BUF_COUNT_MIN 8
310#define QETH_IN_BUF_COUNT_MAX 128
311#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
312#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
313 ((card)->qdio.in_buf_pool.buf_count / 2)
314
315/* buffers we have to be behind before we get a PCI */
316#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
317/*enqueued free buffers left before we get a PCI*/
318#define QETH_PCI_THRESHOLD_B(card) 0
319/*not used unless the microcode gets patched*/
320#define QETH_PCI_TIMER_VALUE(card) 3
321
322#define QETH_MIN_INPUT_THRESHOLD 1
323#define QETH_MAX_INPUT_THRESHOLD 500
324#define QETH_MIN_OUTPUT_THRESHOLD 1
325#define QETH_MAX_OUTPUT_THRESHOLD 300
326
327/* priority queing */
328#define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
329#define QETH_DEFAULT_QUEUE 2
330#define QETH_NO_PRIO_QUEUEING 0
331#define QETH_PRIO_Q_ING_PREC 1
332#define QETH_PRIO_Q_ING_TOS 2
333#define IP_TOS_LOWDELAY 0x10
334#define IP_TOS_HIGHTHROUGHPUT 0x08
335#define IP_TOS_HIGHRELIABILITY 0x04
336#define IP_TOS_NOTIMPORTANT 0x02
337
338/* Packing */
339#define QETH_LOW_WATERMARK_PACK 2
340#define QETH_HIGH_WATERMARK_PACK 5
341#define QETH_WATERMARK_PACK_FUZZ 1
342
343#define QETH_IP_HEADER_SIZE 40
344
345struct qeth_hdr_layer3 {
346 __u8 id;
347 __u8 flags;
348 __u16 inbound_checksum; /*TSO:__u16 seqno */
349 __u32 token; /*TSO: __u32 reserved */
350 __u16 length;
351 __u8 vlan_prio;
352 __u8 ext_flags;
353 __u16 vlan_id;
354 __u16 frame_offset;
355 __u8 dest_addr[16];
356} __attribute__ ((packed));
357
358struct qeth_hdr_layer2 {
359 __u8 id;
360 __u8 flags[3];
361 __u8 port_no;
362 __u8 hdr_length;
363 __u16 pkt_length;
364 __u16 seq_no;
365 __u16 vlan_id;
366 __u32 reserved;
367 __u8 reserved2[16];
368} __attribute__ ((packed));
369
Ursula Braun500f83a2005-09-30 10:19:19 +0200370struct qeth_hdr_osn {
371 __u8 id;
372 __u8 reserved;
373 __u16 seq_no;
374 __u16 reserved2;
375 __u16 control_flags;
376 __u16 pdu_length;
377 __u8 reserved3[18];
378 __u32 ccid;
379} __attribute__ ((packed));
Jeff Garzike82b0f22006-05-26 21:58:38 -0400380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381struct qeth_hdr {
382 union {
383 struct qeth_hdr_layer2 l2;
384 struct qeth_hdr_layer3 l3;
Ursula Braun500f83a2005-09-30 10:19:19 +0200385 struct qeth_hdr_osn osn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 } hdr;
387} __attribute__ ((packed));
388
Frank Pavlic05e08a22005-05-12 20:39:09 +0200389/*TCP Segmentation Offload header*/
390struct qeth_hdr_ext_tso {
391 __u16 hdr_tot_len;
392 __u8 imb_hdr_no;
393 __u8 reserved;
394 __u8 hdr_type;
395 __u8 hdr_version;
396 __u16 hdr_len;
397 __u32 payload_len;
398 __u16 mss;
399 __u16 dg_hdr_len;
400 __u8 padding[16];
401} __attribute__ ((packed));
402
403struct qeth_hdr_tso {
404 struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
405 struct qeth_hdr_ext_tso ext;
406} __attribute__ ((packed));
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409/* flags for qeth_hdr.flags */
410#define QETH_HDR_PASSTHRU 0x10
411#define QETH_HDR_IPV6 0x80
412#define QETH_HDR_CAST_MASK 0x07
413enum qeth_cast_flags {
414 QETH_CAST_UNICAST = 0x06,
415 QETH_CAST_MULTICAST = 0x04,
416 QETH_CAST_BROADCAST = 0x05,
417 QETH_CAST_ANYCAST = 0x07,
418 QETH_CAST_NOCAST = 0x00,
419};
420
421enum qeth_layer2_frame_flags {
422 QETH_LAYER2_FLAG_MULTICAST = 0x01,
423 QETH_LAYER2_FLAG_BROADCAST = 0x02,
424 QETH_LAYER2_FLAG_UNICAST = 0x04,
425 QETH_LAYER2_FLAG_VLAN = 0x10,
426};
427
428enum qeth_header_ids {
429 QETH_HEADER_TYPE_LAYER3 = 0x01,
430 QETH_HEADER_TYPE_LAYER2 = 0x02,
431 QETH_HEADER_TYPE_TSO = 0x03,
Ursula Braun500f83a2005-09-30 10:19:19 +0200432 QETH_HEADER_TYPE_OSN = 0x04,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433};
434/* flags for qeth_hdr.ext_flags */
435#define QETH_HDR_EXT_VLAN_FRAME 0x01
436#define QETH_HDR_EXT_TOKEN_ID 0x02
437#define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
438#define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
439#define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
440#define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
441#define QETH_HDR_EXT_UDP_TSO 0x40 /*bit off for TCP*/
442
443static inline int
444qeth_is_last_sbale(struct qdio_buffer_element *sbale)
445{
446 return (sbale->flags & SBAL_FLAGS_LAST_ENTRY);
447}
448
449enum qeth_qdio_buffer_states {
450 /*
451 * inbound: read out by driver; owned by hardware in order to be filled
452 * outbound: owned by driver in order to be filled
453 */
454 QETH_QDIO_BUF_EMPTY,
455 /*
456 * inbound: filled by hardware; owned by driver in order to be read out
457 * outbound: filled by driver; owned by hardware in order to be sent
458 */
459 QETH_QDIO_BUF_PRIMED,
460};
461
462enum qeth_qdio_info_states {
463 QETH_QDIO_UNINITIALIZED,
464 QETH_QDIO_ALLOCATED,
465 QETH_QDIO_ESTABLISHED,
Frank Pavlicf956b692006-09-15 16:26:52 +0200466 QETH_QDIO_CLEANING
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467};
468
469struct qeth_buffer_pool_entry {
470 struct list_head list;
471 struct list_head init_list;
472 void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
473};
474
475struct qeth_qdio_buffer_pool {
476 struct list_head entry_list;
477 int buf_count;
478};
479
480struct qeth_qdio_buffer {
481 struct qdio_buffer *buffer;
482 volatile enum qeth_qdio_buffer_states state;
483 /* the buffer pool entry currently associated to this buffer */
484 struct qeth_buffer_pool_entry *pool_entry;
485};
486
487struct qeth_qdio_q {
488 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
489 struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
490 /*
491 * buf_to_init means "buffer must be initialized by driver and must
492 * be made available for hardware" -> state is set to EMPTY
493 */
494 volatile int next_buf_to_init;
495} __attribute__ ((aligned(256)));
496
497/* possible types of qeth large_send support */
498enum qeth_large_send_types {
499 QETH_LARGE_SEND_NO,
500 QETH_LARGE_SEND_EDDP,
501 QETH_LARGE_SEND_TSO,
502};
503
504struct qeth_qdio_out_buffer {
505 struct qdio_buffer *buffer;
506 atomic_t state;
507 volatile int next_element_to_fill;
508 struct sk_buff_head skb_list;
509 struct list_head ctx_list;
510};
511
512struct qeth_card;
513
514enum qeth_out_q_states {
515 QETH_OUT_Q_UNLOCKED,
516 QETH_OUT_Q_LOCKED,
517 QETH_OUT_Q_LOCKED_FLUSH,
518};
519
520struct qeth_qdio_out_q {
521 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
522 struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
523 int queue_no;
524 struct qeth_card *card;
525 atomic_t state;
526 volatile int do_pack;
527 /*
528 * index of buffer to be filled by driver; state EMPTY or PACKING
529 */
530 volatile int next_buf_to_fill;
531 /*
532 * number of buffers that are currently filled (PRIMED)
533 * -> these buffers are hardware-owned
534 */
535 atomic_t used_buffers;
536 /* indicates whether PCI flag must be set (or if one is outstanding) */
537 atomic_t set_pci_flags_count;
538} __attribute__ ((aligned(256)));
539
540struct qeth_qdio_info {
Frank Pavlicf956b692006-09-15 16:26:52 +0200541 atomic_t state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* input */
543 struct qeth_qdio_q *in_q;
544 struct qeth_qdio_buffer_pool in_buf_pool;
545 struct qeth_qdio_buffer_pool init_pool;
546 int in_buf_size;
547
548 /* output */
549 int no_out_queues;
550 struct qeth_qdio_out_q **out_qs;
551
552 /* priority queueing */
553 int do_prio_queueing;
554 int default_out_queue;
555};
556
557enum qeth_send_errors {
558 QETH_SEND_ERROR_NONE,
559 QETH_SEND_ERROR_LINK_FAILURE,
560 QETH_SEND_ERROR_RETRY,
561 QETH_SEND_ERROR_KICK_IT,
562};
563
564#define QETH_ETH_MAC_V4 0x0100 /* like v4 */
565#define QETH_ETH_MAC_V6 0x3333 /* like v6 */
566/* tr mc mac is longer, but that will be enough to detect mc frames */
567#define QETH_TR_MAC_NC 0xc000 /* non-canonical */
568#define QETH_TR_MAC_C 0x0300 /* canonical */
569
570#define DEFAULT_ADD_HHLEN 0
571#define MAX_ADD_HHLEN 1024
572
573/**
574 * buffer stuff for read channel
575 */
576#define QETH_CMD_BUFFER_NO 8
577
578/**
579 * channel state machine
580 */
581enum qeth_channel_states {
582 CH_STATE_UP,
583 CH_STATE_DOWN,
584 CH_STATE_ACTIVATING,
585 CH_STATE_HALTED,
586 CH_STATE_STOPPED,
587};
588/**
589 * card state machine
590 */
591enum qeth_card_states {
592 CARD_STATE_DOWN,
593 CARD_STATE_HARDSETUP,
594 CARD_STATE_SOFTSETUP,
595 CARD_STATE_UP,
596 CARD_STATE_RECOVER,
597};
598
599/**
600 * Protocol versions
601 */
602enum qeth_prot_versions {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 QETH_PROT_IPV4 = 0x0004,
604 QETH_PROT_IPV6 = 0x0006,
605};
606
607enum qeth_ip_types {
608 QETH_IP_TYPE_NORMAL,
609 QETH_IP_TYPE_VIPA,
610 QETH_IP_TYPE_RXIP,
611 QETH_IP_TYPE_DEL_ALL_MC,
612};
613
614enum qeth_cmd_buffer_state {
615 BUF_STATE_FREE,
616 BUF_STATE_LOCKED,
617 BUF_STATE_PROCESSED,
618};
619/**
620 * IP address and multicast list
621 */
622struct qeth_ipaddr {
623 struct list_head entry;
624 enum qeth_ip_types type;
625 enum qeth_ipa_setdelip_flags set_flags;
626 enum qeth_ipa_setdelip_flags del_flags;
627 int is_multicast;
628 volatile int users;
629 enum qeth_prot_versions proto;
630 unsigned char mac[OSA_ADDR_LEN];
631 union {
632 struct {
633 unsigned int addr;
634 unsigned int mask;
635 } a4;
636 struct {
637 struct in6_addr addr;
638 unsigned int pfxlen;
639 } a6;
640 } u;
641};
642
643struct qeth_ipato_entry {
644 struct list_head entry;
645 enum qeth_prot_versions proto;
646 char addr[16];
647 int mask_bits;
648};
649
650struct qeth_ipato {
651 int enabled;
652 int invert4;
653 int invert6;
654 struct list_head entries;
655};
656
657struct qeth_channel;
658
659struct qeth_cmd_buffer {
660 enum qeth_cmd_buffer_state state;
661 struct qeth_channel *channel;
662 unsigned char *data;
663 int rc;
664 void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
665};
666
667
668/**
669 * definition of a qeth channel, used for read and write
670 */
671struct qeth_channel {
672 enum qeth_channel_states state;
673 struct ccw1 ccw;
674 spinlock_t iob_lock;
675 wait_queue_head_t wait_q;
676 struct tasklet_struct irq_tasklet;
677 struct ccw_device *ccwdev;
678/*command buffer for control data*/
679 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
680 atomic_t irq_pending;
681 volatile int io_buf_no;
682 volatile int buf_no;
683};
684
685/**
686 * OSA card related definitions
687 */
688struct qeth_token {
689 __u32 issuer_rm_w;
690 __u32 issuer_rm_r;
691 __u32 cm_filter_w;
692 __u32 cm_filter_r;
693 __u32 cm_connection_w;
694 __u32 cm_connection_r;
695 __u32 ulp_filter_w;
696 __u32 ulp_filter_r;
697 __u32 ulp_connection_w;
698 __u32 ulp_connection_r;
699};
700
701struct qeth_seqno {
702 __u32 trans_hdr;
703 __u32 pdu_hdr;
704 __u32 pdu_hdr_ack;
705 __u16 ipa;
Ursula Braun9123e0d2005-09-30 10:17:24 +0200706 __u32 pkt_seqno;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707};
708
709struct qeth_reply {
710 struct list_head list;
711 wait_queue_head_t wait_q;
712 int (*callback)(struct qeth_card *,struct qeth_reply *,unsigned long);
713 u32 seqno;
714 unsigned long offset;
715 int received;
716 int rc;
717 void *param;
718 struct qeth_card *card;
719 atomic_t refcnt;
720};
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723struct qeth_card_blkt {
724 int time_total;
725 int inter_packet;
726 int inter_packet_jumbo;
727};
728
Frank Pavlice08d88c2005-11-10 13:51:17 +0100729#define QETH_BROADCAST_WITH_ECHO 0x01
730#define QETH_BROADCAST_WITHOUT_ECHO 0x02
731#define QETH_LAYER2_MAC_READ 0x01
732#define QETH_LAYER2_MAC_REGISTERED 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733struct qeth_card_info {
734 unsigned short unit_addr2;
735 unsigned short cula;
736 unsigned short chpid;
737 __u16 func_level;
738 char mcl_level[QETH_MCL_LENGTH + 1];
739 int guestlan;
Frank Pavlice08d88c2005-11-10 13:51:17 +0100740 int mac_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 int portname_required;
742 int portno;
743 char portname[9];
744 enum qeth_card_types type;
745 enum qeth_link_types link_type;
746 int is_multicast_different;
747 int initial_mtu;
748 int max_mtu;
749 int broadcast_capable;
750 int unique_id;
751 struct qeth_card_blkt blkt;
752 __u32 csum_mask;
Frank Pavlic6c951b92005-11-10 13:51:25 +0100753 enum qeth_ipa_promisc_modes promisc_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754};
755
756struct qeth_card_options {
757 struct qeth_routing_info route4;
758 struct qeth_ipa_info ipa4;
759 struct qeth_ipa_info adp; /*Adapter parameters*/
760#ifdef CONFIG_QETH_IPV6
761 struct qeth_routing_info route6;
762 struct qeth_ipa_info ipa6;
763#endif /* QETH_IPV6 */
764 enum qeth_checksum_types checksum_type;
765 int broadcast_mode;
766 int macaddr_mode;
767 int fake_broadcast;
768 int add_hhlen;
769 int fake_ll;
770 int layer2;
771 enum qeth_large_send_types large_send;
Frank Pavlic09d2d382006-09-15 16:26:34 +0200772 int performance_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773};
774
775/*
776 * thread bits for qeth_card thread masks
777 */
778enum qeth_threads {
779 QETH_SET_IP_THREAD = 1,
780 QETH_RECOVER_THREAD = 2,
Frank Pavlic6c951b92005-11-10 13:51:25 +0100781 QETH_SET_PROMISC_MODE_THREAD = 4,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782};
783
Ursula Braun500f83a2005-09-30 10:19:19 +0200784struct qeth_osn_info {
785 int (*assist_cb)(struct net_device *dev, void *data);
786 int (*data_cb)(struct sk_buff *skb);
787};
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789struct qeth_card {
790 struct list_head list;
791 enum qeth_card_states state;
792 int lan_online;
793 spinlock_t lock;
794/*hardware and sysfs stuff*/
795 struct ccwgroup_device *gdev;
796 struct qeth_channel read;
797 struct qeth_channel write;
798 struct qeth_channel data;
799
800 struct net_device *dev;
801 struct net_device_stats stats;
802
803 struct qeth_card_info info;
804 struct qeth_token token;
805 struct qeth_seqno seqno;
806 struct qeth_card_options options;
807
808 wait_queue_head_t wait_q;
809#ifdef CONFIG_QETH_VLAN
810 spinlock_t vlanlock;
811 struct vlan_group *vlangrp;
812#endif
813 struct work_struct kernel_thread_starter;
814 spinlock_t thread_mask_lock;
815 volatile unsigned long thread_start_mask;
816 volatile unsigned long thread_allowed_mask;
817 volatile unsigned long thread_running_mask;
818 spinlock_t ip_lock;
819 struct list_head ip_list;
820 struct list_head *ip_tbd_list;
821 struct qeth_ipato ipato;
822 struct list_head cmd_waiter_list;
823 /* QDIO buffer handling */
824 struct qeth_qdio_info qdio;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 struct qeth_perf_stats perf_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 int use_hard_stop;
827 int (*orig_hard_header)(struct sk_buff *,struct net_device *,
828 unsigned short,void *,void *,unsigned);
Jeff Garzike82b0f22006-05-26 21:58:38 -0400829 struct qeth_osn_info osn_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830};
831
832struct qeth_card_list_struct {
833 struct list_head list;
834 rwlock_t rwlock;
835};
836
837extern struct qeth_card_list_struct qeth_card_list;
838
839/*notifier list */
840struct qeth_notify_list_struct {
841 struct list_head list;
842 struct task_struct *task;
843 int signum;
844};
845extern spinlock_t qeth_notify_lock;
846extern struct list_head qeth_notify_list;
847
848/*some helper functions*/
849
850#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
851
Jesper Juhl77933d72005-07-27 11:46:09 -0700852static inline __u8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853qeth_get_ipa_adp_type(enum qeth_link_types link_type)
854{
855 switch (link_type) {
856 case QETH_LINK_TYPE_HSTR:
857 return 2;
858 default:
859 return 1;
860 }
861}
862
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200863static inline struct sk_buff *
864qeth_realloc_headroom(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200866 struct sk_buff *new_skb = skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200868 if (skb_headroom(skb) >= size)
869 return skb;
870 new_skb = skb_realloc_headroom(skb, size);
871 if (!new_skb)
872 PRINT_ERR("Could not realloc headroom for qeth_hdr "
873 "on interface %s", QETH_CARD_IFNAME(card));
874 return new_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875}
Jesper Juhl77933d72005-07-27 11:46:09 -0700876
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877static inline struct sk_buff *
878qeth_pskb_unshare(struct sk_buff *skb, int pri)
879{
880 struct sk_buff *nskb;
881 if (!skb_cloned(skb))
882 return skb;
883 nskb = skb_copy(skb, pri);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return nskb;
885}
886
Jesper Juhl77933d72005-07-27 11:46:09 -0700887static inline void *
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200888qeth_push_skb(struct qeth_card *card, struct sk_buff *skb, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
890 void *hdr;
891
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200892 hdr = (void *) skb_push(skb, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 /*
894 * sanity check, the Linux memory allocation scheme should
895 * never present us cases like this one (the qdio header size plus
896 * the first 40 bytes of the paket cross a 4k boundary)
897 */
898 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
899 (((unsigned long) hdr + size +
900 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
Frank Pavlicf7b65d72006-09-15 16:26:19 +0200901 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 QETH_CARD_IFNAME(card));
903 return NULL;
904 }
905 return hdr;
906}
907
Frank Pavlicd8011452005-05-12 20:37:53 +0200908
Jesper Juhl77933d72005-07-27 11:46:09 -0700909static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910qeth_get_hlen(__u8 link_type)
911{
912#ifdef CONFIG_QETH_IPV6
913 switch (link_type) {
914 case QETH_LINK_TYPE_HSTR:
915 case QETH_LINK_TYPE_LANE_TR:
Frank Pavlic05e08a22005-05-12 20:39:09 +0200916 return sizeof(struct qeth_hdr_tso) + TR_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 default:
918#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200919 return sizeof(struct qeth_hdr_tso) + VLAN_ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200921 return sizeof(struct qeth_hdr_tso) + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#endif
923 }
924#else /* CONFIG_QETH_IPV6 */
925#ifdef CONFIG_QETH_VLAN
Frank Pavlic05e08a22005-05-12 20:39:09 +0200926 return sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927#else
Frank Pavlic05e08a22005-05-12 20:39:09 +0200928 return sizeof(struct qeth_hdr_tso);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929#endif
930#endif /* CONFIG_QETH_IPV6 */
931}
932
Jesper Juhl77933d72005-07-27 11:46:09 -0700933static inline unsigned short
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934qeth_get_netdev_flags(struct qeth_card *card)
935{
Ursula Braun500f83a2005-09-30 10:19:19 +0200936 if (card->options.layer2 &&
937 (card->info.type == QETH_CARD_TYPE_OSAE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return 0;
939 switch (card->info.type) {
940 case QETH_CARD_TYPE_IQD:
Jeff Garzike82b0f22006-05-26 21:58:38 -0400941 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 return IFF_NOARP;
943#ifdef CONFIG_QETH_IPV6
944 default:
945 return 0;
946#else
947 default:
948 return IFF_NOARP;
949#endif
950 }
951}
952
Jesper Juhl77933d72005-07-27 11:46:09 -0700953static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954qeth_get_initial_mtu_for_card(struct qeth_card * card)
955{
956 switch (card->info.type) {
957 case QETH_CARD_TYPE_UNKNOWN:
958 return 1500;
959 case QETH_CARD_TYPE_IQD:
960 return card->info.max_mtu;
961 case QETH_CARD_TYPE_OSAE:
962 switch (card->info.link_type) {
963 case QETH_LINK_TYPE_HSTR:
964 case QETH_LINK_TYPE_LANE_TR:
965 return 2000;
966 default:
967 return 1492;
968 }
969 default:
970 return 1500;
971 }
972}
973
Jesper Juhl77933d72005-07-27 11:46:09 -0700974static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975qeth_get_max_mtu_for_card(int cardtype)
976{
977 switch (cardtype) {
Jeff Garzike82b0f22006-05-26 21:58:38 -0400978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 case QETH_CARD_TYPE_UNKNOWN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +0200981 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 return 61440;
983 case QETH_CARD_TYPE_IQD:
984 return 57344;
985 default:
986 return 1500;
987 }
988}
989
Jesper Juhl77933d72005-07-27 11:46:09 -0700990static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991qeth_get_mtu_out_of_mpc(int cardtype)
992{
993 switch (cardtype) {
994 case QETH_CARD_TYPE_IQD:
995 return 1;
996 default:
997 return 0;
998 }
999}
1000
Jesper Juhl77933d72005-07-27 11:46:09 -07001001static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002qeth_get_mtu_outof_framesize(int framesize)
1003{
1004 switch (framesize) {
1005 case 0x4000:
1006 return 8192;
1007 case 0x6000:
1008 return 16384;
1009 case 0xa000:
1010 return 32768;
1011 case 0xffff:
1012 return 57344;
1013 default:
1014 return 0;
1015 }
1016}
1017
Jesper Juhl77933d72005-07-27 11:46:09 -07001018static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019qeth_mtu_is_valid(struct qeth_card * card, int mtu)
1020{
1021 switch (card->info.type) {
1022 case QETH_CARD_TYPE_OSAE:
1023 return ((mtu >= 576) && (mtu <= 61440));
1024 case QETH_CARD_TYPE_IQD:
1025 return ((mtu >= 576) &&
1026 (mtu <= card->info.max_mtu + 4096 - 32));
Ursula Braun500f83a2005-09-30 10:19:19 +02001027 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 case QETH_CARD_TYPE_UNKNOWN:
1029 default:
1030 return 1;
1031 }
1032}
1033
Jesper Juhl77933d72005-07-27 11:46:09 -07001034static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035qeth_get_arphdr_type(int cardtype, int linktype)
1036{
1037 switch (cardtype) {
1038 case QETH_CARD_TYPE_OSAE:
Ursula Braun500f83a2005-09-30 10:19:19 +02001039 case QETH_CARD_TYPE_OSN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 switch (linktype) {
1041 case QETH_LINK_TYPE_LANE_TR:
1042 case QETH_LINK_TYPE_HSTR:
1043 return ARPHRD_IEEE802_TR;
1044 default:
1045 return ARPHRD_ETHER;
1046 }
1047 case QETH_CARD_TYPE_IQD:
1048 default:
1049 return ARPHRD_ETHER;
1050 }
1051}
1052
Jesper Juhl77933d72005-07-27 11:46:09 -07001053static inline int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054qeth_get_micros(void)
1055{
1056 return (int) (get_clock() >> 12);
1057}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059static inline int
1060qeth_get_qdio_q_format(struct qeth_card *card)
1061{
1062 switch (card->info.type) {
1063 case QETH_CARD_TYPE_IQD:
1064 return 2;
1065 default:
1066 return 0;
1067 }
1068}
1069
Frank Pavlicbd389b92005-11-10 13:49:02 +01001070static inline int
Frank Pavlicbd389b92005-11-10 13:49:02 +01001071qeth_isxdigit(char * buf)
1072{
1073 while (*buf) {
1074 if (!isxdigit(*buf++))
1075 return 0;
1076 }
1077 return 1;
1078}
1079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080static inline void
1081qeth_ipaddr4_to_string(const __u8 *addr, char *buf)
1082{
1083 sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]);
1084}
1085
1086static inline int
1087qeth_string_to_ipaddr4(const char *buf, __u8 *addr)
1088{
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001089 int count = 0, rc = 0;
1090 int in[4];
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001091 char c;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001093 rc = sscanf(buf, "%u.%u.%u.%u%c",
1094 &in[0], &in[1], &in[2], &in[3], &c);
1095 if (rc != 4 && (rc != 5 || c != '\n'))
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001096 return -EINVAL;
1097 for (count = 0; count < 4; count++) {
1098 if (in[count] > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001100 addr[count] = in[count];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 return 0;
1103}
1104
1105static inline void
1106qeth_ipaddr6_to_string(const __u8 *addr, char *buf)
1107{
1108 sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x"
1109 ":%02x%02x:%02x%02x:%02x%02x:%02x%02x",
1110 addr[0], addr[1], addr[2], addr[3],
1111 addr[4], addr[5], addr[6], addr[7],
1112 addr[8], addr[9], addr[10], addr[11],
1113 addr[12], addr[13], addr[14], addr[15]);
1114}
1115
1116static inline int
1117qeth_string_to_ipaddr6(const char *buf, __u8 *addr)
1118{
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001119 const char *end, *end_tmp, *start;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001120 __u16 *in;
1121 char num[5];
1122 int num2, cnt, out, found, save_cnt;
1123 unsigned short in_tmp[8] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001125 cnt = out = found = save_cnt = num2 = 0;
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001126 end = start = buf;
Jeff Garzike82b0f22006-05-26 21:58:38 -04001127 in = (__u16 *) addr;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001128 memset(in, 0, 16);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001129 while (*end) {
1130 end = strchr(start,':');
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001131 if (end == NULL) {
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001132 end = buf + strlen(buf);
1133 if ((end_tmp = strchr(start, '\n')) != NULL)
1134 end = end_tmp;
1135 out = 1;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001136 }
Jeff Garzike82b0f22006-05-26 21:58:38 -04001137 if ((end - start)) {
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001138 memset(num, 0, 5);
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001139 if ((end - start) > 4)
1140 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001141 memcpy(num, start, end - start);
1142 if (!qeth_isxdigit(num))
1143 return -EINVAL;
1144 sscanf(start, "%x", &num2);
1145 if (found)
1146 in_tmp[save_cnt++] = num2;
1147 else
1148 in[cnt++] = num2;
1149 if (out)
1150 break;
1151 } else {
1152 if (found)
1153 return -EINVAL;
1154 found = 1;
Frank Pavlicbd389b92005-11-10 13:49:02 +01001155 }
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001156 start = ++end;
1157 }
Frank Pavlic1fda1a12006-09-15 16:26:07 +02001158 if (cnt + save_cnt > 8)
1159 return -EINVAL;
Frank Pavlic66cc5d52006-02-07 17:04:38 +01001160 cnt = 7;
1161 while (save_cnt)
1162 in[cnt--] = in_tmp[--save_cnt];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 return 0;
1164}
1165
1166static inline void
1167qeth_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr,
1168 char *buf)
1169{
1170 if (proto == QETH_PROT_IPV4)
1171 return qeth_ipaddr4_to_string(addr, buf);
1172 else if (proto == QETH_PROT_IPV6)
1173 return qeth_ipaddr6_to_string(addr, buf);
1174}
1175
1176static inline int
1177qeth_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto,
1178 __u8 *addr)
1179{
1180 if (proto == QETH_PROT_IPV4)
1181 return qeth_string_to_ipaddr4(buf, addr);
1182 else if (proto == QETH_PROT_IPV6)
1183 return qeth_string_to_ipaddr6(buf, addr);
1184 else
1185 return -EINVAL;
1186}
1187
1188extern int
1189qeth_setrouting_v4(struct qeth_card *);
1190extern int
1191qeth_setrouting_v6(struct qeth_card *);
1192
1193extern int
1194qeth_add_ipato_entry(struct qeth_card *, struct qeth_ipato_entry *);
1195
1196extern void
1197qeth_del_ipato_entry(struct qeth_card *, enum qeth_prot_versions, u8 *, int);
1198
1199extern int
1200qeth_add_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1201
1202extern void
1203qeth_del_vipa(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1204
1205extern int
1206qeth_add_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1207
1208extern void
1209qeth_del_rxip(struct qeth_card *, enum qeth_prot_versions, const u8 *);
1210
1211extern int
1212qeth_notifier_register(struct task_struct *, int );
1213
1214extern int
1215qeth_notifier_unregister(struct task_struct * );
1216
1217extern void
1218qeth_schedule_recovery(struct qeth_card *);
1219
1220extern int
1221qeth_realloc_buffer_pool(struct qeth_card *, int);
1222
1223extern int
Frank Pavlic9cb90de2005-09-14 18:03:26 +02001224qeth_set_large_send(struct qeth_card *, enum qeth_large_send_types);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
1226extern void
1227qeth_fill_header(struct qeth_card *, struct qeth_hdr *,
1228 struct sk_buff *, int, int);
1229extern void
1230qeth_flush_buffers(struct qeth_qdio_out_q *, int, int, int);
1231
Ursula Braun500f83a2005-09-30 10:19:19 +02001232extern int
1233qeth_osn_assist(struct net_device *, void *, int);
1234
1235extern int
1236qeth_osn_register(unsigned char *read_dev_no,
1237 struct net_device **,
1238 int (*assist_cb)(struct net_device *, void *),
1239 int (*data_cb)(struct sk_buff *));
1240
1241extern void
1242qeth_osn_deregister(struct net_device *);
Jeff Garzike82b0f22006-05-26 21:58:38 -04001243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244#endif /* __QETH_H__ */