1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2eac3731bSJennifer Hunt /*
3eac3731bSJennifer Hunt * Copyright 2006 IBM Corporation
4eac3731bSJennifer Hunt * IUCV protocol stack for Linux on zSeries
5eac3731bSJennifer Hunt * Version 1.0
6eac3731bSJennifer Hunt * Author(s): Jennifer Hunt <jenhunt@us.ibm.com>
7eac3731bSJennifer Hunt *
8eac3731bSJennifer Hunt */
9eac3731bSJennifer Hunt
10eac3731bSJennifer Hunt #ifndef __AFIUCV_H
11eac3731bSJennifer Hunt #define __AFIUCV_H
12eac3731bSJennifer Hunt
13eac3731bSJennifer Hunt #include <asm/types.h>
14eac3731bSJennifer Hunt #include <asm/byteorder.h>
15eac3731bSJennifer Hunt #include <linux/list.h>
16eac3731bSJennifer Hunt #include <linux/poll.h>
17eac3731bSJennifer Hunt #include <linux/socket.h>
183881ac44SUrsula Braun #include <net/iucv/iucv.h>
19eac3731bSJennifer Hunt
20eac3731bSJennifer Hunt #ifndef AF_IUCV
21eac3731bSJennifer Hunt #define AF_IUCV 32
22eac3731bSJennifer Hunt #define PF_IUCV AF_IUCV
23eac3731bSJennifer Hunt #endif
24eac3731bSJennifer Hunt
25eac3731bSJennifer Hunt /* Connection and socket states */
26eac3731bSJennifer Hunt enum {
27eac3731bSJennifer Hunt IUCV_CONNECTED = 1,
28eac3731bSJennifer Hunt IUCV_OPEN,
29eac3731bSJennifer Hunt IUCV_BOUND,
30eac3731bSJennifer Hunt IUCV_LISTEN,
31eac3731bSJennifer Hunt IUCV_DISCONN,
32561e0360SJennifer Hunt IUCV_CLOSING,
33eac3731bSJennifer Hunt IUCV_CLOSED
34eac3731bSJennifer Hunt };
35eac3731bSJennifer Hunt
36eac3731bSJennifer Hunt #define IUCV_QUEUELEN_DEFAULT 65535
373881ac44SUrsula Braun #define IUCV_HIPER_MSGLIM_DEFAULT 128
38eac3731bSJennifer Hunt #define IUCV_CONN_TIMEOUT (HZ * 40)
39eac3731bSJennifer Hunt #define IUCV_DISCONN_TIMEOUT (HZ * 2)
40eac3731bSJennifer Hunt #define IUCV_CONN_IDLE_TIMEOUT (HZ * 60)
41eac3731bSJennifer Hunt #define IUCV_BUFSIZE_DEFAULT 32768
42eac3731bSJennifer Hunt
43eac3731bSJennifer Hunt /* IUCV socket address */
44eac3731bSJennifer Hunt struct sockaddr_iucv {
45eac3731bSJennifer Hunt sa_family_t siucv_family;
46eac3731bSJennifer Hunt unsigned short siucv_port; /* Reserved */
47eac3731bSJennifer Hunt unsigned int siucv_addr; /* Reserved */
48eac3731bSJennifer Hunt char siucv_nodeid[8]; /* Reserved */
49eac3731bSJennifer Hunt char siucv_user_id[8]; /* Guest User Id */
50eac3731bSJennifer Hunt char siucv_name[8]; /* Application Name */
51eac3731bSJennifer Hunt };
52eac3731bSJennifer Hunt
53eac3731bSJennifer Hunt
54eac3731bSJennifer Hunt /* Common socket structures and functions */
55f0703c80SUrsula Braun struct sock_msg_q {
56f0703c80SUrsula Braun struct iucv_path *path;
57f0703c80SUrsula Braun struct iucv_message msg;
58f0703c80SUrsula Braun struct list_head list;
59f0703c80SUrsula Braun spinlock_t lock;
60f0703c80SUrsula Braun };
61eac3731bSJennifer Hunt
623881ac44SUrsula Braun #define AF_IUCV_FLAG_ACK 0x1
633881ac44SUrsula Braun #define AF_IUCV_FLAG_SYN 0x2
643881ac44SUrsula Braun #define AF_IUCV_FLAG_FIN 0x4
653881ac44SUrsula Braun #define AF_IUCV_FLAG_WIN 0x8
6682492a35SUrsula Braun #define AF_IUCV_FLAG_SHT 0x10
673881ac44SUrsula Braun
683881ac44SUrsula Braun struct af_iucv_trans_hdr {
693881ac44SUrsula Braun u16 magic;
703881ac44SUrsula Braun u8 version;
713881ac44SUrsula Braun u8 flags;
723881ac44SUrsula Braun u16 window;
733881ac44SUrsula Braun char destNodeID[8];
743881ac44SUrsula Braun char destUserID[8];
753881ac44SUrsula Braun char destAppName[16];
763881ac44SUrsula Braun char srcNodeID[8];
773881ac44SUrsula Braun char srcUserID[8];
783881ac44SUrsula Braun char srcAppName[16]; /* => 70 bytes */
793881ac44SUrsula Braun struct iucv_message iucv_hdr; /* => 33 bytes */
803881ac44SUrsula Braun u8 pad; /* total 104 bytes */
813881ac44SUrsula Braun } __packed;
823881ac44SUrsula Braun
iucv_trans_hdr(struct sk_buff * skb)83cd11d112SJulian Wiedmann static inline struct af_iucv_trans_hdr *iucv_trans_hdr(struct sk_buff *skb)
84cd11d112SJulian Wiedmann {
85cd11d112SJulian Wiedmann return (struct af_iucv_trans_hdr *)skb_network_header(skb);
86cd11d112SJulian Wiedmann }
87cd11d112SJulian Wiedmann
883881ac44SUrsula Braun enum iucv_tx_notify {
893881ac44SUrsula Braun /* transmission of skb is completed and was successful */
903881ac44SUrsula Braun TX_NOTIFY_OK = 0,
913881ac44SUrsula Braun /* target is unreachable */
923881ac44SUrsula Braun TX_NOTIFY_UNREACHABLE = 1,
933881ac44SUrsula Braun /* transfer pending queue full */
943881ac44SUrsula Braun TX_NOTIFY_TPQFULL = 2,
953881ac44SUrsula Braun /* general error */
963881ac44SUrsula Braun TX_NOTIFY_GENERALERROR = 3,
973881ac44SUrsula Braun /* transmission of skb is pending - may interleave
983881ac44SUrsula Braun * with TX_NOTIFY_DELAYED_* */
993881ac44SUrsula Braun TX_NOTIFY_PENDING = 4,
1003881ac44SUrsula Braun /* transmission of skb was done successfully (delayed) */
1013881ac44SUrsula Braun TX_NOTIFY_DELAYED_OK = 5,
1023881ac44SUrsula Braun /* target unreachable (detected delayed) */
1033881ac44SUrsula Braun TX_NOTIFY_DELAYED_UNREACHABLE = 6,
1043881ac44SUrsula Braun /* general error (detected delayed) */
1053881ac44SUrsula Braun TX_NOTIFY_DELAYED_GENERALERROR = 7,
1063881ac44SUrsula Braun };
1073881ac44SUrsula Braun
108eac3731bSJennifer Hunt #define iucv_sk(__sk) ((struct iucv_sock *) __sk)
109eac3731bSJennifer Hunt
1103881ac44SUrsula Braun #define AF_IUCV_TRANS_IUCV 0
1113881ac44SUrsula Braun #define AF_IUCV_TRANS_HIPER 1
1123881ac44SUrsula Braun
113eac3731bSJennifer Hunt struct iucv_sock {
114eac3731bSJennifer Hunt struct sock sk;
115*b5d8cf0aSKees Cook struct_group(init,
116eac3731bSJennifer Hunt char src_user_id[8];
117eac3731bSJennifer Hunt char src_name[8];
118eac3731bSJennifer Hunt char dst_user_id[8];
119eac3731bSJennifer Hunt char dst_name[8];
120*b5d8cf0aSKees Cook );
121eac3731bSJennifer Hunt struct list_head accept_q;
122febca281SUrsula Braun spinlock_t accept_q_lock;
123eac3731bSJennifer Hunt struct sock *parent;
124eac3731bSJennifer Hunt struct iucv_path *path;
125800c5eb7SUrsula Braun struct net_device *hs_dev;
126eac3731bSJennifer Hunt struct sk_buff_head send_skb_q;
127561e0360SJennifer Hunt struct sk_buff_head backlog_skb_q;
128f0703c80SUrsula Braun struct sock_msg_q message_q;
129eac3731bSJennifer Hunt unsigned int send_tag;
1309d5c5d8fSHendrik Brueckner u8 flags;
13109488e2eSHendrik Brueckner u16 msglimit;
1323881ac44SUrsula Braun u16 msglimit_peer;
133ef6af7bdSJulian Wiedmann atomic_t skbs_in_xmit;
1343881ac44SUrsula Braun atomic_t msg_sent;
1353881ac44SUrsula Braun atomic_t msg_recv;
1363881ac44SUrsula Braun atomic_t pendings;
1373881ac44SUrsula Braun int transport;
13880bc97aaSJulian Wiedmann void (*sk_txnotify)(struct sock *sk,
1393881ac44SUrsula Braun enum iucv_tx_notify n);
140eac3731bSJennifer Hunt };
141eac3731bSJennifer Hunt
142f9c41a62SUrsula Braun struct iucv_skb_cb {
143f9c41a62SUrsula Braun u32 class; /* target class of message */
144f9c41a62SUrsula Braun u32 tag; /* tag associated with message */
145f9c41a62SUrsula Braun u32 offset; /* offset for skb receival */
146f9c41a62SUrsula Braun };
147f9c41a62SUrsula Braun
148f9c41a62SUrsula Braun #define IUCV_SKB_CB(__skb) ((struct iucv_skb_cb *)&((__skb)->cb[0]))
149f9c41a62SUrsula Braun
1509d5c5d8fSHendrik Brueckner /* iucv socket options (SOL_IUCV) */
1519d5c5d8fSHendrik Brueckner #define SO_IPRMDATA_MSG 0x0080 /* send/recv IPRM_DATA msgs */
15209488e2eSHendrik Brueckner #define SO_MSGLIMIT 0x1000 /* get/set IUCV MSGLIMIT */
15351363b87SUrsula Braun #define SO_MSGSIZE 0x0800 /* get maximum msgsize */
1549d5c5d8fSHendrik Brueckner
15544b1e6b5SHendrik Brueckner /* iucv related control messages (scm) */
15644b1e6b5SHendrik Brueckner #define SCM_IUCV_TRGCLS 0x0001 /* target class control message */
15744b1e6b5SHendrik Brueckner
158eac3731bSJennifer Hunt struct iucv_sock_list {
159eac3731bSJennifer Hunt struct hlist_head head;
160eac3731bSJennifer Hunt rwlock_t lock;
161eac3731bSJennifer Hunt atomic_t autobind_name;
162eac3731bSJennifer Hunt };
163eac3731bSJennifer Hunt
164eac3731bSJennifer Hunt #endif /* __IUCV_H */
165