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