/* * acrypto.h * * Copyright (c) 2004 Evgeniy Polyakov * * * 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 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __ACRYPTO_H #define __ACRYPTO_H #define SCACHE_NAMELEN 32 struct crypto_session_initializer; struct crypto_data; typedef void (*crypto_callback_t)(struct crypto_session_initializer *, struct crypto_data *); #if 0 #define SESSION_COMPLETED 0 #define SESSION_FINISHED 1 #define SESSION_STARTED 2 #define SESSION_PROCESSED 3 #define session_completed(s) (test_bit(SESSION_COMPLETED, (unsigned long *)&s->ci.flags)) #define complete_session(s) do { set_bit(SESSION_COMPLETED, (unsigned long *)&s->ci.flags); }while (0) #define uncomplete_session(s) do { clear_bit(SESSION_COMPLETED, (unsigned long *)&s->ci.flags); } while (0) #define session_started(s) (test_bit(SESSION_STARTED, (unsigned long *)&s->ci.flags)) #define start_session(s) do { set_bit(SESSION_STARTED, (unsigned long *)&s->ci.flags); } while (0) #define unstart_session(s) do { clear_bit(SESSION_STARTED, (unsigned long *)&s->ci.flags); } while (0) #define session_finished(s) (test_bit(SESSION_FINISHED, (unsigned long *)&s->ci.flags)) #define finish_session(s) do { set_bit(SESSION_FINISHED, (unsigned long *)&s->ci.flags); } while (0) #define unfinish_session(s) do { clear_bit(SESSION_FINISHED, (unsigned long *)&s->ci.flags); } while (0) #define session_is_processed(s) (test_bit(SESSION_PROCESSED, (unsigned long *)&s->ci.flags)) #define start_process_session(s) do { set_bit(SESSION_PROCESSED, (unsigned long *)&s->ci.flags); } while (0) #define stop_process_session(s) do { clear_bit(SESSION_PROCESSED, (unsigned long *)&s->ci.flags); } while (0) #else #define SESSION_COMPLETED (1<<15) #define SESSION_FINISHED (1<<14) #define SESSION_STARTED (1<<13) #define SESSION_PROCESSED (1<<12) #define SESSION_BINDED (1<<11) #define SESSION_BROKEN (1<<10) #define session_completed(s) (s->ci.flags & SESSION_COMPLETED) #define complete_session(s) do {s->ci.flags |= SESSION_COMPLETED;} while(0) #define uncomplete_session(s) do {s->ci.flags &= ~SESSION_COMPLETED;} while (0) #define session_finished(s) (s->ci.flags & SESSION_FINISHED) #define finish_session(s) do {s->ci.flags |= SESSION_FINISHED;} while(0) #define unfinish_session(s) do {s->ci.flags &= ~SESSION_FINISHED;} while (0) #define session_started(s) (s->ci.flags & SESSION_STARTED) #define start_session(s) do {s->ci.flags |= SESSION_STARTED;} while(0) #define unstart_session(s) do {s->ci.flags &= ~SESSION_STARTED;} while (0) #define session_is_processed(s) (s->ci.flags & SESSION_PROCESSED) #define start_process_session(s) do {s->ci.flags |= SESSION_PROCESSED;} while(0) #define stop_process_session(s) do {s->ci.flags &= ~SESSION_PROCESSED;} while (0) #define session_binded(s) (s->ci.flags & SESSION_BINDED) #define bind_session(s) do {s->ci.flags |= SESSION_BINDED;} while(0) #define unbind_session(s) do {s->ci.flags &= ~SESSION_BINDED;} while (0) #define sci_binded(ci) (ci->flags & SESSION_BINDED) #define session_broken(s) (s->ci.flags & SESSION_BROKEN) #define broke_session(s) do {s->ci.flags |= SESSION_BROKEN;} while(0) #define unbroke_session(s) do {s->ci.flags &= ~SESSION_BROKEN;} while (0) #endif struct crypto_device_stat { __u64 scompleted; __u64 sfinished; __u64 sstarted; __u64 kmem_failed; }; #ifdef __KERNEL__ #include #include #include #include #include #include #include #define DEBUG #ifdef DEBUG #define dprintk(f, a...) printk(KERN_EMERG f, ##a) #else #define dprintk(f, a...) #endif #define CRYPTO_MAX_PRIV_SIZE 1024 #define DEVICE_BROKEN (1<<0) #define device_broken(dev) (dev->flags & DEVICE_BROKEN) #define broke_device(dev) do {dev->flags |= DEVICE_BROKEN;} while(0) #define repair_device(dev) do {dev->flags &= ~DEVICE_BROKEN;} while(0) struct crypto_capability { u16 operation; u16 type; u16 mode; u16 qlen; }; struct crypto_session_initializer { u16 operation; u16 type; u16 mode; u16 priority; u64 id; u64 dev_id; u32 flags; u32 bdev; crypto_callback_t callback; }; struct crypto_data { int sg_src_num; struct scatterlist sg_src; struct scatterlist sg_dst; struct scatterlist sg_key; struct scatterlist sg_iv; void *priv; unsigned int priv_size; }; struct crypto_device { char name[SCACHE_NAMELEN]; spinlock_t session_lock; struct list_head session_list; u64 sid; spinlock_t lock; atomic_t refcnt; u32 flags; u32 id; struct list_head cdev_entry; void (*data_ready)(struct crypto_device *); struct device_driver *driver; struct device device; struct class_device class_device; struct completion dev_released; spinlock_t stat_lock; struct crypto_device_stat stat; struct crypto_capability *cap; int cap_number; }; struct crypto_route_head { struct crypto_route *next; struct crypto_route *prev; __u32 qlen; spinlock_t lock; }; struct crypto_route { struct crypto_route *next; struct crypto_route *prev; struct crypto_route_head *list; struct crypto_device *dev; struct crypto_session_initializer ci; }; struct crypto_session { struct list_head dev_queue_entry; struct list_head main_queue_entry; struct crypto_session_initializer ci; struct crypto_data data; spinlock_t lock; struct work_struct work; struct crypto_route_head route_list; }; struct crypto_session *crypto_session_alloc(struct crypto_session_initializer *, struct crypto_data *); inline void crypto_session_dequeue_main(struct crypto_session *); inline void __crypto_session_dequeue_main(struct crypto_session *); void crypto_session_dequeue_route(struct crypto_session *); inline void crypto_device_get(struct crypto_device *); inline void crypto_device_put(struct crypto_device *); inline struct crypto_device *crypto_device_get_name(char *); int __crypto_device_add(struct crypto_device *); int crypto_device_add(struct crypto_device *); void __crypto_device_remove(struct crypto_device *); void crypto_device_remove(struct crypto_device *); int match_initializer(struct crypto_device *, struct crypto_session_initializer *); inline void crypto_session_insert_main(struct crypto_device *dev, struct crypto_session *s); inline void crypto_session_insert(struct crypto_device *dev, struct crypto_session *s); #endif /* __KERNEL__ */ #endif /* __ACRYPTO_H */