iucv.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. /*
  2. * drivers/s390/net/iucv.h
  3. * IUCV base support.
  4. *
  5. * S390 version
  6. * Copyright 2000, 2006 IBM Corporation
  7. * Author(s):Alan Altmark (Alan_Altmark@us.ibm.com)
  8. * Xenia Tkatschow (xenia@us.ibm.com)
  9. * Rewritten for af_iucv:
  10. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  11. *
  12. *
  13. * Functionality:
  14. * To explore any of the IUCV functions, one must first register their
  15. * program using iucv_register(). Once your program has successfully
  16. * completed a register, it can exploit the other functions.
  17. * For furthur reference on all IUCV functionality, refer to the
  18. * CP Programming Services book, also available on the web thru
  19. * www.vm.ibm.com/pubs, manual # SC24-6084
  20. *
  21. * Definition of Return Codes
  22. * - All positive return codes including zero are reflected back
  23. * from CP. The definition of each return code can be found in
  24. * CP Programming Services book.
  25. * - Return Code of:
  26. * -EINVAL: Invalid value
  27. * -ENOMEM: storage allocation failed
  28. */
  29. #include <linux/types.h>
  30. #include <linux/slab.h>
  31. #include <asm/debug.h>
  32. /*
  33. * IUCV option flags usable by device drivers:
  34. *
  35. * IUCV_IPRMDATA Indicates that your program can handle a message in the
  36. * parameter list / a message is sent in the parameter list.
  37. * Used for iucv_path_accept, iucv_path_connect,
  38. * iucv_message_reply, iucv_message_send, iucv_message_send2way.
  39. * IUCV_IPQUSCE Indicates that you do not want to receive messages on this
  40. * path until an iucv_path_resume is issued.
  41. * Used for iucv_path_accept, iucv_path_connect.
  42. * IUCV_IPBUFLST Indicates that an address list is used for the message data.
  43. * Used for iucv_message_receive, iucv_message_send,
  44. * iucv_message_send2way.
  45. * IUCV_IPPRTY Specifies that you want to send priority messages.
  46. * Used for iucv_path_accept, iucv_path_connect,
  47. * iucv_message_reply, iucv_message_send, iucv_message_send2way.
  48. * IUCV_IPSYNC Indicates a synchronous send request.
  49. * Used for iucv_message_send, iucv_message_send2way.
  50. * IUCV_IPANSLST Indicates that an address list is used for the reply data.
  51. * Used for iucv_message_reply, iucv_message_send2way.
  52. * IUCV_IPLOCAL Specifies that the communication partner has to be on the
  53. * local system. If local is specified no target class can be
  54. * specified.
  55. * Used for iucv_path_connect.
  56. *
  57. * All flags are defined in the input field IPFLAGS1 of each function
  58. * and can be found in CP Programming Services.
  59. */
  60. #define IUCV_IPRMDATA 0x80
  61. #define IUCV_IPQUSCE 0x40
  62. #define IUCV_IPBUFLST 0x40
  63. #define IUCV_IPPRTY 0x20
  64. #define IUCV_IPANSLST 0x08
  65. #define IUCV_IPSYNC 0x04
  66. #define IUCV_IPLOCAL 0x01
  67. /*
  68. * iucv_array : Defines buffer array.
  69. * Inside the array may be 31- bit addresses and 31-bit lengths.
  70. * Use a pointer to an iucv_array as the buffer, reply or answer
  71. * parameter on iucv_message_send, iucv_message_send2way, iucv_message_receive
  72. * and iucv_message_reply if IUCV_IPBUFLST or IUCV_IPANSLST are used.
  73. */
  74. struct iucv_array {
  75. u32 address;
  76. u32 length;
  77. } __attribute__ ((aligned (8)));
  78. extern struct bus_type iucv_bus;
  79. extern struct device *iucv_root;
  80. /*
  81. * struct iucv_path
  82. * pathid: 16 bit path identification
  83. * msglim: 16 bit message limit
  84. * flags: properties of the path: IPRMDATA, IPQUSCE, IPPRTY
  85. * handler: address of iucv handler structure
  86. * private: private information of the handler associated with the path
  87. * list: list_head for the iucv_handler path list.
  88. */
  89. struct iucv_path {
  90. u16 pathid;
  91. u16 msglim;
  92. u8 flags;
  93. void *private;
  94. struct iucv_handler *handler;
  95. struct list_head list;
  96. };
  97. /*
  98. * struct iucv_message
  99. * id: 32 bit message id
  100. * audit: 32 bit error information of purged or replied messages
  101. * class: 32 bit target class of a message (source class for replies)
  102. * tag: 32 bit tag to be associated with the message
  103. * length: 32 bit length of the message / reply
  104. * reply_size: 32 bit maximum allowed length of the reply
  105. * rmmsg: 8 byte inline message
  106. * flags: message properties (IUCV_IPPRTY)
  107. */
  108. struct iucv_message {
  109. u32 id;
  110. u32 audit;
  111. u32 class;
  112. u32 tag;
  113. u32 length;
  114. u32 reply_size;
  115. u8 rmmsg[8];
  116. u8 flags;
  117. };
  118. /*
  119. * struct iucv_handler
  120. *
  121. * A vector of functions that handle IUCV interrupts. Each functions gets
  122. * a parameter area as defined by the CP Programming Services and private
  123. * pointer that is provided by the user of the interface.
  124. */
  125. struct iucv_handler {
  126. /*
  127. * The path_pending function is called after an iucv interrupt
  128. * type 0x01 has been received. The base code allocates a path
  129. * structure and "asks" the handler if this path belongs to the
  130. * handler. To accept the path the path_pending function needs
  131. * to call iucv_path_accept and return 0. If the callback returns
  132. * a value != 0 the iucv base code will continue with the next
  133. * handler. The order in which the path_pending functions are
  134. * called is the order of the registration of the iucv handlers
  135. * to the base code.
  136. */
  137. int (*path_pending)(struct iucv_path *, u8 ipvmid[8], u8 ipuser[16]);
  138. /*
  139. * The path_complete function is called after an iucv interrupt
  140. * type 0x02 has been received for a path that has been established
  141. * for this handler with iucv_path_connect and got accepted by the
  142. * peer with iucv_path_accept.
  143. */
  144. void (*path_complete)(struct iucv_path *, u8 ipuser[16]);
  145. /*
  146. * The path_severed function is called after an iucv interrupt
  147. * type 0x03 has been received. The communication peer shutdown
  148. * his end of the communication path. The path still exists and
  149. * remaining messages can be received until a iucv_path_sever
  150. * shuts down the other end of the path as well.
  151. */
  152. void (*path_severed)(struct iucv_path *, u8 ipuser[16]);
  153. /*
  154. * The path_quiesced function is called after an icuv interrupt
  155. * type 0x04 has been received. The communication peer has quiesced
  156. * the path. Delivery of messages is stopped until iucv_path_resume
  157. * has been called.
  158. */
  159. void (*path_quiesced)(struct iucv_path *, u8 ipuser[16]);
  160. /*
  161. * The path_resumed function is called after an icuv interrupt
  162. * type 0x05 has been received. The communication peer has resumed
  163. * the path.
  164. */
  165. void (*path_resumed)(struct iucv_path *, u8 ipuser[16]);
  166. /*
  167. * The message_pending function is called after an icuv interrupt
  168. * type 0x06 or type 0x07 has been received. A new message is
  169. * available and can be received with iucv_message_receive.
  170. */
  171. void (*message_pending)(struct iucv_path *, struct iucv_message *);
  172. /*
  173. * The message_complete function is called after an icuv interrupt
  174. * type 0x08 or type 0x09 has been received. A message send with
  175. * iucv_message_send2way has been replied to. The reply can be
  176. * received with iucv_message_receive.
  177. */
  178. void (*message_complete)(struct iucv_path *, struct iucv_message *);
  179. struct list_head list;
  180. struct list_head paths;
  181. };
  182. /**
  183. * iucv_register:
  184. * @handler: address of iucv handler structure
  185. * @smp: != 0 indicates that the handler can deal with out of order messages
  186. *
  187. * Registers a driver with IUCV.
  188. *
  189. * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
  190. * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
  191. */
  192. int iucv_register(struct iucv_handler *handler, int smp);
  193. /**
  194. * iucv_unregister
  195. * @handler: address of iucv handler structure
  196. * @smp: != 0 indicates that the handler can deal with out of order messages
  197. *
  198. * Unregister driver from IUCV.
  199. */
  200. void iucv_unregister(struct iucv_handler *handle, int smp);
  201. /**
  202. * iucv_path_alloc
  203. * @msglim: initial message limit
  204. * @flags: initial flags
  205. * @gfp: kmalloc allocation flag
  206. *
  207. * Allocate a new path structure for use with iucv_connect.
  208. *
  209. * Returns NULL if the memory allocation failed or a pointer to the
  210. * path structure.
  211. */
  212. static inline struct iucv_path *iucv_path_alloc(u16 msglim, u8 flags, gfp_t gfp)
  213. {
  214. struct iucv_path *path;
  215. path = kzalloc(sizeof(struct iucv_path), gfp);
  216. if (path) {
  217. path->msglim = msglim;
  218. path->flags = flags;
  219. }
  220. return path;
  221. }
  222. /**
  223. * iucv_path_free
  224. * @path: address of iucv path structure
  225. *
  226. * Frees a path structure.
  227. */
  228. static inline void iucv_path_free(struct iucv_path *path)
  229. {
  230. kfree(path);
  231. }
  232. /**
  233. * iucv_path_accept
  234. * @path: address of iucv path structure
  235. * @handler: address of iucv handler structure
  236. * @userdata: 16 bytes of data reflected to the communication partner
  237. * @private: private data passed to interrupt handlers for this path
  238. *
  239. * This function is issued after the user received a connection pending
  240. * external interrupt and now wishes to complete the IUCV communication path.
  241. *
  242. * Returns the result of the CP IUCV call.
  243. */
  244. int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
  245. u8 userdata[16], void *private);
  246. /**
  247. * iucv_path_connect
  248. * @path: address of iucv path structure
  249. * @handler: address of iucv handler structure
  250. * @userid: 8-byte user identification
  251. * @system: 8-byte target system identification
  252. * @userdata: 16 bytes of data reflected to the communication partner
  253. * @private: private data passed to interrupt handlers for this path
  254. *
  255. * This function establishes an IUCV path. Although the connect may complete
  256. * successfully, you are not able to use the path until you receive an IUCV
  257. * Connection Complete external interrupt.
  258. *
  259. * Returns the result of the CP IUCV call.
  260. */
  261. int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
  262. u8 userid[8], u8 system[8], u8 userdata[16],
  263. void *private);
  264. /**
  265. * iucv_path_quiesce:
  266. * @path: address of iucv path structure
  267. * @userdata: 16 bytes of data reflected to the communication partner
  268. *
  269. * This function temporarily suspends incoming messages on an IUCV path.
  270. * You can later reactivate the path by invoking the iucv_resume function.
  271. *
  272. * Returns the result from the CP IUCV call.
  273. */
  274. int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16]);
  275. /**
  276. * iucv_path_resume:
  277. * @path: address of iucv path structure
  278. * @userdata: 16 bytes of data reflected to the communication partner
  279. *
  280. * This function resumes incoming messages on an IUCV path that has
  281. * been stopped with iucv_path_quiesce.
  282. *
  283. * Returns the result from the CP IUCV call.
  284. */
  285. int iucv_path_resume(struct iucv_path *path, u8 userdata[16]);
  286. /**
  287. * iucv_path_sever
  288. * @path: address of iucv path structure
  289. * @userdata: 16 bytes of data reflected to the communication partner
  290. *
  291. * This function terminates an IUCV path.
  292. *
  293. * Returns the result from the CP IUCV call.
  294. */
  295. int iucv_path_sever(struct iucv_path *path, u8 userdata[16]);
  296. /**
  297. * iucv_message_purge
  298. * @path: address of iucv path structure
  299. * @msg: address of iucv msg structure
  300. * @srccls: source class of message
  301. *
  302. * Cancels a message you have sent.
  303. *
  304. * Returns the result from the CP IUCV call.
  305. */
  306. int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
  307. u32 srccls);
  308. /**
  309. * iucv_message_receive
  310. * @path: address of iucv path structure
  311. * @msg: address of iucv msg structure
  312. * @flags: flags that affect how the message is received (IUCV_IPBUFLST)
  313. * @buffer: address of data buffer or address of struct iucv_array
  314. * @size: length of data buffer
  315. * @residual:
  316. *
  317. * This function receives messages that are being sent to you over
  318. * established paths. This function will deal with RMDATA messages
  319. * embedded in struct iucv_message as well.
  320. *
  321. * Locking: local_bh_enable/local_bh_disable
  322. *
  323. * Returns the result from the CP IUCV call.
  324. */
  325. int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  326. u8 flags, void *buffer, size_t size, size_t *residual);
  327. /**
  328. * __iucv_message_receive
  329. * @path: address of iucv path structure
  330. * @msg: address of iucv msg structure
  331. * @flags: flags that affect how the message is received (IUCV_IPBUFLST)
  332. * @buffer: address of data buffer or address of struct iucv_array
  333. * @size: length of data buffer
  334. * @residual:
  335. *
  336. * This function receives messages that are being sent to you over
  337. * established paths. This function will deal with RMDATA messages
  338. * embedded in struct iucv_message as well.
  339. *
  340. * Locking: no locking.
  341. *
  342. * Returns the result from the CP IUCV call.
  343. */
  344. int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  345. u8 flags, void *buffer, size_t size,
  346. size_t *residual);
  347. /**
  348. * iucv_message_reject
  349. * @path: address of iucv path structure
  350. * @msg: address of iucv msg structure
  351. *
  352. * The reject function refuses a specified message. Between the time you
  353. * are notified of a message and the time that you complete the message,
  354. * the message may be rejected.
  355. *
  356. * Returns the result from the CP IUCV call.
  357. */
  358. int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg);
  359. /**
  360. * iucv_message_reply
  361. * @path: address of iucv path structure
  362. * @msg: address of iucv msg structure
  363. * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  364. * @reply: address of data buffer or address of struct iucv_array
  365. * @size: length of reply data buffer
  366. *
  367. * This function responds to the two-way messages that you receive. You
  368. * must identify completely the message to which you wish to reply. ie,
  369. * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
  370. * the parameter list.
  371. *
  372. * Returns the result from the CP IUCV call.
  373. */
  374. int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
  375. u8 flags, void *reply, size_t size);
  376. /**
  377. * iucv_message_send
  378. * @path: address of iucv path structure
  379. * @msg: address of iucv msg structure
  380. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  381. * @srccls: source class of message
  382. * @buffer: address of data buffer or address of struct iucv_array
  383. * @size: length of send buffer
  384. *
  385. * This function transmits data to another application. Data to be
  386. * transmitted is in a buffer and this is a one-way message and the
  387. * receiver will not reply to the message.
  388. *
  389. * Locking: local_bh_enable/local_bh_disable
  390. *
  391. * Returns the result from the CP IUCV call.
  392. */
  393. int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  394. u8 flags, u32 srccls, void *buffer, size_t size);
  395. /**
  396. * __iucv_message_send
  397. * @path: address of iucv path structure
  398. * @msg: address of iucv msg structure
  399. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  400. * @srccls: source class of message
  401. * @buffer: address of data buffer or address of struct iucv_array
  402. * @size: length of send buffer
  403. *
  404. * This function transmits data to another application. Data to be
  405. * transmitted is in a buffer and this is a one-way message and the
  406. * receiver will not reply to the message.
  407. *
  408. * Locking: no locking.
  409. *
  410. * Returns the result from the CP IUCV call.
  411. */
  412. int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  413. u8 flags, u32 srccls, void *buffer, size_t size);
  414. /**
  415. * iucv_message_send2way
  416. * @path: address of iucv path structure
  417. * @msg: address of iucv msg structure
  418. * @flags: how the message is sent and the reply is received
  419. * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
  420. * @srccls: source class of message
  421. * @buffer: address of data buffer or address of struct iucv_array
  422. * @size: length of send buffer
  423. * @ansbuf: address of answer buffer or address of struct iucv_array
  424. * @asize: size of reply buffer
  425. *
  426. * This function transmits data to another application. Data to be
  427. * transmitted is in a buffer. The receiver of the send is expected to
  428. * reply to the message and a buffer is provided into which IUCV moves
  429. * the reply to this message.
  430. *
  431. * Returns the result from the CP IUCV call.
  432. */
  433. int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
  434. u8 flags, u32 srccls, void *buffer, size_t size,
  435. void *answer, size_t asize, size_t *residual);