iucv.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545
  1. /*
  2. * IUCV network driver
  3. *
  4. * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
  5. * Author(s):
  6. * Original source:
  7. * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
  8. * Xenia Tkatschow (xenia@us.ibm.com)
  9. * 2Gb awareness and general cleanup:
  10. * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
  11. *
  12. * Documentation used:
  13. * The original source
  14. * CP Programming Service, IBM document # SC24-5760
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2, or (at your option)
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. */
  31. /* #define DEBUG */
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/kernel.h>
  36. #include <linux/slab.h>
  37. #include <linux/init.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/list.h>
  40. #include <linux/errno.h>
  41. #include <linux/err.h>
  42. #include <linux/device.h>
  43. #include <asm/atomic.h>
  44. #include "iucv.h"
  45. #include <asm/io.h>
  46. #include <asm/s390_ext.h>
  47. #include <asm/ebcdic.h>
  48. #include <asm/smp.h>
  49. #include <asm/s390_rdev.h>
  50. /* FLAGS:
  51. * All flags are defined in the field IPFLAGS1 of each function
  52. * and can be found in CP Programming Services.
  53. * IPSRCCLS - Indicates you have specified a source class
  54. * IPFGMCL - Indicates you have specified a target class
  55. * IPFGPID - Indicates you have specified a pathid
  56. * IPFGMID - Indicates you have specified a message ID
  57. * IPANSLST - Indicates that you are using an address list for
  58. * reply data
  59. * IPBUFLST - Indicates that you are using an address list for
  60. * message data
  61. */
  62. #define IPSRCCLS 0x01
  63. #define IPFGMCL 0x01
  64. #define IPFGPID 0x02
  65. #define IPFGMID 0x04
  66. #define IPANSLST 0x08
  67. #define IPBUFLST 0x40
  68. static int
  69. iucv_bus_match (struct device *dev, struct device_driver *drv)
  70. {
  71. return 0;
  72. }
  73. struct bus_type iucv_bus = {
  74. .name = "iucv",
  75. .match = iucv_bus_match,
  76. };
  77. struct device *iucv_root;
  78. /* General IUCV interrupt structure */
  79. typedef struct {
  80. __u16 ippathid;
  81. __u8 res1;
  82. __u8 iptype;
  83. __u32 res2;
  84. __u8 ipvmid[8];
  85. __u8 res3[24];
  86. } iucv_GeneralInterrupt;
  87. static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL;
  88. /* Spin Lock declaration */
  89. static DEFINE_SPINLOCK(iucv_lock);
  90. static int messagesDisabled = 0;
  91. /***************INTERRUPT HANDLING ***************/
  92. typedef struct {
  93. struct list_head queue;
  94. iucv_GeneralInterrupt data;
  95. } iucv_irqdata;
  96. static struct list_head iucv_irq_queue;
  97. static DEFINE_SPINLOCK(iucv_irq_queue_lock);
  98. /*
  99. *Internal function prototypes
  100. */
  101. static void iucv_tasklet_handler(unsigned long);
  102. static void iucv_irq_handler(struct pt_regs *, __u16);
  103. static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0);
  104. /************ FUNCTION ID'S ****************************/
  105. #define ACCEPT 10
  106. #define CONNECT 11
  107. #define DECLARE_BUFFER 12
  108. #define PURGE 9
  109. #define QUERY 0
  110. #define QUIESCE 13
  111. #define RECEIVE 5
  112. #define REJECT 8
  113. #define REPLY 6
  114. #define RESUME 14
  115. #define RETRIEVE_BUFFER 2
  116. #define SEND 4
  117. #define SETMASK 16
  118. #define SEVER 15
  119. /**
  120. * Structure: handler
  121. * members: list - list management.
  122. * structure: id
  123. * userid - 8 char array of machine identification
  124. * user_data - 16 char array for user identification
  125. * mask - 24 char array used to compare the 2 previous
  126. * interrupt_table - vector of interrupt functions.
  127. * pgm_data - ulong, application data that is passed
  128. * to the interrupt handlers
  129. */
  130. typedef struct handler_t {
  131. struct list_head list;
  132. struct {
  133. __u8 userid[8];
  134. __u8 user_data[16];
  135. __u8 mask[24];
  136. } id;
  137. iucv_interrupt_ops_t *interrupt_table;
  138. void *pgm_data;
  139. } handler;
  140. /**
  141. * iucv_handler_table: List of registered handlers.
  142. */
  143. static struct list_head iucv_handler_table;
  144. /**
  145. * iucv_pathid_table: an array of *handler pointing into
  146. * iucv_handler_table for fast indexing by pathid;
  147. */
  148. static handler **iucv_pathid_table;
  149. static unsigned long max_connections;
  150. /**
  151. * iucv_cpuid: contains the logical cpu number of the cpu which
  152. * has declared the iucv buffer by issuing DECLARE_BUFFER.
  153. * If no cpu has done the initialization iucv_cpuid contains -1.
  154. */
  155. static int iucv_cpuid = -1;
  156. /**
  157. * register_flag: is 0 when external interrupt has not been registered
  158. */
  159. static int register_flag;
  160. /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/
  161. /* Data struct 1: iparml_control
  162. * Used for iucv_accept
  163. * iucv_connect
  164. * iucv_quiesce
  165. * iucv_resume
  166. * iucv_sever
  167. * iucv_retrieve_buffer
  168. * Data struct 2: iparml_dpl (data in parameter list)
  169. * Used for iucv_send_prmmsg
  170. * iucv_send2way_prmmsg
  171. * iucv_send2way_prmmsg_array
  172. * iucv_reply_prmmsg
  173. * Data struct 3: iparml_db (data in a buffer)
  174. * Used for iucv_receive
  175. * iucv_receive_array
  176. * iucv_reject
  177. * iucv_reply
  178. * iucv_reply_array
  179. * iucv_send
  180. * iucv_send_array
  181. * iucv_send2way
  182. * iucv_send2way_array
  183. * iucv_declare_buffer
  184. * Data struct 4: iparml_purge
  185. * Used for iucv_purge
  186. * iucv_query
  187. * Data struct 5: iparml_set_mask
  188. * Used for iucv_set_mask
  189. */
  190. typedef struct {
  191. __u16 ippathid;
  192. __u8 ipflags1;
  193. __u8 iprcode;
  194. __u16 ipmsglim;
  195. __u16 res1;
  196. __u8 ipvmid[8];
  197. __u8 ipuser[16];
  198. __u8 iptarget[8];
  199. } iparml_control;
  200. typedef struct {
  201. __u16 ippathid;
  202. __u8 ipflags1;
  203. __u8 iprcode;
  204. __u32 ipmsgid;
  205. __u32 iptrgcls;
  206. __u8 iprmmsg[8];
  207. __u32 ipsrccls;
  208. __u32 ipmsgtag;
  209. __u32 ipbfadr2;
  210. __u32 ipbfln2f;
  211. __u32 res;
  212. } iparml_dpl;
  213. typedef struct {
  214. __u16 ippathid;
  215. __u8 ipflags1;
  216. __u8 iprcode;
  217. __u32 ipmsgid;
  218. __u32 iptrgcls;
  219. __u32 ipbfadr1;
  220. __u32 ipbfln1f;
  221. __u32 ipsrccls;
  222. __u32 ipmsgtag;
  223. __u32 ipbfadr2;
  224. __u32 ipbfln2f;
  225. __u32 res;
  226. } iparml_db;
  227. typedef struct {
  228. __u16 ippathid;
  229. __u8 ipflags1;
  230. __u8 iprcode;
  231. __u32 ipmsgid;
  232. __u8 ipaudit[3];
  233. __u8 res1[5];
  234. __u32 res2;
  235. __u32 ipsrccls;
  236. __u32 ipmsgtag;
  237. __u32 res3[3];
  238. } iparml_purge;
  239. typedef struct {
  240. __u8 ipmask;
  241. __u8 res1[2];
  242. __u8 iprcode;
  243. __u32 res2[9];
  244. } iparml_set_mask;
  245. typedef struct {
  246. union {
  247. iparml_control p_ctrl;
  248. iparml_dpl p_dpl;
  249. iparml_db p_db;
  250. iparml_purge p_purge;
  251. iparml_set_mask p_set_mask;
  252. } param;
  253. atomic_t in_use;
  254. __u32 res;
  255. } __attribute__ ((aligned(8))) iucv_param;
  256. #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param))
  257. static iucv_param * iucv_param_pool;
  258. MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
  259. MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
  260. MODULE_LICENSE("GPL");
  261. /*
  262. * Debugging stuff
  263. *******************************************************************************/
  264. #ifdef DEBUG
  265. static int debuglevel = 0;
  266. module_param(debuglevel, int, 0);
  267. MODULE_PARM_DESC(debuglevel,
  268. "Specifies the debug level (0=off ... 3=all)");
  269. static void
  270. iucv_dumpit(char *title, void *buf, int len)
  271. {
  272. int i;
  273. __u8 *p = (__u8 *)buf;
  274. if (debuglevel < 3)
  275. return;
  276. printk(KERN_DEBUG "%s\n", title);
  277. printk(" ");
  278. for (i = 0; i < len; i++) {
  279. if (!(i % 16) && i != 0)
  280. printk ("\n ");
  281. else if (!(i % 4) && i != 0)
  282. printk(" ");
  283. printk("%02X", *p++);
  284. }
  285. if (len % 16)
  286. printk ("\n");
  287. return;
  288. }
  289. #define iucv_debug(lvl, fmt, args...) \
  290. do { \
  291. if (debuglevel >= lvl) \
  292. printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \
  293. } while (0)
  294. #else
  295. #define iucv_debug(lvl, fmt, args...) do { } while (0)
  296. #define iucv_dumpit(title, buf, len) do { } while (0)
  297. #endif
  298. /*
  299. * Internal functions
  300. *******************************************************************************/
  301. /**
  302. * print start banner
  303. */
  304. static void
  305. iucv_banner(void)
  306. {
  307. printk(KERN_INFO "IUCV lowlevel driver initialized\n");
  308. }
  309. /**
  310. * iucv_init - Initialization
  311. *
  312. * Allocates and initializes various data structures.
  313. */
  314. static int
  315. iucv_init(void)
  316. {
  317. int ret;
  318. if (iucv_external_int_buffer)
  319. return 0;
  320. if (!MACHINE_IS_VM) {
  321. printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n");
  322. return -EPROTONOSUPPORT;
  323. }
  324. ret = bus_register(&iucv_bus);
  325. if (ret) {
  326. printk(KERN_ERR "IUCV: failed to register bus.\n");
  327. return ret;
  328. }
  329. iucv_root = s390_root_dev_register("iucv");
  330. if (IS_ERR(iucv_root)) {
  331. printk(KERN_ERR "IUCV: failed to register iucv root.\n");
  332. bus_unregister(&iucv_bus);
  333. return PTR_ERR(iucv_root);
  334. }
  335. /* Note: GFP_DMA used used to get memory below 2G */
  336. iucv_external_int_buffer = kzalloc(sizeof(iucv_GeneralInterrupt),
  337. GFP_KERNEL|GFP_DMA);
  338. if (!iucv_external_int_buffer) {
  339. printk(KERN_WARNING
  340. "%s: Could not allocate external interrupt buffer\n",
  341. __FUNCTION__);
  342. s390_root_dev_unregister(iucv_root);
  343. bus_unregister(&iucv_bus);
  344. return -ENOMEM;
  345. }
  346. /* Initialize parameter pool */
  347. iucv_param_pool = kzalloc(sizeof(iucv_param) * PARAM_POOL_SIZE,
  348. GFP_KERNEL|GFP_DMA);
  349. if (!iucv_param_pool) {
  350. printk(KERN_WARNING "%s: Could not allocate param pool\n",
  351. __FUNCTION__);
  352. kfree(iucv_external_int_buffer);
  353. iucv_external_int_buffer = NULL;
  354. s390_root_dev_unregister(iucv_root);
  355. bus_unregister(&iucv_bus);
  356. return -ENOMEM;
  357. }
  358. /* Initialize irq queue */
  359. INIT_LIST_HEAD(&iucv_irq_queue);
  360. /* Initialize handler table */
  361. INIT_LIST_HEAD(&iucv_handler_table);
  362. iucv_banner();
  363. return 0;
  364. }
  365. /**
  366. * iucv_exit - De-Initialization
  367. *
  368. * Frees everything allocated from iucv_init.
  369. */
  370. static int iucv_retrieve_buffer (void);
  371. static void
  372. iucv_exit(void)
  373. {
  374. iucv_retrieve_buffer();
  375. kfree(iucv_external_int_buffer);
  376. iucv_external_int_buffer = NULL;
  377. kfree(iucv_param_pool);
  378. iucv_param_pool = NULL;
  379. s390_root_dev_unregister(iucv_root);
  380. bus_unregister(&iucv_bus);
  381. printk(KERN_INFO "IUCV lowlevel driver unloaded\n");
  382. }
  383. /**
  384. * grab_param: - Get a parameter buffer from the pre-allocated pool.
  385. *
  386. * This function searches for an unused element in the pre-allocated pool
  387. * of parameter buffers. If one is found, it marks it "in use" and returns
  388. * a pointer to it. The calling function is responsible for releasing it
  389. * when it has finished its usage.
  390. *
  391. * Returns: A pointer to iucv_param.
  392. */
  393. static __inline__ iucv_param *
  394. grab_param(void)
  395. {
  396. iucv_param *ptr;
  397. static int hint = 0;
  398. ptr = iucv_param_pool + hint;
  399. do {
  400. ptr++;
  401. if (ptr >= iucv_param_pool + PARAM_POOL_SIZE)
  402. ptr = iucv_param_pool;
  403. } while (atomic_cmpxchg(&ptr->in_use, 0, 1) != 0);
  404. hint = ptr - iucv_param_pool;
  405. memset(&ptr->param, 0, sizeof(ptr->param));
  406. return ptr;
  407. }
  408. /**
  409. * release_param - Release a parameter buffer.
  410. * @p: A pointer to a struct iucv_param, previously obtained by calling
  411. * grab_param().
  412. *
  413. * This function marks the specified parameter buffer "unused".
  414. */
  415. static __inline__ void
  416. release_param(void *p)
  417. {
  418. atomic_set(&((iucv_param *)p)->in_use, 0);
  419. }
  420. /**
  421. * iucv_add_handler: - Add a new handler
  422. * @new_handler: handle that is being entered into chain.
  423. *
  424. * Places new handle on iucv_handler_table, if identical handler is not
  425. * found.
  426. *
  427. * Returns: 0 on success, !0 on failure (handler already in chain).
  428. */
  429. static int
  430. iucv_add_handler (handler *new)
  431. {
  432. ulong flags;
  433. iucv_debug(1, "entering");
  434. iucv_dumpit("handler:", new, sizeof(handler));
  435. spin_lock_irqsave (&iucv_lock, flags);
  436. if (!list_empty(&iucv_handler_table)) {
  437. struct list_head *lh;
  438. /**
  439. * Search list for handler with identical id. If one
  440. * is found, the new handler is _not_ added.
  441. */
  442. list_for_each(lh, &iucv_handler_table) {
  443. handler *h = list_entry(lh, handler, list);
  444. if (!memcmp(&new->id, &h->id, sizeof(h->id))) {
  445. iucv_debug(1, "ret 1");
  446. spin_unlock_irqrestore (&iucv_lock, flags);
  447. return 1;
  448. }
  449. }
  450. }
  451. /**
  452. * If we get here, no handler was found.
  453. */
  454. INIT_LIST_HEAD(&new->list);
  455. list_add(&new->list, &iucv_handler_table);
  456. spin_unlock_irqrestore (&iucv_lock, flags);
  457. iucv_debug(1, "exiting");
  458. return 0;
  459. }
  460. /**
  461. * b2f0:
  462. * @code: identifier of IUCV call to CP.
  463. * @parm: pointer to 40 byte iparml area passed to CP
  464. *
  465. * Calls CP to execute IUCV commands.
  466. *
  467. * Returns: return code from CP's IUCV call
  468. */
  469. static __inline__ ulong
  470. b2f0(__u32 code, void *parm)
  471. {
  472. iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
  473. asm volatile (
  474. "LRA 1,0(%1)\n\t"
  475. "LR 0,%0\n\t"
  476. ".long 0xb2f01000"
  477. :
  478. : "d" (code), "a" (parm)
  479. : "0", "1"
  480. );
  481. iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
  482. return (unsigned long)*((__u8 *)(parm + 3));
  483. }
  484. /*
  485. * Name: iucv_add_pathid
  486. * Purpose: Adds a path id to the system.
  487. * Input: pathid - pathid that is going to be entered into system
  488. * handle - address of handler that the pathid will be associated
  489. * with.
  490. * pgm_data - token passed in by application.
  491. * Output: 0: successful addition of pathid
  492. * - EINVAL - pathid entry is being used by another application
  493. * - ENOMEM - storage allocation for a new pathid table failed
  494. */
  495. static int
  496. __iucv_add_pathid(__u16 pathid, handler *handler)
  497. {
  498. iucv_debug(1, "entering");
  499. iucv_debug(1, "handler is pointing to %p", handler);
  500. if (pathid > (max_connections - 1))
  501. return -EINVAL;
  502. if (iucv_pathid_table[pathid]) {
  503. iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
  504. printk(KERN_WARNING
  505. "%s: Pathid being used, error.\n", __FUNCTION__);
  506. return -EINVAL;
  507. }
  508. iucv_pathid_table[pathid] = handler;
  509. iucv_debug(1, "exiting");
  510. return 0;
  511. } /* end of add_pathid function */
  512. static int
  513. iucv_add_pathid(__u16 pathid, handler *handler)
  514. {
  515. ulong flags;
  516. int rc;
  517. spin_lock_irqsave (&iucv_lock, flags);
  518. rc = __iucv_add_pathid(pathid, handler);
  519. spin_unlock_irqrestore (&iucv_lock, flags);
  520. return rc;
  521. }
  522. static void
  523. iucv_remove_pathid(__u16 pathid)
  524. {
  525. ulong flags;
  526. if (pathid > (max_connections - 1))
  527. return;
  528. spin_lock_irqsave (&iucv_lock, flags);
  529. iucv_pathid_table[pathid] = NULL;
  530. spin_unlock_irqrestore (&iucv_lock, flags);
  531. }
  532. /**
  533. * iucv_declare_buffer_cpuid
  534. * Register at VM for subsequent IUCV operations. This is executed
  535. * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
  536. */
  537. static void
  538. iucv_declare_buffer_cpuid (void *result)
  539. {
  540. iparml_db *parm;
  541. parm = (iparml_db *)grab_param();
  542. parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
  543. if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
  544. *((ulong *)result) = parm->iprcode;
  545. release_param(parm);
  546. }
  547. /**
  548. * iucv_retrieve_buffer_cpuid:
  549. * Unregister IUCV usage at VM. This is always executed on the same
  550. * cpu that registered the buffer to VM.
  551. * Called from iucv_retrieve_buffer().
  552. */
  553. static void
  554. iucv_retrieve_buffer_cpuid (void *cpu)
  555. {
  556. iparml_control *parm;
  557. parm = (iparml_control *)grab_param();
  558. b2f0(RETRIEVE_BUFFER, parm);
  559. release_param(parm);
  560. }
  561. /**
  562. * Name: iucv_declare_buffer
  563. * Purpose: Specifies the guests real address of an external
  564. * interrupt.
  565. * Input: void
  566. * Output: iprcode - return code from b2f0 call
  567. */
  568. static int
  569. iucv_declare_buffer (void)
  570. {
  571. unsigned long flags;
  572. ulong b2f0_result;
  573. iucv_debug(1, "entering");
  574. b2f0_result = -ENODEV;
  575. spin_lock_irqsave (&iucv_lock, flags);
  576. if (iucv_cpuid == -1) {
  577. /* Reserve any cpu for use by iucv. */
  578. iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
  579. spin_unlock_irqrestore (&iucv_lock, flags);
  580. smp_call_function_on(iucv_declare_buffer_cpuid,
  581. &b2f0_result, 0, 1, iucv_cpuid);
  582. if (b2f0_result) {
  583. smp_put_cpu(iucv_cpuid);
  584. iucv_cpuid = -1;
  585. }
  586. iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
  587. } else {
  588. spin_unlock_irqrestore (&iucv_lock, flags);
  589. b2f0_result = 0;
  590. }
  591. iucv_debug(1, "exiting");
  592. return b2f0_result;
  593. }
  594. /**
  595. * iucv_retrieve_buffer:
  596. *
  597. * Terminates all use of IUCV.
  598. * Returns: return code from CP
  599. */
  600. static int
  601. iucv_retrieve_buffer (void)
  602. {
  603. iucv_debug(1, "entering");
  604. if (iucv_cpuid != -1) {
  605. smp_call_function_on(iucv_retrieve_buffer_cpuid,
  606. NULL, 0, 1, iucv_cpuid);
  607. /* Release the cpu reserved by iucv_declare_buffer. */
  608. smp_put_cpu(iucv_cpuid);
  609. iucv_cpuid = -1;
  610. }
  611. iucv_debug(1, "exiting");
  612. return 0;
  613. }
  614. /**
  615. * iucv_remove_handler:
  616. * @users_handler: handler to be removed
  617. *
  618. * Remove handler when application unregisters.
  619. */
  620. static void
  621. iucv_remove_handler(handler *handler)
  622. {
  623. unsigned long flags;
  624. if ((!iucv_pathid_table) || (!handler))
  625. return;
  626. iucv_debug(1, "entering");
  627. spin_lock_irqsave (&iucv_lock, flags);
  628. list_del(&handler->list);
  629. if (list_empty(&iucv_handler_table)) {
  630. if (register_flag) {
  631. unregister_external_interrupt(0x4000, iucv_irq_handler);
  632. register_flag = 0;
  633. }
  634. }
  635. spin_unlock_irqrestore (&iucv_lock, flags);
  636. iucv_debug(1, "exiting");
  637. return;
  638. }
  639. /**
  640. * iucv_register_program:
  641. * @pgmname: user identification
  642. * @userid: machine identification
  643. * @pgmmask: Indicates which bits in the pgmname and userid combined will be
  644. * used to determine who is given control.
  645. * @ops: Address of interrupt handler table.
  646. * @pgm_data: Application data to be passed to interrupt handlers.
  647. *
  648. * Registers an application with IUCV.
  649. * Returns:
  650. * The address of handler, or NULL on failure.
  651. * NOTE on pgmmask:
  652. * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
  653. * handler as is.
  654. * If pgmmask is NULL, the internal mask is set to all 0xff's
  655. * When userid is NULL, the first 8 bytes of the internal mask are forced
  656. * to 0x00.
  657. * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
  658. * are forced to 0x00 and the last 16 bytes to 0xff.
  659. */
  660. iucv_handle_t
  661. iucv_register_program (__u8 pgmname[16],
  662. __u8 userid[8],
  663. __u8 pgmmask[24],
  664. iucv_interrupt_ops_t * ops, void *pgm_data)
  665. {
  666. ulong rc = 0; /* return code from function calls */
  667. handler *new_handler;
  668. iucv_debug(1, "entering");
  669. if (ops == NULL) {
  670. /* interrupt table is not defined */
  671. printk(KERN_WARNING "%s: Interrupt table is not defined, "
  672. "exiting\n", __FUNCTION__);
  673. return NULL;
  674. }
  675. if (!pgmname) {
  676. printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
  677. return NULL;
  678. }
  679. /* Allocate handler entry */
  680. new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
  681. if (new_handler == NULL) {
  682. printk(KERN_WARNING "%s: storage allocation for new handler "
  683. "failed.\n", __FUNCTION__);
  684. return NULL;
  685. }
  686. if (!iucv_pathid_table) {
  687. if (iucv_init()) {
  688. kfree(new_handler);
  689. return NULL;
  690. }
  691. max_connections = iucv_query_maxconn();
  692. iucv_pathid_table = kcalloc(max_connections, sizeof(handler *),
  693. GFP_ATOMIC);
  694. if (iucv_pathid_table == NULL) {
  695. printk(KERN_WARNING "%s: iucv_pathid_table storage "
  696. "allocation failed\n", __FUNCTION__);
  697. kfree(new_handler);
  698. return NULL;
  699. }
  700. }
  701. memset(new_handler, 0, sizeof (handler));
  702. memcpy(new_handler->id.user_data, pgmname,
  703. sizeof (new_handler->id.user_data));
  704. if (userid) {
  705. memcpy (new_handler->id.userid, userid,
  706. sizeof (new_handler->id.userid));
  707. ASCEBC (new_handler->id.userid,
  708. sizeof (new_handler->id.userid));
  709. EBC_TOUPPER (new_handler->id.userid,
  710. sizeof (new_handler->id.userid));
  711. if (pgmmask) {
  712. memcpy (new_handler->id.mask, pgmmask,
  713. sizeof (new_handler->id.mask));
  714. } else {
  715. memset (new_handler->id.mask, 0xFF,
  716. sizeof (new_handler->id.mask));
  717. }
  718. } else {
  719. if (pgmmask) {
  720. memcpy (new_handler->id.mask, pgmmask,
  721. sizeof (new_handler->id.mask));
  722. } else {
  723. memset (new_handler->id.mask, 0xFF,
  724. sizeof (new_handler->id.mask));
  725. }
  726. memset (new_handler->id.userid, 0x00,
  727. sizeof (new_handler->id.userid));
  728. }
  729. /* fill in the rest of handler */
  730. new_handler->pgm_data = pgm_data;
  731. new_handler->interrupt_table = ops;
  732. /*
  733. * Check if someone else is registered with same pgmname, userid
  734. * and mask. If someone is already registered with same pgmname,
  735. * userid and mask, registration will fail and NULL will be returned
  736. * to the application.
  737. * If identical handler not found, then handler is added to list.
  738. */
  739. rc = iucv_add_handler(new_handler);
  740. if (rc) {
  741. printk(KERN_WARNING "%s: Someone already registered with same "
  742. "pgmname, userid, pgmmask\n", __FUNCTION__);
  743. kfree (new_handler);
  744. return NULL;
  745. }
  746. rc = iucv_declare_buffer();
  747. if (rc) {
  748. char *err = "Unknown";
  749. iucv_remove_handler(new_handler);
  750. kfree(new_handler);
  751. switch(rc) {
  752. case 0x03:
  753. err = "Directory error";
  754. break;
  755. case 0x0a:
  756. err = "Invalid length";
  757. break;
  758. case 0x13:
  759. err = "Buffer already exists";
  760. break;
  761. case 0x3e:
  762. err = "Buffer overlap";
  763. break;
  764. case 0x5c:
  765. err = "Paging or storage error";
  766. break;
  767. }
  768. printk(KERN_WARNING "%s: iucv_declare_buffer "
  769. "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
  770. return NULL;
  771. }
  772. if (!register_flag) {
  773. /* request the 0x4000 external interrupt */
  774. rc = register_external_interrupt (0x4000, iucv_irq_handler);
  775. if (rc) {
  776. iucv_remove_handler(new_handler);
  777. kfree (new_handler);
  778. printk(KERN_WARNING "%s: "
  779. "register_external_interrupt returned %ld\n",
  780. __FUNCTION__, rc);
  781. return NULL;
  782. }
  783. register_flag = 1;
  784. }
  785. iucv_debug(1, "exiting");
  786. return new_handler;
  787. } /* end of register function */
  788. /**
  789. * iucv_unregister_program:
  790. * @handle: address of handler
  791. *
  792. * Unregister application with IUCV.
  793. * Returns:
  794. * 0 on success, -EINVAL, if specified handle is invalid.
  795. */
  796. int
  797. iucv_unregister_program (iucv_handle_t handle)
  798. {
  799. handler *h = NULL;
  800. struct list_head *lh;
  801. int i;
  802. ulong flags;
  803. iucv_debug(1, "entering");
  804. iucv_debug(1, "address of handler is %p", h);
  805. /* Checking if handle is valid */
  806. spin_lock_irqsave (&iucv_lock, flags);
  807. list_for_each(lh, &iucv_handler_table) {
  808. if ((handler *)handle == list_entry(lh, handler, list)) {
  809. h = (handler *)handle;
  810. break;
  811. }
  812. }
  813. if (!h) {
  814. spin_unlock_irqrestore (&iucv_lock, flags);
  815. if (handle)
  816. printk(KERN_WARNING
  817. "%s: Handler not found in iucv_handler_table.\n",
  818. __FUNCTION__);
  819. else
  820. printk(KERN_WARNING
  821. "%s: NULL handle passed by application.\n",
  822. __FUNCTION__);
  823. return -EINVAL;
  824. }
  825. /**
  826. * First, walk thru iucv_pathid_table and sever any pathid which is
  827. * still pointing to the handler to be removed.
  828. */
  829. for (i = 0; i < max_connections; i++)
  830. if (iucv_pathid_table[i] == h) {
  831. spin_unlock_irqrestore (&iucv_lock, flags);
  832. iucv_sever(i, h->id.user_data);
  833. spin_lock_irqsave(&iucv_lock, flags);
  834. }
  835. spin_unlock_irqrestore (&iucv_lock, flags);
  836. iucv_remove_handler(h);
  837. kfree(h);
  838. iucv_debug(1, "exiting");
  839. return 0;
  840. }
  841. /**
  842. * iucv_accept:
  843. * @pathid: Path identification number
  844. * @msglim_reqstd: The number of outstanding messages requested.
  845. * @user_data: Data specified by the iucv_connect function.
  846. * @flags1: Contains options for this path.
  847. * - IPPRTY (0x20) Specifies if you want to send priority message.
  848. * - IPRMDATA (0x80) Specifies whether your program can handle a message
  849. * in the parameter list.
  850. * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
  851. * established.
  852. * @handle: Address of handler.
  853. * @pgm_data: Application data passed to interrupt handlers.
  854. * @flags1_out: Pointer to an int. If not NULL, on return the options for
  855. * the path are stored at the given location:
  856. * - IPPRTY (0x20) Indicates you may send a priority message.
  857. * @msglim: Pointer to an __u16. If not NULL, on return the maximum
  858. * number of outstanding messages is stored at the given
  859. * location.
  860. *
  861. * This function is issued after the user receives a Connection Pending external
  862. * interrupt and now wishes to complete the IUCV communication path.
  863. * Returns:
  864. * return code from CP
  865. */
  866. int
  867. iucv_accept(__u16 pathid, __u16 msglim_reqstd,
  868. __u8 user_data[16], int flags1,
  869. iucv_handle_t handle, void *pgm_data,
  870. int *flags1_out, __u16 * msglim)
  871. {
  872. ulong b2f0_result = 0;
  873. ulong flags;
  874. struct list_head *lh;
  875. handler *h = NULL;
  876. iparml_control *parm;
  877. iucv_debug(1, "entering");
  878. iucv_debug(1, "pathid = %d", pathid);
  879. /* Checking if handle is valid */
  880. spin_lock_irqsave (&iucv_lock, flags);
  881. list_for_each(lh, &iucv_handler_table) {
  882. if ((handler *)handle == list_entry(lh, handler, list)) {
  883. h = (handler *)handle;
  884. break;
  885. }
  886. }
  887. spin_unlock_irqrestore (&iucv_lock, flags);
  888. if (!h) {
  889. if (handle)
  890. printk(KERN_WARNING
  891. "%s: Handler not found in iucv_handler_table.\n",
  892. __FUNCTION__);
  893. else
  894. printk(KERN_WARNING
  895. "%s: NULL handle passed by application.\n",
  896. __FUNCTION__);
  897. return -EINVAL;
  898. }
  899. parm = (iparml_control *)grab_param();
  900. parm->ippathid = pathid;
  901. parm->ipmsglim = msglim_reqstd;
  902. if (user_data)
  903. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  904. parm->ipflags1 = (__u8)flags1;
  905. b2f0_result = b2f0(ACCEPT, parm);
  906. if (!b2f0_result) {
  907. if (msglim)
  908. *msglim = parm->ipmsglim;
  909. if (pgm_data)
  910. h->pgm_data = pgm_data;
  911. if (flags1_out)
  912. *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
  913. }
  914. release_param(parm);
  915. iucv_debug(1, "exiting");
  916. return b2f0_result;
  917. }
  918. /**
  919. * iucv_connect:
  920. * @pathid: Path identification number
  921. * @msglim_reqstd: Number of outstanding messages requested
  922. * @user_data: 16-byte user data
  923. * @userid: 8-byte of user identification
  924. * @system_name: 8-byte identifying the system name
  925. * @flags1: Specifies options for this path:
  926. * - IPPRTY (0x20) Specifies if you want to send priority message.
  927. * - IPRMDATA (0x80) Specifies whether your program can handle a message
  928. * in the parameter list.
  929. * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
  930. * established.
  931. * - IPLOCAL (0x01) Allows an application to force the partner to be on the
  932. * local system. If local is specified then target class
  933. * cannot be specified.
  934. * @flags1_out: Pointer to an int. If not NULL, on return the options for
  935. * the path are stored at the given location:
  936. * - IPPRTY (0x20) Indicates you may send a priority message.
  937. * @msglim: Pointer to an __u16. If not NULL, on return the maximum
  938. * number of outstanding messages is stored at the given
  939. * location.
  940. * @handle: Address of handler.
  941. * @pgm_data: Application data to be passed to interrupt handlers.
  942. *
  943. * This function establishes an IUCV path. Although the connect may complete
  944. * successfully, you are not able to use the path until you receive an IUCV
  945. * Connection Complete external interrupt.
  946. * Returns: return code from CP, or one of the following
  947. * - ENOMEM
  948. * - return code from iucv_declare_buffer
  949. * - EINVAL - invalid handle passed by application
  950. * - EINVAL - pathid address is NULL
  951. * - ENOMEM - pathid table storage allocation failed
  952. * - return code from internal function add_pathid
  953. */
  954. int
  955. iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
  956. __u8 user_data[16], __u8 userid[8],
  957. __u8 system_name[8], int flags1,
  958. int *flags1_out, __u16 * msglim,
  959. iucv_handle_t handle, void *pgm_data)
  960. {
  961. iparml_control *parm;
  962. iparml_control local_parm;
  963. struct list_head *lh;
  964. ulong b2f0_result = 0;
  965. ulong flags;
  966. int add_pathid_result = 0;
  967. handler *h = NULL;
  968. __u8 no_memory[16] = "NO MEMORY";
  969. iucv_debug(1, "entering");
  970. /* Checking if handle is valid */
  971. spin_lock_irqsave (&iucv_lock, flags);
  972. list_for_each(lh, &iucv_handler_table) {
  973. if ((handler *)handle == list_entry(lh, handler, list)) {
  974. h = (handler *)handle;
  975. break;
  976. }
  977. }
  978. spin_unlock_irqrestore (&iucv_lock, flags);
  979. if (!h) {
  980. if (handle)
  981. printk(KERN_WARNING
  982. "%s: Handler not found in iucv_handler_table.\n",
  983. __FUNCTION__);
  984. else
  985. printk(KERN_WARNING
  986. "%s: NULL handle passed by application.\n",
  987. __FUNCTION__);
  988. return -EINVAL;
  989. }
  990. if (pathid == NULL) {
  991. printk(KERN_WARNING "%s: NULL pathid pointer\n",
  992. __FUNCTION__);
  993. return -EINVAL;
  994. }
  995. parm = (iparml_control *)grab_param();
  996. parm->ipmsglim = msglim_reqstd;
  997. if (user_data)
  998. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  999. if (userid) {
  1000. memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
  1001. ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
  1002. EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
  1003. }
  1004. if (system_name) {
  1005. memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
  1006. ASCEBC(parm->iptarget, sizeof(parm->iptarget));
  1007. EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
  1008. }
  1009. /* In order to establish an IUCV connection, the procedure is:
  1010. *
  1011. * b2f0(CONNECT)
  1012. * take the ippathid from the b2f0 call
  1013. * register the handler to the ippathid
  1014. *
  1015. * Unfortunately, the ConnectionEstablished message gets sent after the
  1016. * b2f0(CONNECT) call but before the register is handled.
  1017. *
  1018. * In order for this race condition to be eliminated, the IUCV Control
  1019. * Interrupts must be disabled for the above procedure.
  1020. *
  1021. * David Kennedy <dkennedy@linuxcare.com>
  1022. */
  1023. /* Enable everything but IUCV Control messages */
  1024. iucv_setmask(~(AllInterrupts));
  1025. messagesDisabled = 1;
  1026. spin_lock_irqsave (&iucv_lock, flags);
  1027. parm->ipflags1 = (__u8)flags1;
  1028. b2f0_result = b2f0(CONNECT, parm);
  1029. memcpy(&local_parm, parm, sizeof(local_parm));
  1030. release_param(parm);
  1031. parm = &local_parm;
  1032. if (!b2f0_result)
  1033. add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
  1034. spin_unlock_irqrestore (&iucv_lock, flags);
  1035. if (b2f0_result) {
  1036. iucv_setmask(~0);
  1037. messagesDisabled = 0;
  1038. return b2f0_result;
  1039. }
  1040. *pathid = parm->ippathid;
  1041. /* Enable everything again */
  1042. iucv_setmask(IUCVControlInterruptsFlag);
  1043. if (msglim)
  1044. *msglim = parm->ipmsglim;
  1045. if (flags1_out)
  1046. *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
  1047. if (add_pathid_result) {
  1048. iucv_sever(*pathid, no_memory);
  1049. printk(KERN_WARNING "%s: add_pathid failed with rc ="
  1050. " %d\n", __FUNCTION__, add_pathid_result);
  1051. return(add_pathid_result);
  1052. }
  1053. iucv_debug(1, "exiting");
  1054. return b2f0_result;
  1055. }
  1056. /**
  1057. * iucv_purge:
  1058. * @pathid: Path identification number
  1059. * @msgid: Message ID of message to purge.
  1060. * @srccls: Message class of the message to purge.
  1061. * @audit: Pointer to an __u32. If not NULL, on return, information about
  1062. * asynchronous errors that may have affected the normal completion
  1063. * of this message ist stored at the given location.
  1064. *
  1065. * Cancels a message you have sent.
  1066. * Returns: return code from CP
  1067. */
  1068. int
  1069. iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
  1070. {
  1071. iparml_purge *parm;
  1072. ulong b2f0_result = 0;
  1073. iucv_debug(1, "entering");
  1074. iucv_debug(1, "pathid = %d", pathid);
  1075. parm = (iparml_purge *)grab_param();
  1076. parm->ipmsgid = msgid;
  1077. parm->ippathid = pathid;
  1078. parm->ipsrccls = srccls;
  1079. parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
  1080. b2f0_result = b2f0(PURGE, parm);
  1081. if (!b2f0_result && audit) {
  1082. memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
  1083. /* parm->ipaudit has only 3 bytes */
  1084. *audit >>= 8;
  1085. }
  1086. release_param(parm);
  1087. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1088. iucv_debug(1, "exiting");
  1089. return b2f0_result;
  1090. }
  1091. /**
  1092. * iucv_query_generic:
  1093. * @want_maxconn: Flag, describing which value is to be returned.
  1094. *
  1095. * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
  1096. *
  1097. * Returns: The buffersize, if want_maxconn is 0; the maximum number of
  1098. * connections, if want_maxconn is 1 or an error-code < 0 on failure.
  1099. */
  1100. static int
  1101. iucv_query_generic(int want_maxconn)
  1102. {
  1103. iparml_purge *parm = (iparml_purge *)grab_param();
  1104. int bufsize, maxconn;
  1105. int ccode;
  1106. /**
  1107. * Call b2f0 and store R0 (max buffer size),
  1108. * R1 (max connections) and CC.
  1109. */
  1110. asm volatile (
  1111. "LRA 1,0(%4)\n\t"
  1112. "LR 0,%3\n\t"
  1113. ".long 0xb2f01000\n\t"
  1114. "IPM %0\n\t"
  1115. "SRL %0,28\n\t"
  1116. "ST 0,%1\n\t"
  1117. "ST 1,%2\n\t"
  1118. : "=d" (ccode), "=m" (bufsize), "=m" (maxconn)
  1119. : "d" (QUERY), "a" (parm)
  1120. : "0", "1", "cc"
  1121. );
  1122. release_param(parm);
  1123. if (ccode)
  1124. return -EPERM;
  1125. if (want_maxconn)
  1126. return maxconn;
  1127. return bufsize;
  1128. }
  1129. /**
  1130. * iucv_query_maxconn:
  1131. *
  1132. * Determines the maximum number of connections thay may be established.
  1133. *
  1134. * Returns: Maximum number of connections that can be.
  1135. */
  1136. ulong
  1137. iucv_query_maxconn(void)
  1138. {
  1139. return iucv_query_generic(1);
  1140. }
  1141. /**
  1142. * iucv_query_bufsize:
  1143. *
  1144. * Determines the size of the external interrupt buffer.
  1145. *
  1146. * Returns: Size of external interrupt buffer.
  1147. */
  1148. ulong
  1149. iucv_query_bufsize (void)
  1150. {
  1151. return iucv_query_generic(0);
  1152. }
  1153. /**
  1154. * iucv_quiesce:
  1155. * @pathid: Path identification number
  1156. * @user_data: 16-byte user data
  1157. *
  1158. * Temporarily suspends incoming messages on an IUCV path.
  1159. * You can later reactivate the path by invoking the iucv_resume function.
  1160. * Returns: return code from CP
  1161. */
  1162. int
  1163. iucv_quiesce (__u16 pathid, __u8 user_data[16])
  1164. {
  1165. iparml_control *parm;
  1166. ulong b2f0_result = 0;
  1167. iucv_debug(1, "entering");
  1168. iucv_debug(1, "pathid = %d", pathid);
  1169. parm = (iparml_control *)grab_param();
  1170. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  1171. parm->ippathid = pathid;
  1172. b2f0_result = b2f0(QUIESCE, parm);
  1173. release_param(parm);
  1174. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1175. iucv_debug(1, "exiting");
  1176. return b2f0_result;
  1177. }
  1178. /**
  1179. * iucv_receive:
  1180. * @pathid: Path identification number.
  1181. * @buffer: Address of buffer to receive. Must be below 2G.
  1182. * @buflen: Length of buffer to receive.
  1183. * @msgid: Specifies the message ID.
  1184. * @trgcls: Specifies target class.
  1185. * @flags1_out: Receives options for path on return.
  1186. * - IPNORPY (0x10) Specifies whether a reply is required
  1187. * - IPPRTY (0x20) Specifies if you want to send priority message
  1188. * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
  1189. * @residual_buffer: Receives the address of buffer updated by the number
  1190. * of bytes you have received on return.
  1191. * @residual_length: On return, receives one of the following values:
  1192. * - 0 If the receive buffer is the same length as
  1193. * the message.
  1194. * - Remaining bytes in buffer If the receive buffer is longer than the
  1195. * message.
  1196. * - Remaining bytes in message If the receive buffer is shorter than the
  1197. * message.
  1198. *
  1199. * This function receives messages that are being sent to you over established
  1200. * paths.
  1201. * Returns: return code from CP IUCV call; If the receive buffer is shorter
  1202. * than the message, always 5
  1203. * -EINVAL - buffer address is pointing to NULL
  1204. */
  1205. int
  1206. iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
  1207. void *buffer, ulong buflen,
  1208. int *flags1_out, ulong * residual_buffer, ulong * residual_length)
  1209. {
  1210. iparml_db *parm;
  1211. ulong b2f0_result;
  1212. int moved = 0; /* number of bytes moved from parmlist to buffer */
  1213. iucv_debug(2, "entering");
  1214. if (!buffer)
  1215. return -EINVAL;
  1216. parm = (iparml_db *)grab_param();
  1217. parm->ipbfadr1 = (__u32) (addr_t) buffer;
  1218. parm->ipbfln1f = (__u32) ((ulong) buflen);
  1219. parm->ipmsgid = msgid;
  1220. parm->ippathid = pathid;
  1221. parm->iptrgcls = trgcls;
  1222. parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
  1223. b2f0_result = b2f0(RECEIVE, parm);
  1224. if (!b2f0_result || b2f0_result == 5) {
  1225. if (flags1_out) {
  1226. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1227. *flags1_out = (parm->ipflags1 & (~0x07));
  1228. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1229. }
  1230. if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
  1231. if (residual_length)
  1232. *residual_length = parm->ipbfln1f;
  1233. if (residual_buffer)
  1234. *residual_buffer = parm->ipbfadr1;
  1235. } else {
  1236. moved = min_t (unsigned long, buflen, 8);
  1237. memcpy ((char *) buffer,
  1238. (char *) &parm->ipbfadr1, moved);
  1239. if (buflen < 8)
  1240. b2f0_result = 5;
  1241. if (residual_length)
  1242. *residual_length = abs (buflen - 8);
  1243. if (residual_buffer)
  1244. *residual_buffer = (ulong) (buffer + moved);
  1245. }
  1246. }
  1247. release_param(parm);
  1248. iucv_debug(2, "exiting");
  1249. return b2f0_result;
  1250. }
  1251. /*
  1252. * Name: iucv_receive_array
  1253. * Purpose: This function receives messages that are being sent to you
  1254. * over established paths.
  1255. * Input: pathid - path identification number
  1256. * buffer - address of array of buffers
  1257. * buflen - total length of buffers
  1258. * msgid - specifies the message ID.
  1259. * trgcls - specifies target class
  1260. * Output:
  1261. * flags1_out: Options for path.
  1262. * IPNORPY - 0x10 specifies whether a reply is required
  1263. * IPPRTY - 0x20 specifies if you want to send priority message
  1264. * IPRMDATA - 0x80 specifies the data is contained in the parameter list
  1265. * residual_buffer - address points to the current list entry IUCV
  1266. * is working on.
  1267. * residual_length -
  1268. * Contains one of the following values, if the receive buffer is:
  1269. * The same length as the message, this field is zero.
  1270. * Longer than the message, this field contains the number of
  1271. * bytes remaining in the buffer.
  1272. * Shorter than the message, this field contains the residual
  1273. * count (that is, the number of bytes remaining in the
  1274. * message that does not fit into the buffer. In this case
  1275. * b2f0_result = 5.
  1276. * Return: b2f0_result - return code from CP
  1277. * (-EINVAL) - buffer address is NULL
  1278. */
  1279. int
  1280. iucv_receive_array (__u16 pathid,
  1281. __u32 msgid, __u32 trgcls,
  1282. iucv_array_t * buffer, ulong buflen,
  1283. int *flags1_out,
  1284. ulong * residual_buffer, ulong * residual_length)
  1285. {
  1286. iparml_db *parm;
  1287. ulong b2f0_result;
  1288. int i = 0, moved = 0, need_to_move = 8, dyn_len;
  1289. iucv_debug(2, "entering");
  1290. if (!buffer)
  1291. return -EINVAL;
  1292. parm = (iparml_db *)grab_param();
  1293. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1294. parm->ipbfln1f = (__u32) buflen;
  1295. parm->ipmsgid = msgid;
  1296. parm->ippathid = pathid;
  1297. parm->iptrgcls = trgcls;
  1298. parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
  1299. b2f0_result = b2f0(RECEIVE, parm);
  1300. if (!b2f0_result || b2f0_result == 5) {
  1301. if (flags1_out) {
  1302. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1303. *flags1_out = (parm->ipflags1 & (~0x07));
  1304. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1305. }
  1306. if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
  1307. if (residual_length)
  1308. *residual_length = parm->ipbfln1f;
  1309. if (residual_buffer)
  1310. *residual_buffer = parm->ipbfadr1;
  1311. } else {
  1312. /* copy msg from parmlist to users array. */
  1313. while ((moved < 8) && (moved < buflen)) {
  1314. dyn_len =
  1315. min_t (unsigned int,
  1316. (buffer + i)->length, need_to_move);
  1317. memcpy ((char *)((ulong)((buffer + i)->address)),
  1318. ((char *) &parm->ipbfadr1) + moved,
  1319. dyn_len);
  1320. moved += dyn_len;
  1321. need_to_move -= dyn_len;
  1322. (buffer + i)->address =
  1323. (__u32)
  1324. ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
  1325. + dyn_len);
  1326. (buffer + i)->length -= dyn_len;
  1327. i++;
  1328. }
  1329. if (need_to_move) /* buflen < 8 bytes */
  1330. b2f0_result = 5;
  1331. if (residual_length)
  1332. *residual_length = abs (buflen - 8);
  1333. if (residual_buffer) {
  1334. if (!moved)
  1335. *residual_buffer = (ulong) buffer;
  1336. else
  1337. *residual_buffer =
  1338. (ulong) (buffer + (i - 1));
  1339. }
  1340. }
  1341. }
  1342. release_param(parm);
  1343. iucv_debug(2, "exiting");
  1344. return b2f0_result;
  1345. }
  1346. /**
  1347. * iucv_reject:
  1348. * @pathid: Path identification number.
  1349. * @msgid: Message ID of the message to reject.
  1350. * @trgcls: Target class of the message to reject.
  1351. * Returns: return code from CP
  1352. *
  1353. * Refuses a specified message. Between the time you are notified of a
  1354. * message and the time that you complete the message, the message may
  1355. * be rejected.
  1356. */
  1357. int
  1358. iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
  1359. {
  1360. iparml_db *parm;
  1361. ulong b2f0_result = 0;
  1362. iucv_debug(1, "entering");
  1363. iucv_debug(1, "pathid = %d", pathid);
  1364. parm = (iparml_db *)grab_param();
  1365. parm->ippathid = pathid;
  1366. parm->ipmsgid = msgid;
  1367. parm->iptrgcls = trgcls;
  1368. parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
  1369. b2f0_result = b2f0(REJECT, parm);
  1370. release_param(parm);
  1371. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1372. iucv_debug(1, "exiting");
  1373. return b2f0_result;
  1374. }
  1375. /*
  1376. * Name: iucv_reply
  1377. * Purpose: This function responds to the two-way messages that you
  1378. * receive. You must identify completely the message to
  1379. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1380. * Input: pathid - path identification number
  1381. * msgid - specifies the message ID.
  1382. * trgcls - specifies target class
  1383. * flags1 - option for path
  1384. * IPPRTY- 0x20 - specifies if you want to send priority message
  1385. * buffer - address of reply buffer
  1386. * buflen - length of reply buffer
  1387. * Output: ipbfadr2 - Address of buffer updated by the number
  1388. * of bytes you have moved.
  1389. * ipbfln2f - Contains one of the following values:
  1390. * If the answer buffer is the same length as the reply, this field
  1391. * contains zero.
  1392. * If the answer buffer is longer than the reply, this field contains
  1393. * the number of bytes remaining in the buffer.
  1394. * If the answer buffer is shorter than the reply, this field contains
  1395. * a residual count (that is, the number of bytes remianing in the
  1396. * reply that does not fit into the buffer. In this
  1397. * case b2f0_result = 5.
  1398. * Return: b2f0_result - return code from CP
  1399. * (-EINVAL) - buffer address is NULL
  1400. */
  1401. int
  1402. iucv_reply (__u16 pathid,
  1403. __u32 msgid, __u32 trgcls,
  1404. int flags1,
  1405. void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
  1406. {
  1407. iparml_db *parm;
  1408. ulong b2f0_result;
  1409. iucv_debug(2, "entering");
  1410. if (!buffer)
  1411. return -EINVAL;
  1412. parm = (iparml_db *)grab_param();
  1413. parm->ipbfadr2 = (__u32) ((ulong) buffer);
  1414. parm->ipbfln2f = (__u32) buflen; /* length of message */
  1415. parm->ippathid = pathid;
  1416. parm->ipmsgid = msgid;
  1417. parm->iptrgcls = trgcls;
  1418. parm->ipflags1 = (__u8) flags1; /* priority message */
  1419. b2f0_result = b2f0(REPLY, parm);
  1420. if ((!b2f0_result) || (b2f0_result == 5)) {
  1421. if (ipbfadr2)
  1422. *ipbfadr2 = parm->ipbfadr2;
  1423. if (ipbfln2f)
  1424. *ipbfln2f = parm->ipbfln2f;
  1425. }
  1426. release_param(parm);
  1427. iucv_debug(2, "exiting");
  1428. return b2f0_result;
  1429. }
  1430. /*
  1431. * Name: iucv_reply_array
  1432. * Purpose: This function responds to the two-way messages that you
  1433. * receive. You must identify completely the message to
  1434. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1435. * The array identifies a list of addresses and lengths of
  1436. * discontiguous buffers that contains the reply data.
  1437. * Input: pathid - path identification number
  1438. * msgid - specifies the message ID.
  1439. * trgcls - specifies target class
  1440. * flags1 - option for path
  1441. * IPPRTY- specifies if you want to send priority message
  1442. * buffer - address of array of reply buffers
  1443. * buflen - total length of reply buffers
  1444. * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
  1445. * ipbfln2f - Contains one of the following values:
  1446. * If the answer buffer is the same length as the reply, this field
  1447. * contains zero.
  1448. * If the answer buffer is longer than the reply, this field contains
  1449. * the number of bytes remaining in the buffer.
  1450. * If the answer buffer is shorter than the reply, this field contains
  1451. * a residual count (that is, the number of bytes remianing in the
  1452. * reply that does not fit into the buffer. In this
  1453. * case b2f0_result = 5.
  1454. * Return: b2f0_result - return code from CP
  1455. * (-EINVAL) - buffer address is NULL
  1456. */
  1457. int
  1458. iucv_reply_array (__u16 pathid,
  1459. __u32 msgid, __u32 trgcls,
  1460. int flags1,
  1461. iucv_array_t * buffer,
  1462. ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
  1463. {
  1464. iparml_db *parm;
  1465. ulong b2f0_result;
  1466. iucv_debug(2, "entering");
  1467. if (!buffer)
  1468. return -EINVAL;
  1469. parm = (iparml_db *)grab_param();
  1470. parm->ipbfadr2 = (__u32) ((ulong) buffer);
  1471. parm->ipbfln2f = buflen; /* length of message */
  1472. parm->ippathid = pathid;
  1473. parm->ipmsgid = msgid;
  1474. parm->iptrgcls = trgcls;
  1475. parm->ipflags1 = (IPANSLST | flags1);
  1476. b2f0_result = b2f0(REPLY, parm);
  1477. if ((!b2f0_result) || (b2f0_result == 5)) {
  1478. if (ipbfadr2)
  1479. *ipbfadr2 = parm->ipbfadr2;
  1480. if (ipbfln2f)
  1481. *ipbfln2f = parm->ipbfln2f;
  1482. }
  1483. release_param(parm);
  1484. iucv_debug(2, "exiting");
  1485. return b2f0_result;
  1486. }
  1487. /*
  1488. * Name: iucv_reply_prmmsg
  1489. * Purpose: This function responds to the two-way messages that you
  1490. * receive. You must identify completely the message to
  1491. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1492. * Prmmsg signifies the data is moved into the
  1493. * parameter list.
  1494. * Input: pathid - path identification number
  1495. * msgid - specifies the message ID.
  1496. * trgcls - specifies target class
  1497. * flags1 - option for path
  1498. * IPPRTY- specifies if you want to send priority message
  1499. * prmmsg - 8-bytes of data to be placed into the parameter
  1500. * list.
  1501. * Output: NA
  1502. * Return: b2f0_result - return code from CP
  1503. */
  1504. int
  1505. iucv_reply_prmmsg (__u16 pathid,
  1506. __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
  1507. {
  1508. iparml_dpl *parm;
  1509. ulong b2f0_result;
  1510. iucv_debug(2, "entering");
  1511. parm = (iparml_dpl *)grab_param();
  1512. parm->ippathid = pathid;
  1513. parm->ipmsgid = msgid;
  1514. parm->iptrgcls = trgcls;
  1515. memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
  1516. parm->ipflags1 = (IPRMDATA | flags1);
  1517. b2f0_result = b2f0(REPLY, parm);
  1518. release_param(parm);
  1519. iucv_debug(2, "exiting");
  1520. return b2f0_result;
  1521. }
  1522. /**
  1523. * iucv_resume:
  1524. * @pathid: Path identification number
  1525. * @user_data: 16-byte of user data
  1526. *
  1527. * This function restores communication over a quiesced path.
  1528. * Returns: return code from CP
  1529. */
  1530. int
  1531. iucv_resume (__u16 pathid, __u8 user_data[16])
  1532. {
  1533. iparml_control *parm;
  1534. ulong b2f0_result = 0;
  1535. iucv_debug(1, "entering");
  1536. iucv_debug(1, "pathid = %d", pathid);
  1537. parm = (iparml_control *)grab_param();
  1538. memcpy (parm->ipuser, user_data, sizeof (*user_data));
  1539. parm->ippathid = pathid;
  1540. b2f0_result = b2f0(RESUME, parm);
  1541. release_param(parm);
  1542. iucv_debug(1, "exiting");
  1543. return b2f0_result;
  1544. }
  1545. /*
  1546. * Name: iucv_send
  1547. * Purpose: sends messages
  1548. * Input: pathid - ushort, pathid
  1549. * msgid - ulong *, id of message returned to caller
  1550. * trgcls - ulong, target message class
  1551. * srccls - ulong, source message class
  1552. * msgtag - ulong, message tag
  1553. * flags1 - Contains options for this path.
  1554. * IPPRTY - Ox20 - specifies if you want to send a priority message.
  1555. * buffer - pointer to buffer
  1556. * buflen - ulong, length of buffer
  1557. * Output: b2f0_result - return code from b2f0 call
  1558. * msgid - returns message id
  1559. */
  1560. int
  1561. iucv_send (__u16 pathid, __u32 * msgid,
  1562. __u32 trgcls, __u32 srccls,
  1563. __u32 msgtag, int flags1, void *buffer, ulong buflen)
  1564. {
  1565. iparml_db *parm;
  1566. ulong b2f0_result;
  1567. iucv_debug(2, "entering");
  1568. if (!buffer)
  1569. return -EINVAL;
  1570. parm = (iparml_db *)grab_param();
  1571. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1572. parm->ippathid = pathid;
  1573. parm->iptrgcls = trgcls;
  1574. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1575. parm->ipsrccls = srccls;
  1576. parm->ipmsgtag = msgtag;
  1577. parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
  1578. b2f0_result = b2f0(SEND, parm);
  1579. if ((!b2f0_result) && (msgid))
  1580. *msgid = parm->ipmsgid;
  1581. release_param(parm);
  1582. iucv_debug(2, "exiting");
  1583. return b2f0_result;
  1584. }
  1585. /*
  1586. * Name: iucv_send_array
  1587. * Purpose: This function transmits data to another application.
  1588. * The contents of buffer is the address of the array of
  1589. * addresses and lengths of discontiguous buffers that hold
  1590. * the message text. This is a one-way message and the
  1591. * receiver will not reply to the message.
  1592. * Input: pathid - path identification number
  1593. * trgcls - specifies target class
  1594. * srccls - specifies the source message class
  1595. * msgtag - specifies a tag to be associated witht the message
  1596. * flags1 - option for path
  1597. * IPPRTY- specifies if you want to send priority message
  1598. * buffer - address of array of send buffers
  1599. * buflen - total length of send buffers
  1600. * Output: msgid - specifies the message ID.
  1601. * Return: b2f0_result - return code from CP
  1602. * (-EINVAL) - buffer address is NULL
  1603. */
  1604. int
  1605. iucv_send_array (__u16 pathid,
  1606. __u32 * msgid,
  1607. __u32 trgcls,
  1608. __u32 srccls,
  1609. __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
  1610. {
  1611. iparml_db *parm;
  1612. ulong b2f0_result;
  1613. iucv_debug(2, "entering");
  1614. if (!buffer)
  1615. return -EINVAL;
  1616. parm = (iparml_db *)grab_param();
  1617. parm->ippathid = pathid;
  1618. parm->iptrgcls = trgcls;
  1619. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1620. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1621. parm->ipsrccls = srccls;
  1622. parm->ipmsgtag = msgtag;
  1623. parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
  1624. b2f0_result = b2f0(SEND, parm);
  1625. if ((!b2f0_result) && (msgid))
  1626. *msgid = parm->ipmsgid;
  1627. release_param(parm);
  1628. iucv_debug(2, "exiting");
  1629. return b2f0_result;
  1630. }
  1631. /*
  1632. * Name: iucv_send_prmmsg
  1633. * Purpose: This function transmits data to another application.
  1634. * Prmmsg specifies that the 8-bytes of data are to be moved
  1635. * into the parameter list. This is a one-way message and the
  1636. * receiver will not reply to the message.
  1637. * Input: pathid - path identification number
  1638. * trgcls - specifies target class
  1639. * srccls - specifies the source message class
  1640. * msgtag - specifies a tag to be associated with the message
  1641. * flags1 - option for path
  1642. * IPPRTY- specifies if you want to send priority message
  1643. * prmmsg - 8-bytes of data to be placed into parameter list
  1644. * Output: msgid - specifies the message ID.
  1645. * Return: b2f0_result - return code from CP
  1646. */
  1647. int
  1648. iucv_send_prmmsg (__u16 pathid,
  1649. __u32 * msgid,
  1650. __u32 trgcls,
  1651. __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
  1652. {
  1653. iparml_dpl *parm;
  1654. ulong b2f0_result;
  1655. iucv_debug(2, "entering");
  1656. parm = (iparml_dpl *)grab_param();
  1657. parm->ippathid = pathid;
  1658. parm->iptrgcls = trgcls;
  1659. parm->ipsrccls = srccls;
  1660. parm->ipmsgtag = msgtag;
  1661. parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
  1662. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1663. b2f0_result = b2f0(SEND, parm);
  1664. if ((!b2f0_result) && (msgid))
  1665. *msgid = parm->ipmsgid;
  1666. release_param(parm);
  1667. iucv_debug(2, "exiting");
  1668. return b2f0_result;
  1669. }
  1670. /*
  1671. * Name: iucv_send2way
  1672. * Purpose: This function transmits data to another application.
  1673. * Data to be transmitted is in a buffer. The receiver
  1674. * of the send is expected to reply to the message and
  1675. * a buffer is provided into which IUCV moves the reply
  1676. * to this message.
  1677. * Input: pathid - path identification number
  1678. * trgcls - specifies target class
  1679. * srccls - specifies the source message class
  1680. * msgtag - specifies a tag associated with the message
  1681. * flags1 - option for path
  1682. * IPPRTY- specifies if you want to send priority message
  1683. * buffer - address of send buffer
  1684. * buflen - length of send buffer
  1685. * ansbuf - address of buffer to reply with
  1686. * anslen - length of buffer to reply with
  1687. * Output: msgid - specifies the message ID.
  1688. * Return: b2f0_result - return code from CP
  1689. * (-EINVAL) - buffer or ansbuf address is NULL
  1690. */
  1691. int
  1692. iucv_send2way (__u16 pathid,
  1693. __u32 * msgid,
  1694. __u32 trgcls,
  1695. __u32 srccls,
  1696. __u32 msgtag,
  1697. int flags1,
  1698. void *buffer, ulong buflen, void *ansbuf, ulong anslen)
  1699. {
  1700. iparml_db *parm;
  1701. ulong b2f0_result;
  1702. iucv_debug(2, "entering");
  1703. if (!buffer || !ansbuf)
  1704. return -EINVAL;
  1705. parm = (iparml_db *)grab_param();
  1706. parm->ippathid = pathid;
  1707. parm->iptrgcls = trgcls;
  1708. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1709. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1710. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1711. parm->ipbfln2f = (__u32) anslen;
  1712. parm->ipsrccls = srccls;
  1713. parm->ipmsgtag = msgtag;
  1714. parm->ipflags1 = flags1; /* priority message */
  1715. b2f0_result = b2f0(SEND, parm);
  1716. if ((!b2f0_result) && (msgid))
  1717. *msgid = parm->ipmsgid;
  1718. release_param(parm);
  1719. iucv_debug(2, "exiting");
  1720. return b2f0_result;
  1721. }
  1722. /*
  1723. * Name: iucv_send2way_array
  1724. * Purpose: This function transmits data to another application.
  1725. * The contents of buffer is the address of the array of
  1726. * addresses and lengths of discontiguous buffers that hold
  1727. * the message text. The receiver of the send is expected to
  1728. * reply to the message and a buffer is provided into which
  1729. * IUCV moves the reply to this message.
  1730. * Input: pathid - path identification number
  1731. * trgcls - specifies target class
  1732. * srccls - specifies the source message class
  1733. * msgtag - spcifies a tag to be associated with the message
  1734. * flags1 - option for path
  1735. * IPPRTY- specifies if you want to send priority message
  1736. * buffer - address of array of send buffers
  1737. * buflen - total length of send buffers
  1738. * ansbuf - address of buffer to reply with
  1739. * anslen - length of buffer to reply with
  1740. * Output: msgid - specifies the message ID.
  1741. * Return: b2f0_result - return code from CP
  1742. * (-EINVAL) - buffer address is NULL
  1743. */
  1744. int
  1745. iucv_send2way_array (__u16 pathid,
  1746. __u32 * msgid,
  1747. __u32 trgcls,
  1748. __u32 srccls,
  1749. __u32 msgtag,
  1750. int flags1,
  1751. iucv_array_t * buffer,
  1752. ulong buflen, iucv_array_t * ansbuf, ulong anslen)
  1753. {
  1754. iparml_db *parm;
  1755. ulong b2f0_result;
  1756. iucv_debug(2, "entering");
  1757. if (!buffer || !ansbuf)
  1758. return -EINVAL;
  1759. parm = (iparml_db *)grab_param();
  1760. parm->ippathid = pathid;
  1761. parm->iptrgcls = trgcls;
  1762. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1763. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1764. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1765. parm->ipbfln2f = (__u32) anslen;
  1766. parm->ipsrccls = srccls;
  1767. parm->ipmsgtag = msgtag;
  1768. parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
  1769. b2f0_result = b2f0(SEND, parm);
  1770. if ((!b2f0_result) && (msgid))
  1771. *msgid = parm->ipmsgid;
  1772. release_param(parm);
  1773. iucv_debug(2, "exiting");
  1774. return b2f0_result;
  1775. }
  1776. /*
  1777. * Name: iucv_send2way_prmmsg
  1778. * Purpose: This function transmits data to another application.
  1779. * Prmmsg specifies that the 8-bytes of data are to be moved
  1780. * into the parameter list. This is a two-way message and the
  1781. * receiver of the message is expected to reply. A buffer
  1782. * is provided into which IUCV moves the reply to this
  1783. * message.
  1784. * Input: pathid - path identification number
  1785. * trgcls - specifies target class
  1786. * srccls - specifies the source message class
  1787. * msgtag - specifies a tag to be associated with the message
  1788. * flags1 - option for path
  1789. * IPPRTY- specifies if you want to send priority message
  1790. * prmmsg - 8-bytes of data to be placed in parameter list
  1791. * ansbuf - address of buffer to reply with
  1792. * anslen - length of buffer to reply with
  1793. * Output: msgid - specifies the message ID.
  1794. * Return: b2f0_result - return code from CP
  1795. * (-EINVAL) - buffer address is NULL
  1796. */
  1797. int
  1798. iucv_send2way_prmmsg (__u16 pathid,
  1799. __u32 * msgid,
  1800. __u32 trgcls,
  1801. __u32 srccls,
  1802. __u32 msgtag,
  1803. ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
  1804. {
  1805. iparml_dpl *parm;
  1806. ulong b2f0_result;
  1807. iucv_debug(2, "entering");
  1808. if (!ansbuf)
  1809. return -EINVAL;
  1810. parm = (iparml_dpl *)grab_param();
  1811. parm->ippathid = pathid;
  1812. parm->iptrgcls = trgcls;
  1813. parm->ipsrccls = srccls;
  1814. parm->ipmsgtag = msgtag;
  1815. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1816. parm->ipbfln2f = (__u32) anslen;
  1817. parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
  1818. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1819. b2f0_result = b2f0(SEND, parm);
  1820. if ((!b2f0_result) && (msgid))
  1821. *msgid = parm->ipmsgid;
  1822. release_param(parm);
  1823. iucv_debug(2, "exiting");
  1824. return b2f0_result;
  1825. }
  1826. /*
  1827. * Name: iucv_send2way_prmmsg_array
  1828. * Purpose: This function transmits data to another application.
  1829. * Prmmsg specifies that the 8-bytes of data are to be moved
  1830. * into the parameter list. This is a two-way message and the
  1831. * receiver of the message is expected to reply. A buffer
  1832. * is provided into which IUCV moves the reply to this
  1833. * message. The contents of ansbuf is the address of the
  1834. * array of addresses and lengths of discontiguous buffers
  1835. * that contain the reply.
  1836. * Input: pathid - path identification number
  1837. * trgcls - specifies target class
  1838. * srccls - specifies the source message class
  1839. * msgtag - specifies a tag to be associated with the message
  1840. * flags1 - option for path
  1841. * IPPRTY- specifies if you want to send priority message
  1842. * prmmsg - 8-bytes of data to be placed into the parameter list
  1843. * ansbuf - address of buffer to reply with
  1844. * anslen - length of buffer to reply with
  1845. * Output: msgid - specifies the message ID.
  1846. * Return: b2f0_result - return code from CP
  1847. * (-EINVAL) - ansbuf address is NULL
  1848. */
  1849. int
  1850. iucv_send2way_prmmsg_array (__u16 pathid,
  1851. __u32 * msgid,
  1852. __u32 trgcls,
  1853. __u32 srccls,
  1854. __u32 msgtag,
  1855. int flags1,
  1856. __u8 prmmsg[8],
  1857. iucv_array_t * ansbuf, ulong anslen)
  1858. {
  1859. iparml_dpl *parm;
  1860. ulong b2f0_result;
  1861. iucv_debug(2, "entering");
  1862. if (!ansbuf)
  1863. return -EINVAL;
  1864. parm = (iparml_dpl *)grab_param();
  1865. parm->ippathid = pathid;
  1866. parm->iptrgcls = trgcls;
  1867. parm->ipsrccls = srccls;
  1868. parm->ipmsgtag = msgtag;
  1869. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1870. parm->ipbfln2f = (__u32) anslen;
  1871. parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
  1872. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1873. b2f0_result = b2f0(SEND, parm);
  1874. if ((!b2f0_result) && (msgid))
  1875. *msgid = parm->ipmsgid;
  1876. release_param(parm);
  1877. iucv_debug(2, "exiting");
  1878. return b2f0_result;
  1879. }
  1880. void
  1881. iucv_setmask_cpuid (void *result)
  1882. {
  1883. iparml_set_mask *parm;
  1884. iucv_debug(1, "entering");
  1885. parm = (iparml_set_mask *)grab_param();
  1886. parm->ipmask = *((__u8*)result);
  1887. *((ulong *)result) = b2f0(SETMASK, parm);
  1888. release_param(parm);
  1889. iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
  1890. iucv_debug(1, "exiting");
  1891. }
  1892. /*
  1893. * Name: iucv_setmask
  1894. * Purpose: This function enables or disables the following IUCV
  1895. * external interruptions: Nonpriority and priority message
  1896. * interrupts, nonpriority and priority reply interrupts.
  1897. * Input: SetMaskFlag - options for interrupts
  1898. * 0x80 - Nonpriority_MessagePendingInterruptsFlag
  1899. * 0x40 - Priority_MessagePendingInterruptsFlag
  1900. * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
  1901. * 0x10 - Priority_MessageCompletionInterruptsFlag
  1902. * 0x08 - IUCVControlInterruptsFlag
  1903. * Output: NA
  1904. * Return: b2f0_result - return code from CP
  1905. */
  1906. int
  1907. iucv_setmask (int SetMaskFlag)
  1908. {
  1909. union {
  1910. ulong result;
  1911. __u8 param;
  1912. } u;
  1913. int cpu;
  1914. u.param = SetMaskFlag;
  1915. cpu = get_cpu();
  1916. smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
  1917. put_cpu();
  1918. return u.result;
  1919. }
  1920. /**
  1921. * iucv_sever:
  1922. * @pathid: Path identification number
  1923. * @user_data: 16-byte of user data
  1924. *
  1925. * This function terminates an iucv path.
  1926. * Returns: return code from CP
  1927. */
  1928. int
  1929. iucv_sever(__u16 pathid, __u8 user_data[16])
  1930. {
  1931. iparml_control *parm;
  1932. ulong b2f0_result = 0;
  1933. iucv_debug(1, "entering");
  1934. parm = (iparml_control *)grab_param();
  1935. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  1936. parm->ippathid = pathid;
  1937. b2f0_result = b2f0(SEVER, parm);
  1938. if (!b2f0_result)
  1939. iucv_remove_pathid(pathid);
  1940. release_param(parm);
  1941. iucv_debug(1, "exiting");
  1942. return b2f0_result;
  1943. }
  1944. /*
  1945. * Interrupt Handlers
  1946. *******************************************************************************/
  1947. /**
  1948. * iucv_irq_handler:
  1949. * @regs: Current registers
  1950. * @code: irq code
  1951. *
  1952. * Handles external interrupts coming in from CP.
  1953. * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
  1954. */
  1955. static void
  1956. iucv_irq_handler(struct pt_regs *regs, __u16 code)
  1957. {
  1958. iucv_irqdata *irqdata;
  1959. irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
  1960. if (!irqdata) {
  1961. printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
  1962. return;
  1963. }
  1964. memcpy(&irqdata->data, iucv_external_int_buffer,
  1965. sizeof(iucv_GeneralInterrupt));
  1966. spin_lock(&iucv_irq_queue_lock);
  1967. list_add_tail(&irqdata->queue, &iucv_irq_queue);
  1968. spin_unlock(&iucv_irq_queue_lock);
  1969. tasklet_schedule(&iucv_tasklet);
  1970. }
  1971. /**
  1972. * iucv_do_int:
  1973. * @int_buf: Pointer to copy of external interrupt buffer
  1974. *
  1975. * The workhorse for handling interrupts queued by iucv_irq_handler().
  1976. * This function is called from the bottom half iucv_tasklet_handler().
  1977. */
  1978. static void
  1979. iucv_do_int(iucv_GeneralInterrupt * int_buf)
  1980. {
  1981. handler *h = NULL;
  1982. struct list_head *lh;
  1983. ulong flags;
  1984. iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
  1985. __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
  1986. int rc = 0, j = 0;
  1987. __u8 no_listener[16] = "NO LISTENER";
  1988. iucv_debug(2, "entering, pathid %d, type %02X",
  1989. int_buf->ippathid, int_buf->iptype);
  1990. iucv_dumpit("External Interrupt Buffer:",
  1991. int_buf, sizeof(iucv_GeneralInterrupt));
  1992. ASCEBC (no_listener, 16);
  1993. if (int_buf->iptype != 01) {
  1994. if ((int_buf->ippathid) > (max_connections - 1)) {
  1995. printk(KERN_WARNING "%s: Got interrupt with pathid %d"
  1996. " > max_connections (%ld)\n", __FUNCTION__,
  1997. int_buf->ippathid, max_connections - 1);
  1998. } else {
  1999. h = iucv_pathid_table[int_buf->ippathid];
  2000. interrupt = h->interrupt_table;
  2001. iucv_dumpit("Handler:", h, sizeof(handler));
  2002. }
  2003. }
  2004. /* end of if statement */
  2005. switch (int_buf->iptype) {
  2006. case 0x01: /* connection pending */
  2007. if (messagesDisabled) {
  2008. iucv_setmask(~0);
  2009. messagesDisabled = 0;
  2010. }
  2011. spin_lock_irqsave(&iucv_lock, flags);
  2012. list_for_each(lh, &iucv_handler_table) {
  2013. h = list_entry(lh, handler, list);
  2014. memcpy(temp_buff1, &(int_buf->ipvmid), 24);
  2015. memcpy(temp_buff2, &(h->id.userid), 24);
  2016. for (j = 0; j < 24; j++) {
  2017. temp_buff1[j] &= (h->id.mask)[j];
  2018. temp_buff2[j] &= (h->id.mask)[j];
  2019. }
  2020. iucv_dumpit("temp_buff1:",
  2021. temp_buff1, sizeof(temp_buff1));
  2022. iucv_dumpit("temp_buff2",
  2023. temp_buff2, sizeof(temp_buff2));
  2024. if (!memcmp (temp_buff1, temp_buff2, 24)) {
  2025. iucv_debug(2,
  2026. "found a matching handler");
  2027. break;
  2028. } else
  2029. h = NULL;
  2030. }
  2031. spin_unlock_irqrestore (&iucv_lock, flags);
  2032. if (h) {
  2033. /* ADD PATH TO PATHID TABLE */
  2034. rc = iucv_add_pathid(int_buf->ippathid, h);
  2035. if (rc) {
  2036. iucv_sever (int_buf->ippathid,
  2037. no_listener);
  2038. iucv_debug(1,
  2039. "add_pathid failed, rc = %d",
  2040. rc);
  2041. } else {
  2042. interrupt = h->interrupt_table;
  2043. if (interrupt->ConnectionPending) {
  2044. EBCASC (int_buf->ipvmid, 8);
  2045. interrupt->ConnectionPending(
  2046. (iucv_ConnectionPending *)int_buf,
  2047. h->pgm_data);
  2048. } else
  2049. iucv_sever(int_buf->ippathid,
  2050. no_listener);
  2051. }
  2052. } else
  2053. iucv_sever(int_buf->ippathid, no_listener);
  2054. break;
  2055. case 0x02: /*connection complete */
  2056. if (messagesDisabled) {
  2057. iucv_setmask(~0);
  2058. messagesDisabled = 0;
  2059. }
  2060. if (h) {
  2061. if (interrupt->ConnectionComplete)
  2062. {
  2063. interrupt->ConnectionComplete(
  2064. (iucv_ConnectionComplete *)int_buf,
  2065. h->pgm_data);
  2066. }
  2067. else
  2068. iucv_debug(1,
  2069. "ConnectionComplete not called");
  2070. } else
  2071. iucv_sever(int_buf->ippathid, no_listener);
  2072. break;
  2073. case 0x03: /* connection severed */
  2074. if (messagesDisabled) {
  2075. iucv_setmask(~0);
  2076. messagesDisabled = 0;
  2077. }
  2078. if (h) {
  2079. if (interrupt->ConnectionSevered)
  2080. interrupt->ConnectionSevered(
  2081. (iucv_ConnectionSevered *)int_buf,
  2082. h->pgm_data);
  2083. else
  2084. iucv_sever (int_buf->ippathid, no_listener);
  2085. } else
  2086. iucv_sever(int_buf->ippathid, no_listener);
  2087. break;
  2088. case 0x04: /* connection quiesced */
  2089. if (messagesDisabled) {
  2090. iucv_setmask(~0);
  2091. messagesDisabled = 0;
  2092. }
  2093. if (h) {
  2094. if (interrupt->ConnectionQuiesced)
  2095. interrupt->ConnectionQuiesced(
  2096. (iucv_ConnectionQuiesced *)int_buf,
  2097. h->pgm_data);
  2098. else
  2099. iucv_debug(1,
  2100. "ConnectionQuiesced not called");
  2101. }
  2102. break;
  2103. case 0x05: /* connection resumed */
  2104. if (messagesDisabled) {
  2105. iucv_setmask(~0);
  2106. messagesDisabled = 0;
  2107. }
  2108. if (h) {
  2109. if (interrupt->ConnectionResumed)
  2110. interrupt->ConnectionResumed(
  2111. (iucv_ConnectionResumed *)int_buf,
  2112. h->pgm_data);
  2113. else
  2114. iucv_debug(1,
  2115. "ConnectionResumed not called");
  2116. }
  2117. break;
  2118. case 0x06: /* priority message complete */
  2119. case 0x07: /* nonpriority message complete */
  2120. if (h) {
  2121. if (interrupt->MessageComplete)
  2122. interrupt->MessageComplete(
  2123. (iucv_MessageComplete *)int_buf,
  2124. h->pgm_data);
  2125. else
  2126. iucv_debug(2,
  2127. "MessageComplete not called");
  2128. }
  2129. break;
  2130. case 0x08: /* priority message pending */
  2131. case 0x09: /* nonpriority message pending */
  2132. if (h) {
  2133. if (interrupt->MessagePending)
  2134. interrupt->MessagePending(
  2135. (iucv_MessagePending *) int_buf,
  2136. h->pgm_data);
  2137. else
  2138. iucv_debug(2,
  2139. "MessagePending not called");
  2140. }
  2141. break;
  2142. default: /* unknown iucv type */
  2143. printk(KERN_WARNING "%s: unknown iucv interrupt\n",
  2144. __FUNCTION__);
  2145. break;
  2146. } /* end switch */
  2147. iucv_debug(2, "exiting pathid %d, type %02X",
  2148. int_buf->ippathid, int_buf->iptype);
  2149. return;
  2150. }
  2151. /**
  2152. * iucv_tasklet_handler:
  2153. *
  2154. * This function loops over the queue of irq buffers and runs iucv_do_int()
  2155. * on every queue element.
  2156. */
  2157. static void
  2158. iucv_tasklet_handler(unsigned long ignored)
  2159. {
  2160. struct list_head head;
  2161. struct list_head *next;
  2162. ulong flags;
  2163. spin_lock_irqsave(&iucv_irq_queue_lock, flags);
  2164. list_add(&head, &iucv_irq_queue);
  2165. list_del_init(&iucv_irq_queue);
  2166. spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
  2167. next = head.next;
  2168. while (next != &head) {
  2169. iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
  2170. next = next->next;
  2171. iucv_do_int(&p->data);
  2172. kfree(p);
  2173. }
  2174. return;
  2175. }
  2176. subsys_initcall(iucv_init);
  2177. module_exit(iucv_exit);
  2178. /**
  2179. * Export all public stuff
  2180. */
  2181. EXPORT_SYMBOL (iucv_bus);
  2182. EXPORT_SYMBOL (iucv_root);
  2183. EXPORT_SYMBOL (iucv_accept);
  2184. EXPORT_SYMBOL (iucv_connect);
  2185. #if 0
  2186. EXPORT_SYMBOL (iucv_purge);
  2187. EXPORT_SYMBOL (iucv_query_maxconn);
  2188. EXPORT_SYMBOL (iucv_query_bufsize);
  2189. EXPORT_SYMBOL (iucv_quiesce);
  2190. #endif
  2191. EXPORT_SYMBOL (iucv_receive);
  2192. #if 0
  2193. EXPORT_SYMBOL (iucv_receive_array);
  2194. #endif
  2195. EXPORT_SYMBOL (iucv_reject);
  2196. #if 0
  2197. EXPORT_SYMBOL (iucv_reply);
  2198. EXPORT_SYMBOL (iucv_reply_array);
  2199. EXPORT_SYMBOL (iucv_resume);
  2200. #endif
  2201. EXPORT_SYMBOL (iucv_reply_prmmsg);
  2202. EXPORT_SYMBOL (iucv_send);
  2203. EXPORT_SYMBOL (iucv_send2way);
  2204. EXPORT_SYMBOL (iucv_send2way_array);
  2205. EXPORT_SYMBOL (iucv_send2way_prmmsg);
  2206. EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
  2207. #if 0
  2208. EXPORT_SYMBOL (iucv_send_array);
  2209. EXPORT_SYMBOL (iucv_send_prmmsg);
  2210. EXPORT_SYMBOL (iucv_setmask);
  2211. #endif
  2212. EXPORT_SYMBOL (iucv_sever);
  2213. EXPORT_SYMBOL (iucv_register_program);
  2214. EXPORT_SYMBOL (iucv_unregister_program);