iucv.c 49 KB

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