Merge branch 'for-linus' of git://git390.osdl.marist.edu/pub/scm/linux-2.6
[pandora-kernel.git] / drivers / s390 / crypto / zcrypt_api.c
index b3fe003..e3625a4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  linux/drivers/s390/crypto/zcrypt_api.c
  *
- *  zcrypt 2.0.0
+ *  zcrypt 2.1.0
  *
  *  Copyright (C)  2001, 2006 IBM Corporation
  *  Author(s): Robert Burroughs
@@ -298,14 +298,14 @@ static long zcrypt_rsa_modexpo(struct ica_rsa_modexpo *mex)
                get_device(&zdev->ap_dev->device);
                zdev->request_count++;
                __zcrypt_decrease_preference(zdev);
-               spin_unlock_bh(&zcrypt_device_lock);
                if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
+                       spin_unlock_bh(&zcrypt_device_lock);
                        rc = zdev->ops->rsa_modexpo(zdev, mex);
+                       spin_lock_bh(&zcrypt_device_lock);
                        module_put(zdev->ap_dev->drv->driver.owner);
                }
                else
                        rc = -EAGAIN;
-               spin_lock_bh(&zcrypt_device_lock);
                zdev->request_count--;
                __zcrypt_increase_preference(zdev);
                put_device(&zdev->ap_dev->device);
@@ -373,14 +373,49 @@ static long zcrypt_rsa_crt(struct ica_rsa_modexpo_crt *crt)
                get_device(&zdev->ap_dev->device);
                zdev->request_count++;
                __zcrypt_decrease_preference(zdev);
-               spin_unlock_bh(&zcrypt_device_lock);
                if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
+                       spin_unlock_bh(&zcrypt_device_lock);
                        rc = zdev->ops->rsa_modexpo_crt(zdev, crt);
