iucv.c 53 KB

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