mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
This patch provides support for new dynamic AP bus message limit with the existing zcrypt device driver and AP bus core code. There is support for a new field 'ml' from TAPQ query. The field gives if != 0 the AP bus limit for this card in 4k chunk units. The actual message size limit per card is shown as a new read-only sysfs attribute. The sysfs attribute /sys/devices/ap/cardxx/max_msg_size shows the upper limit in bytes used by the AP bus and zcrypt device driver for requests and replies send to and received from this card. Currently up to CEX7 support only max 12kB msg size and thus the field shows 12288 meaning the upper limit of a valid msg for this card is 12kB. Please note that the usable payload is somewhat lower and depends on the msg type and thus the header struct which is to be prepended by the zcrypt dd. The dispatcher responsible for choosing the right card and queue is aware of the individual card AP bus message limit. So a request is only assigned to a queue of a card which is able to handle the size of the request (e.g. a 14kB request will never go to a max 12kB card). If no such card is found the ioctl will fail with ENODEV. The reply buffer held by the device driver is determined by the ml field of the TAPQ for this card. If a response from the card exceeds this limit however, the response is not truncated but the ioctl for this request will fail with errno EMSGSIZE to indicate that the device driver has dropped the response because it would overflow the buffer limit. If the request size does not indicate to the dispatcher that an adapter with extended limit is to be used, a random card will be chosen when no specific card is addressed (ANY addressing). This may result in an ioctl failure when the reply size needs an adapter with extended limit but the randomly chosen one is not capable of handling the broader reply size. The user space application needs to use dedicated addressing to forward such a request only to suitable cards to get requests like this processed properly. Signed-off-by: Harald Freudenberger <freude@linux.ibm.com> Reviewed-by: Ingo Tuchscherer <ingo.tuchscherer@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
232 lines
5.4 KiB
C
232 lines
5.4 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright IBM Corp. 2001, 2012
|
|
* Author(s): Robert Burroughs
|
|
* Eric Rossman (edrossma@us.ibm.com)
|
|
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
*
|
|
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
|
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
|
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/miscdevice.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/hw_random.h>
|
|
#include <linux/debugfs.h>
|
|
#include <asm/debug.h>
|
|
|
|
#include "zcrypt_debug.h"
|
|
#include "zcrypt_api.h"
|
|
|
|
#include "zcrypt_msgtype6.h"
|
|
#include "zcrypt_msgtype50.h"
|
|
|
|
/*
|
|
* Device attributes common for all crypto queue devices.
|
|
*/
|
|
|
|
static ssize_t online_show(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct ap_queue *aq = to_ap_queue(dev);
|
|
struct zcrypt_queue *zq = aq->private;
|
|
int online = aq->config && zq->online ? 1 : 0;
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%d\n", online);
|
|
}
|
|
|
|
static ssize_t online_store(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct ap_queue *aq = to_ap_queue(dev);
|
|
struct zcrypt_queue *zq = aq->private;
|
|
struct zcrypt_card *zc = zq->zcard;
|
|
int online;
|
|
|
|
if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1)
|
|
return -EINVAL;
|
|
|
|
if (online && (!aq->config || !aq->card->config))
|
|
return -ENODEV;
|
|
if (online && !zc->online)
|
|
return -EINVAL;
|
|
zq->online = online;
|
|
|
|
ZCRYPT_DBF(DBF_INFO, "queue=%02x.%04x online=%d\n",
|
|
AP_QID_CARD(zq->queue->qid),
|
|
AP_QID_QUEUE(zq->queue->qid),
|
|
online);
|
|
|
|
ap_send_online_uevent(&aq->ap_dev, online);
|
|
|
|
if (!online)
|
|
ap_flush_queue(zq->queue);
|
|
return count;
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(online);
|
|
|
|
static ssize_t load_show(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct zcrypt_queue *zq = to_ap_queue(dev)->private;
|
|
|
|
return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&zq->load));
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(load);
|
|
|
|
static struct attribute *zcrypt_queue_attrs[] = {
|
|
&dev_attr_online.attr,
|
|
&dev_attr_load.attr,
|
|
NULL,
|
|
};
|
|
|
|
static const struct attribute_group zcrypt_queue_attr_group = {
|
|
.attrs = zcrypt_queue_attrs,
|
|
};
|
|
|
|
bool zcrypt_queue_force_online(struct zcrypt_queue *zq, int online)
|
|
{
|
|
if (!!zq->online != !!online) {
|
|
zq->online = online;
|
|
if (!online)
|
|
ap_flush_queue(zq->queue);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
struct zcrypt_queue *zcrypt_queue_alloc(size_t reply_buf_size)
|
|
{
|
|
struct zcrypt_queue *zq;
|
|
|
|
zq = kzalloc(sizeof(struct zcrypt_queue), GFP_KERNEL);
|
|
if (!zq)
|
|
return NULL;
|
|
zq->reply.msg = kmalloc(reply_buf_size, GFP_KERNEL);
|
|
if (!zq->reply.msg)
|
|
goto out_free;
|
|
zq->reply.bufsize = reply_buf_size;
|
|
INIT_LIST_HEAD(&zq->list);
|
|
kref_init(&zq->refcount);
|
|
return zq;
|
|
|
|
out_free:
|
|
kfree(zq);
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_alloc);
|
|
|
|
void zcrypt_queue_free(struct zcrypt_queue *zq)
|
|
{
|
|
kfree(zq->reply.msg);
|
|
kfree(zq);
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_free);
|
|
|
|
static void zcrypt_queue_release(struct kref *kref)
|
|
{
|
|
struct zcrypt_queue *zq =
|
|
container_of(kref, struct zcrypt_queue, refcount);
|
|
zcrypt_queue_free(zq);
|
|
}
|
|
|
|
void zcrypt_queue_get(struct zcrypt_queue *zq)
|
|
{
|
|
kref_get(&zq->refcount);
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_get);
|
|
|
|
int zcrypt_queue_put(struct zcrypt_queue *zq)
|
|
{
|
|
return kref_put(&zq->refcount, zcrypt_queue_release);
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_put);
|
|
|
|
/**
|
|
* zcrypt_queue_register() - Register a crypto queue device.
|
|
* @zq: Pointer to a crypto queue device
|
|
*
|
|
* Register a crypto queue device. Returns 0 if successful.
|
|
*/
|
|
int zcrypt_queue_register(struct zcrypt_queue *zq)
|
|
{
|
|
struct zcrypt_card *zc;
|
|
int rc;
|
|
|
|
spin_lock(&zcrypt_list_lock);
|
|
zc = zq->queue->card->private;
|
|
zcrypt_card_get(zc);
|
|
zq->zcard = zc;
|
|
zq->online = 1; /* New devices are online by default. */
|
|
|
|
ZCRYPT_DBF(DBF_INFO, "queue=%02x.%04x register online=1\n",
|
|
AP_QID_CARD(zq->queue->qid), AP_QID_QUEUE(zq->queue->qid));
|
|
|
|
list_add_tail(&zq->list, &zc->zqueues);
|
|
spin_unlock(&zcrypt_list_lock);
|
|
|
|
rc = sysfs_create_group(&zq->queue->ap_dev.device.kobj,
|
|
&zcrypt_queue_attr_group);
|
|
if (rc)
|
|
goto out;
|
|
|
|
if (zq->ops->rng) {
|
|
rc = zcrypt_rng_device_add();
|
|
if (rc)
|
|
goto out_unregister;
|
|
}
|
|
return 0;
|
|
|
|
out_unregister:
|
|
sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
|
|
&zcrypt_queue_attr_group);
|
|
out:
|
|
spin_lock(&zcrypt_list_lock);
|
|
list_del_init(&zq->list);
|
|
spin_unlock(&zcrypt_list_lock);
|
|
zcrypt_card_put(zc);
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_register);
|
|
|
|
/**
|
|
* zcrypt_queue_unregister(): Unregister a crypto queue device.
|
|
* @zq: Pointer to crypto queue device
|
|
*
|
|
* Unregister a crypto queue device.
|
|
*/
|
|
void zcrypt_queue_unregister(struct zcrypt_queue *zq)
|
|
{
|
|
struct zcrypt_card *zc;
|
|
|
|
ZCRYPT_DBF(DBF_INFO, "queue=%02x.%04x unregister\n",
|
|
AP_QID_CARD(zq->queue->qid), AP_QID_QUEUE(zq->queue->qid));
|
|
|
|
zc = zq->zcard;
|
|
spin_lock(&zcrypt_list_lock);
|
|
list_del_init(&zq->list);
|
|
spin_unlock(&zcrypt_list_lock);
|
|
if (zq->ops->rng)
|
|
zcrypt_rng_device_remove();
|
|
sysfs_remove_group(&zq->queue->ap_dev.device.kobj,
|
|
&zcrypt_queue_attr_group);
|
|
zcrypt_card_put(zc);
|
|
zcrypt_queue_put(zq);
|
|
}
|
|
EXPORT_SYMBOL(zcrypt_queue_unregister);
|