Loading...
1/*
2 * drivers/s390/net/qeth_core.h
3 *
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 */
10
11#ifndef __QETH_CORE_H__
12#define __QETH_CORE_H__
13
14#include <linux/if.h>
15#include <linux/if_arp.h>
16#include <linux/if_tr.h>
17#include <linux/trdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/if_vlan.h>
20#include <linux/ctype.h>
21#include <linux/in6.h>
22#include <linux/bitops.h>
23#include <linux/seq_file.h>
24#include <linux/ethtool.h>
25
26#include <net/ipv6.h>
27#include <net/if_inet6.h>
28#include <net/addrconf.h>
29
30#include <asm/debug.h>
31#include <asm/qdio.h>
32#include <asm/ccwdev.h>
33#include <asm/ccwgroup.h>
34#include <asm/sysinfo.h>
35
36#include "qeth_core_mpc.h"
37
38/**
39 * Debug Facility stuff
40 */
41enum qeth_dbf_names {
42 QETH_DBF_SETUP,
43 QETH_DBF_MSG,
44 QETH_DBF_CTRL,
45 QETH_DBF_INFOS /* must be last element */
46};
47
48struct qeth_dbf_info {
49 char name[DEBUG_MAX_NAME_LEN];
50 int pages;
51 int areas;
52 int len;
53 int level;
54 struct debug_view *view;
55 debug_info_t *id;
56};
57
58#define QETH_DBF_CTRL_LEN 256
59
60#define QETH_DBF_TEXT(name, level, text) \
61 debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
62
63#define QETH_DBF_HEX(name, level, addr, len) \
64 debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
65
66#define QETH_DBF_MESSAGE(level, text...) \
67 debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
68
69#define QETH_DBF_TEXT_(name, level, text...) \
70 qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
71
72#define QETH_CARD_TEXT(card, level, text) \
73 debug_text_event(card->debug, level, text)
74
75#define QETH_CARD_HEX(card, level, addr, len) \
76 debug_event(card->debug, level, (void *)(addr), len)
77
78#define QETH_CARD_MESSAGE(card, text...) \
79 debug_sprintf_event(card->debug, level, text)
80
81#define QETH_CARD_TEXT_(card, level, text...) \
82 qeth_dbf_longtext(card->debug, level, text)
83
84#define SENSE_COMMAND_REJECT_BYTE 0
85#define SENSE_COMMAND_REJECT_FLAG 0x80
86#define SENSE_RESETTING_EVENT_BYTE 1
87#define SENSE_RESETTING_EVENT_FLAG 0x80
88
89/*
90 * Common IO related definitions
91 */
92#define CARD_RDEV(card) card->read.ccwdev
93#define CARD_WDEV(card) card->write.ccwdev
94#define CARD_DDEV(card) card->data.ccwdev
95#define CARD_BUS_ID(card) dev_name(&card->gdev->dev)
96#define CARD_RDEV_ID(card) dev_name(&card->read.ccwdev->dev)
97#define CARD_WDEV_ID(card) dev_name(&card->write.ccwdev->dev)
98#define CARD_DDEV_ID(card) dev_name(&card->data.ccwdev->dev)
99#define CHANNEL_ID(channel) dev_name(&channel->ccwdev->dev)
100
101/**
102 * card stuff
103 */
104struct qeth_perf_stats {
105 unsigned int bufs_rec;
106 unsigned int bufs_sent;
107
108 unsigned int skbs_sent_pack;
109 unsigned int bufs_sent_pack;
110
111 unsigned int sc_dp_p;
112 unsigned int sc_p_dp;
113 /* qdio_input_handler: number of times called, time spent in */
114 __u64 inbound_start_time;
115 unsigned int inbound_cnt;
116 unsigned int inbound_time;
117 /* qeth_send_packet: number of times called, time spent in */
118 __u64 outbound_start_time;
119 unsigned int outbound_cnt;
120 unsigned int outbound_time;
121 /* qdio_output_handler: number of times called, time spent in */
122 __u64 outbound_handler_start_time;
123 unsigned int outbound_handler_cnt;
124 unsigned int outbound_handler_time;
125 /* number of calls to and time spent in do_QDIO for inbound queue */
126 __u64 inbound_do_qdio_start_time;
127 unsigned int inbound_do_qdio_cnt;
128 unsigned int inbound_do_qdio_time;
129 /* number of calls to and time spent in do_QDIO for outbound queues */
130 __u64 outbound_do_qdio_start_time;
131 unsigned int outbound_do_qdio_cnt;
132 unsigned int outbound_do_qdio_time;
133 unsigned int large_send_bytes;
134 unsigned int large_send_cnt;
135 unsigned int sg_skbs_sent;
136 unsigned int sg_frags_sent;
137 /* initial values when measuring starts */
138 unsigned long initial_rx_packets;
139 unsigned long initial_tx_packets;
140 /* inbound scatter gather data */
141 unsigned int sg_skbs_rx;
142 unsigned int sg_frags_rx;
143 unsigned int sg_alloc_page_rx;
144 unsigned int tx_csum;
145 unsigned int tx_lin;
146};
147
148/* Routing stuff */
149struct qeth_routing_info {
150 enum qeth_routing_types type;
151};
152
153/* IPA stuff */
154struct qeth_ipa_info {
155 __u32 supported_funcs;
156 __u32 enabled_funcs;
157};
158
159static inline int qeth_is_ipa_supported(struct qeth_ipa_info *ipa,
160 enum qeth_ipa_funcs func)
161{
162 return (ipa->supported_funcs & func);
163}
164
165static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
166 enum qeth_ipa_funcs func)
167{
168 return (ipa->supported_funcs & ipa->enabled_funcs & func);
169}
170
171#define qeth_adp_supported(c, f) \
172 qeth_is_ipa_supported(&c->options.adp, f)
173#define qeth_adp_enabled(c, f) \
174 qeth_is_ipa_enabled(&c->options.adp, f)
175#define qeth_is_supported(c, f) \
176 qeth_is_ipa_supported(&c->options.ipa4, f)
177#define qeth_is_enabled(c, f) \
178 qeth_is_ipa_enabled(&c->options.ipa4, f)
179#define qeth_is_supported6(c, f) \
180 qeth_is_ipa_supported(&c->options.ipa6, f)
181#define qeth_is_enabled6(c, f) \
182 qeth_is_ipa_enabled(&c->options.ipa6, f)
183#define qeth_is_ipafunc_supported(c, prot, f) \
184 ((prot == QETH_PROT_IPV6) ? \
185 qeth_is_supported6(c, f) : qeth_is_supported(c, f))
186#define qeth_is_ipafunc_enabled(c, prot, f) \
187 ((prot == QETH_PROT_IPV6) ? \
188 qeth_is_enabled6(c, f) : qeth_is_enabled(c, f))
189
190#define QETH_IDX_FUNC_LEVEL_OSD 0x0101
191#define QETH_IDX_FUNC_LEVEL_IQD 0x4108
192
193#define QETH_MODELLIST_ARRAY \
194 {{0x1731, 0x01, 0x1732, QETH_CARD_TYPE_OSD, QETH_MAX_QUEUES, 0}, \
195 {0x1731, 0x05, 0x1732, QETH_CARD_TYPE_IQD, QETH_MAX_QUEUES, 0x103}, \
196 {0x1731, 0x06, 0x1732, QETH_CARD_TYPE_OSN, QETH_MAX_QUEUES, 0}, \
197 {0x1731, 0x02, 0x1732, QETH_CARD_TYPE_OSM, QETH_MAX_QUEUES, 0}, \
198 {0x1731, 0x02, 0x1732, QETH_CARD_TYPE_OSX, QETH_MAX_QUEUES, 0}, \
199 {0, 0, 0, 0, 0, 0} }
200#define QETH_CU_TYPE_IND 0
201#define QETH_CU_MODEL_IND 1
202#define QETH_DEV_TYPE_IND 2
203#define QETH_DEV_MODEL_IND 3
204#define QETH_QUEUE_NO_IND 4
205#define QETH_MULTICAST_IND 5
206
207#define QETH_REAL_CARD 1
208#define QETH_VLAN_CARD 2
209#define QETH_BUFSIZE 4096
210
211/**
212 * some more defs
213 */
214#define QETH_TX_TIMEOUT 100 * HZ
215#define QETH_RCD_TIMEOUT 60 * HZ
216#define QETH_HEADER_SIZE 32
217#define QETH_MAX_PORTNO 15
218
219/*IPv6 address autoconfiguration stuff*/
220#define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
221#define UNIQUE_ID_NOT_BY_CARD 0x10000
222
223/*****************************************************************************/
224/* QDIO queue and buffer handling */
225/*****************************************************************************/
226#define QETH_MAX_QUEUES 4
227#define QETH_IN_BUF_SIZE_DEFAULT 65536
228#define QETH_IN_BUF_COUNT_DEFAULT 64
229#define QETH_IN_BUF_COUNT_HSDEFAULT 128
230#define QETH_IN_BUF_COUNT_MIN 8
231#define QETH_IN_BUF_COUNT_MAX 128
232#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
233#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
234 ((card)->qdio.in_buf_pool.buf_count / 2)
235
236/* buffers we have to be behind before we get a PCI */
237#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
238/*enqueued free buffers left before we get a PCI*/
239#define QETH_PCI_THRESHOLD_B(card) 0
240/*not used unless the microcode gets patched*/
241#define QETH_PCI_TIMER_VALUE(card) 3
242
243/* priority queing */
244#define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
245#define QETH_DEFAULT_QUEUE 2
246#define QETH_NO_PRIO_QUEUEING 0
247#define QETH_PRIO_Q_ING_PREC 1
248#define QETH_PRIO_Q_ING_TOS 2
249#define IP_TOS_LOWDELAY 0x10
250#define IP_TOS_HIGHTHROUGHPUT 0x08
251#define IP_TOS_HIGHRELIABILITY 0x04
252#define IP_TOS_NOTIMPORTANT 0x02
253
254/* Packing */
255#define QETH_LOW_WATERMARK_PACK 2
256#define QETH_HIGH_WATERMARK_PACK 5
257#define QETH_WATERMARK_PACK_FUZZ 1
258
259#define QETH_IP_HEADER_SIZE 40
260
261/* large receive scatter gather copy break */
262#define QETH_RX_SG_CB (PAGE_SIZE >> 1)
263
264struct qeth_hdr_layer3 {
265 __u8 id;
266 __u8 flags;
267 __u16 inbound_checksum; /*TSO:__u16 seqno */
268 __u32 token; /*TSO: __u32 reserved */
269 __u16 length;
270 __u8 vlan_prio;
271 __u8 ext_flags;
272 __u16 vlan_id;
273 __u16 frame_offset;
274 __u8 dest_addr[16];
275} __attribute__ ((packed));
276
277struct qeth_hdr_layer2 {
278 __u8 id;
279 __u8 flags[3];
280 __u8 port_no;
281 __u8 hdr_length;
282 __u16 pkt_length;
283 __u16 seq_no;
284 __u16 vlan_id;
285 __u32 reserved;
286 __u8 reserved2[16];
287} __attribute__ ((packed));
288
289struct qeth_hdr_osn {
290 __u8 id;
291 __u8 reserved;
292 __u16 seq_no;
293 __u16 reserved2;
294 __u16 control_flags;
295 __u16 pdu_length;
296 __u8 reserved3[18];
297 __u32 ccid;
298} __attribute__ ((packed));
299
300struct qeth_hdr {
301 union {
302 struct qeth_hdr_layer2 l2;
303 struct qeth_hdr_layer3 l3;
304 struct qeth_hdr_osn osn;
305 } hdr;
306} __attribute__ ((packed));
307
308/*TCP Segmentation Offload header*/
309struct qeth_hdr_ext_tso {
310 __u16 hdr_tot_len;
311 __u8 imb_hdr_no;
312 __u8 reserved;
313 __u8 hdr_type;
314 __u8 hdr_version;
315 __u16 hdr_len;
316 __u32 payload_len;
317 __u16 mss;
318 __u16 dg_hdr_len;
319 __u8 padding[16];
320} __attribute__ ((packed));
321
322struct qeth_hdr_tso {
323 struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
324 struct qeth_hdr_ext_tso ext;
325} __attribute__ ((packed));
326
327
328/* flags for qeth_hdr.flags */
329#define QETH_HDR_PASSTHRU 0x10
330#define QETH_HDR_IPV6 0x80
331#define QETH_HDR_CAST_MASK 0x07
332enum qeth_cast_flags {
333 QETH_CAST_UNICAST = 0x06,
334 QETH_CAST_MULTICAST = 0x04,
335 QETH_CAST_BROADCAST = 0x05,
336 QETH_CAST_ANYCAST = 0x07,
337 QETH_CAST_NOCAST = 0x00,
338};
339
340enum qeth_layer2_frame_flags {
341 QETH_LAYER2_FLAG_MULTICAST = 0x01,
342 QETH_LAYER2_FLAG_BROADCAST = 0x02,
343 QETH_LAYER2_FLAG_UNICAST = 0x04,
344 QETH_LAYER2_FLAG_VLAN = 0x10,
345};
346
347enum qeth_header_ids {
348 QETH_HEADER_TYPE_LAYER3 = 0x01,
349 QETH_HEADER_TYPE_LAYER2 = 0x02,
350 QETH_HEADER_TYPE_TSO = 0x03,
351 QETH_HEADER_TYPE_OSN = 0x04,
352};
353/* flags for qeth_hdr.ext_flags */
354#define QETH_HDR_EXT_VLAN_FRAME 0x01
355#define QETH_HDR_EXT_TOKEN_ID 0x02
356#define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
357#define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
358#define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
359#define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
360#define QETH_HDR_EXT_UDP 0x40 /*bit off for TCP*/
361
362static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
363{
364 return (sbale->eflags & SBAL_EFLAGS_LAST_ENTRY);
365}
366
367enum qeth_qdio_buffer_states {
368 /*
369 * inbound: read out by driver; owned by hardware in order to be filled
370 * outbound: owned by driver in order to be filled
371 */
372 QETH_QDIO_BUF_EMPTY,
373 /*
374 * inbound: filled by hardware; owned by driver in order to be read out
375 * outbound: filled by driver; owned by hardware in order to be sent
376 */
377 QETH_QDIO_BUF_PRIMED,
378};
379
380enum qeth_qdio_info_states {
381 QETH_QDIO_UNINITIALIZED,
382 QETH_QDIO_ALLOCATED,
383 QETH_QDIO_ESTABLISHED,
384 QETH_QDIO_CLEANING
385};
386
387struct qeth_buffer_pool_entry {
388 struct list_head list;
389 struct list_head init_list;
390 void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
391};
392
393struct qeth_qdio_buffer_pool {
394 struct list_head entry_list;
395 int buf_count;
396};
397
398struct qeth_qdio_buffer {
399 struct qdio_buffer *buffer;
400 /* the buffer pool entry currently associated to this buffer */
401 struct qeth_buffer_pool_entry *pool_entry;
402};
403
404struct qeth_qdio_q {
405 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
406 struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
407 int next_buf_to_init;
408} __attribute__ ((aligned(256)));
409
410struct qeth_qdio_out_buffer {
411 struct qdio_buffer *buffer;
412 atomic_t state;
413 int next_element_to_fill;
414 struct sk_buff_head skb_list;
415 struct list_head ctx_list;
416 int is_header[16];
417};
418
419struct qeth_card;
420
421enum qeth_out_q_states {
422 QETH_OUT_Q_UNLOCKED,
423 QETH_OUT_Q_LOCKED,
424 QETH_OUT_Q_LOCKED_FLUSH,
425};
426
427struct qeth_qdio_out_q {
428 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
429 struct qeth_qdio_out_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
430 int queue_no;
431 struct qeth_card *card;
432 atomic_t state;
433 int do_pack;
434 /*
435 * index of buffer to be filled by driver; state EMPTY or PACKING
436 */
437 int next_buf_to_fill;
438 /*
439 * number of buffers that are currently filled (PRIMED)
440 * -> these buffers are hardware-owned
441 */
442 atomic_t used_buffers;
443 /* indicates whether PCI flag must be set (or if one is outstanding) */
444 atomic_t set_pci_flags_count;
445} __attribute__ ((aligned(256)));
446
447struct qeth_qdio_info {
448 atomic_t state;
449 /* input */
450 struct qeth_qdio_q *in_q;
451 struct qeth_qdio_buffer_pool in_buf_pool;
452 struct qeth_qdio_buffer_pool init_pool;
453 int in_buf_size;
454
455 /* output */
456 int no_out_queues;
457 struct qeth_qdio_out_q **out_qs;
458
459 /* priority queueing */
460 int do_prio_queueing;
461 int default_out_queue;
462};
463
464enum qeth_send_errors {
465 QETH_SEND_ERROR_NONE,
466 QETH_SEND_ERROR_LINK_FAILURE,
467 QETH_SEND_ERROR_RETRY,
468 QETH_SEND_ERROR_KICK_IT,
469};
470
471#define QETH_ETH_MAC_V4 0x0100 /* like v4 */
472#define QETH_ETH_MAC_V6 0x3333 /* like v6 */
473/* tr mc mac is longer, but that will be enough to detect mc frames */
474#define QETH_TR_MAC_NC 0xc000 /* non-canonical */
475#define QETH_TR_MAC_C 0x0300 /* canonical */
476
477#define DEFAULT_ADD_HHLEN 0
478#define MAX_ADD_HHLEN 1024
479
480/**
481 * buffer stuff for read channel
482 */
483#define QETH_CMD_BUFFER_NO 8
484
485/**
486 * channel state machine
487 */
488enum qeth_channel_states {
489 CH_STATE_UP,
490 CH_STATE_DOWN,
491 CH_STATE_ACTIVATING,
492 CH_STATE_HALTED,
493 CH_STATE_STOPPED,
494 CH_STATE_RCD,
495 CH_STATE_RCD_DONE,
496};
497/**
498 * card state machine
499 */
500enum qeth_card_states {
501 CARD_STATE_DOWN,
502 CARD_STATE_HARDSETUP,
503 CARD_STATE_SOFTSETUP,
504 CARD_STATE_UP,
505 CARD_STATE_RECOVER,
506};
507
508/**
509 * Protocol versions
510 */
511enum qeth_prot_versions {
512 QETH_PROT_IPV4 = 0x0004,
513 QETH_PROT_IPV6 = 0x0006,
514};
515
516enum qeth_ip_types {
517 QETH_IP_TYPE_NORMAL,
518 QETH_IP_TYPE_VIPA,
519 QETH_IP_TYPE_RXIP,
520 QETH_IP_TYPE_DEL_ALL_MC,
521};
522
523enum qeth_cmd_buffer_state {
524 BUF_STATE_FREE,
525 BUF_STATE_LOCKED,
526 BUF_STATE_PROCESSED,
527};
528
529struct qeth_ipato {
530 int enabled;
531 int invert4;
532 int invert6;
533 struct list_head entries;
534};
535
536struct qeth_channel;
537
538struct qeth_cmd_buffer {
539 enum qeth_cmd_buffer_state state;
540 struct qeth_channel *channel;
541 unsigned char *data;
542 int rc;
543 void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
544};
545
546/**
547 * definition of a qeth channel, used for read and write
548 */
549struct qeth_channel {
550 enum qeth_channel_states state;
551 struct ccw1 ccw;
552 spinlock_t iob_lock;
553 wait_queue_head_t wait_q;
554 struct tasklet_struct irq_tasklet;
555 struct ccw_device *ccwdev;
556/*command buffer for control data*/
557 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
558 atomic_t irq_pending;
559 int io_buf_no;
560 int buf_no;
561};
562
563/**
564 * OSA card related definitions
565 */
566struct qeth_token {
567 __u32 issuer_rm_w;
568 __u32 issuer_rm_r;
569 __u32 cm_filter_w;
570 __u32 cm_filter_r;
571 __u32 cm_connection_w;
572 __u32 cm_connection_r;
573 __u32 ulp_filter_w;
574 __u32 ulp_filter_r;
575 __u32 ulp_connection_w;
576 __u32 ulp_connection_r;
577};
578
579struct qeth_seqno {
580 __u32 trans_hdr;
581 __u32 pdu_hdr;
582 __u32 pdu_hdr_ack;
583 __u16 ipa;
584 __u32 pkt_seqno;
585};
586
587struct qeth_reply {
588 struct list_head list;
589 wait_queue_head_t wait_q;
590 int (*callback)(struct qeth_card *, struct qeth_reply *,
591 unsigned long);
592 u32 seqno;
593 unsigned long offset;
594 atomic_t received;
595 int rc;
596 void *param;
597 struct qeth_card *card;
598 atomic_t refcnt;
599};
600
601
602struct qeth_card_blkt {
603 int time_total;
604 int inter_packet;
605 int inter_packet_jumbo;
606};
607
608#define QETH_BROADCAST_WITH_ECHO 0x01
609#define QETH_BROADCAST_WITHOUT_ECHO 0x02
610#define QETH_LAYER2_MAC_READ 0x01
611#define QETH_LAYER2_MAC_REGISTERED 0x02
612struct qeth_card_info {
613 unsigned short unit_addr2;
614 unsigned short cula;
615 unsigned short chpid;
616 __u16 func_level;
617 char mcl_level[QETH_MCL_LENGTH + 1];
618 int guestlan;
619 int mac_bits;
620 int portname_required;
621 int portno;
622 char portname[9];
623 enum qeth_card_types type;
624 enum qeth_link_types link_type;
625 int is_multicast_different;
626 int initial_mtu;
627 int max_mtu;
628 int broadcast_capable;
629 int unique_id;
630 struct qeth_card_blkt blkt;
631 __u32 csum_mask;
632 __u32 tx_csum_mask;
633 enum qeth_ipa_promisc_modes promisc_mode;
634 __u32 diagass_support;
635 __u32 hwtrap;
636};
637
638struct qeth_card_options {
639 struct qeth_routing_info route4;
640 struct qeth_ipa_info ipa4;
641 struct qeth_ipa_info adp; /*Adapter parameters*/
642 struct qeth_routing_info route6;
643 struct qeth_ipa_info ipa6;
644 int broadcast_mode;
645 int macaddr_mode;
646 int fake_broadcast;
647 int add_hhlen;
648 int layer2;
649 int performance_stats;
650 int rx_sg_cb;
651 enum qeth_ipa_isolation_modes isolation;
652 int sniffer;
653};
654
655/*
656 * thread bits for qeth_card thread masks
657 */
658enum qeth_threads {
659 QETH_RECOVER_THREAD = 1,
660};
661
662struct qeth_osn_info {
663 int (*assist_cb)(struct net_device *dev, void *data);
664 int (*data_cb)(struct sk_buff *skb);
665};
666
667enum qeth_discipline_id {
668 QETH_DISCIPLINE_LAYER3 = 0,
669 QETH_DISCIPLINE_LAYER2 = 1,
670};
671
672struct qeth_discipline {
673 void (*start_poll)(struct ccw_device *, int, unsigned long);
674 qdio_handler_t *input_handler;
675 qdio_handler_t *output_handler;
676 int (*recover)(void *ptr);
677 struct ccwgroup_driver *ccwgdriver;
678};
679
680struct qeth_vlan_vid {
681 struct list_head list;
682 unsigned short vid;
683};
684
685struct qeth_mc_mac {
686 struct list_head list;
687 __u8 mc_addr[MAX_ADDR_LEN];
688 unsigned char mc_addrlen;
689 int is_vmac;
690};
691
692struct qeth_rx {
693 int b_count;
694 int b_index;
695 struct qdio_buffer_element *b_element;
696 int e_offset;
697 int qdio_err;
698};
699
700#define QETH_NAPI_WEIGHT 128
701
702struct qeth_card {
703 struct list_head list;
704 enum qeth_card_states state;
705 int lan_online;
706 spinlock_t lock;
707 struct ccwgroup_device *gdev;
708 struct qeth_channel read;
709 struct qeth_channel write;
710 struct qeth_channel data;
711
712 struct net_device *dev;
713 struct net_device_stats stats;
714
715 struct qeth_card_info info;
716 struct qeth_token token;
717 struct qeth_seqno seqno;
718 struct qeth_card_options options;
719
720 wait_queue_head_t wait_q;
721 spinlock_t vlanlock;
722 spinlock_t mclock;
723 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
724 struct list_head vid_list;
725 struct list_head mc_list;
726 struct work_struct kernel_thread_starter;
727 spinlock_t thread_mask_lock;
728 unsigned long thread_start_mask;
729 unsigned long thread_allowed_mask;
730 unsigned long thread_running_mask;
731 spinlock_t ip_lock;
732 struct list_head ip_list;
733 struct list_head *ip_tbd_list;
734 struct qeth_ipato ipato;
735 struct list_head cmd_waiter_list;
736 /* QDIO buffer handling */
737 struct qeth_qdio_info qdio;
738 struct qeth_perf_stats perf_stats;
739 int read_or_write_problem;
740 struct qeth_osn_info osn_info;
741 struct qeth_discipline discipline;
742 atomic_t force_alloc_skb;
743 struct service_level qeth_service_level;
744 struct qdio_ssqd_desc ssqd;
745 debug_info_t *debug;
746 struct mutex conf_mutex;
747 struct mutex discipline_mutex;
748 struct napi_struct napi;
749 struct qeth_rx rx;
750};
751
752struct qeth_card_list_struct {
753 struct list_head list;
754 rwlock_t rwlock;
755};
756
757struct qeth_trap_id {
758 __u16 lparnr;
759 char vmname[8];
760 __u8 chpid;
761 __u8 ssid;
762 __u16 devno;
763} __packed;
764
765/*some helper functions*/
766#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
767
768static inline struct qeth_card *CARD_FROM_CDEV(struct ccw_device *cdev)
769{
770 struct qeth_card *card = dev_get_drvdata(&((struct ccwgroup_device *)
771 dev_get_drvdata(&cdev->dev))->dev);
772 return card;
773}
774
775static inline int qeth_get_micros(void)
776{
777 return (int) (get_clock() >> 12);
778}
779
780static inline int qeth_get_ip_version(struct sk_buff *skb)
781{
782 struct ethhdr *ehdr = (struct ethhdr *)skb->data;
783 switch (ehdr->h_proto) {
784 case ETH_P_IPV6:
785 return 6;
786 case ETH_P_IP:
787 return 4;
788 default:
789 return 0;
790 }
791}
792
793static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
794 struct qeth_buffer_pool_entry *entry)
795{
796 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
797}
798
799static inline int qeth_is_diagass_supported(struct qeth_card *card,
800 enum qeth_diags_cmds cmd)
801{
802 return card->info.diagass_support & (__u32)cmd;
803}
804
805extern struct ccwgroup_driver qeth_l2_ccwgroup_driver;
806extern struct ccwgroup_driver qeth_l3_ccwgroup_driver;
807const char *qeth_get_cardname_short(struct qeth_card *);
808int qeth_realloc_buffer_pool(struct qeth_card *, int);
809int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
810void qeth_core_free_discipline(struct qeth_card *);
811int qeth_core_create_device_attributes(struct device *);
812void qeth_core_remove_device_attributes(struct device *);
813int qeth_core_create_osn_attributes(struct device *);
814void qeth_core_remove_osn_attributes(struct device *);
815
816/* exports for qeth discipline device drivers */
817extern struct qeth_card_list_struct qeth_core_card_list;
818extern struct kmem_cache *qeth_core_header_cache;
819extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
820
821void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
822int qeth_threads_running(struct qeth_card *, unsigned long);
823int qeth_wait_for_threads(struct qeth_card *, unsigned long);
824int qeth_do_run_thread(struct qeth_card *, unsigned long);
825void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
826void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
827int qeth_core_hardsetup_card(struct qeth_card *);
828void qeth_print_status_message(struct qeth_card *);
829int qeth_init_qdio_queues(struct qeth_card *);
830int qeth_send_startlan(struct qeth_card *);
831int qeth_send_stoplan(struct qeth_card *);
832int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
833 int (*reply_cb)
834 (struct qeth_card *, struct qeth_reply *, unsigned long),
835 void *);
836struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *,
837 enum qeth_ipa_cmds, enum qeth_prot_versions);
838int qeth_query_setadapterparms(struct qeth_card *);
839int qeth_check_qdio_errors(struct qeth_card *, struct qdio_buffer *,
840 unsigned int, const char *);
841void qeth_queue_input_buffer(struct qeth_card *, int);
842struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
843 struct qdio_buffer *, struct qdio_buffer_element **, int *,
844 struct qeth_hdr **);
845void qeth_schedule_recovery(struct qeth_card *);
846void qeth_qdio_start_poll(struct ccw_device *, int, unsigned long);
847void qeth_qdio_input_handler(struct ccw_device *,
848 unsigned int, unsigned int, int,
849 int, unsigned long);
850void qeth_qdio_output_handler(struct ccw_device *, unsigned int,
851 int, int, int, unsigned long);
852void qeth_clear_ipacmd_list(struct qeth_card *);
853int qeth_qdio_clear_card(struct qeth_card *, int);
854void qeth_clear_working_pool_list(struct qeth_card *);
855void qeth_clear_cmd_buffers(struct qeth_channel *);
856void qeth_clear_qdio_buffers(struct qeth_card *);
857void qeth_setadp_promisc_mode(struct qeth_card *);
858struct net_device_stats *qeth_get_stats(struct net_device *);
859int qeth_change_mtu(struct net_device *, int);
860int qeth_setadpparms_change_macaddr(struct qeth_card *);
861void qeth_tx_timeout(struct net_device *);
862void qeth_prepare_control_data(struct qeth_card *, int,
863 struct qeth_cmd_buffer *);
864void qeth_release_buffer(struct qeth_channel *, struct qeth_cmd_buffer *);
865void qeth_prepare_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *, char);
866struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *);
867int qeth_mdio_read(struct net_device *, int, int);
868int qeth_snmp_command(struct qeth_card *, char __user *);
869struct qeth_cmd_buffer *qeth_get_adapter_cmd(struct qeth_card *, __u32, __u32);
870int qeth_default_setadapterparms_cb(struct qeth_card *, struct qeth_reply *,
871 unsigned long);
872int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
873 int (*reply_cb)(struct qeth_card *, struct qeth_reply*, unsigned long),
874 void *reply_param);
875int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int);
876int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int);
877int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *,
878 struct sk_buff *, struct qeth_hdr *, int, int, int);
879int qeth_do_send_packet(struct qeth_card *, struct qeth_qdio_out_q *,
880 struct sk_buff *, struct qeth_hdr *, int);
881int qeth_core_get_sset_count(struct net_device *, int);
882void qeth_core_get_ethtool_stats(struct net_device *,
883 struct ethtool_stats *, u64 *);
884void qeth_core_get_strings(struct net_device *, u32, u8 *);
885void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
886void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
887int qeth_core_ethtool_get_settings(struct net_device *, struct ethtool_cmd *);
888int qeth_set_access_ctrl_online(struct qeth_card *card);
889int qeth_hdr_chk_and_bounce(struct sk_buff *, int);
890int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
891int qeth_query_ipassists(struct qeth_card *, enum qeth_prot_versions prot);
892
893/* exports for OSN */
894int qeth_osn_assist(struct net_device *, void *, int);
895int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
896 int (*assist_cb)(struct net_device *, void *),
897 int (*data_cb)(struct sk_buff *));
898void qeth_osn_deregister(struct net_device *);
899
900#endif /* __QETH_CORE_H__ */
1/*
2 * Copyright IBM Corp. 2007
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
9#ifndef __QETH_CORE_H__
10#define __QETH_CORE_H__
11
12#include <linux/if.h>
13#include <linux/if_arp.h>
14#include <linux/etherdevice.h>
15#include <linux/if_vlan.h>
16#include <linux/ctype.h>
17#include <linux/in6.h>
18#include <linux/bitops.h>
19#include <linux/seq_file.h>
20#include <linux/ethtool.h>
21
22#include <net/ipv6.h>
23#include <net/if_inet6.h>
24#include <net/addrconf.h>
25
26#include <asm/debug.h>
27#include <asm/qdio.h>
28#include <asm/ccwdev.h>
29#include <asm/ccwgroup.h>
30#include <asm/sysinfo.h>
31
32#include "qeth_core_mpc.h"
33
34/**
35 * Debug Facility stuff
36 */
37enum qeth_dbf_names {
38 QETH_DBF_SETUP,
39 QETH_DBF_MSG,
40 QETH_DBF_CTRL,
41 QETH_DBF_INFOS /* must be last element */
42};
43
44struct qeth_dbf_info {
45 char name[DEBUG_MAX_NAME_LEN];
46 int pages;
47 int areas;
48 int len;
49 int level;
50 struct debug_view *view;
51 debug_info_t *id;
52};
53
54#define QETH_DBF_CTRL_LEN 256
55
56#define QETH_DBF_TEXT(name, level, text) \
57 debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
58
59#define QETH_DBF_HEX(name, level, addr, len) \
60 debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
61
62#define QETH_DBF_MESSAGE(level, text...) \
63 debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
64
65#define QETH_DBF_TEXT_(name, level, text...) \
66 qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
67
68#define QETH_CARD_TEXT(card, level, text) \
69 debug_text_event(card->debug, level, text)
70
71#define QETH_CARD_HEX(card, level, addr, len) \
72 debug_event(card->debug, level, (void *)(addr), len)
73
74#define QETH_CARD_MESSAGE(card, text...) \
75 debug_sprintf_event(card->debug, level, text)
76
77#define QETH_CARD_TEXT_(card, level, text...) \
78 qeth_dbf_longtext(card->debug, level, text)
79
80#define SENSE_COMMAND_REJECT_BYTE 0
81#define SENSE_COMMAND_REJECT_FLAG 0x80
82#define SENSE_RESETTING_EVENT_BYTE 1
83#define SENSE_RESETTING_EVENT_FLAG 0x80
84
85/*
86 * Common IO related definitions
87 */
88#define CARD_RDEV(card) card->read.ccwdev
89#define CARD_WDEV(card) card->write.ccwdev
90#define CARD_DDEV(card) card->data.ccwdev
91#define CARD_BUS_ID(card) dev_name(&card->gdev->dev)
92#define CARD_RDEV_ID(card) dev_name(&card->read.ccwdev->dev)
93#define CARD_WDEV_ID(card) dev_name(&card->write.ccwdev->dev)
94#define CARD_DDEV_ID(card) dev_name(&card->data.ccwdev->dev)
95#define CHANNEL_ID(channel) dev_name(&channel->ccwdev->dev)
96
97/**
98 * card stuff
99 */
100struct qeth_perf_stats {
101 unsigned int bufs_rec;
102 unsigned int bufs_sent;
103
104 unsigned int skbs_sent_pack;
105 unsigned int bufs_sent_pack;
106
107 unsigned int sc_dp_p;
108 unsigned int sc_p_dp;
109 /* qdio_cq_handler: number of times called, time spent in */
110 __u64 cq_start_time;
111 unsigned int cq_cnt;
112 unsigned int cq_time;
113 /* qdio_input_handler: number of times called, time spent in */
114 __u64 inbound_start_time;
115 unsigned int inbound_cnt;
116 unsigned int inbound_time;
117 /* qeth_send_packet: number of times called, time spent in */
118 __u64 outbound_start_time;
119 unsigned int outbound_cnt;
120 unsigned int outbound_time;
121 /* qdio_output_handler: number of times called, time spent in */
122 __u64 outbound_handler_start_time;
123 unsigned int outbound_handler_cnt;
124 unsigned int outbound_handler_time;
125 /* number of calls to and time spent in do_QDIO for inbound queue */
126 __u64 inbound_do_qdio_start_time;
127 unsigned int inbound_do_qdio_cnt;
128 unsigned int inbound_do_qdio_time;
129 /* number of calls to and time spent in do_QDIO for outbound queues */
130 __u64 outbound_do_qdio_start_time;
131 unsigned int outbound_do_qdio_cnt;
132 unsigned int outbound_do_qdio_time;
133 unsigned int large_send_bytes;
134 unsigned int large_send_cnt;
135 unsigned int sg_skbs_sent;
136 unsigned int sg_frags_sent;
137 /* initial values when measuring starts */
138 unsigned long initial_rx_packets;
139 unsigned long initial_tx_packets;
140 /* inbound scatter gather data */
141 unsigned int sg_skbs_rx;
142 unsigned int sg_frags_rx;
143 unsigned int sg_alloc_page_rx;
144 unsigned int tx_csum;
145 unsigned int tx_lin;
146};
147
148/* Routing stuff */
149struct qeth_routing_info {
150 enum qeth_routing_types type;
151};
152
153/* IPA stuff */
154struct qeth_ipa_info {
155 __u32 supported_funcs;
156 __u32 enabled_funcs;
157};
158
159/* SETBRIDGEPORT stuff */
160enum qeth_sbp_roles {
161 QETH_SBP_ROLE_NONE = 0,
162 QETH_SBP_ROLE_PRIMARY = 1,
163 QETH_SBP_ROLE_SECONDARY = 2,
164};
165
166enum qeth_sbp_states {
167 QETH_SBP_STATE_INACTIVE = 0,
168 QETH_SBP_STATE_STANDBY = 1,
169 QETH_SBP_STATE_ACTIVE = 2,
170};
171
172#define QETH_SBP_HOST_NOTIFICATION 1
173
174struct qeth_sbp_info {
175 __u32 supported_funcs;
176 enum qeth_sbp_roles role;
177 __u32 hostnotification:1;
178};
179
180static inline int qeth_is_ipa_supported(struct qeth_ipa_info *ipa,
181 enum qeth_ipa_funcs func)
182{
183 return (ipa->supported_funcs & func);
184}
185
186static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
187 enum qeth_ipa_funcs func)
188{
189 return (ipa->supported_funcs & ipa->enabled_funcs & func);
190}
191
192#define qeth_adp_supported(c, f) \
193 qeth_is_ipa_supported(&c->options.adp, f)
194#define qeth_adp_enabled(c, f) \
195 qeth_is_ipa_enabled(&c->options.adp, f)
196#define qeth_is_supported(c, f) \
197 qeth_is_ipa_supported(&c->options.ipa4, f)
198#define qeth_is_enabled(c, f) \
199 qeth_is_ipa_enabled(&c->options.ipa4, f)
200#define qeth_is_supported6(c, f) \
201 qeth_is_ipa_supported(&c->options.ipa6, f)
202#define qeth_is_enabled6(c, f) \
203 qeth_is_ipa_enabled(&c->options.ipa6, f)
204#define qeth_is_ipafunc_supported(c, prot, f) \
205 ((prot == QETH_PROT_IPV6) ? \
206 qeth_is_supported6(c, f) : qeth_is_supported(c, f))
207#define qeth_is_ipafunc_enabled(c, prot, f) \
208 ((prot == QETH_PROT_IPV6) ? \
209 qeth_is_enabled6(c, f) : qeth_is_enabled(c, f))
210
211#define QETH_IDX_FUNC_LEVEL_OSD 0x0101
212#define QETH_IDX_FUNC_LEVEL_IQD 0x4108
213
214#define QETH_MODELLIST_ARRAY \
215 {{0x1731, 0x01, 0x1732, QETH_CARD_TYPE_OSD, QETH_MAX_QUEUES, 0}, \
216 {0x1731, 0x05, 0x1732, QETH_CARD_TYPE_IQD, QETH_MAX_QUEUES, 0x103}, \
217 {0x1731, 0x06, 0x1732, QETH_CARD_TYPE_OSN, QETH_MAX_QUEUES, 0}, \
218 {0x1731, 0x02, 0x1732, QETH_CARD_TYPE_OSM, QETH_MAX_QUEUES, 0}, \
219 {0x1731, 0x02, 0x1732, QETH_CARD_TYPE_OSX, QETH_MAX_QUEUES, 0}, \
220 {0, 0, 0, 0, 0, 0} }
221#define QETH_CU_TYPE_IND 0
222#define QETH_CU_MODEL_IND 1
223#define QETH_DEV_TYPE_IND 2
224#define QETH_DEV_MODEL_IND 3
225#define QETH_QUEUE_NO_IND 4
226#define QETH_MULTICAST_IND 5
227
228#define QETH_REAL_CARD 1
229#define QETH_VLAN_CARD 2
230#define QETH_BUFSIZE 4096
231
232/**
233 * some more defs
234 */
235#define QETH_TX_TIMEOUT 100 * HZ
236#define QETH_RCD_TIMEOUT 60 * HZ
237#define QETH_RECLAIM_WORK_TIME HZ
238#define QETH_HEADER_SIZE 32
239#define QETH_MAX_PORTNO 15
240
241/*IPv6 address autoconfiguration stuff*/
242#define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
243#define UNIQUE_ID_NOT_BY_CARD 0x10000
244
245/*****************************************************************************/
246/* QDIO queue and buffer handling */
247/*****************************************************************************/
248#define QETH_MAX_QUEUES 4
249#define QETH_IN_BUF_SIZE_DEFAULT 65536
250#define QETH_IN_BUF_COUNT_DEFAULT 64
251#define QETH_IN_BUF_COUNT_HSDEFAULT 128
252#define QETH_IN_BUF_COUNT_MIN 8
253#define QETH_IN_BUF_COUNT_MAX 128
254#define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
255#define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
256 ((card)->qdio.in_buf_pool.buf_count / 2)
257
258/* buffers we have to be behind before we get a PCI */
259#define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
260/*enqueued free buffers left before we get a PCI*/
261#define QETH_PCI_THRESHOLD_B(card) 0
262/*not used unless the microcode gets patched*/
263#define QETH_PCI_TIMER_VALUE(card) 3
264
265/* priority queing */
266#define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
267#define QETH_DEFAULT_QUEUE 2
268#define QETH_NO_PRIO_QUEUEING 0
269#define QETH_PRIO_Q_ING_PREC 1
270#define QETH_PRIO_Q_ING_TOS 2
271#define IP_TOS_LOWDELAY 0x10
272#define IP_TOS_HIGHTHROUGHPUT 0x08
273#define IP_TOS_HIGHRELIABILITY 0x04
274#define IP_TOS_NOTIMPORTANT 0x02
275
276/* Packing */
277#define QETH_LOW_WATERMARK_PACK 2
278#define QETH_HIGH_WATERMARK_PACK 5
279#define QETH_WATERMARK_PACK_FUZZ 1
280
281#define QETH_IP_HEADER_SIZE 40
282
283/* large receive scatter gather copy break */
284#define QETH_RX_SG_CB (PAGE_SIZE >> 1)
285#define QETH_RX_PULL_LEN 256
286
287struct qeth_hdr_layer3 {
288 __u8 id;
289 __u8 flags;
290 __u16 inbound_checksum; /*TSO:__u16 seqno */
291 __u32 token; /*TSO: __u32 reserved */
292 __u16 length;
293 __u8 vlan_prio;
294 __u8 ext_flags;
295 __u16 vlan_id;
296 __u16 frame_offset;
297 __u8 dest_addr[16];
298} __attribute__ ((packed));
299
300struct qeth_hdr_layer2 {
301 __u8 id;
302 __u8 flags[3];
303 __u8 port_no;
304 __u8 hdr_length;
305 __u16 pkt_length;
306 __u16 seq_no;
307 __u16 vlan_id;
308 __u32 reserved;
309 __u8 reserved2[16];
310} __attribute__ ((packed));
311
312struct qeth_hdr_osn {
313 __u8 id;
314 __u8 reserved;
315 __u16 seq_no;
316 __u16 reserved2;
317 __u16 control_flags;
318 __u16 pdu_length;
319 __u8 reserved3[18];
320 __u32 ccid;
321} __attribute__ ((packed));
322
323struct qeth_hdr {
324 union {
325 struct qeth_hdr_layer2 l2;
326 struct qeth_hdr_layer3 l3;
327 struct qeth_hdr_osn osn;
328 } hdr;
329} __attribute__ ((packed));
330
331/*TCP Segmentation Offload header*/
332struct qeth_hdr_ext_tso {
333 __u16 hdr_tot_len;
334 __u8 imb_hdr_no;
335 __u8 reserved;
336 __u8 hdr_type;
337 __u8 hdr_version;
338 __u16 hdr_len;
339 __u32 payload_len;
340 __u16 mss;
341 __u16 dg_hdr_len;
342 __u8 padding[16];
343} __attribute__ ((packed));
344
345struct qeth_hdr_tso {
346 struct qeth_hdr hdr; /*hdr->hdr.l3.xxx*/
347 struct qeth_hdr_ext_tso ext;
348} __attribute__ ((packed));
349
350
351/* flags for qeth_hdr.flags */
352#define QETH_HDR_PASSTHRU 0x10
353#define QETH_HDR_IPV6 0x80
354#define QETH_HDR_CAST_MASK 0x07
355enum qeth_cast_flags {
356 QETH_CAST_UNICAST = 0x06,
357 QETH_CAST_MULTICAST = 0x04,
358 QETH_CAST_BROADCAST = 0x05,
359 QETH_CAST_ANYCAST = 0x07,
360 QETH_CAST_NOCAST = 0x00,
361};
362
363enum qeth_layer2_frame_flags {
364 QETH_LAYER2_FLAG_MULTICAST = 0x01,
365 QETH_LAYER2_FLAG_BROADCAST = 0x02,
366 QETH_LAYER2_FLAG_UNICAST = 0x04,
367 QETH_LAYER2_FLAG_VLAN = 0x10,
368};
369
370enum qeth_header_ids {
371 QETH_HEADER_TYPE_LAYER3 = 0x01,
372 QETH_HEADER_TYPE_LAYER2 = 0x02,
373 QETH_HEADER_TYPE_TSO = 0x03,
374 QETH_HEADER_TYPE_OSN = 0x04,
375};
376/* flags for qeth_hdr.ext_flags */
377#define QETH_HDR_EXT_VLAN_FRAME 0x01
378#define QETH_HDR_EXT_TOKEN_ID 0x02
379#define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
380#define QETH_HDR_EXT_SRC_MAC_ADDR 0x08
381#define QETH_HDR_EXT_CSUM_HDR_REQ 0x10
382#define QETH_HDR_EXT_CSUM_TRANSP_REQ 0x20
383#define QETH_HDR_EXT_UDP 0x40 /*bit off for TCP*/
384
385static inline int qeth_is_last_sbale(struct qdio_buffer_element *sbale)
386{
387 return (sbale->eflags & SBAL_EFLAGS_LAST_ENTRY);
388}
389
390enum qeth_qdio_buffer_states {
391 /*
392 * inbound: read out by driver; owned by hardware in order to be filled
393 * outbound: owned by driver in order to be filled
394 */
395 QETH_QDIO_BUF_EMPTY,
396 /*
397 * inbound: filled by hardware; owned by driver in order to be read out
398 * outbound: filled by driver; owned by hardware in order to be sent
399 */
400 QETH_QDIO_BUF_PRIMED,
401 /*
402 * inbound: not applicable
403 * outbound: identified to be pending in TPQ
404 */
405 QETH_QDIO_BUF_PENDING,
406 /*
407 * inbound: not applicable
408 * outbound: found in completion queue
409 */
410 QETH_QDIO_BUF_IN_CQ,
411 /*
412 * inbound: not applicable
413 * outbound: handled via transfer pending / completion queue
414 */
415 QETH_QDIO_BUF_HANDLED_DELAYED,
416};
417
418enum qeth_qdio_info_states {
419 QETH_QDIO_UNINITIALIZED,
420 QETH_QDIO_ALLOCATED,
421 QETH_QDIO_ESTABLISHED,
422 QETH_QDIO_CLEANING
423};
424
425struct qeth_buffer_pool_entry {
426 struct list_head list;
427 struct list_head init_list;
428 void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
429};
430
431struct qeth_qdio_buffer_pool {
432 struct list_head entry_list;
433 int buf_count;
434};
435
436struct qeth_qdio_buffer {
437 struct qdio_buffer *buffer;
438 /* the buffer pool entry currently associated to this buffer */
439 struct qeth_buffer_pool_entry *pool_entry;
440 struct sk_buff *rx_skb;
441};
442
443struct qeth_qdio_q {
444 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
445 struct qeth_qdio_buffer bufs[QDIO_MAX_BUFFERS_PER_Q];
446 int next_buf_to_init;
447} __attribute__ ((aligned(256)));
448
449struct qeth_qdio_out_buffer {
450 struct qdio_buffer *buffer;
451 atomic_t state;
452 int next_element_to_fill;
453 struct sk_buff_head skb_list;
454 int is_header[16];
455
456 struct qaob *aob;
457 struct qeth_qdio_out_q *q;
458 struct qeth_qdio_out_buffer *next_pending;
459};
460
461struct qeth_card;
462
463enum qeth_out_q_states {
464 QETH_OUT_Q_UNLOCKED,
465 QETH_OUT_Q_LOCKED,
466 QETH_OUT_Q_LOCKED_FLUSH,
467};
468
469struct qeth_qdio_out_q {
470 struct qdio_buffer qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
471 struct qeth_qdio_out_buffer *bufs[QDIO_MAX_BUFFERS_PER_Q];
472 struct qdio_outbuf_state *bufstates; /* convenience pointer */
473 int queue_no;
474 struct qeth_card *card;
475 atomic_t state;
476 int do_pack;
477 /*
478 * index of buffer to be filled by driver; state EMPTY or PACKING
479 */
480 int next_buf_to_fill;
481 /*
482 * number of buffers that are currently filled (PRIMED)
483 * -> these buffers are hardware-owned
484 */
485 atomic_t used_buffers;
486 /* indicates whether PCI flag must be set (or if one is outstanding) */
487 atomic_t set_pci_flags_count;
488} __attribute__ ((aligned(256)));
489
490struct qeth_qdio_info {
491 atomic_t state;
492 /* input */
493 int no_in_queues;
494 struct qeth_qdio_q *in_q;
495 struct qeth_qdio_q *c_q;
496 struct qeth_qdio_buffer_pool in_buf_pool;
497 struct qeth_qdio_buffer_pool init_pool;
498 int in_buf_size;
499
500 /* output */
501 int no_out_queues;
502 struct qeth_qdio_out_q **out_qs;
503 struct qdio_outbuf_state *out_bufstates;
504
505 /* priority queueing */
506 int do_prio_queueing;
507 int default_out_queue;
508};
509
510enum qeth_send_errors {
511 QETH_SEND_ERROR_NONE,
512 QETH_SEND_ERROR_LINK_FAILURE,
513 QETH_SEND_ERROR_RETRY,
514 QETH_SEND_ERROR_KICK_IT,
515};
516
517#define QETH_ETH_MAC_V4 0x0100 /* like v4 */
518#define QETH_ETH_MAC_V6 0x3333 /* like v6 */
519/* tr mc mac is longer, but that will be enough to detect mc frames */
520#define QETH_TR_MAC_NC 0xc000 /* non-canonical */
521#define QETH_TR_MAC_C 0x0300 /* canonical */
522
523#define DEFAULT_ADD_HHLEN 0
524#define MAX_ADD_HHLEN 1024
525
526/**
527 * buffer stuff for read channel
528 */
529#define QETH_CMD_BUFFER_NO 8
530
531/**
532 * channel state machine
533 */
534enum qeth_channel_states {
535 CH_STATE_UP,
536 CH_STATE_DOWN,
537 CH_STATE_ACTIVATING,
538 CH_STATE_HALTED,
539 CH_STATE_STOPPED,
540 CH_STATE_RCD,
541 CH_STATE_RCD_DONE,
542};
543/**
544 * card state machine
545 */
546enum qeth_card_states {
547 CARD_STATE_DOWN,
548 CARD_STATE_HARDSETUP,
549 CARD_STATE_SOFTSETUP,
550 CARD_STATE_UP,
551 CARD_STATE_RECOVER,
552};
553
554/**
555 * Protocol versions
556 */
557enum qeth_prot_versions {
558 QETH_PROT_IPV4 = 0x0004,
559 QETH_PROT_IPV6 = 0x0006,
560};
561
562enum qeth_ip_types {
563 QETH_IP_TYPE_NORMAL,
564 QETH_IP_TYPE_VIPA,
565 QETH_IP_TYPE_RXIP,
566 QETH_IP_TYPE_DEL_ALL_MC,
567};
568
569enum qeth_cmd_buffer_state {
570 BUF_STATE_FREE,
571 BUF_STATE_LOCKED,
572 BUF_STATE_PROCESSED,
573};
574
575enum qeth_cq {
576 QETH_CQ_DISABLED = 0,
577 QETH_CQ_ENABLED = 1,
578 QETH_CQ_NOTAVAILABLE = 2,
579};
580
581struct qeth_ipato {
582 int enabled;
583 int invert4;
584 int invert6;
585 struct list_head entries;
586};
587
588struct qeth_channel;
589
590struct qeth_cmd_buffer {
591 enum qeth_cmd_buffer_state state;
592 struct qeth_channel *channel;
593 unsigned char *data;
594 int rc;
595 void (*callback) (struct qeth_channel *, struct qeth_cmd_buffer *);
596};
597
598/**
599 * definition of a qeth channel, used for read and write
600 */
601struct qeth_channel {
602 enum qeth_channel_states state;
603 struct ccw1 ccw;
604 spinlock_t iob_lock;
605 wait_queue_head_t wait_q;
606 struct tasklet_struct irq_tasklet;
607 struct ccw_device *ccwdev;
608/*command buffer for control data*/
609 struct qeth_cmd_buffer iob[QETH_CMD_BUFFER_NO];
610 atomic_t irq_pending;
611 int io_buf_no;
612 int buf_no;
613};
614
615/**
616 * OSA card related definitions
617 */
618struct qeth_token {
619 __u32 issuer_rm_w;
620 __u32 issuer_rm_r;
621 __u32 cm_filter_w;
622 __u32 cm_filter_r;
623 __u32 cm_connection_w;
624 __u32 cm_connection_r;
625 __u32 ulp_filter_w;
626 __u32 ulp_filter_r;
627 __u32 ulp_connection_w;
628 __u32 ulp_connection_r;
629};
630
631struct qeth_seqno {
632 __u32 trans_hdr;
633 __u32 pdu_hdr;
634 __u32 pdu_hdr_ack;
635 __u16 ipa;
636 __u32 pkt_seqno;
637};
638
639struct qeth_reply {
640 struct list_head list;
641 wait_queue_head_t wait_q;
642 int (*callback)(struct qeth_card *, struct qeth_reply *,
643 unsigned long);
644 u32 seqno;
645 unsigned long offset;
646 atomic_t received;
647 int rc;
648 void *param;
649 struct qeth_card *card;
650 atomic_t refcnt;
651};
652
653
654struct qeth_card_blkt {
655 int time_total;
656 int inter_packet;
657 int inter_packet_jumbo;
658};
659
660#define QETH_BROADCAST_WITH_ECHO 0x01
661#define QETH_BROADCAST_WITHOUT_ECHO 0x02
662#define QETH_LAYER2_MAC_READ 0x01
663#define QETH_LAYER2_MAC_REGISTERED 0x02
664struct qeth_card_info {
665 unsigned short unit_addr2;
666 unsigned short cula;
667 unsigned short chpid;
668 __u16 func_level;
669 char mcl_level[QETH_MCL_LENGTH + 1];
670 int guestlan;
671 int mac_bits;
672 int portname_required;
673 int portno;
674 char portname[9];
675 enum qeth_card_types type;
676 enum qeth_link_types link_type;
677 int is_multicast_different;
678 int initial_mtu;
679 int max_mtu;
680 int broadcast_capable;
681 int unique_id;
682 struct qeth_card_blkt blkt;
683 __u32 csum_mask;
684 __u32 tx_csum_mask;
685 enum qeth_ipa_promisc_modes promisc_mode;
686 __u32 diagass_support;
687 __u32 hwtrap;
688};
689
690struct qeth_card_options {
691 struct qeth_routing_info route4;
692 struct qeth_ipa_info ipa4;
693 struct qeth_ipa_info adp; /*Adapter parameters*/
694 struct qeth_routing_info route6;
695 struct qeth_ipa_info ipa6;
696 struct qeth_sbp_info sbp; /* SETBRIDGEPORT options */
697 int fake_broadcast;
698 int add_hhlen;
699 int layer2;
700 int performance_stats;
701 int rx_sg_cb;
702 enum qeth_ipa_isolation_modes isolation;
703 enum qeth_ipa_isolation_modes prev_isolation;
704 int sniffer;
705 enum qeth_cq cq;
706 char hsuid[9];
707};
708
709/*
710 * thread bits for qeth_card thread masks
711 */
712enum qeth_threads {
713 QETH_RECOVER_THREAD = 1,
714};
715
716struct qeth_osn_info {
717 int (*assist_cb)(struct net_device *dev, void *data);
718 int (*data_cb)(struct sk_buff *skb);
719};
720
721enum qeth_discipline_id {
722 QETH_DISCIPLINE_LAYER3 = 0,
723 QETH_DISCIPLINE_LAYER2 = 1,
724};
725
726struct qeth_discipline {
727 void (*start_poll)(struct ccw_device *, int, unsigned long);
728 qdio_handler_t *input_handler;
729 qdio_handler_t *output_handler;
730 int (*recover)(void *ptr);
731 int (*setup) (struct ccwgroup_device *);
732 void (*remove) (struct ccwgroup_device *);
733 int (*set_online) (struct ccwgroup_device *);
734 int (*set_offline) (struct ccwgroup_device *);
735 void (*shutdown)(struct ccwgroup_device *);
736 int (*prepare) (struct ccwgroup_device *);
737 void (*complete) (struct ccwgroup_device *);
738 int (*freeze)(struct ccwgroup_device *);
739 int (*thaw) (struct ccwgroup_device *);
740 int (*restore)(struct ccwgroup_device *);
741 int (*control_event_handler)(struct qeth_card *card,
742 struct qeth_ipa_cmd *cmd);
743};
744
745struct qeth_vlan_vid {
746 struct list_head list;
747 unsigned short vid;
748};
749
750struct qeth_mc_mac {
751 struct list_head list;
752 __u8 mc_addr[MAX_ADDR_LEN];
753 unsigned char mc_addrlen;
754 int is_vmac;
755};
756
757struct qeth_rx {
758 int b_count;
759 int b_index;
760 struct qdio_buffer_element *b_element;
761 int e_offset;
762 int qdio_err;
763};
764
765struct carrier_info {
766 __u8 card_type;
767 __u16 port_mode;
768 __u32 port_speed;
769};
770
771#define QETH_NAPI_WEIGHT NAPI_POLL_WEIGHT
772
773struct qeth_card {
774 struct list_head list;
775 enum qeth_card_states state;
776 int lan_online;
777 spinlock_t lock;
778 struct ccwgroup_device *gdev;
779 struct qeth_channel read;
780 struct qeth_channel write;
781 struct qeth_channel data;
782
783 struct net_device *dev;
784 struct net_device_stats stats;
785
786 struct qeth_card_info info;
787 struct qeth_token token;
788 struct qeth_seqno seqno;
789 struct qeth_card_options options;
790
791 wait_queue_head_t wait_q;
792 spinlock_t vlanlock;
793 spinlock_t mclock;
794 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
795 struct list_head vid_list;
796 struct list_head mc_list;
797 struct work_struct kernel_thread_starter;
798 spinlock_t thread_mask_lock;
799 unsigned long thread_start_mask;
800 unsigned long thread_allowed_mask;
801 unsigned long thread_running_mask;
802 struct task_struct *recovery_task;
803 spinlock_t ip_lock;
804 struct list_head ip_list;
805 struct list_head *ip_tbd_list;
806 struct qeth_ipato ipato;
807 struct list_head cmd_waiter_list;
808 /* QDIO buffer handling */
809 struct qeth_qdio_info qdio;
810 struct qeth_perf_stats perf_stats;
811 int read_or_write_problem;
812 struct qeth_osn_info osn_info;
813 struct qeth_discipline *discipline;
814 atomic_t force_alloc_skb;
815 struct service_level qeth_service_level;
816 struct qdio_ssqd_desc ssqd;
817 debug_info_t *debug;
818 struct mutex conf_mutex;
819 struct mutex discipline_mutex;
820 struct napi_struct napi;
821 struct qeth_rx rx;
822 struct delayed_work buffer_reclaim_work;
823 int reclaim_index;
824 struct work_struct close_dev_work;
825};
826
827struct qeth_card_list_struct {
828 struct list_head list;
829 rwlock_t rwlock;
830};
831
832struct qeth_trap_id {
833 __u16 lparnr;
834 char vmname[8];
835 __u8 chpid;
836 __u8 ssid;
837 __u16 devno;
838} __packed;
839
840/*some helper functions*/
841#define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
842
843static inline struct qeth_card *CARD_FROM_CDEV(struct ccw_device *cdev)
844{
845 struct qeth_card *card = dev_get_drvdata(&((struct ccwgroup_device *)
846 dev_get_drvdata(&cdev->dev))->dev);
847 return card;
848}
849
850static inline int qeth_get_micros(void)
851{
852 return (int) (get_tod_clock() >> 12);
853}
854
855static inline int qeth_get_ip_version(struct sk_buff *skb)
856{
857 __be16 *p = &((struct ethhdr *)skb->data)->h_proto;
858
859 if (*p == ETH_P_8021Q)
860 p += 2;
861 switch (*p) {
862 case ETH_P_IPV6:
863 return 6;
864 case ETH_P_IP:
865 return 4;
866 default:
867 return 0;
868 }
869}
870
871static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
872 struct qeth_buffer_pool_entry *entry)
873{
874 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
875}
876
877static inline int qeth_is_diagass_supported(struct qeth_card *card,
878 enum qeth_diags_cmds cmd)
879{
880 return card->info.diagass_support & (__u32)cmd;
881}
882
883extern struct qeth_discipline qeth_l2_discipline;
884extern struct qeth_discipline qeth_l3_discipline;
885extern const struct attribute_group *qeth_generic_attr_groups[];
886extern const struct attribute_group *qeth_osn_attr_groups[];
887extern struct workqueue_struct *qeth_wq;
888
889const char *qeth_get_cardname_short(struct qeth_card *);
890int qeth_realloc_buffer_pool(struct qeth_card *, int);
891int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
892void qeth_core_free_discipline(struct qeth_card *);
893void qeth_buffer_reclaim_work(struct work_struct *);
894
895/* exports for qeth discipline device drivers */
896extern struct qeth_card_list_struct qeth_core_card_list;
897extern struct kmem_cache *qeth_core_header_cache;
898extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
899
900void qeth_set_recovery_task(struct qeth_card *);
901void qeth_clear_recovery_task(struct qeth_card *);
902void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
903int qeth_threads_running(struct qeth_card *, unsigned long);
904int qeth_wait_for_threads(struct qeth_card *, unsigned long);
905int qeth_do_run_thread(struct qeth_card *, unsigned long);
906void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
907void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
908int qeth_core_hardsetup_card(struct qeth_card *);
909void qeth_print_status_message(struct qeth_card *);
910int qeth_init_qdio_queues(struct qeth_card *);
911int qeth_send_startlan(struct qeth_card *);
912int qeth_send_stoplan(struct qeth_card *);
913int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
914 int (*reply_cb)
915 (struct qeth_card *, struct qeth_reply *, unsigned long),
916 void *);
917struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *,
918 enum qeth_ipa_cmds, enum qeth_prot_versions);
919int qeth_query_setadapterparms(struct qeth_card *);
920int qeth_check_qdio_errors(struct qeth_card *, struct qdio_buffer *,
921 unsigned int, const char *);
922void qeth_queue_input_buffer(struct qeth_card *, int);
923struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
924 struct qeth_qdio_buffer *, struct qdio_buffer_element **, int *,
925 struct qeth_hdr **);
926void qeth_schedule_recovery(struct qeth_card *);
927void qeth_qdio_start_poll(struct ccw_device *, int, unsigned long);
928void qeth_qdio_input_handler(struct ccw_device *,
929 unsigned int, unsigned int, int,
930 int, unsigned long);
931void qeth_qdio_output_handler(struct ccw_device *, unsigned int,
932 int, int, int, unsigned long);
933void qeth_clear_ipacmd_list(struct qeth_card *);
934int qeth_qdio_clear_card(struct qeth_card *, int);
935void qeth_clear_working_pool_list(struct qeth_card *);
936void qeth_clear_cmd_buffers(struct qeth_channel *);
937void qeth_clear_qdio_buffers(struct qeth_card *);
938void qeth_setadp_promisc_mode(struct qeth_card *);
939struct net_device_stats *qeth_get_stats(struct net_device *);
940int qeth_change_mtu(struct net_device *, int);
941int qeth_setadpparms_change_macaddr(struct qeth_card *);
942void qeth_tx_timeout(struct net_device *);
943void qeth_prepare_control_data(struct qeth_card *, int,
944 struct qeth_cmd_buffer *);
945void qeth_release_buffer(struct qeth_channel *, struct qeth_cmd_buffer *);
946void qeth_prepare_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *, char);
947struct qeth_cmd_buffer *qeth_wait_for_buffer(struct qeth_channel *);
948int qeth_mdio_read(struct net_device *, int, int);
949int qeth_snmp_command(struct qeth_card *, char __user *);
950int qeth_query_oat_command(struct qeth_card *, char __user *);
951int qeth_query_card_info(struct qeth_card *card,
952 struct carrier_info *carrier_info);
953int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
954 int (*reply_cb)(struct qeth_card *, struct qeth_reply*, unsigned long),
955 void *reply_param);
956int qeth_bridgeport_query_ports(struct qeth_card *card,
957 enum qeth_sbp_roles *role, enum qeth_sbp_states *state);
958int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role);
959int qeth_bridgeport_an_set(struct qeth_card *card, int enable);
960int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int);
961int qeth_get_elements_no(struct qeth_card *, struct sk_buff *, int);
962int qeth_get_elements_for_frags(struct sk_buff *);
963int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *,
964 struct sk_buff *, struct qeth_hdr *, int, int, int);
965int qeth_do_send_packet(struct qeth_card *, struct qeth_qdio_out_q *,
966 struct sk_buff *, struct qeth_hdr *, int);
967int qeth_core_get_sset_count(struct net_device *, int);
968void qeth_core_get_ethtool_stats(struct net_device *,
969 struct ethtool_stats *, u64 *);
970void qeth_core_get_strings(struct net_device *, u32, u8 *);
971void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
972void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
973int qeth_core_ethtool_get_settings(struct net_device *, struct ethtool_cmd *);
974int qeth_set_access_ctrl_online(struct qeth_card *card, int fallback);
975int qeth_hdr_chk_and_bounce(struct sk_buff *, struct qeth_hdr **, int);
976int qeth_configure_cq(struct qeth_card *, enum qeth_cq);
977int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
978int qeth_query_ipassists(struct qeth_card *, enum qeth_prot_versions prot);
979void qeth_trace_features(struct qeth_card *);
980void qeth_close_dev(struct qeth_card *);
981
982/* exports for OSN */
983int qeth_osn_assist(struct net_device *, void *, int);
984int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
985 int (*assist_cb)(struct net_device *, void *),
986 int (*data_cb)(struct sk_buff *));
987void qeth_osn_deregister(struct net_device *);
988
989#endif /* __QETH_CORE_H__ */