Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * IUCV network driver |
| 3 | * |
| 4 | * Copyright (C) 2001 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 | * |
| 12 | * Documentation used: |
| 13 | * The original source |
| 14 | * CP Programming Service, IBM document # SC24-5760 |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2, or (at your option) |
| 19 | * any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 29 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | /* #define DEBUG */ |
| 33 | |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/moduleparam.h> |
| 36 | #include <linux/config.h> |
| 37 | |
| 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 <asm/atomic.h> |
| 48 | #include "iucv.h" |
| 49 | #include <asm/io.h> |
| 50 | #include <asm/s390_ext.h> |
| 51 | #include <asm/ebcdic.h> |
| 52 | #include <asm/smp.h> |
Carsten Otte | cfb1b55 | 2006-01-06 00:19:14 -0800 | [diff] [blame] | 53 | #include <asm/s390_rdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* FLAGS: |
| 56 | * All flags are defined in the field IPFLAGS1 of each function |
| 57 | * and can be found in CP Programming Services. |
| 58 | * IPSRCCLS - Indicates you have specified a source class |
| 59 | * IPFGMCL - Indicates you have specified a target class |
| 60 | * IPFGPID - Indicates you have specified a pathid |
| 61 | * IPFGMID - Indicates you have specified a message ID |
| 62 | * IPANSLST - Indicates that you are using an address list for |
| 63 | * reply data |
| 64 | * IPBUFLST - Indicates that you are using an address list for |
| 65 | * message data |
| 66 | */ |
| 67 | |
| 68 | #define IPSRCCLS 0x01 |
| 69 | #define IPFGMCL 0x01 |
| 70 | #define IPFGPID 0x02 |
| 71 | #define IPFGMID 0x04 |
| 72 | #define IPANSLST 0x08 |
| 73 | #define IPBUFLST 0x40 |
| 74 | |
| 75 | static int |
| 76 | iucv_bus_match (struct device *dev, struct device_driver *drv) |
| 77 | { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | struct bus_type iucv_bus = { |
| 82 | .name = "iucv", |
| 83 | .match = iucv_bus_match, |
| 84 | }; |
| 85 | |
| 86 | struct device *iucv_root; |
| 87 | |
| 88 | /* General IUCV interrupt structure */ |
| 89 | typedef struct { |
| 90 | __u16 ippathid; |
| 91 | __u8 res1; |
| 92 | __u8 iptype; |
| 93 | __u32 res2; |
| 94 | __u8 ipvmid[8]; |
| 95 | __u8 res3[24]; |
| 96 | } iucv_GeneralInterrupt; |
| 97 | |
| 98 | static iucv_GeneralInterrupt *iucv_external_int_buffer = NULL; |
| 99 | |
| 100 | /* Spin Lock declaration */ |
| 101 | |
| 102 | static DEFINE_SPINLOCK(iucv_lock); |
| 103 | |
| 104 | static int messagesDisabled = 0; |
| 105 | |
| 106 | /***************INTERRUPT HANDLING ***************/ |
| 107 | |
| 108 | typedef struct { |
| 109 | struct list_head queue; |
| 110 | iucv_GeneralInterrupt data; |
| 111 | } iucv_irqdata; |
| 112 | |
| 113 | static struct list_head iucv_irq_queue; |
| 114 | static DEFINE_SPINLOCK(iucv_irq_queue_lock); |
| 115 | |
| 116 | /* |
| 117 | *Internal function prototypes |
| 118 | */ |
| 119 | static void iucv_tasklet_handler(unsigned long); |
| 120 | static void iucv_irq_handler(struct pt_regs *, __u16); |
| 121 | |
| 122 | static DECLARE_TASKLET(iucv_tasklet,iucv_tasklet_handler,0); |
| 123 | |
| 124 | /************ FUNCTION ID'S ****************************/ |
| 125 | |
| 126 | #define ACCEPT 10 |
| 127 | #define CONNECT 11 |
| 128 | #define DECLARE_BUFFER 12 |
| 129 | #define PURGE 9 |
| 130 | #define QUERY 0 |
| 131 | #define QUIESCE 13 |
| 132 | #define RECEIVE 5 |
| 133 | #define REJECT 8 |
| 134 | #define REPLY 6 |
| 135 | #define RESUME 14 |
| 136 | #define RETRIEVE_BUFFER 2 |
| 137 | #define SEND 4 |
| 138 | #define SETMASK 16 |
| 139 | #define SEVER 15 |
| 140 | |
| 141 | /** |
| 142 | * Structure: handler |
| 143 | * members: list - list management. |
| 144 | * structure: id |
| 145 | * userid - 8 char array of machine identification |
| 146 | * user_data - 16 char array for user identification |
| 147 | * mask - 24 char array used to compare the 2 previous |
| 148 | * interrupt_table - vector of interrupt functions. |
| 149 | * pgm_data - ulong, application data that is passed |
| 150 | * to the interrupt handlers |
| 151 | */ |
| 152 | typedef struct handler_t { |
| 153 | struct list_head list; |
| 154 | struct { |
| 155 | __u8 userid[8]; |
| 156 | __u8 user_data[16]; |
| 157 | __u8 mask[24]; |
| 158 | } id; |
| 159 | iucv_interrupt_ops_t *interrupt_table; |
| 160 | void *pgm_data; |
| 161 | } handler; |
| 162 | |
| 163 | /** |
| 164 | * iucv_handler_table: List of registered handlers. |
| 165 | */ |
| 166 | static struct list_head iucv_handler_table; |
| 167 | |
| 168 | /** |
| 169 | * iucv_pathid_table: an array of *handler pointing into |
| 170 | * iucv_handler_table for fast indexing by pathid; |
| 171 | */ |
| 172 | static handler **iucv_pathid_table; |
| 173 | |
| 174 | static unsigned long max_connections; |
| 175 | |
| 176 | /** |
| 177 | * iucv_cpuid: contains the logical cpu number of the cpu which |
| 178 | * has declared the iucv buffer by issuing DECLARE_BUFFER. |
| 179 | * If no cpu has done the initialization iucv_cpuid contains -1. |
| 180 | */ |
| 181 | static int iucv_cpuid = -1; |
| 182 | /** |
| 183 | * register_flag: is 0 when external interrupt has not been registered |
| 184 | */ |
| 185 | static int register_flag; |
| 186 | |
| 187 | /****************FIVE 40-BYTE PARAMETER STRUCTURES******************/ |
| 188 | /* Data struct 1: iparml_control |
| 189 | * Used for iucv_accept |
| 190 | * iucv_connect |
| 191 | * iucv_quiesce |
| 192 | * iucv_resume |
| 193 | * iucv_sever |
| 194 | * iucv_retrieve_buffer |
| 195 | * Data struct 2: iparml_dpl (data in parameter list) |
| 196 | * Used for iucv_send_prmmsg |
| 197 | * iucv_send2way_prmmsg |
| 198 | * iucv_send2way_prmmsg_array |
| 199 | * iucv_reply_prmmsg |
| 200 | * Data struct 3: iparml_db (data in a buffer) |
| 201 | * Used for iucv_receive |
| 202 | * iucv_receive_array |
| 203 | * iucv_reject |
| 204 | * iucv_reply |
| 205 | * iucv_reply_array |
| 206 | * iucv_send |
| 207 | * iucv_send_array |
| 208 | * iucv_send2way |
| 209 | * iucv_send2way_array |
| 210 | * iucv_declare_buffer |
| 211 | * Data struct 4: iparml_purge |
| 212 | * Used for iucv_purge |
| 213 | * iucv_query |
| 214 | * Data struct 5: iparml_set_mask |
| 215 | * Used for iucv_set_mask |
| 216 | */ |
| 217 | |
| 218 | typedef struct { |
| 219 | __u16 ippathid; |
| 220 | __u8 ipflags1; |
| 221 | __u8 iprcode; |
| 222 | __u16 ipmsglim; |
| 223 | __u16 res1; |
| 224 | __u8 ipvmid[8]; |
| 225 | __u8 ipuser[16]; |
| 226 | __u8 iptarget[8]; |
| 227 | } iparml_control; |
| 228 | |
| 229 | typedef struct { |
| 230 | __u16 ippathid; |
| 231 | __u8 ipflags1; |
| 232 | __u8 iprcode; |
| 233 | __u32 ipmsgid; |
| 234 | __u32 iptrgcls; |
| 235 | __u8 iprmmsg[8]; |
| 236 | __u32 ipsrccls; |
| 237 | __u32 ipmsgtag; |
| 238 | __u32 ipbfadr2; |
| 239 | __u32 ipbfln2f; |
| 240 | __u32 res; |
| 241 | } iparml_dpl; |
| 242 | |
| 243 | typedef struct { |
| 244 | __u16 ippathid; |
| 245 | __u8 ipflags1; |
| 246 | __u8 iprcode; |
| 247 | __u32 ipmsgid; |
| 248 | __u32 iptrgcls; |
| 249 | __u32 ipbfadr1; |
| 250 | __u32 ipbfln1f; |
| 251 | __u32 ipsrccls; |
| 252 | __u32 ipmsgtag; |
| 253 | __u32 ipbfadr2; |
| 254 | __u32 ipbfln2f; |
| 255 | __u32 res; |
| 256 | } iparml_db; |
| 257 | |
| 258 | typedef struct { |
| 259 | __u16 ippathid; |
| 260 | __u8 ipflags1; |
| 261 | __u8 iprcode; |
| 262 | __u32 ipmsgid; |
| 263 | __u8 ipaudit[3]; |
| 264 | __u8 res1[5]; |
| 265 | __u32 res2; |
| 266 | __u32 ipsrccls; |
| 267 | __u32 ipmsgtag; |
| 268 | __u32 res3[3]; |
| 269 | } iparml_purge; |
| 270 | |
| 271 | typedef struct { |
| 272 | __u8 ipmask; |
| 273 | __u8 res1[2]; |
| 274 | __u8 iprcode; |
| 275 | __u32 res2[9]; |
| 276 | } iparml_set_mask; |
| 277 | |
| 278 | typedef struct { |
| 279 | union { |
| 280 | iparml_control p_ctrl; |
| 281 | iparml_dpl p_dpl; |
| 282 | iparml_db p_db; |
| 283 | iparml_purge p_purge; |
| 284 | iparml_set_mask p_set_mask; |
| 285 | } param; |
| 286 | atomic_t in_use; |
| 287 | __u32 res; |
| 288 | } __attribute__ ((aligned(8))) iucv_param; |
| 289 | #define PARAM_POOL_SIZE (PAGE_SIZE / sizeof(iucv_param)) |
| 290 | |
| 291 | static iucv_param * iucv_param_pool; |
| 292 | |
| 293 | MODULE_AUTHOR("(C) 2001 IBM Corp. by Fritz Elfert (felfert@millenux.com)"); |
| 294 | MODULE_DESCRIPTION("Linux for S/390 IUCV lowlevel driver"); |
| 295 | MODULE_LICENSE("GPL"); |
| 296 | |
| 297 | /* |
| 298 | * Debugging stuff |
| 299 | *******************************************************************************/ |
| 300 | |
| 301 | |
| 302 | #ifdef DEBUG |
| 303 | static int debuglevel = 0; |
| 304 | |
| 305 | module_param(debuglevel, int, 0); |
| 306 | MODULE_PARM_DESC(debuglevel, |
| 307 | "Specifies the debug level (0=off ... 3=all)"); |
| 308 | |
| 309 | static void |
| 310 | iucv_dumpit(char *title, void *buf, int len) |
| 311 | { |
| 312 | int i; |
| 313 | __u8 *p = (__u8 *)buf; |
| 314 | |
| 315 | if (debuglevel < 3) |
| 316 | return; |
| 317 | |
| 318 | printk(KERN_DEBUG "%s\n", title); |
| 319 | printk(" "); |
| 320 | for (i = 0; i < len; i++) { |
| 321 | if (!(i % 16) && i != 0) |
| 322 | printk ("\n "); |
| 323 | else if (!(i % 4) && i != 0) |
| 324 | printk(" "); |
| 325 | printk("%02X", *p++); |
| 326 | } |
| 327 | if (len % 16) |
| 328 | printk ("\n"); |
| 329 | return; |
| 330 | } |
| 331 | #define iucv_debug(lvl, fmt, args...) \ |
| 332 | do { \ |
| 333 | if (debuglevel >= lvl) \ |
| 334 | printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__ , ## args); \ |
| 335 | } while (0) |
| 336 | |
| 337 | #else |
| 338 | |
| 339 | #define iucv_debug(lvl, fmt, args...) |
| 340 | #define iucv_dumpit(title, buf, len) |
| 341 | |
| 342 | #endif |
| 343 | |
| 344 | /* |
| 345 | * Internal functions |
| 346 | *******************************************************************************/ |
| 347 | |
| 348 | /** |
| 349 | * print start banner |
| 350 | */ |
| 351 | static void |
| 352 | iucv_banner(void) |
| 353 | { |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 354 | printk(KERN_INFO "IUCV lowlevel driver initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
| 358 | * iucv_init - Initialization |
| 359 | * |
| 360 | * Allocates and initializes various data structures. |
| 361 | */ |
| 362 | static int |
| 363 | iucv_init(void) |
| 364 | { |
| 365 | int ret; |
| 366 | |
| 367 | if (iucv_external_int_buffer) |
| 368 | return 0; |
| 369 | |
| 370 | if (!MACHINE_IS_VM) { |
| 371 | printk(KERN_ERR "IUCV: IUCV connection needs VM as base\n"); |
| 372 | return -EPROTONOSUPPORT; |
| 373 | } |
| 374 | |
| 375 | ret = bus_register(&iucv_bus); |
| 376 | if (ret) { |
| 377 | printk(KERN_ERR "IUCV: failed to register bus.\n"); |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | iucv_root = s390_root_dev_register("iucv"); |
| 382 | if (IS_ERR(iucv_root)) { |
| 383 | printk(KERN_ERR "IUCV: failed to register iucv root.\n"); |
| 384 | bus_unregister(&iucv_bus); |
| 385 | return PTR_ERR(iucv_root); |
| 386 | } |
| 387 | |
| 388 | /* Note: GFP_DMA used used to get memory below 2G */ |
| 389 | iucv_external_int_buffer = kmalloc(sizeof(iucv_GeneralInterrupt), |
| 390 | GFP_KERNEL|GFP_DMA); |
| 391 | if (!iucv_external_int_buffer) { |
| 392 | printk(KERN_WARNING |
| 393 | "%s: Could not allocate external interrupt buffer\n", |
| 394 | __FUNCTION__); |
| 395 | s390_root_dev_unregister(iucv_root); |
| 396 | bus_unregister(&iucv_bus); |
| 397 | return -ENOMEM; |
| 398 | } |
| 399 | memset(iucv_external_int_buffer, 0, sizeof(iucv_GeneralInterrupt)); |
| 400 | |
| 401 | /* Initialize parameter pool */ |
| 402 | iucv_param_pool = kmalloc(sizeof(iucv_param) * PARAM_POOL_SIZE, |
| 403 | GFP_KERNEL|GFP_DMA); |
| 404 | if (!iucv_param_pool) { |
| 405 | printk(KERN_WARNING "%s: Could not allocate param pool\n", |
| 406 | __FUNCTION__); |
| 407 | kfree(iucv_external_int_buffer); |
| 408 | iucv_external_int_buffer = NULL; |
| 409 | s390_root_dev_unregister(iucv_root); |
| 410 | bus_unregister(&iucv_bus); |
| 411 | return -ENOMEM; |
| 412 | } |
| 413 | memset(iucv_param_pool, 0, sizeof(iucv_param) * PARAM_POOL_SIZE); |
| 414 | |
| 415 | /* Initialize irq queue */ |
| 416 | INIT_LIST_HEAD(&iucv_irq_queue); |
| 417 | |
| 418 | /* Initialize handler table */ |
| 419 | INIT_LIST_HEAD(&iucv_handler_table); |
| 420 | |
| 421 | iucv_banner(); |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * iucv_exit - De-Initialization |
| 427 | * |
| 428 | * Frees everything allocated from iucv_init. |
| 429 | */ |
| 430 | static int iucv_retrieve_buffer (void); |
| 431 | |
| 432 | static void |
| 433 | iucv_exit(void) |
| 434 | { |
| 435 | iucv_retrieve_buffer(); |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 436 | kfree(iucv_external_int_buffer); |
| 437 | iucv_external_int_buffer = NULL; |
| 438 | kfree(iucv_param_pool); |
| 439 | iucv_param_pool = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | s390_root_dev_unregister(iucv_root); |
| 441 | bus_unregister(&iucv_bus); |
| 442 | printk(KERN_INFO "IUCV lowlevel driver unloaded\n"); |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * grab_param: - Get a parameter buffer from the pre-allocated pool. |
| 447 | * |
| 448 | * This function searches for an unused element in the pre-allocated pool |
| 449 | * of parameter buffers. If one is found, it marks it "in use" and returns |
| 450 | * a pointer to it. The calling function is responsible for releasing it |
| 451 | * when it has finished its usage. |
| 452 | * |
| 453 | * Returns: A pointer to iucv_param. |
| 454 | */ |
| 455 | static __inline__ iucv_param * |
| 456 | grab_param(void) |
| 457 | { |
| 458 | iucv_param *ptr; |
| 459 | static int hint = 0; |
| 460 | |
| 461 | ptr = iucv_param_pool + hint; |
| 462 | do { |
| 463 | ptr++; |
| 464 | if (ptr >= iucv_param_pool + PARAM_POOL_SIZE) |
| 465 | ptr = iucv_param_pool; |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 466 | } while (atomic_cmpxchg(&ptr->in_use, 0, 1) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | hint = ptr - iucv_param_pool; |
| 468 | |
| 469 | memset(&ptr->param, 0, sizeof(ptr->param)); |
| 470 | return ptr; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * release_param - Release a parameter buffer. |
| 475 | * @p: A pointer to a struct iucv_param, previously obtained by calling |
| 476 | * grab_param(). |
| 477 | * |
| 478 | * This function marks the specified parameter buffer "unused". |
| 479 | */ |
| 480 | static __inline__ void |
| 481 | release_param(void *p) |
| 482 | { |
| 483 | atomic_set(&((iucv_param *)p)->in_use, 0); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * iucv_add_handler: - Add a new handler |
| 488 | * @new_handler: handle that is being entered into chain. |
| 489 | * |
| 490 | * Places new handle on iucv_handler_table, if identical handler is not |
| 491 | * found. |
| 492 | * |
| 493 | * Returns: 0 on success, !0 on failure (handler already in chain). |
| 494 | */ |
| 495 | static int |
| 496 | iucv_add_handler (handler *new) |
| 497 | { |
| 498 | ulong flags; |
| 499 | |
| 500 | iucv_debug(1, "entering"); |
| 501 | iucv_dumpit("handler:", new, sizeof(handler)); |
| 502 | |
| 503 | spin_lock_irqsave (&iucv_lock, flags); |
| 504 | if (!list_empty(&iucv_handler_table)) { |
| 505 | struct list_head *lh; |
| 506 | |
| 507 | /** |
| 508 | * Search list for handler with identical id. If one |
| 509 | * is found, the new handler is _not_ added. |
| 510 | */ |
| 511 | list_for_each(lh, &iucv_handler_table) { |
| 512 | handler *h = list_entry(lh, handler, list); |
| 513 | if (!memcmp(&new->id, &h->id, sizeof(h->id))) { |
| 514 | iucv_debug(1, "ret 1"); |
| 515 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 516 | return 1; |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | /** |
| 521 | * If we get here, no handler was found. |
| 522 | */ |
| 523 | INIT_LIST_HEAD(&new->list); |
| 524 | list_add(&new->list, &iucv_handler_table); |
| 525 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 526 | |
| 527 | iucv_debug(1, "exiting"); |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * b2f0: |
| 533 | * @code: identifier of IUCV call to CP. |
| 534 | * @parm: pointer to 40 byte iparml area passed to CP |
| 535 | * |
| 536 | * Calls CP to execute IUCV commands. |
| 537 | * |
| 538 | * Returns: return code from CP's IUCV call |
| 539 | */ |
| 540 | static __inline__ ulong |
| 541 | b2f0(__u32 code, void *parm) |
| 542 | { |
| 543 | iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param)); |
| 544 | |
| 545 | asm volatile ( |
| 546 | "LRA 1,0(%1)\n\t" |
| 547 | "LR 0,%0\n\t" |
| 548 | ".long 0xb2f01000" |
| 549 | : |
| 550 | : "d" (code), "a" (parm) |
| 551 | : "0", "1" |
| 552 | ); |
| 553 | |
| 554 | iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param)); |
| 555 | |
| 556 | return (unsigned long)*((__u8 *)(parm + 3)); |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Name: iucv_add_pathid |
| 561 | * Purpose: Adds a path id to the system. |
| 562 | * Input: pathid - pathid that is going to be entered into system |
| 563 | * handle - address of handler that the pathid will be associated |
| 564 | * with. |
| 565 | * pgm_data - token passed in by application. |
| 566 | * Output: 0: successful addition of pathid |
| 567 | * - EINVAL - pathid entry is being used by another application |
| 568 | * - ENOMEM - storage allocation for a new pathid table failed |
| 569 | */ |
| 570 | static int |
| 571 | __iucv_add_pathid(__u16 pathid, handler *handler) |
| 572 | { |
| 573 | |
| 574 | iucv_debug(1, "entering"); |
| 575 | |
| 576 | iucv_debug(1, "handler is pointing to %p", handler); |
| 577 | |
| 578 | if (pathid > (max_connections - 1)) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | if (iucv_pathid_table[pathid]) { |
| 582 | iucv_debug(1, "pathid entry is %p", iucv_pathid_table[pathid]); |
| 583 | printk(KERN_WARNING |
| 584 | "%s: Pathid being used, error.\n", __FUNCTION__); |
| 585 | return -EINVAL; |
| 586 | } |
| 587 | iucv_pathid_table[pathid] = handler; |
| 588 | |
| 589 | iucv_debug(1, "exiting"); |
| 590 | return 0; |
| 591 | } /* end of add_pathid function */ |
| 592 | |
| 593 | static int |
| 594 | iucv_add_pathid(__u16 pathid, handler *handler) |
| 595 | { |
| 596 | ulong flags; |
| 597 | int rc; |
| 598 | |
| 599 | spin_lock_irqsave (&iucv_lock, flags); |
| 600 | rc = __iucv_add_pathid(pathid, handler); |
| 601 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 602 | return rc; |
| 603 | } |
| 604 | |
| 605 | static void |
| 606 | iucv_remove_pathid(__u16 pathid) |
| 607 | { |
| 608 | ulong flags; |
| 609 | |
| 610 | if (pathid > (max_connections - 1)) |
| 611 | return; |
| 612 | |
| 613 | spin_lock_irqsave (&iucv_lock, flags); |
| 614 | iucv_pathid_table[pathid] = NULL; |
| 615 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * iucv_declare_buffer_cpuid |
| 620 | * Register at VM for subsequent IUCV operations. This is executed |
| 621 | * on the reserved CPU iucv_cpuid. Called from iucv_declare_buffer(). |
| 622 | */ |
| 623 | static void |
| 624 | iucv_declare_buffer_cpuid (void *result) |
| 625 | { |
| 626 | iparml_db *parm; |
| 627 | |
| 628 | parm = (iparml_db *)grab_param(); |
| 629 | parm->ipbfadr1 = virt_to_phys(iucv_external_int_buffer); |
| 630 | if ((*((ulong *)result) = b2f0(DECLARE_BUFFER, parm)) == 1) |
| 631 | *((ulong *)result) = parm->iprcode; |
| 632 | release_param(parm); |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * iucv_retrieve_buffer_cpuid: |
| 637 | * Unregister IUCV usage at VM. This is always executed on the same |
| 638 | * cpu that registered the buffer to VM. |
| 639 | * Called from iucv_retrieve_buffer(). |
| 640 | */ |
| 641 | static void |
| 642 | iucv_retrieve_buffer_cpuid (void *cpu) |
| 643 | { |
| 644 | iparml_control *parm; |
| 645 | |
| 646 | parm = (iparml_control *)grab_param(); |
| 647 | b2f0(RETRIEVE_BUFFER, parm); |
| 648 | release_param(parm); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Name: iucv_declare_buffer |
| 653 | * Purpose: Specifies the guests real address of an external |
| 654 | * interrupt. |
| 655 | * Input: void |
| 656 | * Output: iprcode - return code from b2f0 call |
| 657 | */ |
| 658 | static int |
| 659 | iucv_declare_buffer (void) |
| 660 | { |
| 661 | unsigned long flags; |
| 662 | ulong b2f0_result; |
| 663 | |
| 664 | iucv_debug(1, "entering"); |
| 665 | b2f0_result = -ENODEV; |
| 666 | spin_lock_irqsave (&iucv_lock, flags); |
| 667 | if (iucv_cpuid == -1) { |
| 668 | /* Reserve any cpu for use by iucv. */ |
| 669 | iucv_cpuid = smp_get_cpu(CPU_MASK_ALL); |
| 670 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 671 | smp_call_function_on(iucv_declare_buffer_cpuid, |
| 672 | &b2f0_result, 0, 1, iucv_cpuid); |
| 673 | if (b2f0_result) { |
| 674 | smp_put_cpu(iucv_cpuid); |
| 675 | iucv_cpuid = -1; |
| 676 | } |
| 677 | iucv_debug(1, "Address of EIB = %p", iucv_external_int_buffer); |
| 678 | } else { |
| 679 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 680 | b2f0_result = 0; |
| 681 | } |
| 682 | iucv_debug(1, "exiting"); |
| 683 | return b2f0_result; |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * iucv_retrieve_buffer: |
| 688 | * |
| 689 | * Terminates all use of IUCV. |
| 690 | * Returns: return code from CP |
| 691 | */ |
| 692 | static int |
| 693 | iucv_retrieve_buffer (void) |
| 694 | { |
| 695 | iucv_debug(1, "entering"); |
| 696 | if (iucv_cpuid != -1) { |
| 697 | smp_call_function_on(iucv_retrieve_buffer_cpuid, |
| 698 | 0, 0, 1, iucv_cpuid); |
| 699 | /* Release the cpu reserved by iucv_declare_buffer. */ |
| 700 | smp_put_cpu(iucv_cpuid); |
| 701 | iucv_cpuid = -1; |
| 702 | } |
| 703 | iucv_debug(1, "exiting"); |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * iucv_remove_handler: |
| 709 | * @users_handler: handler to be removed |
| 710 | * |
| 711 | * Remove handler when application unregisters. |
| 712 | */ |
| 713 | static void |
| 714 | iucv_remove_handler(handler *handler) |
| 715 | { |
| 716 | unsigned long flags; |
| 717 | |
| 718 | if ((!iucv_pathid_table) || (!handler)) |
| 719 | return; |
| 720 | |
| 721 | iucv_debug(1, "entering"); |
| 722 | |
| 723 | spin_lock_irqsave (&iucv_lock, flags); |
| 724 | list_del(&handler->list); |
| 725 | if (list_empty(&iucv_handler_table)) { |
| 726 | if (register_flag) { |
| 727 | unregister_external_interrupt(0x4000, iucv_irq_handler); |
| 728 | register_flag = 0; |
| 729 | } |
| 730 | } |
| 731 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 732 | |
| 733 | iucv_debug(1, "exiting"); |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * iucv_register_program: |
| 739 | * @pgmname: user identification |
| 740 | * @userid: machine identification |
| 741 | * @pgmmask: Indicates which bits in the pgmname and userid combined will be |
| 742 | * used to determine who is given control. |
| 743 | * @ops: Address of interrupt handler table. |
| 744 | * @pgm_data: Application data to be passed to interrupt handlers. |
| 745 | * |
| 746 | * Registers an application with IUCV. |
| 747 | * Returns: |
| 748 | * The address of handler, or NULL on failure. |
| 749 | * NOTE on pgmmask: |
| 750 | * If pgmname, userid and pgmmask are provided, pgmmask is entered into the |
| 751 | * handler as is. |
| 752 | * If pgmmask is NULL, the internal mask is set to all 0xff's |
| 753 | * When userid is NULL, the first 8 bytes of the internal mask are forced |
| 754 | * to 0x00. |
| 755 | * If pgmmask and userid are NULL, the first 8 bytes of the internal mask |
| 756 | * are forced to 0x00 and the last 16 bytes to 0xff. |
| 757 | */ |
| 758 | |
| 759 | iucv_handle_t |
| 760 | iucv_register_program (__u8 pgmname[16], |
| 761 | __u8 userid[8], |
| 762 | __u8 pgmmask[24], |
| 763 | iucv_interrupt_ops_t * ops, void *pgm_data) |
| 764 | { |
| 765 | ulong rc = 0; /* return code from function calls */ |
| 766 | handler *new_handler; |
| 767 | |
| 768 | iucv_debug(1, "entering"); |
| 769 | |
| 770 | if (ops == NULL) { |
| 771 | /* interrupt table is not defined */ |
| 772 | printk(KERN_WARNING "%s: Interrupt table is not defined, " |
| 773 | "exiting\n", __FUNCTION__); |
| 774 | return NULL; |
| 775 | } |
| 776 | if (!pgmname) { |
| 777 | printk(KERN_WARNING "%s: pgmname not provided\n", __FUNCTION__); |
| 778 | return NULL; |
| 779 | } |
| 780 | |
| 781 | /* Allocate handler entry */ |
| 782 | new_handler = (handler *)kmalloc(sizeof(handler), GFP_ATOMIC); |
| 783 | if (new_handler == NULL) { |
| 784 | printk(KERN_WARNING "%s: storage allocation for new handler " |
| 785 | "failed.\n", __FUNCTION__); |
| 786 | return NULL; |
| 787 | } |
| 788 | |
| 789 | if (!iucv_pathid_table) { |
| 790 | if (iucv_init()) { |
| 791 | kfree(new_handler); |
| 792 | return NULL; |
| 793 | } |
| 794 | |
| 795 | max_connections = iucv_query_maxconn(); |
| 796 | iucv_pathid_table = kmalloc(max_connections * sizeof(handler *), |
| 797 | GFP_ATOMIC); |
| 798 | if (iucv_pathid_table == NULL) { |
| 799 | printk(KERN_WARNING "%s: iucv_pathid_table storage " |
| 800 | "allocation failed\n", __FUNCTION__); |
| 801 | kfree(new_handler); |
| 802 | return NULL; |
| 803 | } |
| 804 | memset (iucv_pathid_table, 0, max_connections * sizeof(handler *)); |
| 805 | } |
| 806 | memset(new_handler, 0, sizeof (handler)); |
| 807 | memcpy(new_handler->id.user_data, pgmname, |
| 808 | sizeof (new_handler->id.user_data)); |
| 809 | if (userid) { |
| 810 | memcpy (new_handler->id.userid, userid, |
| 811 | sizeof (new_handler->id.userid)); |
| 812 | ASCEBC (new_handler->id.userid, |
| 813 | sizeof (new_handler->id.userid)); |
| 814 | EBC_TOUPPER (new_handler->id.userid, |
| 815 | sizeof (new_handler->id.userid)); |
| 816 | |
| 817 | if (pgmmask) { |
| 818 | memcpy (new_handler->id.mask, pgmmask, |
| 819 | sizeof (new_handler->id.mask)); |
| 820 | } else { |
| 821 | memset (new_handler->id.mask, 0xFF, |
| 822 | sizeof (new_handler->id.mask)); |
| 823 | } |
| 824 | } else { |
| 825 | if (pgmmask) { |
| 826 | memcpy (new_handler->id.mask, pgmmask, |
| 827 | sizeof (new_handler->id.mask)); |
| 828 | } else { |
| 829 | memset (new_handler->id.mask, 0xFF, |
| 830 | sizeof (new_handler->id.mask)); |
| 831 | } |
| 832 | memset (new_handler->id.userid, 0x00, |
| 833 | sizeof (new_handler->id.userid)); |
| 834 | } |
| 835 | /* fill in the rest of handler */ |
| 836 | new_handler->pgm_data = pgm_data; |
| 837 | new_handler->interrupt_table = ops; |
| 838 | |
| 839 | /* |
| 840 | * Check if someone else is registered with same pgmname, userid |
| 841 | * and mask. If someone is already registered with same pgmname, |
| 842 | * userid and mask, registration will fail and NULL will be returned |
| 843 | * to the application. |
| 844 | * If identical handler not found, then handler is added to list. |
| 845 | */ |
| 846 | rc = iucv_add_handler(new_handler); |
| 847 | if (rc) { |
| 848 | printk(KERN_WARNING "%s: Someone already registered with same " |
| 849 | "pgmname, userid, pgmmask\n", __FUNCTION__); |
| 850 | kfree (new_handler); |
| 851 | return NULL; |
| 852 | } |
| 853 | |
| 854 | rc = iucv_declare_buffer(); |
| 855 | if (rc) { |
| 856 | char *err = "Unknown"; |
| 857 | iucv_remove_handler(new_handler); |
| 858 | kfree(new_handler); |
| 859 | switch(rc) { |
| 860 | case 0x03: |
| 861 | err = "Directory error"; |
| 862 | break; |
| 863 | case 0x0a: |
| 864 | err = "Invalid length"; |
| 865 | break; |
| 866 | case 0x13: |
| 867 | err = "Buffer already exists"; |
| 868 | break; |
| 869 | case 0x3e: |
| 870 | err = "Buffer overlap"; |
| 871 | break; |
| 872 | case 0x5c: |
| 873 | err = "Paging or storage error"; |
| 874 | break; |
| 875 | } |
| 876 | printk(KERN_WARNING "%s: iucv_declare_buffer " |
| 877 | "returned error 0x%02lx (%s)\n", __FUNCTION__, rc, err); |
| 878 | return NULL; |
| 879 | } |
| 880 | if (!register_flag) { |
| 881 | /* request the 0x4000 external interrupt */ |
| 882 | rc = register_external_interrupt (0x4000, iucv_irq_handler); |
| 883 | if (rc) { |
| 884 | iucv_remove_handler(new_handler); |
| 885 | kfree (new_handler); |
| 886 | printk(KERN_WARNING "%s: " |
| 887 | "register_external_interrupt returned %ld\n", |
| 888 | __FUNCTION__, rc); |
| 889 | return NULL; |
| 890 | |
| 891 | } |
| 892 | register_flag = 1; |
| 893 | } |
| 894 | iucv_debug(1, "exiting"); |
| 895 | return new_handler; |
| 896 | } /* end of register function */ |
| 897 | |
| 898 | /** |
| 899 | * iucv_unregister_program: |
| 900 | * @handle: address of handler |
| 901 | * |
| 902 | * Unregister application with IUCV. |
| 903 | * Returns: |
| 904 | * 0 on success, -EINVAL, if specified handle is invalid. |
| 905 | */ |
| 906 | |
| 907 | int |
| 908 | iucv_unregister_program (iucv_handle_t handle) |
| 909 | { |
| 910 | handler *h = NULL; |
| 911 | struct list_head *lh; |
| 912 | int i; |
| 913 | ulong flags; |
| 914 | |
| 915 | iucv_debug(1, "entering"); |
| 916 | iucv_debug(1, "address of handler is %p", h); |
| 917 | |
| 918 | /* Checking if handle is valid */ |
| 919 | spin_lock_irqsave (&iucv_lock, flags); |
| 920 | list_for_each(lh, &iucv_handler_table) { |
| 921 | if ((handler *)handle == list_entry(lh, handler, list)) { |
| 922 | h = (handler *)handle; |
| 923 | break; |
| 924 | } |
| 925 | } |
| 926 | if (!h) { |
| 927 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 928 | if (handle) |
| 929 | printk(KERN_WARNING |
| 930 | "%s: Handler not found in iucv_handler_table.\n", |
| 931 | __FUNCTION__); |
| 932 | else |
| 933 | printk(KERN_WARNING |
| 934 | "%s: NULL handle passed by application.\n", |
| 935 | __FUNCTION__); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * First, walk thru iucv_pathid_table and sever any pathid which is |
| 941 | * still pointing to the handler to be removed. |
| 942 | */ |
| 943 | for (i = 0; i < max_connections; i++) |
| 944 | if (iucv_pathid_table[i] == h) { |
| 945 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 946 | iucv_sever(i, h->id.user_data); |
| 947 | spin_lock_irqsave(&iucv_lock, flags); |
| 948 | } |
| 949 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 950 | |
| 951 | iucv_remove_handler(h); |
| 952 | kfree(h); |
| 953 | |
| 954 | iucv_debug(1, "exiting"); |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * iucv_accept: |
| 960 | * @pathid: Path identification number |
| 961 | * @msglim_reqstd: The number of outstanding messages requested. |
| 962 | * @user_data: Data specified by the iucv_connect function. |
| 963 | * @flags1: Contains options for this path. |
| 964 | * - IPPRTY (0x20) Specifies if you want to send priority message. |
| 965 | * - IPRMDATA (0x80) Specifies whether your program can handle a message |
| 966 | * in the parameter list. |
| 967 | * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being |
| 968 | * established. |
| 969 | * @handle: Address of handler. |
| 970 | * @pgm_data: Application data passed to interrupt handlers. |
| 971 | * @flags1_out: Pointer to an int. If not NULL, on return the options for |
| 972 | * the path are stored at the given location: |
| 973 | * - IPPRTY (0x20) Indicates you may send a priority message. |
| 974 | * @msglim: Pointer to an __u16. If not NULL, on return the maximum |
| 975 | * number of outstanding messages is stored at the given |
| 976 | * location. |
| 977 | * |
| 978 | * This function is issued after the user receives a Connection Pending external |
| 979 | * interrupt and now wishes to complete the IUCV communication path. |
| 980 | * Returns: |
| 981 | * return code from CP |
| 982 | */ |
| 983 | int |
| 984 | iucv_accept(__u16 pathid, __u16 msglim_reqstd, |
| 985 | __u8 user_data[16], int flags1, |
| 986 | iucv_handle_t handle, void *pgm_data, |
| 987 | int *flags1_out, __u16 * msglim) |
| 988 | { |
| 989 | ulong b2f0_result = 0; |
| 990 | ulong flags; |
| 991 | struct list_head *lh; |
| 992 | handler *h = NULL; |
| 993 | iparml_control *parm; |
| 994 | |
| 995 | iucv_debug(1, "entering"); |
| 996 | iucv_debug(1, "pathid = %d", pathid); |
| 997 | |
| 998 | /* Checking if handle is valid */ |
| 999 | spin_lock_irqsave (&iucv_lock, flags); |
| 1000 | list_for_each(lh, &iucv_handler_table) { |
| 1001 | if ((handler *)handle == list_entry(lh, handler, list)) { |
| 1002 | h = (handler *)handle; |
| 1003 | break; |
| 1004 | } |
| 1005 | } |
| 1006 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 1007 | |
| 1008 | if (!h) { |
| 1009 | if (handle) |
| 1010 | printk(KERN_WARNING |
| 1011 | "%s: Handler not found in iucv_handler_table.\n", |
| 1012 | __FUNCTION__); |
| 1013 | else |
| 1014 | printk(KERN_WARNING |
| 1015 | "%s: NULL handle passed by application.\n", |
| 1016 | __FUNCTION__); |
| 1017 | return -EINVAL; |
| 1018 | } |
| 1019 | |
| 1020 | parm = (iparml_control *)grab_param(); |
| 1021 | |
| 1022 | parm->ippathid = pathid; |
| 1023 | parm->ipmsglim = msglim_reqstd; |
| 1024 | if (user_data) |
| 1025 | memcpy(parm->ipuser, user_data, sizeof(parm->ipuser)); |
| 1026 | |
| 1027 | parm->ipflags1 = (__u8)flags1; |
| 1028 | b2f0_result = b2f0(ACCEPT, parm); |
| 1029 | |
| 1030 | if (!b2f0_result) { |
| 1031 | if (msglim) |
| 1032 | *msglim = parm->ipmsglim; |
| 1033 | if (pgm_data) |
| 1034 | h->pgm_data = pgm_data; |
| 1035 | if (flags1_out) |
| 1036 | *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0; |
| 1037 | } |
| 1038 | release_param(parm); |
| 1039 | |
| 1040 | iucv_debug(1, "exiting"); |
| 1041 | return b2f0_result; |
| 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * iucv_connect: |
| 1046 | * @pathid: Path identification number |
| 1047 | * @msglim_reqstd: Number of outstanding messages requested |
| 1048 | * @user_data: 16-byte user data |
| 1049 | * @userid: 8-byte of user identification |
| 1050 | * @system_name: 8-byte identifying the system name |
| 1051 | * @flags1: Specifies options for this path: |
| 1052 | * - IPPRTY (0x20) Specifies if you want to send priority message. |
| 1053 | * - IPRMDATA (0x80) Specifies whether your program can handle a message |
| 1054 | * in the parameter list. |
| 1055 | * - IPQUSCE (0x40) Specifies whether you want to quiesce the path being |
| 1056 | * established. |
| 1057 | * - IPLOCAL (0x01) Allows an application to force the partner to be on the |
| 1058 | * local system. If local is specified then target class |
| 1059 | * cannot be specified. |
| 1060 | * @flags1_out: Pointer to an int. If not NULL, on return the options for |
| 1061 | * the path are stored at the given location: |
| 1062 | * - IPPRTY (0x20) Indicates you may send a priority message. |
| 1063 | * @msglim: Pointer to an __u16. If not NULL, on return the maximum |
| 1064 | * number of outstanding messages is stored at the given |
| 1065 | * location. |
| 1066 | * @handle: Address of handler. |
| 1067 | * @pgm_data: Application data to be passed to interrupt handlers. |
| 1068 | * |
| 1069 | * This function establishes an IUCV path. Although the connect may complete |
| 1070 | * successfully, you are not able to use the path until you receive an IUCV |
| 1071 | * Connection Complete external interrupt. |
| 1072 | * Returns: return code from CP, or one of the following |
| 1073 | * - ENOMEM |
| 1074 | * - return code from iucv_declare_buffer |
| 1075 | * - EINVAL - invalid handle passed by application |
| 1076 | * - EINVAL - pathid address is NULL |
| 1077 | * - ENOMEM - pathid table storage allocation failed |
| 1078 | * - return code from internal function add_pathid |
| 1079 | */ |
| 1080 | int |
| 1081 | iucv_connect (__u16 *pathid, __u16 msglim_reqstd, |
| 1082 | __u8 user_data[16], __u8 userid[8], |
| 1083 | __u8 system_name[8], int flags1, |
| 1084 | int *flags1_out, __u16 * msglim, |
| 1085 | iucv_handle_t handle, void *pgm_data) |
| 1086 | { |
| 1087 | iparml_control *parm; |
| 1088 | iparml_control local_parm; |
| 1089 | struct list_head *lh; |
| 1090 | ulong b2f0_result = 0; |
| 1091 | ulong flags; |
| 1092 | int add_pathid_result = 0; |
| 1093 | handler *h = NULL; |
| 1094 | __u8 no_memory[16] = "NO MEMORY"; |
| 1095 | |
| 1096 | iucv_debug(1, "entering"); |
| 1097 | |
| 1098 | /* Checking if handle is valid */ |
| 1099 | spin_lock_irqsave (&iucv_lock, flags); |
| 1100 | list_for_each(lh, &iucv_handler_table) { |
| 1101 | if ((handler *)handle == list_entry(lh, handler, list)) { |
| 1102 | h = (handler *)handle; |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
| 1106 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 1107 | |
| 1108 | if (!h) { |
| 1109 | if (handle) |
| 1110 | printk(KERN_WARNING |
| 1111 | "%s: Handler not found in iucv_handler_table.\n", |
| 1112 | __FUNCTION__); |
| 1113 | else |
| 1114 | printk(KERN_WARNING |
| 1115 | "%s: NULL handle passed by application.\n", |
| 1116 | __FUNCTION__); |
| 1117 | return -EINVAL; |
| 1118 | } |
| 1119 | |
| 1120 | if (pathid == NULL) { |
| 1121 | printk(KERN_WARNING "%s: NULL pathid pointer\n", |
| 1122 | __FUNCTION__); |
| 1123 | return -EINVAL; |
| 1124 | } |
| 1125 | |
| 1126 | parm = (iparml_control *)grab_param(); |
| 1127 | |
| 1128 | parm->ipmsglim = msglim_reqstd; |
| 1129 | |
| 1130 | if (user_data) |
| 1131 | memcpy(parm->ipuser, user_data, sizeof(parm->ipuser)); |
| 1132 | |
| 1133 | if (userid) { |
| 1134 | memcpy(parm->ipvmid, userid, sizeof(parm->ipvmid)); |
| 1135 | ASCEBC(parm->ipvmid, sizeof(parm->ipvmid)); |
| 1136 | EBC_TOUPPER(parm->ipvmid, sizeof(parm->ipvmid)); |
| 1137 | } |
| 1138 | |
| 1139 | if (system_name) { |
| 1140 | memcpy(parm->iptarget, system_name, sizeof(parm->iptarget)); |
| 1141 | ASCEBC(parm->iptarget, sizeof(parm->iptarget)); |
| 1142 | EBC_TOUPPER(parm->iptarget, sizeof(parm->iptarget)); |
| 1143 | } |
| 1144 | |
| 1145 | /* In order to establish an IUCV connection, the procedure is: |
| 1146 | * |
| 1147 | * b2f0(CONNECT) |
| 1148 | * take the ippathid from the b2f0 call |
| 1149 | * register the handler to the ippathid |
| 1150 | * |
| 1151 | * Unfortunately, the ConnectionEstablished message gets sent after the |
| 1152 | * b2f0(CONNECT) call but before the register is handled. |
| 1153 | * |
| 1154 | * In order for this race condition to be eliminated, the IUCV Control |
| 1155 | * Interrupts must be disabled for the above procedure. |
| 1156 | * |
| 1157 | * David Kennedy <dkennedy@linuxcare.com> |
| 1158 | */ |
| 1159 | |
| 1160 | /* Enable everything but IUCV Control messages */ |
| 1161 | iucv_setmask(~(AllInterrupts)); |
| 1162 | messagesDisabled = 1; |
| 1163 | |
| 1164 | spin_lock_irqsave (&iucv_lock, flags); |
| 1165 | parm->ipflags1 = (__u8)flags1; |
| 1166 | b2f0_result = b2f0(CONNECT, parm); |
| 1167 | memcpy(&local_parm, parm, sizeof(local_parm)); |
| 1168 | release_param(parm); |
| 1169 | parm = &local_parm; |
| 1170 | if (!b2f0_result) |
| 1171 | add_pathid_result = __iucv_add_pathid(parm->ippathid, h); |
| 1172 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 1173 | |
| 1174 | if (b2f0_result) { |
| 1175 | iucv_setmask(~0); |
| 1176 | messagesDisabled = 0; |
| 1177 | return b2f0_result; |
| 1178 | } |
| 1179 | |
| 1180 | *pathid = parm->ippathid; |
| 1181 | |
| 1182 | /* Enable everything again */ |
| 1183 | iucv_setmask(IUCVControlInterruptsFlag); |
| 1184 | |
| 1185 | if (msglim) |
| 1186 | *msglim = parm->ipmsglim; |
| 1187 | if (flags1_out) |
| 1188 | *flags1_out = (parm->ipflags1 & IPPRTY) ? IPPRTY : 0; |
| 1189 | |
| 1190 | if (add_pathid_result) { |
| 1191 | iucv_sever(*pathid, no_memory); |
| 1192 | printk(KERN_WARNING "%s: add_pathid failed with rc =" |
| 1193 | " %d\n", __FUNCTION__, add_pathid_result); |
| 1194 | return(add_pathid_result); |
| 1195 | } |
| 1196 | |
| 1197 | iucv_debug(1, "exiting"); |
| 1198 | return b2f0_result; |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * iucv_purge: |
| 1203 | * @pathid: Path identification number |
| 1204 | * @msgid: Message ID of message to purge. |
| 1205 | * @srccls: Message class of the message to purge. |
| 1206 | * @audit: Pointer to an __u32. If not NULL, on return, information about |
| 1207 | * asynchronous errors that may have affected the normal completion |
| 1208 | * of this message ist stored at the given location. |
| 1209 | * |
| 1210 | * Cancels a message you have sent. |
| 1211 | * Returns: return code from CP |
| 1212 | */ |
| 1213 | int |
| 1214 | iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit) |
| 1215 | { |
| 1216 | iparml_purge *parm; |
| 1217 | ulong b2f0_result = 0; |
| 1218 | |
| 1219 | iucv_debug(1, "entering"); |
| 1220 | iucv_debug(1, "pathid = %d", pathid); |
| 1221 | |
| 1222 | parm = (iparml_purge *)grab_param(); |
| 1223 | |
| 1224 | parm->ipmsgid = msgid; |
| 1225 | parm->ippathid = pathid; |
| 1226 | parm->ipsrccls = srccls; |
| 1227 | parm->ipflags1 |= (IPSRCCLS | IPFGMID | IPFGPID); |
| 1228 | b2f0_result = b2f0(PURGE, parm); |
| 1229 | |
| 1230 | if (!b2f0_result && audit) { |
| 1231 | memcpy(audit, parm->ipaudit, sizeof(parm->ipaudit)); |
| 1232 | /* parm->ipaudit has only 3 bytes */ |
| 1233 | *audit >>= 8; |
| 1234 | } |
| 1235 | |
| 1236 | release_param(parm); |
| 1237 | |
| 1238 | iucv_debug(1, "b2f0_result = %ld", b2f0_result); |
| 1239 | iucv_debug(1, "exiting"); |
| 1240 | return b2f0_result; |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * iucv_query_generic: |
| 1245 | * @want_maxconn: Flag, describing which value is to be returned. |
| 1246 | * |
| 1247 | * Helper function for iucv_query_maxconn() and iucv_query_bufsize(). |
| 1248 | * |
| 1249 | * Returns: The buffersize, if want_maxconn is 0; the maximum number of |
| 1250 | * connections, if want_maxconn is 1 or an error-code < 0 on failure. |
| 1251 | */ |
| 1252 | static int |
| 1253 | iucv_query_generic(int want_maxconn) |
| 1254 | { |
| 1255 | iparml_purge *parm = (iparml_purge *)grab_param(); |
| 1256 | int bufsize, maxconn; |
| 1257 | int ccode; |
| 1258 | |
| 1259 | /** |
| 1260 | * Call b2f0 and store R0 (max buffer size), |
| 1261 | * R1 (max connections) and CC. |
| 1262 | */ |
| 1263 | asm volatile ( |
| 1264 | "LRA 1,0(%4)\n\t" |
| 1265 | "LR 0,%3\n\t" |
| 1266 | ".long 0xb2f01000\n\t" |
| 1267 | "IPM %0\n\t" |
| 1268 | "SRL %0,28\n\t" |
| 1269 | "ST 0,%1\n\t" |
| 1270 | "ST 1,%2\n\t" |
| 1271 | : "=d" (ccode), "=m" (bufsize), "=m" (maxconn) |
| 1272 | : "d" (QUERY), "a" (parm) |
| 1273 | : "0", "1", "cc" |
| 1274 | ); |
| 1275 | release_param(parm); |
| 1276 | |
| 1277 | if (ccode) |
| 1278 | return -EPERM; |
| 1279 | if (want_maxconn) |
| 1280 | return maxconn; |
| 1281 | return bufsize; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * iucv_query_maxconn: |
| 1286 | * |
| 1287 | * Determines the maximum number of connections thay may be established. |
| 1288 | * |
| 1289 | * Returns: Maximum number of connections that can be. |
| 1290 | */ |
| 1291 | ulong |
| 1292 | iucv_query_maxconn(void) |
| 1293 | { |
| 1294 | return iucv_query_generic(1); |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * iucv_query_bufsize: |
| 1299 | * |
| 1300 | * Determines the size of the external interrupt buffer. |
| 1301 | * |
| 1302 | * Returns: Size of external interrupt buffer. |
| 1303 | */ |
| 1304 | ulong |
| 1305 | iucv_query_bufsize (void) |
| 1306 | { |
| 1307 | return iucv_query_generic(0); |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * iucv_quiesce: |
| 1312 | * @pathid: Path identification number |
| 1313 | * @user_data: 16-byte user data |
| 1314 | * |
| 1315 | * Temporarily suspends incoming messages on an IUCV path. |
| 1316 | * You can later reactivate the path by invoking the iucv_resume function. |
| 1317 | * Returns: return code from CP |
| 1318 | */ |
| 1319 | int |
| 1320 | iucv_quiesce (__u16 pathid, __u8 user_data[16]) |
| 1321 | { |
| 1322 | iparml_control *parm; |
| 1323 | ulong b2f0_result = 0; |
| 1324 | |
| 1325 | iucv_debug(1, "entering"); |
| 1326 | iucv_debug(1, "pathid = %d", pathid); |
| 1327 | |
| 1328 | parm = (iparml_control *)grab_param(); |
| 1329 | |
| 1330 | memcpy(parm->ipuser, user_data, sizeof(parm->ipuser)); |
| 1331 | parm->ippathid = pathid; |
| 1332 | |
| 1333 | b2f0_result = b2f0(QUIESCE, parm); |
| 1334 | release_param(parm); |
| 1335 | |
| 1336 | iucv_debug(1, "b2f0_result = %ld", b2f0_result); |
| 1337 | iucv_debug(1, "exiting"); |
| 1338 | |
| 1339 | return b2f0_result; |
| 1340 | } |
| 1341 | |
| 1342 | /** |
| 1343 | * iucv_receive: |
| 1344 | * @pathid: Path identification number. |
| 1345 | * @buffer: Address of buffer to receive. Must be below 2G. |
| 1346 | * @buflen: Length of buffer to receive. |
| 1347 | * @msgid: Specifies the message ID. |
| 1348 | * @trgcls: Specifies target class. |
| 1349 | * @flags1_out: Receives options for path on return. |
| 1350 | * - IPNORPY (0x10) Specifies whether a reply is required |
| 1351 | * - IPPRTY (0x20) Specifies if you want to send priority message |
| 1352 | * - IPRMDATA (0x80) Specifies the data is contained in the parameter list |
| 1353 | * @residual_buffer: Receives the address of buffer updated by the number |
| 1354 | * of bytes you have received on return. |
| 1355 | * @residual_length: On return, receives one of the following values: |
| 1356 | * - 0 If the receive buffer is the same length as |
| 1357 | * the message. |
| 1358 | * - Remaining bytes in buffer If the receive buffer is longer than the |
| 1359 | * message. |
| 1360 | * - Remaining bytes in message If the receive buffer is shorter than the |
| 1361 | * message. |
| 1362 | * |
| 1363 | * This function receives messages that are being sent to you over established |
| 1364 | * paths. |
| 1365 | * Returns: return code from CP IUCV call; If the receive buffer is shorter |
| 1366 | * than the message, always 5 |
| 1367 | * -EINVAL - buffer address is pointing to NULL |
| 1368 | */ |
| 1369 | int |
| 1370 | iucv_receive (__u16 pathid, __u32 msgid, __u32 trgcls, |
| 1371 | void *buffer, ulong buflen, |
| 1372 | int *flags1_out, ulong * residual_buffer, ulong * residual_length) |
| 1373 | { |
| 1374 | iparml_db *parm; |
| 1375 | ulong b2f0_result; |
| 1376 | int moved = 0; /* number of bytes moved from parmlist to buffer */ |
| 1377 | |
| 1378 | iucv_debug(2, "entering"); |
| 1379 | |
| 1380 | if (!buffer) |
| 1381 | return -EINVAL; |
| 1382 | |
| 1383 | parm = (iparml_db *)grab_param(); |
| 1384 | |
| 1385 | parm->ipbfadr1 = (__u32) (addr_t) buffer; |
| 1386 | parm->ipbfln1f = (__u32) ((ulong) buflen); |
| 1387 | parm->ipmsgid = msgid; |
| 1388 | parm->ippathid = pathid; |
| 1389 | parm->iptrgcls = trgcls; |
| 1390 | parm->ipflags1 = (IPFGPID | IPFGMID | IPFGMCL); |
| 1391 | |
| 1392 | b2f0_result = b2f0(RECEIVE, parm); |
| 1393 | |
| 1394 | if (!b2f0_result || b2f0_result == 5) { |
| 1395 | if (flags1_out) { |
| 1396 | iucv_debug(2, "*flags1_out = %d", *flags1_out); |
| 1397 | *flags1_out = (parm->ipflags1 & (~0x07)); |
| 1398 | iucv_debug(2, "*flags1_out = %d", *flags1_out); |
| 1399 | } |
| 1400 | |
| 1401 | if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */ |
| 1402 | if (residual_length) |
| 1403 | *residual_length = parm->ipbfln1f; |
| 1404 | |
| 1405 | if (residual_buffer) |
| 1406 | *residual_buffer = parm->ipbfadr1; |
| 1407 | } else { |
| 1408 | moved = min_t (unsigned long, buflen, 8); |
| 1409 | |
| 1410 | memcpy ((char *) buffer, |
| 1411 | (char *) &parm->ipbfadr1, moved); |
| 1412 | |
| 1413 | if (buflen < 8) |
| 1414 | b2f0_result = 5; |
| 1415 | |
| 1416 | if (residual_length) |
| 1417 | *residual_length = abs (buflen - 8); |
| 1418 | |
| 1419 | if (residual_buffer) |
| 1420 | *residual_buffer = (ulong) (buffer + moved); |
| 1421 | } |
| 1422 | } |
| 1423 | release_param(parm); |
| 1424 | |
| 1425 | iucv_debug(2, "exiting"); |
| 1426 | return b2f0_result; |
| 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * Name: iucv_receive_array |
| 1431 | * Purpose: This function receives messages that are being sent to you |
| 1432 | * over established paths. |
| 1433 | * Input: pathid - path identification number |
| 1434 | * buffer - address of array of buffers |
| 1435 | * buflen - total length of buffers |
| 1436 | * msgid - specifies the message ID. |
| 1437 | * trgcls - specifies target class |
| 1438 | * Output: |
| 1439 | * flags1_out: Options for path. |
| 1440 | * IPNORPY - 0x10 specifies whether a reply is required |
| 1441 | * IPPRTY - 0x20 specifies if you want to send priority message |
| 1442 | * IPRMDATA - 0x80 specifies the data is contained in the parameter list |
| 1443 | * residual_buffer - address points to the current list entry IUCV |
| 1444 | * is working on. |
| 1445 | * residual_length - |
| 1446 | * Contains one of the following values, if the receive buffer is: |
| 1447 | * The same length as the message, this field is zero. |
| 1448 | * Longer than the message, this field contains the number of |
| 1449 | * bytes remaining in the buffer. |
| 1450 | * Shorter than the message, this field contains the residual |
| 1451 | * count (that is, the number of bytes remaining in the |
| 1452 | * message that does not fit into the buffer. In this case |
| 1453 | * b2f0_result = 5. |
| 1454 | * Return: b2f0_result - return code from CP |
| 1455 | * (-EINVAL) - buffer address is NULL |
| 1456 | */ |
| 1457 | int |
| 1458 | iucv_receive_array (__u16 pathid, |
| 1459 | __u32 msgid, __u32 trgcls, |
| 1460 | iucv_array_t * buffer, ulong buflen, |
| 1461 | int *flags1_out, |
| 1462 | ulong * residual_buffer, ulong * residual_length) |
| 1463 | { |
| 1464 | iparml_db *parm; |
| 1465 | ulong b2f0_result; |
| 1466 | int i = 0, moved = 0, need_to_move = 8, dyn_len; |
| 1467 | |
| 1468 | iucv_debug(2, "entering"); |
| 1469 | |
| 1470 | if (!buffer) |
| 1471 | return -EINVAL; |
| 1472 | |
| 1473 | parm = (iparml_db *)grab_param(); |
| 1474 | |
| 1475 | parm->ipbfadr1 = (__u32) ((ulong) buffer); |
| 1476 | parm->ipbfln1f = (__u32) buflen; |
| 1477 | parm->ipmsgid = msgid; |
| 1478 | parm->ippathid = pathid; |
| 1479 | parm->iptrgcls = trgcls; |
| 1480 | parm->ipflags1 = (IPBUFLST | IPFGPID | IPFGMID | IPFGMCL); |
| 1481 | |
| 1482 | b2f0_result = b2f0(RECEIVE, parm); |
| 1483 | |
| 1484 | if (!b2f0_result || b2f0_result == 5) { |
| 1485 | |
| 1486 | if (flags1_out) { |
| 1487 | iucv_debug(2, "*flags1_out = %d", *flags1_out); |
| 1488 | *flags1_out = (parm->ipflags1 & (~0x07)); |
| 1489 | iucv_debug(2, "*flags1_out = %d", *flags1_out); |
| 1490 | } |
| 1491 | |
| 1492 | if (!(parm->ipflags1 & IPRMDATA)) { /*msg not in parmlist */ |
| 1493 | |
| 1494 | if (residual_length) |
| 1495 | *residual_length = parm->ipbfln1f; |
| 1496 | |
| 1497 | if (residual_buffer) |
| 1498 | *residual_buffer = parm->ipbfadr1; |
| 1499 | |
| 1500 | } else { |
| 1501 | /* copy msg from parmlist to users array. */ |
| 1502 | |
| 1503 | while ((moved < 8) && (moved < buflen)) { |
| 1504 | dyn_len = |
| 1505 | min_t (unsigned int, |
| 1506 | (buffer + i)->length, need_to_move); |
| 1507 | |
| 1508 | memcpy ((char *)((ulong)((buffer + i)->address)), |
| 1509 | ((char *) &parm->ipbfadr1) + moved, |
| 1510 | dyn_len); |
| 1511 | |
| 1512 | moved += dyn_len; |
| 1513 | need_to_move -= dyn_len; |
| 1514 | |
| 1515 | (buffer + i)->address = |
| 1516 | (__u32) |
| 1517 | ((ulong)(__u8 *) ((ulong)(buffer + i)->address) |
| 1518 | + dyn_len); |
| 1519 | |
| 1520 | (buffer + i)->length -= dyn_len; |
| 1521 | i++; |
| 1522 | } |
| 1523 | |
| 1524 | if (need_to_move) /* buflen < 8 bytes */ |
| 1525 | b2f0_result = 5; |
| 1526 | |
| 1527 | if (residual_length) |
| 1528 | *residual_length = abs (buflen - 8); |
| 1529 | |
| 1530 | if (residual_buffer) { |
| 1531 | if (!moved) |
| 1532 | *residual_buffer = (ulong) buffer; |
| 1533 | else |
| 1534 | *residual_buffer = |
| 1535 | (ulong) (buffer + (i - 1)); |
| 1536 | } |
| 1537 | |
| 1538 | } |
| 1539 | } |
| 1540 | release_param(parm); |
| 1541 | |
| 1542 | iucv_debug(2, "exiting"); |
| 1543 | return b2f0_result; |
| 1544 | } |
| 1545 | |
| 1546 | /** |
| 1547 | * iucv_reject: |
| 1548 | * @pathid: Path identification number. |
| 1549 | * @msgid: Message ID of the message to reject. |
| 1550 | * @trgcls: Target class of the message to reject. |
| 1551 | * Returns: return code from CP |
| 1552 | * |
| 1553 | * Refuses a specified message. Between the time you are notified of a |
| 1554 | * message and the time that you complete the message, the message may |
| 1555 | * be rejected. |
| 1556 | */ |
| 1557 | int |
| 1558 | iucv_reject (__u16 pathid, __u32 msgid, __u32 trgcls) |
| 1559 | { |
| 1560 | iparml_db *parm; |
| 1561 | ulong b2f0_result = 0; |
| 1562 | |
| 1563 | iucv_debug(1, "entering"); |
| 1564 | iucv_debug(1, "pathid = %d", pathid); |
| 1565 | |
| 1566 | parm = (iparml_db *)grab_param(); |
| 1567 | |
| 1568 | parm->ippathid = pathid; |
| 1569 | parm->ipmsgid = msgid; |
| 1570 | parm->iptrgcls = trgcls; |
| 1571 | parm->ipflags1 = (IPFGMCL | IPFGMID | IPFGPID); |
| 1572 | |
| 1573 | b2f0_result = b2f0(REJECT, parm); |
| 1574 | release_param(parm); |
| 1575 | |
| 1576 | iucv_debug(1, "b2f0_result = %ld", b2f0_result); |
| 1577 | iucv_debug(1, "exiting"); |
| 1578 | |
| 1579 | return b2f0_result; |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | * Name: iucv_reply |
| 1584 | * Purpose: This function responds to the two-way messages that you |
| 1585 | * receive. You must identify completely the message to |
| 1586 | * which you wish to reply. ie, pathid, msgid, and trgcls. |
| 1587 | * Input: pathid - path identification number |
| 1588 | * msgid - specifies the message ID. |
| 1589 | * trgcls - specifies target class |
| 1590 | * flags1 - option for path |
| 1591 | * IPPRTY- 0x20 - specifies if you want to send priority message |
| 1592 | * buffer - address of reply buffer |
| 1593 | * buflen - length of reply buffer |
| 1594 | * Output: ipbfadr2 - Address of buffer updated by the number |
| 1595 | * of bytes you have moved. |
| 1596 | * ipbfln2f - Contains one of the following values: |
| 1597 | * If the answer buffer is the same length as the reply, this field |
| 1598 | * contains zero. |
| 1599 | * If the answer buffer is longer than the reply, this field contains |
| 1600 | * the number of bytes remaining in the buffer. |
| 1601 | * If the answer buffer is shorter than the reply, this field contains |
| 1602 | * a residual count (that is, the number of bytes remianing in the |
| 1603 | * reply that does not fit into the buffer. In this |
| 1604 | * case b2f0_result = 5. |
| 1605 | * Return: b2f0_result - return code from CP |
| 1606 | * (-EINVAL) - buffer address is NULL |
| 1607 | */ |
| 1608 | int |
| 1609 | iucv_reply (__u16 pathid, |
| 1610 | __u32 msgid, __u32 trgcls, |
| 1611 | int flags1, |
| 1612 | void *buffer, ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f) |
| 1613 | { |
| 1614 | iparml_db *parm; |
| 1615 | ulong b2f0_result; |
| 1616 | |
| 1617 | iucv_debug(2, "entering"); |
| 1618 | |
| 1619 | if (!buffer) |
| 1620 | return -EINVAL; |
| 1621 | |
| 1622 | parm = (iparml_db *)grab_param(); |
| 1623 | |
| 1624 | parm->ipbfadr2 = (__u32) ((ulong) buffer); |
| 1625 | parm->ipbfln2f = (__u32) buflen; /* length of message */ |
| 1626 | parm->ippathid = pathid; |
| 1627 | parm->ipmsgid = msgid; |
| 1628 | parm->iptrgcls = trgcls; |
| 1629 | parm->ipflags1 = (__u8) flags1; /* priority message */ |
| 1630 | |
| 1631 | b2f0_result = b2f0(REPLY, parm); |
| 1632 | |
| 1633 | if ((!b2f0_result) || (b2f0_result == 5)) { |
| 1634 | if (ipbfadr2) |
| 1635 | *ipbfadr2 = parm->ipbfadr2; |
| 1636 | if (ipbfln2f) |
| 1637 | *ipbfln2f = parm->ipbfln2f; |
| 1638 | } |
| 1639 | release_param(parm); |
| 1640 | |
| 1641 | iucv_debug(2, "exiting"); |
| 1642 | |
| 1643 | return b2f0_result; |
| 1644 | } |
| 1645 | |
| 1646 | /* |
| 1647 | * Name: iucv_reply_array |
| 1648 | * Purpose: This function responds to the two-way messages that you |
| 1649 | * receive. You must identify completely the message to |
| 1650 | * which you wish to reply. ie, pathid, msgid, and trgcls. |
| 1651 | * The array identifies a list of addresses and lengths of |
| 1652 | * discontiguous buffers that contains the reply data. |
| 1653 | * Input: pathid - path identification number |
| 1654 | * msgid - specifies the message ID. |
| 1655 | * trgcls - specifies target class |
| 1656 | * flags1 - option for path |
| 1657 | * IPPRTY- specifies if you want to send priority message |
| 1658 | * buffer - address of array of reply buffers |
| 1659 | * buflen - total length of reply buffers |
| 1660 | * Output: ipbfadr2 - Address of buffer which IUCV is currently working on. |
| 1661 | * ipbfln2f - Contains one of the following values: |
| 1662 | * If the answer buffer is the same length as the reply, this field |
| 1663 | * contains zero. |
| 1664 | * If the answer buffer is longer than the reply, this field contains |
| 1665 | * the number of bytes remaining in the buffer. |
| 1666 | * If the answer buffer is shorter than the reply, this field contains |
| 1667 | * a residual count (that is, the number of bytes remianing in the |
| 1668 | * reply that does not fit into the buffer. In this |
| 1669 | * case b2f0_result = 5. |
| 1670 | * Return: b2f0_result - return code from CP |
| 1671 | * (-EINVAL) - buffer address is NULL |
| 1672 | */ |
| 1673 | int |
| 1674 | iucv_reply_array (__u16 pathid, |
| 1675 | __u32 msgid, __u32 trgcls, |
| 1676 | int flags1, |
| 1677 | iucv_array_t * buffer, |
| 1678 | ulong buflen, ulong * ipbfadr2, ulong * ipbfln2f) |
| 1679 | { |
| 1680 | iparml_db *parm; |
| 1681 | ulong b2f0_result; |
| 1682 | |
| 1683 | iucv_debug(2, "entering"); |
| 1684 | |
| 1685 | if (!buffer) |
| 1686 | return -EINVAL; |
| 1687 | |
| 1688 | parm = (iparml_db *)grab_param(); |
| 1689 | |
| 1690 | parm->ipbfadr2 = (__u32) ((ulong) buffer); |
| 1691 | parm->ipbfln2f = buflen; /* length of message */ |
| 1692 | parm->ippathid = pathid; |
| 1693 | parm->ipmsgid = msgid; |
| 1694 | parm->iptrgcls = trgcls; |
| 1695 | parm->ipflags1 = (IPANSLST | flags1); |
| 1696 | |
| 1697 | b2f0_result = b2f0(REPLY, parm); |
| 1698 | |
| 1699 | if ((!b2f0_result) || (b2f0_result == 5)) { |
| 1700 | |
| 1701 | if (ipbfadr2) |
| 1702 | *ipbfadr2 = parm->ipbfadr2; |
| 1703 | if (ipbfln2f) |
| 1704 | *ipbfln2f = parm->ipbfln2f; |
| 1705 | } |
| 1706 | release_param(parm); |
| 1707 | |
| 1708 | iucv_debug(2, "exiting"); |
| 1709 | |
| 1710 | return b2f0_result; |
| 1711 | } |
| 1712 | |
| 1713 | /* |
| 1714 | * Name: iucv_reply_prmmsg |
| 1715 | * Purpose: This function responds to the two-way messages that you |
| 1716 | * receive. You must identify completely the message to |
| 1717 | * which you wish to reply. ie, pathid, msgid, and trgcls. |
| 1718 | * Prmmsg signifies the data is moved into the |
| 1719 | * parameter list. |
| 1720 | * Input: pathid - path identification number |
| 1721 | * msgid - specifies the message ID. |
| 1722 | * trgcls - specifies target class |
| 1723 | * flags1 - option for path |
| 1724 | * IPPRTY- specifies if you want to send priority message |
| 1725 | * prmmsg - 8-bytes of data to be placed into the parameter |
| 1726 | * list. |
| 1727 | * Output: NA |
| 1728 | * Return: b2f0_result - return code from CP |
| 1729 | */ |
| 1730 | int |
| 1731 | iucv_reply_prmmsg (__u16 pathid, |
| 1732 | __u32 msgid, __u32 trgcls, int flags1, __u8 prmmsg[8]) |
| 1733 | { |
| 1734 | iparml_dpl *parm; |
| 1735 | ulong b2f0_result; |
| 1736 | |
| 1737 | iucv_debug(2, "entering"); |
| 1738 | |
| 1739 | parm = (iparml_dpl *)grab_param(); |
| 1740 | |
| 1741 | parm->ippathid = pathid; |
| 1742 | parm->ipmsgid = msgid; |
| 1743 | parm->iptrgcls = trgcls; |
| 1744 | memcpy(parm->iprmmsg, prmmsg, sizeof (parm->iprmmsg)); |
| 1745 | parm->ipflags1 = (IPRMDATA | flags1); |
| 1746 | |
| 1747 | b2f0_result = b2f0(REPLY, parm); |
| 1748 | release_param(parm); |
| 1749 | |
| 1750 | iucv_debug(2, "exiting"); |
| 1751 | |
| 1752 | return b2f0_result; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
| 1756 | * iucv_resume: |
| 1757 | * @pathid: Path identification number |
| 1758 | * @user_data: 16-byte of user data |
| 1759 | * |
| 1760 | * This function restores communication over a quiesced path. |
| 1761 | * Returns: return code from CP |
| 1762 | */ |
| 1763 | int |
| 1764 | iucv_resume (__u16 pathid, __u8 user_data[16]) |
| 1765 | { |
| 1766 | iparml_control *parm; |
| 1767 | ulong b2f0_result = 0; |
| 1768 | |
| 1769 | iucv_debug(1, "entering"); |
| 1770 | iucv_debug(1, "pathid = %d", pathid); |
| 1771 | |
| 1772 | parm = (iparml_control *)grab_param(); |
| 1773 | |
| 1774 | memcpy (parm->ipuser, user_data, sizeof (*user_data)); |
| 1775 | parm->ippathid = pathid; |
| 1776 | |
| 1777 | b2f0_result = b2f0(RESUME, parm); |
| 1778 | release_param(parm); |
| 1779 | |
| 1780 | iucv_debug(1, "exiting"); |
| 1781 | |
| 1782 | return b2f0_result; |
| 1783 | } |
| 1784 | |
| 1785 | /* |
| 1786 | * Name: iucv_send |
| 1787 | * Purpose: sends messages |
| 1788 | * Input: pathid - ushort, pathid |
| 1789 | * msgid - ulong *, id of message returned to caller |
| 1790 | * trgcls - ulong, target message class |
| 1791 | * srccls - ulong, source message class |
| 1792 | * msgtag - ulong, message tag |
| 1793 | * flags1 - Contains options for this path. |
| 1794 | * IPPRTY - Ox20 - specifies if you want to send a priority message. |
| 1795 | * buffer - pointer to buffer |
| 1796 | * buflen - ulong, length of buffer |
| 1797 | * Output: b2f0_result - return code from b2f0 call |
| 1798 | * msgid - returns message id |
| 1799 | */ |
| 1800 | int |
| 1801 | iucv_send (__u16 pathid, __u32 * msgid, |
| 1802 | __u32 trgcls, __u32 srccls, |
| 1803 | __u32 msgtag, int flags1, void *buffer, ulong buflen) |
| 1804 | { |
| 1805 | iparml_db *parm; |
| 1806 | ulong b2f0_result; |
| 1807 | |
| 1808 | iucv_debug(2, "entering"); |
| 1809 | |
| 1810 | if (!buffer) |
| 1811 | return -EINVAL; |
| 1812 | |
| 1813 | parm = (iparml_db *)grab_param(); |
| 1814 | |
| 1815 | parm->ipbfadr1 = (__u32) ((ulong) buffer); |
| 1816 | parm->ippathid = pathid; |
| 1817 | parm->iptrgcls = trgcls; |
| 1818 | parm->ipbfln1f = (__u32) buflen; /* length of message */ |
| 1819 | parm->ipsrccls = srccls; |
| 1820 | parm->ipmsgtag = msgtag; |
| 1821 | parm->ipflags1 = (IPNORPY | flags1); /* one way priority message */ |
| 1822 | |
| 1823 | b2f0_result = b2f0(SEND, parm); |
| 1824 | |
| 1825 | if ((!b2f0_result) && (msgid)) |
| 1826 | *msgid = parm->ipmsgid; |
| 1827 | release_param(parm); |
| 1828 | |
| 1829 | iucv_debug(2, "exiting"); |
| 1830 | |
| 1831 | return b2f0_result; |
| 1832 | } |
| 1833 | |
| 1834 | /* |
| 1835 | * Name: iucv_send_array |
| 1836 | * Purpose: This function transmits data to another application. |
| 1837 | * The contents of buffer is the address of the array of |
| 1838 | * addresses and lengths of discontiguous buffers that hold |
| 1839 | * the message text. This is a one-way message and the |
| 1840 | * receiver will not reply to the message. |
| 1841 | * Input: pathid - path identification number |
| 1842 | * trgcls - specifies target class |
| 1843 | * srccls - specifies the source message class |
| 1844 | * msgtag - specifies a tag to be associated witht the message |
| 1845 | * flags1 - option for path |
| 1846 | * IPPRTY- specifies if you want to send priority message |
| 1847 | * buffer - address of array of send buffers |
| 1848 | * buflen - total length of send buffers |
| 1849 | * Output: msgid - specifies the message ID. |
| 1850 | * Return: b2f0_result - return code from CP |
| 1851 | * (-EINVAL) - buffer address is NULL |
| 1852 | */ |
| 1853 | int |
| 1854 | iucv_send_array (__u16 pathid, |
| 1855 | __u32 * msgid, |
| 1856 | __u32 trgcls, |
| 1857 | __u32 srccls, |
| 1858 | __u32 msgtag, int flags1, iucv_array_t * buffer, ulong buflen) |
| 1859 | { |
| 1860 | iparml_db *parm; |
| 1861 | ulong b2f0_result; |
| 1862 | |
| 1863 | iucv_debug(2, "entering"); |
| 1864 | |
| 1865 | if (!buffer) |
| 1866 | return -EINVAL; |
| 1867 | |
| 1868 | parm = (iparml_db *)grab_param(); |
| 1869 | |
| 1870 | parm->ippathid = pathid; |
| 1871 | parm->iptrgcls = trgcls; |
| 1872 | parm->ipbfadr1 = (__u32) ((ulong) buffer); |
| 1873 | parm->ipbfln1f = (__u32) buflen; /* length of message */ |
| 1874 | parm->ipsrccls = srccls; |
| 1875 | parm->ipmsgtag = msgtag; |
| 1876 | parm->ipflags1 = (IPNORPY | IPBUFLST | flags1); |
| 1877 | b2f0_result = b2f0(SEND, parm); |
| 1878 | |
| 1879 | if ((!b2f0_result) && (msgid)) |
| 1880 | *msgid = parm->ipmsgid; |
| 1881 | release_param(parm); |
| 1882 | |
| 1883 | iucv_debug(2, "exiting"); |
| 1884 | return b2f0_result; |
| 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * Name: iucv_send_prmmsg |
| 1889 | * Purpose: This function transmits data to another application. |
| 1890 | * Prmmsg specifies that the 8-bytes of data are to be moved |
| 1891 | * into the parameter list. This is a one-way message and the |
| 1892 | * receiver will not reply to the message. |
| 1893 | * Input: pathid - path identification number |
| 1894 | * trgcls - specifies target class |
| 1895 | * srccls - specifies the source message class |
| 1896 | * msgtag - specifies a tag to be associated with the message |
| 1897 | * flags1 - option for path |
| 1898 | * IPPRTY- specifies if you want to send priority message |
| 1899 | * prmmsg - 8-bytes of data to be placed into parameter list |
| 1900 | * Output: msgid - specifies the message ID. |
| 1901 | * Return: b2f0_result - return code from CP |
| 1902 | */ |
| 1903 | int |
| 1904 | iucv_send_prmmsg (__u16 pathid, |
| 1905 | __u32 * msgid, |
| 1906 | __u32 trgcls, |
| 1907 | __u32 srccls, __u32 msgtag, int flags1, __u8 prmmsg[8]) |
| 1908 | { |
| 1909 | iparml_dpl *parm; |
| 1910 | ulong b2f0_result; |
| 1911 | |
| 1912 | iucv_debug(2, "entering"); |
| 1913 | |
| 1914 | parm = (iparml_dpl *)grab_param(); |
| 1915 | |
| 1916 | parm->ippathid = pathid; |
| 1917 | parm->iptrgcls = trgcls; |
| 1918 | parm->ipsrccls = srccls; |
| 1919 | parm->ipmsgtag = msgtag; |
| 1920 | parm->ipflags1 = (IPRMDATA | IPNORPY | flags1); |
| 1921 | memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg)); |
| 1922 | |
| 1923 | b2f0_result = b2f0(SEND, parm); |
| 1924 | |
| 1925 | if ((!b2f0_result) && (msgid)) |
| 1926 | *msgid = parm->ipmsgid; |
| 1927 | release_param(parm); |
| 1928 | |
| 1929 | iucv_debug(2, "exiting"); |
| 1930 | |
| 1931 | return b2f0_result; |
| 1932 | } |
| 1933 | |
| 1934 | /* |
| 1935 | * Name: iucv_send2way |
| 1936 | * Purpose: This function transmits data to another application. |
| 1937 | * Data to be transmitted is in a buffer. The receiver |
| 1938 | * of the send is expected to reply to the message and |
| 1939 | * a buffer is provided into which IUCV moves the reply |
| 1940 | * to this message. |
| 1941 | * Input: pathid - path identification number |
| 1942 | * trgcls - specifies target class |
| 1943 | * srccls - specifies the source message class |
| 1944 | * msgtag - specifies a tag associated with the message |
| 1945 | * flags1 - option for path |
| 1946 | * IPPRTY- specifies if you want to send priority message |
| 1947 | * buffer - address of send buffer |
| 1948 | * buflen - length of send buffer |
| 1949 | * ansbuf - address of buffer to reply with |
| 1950 | * anslen - length of buffer to reply with |
| 1951 | * Output: msgid - specifies the message ID. |
| 1952 | * Return: b2f0_result - return code from CP |
| 1953 | * (-EINVAL) - buffer or ansbuf address is NULL |
| 1954 | */ |
| 1955 | int |
| 1956 | iucv_send2way (__u16 pathid, |
| 1957 | __u32 * msgid, |
| 1958 | __u32 trgcls, |
| 1959 | __u32 srccls, |
| 1960 | __u32 msgtag, |
| 1961 | int flags1, |
| 1962 | void *buffer, ulong buflen, void *ansbuf, ulong anslen) |
| 1963 | { |
| 1964 | iparml_db *parm; |
| 1965 | ulong b2f0_result; |
| 1966 | |
| 1967 | iucv_debug(2, "entering"); |
| 1968 | |
| 1969 | if (!buffer || !ansbuf) |
| 1970 | return -EINVAL; |
| 1971 | |
| 1972 | parm = (iparml_db *)grab_param(); |
| 1973 | |
| 1974 | parm->ippathid = pathid; |
| 1975 | parm->iptrgcls = trgcls; |
| 1976 | parm->ipbfadr1 = (__u32) ((ulong) buffer); |
| 1977 | parm->ipbfln1f = (__u32) buflen; /* length of message */ |
| 1978 | parm->ipbfadr2 = (__u32) ((ulong) ansbuf); |
| 1979 | parm->ipbfln2f = (__u32) anslen; |
| 1980 | parm->ipsrccls = srccls; |
| 1981 | parm->ipmsgtag = msgtag; |
| 1982 | parm->ipflags1 = flags1; /* priority message */ |
| 1983 | |
| 1984 | b2f0_result = b2f0(SEND, parm); |
| 1985 | |
| 1986 | if ((!b2f0_result) && (msgid)) |
| 1987 | *msgid = parm->ipmsgid; |
| 1988 | release_param(parm); |
| 1989 | |
| 1990 | iucv_debug(2, "exiting"); |
| 1991 | |
| 1992 | return b2f0_result; |
| 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * Name: iucv_send2way_array |
| 1997 | * Purpose: This function transmits data to another application. |
| 1998 | * The contents of buffer is the address of the array of |
| 1999 | * addresses and lengths of discontiguous buffers that hold |
| 2000 | * the message text. The receiver of the send is expected to |
| 2001 | * reply to the message and a buffer is provided into which |
| 2002 | * IUCV moves the reply to this message. |
| 2003 | * Input: pathid - path identification number |
| 2004 | * trgcls - specifies target class |
| 2005 | * srccls - specifies the source message class |
| 2006 | * msgtag - spcifies a tag to be associated with the message |
| 2007 | * flags1 - option for path |
| 2008 | * IPPRTY- specifies if you want to send priority message |
| 2009 | * buffer - address of array of send buffers |
| 2010 | * buflen - total length of send buffers |
| 2011 | * ansbuf - address of buffer to reply with |
| 2012 | * anslen - length of buffer to reply with |
| 2013 | * Output: msgid - specifies the message ID. |
| 2014 | * Return: b2f0_result - return code from CP |
| 2015 | * (-EINVAL) - buffer address is NULL |
| 2016 | */ |
| 2017 | int |
| 2018 | iucv_send2way_array (__u16 pathid, |
| 2019 | __u32 * msgid, |
| 2020 | __u32 trgcls, |
| 2021 | __u32 srccls, |
| 2022 | __u32 msgtag, |
| 2023 | int flags1, |
| 2024 | iucv_array_t * buffer, |
| 2025 | ulong buflen, iucv_array_t * ansbuf, ulong anslen) |
| 2026 | { |
| 2027 | iparml_db *parm; |
| 2028 | ulong b2f0_result; |
| 2029 | |
| 2030 | iucv_debug(2, "entering"); |
| 2031 | |
| 2032 | if (!buffer || !ansbuf) |
| 2033 | return -EINVAL; |
| 2034 | |
| 2035 | parm = (iparml_db *)grab_param(); |
| 2036 | |
| 2037 | parm->ippathid = pathid; |
| 2038 | parm->iptrgcls = trgcls; |
| 2039 | parm->ipbfadr1 = (__u32) ((ulong) buffer); |
| 2040 | parm->ipbfln1f = (__u32) buflen; /* length of message */ |
| 2041 | parm->ipbfadr2 = (__u32) ((ulong) ansbuf); |
| 2042 | parm->ipbfln2f = (__u32) anslen; |
| 2043 | parm->ipsrccls = srccls; |
| 2044 | parm->ipmsgtag = msgtag; |
| 2045 | parm->ipflags1 = (IPBUFLST | IPANSLST | flags1); |
| 2046 | b2f0_result = b2f0(SEND, parm); |
| 2047 | if ((!b2f0_result) && (msgid)) |
| 2048 | *msgid = parm->ipmsgid; |
| 2049 | release_param(parm); |
| 2050 | |
| 2051 | iucv_debug(2, "exiting"); |
| 2052 | return b2f0_result; |
| 2053 | } |
| 2054 | |
| 2055 | /* |
| 2056 | * Name: iucv_send2way_prmmsg |
| 2057 | * Purpose: This function transmits data to another application. |
| 2058 | * Prmmsg specifies that the 8-bytes of data are to be moved |
| 2059 | * into the parameter list. This is a two-way message and the |
| 2060 | * receiver of the message is expected to reply. A buffer |
| 2061 | * is provided into which IUCV moves the reply to this |
| 2062 | * message. |
| 2063 | * Input: pathid - path identification number |
| 2064 | * trgcls - specifies target class |
| 2065 | * srccls - specifies the source message class |
| 2066 | * msgtag - specifies a tag to be associated with the message |
| 2067 | * flags1 - option for path |
| 2068 | * IPPRTY- specifies if you want to send priority message |
| 2069 | * prmmsg - 8-bytes of data to be placed in parameter list |
| 2070 | * ansbuf - address of buffer to reply with |
| 2071 | * anslen - length of buffer to reply with |
| 2072 | * Output: msgid - specifies the message ID. |
| 2073 | * Return: b2f0_result - return code from CP |
| 2074 | * (-EINVAL) - buffer address is NULL |
| 2075 | */ |
| 2076 | int |
| 2077 | iucv_send2way_prmmsg (__u16 pathid, |
| 2078 | __u32 * msgid, |
| 2079 | __u32 trgcls, |
| 2080 | __u32 srccls, |
| 2081 | __u32 msgtag, |
| 2082 | ulong flags1, __u8 prmmsg[8], void *ansbuf, ulong anslen) |
| 2083 | { |
| 2084 | iparml_dpl *parm; |
| 2085 | ulong b2f0_result; |
| 2086 | |
| 2087 | iucv_debug(2, "entering"); |
| 2088 | |
| 2089 | if (!ansbuf) |
| 2090 | return -EINVAL; |
| 2091 | |
| 2092 | parm = (iparml_dpl *)grab_param(); |
| 2093 | |
| 2094 | parm->ippathid = pathid; |
| 2095 | parm->iptrgcls = trgcls; |
| 2096 | parm->ipsrccls = srccls; |
| 2097 | parm->ipmsgtag = msgtag; |
| 2098 | parm->ipbfadr2 = (__u32) ((ulong) ansbuf); |
| 2099 | parm->ipbfln2f = (__u32) anslen; |
| 2100 | parm->ipflags1 = (IPRMDATA | flags1); /* message in prmlist */ |
| 2101 | memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg)); |
| 2102 | |
| 2103 | b2f0_result = b2f0(SEND, parm); |
| 2104 | |
| 2105 | if ((!b2f0_result) && (msgid)) |
| 2106 | *msgid = parm->ipmsgid; |
| 2107 | release_param(parm); |
| 2108 | |
| 2109 | iucv_debug(2, "exiting"); |
| 2110 | |
| 2111 | return b2f0_result; |
| 2112 | } |
| 2113 | |
| 2114 | /* |
| 2115 | * Name: iucv_send2way_prmmsg_array |
| 2116 | * Purpose: This function transmits data to another application. |
| 2117 | * Prmmsg specifies that the 8-bytes of data are to be moved |
| 2118 | * into the parameter list. This is a two-way message and the |
| 2119 | * receiver of the message is expected to reply. A buffer |
| 2120 | * is provided into which IUCV moves the reply to this |
| 2121 | * message. The contents of ansbuf is the address of the |
| 2122 | * array of addresses and lengths of discontiguous buffers |
| 2123 | * that contain the reply. |
| 2124 | * Input: pathid - path identification number |
| 2125 | * trgcls - specifies target class |
| 2126 | * srccls - specifies the source message class |
| 2127 | * msgtag - specifies a tag to be associated with the message |
| 2128 | * flags1 - option for path |
| 2129 | * IPPRTY- specifies if you want to send priority message |
| 2130 | * prmmsg - 8-bytes of data to be placed into the parameter list |
| 2131 | * ansbuf - address of buffer to reply with |
| 2132 | * anslen - length of buffer to reply with |
| 2133 | * Output: msgid - specifies the message ID. |
| 2134 | * Return: b2f0_result - return code from CP |
| 2135 | * (-EINVAL) - ansbuf address is NULL |
| 2136 | */ |
| 2137 | int |
| 2138 | iucv_send2way_prmmsg_array (__u16 pathid, |
| 2139 | __u32 * msgid, |
| 2140 | __u32 trgcls, |
| 2141 | __u32 srccls, |
| 2142 | __u32 msgtag, |
| 2143 | int flags1, |
| 2144 | __u8 prmmsg[8], |
| 2145 | iucv_array_t * ansbuf, ulong anslen) |
| 2146 | { |
| 2147 | iparml_dpl *parm; |
| 2148 | ulong b2f0_result; |
| 2149 | |
| 2150 | iucv_debug(2, "entering"); |
| 2151 | |
| 2152 | if (!ansbuf) |
| 2153 | return -EINVAL; |
| 2154 | |
| 2155 | parm = (iparml_dpl *)grab_param(); |
| 2156 | |
| 2157 | parm->ippathid = pathid; |
| 2158 | parm->iptrgcls = trgcls; |
| 2159 | parm->ipsrccls = srccls; |
| 2160 | parm->ipmsgtag = msgtag; |
| 2161 | parm->ipbfadr2 = (__u32) ((ulong) ansbuf); |
| 2162 | parm->ipbfln2f = (__u32) anslen; |
| 2163 | parm->ipflags1 = (IPRMDATA | IPANSLST | flags1); |
| 2164 | memcpy(parm->iprmmsg, prmmsg, sizeof(parm->iprmmsg)); |
| 2165 | b2f0_result = b2f0(SEND, parm); |
| 2166 | if ((!b2f0_result) && (msgid)) |
| 2167 | *msgid = parm->ipmsgid; |
| 2168 | release_param(parm); |
| 2169 | |
| 2170 | iucv_debug(2, "exiting"); |
| 2171 | return b2f0_result; |
| 2172 | } |
| 2173 | |
| 2174 | void |
| 2175 | iucv_setmask_cpuid (void *result) |
| 2176 | { |
| 2177 | iparml_set_mask *parm; |
| 2178 | |
| 2179 | iucv_debug(1, "entering"); |
| 2180 | parm = (iparml_set_mask *)grab_param(); |
| 2181 | parm->ipmask = *((__u8*)result); |
| 2182 | *((ulong *)result) = b2f0(SETMASK, parm); |
| 2183 | release_param(parm); |
| 2184 | |
| 2185 | iucv_debug(1, "b2f0_result = %ld", *((ulong *)result)); |
| 2186 | iucv_debug(1, "exiting"); |
| 2187 | } |
| 2188 | |
| 2189 | /* |
| 2190 | * Name: iucv_setmask |
| 2191 | * Purpose: This function enables or disables the following IUCV |
| 2192 | * external interruptions: Nonpriority and priority message |
| 2193 | * interrupts, nonpriority and priority reply interrupts. |
| 2194 | * Input: SetMaskFlag - options for interrupts |
| 2195 | * 0x80 - Nonpriority_MessagePendingInterruptsFlag |
| 2196 | * 0x40 - Priority_MessagePendingInterruptsFlag |
| 2197 | * 0x20 - Nonpriority_MessageCompletionInterruptsFlag |
| 2198 | * 0x10 - Priority_MessageCompletionInterruptsFlag |
| 2199 | * 0x08 - IUCVControlInterruptsFlag |
| 2200 | * Output: NA |
| 2201 | * Return: b2f0_result - return code from CP |
| 2202 | */ |
| 2203 | int |
| 2204 | iucv_setmask (int SetMaskFlag) |
| 2205 | { |
| 2206 | union { |
| 2207 | ulong result; |
| 2208 | __u8 param; |
| 2209 | } u; |
| 2210 | int cpu; |
| 2211 | |
| 2212 | u.param = SetMaskFlag; |
| 2213 | cpu = get_cpu(); |
| 2214 | smp_call_function_on(iucv_setmask_cpuid, &u, 0, 1, iucv_cpuid); |
| 2215 | put_cpu(); |
| 2216 | |
| 2217 | return u.result; |
| 2218 | } |
| 2219 | |
| 2220 | /** |
| 2221 | * iucv_sever: |
| 2222 | * @pathid: Path identification number |
| 2223 | * @user_data: 16-byte of user data |
| 2224 | * |
| 2225 | * This function terminates an iucv path. |
| 2226 | * Returns: return code from CP |
| 2227 | */ |
| 2228 | int |
| 2229 | iucv_sever(__u16 pathid, __u8 user_data[16]) |
| 2230 | { |
| 2231 | iparml_control *parm; |
| 2232 | ulong b2f0_result = 0; |
| 2233 | |
| 2234 | iucv_debug(1, "entering"); |
| 2235 | parm = (iparml_control *)grab_param(); |
| 2236 | |
| 2237 | memcpy(parm->ipuser, user_data, sizeof(parm->ipuser)); |
| 2238 | parm->ippathid = pathid; |
| 2239 | |
| 2240 | b2f0_result = b2f0(SEVER, parm); |
| 2241 | |
| 2242 | if (!b2f0_result) |
| 2243 | iucv_remove_pathid(pathid); |
| 2244 | release_param(parm); |
| 2245 | |
| 2246 | iucv_debug(1, "exiting"); |
| 2247 | return b2f0_result; |
| 2248 | } |
| 2249 | |
| 2250 | /* |
| 2251 | * Interrupt Handlers |
| 2252 | *******************************************************************************/ |
| 2253 | |
| 2254 | /** |
| 2255 | * iucv_irq_handler: |
| 2256 | * @regs: Current registers |
| 2257 | * @code: irq code |
| 2258 | * |
| 2259 | * Handles external interrupts coming in from CP. |
| 2260 | * Places the interrupt buffer on a queue and schedules iucv_tasklet_handler(). |
| 2261 | */ |
| 2262 | static void |
| 2263 | iucv_irq_handler(struct pt_regs *regs, __u16 code) |
| 2264 | { |
| 2265 | iucv_irqdata *irqdata; |
| 2266 | |
| 2267 | irqdata = kmalloc(sizeof(iucv_irqdata), GFP_ATOMIC); |
| 2268 | if (!irqdata) { |
| 2269 | printk(KERN_WARNING "%s: out of memory\n", __FUNCTION__); |
| 2270 | return; |
| 2271 | } |
| 2272 | |
| 2273 | memcpy(&irqdata->data, iucv_external_int_buffer, |
| 2274 | sizeof(iucv_GeneralInterrupt)); |
| 2275 | |
| 2276 | spin_lock(&iucv_irq_queue_lock); |
| 2277 | list_add_tail(&irqdata->queue, &iucv_irq_queue); |
| 2278 | spin_unlock(&iucv_irq_queue_lock); |
| 2279 | |
| 2280 | tasklet_schedule(&iucv_tasklet); |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * iucv_do_int: |
| 2285 | * @int_buf: Pointer to copy of external interrupt buffer |
| 2286 | * |
| 2287 | * The workhorse for handling interrupts queued by iucv_irq_handler(). |
| 2288 | * This function is called from the bottom half iucv_tasklet_handler(). |
| 2289 | */ |
| 2290 | static void |
| 2291 | iucv_do_int(iucv_GeneralInterrupt * int_buf) |
| 2292 | { |
| 2293 | handler *h = NULL; |
| 2294 | struct list_head *lh; |
| 2295 | ulong flags; |
| 2296 | iucv_interrupt_ops_t *interrupt = NULL; /* interrupt addresses */ |
| 2297 | __u8 temp_buff1[24], temp_buff2[24]; /* masked handler id. */ |
| 2298 | int rc = 0, j = 0; |
| 2299 | __u8 no_listener[16] = "NO LISTENER"; |
| 2300 | |
| 2301 | iucv_debug(2, "entering, pathid %d, type %02X", |
| 2302 | int_buf->ippathid, int_buf->iptype); |
| 2303 | iucv_dumpit("External Interrupt Buffer:", |
| 2304 | int_buf, sizeof(iucv_GeneralInterrupt)); |
| 2305 | |
| 2306 | ASCEBC (no_listener, 16); |
| 2307 | |
| 2308 | if (int_buf->iptype != 01) { |
| 2309 | if ((int_buf->ippathid) > (max_connections - 1)) { |
| 2310 | printk(KERN_WARNING "%s: Got interrupt with pathid %d" |
| 2311 | " > max_connections (%ld)\n", __FUNCTION__, |
| 2312 | int_buf->ippathid, max_connections - 1); |
| 2313 | } else { |
| 2314 | h = iucv_pathid_table[int_buf->ippathid]; |
| 2315 | interrupt = h->interrupt_table; |
| 2316 | iucv_dumpit("Handler:", h, sizeof(handler)); |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | /* end of if statement */ |
| 2321 | switch (int_buf->iptype) { |
| 2322 | case 0x01: /* connection pending */ |
| 2323 | if (messagesDisabled) { |
| 2324 | iucv_setmask(~0); |
| 2325 | messagesDisabled = 0; |
| 2326 | } |
| 2327 | spin_lock_irqsave(&iucv_lock, flags); |
| 2328 | list_for_each(lh, &iucv_handler_table) { |
| 2329 | h = list_entry(lh, handler, list); |
| 2330 | memcpy(temp_buff1, &(int_buf->ipvmid), 24); |
| 2331 | memcpy(temp_buff2, &(h->id.userid), 24); |
| 2332 | for (j = 0; j < 24; j++) { |
| 2333 | temp_buff1[j] &= (h->id.mask)[j]; |
| 2334 | temp_buff2[j] &= (h->id.mask)[j]; |
| 2335 | } |
| 2336 | |
| 2337 | iucv_dumpit("temp_buff1:", |
| 2338 | temp_buff1, sizeof(temp_buff1)); |
| 2339 | iucv_dumpit("temp_buff2", |
| 2340 | temp_buff2, sizeof(temp_buff2)); |
| 2341 | |
| 2342 | if (!memcmp (temp_buff1, temp_buff2, 24)) { |
| 2343 | |
| 2344 | iucv_debug(2, |
| 2345 | "found a matching handler"); |
| 2346 | break; |
| 2347 | } else |
| 2348 | h = NULL; |
| 2349 | } |
| 2350 | spin_unlock_irqrestore (&iucv_lock, flags); |
| 2351 | if (h) { |
| 2352 | /* ADD PATH TO PATHID TABLE */ |
| 2353 | rc = iucv_add_pathid(int_buf->ippathid, h); |
| 2354 | if (rc) { |
| 2355 | iucv_sever (int_buf->ippathid, |
| 2356 | no_listener); |
| 2357 | iucv_debug(1, |
| 2358 | "add_pathid failed, rc = %d", |
| 2359 | rc); |
| 2360 | } else { |
| 2361 | interrupt = h->interrupt_table; |
| 2362 | if (interrupt->ConnectionPending) { |
| 2363 | EBCASC (int_buf->ipvmid, 8); |
| 2364 | interrupt->ConnectionPending( |
| 2365 | (iucv_ConnectionPending *)int_buf, |
| 2366 | h->pgm_data); |
| 2367 | } else |
| 2368 | iucv_sever(int_buf->ippathid, |
| 2369 | no_listener); |
| 2370 | } |
| 2371 | } else |
| 2372 | iucv_sever(int_buf->ippathid, no_listener); |
| 2373 | break; |
| 2374 | |
| 2375 | case 0x02: /*connection complete */ |
| 2376 | if (messagesDisabled) { |
| 2377 | iucv_setmask(~0); |
| 2378 | messagesDisabled = 0; |
| 2379 | } |
| 2380 | if (h) { |
| 2381 | if (interrupt->ConnectionComplete) |
| 2382 | { |
| 2383 | interrupt->ConnectionComplete( |
| 2384 | (iucv_ConnectionComplete *)int_buf, |
| 2385 | h->pgm_data); |
| 2386 | } |
| 2387 | else |
| 2388 | iucv_debug(1, |
| 2389 | "ConnectionComplete not called"); |
| 2390 | } else |
| 2391 | iucv_sever(int_buf->ippathid, no_listener); |
| 2392 | break; |
| 2393 | |
| 2394 | case 0x03: /* connection severed */ |
| 2395 | if (messagesDisabled) { |
| 2396 | iucv_setmask(~0); |
| 2397 | messagesDisabled = 0; |
| 2398 | } |
| 2399 | if (h) { |
| 2400 | if (interrupt->ConnectionSevered) |
| 2401 | interrupt->ConnectionSevered( |
| 2402 | (iucv_ConnectionSevered *)int_buf, |
| 2403 | h->pgm_data); |
| 2404 | |
| 2405 | else |
| 2406 | iucv_sever (int_buf->ippathid, no_listener); |
| 2407 | } else |
| 2408 | iucv_sever(int_buf->ippathid, no_listener); |
| 2409 | break; |
| 2410 | |
| 2411 | case 0x04: /* connection quiesced */ |
| 2412 | if (messagesDisabled) { |
| 2413 | iucv_setmask(~0); |
| 2414 | messagesDisabled = 0; |
| 2415 | } |
| 2416 | if (h) { |
| 2417 | if (interrupt->ConnectionQuiesced) |
| 2418 | interrupt->ConnectionQuiesced( |
| 2419 | (iucv_ConnectionQuiesced *)int_buf, |
| 2420 | h->pgm_data); |
| 2421 | else |
| 2422 | iucv_debug(1, |
| 2423 | "ConnectionQuiesced not called"); |
| 2424 | } |
| 2425 | break; |
| 2426 | |
| 2427 | case 0x05: /* connection resumed */ |
| 2428 | if (messagesDisabled) { |
| 2429 | iucv_setmask(~0); |
| 2430 | messagesDisabled = 0; |
| 2431 | } |
| 2432 | if (h) { |
| 2433 | if (interrupt->ConnectionResumed) |
| 2434 | interrupt->ConnectionResumed( |
| 2435 | (iucv_ConnectionResumed *)int_buf, |
| 2436 | h->pgm_data); |
| 2437 | else |
| 2438 | iucv_debug(1, |
| 2439 | "ConnectionResumed not called"); |
| 2440 | } |
| 2441 | break; |
| 2442 | |
| 2443 | case 0x06: /* priority message complete */ |
| 2444 | case 0x07: /* nonpriority message complete */ |
| 2445 | if (h) { |
| 2446 | if (interrupt->MessageComplete) |
| 2447 | interrupt->MessageComplete( |
| 2448 | (iucv_MessageComplete *)int_buf, |
| 2449 | h->pgm_data); |
| 2450 | else |
| 2451 | iucv_debug(2, |
| 2452 | "MessageComplete not called"); |
| 2453 | } |
| 2454 | break; |
| 2455 | |
| 2456 | case 0x08: /* priority message pending */ |
| 2457 | case 0x09: /* nonpriority message pending */ |
| 2458 | if (h) { |
| 2459 | if (interrupt->MessagePending) |
| 2460 | interrupt->MessagePending( |
| 2461 | (iucv_MessagePending *) int_buf, |
| 2462 | h->pgm_data); |
| 2463 | else |
| 2464 | iucv_debug(2, |
| 2465 | "MessagePending not called"); |
| 2466 | } |
| 2467 | break; |
| 2468 | default: /* unknown iucv type */ |
| 2469 | printk(KERN_WARNING "%s: unknown iucv interrupt\n", |
| 2470 | __FUNCTION__); |
| 2471 | break; |
| 2472 | } /* end switch */ |
| 2473 | |
| 2474 | iucv_debug(2, "exiting pathid %d, type %02X", |
| 2475 | int_buf->ippathid, int_buf->iptype); |
| 2476 | |
| 2477 | return; |
| 2478 | } |
| 2479 | |
| 2480 | /** |
| 2481 | * iucv_tasklet_handler: |
| 2482 | * |
| 2483 | * This function loops over the queue of irq buffers and runs iucv_do_int() |
| 2484 | * on every queue element. |
| 2485 | */ |
| 2486 | static void |
| 2487 | iucv_tasklet_handler(unsigned long ignored) |
| 2488 | { |
| 2489 | struct list_head head; |
| 2490 | struct list_head *next; |
| 2491 | ulong flags; |
| 2492 | |
| 2493 | spin_lock_irqsave(&iucv_irq_queue_lock, flags); |
| 2494 | list_add(&head, &iucv_irq_queue); |
| 2495 | list_del_init(&iucv_irq_queue); |
| 2496 | spin_unlock_irqrestore (&iucv_irq_queue_lock, flags); |
| 2497 | |
| 2498 | next = head.next; |
| 2499 | while (next != &head) { |
| 2500 | iucv_irqdata *p = list_entry(next, iucv_irqdata, queue); |
| 2501 | |
| 2502 | next = next->next; |
| 2503 | iucv_do_int(&p->data); |
| 2504 | kfree(p); |
| 2505 | } |
| 2506 | |
| 2507 | return; |
| 2508 | } |
| 2509 | |
| 2510 | subsys_initcall(iucv_init); |
| 2511 | module_exit(iucv_exit); |
| 2512 | |
| 2513 | /** |
| 2514 | * Export all public stuff |
| 2515 | */ |
| 2516 | EXPORT_SYMBOL (iucv_bus); |
| 2517 | EXPORT_SYMBOL (iucv_root); |
| 2518 | EXPORT_SYMBOL (iucv_accept); |
| 2519 | EXPORT_SYMBOL (iucv_connect); |
| 2520 | #if 0 |
| 2521 | EXPORT_SYMBOL (iucv_purge); |
| 2522 | EXPORT_SYMBOL (iucv_query_maxconn); |
| 2523 | EXPORT_SYMBOL (iucv_query_bufsize); |
| 2524 | EXPORT_SYMBOL (iucv_quiesce); |
| 2525 | #endif |
| 2526 | EXPORT_SYMBOL (iucv_receive); |
| 2527 | #if 0 |
| 2528 | EXPORT_SYMBOL (iucv_receive_array); |
| 2529 | #endif |
| 2530 | EXPORT_SYMBOL (iucv_reject); |
| 2531 | #if 0 |
| 2532 | EXPORT_SYMBOL (iucv_reply); |
| 2533 | EXPORT_SYMBOL (iucv_reply_array); |
| 2534 | EXPORT_SYMBOL (iucv_resume); |
| 2535 | #endif |
| 2536 | EXPORT_SYMBOL (iucv_reply_prmmsg); |
| 2537 | EXPORT_SYMBOL (iucv_send); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | EXPORT_SYMBOL (iucv_send2way); |
| 2539 | EXPORT_SYMBOL (iucv_send2way_array); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | EXPORT_SYMBOL (iucv_send2way_prmmsg); |
| 2541 | EXPORT_SYMBOL (iucv_send2way_prmmsg_array); |
Frank Pavlic | 5e39f29 | 2005-05-12 20:37:00 +0200 | [diff] [blame] | 2542 | #if 0 |
| 2543 | EXPORT_SYMBOL (iucv_send_array); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | EXPORT_SYMBOL (iucv_send_prmmsg); |
| 2545 | EXPORT_SYMBOL (iucv_setmask); |
| 2546 | #endif |
| 2547 | EXPORT_SYMBOL (iucv_sever); |
| 2548 | EXPORT_SYMBOL (iucv_register_program); |
| 2549 | EXPORT_SYMBOL (iucv_unregister_program); |