call.h 8.6 KB

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