iucv.c 48 KB

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