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