iucv.c 48 KB

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