iucv.c 43 KB

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