iucv.c 67 KB

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