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) */
23 extern unsigned rxrpc_call_acks_timeout
; /* pending ACK (retransmit) timeout (secs) */
24 extern unsigned rxrpc_call_dfr_ack_timeout
; /* deferred ACK timeout (secs) */
25 extern unsigned short rxrpc_call_max_resend
; /* maximum consecutive resend count */
27 /* application call state
28 * - only state 0 and ffff are reserved, the state is set to 1 after an opid is received
30 enum rxrpc_app_cstate
{
31 RXRPC_CSTATE_COMPLETE
= 0, /* operation complete */
32 RXRPC_CSTATE_ERROR
, /* operation ICMP error or aborted */
33 RXRPC_CSTATE_SRVR_RCV_OPID
, /* [SERVER] receiving operation ID */
34 RXRPC_CSTATE_SRVR_RCV_ARGS
, /* [SERVER] receiving operation data */
35 RXRPC_CSTATE_SRVR_GOT_ARGS
, /* [SERVER] completely received operation data */
36 RXRPC_CSTATE_SRVR_SND_REPLY
, /* [SERVER] sending operation reply */
37 RXRPC_CSTATE_SRVR_RCV_FINAL_ACK
, /* [SERVER] receiving final ACK */
38 RXRPC_CSTATE_CLNT_SND_ARGS
, /* [CLIENT] sending operation args */
39 RXRPC_CSTATE_CLNT_RCV_REPLY
, /* [CLIENT] receiving operation reply */
40 RXRPC_CSTATE_CLNT_GOT_REPLY
, /* [CLIENT] completely received operation reply */
41 } __attribute__((packed
));
43 extern const char *rxrpc_call_states
[];
45 enum rxrpc_app_estate
{
46 RXRPC_ESTATE_NO_ERROR
= 0, /* no error */
47 RXRPC_ESTATE_LOCAL_ABORT
, /* aborted locally by application layer */
48 RXRPC_ESTATE_PEER_ABORT
, /* aborted remotely by peer */
49 RXRPC_ESTATE_LOCAL_ERROR
, /* local ICMP network error */
50 RXRPC_ESTATE_REMOTE_ERROR
, /* remote ICMP network error */
51 } __attribute__((packed
));
53 extern const char *rxrpc_call_error_states
[];
55 /*****************************************************************************/
57 * Rx call record and application scratch buffer
58 * - the call record occupies the bottom of a complete page
59 * - the application scratch buffer occupies the rest
64 struct rxrpc_connection
*conn
; /* connection upon which active */
65 spinlock_t lock
; /* access lock */
66 struct module
*owner
; /* owner module */
67 wait_queue_head_t waitq
; /* wait queue for events to happen */
68 struct list_head link
; /* general internal list link */
69 struct list_head call_link
; /* master call list link */
70 u32 chan_ix
; /* connection channel index (net order) */
71 u32 call_id
; /* call ID on connection (net order) */
72 unsigned long cjif
; /* jiffies at call creation */
73 unsigned long flags
; /* control flags */
74 #define RXRPC_CALL_ACKS_TIMO 0x00000001 /* ACKS timeout reached */
75 #define RXRPC_CALL_ACKR_TIMO 0x00000002 /* ACKR timeout reached */
76 #define RXRPC_CALL_RCV_TIMO 0x00000004 /* RCV timeout reached */
77 #define RXRPC_CALL_RCV_PKT 0x00000008 /* received packet */
80 rxrpc_seq_t snd_seq_count
; /* outgoing packet sequence number counter */
81 struct rxrpc_message
*snd_nextmsg
; /* next message being constructed for sending */
82 struct rxrpc_message
*snd_ping
; /* last ping message sent */
83 unsigned short snd_resend_cnt
; /* count of resends since last ACK */
85 /* transmission ACK tracking */
86 struct list_head acks_pendq
; /* messages pending ACK (ordered by seq) */
87 unsigned acks_pend_cnt
; /* number of un-ACK'd packets */
88 rxrpc_seq_t acks_dftv_seq
; /* highest definitively ACK'd msg seq */
89 struct timer_list acks_timeout
; /* timeout on expected ACK */
92 struct list_head rcv_receiveq
; /* messages pending reception (ordered by seq) */
93 struct list_head rcv_krxiodq_lk
; /* krxiod queue for new inbound packets */
94 struct timer_list rcv_timeout
; /* call receive activity timeout */
96 /* reception ACK'ing */
97 rxrpc_seq_t ackr_win_bot
; /* bottom of ACK window */
98 rxrpc_seq_t ackr_win_top
; /* top of ACK window */
99 rxrpc_seq_t ackr_high_seq
; /* highest seqno yet received */
100 rxrpc_seq_t ackr_prev_seq
; /* previous seqno received */
101 unsigned ackr_pend_cnt
; /* number of pending ACKs */
102 struct timer_list ackr_dfr_timo
; /* timeout on deferred ACK */
103 char ackr_dfr_perm
; /* request for deferred ACKs permitted */
104 rxrpc_seq_t ackr_dfr_seq
; /* seqno for deferred ACK */
105 struct rxrpc_ackpacket ackr
; /* pending normal ACK packet */
106 u8 ackr_array
[RXRPC_CALL_ACK_WINDOW_SIZE
]; /* ACK records */
108 /* presentation layer */
109 char app_last_rcv
; /* T if received last packet from remote end */
110 enum rxrpc_app_cstate app_call_state
; /* call state */
111 enum rxrpc_app_estate app_err_state
; /* abort/error state */
112 struct list_head app_readyq
; /* ordered ready received packet queue */
113 struct list_head app_unreadyq
; /* ordered post-hole recv'd packet queue */
114 rxrpc_seq_t app_ready_seq
; /* last seq number dropped into readyq */
115 size_t app_ready_qty
; /* amount of data ready in readyq */
116 unsigned app_opcode
; /* operation ID */
117 unsigned app_abort_code
; /* abort code (when aborted) */
118 int app_errno
; /* error number (when ICMP error received) */
121 unsigned pkt_rcv_count
; /* count of received packets on this call */
122 unsigned pkt_snd_count
; /* count of sent packets on this call */
123 unsigned app_read_count
; /* number of reads issued */
125 /* bits for the application to use */
126 rxrpc_call_attn_func_t app_attn_func
; /* callback when attention required */
127 rxrpc_call_error_func_t app_error_func
; /* callback when abort sent (cleanup and put) */
128 rxrpc_call_aemap_func_t app_aemap_func
; /* callback to map abort code to/from errno */
129 void *app_user
; /* application data */
130 struct list_head app_link
; /* application list linkage */
131 struct list_head app_attn_link
; /* application attention list linkage */
132 size_t app_mark
; /* trigger callback when app_ready_qty>=app_mark */
133 char app_async_read
; /* T if in async-read mode */
134 u8
*app_read_buf
; /* application async read buffer (app_mark size) */
135 u8
*app_scr_alloc
; /* application scratch allocation pointer */
136 void *app_scr_ptr
; /* application pointer into scratch buffer */
138 #define RXRPC_APP_MARK_EOF 0xFFFFFFFFU /* mark at end of input */
140 /* application scratch buffer */
141 u8 app_scratch
[0] __attribute__((aligned(sizeof(long))));
144 #define RXRPC_CALL_SCRATCH_SIZE (PAGE_SIZE - sizeof(struct rxrpc_call))
146 #define rxrpc_call_reset_scratch(CALL) \
147 do { (CALL)->app_scr_alloc = (CALL)->app_scratch; } while(0)
149 #define rxrpc_call_alloc_scratch(CALL,SIZE) \
152 ptr = (CALL)->app_scr_alloc; \
153 (CALL)->app_scr_alloc += (SIZE); \
154 if ((SIZE)>RXRPC_CALL_SCRATCH_SIZE || \
155 (size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
156 printk("rxrpc_call_alloc_scratch(%p,%Zu)\n",(CALL),(size_t)(SIZE)); \
162 #define rxrpc_call_alloc_scratch_s(CALL,TYPE) \
164 size_t size = sizeof(TYPE); \
166 ptr = (TYPE*)(CALL)->app_scr_alloc; \
167 (CALL)->app_scr_alloc += size; \
168 if (size>RXRPC_CALL_SCRATCH_SIZE || \
169 (size_t)((CALL)->app_scr_alloc - (u8*)(CALL)) > RXRPC_CALL_SCRATCH_SIZE) { \
170 printk("rxrpc_call_alloc_scratch(%p,%Zu)\n",(CALL),size); \
176 #define rxrpc_call_is_ack_pending(CALL) ((CALL)->ackr.reason != 0)
178 extern int rxrpc_create_call(struct rxrpc_connection
*conn
,
179 rxrpc_call_attn_func_t attn
,
180 rxrpc_call_error_func_t error
,
181 rxrpc_call_aemap_func_t aemap
,
182 struct rxrpc_call
**_call
);
184 extern int rxrpc_incoming_call(struct rxrpc_connection
*conn
,
185 struct rxrpc_message
*msg
,
186 struct rxrpc_call
**_call
);
188 static inline void rxrpc_get_call(struct rxrpc_call
*call
)
190 if (atomic_read(&call
->usage
)<=0)
192 atomic_inc(&call
->usage
);
193 /*printk("rxrpc_get_call(%p{u=%d})\n",(C),atomic_read(&(C)->usage));*/
196 extern void rxrpc_put_call(struct rxrpc_call
*call
);
198 extern void rxrpc_call_do_stuff(struct rxrpc_call
*call
);
200 extern int rxrpc_call_abort(struct rxrpc_call
*call
, int error
);
202 #define RXRPC_CALL_READ_BLOCK 0x0001 /* block if not enough data and not yet EOF */
203 #define RXRPC_CALL_READ_ALL 0x0002 /* error if insufficient data received */
204 extern int rxrpc_call_read_data(struct rxrpc_call
*call
, void *buffer
, size_t size
, int flags
);
206 extern int rxrpc_call_write_data(struct rxrpc_call
*call
,
214 extern int rxrpc_call_flush(struct rxrpc_call
*call
);
216 extern void rxrpc_call_handle_error(struct rxrpc_call
*conn
, int local
, int errno
);
218 #endif /* _LINUX_RXRPC_CALL_H */