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