iucv.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  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. rc = -ENOMEM;
  465. alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
  466. iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
  467. if (!iucv_path_table)
  468. goto out;
  469. /* Declare per cpu buffers. */
  470. rc = -EIO;
  471. get_online_cpus();
  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_path;
  477. put_online_cpus();
  478. return 0;
  479. out_path:
  480. put_online_cpus();
  481. kfree(iucv_path_table);
  482. out:
  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. put_online_cpus();
  497. kfree(iucv_path_table);
  498. }
  499. static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
  500. unsigned long action, void *hcpu)
  501. {
  502. cpumask_t cpumask;
  503. long cpu = (long) hcpu;
  504. switch (action) {
  505. case CPU_UP_PREPARE:
  506. case CPU_UP_PREPARE_FROZEN:
  507. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  508. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  509. if (!iucv_irq_data[cpu])
  510. return NOTIFY_BAD;
  511. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  512. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  513. if (!iucv_param[cpu]) {
  514. kfree(iucv_irq_data[cpu]);
  515. iucv_irq_data[cpu] = NULL;
  516. return NOTIFY_BAD;
  517. }
  518. break;
  519. case CPU_UP_CANCELED:
  520. case CPU_UP_CANCELED_FROZEN:
  521. case CPU_DEAD:
  522. case CPU_DEAD_FROZEN:
  523. kfree(iucv_param[cpu]);
  524. iucv_param[cpu] = NULL;
  525. kfree(iucv_irq_data[cpu]);
  526. iucv_irq_data[cpu] = NULL;
  527. break;
  528. case CPU_ONLINE:
  529. case CPU_ONLINE_FROZEN:
  530. case CPU_DOWN_FAILED:
  531. case CPU_DOWN_FAILED_FROZEN:
  532. smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
  533. break;
  534. case CPU_DOWN_PREPARE:
  535. case CPU_DOWN_PREPARE_FROZEN:
  536. cpumask = iucv_buffer_cpumask;
  537. cpu_clear(cpu, cpumask);
  538. if (cpus_empty(cpumask))
  539. /* Can't offline last IUCV enabled cpu. */
  540. return NOTIFY_BAD;
  541. smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
  542. if (cpus_empty(iucv_irq_cpumask))
  543. smp_call_function_single(first_cpu(iucv_buffer_cpumask),
  544. iucv_allow_cpu, NULL, 1);
  545. break;
  546. }
  547. return NOTIFY_OK;
  548. }
  549. static struct notifier_block __refdata iucv_cpu_notifier = {
  550. .notifier_call = iucv_cpu_notify,
  551. };
  552. /**
  553. * iucv_sever_pathid
  554. * @pathid: path identification number.
  555. * @userdata: 16-bytes of user data.
  556. *
  557. * Sever an iucv path to free up the pathid. Used internally.
  558. */
  559. static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
  560. {
  561. union iucv_param *parm;
  562. parm = iucv_param[smp_processor_id()];
  563. memset(parm, 0, sizeof(union iucv_param));
  564. if (userdata)
  565. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  566. parm->ctrl.ippathid = pathid;
  567. return iucv_call_b2f0(IUCV_SEVER, parm);
  568. }
  569. /**
  570. * __iucv_cleanup_queue
  571. * @dummy: unused dummy argument
  572. *
  573. * Nop function called via smp_call_function to force work items from
  574. * pending external iucv interrupts to the work queue.
  575. */
  576. static void __iucv_cleanup_queue(void *dummy)
  577. {
  578. }
  579. /**
  580. * iucv_cleanup_queue
  581. *
  582. * Function called after a path has been severed to find all remaining
  583. * work items for the now stale pathid. The caller needs to hold the
  584. * iucv_table_lock.
  585. */
  586. static void iucv_cleanup_queue(void)
  587. {
  588. struct iucv_irq_list *p, *n;
  589. /*
  590. * When a path is severed, the pathid can be reused immediatly
  591. * on a iucv connect or a connection pending interrupt. Remove
  592. * all entries from the task queue that refer to a stale pathid
  593. * (iucv_path_table[ix] == NULL). Only then do the iucv connect
  594. * or deliver the connection pending interrupt. To get all the
  595. * pending interrupts force them to the work queue by calling
  596. * an empty function on all cpus.
  597. */
  598. smp_call_function(__iucv_cleanup_queue, NULL, 1);
  599. spin_lock_irq(&iucv_queue_lock);
  600. list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
  601. /* Remove stale work items from the task queue. */
  602. if (iucv_path_table[p->data.ippathid] == NULL) {
  603. list_del(&p->list);
  604. kfree(p);
  605. }
  606. }
  607. spin_unlock_irq(&iucv_queue_lock);
  608. }
  609. /**
  610. * iucv_register:
  611. * @handler: address of iucv handler structure
  612. * @smp: != 0 indicates that the handler can deal with out of order messages
  613. *
  614. * Registers a driver with IUCV.
  615. *
  616. * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
  617. * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
  618. */
  619. int iucv_register(struct iucv_handler *handler, int smp)
  620. {
  621. int rc;
  622. if (!iucv_available)
  623. return -ENOSYS;
  624. mutex_lock(&iucv_register_mutex);
  625. if (!smp)
  626. iucv_nonsmp_handler++;
  627. if (list_empty(&iucv_handler_list)) {
  628. rc = iucv_enable();
  629. if (rc)
  630. goto out_mutex;
  631. } else if (!smp && iucv_nonsmp_handler == 1)
  632. iucv_setmask_up();
  633. INIT_LIST_HEAD(&handler->paths);
  634. spin_lock_bh(&iucv_table_lock);
  635. list_add_tail(&handler->list, &iucv_handler_list);
  636. spin_unlock_bh(&iucv_table_lock);
  637. rc = 0;
  638. out_mutex:
  639. mutex_unlock(&iucv_register_mutex);
  640. return rc;
  641. }
  642. EXPORT_SYMBOL(iucv_register);
  643. /**
  644. * iucv_unregister
  645. * @handler: address of iucv handler structure
  646. * @smp: != 0 indicates that the handler can deal with out of order messages
  647. *
  648. * Unregister driver from IUCV.
  649. */
  650. void iucv_unregister(struct iucv_handler *handler, int smp)
  651. {
  652. struct iucv_path *p, *n;
  653. mutex_lock(&iucv_register_mutex);
  654. spin_lock_bh(&iucv_table_lock);
  655. /* Remove handler from the iucv_handler_list. */
  656. list_del_init(&handler->list);
  657. /* Sever all pathids still refering to the handler. */
  658. list_for_each_entry_safe(p, n, &handler->paths, list) {
  659. iucv_sever_pathid(p->pathid, NULL);
  660. iucv_path_table[p->pathid] = NULL;
  661. list_del(&p->list);
  662. iucv_path_free(p);
  663. }
  664. spin_unlock_bh(&iucv_table_lock);
  665. if (!smp)
  666. iucv_nonsmp_handler--;
  667. if (list_empty(&iucv_handler_list))
  668. iucv_disable();
  669. else if (!smp && iucv_nonsmp_handler == 0)
  670. iucv_setmask_mp();
  671. mutex_unlock(&iucv_register_mutex);
  672. }
  673. EXPORT_SYMBOL(iucv_unregister);
  674. /**
  675. * iucv_path_accept
  676. * @path: address of iucv path structure
  677. * @handler: address of iucv handler structure
  678. * @userdata: 16 bytes of data reflected to the communication partner
  679. * @private: private data passed to interrupt handlers for this path
  680. *
  681. * This function is issued after the user received a connection pending
  682. * external interrupt and now wishes to complete the IUCV communication path.
  683. *
  684. * Returns the result of the CP IUCV call.
  685. */
  686. int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
  687. u8 userdata[16], void *private)
  688. {
  689. union iucv_param *parm;
  690. int rc;
  691. local_bh_disable();
  692. /* Prepare parameter block. */
  693. parm = iucv_param[smp_processor_id()];
  694. memset(parm, 0, sizeof(union iucv_param));
  695. parm->ctrl.ippathid = path->pathid;
  696. parm->ctrl.ipmsglim = path->msglim;
  697. if (userdata)
  698. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  699. parm->ctrl.ipflags1 = path->flags;
  700. rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
  701. if (!rc) {
  702. path->private = private;
  703. path->msglim = parm->ctrl.ipmsglim;
  704. path->flags = parm->ctrl.ipflags1;
  705. }
  706. local_bh_enable();
  707. return rc;
  708. }
  709. EXPORT_SYMBOL(iucv_path_accept);
  710. /**
  711. * iucv_path_connect
  712. * @path: address of iucv path structure
  713. * @handler: address of iucv handler structure
  714. * @userid: 8-byte user identification
  715. * @system: 8-byte target system identification
  716. * @userdata: 16 bytes of data reflected to the communication partner
  717. * @private: private data passed to interrupt handlers for this path
  718. *
  719. * This function establishes an IUCV path. Although the connect may complete
  720. * successfully, you are not able to use the path until you receive an IUCV
  721. * Connection Complete external interrupt.
  722. *
  723. * Returns the result of the CP IUCV call.
  724. */
  725. int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
  726. u8 userid[8], u8 system[8], u8 userdata[16],
  727. void *private)
  728. {
  729. union iucv_param *parm;
  730. int rc;
  731. spin_lock_bh(&iucv_table_lock);
  732. iucv_cleanup_queue();
  733. parm = iucv_param[smp_processor_id()];
  734. memset(parm, 0, sizeof(union iucv_param));
  735. parm->ctrl.ipmsglim = path->msglim;
  736. parm->ctrl.ipflags1 = path->flags;
  737. if (userid) {
  738. memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
  739. ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  740. EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  741. }
  742. if (system) {
  743. memcpy(parm->ctrl.iptarget, system,
  744. sizeof(parm->ctrl.iptarget));
  745. ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  746. EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  747. }
  748. if (userdata)
  749. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  750. rc = iucv_call_b2f0(IUCV_CONNECT, parm);
  751. if (!rc) {
  752. if (parm->ctrl.ippathid < iucv_max_pathid) {
  753. path->pathid = parm->ctrl.ippathid;
  754. path->msglim = parm->ctrl.ipmsglim;
  755. path->flags = parm->ctrl.ipflags1;
  756. path->handler = handler;
  757. path->private = private;
  758. list_add_tail(&path->list, &handler->paths);
  759. iucv_path_table[path->pathid] = path;
  760. } else {
  761. iucv_sever_pathid(parm->ctrl.ippathid,
  762. iucv_error_pathid);
  763. rc = -EIO;
  764. }
  765. }
  766. spin_unlock_bh(&iucv_table_lock);
  767. return rc;
  768. }
  769. EXPORT_SYMBOL(iucv_path_connect);
  770. /**
  771. * iucv_path_quiesce:
  772. * @path: address of iucv path structure
  773. * @userdata: 16 bytes of data reflected to the communication partner
  774. *
  775. * This function temporarily suspends incoming messages on an IUCV path.
  776. * You can later reactivate the path by invoking the iucv_resume function.
  777. *
  778. * Returns the result from the CP IUCV call.
  779. */
  780. int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
  781. {
  782. union iucv_param *parm;
  783. int rc;
  784. local_bh_disable();
  785. parm = iucv_param[smp_processor_id()];
  786. memset(parm, 0, sizeof(union iucv_param));
  787. if (userdata)
  788. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  789. parm->ctrl.ippathid = path->pathid;
  790. rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
  791. local_bh_enable();
  792. return rc;
  793. }
  794. EXPORT_SYMBOL(iucv_path_quiesce);
  795. /**
  796. * iucv_path_resume:
  797. * @path: address of iucv path structure
  798. * @userdata: 16 bytes of data reflected to the communication partner
  799. *
  800. * This function resumes incoming messages on an IUCV path that has
  801. * been stopped with iucv_path_quiesce.
  802. *
  803. * Returns the result from the CP IUCV call.
  804. */
  805. int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
  806. {
  807. union iucv_param *parm;
  808. int rc;
  809. local_bh_disable();
  810. parm = iucv_param[smp_processor_id()];
  811. memset(parm, 0, sizeof(union iucv_param));
  812. if (userdata)
  813. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  814. parm->ctrl.ippathid = path->pathid;
  815. rc = iucv_call_b2f0(IUCV_RESUME, parm);
  816. local_bh_enable();
  817. return rc;
  818. }
  819. /**
  820. * iucv_path_sever
  821. * @path: address of iucv path structure
  822. * @userdata: 16 bytes of data reflected to the communication partner
  823. *
  824. * This function terminates an IUCV path.
  825. *
  826. * Returns the result from the CP IUCV call.
  827. */
  828. int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
  829. {
  830. int rc;
  831. preempt_disable();
  832. if (iucv_active_cpu != smp_processor_id())
  833. spin_lock_bh(&iucv_table_lock);
  834. rc = iucv_sever_pathid(path->pathid, userdata);
  835. if (!rc) {
  836. iucv_path_table[path->pathid] = NULL;
  837. list_del_init(&path->list);
  838. }
  839. if (iucv_active_cpu != smp_processor_id())
  840. spin_unlock_bh(&iucv_table_lock);
  841. preempt_enable();
  842. return rc;
  843. }
  844. EXPORT_SYMBOL(iucv_path_sever);
  845. /**
  846. * iucv_message_purge
  847. * @path: address of iucv path structure
  848. * @msg: address of iucv msg structure
  849. * @srccls: source class of message
  850. *
  851. * Cancels a message you have sent.
  852. *
  853. * Returns the result from the CP IUCV call.
  854. */
  855. int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
  856. u32 srccls)
  857. {
  858. union iucv_param *parm;
  859. int rc;
  860. local_bh_disable();
  861. parm = iucv_param[smp_processor_id()];
  862. memset(parm, 0, sizeof(union iucv_param));
  863. parm->purge.ippathid = path->pathid;
  864. parm->purge.ipmsgid = msg->id;
  865. parm->purge.ipsrccls = srccls;
  866. parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
  867. rc = iucv_call_b2f0(IUCV_PURGE, parm);
  868. if (!rc) {
  869. msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
  870. msg->tag = parm->purge.ipmsgtag;
  871. }
  872. local_bh_enable();
  873. return rc;
  874. }
  875. EXPORT_SYMBOL(iucv_message_purge);
  876. /**
  877. * iucv_message_receive_iprmdata
  878. * @path: address of iucv path structure
  879. * @msg: address of iucv msg structure
  880. * @flags: how the message is received (IUCV_IPBUFLST)
  881. * @buffer: address of data buffer or address of struct iucv_array
  882. * @size: length of data buffer
  883. * @residual:
  884. *
  885. * Internal function used by iucv_message_receive and __iucv_message_receive
  886. * to receive RMDATA data stored in struct iucv_message.
  887. */
  888. static int iucv_message_receive_iprmdata(struct iucv_path *path,
  889. struct iucv_message *msg,
  890. u8 flags, void *buffer,
  891. size_t size, size_t *residual)
  892. {
  893. struct iucv_array *array;
  894. u8 *rmmsg;
  895. size_t copy;
  896. /*
  897. * Message is 8 bytes long and has been stored to the
  898. * message descriptor itself.
  899. */
  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. /**
  920. * __iucv_message_receive
  921. * @path: address of iucv path structure
  922. * @msg: address of iucv msg structure
  923. * @flags: how the message is received (IUCV_IPBUFLST)
  924. * @buffer: address of data buffer or address of struct iucv_array
  925. * @size: length of data buffer
  926. * @residual:
  927. *
  928. * This function receives messages that are being sent to you over
  929. * established paths. This function will deal with RMDATA messages
  930. * embedded in struct iucv_message as well.
  931. *
  932. * Locking: no locking
  933. *
  934. * Returns the result from the CP IUCV call.
  935. */
  936. int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  937. u8 flags, void *buffer, size_t size, size_t *residual)
  938. {
  939. union iucv_param *parm;
  940. int rc;
  941. if (msg->flags & IUCV_IPRMDATA)
  942. return iucv_message_receive_iprmdata(path, msg, flags,
  943. buffer, size, residual);
  944. parm = iucv_param[smp_processor_id()];
  945. memset(parm, 0, sizeof(union iucv_param));
  946. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  947. parm->db.ipbfln1f = (u32) size;
  948. parm->db.ipmsgid = msg->id;
  949. parm->db.ippathid = path->pathid;
  950. parm->db.iptrgcls = msg->class;
  951. parm->db.ipflags1 = (flags | IUCV_IPFGPID |
  952. IUCV_IPFGMID | IUCV_IPTRGCLS);
  953. rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
  954. if (!rc || rc == 5) {
  955. msg->flags = parm->db.ipflags1;
  956. if (residual)
  957. *residual = parm->db.ipbfln1f;
  958. }
  959. return rc;
  960. }
  961. EXPORT_SYMBOL(__iucv_message_receive);
  962. /**
  963. * iucv_message_receive
  964. * @path: address of iucv path structure
  965. * @msg: address of iucv msg structure
  966. * @flags: how the message is received (IUCV_IPBUFLST)
  967. * @buffer: address of data buffer or address of struct iucv_array
  968. * @size: length of data buffer
  969. * @residual:
  970. *
  971. * This function receives messages that are being sent to you over
  972. * established paths. This function will deal with RMDATA messages
  973. * embedded in struct iucv_message as well.
  974. *
  975. * Locking: local_bh_enable/local_bh_disable
  976. *
  977. * Returns the result from the CP IUCV call.
  978. */
  979. int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  980. u8 flags, void *buffer, size_t size, size_t *residual)
  981. {
  982. int rc;
  983. if (msg->flags & IUCV_IPRMDATA)
  984. return iucv_message_receive_iprmdata(path, msg, flags,
  985. buffer, size, residual);
  986. local_bh_disable();
  987. rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
  988. local_bh_enable();
  989. return rc;
  990. }
  991. EXPORT_SYMBOL(iucv_message_receive);
  992. /**
  993. * iucv_message_reject
  994. * @path: address of iucv path structure
  995. * @msg: address of iucv msg structure
  996. *
  997. * The reject function refuses a specified message. Between the time you
  998. * are notified of a message and the time that you complete the message,
  999. * the message may be rejected.
  1000. *
  1001. * Returns the result from the CP IUCV call.
  1002. */
  1003. int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
  1004. {
  1005. union iucv_param *parm;
  1006. int rc;
  1007. local_bh_disable();
  1008. parm = iucv_param[smp_processor_id()];
  1009. memset(parm, 0, sizeof(union iucv_param));
  1010. parm->db.ippathid = path->pathid;
  1011. parm->db.ipmsgid = msg->id;
  1012. parm->db.iptrgcls = msg->class;
  1013. parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
  1014. rc = iucv_call_b2f0(IUCV_REJECT, parm);
  1015. local_bh_enable();
  1016. return rc;
  1017. }
  1018. EXPORT_SYMBOL(iucv_message_reject);
  1019. /**
  1020. * iucv_message_reply
  1021. * @path: address of iucv path structure
  1022. * @msg: address of iucv msg structure
  1023. * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1024. * @reply: address of reply data buffer or address of struct iucv_array
  1025. * @size: length of reply data buffer
  1026. *
  1027. * This function responds to the two-way messages that you receive. You
  1028. * must identify completely the message to which you wish to reply. ie,
  1029. * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
  1030. * the parameter list.
  1031. *
  1032. * Returns the result from the CP IUCV call.
  1033. */
  1034. int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
  1035. u8 flags, void *reply, size_t size)
  1036. {
  1037. union iucv_param *parm;
  1038. int rc;
  1039. local_bh_disable();
  1040. parm = iucv_param[smp_processor_id()];
  1041. memset(parm, 0, sizeof(union iucv_param));
  1042. if (flags & IUCV_IPRMDATA) {
  1043. parm->dpl.ippathid = path->pathid;
  1044. parm->dpl.ipflags1 = flags;
  1045. parm->dpl.ipmsgid = msg->id;
  1046. parm->dpl.iptrgcls = msg->class;
  1047. memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
  1048. } else {
  1049. parm->db.ipbfadr1 = (u32)(addr_t) reply;
  1050. parm->db.ipbfln1f = (u32) size;
  1051. parm->db.ippathid = path->pathid;
  1052. parm->db.ipflags1 = flags;
  1053. parm->db.ipmsgid = msg->id;
  1054. parm->db.iptrgcls = msg->class;
  1055. }
  1056. rc = iucv_call_b2f0(IUCV_REPLY, parm);
  1057. local_bh_enable();
  1058. return rc;
  1059. }
  1060. EXPORT_SYMBOL(iucv_message_reply);
  1061. /**
  1062. * __iucv_message_send
  1063. * @path: address of iucv path structure
  1064. * @msg: address of iucv msg structure
  1065. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1066. * @srccls: source class of message
  1067. * @buffer: address of send buffer or address of struct iucv_array
  1068. * @size: length of send buffer
  1069. *
  1070. * This function transmits data to another application. Data to be
  1071. * transmitted is in a buffer and this is a one-way message and the
  1072. * receiver will not reply to the message.
  1073. *
  1074. * Locking: no locking
  1075. *
  1076. * Returns the result from the CP IUCV call.
  1077. */
  1078. int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1079. u8 flags, u32 srccls, void *buffer, size_t size)
  1080. {
  1081. union iucv_param *parm;
  1082. int rc;
  1083. parm = iucv_param[smp_processor_id()];
  1084. memset(parm, 0, sizeof(union iucv_param));
  1085. if (flags & IUCV_IPRMDATA) {
  1086. /* Message of 8 bytes can be placed into the parameter list. */
  1087. parm->dpl.ippathid = path->pathid;
  1088. parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
  1089. parm->dpl.iptrgcls = msg->class;
  1090. parm->dpl.ipsrccls = srccls;
  1091. parm->dpl.ipmsgtag = msg->tag;
  1092. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1093. } else {
  1094. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1095. parm->db.ipbfln1f = (u32) size;
  1096. parm->db.ippathid = path->pathid;
  1097. parm->db.ipflags1 = flags | IUCV_IPNORPY;
  1098. parm->db.iptrgcls = msg->class;
  1099. parm->db.ipsrccls = srccls;
  1100. parm->db.ipmsgtag = msg->tag;
  1101. }
  1102. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1103. if (!rc)
  1104. msg->id = parm->db.ipmsgid;
  1105. return rc;
  1106. }
  1107. EXPORT_SYMBOL(__iucv_message_send);
  1108. /**
  1109. * iucv_message_send
  1110. * @path: address of iucv path structure
  1111. * @msg: address of iucv msg structure
  1112. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1113. * @srccls: source class of message
  1114. * @buffer: address of send buffer or address of struct iucv_array
  1115. * @size: length of send buffer
  1116. *
  1117. * This function transmits data to another application. Data to be
  1118. * transmitted is in a buffer and this is a one-way message and the
  1119. * receiver will not reply to the message.
  1120. *
  1121. * Locking: local_bh_enable/local_bh_disable
  1122. *
  1123. * Returns the result from the CP IUCV call.
  1124. */
  1125. int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1126. u8 flags, u32 srccls, void *buffer, size_t size)
  1127. {
  1128. int rc;
  1129. local_bh_disable();
  1130. rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
  1131. local_bh_enable();
  1132. return rc;
  1133. }
  1134. EXPORT_SYMBOL(iucv_message_send);
  1135. /**
  1136. * iucv_message_send2way
  1137. * @path: address of iucv path structure
  1138. * @msg: address of iucv msg structure
  1139. * @flags: how the message is sent and the reply is received
  1140. * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
  1141. * @srccls: source class of message
  1142. * @buffer: address of send buffer or address of struct iucv_array
  1143. * @size: length of send buffer
  1144. * @ansbuf: address of answer buffer or address of struct iucv_array
  1145. * @asize: size of reply buffer
  1146. *
  1147. * This function transmits data to another application. Data to be
  1148. * transmitted is in a buffer. The receiver of the send is expected to
  1149. * reply to the message and a buffer is provided into which IUCV moves
  1150. * the reply to this message.
  1151. *
  1152. * Returns the result from the CP IUCV call.
  1153. */
  1154. int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
  1155. u8 flags, u32 srccls, void *buffer, size_t size,
  1156. void *answer, size_t asize, size_t *residual)
  1157. {
  1158. union iucv_param *parm;
  1159. int rc;
  1160. local_bh_disable();
  1161. parm = iucv_param[smp_processor_id()];
  1162. memset(parm, 0, sizeof(union iucv_param));
  1163. if (flags & IUCV_IPRMDATA) {
  1164. parm->dpl.ippathid = path->pathid;
  1165. parm->dpl.ipflags1 = path->flags; /* priority message */
  1166. parm->dpl.iptrgcls = msg->class;
  1167. parm->dpl.ipsrccls = srccls;
  1168. parm->dpl.ipmsgtag = msg->tag;
  1169. parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
  1170. parm->dpl.ipbfln2f = (u32) asize;
  1171. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1172. } else {
  1173. parm->db.ippathid = path->pathid;
  1174. parm->db.ipflags1 = path->flags; /* priority message */
  1175. parm->db.iptrgcls = msg->class;
  1176. parm->db.ipsrccls = srccls;
  1177. parm->db.ipmsgtag = msg->tag;
  1178. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1179. parm->db.ipbfln1f = (u32) size;
  1180. parm->db.ipbfadr2 = (u32)(addr_t) answer;
  1181. parm->db.ipbfln2f = (u32) asize;
  1182. }
  1183. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1184. if (!rc)
  1185. msg->id = parm->db.ipmsgid;
  1186. local_bh_enable();
  1187. return rc;
  1188. }
  1189. EXPORT_SYMBOL(iucv_message_send2way);
  1190. /**
  1191. * iucv_path_pending
  1192. * @data: Pointer to external interrupt buffer
  1193. *
  1194. * Process connection pending work item. Called from tasklet while holding
  1195. * iucv_table_lock.
  1196. */
  1197. struct iucv_path_pending {
  1198. u16 ippathid;
  1199. u8 ipflags1;
  1200. u8 iptype;
  1201. u16 ipmsglim;
  1202. u16 res1;
  1203. u8 ipvmid[8];
  1204. u8 ipuser[16];
  1205. u32 res3;
  1206. u8 ippollfg;
  1207. u8 res4[3];
  1208. } __attribute__ ((packed));
  1209. static void iucv_path_pending(struct iucv_irq_data *data)
  1210. {
  1211. struct iucv_path_pending *ipp = (void *) data;
  1212. struct iucv_handler *handler;
  1213. struct iucv_path *path;
  1214. char *error;
  1215. BUG_ON(iucv_path_table[ipp->ippathid]);
  1216. /* New pathid, handler found. Create a new path struct. */
  1217. error = iucv_error_no_memory;
  1218. path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
  1219. if (!path)
  1220. goto out_sever;
  1221. path->pathid = ipp->ippathid;
  1222. iucv_path_table[path->pathid] = path;
  1223. EBCASC(ipp->ipvmid, 8);
  1224. /* Call registered handler until one is found that wants the path. */
  1225. list_for_each_entry(handler, &iucv_handler_list, list) {
  1226. if (!handler->path_pending)
  1227. continue;
  1228. /*
  1229. * Add path to handler to allow a call to iucv_path_sever
  1230. * inside the path_pending function. If the handler returns
  1231. * an error remove the path from the handler again.
  1232. */
  1233. list_add(&path->list, &handler->paths);
  1234. path->handler = handler;
  1235. if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
  1236. return;
  1237. list_del(&path->list);
  1238. path->handler = NULL;
  1239. }
  1240. /* No handler wanted the path. */
  1241. iucv_path_table[path->pathid] = NULL;
  1242. iucv_path_free(path);
  1243. error = iucv_error_no_listener;
  1244. out_sever:
  1245. iucv_sever_pathid(ipp->ippathid, error);
  1246. }
  1247. /**
  1248. * iucv_path_complete
  1249. * @data: Pointer to external interrupt buffer
  1250. *
  1251. * Process connection complete work item. Called from tasklet while holding
  1252. * iucv_table_lock.
  1253. */
  1254. struct iucv_path_complete {
  1255. u16 ippathid;
  1256. u8 ipflags1;
  1257. u8 iptype;
  1258. u16 ipmsglim;
  1259. u16 res1;
  1260. u8 res2[8];
  1261. u8 ipuser[16];
  1262. u32 res3;
  1263. u8 ippollfg;
  1264. u8 res4[3];
  1265. } __attribute__ ((packed));
  1266. static void iucv_path_complete(struct iucv_irq_data *data)
  1267. {
  1268. struct iucv_path_complete *ipc = (void *) data;
  1269. struct iucv_path *path = iucv_path_table[ipc->ippathid];
  1270. if (path && path->handler && path->handler->path_complete)
  1271. path->handler->path_complete(path, ipc->ipuser);
  1272. }
  1273. /**
  1274. * iucv_path_severed
  1275. * @data: Pointer to external interrupt buffer
  1276. *
  1277. * Process connection severed work item. Called from tasklet while holding
  1278. * iucv_table_lock.
  1279. */
  1280. struct iucv_path_severed {
  1281. u16 ippathid;
  1282. u8 res1;
  1283. u8 iptype;
  1284. u32 res2;
  1285. u8 res3[8];
  1286. u8 ipuser[16];
  1287. u32 res4;
  1288. u8 ippollfg;
  1289. u8 res5[3];
  1290. } __attribute__ ((packed));
  1291. static void iucv_path_severed(struct iucv_irq_data *data)
  1292. {
  1293. struct iucv_path_severed *ips = (void *) data;
  1294. struct iucv_path *path = iucv_path_table[ips->ippathid];
  1295. if (!path || !path->handler) /* Already severed */
  1296. return;
  1297. if (path->handler->path_severed)
  1298. path->handler->path_severed(path, ips->ipuser);
  1299. else {
  1300. iucv_sever_pathid(path->pathid, NULL);
  1301. iucv_path_table[path->pathid] = NULL;
  1302. list_del_init(&path->list);
  1303. iucv_path_free(path);
  1304. }
  1305. }
  1306. /**
  1307. * iucv_path_quiesced
  1308. * @data: Pointer to external interrupt buffer
  1309. *
  1310. * Process connection quiesced work item. Called from tasklet while holding
  1311. * iucv_table_lock.
  1312. */
  1313. struct iucv_path_quiesced {
  1314. u16 ippathid;
  1315. u8 res1;
  1316. u8 iptype;
  1317. u32 res2;
  1318. u8 res3[8];
  1319. u8 ipuser[16];
  1320. u32 res4;
  1321. u8 ippollfg;
  1322. u8 res5[3];
  1323. } __attribute__ ((packed));
  1324. static void iucv_path_quiesced(struct iucv_irq_data *data)
  1325. {
  1326. struct iucv_path_quiesced *ipq = (void *) data;
  1327. struct iucv_path *path = iucv_path_table[ipq->ippathid];
  1328. if (path && path->handler && path->handler->path_quiesced)
  1329. path->handler->path_quiesced(path, ipq->ipuser);
  1330. }
  1331. /**
  1332. * iucv_path_resumed
  1333. * @data: Pointer to external interrupt buffer
  1334. *
  1335. * Process connection resumed work item. Called from tasklet while holding
  1336. * iucv_table_lock.
  1337. */
  1338. struct iucv_path_resumed {
  1339. u16 ippathid;
  1340. u8 res1;
  1341. u8 iptype;
  1342. u32 res2;
  1343. u8 res3[8];
  1344. u8 ipuser[16];
  1345. u32 res4;
  1346. u8 ippollfg;
  1347. u8 res5[3];
  1348. } __attribute__ ((packed));
  1349. static void iucv_path_resumed(struct iucv_irq_data *data)
  1350. {
  1351. struct iucv_path_resumed *ipr = (void *) data;
  1352. struct iucv_path *path = iucv_path_table[ipr->ippathid];
  1353. if (path && path->handler && path->handler->path_resumed)
  1354. path->handler->path_resumed(path, ipr->ipuser);
  1355. }
  1356. /**
  1357. * iucv_message_complete
  1358. * @data: Pointer to external interrupt buffer
  1359. *
  1360. * Process message complete work item. Called from tasklet while holding
  1361. * iucv_table_lock.
  1362. */
  1363. struct iucv_message_complete {
  1364. u16 ippathid;
  1365. u8 ipflags1;
  1366. u8 iptype;
  1367. u32 ipmsgid;
  1368. u32 ipaudit;
  1369. u8 iprmmsg[8];
  1370. u32 ipsrccls;
  1371. u32 ipmsgtag;
  1372. u32 res;
  1373. u32 ipbfln2f;
  1374. u8 ippollfg;
  1375. u8 res2[3];
  1376. } __attribute__ ((packed));
  1377. static void iucv_message_complete(struct iucv_irq_data *data)
  1378. {
  1379. struct iucv_message_complete *imc = (void *) data;
  1380. struct iucv_path *path = iucv_path_table[imc->ippathid];
  1381. struct iucv_message msg;
  1382. if (path && path->handler && path->handler->message_complete) {
  1383. msg.flags = imc->ipflags1;
  1384. msg.id = imc->ipmsgid;
  1385. msg.audit = imc->ipaudit;
  1386. memcpy(msg.rmmsg, imc->iprmmsg, 8);
  1387. msg.class = imc->ipsrccls;
  1388. msg.tag = imc->ipmsgtag;
  1389. msg.length = imc->ipbfln2f;
  1390. path->handler->message_complete(path, &msg);
  1391. }
  1392. }
  1393. /**
  1394. * iucv_message_pending
  1395. * @data: Pointer to external interrupt buffer
  1396. *
  1397. * Process message pending work item. Called from tasklet while holding
  1398. * iucv_table_lock.
  1399. */
  1400. struct iucv_message_pending {
  1401. u16 ippathid;
  1402. u8 ipflags1;
  1403. u8 iptype;
  1404. u32 ipmsgid;
  1405. u32 iptrgcls;
  1406. union {
  1407. u32 iprmmsg1_u32;
  1408. u8 iprmmsg1[4];
  1409. } ln1msg1;
  1410. union {
  1411. u32 ipbfln1f;
  1412. u8 iprmmsg2[4];
  1413. } ln1msg2;
  1414. u32 res1[3];
  1415. u32 ipbfln2f;
  1416. u8 ippollfg;
  1417. u8 res2[3];
  1418. } __attribute__ ((packed));
  1419. static void iucv_message_pending(struct iucv_irq_data *data)
  1420. {
  1421. struct iucv_message_pending *imp = (void *) data;
  1422. struct iucv_path *path = iucv_path_table[imp->ippathid];
  1423. struct iucv_message msg;
  1424. if (path && path->handler && path->handler->message_pending) {
  1425. msg.flags = imp->ipflags1;
  1426. msg.id = imp->ipmsgid;
  1427. msg.class = imp->iptrgcls;
  1428. if (imp->ipflags1 & IUCV_IPRMDATA) {
  1429. memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
  1430. msg.length = 8;
  1431. } else
  1432. msg.length = imp->ln1msg2.ipbfln1f;
  1433. msg.reply_size = imp->ipbfln2f;
  1434. path->handler->message_pending(path, &msg);
  1435. }
  1436. }
  1437. /**
  1438. * iucv_tasklet_fn:
  1439. *
  1440. * This tasklet loops over the queue of irq buffers created by
  1441. * iucv_external_interrupt, calls the appropriate action handler
  1442. * and then frees the buffer.
  1443. */
  1444. static void iucv_tasklet_fn(unsigned long ignored)
  1445. {
  1446. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1447. static iucv_irq_fn *irq_fn[] = {
  1448. [0x02] = iucv_path_complete,
  1449. [0x03] = iucv_path_severed,
  1450. [0x04] = iucv_path_quiesced,
  1451. [0x05] = iucv_path_resumed,
  1452. [0x06] = iucv_message_complete,
  1453. [0x07] = iucv_message_complete,
  1454. [0x08] = iucv_message_pending,
  1455. [0x09] = iucv_message_pending,
  1456. };
  1457. LIST_HEAD(task_queue);
  1458. struct iucv_irq_list *p, *n;
  1459. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1460. if (!spin_trylock(&iucv_table_lock)) {
  1461. tasklet_schedule(&iucv_tasklet);
  1462. return;
  1463. }
  1464. iucv_active_cpu = smp_processor_id();
  1465. spin_lock_irq(&iucv_queue_lock);
  1466. list_splice_init(&iucv_task_queue, &task_queue);
  1467. spin_unlock_irq(&iucv_queue_lock);
  1468. list_for_each_entry_safe(p, n, &task_queue, list) {
  1469. list_del_init(&p->list);
  1470. irq_fn[p->data.iptype](&p->data);
  1471. kfree(p);
  1472. }
  1473. iucv_active_cpu = -1;
  1474. spin_unlock(&iucv_table_lock);
  1475. }
  1476. /**
  1477. * iucv_work_fn:
  1478. *
  1479. * This work function loops over the queue of path pending irq blocks
  1480. * created by iucv_external_interrupt, calls the appropriate action
  1481. * handler and then frees the buffer.
  1482. */
  1483. static void iucv_work_fn(struct work_struct *work)
  1484. {
  1485. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1486. LIST_HEAD(work_queue);
  1487. struct iucv_irq_list *p, *n;
  1488. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1489. spin_lock_bh(&iucv_table_lock);
  1490. iucv_active_cpu = smp_processor_id();
  1491. spin_lock_irq(&iucv_queue_lock);
  1492. list_splice_init(&iucv_work_queue, &work_queue);
  1493. spin_unlock_irq(&iucv_queue_lock);
  1494. iucv_cleanup_queue();
  1495. list_for_each_entry_safe(p, n, &work_queue, list) {
  1496. list_del_init(&p->list);
  1497. iucv_path_pending(&p->data);
  1498. kfree(p);
  1499. }
  1500. iucv_active_cpu = -1;
  1501. spin_unlock_bh(&iucv_table_lock);
  1502. }
  1503. /**
  1504. * iucv_external_interrupt
  1505. * @code: irq code
  1506. *
  1507. * Handles external interrupts coming in from CP.
  1508. * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
  1509. */
  1510. static void iucv_external_interrupt(u16 code)
  1511. {
  1512. struct iucv_irq_data *p;
  1513. struct iucv_irq_list *work;
  1514. p = iucv_irq_data[smp_processor_id()];
  1515. if (p->ippathid >= iucv_max_pathid) {
  1516. WARN_ON(p->ippathid >= iucv_max_pathid);
  1517. iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
  1518. return;
  1519. }
  1520. BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
  1521. work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
  1522. if (!work) {
  1523. pr_warning("iucv_external_interrupt: out of memory\n");
  1524. return;
  1525. }
  1526. memcpy(&work->data, p, sizeof(work->data));
  1527. spin_lock(&iucv_queue_lock);
  1528. if (p->iptype == 0x01) {
  1529. /* Path pending interrupt. */
  1530. list_add_tail(&work->list, &iucv_work_queue);
  1531. schedule_work(&iucv_work);
  1532. } else {
  1533. /* The other interrupts. */
  1534. list_add_tail(&work->list, &iucv_task_queue);
  1535. tasklet_schedule(&iucv_tasklet);
  1536. }
  1537. spin_unlock(&iucv_queue_lock);
  1538. }
  1539. /**
  1540. * iucv_init
  1541. *
  1542. * Allocates and initializes various data structures.
  1543. */
  1544. static int __init iucv_init(void)
  1545. {
  1546. int rc;
  1547. int cpu;
  1548. if (!MACHINE_IS_VM) {
  1549. rc = -EPROTONOSUPPORT;
  1550. goto out;
  1551. }
  1552. rc = iucv_query_maxconn();
  1553. if (rc)
  1554. goto out;
  1555. rc = register_external_interrupt(0x4000, iucv_external_interrupt);
  1556. if (rc)
  1557. goto out;
  1558. iucv_root = s390_root_dev_register("iucv");
  1559. if (IS_ERR(iucv_root)) {
  1560. rc = PTR_ERR(iucv_root);
  1561. goto out_int;
  1562. }
  1563. for_each_online_cpu(cpu) {
  1564. /* Note: GFP_DMA used to get memory below 2G */
  1565. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  1566. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1567. if (!iucv_irq_data[cpu]) {
  1568. rc = -ENOMEM;
  1569. goto out_free;
  1570. }
  1571. /* Allocate parameter blocks. */
  1572. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  1573. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1574. if (!iucv_param[cpu]) {
  1575. rc = -ENOMEM;
  1576. goto out_free;
  1577. }
  1578. }
  1579. rc = register_hotcpu_notifier(&iucv_cpu_notifier);
  1580. if (rc)
  1581. goto out_free;
  1582. ASCEBC(iucv_error_no_listener, 16);
  1583. ASCEBC(iucv_error_no_memory, 16);
  1584. ASCEBC(iucv_error_pathid, 16);
  1585. iucv_available = 1;
  1586. rc = bus_register(&iucv_bus);
  1587. if (rc)
  1588. goto out_cpu;
  1589. return 0;
  1590. out_cpu:
  1591. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1592. out_free:
  1593. for_each_possible_cpu(cpu) {
  1594. kfree(iucv_param[cpu]);
  1595. iucv_param[cpu] = NULL;
  1596. kfree(iucv_irq_data[cpu]);
  1597. iucv_irq_data[cpu] = NULL;
  1598. }
  1599. s390_root_dev_unregister(iucv_root);
  1600. out_int:
  1601. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1602. out:
  1603. return rc;
  1604. }
  1605. /**
  1606. * iucv_exit
  1607. *
  1608. * Frees everything allocated from iucv_init.
  1609. */
  1610. static void __exit iucv_exit(void)
  1611. {
  1612. struct iucv_irq_list *p, *n;
  1613. int cpu;
  1614. spin_lock_irq(&iucv_queue_lock);
  1615. list_for_each_entry_safe(p, n, &iucv_task_queue, list)
  1616. kfree(p);
  1617. list_for_each_entry_safe(p, n, &iucv_work_queue, list)
  1618. kfree(p);
  1619. spin_unlock_irq(&iucv_queue_lock);
  1620. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1621. for_each_possible_cpu(cpu) {
  1622. kfree(iucv_param[cpu]);
  1623. iucv_param[cpu] = NULL;
  1624. kfree(iucv_irq_data[cpu]);
  1625. iucv_irq_data[cpu] = NULL;
  1626. }
  1627. s390_root_dev_unregister(iucv_root);
  1628. bus_unregister(&iucv_bus);
  1629. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1630. }
  1631. subsys_initcall(iucv_init);
  1632. module_exit(iucv_exit);
  1633. MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
  1634. MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
  1635. MODULE_LICENSE("GPL");