iucv.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. /*
  2. * IUCV base infrastructure.
  3. *
  4. * Copyright IBM Corp. 2001, 2009
  5. *
  6. * Author(s):
  7. * Original source:
  8. * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000
  9. * Xenia Tkatschow (xenia@us.ibm.com)
  10. * 2Gb awareness and general cleanup:
  11. * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
  12. * Rewritten for af_iucv:
  13. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  14. *
  15. * Documentation used:
  16. * The original source
  17. * CP Programming Service, IBM document # SC24-5760
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2, or (at your option)
  22. * any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. */
  33. #define KMSG_COMPONENT "iucv"
  34. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/kernel.h>
  39. #include <linux/slab.h>
  40. #include <linux/init.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/list.h>
  43. #include <linux/errno.h>
  44. #include <linux/err.h>
  45. #include <linux/device.h>
  46. #include <linux/cpu.h>
  47. #include <linux/reboot.h>
  48. #include <net/iucv/iucv.h>
  49. #include <asm/atomic.h>
  50. #include <asm/ebcdic.h>
  51. #include <asm/io.h>
  52. #include <asm/s390_ext.h>
  53. #include <asm/smp.h>
  54. /*
  55. * FLAGS:
  56. * All flags are defined in the field IPFLAGS1 of each function
  57. * and can be found in CP Programming Services.
  58. * IPSRCCLS - Indicates you have specified a source class.
  59. * IPTRGCLS - Indicates you have specified a target class.
  60. * IPFGPID - Indicates you have specified a pathid.
  61. * IPFGMID - Indicates you have specified a message ID.
  62. * IPNORPY - Indicates a one-way message. No reply expected.
  63. * IPALL - Indicates that all paths are affected.
  64. */
  65. #define IUCV_IPSRCCLS 0x01
  66. #define IUCV_IPTRGCLS 0x01
  67. #define IUCV_IPFGPID 0x02
  68. #define IUCV_IPFGMID 0x04
  69. #define IUCV_IPNORPY 0x10
  70. #define IUCV_IPALL 0x80
  71. static int iucv_bus_match(struct device *dev, struct device_driver *drv)
  72. {
  73. return 0;
  74. }
  75. struct bus_type iucv_bus = {
  76. .name = "iucv",
  77. .match = iucv_bus_match,
  78. };
  79. EXPORT_SYMBOL(iucv_bus);
  80. struct device *iucv_root;
  81. EXPORT_SYMBOL(iucv_root);
  82. static int iucv_available;
  83. /* General IUCV interrupt structure */
  84. struct iucv_irq_data {
  85. u16 ippathid;
  86. u8 ipflags1;
  87. u8 iptype;
  88. u32 res2[8];
  89. };
  90. struct iucv_irq_list {
  91. struct list_head list;
  92. struct iucv_irq_data data;
  93. };
  94. static struct iucv_irq_data *iucv_irq_data[NR_CPUS];
  95. static cpumask_t iucv_buffer_cpumask = CPU_MASK_NONE;
  96. static cpumask_t iucv_irq_cpumask = CPU_MASK_NONE;
  97. /*
  98. * Queue of interrupt buffers lock for delivery via the tasklet
  99. * (fast but can't call smp_call_function).
  100. */
  101. static LIST_HEAD(iucv_task_queue);
  102. /*
  103. * The tasklet for fast delivery of iucv interrupts.
  104. */
  105. static void iucv_tasklet_fn(unsigned long);
  106. static DECLARE_TASKLET(iucv_tasklet, iucv_tasklet_fn,0);
  107. /*
  108. * Queue of interrupt buffers for delivery via a work queue
  109. * (slower but can call smp_call_function).
  110. */
  111. static LIST_HEAD(iucv_work_queue);
  112. /*
  113. * The work element to deliver path pending interrupts.
  114. */
  115. static void iucv_work_fn(struct work_struct *work);
  116. static DECLARE_WORK(iucv_work, iucv_work_fn);
  117. /*
  118. * Spinlock protecting task and work queue.
  119. */
  120. static DEFINE_SPINLOCK(iucv_queue_lock);
  121. enum iucv_command_codes {
  122. IUCV_QUERY = 0,
  123. IUCV_RETRIEVE_BUFFER = 2,
  124. IUCV_SEND = 4,
  125. IUCV_RECEIVE = 5,
  126. IUCV_REPLY = 6,
  127. IUCV_REJECT = 8,
  128. IUCV_PURGE = 9,
  129. IUCV_ACCEPT = 10,
  130. IUCV_CONNECT = 11,
  131. IUCV_DECLARE_BUFFER = 12,
  132. IUCV_QUIESCE = 13,
  133. IUCV_RESUME = 14,
  134. IUCV_SEVER = 15,
  135. IUCV_SETMASK = 16,
  136. };
  137. /*
  138. * Error messages that are used with the iucv_sever function. They get
  139. * converted to EBCDIC.
  140. */
  141. static char iucv_error_no_listener[16] = "NO LISTENER";
  142. static char iucv_error_no_memory[16] = "NO MEMORY";
  143. static char iucv_error_pathid[16] = "INVALID PATHID";
  144. /*
  145. * iucv_handler_list: List of registered handlers.
  146. */
  147. static LIST_HEAD(iucv_handler_list);
  148. /*
  149. * iucv_path_table: an array of iucv_path structures.
  150. */
  151. static struct iucv_path **iucv_path_table;
  152. static unsigned long iucv_max_pathid;
  153. /*
  154. * iucv_lock: spinlock protecting iucv_handler_list and iucv_pathid_table
  155. */
  156. static DEFINE_SPINLOCK(iucv_table_lock);
  157. /*
  158. * iucv_active_cpu: contains the number of the cpu executing the tasklet
  159. * or the work handler. Needed for iucv_path_sever called from tasklet.
  160. */
  161. static int iucv_active_cpu = -1;
  162. /*
  163. * Mutex and wait queue for iucv_register/iucv_unregister.
  164. */
  165. static DEFINE_MUTEX(iucv_register_mutex);
  166. /*
  167. * Counter for number of non-smp capable handlers.
  168. */
  169. static int iucv_nonsmp_handler;
  170. /*
  171. * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect,
  172. * iucv_path_quiesce and iucv_path_sever.
  173. */
  174. struct iucv_cmd_control {
  175. u16 ippathid;
  176. u8 ipflags1;
  177. u8 iprcode;
  178. u16 ipmsglim;
  179. u16 res1;
  180. u8 ipvmid[8];
  181. u8 ipuser[16];
  182. u8 iptarget[8];
  183. } __attribute__ ((packed,aligned(8)));
  184. /*
  185. * Data in parameter list iucv structure. Used by iucv_message_send,
  186. * iucv_message_send2way and iucv_message_reply.
  187. */
  188. struct iucv_cmd_dpl {
  189. u16 ippathid;
  190. u8 ipflags1;
  191. u8 iprcode;
  192. u32 ipmsgid;
  193. u32 iptrgcls;
  194. u8 iprmmsg[8];
  195. u32 ipsrccls;
  196. u32 ipmsgtag;
  197. u32 ipbfadr2;
  198. u32 ipbfln2f;
  199. u32 res;
  200. } __attribute__ ((packed,aligned(8)));
  201. /*
  202. * Data in buffer iucv structure. Used by iucv_message_receive,
  203. * iucv_message_reject, iucv_message_send, iucv_message_send2way
  204. * and iucv_declare_cpu.
  205. */
  206. struct iucv_cmd_db {
  207. u16 ippathid;
  208. u8 ipflags1;
  209. u8 iprcode;
  210. u32 ipmsgid;
  211. u32 iptrgcls;
  212. u32 ipbfadr1;
  213. u32 ipbfln1f;
  214. u32 ipsrccls;
  215. u32 ipmsgtag;
  216. u32 ipbfadr2;
  217. u32 ipbfln2f;
  218. u32 res;
  219. } __attribute__ ((packed,aligned(8)));
  220. /*
  221. * Purge message iucv structure. Used by iucv_message_purge.
  222. */
  223. struct iucv_cmd_purge {
  224. u16 ippathid;
  225. u8 ipflags1;
  226. u8 iprcode;
  227. u32 ipmsgid;
  228. u8 ipaudit[3];
  229. u8 res1[5];
  230. u32 res2;
  231. u32 ipsrccls;
  232. u32 ipmsgtag;
  233. u32 res3[3];
  234. } __attribute__ ((packed,aligned(8)));
  235. /*
  236. * Set mask iucv structure. Used by iucv_enable_cpu.
  237. */
  238. struct iucv_cmd_set_mask {
  239. u8 ipmask;
  240. u8 res1[2];
  241. u8 iprcode;
  242. u32 res2[9];
  243. } __attribute__ ((packed,aligned(8)));
  244. union iucv_param {
  245. struct iucv_cmd_control ctrl;
  246. struct iucv_cmd_dpl dpl;
  247. struct iucv_cmd_db db;
  248. struct iucv_cmd_purge purge;
  249. struct iucv_cmd_set_mask set_mask;
  250. };
  251. /*
  252. * Anchor for per-cpu IUCV command parameter block.
  253. */
  254. static union iucv_param *iucv_param[NR_CPUS];
  255. static union iucv_param *iucv_param_irq[NR_CPUS];
  256. /**
  257. * iucv_call_b2f0
  258. * @code: identifier of IUCV call to CP.
  259. * @parm: pointer to a struct iucv_parm block
  260. *
  261. * Calls CP to execute IUCV commands.
  262. *
  263. * Returns the result of the CP IUCV call.
  264. */
  265. static inline int iucv_call_b2f0(int command, union iucv_param *parm)
  266. {
  267. register unsigned long reg0 asm ("0");
  268. register unsigned long reg1 asm ("1");
  269. int ccode;
  270. reg0 = command;
  271. reg1 = virt_to_phys(parm);
  272. asm volatile(
  273. " .long 0xb2f01000\n"
  274. " ipm %0\n"
  275. " srl %0,28\n"
  276. : "=d" (ccode), "=m" (*parm), "+d" (reg0), "+a" (reg1)
  277. : "m" (*parm) : "cc");
  278. return (ccode == 1) ? parm->ctrl.iprcode : ccode;
  279. }
  280. /**
  281. * iucv_query_maxconn
  282. *
  283. * Determines the maximum number of connections that may be established.
  284. *
  285. * Returns the maximum number of connections or -EPERM is IUCV is not
  286. * available.
  287. */
  288. static int iucv_query_maxconn(void)
  289. {
  290. register unsigned long reg0 asm ("0");
  291. register unsigned long reg1 asm ("1");
  292. void *param;
  293. int ccode;
  294. param = kzalloc(sizeof(union iucv_param), GFP_KERNEL|GFP_DMA);
  295. if (!param)
  296. return -ENOMEM;
  297. reg0 = IUCV_QUERY;
  298. reg1 = (unsigned long) param;
  299. asm volatile (
  300. " .long 0xb2f01000\n"
  301. " ipm %0\n"
  302. " srl %0,28\n"
  303. : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
  304. if (ccode == 0)
  305. iucv_max_pathid = reg0;
  306. kfree(param);
  307. return ccode ? -EPERM : 0;
  308. }
  309. /**
  310. * iucv_allow_cpu
  311. * @data: unused
  312. *
  313. * Allow iucv interrupts on this cpu.
  314. */
  315. static void iucv_allow_cpu(void *data)
  316. {
  317. int cpu = smp_processor_id();
  318. union iucv_param *parm;
  319. /*
  320. * Enable all iucv interrupts.
  321. * ipmask contains bits for the different interrupts
  322. * 0x80 - Flag to allow nonpriority message pending interrupts
  323. * 0x40 - Flag to allow priority message pending interrupts
  324. * 0x20 - Flag to allow nonpriority message completion interrupts
  325. * 0x10 - Flag to allow priority message completion interrupts
  326. * 0x08 - Flag to allow IUCV control interrupts
  327. */
  328. parm = iucv_param_irq[cpu];
  329. memset(parm, 0, sizeof(union iucv_param));
  330. parm->set_mask.ipmask = 0xf8;
  331. iucv_call_b2f0(IUCV_SETMASK, parm);
  332. /* Set indication that iucv interrupts are allowed for this cpu. */
  333. cpu_set(cpu, iucv_irq_cpumask);
  334. }
  335. /**
  336. * iucv_block_cpu
  337. * @data: unused
  338. *
  339. * Block iucv interrupts on this cpu.
  340. */
  341. static void iucv_block_cpu(void *data)
  342. {
  343. int cpu = smp_processor_id();
  344. union iucv_param *parm;
  345. /* Disable all iucv interrupts. */
  346. parm = iucv_param_irq[cpu];
  347. memset(parm, 0, sizeof(union iucv_param));
  348. iucv_call_b2f0(IUCV_SETMASK, parm);
  349. /* Clear indication that iucv interrupts are allowed for this cpu. */
  350. cpu_clear(cpu, iucv_irq_cpumask);
  351. }
  352. /**
  353. * iucv_declare_cpu
  354. * @data: unused
  355. *
  356. * Declare a interrupt buffer on this cpu.
  357. */
  358. static void iucv_declare_cpu(void *data)
  359. {
  360. int cpu = smp_processor_id();
  361. union iucv_param *parm;
  362. int rc;
  363. if (cpu_isset(cpu, iucv_buffer_cpumask))
  364. return;
  365. /* Declare interrupt buffer. */
  366. parm = iucv_param_irq[cpu];
  367. memset(parm, 0, sizeof(union iucv_param));
  368. parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
  369. rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
  370. if (rc) {
  371. char *err = "Unknown";
  372. switch (rc) {
  373. case 0x03:
  374. err = "Directory error";
  375. break;
  376. case 0x0a:
  377. err = "Invalid length";
  378. break;
  379. case 0x13:
  380. err = "Buffer already exists";
  381. break;
  382. case 0x3e:
  383. err = "Buffer overlap";
  384. break;
  385. case 0x5c:
  386. err = "Paging or storage error";
  387. break;
  388. }
  389. pr_warning("Defining an interrupt buffer on CPU %i"
  390. " failed with 0x%02x (%s)\n", cpu, rc, err);
  391. return;
  392. }
  393. /* Set indication that an iucv buffer exists for this cpu. */
  394. cpu_set(cpu, iucv_buffer_cpumask);
  395. if (iucv_nonsmp_handler == 0 || cpus_empty(iucv_irq_cpumask))
  396. /* Enable iucv interrupts on this cpu. */
  397. iucv_allow_cpu(NULL);
  398. else
  399. /* Disable iucv interrupts on this cpu. */
  400. iucv_block_cpu(NULL);
  401. }
  402. /**
  403. * iucv_retrieve_cpu
  404. * @data: unused
  405. *
  406. * Retrieve interrupt buffer on this cpu.
  407. */
  408. static void iucv_retrieve_cpu(void *data)
  409. {
  410. int cpu = smp_processor_id();
  411. union iucv_param *parm;
  412. if (!cpu_isset(cpu, iucv_buffer_cpumask))
  413. return;
  414. /* Block iucv interrupts. */
  415. iucv_block_cpu(NULL);
  416. /* Retrieve interrupt buffer. */
  417. parm = iucv_param_irq[cpu];
  418. iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
  419. /* Clear indication that an iucv buffer exists for this cpu. */
  420. cpu_clear(cpu, iucv_buffer_cpumask);
  421. }
  422. /**
  423. * iucv_setmask_smp
  424. *
  425. * Allow iucv interrupts on all cpus.
  426. */
  427. static void iucv_setmask_mp(void)
  428. {
  429. int cpu;
  430. get_online_cpus();
  431. for_each_online_cpu(cpu)
  432. /* Enable all cpus with a declared buffer. */
  433. if (cpu_isset(cpu, iucv_buffer_cpumask) &&
  434. !cpu_isset(cpu, iucv_irq_cpumask))
  435. smp_call_function_single(cpu, iucv_allow_cpu,
  436. NULL, 1);
  437. put_online_cpus();
  438. }
  439. /**
  440. * iucv_setmask_up
  441. *
  442. * Allow iucv interrupts on a single cpu.
  443. */
  444. static void iucv_setmask_up(void)
  445. {
  446. cpumask_t cpumask;
  447. int cpu;
  448. /* Disable all cpu but the first in cpu_irq_cpumask. */
  449. cpumask = iucv_irq_cpumask;
  450. cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
  451. for_each_cpu_mask_nr(cpu, cpumask)
  452. smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
  453. }
  454. /**
  455. * iucv_enable
  456. *
  457. * This function makes iucv ready for use. It allocates the pathid
  458. * table, declares an iucv interrupt buffer and enables the iucv
  459. * interrupts. Called when the first user has registered an iucv
  460. * handler.
  461. */
  462. static int iucv_enable(void)
  463. {
  464. size_t alloc_size;
  465. int cpu, rc;
  466. get_online_cpus();
  467. rc = -ENOMEM;
  468. alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
  469. iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
  470. if (!iucv_path_table)
  471. goto out;
  472. /* Declare per cpu buffers. */
  473. rc = -EIO;
  474. for_each_online_cpu(cpu)
  475. smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
  476. if (cpus_empty(iucv_buffer_cpumask))
  477. /* No cpu could declare an iucv buffer. */
  478. goto out;
  479. put_online_cpus();
  480. return 0;
  481. out:
  482. kfree(iucv_path_table);
  483. iucv_path_table = NULL;
  484. put_online_cpus();
  485. return rc;
  486. }
  487. /**
  488. * iucv_disable
  489. *
  490. * This function shuts down iucv. It disables iucv interrupts, retrieves
  491. * the iucv interrupt buffer and frees the pathid table. Called after the
  492. * last user unregister its iucv handler.
  493. */
  494. static void iucv_disable(void)
  495. {
  496. get_online_cpus();
  497. on_each_cpu(iucv_retrieve_cpu, NULL, 1);
  498. kfree(iucv_path_table);
  499. iucv_path_table = NULL;
  500. put_online_cpus();
  501. }
  502. static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
  503. unsigned long action, void *hcpu)
  504. {
  505. cpumask_t cpumask;
  506. long cpu = (long) hcpu;
  507. switch (action) {
  508. case CPU_UP_PREPARE:
  509. case CPU_UP_PREPARE_FROZEN:
  510. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  511. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  512. if (!iucv_irq_data[cpu])
  513. return NOTIFY_BAD;
  514. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  515. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  516. if (!iucv_param[cpu]) {
  517. kfree(iucv_irq_data[cpu]);
  518. iucv_irq_data[cpu] = NULL;
  519. return NOTIFY_BAD;
  520. }
  521. iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
  522. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  523. if (!iucv_param_irq[cpu]) {
  524. kfree(iucv_param[cpu]);
  525. iucv_param[cpu] = NULL;
  526. kfree(iucv_irq_data[cpu]);
  527. iucv_irq_data[cpu] = NULL;
  528. return NOTIFY_BAD;
  529. }
  530. break;
  531. case CPU_UP_CANCELED:
  532. case CPU_UP_CANCELED_FROZEN:
  533. case CPU_DEAD:
  534. case CPU_DEAD_FROZEN:
  535. kfree(iucv_param_irq[cpu]);
  536. iucv_param_irq[cpu] = NULL;
  537. kfree(iucv_param[cpu]);
  538. iucv_param[cpu] = NULL;
  539. kfree(iucv_irq_data[cpu]);
  540. iucv_irq_data[cpu] = NULL;
  541. break;
  542. case CPU_ONLINE:
  543. case CPU_ONLINE_FROZEN:
  544. case CPU_DOWN_FAILED:
  545. case CPU_DOWN_FAILED_FROZEN:
  546. if (!iucv_path_table)
  547. break;
  548. smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
  549. break;
  550. case CPU_DOWN_PREPARE:
  551. case CPU_DOWN_PREPARE_FROZEN:
  552. if (!iucv_path_table)
  553. break;
  554. cpumask = iucv_buffer_cpumask;
  555. cpu_clear(cpu, cpumask);
  556. if (cpus_empty(cpumask))
  557. /* Can't offline last IUCV enabled cpu. */
  558. return NOTIFY_BAD;
  559. smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
  560. if (cpus_empty(iucv_irq_cpumask))
  561. smp_call_function_single(first_cpu(iucv_buffer_cpumask),
  562. iucv_allow_cpu, NULL, 1);
  563. break;
  564. }
  565. return NOTIFY_OK;
  566. }
  567. static struct notifier_block __refdata iucv_cpu_notifier = {
  568. .notifier_call = iucv_cpu_notify,
  569. };
  570. /**
  571. * iucv_sever_pathid
  572. * @pathid: path identification number.
  573. * @userdata: 16-bytes of user data.
  574. *
  575. * Sever an iucv path to free up the pathid. Used internally.
  576. */
  577. static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
  578. {
  579. union iucv_param *parm;
  580. parm = iucv_param_irq[smp_processor_id()];
  581. memset(parm, 0, sizeof(union iucv_param));
  582. if (userdata)
  583. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  584. parm->ctrl.ippathid = pathid;
  585. return iucv_call_b2f0(IUCV_SEVER, parm);
  586. }
  587. /**
  588. * __iucv_cleanup_queue
  589. * @dummy: unused dummy argument
  590. *
  591. * Nop function called via smp_call_function to force work items from
  592. * pending external iucv interrupts to the work queue.
  593. */
  594. static void __iucv_cleanup_queue(void *dummy)
  595. {
  596. }
  597. /**
  598. * iucv_cleanup_queue
  599. *
  600. * Function called after a path has been severed to find all remaining
  601. * work items for the now stale pathid. The caller needs to hold the
  602. * iucv_table_lock.
  603. */
  604. static void iucv_cleanup_queue(void)
  605. {
  606. struct iucv_irq_list *p, *n;
  607. /*
  608. * When a path is severed, the pathid can be reused immediatly
  609. * on a iucv connect or a connection pending interrupt. Remove
  610. * all entries from the task queue that refer to a stale pathid
  611. * (iucv_path_table[ix] == NULL). Only then do the iucv connect
  612. * or deliver the connection pending interrupt. To get all the
  613. * pending interrupts force them to the work queue by calling
  614. * an empty function on all cpus.
  615. */
  616. smp_call_function(__iucv_cleanup_queue, NULL, 1);
  617. spin_lock_irq(&iucv_queue_lock);
  618. list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
  619. /* Remove stale work items from the task queue. */
  620. if (iucv_path_table[p->data.ippathid] == NULL) {
  621. list_del(&p->list);
  622. kfree(p);
  623. }
  624. }
  625. spin_unlock_irq(&iucv_queue_lock);
  626. }
  627. /**
  628. * iucv_register:
  629. * @handler: address of iucv handler structure
  630. * @smp: != 0 indicates that the handler can deal with out of order messages
  631. *
  632. * Registers a driver with IUCV.
  633. *
  634. * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
  635. * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
  636. */
  637. int iucv_register(struct iucv_handler *handler, int smp)
  638. {
  639. int rc;
  640. if (!iucv_available)
  641. return -ENOSYS;
  642. mutex_lock(&iucv_register_mutex);
  643. if (!smp)
  644. iucv_nonsmp_handler++;
  645. if (list_empty(&iucv_handler_list)) {
  646. rc = iucv_enable();
  647. if (rc)
  648. goto out_mutex;
  649. } else if (!smp && iucv_nonsmp_handler == 1)
  650. iucv_setmask_up();
  651. INIT_LIST_HEAD(&handler->paths);
  652. spin_lock_bh(&iucv_table_lock);
  653. list_add_tail(&handler->list, &iucv_handler_list);
  654. spin_unlock_bh(&iucv_table_lock);
  655. rc = 0;
  656. out_mutex:
  657. mutex_unlock(&iucv_register_mutex);
  658. return rc;
  659. }
  660. EXPORT_SYMBOL(iucv_register);
  661. /**
  662. * iucv_unregister
  663. * @handler: address of iucv handler structure
  664. * @smp: != 0 indicates that the handler can deal with out of order messages
  665. *
  666. * Unregister driver from IUCV.
  667. */
  668. void iucv_unregister(struct iucv_handler *handler, int smp)
  669. {
  670. struct iucv_path *p, *n;
  671. mutex_lock(&iucv_register_mutex);
  672. spin_lock_bh(&iucv_table_lock);
  673. /* Remove handler from the iucv_handler_list. */
  674. list_del_init(&handler->list);
  675. /* Sever all pathids still refering to the handler. */
  676. list_for_each_entry_safe(p, n, &handler->paths, list) {
  677. iucv_sever_pathid(p->pathid, NULL);
  678. iucv_path_table[p->pathid] = NULL;
  679. list_del(&p->list);
  680. iucv_path_free(p);
  681. }
  682. spin_unlock_bh(&iucv_table_lock);
  683. if (!smp)
  684. iucv_nonsmp_handler--;
  685. if (list_empty(&iucv_handler_list))
  686. iucv_disable();
  687. else if (!smp && iucv_nonsmp_handler == 0)
  688. iucv_setmask_mp();
  689. mutex_unlock(&iucv_register_mutex);
  690. }
  691. EXPORT_SYMBOL(iucv_unregister);
  692. static int iucv_reboot_event(struct notifier_block *this,
  693. unsigned long event, void *ptr)
  694. {
  695. int i, rc;
  696. get_online_cpus();
  697. on_each_cpu(iucv_block_cpu, NULL, 1);
  698. preempt_disable();
  699. for (i = 0; i < iucv_max_pathid; i++) {
  700. if (iucv_path_table[i])
  701. rc = iucv_sever_pathid(i, NULL);
  702. }
  703. preempt_enable();
  704. put_online_cpus();
  705. iucv_disable();
  706. return NOTIFY_DONE;
  707. }
  708. static struct notifier_block iucv_reboot_notifier = {
  709. .notifier_call = iucv_reboot_event,
  710. };
  711. /**
  712. * iucv_path_accept
  713. * @path: address of iucv path structure
  714. * @handler: address of iucv handler structure
  715. * @userdata: 16 bytes of data reflected to the communication partner
  716. * @private: private data passed to interrupt handlers for this path
  717. *
  718. * This function is issued after the user received a connection pending
  719. * external interrupt and now wishes to complete the IUCV communication path.
  720. *
  721. * Returns the result of the CP IUCV call.
  722. */
  723. int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
  724. u8 userdata[16], void *private)
  725. {
  726. union iucv_param *parm;
  727. int rc;
  728. local_bh_disable();
  729. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  730. rc = -EIO;
  731. goto out;
  732. }
  733. /* Prepare parameter block. */
  734. parm = iucv_param[smp_processor_id()];
  735. memset(parm, 0, sizeof(union iucv_param));
  736. parm->ctrl.ippathid = path->pathid;
  737. parm->ctrl.ipmsglim = path->msglim;
  738. if (userdata)
  739. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  740. parm->ctrl.ipflags1 = path->flags;
  741. rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
  742. if (!rc) {
  743. path->private = private;
  744. path->msglim = parm->ctrl.ipmsglim;
  745. path->flags = parm->ctrl.ipflags1;
  746. }
  747. out:
  748. local_bh_enable();
  749. return rc;
  750. }
  751. EXPORT_SYMBOL(iucv_path_accept);
  752. /**
  753. * iucv_path_connect
  754. * @path: address of iucv path structure
  755. * @handler: address of iucv handler structure
  756. * @userid: 8-byte user identification
  757. * @system: 8-byte target system identification
  758. * @userdata: 16 bytes of data reflected to the communication partner
  759. * @private: private data passed to interrupt handlers for this path
  760. *
  761. * This function establishes an IUCV path. Although the connect may complete
  762. * successfully, you are not able to use the path until you receive an IUCV
  763. * Connection Complete external interrupt.
  764. *
  765. * Returns the result of the CP IUCV call.
  766. */
  767. int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
  768. u8 userid[8], u8 system[8], u8 userdata[16],
  769. void *private)
  770. {
  771. union iucv_param *parm;
  772. int rc;
  773. spin_lock_bh(&iucv_table_lock);
  774. iucv_cleanup_queue();
  775. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  776. rc = -EIO;
  777. goto out;
  778. }
  779. parm = iucv_param[smp_processor_id()];
  780. memset(parm, 0, sizeof(union iucv_param));
  781. parm->ctrl.ipmsglim = path->msglim;
  782. parm->ctrl.ipflags1 = path->flags;
  783. if (userid) {
  784. memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
  785. ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  786. EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  787. }
  788. if (system) {
  789. memcpy(parm->ctrl.iptarget, system,
  790. sizeof(parm->ctrl.iptarget));
  791. ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  792. EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  793. }
  794. if (userdata)
  795. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  796. rc = iucv_call_b2f0(IUCV_CONNECT, parm);
  797. if (!rc) {
  798. if (parm->ctrl.ippathid < iucv_max_pathid) {
  799. path->pathid = parm->ctrl.ippathid;
  800. path->msglim = parm->ctrl.ipmsglim;
  801. path->flags = parm->ctrl.ipflags1;
  802. path->handler = handler;
  803. path->private = private;
  804. list_add_tail(&path->list, &handler->paths);
  805. iucv_path_table[path->pathid] = path;
  806. } else {
  807. iucv_sever_pathid(parm->ctrl.ippathid,
  808. iucv_error_pathid);
  809. rc = -EIO;
  810. }
  811. }
  812. out:
  813. spin_unlock_bh(&iucv_table_lock);
  814. return rc;
  815. }
  816. EXPORT_SYMBOL(iucv_path_connect);
  817. /**
  818. * iucv_path_quiesce:
  819. * @path: address of iucv path structure
  820. * @userdata: 16 bytes of data reflected to the communication partner
  821. *
  822. * This function temporarily suspends incoming messages on an IUCV path.
  823. * You can later reactivate the path by invoking the iucv_resume function.
  824. *
  825. * Returns the result from the CP IUCV call.
  826. */
  827. int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
  828. {
  829. union iucv_param *parm;
  830. int rc;
  831. local_bh_disable();
  832. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  833. rc = -EIO;
  834. goto out;
  835. }
  836. parm = iucv_param[smp_processor_id()];
  837. memset(parm, 0, sizeof(union iucv_param));
  838. if (userdata)
  839. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  840. parm->ctrl.ippathid = path->pathid;
  841. rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
  842. out:
  843. local_bh_enable();
  844. return rc;
  845. }
  846. EXPORT_SYMBOL(iucv_path_quiesce);
  847. /**
  848. * iucv_path_resume:
  849. * @path: address of iucv path structure
  850. * @userdata: 16 bytes of data reflected to the communication partner
  851. *
  852. * This function resumes incoming messages on an IUCV path that has
  853. * been stopped with iucv_path_quiesce.
  854. *
  855. * Returns the result from the CP IUCV call.
  856. */
  857. int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
  858. {
  859. union iucv_param *parm;
  860. int rc;
  861. local_bh_disable();
  862. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  863. rc = -EIO;
  864. goto out;
  865. }
  866. parm = iucv_param[smp_processor_id()];
  867. memset(parm, 0, sizeof(union iucv_param));
  868. if (userdata)
  869. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  870. parm->ctrl.ippathid = path->pathid;
  871. rc = iucv_call_b2f0(IUCV_RESUME, parm);
  872. out:
  873. local_bh_enable();
  874. return rc;
  875. }
  876. /**
  877. * iucv_path_sever
  878. * @path: address of iucv path structure
  879. * @userdata: 16 bytes of data reflected to the communication partner
  880. *
  881. * This function terminates an IUCV path.
  882. *
  883. * Returns the result from the CP IUCV call.
  884. */
  885. int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
  886. {
  887. int rc;
  888. preempt_disable();
  889. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  890. rc = -EIO;
  891. goto out;
  892. }
  893. if (iucv_active_cpu != smp_processor_id())
  894. spin_lock_bh(&iucv_table_lock);
  895. rc = iucv_sever_pathid(path->pathid, userdata);
  896. iucv_path_table[path->pathid] = NULL;
  897. list_del_init(&path->list);
  898. if (iucv_active_cpu != smp_processor_id())
  899. spin_unlock_bh(&iucv_table_lock);
  900. out:
  901. preempt_enable();
  902. return rc;
  903. }
  904. EXPORT_SYMBOL(iucv_path_sever);
  905. /**
  906. * iucv_message_purge
  907. * @path: address of iucv path structure
  908. * @msg: address of iucv msg structure
  909. * @srccls: source class of message
  910. *
  911. * Cancels a message you have sent.
  912. *
  913. * Returns the result from the CP IUCV call.
  914. */
  915. int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
  916. u32 srccls)
  917. {
  918. union iucv_param *parm;
  919. int rc;
  920. local_bh_disable();
  921. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  922. rc = -EIO;
  923. goto out;
  924. }
  925. parm = iucv_param[smp_processor_id()];
  926. memset(parm, 0, sizeof(union iucv_param));
  927. parm->purge.ippathid = path->pathid;
  928. parm->purge.ipmsgid = msg->id;
  929. parm->purge.ipsrccls = srccls;
  930. parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
  931. rc = iucv_call_b2f0(IUCV_PURGE, parm);
  932. if (!rc) {
  933. msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
  934. msg->tag = parm->purge.ipmsgtag;
  935. }
  936. out:
  937. local_bh_enable();
  938. return rc;
  939. }
  940. EXPORT_SYMBOL(iucv_message_purge);
  941. /**
  942. * iucv_message_receive_iprmdata
  943. * @path: address of iucv path structure
  944. * @msg: address of iucv msg structure
  945. * @flags: how the message is received (IUCV_IPBUFLST)
  946. * @buffer: address of data buffer or address of struct iucv_array
  947. * @size: length of data buffer
  948. * @residual:
  949. *
  950. * Internal function used by iucv_message_receive and __iucv_message_receive
  951. * to receive RMDATA data stored in struct iucv_message.
  952. */
  953. static int iucv_message_receive_iprmdata(struct iucv_path *path,
  954. struct iucv_message *msg,
  955. u8 flags, void *buffer,
  956. size_t size, size_t *residual)
  957. {
  958. struct iucv_array *array;
  959. u8 *rmmsg;
  960. size_t copy;
  961. /*
  962. * Message is 8 bytes long and has been stored to the
  963. * message descriptor itself.
  964. */
  965. if (residual)
  966. *residual = abs(size - 8);
  967. rmmsg = msg->rmmsg;
  968. if (flags & IUCV_IPBUFLST) {
  969. /* Copy to struct iucv_array. */
  970. size = (size < 8) ? size : 8;
  971. for (array = buffer; size > 0; array++) {
  972. copy = min_t(size_t, size, array->length);
  973. memcpy((u8 *)(addr_t) array->address,
  974. rmmsg, copy);
  975. rmmsg += copy;
  976. size -= copy;
  977. }
  978. } else {
  979. /* Copy to direct buffer. */
  980. memcpy(buffer, rmmsg, min_t(size_t, size, 8));
  981. }
  982. return 0;
  983. }
  984. /**
  985. * __iucv_message_receive
  986. * @path: address of iucv path structure
  987. * @msg: address of iucv msg structure
  988. * @flags: how the message is received (IUCV_IPBUFLST)
  989. * @buffer: address of data buffer or address of struct iucv_array
  990. * @size: length of data buffer
  991. * @residual:
  992. *
  993. * This function receives messages that are being sent to you over
  994. * established paths. This function will deal with RMDATA messages
  995. * embedded in struct iucv_message as well.
  996. *
  997. * Locking: no locking
  998. *
  999. * Returns the result from the CP IUCV call.
  1000. */
  1001. int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  1002. u8 flags, void *buffer, size_t size, size_t *residual)
  1003. {
  1004. union iucv_param *parm;
  1005. int rc;
  1006. if (msg->flags & IUCV_IPRMDATA)
  1007. return iucv_message_receive_iprmdata(path, msg, flags,
  1008. buffer, size, residual);
  1009. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  1010. rc = -EIO;
  1011. goto out;
  1012. }
  1013. parm = iucv_param[smp_processor_id()];
  1014. memset(parm, 0, sizeof(union iucv_param));
  1015. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1016. parm->db.ipbfln1f = (u32) size;
  1017. parm->db.ipmsgid = msg->id;
  1018. parm->db.ippathid = path->pathid;
  1019. parm->db.iptrgcls = msg->class;
  1020. parm->db.ipflags1 = (flags | IUCV_IPFGPID |
  1021. IUCV_IPFGMID | IUCV_IPTRGCLS);
  1022. rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
  1023. if (!rc || rc == 5) {
  1024. msg->flags = parm->db.ipflags1;
  1025. if (residual)
  1026. *residual = parm->db.ipbfln1f;
  1027. }
  1028. out:
  1029. return rc;
  1030. }
  1031. EXPORT_SYMBOL(__iucv_message_receive);
  1032. /**
  1033. * iucv_message_receive
  1034. * @path: address of iucv path structure
  1035. * @msg: address of iucv msg structure
  1036. * @flags: how the message is received (IUCV_IPBUFLST)
  1037. * @buffer: address of data buffer or address of struct iucv_array
  1038. * @size: length of data buffer
  1039. * @residual:
  1040. *
  1041. * This function receives messages that are being sent to you over
  1042. * established paths. This function will deal with RMDATA messages
  1043. * embedded in struct iucv_message as well.
  1044. *
  1045. * Locking: local_bh_enable/local_bh_disable
  1046. *
  1047. * Returns the result from the CP IUCV call.
  1048. */
  1049. int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  1050. u8 flags, void *buffer, size_t size, size_t *residual)
  1051. {
  1052. int rc;
  1053. if (msg->flags & IUCV_IPRMDATA)
  1054. return iucv_message_receive_iprmdata(path, msg, flags,
  1055. buffer, size, residual);
  1056. local_bh_disable();
  1057. rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
  1058. local_bh_enable();
  1059. return rc;
  1060. }
  1061. EXPORT_SYMBOL(iucv_message_receive);
  1062. /**
  1063. * iucv_message_reject
  1064. * @path: address of iucv path structure
  1065. * @msg: address of iucv msg structure
  1066. *
  1067. * The reject function refuses a specified message. Between the time you
  1068. * are notified of a message and the time that you complete the message,
  1069. * the message may be rejected.
  1070. *
  1071. * Returns the result from the CP IUCV call.
  1072. */
  1073. int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
  1074. {
  1075. union iucv_param *parm;
  1076. int rc;
  1077. local_bh_disable();
  1078. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  1079. rc = -EIO;
  1080. goto out;
  1081. }
  1082. parm = iucv_param[smp_processor_id()];
  1083. memset(parm, 0, sizeof(union iucv_param));
  1084. parm->db.ippathid = path->pathid;
  1085. parm->db.ipmsgid = msg->id;
  1086. parm->db.iptrgcls = msg->class;
  1087. parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
  1088. rc = iucv_call_b2f0(IUCV_REJECT, parm);
  1089. out:
  1090. local_bh_enable();
  1091. return rc;
  1092. }
  1093. EXPORT_SYMBOL(iucv_message_reject);
  1094. /**
  1095. * iucv_message_reply
  1096. * @path: address of iucv path structure
  1097. * @msg: address of iucv msg structure
  1098. * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1099. * @reply: address of reply data buffer or address of struct iucv_array
  1100. * @size: length of reply data buffer
  1101. *
  1102. * This function responds to the two-way messages that you receive. You
  1103. * must identify completely the message to which you wish to reply. ie,
  1104. * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
  1105. * the parameter list.
  1106. *
  1107. * Returns the result from the CP IUCV call.
  1108. */
  1109. int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
  1110. u8 flags, void *reply, size_t size)
  1111. {
  1112. union iucv_param *parm;
  1113. int rc;
  1114. local_bh_disable();
  1115. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  1116. rc = -EIO;
  1117. goto out;
  1118. }
  1119. parm = iucv_param[smp_processor_id()];
  1120. memset(parm, 0, sizeof(union iucv_param));
  1121. if (flags & IUCV_IPRMDATA) {
  1122. parm->dpl.ippathid = path->pathid;
  1123. parm->dpl.ipflags1 = flags;
  1124. parm->dpl.ipmsgid = msg->id;
  1125. parm->dpl.iptrgcls = msg->class;
  1126. memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
  1127. } else {
  1128. parm->db.ipbfadr1 = (u32)(addr_t) reply;
  1129. parm->db.ipbfln1f = (u32) size;
  1130. parm->db.ippathid = path->pathid;
  1131. parm->db.ipflags1 = flags;
  1132. parm->db.ipmsgid = msg->id;
  1133. parm->db.iptrgcls = msg->class;
  1134. }
  1135. rc = iucv_call_b2f0(IUCV_REPLY, parm);
  1136. out:
  1137. local_bh_enable();
  1138. return rc;
  1139. }
  1140. EXPORT_SYMBOL(iucv_message_reply);
  1141. /**
  1142. * __iucv_message_send
  1143. * @path: address of iucv path structure
  1144. * @msg: address of iucv msg structure
  1145. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1146. * @srccls: source class of message
  1147. * @buffer: address of send buffer or address of struct iucv_array
  1148. * @size: length of send buffer
  1149. *
  1150. * This function transmits data to another application. Data to be
  1151. * transmitted is in a buffer and this is a one-way message and the
  1152. * receiver will not reply to the message.
  1153. *
  1154. * Locking: no locking
  1155. *
  1156. * Returns the result from the CP IUCV call.
  1157. */
  1158. int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1159. u8 flags, u32 srccls, void *buffer, size_t size)
  1160. {
  1161. union iucv_param *parm;
  1162. int rc;
  1163. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  1164. rc = -EIO;
  1165. goto out;
  1166. }
  1167. parm = iucv_param[smp_processor_id()];
  1168. memset(parm, 0, sizeof(union iucv_param));
  1169. if (flags & IUCV_IPRMDATA) {
  1170. /* Message of 8 bytes can be placed into the parameter list. */
  1171. parm->dpl.ippathid = path->pathid;
  1172. parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
  1173. parm->dpl.iptrgcls = msg->class;
  1174. parm->dpl.ipsrccls = srccls;
  1175. parm->dpl.ipmsgtag = msg->tag;
  1176. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1177. } else {
  1178. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1179. parm->db.ipbfln1f = (u32) size;
  1180. parm->db.ippathid = path->pathid;
  1181. parm->db.ipflags1 = flags | IUCV_IPNORPY;
  1182. parm->db.iptrgcls = msg->class;
  1183. parm->db.ipsrccls = srccls;
  1184. parm->db.ipmsgtag = msg->tag;
  1185. }
  1186. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1187. if (!rc)
  1188. msg->id = parm->db.ipmsgid;
  1189. out:
  1190. return rc;
  1191. }
  1192. EXPORT_SYMBOL(__iucv_message_send);
  1193. /**
  1194. * iucv_message_send
  1195. * @path: address of iucv path structure
  1196. * @msg: address of iucv msg structure
  1197. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1198. * @srccls: source class of message
  1199. * @buffer: address of send buffer or address of struct iucv_array
  1200. * @size: length of send buffer
  1201. *
  1202. * This function transmits data to another application. Data to be
  1203. * transmitted is in a buffer and this is a one-way message and the
  1204. * receiver will not reply to the message.
  1205. *
  1206. * Locking: local_bh_enable/local_bh_disable
  1207. *
  1208. * Returns the result from the CP IUCV call.
  1209. */
  1210. int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1211. u8 flags, u32 srccls, void *buffer, size_t size)
  1212. {
  1213. int rc;
  1214. local_bh_disable();
  1215. rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
  1216. local_bh_enable();
  1217. return rc;
  1218. }
  1219. EXPORT_SYMBOL(iucv_message_send);
  1220. /**
  1221. * iucv_message_send2way
  1222. * @path: address of iucv path structure
  1223. * @msg: address of iucv msg structure
  1224. * @flags: how the message is sent and the reply is received
  1225. * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
  1226. * @srccls: source class of message
  1227. * @buffer: address of send buffer or address of struct iucv_array
  1228. * @size: length of send buffer
  1229. * @ansbuf: address of answer buffer or address of struct iucv_array
  1230. * @asize: size of reply buffer
  1231. *
  1232. * This function transmits data to another application. Data to be
  1233. * transmitted is in a buffer. The receiver of the send is expected to
  1234. * reply to the message and a buffer is provided into which IUCV moves
  1235. * the reply to this message.
  1236. *
  1237. * Returns the result from the CP IUCV call.
  1238. */
  1239. int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
  1240. u8 flags, u32 srccls, void *buffer, size_t size,
  1241. void *answer, size_t asize, size_t *residual)
  1242. {
  1243. union iucv_param *parm;
  1244. int rc;
  1245. local_bh_disable();
  1246. if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
  1247. rc = -EIO;
  1248. goto out;
  1249. }
  1250. parm = iucv_param[smp_processor_id()];
  1251. memset(parm, 0, sizeof(union iucv_param));
  1252. if (flags & IUCV_IPRMDATA) {
  1253. parm->dpl.ippathid = path->pathid;
  1254. parm->dpl.ipflags1 = path->flags; /* priority message */
  1255. parm->dpl.iptrgcls = msg->class;
  1256. parm->dpl.ipsrccls = srccls;
  1257. parm->dpl.ipmsgtag = msg->tag;
  1258. parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
  1259. parm->dpl.ipbfln2f = (u32) asize;
  1260. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1261. } else {
  1262. parm->db.ippathid = path->pathid;
  1263. parm->db.ipflags1 = path->flags; /* priority message */
  1264. parm->db.iptrgcls = msg->class;
  1265. parm->db.ipsrccls = srccls;
  1266. parm->db.ipmsgtag = msg->tag;
  1267. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1268. parm->db.ipbfln1f = (u32) size;
  1269. parm->db.ipbfadr2 = (u32)(addr_t) answer;
  1270. parm->db.ipbfln2f = (u32) asize;
  1271. }
  1272. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1273. if (!rc)
  1274. msg->id = parm->db.ipmsgid;
  1275. out:
  1276. local_bh_enable();
  1277. return rc;
  1278. }
  1279. EXPORT_SYMBOL(iucv_message_send2way);
  1280. /**
  1281. * iucv_path_pending
  1282. * @data: Pointer to external interrupt buffer
  1283. *
  1284. * Process connection pending work item. Called from tasklet while holding
  1285. * iucv_table_lock.
  1286. */
  1287. struct iucv_path_pending {
  1288. u16 ippathid;
  1289. u8 ipflags1;
  1290. u8 iptype;
  1291. u16 ipmsglim;
  1292. u16 res1;
  1293. u8 ipvmid[8];
  1294. u8 ipuser[16];
  1295. u32 res3;
  1296. u8 ippollfg;
  1297. u8 res4[3];
  1298. } __attribute__ ((packed));
  1299. static void iucv_path_pending(struct iucv_irq_data *data)
  1300. {
  1301. struct iucv_path_pending *ipp = (void *) data;
  1302. struct iucv_handler *handler;
  1303. struct iucv_path *path;
  1304. char *error;
  1305. BUG_ON(iucv_path_table[ipp->ippathid]);
  1306. /* New pathid, handler found. Create a new path struct. */
  1307. error = iucv_error_no_memory;
  1308. path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
  1309. if (!path)
  1310. goto out_sever;
  1311. path->pathid = ipp->ippathid;
  1312. iucv_path_table[path->pathid] = path;
  1313. EBCASC(ipp->ipvmid, 8);
  1314. /* Call registered handler until one is found that wants the path. */
  1315. list_for_each_entry(handler, &iucv_handler_list, list) {
  1316. if (!handler->path_pending)
  1317. continue;
  1318. /*
  1319. * Add path to handler to allow a call to iucv_path_sever
  1320. * inside the path_pending function. If the handler returns
  1321. * an error remove the path from the handler again.
  1322. */
  1323. list_add(&path->list, &handler->paths);
  1324. path->handler = handler;
  1325. if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
  1326. return;
  1327. list_del(&path->list);
  1328. path->handler = NULL;
  1329. }
  1330. /* No handler wanted the path. */
  1331. iucv_path_table[path->pathid] = NULL;
  1332. iucv_path_free(path);
  1333. error = iucv_error_no_listener;
  1334. out_sever:
  1335. iucv_sever_pathid(ipp->ippathid, error);
  1336. }
  1337. /**
  1338. * iucv_path_complete
  1339. * @data: Pointer to external interrupt buffer
  1340. *
  1341. * Process connection complete work item. Called from tasklet while holding
  1342. * iucv_table_lock.
  1343. */
  1344. struct iucv_path_complete {
  1345. u16 ippathid;
  1346. u8 ipflags1;
  1347. u8 iptype;
  1348. u16 ipmsglim;
  1349. u16 res1;
  1350. u8 res2[8];
  1351. u8 ipuser[16];
  1352. u32 res3;
  1353. u8 ippollfg;
  1354. u8 res4[3];
  1355. } __attribute__ ((packed));
  1356. static void iucv_path_complete(struct iucv_irq_data *data)
  1357. {
  1358. struct iucv_path_complete *ipc = (void *) data;
  1359. struct iucv_path *path = iucv_path_table[ipc->ippathid];
  1360. if (path)
  1361. path->flags = ipc->ipflags1;
  1362. if (path && path->handler && path->handler->path_complete)
  1363. path->handler->path_complete(path, ipc->ipuser);
  1364. }
  1365. /**
  1366. * iucv_path_severed
  1367. * @data: Pointer to external interrupt buffer
  1368. *
  1369. * Process connection severed work item. Called from tasklet while holding
  1370. * iucv_table_lock.
  1371. */
  1372. struct iucv_path_severed {
  1373. u16 ippathid;
  1374. u8 res1;
  1375. u8 iptype;
  1376. u32 res2;
  1377. u8 res3[8];
  1378. u8 ipuser[16];
  1379. u32 res4;
  1380. u8 ippollfg;
  1381. u8 res5[3];
  1382. } __attribute__ ((packed));
  1383. static void iucv_path_severed(struct iucv_irq_data *data)
  1384. {
  1385. struct iucv_path_severed *ips = (void *) data;
  1386. struct iucv_path *path = iucv_path_table[ips->ippathid];
  1387. if (!path || !path->handler) /* Already severed */
  1388. return;
  1389. if (path->handler->path_severed)
  1390. path->handler->path_severed(path, ips->ipuser);
  1391. else {
  1392. iucv_sever_pathid(path->pathid, NULL);
  1393. iucv_path_table[path->pathid] = NULL;
  1394. list_del(&path->list);
  1395. iucv_path_free(path);
  1396. }
  1397. }
  1398. /**
  1399. * iucv_path_quiesced
  1400. * @data: Pointer to external interrupt buffer
  1401. *
  1402. * Process connection quiesced work item. Called from tasklet while holding
  1403. * iucv_table_lock.
  1404. */
  1405. struct iucv_path_quiesced {
  1406. u16 ippathid;
  1407. u8 res1;
  1408. u8 iptype;
  1409. u32 res2;
  1410. u8 res3[8];
  1411. u8 ipuser[16];
  1412. u32 res4;
  1413. u8 ippollfg;
  1414. u8 res5[3];
  1415. } __attribute__ ((packed));
  1416. static void iucv_path_quiesced(struct iucv_irq_data *data)
  1417. {
  1418. struct iucv_path_quiesced *ipq = (void *) data;
  1419. struct iucv_path *path = iucv_path_table[ipq->ippathid];
  1420. if (path && path->handler && path->handler->path_quiesced)
  1421. path->handler->path_quiesced(path, ipq->ipuser);
  1422. }
  1423. /**
  1424. * iucv_path_resumed
  1425. * @data: Pointer to external interrupt buffer
  1426. *
  1427. * Process connection resumed work item. Called from tasklet while holding
  1428. * iucv_table_lock.
  1429. */
  1430. struct iucv_path_resumed {
  1431. u16 ippathid;
  1432. u8 res1;
  1433. u8 iptype;
  1434. u32 res2;
  1435. u8 res3[8];
  1436. u8 ipuser[16];
  1437. u32 res4;
  1438. u8 ippollfg;
  1439. u8 res5[3];
  1440. } __attribute__ ((packed));
  1441. static void iucv_path_resumed(struct iucv_irq_data *data)
  1442. {
  1443. struct iucv_path_resumed *ipr = (void *) data;
  1444. struct iucv_path *path = iucv_path_table[ipr->ippathid];
  1445. if (path && path->handler && path->handler->path_resumed)
  1446. path->handler->path_resumed(path, ipr->ipuser);
  1447. }
  1448. /**
  1449. * iucv_message_complete
  1450. * @data: Pointer to external interrupt buffer
  1451. *
  1452. * Process message complete work item. Called from tasklet while holding
  1453. * iucv_table_lock.
  1454. */
  1455. struct iucv_message_complete {
  1456. u16 ippathid;
  1457. u8 ipflags1;
  1458. u8 iptype;
  1459. u32 ipmsgid;
  1460. u32 ipaudit;
  1461. u8 iprmmsg[8];
  1462. u32 ipsrccls;
  1463. u32 ipmsgtag;
  1464. u32 res;
  1465. u32 ipbfln2f;
  1466. u8 ippollfg;
  1467. u8 res2[3];
  1468. } __attribute__ ((packed));
  1469. static void iucv_message_complete(struct iucv_irq_data *data)
  1470. {
  1471. struct iucv_message_complete *imc = (void *) data;
  1472. struct iucv_path *path = iucv_path_table[imc->ippathid];
  1473. struct iucv_message msg;
  1474. if (path && path->handler && path->handler->message_complete) {
  1475. msg.flags = imc->ipflags1;
  1476. msg.id = imc->ipmsgid;
  1477. msg.audit = imc->ipaudit;
  1478. memcpy(msg.rmmsg, imc->iprmmsg, 8);
  1479. msg.class = imc->ipsrccls;
  1480. msg.tag = imc->ipmsgtag;
  1481. msg.length = imc->ipbfln2f;
  1482. path->handler->message_complete(path, &msg);
  1483. }
  1484. }
  1485. /**
  1486. * iucv_message_pending
  1487. * @data: Pointer to external interrupt buffer
  1488. *
  1489. * Process message pending work item. Called from tasklet while holding
  1490. * iucv_table_lock.
  1491. */
  1492. struct iucv_message_pending {
  1493. u16 ippathid;
  1494. u8 ipflags1;
  1495. u8 iptype;
  1496. u32 ipmsgid;
  1497. u32 iptrgcls;
  1498. union {
  1499. u32 iprmmsg1_u32;
  1500. u8 iprmmsg1[4];
  1501. } ln1msg1;
  1502. union {
  1503. u32 ipbfln1f;
  1504. u8 iprmmsg2[4];
  1505. } ln1msg2;
  1506. u32 res1[3];
  1507. u32 ipbfln2f;
  1508. u8 ippollfg;
  1509. u8 res2[3];
  1510. } __attribute__ ((packed));
  1511. static void iucv_message_pending(struct iucv_irq_data *data)
  1512. {
  1513. struct iucv_message_pending *imp = (void *) data;
  1514. struct iucv_path *path = iucv_path_table[imp->ippathid];
  1515. struct iucv_message msg;
  1516. if (path && path->handler && path->handler->message_pending) {
  1517. msg.flags = imp->ipflags1;
  1518. msg.id = imp->ipmsgid;
  1519. msg.class = imp->iptrgcls;
  1520. if (imp->ipflags1 & IUCV_IPRMDATA) {
  1521. memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
  1522. msg.length = 8;
  1523. } else
  1524. msg.length = imp->ln1msg2.ipbfln1f;
  1525. msg.reply_size = imp->ipbfln2f;
  1526. path->handler->message_pending(path, &msg);
  1527. }
  1528. }
  1529. /**
  1530. * iucv_tasklet_fn:
  1531. *
  1532. * This tasklet loops over the queue of irq buffers created by
  1533. * iucv_external_interrupt, calls the appropriate action handler
  1534. * and then frees the buffer.
  1535. */
  1536. static void iucv_tasklet_fn(unsigned long ignored)
  1537. {
  1538. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1539. static iucv_irq_fn *irq_fn[] = {
  1540. [0x02] = iucv_path_complete,
  1541. [0x03] = iucv_path_severed,
  1542. [0x04] = iucv_path_quiesced,
  1543. [0x05] = iucv_path_resumed,
  1544. [0x06] = iucv_message_complete,
  1545. [0x07] = iucv_message_complete,
  1546. [0x08] = iucv_message_pending,
  1547. [0x09] = iucv_message_pending,
  1548. };
  1549. LIST_HEAD(task_queue);
  1550. struct iucv_irq_list *p, *n;
  1551. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1552. if (!spin_trylock(&iucv_table_lock)) {
  1553. tasklet_schedule(&iucv_tasklet);
  1554. return;
  1555. }
  1556. iucv_active_cpu = smp_processor_id();
  1557. spin_lock_irq(&iucv_queue_lock);
  1558. list_splice_init(&iucv_task_queue, &task_queue);
  1559. spin_unlock_irq(&iucv_queue_lock);
  1560. list_for_each_entry_safe(p, n, &task_queue, list) {
  1561. list_del_init(&p->list);
  1562. irq_fn[p->data.iptype](&p->data);
  1563. kfree(p);
  1564. }
  1565. iucv_active_cpu = -1;
  1566. spin_unlock(&iucv_table_lock);
  1567. }
  1568. /**
  1569. * iucv_work_fn:
  1570. *
  1571. * This work function loops over the queue of path pending irq blocks
  1572. * created by iucv_external_interrupt, calls the appropriate action
  1573. * handler and then frees the buffer.
  1574. */
  1575. static void iucv_work_fn(struct work_struct *work)
  1576. {
  1577. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1578. LIST_HEAD(work_queue);
  1579. struct iucv_irq_list *p, *n;
  1580. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1581. spin_lock_bh(&iucv_table_lock);
  1582. iucv_active_cpu = smp_processor_id();
  1583. spin_lock_irq(&iucv_queue_lock);
  1584. list_splice_init(&iucv_work_queue, &work_queue);
  1585. spin_unlock_irq(&iucv_queue_lock);
  1586. iucv_cleanup_queue();
  1587. list_for_each_entry_safe(p, n, &work_queue, list) {
  1588. list_del_init(&p->list);
  1589. iucv_path_pending(&p->data);
  1590. kfree(p);
  1591. }
  1592. iucv_active_cpu = -1;
  1593. spin_unlock_bh(&iucv_table_lock);
  1594. }
  1595. /**
  1596. * iucv_external_interrupt
  1597. * @code: irq code
  1598. *
  1599. * Handles external interrupts coming in from CP.
  1600. * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
  1601. */
  1602. static void iucv_external_interrupt(u16 code)
  1603. {
  1604. struct iucv_irq_data *p;
  1605. struct iucv_irq_list *work;
  1606. p = iucv_irq_data[smp_processor_id()];
  1607. if (p->ippathid >= iucv_max_pathid) {
  1608. WARN_ON(p->ippathid >= iucv_max_pathid);
  1609. iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
  1610. return;
  1611. }
  1612. BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
  1613. work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
  1614. if (!work) {
  1615. pr_warning("iucv_external_interrupt: out of memory\n");
  1616. return;
  1617. }
  1618. memcpy(&work->data, p, sizeof(work->data));
  1619. spin_lock(&iucv_queue_lock);
  1620. if (p->iptype == 0x01) {
  1621. /* Path pending interrupt. */
  1622. list_add_tail(&work->list, &iucv_work_queue);
  1623. schedule_work(&iucv_work);
  1624. } else {
  1625. /* The other interrupts. */
  1626. list_add_tail(&work->list, &iucv_task_queue);
  1627. tasklet_schedule(&iucv_tasklet);
  1628. }
  1629. spin_unlock(&iucv_queue_lock);
  1630. }
  1631. /**
  1632. * iucv_init
  1633. *
  1634. * Allocates and initializes various data structures.
  1635. */
  1636. static int __init iucv_init(void)
  1637. {
  1638. int rc;
  1639. int cpu;
  1640. if (!MACHINE_IS_VM) {
  1641. rc = -EPROTONOSUPPORT;
  1642. goto out;
  1643. }
  1644. rc = iucv_query_maxconn();
  1645. if (rc)
  1646. goto out;
  1647. rc = register_external_interrupt(0x4000, iucv_external_interrupt);
  1648. if (rc)
  1649. goto out;
  1650. iucv_root = root_device_register("iucv");
  1651. if (IS_ERR(iucv_root)) {
  1652. rc = PTR_ERR(iucv_root);
  1653. goto out_int;
  1654. }
  1655. for_each_online_cpu(cpu) {
  1656. /* Note: GFP_DMA used to get memory below 2G */
  1657. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  1658. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1659. if (!iucv_irq_data[cpu]) {
  1660. rc = -ENOMEM;
  1661. goto out_free;
  1662. }
  1663. /* Allocate parameter blocks. */
  1664. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  1665. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1666. if (!iucv_param[cpu]) {
  1667. rc = -ENOMEM;
  1668. goto out_free;
  1669. }
  1670. iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
  1671. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1672. if (!iucv_param_irq[cpu]) {
  1673. rc = -ENOMEM;
  1674. goto out_free;
  1675. }
  1676. }
  1677. rc = register_hotcpu_notifier(&iucv_cpu_notifier);
  1678. if (rc)
  1679. goto out_free;
  1680. rc = register_reboot_notifier(&iucv_reboot_notifier);
  1681. if (rc)
  1682. goto out_cpu;
  1683. ASCEBC(iucv_error_no_listener, 16);
  1684. ASCEBC(iucv_error_no_memory, 16);
  1685. ASCEBC(iucv_error_pathid, 16);
  1686. iucv_available = 1;
  1687. rc = bus_register(&iucv_bus);
  1688. if (rc)
  1689. goto out_reboot;
  1690. return 0;
  1691. out_reboot:
  1692. unregister_reboot_notifier(&iucv_reboot_notifier);
  1693. out_cpu:
  1694. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1695. out_free:
  1696. for_each_possible_cpu(cpu) {
  1697. kfree(iucv_param_irq[cpu]);
  1698. iucv_param_irq[cpu] = NULL;
  1699. kfree(iucv_param[cpu]);
  1700. iucv_param[cpu] = NULL;
  1701. kfree(iucv_irq_data[cpu]);
  1702. iucv_irq_data[cpu] = NULL;
  1703. }
  1704. root_device_unregister(iucv_root);
  1705. out_int:
  1706. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1707. out:
  1708. return rc;
  1709. }
  1710. /**
  1711. * iucv_exit
  1712. *
  1713. * Frees everything allocated from iucv_init.
  1714. */
  1715. static void __exit iucv_exit(void)
  1716. {
  1717. struct iucv_irq_list *p, *n;
  1718. int cpu;
  1719. spin_lock_irq(&iucv_queue_lock);
  1720. list_for_each_entry_safe(p, n, &iucv_task_queue, list)
  1721. kfree(p);
  1722. list_for_each_entry_safe(p, n, &iucv_work_queue, list)
  1723. kfree(p);
  1724. spin_unlock_irq(&iucv_queue_lock);
  1725. unregister_reboot_notifier(&iucv_reboot_notifier);
  1726. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1727. for_each_possible_cpu(cpu) {
  1728. kfree(iucv_param_irq[cpu]);
  1729. iucv_param_irq[cpu] = NULL;
  1730. kfree(iucv_param[cpu]);
  1731. iucv_param[cpu] = NULL;
  1732. kfree(iucv_irq_data[cpu]);
  1733. iucv_irq_data[cpu] = NULL;
  1734. }
  1735. root_device_unregister(iucv_root);
  1736. bus_unregister(&iucv_bus);
  1737. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1738. }
  1739. subsys_initcall(iucv_init);
  1740. module_exit(iucv_exit);
  1741. MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
  1742. MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
  1743. MODULE_LICENSE("GPL");