iucv.h 17 KB

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