+                       spin_lock_bh(&zcrypt_device_lock);
+                       module_put(zdev->ap_dev->drv->driver.owner);
+               }
+               else
+                       rc = -EAGAIN;
+               zdev->request_count--;
+               __zcrypt_increase_preference(zdev);
+               put_device(&zdev->ap_dev->device);
+               zcrypt_device_put(zdev);
+               spin_unlock_bh(&zcrypt_device_lock);
+               return rc;
+       }
+       spin_unlock_bh(&zcrypt_device_lock);
+       return -ENODEV;
+}
+
+static long zcrypt_send_cprb(struct ica_xcRB *xcRB)
+{
+       struct zcrypt_device *zdev;
+       int rc;
+
+       spin_lock_bh(&zcrypt_device_lock);
+       list_for_each_entry(zdev, &zcrypt_device_list, list) {
+               if (!zdev->online || !zdev->ops->send_cprb ||
+                   (xcRB->user_defined != AUTOSELECT &&
+                       AP_QID_DEVICE(zdev->ap_dev->qid) != xcRB->user_defined)
+                   )
+                       continue;
+               zcrypt_device_get(zdev);
+               get_device(&zdev->ap_dev->device);
+               zdev->request_count++;
+               __zcrypt_decrease_preference(zdev);
+               if (try_module_get(zdev->ap_dev->drv->driver.owner)) {
+                       spin_unlock_bh(&zcrypt_device_lock);
+                       rc = zdev->ops->send_cprb(zdev, xcRB);
+                       spin_lock_bh(&zcrypt_device_lock);
                        module_put(zdev->ap_dev->drv->driver.owner);
                }
                else
                        rc = -EAGAIN;
-               spin_lock_bh(&zcrypt_device_lock);
                zdev->request_count--;
                __zcrypt_increase_preference(zdev);
                put_device(&zdev->ap_dev->device);
@@ -535,6 +570,18 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd,
                        return rc;
                return put_user(crt.outputdatalength, &ucrt->outputdatalength);
        }
+       case ZSECSENDCPRB: {
+               struct ica_xcRB __user *uxcRB = (void __user *) arg;
+               struct ica_xcRB xcRB;
+               if (copy_from_user(&xcRB, uxcRB, sizeof(xcRB)))
+                       return -EFAULT;
+               do {
+                       rc = zcrypt_send_cprb(&xcRB);
+               } while (rc == -EAGAIN);
+               if (copy_to_user(uxcRB, &xcRB, sizeof(xcRB)))
+                       return -EFAULT;
+               return rc;
+       }
        case Z90STAT_STATUS_MASK: {
                char status[AP_DEVICES];
                zcrypt_status_mask(status);
@@ -683,13 +730,76 @@ static long trans_modexpo_crt32(struct file *filp, unsigned int cmd,
        return rc;
 }
 
-long zcrypt_compat_ioctl(struct file *filp, unsigned int cmd,
+struct compat_ica_xcRB {
+       unsigned short  agent_ID;
+       unsigned int    user_defined;
+       unsigned short  request_ID;
+       unsigned int    request_control_blk_length;
+       unsigned char   padding1[16 - sizeof (compat_uptr_t)];
+       compat_uptr_t   request_control_blk_addr;
+       unsigned int    request_data_length;
+       char            padding2[16 - sizeof (compat_uptr_t)];
+       compat_uptr_t   request_data_address;
+       unsigned int    reply_control_blk_length;
+       char            padding3[16 - sizeof (compat_uptr_t)];
+       compat_uptr_t   reply_control_blk_addr;
+       unsigned int    reply_data_length;
+       char            padding4[16 - sizeof (compat_uptr_t)];
+       compat_uptr_t   reply_data_addr;
+       unsigned short  priority_window;
+       unsigned int    status;
+} __attribute__((packed));
+
+static long trans_xcRB32(struct file *filp, unsigned int cmd,
+                        unsigned long arg)
+{
+       struct compat_ica_xcRB __user *uxcRB32 = compat_ptr(arg);
+       struct compat_ica_xcRB xcRB32;
+       struct ica_xcRB xcRB64;
+       long rc;
+
+       if (copy_from_user(&xcRB32, uxcRB32, sizeof(xcRB32)))
+               return -EFAULT;
+       xcRB64.agent_ID = xcRB32.agent_ID;
+       xcRB64.user_defined = xcRB32.user_defined;
+       xcRB64.request_ID = xcRB32.request_ID;
+       xcRB64.request_control_blk_length =
+               xcRB32.request_control_blk_length;
+       xcRB64.request_control_blk_addr =
+               compat_ptr(xcRB32.request_control_blk_addr);
+       xcRB64.request_data_length =
+               xcRB32.request_data_length;
+       xcRB64.request_data_address =
+               compat_ptr(xcRB32.request_data_address);
+       xcRB64.reply_control_blk_length =
+               xcRB32.reply_control_blk_length;
+       xcRB64.reply_control_blk_addr =
+               compat_ptr(xcRB32.reply_control_blk_addr);
+       xcRB64.reply_data_length = xcRB32.reply_data_length;
+       xcRB64.reply_data_addr =
+               compat_ptr(xcRB32.reply_data_addr);
+       xcRB64.priority_window = xcRB32.priority_window;
+       xcRB64.status = xcRB32.status;
+       do {
+               rc = zcrypt_send_cprb(&xcRB64);
+       } while (rc == -EAGAIN);
+       xcRB32.reply_control_blk_length = xcRB64.reply_control_blk_length;
+       xcRB32.reply_data_length = xcRB64.reply_data_length;
+       xcRB32.status = xcRB64.status;
+       if (copy_to_user(uxcRB32, &xcRB32, sizeof(xcRB32)))
+                       return -EFAULT;
+       return rc;
+}
+
+static long zcrypt_compat_ioctl(struct file *filp, unsigned int cmd,
                         unsigned long arg)
 {
        if (cmd == ICARSAMODEXPO)
                return trans_modexpo32(filp, cmd, arg);
        if (cmd == ICARSACRT)
                return trans_modexpo_crt32(filp, cmd, arg);
+       if (cmd == ZSECSENDCPRB)
+               return trans_xcRB32(filp, cmd, arg);
        return zcrypt_unlocked_ioctl(filp, cmd, arg);
 }
 #endif
@@ -697,7 +807,7 @@ long zcrypt_compat_ioctl(struct file *filp, unsigned int cmd,
 /**
  * Misc device file operations.
  */
-static struct file_operations zcrypt_fops = {
+static const struct file_operations zcrypt_fops = {
        .owner          = THIS_MODULE,
        .read           = zcrypt_read,
        .write          = zcrypt_write,
@@ -723,8 +833,8 @@ static struct miscdevice zcrypt_misc_device = {
  */
 static struct proc_dir_entry *zcrypt_entry;
 
-static inline int sprintcl(unsigned char *outaddr, unsigned char *addr,
-                          unsigned int len)
+static int sprintcl(unsigned char *outaddr, unsigned char *addr,
+                   unsigned int len)
 {
        int hl, i;
 
@@ -735,8 +845,8 @@ static inline int sprintcl(unsigned char *outaddr, unsigned char *addr,
        return hl;
 }
 
-static inline int sprintrw(unsigned char *outaddr, unsigned char *addr,
-                          unsigned int len)
+static int sprintrw(unsigned char *outaddr, unsigned char *addr,
+                   unsigned int len)
 {
        int hl, inl, c, cx;
 
@@ -755,8 +865,8 @@ static inline int sprintrw(unsigned char *outaddr, unsigned char *addr,
        return hl;
 }
 
-static inline int sprinthx(unsigned char *title, unsigned char *outaddr,
-                          unsigned char *addr, unsigned int len)
+static int sprinthx(unsigned char *title, unsigned char *outaddr,
+                   unsigned char *addr, unsigned int len)
 {
        int hl, inl, r, rx;
 
@@ -775,8 +885,8 @@ static inline int sprinthx(unsigned char *title, unsigned char *outaddr,
        return hl;
 }
 
-static inline int sprinthx4(unsigned char *title, unsigned char *outaddr,
-                           unsigned int *array, unsigned int len)
+static int sprinthx4(unsigned char *title, unsigned char *outaddr,
+                    unsigned int *array, unsigned int len)
 {
        int hl, r;
 
@@ -833,7 +943,7 @@ static int zcrypt_status_read(char *resp_buff, char **start, off_t offset,
        zcrypt_qdepth_mask(workarea);
        len += sprinthx("Waiting work element counts",
                        resp_buff+len, workarea, AP_DEVICES);
-       zcrypt_perdev_reqcnt((unsigned int *) workarea);
+       zcrypt_perdev_reqcnt((int *) workarea);
        len += sprinthx4("Per-device successfully completed request counts",
                         resp_buff+len,(unsigned int *) workarea, AP_DEVICES);
        *eof = 1;
@@ -953,7 +1063,6 @@ int __init zcrypt_api_init(void)
                rc = -ENOMEM;
                goto out_misc;
        }
-       zcrypt_entry->nlink = 1;
        zcrypt_entry->data = NULL;
        zcrypt_entry->read_proc = zcrypt_status_read;
        zcrypt_entry->write_proc = zcrypt_status_write;