iucv.h 17 KB

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