iucv.c 53 KB

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