/* * FLAGS: * All flags are defined in the field IPFLAGS1 of each function * and can be found in CP Programming Services. * IPSRCCLS - Indicates you have specified a source class. * IPTRGCLS - Indicates you have specified a target class. * IPFGPID - Indicates you have specified a pathid. * IPFGMID - Indicates you have specified a message ID. * IPNORPY - Indicates a one-way message. No reply expected. * IPALL - Indicates that all paths are affected.
*/ #define IUCV_IPSRCCLS 0x01 #define IUCV_IPTRGCLS 0x01 #define IUCV_IPFGPID 0x02 #define IUCV_IPFGMID 0x04 #define IUCV_IPNORPY 0x10 #define IUCV_IPALL 0x80
/* * Queue of interrupt buffers lock for delivery via the tasklet * (fast but can't call smp_call_function).
*/ static LIST_HEAD(iucv_task_queue);
/* * The tasklet for fast delivery of iucv interrupts.
*/ staticvoid iucv_tasklet_fn(unsignedlong); static DECLARE_TASKLET_OLD(iucv_tasklet, iucv_tasklet_fn);
/* * Queue of interrupt buffers for delivery via a work queue * (slower but can call smp_call_function).
*/ static LIST_HEAD(iucv_work_queue);
/* * The work element to deliver path pending interrupts.
*/ staticvoid iucv_work_fn(struct work_struct *work); static DECLARE_WORK(iucv_work, iucv_work_fn);
/* * Spinlock protecting task and work queue.
*/ static DEFINE_SPINLOCK(iucv_queue_lock);
/* * Error messages that are used with the iucv_sever function. They get * converted to EBCDIC.
*/ staticchar iucv_error_no_listener[16] = "NO LISTENER"; staticchar iucv_error_no_memory[16] = "NO MEMORY"; staticchar iucv_error_pathid[16] = "INVALID PATHID";
/* * iucv_handler_list: List of registered handlers.
*/ static LIST_HEAD(iucv_handler_list);
/* * iucv_path_table: array of pointers to iucv_path structures.
*/ staticstruct iucv_path **iucv_path_table; staticunsignedlong iucv_max_pathid;
/* * iucv_active_cpu: contains the number of the cpu executing the tasklet * or the work handler. Needed for iucv_path_sever called from tasklet.
*/ staticint iucv_active_cpu = -1;
/* * Mutex and wait queue for iucv_register/iucv_unregister.
*/ static DEFINE_MUTEX(iucv_register_mutex);
/* * Counter for number of non-smp capable handlers.
*/ staticint iucv_nonsmp_handler;
/* * IUCV control data structure. Used by iucv_path_accept, iucv_path_connect, * iucv_path_quiesce and iucv_path_sever.
*/ struct iucv_cmd_control {
u16 ippathid;
u8 ipflags1;
u8 iprcode;
u16 ipmsglim;
u16 res1;
u8 ipvmid[8];
u8 ipuser[16];
u8 iptarget[8];
} __attribute__ ((packed,aligned(8)));
/* * Data in parameter list iucv structure. Used by iucv_message_send, * iucv_message_send2way and iucv_message_reply.
*/ struct iucv_cmd_dpl {
u16 ippathid;
u8 ipflags1;
u8 iprcode;
u32 ipmsgid;
u32 iptrgcls;
u8 iprmmsg[8];
u32 ipsrccls;
u32 ipmsgtag;
dma32_t ipbfadr2;
u32 ipbfln2f;
u32 res;
} __attribute__ ((packed,aligned(8)));
/* * Data in buffer iucv structure. Used by iucv_message_receive, * iucv_message_reject, iucv_message_send, iucv_message_send2way * and iucv_declare_cpu.
*/ struct iucv_cmd_db {
u16 ippathid;
u8 ipflags1;
u8 iprcode;
u32 ipmsgid;
u32 iptrgcls;
dma32_t ipbfadr1;
u32 ipbfln1f;
u32 ipsrccls;
u32 ipmsgtag;
dma32_t ipbfadr2;
u32 ipbfln2f;
u32 res;
} __attribute__ ((packed,aligned(8)));
/** * __iucv_call_b2f0 * @command: identifier of IUCV call to CP. * @parm: pointer to a struct iucv_parm block * * Calls CP to execute IUCV commands. * * Returns the result of the CP IUCV call.
*/ staticinlineint __iucv_call_b2f0(int command, union iucv_param *parm)
{ unsignedlong reg1 = virt_to_phys(parm); int cc;
/* * iucv_query_maxconn * * Determines the maximum number of connections that may be established. * * Returns the maximum number of connections or -EPERM is IUCV is not * available.
*/ staticint __iucv_query_maxconn(void *param, unsignedlong *max_pathid)
{ unsignedlong reg1 = virt_to_phys(param); int cc;
/** * iucv_allow_cpu * @data: unused * * Allow iucv interrupts on this cpu.
*/ staticvoid iucv_allow_cpu(void *data)
{ int cpu = smp_processor_id(); union iucv_param *parm;
/* * Enable all iucv interrupts. * ipmask contains bits for the different interrupts * 0x80 - Flag to allow nonpriority message pending interrupts * 0x40 - Flag to allow priority message pending interrupts * 0x20 - Flag to allow nonpriority message completion interrupts * 0x10 - Flag to allow priority message completion interrupts * 0x08 - Flag to allow IUCV control interrupts
*/
parm = iucv_param_irq[cpu];
memset(parm, 0, sizeof(union iucv_param));
parm->set_mask.ipmask = 0xf8;
iucv_call_b2f0(IUCV_SETMASK, parm);
/* * Enable all iucv control interrupts. * ipmask contains bits for the different interrupts * 0x80 - Flag to allow pending connections interrupts * 0x40 - Flag to allow connection complete interrupts * 0x20 - Flag to allow connection severed interrupts * 0x10 - Flag to allow connection quiesced interrupts * 0x08 - Flag to allow connection resumed interrupts
*/
memset(parm, 0, sizeof(union iucv_param));
parm->set_mask.ipmask = 0xf8;
iucv_call_b2f0(IUCV_SETCONTROLMASK, parm); /* Set indication that iucv interrupts are allowed for this cpu. */
cpumask_set_cpu(cpu, &iucv_irq_cpumask);
}
/** * iucv_block_cpu * @data: unused * * Block iucv interrupts on this cpu.
*/ staticvoid iucv_block_cpu(void *data)
{ int cpu = smp_processor_id(); union iucv_param *parm;
/* Clear indication that iucv interrupts are allowed for this cpu. */
cpumask_clear_cpu(cpu, &iucv_irq_cpumask);
}
/** * iucv_declare_cpu * @data: unused * * Declare a interrupt buffer on this cpu.
*/ staticvoid iucv_declare_cpu(void *data)
{ int cpu = smp_processor_id(); union iucv_param *parm; int rc;
if (cpumask_test_cpu(cpu, &iucv_buffer_cpumask)) return;
/* Declare interrupt buffer. */
parm = iucv_param_irq[cpu];
memset(parm, 0, sizeof(union iucv_param));
parm->db.ipbfadr1 = virt_to_dma32(iucv_irq_data[cpu]);
rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm); if (rc) { char *err = "Unknown"; switch (rc) { case 0x03:
err = "Directory error"; break; case 0x0a:
err = "Invalid length"; break; case 0x13:
err = "Buffer already exists"; break; case 0x3e:
err = "Buffer overlap"; break; case 0x5c:
err = "Paging or storage error"; break;
}
pr_warn("Defining an interrupt buffer on CPU %i failed with 0x%02x (%s)\n",
cpu, rc, err); return;
}
/* Set indication that an iucv buffer exists for this cpu. */
cpumask_set_cpu(cpu, &iucv_buffer_cpumask);
if (iucv_nonsmp_handler == 0 || cpumask_empty(&iucv_irq_cpumask)) /* Enable iucv interrupts on this cpu. */
iucv_allow_cpu(NULL); else /* Disable iucv interrupts on this cpu. */
iucv_block_cpu(NULL);
}
/** * iucv_retrieve_cpu * @data: unused * * Retrieve interrupt buffer on this cpu.
*/ staticvoid iucv_retrieve_cpu(void *data)
{ int cpu = smp_processor_id(); union iucv_param *parm;
if (!cpumask_test_cpu(cpu, &iucv_buffer_cpumask)) return;
/* Clear indication that an iucv buffer exists for this cpu. */
cpumask_clear_cpu(cpu, &iucv_buffer_cpumask);
}
/* * iucv_setmask_mp * * Allow iucv interrupts on all cpus.
*/ staticvoid iucv_setmask_mp(void)
{ int cpu;
cpus_read_lock();
for_each_online_cpu(cpu) /* Enable all cpus with a declared buffer. */ if (cpumask_test_cpu(cpu, &iucv_buffer_cpumask) &&
!cpumask_test_cpu(cpu, &iucv_irq_cpumask))
smp_call_function_single(cpu, iucv_allow_cpu,
NULL, 1);
cpus_read_unlock();
}
/* * iucv_setmask_up * * Allow iucv interrupts on a single cpu.
*/ staticvoid iucv_setmask_up(void)
{ static cpumask_t cpumask; int cpu;
/* Disable all cpu but the first in cpu_irq_cpumask. */
cpumask_copy(&cpumask, &iucv_irq_cpumask);
cpumask_clear_cpu(cpumask_first(&iucv_irq_cpumask), &cpumask);
for_each_cpu(cpu, &cpumask)
smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
}
/* * iucv_enable * * This function makes iucv ready for use. It allocates the pathid * table, declares an iucv interrupt buffer and enables the iucv * interrupts. Called when the first user has registered an iucv * handler.
*/ staticint iucv_enable(void)
{
size_t alloc_size; int cpu, rc;
cpus_read_lock();
rc = -ENOMEM;
alloc_size = iucv_max_pathid * sizeof(*iucv_path_table);
iucv_path_table = kzalloc(alloc_size, GFP_KERNEL); if (!iucv_path_table) goto out; /* Declare per cpu buffers. */
rc = -EIO;
for_each_online_cpu(cpu)
smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1); if (cpumask_empty(&iucv_buffer_cpumask)) /* No cpu could declare an iucv buffer. */ goto out;
cpus_read_unlock(); return 0;
out:
kfree(iucv_path_table);
iucv_path_table = NULL;
cpus_read_unlock(); return rc;
}
/* * iucv_disable * * This function shuts down iucv. It disables iucv interrupts, retrieves * the iucv interrupt buffer and frees the pathid table. Called after the * last user unregister its iucv handler.
*/ staticvoid iucv_disable(void)
{
cpus_read_lock();
on_each_cpu(iucv_retrieve_cpu, NULL, 1);
kfree(iucv_path_table);
iucv_path_table = NULL;
cpus_read_unlock();
}
/** * iucv_sever_pathid * @pathid: path identification number. * @userdata: 16-bytes of user data. * * Sever an iucv path to free up the pathid. Used internally.
*/ staticint iucv_sever_pathid(u16 pathid, u8 *userdata)
{ union iucv_param *parm;
/** * __iucv_cleanup_queue * @dummy: unused dummy argument * * Nop function called via smp_call_function to force work items from * pending external iucv interrupts to the work queue.
*/ staticvoid __iucv_cleanup_queue(void *dummy)
{
}
/** * iucv_cleanup_queue * * Function called after a path has been severed to find all remaining * work items for the now stale pathid. The caller needs to hold the * iucv_table_lock.
*/ staticvoid iucv_cleanup_queue(void)
{ struct iucv_irq_list *p, *n;
/* * When a path is severed, the pathid can be reused immediately * on a iucv connect or a connection pending interrupt. Remove * all entries from the task queue that refer to a stale pathid * (iucv_path_table[ix] == NULL). Only then do the iucv connect * or deliver the connection pending interrupt. To get all the * pending interrupts force them to the work queue by calling * an empty function on all cpus.
*/
smp_call_function(__iucv_cleanup_queue, NULL, 1);
spin_lock_irq(&iucv_queue_lock);
list_for_each_entry_safe(p, n, &iucv_task_queue, list) { /* Remove stale work items from the task queue. */ if (iucv_path_table[p->data.ippathid] == NULL) {
list_del(&p->list);
kfree(p);
}
}
spin_unlock_irq(&iucv_queue_lock);
}
/** * iucv_register: * @handler: address of iucv handler structure * @smp: != 0 indicates that the handler can deal with out of order messages * * Registers a driver with IUCV. * * Returns 0 on success, -ENOMEM if the memory allocation for the pathid * table failed, or -EIO if IUCV_DECLARE_BUFFER failed on all cpus.
*/ int iucv_register(struct iucv_handler *handler, int smp)
{ int rc;
if (!iucv_available) return -ENOSYS;
mutex_lock(&iucv_register_mutex); if (!smp)
iucv_nonsmp_handler++; if (list_empty(&iucv_handler_list)) {
rc = iucv_enable(); if (rc) goto out_mutex;
} elseif (!smp && iucv_nonsmp_handler == 1)
iucv_setmask_up();
INIT_LIST_HEAD(&handler->paths);
/** * iucv_unregister * @handler: address of iucv handler structure * @smp: != 0 indicates that the handler can deal with out of order messages * * Unregister driver from IUCV.
*/ void iucv_unregister(struct iucv_handler *handler, int smp)
{ struct iucv_path *p, *n;
mutex_lock(&iucv_register_mutex);
spin_lock_bh(&iucv_table_lock); /* Remove handler from the iucv_handler_list. */
list_del_init(&handler->list); /* Sever all pathids still referring to the handler. */
list_for_each_entry_safe(p, n, &handler->paths, list) {
iucv_sever_pathid(p->pathid, NULL);
iucv_path_table[p->pathid] = NULL;
list_del(&p->list);
iucv_path_free(p);
}
spin_unlock_bh(&iucv_table_lock); if (!smp)
iucv_nonsmp_handler--; if (list_empty(&iucv_handler_list))
iucv_disable(); elseif (!smp && iucv_nonsmp_handler == 0)
iucv_setmask_mp();
mutex_unlock(&iucv_register_mutex);
}
EXPORT_SYMBOL(iucv_unregister);
/** * iucv_path_accept * @path: address of iucv path structure * @handler: address of iucv handler structure * @userdata: 16 bytes of data reflected to the communication partner * @private: private data passed to interrupt handlers for this path * * This function is issued after the user received a connection pending * external interrupt and now wishes to complete the IUCV communication path. * * Returns the result of the CP IUCV call.
*/ int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
u8 *userdata, void *private)
{ union iucv_param *parm; int rc;
/** * iucv_path_connect * @path: address of iucv path structure * @handler: address of iucv handler structure * @userid: 8-byte user identification * @system: 8-byte target system identification * @userdata: 16 bytes of data reflected to the communication partner * @private: private data passed to interrupt handlers for this path * * This function establishes an IUCV path. Although the connect may complete * successfully, you are not able to use the path until you receive an IUCV * Connection Complete external interrupt. * * Returns the result of the CP IUCV call.
*/ int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
u8 *userid, u8 *system, u8 *userdata, void *private)
{ union iucv_param *parm; int rc;
/** * iucv_path_quiesce: * @path: address of iucv path structure * @userdata: 16 bytes of data reflected to the communication partner * * This function temporarily suspends incoming messages on an IUCV path. * You can later reactivate the path by invoking the iucv_resume function. * * Returns the result from the CP IUCV call.
*/ int iucv_path_quiesce(struct iucv_path *path, u8 *userdata)
{ union iucv_param *parm; int rc;
/** * iucv_path_resume: * @path: address of iucv path structure * @userdata: 16 bytes of data reflected to the communication partner * * This function resumes incoming messages on an IUCV path that has * been stopped with iucv_path_quiesce. * * Returns the result from the CP IUCV call.
*/ int iucv_path_resume(struct iucv_path *path, u8 *userdata)
{ union iucv_param *parm; int rc;
/** * iucv_path_sever * @path: address of iucv path structure * @userdata: 16 bytes of data reflected to the communication partner * * This function terminates an IUCV path. * * Returns the result from the CP IUCV call.
*/ int iucv_path_sever(struct iucv_path *path, u8 *userdata)
{ int rc;
/** * iucv_message_purge * @path: address of iucv path structure * @msg: address of iucv msg structure * @srccls: source class of message * * Cancels a message you have sent. * * Returns the result from the CP IUCV call.
*/ int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
u32 srccls)
{ union iucv_param *parm; int rc;
/** * iucv_message_receive_iprmdata * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is received (IUCV_IPBUFLST) * @buffer: address of data buffer or address of struct iucv_array * @size: length of data buffer * @residual: * * Internal function used by iucv_message_receive and __iucv_message_receive * to receive RMDATA data stored in struct iucv_message.
*/ staticint iucv_message_receive_iprmdata(struct iucv_path *path, struct iucv_message *msg,
u8 flags, void *buffer,
size_t size, size_t *residual)
{ struct iucv_array *array;
u8 *rmmsg;
size_t copy;
/* * Message is 8 bytes long and has been stored to the * message descriptor itself.
*/ if (residual)
*residual = abs(size - 8);
rmmsg = msg->rmmsg; if (flags & IUCV_IPBUFLST) { /* Copy to struct iucv_array. */
size = (size < 8) ? size : 8; for (array = buffer; size > 0; array++) {
copy = min_t(size_t, size, array->length);
memcpy(dma32_to_virt(array->address), rmmsg, copy);
rmmsg += copy;
size -= copy;
}
} else { /* Copy to direct buffer. */
memcpy(buffer, rmmsg, min_t(size_t, size, 8));
} return 0;
}
/** * __iucv_message_receive * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is received (IUCV_IPBUFLST) * @buffer: address of data buffer or address of struct iucv_array * @size: length of data buffer * @residual: * * This function receives messages that are being sent to you over * established paths. This function will deal with RMDATA messages * embedded in struct iucv_message as well. * * Locking: no locking * * Returns the result from the CP IUCV call.
*/ int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
u8 flags, void *buffer, size_t size, size_t *residual)
{ union iucv_param *parm; int rc;
if (msg->flags & IUCV_IPRMDATA) return iucv_message_receive_iprmdata(path, msg, flags,
buffer, size, residual); if (cpumask_empty(&iucv_buffer_cpumask)) return -EIO;
/** * iucv_message_receive * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is received (IUCV_IPBUFLST) * @buffer: address of data buffer or address of struct iucv_array * @size: length of data buffer * @residual: * * This function receives messages that are being sent to you over * established paths. This function will deal with RMDATA messages * embedded in struct iucv_message as well. * * Locking: local_bh_enable/local_bh_disable * * Returns the result from the CP IUCV call.
*/ int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
u8 flags, void *buffer, size_t size, size_t *residual)
{ int rc;
/** * iucv_message_reject * @path: address of iucv path structure * @msg: address of iucv msg structure * * The reject function refuses a specified message. Between the time you * are notified of a message and the time that you complete the message, * the message may be rejected. * * Returns the result from the CP IUCV call.
*/ int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
{ union iucv_param *parm; int rc;
/** * iucv_message_reply * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the reply is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST) * @reply: address of reply data buffer or address of struct iucv_array * @size: length of reply data buffer * * This function responds to the two-way messages that you receive. You * must identify completely the message to which you wish to reply. ie, * pathid, msgid, and trgcls. Prmmsg signifies the data is moved into * the parameter list. * * Returns the result from the CP IUCV call.
*/ int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
u8 flags, void *reply, size_t size)
{ union iucv_param *parm; int rc;
/** * __iucv_message_send * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST) * @srccls: source class of message * @buffer: address of send buffer or address of struct iucv_array * @size: length of send buffer * * This function transmits data to another application. Data to be * transmitted is in a buffer and this is a one-way message and the * receiver will not reply to the message. * * Locking: no locking * * Returns the result from the CP IUCV call.
*/ int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
u8 flags, u32 srccls, void *buffer, size_t size)
{ union iucv_param *parm; int rc;
/** * iucv_message_send * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST) * @srccls: source class of message * @buffer: address of send buffer or address of struct iucv_array * @size: length of send buffer * * This function transmits data to another application. Data to be * transmitted is in a buffer and this is a one-way message and the * receiver will not reply to the message. * * Locking: local_bh_enable/local_bh_disable * * Returns the result from the CP IUCV call.
*/ int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
u8 flags, u32 srccls, void *buffer, size_t size)
{ int rc;
/** * iucv_message_send2way * @path: address of iucv path structure * @msg: address of iucv msg structure * @flags: how the message is sent and the reply is received * (IUCV_IPRMDATA, IUCV_IPBUFLST, IUCV_IPPRTY, IUCV_ANSLST) * @srccls: source class of message * @buffer: address of send buffer or address of struct iucv_array * @size: length of send buffer * @answer: address of answer buffer or address of struct iucv_array * @asize: size of reply buffer * @residual: ignored * * This function transmits data to another application. Data to be * transmitted is in a buffer. The receiver of the send is expected to * reply to the message and a buffer is provided into which IUCV moves * the reply to this message. * * Returns the result from the CP IUCV call.
*/ int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
u8 flags, u32 srccls, void *buffer, size_t size, void *answer, size_t asize, size_t *residual)
{ union iucv_param *parm; int rc;
/** * iucv_path_pending * @data: Pointer to external interrupt buffer * * Process connection pending work item. Called from tasklet while holding * iucv_table_lock.
*/ staticvoid iucv_path_pending(struct iucv_irq_data *data)
{ struct iucv_path_pending *ipp = (void *) data; struct iucv_handler *handler; struct iucv_path *path; char *error;
BUG_ON(iucv_path_table[ipp->ippathid]); /* New pathid, handler found. Create a new path struct. */
error = iucv_error_no_memory;
path = iucv_path_alloc(ipp->ipmsglim, ipp->ipflags1, GFP_ATOMIC); if (!path) goto out_sever;
path->pathid = ipp->ippathid;
iucv_path_table[path->pathid] = path;
EBCASC(ipp->ipvmid, 8);
/* Call registered handler until one is found that wants the path. */
list_for_each_entry(handler, &iucv_handler_list, list) { if (!handler->path_pending) continue; /* * Add path to handler to allow a call to iucv_path_sever * inside the path_pending function. If the handler returns * an error remove the path from the handler again.
*/
list_add(&path->list, &handler->paths);
path->handler = handler; if (!handler->path_pending(path, ipp->ipvmid, ipp->ipuser)) return;
list_del(&path->list);
path->handler = NULL;
} /* No handler wanted the path. */
iucv_path_table[path->pathid] = NULL;
iucv_path_free(path);
error = iucv_error_no_listener;
out_sever:
iucv_sever_pathid(ipp->ippathid, error);
}
/* * iucv_work_fn: * * This work function loops over the queue of path pending irq blocks * created by iucv_external_interrupt, calls the appropriate action * handler and then frees the buffer.
*/ staticvoid iucv_work_fn(struct work_struct *work)
{
LIST_HEAD(work_queue); struct iucv_irq_list *p, *n;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.