iucv.c 53 KB

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