iucv.c 53 KB

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