iucv.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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 <linux/atomic.h>
  53. #include <asm/ebcdic.h>
  54. #include <asm/io.h>
  55. #include <asm/irq.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_BITS_NONE };
  119. static cpumask_t iucv_irq_cpumask = { CPU_BITS_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. cpumask_set_cpu(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. cpumask_clear_cpu(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. cpumask_clear_cpu(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 (cpumask_test_cpu(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_warn("Defining an interrupt buffer on CPU %i failed with 0x%02x (%s)\n",
  448. cpu, rc, err);
  449. return;
  450. }
  451. /* Set indication that an iucv buffer exists for this cpu. */
  452. cpumask_set_cpu(cpu, &iucv_buffer_cpumask);
  453. if (iucv_nonsmp_handler == 0 || cpumask_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 (!cpumask_test_cpu(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. cpumask_clear_cpu(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 (cpumask_test_cpu(cpu, &iucv_buffer_cpumask) &&
  492. !cpumask_test_cpu(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_copy(&cpumask, &iucv_irq_cpumask);
  508. cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask), &cpumask);
  509. for_each_cpu(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 (cpumask_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 void free_iucv_data(int cpu)
  561. {
  562. kfree(iucv_param_irq[cpu]);
  563. iucv_param_irq[cpu] = NULL;
  564. kfree(iucv_param[cpu]);
  565. iucv_param[cpu] = NULL;
  566. kfree(iucv_irq_data[cpu]);
  567. iucv_irq_data[cpu] = NULL;
  568. }
  569. static int alloc_iucv_data(int cpu)
  570. {
  571. /* Note: GFP_DMA used to get memory below 2G */
  572. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  573. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  574. if (!iucv_irq_data[cpu])
  575. goto out_free;
  576. /* Allocate parameter blocks. */
  577. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  578. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  579. if (!iucv_param[cpu])
  580. goto out_free;
  581. iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
  582. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  583. if (!iucv_param_irq[cpu])
  584. goto out_free;
  585. return 0;
  586. out_free:
  587. free_iucv_data(cpu);
  588. return -ENOMEM;
  589. }
  590. static int iucv_cpu_notify(struct notifier_block *self,
  591. unsigned long action, void *hcpu)
  592. {
  593. cpumask_t cpumask;
  594. long cpu = (long) hcpu;
  595. switch (action) {
  596. case CPU_UP_PREPARE:
  597. case CPU_UP_PREPARE_FROZEN:
  598. if (alloc_iucv_data(cpu))
  599. return notifier_from_errno(-ENOMEM);
  600. break;
  601. case CPU_UP_CANCELED:
  602. case CPU_UP_CANCELED_FROZEN:
  603. case CPU_DEAD:
  604. case CPU_DEAD_FROZEN:
  605. free_iucv_data(cpu);
  606. break;
  607. case CPU_ONLINE:
  608. case CPU_ONLINE_FROZEN:
  609. case CPU_DOWN_FAILED:
  610. case CPU_DOWN_FAILED_FROZEN:
  611. if (!iucv_path_table)
  612. break;
  613. smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
  614. break;
  615. case CPU_DOWN_PREPARE:
  616. case CPU_DOWN_PREPARE_FROZEN:
  617. if (!iucv_path_table)
  618. break;
  619. cpumask_copy(&cpumask, &iucv_buffer_cpumask);
  620. cpumask_clear_cpu(cpu, &cpumask);
  621. if (cpumask_empty(&cpumask))
  622. /* Can't offline last IUCV enabled cpu. */
  623. return notifier_from_errno(-EINVAL);
  624. smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
  625. if (cpumask_empty(&iucv_irq_cpumask))
  626. smp_call_function_single(
  627. cpumask_first(&iucv_buffer_cpumask),
  628. iucv_allow_cpu, NULL, 1);
  629. break;
  630. }
  631. return NOTIFY_OK;
  632. }
  633. static struct notifier_block __refdata iucv_cpu_notifier = {
  634. .notifier_call = iucv_cpu_notify,
  635. };
  636. /**
  637. * iucv_sever_pathid
  638. * @pathid: path identification number.
  639. * @userdata: 16-bytes of user data.
  640. *
  641. * Sever an iucv path to free up the pathid. Used internally.
  642. */
  643. static int iucv_sever_pathid(u16 pathid, u8 *userdata)
  644. {
  645. union iucv_param *parm;
  646. parm = iucv_param_irq[smp_processor_id()];
  647. memset(parm, 0, sizeof(union iucv_param));
  648. if (userdata)
  649. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  650. parm->ctrl.ippathid = pathid;
  651. return iucv_call_b2f0(IUCV_SEVER, parm);
  652. }
  653. /**
  654. * __iucv_cleanup_queue
  655. * @dummy: unused dummy argument
  656. *
  657. * Nop function called via smp_call_function to force work items from
  658. * pending external iucv interrupts to the work queue.
  659. */
  660. static void __iucv_cleanup_queue(void *dummy)
  661. {
  662. }
  663. /**
  664. * iucv_cleanup_queue
  665. *
  666. * Function called after a path has been severed to find all remaining
  667. * work items for the now stale pathid. The caller needs to hold the
  668. * iucv_table_lock.
  669. */
  670. static void iucv_cleanup_queue(void)
  671. {
  672. struct iucv_irq_list *p, *n;
  673. /*
  674. * When a path is severed, the pathid can be reused immediately
  675. * on a iucv connect or a connection pending interrupt. Remove
  676. * all entries from the task queue that refer to a stale pathid
  677. * (iucv_path_table[ix] == NULL). Only then do the iucv connect
  678. * or deliver the connection pending interrupt. To get all the
  679. * pending interrupts force them to the work queue by calling
  680. * an empty function on all cpus.
  681. */
  682. smp_call_function(__iucv_cleanup_queue, NULL, 1);
  683. spin_lock_irq(&iucv_queue_lock);
  684. list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
  685. /* Remove stale work items from the task queue. */
  686. if (iucv_path_table[p->data.ippathid] == NULL) {
  687. list_del(&p->list);
  688. kfree(p);
  689. }
  690. }
  691. spin_unlock_irq(&iucv_queue_lock);
  692. }
  693. /**
  694. * iucv_register:
  695. * @handler: address of iucv handler structure
  696. * @smp: != 0 indicates that the handler can deal with out of order messages
  697. *
  698. * Registers a driver with IUCV.
  699. *
  700. * Returns 0 on success, -ENOMEM if the memory allocation for the pathid
  701. * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
  702. */
  703. int iucv_register(struct iucv_handler *handler, int smp)
  704. {
  705. int rc;
  706. if (!iucv_available)
  707. return -ENOSYS;
  708. mutex_lock(&iucv_register_mutex);
  709. if (!smp)
  710. iucv_nonsmp_handler++;
  711. if (list_empty(&iucv_handler_list)) {
  712. rc = iucv_enable();
  713. if (rc)
  714. goto out_mutex;
  715. } else if (!smp && iucv_nonsmp_handler == 1)
  716. iucv_setmask_up();
  717. INIT_LIST_HEAD(&handler->paths);
  718. spin_lock_bh(&iucv_table_lock);
  719. list_add_tail(&handler->list, &iucv_handler_list);
  720. spin_unlock_bh(&iucv_table_lock);
  721. rc = 0;
  722. out_mutex:
  723. mutex_unlock(&iucv_register_mutex);
  724. return rc;
  725. }
  726. EXPORT_SYMBOL(iucv_register);
  727. /**
  728. * iucv_unregister
  729. * @handler: address of iucv handler structure
  730. * @smp: != 0 indicates that the handler can deal with out of order messages
  731. *
  732. * Unregister driver from IUCV.
  733. */
  734. void iucv_unregister(struct iucv_handler *handler, int smp)
  735. {
  736. struct iucv_path *p, *n;
  737. mutex_lock(&iucv_register_mutex);
  738. spin_lock_bh(&iucv_table_lock);
  739. /* Remove handler from the iucv_handler_list. */
  740. list_del_init(&handler->list);
  741. /* Sever all pathids still referring to the handler. */
  742. list_for_each_entry_safe(p, n, &handler->paths, list) {
  743. iucv_sever_pathid(p->pathid, NULL);
  744. iucv_path_table[p->pathid] = NULL;
  745. list_del(&p->list);
  746. iucv_path_free(p);
  747. }
  748. spin_unlock_bh(&iucv_table_lock);
  749. if (!smp)
  750. iucv_nonsmp_handler--;
  751. if (list_empty(&iucv_handler_list))
  752. iucv_disable();
  753. else if (!smp && iucv_nonsmp_handler == 0)
  754. iucv_setmask_mp();
  755. mutex_unlock(&iucv_register_mutex);
  756. }
  757. EXPORT_SYMBOL(iucv_unregister);
  758. static int iucv_reboot_event(struct notifier_block *this,
  759. unsigned long event, void *ptr)
  760. {
  761. int i;
  762. if (cpumask_empty(&iucv_irq_cpumask))
  763. return NOTIFY_DONE;
  764. get_online_cpus();
  765. on_each_cpu_mask(&iucv_irq_cpumask, iucv_block_cpu, NULL, 1);
  766. preempt_disable();
  767. for (i = 0; i < iucv_max_pathid; i++) {
  768. if (iucv_path_table[i])
  769. iucv_sever_pathid(i, NULL);
  770. }
  771. preempt_enable();
  772. put_online_cpus();
  773. iucv_disable();
  774. return NOTIFY_DONE;
  775. }
  776. static struct notifier_block iucv_reboot_notifier = {
  777. .notifier_call = iucv_reboot_event,
  778. };
  779. /**
  780. * iucv_path_accept
  781. * @path: address of iucv path structure
  782. * @handler: address of iucv handler structure
  783. * @userdata: 16 bytes of data reflected to the communication partner
  784. * @private: private data passed to interrupt handlers for this path
  785. *
  786. * This function is issued after the user received a connection pending
  787. * external interrupt and now wishes to complete the IUCV communication path.
  788. *
  789. * Returns the result of the CP IUCV call.
  790. */
  791. int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
  792. u8 *userdata, void *private)
  793. {
  794. union iucv_param *parm;
  795. int rc;
  796. local_bh_disable();
  797. if (cpumask_empty(&iucv_buffer_cpumask)) {
  798. rc = -EIO;
  799. goto out;
  800. }
  801. /* Prepare parameter block. */
  802. parm = iucv_param[smp_processor_id()];
  803. memset(parm, 0, sizeof(union iucv_param));
  804. parm->ctrl.ippathid = path->pathid;
  805. parm->ctrl.ipmsglim = path->msglim;
  806. if (userdata)
  807. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  808. parm->ctrl.ipflags1 = path->flags;
  809. rc = iucv_call_b2f0(IUCV_ACCEPT, parm);
  810. if (!rc) {
  811. path->private = private;
  812. path->msglim = parm->ctrl.ipmsglim;
  813. path->flags = parm->ctrl.ipflags1;
  814. }
  815. out:
  816. local_bh_enable();
  817. return rc;
  818. }
  819. EXPORT_SYMBOL(iucv_path_accept);
  820. /**
  821. * iucv_path_connect
  822. * @path: address of iucv path structure
  823. * @handler: address of iucv handler structure
  824. * @userid: 8-byte user identification
  825. * @system: 8-byte target system identification
  826. * @userdata: 16 bytes of data reflected to the communication partner
  827. * @private: private data passed to interrupt handlers for this path
  828. *
  829. * This function establishes an IUCV path. Although the connect may complete
  830. * successfully, you are not able to use the path until you receive an IUCV
  831. * Connection Complete external interrupt.
  832. *
  833. * Returns the result of the CP IUCV call.
  834. */
  835. int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
  836. u8 *userid, u8 *system, u8 *userdata,
  837. void *private)
  838. {
  839. union iucv_param *parm;
  840. int rc;
  841. spin_lock_bh(&iucv_table_lock);
  842. iucv_cleanup_queue();
  843. if (cpumask_empty(&iucv_buffer_cpumask)) {
  844. rc = -EIO;
  845. goto out;
  846. }
  847. parm = iucv_param[smp_processor_id()];
  848. memset(parm, 0, sizeof(union iucv_param));
  849. parm->ctrl.ipmsglim = path->msglim;
  850. parm->ctrl.ipflags1 = path->flags;
  851. if (userid) {
  852. memcpy(parm->ctrl.ipvmid, userid, sizeof(parm->ctrl.ipvmid));
  853. ASCEBC(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  854. EBC_TOUPPER(parm->ctrl.ipvmid, sizeof(parm->ctrl.ipvmid));
  855. }
  856. if (system) {
  857. memcpy(parm->ctrl.iptarget, system,
  858. sizeof(parm->ctrl.iptarget));
  859. ASCEBC(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  860. EBC_TOUPPER(parm->ctrl.iptarget, sizeof(parm->ctrl.iptarget));
  861. }
  862. if (userdata)
  863. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  864. rc = iucv_call_b2f0(IUCV_CONNECT, parm);
  865. if (!rc) {
  866. if (parm->ctrl.ippathid < iucv_max_pathid) {
  867. path->pathid = parm->ctrl.ippathid;
  868. path->msglim = parm->ctrl.ipmsglim;
  869. path->flags = parm->ctrl.ipflags1;
  870. path->handler = handler;
  871. path->private = private;
  872. list_add_tail(&path->list, &handler->paths);
  873. iucv_path_table[path->pathid] = path;
  874. } else {
  875. iucv_sever_pathid(parm->ctrl.ippathid,
  876. iucv_error_pathid);
  877. rc = -EIO;
  878. }
  879. }
  880. out:
  881. spin_unlock_bh(&iucv_table_lock);
  882. return rc;
  883. }
  884. EXPORT_SYMBOL(iucv_path_connect);
  885. /**
  886. * iucv_path_quiesce:
  887. * @path: address of iucv path structure
  888. * @userdata: 16 bytes of data reflected to the communication partner
  889. *
  890. * This function temporarily suspends incoming messages on an IUCV path.
  891. * You can later reactivate the path by invoking the iucv_resume function.
  892. *
  893. * Returns the result from the CP IUCV call.
  894. */
  895. int iucv_path_quiesce(struct iucv_path *path, u8 *userdata)
  896. {
  897. union iucv_param *parm;
  898. int rc;
  899. local_bh_disable();
  900. if (cpumask_empty(&iucv_buffer_cpumask)) {
  901. rc = -EIO;
  902. goto out;
  903. }
  904. parm = iucv_param[smp_processor_id()];
  905. memset(parm, 0, sizeof(union iucv_param));
  906. if (userdata)
  907. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  908. parm->ctrl.ippathid = path->pathid;
  909. rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
  910. out:
  911. local_bh_enable();
  912. return rc;
  913. }
  914. EXPORT_SYMBOL(iucv_path_quiesce);
  915. /**
  916. * iucv_path_resume:
  917. * @path: address of iucv path structure
  918. * @userdata: 16 bytes of data reflected to the communication partner
  919. *
  920. * This function resumes incoming messages on an IUCV path that has
  921. * been stopped with iucv_path_quiesce.
  922. *
  923. * Returns the result from the CP IUCV call.
  924. */
  925. int iucv_path_resume(struct iucv_path *path, u8 *userdata)
  926. {
  927. union iucv_param *parm;
  928. int rc;
  929. local_bh_disable();
  930. if (cpumask_empty(&iucv_buffer_cpumask)) {
  931. rc = -EIO;
  932. goto out;
  933. }
  934. parm = iucv_param[smp_processor_id()];
  935. memset(parm, 0, sizeof(union iucv_param));
  936. if (userdata)
  937. memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
  938. parm->ctrl.ippathid = path->pathid;
  939. rc = iucv_call_b2f0(IUCV_RESUME, parm);
  940. out:
  941. local_bh_enable();
  942. return rc;
  943. }
  944. /**
  945. * iucv_path_sever
  946. * @path: address of iucv path structure
  947. * @userdata: 16 bytes of data reflected to the communication partner
  948. *
  949. * This function terminates an IUCV path.
  950. *
  951. * Returns the result from the CP IUCV call.
  952. */
  953. int iucv_path_sever(struct iucv_path *path, u8 *userdata)
  954. {
  955. int rc;
  956. preempt_disable();
  957. if (cpumask_empty(&iucv_buffer_cpumask)) {
  958. rc = -EIO;
  959. goto out;
  960. }
  961. if (iucv_active_cpu != smp_processor_id())
  962. spin_lock_bh(&iucv_table_lock);
  963. rc = iucv_sever_pathid(path->pathid, userdata);
  964. iucv_path_table[path->pathid] = NULL;
  965. list_del_init(&path->list);
  966. if (iucv_active_cpu != smp_processor_id())
  967. spin_unlock_bh(&iucv_table_lock);
  968. out:
  969. preempt_enable();
  970. return rc;
  971. }
  972. EXPORT_SYMBOL(iucv_path_sever);
  973. /**
  974. * iucv_message_purge
  975. * @path: address of iucv path structure
  976. * @msg: address of iucv msg structure
  977. * @srccls: source class of message
  978. *
  979. * Cancels a message you have sent.
  980. *
  981. * Returns the result from the CP IUCV call.
  982. */
  983. int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
  984. u32 srccls)
  985. {
  986. union iucv_param *parm;
  987. int rc;
  988. local_bh_disable();
  989. if (cpumask_empty(&iucv_buffer_cpumask)) {
  990. rc = -EIO;
  991. goto out;
  992. }
  993. parm = iucv_param[smp_processor_id()];
  994. memset(parm, 0, sizeof(union iucv_param));
  995. parm->purge.ippathid = path->pathid;
  996. parm->purge.ipmsgid = msg->id;
  997. parm->purge.ipsrccls = srccls;
  998. parm->purge.ipflags1 = IUCV_IPSRCCLS | IUCV_IPFGMID | IUCV_IPFGPID;
  999. rc = iucv_call_b2f0(IUCV_PURGE, parm);
  1000. if (!rc) {
  1001. msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
  1002. msg->tag = parm->purge.ipmsgtag;
  1003. }
  1004. out:
  1005. local_bh_enable();
  1006. return rc;
  1007. }
  1008. EXPORT_SYMBOL(iucv_message_purge);
  1009. /**
  1010. * iucv_message_receive_iprmdata
  1011. * @path: address of iucv path structure
  1012. * @msg: address of iucv msg structure
  1013. * @flags: how the message is received (IUCV_IPBUFLST)
  1014. * @buffer: address of data buffer or address of struct iucv_array
  1015. * @size: length of data buffer
  1016. * @residual:
  1017. *
  1018. * Internal function used by iucv_message_receive and __iucv_message_receive
  1019. * to receive RMDATA data stored in struct iucv_message.
  1020. */
  1021. static int iucv_message_receive_iprmdata(struct iucv_path *path,
  1022. struct iucv_message *msg,
  1023. u8 flags, void *buffer,
  1024. size_t size, size_t *residual)
  1025. {
  1026. struct iucv_array *array;
  1027. u8 *rmmsg;
  1028. size_t copy;
  1029. /*
  1030. * Message is 8 bytes long and has been stored to the
  1031. * message descriptor itself.
  1032. */
  1033. if (residual)
  1034. *residual = abs(size - 8);
  1035. rmmsg = msg->rmmsg;
  1036. if (flags & IUCV_IPBUFLST) {
  1037. /* Copy to struct iucv_array. */
  1038. size = (size < 8) ? size : 8;
  1039. for (array = buffer; size > 0; array++) {
  1040. copy = min_t(size_t, size, array->length);
  1041. memcpy((u8 *)(addr_t) array->address,
  1042. rmmsg, copy);
  1043. rmmsg += copy;
  1044. size -= copy;
  1045. }
  1046. } else {
  1047. /* Copy to direct buffer. */
  1048. memcpy(buffer, rmmsg, min_t(size_t, size, 8));
  1049. }
  1050. return 0;
  1051. }
  1052. /**
  1053. * __iucv_message_receive
  1054. * @path: address of iucv path structure
  1055. * @msg: address of iucv msg structure
  1056. * @flags: how the message is received (IUCV_IPBUFLST)
  1057. * @buffer: address of data buffer or address of struct iucv_array
  1058. * @size: length of data buffer
  1059. * @residual:
  1060. *
  1061. * This function receives messages that are being sent to you over
  1062. * established paths. This function will deal with RMDATA messages
  1063. * embedded in struct iucv_message as well.
  1064. *
  1065. * Locking: no locking
  1066. *
  1067. * Returns the result from the CP IUCV call.
  1068. */
  1069. int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  1070. u8 flags, void *buffer, size_t size, size_t *residual)
  1071. {
  1072. union iucv_param *parm;
  1073. int rc;
  1074. if (msg->flags & IUCV_IPRMDATA)
  1075. return iucv_message_receive_iprmdata(path, msg, flags,
  1076. buffer, size, residual);
  1077. if (cpumask_empty(&iucv_buffer_cpumask)) {
  1078. rc = -EIO;
  1079. goto out;
  1080. }
  1081. parm = iucv_param[smp_processor_id()];
  1082. memset(parm, 0, sizeof(union iucv_param));
  1083. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1084. parm->db.ipbfln1f = (u32) size;
  1085. parm->db.ipmsgid = msg->id;
  1086. parm->db.ippathid = path->pathid;
  1087. parm->db.iptrgcls = msg->class;
  1088. parm->db.ipflags1 = (flags | IUCV_IPFGPID |
  1089. IUCV_IPFGMID | IUCV_IPTRGCLS);
  1090. rc = iucv_call_b2f0(IUCV_RECEIVE, parm);
  1091. if (!rc || rc == 5) {
  1092. msg->flags = parm->db.ipflags1;
  1093. if (residual)
  1094. *residual = parm->db.ipbfln1f;
  1095. }
  1096. out:
  1097. return rc;
  1098. }
  1099. EXPORT_SYMBOL(__iucv_message_receive);
  1100. /**
  1101. * iucv_message_receive
  1102. * @path: address of iucv path structure
  1103. * @msg: address of iucv msg structure
  1104. * @flags: how the message is received (IUCV_IPBUFLST)
  1105. * @buffer: address of data buffer or address of struct iucv_array
  1106. * @size: length of data buffer
  1107. * @residual:
  1108. *
  1109. * This function receives messages that are being sent to you over
  1110. * established paths. This function will deal with RMDATA messages
  1111. * embedded in struct iucv_message as well.
  1112. *
  1113. * Locking: local_bh_enable/local_bh_disable
  1114. *
  1115. * Returns the result from the CP IUCV call.
  1116. */
  1117. int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
  1118. u8 flags, void *buffer, size_t size, size_t *residual)
  1119. {
  1120. int rc;
  1121. if (msg->flags & IUCV_IPRMDATA)
  1122. return iucv_message_receive_iprmdata(path, msg, flags,
  1123. buffer, size, residual);
  1124. local_bh_disable();
  1125. rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
  1126. local_bh_enable();
  1127. return rc;
  1128. }
  1129. EXPORT_SYMBOL(iucv_message_receive);
  1130. /**
  1131. * iucv_message_reject
  1132. * @path: address of iucv path structure
  1133. * @msg: address of iucv msg structure
  1134. *
  1135. * The reject function refuses a specified message. Between the time you
  1136. * are notified of a message and the time that you complete the message,
  1137. * the message may be rejected.
  1138. *
  1139. * Returns the result from the CP IUCV call.
  1140. */
  1141. int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
  1142. {
  1143. union iucv_param *parm;
  1144. int rc;
  1145. local_bh_disable();
  1146. if (cpumask_empty(&iucv_buffer_cpumask)) {
  1147. rc = -EIO;
  1148. goto out;
  1149. }
  1150. parm = iucv_param[smp_processor_id()];
  1151. memset(parm, 0, sizeof(union iucv_param));
  1152. parm->db.ippathid = path->pathid;
  1153. parm->db.ipmsgid = msg->id;
  1154. parm->db.iptrgcls = msg->class;
  1155. parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
  1156. rc = iucv_call_b2f0(IUCV_REJECT, parm);
  1157. out:
  1158. local_bh_enable();
  1159. return rc;
  1160. }
  1161. EXPORT_SYMBOL(iucv_message_reject);
  1162. /**
  1163. * iucv_message_reply
  1164. * @path: address of iucv path structure
  1165. * @msg: address of iucv msg structure
  1166. * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1167. * @reply: address of reply data buffer or address of struct iucv_array
  1168. * @size: length of reply data buffer
  1169. *
  1170. * This function responds to the two-way messages that you receive. You
  1171. * must identify completely the message to which you wish to reply. ie,
  1172. * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into
  1173. * the parameter list.
  1174. *
  1175. * Returns the result from the CP IUCV call.
  1176. */
  1177. int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
  1178. u8 flags, void *reply, size_t size)
  1179. {
  1180. union iucv_param *parm;
  1181. int rc;
  1182. local_bh_disable();
  1183. if (cpumask_empty(&iucv_buffer_cpumask)) {
  1184. rc = -EIO;
  1185. goto out;
  1186. }
  1187. parm = iucv_param[smp_processor_id()];
  1188. memset(parm, 0, sizeof(union iucv_param));
  1189. if (flags & IUCV_IPRMDATA) {
  1190. parm->dpl.ippathid = path->pathid;
  1191. parm->dpl.ipflags1 = flags;
  1192. parm->dpl.ipmsgid = msg->id;
  1193. parm->dpl.iptrgcls = msg->class;
  1194. memcpy(parm->dpl.iprmmsg, reply, min_t(size_t, size, 8));
  1195. } else {
  1196. parm->db.ipbfadr1 = (u32)(addr_t) reply;
  1197. parm->db.ipbfln1f = (u32) size;
  1198. parm->db.ippathid = path->pathid;
  1199. parm->db.ipflags1 = flags;
  1200. parm->db.ipmsgid = msg->id;
  1201. parm->db.iptrgcls = msg->class;
  1202. }
  1203. rc = iucv_call_b2f0(IUCV_REPLY, parm);
  1204. out:
  1205. local_bh_enable();
  1206. return rc;
  1207. }
  1208. EXPORT_SYMBOL(iucv_message_reply);
  1209. /**
  1210. * __iucv_message_send
  1211. * @path: address of iucv path structure
  1212. * @msg: address of iucv msg structure
  1213. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1214. * @srccls: source class of message
  1215. * @buffer: address of send buffer or address of struct iucv_array
  1216. * @size: length of send buffer
  1217. *
  1218. * This function transmits data to another application. Data to be
  1219. * transmitted is in a buffer and this is a one-way message and the
  1220. * receiver will not reply to the message.
  1221. *
  1222. * Locking: no locking
  1223. *
  1224. * Returns the result from the CP IUCV call.
  1225. */
  1226. int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1227. u8 flags, u32 srccls, void *buffer, size_t size)
  1228. {
  1229. union iucv_param *parm;
  1230. int rc;
  1231. if (cpumask_empty(&iucv_buffer_cpumask)) {
  1232. rc = -EIO;
  1233. goto out;
  1234. }
  1235. parm = iucv_param[smp_processor_id()];
  1236. memset(parm, 0, sizeof(union iucv_param));
  1237. if (flags & IUCV_IPRMDATA) {
  1238. /* Message of 8 bytes can be placed into the parameter list. */
  1239. parm->dpl.ippathid = path->pathid;
  1240. parm->dpl.ipflags1 = flags | IUCV_IPNORPY;
  1241. parm->dpl.iptrgcls = msg->class;
  1242. parm->dpl.ipsrccls = srccls;
  1243. parm->dpl.ipmsgtag = msg->tag;
  1244. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1245. } else {
  1246. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1247. parm->db.ipbfln1f = (u32) size;
  1248. parm->db.ippathid = path->pathid;
  1249. parm->db.ipflags1 = flags | IUCV_IPNORPY;
  1250. parm->db.iptrgcls = msg->class;
  1251. parm->db.ipsrccls = srccls;
  1252. parm->db.ipmsgtag = msg->tag;
  1253. }
  1254. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1255. if (!rc)
  1256. msg->id = parm->db.ipmsgid;
  1257. out:
  1258. return rc;
  1259. }
  1260. EXPORT_SYMBOL(__iucv_message_send);
  1261. /**
  1262. * iucv_message_send
  1263. * @path: address of iucv path structure
  1264. * @msg: address of iucv msg structure
  1265. * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
  1266. * @srccls: source class of message
  1267. * @buffer: address of send buffer or address of struct iucv_array
  1268. * @size: length of send buffer
  1269. *
  1270. * This function transmits data to another application. Data to be
  1271. * transmitted is in a buffer and this is a one-way message and the
  1272. * receiver will not reply to the message.
  1273. *
  1274. * Locking: local_bh_enable/local_bh_disable
  1275. *
  1276. * Returns the result from the CP IUCV call.
  1277. */
  1278. int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
  1279. u8 flags, u32 srccls, void *buffer, size_t size)
  1280. {
  1281. int rc;
  1282. local_bh_disable();
  1283. rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
  1284. local_bh_enable();
  1285. return rc;
  1286. }
  1287. EXPORT_SYMBOL(iucv_message_send);
  1288. /**
  1289. * iucv_message_send2way
  1290. * @path: address of iucv path structure
  1291. * @msg: address of iucv msg structure
  1292. * @flags: how the message is sent and the reply is received
  1293. * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST)
  1294. * @srccls: source class of message
  1295. * @buffer: address of send buffer or address of struct iucv_array
  1296. * @size: length of send buffer
  1297. * @ansbuf: address of answer buffer or address of struct iucv_array
  1298. * @asize: size of reply buffer
  1299. *
  1300. * This function transmits data to another application. Data to be
  1301. * transmitted is in a buffer. The receiver of the send is expected to
  1302. * reply to the message and a buffer is provided into which IUCV moves
  1303. * the reply to this message.
  1304. *
  1305. * Returns the result from the CP IUCV call.
  1306. */
  1307. int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
  1308. u8 flags, u32 srccls, void *buffer, size_t size,
  1309. void *answer, size_t asize, size_t *residual)
  1310. {
  1311. union iucv_param *parm;
  1312. int rc;
  1313. local_bh_disable();
  1314. if (cpumask_empty(&iucv_buffer_cpumask)) {
  1315. rc = -EIO;
  1316. goto out;
  1317. }
  1318. parm = iucv_param[smp_processor_id()];
  1319. memset(parm, 0, sizeof(union iucv_param));
  1320. if (flags & IUCV_IPRMDATA) {
  1321. parm->dpl.ippathid = path->pathid;
  1322. parm->dpl.ipflags1 = path->flags; /* priority message */
  1323. parm->dpl.iptrgcls = msg->class;
  1324. parm->dpl.ipsrccls = srccls;
  1325. parm->dpl.ipmsgtag = msg->tag;
  1326. parm->dpl.ipbfadr2 = (u32)(addr_t) answer;
  1327. parm->dpl.ipbfln2f = (u32) asize;
  1328. memcpy(parm->dpl.iprmmsg, buffer, 8);
  1329. } else {
  1330. parm->db.ippathid = path->pathid;
  1331. parm->db.ipflags1 = path->flags; /* priority message */
  1332. parm->db.iptrgcls = msg->class;
  1333. parm->db.ipsrccls = srccls;
  1334. parm->db.ipmsgtag = msg->tag;
  1335. parm->db.ipbfadr1 = (u32)(addr_t) buffer;
  1336. parm->db.ipbfln1f = (u32) size;
  1337. parm->db.ipbfadr2 = (u32)(addr_t) answer;
  1338. parm->db.ipbfln2f = (u32) asize;
  1339. }
  1340. rc = iucv_call_b2f0(IUCV_SEND, parm);
  1341. if (!rc)
  1342. msg->id = parm->db.ipmsgid;
  1343. out:
  1344. local_bh_enable();
  1345. return rc;
  1346. }
  1347. EXPORT_SYMBOL(iucv_message_send2way);
  1348. /**
  1349. * iucv_path_pending
  1350. * @data: Pointer to external interrupt buffer
  1351. *
  1352. * Process connection pending work item. Called from tasklet while holding
  1353. * iucv_table_lock.
  1354. */
  1355. struct iucv_path_pending {
  1356. u16 ippathid;
  1357. u8 ipflags1;
  1358. u8 iptype;
  1359. u16 ipmsglim;
  1360. u16 res1;
  1361. u8 ipvmid[8];
  1362. u8 ipuser[16];
  1363. u32 res3;
  1364. u8 ippollfg;
  1365. u8 res4[3];
  1366. } __packed;
  1367. static void iucv_path_pending(struct iucv_irq_data *data)
  1368. {
  1369. struct iucv_path_pending *ipp = (void *) data;
  1370. struct iucv_handler *handler;
  1371. struct iucv_path *path;
  1372. char *error;
  1373. BUG_ON(iucv_path_table[ipp->ippathid]);
  1374. /* New pathid, handler found. Create a new path struct. */
  1375. error = iucv_error_no_memory;
  1376. path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC);
  1377. if (!path)
  1378. goto out_sever;
  1379. path->pathid = ipp->ippathid;
  1380. iucv_path_table[path->pathid] = path;
  1381. EBCASC(ipp->ipvmid, 8);
  1382. /* Call registered handler until one is found that wants the path. */
  1383. list_for_each_entry(handler, &iucv_handler_list, list) {
  1384. if (!handler->path_pending)
  1385. continue;
  1386. /*
  1387. * Add path to handler to allow a call to iucv_path_sever
  1388. * inside the path_pending function. If the handler returns
  1389. * an error remove the path from the handler again.
  1390. */
  1391. list_add(&path->list, &handler->paths);
  1392. path->handler = handler;
  1393. if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser))
  1394. return;
  1395. list_del(&path->list);
  1396. path->handler = NULL;
  1397. }
  1398. /* No handler wanted the path. */
  1399. iucv_path_table[path->pathid] = NULL;
  1400. iucv_path_free(path);
  1401. error = iucv_error_no_listener;
  1402. out_sever:
  1403. iucv_sever_pathid(ipp->ippathid, error);
  1404. }
  1405. /**
  1406. * iucv_path_complete
  1407. * @data: Pointer to external interrupt buffer
  1408. *
  1409. * Process connection complete work item. Called from tasklet while holding
  1410. * iucv_table_lock.
  1411. */
  1412. struct iucv_path_complete {
  1413. u16 ippathid;
  1414. u8 ipflags1;
  1415. u8 iptype;
  1416. u16 ipmsglim;
  1417. u16 res1;
  1418. u8 res2[8];
  1419. u8 ipuser[16];
  1420. u32 res3;
  1421. u8 ippollfg;
  1422. u8 res4[3];
  1423. } __packed;
  1424. static void iucv_path_complete(struct iucv_irq_data *data)
  1425. {
  1426. struct iucv_path_complete *ipc = (void *) data;
  1427. struct iucv_path *path = iucv_path_table[ipc->ippathid];
  1428. if (path)
  1429. path->flags = ipc->ipflags1;
  1430. if (path && path->handler && path->handler->path_complete)
  1431. path->handler->path_complete(path, ipc->ipuser);
  1432. }
  1433. /**
  1434. * iucv_path_severed
  1435. * @data: Pointer to external interrupt buffer
  1436. *
  1437. * Process connection severed work item. Called from tasklet while holding
  1438. * iucv_table_lock.
  1439. */
  1440. struct iucv_path_severed {
  1441. u16 ippathid;
  1442. u8 res1;
  1443. u8 iptype;
  1444. u32 res2;
  1445. u8 res3[8];
  1446. u8 ipuser[16];
  1447. u32 res4;
  1448. u8 ippollfg;
  1449. u8 res5[3];
  1450. } __packed;
  1451. static void iucv_path_severed(struct iucv_irq_data *data)
  1452. {
  1453. struct iucv_path_severed *ips = (void *) data;
  1454. struct iucv_path *path = iucv_path_table[ips->ippathid];
  1455. if (!path || !path->handler) /* Already severed */
  1456. return;
  1457. if (path->handler->path_severed)
  1458. path->handler->path_severed(path, ips->ipuser);
  1459. else {
  1460. iucv_sever_pathid(path->pathid, NULL);
  1461. iucv_path_table[path->pathid] = NULL;
  1462. list_del(&path->list);
  1463. iucv_path_free(path);
  1464. }
  1465. }
  1466. /**
  1467. * iucv_path_quiesced
  1468. * @data: Pointer to external interrupt buffer
  1469. *
  1470. * Process connection quiesced work item. Called from tasklet while holding
  1471. * iucv_table_lock.
  1472. */
  1473. struct iucv_path_quiesced {
  1474. u16 ippathid;
  1475. u8 res1;
  1476. u8 iptype;
  1477. u32 res2;
  1478. u8 res3[8];
  1479. u8 ipuser[16];
  1480. u32 res4;
  1481. u8 ippollfg;
  1482. u8 res5[3];
  1483. } __packed;
  1484. static void iucv_path_quiesced(struct iucv_irq_data *data)
  1485. {
  1486. struct iucv_path_quiesced *ipq = (void *) data;
  1487. struct iucv_path *path = iucv_path_table[ipq->ippathid];
  1488. if (path && path->handler && path->handler->path_quiesced)
  1489. path->handler->path_quiesced(path, ipq->ipuser);
  1490. }
  1491. /**
  1492. * iucv_path_resumed
  1493. * @data: Pointer to external interrupt buffer
  1494. *
  1495. * Process connection resumed work item. Called from tasklet while holding
  1496. * iucv_table_lock.
  1497. */
  1498. struct iucv_path_resumed {
  1499. u16 ippathid;
  1500. u8 res1;
  1501. u8 iptype;
  1502. u32 res2;
  1503. u8 res3[8];
  1504. u8 ipuser[16];
  1505. u32 res4;
  1506. u8 ippollfg;
  1507. u8 res5[3];
  1508. } __packed;
  1509. static void iucv_path_resumed(struct iucv_irq_data *data)
  1510. {
  1511. struct iucv_path_resumed *ipr = (void *) data;
  1512. struct iucv_path *path = iucv_path_table[ipr->ippathid];
  1513. if (path && path->handler && path->handler->path_resumed)
  1514. path->handler->path_resumed(path, ipr->ipuser);
  1515. }
  1516. /**
  1517. * iucv_message_complete
  1518. * @data: Pointer to external interrupt buffer
  1519. *
  1520. * Process message complete work item. Called from tasklet while holding
  1521. * iucv_table_lock.
  1522. */
  1523. struct iucv_message_complete {
  1524. u16 ippathid;
  1525. u8 ipflags1;
  1526. u8 iptype;
  1527. u32 ipmsgid;
  1528. u32 ipaudit;
  1529. u8 iprmmsg[8];
  1530. u32 ipsrccls;
  1531. u32 ipmsgtag;
  1532. u32 res;
  1533. u32 ipbfln2f;
  1534. u8 ippollfg;
  1535. u8 res2[3];
  1536. } __packed;
  1537. static void iucv_message_complete(struct iucv_irq_data *data)
  1538. {
  1539. struct iucv_message_complete *imc = (void *) data;
  1540. struct iucv_path *path = iucv_path_table[imc->ippathid];
  1541. struct iucv_message msg;
  1542. if (path && path->handler && path->handler->message_complete) {
  1543. msg.flags = imc->ipflags1;
  1544. msg.id = imc->ipmsgid;
  1545. msg.audit = imc->ipaudit;
  1546. memcpy(msg.rmmsg, imc->iprmmsg, 8);
  1547. msg.class = imc->ipsrccls;
  1548. msg.tag = imc->ipmsgtag;
  1549. msg.length = imc->ipbfln2f;
  1550. path->handler->message_complete(path, &msg);
  1551. }
  1552. }
  1553. /**
  1554. * iucv_message_pending
  1555. * @data: Pointer to external interrupt buffer
  1556. *
  1557. * Process message pending work item. Called from tasklet while holding
  1558. * iucv_table_lock.
  1559. */
  1560. struct iucv_message_pending {
  1561. u16 ippathid;
  1562. u8 ipflags1;
  1563. u8 iptype;
  1564. u32 ipmsgid;
  1565. u32 iptrgcls;
  1566. union {
  1567. u32 iprmmsg1_u32;
  1568. u8 iprmmsg1[4];
  1569. } ln1msg1;
  1570. union {
  1571. u32 ipbfln1f;
  1572. u8 iprmmsg2[4];
  1573. } ln1msg2;
  1574. u32 res1[3];
  1575. u32 ipbfln2f;
  1576. u8 ippollfg;
  1577. u8 res2[3];
  1578. } __packed;
  1579. static void iucv_message_pending(struct iucv_irq_data *data)
  1580. {
  1581. struct iucv_message_pending *imp = (void *) data;
  1582. struct iucv_path *path = iucv_path_table[imp->ippathid];
  1583. struct iucv_message msg;
  1584. if (path && path->handler && path->handler->message_pending) {
  1585. msg.flags = imp->ipflags1;
  1586. msg.id = imp->ipmsgid;
  1587. msg.class = imp->iptrgcls;
  1588. if (imp->ipflags1 & IUCV_IPRMDATA) {
  1589. memcpy(msg.rmmsg, imp->ln1msg1.iprmmsg1, 8);
  1590. msg.length = 8;
  1591. } else
  1592. msg.length = imp->ln1msg2.ipbfln1f;
  1593. msg.reply_size = imp->ipbfln2f;
  1594. path->handler->message_pending(path, &msg);
  1595. }
  1596. }
  1597. /**
  1598. * iucv_tasklet_fn:
  1599. *
  1600. * This tasklet loops over the queue of irq buffers created by
  1601. * iucv_external_interrupt, calls the appropriate action handler
  1602. * and then frees the buffer.
  1603. */
  1604. static void iucv_tasklet_fn(unsigned long ignored)
  1605. {
  1606. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1607. static iucv_irq_fn *irq_fn[] = {
  1608. [0x02] = iucv_path_complete,
  1609. [0x03] = iucv_path_severed,
  1610. [0x04] = iucv_path_quiesced,
  1611. [0x05] = iucv_path_resumed,
  1612. [0x06] = iucv_message_complete,
  1613. [0x07] = iucv_message_complete,
  1614. [0x08] = iucv_message_pending,
  1615. [0x09] = iucv_message_pending,
  1616. };
  1617. LIST_HEAD(task_queue);
  1618. struct iucv_irq_list *p, *n;
  1619. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1620. if (!spin_trylock(&iucv_table_lock)) {
  1621. tasklet_schedule(&iucv_tasklet);
  1622. return;
  1623. }
  1624. iucv_active_cpu = smp_processor_id();
  1625. spin_lock_irq(&iucv_queue_lock);
  1626. list_splice_init(&iucv_task_queue, &task_queue);
  1627. spin_unlock_irq(&iucv_queue_lock);
  1628. list_for_each_entry_safe(p, n, &task_queue, list) {
  1629. list_del_init(&p->list);
  1630. irq_fn[p->data.iptype](&p->data);
  1631. kfree(p);
  1632. }
  1633. iucv_active_cpu = -1;
  1634. spin_unlock(&iucv_table_lock);
  1635. }
  1636. /**
  1637. * iucv_work_fn:
  1638. *
  1639. * This work function loops over the queue of path pending irq blocks
  1640. * created by iucv_external_interrupt, calls the appropriate action
  1641. * handler and then frees the buffer.
  1642. */
  1643. static void iucv_work_fn(struct work_struct *work)
  1644. {
  1645. LIST_HEAD(work_queue);
  1646. struct iucv_irq_list *p, *n;
  1647. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1648. spin_lock_bh(&iucv_table_lock);
  1649. iucv_active_cpu = smp_processor_id();
  1650. spin_lock_irq(&iucv_queue_lock);
  1651. list_splice_init(&iucv_work_queue, &work_queue);
  1652. spin_unlock_irq(&iucv_queue_lock);
  1653. iucv_cleanup_queue();
  1654. list_for_each_entry_safe(p, n, &work_queue, list) {
  1655. list_del_init(&p->list);
  1656. iucv_path_pending(&p->data);
  1657. kfree(p);
  1658. }
  1659. iucv_active_cpu = -1;
  1660. spin_unlock_bh(&iucv_table_lock);
  1661. }
  1662. /**
  1663. * iucv_external_interrupt
  1664. * @code: irq code
  1665. *
  1666. * Handles external interrupts coming in from CP.
  1667. * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
  1668. */
  1669. static void iucv_external_interrupt(struct ext_code ext_code,
  1670. unsigned int param32, unsigned long param64)
  1671. {
  1672. struct iucv_irq_data *p;
  1673. struct iucv_irq_list *work;
  1674. inc_irq_stat(IRQEXT_IUC);
  1675. p = iucv_irq_data[smp_processor_id()];
  1676. if (p->ippathid >= iucv_max_pathid) {
  1677. WARN_ON(p->ippathid >= iucv_max_pathid);
  1678. iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
  1679. return;
  1680. }
  1681. BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
  1682. work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
  1683. if (!work) {
  1684. pr_warn("iucv_external_interrupt: out of memory\n");
  1685. return;
  1686. }
  1687. memcpy(&work->data, p, sizeof(work->data));
  1688. spin_lock(&iucv_queue_lock);
  1689. if (p->iptype == 0x01) {
  1690. /* Path pending interrupt. */
  1691. list_add_tail(&work->list, &iucv_work_queue);
  1692. schedule_work(&iucv_work);
  1693. } else {
  1694. /* The other interrupts. */
  1695. list_add_tail(&work->list, &iucv_task_queue);
  1696. tasklet_schedule(&iucv_tasklet);
  1697. }
  1698. spin_unlock(&iucv_queue_lock);
  1699. }
  1700. static int iucv_pm_prepare(struct device *dev)
  1701. {
  1702. int rc = 0;
  1703. #ifdef CONFIG_PM_DEBUG
  1704. printk(KERN_INFO "iucv_pm_prepare\n");
  1705. #endif
  1706. if (dev->driver && dev->driver->pm && dev->driver->pm->prepare)
  1707. rc = dev->driver->pm->prepare(dev);
  1708. return rc;
  1709. }
  1710. static void iucv_pm_complete(struct device *dev)
  1711. {
  1712. #ifdef CONFIG_PM_DEBUG
  1713. printk(KERN_INFO "iucv_pm_complete\n");
  1714. #endif
  1715. if (dev->driver && dev->driver->pm && dev->driver->pm->complete)
  1716. dev->driver->pm->complete(dev);
  1717. }
  1718. /**
  1719. * iucv_path_table_empty() - determine if iucv path table is empty
  1720. *
  1721. * Returns 0 if there are still iucv pathes defined
  1722. * 1 if there are no iucv pathes defined
  1723. */
  1724. int iucv_path_table_empty(void)
  1725. {
  1726. int i;
  1727. for (i = 0; i < iucv_max_pathid; i++) {
  1728. if (iucv_path_table[i])
  1729. return 0;
  1730. }
  1731. return 1;
  1732. }
  1733. /**
  1734. * iucv_pm_freeze() - Freeze PM callback
  1735. * @dev: iucv-based device
  1736. *
  1737. * disable iucv interrupts
  1738. * invoke callback function of the iucv-based driver
  1739. * shut down iucv, if no iucv-pathes are established anymore
  1740. */
  1741. static int iucv_pm_freeze(struct device *dev)
  1742. {
  1743. int cpu;
  1744. struct iucv_irq_list *p, *n;
  1745. int rc = 0;
  1746. #ifdef CONFIG_PM_DEBUG
  1747. printk(KERN_WARNING "iucv_pm_freeze\n");
  1748. #endif
  1749. if (iucv_pm_state != IUCV_PM_FREEZING) {
  1750. for_each_cpu(cpu, &iucv_irq_cpumask)
  1751. smp_call_function_single(cpu, iucv_block_cpu_almost,
  1752. NULL, 1);
  1753. cancel_work_sync(&iucv_work);
  1754. list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
  1755. list_del_init(&p->list);
  1756. iucv_sever_pathid(p->data.ippathid,
  1757. iucv_error_no_listener);
  1758. kfree(p);
  1759. }
  1760. }
  1761. iucv_pm_state = IUCV_PM_FREEZING;
  1762. if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
  1763. rc = dev->driver->pm->freeze(dev);
  1764. if (iucv_path_table_empty())
  1765. iucv_disable();
  1766. return rc;
  1767. }
  1768. /**
  1769. * iucv_pm_thaw() - Thaw PM callback
  1770. * @dev: iucv-based device
  1771. *
  1772. * make iucv ready for use again: allocate path table, declare interrupt buffers
  1773. * and enable iucv interrupts
  1774. * invoke callback function of the iucv-based driver
  1775. */
  1776. static int iucv_pm_thaw(struct device *dev)
  1777. {
  1778. int rc = 0;
  1779. #ifdef CONFIG_PM_DEBUG
  1780. printk(KERN_WARNING "iucv_pm_thaw\n");
  1781. #endif
  1782. iucv_pm_state = IUCV_PM_THAWING;
  1783. if (!iucv_path_table) {
  1784. rc = iucv_enable();
  1785. if (rc)
  1786. goto out;
  1787. }
  1788. if (cpumask_empty(&iucv_irq_cpumask)) {
  1789. if (iucv_nonsmp_handler)
  1790. /* enable interrupts on one cpu */
  1791. iucv_allow_cpu(NULL);
  1792. else
  1793. /* enable interrupts on all cpus */
  1794. iucv_setmask_mp();
  1795. }
  1796. if (dev->driver && dev->driver->pm && dev->driver->pm->thaw)
  1797. rc = dev->driver->pm->thaw(dev);
  1798. out:
  1799. return rc;
  1800. }
  1801. /**
  1802. * iucv_pm_restore() - Restore PM callback
  1803. * @dev: iucv-based device
  1804. *
  1805. * make iucv ready for use again: allocate path table, declare interrupt buffers
  1806. * and enable iucv interrupts
  1807. * invoke callback function of the iucv-based driver
  1808. */
  1809. static int iucv_pm_restore(struct device *dev)
  1810. {
  1811. int rc = 0;
  1812. #ifdef CONFIG_PM_DEBUG
  1813. printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
  1814. #endif
  1815. if ((iucv_pm_state != IUCV_PM_RESTORING) && iucv_path_table)
  1816. pr_warn("Suspending Linux did not completely close all IUCV connections\n");
  1817. iucv_pm_state = IUCV_PM_RESTORING;
  1818. if (cpumask_empty(&iucv_irq_cpumask)) {
  1819. rc = iucv_query_maxconn();
  1820. rc = iucv_enable();
  1821. if (rc)
  1822. goto out;
  1823. }
  1824. if (dev->driver && dev->driver->pm && dev->driver->pm->restore)
  1825. rc = dev->driver->pm->restore(dev);
  1826. out:
  1827. return rc;
  1828. }
  1829. struct iucv_interface iucv_if = {
  1830. .message_receive = iucv_message_receive,
  1831. .__message_receive = __iucv_message_receive,
  1832. .message_reply = iucv_message_reply,
  1833. .message_reject = iucv_message_reject,
  1834. .message_send = iucv_message_send,
  1835. .__message_send = __iucv_message_send,
  1836. .message_send2way = iucv_message_send2way,
  1837. .message_purge = iucv_message_purge,
  1838. .path_accept = iucv_path_accept,
  1839. .path_connect = iucv_path_connect,
  1840. .path_quiesce = iucv_path_quiesce,
  1841. .path_resume = iucv_path_resume,
  1842. .path_sever = iucv_path_sever,
  1843. .iucv_register = iucv_register,
  1844. .iucv_unregister = iucv_unregister,
  1845. .bus = NULL,
  1846. .root = NULL,
  1847. };
  1848. EXPORT_SYMBOL(iucv_if);
  1849. /**
  1850. * iucv_init
  1851. *
  1852. * Allocates and initializes various data structures.
  1853. */
  1854. static int __init iucv_init(void)
  1855. {
  1856. int rc;
  1857. int cpu;
  1858. if (!MACHINE_IS_VM) {
  1859. rc = -EPROTONOSUPPORT;
  1860. goto out;
  1861. }
  1862. ctl_set_bit(0, 1);
  1863. rc = iucv_query_maxconn();
  1864. if (rc)
  1865. goto out_ctl;
  1866. rc = register_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
  1867. if (rc)
  1868. goto out_ctl;
  1869. iucv_root = root_device_register("iucv");
  1870. if (IS_ERR(iucv_root)) {
  1871. rc = PTR_ERR(iucv_root);
  1872. goto out_int;
  1873. }
  1874. cpu_notifier_register_begin();
  1875. for_each_online_cpu(cpu) {
  1876. if (alloc_iucv_data(cpu)) {
  1877. rc = -ENOMEM;
  1878. goto out_free;
  1879. }
  1880. }
  1881. rc = __register_hotcpu_notifier(&iucv_cpu_notifier);
  1882. if (rc)
  1883. goto out_free;
  1884. cpu_notifier_register_done();
  1885. rc = register_reboot_notifier(&iucv_reboot_notifier);
  1886. if (rc)
  1887. goto out_cpu;
  1888. ASCEBC(iucv_error_no_listener, 16);
  1889. ASCEBC(iucv_error_no_memory, 16);
  1890. ASCEBC(iucv_error_pathid, 16);
  1891. iucv_available = 1;
  1892. rc = bus_register(&iucv_bus);
  1893. if (rc)
  1894. goto out_reboot;
  1895. iucv_if.root = iucv_root;
  1896. iucv_if.bus = &iucv_bus;
  1897. return 0;
  1898. out_reboot:
  1899. unregister_reboot_notifier(&iucv_reboot_notifier);
  1900. out_cpu:
  1901. cpu_notifier_register_begin();
  1902. __unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1903. out_free:
  1904. for_each_possible_cpu(cpu)
  1905. free_iucv_data(cpu);
  1906. cpu_notifier_register_done();
  1907. root_device_unregister(iucv_root);
  1908. out_int:
  1909. unregister_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
  1910. out_ctl:
  1911. ctl_clear_bit(0, 1);
  1912. out:
  1913. return rc;
  1914. }
  1915. /**
  1916. * iucv_exit
  1917. *
  1918. * Frees everything allocated from iucv_init.
  1919. */
  1920. static void __exit iucv_exit(void)
  1921. {
  1922. struct iucv_irq_list *p, *n;
  1923. int cpu;
  1924. spin_lock_irq(&iucv_queue_lock);
  1925. list_for_each_entry_safe(p, n, &iucv_task_queue, list)
  1926. kfree(p);
  1927. list_for_each_entry_safe(p, n, &iucv_work_queue, list)
  1928. kfree(p);
  1929. spin_unlock_irq(&iucv_queue_lock);
  1930. unregister_reboot_notifier(&iucv_reboot_notifier);
  1931. cpu_notifier_register_begin();
  1932. __unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1933. for_each_possible_cpu(cpu)
  1934. free_iucv_data(cpu);
  1935. cpu_notifier_register_done();
  1936. root_device_unregister(iucv_root);
  1937. bus_unregister(&iucv_bus);
  1938. unregister_external_irq(EXT_IRQ_IUCV, iucv_external_interrupt);
  1939. }
  1940. subsys_initcall(iucv_init);
  1941. module_exit(iucv_exit);
  1942. MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
  1943. MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
  1944. MODULE_LICENSE("GPL");