xref: /openbmc/linux/drivers/s390/net/qeth_core.h (revision ccf988b6)
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 	int (*callback)(struct qeth_card *, struct qeth_reply *,
633 		unsigned long);
634 	u32 seqno;
635 	unsigned long offset;
636 	int rc;
637 	void *param;
638 	refcount_t refcnt;
639 };
640 
641 struct qeth_card_blkt {
642 	int time_total;
643 	int inter_packet;
644 	int inter_packet_jumbo;
645 };
646 
647 #define QETH_BROADCAST_WITH_ECHO    0x01
648 #define QETH_BROADCAST_WITHOUT_ECHO 0x02
649 #define QETH_LAYER2_MAC_REGISTERED  0x02
650 struct qeth_card_info {
651 	unsigned short unit_addr2;
652 	unsigned short cula;
653 	unsigned short chpid;
654 	__u16 func_level;
655 	char mcl_level[QETH_MCL_LENGTH + 1];
656 	u8 open_when_online:1;
657 	u8 use_v1_blkt:1;
658 	u8 is_vm_nic:1;
659 	int mac_bits;
660 	enum qeth_card_types type;
661 	enum qeth_link_types link_type;
662 	int broadcast_capable;
663 	int unique_id;
664 	bool layer_enforced;
665 	struct qeth_card_blkt blkt;
666 	enum qeth_ipa_promisc_modes promisc_mode;
667 	__u32 diagass_support;
668 	__u32 hwtrap;
669 };
670 
671 enum qeth_discipline_id {
672 	QETH_DISCIPLINE_UNDETERMINED = -1,
673 	QETH_DISCIPLINE_LAYER3 = 0,
674 	QETH_DISCIPLINE_LAYER2 = 1,
675 };
676 
677 struct qeth_card_options {
678 	struct qeth_routing_info route4;
679 	struct qeth_ipa_info ipa4;
680 	struct qeth_ipa_info adp; /*Adapter parameters*/
681 	struct qeth_routing_info route6;
682 	struct qeth_ipa_info ipa6;
683 	struct qeth_sbp_info sbp; /* SETBRIDGEPORT options */
684 	struct qeth_vnicc_info vnicc; /* VNICC options */
685 	int fake_broadcast;
686 	enum qeth_discipline_id layer;
687 	int rx_sg_cb;
688 	enum qeth_ipa_isolation_modes isolation;
689 	enum qeth_ipa_isolation_modes prev_isolation;
690 	int sniffer;
691 	enum qeth_cq cq;
692 	char hsuid[9];
693 };
694 
695 #define	IS_LAYER2(card)	((card)->options.layer == QETH_DISCIPLINE_LAYER2)
696 #define	IS_LAYER3(card)	((card)->options.layer == QETH_DISCIPLINE_LAYER3)
697 
698 /*
699  * thread bits for qeth_card thread masks
700  */
701 enum qeth_threads {
702 	QETH_RECOVER_THREAD = 1,
703 };
704 
705 struct qeth_osn_info {
706 	int (*assist_cb)(struct net_device *dev, void *data);
707 	int (*data_cb)(struct sk_buff *skb);
708 };
709 
710 struct qeth_discipline {
711 	const struct device_type *devtype;
712 	int (*process_rx_buffer)(struct qeth_card *card, int budget, int *done);
713 	int (*recover)(void *ptr);
714 	int (*setup) (struct ccwgroup_device *);
715 	void (*remove) (struct ccwgroup_device *);
716 	int (*set_online) (struct ccwgroup_device *);
717 	int (*set_offline) (struct ccwgroup_device *);
718 	int (*do_ioctl)(struct net_device *dev, struct ifreq *rq, int cmd);
719 	int (*control_event_handler)(struct qeth_card *card,
720 					struct qeth_ipa_cmd *cmd);
721 };
722 
723 enum qeth_addr_disposition {
724 	QETH_DISP_ADDR_DELETE = 0,
725 	QETH_DISP_ADDR_DO_NOTHING = 1,
726 	QETH_DISP_ADDR_ADD = 2,
727 };
728 
729 struct qeth_rx {
730 	int b_count;
731 	int b_index;
732 	struct qdio_buffer_element *b_element;
733 	int e_offset;
734 	int qdio_err;
735 };
736 
737 struct carrier_info {
738 	__u8  card_type;
739 	__u16 port_mode;
740 	__u32 port_speed;
741 };
742 
743 struct qeth_switch_info {
744 	__u32 capabilities;
745 	__u32 settings;
746 };
747 
748 #define QETH_NAPI_WEIGHT NAPI_POLL_WEIGHT
749 
750 struct qeth_card {
751 	enum qeth_card_states state;
752 	spinlock_t lock;
753 	struct ccwgroup_device *gdev;
754 	struct qeth_cmd_buffer *read_cmd;
755 	struct qeth_channel read;
756 	struct qeth_channel write;
757 	struct qeth_channel data;
758 
759 	struct net_device *dev;
760 	struct qeth_card_stats stats;
761 	struct qeth_card_info info;
762 	struct qeth_token token;
763 	struct qeth_seqno seqno;
764 	struct qeth_card_options options;
765 
766 	struct workqueue_struct *event_wq;
767 	struct workqueue_struct *cmd_wq;
768 	wait_queue_head_t wait_q;
769 	unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
770 	DECLARE_HASHTABLE(mac_htable, 4);
771 	DECLARE_HASHTABLE(ip_htable, 4);
772 	struct mutex ip_lock;
773 	DECLARE_HASHTABLE(ip_mc_htable, 4);
774 	struct work_struct rx_mode_work;
775 	struct work_struct kernel_thread_starter;
776 	spinlock_t thread_mask_lock;
777 	unsigned long thread_start_mask;
778 	unsigned long thread_allowed_mask;
779 	unsigned long thread_running_mask;
780 	struct qeth_ipato ipato;
781 	struct list_head cmd_waiter_list;
782 	/* QDIO buffer handling */
783 	struct qeth_qdio_info qdio;
784 	int read_or_write_problem;
785 	struct qeth_osn_info osn_info;
786 	struct qeth_discipline *discipline;
787 	atomic_t force_alloc_skb;
788 	struct service_level qeth_service_level;
789 	struct qdio_ssqd_desc ssqd;
790 	debug_info_t *debug;
791 	struct mutex conf_mutex;
792 	struct mutex discipline_mutex;
793 	struct napi_struct napi;
794 	struct qeth_rx rx;
795 	struct delayed_work buffer_reclaim_work;
796 	int reclaim_index;
797 	struct work_struct close_dev_work;
798 };
799 
800 static inline bool qeth_card_hw_is_reachable(struct qeth_card *card)
801 {
802 	return card->state == CARD_STATE_SOFTSETUP;
803 }
804 
805 struct qeth_trap_id {
806 	__u16 lparnr;
807 	char vmname[8];
808 	__u8 chpid;
809 	__u8 ssid;
810 	__u16 devno;
811 } __packed;
812 
813 /*some helper functions*/
814 #define QETH_CARD_IFNAME(card) (((card)->dev)? (card)->dev->name : "")
815 
816 static inline bool qeth_netdev_is_registered(struct net_device *dev)
817 {
818 	return dev->netdev_ops != NULL;
819 }
820 
821 static inline u16 qeth_iqd_translate_txq(struct net_device *dev, u16 txq)
822 {
823 	if (txq == QETH_IQD_MCAST_TXQ)
824 		return dev->num_tx_queues - 1;
825 	if (txq == dev->num_tx_queues - 1)
826 		return QETH_IQD_MCAST_TXQ;
827 	return txq;
828 }
829 
830 static inline void qeth_scrub_qdio_buffer(struct qdio_buffer *buf,
831 					  unsigned int elements)
832 {
833 	unsigned int i;
834 
835 	for (i = 0; i < elements; i++)
836 		memset(&buf->element[i], 0, sizeof(struct qdio_buffer_element));
837 	buf->element[14].sflags = 0;
838 	buf->element[15].sflags = 0;
839 }
840 
841 /**
842  * qeth_get_elements_for_range() -	find number of SBALEs to cover range.
843  * @start:				Start of the address range.
844  * @end:				Address after the end of the range.
845  *
846  * Returns the number of pages, and thus QDIO buffer elements, needed to cover
847  * the specified address range.
848  */
849 static inline int qeth_get_elements_for_range(addr_t start, addr_t end)
850 {
851 	return PFN_UP(end) - PFN_DOWN(start);
852 }
853 
854 static inline int qeth_get_ip_version(struct sk_buff *skb)
855 {
856 	struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
857 	__be16 prot = veth->h_vlan_proto;
858 
859 	if (prot == htons(ETH_P_8021Q))
860 		prot = veth->h_vlan_encapsulated_proto;
861 
862 	switch (prot) {
863 	case htons(ETH_P_IPV6):
864 		return 6;
865 	case htons(ETH_P_IP):
866 		return 4;
867 	default:
868 		return 0;
869 	}
870 }
871 
872 static inline int qeth_get_ether_cast_type(struct sk_buff *skb)
873 {
874 	u8 *addr = eth_hdr(skb)->h_dest;
875 
876 	if (is_multicast_ether_addr(addr))
877 		return is_broadcast_ether_addr(addr) ? RTN_BROADCAST :
878 						       RTN_MULTICAST;
879 	return RTN_UNICAST;
880 }
881 
882 static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb, int ipv)
883 {
884 	struct dst_entry *dst = skb_dst(skb);
885 	struct rt6_info *rt;
886 
887 	rt = (struct rt6_info *) dst;
888 	if (dst)
889 		dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0);
890 	return dst;
891 }
892 
893 static inline void qeth_rx_csum(struct qeth_card *card, struct sk_buff *skb,
894 				u8 flags)
895 {
896 	if ((card->dev->features & NETIF_F_RXCSUM) &&
897 	    (flags & QETH_HDR_EXT_CSUM_TRANSP_REQ)) {
898 		skb->ip_summed = CHECKSUM_UNNECESSARY;
899 		QETH_CARD_STAT_INC(card, rx_skb_csum);
900 	} else {
901 		skb->ip_summed = CHECKSUM_NONE;
902 	}
903 }
904 
905 static inline void qeth_tx_csum(struct sk_buff *skb, u8 *flags, int ipv)
906 {
907 	*flags |= QETH_HDR_EXT_CSUM_TRANSP_REQ;
908 	if ((ipv == 4 && ip_hdr(skb)->protocol == IPPROTO_UDP) ||
909 	    (ipv == 6 && ipv6_hdr(skb)->nexthdr == IPPROTO_UDP))
910 		*flags |= QETH_HDR_EXT_UDP;
911 }
912 
913 static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
914 		struct qeth_buffer_pool_entry *entry)
915 {
916 	list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
917 }
918 
919 static inline int qeth_is_diagass_supported(struct qeth_card *card,
920 		enum qeth_diags_cmds cmd)
921 {
922 	return card->info.diagass_support & (__u32)cmd;
923 }
924 
925 int qeth_send_simple_setassparms_prot(struct qeth_card *card,
926 				      enum qeth_ipa_funcs ipa_func,
927 				      u16 cmd_code, u32 *data,
928 				      enum qeth_prot_versions prot);
929 /* IPv4 variant */
930 static inline int qeth_send_simple_setassparms(struct qeth_card *card,
931 					       enum qeth_ipa_funcs ipa_func,
932 					       u16 cmd_code, u32 *data)
933 {
934 	return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
935 						 data, QETH_PROT_IPV4);
936 }
937 
938 static inline int qeth_send_simple_setassparms_v6(struct qeth_card *card,
939 						  enum qeth_ipa_funcs ipa_func,
940 						  u16 cmd_code, u32 *data)
941 {
942 	return qeth_send_simple_setassparms_prot(card, ipa_func, cmd_code,
943 						 data, QETH_PROT_IPV6);
944 }
945 
946 int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb);
947 
948 extern struct qeth_discipline qeth_l2_discipline;
949 extern struct qeth_discipline qeth_l3_discipline;
950 extern const struct ethtool_ops qeth_ethtool_ops;
951 extern const struct ethtool_ops qeth_osn_ethtool_ops;
952 extern const struct attribute_group *qeth_generic_attr_groups[];
953 extern const struct attribute_group *qeth_osn_attr_groups[];
954 extern const struct attribute_group qeth_device_attr_group;
955 extern const struct attribute_group qeth_device_blkt_group;
956 extern const struct device_type qeth_generic_devtype;
957 
958 const char *qeth_get_cardname_short(struct qeth_card *);
959 int qeth_realloc_buffer_pool(struct qeth_card *, int);
960 int qeth_core_load_discipline(struct qeth_card *, enum qeth_discipline_id);
961 void qeth_core_free_discipline(struct qeth_card *);
962 
963 /* exports for qeth discipline device drivers */
964 extern struct kmem_cache *qeth_core_header_cache;
965 extern struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS];
966 
967 struct net_device *qeth_clone_netdev(struct net_device *orig);
968 struct qeth_card *qeth_get_card_by_busid(char *bus_id);
969 void qeth_set_allowed_threads(struct qeth_card *, unsigned long , int);
970 int qeth_threads_running(struct qeth_card *, unsigned long);
971 int qeth_do_run_thread(struct qeth_card *, unsigned long);
972 void qeth_clear_thread_start_bit(struct qeth_card *, unsigned long);
973 void qeth_clear_thread_running_bit(struct qeth_card *, unsigned long);
974 int qeth_core_hardsetup_card(struct qeth_card *card, bool *carrier_ok);
975 void qeth_print_status_message(struct qeth_card *);
976 int qeth_init_qdio_queues(struct qeth_card *);
977 int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *,
978 		  int (*reply_cb)
979 		  (struct qeth_card *, struct qeth_reply *, unsigned long),
980 		  void *);
981 struct qeth_cmd_buffer *qeth_ipa_alloc_cmd(struct qeth_card *card,
982 					   enum qeth_ipa_cmds cmd_code,
983 					   enum qeth_prot_versions prot,
984 					   unsigned int data_length);
985 struct qeth_cmd_buffer *qeth_alloc_cmd(struct qeth_channel *channel,
986 				       unsigned int length, unsigned int ccws,
987 				       long timeout);
988 struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
989 						 enum qeth_ipa_funcs ipa_func,
990 						 u16 cmd_code,
991 						 unsigned int data_length,
992 						 enum qeth_prot_versions prot);
993 struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
994 					  enum qeth_diags_cmds sub_cmd,
995 					  unsigned int data_length);
996 void qeth_put_cmd(struct qeth_cmd_buffer *iob);
997 
998 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
999 		struct qeth_qdio_buffer *, struct qdio_buffer_element **, int *,
1000 		struct qeth_hdr **);
1001 void qeth_schedule_recovery(struct qeth_card *);
1002 int qeth_poll(struct napi_struct *napi, int budget);
1003 void qeth_clear_ipacmd_list(struct qeth_card *);
1004 int qeth_qdio_clear_card(struct qeth_card *, int);
1005 void qeth_clear_working_pool_list(struct qeth_card *);
1006 void qeth_drain_output_queues(struct qeth_card *card);
1007 void qeth_setadp_promisc_mode(struct qeth_card *);
1008 int qeth_setadpparms_change_macaddr(struct qeth_card *);
1009 void qeth_tx_timeout(struct net_device *);
1010 void qeth_notify_reply(struct qeth_reply *reply, int reason);
1011 void qeth_prepare_ipa_cmd(struct qeth_card *card, struct qeth_cmd_buffer *iob,
1012 			  u16 cmd_length);
1013 int qeth_query_switch_attributes(struct qeth_card *card,
1014 				  struct qeth_switch_info *sw_info);
1015 int qeth_query_card_info(struct qeth_card *card,
1016 			 struct carrier_info *carrier_info);
1017 unsigned int qeth_count_elements(struct sk_buff *skb, unsigned int data_offset);
1018 int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
1019 			struct sk_buff *skb, struct qeth_hdr *hdr,
1020 			unsigned int offset, unsigned int hd_len,
1021 			int elements_needed);
1022 int qeth_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1023 void qeth_dbf_longtext(debug_info_t *id, int level, char *text, ...);
1024 int qeth_set_access_ctrl_online(struct qeth_card *card, int fallback);
1025 int qeth_configure_cq(struct qeth_card *, enum qeth_cq);
1026 int qeth_hw_trap(struct qeth_card *, enum qeth_diags_trap_action);
1027 void qeth_trace_features(struct qeth_card *);
1028 int qeth_setassparms_cb(struct qeth_card *, struct qeth_reply *, unsigned long);
1029 int qeth_set_features(struct net_device *, netdev_features_t);
1030 void qeth_enable_hw_features(struct net_device *dev);
1031 netdev_features_t qeth_fix_features(struct net_device *, netdev_features_t);
1032 netdev_features_t qeth_features_check(struct sk_buff *skb,
1033 				      struct net_device *dev,
1034 				      netdev_features_t features);
1035 void qeth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats);
1036 u16 qeth_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
1037 			  u8 cast_type, struct net_device *sb_dev);
1038 int qeth_open(struct net_device *dev);
1039 int qeth_stop(struct net_device *dev);
1040 
1041 int qeth_vm_request_mac(struct qeth_card *card);
1042 int qeth_xmit(struct qeth_card *card, struct sk_buff *skb,
1043 	      struct qeth_qdio_out_q *queue, int ipv,
1044 	      void (*fill_header)(struct qeth_qdio_out_q *queue,
1045 				  struct qeth_hdr *hdr, struct sk_buff *skb,
1046 				  int ipv, unsigned int data_len));
1047 
1048 /* exports for OSN */
1049 int qeth_osn_assist(struct net_device *, void *, int);
1050 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **,
1051 		int (*assist_cb)(struct net_device *, void *),
1052 		int (*data_cb)(struct sk_buff *));
1053 void qeth_osn_deregister(struct net_device *);
1054 
1055 #endif /* __QETH_CORE_H__ */
1056