iucv.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540
  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(__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 b2f0(__u32 code, void *parm)
  470. {
  471. register unsigned long reg0 asm ("0");
  472. register unsigned long reg1 asm ("1");
  473. iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
  474. reg0 = code;
  475. reg1 = virt_to_phys(parm);
  476. asm volatile(".long 0xb2f01000" : : "d" (reg0), "a" (reg1));
  477. iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
  478. return (unsigned long)*((__u8 *)(parm + 3));
  479. }
  480. /*
  481. * Name: iucv_add_pathid
  482. * Purpose: Adds a path id to the system.
  483. * Input: pathid - pathid that is going to be entered into system
  484. * handle - address of handler that the pathid will be associated
  485. * with.
  486. * pgm_data - token passed in by application.
  487. * Output: 0: successful addition of pathid
  488. * - EINVAL - pathid entry is being used by another application
  489. * - ENOMEM - storage allocation for a new pathid table failed
  490. */
  491. static int
  492. __iucv_add_pathid(__u16 pathid, handler *handler)
  493. {
  494. iucv_debug(1, "entering");
  495. iucv_debug(1, "handler is pointing to %p", handler);
  496. if (pathid > (max_connections - 1))
  497. return -EINVAL;
  498. if (iucv_pathid_table[pathid]) {
  499. iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]);
  500. printk(KERN_WARNING
  501. "%s: Pathid being used, error.\n", __FUNCTION__);
  502. return -EINVAL;
  503. }
  504. iucv_pathid_table[pathid] = handler;
  505. iucv_debug(1, "exiting");
  506. return 0;
  507. } /* end of add_pathid function */
  508. static int
  509. iucv_add_pathid(__u16 pathid, handler *handler)
  510. {
  511. ulong flags;
  512. int rc;
  513. spin_lock_irqsave (&iucv_lock, flags);
  514. rc = __iucv_add_pathid(pathid, handler);
  515. spin_unlock_irqrestore (&iucv_lock, flags);
  516. return rc;
  517. }
  518. static void
  519. iucv_remove_pathid(__u16 pathid)
  520. {
  521. ulong flags;
  522. if (pathid > (max_connections - 1))
  523. return;
  524. spin_lock_irqsave (&iucv_lock, flags);
  525. iucv_pathid_table[pathid] = NULL;
  526. spin_unlock_irqrestore (&iucv_lock, flags);
  527. }
  528. /**
  529. * iucv_declare_buffer_cpuid
  530. * Register at VM for subsequent IUCV operations. This is executed
  531. * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer().
  532. */
  533. static void
  534. iucv_declare_buffer_cpuid (void *result)
  535. {
  536. iparml_db *parm;
  537. parm = (iparml_db *)grab_param();
  538. parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer);
  539. if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1)
  540. *((ulong *)result) = parm->iprcode;
  541. release_param(parm);
  542. }
  543. /**
  544. * iucv_retrieve_buffer_cpuid:
  545. * Unregister IUCV usage at VM. This is always executed on the same
  546. * cpu that registered the buffer to VM.
  547. * Called from iucv_retrieve_buffer().
  548. */
  549. static void
  550. iucv_retrieve_buffer_cpuid (void *cpu)
  551. {
  552. iparml_control *parm;
  553. parm = (iparml_control *)grab_param();
  554. b2f0(RETRIEVE_BUFFER, parm);
  555. release_param(parm);
  556. }
  557. /**
  558. * Name: iucv_declare_buffer
  559. * Purpose: Specifies the guests real address of an external
  560. * interrupt.
  561. * Input: void
  562. * Output: iprcode - return code from b2f0 call
  563. */
  564. static int
  565. iucv_declare_buffer (void)
  566. {
  567. unsigned long flags;
  568. ulong b2f0_result;
  569. iucv_debug(1, "entering");
  570. b2f0_result = -ENODEV;
  571. spin_lock_irqsave (&iucv_lock, flags);
  572. if (iucv_cpuid == -1) {
  573. /* Reserve any cpu for use by iucv. */
  574. iucv_cpuid = smp_get_cpu(CPU_MASK_ALL);
  575. spin_unlock_irqrestore (&iucv_lock, flags);
  576. smp_call_function_on(iucv_declare_buffer_cpuid,
  577. &b2f0_result, 0, 1, iucv_cpuid);
  578. if (b2f0_result) {
  579. smp_put_cpu(iucv_cpuid);
  580. iucv_cpuid = -1;
  581. }
  582. iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer);
  583. } else {
  584. spin_unlock_irqrestore (&iucv_lock, flags);
  585. b2f0_result = 0;
  586. }
  587. iucv_debug(1, "exiting");
  588. return b2f0_result;
  589. }
  590. /**
  591. * iucv_retrieve_buffer:
  592. *
  593. * Terminates all use of IUCV.
  594. * Returns: return code from CP
  595. */
  596. static int
  597. iucv_retrieve_buffer (void)
  598. {
  599. iucv_debug(1, "entering");
  600. if (iucv_cpuid != -1) {
  601. smp_call_function_on(iucv_retrieve_buffer_cpuid,
  602. NULL, 0, 1, iucv_cpuid);
  603. /* Release the cpu reserved by iucv_declare_buffer. */
  604. smp_put_cpu(iucv_cpuid);
  605. iucv_cpuid = -1;
  606. }
  607. iucv_debug(1, "exiting");
  608. return 0;
  609. }
  610. /**
  611. * iucv_remove_handler:
  612. * @users_handler: handler to be removed
  613. *
  614. * Remove handler when application unregisters.
  615. */
  616. static void
  617. iucv_remove_handler(handler *handler)
  618. {
  619. unsigned long flags;
  620. if ((!iucv_pathid_table) || (!handler))
  621. return;
  622. iucv_debug(1, "entering");
  623. spin_lock_irqsave (&iucv_lock, flags);
  624. list_del(&handler->list);
  625. if (list_empty(&iucv_handler_table)) {
  626. if (register_flag) {
  627. unregister_external_interrupt(0x4000, iucv_irq_handler);
  628. register_flag = 0;
  629. }
  630. }
  631. spin_unlock_irqrestore (&iucv_lock, flags);
  632. iucv_debug(1, "exiting");
  633. return;
  634. }
  635. /**
  636. * iucv_register_program:
  637. * @pgmname: user identification
  638. * @userid: machine identification
  639. * @pgmmask: Indicates which bits in the pgmname and userid combined will be
  640. * used to determine who is given control.
  641. * @ops: Address of interrupt handler table.
  642. * @pgm_data: Application data to be passed to interrupt handlers.
  643. *
  644. * Registers an application with IUCV.
  645. * Returns:
  646. * The address of handler, or NULL on failure.
  647. * NOTE on pgmmask:
  648. * If pgmname, userid and pgmmask are provided, pgmmask is entered into the
  649. * handler as is.
  650. * If pgmmask is NULL, the internal mask is set to all 0xff's
  651. * When userid is NULL, the first 8 bytes of the internal mask are forced
  652. * to 0x00.
  653. * If pgmmask and userid are NULL, the first 8 bytes of the internal mask
  654. * are forced to 0x00 and the last 16 bytes to 0xff.
  655. */
  656. iucv_handle_t
  657. iucv_register_program (__u8 pgmname[16],
  658. __u8 userid[8],
  659. __u8 pgmmask[24],
  660. iucv_interrupt_ops_t * ops, void *pgm_data)
  661. {
  662. ulong rc = 0; /* return code from function calls */
  663. handler *new_handler;
  664. iucv_debug(1, "entering");
  665. if (ops == NULL) {
  666. /* interrupt table is not defined */
  667. printk(KERN_WARNING "%s: Interrupt table is not defined, "
  668. "exiting\n", __FUNCTION__);
  669. return NULL;
  670. }
  671. if (!pgmname) {
  672. printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__);
  673. return NULL;
  674. }
  675. /* Allocate handler entry */
  676. new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC);
  677. if (new_handler == NULL) {
  678. printk(KERN_WARNING "%s: storage allocation for new handler "
  679. "failed.\n", __FUNCTION__);
  680. return NULL;
  681. }
  682. if (!iucv_pathid_table) {
  683. if (iucv_init()) {
  684. kfree(new_handler);
  685. return NULL;
  686. }
  687. max_connections = iucv_query_maxconn();
  688. iucv_pathid_table = kcalloc(max_connections, sizeof(handler *),
  689. GFP_ATOMIC);
  690. if (iucv_pathid_table == NULL) {
  691. printk(KERN_WARNING "%s: iucv_pathid_table storage "
  692. "allocation failed\n", __FUNCTION__);
  693. kfree(new_handler);
  694. return NULL;
  695. }
  696. }
  697. memset(new_handler, 0, sizeof (handler));
  698. memcpy(new_handler->id.user_data, pgmname,
  699. sizeof (new_handler->id.user_data));
  700. if (userid) {
  701. memcpy (new_handler->id.userid, userid,
  702. sizeof (new_handler->id.userid));
  703. ASCEBC (new_handler->id.userid,
  704. sizeof (new_handler->id.userid));
  705. EBC_TOUPPER (new_handler->id.userid,
  706. sizeof (new_handler->id.userid));
  707. if (pgmmask) {
  708. memcpy (new_handler->id.mask, pgmmask,
  709. sizeof (new_handler->id.mask));
  710. } else {
  711. memset (new_handler->id.mask, 0xFF,
  712. sizeof (new_handler->id.mask));
  713. }
  714. } else {
  715. if (pgmmask) {
  716. memcpy (new_handler->id.mask, pgmmask,
  717. sizeof (new_handler->id.mask));
  718. } else {
  719. memset (new_handler->id.mask, 0xFF,
  720. sizeof (new_handler->id.mask));
  721. }
  722. memset (new_handler->id.userid, 0x00,
  723. sizeof (new_handler->id.userid));
  724. }
  725. /* fill in the rest of handler */
  726. new_handler->pgm_data = pgm_data;
  727. new_handler->interrupt_table = ops;
  728. /*
  729. * Check if someone else is registered with same pgmname, userid
  730. * and mask. If someone is already registered with same pgmname,
  731. * userid and mask, registration will fail and NULL will be returned
  732. * to the application.
  733. * If identical handler not found, then handler is added to list.
  734. */
  735. rc = iucv_add_handler(new_handler);
  736. if (rc) {
  737. printk(KERN_WARNING "%s: Someone already registered with same "
  738. "pgmname, userid, pgmmask\n", __FUNCTION__);
  739. kfree (new_handler);
  740. return NULL;
  741. }
  742. rc = iucv_declare_buffer();
  743. if (rc) {
  744. char *err = "Unknown";
  745. iucv_remove_handler(new_handler);
  746. kfree(new_handler);
  747. switch(rc) {
  748. case 0x03:
  749. err = "Directory error";
  750. break;
  751. case 0x0a:
  752. err = "Invalid length";
  753. break;
  754. case 0x13:
  755. err = "Buffer already exists";
  756. break;
  757. case 0x3e:
  758. err = "Buffer overlap";
  759. break;
  760. case 0x5c:
  761. err = "Paging or storage error";
  762. break;
  763. }
  764. printk(KERN_WARNING "%s: iucv_declare_buffer "
  765. "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err);
  766. return NULL;
  767. }
  768. if (!register_flag) {
  769. /* request the 0x4000 external interrupt */
  770. rc = register_external_interrupt (0x4000, iucv_irq_handler);
  771. if (rc) {
  772. iucv_remove_handler(new_handler);
  773. kfree (new_handler);
  774. printk(KERN_WARNING "%s: "
  775. "register_external_interrupt returned %ld\n",
  776. __FUNCTION__, rc);
  777. return NULL;
  778. }
  779. register_flag = 1;
  780. }
  781. iucv_debug(1, "exiting");
  782. return new_handler;
  783. } /* end of register function */
  784. /**
  785. * iucv_unregister_program:
  786. * @handle: address of handler
  787. *
  788. * Unregister application with IUCV.
  789. * Returns:
  790. * 0 on success, -EINVAL, if specified handle is invalid.
  791. */
  792. int
  793. iucv_unregister_program (iucv_handle_t handle)
  794. {
  795. handler *h = NULL;
  796. struct list_head *lh;
  797. int i;
  798. ulong flags;
  799. iucv_debug(1, "entering");
  800. iucv_debug(1, "address of handler is %p", h);
  801. /* Checking if handle is valid */
  802. spin_lock_irqsave (&iucv_lock, flags);
  803. list_for_each(lh, &iucv_handler_table) {
  804. if ((handler *)handle == list_entry(lh, handler, list)) {
  805. h = (handler *)handle;
  806. break;
  807. }
  808. }
  809. if (!h) {
  810. spin_unlock_irqrestore (&iucv_lock, flags);
  811. if (handle)
  812. printk(KERN_WARNING
  813. "%s: Handler not found in iucv_handler_table.\n",
  814. __FUNCTION__);
  815. else
  816. printk(KERN_WARNING
  817. "%s: NULL handle passed by application.\n",
  818. __FUNCTION__);
  819. return -EINVAL;
  820. }
  821. /**
  822. * First, walk thru iucv_pathid_table and sever any pathid which is
  823. * still pointing to the handler to be removed.
  824. */
  825. for (i = 0; i < max_connections; i++)
  826. if (iucv_pathid_table[i] == h) {
  827. spin_unlock_irqrestore (&iucv_lock, flags);
  828. iucv_sever(i, h->id.user_data);
  829. spin_lock_irqsave(&iucv_lock, flags);
  830. }
  831. spin_unlock_irqrestore (&iucv_lock, flags);
  832. iucv_remove_handler(h);
  833. kfree(h);
  834. iucv_debug(1, "exiting");
  835. return 0;
  836. }
  837. /**
  838. * iucv_accept:
  839. * @pathid: Path identification number
  840. * @msglim_reqstd: The number of outstanding messages requested.
  841. * @user_data: Data specified by the iucv_connect function.
  842. * @flags1: Contains options for this path.
  843. * - IPPRTY (0x20) Specifies if you want to send priority message.
  844. * - IPRMDATA (0x80) Specifies whether your program can handle a message
  845. * in the parameter list.
  846. * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
  847. * established.
  848. * @handle: Address of handler.
  849. * @pgm_data: Application data passed to interrupt handlers.
  850. * @flags1_out: Pointer to an int. If not NULL, on return the options for
  851. * the path are stored at the given location:
  852. * - IPPRTY (0x20) Indicates you may send a priority message.
  853. * @msglim: Pointer to an __u16. If not NULL, on return the maximum
  854. * number of outstanding messages is stored at the given
  855. * location.
  856. *
  857. * This function is issued after the user receives a Connection Pending external
  858. * interrupt and now wishes to complete the IUCV communication path.
  859. * Returns:
  860. * return code from CP
  861. */
  862. int
  863. iucv_accept(__u16 pathid, __u16 msglim_reqstd,
  864. __u8 user_data[16], int flags1,
  865. iucv_handle_t handle, void *pgm_data,
  866. int *flags1_out, __u16 * msglim)
  867. {
  868. ulong b2f0_result = 0;
  869. ulong flags;
  870. struct list_head *lh;
  871. handler *h = NULL;
  872. iparml_control *parm;
  873. iucv_debug(1, "entering");
  874. iucv_debug(1, "pathid = %d", pathid);
  875. /* Checking if handle is valid */
  876. spin_lock_irqsave (&iucv_lock, flags);
  877. list_for_each(lh, &iucv_handler_table) {
  878. if ((handler *)handle == list_entry(lh, handler, list)) {
  879. h = (handler *)handle;
  880. break;
  881. }
  882. }
  883. spin_unlock_irqrestore (&iucv_lock, flags);
  884. if (!h) {
  885. if (handle)
  886. printk(KERN_WARNING
  887. "%s: Handler not found in iucv_handler_table.\n",
  888. __FUNCTION__);
  889. else
  890. printk(KERN_WARNING
  891. "%s: NULL handle passed by application.\n",
  892. __FUNCTION__);
  893. return -EINVAL;
  894. }
  895. parm = (iparml_control *)grab_param();
  896. parm->ippathid = pathid;
  897. parm->ipmsglim = msglim_reqstd;
  898. if (user_data)
  899. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  900. parm->ipflags1 = (__u8)flags1;
  901. b2f0_result = b2f0(ACCEPT, parm);
  902. if (!b2f0_result) {
  903. if (msglim)
  904. *msglim = parm->ipmsglim;
  905. if (pgm_data)
  906. h->pgm_data = pgm_data;
  907. if (flags1_out)
  908. *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
  909. }
  910. release_param(parm);
  911. iucv_debug(1, "exiting");
  912. return b2f0_result;
  913. }
  914. /**
  915. * iucv_connect:
  916. * @pathid: Path identification number
  917. * @msglim_reqstd: Number of outstanding messages requested
  918. * @user_data: 16-byte user data
  919. * @userid: 8-byte of user identification
  920. * @system_name: 8-byte identifying the system name
  921. * @flags1: Specifies options for this path:
  922. * - IPPRTY (0x20) Specifies if you want to send priority message.
  923. * - IPRMDATA (0x80) Specifies whether your program can handle a message
  924. * in the parameter list.
  925. * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being
  926. * established.
  927. * - IPLOCAL (0x01) Allows an application to force the partner to be on the
  928. * local system. If local is specified then target class
  929. * cannot be specified.
  930. * @flags1_out: Pointer to an int. If not NULL, on return the options for
  931. * the path are stored at the given location:
  932. * - IPPRTY (0x20) Indicates you may send a priority message.
  933. * @msglim: Pointer to an __u16. If not NULL, on return the maximum
  934. * number of outstanding messages is stored at the given
  935. * location.
  936. * @handle: Address of handler.
  937. * @pgm_data: Application data to be passed to interrupt handlers.
  938. *
  939. * This function establishes an IUCV path. Although the connect may complete
  940. * successfully, you are not able to use the path until you receive an IUCV
  941. * Connection Complete external interrupt.
  942. * Returns: return code from CP, or one of the following
  943. * - ENOMEM
  944. * - return code from iucv_declare_buffer
  945. * - EINVAL - invalid handle passed by application
  946. * - EINVAL - pathid address is NULL
  947. * - ENOMEM - pathid table storage allocation failed
  948. * - return code from internal function add_pathid
  949. */
  950. int
  951. iucv_connect (__u16 *pathid, __u16 msglim_reqstd,
  952. __u8 user_data[16], __u8 userid[8],
  953. __u8 system_name[8], int flags1,
  954. int *flags1_out, __u16 * msglim,
  955. iucv_handle_t handle, void *pgm_data)
  956. {
  957. iparml_control *parm;
  958. iparml_control local_parm;
  959. struct list_head *lh;
  960. ulong b2f0_result = 0;
  961. ulong flags;
  962. int add_pathid_result = 0;
  963. handler *h = NULL;
  964. __u8 no_memory[16] = "NO MEMORY";
  965. iucv_debug(1, "entering");
  966. /* Checking if handle is valid */
  967. spin_lock_irqsave (&iucv_lock, flags);
  968. list_for_each(lh, &iucv_handler_table) {
  969. if ((handler *)handle == list_entry(lh, handler, list)) {
  970. h = (handler *)handle;
  971. break;
  972. }
  973. }
  974. spin_unlock_irqrestore (&iucv_lock, flags);
  975. if (!h) {
  976. if (handle)
  977. printk(KERN_WARNING
  978. "%s: Handler not found in iucv_handler_table.\n",
  979. __FUNCTION__);
  980. else
  981. printk(KERN_WARNING
  982. "%s: NULL handle passed by application.\n",
  983. __FUNCTION__);
  984. return -EINVAL;
  985. }
  986. if (pathid == NULL) {
  987. printk(KERN_WARNING "%s: NULL pathid pointer\n",
  988. __FUNCTION__);
  989. return -EINVAL;
  990. }
  991. parm = (iparml_control *)grab_param();
  992. parm->ipmsglim = msglim_reqstd;
  993. if (user_data)
  994. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  995. if (userid) {
  996. memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid));
  997. ASCEBC(parm->ipvmid, sizeof(parm->ipvmid));
  998. EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid));
  999. }
  1000. if (system_name) {
  1001. memcpy(parm->iptarget, system_name, sizeof(parm->iptarget));
  1002. ASCEBC(parm->iptarget, sizeof(parm->iptarget));
  1003. EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget));
  1004. }
  1005. /* In order to establish an IUCV connection, the procedure is:
  1006. *
  1007. * b2f0(CONNECT)
  1008. * take the ippathid from the b2f0 call
  1009. * register the handler to the ippathid
  1010. *
  1011. * Unfortunately, the ConnectionEstablished message gets sent after the
  1012. * b2f0(CONNECT) call but before the register is handled.
  1013. *
  1014. * In order for this race condition to be eliminated, the IUCV Control
  1015. * Interrupts must be disabled for the above procedure.
  1016. *
  1017. * David Kennedy <dkennedy@linuxcare.com>
  1018. */
  1019. /* Enable everything but IUCV Control messages */
  1020. iucv_setmask(~(AllInterrupts));
  1021. messagesDisabled = 1;
  1022. spin_lock_irqsave (&iucv_lock, flags);
  1023. parm->ipflags1 = (__u8)flags1;
  1024. b2f0_result = b2f0(CONNECT, parm);
  1025. memcpy(&local_parm, parm, sizeof(local_parm));
  1026. release_param(parm);
  1027. parm = &local_parm;
  1028. if (!b2f0_result)
  1029. add_pathid_result = __iucv_add_pathid(parm->ippathid, h);
  1030. spin_unlock_irqrestore (&iucv_lock, flags);
  1031. if (b2f0_result) {
  1032. iucv_setmask(~0);
  1033. messagesDisabled = 0;
  1034. return b2f0_result;
  1035. }
  1036. *pathid = parm->ippathid;
  1037. /* Enable everything again */
  1038. iucv_setmask(IUCVControlInterruptsFlag);
  1039. if (msglim)
  1040. *msglim = parm->ipmsglim;
  1041. if (flags1_out)
  1042. *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0;
  1043. if (add_pathid_result) {
  1044. iucv_sever(*pathid, no_memory);
  1045. printk(KERN_WARNING "%s: add_pathid failed with rc ="
  1046. " %d\n", __FUNCTION__, add_pathid_result);
  1047. return(add_pathid_result);
  1048. }
  1049. iucv_debug(1, "exiting");
  1050. return b2f0_result;
  1051. }
  1052. /**
  1053. * iucv_purge:
  1054. * @pathid: Path identification number
  1055. * @msgid: Message ID of message to purge.
  1056. * @srccls: Message class of the message to purge.
  1057. * @audit: Pointer to an __u32. If not NULL, on return, information about
  1058. * asynchronous errors that may have affected the normal completion
  1059. * of this message ist stored at the given location.
  1060. *
  1061. * Cancels a message you have sent.
  1062. * Returns: return code from CP
  1063. */
  1064. int
  1065. iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
  1066. {
  1067. iparml_purge *parm;
  1068. ulong b2f0_result = 0;
  1069. iucv_debug(1, "entering");
  1070. iucv_debug(1, "pathid = %d", pathid);
  1071. parm = (iparml_purge *)grab_param();
  1072. parm->ipmsgid = msgid;
  1073. parm->ippathid = pathid;
  1074. parm->ipsrccls = srccls;
  1075. parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID);
  1076. b2f0_result = b2f0(PURGE, parm);
  1077. if (!b2f0_result && audit) {
  1078. memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit));
  1079. /* parm->ipaudit has only 3 bytes */
  1080. *audit >>= 8;
  1081. }
  1082. release_param(parm);
  1083. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1084. iucv_debug(1, "exiting");
  1085. return b2f0_result;
  1086. }
  1087. /**
  1088. * iucv_query_generic:
  1089. * @want_maxconn: Flag, describing which value is to be returned.
  1090. *
  1091. * Helper function for iucv_query_maxconn() and iucv_query_bufsize().
  1092. *
  1093. * Returns: The buffersize, if want_maxconn is 0; the maximum number of
  1094. * connections, if want_maxconn is 1 or an error-code < 0 on failure.
  1095. */
  1096. static int
  1097. iucv_query_generic(int want_maxconn)
  1098. {
  1099. register unsigned long reg0 asm ("0");
  1100. register unsigned long reg1 asm ("1");
  1101. iparml_purge *parm = (iparml_purge *)grab_param();
  1102. int bufsize, maxconn;
  1103. int ccode;
  1104. /**
  1105. * Call b2f0 and store R0 (max buffer size),
  1106. * R1 (max connections) and CC.
  1107. */
  1108. reg0 = QUERY;
  1109. reg1 = virt_to_phys(parm);
  1110. asm volatile(
  1111. " .long 0xb2f01000\n"
  1112. " ipm %0\n"
  1113. " srl %0,28\n"
  1114. : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
  1115. bufsize = reg0;
  1116. maxconn = reg1;
  1117. release_param(parm);
  1118. if (ccode)
  1119. return -EPERM;
  1120. if (want_maxconn)
  1121. return maxconn;
  1122. return bufsize;
  1123. }
  1124. /**
  1125. * iucv_query_maxconn:
  1126. *
  1127. * Determines the maximum number of connections thay may be established.
  1128. *
  1129. * Returns: Maximum number of connections that can be.
  1130. */
  1131. ulong
  1132. iucv_query_maxconn(void)
  1133. {
  1134. return iucv_query_generic(1);
  1135. }
  1136. /**
  1137. * iucv_query_bufsize:
  1138. *
  1139. * Determines the size of the external interrupt buffer.
  1140. *
  1141. * Returns: Size of external interrupt buffer.
  1142. */
  1143. ulong
  1144. iucv_query_bufsize (void)
  1145. {
  1146. return iucv_query_generic(0);
  1147. }
  1148. /**
  1149. * iucv_quiesce:
  1150. * @pathid: Path identification number
  1151. * @user_data: 16-byte user data
  1152. *
  1153. * Temporarily suspends incoming messages on an IUCV path.
  1154. * You can later reactivate the path by invoking the iucv_resume function.
  1155. * Returns: return code from CP
  1156. */
  1157. int
  1158. iucv_quiesce (__u16 pathid, __u8 user_data[16])
  1159. {
  1160. iparml_control *parm;
  1161. ulong b2f0_result = 0;
  1162. iucv_debug(1, "entering");
  1163. iucv_debug(1, "pathid = %d", pathid);
  1164. parm = (iparml_control *)grab_param();
  1165. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  1166. parm->ippathid = pathid;
  1167. b2f0_result = b2f0(QUIESCE, parm);
  1168. release_param(parm);
  1169. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1170. iucv_debug(1, "exiting");
  1171. return b2f0_result;
  1172. }
  1173. /**
  1174. * iucv_receive:
  1175. * @pathid: Path identification number.
  1176. * @buffer: Address of buffer to receive. Must be below 2G.
  1177. * @buflen: Length of buffer to receive.
  1178. * @msgid: Specifies the message ID.
  1179. * @trgcls: Specifies target class.
  1180. * @flags1_out: Receives options for path on return.
  1181. * - IPNORPY (0x10) Specifies whether a reply is required
  1182. * - IPPRTY (0x20) Specifies if you want to send priority message
  1183. * - IPRMDATA (0x80) Specifies the data is contained in the parameter list
  1184. * @residual_buffer: Receives the address of buffer updated by the number
  1185. * of bytes you have received on return.
  1186. * @residual_length: On return, receives one of the following values:
  1187. * - 0 If the receive buffer is the same length as
  1188. * the message.
  1189. * - Remaining bytes in buffer If the receive buffer is longer than the
  1190. * message.
  1191. * - Remaining bytes in message If the receive buffer is shorter than the
  1192. * message.
  1193. *
  1194. * This function receives messages that are being sent to you over established
  1195. * paths.
  1196. * Returns: return code from CP IUCV call; If the receive buffer is shorter
  1197. * than the message, always 5
  1198. * -EINVAL - buffer address is pointing to NULL
  1199. */
  1200. int
  1201. iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls,
  1202. void *buffer, ulong buflen,
  1203. int *flags1_out, ulong * residual_buffer, ulong * residual_length)
  1204. {
  1205. iparml_db *parm;
  1206. ulong b2f0_result;
  1207. int moved = 0; /* number of bytes moved from parmlist to buffer */
  1208. iucv_debug(2, "entering");
  1209. if (!buffer)
  1210. return -EINVAL;
  1211. parm = (iparml_db *)grab_param();
  1212. parm->ipbfadr1 = (__u32) (addr_t) buffer;
  1213. parm->ipbfln1f = (__u32) ((ulong) buflen);
  1214. parm->ipmsgid = msgid;
  1215. parm->ippathid = pathid;
  1216. parm->iptrgcls = trgcls;
  1217. parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL);
  1218. b2f0_result = b2f0(RECEIVE, parm);
  1219. if (!b2f0_result || b2f0_result == 5) {
  1220. if (flags1_out) {
  1221. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1222. *flags1_out = (parm->ipflags1 & (~0x07));
  1223. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1224. }
  1225. if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
  1226. if (residual_length)
  1227. *residual_length = parm->ipbfln1f;
  1228. if (residual_buffer)
  1229. *residual_buffer = parm->ipbfadr1;
  1230. } else {
  1231. moved = min_t (unsigned long, buflen, 8);
  1232. memcpy ((char *) buffer,
  1233. (char *) &parm->ipbfadr1, moved);
  1234. if (buflen < 8)
  1235. b2f0_result = 5;
  1236. if (residual_length)
  1237. *residual_length = abs (buflen - 8);
  1238. if (residual_buffer)
  1239. *residual_buffer = (ulong) (buffer + moved);
  1240. }
  1241. }
  1242. release_param(parm);
  1243. iucv_debug(2, "exiting");
  1244. return b2f0_result;
  1245. }
  1246. /*
  1247. * Name: iucv_receive_array
  1248. * Purpose: This function receives messages that are being sent to you
  1249. * over established paths.
  1250. * Input: pathid - path identification number
  1251. * buffer - address of array of buffers
  1252. * buflen - total length of buffers
  1253. * msgid - specifies the message ID.
  1254. * trgcls - specifies target class
  1255. * Output:
  1256. * flags1_out: Options for path.
  1257. * IPNORPY - 0x10 specifies whether a reply is required
  1258. * IPPRTY - 0x20 specifies if you want to send priority message
  1259. * IPRMDATA - 0x80 specifies the data is contained in the parameter list
  1260. * residual_buffer - address points to the current list entry IUCV
  1261. * is working on.
  1262. * residual_length -
  1263. * Contains one of the following values, if the receive buffer is:
  1264. * The same length as the message, this field is zero.
  1265. * Longer than the message, this field contains the number of
  1266. * bytes remaining in the buffer.
  1267. * Shorter than the message, this field contains the residual
  1268. * count (that is, the number of bytes remaining in the
  1269. * message that does not fit into the buffer. In this case
  1270. * b2f0_result = 5.
  1271. * Return: b2f0_result - return code from CP
  1272. * (-EINVAL) - buffer address is NULL
  1273. */
  1274. int
  1275. iucv_receive_array (__u16 pathid,
  1276. __u32 msgid, __u32 trgcls,
  1277. iucv_array_t * buffer, ulong buflen,
  1278. int *flags1_out,
  1279. ulong * residual_buffer, ulong * residual_length)
  1280. {
  1281. iparml_db *parm;
  1282. ulong b2f0_result;
  1283. int i = 0, moved = 0, need_to_move = 8, dyn_len;
  1284. iucv_debug(2, "entering");
  1285. if (!buffer)
  1286. return -EINVAL;
  1287. parm = (iparml_db *)grab_param();
  1288. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1289. parm->ipbfln1f = (__u32) buflen;
  1290. parm->ipmsgid = msgid;
  1291. parm->ippathid = pathid;
  1292. parm->iptrgcls = trgcls;
  1293. parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL);
  1294. b2f0_result = b2f0(RECEIVE, parm);
  1295. if (!b2f0_result || b2f0_result == 5) {
  1296. if (flags1_out) {
  1297. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1298. *flags1_out = (parm->ipflags1 & (~0x07));
  1299. iucv_debug(2, "*flags1_out = %d", *flags1_out);
  1300. }
  1301. if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */
  1302. if (residual_length)
  1303. *residual_length = parm->ipbfln1f;
  1304. if (residual_buffer)
  1305. *residual_buffer = parm->ipbfadr1;
  1306. } else {
  1307. /* copy msg from parmlist to users array. */
  1308. while ((moved < 8) && (moved < buflen)) {
  1309. dyn_len =
  1310. min_t (unsigned int,
  1311. (buffer + i)->length, need_to_move);
  1312. memcpy ((char *)((ulong)((buffer + i)->address)),
  1313. ((char *) &parm->ipbfadr1) + moved,
  1314. dyn_len);
  1315. moved += dyn_len;
  1316. need_to_move -= dyn_len;
  1317. (buffer + i)->address =
  1318. (__u32)
  1319. ((ulong)(__u8 *) ((ulong)(buffer + i)->address)
  1320. + dyn_len);
  1321. (buffer + i)->length -= dyn_len;
  1322. i++;
  1323. }
  1324. if (need_to_move) /* buflen < 8 bytes */
  1325. b2f0_result = 5;
  1326. if (residual_length)
  1327. *residual_length = abs (buflen - 8);
  1328. if (residual_buffer) {
  1329. if (!moved)
  1330. *residual_buffer = (ulong) buffer;
  1331. else
  1332. *residual_buffer =
  1333. (ulong) (buffer + (i - 1));
  1334. }
  1335. }
  1336. }
  1337. release_param(parm);
  1338. iucv_debug(2, "exiting");
  1339. return b2f0_result;
  1340. }
  1341. /**
  1342. * iucv_reject:
  1343. * @pathid: Path identification number.
  1344. * @msgid: Message ID of the message to reject.
  1345. * @trgcls: Target class of the message to reject.
  1346. * Returns: return code from CP
  1347. *
  1348. * Refuses a specified message. Between the time you are notified of a
  1349. * message and the time that you complete the message, the message may
  1350. * be rejected.
  1351. */
  1352. int
  1353. iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls)
  1354. {
  1355. iparml_db *parm;
  1356. ulong b2f0_result = 0;
  1357. iucv_debug(1, "entering");
  1358. iucv_debug(1, "pathid = %d", pathid);
  1359. parm = (iparml_db *)grab_param();
  1360. parm->ippathid = pathid;
  1361. parm->ipmsgid = msgid;
  1362. parm->iptrgcls = trgcls;
  1363. parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID);
  1364. b2f0_result = b2f0(REJECT, parm);
  1365. release_param(parm);
  1366. iucv_debug(1, "b2f0_result = %ld", b2f0_result);
  1367. iucv_debug(1, "exiting");
  1368. return b2f0_result;
  1369. }
  1370. /*
  1371. * Name: iucv_reply
  1372. * Purpose: This function responds to the two-way messages that you
  1373. * receive. You must identify completely the message to
  1374. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1375. * Input: pathid - path identification number
  1376. * msgid - specifies the message ID.
  1377. * trgcls - specifies target class
  1378. * flags1 - option for path
  1379. * IPPRTY- 0x20 - specifies if you want to send priority message
  1380. * buffer - address of reply buffer
  1381. * buflen - length of reply buffer
  1382. * Output: ipbfadr2 - Address of buffer updated by the number
  1383. * of bytes you have moved.
  1384. * ipbfln2f - Contains one of the following values:
  1385. * If the answer buffer is the same length as the reply, this field
  1386. * contains zero.
  1387. * If the answer buffer is longer than the reply, this field contains
  1388. * the number of bytes remaining in the buffer.
  1389. * If the answer buffer is shorter than the reply, this field contains
  1390. * a residual count (that is, the number of bytes remianing in the
  1391. * reply that does not fit into the buffer. In this
  1392. * case b2f0_result = 5.
  1393. * Return: b2f0_result - return code from CP
  1394. * (-EINVAL) - buffer address is NULL
  1395. */
  1396. int
  1397. iucv_reply (__u16 pathid,
  1398. __u32 msgid, __u32 trgcls,
  1399. int flags1,
  1400. void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
  1401. {
  1402. iparml_db *parm;
  1403. ulong b2f0_result;
  1404. iucv_debug(2, "entering");
  1405. if (!buffer)
  1406. return -EINVAL;
  1407. parm = (iparml_db *)grab_param();
  1408. parm->ipbfadr2 = (__u32) ((ulong) buffer);
  1409. parm->ipbfln2f = (__u32) buflen; /* length of message */
  1410. parm->ippathid = pathid;
  1411. parm->ipmsgid = msgid;
  1412. parm->iptrgcls = trgcls;
  1413. parm->ipflags1 = (__u8) flags1; /* priority message */
  1414. b2f0_result = b2f0(REPLY, parm);
  1415. if ((!b2f0_result) || (b2f0_result == 5)) {
  1416. if (ipbfadr2)
  1417. *ipbfadr2 = parm->ipbfadr2;
  1418. if (ipbfln2f)
  1419. *ipbfln2f = parm->ipbfln2f;
  1420. }
  1421. release_param(parm);
  1422. iucv_debug(2, "exiting");
  1423. return b2f0_result;
  1424. }
  1425. /*
  1426. * Name: iucv_reply_array
  1427. * Purpose: This function responds to the two-way messages that you
  1428. * receive. You must identify completely the message to
  1429. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1430. * The array identifies a list of addresses and lengths of
  1431. * discontiguous buffers that contains the reply data.
  1432. * Input: pathid - path identification number
  1433. * msgid - specifies the message ID.
  1434. * trgcls - specifies target class
  1435. * flags1 - option for path
  1436. * IPPRTY- specifies if you want to send priority message
  1437. * buffer - address of array of reply buffers
  1438. * buflen - total length of reply buffers
  1439. * Output: ipbfadr2 - Address of buffer which IUCV is currently working on.
  1440. * ipbfln2f - Contains one of the following values:
  1441. * If the answer buffer is the same length as the reply, this field
  1442. * contains zero.
  1443. * If the answer buffer is longer than the reply, this field contains
  1444. * the number of bytes remaining in the buffer.
  1445. * If the answer buffer is shorter than the reply, this field contains
  1446. * a residual count (that is, the number of bytes remianing in the
  1447. * reply that does not fit into the buffer. In this
  1448. * case b2f0_result = 5.
  1449. * Return: b2f0_result - return code from CP
  1450. * (-EINVAL) - buffer address is NULL
  1451. */
  1452. int
  1453. iucv_reply_array (__u16 pathid,
  1454. __u32 msgid, __u32 trgcls,
  1455. int flags1,
  1456. iucv_array_t * buffer,
  1457. ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f)
  1458. {
  1459. iparml_db *parm;
  1460. ulong b2f0_result;
  1461. iucv_debug(2, "entering");
  1462. if (!buffer)
  1463. return -EINVAL;
  1464. parm = (iparml_db *)grab_param();
  1465. parm->ipbfadr2 = (__u32) ((ulong) buffer);
  1466. parm->ipbfln2f = buflen; /* length of message */
  1467. parm->ippathid = pathid;
  1468. parm->ipmsgid = msgid;
  1469. parm->iptrgcls = trgcls;
  1470. parm->ipflags1 = (IPANSLST | flags1);
  1471. b2f0_result = b2f0(REPLY, parm);
  1472. if ((!b2f0_result) || (b2f0_result == 5)) {
  1473. if (ipbfadr2)
  1474. *ipbfadr2 = parm->ipbfadr2;
  1475. if (ipbfln2f)
  1476. *ipbfln2f = parm->ipbfln2f;
  1477. }
  1478. release_param(parm);
  1479. iucv_debug(2, "exiting");
  1480. return b2f0_result;
  1481. }
  1482. /*
  1483. * Name: iucv_reply_prmmsg
  1484. * Purpose: This function responds to the two-way messages that you
  1485. * receive. You must identify completely the message to
  1486. * which you wish to reply. ie, pathid, msgid, and trgcls.
  1487. * Prmmsg signifies the data is moved into the
  1488. * parameter list.
  1489. * Input: pathid - path identification number
  1490. * msgid - specifies the message ID.
  1491. * trgcls - specifies target class
  1492. * flags1 - option for path
  1493. * IPPRTY- specifies if you want to send priority message
  1494. * prmmsg - 8-bytes of data to be placed into the parameter
  1495. * list.
  1496. * Output: NA
  1497. * Return: b2f0_result - return code from CP
  1498. */
  1499. int
  1500. iucv_reply_prmmsg (__u16 pathid,
  1501. __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8])
  1502. {
  1503. iparml_dpl *parm;
  1504. ulong b2f0_result;
  1505. iucv_debug(2, "entering");
  1506. parm = (iparml_dpl *)grab_param();
  1507. parm->ippathid = pathid;
  1508. parm->ipmsgid = msgid;
  1509. parm->iptrgcls = trgcls;
  1510. memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg));
  1511. parm->ipflags1 = (IPRMDATA | flags1);
  1512. b2f0_result = b2f0(REPLY, parm);
  1513. release_param(parm);
  1514. iucv_debug(2, "exiting");
  1515. return b2f0_result;
  1516. }
  1517. /**
  1518. * iucv_resume:
  1519. * @pathid: Path identification number
  1520. * @user_data: 16-byte of user data
  1521. *
  1522. * This function restores communication over a quiesced path.
  1523. * Returns: return code from CP
  1524. */
  1525. int
  1526. iucv_resume (__u16 pathid, __u8 user_data[16])
  1527. {
  1528. iparml_control *parm;
  1529. ulong b2f0_result = 0;
  1530. iucv_debug(1, "entering");
  1531. iucv_debug(1, "pathid = %d", pathid);
  1532. parm = (iparml_control *)grab_param();
  1533. memcpy (parm->ipuser, user_data, sizeof (*user_data));
  1534. parm->ippathid = pathid;
  1535. b2f0_result = b2f0(RESUME, parm);
  1536. release_param(parm);
  1537. iucv_debug(1, "exiting");
  1538. return b2f0_result;
  1539. }
  1540. /*
  1541. * Name: iucv_send
  1542. * Purpose: sends messages
  1543. * Input: pathid - ushort, pathid
  1544. * msgid - ulong *, id of message returned to caller
  1545. * trgcls - ulong, target message class
  1546. * srccls - ulong, source message class
  1547. * msgtag - ulong, message tag
  1548. * flags1 - Contains options for this path.
  1549. * IPPRTY - Ox20 - specifies if you want to send a priority message.
  1550. * buffer - pointer to buffer
  1551. * buflen - ulong, length of buffer
  1552. * Output: b2f0_result - return code from b2f0 call
  1553. * msgid - returns message id
  1554. */
  1555. int
  1556. iucv_send (__u16 pathid, __u32 * msgid,
  1557. __u32 trgcls, __u32 srccls,
  1558. __u32 msgtag, int flags1, void *buffer, ulong buflen)
  1559. {
  1560. iparml_db *parm;
  1561. ulong b2f0_result;
  1562. iucv_debug(2, "entering");
  1563. if (!buffer)
  1564. return -EINVAL;
  1565. parm = (iparml_db *)grab_param();
  1566. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1567. parm->ippathid = pathid;
  1568. parm->iptrgcls = trgcls;
  1569. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1570. parm->ipsrccls = srccls;
  1571. parm->ipmsgtag = msgtag;
  1572. parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */
  1573. b2f0_result = b2f0(SEND, parm);
  1574. if ((!b2f0_result) && (msgid))
  1575. *msgid = parm->ipmsgid;
  1576. release_param(parm);
  1577. iucv_debug(2, "exiting");
  1578. return b2f0_result;
  1579. }
  1580. /*
  1581. * Name: iucv_send_array
  1582. * Purpose: This function transmits data to another application.
  1583. * The contents of buffer is the address of the array of
  1584. * addresses and lengths of discontiguous buffers that hold
  1585. * the message text. This is a one-way message and the
  1586. * receiver will not reply to the message.
  1587. * Input: pathid - path identification number
  1588. * trgcls - specifies target class
  1589. * srccls - specifies the source message class
  1590. * msgtag - specifies a tag to be associated witht the message
  1591. * flags1 - option for path
  1592. * IPPRTY- specifies if you want to send priority message
  1593. * buffer - address of array of send buffers
  1594. * buflen - total length of send buffers
  1595. * Output: msgid - specifies the message ID.
  1596. * Return: b2f0_result - return code from CP
  1597. * (-EINVAL) - buffer address is NULL
  1598. */
  1599. int
  1600. iucv_send_array (__u16 pathid,
  1601. __u32 * msgid,
  1602. __u32 trgcls,
  1603. __u32 srccls,
  1604. __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen)
  1605. {
  1606. iparml_db *parm;
  1607. ulong b2f0_result;
  1608. iucv_debug(2, "entering");
  1609. if (!buffer)
  1610. return -EINVAL;
  1611. parm = (iparml_db *)grab_param();
  1612. parm->ippathid = pathid;
  1613. parm->iptrgcls = trgcls;
  1614. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1615. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1616. parm->ipsrccls = srccls;
  1617. parm->ipmsgtag = msgtag;
  1618. parm->ipflags1 = (IPNORPY | IPBUFLST | flags1);
  1619. b2f0_result = b2f0(SEND, parm);
  1620. if ((!b2f0_result) && (msgid))
  1621. *msgid = parm->ipmsgid;
  1622. release_param(parm);
  1623. iucv_debug(2, "exiting");
  1624. return b2f0_result;
  1625. }
  1626. /*
  1627. * Name: iucv_send_prmmsg
  1628. * Purpose: This function transmits data to another application.
  1629. * Prmmsg specifies that the 8-bytes of data are to be moved
  1630. * into the parameter list. This is a one-way message and the
  1631. * receiver will not reply to the message.
  1632. * Input: pathid - path identification number
  1633. * trgcls - specifies target class
  1634. * srccls - specifies the source message class
  1635. * msgtag - specifies a tag to be associated with the message
  1636. * flags1 - option for path
  1637. * IPPRTY- specifies if you want to send priority message
  1638. * prmmsg - 8-bytes of data to be placed into parameter list
  1639. * Output: msgid - specifies the message ID.
  1640. * Return: b2f0_result - return code from CP
  1641. */
  1642. int
  1643. iucv_send_prmmsg (__u16 pathid,
  1644. __u32 * msgid,
  1645. __u32 trgcls,
  1646. __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8])
  1647. {
  1648. iparml_dpl *parm;
  1649. ulong b2f0_result;
  1650. iucv_debug(2, "entering");
  1651. parm = (iparml_dpl *)grab_param();
  1652. parm->ippathid = pathid;
  1653. parm->iptrgcls = trgcls;
  1654. parm->ipsrccls = srccls;
  1655. parm->ipmsgtag = msgtag;
  1656. parm->ipflags1 = (IPRMDATA | IPNORPY | flags1);
  1657. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1658. b2f0_result = b2f0(SEND, parm);
  1659. if ((!b2f0_result) && (msgid))
  1660. *msgid = parm->ipmsgid;
  1661. release_param(parm);
  1662. iucv_debug(2, "exiting");
  1663. return b2f0_result;
  1664. }
  1665. /*
  1666. * Name: iucv_send2way
  1667. * Purpose: This function transmits data to another application.
  1668. * Data to be transmitted is in a buffer. The receiver
  1669. * of the send is expected to reply to the message and
  1670. * a buffer is provided into which IUCV moves the reply
  1671. * to this message.
  1672. * Input: pathid - path identification number
  1673. * trgcls - specifies target class
  1674. * srccls - specifies the source message class
  1675. * msgtag - specifies a tag associated with the message
  1676. * flags1 - option for path
  1677. * IPPRTY- specifies if you want to send priority message
  1678. * buffer - address of send buffer
  1679. * buflen - length of send buffer
  1680. * ansbuf - address of buffer to reply with
  1681. * anslen - length of buffer to reply with
  1682. * Output: msgid - specifies the message ID.
  1683. * Return: b2f0_result - return code from CP
  1684. * (-EINVAL) - buffer or ansbuf address is NULL
  1685. */
  1686. int
  1687. iucv_send2way (__u16 pathid,
  1688. __u32 * msgid,
  1689. __u32 trgcls,
  1690. __u32 srccls,
  1691. __u32 msgtag,
  1692. int flags1,
  1693. void *buffer, ulong buflen, void *ansbuf, ulong anslen)
  1694. {
  1695. iparml_db *parm;
  1696. ulong b2f0_result;
  1697. iucv_debug(2, "entering");
  1698. if (!buffer || !ansbuf)
  1699. return -EINVAL;
  1700. parm = (iparml_db *)grab_param();
  1701. parm->ippathid = pathid;
  1702. parm->iptrgcls = trgcls;
  1703. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1704. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1705. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1706. parm->ipbfln2f = (__u32) anslen;
  1707. parm->ipsrccls = srccls;
  1708. parm->ipmsgtag = msgtag;
  1709. parm->ipflags1 = flags1; /* priority message */
  1710. b2f0_result = b2f0(SEND, parm);
  1711. if ((!b2f0_result) && (msgid))
  1712. *msgid = parm->ipmsgid;
  1713. release_param(parm);
  1714. iucv_debug(2, "exiting");
  1715. return b2f0_result;
  1716. }
  1717. /*
  1718. * Name: iucv_send2way_array
  1719. * Purpose: This function transmits data to another application.
  1720. * The contents of buffer is the address of the array of
  1721. * addresses and lengths of discontiguous buffers that hold
  1722. * the message text. The receiver of the send is expected to
  1723. * reply to the message and a buffer is provided into which
  1724. * IUCV moves the reply to this message.
  1725. * Input: pathid - path identification number
  1726. * trgcls - specifies target class
  1727. * srccls - specifies the source message class
  1728. * msgtag - spcifies a tag to be associated with the message
  1729. * flags1 - option for path
  1730. * IPPRTY- specifies if you want to send priority message
  1731. * buffer - address of array of send buffers
  1732. * buflen - total length of send buffers
  1733. * ansbuf - address of buffer to reply with
  1734. * anslen - length of buffer to reply with
  1735. * Output: msgid - specifies the message ID.
  1736. * Return: b2f0_result - return code from CP
  1737. * (-EINVAL) - buffer address is NULL
  1738. */
  1739. int
  1740. iucv_send2way_array (__u16 pathid,
  1741. __u32 * msgid,
  1742. __u32 trgcls,
  1743. __u32 srccls,
  1744. __u32 msgtag,
  1745. int flags1,
  1746. iucv_array_t * buffer,
  1747. ulong buflen, iucv_array_t * ansbuf, ulong anslen)
  1748. {
  1749. iparml_db *parm;
  1750. ulong b2f0_result;
  1751. iucv_debug(2, "entering");
  1752. if (!buffer || !ansbuf)
  1753. return -EINVAL;
  1754. parm = (iparml_db *)grab_param();
  1755. parm->ippathid = pathid;
  1756. parm->iptrgcls = trgcls;
  1757. parm->ipbfadr1 = (__u32) ((ulong) buffer);
  1758. parm->ipbfln1f = (__u32) buflen; /* length of message */
  1759. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1760. parm->ipbfln2f = (__u32) anslen;
  1761. parm->ipsrccls = srccls;
  1762. parm->ipmsgtag = msgtag;
  1763. parm->ipflags1 = (IPBUFLST | IPANSLST | flags1);
  1764. b2f0_result = b2f0(SEND, parm);
  1765. if ((!b2f0_result) && (msgid))
  1766. *msgid = parm->ipmsgid;
  1767. release_param(parm);
  1768. iucv_debug(2, "exiting");
  1769. return b2f0_result;
  1770. }
  1771. /*
  1772. * Name: iucv_send2way_prmmsg
  1773. * Purpose: This function transmits data to another application.
  1774. * Prmmsg specifies that the 8-bytes of data are to be moved
  1775. * into the parameter list. This is a two-way message and the
  1776. * receiver of the message is expected to reply. A buffer
  1777. * is provided into which IUCV moves the reply to this
  1778. * message.
  1779. * Input: pathid - path identification number
  1780. * trgcls - specifies target class
  1781. * srccls - specifies the source message class
  1782. * msgtag - specifies a tag to be associated with the message
  1783. * flags1 - option for path
  1784. * IPPRTY- specifies if you want to send priority message
  1785. * prmmsg - 8-bytes of data to be placed in parameter list
  1786. * ansbuf - address of buffer to reply with
  1787. * anslen - length of buffer to reply with
  1788. * Output: msgid - specifies the message ID.
  1789. * Return: b2f0_result - return code from CP
  1790. * (-EINVAL) - buffer address is NULL
  1791. */
  1792. int
  1793. iucv_send2way_prmmsg (__u16 pathid,
  1794. __u32 * msgid,
  1795. __u32 trgcls,
  1796. __u32 srccls,
  1797. __u32 msgtag,
  1798. ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen)
  1799. {
  1800. iparml_dpl *parm;
  1801. ulong b2f0_result;
  1802. iucv_debug(2, "entering");
  1803. if (!ansbuf)
  1804. return -EINVAL;
  1805. parm = (iparml_dpl *)grab_param();
  1806. parm->ippathid = pathid;
  1807. parm->iptrgcls = trgcls;
  1808. parm->ipsrccls = srccls;
  1809. parm->ipmsgtag = msgtag;
  1810. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1811. parm->ipbfln2f = (__u32) anslen;
  1812. parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */
  1813. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1814. b2f0_result = b2f0(SEND, parm);
  1815. if ((!b2f0_result) && (msgid))
  1816. *msgid = parm->ipmsgid;
  1817. release_param(parm);
  1818. iucv_debug(2, "exiting");
  1819. return b2f0_result;
  1820. }
  1821. /*
  1822. * Name: iucv_send2way_prmmsg_array
  1823. * Purpose: This function transmits data to another application.
  1824. * Prmmsg specifies that the 8-bytes of data are to be moved
  1825. * into the parameter list. This is a two-way message and the
  1826. * receiver of the message is expected to reply. A buffer
  1827. * is provided into which IUCV moves the reply to this
  1828. * message. The contents of ansbuf is the address of the
  1829. * array of addresses and lengths of discontiguous buffers
  1830. * that contain the reply.
  1831. * Input: pathid - path identification number
  1832. * trgcls - specifies target class
  1833. * srccls - specifies the source message class
  1834. * msgtag - specifies a tag to be associated with the message
  1835. * flags1 - option for path
  1836. * IPPRTY- specifies if you want to send priority message
  1837. * prmmsg - 8-bytes of data to be placed into the parameter list
  1838. * ansbuf - address of buffer to reply with
  1839. * anslen - length of buffer to reply with
  1840. * Output: msgid - specifies the message ID.
  1841. * Return: b2f0_result - return code from CP
  1842. * (-EINVAL) - ansbuf address is NULL
  1843. */
  1844. int
  1845. iucv_send2way_prmmsg_array (__u16 pathid,
  1846. __u32 * msgid,
  1847. __u32 trgcls,
  1848. __u32 srccls,
  1849. __u32 msgtag,
  1850. int flags1,
  1851. __u8 prmmsg[8],
  1852. iucv_array_t * ansbuf, ulong anslen)
  1853. {
  1854. iparml_dpl *parm;
  1855. ulong b2f0_result;
  1856. iucv_debug(2, "entering");
  1857. if (!ansbuf)
  1858. return -EINVAL;
  1859. parm = (iparml_dpl *)grab_param();
  1860. parm->ippathid = pathid;
  1861. parm->iptrgcls = trgcls;
  1862. parm->ipsrccls = srccls;
  1863. parm->ipmsgtag = msgtag;
  1864. parm->ipbfadr2 = (__u32) ((ulong) ansbuf);
  1865. parm->ipbfln2f = (__u32) anslen;
  1866. parm->ipflags1 = (IPRMDATA | IPANSLST | flags1);
  1867. memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg));
  1868. b2f0_result = b2f0(SEND, parm);
  1869. if ((!b2f0_result) && (msgid))
  1870. *msgid = parm->ipmsgid;
  1871. release_param(parm);
  1872. iucv_debug(2, "exiting");
  1873. return b2f0_result;
  1874. }
  1875. void
  1876. iucv_setmask_cpuid (void *result)
  1877. {
  1878. iparml_set_mask *parm;
  1879. iucv_debug(1, "entering");
  1880. parm = (iparml_set_mask *)grab_param();
  1881. parm->ipmask = *((__u8*)result);
  1882. *((ulong *)result) = b2f0(SETMASK, parm);
  1883. release_param(parm);
  1884. iucv_debug(1, "b2f0_result = %ld", *((ulong *)result));
  1885. iucv_debug(1, "exiting");
  1886. }
  1887. /*
  1888. * Name: iucv_setmask
  1889. * Purpose: This function enables or disables the following IUCV
  1890. * external interruptions: Nonpriority and priority message
  1891. * interrupts, nonpriority and priority reply interrupts.
  1892. * Input: SetMaskFlag - options for interrupts
  1893. * 0x80 - Nonpriority_MessagePendingInterruptsFlag
  1894. * 0x40 - Priority_MessagePendingInterruptsFlag
  1895. * 0x20 - Nonpriority_MessageCompletionInterruptsFlag
  1896. * 0x10 - Priority_MessageCompletionInterruptsFlag
  1897. * 0x08 - IUCVControlInterruptsFlag
  1898. * Output: NA
  1899. * Return: b2f0_result - return code from CP
  1900. */
  1901. int
  1902. iucv_setmask (int SetMaskFlag)
  1903. {
  1904. union {
  1905. ulong result;
  1906. __u8 param;
  1907. } u;
  1908. int cpu;
  1909. u.param = SetMaskFlag;
  1910. cpu = get_cpu();
  1911. smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid);
  1912. put_cpu();
  1913. return u.result;
  1914. }
  1915. /**
  1916. * iucv_sever:
  1917. * @pathid: Path identification number
  1918. * @user_data: 16-byte of user data
  1919. *
  1920. * This function terminates an iucv path.
  1921. * Returns: return code from CP
  1922. */
  1923. int
  1924. iucv_sever(__u16 pathid, __u8 user_data[16])
  1925. {
  1926. iparml_control *parm;
  1927. ulong b2f0_result = 0;
  1928. iucv_debug(1, "entering");
  1929. parm = (iparml_control *)grab_param();
  1930. memcpy(parm->ipuser, user_data, sizeof(parm->ipuser));
  1931. parm->ippathid = pathid;
  1932. b2f0_result = b2f0(SEVER, parm);
  1933. if (!b2f0_result)
  1934. iucv_remove_pathid(pathid);
  1935. release_param(parm);
  1936. iucv_debug(1, "exiting");
  1937. return b2f0_result;
  1938. }
  1939. /*
  1940. * Interrupt Handlers
  1941. *******************************************************************************/
  1942. /**
  1943. * iucv_irq_handler:
  1944. * @regs: Current registers
  1945. * @code: irq code
  1946. *
  1947. * Handles external interrupts coming in from CP.
  1948. * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler().
  1949. */
  1950. static void
  1951. iucv_irq_handler(__u16 code)
  1952. {
  1953. iucv_irqdata *irqdata;
  1954. irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC);
  1955. if (!irqdata) {
  1956. printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__);
  1957. return;
  1958. }
  1959. memcpy(&irqdata->data, iucv_external_int_buffer,
  1960. sizeof(iucv_GeneralInterrupt));
  1961. spin_lock(&iucv_irq_queue_lock);
  1962. list_add_tail(&irqdata->queue, &iucv_irq_queue);
  1963. spin_unlock(&iucv_irq_queue_lock);
  1964. tasklet_schedule(&iucv_tasklet);
  1965. }
  1966. /**
  1967. * iucv_do_int:
  1968. * @int_buf: Pointer to copy of external interrupt buffer
  1969. *
  1970. * The workhorse for handling interrupts queued by iucv_irq_handler().
  1971. * This function is called from the bottom half iucv_tasklet_handler().
  1972. */
  1973. static void
  1974. iucv_do_int(iucv_GeneralInterrupt * int_buf)
  1975. {
  1976. handler *h = NULL;
  1977. struct list_head *lh;
  1978. ulong flags;
  1979. iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */
  1980. __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */
  1981. int rc = 0, j = 0;
  1982. __u8 no_listener[16] = "NO LISTENER";
  1983. iucv_debug(2, "entering, pathid %d, type %02X",
  1984. int_buf->ippathid, int_buf->iptype);
  1985. iucv_dumpit("External Interrupt Buffer:",
  1986. int_buf, sizeof(iucv_GeneralInterrupt));
  1987. ASCEBC (no_listener, 16);
  1988. if (int_buf->iptype != 01) {
  1989. if ((int_buf->ippathid) > (max_connections - 1)) {
  1990. printk(KERN_WARNING "%s: Got interrupt with pathid %d"
  1991. " > max_connections (%ld)\n", __FUNCTION__,
  1992. int_buf->ippathid, max_connections - 1);
  1993. } else {
  1994. h = iucv_pathid_table[int_buf->ippathid];
  1995. interrupt = h->interrupt_table;
  1996. iucv_dumpit("Handler:", h, sizeof(handler));
  1997. }
  1998. }
  1999. /* end of if statement */
  2000. switch (int_buf->iptype) {
  2001. case 0x01: /* connection pending */
  2002. if (messagesDisabled) {
  2003. iucv_setmask(~0);
  2004. messagesDisabled = 0;
  2005. }
  2006. spin_lock_irqsave(&iucv_lock, flags);
  2007. list_for_each(lh, &iucv_handler_table) {
  2008. h = list_entry(lh, handler, list);
  2009. memcpy(temp_buff1, &(int_buf->ipvmid), 24);
  2010. memcpy(temp_buff2, &(h->id.userid), 24);
  2011. for (j = 0; j < 24; j++) {
  2012. temp_buff1[j] &= (h->id.mask)[j];
  2013. temp_buff2[j] &= (h->id.mask)[j];
  2014. }
  2015. iucv_dumpit("temp_buff1:",
  2016. temp_buff1, sizeof(temp_buff1));
  2017. iucv_dumpit("temp_buff2",
  2018. temp_buff2, sizeof(temp_buff2));
  2019. if (!memcmp (temp_buff1, temp_buff2, 24)) {
  2020. iucv_debug(2,
  2021. "found a matching handler");
  2022. break;
  2023. } else
  2024. h = NULL;
  2025. }
  2026. spin_unlock_irqrestore (&iucv_lock, flags);
  2027. if (h) {
  2028. /* ADD PATH TO PATHID TABLE */
  2029. rc = iucv_add_pathid(int_buf->ippathid, h);
  2030. if (rc) {
  2031. iucv_sever (int_buf->ippathid,
  2032. no_listener);
  2033. iucv_debug(1,
  2034. "add_pathid failed, rc = %d",
  2035. rc);
  2036. } else {
  2037. interrupt = h->interrupt_table;
  2038. if (interrupt->ConnectionPending) {
  2039. EBCASC (int_buf->ipvmid, 8);
  2040. interrupt->ConnectionPending(
  2041. (iucv_ConnectionPending *)int_buf,
  2042. h->pgm_data);
  2043. } else
  2044. iucv_sever(int_buf->ippathid,
  2045. no_listener);
  2046. }
  2047. } else
  2048. iucv_sever(int_buf->ippathid, no_listener);
  2049. break;
  2050. case 0x02: /*connection complete */
  2051. if (messagesDisabled) {
  2052. iucv_setmask(~0);
  2053. messagesDisabled = 0;
  2054. }
  2055. if (h) {
  2056. if (interrupt->ConnectionComplete)
  2057. {
  2058. interrupt->ConnectionComplete(
  2059. (iucv_ConnectionComplete *)int_buf,
  2060. h->pgm_data);
  2061. }
  2062. else
  2063. iucv_debug(1,
  2064. "ConnectionComplete not called");
  2065. } else
  2066. iucv_sever(int_buf->ippathid, no_listener);
  2067. break;
  2068. case 0x03: /* connection severed */
  2069. if (messagesDisabled) {
  2070. iucv_setmask(~0);
  2071. messagesDisabled = 0;
  2072. }
  2073. if (h) {
  2074. if (interrupt->ConnectionSevered)
  2075. interrupt->ConnectionSevered(
  2076. (iucv_ConnectionSevered *)int_buf,
  2077. h->pgm_data);
  2078. else
  2079. iucv_sever (int_buf->ippathid, no_listener);
  2080. } else
  2081. iucv_sever(int_buf->ippathid, no_listener);
  2082. break;
  2083. case 0x04: /* connection quiesced */
  2084. if (messagesDisabled) {
  2085. iucv_setmask(~0);
  2086. messagesDisabled = 0;
  2087. }
  2088. if (h) {
  2089. if (interrupt->ConnectionQuiesced)
  2090. interrupt->ConnectionQuiesced(
  2091. (iucv_ConnectionQuiesced *)int_buf,
  2092. h->pgm_data);
  2093. else
  2094. iucv_debug(1,
  2095. "ConnectionQuiesced not called");
  2096. }
  2097. break;
  2098. case 0x05: /* connection resumed */
  2099. if (messagesDisabled) {
  2100. iucv_setmask(~0);
  2101. messagesDisabled = 0;
  2102. }
  2103. if (h) {
  2104. if (interrupt->ConnectionResumed)
  2105. interrupt->ConnectionResumed(
  2106. (iucv_ConnectionResumed *)int_buf,
  2107. h->pgm_data);
  2108. else
  2109. iucv_debug(1,
  2110. "ConnectionResumed not called");
  2111. }
  2112. break;
  2113. case 0x06: /* priority message complete */
  2114. case 0x07: /* nonpriority message complete */
  2115. if (h) {
  2116. if (interrupt->MessageComplete)
  2117. interrupt->MessageComplete(
  2118. (iucv_MessageComplete *)int_buf,
  2119. h->pgm_data);
  2120. else
  2121. iucv_debug(2,
  2122. "MessageComplete not called");
  2123. }
  2124. break;
  2125. case 0x08: /* priority message pending */
  2126. case 0x09: /* nonpriority message pending */
  2127. if (h) {
  2128. if (interrupt->MessagePending)
  2129. interrupt->MessagePending(
  2130. (iucv_MessagePending *) int_buf,
  2131. h->pgm_data);
  2132. else
  2133. iucv_debug(2,
  2134. "MessagePending not called");
  2135. }
  2136. break;
  2137. default: /* unknown iucv type */
  2138. printk(KERN_WARNING "%s: unknown iucv interrupt\n",
  2139. __FUNCTION__);
  2140. break;
  2141. } /* end switch */
  2142. iucv_debug(2, "exiting pathid %d, type %02X",
  2143. int_buf->ippathid, int_buf->iptype);
  2144. return;
  2145. }
  2146. /**
  2147. * iucv_tasklet_handler:
  2148. *
  2149. * This function loops over the queue of irq buffers and runs iucv_do_int()
  2150. * on every queue element.
  2151. */
  2152. static void
  2153. iucv_tasklet_handler(unsigned long ignored)
  2154. {
  2155. struct list_head head;
  2156. struct list_head *next;
  2157. ulong flags;
  2158. spin_lock_irqsave(&iucv_irq_queue_lock, flags);
  2159. list_add(&head, &iucv_irq_queue);
  2160. list_del_init(&iucv_irq_queue);
  2161. spin_unlock_irqrestore (&iucv_irq_queue_lock, flags);
  2162. next = head.next;
  2163. while (next != &head) {
  2164. iucv_irqdata *p = list_entry(next, iucv_irqdata, queue);
  2165. next = next->next;
  2166. iucv_do_int(&p->data);
  2167. kfree(p);
  2168. }
  2169. return;
  2170. }
  2171. subsys_initcall(iucv_init);
  2172. module_exit(iucv_exit);
  2173. /**
  2174. * Export all public stuff
  2175. */
  2176. EXPORT_SYMBOL (iucv_bus);
  2177. EXPORT_SYMBOL (iucv_root);
  2178. EXPORT_SYMBOL (iucv_accept);
  2179. EXPORT_SYMBOL (iucv_connect);
  2180. #if 0
  2181. EXPORT_SYMBOL (iucv_purge);
  2182. EXPORT_SYMBOL (iucv_query_maxconn);
  2183. EXPORT_SYMBOL (iucv_query_bufsize);
  2184. EXPORT_SYMBOL (iucv_quiesce);
  2185. #endif
  2186. EXPORT_SYMBOL (iucv_receive);
  2187. #if 0
  2188. EXPORT_SYMBOL (iucv_receive_array);
  2189. #endif
  2190. EXPORT_SYMBOL (iucv_reject);
  2191. #if 0
  2192. EXPORT_SYMBOL (iucv_reply);
  2193. EXPORT_SYMBOL (iucv_reply_array);
  2194. EXPORT_SYMBOL (iucv_resume);
  2195. #endif
  2196. EXPORT_SYMBOL (iucv_reply_prmmsg);
  2197. EXPORT_SYMBOL (iucv_send);
  2198. EXPORT_SYMBOL (iucv_send2way);
  2199. EXPORT_SYMBOL (iucv_send2way_array);
  2200. EXPORT_SYMBOL (iucv_send2way_prmmsg);
  2201. EXPORT_SYMBOL (iucv_send2way_prmmsg_array);
  2202. #if 0
  2203. EXPORT_SYMBOL (iucv_send_array);
  2204. EXPORT_SYMBOL (iucv_send_prmmsg);
  2205. EXPORT_SYMBOL (iucv_setmask);
  2206. #endif
  2207. EXPORT_SYMBOL (iucv_sever);
  2208. EXPORT_SYMBOL (iucv_register_program);
  2209. EXPORT_SYMBOL (iucv_unregister_program);