iucv.c 45 KB

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