Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[sfrench/cifs-2.6.git] / drivers / s390 / net / qeth_core.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *    Copyright IBM Corp. 2007
4  *    Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5  *               Frank Pavlic <fpavlic@de.ibm.com>,
6  *               Thomas Spatzier <tspat@de.ibm.com>,
7  *               Frank Blaschka <frank.blaschka@de.ibm.com>
8  */
9
10 #ifndef __QETH_CORE_H__
11 #define __QETH_CORE_H__
12
13 #include <linux/completion.h>
14 #include <linux/if.h>
15 #include <linux/if_arp.h>
16 #include <linux/etherdevice.h>
17 #include <linux/if_vlan.h>
18 #include <linux/ctype.h>
19 #include <linux/in6.h>
20 #include <linux/bitops.h>
21 #include <linux/seq_file.h>
22 #include <linux/hashtable.h>
23 #include <linux/ip.h>
24 #include <linux/refcount.h>
25 #include <linux/wait.h>
26 #include <linux/workqueue.h>
27
28 #include <net/dst.h>
29 #include <net/ip6_fib.h>
30 #include <net/ipv6.h>
31 #include <net/if_inet6.h>
32 #include <net/addrconf.h>
33 #include <net/tcp.h>
34
35 #include <asm/debug.h>
36 #include <asm/qdio.h>
37 #include <asm/ccwdev.h>
38 #include <asm/ccwgroup.h>
39 #include <asm/sysinfo.h>
40
41 #include <uapi/linux/if_link.h>
42
43 #include "qeth_core_mpc.h"
44
45 /**
46  * Debug Facility stuff
47  */
48 enum qeth_dbf_names {
49         QETH_DBF_SETUP,
50         QETH_DBF_MSG,
51         QETH_DBF_CTRL,
52         QETH_DBF_INFOS  /* must be last element */
53 };
54
55 struct qeth_dbf_info {
56         char name[DEBUG_MAX_NAME_LEN];
57         int pages;
58         int areas;
59         int len;
60         int level;
61         struct debug_view *view;
62         debug_info_t *id;
63 };
64
65 #define QETH_DBF_CTRL_LEN 256U
66
67 #define QETH_DBF_TEXT(name, level, text) \
68         debug_text_event(qeth_dbf[QETH_DBF_##name].id, level, text)
69
70 #define QETH_DBF_HEX(name, level, addr, len) \
71         debug_event(qeth_dbf[QETH_DBF_##name].id, level, (void *)(addr), len)
72
73 #define QETH_DBF_MESSAGE(level, text...) \
74         debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
75
76 #define QETH_DBF_TEXT_(name, level, text...) \
77         qeth_dbf_longtext(qeth_dbf[QETH_DBF_##name].id, level, text)
78
79 #define QETH_CARD_TEXT(card, level, text) \
80         debug_text_event(card->debug, level, text)
81
82 #define QETH_CARD_HEX(card, level, addr, len) \
83         debug_event(card->debug, level, (void *)(addr), len)
84
85 #define QETH_CARD_MESSAGE(card, text...) \
86         debug_sprintf_event(card->debug, level, text)
87
88 #define QETH_CARD_TEXT_(card, level, text...) \
89         qeth_dbf_longtext(card->debug, level, text)
90
91 #define SENSE_COMMAND_REJECT_BYTE 0
92 #define SENSE_COMMAND_REJECT_FLAG 0x80
93 #define SENSE_RESETTING_EVENT_BYTE 1
94 #define SENSE_RESETTING_EVENT_FLAG 0x80
95
96 static inline u32 qeth_get_device_id(struct ccw_device *cdev)
97 {
98         struct ccw_dev_id dev_id;
99         u32 id;
100
101         ccw_device_get_id(cdev, &dev_id);
102         id = dev_id.devno;
103         id |= (u32) (dev_id.ssid << 16);
104
105         return id;
106 }
107
108 /*
109  * Common IO related definitions
110  */
111 #define CARD_RDEV(card) card->read.ccwdev
112 #define CARD_WDEV(card) card->write.ccwdev
113 #define CARD_DDEV(card) card->data.ccwdev
114 #define CARD_BUS_ID(card) dev_name(&card->gdev->dev)
115 #define CARD_RDEV_ID(card) dev_name(&card->read.ccwdev->dev)
116 #define CARD_WDEV_ID(card) dev_name(&card->write.ccwdev->dev)
117 #define CARD_DDEV_ID(card) dev_name(&card->data.ccwdev->dev)
118 #define CCW_DEVID(cdev)         (qeth_get_device_id(cdev))
119 #define CARD_DEVID(card)        (CCW_DEVID(CARD_RDEV(card)))
120
121 /* Routing stuff */
122 struct qeth_routing_info {
123         enum qeth_routing_types type;
124 };
125
126 /* IPA stuff */
127 struct qeth_ipa_info {
128         __u32 supported_funcs;
129         __u32 enabled_funcs;
130 };
131
132 /* SETBRIDGEPORT stuff */
133 enum qeth_sbp_roles {
134         QETH_SBP_ROLE_NONE      = 0,
135         QETH_SBP_ROLE_PRIMARY   = 1,
136         QETH_SBP_ROLE_SECONDARY = 2,
137 };
138
139 enum qeth_sbp_states {
140         QETH_SBP_STATE_INACTIVE = 0,
141         QETH_SBP_STATE_STANDBY  = 1,
142         QETH_SBP_STATE_ACTIVE   = 2,
143 };
144
145 #define QETH_SBP_HOST_NOTIFICATION 1
146
147 struct qeth_sbp_info {
148         __u32 supported_funcs;
149         enum qeth_sbp_roles role;
150         __u32 hostnotification:1;
151         __u32 reflect_promisc:1;
152         __u32 reflect_promisc_primary:1;
153 };
154
155 struct qeth_vnicc_info {
156         /* supported/currently configured VNICCs; updated in IPA exchanges */
157         u32 sup_chars;
158         u32 cur_chars;
159         /* supported commands: bitmasks which VNICCs support respective cmd */
160         u32 set_char_sup;
161         u32 getset_timeout_sup;
162         /* timeout value for the learning characteristic */
163         u32 learning_timeout;
164         /* characteristics wanted/configured by user */
165         u32 wanted_chars;
166         /* has user explicitly enabled rx_bcast while online? */
167         bool rx_bcast_enabled;
168 };
169
170 static inline int qeth_is_adp_supported(struct qeth_ipa_info *ipa,
171                 enum qeth_ipa_setadp_cmd func)
172 {
173         return (ipa->supported_funcs & func);
174 }
175
176 static inline int qeth_is_ipa_supported(struct qeth_ipa_info *ipa,
177                 enum qeth_ipa_funcs func)
178 {
179         return (ipa->supported_funcs & func);
180 }
181
182 static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa,
183                 enum qeth_ipa_funcs func)
184 {
185         return (ipa->supported_funcs & ipa->enabled_funcs & func);
186 }
187
188 #define qeth_adp_supported(c, f) \
189         qeth_is_adp_supported(&c->options.adp, f)
190 #define qeth_is_supported(c, f) \
191         qeth_is_ipa_supported(&c->options.ipa4, f)
192 #define qeth_is_enabled(c, f) \
193         qeth_is_ipa_enabled(&c->options.ipa4, f)
194 #define qeth_is_supported6(c, f) \
195         qeth_is_ipa_supported(&c->options.ipa6, f)
196 #define qeth_is_enabled6(c, f) \
197         qeth_is_ipa_enabled(&c->options.ipa6, f)
198 #define qeth_is_ipafunc_supported(c, prot, f) \
199          ((prot == QETH_PROT_IPV6) ? \
200                 qeth_is_supported6(c, f) : qeth_is_supported(c, f))
201 #define qeth_is_ipafunc_enabled(c, prot, f) \
202          ((prot == QETH_PROT_IPV6) ? \
203                 qeth_is_enabled6(c, f) : qeth_is_enabled(c, f))
204
205 #define QETH_IDX_FUNC_LEVEL_OSD          0x0101
206 #define QETH_IDX_FUNC_LEVEL_IQD          0x4108
207
208 #define QETH_BUFSIZE            4096
209 #define CCW_CMD_WRITE           0x01
210 #define CCW_CMD_READ            0x02
211
212 /**
213  * some more defs
214  */
215 #define QETH_TX_TIMEOUT         100 * HZ
216 #define QETH_RCD_TIMEOUT        60 * HZ
217 #define QETH_RECLAIM_WORK_TIME  HZ
218 #define QETH_MAX_PORTNO         15
219
220 /*IPv6 address autoconfiguration stuff*/
221 #define UNIQUE_ID_IF_CREATE_ADDR_FAILED 0xfffe
222 #define UNIQUE_ID_NOT_BY_CARD           0x10000
223
224 /*****************************************************************************/
225 /* QDIO queue and buffer handling                                            */
226 /*****************************************************************************/
227 #define QETH_MAX_QUEUES 4
228 #define QETH_IQD_MIN_TXQ        2       /* One for ucast, one for mcast. */
229 #define QETH_IQD_MCAST_TXQ      0
230 #define QETH_IQD_MIN_UCAST_TXQ  1
231 #define QETH_IN_BUF_SIZE_DEFAULT 65536
232 #define QETH_IN_BUF_COUNT_DEFAULT 64
233 #define QETH_IN_BUF_COUNT_HSDEFAULT 128
234 #define QETH_IN_BUF_COUNT_MIN 8
235 #define QETH_IN_BUF_COUNT_MAX 128
236 #define QETH_MAX_BUFFER_ELEMENTS(card) ((card)->qdio.in_buf_size >> 12)
237 #define QETH_IN_BUF_REQUEUE_THRESHOLD(card) \
238                  ((card)->qdio.in_buf_pool.buf_count / 2)
239
240 /* buffers we have to be behind before we get a PCI */
241 #define QETH_PCI_THRESHOLD_A(card) ((card)->qdio.in_buf_pool.buf_count+1)
242 /*enqueued free buffers left before we get a PCI*/
243 #define QETH_PCI_THRESHOLD_B(card) 0
244 /*not used unless the microcode gets patched*/
245 #define QETH_PCI_TIMER_VALUE(card) 3
246
247 /* priority queing */
248 #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING
249 #define QETH_DEFAULT_QUEUE    2
250 #define QETH_NO_PRIO_QUEUEING 0
251 #define QETH_PRIO_Q_ING_PREC  1
252 #define QETH_PRIO_Q_ING_TOS   2
253 #define QETH_PRIO_Q_ING_SKB   3
254 #define QETH_PRIO_Q_ING_VLAN  4
255
256 /* Packing */
257 #define QETH_LOW_WATERMARK_PACK  2
258 #define QETH_HIGH_WATERMARK_PACK 5
259 #define QETH_WATERMARK_PACK_FUZZ 1
260
261 /* large receive scatter gather copy break */
262 #define QETH_RX_SG_CB (PAGE_SIZE >> 1)
263 #define QETH_RX_PULL_LEN 256
264
265 struct qeth_hdr_layer3 {
266         __u8  id;
267         __u8  flags;
268         __u16 inbound_checksum; /*TSO:__u16 seqno */
269         __u32 token;            /*TSO: __u32 reserved */
270         __u16 length;
271         __u8  vlan_prio;
272         __u8  ext_flags;
273         __u16 vlan_id;
274         __u16 frame_offset;
275         union {
276                 /* TX: */
277                 struct in6_addr ipv6_addr;
278                 struct ipv4 {
279                         u8 res[12];
280                         u32 addr;
281                 } ipv4;
282                 /* RX: */
283                 struct rx {
284                         u8 res1[2];
285                         u8 src_mac[6];
286                         u8 res2[4];
287                         u16 vlan_id;
288                         u8 res3[2];
289                 } rx;
290         } next_hop;
291 };
292
293 struct qeth_hdr_layer2 {
294         __u8 id;
295         __u8 flags[3];
296         __u8 port_no;
297         __u8 hdr_length;
298         __u16 pkt_length;
299         __u16 seq_no;
300         __u16 vlan_id;
301         __u32 reserved;
302         __u8 reserved2[16];
303 } __attribute__ ((packed));
304
305 struct qeth_hdr_osn {
306         __u8 id;
307         __u8 reserved;
308         __u16 seq_no;
309         __u16 reserved2;
310         __u16 control_flags;
311         __u16 pdu_length;
312         __u8 reserved3[18];
313         __u32 ccid;
314 } __attribute__ ((packed));
315
316 struct qeth_hdr {
317         union {
318                 struct qeth_hdr_layer2 l2;
319                 struct qeth_hdr_layer3 l3;
320                 struct qeth_hdr_osn    osn;
321         } hdr;
322 } __attribute__ ((packed));
323
324 /*TCP Segmentation Offload header*/
325 struct qeth_hdr_ext_tso {
326         __u16 hdr_tot_len;
327         __u8  imb_hdr_no;
328         __u8  reserved;
329         __u8  hdr_type;
330         __u8  hdr_version;
331         __u16 hdr_len;
332         __u32 payload_len;
333         __u16 mss;
334         __u16 dg_hdr_len;
335         __u8  padding[16];
336 } __attribute__ ((packed));
337
338 struct qeth_hdr_tso {
339         struct qeth_hdr hdr;    /*hdr->hdr.l3.xxx*/
340         struct qeth_hdr_ext_tso ext;
341 } __attribute__ ((packed));
342
343
344 /* flags for qeth_hdr.flags */
345 #define QETH_HDR_PASSTHRU 0x10
346 #define QETH_HDR_IPV6     0x80
347 #define QETH_HDR_CAST_MASK 0x07
348 enum qeth_cast_flags {
349         QETH_CAST_UNICAST   = 0x06,
350         QETH_CAST_MULTICAST = 0x04,
351         QETH_CAST_BROADCAST = 0x05,
352         QETH_CAST_ANYCAST   = 0x07,
353         QETH_CAST_NOCAST    = 0x00,
354 };
355
356 enum qeth_layer2_frame_flags {
357         QETH_LAYER2_FLAG_MULTICAST = 0x01,
358         QETH_LAYER2_FLAG_BROADCAST = 0x02,
359         QETH_LAYER2_FLAG_UNICAST   = 0x04,
360         QETH_LAYER2_FLAG_VLAN      = 0x10,
361 };
362
363 enum qeth_header_ids {
364         QETH_HEADER_TYPE_LAYER3 = 0x01,
365         QETH_HEADER_TYPE_LAYER2 = 0x02,
366         QETH_HEADER_TYPE_L3_TSO = 0x03,
367         QETH_HEADER_TYPE_OSN    = 0x04,
368         QETH_HEADER_TYPE_L2_TSO = 0x06,
369 };
370 /* flags for qeth_hdr.ext_flags */
371 #define QETH_HDR_EXT_VLAN_FRAME       0x01
372 #define QETH_HDR_EXT_TOKEN_ID         0x02
373 #define QETH_HDR_EXT_INCLUDE_VLAN_TAG 0x04
374 #define QETH_HDR_EXT_SRC_MAC_ADDR     0x08
375 #define QETH_HDR_EXT_CSUM_HDR_REQ     0x10
376 #define QETH_HDR_EXT_CSUM_TRANSP_REQ  0x20
377 #define QETH_HDR_EXT_UDP              0x40 /*bit off for TCP*/
378
379 enum qeth_qdio_info_states {
380         QETH_QDIO_UNINITIALIZED,
381         QETH_QDIO_ALLOCATED,
382         QETH_QDIO_ESTABLISHED,
383         QETH_QDIO_CLEANING
384 };
385
386 struct qeth_buffer_pool_entry {
387         struct list_head list;
388         struct list_head init_list;
389         void *elements[QDIO_MAX_ELEMENTS_PER_BUFFER];
390 };
391
392 struct qeth_qdio_buffer_pool {
393         struct list_head entry_list;
394         int buf_count;
395 };
396
397 struct qeth_qdio_buffer {
398         struct qdio_buffer *buffer;
399         /* the buffer pool entry currently associated to this buffer */
400         struct qeth_buffer_pool_entry *pool_entry;
401         struct sk_buff *rx_skb;
402 };
403
404 struct 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 };
409
410 enum qeth_qdio_out_buffer_state {
411         /* Owned by driver, in order to be filled. */
412         QETH_QDIO_BUF_EMPTY,
413         /* Filled by driver; owned by hardware in order to be sent. */
414         QETH_QDIO_BUF_PRIMED,
415         /* Identified to be pending in TPQ. */
416         QETH_QDIO_BUF_PENDING,
417         /* Found in completion queue. */
418         QETH_QDIO_BUF_IN_CQ,
419         /* Handled via transfer pending / completion queue. */
420         QETH_QDIO_BUF_HANDLED_DELAYED,
421 };
422
423 struct qeth_qdio_out_buffer {
424         struct qdio_buffer *buffer;
425         atomic_t state;
426         int next_element_to_fill;
427         struct sk_buff_head skb_list;
428         int is_header[QDIO_MAX_ELEMENTS_PER_BUFFER];
429
430         struct qeth_qdio_out_q *q;
431         struct qeth_qdio_out_buffer *next_pending;
432 };
433
434 struct qeth_card;
435
436 enum qeth_out_q_states {
437        QETH_OUT_Q_UNLOCKED,
438        QETH_OUT_Q_LOCKED,
439        QETH_OUT_Q_LOCKED_FLUSH,
440 };
441
442 #define QETH_CARD_STAT_ADD(_c, _stat, _val)     ((_c)->stats._stat += (_val))
443 #define QETH_CARD_STAT_INC(_c, _stat)           QETH_CARD_STAT_ADD(_c, _stat, 1)
444
445 #define QETH_TXQ_STAT_ADD(_q, _stat, _val)      ((_q)->stats._stat += (_val))
446 #define QETH_TXQ_STAT_INC(_q, _stat)            QETH_TXQ_STAT_ADD(_q, _stat, 1)
447
448 struct qeth_card_stats {
449         u64 rx_bufs;
450         u64 rx_skb_csum;
451         u64 rx_sg_skbs;
452         u64 rx_sg_frags;
453         u64 rx_sg_alloc_page;
454
455         /* rtnl_link_stats64 */
456         u64 rx_packets;
457         u64 rx_bytes;
458         u64 rx_errors;
459         u64 rx_dropped;
460         u64 rx_multicast;
461 };
462
463 struct qeth_out_q_stats {
464         u64 bufs;
465         u64 bufs_pack;
466         u64 buf_elements;
467         u64 skbs_pack;
468         u64 skbs_sg;
469         u64 skbs_csum;
470         u64 skbs_tso;
471         u64 skbs_linearized;
472         u64 skbs_linearized_fail;
473         u64 tso_bytes;
474         u64 packing_mode_switch;
475         u64 stopped;
476
477         /* rtnl_link_stats64 */
478         u64 tx_packets;
479         u64 tx_bytes;
480         u64 tx_errors;
481         u64 tx_dropped;
482 };
483
484 struct qeth_qdio_out_q {
485         struct qdio_buffer *qdio_bufs[QDIO_MAX_BUFFERS_PER_Q];
486         struct qeth_qdio_out_buffer *bufs[QDIO_MAX_BUFFERS_PER_Q];
487         struct qdio_outbuf_state *bufstates; /* convenience pointer */
488         struct qeth_out_q_stats stats;
489         u8 next_buf_to_fill;
490         u8 max_elements;
491         u8 queue_no;
492         u8 do_pack;
493         struct qeth_card *card;
494         atomic_t state;
495         /*
496          * number of buffers that are currently filled (PRIMED)
497          * -> these buffers are hardware-owned
498          */
499         atomic_t used_buffers;
500         /* indicates whether PCI flag must be set (or if one is outstanding) */
501         atomic_t set_pci_flags_count;
502 };
503
504 static inline bool qeth_out_queue_is_full(struct qeth_qdio_out_q *queue)
505 {
506         return atomic_read(&queue->used_buffers) >= QDIO_MAX_BUFFERS_PER_Q;
507 }
508
509 struct qeth_qdio_info {
510         atomic_t state;
511         /* input */
512         int no_in_queues;
513         struct qeth_qdio_q *in_q;
514         struct qeth_qdio_q *c_q;
515         struct qeth_qdio_buffer_pool in_buf_pool;
516         struct qeth_qdio_buffer_pool init_pool;
517         int in_buf_size;
518
519         /* output */
520         int no_out_queues;
521         struct qeth_qdio_out_q *out_qs[QETH_MAX_QUEUES];
522         struct qdio_outbuf_state *out_bufstates;
523
524         /* priority queueing */
525         int do_prio_queueing;
526         int default_out_queue;
527 };
528
529 /**
530  *  channel state machine
531  */
532 enum qeth_channel_states {
533         CH_STATE_UP,
534         CH_STATE_DOWN,
535         CH_STATE_HALTED,
536         CH_STATE_STOPPED,
537 };
538 /**
539  * card state machine
540  */
541 enum qeth_card_states {
542         CARD_STATE_DOWN,
543         CARD_STATE_HARDSETUP,
544         CARD_STATE_SOFTSETUP,
545 };
546
547 /**
548  * Protocol versions
549  */
550 enum qeth_prot_versions {
551         QETH_PROT_NONE = 0x0000,
552         QETH_PROT_IPV4 = 0x0004,
553         QETH_PROT_IPV6 = 0x0006,
554 };
555
556 enum qeth_cq {
557         QETH_CQ_DISABLED = 0,
558         QETH_CQ_ENABLED = 1,
559         QETH_CQ_NOTAVAILABLE = 2,
560 };
561
562 struct qeth_ipato {
563         bool enabled;
564         bool invert4;
565         bool invert6;
566         struct list_head entries;
567 };
568
569 struct qeth_channel {
570         struct ccw_device *ccwdev;
571         enum qeth_channel_states state;
572         atomic_t irq_pending;
573 };
574
575 struct qeth_cmd_buffer {
576         unsigned int length;
577         refcount_t ref_count;
578         struct qeth_channel *channel;
579         struct qeth_reply *reply;
580         long timeout;
581         unsigned char *data;
582         void (*finalize)(struct qeth_card *card, struct qeth_cmd_buffer *iob);
583         void (*callback)(struct qeth_card *card, struct qeth_cmd_buffer *iob);
584 };
585
586 static inline void qeth_get_cmd(struct qeth_cmd_buffer *iob)
587 {
588         refcount_inc(&iob->ref_count);
589 }
590
591 static inline struct qeth_ipa_cmd *__ipa_cmd(struct qeth_cmd_buffer *iob)
592 {
593         return (struct qeth_ipa_cmd *)(iob->data + IPA_PDU_HEADER_SIZE);
594 }
595
596 static inline struct ccw1 *__ccw_from_cmd(struct qeth_cmd_buffer *iob)
597 {
598         return (struct ccw1 *)(iob->data + ALIGN(iob->length, 8));
599 }
600
601 static inline bool qeth_trylock_channel(struct qeth_channel *channel)
602 {
603         return atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0;
604 }
605
606 /**
607  *  OSA card related definitions
608  */
609 struct qeth_token {
610         __u32 issuer_rm_w;
611         __u32 issuer_rm_r;
612         __u32 cm_filter_w;
613         __u32 cm_filter_r;
614         __u32 cm_connection_w;
615         __u32 cm_connection_r;
616         __u32 ulp_filter_w;
617         __u32 ulp_filter_r;
618         __u32 ulp_connection_w;
619         __u32 ulp_connection_r;
620 };
621
622 struct qeth_seqno {
623         __u32 trans_hdr;
624         __u32 pdu_hdr;
625         __u32 pdu_hdr_ack;
626         __u16 ipa;
627 };
628
629 struct qeth_reply {
630         struct list_head list;
631         struct completion received;
632         spinlock_t lock;
633         int (*callback)(struct qeth_card *, struct qeth_reply *,
634                 unsigned long);
635         u32 seqno;
636         unsigned long offset;
637         int rc;
638         void *param;
639         refcount_t refcnt;
640 };
641
642 struct qeth_card_blkt {
643         int time_total;
644         int inter_packet;
645         int inter_packet_jumbo;
646 };
647
648 #define QETH_BROADCAST_WITH_ECHO    0x01
649 #define QETH_BROADCAST_WITHOUT_ECHO 0x02
650 #define QETH_LAYER2_MAC_REGISTERED  0x02
651 struct qeth_card_info {
652         unsigned short unit_addr2;
653         unsigned short cula;
654         unsigned short chpid;
655         __u16 func_level;
656         char mcl_level[QETH_MCL_LENGTH + 1];
657         u8 open_when_online:1;
658         u8 use_v1_blkt:1;
659         u8 is_vm_nic:1;
660         int mac_bits;
661         enum qeth_card_types type;
662         enum qeth_link_types link_type;
663         int broadcast_capable;
664         int unique_id;
665         bool layer_enforced;
666         struct qeth_card_blkt blkt;
667         enum qeth_ipa_promisc_modes promisc_mode;
668         __u32 diagass_support;
669         __u32 hwtrap;
670 };
671
672 enum qeth_discipline_id {
673         QETH_DISCIPLINE_UNDETERMINED = -1,
674         QETH_DISCIPLINE_LAYER3 = 0,
675         QETH_DISCIPLINE_LAYER2 = 1,
676 };
677
678 struct qeth_card_options {
679         struct qeth_routing_info route4;
680         struct qeth_ipa_info ipa4;
681         struct qeth_ipa_info adp; /*Adapter parameters*/
682         struct qeth_routing_info route6;
683         struct qeth_ipa_info ipa6;
684         struct qeth_sbp_info sbp; /* SETBRIDGEPORT options */
685         struct qeth_vnicc_info vnicc; /* VNICC options */
686         int fake_broadcast;
687         enum qeth_discipline_id layer;
688         int rx_sg_cb;
689         enum qeth_ipa_isolation_modes isolation;
690         enum qeth_ipa_isolation_modes prev_isolation;
691         int sniffer;
692         enum qeth_cq cq;
693         char hsuid[9];
694 };
695
696 #define IS_LAYER2(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER2)
697 #define IS_LAYER3(card) ((card)->options.layer == QETH_DISCIPLINE_LAYER3)
698
699 /*
700  * thread bits for qeth_card thread masks
701  */
702 enum qeth_threads {
703         QETH_RECOVER_THREAD = 1,
704 };
705
706 struct qeth_osn_info {
707         int (*assist_cb)(struct net_device *dev, void *data);
708         int (*data_cb)(struct sk_buff *skb);
709 };
710
711 struct qeth_discipline {
712         const struct device_type *devtype;
713         int (*process_rx_buffer)(struct qeth_card *card, int budget, int *done);
714         int (*recover)(void *ptr);
715         int (*setup) (struct ccwgroup_device *);
716         void (*remove) (struct ccwgroup_device *);
717         int (*set_online) (struct ccwgroup_device *);
718         int (*set_offline) (struct ccwgroup_device *);
719         int (*do_ioctl)(struct net_device *dev, struct ifreq *rq, int cmd);
720         int (*control_event_handler)(struct qeth_card *card,
721                                         struct qeth_ipa_cmd *cmd);
722 };
723
724 enum qeth_addr_disposition {
725         QETH_DISP_ADDR_DELETE = 0,
726         QETH_DISP_ADDR_DO_NOTHING = 1,
727         QETH_DISP_ADDR_ADD = 2,
728 };
729
730 struct qeth_rx {
731         int b_count;
732         int b_index;
733         struct qdio_buffer_element *b_element;
734         int e_offset;
735         int qdio_err;
736 };
737
738 struct carrier_info {
739         __u8  card_type;
740         __u16 port_mode;
741         __u32 port_speed;
742 };
743
744 struct qeth_switch_info {
745         __u32 capabilities;
746         __u32 settings;
747 };
748
749 #define QETH_NAPI_WEIGHT NAPI_POLL_WEIGHT
750
751 struct qeth_card {
752         enum qeth_card_states state;
753         spinlock_t lock;
754         struct ccwgroup_device *gdev;
755         struct qeth_cmd_buffer *read_cmd;
756         struct qeth_channel read;
757         struct qeth_channel write;
758         struct qeth_channel data;
759
760         struct net_device *dev;
761         struct qeth_card_stats stats;
762         struct qeth_card_info info;
763         struct qeth_token token;
764         struct qeth_seqno seqno;
765         struct qeth_card_options options;
766
767         struct workqueue_struct *event_wq;
768         struct workqueue_struct *cmd_wq;
769         wait_queue_head_t wait_q;
770         unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
771         DECLARE_HASHTABLE(mac_htable, 4);
772         DECLARE_HASHTABLE(ip_htable, 4);
773         struct mutex ip_lock;
774         DECLARE_HASHTABLE(ip_mc_htable, 4);
775         struct work_struct rx_mode_work;
776         struct work_struct kernel_thread_starter;
777         spinlock_t thread_mask_lock;
778         unsigned long thread_start_mask;
779         unsigned long thread_allowed_mask;
780         unsigned long thread_running_mask;
781         struct qeth_ipato ipato;
782         struct list_head cmd_waiter_list;
783         /* QDIO buffer handling */
784         struct qeth_qdio_info qdio;
785         int read_or_write_problem;
786         struct qeth_osn_info osn_info;
787         struct qeth_discipline *discipline;
788         atomic_t force_alloc_skb;
789         struct service_level qeth_service_level;
790         struct qdio_ssqd_desc ssqd;
791         debug_info_t *debug;
792         struct mutex conf_mutex;
793         struct mutex discipline_mutex;
794         struct napi_struct napi;
795         struct qeth_rx rx;
796         struct delayed_work buffer_reclaim_work;
797         int reclaim_index;
798         struct work_struct close_dev_work;
799 };
800
801 static inline bool qeth_card_hw_is_reachable(struct qeth_card *card)
802 {
803         return card->state == CARD_STATE_SOFTSETUP;
804 }
805
806 struct qeth_trap_id {
807         __u16 lparnr;
808         char vmname[8];
809         __u8 chpid;
810         __u8 ssid;
811         __u16 devno;
812 } __packed;
813
814 /*some helper functions*/
815 #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
816
817 static inline bool qeth_netdev_is_registered(struct net_device *dev)
818 {
819         return dev->netdev_ops != NULL;
820 }
821
822 static inline u16 qeth_iqd_translate_txq(struct net_device *dev, u16 txq)
823 {
824         if (txq == QETH_IQD_MCAST_TXQ)
825                 return dev->num_tx_queues - 1;
826         if (txq == dev->num_tx_queues - 1)
827                 return QETH_IQD_MCAST_TXQ;
828         return txq;
829 }
830
831 static inline void qeth_scrub_qdio_buffer(struct qdio_buffer *buf,
832                                           unsigned int elements)
833 {
834         unsigned int i;
835
836         for (i = 0; i < elements; i++)
837                 memset(&buf->element[i], 0, sizeof(struct qdio_buffer_element));
838         buf->element[14].sflags = 0;
839         buf->element[15].sflags = 0;
840 }
841
842 /**
843  * qeth_get_elements_for_range() -      find number of SBALEs to cover range.
844  * @start:                              Start of the address range.
845  * @end:                                Address after the end of the range.
846  *
847  * Returns the number of pages, and thus QDIO buffer elements, needed to cover
848  * the specified address range.
849  */
850 static inline int qeth_get_elements_for_range(addr_t start, addr_t end)
851 {
852         return PFN_UP(end) - PFN_DOWN(start);
853 }
854
855 static inline int qeth_get_ip_version(struct sk_buff *skb)
856 {
857         struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
858         __be16 prot = veth->h_vlan_proto;
859
860         if (prot == htons(ETH_P_8021Q))
861                 prot = veth->h_vlan_encapsulated_proto;
862
863         switch (prot) {
864         case htons(ETH_P_IPV6):
865                 return 6;
866         case htons(ETH_P_IP):
867                 return 4;
868         default:
869                 return 0;
870         }
871 }
872
873 static inline int qeth_get_ether_cast_type(struct sk_buff *skb)
874 {
875         u8 *addr = eth_hdr(skb)->h_dest;
876
877         if (is_multicast_ether_addr(addr))
878                 return is_broadcast_ether_addr(addr) ? RTN_BROADCAST :
879                                                        RTN_MULTICAST;
880         return RTN_UNICAST;
881 }
882
883 static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb, int ipv)
884 {
885         struct dst_entry *dst = skb_dst(skb);
886         struct rt6_info *rt;
887
888         rt = (struct rt6_info *) dst;
889         if (dst)
890                 dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0);
891         return dst;
892 }
893
894 static inline void qeth_rx_csum(struct qeth_card *card, struct sk_buff *skb,
895                                 u8 flags)
896 {
897         if ((card->dev->features & NETIF_F_RXCSUM) &&
898             (flags & QETH_HDR_EXT_CSUM_TRANSP_REQ)) {
899                 skb->ip_summed = CHECKSUM_UNNECESSARY;
900                 QETH_CARD_STAT_INC(card, rx_skb_csum);
901         } else {
902                 skb->ip_summed = CHECKSUM_NONE;
903         }
904 }
905
906 static inline void qeth_tx_csum(struct sk_buff *skb, u8 *flags, int ipv)
907 {
908         *flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
909         if ((ipv == 4 && ip_hdr(skb)->protocol == IPPROTO_UDP) ||
910             (ipv == 6 && ipv6_hdr(skb)->nexthdr == IPPROTO_UDP))
911                 *flags |= QETH_HDR_EXT_UDP;
912 }
913
914 static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
915                 struct qeth_buffer_pool_entry *entry)
916 {
917         list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
918 }
919
920 static inline int qeth_is_diagass_supported(struct qeth_card *card,
921                 enum qeth_diags_cmds cmd)
922 {
923         return card->info.diagass_support & (__u32)cmd;
924 }
925
926 int qeth_send_simple_setassparms_prot(struct qeth_card *card,
927                                       enum qeth_ipa_funcs ipa_func,
928                                       u16 cmd_code, u32 *data,
929                                       enum qeth_prot_versions prot);
930 /* IPv4 variant */
931 static inline int qeth_send_simple_setassparms(struct qeth_card *card,
932                                                enum qeth_ipa_funcs ipa_func,
933                                                u16 cmd_code, u32 *data)
934 {
935         return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
936                                                  data, QETH_PROT_IPV4);
937 }
938
939 static inline int qeth_send_simple_setassparms_v6(struct qeth_card *card,
940                                                   enum qeth_ipa_funcs ipa_func,
941                                                   u16 cmd_code, u32 *data)
942 {
943         return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
944                                                  data, QETH_PROT_IPV6);
945 }
946
947 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb);
948
949 extern struct qeth_discipline qeth_l2_discipline;
950 extern struct qeth_discipline qeth_l3_discipline;
951 extern const struct ethtool_ops qeth_ethtool_ops;
952 extern const struct ethtool_ops qeth_osn_ethtool_ops;
953 extern const struct attribute_group *qeth_generic_attr_groups[];
954 extern const struct attribute_group *qeth_osn_attr_groups[];
955 extern const struct attribute_group qeth_device_attr_group;
956 extern const struct attribute_group qeth_device_blkt_group;
957 extern const struct device_type qeth_generic_devtype;
958
959 const char *qeth_get_cardname_short(struct qeth_card *);
960 int qeth_realloc_buffer_pool(struct qeth_card *, int);
961 int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
962 void qeth_core_free_discipline(struct qeth_card *);
963
964 /* exports for qeth discipline device drivers */
965 extern struct kmem_cache *qeth_core_header_cache;
966 extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
967
968 struct net_device *qeth_clone_netdev(struct net_device *orig);
969 struct qeth_card *qeth_get_card_by_busid(char *bus_id);
970 void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
971 int qeth_threads_running(struct qeth_card *, unsigned long);
972 int qeth_do_run_thread(struct qeth_card *, unsigned long);
973 void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
974 void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
975 int qeth_core_hardsetup_card(struct qeth_card *card, bool *carrier_ok);
976 void qeth_print_status_message(struct qeth_card *);
977 int qeth_init_qdio_queues(struct qeth_card *);
978 int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
979                   int (*reply_cb)
980                   (struct qeth_card *, struct qeth_reply *, unsigned long),
981                   void *);
982 struct qeth_cmd_buffer *qeth_ipa_alloc_cmd(struct qeth_card *card,
983                                            enum qeth_ipa_cmds cmd_code,
984                                            enum qeth_prot_versions prot,
985                                            unsigned int data_length);
986 struct qeth_cmd_buffer *qeth_alloc_cmd(struct qeth_channel *channel,
987                                        unsigned int length, unsigned int ccws,
988                                        long timeout);
989 struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
990                                                  enum qeth_ipa_funcs ipa_func,
991                                                  u16 cmd_code,
992                                                  unsigned int data_length,
993                                                  enum qeth_prot_versions prot);
994 struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
995                                           enum qeth_diags_cmds sub_cmd,
996                                           unsigned int data_length);
997 void qeth_put_cmd(struct qeth_cmd_buffer *iob);
998
999 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
1000                 struct qeth_qdio_buffer *, struct qdio_buffer_element **, int *,
1001                 struct qeth_hdr **);
1002 void qeth_schedule_recovery(struct qeth_card *);
1003 int qeth_poll(struct napi_struct *napi, int budget);
1004 void qeth_clear_ipacmd_list(struct qeth_card *);
1005 int qeth_qdio_clear_card(struct qeth_card *, int);
1006 void qeth_clear_working_pool_list(struct qeth_card *);
1007 void qeth_drain_output_queues(struct qeth_card *card);
1008 void qeth_setadp_promisc_mode(struct qeth_card *);
1009 int qeth_setadpparms_change_macaddr(struct qeth_card *);
1010 void qeth_tx_timeout(struct net_device *);
1011 void qeth_notify_reply(struct qeth_reply *reply, int reason);
1012 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1013                           u16 cmd_length);
1014 int qeth_query_switch_attributes(struct qeth_card *card,
1015                                   struct qeth_switch_info *sw_info);
1016 int qeth_query_card_info(struct qeth_card *card,
1017                          struct carrier_info *carrier_info);
1018 unsigned int qeth_count_elements(struct sk_buff *skb, unsigned int data_offset);
1019 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
1020                         struct sk_buff *skb, struct qeth_hdr *hdr,
1021                         unsigned int offset, unsigned int hd_len,
1022                         int elements_needed);
1023 int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1024 void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
1025 int qeth_set_access_ctrl_online(struct qeth_card *card, int fallback);
1026 int qeth_configure_cq(struct qeth_card *, enum qeth_cq);
1027 int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
1028 void qeth_trace_features(struct qeth_card *);
1029 int qeth_setassparms_cb(struct qeth_card *, struct qeth_reply *, unsigned long);
1030 int qeth_set_features(struct net_device *, netdev_features_t);
1031 void qeth_enable_hw_features(struct net_device *dev);
1032 netdev_features_t qeth_fix_features(struct net_device *, netdev_features_t);
1033 netdev_features_t qeth_features_check(struct sk_buff *skb,
1034                                       struct net_device *dev,
1035                                       netdev_features_t features);
1036 void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
1037 u16 qeth_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
1038                           u8 cast_type, struct net_device *sb_dev);
1039 int qeth_open(struct net_device *dev);
1040 int qeth_stop(struct net_device *dev);
1041
1042 int qeth_vm_request_mac(struct qeth_card *card);
1043 int qeth_xmit(struct qeth_card *card, struct sk_buff *skb,
1044               struct qeth_qdio_out_q *queue, int ipv,
1045               void (*fill_header)(struct qeth_qdio_out_q *queue,
1046                                   struct qeth_hdr *hdr, struct sk_buff *skb,
1047                                   int ipv, unsigned int data_len));
1048
1049 /* exports for OSN */
1050 int qeth_osn_assist(struct net_device *, void *, int);
1051 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
1052                 int (*assist_cb)(struct net_device *, void *),
1053                 int (*data_cb)(struct sk_buff *));
1054 void qeth_osn_deregister(struct net_device *);
1055
1056 #endif /* __QETH_CORE_H__ */