Commit 5e55a488 authored by Holger Dengler's avatar Holger Dengler Committed by Martin Schwidefsky

s390/zcrypt: Separate msgtype implementation from card modules.

Msgtype implementations are now separated from card specific modules
and can be dynamically registered. Existing msgtype implementations
are restructured in modules.
Signed-off-by: default avatarHolger Dengler <hd@linux.vnet.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent b26bd941
...@@ -5,3 +5,4 @@ ...@@ -5,3 +5,4 @@
ap-objs := ap_bus.o ap-objs := ap_bus.o
obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcicc.o zcrypt_pcixcc.o obj-$(CONFIG_ZCRYPT) += ap.o zcrypt_api.o zcrypt_pcicc.o zcrypt_pcixcc.o
obj-$(CONFIG_ZCRYPT) += zcrypt_pcica.o zcrypt_cex2a.o obj-$(CONFIG_ZCRYPT) += zcrypt_pcica.o zcrypt_cex2a.o
obj-$(CONFIG_ZCRYPT) += zcrypt_msgtype6.o zcrypt_msgtype50.o
/* /*
* zcrypt 2.1.0 * zcrypt 2.1.0
* *
* Copyright IBM Corp. 2001, 2006 * Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs * Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com) * Eric Rossman (edrossma@us.ibm.com)
* Cornelia Huck <cornelia.huck@de.ibm.com> * Cornelia Huck <cornelia.huck@de.ibm.com>
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* Ralph Wuerthner <rwuerthn@de.ibm.com> * Ralph Wuerthner <rwuerthn@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -44,8 +45,8 @@ ...@@ -44,8 +45,8 @@
* Module description. * Module description.
*/ */
MODULE_AUTHOR("IBM Corporation"); MODULE_AUTHOR("IBM Corporation");
MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " MODULE_DESCRIPTION("Cryptographic Coprocessor interface, " \
"Copyright IBM Corp. 2001, 2006"); "Copyright IBM Corp. 2001, 2012");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static DEFINE_SPINLOCK(zcrypt_device_lock); static DEFINE_SPINLOCK(zcrypt_device_lock);
...@@ -56,6 +57,9 @@ static atomic_t zcrypt_open_count = ATOMIC_INIT(0); ...@@ -56,6 +57,9 @@ static atomic_t zcrypt_open_count = ATOMIC_INIT(0);
static int zcrypt_rng_device_add(void); static int zcrypt_rng_device_add(void);
static void zcrypt_rng_device_remove(void); static void zcrypt_rng_device_remove(void);
static DEFINE_SPINLOCK(zcrypt_ops_list_lock);
static LIST_HEAD(zcrypt_ops_list);
/* /*
* Device attributes common for all crypto devices. * Device attributes common for all crypto devices.
*/ */
...@@ -215,6 +219,8 @@ int zcrypt_device_register(struct zcrypt_device *zdev) ...@@ -215,6 +219,8 @@ int zcrypt_device_register(struct zcrypt_device *zdev)
{ {
int rc; int rc;
if (!zdev->ops)
return -ENODEV;
rc = sysfs_create_group(&zdev->ap_dev->device.kobj, rc = sysfs_create_group(&zdev->ap_dev->device.kobj,
&zcrypt_device_attr_group); &zcrypt_device_attr_group);
if (rc) if (rc)
...@@ -269,6 +275,67 @@ void zcrypt_device_unregister(struct zcrypt_device *zdev) ...@@ -269,6 +275,67 @@ void zcrypt_device_unregister(struct zcrypt_device *zdev)
} }
EXPORT_SYMBOL(zcrypt_device_unregister); EXPORT_SYMBOL(zcrypt_device_unregister);
void zcrypt_msgtype_register(struct zcrypt_ops *zops)
{
if (zops->owner) {
spin_lock_bh(&zcrypt_ops_list_lock);
list_add_tail(&zops->list, &zcrypt_ops_list);
spin_unlock_bh(&zcrypt_ops_list_lock);
}
}
EXPORT_SYMBOL(zcrypt_msgtype_register);
void zcrypt_msgtype_unregister(struct zcrypt_ops *zops)
{
spin_lock_bh(&zcrypt_ops_list_lock);
list_del_init(&zops->list);
spin_unlock_bh(&zcrypt_ops_list_lock);
}
EXPORT_SYMBOL(zcrypt_msgtype_unregister);
static inline
struct zcrypt_ops *__ops_lookup(unsigned char *name, int variant)
{
struct zcrypt_ops *zops;
int found = 0;
spin_lock_bh(&zcrypt_ops_list_lock);
list_for_each_entry(zops, &zcrypt_ops_list, list) {
if ((zops->variant == variant) &&
(!strncmp(zops->owner->name, name, MODULE_NAME_LEN))) {
found = 1;
break;
}
}
spin_unlock_bh(&zcrypt_ops_list_lock);
if (!found)
return NULL;
return zops;
}
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *name, int variant)
{
struct zcrypt_ops *zops = NULL;
zops = __ops_lookup(name, variant);
if (!zops) {
request_module(name);
zops = __ops_lookup(name, variant);
}
if ((!zops) || (!try_module_get(zops->owner)))
return NULL;
return zops;
}
EXPORT_SYMBOL(zcrypt_msgtype_request);
void zcrypt_msgtype_release(struct zcrypt_ops *zops)
{
if (zops)
module_put(zops->owner);
}
EXPORT_SYMBOL(zcrypt_msgtype_release);
/** /**
* zcrypt_read (): Not supported beyond zcrypt 1.3.1. * zcrypt_read (): Not supported beyond zcrypt 1.3.1.
* *
......
/* /*
* zcrypt 2.1.0 * zcrypt 2.1.0
* *
* Copyright IBM Corp. 2001, 2006 * Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs * Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com) * Eric Rossman (edrossma@us.ibm.com)
* Cornelia Huck <cornelia.huck@de.ibm.com> * Cornelia Huck <cornelia.huck@de.ibm.com>
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* Ralph Wuerthner <rwuerthn@de.ibm.com> * Ralph Wuerthner <rwuerthn@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -87,6 +88,9 @@ struct zcrypt_ops { ...@@ -87,6 +88,9 @@ struct zcrypt_ops {
struct ica_rsa_modexpo_crt *); struct ica_rsa_modexpo_crt *);
long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *); long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *);
long (*rng)(struct zcrypt_device *, char *); long (*rng)(struct zcrypt_device *, char *);
struct list_head list; /* zcrypt ops list. */
struct module *owner;
int variant;
}; };
struct zcrypt_device { struct zcrypt_device {
...@@ -116,6 +120,10 @@ void zcrypt_device_get(struct zcrypt_device *); ...@@ -116,6 +120,10 @@ void zcrypt_device_get(struct zcrypt_device *);
int zcrypt_device_put(struct zcrypt_device *); int zcrypt_device_put(struct zcrypt_device *);
int zcrypt_device_register(struct zcrypt_device *); int zcrypt_device_register(struct zcrypt_device *);
void zcrypt_device_unregister(struct zcrypt_device *); void zcrypt_device_unregister(struct zcrypt_device *);
void zcrypt_msgtype_register(struct zcrypt_ops *);
void zcrypt_msgtype_unregister(struct zcrypt_ops *);
struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *, int);
void zcrypt_msgtype_release(struct zcrypt_ops *);
int zcrypt_api_init(void); int zcrypt_api_init(void);
void zcrypt_api_exit(void); void zcrypt_api_exit(void);
......
This diff is collapsed.
This diff is collapsed.
/*
* zcrypt 2.1.0
*
* Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com)
*
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ZCRYPT_MSGTYPE50_H_
#define _ZCRYPT_MSGTYPE50_H_
#define MSGTYPE50_NAME "zcrypt_msgtype50"
#define MSGTYPE50_VARIANT_DEFAULT 0
#define MSGTYPE50_CRB2_MAX_MSG_SIZE 0x390 /*sizeof(struct type50_crb2_msg)*/
#define MSGTYPE50_CRB3_MAX_MSG_SIZE 0x710 /*sizeof(struct type50_crb3_msg)*/
int zcrypt_msgtype50_init(void);
void zcrypt_msgtype50_exit(void);
#endif /* _ZCRYPT_MSGTYPE50_H_ */
This diff is collapsed.
/*
* zcrypt 2.1.0
*
* Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com)
*
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ZCRYPT_MSGTYPE6_H_
#define _ZCRYPT_MSGTYPE6_H_
#include <asm/zcrypt.h>
#define MSGTYPE06_NAME "zcrypt_msgtype6"
#define MSGTYPE06_VARIANT_DEFAULT 0
#define MSGTYPE06_VARIANT_NORNG 1
#define MSGTYPE06_MAX_MSG_SIZE (12*1024)
/**
* The type 6 message family is associated with PCICC or PCIXCC cards.
*
* It contains a message header followed by a CPRB, both of which
* are described below.
*
* Note that all reserved fields must be zeroes.
*/
struct type6_hdr {
unsigned char reserved1; /* 0x00 */
unsigned char type; /* 0x06 */
unsigned char reserved2[2]; /* 0x0000 */
unsigned char right[4]; /* 0x00000000 */
unsigned char reserved3[2]; /* 0x0000 */
unsigned char reserved4[2]; /* 0x0000 */
unsigned char apfs[4]; /* 0x00000000 */
unsigned int offset1; /* 0x00000058 (offset to CPRB) */
unsigned int offset2; /* 0x00000000 */
unsigned int offset3; /* 0x00000000 */
unsigned int offset4; /* 0x00000000 */
unsigned char agent_id[16]; /* PCICC: */
/* 0x0100 */
/* 0x4343412d4150504c202020 */
/* 0x010101 */
/* PCIXCC: */
/* 0x4341000000000000 */
/* 0x0000000000000000 */
unsigned char rqid[2]; /* rqid. internal to 603 */
unsigned char reserved5[2]; /* 0x0000 */
unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */
unsigned char reserved6[2]; /* 0x0000 */
unsigned int ToCardLen1; /* (request CPRB len + 3) & -4 */
unsigned int ToCardLen2; /* db len 0x00000000 for PKD */
unsigned int ToCardLen3; /* 0x00000000 */
unsigned int ToCardLen4; /* 0x00000000 */
unsigned int FromCardLen1; /* response buffer length */
unsigned int FromCardLen2; /* db len 0x00000000 for PKD */
unsigned int FromCardLen3; /* 0x00000000 */
unsigned int FromCardLen4; /* 0x00000000 */
} __packed;
/**
* The type 86 message family is associated with PCICC and PCIXCC cards.
*
* It contains a message header followed by a CPRB. The CPRB is
* the same as the request CPRB, which is described above.
*
* If format is 1, an error condition exists and no data beyond
* the 8-byte message header is of interest.
*
* The non-error message is shown below.
*
* Note that all reserved fields must be zeroes.
*/
struct type86_hdr {
unsigned char reserved1; /* 0x00 */
unsigned char type; /* 0x86 */
unsigned char format; /* 0x01 (error) or 0x02 (ok) */
unsigned char reserved2; /* 0x00 */
unsigned char reply_code; /* reply code (see above) */
unsigned char reserved3[3]; /* 0x000000 */
} __packed;
#define TYPE86_RSP_CODE 0x86
#define TYPE86_FMT2 0x02
struct type86_fmt2_ext {
unsigned char reserved[4]; /* 0x00000000 */
unsigned char apfs[4]; /* final status */
unsigned int count1; /* length of CPRB + parameters */
unsigned int offset1; /* offset to CPRB */
unsigned int count2; /* 0x00000000 */
unsigned int offset2; /* db offset 0x00000000 for PKD */
unsigned int count3; /* 0x00000000 */
unsigned int offset3; /* 0x00000000 */
unsigned int count4; /* 0x00000000 */
unsigned int offset4; /* 0x00000000 */
} __packed;
/**
* Prepare a type6 CPRB message for random number generation
*
* @ap_dev: AP device pointer
* @ap_msg: pointer to AP message
*/
static inline void rng_type6CPRB_msgX(struct ap_device *ap_dev,
struct ap_message *ap_msg,
unsigned random_number_length)
{
struct {
struct type6_hdr hdr;
struct CPRBX cprbx;
char function_code[2];
short int rule_length;
char rule[8];
short int verb_length;
short int key_length;
} __packed * msg = ap_msg->message;
static struct type6_hdr static_type6_hdrX = {
.type = 0x06,
.offset1 = 0x00000058,
.agent_id = {'C', 'A'},
.function_code = {'R', 'L'},
.ToCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
.FromCardLen1 = sizeof(*msg) - sizeof(msg->hdr),
};
static struct CPRBX local_cprbx = {
.cprb_len = 0x00dc,
.cprb_ver_id = 0x02,
.func_id = {0x54, 0x32},
.req_parml = sizeof(*msg) - sizeof(msg->hdr) -
sizeof(msg->cprbx),
.rpl_msgbl = sizeof(*msg) - sizeof(msg->hdr),
};
msg->hdr = static_type6_hdrX;
msg->hdr.FromCardLen2 = random_number_length,
msg->cprbx = local_cprbx;
msg->cprbx.rpl_datal = random_number_length,
msg->cprbx.domain = AP_QID_QUEUE(ap_dev->qid);
memcpy(msg->function_code, msg->hdr.function_code, 0x02);
msg->rule_length = 0x0a;
memcpy(msg->rule, "RANDOM ", 8);
msg->verb_length = 0x02;
msg->key_length = 0x02;
ap_msg->length = sizeof(*msg);
}
int zcrypt_msgtype6_init(void);
void zcrypt_msgtype6_exit(void);
#endif /* _ZCRYPT_MSGTYPE6_H_ */
This diff is collapsed.
/* /*
* zcrypt 2.1.0 * zcrypt 2.1.0
* *
* Copyright IBM Corp. 2001, 2006 * Copyright IBM Corp. 2001, 2012
* Author(s): Robert Burroughs * Author(s): Robert Burroughs
* Eric Rossman (edrossma@us.ibm.com) * Eric Rossman (edrossma@us.ibm.com)
* *
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com) * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com> * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment