s390/ap: move receive callback to message struct

Move the receive callback from zdev_driver to ap_message structure to
get a more flexible asynchronous ap message handling.

Signed-off-by: Holger Dengler <hd@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
Holger Dengler 2012-05-16 14:08:22 +02:00 committed by Martin Schwidefsky
parent 505e5ecfd3
commit 54a8f5611d
6 changed files with 24 additions and 13 deletions

View File

@ -836,12 +836,12 @@ static void __ap_flush_queue(struct ap_device *ap_dev)
list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) { list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
list_del_init(&ap_msg->list); list_del_init(&ap_msg->list);
ap_dev->pendingq_count--; ap_dev->pendingq_count--;
ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
} }
list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) { list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
list_del_init(&ap_msg->list); list_del_init(&ap_msg->list);
ap_dev->requestq_count--; ap_dev->requestq_count--;
ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
} }
} }
@ -1329,7 +1329,7 @@ static int ap_poll_read(struct ap_device *ap_dev, unsigned long *flags)
continue; continue;
list_del_init(&ap_msg->list); list_del_init(&ap_msg->list);
ap_dev->pendingq_count--; ap_dev->pendingq_count--;
ap_dev->drv->receive(ap_dev, ap_msg, ap_dev->reply); ap_msg->receive(ap_dev, ap_msg, ap_dev->reply);
break; break;
} }
if (ap_dev->queue_count > 0) if (ap_dev->queue_count > 0)
@ -1450,10 +1450,10 @@ static int __ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_ms
return -EBUSY; return -EBUSY;
case AP_RESPONSE_REQ_FAC_NOT_INST: case AP_RESPONSE_REQ_FAC_NOT_INST:
case AP_RESPONSE_MESSAGE_TOO_BIG: case AP_RESPONSE_MESSAGE_TOO_BIG:
ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL)); ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-EINVAL));
return -EINVAL; return -EINVAL;
default: /* Device is gone. */ default: /* Device is gone. */
ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
return -ENODEV; return -ENODEV;
} }
} else { } else {
@ -1471,6 +1471,10 @@ void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
unsigned long flags; unsigned long flags;
int rc; int rc;
/* For asynchronous message handling a valid receive-callback
* is required. */
BUG_ON(!ap_msg->receive);
spin_lock_bh(&ap_dev->lock); spin_lock_bh(&ap_dev->lock);
if (!ap_dev->unregistered) { if (!ap_dev->unregistered) {
/* Make room on the queue by polling for finished requests. */ /* Make room on the queue by polling for finished requests. */
@ -1482,7 +1486,7 @@ void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
if (rc == -ENODEV) if (rc == -ENODEV)
ap_dev->unregistered = 1; ap_dev->unregistered = 1;
} else { } else {
ap_dev->drv->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV)); ap_msg->receive(ap_dev, ap_msg, ERR_PTR(-ENODEV));
rc = -ENODEV; rc = -ENODEV;
} }
spin_unlock_bh(&ap_dev->lock); spin_unlock_bh(&ap_dev->lock);

View File

@ -136,9 +136,6 @@ struct ap_driver {
int (*probe)(struct ap_device *); int (*probe)(struct ap_device *);
void (*remove)(struct ap_device *); void (*remove)(struct ap_device *);
/* receive is called from tasklet context */
void (*receive)(struct ap_device *, struct ap_message *,
struct ap_message *);
int request_timeout; /* request timeout in jiffies */ int request_timeout; /* request timeout in jiffies */
}; };
@ -183,6 +180,9 @@ struct ap_message {
void *private; /* ap driver private pointer. */ void *private; /* ap driver private pointer. */
unsigned int special:1; /* Used for special commands. */ unsigned int special:1; /* Used for special commands. */
/* receive is called from tasklet context */
void (*receive)(struct ap_device *, struct ap_message *,
struct ap_message *);
}; };
#define AP_DEVICE(dt) \ #define AP_DEVICE(dt) \
@ -199,6 +199,7 @@ static inline void ap_init_message(struct ap_message *ap_msg)
ap_msg->psmid = 0; ap_msg->psmid = 0;
ap_msg->length = 0; ap_msg->length = 0;
ap_msg->special = 0; ap_msg->special = 0;
ap_msg->receive = NULL;
} }
/* /*

View File

@ -77,7 +77,6 @@ static void zcrypt_cex2a_receive(struct ap_device *, struct ap_message *,
static struct ap_driver zcrypt_cex2a_driver = { static struct ap_driver zcrypt_cex2a_driver = {
.probe = zcrypt_cex2a_probe, .probe = zcrypt_cex2a_probe,
.remove = zcrypt_cex2a_remove, .remove = zcrypt_cex2a_remove,
.receive = zcrypt_cex2a_receive,
.ids = zcrypt_cex2a_ids, .ids = zcrypt_cex2a_ids,
.request_timeout = CEX2A_CLEANUP_TIME, .request_timeout = CEX2A_CLEANUP_TIME,
}; };
@ -349,6 +348,7 @@ static long zcrypt_cex2a_modexpo(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_cex2a_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &work; ap_msg.private = &work;
@ -390,6 +390,7 @@ static long zcrypt_cex2a_modexpo_crt(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(CEX3A_MAX_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_cex2a_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &work; ap_msg.private = &work;

View File

@ -67,7 +67,6 @@ static void zcrypt_pcica_receive(struct ap_device *, struct ap_message *,
static struct ap_driver zcrypt_pcica_driver = { static struct ap_driver zcrypt_pcica_driver = {
.probe = zcrypt_pcica_probe, .probe = zcrypt_pcica_probe,
.remove = zcrypt_pcica_remove, .remove = zcrypt_pcica_remove,
.receive = zcrypt_pcica_receive,
.ids = zcrypt_pcica_ids, .ids = zcrypt_pcica_ids,
.request_timeout = PCICA_CLEANUP_TIME, .request_timeout = PCICA_CLEANUP_TIME,
}; };
@ -284,6 +283,7 @@ static long zcrypt_pcica_modexpo(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcica_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &work; ap_msg.private = &work;
@ -322,6 +322,7 @@ static long zcrypt_pcica_modexpo_crt(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(PCICA_MAX_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcica_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &work; ap_msg.private = &work;

View File

@ -79,7 +79,6 @@ static void zcrypt_pcicc_receive(struct ap_device *, struct ap_message *,
static struct ap_driver zcrypt_pcicc_driver = { static struct ap_driver zcrypt_pcicc_driver = {
.probe = zcrypt_pcicc_probe, .probe = zcrypt_pcicc_probe,
.remove = zcrypt_pcicc_remove, .remove = zcrypt_pcicc_remove,
.receive = zcrypt_pcicc_receive,
.ids = zcrypt_pcicc_ids, .ids = zcrypt_pcicc_ids,
.request_timeout = PCICC_CLEANUP_TIME, .request_timeout = PCICC_CLEANUP_TIME,
}; };
@ -488,6 +487,7 @@ static long zcrypt_pcicc_modexpo(struct zcrypt_device *zdev,
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcicc_receive;
ap_msg.length = PAGE_SIZE; ap_msg.length = PAGE_SIZE;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
@ -527,6 +527,7 @@ static long zcrypt_pcicc_modexpo_crt(struct zcrypt_device *zdev,
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcicc_receive;
ap_msg.length = PAGE_SIZE; ap_msg.length = PAGE_SIZE;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);

View File

@ -89,7 +89,6 @@ static void zcrypt_pcixcc_receive(struct ap_device *, struct ap_message *,
static struct ap_driver zcrypt_pcixcc_driver = { static struct ap_driver zcrypt_pcixcc_driver = {
.probe = zcrypt_pcixcc_probe, .probe = zcrypt_pcixcc_probe,
.remove = zcrypt_pcixcc_remove, .remove = zcrypt_pcixcc_remove,
.receive = zcrypt_pcixcc_receive,
.ids = zcrypt_pcixcc_ids, .ids = zcrypt_pcixcc_ids,
.request_timeout = PCIXCC_CLEANUP_TIME, .request_timeout = PCIXCC_CLEANUP_TIME,
}; };
@ -698,6 +697,7 @@ static long zcrypt_pcixcc_modexpo(struct zcrypt_device *zdev,
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcixcc_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &resp_type; ap_msg.private = &resp_type;
@ -738,6 +738,7 @@ static long zcrypt_pcixcc_modexpo_crt(struct zcrypt_device *zdev,
ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL); ap_msg.message = (void *) get_zeroed_page(GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcixcc_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &resp_type; ap_msg.private = &resp_type;
@ -778,6 +779,7 @@ static long zcrypt_pcixcc_send_cprb(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcixcc_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &resp_type; ap_msg.private = &resp_type;
@ -818,6 +820,7 @@ static long zcrypt_pcixcc_rng(struct zcrypt_device *zdev,
ap_msg.message = kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL); ap_msg.message = kmalloc(PCIXCC_MAX_XCRB_MESSAGE_SIZE, GFP_KERNEL);
if (!ap_msg.message) if (!ap_msg.message)
return -ENOMEM; return -ENOMEM;
ap_msg.receive = zcrypt_pcixcc_receive;
ap_msg.psmid = (((unsigned long long) current->pid) << 32) + ap_msg.psmid = (((unsigned long long) current->pid) << 32) +
atomic_inc_return(&zcrypt_step); atomic_inc_return(&zcrypt_step);
ap_msg.private = &resp_type; ap_msg.private = &resp_type;