[PATCH] aic7xxx_osm build fix
[cris-mirror.git] / include / rxrpc / call.h
blobf48f27e9e0ab26397ab396d49df3d25918a175d2
1 /* call.h: Rx call record
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #ifndef _LINUX_RXRPC_CALL_H
13 #define _LINUX_RXRPC_CALL_H
15 #include <rxrpc/types.h>
16 #include <rxrpc/rxrpc.h>
17 #include <rxrpc/packet.h>
18 #include <linux/timer.h>
20 #define RXRPC_CALL_ACK_WINDOW_SIZE 16
22 extern unsigned rxrpc_call_rcv_timeout; /* receive activity timeout (secs) */
24 /* application call state
25 * - only state 0 and ffff are reserved, the state is set to 1 after an opid is received
27 enum rxrpc_app_cstate {
28 RXRPC_CSTATE_COMPLETE = 0, /* operation complete */
29 RXRPC_CSTATE_ERROR, /* operation ICMP error or aborted */
30 RXRPC_CSTATE_SRVR_RCV_OPID, /* [SERVER] receiving operation ID */
31 RXRPC_CSTATE_SRVR_RCV_ARGS, /* [SERVER] receiving operation data */
32 RXRPC_CSTATE_SRVR_GOT_ARGS, /* [SERVER] completely received operation data */
33 RXRPC_CSTATE_SRVR_SND_REPLY, /* [SERVER] sending operation reply */
34 RXRPC_CSTATE_SRVR_RCV_FINAL_ACK, /* [SERVER] receiving final ACK */
35 RXRPC_CSTATE_CLNT_SND_ARGS, /* [CLIENT] sending operation args */
36 RXRPC_CSTATE_CLNT_RCV_REPLY, /* [CLIENT] receiving operation reply */
37 RXRPC_CSTATE_CLNT_GOT_REPLY, /* [CLIENT] completely received operation reply */
38 } __attribute__((packed));
40 extern const char *rxrpc_call_states[];
42 enum rxrpc_app_estate {
43 RXRPC_ESTATE_NO_ERROR = 0, /* no error */
44 RXRPC_ESTATE_LOCAL_ABORT, /* aborted locally by application layer */
45 RXRPC_ESTATE_PEER_ABORT, /* aborted remotely by peer */
46 RXRPC_ESTATE_LOCAL_ERROR, /* local ICMP network error */
47 RXRPC_ESTATE_REMOTE_ERROR, /* remote ICMP network error */
48 } __attribute__((packed));
50 extern const char *rxrpc_call_error_states[];
52 /*****************************************************************************/
54 * Rx call record and application scratch buffer
55 * - the call record occupies the bottom of a complete page
56 * - the application scratch buffer occupies the rest
58 struct rxrpc_call
60 atomic_t usage;
61 struct rxrpc_connection *conn; /* connection upon which active */
62 spinlock_t lock; /* access lock */
63 struct module *owner; /* owner module */
64 wait_queue_head_t waitq; /* wait queue for events to happen */
65 struct list_head link; /* general internal list link */
66 struct list_head call_link; /* master call list link */
67 __be32 chan_ix; /* connection channel index */
68 __be32 call_id; /* call ID on connection */
69 unsigned long cjif; /* jiffies at call creation */
70 unsigned long flags; /* control flags */
71 #define RXRPC_CALL_ACKS_TIMO 0x00000001 /* ACKS timeout reached */
72 #define RXRPC_CALL_ACKR_TIMO 0x00000002 /* ACKR timeout reached */
73 #define RXRPC_CALL_RCV_TIMO 0x00000004 /* RCV timeout reached */
74 #define RXRPC_CALL_RCV_PKT 0x00000008 /* received packet */
76 /* transmission */
77 rxrpc_seq_t snd_seq_count; /* outgoing packet sequence number counter */
78 struct rxrpc_message *snd_nextmsg; /* next message being constructed for sending */
79 struct rxrpc_message *snd_ping; /* last ping message sent */
80 unsigned short snd_resend_cnt; /* count of resends since last ACK */
82 /* transmission ACK tracking */
83 struct list_head acks_pendq; /* messages pending ACK (ordered by seq) */
84 unsigned acks_pend_cnt; /* number of un-ACK'd packets */
85 rxrpc_seq_t acks_dftv_seq; /* highest definitively ACK'd msg seq */
86 struct timer_list acks_timeout; /* timeout on expected ACK */
88 /* reception */
89 struct list_head rcv_receiveq; /* messages pending reception (ordered by seq) */
90 struct list_head rcv_krxiodq_lk; /* krxiod queue for new inbound packets */
91 struct timer_list rcv_timeout; /* call receive activity timeout */
93 /* reception ACK'ing */
94 rxrpc_seq_t ackr_win_bot; /* bottom of ACK window */
95 rxrpc_seq_t ackr_win_top; /* top of ACK window */
96 rxrpc_seq_t ackr_high_seq; /* highest seqno yet received */
97 rxrpc_seq_net_t ackr_prev_seq; /* previous seqno received */
98 unsigned ackr_pend_cnt; /* number of pending ACKs */
99 struct timer_list ackr_dfr_timo; /* timeout on deferred ACK */
100 char ackr_dfr_perm; /* request for deferred ACKs permitted */
101 rxrpc_seq_t ackr_dfr_seq; /* seqno for deferred ACK */
102 struct rxrpc_ackpacket ackr; /* pending normal ACK packet */
103 uint8_t ackr_array[RXRPC_CALL_ACK_WINDOW_SIZE]; /* ACK records */
105 /* presentation layer */
106 char app_last_rcv; /* T if received last packet from remote end */
107 enum rxrpc_app_cstate app_call_state; /* call state */
108 enum rxrpc_app_estate app_err_state; /* abort/error state */
109 struct list_head app_readyq; /* ordered ready received packet queue */
110 struct list_head app_unreadyq; /* ordered post-hole recv'd packet queue */
111 rxrpc_seq_t app_ready_seq; /* last seq number dropped into readyq */
112 size_t app_ready_qty; /* amount of data ready in readyq */
113 unsigned app_opcode; /* operation ID */
114 unsigned app_abort_code; /* abort code (when aborted) */
115 int app_errno; /* error number (when ICMP error received) */
117 /* statisics */
118 unsigned pkt_rcv_count; /* count of received packets on this call */
119 unsigned pkt_snd_count; /* count of sent packets on this call */
120 unsigned app_read_count; /* number of reads issued */
122 /* bits for the application to use */
123 rxrpc_call_attn_func_t app_attn_func; /* callback when attention required */
124 rxrpc_call_error_func_t app_error_func; /* callback when abort sent (cleanup and put) */
125 rxrpc_call_aemap_func_t app_aemap_func; /* callback to map abort code to/from errno */
126 void *app_user; /* application data */
127 struct list_head app_link; /* application list linkage */
128 struct list_head app_attn_link; /* application attention list linkage */
129 size_t app_mark; /* trigger callback when app_ready_qty>=app_mark */
130 char app_async_read; /* T if in async-read mode */
131 uint8_t *app_read_buf; /* application async read buffer (app_mark size) */
132 uint8_t *app_scr_alloc; /* application scratch allocation pointer */
133 void *app_scr_ptr; /* application pointer into scratch buffer */
135 #define RXRPC_APP_MARK_EOF 0xFFFFFFFFU /* mark at end of input */
137 /* application scratch buffer */
138 uint8_t app_scratch[0] __attribute__((aligned(sizeof(long))));
141 #define RXRPC_CALL_SCRATCH_SIZE (PAGE_SIZE - sizeof(struct rxrpc_call))
143 #define rxrpc_call_reset_scratch(CALL) \
144 do { (CALL)->app_scr_alloc = (CALL)->app_scratch; } while(0)
146 #define rxrpc_call_alloc_scratch(CALL,SIZE) \
147 ({ \
148 void *ptr; \
149 ptr = (CALL)->app_scr_alloc; \
150 (CALL)->app_scr_alloc += (SIZE); \
151 if ((SIZE)>RXRPC_CALL_SCRATCH_SIZE || \
152 (size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
153 printk("rxrpc_call_alloc_scratch(%p,%Zu)\n",(CALL),(size_t)(SIZE)); \
154 BUG(); \
156 ptr; \
159 #define rxrpc_call_alloc_scratch_s(CALL,TYPE) \
160 ({ \
161 size_t size = sizeof(TYPE); \
162 TYPE *ptr; \
163 ptr = (TYPE*)(CALL)->app_scr_alloc; \
164 (CALL)->app_scr_alloc += size; \
165 if (size>RXRPC_CALL_SCRATCH_SIZE || \
166 (size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
167 printk("rxrpc_call_alloc_scratch(%p,%Zu)\n",(CALL),size); \
168 BUG(); \
170 ptr; \
173 #define rxrpc_call_is_ack_pending(CALL) ((CALL)->ackr.reason != 0)
175 extern int rxrpc_create_call(struct rxrpc_connection *conn,
176 rxrpc_call_attn_func_t attn,
177 rxrpc_call_error_func_t error,
178 rxrpc_call_aemap_func_t aemap,
179 struct rxrpc_call **_call);
181 extern int rxrpc_incoming_call(struct rxrpc_connection *conn,
182 struct rxrpc_message *msg,
183 struct rxrpc_call **_call);
185 static inline void rxrpc_get_call(struct rxrpc_call *call)
187 BUG_ON(atomic_read(&call->usage)<=0);
188 atomic_inc(&call->usage);
189 /*printk("rxrpc_get_call(%p{u=%d})\n",(C),atomic_read(&(C)->usage));*/
192 extern void rxrpc_put_call(struct rxrpc_call *call);
194 extern void rxrpc_call_do_stuff(struct rxrpc_call *call);
196 extern int rxrpc_call_abort(struct rxrpc_call *call, int error);
198 #define RXRPC_CALL_READ_BLOCK 0x0001 /* block if not enough data and not yet EOF */
199 #define RXRPC_CALL_READ_ALL 0x0002 /* error if insufficient data received */
200 extern int rxrpc_call_read_data(struct rxrpc_call *call, void *buffer, size_t size, int flags);
202 extern int rxrpc_call_write_data(struct rxrpc_call *call,
203 size_t sioc,
204 struct kvec *siov,
205 uint8_t rxhdr_flags,
206 int alloc_flags,
207 int dup_data,
208 size_t *size_sent);
210 extern void rxrpc_call_handle_error(struct rxrpc_call *conn, int local, int errno);
212 #endif /* _LINUX_RXRPC_CALL_H */