iucv.c 45 KB

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