iucv.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083
  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 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 NOTIFY_BAD;
  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 NOTIFY_BAD;
  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 NOTIFY_BAD;
  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 NOTIFY_BAD;
  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. } __attribute__ ((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. } __attribute__ ((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. } __attribute__ ((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. } __attribute__ ((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. } __attribute__ ((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. } __attribute__ ((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. } __attribute__ ((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. typedef void iucv_irq_fn(struct iucv_irq_data *);
  1635. LIST_HEAD(work_queue);
  1636. struct iucv_irq_list *p, *n;
  1637. /* Serialize tasklet, iucv_path_sever and iucv_path_connect. */
  1638. spin_lock_bh(&iucv_table_lock);
  1639. iucv_active_cpu = smp_processor_id();
  1640. spin_lock_irq(&iucv_queue_lock);
  1641. list_splice_init(&iucv_work_queue, &work_queue);
  1642. spin_unlock_irq(&iucv_queue_lock);
  1643. iucv_cleanup_queue();
  1644. list_for_each_entry_safe(p, n, &work_queue, list) {
  1645. list_del_init(&p->list);
  1646. iucv_path_pending(&p->data);
  1647. kfree(p);
  1648. }
  1649. iucv_active_cpu = -1;
  1650. spin_unlock_bh(&iucv_table_lock);
  1651. }
  1652. /**
  1653. * iucv_external_interrupt
  1654. * @code: irq code
  1655. *
  1656. * Handles external interrupts coming in from CP.
  1657. * Places the interrupt buffer on a queue and schedules iucv_tasklet_fn().
  1658. */
  1659. static void iucv_external_interrupt(u16 code)
  1660. {
  1661. struct iucv_irq_data *p;
  1662. struct iucv_irq_list *work;
  1663. p = iucv_irq_data[smp_processor_id()];
  1664. if (p->ippathid >= iucv_max_pathid) {
  1665. WARN_ON(p->ippathid >= iucv_max_pathid);
  1666. iucv_sever_pathid(p->ippathid, iucv_error_no_listener);
  1667. return;
  1668. }
  1669. BUG_ON(p->iptype < 0x01 || p->iptype > 0x09);
  1670. work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
  1671. if (!work) {
  1672. pr_warning("iucv_external_interrupt: out of memory\n");
  1673. return;
  1674. }
  1675. memcpy(&work->data, p, sizeof(work->data));
  1676. spin_lock(&iucv_queue_lock);
  1677. if (p->iptype == 0x01) {
  1678. /* Path pending interrupt. */
  1679. list_add_tail(&work->list, &iucv_work_queue);
  1680. schedule_work(&iucv_work);
  1681. } else {
  1682. /* The other interrupts. */
  1683. list_add_tail(&work->list, &iucv_task_queue);
  1684. tasklet_schedule(&iucv_tasklet);
  1685. }
  1686. spin_unlock(&iucv_queue_lock);
  1687. }
  1688. static int iucv_pm_prepare(struct device *dev)
  1689. {
  1690. int rc = 0;
  1691. #ifdef CONFIG_PM_DEBUG
  1692. printk(KERN_INFO "iucv_pm_prepare\n");
  1693. #endif
  1694. if (dev->driver && dev->driver->pm && dev->driver->pm->prepare)
  1695. rc = dev->driver->pm->prepare(dev);
  1696. return rc;
  1697. }
  1698. static void iucv_pm_complete(struct device *dev)
  1699. {
  1700. #ifdef CONFIG_PM_DEBUG
  1701. printk(KERN_INFO "iucv_pm_complete\n");
  1702. #endif
  1703. if (dev->driver && dev->driver->pm && dev->driver->pm->complete)
  1704. dev->driver->pm->complete(dev);
  1705. }
  1706. /**
  1707. * iucv_path_table_empty() - determine if iucv path table is empty
  1708. *
  1709. * Returns 0 if there are still iucv pathes defined
  1710. * 1 if there are no iucv pathes defined
  1711. */
  1712. int iucv_path_table_empty(void)
  1713. {
  1714. int i;
  1715. for (i = 0; i < iucv_max_pathid; i++) {
  1716. if (iucv_path_table[i])
  1717. return 0;
  1718. }
  1719. return 1;
  1720. }
  1721. /**
  1722. * iucv_pm_freeze() - Freeze PM callback
  1723. * @dev: iucv-based device
  1724. *
  1725. * disable iucv interrupts
  1726. * invoke callback function of the iucv-based driver
  1727. * shut down iucv, if no iucv-pathes are established anymore
  1728. */
  1729. static int iucv_pm_freeze(struct device *dev)
  1730. {
  1731. int cpu;
  1732. int rc = 0;
  1733. #ifdef CONFIG_PM_DEBUG
  1734. printk(KERN_WARNING "iucv_pm_freeze\n");
  1735. #endif
  1736. 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, NULL, 1);
  1739. if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
  1740. rc = dev->driver->pm->freeze(dev);
  1741. if (iucv_path_table_empty())
  1742. iucv_disable();
  1743. return rc;
  1744. }
  1745. /**
  1746. * iucv_pm_thaw() - Thaw PM callback
  1747. * @dev: iucv-based device
  1748. *
  1749. * make iucv ready for use again: allocate path table, declare interrupt buffers
  1750. * and enable iucv interrupts
  1751. * invoke callback function of the iucv-based driver
  1752. */
  1753. static int iucv_pm_thaw(struct device *dev)
  1754. {
  1755. int rc = 0;
  1756. #ifdef CONFIG_PM_DEBUG
  1757. printk(KERN_WARNING "iucv_pm_thaw\n");
  1758. #endif
  1759. iucv_pm_state = IUCV_PM_THAWING;
  1760. if (!iucv_path_table) {
  1761. rc = iucv_enable();
  1762. if (rc)
  1763. goto out;
  1764. }
  1765. if (cpus_empty(iucv_irq_cpumask)) {
  1766. if (iucv_nonsmp_handler)
  1767. /* enable interrupts on one cpu */
  1768. iucv_allow_cpu(NULL);
  1769. else
  1770. /* enable interrupts on all cpus */
  1771. iucv_setmask_mp();
  1772. }
  1773. if (dev->driver && dev->driver->pm && dev->driver->pm->thaw)
  1774. rc = dev->driver->pm->thaw(dev);
  1775. out:
  1776. return rc;
  1777. }
  1778. /**
  1779. * iucv_pm_restore() - Restore PM callback
  1780. * @dev: iucv-based device
  1781. *
  1782. * make iucv ready for use again: allocate path table, declare interrupt buffers
  1783. * and enable iucv interrupts
  1784. * invoke callback function of the iucv-based driver
  1785. */
  1786. static int iucv_pm_restore(struct device *dev)
  1787. {
  1788. int rc = 0;
  1789. #ifdef CONFIG_PM_DEBUG
  1790. printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
  1791. #endif
  1792. if ((iucv_pm_state != IUCV_PM_RESTORING) && iucv_path_table)
  1793. pr_warning("Suspending Linux did not completely close all IUCV "
  1794. "connections\n");
  1795. iucv_pm_state = IUCV_PM_RESTORING;
  1796. if (cpus_empty(iucv_irq_cpumask)) {
  1797. rc = iucv_query_maxconn();
  1798. rc = iucv_enable();
  1799. if (rc)
  1800. goto out;
  1801. }
  1802. if (dev->driver && dev->driver->pm && dev->driver->pm->restore)
  1803. rc = dev->driver->pm->restore(dev);
  1804. out:
  1805. return rc;
  1806. }
  1807. /**
  1808. * iucv_init
  1809. *
  1810. * Allocates and initializes various data structures.
  1811. */
  1812. static int __init iucv_init(void)
  1813. {
  1814. int rc;
  1815. int cpu;
  1816. if (!MACHINE_IS_VM) {
  1817. rc = -EPROTONOSUPPORT;
  1818. goto out;
  1819. }
  1820. rc = iucv_query_maxconn();
  1821. if (rc)
  1822. goto out;
  1823. rc = register_external_interrupt(0x4000, iucv_external_interrupt);
  1824. if (rc)
  1825. goto out;
  1826. iucv_root = root_device_register("iucv");
  1827. if (IS_ERR(iucv_root)) {
  1828. rc = PTR_ERR(iucv_root);
  1829. goto out_int;
  1830. }
  1831. for_each_online_cpu(cpu) {
  1832. /* Note: GFP_DMA used to get memory below 2G */
  1833. iucv_irq_data[cpu] = kmalloc_node(sizeof(struct iucv_irq_data),
  1834. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1835. if (!iucv_irq_data[cpu]) {
  1836. rc = -ENOMEM;
  1837. goto out_free;
  1838. }
  1839. /* Allocate parameter blocks. */
  1840. iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
  1841. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1842. if (!iucv_param[cpu]) {
  1843. rc = -ENOMEM;
  1844. goto out_free;
  1845. }
  1846. iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
  1847. GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
  1848. if (!iucv_param_irq[cpu]) {
  1849. rc = -ENOMEM;
  1850. goto out_free;
  1851. }
  1852. }
  1853. rc = register_hotcpu_notifier(&iucv_cpu_notifier);
  1854. if (rc)
  1855. goto out_free;
  1856. rc = register_reboot_notifier(&iucv_reboot_notifier);
  1857. if (rc)
  1858. goto out_cpu;
  1859. ASCEBC(iucv_error_no_listener, 16);
  1860. ASCEBC(iucv_error_no_memory, 16);
  1861. ASCEBC(iucv_error_pathid, 16);
  1862. iucv_available = 1;
  1863. rc = bus_register(&iucv_bus);
  1864. if (rc)
  1865. goto out_reboot;
  1866. return 0;
  1867. out_reboot:
  1868. unregister_reboot_notifier(&iucv_reboot_notifier);
  1869. out_cpu:
  1870. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1871. out_free:
  1872. for_each_possible_cpu(cpu) {
  1873. kfree(iucv_param_irq[cpu]);
  1874. iucv_param_irq[cpu] = NULL;
  1875. kfree(iucv_param[cpu]);
  1876. iucv_param[cpu] = NULL;
  1877. kfree(iucv_irq_data[cpu]);
  1878. iucv_irq_data[cpu] = NULL;
  1879. }
  1880. root_device_unregister(iucv_root);
  1881. out_int:
  1882. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1883. out:
  1884. return rc;
  1885. }
  1886. /**
  1887. * iucv_exit
  1888. *
  1889. * Frees everything allocated from iucv_init.
  1890. */
  1891. static void __exit iucv_exit(void)
  1892. {
  1893. struct iucv_irq_list *p, *n;
  1894. int cpu;
  1895. spin_lock_irq(&iucv_queue_lock);
  1896. list_for_each_entry_safe(p, n, &iucv_task_queue, list)
  1897. kfree(p);
  1898. list_for_each_entry_safe(p, n, &iucv_work_queue, list)
  1899. kfree(p);
  1900. spin_unlock_irq(&iucv_queue_lock);
  1901. unregister_reboot_notifier(&iucv_reboot_notifier);
  1902. unregister_hotcpu_notifier(&iucv_cpu_notifier);
  1903. for_each_possible_cpu(cpu) {
  1904. kfree(iucv_param_irq[cpu]);
  1905. iucv_param_irq[cpu] = NULL;
  1906. kfree(iucv_param[cpu]);
  1907. iucv_param[cpu] = NULL;
  1908. kfree(iucv_irq_data[cpu]);
  1909. iucv_irq_data[cpu] = NULL;
  1910. }
  1911. root_device_unregister(iucv_root);
  1912. bus_unregister(&iucv_bus);
  1913. unregister_external_interrupt(0x4000, iucv_external_interrupt);
  1914. }
  1915. subsys_initcall(iucv_init);
  1916. module_exit(iucv_exit);
  1917. MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)");
  1918. MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver");
  1919. MODULE_LICENSE("GPL");