iucv.c 53 KB

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