iucv.c 43 KB

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