iucv.c 43 KB

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