aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/crypto/api-intro.txt41
-rw-r--r--Documentation/kobject.txt489
-rw-r--r--Documentation/pnp.txt4
-rw-r--r--Documentation/s390/cds.txt2
-rw-r--r--Documentation/vm/slabinfo.c2
-rw-r--r--Documentation/vm/slub.txt2
-rw-r--r--Documentation/zh_CN/CodingStyle701
-rw-r--r--Documentation/zh_CN/HOWTO10
-rw-r--r--Documentation/zh_CN/SubmittingDrivers168
-rw-r--r--Documentation/zh_CN/SubmittingPatches416
-rw-r--r--Documentation/zh_CN/oops-tracing.txt212
-rw-r--r--Documentation/zh_CN/sparse.txt100
-rw-r--r--Documentation/zh_CN/stable_kernel_rules.txt66
-rw-r--r--Documentation/zh_CN/volatile-considered-harmful.txt113
-rw-r--r--arch/arm/kernel/time.c4
-rw-r--r--arch/arm/mach-integrator/integrator_ap.c2
-rw-r--r--arch/arm/mach-omap1/pm.c23
-rw-r--r--arch/arm/mach-pxa/cm-x270.c2
-rw-r--r--arch/arm/mach-pxa/lpd270.c2
-rw-r--r--arch/arm/mach-pxa/lubbock.c2
-rw-r--r--arch/arm/mach-pxa/mainstone.c2
-rw-r--r--arch/arm/mach-s3c2410/s3c2410.c2
-rw-r--r--arch/arm/mach-s3c2412/s3c2412.c2
-rw-r--r--arch/arm/mach-s3c2440/mach-osiris.c2
-rw-r--r--arch/arm/mach-s3c2443/s3c2443.c2
-rw-r--r--arch/arm/mach-sa1100/irq.c2
-rw-r--r--arch/arm/oprofile/common.c2
-rw-r--r--arch/arm/plat-omap/gpio.c2
-rw-r--r--arch/arm/plat-s3c24xx/dma.c2
-rw-r--r--arch/arm/plat-s3c24xx/s3c244x.c4
-rw-r--r--arch/avr32/kernel/time.c2
-rw-r--r--arch/cris/arch-v32/drivers/iop_fw_load.c11
-rw-r--r--arch/ia64/kernel/topology.c26
-rw-r--r--arch/mips/kernel/i8259.c2
-rw-r--r--arch/powerpc/platforms/cell/spu_base.c2
-rw-r--r--arch/powerpc/platforms/powermac/pic.c2
-rw-r--r--arch/powerpc/platforms/pseries/power.c32
-rw-r--r--arch/powerpc/sysdev/ipic.c2
-rw-r--r--arch/powerpc/sysdev/mpic.c2
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe_ic.c2
-rw-r--r--arch/ppc/syslib/ipic.c2
-rw-r--r--arch/ppc/syslib/open_pic.c2
-rw-r--r--arch/ppc/syslib/open_pic2.c2
-rw-r--r--arch/s390/crypto/aes_s390.c227
-rw-r--r--arch/s390/hypfs/inode.c13
-rw-r--r--arch/s390/kernel/ipl.c147
-rw-r--r--arch/s390/kernel/time.c2
-rw-r--r--arch/sh/drivers/dma/dma-sysfs.c2
-rw-r--r--arch/sh/kernel/cpu/sh4/sq.c13
-rw-r--r--arch/sh/kernel/time.c2
-rw-r--r--arch/x86/crypto/Makefile12
-rw-r--r--arch/x86/crypto/aes-i586-asm_32.S89
-rw-r--r--arch/x86/crypto/aes-x86_64-asm_64.S68
-rw-r--r--arch/x86/crypto/aes_32.c515
-rw-r--r--arch/x86/crypto/aes_64.c336
-rw-r--r--arch/x86/crypto/aes_glue.c57
-rw-r--r--arch/x86/crypto/salsa20-i586-asm_32.S1114
-rw-r--r--arch/x86/crypto/salsa20-x86_64-asm_64.S920
-rw-r--r--arch/x86/crypto/salsa20_glue.c129
-rw-r--r--arch/x86/crypto/twofish_64.c97
-rw-r--r--arch/x86/crypto/twofish_glue.c (renamed from arch/x86/crypto/twofish_32.c)8
-rw-r--r--arch/x86/kernel/apic_32.c2
-rw-r--r--arch/x86/kernel/apic_64.c2
-rw-r--r--arch/x86/kernel/cpu/intel_cacheinfo.c24
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce_64.c2
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce_amd_64.c30
-rw-r--r--arch/x86/kernel/cpuid.c6
-rw-r--r--arch/x86/kernel/i8237.c2
-rw-r--r--arch/x86/kernel/i8259_32.c2
-rw-r--r--arch/x86/kernel/i8259_64.c2
-rw-r--r--arch/x86/kernel/io_apic_32.c2
-rw-r--r--arch/x86/kernel/io_apic_64.c2
-rw-r--r--arch/x86/kernel/msr.c6
-rw-r--r--arch/x86/kernel/nmi_32.c2
-rw-r--r--arch/x86/kernel/nmi_64.c2
-rw-r--r--arch/x86/oprofile/nmi_int.c2
-rw-r--r--block/elevator.c8
-rw-r--r--block/genhd.c419
-rw-r--r--block/ll_rw_blk.c11
-rw-r--r--crypto/Kconfig97
-rw-r--r--crypto/Makefile14
-rw-r--r--crypto/ablkcipher.c241
-rw-r--r--crypto/aead.c400
-rw-r--r--crypto/aes_generic.c468
-rw-r--r--crypto/algapi.c65
-rw-r--r--crypto/api.c19
-rw-r--r--crypto/authenc.c334
-rw-r--r--crypto/blkcipher.c202
-rw-r--r--crypto/camellia.c1781
-rw-r--r--crypto/cast6.c6
-rw-r--r--crypto/cbc.c109
-rw-r--r--crypto/ccm.c889
-rw-r--r--crypto/chainiv.c331
-rw-r--r--crypto/cryptd.c6
-rw-r--r--crypto/crypto_null.c70
-rw-r--r--crypto/ctr.c422
-rw-r--r--crypto/des_generic.c17
-rw-r--r--crypto/digest.c4
-rw-r--r--crypto/eseqiv.c264
-rw-r--r--crypto/gcm.c823
-rw-r--r--crypto/hmac.c3
-rw-r--r--crypto/internal.h31
-rw-r--r--crypto/lzo.c106
-rw-r--r--crypto/pcbc.c105
-rw-r--r--crypto/salsa20_generic.c255
-rw-r--r--crypto/scatterwalk.c10
-rw-r--r--crypto/seqiv.c345
-rw-r--r--crypto/sha256_generic.c72
-rw-r--r--crypto/tcrypt.c449
-rw-r--r--crypto/tcrypt.h3415
-rw-r--r--crypto/twofish_common.c96
-rw-r--r--crypto/xcbc.c10
-rw-r--r--drivers/acpi/bus.c11
-rw-r--r--drivers/acpi/pci_link.c2
-rw-r--r--drivers/acpi/system.c13
-rw-r--r--drivers/base/Makefile3
-rw-r--r--drivers/base/attribute_container.c9
-rw-r--r--drivers/base/base.h64
-rw-r--r--drivers/base/bus.c501
-rw-r--r--drivers/base/class.c319
-rw-r--r--drivers/base/core.c582
-rw-r--r--drivers/base/cpu.c2
-rw-r--r--drivers/base/dd.c164
-rw-r--r--drivers/base/driver.c216
-rw-r--r--drivers/base/firmware.c26
-rw-r--r--drivers/base/hypervisor.c12
-rw-r--r--drivers/base/init.c10
-rw-r--r--drivers/base/memory.c2
-rw-r--r--drivers/base/module.c94
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/base/platform.c239
-rw-r--r--drivers/base/power/Makefile1
-rw-r--r--drivers/base/power/main.c502
-rw-r--r--drivers/base/power/power.h19
-rw-r--r--drivers/base/power/shutdown.c48
-rw-r--r--drivers/base/sys.c49
-rw-r--r--drivers/block/aoe/aoeblk.c51
-rw-r--r--drivers/block/aoe/aoechr.c7
-rw-r--r--drivers/block/nbd.c15
-rw-r--r--drivers/block/paride/pg.c6
-rw-r--r--drivers/block/paride/pt.c12
-rw-r--r--drivers/block/pktcdvd.c27
-rw-r--r--drivers/char/Kconfig10
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/hvc_console.c80
-rw-r--r--drivers/char/hvcs.c78
-rw-r--r--drivers/char/hw_random/amd-rng.c12
-rw-r--r--drivers/char/hw_random/core.c24
-rw-r--r--drivers/char/hw_random/geode-rng.c12
-rw-r--r--drivers/char/hw_random/intel-rng.c15
-rw-r--r--drivers/char/hw_random/omap-rng.c13
-rw-r--r--drivers/char/hw_random/pasemi-rng.c16
-rw-r--r--drivers/char/hw_random/via-rng.c19
-rw-r--r--drivers/char/nozomi.c1993
-rw-r--r--drivers/cpufreq/cpufreq.c12
-rw-r--r--drivers/cpuidle/sysfs.c21
-rw-r--r--drivers/crypto/Kconfig11
-rw-r--r--drivers/crypto/Makefile1
-rw-r--r--drivers/crypto/geode-aes.c298
-rw-r--r--drivers/crypto/geode-aes.h44
-rw-r--r--drivers/crypto/hifn_795x.c2838
-rw-r--r--drivers/crypto/padlock-aes.c24
-rw-r--r--drivers/dma/dmaengine.c43
-rw-r--r--drivers/edac/edac_device_sysfs.c49
-rw-r--r--drivers/edac/edac_mc_sysfs.c40
-rw-r--r--drivers/edac/edac_module.c2
-rw-r--r--drivers/edac/edac_pci_sysfs.c35
-rw-r--r--drivers/firmware/edd.c25
-rw-r--r--drivers/firmware/efivars.c130
-rw-r--r--drivers/i2c/chips/isp1301_omap.c6
-rw-r--r--drivers/ide/ide-probe.c2
-rw-r--r--drivers/ide/ide-tape.c14
-rw-r--r--drivers/ieee1394/nodemgr.c314
-rw-r--r--drivers/infiniband/core/sysfs.c39
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c13
-rw-r--r--drivers/infiniband/hw/ipath/ipath_driver.c17
-rw-r--r--drivers/infiniband/hw/ipath/ipath_kernel.h3
-rw-r--r--drivers/infiniband/hw/ipath/ipath_sysfs.c30
-rw-r--r--drivers/isdn/capi/capi.c6
-rw-r--r--drivers/isdn/capi/capidrv.c9
-rw-r--r--drivers/isdn/gigaset/gigaset.h6
-rw-r--r--drivers/kvm/kvm_main.c2
-rw-r--r--drivers/macintosh/adb.c2
-rw-r--r--drivers/macintosh/via-pmu.c2
-rw-r--r--drivers/md/dm.c4
-rw-r--r--drivers/md/md.c31
-rw-r--r--drivers/mfd/ucb1x00-assabet.c17
-rw-r--r--drivers/mfd/ucb1x00-core.c14
-rw-r--r--drivers/mfd/ucb1x00.h4
-rw-r--r--drivers/misc/ibmasm/command.c12
-rw-r--r--drivers/misc/ibmasm/ibmasm.h10
-rw-r--r--drivers/misc/tifm_7xx1.c4
-rw-r--r--drivers/misc/tifm_core.c24
-rw-r--r--drivers/mtd/mtdchar.c12
-rw-r--r--drivers/net/ibmveth.c12
-rw-r--r--drivers/net/iseries_veth.c19
-rw-r--r--drivers/net/wan/cosa.c5
-rw-r--r--drivers/parisc/pdc_stable.c194
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c4
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c39
-rw-r--r--drivers/pci/hotplug/rpadlpar_sysfs.c113
-rw-r--r--drivers/pci/pci-driver.c59
-rw-r--r--drivers/pci/probe.c11
-rw-r--r--drivers/pcmcia/ds.c3
-rw-r--r--drivers/power/apm_power.c116
-rw-r--r--drivers/power/power_supply_core.c74
-rw-r--r--drivers/rtc/interface.c22
-rw-r--r--drivers/s390/net/netiucv.c16
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c14
-rw-r--r--drivers/s390/scsi/zfcp_ext.h3
-rw-r--r--drivers/s390/scsi/zfcp_sysfs_driver.c27
-rw-r--r--drivers/scsi/hosts.c24
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c2
-rw-r--r--drivers/serial/icom.c24
-rw-r--r--drivers/serial/icom.h2
-rw-r--r--drivers/spi/spi.c26
-rw-r--r--drivers/uio/uio.c95
-rw-r--r--drivers/usb/core/driver.c8
-rw-r--r--fs/block_dev.c8
-rw-r--r--fs/char_dev.c6
-rw-r--r--fs/coda/psdev.c8
-rw-r--r--fs/configfs/mount.c13
-rw-r--r--fs/debugfs/inode.c13
-rw-r--r--fs/dlm/lockspace.c50
-rw-r--r--fs/ecryptfs/main.c129
-rw-r--r--fs/fuse/inode.c26
-rw-r--r--fs/gfs2/Makefile2
-rw-r--r--fs/gfs2/bmap.c37
-rw-r--r--fs/gfs2/bmap.h2
-rw-r--r--fs/gfs2/daemon.c50
-rw-r--r--fs/gfs2/daemon.h1
-rw-r--r--fs/gfs2/dir.c4
-rw-r--r--fs/gfs2/eaops.c84
-rw-r--r--fs/gfs2/eattr.c2
-rw-r--r--fs/gfs2/glock.c83
-rw-r--r--fs/gfs2/glops.c110
-rw-r--r--fs/gfs2/incore.h47
-rw-r--r--fs/gfs2/inode.c41
-rw-r--r--fs/gfs2/inode.h12
-rw-r--r--fs/gfs2/locking/dlm/mount.c5
-rw-r--r--fs/gfs2/locking/dlm/plock.c18
-rw-r--r--fs/gfs2/locking/dlm/sysfs.c38
-rw-r--r--fs/gfs2/locking/dlm/thread.c9
-rw-r--r--fs/gfs2/log.c119
-rw-r--r--fs/gfs2/log.h14
-rw-r--r--fs/gfs2/lops.c71
-rw-r--r--fs/gfs2/main.c3
-rw-r--r--fs/gfs2/meta_io.c97
-rw-r--r--fs/gfs2/meta_io.h1
-rw-r--r--fs/gfs2/ops_address.c649
-rw-r--r--fs/gfs2/ops_address.h7
-rw-r--r--fs/gfs2/ops_file.c229
-rw-r--r--fs/gfs2/ops_file.h24
-rw-r--r--fs/gfs2/ops_fstype.c73
-rw-r--r--fs/gfs2/ops_inode.c20
-rw-r--r--fs/gfs2/ops_inode.h6
-rw-r--r--fs/gfs2/ops_super.c1
-rw-r--r--fs/gfs2/ops_vm.c169
-rw-r--r--fs/gfs2/ops_vm.h18
-rw-r--r--fs/gfs2/quota.c29
-rw-r--r--fs/gfs2/recovery.c18
-rw-r--r--fs/gfs2/rgrp.c104
-rw-r--r--fs/gfs2/rgrp.h4
-rw-r--r--fs/gfs2/super.c25
-rw-r--r--fs/gfs2/sys.c36
-rw-r--r--fs/gfs2/trans.c5
-rw-r--r--fs/gfs2/trans.h1
-rw-r--r--fs/namespace.c11
-rw-r--r--fs/ocfs2/cluster/masklog.c4
-rw-r--r--fs/ocfs2/cluster/sys.c83
-rw-r--r--fs/partitions/check.c327
-rw-r--r--fs/sysfs/dir.c2
-rw-r--r--fs/sysfs/file.c67
-rw-r--r--fs/sysfs/symlink.c88
-rw-r--r--include/acpi/acpi_bus.h2
-rw-r--r--include/crypto/aead.h105
-rw-r--r--include/crypto/aes.h31
-rw-r--r--include/crypto/algapi.h31
-rw-r--r--include/crypto/authenc.h27
-rw-r--r--include/crypto/ctr.h20
-rw-r--r--include/crypto/des.h19
-rw-r--r--include/crypto/internal/aead.h80
-rw-r--r--include/crypto/internal/skcipher.h110
-rw-r--r--include/crypto/scatterwalk.h (renamed from crypto/scatterwalk.h)45
-rw-r--r--include/crypto/sha.h12
-rw-r--r--include/crypto/skcipher.h110
-rw-r--r--include/linux/crypto.h103
-rw-r--r--include/linux/device.h360
-rw-r--r--include/linux/dmaengine.h3
-rw-r--r--include/linux/fs.h2
-rw-r--r--include/linux/genhd.h37
-rw-r--r--include/linux/hw_random.h2
-rw-r--r--include/linux/kobject.h184
-rw-r--r--include/linux/kref.h1
-rw-r--r--include/linux/module.h19
-rw-r--r--include/linux/pci_hotplug.h2
-rw-r--r--include/linux/pktcdvd.h2
-rw-r--r--include/linux/platform_device.h2
-rw-r--r--include/linux/sched.h9
-rw-r--r--include/linux/sysdev.h1
-rw-r--r--include/linux/tifm.h2
-rw-r--r--include/linux/uio_driver.h6
-rw-r--r--include/rdma/ib_verbs.h2
-rw-r--r--init/Kconfig1
-rw-r--r--init/do_mounts.c108
-rw-r--r--kernel/ksysfs.c82
-rw-r--r--kernel/module.c128
-rw-r--r--kernel/params.c44
-rw-r--r--kernel/power/disk.c20
-rw-r--r--kernel/power/main.c23
-rw-r--r--kernel/power/power.h4
-rw-r--r--kernel/rtmutex-tester.c2
-rw-r--r--kernel/time/clocksource.c2
-rw-r--r--kernel/time/timekeeping.c2
-rw-r--r--kernel/user.c107
-rw-r--r--lib/kobject.c734
-rw-r--r--lib/kobject_uevent.c38
-rw-r--r--lib/kref.c15
-rw-r--r--mm/slab.c46
-rw-r--r--mm/slub.c23
-rw-r--r--net/bridge/br_if.c12
-rw-r--r--net/bridge/br_private.h2
-rw-r--r--net/bridge/br_sysfs_br.c14
-rw-r--r--net/bridge/br_sysfs_if.c2
-rw-r--r--samples/Kconfig10
-rw-r--r--samples/Makefile2
-rw-r--r--samples/kobject/Makefile1
-rw-r--r--samples/kobject/kobject-example.c137
-rw-r--r--samples/kobject/kset-example.c278
-rw-r--r--security/inode.c11
330 files changed, 25830 insertions, 9021 deletions
diff --git a/Documentation/crypto/api-intro.txt b/Documentation/crypto/api-intro.txt
index a2ac6d294793..8b49302712a8 100644
--- a/Documentation/crypto/api-intro.txt
+++ b/Documentation/crypto/api-intro.txt
@@ -33,9 +33,16 @@ The idea is to make the user interface and algorithm registration API
33very simple, while hiding the core logic from both. Many good ideas 33very simple, while hiding the core logic from both. Many good ideas
34from existing APIs such as Cryptoapi and Nettle have been adapted for this. 34from existing APIs such as Cryptoapi and Nettle have been adapted for this.
35 35
36The API currently supports three types of transforms: Ciphers, Digests and 36The API currently supports five main types of transforms: AEAD (Authenticated
37Compressors. The compression algorithms especially seem to be performing 37Encryption with Associated Data), Block Ciphers, Ciphers, Compressors and
38very well so far. 38Hashes.
39
40Please note that Block Ciphers is somewhat of a misnomer. It is in fact
41meant to support all ciphers including stream ciphers. The difference
42between Block Ciphers and Ciphers is that the latter operates on exactly
43one block while the former can operate on an arbitrary amount of data,
44subject to block size requirements (i.e., non-stream ciphers can only
45process multiples of blocks).
39 46
40Support for hardware crypto devices via an asynchronous interface is 47Support for hardware crypto devices via an asynchronous interface is
41under development. 48under development.
@@ -69,29 +76,12 @@ Here's an example of how to use the API:
69Many real examples are available in the regression test module (tcrypt.c). 76Many real examples are available in the regression test module (tcrypt.c).
70 77
71 78
72CONFIGURATION NOTES
73
74As Triple DES is part of the DES module, for those using modular builds,
75add the following line to /etc/modprobe.conf:
76
77 alias des3_ede des
78
79The Null algorithms reside in the crypto_null module, so these lines
80should also be added:
81
82 alias cipher_null crypto_null
83 alias digest_null crypto_null
84 alias compress_null crypto_null
85
86The SHA384 algorithm shares code within the SHA512 module, so you'll
87also need:
88 alias sha384 sha512
89
90
91DEVELOPER NOTES 79DEVELOPER NOTES
92 80
93Transforms may only be allocated in user context, and cryptographic 81Transforms may only be allocated in user context, and cryptographic
94methods may only be called from softirq and user contexts. 82methods may only be called from softirq and user contexts. For
83transforms with a setkey method it too should only be called from
84user context.
95 85
96When using the API for ciphers, performance will be optimal if each 86When using the API for ciphers, performance will be optimal if each
97scatterlist contains data which is a multiple of the cipher's block 87scatterlist contains data which is a multiple of the cipher's block
@@ -130,8 +120,9 @@ might already be working on.
130BUGS 120BUGS
131 121
132Send bug reports to: 122Send bug reports to:
133Herbert Xu <herbert@gondor.apana.org.au> 123linux-crypto@vger.kernel.org
134Cc: David S. Miller <davem@redhat.com> 124Cc: Herbert Xu <herbert@gondor.apana.org.au>,
125 David S. Miller <davem@redhat.com>
135 126
136 127
137FURTHER INFORMATION 128FURTHER INFORMATION
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index ca86a885ad8f..bf3256e04027 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -1,289 +1,386 @@
1The kobject Infrastructure 1Everything you never wanted to know about kobjects, ksets, and ktypes
2 2
3Patrick Mochel <mochel@osdl.org> 3Greg Kroah-Hartman <gregkh@suse.de>
4 4
5Updated: 3 June 2003 5Based on an original article by Jon Corbet for lwn.net written October 1,
62003 and located at http://lwn.net/Articles/51437/
6 7
8Last updated December 19, 2007
7 9
8Copyright (c) 2003 Patrick Mochel
9Copyright (c) 2003 Open Source Development Labs
10 10
11Part of the difficulty in understanding the driver model - and the kobject
12abstraction upon which it is built - is that there is no obvious starting
13place. Dealing with kobjects requires understanding a few different types,
14all of which make reference to each other. In an attempt to make things
15easier, we'll take a multi-pass approach, starting with vague terms and
16adding detail as we go. To that end, here are some quick definitions of
17some terms we will be working with.
11 18
120. Introduction 19 - A kobject is an object of type struct kobject. Kobjects have a name
20 and a reference count. A kobject also has a parent pointer (allowing
21 objects to be arranged into hierarchies), a specific type, and,
22 usually, a representation in the sysfs virtual filesystem.
13 23
14The kobject infrastructure performs basic object management that larger 24 Kobjects are generally not interesting on their own; instead, they are
15data structures and subsystems can leverage, rather than reimplement 25 usually embedded within some other structure which contains the stuff
16similar functionality. This functionality primarily concerns: 26 the code is really interested in.
17 27
18- Object reference counting. 28 No structure should EVER have more than one kobject embedded within it.
19- Maintaining lists (sets) of objects. 29 If it does, the reference counting for the object is sure to be messed
20- Object set locking. 30 up and incorrect, and your code will be buggy. So do not do this.
21- Userspace representation.
22 31
23The infrastructure consists of a number of object types to support 32 - A ktype is the type of object that embeds a kobject. Every structure
24this functionality. Their programming interfaces are described below 33 that embeds a kobject needs a corresponding ktype. The ktype controls
25in detail, and briefly here: 34 what happens to the kobject when it is created and destroyed.
26 35
27- kobjects a simple object. 36 - A kset is a group of kobjects. These kobjects can be of the same ktype
28- kset a set of objects of a certain type. 37 or belong to different ktypes. The kset is the basic container type for
29- ktype a set of helpers for objects of a common type. 38 collections of kobjects. Ksets contain their own kobjects, but you can
39 safely ignore that implementation detail as the kset core code handles
40 this kobject automatically.
30 41
42 When you see a sysfs directory full of other directories, generally each
43 of those directories corresponds to a kobject in the same kset.
31 44
32The kobject infrastructure maintains a close relationship with the 45We'll look at how to create and manipulate all of these types. A bottom-up
33sysfs filesystem. Each kobject that is registered with the kobject 46approach will be taken, so we'll go back to kobjects.
34core receives a directory in sysfs. Attributes about the kobject can
35then be exported. Please see Documentation/filesystems/sysfs.txt for
36more information.
37 47
38The kobject infrastructure provides a flexible programming interface,
39and allows kobjects and ksets to be used without being registered
40(i.e. with no sysfs representation). This is also described later.
41 48
49Embedding kobjects
42 50
431. kobjects 51It is rare for kernel code to create a standalone kobject, with one major
52exception explained below. Instead, kobjects are used to control access to
53a larger, domain-specific object. To this end, kobjects will be found
54embedded in other structures. If you are used to thinking of things in
55object-oriented terms, kobjects can be seen as a top-level, abstract class
56from which other classes are derived. A kobject implements a set of
57capabilities which are not particularly useful by themselves, but which are
58nice to have in other objects. The C language does not allow for the
59direct expression of inheritance, so other techniques - such as structure
60embedding - must be used.
44 61
451.1 Description 62So, for example, the UIO code has a structure that defines the memory
63region associated with a uio device:
46 64
65struct uio_mem {
66 struct kobject kobj;
67 unsigned long addr;
68 unsigned long size;
69 int memtype;
70 void __iomem *internal_addr;
71};
47 72
48struct kobject is a simple data type that provides a foundation for 73If you have a struct uio_mem structure, finding its embedded kobject is
49more complex object types. It provides a set of basic fields that 74just a matter of using the kobj member. Code that works with kobjects will
50almost all complex data types share. kobjects are intended to be 75often have the opposite problem, however: given a struct kobject pointer,
51embedded in larger data structures and replace fields they duplicate. 76what is the pointer to the containing structure? You must avoid tricks
77(such as assuming that the kobject is at the beginning of the structure)
78and, instead, use the container_of() macro, found in <linux/kernel.h>:
52 79
531.2 Definition 80 container_of(pointer, type, member)
54 81
55struct kobject { 82where pointer is the pointer to the embedded kobject, type is the type of
56 const char * k_name; 83the containing structure, and member is the name of the structure field to
57 struct kref kref; 84which pointer points. The return value from container_of() is a pointer to
58 struct list_head entry; 85the given type. So, for example, a pointer "kp" to a struct kobject
59 struct kobject * parent; 86embedded within a struct uio_mem could be converted to a pointer to the
60 struct kset * kset; 87containing uio_mem structure with:
61 struct kobj_type * ktype;
62 struct sysfs_dirent * sd;
63 wait_queue_head_t poll;
64};
65 88
66void kobject_init(struct kobject *); 89 struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj);
67int kobject_add(struct kobject *);
68int kobject_register(struct kobject *);
69 90
70void kobject_del(struct kobject *); 91Programmers often define a simple macro for "back-casting" kobject pointers
71void kobject_unregister(struct kobject *); 92to the containing type.
72 93
73struct kobject * kobject_get(struct kobject *);
74void kobject_put(struct kobject *);
75 94
95Initialization of kobjects
76 96
771.3 kobject Programming Interface 97Code which creates a kobject must, of course, initialize that object. Some
98of the internal fields are setup with a (mandatory) call to kobject_init():
78 99
79kobjects may be dynamically added and removed from the kobject core 100 void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
80using kobject_register() and kobject_unregister(). Registration
81includes inserting the kobject in the list of its dominant kset and
82creating a directory for it in sysfs.
83 101
84Alternatively, one may use a kobject without adding it to its kset's list 102The ktype is required for a kobject to be created properly, as every kobject
85or exporting it via sysfs, by simply calling kobject_init(). An 103must have an associated kobj_type. After calling kobject_init(), to
86initialized kobject may later be added to the object hierarchy by 104register the kobject with sysfs, the function kobject_add() must be called:
87calling kobject_add(). An initialized kobject may be used for
88reference counting.
89 105
90Note: calling kobject_init() then kobject_add() is functionally 106 int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...);
91equivalent to calling kobject_register().
92 107
93When a kobject is unregistered, it is removed from its kset's list, 108This sets up the parent of the kobject and the name for the kobject
94removed from the sysfs filesystem, and its reference count is decremented. 109properly. If the kobject is to be associated with a specific kset,
95List and sysfs removal happen in kobject_del(), and may be called 110kobj->kset must be assigned before calling kobject_add(). If a kset is
96manually. kobject_put() decrements the reference count, and may also 111associated with a kobject, then the parent for the kobject can be set to
97be called manually. 112NULL in the call to kobject_add() and then the kobject's parent will be the
113kset itself.
98 114
99A kobject's reference count may be incremented with kobject_get(), 115As the name of the kobject is set when it is added to the kernel, the name
100which returns a valid reference to a kobject; and decremented with 116of the kobject should never be manipulated directly. If you must change
101kobject_put(). An object's reference count may only be incremented if 117the name of the kobject, call kobject_rename():
102it is already positive.
103 118
104When a kobject's reference count reaches 0, the method struct 119 int kobject_rename(struct kobject *kobj, const char *new_name);
105kobj_type::release() (which the kobject's kset points to) is called.
106This allows any memory allocated for the object to be freed.
107 120
121There is a function called kobject_set_name() but that is legacy cruft and
122is being removed. If your code needs to call this function, it is
123incorrect and needs to be fixed.
108 124
109NOTE!!! 125To properly access the name of the kobject, use the function
126kobject_name():
110 127
111It is _imperative_ that you supply a destructor for dynamically 128 const char *kobject_name(const struct kobject * kobj);
112allocated kobjects to free them if you are using kobject reference
113counts. The reference count controls the lifetime of the object.
114If it goes to 0, then it is assumed that the object will
115be freed and cannot be used.
116 129
117More importantly, you must free the object there, and not immediately 130There is a helper function to both initialize and add the kobject to the
118after an unregister call. If someone else is referencing the object 131kernel at the same time, called supprisingly enough kobject_init_and_add():
119(e.g. through a sysfs file), they will obtain a reference to the
120object, assume it's valid and operate on it. If the object is
121unregistered and freed in the meantime, the operation will then
122reference freed memory and go boom.
123 132
124This can be prevented, in the simplest case, by defining a release 133 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
125method and freeing the object from there only. Note that this will not 134 struct kobject *parent, const char *fmt, ...);
126secure reference count/object management models that use a dual
127reference count or do other wacky things with the reference count
128(like the networking layer).
129 135
136The arguments are the same as the individual kobject_init() and
137kobject_add() functions described above.
130 138
1311.4 sysfs
132 139
133Each kobject receives a directory in sysfs. This directory is created 140Uevents
134under the kobject's parent directory.
135 141
136If a kobject does not have a parent when it is registered, its parent 142After a kobject has been registered with the kobject core, you need to
137becomes its dominant kset. 143announce to the world that it has been created. This can be done with a
144call to kobject_uevent():
138 145
139If a kobject does not have a parent nor a dominant kset, its directory 146 int kobject_uevent(struct kobject *kobj, enum kobject_action action);
140is created at the top-level of the sysfs partition.
141 147
148Use the KOBJ_ADD action for when the kobject is first added to the kernel.
149This should be done only after any attributes or children of the kobject
150have been initialized properly, as userspace will instantly start to look
151for them when this call happens.
142 152
153When the kobject is removed from the kernel (details on how to do that is
154below), the uevent for KOBJ_REMOVE will be automatically created by the
155kobject core, so the caller does not have to worry about doing that by
156hand.
143 157
1442. ksets
145 158
1462.1 Description 159Reference counts
147 160
148A kset is a set of kobjects that are embedded in the same type. 161One of the key functions of a kobject is to serve as a reference counter
162for the object in which it is embedded. As long as references to the object
163exist, the object (and the code which supports it) must continue to exist.
164The low-level functions for manipulating a kobject's reference counts are:
149 165
166 struct kobject *kobject_get(struct kobject *kobj);
167 void kobject_put(struct kobject *kobj);
150 168
151struct kset { 169A successful call to kobject_get() will increment the kobject's reference
152 struct kobj_type * ktype; 170counter and return the pointer to the kobject.
153 struct list_head list;
154 struct kobject kobj;
155 struct kset_uevent_ops * uevent_ops;
156};
157 171
172When a reference is released, the call to kobject_put() will decrement the
173reference count and, possibly, free the object. Note that kobject_init()
174sets the reference count to one, so the code which sets up the kobject will
175need to do a kobject_put() eventually to release that reference.
158 176
159void kset_init(struct kset * k); 177Because kobjects are dynamic, they must not be declared statically or on
160int kset_add(struct kset * k); 178the stack, but instead, always allocated dynamically. Future versions of
161int kset_register(struct kset * k); 179the kernel will contain a run-time check for kobjects that are created
162void kset_unregister(struct kset * k); 180statically and will warn the developer of this improper usage.
163 181
164struct kset * kset_get(struct kset * k); 182If all that you want to use a kobject for is to provide a reference counter
165void kset_put(struct kset * k); 183for your structure, please use the struct kref instead; a kobject would be
184overkill. For more information on how to use struct kref, please see the
185file Documentation/kref.txt in the Linux kernel source tree.
166 186
167struct kobject * kset_find_obj(struct kset *, char *);
168 187
188Creating "simple" kobjects
169 189
170The type that the kobjects are embedded in is described by the ktype 190Sometimes all that a developer wants is a way to create a simple directory
171pointer. 191in the sysfs hierarchy, and not have to mess with the whole complication of
192ksets, show and store functions, and other details. This is the one
193exception where a single kobject should be created. To create such an
194entry, use the function:
172 195
173A kset contains a kobject itself, meaning that it may be registered in 196 struct kobject *kobject_create_and_add(char *name, struct kobject *parent);
174the kobject hierarchy and exported via sysfs. More importantly, the
175kset may be embedded in a larger data type, and may be part of another
176kset (of that object type).
177 197
178For example, a block device is an object (struct gendisk) that is 198This function will create a kobject and place it in sysfs in the location
179contained in a set of block devices. It may also contain a set of 199underneath the specified parent kobject. To create simple attributes
180partitions (struct hd_struct) that have been found on the device. The 200associated with this kobject, use:
181following code snippet illustrates how to express this properly.
182 201
183 struct gendisk * disk; 202 int sysfs_create_file(struct kobject *kobj, struct attribute *attr);
184 ... 203or
185 disk->kset.kobj.kset = &block_kset; 204 int sysfs_create_group(struct kobject *kobj, struct attribute_group *grp);
186 disk->kset.ktype = &partition_ktype;
187 kset_register(&disk->kset);
188 205
189- The kset that the disk's embedded object belongs to is the 206Both types of attributes used here, with a kobject that has been created
190 block_kset, and is pointed to by disk->kset.kobj.kset. 207with the kobject_create_and_add(), can be of type kobj_attribute, so no
208special custom attribute is needed to be created.
191 209
192- The type of objects on the disk's _subordinate_ list are partitions, 210See the example module, samples/kobject/kobject-example.c for an
193 and is set in disk->kset.ktype. 211implementation of a simple kobject and attributes.
194 212
195- The kset is then registered, which handles initializing and adding
196 the embedded kobject to the hierarchy.
197 213
198 214
1992.2 kset Programming Interface 215ktypes and release methods
200 216
201All kset functions, except kset_find_obj(), eventually forward the 217One important thing still missing from the discussion is what happens to a
202calls to their embedded kobjects after performing kset-specific 218kobject when its reference count reaches zero. The code which created the
203operations. ksets offer a similar programming model to kobjects: they 219kobject generally does not know when that will happen; if it did, there
204may be used after they are initialized, without registering them in 220would be little point in using a kobject in the first place. Even
205the hierarchy. 221predictable object lifecycles become more complicated when sysfs is brought
222in as other portions of the kernel can get a reference on any kobject that
223is registered in the system.
206 224
207kset_find_obj() may be used to locate a kobject with a particular 225The end result is that a structure protected by a kobject cannot be freed
208name. The kobject, if found, is returned. 226before its reference count goes to zero. The reference count is not under
227the direct control of the code which created the kobject. So that code must
228be notified asynchronously whenever the last reference to one of its
229kobjects goes away.
209 230
210There are also some helper functions which names point to the formerly 231Once you registered your kobject via kobject_add(), you must never use
211existing "struct subsystem", whose functions have been taken over by 232kfree() to free it directly. The only safe way is to use kobject_put(). It
212ksets. 233is good practice to always use kobject_put() after kobject_init() to avoid
234errors creeping in.
213 235
236This notification is done through a kobject's release() method. Usually
237such a method has a form like:
214 238
215decl_subsys(name,type,uevent_ops) 239 void my_object_release(struct kobject *kobj)
240 {
241 struct my_object *mine = container_of(kobj, struct my_object, kobj);
216 242
217Declares a kset named '<name>_subsys' of type <type> with 243 /* Perform any additional cleanup on this object, then... */
218uevent_ops <uevent_ops>. For example, 244 kfree(mine);
245 }
219 246
220decl_subsys(devices, &ktype_device, &device_uevent_ops); 247One important point cannot be overstated: every kobject must have a
248release() method, and the kobject must persist (in a consistent state)
249until that method is called. If these constraints are not met, the code is
250flawed. Note that the kernel will warn you if you forget to provide a
251release() method. Do not try to get rid of this warning by providing an
252"empty" release function; you will be mocked mercilessly by the kobject
253maintainer if you attempt this.
221 254
222is equivalent to doing: 255Note, the name of the kobject is available in the release function, but it
256must NOT be changed within this callback. Otherwise there will be a memory
257leak in the kobject core, which makes people unhappy.
223 258
224struct kset devices_subsys = { 259Interestingly, the release() method is not stored in the kobject itself;
225 .ktype = &ktype_devices, 260instead, it is associated with the ktype. So let us introduce struct
226 .uevent_ops = &device_uevent_ops, 261kobj_type:
227}; 262
228kobject_set_name(&devices_subsys, name); 263 struct kobj_type {
264 void (*release)(struct kobject *);
265 struct sysfs_ops *sysfs_ops;
266 struct attribute **default_attrs;
267 };
229 268
230The objects that are registered with a subsystem that use the 269This structure is used to describe a particular type of kobject (or, more
231subsystem's default list must have their kset ptr set properly. These 270correctly, of containing object). Every kobject needs to have an associated
232objects may have embedded kobjects or ksets. The 271kobj_type structure; a pointer to that structure must be specified when you
233following helper makes setting the kset easier: 272call kobject_init() or kobject_init_and_add().
234 273
274The release field in struct kobj_type is, of course, a pointer to the
275release() method for this type of kobject. The other two fields (sysfs_ops
276and default_attrs) control how objects of this type are represented in
277sysfs; they are beyond the scope of this document.
235 278
236kobj_set_kset_s(obj,subsys) 279The default_attrs pointer is a list of default attributes that will be
280automatically created for any kobject that is registered with this ktype.
237 281
238- Assumes that obj->kobj exists, and is a struct kobject.
239- Sets the kset of that kobject to the kset <subsys>.
240 282
241int subsystem_register(struct kset *s); 283ksets
242void subsystem_unregister(struct kset *s);
243 284
244These are just wrappers around the respective kset_* functions. 285A kset is merely a collection of kobjects that want to be associated with
286each other. There is no restriction that they be of the same ktype, but be
287very careful if they are not.
245 288
2462.3 sysfs 289A kset serves these functions:
247 290
248ksets are represented in sysfs when their embedded kobjects are 291 - It serves as a bag containing a group of objects. A kset can be used by
249registered. They follow the same rules of parenting, with one 292 the kernel to track "all block devices" or "all PCI device drivers."
250exception. If a kset does not have a parent, nor is its embedded
251kobject part of another kset, the kset's parent becomes its dominant
252subsystem.
253 293
254If the kset does not have a parent, its directory is created at the 294 - A kset is also a subdirectory in sysfs, where the associated kobjects
255sysfs root. This should only happen when the kset registered is 295 with the kset can show up. Every kset contains a kobject which can be
256embedded in a subsystem itself. 296 set up to be the parent of other kobjects; the top-level directories of
297 the sysfs hierarchy are constructed in this way.
257 298
299 - Ksets can support the "hotplugging" of kobjects and influence how
300 uevent events are reported to user space.
258 301
2593. struct ktype 302In object-oriented terms, "kset" is the top-level container class; ksets
303contain their own kobject, but that kobject is managed by the kset code and
304should not be manipulated by any other user.
260 305
2613.1. Description 306A kset keeps its children in a standard kernel linked list. Kobjects point
307back to their containing kset via their kset field. In almost all cases,
308the kobjects belonging to a ket have that kset (or, strictly, its embedded
309kobject) in their parent.
262 310
263struct kobj_type { 311As a kset contains a kobject within it, it should always be dynamically
264 void (*release)(struct kobject *); 312created and never declared statically or on the stack. To create a new
265 struct sysfs_ops * sysfs_ops; 313kset use:
266 struct attribute ** default_attrs; 314 struct kset *kset_create_and_add(const char *name,
315 struct kset_uevent_ops *u,
316 struct kobject *parent);
317
318When you are finished with the kset, call:
319 void kset_unregister(struct kset *kset);
320to destroy it.
321
322An example of using a kset can be seen in the
323samples/kobject/kset-example.c file in the kernel tree.
324
325If a kset wishes to control the uevent operations of the kobjects
326associated with it, it can use the struct kset_uevent_ops to handle it:
327
328struct kset_uevent_ops {
329 int (*filter)(struct kset *kset, struct kobject *kobj);
330 const char *(*name)(struct kset *kset, struct kobject *kobj);
331 int (*uevent)(struct kset *kset, struct kobject *kobj,
332 struct kobj_uevent_env *env);
267}; 333};
268 334
269 335
270Object types require specific functions for converting between the 336The filter function allows a kset to prevent a uevent from being emitted to
271generic object and the more complex type. struct kobj_type provides 337userspace for a specific kobject. If the function returns 0, the uevent
272the object-specific fields, which include: 338will not be emitted.
339
340The name function will be called to override the default name of the kset
341that the uevent sends to userspace. By default, the name will be the same
342as the kset itself, but this function, if present, can override that name.
343
344The uevent function will be called when the uevent is about to be sent to
345userspace to allow more environment variables to be added to the uevent.
346
347One might ask how, exactly, a kobject is added to a kset, given that no
348functions which perform that function have been presented. The answer is
349that this task is handled by kobject_add(). When a kobject is passed to
350kobject_add(), its kset member should point to the kset to which the
351kobject will belong. kobject_add() will handle the rest.
352
353If the kobject belonging to a kset has no parent kobject set, it will be
354added to the kset's directory. Not all members of a kset do necessarily
355live in the kset directory. If an explicit parent kobject is assigned
356before the kobject is added, the kobject is registered with the kset, but
357added below the parent kobject.
358
359
360Kobject removal
273 361
274- release: Called when the kobject's reference count reaches 0. This 362After a kobject has been registered with the kobject core successfully, it
275 should convert the object to the more complex type and free it. 363must be cleaned up when the code is finished with it. To do that, call
364kobject_put(). By doing this, the kobject core will automatically clean up
365all of the memory allocated by this kobject. If a KOBJ_ADD uevent has been
366sent for the object, a corresponding KOBJ_REMOVE uevent will be sent, and
367any other sysfs housekeeping will be handled for the caller properly.
276 368
277- sysfs_ops: Provides conversion functions for sysfs access. Please 369If you need to do a two-stage delete of the kobject (say you are not
278 see the sysfs documentation for more information. 370allowed to sleep when you need to destroy the object), then call
371kobject_del() which will unregister the kobject from sysfs. This makes the
372kobject "invisible", but it is not cleaned up, and the reference count of
373the object is still the same. At a later time call kobject_put() to finish
374the cleanup of the memory associated with the kobject.
279 375
280- default_attrs: Default attributes to be exported via sysfs when the 376kobject_del() can be used to drop the reference to the parent object, if
281 object is registered.Note that the last attribute has to be 377circular references are constructed. It is valid in some cases, that a
282 initialized to NULL ! You can find a complete implementation 378parent objects references a child. Circular references _must_ be broken
283 in block/genhd.c 379with an explicit call to kobject_del(), so that a release functions will be
380called, and the objects in the former circle release each other.
284 381
285 382
286Instances of struct kobj_type are not registered; only referenced by 383Example code to copy from
287the kset. A kobj_type may be referenced by an arbitrary number of
288ksets, as there may be disparate sets of identical objects.
289 384
385For a more complete example of using ksets and kobjects properly, see the
386sample/kobject/kset-example.c code.
diff --git a/Documentation/pnp.txt b/Documentation/pnp.txt
index 481faf515d53..a327db67782a 100644
--- a/Documentation/pnp.txt
+++ b/Documentation/pnp.txt
@@ -17,9 +17,9 @@ The User Interface
17------------------ 17------------------
18 The Linux Plug and Play user interface provides a means to activate PnP devices 18 The Linux Plug and Play user interface provides a means to activate PnP devices
19for legacy and user level drivers that do not support Linux Plug and Play. The 19for legacy and user level drivers that do not support Linux Plug and Play. The
20user interface is integrated into driverfs. 20user interface is integrated into sysfs.
21 21
22In addition to the standard driverfs file the following are created in each 22In addition to the standard sysfs file the following are created in each
23device's directory: 23device's directory:
24id - displays a list of support EISA IDs 24id - displays a list of support EISA IDs
25options - displays possible resource configurations 25options - displays possible resource configurations
diff --git a/Documentation/s390/cds.txt b/Documentation/s390/cds.txt
index 3081927cc2d6..c4b7b2bd369a 100644
--- a/Documentation/s390/cds.txt
+++ b/Documentation/s390/cds.txt
@@ -133,7 +133,7 @@ During its startup the Linux/390 system checks for peripheral devices. Each
133of those devices is uniquely defined by a so called subchannel by the ESA/390 133of those devices is uniquely defined by a so called subchannel by the ESA/390
134channel subsystem. While the subchannel numbers are system generated, each 134channel subsystem. While the subchannel numbers are system generated, each
135subchannel also takes a user defined attribute, the so called device number. 135subchannel also takes a user defined attribute, the so called device number.
136Both subchannel number and device number cannot exceed 65535. During driverfs 136Both subchannel number and device number cannot exceed 65535. During sysfs
137initialisation, the information about control unit type and device types that 137initialisation, the information about control unit type and device types that
138imply specific I/O commands (channel command words - CCWs) in order to operate 138imply specific I/O commands (channel command words - CCWs) in order to operate
139the device are gathered. Device drivers can retrieve this set of hardware 139the device are gathered. Device drivers can retrieve this set of hardware
diff --git a/Documentation/vm/slabinfo.c b/Documentation/vm/slabinfo.c
index 7047696c47a1..488c1f31b992 100644
--- a/Documentation/vm/slabinfo.c
+++ b/Documentation/vm/slabinfo.c
@@ -1021,7 +1021,7 @@ void read_slab_dir(void)
1021 char *t; 1021 char *t;
1022 int count; 1022 int count;
1023 1023
1024 if (chdir("/sys/slab")) 1024 if (chdir("/sys/kernel/slab"))
1025 fatal("SYSFS support for SLUB not active\n"); 1025 fatal("SYSFS support for SLUB not active\n");
1026 1026
1027 dir = opendir("."); 1027 dir = opendir(".");
diff --git a/Documentation/vm/slub.txt b/Documentation/vm/slub.txt
index d17f324db9f5..dcf8bcf846d6 100644
--- a/Documentation/vm/slub.txt
+++ b/Documentation/vm/slub.txt
@@ -63,7 +63,7 @@ In case you forgot to enable debugging on the kernel command line: It is
63possible to enable debugging manually when the kernel is up. Look at the 63possible to enable debugging manually when the kernel is up. Look at the
64contents of: 64contents of:
65 65
66/sys/slab/<slab name>/ 66/sys/kernel/slab/<slab name>/
67 67
68Look at the writable files. Writing 1 to them will enable the 68Look at the writable files. Writing 1 to them will enable the
69corresponding debug option. All options can be set on a slab that does 69corresponding debug option. All options can be set on a slab that does
diff --git a/Documentation/zh_CN/CodingStyle b/Documentation/zh_CN/CodingStyle
new file mode 100644
index 000000000000..ecd9307a641f
--- /dev/null
+++ b/Documentation/zh_CN/CodingStyle
@@ -0,0 +1,701 @@
1Chinese translated version of Documentation/CodingStyle
2
3If you have any comment or update to the content, please post to LKML directly.
4However, if you have problem communicating in English you can also ask the
5Chinese maintainer for help. Contact the Chinese maintainer, if this
6translation is outdated or there is problem with translation.
7
8Chinese maintainer: Zhang Le <r0bertz@gentoo.org>
9---------------------------------------------------------------------
10Documentation/CodingStyle的中文翻译
11
12如果想评论或更新本文的内容,请直接发信到LKML。如果你使用英文交流有困难的话,也可
13以向中文版维护者求助。如果本翻译更新不及时或者翻译存在问题,请联系中文版维护者。
14
15中文版维护者: 张乐 Zhang Le <r0bertz@gentoo.org>
16中文版翻译者: 张乐 Zhang Le <r0bertz@gentoo.org>
17中文版校译者: 王聪 Wang Cong <xiyou.wangcong@gmail.com>
18 wheelz <kernel.zeng@gmail.com>
19 管旭东 Xudong Guan <xudong.guan@gmail.com>
20 Li Zefan <lizf@cn.fujitsu.com>
21 Wang Chen <wangchen@cn.fujitsu.com>
22以下为正文
23---------------------------------------------------------------------
24
25 Linux内核代码风格
26
27这是一个简短的文档,描述了linux内核的首选代码风格。代码风格是因人而异的,而且我
28不愿意把我的观点强加给任何人,不过这里所讲述的是我必须要维护的代码所遵守的风格,
29并且我也希望绝大多数其他代码也能遵守这个风格。请在写代码时至少考虑一下本文所述的
30风格。
31
32首先,我建议你打印一份GNU代码规范,然后不要读它。烧了它,这是一个具有重大象征性
33意义的动作。
34
35不管怎样,现在我们开始:
36
37
38 第一章:缩进
39
40制表符是8个字符,所以缩进也是8个字符。有些异端运动试图将缩进变为4(乃至2)个字符
41深,这几乎相当于尝试将圆周率的值定义为3。
42
43理由:缩进的全部意义就在于清楚的定义一个控制块起止于何处。尤其是当你盯着你的屏幕
44连续看了20小时之后,你将会发现大一点的缩进会使你更容易分辨缩进。
45
46现在,有些人会抱怨8个字符的缩进会使代码向右边移动的太远,在80个字符的终端屏幕上
47就很难读这样的代码。这个问题的答案是,如果你需要3级以上的缩进,不管用何种方式你
48的代码已经有问题了,应该修正你的程序。
49
50简而言之,8个字符的缩进可以让代码更容易阅读,还有一个好处是当你的函数嵌套太深的
51时候可以给你警告。留心这个警告。
52
53在switch语句中消除多级缩进的首选的方式是让“switch”和从属于它的“case”标签对齐于同
54一列,而不要“两次缩进”“case”标签。比如:
55
56 switch (suffix) {
57 case 'G':
58 case 'g':
59 mem <<= 30;
60 break;
61 case 'M':
62 case 'm':
63 mem <<= 20;
64 break;
65 case 'K':
66 case 'k':
67 mem <<= 10;
68 /* fall through */
69 default:
70 break;
71 }
72
73
74不要把多个语句放在一行里,除非你有什么东西要隐藏:
75
76 if (condition) do_this;
77 do_something_everytime;
78
79也不要在一行里放多个赋值语句。内核代码风格超级简单。就是避免可能导致别人误读的表
80达式。
81
82除了注释、文档和Kconfig之外,不要使用空格来缩进,前面的例子是例外,是有意为之。
83
84选用一个好的编辑器,不要在行尾留空格。
85
86
87 第二章:把长的行和字符串打散
88
89代码风格的意义就在于使用平常使用的工具来维持代码的可读性和可维护性。
90
91每一行的长度的限制是80列,我们强烈建议您遵守这个惯例。
92
93长于80列的语句要打散成有意义的片段。每个片段要明显短于原来的语句,而且放置的位置
94也明显的靠右。同样的规则也适用于有很长参数列表的函数头。长字符串也要打散成较短的
95字符串。唯一的例外是超过80列可以大幅度提高可读性并且不会隐藏信息的情况。
96
97void fun(int a, int b, int c)
98{
99 if (condition)
100 printk(KERN_WARNING "Warning this is a long printk with "
101 "3 parameters a: %u b: %u "
102 "c: %u \n", a, b, c);
103 else
104 next_statement;
105}
106
107 第三章:大括号和空格的放置
108
109C语言风格中另外一个常见问题是大括号的放置。和缩进大小不同,选择或弃用某种放置策
110略并没有多少技术上的原因,不过首选的方式,就像Kernighan和Ritchie展示给我们的,是
111把起始大括号放在行尾,而把结束大括号放在行首,所以:
112
113 if (x is true) {
114 we do y
115 }
116
117这适用于所有的非函数语句块(if、switch、for、while、do)。比如:
118
119 switch (action) {
120 case KOBJ_ADD:
121 return "add";
122 case KOBJ_REMOVE:
123 return "remove";
124 case KOBJ_CHANGE:
125 return "change";
126 default:
127 return NULL;
128 }
129
130不过,有一个例外,那就是函数:函数的起始大括号放置于下一行的开头,所以:
131
132 int function(int x)
133 {
134 body of function
135 }
136
137全世界的异端可能会抱怨这个不一致性是……呃……不一致的,不过所有思维健全的人都知道(
138a)K&R是_正确的_,并且(b)K&R是正确的。此外,不管怎样函数都是特殊的(在C语言中
139,函数是不能嵌套的)。
140
141注意结束大括号独自占据一行,除非它后面跟着同一个语句的剩余部分,也就是do语句中的
142“while”或者if语句中的“else”,像这样:
143
144 do {
145 body of do-loop
146 } while (condition);
147
148
149
150 if (x == y) {
151 ..
152 } else if (x > y) {
153 ...
154 } else {
155 ....
156 }
157
158理由:K&R。
159
160也请注意这种大括号的放置方式也能使空(或者差不多空的)行的数量最小化,同时不失可
161读性。因此,由于你的屏幕上的新行是不可再生资源(想想25行的终端屏幕),你将会有更
162多的空行来放置注释。
163
164当只有一个单独的语句的时候,不用加不必要的大括号。
165
166if (condition)
167 action();
168
169这点不适用于本身为某个条件语句的一个分支的单独语句。这时需要在两个分支里都使用大
170括号。
171
172if (condition) {
173 do_this();
174 do_that();
175} else {
176 otherwise();
177}
178
179 3.1:空格
180
181Linux内核的空格使用方式(主要)取决于它是用于函数还是关键字。(大多数)关键字后
182要加一个空格。值得注意的例外是sizeof、typeof、alignof和__attribute__,这些关键字
183某些程度上看起来更像函数(它们在Linux里也常常伴随小括号而使用,尽管在C语言里这样
184的小括号不是必需的,就像“struct fileinfo info”声明过后的“sizeof info”)。
185
186所以在这些关键字之后放一个空格:
187 if, switch, case, for, do, while
188但是不要在sizeof、typeof、alignof或者__attribute__这些关键字之后放空格。例如,
189 s = sizeof(struct file);
190
191不要在小括号里的表达式两侧加空格。这是一个反例:
192
193 s = sizeof( struct file );
194
195当声明指针类型或者返回指针类型的函数时,“*”的首选使用方式是使之靠近变量名或者函
196数名,而不是靠近类型名。例子:
197
198 char *linux_banner;
199 unsigned long long memparse(char *ptr, char **retptr);
200 char *match_strdup(substring_t *s);
201
202在大多数二元和三元操作符两侧使用一个空格,例如下面所有这些操作符:
203
204 = + - < > * / % | & ^ <= >= == != ? :
205
206但是一元操作符后不要加空格:
207 & * + - ~ ! sizeof typeof alignof __attribute__ defined
208
209后缀自加和自减一元操作符前不加空格:
210 ++ --
211
212前缀自加和自减一元操作符后不加空格:
213 ++ --
214
215“.”和“->”结构体成员操作符前后不加空格。
216
217不要在行尾留空白。有些可以自动缩进的编辑器会在新行的行首加入适量的空白,然后你
218就可以直接在那一行输入代码。不过假如你最后没有在那一行输入代码,有些编辑器就不
219会移除已经加入的空白,就像你故意留下一个只有空白的行。包含行尾空白的行就这样产
220生了。
221
222当git发现补丁包含了行尾空白的时候会警告你,并且可以应你的要求去掉行尾空白;不过
223如果你是正在打一系列补丁,这样做会导致后面的补丁失败,因为你改变了补丁的上下文。
224
225
226 第四章:命名
227
228C是一个简朴的语言,你的命名也应该这样。和Modula-2和Pascal程序员不同,C程序员不使
229用类似ThisVariableIsATemporaryCounter这样华丽的名字。C程序员会称那个变量为“tmp”
230,这样写起来会更容易,而且至少不会令其难于理解。
231
232不过,虽然混用大小写的名字是不提倡使用的,但是全局变量还是需要一个具描述性的名字
233。称一个全局函数为“foo”是一个难以饶恕的错误。
234
235全局变量(只有当你真正需要它们的时候再用它)需要有一个具描述性的名字,就像全局函
236数。如果你有一个可以计算活动用户数量的函数,你应该叫它“count_active_users()”或者
237类似的名字,你不应该叫它“cntuser()”。
238
239在函数名中包含函数类型(所谓的匈牙利命名法)是脑子出了问题——编译器知道那些类型而
240且能够检查那些类型,这样做只能把程序员弄糊涂了。难怪微软总是制造出有问题的程序。
241
242本地变量名应该简短,而且能够表达相关的含义。如果你有一些随机的整数型的循环计数器
243,它应该被称为“i”。叫它“loop_counter”并无益处,如果它没有被误解的可能的话。类似
244的,“tmp”可以用来称呼任意类型的临时变量。
245
246如果你怕混淆了你的本地变量名,你就遇到另一个问题了,叫做函数增长荷尔蒙失衡综合症
247。请看第六章(函数)。
248
249
250 第五章:Typedef
251
252不要使用类似“vps_t”之类的东西。
253
254对结构体和指针使用typedef是一个错误。当你在代码里看到:
255
256 vps_t a;
257
258这代表什么意思呢?
259
260相反,如果是这样
261
262 struct virtual_container *a;
263
264你就知道“a”是什么了。
265
266很多人认为typedef“能提高可读性”。实际不是这样的。它们只在下列情况下有用:
267
268 (a) 完全不透明的对象(这种情况下要主动使用typedef来隐藏这个对象实际上是什么)。
269
270 例如:“pte_t”等不透明对象,你只能用合适的访问函数来访问它们。
271
272 注意!不透明性和“访问函数”本身是不好的。我们使用pte_t等类型的原因在于真的是
273 完全没有任何共用的可访问信息。
274
275 (b) 清楚的整数类型,如此,这层抽象就可以帮助消除到底是“int”还是“long”的混淆。
276
277 u8/u16/u32是完全没有问题的typedef,不过它们更符合类别(d)而不是这里。
278
279 再次注意!要这样做,必须事出有因。如果某个变量是“unsigned long“,那么没有必要
280
281 typedef unsigned long myflags_t;
282
283 不过如果有一个明确的原因,比如它在某种情况下可能会是一个“unsigned int”而在
284 其他情况下可能为“unsigned long”,那么就不要犹豫,请务必使用typedef。
285
286 (c) 当你使用sparse按字面的创建一个新类型来做类型检查的时候。
287
288 (d) 和标准C99类型相同的类型,在某些例外的情况下。
289
290 虽然让眼睛和脑筋来适应新的标准类型比如“uint32_t”不需要花很多时间,可是有些
291 人仍然拒绝使用它们。
292
293 因此,Linux特有的等同于标准类型的“u8/u16/u32/u64”类型和它们的有符号类型是被
294 允许的——尽管在你自己的新代码中,它们不是强制要求要使用的。
295
296 当编辑已经使用了某个类型集的已有代码时,你应该遵循那些代码中已经做出的选择。
297
298 (e) 可以在用户空间安全使用的类型。
299
300 在某些用户空间可见的结构体里,我们不能要求C99类型而且不能用上面提到的“u32”
301 类型。因此,我们在与用户空间共享的所有结构体中使用__u32和类似的类型。
302
303可能还有其他的情况,不过基本的规则是永远不要使用typedef,除非你可以明确的应用上
304述某个规则中的一个。
305
306总的来说,如果一个指针或者一个结构体里的元素可以合理的被直接访问到,那么它们就不
307应该是一个typedef。
308
309
310 第六章:函数
311
312函数应该简短而漂亮,并且只完成一件事情。函数应该可以一屏或者两屏显示完(我们都知
313道ISO/ANSI屏幕大小是80x24),只做一件事情,而且把它做好。
314
315一个函数的最大长度是和该函数的复杂度和缩进级数成反比的。所以,如果你有一个理论上
316很简单的只有一个很长(但是简单)的case语句的函数,而且你需要在每个case里做很多很
317小的事情,这样的函数尽管很长,但也是可以的。
318
319不过,如果你有一个复杂的函数,而且你怀疑一个天分不是很高的高中一年级学生可能甚至
320搞不清楚这个函数的目的,你应该严格的遵守前面提到的长度限制。使用辅助函数,并为之
321取个具描述性的名字(如果你觉得它们的性能很重要的话,可以让编译器内联它们,这样的
322效果往往会比你写一个复杂函数的效果要好。)
323
324函数的另外一个衡量标准是本地变量的数量。此数量不应超过5-10个,否则你的函数就有
325问题了。重新考虑一下你的函数,把它分拆成更小的函数。人的大脑一般可以轻松的同时跟
326踪7个不同的事物,如果再增多的话,就会糊涂了。即便你聪颖过人,你也可能会记不清你2
327个星期前做过的事情。
328
329在源文件里,使用空行隔开不同的函数。如果该函数需要被导出,它的EXPORT*宏应该紧贴
330在它的结束大括号之下。比如:
331
332int system_is_up(void)
333{
334 return system_state == SYSTEM_RUNNING;
335}
336EXPORT_SYMBOL(system_is_up);
337
338在函数原型中,包含函数名和它们的数据类型。虽然C语言里没有这样的要求,在Linux里这
339是提倡的做法,因为这样可以很简单的给读者提供更多的有价值的信息。
340
341
342 第七章:集中的函数退出途径
343
344虽然被某些人声称已经过时,但是goto语句的等价物还是经常被编译器所使用,具体形式是
345无条件跳转指令。
346
347当一个函数从多个位置退出并且需要做一些通用的清理工作的时候,goto的好处就显现出来
348了。
349
350理由是:
351
352- 无条件语句容易理解和跟踪
353- 嵌套程度减小
354- 可以避免由于修改时忘记更新某个单独的退出点而导致的错误
355- 减轻了编译器的工作,无需删除冗余代码;)
356
357int fun(int a)
358{
359 int result = 0;
360 char *buffer = kmalloc(SIZE);
361
362 if (buffer == NULL)
363 return -ENOMEM;
364
365 if (condition1) {
366 while (loop1) {
367 ...
368 }
369 result = 1;
370 goto out;
371 }
372 ...
373out:
374 kfree(buffer);
375 return result;
376}
377
378 第八章:注释
379
380注释是好的,不过有过度注释的危险。永远不要在注释里解释你的代码是如何运作的:更好
381的做法是让别人一看你的代码就可以明白,解释写的很差的代码是浪费时间。
382
383一般的,你想要你的注释告诉别人你的代码做了什么,而不是怎么做的。也请你不要把注释
384放在一个函数体内部:如果函数复杂到你需要独立的注释其中的一部分,你很可能需要回到
385第六章看一看。你可以做一些小注释来注明或警告某些很聪明(或者槽糕)的做法,但不要
386加太多。你应该做的,是把注释放在函数的头部,告诉人们它做了什么,也可以加上它做这
387些事情的原因。
388
389当注释内核API函数时,请使用kernel-doc格式。请看
390Documentation/kernel-doc-nano-HOWTO.txt和scripts/kernel-doc以获得详细信息。
391
392Linux的注释风格是C89“/* ... */”风格。不要使用C99风格“// ...”注释。
393
394长(多行)的首选注释风格是:
395
396 /*
397 * This is the preferred style for multi-line
398 * comments in the Linux kernel source code.
399 * Please use it consistently.
400 *
401 * Description: A column of asterisks on the left side,
402 * with beginning and ending almost-blank lines.
403 */
404
405注释数据也是很重要的,不管是基本类型还是衍生类型。为了方便实现这一点,每一行应只
406声明一个数据(不要使用逗号来一次声明多个数据)。这样你就有空间来为每个数据写一段
407小注释来解释它们的用途了。
408
409
410 第九章:你已经把事情弄糟了
411
412这没什么,我们都是这样。可能你的使用了很长时间Unix的朋友已经告诉你“GNU emacs”能
413自动帮你格式化C源代码,而且你也注意到了,确实是这样,不过它所使用的默认值和我们
414想要的相去甚远(实际上,甚至比随机打的还要差——无数个猴子在GNU emacs里打字永远不
415会创造出一个好程序)(译注:请参考Infinite Monkey Theorem)
416
417所以你要么放弃GNU emacs,要么改变它让它使用更合理的设定。要采用后一个方案,你可
418以把下面这段粘贴到你的.emacs文件里。
419
420(defun linux-c-mode ()
421 "C mode with adjusted defaults for use with the Linux kernel."
422 (interactive)
423 (c-mode)
424 (c-set-style "K&R")
425 (setq tab-width 8)
426 (setq indent-tabs-mode t)
427 (setq c-basic-offset 8))
428
429这样就定义了M-x linux-c-mode命令。当你hack一个模块的时候,如果你把字符串
430-*- linux-c -*-放在头两行的某个位置,这个模式将会被自动调用。如果你希望在你修改
431/usr/src/linux里的文件时魔术般自动打开linux-c-mode的话,你也可能需要添加
432
433(setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode)
434 auto-mode-alist))
435
436到你的.emacs文件里。
437
438不过就算你尝试让emacs正确的格式化代码失败了,也并不意味着你失去了一切:还可以用“
439indent”。
440
441不过,GNU indent也有和GNU emacs一样有问题的设定,所以你需要给它一些命令选项。不
442过,这还不算太糟糕,因为就算是GNU indent的作者也认同K&R的权威性(GNU的人并不是坏
443人,他们只是在这个问题上被严重的误导了),所以你只要给indent指定选项“-kr -i8”
444(代表“K&R,8个字符缩进”),或者使用“scripts/Lindent”,这样就可以以最时髦的方式
445缩进源代码。
446
447“indent”有很多选项,特别是重新格式化注释的时候,你可能需要看一下它的手册页。不过
448记住:“indent”不能修正坏的编程习惯。
449
450
451 第十章:Kconfig配置文件
452
453对于遍布源码树的所有Kconfig*配置文件来说,它们缩进方式与C代码相比有所不同。紧挨
454在“config”定义下面的行缩进一个制表符,帮助信息则再多缩进2个空格。比如:
455
456config AUDIT
457 bool "Auditing support"
458 depends on NET
459 help
460 Enable auditing infrastructure that can be used with another
461 kernel subsystem, such as SELinux (which requires this for
462 logging of avc messages output). Does not do system-call
463 auditing without CONFIG_AUDITSYSCALL.
464
465仍然被认为不够稳定的功能应该被定义为依赖于“EXPERIMENTAL”:
466
467config SLUB
468 depends on EXPERIMENTAL && !ARCH_USES_SLAB_PAGE_STRUCT
469 bool "SLUB (Unqueued Allocator)"
470 ...
471
472而那些危险的功能(比如某些文件系统的写支持)应该在它们的提示字符串里显著的声明这
473一点:
474
475config ADFS_FS_RW
476 bool "ADFS write support (DANGEROUS)"
477 depends on ADFS_FS
478 ...
479
480要查看配置文件的完整文档,请看Documentation/kbuild/kconfig-language.txt。
481
482
483 第十一章:数据结构
484
485如果一个数据结构,在创建和销毁它的单线执行环境之外可见,那么它必须要有一个引用计
486数器。内核里没有垃圾收集(并且内核之外的垃圾收集慢且效率低下),这意味着你绝对需
487要记录你对这种数据结构的使用情况。
488
489引用计数意味着你能够避免上锁,并且允许多个用户并行访问这个数据结构——而不需要担心
490这个数据结构仅仅因为暂时不被使用就消失了,那些用户可能不过是沉睡了一阵或者做了一
491些其他事情而已。
492
493注意上锁不能取代引用计数。上锁是为了保持数据结构的一致性,而引用计数是一个内存管
494理技巧。通常二者都需要,不要把两个搞混了。
495
496很多数据结构实际上有2级引用计数,它们通常有不同“类”的用户。子类计数器统计子类用
497户的数量,每当子类计数器减至零时,全局计数器减一。
498
499这种“多级引用计数”的例子可以在内存管理(“struct mm_struct”:mm_users和mm_count)
500和文件系统(“struct super_block”:s_count和s_active)中找到。
501
502记住:如果另一个执行线索可以找到你的数据结构,但是这个数据结构没有引用计数器,这
503里几乎肯定是一个bug。
504
505
506 第十二章:宏,枚举和RTL
507
508用于定义常量的宏的名字及枚举里的标签需要大写。
509
510#define CONSTANT 0x12345
511
512在定义几个相关的常量时,最好用枚举。
513
514宏的名字请用大写字母,不过形如函数的宏的名字可以用小写字母。
515
516一般的,如果能写成内联函数就不要写成像函数的宏。
517
518含有多个语句的宏应该被包含在一个do-while代码块里:
519
520#define macrofun(a, b, c) \
521 do { \
522 if (a == 5) \
523 do_this(b, c); \
524 } while (0)
525
526使用宏的时候应避免的事情:
527
5281) 影响控制流程的宏:
529
530#define FOO(x) \
531 do { \
532 if (blah(x) < 0) \
533 return -EBUGGERED; \
534 } while(0)
535
536非常不好。它看起来像一个函数,不过却能导致“调用”它的函数退出;不要打乱读者大脑里
537的语法分析器。
538
5392) 依赖于一个固定名字的本地变量的宏:
540
541#define FOO(val) bar(index, val)
542
543可能看起来像是个不错的东西,不过它非常容易把读代码的人搞糊涂,而且容易导致看起来
544不相关的改动带来错误。
545
5463) 作为左值的带参数的宏: FOO(x) = y;如果有人把FOO变成一个内联函数的话,这种用
547法就会出错了。
548
5494) 忘记了优先级:使用表达式定义常量的宏必须将表达式置于一对小括号之内。带参数的
550宏也要注意此类问题。
551
552#define CONSTANT 0x4000
553#define CONSTEXP (CONSTANT | 3)
554
555cpp手册对宏的讲解很详细。Gcc internals手册也详细讲解了RTL(译注:register
556transfer language),内核里的汇编语言经常用到它。
557
558
559 第十三章:打印内核消息
560
561内核开发者应该是受过良好教育的。请一定注意内核信息的拼写,以给人以好的印象。不要
562用不规范的单词比如“dont”,而要用“do not”或者“don't”。保证这些信息简单、明了、无
563歧义。
564
565内核信息不必以句号(译注:英文句号,即点)结束。
566
567在小括号里打印数字(%d)没有任何价值,应该避免这样做。
568
569<linux/device.h>里有一些驱动模型诊断宏,你应该使用它们,以确保信息对应于正确的
570设备和驱动,并且被标记了正确的消息级别。这些宏有:dev_err(), dev_warn(),
571dev_info()等等。对于那些不和某个特定设备相关连的信息,<linux/kernel.h>定义了
572pr_debug()和pr_info()。
573
574写出好的调试信息可以是一个很大的挑战;当你写出来之后,这些信息在远程除错的时候
575就会成为极大的帮助。当DEBUG符号没有被定义的时候,这些信息不应该被编译进内核里
576(也就是说,默认地,它们不应该被包含在内)。如果你使用dev_dbg()或者pr_debug(),
577就能自动达到这个效果。很多子系统拥有Kconfig选项来启用-DDEBUG。还有一个相关的惯例
578是使用VERBOSE_DEBUG来添加dev_vdbg()消息到那些已经由DEBUG启用的消息之上。
579
580
581 第十四章:分配内存
582
583内核提供了下面的一般用途的内存分配函数:kmalloc(),kzalloc(),kcalloc()和
584vmalloc()。请参考API文档以获取有关它们的详细信息。
585
586传递结构体大小的首选形式是这样的:
587
588 p = kmalloc(sizeof(*p), ...);
589
590另外一种传递方式中,sizeof的操作数是结构体的名字,这样会降低可读性,并且可能会引
591入bug。有可能指针变量类型被改变时,而对应的传递给内存分配函数的sizeof的结果不变。
592
593强制转换一个void指针返回值是多余的。C语言本身保证了从void指针到其他任何指针类型
594的转换是没有问题的。
595
596
597 第十五章:内联弊病
598
599有一个常见的误解是内联函数是gcc提供的可以让代码运行更快的一个选项。虽然使用内联
600函数有时候是恰当的(比如作为一种替代宏的方式,请看第十二章),不过很多情况下不是
601这样。inline关键字的过度使用会使内核变大,从而使整个系统运行速度变慢。因为大内核
602会占用更多的指令高速缓存(译注:一级缓存通常是指令缓存和数据缓存分开的)而且会导
603致pagecache的可用内存减少。想象一下,一次pagecache未命中就会导致一次磁盘寻址,将
604耗时5毫秒。5毫秒的时间内CPU能执行很多很多指令。
605
606一个基本的原则是如果一个函数有3行以上,就不要把它变成内联函数。这个原则的一个例
607外是,如果你知道某个参数是一个编译时常量,而且因为这个常量你确定编译器在编译时能
608优化掉你的函数的大部分代码,那仍然可以给它加上inline关键字。kmalloc()内联函数就
609是一个很好的例子。
610
611人们经常主张给static的而且只用了一次的函数加上inline,如此不会有任何损失,因为没
612有什么好权衡的。虽然从技术上说这是正确的,但是实际上这种情况下即使不加inline gcc
613也可以自动使其内联。而且其他用户可能会要求移除inline,由此而来的争论会抵消inline
614自身的潜在价值,得不偿失。
615
616
617 第十六章:函数返回值及命名
618
619函数可以返回很多种不同类型的值,最常见的一种是表明函数执行成功或者失败的值。这样
620的一个值可以表示为一个错误代码整数(-Exxx=失败,0=成功)或者一个“成功”布尔值(
6210=失败,非0=成功)。
622
623混合使用这两种表达方式是难于发现的bug的来源。如果C语言本身严格区分整形和布尔型变
624量,那么编译器就能够帮我们发现这些错误……不过C语言不区分。为了避免产生这种bug,请
625遵循下面的惯例:
626
627 如果函数的名字是一个动作或者强制性的命令,那么这个函数应该返回错误代码整
628 数。如果是一个判断,那么函数应该返回一个“成功”布尔值。
629
630比如,“add work”是一个命令,所以add_work()函数在成功时返回0,在失败时返回-EBUSY。
631类似的,因为“PCI device present”是一个判断,所以pci_dev_present()函数在成功找到
632一个匹配的设备时应该返回1,如果找不到时应该返回0。
633
634所有导出(译注:EXPORT)的函数都必须遵守这个惯例,所有的公共函数也都应该如此。私
635有(static)函数不需要如此,但是我们也推荐这样做。
636
637返回值是实际计算结果而不是计算是否成功的标志的函数不受此惯例的限制。一般的,他们
638通过返回一些正常值范围之外的结果来表示出错。典型的例子是返回指针的函数,他们使用
639NULL或者ERR_PTR机制来报告错误。
640
641
642 第十七章:不要重新发明内核宏
643
644头文件include/linux/kernel.h包含了一些宏,你应该使用它们,而不要自己写一些它们的
645变种。比如,如果你需要计算一个数组的长度,使用这个宏
646
647 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
648
649类似的,如果你要计算某结构体成员的大小,使用
650
651 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
652
653还有可以做严格的类型检查的min()和max()宏,如果你需要可以使用它们。你可以自己看看
654那个头文件里还定义了什么你可以拿来用的东西,如果有定义的话,你就不应在你的代码里
655自己重新定义。
656
657
658 第十八章:编辑器模式行和其他需要罗嗦的事情
659
660有一些编辑器可以解释嵌入在源文件里的由一些特殊标记标明的配置信息。比如,emacs
661能够解释被标记成这样的行:
662
663-*- mode: c -*-
664
665或者这样的:
666
667/*
668Local Variables:
669compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
670End:
671*/
672
673Vim能够解释这样的标记:
674
675/* vim:set sw=8 noet */
676
677不要在源代码中包含任何这样的内容。每个人都有他自己的编辑器配置,你的源文件不应
678该覆盖别人的配置。这包括有关缩进和模式配置的标记。人们可以使用他们自己定制的模
679式,或者使用其他可以产生正确的缩进的巧妙方法。
680
681
682
683 附录 I:参考
684
685The C Programming Language, 第二版, 作者Brian W. Kernighan和Denni
686M. Ritchie. Prentice Hall, Inc., 1988. ISBN 0-13-110362-8 (软皮),
6870-13-110370-9 (硬皮). URL: http://cm.bell-labs.com/cm/cs/cbook/
688
689The Practice of Programming 作者Brian W. Kernighan和Rob Pike. Addison-Wesley,
690Inc., 1999. ISBN 0-201-61586-X. URL: http://cm.bell-labs.com/cm/cs/tpop/
691
692cpp,gcc,gcc internals和indent的GNU手册——和K&R及本文相符合的部分,全部可以在
693http://www.gnu.org/manual/找到
694
695WG14是C语言的国际标准化工作组,URL: http://www.open-std.org/JTC1/SC22/WG14/
696
697Kernel CodingStyle,作者greg@kroah.com发表于OLS 2002:
698http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
699
700--
701最后更新于2007年7月13日。
diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index 48fc67bfbe3d..3d80e8af36ec 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -1,10 +1,10 @@
1Chinese translated version of Documentation/HOWTO 1Chinese translated version of Documentation/HOWTO
2 2
3If you have any comment or update to the content, please contact the 3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have problem 4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for 5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer, if this translation is outdated 6help. Contact the Chinese maintainer if this translation is outdated
7or there is problem with translation. 7or if there is a problem with the translation.
8 8
9Maintainer: Greg Kroah-Hartman <greg@kroah.com> 9Maintainer: Greg Kroah-Hartman <greg@kroah.com>
10Chinese maintainer: Li Yang <leoli@freescale.com> 10Chinese maintainer: Li Yang <leoli@freescale.com>
@@ -85,7 +85,7 @@ Linux内核源代码都是在GPL(通用公共许可证)的保护下发布的
85Linux内核代码中包含有大量的文档。这些文档对于学习如何与内核社区互动有着 85Linux内核代码中包含有大量的文档。这些文档对于学习如何与内核社区互动有着
86不可估量的价值。当一个新的功能被加入内核,最好把解释如何使用这个功能的文 86不可估量的价值。当一个新的功能被加入内核,最好把解释如何使用这个功能的文
87档也放进内核。当内核的改动导致面向用户空间的接口发生变化时,最好将相关信 87档也放进内核。当内核的改动导致面向用户空间的接口发生变化时,最好将相关信
88息或手册页(manpages)的补丁发到mtk-manpages@gmx.net,以向手册页(manpages) 88息或手册页(manpages)的补丁发到mtk.manpages@gmail.com,以向手册页(manpages)
89的维护者解释这些变化。 89的维护者解释这些变化。
90 90
91以下是内核代码中需要阅读的文档: 91以下是内核代码中需要阅读的文档:
@@ -218,6 +218,8 @@ kernel.org网站的pub/linux/kernel/v2.6/目录下找到它。它的开发遵循
218 时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。 218 时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。
219 - 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是 219 - 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是
220 6个星期。 220 6个星期。
221 - 以下地址跟踪了在每个-rc发布中发现的退步列表:
222 http://kernelnewbies.org/known_regressions
221 223
222关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说: 224关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说:
223 “没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定 225 “没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定
diff --git a/Documentation/zh_CN/SubmittingDrivers b/Documentation/zh_CN/SubmittingDrivers
new file mode 100644
index 000000000000..5f4815c63ec7
--- /dev/null
+++ b/Documentation/zh_CN/SubmittingDrivers
@@ -0,0 +1,168 @@
1Chinese translated version of Documentation/SubmittingDrivers
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: Li Yang <leo@zh-kernel.org>
10---------------------------------------------------------------------
11Documentation/SubmittingDrivers 的中文翻译
12
13如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
14交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
15译存在问题,请联系中文版维护者。
16
17中文版维护者: 李阳 Li Yang <leo@zh-kernel.org>
18中文版翻译者: 李阳 Li Yang <leo@zh-kernel.org>
19中文版校译者: 陈琦 Maggie Chen <chenqi@beyondsoft.com>
20 王聪 Wang Cong <xiyou.wangcong@gmail.com>
21 张巍 Zhang Wei <Wei.Zhang@freescale.com>
22
23以下为正文
24---------------------------------------------------------------------
25
26如何向 Linux 内核提交驱动程序
27-----------------------------
28
29这篇文档将会解释如何向不同的内核源码树提交设备驱动程序。请注意,如果你感
30兴趣的是显卡驱动程序,你也许应该访问 XFree86 项目(http://www.xfree86.org/)
31和/或 X.org 项目 (http://x.org)。
32
33另请参阅 Documentation/SubmittingPatches 文档。
34
35
36分配设备号
37----------
38
39块设备和字符设备的主设备号与从设备号是由 Linux 命名编号分配权威 LANANA(
40现在是 Torben Mathiasen)负责分配。申请的网址是 http://www.lanana.org/。
41即使不准备提交到主流内核的设备驱动也需要在这里分配设备号。有关详细信息,
42请参阅 Documentation/devices.txt。
43
44如果你使用的不是已经分配的设备号,那么当你提交设备驱动的时候,它将会被强
45制分配一个新的设备号,即便这个设备号和你之前发给客户的截然不同。
46
47设备驱动的提交对象
48------------------
49
50Linux 2.0:
51 此内核源码树不接受新的驱动程序。
52
53Linux 2.2:
54 此内核源码树不接受新的驱动程序。
55
56Linux 2.4:
57 如果所属的代码领域在内核的 MAINTAINERS 文件中列有一个总维护者,
58 那么请将驱动程序提交给他。如果此维护者没有回应或者你找不到恰当的
59 维护者,那么请联系 Willy Tarreau <w@1wt.eu>。
60
61Linux 2.6:
62 除了遵循和 2.4 版内核同样的规则外,你还需要在 linux-kernel 邮件
63 列表上跟踪最新的 API 变化。向 Linux 2.6 内核提交驱动的顶级联系人
64 是 Andrew Morton <akpm@osdl.org>。
65
66决定设备驱动能否被接受的条件
67----------------------------
68
69许可: 代码必须使用 GNU 通用公开许可证 (GPL) 提交给 Linux,但是
70 我们并不要求 GPL 是唯一的许可。你或许会希望同时使用多种
71 许可证发布,如果希望驱动程序可以被其他开源社区(比如BSD)
72 使用。请参考 include/linux/module.h 文件中所列出的可被
73 接受共存的许可。
74
75版权: 版权所有者必须同意使用 GPL 许可。最好提交者和版权所有者
76 是相同个人或实体。否则,必需列出授权使用 GPL 的版权所有
77 人或实体,以备验证之需。
78
79接口: 如果你的驱动程序使用现成的接口并且和其他同类的驱动程序行
80 为相似,而不是去发明无谓的新接口,那么它将会更容易被接受。
81 如果你需要一个 Linux 和 NT 的通用驱动接口,那么请在用
82 户空间实现它。
83
84代码: 请使用 Documentation/CodingStyle 中所描述的 Linux 代码风
85 格。如果你的某些代码段(例如那些与 Windows 驱动程序包共
86 享的代码段)需要使用其他格式,而你却只希望维护一份代码,
87 那么请将它们很好地区分出来,并且注明原因。
88
89可移植性: 请注意,指针并不永远是 32 位的,不是所有的计算机都使用小
90 尾模式 (little endian) 存储数据,不是所有的人都拥有浮点
91 单元,不要随便在你的驱动程序里嵌入 x86 汇编指令。只能在
92 x86 上运行的驱动程序一般是不受欢迎的。虽然你可能只有 x86
93 硬件,很难测试驱动程序在其他平台上是否可用,但是确保代码
94 可以被轻松地移植却是很简单的。
95
96清晰度: 做到所有人都能修补这个驱动程序将会很有好处,因为这样你将
97 会直接收到修复的补丁而不是 bug 报告。如果你提交一个试图
98 隐藏硬件工作机理的驱动程序,那么它将会被扔进废纸篓。
99
100电源管理: 因为 Linux 正在被很多移动设备和桌面系统使用,所以你的驱
101 动程序也很有可能被使用在这些设备上。它应该支持最基本的电
102 源管理,即在需要的情况下实现系统级休眠和唤醒要用到的
103 .suspend 和 .resume 函数。你应该检查你的驱动程序是否能正
104 确地处理休眠与唤醒,如果实在无法确认,请至少把 .suspend
105 函数定义成返回 -ENOSYS(功能未实现)错误。你还应该尝试确
106 保你的驱动在什么都不干的情况下将耗电降到最低。要获得驱动
107 程序测试的指导,请参阅
108 Documentation/power/drivers-testing.txt。有关驱动程序电
109 源管理问题相对全面的概述,请参阅
110 Documentation/power/devices.txt。
111
112管理: 如果一个驱动程序的作者还在进行有效的维护,那么通常除了那
113 些明显正确且不需要任何检查的补丁以外,其他所有的补丁都会
114 被转发给作者。如果你希望成为驱动程序的联系人和更新者,最
115 好在代码注释中写明并且在 MAINTAINERS 文件中加入这个驱动
116 程序的条目。
117
118不影响设备驱动能否被接受的条件
119------------------------------
120
121供应商: 由硬件供应商来维护驱动程序通常是一件好事。不过,如果源码
122 树里已经有其他人提供了可稳定工作的驱动程序,那么请不要期
123 望“我是供应商”会成为内核改用你的驱动程序的理由。理想的情
124 况是:供应商与现有驱动程序的作者合作,构建一个统一完美的
125 驱动程序。
126
127作者: 驱动程序是由大的 Linux 公司研发还是由你个人编写,并不影
128 响其是否能被内核接受。没有人对内核源码树享有特权。只要你
129 充分了解内核社区,你就会发现这一点。
130
131
132资源列表
133--------
134
135Linux 内核主源码树:
136 ftp.??.kernel.org:/pub/linux/kernel/...
137 ?? == 你的国家代码,例如 "cn"、"us"、"uk"、"fr" 等等
138
139Linux 内核邮件列表:
140 linux-kernel@vger.kernel.org
141 [可通过向majordomo@vger.kernel.org发邮件来订阅]
142
143Linux 设备驱动程序,第三版(探讨 2.6.10 版内核):
144 http://lwn.net/Kernel/LDD3/ (免费版)
145
146LWN.net:
147 每周内核开发活动摘要 - http://lwn.net/
148 2.6 版中 API 的变更:
149 http://lwn.net/Articles/2.6-kernel-api/
150 将旧版内核的驱动程序移植到 2.6 版:
151 http://lwn.net/Articles/driver-porting/
152
153KernelTrap:
154 Linux 内核的最新动态以及开发者访谈
155 http://kerneltrap.org/
156
157内核新手(KernelNewbies):
158 为新的内核开发者提供文档和帮助
159 http://kernelnewbies.org/
160
161Linux USB项目:
162 http://www.linux-usb.org/
163
164写内核驱动的“不要”(Arjan van de Ven著):
165 http://www.fenrus.org/how-to-not-write-a-device-driver-paper.pdf
166
167内核清洁工 (Kernel Janitor):
168 http://janitor.kernelnewbies.org/
diff --git a/Documentation/zh_CN/SubmittingPatches b/Documentation/zh_CN/SubmittingPatches
new file mode 100644
index 000000000000..985c92e20b73
--- /dev/null
+++ b/Documentation/zh_CN/SubmittingPatches
@@ -0,0 +1,416 @@
1Chinese translated version of Documentation/SubmittingPatches
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: TripleX Chung <triplex@zh-kernel.org>
10---------------------------------------------------------------------
11Documentation/SubmittingPatches 的中文翻译
12
13如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
14交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
15译存在问题,请联系中文版维护者。
16
17中文版维护者: 钟宇 TripleX Chung <triplex@zh-kernel.org>
18中文版翻译者: 钟宇 TripleX Chung <triplex@zh-kernel.org>
19中文版校译者: 李阳 Li Yang <leo@zh-kernel.org>
20 王聪 Wang Cong <xiyou.wangcong@gmail.com>
21
22以下为正文
23---------------------------------------------------------------------
24
25 如何让你的改动进入内核
26 或者
27 获得亲爱的 Linus Torvalds 的关注和处理
28----------------------------------
29
30对于想要将改动提交到 Linux 内核的个人或者公司来说,如果不熟悉“规矩”,
31提交的流程会让人畏惧。本文档收集了一系列建议,这些建议可以大大的提高你
32的改动被接受的机会。
33阅读 Documentation/SubmitChecklist 来获得在提交代码前需要检查的项目的列
34表。如果你在提交一个驱动程序,那么同时阅读一下
35Documentation/SubmittingDrivers 。
36
37
38--------------------------
39第一节 - 创建并发送你的改动
40--------------------------
41
421) "diff -up"
43-----------
44
45使用 "diff -up" 或者 "diff -uprN" 来创建补丁。
46
47所有内核的改动,都是以补丁的形式呈现的,补丁由 diff(1) 生成。创建补丁的
48时候,要确认它是以 "unified diff" 格式创建的,这种格式由 diff(1) 的 '-u'
49参数生成。而且,请使用 '-p' 参数,那样会显示每个改动所在的C函数,使得
50产生的补丁容易读得多。补丁应该基于内核源代码树的根目录,而不是里边的任
51何子目录。
52为一个单独的文件创建补丁,一般来说这样做就够了:
53
54 SRCTREE= linux-2.6
55 MYFILE= drivers/net/mydriver.c
56
57 cd $SRCTREE
58 cp $MYFILE $MYFILE.orig
59 vi $MYFILE # make your change
60 cd ..
61 diff -up $SRCTREE/$MYFILE{.orig,} > /tmp/patch
62
63为多个文件创建补丁,你可以解开一个没有修改过的内核源代码树,然后和你自
64己的代码树之间做 diff 。例如:
65
66 MYSRC= /devel/linux-2.6
67
68 tar xvfz linux-2.6.12.tar.gz
69 mv linux-2.6.12 linux-2.6.12-vanilla
70 diff -uprN -X linux-2.6.12-vanilla/Documentation/dontdiff \
71 linux-2.6.12-vanilla $MYSRC > /tmp/patch
72
73"dontdiff" 是内核在编译的时候产生的文件的列表,列表中的文件在 diff(1)
74产生的补丁里会被跳过。"dontdiff" 文件被包含在2.6.12和之后版本的内核源代
75码树中。对于更早的内核版本,你可以从
76<http://www.xenotime.net/linux/doc/dontdiff> 获取它。
77确定你的补丁里没有包含任何不属于这次补丁提交的额外文件。记得在用diff(1)
78生成补丁之后,审阅一次补丁,以确保准确。
79如果你的改动很散乱,你应该研究一下如何将补丁分割成独立的部分,将改动分
80割成一系列合乎逻辑的步骤。这样更容易让其他内核开发者审核,如果你想你的
81补丁被接受,这是很重要的。下面这些脚本能够帮助你做这件事情:
82Quilt:
83http://savannah.nongnu.org/projects/quilt
84
85Andrew Morton 的补丁脚本:
86http://www.zip.com.au/~akpm/linux/patches/
87作为这些脚本的替代,quilt 是值得推荐的补丁管理工具(看上面的链接)。
88
892)描述你的改动。
90描述你的改动包含的技术细节。
91
92要多具体就写多具体。最糟糕的描述可能是像下面这些语句:“更新了某驱动程
93序”,“修正了某驱动程序的bug”,或者“这个补丁包含了某子系统的修改,请
94使用。”
95
96如果你的描述开始变长,这表示你也许需要拆分你的补丁了,请看第3小节,
97继续。
98
993)拆分你的改动
100
101将改动拆分,逻辑类似的放到同一个补丁文件里。
102
103例如,如果你的改动里同时有bug修正和性能优化,那么把这些改动才分到两个或
104者更多的补丁文件中。如果你的改动包含对API的修改,并且修改了驱动程序来适
105应这些新的API,那么把这些修改分成两个补丁。
106
107另一方面,如果你将一个单独的改动做成多个补丁文件,那么将它们合并成一个
108单独的补丁文件。这样一个逻辑上单独的改动只被包含在一个补丁文件里。
109
110如果有一个补丁依赖另外一个补丁来完成它的改动,那没问题。简单的在你的补
111丁描述里指出“这个补丁依赖某补丁”就好了。
112
113如果你不能将补丁浓缩成更少的文件,那么每次大约发送出15个,然后等待审查
114和整合。
115
1164)选择 e-mail 的收件人
117
118看一遍 MAINTAINERS 文件和源代码,看看你所的改动所在的内核子系统有没有指
119定的维护者。如果有,给他们发e-mail。
120
121如果没有找到维护者,或者维护者没有反馈,将你的补丁发送到内核开发者主邮
122件列表 linux-kernel@vger.kernel.org。大部分的内核开发者都跟踪这个邮件列
123表,可以评价你的改动。
124
125每次不要发送超过15个补丁到 vger 邮件列表!!!
126
127Linus Torvalds 是决定改动能否进入 Linux 内核的最终裁决者。他的 e-mail
128地址是 <torvalds@linux-foundation.org> 。他收到的 e-mail 很多,所以一般
129的说,最好别给他发 e-mail。
130
131那些修正bug,“显而易见”的修改或者是类似的只需要很少讨论的补丁可以直接
132发送或者CC给Linus。那些需要讨论或者没有很清楚的好处的补丁,一般先发送到
133linux-kernel邮件列表。只有当补丁被讨论得差不多了,才提交给Linus。
134
1355)选择CC( e-mail 抄送)列表
136
137除非你有理由不这样做,否则CC linux-kernel@vger.kernel.org。
138
139除了 Linus 之外,其他内核开发者也需要注意到你的改动,这样他们才能评论你
140的改动并提供代码审查和建议。linux-kernel 是 Linux 内核开发者主邮件列表
141。其它的邮件列表为特定的子系统提供服务,比如 USB,framebuffer 设备,虚
142拟文件系统,SCSI 子系统,等等。查看 MAINTAINERS 文件来获得和你的改动有
143关的邮件列表。
144
145Majordomo lists of VGER.KERNEL.ORG at:
146 <http://vger.kernel.org/vger-lists.html>
147
148如果改动影响了用户空间和内核之间的接口,请给 MAN-PAGES 的维护者(列在
149MAITAINERS 文件里的)发送一个手册页(man-pages)补丁,或者至少通知一下改
150变,让一些信息有途径进入手册页。
151
152即使在第四步的时候,维护者没有作出回应,也要确认在修改他们的代码的时候
153,一直将维护者拷贝到CC列表中。
154
155对于小的补丁,你也许会CC到 Adrian Bunk 管理的搜集琐碎补丁的邮件列表
156(Trivial Patch Monkey)trivial@kernel.org,那里专门收集琐碎的补丁。下面这样
157的补丁会被看作“琐碎的”补丁:
158 文档的拼写修正。
159 修正会影响到 grep(1) 的拼写。
160 警告信息修正(频繁的打印无用的警告是不好的。)
161 编译错误修正(代码逻辑的确是对的,只是编译有问题。)
162 运行时修正(只要真的修正了错误。)
163 移除使用了被废弃的函数/宏的代码(例如 check_region。)
164 联系方式和文档修正。
165 用可移植的代码替换不可移植的代码(即使在体系结构相关的代码中,既然有
166 人拷贝,只要它是琐碎的)
167 任何文件的作者/维护者对该文件的改动(例如 patch monkey 在重传模式下)
168
169URL: <http://www.kernel.org/pub/linux/kernel/people/bunk/trivial/>
170
171(译注,关于“琐碎补丁”的一些说明:因为原文的这一部分写得比较简单,所以不得不
172违例写一下译注。"trivial"这个英文单词的本意是“琐碎的,不重要的。”但是在这里
173有稍微有一些变化,例如对一些明显的NULL指针的修正,属于运行时修正,会被归类
174到琐碎补丁里。虽然NULL指针的修正很重要,但是这样的修正往往很小而且很容易得到
175检验,所以也被归入琐碎补丁。琐碎补丁更精确的归类应该是
176“simple, localized & easy to verify”,也就是说简单的,局部的和易于检验的。
177trivial@kernel.org邮件列表的目的是针对这样的补丁,为提交者提供一个中心,来
178降低提交的门槛。)
179
1806)没有 MIME 编码,没有链接,没有压缩,没有附件,只有纯文本。
181
182Linus 和其他的内核开发者需要阅读和评论你提交的改动。对于内核开发者来说
183,可以“引用”你的改动很重要,使用一般的 e-mail 工具,他们就可以在你的
184代码的任何位置添加评论。
185
186因为这个原因,所有的提交的补丁都是 e-mail 中“内嵌”的。
187警告:如果你使用剪切-粘贴你的补丁,小心你的编辑器的自动换行功能破坏你的
188补丁。
189
190不要将补丁作为 MIME 编码的附件,不管是否压缩。很多流行的 e-mail 软件不
191是任何时候都将 MIME 编码的附件当作纯文本发送的,这会使得别人无法在你的
192代码中加评论。另外,MIME 编码的附件会让 Linus 多花一点时间来处理,这就
193降低了你的改动被接受的可能性。
194
195警告:一些邮件软件,比如 Mozilla 会将你的信息以如下格式发送:
196---- 邮件头 ----
197Content-Type: text/plain; charset=us-ascii; format=flowed
198---- 邮件头 ----
199问题在于 “format=flowed” 会让接收端的某些邮件软件将邮件中的制表符替换
200成空格以及做一些类似的替换。这样,你发送的时候看起来没问题的补丁就被破
201坏了。
202
203要修正这个问题,只需要将你的 mozilla 的 defaults/pref/mailnews.js 文件
204里的
205pref("mailnews.send_plaintext_flowed", false); // RFC 2646=======
206修改成
207pref("mailnews.display.disable_format_flowed_support", true);
208就可以了。
209
2107) e-mail 的大小
211
212给 Linus 发送补丁的时候,永远按照第6小节说的做。
213
214大的改动对邮件列表不合适,对某些维护者也不合适。如果你的补丁,在不压缩
215的情况下,超过了40kB,那么你最好将补丁放在一个能通过 internet 访问的服
216务器上,然后用指向你的补丁的 URL 替代。
217
2188) 指出你的内核版本
219
220在标题和在补丁的描述中,指出补丁对应的内核的版本,是很重要的。
221
222如果补丁不能干净的在最新版本的内核上打上,Linus 是不会接受它的。
223
2249) 不要气馁,继续提交。
225
226当你提交了改动以后,耐心地等待。如果 Linus 喜欢你的改动并且同意它,那么
227它将在下一个内核发布版本中出现。
228
229然而,如果你的改动没有出现在下一个版本的内核中,可能有若干原因。减少那
230些原因,修正错误,重新提交更新后的改动,是你自己的工作。
231
232Linus不给出任何评论就“丢弃”你的补丁是常见的事情。在系统中这样的事情很
233平常。如果他没有接受你的补丁,也许是由于以下原本:
234* 你的补丁不能在最新版本的内核上干净的打上。
235* 你的补丁在 linux-kernel 邮件列表中没有得到充分的讨论。
236* 风格问题(参照第2小节)
237* 邮件格式问题(重读本节)
238* 你的改动有技术问题。
239* 他收到了成吨的 e-mail,而你的在混乱中丢失了。
240* 你让人为难。
241
242有疑问的时候,在 linux-kernel 邮件列表上请求评论。
243
24410) 在标题上加上 PATCH 的字样
245
246Linus 和 linux-kernel 邮件列表的 e-mail 流量都很高,一个通常的约定是标
247题行以 [PATCH] 开头。这样可以让 Linus 和其他内核开发人员可以从 e-mail
248的讨论中很轻易的将补丁分辨出来。
249
25011)为你的工作签名
251
252为了加强对谁做了何事的追踪,尤其是对那些透过好几层的维护者的补丁,我们
253建议在发送出去的补丁上加一个 “sign-off” 的过程。
254
255"sign-off" 是在补丁的注释的最后的简单的一行文字,认证你编写了它或者其他
256人有权力将它作为开放源代码的补丁传递。规则很简单:如果你能认证如下信息
257
258 开发者来源证书 1.1
259 对于本项目的贡献,我认证如下信息:
260 (a)这些贡献是完全或者部分的由我创建,我有权利以文件中指出
261 的开放源代码许可证提交它;或者
262 (b)这些贡献基于以前的工作,据我所知,这些以前的工作受恰当的开放
263 源代码许可证保护,而且,根据许可证,我有权提交修改后的贡献,
264 无论是完全还是部分由我创造,这些贡献都使用同一个开放源代码许可证
265 (除非我被允许用其它的许可证),正如文件中指出的;或者
266 (c)这些贡献由认证(a),(b)或者(c)的人直接提供给我,而
267 且我没有修改它。
268 (d)我理解并同意这个项目和贡献是公开的,贡献的记录(包括我
269 一起提交的个人记录,包括 sign-off )被永久维护并且可以和这个项目
270 或者开放源代码的许可证同步地再发行。
271 那么加入这样一行:
272 Signed-off-by: Random J Developer <random@developer.example.org>
273
274使用你的真名(抱歉,不能使用假名或者匿名。)
275
276有人在最后加上标签。现在这些东西会被忽略,但是你可以这样做,来标记公司
277内部的过程,或者只是指出关于 sign-off 的一些特殊细节。
278
27912)标准补丁格式
280
281标准的补丁,标题行是:
282 Subject: [PATCH 001/123] 子系统:一句话概述
283
284标准补丁的信体存在如下部分:
285
286 - 一个 "from" 行指出补丁作者。
287
288 - 一个空行
289
290 - 说明的主体,这些说明文字会被拷贝到描述该补丁的永久改动记录里。
291
292 - 一个由"---"构成的标记行
293
294 - 不合适放到改动记录里的额外的注解。
295
296 - 补丁本身(diff 输出)
297
298标题行的格式,使得对标题行按字母序排序非常的容易 - 很多 e-mail 客户端都
299可以支持 - 因为序列号是用零填充的,所以按数字排序和按字母排序是一样的。
300
301e-mail 标题中的“子系统”标识哪个内核子系统将被打补丁。
302
303e-mail 标题中的“一句话概述”扼要的描述 e-mail 中的补丁。“一句话概述”
304不应该是一个文件名。对于一个补丁系列(“补丁系列”指一系列的多个相关补
305丁),不要对每个补丁都使用同样的“一句话概述”。
306
307记住 e-mail 的“一句话概述”会成为该补丁的全局唯一标识。它会蔓延到 git
308的改动记录里。然后“一句话概述”会被用在开发者的讨论里,用来指代这个补
309丁。用户将希望通过 google 来搜索"一句话概述"来找到那些讨论这个补丁的文
310章。
311
312一些标题的例子:
313
314 Subject: [patch 2/5] ext2: improve scalability of bitmap searching
315 Subject: [PATCHv2 001/207] x86: fix eflags tracking
316
317"from" 行是信体里的最上面一行,具有如下格式:
318 From: Original Author <author@example.com>
319
320"from" 行指明在永久改动日志里,谁会被确认为作者。如果没有 "from" 行,那
321么邮件头里的 "From: " 行会被用来决定改动日志中的作者。
322
323说明的主题将会被提交到永久的源代码改动日志里,因此对那些早已经不记得和
324这个补丁相关的讨论细节的有能力的读者来说,是有意义的。
325
326"---" 标记行对于补丁处理工具要找到哪里是改动日志信息的结束,是不可缺少
327的。
328
329对于 "---" 标记之后的额外注解,一个好的用途就是用来写 diffstat,用来显
330示修改了什么文件和每个文件都增加和删除了多少行。diffstat 对于比较大的补
331丁特别有用。其余那些只是和时刻或者开发者相关的注解,不合适放到永久的改
332动日志里的,也应该放这里。
333使用 diffstat的选项 "-p 1 -w 70" 这样文件名就会从内核源代码树的目录开始
334,不会占用太宽的空间(很容易适合80列的宽度,也许会有一些缩进。)
335
336在后面的参考资料中能看到适当的补丁格式的更多细节。
337
338-------------------------------
339第二节 提示,建议和诀窍
340-------------------------------
341
342本节包含很多和提交到内核的代码有关的通常的"规则"。事情永远有例外...但是
343你必须真的有好的理由这样做。你可以把本节叫做Linus的计算机科学入门课。
344
3451) 读 Document/CodingStyle
346
347Nuff 说过,如果你的代码和这个偏离太多,那么它有可能会被拒绝,没有更多的
348审查,没有更多的评价。
349
3502) #ifdef 是丑陋的
351混杂了 ifdef 的代码难以阅读和维护。别这样做。作为替代,将你的 ifdef 放
352在头文件里,有条件地定义 "static inline" 函数,或者宏,在代码里用这些东
353西。让编译器把那些"空操作"优化掉。
354
355一个简单的例子,不好的代码:
356
357 dev = alloc_etherdev (sizeof(struct funky_private));
358 if (!dev)
359 return -ENODEV;
360 #ifdef CONFIG_NET_FUNKINESS
361 init_funky_net(dev);
362 #endif
363
364清理后的例子:
365
366(头文件里)
367 #ifndef CONFIG_NET_FUNKINESS
368 static inline void init_funky_net (struct net_device *d) {}
369 #endif
370
371(代码文件里)
372 dev = alloc_etherdev (sizeof(struct funky_private));
373 if (!dev)
374 return -ENODEV;
375 init_funky_net(dev);
376
3773) 'static inline' 比宏好
378
379Static inline 函数相比宏来说,是好得多的选择。Static inline 函数提供了
380类型安全,没有长度限制,没有格式限制,在 gcc 下开销和宏一样小。
381
382宏只在 static inline 函数不是最优的时候[在 fast paths 里有很少的独立的
383案例],或者不可能用 static inline 函数的时候[例如字符串分配]。
384应该用 'static inline' 而不是 'static __inline__', 'extern inline' 和
385'extern __inline__' 。
386
3874) 不要过度设计
388
389不要试图预计模糊的未来事情,这些事情也许有用也许没有用:"让事情尽可能的
390简单,而不是更简单"。
391
392----------------
393第三节 参考文献
394----------------
395
396Andrew Morton, "The perfect patch" (tpp).
397 <http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt>
398
399Jeff Garzik, "Linux kernel patch submission format".
400 <http://linux.yyz.us/patch-format.html>
401
402Greg Kroah-Hartman, "How to piss off a kernel subsystem maintainer".
403 <http://www.kroah.com/log/2005/03/31/>
404 <http://www.kroah.com/log/2005/07/08/>
405 <http://www.kroah.com/log/2005/10/19/>
406 <http://www.kroah.com/log/2006/01/11/>
407
408NO!!!! No more huge patch bombs to linux-kernel@vger.kernel.org people!
409 <http://marc.theaimsgroup.com/?l=linux-kernel&m=112112749912944&w=2>
410
411Kernel Documentation/CodingStyle:
412 <http://sosdg.org/~coywolf/lxr/source/Documentation/CodingStyle>
413
414Linus Torvalds's mail on the canonical patch format:
415 <http://lkml.org/lkml/2005/4/7/183>
416--
diff --git a/Documentation/zh_CN/oops-tracing.txt b/Documentation/zh_CN/oops-tracing.txt
new file mode 100644
index 000000000000..9312608ffb8d
--- /dev/null
+++ b/Documentation/zh_CN/oops-tracing.txt
@@ -0,0 +1,212 @@
1Chinese translated version of Documentation/oops-tracing.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: Dave Young <hidave.darkstar@gmail.com>
10---------------------------------------------------------------------
11Documentation/oops-tracing.txt 的中文翻译
12
13如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
14交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
15译存在问题,请联系中文版维护者。
16
17中文版维护者: 杨瑞 Dave Young <hidave.darkstar@gmail.com>
18中文版翻译者: 杨瑞 Dave Young <hidave.darkstar@gmail.com>
19中文版校译者: 李阳 Li Yang <leo@zh-kernel.org>
20 王聪 Wang Cong <xiyou.wangcong@gmail.com>
21
22以下为正文
23---------------------------------------------------------------------
24
25注意: ksymoops 在2.6中是没有用的。 请以原有格式使用Oops(来自dmesg,等等)。
26忽略任何这样那样关于“解码Oops”或者“通过ksymoops运行”的文档。 如果你贴出运行过
27ksymoops的来自2.6的Oops,人们只会让你重贴一次。
28
29快速总结
30-------------
31
32发现Oops并发送给看似相关的内核领域的维护者。别太担心对不上号。如果你不确定就发给
33和你所做的事情相关的代码的负责人。 如果可重现试着描述怎样重构。 那甚至比oops更有
34价值。
35
36如果你对于发送给谁一无所知, 发给linux-kernel@vger.kernel.org。感谢你帮助Linux
37尽可能地稳定。
38
39Oops在哪里?
40----------------------
41
42通常Oops文本由klogd从内核缓冲区里读取并传给syslogd,由syslogd写到syslog文件中,
43典型地是/var/log/messages(依赖于/etc/syslog.conf)。有时klogd崩溃了,这种情况下你
44能够运行dmesg > file来从内核缓冲区中读取数据并保存下来。 否则你可以
45cat /proc/kmsg > file, 然而你必须介入中止传输, kmsg是一个“永不结束的文件”。如
46果机器崩溃坏到你不能输入命令或者磁盘不可用那么你有三种选择:-
47
48(1) 手抄屏幕上的文本待机器重启后再输入计算机。 麻烦但如果没有针对崩溃的准备,
49这是仅有的选择。 另外,你可以用数码相机把屏幕拍下来-不太好,但比没有强。 如果信
50息滚动到了终端的上面,你会发现以高分辩率启动(比如,vga=791)会让你读到更多的文
51本。(注意:这需要vesafb,所以对‘早期’的oops没有帮助)
52
53(2)用串口终端启动(请参看Documentation/serial-console.txt),运行一个null
54modem到另一台机器并用你喜欢的通讯工具获取输出。Minicom工作地很好。
55
56(3)使用Kdump(请参看Documentation/kdump/kdump.txt),
57使用在Documentation/kdump/gdbmacros.txt中定义的dmesg gdb宏,从旧的内存中提取内核
58环形缓冲区。
59
60完整信息
61----------------
62
63注意:以下来自于Linus的邮件适用于2.4内核。 我因为历史原因保留了它,并且因为其中
64一些信息仍然适用。 特别注意的是,请忽略任何ksymoops的引用。
65
66From: Linus Torvalds <torvalds@osdl.org>
67
68怎样跟踪Oops.. [原发到linux-kernel的一封邮件]
69
70主要的窍门是有五年和这些烦人的oops消息打交道的经验;-)
71
72实际上,你有办法使它更简单。我有两个不同的方法:
73
74 gdb /usr/src/linux/vmlinux
75 gdb> disassemble <offending_function>
76
77那是发现问题的简单办法,至少如果bug报告做的好的情况下(象这个一样-运行ksymoops
78得到oops发生的函数及函数内的偏移)。
79
80哦,如果报告发生的内核以相同的编译器和相似的配置编译它会有帮助的。
81
82另一件要做的事是反汇编bug报告的“Code”部分:ksymoops也会用正确的工具来做这件事,
83但如果没有那些工具你可以写一个傻程序:
84
85 char str[] = "\xXX\xXX\xXX...";
86 main(){}
87
88并用gcc -g编译它然后执行“disassemble str”(XX部分是由Oops报告的值-你可以仅剪切
89粘贴并用“\x”替换空格-我就是这么做的,因为我懒得写程序自动做这一切)。
90
91另外,你可以用scripts/decodecode这个shell脚本。它的使用方法是:
92decodecode < oops.txt
93
94“Code”之后的十六进制字节可能(在某些架构上)有一些当前指令之前的指令字节以及
95当前和之后的指令字节
96
97Code: f9 0f 8d f9 00 00 00 8d 42 0c e8 dd 26 11 c7 a1 60 ea 2b f9 8b 50 08 a1
9864 ea 2b f9 8d 34 82 8b 1e 85 db 74 6d 8b 15 60 ea 2b f9 <8b> 43 04 39 42 54
997e 04 40 89 42 54 8b 43 04 3b 05 00 f6 52 c0
100
101最后,如果你想知道代码来自哪里,你可以:
102
103 cd /usr/src/linux
104 make fs/buffer.s # 或任何产生BUG的文件
105
106然后你会比gdb反汇编更清楚的知道发生了什么。
107
108现在,问题是把你所拥有的所有数据结合起来:C源码(关于它应该怎样的一般知识),
109汇编代码及其反汇编得到的代码(另外还有从“oops”消息得到的寄存器状态-对了解毁坏的
110指针有用,而且当你有了汇编代码你也能拿其它的寄存器和任何它们对应的C表达式做匹配
111)。
112
113实际上,你仅需看看哪里不匹配(这个例子是“Code”反汇编和编译器生成的代码不匹配)。
114然后你须要找出为什么不匹配。通常很简单-你看到代码使用了空指针然后你看代码想知道
115空指针是怎么出现的,还有检查它是否合法..
116
117现在,如果明白这是一项耗时的工作而且需要一丁点儿的专心,没错。这就是我为什么大多
118只是忽略那些没有符号表信息的崩溃报告的原因:简单的说太难查找了(我有一些
119程序用于在内核代码段中搜索特定的模式,而且有时我也已经能找出那些崩溃的地方,但是
120仅仅是找出正确的序列也确实需要相当扎实的内核知识)
121
122_有时_会发生这种情况,我仅看到崩溃中的反汇编代码序列, 然后我马上就明白问题出在
123哪里。这时我才意识到自己干这个工作已经太长时间了;-)
124
125 Linus
126
127
128---------------------------------------------------------------------------
129关于Oops跟踪的注解:
130
131为了帮助Linus和其它内核开发者,klogd纳入了大量的支持来处理保护错误。为了拥有对
132地址解析的完整支持至少应该使用1.3-pl3的sysklogd包。
133
134当保护错误发生时,klogd守护进程自动把内核日志信息中的重要地址翻译成它们相应的符
135号。
136
137klogd执行两种类型的地址解析。首先是静态翻译其次是动态翻译。静态翻译和ksymoops
138一样使用System.map文件。为了做静态翻译klogd守护进程必须在初始化时能找到system
139map文件。关于klogd怎样搜索map文件请参看klogd手册页。
140
141动态地址翻译在使用内核可装载模块时很重要。 因为内核模块的内存是从内核动态内存池
142里分配的,所以不管是模块开始位置还是模块中函数和符号的位置都不是固定的。
143
144内核支持允许程序决定装载哪些模块和它们在内存中位置的系统调用。使用这些系统调用
145klogd守护进程生成一张符号表用于调试发生在可装载模块中的保护错误。
146
147至少klogd会提供产生保护错误的模块名。还可有额外的符号信息供可装载模块开发者选择
148以从模块中输出符号信息。
149
150因为内核模块环境可能是动态的,所以必须有一种机制当模块环境发生改变时来通知klogd
151守护进程。 有一些可用的命令行选项允许klogd向当前执行中的守护进程发送信号,告知符
152号信息应该被刷新了。 更多信息请参看klogd手册页。
153
154sysklogd发布时包含一个补丁修改了modules-2.0.0包,无论何时一个模块装载或者卸载都
155会自动向klogd发送信号。打上这个补丁提供了必要的对调试发生于内核可装载模块的保护
156错误的无缝支持。
157
158以下是被klogd处理过的发生在可装载模块中的一个保护错误例子:
159---------------------------------------------------------------------------
160Aug 29 09:51:01 blizard kernel: Unable to handle kernel paging request at virtual address f15e97cc
161Aug 29 09:51:01 blizard kernel: current->tss.cr3 = 0062d000, %cr3 = 0062d000
162Aug 29 09:51:01 blizard kernel: *pde = 00000000
163Aug 29 09:51:01 blizard kernel: Oops: 0002
164Aug 29 09:51:01 blizard kernel: CPU: 0
165Aug 29 09:51:01 blizard kernel: EIP: 0010:[oops:_oops+16/3868]
166Aug 29 09:51:01 blizard kernel: EFLAGS: 00010212
167Aug 29 09:51:01 blizard kernel: eax: 315e97cc ebx: 003a6f80 ecx: 001be77b edx: 00237c0c
168Aug 29 09:51:01 blizard kernel: esi: 00000000 edi: bffffdb3 ebp: 00589f90 esp: 00589f8c
169Aug 29 09:51:01 blizard kernel: ds: 0018 es: 0018 fs: 002b gs: 002b ss: 0018
170Aug 29 09:51:01 blizard kernel: Process oops_test (pid: 3374, process nr: 21, stackpage=00589000)
171Aug 29 09:51:01 blizard kernel: Stack: 315e97cc 00589f98 0100b0b4 bffffed4 0012e38e 00240c64 003a6f80 00000001
172Aug 29 09:51:01 blizard kernel: 00000000 00237810 bfffff00 0010a7fa 00000003 00000001 00000000 bfffff00
173Aug 29 09:51:01 blizard kernel: bffffdb3 bffffed4 ffffffda 0000002b 0007002b 0000002b 0000002b 00000036
174Aug 29 09:51:01 blizard kernel: Call Trace: [oops:_oops_ioctl+48/80] [_sys_ioctl+254/272] [_system_call+82/128]
175Aug 29 09:51:01 blizard kernel: Code: c7 00 05 00 00 00 eb 08 90 90 90 90 90 90 90 90 89 ec 5d c3
176---------------------------------------------------------------------------
177
178Dr. G.W. Wettstein Oncology Research Div. Computing Facility
179Roger Maris Cancer Center INTERNET: greg@wind.rmcc.com
180820 4th St. N.
181Fargo, ND 58122
182Phone: 701-234-7556
183
184
185---------------------------------------------------------------------------
186受污染的内核
187
188一些oops报告在程序记数器之后包含字符串'Tainted: '。这表明内核已经被一些东西给污
189染了。 该字符串之后紧跟着一系列的位置敏感的字符,每个代表一个特定的污染值。
190
191 1:'G'如果所有装载的模块都有GPL或相容的许可证,'P'如果装载了任何的专有模块。
192没有模块MODULE_LICENSE或者带有insmod认为是与GPL不相容的的MODULE_LICENSE的模块被
193认定是专有的。
194
195 2:'F'如果有任何通过“insmod -f”被强制装载的模块,' '如果所有模块都被正常装载。
196
197 3:'S'如果oops发生在SMP内核中,运行于没有证明安全运行多处理器的硬件。 当前这种
198情况仅限于几种不支持SMP的速龙处理器。
199
200 4:'R'如果模块通过“insmod -f”被强制装载,' '如果所有模块都被正常装载。
201
202 5:'M'如果任何处理器报告了机器检查异常,' '如果没有发生机器检查异常。
203
204 6:'B'如果页释放函数发现了一个错误的页引用或者一些非预期的页标志。
205
206 7:'U'如果用户或者用户应用程序特别请求设置污染标志,否则' '。
207
208 8:'D'如果内核刚刚死掉,比如有OOPS或者BUG。
209
210使用'Tainted: '字符串的主要原因是要告诉内核调试者,这是否是一个干净的内核亦或发
211生了任何的不正常的事。污染是永久的:即使出错的模块已经被卸载了,污染值仍然存在,
212以表明内核不再值得信任。
diff --git a/Documentation/zh_CN/sparse.txt b/Documentation/zh_CN/sparse.txt
new file mode 100644
index 000000000000..75992a603ae3
--- /dev/null
+++ b/Documentation/zh_CN/sparse.txt
@@ -0,0 +1,100 @@
1Chinese translated version of Documentation/sparse.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: Li Yang <leo@zh-kernel.org>
10---------------------------------------------------------------------
11Documentation/sparse.txt 的中文翻译
12
13如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
14交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
15译存在问题,请联系中文版维护者。
16
17中文版维护者: 李阳 Li Yang <leo@zh-kernel.org>
18中文版翻译者: 李阳 Li Yang <leo@zh-kernel.org>
19
20
21以下为正文
22---------------------------------------------------------------------
23
24Copyright 2004 Linus Torvalds
25Copyright 2004 Pavel Machek <pavel@suse.cz>
26Copyright 2006 Bob Copeland <me@bobcopeland.com>
27
28使用 sparse 工具做类型检查
29~~~~~~~~~~~~~~~~~~~~~~~~~~
30
31"__bitwise" 是一种类型属性,所以你应该这样使用它:
32
33 typedef int __bitwise pm_request_t;
34
35 enum pm_request {
36 PM_SUSPEND = (__force pm_request_t) 1,
37 PM_RESUME = (__force pm_request_t) 2
38 };
39
40这样会使 PM_SUSPEND 和 PM_RESUME 成为位方式(bitwise)整数(使用"__force"
41是因为 sparse 会抱怨改变位方式的类型转换,但是这里我们确实需要强制进行转
42换)。而且因为所有枚举值都使用了相同的类型,这里的"enum pm_request"也将
43会使用那个类型做为底层实现。
44
45而且使用 gcc 编译的时候,所有的 __bitwise/__force 都会消失,最后在 gcc
46看来它们只不过是普通的整数。
47
48坦白来说,你并不需要使用枚举类型。上面那些实际都可以浓缩成一个特殊的"int
49__bitwise"类型。
50
51所以更简单的办法只要这样做:
52
53 typedef int __bitwise pm_request_t;
54
55 #define PM_SUSPEND ((__force pm_request_t) 1)
56 #define PM_RESUME ((__force pm_request_t) 2)
57
58现在你就有了严格的类型检查所需要的所有基础架构。
59
60一个小提醒:常数整数"0"是特殊的。你可以直接把常数零当作位方式整数使用而
61不用担心 sparse 会抱怨。这是因为"bitwise"(恰如其名)是用来确保不同位方
62式类型不会被弄混(小尾模式,大尾模式,cpu尾模式,或者其他),对他们来说
63常数"0"确实是特殊的。
64
65获取 sparse 工具
66~~~~~~~~~~~~~~~~
67
68你可以从 Sparse 的主页获取最新的发布版本:
69
70 http://www.kernel.org/pub/linux/kernel/people/josh/sparse/
71
72或者,你也可以使用 git 克隆最新的 sparse 开发版本:
73
74 git://git.kernel.org/pub/scm/linux/kernel/git/josh/sparse.git
75
76DaveJ 把每小时自动生成的 git 源码树 tar 包放在以下地址:
77
78 http://www.codemonkey.org.uk/projects/git-snapshots/sparse/
79
80一旦你下载了源码,只要以普通用户身份运行:
81
82 make
83 make install
84
85它将会被自动安装到你的 ~/bin 目录下。
86
87使用 sparse 工具
88~~~~~~~~~~~~~~~~
89
90用"make C=1"命令来编译内核,会对所有重新编译的 C 文件使用 sparse 工具。
91或者使用"make C=2"命令,无论文件是否被重新编译都会对其使用 sparse 工具。
92如果你已经编译了内核,用后一种方式可以很快地检查整个源码树。
93
94make 的可选变量 CHECKFLAGS 可以用来向 sparse 工具传递参数。编译系统会自
95动向 sparse 工具传递 -Wbitwise 参数。你可以定义 __CHECK_ENDIAN__ 来进行
96大小尾检查。
97
98 make C=2 CHECKFLAGS="-D__CHECK_ENDIAN__"
99
100这些检查默认都是被关闭的,因为他们通常会产生大量的警告。
diff --git a/Documentation/zh_CN/stable_kernel_rules.txt b/Documentation/zh_CN/stable_kernel_rules.txt
new file mode 100644
index 000000000000..b5b9b0ab02fd
--- /dev/null
+++ b/Documentation/zh_CN/stable_kernel_rules.txt
@@ -0,0 +1,66 @@
1Chinese translated version of Documentation/stable_kernel_rules.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: TripleX Chung <triplex@zh-kernel.org>
10---------------------------------------------------------------------
11Documentation/stable_kernel_rules.txt 的中文翻译
12
13如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
14交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
15译存在问题,请联系中文版维护者。
16
17
18中文版维护者: 钟宇 TripleX Chung <triplex@zh-kernel.org>
19中文版翻译者: 钟宇 TripleX Chung <triplex@zh-kernel.org>
20中文版校译者: 李阳 Li Yang <leo@zh-kernel.org>
21 Kangkai Yin <e12051@motorola.com>
22
23以下为正文
24---------------------------------------------------------------------
25
26关于Linux 2.6稳定版发布,所有你想知道的事情。
27
28关于哪些类型的补丁可以被接收进入稳定版代码树,哪些不可以的规则:
29
30 - 必须是显而易见的正确,并且经过测试的。
31 - 连同上下文,不能大于100行。
32 - 必须只修正一件事情。
33 - 必须修正了一个给大家带来麻烦的真正的bug(不是“这也许是一个问题...”
34 那样的东西)。
35 - 必须修正带来如下后果的问题:编译错误(对被标记为CONFIG_BROKEN的例外),
36 内核崩溃,挂起,数据损坏,真正的安全问题,或者一些类似“哦,这不
37 好”的问题。简短的说,就是一些致命的问题。
38 - 没有“理论上的竞争条件”,除非能给出竞争条件如何被利用的解释。
39 - 不能存在任何的“琐碎的”修正(拼写修正,去掉多余空格之类的)。
40 - 必须被相关子系统的维护者接受。
41 - 必须遵循Documentation/SubmittingPatches里的规则。
42
43向稳定版代码树提交补丁的过程:
44
45 - 在确认了补丁符合以上的规则后,将补丁发送到stable@kernel.org。
46 - 如果补丁被接受到队列里,发送者会收到一个ACK回复,如果没有被接受,收
47 到的是NAK回复。回复需要几天的时间,这取决于开发者的时间安排。
48 - 被接受的补丁会被加到稳定版本队列里,等待其他开发者的审查。
49 - 安全方面的补丁不要发到这个列表,应该发送到security@kernel.org。
50
51审查周期:
52
53 - 当稳定版的维护者决定开始一个审查周期,补丁将被发送到审查委员会,以
54 及被补丁影响的领域的维护者(除非提交者就是该领域的维护者)并且抄送
55 到linux-kernel邮件列表。
56 - 审查委员会有48小时的时间,用来决定给该补丁回复ACK还是NAK。
57 - 如果委员会中有成员拒绝这个补丁,或者linux-kernel列表上有人反对这个
58 补丁,并提出维护者和审查委员会之前没有意识到的问题,补丁会从队列中
59 丢弃。
60 - 在审查周期结束的时候,那些得到ACK回应的补丁将会被加入到最新的稳定版
61 发布中,一个新的稳定版发布就此产生。
62 - 安全性补丁将从内核安全小组那里直接接收到稳定版代码树中,而不是通过
63 通常的审查周期。请联系内核安全小组以获得关于这个过程的更多细节。
64
65审查委员会:
66 - 由一些自愿承担这项任务的内核开发者,和几个非志愿的组成。
diff --git a/Documentation/zh_CN/volatile-considered-harmful.txt b/Documentation/zh_CN/volatile-considered-harmful.txt
new file mode 100644
index 000000000000..ba8149d2233a
--- /dev/null
+++ b/Documentation/zh_CN/volatile-considered-harmful.txt
@@ -0,0 +1,113 @@
1Chinese translated version of Documentation/volatile-considered-harmful.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Maintainer: Jonathan Corbet <corbet@lwn.net>
10Chinese maintainer: Bryan Wu <bryan.wu@analog.com>
11---------------------------------------------------------------------
12Documentation/volatile-considered-harmful.txt 的中文翻译
13
14如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
15交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
16译存在问题,请联系中文版维护者。
17
18英文版维护者: Jonathan Corbet <corbet@lwn.net>
19中文版维护者: 伍鹏 Bryan Wu <bryan.wu@analog.com>
20中文版翻译者: 伍鹏 Bryan Wu <bryan.wu@analog.com>
21中文版校译者: 张汉辉 Eugene Teo <eugeneteo@kernel.sg>
22 杨瑞 Dave Young <hidave.darkstar@gmail.com>
23以下为正文
24---------------------------------------------------------------------
25
26为什么不应该使用“volatile”类型
27------------------------------
28
29C程序员通常认为volatile表示某个变量可以在当前执行的线程之外被改变;因此,在内核
30中用到共享数据结构时,常常会有C程序员喜欢使用volatile这类变量。换句话说,他们经
31常会把volatile类型看成某种简易的原子变量,当然它们不是。在内核中使用volatile几
32乎总是错误的;本文档将解释为什么这样。
33
34理解volatile的关键是知道它的目的是用来消除优化,实际上很少有人真正需要这样的应
35用。在内核中,程序员必须防止意外的并发访问破坏共享的数据结构,这其实是一个完全
36不同的任务。用来防止意外并发访问的保护措施,可以更加高效的避免大多数优化相关的
37问题。
38
39像volatile一样,内核提供了很多原语来保证并发访问时的数据安全(自旋锁, 互斥量,内
40存屏障等等),同样可以防止意外的优化。如果可以正确使用这些内核原语,那么就没有
41必要再使用volatile。如果仍然必须使用volatile,那么几乎可以肯定在代码的某处有一
42个bug。在正确设计的内核代码中,volatile能带来的仅仅是使事情变慢。
43
44思考一下这段典型的内核代码:
45
46 spin_lock(&the_lock);
47 do_something_on(&shared_data);
48 do_something_else_with(&shared_data);
49 spin_unlock(&the_lock);
50
51如果所有的代码都遵循加锁规则,当持有the_lock的时候,不可能意外的改变shared_data的
52值。任何可能访问该数据的其他代码都会在这个锁上等待。自旋锁原语跟内存屏障一样—— 它
53们显式的用来书写成这样 —— 意味着数据访问不会跨越它们而被优化。所以本来编译器认为
54它知道在shared_data里面将有什么,但是因为spin_lock()调用跟内存屏障一样,会强制编
55译器忘记它所知道的一切。那么在访问这些数据时不会有优化的问题。
56
57如果shared_data被声名为volatile,锁操作将仍然是必须的。就算我们知道没有其他人正在
58使用它,编译器也将被阻止优化对临界区内shared_data的访问。在锁有效的同时,
59shared_data不是volatile的。在处理共享数据的时候,适当的锁操作可以不再需要
60volatile —— 并且是有潜在危害的。
61
62volatile的存储类型最初是为那些内存映射的I/O寄存器而定义。在内核里,寄存器访问也应
63该被锁保护,但是人们也不希望编译器“优化”临界区内的寄存器访问。内核里I/O的内存访问
64是通过访问函数完成的;不赞成通过指针对I/O内存的直接访问,并且不是在所有体系架构上
65都能工作。那些访问函数正是为了防止意外优化而写的,因此,再说一次,volatile类型不
66是必需的。
67
68另一种引起用户可能使用volatile的情况是当处理器正忙着等待一个变量的值。正确执行一
69个忙等待的方法是:
70
71 while (my_variable != what_i_want)
72 cpu_relax();
73
74cpu_relax()调用会降低CPU的能量消耗或者让位于超线程双处理器;它也作为内存屏障一样出
75现,所以,再一次,volatile不是必需的。当然,忙等待一开始就是一种反常规的做法。
76
77在内核中,一些稀少的情况下volatile仍然是有意义的:
78
79 - 在一些体系架构的系统上,允许直接的I/0内存访问,那么前面提到的访问函数可以使用
80 volatile。基本上,每一个访问函数调用它自己都是一个小的临界区域并且保证了按照
81 程序员期望的那样发生访问操作。
82
83 - 某些会改变内存的内联汇编代码虽然没有什么其他明显的附作用,但是有被GCC删除的可
84 能性。在汇编声明中加上volatile关键字可以防止这种删除操作。
85
86 - Jiffies变量是一种特殊情况,虽然每次引用它的时候都可以有不同的值,但读jiffies
87 变量时不需要任何特殊的加锁保护。所以jiffies变量可以使用volatile,但是不赞成
88 其他跟jiffies相同类型变量使用volatile。Jiffies被认为是一种“愚蠢的遗留物"
89 (Linus的话)因为解决这个问题比保持现状要麻烦的多。
90
91 - 由于某些I/0设备可能会修改连续一致的内存,所以有时,指向连续一致内存的数据结构
92 的指针需要正确的使用volatile。网络适配器使用的环状缓存区正是这类情形的一个例
93 子,其中适配器用改变指针来表示哪些描述符已经处理过了。
94
95对于大多代码,上述几种可以使用volatile的情况都不适用。所以,使用volatile是一种
96bug并且需要对这样的代码额外仔细检查。那些试图使用volatile的开发人员需要退一步想想
97他们真正想实现的是什么。
98
99非常欢迎删除volatile变量的补丁 - 只要证明这些补丁完整的考虑了并发问题。
100
101注释
102----
103
104[1] http://lwn.net/Articles/233481/
105[2] http://lwn.net/Articles/233482/
106
107致谢
108----
109
110最初由Randy Dunlap推动并作初步研究
111由Jonathan Corbet撰写
112参考Satyam Sharma,Johannes Stezenbach,Jesper Juhl,Heikki Orsila,
113H. Peter Anvin,Philipp Hahn和Stefan Richter的意见改善了本档。
diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index 1533d3ecd7a0..f6f3689a86ee 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -195,7 +195,7 @@ static int leds_shutdown(struct sys_device *dev)
195} 195}
196 196
197static struct sysdev_class leds_sysclass = { 197static struct sysdev_class leds_sysclass = {
198 set_kset_name("leds"), 198 .name = "leds",
199 .shutdown = leds_shutdown, 199 .shutdown = leds_shutdown,
200 .suspend = leds_suspend, 200 .suspend = leds_suspend,
201 .resume = leds_resume, 201 .resume = leds_resume,
@@ -369,7 +369,7 @@ static int timer_resume(struct sys_device *dev)
369#endif 369#endif
370 370
371static struct sysdev_class timer_sysclass = { 371static struct sysdev_class timer_sysclass = {
372 set_kset_name("timer"), 372 .name = "timer",
373 .suspend = timer_suspend, 373 .suspend = timer_suspend,
374 .resume = timer_resume, 374 .resume = timer_resume,
375}; 375};
diff --git a/arch/arm/mach-integrator/integrator_ap.c b/arch/arm/mach-integrator/integrator_ap.c
index 72280754354d..df37e93c6fc9 100644
--- a/arch/arm/mach-integrator/integrator_ap.c
+++ b/arch/arm/mach-integrator/integrator_ap.c
@@ -214,7 +214,7 @@ static int irq_resume(struct sys_device *dev)
214#endif 214#endif
215 215
216static struct sysdev_class irq_class = { 216static struct sysdev_class irq_class = {
217 set_kset_name("irq"), 217 .name = "irq",
218 .suspend = irq_suspend, 218 .suspend = irq_suspend,
219 .resume = irq_resume, 219 .resume = irq_resume,
220}; 220};
diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 3bf01e28df33..d9805e3d9304 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -69,14 +69,14 @@ static unsigned int mpui1610_sleep_save[MPUI1610_SLEEP_SAVE_SIZE];
69 69
70static unsigned short enable_dyn_sleep = 1; 70static unsigned short enable_dyn_sleep = 1;
71 71
72static ssize_t omap_pm_sleep_while_idle_show(struct kset *kset, char *buf) 72static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
73 char *buf)
73{ 74{
74 return sprintf(buf, "%hu\n", enable_dyn_sleep); 75 return sprintf(buf, "%hu\n", enable_dyn_sleep);
75} 76}
76 77
77static ssize_t omap_pm_sleep_while_idle_store(struct kset *kset, 78static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr,
78 const char * buf, 79 const char * buf, size_t n)
79 size_t n)
80{ 80{
81 unsigned short value; 81 unsigned short value;
82 if (sscanf(buf, "%hu", &value) != 1 || 82 if (sscanf(buf, "%hu", &value) != 1 ||
@@ -88,16 +88,9 @@ static ssize_t omap_pm_sleep_while_idle_store(struct kset *kset,
88 return n; 88 return n;
89} 89}
90 90
91static struct subsys_attribute sleep_while_idle_attr = { 91static struct kobj_attribute sleep_while_idle_attr =
92 .attr = { 92 __ATTR(sleep_while_idle, 0644, idle_show, idle_store);
93 .name = __stringify(sleep_while_idle),
94 .mode = 0644,
95 },
96 .show = omap_pm_sleep_while_idle_show,
97 .store = omap_pm_sleep_while_idle_store,
98};
99 93
100extern struct kset power_subsys;
101static void (*omap_sram_idle)(void) = NULL; 94static void (*omap_sram_idle)(void) = NULL;
102static void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL; 95static void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL;
103 96
@@ -726,9 +719,9 @@ static int __init omap_pm_init(void)
726 omap_pm_init_proc(); 719 omap_pm_init_proc();
727#endif 720#endif
728 721
729 error = subsys_create_file(&power_subsys, &sleep_while_idle_attr); 722 error = sysfs_create_file(power_kobj, &sleep_while_idle_attr);
730 if (error) 723 if (error)
731 printk(KERN_ERR "subsys_create_file failed: %d\n", error); 724 printk(KERN_ERR "sysfs_create_file failed: %d\n", error);
732 725
733 if (cpu_is_omap16xx()) { 726 if (cpu_is_omap16xx()) {
734 /* configure LOW_PWR pin */ 727 /* configure LOW_PWR pin */
diff --git a/arch/arm/mach-pxa/cm-x270.c b/arch/arm/mach-pxa/cm-x270.c
index 177664ccb2e2..a16349272f54 100644
--- a/arch/arm/mach-pxa/cm-x270.c
+++ b/arch/arm/mach-pxa/cm-x270.c
@@ -566,7 +566,7 @@ static int cmx270_resume(struct sys_device *dev)
566} 566}
567 567
568static struct sysdev_class cmx270_pm_sysclass = { 568static struct sysdev_class cmx270_pm_sysclass = {
569 set_kset_name("pm"), 569 .name = "pm",
570 .resume = cmx270_resume, 570 .resume = cmx270_resume,
571 .suspend = cmx270_suspend, 571 .suspend = cmx270_suspend,
572}; 572};
diff --git a/arch/arm/mach-pxa/lpd270.c b/arch/arm/mach-pxa/lpd270.c
index 26116440a7c9..78ebad063cba 100644
--- a/arch/arm/mach-pxa/lpd270.c
+++ b/arch/arm/mach-pxa/lpd270.c
@@ -122,7 +122,7 @@ static int lpd270_irq_resume(struct sys_device *dev)
122} 122}
123 123
124static struct sysdev_class lpd270_irq_sysclass = { 124static struct sysdev_class lpd270_irq_sysclass = {
125 set_kset_name("cpld_irq"), 125 .name = "cpld_irq",
126 .resume = lpd270_irq_resume, 126 .resume = lpd270_irq_resume,
127}; 127};
128 128
diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
index 011a1a72b61c..1d3112dc629e 100644
--- a/arch/arm/mach-pxa/lubbock.c
+++ b/arch/arm/mach-pxa/lubbock.c
@@ -126,7 +126,7 @@ static int lubbock_irq_resume(struct sys_device *dev)
126} 126}
127 127
128static struct sysdev_class lubbock_irq_sysclass = { 128static struct sysdev_class lubbock_irq_sysclass = {
129 set_kset_name("cpld_irq"), 129 .name = "cpld_irq",
130 .resume = lubbock_irq_resume, 130 .resume = lubbock_irq_resume,
131}; 131};
132 132
diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index a4bc3483cbb3..41d8c6cea62b 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -120,7 +120,7 @@ static int mainstone_irq_resume(struct sys_device *dev)
120} 120}
121 121
122static struct sysdev_class mainstone_irq_sysclass = { 122static struct sysdev_class mainstone_irq_sysclass = {
123 set_kset_name("cpld_irq"), 123 .name = "cpld_irq",
124 .resume = mainstone_irq_resume, 124 .resume = mainstone_irq_resume,
125}; 125};
126 126
diff --git a/arch/arm/mach-s3c2410/s3c2410.c b/arch/arm/mach-s3c2410/s3c2410.c
index e580303cb0ab..0e7991940f81 100644
--- a/arch/arm/mach-s3c2410/s3c2410.c
+++ b/arch/arm/mach-s3c2410/s3c2410.c
@@ -100,7 +100,7 @@ void __init s3c2410_init_clocks(int xtal)
100} 100}
101 101
102struct sysdev_class s3c2410_sysclass = { 102struct sysdev_class s3c2410_sysclass = {
103 set_kset_name("s3c2410-core"), 103 .name = "s3c2410-core",
104}; 104};
105 105
106static struct sys_device s3c2410_sysdev = { 106static struct sys_device s3c2410_sysdev = {
diff --git a/arch/arm/mach-s3c2412/s3c2412.c b/arch/arm/mach-s3c2412/s3c2412.c
index 4f92a1562d77..265cd3f567a3 100644
--- a/arch/arm/mach-s3c2412/s3c2412.c
+++ b/arch/arm/mach-s3c2412/s3c2412.c
@@ -196,7 +196,7 @@ void __init s3c2412_init_clocks(int xtal)
196*/ 196*/
197 197
198struct sysdev_class s3c2412_sysclass = { 198struct sysdev_class s3c2412_sysclass = {
199 set_kset_name("s3c2412-core"), 199 .name = "s3c2412-core",
200}; 200};
201 201
202static int __init s3c2412_core_init(void) 202static int __init s3c2412_core_init(void)
diff --git a/arch/arm/mach-s3c2440/mach-osiris.c b/arch/arm/mach-s3c2440/mach-osiris.c
index c326983f4a8f..78af7664988b 100644
--- a/arch/arm/mach-s3c2440/mach-osiris.c
+++ b/arch/arm/mach-s3c2440/mach-osiris.c
@@ -312,7 +312,7 @@ static int osiris_pm_resume(struct sys_device *sd)
312#endif 312#endif
313 313
314static struct sysdev_class osiris_pm_sysclass = { 314static struct sysdev_class osiris_pm_sysclass = {
315 set_kset_name("mach-osiris"), 315 .name = "mach-osiris",
316 .suspend = osiris_pm_suspend, 316 .suspend = osiris_pm_suspend,
317 .resume = osiris_pm_resume, 317 .resume = osiris_pm_resume,
318}; 318};
diff --git a/arch/arm/mach-s3c2443/s3c2443.c b/arch/arm/mach-s3c2443/s3c2443.c
index 8d8117158d23..9ce490560af9 100644
--- a/arch/arm/mach-s3c2443/s3c2443.c
+++ b/arch/arm/mach-s3c2443/s3c2443.c
@@ -43,7 +43,7 @@ static struct map_desc s3c2443_iodesc[] __initdata = {
43}; 43};
44 44
45struct sysdev_class s3c2443_sysclass = { 45struct sysdev_class s3c2443_sysclass = {
46 set_kset_name("s3c2443-core"), 46 .name = "s3c2443-core",
47}; 47};
48 48
49static struct sys_device s3c2443_sysdev = { 49static struct sys_device s3c2443_sysdev = {
diff --git a/arch/arm/mach-sa1100/irq.c b/arch/arm/mach-sa1100/irq.c
index edf3347d9c5b..3dc17d7bf38e 100644
--- a/arch/arm/mach-sa1100/irq.c
+++ b/arch/arm/mach-sa1100/irq.c
@@ -283,7 +283,7 @@ static int sa1100irq_resume(struct sys_device *dev)
283} 283}
284 284
285static struct sysdev_class sa1100irq_sysclass = { 285static struct sysdev_class sa1100irq_sysclass = {
286 set_kset_name("sa11x0-irq"), 286 .name = "sa11x0-irq",
287 .suspend = sa1100irq_suspend, 287 .suspend = sa1100irq_suspend,
288 .resume = sa1100irq_resume, 288 .resume = sa1100irq_resume,
289}; 289};
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index a9de727c9327..0a5cf3a6438b 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -96,7 +96,7 @@ static int op_arm_resume(struct sys_device *dev)
96} 96}
97 97
98static struct sysdev_class oprofile_sysclass = { 98static struct sysdev_class oprofile_sysclass = {
99 set_kset_name("oprofile"), 99 .name = "oprofile",
100 .resume = op_arm_resume, 100 .resume = op_arm_resume,
101 .suspend = op_arm_suspend, 101 .suspend = op_arm_suspend,
102}; 102};
diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c
index 6097753394ad..b2a87b8ef673 100644
--- a/arch/arm/plat-omap/gpio.c
+++ b/arch/arm/plat-omap/gpio.c
@@ -1455,7 +1455,7 @@ static int omap_gpio_resume(struct sys_device *dev)
1455} 1455}
1456 1456
1457static struct sysdev_class omap_gpio_sysclass = { 1457static struct sysdev_class omap_gpio_sysclass = {
1458 set_kset_name("gpio"), 1458 .name = "gpio",
1459 .suspend = omap_gpio_suspend, 1459 .suspend = omap_gpio_suspend,
1460 .resume = omap_gpio_resume, 1460 .resume = omap_gpio_resume,
1461}; 1461};
diff --git a/arch/arm/plat-s3c24xx/dma.c b/arch/arm/plat-s3c24xx/dma.c
index 29696e46ed65..aae1b9cbaf44 100644
--- a/arch/arm/plat-s3c24xx/dma.c
+++ b/arch/arm/plat-s3c24xx/dma.c
@@ -1265,7 +1265,7 @@ static int s3c2410_dma_resume(struct sys_device *dev)
1265#endif /* CONFIG_PM */ 1265#endif /* CONFIG_PM */
1266 1266
1267struct sysdev_class dma_sysclass = { 1267struct sysdev_class dma_sysclass = {
1268 set_kset_name("s3c24xx-dma"), 1268 .name = "s3c24xx-dma",
1269 .suspend = s3c2410_dma_suspend, 1269 .suspend = s3c2410_dma_suspend,
1270 .resume = s3c2410_dma_resume, 1270 .resume = s3c2410_dma_resume,
1271}; 1271};
diff --git a/arch/arm/plat-s3c24xx/s3c244x.c b/arch/arm/plat-s3c24xx/s3c244x.c
index 3444b13afac5..f197bb3a2366 100644
--- a/arch/arm/plat-s3c24xx/s3c244x.c
+++ b/arch/arm/plat-s3c24xx/s3c244x.c
@@ -151,13 +151,13 @@ static int s3c244x_resume(struct sys_device *dev)
151/* Since the S3C2442 and S3C2440 share items, put both sysclasses here */ 151/* Since the S3C2442 and S3C2440 share items, put both sysclasses here */
152 152
153struct sysdev_class s3c2440_sysclass = { 153struct sysdev_class s3c2440_sysclass = {
154 set_kset_name("s3c2440-core"), 154 .name = "s3c2440-core",
155 .suspend = s3c244x_suspend, 155 .suspend = s3c244x_suspend,
156 .resume = s3c244x_resume 156 .resume = s3c244x_resume
157}; 157};
158 158
159struct sysdev_class s3c2442_sysclass = { 159struct sysdev_class s3c2442_sysclass = {
160 set_kset_name("s3c2442-core"), 160 .name = "s3c2442-core",
161 .suspend = s3c244x_suspend, 161 .suspend = s3c244x_suspend,
162 .resume = s3c244x_resume 162 .resume = s3c244x_resume
163}; 163};
diff --git a/arch/avr32/kernel/time.c b/arch/avr32/kernel/time.c
index 7014a3571ec0..36a46c3ae308 100644
--- a/arch/avr32/kernel/time.c
+++ b/arch/avr32/kernel/time.c
@@ -214,7 +214,7 @@ void __init time_init(void)
214} 214}
215 215
216static struct sysdev_class timer_class = { 216static struct sysdev_class timer_class = {
217 set_kset_name("timer"), 217 .name = "timer",
218}; 218};
219 219
220static struct sys_device timer_device = { 220static struct sys_device timer_device = {
diff --git a/arch/cris/arch-v32/drivers/iop_fw_load.c b/arch/cris/arch-v32/drivers/iop_fw_load.c
index 11f9895ded50..f4bdc1dfa320 100644
--- a/arch/cris/arch-v32/drivers/iop_fw_load.c
+++ b/arch/cris/arch-v32/drivers/iop_fw_load.c
@@ -20,6 +20,9 @@
20 20
21#define IOP_TIMEOUT 100 21#define IOP_TIMEOUT 100
22 22
23#error "This driver is broken with regard to its driver core usage."
24#error "Please contact <greg@kroah.com> for details on how to fix it properly."
25
23static struct device iop_spu_device[2] = { 26static struct device iop_spu_device[2] = {
24 { .bus_id = "iop-spu0", }, 27 { .bus_id = "iop-spu0", },
25 { .bus_id = "iop-spu1", }, 28 { .bus_id = "iop-spu1", },
@@ -192,6 +195,13 @@ int iop_start_mpu(unsigned int start_addr)
192 195
193static int __init iop_fw_load_init(void) 196static int __init iop_fw_load_init(void)
194{ 197{
198#if 0
199 /*
200 * static struct devices can not be added directly to sysfs by ignoring
201 * the driver model infrastructure. To fix this properly, please use
202 * the platform_bus to register these devices to be able to properly
203 * use the firmware infrastructure.
204 */
195 device_initialize(&iop_spu_device[0]); 205 device_initialize(&iop_spu_device[0]);
196 kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0"); 206 kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0");
197 kobject_add(&iop_spu_device[0].kobj); 207 kobject_add(&iop_spu_device[0].kobj);
@@ -201,6 +211,7 @@ static int __init iop_fw_load_init(void)
201 device_initialize(&iop_mpu_device); 211 device_initialize(&iop_mpu_device);
202 kobject_set_name(&iop_mpu_device.kobj, "iop-mpu"); 212 kobject_set_name(&iop_mpu_device.kobj, "iop-mpu");
203 kobject_add(&iop_mpu_device.kobj); 213 kobject_add(&iop_mpu_device.kobj);
214#endif
204 return 0; 215 return 0;
205} 216}
206 217
diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index 14261fee5f4d..a2484fc1a06c 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -354,27 +354,27 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
354 if (unlikely(retval < 0)) 354 if (unlikely(retval < 0))
355 return retval; 355 return retval;
356 356
357 all_cpu_cache_info[cpu].kobj.parent = &sys_dev->kobj; 357 retval = kobject_init_and_add(&all_cpu_cache_info[cpu].kobj,
358 kobject_set_name(&all_cpu_cache_info[cpu].kobj, "%s", "cache"); 358 &cache_ktype_percpu_entry, &sys_dev->kobj,
359 all_cpu_cache_info[cpu].kobj.ktype = &cache_ktype_percpu_entry; 359 "%s", "cache");
360 retval = kobject_register(&all_cpu_cache_info[cpu].kobj);
361 360
362 for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) { 361 for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) {
363 this_object = LEAF_KOBJECT_PTR(cpu,i); 362 this_object = LEAF_KOBJECT_PTR(cpu,i);
364 this_object->kobj.parent = &all_cpu_cache_info[cpu].kobj; 363 retval = kobject_init_and_add(&(this_object->kobj),
365 kobject_set_name(&(this_object->kobj), "index%1lu", i); 364 &cache_ktype,
366 this_object->kobj.ktype = &cache_ktype; 365 &all_cpu_cache_info[cpu].kobj,
367 retval = kobject_register(&(this_object->kobj)); 366 "index%1lu", i);
368 if (unlikely(retval)) { 367 if (unlikely(retval)) {
369 for (j = 0; j < i; j++) { 368 for (j = 0; j < i; j++) {
370 kobject_unregister( 369 kobject_put(&(LEAF_KOBJECT_PTR(cpu,j)->kobj));
371 &(LEAF_KOBJECT_PTR(cpu,j)->kobj));
372 } 370 }
373 kobject_unregister(&all_cpu_cache_info[cpu].kobj); 371 kobject_put(&all_cpu_cache_info[cpu].kobj);
374 cpu_cache_sysfs_exit(cpu); 372 cpu_cache_sysfs_exit(cpu);
375 break; 373 break;
376 } 374 }
375 kobject_uevent(&(this_object->kobj), KOBJ_ADD);
377 } 376 }
377 kobject_uevent(&all_cpu_cache_info[cpu].kobj, KOBJ_ADD);
378 return retval; 378 return retval;
379} 379}
380 380
@@ -385,10 +385,10 @@ static int __cpuinit cache_remove_dev(struct sys_device * sys_dev)
385 unsigned long i; 385 unsigned long i;
386 386
387 for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) 387 for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++)
388 kobject_unregister(&(LEAF_KOBJECT_PTR(cpu,i)->kobj)); 388 kobject_put(&(LEAF_KOBJECT_PTR(cpu,i)->kobj));
389 389
390 if (all_cpu_cache_info[cpu].kobj.parent) { 390 if (all_cpu_cache_info[cpu].kobj.parent) {
391 kobject_unregister(&all_cpu_cache_info[cpu].kobj); 391 kobject_put(&all_cpu_cache_info[cpu].kobj);
392 memset(&all_cpu_cache_info[cpu].kobj, 392 memset(&all_cpu_cache_info[cpu].kobj,
393 0, 393 0,
394 sizeof(struct kobject)); 394 sizeof(struct kobject));
diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
index 471013577108..197d7977de35 100644
--- a/arch/mips/kernel/i8259.c
+++ b/arch/mips/kernel/i8259.c
@@ -238,7 +238,7 @@ static int i8259A_shutdown(struct sys_device *dev)
238} 238}
239 239
240static struct sysdev_class i8259_sysdev_class = { 240static struct sysdev_class i8259_sysdev_class = {
241 set_kset_name("i8259"), 241 .name = "i8259",
242 .resume = i8259A_resume, 242 .resume = i8259A_resume,
243 .shutdown = i8259A_shutdown, 243 .shutdown = i8259A_shutdown,
244}; 244};
diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
index c83c3e3f5178..a08862203643 100644
--- a/arch/powerpc/platforms/cell/spu_base.c
+++ b/arch/powerpc/platforms/cell/spu_base.c
@@ -459,7 +459,7 @@ static int spu_shutdown(struct sys_device *sysdev)
459} 459}
460 460
461static struct sysdev_class spu_sysdev_class = { 461static struct sysdev_class spu_sysdev_class = {
462 set_kset_name("spu"), 462 .name = "spu",
463 .shutdown = spu_shutdown, 463 .shutdown = spu_shutdown,
464}; 464};
465 465
diff --git a/arch/powerpc/platforms/powermac/pic.c b/arch/powerpc/platforms/powermac/pic.c
index 999f5e160897..84c0d4ef76a2 100644
--- a/arch/powerpc/platforms/powermac/pic.c
+++ b/arch/powerpc/platforms/powermac/pic.c
@@ -663,7 +663,7 @@ static int pmacpic_resume(struct sys_device *sysdev)
663#endif /* CONFIG_PM && CONFIG_PPC32 */ 663#endif /* CONFIG_PM && CONFIG_PPC32 */
664 664
665static struct sysdev_class pmacpic_sysclass = { 665static struct sysdev_class pmacpic_sysclass = {
666 set_kset_name("pmac_pic"), 666 .name = "pmac_pic",
667}; 667};
668 668
669static struct sys_device device_pmacpic = { 669static struct sys_device device_pmacpic = {
diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index 73e69023d90a..e95fc1594c84 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -28,13 +28,15 @@
28 28
29unsigned long rtas_poweron_auto; /* default and normal state is 0 */ 29unsigned long rtas_poweron_auto; /* default and normal state is 0 */
30 30
31static ssize_t auto_poweron_show(struct kset *kset, char *buf) 31static ssize_t auto_poweron_show(struct kobject *kobj,
32 struct kobj_attribute *attr, char *buf)
32{ 33{
33 return sprintf(buf, "%lu\n", rtas_poweron_auto); 34 return sprintf(buf, "%lu\n", rtas_poweron_auto);
34} 35}
35 36
36static ssize_t 37static ssize_t auto_poweron_store(struct kobject *kobj,
37auto_poweron_store(struct kset *kset, const char *buf, size_t n) 38 struct kobj_attribute *attr,
39 const char *buf, size_t n)
38{ 40{
39 int ret; 41 int ret;
40 unsigned long ups_restart; 42 unsigned long ups_restart;
@@ -47,17 +49,11 @@ auto_poweron_store(struct kset *kset, const char *buf, size_t n)
47 return -EINVAL; 49 return -EINVAL;
48} 50}
49 51
50static struct subsys_attribute auto_poweron_attr = { 52static struct kobj_attribute auto_poweron_attr =
51 .attr = { 53 __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);
52 .name = __stringify(auto_poweron),
53 .mode = 0644,
54 },
55 .show = auto_poweron_show,
56 .store = auto_poweron_store,
57};
58 54
59#ifndef CONFIG_PM 55#ifndef CONFIG_PM
60decl_subsys(power,NULL,NULL); 56struct kobject *power_kobj;
61 57
62static struct attribute *g[] = { 58static struct attribute *g[] = {
63 &auto_poweron_attr.attr, 59 &auto_poweron_attr.attr,
@@ -70,18 +66,16 @@ static struct attribute_group attr_group = {
70 66
71static int __init pm_init(void) 67static int __init pm_init(void)
72{ 68{
73 int error = subsystem_register(&power_subsys); 69 power_kobj = kobject_create_and_add("power", NULL);
74 if (!error) 70 if (!power_kobj)
75 error = sysfs_create_group(&power_subsys.kobj, &attr_group); 71 return -ENOMEM;
76 return error; 72 return sysfs_create_group(power_kobj, &attr_group);
77} 73}
78core_initcall(pm_init); 74core_initcall(pm_init);
79#else 75#else
80extern struct kset power_subsys;
81
82static int __init apo_pm_init(void) 76static int __init apo_pm_init(void)
83{ 77{
84 return (subsys_create_file(&power_subsys, &auto_poweron_attr)); 78 return (sysfs_create_file(power_kobj, &auto_poweron_attr));
85} 79}
86__initcall(apo_pm_init); 80__initcall(apo_pm_init);
87#endif 81#endif
diff --git a/arch/powerpc/sysdev/ipic.c b/arch/powerpc/sysdev/ipic.c
index 05a56e55804c..e898ff4d2b97 100644
--- a/arch/powerpc/sysdev/ipic.c
+++ b/arch/powerpc/sysdev/ipic.c
@@ -725,7 +725,7 @@ unsigned int ipic_get_irq(void)
725} 725}
726 726
727static struct sysdev_class ipic_sysclass = { 727static struct sysdev_class ipic_sysclass = {
728 set_kset_name("ipic"), 728 .name = "ipic",
729}; 729};
730 730
731static struct sys_device device_ipic = { 731static struct sys_device device_ipic = {
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index e47938899a92..212a94f5d34b 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1584,7 +1584,7 @@ static struct sysdev_class mpic_sysclass = {
1584 .resume = mpic_resume, 1584 .resume = mpic_resume,
1585 .suspend = mpic_suspend, 1585 .suspend = mpic_suspend,
1586#endif 1586#endif
1587 set_kset_name("mpic"), 1587 .name = "mpic",
1588}; 1588};
1589 1589
1590static int mpic_init_sys(void) 1590static int mpic_init_sys(void)
diff --git a/arch/powerpc/sysdev/qe_lib/qe_ic.c b/arch/powerpc/sysdev/qe_lib/qe_ic.c
index e1c0fd6dbc1a..f59444d3be75 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_ic.c
+++ b/arch/powerpc/sysdev/qe_lib/qe_ic.c
@@ -483,7 +483,7 @@ int qe_ic_set_high_priority(unsigned int virq, unsigned int priority, int high)
483} 483}
484 484
485static struct sysdev_class qe_ic_sysclass = { 485static struct sysdev_class qe_ic_sysclass = {
486 set_kset_name("qe_ic"), 486 .name = "qe_ic",
487}; 487};
488 488
489static struct sys_device device_qe_ic = { 489static struct sys_device device_qe_ic = {
diff --git a/arch/ppc/syslib/ipic.c b/arch/ppc/syslib/ipic.c
index 9192777d0f78..4f163e20939e 100644
--- a/arch/ppc/syslib/ipic.c
+++ b/arch/ppc/syslib/ipic.c
@@ -614,7 +614,7 @@ int ipic_get_irq(void)
614} 614}
615 615
616static struct sysdev_class ipic_sysclass = { 616static struct sysdev_class ipic_sysclass = {
617 set_kset_name("ipic"), 617 .name = "ipic",
618}; 618};
619 619
620static struct sys_device device_ipic = { 620static struct sys_device device_ipic = {
diff --git a/arch/ppc/syslib/open_pic.c b/arch/ppc/syslib/open_pic.c
index 18ec94733293..da36522d327a 100644
--- a/arch/ppc/syslib/open_pic.c
+++ b/arch/ppc/syslib/open_pic.c
@@ -1043,7 +1043,7 @@ int openpic_resume(struct sys_device *sysdev)
1043#endif /* CONFIG_PM */ 1043#endif /* CONFIG_PM */
1044 1044
1045static struct sysdev_class openpic_sysclass = { 1045static struct sysdev_class openpic_sysclass = {
1046 set_kset_name("openpic"), 1046 .name = "openpic",
1047}; 1047};
1048 1048
1049static struct sys_device device_openpic = { 1049static struct sys_device device_openpic = {
diff --git a/arch/ppc/syslib/open_pic2.c b/arch/ppc/syslib/open_pic2.c
index d585207f9f77..449075a04798 100644
--- a/arch/ppc/syslib/open_pic2.c
+++ b/arch/ppc/syslib/open_pic2.c
@@ -666,7 +666,7 @@ int openpic2_resume(struct sys_device *sysdev)
666 666
667/* HACK ALERT */ 667/* HACK ALERT */
668static struct sysdev_class openpic2_sysclass = { 668static struct sysdev_class openpic2_sysclass = {
669 set_kset_name("openpic2"), 669 .name = "openpic2",
670}; 670};
671 671
672static struct sys_device device_openpic2 = { 672static struct sys_device device_openpic2 = {
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 512669691ad0..46c97058ebe1 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -6,6 +6,7 @@
6 * s390 Version: 6 * s390 Version:
7 * Copyright IBM Corp. 2005,2007 7 * Copyright IBM Corp. 2005,2007
8 * Author(s): Jan Glauber (jang@de.ibm.com) 8 * Author(s): Jan Glauber (jang@de.ibm.com)
9 * Sebastian Siewior (sebastian@breakpoint.cc> SW-Fallback
9 * 10 *
10 * Derived from "crypto/aes_generic.c" 11 * Derived from "crypto/aes_generic.c"
11 * 12 *
@@ -16,17 +17,13 @@
16 * 17 *
17 */ 18 */
18 19
20#include <crypto/aes.h>
19#include <crypto/algapi.h> 21#include <crypto/algapi.h>
22#include <linux/err.h>
20#include <linux/module.h> 23#include <linux/module.h>
21#include <linux/init.h> 24#include <linux/init.h>
22#include "crypt_s390.h" 25#include "crypt_s390.h"
23 26
24#define AES_MIN_KEY_SIZE 16
25#define AES_MAX_KEY_SIZE 32
26
27/* data block size for all key lengths */
28#define AES_BLOCK_SIZE 16
29
30#define AES_KEYLEN_128 1 27#define AES_KEYLEN_128 1
31#define AES_KEYLEN_192 2 28#define AES_KEYLEN_192 2
32#define AES_KEYLEN_256 4 29#define AES_KEYLEN_256 4
@@ -39,45 +36,89 @@ struct s390_aes_ctx {
39 long enc; 36 long enc;
40 long dec; 37 long dec;
41 int key_len; 38 int key_len;
39 union {
40 struct crypto_blkcipher *blk;
41 struct crypto_cipher *cip;
42 } fallback;
42}; 43};
43 44
44static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 45/*
45 unsigned int key_len) 46 * Check if the key_len is supported by the HW.
47 * Returns 0 if it is, a positive number if it is not and software fallback is
48 * required or a negative number in case the key size is not valid
49 */
50static int need_fallback(unsigned int key_len)
46{ 51{
47 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
48 u32 *flags = &tfm->crt_flags;
49
50 switch (key_len) { 52 switch (key_len) {
51 case 16: 53 case 16:
52 if (!(keylen_flag & AES_KEYLEN_128)) 54 if (!(keylen_flag & AES_KEYLEN_128))
53 goto fail; 55 return 1;
54 break; 56 break;
55 case 24: 57 case 24:
56 if (!(keylen_flag & AES_KEYLEN_192)) 58 if (!(keylen_flag & AES_KEYLEN_192))
57 goto fail; 59 return 1;
58
59 break; 60 break;
60 case 32: 61 case 32:
61 if (!(keylen_flag & AES_KEYLEN_256)) 62 if (!(keylen_flag & AES_KEYLEN_256))
62 goto fail; 63 return 1;
63 break; 64 break;
64 default: 65 default:
65 goto fail; 66 return -1;
66 break; 67 break;
67 } 68 }
69 return 0;
70}
71
72static int setkey_fallback_cip(struct crypto_tfm *tfm, const u8 *in_key,
73 unsigned int key_len)
74{
75 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
76 int ret;
77
78 sctx->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK;
79 sctx->fallback.blk->base.crt_flags |= (tfm->crt_flags &
80 CRYPTO_TFM_REQ_MASK);
81
82 ret = crypto_cipher_setkey(sctx->fallback.cip, in_key, key_len);
83 if (ret) {
84 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
85 tfm->crt_flags |= (sctx->fallback.blk->base.crt_flags &
86 CRYPTO_TFM_RES_MASK);
87 }
88 return ret;
89}
90
91static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
92 unsigned int key_len)
93{
94 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
95 u32 *flags = &tfm->crt_flags;
96 int ret;
97
98 ret = need_fallback(key_len);
99 if (ret < 0) {
100 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
101 return -EINVAL;
102 }
68 103
69 sctx->key_len = key_len; 104 sctx->key_len = key_len;
70 memcpy(sctx->key, in_key, key_len); 105 if (!ret) {
71 return 0; 106 memcpy(sctx->key, in_key, key_len);
72fail: 107 return 0;
73 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 108 }
74 return -EINVAL; 109
110 return setkey_fallback_cip(tfm, in_key, key_len);
75} 111}
76 112
77static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 113static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
78{ 114{
79 const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); 115 const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
80 116
117 if (unlikely(need_fallback(sctx->key_len))) {
118 crypto_cipher_encrypt_one(sctx->fallback.cip, out, in);
119 return;
120 }
121
81 switch (sctx->key_len) { 122 switch (sctx->key_len) {
82 case 16: 123 case 16:
83 crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in, 124 crypt_s390_km(KM_AES_128_ENCRYPT, &sctx->key, out, in,
@@ -98,6 +139,11 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
98{ 139{
99 const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); 140 const struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
100 141
142 if (unlikely(need_fallback(sctx->key_len))) {
143 crypto_cipher_decrypt_one(sctx->fallback.cip, out, in);
144 return;
145 }
146
101 switch (sctx->key_len) { 147 switch (sctx->key_len) {
102 case 16: 148 case 16:
103 crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in, 149 crypt_s390_km(KM_AES_128_DECRYPT, &sctx->key, out, in,
@@ -114,6 +160,29 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
114 } 160 }
115} 161}
116 162
163static int fallback_init_cip(struct crypto_tfm *tfm)
164{
165 const char *name = tfm->__crt_alg->cra_name;
166 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
167
168 sctx->fallback.cip = crypto_alloc_cipher(name, 0,
169 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
170
171 if (IS_ERR(sctx->fallback.cip)) {
172 printk(KERN_ERR "Error allocating fallback algo %s\n", name);
173 return PTR_ERR(sctx->fallback.blk);
174 }
175
176 return 0;
177}
178
179static void fallback_exit_cip(struct crypto_tfm *tfm)
180{
181 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
182
183 crypto_free_cipher(sctx->fallback.cip);
184 sctx->fallback.cip = NULL;
185}
117 186
118static struct crypto_alg aes_alg = { 187static struct crypto_alg aes_alg = {
119 .cra_name = "aes", 188 .cra_name = "aes",
@@ -125,6 +194,8 @@ static struct crypto_alg aes_alg = {
125 .cra_ctxsize = sizeof(struct s390_aes_ctx), 194 .cra_ctxsize = sizeof(struct s390_aes_ctx),
126 .cra_module = THIS_MODULE, 195 .cra_module = THIS_MODULE,
127 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list), 196 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
197 .cra_init = fallback_init_cip,
198 .cra_exit = fallback_exit_cip,
128 .cra_u = { 199 .cra_u = {
129 .cipher = { 200 .cipher = {
130 .cia_min_keysize = AES_MIN_KEY_SIZE, 201 .cia_min_keysize = AES_MIN_KEY_SIZE,
@@ -136,10 +207,70 @@ static struct crypto_alg aes_alg = {
136 } 207 }
137}; 208};
138 209
210static int setkey_fallback_blk(struct crypto_tfm *tfm, const u8 *key,
211 unsigned int len)
212{
213 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
214 unsigned int ret;
215
216 sctx->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK;
217 sctx->fallback.blk->base.crt_flags |= (tfm->crt_flags &
218 CRYPTO_TFM_REQ_MASK);
219
220 ret = crypto_blkcipher_setkey(sctx->fallback.blk, key, len);
221 if (ret) {
222 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
223 tfm->crt_flags |= (sctx->fallback.blk->base.crt_flags &
224 CRYPTO_TFM_RES_MASK);
225 }
226 return ret;
227}
228
229static int fallback_blk_dec(struct blkcipher_desc *desc,
230 struct scatterlist *dst, struct scatterlist *src,
231 unsigned int nbytes)
232{
233 unsigned int ret;
234 struct crypto_blkcipher *tfm;
235 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
236
237 tfm = desc->tfm;
238 desc->tfm = sctx->fallback.blk;
239
240 ret = crypto_blkcipher_decrypt_iv(desc, dst, src, nbytes);
241
242 desc->tfm = tfm;
243 return ret;
244}
245
246static int fallback_blk_enc(struct blkcipher_desc *desc,
247 struct scatterlist *dst, struct scatterlist *src,
248 unsigned int nbytes)
249{
250 unsigned int ret;
251 struct crypto_blkcipher *tfm;
252 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
253
254 tfm = desc->tfm;
255 desc->tfm = sctx->fallback.blk;
256
257 ret = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes);
258
259 desc->tfm = tfm;
260 return ret;
261}
262
139static int ecb_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 263static int ecb_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
140 unsigned int key_len) 264 unsigned int key_len)
141{ 265{
142 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); 266 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
267 int ret;
268
269 ret = need_fallback(key_len);
270 if (ret > 0) {
271 sctx->key_len = key_len;
272 return setkey_fallback_blk(tfm, in_key, key_len);
273 }
143 274
144 switch (key_len) { 275 switch (key_len) {
145 case 16: 276 case 16:
@@ -188,6 +319,9 @@ static int ecb_aes_encrypt(struct blkcipher_desc *desc,
188 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 319 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
189 struct blkcipher_walk walk; 320 struct blkcipher_walk walk;
190 321
322 if (unlikely(need_fallback(sctx->key_len)))
323 return fallback_blk_enc(desc, dst, src, nbytes);
324
191 blkcipher_walk_init(&walk, dst, src, nbytes); 325 blkcipher_walk_init(&walk, dst, src, nbytes);
192 return ecb_aes_crypt(desc, sctx->enc, sctx->key, &walk); 326 return ecb_aes_crypt(desc, sctx->enc, sctx->key, &walk);
193} 327}
@@ -199,10 +333,37 @@ static int ecb_aes_decrypt(struct blkcipher_desc *desc,
199 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 333 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
200 struct blkcipher_walk walk; 334 struct blkcipher_walk walk;
201 335
336 if (unlikely(need_fallback(sctx->key_len)))
337 return fallback_blk_dec(desc, dst, src, nbytes);
338
202 blkcipher_walk_init(&walk, dst, src, nbytes); 339 blkcipher_walk_init(&walk, dst, src, nbytes);
203 return ecb_aes_crypt(desc, sctx->dec, sctx->key, &walk); 340 return ecb_aes_crypt(desc, sctx->dec, sctx->key, &walk);
204} 341}
205 342
343static int fallback_init_blk(struct crypto_tfm *tfm)
344{
345 const char *name = tfm->__crt_alg->cra_name;
346 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
347
348 sctx->fallback.blk = crypto_alloc_blkcipher(name, 0,
349 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
350
351 if (IS_ERR(sctx->fallback.blk)) {
352 printk(KERN_ERR "Error allocating fallback algo %s\n", name);
353 return PTR_ERR(sctx->fallback.blk);
354 }
355
356 return 0;
357}
358
359static void fallback_exit_blk(struct crypto_tfm *tfm)
360{
361 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
362
363 crypto_free_blkcipher(sctx->fallback.blk);
364 sctx->fallback.blk = NULL;
365}
366
206static struct crypto_alg ecb_aes_alg = { 367static struct crypto_alg ecb_aes_alg = {
207 .cra_name = "ecb(aes)", 368 .cra_name = "ecb(aes)",
208 .cra_driver_name = "ecb-aes-s390", 369 .cra_driver_name = "ecb-aes-s390",
@@ -214,6 +375,8 @@ static struct crypto_alg ecb_aes_alg = {
214 .cra_type = &crypto_blkcipher_type, 375 .cra_type = &crypto_blkcipher_type,
215 .cra_module = THIS_MODULE, 376 .cra_module = THIS_MODULE,
216 .cra_list = LIST_HEAD_INIT(ecb_aes_alg.cra_list), 377 .cra_list = LIST_HEAD_INIT(ecb_aes_alg.cra_list),
378 .cra_init = fallback_init_blk,
379 .cra_exit = fallback_exit_blk,
217 .cra_u = { 380 .cra_u = {
218 .blkcipher = { 381 .blkcipher = {
219 .min_keysize = AES_MIN_KEY_SIZE, 382 .min_keysize = AES_MIN_KEY_SIZE,
@@ -229,6 +392,13 @@ static int cbc_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
229 unsigned int key_len) 392 unsigned int key_len)
230{ 393{
231 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); 394 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
395 int ret;
396
397 ret = need_fallback(key_len);
398 if (ret > 0) {
399 sctx->key_len = key_len;
400 return setkey_fallback_blk(tfm, in_key, key_len);
401 }
232 402
233 switch (key_len) { 403 switch (key_len) {
234 case 16: 404 case 16:
@@ -283,6 +453,9 @@ static int cbc_aes_encrypt(struct blkcipher_desc *desc,
283 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 453 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
284 struct blkcipher_walk walk; 454 struct blkcipher_walk walk;
285 455
456 if (unlikely(need_fallback(sctx->key_len)))
457 return fallback_blk_enc(desc, dst, src, nbytes);
458
286 blkcipher_walk_init(&walk, dst, src, nbytes); 459 blkcipher_walk_init(&walk, dst, src, nbytes);
287 return cbc_aes_crypt(desc, sctx->enc, sctx->iv, &walk); 460 return cbc_aes_crypt(desc, sctx->enc, sctx->iv, &walk);
288} 461}
@@ -294,6 +467,9 @@ static int cbc_aes_decrypt(struct blkcipher_desc *desc,
294 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm); 467 struct s390_aes_ctx *sctx = crypto_blkcipher_ctx(desc->tfm);
295 struct blkcipher_walk walk; 468 struct blkcipher_walk walk;
296 469
470 if (unlikely(need_fallback(sctx->key_len)))
471 return fallback_blk_dec(desc, dst, src, nbytes);
472
297 blkcipher_walk_init(&walk, dst, src, nbytes); 473 blkcipher_walk_init(&walk, dst, src, nbytes);
298 return cbc_aes_crypt(desc, sctx->dec, sctx->iv, &walk); 474 return cbc_aes_crypt(desc, sctx->dec, sctx->iv, &walk);
299} 475}
@@ -309,6 +485,8 @@ static struct crypto_alg cbc_aes_alg = {
309 .cra_type = &crypto_blkcipher_type, 485 .cra_type = &crypto_blkcipher_type,
310 .cra_module = THIS_MODULE, 486 .cra_module = THIS_MODULE,
311 .cra_list = LIST_HEAD_INIT(cbc_aes_alg.cra_list), 487 .cra_list = LIST_HEAD_INIT(cbc_aes_alg.cra_list),
488 .cra_init = fallback_init_blk,
489 .cra_exit = fallback_exit_blk,
312 .cra_u = { 490 .cra_u = {
313 .blkcipher = { 491 .blkcipher = {
314 .min_keysize = AES_MIN_KEY_SIZE, 492 .min_keysize = AES_MIN_KEY_SIZE,
@@ -336,14 +514,10 @@ static int __init aes_init(void)
336 return -EOPNOTSUPP; 514 return -EOPNOTSUPP;
337 515
338 /* z9 109 and z9 BC/EC only support 128 bit key length */ 516 /* z9 109 and z9 BC/EC only support 128 bit key length */
339 if (keylen_flag == AES_KEYLEN_128) { 517 if (keylen_flag == AES_KEYLEN_128)
340 aes_alg.cra_u.cipher.cia_max_keysize = AES_MIN_KEY_SIZE;
341 ecb_aes_alg.cra_u.blkcipher.max_keysize = AES_MIN_KEY_SIZE;
342 cbc_aes_alg.cra_u.blkcipher.max_keysize = AES_MIN_KEY_SIZE;
343 printk(KERN_INFO 518 printk(KERN_INFO
344 "aes_s390: hardware acceleration only available for" 519 "aes_s390: hardware acceleration only available for"
345 "128 bit keys\n"); 520 "128 bit keys\n");
346 }
347 521
348 ret = crypto_register_alg(&aes_alg); 522 ret = crypto_register_alg(&aes_alg);
349 if (ret) 523 if (ret)
@@ -382,4 +556,3 @@ MODULE_ALIAS("aes");
382 556
383MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm"); 557MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
384MODULE_LICENSE("GPL"); 558MODULE_LICENSE("GPL");
385
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 5245717295b8..4b010ff814c9 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -490,7 +490,7 @@ static struct super_operations hypfs_s_ops = {
490 .show_options = hypfs_show_options, 490 .show_options = hypfs_show_options,
491}; 491};
492 492
493static decl_subsys(s390, NULL, NULL); 493static struct kobject *s390_kobj;
494 494
495static int __init hypfs_init(void) 495static int __init hypfs_init(void)
496{ 496{
@@ -506,17 +506,18 @@ static int __init hypfs_init(void)
506 goto fail_diag; 506 goto fail_diag;
507 } 507 }
508 } 508 }
509 kobj_set_kset_s(&s390_subsys, hypervisor_subsys); 509 s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
510 rc = subsystem_register(&s390_subsys); 510 if (!s390_kobj) {
511 if (rc) 511 rc = -ENOMEM;;
512 goto fail_sysfs; 512 goto fail_sysfs;
513 }
513 rc = register_filesystem(&hypfs_type); 514 rc = register_filesystem(&hypfs_type);
514 if (rc) 515 if (rc)
515 goto fail_filesystem; 516 goto fail_filesystem;
516 return 0; 517 return 0;
517 518
518fail_filesystem: 519fail_filesystem:
519 subsystem_unregister(&s390_subsys); 520 kobject_put(s390_kobj);
520fail_sysfs: 521fail_sysfs:
521 if (!MACHINE_IS_VM) 522 if (!MACHINE_IS_VM)
522 hypfs_diag_exit(); 523 hypfs_diag_exit();
@@ -530,7 +531,7 @@ static void __exit hypfs_exit(void)
530 if (!MACHINE_IS_VM) 531 if (!MACHINE_IS_VM)
531 hypfs_diag_exit(); 532 hypfs_diag_exit();
532 unregister_filesystem(&hypfs_type); 533 unregister_filesystem(&hypfs_type);
533 subsystem_unregister(&s390_subsys); 534 kobject_put(s390_kobj);
534} 535}
535 536
536module_init(hypfs_init) 537module_init(hypfs_init)
diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index ce0856d32500..b97694fa62ec 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -162,22 +162,25 @@ EXPORT_SYMBOL_GPL(diag308);
162/* SYSFS */ 162/* SYSFS */
163 163
164#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ 164#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
165static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \ 165static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
166 struct kobj_attribute *attr, \
166 char *page) \ 167 char *page) \
167{ \ 168{ \
168 return sprintf(page, _format, _value); \ 169 return sprintf(page, _format, _value); \
169} \ 170} \
170static struct subsys_attribute sys_##_prefix##_##_name##_attr = \ 171static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
171 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL); 172 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
172 173
173#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ 174#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
174static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \ 175static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
176 struct kobj_attribute *attr, \
175 char *page) \ 177 char *page) \
176{ \ 178{ \
177 return sprintf(page, _fmt_out, \ 179 return sprintf(page, _fmt_out, \
178 (unsigned long long) _value); \ 180 (unsigned long long) _value); \
179} \ 181} \
180static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \ 182static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
181 const char *buf, size_t len) \ 184 const char *buf, size_t len) \
182{ \ 185{ \
183 unsigned long long value; \ 186 unsigned long long value; \
@@ -186,25 +189,27 @@ static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \
186 _value = value; \ 189 _value = value; \
187 return len; \ 190 return len; \
188} \ 191} \
189static struct subsys_attribute sys_##_prefix##_##_name##_attr = \ 192static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
190 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 193 __ATTR(_name,(S_IRUGO | S_IWUSR), \
191 sys_##_prefix##_##_name##_show, \ 194 sys_##_prefix##_##_name##_show, \
192 sys_##_prefix##_##_name##_store); 195 sys_##_prefix##_##_name##_store);
193 196
194#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\ 197#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
195static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \ 198static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
199 struct kobj_attribute *attr, \
196 char *page) \ 200 char *page) \
197{ \ 201{ \
198 return sprintf(page, _fmt_out, _value); \ 202 return sprintf(page, _fmt_out, _value); \
199} \ 203} \
200static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \ 204static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
205 struct kobj_attribute *attr, \
201 const char *buf, size_t len) \ 206 const char *buf, size_t len) \
202{ \ 207{ \
203 if (sscanf(buf, _fmt_in, _value) != 1) \ 208 if (sscanf(buf, _fmt_in, _value) != 1) \
204 return -EINVAL; \ 209 return -EINVAL; \
205 return len; \ 210 return len; \
206} \ 211} \
207static struct subsys_attribute sys_##_prefix##_##_name##_attr = \ 212static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
208 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 213 __ATTR(_name,(S_IRUGO | S_IWUSR), \
209 sys_##_prefix##_##_name##_show, \ 214 sys_##_prefix##_##_name##_show, \
210 sys_##_prefix##_##_name##_store); 215 sys_##_prefix##_##_name##_store);
@@ -270,14 +275,16 @@ void __init setup_ipl_info(void)
270struct ipl_info ipl_info; 275struct ipl_info ipl_info;
271EXPORT_SYMBOL_GPL(ipl_info); 276EXPORT_SYMBOL_GPL(ipl_info);
272 277
273static ssize_t ipl_type_show(struct kset *kset, char *page) 278static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
279 char *page)
274{ 280{
275 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type)); 281 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
276} 282}
277 283
278static struct subsys_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); 284static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
279 285
280static ssize_t sys_ipl_device_show(struct kset *kset, char *page) 286static ssize_t sys_ipl_device_show(struct kobject *kobj,
287 struct kobj_attribute *attr, char *page)
281{ 288{
282 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; 289 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
283 290
@@ -292,7 +299,7 @@ static ssize_t sys_ipl_device_show(struct kset *kset, char *page)
292 } 299 }
293} 300}
294 301
295static struct subsys_attribute sys_ipl_device_attr = 302static struct kobj_attribute sys_ipl_device_attr =
296 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); 303 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
297 304
298static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr, 305static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
@@ -367,7 +374,8 @@ static struct attribute_group ipl_fcp_attr_group = {
367 374
368/* CCW ipl device attributes */ 375/* CCW ipl device attributes */
369 376
370static ssize_t ipl_ccw_loadparm_show(struct kset *kset, char *page) 377static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
378 struct kobj_attribute *attr, char *page)
371{ 379{
372 char loadparm[LOADPARM_LEN + 1] = {}; 380 char loadparm[LOADPARM_LEN + 1] = {};
373 381
@@ -379,7 +387,7 @@ static ssize_t ipl_ccw_loadparm_show(struct kset *kset, char *page)
379 return sprintf(page, "%s\n", loadparm); 387 return sprintf(page, "%s\n", loadparm);
380} 388}
381 389
382static struct subsys_attribute sys_ipl_ccw_loadparm_attr = 390static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
383 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); 391 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
384 392
385static struct attribute *ipl_ccw_attrs[] = { 393static struct attribute *ipl_ccw_attrs[] = {
@@ -418,7 +426,7 @@ static struct attribute_group ipl_unknown_attr_group = {
418 .attrs = ipl_unknown_attrs, 426 .attrs = ipl_unknown_attrs,
419}; 427};
420 428
421static decl_subsys(ipl, NULL, NULL); 429static struct kset *ipl_kset;
422 430
423/* 431/*
424 * reipl section 432 * reipl section
@@ -465,7 +473,8 @@ static void reipl_get_ascii_loadparm(char *loadparm)
465 strstrip(loadparm); 473 strstrip(loadparm);
466} 474}
467 475
468static ssize_t reipl_ccw_loadparm_show(struct kset *kset, char *page) 476static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
477 struct kobj_attribute *attr, char *page)
469{ 478{
470 char buf[LOADPARM_LEN + 1]; 479 char buf[LOADPARM_LEN + 1];
471 480
@@ -473,7 +482,8 @@ static ssize_t reipl_ccw_loadparm_show(struct kset *kset, char *page)
473 return sprintf(page, "%s\n", buf); 482 return sprintf(page, "%s\n", buf);
474} 483}
475 484
476static ssize_t reipl_ccw_loadparm_store(struct kset *kset, 485static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
486 struct kobj_attribute *attr,
477 const char *buf, size_t len) 487 const char *buf, size_t len)
478{ 488{
479 int i, lp_len; 489 int i, lp_len;
@@ -500,7 +510,7 @@ static ssize_t reipl_ccw_loadparm_store(struct kset *kset,
500 return len; 510 return len;
501} 511}
502 512
503static struct subsys_attribute sys_reipl_ccw_loadparm_attr = 513static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
504 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show, 514 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
505 reipl_ccw_loadparm_store); 515 reipl_ccw_loadparm_store);
506 516
@@ -568,13 +578,15 @@ static int reipl_set_type(enum ipl_type type)
568 return 0; 578 return 0;
569} 579}
570 580
571static ssize_t reipl_type_show(struct kset *kset, char *page) 581static ssize_t reipl_type_show(struct kobject *kobj,
582 struct kobj_attribute *attr, char *page)
572{ 583{
573 return sprintf(page, "%s\n", ipl_type_str(reipl_type)); 584 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
574} 585}
575 586
576static ssize_t reipl_type_store(struct kset *kset, const char *buf, 587static ssize_t reipl_type_store(struct kobject *kobj,
577 size_t len) 588 struct kobj_attribute *attr,
589 const char *buf, size_t len)
578{ 590{
579 int rc = -EINVAL; 591 int rc = -EINVAL;
580 592
@@ -587,10 +599,10 @@ static ssize_t reipl_type_store(struct kset *kset, const char *buf,
587 return (rc != 0) ? rc : len; 599 return (rc != 0) ? rc : len;
588} 600}
589 601
590static struct subsys_attribute reipl_type_attr = 602static struct kobj_attribute reipl_type_attr =
591 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); 603 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
592 604
593static decl_subsys(reipl, NULL, NULL); 605static struct kset *reipl_kset;
594 606
595/* 607/*
596 * dump section 608 * dump section
@@ -663,13 +675,15 @@ static int dump_set_type(enum dump_type type)
663 return 0; 675 return 0;
664} 676}
665 677
666static ssize_t dump_type_show(struct kset *kset, char *page) 678static ssize_t dump_type_show(struct kobject *kobj,
679 struct kobj_attribute *attr, char *page)
667{ 680{
668 return sprintf(page, "%s\n", dump_type_str(dump_type)); 681 return sprintf(page, "%s\n", dump_type_str(dump_type));
669} 682}
670 683
671static ssize_t dump_type_store(struct kset *kset, const char *buf, 684static ssize_t dump_type_store(struct kobject *kobj,
672 size_t len) 685 struct kobj_attribute *attr,
686 const char *buf, size_t len)
673{ 687{
674 int rc = -EINVAL; 688 int rc = -EINVAL;
675 689
@@ -682,26 +696,28 @@ static ssize_t dump_type_store(struct kset *kset, const char *buf,
682 return (rc != 0) ? rc : len; 696 return (rc != 0) ? rc : len;
683} 697}
684 698
685static struct subsys_attribute dump_type_attr = 699static struct kobj_attribute dump_type_attr =
686 __ATTR(dump_type, 0644, dump_type_show, dump_type_store); 700 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
687 701
688static decl_subsys(dump, NULL, NULL); 702static struct kset *dump_kset;
689 703
690/* 704/*
691 * Shutdown actions section 705 * Shutdown actions section
692 */ 706 */
693 707
694static decl_subsys(shutdown_actions, NULL, NULL); 708static struct kset *shutdown_actions_kset;
695 709
696/* on panic */ 710/* on panic */
697 711
698static ssize_t on_panic_show(struct kset *kset, char *page) 712static ssize_t on_panic_show(struct kobject *kobj,
713 struct kobj_attribute *attr, char *page)
699{ 714{
700 return sprintf(page, "%s\n", shutdown_action_str(on_panic_action)); 715 return sprintf(page, "%s\n", shutdown_action_str(on_panic_action));
701} 716}
702 717
703static ssize_t on_panic_store(struct kset *kset, const char *buf, 718static ssize_t on_panic_store(struct kobject *kobj,
704 size_t len) 719 struct kobj_attribute *attr,
720 const char *buf, size_t len)
705{ 721{
706 if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0) 722 if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0)
707 on_panic_action = SHUTDOWN_REIPL; 723 on_panic_action = SHUTDOWN_REIPL;
@@ -717,7 +733,7 @@ static ssize_t on_panic_store(struct kset *kset, const char *buf,
717 return len; 733 return len;
718} 734}
719 735
720static struct subsys_attribute on_panic_attr = 736static struct kobj_attribute on_panic_attr =
721 __ATTR(on_panic, 0644, on_panic_show, on_panic_store); 737 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
722 738
723void do_reipl(void) 739void do_reipl(void)
@@ -814,23 +830,23 @@ static int __init ipl_register_fcp_files(void)
814{ 830{
815 int rc; 831 int rc;
816 832
817 rc = sysfs_create_group(&ipl_subsys.kobj, 833 rc = sysfs_create_group(&ipl_kset->kobj,
818 &ipl_fcp_attr_group); 834 &ipl_fcp_attr_group);
819 if (rc) 835 if (rc)
820 goto out; 836 goto out;
821 rc = sysfs_create_bin_file(&ipl_subsys.kobj, 837 rc = sysfs_create_bin_file(&ipl_kset->kobj,
822 &ipl_parameter_attr); 838 &ipl_parameter_attr);
823 if (rc) 839 if (rc)
824 goto out_ipl_parm; 840 goto out_ipl_parm;
825 rc = sysfs_create_bin_file(&ipl_subsys.kobj, 841 rc = sysfs_create_bin_file(&ipl_kset->kobj,
826 &ipl_scp_data_attr); 842 &ipl_scp_data_attr);
827 if (!rc) 843 if (!rc)
828 goto out; 844 goto out;
829 845
830 sysfs_remove_bin_file(&ipl_subsys.kobj, &ipl_parameter_attr); 846 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
831 847
832out_ipl_parm: 848out_ipl_parm:
833 sysfs_remove_group(&ipl_subsys.kobj, &ipl_fcp_attr_group); 849 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
834out: 850out:
835 return rc; 851 return rc;
836} 852}
@@ -839,12 +855,12 @@ static int __init ipl_init(void)
839{ 855{
840 int rc; 856 int rc;
841 857
842 rc = firmware_register(&ipl_subsys); 858 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
843 if (rc) 859 if (!ipl_kset)
844 return rc; 860 return -ENOMEM;
845 switch (ipl_info.type) { 861 switch (ipl_info.type) {
846 case IPL_TYPE_CCW: 862 case IPL_TYPE_CCW:
847 rc = sysfs_create_group(&ipl_subsys.kobj, 863 rc = sysfs_create_group(&ipl_kset->kobj,
848 &ipl_ccw_attr_group); 864 &ipl_ccw_attr_group);
849 break; 865 break;
850 case IPL_TYPE_FCP: 866 case IPL_TYPE_FCP:
@@ -852,16 +868,16 @@ static int __init ipl_init(void)
852 rc = ipl_register_fcp_files(); 868 rc = ipl_register_fcp_files();
853 break; 869 break;
854 case IPL_TYPE_NSS: 870 case IPL_TYPE_NSS:
855 rc = sysfs_create_group(&ipl_subsys.kobj, 871 rc = sysfs_create_group(&ipl_kset->kobj,
856 &ipl_nss_attr_group); 872 &ipl_nss_attr_group);
857 break; 873 break;
858 default: 874 default:
859 rc = sysfs_create_group(&ipl_subsys.kobj, 875 rc = sysfs_create_group(&ipl_kset->kobj,
860 &ipl_unknown_attr_group); 876 &ipl_unknown_attr_group);
861 break; 877 break;
862 } 878 }
863 if (rc) 879 if (rc)
864 firmware_unregister(&ipl_subsys); 880 kset_unregister(ipl_kset);
865 return rc; 881 return rc;
866} 882}
867 883
@@ -883,7 +899,7 @@ static int __init reipl_nss_init(void)
883 899
884 if (!MACHINE_IS_VM) 900 if (!MACHINE_IS_VM)
885 return 0; 901 return 0;
886 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_nss_attr_group); 902 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
887 if (rc) 903 if (rc)
888 return rc; 904 return rc;
889 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1); 905 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
@@ -898,7 +914,7 @@ static int __init reipl_ccw_init(void)
898 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 914 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
899 if (!reipl_block_ccw) 915 if (!reipl_block_ccw)
900 return -ENOMEM; 916 return -ENOMEM;
901 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_ccw_attr_group); 917 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
902 if (rc) { 918 if (rc) {
903 free_page((unsigned long)reipl_block_ccw); 919 free_page((unsigned long)reipl_block_ccw);
904 return rc; 920 return rc;
@@ -936,7 +952,7 @@ static int __init reipl_fcp_init(void)
936 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 952 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
937 if (!reipl_block_fcp) 953 if (!reipl_block_fcp)
938 return -ENOMEM; 954 return -ENOMEM;
939 rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_fcp_attr_group); 955 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
940 if (rc) { 956 if (rc) {
941 free_page((unsigned long)reipl_block_fcp); 957 free_page((unsigned long)reipl_block_fcp);
942 return rc; 958 return rc;
@@ -958,12 +974,12 @@ static int __init reipl_init(void)
958{ 974{
959 int rc; 975 int rc;
960 976
961 rc = firmware_register(&reipl_subsys); 977 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
962 if (rc) 978 if (!reipl_kset)
963 return rc; 979 return -ENOMEM;
964 rc = subsys_create_file(&reipl_subsys, &reipl_type_attr); 980 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
965 if (rc) { 981 if (rc) {
966 firmware_unregister(&reipl_subsys); 982 kset_unregister(reipl_kset);
967 return rc; 983 return rc;
968 } 984 }
969 rc = reipl_ccw_init(); 985 rc = reipl_ccw_init();
@@ -988,7 +1004,7 @@ static int __init dump_ccw_init(void)
988 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 1004 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
989 if (!dump_block_ccw) 1005 if (!dump_block_ccw)
990 return -ENOMEM; 1006 return -ENOMEM;
991 rc = sysfs_create_group(&dump_subsys.kobj, &dump_ccw_attr_group); 1007 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
992 if (rc) { 1008 if (rc) {
993 free_page((unsigned long)dump_block_ccw); 1009 free_page((unsigned long)dump_block_ccw);
994 return rc; 1010 return rc;
@@ -1012,7 +1028,7 @@ static int __init dump_fcp_init(void)
1012 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 1028 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1013 if (!dump_block_fcp) 1029 if (!dump_block_fcp)
1014 return -ENOMEM; 1030 return -ENOMEM;
1015 rc = sysfs_create_group(&dump_subsys.kobj, &dump_fcp_attr_group); 1031 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1016 if (rc) { 1032 if (rc) {
1017 free_page((unsigned long)dump_block_fcp); 1033 free_page((unsigned long)dump_block_fcp);
1018 return rc; 1034 return rc;
@@ -1047,12 +1063,12 @@ static int __init dump_init(void)
1047{ 1063{
1048 int rc; 1064 int rc;
1049 1065
1050 rc = firmware_register(&dump_subsys); 1066 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1051 if (rc) 1067 if (!dump_kset)
1052 return rc; 1068 return -ENOMEM;
1053 rc = subsys_create_file(&dump_subsys, &dump_type_attr); 1069 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr);
1054 if (rc) { 1070 if (rc) {
1055 firmware_unregister(&dump_subsys); 1071 kset_unregister(dump_kset);
1056 return rc; 1072 return rc;
1057 } 1073 }
1058 rc = dump_ccw_init(); 1074 rc = dump_ccw_init();
@@ -1069,12 +1085,13 @@ static int __init shutdown_actions_init(void)
1069{ 1085{
1070 int rc; 1086 int rc;
1071 1087
1072 rc = firmware_register(&shutdown_actions_subsys); 1088 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1073 if (rc) 1089 firmware_kobj);
1074 return rc; 1090 if (!shutdown_actions_kset)
1075 rc = subsys_create_file(&shutdown_actions_subsys, &on_panic_attr); 1091 return -ENOMEM;
1092 rc = sysfs_create_file(&shutdown_actions_kset->kobj, &on_panic_attr);
1076 if (rc) { 1093 if (rc) {
1077 firmware_unregister(&shutdown_actions_subsys); 1094 kset_unregister(shutdown_actions_kset);
1078 return rc; 1095 return rc;
1079 } 1096 }
1080 atomic_notifier_chain_register(&panic_notifier_list, 1097 atomic_notifier_chain_register(&panic_notifier_list,
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index 22b800ce2126..3bbac1293be4 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -1145,7 +1145,7 @@ static void etr_work_fn(struct work_struct *work)
1145 * Sysfs interface functions 1145 * Sysfs interface functions
1146 */ 1146 */
1147static struct sysdev_class etr_sysclass = { 1147static struct sysdev_class etr_sysclass = {
1148 set_kset_name("etr") 1148 .name = "etr",
1149}; 1149};
1150 1150
1151static struct sys_device etr_port0_dev = { 1151static struct sys_device etr_port0_dev = {
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index eebcd4768bbf..51b57c0d1a3c 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -19,7 +19,7 @@
19#include <asm/dma.h> 19#include <asm/dma.h>
20 20
21static struct sysdev_class dma_sysclass = { 21static struct sysdev_class dma_sysclass = {
22 set_kset_name("dma"), 22 .name = "dma",
23}; 23};
24EXPORT_SYMBOL(dma_sysclass); 24EXPORT_SYMBOL(dma_sysclass);
25 25
diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index b22a78c807e6..3008c00eea6b 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -341,17 +341,18 @@ static int __devinit sq_sysdev_add(struct sys_device *sysdev)
341{ 341{
342 unsigned int cpu = sysdev->id; 342 unsigned int cpu = sysdev->id;
343 struct kobject *kobj; 343 struct kobject *kobj;
344 int error;
344 345
345 sq_kobject[cpu] = kzalloc(sizeof(struct kobject), GFP_KERNEL); 346 sq_kobject[cpu] = kzalloc(sizeof(struct kobject), GFP_KERNEL);
346 if (unlikely(!sq_kobject[cpu])) 347 if (unlikely(!sq_kobject[cpu]))
347 return -ENOMEM; 348 return -ENOMEM;
348 349
349 kobj = sq_kobject[cpu]; 350 kobj = sq_kobject[cpu];
350 kobj->parent = &sysdev->kobj; 351 error = kobject_init_and_add(kobj, &ktype_percpu_entry, &sysdev->kobj,
351 kobject_set_name(kobj, "%s", "sq"); 352 "%s", "sq");
352 kobj->ktype = &ktype_percpu_entry; 353 if (!error)
353 354 kobject_uevent(kobj, KOBJ_ADD);
354 return kobject_register(kobj); 355 return error;
355} 356}
356 357
357static int __devexit sq_sysdev_remove(struct sys_device *sysdev) 358static int __devexit sq_sysdev_remove(struct sys_device *sysdev)
@@ -359,7 +360,7 @@ static int __devexit sq_sysdev_remove(struct sys_device *sysdev)
359 unsigned int cpu = sysdev->id; 360 unsigned int cpu = sysdev->id;
360 struct kobject *kobj = sq_kobject[cpu]; 361 struct kobject *kobj = sq_kobject[cpu];
361 362
362 kobject_unregister(kobj); 363 kobject_put(kobj);
363 return 0; 364 return 0;
364} 365}
365 366
diff --git a/arch/sh/kernel/time.c b/arch/sh/kernel/time.c
index a3a67d151e52..2bc04bfee738 100644
--- a/arch/sh/kernel/time.c
+++ b/arch/sh/kernel/time.c
@@ -174,7 +174,7 @@ int timer_resume(struct sys_device *dev)
174#endif 174#endif
175 175
176static struct sysdev_class timer_sysclass = { 176static struct sysdev_class timer_sysclass = {
177 set_kset_name("timer"), 177 .name = "timer",
178 .suspend = timer_suspend, 178 .suspend = timer_suspend,
179 .resume = timer_resume, 179 .resume = timer_resume,
180}; 180};
diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
index 46bb609e2444..3874c2de5403 100644
--- a/arch/x86/crypto/Makefile
+++ b/arch/x86/crypto/Makefile
@@ -4,12 +4,16 @@
4 4
5obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o 5obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
6obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o 6obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o
7obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o
7 8
8obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o 9obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
9obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o 10obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
11obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
10 12
11aes-i586-y := aes-i586-asm_32.o aes_32.o 13aes-i586-y := aes-i586-asm_32.o aes_glue.o
12twofish-i586-y := twofish-i586-asm_32.o twofish_32.o 14twofish-i586-y := twofish-i586-asm_32.o twofish_glue.o
15salsa20-i586-y := salsa20-i586-asm_32.o salsa20_glue.o
13 16
14aes-x86_64-y := aes-x86_64-asm_64.o aes_64.o 17aes-x86_64-y := aes-x86_64-asm_64.o aes_glue.o
15twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_64.o 18twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_glue.o
19salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o
diff --git a/arch/x86/crypto/aes-i586-asm_32.S b/arch/x86/crypto/aes-i586-asm_32.S
index f942f0c8f630..1093bede3e0a 100644
--- a/arch/x86/crypto/aes-i586-asm_32.S
+++ b/arch/x86/crypto/aes-i586-asm_32.S
@@ -46,9 +46,9 @@
46#define in_blk 16 46#define in_blk 16
47 47
48/* offsets in crypto_tfm structure */ 48/* offsets in crypto_tfm structure */
49#define ekey (crypto_tfm_ctx_offset + 0) 49#define klen (crypto_tfm_ctx_offset + 0)
50#define nrnd (crypto_tfm_ctx_offset + 256) 50#define ekey (crypto_tfm_ctx_offset + 4)
51#define dkey (crypto_tfm_ctx_offset + 260) 51#define dkey (crypto_tfm_ctx_offset + 244)
52 52
53// register mapping for encrypt and decrypt subroutines 53// register mapping for encrypt and decrypt subroutines
54 54
@@ -221,8 +221,8 @@
221 221
222.global aes_enc_blk 222.global aes_enc_blk
223 223
224.extern ft_tab 224.extern crypto_ft_tab
225.extern fl_tab 225.extern crypto_fl_tab
226 226
227.align 4 227.align 4
228 228
@@ -236,7 +236,7 @@ aes_enc_blk:
2361: push %ebx 2361: push %ebx
237 mov in_blk+4(%esp),%r2 237 mov in_blk+4(%esp),%r2
238 push %esi 238 push %esi
239 mov nrnd(%ebp),%r3 // number of rounds 239 mov klen(%ebp),%r3 // key size
240 push %edi 240 push %edi
241#if ekey != 0 241#if ekey != 0
242 lea ekey(%ebp),%ebp // key pointer 242 lea ekey(%ebp),%ebp // key pointer
@@ -255,26 +255,26 @@ aes_enc_blk:
255 255
256 sub $8,%esp // space for register saves on stack 256 sub $8,%esp // space for register saves on stack
257 add $16,%ebp // increment to next round key 257 add $16,%ebp // increment to next round key
258 cmp $12,%r3 258 cmp $24,%r3
259 jb 4f // 10 rounds for 128-bit key 259 jb 4f // 10 rounds for 128-bit key
260 lea 32(%ebp),%ebp 260 lea 32(%ebp),%ebp
261 je 3f // 12 rounds for 192-bit key 261 je 3f // 12 rounds for 192-bit key
262 lea 32(%ebp),%ebp 262 lea 32(%ebp),%ebp
263 263
2642: fwd_rnd1( -64(%ebp) ,ft_tab) // 14 rounds for 256-bit key 2642: fwd_rnd1( -64(%ebp), crypto_ft_tab) // 14 rounds for 256-bit key
265 fwd_rnd2( -48(%ebp) ,ft_tab) 265 fwd_rnd2( -48(%ebp), crypto_ft_tab)
2663: fwd_rnd1( -32(%ebp) ,ft_tab) // 12 rounds for 192-bit key 2663: fwd_rnd1( -32(%ebp), crypto_ft_tab) // 12 rounds for 192-bit key
267 fwd_rnd2( -16(%ebp) ,ft_tab) 267 fwd_rnd2( -16(%ebp), crypto_ft_tab)
2684: fwd_rnd1( (%ebp) ,ft_tab) // 10 rounds for 128-bit key 2684: fwd_rnd1( (%ebp), crypto_ft_tab) // 10 rounds for 128-bit key
269 fwd_rnd2( +16(%ebp) ,ft_tab) 269 fwd_rnd2( +16(%ebp), crypto_ft_tab)
270 fwd_rnd1( +32(%ebp) ,ft_tab) 270 fwd_rnd1( +32(%ebp), crypto_ft_tab)
271 fwd_rnd2( +48(%ebp) ,ft_tab) 271 fwd_rnd2( +48(%ebp), crypto_ft_tab)
272 fwd_rnd1( +64(%ebp) ,ft_tab) 272 fwd_rnd1( +64(%ebp), crypto_ft_tab)
273 fwd_rnd2( +80(%ebp) ,ft_tab) 273 fwd_rnd2( +80(%ebp), crypto_ft_tab)
274 fwd_rnd1( +96(%ebp) ,ft_tab) 274 fwd_rnd1( +96(%ebp), crypto_ft_tab)
275 fwd_rnd2(+112(%ebp) ,ft_tab) 275 fwd_rnd2(+112(%ebp), crypto_ft_tab)
276 fwd_rnd1(+128(%ebp) ,ft_tab) 276 fwd_rnd1(+128(%ebp), crypto_ft_tab)
277 fwd_rnd2(+144(%ebp) ,fl_tab) // last round uses a different table 277 fwd_rnd2(+144(%ebp), crypto_fl_tab) // last round uses a different table
278 278
279// move final values to the output array. CAUTION: the 279// move final values to the output array. CAUTION: the
280// order of these assigns rely on the register mappings 280// order of these assigns rely on the register mappings
@@ -297,8 +297,8 @@ aes_enc_blk:
297 297
298.global aes_dec_blk 298.global aes_dec_blk
299 299
300.extern it_tab 300.extern crypto_it_tab
301.extern il_tab 301.extern crypto_il_tab
302 302
303.align 4 303.align 4
304 304
@@ -312,14 +312,11 @@ aes_dec_blk:
3121: push %ebx 3121: push %ebx
313 mov in_blk+4(%esp),%r2 313 mov in_blk+4(%esp),%r2
314 push %esi 314 push %esi
315 mov nrnd(%ebp),%r3 // number of rounds 315 mov klen(%ebp),%r3 // key size
316 push %edi 316 push %edi
317#if dkey != 0 317#if dkey != 0
318 lea dkey(%ebp),%ebp // key pointer 318 lea dkey(%ebp),%ebp // key pointer
319#endif 319#endif
320 mov %r3,%r0
321 shl $4,%r0
322 add %r0,%ebp
323 320
324// input four columns and xor in first round key 321// input four columns and xor in first round key
325 322
@@ -333,27 +330,27 @@ aes_dec_blk:
333 xor 12(%ebp),%r5 330 xor 12(%ebp),%r5
334 331
335 sub $8,%esp // space for register saves on stack 332 sub $8,%esp // space for register saves on stack
336 sub $16,%ebp // increment to next round key 333 add $16,%ebp // increment to next round key
337 cmp $12,%r3 334 cmp $24,%r3
338 jb 4f // 10 rounds for 128-bit key 335 jb 4f // 10 rounds for 128-bit key
339 lea -32(%ebp),%ebp 336 lea 32(%ebp),%ebp
340 je 3f // 12 rounds for 192-bit key 337 je 3f // 12 rounds for 192-bit key
341 lea -32(%ebp),%ebp 338 lea 32(%ebp),%ebp
342 339
3432: inv_rnd1( +64(%ebp), it_tab) // 14 rounds for 256-bit key 3402: inv_rnd1( -64(%ebp), crypto_it_tab) // 14 rounds for 256-bit key
344 inv_rnd2( +48(%ebp), it_tab) 341 inv_rnd2( -48(%ebp), crypto_it_tab)
3453: inv_rnd1( +32(%ebp), it_tab) // 12 rounds for 192-bit key 3423: inv_rnd1( -32(%ebp), crypto_it_tab) // 12 rounds for 192-bit key
346 inv_rnd2( +16(%ebp), it_tab) 343 inv_rnd2( -16(%ebp), crypto_it_tab)
3474: inv_rnd1( (%ebp), it_tab) // 10 rounds for 128-bit key 3444: inv_rnd1( (%ebp), crypto_it_tab) // 10 rounds for 128-bit key
348 inv_rnd2( -16(%ebp), it_tab) 345 inv_rnd2( +16(%ebp), crypto_it_tab)
349 inv_rnd1( -32(%ebp), it_tab) 346 inv_rnd1( +32(%ebp), crypto_it_tab)
350 inv_rnd2( -48(%ebp), it_tab) 347 inv_rnd2( +48(%ebp), crypto_it_tab)
351 inv_rnd1( -64(%ebp), it_tab) 348 inv_rnd1( +64(%ebp), crypto_it_tab)
352 inv_rnd2( -80(%ebp), it_tab) 349 inv_rnd2( +80(%ebp), crypto_it_tab)
353 inv_rnd1( -96(%ebp), it_tab) 350 inv_rnd1( +96(%ebp), crypto_it_tab)
354 inv_rnd2(-112(%ebp), it_tab) 351 inv_rnd2(+112(%ebp), crypto_it_tab)
355 inv_rnd1(-128(%ebp), it_tab) 352 inv_rnd1(+128(%ebp), crypto_it_tab)
356 inv_rnd2(-144(%ebp), il_tab) // last round uses a different table 353 inv_rnd2(+144(%ebp), crypto_il_tab) // last round uses a different table
357 354
358// move final values to the output array. CAUTION: the 355// move final values to the output array. CAUTION: the
359// order of these assigns rely on the register mappings 356// order of these assigns rely on the register mappings
diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
index 26b40de4d0b0..a120f526c3df 100644
--- a/arch/x86/crypto/aes-x86_64-asm_64.S
+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
@@ -8,10 +8,10 @@
8 * including this sentence is retained in full. 8 * including this sentence is retained in full.
9 */ 9 */
10 10
11.extern aes_ft_tab 11.extern crypto_ft_tab
12.extern aes_it_tab 12.extern crypto_it_tab
13.extern aes_fl_tab 13.extern crypto_fl_tab
14.extern aes_il_tab 14.extern crypto_il_tab
15 15
16.text 16.text
17 17
@@ -56,13 +56,13 @@
56 .align 8; \ 56 .align 8; \
57FUNC: movq r1,r2; \ 57FUNC: movq r1,r2; \
58 movq r3,r4; \ 58 movq r3,r4; \
59 leaq BASE+KEY+52(r8),r9; \ 59 leaq BASE+KEY+48+4(r8),r9; \
60 movq r10,r11; \ 60 movq r10,r11; \
61 movl (r7),r5 ## E; \ 61 movl (r7),r5 ## E; \
62 movl 4(r7),r1 ## E; \ 62 movl 4(r7),r1 ## E; \
63 movl 8(r7),r6 ## E; \ 63 movl 8(r7),r6 ## E; \
64 movl 12(r7),r7 ## E; \ 64 movl 12(r7),r7 ## E; \
65 movl BASE(r8),r10 ## E; \ 65 movl BASE+0(r8),r10 ## E; \
66 xorl -48(r9),r5 ## E; \ 66 xorl -48(r9),r5 ## E; \
67 xorl -44(r9),r1 ## E; \ 67 xorl -44(r9),r1 ## E; \
68 xorl -40(r9),r6 ## E; \ 68 xorl -40(r9),r6 ## E; \
@@ -154,37 +154,37 @@ FUNC: movq r1,r2; \
154/* void aes_enc_blk(stuct crypto_tfm *tfm, u8 *out, const u8 *in) */ 154/* void aes_enc_blk(stuct crypto_tfm *tfm, u8 *out, const u8 *in) */
155 155
156 entry(aes_enc_blk,0,enc128,enc192) 156 entry(aes_enc_blk,0,enc128,enc192)
157 encrypt_round(aes_ft_tab,-96) 157 encrypt_round(crypto_ft_tab,-96)
158 encrypt_round(aes_ft_tab,-80) 158 encrypt_round(crypto_ft_tab,-80)
159enc192: encrypt_round(aes_ft_tab,-64) 159enc192: encrypt_round(crypto_ft_tab,-64)
160 encrypt_round(aes_ft_tab,-48) 160 encrypt_round(crypto_ft_tab,-48)
161enc128: encrypt_round(aes_ft_tab,-32) 161enc128: encrypt_round(crypto_ft_tab,-32)
162 encrypt_round(aes_ft_tab,-16) 162 encrypt_round(crypto_ft_tab,-16)
163 encrypt_round(aes_ft_tab, 0) 163 encrypt_round(crypto_ft_tab, 0)
164 encrypt_round(aes_ft_tab, 16) 164 encrypt_round(crypto_ft_tab, 16)
165 encrypt_round(aes_ft_tab, 32) 165 encrypt_round(crypto_ft_tab, 32)
166 encrypt_round(aes_ft_tab, 48) 166 encrypt_round(crypto_ft_tab, 48)
167 encrypt_round(aes_ft_tab, 64) 167 encrypt_round(crypto_ft_tab, 64)
168 encrypt_round(aes_ft_tab, 80) 168 encrypt_round(crypto_ft_tab, 80)
169 encrypt_round(aes_ft_tab, 96) 169 encrypt_round(crypto_ft_tab, 96)
170 encrypt_final(aes_fl_tab,112) 170 encrypt_final(crypto_fl_tab,112)
171 return 171 return
172 172
173/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in) */ 173/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in) */
174 174
175 entry(aes_dec_blk,240,dec128,dec192) 175 entry(aes_dec_blk,240,dec128,dec192)
176 decrypt_round(aes_it_tab,-96) 176 decrypt_round(crypto_it_tab,-96)
177 decrypt_round(aes_it_tab,-80) 177 decrypt_round(crypto_it_tab,-80)
178dec192: decrypt_round(aes_it_tab,-64) 178dec192: decrypt_round(crypto_it_tab,-64)
179 decrypt_round(aes_it_tab,-48) 179 decrypt_round(crypto_it_tab,-48)
180dec128: decrypt_round(aes_it_tab,-32) 180dec128: decrypt_round(crypto_it_tab,-32)
181 decrypt_round(aes_it_tab,-16) 181 decrypt_round(crypto_it_tab,-16)
182 decrypt_round(aes_it_tab, 0) 182 decrypt_round(crypto_it_tab, 0)
183 decrypt_round(aes_it_tab, 16) 183 decrypt_round(crypto_it_tab, 16)
184 decrypt_round(aes_it_tab, 32) 184 decrypt_round(crypto_it_tab, 32)
185 decrypt_round(aes_it_tab, 48) 185 decrypt_round(crypto_it_tab, 48)
186 decrypt_round(aes_it_tab, 64) 186 decrypt_round(crypto_it_tab, 64)
187 decrypt_round(aes_it_tab, 80) 187 decrypt_round(crypto_it_tab, 80)
188 decrypt_round(aes_it_tab, 96) 188 decrypt_round(crypto_it_tab, 96)
189 decrypt_final(aes_il_tab,112) 189 decrypt_final(crypto_il_tab,112)
190 return 190 return
diff --git a/arch/x86/crypto/aes_32.c b/arch/x86/crypto/aes_32.c
deleted file mode 100644
index 49aad9397f10..000000000000
--- a/arch/x86/crypto/aes_32.c
+++ /dev/null
@@ -1,515 +0,0 @@
1/*
2 *
3 * Glue Code for optimized 586 assembler version of AES
4 *
5 * Copyright (c) 2002, Dr Brian Gladman <>, Worcester, UK.
6 * All rights reserved.
7 *
8 * LICENSE TERMS
9 *
10 * The free distribution and use of this software in both source and binary
11 * form is allowed (with or without changes) provided that:
12 *
13 * 1. distributions of this source code include the above copyright
14 * notice, this list of conditions and the following disclaimer;
15 *
16 * 2. distributions in binary form include the above copyright
17 * notice, this list of conditions and the following disclaimer
18 * in the documentation and/or other associated materials;
19 *
20 * 3. the copyright holder's name is not used to endorse products
21 * built using this software without specific written permission.
22 *
23 * ALTERNATIVELY, provided that this notice is retained in full, this product
24 * may be distributed under the terms of the GNU General Public License (GPL),
25 * in which case the provisions of the GPL apply INSTEAD OF those given above.
26 *
27 * DISCLAIMER
28 *
29 * This software is provided 'as is' with no explicit or implied warranties
30 * in respect of its properties, including, but not limited to, correctness
31 * and/or fitness for purpose.
32 *
33 * Copyright (c) 2003, Adam J. Richter <adam@yggdrasil.com> (conversion to
34 * 2.5 API).
35 * Copyright (c) 2003, 2004 Fruhwirth Clemens <clemens@endorphin.org>
36 * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
37 *
38 */
39
40#include <asm/byteorder.h>
41#include <linux/kernel.h>
42#include <linux/module.h>
43#include <linux/init.h>
44#include <linux/types.h>
45#include <linux/crypto.h>
46#include <linux/linkage.h>
47
48asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
49asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
50
51#define AES_MIN_KEY_SIZE 16
52#define AES_MAX_KEY_SIZE 32
53#define AES_BLOCK_SIZE 16
54#define AES_KS_LENGTH 4 * AES_BLOCK_SIZE
55#define RC_LENGTH 29
56
57struct aes_ctx {
58 u32 ekey[AES_KS_LENGTH];
59 u32 rounds;
60 u32 dkey[AES_KS_LENGTH];
61};
62
63#define WPOLY 0x011b
64#define bytes2word(b0, b1, b2, b3) \
65 (((u32)(b3) << 24) | ((u32)(b2) << 16) | ((u32)(b1) << 8) | (b0))
66
67/* define the finite field multiplies required for Rijndael */
68#define f2(x) ((x) ? pow[log[x] + 0x19] : 0)
69#define f3(x) ((x) ? pow[log[x] + 0x01] : 0)
70#define f9(x) ((x) ? pow[log[x] + 0xc7] : 0)
71#define fb(x) ((x) ? pow[log[x] + 0x68] : 0)
72#define fd(x) ((x) ? pow[log[x] + 0xee] : 0)
73#define fe(x) ((x) ? pow[log[x] + 0xdf] : 0)
74#define fi(x) ((x) ? pow[255 - log[x]]: 0)
75
76static inline u32 upr(u32 x, int n)
77{
78 return (x << 8 * n) | (x >> (32 - 8 * n));
79}
80
81static inline u8 bval(u32 x, int n)
82{
83 return x >> 8 * n;
84}
85
86/* The forward and inverse affine transformations used in the S-box */
87#define fwd_affine(x) \
88 (w = (u32)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(u8)(w^(w>>8)))
89
90#define inv_affine(x) \
91 (w = (u32)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(u8)(w^(w>>8)))
92
93static u32 rcon_tab[RC_LENGTH];
94
95u32 ft_tab[4][256];
96u32 fl_tab[4][256];
97static u32 im_tab[4][256];
98u32 il_tab[4][256];
99u32 it_tab[4][256];
100
101static void gen_tabs(void)
102{
103 u32 i, w;
104 u8 pow[512], log[256];
105
106 /*
107 * log and power tables for GF(2^8) finite field with
108 * WPOLY as modular polynomial - the simplest primitive
109 * root is 0x03, used here to generate the tables.
110 */
111 i = 0; w = 1;
112
113 do {
114 pow[i] = (u8)w;
115 pow[i + 255] = (u8)w;
116 log[w] = (u8)i++;
117 w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0);
118 } while (w != 1);
119
120 for(i = 0, w = 1; i < RC_LENGTH; ++i) {
121 rcon_tab[i] = bytes2word(w, 0, 0, 0);
122 w = f2(w);
123 }
124
125 for(i = 0; i < 256; ++i) {
126 u8 b;
127
128 b = fwd_affine(fi((u8)i));
129 w = bytes2word(f2(b), b, b, f3(b));
130
131 /* tables for a normal encryption round */
132 ft_tab[0][i] = w;
133 ft_tab[1][i] = upr(w, 1);
134 ft_tab[2][i] = upr(w, 2);
135 ft_tab[3][i] = upr(w, 3);
136 w = bytes2word(b, 0, 0, 0);
137
138 /*
139 * tables for last encryption round
140 * (may also be used in the key schedule)
141 */
142 fl_tab[0][i] = w;
143 fl_tab[1][i] = upr(w, 1);
144 fl_tab[2][i] = upr(w, 2);
145 fl_tab[3][i] = upr(w, 3);
146
147 b = fi(inv_affine((u8)i));
148 w = bytes2word(fe(b), f9(b), fd(b), fb(b));
149
150 /* tables for the inverse mix column operation */
151 im_tab[0][b] = w;
152 im_tab[1][b] = upr(w, 1);
153 im_tab[2][b] = upr(w, 2);
154 im_tab[3][b] = upr(w, 3);
155
156 /* tables for a normal decryption round */
157 it_tab[0][i] = w;
158 it_tab[1][i] = upr(w,1);
159 it_tab[2][i] = upr(w,2);
160 it_tab[3][i] = upr(w,3);
161
162 w = bytes2word(b, 0, 0, 0);
163
164 /* tables for last decryption round */
165 il_tab[0][i] = w;
166 il_tab[1][i] = upr(w,1);
167 il_tab[2][i] = upr(w,2);
168 il_tab[3][i] = upr(w,3);
169 }
170}
171
172#define four_tables(x,tab,vf,rf,c) \
173( tab[0][bval(vf(x,0,c),rf(0,c))] ^ \
174 tab[1][bval(vf(x,1,c),rf(1,c))] ^ \
175 tab[2][bval(vf(x,2,c),rf(2,c))] ^ \
176 tab[3][bval(vf(x,3,c),rf(3,c))] \
177)
178
179#define vf1(x,r,c) (x)
180#define rf1(r,c) (r)
181#define rf2(r,c) ((r-c)&3)
182
183#define inv_mcol(x) four_tables(x,im_tab,vf1,rf1,0)
184#define ls_box(x,c) four_tables(x,fl_tab,vf1,rf2,c)
185
186#define ff(x) inv_mcol(x)
187
188#define ke4(k,i) \
189{ \
190 k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; \
191 k[4*(i)+5] = ss[1] ^= ss[0]; \
192 k[4*(i)+6] = ss[2] ^= ss[1]; \
193 k[4*(i)+7] = ss[3] ^= ss[2]; \
194}
195
196#define kel4(k,i) \
197{ \
198 k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ rcon_tab[i]; \
199 k[4*(i)+5] = ss[1] ^= ss[0]; \
200 k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \
201}
202
203#define ke6(k,i) \
204{ \
205 k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; \
206 k[6*(i)+ 7] = ss[1] ^= ss[0]; \
207 k[6*(i)+ 8] = ss[2] ^= ss[1]; \
208 k[6*(i)+ 9] = ss[3] ^= ss[2]; \
209 k[6*(i)+10] = ss[4] ^= ss[3]; \
210 k[6*(i)+11] = ss[5] ^= ss[4]; \
211}
212
213#define kel6(k,i) \
214{ \
215 k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; \
216 k[6*(i)+ 7] = ss[1] ^= ss[0]; \
217 k[6*(i)+ 8] = ss[2] ^= ss[1]; \
218 k[6*(i)+ 9] = ss[3] ^= ss[2]; \
219}
220
221#define ke8(k,i) \
222{ \
223 k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; \
224 k[8*(i)+ 9] = ss[1] ^= ss[0]; \
225 k[8*(i)+10] = ss[2] ^= ss[1]; \
226 k[8*(i)+11] = ss[3] ^= ss[2]; \
227 k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); \
228 k[8*(i)+13] = ss[5] ^= ss[4]; \
229 k[8*(i)+14] = ss[6] ^= ss[5]; \
230 k[8*(i)+15] = ss[7] ^= ss[6]; \
231}
232
233#define kel8(k,i) \
234{ \
235 k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; \
236 k[8*(i)+ 9] = ss[1] ^= ss[0]; \
237 k[8*(i)+10] = ss[2] ^= ss[1]; \
238 k[8*(i)+11] = ss[3] ^= ss[2]; \
239}
240
241#define kdf4(k,i) \
242{ \
243 ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; \
244 ss[1] = ss[1] ^ ss[3]; \
245 ss[2] = ss[2] ^ ss[3]; \
246 ss[3] = ss[3]; \
247 ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; \
248 ss[i % 4] ^= ss[4]; \
249 ss[4] ^= k[4*(i)]; \
250 k[4*(i)+4] = ff(ss[4]); \
251 ss[4] ^= k[4*(i)+1]; \
252 k[4*(i)+5] = ff(ss[4]); \
253 ss[4] ^= k[4*(i)+2]; \
254 k[4*(i)+6] = ff(ss[4]); \
255 ss[4] ^= k[4*(i)+3]; \
256 k[4*(i)+7] = ff(ss[4]); \
257}
258
259#define kd4(k,i) \
260{ \
261 ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; \
262 ss[i % 4] ^= ss[4]; \
263 ss[4] = ff(ss[4]); \
264 k[4*(i)+4] = ss[4] ^= k[4*(i)]; \
265 k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \
266 k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; \
267 k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \
268}
269
270#define kdl4(k,i) \
271{ \
272 ss[4] = ls_box(ss[(i+3) % 4], 3) ^ rcon_tab[i]; \
273 ss[i % 4] ^= ss[4]; \
274 k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; \
275 k[4*(i)+5] = ss[1] ^ ss[3]; \
276 k[4*(i)+6] = ss[0]; \
277 k[4*(i)+7] = ss[1]; \
278}
279
280#define kdf6(k,i) \
281{ \
282 ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; \
283 k[6*(i)+ 6] = ff(ss[0]); \
284 ss[1] ^= ss[0]; \
285 k[6*(i)+ 7] = ff(ss[1]); \
286 ss[2] ^= ss[1]; \
287 k[6*(i)+ 8] = ff(ss[2]); \
288 ss[3] ^= ss[2]; \
289 k[6*(i)+ 9] = ff(ss[3]); \
290 ss[4] ^= ss[3]; \
291 k[6*(i)+10] = ff(ss[4]); \
292 ss[5] ^= ss[4]; \
293 k[6*(i)+11] = ff(ss[5]); \
294}
295
296#define kd6(k,i) \
297{ \
298 ss[6] = ls_box(ss[5],3) ^ rcon_tab[i]; \
299 ss[0] ^= ss[6]; ss[6] = ff(ss[6]); \
300 k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \
301 ss[1] ^= ss[0]; \
302 k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \
303 ss[2] ^= ss[1]; \
304 k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \
305 ss[3] ^= ss[2]; \
306 k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \
307 ss[4] ^= ss[3]; \
308 k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \
309 ss[5] ^= ss[4]; \
310 k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \
311}
312
313#define kdl6(k,i) \
314{ \
315 ss[0] ^= ls_box(ss[5],3) ^ rcon_tab[i]; \
316 k[6*(i)+ 6] = ss[0]; \
317 ss[1] ^= ss[0]; \
318 k[6*(i)+ 7] = ss[1]; \
319 ss[2] ^= ss[1]; \
320 k[6*(i)+ 8] = ss[2]; \
321 ss[3] ^= ss[2]; \
322 k[6*(i)+ 9] = ss[3]; \
323}
324
325#define kdf8(k,i) \
326{ \
327 ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; \
328 k[8*(i)+ 8] = ff(ss[0]); \
329 ss[1] ^= ss[0]; \
330 k[8*(i)+ 9] = ff(ss[1]); \
331 ss[2] ^= ss[1]; \
332 k[8*(i)+10] = ff(ss[2]); \
333 ss[3] ^= ss[2]; \
334 k[8*(i)+11] = ff(ss[3]); \
335 ss[4] ^= ls_box(ss[3],0); \
336 k[8*(i)+12] = ff(ss[4]); \
337 ss[5] ^= ss[4]; \
338 k[8*(i)+13] = ff(ss[5]); \
339 ss[6] ^= ss[5]; \
340 k[8*(i)+14] = ff(ss[6]); \
341 ss[7] ^= ss[6]; \
342 k[8*(i)+15] = ff(ss[7]); \
343}
344
345#define kd8(k,i) \
346{ \
347 u32 __g = ls_box(ss[7],3) ^ rcon_tab[i]; \
348 ss[0] ^= __g; \
349 __g = ff(__g); \
350 k[8*(i)+ 8] = __g ^= k[8*(i)]; \
351 ss[1] ^= ss[0]; \
352 k[8*(i)+ 9] = __g ^= k[8*(i)+ 1]; \
353 ss[2] ^= ss[1]; \
354 k[8*(i)+10] = __g ^= k[8*(i)+ 2]; \
355 ss[3] ^= ss[2]; \
356 k[8*(i)+11] = __g ^= k[8*(i)+ 3]; \
357 __g = ls_box(ss[3],0); \
358 ss[4] ^= __g; \
359 __g = ff(__g); \
360 k[8*(i)+12] = __g ^= k[8*(i)+ 4]; \
361 ss[5] ^= ss[4]; \
362 k[8*(i)+13] = __g ^= k[8*(i)+ 5]; \
363 ss[6] ^= ss[5]; \
364 k[8*(i)+14] = __g ^= k[8*(i)+ 6]; \
365 ss[7] ^= ss[6]; \
366 k[8*(i)+15] = __g ^= k[8*(i)+ 7]; \
367}
368
369#define kdl8(k,i) \
370{ \
371 ss[0] ^= ls_box(ss[7],3) ^ rcon_tab[i]; \
372 k[8*(i)+ 8] = ss[0]; \
373 ss[1] ^= ss[0]; \
374 k[8*(i)+ 9] = ss[1]; \
375 ss[2] ^= ss[1]; \
376 k[8*(i)+10] = ss[2]; \
377 ss[3] ^= ss[2]; \
378 k[8*(i)+11] = ss[3]; \
379}
380
381static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
382 unsigned int key_len)
383{
384 int i;
385 u32 ss[8];
386 struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
387 const __le32 *key = (const __le32 *)in_key;
388 u32 *flags = &tfm->crt_flags;
389
390 /* encryption schedule */
391
392 ctx->ekey[0] = ss[0] = le32_to_cpu(key[0]);
393 ctx->ekey[1] = ss[1] = le32_to_cpu(key[1]);
394 ctx->ekey[2] = ss[2] = le32_to_cpu(key[2]);
395 ctx->ekey[3] = ss[3] = le32_to_cpu(key[3]);
396
397 switch(key_len) {
398 case 16:
399 for (i = 0; i < 9; i++)
400 ke4(ctx->ekey, i);
401 kel4(ctx->ekey, 9);
402 ctx->rounds = 10;
403 break;
404
405 case 24:
406 ctx->ekey[4] = ss[4] = le32_to_cpu(key[4]);
407 ctx->ekey[5] = ss[5] = le32_to_cpu(key[5]);
408 for (i = 0; i < 7; i++)
409 ke6(ctx->ekey, i);
410 kel6(ctx->ekey, 7);
411 ctx->rounds = 12;
412 break;
413
414 case 32:
415 ctx->ekey[4] = ss[4] = le32_to_cpu(key[4]);
416 ctx->ekey[5] = ss[5] = le32_to_cpu(key[5]);
417 ctx->ekey[6] = ss[6] = le32_to_cpu(key[6]);
418 ctx->ekey[7] = ss[7] = le32_to_cpu(key[7]);
419 for (i = 0; i < 6; i++)
420 ke8(ctx->ekey, i);
421 kel8(ctx->ekey, 6);
422 ctx->rounds = 14;
423 break;
424
425 default:
426 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
427 return -EINVAL;
428 }
429
430 /* decryption schedule */
431
432 ctx->dkey[0] = ss[0] = le32_to_cpu(key[0]);
433 ctx->dkey[1] = ss[1] = le32_to_cpu(key[1]);
434 ctx->dkey[2] = ss[2] = le32_to_cpu(key[2]);
435 ctx->dkey[3] = ss[3] = le32_to_cpu(key[3]);
436
437 switch (key_len) {
438 case 16:
439 kdf4(ctx->dkey, 0);
440 for (i = 1; i < 9; i++)
441 kd4(ctx->dkey, i);
442 kdl4(ctx->dkey, 9);
443 break;
444
445 case 24:
446 ctx->dkey[4] = ff(ss[4] = le32_to_cpu(key[4]));
447 ctx->dkey[5] = ff(ss[5] = le32_to_cpu(key[5]));
448 kdf6(ctx->dkey, 0);
449 for (i = 1; i < 7; i++)
450 kd6(ctx->dkey, i);
451 kdl6(ctx->dkey, 7);
452 break;
453
454 case 32:
455 ctx->dkey[4] = ff(ss[4] = le32_to_cpu(key[4]));
456 ctx->dkey[5] = ff(ss[5] = le32_to_cpu(key[5]));
457 ctx->dkey[6] = ff(ss[6] = le32_to_cpu(key[6]));
458 ctx->dkey[7] = ff(ss[7] = le32_to_cpu(key[7]));
459 kdf8(ctx->dkey, 0);
460 for (i = 1; i < 6; i++)
461 kd8(ctx->dkey, i);
462 kdl8(ctx->dkey, 6);
463 break;
464 }
465 return 0;
466}
467
468static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
469{
470 aes_enc_blk(tfm, dst, src);
471}
472
473static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
474{
475 aes_dec_blk(tfm, dst, src);
476}
477
478static struct crypto_alg aes_alg = {
479 .cra_name = "aes",
480 .cra_driver_name = "aes-i586",
481 .cra_priority = 200,
482 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
483 .cra_blocksize = AES_BLOCK_SIZE,
484 .cra_ctxsize = sizeof(struct aes_ctx),
485 .cra_module = THIS_MODULE,
486 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
487 .cra_u = {
488 .cipher = {
489 .cia_min_keysize = AES_MIN_KEY_SIZE,
490 .cia_max_keysize = AES_MAX_KEY_SIZE,
491 .cia_setkey = aes_set_key,
492 .cia_encrypt = aes_encrypt,
493 .cia_decrypt = aes_decrypt
494 }
495 }
496};
497
498static int __init aes_init(void)
499{
500 gen_tabs();
501 return crypto_register_alg(&aes_alg);
502}
503
504static void __exit aes_fini(void)
505{
506 crypto_unregister_alg(&aes_alg);
507}
508
509module_init(aes_init);
510module_exit(aes_fini);
511
512MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, i586 asm optimized");
513MODULE_LICENSE("Dual BSD/GPL");
514MODULE_AUTHOR("Fruhwirth Clemens, James Morris, Brian Gladman, Adam Richter");
515MODULE_ALIAS("aes");
diff --git a/arch/x86/crypto/aes_64.c b/arch/x86/crypto/aes_64.c
deleted file mode 100644
index 5cdb13ea5cc2..000000000000
--- a/arch/x86/crypto/aes_64.c
+++ /dev/null
@@ -1,336 +0,0 @@
1/*
2 * Cryptographic API.
3 *
4 * AES Cipher Algorithm.
5 *
6 * Based on Brian Gladman's code.
7 *
8 * Linux developers:
9 * Alexander Kjeldaas <astor@fast.no>
10 * Herbert Valerio Riedel <hvr@hvrlab.org>
11 * Kyle McMartin <kyle@debian.org>
12 * Adam J. Richter <adam@yggdrasil.com> (conversion to 2.5 API).
13 * Andreas Steinmetz <ast@domdv.de> (adapted to x86_64 assembler)
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * ---------------------------------------------------------------------------
21 * Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
22 * All rights reserved.
23 *
24 * LICENSE TERMS
25 *
26 * The free distribution and use of this software in both source and binary
27 * form is allowed (with or without changes) provided that:
28 *
29 * 1. distributions of this source code include the above copyright
30 * notice, this list of conditions and the following disclaimer;
31 *
32 * 2. distributions in binary form include the above copyright
33 * notice, this list of conditions and the following disclaimer
34 * in the documentation and/or other associated materials;
35 *
36 * 3. the copyright holder's name is not used to endorse products
37 * built using this software without specific written permission.
38 *
39 * ALTERNATIVELY, provided that this notice is retained in full, this product
40 * may be distributed under the terms of the GNU General Public License (GPL),
41 * in which case the provisions of the GPL apply INSTEAD OF those given above.
42 *
43 * DISCLAIMER
44 *
45 * This software is provided 'as is' with no explicit or implied warranties
46 * in respect of its properties, including, but not limited to, correctness
47 * and/or fitness for purpose.
48 * ---------------------------------------------------------------------------
49 */
50
51/* Some changes from the Gladman version:
52 s/RIJNDAEL(e_key)/E_KEY/g
53 s/RIJNDAEL(d_key)/D_KEY/g
54*/
55
56#include <asm/byteorder.h>
57#include <linux/bitops.h>
58#include <linux/crypto.h>
59#include <linux/errno.h>
60#include <linux/init.h>
61#include <linux/module.h>
62#include <linux/types.h>
63
64#define AES_MIN_KEY_SIZE 16
65#define AES_MAX_KEY_SIZE 32
66
67#define AES_BLOCK_SIZE 16
68
69/*
70 * #define byte(x, nr) ((unsigned char)((x) >> (nr*8)))
71 */
72static inline u8 byte(const u32 x, const unsigned n)
73{
74 return x >> (n << 3);
75}
76
77struct aes_ctx
78{
79 u32 key_length;
80 u32 buf[120];
81};
82
83#define E_KEY (&ctx->buf[0])
84#define D_KEY (&ctx->buf[60])
85
86static u8 pow_tab[256] __initdata;
87static u8 log_tab[256] __initdata;
88static u8 sbx_tab[256] __initdata;
89static u8 isb_tab[256] __initdata;
90static u32 rco_tab[10];
91u32 aes_ft_tab[4][256];
92u32 aes_it_tab[4][256];
93
94u32 aes_fl_tab[4][256];
95u32 aes_il_tab[4][256];
96
97static inline u8 f_mult(u8 a, u8 b)
98{
99 u8 aa = log_tab[a], cc = aa + log_tab[b];
100
101 return pow_tab[cc + (cc < aa ? 1 : 0)];
102}
103
104#define ff_mult(a, b) (a && b ? f_mult(a, b) : 0)
105
106#define ls_box(x) \
107 (aes_fl_tab[0][byte(x, 0)] ^ \
108 aes_fl_tab[1][byte(x, 1)] ^ \
109 aes_fl_tab[2][byte(x, 2)] ^ \
110 aes_fl_tab[3][byte(x, 3)])
111
112static void __init gen_tabs(void)
113{
114 u32 i, t;
115 u8 p, q;
116
117 /* log and power tables for GF(2**8) finite field with
118 0x011b as modular polynomial - the simplest primitive
119 root is 0x03, used here to generate the tables */
120
121 for (i = 0, p = 1; i < 256; ++i) {
122 pow_tab[i] = (u8)p;
123 log_tab[p] = (u8)i;
124
125 p ^= (p << 1) ^ (p & 0x80 ? 0x01b : 0);
126 }
127
128 log_tab[1] = 0;
129
130 for (i = 0, p = 1; i < 10; ++i) {
131 rco_tab[i] = p;
132
133 p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
134 }
135
136 for (i = 0; i < 256; ++i) {
137 p = (i ? pow_tab[255 - log_tab[i]] : 0);
138 q = ((p >> 7) | (p << 1)) ^ ((p >> 6) | (p << 2));
139 p ^= 0x63 ^ q ^ ((q >> 6) | (q << 2));
140 sbx_tab[i] = p;
141 isb_tab[p] = (u8)i;
142 }
143
144 for (i = 0; i < 256; ++i) {
145 p = sbx_tab[i];
146
147 t = p;
148 aes_fl_tab[0][i] = t;
149 aes_fl_tab[1][i] = rol32(t, 8);
150 aes_fl_tab[2][i] = rol32(t, 16);
151 aes_fl_tab[3][i] = rol32(t, 24);
152
153 t = ((u32)ff_mult(2, p)) |
154 ((u32)p << 8) |
155 ((u32)p << 16) | ((u32)ff_mult(3, p) << 24);
156
157 aes_ft_tab[0][i] = t;
158 aes_ft_tab[1][i] = rol32(t, 8);
159 aes_ft_tab[2][i] = rol32(t, 16);
160 aes_ft_tab[3][i] = rol32(t, 24);
161
162 p = isb_tab[i];
163
164 t = p;
165 aes_il_tab[0][i] = t;
166 aes_il_tab[1][i] = rol32(t, 8);
167 aes_il_tab[2][i] = rol32(t, 16);
168 aes_il_tab[3][i] = rol32(t, 24);
169
170 t = ((u32)ff_mult(14, p)) |
171 ((u32)ff_mult(9, p) << 8) |
172 ((u32)ff_mult(13, p) << 16) |
173 ((u32)ff_mult(11, p) << 24);
174
175 aes_it_tab[0][i] = t;
176 aes_it_tab[1][i] = rol32(t, 8);
177 aes_it_tab[2][i] = rol32(t, 16);
178 aes_it_tab[3][i] = rol32(t, 24);
179 }
180}
181
182#define star_x(x) (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
183
184#define imix_col(y, x) \
185 u = star_x(x); \
186 v = star_x(u); \
187 w = star_x(v); \
188 t = w ^ (x); \
189 (y) = u ^ v ^ w; \
190 (y) ^= ror32(u ^ t, 8) ^ \
191 ror32(v ^ t, 16) ^ \
192 ror32(t, 24)
193
194/* initialise the key schedule from the user supplied key */
195
196#define loop4(i) \
197{ \
198 t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
199 t ^= E_KEY[4 * i]; E_KEY[4 * i + 4] = t; \
200 t ^= E_KEY[4 * i + 1]; E_KEY[4 * i + 5] = t; \
201 t ^= E_KEY[4 * i + 2]; E_KEY[4 * i + 6] = t; \
202 t ^= E_KEY[4 * i + 3]; E_KEY[4 * i + 7] = t; \
203}
204
205#define loop6(i) \
206{ \
207 t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
208 t ^= E_KEY[6 * i]; E_KEY[6 * i + 6] = t; \
209 t ^= E_KEY[6 * i + 1]; E_KEY[6 * i + 7] = t; \
210 t ^= E_KEY[6 * i + 2]; E_KEY[6 * i + 8] = t; \
211 t ^= E_KEY[6 * i + 3]; E_KEY[6 * i + 9] = t; \
212 t ^= E_KEY[6 * i + 4]; E_KEY[6 * i + 10] = t; \
213 t ^= E_KEY[6 * i + 5]; E_KEY[6 * i + 11] = t; \
214}
215
216#define loop8(i) \
217{ \
218 t = ror32(t, 8); ; t = ls_box(t) ^ rco_tab[i]; \
219 t ^= E_KEY[8 * i]; E_KEY[8 * i + 8] = t; \
220 t ^= E_KEY[8 * i + 1]; E_KEY[8 * i + 9] = t; \
221 t ^= E_KEY[8 * i + 2]; E_KEY[8 * i + 10] = t; \
222 t ^= E_KEY[8 * i + 3]; E_KEY[8 * i + 11] = t; \
223 t = E_KEY[8 * i + 4] ^ ls_box(t); \
224 E_KEY[8 * i + 12] = t; \
225 t ^= E_KEY[8 * i + 5]; E_KEY[8 * i + 13] = t; \
226 t ^= E_KEY[8 * i + 6]; E_KEY[8 * i + 14] = t; \
227 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
228}
229
230static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
231 unsigned int key_len)
232{
233 struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
234 const __le32 *key = (const __le32 *)in_key;
235 u32 *flags = &tfm->crt_flags;
236 u32 i, j, t, u, v, w;
237
238 if (key_len % 8) {
239 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
240 return -EINVAL;
241 }
242
243 ctx->key_length = key_len;
244
245 D_KEY[key_len + 24] = E_KEY[0] = le32_to_cpu(key[0]);
246 D_KEY[key_len + 25] = E_KEY[1] = le32_to_cpu(key[1]);
247 D_KEY[key_len + 26] = E_KEY[2] = le32_to_cpu(key[2]);
248 D_KEY[key_len + 27] = E_KEY[3] = le32_to_cpu(key[3]);
249
250 switch (key_len) {
251 case 16:
252 t = E_KEY[3];
253 for (i = 0; i < 10; ++i)
254 loop4(i);
255 break;
256
257 case 24:
258 E_KEY[4] = le32_to_cpu(key[4]);
259 t = E_KEY[5] = le32_to_cpu(key[5]);
260 for (i = 0; i < 8; ++i)
261 loop6 (i);
262 break;
263
264 case 32:
265 E_KEY[4] = le32_to_cpu(key[4]);
266 E_KEY[5] = le32_to_cpu(key[5]);
267 E_KEY[6] = le32_to_cpu(key[6]);
268 t = E_KEY[7] = le32_to_cpu(key[7]);
269 for (i = 0; i < 7; ++i)
270 loop8(i);
271 break;
272 }
273
274 D_KEY[0] = E_KEY[key_len + 24];
275 D_KEY[1] = E_KEY[key_len + 25];
276 D_KEY[2] = E_KEY[key_len + 26];
277 D_KEY[3] = E_KEY[key_len + 27];
278
279 for (i = 4; i < key_len + 24; ++i) {
280 j = key_len + 24 - (i & ~3) + (i & 3);
281 imix_col(D_KEY[j], E_KEY[i]);
282 }
283
284 return 0;
285}
286
287asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
288asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
289
290static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
291{
292 aes_enc_blk(tfm, dst, src);
293}
294
295static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
296{
297 aes_dec_blk(tfm, dst, src);
298}
299
300static struct crypto_alg aes_alg = {
301 .cra_name = "aes",
302 .cra_driver_name = "aes-x86_64",
303 .cra_priority = 200,
304 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
305 .cra_blocksize = AES_BLOCK_SIZE,
306 .cra_ctxsize = sizeof(struct aes_ctx),
307 .cra_module = THIS_MODULE,
308 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
309 .cra_u = {
310 .cipher = {
311 .cia_min_keysize = AES_MIN_KEY_SIZE,
312 .cia_max_keysize = AES_MAX_KEY_SIZE,
313 .cia_setkey = aes_set_key,
314 .cia_encrypt = aes_encrypt,
315 .cia_decrypt = aes_decrypt
316 }
317 }
318};
319
320static int __init aes_init(void)
321{
322 gen_tabs();
323 return crypto_register_alg(&aes_alg);
324}
325
326static void __exit aes_fini(void)
327{
328 crypto_unregister_alg(&aes_alg);
329}
330
331module_init(aes_init);
332module_exit(aes_fini);
333
334MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
335MODULE_LICENSE("GPL");
336MODULE_ALIAS("aes");
diff --git a/arch/x86/crypto/aes_glue.c b/arch/x86/crypto/aes_glue.c
new file mode 100644
index 000000000000..71f457827116
--- /dev/null
+++ b/arch/x86/crypto/aes_glue.c
@@ -0,0 +1,57 @@
1/*
2 * Glue Code for the asm optimized version of the AES Cipher Algorithm
3 *
4 */
5
6#include <crypto/aes.h>
7
8asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
9asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
10
11static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
12{
13 aes_enc_blk(tfm, dst, src);
14}
15
16static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
17{
18 aes_dec_blk(tfm, dst, src);
19}
20
21static struct crypto_alg aes_alg = {
22 .cra_name = "aes",
23 .cra_driver_name = "aes-asm",
24 .cra_priority = 200,
25 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
26 .cra_blocksize = AES_BLOCK_SIZE,
27 .cra_ctxsize = sizeof(struct crypto_aes_ctx),
28 .cra_module = THIS_MODULE,
29 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
30 .cra_u = {
31 .cipher = {
32 .cia_min_keysize = AES_MIN_KEY_SIZE,
33 .cia_max_keysize = AES_MAX_KEY_SIZE,
34 .cia_setkey = crypto_aes_set_key,
35 .cia_encrypt = aes_encrypt,
36 .cia_decrypt = aes_decrypt
37 }
38 }
39};
40
41static int __init aes_init(void)
42{
43 return crypto_register_alg(&aes_alg);
44}
45
46static void __exit aes_fini(void)
47{
48 crypto_unregister_alg(&aes_alg);
49}
50
51module_init(aes_init);
52module_exit(aes_fini);
53
54MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, asm optimized");
55MODULE_LICENSE("GPL");
56MODULE_ALIAS("aes");
57MODULE_ALIAS("aes-asm");
diff --git a/arch/x86/crypto/salsa20-i586-asm_32.S b/arch/x86/crypto/salsa20-i586-asm_32.S
new file mode 100644
index 000000000000..72eb306680b2
--- /dev/null
+++ b/arch/x86/crypto/salsa20-i586-asm_32.S
@@ -0,0 +1,1114 @@
1# salsa20_pm.s version 20051229
2# D. J. Bernstein
3# Public domain.
4
5# enter ECRYPT_encrypt_bytes
6.text
7.p2align 5
8.globl ECRYPT_encrypt_bytes
9ECRYPT_encrypt_bytes:
10 mov %esp,%eax
11 and $31,%eax
12 add $256,%eax
13 sub %eax,%esp
14 # eax_stack = eax
15 movl %eax,80(%esp)
16 # ebx_stack = ebx
17 movl %ebx,84(%esp)
18 # esi_stack = esi
19 movl %esi,88(%esp)
20 # edi_stack = edi
21 movl %edi,92(%esp)
22 # ebp_stack = ebp
23 movl %ebp,96(%esp)
24 # x = arg1
25 movl 4(%esp,%eax),%edx
26 # m = arg2
27 movl 8(%esp,%eax),%esi
28 # out = arg3
29 movl 12(%esp,%eax),%edi
30 # bytes = arg4
31 movl 16(%esp,%eax),%ebx
32 # bytes -= 0
33 sub $0,%ebx
34 # goto done if unsigned<=
35 jbe ._done
36._start:
37 # in0 = *(uint32 *) (x + 0)
38 movl 0(%edx),%eax
39 # in1 = *(uint32 *) (x + 4)
40 movl 4(%edx),%ecx
41 # in2 = *(uint32 *) (x + 8)
42 movl 8(%edx),%ebp
43 # j0 = in0
44 movl %eax,164(%esp)
45 # in3 = *(uint32 *) (x + 12)
46 movl 12(%edx),%eax
47 # j1 = in1
48 movl %ecx,168(%esp)
49 # in4 = *(uint32 *) (x + 16)
50 movl 16(%edx),%ecx
51 # j2 = in2
52 movl %ebp,172(%esp)
53 # in5 = *(uint32 *) (x + 20)
54 movl 20(%edx),%ebp
55 # j3 = in3
56 movl %eax,176(%esp)
57 # in6 = *(uint32 *) (x + 24)
58 movl 24(%edx),%eax
59 # j4 = in4
60 movl %ecx,180(%esp)
61 # in7 = *(uint32 *) (x + 28)
62 movl 28(%edx),%ecx
63 # j5 = in5
64 movl %ebp,184(%esp)
65 # in8 = *(uint32 *) (x + 32)
66 movl 32(%edx),%ebp
67 # j6 = in6
68 movl %eax,188(%esp)
69 # in9 = *(uint32 *) (x + 36)
70 movl 36(%edx),%eax
71 # j7 = in7
72 movl %ecx,192(%esp)
73 # in10 = *(uint32 *) (x + 40)
74 movl 40(%edx),%ecx
75 # j8 = in8
76 movl %ebp,196(%esp)
77 # in11 = *(uint32 *) (x + 44)
78 movl 44(%edx),%ebp
79 # j9 = in9
80 movl %eax,200(%esp)
81 # in12 = *(uint32 *) (x + 48)
82 movl 48(%edx),%eax
83 # j10 = in10
84 movl %ecx,204(%esp)
85 # in13 = *(uint32 *) (x + 52)
86 movl 52(%edx),%ecx
87 # j11 = in11
88 movl %ebp,208(%esp)
89 # in14 = *(uint32 *) (x + 56)
90 movl 56(%edx),%ebp
91 # j12 = in12
92 movl %eax,212(%esp)
93 # in15 = *(uint32 *) (x + 60)
94 movl 60(%edx),%eax
95 # j13 = in13
96 movl %ecx,216(%esp)
97 # j14 = in14
98 movl %ebp,220(%esp)
99 # j15 = in15
100 movl %eax,224(%esp)
101 # x_backup = x
102 movl %edx,64(%esp)
103._bytesatleast1:
104 # bytes - 64
105 cmp $64,%ebx
106 # goto nocopy if unsigned>=
107 jae ._nocopy
108 # ctarget = out
109 movl %edi,228(%esp)
110 # out = &tmp
111 leal 0(%esp),%edi
112 # i = bytes
113 mov %ebx,%ecx
114 # while (i) { *out++ = *m++; --i }
115 rep movsb
116 # out = &tmp
117 leal 0(%esp),%edi
118 # m = &tmp
119 leal 0(%esp),%esi
120._nocopy:
121 # out_backup = out
122 movl %edi,72(%esp)
123 # m_backup = m
124 movl %esi,68(%esp)
125 # bytes_backup = bytes
126 movl %ebx,76(%esp)
127 # in0 = j0
128 movl 164(%esp),%eax
129 # in1 = j1
130 movl 168(%esp),%ecx
131 # in2 = j2
132 movl 172(%esp),%edx
133 # in3 = j3
134 movl 176(%esp),%ebx
135 # x0 = in0
136 movl %eax,100(%esp)
137 # x1 = in1
138 movl %ecx,104(%esp)
139 # x2 = in2
140 movl %edx,108(%esp)
141 # x3 = in3
142 movl %ebx,112(%esp)
143 # in4 = j4
144 movl 180(%esp),%eax
145 # in5 = j5
146 movl 184(%esp),%ecx
147 # in6 = j6
148 movl 188(%esp),%edx
149 # in7 = j7
150 movl 192(%esp),%ebx
151 # x4 = in4
152 movl %eax,116(%esp)
153 # x5 = in5
154 movl %ecx,120(%esp)
155 # x6 = in6
156 movl %edx,124(%esp)
157 # x7 = in7
158 movl %ebx,128(%esp)
159 # in8 = j8
160 movl 196(%esp),%eax
161 # in9 = j9
162 movl 200(%esp),%ecx
163 # in10 = j10
164 movl 204(%esp),%edx
165 # in11 = j11
166 movl 208(%esp),%ebx
167 # x8 = in8
168 movl %eax,132(%esp)
169 # x9 = in9
170 movl %ecx,136(%esp)
171 # x10 = in10
172 movl %edx,140(%esp)
173 # x11 = in11
174 movl %ebx,144(%esp)
175 # in12 = j12
176 movl 212(%esp),%eax
177 # in13 = j13
178 movl 216(%esp),%ecx
179 # in14 = j14
180 movl 220(%esp),%edx
181 # in15 = j15
182 movl 224(%esp),%ebx
183 # x12 = in12
184 movl %eax,148(%esp)
185 # x13 = in13
186 movl %ecx,152(%esp)
187 # x14 = in14
188 movl %edx,156(%esp)
189 # x15 = in15
190 movl %ebx,160(%esp)
191 # i = 20
192 mov $20,%ebp
193 # p = x0
194 movl 100(%esp),%eax
195 # s = x5
196 movl 120(%esp),%ecx
197 # t = x10
198 movl 140(%esp),%edx
199 # w = x15
200 movl 160(%esp),%ebx
201._mainloop:
202 # x0 = p
203 movl %eax,100(%esp)
204 # x10 = t
205 movl %edx,140(%esp)
206 # p += x12
207 addl 148(%esp),%eax
208 # x5 = s
209 movl %ecx,120(%esp)
210 # t += x6
211 addl 124(%esp),%edx
212 # x15 = w
213 movl %ebx,160(%esp)
214 # r = x1
215 movl 104(%esp),%esi
216 # r += s
217 add %ecx,%esi
218 # v = x11
219 movl 144(%esp),%edi
220 # v += w
221 add %ebx,%edi
222 # p <<<= 7
223 rol $7,%eax
224 # p ^= x4
225 xorl 116(%esp),%eax
226 # t <<<= 7
227 rol $7,%edx
228 # t ^= x14
229 xorl 156(%esp),%edx
230 # r <<<= 7
231 rol $7,%esi
232 # r ^= x9
233 xorl 136(%esp),%esi
234 # v <<<= 7
235 rol $7,%edi
236 # v ^= x3
237 xorl 112(%esp),%edi
238 # x4 = p
239 movl %eax,116(%esp)
240 # x14 = t
241 movl %edx,156(%esp)
242 # p += x0
243 addl 100(%esp),%eax
244 # x9 = r
245 movl %esi,136(%esp)
246 # t += x10
247 addl 140(%esp),%edx
248 # x3 = v
249 movl %edi,112(%esp)
250 # p <<<= 9
251 rol $9,%eax
252 # p ^= x8
253 xorl 132(%esp),%eax
254 # t <<<= 9
255 rol $9,%edx
256 # t ^= x2
257 xorl 108(%esp),%edx
258 # s += r
259 add %esi,%ecx
260 # s <<<= 9
261 rol $9,%ecx
262 # s ^= x13
263 xorl 152(%esp),%ecx
264 # w += v
265 add %edi,%ebx
266 # w <<<= 9
267 rol $9,%ebx
268 # w ^= x7
269 xorl 128(%esp),%ebx
270 # x8 = p
271 movl %eax,132(%esp)
272 # x2 = t
273 movl %edx,108(%esp)
274 # p += x4
275 addl 116(%esp),%eax
276 # x13 = s
277 movl %ecx,152(%esp)
278 # t += x14
279 addl 156(%esp),%edx
280 # x7 = w
281 movl %ebx,128(%esp)
282 # p <<<= 13
283 rol $13,%eax
284 # p ^= x12
285 xorl 148(%esp),%eax
286 # t <<<= 13
287 rol $13,%edx
288 # t ^= x6
289 xorl 124(%esp),%edx
290 # r += s
291 add %ecx,%esi
292 # r <<<= 13
293 rol $13,%esi
294 # r ^= x1
295 xorl 104(%esp),%esi
296 # v += w
297 add %ebx,%edi
298 # v <<<= 13
299 rol $13,%edi
300 # v ^= x11
301 xorl 144(%esp),%edi
302 # x12 = p
303 movl %eax,148(%esp)
304 # x6 = t
305 movl %edx,124(%esp)
306 # p += x8
307 addl 132(%esp),%eax
308 # x1 = r
309 movl %esi,104(%esp)
310 # t += x2
311 addl 108(%esp),%edx
312 # x11 = v
313 movl %edi,144(%esp)
314 # p <<<= 18
315 rol $18,%eax
316 # p ^= x0
317 xorl 100(%esp),%eax
318 # t <<<= 18
319 rol $18,%edx
320 # t ^= x10
321 xorl 140(%esp),%edx
322 # s += r
323 add %esi,%ecx
324 # s <<<= 18
325 rol $18,%ecx
326 # s ^= x5
327 xorl 120(%esp),%ecx
328 # w += v
329 add %edi,%ebx
330 # w <<<= 18
331 rol $18,%ebx
332 # w ^= x15
333 xorl 160(%esp),%ebx
334 # x0 = p
335 movl %eax,100(%esp)
336 # x10 = t
337 movl %edx,140(%esp)
338 # p += x3
339 addl 112(%esp),%eax
340 # p <<<= 7
341 rol $7,%eax
342 # x5 = s
343 movl %ecx,120(%esp)
344 # t += x9
345 addl 136(%esp),%edx
346 # x15 = w
347 movl %ebx,160(%esp)
348 # r = x4
349 movl 116(%esp),%esi
350 # r += s
351 add %ecx,%esi
352 # v = x14
353 movl 156(%esp),%edi
354 # v += w
355 add %ebx,%edi
356 # p ^= x1
357 xorl 104(%esp),%eax
358 # t <<<= 7
359 rol $7,%edx
360 # t ^= x11
361 xorl 144(%esp),%edx
362 # r <<<= 7
363 rol $7,%esi
364 # r ^= x6
365 xorl 124(%esp),%esi
366 # v <<<= 7
367 rol $7,%edi
368 # v ^= x12
369 xorl 148(%esp),%edi
370 # x1 = p
371 movl %eax,104(%esp)
372 # x11 = t
373 movl %edx,144(%esp)
374 # p += x0
375 addl 100(%esp),%eax
376 # x6 = r
377 movl %esi,124(%esp)
378 # t += x10
379 addl 140(%esp),%edx
380 # x12 = v
381 movl %edi,148(%esp)
382 # p <<<= 9
383 rol $9,%eax
384 # p ^= x2
385 xorl 108(%esp),%eax
386 # t <<<= 9
387 rol $9,%edx
388 # t ^= x8
389 xorl 132(%esp),%edx
390 # s += r
391 add %esi,%ecx
392 # s <<<= 9
393 rol $9,%ecx
394 # s ^= x7
395 xorl 128(%esp),%ecx
396 # w += v
397 add %edi,%ebx
398 # w <<<= 9
399 rol $9,%ebx
400 # w ^= x13
401 xorl 152(%esp),%ebx
402 # x2 = p
403 movl %eax,108(%esp)
404 # x8 = t
405 movl %edx,132(%esp)
406 # p += x1
407 addl 104(%esp),%eax
408 # x7 = s
409 movl %ecx,128(%esp)
410 # t += x11
411 addl 144(%esp),%edx
412 # x13 = w
413 movl %ebx,152(%esp)
414 # p <<<= 13
415 rol $13,%eax
416 # p ^= x3
417 xorl 112(%esp),%eax
418 # t <<<= 13
419 rol $13,%edx
420 # t ^= x9
421 xorl 136(%esp),%edx
422 # r += s
423 add %ecx,%esi
424 # r <<<= 13
425 rol $13,%esi
426 # r ^= x4
427 xorl 116(%esp),%esi
428 # v += w
429 add %ebx,%edi
430 # v <<<= 13
431 rol $13,%edi
432 # v ^= x14
433 xorl 156(%esp),%edi
434 # x3 = p
435 movl %eax,112(%esp)
436 # x9 = t
437 movl %edx,136(%esp)
438 # p += x2
439 addl 108(%esp),%eax
440 # x4 = r
441 movl %esi,116(%esp)
442 # t += x8
443 addl 132(%esp),%edx
444 # x14 = v
445 movl %edi,156(%esp)
446 # p <<<= 18
447 rol $18,%eax
448 # p ^= x0
449 xorl 100(%esp),%eax
450 # t <<<= 18
451 rol $18,%edx
452 # t ^= x10
453 xorl 140(%esp),%edx
454 # s += r
455 add %esi,%ecx
456 # s <<<= 18
457 rol $18,%ecx
458 # s ^= x5
459 xorl 120(%esp),%ecx
460 # w += v
461 add %edi,%ebx
462 # w <<<= 18
463 rol $18,%ebx
464 # w ^= x15
465 xorl 160(%esp),%ebx
466 # x0 = p
467 movl %eax,100(%esp)
468 # x10 = t
469 movl %edx,140(%esp)
470 # p += x12
471 addl 148(%esp),%eax
472 # x5 = s
473 movl %ecx,120(%esp)
474 # t += x6
475 addl 124(%esp),%edx
476 # x15 = w
477 movl %ebx,160(%esp)
478 # r = x1
479 movl 104(%esp),%esi
480 # r += s
481 add %ecx,%esi
482 # v = x11
483 movl 144(%esp),%edi
484 # v += w
485 add %ebx,%edi
486 # p <<<= 7
487 rol $7,%eax
488 # p ^= x4
489 xorl 116(%esp),%eax
490 # t <<<= 7
491 rol $7,%edx
492 # t ^= x14
493 xorl 156(%esp),%edx
494 # r <<<= 7
495 rol $7,%esi
496 # r ^= x9
497 xorl 136(%esp),%esi
498 # v <<<= 7
499 rol $7,%edi
500 # v ^= x3
501 xorl 112(%esp),%edi
502 # x4 = p
503 movl %eax,116(%esp)
504 # x14 = t
505 movl %edx,156(%esp)
506 # p += x0
507 addl 100(%esp),%eax
508 # x9 = r
509 movl %esi,136(%esp)
510 # t += x10
511 addl 140(%esp),%edx
512 # x3 = v
513 movl %edi,112(%esp)
514 # p <<<= 9
515 rol $9,%eax
516 # p ^= x8
517 xorl 132(%esp),%eax
518 # t <<<= 9
519 rol $9,%edx
520 # t ^= x2
521 xorl 108(%esp),%edx
522 # s += r
523 add %esi,%ecx
524 # s <<<= 9
525 rol $9,%ecx
526 # s ^= x13
527 xorl 152(%esp),%ecx
528 # w += v
529 add %edi,%ebx
530 # w <<<= 9
531 rol $9,%ebx
532 # w ^= x7
533 xorl 128(%esp),%ebx
534 # x8 = p
535 movl %eax,132(%esp)
536 # x2 = t
537 movl %edx,108(%esp)
538 # p += x4
539 addl 116(%esp),%eax
540 # x13 = s
541 movl %ecx,152(%esp)
542 # t += x14
543 addl 156(%esp),%edx
544 # x7 = w
545 movl %ebx,128(%esp)
546 # p <<<= 13
547 rol $13,%eax
548 # p ^= x12
549 xorl 148(%esp),%eax
550 # t <<<= 13
551 rol $13,%edx
552 # t ^= x6
553 xorl 124(%esp),%edx
554 # r += s
555 add %ecx,%esi
556 # r <<<= 13
557 rol $13,%esi
558 # r ^= x1
559 xorl 104(%esp),%esi
560 # v += w
561 add %ebx,%edi
562 # v <<<= 13
563 rol $13,%edi
564 # v ^= x11
565 xorl 144(%esp),%edi
566 # x12 = p
567 movl %eax,148(%esp)
568 # x6 = t
569 movl %edx,124(%esp)
570 # p += x8
571 addl 132(%esp),%eax
572 # x1 = r
573 movl %esi,104(%esp)
574 # t += x2
575 addl 108(%esp),%edx
576 # x11 = v
577 movl %edi,144(%esp)
578 # p <<<= 18
579 rol $18,%eax
580 # p ^= x0
581 xorl 100(%esp),%eax
582 # t <<<= 18
583 rol $18,%edx
584 # t ^= x10
585 xorl 140(%esp),%edx
586 # s += r
587 add %esi,%ecx
588 # s <<<= 18
589 rol $18,%ecx
590 # s ^= x5
591 xorl 120(%esp),%ecx
592 # w += v
593 add %edi,%ebx
594 # w <<<= 18
595 rol $18,%ebx
596 # w ^= x15
597 xorl 160(%esp),%ebx
598 # x0 = p
599 movl %eax,100(%esp)
600 # x10 = t
601 movl %edx,140(%esp)
602 # p += x3
603 addl 112(%esp),%eax
604 # p <<<= 7
605 rol $7,%eax
606 # x5 = s
607 movl %ecx,120(%esp)
608 # t += x9
609 addl 136(%esp),%edx
610 # x15 = w
611 movl %ebx,160(%esp)
612 # r = x4
613 movl 116(%esp),%esi
614 # r += s
615 add %ecx,%esi
616 # v = x14
617 movl 156(%esp),%edi
618 # v += w
619 add %ebx,%edi
620 # p ^= x1
621 xorl 104(%esp),%eax
622 # t <<<= 7
623 rol $7,%edx
624 # t ^= x11
625 xorl 144(%esp),%edx
626 # r <<<= 7
627 rol $7,%esi
628 # r ^= x6
629 xorl 124(%esp),%esi
630 # v <<<= 7
631 rol $7,%edi
632 # v ^= x12
633 xorl 148(%esp),%edi
634 # x1 = p
635 movl %eax,104(%esp)
636 # x11 = t
637 movl %edx,144(%esp)
638 # p += x0
639 addl 100(%esp),%eax
640 # x6 = r
641 movl %esi,124(%esp)
642 # t += x10
643 addl 140(%esp),%edx
644 # x12 = v
645 movl %edi,148(%esp)
646 # p <<<= 9
647 rol $9,%eax
648 # p ^= x2
649 xorl 108(%esp),%eax
650 # t <<<= 9
651 rol $9,%edx
652 # t ^= x8
653 xorl 132(%esp),%edx
654 # s += r
655 add %esi,%ecx
656 # s <<<= 9
657 rol $9,%ecx
658 # s ^= x7
659 xorl 128(%esp),%ecx
660 # w += v
661 add %edi,%ebx
662 # w <<<= 9
663 rol $9,%ebx
664 # w ^= x13
665 xorl 152(%esp),%ebx
666 # x2 = p
667 movl %eax,108(%esp)
668 # x8 = t
669 movl %edx,132(%esp)
670 # p += x1
671 addl 104(%esp),%eax
672 # x7 = s
673 movl %ecx,128(%esp)
674 # t += x11
675 addl 144(%esp),%edx
676 # x13 = w
677 movl %ebx,152(%esp)
678 # p <<<= 13
679 rol $13,%eax
680 # p ^= x3
681 xorl 112(%esp),%eax
682 # t <<<= 13
683 rol $13,%edx
684 # t ^= x9
685 xorl 136(%esp),%edx
686 # r += s
687 add %ecx,%esi
688 # r <<<= 13
689 rol $13,%esi
690 # r ^= x4
691 xorl 116(%esp),%esi
692 # v += w
693 add %ebx,%edi
694 # v <<<= 13
695 rol $13,%edi
696 # v ^= x14
697 xorl 156(%esp),%edi
698 # x3 = p
699 movl %eax,112(%esp)
700 # x9 = t
701 movl %edx,136(%esp)
702 # p += x2
703 addl 108(%esp),%eax
704 # x4 = r
705 movl %esi,116(%esp)
706 # t += x8
707 addl 132(%esp),%edx
708 # x14 = v
709 movl %edi,156(%esp)
710 # p <<<= 18
711 rol $18,%eax
712 # p ^= x0
713 xorl 100(%esp),%eax
714 # t <<<= 18
715 rol $18,%edx
716 # t ^= x10
717 xorl 140(%esp),%edx
718 # s += r
719 add %esi,%ecx
720 # s <<<= 18
721 rol $18,%ecx
722 # s ^= x5
723 xorl 120(%esp),%ecx
724 # w += v
725 add %edi,%ebx
726 # w <<<= 18
727 rol $18,%ebx
728 # w ^= x15
729 xorl 160(%esp),%ebx
730 # i -= 4
731 sub $4,%ebp
732 # goto mainloop if unsigned >
733 ja ._mainloop
734 # x0 = p
735 movl %eax,100(%esp)
736 # x5 = s
737 movl %ecx,120(%esp)
738 # x10 = t
739 movl %edx,140(%esp)
740 # x15 = w
741 movl %ebx,160(%esp)
742 # out = out_backup
743 movl 72(%esp),%edi
744 # m = m_backup
745 movl 68(%esp),%esi
746 # in0 = x0
747 movl 100(%esp),%eax
748 # in1 = x1
749 movl 104(%esp),%ecx
750 # in0 += j0
751 addl 164(%esp),%eax
752 # in1 += j1
753 addl 168(%esp),%ecx
754 # in0 ^= *(uint32 *) (m + 0)
755 xorl 0(%esi),%eax
756 # in1 ^= *(uint32 *) (m + 4)
757 xorl 4(%esi),%ecx
758 # *(uint32 *) (out + 0) = in0
759 movl %eax,0(%edi)
760 # *(uint32 *) (out + 4) = in1
761 movl %ecx,4(%edi)
762 # in2 = x2
763 movl 108(%esp),%eax
764 # in3 = x3
765 movl 112(%esp),%ecx
766 # in2 += j2
767 addl 172(%esp),%eax
768 # in3 += j3
769 addl 176(%esp),%ecx
770 # in2 ^= *(uint32 *) (m + 8)
771 xorl 8(%esi),%eax
772 # in3 ^= *(uint32 *) (m + 12)
773 xorl 12(%esi),%ecx
774 # *(uint32 *) (out + 8) = in2
775 movl %eax,8(%edi)
776 # *(uint32 *) (out + 12) = in3
777 movl %ecx,12(%edi)
778 # in4 = x4
779 movl 116(%esp),%eax
780 # in5 = x5
781 movl 120(%esp),%ecx
782 # in4 += j4
783 addl 180(%esp),%eax
784 # in5 += j5
785 addl 184(%esp),%ecx
786 # in4 ^= *(uint32 *) (m + 16)
787 xorl 16(%esi),%eax
788 # in5 ^= *(uint32 *) (m + 20)
789 xorl 20(%esi),%ecx
790 # *(uint32 *) (out + 16) = in4
791 movl %eax,16(%edi)
792 # *(uint32 *) (out + 20) = in5
793 movl %ecx,20(%edi)
794 # in6 = x6
795 movl 124(%esp),%eax
796 # in7 = x7
797 movl 128(%esp),%ecx
798 # in6 += j6
799 addl 188(%esp),%eax
800 # in7 += j7
801 addl 192(%esp),%ecx
802 # in6 ^= *(uint32 *) (m + 24)
803 xorl 24(%esi),%eax
804 # in7 ^= *(uint32 *) (m + 28)
805 xorl 28(%esi),%ecx
806 # *(uint32 *) (out + 24) = in6
807 movl %eax,24(%edi)
808 # *(uint32 *) (out + 28) = in7
809 movl %ecx,28(%edi)
810 # in8 = x8
811 movl 132(%esp),%eax
812 # in9 = x9
813 movl 136(%esp),%ecx
814 # in8 += j8
815 addl 196(%esp),%eax
816 # in9 += j9
817 addl 200(%esp),%ecx
818 # in8 ^= *(uint32 *) (m + 32)
819 xorl 32(%esi),%eax
820 # in9 ^= *(uint32 *) (m + 36)
821 xorl 36(%esi),%ecx
822 # *(uint32 *) (out + 32) = in8
823 movl %eax,32(%edi)
824 # *(uint32 *) (out + 36) = in9
825 movl %ecx,36(%edi)
826 # in10 = x10
827 movl 140(%esp),%eax
828 # in11 = x11
829 movl 144(%esp),%ecx
830 # in10 += j10
831 addl 204(%esp),%eax
832 # in11 += j11
833 addl 208(%esp),%ecx
834 # in10 ^= *(uint32 *) (m + 40)
835 xorl 40(%esi),%eax
836 # in11 ^= *(uint32 *) (m + 44)
837 xorl 44(%esi),%ecx
838 # *(uint32 *) (out + 40) = in10
839 movl %eax,40(%edi)
840 # *(uint32 *) (out + 44) = in11
841 movl %ecx,44(%edi)
842 # in12 = x12
843 movl 148(%esp),%eax
844 # in13 = x13
845 movl 152(%esp),%ecx
846 # in12 += j12
847 addl 212(%esp),%eax
848 # in13 += j13
849 addl 216(%esp),%ecx
850 # in12 ^= *(uint32 *) (m + 48)
851 xorl 48(%esi),%eax
852 # in13 ^= *(uint32 *) (m + 52)
853 xorl 52(%esi),%ecx
854 # *(uint32 *) (out + 48) = in12
855 movl %eax,48(%edi)
856 # *(uint32 *) (out + 52) = in13
857 movl %ecx,52(%edi)
858 # in14 = x14
859 movl 156(%esp),%eax
860 # in15 = x15
861 movl 160(%esp),%ecx
862 # in14 += j14
863 addl 220(%esp),%eax
864 # in15 += j15
865 addl 224(%esp),%ecx
866 # in14 ^= *(uint32 *) (m + 56)
867 xorl 56(%esi),%eax
868 # in15 ^= *(uint32 *) (m + 60)
869 xorl 60(%esi),%ecx
870 # *(uint32 *) (out + 56) = in14
871 movl %eax,56(%edi)
872 # *(uint32 *) (out + 60) = in15
873 movl %ecx,60(%edi)
874 # bytes = bytes_backup
875 movl 76(%esp),%ebx
876 # in8 = j8
877 movl 196(%esp),%eax
878 # in9 = j9
879 movl 200(%esp),%ecx
880 # in8 += 1
881 add $1,%eax
882 # in9 += 0 + carry
883 adc $0,%ecx
884 # j8 = in8
885 movl %eax,196(%esp)
886 # j9 = in9
887 movl %ecx,200(%esp)
888 # bytes - 64
889 cmp $64,%ebx
890 # goto bytesatleast65 if unsigned>
891 ja ._bytesatleast65
892 # goto bytesatleast64 if unsigned>=
893 jae ._bytesatleast64
894 # m = out
895 mov %edi,%esi
896 # out = ctarget
897 movl 228(%esp),%edi
898 # i = bytes
899 mov %ebx,%ecx
900 # while (i) { *out++ = *m++; --i }
901 rep movsb
902._bytesatleast64:
903 # x = x_backup
904 movl 64(%esp),%eax
905 # in8 = j8
906 movl 196(%esp),%ecx
907 # in9 = j9
908 movl 200(%esp),%edx
909 # *(uint32 *) (x + 32) = in8
910 movl %ecx,32(%eax)
911 # *(uint32 *) (x + 36) = in9
912 movl %edx,36(%eax)
913._done:
914 # eax = eax_stack
915 movl 80(%esp),%eax
916 # ebx = ebx_stack
917 movl 84(%esp),%ebx
918 # esi = esi_stack
919 movl 88(%esp),%esi
920 # edi = edi_stack
921 movl 92(%esp),%edi
922 # ebp = ebp_stack
923 movl 96(%esp),%ebp
924 # leave
925 add %eax,%esp
926 ret
927._bytesatleast65:
928 # bytes -= 64
929 sub $64,%ebx
930 # out += 64
931 add $64,%edi
932 # m += 64
933 add $64,%esi
934 # goto bytesatleast1
935 jmp ._bytesatleast1
936# enter ECRYPT_keysetup
937.text
938.p2align 5
939.globl ECRYPT_keysetup
940ECRYPT_keysetup:
941 mov %esp,%eax
942 and $31,%eax
943 add $256,%eax
944 sub %eax,%esp
945 # eax_stack = eax
946 movl %eax,64(%esp)
947 # ebx_stack = ebx
948 movl %ebx,68(%esp)
949 # esi_stack = esi
950 movl %esi,72(%esp)
951 # edi_stack = edi
952 movl %edi,76(%esp)
953 # ebp_stack = ebp
954 movl %ebp,80(%esp)
955 # k = arg2
956 movl 8(%esp,%eax),%ecx
957 # kbits = arg3
958 movl 12(%esp,%eax),%edx
959 # x = arg1
960 movl 4(%esp,%eax),%eax
961 # in1 = *(uint32 *) (k + 0)
962 movl 0(%ecx),%ebx
963 # in2 = *(uint32 *) (k + 4)
964 movl 4(%ecx),%esi
965 # in3 = *(uint32 *) (k + 8)
966 movl 8(%ecx),%edi
967 # in4 = *(uint32 *) (k + 12)
968 movl 12(%ecx),%ebp
969 # *(uint32 *) (x + 4) = in1
970 movl %ebx,4(%eax)
971 # *(uint32 *) (x + 8) = in2
972 movl %esi,8(%eax)
973 # *(uint32 *) (x + 12) = in3
974 movl %edi,12(%eax)
975 # *(uint32 *) (x + 16) = in4
976 movl %ebp,16(%eax)
977 # kbits - 256
978 cmp $256,%edx
979 # goto kbits128 if unsigned<
980 jb ._kbits128
981._kbits256:
982 # in11 = *(uint32 *) (k + 16)
983 movl 16(%ecx),%edx
984 # in12 = *(uint32 *) (k + 20)
985 movl 20(%ecx),%ebx
986 # in13 = *(uint32 *) (k + 24)
987 movl 24(%ecx),%esi
988 # in14 = *(uint32 *) (k + 28)
989 movl 28(%ecx),%ecx
990 # *(uint32 *) (x + 44) = in11
991 movl %edx,44(%eax)
992 # *(uint32 *) (x + 48) = in12
993 movl %ebx,48(%eax)
994 # *(uint32 *) (x + 52) = in13
995 movl %esi,52(%eax)
996 # *(uint32 *) (x + 56) = in14
997 movl %ecx,56(%eax)
998 # in0 = 1634760805
999 mov $1634760805,%ecx
1000 # in5 = 857760878
1001 mov $857760878,%edx
1002 # in10 = 2036477234
1003 mov $2036477234,%ebx
1004 # in15 = 1797285236
1005 mov $1797285236,%esi
1006 # *(uint32 *) (x + 0) = in0
1007 movl %ecx,0(%eax)
1008 # *(uint32 *) (x + 20) = in5
1009 movl %edx,20(%eax)
1010 # *(uint32 *) (x + 40) = in10
1011 movl %ebx,40(%eax)
1012 # *(uint32 *) (x + 60) = in15
1013 movl %esi,60(%eax)
1014 # goto keysetupdone
1015 jmp ._keysetupdone
1016._kbits128:
1017 # in11 = *(uint32 *) (k + 0)
1018 movl 0(%ecx),%edx
1019 # in12 = *(uint32 *) (k + 4)
1020 movl 4(%ecx),%ebx
1021 # in13 = *(uint32 *) (k + 8)
1022 movl 8(%ecx),%esi
1023 # in14 = *(uint32 *) (k + 12)
1024 movl 12(%ecx),%ecx
1025 # *(uint32 *) (x + 44) = in11
1026 movl %edx,44(%eax)
1027 # *(uint32 *) (x + 48) = in12
1028 movl %ebx,48(%eax)
1029 # *(uint32 *) (x + 52) = in13
1030 movl %esi,52(%eax)
1031 # *(uint32 *) (x + 56) = in14
1032 movl %ecx,56(%eax)
1033 # in0 = 1634760805
1034 mov $1634760805,%ecx
1035 # in5 = 824206446
1036 mov $824206446,%edx
1037 # in10 = 2036477238
1038 mov $2036477238,%ebx
1039 # in15 = 1797285236
1040 mov $1797285236,%esi
1041 # *(uint32 *) (x + 0) = in0
1042 movl %ecx,0(%eax)
1043 # *(uint32 *) (x + 20) = in5
1044 movl %edx,20(%eax)
1045 # *(uint32 *) (x + 40) = in10
1046 movl %ebx,40(%eax)
1047 # *(uint32 *) (x + 60) = in15
1048 movl %esi,60(%eax)
1049._keysetupdone:
1050 # eax = eax_stack
1051 movl 64(%esp),%eax
1052 # ebx = ebx_stack
1053 movl 68(%esp),%ebx
1054 # esi = esi_stack
1055 movl 72(%esp),%esi
1056 # edi = edi_stack
1057 movl 76(%esp),%edi
1058 # ebp = ebp_stack
1059 movl 80(%esp),%ebp
1060 # leave
1061 add %eax,%esp
1062 ret
1063# enter ECRYPT_ivsetup
1064.text
1065.p2align 5
1066.globl ECRYPT_ivsetup
1067ECRYPT_ivsetup:
1068 mov %esp,%eax
1069 and $31,%eax
1070 add $256,%eax
1071 sub %eax,%esp
1072 # eax_stack = eax
1073 movl %eax,64(%esp)
1074 # ebx_stack = ebx
1075 movl %ebx,68(%esp)
1076 # esi_stack = esi
1077 movl %esi,72(%esp)
1078 # edi_stack = edi
1079 movl %edi,76(%esp)
1080 # ebp_stack = ebp
1081 movl %ebp,80(%esp)
1082 # iv = arg2
1083 movl 8(%esp,%eax),%ecx
1084 # x = arg1
1085 movl 4(%esp,%eax),%eax
1086 # in6 = *(uint32 *) (iv + 0)
1087 movl 0(%ecx),%edx
1088 # in7 = *(uint32 *) (iv + 4)
1089 movl 4(%ecx),%ecx
1090 # in8 = 0
1091 mov $0,%ebx
1092 # in9 = 0
1093 mov $0,%esi
1094 # *(uint32 *) (x + 24) = in6
1095 movl %edx,24(%eax)
1096 # *(uint32 *) (x + 28) = in7
1097 movl %ecx,28(%eax)
1098 # *(uint32 *) (x + 32) = in8
1099 movl %ebx,32(%eax)
1100 # *(uint32 *) (x + 36) = in9
1101 movl %esi,36(%eax)
1102 # eax = eax_stack
1103 movl 64(%esp),%eax
1104 # ebx = ebx_stack
1105 movl 68(%esp),%ebx
1106 # esi = esi_stack
1107 movl 72(%esp),%esi
1108 # edi = edi_stack
1109 movl 76(%esp),%edi
1110 # ebp = ebp_stack
1111 movl 80(%esp),%ebp
1112 # leave
1113 add %eax,%esp
1114 ret
diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
new file mode 100644
index 000000000000..6214a9b09706
--- /dev/null
+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
@@ -0,0 +1,920 @@
1# enter ECRYPT_encrypt_bytes
2.text
3.p2align 5
4.globl ECRYPT_encrypt_bytes
5ECRYPT_encrypt_bytes:
6 mov %rsp,%r11
7 and $31,%r11
8 add $256,%r11
9 sub %r11,%rsp
10 # x = arg1
11 mov %rdi,%r8
12 # m = arg2
13 mov %rsi,%rsi
14 # out = arg3
15 mov %rdx,%rdi
16 # bytes = arg4
17 mov %rcx,%rdx
18 # unsigned>? bytes - 0
19 cmp $0,%rdx
20 # comment:fp stack unchanged by jump
21 # goto done if !unsigned>
22 jbe ._done
23 # comment:fp stack unchanged by fallthrough
24# start:
25._start:
26 # r11_stack = r11
27 movq %r11,0(%rsp)
28 # r12_stack = r12
29 movq %r12,8(%rsp)
30 # r13_stack = r13
31 movq %r13,16(%rsp)
32 # r14_stack = r14
33 movq %r14,24(%rsp)
34 # r15_stack = r15
35 movq %r15,32(%rsp)
36 # rbx_stack = rbx
37 movq %rbx,40(%rsp)
38 # rbp_stack = rbp
39 movq %rbp,48(%rsp)
40 # in0 = *(uint64 *) (x + 0)
41 movq 0(%r8),%rcx
42 # in2 = *(uint64 *) (x + 8)
43 movq 8(%r8),%r9
44 # in4 = *(uint64 *) (x + 16)
45 movq 16(%r8),%rax
46 # in6 = *(uint64 *) (x + 24)
47 movq 24(%r8),%r10
48 # in8 = *(uint64 *) (x + 32)
49 movq 32(%r8),%r11
50 # in10 = *(uint64 *) (x + 40)
51 movq 40(%r8),%r12
52 # in12 = *(uint64 *) (x + 48)
53 movq 48(%r8),%r13
54 # in14 = *(uint64 *) (x + 56)
55 movq 56(%r8),%r14
56 # j0 = in0
57 movq %rcx,56(%rsp)
58 # j2 = in2
59 movq %r9,64(%rsp)
60 # j4 = in4
61 movq %rax,72(%rsp)
62 # j6 = in6
63 movq %r10,80(%rsp)
64 # j8 = in8
65 movq %r11,88(%rsp)
66 # j10 = in10
67 movq %r12,96(%rsp)
68 # j12 = in12
69 movq %r13,104(%rsp)
70 # j14 = in14
71 movq %r14,112(%rsp)
72 # x_backup = x
73 movq %r8,120(%rsp)
74# bytesatleast1:
75._bytesatleast1:
76 # unsigned<? bytes - 64
77 cmp $64,%rdx
78 # comment:fp stack unchanged by jump
79 # goto nocopy if !unsigned<
80 jae ._nocopy
81 # ctarget = out
82 movq %rdi,128(%rsp)
83 # out = &tmp
84 leaq 192(%rsp),%rdi
85 # i = bytes
86 mov %rdx,%rcx
87 # while (i) { *out++ = *m++; --i }
88 rep movsb
89 # out = &tmp
90 leaq 192(%rsp),%rdi
91 # m = &tmp
92 leaq 192(%rsp),%rsi
93 # comment:fp stack unchanged by fallthrough
94# nocopy:
95._nocopy:
96 # out_backup = out
97 movq %rdi,136(%rsp)
98 # m_backup = m
99 movq %rsi,144(%rsp)
100 # bytes_backup = bytes
101 movq %rdx,152(%rsp)
102 # x1 = j0
103 movq 56(%rsp),%rdi
104 # x0 = x1
105 mov %rdi,%rdx
106 # (uint64) x1 >>= 32
107 shr $32,%rdi
108 # x3 = j2
109 movq 64(%rsp),%rsi
110 # x2 = x3
111 mov %rsi,%rcx
112 # (uint64) x3 >>= 32
113 shr $32,%rsi
114 # x5 = j4
115 movq 72(%rsp),%r8
116 # x4 = x5
117 mov %r8,%r9
118 # (uint64) x5 >>= 32
119 shr $32,%r8
120 # x5_stack = x5
121 movq %r8,160(%rsp)
122 # x7 = j6
123 movq 80(%rsp),%r8
124 # x6 = x7
125 mov %r8,%rax
126 # (uint64) x7 >>= 32
127 shr $32,%r8
128 # x9 = j8
129 movq 88(%rsp),%r10
130 # x8 = x9
131 mov %r10,%r11
132 # (uint64) x9 >>= 32
133 shr $32,%r10
134 # x11 = j10
135 movq 96(%rsp),%r12
136 # x10 = x11
137 mov %r12,%r13
138 # x10_stack = x10
139 movq %r13,168(%rsp)
140 # (uint64) x11 >>= 32
141 shr $32,%r12
142 # x13 = j12
143 movq 104(%rsp),%r13
144 # x12 = x13
145 mov %r13,%r14
146 # (uint64) x13 >>= 32
147 shr $32,%r13
148 # x15 = j14
149 movq 112(%rsp),%r15
150 # x14 = x15
151 mov %r15,%rbx
152 # (uint64) x15 >>= 32
153 shr $32,%r15
154 # x15_stack = x15
155 movq %r15,176(%rsp)
156 # i = 20
157 mov $20,%r15
158# mainloop:
159._mainloop:
160 # i_backup = i
161 movq %r15,184(%rsp)
162 # x5 = x5_stack
163 movq 160(%rsp),%r15
164 # a = x12 + x0
165 lea (%r14,%rdx),%rbp
166 # (uint32) a <<<= 7
167 rol $7,%ebp
168 # x4 ^= a
169 xor %rbp,%r9
170 # b = x1 + x5
171 lea (%rdi,%r15),%rbp
172 # (uint32) b <<<= 7
173 rol $7,%ebp
174 # x9 ^= b
175 xor %rbp,%r10
176 # a = x0 + x4
177 lea (%rdx,%r9),%rbp
178 # (uint32) a <<<= 9
179 rol $9,%ebp
180 # x8 ^= a
181 xor %rbp,%r11
182 # b = x5 + x9
183 lea (%r15,%r10),%rbp
184 # (uint32) b <<<= 9
185 rol $9,%ebp
186 # x13 ^= b
187 xor %rbp,%r13
188 # a = x4 + x8
189 lea (%r9,%r11),%rbp
190 # (uint32) a <<<= 13
191 rol $13,%ebp
192 # x12 ^= a
193 xor %rbp,%r14
194 # b = x9 + x13
195 lea (%r10,%r13),%rbp
196 # (uint32) b <<<= 13
197 rol $13,%ebp
198 # x1 ^= b
199 xor %rbp,%rdi
200 # a = x8 + x12
201 lea (%r11,%r14),%rbp
202 # (uint32) a <<<= 18
203 rol $18,%ebp
204 # x0 ^= a
205 xor %rbp,%rdx
206 # b = x13 + x1
207 lea (%r13,%rdi),%rbp
208 # (uint32) b <<<= 18
209 rol $18,%ebp
210 # x5 ^= b
211 xor %rbp,%r15
212 # x10 = x10_stack
213 movq 168(%rsp),%rbp
214 # x5_stack = x5
215 movq %r15,160(%rsp)
216 # c = x6 + x10
217 lea (%rax,%rbp),%r15
218 # (uint32) c <<<= 7
219 rol $7,%r15d
220 # x14 ^= c
221 xor %r15,%rbx
222 # c = x10 + x14
223 lea (%rbp,%rbx),%r15
224 # (uint32) c <<<= 9
225 rol $9,%r15d
226 # x2 ^= c
227 xor %r15,%rcx
228 # c = x14 + x2
229 lea (%rbx,%rcx),%r15
230 # (uint32) c <<<= 13
231 rol $13,%r15d
232 # x6 ^= c
233 xor %r15,%rax
234 # c = x2 + x6
235 lea (%rcx,%rax),%r15
236 # (uint32) c <<<= 18
237 rol $18,%r15d
238 # x10 ^= c
239 xor %r15,%rbp
240 # x15 = x15_stack
241 movq 176(%rsp),%r15
242 # x10_stack = x10
243 movq %rbp,168(%rsp)
244 # d = x11 + x15
245 lea (%r12,%r15),%rbp
246 # (uint32) d <<<= 7
247 rol $7,%ebp
248 # x3 ^= d
249 xor %rbp,%rsi
250 # d = x15 + x3
251 lea (%r15,%rsi),%rbp
252 # (uint32) d <<<= 9
253 rol $9,%ebp
254 # x7 ^= d
255 xor %rbp,%r8
256 # d = x3 + x7
257 lea (%rsi,%r8),%rbp
258 # (uint32) d <<<= 13
259 rol $13,%ebp
260 # x11 ^= d
261 xor %rbp,%r12
262 # d = x7 + x11
263 lea (%r8,%r12),%rbp
264 # (uint32) d <<<= 18
265 rol $18,%ebp
266 # x15 ^= d
267 xor %rbp,%r15
268 # x15_stack = x15
269 movq %r15,176(%rsp)
270 # x5 = x5_stack
271 movq 160(%rsp),%r15
272 # a = x3 + x0
273 lea (%rsi,%rdx),%rbp
274 # (uint32) a <<<= 7
275 rol $7,%ebp
276 # x1 ^= a
277 xor %rbp,%rdi
278 # b = x4 + x5
279 lea (%r9,%r15),%rbp
280 # (uint32) b <<<= 7
281 rol $7,%ebp
282 # x6 ^= b
283 xor %rbp,%rax
284 # a = x0 + x1
285 lea (%rdx,%rdi),%rbp
286 # (uint32) a <<<= 9
287 rol $9,%ebp
288 # x2 ^= a
289 xor %rbp,%rcx
290 # b = x5 + x6
291 lea (%r15,%rax),%rbp
292 # (uint32) b <<<= 9
293 rol $9,%ebp
294 # x7 ^= b
295 xor %rbp,%r8
296 # a = x1 + x2
297 lea (%rdi,%rcx),%rbp
298 # (uint32) a <<<= 13
299 rol $13,%ebp
300 # x3 ^= a
301 xor %rbp,%rsi
302 # b = x6 + x7
303 lea (%rax,%r8),%rbp
304 # (uint32) b <<<= 13
305 rol $13,%ebp
306 # x4 ^= b
307 xor %rbp,%r9
308 # a = x2 + x3
309 lea (%rcx,%rsi),%rbp
310 # (uint32) a <<<= 18
311 rol $18,%ebp
312 # x0 ^= a
313 xor %rbp,%rdx
314 # b = x7 + x4
315 lea (%r8,%r9),%rbp
316 # (uint32) b <<<= 18
317 rol $18,%ebp
318 # x5 ^= b
319 xor %rbp,%r15
320 # x10 = x10_stack
321 movq 168(%rsp),%rbp
322 # x5_stack = x5
323 movq %r15,160(%rsp)
324 # c = x9 + x10
325 lea (%r10,%rbp),%r15
326 # (uint32) c <<<= 7
327 rol $7,%r15d
328 # x11 ^= c
329 xor %r15,%r12
330 # c = x10 + x11
331 lea (%rbp,%r12),%r15
332 # (uint32) c <<<= 9
333 rol $9,%r15d
334 # x8 ^= c
335 xor %r15,%r11
336 # c = x11 + x8
337 lea (%r12,%r11),%r15
338 # (uint32) c <<<= 13
339 rol $13,%r15d
340 # x9 ^= c
341 xor %r15,%r10
342 # c = x8 + x9
343 lea (%r11,%r10),%r15
344 # (uint32) c <<<= 18
345 rol $18,%r15d
346 # x10 ^= c
347 xor %r15,%rbp
348 # x15 = x15_stack
349 movq 176(%rsp),%r15
350 # x10_stack = x10
351 movq %rbp,168(%rsp)
352 # d = x14 + x15
353 lea (%rbx,%r15),%rbp
354 # (uint32) d <<<= 7
355 rol $7,%ebp
356 # x12 ^= d
357 xor %rbp,%r14
358 # d = x15 + x12
359 lea (%r15,%r14),%rbp
360 # (uint32) d <<<= 9
361 rol $9,%ebp
362 # x13 ^= d
363 xor %rbp,%r13
364 # d = x12 + x13
365 lea (%r14,%r13),%rbp
366 # (uint32) d <<<= 13
367 rol $13,%ebp
368 # x14 ^= d
369 xor %rbp,%rbx
370 # d = x13 + x14
371 lea (%r13,%rbx),%rbp
372 # (uint32) d <<<= 18
373 rol $18,%ebp
374 # x15 ^= d
375 xor %rbp,%r15
376 # x15_stack = x15
377 movq %r15,176(%rsp)
378 # x5 = x5_stack
379 movq 160(%rsp),%r15
380 # a = x12 + x0
381 lea (%r14,%rdx),%rbp
382 # (uint32) a <<<= 7
383 rol $7,%ebp
384 # x4 ^= a
385 xor %rbp,%r9
386 # b = x1 + x5
387 lea (%rdi,%r15),%rbp
388 # (uint32) b <<<= 7
389 rol $7,%ebp
390 # x9 ^= b
391 xor %rbp,%r10
392 # a = x0 + x4
393 lea (%rdx,%r9),%rbp
394 # (uint32) a <<<= 9
395 rol $9,%ebp
396 # x8 ^= a
397 xor %rbp,%r11
398 # b = x5 + x9
399 lea (%r15,%r10),%rbp
400 # (uint32) b <<<= 9
401 rol $9,%ebp
402 # x13 ^= b
403 xor %rbp,%r13
404 # a = x4 + x8
405 lea (%r9,%r11),%rbp
406 # (uint32) a <<<= 13
407 rol $13,%ebp
408 # x12 ^= a
409 xor %rbp,%r14
410 # b = x9 + x13
411 lea (%r10,%r13),%rbp
412 # (uint32) b <<<= 13
413 rol $13,%ebp
414 # x1 ^= b
415 xor %rbp,%rdi
416 # a = x8 + x12
417 lea (%r11,%r14),%rbp
418 # (uint32) a <<<= 18
419 rol $18,%ebp
420 # x0 ^= a
421 xor %rbp,%rdx
422 # b = x13 + x1
423 lea (%r13,%rdi),%rbp
424 # (uint32) b <<<= 18
425 rol $18,%ebp
426 # x5 ^= b
427 xor %rbp,%r15
428 # x10 = x10_stack
429 movq 168(%rsp),%rbp
430 # x5_stack = x5
431 movq %r15,160(%rsp)
432 # c = x6 + x10
433 lea (%rax,%rbp),%r15
434 # (uint32) c <<<= 7
435 rol $7,%r15d
436 # x14 ^= c
437 xor %r15,%rbx
438 # c = x10 + x14
439 lea (%rbp,%rbx),%r15
440 # (uint32) c <<<= 9
441 rol $9,%r15d
442 # x2 ^= c
443 xor %r15,%rcx
444 # c = x14 + x2
445 lea (%rbx,%rcx),%r15
446 # (uint32) c <<<= 13
447 rol $13,%r15d
448 # x6 ^= c
449 xor %r15,%rax
450 # c = x2 + x6
451 lea (%rcx,%rax),%r15
452 # (uint32) c <<<= 18
453 rol $18,%r15d
454 # x10 ^= c
455 xor %r15,%rbp
456 # x15 = x15_stack
457 movq 176(%rsp),%r15
458 # x10_stack = x10
459 movq %rbp,168(%rsp)
460 # d = x11 + x15
461 lea (%r12,%r15),%rbp
462 # (uint32) d <<<= 7
463 rol $7,%ebp
464 # x3 ^= d
465 xor %rbp,%rsi
466 # d = x15 + x3
467 lea (%r15,%rsi),%rbp
468 # (uint32) d <<<= 9
469 rol $9,%ebp
470 # x7 ^= d
471 xor %rbp,%r8
472 # d = x3 + x7
473 lea (%rsi,%r8),%rbp
474 # (uint32) d <<<= 13
475 rol $13,%ebp
476 # x11 ^= d
477 xor %rbp,%r12
478 # d = x7 + x11
479 lea (%r8,%r12),%rbp
480 # (uint32) d <<<= 18
481 rol $18,%ebp
482 # x15 ^= d
483 xor %rbp,%r15
484 # x15_stack = x15
485 movq %r15,176(%rsp)
486 # x5 = x5_stack
487 movq 160(%rsp),%r15
488 # a = x3 + x0
489 lea (%rsi,%rdx),%rbp
490 # (uint32) a <<<= 7
491 rol $7,%ebp
492 # x1 ^= a
493 xor %rbp,%rdi
494 # b = x4 + x5
495 lea (%r9,%r15),%rbp
496 # (uint32) b <<<= 7
497 rol $7,%ebp
498 # x6 ^= b
499 xor %rbp,%rax
500 # a = x0 + x1
501 lea (%rdx,%rdi),%rbp
502 # (uint32) a <<<= 9
503 rol $9,%ebp
504 # x2 ^= a
505 xor %rbp,%rcx
506 # b = x5 + x6
507 lea (%r15,%rax),%rbp
508 # (uint32) b <<<= 9
509 rol $9,%ebp
510 # x7 ^= b
511 xor %rbp,%r8
512 # a = x1 + x2
513 lea (%rdi,%rcx),%rbp
514 # (uint32) a <<<= 13
515 rol $13,%ebp
516 # x3 ^= a
517 xor %rbp,%rsi
518 # b = x6 + x7
519 lea (%rax,%r8),%rbp
520 # (uint32) b <<<= 13
521 rol $13,%ebp
522 # x4 ^= b
523 xor %rbp,%r9
524 # a = x2 + x3
525 lea (%rcx,%rsi),%rbp
526 # (uint32) a <<<= 18
527 rol $18,%ebp
528 # x0 ^= a
529 xor %rbp,%rdx
530 # b = x7 + x4
531 lea (%r8,%r9),%rbp
532 # (uint32) b <<<= 18
533 rol $18,%ebp
534 # x5 ^= b
535 xor %rbp,%r15
536 # x10 = x10_stack
537 movq 168(%rsp),%rbp
538 # x5_stack = x5
539 movq %r15,160(%rsp)
540 # c = x9 + x10
541 lea (%r10,%rbp),%r15
542 # (uint32) c <<<= 7
543 rol $7,%r15d
544 # x11 ^= c
545 xor %r15,%r12
546 # c = x10 + x11
547 lea (%rbp,%r12),%r15
548 # (uint32) c <<<= 9
549 rol $9,%r15d
550 # x8 ^= c
551 xor %r15,%r11
552 # c = x11 + x8
553 lea (%r12,%r11),%r15
554 # (uint32) c <<<= 13
555 rol $13,%r15d
556 # x9 ^= c
557 xor %r15,%r10
558 # c = x8 + x9
559 lea (%r11,%r10),%r15
560 # (uint32) c <<<= 18
561 rol $18,%r15d
562 # x10 ^= c
563 xor %r15,%rbp
564 # x15 = x15_stack
565 movq 176(%rsp),%r15
566 # x10_stack = x10
567 movq %rbp,168(%rsp)
568 # d = x14 + x15
569 lea (%rbx,%r15),%rbp
570 # (uint32) d <<<= 7
571 rol $7,%ebp
572 # x12 ^= d
573 xor %rbp,%r14
574 # d = x15 + x12
575 lea (%r15,%r14),%rbp
576 # (uint32) d <<<= 9
577 rol $9,%ebp
578 # x13 ^= d
579 xor %rbp,%r13
580 # d = x12 + x13
581 lea (%r14,%r13),%rbp
582 # (uint32) d <<<= 13
583 rol $13,%ebp
584 # x14 ^= d
585 xor %rbp,%rbx
586 # d = x13 + x14
587 lea (%r13,%rbx),%rbp
588 # (uint32) d <<<= 18
589 rol $18,%ebp
590 # x15 ^= d
591 xor %rbp,%r15
592 # x15_stack = x15
593 movq %r15,176(%rsp)
594 # i = i_backup
595 movq 184(%rsp),%r15
596 # unsigned>? i -= 4
597 sub $4,%r15
598 # comment:fp stack unchanged by jump
599 # goto mainloop if unsigned>
600 ja ._mainloop
601 # (uint32) x2 += j2
602 addl 64(%rsp),%ecx
603 # x3 <<= 32
604 shl $32,%rsi
605 # x3 += j2
606 addq 64(%rsp),%rsi
607 # (uint64) x3 >>= 32
608 shr $32,%rsi
609 # x3 <<= 32
610 shl $32,%rsi
611 # x2 += x3
612 add %rsi,%rcx
613 # (uint32) x6 += j6
614 addl 80(%rsp),%eax
615 # x7 <<= 32
616 shl $32,%r8
617 # x7 += j6
618 addq 80(%rsp),%r8
619 # (uint64) x7 >>= 32
620 shr $32,%r8
621 # x7 <<= 32
622 shl $32,%r8
623 # x6 += x7
624 add %r8,%rax
625 # (uint32) x8 += j8
626 addl 88(%rsp),%r11d
627 # x9 <<= 32
628 shl $32,%r10
629 # x9 += j8
630 addq 88(%rsp),%r10
631 # (uint64) x9 >>= 32
632 shr $32,%r10
633 # x9 <<= 32
634 shl $32,%r10
635 # x8 += x9
636 add %r10,%r11
637 # (uint32) x12 += j12
638 addl 104(%rsp),%r14d
639 # x13 <<= 32
640 shl $32,%r13
641 # x13 += j12
642 addq 104(%rsp),%r13
643 # (uint64) x13 >>= 32
644 shr $32,%r13
645 # x13 <<= 32
646 shl $32,%r13
647 # x12 += x13
648 add %r13,%r14
649 # (uint32) x0 += j0
650 addl 56(%rsp),%edx
651 # x1 <<= 32
652 shl $32,%rdi
653 # x1 += j0
654 addq 56(%rsp),%rdi
655 # (uint64) x1 >>= 32
656 shr $32,%rdi
657 # x1 <<= 32
658 shl $32,%rdi
659 # x0 += x1
660 add %rdi,%rdx
661 # x5 = x5_stack
662 movq 160(%rsp),%rdi
663 # (uint32) x4 += j4
664 addl 72(%rsp),%r9d
665 # x5 <<= 32
666 shl $32,%rdi
667 # x5 += j4
668 addq 72(%rsp),%rdi
669 # (uint64) x5 >>= 32
670 shr $32,%rdi
671 # x5 <<= 32
672 shl $32,%rdi
673 # x4 += x5
674 add %rdi,%r9
675 # x10 = x10_stack
676 movq 168(%rsp),%r8
677 # (uint32) x10 += j10
678 addl 96(%rsp),%r8d
679 # x11 <<= 32
680 shl $32,%r12
681 # x11 += j10
682 addq 96(%rsp),%r12
683 # (uint64) x11 >>= 32
684 shr $32,%r12
685 # x11 <<= 32
686 shl $32,%r12
687 # x10 += x11
688 add %r12,%r8
689 # x15 = x15_stack
690 movq 176(%rsp),%rdi
691 # (uint32) x14 += j14
692 addl 112(%rsp),%ebx
693 # x15 <<= 32
694 shl $32,%rdi
695 # x15 += j14
696 addq 112(%rsp),%rdi
697 # (uint64) x15 >>= 32
698 shr $32,%rdi
699 # x15 <<= 32
700 shl $32,%rdi
701 # x14 += x15
702 add %rdi,%rbx
703 # out = out_backup
704 movq 136(%rsp),%rdi
705 # m = m_backup
706 movq 144(%rsp),%rsi
707 # x0 ^= *(uint64 *) (m + 0)
708 xorq 0(%rsi),%rdx
709 # *(uint64 *) (out + 0) = x0
710 movq %rdx,0(%rdi)
711 # x2 ^= *(uint64 *) (m + 8)
712 xorq 8(%rsi),%rcx
713 # *(uint64 *) (out + 8) = x2
714 movq %rcx,8(%rdi)
715 # x4 ^= *(uint64 *) (m + 16)
716 xorq 16(%rsi),%r9
717 # *(uint64 *) (out + 16) = x4
718 movq %r9,16(%rdi)
719 # x6 ^= *(uint64 *) (m + 24)
720 xorq 24(%rsi),%rax
721 # *(uint64 *) (out + 24) = x6
722 movq %rax,24(%rdi)
723 # x8 ^= *(uint64 *) (m + 32)
724 xorq 32(%rsi),%r11
725 # *(uint64 *) (out + 32) = x8
726 movq %r11,32(%rdi)
727 # x10 ^= *(uint64 *) (m + 40)
728 xorq 40(%rsi),%r8
729 # *(uint64 *) (out + 40) = x10
730 movq %r8,40(%rdi)
731 # x12 ^= *(uint64 *) (m + 48)
732 xorq 48(%rsi),%r14
733 # *(uint64 *) (out + 48) = x12
734 movq %r14,48(%rdi)
735 # x14 ^= *(uint64 *) (m + 56)
736 xorq 56(%rsi),%rbx
737 # *(uint64 *) (out + 56) = x14
738 movq %rbx,56(%rdi)
739 # bytes = bytes_backup
740 movq 152(%rsp),%rdx
741 # in8 = j8
742 movq 88(%rsp),%rcx
743 # in8 += 1
744 add $1,%rcx
745 # j8 = in8
746 movq %rcx,88(%rsp)
747 # unsigned>? unsigned<? bytes - 64
748 cmp $64,%rdx
749 # comment:fp stack unchanged by jump
750 # goto bytesatleast65 if unsigned>
751 ja ._bytesatleast65
752 # comment:fp stack unchanged by jump
753 # goto bytesatleast64 if !unsigned<
754 jae ._bytesatleast64
755 # m = out
756 mov %rdi,%rsi
757 # out = ctarget
758 movq 128(%rsp),%rdi
759 # i = bytes
760 mov %rdx,%rcx
761 # while (i) { *out++ = *m++; --i }
762 rep movsb
763 # comment:fp stack unchanged by fallthrough
764# bytesatleast64:
765._bytesatleast64:
766 # x = x_backup
767 movq 120(%rsp),%rdi
768 # in8 = j8
769 movq 88(%rsp),%rsi
770 # *(uint64 *) (x + 32) = in8
771 movq %rsi,32(%rdi)
772 # r11 = r11_stack
773 movq 0(%rsp),%r11
774 # r12 = r12_stack
775 movq 8(%rsp),%r12
776 # r13 = r13_stack
777 movq 16(%rsp),%r13
778 # r14 = r14_stack
779 movq 24(%rsp),%r14
780 # r15 = r15_stack
781 movq 32(%rsp),%r15
782 # rbx = rbx_stack
783 movq 40(%rsp),%rbx
784 # rbp = rbp_stack
785 movq 48(%rsp),%rbp
786 # comment:fp stack unchanged by fallthrough
787# done:
788._done:
789 # leave
790 add %r11,%rsp
791 mov %rdi,%rax
792 mov %rsi,%rdx
793 ret
794# bytesatleast65:
795._bytesatleast65:
796 # bytes -= 64
797 sub $64,%rdx
798 # out += 64
799 add $64,%rdi
800 # m += 64
801 add $64,%rsi
802 # comment:fp stack unchanged by jump
803 # goto bytesatleast1
804 jmp ._bytesatleast1
805# enter ECRYPT_keysetup
806.text
807.p2align 5
808.globl ECRYPT_keysetup
809ECRYPT_keysetup:
810 mov %rsp,%r11
811 and $31,%r11
812 add $256,%r11
813 sub %r11,%rsp
814 # k = arg2
815 mov %rsi,%rsi
816 # kbits = arg3
817 mov %rdx,%rdx
818 # x = arg1
819 mov %rdi,%rdi
820 # in0 = *(uint64 *) (k + 0)
821 movq 0(%rsi),%r8
822 # in2 = *(uint64 *) (k + 8)
823 movq 8(%rsi),%r9
824 # *(uint64 *) (x + 4) = in0
825 movq %r8,4(%rdi)
826 # *(uint64 *) (x + 12) = in2
827 movq %r9,12(%rdi)
828 # unsigned<? kbits - 256
829 cmp $256,%rdx
830 # comment:fp stack unchanged by jump
831 # goto kbits128 if unsigned<
832 jb ._kbits128
833# kbits256:
834._kbits256:
835 # in10 = *(uint64 *) (k + 16)
836 movq 16(%rsi),%rdx
837 # in12 = *(uint64 *) (k + 24)
838 movq 24(%rsi),%rsi
839 # *(uint64 *) (x + 44) = in10
840 movq %rdx,44(%rdi)
841 # *(uint64 *) (x + 52) = in12
842 movq %rsi,52(%rdi)
843 # in0 = 1634760805
844 mov $1634760805,%rsi
845 # in4 = 857760878
846 mov $857760878,%rdx
847 # in10 = 2036477234
848 mov $2036477234,%rcx
849 # in14 = 1797285236
850 mov $1797285236,%r8
851 # *(uint32 *) (x + 0) = in0
852 movl %esi,0(%rdi)
853 # *(uint32 *) (x + 20) = in4
854 movl %edx,20(%rdi)
855 # *(uint32 *) (x + 40) = in10
856 movl %ecx,40(%rdi)
857 # *(uint32 *) (x + 60) = in14
858 movl %r8d,60(%rdi)
859 # comment:fp stack unchanged by jump
860 # goto keysetupdone
861 jmp ._keysetupdone
862# kbits128:
863._kbits128:
864 # in10 = *(uint64 *) (k + 0)
865 movq 0(%rsi),%rdx
866 # in12 = *(uint64 *) (k + 8)
867 movq 8(%rsi),%rsi
868 # *(uint64 *) (x + 44) = in10
869 movq %rdx,44(%rdi)
870 # *(uint64 *) (x + 52) = in12
871 movq %rsi,52(%rdi)
872 # in0 = 1634760805
873 mov $1634760805,%rsi
874 # in4 = 824206446
875 mov $824206446,%rdx
876 # in10 = 2036477238
877 mov $2036477238,%rcx
878 # in14 = 1797285236
879 mov $1797285236,%r8
880 # *(uint32 *) (x + 0) = in0
881 movl %esi,0(%rdi)
882 # *(uint32 *) (x + 20) = in4
883 movl %edx,20(%rdi)
884 # *(uint32 *) (x + 40) = in10
885 movl %ecx,40(%rdi)
886 # *(uint32 *) (x + 60) = in14
887 movl %r8d,60(%rdi)
888# keysetupdone:
889._keysetupdone:
890 # leave
891 add %r11,%rsp
892 mov %rdi,%rax
893 mov %rsi,%rdx
894 ret
895# enter ECRYPT_ivsetup
896.text
897.p2align 5
898.globl ECRYPT_ivsetup
899ECRYPT_ivsetup:
900 mov %rsp,%r11
901 and $31,%r11
902 add $256,%r11
903 sub %r11,%rsp
904 # iv = arg2
905 mov %rsi,%rsi
906 # x = arg1
907 mov %rdi,%rdi
908 # in6 = *(uint64 *) (iv + 0)
909 movq 0(%rsi),%rsi
910 # in8 = 0
911 mov $0,%r8
912 # *(uint64 *) (x + 24) = in6
913 movq %rsi,24(%rdi)
914 # *(uint64 *) (x + 32) = in8
915 movq %r8,32(%rdi)
916 # leave
917 add %r11,%rsp
918 mov %rdi,%rax
919 mov %rsi,%rdx
920 ret
diff --git a/arch/x86/crypto/salsa20_glue.c b/arch/x86/crypto/salsa20_glue.c
new file mode 100644
index 000000000000..bccb76d80987
--- /dev/null
+++ b/arch/x86/crypto/salsa20_glue.c
@@ -0,0 +1,129 @@
1/*
2 * Glue code for optimized assembly version of Salsa20.
3 *
4 * Copyright (c) 2007 Tan Swee Heng <thesweeheng@gmail.com>
5 *
6 * The assembly codes are public domain assembly codes written by Daniel. J.
7 * Bernstein <djb@cr.yp.to>. The codes are modified to include indentation
8 * and to remove extraneous comments and functions that are not needed.
9 * - i586 version, renamed as salsa20-i586-asm_32.S
10 * available from <http://cr.yp.to/snuffle/salsa20/x86-pm/salsa20.s>
11 * - x86-64 version, renamed as salsa20-x86_64-asm_64.S
12 * available from <http://cr.yp.to/snuffle/salsa20/amd64-3/salsa20.s>
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the Free
16 * Software Foundation; either version 2 of the License, or (at your option)
17 * any later version.
18 *
19 */
20
21#include <crypto/algapi.h>
22#include <linux/module.h>
23#include <linux/crypto.h>
24
25#define SALSA20_IV_SIZE 8U
26#define SALSA20_MIN_KEY_SIZE 16U
27#define SALSA20_MAX_KEY_SIZE 32U
28
29// use the ECRYPT_* function names
30#define salsa20_keysetup ECRYPT_keysetup
31#define salsa20_ivsetup ECRYPT_ivsetup
32#define salsa20_encrypt_bytes ECRYPT_encrypt_bytes
33
34struct salsa20_ctx
35{
36 u32 input[16];
37};
38
39asmlinkage void salsa20_keysetup(struct salsa20_ctx *ctx, const u8 *k,
40 u32 keysize, u32 ivsize);
41asmlinkage void salsa20_ivsetup(struct salsa20_ctx *ctx, const u8 *iv);
42asmlinkage void salsa20_encrypt_bytes(struct salsa20_ctx *ctx,
43 const u8 *src, u8 *dst, u32 bytes);
44
45static int setkey(struct crypto_tfm *tfm, const u8 *key,
46 unsigned int keysize)
47{
48 struct salsa20_ctx *ctx = crypto_tfm_ctx(tfm);
49 salsa20_keysetup(ctx, key, keysize*8, SALSA20_IV_SIZE*8);
50 return 0;
51}
52
53static int encrypt(struct blkcipher_desc *desc,
54 struct scatterlist *dst, struct scatterlist *src,
55 unsigned int nbytes)
56{
57 struct blkcipher_walk walk;
58 struct crypto_blkcipher *tfm = desc->tfm;
59 struct salsa20_ctx *ctx = crypto_blkcipher_ctx(tfm);
60 int err;
61
62 blkcipher_walk_init(&walk, dst, src, nbytes);
63 err = blkcipher_walk_virt_block(desc, &walk, 64);
64
65 salsa20_ivsetup(ctx, walk.iv);
66
67 if (likely(walk.nbytes == nbytes))
68 {
69 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
70 walk.dst.virt.addr, nbytes);
71 return blkcipher_walk_done(desc, &walk, 0);
72 }
73
74 while (walk.nbytes >= 64) {
75 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
76 walk.dst.virt.addr,
77 walk.nbytes - (walk.nbytes % 64));
78 err = blkcipher_walk_done(desc, &walk, walk.nbytes % 64);
79 }
80
81 if (walk.nbytes) {
82 salsa20_encrypt_bytes(ctx, walk.src.virt.addr,
83 walk.dst.virt.addr, walk.nbytes);
84 err = blkcipher_walk_done(desc, &walk, 0);
85 }
86
87 return err;
88}
89
90static struct crypto_alg alg = {
91 .cra_name = "salsa20",
92 .cra_driver_name = "salsa20-asm",
93 .cra_priority = 200,
94 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
95 .cra_type = &crypto_blkcipher_type,
96 .cra_blocksize = 1,
97 .cra_ctxsize = sizeof(struct salsa20_ctx),
98 .cra_alignmask = 3,
99 .cra_module = THIS_MODULE,
100 .cra_list = LIST_HEAD_INIT(alg.cra_list),
101 .cra_u = {
102 .blkcipher = {
103 .setkey = setkey,
104 .encrypt = encrypt,
105 .decrypt = encrypt,
106 .min_keysize = SALSA20_MIN_KEY_SIZE,
107 .max_keysize = SALSA20_MAX_KEY_SIZE,
108 .ivsize = SALSA20_IV_SIZE,
109 }
110 }
111};
112
113static int __init init(void)
114{
115 return crypto_register_alg(&alg);
116}
117
118static void __exit fini(void)
119{
120 crypto_unregister_alg(&alg);
121}
122
123module_init(init);
124module_exit(fini);
125
126MODULE_LICENSE("GPL");
127MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm (optimized assembly version)");
128MODULE_ALIAS("salsa20");
129MODULE_ALIAS("salsa20-asm");
diff --git a/arch/x86/crypto/twofish_64.c b/arch/x86/crypto/twofish_64.c
deleted file mode 100644
index 182d91d5cfb9..000000000000
--- a/arch/x86/crypto/twofish_64.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/*
2 * Glue Code for optimized x86_64 assembler version of TWOFISH
3 *
4 * Originally Twofish for GPG
5 * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
6 * 256-bit key length added March 20, 1999
7 * Some modifications to reduce the text size by Werner Koch, April, 1998
8 * Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com>
9 * Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
10 *
11 * The original author has disclaimed all copyright interest in this
12 * code and thus put it in the public domain. The subsequent authors
13 * have put this under the GNU General Public License.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 * USA
29 *
30 * This code is a "clean room" implementation, written from the paper
31 * _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey,
32 * Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available
33 * through http://www.counterpane.com/twofish.html
34 *
35 * For background information on multiplication in finite fields, used for
36 * the matrix operations in the key schedule, see the book _Contemporary
37 * Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
38 * Third Edition.
39 */
40
41#include <crypto/twofish.h>
42#include <linux/crypto.h>
43#include <linux/init.h>
44#include <linux/kernel.h>
45#include <linux/module.h>
46#include <linux/types.h>
47
48asmlinkage void twofish_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
49asmlinkage void twofish_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
50
51static void twofish_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
52{
53 twofish_enc_blk(tfm, dst, src);
54}
55
56static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
57{
58 twofish_dec_blk(tfm, dst, src);
59}
60
61static struct crypto_alg alg = {
62 .cra_name = "twofish",
63 .cra_driver_name = "twofish-x86_64",
64 .cra_priority = 200,
65 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
66 .cra_blocksize = TF_BLOCK_SIZE,
67 .cra_ctxsize = sizeof(struct twofish_ctx),
68 .cra_alignmask = 3,
69 .cra_module = THIS_MODULE,
70 .cra_list = LIST_HEAD_INIT(alg.cra_list),
71 .cra_u = {
72 .cipher = {
73 .cia_min_keysize = TF_MIN_KEY_SIZE,
74 .cia_max_keysize = TF_MAX_KEY_SIZE,
75 .cia_setkey = twofish_setkey,
76 .cia_encrypt = twofish_encrypt,
77 .cia_decrypt = twofish_decrypt
78 }
79 }
80};
81
82static int __init init(void)
83{
84 return crypto_register_alg(&alg);
85}
86
87static void __exit fini(void)
88{
89 crypto_unregister_alg(&alg);
90}
91
92module_init(init);
93module_exit(fini);
94
95MODULE_LICENSE("GPL");
96MODULE_DESCRIPTION ("Twofish Cipher Algorithm, x86_64 asm optimized");
97MODULE_ALIAS("twofish");
diff --git a/arch/x86/crypto/twofish_32.c b/arch/x86/crypto/twofish_glue.c
index e3004dfe9c7a..cefaf8b9aa18 100644
--- a/arch/x86/crypto/twofish_32.c
+++ b/arch/x86/crypto/twofish_glue.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Glue Code for optimized 586 assembler version of TWOFISH 2 * Glue Code for assembler optimized version of TWOFISH
3 * 3 *
4 * Originally Twofish for GPG 4 * Originally Twofish for GPG
5 * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998 5 * By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
@@ -44,7 +44,6 @@
44#include <linux/module.h> 44#include <linux/module.h>
45#include <linux/types.h> 45#include <linux/types.h>
46 46
47
48asmlinkage void twofish_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src); 47asmlinkage void twofish_enc_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
49asmlinkage void twofish_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src); 48asmlinkage void twofish_dec_blk(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
50 49
@@ -60,7 +59,7 @@ static void twofish_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
60 59
61static struct crypto_alg alg = { 60static struct crypto_alg alg = {
62 .cra_name = "twofish", 61 .cra_name = "twofish",
63 .cra_driver_name = "twofish-i586", 62 .cra_driver_name = "twofish-asm",
64 .cra_priority = 200, 63 .cra_priority = 200,
65 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 64 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
66 .cra_blocksize = TF_BLOCK_SIZE, 65 .cra_blocksize = TF_BLOCK_SIZE,
@@ -93,5 +92,6 @@ module_init(init);
93module_exit(fini); 92module_exit(fini);
94 93
95MODULE_LICENSE("GPL"); 94MODULE_LICENSE("GPL");
96MODULE_DESCRIPTION ("Twofish Cipher Algorithm, i586 asm optimized"); 95MODULE_DESCRIPTION ("Twofish Cipher Algorithm, asm optimized");
97MODULE_ALIAS("twofish"); 96MODULE_ALIAS("twofish");
97MODULE_ALIAS("twofish-asm");
diff --git a/arch/x86/kernel/apic_32.c b/arch/x86/kernel/apic_32.c
index edb5108e5d0e..a56c782653be 100644
--- a/arch/x86/kernel/apic_32.c
+++ b/arch/x86/kernel/apic_32.c
@@ -1530,7 +1530,7 @@ static int lapic_resume(struct sys_device *dev)
1530 */ 1530 */
1531 1531
1532static struct sysdev_class lapic_sysclass = { 1532static struct sysdev_class lapic_sysclass = {
1533 set_kset_name("lapic"), 1533 .name = "lapic",
1534 .resume = lapic_resume, 1534 .resume = lapic_resume,
1535 .suspend = lapic_suspend, 1535 .suspend = lapic_suspend,
1536}; 1536};
diff --git a/arch/x86/kernel/apic_64.c b/arch/x86/kernel/apic_64.c
index f28ccb588fba..fa6cdee6d303 100644
--- a/arch/x86/kernel/apic_64.c
+++ b/arch/x86/kernel/apic_64.c
@@ -639,7 +639,7 @@ static int lapic_resume(struct sys_device *dev)
639} 639}
640 640
641static struct sysdev_class lapic_sysclass = { 641static struct sysdev_class lapic_sysclass = {
642 set_kset_name("lapic"), 642 .name = "lapic",
643 .resume = lapic_resume, 643 .resume = lapic_resume,
644 .suspend = lapic_suspend, 644 .suspend = lapic_suspend,
645}; 645};
diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 9f530ff43c21..8b4507b8469b 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -733,10 +733,8 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
733 if (unlikely(retval < 0)) 733 if (unlikely(retval < 0))
734 return retval; 734 return retval;
735 735
736 cache_kobject[cpu]->parent = &sys_dev->kobj; 736 retval = kobject_init_and_add(cache_kobject[cpu], &ktype_percpu_entry,
737 kobject_set_name(cache_kobject[cpu], "%s", "cache"); 737 &sys_dev->kobj, "%s", "cache");
738 cache_kobject[cpu]->ktype = &ktype_percpu_entry;
739 retval = kobject_register(cache_kobject[cpu]);
740 if (retval < 0) { 738 if (retval < 0) {
741 cpuid4_cache_sysfs_exit(cpu); 739 cpuid4_cache_sysfs_exit(cpu);
742 return retval; 740 return retval;
@@ -746,23 +744,23 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
746 this_object = INDEX_KOBJECT_PTR(cpu,i); 744 this_object = INDEX_KOBJECT_PTR(cpu,i);
747 this_object->cpu = cpu; 745 this_object->cpu = cpu;
748 this_object->index = i; 746 this_object->index = i;
749 this_object->kobj.parent = cache_kobject[cpu]; 747 retval = kobject_init_and_add(&(this_object->kobj),
750 kobject_set_name(&(this_object->kobj), "index%1lu", i); 748 &ktype_cache, cache_kobject[cpu],
751 this_object->kobj.ktype = &ktype_cache; 749 "index%1lu", i);
752 retval = kobject_register(&(this_object->kobj));
753 if (unlikely(retval)) { 750 if (unlikely(retval)) {
754 for (j = 0; j < i; j++) { 751 for (j = 0; j < i; j++) {
755 kobject_unregister( 752 kobject_put(&(INDEX_KOBJECT_PTR(cpu,j)->kobj));
756 &(INDEX_KOBJECT_PTR(cpu,j)->kobj));
757 } 753 }
758 kobject_unregister(cache_kobject[cpu]); 754 kobject_put(cache_kobject[cpu]);
759 cpuid4_cache_sysfs_exit(cpu); 755 cpuid4_cache_sysfs_exit(cpu);
760 break; 756 break;
761 } 757 }
758 kobject_uevent(&(this_object->kobj), KOBJ_ADD);
762 } 759 }
763 if (!retval) 760 if (!retval)
764 cpu_set(cpu, cache_dev_map); 761 cpu_set(cpu, cache_dev_map);
765 762
763 kobject_uevent(cache_kobject[cpu], KOBJ_ADD);
766 return retval; 764 return retval;
767} 765}
768 766
@@ -778,8 +776,8 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
778 cpu_clear(cpu, cache_dev_map); 776 cpu_clear(cpu, cache_dev_map);
779 777
780 for (i = 0; i < num_cache_leaves; i++) 778 for (i = 0; i < num_cache_leaves; i++)
781 kobject_unregister(&(INDEX_KOBJECT_PTR(cpu,i)->kobj)); 779 kobject_put(&(INDEX_KOBJECT_PTR(cpu,i)->kobj));
782 kobject_unregister(cache_kobject[cpu]); 780 kobject_put(cache_kobject[cpu]);
783 cpuid4_cache_sysfs_exit(cpu); 781 cpuid4_cache_sysfs_exit(cpu);
784} 782}
785 783
diff --git a/arch/x86/kernel/cpu/mcheck/mce_64.c b/arch/x86/kernel/cpu/mcheck/mce_64.c
index 4b21d29fb5aa..242e8668dbeb 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -745,7 +745,7 @@ static void mce_restart(void)
745 745
746static struct sysdev_class mce_sysclass = { 746static struct sysdev_class mce_sysclass = {
747 .resume = mce_resume, 747 .resume = mce_resume,
748 set_kset_name("machinecheck"), 748 .name = "machinecheck",
749}; 749};
750 750
751DEFINE_PER_CPU(struct sys_device, device_mce); 751DEFINE_PER_CPU(struct sys_device, device_mce);
diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
index 752fb16a817d..753588755fee 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
@@ -65,7 +65,7 @@ static struct threshold_block threshold_defaults = {
65}; 65};
66 66
67struct threshold_bank { 67struct threshold_bank {
68 struct kobject kobj; 68 struct kobject *kobj;
69 struct threshold_block *blocks; 69 struct threshold_block *blocks;
70 cpumask_t cpus; 70 cpumask_t cpus;
71}; 71};
@@ -432,10 +432,9 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
432 else 432 else
433 per_cpu(threshold_banks, cpu)[bank]->blocks = b; 433 per_cpu(threshold_banks, cpu)[bank]->blocks = b;
434 434
435 kobject_set_name(&b->kobj, "misc%i", block); 435 err = kobject_init_and_add(&b->kobj, &threshold_ktype,
436 b->kobj.parent = &per_cpu(threshold_banks, cpu)[bank]->kobj; 436 per_cpu(threshold_banks, cpu)[bank]->kobj,
437 b->kobj.ktype = &threshold_ktype; 437 "misc%i", block);
438 err = kobject_register(&b->kobj);
439 if (err) 438 if (err)
440 goto out_free; 439 goto out_free;
441recurse: 440recurse:
@@ -451,11 +450,13 @@ recurse:
451 if (err) 450 if (err)
452 goto out_free; 451 goto out_free;
453 452
453 kobject_uevent(&b->kobj, KOBJ_ADD);
454
454 return err; 455 return err;
455 456
456out_free: 457out_free:
457 if (b) { 458 if (b) {
458 kobject_unregister(&b->kobj); 459 kobject_put(&b->kobj);
459 kfree(b); 460 kfree(b);
460 } 461 }
461 return err; 462 return err;
@@ -489,7 +490,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
489 goto out; 490 goto out;
490 491
491 err = sysfs_create_link(&per_cpu(device_mce, cpu).kobj, 492 err = sysfs_create_link(&per_cpu(device_mce, cpu).kobj,
492 &b->kobj, name); 493 b->kobj, name);
493 if (err) 494 if (err)
494 goto out; 495 goto out;
495 496
@@ -505,16 +506,15 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
505 goto out; 506 goto out;
506 } 507 }
507 508
508 kobject_set_name(&b->kobj, "threshold_bank%i", bank); 509 b->kobj = kobject_create_and_add(name, &per_cpu(device_mce, cpu).kobj);
509 b->kobj.parent = &per_cpu(device_mce, cpu).kobj; 510 if (!b->kobj)
511 goto out_free;
512
510#ifndef CONFIG_SMP 513#ifndef CONFIG_SMP
511 b->cpus = CPU_MASK_ALL; 514 b->cpus = CPU_MASK_ALL;
512#else 515#else
513 b->cpus = per_cpu(cpu_core_map, cpu); 516 b->cpus = per_cpu(cpu_core_map, cpu);
514#endif 517#endif
515 err = kobject_register(&b->kobj);
516 if (err)
517 goto out_free;
518 518
519 per_cpu(threshold_banks, cpu)[bank] = b; 519 per_cpu(threshold_banks, cpu)[bank] = b;
520 520
@@ -531,7 +531,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
531 continue; 531 continue;
532 532
533 err = sysfs_create_link(&per_cpu(device_mce, i).kobj, 533 err = sysfs_create_link(&per_cpu(device_mce, i).kobj,
534 &b->kobj, name); 534 b->kobj, name);
535 if (err) 535 if (err)
536 goto out; 536 goto out;
537 537
@@ -581,7 +581,7 @@ static void deallocate_threshold_block(unsigned int cpu,
581 return; 581 return;
582 582
583 list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) { 583 list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) {
584 kobject_unregister(&pos->kobj); 584 kobject_put(&pos->kobj);
585 list_del(&pos->miscj); 585 list_del(&pos->miscj);
586 kfree(pos); 586 kfree(pos);
587 } 587 }
@@ -627,7 +627,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
627 deallocate_threshold_block(cpu, bank); 627 deallocate_threshold_block(cpu, bank);
628 628
629free_out: 629free_out:
630 kobject_unregister(&b->kobj); 630 kobject_put(b->kobj);
631 kfree(b); 631 kfree(b);
632 per_cpu(threshold_banks, cpu)[bank] = NULL; 632 per_cpu(threshold_banks, cpu)[bank] = NULL;
633} 633}
diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 05c9936a16cc..d387c770c518 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -157,15 +157,15 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
157 157
158 switch (action) { 158 switch (action) {
159 case CPU_UP_PREPARE: 159 case CPU_UP_PREPARE:
160 case CPU_UP_PREPARE_FROZEN:
161 err = cpuid_device_create(cpu); 160 err = cpuid_device_create(cpu);
162 break; 161 break;
163 case CPU_UP_CANCELED: 162 case CPU_UP_CANCELED:
164 case CPU_UP_CANCELED_FROZEN:
165 case CPU_DEAD: 163 case CPU_DEAD:
166 case CPU_DEAD_FROZEN:
167 cpuid_device_destroy(cpu); 164 cpuid_device_destroy(cpu);
168 break; 165 break;
166 case CPU_UP_CANCELED_FROZEN:
167 destroy_suspended_device(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
168 break;
169 } 169 }
170 return err ? NOTIFY_BAD : NOTIFY_OK; 170 return err ? NOTIFY_BAD : NOTIFY_OK;
171} 171}
diff --git a/arch/x86/kernel/i8237.c b/arch/x86/kernel/i8237.c
index 29313832df0c..dbd6c1d1b638 100644
--- a/arch/x86/kernel/i8237.c
+++ b/arch/x86/kernel/i8237.c
@@ -51,7 +51,7 @@ static int i8237A_suspend(struct sys_device *dev, pm_message_t state)
51} 51}
52 52
53static struct sysdev_class i8237_sysdev_class = { 53static struct sysdev_class i8237_sysdev_class = {
54 set_kset_name("i8237"), 54 .name = "i8237",
55 .suspend = i8237A_suspend, 55 .suspend = i8237A_suspend,
56 .resume = i8237A_resume, 56 .resume = i8237A_resume,
57}; 57};
diff --git a/arch/x86/kernel/i8259_32.c b/arch/x86/kernel/i8259_32.c
index f634fc715c99..5f3496d01984 100644
--- a/arch/x86/kernel/i8259_32.c
+++ b/arch/x86/kernel/i8259_32.c
@@ -258,7 +258,7 @@ static int i8259A_shutdown(struct sys_device *dev)
258} 258}
259 259
260static struct sysdev_class i8259_sysdev_class = { 260static struct sysdev_class i8259_sysdev_class = {
261 set_kset_name("i8259"), 261 .name = "i8259",
262 .suspend = i8259A_suspend, 262 .suspend = i8259A_suspend,
263 .resume = i8259A_resume, 263 .resume = i8259A_resume,
264 .shutdown = i8259A_shutdown, 264 .shutdown = i8259A_shutdown,
diff --git a/arch/x86/kernel/i8259_64.c b/arch/x86/kernel/i8259_64.c
index 3f27ea0b9816..ba6d57286f56 100644
--- a/arch/x86/kernel/i8259_64.c
+++ b/arch/x86/kernel/i8259_64.c
@@ -370,7 +370,7 @@ static int i8259A_shutdown(struct sys_device *dev)
370} 370}
371 371
372static struct sysdev_class i8259_sysdev_class = { 372static struct sysdev_class i8259_sysdev_class = {
373 set_kset_name("i8259"), 373 .name = "i8259",
374 .suspend = i8259A_suspend, 374 .suspend = i8259A_suspend,
375 .resume = i8259A_resume, 375 .resume = i8259A_resume,
376 .shutdown = i8259A_shutdown, 376 .shutdown = i8259A_shutdown,
diff --git a/arch/x86/kernel/io_apic_32.c b/arch/x86/kernel/io_apic_32.c
index a6b1490e00c4..ab77f1905469 100644
--- a/arch/x86/kernel/io_apic_32.c
+++ b/arch/x86/kernel/io_apic_32.c
@@ -2401,7 +2401,7 @@ static int ioapic_resume(struct sys_device *dev)
2401} 2401}
2402 2402
2403static struct sysdev_class ioapic_sysdev_class = { 2403static struct sysdev_class ioapic_sysdev_class = {
2404 set_kset_name("ioapic"), 2404 .name = "ioapic",
2405 .suspend = ioapic_suspend, 2405 .suspend = ioapic_suspend,
2406 .resume = ioapic_resume, 2406 .resume = ioapic_resume,
2407}; 2407};
diff --git a/arch/x86/kernel/io_apic_64.c b/arch/x86/kernel/io_apic_64.c
index cbac1670c7c3..23a3ac06a23e 100644
--- a/arch/x86/kernel/io_apic_64.c
+++ b/arch/x86/kernel/io_apic_64.c
@@ -1850,7 +1850,7 @@ static int ioapic_resume(struct sys_device *dev)
1850} 1850}
1851 1851
1852static struct sysdev_class ioapic_sysdev_class = { 1852static struct sysdev_class ioapic_sysdev_class = {
1853 set_kset_name("ioapic"), 1853 .name = "ioapic",
1854 .suspend = ioapic_suspend, 1854 .suspend = ioapic_suspend,
1855 .resume = ioapic_resume, 1855 .resume = ioapic_resume,
1856}; 1856};
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index ee6eba4ecfea..21f6e3c0be18 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -155,15 +155,15 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
155 155
156 switch (action) { 156 switch (action) {
157 case CPU_UP_PREPARE: 157 case CPU_UP_PREPARE:
158 case CPU_UP_PREPARE_FROZEN:
159 err = msr_device_create(cpu); 158 err = msr_device_create(cpu);
160 break; 159 break;
161 case CPU_UP_CANCELED: 160 case CPU_UP_CANCELED:
162 case CPU_UP_CANCELED_FROZEN:
163 case CPU_DEAD: 161 case CPU_DEAD:
164 case CPU_DEAD_FROZEN:
165 msr_device_destroy(cpu); 162 msr_device_destroy(cpu);
166 break; 163 break;
164 case CPU_UP_CANCELED_FROZEN:
165 destroy_suspended_device(msr_class, MKDEV(MSR_MAJOR, cpu));
166 break;
167 } 167 }
168 return err ? NOTIFY_BAD : NOTIFY_OK; 168 return err ? NOTIFY_BAD : NOTIFY_OK;
169} 169}
diff --git a/arch/x86/kernel/nmi_32.c b/arch/x86/kernel/nmi_32.c
index 852db2906921..4f4bfd3a88b6 100644
--- a/arch/x86/kernel/nmi_32.c
+++ b/arch/x86/kernel/nmi_32.c
@@ -176,7 +176,7 @@ static int lapic_nmi_resume(struct sys_device *dev)
176 176
177 177
178static struct sysdev_class nmi_sysclass = { 178static struct sysdev_class nmi_sysclass = {
179 set_kset_name("lapic_nmi"), 179 .name = "lapic_nmi",
180 .resume = lapic_nmi_resume, 180 .resume = lapic_nmi_resume,
181 .suspend = lapic_nmi_suspend, 181 .suspend = lapic_nmi_suspend,
182}; 182};
diff --git a/arch/x86/kernel/nmi_64.c b/arch/x86/kernel/nmi_64.c
index 4253c4e8849c..c3d1476b6a11 100644
--- a/arch/x86/kernel/nmi_64.c
+++ b/arch/x86/kernel/nmi_64.c
@@ -211,7 +211,7 @@ static int lapic_nmi_resume(struct sys_device *dev)
211} 211}
212 212
213static struct sysdev_class nmi_sysclass = { 213static struct sysdev_class nmi_sysclass = {
214 set_kset_name("lapic_nmi"), 214 .name = "lapic_nmi",
215 .resume = lapic_nmi_resume, 215 .resume = lapic_nmi_resume,
216 .suspend = lapic_nmi_suspend, 216 .suspend = lapic_nmi_suspend,
217}; 217};
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 944bbcdd2b8d..c8ab79ef4276 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -51,7 +51,7 @@ static int nmi_resume(struct sys_device *dev)
51 51
52 52
53static struct sysdev_class oprofile_sysclass = { 53static struct sysdev_class oprofile_sysclass = {
54 set_kset_name("oprofile"), 54 .name = "oprofile",
55 .resume = nmi_resume, 55 .resume = nmi_resume,
56 .suspend = nmi_suspend, 56 .suspend = nmi_suspend,
57}; 57};
diff --git a/block/elevator.c b/block/elevator.c
index e452deb80395..f9736fbdab03 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -185,9 +185,7 @@ static elevator_t *elevator_alloc(struct request_queue *q,
185 185
186 eq->ops = &e->ops; 186 eq->ops = &e->ops;
187 eq->elevator_type = e; 187 eq->elevator_type = e;
188 kobject_init(&eq->kobj); 188 kobject_init(&eq->kobj, &elv_ktype);
189 kobject_set_name(&eq->kobj, "%s", "iosched");
190 eq->kobj.ktype = &elv_ktype;
191 mutex_init(&eq->sysfs_lock); 189 mutex_init(&eq->sysfs_lock);
192 190
193 eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES, 191 eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES,
@@ -931,9 +929,7 @@ int elv_register_queue(struct request_queue *q)
931 elevator_t *e = q->elevator; 929 elevator_t *e = q->elevator;
932 int error; 930 int error;
933 931
934 e->kobj.parent = &q->kobj; 932 error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched");
935
936 error = kobject_add(&e->kobj);
937 if (!error) { 933 if (!error) {
938 struct elv_fs_entry *attr = e->elevator_type->elevator_attrs; 934 struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
939 if (attr) { 935 if (attr) {
diff --git a/block/genhd.c b/block/genhd.c
index f2ac914160d1..5e4ab4b37d9f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -17,8 +17,10 @@
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19 19
20struct kset block_subsys; 20static DEFINE_MUTEX(block_class_lock);
21static DEFINE_MUTEX(block_subsys_lock); 21#ifndef CONFIG_SYSFS_DEPRECATED
22struct kobject *block_depr;
23#endif
22 24
23/* 25/*
24 * Can be deleted altogether. Later. 26 * Can be deleted altogether. Later.
@@ -37,19 +39,17 @@ static inline int major_to_index(int major)
37} 39}
38 40
39#ifdef CONFIG_PROC_FS 41#ifdef CONFIG_PROC_FS
40
41void blkdev_show(struct seq_file *f, off_t offset) 42void blkdev_show(struct seq_file *f, off_t offset)
42{ 43{
43 struct blk_major_name *dp; 44 struct blk_major_name *dp;
44 45
45 if (offset < BLKDEV_MAJOR_HASH_SIZE) { 46 if (offset < BLKDEV_MAJOR_HASH_SIZE) {
46 mutex_lock(&block_subsys_lock); 47 mutex_lock(&block_class_lock);
47 for (dp = major_names[offset]; dp; dp = dp->next) 48 for (dp = major_names[offset]; dp; dp = dp->next)
48 seq_printf(f, "%3d %s\n", dp->major, dp->name); 49 seq_printf(f, "%3d %s\n", dp->major, dp->name);
49 mutex_unlock(&block_subsys_lock); 50 mutex_unlock(&block_class_lock);
50 } 51 }
51} 52}
52
53#endif /* CONFIG_PROC_FS */ 53#endif /* CONFIG_PROC_FS */
54 54
55int register_blkdev(unsigned int major, const char *name) 55int register_blkdev(unsigned int major, const char *name)
@@ -57,7 +57,7 @@ int register_blkdev(unsigned int major, const char *name)
57 struct blk_major_name **n, *p; 57 struct blk_major_name **n, *p;
58 int index, ret = 0; 58 int index, ret = 0;
59 59
60 mutex_lock(&block_subsys_lock); 60 mutex_lock(&block_class_lock);
61 61
62 /* temporary */ 62 /* temporary */
63 if (major == 0) { 63 if (major == 0) {
@@ -102,7 +102,7 @@ int register_blkdev(unsigned int major, const char *name)
102 kfree(p); 102 kfree(p);
103 } 103 }
104out: 104out:
105 mutex_unlock(&block_subsys_lock); 105 mutex_unlock(&block_class_lock);
106 return ret; 106 return ret;
107} 107}
108 108
@@ -114,7 +114,7 @@ void unregister_blkdev(unsigned int major, const char *name)
114 struct blk_major_name *p = NULL; 114 struct blk_major_name *p = NULL;
115 int index = major_to_index(major); 115 int index = major_to_index(major);
116 116
117 mutex_lock(&block_subsys_lock); 117 mutex_lock(&block_class_lock);
118 for (n = &major_names[index]; *n; n = &(*n)->next) 118 for (n = &major_names[index]; *n; n = &(*n)->next)
119 if ((*n)->major == major) 119 if ((*n)->major == major)
120 break; 120 break;
@@ -124,7 +124,7 @@ void unregister_blkdev(unsigned int major, const char *name)
124 p = *n; 124 p = *n;
125 *n = p->next; 125 *n = p->next;
126 } 126 }
127 mutex_unlock(&block_subsys_lock); 127 mutex_unlock(&block_class_lock);
128 kfree(p); 128 kfree(p);
129} 129}
130 130
@@ -137,29 +137,30 @@ static struct kobj_map *bdev_map;
137 * range must be nonzero 137 * range must be nonzero
138 * The hash chain is sorted on range, so that subranges can override. 138 * The hash chain is sorted on range, so that subranges can override.
139 */ 139 */
140void blk_register_region(dev_t dev, unsigned long range, struct module *module, 140void blk_register_region(dev_t devt, unsigned long range, struct module *module,
141 struct kobject *(*probe)(dev_t, int *, void *), 141 struct kobject *(*probe)(dev_t, int *, void *),
142 int (*lock)(dev_t, void *), void *data) 142 int (*lock)(dev_t, void *), void *data)
143{ 143{
144 kobj_map(bdev_map, dev, range, module, probe, lock, data); 144 kobj_map(bdev_map, devt, range, module, probe, lock, data);
145} 145}
146 146
147EXPORT_SYMBOL(blk_register_region); 147EXPORT_SYMBOL(blk_register_region);
148 148
149void blk_unregister_region(dev_t dev, unsigned long range) 149void blk_unregister_region(dev_t devt, unsigned long range)
150{ 150{
151 kobj_unmap(bdev_map, dev, range); 151 kobj_unmap(bdev_map, devt, range);
152} 152}
153 153
154EXPORT_SYMBOL(blk_unregister_region); 154EXPORT_SYMBOL(blk_unregister_region);
155 155
156static struct kobject *exact_match(dev_t dev, int *part, void *data) 156static struct kobject *exact_match(dev_t devt, int *part, void *data)
157{ 157{
158 struct gendisk *p = data; 158 struct gendisk *p = data;
159 return &p->kobj; 159
160 return &p->dev.kobj;
160} 161}
161 162
162static int exact_lock(dev_t dev, void *data) 163static int exact_lock(dev_t devt, void *data)
163{ 164{
164 struct gendisk *p = data; 165 struct gendisk *p = data;
165 166
@@ -194,8 +195,6 @@ void unlink_gendisk(struct gendisk *disk)
194 disk->minors); 195 disk->minors);
195} 196}
196 197
197#define to_disk(obj) container_of(obj,struct gendisk,kobj)
198
199/** 198/**
200 * get_gendisk - get partitioning information for a given device 199 * get_gendisk - get partitioning information for a given device
201 * @dev: device to get partitioning information for 200 * @dev: device to get partitioning information for
@@ -203,10 +202,12 @@ void unlink_gendisk(struct gendisk *disk)
203 * This function gets the structure containing partitioning 202 * This function gets the structure containing partitioning
204 * information for the given device @dev. 203 * information for the given device @dev.
205 */ 204 */
206struct gendisk *get_gendisk(dev_t dev, int *part) 205struct gendisk *get_gendisk(dev_t devt, int *part)
207{ 206{
208 struct kobject *kobj = kobj_lookup(bdev_map, dev, part); 207 struct kobject *kobj = kobj_lookup(bdev_map, devt, part);
209 return kobj ? to_disk(kobj) : NULL; 208 struct device *dev = kobj_to_dev(kobj);
209
210 return kobj ? dev_to_disk(dev) : NULL;
210} 211}
211 212
212/* 213/*
@@ -216,13 +217,17 @@ struct gendisk *get_gendisk(dev_t dev, int *part)
216 */ 217 */
217void __init printk_all_partitions(void) 218void __init printk_all_partitions(void)
218{ 219{
219 int n; 220 struct device *dev;
220 struct gendisk *sgp; 221 struct gendisk *sgp;
222 char buf[BDEVNAME_SIZE];
223 int n;
221 224
222 mutex_lock(&block_subsys_lock); 225 mutex_lock(&block_class_lock);
223 /* For each block device... */ 226 /* For each block device... */
224 list_for_each_entry(sgp, &block_subsys.list, kobj.entry) { 227 list_for_each_entry(dev, &block_class.devices, node) {
225 char buf[BDEVNAME_SIZE]; 228 if (dev->type != &disk_type)
229 continue;
230 sgp = dev_to_disk(dev);
226 /* 231 /*
227 * Don't show empty devices or things that have been surpressed 232 * Don't show empty devices or things that have been surpressed
228 */ 233 */
@@ -255,38 +260,46 @@ void __init printk_all_partitions(void)
255 sgp->major, n + 1 + sgp->first_minor, 260 sgp->major, n + 1 + sgp->first_minor,
256 (unsigned long long)sgp->part[n]->nr_sects >> 1, 261 (unsigned long long)sgp->part[n]->nr_sects >> 1,
257 disk_name(sgp, n + 1, buf)); 262 disk_name(sgp, n + 1, buf));
258 } /* partition subloop */ 263 }
259 } /* Block device loop */ 264 }
260 265
261 mutex_unlock(&block_subsys_lock); 266 mutex_unlock(&block_class_lock);
262 return;
263} 267}
264 268
265#ifdef CONFIG_PROC_FS 269#ifdef CONFIG_PROC_FS
266/* iterator */ 270/* iterator */
267static void *part_start(struct seq_file *part, loff_t *pos) 271static void *part_start(struct seq_file *part, loff_t *pos)
268{ 272{
269 struct list_head *p; 273 loff_t k = *pos;
270 loff_t l = *pos; 274 struct device *dev;
271 275
272 mutex_lock(&block_subsys_lock); 276 mutex_lock(&block_class_lock);
273 list_for_each(p, &block_subsys.list) 277 list_for_each_entry(dev, &block_class.devices, node) {
274 if (!l--) 278 if (dev->type != &disk_type)
275 return list_entry(p, struct gendisk, kobj.entry); 279 continue;
280 if (!k--)
281 return dev_to_disk(dev);
282 }
276 return NULL; 283 return NULL;
277} 284}
278 285
279static void *part_next(struct seq_file *part, void *v, loff_t *pos) 286static void *part_next(struct seq_file *part, void *v, loff_t *pos)
280{ 287{
281 struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; 288 struct gendisk *gp = v;
289 struct device *dev;
282 ++*pos; 290 ++*pos;
283 return p==&block_subsys.list ? NULL : 291 list_for_each_entry(dev, &gp->dev.node, node) {
284 list_entry(p, struct gendisk, kobj.entry); 292 if (&dev->node == &block_class.devices)
293 return NULL;
294 if (dev->type == &disk_type)
295 return dev_to_disk(dev);
296 }
297 return NULL;
285} 298}
286 299
287static void part_stop(struct seq_file *part, void *v) 300static void part_stop(struct seq_file *part, void *v)
288{ 301{
289 mutex_unlock(&block_subsys_lock); 302 mutex_unlock(&block_class_lock);
290} 303}
291 304
292static int show_partition(struct seq_file *part, void *v) 305static int show_partition(struct seq_file *part, void *v)
@@ -295,7 +308,7 @@ static int show_partition(struct seq_file *part, void *v)
295 int n; 308 int n;
296 char buf[BDEVNAME_SIZE]; 309 char buf[BDEVNAME_SIZE];
297 310
298 if (&sgp->kobj.entry == block_subsys.list.next) 311 if (&sgp->dev.node == block_class.devices.next)
299 seq_puts(part, "major minor #blocks name\n\n"); 312 seq_puts(part, "major minor #blocks name\n\n");
300 313
301 /* Don't show non-partitionable removeable devices or empty devices */ 314 /* Don't show non-partitionable removeable devices or empty devices */
@@ -325,110 +338,81 @@ static int show_partition(struct seq_file *part, void *v)
325} 338}
326 339
327struct seq_operations partitions_op = { 340struct seq_operations partitions_op = {
328 .start =part_start, 341 .start = part_start,
329 .next = part_next, 342 .next = part_next,
330 .stop = part_stop, 343 .stop = part_stop,
331 .show = show_partition 344 .show = show_partition
332}; 345};
333#endif 346#endif
334 347
335 348
336extern int blk_dev_init(void); 349extern int blk_dev_init(void);
337 350
338static struct kobject *base_probe(dev_t dev, int *part, void *data) 351static struct kobject *base_probe(dev_t devt, int *part, void *data)
339{ 352{
340 if (request_module("block-major-%d-%d", MAJOR(dev), MINOR(dev)) > 0) 353 if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
341 /* Make old-style 2.4 aliases work */ 354 /* Make old-style 2.4 aliases work */
342 request_module("block-major-%d", MAJOR(dev)); 355 request_module("block-major-%d", MAJOR(devt));
343 return NULL; 356 return NULL;
344} 357}
345 358
346static int __init genhd_device_init(void) 359static int __init genhd_device_init(void)
347{ 360{
348 int err; 361 class_register(&block_class);
349 362 bdev_map = kobj_map_init(base_probe, &block_class_lock);
350 bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
351 blk_dev_init(); 363 blk_dev_init();
352 err = subsystem_register(&block_subsys); 364
353 if (err < 0) 365#ifndef CONFIG_SYSFS_DEPRECATED
354 printk(KERN_WARNING "%s: subsystem_register error: %d\n", 366 /* create top-level block dir */
355 __FUNCTION__, err); 367 block_depr = kobject_create_and_add("block", NULL);
356 return err; 368#endif
369 return 0;
357} 370}
358 371
359subsys_initcall(genhd_device_init); 372subsys_initcall(genhd_device_init);
360 373
361 374static ssize_t disk_range_show(struct device *dev,
362 375 struct device_attribute *attr, char *buf)
363/*
364 * kobject & sysfs bindings for block devices
365 */
366static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr,
367 char *page)
368{ 376{
369 struct gendisk *disk = to_disk(kobj); 377 struct gendisk *disk = dev_to_disk(dev);
370 struct disk_attribute *disk_attr =
371 container_of(attr,struct disk_attribute,attr);
372 ssize_t ret = -EIO;
373 378
374 if (disk_attr->show) 379 return sprintf(buf, "%d\n", disk->minors);
375 ret = disk_attr->show(disk,page);
376 return ret;
377} 380}
378 381
379static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr, 382static ssize_t disk_removable_show(struct device *dev,
380 const char *page, size_t count) 383 struct device_attribute *attr, char *buf)
381{ 384{
382 struct gendisk *disk = to_disk(kobj); 385 struct gendisk *disk = dev_to_disk(dev);
383 struct disk_attribute *disk_attr =
384 container_of(attr,struct disk_attribute,attr);
385 ssize_t ret = 0;
386 386
387 if (disk_attr->store) 387 return sprintf(buf, "%d\n",
388 ret = disk_attr->store(disk, page, count); 388 (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
389 return ret;
390} 389}
391 390
392static struct sysfs_ops disk_sysfs_ops = { 391static ssize_t disk_size_show(struct device *dev,
393 .show = &disk_attr_show, 392 struct device_attribute *attr, char *buf)
394 .store = &disk_attr_store,
395};
396
397static ssize_t disk_uevent_store(struct gendisk * disk,
398 const char *buf, size_t count)
399{
400 kobject_uevent(&disk->kobj, KOBJ_ADD);
401 return count;
402}
403static ssize_t disk_dev_read(struct gendisk * disk, char *page)
404{
405 dev_t base = MKDEV(disk->major, disk->first_minor);
406 return print_dev_t(page, base);
407}
408static ssize_t disk_range_read(struct gendisk * disk, char *page)
409{ 393{
410 return sprintf(page, "%d\n", disk->minors); 394 struct gendisk *disk = dev_to_disk(dev);
411}
412static ssize_t disk_removable_read(struct gendisk * disk, char *page)
413{
414 return sprintf(page, "%d\n",
415 (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
416 395
396 return sprintf(buf, "%llu\n", (unsigned long long)get_capacity(disk));
417} 397}
418static ssize_t disk_size_read(struct gendisk * disk, char *page) 398
419{ 399static ssize_t disk_capability_show(struct device *dev,
420 return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk)); 400 struct device_attribute *attr, char *buf)
421}
422static ssize_t disk_capability_read(struct gendisk *disk, char *page)
423{ 401{
424 return sprintf(page, "%x\n", disk->flags); 402 struct gendisk *disk = dev_to_disk(dev);
403
404 return sprintf(buf, "%x\n", disk->flags);
425} 405}
426static ssize_t disk_stats_read(struct gendisk * disk, char *page) 406
407static ssize_t disk_stat_show(struct device *dev,
408 struct device_attribute *attr, char *buf)
427{ 409{
410 struct gendisk *disk = dev_to_disk(dev);
411
428 preempt_disable(); 412 preempt_disable();
429 disk_round_stats(disk); 413 disk_round_stats(disk);
430 preempt_enable(); 414 preempt_enable();
431 return sprintf(page, 415 return sprintf(buf,
432 "%8lu %8lu %8llu %8u " 416 "%8lu %8lu %8llu %8u "
433 "%8lu %8lu %8llu %8u " 417 "%8lu %8lu %8llu %8u "
434 "%8u %8u %8u" 418 "%8u %8u %8u"
@@ -445,40 +429,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
445 jiffies_to_msecs(disk_stat_read(disk, io_ticks)), 429 jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
446 jiffies_to_msecs(disk_stat_read(disk, time_in_queue))); 430 jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
447} 431}
448static struct disk_attribute disk_attr_uevent = {
449 .attr = {.name = "uevent", .mode = S_IWUSR },
450 .store = disk_uevent_store
451};
452static struct disk_attribute disk_attr_dev = {
453 .attr = {.name = "dev", .mode = S_IRUGO },
454 .show = disk_dev_read
455};
456static struct disk_attribute disk_attr_range = {
457 .attr = {.name = "range", .mode = S_IRUGO },
458 .show = disk_range_read
459};
460static struct disk_attribute disk_attr_removable = {
461 .attr = {.name = "removable", .mode = S_IRUGO },
462 .show = disk_removable_read
463};
464static struct disk_attribute disk_attr_size = {
465 .attr = {.name = "size", .mode = S_IRUGO },
466 .show = disk_size_read
467};
468static struct disk_attribute disk_attr_capability = {
469 .attr = {.name = "capability", .mode = S_IRUGO },
470 .show = disk_capability_read
471};
472static struct disk_attribute disk_attr_stat = {
473 .attr = {.name = "stat", .mode = S_IRUGO },
474 .show = disk_stats_read
475};
476 432
477#ifdef CONFIG_FAIL_MAKE_REQUEST 433#ifdef CONFIG_FAIL_MAKE_REQUEST
434static ssize_t disk_fail_show(struct device *dev,
435 struct device_attribute *attr, char *buf)
436{
437 struct gendisk *disk = dev_to_disk(dev);
438
439 return sprintf(buf, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
440}
478 441
479static ssize_t disk_fail_store(struct gendisk * disk, 442static ssize_t disk_fail_store(struct device *dev,
443 struct device_attribute *attr,
480 const char *buf, size_t count) 444 const char *buf, size_t count)
481{ 445{
446 struct gendisk *disk = dev_to_disk(dev);
482 int i; 447 int i;
483 448
484 if (count > 0 && sscanf(buf, "%d", &i) > 0) { 449 if (count > 0 && sscanf(buf, "%d", &i) > 0) {
@@ -490,136 +455,100 @@ static ssize_t disk_fail_store(struct gendisk * disk,
490 455
491 return count; 456 return count;
492} 457}
493static ssize_t disk_fail_read(struct gendisk * disk, char *page)
494{
495 return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
496}
497static struct disk_attribute disk_attr_fail = {
498 .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
499 .store = disk_fail_store,
500 .show = disk_fail_read
501};
502 458
503#endif 459#endif
504 460
505static struct attribute * default_attrs[] = { 461static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
506 &disk_attr_uevent.attr, 462static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
507 &disk_attr_dev.attr, 463static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL);
508 &disk_attr_range.attr, 464static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
509 &disk_attr_removable.attr, 465static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);
510 &disk_attr_size.attr, 466#ifdef CONFIG_FAIL_MAKE_REQUEST
511 &disk_attr_stat.attr, 467static struct device_attribute dev_attr_fail =
512 &disk_attr_capability.attr, 468 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, disk_fail_show, disk_fail_store);
469#endif
470
471static struct attribute *disk_attrs[] = {
472 &dev_attr_range.attr,
473 &dev_attr_removable.attr,
474 &dev_attr_size.attr,
475 &dev_attr_capability.attr,
476 &dev_attr_stat.attr,
513#ifdef CONFIG_FAIL_MAKE_REQUEST 477#ifdef CONFIG_FAIL_MAKE_REQUEST
514 &disk_attr_fail.attr, 478 &dev_attr_fail.attr,
515#endif 479#endif
516 NULL, 480 NULL
481};
482
483static struct attribute_group disk_attr_group = {
484 .attrs = disk_attrs,
517}; 485};
518 486
519static void disk_release(struct kobject * kobj) 487static struct attribute_group *disk_attr_groups[] = {
488 &disk_attr_group,
489 NULL
490};
491
492static void disk_release(struct device *dev)
520{ 493{
521 struct gendisk *disk = to_disk(kobj); 494 struct gendisk *disk = dev_to_disk(dev);
495
522 kfree(disk->random); 496 kfree(disk->random);
523 kfree(disk->part); 497 kfree(disk->part);
524 free_disk_stats(disk); 498 free_disk_stats(disk);
525 kfree(disk); 499 kfree(disk);
526} 500}
527 501struct class block_class = {
528static struct kobj_type ktype_block = { 502 .name = "block",
529 .release = disk_release,
530 .sysfs_ops = &disk_sysfs_ops,
531 .default_attrs = default_attrs,
532}; 503};
533 504
534extern struct kobj_type ktype_part; 505struct device_type disk_type = {
535 506 .name = "disk",
536static int block_uevent_filter(struct kset *kset, struct kobject *kobj) 507 .groups = disk_attr_groups,
537{ 508 .release = disk_release,
538 struct kobj_type *ktype = get_ktype(kobj);
539
540 return ((ktype == &ktype_block) || (ktype == &ktype_part));
541}
542
543static int block_uevent(struct kset *kset, struct kobject *kobj,
544 struct kobj_uevent_env *env)
545{
546 struct kobj_type *ktype = get_ktype(kobj);
547 struct device *physdev;
548 struct gendisk *disk;
549 struct hd_struct *part;
550
551 if (ktype == &ktype_block) {
552 disk = container_of(kobj, struct gendisk, kobj);
553 add_uevent_var(env, "MINOR=%u", disk->first_minor);
554 } else if (ktype == &ktype_part) {
555 disk = container_of(kobj->parent, struct gendisk, kobj);
556 part = container_of(kobj, struct hd_struct, kobj);
557 add_uevent_var(env, "MINOR=%u",
558 disk->first_minor + part->partno);
559 } else
560 return 0;
561
562 add_uevent_var(env, "MAJOR=%u", disk->major);
563
564 /* add physical device, backing this device */
565 physdev = disk->driverfs_dev;
566 if (physdev) {
567 char *path = kobject_get_path(&physdev->kobj, GFP_KERNEL);
568
569 add_uevent_var(env, "PHYSDEVPATH=%s", path);
570 kfree(path);
571
572 if (physdev->bus)
573 add_uevent_var(env, "PHYSDEVBUS=%s", physdev->bus->name);
574
575 if (physdev->driver)
576 add_uevent_var(env, physdev->driver->name);
577 }
578
579 return 0;
580}
581
582static struct kset_uevent_ops block_uevent_ops = {
583 .filter = block_uevent_filter,
584 .uevent = block_uevent,
585}; 509};
586 510
587decl_subsys(block, &ktype_block, &block_uevent_ops);
588
589/* 511/*
590 * aggregate disk stat collector. Uses the same stats that the sysfs 512 * aggregate disk stat collector. Uses the same stats that the sysfs
591 * entries do, above, but makes them available through one seq_file. 513 * entries do, above, but makes them available through one seq_file.
592 * Watching a few disks may be efficient through sysfs, but watching
593 * all of them will be more efficient through this interface.
594 * 514 *
595 * The output looks suspiciously like /proc/partitions with a bunch of 515 * The output looks suspiciously like /proc/partitions with a bunch of
596 * extra fields. 516 * extra fields.
597 */ 517 */
598 518
599/* iterator */
600static void *diskstats_start(struct seq_file *part, loff_t *pos) 519static void *diskstats_start(struct seq_file *part, loff_t *pos)
601{ 520{
602 loff_t k = *pos; 521 loff_t k = *pos;
603 struct list_head *p; 522 struct device *dev;
604 523
605 mutex_lock(&block_subsys_lock); 524 mutex_lock(&block_class_lock);
606 list_for_each(p, &block_subsys.list) 525 list_for_each_entry(dev, &block_class.devices, node) {
526 if (dev->type != &disk_type)
527 continue;
607 if (!k--) 528 if (!k--)
608 return list_entry(p, struct gendisk, kobj.entry); 529 return dev_to_disk(dev);
530 }
609 return NULL; 531 return NULL;
610} 532}
611 533
612static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos) 534static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
613{ 535{
614 struct list_head *p = ((struct gendisk *)v)->kobj.entry.next; 536 struct gendisk *gp = v;
537 struct device *dev;
538
615 ++*pos; 539 ++*pos;
616 return p==&block_subsys.list ? NULL : 540 list_for_each_entry(dev, &gp->dev.node, node) {
617 list_entry(p, struct gendisk, kobj.entry); 541 if (&dev->node == &block_class.devices)
542 return NULL;
543 if (dev->type == &disk_type)
544 return dev_to_disk(dev);
545 }
546 return NULL;
618} 547}
619 548
620static void diskstats_stop(struct seq_file *part, void *v) 549static void diskstats_stop(struct seq_file *part, void *v)
621{ 550{
622 mutex_unlock(&block_subsys_lock); 551 mutex_unlock(&block_class_lock);
623} 552}
624 553
625static int diskstats_show(struct seq_file *s, void *v) 554static int diskstats_show(struct seq_file *s, void *v)
@@ -629,7 +558,7 @@ static int diskstats_show(struct seq_file *s, void *v)
629 int n = 0; 558 int n = 0;
630 559
631 /* 560 /*
632 if (&sgp->kobj.entry == block_subsys.kset.list.next) 561 if (&gp->dev.kobj.entry == block_class.devices.next)
633 seq_puts(s, "major minor name" 562 seq_puts(s, "major minor name"
634 " rio rmerge rsect ruse wio wmerge " 563 " rio rmerge rsect ruse wio wmerge "
635 "wsect wuse running use aveq" 564 "wsect wuse running use aveq"
@@ -683,7 +612,7 @@ static void media_change_notify_thread(struct work_struct *work)
683 * set enviroment vars to indicate which event this is for 612 * set enviroment vars to indicate which event this is for
684 * so that user space will know to go check the media status. 613 * so that user space will know to go check the media status.
685 */ 614 */
686 kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp); 615 kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp);
687 put_device(gd->driverfs_dev); 616 put_device(gd->driverfs_dev);
688} 617}
689 618
@@ -694,6 +623,25 @@ void genhd_media_change_notify(struct gendisk *disk)
694} 623}
695EXPORT_SYMBOL_GPL(genhd_media_change_notify); 624EXPORT_SYMBOL_GPL(genhd_media_change_notify);
696 625
626dev_t blk_lookup_devt(const char *name)
627{
628 struct device *dev;
629 dev_t devt = MKDEV(0, 0);
630
631 mutex_lock(&block_class_lock);
632 list_for_each_entry(dev, &block_class.devices, node) {
633 if (strcmp(dev->bus_id, name) == 0) {
634 devt = dev->devt;
635 break;
636 }
637 }
638 mutex_unlock(&block_class_lock);
639
640 return devt;
641}
642
643EXPORT_SYMBOL(blk_lookup_devt);
644
697struct gendisk *alloc_disk(int minors) 645struct gendisk *alloc_disk(int minors)
698{ 646{
699 return alloc_disk_node(minors, -1); 647 return alloc_disk_node(minors, -1);
@@ -721,9 +669,10 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
721 } 669 }
722 } 670 }
723 disk->minors = minors; 671 disk->minors = minors;
724 kobj_set_kset_s(disk,block_subsys);
725 kobject_init(&disk->kobj);
726 rand_initialize_disk(disk); 672 rand_initialize_disk(disk);
673 disk->dev.class = &block_class;
674 disk->dev.type = &disk_type;
675 device_initialize(&disk->dev);
727 INIT_WORK(&disk->async_notify, 676 INIT_WORK(&disk->async_notify,
728 media_change_notify_thread); 677 media_change_notify_thread);
729 } 678 }
@@ -743,7 +692,7 @@ struct kobject *get_disk(struct gendisk *disk)
743 owner = disk->fops->owner; 692 owner = disk->fops->owner;
744 if (owner && !try_module_get(owner)) 693 if (owner && !try_module_get(owner))
745 return NULL; 694 return NULL;
746 kobj = kobject_get(&disk->kobj); 695 kobj = kobject_get(&disk->dev.kobj);
747 if (kobj == NULL) { 696 if (kobj == NULL) {
748 module_put(owner); 697 module_put(owner);
749 return NULL; 698 return NULL;
@@ -757,7 +706,7 @@ EXPORT_SYMBOL(get_disk);
757void put_disk(struct gendisk *disk) 706void put_disk(struct gendisk *disk)
758{ 707{
759 if (disk) 708 if (disk)
760 kobject_put(&disk->kobj); 709 kobject_put(&disk->dev.kobj);
761} 710}
762 711
763EXPORT_SYMBOL(put_disk); 712EXPORT_SYMBOL(put_disk);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 8b919940b2ab..5ccec8aa964b 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1862,9 +1862,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
1862 1862
1863 init_timer(&q->unplug_timer); 1863 init_timer(&q->unplug_timer);
1864 1864
1865 kobject_set_name(&q->kobj, "%s", "queue"); 1865 kobject_init(&q->kobj, &queue_ktype);
1866 q->kobj.ktype = &queue_ktype;
1867 kobject_init(&q->kobj);
1868 1866
1869 mutex_init(&q->sysfs_lock); 1867 mutex_init(&q->sysfs_lock);
1870 1868
@@ -4182,9 +4180,8 @@ int blk_register_queue(struct gendisk *disk)
4182 if (!q || !q->request_fn) 4180 if (!q || !q->request_fn)
4183 return -ENXIO; 4181 return -ENXIO;
4184 4182
4185 q->kobj.parent = kobject_get(&disk->kobj); 4183 ret = kobject_add(&q->kobj, kobject_get(&disk->dev.kobj),
4186 4184 "%s", "queue");
4187 ret = kobject_add(&q->kobj);
4188 if (ret < 0) 4185 if (ret < 0)
4189 return ret; 4186 return ret;
4190 4187
@@ -4209,6 +4206,6 @@ void blk_unregister_queue(struct gendisk *disk)
4209 4206
4210 kobject_uevent(&q->kobj, KOBJ_REMOVE); 4207 kobject_uevent(&q->kobj, KOBJ_REMOVE);
4211 kobject_del(&q->kobj); 4208 kobject_del(&q->kobj);
4212 kobject_put(&disk->kobj); 4209 kobject_put(&disk->dev.kobj);
4213 } 4210 }
4214} 4211}
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 083d2e1dfc21..c3166a1a5bb6 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -24,10 +24,6 @@ config CRYPTO_ALGAPI
24 help 24 help
25 This option provides the API for cryptographic algorithms. 25 This option provides the API for cryptographic algorithms.
26 26
27config CRYPTO_ABLKCIPHER
28 tristate
29 select CRYPTO_BLKCIPHER
30
31config CRYPTO_AEAD 27config CRYPTO_AEAD
32 tristate 28 tristate
33 select CRYPTO_ALGAPI 29 select CRYPTO_ALGAPI
@@ -36,6 +32,15 @@ config CRYPTO_BLKCIPHER
36 tristate 32 tristate
37 select CRYPTO_ALGAPI 33 select CRYPTO_ALGAPI
38 34
35config CRYPTO_SEQIV
36 tristate "Sequence Number IV Generator"
37 select CRYPTO_AEAD
38 select CRYPTO_BLKCIPHER
39 help
40 This IV generator generates an IV based on a sequence number by
41 xoring it with a salt. This algorithm is mainly useful for CTR
42 and similar modes.
43
39config CRYPTO_HASH 44config CRYPTO_HASH
40 tristate 45 tristate
41 select CRYPTO_ALGAPI 46 select CRYPTO_ALGAPI
@@ -91,7 +96,7 @@ config CRYPTO_SHA1
91 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). 96 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
92 97
93config CRYPTO_SHA256 98config CRYPTO_SHA256
94 tristate "SHA256 digest algorithm" 99 tristate "SHA224 and SHA256 digest algorithm"
95 select CRYPTO_ALGAPI 100 select CRYPTO_ALGAPI
96 help 101 help
97 SHA256 secure hash standard (DFIPS 180-2). 102 SHA256 secure hash standard (DFIPS 180-2).
@@ -99,6 +104,9 @@ config CRYPTO_SHA256
99 This version of SHA implements a 256 bit hash with 128 bits of 104 This version of SHA implements a 256 bit hash with 128 bits of
100 security against collision attacks. 105 security against collision attacks.
101 106
107 This code also includes SHA-224, a 224 bit hash with 112 bits
108 of security against collision attacks.
109
102config CRYPTO_SHA512 110config CRYPTO_SHA512
103 tristate "SHA384 and SHA512 digest algorithms" 111 tristate "SHA384 and SHA512 digest algorithms"
104 select CRYPTO_ALGAPI 112 select CRYPTO_ALGAPI
@@ -195,9 +203,34 @@ config CRYPTO_XTS
195 key size 256, 384 or 512 bits. This implementation currently 203 key size 256, 384 or 512 bits. This implementation currently
196 can't handle a sectorsize which is not a multiple of 16 bytes. 204 can't handle a sectorsize which is not a multiple of 16 bytes.
197 205
206config CRYPTO_CTR
207 tristate "CTR support"
208 select CRYPTO_BLKCIPHER
209 select CRYPTO_SEQIV
210 select CRYPTO_MANAGER
211 help
212 CTR: Counter mode
213 This block cipher algorithm is required for IPSec.
214
215config CRYPTO_GCM
216 tristate "GCM/GMAC support"
217 select CRYPTO_CTR
218 select CRYPTO_AEAD
219 select CRYPTO_GF128MUL
220 help
221 Support for Galois/Counter Mode (GCM) and Galois Message
222 Authentication Code (GMAC). Required for IPSec.
223
224config CRYPTO_CCM
225 tristate "CCM support"
226 select CRYPTO_CTR
227 select CRYPTO_AEAD
228 help
229 Support for Counter with CBC MAC. Required for IPsec.
230
198config CRYPTO_CRYPTD 231config CRYPTO_CRYPTD
199 tristate "Software async crypto daemon" 232 tristate "Software async crypto daemon"
200 select CRYPTO_ABLKCIPHER 233 select CRYPTO_BLKCIPHER
201 select CRYPTO_MANAGER 234 select CRYPTO_MANAGER
202 help 235 help
203 This is a generic software asynchronous crypto daemon that 236 This is a generic software asynchronous crypto daemon that
@@ -320,6 +353,7 @@ config CRYPTO_AES_586
320 tristate "AES cipher algorithms (i586)" 353 tristate "AES cipher algorithms (i586)"
321 depends on (X86 || UML_X86) && !64BIT 354 depends on (X86 || UML_X86) && !64BIT
322 select CRYPTO_ALGAPI 355 select CRYPTO_ALGAPI
356 select CRYPTO_AES
323 help 357 help
324 AES cipher algorithms (FIPS-197). AES uses the Rijndael 358 AES cipher algorithms (FIPS-197). AES uses the Rijndael
325 algorithm. 359 algorithm.
@@ -341,6 +375,7 @@ config CRYPTO_AES_X86_64
341 tristate "AES cipher algorithms (x86_64)" 375 tristate "AES cipher algorithms (x86_64)"
342 depends on (X86 || UML_X86) && 64BIT 376 depends on (X86 || UML_X86) && 64BIT
343 select CRYPTO_ALGAPI 377 select CRYPTO_ALGAPI
378 select CRYPTO_AES
344 help 379 help
345 AES cipher algorithms (FIPS-197). AES uses the Rijndael 380 AES cipher algorithms (FIPS-197). AES uses the Rijndael
346 algorithm. 381 algorithm.
@@ -441,6 +476,46 @@ config CRYPTO_SEED
441 See also: 476 See also:
442 <http://www.kisa.or.kr/kisa/seed/jsp/seed_eng.jsp> 477 <http://www.kisa.or.kr/kisa/seed/jsp/seed_eng.jsp>
443 478
479config CRYPTO_SALSA20
480 tristate "Salsa20 stream cipher algorithm (EXPERIMENTAL)"
481 depends on EXPERIMENTAL
482 select CRYPTO_BLKCIPHER
483 help
484 Salsa20 stream cipher algorithm.
485
486 Salsa20 is a stream cipher submitted to eSTREAM, the ECRYPT
487 Stream Cipher Project. See <http://www.ecrypt.eu.org/stream/>
488
489 The Salsa20 stream cipher algorithm is designed by Daniel J.
490 Bernstein <djb@cr.yp.to>. See <http://cr.yp.to/snuffle.html>
491
492config CRYPTO_SALSA20_586
493 tristate "Salsa20 stream cipher algorithm (i586) (EXPERIMENTAL)"
494 depends on (X86 || UML_X86) && !64BIT
495 depends on EXPERIMENTAL
496 select CRYPTO_BLKCIPHER
497 help
498 Salsa20 stream cipher algorithm.
499
500 Salsa20 is a stream cipher submitted to eSTREAM, the ECRYPT
501 Stream Cipher Project. See <http://www.ecrypt.eu.org/stream/>
502
503 The Salsa20 stream cipher algorithm is designed by Daniel J.
504 Bernstein <djb@cr.yp.to>. See <http://cr.yp.to/snuffle.html>
505
506config CRYPTO_SALSA20_X86_64
507 tristate "Salsa20 stream cipher algorithm (x86_64) (EXPERIMENTAL)"
508 depends on (X86 || UML_X86) && 64BIT
509 depends on EXPERIMENTAL
510 select CRYPTO_BLKCIPHER
511 help
512 Salsa20 stream cipher algorithm.
513
514 Salsa20 is a stream cipher submitted to eSTREAM, the ECRYPT
515 Stream Cipher Project. See <http://www.ecrypt.eu.org/stream/>
516
517 The Salsa20 stream cipher algorithm is designed by Daniel J.
518 Bernstein <djb@cr.yp.to>. See <http://cr.yp.to/snuffle.html>
444 519
445config CRYPTO_DEFLATE 520config CRYPTO_DEFLATE
446 tristate "Deflate compression algorithm" 521 tristate "Deflate compression algorithm"
@@ -491,6 +566,7 @@ config CRYPTO_TEST
491 tristate "Testing module" 566 tristate "Testing module"
492 depends on m 567 depends on m
493 select CRYPTO_ALGAPI 568 select CRYPTO_ALGAPI
569 select CRYPTO_AEAD
494 help 570 help
495 Quick & dirty crypto test module. 571 Quick & dirty crypto test module.
496 572
@@ -498,10 +574,19 @@ config CRYPTO_AUTHENC
498 tristate "Authenc support" 574 tristate "Authenc support"
499 select CRYPTO_AEAD 575 select CRYPTO_AEAD
500 select CRYPTO_MANAGER 576 select CRYPTO_MANAGER
577 select CRYPTO_HASH
501 help 578 help
502 Authenc: Combined mode wrapper for IPsec. 579 Authenc: Combined mode wrapper for IPsec.
503 This is required for IPSec. 580 This is required for IPSec.
504 581
582config CRYPTO_LZO
583 tristate "LZO compression algorithm"
584 select CRYPTO_ALGAPI
585 select LZO_COMPRESS
586 select LZO_DECOMPRESS
587 help
588 This is the LZO algorithm.
589
505source "drivers/crypto/Kconfig" 590source "drivers/crypto/Kconfig"
506 591
507endif # if CRYPTO 592endif # if CRYPTO
diff --git a/crypto/Makefile b/crypto/Makefile
index 43c2a0dc9936..48c758379954 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -8,9 +8,14 @@ crypto_algapi-$(CONFIG_PROC_FS) += proc.o
8crypto_algapi-objs := algapi.o scatterwalk.o $(crypto_algapi-y) 8crypto_algapi-objs := algapi.o scatterwalk.o $(crypto_algapi-y)
9obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o 9obj-$(CONFIG_CRYPTO_ALGAPI) += crypto_algapi.o
10 10
11obj-$(CONFIG_CRYPTO_ABLKCIPHER) += ablkcipher.o
12obj-$(CONFIG_CRYPTO_AEAD) += aead.o 11obj-$(CONFIG_CRYPTO_AEAD) += aead.o
13obj-$(CONFIG_CRYPTO_BLKCIPHER) += blkcipher.o 12
13crypto_blkcipher-objs := ablkcipher.o
14crypto_blkcipher-objs += blkcipher.o
15obj-$(CONFIG_CRYPTO_BLKCIPHER) += crypto_blkcipher.o
16obj-$(CONFIG_CRYPTO_BLKCIPHER) += chainiv.o
17obj-$(CONFIG_CRYPTO_BLKCIPHER) += eseqiv.o
18obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o
14 19
15crypto_hash-objs := hash.o 20crypto_hash-objs := hash.o
16obj-$(CONFIG_CRYPTO_HASH) += crypto_hash.o 21obj-$(CONFIG_CRYPTO_HASH) += crypto_hash.o
@@ -32,6 +37,9 @@ obj-$(CONFIG_CRYPTO_CBC) += cbc.o
32obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o 37obj-$(CONFIG_CRYPTO_PCBC) += pcbc.o
33obj-$(CONFIG_CRYPTO_LRW) += lrw.o 38obj-$(CONFIG_CRYPTO_LRW) += lrw.o
34obj-$(CONFIG_CRYPTO_XTS) += xts.o 39obj-$(CONFIG_CRYPTO_XTS) += xts.o
40obj-$(CONFIG_CRYPTO_CTR) += ctr.o
41obj-$(CONFIG_CRYPTO_GCM) += gcm.o
42obj-$(CONFIG_CRYPTO_CCM) += ccm.o
35obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o 43obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
36obj-$(CONFIG_CRYPTO_DES) += des_generic.o 44obj-$(CONFIG_CRYPTO_DES) += des_generic.o
37obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o 45obj-$(CONFIG_CRYPTO_FCRYPT) += fcrypt.o
@@ -48,10 +56,12 @@ obj-$(CONFIG_CRYPTO_TEA) += tea.o
48obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o 56obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o
49obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o 57obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
50obj-$(CONFIG_CRYPTO_SEED) += seed.o 58obj-$(CONFIG_CRYPTO_SEED) += seed.o
59obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
51obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o 60obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
52obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o 61obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
53obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o 62obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
54obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o 63obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
64obj-$(CONFIG_CRYPTO_LZO) += lzo.o
55 65
56obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o 66obj-$(CONFIG_CRYPTO_TEST) += tcrypt.o
57 67
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 2731acb86e7d..3bcb099b4a85 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -13,14 +13,18 @@
13 * 13 *
14 */ 14 */
15 15
16#include <crypto/algapi.h> 16#include <crypto/internal/skcipher.h>
17#include <linux/errno.h> 17#include <linux/err.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/rtnetlink.h>
22#include <linux/sched.h>
21#include <linux/slab.h> 23#include <linux/slab.h>
22#include <linux/seq_file.h> 24#include <linux/seq_file.h>
23 25
26#include "internal.h"
27
24static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key, 28static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key,
25 unsigned int keylen) 29 unsigned int keylen)
26{ 30{
@@ -66,6 +70,16 @@ static unsigned int crypto_ablkcipher_ctxsize(struct crypto_alg *alg, u32 type,
66 return alg->cra_ctxsize; 70 return alg->cra_ctxsize;
67} 71}
68 72
73int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req)
74{
75 return crypto_ablkcipher_encrypt(&req->creq);
76}
77
78int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req)
79{
80 return crypto_ablkcipher_decrypt(&req->creq);
81}
82
69static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type, 83static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
70 u32 mask) 84 u32 mask)
71{ 85{
@@ -78,6 +92,11 @@ static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
78 crt->setkey = setkey; 92 crt->setkey = setkey;
79 crt->encrypt = alg->encrypt; 93 crt->encrypt = alg->encrypt;
80 crt->decrypt = alg->decrypt; 94 crt->decrypt = alg->decrypt;
95 if (!alg->ivsize) {
96 crt->givencrypt = skcipher_null_givencrypt;
97 crt->givdecrypt = skcipher_null_givdecrypt;
98 }
99 crt->base = __crypto_ablkcipher_cast(tfm);
81 crt->ivsize = alg->ivsize; 100 crt->ivsize = alg->ivsize;
82 101
83 return 0; 102 return 0;
@@ -90,10 +109,13 @@ static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
90 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher; 109 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
91 110
92 seq_printf(m, "type : ablkcipher\n"); 111 seq_printf(m, "type : ablkcipher\n");
112 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
113 "yes" : "no");
93 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); 114 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
94 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize); 115 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
95 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize); 116 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
96 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize); 117 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
118 seq_printf(m, "geniv : %s\n", ablkcipher->geniv ?: "<default>");
97} 119}
98 120
99const struct crypto_type crypto_ablkcipher_type = { 121const struct crypto_type crypto_ablkcipher_type = {
@@ -105,5 +127,220 @@ const struct crypto_type crypto_ablkcipher_type = {
105}; 127};
106EXPORT_SYMBOL_GPL(crypto_ablkcipher_type); 128EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
107 129
130static int no_givdecrypt(struct skcipher_givcrypt_request *req)
131{
132 return -ENOSYS;
133}
134
135static int crypto_init_givcipher_ops(struct crypto_tfm *tfm, u32 type,
136 u32 mask)
137{
138 struct ablkcipher_alg *alg = &tfm->__crt_alg->cra_ablkcipher;
139 struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
140
141 if (alg->ivsize > PAGE_SIZE / 8)
142 return -EINVAL;
143
144 crt->setkey = tfm->__crt_alg->cra_flags & CRYPTO_ALG_GENIV ?
145 alg->setkey : setkey;
146 crt->encrypt = alg->encrypt;
147 crt->decrypt = alg->decrypt;
148 crt->givencrypt = alg->givencrypt;
149 crt->givdecrypt = alg->givdecrypt ?: no_givdecrypt;
150 crt->base = __crypto_ablkcipher_cast(tfm);
151 crt->ivsize = alg->ivsize;
152
153 return 0;
154}
155
156static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
157 __attribute__ ((unused));
158static void crypto_givcipher_show(struct seq_file *m, struct crypto_alg *alg)
159{
160 struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
161
162 seq_printf(m, "type : givcipher\n");
163 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
164 "yes" : "no");
165 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
166 seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
167 seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
168 seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
169 seq_printf(m, "geniv : %s\n", ablkcipher->geniv ?: "<built-in>");
170}
171
172const struct crypto_type crypto_givcipher_type = {
173 .ctxsize = crypto_ablkcipher_ctxsize,
174 .init = crypto_init_givcipher_ops,
175#ifdef CONFIG_PROC_FS
176 .show = crypto_givcipher_show,
177#endif
178};
179EXPORT_SYMBOL_GPL(crypto_givcipher_type);
180
181const char *crypto_default_geniv(const struct crypto_alg *alg)
182{
183 return alg->cra_flags & CRYPTO_ALG_ASYNC ? "eseqiv" : "chainiv";
184}
185
186static int crypto_givcipher_default(struct crypto_alg *alg, u32 type, u32 mask)
187{
188 struct rtattr *tb[3];
189 struct {
190 struct rtattr attr;
191 struct crypto_attr_type data;
192 } ptype;
193 struct {
194 struct rtattr attr;
195 struct crypto_attr_alg data;
196 } palg;
197 struct crypto_template *tmpl;
198 struct crypto_instance *inst;
199 struct crypto_alg *larval;
200 const char *geniv;
201 int err;
202
203 larval = crypto_larval_lookup(alg->cra_driver_name,
204 CRYPTO_ALG_TYPE_GIVCIPHER,
205 CRYPTO_ALG_TYPE_MASK);
206 err = PTR_ERR(larval);
207 if (IS_ERR(larval))
208 goto out;
209
210 err = -EAGAIN;
211 if (!crypto_is_larval(larval))
212 goto drop_larval;
213
214 ptype.attr.rta_len = sizeof(ptype);
215 ptype.attr.rta_type = CRYPTOA_TYPE;
216 ptype.data.type = type | CRYPTO_ALG_GENIV;
217 /* GENIV tells the template that we're making a default geniv. */
218 ptype.data.mask = mask | CRYPTO_ALG_GENIV;
219 tb[0] = &ptype.attr;
220
221 palg.attr.rta_len = sizeof(palg);
222 palg.attr.rta_type = CRYPTOA_ALG;
223 /* Must use the exact name to locate ourselves. */
224 memcpy(palg.data.name, alg->cra_driver_name, CRYPTO_MAX_ALG_NAME);
225 tb[1] = &palg.attr;
226
227 tb[2] = NULL;
228
229 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
230 CRYPTO_ALG_TYPE_BLKCIPHER)
231 geniv = alg->cra_blkcipher.geniv;
232 else
233 geniv = alg->cra_ablkcipher.geniv;
234
235 if (!geniv)
236 geniv = crypto_default_geniv(alg);
237
238 tmpl = crypto_lookup_template(geniv);
239 err = -ENOENT;
240 if (!tmpl)
241 goto kill_larval;
242
243 inst = tmpl->alloc(tb);
244 err = PTR_ERR(inst);
245 if (IS_ERR(inst))
246 goto put_tmpl;
247
248 if ((err = crypto_register_instance(tmpl, inst))) {
249 tmpl->free(inst);
250 goto put_tmpl;
251 }
252
253 /* Redo the lookup to use the instance we just registered. */
254 err = -EAGAIN;
255
256put_tmpl:
257 crypto_tmpl_put(tmpl);
258kill_larval:
259 crypto_larval_kill(larval);
260drop_larval:
261 crypto_mod_put(larval);
262out:
263 crypto_mod_put(alg);
264 return err;
265}
266
267static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
268 u32 mask)
269{
270 struct crypto_alg *alg;
271
272 alg = crypto_alg_mod_lookup(name, type, mask);
273 if (IS_ERR(alg))
274 return alg;
275
276 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
277 CRYPTO_ALG_TYPE_GIVCIPHER)
278 return alg;
279
280 if (!((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
281 CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
282 alg->cra_ablkcipher.ivsize))
283 return alg;
284
285 return ERR_PTR(crypto_givcipher_default(alg, type, mask));
286}
287
288int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
289 u32 type, u32 mask)
290{
291 struct crypto_alg *alg;
292 int err;
293
294 type = crypto_skcipher_type(type);
295 mask = crypto_skcipher_mask(mask);
296
297 alg = crypto_lookup_skcipher(name, type, mask);
298 if (IS_ERR(alg))
299 return PTR_ERR(alg);
300
301 err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
302 crypto_mod_put(alg);
303 return err;
304}
305EXPORT_SYMBOL_GPL(crypto_grab_skcipher);
306
307struct crypto_ablkcipher *crypto_alloc_ablkcipher(const char *alg_name,
308 u32 type, u32 mask)
309{
310 struct crypto_tfm *tfm;
311 int err;
312
313 type = crypto_skcipher_type(type);
314 mask = crypto_skcipher_mask(mask);
315
316 for (;;) {
317 struct crypto_alg *alg;
318
319 alg = crypto_lookup_skcipher(alg_name, type, mask);
320 if (IS_ERR(alg)) {
321 err = PTR_ERR(alg);
322 goto err;
323 }
324
325 tfm = __crypto_alloc_tfm(alg, type, mask);
326 if (!IS_ERR(tfm))
327 return __crypto_ablkcipher_cast(tfm);
328
329 crypto_mod_put(alg);
330 err = PTR_ERR(tfm);
331
332err:
333 if (err != -EAGAIN)
334 break;
335 if (signal_pending(current)) {
336 err = -EINTR;
337 break;
338 }
339 }
340
341 return ERR_PTR(err);
342}
343EXPORT_SYMBOL_GPL(crypto_alloc_ablkcipher);
344
108MODULE_LICENSE("GPL"); 345MODULE_LICENSE("GPL");
109MODULE_DESCRIPTION("Asynchronous block chaining cipher type"); 346MODULE_DESCRIPTION("Asynchronous block chaining cipher type");
diff --git a/crypto/aead.c b/crypto/aead.c
index 84a3501fb478..3a6f3f52c7c7 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -12,14 +12,17 @@
12 * 12 *
13 */ 13 */
14 14
15#include <crypto/algapi.h> 15#include <crypto/internal/aead.h>
16#include <linux/errno.h> 16#include <linux/err.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/rtnetlink.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/seq_file.h> 22#include <linux/seq_file.h>
22 23
24#include "internal.h"
25
23static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key, 26static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
24 unsigned int keylen) 27 unsigned int keylen)
25{ 28{
@@ -53,25 +56,54 @@ static int setkey(struct crypto_aead *tfm, const u8 *key, unsigned int keylen)
53 return aead->setkey(tfm, key, keylen); 56 return aead->setkey(tfm, key, keylen);
54} 57}
55 58
59int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
60{
61 struct aead_tfm *crt = crypto_aead_crt(tfm);
62 int err;
63
64 if (authsize > crypto_aead_alg(tfm)->maxauthsize)
65 return -EINVAL;
66
67 if (crypto_aead_alg(tfm)->setauthsize) {
68 err = crypto_aead_alg(tfm)->setauthsize(crt->base, authsize);
69 if (err)
70 return err;
71 }
72
73 crypto_aead_crt(crt->base)->authsize = authsize;
74 crt->authsize = authsize;
75 return 0;
76}
77EXPORT_SYMBOL_GPL(crypto_aead_setauthsize);
78
56static unsigned int crypto_aead_ctxsize(struct crypto_alg *alg, u32 type, 79static unsigned int crypto_aead_ctxsize(struct crypto_alg *alg, u32 type,
57 u32 mask) 80 u32 mask)
58{ 81{
59 return alg->cra_ctxsize; 82 return alg->cra_ctxsize;
60} 83}
61 84
85static int no_givcrypt(struct aead_givcrypt_request *req)
86{
87 return -ENOSYS;
88}
89
62static int crypto_init_aead_ops(struct crypto_tfm *tfm, u32 type, u32 mask) 90static int crypto_init_aead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
63{ 91{
64 struct aead_alg *alg = &tfm->__crt_alg->cra_aead; 92 struct aead_alg *alg = &tfm->__crt_alg->cra_aead;
65 struct aead_tfm *crt = &tfm->crt_aead; 93 struct aead_tfm *crt = &tfm->crt_aead;
66 94
67 if (max(alg->authsize, alg->ivsize) > PAGE_SIZE / 8) 95 if (max(alg->maxauthsize, alg->ivsize) > PAGE_SIZE / 8)
68 return -EINVAL; 96 return -EINVAL;
69 97
70 crt->setkey = setkey; 98 crt->setkey = tfm->__crt_alg->cra_flags & CRYPTO_ALG_GENIV ?
99 alg->setkey : setkey;
71 crt->encrypt = alg->encrypt; 100 crt->encrypt = alg->encrypt;
72 crt->decrypt = alg->decrypt; 101 crt->decrypt = alg->decrypt;
102 crt->givencrypt = alg->givencrypt ?: no_givcrypt;
103 crt->givdecrypt = alg->givdecrypt ?: no_givcrypt;
104 crt->base = __crypto_aead_cast(tfm);
73 crt->ivsize = alg->ivsize; 105 crt->ivsize = alg->ivsize;
74 crt->authsize = alg->authsize; 106 crt->authsize = alg->maxauthsize;
75 107
76 return 0; 108 return 0;
77} 109}
@@ -83,9 +115,12 @@ static void crypto_aead_show(struct seq_file *m, struct crypto_alg *alg)
83 struct aead_alg *aead = &alg->cra_aead; 115 struct aead_alg *aead = &alg->cra_aead;
84 116
85 seq_printf(m, "type : aead\n"); 117 seq_printf(m, "type : aead\n");
118 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
119 "yes" : "no");
86 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); 120 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
87 seq_printf(m, "ivsize : %u\n", aead->ivsize); 121 seq_printf(m, "ivsize : %u\n", aead->ivsize);
88 seq_printf(m, "authsize : %u\n", aead->authsize); 122 seq_printf(m, "maxauthsize : %u\n", aead->maxauthsize);
123 seq_printf(m, "geniv : %s\n", aead->geniv ?: "<built-in>");
89} 124}
90 125
91const struct crypto_type crypto_aead_type = { 126const struct crypto_type crypto_aead_type = {
@@ -97,5 +132,358 @@ const struct crypto_type crypto_aead_type = {
97}; 132};
98EXPORT_SYMBOL_GPL(crypto_aead_type); 133EXPORT_SYMBOL_GPL(crypto_aead_type);
99 134
135static int aead_null_givencrypt(struct aead_givcrypt_request *req)
136{
137 return crypto_aead_encrypt(&req->areq);
138}
139
140static int aead_null_givdecrypt(struct aead_givcrypt_request *req)
141{
142 return crypto_aead_decrypt(&req->areq);
143}
144
145static int crypto_init_nivaead_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
146{
147 struct aead_alg *alg = &tfm->__crt_alg->cra_aead;
148 struct aead_tfm *crt = &tfm->crt_aead;
149
150 if (max(alg->maxauthsize, alg->ivsize) > PAGE_SIZE / 8)
151 return -EINVAL;
152
153 crt->setkey = setkey;
154 crt->encrypt = alg->encrypt;
155 crt->decrypt = alg->decrypt;
156 if (!alg->ivsize) {
157 crt->givencrypt = aead_null_givencrypt;
158 crt->givdecrypt = aead_null_givdecrypt;
159 }
160 crt->base = __crypto_aead_cast(tfm);
161 crt->ivsize = alg->ivsize;
162 crt->authsize = alg->maxauthsize;
163
164 return 0;
165}
166
167static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
168 __attribute__ ((unused));
169static void crypto_nivaead_show(struct seq_file *m, struct crypto_alg *alg)
170{
171 struct aead_alg *aead = &alg->cra_aead;
172
173 seq_printf(m, "type : nivaead\n");
174 seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
175 "yes" : "no");
176 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
177 seq_printf(m, "ivsize : %u\n", aead->ivsize);
178 seq_printf(m, "maxauthsize : %u\n", aead->maxauthsize);
179 seq_printf(m, "geniv : %s\n", aead->geniv);
180}
181
182const struct crypto_type crypto_nivaead_type = {
183 .ctxsize = crypto_aead_ctxsize,
184 .init = crypto_init_nivaead_ops,
185#ifdef CONFIG_PROC_FS
186 .show = crypto_nivaead_show,
187#endif
188};
189EXPORT_SYMBOL_GPL(crypto_nivaead_type);
190
191static int crypto_grab_nivaead(struct crypto_aead_spawn *spawn,
192 const char *name, u32 type, u32 mask)
193{
194 struct crypto_alg *alg;
195 int err;
196
197 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
198 type |= CRYPTO_ALG_TYPE_AEAD;
199 mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV;
200
201 alg = crypto_alg_mod_lookup(name, type, mask);
202 if (IS_ERR(alg))
203 return PTR_ERR(alg);
204
205 err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
206 crypto_mod_put(alg);
207 return err;
208}
209
210struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
211 struct rtattr **tb, u32 type,
212 u32 mask)
213{
214 const char *name;
215 struct crypto_aead_spawn *spawn;
216 struct crypto_attr_type *algt;
217 struct crypto_instance *inst;
218 struct crypto_alg *alg;
219 int err;
220
221 algt = crypto_get_attr_type(tb);
222 err = PTR_ERR(algt);
223 if (IS_ERR(algt))
224 return ERR_PTR(err);
225
226 if ((algt->type ^ (CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_GENIV)) &
227 algt->mask)
228 return ERR_PTR(-EINVAL);
229
230 name = crypto_attr_alg_name(tb[1]);
231 err = PTR_ERR(name);
232 if (IS_ERR(name))
233 return ERR_PTR(err);
234
235 inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
236 if (!inst)
237 return ERR_PTR(-ENOMEM);
238
239 spawn = crypto_instance_ctx(inst);
240
241 /* Ignore async algorithms if necessary. */
242 mask |= crypto_requires_sync(algt->type, algt->mask);
243
244 crypto_set_aead_spawn(spawn, inst);
245 err = crypto_grab_nivaead(spawn, name, type, mask);
246 if (err)
247 goto err_free_inst;
248
249 alg = crypto_aead_spawn_alg(spawn);
250
251 err = -EINVAL;
252 if (!alg->cra_aead.ivsize)
253 goto err_drop_alg;
254
255 /*
256 * This is only true if we're constructing an algorithm with its
257 * default IV generator. For the default generator we elide the
258 * template name and double-check the IV generator.
259 */
260 if (algt->mask & CRYPTO_ALG_GENIV) {
261 if (strcmp(tmpl->name, alg->cra_aead.geniv))
262 goto err_drop_alg;
263
264 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
265 memcpy(inst->alg.cra_driver_name, alg->cra_driver_name,
266 CRYPTO_MAX_ALG_NAME);
267 } else {
268 err = -ENAMETOOLONG;
269 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
270 "%s(%s)", tmpl->name, alg->cra_name) >=
271 CRYPTO_MAX_ALG_NAME)
272 goto err_drop_alg;
273 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
274 "%s(%s)", tmpl->name, alg->cra_driver_name) >=
275 CRYPTO_MAX_ALG_NAME)
276 goto err_drop_alg;
277 }
278
279 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_GENIV;
280 inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
281 inst->alg.cra_priority = alg->cra_priority;
282 inst->alg.cra_blocksize = alg->cra_blocksize;
283 inst->alg.cra_alignmask = alg->cra_alignmask;
284 inst->alg.cra_type = &crypto_aead_type;
285
286 inst->alg.cra_aead.ivsize = alg->cra_aead.ivsize;
287 inst->alg.cra_aead.maxauthsize = alg->cra_aead.maxauthsize;
288 inst->alg.cra_aead.geniv = alg->cra_aead.geniv;
289
290 inst->alg.cra_aead.setkey = alg->cra_aead.setkey;
291 inst->alg.cra_aead.setauthsize = alg->cra_aead.setauthsize;
292 inst->alg.cra_aead.encrypt = alg->cra_aead.encrypt;
293 inst->alg.cra_aead.decrypt = alg->cra_aead.decrypt;
294
295out:
296 return inst;
297
298err_drop_alg:
299 crypto_drop_aead(spawn);
300err_free_inst:
301 kfree(inst);
302 inst = ERR_PTR(err);
303 goto out;
304}
305EXPORT_SYMBOL_GPL(aead_geniv_alloc);
306
307void aead_geniv_free(struct crypto_instance *inst)
308{
309 crypto_drop_aead(crypto_instance_ctx(inst));
310 kfree(inst);
311}
312EXPORT_SYMBOL_GPL(aead_geniv_free);
313
314int aead_geniv_init(struct crypto_tfm *tfm)
315{
316 struct crypto_instance *inst = (void *)tfm->__crt_alg;
317 struct crypto_aead *aead;
318
319 aead = crypto_spawn_aead(crypto_instance_ctx(inst));
320 if (IS_ERR(aead))
321 return PTR_ERR(aead);
322
323 tfm->crt_aead.base = aead;
324 tfm->crt_aead.reqsize += crypto_aead_reqsize(aead);
325
326 return 0;
327}
328EXPORT_SYMBOL_GPL(aead_geniv_init);
329
330void aead_geniv_exit(struct crypto_tfm *tfm)
331{
332 crypto_free_aead(tfm->crt_aead.base);
333}
334EXPORT_SYMBOL_GPL(aead_geniv_exit);
335
336static int crypto_nivaead_default(struct crypto_alg *alg, u32 type, u32 mask)
337{
338 struct rtattr *tb[3];
339 struct {
340 struct rtattr attr;
341 struct crypto_attr_type data;
342 } ptype;
343 struct {
344 struct rtattr attr;
345 struct crypto_attr_alg data;
346 } palg;
347 struct crypto_template *tmpl;
348 struct crypto_instance *inst;
349 struct crypto_alg *larval;
350 const char *geniv;
351 int err;
352
353 larval = crypto_larval_lookup(alg->cra_driver_name,
354 CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_GENIV,
355 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
356 err = PTR_ERR(larval);
357 if (IS_ERR(larval))
358 goto out;
359
360 err = -EAGAIN;
361 if (!crypto_is_larval(larval))
362 goto drop_larval;
363
364 ptype.attr.rta_len = sizeof(ptype);
365 ptype.attr.rta_type = CRYPTOA_TYPE;
366 ptype.data.type = type | CRYPTO_ALG_GENIV;
367 /* GENIV tells the template that we're making a default geniv. */
368 ptype.data.mask = mask | CRYPTO_ALG_GENIV;
369 tb[0] = &ptype.attr;
370
371 palg.attr.rta_len = sizeof(palg);
372 palg.attr.rta_type = CRYPTOA_ALG;
373 /* Must use the exact name to locate ourselves. */
374 memcpy(palg.data.name, alg->cra_driver_name, CRYPTO_MAX_ALG_NAME);
375 tb[1] = &palg.attr;
376
377 tb[2] = NULL;
378
379 geniv = alg->cra_aead.geniv;
380
381 tmpl = crypto_lookup_template(geniv);
382 err = -ENOENT;
383 if (!tmpl)
384 goto kill_larval;
385
386 inst = tmpl->alloc(tb);
387 err = PTR_ERR(inst);
388 if (IS_ERR(inst))
389 goto put_tmpl;
390
391 if ((err = crypto_register_instance(tmpl, inst))) {
392 tmpl->free(inst);
393 goto put_tmpl;
394 }
395
396 /* Redo the lookup to use the instance we just registered. */
397 err = -EAGAIN;
398
399put_tmpl:
400 crypto_tmpl_put(tmpl);
401kill_larval:
402 crypto_larval_kill(larval);
403drop_larval:
404 crypto_mod_put(larval);
405out:
406 crypto_mod_put(alg);
407 return err;
408}
409
410static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type,
411 u32 mask)
412{
413 struct crypto_alg *alg;
414
415 alg = crypto_alg_mod_lookup(name, type, mask);
416 if (IS_ERR(alg))
417 return alg;
418
419 if (alg->cra_type == &crypto_aead_type)
420 return alg;
421
422 if (!alg->cra_aead.ivsize)
423 return alg;
424
425 return ERR_PTR(crypto_nivaead_default(alg, type, mask));
426}
427
428int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
429 u32 type, u32 mask)
430{
431 struct crypto_alg *alg;
432 int err;
433
434 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
435 type |= CRYPTO_ALG_TYPE_AEAD;
436 mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
437 mask |= CRYPTO_ALG_TYPE_MASK;
438
439 alg = crypto_lookup_aead(name, type, mask);
440 if (IS_ERR(alg))
441 return PTR_ERR(alg);
442
443 err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
444 crypto_mod_put(alg);
445 return err;
446}
447EXPORT_SYMBOL_GPL(crypto_grab_aead);
448
449struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask)
450{
451 struct crypto_tfm *tfm;
452 int err;
453
454 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
455 type |= CRYPTO_ALG_TYPE_AEAD;
456 mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
457 mask |= CRYPTO_ALG_TYPE_MASK;
458
459 for (;;) {
460 struct crypto_alg *alg;
461
462 alg = crypto_lookup_aead(alg_name, type, mask);
463 if (IS_ERR(alg)) {
464 err = PTR_ERR(alg);
465 goto err;
466 }
467
468 tfm = __crypto_alloc_tfm(alg, type, mask);
469 if (!IS_ERR(tfm))
470 return __crypto_aead_cast(tfm);
471
472 crypto_mod_put(alg);
473 err = PTR_ERR(tfm);
474
475err:
476 if (err != -EAGAIN)
477 break;
478 if (signal_pending(current)) {
479 err = -EINTR;
480 break;
481 }
482 }
483
484 return ERR_PTR(err);
485}
486EXPORT_SYMBOL_GPL(crypto_alloc_aead);
487
100MODULE_LICENSE("GPL"); 488MODULE_LICENSE("GPL");
101MODULE_DESCRIPTION("Authenticated Encryption with Associated Data (AEAD)"); 489MODULE_DESCRIPTION("Authenticated Encryption with Associated Data (AEAD)");
diff --git a/crypto/aes_generic.c b/crypto/aes_generic.c
index 9401dca85e87..cf30af74480f 100644
--- a/crypto/aes_generic.c
+++ b/crypto/aes_generic.c
@@ -47,11 +47,7 @@
47 * --------------------------------------------------------------------------- 47 * ---------------------------------------------------------------------------
48 */ 48 */
49 49
50/* Some changes from the Gladman version: 50#include <crypto/aes.h>
51 s/RIJNDAEL(e_key)/E_KEY/g
52 s/RIJNDAEL(d_key)/D_KEY/g
53*/
54
55#include <linux/module.h> 51#include <linux/module.h>
56#include <linux/init.h> 52#include <linux/init.h>
57#include <linux/types.h> 53#include <linux/types.h>
@@ -59,88 +55,46 @@
59#include <linux/crypto.h> 55#include <linux/crypto.h>
60#include <asm/byteorder.h> 56#include <asm/byteorder.h>
61 57
62#define AES_MIN_KEY_SIZE 16 58static inline u8 byte(const u32 x, const unsigned n)
63#define AES_MAX_KEY_SIZE 32
64
65#define AES_BLOCK_SIZE 16
66
67/*
68 * #define byte(x, nr) ((unsigned char)((x) >> (nr*8)))
69 */
70static inline u8
71byte(const u32 x, const unsigned n)
72{ 59{
73 return x >> (n << 3); 60 return x >> (n << 3);
74} 61}
75 62
76struct aes_ctx {
77 int key_length;
78 u32 buf[120];
79};
80
81#define E_KEY (&ctx->buf[0])
82#define D_KEY (&ctx->buf[60])
83
84static u8 pow_tab[256] __initdata; 63static u8 pow_tab[256] __initdata;
85static u8 log_tab[256] __initdata; 64static u8 log_tab[256] __initdata;
86static u8 sbx_tab[256] __initdata; 65static u8 sbx_tab[256] __initdata;
87static u8 isb_tab[256] __initdata; 66static u8 isb_tab[256] __initdata;
88static u32 rco_tab[10]; 67static u32 rco_tab[10];
89static u32 ft_tab[4][256];
90static u32 it_tab[4][256];
91 68
92static u32 fl_tab[4][256]; 69u32 crypto_ft_tab[4][256];
93static u32 il_tab[4][256]; 70u32 crypto_fl_tab[4][256];
71u32 crypto_it_tab[4][256];
72u32 crypto_il_tab[4][256];
94 73
95static inline u8 __init 74EXPORT_SYMBOL_GPL(crypto_ft_tab);
96f_mult (u8 a, u8 b) 75EXPORT_SYMBOL_GPL(crypto_fl_tab);
76EXPORT_SYMBOL_GPL(crypto_it_tab);
77EXPORT_SYMBOL_GPL(crypto_il_tab);
78
79static inline u8 __init f_mult(u8 a, u8 b)
97{ 80{
98 u8 aa = log_tab[a], cc = aa + log_tab[b]; 81 u8 aa = log_tab[a], cc = aa + log_tab[b];
99 82
100 return pow_tab[cc + (cc < aa ? 1 : 0)]; 83 return pow_tab[cc + (cc < aa ? 1 : 0)];
101} 84}
102 85
103#define ff_mult(a,b) (a && b ? f_mult(a, b) : 0) 86#define ff_mult(a, b) (a && b ? f_mult(a, b) : 0)
104 87
105#define f_rn(bo, bi, n, k) \ 88static void __init gen_tabs(void)
106 bo[n] = ft_tab[0][byte(bi[n],0)] ^ \
107 ft_tab[1][byte(bi[(n + 1) & 3],1)] ^ \
108 ft_tab[2][byte(bi[(n + 2) & 3],2)] ^ \
109 ft_tab[3][byte(bi[(n + 3) & 3],3)] ^ *(k + n)
110
111#define i_rn(bo, bi, n, k) \
112 bo[n] = it_tab[0][byte(bi[n],0)] ^ \
113 it_tab[1][byte(bi[(n + 3) & 3],1)] ^ \
114 it_tab[2][byte(bi[(n + 2) & 3],2)] ^ \
115 it_tab[3][byte(bi[(n + 1) & 3],3)] ^ *(k + n)
116
117#define ls_box(x) \
118 ( fl_tab[0][byte(x, 0)] ^ \
119 fl_tab[1][byte(x, 1)] ^ \
120 fl_tab[2][byte(x, 2)] ^ \
121 fl_tab[3][byte(x, 3)] )
122
123#define f_rl(bo, bi, n, k) \
124 bo[n] = fl_tab[0][byte(bi[n],0)] ^ \
125 fl_tab[1][byte(bi[(n + 1) & 3],1)] ^ \
126 fl_tab[2][byte(bi[(n + 2) & 3],2)] ^ \
127 fl_tab[3][byte(bi[(n + 3) & 3],3)] ^ *(k + n)
128
129#define i_rl(bo, bi, n, k) \
130 bo[n] = il_tab[0][byte(bi[n],0)] ^ \
131 il_tab[1][byte(bi[(n + 3) & 3],1)] ^ \
132 il_tab[2][byte(bi[(n + 2) & 3],2)] ^ \
133 il_tab[3][byte(bi[(n + 1) & 3],3)] ^ *(k + n)
134
135static void __init
136gen_tabs (void)
137{ 89{
138 u32 i, t; 90 u32 i, t;
139 u8 p, q; 91 u8 p, q;
140 92
141 /* log and power tables for GF(2**8) finite field with 93 /*
142 0x011b as modular polynomial - the simplest primitive 94 * log and power tables for GF(2**8) finite field with
143 root is 0x03, used here to generate the tables */ 95 * 0x011b as modular polynomial - the simplest primitive
96 * root is 0x03, used here to generate the tables
97 */
144 98
145 for (i = 0, p = 1; i < 256; ++i) { 99 for (i = 0, p = 1; i < 256; ++i) {
146 pow_tab[i] = (u8) p; 100 pow_tab[i] = (u8) p;
@@ -169,92 +123,119 @@ gen_tabs (void)
169 p = sbx_tab[i]; 123 p = sbx_tab[i];
170 124
171 t = p; 125 t = p;
172 fl_tab[0][i] = t; 126 crypto_fl_tab[0][i] = t;
173 fl_tab[1][i] = rol32(t, 8); 127 crypto_fl_tab[1][i] = rol32(t, 8);
174 fl_tab[2][i] = rol32(t, 16); 128 crypto_fl_tab[2][i] = rol32(t, 16);
175 fl_tab[3][i] = rol32(t, 24); 129 crypto_fl_tab[3][i] = rol32(t, 24);
176 130
177 t = ((u32) ff_mult (2, p)) | 131 t = ((u32) ff_mult(2, p)) |
178 ((u32) p << 8) | 132 ((u32) p << 8) |
179 ((u32) p << 16) | ((u32) ff_mult (3, p) << 24); 133 ((u32) p << 16) | ((u32) ff_mult(3, p) << 24);
180 134
181 ft_tab[0][i] = t; 135 crypto_ft_tab[0][i] = t;
182 ft_tab[1][i] = rol32(t, 8); 136 crypto_ft_tab[1][i] = rol32(t, 8);
183 ft_tab[2][i] = rol32(t, 16); 137 crypto_ft_tab[2][i] = rol32(t, 16);
184 ft_tab[3][i] = rol32(t, 24); 138 crypto_ft_tab[3][i] = rol32(t, 24);
185 139
186 p = isb_tab[i]; 140 p = isb_tab[i];
187 141
188 t = p; 142 t = p;
189 il_tab[0][i] = t; 143 crypto_il_tab[0][i] = t;
190 il_tab[1][i] = rol32(t, 8); 144 crypto_il_tab[1][i] = rol32(t, 8);
191 il_tab[2][i] = rol32(t, 16); 145 crypto_il_tab[2][i] = rol32(t, 16);
192 il_tab[3][i] = rol32(t, 24); 146 crypto_il_tab[3][i] = rol32(t, 24);
193 147
194 t = ((u32) ff_mult (14, p)) | 148 t = ((u32) ff_mult(14, p)) |
195 ((u32) ff_mult (9, p) << 8) | 149 ((u32) ff_mult(9, p) << 8) |
196 ((u32) ff_mult (13, p) << 16) | 150 ((u32) ff_mult(13, p) << 16) |
197 ((u32) ff_mult (11, p) << 24); 151 ((u32) ff_mult(11, p) << 24);
198 152
199 it_tab[0][i] = t; 153 crypto_it_tab[0][i] = t;
200 it_tab[1][i] = rol32(t, 8); 154 crypto_it_tab[1][i] = rol32(t, 8);
201 it_tab[2][i] = rol32(t, 16); 155 crypto_it_tab[2][i] = rol32(t, 16);
202 it_tab[3][i] = rol32(t, 24); 156 crypto_it_tab[3][i] = rol32(t, 24);
203 } 157 }
204} 158}
205 159
206#define star_x(x) (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
207
208#define imix_col(y,x) \
209 u = star_x(x); \
210 v = star_x(u); \
211 w = star_x(v); \
212 t = w ^ (x); \
213 (y) = u ^ v ^ w; \
214 (y) ^= ror32(u ^ t, 8) ^ \
215 ror32(v ^ t, 16) ^ \
216 ror32(t,24)
217
218/* initialise the key schedule from the user supplied key */ 160/* initialise the key schedule from the user supplied key */
219 161
220#define loop4(i) \ 162#define star_x(x) (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
221{ t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
222 t ^= E_KEY[4 * i]; E_KEY[4 * i + 4] = t; \
223 t ^= E_KEY[4 * i + 1]; E_KEY[4 * i + 5] = t; \
224 t ^= E_KEY[4 * i + 2]; E_KEY[4 * i + 6] = t; \
225 t ^= E_KEY[4 * i + 3]; E_KEY[4 * i + 7] = t; \
226}
227
228#define loop6(i) \
229{ t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
230 t ^= E_KEY[6 * i]; E_KEY[6 * i + 6] = t; \
231 t ^= E_KEY[6 * i + 1]; E_KEY[6 * i + 7] = t; \
232 t ^= E_KEY[6 * i + 2]; E_KEY[6 * i + 8] = t; \
233 t ^= E_KEY[6 * i + 3]; E_KEY[6 * i + 9] = t; \
234 t ^= E_KEY[6 * i + 4]; E_KEY[6 * i + 10] = t; \
235 t ^= E_KEY[6 * i + 5]; E_KEY[6 * i + 11] = t; \
236}
237
238#define loop8(i) \
239{ t = ror32(t, 8); ; t = ls_box(t) ^ rco_tab[i]; \
240 t ^= E_KEY[8 * i]; E_KEY[8 * i + 8] = t; \
241 t ^= E_KEY[8 * i + 1]; E_KEY[8 * i + 9] = t; \
242 t ^= E_KEY[8 * i + 2]; E_KEY[8 * i + 10] = t; \
243 t ^= E_KEY[8 * i + 3]; E_KEY[8 * i + 11] = t; \
244 t = E_KEY[8 * i + 4] ^ ls_box(t); \
245 E_KEY[8 * i + 12] = t; \
246 t ^= E_KEY[8 * i + 5]; E_KEY[8 * i + 13] = t; \
247 t ^= E_KEY[8 * i + 6]; E_KEY[8 * i + 14] = t; \
248 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
249}
250 163
251static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 164#define imix_col(y,x) do { \
252 unsigned int key_len) 165 u = star_x(x); \
166 v = star_x(u); \
167 w = star_x(v); \
168 t = w ^ (x); \
169 (y) = u ^ v ^ w; \
170 (y) ^= ror32(u ^ t, 8) ^ \
171 ror32(v ^ t, 16) ^ \
172 ror32(t, 24); \
173} while (0)
174
175#define ls_box(x) \
176 crypto_fl_tab[0][byte(x, 0)] ^ \
177 crypto_fl_tab[1][byte(x, 1)] ^ \
178 crypto_fl_tab[2][byte(x, 2)] ^ \
179 crypto_fl_tab[3][byte(x, 3)]
180
181#define loop4(i) do { \
182 t = ror32(t, 8); \
183 t = ls_box(t) ^ rco_tab[i]; \
184 t ^= ctx->key_enc[4 * i]; \
185 ctx->key_enc[4 * i + 4] = t; \
186 t ^= ctx->key_enc[4 * i + 1]; \
187 ctx->key_enc[4 * i + 5] = t; \
188 t ^= ctx->key_enc[4 * i + 2]; \
189 ctx->key_enc[4 * i + 6] = t; \
190 t ^= ctx->key_enc[4 * i + 3]; \
191 ctx->key_enc[4 * i + 7] = t; \
192} while (0)
193
194#define loop6(i) do { \
195 t = ror32(t, 8); \
196 t = ls_box(t) ^ rco_tab[i]; \
197 t ^= ctx->key_enc[6 * i]; \
198 ctx->key_enc[6 * i + 6] = t; \
199 t ^= ctx->key_enc[6 * i + 1]; \
200 ctx->key_enc[6 * i + 7] = t; \
201 t ^= ctx->key_enc[6 * i + 2]; \
202 ctx->key_enc[6 * i + 8] = t; \
203 t ^= ctx->key_enc[6 * i + 3]; \
204 ctx->key_enc[6 * i + 9] = t; \
205 t ^= ctx->key_enc[6 * i + 4]; \
206 ctx->key_enc[6 * i + 10] = t; \
207 t ^= ctx->key_enc[6 * i + 5]; \
208 ctx->key_enc[6 * i + 11] = t; \
209} while (0)
210
211#define loop8(i) do { \
212 t = ror32(t, 8); \
213 t = ls_box(t) ^ rco_tab[i]; \
214 t ^= ctx->key_enc[8 * i]; \
215 ctx->key_enc[8 * i + 8] = t; \
216 t ^= ctx->key_enc[8 * i + 1]; \
217 ctx->key_enc[8 * i + 9] = t; \
218 t ^= ctx->key_enc[8 * i + 2]; \
219 ctx->key_enc[8 * i + 10] = t; \
220 t ^= ctx->key_enc[8 * i + 3]; \
221 ctx->key_enc[8 * i + 11] = t; \
222 t = ctx->key_enc[8 * i + 4] ^ ls_box(t); \
223 ctx->key_enc[8 * i + 12] = t; \
224 t ^= ctx->key_enc[8 * i + 5]; \
225 ctx->key_enc[8 * i + 13] = t; \
226 t ^= ctx->key_enc[8 * i + 6]; \
227 ctx->key_enc[8 * i + 14] = t; \
228 t ^= ctx->key_enc[8 * i + 7]; \
229 ctx->key_enc[8 * i + 15] = t; \
230} while (0)
231
232int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
233 unsigned int key_len)
253{ 234{
254 struct aes_ctx *ctx = crypto_tfm_ctx(tfm); 235 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
255 const __le32 *key = (const __le32 *)in_key; 236 const __le32 *key = (const __le32 *)in_key;
256 u32 *flags = &tfm->crt_flags; 237 u32 *flags = &tfm->crt_flags;
257 u32 i, t, u, v, w; 238 u32 i, t, u, v, w, j;
258 239
259 if (key_len % 8) { 240 if (key_len % 8) {
260 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 241 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
@@ -263,95 +244,113 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
263 244
264 ctx->key_length = key_len; 245 ctx->key_length = key_len;
265 246
266 E_KEY[0] = le32_to_cpu(key[0]); 247 ctx->key_dec[key_len + 24] = ctx->key_enc[0] = le32_to_cpu(key[0]);
267 E_KEY[1] = le32_to_cpu(key[1]); 248 ctx->key_dec[key_len + 25] = ctx->key_enc[1] = le32_to_cpu(key[1]);
268 E_KEY[2] = le32_to_cpu(key[2]); 249 ctx->key_dec[key_len + 26] = ctx->key_enc[2] = le32_to_cpu(key[2]);
269 E_KEY[3] = le32_to_cpu(key[3]); 250 ctx->key_dec[key_len + 27] = ctx->key_enc[3] = le32_to_cpu(key[3]);
270 251
271 switch (key_len) { 252 switch (key_len) {
272 case 16: 253 case 16:
273 t = E_KEY[3]; 254 t = ctx->key_enc[3];
274 for (i = 0; i < 10; ++i) 255 for (i = 0; i < 10; ++i)
275 loop4 (i); 256 loop4(i);
276 break; 257 break;
277 258
278 case 24: 259 case 24:
279 E_KEY[4] = le32_to_cpu(key[4]); 260 ctx->key_enc[4] = le32_to_cpu(key[4]);
280 t = E_KEY[5] = le32_to_cpu(key[5]); 261 t = ctx->key_enc[5] = le32_to_cpu(key[5]);
281 for (i = 0; i < 8; ++i) 262 for (i = 0; i < 8; ++i)
282 loop6 (i); 263 loop6(i);
283 break; 264 break;
284 265
285 case 32: 266 case 32:
286 E_KEY[4] = le32_to_cpu(key[4]); 267 ctx->key_enc[4] = le32_to_cpu(key[4]);
287 E_KEY[5] = le32_to_cpu(key[5]); 268 ctx->key_enc[5] = le32_to_cpu(key[5]);
288 E_KEY[6] = le32_to_cpu(key[6]); 269 ctx->key_enc[6] = le32_to_cpu(key[6]);
289 t = E_KEY[7] = le32_to_cpu(key[7]); 270 t = ctx->key_enc[7] = le32_to_cpu(key[7]);
290 for (i = 0; i < 7; ++i) 271 for (i = 0; i < 7; ++i)
291 loop8 (i); 272 loop8(i);
292 break; 273 break;
293 } 274 }
294 275
295 D_KEY[0] = E_KEY[0]; 276 ctx->key_dec[0] = ctx->key_enc[key_len + 24];
296 D_KEY[1] = E_KEY[1]; 277 ctx->key_dec[1] = ctx->key_enc[key_len + 25];
297 D_KEY[2] = E_KEY[2]; 278 ctx->key_dec[2] = ctx->key_enc[key_len + 26];
298 D_KEY[3] = E_KEY[3]; 279 ctx->key_dec[3] = ctx->key_enc[key_len + 27];
299 280
300 for (i = 4; i < key_len + 24; ++i) { 281 for (i = 4; i < key_len + 24; ++i) {
301 imix_col (D_KEY[i], E_KEY[i]); 282 j = key_len + 24 - (i & ~3) + (i & 3);
283 imix_col(ctx->key_dec[j], ctx->key_enc[i]);
302 } 284 }
303
304 return 0; 285 return 0;
305} 286}
287EXPORT_SYMBOL_GPL(crypto_aes_set_key);
306 288
307/* encrypt a block of text */ 289/* encrypt a block of text */
308 290
309#define f_nround(bo, bi, k) \ 291#define f_rn(bo, bi, n, k) do { \
310 f_rn(bo, bi, 0, k); \ 292 bo[n] = crypto_ft_tab[0][byte(bi[n], 0)] ^ \
311 f_rn(bo, bi, 1, k); \ 293 crypto_ft_tab[1][byte(bi[(n + 1) & 3], 1)] ^ \
312 f_rn(bo, bi, 2, k); \ 294 crypto_ft_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
313 f_rn(bo, bi, 3, k); \ 295 crypto_ft_tab[3][byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \
314 k += 4 296} while (0)
315 297
316#define f_lround(bo, bi, k) \ 298#define f_nround(bo, bi, k) do {\
317 f_rl(bo, bi, 0, k); \ 299 f_rn(bo, bi, 0, k); \
318 f_rl(bo, bi, 1, k); \ 300 f_rn(bo, bi, 1, k); \
319 f_rl(bo, bi, 2, k); \ 301 f_rn(bo, bi, 2, k); \
320 f_rl(bo, bi, 3, k) 302 f_rn(bo, bi, 3, k); \
303 k += 4; \
304} while (0)
305
306#define f_rl(bo, bi, n, k) do { \
307 bo[n] = crypto_fl_tab[0][byte(bi[n], 0)] ^ \
308 crypto_fl_tab[1][byte(bi[(n + 1) & 3], 1)] ^ \
309 crypto_fl_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
310 crypto_fl_tab[3][byte(bi[(n + 3) & 3], 3)] ^ *(k + n); \
311} while (0)
312
313#define f_lround(bo, bi, k) do {\
314 f_rl(bo, bi, 0, k); \
315 f_rl(bo, bi, 1, k); \
316 f_rl(bo, bi, 2, k); \
317 f_rl(bo, bi, 3, k); \
318} while (0)
321 319
322static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 320static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
323{ 321{
324 const struct aes_ctx *ctx = crypto_tfm_ctx(tfm); 322 const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
325 const __le32 *src = (const __le32 *)in; 323 const __le32 *src = (const __le32 *)in;
326 __le32 *dst = (__le32 *)out; 324 __le32 *dst = (__le32 *)out;
327 u32 b0[4], b1[4]; 325 u32 b0[4], b1[4];
328 const u32 *kp = E_KEY + 4; 326 const u32 *kp = ctx->key_enc + 4;
327 const int key_len = ctx->key_length;
329 328
330 b0[0] = le32_to_cpu(src[0]) ^ E_KEY[0]; 329 b0[0] = le32_to_cpu(src[0]) ^ ctx->key_enc[0];
331 b0[1] = le32_to_cpu(src[1]) ^ E_KEY[1]; 330 b0[1] = le32_to_cpu(src[1]) ^ ctx->key_enc[1];
332 b0[2] = le32_to_cpu(src[2]) ^ E_KEY[2]; 331 b0[2] = le32_to_cpu(src[2]) ^ ctx->key_enc[2];
333 b0[3] = le32_to_cpu(src[3]) ^ E_KEY[3]; 332 b0[3] = le32_to_cpu(src[3]) ^ ctx->key_enc[3];
334 333
335 if (ctx->key_length > 24) { 334 if (key_len > 24) {
336 f_nround (b1, b0, kp); 335 f_nround(b1, b0, kp);
337 f_nround (b0, b1, kp); 336 f_nround(b0, b1, kp);
338 } 337 }
339 338
340 if (ctx->key_length > 16) { 339 if (key_len > 16) {
341 f_nround (b1, b0, kp); 340 f_nround(b1, b0, kp);
342 f_nround (b0, b1, kp); 341 f_nround(b0, b1, kp);
343 } 342 }
344 343
345 f_nround (b1, b0, kp); 344 f_nround(b1, b0, kp);
346 f_nround (b0, b1, kp); 345 f_nround(b0, b1, kp);
347 f_nround (b1, b0, kp); 346 f_nround(b1, b0, kp);
348 f_nround (b0, b1, kp); 347 f_nround(b0, b1, kp);
349 f_nround (b1, b0, kp); 348 f_nround(b1, b0, kp);
350 f_nround (b0, b1, kp); 349 f_nround(b0, b1, kp);
351 f_nround (b1, b0, kp); 350 f_nround(b1, b0, kp);
352 f_nround (b0, b1, kp); 351 f_nround(b0, b1, kp);
353 f_nround (b1, b0, kp); 352 f_nround(b1, b0, kp);
354 f_lround (b0, b1, kp); 353 f_lround(b0, b1, kp);
355 354
356 dst[0] = cpu_to_le32(b0[0]); 355 dst[0] = cpu_to_le32(b0[0]);
357 dst[1] = cpu_to_le32(b0[1]); 356 dst[1] = cpu_to_le32(b0[1]);
@@ -361,53 +360,69 @@ static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
361 360
362/* decrypt a block of text */ 361/* decrypt a block of text */
363 362
364#define i_nround(bo, bi, k) \ 363#define i_rn(bo, bi, n, k) do { \
365 i_rn(bo, bi, 0, k); \ 364 bo[n] = crypto_it_tab[0][byte(bi[n], 0)] ^ \
366 i_rn(bo, bi, 1, k); \ 365 crypto_it_tab[1][byte(bi[(n + 3) & 3], 1)] ^ \
367 i_rn(bo, bi, 2, k); \ 366 crypto_it_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
368 i_rn(bo, bi, 3, k); \ 367 crypto_it_tab[3][byte(bi[(n + 1) & 3], 3)] ^ *(k + n); \
369 k -= 4 368} while (0)
370 369
371#define i_lround(bo, bi, k) \ 370#define i_nround(bo, bi, k) do {\
372 i_rl(bo, bi, 0, k); \ 371 i_rn(bo, bi, 0, k); \
373 i_rl(bo, bi, 1, k); \ 372 i_rn(bo, bi, 1, k); \
374 i_rl(bo, bi, 2, k); \ 373 i_rn(bo, bi, 2, k); \
375 i_rl(bo, bi, 3, k) 374 i_rn(bo, bi, 3, k); \
375 k += 4; \
376} while (0)
377
378#define i_rl(bo, bi, n, k) do { \
379 bo[n] = crypto_il_tab[0][byte(bi[n], 0)] ^ \
380 crypto_il_tab[1][byte(bi[(n + 3) & 3], 1)] ^ \
381 crypto_il_tab[2][byte(bi[(n + 2) & 3], 2)] ^ \
382 crypto_il_tab[3][byte(bi[(n + 1) & 3], 3)] ^ *(k + n); \
383} while (0)
384
385#define i_lround(bo, bi, k) do {\
386 i_rl(bo, bi, 0, k); \
387 i_rl(bo, bi, 1, k); \
388 i_rl(bo, bi, 2, k); \
389 i_rl(bo, bi, 3, k); \
390} while (0)
376 391
377static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 392static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
378{ 393{
379 const struct aes_ctx *ctx = crypto_tfm_ctx(tfm); 394 const struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
380 const __le32 *src = (const __le32 *)in; 395 const __le32 *src = (const __le32 *)in;
381 __le32 *dst = (__le32 *)out; 396 __le32 *dst = (__le32 *)out;
382 u32 b0[4], b1[4]; 397 u32 b0[4], b1[4];
383 const int key_len = ctx->key_length; 398 const int key_len = ctx->key_length;
384 const u32 *kp = D_KEY + key_len + 20; 399 const u32 *kp = ctx->key_dec + 4;
385 400
386 b0[0] = le32_to_cpu(src[0]) ^ E_KEY[key_len + 24]; 401 b0[0] = le32_to_cpu(src[0]) ^ ctx->key_dec[0];
387 b0[1] = le32_to_cpu(src[1]) ^ E_KEY[key_len + 25]; 402 b0[1] = le32_to_cpu(src[1]) ^ ctx->key_dec[1];
388 b0[2] = le32_to_cpu(src[2]) ^ E_KEY[key_len + 26]; 403 b0[2] = le32_to_cpu(src[2]) ^ ctx->key_dec[2];
389 b0[3] = le32_to_cpu(src[3]) ^ E_KEY[key_len + 27]; 404 b0[3] = le32_to_cpu(src[3]) ^ ctx->key_dec[3];
390 405
391 if (key_len > 24) { 406 if (key_len > 24) {
392 i_nround (b1, b0, kp); 407 i_nround(b1, b0, kp);
393 i_nround (b0, b1, kp); 408 i_nround(b0, b1, kp);
394 } 409 }
395 410
396 if (key_len > 16) { 411 if (key_len > 16) {
397 i_nround (b1, b0, kp); 412 i_nround(b1, b0, kp);
398 i_nround (b0, b1, kp); 413 i_nround(b0, b1, kp);
399 } 414 }
400 415
401 i_nround (b1, b0, kp); 416 i_nround(b1, b0, kp);
402 i_nround (b0, b1, kp); 417 i_nround(b0, b1, kp);
403 i_nround (b1, b0, kp); 418 i_nround(b1, b0, kp);
404 i_nround (b0, b1, kp); 419 i_nround(b0, b1, kp);
405 i_nround (b1, b0, kp); 420 i_nround(b1, b0, kp);
406 i_nround (b0, b1, kp); 421 i_nround(b0, b1, kp);
407 i_nround (b1, b0, kp); 422 i_nround(b1, b0, kp);
408 i_nround (b0, b1, kp); 423 i_nround(b0, b1, kp);
409 i_nround (b1, b0, kp); 424 i_nround(b1, b0, kp);
410 i_lround (b0, b1, kp); 425 i_lround(b0, b1, kp);
411 426
412 dst[0] = cpu_to_le32(b0[0]); 427 dst[0] = cpu_to_le32(b0[0]);
413 dst[1] = cpu_to_le32(b0[1]); 428 dst[1] = cpu_to_le32(b0[1]);
@@ -415,14 +430,13 @@ static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
415 dst[3] = cpu_to_le32(b0[3]); 430 dst[3] = cpu_to_le32(b0[3]);
416} 431}
417 432
418
419static struct crypto_alg aes_alg = { 433static struct crypto_alg aes_alg = {
420 .cra_name = "aes", 434 .cra_name = "aes",
421 .cra_driver_name = "aes-generic", 435 .cra_driver_name = "aes-generic",
422 .cra_priority = 100, 436 .cra_priority = 100,
423 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 437 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
424 .cra_blocksize = AES_BLOCK_SIZE, 438 .cra_blocksize = AES_BLOCK_SIZE,
425 .cra_ctxsize = sizeof(struct aes_ctx), 439 .cra_ctxsize = sizeof(struct crypto_aes_ctx),
426 .cra_alignmask = 3, 440 .cra_alignmask = 3,
427 .cra_module = THIS_MODULE, 441 .cra_module = THIS_MODULE,
428 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list), 442 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
@@ -430,9 +444,9 @@ static struct crypto_alg aes_alg = {
430 .cipher = { 444 .cipher = {
431 .cia_min_keysize = AES_MIN_KEY_SIZE, 445 .cia_min_keysize = AES_MIN_KEY_SIZE,
432 .cia_max_keysize = AES_MAX_KEY_SIZE, 446 .cia_max_keysize = AES_MAX_KEY_SIZE,
433 .cia_setkey = aes_set_key, 447 .cia_setkey = crypto_aes_set_key,
434 .cia_encrypt = aes_encrypt, 448 .cia_encrypt = aes_encrypt,
435 .cia_decrypt = aes_decrypt 449 .cia_decrypt = aes_decrypt
436 } 450 }
437 } 451 }
438}; 452};
diff --git a/crypto/algapi.c b/crypto/algapi.c
index 8383282de1dd..e65cb50cf4af 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -472,7 +472,7 @@ int crypto_check_attr_type(struct rtattr **tb, u32 type)
472} 472}
473EXPORT_SYMBOL_GPL(crypto_check_attr_type); 473EXPORT_SYMBOL_GPL(crypto_check_attr_type);
474 474
475struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask) 475const char *crypto_attr_alg_name(struct rtattr *rta)
476{ 476{
477 struct crypto_attr_alg *alga; 477 struct crypto_attr_alg *alga;
478 478
@@ -486,7 +486,21 @@ struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
486 alga = RTA_DATA(rta); 486 alga = RTA_DATA(rta);
487 alga->name[CRYPTO_MAX_ALG_NAME - 1] = 0; 487 alga->name[CRYPTO_MAX_ALG_NAME - 1] = 0;
488 488
489 return crypto_alg_mod_lookup(alga->name, type, mask); 489 return alga->name;
490}
491EXPORT_SYMBOL_GPL(crypto_attr_alg_name);
492
493struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
494{
495 const char *name;
496 int err;
497
498 name = crypto_attr_alg_name(rta);
499 err = PTR_ERR(name);
500 if (IS_ERR(name))
501 return ERR_PTR(err);
502
503 return crypto_alg_mod_lookup(name, type, mask);
490} 504}
491EXPORT_SYMBOL_GPL(crypto_attr_alg); 505EXPORT_SYMBOL_GPL(crypto_attr_alg);
492 506
@@ -605,6 +619,53 @@ int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm)
605} 619}
606EXPORT_SYMBOL_GPL(crypto_tfm_in_queue); 620EXPORT_SYMBOL_GPL(crypto_tfm_in_queue);
607 621
622static inline void crypto_inc_byte(u8 *a, unsigned int size)
623{
624 u8 *b = (a + size);
625 u8 c;
626
627 for (; size; size--) {
628 c = *--b + 1;
629 *b = c;
630 if (c)
631 break;
632 }
633}
634
635void crypto_inc(u8 *a, unsigned int size)
636{
637 __be32 *b = (__be32 *)(a + size);
638 u32 c;
639
640 for (; size >= 4; size -= 4) {
641 c = be32_to_cpu(*--b) + 1;
642 *b = cpu_to_be32(c);
643 if (c)
644 return;
645 }
646
647 crypto_inc_byte(a, size);
648}
649EXPORT_SYMBOL_GPL(crypto_inc);
650
651static inline void crypto_xor_byte(u8 *a, const u8 *b, unsigned int size)
652{
653 for (; size; size--)
654 *a++ ^= *b++;
655}
656
657void crypto_xor(u8 *dst, const u8 *src, unsigned int size)
658{
659 u32 *a = (u32 *)dst;
660 u32 *b = (u32 *)src;
661
662 for (; size >= 4; size -= 4)
663 *a++ ^= *b++;
664
665 crypto_xor_byte((u8 *)a, (u8 *)b, size);
666}
667EXPORT_SYMBOL_GPL(crypto_xor);
668
608static int __init crypto_algapi_init(void) 669static int __init crypto_algapi_init(void)
609{ 670{
610 crypto_init_proc(); 671 crypto_init_proc();
diff --git a/crypto/api.c b/crypto/api.c
index 1f5c72477356..a2496d1bc6d4 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -137,7 +137,7 @@ static struct crypto_alg *crypto_larval_alloc(const char *name, u32 type,
137 return alg; 137 return alg;
138} 138}
139 139
140static void crypto_larval_kill(struct crypto_alg *alg) 140void crypto_larval_kill(struct crypto_alg *alg)
141{ 141{
142 struct crypto_larval *larval = (void *)alg; 142 struct crypto_larval *larval = (void *)alg;
143 143
@@ -147,6 +147,7 @@ static void crypto_larval_kill(struct crypto_alg *alg)
147 complete_all(&larval->completion); 147 complete_all(&larval->completion);
148 crypto_alg_put(alg); 148 crypto_alg_put(alg);
149} 149}
150EXPORT_SYMBOL_GPL(crypto_larval_kill);
150 151
151static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) 152static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
152{ 153{
@@ -176,11 +177,9 @@ static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
176 return alg; 177 return alg;
177} 178}
178 179
179struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask) 180struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask)
180{ 181{
181 struct crypto_alg *alg; 182 struct crypto_alg *alg;
182 struct crypto_alg *larval;
183 int ok;
184 183
185 if (!name) 184 if (!name)
186 return ERR_PTR(-ENOENT); 185 return ERR_PTR(-ENOENT);
@@ -193,7 +192,17 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
193 if (alg) 192 if (alg)
194 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg; 193 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
195 194
196 larval = crypto_larval_alloc(name, type, mask); 195 return crypto_larval_alloc(name, type, mask);
196}
197EXPORT_SYMBOL_GPL(crypto_larval_lookup);
198
199struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
200{
201 struct crypto_alg *alg;
202 struct crypto_alg *larval;
203 int ok;
204
205 larval = crypto_larval_lookup(name, type, mask);
197 if (IS_ERR(larval) || !crypto_is_larval(larval)) 206 if (IS_ERR(larval) || !crypto_is_larval(larval))
198 return larval; 207 return larval;
199 208
diff --git a/crypto/authenc.c b/crypto/authenc.c
index 126a529b496d..ed8ac5a6fa5f 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -10,22 +10,21 @@
10 * 10 *
11 */ 11 */
12 12
13#include <crypto/algapi.h> 13#include <crypto/aead.h>
14#include <crypto/internal/skcipher.h>
15#include <crypto/authenc.h>
16#include <crypto/scatterwalk.h>
14#include <linux/err.h> 17#include <linux/err.h>
15#include <linux/init.h> 18#include <linux/init.h>
16#include <linux/kernel.h> 19#include <linux/kernel.h>
17#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/rtnetlink.h>
18#include <linux/slab.h> 22#include <linux/slab.h>
19#include <linux/spinlock.h> 23#include <linux/spinlock.h>
20 24
21#include "scatterwalk.h"
22
23struct authenc_instance_ctx { 25struct authenc_instance_ctx {
24 struct crypto_spawn auth; 26 struct crypto_spawn auth;
25 struct crypto_spawn enc; 27 struct crypto_skcipher_spawn enc;
26
27 unsigned int authsize;
28 unsigned int enckeylen;
29}; 28};
30 29
31struct crypto_authenc_ctx { 30struct crypto_authenc_ctx {
@@ -37,19 +36,31 @@ struct crypto_authenc_ctx {
37static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key, 36static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
38 unsigned int keylen) 37 unsigned int keylen)
39{ 38{
40 struct authenc_instance_ctx *ictx =
41 crypto_instance_ctx(crypto_aead_alg_instance(authenc));
42 unsigned int enckeylen = ictx->enckeylen;
43 unsigned int authkeylen; 39 unsigned int authkeylen;
40 unsigned int enckeylen;
44 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); 41 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
45 struct crypto_hash *auth = ctx->auth; 42 struct crypto_hash *auth = ctx->auth;
46 struct crypto_ablkcipher *enc = ctx->enc; 43 struct crypto_ablkcipher *enc = ctx->enc;
44 struct rtattr *rta = (void *)key;
45 struct crypto_authenc_key_param *param;
47 int err = -EINVAL; 46 int err = -EINVAL;
48 47
49 if (keylen < enckeylen) { 48 if (!RTA_OK(rta, keylen))
50 crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN); 49 goto badkey;
51 goto out; 50 if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
52 } 51 goto badkey;
52 if (RTA_PAYLOAD(rta) < sizeof(*param))
53 goto badkey;
54
55 param = RTA_DATA(rta);
56 enckeylen = be32_to_cpu(param->enckeylen);
57
58 key += RTA_ALIGN(rta->rta_len);
59 keylen -= RTA_ALIGN(rta->rta_len);
60
61 if (keylen < enckeylen)
62 goto badkey;
63
53 authkeylen = keylen - enckeylen; 64 authkeylen = keylen - enckeylen;
54 65
55 crypto_hash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); 66 crypto_hash_clear_flags(auth, CRYPTO_TFM_REQ_MASK);
@@ -71,21 +82,38 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
71 82
72out: 83out:
73 return err; 84 return err;
85
86badkey:
87 crypto_aead_set_flags(authenc, CRYPTO_TFM_RES_BAD_KEY_LEN);
88 goto out;
74} 89}
75 90
76static int crypto_authenc_hash(struct aead_request *req) 91static void authenc_chain(struct scatterlist *head, struct scatterlist *sg,
92 int chain)
93{
94 if (chain) {
95 head->length += sg->length;
96 sg = scatterwalk_sg_next(sg);
97 }
98
99 if (sg)
100 scatterwalk_sg_chain(head, 2, sg);
101 else
102 sg_mark_end(head);
103}
104
105static u8 *crypto_authenc_hash(struct aead_request *req, unsigned int flags,
106 struct scatterlist *cipher,
107 unsigned int cryptlen)
77{ 108{
78 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 109 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
79 struct authenc_instance_ctx *ictx =
80 crypto_instance_ctx(crypto_aead_alg_instance(authenc));
81 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); 110 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
82 struct crypto_hash *auth = ctx->auth; 111 struct crypto_hash *auth = ctx->auth;
83 struct hash_desc desc = { 112 struct hash_desc desc = {
84 .tfm = auth, 113 .tfm = auth,
114 .flags = aead_request_flags(req) & flags,
85 }; 115 };
86 u8 *hash = aead_request_ctx(req); 116 u8 *hash = aead_request_ctx(req);
87 struct scatterlist *dst = req->dst;
88 unsigned int cryptlen = req->cryptlen;
89 int err; 117 int err;
90 118
91 hash = (u8 *)ALIGN((unsigned long)hash + crypto_hash_alignmask(auth), 119 hash = (u8 *)ALIGN((unsigned long)hash + crypto_hash_alignmask(auth),
@@ -100,7 +128,7 @@ static int crypto_authenc_hash(struct aead_request *req)
100 if (err) 128 if (err)
101 goto auth_unlock; 129 goto auth_unlock;
102 130
103 err = crypto_hash_update(&desc, dst, cryptlen); 131 err = crypto_hash_update(&desc, cipher, cryptlen);
104 if (err) 132 if (err)
105 goto auth_unlock; 133 goto auth_unlock;
106 134
@@ -109,17 +137,53 @@ auth_unlock:
109 spin_unlock_bh(&ctx->auth_lock); 137 spin_unlock_bh(&ctx->auth_lock);
110 138
111 if (err) 139 if (err)
112 return err; 140 return ERR_PTR(err);
141
142 return hash;
143}
113 144
114 scatterwalk_map_and_copy(hash, dst, cryptlen, ictx->authsize, 1); 145static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
146 unsigned int flags)
147{
148 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
149 struct scatterlist *dst = req->dst;
150 struct scatterlist cipher[2];
151 struct page *dstp;
152 unsigned int ivsize = crypto_aead_ivsize(authenc);
153 unsigned int cryptlen;
154 u8 *vdst;
155 u8 *hash;
156
157 dstp = sg_page(dst);
158 vdst = PageHighMem(dstp) ? NULL : page_address(dstp) + dst->offset;
159
160 sg_init_table(cipher, 2);
161 sg_set_buf(cipher, iv, ivsize);
162 authenc_chain(cipher, dst, vdst == iv + ivsize);
163
164 cryptlen = req->cryptlen + ivsize;
165 hash = crypto_authenc_hash(req, flags, cipher, cryptlen);
166 if (IS_ERR(hash))
167 return PTR_ERR(hash);
168
169 scatterwalk_map_and_copy(hash, cipher, cryptlen,
170 crypto_aead_authsize(authenc), 1);
115 return 0; 171 return 0;
116} 172}
117 173
118static void crypto_authenc_encrypt_done(struct crypto_async_request *req, 174static void crypto_authenc_encrypt_done(struct crypto_async_request *req,
119 int err) 175 int err)
120{ 176{
121 if (!err) 177 if (!err) {
122 err = crypto_authenc_hash(req->data); 178 struct aead_request *areq = req->data;
179 struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
180 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
181 struct ablkcipher_request *abreq = aead_request_ctx(areq);
182 u8 *iv = (u8 *)(abreq + 1) +
183 crypto_ablkcipher_reqsize(ctx->enc);
184
185 err = crypto_authenc_genicv(areq, iv, 0);
186 }
123 187
124 aead_request_complete(req->data, err); 188 aead_request_complete(req->data, err);
125} 189}
@@ -129,72 +193,99 @@ static int crypto_authenc_encrypt(struct aead_request *req)
129 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 193 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
130 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); 194 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
131 struct ablkcipher_request *abreq = aead_request_ctx(req); 195 struct ablkcipher_request *abreq = aead_request_ctx(req);
196 struct crypto_ablkcipher *enc = ctx->enc;
197 struct scatterlist *dst = req->dst;
198 unsigned int cryptlen = req->cryptlen;
199 u8 *iv = (u8 *)(abreq + 1) + crypto_ablkcipher_reqsize(enc);
132 int err; 200 int err;
133 201
134 ablkcipher_request_set_tfm(abreq, ctx->enc); 202 ablkcipher_request_set_tfm(abreq, enc);
135 ablkcipher_request_set_callback(abreq, aead_request_flags(req), 203 ablkcipher_request_set_callback(abreq, aead_request_flags(req),
136 crypto_authenc_encrypt_done, req); 204 crypto_authenc_encrypt_done, req);
137 ablkcipher_request_set_crypt(abreq, req->src, req->dst, req->cryptlen, 205 ablkcipher_request_set_crypt(abreq, req->src, dst, cryptlen, req->iv);
138 req->iv); 206
207 memcpy(iv, req->iv, crypto_aead_ivsize(authenc));
139 208
140 err = crypto_ablkcipher_encrypt(abreq); 209 err = crypto_ablkcipher_encrypt(abreq);
141 if (err) 210 if (err)
142 return err; 211 return err;
143 212
144 return crypto_authenc_hash(req); 213 return crypto_authenc_genicv(req, iv, CRYPTO_TFM_REQ_MAY_SLEEP);
145} 214}
146 215
147static int crypto_authenc_verify(struct aead_request *req) 216static void crypto_authenc_givencrypt_done(struct crypto_async_request *req,
217 int err)
148{ 218{
149 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 219 if (!err) {
150 struct authenc_instance_ctx *ictx = 220 struct aead_givcrypt_request *greq = req->data;
151 crypto_instance_ctx(crypto_aead_alg_instance(authenc)); 221
222 err = crypto_authenc_genicv(&greq->areq, greq->giv, 0);
223 }
224
225 aead_request_complete(req->data, err);
226}
227
228static int crypto_authenc_givencrypt(struct aead_givcrypt_request *req)
229{
230 struct crypto_aead *authenc = aead_givcrypt_reqtfm(req);
152 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); 231 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
153 struct crypto_hash *auth = ctx->auth; 232 struct aead_request *areq = &req->areq;
154 struct hash_desc desc = { 233 struct skcipher_givcrypt_request *greq = aead_request_ctx(areq);
155 .tfm = auth, 234 u8 *iv = req->giv;
156 .flags = aead_request_flags(req),
157 };
158 u8 *ohash = aead_request_ctx(req);
159 u8 *ihash;
160 struct scatterlist *src = req->src;
161 unsigned int cryptlen = req->cryptlen;
162 unsigned int authsize;
163 int err; 235 int err;
164 236
165 ohash = (u8 *)ALIGN((unsigned long)ohash + crypto_hash_alignmask(auth), 237 skcipher_givcrypt_set_tfm(greq, ctx->enc);
166 crypto_hash_alignmask(auth) + 1); 238 skcipher_givcrypt_set_callback(greq, aead_request_flags(areq),
167 ihash = ohash + crypto_hash_digestsize(auth); 239 crypto_authenc_givencrypt_done, areq);
168 240 skcipher_givcrypt_set_crypt(greq, areq->src, areq->dst, areq->cryptlen,
169 spin_lock_bh(&ctx->auth_lock); 241 areq->iv);
170 err = crypto_hash_init(&desc); 242 skcipher_givcrypt_set_giv(greq, iv, req->seq);
171 if (err)
172 goto auth_unlock;
173 243
174 err = crypto_hash_update(&desc, req->assoc, req->assoclen); 244 err = crypto_skcipher_givencrypt(greq);
175 if (err) 245 if (err)
176 goto auth_unlock; 246 return err;
177 247
178 err = crypto_hash_update(&desc, src, cryptlen); 248 return crypto_authenc_genicv(areq, iv, CRYPTO_TFM_REQ_MAY_SLEEP);
179 if (err) 249}
180 goto auth_unlock;
181 250
182 err = crypto_hash_final(&desc, ohash); 251static int crypto_authenc_verify(struct aead_request *req,
183auth_unlock: 252 struct scatterlist *cipher,
184 spin_unlock_bh(&ctx->auth_lock); 253 unsigned int cryptlen)
254{
255 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
256 u8 *ohash;
257 u8 *ihash;
258 unsigned int authsize;
185 259
186 if (err) 260 ohash = crypto_authenc_hash(req, CRYPTO_TFM_REQ_MAY_SLEEP, cipher,
187 return err; 261 cryptlen);
262 if (IS_ERR(ohash))
263 return PTR_ERR(ohash);
188 264
189 authsize = ictx->authsize; 265 authsize = crypto_aead_authsize(authenc);
190 scatterwalk_map_and_copy(ihash, src, cryptlen, authsize, 0); 266 ihash = ohash + authsize;
191 return memcmp(ihash, ohash, authsize) ? -EINVAL : 0; 267 scatterwalk_map_and_copy(ihash, cipher, cryptlen, authsize, 0);
268 return memcmp(ihash, ohash, authsize) ? -EBADMSG: 0;
192} 269}
193 270
194static void crypto_authenc_decrypt_done(struct crypto_async_request *req, 271static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
195 int err) 272 unsigned int cryptlen)
196{ 273{
197 aead_request_complete(req->data, err); 274 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
275 struct scatterlist *src = req->src;
276 struct scatterlist cipher[2];
277 struct page *srcp;
278 unsigned int ivsize = crypto_aead_ivsize(authenc);
279 u8 *vsrc;
280
281 srcp = sg_page(src);
282 vsrc = PageHighMem(srcp) ? NULL : page_address(srcp) + src->offset;
283
284 sg_init_table(cipher, 2);
285 sg_set_buf(cipher, iv, ivsize);
286 authenc_chain(cipher, src, vsrc == iv + ivsize);
287
288 return crypto_authenc_verify(req, cipher, cryptlen + ivsize);
198} 289}
199 290
200static int crypto_authenc_decrypt(struct aead_request *req) 291static int crypto_authenc_decrypt(struct aead_request *req)
@@ -202,17 +293,23 @@ static int crypto_authenc_decrypt(struct aead_request *req)
202 struct crypto_aead *authenc = crypto_aead_reqtfm(req); 293 struct crypto_aead *authenc = crypto_aead_reqtfm(req);
203 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc); 294 struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
204 struct ablkcipher_request *abreq = aead_request_ctx(req); 295 struct ablkcipher_request *abreq = aead_request_ctx(req);
296 unsigned int cryptlen = req->cryptlen;
297 unsigned int authsize = crypto_aead_authsize(authenc);
298 u8 *iv = req->iv;
205 int err; 299 int err;
206 300
207 err = crypto_authenc_verify(req); 301 if (cryptlen < authsize)
302 return -EINVAL;
303 cryptlen -= authsize;
304
305 err = crypto_authenc_iverify(req, iv, cryptlen);
208 if (err) 306 if (err)
209 return err; 307 return err;
210 308
211 ablkcipher_request_set_tfm(abreq, ctx->enc); 309 ablkcipher_request_set_tfm(abreq, ctx->enc);
212 ablkcipher_request_set_callback(abreq, aead_request_flags(req), 310 ablkcipher_request_set_callback(abreq, aead_request_flags(req),
213 crypto_authenc_decrypt_done, req); 311 req->base.complete, req->base.data);
214 ablkcipher_request_set_crypt(abreq, req->src, req->dst, req->cryptlen, 312 ablkcipher_request_set_crypt(abreq, req->src, req->dst, cryptlen, iv);
215 req->iv);
216 313
217 return crypto_ablkcipher_decrypt(abreq); 314 return crypto_ablkcipher_decrypt(abreq);
218} 315}
@@ -224,19 +321,13 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
224 struct crypto_authenc_ctx *ctx = crypto_tfm_ctx(tfm); 321 struct crypto_authenc_ctx *ctx = crypto_tfm_ctx(tfm);
225 struct crypto_hash *auth; 322 struct crypto_hash *auth;
226 struct crypto_ablkcipher *enc; 323 struct crypto_ablkcipher *enc;
227 unsigned int digestsize;
228 int err; 324 int err;
229 325
230 auth = crypto_spawn_hash(&ictx->auth); 326 auth = crypto_spawn_hash(&ictx->auth);
231 if (IS_ERR(auth)) 327 if (IS_ERR(auth))
232 return PTR_ERR(auth); 328 return PTR_ERR(auth);
233 329
234 err = -EINVAL; 330 enc = crypto_spawn_skcipher(&ictx->enc);
235 digestsize = crypto_hash_digestsize(auth);
236 if (ictx->authsize > digestsize)
237 goto err_free_hash;
238
239 enc = crypto_spawn_ablkcipher(&ictx->enc);
240 err = PTR_ERR(enc); 331 err = PTR_ERR(enc);
241 if (IS_ERR(enc)) 332 if (IS_ERR(enc))
242 goto err_free_hash; 333 goto err_free_hash;
@@ -246,9 +337,10 @@ static int crypto_authenc_init_tfm(struct crypto_tfm *tfm)
246 tfm->crt_aead.reqsize = max_t(unsigned int, 337 tfm->crt_aead.reqsize = max_t(unsigned int,
247 (crypto_hash_alignmask(auth) & 338 (crypto_hash_alignmask(auth) &
248 ~(crypto_tfm_ctx_alignment() - 1)) + 339 ~(crypto_tfm_ctx_alignment() - 1)) +
249 digestsize * 2, 340 crypto_hash_digestsize(auth) * 2,
250 sizeof(struct ablkcipher_request) + 341 sizeof(struct skcipher_givcrypt_request) +
251 crypto_ablkcipher_reqsize(enc)); 342 crypto_ablkcipher_reqsize(enc) +
343 crypto_ablkcipher_ivsize(enc));
252 344
253 spin_lock_init(&ctx->auth_lock); 345 spin_lock_init(&ctx->auth_lock);
254 346
@@ -269,75 +361,74 @@ static void crypto_authenc_exit_tfm(struct crypto_tfm *tfm)
269 361
270static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb) 362static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
271{ 363{
364 struct crypto_attr_type *algt;
272 struct crypto_instance *inst; 365 struct crypto_instance *inst;
273 struct crypto_alg *auth; 366 struct crypto_alg *auth;
274 struct crypto_alg *enc; 367 struct crypto_alg *enc;
275 struct authenc_instance_ctx *ctx; 368 struct authenc_instance_ctx *ctx;
276 unsigned int authsize; 369 const char *enc_name;
277 unsigned int enckeylen;
278 int err; 370 int err;
279 371
280 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD); 372 algt = crypto_get_attr_type(tb);
281 if (err) 373 err = PTR_ERR(algt);
374 if (IS_ERR(algt))
282 return ERR_PTR(err); 375 return ERR_PTR(err);
283 376
377 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
378 return ERR_PTR(-EINVAL);
379
284 auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, 380 auth = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH,
285 CRYPTO_ALG_TYPE_HASH_MASK); 381 CRYPTO_ALG_TYPE_HASH_MASK);
286 if (IS_ERR(auth)) 382 if (IS_ERR(auth))
287 return ERR_PTR(PTR_ERR(auth)); 383 return ERR_PTR(PTR_ERR(auth));
288 384
289 err = crypto_attr_u32(tb[2], &authsize); 385 enc_name = crypto_attr_alg_name(tb[2]);
290 inst = ERR_PTR(err); 386 err = PTR_ERR(enc_name);
291 if (err) 387 if (IS_ERR(enc_name))
292 goto out_put_auth;
293
294 enc = crypto_attr_alg(tb[3], CRYPTO_ALG_TYPE_BLKCIPHER,
295 CRYPTO_ALG_TYPE_MASK);
296 inst = ERR_PTR(PTR_ERR(enc));
297 if (IS_ERR(enc))
298 goto out_put_auth; 388 goto out_put_auth;
299 389
300 err = crypto_attr_u32(tb[4], &enckeylen);
301 if (err)
302 goto out_put_enc;
303
304 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); 390 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
305 err = -ENOMEM; 391 err = -ENOMEM;
306 if (!inst) 392 if (!inst)
307 goto out_put_enc; 393 goto out_put_auth;
308
309 err = -ENAMETOOLONG;
310 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
311 "authenc(%s,%u,%s,%u)", auth->cra_name, authsize,
312 enc->cra_name, enckeylen) >= CRYPTO_MAX_ALG_NAME)
313 goto err_free_inst;
314
315 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
316 "authenc(%s,%u,%s,%u)", auth->cra_driver_name,
317 authsize, enc->cra_driver_name, enckeylen) >=
318 CRYPTO_MAX_ALG_NAME)
319 goto err_free_inst;
320 394
321 ctx = crypto_instance_ctx(inst); 395 ctx = crypto_instance_ctx(inst);
322 ctx->authsize = authsize;
323 ctx->enckeylen = enckeylen;
324 396
325 err = crypto_init_spawn(&ctx->auth, auth, inst, CRYPTO_ALG_TYPE_MASK); 397 err = crypto_init_spawn(&ctx->auth, auth, inst, CRYPTO_ALG_TYPE_MASK);
326 if (err) 398 if (err)
327 goto err_free_inst; 399 goto err_free_inst;
328 400
329 err = crypto_init_spawn(&ctx->enc, enc, inst, CRYPTO_ALG_TYPE_MASK); 401 crypto_set_skcipher_spawn(&ctx->enc, inst);
402 err = crypto_grab_skcipher(&ctx->enc, enc_name, 0,
403 crypto_requires_sync(algt->type,
404 algt->mask));
330 if (err) 405 if (err)
331 goto err_drop_auth; 406 goto err_drop_auth;
332 407
333 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; 408 enc = crypto_skcipher_spawn_alg(&ctx->enc);
409
410 err = -ENAMETOOLONG;
411 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
412 "authenc(%s,%s)", auth->cra_name, enc->cra_name) >=
413 CRYPTO_MAX_ALG_NAME)
414 goto err_drop_enc;
415
416 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
417 "authenc(%s,%s)", auth->cra_driver_name,
418 enc->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
419 goto err_drop_enc;
420
421 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
422 inst->alg.cra_flags |= enc->cra_flags & CRYPTO_ALG_ASYNC;
334 inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority; 423 inst->alg.cra_priority = enc->cra_priority * 10 + auth->cra_priority;
335 inst->alg.cra_blocksize = enc->cra_blocksize; 424 inst->alg.cra_blocksize = enc->cra_blocksize;
336 inst->alg.cra_alignmask = max(auth->cra_alignmask, enc->cra_alignmask); 425 inst->alg.cra_alignmask = auth->cra_alignmask | enc->cra_alignmask;
337 inst->alg.cra_type = &crypto_aead_type; 426 inst->alg.cra_type = &crypto_aead_type;
338 427
339 inst->alg.cra_aead.ivsize = enc->cra_blkcipher.ivsize; 428 inst->alg.cra_aead.ivsize = enc->cra_ablkcipher.ivsize;
340 inst->alg.cra_aead.authsize = authsize; 429 inst->alg.cra_aead.maxauthsize = auth->cra_type == &crypto_hash_type ?
430 auth->cra_hash.digestsize :
431 auth->cra_digest.dia_digestsize;
341 432
342 inst->alg.cra_ctxsize = sizeof(struct crypto_authenc_ctx); 433 inst->alg.cra_ctxsize = sizeof(struct crypto_authenc_ctx);
343 434
@@ -347,18 +438,19 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
347 inst->alg.cra_aead.setkey = crypto_authenc_setkey; 438 inst->alg.cra_aead.setkey = crypto_authenc_setkey;
348 inst->alg.cra_aead.encrypt = crypto_authenc_encrypt; 439 inst->alg.cra_aead.encrypt = crypto_authenc_encrypt;
349 inst->alg.cra_aead.decrypt = crypto_authenc_decrypt; 440 inst->alg.cra_aead.decrypt = crypto_authenc_decrypt;
441 inst->alg.cra_aead.givencrypt = crypto_authenc_givencrypt;
350 442
351out: 443out:
352 crypto_mod_put(enc);
353out_put_auth:
354 crypto_mod_put(auth); 444 crypto_mod_put(auth);
355 return inst; 445 return inst;
356 446
447err_drop_enc:
448 crypto_drop_skcipher(&ctx->enc);
357err_drop_auth: 449err_drop_auth:
358 crypto_drop_spawn(&ctx->auth); 450 crypto_drop_spawn(&ctx->auth);
359err_free_inst: 451err_free_inst:
360 kfree(inst); 452 kfree(inst);
361out_put_enc: 453out_put_auth:
362 inst = ERR_PTR(err); 454 inst = ERR_PTR(err);
363 goto out; 455 goto out;
364} 456}
@@ -367,7 +459,7 @@ static void crypto_authenc_free(struct crypto_instance *inst)
367{ 459{
368 struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst); 460 struct authenc_instance_ctx *ctx = crypto_instance_ctx(inst);
369 461
370 crypto_drop_spawn(&ctx->enc); 462 crypto_drop_skcipher(&ctx->enc);
371 crypto_drop_spawn(&ctx->auth); 463 crypto_drop_spawn(&ctx->auth);
372 kfree(inst); 464 kfree(inst);
373} 465}
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index f6c67f9d4e5c..4a7e65c4df4d 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -14,7 +14,8 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/crypto.h> 17#include <crypto/internal/skcipher.h>
18#include <crypto/scatterwalk.h>
18#include <linux/errno.h> 19#include <linux/errno.h>
19#include <linux/hardirq.h> 20#include <linux/hardirq.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -25,7 +26,6 @@
25#include <linux/string.h> 26#include <linux/string.h>
26 27
27#include "internal.h" 28#include "internal.h"
28#include "scatterwalk.h"
29 29
30enum { 30enum {
31 BLKCIPHER_WALK_PHYS = 1 << 0, 31 BLKCIPHER_WALK_PHYS = 1 << 0,
@@ -433,9 +433,8 @@ static unsigned int crypto_blkcipher_ctxsize(struct crypto_alg *alg, u32 type,
433 struct blkcipher_alg *cipher = &alg->cra_blkcipher; 433 struct blkcipher_alg *cipher = &alg->cra_blkcipher;
434 unsigned int len = alg->cra_ctxsize; 434 unsigned int len = alg->cra_ctxsize;
435 435
436 type ^= CRYPTO_ALG_ASYNC; 436 if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK &&
437 mask &= CRYPTO_ALG_ASYNC; 437 cipher->ivsize) {
438 if ((type & mask) && cipher->ivsize) {
439 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1); 438 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
440 len += cipher->ivsize; 439 len += cipher->ivsize;
441 } 440 }
@@ -451,6 +450,11 @@ static int crypto_init_blkcipher_ops_async(struct crypto_tfm *tfm)
451 crt->setkey = async_setkey; 450 crt->setkey = async_setkey;
452 crt->encrypt = async_encrypt; 451 crt->encrypt = async_encrypt;
453 crt->decrypt = async_decrypt; 452 crt->decrypt = async_decrypt;
453 if (!alg->ivsize) {
454 crt->givencrypt = skcipher_null_givencrypt;
455 crt->givdecrypt = skcipher_null_givdecrypt;
456 }
457 crt->base = __crypto_ablkcipher_cast(tfm);
454 crt->ivsize = alg->ivsize; 458 crt->ivsize = alg->ivsize;
455 459
456 return 0; 460 return 0;
@@ -482,9 +486,7 @@ static int crypto_init_blkcipher_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
482 if (alg->ivsize > PAGE_SIZE / 8) 486 if (alg->ivsize > PAGE_SIZE / 8)
483 return -EINVAL; 487 return -EINVAL;
484 488
485 type ^= CRYPTO_ALG_ASYNC; 489 if ((mask & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_MASK)
486 mask &= CRYPTO_ALG_ASYNC;
487 if (type & mask)
488 return crypto_init_blkcipher_ops_sync(tfm); 490 return crypto_init_blkcipher_ops_sync(tfm);
489 else 491 else
490 return crypto_init_blkcipher_ops_async(tfm); 492 return crypto_init_blkcipher_ops_async(tfm);
@@ -499,6 +501,8 @@ static void crypto_blkcipher_show(struct seq_file *m, struct crypto_alg *alg)
499 seq_printf(m, "min keysize : %u\n", alg->cra_blkcipher.min_keysize); 501 seq_printf(m, "min keysize : %u\n", alg->cra_blkcipher.min_keysize);
500 seq_printf(m, "max keysize : %u\n", alg->cra_blkcipher.max_keysize); 502 seq_printf(m, "max keysize : %u\n", alg->cra_blkcipher.max_keysize);
501 seq_printf(m, "ivsize : %u\n", alg->cra_blkcipher.ivsize); 503 seq_printf(m, "ivsize : %u\n", alg->cra_blkcipher.ivsize);
504 seq_printf(m, "geniv : %s\n", alg->cra_blkcipher.geniv ?:
505 "<default>");
502} 506}
503 507
504const struct crypto_type crypto_blkcipher_type = { 508const struct crypto_type crypto_blkcipher_type = {
@@ -510,5 +514,187 @@ const struct crypto_type crypto_blkcipher_type = {
510}; 514};
511EXPORT_SYMBOL_GPL(crypto_blkcipher_type); 515EXPORT_SYMBOL_GPL(crypto_blkcipher_type);
512 516
517static int crypto_grab_nivcipher(struct crypto_skcipher_spawn *spawn,
518 const char *name, u32 type, u32 mask)
519{
520 struct crypto_alg *alg;
521 int err;
522
523 type = crypto_skcipher_type(type);
524 mask = crypto_skcipher_mask(mask) | CRYPTO_ALG_GENIV;
525
526 alg = crypto_alg_mod_lookup(name, type, mask);
527 if (IS_ERR(alg))
528 return PTR_ERR(alg);
529
530 err = crypto_init_spawn(&spawn->base, alg, spawn->base.inst, mask);
531 crypto_mod_put(alg);
532 return err;
533}
534
535struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
536 struct rtattr **tb, u32 type,
537 u32 mask)
538{
539 struct {
540 int (*setkey)(struct crypto_ablkcipher *tfm, const u8 *key,
541 unsigned int keylen);
542 int (*encrypt)(struct ablkcipher_request *req);
543 int (*decrypt)(struct ablkcipher_request *req);
544
545 unsigned int min_keysize;
546 unsigned int max_keysize;
547 unsigned int ivsize;
548
549 const char *geniv;
550 } balg;
551 const char *name;
552 struct crypto_skcipher_spawn *spawn;
553 struct crypto_attr_type *algt;
554 struct crypto_instance *inst;
555 struct crypto_alg *alg;
556 int err;
557
558 algt = crypto_get_attr_type(tb);
559 err = PTR_ERR(algt);
560 if (IS_ERR(algt))
561 return ERR_PTR(err);
562
563 if ((algt->type ^ (CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV)) &
564 algt->mask)
565 return ERR_PTR(-EINVAL);
566
567 name = crypto_attr_alg_name(tb[1]);
568 err = PTR_ERR(name);
569 if (IS_ERR(name))
570 return ERR_PTR(err);
571
572 inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
573 if (!inst)
574 return ERR_PTR(-ENOMEM);
575
576 spawn = crypto_instance_ctx(inst);
577
578 /* Ignore async algorithms if necessary. */
579 mask |= crypto_requires_sync(algt->type, algt->mask);
580
581 crypto_set_skcipher_spawn(spawn, inst);
582 err = crypto_grab_nivcipher(spawn, name, type, mask);
583 if (err)
584 goto err_free_inst;
585
586 alg = crypto_skcipher_spawn_alg(spawn);
587
588 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
589 CRYPTO_ALG_TYPE_BLKCIPHER) {
590 balg.ivsize = alg->cra_blkcipher.ivsize;
591 balg.min_keysize = alg->cra_blkcipher.min_keysize;
592 balg.max_keysize = alg->cra_blkcipher.max_keysize;
593
594 balg.setkey = async_setkey;
595 balg.encrypt = async_encrypt;
596 balg.decrypt = async_decrypt;
597
598 balg.geniv = alg->cra_blkcipher.geniv;
599 } else {
600 balg.ivsize = alg->cra_ablkcipher.ivsize;
601 balg.min_keysize = alg->cra_ablkcipher.min_keysize;
602 balg.max_keysize = alg->cra_ablkcipher.max_keysize;
603
604 balg.setkey = alg->cra_ablkcipher.setkey;
605 balg.encrypt = alg->cra_ablkcipher.encrypt;
606 balg.decrypt = alg->cra_ablkcipher.decrypt;
607
608 balg.geniv = alg->cra_ablkcipher.geniv;
609 }
610
611 err = -EINVAL;
612 if (!balg.ivsize)
613 goto err_drop_alg;
614
615 /*
616 * This is only true if we're constructing an algorithm with its
617 * default IV generator. For the default generator we elide the
618 * template name and double-check the IV generator.
619 */
620 if (algt->mask & CRYPTO_ALG_GENIV) {
621 if (!balg.geniv)
622 balg.geniv = crypto_default_geniv(alg);
623 err = -EAGAIN;
624 if (strcmp(tmpl->name, balg.geniv))
625 goto err_drop_alg;
626
627 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
628 memcpy(inst->alg.cra_driver_name, alg->cra_driver_name,
629 CRYPTO_MAX_ALG_NAME);
630 } else {
631 err = -ENAMETOOLONG;
632 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
633 "%s(%s)", tmpl->name, alg->cra_name) >=
634 CRYPTO_MAX_ALG_NAME)
635 goto err_drop_alg;
636 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
637 "%s(%s)", tmpl->name, alg->cra_driver_name) >=
638 CRYPTO_MAX_ALG_NAME)
639 goto err_drop_alg;
640 }
641
642 inst->alg.cra_flags = CRYPTO_ALG_TYPE_GIVCIPHER | CRYPTO_ALG_GENIV;
643 inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
644 inst->alg.cra_priority = alg->cra_priority;
645 inst->alg.cra_blocksize = alg->cra_blocksize;
646 inst->alg.cra_alignmask = alg->cra_alignmask;
647 inst->alg.cra_type = &crypto_givcipher_type;
648
649 inst->alg.cra_ablkcipher.ivsize = balg.ivsize;
650 inst->alg.cra_ablkcipher.min_keysize = balg.min_keysize;
651 inst->alg.cra_ablkcipher.max_keysize = balg.max_keysize;
652 inst->alg.cra_ablkcipher.geniv = balg.geniv;
653
654 inst->alg.cra_ablkcipher.setkey = balg.setkey;
655 inst->alg.cra_ablkcipher.encrypt = balg.encrypt;
656 inst->alg.cra_ablkcipher.decrypt = balg.decrypt;
657
658out:
659 return inst;
660
661err_drop_alg:
662 crypto_drop_skcipher(spawn);
663err_free_inst:
664 kfree(inst);
665 inst = ERR_PTR(err);
666 goto out;
667}
668EXPORT_SYMBOL_GPL(skcipher_geniv_alloc);
669
670void skcipher_geniv_free(struct crypto_instance *inst)
671{
672 crypto_drop_skcipher(crypto_instance_ctx(inst));
673 kfree(inst);
674}
675EXPORT_SYMBOL_GPL(skcipher_geniv_free);
676
677int skcipher_geniv_init(struct crypto_tfm *tfm)
678{
679 struct crypto_instance *inst = (void *)tfm->__crt_alg;
680 struct crypto_ablkcipher *cipher;
681
682 cipher = crypto_spawn_skcipher(crypto_instance_ctx(inst));
683 if (IS_ERR(cipher))
684 return PTR_ERR(cipher);
685
686 tfm->crt_ablkcipher.base = cipher;
687 tfm->crt_ablkcipher.reqsize += crypto_ablkcipher_reqsize(cipher);
688
689 return 0;
690}
691EXPORT_SYMBOL_GPL(skcipher_geniv_init);
692
693void skcipher_geniv_exit(struct crypto_tfm *tfm)
694{
695 crypto_free_ablkcipher(tfm->crt_ablkcipher.base);
696}
697EXPORT_SYMBOL_GPL(skcipher_geniv_exit);
698
513MODULE_LICENSE("GPL"); 699MODULE_LICENSE("GPL");
514MODULE_DESCRIPTION("Generic block chaining cipher type"); 700MODULE_DESCRIPTION("Generic block chaining cipher type");
diff --git a/crypto/camellia.c b/crypto/camellia.c
index 6877ecfd90bb..493fee7e0a8b 100644
--- a/crypto/camellia.c
+++ b/crypto/camellia.c
@@ -36,176 +36,6 @@
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38 38
39
40#define CAMELLIA_MIN_KEY_SIZE 16
41#define CAMELLIA_MAX_KEY_SIZE 32
42#define CAMELLIA_BLOCK_SIZE 16
43#define CAMELLIA_TABLE_BYTE_LEN 272
44#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4)
45
46typedef u32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN];
47
48
49/* key constants */
50
51#define CAMELLIA_SIGMA1L (0xA09E667FL)
52#define CAMELLIA_SIGMA1R (0x3BCC908BL)
53#define CAMELLIA_SIGMA2L (0xB67AE858L)
54#define CAMELLIA_SIGMA2R (0x4CAA73B2L)
55#define CAMELLIA_SIGMA3L (0xC6EF372FL)
56#define CAMELLIA_SIGMA3R (0xE94F82BEL)
57#define CAMELLIA_SIGMA4L (0x54FF53A5L)
58#define CAMELLIA_SIGMA4R (0xF1D36F1CL)
59#define CAMELLIA_SIGMA5L (0x10E527FAL)
60#define CAMELLIA_SIGMA5R (0xDE682D1DL)
61#define CAMELLIA_SIGMA6L (0xB05688C2L)
62#define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
63
64struct camellia_ctx {
65 int key_length;
66 KEY_TABLE_TYPE key_table;
67};
68
69
70/*
71 * macros
72 */
73
74
75# define GETU32(pt) (((u32)(pt)[0] << 24) \
76 ^ ((u32)(pt)[1] << 16) \
77 ^ ((u32)(pt)[2] << 8) \
78 ^ ((u32)(pt)[3]))
79
80#define COPY4WORD(dst, src) \
81 do { \
82 (dst)[0]=(src)[0]; \
83 (dst)[1]=(src)[1]; \
84 (dst)[2]=(src)[2]; \
85 (dst)[3]=(src)[3]; \
86 }while(0)
87
88#define SWAP4WORD(word) \
89 do { \
90 CAMELLIA_SWAP4((word)[0]); \
91 CAMELLIA_SWAP4((word)[1]); \
92 CAMELLIA_SWAP4((word)[2]); \
93 CAMELLIA_SWAP4((word)[3]); \
94 }while(0)
95
96#define XOR4WORD(a, b)/* a = a ^ b */ \
97 do { \
98 (a)[0]^=(b)[0]; \
99 (a)[1]^=(b)[1]; \
100 (a)[2]^=(b)[2]; \
101 (a)[3]^=(b)[3]; \
102 }while(0)
103
104#define XOR4WORD2(a, b, c)/* a = b ^ c */ \
105 do { \
106 (a)[0]=(b)[0]^(c)[0]; \
107 (a)[1]=(b)[1]^(c)[1]; \
108 (a)[2]=(b)[2]^(c)[2]; \
109 (a)[3]=(b)[3]^(c)[3]; \
110 }while(0)
111
112#define CAMELLIA_SUBKEY_L(INDEX) (subkey[(INDEX)*2])
113#define CAMELLIA_SUBKEY_R(INDEX) (subkey[(INDEX)*2 + 1])
114
115/* rotation right shift 1byte */
116#define CAMELLIA_RR8(x) (((x) >> 8) + ((x) << 24))
117/* rotation left shift 1bit */
118#define CAMELLIA_RL1(x) (((x) << 1) + ((x) >> 31))
119/* rotation left shift 1byte */
120#define CAMELLIA_RL8(x) (((x) << 8) + ((x) >> 24))
121
122#define CAMELLIA_ROLDQ(ll, lr, rl, rr, w0, w1, bits) \
123 do { \
124 w0 = ll; \
125 ll = (ll << bits) + (lr >> (32 - bits)); \
126 lr = (lr << bits) + (rl >> (32 - bits)); \
127 rl = (rl << bits) + (rr >> (32 - bits)); \
128 rr = (rr << bits) + (w0 >> (32 - bits)); \
129 } while(0)
130
131#define CAMELLIA_ROLDQo32(ll, lr, rl, rr, w0, w1, bits) \
132 do { \
133 w0 = ll; \
134 w1 = lr; \
135 ll = (lr << (bits - 32)) + (rl >> (64 - bits)); \
136 lr = (rl << (bits - 32)) + (rr >> (64 - bits)); \
137 rl = (rr << (bits - 32)) + (w0 >> (64 - bits)); \
138 rr = (w0 << (bits - 32)) + (w1 >> (64 - bits)); \
139 } while(0)
140
141#define CAMELLIA_SP1110(INDEX) (camellia_sp1110[(INDEX)])
142#define CAMELLIA_SP0222(INDEX) (camellia_sp0222[(INDEX)])
143#define CAMELLIA_SP3033(INDEX) (camellia_sp3033[(INDEX)])
144#define CAMELLIA_SP4404(INDEX) (camellia_sp4404[(INDEX)])
145
146#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) \
147 do { \
148 il = xl ^ kl; \
149 ir = xr ^ kr; \
150 t0 = il >> 16; \
151 t1 = ir >> 16; \
152 yl = CAMELLIA_SP1110(ir & 0xff) \
153 ^ CAMELLIA_SP0222((t1 >> 8) & 0xff) \
154 ^ CAMELLIA_SP3033(t1 & 0xff) \
155 ^ CAMELLIA_SP4404((ir >> 8) & 0xff); \
156 yr = CAMELLIA_SP1110((t0 >> 8) & 0xff) \
157 ^ CAMELLIA_SP0222(t0 & 0xff) \
158 ^ CAMELLIA_SP3033((il >> 8) & 0xff) \
159 ^ CAMELLIA_SP4404(il & 0xff); \
160 yl ^= yr; \
161 yr = CAMELLIA_RR8(yr); \
162 yr ^= yl; \
163 } while(0)
164
165
166/*
167 * for speed up
168 *
169 */
170#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
171 do { \
172 t0 = kll; \
173 t2 = krr; \
174 t0 &= ll; \
175 t2 |= rr; \
176 rl ^= t2; \
177 lr ^= CAMELLIA_RL1(t0); \
178 t3 = krl; \
179 t1 = klr; \
180 t3 &= rl; \
181 t1 |= lr; \
182 ll ^= t1; \
183 rr ^= CAMELLIA_RL1(t3); \
184 } while(0)
185
186#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) \
187 do { \
188 ir = CAMELLIA_SP1110(xr & 0xff); \
189 il = CAMELLIA_SP1110((xl>>24) & 0xff); \
190 ir ^= CAMELLIA_SP0222((xr>>24) & 0xff); \
191 il ^= CAMELLIA_SP0222((xl>>16) & 0xff); \
192 ir ^= CAMELLIA_SP3033((xr>>16) & 0xff); \
193 il ^= CAMELLIA_SP3033((xl>>8) & 0xff); \
194 ir ^= CAMELLIA_SP4404((xr>>8) & 0xff); \
195 il ^= CAMELLIA_SP4404(xl & 0xff); \
196 il ^= kl; \
197 ir ^= il ^ kr; \
198 yl ^= ir; \
199 yr ^= CAMELLIA_RR8(il) ^ ir; \
200 } while(0)
201
202/**
203 * Stuff related to the Camellia key schedule
204 */
205#define SUBL(x) subL[(x)]
206#define SUBR(x) subR[(x)]
207
208
209static const u32 camellia_sp1110[256] = { 39static const u32 camellia_sp1110[256] = {
210 0x70707000,0x82828200,0x2c2c2c00,0xececec00, 40 0x70707000,0x82828200,0x2c2c2c00,0xececec00,
211 0xb3b3b300,0x27272700,0xc0c0c000,0xe5e5e500, 41 0xb3b3b300,0x27272700,0xc0c0c000,0xe5e5e500,
@@ -475,67 +305,348 @@ static const u32 camellia_sp4404[256] = {
475}; 305};
476 306
477 307
308#define CAMELLIA_MIN_KEY_SIZE 16
309#define CAMELLIA_MAX_KEY_SIZE 32
310#define CAMELLIA_BLOCK_SIZE 16
311#define CAMELLIA_TABLE_BYTE_LEN 272
312
313/*
314 * NB: L and R below stand for 'left' and 'right' as in written numbers.
315 * That is, in (xxxL,xxxR) pair xxxL holds most significant digits,
316 * _not_ least significant ones!
317 */
318
319
320/* key constants */
321
322#define CAMELLIA_SIGMA1L (0xA09E667FL)
323#define CAMELLIA_SIGMA1R (0x3BCC908BL)
324#define CAMELLIA_SIGMA2L (0xB67AE858L)
325#define CAMELLIA_SIGMA2R (0x4CAA73B2L)
326#define CAMELLIA_SIGMA3L (0xC6EF372FL)
327#define CAMELLIA_SIGMA3R (0xE94F82BEL)
328#define CAMELLIA_SIGMA4L (0x54FF53A5L)
329#define CAMELLIA_SIGMA4R (0xF1D36F1CL)
330#define CAMELLIA_SIGMA5L (0x10E527FAL)
331#define CAMELLIA_SIGMA5R (0xDE682D1DL)
332#define CAMELLIA_SIGMA6L (0xB05688C2L)
333#define CAMELLIA_SIGMA6R (0xB3E6C1FDL)
334
335/*
336 * macros
337 */
338#define GETU32(v, pt) \
339 do { \
340 /* latest breed of gcc is clever enough to use move */ \
341 memcpy(&(v), (pt), 4); \
342 (v) = be32_to_cpu(v); \
343 } while(0)
344
345/* rotation right shift 1byte */
346#define ROR8(x) (((x) >> 8) + ((x) << 24))
347/* rotation left shift 1bit */
348#define ROL1(x) (((x) << 1) + ((x) >> 31))
349/* rotation left shift 1byte */
350#define ROL8(x) (((x) << 8) + ((x) >> 24))
351
352#define ROLDQ(ll, lr, rl, rr, w0, w1, bits) \
353 do { \
354 w0 = ll; \
355 ll = (ll << bits) + (lr >> (32 - bits)); \
356 lr = (lr << bits) + (rl >> (32 - bits)); \
357 rl = (rl << bits) + (rr >> (32 - bits)); \
358 rr = (rr << bits) + (w0 >> (32 - bits)); \
359 } while(0)
360
361#define ROLDQo32(ll, lr, rl, rr, w0, w1, bits) \
362 do { \
363 w0 = ll; \
364 w1 = lr; \
365 ll = (lr << (bits - 32)) + (rl >> (64 - bits)); \
366 lr = (rl << (bits - 32)) + (rr >> (64 - bits)); \
367 rl = (rr << (bits - 32)) + (w0 >> (64 - bits)); \
368 rr = (w0 << (bits - 32)) + (w1 >> (64 - bits)); \
369 } while(0)
370
371#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) \
372 do { \
373 il = xl ^ kl; \
374 ir = xr ^ kr; \
375 t0 = il >> 16; \
376 t1 = ir >> 16; \
377 yl = camellia_sp1110[(u8)(ir )] \
378 ^ camellia_sp0222[ (t1 >> 8)] \
379 ^ camellia_sp3033[(u8)(t1 )] \
380 ^ camellia_sp4404[(u8)(ir >> 8)]; \
381 yr = camellia_sp1110[ (t0 >> 8)] \
382 ^ camellia_sp0222[(u8)(t0 )] \
383 ^ camellia_sp3033[(u8)(il >> 8)] \
384 ^ camellia_sp4404[(u8)(il )]; \
385 yl ^= yr; \
386 yr = ROR8(yr); \
387 yr ^= yl; \
388 } while(0)
389
390#define SUBKEY_L(INDEX) (subkey[(INDEX)*2])
391#define SUBKEY_R(INDEX) (subkey[(INDEX)*2 + 1])
392
393static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
394{
395 u32 dw, tl, tr;
396 u32 kw4l, kw4r;
397 int i;
398
399 /* absorb kw2 to other subkeys */
400 /* round 2 */
401 subL[3] ^= subL[1]; subR[3] ^= subR[1];
402 /* round 4 */
403 subL[5] ^= subL[1]; subR[5] ^= subR[1];
404 /* round 6 */
405 subL[7] ^= subL[1]; subR[7] ^= subR[1];
406 subL[1] ^= subR[1] & ~subR[9];
407 dw = subL[1] & subL[9],
408 subR[1] ^= ROL1(dw); /* modified for FLinv(kl2) */
409 /* round 8 */
410 subL[11] ^= subL[1]; subR[11] ^= subR[1];
411 /* round 10 */
412 subL[13] ^= subL[1]; subR[13] ^= subR[1];
413 /* round 12 */
414 subL[15] ^= subL[1]; subR[15] ^= subR[1];
415 subL[1] ^= subR[1] & ~subR[17];
416 dw = subL[1] & subL[17],
417 subR[1] ^= ROL1(dw); /* modified for FLinv(kl4) */
418 /* round 14 */
419 subL[19] ^= subL[1]; subR[19] ^= subR[1];
420 /* round 16 */
421 subL[21] ^= subL[1]; subR[21] ^= subR[1];
422 /* round 18 */
423 subL[23] ^= subL[1]; subR[23] ^= subR[1];
424 if (max == 24) {
425 /* kw3 */
426 subL[24] ^= subL[1]; subR[24] ^= subR[1];
427
428 /* absorb kw4 to other subkeys */
429 kw4l = subL[25]; kw4r = subR[25];
430 } else {
431 subL[1] ^= subR[1] & ~subR[25];
432 dw = subL[1] & subL[25],
433 subR[1] ^= ROL1(dw); /* modified for FLinv(kl6) */
434 /* round 20 */
435 subL[27] ^= subL[1]; subR[27] ^= subR[1];
436 /* round 22 */
437 subL[29] ^= subL[1]; subR[29] ^= subR[1];
438 /* round 24 */
439 subL[31] ^= subL[1]; subR[31] ^= subR[1];
440 /* kw3 */
441 subL[32] ^= subL[1]; subR[32] ^= subR[1];
442
443 /* absorb kw4 to other subkeys */
444 kw4l = subL[33]; kw4r = subR[33];
445 /* round 23 */
446 subL[30] ^= kw4l; subR[30] ^= kw4r;
447 /* round 21 */
448 subL[28] ^= kw4l; subR[28] ^= kw4r;
449 /* round 19 */
450 subL[26] ^= kw4l; subR[26] ^= kw4r;
451 kw4l ^= kw4r & ~subR[24];
452 dw = kw4l & subL[24],
453 kw4r ^= ROL1(dw); /* modified for FL(kl5) */
454 }
455 /* round 17 */
456 subL[22] ^= kw4l; subR[22] ^= kw4r;
457 /* round 15 */
458 subL[20] ^= kw4l; subR[20] ^= kw4r;
459 /* round 13 */
460 subL[18] ^= kw4l; subR[18] ^= kw4r;
461 kw4l ^= kw4r & ~subR[16];
462 dw = kw4l & subL[16],
463 kw4r ^= ROL1(dw); /* modified for FL(kl3) */
464 /* round 11 */
465 subL[14] ^= kw4l; subR[14] ^= kw4r;
466 /* round 9 */
467 subL[12] ^= kw4l; subR[12] ^= kw4r;
468 /* round 7 */
469 subL[10] ^= kw4l; subR[10] ^= kw4r;
470 kw4l ^= kw4r & ~subR[8];
471 dw = kw4l & subL[8],
472 kw4r ^= ROL1(dw); /* modified for FL(kl1) */
473 /* round 5 */
474 subL[6] ^= kw4l; subR[6] ^= kw4r;
475 /* round 3 */
476 subL[4] ^= kw4l; subR[4] ^= kw4r;
477 /* round 1 */
478 subL[2] ^= kw4l; subR[2] ^= kw4r;
479 /* kw1 */
480 subL[0] ^= kw4l; subR[0] ^= kw4r;
481
482 /* key XOR is end of F-function */
483 SUBKEY_L(0) = subL[0] ^ subL[2];/* kw1 */
484 SUBKEY_R(0) = subR[0] ^ subR[2];
485 SUBKEY_L(2) = subL[3]; /* round 1 */
486 SUBKEY_R(2) = subR[3];
487 SUBKEY_L(3) = subL[2] ^ subL[4]; /* round 2 */
488 SUBKEY_R(3) = subR[2] ^ subR[4];
489 SUBKEY_L(4) = subL[3] ^ subL[5]; /* round 3 */
490 SUBKEY_R(4) = subR[3] ^ subR[5];
491 SUBKEY_L(5) = subL[4] ^ subL[6]; /* round 4 */
492 SUBKEY_R(5) = subR[4] ^ subR[6];
493 SUBKEY_L(6) = subL[5] ^ subL[7]; /* round 5 */
494 SUBKEY_R(6) = subR[5] ^ subR[7];
495 tl = subL[10] ^ (subR[10] & ~subR[8]);
496 dw = tl & subL[8], /* FL(kl1) */
497 tr = subR[10] ^ ROL1(dw);
498 SUBKEY_L(7) = subL[6] ^ tl; /* round 6 */
499 SUBKEY_R(7) = subR[6] ^ tr;
500 SUBKEY_L(8) = subL[8]; /* FL(kl1) */
501 SUBKEY_R(8) = subR[8];
502 SUBKEY_L(9) = subL[9]; /* FLinv(kl2) */
503 SUBKEY_R(9) = subR[9];
504 tl = subL[7] ^ (subR[7] & ~subR[9]);
505 dw = tl & subL[9], /* FLinv(kl2) */
506 tr = subR[7] ^ ROL1(dw);
507 SUBKEY_L(10) = tl ^ subL[11]; /* round 7 */
508 SUBKEY_R(10) = tr ^ subR[11];
509 SUBKEY_L(11) = subL[10] ^ subL[12]; /* round 8 */
510 SUBKEY_R(11) = subR[10] ^ subR[12];
511 SUBKEY_L(12) = subL[11] ^ subL[13]; /* round 9 */
512 SUBKEY_R(12) = subR[11] ^ subR[13];
513 SUBKEY_L(13) = subL[12] ^ subL[14]; /* round 10 */
514 SUBKEY_R(13) = subR[12] ^ subR[14];
515 SUBKEY_L(14) = subL[13] ^ subL[15]; /* round 11 */
516 SUBKEY_R(14) = subR[13] ^ subR[15];
517 tl = subL[18] ^ (subR[18] & ~subR[16]);
518 dw = tl & subL[16], /* FL(kl3) */
519 tr = subR[18] ^ ROL1(dw);
520 SUBKEY_L(15) = subL[14] ^ tl; /* round 12 */
521 SUBKEY_R(15) = subR[14] ^ tr;
522 SUBKEY_L(16) = subL[16]; /* FL(kl3) */
523 SUBKEY_R(16) = subR[16];
524 SUBKEY_L(17) = subL[17]; /* FLinv(kl4) */
525 SUBKEY_R(17) = subR[17];
526 tl = subL[15] ^ (subR[15] & ~subR[17]);
527 dw = tl & subL[17], /* FLinv(kl4) */
528 tr = subR[15] ^ ROL1(dw);
529 SUBKEY_L(18) = tl ^ subL[19]; /* round 13 */
530 SUBKEY_R(18) = tr ^ subR[19];
531 SUBKEY_L(19) = subL[18] ^ subL[20]; /* round 14 */
532 SUBKEY_R(19) = subR[18] ^ subR[20];
533 SUBKEY_L(20) = subL[19] ^ subL[21]; /* round 15 */
534 SUBKEY_R(20) = subR[19] ^ subR[21];
535 SUBKEY_L(21) = subL[20] ^ subL[22]; /* round 16 */
536 SUBKEY_R(21) = subR[20] ^ subR[22];
537 SUBKEY_L(22) = subL[21] ^ subL[23]; /* round 17 */
538 SUBKEY_R(22) = subR[21] ^ subR[23];
539 if (max == 24) {
540 SUBKEY_L(23) = subL[22]; /* round 18 */
541 SUBKEY_R(23) = subR[22];
542 SUBKEY_L(24) = subL[24] ^ subL[23]; /* kw3 */
543 SUBKEY_R(24) = subR[24] ^ subR[23];
544 } else {
545 tl = subL[26] ^ (subR[26] & ~subR[24]);
546 dw = tl & subL[24], /* FL(kl5) */
547 tr = subR[26] ^ ROL1(dw);
548 SUBKEY_L(23) = subL[22] ^ tl; /* round 18 */
549 SUBKEY_R(23) = subR[22] ^ tr;
550 SUBKEY_L(24) = subL[24]; /* FL(kl5) */
551 SUBKEY_R(24) = subR[24];
552 SUBKEY_L(25) = subL[25]; /* FLinv(kl6) */
553 SUBKEY_R(25) = subR[25];
554 tl = subL[23] ^ (subR[23] & ~subR[25]);
555 dw = tl & subL[25], /* FLinv(kl6) */
556 tr = subR[23] ^ ROL1(dw);
557 SUBKEY_L(26) = tl ^ subL[27]; /* round 19 */
558 SUBKEY_R(26) = tr ^ subR[27];
559 SUBKEY_L(27) = subL[26] ^ subL[28]; /* round 20 */
560 SUBKEY_R(27) = subR[26] ^ subR[28];
561 SUBKEY_L(28) = subL[27] ^ subL[29]; /* round 21 */
562 SUBKEY_R(28) = subR[27] ^ subR[29];
563 SUBKEY_L(29) = subL[28] ^ subL[30]; /* round 22 */
564 SUBKEY_R(29) = subR[28] ^ subR[30];
565 SUBKEY_L(30) = subL[29] ^ subL[31]; /* round 23 */
566 SUBKEY_R(30) = subR[29] ^ subR[31];
567 SUBKEY_L(31) = subL[30]; /* round 24 */
568 SUBKEY_R(31) = subR[30];
569 SUBKEY_L(32) = subL[32] ^ subL[31]; /* kw3 */
570 SUBKEY_R(32) = subR[32] ^ subR[31];
571 }
572
573 /* apply the inverse of the last half of P-function */
574 i = 2;
575 do {
576 dw = SUBKEY_L(i + 0) ^ SUBKEY_R(i + 0); dw = ROL8(dw);/* round 1 */
577 SUBKEY_R(i + 0) = SUBKEY_L(i + 0) ^ dw; SUBKEY_L(i + 0) = dw;
578 dw = SUBKEY_L(i + 1) ^ SUBKEY_R(i + 1); dw = ROL8(dw);/* round 2 */
579 SUBKEY_R(i + 1) = SUBKEY_L(i + 1) ^ dw; SUBKEY_L(i + 1) = dw;
580 dw = SUBKEY_L(i + 2) ^ SUBKEY_R(i + 2); dw = ROL8(dw);/* round 3 */
581 SUBKEY_R(i + 2) = SUBKEY_L(i + 2) ^ dw; SUBKEY_L(i + 2) = dw;
582 dw = SUBKEY_L(i + 3) ^ SUBKEY_R(i + 3); dw = ROL8(dw);/* round 4 */
583 SUBKEY_R(i + 3) = SUBKEY_L(i + 3) ^ dw; SUBKEY_L(i + 3) = dw;
584 dw = SUBKEY_L(i + 4) ^ SUBKEY_R(i + 4); dw = ROL8(dw);/* round 5 */
585 SUBKEY_R(i + 4) = SUBKEY_L(i + 4) ^ dw; SUBKEY_L(i + 4) = dw;
586 dw = SUBKEY_L(i + 5) ^ SUBKEY_R(i + 5); dw = ROL8(dw);/* round 6 */
587 SUBKEY_R(i + 5) = SUBKEY_L(i + 5) ^ dw; SUBKEY_L(i + 5) = dw;
588 i += 8;
589 } while (i < max);
590}
478 591
479static void camellia_setup128(const unsigned char *key, u32 *subkey) 592static void camellia_setup128(const unsigned char *key, u32 *subkey)
480{ 593{
481 u32 kll, klr, krl, krr; 594 u32 kll, klr, krl, krr;
482 u32 il, ir, t0, t1, w0, w1; 595 u32 il, ir, t0, t1, w0, w1;
483 u32 kw4l, kw4r, dw, tl, tr;
484 u32 subL[26]; 596 u32 subL[26];
485 u32 subR[26]; 597 u32 subR[26];
486 598
487 /** 599 /**
488 * k == kll || klr || krl || krr (|| is concatination) 600 * k == kll || klr || krl || krr (|| is concatenation)
489 */
490 kll = GETU32(key );
491 klr = GETU32(key + 4);
492 krl = GETU32(key + 8);
493 krr = GETU32(key + 12);
494 /**
495 * generate KL dependent subkeys
496 */ 601 */
602 GETU32(kll, key );
603 GETU32(klr, key + 4);
604 GETU32(krl, key + 8);
605 GETU32(krr, key + 12);
606
607 /* generate KL dependent subkeys */
497 /* kw1 */ 608 /* kw1 */
498 SUBL(0) = kll; SUBR(0) = klr; 609 subL[0] = kll; subR[0] = klr;
499 /* kw2 */ 610 /* kw2 */
500 SUBL(1) = krl; SUBR(1) = krr; 611 subL[1] = krl; subR[1] = krr;
501 /* rotation left shift 15bit */ 612 /* rotation left shift 15bit */
502 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 613 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
503 /* k3 */ 614 /* k3 */
504 SUBL(4) = kll; SUBR(4) = klr; 615 subL[4] = kll; subR[4] = klr;
505 /* k4 */ 616 /* k4 */
506 SUBL(5) = krl; SUBR(5) = krr; 617 subL[5] = krl; subR[5] = krr;
507 /* rotation left shift 15+30bit */ 618 /* rotation left shift 15+30bit */
508 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30); 619 ROLDQ(kll, klr, krl, krr, w0, w1, 30);
509 /* k7 */ 620 /* k7 */
510 SUBL(10) = kll; SUBR(10) = klr; 621 subL[10] = kll; subR[10] = klr;
511 /* k8 */ 622 /* k8 */
512 SUBL(11) = krl; SUBR(11) = krr; 623 subL[11] = krl; subR[11] = krr;
513 /* rotation left shift 15+30+15bit */ 624 /* rotation left shift 15+30+15bit */
514 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 625 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
515 /* k10 */ 626 /* k10 */
516 SUBL(13) = krl; SUBR(13) = krr; 627 subL[13] = krl; subR[13] = krr;
517 /* rotation left shift 15+30+15+17 bit */ 628 /* rotation left shift 15+30+15+17 bit */
518 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17); 629 ROLDQ(kll, klr, krl, krr, w0, w1, 17);
519 /* kl3 */ 630 /* kl3 */
520 SUBL(16) = kll; SUBR(16) = klr; 631 subL[16] = kll; subR[16] = klr;
521 /* kl4 */ 632 /* kl4 */
522 SUBL(17) = krl; SUBR(17) = krr; 633 subL[17] = krl; subR[17] = krr;
523 /* rotation left shift 15+30+15+17+17 bit */ 634 /* rotation left shift 15+30+15+17+17 bit */
524 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17); 635 ROLDQ(kll, klr, krl, krr, w0, w1, 17);
525 /* k13 */ 636 /* k13 */
526 SUBL(18) = kll; SUBR(18) = klr; 637 subL[18] = kll; subR[18] = klr;
527 /* k14 */ 638 /* k14 */
528 SUBL(19) = krl; SUBR(19) = krr; 639 subL[19] = krl; subR[19] = krr;
529 /* rotation left shift 15+30+15+17+17+17 bit */ 640 /* rotation left shift 15+30+15+17+17+17 bit */
530 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17); 641 ROLDQ(kll, klr, krl, krr, w0, w1, 17);
531 /* k17 */ 642 /* k17 */
532 SUBL(22) = kll; SUBR(22) = klr; 643 subL[22] = kll; subR[22] = klr;
533 /* k18 */ 644 /* k18 */
534 SUBL(23) = krl; SUBR(23) = krr; 645 subL[23] = krl; subR[23] = krr;
535 646
536 /* generate KA */ 647 /* generate KA */
537 kll = SUBL(0); klr = SUBR(0); 648 kll = subL[0]; klr = subR[0];
538 krl = SUBL(1); krr = SUBR(1); 649 krl = subL[1]; krr = subR[1];
539 CAMELLIA_F(kll, klr, 650 CAMELLIA_F(kll, klr,
540 CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R, 651 CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
541 w0, w1, il, ir, t0, t1); 652 w0, w1, il, ir, t0, t1);
@@ -555,306 +666,108 @@ static void camellia_setup128(const unsigned char *key, u32 *subkey)
555 666
556 /* generate KA dependent subkeys */ 667 /* generate KA dependent subkeys */
557 /* k1, k2 */ 668 /* k1, k2 */
558 SUBL(2) = kll; SUBR(2) = klr; 669 subL[2] = kll; subR[2] = klr;
559 SUBL(3) = krl; SUBR(3) = krr; 670 subL[3] = krl; subR[3] = krr;
560 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 671 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
561 /* k5,k6 */ 672 /* k5,k6 */
562 SUBL(6) = kll; SUBR(6) = klr; 673 subL[6] = kll; subR[6] = klr;
563 SUBL(7) = krl; SUBR(7) = krr; 674 subL[7] = krl; subR[7] = krr;
564 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 675 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
565 /* kl1, kl2 */ 676 /* kl1, kl2 */
566 SUBL(8) = kll; SUBR(8) = klr; 677 subL[8] = kll; subR[8] = klr;
567 SUBL(9) = krl; SUBR(9) = krr; 678 subL[9] = krl; subR[9] = krr;
568 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 679 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
569 /* k9 */ 680 /* k9 */
570 SUBL(12) = kll; SUBR(12) = klr; 681 subL[12] = kll; subR[12] = klr;
571 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 682 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
572 /* k11, k12 */ 683 /* k11, k12 */
573 SUBL(14) = kll; SUBR(14) = klr; 684 subL[14] = kll; subR[14] = klr;
574 SUBL(15) = krl; SUBR(15) = krr; 685 subL[15] = krl; subR[15] = krr;
575 CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34); 686 ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
576 /* k15, k16 */ 687 /* k15, k16 */
577 SUBL(20) = kll; SUBR(20) = klr; 688 subL[20] = kll; subR[20] = klr;
578 SUBL(21) = krl; SUBR(21) = krr; 689 subL[21] = krl; subR[21] = krr;
579 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17); 690 ROLDQ(kll, klr, krl, krr, w0, w1, 17);
580 /* kw3, kw4 */ 691 /* kw3, kw4 */
581 SUBL(24) = kll; SUBR(24) = klr; 692 subL[24] = kll; subR[24] = klr;
582 SUBL(25) = krl; SUBR(25) = krr; 693 subL[25] = krl; subR[25] = krr;
583 694
584 695 camellia_setup_tail(subkey, subL, subR, 24);
585 /* absorb kw2 to other subkeys */
586 /* round 2 */
587 SUBL(3) ^= SUBL(1); SUBR(3) ^= SUBR(1);
588 /* round 4 */
589 SUBL(5) ^= SUBL(1); SUBR(5) ^= SUBR(1);
590 /* round 6 */
591 SUBL(7) ^= SUBL(1); SUBR(7) ^= SUBR(1);
592 SUBL(1) ^= SUBR(1) & ~SUBR(9);
593 dw = SUBL(1) & SUBL(9),
594 SUBR(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl2) */
595 /* round 8 */
596 SUBL(11) ^= SUBL(1); SUBR(11) ^= SUBR(1);
597 /* round 10 */
598 SUBL(13) ^= SUBL(1); SUBR(13) ^= SUBR(1);
599 /* round 12 */
600 SUBL(15) ^= SUBL(1); SUBR(15) ^= SUBR(1);
601 SUBL(1) ^= SUBR(1) & ~SUBR(17);
602 dw = SUBL(1) & SUBL(17),
603 SUBR(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl4) */
604 /* round 14 */
605 SUBL(19) ^= SUBL(1); SUBR(19) ^= SUBR(1);
606 /* round 16 */
607 SUBL(21) ^= SUBL(1); SUBR(21) ^= SUBR(1);
608 /* round 18 */
609 SUBL(23) ^= SUBL(1); SUBR(23) ^= SUBR(1);
610 /* kw3 */
611 SUBL(24) ^= SUBL(1); SUBR(24) ^= SUBR(1);
612
613 /* absorb kw4 to other subkeys */
614 kw4l = SUBL(25); kw4r = SUBR(25);
615 /* round 17 */
616 SUBL(22) ^= kw4l; SUBR(22) ^= kw4r;
617 /* round 15 */
618 SUBL(20) ^= kw4l; SUBR(20) ^= kw4r;
619 /* round 13 */
620 SUBL(18) ^= kw4l; SUBR(18) ^= kw4r;
621 kw4l ^= kw4r & ~SUBR(16);
622 dw = kw4l & SUBL(16),
623 kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl3) */
624 /* round 11 */
625 SUBL(14) ^= kw4l; SUBR(14) ^= kw4r;
626 /* round 9 */
627 SUBL(12) ^= kw4l; SUBR(12) ^= kw4r;
628 /* round 7 */
629 SUBL(10) ^= kw4l; SUBR(10) ^= kw4r;
630 kw4l ^= kw4r & ~SUBR(8);
631 dw = kw4l & SUBL(8),
632 kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl1) */
633 /* round 5 */
634 SUBL(6) ^= kw4l; SUBR(6) ^= kw4r;
635 /* round 3 */
636 SUBL(4) ^= kw4l; SUBR(4) ^= kw4r;
637 /* round 1 */
638 SUBL(2) ^= kw4l; SUBR(2) ^= kw4r;
639 /* kw1 */
640 SUBL(0) ^= kw4l; SUBR(0) ^= kw4r;
641
642
643 /* key XOR is end of F-function */
644 CAMELLIA_SUBKEY_L(0) = SUBL(0) ^ SUBL(2);/* kw1 */
645 CAMELLIA_SUBKEY_R(0) = SUBR(0) ^ SUBR(2);
646 CAMELLIA_SUBKEY_L(2) = SUBL(3); /* round 1 */
647 CAMELLIA_SUBKEY_R(2) = SUBR(3);
648 CAMELLIA_SUBKEY_L(3) = SUBL(2) ^ SUBL(4); /* round 2 */
649 CAMELLIA_SUBKEY_R(3) = SUBR(2) ^ SUBR(4);
650 CAMELLIA_SUBKEY_L(4) = SUBL(3) ^ SUBL(5); /* round 3 */
651 CAMELLIA_SUBKEY_R(4) = SUBR(3) ^ SUBR(5);
652 CAMELLIA_SUBKEY_L(5) = SUBL(4) ^ SUBL(6); /* round 4 */
653 CAMELLIA_SUBKEY_R(5) = SUBR(4) ^ SUBR(6);
654 CAMELLIA_SUBKEY_L(6) = SUBL(5) ^ SUBL(7); /* round 5 */
655 CAMELLIA_SUBKEY_R(6) = SUBR(5) ^ SUBR(7);
656 tl = SUBL(10) ^ (SUBR(10) & ~SUBR(8));
657 dw = tl & SUBL(8), /* FL(kl1) */
658 tr = SUBR(10) ^ CAMELLIA_RL1(dw);
659 CAMELLIA_SUBKEY_L(7) = SUBL(6) ^ tl; /* round 6 */
660 CAMELLIA_SUBKEY_R(7) = SUBR(6) ^ tr;
661 CAMELLIA_SUBKEY_L(8) = SUBL(8); /* FL(kl1) */
662 CAMELLIA_SUBKEY_R(8) = SUBR(8);
663 CAMELLIA_SUBKEY_L(9) = SUBL(9); /* FLinv(kl2) */
664 CAMELLIA_SUBKEY_R(9) = SUBR(9);
665 tl = SUBL(7) ^ (SUBR(7) & ~SUBR(9));
666 dw = tl & SUBL(9), /* FLinv(kl2) */
667 tr = SUBR(7) ^ CAMELLIA_RL1(dw);
668 CAMELLIA_SUBKEY_L(10) = tl ^ SUBL(11); /* round 7 */
669 CAMELLIA_SUBKEY_R(10) = tr ^ SUBR(11);
670 CAMELLIA_SUBKEY_L(11) = SUBL(10) ^ SUBL(12); /* round 8 */
671 CAMELLIA_SUBKEY_R(11) = SUBR(10) ^ SUBR(12);
672 CAMELLIA_SUBKEY_L(12) = SUBL(11) ^ SUBL(13); /* round 9 */
673 CAMELLIA_SUBKEY_R(12) = SUBR(11) ^ SUBR(13);
674 CAMELLIA_SUBKEY_L(13) = SUBL(12) ^ SUBL(14); /* round 10 */
675 CAMELLIA_SUBKEY_R(13) = SUBR(12) ^ SUBR(14);
676 CAMELLIA_SUBKEY_L(14) = SUBL(13) ^ SUBL(15); /* round 11 */
677 CAMELLIA_SUBKEY_R(14) = SUBR(13) ^ SUBR(15);
678 tl = SUBL(18) ^ (SUBR(18) & ~SUBR(16));
679 dw = tl & SUBL(16), /* FL(kl3) */
680 tr = SUBR(18) ^ CAMELLIA_RL1(dw);
681 CAMELLIA_SUBKEY_L(15) = SUBL(14) ^ tl; /* round 12 */
682 CAMELLIA_SUBKEY_R(15) = SUBR(14) ^ tr;
683 CAMELLIA_SUBKEY_L(16) = SUBL(16); /* FL(kl3) */
684 CAMELLIA_SUBKEY_R(16) = SUBR(16);
685 CAMELLIA_SUBKEY_L(17) = SUBL(17); /* FLinv(kl4) */
686 CAMELLIA_SUBKEY_R(17) = SUBR(17);
687 tl = SUBL(15) ^ (SUBR(15) & ~SUBR(17));
688 dw = tl & SUBL(17), /* FLinv(kl4) */
689 tr = SUBR(15) ^ CAMELLIA_RL1(dw);
690 CAMELLIA_SUBKEY_L(18) = tl ^ SUBL(19); /* round 13 */
691 CAMELLIA_SUBKEY_R(18) = tr ^ SUBR(19);
692 CAMELLIA_SUBKEY_L(19) = SUBL(18) ^ SUBL(20); /* round 14 */
693 CAMELLIA_SUBKEY_R(19) = SUBR(18) ^ SUBR(20);
694 CAMELLIA_SUBKEY_L(20) = SUBL(19) ^ SUBL(21); /* round 15 */
695 CAMELLIA_SUBKEY_R(20) = SUBR(19) ^ SUBR(21);
696 CAMELLIA_SUBKEY_L(21) = SUBL(20) ^ SUBL(22); /* round 16 */
697 CAMELLIA_SUBKEY_R(21) = SUBR(20) ^ SUBR(22);
698 CAMELLIA_SUBKEY_L(22) = SUBL(21) ^ SUBL(23); /* round 17 */
699 CAMELLIA_SUBKEY_R(22) = SUBR(21) ^ SUBR(23);
700 CAMELLIA_SUBKEY_L(23) = SUBL(22); /* round 18 */
701 CAMELLIA_SUBKEY_R(23) = SUBR(22);
702 CAMELLIA_SUBKEY_L(24) = SUBL(24) ^ SUBL(23); /* kw3 */
703 CAMELLIA_SUBKEY_R(24) = SUBR(24) ^ SUBR(23);
704
705 /* apply the inverse of the last half of P-function */
706 dw = CAMELLIA_SUBKEY_L(2) ^ CAMELLIA_SUBKEY_R(2),
707 dw = CAMELLIA_RL8(dw);/* round 1 */
708 CAMELLIA_SUBKEY_R(2) = CAMELLIA_SUBKEY_L(2) ^ dw,
709 CAMELLIA_SUBKEY_L(2) = dw;
710 dw = CAMELLIA_SUBKEY_L(3) ^ CAMELLIA_SUBKEY_R(3),
711 dw = CAMELLIA_RL8(dw);/* round 2 */
712 CAMELLIA_SUBKEY_R(3) = CAMELLIA_SUBKEY_L(3) ^ dw,
713 CAMELLIA_SUBKEY_L(3) = dw;
714 dw = CAMELLIA_SUBKEY_L(4) ^ CAMELLIA_SUBKEY_R(4),
715 dw = CAMELLIA_RL8(dw);/* round 3 */
716 CAMELLIA_SUBKEY_R(4) = CAMELLIA_SUBKEY_L(4) ^ dw,
717 CAMELLIA_SUBKEY_L(4) = dw;
718 dw = CAMELLIA_SUBKEY_L(5) ^ CAMELLIA_SUBKEY_R(5),
719 dw = CAMELLIA_RL8(dw);/* round 4 */
720 CAMELLIA_SUBKEY_R(5) = CAMELLIA_SUBKEY_L(5) ^ dw,
721 CAMELLIA_SUBKEY_L(5) = dw;
722 dw = CAMELLIA_SUBKEY_L(6) ^ CAMELLIA_SUBKEY_R(6),
723 dw = CAMELLIA_RL8(dw);/* round 5 */
724 CAMELLIA_SUBKEY_R(6) = CAMELLIA_SUBKEY_L(6) ^ dw,
725 CAMELLIA_SUBKEY_L(6) = dw;
726 dw = CAMELLIA_SUBKEY_L(7) ^ CAMELLIA_SUBKEY_R(7),
727 dw = CAMELLIA_RL8(dw);/* round 6 */
728 CAMELLIA_SUBKEY_R(7) = CAMELLIA_SUBKEY_L(7) ^ dw,
729 CAMELLIA_SUBKEY_L(7) = dw;
730 dw = CAMELLIA_SUBKEY_L(10) ^ CAMELLIA_SUBKEY_R(10),
731 dw = CAMELLIA_RL8(dw);/* round 7 */
732 CAMELLIA_SUBKEY_R(10) = CAMELLIA_SUBKEY_L(10) ^ dw,
733 CAMELLIA_SUBKEY_L(10) = dw;
734 dw = CAMELLIA_SUBKEY_L(11) ^ CAMELLIA_SUBKEY_R(11),
735 dw = CAMELLIA_RL8(dw);/* round 8 */
736 CAMELLIA_SUBKEY_R(11) = CAMELLIA_SUBKEY_L(11) ^ dw,
737 CAMELLIA_SUBKEY_L(11) = dw;
738 dw = CAMELLIA_SUBKEY_L(12) ^ CAMELLIA_SUBKEY_R(12),
739 dw = CAMELLIA_RL8(dw);/* round 9 */
740 CAMELLIA_SUBKEY_R(12) = CAMELLIA_SUBKEY_L(12) ^ dw,
741 CAMELLIA_SUBKEY_L(12) = dw;
742 dw = CAMELLIA_SUBKEY_L(13) ^ CAMELLIA_SUBKEY_R(13),
743 dw = CAMELLIA_RL8(dw);/* round 10 */
744 CAMELLIA_SUBKEY_R(13) = CAMELLIA_SUBKEY_L(13) ^ dw,
745 CAMELLIA_SUBKEY_L(13) = dw;
746 dw = CAMELLIA_SUBKEY_L(14) ^ CAMELLIA_SUBKEY_R(14),
747 dw = CAMELLIA_RL8(dw);/* round 11 */
748 CAMELLIA_SUBKEY_R(14) = CAMELLIA_SUBKEY_L(14) ^ dw,
749 CAMELLIA_SUBKEY_L(14) = dw;
750 dw = CAMELLIA_SUBKEY_L(15) ^ CAMELLIA_SUBKEY_R(15),
751 dw = CAMELLIA_RL8(dw);/* round 12 */
752 CAMELLIA_SUBKEY_R(15) = CAMELLIA_SUBKEY_L(15) ^ dw,
753 CAMELLIA_SUBKEY_L(15) = dw;
754 dw = CAMELLIA_SUBKEY_L(18) ^ CAMELLIA_SUBKEY_R(18),
755 dw = CAMELLIA_RL8(dw);/* round 13 */
756 CAMELLIA_SUBKEY_R(18) = CAMELLIA_SUBKEY_L(18) ^ dw,
757 CAMELLIA_SUBKEY_L(18) = dw;
758 dw = CAMELLIA_SUBKEY_L(19) ^ CAMELLIA_SUBKEY_R(19),
759 dw = CAMELLIA_RL8(dw);/* round 14 */
760 CAMELLIA_SUBKEY_R(19) = CAMELLIA_SUBKEY_L(19) ^ dw,
761 CAMELLIA_SUBKEY_L(19) = dw;
762 dw = CAMELLIA_SUBKEY_L(20) ^ CAMELLIA_SUBKEY_R(20),
763 dw = CAMELLIA_RL8(dw);/* round 15 */
764 CAMELLIA_SUBKEY_R(20) = CAMELLIA_SUBKEY_L(20) ^ dw,
765 CAMELLIA_SUBKEY_L(20) = dw;
766 dw = CAMELLIA_SUBKEY_L(21) ^ CAMELLIA_SUBKEY_R(21),
767 dw = CAMELLIA_RL8(dw);/* round 16 */
768 CAMELLIA_SUBKEY_R(21) = CAMELLIA_SUBKEY_L(21) ^ dw,
769 CAMELLIA_SUBKEY_L(21) = dw;
770 dw = CAMELLIA_SUBKEY_L(22) ^ CAMELLIA_SUBKEY_R(22),
771 dw = CAMELLIA_RL8(dw);/* round 17 */
772 CAMELLIA_SUBKEY_R(22) = CAMELLIA_SUBKEY_L(22) ^ dw,
773 CAMELLIA_SUBKEY_L(22) = dw;
774 dw = CAMELLIA_SUBKEY_L(23) ^ CAMELLIA_SUBKEY_R(23),
775 dw = CAMELLIA_RL8(dw);/* round 18 */
776 CAMELLIA_SUBKEY_R(23) = CAMELLIA_SUBKEY_L(23) ^ dw,
777 CAMELLIA_SUBKEY_L(23) = dw;
778
779 return;
780} 696}
781 697
782
783static void camellia_setup256(const unsigned char *key, u32 *subkey) 698static void camellia_setup256(const unsigned char *key, u32 *subkey)
784{ 699{
785 u32 kll,klr,krl,krr; /* left half of key */ 700 u32 kll, klr, krl, krr; /* left half of key */
786 u32 krll,krlr,krrl,krrr; /* right half of key */ 701 u32 krll, krlr, krrl, krrr; /* right half of key */
787 u32 il, ir, t0, t1, w0, w1; /* temporary variables */ 702 u32 il, ir, t0, t1, w0, w1; /* temporary variables */
788 u32 kw4l, kw4r, dw, tl, tr;
789 u32 subL[34]; 703 u32 subL[34];
790 u32 subR[34]; 704 u32 subR[34];
791 705
792 /** 706 /**
793 * key = (kll || klr || krl || krr || krll || krlr || krrl || krrr) 707 * key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
794 * (|| is concatination) 708 * (|| is concatenation)
795 */ 709 */
796 710 GETU32(kll, key );
797 kll = GETU32(key ); 711 GETU32(klr, key + 4);
798 klr = GETU32(key + 4); 712 GETU32(krl, key + 8);
799 krl = GETU32(key + 8); 713 GETU32(krr, key + 12);
800 krr = GETU32(key + 12); 714 GETU32(krll, key + 16);
801 krll = GETU32(key + 16); 715 GETU32(krlr, key + 20);
802 krlr = GETU32(key + 20); 716 GETU32(krrl, key + 24);
803 krrl = GETU32(key + 24); 717 GETU32(krrr, key + 28);
804 krrr = GETU32(key + 28);
805 718
806 /* generate KL dependent subkeys */ 719 /* generate KL dependent subkeys */
807 /* kw1 */ 720 /* kw1 */
808 SUBL(0) = kll; SUBR(0) = klr; 721 subL[0] = kll; subR[0] = klr;
809 /* kw2 */ 722 /* kw2 */
810 SUBL(1) = krl; SUBR(1) = krr; 723 subL[1] = krl; subR[1] = krr;
811 CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 45); 724 ROLDQo32(kll, klr, krl, krr, w0, w1, 45);
812 /* k9 */ 725 /* k9 */
813 SUBL(12) = kll; SUBR(12) = klr; 726 subL[12] = kll; subR[12] = klr;
814 /* k10 */ 727 /* k10 */
815 SUBL(13) = krl; SUBR(13) = krr; 728 subL[13] = krl; subR[13] = krr;
816 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 729 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
817 /* kl3 */ 730 /* kl3 */
818 SUBL(16) = kll; SUBR(16) = klr; 731 subL[16] = kll; subR[16] = klr;
819 /* kl4 */ 732 /* kl4 */
820 SUBL(17) = krl; SUBR(17) = krr; 733 subL[17] = krl; subR[17] = krr;
821 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17); 734 ROLDQ(kll, klr, krl, krr, w0, w1, 17);
822 /* k17 */ 735 /* k17 */
823 SUBL(22) = kll; SUBR(22) = klr; 736 subL[22] = kll; subR[22] = klr;
824 /* k18 */ 737 /* k18 */
825 SUBL(23) = krl; SUBR(23) = krr; 738 subL[23] = krl; subR[23] = krr;
826 CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34); 739 ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
827 /* k23 */ 740 /* k23 */
828 SUBL(30) = kll; SUBR(30) = klr; 741 subL[30] = kll; subR[30] = klr;
829 /* k24 */ 742 /* k24 */
830 SUBL(31) = krl; SUBR(31) = krr; 743 subL[31] = krl; subR[31] = krr;
831 744
832 /* generate KR dependent subkeys */ 745 /* generate KR dependent subkeys */
833 CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15); 746 ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
834 /* k3 */ 747 /* k3 */
835 SUBL(4) = krll; SUBR(4) = krlr; 748 subL[4] = krll; subR[4] = krlr;
836 /* k4 */ 749 /* k4 */
837 SUBL(5) = krrl; SUBR(5) = krrr; 750 subL[5] = krrl; subR[5] = krrr;
838 CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15); 751 ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
839 /* kl1 */ 752 /* kl1 */
840 SUBL(8) = krll; SUBR(8) = krlr; 753 subL[8] = krll; subR[8] = krlr;
841 /* kl2 */ 754 /* kl2 */
842 SUBL(9) = krrl; SUBR(9) = krrr; 755 subL[9] = krrl; subR[9] = krrr;
843 CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30); 756 ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
844 /* k13 */ 757 /* k13 */
845 SUBL(18) = krll; SUBR(18) = krlr; 758 subL[18] = krll; subR[18] = krlr;
846 /* k14 */ 759 /* k14 */
847 SUBL(19) = krrl; SUBR(19) = krrr; 760 subL[19] = krrl; subR[19] = krrr;
848 CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34); 761 ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
849 /* k19 */ 762 /* k19 */
850 SUBL(26) = krll; SUBR(26) = krlr; 763 subL[26] = krll; subR[26] = krlr;
851 /* k20 */ 764 /* k20 */
852 SUBL(27) = krrl; SUBR(27) = krrr; 765 subL[27] = krrl; subR[27] = krrr;
853 CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34); 766 ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
854 767
855 /* generate KA */ 768 /* generate KA */
856 kll = SUBL(0) ^ krll; klr = SUBR(0) ^ krlr; 769 kll = subL[0] ^ krll; klr = subR[0] ^ krlr;
857 krl = SUBL(1) ^ krrl; krr = SUBR(1) ^ krrr; 770 krl = subL[1] ^ krrl; krr = subR[1] ^ krrr;
858 CAMELLIA_F(kll, klr, 771 CAMELLIA_F(kll, klr,
859 CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R, 772 CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
860 w0, w1, il, ir, t0, t1); 773 w0, w1, il, ir, t0, t1);
@@ -885,310 +798,50 @@ static void camellia_setup256(const unsigned char *key, u32 *subkey)
885 krll ^= w0; krlr ^= w1; 798 krll ^= w0; krlr ^= w1;
886 799
887 /* generate KA dependent subkeys */ 800 /* generate KA dependent subkeys */
888 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15); 801 ROLDQ(kll, klr, krl, krr, w0, w1, 15);
889 /* k5 */ 802 /* k5 */
890 SUBL(6) = kll; SUBR(6) = klr; 803 subL[6] = kll; subR[6] = klr;
891 /* k6 */ 804 /* k6 */
892 SUBL(7) = krl; SUBR(7) = krr; 805 subL[7] = krl; subR[7] = krr;
893 CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30); 806 ROLDQ(kll, klr, krl, krr, w0, w1, 30);
894 /* k11 */ 807 /* k11 */
895 SUBL(14) = kll; SUBR(14) = klr; 808 subL[14] = kll; subR[14] = klr;
896 /* k12 */ 809 /* k12 */
897 SUBL(15) = krl; SUBR(15) = krr; 810 subL[15] = krl; subR[15] = krr;
898 /* rotation left shift 32bit */ 811 /* rotation left shift 32bit */
899 /* kl5 */ 812 /* kl5 */
900 SUBL(24) = klr; SUBR(24) = krl; 813 subL[24] = klr; subR[24] = krl;
901 /* kl6 */ 814 /* kl6 */
902 SUBL(25) = krr; SUBR(25) = kll; 815 subL[25] = krr; subR[25] = kll;
903 /* rotation left shift 49 from k11,k12 -> k21,k22 */ 816 /* rotation left shift 49 from k11,k12 -> k21,k22 */
904 CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 49); 817 ROLDQo32(kll, klr, krl, krr, w0, w1, 49);
905 /* k21 */ 818 /* k21 */
906 SUBL(28) = kll; SUBR(28) = klr; 819 subL[28] = kll; subR[28] = klr;
907 /* k22 */ 820 /* k22 */
908 SUBL(29) = krl; SUBR(29) = krr; 821 subL[29] = krl; subR[29] = krr;
909 822
910 /* generate KB dependent subkeys */ 823 /* generate KB dependent subkeys */
911 /* k1 */ 824 /* k1 */
912 SUBL(2) = krll; SUBR(2) = krlr; 825 subL[2] = krll; subR[2] = krlr;
913 /* k2 */ 826 /* k2 */
914 SUBL(3) = krrl; SUBR(3) = krrr; 827 subL[3] = krrl; subR[3] = krrr;
915 CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30); 828 ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
916 /* k7 */ 829 /* k7 */
917 SUBL(10) = krll; SUBR(10) = krlr; 830 subL[10] = krll; subR[10] = krlr;
918 /* k8 */ 831 /* k8 */
919 SUBL(11) = krrl; SUBR(11) = krrr; 832 subL[11] = krrl; subR[11] = krrr;
920 CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30); 833 ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
921 /* k15 */ 834 /* k15 */
922 SUBL(20) = krll; SUBR(20) = krlr; 835 subL[20] = krll; subR[20] = krlr;
923 /* k16 */ 836 /* k16 */
924 SUBL(21) = krrl; SUBR(21) = krrr; 837 subL[21] = krrl; subR[21] = krrr;
925 CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 51); 838 ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 51);
926 /* kw3 */ 839 /* kw3 */
927 SUBL(32) = krll; SUBR(32) = krlr; 840 subL[32] = krll; subR[32] = krlr;
928 /* kw4 */ 841 /* kw4 */
929 SUBL(33) = krrl; SUBR(33) = krrr; 842 subL[33] = krrl; subR[33] = krrr;
930
931 /* absorb kw2 to other subkeys */
932 /* round 2 */
933 SUBL(3) ^= SUBL(1); SUBR(3) ^= SUBR(1);
934 /* round 4 */
935 SUBL(5) ^= SUBL(1); SUBR(5) ^= SUBR(1);
936 /* round 6 */
937 SUBL(7) ^= SUBL(1); SUBR(7) ^= SUBR(1);
938 SUBL(1) ^= SUBR(1) & ~SUBR(9);
939 dw = SUBL(1) & SUBL(9),
940 SUBR(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl2) */
941 /* round 8 */
942 SUBL(11) ^= SUBL(1); SUBR(11) ^= SUBR(1);
943 /* round 10 */
944 SUBL(13) ^= SUBL(1); SUBR(13) ^= SUBR(1);
945 /* round 12 */
946 SUBL(15) ^= SUBL(1); SUBR(15) ^= SUBR(1);
947 SUBL(1) ^= SUBR(1) & ~SUBR(17);
948 dw = SUBL(1) & SUBL(17),
949 SUBR(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl4) */
950 /* round 14 */
951 SUBL(19) ^= SUBL(1); SUBR(19) ^= SUBR(1);
952 /* round 16 */
953 SUBL(21) ^= SUBL(1); SUBR(21) ^= SUBR(1);
954 /* round 18 */
955 SUBL(23) ^= SUBL(1); SUBR(23) ^= SUBR(1);
956 SUBL(1) ^= SUBR(1) & ~SUBR(25);
957 dw = SUBL(1) & SUBL(25),
958 SUBR(1) ^= CAMELLIA_RL1(dw); /* modified for FLinv(kl6) */
959 /* round 20 */
960 SUBL(27) ^= SUBL(1); SUBR(27) ^= SUBR(1);
961 /* round 22 */
962 SUBL(29) ^= SUBL(1); SUBR(29) ^= SUBR(1);
963 /* round 24 */
964 SUBL(31) ^= SUBL(1); SUBR(31) ^= SUBR(1);
965 /* kw3 */
966 SUBL(32) ^= SUBL(1); SUBR(32) ^= SUBR(1);
967
968
969 /* absorb kw4 to other subkeys */
970 kw4l = SUBL(33); kw4r = SUBR(33);
971 /* round 23 */
972 SUBL(30) ^= kw4l; SUBR(30) ^= kw4r;
973 /* round 21 */
974 SUBL(28) ^= kw4l; SUBR(28) ^= kw4r;
975 /* round 19 */
976 SUBL(26) ^= kw4l; SUBR(26) ^= kw4r;
977 kw4l ^= kw4r & ~SUBR(24);
978 dw = kw4l & SUBL(24),
979 kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl5) */
980 /* round 17 */
981 SUBL(22) ^= kw4l; SUBR(22) ^= kw4r;
982 /* round 15 */
983 SUBL(20) ^= kw4l; SUBR(20) ^= kw4r;
984 /* round 13 */
985 SUBL(18) ^= kw4l; SUBR(18) ^= kw4r;
986 kw4l ^= kw4r & ~SUBR(16);
987 dw = kw4l & SUBL(16),
988 kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl3) */
989 /* round 11 */
990 SUBL(14) ^= kw4l; SUBR(14) ^= kw4r;
991 /* round 9 */
992 SUBL(12) ^= kw4l; SUBR(12) ^= kw4r;
993 /* round 7 */
994 SUBL(10) ^= kw4l; SUBR(10) ^= kw4r;
995 kw4l ^= kw4r & ~SUBR(8);
996 dw = kw4l & SUBL(8),
997 kw4r ^= CAMELLIA_RL1(dw); /* modified for FL(kl1) */
998 /* round 5 */
999 SUBL(6) ^= kw4l; SUBR(6) ^= kw4r;
1000 /* round 3 */
1001 SUBL(4) ^= kw4l; SUBR(4) ^= kw4r;
1002 /* round 1 */
1003 SUBL(2) ^= kw4l; SUBR(2) ^= kw4r;
1004 /* kw1 */
1005 SUBL(0) ^= kw4l; SUBR(0) ^= kw4r;
1006 843
1007 /* key XOR is end of F-function */ 844 camellia_setup_tail(subkey, subL, subR, 32);
1008 CAMELLIA_SUBKEY_L(0) = SUBL(0) ^ SUBL(2);/* kw1 */
1009 CAMELLIA_SUBKEY_R(0) = SUBR(0) ^ SUBR(2);
1010 CAMELLIA_SUBKEY_L(2) = SUBL(3); /* round 1 */
1011 CAMELLIA_SUBKEY_R(2) = SUBR(3);
1012 CAMELLIA_SUBKEY_L(3) = SUBL(2) ^ SUBL(4); /* round 2 */
1013 CAMELLIA_SUBKEY_R(3) = SUBR(2) ^ SUBR(4);
1014 CAMELLIA_SUBKEY_L(4) = SUBL(3) ^ SUBL(5); /* round 3 */
1015 CAMELLIA_SUBKEY_R(4) = SUBR(3) ^ SUBR(5);
1016 CAMELLIA_SUBKEY_L(5) = SUBL(4) ^ SUBL(6); /* round 4 */
1017 CAMELLIA_SUBKEY_R(5) = SUBR(4) ^ SUBR(6);
1018 CAMELLIA_SUBKEY_L(6) = SUBL(5) ^ SUBL(7); /* round 5 */
1019 CAMELLIA_SUBKEY_R(6) = SUBR(5) ^ SUBR(7);
1020 tl = SUBL(10) ^ (SUBR(10) & ~SUBR(8));
1021 dw = tl & SUBL(8), /* FL(kl1) */
1022 tr = SUBR(10) ^ CAMELLIA_RL1(dw);
1023 CAMELLIA_SUBKEY_L(7) = SUBL(6) ^ tl; /* round 6 */
1024 CAMELLIA_SUBKEY_R(7) = SUBR(6) ^ tr;
1025 CAMELLIA_SUBKEY_L(8) = SUBL(8); /* FL(kl1) */
1026 CAMELLIA_SUBKEY_R(8) = SUBR(8);
1027 CAMELLIA_SUBKEY_L(9) = SUBL(9); /* FLinv(kl2) */
1028 CAMELLIA_SUBKEY_R(9) = SUBR(9);
1029 tl = SUBL(7) ^ (SUBR(7) & ~SUBR(9));
1030 dw = tl & SUBL(9), /* FLinv(kl2) */
1031 tr = SUBR(7) ^ CAMELLIA_RL1(dw);
1032 CAMELLIA_SUBKEY_L(10) = tl ^ SUBL(11); /* round 7 */
1033 CAMELLIA_SUBKEY_R(10) = tr ^ SUBR(11);
1034 CAMELLIA_SUBKEY_L(11) = SUBL(10) ^ SUBL(12); /* round 8 */
1035 CAMELLIA_SUBKEY_R(11) = SUBR(10) ^ SUBR(12);
1036 CAMELLIA_SUBKEY_L(12) = SUBL(11) ^ SUBL(13); /* round 9 */
1037 CAMELLIA_SUBKEY_R(12) = SUBR(11) ^ SUBR(13);
1038 CAMELLIA_SUBKEY_L(13) = SUBL(12) ^ SUBL(14); /* round 10 */
1039 CAMELLIA_SUBKEY_R(13) = SUBR(12) ^ SUBR(14);
1040 CAMELLIA_SUBKEY_L(14) = SUBL(13) ^ SUBL(15); /* round 11 */
1041 CAMELLIA_SUBKEY_R(14) = SUBR(13) ^ SUBR(15);
1042 tl = SUBL(18) ^ (SUBR(18) & ~SUBR(16));
1043 dw = tl & SUBL(16), /* FL(kl3) */
1044 tr = SUBR(18) ^ CAMELLIA_RL1(dw);
1045 CAMELLIA_SUBKEY_L(15) = SUBL(14) ^ tl; /* round 12 */
1046 CAMELLIA_SUBKEY_R(15) = SUBR(14) ^ tr;
1047 CAMELLIA_SUBKEY_L(16) = SUBL(16); /* FL(kl3) */
1048 CAMELLIA_SUBKEY_R(16) = SUBR(16);
1049 CAMELLIA_SUBKEY_L(17) = SUBL(17); /* FLinv(kl4) */
1050 CAMELLIA_SUBKEY_R(17) = SUBR(17);
1051 tl = SUBL(15) ^ (SUBR(15) & ~SUBR(17));
1052 dw = tl & SUBL(17), /* FLinv(kl4) */
1053 tr = SUBR(15) ^ CAMELLIA_RL1(dw);
1054 CAMELLIA_SUBKEY_L(18) = tl ^ SUBL(19); /* round 13 */
1055 CAMELLIA_SUBKEY_R(18) = tr ^ SUBR(19);
1056 CAMELLIA_SUBKEY_L(19) = SUBL(18) ^ SUBL(20); /* round 14 */
1057 CAMELLIA_SUBKEY_R(19) = SUBR(18) ^ SUBR(20);
1058 CAMELLIA_SUBKEY_L(20) = SUBL(19) ^ SUBL(21); /* round 15 */
1059 CAMELLIA_SUBKEY_R(20) = SUBR(19) ^ SUBR(21);
1060 CAMELLIA_SUBKEY_L(21) = SUBL(20) ^ SUBL(22); /* round 16 */
1061 CAMELLIA_SUBKEY_R(21) = SUBR(20) ^ SUBR(22);
1062 CAMELLIA_SUBKEY_L(22) = SUBL(21) ^ SUBL(23); /* round 17 */
1063 CAMELLIA_SUBKEY_R(22) = SUBR(21) ^ SUBR(23);
1064 tl = SUBL(26) ^ (SUBR(26)
1065 & ~SUBR(24));
1066 dw = tl & SUBL(24), /* FL(kl5) */
1067 tr = SUBR(26) ^ CAMELLIA_RL1(dw);
1068 CAMELLIA_SUBKEY_L(23) = SUBL(22) ^ tl; /* round 18 */
1069 CAMELLIA_SUBKEY_R(23) = SUBR(22) ^ tr;
1070 CAMELLIA_SUBKEY_L(24) = SUBL(24); /* FL(kl5) */
1071 CAMELLIA_SUBKEY_R(24) = SUBR(24);
1072 CAMELLIA_SUBKEY_L(25) = SUBL(25); /* FLinv(kl6) */
1073 CAMELLIA_SUBKEY_R(25) = SUBR(25);
1074 tl = SUBL(23) ^ (SUBR(23) &
1075 ~SUBR(25));
1076 dw = tl & SUBL(25), /* FLinv(kl6) */
1077 tr = SUBR(23) ^ CAMELLIA_RL1(dw);
1078 CAMELLIA_SUBKEY_L(26) = tl ^ SUBL(27); /* round 19 */
1079 CAMELLIA_SUBKEY_R(26) = tr ^ SUBR(27);
1080 CAMELLIA_SUBKEY_L(27) = SUBL(26) ^ SUBL(28); /* round 20 */
1081 CAMELLIA_SUBKEY_R(27) = SUBR(26) ^ SUBR(28);
1082 CAMELLIA_SUBKEY_L(28) = SUBL(27) ^ SUBL(29); /* round 21 */
1083 CAMELLIA_SUBKEY_R(28) = SUBR(27) ^ SUBR(29);
1084 CAMELLIA_SUBKEY_L(29) = SUBL(28) ^ SUBL(30); /* round 22 */
1085 CAMELLIA_SUBKEY_R(29) = SUBR(28) ^ SUBR(30);
1086 CAMELLIA_SUBKEY_L(30) = SUBL(29) ^ SUBL(31); /* round 23 */
1087 CAMELLIA_SUBKEY_R(30) = SUBR(29) ^ SUBR(31);
1088 CAMELLIA_SUBKEY_L(31) = SUBL(30); /* round 24 */
1089 CAMELLIA_SUBKEY_R(31) = SUBR(30);
1090 CAMELLIA_SUBKEY_L(32) = SUBL(32) ^ SUBL(31); /* kw3 */
1091 CAMELLIA_SUBKEY_R(32) = SUBR(32) ^ SUBR(31);
1092
1093 /* apply the inverse of the last half of P-function */
1094 dw = CAMELLIA_SUBKEY_L(2) ^ CAMELLIA_SUBKEY_R(2),
1095 dw = CAMELLIA_RL8(dw);/* round 1 */
1096 CAMELLIA_SUBKEY_R(2) = CAMELLIA_SUBKEY_L(2) ^ dw,
1097 CAMELLIA_SUBKEY_L(2) = dw;
1098 dw = CAMELLIA_SUBKEY_L(3) ^ CAMELLIA_SUBKEY_R(3),
1099 dw = CAMELLIA_RL8(dw);/* round 2 */
1100 CAMELLIA_SUBKEY_R(3) = CAMELLIA_SUBKEY_L(3) ^ dw,
1101 CAMELLIA_SUBKEY_L(3) = dw;
1102 dw = CAMELLIA_SUBKEY_L(4) ^ CAMELLIA_SUBKEY_R(4),
1103 dw = CAMELLIA_RL8(dw);/* round 3 */
1104 CAMELLIA_SUBKEY_R(4) = CAMELLIA_SUBKEY_L(4) ^ dw,
1105 CAMELLIA_SUBKEY_L(4) = dw;
1106 dw = CAMELLIA_SUBKEY_L(5) ^ CAMELLIA_SUBKEY_R(5),
1107 dw = CAMELLIA_RL8(dw);/* round 4 */
1108 CAMELLIA_SUBKEY_R(5) = CAMELLIA_SUBKEY_L(5) ^ dw,
1109 CAMELLIA_SUBKEY_L(5) = dw;
1110 dw = CAMELLIA_SUBKEY_L(6) ^ CAMELLIA_SUBKEY_R(6),
1111 dw = CAMELLIA_RL8(dw);/* round 5 */
1112 CAMELLIA_SUBKEY_R(6) = CAMELLIA_SUBKEY_L(6) ^ dw,
1113 CAMELLIA_SUBKEY_L(6) = dw;
1114 dw = CAMELLIA_SUBKEY_L(7) ^ CAMELLIA_SUBKEY_R(7),
1115 dw = CAMELLIA_RL8(dw);/* round 6 */
1116 CAMELLIA_SUBKEY_R(7) = CAMELLIA_SUBKEY_L(7) ^ dw,
1117 CAMELLIA_SUBKEY_L(7) = dw;
1118 dw = CAMELLIA_SUBKEY_L(10) ^ CAMELLIA_SUBKEY_R(10),
1119 dw = CAMELLIA_RL8(dw);/* round 7 */
1120 CAMELLIA_SUBKEY_R(10) = CAMELLIA_SUBKEY_L(10) ^ dw,
1121 CAMELLIA_SUBKEY_L(10) = dw;
1122 dw = CAMELLIA_SUBKEY_L(11) ^ CAMELLIA_SUBKEY_R(11),
1123 dw = CAMELLIA_RL8(dw);/* round 8 */
1124 CAMELLIA_SUBKEY_R(11) = CAMELLIA_SUBKEY_L(11) ^ dw,
1125 CAMELLIA_SUBKEY_L(11) = dw;
1126 dw = CAMELLIA_SUBKEY_L(12) ^ CAMELLIA_SUBKEY_R(12),
1127 dw = CAMELLIA_RL8(dw);/* round 9 */
1128 CAMELLIA_SUBKEY_R(12) = CAMELLIA_SUBKEY_L(12) ^ dw,
1129 CAMELLIA_SUBKEY_L(12) = dw;
1130 dw = CAMELLIA_SUBKEY_L(13) ^ CAMELLIA_SUBKEY_R(13),
1131 dw = CAMELLIA_RL8(dw);/* round 10 */
1132 CAMELLIA_SUBKEY_R(13) = CAMELLIA_SUBKEY_L(13) ^ dw,
1133 CAMELLIA_SUBKEY_L(13) = dw;
1134 dw = CAMELLIA_SUBKEY_L(14) ^ CAMELLIA_SUBKEY_R(14),
1135 dw = CAMELLIA_RL8(dw);/* round 11 */
1136 CAMELLIA_SUBKEY_R(14) = CAMELLIA_SUBKEY_L(14) ^ dw,
1137 CAMELLIA_SUBKEY_L(14) = dw;
1138 dw = CAMELLIA_SUBKEY_L(15) ^ CAMELLIA_SUBKEY_R(15),
1139 dw = CAMELLIA_RL8(dw);/* round 12 */
1140 CAMELLIA_SUBKEY_R(15) = CAMELLIA_SUBKEY_L(15) ^ dw,
1141 CAMELLIA_SUBKEY_L(15) = dw;
1142 dw = CAMELLIA_SUBKEY_L(18) ^ CAMELLIA_SUBKEY_R(18),
1143 dw = CAMELLIA_RL8(dw);/* round 13 */
1144 CAMELLIA_SUBKEY_R(18) = CAMELLIA_SUBKEY_L(18) ^ dw,
1145 CAMELLIA_SUBKEY_L(18) = dw;
1146 dw = CAMELLIA_SUBKEY_L(19) ^ CAMELLIA_SUBKEY_R(19),
1147 dw = CAMELLIA_RL8(dw);/* round 14 */
1148 CAMELLIA_SUBKEY_R(19) = CAMELLIA_SUBKEY_L(19) ^ dw,
1149 CAMELLIA_SUBKEY_L(19) = dw;
1150 dw = CAMELLIA_SUBKEY_L(20) ^ CAMELLIA_SUBKEY_R(20),
1151 dw = CAMELLIA_RL8(dw);/* round 15 */
1152 CAMELLIA_SUBKEY_R(20) = CAMELLIA_SUBKEY_L(20) ^ dw,
1153 CAMELLIA_SUBKEY_L(20) = dw;
1154 dw = CAMELLIA_SUBKEY_L(21) ^ CAMELLIA_SUBKEY_R(21),
1155 dw = CAMELLIA_RL8(dw);/* round 16 */
1156 CAMELLIA_SUBKEY_R(21) = CAMELLIA_SUBKEY_L(21) ^ dw,
1157 CAMELLIA_SUBKEY_L(21) = dw;
1158 dw = CAMELLIA_SUBKEY_L(22) ^ CAMELLIA_SUBKEY_R(22),
1159 dw = CAMELLIA_RL8(dw);/* round 17 */
1160 CAMELLIA_SUBKEY_R(22) = CAMELLIA_SUBKEY_L(22) ^ dw,
1161 CAMELLIA_SUBKEY_L(22) = dw;
1162 dw = CAMELLIA_SUBKEY_L(23) ^ CAMELLIA_SUBKEY_R(23),
1163 dw = CAMELLIA_RL8(dw);/* round 18 */
1164 CAMELLIA_SUBKEY_R(23) = CAMELLIA_SUBKEY_L(23) ^ dw,
1165 CAMELLIA_SUBKEY_L(23) = dw;
1166 dw = CAMELLIA_SUBKEY_L(26) ^ CAMELLIA_SUBKEY_R(26),
1167 dw = CAMELLIA_RL8(dw);/* round 19 */
1168 CAMELLIA_SUBKEY_R(26) = CAMELLIA_SUBKEY_L(26) ^ dw,
1169 CAMELLIA_SUBKEY_L(26) = dw;
1170 dw = CAMELLIA_SUBKEY_L(27) ^ CAMELLIA_SUBKEY_R(27),
1171 dw = CAMELLIA_RL8(dw);/* round 20 */
1172 CAMELLIA_SUBKEY_R(27) = CAMELLIA_SUBKEY_L(27) ^ dw,
1173 CAMELLIA_SUBKEY_L(27) = dw;
1174 dw = CAMELLIA_SUBKEY_L(28) ^ CAMELLIA_SUBKEY_R(28),
1175 dw = CAMELLIA_RL8(dw);/* round 21 */
1176 CAMELLIA_SUBKEY_R(28) = CAMELLIA_SUBKEY_L(28) ^ dw,
1177 CAMELLIA_SUBKEY_L(28) = dw;
1178 dw = CAMELLIA_SUBKEY_L(29) ^ CAMELLIA_SUBKEY_R(29),
1179 dw = CAMELLIA_RL8(dw);/* round 22 */
1180 CAMELLIA_SUBKEY_R(29) = CAMELLIA_SUBKEY_L(29) ^ dw,
1181 CAMELLIA_SUBKEY_L(29) = dw;
1182 dw = CAMELLIA_SUBKEY_L(30) ^ CAMELLIA_SUBKEY_R(30),
1183 dw = CAMELLIA_RL8(dw);/* round 23 */
1184 CAMELLIA_SUBKEY_R(30) = CAMELLIA_SUBKEY_L(30) ^ dw,
1185 CAMELLIA_SUBKEY_L(30) = dw;
1186 dw = CAMELLIA_SUBKEY_L(31) ^ CAMELLIA_SUBKEY_R(31),
1187 dw = CAMELLIA_RL8(dw);/* round 24 */
1188 CAMELLIA_SUBKEY_R(31) = CAMELLIA_SUBKEY_L(31) ^ dw,
1189 CAMELLIA_SUBKEY_L(31) = dw;
1190
1191 return;
1192} 845}
1193 846
1194static void camellia_setup192(const unsigned char *key, u32 *subkey) 847static void camellia_setup192(const unsigned char *key, u32 *subkey)
@@ -1197,482 +850,168 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey)
1197 u32 krll, krlr, krrl,krrr; 850 u32 krll, krlr, krrl,krrr;
1198 851
1199 memcpy(kk, key, 24); 852 memcpy(kk, key, 24);
1200 memcpy((unsigned char *)&krll, key+16,4); 853 memcpy((unsigned char *)&krll, key+16, 4);
1201 memcpy((unsigned char *)&krlr, key+20,4); 854 memcpy((unsigned char *)&krlr, key+20, 4);
1202 krrl = ~krll; 855 krrl = ~krll;
1203 krrr = ~krlr; 856 krrr = ~krlr;
1204 memcpy(kk+24, (unsigned char *)&krrl, 4); 857 memcpy(kk+24, (unsigned char *)&krrl, 4);
1205 memcpy(kk+28, (unsigned char *)&krrr, 4); 858 memcpy(kk+28, (unsigned char *)&krrr, 4);
1206 camellia_setup256(kk, subkey); 859 camellia_setup256(kk, subkey);
1207 return;
1208} 860}
1209 861
1210 862
1211/** 863/*
1212 * Stuff related to camellia encryption/decryption 864 * Encrypt/decrypt
1213 */ 865 */
1214static void camellia_encrypt128(const u32 *subkey, __be32 *io_text) 866#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
1215{ 867 do { \
1216 u32 il,ir,t0,t1; /* temporary valiables */ 868 t0 = kll; \
1217 869 t2 = krr; \
1218 u32 io[4]; 870 t0 &= ll; \
1219 871 t2 |= rr; \
1220 io[0] = be32_to_cpu(io_text[0]); 872 rl ^= t2; \
1221 io[1] = be32_to_cpu(io_text[1]); 873 lr ^= ROL1(t0); \
1222 io[2] = be32_to_cpu(io_text[2]); 874 t3 = krl; \
1223 io[3] = be32_to_cpu(io_text[3]); 875 t1 = klr; \
1224 876 t3 &= rl; \
1225 /* pre whitening but absorb kw2*/ 877 t1 |= lr; \
1226 io[0] ^= CAMELLIA_SUBKEY_L(0); 878 ll ^= t1; \
1227 io[1] ^= CAMELLIA_SUBKEY_R(0); 879 rr ^= ROL1(t3); \
1228 /* main iteration */ 880 } while(0)
1229
1230 CAMELLIA_ROUNDSM(io[0],io[1],
1231 CAMELLIA_SUBKEY_L(2),CAMELLIA_SUBKEY_R(2),
1232 io[2],io[3],il,ir,t0,t1);
1233 CAMELLIA_ROUNDSM(io[2],io[3],
1234 CAMELLIA_SUBKEY_L(3),CAMELLIA_SUBKEY_R(3),
1235 io[0],io[1],il,ir,t0,t1);
1236 CAMELLIA_ROUNDSM(io[0],io[1],
1237 CAMELLIA_SUBKEY_L(4),CAMELLIA_SUBKEY_R(4),
1238 io[2],io[3],il,ir,t0,t1);
1239 CAMELLIA_ROUNDSM(io[2],io[3],
1240 CAMELLIA_SUBKEY_L(5),CAMELLIA_SUBKEY_R(5),
1241 io[0],io[1],il,ir,t0,t1);
1242 CAMELLIA_ROUNDSM(io[0],io[1],
1243 CAMELLIA_SUBKEY_L(6),CAMELLIA_SUBKEY_R(6),
1244 io[2],io[3],il,ir,t0,t1);
1245 CAMELLIA_ROUNDSM(io[2],io[3],
1246 CAMELLIA_SUBKEY_L(7),CAMELLIA_SUBKEY_R(7),
1247 io[0],io[1],il,ir,t0,t1);
1248
1249 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1250 CAMELLIA_SUBKEY_L(8),CAMELLIA_SUBKEY_R(8),
1251 CAMELLIA_SUBKEY_L(9),CAMELLIA_SUBKEY_R(9),
1252 t0,t1,il,ir);
1253
1254 CAMELLIA_ROUNDSM(io[0],io[1],
1255 CAMELLIA_SUBKEY_L(10),CAMELLIA_SUBKEY_R(10),
1256 io[2],io[3],il,ir,t0,t1);
1257 CAMELLIA_ROUNDSM(io[2],io[3],
1258 CAMELLIA_SUBKEY_L(11),CAMELLIA_SUBKEY_R(11),
1259 io[0],io[1],il,ir,t0,t1);
1260 CAMELLIA_ROUNDSM(io[0],io[1],
1261 CAMELLIA_SUBKEY_L(12),CAMELLIA_SUBKEY_R(12),
1262 io[2],io[3],il,ir,t0,t1);
1263 CAMELLIA_ROUNDSM(io[2],io[3],
1264 CAMELLIA_SUBKEY_L(13),CAMELLIA_SUBKEY_R(13),
1265 io[0],io[1],il,ir,t0,t1);
1266 CAMELLIA_ROUNDSM(io[0],io[1],
1267 CAMELLIA_SUBKEY_L(14),CAMELLIA_SUBKEY_R(14),
1268 io[2],io[3],il,ir,t0,t1);
1269 CAMELLIA_ROUNDSM(io[2],io[3],
1270 CAMELLIA_SUBKEY_L(15),CAMELLIA_SUBKEY_R(15),
1271 io[0],io[1],il,ir,t0,t1);
1272
1273 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1274 CAMELLIA_SUBKEY_L(16),CAMELLIA_SUBKEY_R(16),
1275 CAMELLIA_SUBKEY_L(17),CAMELLIA_SUBKEY_R(17),
1276 t0,t1,il,ir);
1277
1278 CAMELLIA_ROUNDSM(io[0],io[1],
1279 CAMELLIA_SUBKEY_L(18),CAMELLIA_SUBKEY_R(18),
1280 io[2],io[3],il,ir,t0,t1);
1281 CAMELLIA_ROUNDSM(io[2],io[3],
1282 CAMELLIA_SUBKEY_L(19),CAMELLIA_SUBKEY_R(19),
1283 io[0],io[1],il,ir,t0,t1);
1284 CAMELLIA_ROUNDSM(io[0],io[1],
1285 CAMELLIA_SUBKEY_L(20),CAMELLIA_SUBKEY_R(20),
1286 io[2],io[3],il,ir,t0,t1);
1287 CAMELLIA_ROUNDSM(io[2],io[3],
1288 CAMELLIA_SUBKEY_L(21),CAMELLIA_SUBKEY_R(21),
1289 io[0],io[1],il,ir,t0,t1);
1290 CAMELLIA_ROUNDSM(io[0],io[1],
1291 CAMELLIA_SUBKEY_L(22),CAMELLIA_SUBKEY_R(22),
1292 io[2],io[3],il,ir,t0,t1);
1293 CAMELLIA_ROUNDSM(io[2],io[3],
1294 CAMELLIA_SUBKEY_L(23),CAMELLIA_SUBKEY_R(23),
1295 io[0],io[1],il,ir,t0,t1);
1296 881
1297 /* post whitening but kw4 */ 882#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir) \
1298 io[2] ^= CAMELLIA_SUBKEY_L(24); 883 do { \
1299 io[3] ^= CAMELLIA_SUBKEY_R(24); 884 ir = camellia_sp1110[(u8)xr]; \
1300 885 il = camellia_sp1110[ (xl >> 24)]; \
1301 t0 = io[0]; 886 ir ^= camellia_sp0222[ (xr >> 24)]; \
1302 t1 = io[1]; 887 il ^= camellia_sp0222[(u8)(xl >> 16)]; \
1303 io[0] = io[2]; 888 ir ^= camellia_sp3033[(u8)(xr >> 16)]; \
1304 io[1] = io[3]; 889 il ^= camellia_sp3033[(u8)(xl >> 8)]; \
1305 io[2] = t0; 890 ir ^= camellia_sp4404[(u8)(xr >> 8)]; \
1306 io[3] = t1; 891 il ^= camellia_sp4404[(u8)xl]; \
1307 892 il ^= kl; \
1308 io_text[0] = cpu_to_be32(io[0]); 893 ir ^= il ^ kr; \
1309 io_text[1] = cpu_to_be32(io[1]); 894 yl ^= ir; \
1310 io_text[2] = cpu_to_be32(io[2]); 895 yr ^= ROR8(il) ^ ir; \
1311 io_text[3] = cpu_to_be32(io[3]); 896 } while(0)
1312
1313 return;
1314}
1315 897
1316static void camellia_decrypt128(const u32 *subkey, __be32 *io_text) 898/* max = 24: 128bit encrypt, max = 32: 256bit encrypt */
899static void camellia_do_encrypt(const u32 *subkey, u32 *io, unsigned max)
1317{ 900{
1318 u32 il,ir,t0,t1; /* temporary valiables */ 901 u32 il,ir,t0,t1; /* temporary variables */
1319 902
1320 u32 io[4]; 903 /* pre whitening but absorb kw2 */
1321 904 io[0] ^= SUBKEY_L(0);
1322 io[0] = be32_to_cpu(io_text[0]); 905 io[1] ^= SUBKEY_R(0);
1323 io[1] = be32_to_cpu(io_text[1]);
1324 io[2] = be32_to_cpu(io_text[2]);
1325 io[3] = be32_to_cpu(io_text[3]);
1326
1327 /* pre whitening but absorb kw2*/
1328 io[0] ^= CAMELLIA_SUBKEY_L(24);
1329 io[1] ^= CAMELLIA_SUBKEY_R(24);
1330 906
1331 /* main iteration */ 907 /* main iteration */
1332 CAMELLIA_ROUNDSM(io[0],io[1], 908#define ROUNDS(i) do { \
1333 CAMELLIA_SUBKEY_L(23),CAMELLIA_SUBKEY_R(23), 909 CAMELLIA_ROUNDSM(io[0],io[1], \
1334 io[2],io[3],il,ir,t0,t1); 910 SUBKEY_L(i + 2),SUBKEY_R(i + 2), \
1335 CAMELLIA_ROUNDSM(io[2],io[3], 911 io[2],io[3],il,ir); \
1336 CAMELLIA_SUBKEY_L(22),CAMELLIA_SUBKEY_R(22), 912 CAMELLIA_ROUNDSM(io[2],io[3], \
1337 io[0],io[1],il,ir,t0,t1); 913 SUBKEY_L(i + 3),SUBKEY_R(i + 3), \
1338 CAMELLIA_ROUNDSM(io[0],io[1], 914 io[0],io[1],il,ir); \
1339 CAMELLIA_SUBKEY_L(21),CAMELLIA_SUBKEY_R(21), 915 CAMELLIA_ROUNDSM(io[0],io[1], \
1340 io[2],io[3],il,ir,t0,t1); 916 SUBKEY_L(i + 4),SUBKEY_R(i + 4), \
1341 CAMELLIA_ROUNDSM(io[2],io[3], 917 io[2],io[3],il,ir); \
1342 CAMELLIA_SUBKEY_L(20),CAMELLIA_SUBKEY_R(20), 918 CAMELLIA_ROUNDSM(io[2],io[3], \
1343 io[0],io[1],il,ir,t0,t1); 919 SUBKEY_L(i + 5),SUBKEY_R(i + 5), \
1344 CAMELLIA_ROUNDSM(io[0],io[1], 920 io[0],io[1],il,ir); \
1345 CAMELLIA_SUBKEY_L(19),CAMELLIA_SUBKEY_R(19), 921 CAMELLIA_ROUNDSM(io[0],io[1], \
1346 io[2],io[3],il,ir,t0,t1); 922 SUBKEY_L(i + 6),SUBKEY_R(i + 6), \
1347 CAMELLIA_ROUNDSM(io[2],io[3], 923 io[2],io[3],il,ir); \
1348 CAMELLIA_SUBKEY_L(18),CAMELLIA_SUBKEY_R(18), 924 CAMELLIA_ROUNDSM(io[2],io[3], \
1349 io[0],io[1],il,ir,t0,t1); 925 SUBKEY_L(i + 7),SUBKEY_R(i + 7), \
1350 926 io[0],io[1],il,ir); \
1351 CAMELLIA_FLS(io[0],io[1],io[2],io[3], 927} while (0)
1352 CAMELLIA_SUBKEY_L(17),CAMELLIA_SUBKEY_R(17), 928#define FLS(i) do { \
1353 CAMELLIA_SUBKEY_L(16),CAMELLIA_SUBKEY_R(16), 929 CAMELLIA_FLS(io[0],io[1],io[2],io[3], \
1354 t0,t1,il,ir); 930 SUBKEY_L(i + 0),SUBKEY_R(i + 0), \
1355 931 SUBKEY_L(i + 1),SUBKEY_R(i + 1), \
1356 CAMELLIA_ROUNDSM(io[0],io[1], 932 t0,t1,il,ir); \
1357 CAMELLIA_SUBKEY_L(15),CAMELLIA_SUBKEY_R(15), 933} while (0)
1358 io[2],io[3],il,ir,t0,t1); 934
1359 CAMELLIA_ROUNDSM(io[2],io[3], 935 ROUNDS(0);
1360 CAMELLIA_SUBKEY_L(14),CAMELLIA_SUBKEY_R(14), 936 FLS(8);
1361 io[0],io[1],il,ir,t0,t1); 937 ROUNDS(8);
1362 CAMELLIA_ROUNDSM(io[0],io[1], 938 FLS(16);
1363 CAMELLIA_SUBKEY_L(13),CAMELLIA_SUBKEY_R(13), 939 ROUNDS(16);
1364 io[2],io[3],il,ir,t0,t1); 940 if (max == 32) {
1365 CAMELLIA_ROUNDSM(io[2],io[3], 941 FLS(24);
1366 CAMELLIA_SUBKEY_L(12),CAMELLIA_SUBKEY_R(12), 942 ROUNDS(24);
1367 io[0],io[1],il,ir,t0,t1); 943 }
1368 CAMELLIA_ROUNDSM(io[0],io[1],
1369 CAMELLIA_SUBKEY_L(11),CAMELLIA_SUBKEY_R(11),
1370 io[2],io[3],il,ir,t0,t1);
1371 CAMELLIA_ROUNDSM(io[2],io[3],
1372 CAMELLIA_SUBKEY_L(10),CAMELLIA_SUBKEY_R(10),
1373 io[0],io[1],il,ir,t0,t1);
1374
1375 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1376 CAMELLIA_SUBKEY_L(9),CAMELLIA_SUBKEY_R(9),
1377 CAMELLIA_SUBKEY_L(8),CAMELLIA_SUBKEY_R(8),
1378 t0,t1,il,ir);
1379
1380 CAMELLIA_ROUNDSM(io[0],io[1],
1381 CAMELLIA_SUBKEY_L(7),CAMELLIA_SUBKEY_R(7),
1382 io[2],io[3],il,ir,t0,t1);
1383 CAMELLIA_ROUNDSM(io[2],io[3],
1384 CAMELLIA_SUBKEY_L(6),CAMELLIA_SUBKEY_R(6),
1385 io[0],io[1],il,ir,t0,t1);
1386 CAMELLIA_ROUNDSM(io[0],io[1],
1387 CAMELLIA_SUBKEY_L(5),CAMELLIA_SUBKEY_R(5),
1388 io[2],io[3],il,ir,t0,t1);
1389 CAMELLIA_ROUNDSM(io[2],io[3],
1390 CAMELLIA_SUBKEY_L(4),CAMELLIA_SUBKEY_R(4),
1391 io[0],io[1],il,ir,t0,t1);
1392 CAMELLIA_ROUNDSM(io[0],io[1],
1393 CAMELLIA_SUBKEY_L(3),CAMELLIA_SUBKEY_R(3),
1394 io[2],io[3],il,ir,t0,t1);
1395 CAMELLIA_ROUNDSM(io[2],io[3],
1396 CAMELLIA_SUBKEY_L(2),CAMELLIA_SUBKEY_R(2),
1397 io[0],io[1],il,ir,t0,t1);
1398
1399 /* post whitening but kw4 */
1400 io[2] ^= CAMELLIA_SUBKEY_L(0);
1401 io[3] ^= CAMELLIA_SUBKEY_R(0);
1402
1403 t0 = io[0];
1404 t1 = io[1];
1405 io[0] = io[2];
1406 io[1] = io[3];
1407 io[2] = t0;
1408 io[3] = t1;
1409
1410 io_text[0] = cpu_to_be32(io[0]);
1411 io_text[1] = cpu_to_be32(io[1]);
1412 io_text[2] = cpu_to_be32(io[2]);
1413 io_text[3] = cpu_to_be32(io[3]);
1414
1415 return;
1416}
1417
1418
1419/**
1420 * stuff for 192 and 256bit encryption/decryption
1421 */
1422static void camellia_encrypt256(const u32 *subkey, __be32 *io_text)
1423{
1424 u32 il,ir,t0,t1; /* temporary valiables */
1425
1426 u32 io[4];
1427
1428 io[0] = be32_to_cpu(io_text[0]);
1429 io[1] = be32_to_cpu(io_text[1]);
1430 io[2] = be32_to_cpu(io_text[2]);
1431 io[3] = be32_to_cpu(io_text[3]);
1432 944
1433 /* pre whitening but absorb kw2*/ 945#undef ROUNDS
1434 io[0] ^= CAMELLIA_SUBKEY_L(0); 946#undef FLS
1435 io[1] ^= CAMELLIA_SUBKEY_R(0);
1436
1437 /* main iteration */
1438 CAMELLIA_ROUNDSM(io[0],io[1],
1439 CAMELLIA_SUBKEY_L(2),CAMELLIA_SUBKEY_R(2),
1440 io[2],io[3],il,ir,t0,t1);
1441 CAMELLIA_ROUNDSM(io[2],io[3],
1442 CAMELLIA_SUBKEY_L(3),CAMELLIA_SUBKEY_R(3),
1443 io[0],io[1],il,ir,t0,t1);
1444 CAMELLIA_ROUNDSM(io[0],io[1],
1445 CAMELLIA_SUBKEY_L(4),CAMELLIA_SUBKEY_R(4),
1446 io[2],io[3],il,ir,t0,t1);
1447 CAMELLIA_ROUNDSM(io[2],io[3],
1448 CAMELLIA_SUBKEY_L(5),CAMELLIA_SUBKEY_R(5),
1449 io[0],io[1],il,ir,t0,t1);
1450 CAMELLIA_ROUNDSM(io[0],io[1],
1451 CAMELLIA_SUBKEY_L(6),CAMELLIA_SUBKEY_R(6),
1452 io[2],io[3],il,ir,t0,t1);
1453 CAMELLIA_ROUNDSM(io[2],io[3],
1454 CAMELLIA_SUBKEY_L(7),CAMELLIA_SUBKEY_R(7),
1455 io[0],io[1],il,ir,t0,t1);
1456
1457 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1458 CAMELLIA_SUBKEY_L(8),CAMELLIA_SUBKEY_R(8),
1459 CAMELLIA_SUBKEY_L(9),CAMELLIA_SUBKEY_R(9),
1460 t0,t1,il,ir);
1461
1462 CAMELLIA_ROUNDSM(io[0],io[1],
1463 CAMELLIA_SUBKEY_L(10),CAMELLIA_SUBKEY_R(10),
1464 io[2],io[3],il,ir,t0,t1);
1465 CAMELLIA_ROUNDSM(io[2],io[3],
1466 CAMELLIA_SUBKEY_L(11),CAMELLIA_SUBKEY_R(11),
1467 io[0],io[1],il,ir,t0,t1);
1468 CAMELLIA_ROUNDSM(io[0],io[1],
1469 CAMELLIA_SUBKEY_L(12),CAMELLIA_SUBKEY_R(12),
1470 io[2],io[3],il,ir,t0,t1);
1471 CAMELLIA_ROUNDSM(io[2],io[3],
1472 CAMELLIA_SUBKEY_L(13),CAMELLIA_SUBKEY_R(13),
1473 io[0],io[1],il,ir,t0,t1);
1474 CAMELLIA_ROUNDSM(io[0],io[1],
1475 CAMELLIA_SUBKEY_L(14),CAMELLIA_SUBKEY_R(14),
1476 io[2],io[3],il,ir,t0,t1);
1477 CAMELLIA_ROUNDSM(io[2],io[3],
1478 CAMELLIA_SUBKEY_L(15),CAMELLIA_SUBKEY_R(15),
1479 io[0],io[1],il,ir,t0,t1);
1480
1481 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1482 CAMELLIA_SUBKEY_L(16),CAMELLIA_SUBKEY_R(16),
1483 CAMELLIA_SUBKEY_L(17),CAMELLIA_SUBKEY_R(17),
1484 t0,t1,il,ir);
1485
1486 CAMELLIA_ROUNDSM(io[0],io[1],
1487 CAMELLIA_SUBKEY_L(18),CAMELLIA_SUBKEY_R(18),
1488 io[2],io[3],il,ir,t0,t1);
1489 CAMELLIA_ROUNDSM(io[2],io[3],
1490 CAMELLIA_SUBKEY_L(19),CAMELLIA_SUBKEY_R(19),
1491 io[0],io[1],il,ir,t0,t1);
1492 CAMELLIA_ROUNDSM(io[0],io[1],
1493 CAMELLIA_SUBKEY_L(20),CAMELLIA_SUBKEY_R(20),
1494 io[2],io[3],il,ir,t0,t1);
1495 CAMELLIA_ROUNDSM(io[2],io[3],
1496 CAMELLIA_SUBKEY_L(21),CAMELLIA_SUBKEY_R(21),
1497 io[0],io[1],il,ir,t0,t1);
1498 CAMELLIA_ROUNDSM(io[0],io[1],
1499 CAMELLIA_SUBKEY_L(22),CAMELLIA_SUBKEY_R(22),
1500 io[2],io[3],il,ir,t0,t1);
1501 CAMELLIA_ROUNDSM(io[2],io[3],
1502 CAMELLIA_SUBKEY_L(23),CAMELLIA_SUBKEY_R(23),
1503 io[0],io[1],il,ir,t0,t1);
1504
1505 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1506 CAMELLIA_SUBKEY_L(24),CAMELLIA_SUBKEY_R(24),
1507 CAMELLIA_SUBKEY_L(25),CAMELLIA_SUBKEY_R(25),
1508 t0,t1,il,ir);
1509
1510 CAMELLIA_ROUNDSM(io[0],io[1],
1511 CAMELLIA_SUBKEY_L(26),CAMELLIA_SUBKEY_R(26),
1512 io[2],io[3],il,ir,t0,t1);
1513 CAMELLIA_ROUNDSM(io[2],io[3],
1514 CAMELLIA_SUBKEY_L(27),CAMELLIA_SUBKEY_R(27),
1515 io[0],io[1],il,ir,t0,t1);
1516 CAMELLIA_ROUNDSM(io[0],io[1],
1517 CAMELLIA_SUBKEY_L(28),CAMELLIA_SUBKEY_R(28),
1518 io[2],io[3],il,ir,t0,t1);
1519 CAMELLIA_ROUNDSM(io[2],io[3],
1520 CAMELLIA_SUBKEY_L(29),CAMELLIA_SUBKEY_R(29),
1521 io[0],io[1],il,ir,t0,t1);
1522 CAMELLIA_ROUNDSM(io[0],io[1],
1523 CAMELLIA_SUBKEY_L(30),CAMELLIA_SUBKEY_R(30),
1524 io[2],io[3],il,ir,t0,t1);
1525 CAMELLIA_ROUNDSM(io[2],io[3],
1526 CAMELLIA_SUBKEY_L(31),CAMELLIA_SUBKEY_R(31),
1527 io[0],io[1],il,ir,t0,t1);
1528 947
1529 /* post whitening but kw4 */ 948 /* post whitening but kw4 */
1530 io[2] ^= CAMELLIA_SUBKEY_L(32); 949 io[2] ^= SUBKEY_L(max);
1531 io[3] ^= CAMELLIA_SUBKEY_R(32); 950 io[3] ^= SUBKEY_R(max);
1532 951 /* NB: io[0],[1] should be swapped with [2],[3] by caller! */
1533 t0 = io[0];
1534 t1 = io[1];
1535 io[0] = io[2];
1536 io[1] = io[3];
1537 io[2] = t0;
1538 io[3] = t1;
1539
1540 io_text[0] = cpu_to_be32(io[0]);
1541 io_text[1] = cpu_to_be32(io[1]);
1542 io_text[2] = cpu_to_be32(io[2]);
1543 io_text[3] = cpu_to_be32(io[3]);
1544
1545 return;
1546} 952}
1547 953
1548 954static void camellia_do_decrypt(const u32 *subkey, u32 *io, unsigned i)
1549static void camellia_decrypt256(const u32 *subkey, __be32 *io_text)
1550{ 955{
1551 u32 il,ir,t0,t1; /* temporary valiables */ 956 u32 il,ir,t0,t1; /* temporary variables */
1552 957
1553 u32 io[4]; 958 /* pre whitening but absorb kw2 */
1554 959 io[0] ^= SUBKEY_L(i);
1555 io[0] = be32_to_cpu(io_text[0]); 960 io[1] ^= SUBKEY_R(i);
1556 io[1] = be32_to_cpu(io_text[1]);
1557 io[2] = be32_to_cpu(io_text[2]);
1558 io[3] = be32_to_cpu(io_text[3]);
1559
1560 /* pre whitening but absorb kw2*/
1561 io[0] ^= CAMELLIA_SUBKEY_L(32);
1562 io[1] ^= CAMELLIA_SUBKEY_R(32);
1563 961
1564 /* main iteration */ 962 /* main iteration */
1565 CAMELLIA_ROUNDSM(io[0],io[1], 963#define ROUNDS(i) do { \
1566 CAMELLIA_SUBKEY_L(31),CAMELLIA_SUBKEY_R(31), 964 CAMELLIA_ROUNDSM(io[0],io[1], \
1567 io[2],io[3],il,ir,t0,t1); 965 SUBKEY_L(i + 7),SUBKEY_R(i + 7), \
1568 CAMELLIA_ROUNDSM(io[2],io[3], 966 io[2],io[3],il,ir); \
1569 CAMELLIA_SUBKEY_L(30),CAMELLIA_SUBKEY_R(30), 967 CAMELLIA_ROUNDSM(io[2],io[3], \
1570 io[0],io[1],il,ir,t0,t1); 968 SUBKEY_L(i + 6),SUBKEY_R(i + 6), \
1571 CAMELLIA_ROUNDSM(io[0],io[1], 969 io[0],io[1],il,ir); \
1572 CAMELLIA_SUBKEY_L(29),CAMELLIA_SUBKEY_R(29), 970 CAMELLIA_ROUNDSM(io[0],io[1], \
1573 io[2],io[3],il,ir,t0,t1); 971 SUBKEY_L(i + 5),SUBKEY_R(i + 5), \
1574 CAMELLIA_ROUNDSM(io[2],io[3], 972 io[2],io[3],il,ir); \
1575 CAMELLIA_SUBKEY_L(28),CAMELLIA_SUBKEY_R(28), 973 CAMELLIA_ROUNDSM(io[2],io[3], \
1576 io[0],io[1],il,ir,t0,t1); 974 SUBKEY_L(i + 4),SUBKEY_R(i + 4), \
1577 CAMELLIA_ROUNDSM(io[0],io[1], 975 io[0],io[1],il,ir); \
1578 CAMELLIA_SUBKEY_L(27),CAMELLIA_SUBKEY_R(27), 976 CAMELLIA_ROUNDSM(io[0],io[1], \
1579 io[2],io[3],il,ir,t0,t1); 977 SUBKEY_L(i + 3),SUBKEY_R(i + 3), \
1580 CAMELLIA_ROUNDSM(io[2],io[3], 978 io[2],io[3],il,ir); \
1581 CAMELLIA_SUBKEY_L(26),CAMELLIA_SUBKEY_R(26), 979 CAMELLIA_ROUNDSM(io[2],io[3], \
1582 io[0],io[1],il,ir,t0,t1); 980 SUBKEY_L(i + 2),SUBKEY_R(i + 2), \
1583 981 io[0],io[1],il,ir); \
1584 CAMELLIA_FLS(io[0],io[1],io[2],io[3], 982} while (0)
1585 CAMELLIA_SUBKEY_L(25),CAMELLIA_SUBKEY_R(25), 983#define FLS(i) do { \
1586 CAMELLIA_SUBKEY_L(24),CAMELLIA_SUBKEY_R(24), 984 CAMELLIA_FLS(io[0],io[1],io[2],io[3], \
1587 t0,t1,il,ir); 985 SUBKEY_L(i + 1),SUBKEY_R(i + 1), \
1588 986 SUBKEY_L(i + 0),SUBKEY_R(i + 0), \
1589 CAMELLIA_ROUNDSM(io[0],io[1], 987 t0,t1,il,ir); \
1590 CAMELLIA_SUBKEY_L(23),CAMELLIA_SUBKEY_R(23), 988} while (0)
1591 io[2],io[3],il,ir,t0,t1); 989
1592 CAMELLIA_ROUNDSM(io[2],io[3], 990 if (i == 32) {
1593 CAMELLIA_SUBKEY_L(22),CAMELLIA_SUBKEY_R(22), 991 ROUNDS(24);
1594 io[0],io[1],il,ir,t0,t1); 992 FLS(24);
1595 CAMELLIA_ROUNDSM(io[0],io[1], 993 }
1596 CAMELLIA_SUBKEY_L(21),CAMELLIA_SUBKEY_R(21), 994 ROUNDS(16);
1597 io[2],io[3],il,ir,t0,t1); 995 FLS(16);
1598 CAMELLIA_ROUNDSM(io[2],io[3], 996 ROUNDS(8);
1599 CAMELLIA_SUBKEY_L(20),CAMELLIA_SUBKEY_R(20), 997 FLS(8);
1600 io[0],io[1],il,ir,t0,t1); 998 ROUNDS(0);
1601 CAMELLIA_ROUNDSM(io[0],io[1], 999
1602 CAMELLIA_SUBKEY_L(19),CAMELLIA_SUBKEY_R(19), 1000#undef ROUNDS
1603 io[2],io[3],il,ir,t0,t1); 1001#undef FLS
1604 CAMELLIA_ROUNDSM(io[2],io[3],
1605 CAMELLIA_SUBKEY_L(18),CAMELLIA_SUBKEY_R(18),
1606 io[0],io[1],il,ir,t0,t1);
1607
1608 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1609 CAMELLIA_SUBKEY_L(17),CAMELLIA_SUBKEY_R(17),
1610 CAMELLIA_SUBKEY_L(16),CAMELLIA_SUBKEY_R(16),
1611 t0,t1,il,ir);
1612
1613 CAMELLIA_ROUNDSM(io[0],io[1],
1614 CAMELLIA_SUBKEY_L(15),CAMELLIA_SUBKEY_R(15),
1615 io[2],io[3],il,ir,t0,t1);
1616 CAMELLIA_ROUNDSM(io[2],io[3],
1617 CAMELLIA_SUBKEY_L(14),CAMELLIA_SUBKEY_R(14),
1618 io[0],io[1],il,ir,t0,t1);
1619 CAMELLIA_ROUNDSM(io[0],io[1],
1620 CAMELLIA_SUBKEY_L(13),CAMELLIA_SUBKEY_R(13),
1621 io[2],io[3],il,ir,t0,t1);
1622 CAMELLIA_ROUNDSM(io[2],io[3],
1623 CAMELLIA_SUBKEY_L(12),CAMELLIA_SUBKEY_R(12),
1624 io[0],io[1],il,ir,t0,t1);
1625 CAMELLIA_ROUNDSM(io[0],io[1],
1626 CAMELLIA_SUBKEY_L(11),CAMELLIA_SUBKEY_R(11),
1627 io[2],io[3],il,ir,t0,t1);
1628 CAMELLIA_ROUNDSM(io[2],io[3],
1629 CAMELLIA_SUBKEY_L(10),CAMELLIA_SUBKEY_R(10),
1630 io[0],io[1],il,ir,t0,t1);
1631
1632 CAMELLIA_FLS(io[0],io[1],io[2],io[3],
1633 CAMELLIA_SUBKEY_L(9),CAMELLIA_SUBKEY_R(9),
1634 CAMELLIA_SUBKEY_L(8),CAMELLIA_SUBKEY_R(8),
1635 t0,t1,il,ir);
1636
1637 CAMELLIA_ROUNDSM(io[0],io[1],
1638 CAMELLIA_SUBKEY_L(7),CAMELLIA_SUBKEY_R(7),
1639 io[2],io[3],il,ir,t0,t1);
1640 CAMELLIA_ROUNDSM(io[2],io[3],
1641 CAMELLIA_SUBKEY_L(6),CAMELLIA_SUBKEY_R(6),
1642 io[0],io[1],il,ir,t0,t1);
1643 CAMELLIA_ROUNDSM(io[0],io[1],
1644 CAMELLIA_SUBKEY_L(5),CAMELLIA_SUBKEY_R(5),
1645 io[2],io[3],il,ir,t0,t1);
1646 CAMELLIA_ROUNDSM(io[2],io[3],
1647 CAMELLIA_SUBKEY_L(4),CAMELLIA_SUBKEY_R(4),
1648 io[0],io[1],il,ir,t0,t1);
1649 CAMELLIA_ROUNDSM(io[0],io[1],
1650 CAMELLIA_SUBKEY_L(3),CAMELLIA_SUBKEY_R(3),
1651 io[2],io[3],il,ir,t0,t1);
1652 CAMELLIA_ROUNDSM(io[2],io[3],
1653 CAMELLIA_SUBKEY_L(2),CAMELLIA_SUBKEY_R(2),
1654 io[0],io[1],il,ir,t0,t1);
1655 1002
1656 /* post whitening but kw4 */ 1003 /* post whitening but kw4 */
1657 io[2] ^= CAMELLIA_SUBKEY_L(0); 1004 io[2] ^= SUBKEY_L(0);
1658 io[3] ^= CAMELLIA_SUBKEY_R(0); 1005 io[3] ^= SUBKEY_R(0);
1659 1006 /* NB: 0,1 should be swapped with 2,3 by caller! */
1660 t0 = io[0];
1661 t1 = io[1];
1662 io[0] = io[2];
1663 io[1] = io[3];
1664 io[2] = t0;
1665 io[3] = t1;
1666
1667 io_text[0] = cpu_to_be32(io[0]);
1668 io_text[1] = cpu_to_be32(io[1]);
1669 io_text[2] = cpu_to_be32(io[2]);
1670 io_text[3] = cpu_to_be32(io[3]);
1671
1672 return;
1673} 1007}
1674 1008
1675 1009
1010struct camellia_ctx {
1011 int key_length;
1012 u32 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u32)];
1013};
1014
1676static int 1015static int
1677camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key, 1016camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1678 unsigned int key_len) 1017 unsigned int key_len)
@@ -1688,7 +1027,7 @@ camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1688 1027
1689 cctx->key_length = key_len; 1028 cctx->key_length = key_len;
1690 1029
1691 switch(key_len) { 1030 switch (key_len) {
1692 case 16: 1031 case 16:
1693 camellia_setup128(key, cctx->key_table); 1032 camellia_setup128(key, cctx->key_table);
1694 break; 1033 break;
@@ -1698,68 +1037,59 @@ camellia_set_key(struct crypto_tfm *tfm, const u8 *in_key,
1698 case 32: 1037 case 32:
1699 camellia_setup256(key, cctx->key_table); 1038 camellia_setup256(key, cctx->key_table);
1700 break; 1039 break;
1701 default:
1702 break;
1703 } 1040 }
1704 1041
1705 return 0; 1042 return 0;
1706} 1043}
1707 1044
1708
1709static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 1045static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1710{ 1046{
1711 const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm); 1047 const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
1712 const __be32 *src = (const __be32 *)in; 1048 const __be32 *src = (const __be32 *)in;
1713 __be32 *dst = (__be32 *)out; 1049 __be32 *dst = (__be32 *)out;
1714 1050
1715 __be32 tmp[4]; 1051 u32 tmp[4];
1716 1052
1717 memcpy(tmp, src, CAMELLIA_BLOCK_SIZE); 1053 tmp[0] = be32_to_cpu(src[0]);
1054 tmp[1] = be32_to_cpu(src[1]);
1055 tmp[2] = be32_to_cpu(src[2]);
1056 tmp[3] = be32_to_cpu(src[3]);
1718 1057
1719 switch (cctx->key_length) { 1058 camellia_do_encrypt(cctx->key_table, tmp,
1720 case 16: 1059 cctx->key_length == 16 ? 24 : 32 /* for key lengths of 24 and 32 */
1721 camellia_encrypt128(cctx->key_table, tmp); 1060 );
1722 break;
1723 case 24:
1724 /* fall through */
1725 case 32:
1726 camellia_encrypt256(cctx->key_table, tmp);
1727 break;
1728 default:
1729 break;
1730 }
1731 1061
1732 memcpy(dst, tmp, CAMELLIA_BLOCK_SIZE); 1062 /* do_encrypt returns 0,1 swapped with 2,3 */
1063 dst[0] = cpu_to_be32(tmp[2]);
1064 dst[1] = cpu_to_be32(tmp[3]);
1065 dst[2] = cpu_to_be32(tmp[0]);
1066 dst[3] = cpu_to_be32(tmp[1]);
1733} 1067}
1734 1068
1735
1736static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 1069static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
1737{ 1070{
1738 const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm); 1071 const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
1739 const __be32 *src = (const __be32 *)in; 1072 const __be32 *src = (const __be32 *)in;
1740 __be32 *dst = (__be32 *)out; 1073 __be32 *dst = (__be32 *)out;
1741 1074
1742 __be32 tmp[4]; 1075 u32 tmp[4];
1743 1076
1744 memcpy(tmp, src, CAMELLIA_BLOCK_SIZE); 1077 tmp[0] = be32_to_cpu(src[0]);
1078 tmp[1] = be32_to_cpu(src[1]);
1079 tmp[2] = be32_to_cpu(src[2]);
1080 tmp[3] = be32_to_cpu(src[3]);
1745 1081
1746 switch (cctx->key_length) { 1082 camellia_do_decrypt(cctx->key_table, tmp,
1747 case 16: 1083 cctx->key_length == 16 ? 24 : 32 /* for key lengths of 24 and 32 */
1748 camellia_decrypt128(cctx->key_table, tmp); 1084 );
1749 break;
1750 case 24:
1751 /* fall through */
1752 case 32:
1753 camellia_decrypt256(cctx->key_table, tmp);
1754 break;
1755 default:
1756 break;
1757 }
1758 1085
1759 memcpy(dst, tmp, CAMELLIA_BLOCK_SIZE); 1086 /* do_decrypt returns 0,1 swapped with 2,3 */
1087 dst[0] = cpu_to_be32(tmp[2]);
1088 dst[1] = cpu_to_be32(tmp[3]);
1089 dst[2] = cpu_to_be32(tmp[0]);
1090 dst[3] = cpu_to_be32(tmp[1]);
1760} 1091}
1761 1092
1762
1763static struct crypto_alg camellia_alg = { 1093static struct crypto_alg camellia_alg = {
1764 .cra_name = "camellia", 1094 .cra_name = "camellia",
1765 .cra_driver_name = "camellia-generic", 1095 .cra_driver_name = "camellia-generic",
@@ -1786,16 +1116,13 @@ static int __init camellia_init(void)
1786 return crypto_register_alg(&camellia_alg); 1116 return crypto_register_alg(&camellia_alg);
1787} 1117}
1788 1118
1789
1790static void __exit camellia_fini(void) 1119static void __exit camellia_fini(void)
1791{ 1120{
1792 crypto_unregister_alg(&camellia_alg); 1121 crypto_unregister_alg(&camellia_alg);
1793} 1122}
1794 1123
1795
1796module_init(camellia_init); 1124module_init(camellia_init);
1797module_exit(camellia_fini); 1125module_exit(camellia_fini);
1798 1126
1799
1800MODULE_DESCRIPTION("Camellia Cipher Algorithm"); 1127MODULE_DESCRIPTION("Camellia Cipher Algorithm");
1801MODULE_LICENSE("GPL"); 1128MODULE_LICENSE("GPL");
diff --git a/crypto/cast6.c b/crypto/cast6.c
index 136ab6dfe8c5..5fd9420dc58e 100644
--- a/crypto/cast6.c
+++ b/crypto/cast6.c
@@ -369,7 +369,7 @@ static const u8 Tr[4][8] = {
369}; 369};
370 370
371/* forward octave */ 371/* forward octave */
372static inline void W(u32 *key, unsigned int i) { 372static void W(u32 *key, unsigned int i) {
373 u32 I; 373 u32 I;
374 key[6] ^= F1(key[7], Tr[i % 4][0], Tm[i][0]); 374 key[6] ^= F1(key[7], Tr[i % 4][0], Tm[i][0]);
375 key[5] ^= F2(key[6], Tr[i % 4][1], Tm[i][1]); 375 key[5] ^= F2(key[6], Tr[i % 4][1], Tm[i][1]);
@@ -428,7 +428,7 @@ static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key,
428} 428}
429 429
430/*forward quad round*/ 430/*forward quad round*/
431static inline void Q (u32 * block, u8 * Kr, u32 * Km) { 431static void Q (u32 * block, u8 * Kr, u32 * Km) {
432 u32 I; 432 u32 I;
433 block[2] ^= F1(block[3], Kr[0], Km[0]); 433 block[2] ^= F1(block[3], Kr[0], Km[0]);
434 block[1] ^= F2(block[2], Kr[1], Km[1]); 434 block[1] ^= F2(block[2], Kr[1], Km[1]);
@@ -437,7 +437,7 @@ static inline void Q (u32 * block, u8 * Kr, u32 * Km) {
437} 437}
438 438
439/*reverse quad round*/ 439/*reverse quad round*/
440static inline void QBAR (u32 * block, u8 * Kr, u32 * Km) { 440static void QBAR (u32 * block, u8 * Kr, u32 * Km) {
441 u32 I; 441 u32 I;
442 block[3] ^= F1(block[0], Kr[3], Km[3]); 442 block[3] ^= F1(block[0], Kr[3], Km[3]);
443 block[0] ^= F3(block[1], Kr[2], Km[2]); 443 block[0] ^= F3(block[1], Kr[2], Km[2]);
diff --git a/crypto/cbc.c b/crypto/cbc.c
index 1f2649e13b42..6affff882cf8 100644
--- a/crypto/cbc.c
+++ b/crypto/cbc.c
@@ -14,13 +14,13 @@
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/log2.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20 21
21struct crypto_cbc_ctx { 22struct crypto_cbc_ctx {
22 struct crypto_cipher *child; 23 struct crypto_cipher *child;
23 void (*xor)(u8 *dst, const u8 *src, unsigned int bs);
24}; 24};
25 25
26static int crypto_cbc_setkey(struct crypto_tfm *parent, const u8 *key, 26static int crypto_cbc_setkey(struct crypto_tfm *parent, const u8 *key,
@@ -41,9 +41,7 @@ static int crypto_cbc_setkey(struct crypto_tfm *parent, const u8 *key,
41 41
42static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc, 42static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc,
43 struct blkcipher_walk *walk, 43 struct blkcipher_walk *walk,
44 struct crypto_cipher *tfm, 44 struct crypto_cipher *tfm)
45 void (*xor)(u8 *, const u8 *,
46 unsigned int))
47{ 45{
48 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 46 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
49 crypto_cipher_alg(tfm)->cia_encrypt; 47 crypto_cipher_alg(tfm)->cia_encrypt;
@@ -54,7 +52,7 @@ static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc,
54 u8 *iv = walk->iv; 52 u8 *iv = walk->iv;
55 53
56 do { 54 do {
57 xor(iv, src, bsize); 55 crypto_xor(iv, src, bsize);
58 fn(crypto_cipher_tfm(tfm), dst, iv); 56 fn(crypto_cipher_tfm(tfm), dst, iv);
59 memcpy(iv, dst, bsize); 57 memcpy(iv, dst, bsize);
60 58
@@ -67,9 +65,7 @@ static int crypto_cbc_encrypt_segment(struct blkcipher_desc *desc,
67 65
68static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc, 66static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
69 struct blkcipher_walk *walk, 67 struct blkcipher_walk *walk,
70 struct crypto_cipher *tfm, 68 struct crypto_cipher *tfm)
71 void (*xor)(u8 *, const u8 *,
72 unsigned int))
73{ 69{
74 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 70 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
75 crypto_cipher_alg(tfm)->cia_encrypt; 71 crypto_cipher_alg(tfm)->cia_encrypt;
@@ -79,7 +75,7 @@ static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
79 u8 *iv = walk->iv; 75 u8 *iv = walk->iv;
80 76
81 do { 77 do {
82 xor(src, iv, bsize); 78 crypto_xor(src, iv, bsize);
83 fn(crypto_cipher_tfm(tfm), src, src); 79 fn(crypto_cipher_tfm(tfm), src, src);
84 iv = src; 80 iv = src;
85 81
@@ -99,7 +95,6 @@ static int crypto_cbc_encrypt(struct blkcipher_desc *desc,
99 struct crypto_blkcipher *tfm = desc->tfm; 95 struct crypto_blkcipher *tfm = desc->tfm;
100 struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm); 96 struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
101 struct crypto_cipher *child = ctx->child; 97 struct crypto_cipher *child = ctx->child;
102 void (*xor)(u8 *, const u8 *, unsigned int bs) = ctx->xor;
103 int err; 98 int err;
104 99
105 blkcipher_walk_init(&walk, dst, src, nbytes); 100 blkcipher_walk_init(&walk, dst, src, nbytes);
@@ -107,11 +102,9 @@ static int crypto_cbc_encrypt(struct blkcipher_desc *desc,
107 102
108 while ((nbytes = walk.nbytes)) { 103 while ((nbytes = walk.nbytes)) {
109 if (walk.src.virt.addr == walk.dst.virt.addr) 104 if (walk.src.virt.addr == walk.dst.virt.addr)
110 nbytes = crypto_cbc_encrypt_inplace(desc, &walk, child, 105 nbytes = crypto_cbc_encrypt_inplace(desc, &walk, child);
111 xor);
112 else 106 else
113 nbytes = crypto_cbc_encrypt_segment(desc, &walk, child, 107 nbytes = crypto_cbc_encrypt_segment(desc, &walk, child);
114 xor);
115 err = blkcipher_walk_done(desc, &walk, nbytes); 108 err = blkcipher_walk_done(desc, &walk, nbytes);
116 } 109 }
117 110
@@ -120,9 +113,7 @@ static int crypto_cbc_encrypt(struct blkcipher_desc *desc,
120 113
121static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc, 114static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc,
122 struct blkcipher_walk *walk, 115 struct blkcipher_walk *walk,
123 struct crypto_cipher *tfm, 116 struct crypto_cipher *tfm)
124 void (*xor)(u8 *, const u8 *,
125 unsigned int))
126{ 117{
127 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 118 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
128 crypto_cipher_alg(tfm)->cia_decrypt; 119 crypto_cipher_alg(tfm)->cia_decrypt;
@@ -134,7 +125,7 @@ static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc,
134 125
135 do { 126 do {
136 fn(crypto_cipher_tfm(tfm), dst, src); 127 fn(crypto_cipher_tfm(tfm), dst, src);
137 xor(dst, iv, bsize); 128 crypto_xor(dst, iv, bsize);
138 iv = src; 129 iv = src;
139 130
140 src += bsize; 131 src += bsize;
@@ -148,34 +139,29 @@ static int crypto_cbc_decrypt_segment(struct blkcipher_desc *desc,
148 139
149static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc, 140static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc,
150 struct blkcipher_walk *walk, 141 struct blkcipher_walk *walk,
151 struct crypto_cipher *tfm, 142 struct crypto_cipher *tfm)
152 void (*xor)(u8 *, const u8 *,
153 unsigned int))
154{ 143{
155 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 144 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
156 crypto_cipher_alg(tfm)->cia_decrypt; 145 crypto_cipher_alg(tfm)->cia_decrypt;
157 int bsize = crypto_cipher_blocksize(tfm); 146 int bsize = crypto_cipher_blocksize(tfm);
158 unsigned long alignmask = crypto_cipher_alignmask(tfm);
159 unsigned int nbytes = walk->nbytes; 147 unsigned int nbytes = walk->nbytes;
160 u8 *src = walk->src.virt.addr; 148 u8 *src = walk->src.virt.addr;
161 u8 stack[bsize + alignmask]; 149 u8 last_iv[bsize];
162 u8 *first_iv = (u8 *)ALIGN((unsigned long)stack, alignmask + 1);
163
164 memcpy(first_iv, walk->iv, bsize);
165 150
166 /* Start of the last block. */ 151 /* Start of the last block. */
167 src += nbytes - nbytes % bsize - bsize; 152 src += nbytes - (nbytes & (bsize - 1)) - bsize;
168 memcpy(walk->iv, src, bsize); 153 memcpy(last_iv, src, bsize);
169 154
170 for (;;) { 155 for (;;) {
171 fn(crypto_cipher_tfm(tfm), src, src); 156 fn(crypto_cipher_tfm(tfm), src, src);
172 if ((nbytes -= bsize) < bsize) 157 if ((nbytes -= bsize) < bsize)
173 break; 158 break;
174 xor(src, src - bsize, bsize); 159 crypto_xor(src, src - bsize, bsize);
175 src -= bsize; 160 src -= bsize;
176 } 161 }
177 162
178 xor(src, first_iv, bsize); 163 crypto_xor(src, walk->iv, bsize);
164 memcpy(walk->iv, last_iv, bsize);
179 165
180 return nbytes; 166 return nbytes;
181} 167}
@@ -188,7 +174,6 @@ static int crypto_cbc_decrypt(struct blkcipher_desc *desc,
188 struct crypto_blkcipher *tfm = desc->tfm; 174 struct crypto_blkcipher *tfm = desc->tfm;
189 struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm); 175 struct crypto_cbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
190 struct crypto_cipher *child = ctx->child; 176 struct crypto_cipher *child = ctx->child;
191 void (*xor)(u8 *, const u8 *, unsigned int bs) = ctx->xor;
192 int err; 177 int err;
193 178
194 blkcipher_walk_init(&walk, dst, src, nbytes); 179 blkcipher_walk_init(&walk, dst, src, nbytes);
@@ -196,48 +181,15 @@ static int crypto_cbc_decrypt(struct blkcipher_desc *desc,
196 181
197 while ((nbytes = walk.nbytes)) { 182 while ((nbytes = walk.nbytes)) {
198 if (walk.src.virt.addr == walk.dst.virt.addr) 183 if (walk.src.virt.addr == walk.dst.virt.addr)
199 nbytes = crypto_cbc_decrypt_inplace(desc, &walk, child, 184 nbytes = crypto_cbc_decrypt_inplace(desc, &walk, child);
200 xor);
201 else 185 else
202 nbytes = crypto_cbc_decrypt_segment(desc, &walk, child, 186 nbytes = crypto_cbc_decrypt_segment(desc, &walk, child);
203 xor);
204 err = blkcipher_walk_done(desc, &walk, nbytes); 187 err = blkcipher_walk_done(desc, &walk, nbytes);
205 } 188 }
206 189
207 return err; 190 return err;
208} 191}
209 192
210static void xor_byte(u8 *a, const u8 *b, unsigned int bs)
211{
212 do {
213 *a++ ^= *b++;
214 } while (--bs);
215}
216
217static void xor_quad(u8 *dst, const u8 *src, unsigned int bs)
218{
219 u32 *a = (u32 *)dst;
220 u32 *b = (u32 *)src;
221
222 do {
223 *a++ ^= *b++;
224 } while ((bs -= 4));
225}
226
227static void xor_64(u8 *a, const u8 *b, unsigned int bs)
228{
229 ((u32 *)a)[0] ^= ((u32 *)b)[0];
230 ((u32 *)a)[1] ^= ((u32 *)b)[1];
231}
232
233static void xor_128(u8 *a, const u8 *b, unsigned int bs)
234{
235 ((u32 *)a)[0] ^= ((u32 *)b)[0];
236 ((u32 *)a)[1] ^= ((u32 *)b)[1];
237 ((u32 *)a)[2] ^= ((u32 *)b)[2];
238 ((u32 *)a)[3] ^= ((u32 *)b)[3];
239}
240
241static int crypto_cbc_init_tfm(struct crypto_tfm *tfm) 193static int crypto_cbc_init_tfm(struct crypto_tfm *tfm)
242{ 194{
243 struct crypto_instance *inst = (void *)tfm->__crt_alg; 195 struct crypto_instance *inst = (void *)tfm->__crt_alg;
@@ -245,22 +197,6 @@ static int crypto_cbc_init_tfm(struct crypto_tfm *tfm)
245 struct crypto_cbc_ctx *ctx = crypto_tfm_ctx(tfm); 197 struct crypto_cbc_ctx *ctx = crypto_tfm_ctx(tfm);
246 struct crypto_cipher *cipher; 198 struct crypto_cipher *cipher;
247 199
248 switch (crypto_tfm_alg_blocksize(tfm)) {
249 case 8:
250 ctx->xor = xor_64;
251 break;
252
253 case 16:
254 ctx->xor = xor_128;
255 break;
256
257 default:
258 if (crypto_tfm_alg_blocksize(tfm) % 4)
259 ctx->xor = xor_byte;
260 else
261 ctx->xor = xor_quad;
262 }
263
264 cipher = crypto_spawn_cipher(spawn); 200 cipher = crypto_spawn_cipher(spawn);
265 if (IS_ERR(cipher)) 201 if (IS_ERR(cipher))
266 return PTR_ERR(cipher); 202 return PTR_ERR(cipher);
@@ -290,6 +226,10 @@ static struct crypto_instance *crypto_cbc_alloc(struct rtattr **tb)
290 if (IS_ERR(alg)) 226 if (IS_ERR(alg))
291 return ERR_PTR(PTR_ERR(alg)); 227 return ERR_PTR(PTR_ERR(alg));
292 228
229 inst = ERR_PTR(-EINVAL);
230 if (!is_power_of_2(alg->cra_blocksize))
231 goto out_put_alg;
232
293 inst = crypto_alloc_instance("cbc", alg); 233 inst = crypto_alloc_instance("cbc", alg);
294 if (IS_ERR(inst)) 234 if (IS_ERR(inst))
295 goto out_put_alg; 235 goto out_put_alg;
@@ -300,8 +240,9 @@ static struct crypto_instance *crypto_cbc_alloc(struct rtattr **tb)
300 inst->alg.cra_alignmask = alg->cra_alignmask; 240 inst->alg.cra_alignmask = alg->cra_alignmask;
301 inst->alg.cra_type = &crypto_blkcipher_type; 241 inst->alg.cra_type = &crypto_blkcipher_type;
302 242
303 if (!(alg->cra_blocksize % 4)) 243 /* We access the data as u32s when xoring. */
304 inst->alg.cra_alignmask |= 3; 244 inst->alg.cra_alignmask |= __alignof__(u32) - 1;
245
305 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize; 246 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize;
306 inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 247 inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
307 inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize; 248 inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
diff --git a/crypto/ccm.c b/crypto/ccm.c
new file mode 100644
index 000000000000..7cf7e5a6b781
--- /dev/null
+++ b/crypto/ccm.c
@@ -0,0 +1,889 @@
1/*
2 * CCM: Counter with CBC-MAC
3 *
4 * (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <crypto/internal/aead.h>
14#include <crypto/internal/skcipher.h>
15#include <crypto/scatterwalk.h>
16#include <linux/err.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21
22#include "internal.h"
23
24struct ccm_instance_ctx {
25 struct crypto_skcipher_spawn ctr;
26 struct crypto_spawn cipher;
27};
28
29struct crypto_ccm_ctx {
30 struct crypto_cipher *cipher;
31 struct crypto_ablkcipher *ctr;
32};
33
34struct crypto_rfc4309_ctx {
35 struct crypto_aead *child;
36 u8 nonce[3];
37};
38
39struct crypto_ccm_req_priv_ctx {
40 u8 odata[16];
41 u8 idata[16];
42 u8 auth_tag[16];
43 u32 ilen;
44 u32 flags;
45 struct scatterlist src[2];
46 struct scatterlist dst[2];
47 struct ablkcipher_request abreq;
48};
49
50static inline struct crypto_ccm_req_priv_ctx *crypto_ccm_reqctx(
51 struct aead_request *req)
52{
53 unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req));
54
55 return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1);
56}
57
58static int set_msg_len(u8 *block, unsigned int msglen, int csize)
59{
60 __be32 data;
61
62 memset(block, 0, csize);
63 block += csize;
64
65 if (csize >= 4)
66 csize = 4;
67 else if (msglen > (1 << (8 * csize)))
68 return -EOVERFLOW;
69
70 data = cpu_to_be32(msglen);
71 memcpy(block - csize, (u8 *)&data + 4 - csize, csize);
72
73 return 0;
74}
75
76static int crypto_ccm_setkey(struct crypto_aead *aead, const u8 *key,
77 unsigned int keylen)
78{
79 struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
80 struct crypto_ablkcipher *ctr = ctx->ctr;
81 struct crypto_cipher *tfm = ctx->cipher;
82 int err = 0;
83
84 crypto_ablkcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK);
85 crypto_ablkcipher_set_flags(ctr, crypto_aead_get_flags(aead) &
86 CRYPTO_TFM_REQ_MASK);
87 err = crypto_ablkcipher_setkey(ctr, key, keylen);
88 crypto_aead_set_flags(aead, crypto_ablkcipher_get_flags(ctr) &
89 CRYPTO_TFM_RES_MASK);
90 if (err)
91 goto out;
92
93 crypto_cipher_clear_flags(tfm, CRYPTO_TFM_REQ_MASK);
94 crypto_cipher_set_flags(tfm, crypto_aead_get_flags(aead) &
95 CRYPTO_TFM_REQ_MASK);
96 err = crypto_cipher_setkey(tfm, key, keylen);
97 crypto_aead_set_flags(aead, crypto_cipher_get_flags(tfm) &
98 CRYPTO_TFM_RES_MASK);
99
100out:
101 return err;
102}
103
104static int crypto_ccm_setauthsize(struct crypto_aead *tfm,
105 unsigned int authsize)
106{
107 switch (authsize) {
108 case 4:
109 case 6:
110 case 8:
111 case 10:
112 case 12:
113 case 14:
114 case 16:
115 break;
116 default:
117 return -EINVAL;
118 }
119
120 return 0;
121}
122
123static int format_input(u8 *info, struct aead_request *req,
124 unsigned int cryptlen)
125{
126 struct crypto_aead *aead = crypto_aead_reqtfm(req);
127 unsigned int lp = req->iv[0];
128 unsigned int l = lp + 1;
129 unsigned int m;
130
131 m = crypto_aead_authsize(aead);
132
133 memcpy(info, req->iv, 16);
134
135 /* format control info per RFC 3610 and
136 * NIST Special Publication 800-38C
137 */
138 *info |= (8 * ((m - 2) / 2));
139 if (req->assoclen)
140 *info |= 64;
141
142 return set_msg_len(info + 16 - l, cryptlen, l);
143}
144
145static int format_adata(u8 *adata, unsigned int a)
146{
147 int len = 0;
148
149 /* add control info for associated data
150 * RFC 3610 and NIST Special Publication 800-38C
151 */
152 if (a < 65280) {
153 *(__be16 *)adata = cpu_to_be16(a);
154 len = 2;
155 } else {
156 *(__be16 *)adata = cpu_to_be16(0xfffe);
157 *(__be32 *)&adata[2] = cpu_to_be32(a);
158 len = 6;
159 }
160
161 return len;
162}
163
164static void compute_mac(struct crypto_cipher *tfm, u8 *data, int n,
165 struct crypto_ccm_req_priv_ctx *pctx)
166{
167 unsigned int bs = 16;
168 u8 *odata = pctx->odata;
169 u8 *idata = pctx->idata;
170 int datalen, getlen;
171
172 datalen = n;
173
174 /* first time in here, block may be partially filled. */
175 getlen = bs - pctx->ilen;
176 if (datalen >= getlen) {
177 memcpy(idata + pctx->ilen, data, getlen);
178 crypto_xor(odata, idata, bs);
179 crypto_cipher_encrypt_one(tfm, odata, odata);
180 datalen -= getlen;
181 data += getlen;
182 pctx->ilen = 0;
183 }
184
185 /* now encrypt rest of data */
186 while (datalen >= bs) {
187 crypto_xor(odata, data, bs);
188 crypto_cipher_encrypt_one(tfm, odata, odata);
189
190 datalen -= bs;
191 data += bs;
192 }
193
194 /* check and see if there's leftover data that wasn't
195 * enough to fill a block.
196 */
197 if (datalen) {
198 memcpy(idata + pctx->ilen, data, datalen);
199 pctx->ilen += datalen;
200 }
201}
202
203static void get_data_to_compute(struct crypto_cipher *tfm,
204 struct crypto_ccm_req_priv_ctx *pctx,
205 struct scatterlist *sg, unsigned int len)
206{
207 struct scatter_walk walk;
208 u8 *data_src;
209 int n;
210
211 scatterwalk_start(&walk, sg);
212
213 while (len) {
214 n = scatterwalk_clamp(&walk, len);
215 if (!n) {
216 scatterwalk_start(&walk, sg_next(walk.sg));
217 n = scatterwalk_clamp(&walk, len);
218 }
219 data_src = scatterwalk_map(&walk, 0);
220
221 compute_mac(tfm, data_src, n, pctx);
222 len -= n;
223
224 scatterwalk_unmap(data_src, 0);
225 scatterwalk_advance(&walk, n);
226 scatterwalk_done(&walk, 0, len);
227 if (len)
228 crypto_yield(pctx->flags);
229 }
230
231 /* any leftover needs padding and then encrypted */
232 if (pctx->ilen) {
233 int padlen;
234 u8 *odata = pctx->odata;
235 u8 *idata = pctx->idata;
236
237 padlen = 16 - pctx->ilen;
238 memset(idata + pctx->ilen, 0, padlen);
239 crypto_xor(odata, idata, 16);
240 crypto_cipher_encrypt_one(tfm, odata, odata);
241 pctx->ilen = 0;
242 }
243}
244
245static int crypto_ccm_auth(struct aead_request *req, struct scatterlist *plain,
246 unsigned int cryptlen)
247{
248 struct crypto_aead *aead = crypto_aead_reqtfm(req);
249 struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
250 struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
251 struct crypto_cipher *cipher = ctx->cipher;
252 unsigned int assoclen = req->assoclen;
253 u8 *odata = pctx->odata;
254 u8 *idata = pctx->idata;
255 int err;
256
257 /* format control data for input */
258 err = format_input(odata, req, cryptlen);
259 if (err)
260 goto out;
261
262 /* encrypt first block to use as start in computing mac */
263 crypto_cipher_encrypt_one(cipher, odata, odata);
264
265 /* format associated data and compute into mac */
266 if (assoclen) {
267 pctx->ilen = format_adata(idata, assoclen);
268 get_data_to_compute(cipher, pctx, req->assoc, req->assoclen);
269 }
270
271 /* compute plaintext into mac */
272 get_data_to_compute(cipher, pctx, plain, cryptlen);
273
274out:
275 return err;
276}
277
278static void crypto_ccm_encrypt_done(struct crypto_async_request *areq, int err)
279{
280 struct aead_request *req = areq->data;
281 struct crypto_aead *aead = crypto_aead_reqtfm(req);
282 struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
283 u8 *odata = pctx->odata;
284
285 if (!err)
286 scatterwalk_map_and_copy(odata, req->dst, req->cryptlen,
287 crypto_aead_authsize(aead), 1);
288 aead_request_complete(req, err);
289}
290
291static inline int crypto_ccm_check_iv(const u8 *iv)
292{
293 /* 2 <= L <= 8, so 1 <= L' <= 7. */
294 if (1 > iv[0] || iv[0] > 7)
295 return -EINVAL;
296
297 return 0;
298}
299
300static int crypto_ccm_encrypt(struct aead_request *req)
301{
302 struct crypto_aead *aead = crypto_aead_reqtfm(req);
303 struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
304 struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
305 struct ablkcipher_request *abreq = &pctx->abreq;
306 struct scatterlist *dst;
307 unsigned int cryptlen = req->cryptlen;
308 u8 *odata = pctx->odata;
309 u8 *iv = req->iv;
310 int err;
311
312 err = crypto_ccm_check_iv(iv);
313 if (err)
314 return err;
315
316 pctx->flags = aead_request_flags(req);
317
318 err = crypto_ccm_auth(req, req->src, cryptlen);
319 if (err)
320 return err;
321
322 /* Note: rfc 3610 and NIST 800-38C require counter of
323 * zero to encrypt auth tag.
324 */
325 memset(iv + 15 - iv[0], 0, iv[0] + 1);
326
327 sg_init_table(pctx->src, 2);
328 sg_set_buf(pctx->src, odata, 16);
329 scatterwalk_sg_chain(pctx->src, 2, req->src);
330
331 dst = pctx->src;
332 if (req->src != req->dst) {
333 sg_init_table(pctx->dst, 2);
334 sg_set_buf(pctx->dst, odata, 16);
335 scatterwalk_sg_chain(pctx->dst, 2, req->dst);
336 dst = pctx->dst;
337 }
338
339 ablkcipher_request_set_tfm(abreq, ctx->ctr);
340 ablkcipher_request_set_callback(abreq, pctx->flags,
341 crypto_ccm_encrypt_done, req);
342 ablkcipher_request_set_crypt(abreq, pctx->src, dst, cryptlen + 16, iv);
343 err = crypto_ablkcipher_encrypt(abreq);
344 if (err)
345 return err;
346
347 /* copy authtag to end of dst */
348 scatterwalk_map_and_copy(odata, req->dst, cryptlen,
349 crypto_aead_authsize(aead), 1);
350 return err;
351}
352
353static void crypto_ccm_decrypt_done(struct crypto_async_request *areq,
354 int err)
355{
356 struct aead_request *req = areq->data;
357 struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
358 struct crypto_aead *aead = crypto_aead_reqtfm(req);
359 unsigned int authsize = crypto_aead_authsize(aead);
360 unsigned int cryptlen = req->cryptlen - authsize;
361
362 if (!err) {
363 err = crypto_ccm_auth(req, req->dst, cryptlen);
364 if (!err && memcmp(pctx->auth_tag, pctx->odata, authsize))
365 err = -EBADMSG;
366 }
367 aead_request_complete(req, err);
368}
369
370static int crypto_ccm_decrypt(struct aead_request *req)
371{
372 struct crypto_aead *aead = crypto_aead_reqtfm(req);
373 struct crypto_ccm_ctx *ctx = crypto_aead_ctx(aead);
374 struct crypto_ccm_req_priv_ctx *pctx = crypto_ccm_reqctx(req);
375 struct ablkcipher_request *abreq = &pctx->abreq;
376 struct scatterlist *dst;
377 unsigned int authsize = crypto_aead_authsize(aead);
378 unsigned int cryptlen = req->cryptlen;
379 u8 *authtag = pctx->auth_tag;
380 u8 *odata = pctx->odata;
381 u8 *iv = req->iv;
382 int err;
383
384 if (cryptlen < authsize)
385 return -EINVAL;
386 cryptlen -= authsize;
387
388 err = crypto_ccm_check_iv(iv);
389 if (err)
390 return err;
391
392 pctx->flags = aead_request_flags(req);
393
394 scatterwalk_map_and_copy(authtag, req->src, cryptlen, authsize, 0);
395
396 memset(iv + 15 - iv[0], 0, iv[0] + 1);
397
398 sg_init_table(pctx->src, 2);
399 sg_set_buf(pctx->src, authtag, 16);
400 scatterwalk_sg_chain(pctx->src, 2, req->src);
401
402 dst = pctx->src;
403 if (req->src != req->dst) {
404 sg_init_table(pctx->dst, 2);
405 sg_set_buf(pctx->dst, authtag, 16);
406 scatterwalk_sg_chain(pctx->dst, 2, req->dst);
407 dst = pctx->dst;
408 }
409
410 ablkcipher_request_set_tfm(abreq, ctx->ctr);
411 ablkcipher_request_set_callback(abreq, pctx->flags,
412 crypto_ccm_decrypt_done, req);
413 ablkcipher_request_set_crypt(abreq, pctx->src, dst, cryptlen + 16, iv);
414 err = crypto_ablkcipher_decrypt(abreq);
415 if (err)
416 return err;
417
418 err = crypto_ccm_auth(req, req->dst, cryptlen);
419 if (err)
420 return err;
421
422 /* verify */
423 if (memcmp(authtag, odata, authsize))
424 return -EBADMSG;
425
426 return err;
427}
428
429static int crypto_ccm_init_tfm(struct crypto_tfm *tfm)
430{
431 struct crypto_instance *inst = (void *)tfm->__crt_alg;
432 struct ccm_instance_ctx *ictx = crypto_instance_ctx(inst);
433 struct crypto_ccm_ctx *ctx = crypto_tfm_ctx(tfm);
434 struct crypto_cipher *cipher;
435 struct crypto_ablkcipher *ctr;
436 unsigned long align;
437 int err;
438
439 cipher = crypto_spawn_cipher(&ictx->cipher);
440 if (IS_ERR(cipher))
441 return PTR_ERR(cipher);
442
443 ctr = crypto_spawn_skcipher(&ictx->ctr);
444 err = PTR_ERR(ctr);
445 if (IS_ERR(ctr))
446 goto err_free_cipher;
447
448 ctx->cipher = cipher;
449 ctx->ctr = ctr;
450
451 align = crypto_tfm_alg_alignmask(tfm);
452 align &= ~(crypto_tfm_ctx_alignment() - 1);
453 tfm->crt_aead.reqsize = align +
454 sizeof(struct crypto_ccm_req_priv_ctx) +
455 crypto_ablkcipher_reqsize(ctr);
456
457 return 0;
458
459err_free_cipher:
460 crypto_free_cipher(cipher);
461 return err;
462}
463
464static void crypto_ccm_exit_tfm(struct crypto_tfm *tfm)
465{
466 struct crypto_ccm_ctx *ctx = crypto_tfm_ctx(tfm);
467
468 crypto_free_cipher(ctx->cipher);
469 crypto_free_ablkcipher(ctx->ctr);
470}
471
472static struct crypto_instance *crypto_ccm_alloc_common(struct rtattr **tb,
473 const char *full_name,
474 const char *ctr_name,
475 const char *cipher_name)
476{
477 struct crypto_attr_type *algt;
478 struct crypto_instance *inst;
479 struct crypto_alg *ctr;
480 struct crypto_alg *cipher;
481 struct ccm_instance_ctx *ictx;
482 int err;
483
484 algt = crypto_get_attr_type(tb);
485 err = PTR_ERR(algt);
486 if (IS_ERR(algt))
487 return ERR_PTR(err);
488
489 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
490 return ERR_PTR(-EINVAL);
491
492 cipher = crypto_alg_mod_lookup(cipher_name, CRYPTO_ALG_TYPE_CIPHER,
493 CRYPTO_ALG_TYPE_MASK);
494 err = PTR_ERR(cipher);
495 if (IS_ERR(cipher))
496 return ERR_PTR(err);
497
498 err = -EINVAL;
499 if (cipher->cra_blocksize != 16)
500 goto out_put_cipher;
501
502 inst = kzalloc(sizeof(*inst) + sizeof(*ictx), GFP_KERNEL);
503 err = -ENOMEM;
504 if (!inst)
505 goto out_put_cipher;
506
507 ictx = crypto_instance_ctx(inst);
508
509 err = crypto_init_spawn(&ictx->cipher, cipher, inst,
510 CRYPTO_ALG_TYPE_MASK);
511 if (err)
512 goto err_free_inst;
513
514 crypto_set_skcipher_spawn(&ictx->ctr, inst);
515 err = crypto_grab_skcipher(&ictx->ctr, ctr_name, 0,
516 crypto_requires_sync(algt->type,
517 algt->mask));
518 if (err)
519 goto err_drop_cipher;
520
521 ctr = crypto_skcipher_spawn_alg(&ictx->ctr);
522
523 /* Not a stream cipher? */
524 err = -EINVAL;
525 if (ctr->cra_blocksize != 1)
526 goto err_drop_ctr;
527
528 /* We want the real thing! */
529 if (ctr->cra_ablkcipher.ivsize != 16)
530 goto err_drop_ctr;
531
532 err = -ENAMETOOLONG;
533 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
534 "ccm_base(%s,%s)", ctr->cra_driver_name,
535 cipher->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
536 goto err_drop_ctr;
537
538 memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
539
540 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
541 inst->alg.cra_flags |= ctr->cra_flags & CRYPTO_ALG_ASYNC;
542 inst->alg.cra_priority = cipher->cra_priority + ctr->cra_priority;
543 inst->alg.cra_blocksize = 1;
544 inst->alg.cra_alignmask = cipher->cra_alignmask | ctr->cra_alignmask |
545 (__alignof__(u32) - 1);
546 inst->alg.cra_type = &crypto_aead_type;
547 inst->alg.cra_aead.ivsize = 16;
548 inst->alg.cra_aead.maxauthsize = 16;
549 inst->alg.cra_ctxsize = sizeof(struct crypto_ccm_ctx);
550 inst->alg.cra_init = crypto_ccm_init_tfm;
551 inst->alg.cra_exit = crypto_ccm_exit_tfm;
552 inst->alg.cra_aead.setkey = crypto_ccm_setkey;
553 inst->alg.cra_aead.setauthsize = crypto_ccm_setauthsize;
554 inst->alg.cra_aead.encrypt = crypto_ccm_encrypt;
555 inst->alg.cra_aead.decrypt = crypto_ccm_decrypt;
556
557out:
558 crypto_mod_put(cipher);
559 return inst;
560
561err_drop_ctr:
562 crypto_drop_skcipher(&ictx->ctr);
563err_drop_cipher:
564 crypto_drop_spawn(&ictx->cipher);
565err_free_inst:
566 kfree(inst);
567out_put_cipher:
568 inst = ERR_PTR(err);
569 goto out;
570}
571
572static struct crypto_instance *crypto_ccm_alloc(struct rtattr **tb)
573{
574 int err;
575 const char *cipher_name;
576 char ctr_name[CRYPTO_MAX_ALG_NAME];
577 char full_name[CRYPTO_MAX_ALG_NAME];
578
579 cipher_name = crypto_attr_alg_name(tb[1]);
580 err = PTR_ERR(cipher_name);
581 if (IS_ERR(cipher_name))
582 return ERR_PTR(err);
583
584 if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)",
585 cipher_name) >= CRYPTO_MAX_ALG_NAME)
586 return ERR_PTR(-ENAMETOOLONG);
587
588 if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm(%s)", cipher_name) >=
589 CRYPTO_MAX_ALG_NAME)
590 return ERR_PTR(-ENAMETOOLONG);
591
592 return crypto_ccm_alloc_common(tb, full_name, ctr_name, cipher_name);
593}
594
595static void crypto_ccm_free(struct crypto_instance *inst)
596{
597 struct ccm_instance_ctx *ctx = crypto_instance_ctx(inst);
598
599 crypto_drop_spawn(&ctx->cipher);
600 crypto_drop_skcipher(&ctx->ctr);
601 kfree(inst);
602}
603
604static struct crypto_template crypto_ccm_tmpl = {
605 .name = "ccm",
606 .alloc = crypto_ccm_alloc,
607 .free = crypto_ccm_free,
608 .module = THIS_MODULE,
609};
610
611static struct crypto_instance *crypto_ccm_base_alloc(struct rtattr **tb)
612{
613 int err;
614 const char *ctr_name;
615 const char *cipher_name;
616 char full_name[CRYPTO_MAX_ALG_NAME];
617
618 ctr_name = crypto_attr_alg_name(tb[1]);
619 err = PTR_ERR(ctr_name);
620 if (IS_ERR(ctr_name))
621 return ERR_PTR(err);
622
623 cipher_name = crypto_attr_alg_name(tb[2]);
624 err = PTR_ERR(cipher_name);
625 if (IS_ERR(cipher_name))
626 return ERR_PTR(err);
627
628 if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "ccm_base(%s,%s)",
629 ctr_name, cipher_name) >= CRYPTO_MAX_ALG_NAME)
630 return ERR_PTR(-ENAMETOOLONG);
631
632 return crypto_ccm_alloc_common(tb, full_name, ctr_name, cipher_name);
633}
634
635static struct crypto_template crypto_ccm_base_tmpl = {
636 .name = "ccm_base",
637 .alloc = crypto_ccm_base_alloc,
638 .free = crypto_ccm_free,
639 .module = THIS_MODULE,
640};
641
642static int crypto_rfc4309_setkey(struct crypto_aead *parent, const u8 *key,
643 unsigned int keylen)
644{
645 struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(parent);
646 struct crypto_aead *child = ctx->child;
647 int err;
648
649 if (keylen < 3)
650 return -EINVAL;
651
652 keylen -= 3;
653 memcpy(ctx->nonce, key + keylen, 3);
654
655 crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK);
656 crypto_aead_set_flags(child, crypto_aead_get_flags(parent) &
657 CRYPTO_TFM_REQ_MASK);
658 err = crypto_aead_setkey(child, key, keylen);
659 crypto_aead_set_flags(parent, crypto_aead_get_flags(child) &
660 CRYPTO_TFM_RES_MASK);
661
662 return err;
663}
664
665static int crypto_rfc4309_setauthsize(struct crypto_aead *parent,
666 unsigned int authsize)
667{
668 struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(parent);
669
670 switch (authsize) {
671 case 8:
672 case 12:
673 case 16:
674 break;
675 default:
676 return -EINVAL;
677 }
678
679 return crypto_aead_setauthsize(ctx->child, authsize);
680}
681
682static struct aead_request *crypto_rfc4309_crypt(struct aead_request *req)
683{
684 struct aead_request *subreq = aead_request_ctx(req);
685 struct crypto_aead *aead = crypto_aead_reqtfm(req);
686 struct crypto_rfc4309_ctx *ctx = crypto_aead_ctx(aead);
687 struct crypto_aead *child = ctx->child;
688 u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child),
689 crypto_aead_alignmask(child) + 1);
690
691 /* L' */
692 iv[0] = 3;
693
694 memcpy(iv + 1, ctx->nonce, 3);
695 memcpy(iv + 4, req->iv, 8);
696
697 aead_request_set_tfm(subreq, child);
698 aead_request_set_callback(subreq, req->base.flags, req->base.complete,
699 req->base.data);
700 aead_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, iv);
701 aead_request_set_assoc(subreq, req->assoc, req->assoclen);
702
703 return subreq;
704}
705
706static int crypto_rfc4309_encrypt(struct aead_request *req)
707{
708 req = crypto_rfc4309_crypt(req);
709
710 return crypto_aead_encrypt(req);
711}
712
713static int crypto_rfc4309_decrypt(struct aead_request *req)
714{
715 req = crypto_rfc4309_crypt(req);
716
717 return crypto_aead_decrypt(req);
718}
719
720static int crypto_rfc4309_init_tfm(struct crypto_tfm *tfm)
721{
722 struct crypto_instance *inst = (void *)tfm->__crt_alg;
723 struct crypto_aead_spawn *spawn = crypto_instance_ctx(inst);
724 struct crypto_rfc4309_ctx *ctx = crypto_tfm_ctx(tfm);
725 struct crypto_aead *aead;
726 unsigned long align;
727
728 aead = crypto_spawn_aead(spawn);
729 if (IS_ERR(aead))
730 return PTR_ERR(aead);
731
732 ctx->child = aead;
733
734 align = crypto_aead_alignmask(aead);
735 align &= ~(crypto_tfm_ctx_alignment() - 1);
736 tfm->crt_aead.reqsize = sizeof(struct aead_request) +
737 ALIGN(crypto_aead_reqsize(aead),
738 crypto_tfm_ctx_alignment()) +
739 align + 16;
740
741 return 0;
742}
743
744static void crypto_rfc4309_exit_tfm(struct crypto_tfm *tfm)
745{
746 struct crypto_rfc4309_ctx *ctx = crypto_tfm_ctx(tfm);
747
748 crypto_free_aead(ctx->child);
749}
750
751static struct crypto_instance *crypto_rfc4309_alloc(struct rtattr **tb)
752{
753 struct crypto_attr_type *algt;
754 struct crypto_instance *inst;
755 struct crypto_aead_spawn *spawn;
756 struct crypto_alg *alg;
757 const char *ccm_name;
758 int err;
759
760 algt = crypto_get_attr_type(tb);
761 err = PTR_ERR(algt);
762 if (IS_ERR(algt))
763 return ERR_PTR(err);
764
765 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
766 return ERR_PTR(-EINVAL);
767
768 ccm_name = crypto_attr_alg_name(tb[1]);
769 err = PTR_ERR(ccm_name);
770 if (IS_ERR(ccm_name))
771 return ERR_PTR(err);
772
773 inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
774 if (!inst)
775 return ERR_PTR(-ENOMEM);
776
777 spawn = crypto_instance_ctx(inst);
778 crypto_set_aead_spawn(spawn, inst);
779 err = crypto_grab_aead(spawn, ccm_name, 0,
780 crypto_requires_sync(algt->type, algt->mask));
781 if (err)
782 goto out_free_inst;
783
784 alg = crypto_aead_spawn_alg(spawn);
785
786 err = -EINVAL;
787
788 /* We only support 16-byte blocks. */
789 if (alg->cra_aead.ivsize != 16)
790 goto out_drop_alg;
791
792 /* Not a stream cipher? */
793 if (alg->cra_blocksize != 1)
794 goto out_drop_alg;
795
796 err = -ENAMETOOLONG;
797 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
798 "rfc4309(%s)", alg->cra_name) >= CRYPTO_MAX_ALG_NAME ||
799 snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
800 "rfc4309(%s)", alg->cra_driver_name) >=
801 CRYPTO_MAX_ALG_NAME)
802 goto out_drop_alg;
803
804 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
805 inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
806 inst->alg.cra_priority = alg->cra_priority;
807 inst->alg.cra_blocksize = 1;
808 inst->alg.cra_alignmask = alg->cra_alignmask;
809 inst->alg.cra_type = &crypto_nivaead_type;
810
811 inst->alg.cra_aead.ivsize = 8;
812 inst->alg.cra_aead.maxauthsize = 16;
813
814 inst->alg.cra_ctxsize = sizeof(struct crypto_rfc4309_ctx);
815
816 inst->alg.cra_init = crypto_rfc4309_init_tfm;
817 inst->alg.cra_exit = crypto_rfc4309_exit_tfm;
818
819 inst->alg.cra_aead.setkey = crypto_rfc4309_setkey;
820 inst->alg.cra_aead.setauthsize = crypto_rfc4309_setauthsize;
821 inst->alg.cra_aead.encrypt = crypto_rfc4309_encrypt;
822 inst->alg.cra_aead.decrypt = crypto_rfc4309_decrypt;
823
824 inst->alg.cra_aead.geniv = "seqiv";
825
826out:
827 return inst;
828
829out_drop_alg:
830 crypto_drop_aead(spawn);
831out_free_inst:
832 kfree(inst);
833 inst = ERR_PTR(err);
834 goto out;
835}
836
837static void crypto_rfc4309_free(struct crypto_instance *inst)
838{
839 crypto_drop_spawn(crypto_instance_ctx(inst));
840 kfree(inst);
841}
842
843static struct crypto_template crypto_rfc4309_tmpl = {
844 .name = "rfc4309",
845 .alloc = crypto_rfc4309_alloc,
846 .free = crypto_rfc4309_free,
847 .module = THIS_MODULE,
848};
849
850static int __init crypto_ccm_module_init(void)
851{
852 int err;
853
854 err = crypto_register_template(&crypto_ccm_base_tmpl);
855 if (err)
856 goto out;
857
858 err = crypto_register_template(&crypto_ccm_tmpl);
859 if (err)
860 goto out_undo_base;
861
862 err = crypto_register_template(&crypto_rfc4309_tmpl);
863 if (err)
864 goto out_undo_ccm;
865
866out:
867 return err;
868
869out_undo_ccm:
870 crypto_unregister_template(&crypto_ccm_tmpl);
871out_undo_base:
872 crypto_unregister_template(&crypto_ccm_base_tmpl);
873 goto out;
874}
875
876static void __exit crypto_ccm_module_exit(void)
877{
878 crypto_unregister_template(&crypto_rfc4309_tmpl);
879 crypto_unregister_template(&crypto_ccm_tmpl);
880 crypto_unregister_template(&crypto_ccm_base_tmpl);
881}
882
883module_init(crypto_ccm_module_init);
884module_exit(crypto_ccm_module_exit);
885
886MODULE_LICENSE("GPL");
887MODULE_DESCRIPTION("Counter with CBC MAC");
888MODULE_ALIAS("ccm_base");
889MODULE_ALIAS("rfc4309");
diff --git a/crypto/chainiv.c b/crypto/chainiv.c
new file mode 100644
index 000000000000..d17fa0454dc3
--- /dev/null
+++ b/crypto/chainiv.c
@@ -0,0 +1,331 @@
1/*
2 * chainiv: Chain IV Generator
3 *
4 * Generate IVs simply be using the last block of the previous encryption.
5 * This is mainly useful for CBC with a synchronous algorithm.
6 *
7 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 */
15
16#include <crypto/internal/skcipher.h>
17#include <linux/err.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/random.h>
22#include <linux/spinlock.h>
23#include <linux/string.h>
24#include <linux/workqueue.h>
25
26enum {
27 CHAINIV_STATE_INUSE = 0,
28};
29
30struct chainiv_ctx {
31 spinlock_t lock;
32 char iv[];
33};
34
35struct async_chainiv_ctx {
36 unsigned long state;
37
38 spinlock_t lock;
39 int err;
40
41 struct crypto_queue queue;
42 struct work_struct postponed;
43
44 char iv[];
45};
46
47static int chainiv_givencrypt(struct skcipher_givcrypt_request *req)
48{
49 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
50 struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
51 struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
52 unsigned int ivsize;
53 int err;
54
55 ablkcipher_request_set_tfm(subreq, skcipher_geniv_cipher(geniv));
56 ablkcipher_request_set_callback(subreq, req->creq.base.flags &
57 ~CRYPTO_TFM_REQ_MAY_SLEEP,
58 req->creq.base.complete,
59 req->creq.base.data);
60 ablkcipher_request_set_crypt(subreq, req->creq.src, req->creq.dst,
61 req->creq.nbytes, req->creq.info);
62
63 spin_lock_bh(&ctx->lock);
64
65 ivsize = crypto_ablkcipher_ivsize(geniv);
66
67 memcpy(req->giv, ctx->iv, ivsize);
68 memcpy(subreq->info, ctx->iv, ivsize);
69
70 err = crypto_ablkcipher_encrypt(subreq);
71 if (err)
72 goto unlock;
73
74 memcpy(ctx->iv, subreq->info, ivsize);
75
76unlock:
77 spin_unlock_bh(&ctx->lock);
78
79 return err;
80}
81
82static int chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
83{
84 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
85 struct chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
86
87 spin_lock_bh(&ctx->lock);
88 if (crypto_ablkcipher_crt(geniv)->givencrypt !=
89 chainiv_givencrypt_first)
90 goto unlock;
91
92 crypto_ablkcipher_crt(geniv)->givencrypt = chainiv_givencrypt;
93 get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv));
94
95unlock:
96 spin_unlock_bh(&ctx->lock);
97
98 return chainiv_givencrypt(req);
99}
100
101static int chainiv_init_common(struct crypto_tfm *tfm)
102{
103 tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request);
104
105 return skcipher_geniv_init(tfm);
106}
107
108static int chainiv_init(struct crypto_tfm *tfm)
109{
110 struct chainiv_ctx *ctx = crypto_tfm_ctx(tfm);
111
112 spin_lock_init(&ctx->lock);
113
114 return chainiv_init_common(tfm);
115}
116
117static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx)
118{
119 int queued;
120
121 if (!ctx->queue.qlen) {
122 smp_mb__before_clear_bit();
123 clear_bit(CHAINIV_STATE_INUSE, &ctx->state);
124
125 if (!ctx->queue.qlen ||
126 test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
127 goto out;
128 }
129
130 queued = schedule_work(&ctx->postponed);
131 BUG_ON(!queued);
132
133out:
134 return ctx->err;
135}
136
137static int async_chainiv_postpone_request(struct skcipher_givcrypt_request *req)
138{
139 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
140 struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
141 int err;
142
143 spin_lock_bh(&ctx->lock);
144 err = skcipher_enqueue_givcrypt(&ctx->queue, req);
145 spin_unlock_bh(&ctx->lock);
146
147 if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
148 return err;
149
150 ctx->err = err;
151 return async_chainiv_schedule_work(ctx);
152}
153
154static int async_chainiv_givencrypt_tail(struct skcipher_givcrypt_request *req)
155{
156 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
157 struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
158 struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
159 unsigned int ivsize = crypto_ablkcipher_ivsize(geniv);
160
161 memcpy(req->giv, ctx->iv, ivsize);
162 memcpy(subreq->info, ctx->iv, ivsize);
163
164 ctx->err = crypto_ablkcipher_encrypt(subreq);
165 if (ctx->err)
166 goto out;
167
168 memcpy(ctx->iv, subreq->info, ivsize);
169
170out:
171 return async_chainiv_schedule_work(ctx);
172}
173
174static int async_chainiv_givencrypt(struct skcipher_givcrypt_request *req)
175{
176 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
177 struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
178 struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
179
180 ablkcipher_request_set_tfm(subreq, skcipher_geniv_cipher(geniv));
181 ablkcipher_request_set_callback(subreq, req->creq.base.flags,
182 req->creq.base.complete,
183 req->creq.base.data);
184 ablkcipher_request_set_crypt(subreq, req->creq.src, req->creq.dst,
185 req->creq.nbytes, req->creq.info);
186
187 if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
188 goto postpone;
189
190 if (ctx->queue.qlen) {
191 clear_bit(CHAINIV_STATE_INUSE, &ctx->state);
192 goto postpone;
193 }
194
195 return async_chainiv_givencrypt_tail(req);
196
197postpone:
198 return async_chainiv_postpone_request(req);
199}
200
201static int async_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req)
202{
203 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
204 struct async_chainiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
205
206 if (test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))
207 goto out;
208
209 if (crypto_ablkcipher_crt(geniv)->givencrypt !=
210 async_chainiv_givencrypt_first)
211 goto unlock;
212
213 crypto_ablkcipher_crt(geniv)->givencrypt = async_chainiv_givencrypt;
214 get_random_bytes(ctx->iv, crypto_ablkcipher_ivsize(geniv));
215
216unlock:
217 clear_bit(CHAINIV_STATE_INUSE, &ctx->state);
218
219out:
220 return async_chainiv_givencrypt(req);
221}
222
223static void async_chainiv_do_postponed(struct work_struct *work)
224{
225 struct async_chainiv_ctx *ctx = container_of(work,
226 struct async_chainiv_ctx,
227 postponed);
228 struct skcipher_givcrypt_request *req;
229 struct ablkcipher_request *subreq;
230
231 /* Only handle one request at a time to avoid hogging keventd. */
232 spin_lock_bh(&ctx->lock);
233 req = skcipher_dequeue_givcrypt(&ctx->queue);
234 spin_unlock_bh(&ctx->lock);
235
236 if (!req) {
237 async_chainiv_schedule_work(ctx);
238 return;
239 }
240
241 subreq = skcipher_givcrypt_reqctx(req);
242 subreq->base.flags |= CRYPTO_TFM_REQ_MAY_SLEEP;
243
244 async_chainiv_givencrypt_tail(req);
245}
246
247static int async_chainiv_init(struct crypto_tfm *tfm)
248{
249 struct async_chainiv_ctx *ctx = crypto_tfm_ctx(tfm);
250
251 spin_lock_init(&ctx->lock);
252
253 crypto_init_queue(&ctx->queue, 100);
254 INIT_WORK(&ctx->postponed, async_chainiv_do_postponed);
255
256 return chainiv_init_common(tfm);
257}
258
259static void async_chainiv_exit(struct crypto_tfm *tfm)
260{
261 struct async_chainiv_ctx *ctx = crypto_tfm_ctx(tfm);
262
263 BUG_ON(test_bit(CHAINIV_STATE_INUSE, &ctx->state) || ctx->queue.qlen);
264
265 skcipher_geniv_exit(tfm);
266}
267
268static struct crypto_template chainiv_tmpl;
269
270static struct crypto_instance *chainiv_alloc(struct rtattr **tb)
271{
272 struct crypto_attr_type *algt;
273 struct crypto_instance *inst;
274 int err;
275
276 algt = crypto_get_attr_type(tb);
277 err = PTR_ERR(algt);
278 if (IS_ERR(algt))
279 return ERR_PTR(err);
280
281 inst = skcipher_geniv_alloc(&chainiv_tmpl, tb, 0, 0);
282 if (IS_ERR(inst))
283 goto out;
284
285 inst->alg.cra_ablkcipher.givencrypt = chainiv_givencrypt_first;
286
287 inst->alg.cra_init = chainiv_init;
288 inst->alg.cra_exit = skcipher_geniv_exit;
289
290 inst->alg.cra_ctxsize = sizeof(struct chainiv_ctx);
291
292 if (!crypto_requires_sync(algt->type, algt->mask)) {
293 inst->alg.cra_flags |= CRYPTO_ALG_ASYNC;
294
295 inst->alg.cra_ablkcipher.givencrypt =
296 async_chainiv_givencrypt_first;
297
298 inst->alg.cra_init = async_chainiv_init;
299 inst->alg.cra_exit = async_chainiv_exit;
300
301 inst->alg.cra_ctxsize = sizeof(struct async_chainiv_ctx);
302 }
303
304 inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize;
305
306out:
307 return inst;
308}
309
310static struct crypto_template chainiv_tmpl = {
311 .name = "chainiv",
312 .alloc = chainiv_alloc,
313 .free = skcipher_geniv_free,
314 .module = THIS_MODULE,
315};
316
317static int __init chainiv_module_init(void)
318{
319 return crypto_register_template(&chainiv_tmpl);
320}
321
322static void __exit chainiv_module_exit(void)
323{
324 crypto_unregister_template(&chainiv_tmpl);
325}
326
327module_init(chainiv_module_init);
328module_exit(chainiv_module_exit);
329
330MODULE_LICENSE("GPL");
331MODULE_DESCRIPTION("Chain IV Generator");
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 8bf2da835f7b..074298f2f8e3 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -228,7 +228,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
228 struct crypto_alg *alg; 228 struct crypto_alg *alg;
229 229
230 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER, 230 alg = crypto_get_attr_alg(tb, CRYPTO_ALG_TYPE_BLKCIPHER,
231 CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 231 CRYPTO_ALG_TYPE_MASK);
232 if (IS_ERR(alg)) 232 if (IS_ERR(alg))
233 return ERR_PTR(PTR_ERR(alg)); 233 return ERR_PTR(PTR_ERR(alg));
234 234
@@ -236,13 +236,15 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
236 if (IS_ERR(inst)) 236 if (IS_ERR(inst))
237 goto out_put_alg; 237 goto out_put_alg;
238 238
239 inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | CRYPTO_ALG_ASYNC; 239 inst->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
240 inst->alg.cra_type = &crypto_ablkcipher_type; 240 inst->alg.cra_type = &crypto_ablkcipher_type;
241 241
242 inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize; 242 inst->alg.cra_ablkcipher.ivsize = alg->cra_blkcipher.ivsize;
243 inst->alg.cra_ablkcipher.min_keysize = alg->cra_blkcipher.min_keysize; 243 inst->alg.cra_ablkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
244 inst->alg.cra_ablkcipher.max_keysize = alg->cra_blkcipher.max_keysize; 244 inst->alg.cra_ablkcipher.max_keysize = alg->cra_blkcipher.max_keysize;
245 245
246 inst->alg.cra_ablkcipher.geniv = alg->cra_blkcipher.geniv;
247
246 inst->alg.cra_ctxsize = sizeof(struct cryptd_blkcipher_ctx); 248 inst->alg.cra_ctxsize = sizeof(struct cryptd_blkcipher_ctx);
247 249
248 inst->alg.cra_init = cryptd_blkcipher_init_tfm; 250 inst->alg.cra_init = cryptd_blkcipher_init_tfm;
diff --git a/crypto/crypto_null.c b/crypto/crypto_null.c
index 29f77477d701..ff7b3de1bcfd 100644
--- a/crypto/crypto_null.c
+++ b/crypto/crypto_null.c
@@ -16,15 +16,17 @@
16 * (at your option) any later version. 16 * (at your option) any later version.
17 * 17 *
18 */ 18 */
19
20#include <crypto/internal/skcipher.h>
19#include <linux/init.h> 21#include <linux/init.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/mm.h> 23#include <linux/mm.h>
22#include <linux/crypto.h>
23#include <linux/string.h> 24#include <linux/string.h>
24 25
25#define NULL_KEY_SIZE 0 26#define NULL_KEY_SIZE 0
26#define NULL_BLOCK_SIZE 1 27#define NULL_BLOCK_SIZE 1
27#define NULL_DIGEST_SIZE 0 28#define NULL_DIGEST_SIZE 0
29#define NULL_IV_SIZE 0
28 30
29static int null_compress(struct crypto_tfm *tfm, const u8 *src, 31static int null_compress(struct crypto_tfm *tfm, const u8 *src,
30 unsigned int slen, u8 *dst, unsigned int *dlen) 32 unsigned int slen, u8 *dst, unsigned int *dlen)
@@ -55,6 +57,26 @@ static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
55 memcpy(dst, src, NULL_BLOCK_SIZE); 57 memcpy(dst, src, NULL_BLOCK_SIZE);
56} 58}
57 59
60static int skcipher_null_crypt(struct blkcipher_desc *desc,
61 struct scatterlist *dst,
62 struct scatterlist *src, unsigned int nbytes)
63{
64 struct blkcipher_walk walk;
65 int err;
66
67 blkcipher_walk_init(&walk, dst, src, nbytes);
68 err = blkcipher_walk_virt(desc, &walk);
69
70 while (walk.nbytes) {
71 if (walk.src.virt.addr != walk.dst.virt.addr)
72 memcpy(walk.dst.virt.addr, walk.src.virt.addr,
73 walk.nbytes);
74 err = blkcipher_walk_done(desc, &walk, 0);
75 }
76
77 return err;
78}
79
58static struct crypto_alg compress_null = { 80static struct crypto_alg compress_null = {
59 .cra_name = "compress_null", 81 .cra_name = "compress_null",
60 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS, 82 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
@@ -76,6 +98,7 @@ static struct crypto_alg digest_null = {
76 .cra_list = LIST_HEAD_INIT(digest_null.cra_list), 98 .cra_list = LIST_HEAD_INIT(digest_null.cra_list),
77 .cra_u = { .digest = { 99 .cra_u = { .digest = {
78 .dia_digestsize = NULL_DIGEST_SIZE, 100 .dia_digestsize = NULL_DIGEST_SIZE,
101 .dia_setkey = null_setkey,
79 .dia_init = null_init, 102 .dia_init = null_init,
80 .dia_update = null_update, 103 .dia_update = null_update,
81 .dia_final = null_final } } 104 .dia_final = null_final } }
@@ -96,6 +119,25 @@ static struct crypto_alg cipher_null = {
96 .cia_decrypt = null_crypt } } 119 .cia_decrypt = null_crypt } }
97}; 120};
98 121
122static struct crypto_alg skcipher_null = {
123 .cra_name = "ecb(cipher_null)",
124 .cra_driver_name = "ecb-cipher_null",
125 .cra_priority = 100,
126 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
127 .cra_blocksize = NULL_BLOCK_SIZE,
128 .cra_type = &crypto_blkcipher_type,
129 .cra_ctxsize = 0,
130 .cra_module = THIS_MODULE,
131 .cra_list = LIST_HEAD_INIT(skcipher_null.cra_list),
132 .cra_u = { .blkcipher = {
133 .min_keysize = NULL_KEY_SIZE,
134 .max_keysize = NULL_KEY_SIZE,
135 .ivsize = NULL_IV_SIZE,
136 .setkey = null_setkey,
137 .encrypt = skcipher_null_crypt,
138 .decrypt = skcipher_null_crypt } }
139};
140
99MODULE_ALIAS("compress_null"); 141MODULE_ALIAS("compress_null");
100MODULE_ALIAS("digest_null"); 142MODULE_ALIAS("digest_null");
101MODULE_ALIAS("cipher_null"); 143MODULE_ALIAS("cipher_null");
@@ -108,27 +150,35 @@ static int __init init(void)
108 if (ret < 0) 150 if (ret < 0)
109 goto out; 151 goto out;
110 152
153 ret = crypto_register_alg(&skcipher_null);
154 if (ret < 0)
155 goto out_unregister_cipher;
156
111 ret = crypto_register_alg(&digest_null); 157 ret = crypto_register_alg(&digest_null);
112 if (ret < 0) { 158 if (ret < 0)
113 crypto_unregister_alg(&cipher_null); 159 goto out_unregister_skcipher;
114 goto out;
115 }
116 160
117 ret = crypto_register_alg(&compress_null); 161 ret = crypto_register_alg(&compress_null);
118 if (ret < 0) { 162 if (ret < 0)
119 crypto_unregister_alg(&digest_null); 163 goto out_unregister_digest;
120 crypto_unregister_alg(&cipher_null);
121 goto out;
122 }
123 164
124out: 165out:
125 return ret; 166 return ret;
167
168out_unregister_digest:
169 crypto_unregister_alg(&digest_null);
170out_unregister_skcipher:
171 crypto_unregister_alg(&skcipher_null);
172out_unregister_cipher:
173 crypto_unregister_alg(&cipher_null);
174 goto out;
126} 175}
127 176
128static void __exit fini(void) 177static void __exit fini(void)
129{ 178{
130 crypto_unregister_alg(&compress_null); 179 crypto_unregister_alg(&compress_null);
131 crypto_unregister_alg(&digest_null); 180 crypto_unregister_alg(&digest_null);
181 crypto_unregister_alg(&skcipher_null);
132 crypto_unregister_alg(&cipher_null); 182 crypto_unregister_alg(&cipher_null);
133} 183}
134 184
diff --git a/crypto/ctr.c b/crypto/ctr.c
new file mode 100644
index 000000000000..2d7425f0e7b8
--- /dev/null
+++ b/crypto/ctr.c
@@ -0,0 +1,422 @@
1/*
2 * CTR: Counter mode
3 *
4 * (C) Copyright IBM Corp. 2007 - Joy Latten <latten@us.ibm.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <crypto/algapi.h>
14#include <crypto/ctr.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/random.h>
20#include <linux/scatterlist.h>
21#include <linux/slab.h>
22
23struct crypto_ctr_ctx {
24 struct crypto_cipher *child;
25};
26
27struct crypto_rfc3686_ctx {
28 struct crypto_blkcipher *child;
29 u8 nonce[CTR_RFC3686_NONCE_SIZE];
30};
31
32static int crypto_ctr_setkey(struct crypto_tfm *parent, const u8 *key,
33 unsigned int keylen)
34{
35 struct crypto_ctr_ctx *ctx = crypto_tfm_ctx(parent);
36 struct crypto_cipher *child = ctx->child;
37 int err;
38
39 crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
40 crypto_cipher_set_flags(child, crypto_tfm_get_flags(parent) &
41 CRYPTO_TFM_REQ_MASK);
42 err = crypto_cipher_setkey(child, key, keylen);
43 crypto_tfm_set_flags(parent, crypto_cipher_get_flags(child) &
44 CRYPTO_TFM_RES_MASK);
45
46 return err;
47}
48
49static void crypto_ctr_crypt_final(struct blkcipher_walk *walk,
50 struct crypto_cipher *tfm)
51{
52 unsigned int bsize = crypto_cipher_blocksize(tfm);
53 unsigned long alignmask = crypto_cipher_alignmask(tfm);
54 u8 *ctrblk = walk->iv;
55 u8 tmp[bsize + alignmask];
56 u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1);
57 u8 *src = walk->src.virt.addr;
58 u8 *dst = walk->dst.virt.addr;
59 unsigned int nbytes = walk->nbytes;
60
61 crypto_cipher_encrypt_one(tfm, keystream, ctrblk);
62 crypto_xor(keystream, src, nbytes);
63 memcpy(dst, keystream, nbytes);
64
65 crypto_inc(ctrblk, bsize);
66}
67
68static int crypto_ctr_crypt_segment(struct blkcipher_walk *walk,
69 struct crypto_cipher *tfm)
70{
71 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
72 crypto_cipher_alg(tfm)->cia_encrypt;
73 unsigned int bsize = crypto_cipher_blocksize(tfm);
74 u8 *ctrblk = walk->iv;
75 u8 *src = walk->src.virt.addr;
76 u8 *dst = walk->dst.virt.addr;
77 unsigned int nbytes = walk->nbytes;
78
79 do {
80 /* create keystream */
81 fn(crypto_cipher_tfm(tfm), dst, ctrblk);
82 crypto_xor(dst, src, bsize);
83
84 /* increment counter in counterblock */
85 crypto_inc(ctrblk, bsize);
86
87 src += bsize;
88 dst += bsize;
89 } while ((nbytes -= bsize) >= bsize);
90
91 return nbytes;
92}
93
94static int crypto_ctr_crypt_inplace(struct blkcipher_walk *walk,
95 struct crypto_cipher *tfm)
96{
97 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
98 crypto_cipher_alg(tfm)->cia_encrypt;
99 unsigned int bsize = crypto_cipher_blocksize(tfm);
100 unsigned long alignmask = crypto_cipher_alignmask(tfm);
101 unsigned int nbytes = walk->nbytes;
102 u8 *ctrblk = walk->iv;
103 u8 *src = walk->src.virt.addr;
104 u8 tmp[bsize + alignmask];
105 u8 *keystream = PTR_ALIGN(tmp + 0, alignmask + 1);
106
107 do {
108 /* create keystream */
109 fn(crypto_cipher_tfm(tfm), keystream, ctrblk);
110 crypto_xor(src, keystream, bsize);
111
112 /* increment counter in counterblock */
113 crypto_inc(ctrblk, bsize);
114
115 src += bsize;
116 } while ((nbytes -= bsize) >= bsize);
117
118 return nbytes;
119}
120
121static int crypto_ctr_crypt(struct blkcipher_desc *desc,
122 struct scatterlist *dst, struct scatterlist *src,
123 unsigned int nbytes)
124{
125 struct blkcipher_walk walk;
126 struct crypto_blkcipher *tfm = desc->tfm;
127 struct crypto_ctr_ctx *ctx = crypto_blkcipher_ctx(tfm);
128 struct crypto_cipher *child = ctx->child;
129 unsigned int bsize = crypto_cipher_blocksize(child);
130 int err;
131
132 blkcipher_walk_init(&walk, dst, src, nbytes);
133 err = blkcipher_walk_virt_block(desc, &walk, bsize);
134
135 while (walk.nbytes >= bsize) {
136 if (walk.src.virt.addr == walk.dst.virt.addr)
137 nbytes = crypto_ctr_crypt_inplace(&walk, child);
138 else
139 nbytes = crypto_ctr_crypt_segment(&walk, child);
140
141 err = blkcipher_walk_done(desc, &walk, nbytes);
142 }
143
144 if (walk.nbytes) {
145 crypto_ctr_crypt_final(&walk, child);
146 err = blkcipher_walk_done(desc, &walk, 0);
147 }
148
149 return err;
150}
151
152static int crypto_ctr_init_tfm(struct crypto_tfm *tfm)
153{
154 struct crypto_instance *inst = (void *)tfm->__crt_alg;
155 struct crypto_spawn *spawn = crypto_instance_ctx(inst);
156 struct crypto_ctr_ctx *ctx = crypto_tfm_ctx(tfm);
157 struct crypto_cipher *cipher;
158
159 cipher = crypto_spawn_cipher(spawn);
160 if (IS_ERR(cipher))
161 return PTR_ERR(cipher);
162
163 ctx->child = cipher;
164
165 return 0;
166}
167
168static void crypto_ctr_exit_tfm(struct crypto_tfm *tfm)
169{
170 struct crypto_ctr_ctx *ctx = crypto_tfm_ctx(tfm);
171
172 crypto_free_cipher(ctx->child);
173}
174
175static struct crypto_instance *crypto_ctr_alloc(struct rtattr **tb)
176{
177 struct crypto_instance *inst;
178 struct crypto_alg *alg;
179 int err;
180
181 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
182 if (err)
183 return ERR_PTR(err);
184
185 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_CIPHER,
186 CRYPTO_ALG_TYPE_MASK);
187 if (IS_ERR(alg))
188 return ERR_PTR(PTR_ERR(alg));
189
190 /* Block size must be >= 4 bytes. */
191 err = -EINVAL;
192 if (alg->cra_blocksize < 4)
193 goto out_put_alg;
194
195 /* If this is false we'd fail the alignment of crypto_inc. */
196 if (alg->cra_blocksize % 4)
197 goto out_put_alg;
198
199 inst = crypto_alloc_instance("ctr", alg);
200 if (IS_ERR(inst))
201 goto out;
202
203 inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER;
204 inst->alg.cra_priority = alg->cra_priority;
205 inst->alg.cra_blocksize = 1;
206 inst->alg.cra_alignmask = alg->cra_alignmask | (__alignof__(u32) - 1);
207 inst->alg.cra_type = &crypto_blkcipher_type;
208
209 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize;
210 inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
211 inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
212
213 inst->alg.cra_ctxsize = sizeof(struct crypto_ctr_ctx);
214
215 inst->alg.cra_init = crypto_ctr_init_tfm;
216 inst->alg.cra_exit = crypto_ctr_exit_tfm;
217
218 inst->alg.cra_blkcipher.setkey = crypto_ctr_setkey;
219 inst->alg.cra_blkcipher.encrypt = crypto_ctr_crypt;
220 inst->alg.cra_blkcipher.decrypt = crypto_ctr_crypt;
221
222out:
223 crypto_mod_put(alg);
224 return inst;
225
226out_put_alg:
227 inst = ERR_PTR(err);
228 goto out;
229}
230
231static void crypto_ctr_free(struct crypto_instance *inst)
232{
233 crypto_drop_spawn(crypto_instance_ctx(inst));
234 kfree(inst);
235}
236
237static struct crypto_template crypto_ctr_tmpl = {
238 .name = "ctr",
239 .alloc = crypto_ctr_alloc,
240 .free = crypto_ctr_free,
241 .module = THIS_MODULE,
242};
243
244static int crypto_rfc3686_setkey(struct crypto_tfm *parent, const u8 *key,
245 unsigned int keylen)
246{
247 struct crypto_rfc3686_ctx *ctx = crypto_tfm_ctx(parent);
248 struct crypto_blkcipher *child = ctx->child;
249 int err;
250
251 /* the nonce is stored in bytes at end of key */
252 if (keylen < CTR_RFC3686_NONCE_SIZE)
253 return -EINVAL;
254
255 memcpy(ctx->nonce, key + (keylen - CTR_RFC3686_NONCE_SIZE),
256 CTR_RFC3686_NONCE_SIZE);
257
258 keylen -= CTR_RFC3686_NONCE_SIZE;
259
260 crypto_blkcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
261 crypto_blkcipher_set_flags(child, crypto_tfm_get_flags(parent) &
262 CRYPTO_TFM_REQ_MASK);
263 err = crypto_blkcipher_setkey(child, key, keylen);
264 crypto_tfm_set_flags(parent, crypto_blkcipher_get_flags(child) &
265 CRYPTO_TFM_RES_MASK);
266
267 return err;
268}
269
270static int crypto_rfc3686_crypt(struct blkcipher_desc *desc,
271 struct scatterlist *dst,
272 struct scatterlist *src, unsigned int nbytes)
273{
274 struct crypto_blkcipher *tfm = desc->tfm;
275 struct crypto_rfc3686_ctx *ctx = crypto_blkcipher_ctx(tfm);
276 struct crypto_blkcipher *child = ctx->child;
277 unsigned long alignmask = crypto_blkcipher_alignmask(tfm);
278 u8 ivblk[CTR_RFC3686_BLOCK_SIZE + alignmask];
279 u8 *iv = PTR_ALIGN(ivblk + 0, alignmask + 1);
280 u8 *info = desc->info;
281 int err;
282
283 /* set up counter block */
284 memcpy(iv, ctx->nonce, CTR_RFC3686_NONCE_SIZE);
285 memcpy(iv + CTR_RFC3686_NONCE_SIZE, info, CTR_RFC3686_IV_SIZE);
286
287 /* initialize counter portion of counter block */
288 *(__be32 *)(iv + CTR_RFC3686_NONCE_SIZE + CTR_RFC3686_IV_SIZE) =
289 cpu_to_be32(1);
290
291 desc->tfm = child;
292 desc->info = iv;
293 err = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes);
294 desc->tfm = tfm;
295 desc->info = info;
296
297 return err;
298}
299
300static int crypto_rfc3686_init_tfm(struct crypto_tfm *tfm)
301{
302 struct crypto_instance *inst = (void *)tfm->__crt_alg;
303 struct crypto_spawn *spawn = crypto_instance_ctx(inst);
304 struct crypto_rfc3686_ctx *ctx = crypto_tfm_ctx(tfm);
305 struct crypto_blkcipher *cipher;
306
307 cipher = crypto_spawn_blkcipher(spawn);
308 if (IS_ERR(cipher))
309 return PTR_ERR(cipher);
310
311 ctx->child = cipher;
312
313 return 0;
314}
315
316static void crypto_rfc3686_exit_tfm(struct crypto_tfm *tfm)
317{
318 struct crypto_rfc3686_ctx *ctx = crypto_tfm_ctx(tfm);
319
320 crypto_free_blkcipher(ctx->child);
321}
322
323static struct crypto_instance *crypto_rfc3686_alloc(struct rtattr **tb)
324{
325 struct crypto_instance *inst;
326 struct crypto_alg *alg;
327 int err;
328
329 err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_BLKCIPHER);
330 if (err)
331 return ERR_PTR(err);
332
333 alg = crypto_attr_alg(tb[1], CRYPTO_ALG_TYPE_BLKCIPHER,
334 CRYPTO_ALG_TYPE_MASK);
335 err = PTR_ERR(alg);
336 if (IS_ERR(alg))
337 return ERR_PTR(err);
338
339 /* We only support 16-byte blocks. */
340 err = -EINVAL;
341 if (alg->cra_blkcipher.ivsize != CTR_RFC3686_BLOCK_SIZE)
342 goto out_put_alg;
343
344 /* Not a stream cipher? */
345 if (alg->cra_blocksize != 1)
346 goto out_put_alg;
347
348 inst = crypto_alloc_instance("rfc3686", alg);
349 if (IS_ERR(inst))
350 goto out;
351
352 inst->alg.cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER;
353 inst->alg.cra_priority = alg->cra_priority;
354 inst->alg.cra_blocksize = 1;
355 inst->alg.cra_alignmask = alg->cra_alignmask;
356 inst->alg.cra_type = &crypto_blkcipher_type;
357
358 inst->alg.cra_blkcipher.ivsize = CTR_RFC3686_IV_SIZE;
359 inst->alg.cra_blkcipher.min_keysize = alg->cra_blkcipher.min_keysize
360 + CTR_RFC3686_NONCE_SIZE;
361 inst->alg.cra_blkcipher.max_keysize = alg->cra_blkcipher.max_keysize
362 + CTR_RFC3686_NONCE_SIZE;
363
364 inst->alg.cra_blkcipher.geniv = "seqiv";
365
366 inst->alg.cra_ctxsize = sizeof(struct crypto_rfc3686_ctx);
367
368 inst->alg.cra_init = crypto_rfc3686_init_tfm;
369 inst->alg.cra_exit = crypto_rfc3686_exit_tfm;
370
371 inst->alg.cra_blkcipher.setkey = crypto_rfc3686_setkey;
372 inst->alg.cra_blkcipher.encrypt = crypto_rfc3686_crypt;
373 inst->alg.cra_blkcipher.decrypt = crypto_rfc3686_crypt;
374
375out:
376 crypto_mod_put(alg);
377 return inst;
378
379out_put_alg:
380 inst = ERR_PTR(err);
381 goto out;
382}
383
384static struct crypto_template crypto_rfc3686_tmpl = {
385 .name = "rfc3686",
386 .alloc = crypto_rfc3686_alloc,
387 .free = crypto_ctr_free,
388 .module = THIS_MODULE,
389};
390
391static int __init crypto_ctr_module_init(void)
392{
393 int err;
394
395 err = crypto_register_template(&crypto_ctr_tmpl);
396 if (err)
397 goto out;
398
399 err = crypto_register_template(&crypto_rfc3686_tmpl);
400 if (err)
401 goto out_drop_ctr;
402
403out:
404 return err;
405
406out_drop_ctr:
407 crypto_unregister_template(&crypto_ctr_tmpl);
408 goto out;
409}
410
411static void __exit crypto_ctr_module_exit(void)
412{
413 crypto_unregister_template(&crypto_rfc3686_tmpl);
414 crypto_unregister_template(&crypto_ctr_tmpl);
415}
416
417module_init(crypto_ctr_module_init);
418module_exit(crypto_ctr_module_exit);
419
420MODULE_LICENSE("GPL");
421MODULE_DESCRIPTION("CTR Counter block mode");
422MODULE_ALIAS("rfc3686");
diff --git a/crypto/des_generic.c b/crypto/des_generic.c
index 59966d14b8e0..355ecb71cb0d 100644
--- a/crypto/des_generic.c
+++ b/crypto/des_generic.c
@@ -20,13 +20,7 @@
20#include <linux/crypto.h> 20#include <linux/crypto.h>
21#include <linux/types.h> 21#include <linux/types.h>
22 22
23#define DES_KEY_SIZE 8 23#include <crypto/des.h>
24#define DES_EXPKEY_WORDS 32
25#define DES_BLOCK_SIZE 8
26
27#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
28#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
29#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
30 24
31#define ROL(x, r) ((x) = rol32((x), (r))) 25#define ROL(x, r) ((x) = rol32((x), (r)))
32#define ROR(x, r) ((x) = ror32((x), (r))) 26#define ROR(x, r) ((x) = ror32((x), (r)))
@@ -634,7 +628,7 @@ static const u32 S8[64] = {
634 * Choice 1 has operated on the key. 628 * Choice 1 has operated on the key.
635 * 629 *
636 */ 630 */
637static unsigned long ekey(u32 *pe, const u8 *k) 631unsigned long des_ekey(u32 *pe, const u8 *k)
638{ 632{
639 /* K&R: long is at least 32 bits */ 633 /* K&R: long is at least 32 bits */
640 unsigned long a, b, c, d, w; 634 unsigned long a, b, c, d, w;
@@ -709,6 +703,7 @@ static unsigned long ekey(u32 *pe, const u8 *k)
709 /* Zero if weak key */ 703 /* Zero if weak key */
710 return w; 704 return w;
711} 705}
706EXPORT_SYMBOL_GPL(des_ekey);
712 707
713/* 708/*
714 * Decryption key expansion 709 * Decryption key expansion
@@ -792,7 +787,7 @@ static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
792 int ret; 787 int ret;
793 788
794 /* Expand to tmp */ 789 /* Expand to tmp */
795 ret = ekey(tmp, key); 790 ret = des_ekey(tmp, key);
796 791
797 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) { 792 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
798 *flags |= CRYPTO_TFM_RES_WEAK_KEY; 793 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
@@ -879,9 +874,9 @@ static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key,
879 return -EINVAL; 874 return -EINVAL;
880 } 875 }
881 876
882 ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 877 des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE;
883 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 878 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE;
884 ekey(expkey, key); 879 des_ekey(expkey, key);
885 880
886 return 0; 881 return 0;
887} 882}
diff --git a/crypto/digest.c b/crypto/digest.c
index 8871dec8cae7..6fd43bddd545 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -12,6 +12,7 @@
12 * 12 *
13 */ 13 */
14 14
15#include <crypto/scatterwalk.h>
15#include <linux/mm.h> 16#include <linux/mm.h>
16#include <linux/errno.h> 17#include <linux/errno.h>
17#include <linux/hardirq.h> 18#include <linux/hardirq.h>
@@ -20,9 +21,6 @@
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
22 23
23#include "internal.h"
24#include "scatterwalk.h"
25
26static int init(struct hash_desc *desc) 24static int init(struct hash_desc *desc)
27{ 25{
28 struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm); 26 struct crypto_tfm *tfm = crypto_hash_tfm(desc->tfm);
diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c
new file mode 100644
index 000000000000..eb90d27ae118
--- /dev/null
+++ b/crypto/eseqiv.c
@@ -0,0 +1,264 @@
1/*
2 * eseqiv: Encrypted Sequence Number IV Generator
3 *
4 * This generator generates an IV based on a sequence number by xoring it
5 * with a salt and then encrypting it with the same key as used to encrypt
6 * the plain text. This algorithm requires that the block size be equal
7 * to the IV size. It is mainly useful for CBC.
8 *
9 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 */
17
18#include <crypto/internal/skcipher.h>
19#include <crypto/scatterwalk.h>
20#include <linux/err.h>
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/mm.h>
24#include <linux/module.h>
25#include <linux/random.h>
26#include <linux/scatterlist.h>
27#include <linux/spinlock.h>
28#include <linux/string.h>
29
30struct eseqiv_request_ctx {
31 struct scatterlist src[2];
32 struct scatterlist dst[2];
33 char tail[];
34};
35
36struct eseqiv_ctx {
37 spinlock_t lock;
38 unsigned int reqoff;
39 char salt[];
40};
41
42static void eseqiv_complete2(struct skcipher_givcrypt_request *req)
43{
44 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
45 struct eseqiv_request_ctx *reqctx = skcipher_givcrypt_reqctx(req);
46
47 memcpy(req->giv, PTR_ALIGN((u8 *)reqctx->tail,
48 crypto_ablkcipher_alignmask(geniv) + 1),
49 crypto_ablkcipher_ivsize(geniv));
50}
51
52static void eseqiv_complete(struct crypto_async_request *base, int err)
53{
54 struct skcipher_givcrypt_request *req = base->data;
55
56 if (err)
57 goto out;
58
59 eseqiv_complete2(req);
60
61out:
62 skcipher_givcrypt_complete(req, err);
63}
64
65static void eseqiv_chain(struct scatterlist *head, struct scatterlist *sg,
66 int chain)
67{
68 if (chain) {
69 head->length += sg->length;
70 sg = scatterwalk_sg_next(sg);
71 }
72
73 if (sg)
74 scatterwalk_sg_chain(head, 2, sg);
75 else
76 sg_mark_end(head);
77}
78
79static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
80{
81 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
82 struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
83 struct eseqiv_request_ctx *reqctx = skcipher_givcrypt_reqctx(req);
84 struct ablkcipher_request *subreq;
85 crypto_completion_t complete;
86 void *data;
87 struct scatterlist *osrc, *odst;
88 struct scatterlist *dst;
89 struct page *srcp;
90 struct page *dstp;
91 u8 *giv;
92 u8 *vsrc;
93 u8 *vdst;
94 __be64 seq;
95 unsigned int ivsize;
96 unsigned int len;
97 int err;
98
99 subreq = (void *)(reqctx->tail + ctx->reqoff);
100 ablkcipher_request_set_tfm(subreq, skcipher_geniv_cipher(geniv));
101
102 giv = req->giv;
103 complete = req->creq.base.complete;
104 data = req->creq.base.data;
105
106 osrc = req->creq.src;
107 odst = req->creq.dst;
108 srcp = sg_page(osrc);
109 dstp = sg_page(odst);
110 vsrc = PageHighMem(srcp) ? NULL : page_address(srcp) + osrc->offset;
111 vdst = PageHighMem(dstp) ? NULL : page_address(dstp) + odst->offset;
112
113 ivsize = crypto_ablkcipher_ivsize(geniv);
114
115 if (vsrc != giv + ivsize && vdst != giv + ivsize) {
116 giv = PTR_ALIGN((u8 *)reqctx->tail,
117 crypto_ablkcipher_alignmask(geniv) + 1);
118 complete = eseqiv_complete;
119 data = req;
120 }
121
122 ablkcipher_request_set_callback(subreq, req->creq.base.flags, complete,
123 data);
124
125 sg_init_table(reqctx->src, 2);
126 sg_set_buf(reqctx->src, giv, ivsize);
127 eseqiv_chain(reqctx->src, osrc, vsrc == giv + ivsize);
128
129 dst = reqctx->src;
130 if (osrc != odst) {
131 sg_init_table(reqctx->dst, 2);
132 sg_set_buf(reqctx->dst, giv, ivsize);
133 eseqiv_chain(reqctx->dst, odst, vdst == giv + ivsize);
134
135 dst = reqctx->dst;
136 }
137
138 ablkcipher_request_set_crypt(subreq, reqctx->src, dst,
139 req->creq.nbytes, req->creq.info);
140
141 memcpy(req->creq.info, ctx->salt, ivsize);
142
143 len = ivsize;
144 if (ivsize > sizeof(u64)) {
145 memset(req->giv, 0, ivsize - sizeof(u64));
146 len = sizeof(u64);
147 }
148 seq = cpu_to_be64(req->seq);
149 memcpy(req->giv + ivsize - len, &seq, len);
150
151 err = crypto_ablkcipher_encrypt(subreq);
152 if (err)
153 goto out;
154
155 eseqiv_complete2(req);
156
157out:
158 return err;
159}
160
161static int eseqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
162{
163 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
164 struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
165
166 spin_lock_bh(&ctx->lock);
167 if (crypto_ablkcipher_crt(geniv)->givencrypt != eseqiv_givencrypt_first)
168 goto unlock;
169
170 crypto_ablkcipher_crt(geniv)->givencrypt = eseqiv_givencrypt;
171 get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv));
172
173unlock:
174 spin_unlock_bh(&ctx->lock);
175
176 return eseqiv_givencrypt(req);
177}
178
179static int eseqiv_init(struct crypto_tfm *tfm)
180{
181 struct crypto_ablkcipher *geniv = __crypto_ablkcipher_cast(tfm);
182 struct eseqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
183 unsigned long alignmask;
184 unsigned int reqsize;
185
186 spin_lock_init(&ctx->lock);
187
188 alignmask = crypto_tfm_ctx_alignment() - 1;
189 reqsize = sizeof(struct eseqiv_request_ctx);
190
191 if (alignmask & reqsize) {
192 alignmask &= reqsize;
193 alignmask--;
194 }
195
196 alignmask = ~alignmask;
197 alignmask &= crypto_ablkcipher_alignmask(geniv);
198
199 reqsize += alignmask;
200 reqsize += crypto_ablkcipher_ivsize(geniv);
201 reqsize = ALIGN(reqsize, crypto_tfm_ctx_alignment());
202
203 ctx->reqoff = reqsize - sizeof(struct eseqiv_request_ctx);
204
205 tfm->crt_ablkcipher.reqsize = reqsize +
206 sizeof(struct ablkcipher_request);
207
208 return skcipher_geniv_init(tfm);
209}
210
211static struct crypto_template eseqiv_tmpl;
212
213static struct crypto_instance *eseqiv_alloc(struct rtattr **tb)
214{
215 struct crypto_instance *inst;
216 int err;
217
218 inst = skcipher_geniv_alloc(&eseqiv_tmpl, tb, 0, 0);
219 if (IS_ERR(inst))
220 goto out;
221
222 err = -EINVAL;
223 if (inst->alg.cra_ablkcipher.ivsize != inst->alg.cra_blocksize)
224 goto free_inst;
225
226 inst->alg.cra_ablkcipher.givencrypt = eseqiv_givencrypt_first;
227
228 inst->alg.cra_init = eseqiv_init;
229 inst->alg.cra_exit = skcipher_geniv_exit;
230
231 inst->alg.cra_ctxsize = sizeof(struct eseqiv_ctx);
232 inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize;
233
234out:
235 return inst;
236
237free_inst:
238 skcipher_geniv_free(inst);
239 inst = ERR_PTR(err);
240 goto out;
241}
242
243static struct crypto_template eseqiv_tmpl = {
244 .name = "eseqiv",
245 .alloc = eseqiv_alloc,
246 .free = skcipher_geniv_free,
247 .module = THIS_MODULE,
248};
249
250static int __init eseqiv_module_init(void)
251{
252 return crypto_register_template(&eseqiv_tmpl);
253}
254
255static void __exit eseqiv_module_exit(void)
256{
257 crypto_unregister_template(&eseqiv_tmpl);
258}
259
260module_init(eseqiv_module_init);
261module_exit(eseqiv_module_exit);
262
263MODULE_LICENSE("GPL");
264MODULE_DESCRIPTION("Encrypted Sequence Number IV Generator");
diff --git a/crypto/gcm.c b/crypto/gcm.c
new file mode 100644
index 000000000000..e70afd0c73dd
--- /dev/null
+++ b/crypto/gcm.c
@@ -0,0 +1,823 @@
1/*
2 * GCM: Galois/Counter Mode.
3 *
4 * Copyright (c) 2007 Nokia Siemens Networks - Mikko Herranen <mh1@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11#include <crypto/gf128mul.h>
12#include <crypto/internal/aead.h>
13#include <crypto/internal/skcipher.h>
14#include <crypto/scatterwalk.h>
15#include <linux/completion.h>
16#include <linux/err.h>
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/slab.h>
21
22struct gcm_instance_ctx {
23 struct crypto_skcipher_spawn ctr;
24};
25
26struct crypto_gcm_ctx {
27 struct crypto_ablkcipher *ctr;
28 struct gf128mul_4k *gf128;
29};
30
31struct crypto_rfc4106_ctx {
32 struct crypto_aead *child;
33 u8 nonce[4];
34};
35
36struct crypto_gcm_ghash_ctx {
37 u32 bytes;
38 u32 flags;
39 struct gf128mul_4k *gf128;
40 u8 buffer[16];
41};
42
43struct crypto_gcm_req_priv_ctx {
44 u8 auth_tag[16];
45 u8 iauth_tag[16];
46 struct scatterlist src[2];
47 struct scatterlist dst[2];
48 struct crypto_gcm_ghash_ctx ghash;
49 struct ablkcipher_request abreq;
50};
51
52struct crypto_gcm_setkey_result {
53 int err;
54 struct completion completion;
55};
56
57static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx(
58 struct aead_request *req)
59{
60 unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req));
61
62 return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1);
63}
64
65static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags,
66 struct gf128mul_4k *gf128)
67{
68 ctx->bytes = 0;
69 ctx->flags = flags;
70 ctx->gf128 = gf128;
71 memset(ctx->buffer, 0, 16);
72}
73
74static void crypto_gcm_ghash_update(struct crypto_gcm_ghash_ctx *ctx,
75 const u8 *src, unsigned int srclen)
76{
77 u8 *dst = ctx->buffer;
78
79 if (ctx->bytes) {
80 int n = min(srclen, ctx->bytes);
81 u8 *pos = dst + (16 - ctx->bytes);
82
83 ctx->bytes -= n;
84 srclen -= n;
85
86 while (n--)
87 *pos++ ^= *src++;
88
89 if (!ctx->bytes)
90 gf128mul_4k_lle((be128 *)dst, ctx->gf128);
91 }
92
93 while (srclen >= 16) {
94 crypto_xor(dst, src, 16);
95 gf128mul_4k_lle((be128 *)dst, ctx->gf128);
96 src += 16;
97 srclen -= 16;
98 }
99
100 if (srclen) {
101 ctx->bytes = 16 - srclen;
102 while (srclen--)
103 *dst++ ^= *src++;
104 }
105}
106
107static void crypto_gcm_ghash_update_sg(struct crypto_gcm_ghash_ctx *ctx,
108 struct scatterlist *sg, int len)
109{
110 struct scatter_walk walk;
111 u8 *src;
112 int n;
113
114 if (!len)
115 return;
116
117 scatterwalk_start(&walk, sg);
118
119 while (len) {
120 n = scatterwalk_clamp(&walk, len);
121
122 if (!n) {
123 scatterwalk_start(&walk, scatterwalk_sg_next(walk.sg));
124 n = scatterwalk_clamp(&walk, len);
125 }
126
127 src = scatterwalk_map(&walk, 0);
128
129 crypto_gcm_ghash_update(ctx, src, n);
130 len -= n;
131
132 scatterwalk_unmap(src, 0);
133 scatterwalk_advance(&walk, n);
134 scatterwalk_done(&walk, 0, len);
135 if (len)
136 crypto_yield(ctx->flags);
137 }
138}
139
140static void crypto_gcm_ghash_flush(struct crypto_gcm_ghash_ctx *ctx)
141{
142 u8 *dst = ctx->buffer;
143
144 if (ctx->bytes) {
145 u8 *tmp = dst + (16 - ctx->bytes);
146
147 while (ctx->bytes--)
148 *tmp++ ^= 0;
149
150 gf128mul_4k_lle((be128 *)dst, ctx->gf128);
151 }
152
153 ctx->bytes = 0;
154}
155
156static void crypto_gcm_ghash_final_xor(struct crypto_gcm_ghash_ctx *ctx,
157 unsigned int authlen,
158 unsigned int cryptlen, u8 *dst)
159{
160 u8 *buf = ctx->buffer;
161 u128 lengths;
162
163 lengths.a = cpu_to_be64(authlen * 8);
164 lengths.b = cpu_to_be64(cryptlen * 8);
165
166 crypto_gcm_ghash_flush(ctx);
167 crypto_xor(buf, (u8 *)&lengths, 16);
168 gf128mul_4k_lle((be128 *)buf, ctx->gf128);
169 crypto_xor(dst, buf, 16);
170}
171
172static void crypto_gcm_setkey_done(struct crypto_async_request *req, int err)
173{
174 struct crypto_gcm_setkey_result *result = req->data;
175
176 if (err == -EINPROGRESS)
177 return;
178
179 result->err = err;
180 complete(&result->completion);
181}
182
183static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key,
184 unsigned int keylen)
185{
186 struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead);
187 struct crypto_ablkcipher *ctr = ctx->ctr;
188 struct {
189 be128 hash;
190 u8 iv[8];
191
192 struct crypto_gcm_setkey_result result;
193
194 struct scatterlist sg[1];
195 struct ablkcipher_request req;
196 } *data;
197 int err;
198
199 crypto_ablkcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK);
200 crypto_ablkcipher_set_flags(ctr, crypto_aead_get_flags(aead) &
201 CRYPTO_TFM_REQ_MASK);
202
203 err = crypto_ablkcipher_setkey(ctr, key, keylen);
204 if (err)
205 return err;
206
207 crypto_aead_set_flags(aead, crypto_ablkcipher_get_flags(ctr) &
208 CRYPTO_TFM_RES_MASK);
209
210 data = kzalloc(sizeof(*data) + crypto_ablkcipher_reqsize(ctr),
211 GFP_KERNEL);
212 if (!data)
213 return -ENOMEM;
214
215 init_completion(&data->result.completion);
216 sg_init_one(data->sg, &data->hash, sizeof(data->hash));
217 ablkcipher_request_set_tfm(&data->req, ctr);
218 ablkcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP |
219 CRYPTO_TFM_REQ_MAY_BACKLOG,
220 crypto_gcm_setkey_done,
221 &data->result);
222 ablkcipher_request_set_crypt(&data->req, data->sg, data->sg,
223 sizeof(data->hash), data->iv);
224
225 err = crypto_ablkcipher_encrypt(&data->req);
226 if (err == -EINPROGRESS || err == -EBUSY) {
227 err = wait_for_completion_interruptible(
228 &data->result.completion);
229 if (!err)
230 err = data->result.err;
231 }
232
233 if (err)
234 goto out;
235
236 if (ctx->gf128 != NULL)
237 gf128mul_free_4k(ctx->gf128);
238
239 ctx->gf128 = gf128mul_init_4k_lle(&data->hash);
240
241 if (ctx->gf128 == NULL)
242 err = -ENOMEM;
243
244out:
245 kfree(data);
246 return err;
247}
248
249static int crypto_gcm_setauthsize(struct crypto_aead *tfm,
250 unsigned int authsize)
251{
252 switch (authsize) {
253 case 4:
254 case 8:
255 case 12:
256 case 13:
257 case 14:
258 case 15:
259 case 16:
260 break;
261 default:
262 return -EINVAL;
263 }
264
265 return 0;
266}
267
268static void crypto_gcm_init_crypt(struct ablkcipher_request *ablk_req,
269 struct aead_request *req,
270 unsigned int cryptlen)
271{
272 struct crypto_aead *aead = crypto_aead_reqtfm(req);
273 struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead);
274 struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
275 u32 flags = req->base.tfm->crt_flags;
276 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash;
277 struct scatterlist *dst;
278 __be32 counter = cpu_to_be32(1);
279
280 memset(pctx->auth_tag, 0, sizeof(pctx->auth_tag));
281 memcpy(req->iv + 12, &counter, 4);
282
283 sg_init_table(pctx->src, 2);
284 sg_set_buf(pctx->src, pctx->auth_tag, sizeof(pctx->auth_tag));
285 scatterwalk_sg_chain(pctx->src, 2, req->src);
286
287 dst = pctx->src;
288 if (req->src != req->dst) {
289 sg_init_table(pctx->dst, 2);
290 sg_set_buf(pctx->dst, pctx->auth_tag, sizeof(pctx->auth_tag));
291 scatterwalk_sg_chain(pctx->dst, 2, req->dst);
292 dst = pctx->dst;
293 }
294
295 ablkcipher_request_set_tfm(ablk_req, ctx->ctr);
296 ablkcipher_request_set_crypt(ablk_req, pctx->src, dst,
297 cryptlen + sizeof(pctx->auth_tag),
298 req->iv);
299
300 crypto_gcm_ghash_init(ghash, flags, ctx->gf128);
301
302 crypto_gcm_ghash_update_sg(ghash, req->assoc, req->assoclen);
303 crypto_gcm_ghash_flush(ghash);
304}
305
306static int crypto_gcm_hash(struct aead_request *req)
307{
308 struct crypto_aead *aead = crypto_aead_reqtfm(req);
309 struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
310 u8 *auth_tag = pctx->auth_tag;
311 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash;
312
313 crypto_gcm_ghash_update_sg(ghash, req->dst, req->cryptlen);
314 crypto_gcm_ghash_final_xor(ghash, req->assoclen, req->cryptlen,
315 auth_tag);
316
317 scatterwalk_map_and_copy(auth_tag, req->dst, req->cryptlen,
318 crypto_aead_authsize(aead), 1);
319 return 0;
320}
321
322static void crypto_gcm_encrypt_done(struct crypto_async_request *areq, int err)
323{
324 struct aead_request *req = areq->data;
325
326 if (!err)
327 err = crypto_gcm_hash(req);
328
329 aead_request_complete(req, err);
330}
331
332static int crypto_gcm_encrypt(struct aead_request *req)
333{
334 struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
335 struct ablkcipher_request *abreq = &pctx->abreq;
336 int err;
337
338 crypto_gcm_init_crypt(abreq, req, req->cryptlen);
339 ablkcipher_request_set_callback(abreq, aead_request_flags(req),
340 crypto_gcm_encrypt_done, req);
341
342 err = crypto_ablkcipher_encrypt(abreq);
343 if (err)
344 return err;
345
346 return crypto_gcm_hash(req);
347}
348
349static int crypto_gcm_verify(struct aead_request *req)
350{
351 struct crypto_aead *aead = crypto_aead_reqtfm(req);
352 struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
353 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash;
354 u8 *auth_tag = pctx->auth_tag;
355 u8 *iauth_tag = pctx->iauth_tag;
356 unsigned int authsize = crypto_aead_authsize(aead);
357 unsigned int cryptlen = req->cryptlen - authsize;
358
359 crypto_gcm_ghash_final_xor(ghash, req->assoclen, cryptlen, auth_tag);
360
361 authsize = crypto_aead_authsize(aead);
362 scatterwalk_map_and_copy(iauth_tag, req->src, cryptlen, authsize, 0);
363 return memcmp(iauth_tag, auth_tag, authsize) ? -EBADMSG : 0;
364}
365
366static void crypto_gcm_decrypt_done(struct crypto_async_request *areq, int err)
367{
368 struct aead_request *req = areq->data;
369
370 if (!err)
371 err = crypto_gcm_verify(req);
372
373 aead_request_complete(req, err);
374}
375
376static int crypto_gcm_decrypt(struct aead_request *req)
377{
378 struct crypto_aead *aead = crypto_aead_reqtfm(req);
379 struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req);
380 struct ablkcipher_request *abreq = &pctx->abreq;
381 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash;
382 unsigned int cryptlen = req->cryptlen;
383 unsigned int authsize = crypto_aead_authsize(aead);
384 int err;
385
386 if (cryptlen < authsize)
387 return -EINVAL;
388 cryptlen -= authsize;
389
390 crypto_gcm_init_crypt(abreq, req, cryptlen);
391 ablkcipher_request_set_callback(abreq, aead_request_flags(req),
392 crypto_gcm_decrypt_done, req);
393
394 crypto_gcm_ghash_update_sg(ghash, req->src, cryptlen);
395
396 err = crypto_ablkcipher_decrypt(abreq);
397 if (err)
398 return err;
399
400 return crypto_gcm_verify(req);
401}
402
403static int crypto_gcm_init_tfm(struct crypto_tfm *tfm)
404{
405 struct crypto_instance *inst = (void *)tfm->__crt_alg;
406 struct gcm_instance_ctx *ictx = crypto_instance_ctx(inst);
407 struct crypto_gcm_ctx *ctx = crypto_tfm_ctx(tfm);
408 struct crypto_ablkcipher *ctr;
409 unsigned long align;
410 int err;
411
412 ctr = crypto_spawn_skcipher(&ictx->ctr);
413 err = PTR_ERR(ctr);
414 if (IS_ERR(ctr))
415 return err;
416
417 ctx->ctr = ctr;
418 ctx->gf128 = NULL;
419
420 align = crypto_tfm_alg_alignmask(tfm);
421 align &= ~(crypto_tfm_ctx_alignment() - 1);
422 tfm->crt_aead.reqsize = align +
423 sizeof(struct crypto_gcm_req_priv_ctx) +
424 crypto_ablkcipher_reqsize(ctr);
425
426 return 0;
427}
428
429static void crypto_gcm_exit_tfm(struct crypto_tfm *tfm)
430{
431 struct crypto_gcm_ctx *ctx = crypto_tfm_ctx(tfm);
432
433 if (ctx->gf128 != NULL)
434 gf128mul_free_4k(ctx->gf128);
435
436 crypto_free_ablkcipher(ctx->ctr);
437}
438
439static struct crypto_instance *crypto_gcm_alloc_common(struct rtattr **tb,
440 const char *full_name,
441 const char *ctr_name)
442{
443 struct crypto_attr_type *algt;
444 struct crypto_instance *inst;
445 struct crypto_alg *ctr;
446 struct gcm_instance_ctx *ctx;
447 int err;
448
449 algt = crypto_get_attr_type(tb);
450 err = PTR_ERR(algt);
451 if (IS_ERR(algt))
452 return ERR_PTR(err);
453
454 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
455 return ERR_PTR(-EINVAL);
456
457 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
458 if (!inst)
459 return ERR_PTR(-ENOMEM);
460
461 ctx = crypto_instance_ctx(inst);
462 crypto_set_skcipher_spawn(&ctx->ctr, inst);
463 err = crypto_grab_skcipher(&ctx->ctr, ctr_name, 0,
464 crypto_requires_sync(algt->type,
465 algt->mask));
466 if (err)
467 goto err_free_inst;
468
469 ctr = crypto_skcipher_spawn_alg(&ctx->ctr);
470
471 /* We only support 16-byte blocks. */
472 if (ctr->cra_ablkcipher.ivsize != 16)
473 goto out_put_ctr;
474
475 /* Not a stream cipher? */
476 err = -EINVAL;
477 if (ctr->cra_blocksize != 1)
478 goto out_put_ctr;
479
480 err = -ENAMETOOLONG;
481 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
482 "gcm_base(%s)", ctr->cra_driver_name) >=
483 CRYPTO_MAX_ALG_NAME)
484 goto out_put_ctr;
485
486 memcpy(inst->alg.cra_name, full_name, CRYPTO_MAX_ALG_NAME);
487
488 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
489 inst->alg.cra_flags |= ctr->cra_flags & CRYPTO_ALG_ASYNC;
490 inst->alg.cra_priority = ctr->cra_priority;
491 inst->alg.cra_blocksize = 1;
492 inst->alg.cra_alignmask = ctr->cra_alignmask | (__alignof__(u64) - 1);
493 inst->alg.cra_type = &crypto_aead_type;
494 inst->alg.cra_aead.ivsize = 16;
495 inst->alg.cra_aead.maxauthsize = 16;
496 inst->alg.cra_ctxsize = sizeof(struct crypto_gcm_ctx);
497 inst->alg.cra_init = crypto_gcm_init_tfm;
498 inst->alg.cra_exit = crypto_gcm_exit_tfm;
499 inst->alg.cra_aead.setkey = crypto_gcm_setkey;
500 inst->alg.cra_aead.setauthsize = crypto_gcm_setauthsize;
501 inst->alg.cra_aead.encrypt = crypto_gcm_encrypt;
502 inst->alg.cra_aead.decrypt = crypto_gcm_decrypt;
503
504out:
505 return inst;
506
507out_put_ctr:
508 crypto_drop_skcipher(&ctx->ctr);
509err_free_inst:
510 kfree(inst);
511 inst = ERR_PTR(err);
512 goto out;
513}
514
515static struct crypto_instance *crypto_gcm_alloc(struct rtattr **tb)
516{
517 int err;
518 const char *cipher_name;
519 char ctr_name[CRYPTO_MAX_ALG_NAME];
520 char full_name[CRYPTO_MAX_ALG_NAME];
521
522 cipher_name = crypto_attr_alg_name(tb[1]);
523 err = PTR_ERR(cipher_name);
524 if (IS_ERR(cipher_name))
525 return ERR_PTR(err);
526
527 if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", cipher_name) >=
528 CRYPTO_MAX_ALG_NAME)
529 return ERR_PTR(-ENAMETOOLONG);
530
531 if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm(%s)", cipher_name) >=
532 CRYPTO_MAX_ALG_NAME)
533 return ERR_PTR(-ENAMETOOLONG);
534
535 return crypto_gcm_alloc_common(tb, full_name, ctr_name);
536}
537
538static void crypto_gcm_free(struct crypto_instance *inst)
539{
540 struct gcm_instance_ctx *ctx = crypto_instance_ctx(inst);
541
542 crypto_drop_skcipher(&ctx->ctr);
543 kfree(inst);
544}
545
546static struct crypto_template crypto_gcm_tmpl = {
547 .name = "gcm",
548 .alloc = crypto_gcm_alloc,
549 .free = crypto_gcm_free,
550 .module = THIS_MODULE,
551};
552
553static struct crypto_instance *crypto_gcm_base_alloc(struct rtattr **tb)
554{
555 int err;
556 const char *ctr_name;
557 char full_name[CRYPTO_MAX_ALG_NAME];
558
559 ctr_name = crypto_attr_alg_name(tb[1]);
560 err = PTR_ERR(ctr_name);
561 if (IS_ERR(ctr_name))
562 return ERR_PTR(err);
563
564 if (snprintf(full_name, CRYPTO_MAX_ALG_NAME, "gcm_base(%s)",
565 ctr_name) >= CRYPTO_MAX_ALG_NAME)
566 return ERR_PTR(-ENAMETOOLONG);
567
568 return crypto_gcm_alloc_common(tb, full_name, ctr_name);
569}
570
571static struct crypto_template crypto_gcm_base_tmpl = {
572 .name = "gcm_base",
573 .alloc = crypto_gcm_base_alloc,
574 .free = crypto_gcm_free,
575 .module = THIS_MODULE,
576};
577
578static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key,
579 unsigned int keylen)
580{
581 struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent);
582 struct crypto_aead *child = ctx->child;
583 int err;
584
585 if (keylen < 4)
586 return -EINVAL;
587
588 keylen -= 4;
589 memcpy(ctx->nonce, key + keylen, 4);
590
591 crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK);
592 crypto_aead_set_flags(child, crypto_aead_get_flags(parent) &
593 CRYPTO_TFM_REQ_MASK);
594 err = crypto_aead_setkey(child, key, keylen);
595 crypto_aead_set_flags(parent, crypto_aead_get_flags(child) &
596 CRYPTO_TFM_RES_MASK);
597
598 return err;
599}
600
601static int crypto_rfc4106_setauthsize(struct crypto_aead *parent,
602 unsigned int authsize)
603{
604 struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent);
605
606 switch (authsize) {
607 case 8:
608 case 12:
609 case 16:
610 break;
611 default:
612 return -EINVAL;
613 }
614
615 return crypto_aead_setauthsize(ctx->child, authsize);
616}
617
618static struct aead_request *crypto_rfc4106_crypt(struct aead_request *req)
619{
620 struct aead_request *subreq = aead_request_ctx(req);
621 struct crypto_aead *aead = crypto_aead_reqtfm(req);
622 struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(aead);
623 struct crypto_aead *child = ctx->child;
624 u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child),
625 crypto_aead_alignmask(child) + 1);
626
627 memcpy(iv, ctx->nonce, 4);
628 memcpy(iv + 4, req->iv, 8);
629
630 aead_request_set_tfm(subreq, child);
631 aead_request_set_callback(subreq, req->base.flags, req->base.complete,
632 req->base.data);
633 aead_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, iv);
634 aead_request_set_assoc(subreq, req->assoc, req->assoclen);
635
636 return subreq;
637}
638
639static int crypto_rfc4106_encrypt(struct aead_request *req)
640{
641 req = crypto_rfc4106_crypt(req);
642
643 return crypto_aead_encrypt(req);
644}
645
646static int crypto_rfc4106_decrypt(struct aead_request *req)
647{
648 req = crypto_rfc4106_crypt(req);
649
650 return crypto_aead_decrypt(req);
651}
652
653static int crypto_rfc4106_init_tfm(struct crypto_tfm *tfm)
654{
655 struct crypto_instance *inst = (void *)tfm->__crt_alg;
656 struct crypto_aead_spawn *spawn = crypto_instance_ctx(inst);
657 struct crypto_rfc4106_ctx *ctx = crypto_tfm_ctx(tfm);
658 struct crypto_aead *aead;
659 unsigned long align;
660
661 aead = crypto_spawn_aead(spawn);
662 if (IS_ERR(aead))
663 return PTR_ERR(aead);
664
665 ctx->child = aead;
666
667 align = crypto_aead_alignmask(aead);
668 align &= ~(crypto_tfm_ctx_alignment() - 1);
669 tfm->crt_aead.reqsize = sizeof(struct aead_request) +
670 ALIGN(crypto_aead_reqsize(aead),
671 crypto_tfm_ctx_alignment()) +
672 align + 16;
673
674 return 0;
675}
676
677static void crypto_rfc4106_exit_tfm(struct crypto_tfm *tfm)
678{
679 struct crypto_rfc4106_ctx *ctx = crypto_tfm_ctx(tfm);
680
681 crypto_free_aead(ctx->child);
682}
683
684static struct crypto_instance *crypto_rfc4106_alloc(struct rtattr **tb)
685{
686 struct crypto_attr_type *algt;
687 struct crypto_instance *inst;
688 struct crypto_aead_spawn *spawn;
689 struct crypto_alg *alg;
690 const char *ccm_name;
691 int err;
692
693 algt = crypto_get_attr_type(tb);
694 err = PTR_ERR(algt);
695 if (IS_ERR(algt))
696 return ERR_PTR(err);
697
698 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask)
699 return ERR_PTR(-EINVAL);
700
701 ccm_name = crypto_attr_alg_name(tb[1]);
702 err = PTR_ERR(ccm_name);
703 if (IS_ERR(ccm_name))
704 return ERR_PTR(err);
705
706 inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL);
707 if (!inst)
708 return ERR_PTR(-ENOMEM);
709
710 spawn = crypto_instance_ctx(inst);
711 crypto_set_aead_spawn(spawn, inst);
712 err = crypto_grab_aead(spawn, ccm_name, 0,
713 crypto_requires_sync(algt->type, algt->mask));
714 if (err)
715 goto out_free_inst;
716
717 alg = crypto_aead_spawn_alg(spawn);
718
719 err = -EINVAL;
720
721 /* We only support 16-byte blocks. */
722 if (alg->cra_aead.ivsize != 16)
723 goto out_drop_alg;
724
725 /* Not a stream cipher? */
726 if (alg->cra_blocksize != 1)
727 goto out_drop_alg;
728
729 err = -ENAMETOOLONG;
730 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME,
731 "rfc4106(%s)", alg->cra_name) >= CRYPTO_MAX_ALG_NAME ||
732 snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
733 "rfc4106(%s)", alg->cra_driver_name) >=
734 CRYPTO_MAX_ALG_NAME)
735 goto out_drop_alg;
736
737 inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD;
738 inst->alg.cra_flags |= alg->cra_flags & CRYPTO_ALG_ASYNC;
739 inst->alg.cra_priority = alg->cra_priority;
740 inst->alg.cra_blocksize = 1;
741 inst->alg.cra_alignmask = alg->cra_alignmask;
742 inst->alg.cra_type = &crypto_nivaead_type;
743
744 inst->alg.cra_aead.ivsize = 8;
745 inst->alg.cra_aead.maxauthsize = 16;
746
747 inst->alg.cra_ctxsize = sizeof(struct crypto_rfc4106_ctx);
748
749 inst->alg.cra_init = crypto_rfc4106_init_tfm;
750 inst->alg.cra_exit = crypto_rfc4106_exit_tfm;
751
752 inst->alg.cra_aead.setkey = crypto_rfc4106_setkey;
753 inst->alg.cra_aead.setauthsize = crypto_rfc4106_setauthsize;
754 inst->alg.cra_aead.encrypt = crypto_rfc4106_encrypt;
755 inst->alg.cra_aead.decrypt = crypto_rfc4106_decrypt;
756
757 inst->alg.cra_aead.geniv = "seqiv";
758
759out:
760 return inst;
761
762out_drop_alg:
763 crypto_drop_aead(spawn);
764out_free_inst:
765 kfree(inst);
766 inst = ERR_PTR(err);
767 goto out;
768}
769
770static void crypto_rfc4106_free(struct crypto_instance *inst)
771{
772 crypto_drop_spawn(crypto_instance_ctx(inst));
773 kfree(inst);
774}
775
776static struct crypto_template crypto_rfc4106_tmpl = {
777 .name = "rfc4106",
778 .alloc = crypto_rfc4106_alloc,
779 .free = crypto_rfc4106_free,
780 .module = THIS_MODULE,
781};
782
783static int __init crypto_gcm_module_init(void)
784{
785 int err;
786
787 err = crypto_register_template(&crypto_gcm_base_tmpl);
788 if (err)
789 goto out;
790
791 err = crypto_register_template(&crypto_gcm_tmpl);
792 if (err)
793 goto out_undo_base;
794
795 err = crypto_register_template(&crypto_rfc4106_tmpl);
796 if (err)
797 goto out_undo_gcm;
798
799out:
800 return err;
801
802out_undo_gcm:
803 crypto_unregister_template(&crypto_gcm_tmpl);
804out_undo_base:
805 crypto_unregister_template(&crypto_gcm_base_tmpl);
806 goto out;
807}
808
809static void __exit crypto_gcm_module_exit(void)
810{
811 crypto_unregister_template(&crypto_rfc4106_tmpl);
812 crypto_unregister_template(&crypto_gcm_tmpl);
813 crypto_unregister_template(&crypto_gcm_base_tmpl);
814}
815
816module_init(crypto_gcm_module_init);
817module_exit(crypto_gcm_module_exit);
818
819MODULE_LICENSE("GPL");
820MODULE_DESCRIPTION("Galois/Counter Mode");
821MODULE_AUTHOR("Mikko Herranen <mh1@iki.fi>");
822MODULE_ALIAS("gcm_base");
823MODULE_ALIAS("rfc4106");
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 0f05be769c34..a1d016a50e7d 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <crypto/algapi.h> 19#include <crypto/algapi.h>
20#include <crypto/scatterwalk.h>
20#include <linux/err.h> 21#include <linux/err.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
@@ -160,7 +161,7 @@ static int hmac_digest(struct hash_desc *pdesc, struct scatterlist *sg,
160 161
161 sg_init_table(sg1, 2); 162 sg_init_table(sg1, 2);
162 sg_set_buf(sg1, ipad, bs); 163 sg_set_buf(sg1, ipad, bs);
163 sg_set_page(&sg1[1], (void *) sg, 0, 0); 164 scatterwalk_sg_chain(sg1, 2, sg);
164 165
165 sg_init_table(sg2, 1); 166 sg_init_table(sg2, 1);
166 sg_set_buf(sg2, opad, bs + ds); 167 sg_set_buf(sg2, opad, bs + ds);
diff --git a/crypto/internal.h b/crypto/internal.h
index abb01f71f817..32f4c2145603 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -25,7 +25,6 @@
25#include <linux/notifier.h> 25#include <linux/notifier.h>
26#include <linux/rwsem.h> 26#include <linux/rwsem.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <asm/kmap_types.h>
29 28
30/* Crypto notification events. */ 29/* Crypto notification events. */
31enum { 30enum {
@@ -50,34 +49,6 @@ extern struct list_head crypto_alg_list;
50extern struct rw_semaphore crypto_alg_sem; 49extern struct rw_semaphore crypto_alg_sem;
51extern struct blocking_notifier_head crypto_chain; 50extern struct blocking_notifier_head crypto_chain;
52 51
53static inline enum km_type crypto_kmap_type(int out)
54{
55 enum km_type type;
56
57 if (in_softirq())
58 type = out * (KM_SOFTIRQ1 - KM_SOFTIRQ0) + KM_SOFTIRQ0;
59 else
60 type = out * (KM_USER1 - KM_USER0) + KM_USER0;
61
62 return type;
63}
64
65static inline void *crypto_kmap(struct page *page, int out)
66{
67 return kmap_atomic(page, crypto_kmap_type(out));
68}
69
70static inline void crypto_kunmap(void *vaddr, int out)
71{
72 kunmap_atomic(vaddr, crypto_kmap_type(out));
73}
74
75static inline void crypto_yield(u32 flags)
76{
77 if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
78 cond_resched();
79}
80
81#ifdef CONFIG_PROC_FS 52#ifdef CONFIG_PROC_FS
82void __init crypto_init_proc(void); 53void __init crypto_init_proc(void);
83void __exit crypto_exit_proc(void); 54void __exit crypto_exit_proc(void);
@@ -122,6 +93,8 @@ void crypto_exit_digest_ops(struct crypto_tfm *tfm);
122void crypto_exit_cipher_ops(struct crypto_tfm *tfm); 93void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
123void crypto_exit_compress_ops(struct crypto_tfm *tfm); 94void crypto_exit_compress_ops(struct crypto_tfm *tfm);
124 95
96void crypto_larval_kill(struct crypto_alg *alg);
97struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
125void crypto_larval_error(const char *name, u32 type, u32 mask); 98void crypto_larval_error(const char *name, u32 type, u32 mask);
126 99
127void crypto_shoot_alg(struct crypto_alg *alg); 100void crypto_shoot_alg(struct crypto_alg *alg);
diff --git a/crypto/lzo.c b/crypto/lzo.c
new file mode 100644
index 000000000000..48c32883f024
--- /dev/null
+++ b/crypto/lzo.c
@@ -0,0 +1,106 @@
1/*
2 * Cryptographic API.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 */
18
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/crypto.h>
22#include <linux/vmalloc.h>
23#include <linux/lzo.h>
24
25struct lzo_ctx {
26 void *lzo_comp_mem;
27};
28
29static int lzo_init(struct crypto_tfm *tfm)
30{
31 struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
32
33 ctx->lzo_comp_mem = vmalloc(LZO1X_MEM_COMPRESS);
34 if (!ctx->lzo_comp_mem)
35 return -ENOMEM;
36
37 return 0;
38}
39
40static void lzo_exit(struct crypto_tfm *tfm)
41{
42 struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
43
44 vfree(ctx->lzo_comp_mem);
45}
46
47static int lzo_compress(struct crypto_tfm *tfm, const u8 *src,
48 unsigned int slen, u8 *dst, unsigned int *dlen)
49{
50 struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
51 size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
52 int err;
53
54 err = lzo1x_1_compress(src, slen, dst, &tmp_len, ctx->lzo_comp_mem);
55
56 if (err != LZO_E_OK)
57 return -EINVAL;
58
59 *dlen = tmp_len;
60 return 0;
61}
62
63static int lzo_decompress(struct crypto_tfm *tfm, const u8 *src,
64 unsigned int slen, u8 *dst, unsigned int *dlen)
65{
66 int err;
67 size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
68
69 err = lzo1x_decompress_safe(src, slen, dst, &tmp_len);
70
71 if (err != LZO_E_OK)
72 return -EINVAL;
73
74 *dlen = tmp_len;
75 return 0;
76
77}
78
79static struct crypto_alg alg = {
80 .cra_name = "lzo",
81 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
82 .cra_ctxsize = sizeof(struct lzo_ctx),
83 .cra_module = THIS_MODULE,
84 .cra_list = LIST_HEAD_INIT(alg.cra_list),
85 .cra_init = lzo_init,
86 .cra_exit = lzo_exit,
87 .cra_u = { .compress = {
88 .coa_compress = lzo_compress,
89 .coa_decompress = lzo_decompress } }
90};
91
92static int __init init(void)
93{
94 return crypto_register_alg(&alg);
95}
96
97static void __exit fini(void)
98{
99 crypto_unregister_alg(&alg);
100}
101
102module_init(init);
103module_exit(fini);
104
105MODULE_LICENSE("GPL");
106MODULE_DESCRIPTION("LZO Compression Algorithm");
diff --git a/crypto/pcbc.c b/crypto/pcbc.c
index c3ed8a1c9f46..fe704775f88f 100644
--- a/crypto/pcbc.c
+++ b/crypto/pcbc.c
@@ -24,7 +24,6 @@
24 24
25struct crypto_pcbc_ctx { 25struct crypto_pcbc_ctx {
26 struct crypto_cipher *child; 26 struct crypto_cipher *child;
27 void (*xor)(u8 *dst, const u8 *src, unsigned int bs);
28}; 27};
29 28
30static int crypto_pcbc_setkey(struct crypto_tfm *parent, const u8 *key, 29static int crypto_pcbc_setkey(struct crypto_tfm *parent, const u8 *key,
@@ -45,9 +44,7 @@ static int crypto_pcbc_setkey(struct crypto_tfm *parent, const u8 *key,
45 44
46static int crypto_pcbc_encrypt_segment(struct blkcipher_desc *desc, 45static int crypto_pcbc_encrypt_segment(struct blkcipher_desc *desc,
47 struct blkcipher_walk *walk, 46 struct blkcipher_walk *walk,
48 struct crypto_cipher *tfm, 47 struct crypto_cipher *tfm)
49 void (*xor)(u8 *, const u8 *,
50 unsigned int))
51{ 48{
52 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 49 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
53 crypto_cipher_alg(tfm)->cia_encrypt; 50 crypto_cipher_alg(tfm)->cia_encrypt;
@@ -58,10 +55,10 @@ static int crypto_pcbc_encrypt_segment(struct blkcipher_desc *desc,
58 u8 *iv = walk->iv; 55 u8 *iv = walk->iv;
59 56
60 do { 57 do {
61 xor(iv, src, bsize); 58 crypto_xor(iv, src, bsize);
62 fn(crypto_cipher_tfm(tfm), dst, iv); 59 fn(crypto_cipher_tfm(tfm), dst, iv);
63 memcpy(iv, dst, bsize); 60 memcpy(iv, dst, bsize);
64 xor(iv, src, bsize); 61 crypto_xor(iv, src, bsize);
65 62
66 src += bsize; 63 src += bsize;
67 dst += bsize; 64 dst += bsize;
@@ -72,9 +69,7 @@ static int crypto_pcbc_encrypt_segment(struct blkcipher_desc *desc,
72 69
73static int crypto_pcbc_encrypt_inplace(struct blkcipher_desc *desc, 70static int crypto_pcbc_encrypt_inplace(struct blkcipher_desc *desc,
74 struct blkcipher_walk *walk, 71 struct blkcipher_walk *walk,
75 struct crypto_cipher *tfm, 72 struct crypto_cipher *tfm)
76 void (*xor)(u8 *, const u8 *,
77 unsigned int))
78{ 73{
79 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 74 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
80 crypto_cipher_alg(tfm)->cia_encrypt; 75 crypto_cipher_alg(tfm)->cia_encrypt;
@@ -86,10 +81,10 @@ static int crypto_pcbc_encrypt_inplace(struct blkcipher_desc *desc,
86 81
87 do { 82 do {
88 memcpy(tmpbuf, src, bsize); 83 memcpy(tmpbuf, src, bsize);
89 xor(iv, tmpbuf, bsize); 84 crypto_xor(iv, src, bsize);
90 fn(crypto_cipher_tfm(tfm), src, iv); 85 fn(crypto_cipher_tfm(tfm), src, iv);
91 memcpy(iv, src, bsize); 86 memcpy(iv, tmpbuf, bsize);
92 xor(iv, tmpbuf, bsize); 87 crypto_xor(iv, src, bsize);
93 88
94 src += bsize; 89 src += bsize;
95 } while ((nbytes -= bsize) >= bsize); 90 } while ((nbytes -= bsize) >= bsize);
@@ -107,7 +102,6 @@ static int crypto_pcbc_encrypt(struct blkcipher_desc *desc,
107 struct crypto_blkcipher *tfm = desc->tfm; 102 struct crypto_blkcipher *tfm = desc->tfm;
108 struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm); 103 struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
109 struct crypto_cipher *child = ctx->child; 104 struct crypto_cipher *child = ctx->child;
110 void (*xor)(u8 *, const u8 *, unsigned int bs) = ctx->xor;
111 int err; 105 int err;
112 106
113 blkcipher_walk_init(&walk, dst, src, nbytes); 107 blkcipher_walk_init(&walk, dst, src, nbytes);
@@ -115,11 +109,11 @@ static int crypto_pcbc_encrypt(struct blkcipher_desc *desc,
115 109
116 while ((nbytes = walk.nbytes)) { 110 while ((nbytes = walk.nbytes)) {
117 if (walk.src.virt.addr == walk.dst.virt.addr) 111 if (walk.src.virt.addr == walk.dst.virt.addr)
118 nbytes = crypto_pcbc_encrypt_inplace(desc, &walk, child, 112 nbytes = crypto_pcbc_encrypt_inplace(desc, &walk,
119 xor); 113 child);
120 else 114 else
121 nbytes = crypto_pcbc_encrypt_segment(desc, &walk, child, 115 nbytes = crypto_pcbc_encrypt_segment(desc, &walk,
122 xor); 116 child);
123 err = blkcipher_walk_done(desc, &walk, nbytes); 117 err = blkcipher_walk_done(desc, &walk, nbytes);
124 } 118 }
125 119
@@ -128,9 +122,7 @@ static int crypto_pcbc_encrypt(struct blkcipher_desc *desc,
128 122
129static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc, 123static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc,
130 struct blkcipher_walk *walk, 124 struct blkcipher_walk *walk,
131 struct crypto_cipher *tfm, 125 struct crypto_cipher *tfm)
132 void (*xor)(u8 *, const u8 *,
133 unsigned int))
134{ 126{
135 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 127 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
136 crypto_cipher_alg(tfm)->cia_decrypt; 128 crypto_cipher_alg(tfm)->cia_decrypt;
@@ -142,9 +134,9 @@ static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc,
142 134
143 do { 135 do {
144 fn(crypto_cipher_tfm(tfm), dst, src); 136 fn(crypto_cipher_tfm(tfm), dst, src);
145 xor(dst, iv, bsize); 137 crypto_xor(dst, iv, bsize);
146 memcpy(iv, src, bsize); 138 memcpy(iv, src, bsize);
147 xor(iv, dst, bsize); 139 crypto_xor(iv, dst, bsize);
148 140
149 src += bsize; 141 src += bsize;
150 dst += bsize; 142 dst += bsize;
@@ -157,9 +149,7 @@ static int crypto_pcbc_decrypt_segment(struct blkcipher_desc *desc,
157 149
158static int crypto_pcbc_decrypt_inplace(struct blkcipher_desc *desc, 150static int crypto_pcbc_decrypt_inplace(struct blkcipher_desc *desc,
159 struct blkcipher_walk *walk, 151 struct blkcipher_walk *walk,
160 struct crypto_cipher *tfm, 152 struct crypto_cipher *tfm)
161 void (*xor)(u8 *, const u8 *,
162 unsigned int))
163{ 153{
164 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) = 154 void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
165 crypto_cipher_alg(tfm)->cia_decrypt; 155 crypto_cipher_alg(tfm)->cia_decrypt;
@@ -172,9 +162,9 @@ static int crypto_pcbc_decrypt_inplace(struct blkcipher_desc *desc,
172 do { 162 do {
173 memcpy(tmpbuf, src, bsize); 163 memcpy(tmpbuf, src, bsize);
174 fn(crypto_cipher_tfm(tfm), src, src); 164 fn(crypto_cipher_tfm(tfm), src, src);
175 xor(src, iv, bsize); 165 crypto_xor(src, iv, bsize);
176 memcpy(iv, tmpbuf, bsize); 166 memcpy(iv, tmpbuf, bsize);
177 xor(iv, src, bsize); 167 crypto_xor(iv, src, bsize);
178 168
179 src += bsize; 169 src += bsize;
180 } while ((nbytes -= bsize) >= bsize); 170 } while ((nbytes -= bsize) >= bsize);
@@ -192,7 +182,6 @@ static int crypto_pcbc_decrypt(struct blkcipher_desc *desc,
192 struct crypto_blkcipher *tfm = desc->tfm; 182 struct crypto_blkcipher *tfm = desc->tfm;
193 struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm); 183 struct crypto_pcbc_ctx *ctx = crypto_blkcipher_ctx(tfm);
194 struct crypto_cipher *child = ctx->child; 184 struct crypto_cipher *child = ctx->child;
195 void (*xor)(u8 *, const u8 *, unsigned int bs) = ctx->xor;
196 int err; 185 int err;
197 186
198 blkcipher_walk_init(&walk, dst, src, nbytes); 187 blkcipher_walk_init(&walk, dst, src, nbytes);
@@ -200,48 +189,17 @@ static int crypto_pcbc_decrypt(struct blkcipher_desc *desc,
200 189
201 while ((nbytes = walk.nbytes)) { 190 while ((nbytes = walk.nbytes)) {
202 if (walk.src.virt.addr == walk.dst.virt.addr) 191 if (walk.src.virt.addr == walk.dst.virt.addr)
203 nbytes = crypto_pcbc_decrypt_inplace(desc, &walk, child, 192 nbytes = crypto_pcbc_decrypt_inplace(desc, &walk,
204 xor); 193 child);
205 else 194 else
206 nbytes = crypto_pcbc_decrypt_segment(desc, &walk, child, 195 nbytes = crypto_pcbc_decrypt_segment(desc, &walk,
207 xor); 196 child);
208 err = blkcipher_walk_done(desc, &walk, nbytes); 197 err = blkcipher_walk_done(desc, &walk, nbytes);
209 } 198 }
210 199
211 return err; 200 return err;
212} 201}
213 202
214static void xor_byte(u8 *a, const u8 *b, unsigned int bs)
215{
216 do {
217 *a++ ^= *b++;
218 } while (--bs);
219}
220
221static void xor_quad(u8 *dst, const u8 *src, unsigned int bs)
222{
223 u32 *a = (u32 *)dst;
224 u32 *b = (u32 *)src;
225
226 do {
227 *a++ ^= *b++;
228 } while ((bs -= 4));
229}
230
231static void xor_64(u8 *a, const u8 *b, unsigned int bs)
232{
233 ((u32 *)a)[0] ^= ((u32 *)b)[0];
234 ((u32 *)a)[1] ^= ((u32 *)b)[1];
235}
236
237static void xor_128(u8 *a, const u8 *b, unsigned int bs)
238{
239 ((u32 *)a)[0] ^= ((u32 *)b)[0];
240 ((u32 *)a)[1] ^= ((u32 *)b)[1];
241 ((u32 *)a)[2] ^= ((u32 *)b)[2];
242 ((u32 *)a)[3] ^= ((u32 *)b)[3];
243}
244
245static int crypto_pcbc_init_tfm(struct crypto_tfm *tfm) 203static int crypto_pcbc_init_tfm(struct crypto_tfm *tfm)
246{ 204{
247 struct crypto_instance *inst = (void *)tfm->__crt_alg; 205 struct crypto_instance *inst = (void *)tfm->__crt_alg;
@@ -249,22 +207,6 @@ static int crypto_pcbc_init_tfm(struct crypto_tfm *tfm)
249 struct crypto_pcbc_ctx *ctx = crypto_tfm_ctx(tfm); 207 struct crypto_pcbc_ctx *ctx = crypto_tfm_ctx(tfm);
250 struct crypto_cipher *cipher; 208 struct crypto_cipher *cipher;
251 209
252 switch (crypto_tfm_alg_blocksize(tfm)) {
253 case 8:
254 ctx->xor = xor_64;
255 break;
256
257 case 16:
258 ctx->xor = xor_128;
259 break;
260
261 default:
262 if (crypto_tfm_alg_blocksize(tfm) % 4)
263 ctx->xor = xor_byte;
264 else
265 ctx->xor = xor_quad;
266 }
267
268 cipher = crypto_spawn_cipher(spawn); 210 cipher = crypto_spawn_cipher(spawn);
269 if (IS_ERR(cipher)) 211 if (IS_ERR(cipher))
270 return PTR_ERR(cipher); 212 return PTR_ERR(cipher);
@@ -304,8 +246,9 @@ static struct crypto_instance *crypto_pcbc_alloc(struct rtattr **tb)
304 inst->alg.cra_alignmask = alg->cra_alignmask; 246 inst->alg.cra_alignmask = alg->cra_alignmask;
305 inst->alg.cra_type = &crypto_blkcipher_type; 247 inst->alg.cra_type = &crypto_blkcipher_type;
306 248
307 if (!(alg->cra_blocksize % 4)) 249 /* We access the data as u32s when xoring. */
308 inst->alg.cra_alignmask |= 3; 250 inst->alg.cra_alignmask |= __alignof__(u32) - 1;
251
309 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize; 252 inst->alg.cra_blkcipher.ivsize = alg->cra_blocksize;
310 inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize; 253 inst->alg.cra_blkcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
311 inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize; 254 inst->alg.cra_blkcipher.max_keysize = alg->cra_cipher.cia_max_keysize;
diff --git a/crypto/salsa20_generic.c b/crypto/salsa20_generic.c
new file mode 100644
index 000000000000..1fa4e4ddcab5
--- /dev/null
+++ b/crypto/salsa20_generic.c
@@ -0,0 +1,255 @@
1/*
2 * Salsa20: Salsa20 stream cipher algorithm
3 *
4 * Copyright (c) 2007 Tan Swee Heng <thesweeheng@gmail.com>
5 *
6 * Derived from:
7 * - salsa20.c: Public domain C code by Daniel J. Bernstein <djb@cr.yp.to>
8 *
9 * Salsa20 is a stream cipher candidate in eSTREAM, the ECRYPT Stream
10 * Cipher Project. It is designed by Daniel J. Bernstein <djb@cr.yp.to>.
11 * More information about eSTREAM and Salsa20 can be found here:
12 * http://www.ecrypt.eu.org/stream/
13 * http://cr.yp.to/snuffle.html
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the Free
17 * Software Foundation; either version 2 of the License, or (at your option)
18 * any later version.
19 *
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/crypto.h>
26#include <linux/types.h>
27#include <crypto/algapi.h>
28#include <asm/byteorder.h>
29
30#define SALSA20_IV_SIZE 8U
31#define SALSA20_MIN_KEY_SIZE 16U
32#define SALSA20_MAX_KEY_SIZE 32U
33
34/*
35 * Start of code taken from D. J. Bernstein's reference implementation.
36 * With some modifications and optimizations made to suit our needs.
37 */
38
39/*
40salsa20-ref.c version 20051118
41D. J. Bernstein
42Public domain.
43*/
44
45#define ROTATE(v,n) (((v) << (n)) | ((v) >> (32 - (n))))
46#define XOR(v,w) ((v) ^ (w))
47#define PLUS(v,w) (((v) + (w)))
48#define PLUSONE(v) (PLUS((v),1))
49#define U32TO8_LITTLE(p, v) \
50 { (p)[0] = (v >> 0) & 0xff; (p)[1] = (v >> 8) & 0xff; \
51 (p)[2] = (v >> 16) & 0xff; (p)[3] = (v >> 24) & 0xff; }
52#define U8TO32_LITTLE(p) \
53 (((u32)((p)[0]) ) | ((u32)((p)[1]) << 8) | \
54 ((u32)((p)[2]) << 16) | ((u32)((p)[3]) << 24) )
55
56struct salsa20_ctx
57{
58 u32 input[16];
59};
60
61static void salsa20_wordtobyte(u8 output[64], const u32 input[16])
62{
63 u32 x[16];
64 int i;
65
66 memcpy(x, input, sizeof(x));
67 for (i = 20; i > 0; i -= 2) {
68 x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 0],x[12]), 7));
69 x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[ 4],x[ 0]), 9));
70 x[12] = XOR(x[12],ROTATE(PLUS(x[ 8],x[ 4]),13));
71 x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[12],x[ 8]),18));
72 x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 5],x[ 1]), 7));
73 x[13] = XOR(x[13],ROTATE(PLUS(x[ 9],x[ 5]), 9));
74 x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[13],x[ 9]),13));
75 x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 1],x[13]),18));
76 x[14] = XOR(x[14],ROTATE(PLUS(x[10],x[ 6]), 7));
77 x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[14],x[10]), 9));
78 x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 2],x[14]),13));
79 x[10] = XOR(x[10],ROTATE(PLUS(x[ 6],x[ 2]),18));
80 x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[15],x[11]), 7));
81 x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 3],x[15]), 9));
82 x[11] = XOR(x[11],ROTATE(PLUS(x[ 7],x[ 3]),13));
83 x[15] = XOR(x[15],ROTATE(PLUS(x[11],x[ 7]),18));
84 x[ 1] = XOR(x[ 1],ROTATE(PLUS(x[ 0],x[ 3]), 7));
85 x[ 2] = XOR(x[ 2],ROTATE(PLUS(x[ 1],x[ 0]), 9));
86 x[ 3] = XOR(x[ 3],ROTATE(PLUS(x[ 2],x[ 1]),13));
87 x[ 0] = XOR(x[ 0],ROTATE(PLUS(x[ 3],x[ 2]),18));
88 x[ 6] = XOR(x[ 6],ROTATE(PLUS(x[ 5],x[ 4]), 7));
89 x[ 7] = XOR(x[ 7],ROTATE(PLUS(x[ 6],x[ 5]), 9));
90 x[ 4] = XOR(x[ 4],ROTATE(PLUS(x[ 7],x[ 6]),13));
91 x[ 5] = XOR(x[ 5],ROTATE(PLUS(x[ 4],x[ 7]),18));
92 x[11] = XOR(x[11],ROTATE(PLUS(x[10],x[ 9]), 7));
93 x[ 8] = XOR(x[ 8],ROTATE(PLUS(x[11],x[10]), 9));
94 x[ 9] = XOR(x[ 9],ROTATE(PLUS(x[ 8],x[11]),13));
95 x[10] = XOR(x[10],ROTATE(PLUS(x[ 9],x[ 8]),18));
96 x[12] = XOR(x[12],ROTATE(PLUS(x[15],x[14]), 7));
97 x[13] = XOR(x[13],ROTATE(PLUS(x[12],x[15]), 9));
98 x[14] = XOR(x[14],ROTATE(PLUS(x[13],x[12]),13));
99 x[15] = XOR(x[15],ROTATE(PLUS(x[14],x[13]),18));
100 }
101 for (i = 0; i < 16; ++i)
102 x[i] = PLUS(x[i],input[i]);
103 for (i = 0; i < 16; ++i)
104 U32TO8_LITTLE(output + 4 * i,x[i]);
105}
106
107static const char sigma[16] = "expand 32-byte k";
108static const char tau[16] = "expand 16-byte k";
109
110static void salsa20_keysetup(struct salsa20_ctx *ctx, const u8 *k, u32 kbytes)
111{
112 const char *constants;
113
114 ctx->input[1] = U8TO32_LITTLE(k + 0);
115 ctx->input[2] = U8TO32_LITTLE(k + 4);
116 ctx->input[3] = U8TO32_LITTLE(k + 8);
117 ctx->input[4] = U8TO32_LITTLE(k + 12);
118 if (kbytes == 32) { /* recommended */
119 k += 16;
120 constants = sigma;
121 } else { /* kbytes == 16 */
122 constants = tau;
123 }
124 ctx->input[11] = U8TO32_LITTLE(k + 0);
125 ctx->input[12] = U8TO32_LITTLE(k + 4);
126 ctx->input[13] = U8TO32_LITTLE(k + 8);
127 ctx->input[14] = U8TO32_LITTLE(k + 12);
128 ctx->input[0] = U8TO32_LITTLE(constants + 0);
129 ctx->input[5] = U8TO32_LITTLE(constants + 4);
130 ctx->input[10] = U8TO32_LITTLE(constants + 8);
131 ctx->input[15] = U8TO32_LITTLE(constants + 12);
132}
133
134static void salsa20_ivsetup(struct salsa20_ctx *ctx, const u8 *iv)
135{
136 ctx->input[6] = U8TO32_LITTLE(iv + 0);
137 ctx->input[7] = U8TO32_LITTLE(iv + 4);
138 ctx->input[8] = 0;
139 ctx->input[9] = 0;
140}
141
142static void salsa20_encrypt_bytes(struct salsa20_ctx *ctx, u8 *dst,
143 const u8 *src, unsigned int bytes)
144{
145 u8 buf[64];
146
147 if (dst != src)
148 memcpy(dst, src, bytes);
149
150 while (bytes) {
151 salsa20_wordtobyte(buf, ctx->input);
152
153 ctx->input[8] = PLUSONE(ctx->input[8]);
154 if (!ctx->input[8])
155 ctx->input[9] = PLUSONE(ctx->input[9]);
156
157 if (bytes <= 64) {
158 crypto_xor(dst, buf, bytes);
159 return;
160 }
161
162 crypto_xor(dst, buf, 64);
163 bytes -= 64;
164 dst += 64;
165 }
166}
167
168/*
169 * End of code taken from D. J. Bernstein's reference implementation.
170 */
171
172static int setkey(struct crypto_tfm *tfm, const u8 *key,
173 unsigned int keysize)
174{
175 struct salsa20_ctx *ctx = crypto_tfm_ctx(tfm);
176 salsa20_keysetup(ctx, key, keysize);
177 return 0;
178}
179
180static int encrypt(struct blkcipher_desc *desc,
181 struct scatterlist *dst, struct scatterlist *src,
182 unsigned int nbytes)
183{
184 struct blkcipher_walk walk;
185 struct crypto_blkcipher *tfm = desc->tfm;
186 struct salsa20_ctx *ctx = crypto_blkcipher_ctx(tfm);
187 int err;
188
189 blkcipher_walk_init(&walk, dst, src, nbytes);
190 err = blkcipher_walk_virt_block(desc, &walk, 64);
191
192 salsa20_ivsetup(ctx, walk.iv);
193
194 if (likely(walk.nbytes == nbytes))
195 {
196 salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
197 walk.src.virt.addr, nbytes);
198 return blkcipher_walk_done(desc, &walk, 0);
199 }
200
201 while (walk.nbytes >= 64) {
202 salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
203 walk.src.virt.addr,
204 walk.nbytes - (walk.nbytes % 64));
205 err = blkcipher_walk_done(desc, &walk, walk.nbytes % 64);
206 }
207
208 if (walk.nbytes) {
209 salsa20_encrypt_bytes(ctx, walk.dst.virt.addr,
210 walk.src.virt.addr, walk.nbytes);
211 err = blkcipher_walk_done(desc, &walk, 0);
212 }
213
214 return err;
215}
216
217static struct crypto_alg alg = {
218 .cra_name = "salsa20",
219 .cra_driver_name = "salsa20-generic",
220 .cra_priority = 100,
221 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
222 .cra_type = &crypto_blkcipher_type,
223 .cra_blocksize = 1,
224 .cra_ctxsize = sizeof(struct salsa20_ctx),
225 .cra_alignmask = 3,
226 .cra_module = THIS_MODULE,
227 .cra_list = LIST_HEAD_INIT(alg.cra_list),
228 .cra_u = {
229 .blkcipher = {
230 .setkey = setkey,
231 .encrypt = encrypt,
232 .decrypt = encrypt,
233 .min_keysize = SALSA20_MIN_KEY_SIZE,
234 .max_keysize = SALSA20_MAX_KEY_SIZE,
235 .ivsize = SALSA20_IV_SIZE,
236 }
237 }
238};
239
240static int __init init(void)
241{
242 return crypto_register_alg(&alg);
243}
244
245static void __exit fini(void)
246{
247 crypto_unregister_alg(&alg);
248}
249
250module_init(init);
251module_exit(fini);
252
253MODULE_LICENSE("GPL");
254MODULE_DESCRIPTION ("Salsa20 stream cipher algorithm");
255MODULE_ALIAS("salsa20");
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index b9bbda0bb9f9..9aeeb52004a5 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -13,6 +13,8 @@
13 * any later version. 13 * any later version.
14 * 14 *
15 */ 15 */
16
17#include <crypto/scatterwalk.h>
16#include <linux/kernel.h> 18#include <linux/kernel.h>
17#include <linux/mm.h> 19#include <linux/mm.h>
18#include <linux/module.h> 20#include <linux/module.h>
@@ -20,9 +22,6 @@
20#include <linux/highmem.h> 22#include <linux/highmem.h>
21#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
22 24
23#include "internal.h"
24#include "scatterwalk.h"
25
26static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out) 25static inline void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out)
27{ 26{
28 void *src = out ? buf : sgdata; 27 void *src = out ? buf : sgdata;
@@ -106,6 +105,9 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
106 struct scatter_walk walk; 105 struct scatter_walk walk;
107 unsigned int offset = 0; 106 unsigned int offset = 0;
108 107
108 if (!nbytes)
109 return;
110
109 for (;;) { 111 for (;;) {
110 scatterwalk_start(&walk, sg); 112 scatterwalk_start(&walk, sg);
111 113
@@ -113,7 +115,7 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg,
113 break; 115 break;
114 116
115 offset += sg->length; 117 offset += sg->length;
116 sg = sg_next(sg); 118 sg = scatterwalk_sg_next(sg);
117 } 119 }
118 120
119 scatterwalk_advance(&walk, start - offset); 121 scatterwalk_advance(&walk, start - offset);
diff --git a/crypto/seqiv.c b/crypto/seqiv.c
new file mode 100644
index 000000000000..b903aab31577
--- /dev/null
+++ b/crypto/seqiv.c
@@ -0,0 +1,345 @@
1/*
2 * seqiv: Sequence Number IV Generator
3 *
4 * This generator generates an IV based on a sequence number by xoring it
5 * with a salt. This algorithm is mainly useful for CTR and similar modes.
6 *
7 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 */
15
16#include <crypto/internal/aead.h>
17#include <crypto/internal/skcipher.h>
18#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/random.h>
23#include <linux/spinlock.h>
24#include <linux/string.h>
25
26struct seqiv_ctx {
27 spinlock_t lock;
28 u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
29};
30
31static void seqiv_complete2(struct skcipher_givcrypt_request *req, int err)
32{
33 struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
34 struct crypto_ablkcipher *geniv;
35
36 if (err == -EINPROGRESS)
37 return;
38
39 if (err)
40 goto out;
41
42 geniv = skcipher_givcrypt_reqtfm(req);
43 memcpy(req->creq.info, subreq->info, crypto_ablkcipher_ivsize(geniv));
44
45out:
46 kfree(subreq->info);
47}
48
49static void seqiv_complete(struct crypto_async_request *base, int err)
50{
51 struct skcipher_givcrypt_request *req = base->data;
52
53 seqiv_complete2(req, err);
54 skcipher_givcrypt_complete(req, err);
55}
56
57static void seqiv_aead_complete2(struct aead_givcrypt_request *req, int err)
58{
59 struct aead_request *subreq = aead_givcrypt_reqctx(req);
60 struct crypto_aead *geniv;
61
62 if (err == -EINPROGRESS)
63 return;
64
65 if (err)
66 goto out;
67
68 geniv = aead_givcrypt_reqtfm(req);
69 memcpy(req->areq.iv, subreq->iv, crypto_aead_ivsize(geniv));
70
71out:
72 kfree(subreq->iv);
73}
74
75static void seqiv_aead_complete(struct crypto_async_request *base, int err)
76{
77 struct aead_givcrypt_request *req = base->data;
78
79 seqiv_aead_complete2(req, err);
80 aead_givcrypt_complete(req, err);
81}
82
83static void seqiv_geniv(struct seqiv_ctx *ctx, u8 *info, u64 seq,
84 unsigned int ivsize)
85{
86 unsigned int len = ivsize;
87
88 if (ivsize > sizeof(u64)) {
89 memset(info, 0, ivsize - sizeof(u64));
90 len = sizeof(u64);
91 }
92 seq = cpu_to_be64(seq);
93 memcpy(info + ivsize - len, &seq, len);
94 crypto_xor(info, ctx->salt, ivsize);
95}
96
97static int seqiv_givencrypt(struct skcipher_givcrypt_request *req)
98{
99 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
100 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
101 struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
102 crypto_completion_t complete;
103 void *data;
104 u8 *info;
105 unsigned int ivsize;
106 int err;
107
108 ablkcipher_request_set_tfm(subreq, skcipher_geniv_cipher(geniv));
109
110 complete = req->creq.base.complete;
111 data = req->creq.base.data;
112 info = req->creq.info;
113
114 ivsize = crypto_ablkcipher_ivsize(geniv);
115
116 if (unlikely(!IS_ALIGNED((unsigned long)info,
117 crypto_ablkcipher_alignmask(geniv) + 1))) {
118 info = kmalloc(ivsize, req->creq.base.flags &
119 CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
120 GFP_ATOMIC);
121 if (!info)
122 return -ENOMEM;
123
124 complete = seqiv_complete;
125 data = req;
126 }
127
128 ablkcipher_request_set_callback(subreq, req->creq.base.flags, complete,
129 data);
130 ablkcipher_request_set_crypt(subreq, req->creq.src, req->creq.dst,
131 req->creq.nbytes, info);
132
133 seqiv_geniv(ctx, info, req->seq, ivsize);
134 memcpy(req->giv, info, ivsize);
135
136 err = crypto_ablkcipher_encrypt(subreq);
137 if (unlikely(info != req->creq.info))
138 seqiv_complete2(req, err);
139 return err;
140}
141
142static int seqiv_aead_givencrypt(struct aead_givcrypt_request *req)
143{
144 struct crypto_aead *geniv = aead_givcrypt_reqtfm(req);
145 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
146 struct aead_request *areq = &req->areq;
147 struct aead_request *subreq = aead_givcrypt_reqctx(req);
148 crypto_completion_t complete;
149 void *data;
150 u8 *info;
151 unsigned int ivsize;
152 int err;
153
154 aead_request_set_tfm(subreq, aead_geniv_base(geniv));
155
156 complete = areq->base.complete;
157 data = areq->base.data;
158 info = areq->iv;
159
160 ivsize = crypto_aead_ivsize(geniv);
161
162 if (unlikely(!IS_ALIGNED((unsigned long)info,
163 crypto_aead_alignmask(geniv) + 1))) {
164 info = kmalloc(ivsize, areq->base.flags &
165 CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
166 GFP_ATOMIC);
167 if (!info)
168 return -ENOMEM;
169
170 complete = seqiv_aead_complete;
171 data = req;
172 }
173
174 aead_request_set_callback(subreq, areq->base.flags, complete, data);
175 aead_request_set_crypt(subreq, areq->src, areq->dst, areq->cryptlen,
176 info);
177 aead_request_set_assoc(subreq, areq->assoc, areq->assoclen);
178
179 seqiv_geniv(ctx, info, req->seq, ivsize);
180 memcpy(req->giv, info, ivsize);
181
182 err = crypto_aead_encrypt(subreq);
183 if (unlikely(info != areq->iv))
184 seqiv_aead_complete2(req, err);
185 return err;
186}
187
188static int seqiv_givencrypt_first(struct skcipher_givcrypt_request *req)
189{
190 struct crypto_ablkcipher *geniv = skcipher_givcrypt_reqtfm(req);
191 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
192
193 spin_lock_bh(&ctx->lock);
194 if (crypto_ablkcipher_crt(geniv)->givencrypt != seqiv_givencrypt_first)
195 goto unlock;
196
197 crypto_ablkcipher_crt(geniv)->givencrypt = seqiv_givencrypt;
198 get_random_bytes(ctx->salt, crypto_ablkcipher_ivsize(geniv));
199
200unlock:
201 spin_unlock_bh(&ctx->lock);
202
203 return seqiv_givencrypt(req);
204}
205
206static int seqiv_aead_givencrypt_first(struct aead_givcrypt_request *req)
207{
208 struct crypto_aead *geniv = aead_givcrypt_reqtfm(req);
209 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
210
211 spin_lock_bh(&ctx->lock);
212 if (crypto_aead_crt(geniv)->givencrypt != seqiv_aead_givencrypt_first)
213 goto unlock;
214
215 crypto_aead_crt(geniv)->givencrypt = seqiv_aead_givencrypt;
216 get_random_bytes(ctx->salt, crypto_aead_ivsize(geniv));
217
218unlock:
219 spin_unlock_bh(&ctx->lock);
220
221 return seqiv_aead_givencrypt(req);
222}
223
224static int seqiv_init(struct crypto_tfm *tfm)
225{
226 struct crypto_ablkcipher *geniv = __crypto_ablkcipher_cast(tfm);
227 struct seqiv_ctx *ctx = crypto_ablkcipher_ctx(geniv);
228
229 spin_lock_init(&ctx->lock);
230
231 tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request);
232
233 return skcipher_geniv_init(tfm);
234}
235
236static int seqiv_aead_init(struct crypto_tfm *tfm)
237{
238 struct crypto_aead *geniv = __crypto_aead_cast(tfm);
239 struct seqiv_ctx *ctx = crypto_aead_ctx(geniv);
240
241 spin_lock_init(&ctx->lock);
242
243 tfm->crt_aead.reqsize = sizeof(struct aead_request);
244
245 return aead_geniv_init(tfm);
246}
247
248static struct crypto_template seqiv_tmpl;
249
250static struct crypto_instance *seqiv_ablkcipher_alloc(struct rtattr **tb)
251{
252 struct crypto_instance *inst;
253
254 inst = skcipher_geniv_alloc(&seqiv_tmpl, tb, 0, 0);
255
256 if (IS_ERR(inst))
257 goto out;
258
259 inst->alg.cra_ablkcipher.givencrypt = seqiv_givencrypt_first;
260
261 inst->alg.cra_init = seqiv_init;
262 inst->alg.cra_exit = skcipher_geniv_exit;
263
264 inst->alg.cra_ctxsize += inst->alg.cra_ablkcipher.ivsize;
265
266out:
267 return inst;
268}
269
270static struct crypto_instance *seqiv_aead_alloc(struct rtattr **tb)
271{
272 struct crypto_instance *inst;
273
274 inst = aead_geniv_alloc(&seqiv_tmpl, tb, 0, 0);
275
276 if (IS_ERR(inst))
277 goto out;
278
279 inst->alg.cra_aead.givencrypt = seqiv_aead_givencrypt_first;
280
281 inst->alg.cra_init = seqiv_aead_init;
282 inst->alg.cra_exit = aead_geniv_exit;
283
284 inst->alg.cra_ctxsize = inst->alg.cra_aead.ivsize;
285
286out:
287 return inst;
288}
289
290static struct crypto_instance *seqiv_alloc(struct rtattr **tb)
291{
292 struct crypto_attr_type *algt;
293 struct crypto_instance *inst;
294 int err;
295
296 algt = crypto_get_attr_type(tb);
297 err = PTR_ERR(algt);
298 if (IS_ERR(algt))
299 return ERR_PTR(err);
300
301 if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
302 inst = seqiv_ablkcipher_alloc(tb);
303 else
304 inst = seqiv_aead_alloc(tb);
305
306 if (IS_ERR(inst))
307 goto out;
308
309 inst->alg.cra_alignmask |= __alignof__(u32) - 1;
310 inst->alg.cra_ctxsize += sizeof(struct seqiv_ctx);
311
312out:
313 return inst;
314}
315
316static void seqiv_free(struct crypto_instance *inst)
317{
318 if ((inst->alg.cra_flags ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
319 skcipher_geniv_free(inst);
320 else
321 aead_geniv_free(inst);
322}
323
324static struct crypto_template seqiv_tmpl = {
325 .name = "seqiv",
326 .alloc = seqiv_alloc,
327 .free = seqiv_free,
328 .module = THIS_MODULE,
329};
330
331static int __init seqiv_module_init(void)
332{
333 return crypto_register_template(&seqiv_tmpl);
334}
335
336static void __exit seqiv_module_exit(void)
337{
338 crypto_unregister_template(&seqiv_tmpl);
339}
340
341module_init(seqiv_module_init);
342module_exit(seqiv_module_exit);
343
344MODULE_LICENSE("GPL");
345MODULE_DESCRIPTION("Sequence Number IV Generator");
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index fd3918be58b5..3cc93fd61043 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -9,6 +9,7 @@
9 * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com> 9 * Copyright (c) Jean-Luc Cooke <jlcooke@certainkey.com>
10 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk> 10 * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 11 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
12 * SHA224 Support Copyright 2007 Intel Corporation <jonathan.lynch@intel.com>
12 * 13 *
13 * This program is free software; you can redistribute it and/or modify it 14 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free 15 * under the terms of the GNU General Public License as published by the Free
@@ -218,6 +219,22 @@ static void sha256_transform(u32 *state, const u8 *input)
218 memset(W, 0, 64 * sizeof(u32)); 219 memset(W, 0, 64 * sizeof(u32));
219} 220}
220 221
222
223static void sha224_init(struct crypto_tfm *tfm)
224{
225 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
226 sctx->state[0] = SHA224_H0;
227 sctx->state[1] = SHA224_H1;
228 sctx->state[2] = SHA224_H2;
229 sctx->state[3] = SHA224_H3;
230 sctx->state[4] = SHA224_H4;
231 sctx->state[5] = SHA224_H5;
232 sctx->state[6] = SHA224_H6;
233 sctx->state[7] = SHA224_H7;
234 sctx->count[0] = 0;
235 sctx->count[1] = 0;
236}
237
221static void sha256_init(struct crypto_tfm *tfm) 238static void sha256_init(struct crypto_tfm *tfm)
222{ 239{
223 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); 240 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
@@ -294,8 +311,17 @@ static void sha256_final(struct crypto_tfm *tfm, u8 *out)
294 memset(sctx, 0, sizeof(*sctx)); 311 memset(sctx, 0, sizeof(*sctx));
295} 312}
296 313
314static void sha224_final(struct crypto_tfm *tfm, u8 *hash)
315{
316 u8 D[SHA256_DIGEST_SIZE];
317
318 sha256_final(tfm, D);
319
320 memcpy(hash, D, SHA224_DIGEST_SIZE);
321 memset(D, 0, SHA256_DIGEST_SIZE);
322}
297 323
298static struct crypto_alg alg = { 324static struct crypto_alg sha256 = {
299 .cra_name = "sha256", 325 .cra_name = "sha256",
300 .cra_driver_name= "sha256-generic", 326 .cra_driver_name= "sha256-generic",
301 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 327 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
@@ -303,28 +329,58 @@ static struct crypto_alg alg = {
303 .cra_ctxsize = sizeof(struct sha256_ctx), 329 .cra_ctxsize = sizeof(struct sha256_ctx),
304 .cra_module = THIS_MODULE, 330 .cra_module = THIS_MODULE,
305 .cra_alignmask = 3, 331 .cra_alignmask = 3,
306 .cra_list = LIST_HEAD_INIT(alg.cra_list), 332 .cra_list = LIST_HEAD_INIT(sha256.cra_list),
307 .cra_u = { .digest = { 333 .cra_u = { .digest = {
308 .dia_digestsize = SHA256_DIGEST_SIZE, 334 .dia_digestsize = SHA256_DIGEST_SIZE,
309 .dia_init = sha256_init, 335 .dia_init = sha256_init,
310 .dia_update = sha256_update, 336 .dia_update = sha256_update,
311 .dia_final = sha256_final } } 337 .dia_final = sha256_final } }
338};
339
340static struct crypto_alg sha224 = {
341 .cra_name = "sha224",
342 .cra_driver_name = "sha224-generic",
343 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
344 .cra_blocksize = SHA224_BLOCK_SIZE,
345 .cra_ctxsize = sizeof(struct sha256_ctx),
346 .cra_module = THIS_MODULE,
347 .cra_alignmask = 3,
348 .cra_list = LIST_HEAD_INIT(sha224.cra_list),
349 .cra_u = { .digest = {
350 .dia_digestsize = SHA224_DIGEST_SIZE,
351 .dia_init = sha224_init,
352 .dia_update = sha256_update,
353 .dia_final = sha224_final } }
312}; 354};
313 355
314static int __init init(void) 356static int __init init(void)
315{ 357{
316 return crypto_register_alg(&alg); 358 int ret = 0;
359
360 ret = crypto_register_alg(&sha224);
361
362 if (ret < 0)
363 return ret;
364
365 ret = crypto_register_alg(&sha256);
366
367 if (ret < 0)
368 crypto_unregister_alg(&sha224);
369
370 return ret;
317} 371}
318 372
319static void __exit fini(void) 373static void __exit fini(void)
320{ 374{
321 crypto_unregister_alg(&alg); 375 crypto_unregister_alg(&sha224);
376 crypto_unregister_alg(&sha256);
322} 377}
323 378
324module_init(init); 379module_init(init);
325module_exit(fini); 380module_exit(fini);
326 381
327MODULE_LICENSE("GPL"); 382MODULE_LICENSE("GPL");
328MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm"); 383MODULE_DESCRIPTION("SHA-224 and SHA-256 Secure Hash Algorithm");
329 384
385MODULE_ALIAS("sha224");
330MODULE_ALIAS("sha256"); 386MODULE_ALIAS("sha256");
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 24141fb6f5cb..1ab8c017a011 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -6,12 +6,16 @@
6 * 6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 12 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option) 13 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version. 14 * any later version.
14 * 15 *
16 * 2007-11-13 Added GCM tests
17 * 2007-11-13 Added AEAD support
18 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
15 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests 19 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
16 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) 20 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
17 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt 21 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
@@ -71,22 +75,23 @@ static unsigned int sec;
71 75
72static int mode; 76static int mode;
73static char *xbuf; 77static char *xbuf;
78static char *axbuf;
74static char *tvmem; 79static char *tvmem;
75 80
76static char *check[] = { 81static char *check[] = {
77 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", 82 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
78 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", 83 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
84 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
79 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", 85 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
80 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", 86 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
81 "camellia", "seed", NULL 87 "camellia", "seed", "salsa20", "lzo", NULL
82}; 88};
83 89
84static void hexdump(unsigned char *buf, unsigned int len) 90static void hexdump(unsigned char *buf, unsigned int len)
85{ 91{
86 while (len--) 92 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
87 printk("%02x", *buf++); 93 16, 1,
88 94 buf, len, false);
89 printk("\n");
90} 95}
91 96
92static void tcrypt_complete(struct crypto_async_request *req, int err) 97static void tcrypt_complete(struct crypto_async_request *req, int err)
@@ -215,6 +220,238 @@ out:
215 crypto_free_hash(tfm); 220 crypto_free_hash(tfm);
216} 221}
217 222
223static void test_aead(char *algo, int enc, struct aead_testvec *template,
224 unsigned int tcount)
225{
226 unsigned int ret, i, j, k, temp;
227 unsigned int tsize;
228 char *q;
229 struct crypto_aead *tfm;
230 char *key;
231 struct aead_testvec *aead_tv;
232 struct aead_request *req;
233 struct scatterlist sg[8];
234 struct scatterlist asg[8];
235 const char *e;
236 struct tcrypt_result result;
237 unsigned int authsize;
238
239 if (enc == ENCRYPT)
240 e = "encryption";
241 else
242 e = "decryption";
243
244 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
245
246 tsize = sizeof(struct aead_testvec);
247 tsize *= tcount;
248
249 if (tsize > TVMEMSIZE) {
250 printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
251 tsize, TVMEMSIZE);
252 return;
253 }
254
255 memcpy(tvmem, template, tsize);
256 aead_tv = (void *)tvmem;
257
258 init_completion(&result.completion);
259
260 tfm = crypto_alloc_aead(algo, 0, 0);
261
262 if (IS_ERR(tfm)) {
263 printk(KERN_INFO "failed to load transform for %s: %ld\n",
264 algo, PTR_ERR(tfm));
265 return;
266 }
267
268 req = aead_request_alloc(tfm, GFP_KERNEL);
269 if (!req) {
270 printk(KERN_INFO "failed to allocate request for %s\n", algo);
271 goto out;
272 }
273
274 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
275 tcrypt_complete, &result);
276
277 for (i = 0, j = 0; i < tcount; i++) {
278 if (!aead_tv[i].np) {
279 printk(KERN_INFO "test %u (%d bit key):\n",
280 ++j, aead_tv[i].klen * 8);
281
282 crypto_aead_clear_flags(tfm, ~0);
283 if (aead_tv[i].wk)
284 crypto_aead_set_flags(
285 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
286 key = aead_tv[i].key;
287
288 ret = crypto_aead_setkey(tfm, key,
289 aead_tv[i].klen);
290 if (ret) {
291 printk(KERN_INFO "setkey() failed flags=%x\n",
292 crypto_aead_get_flags(tfm));
293
294 if (!aead_tv[i].fail)
295 goto out;
296 }
297
298 authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
299 ret = crypto_aead_setauthsize(tfm, authsize);
300 if (ret) {
301 printk(KERN_INFO
302 "failed to set authsize = %u\n",
303 authsize);
304 goto out;
305 }
306
307 sg_init_one(&sg[0], aead_tv[i].input,
308 aead_tv[i].ilen + (enc ? authsize : 0));
309
310 sg_init_one(&asg[0], aead_tv[i].assoc,
311 aead_tv[i].alen);
312
313 aead_request_set_crypt(req, sg, sg,
314 aead_tv[i].ilen,
315 aead_tv[i].iv);
316
317 aead_request_set_assoc(req, asg, aead_tv[i].alen);
318
319 ret = enc ?
320 crypto_aead_encrypt(req) :
321 crypto_aead_decrypt(req);
322
323 switch (ret) {
324 case 0:
325 break;
326 case -EINPROGRESS:
327 case -EBUSY:
328 ret = wait_for_completion_interruptible(
329 &result.completion);
330 if (!ret && !(ret = result.err)) {
331 INIT_COMPLETION(result.completion);
332 break;
333 }
334 /* fall through */
335 default:
336 printk(KERN_INFO "%s () failed err=%d\n",
337 e, -ret);
338 goto out;
339 }
340
341 q = kmap(sg_page(&sg[0])) + sg[0].offset;
342 hexdump(q, aead_tv[i].rlen);
343
344 printk(KERN_INFO "enc/dec: %s\n",
345 memcmp(q, aead_tv[i].result,
346 aead_tv[i].rlen) ? "fail" : "pass");
347 }
348 }
349
350 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
351 memset(xbuf, 0, XBUFSIZE);
352 memset(axbuf, 0, XBUFSIZE);
353
354 for (i = 0, j = 0; i < tcount; i++) {
355 if (aead_tv[i].np) {
356 printk(KERN_INFO "test %u (%d bit key):\n",
357 ++j, aead_tv[i].klen * 8);
358
359 crypto_aead_clear_flags(tfm, ~0);
360 if (aead_tv[i].wk)
361 crypto_aead_set_flags(
362 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
363 key = aead_tv[i].key;
364
365 ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
366 if (ret) {
367 printk(KERN_INFO "setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm));
369
370 if (!aead_tv[i].fail)
371 goto out;
372 }
373
374 sg_init_table(sg, aead_tv[i].np);
375 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
376 memcpy(&xbuf[IDX[k]],
377 aead_tv[i].input + temp,
378 aead_tv[i].tap[k]);
379 temp += aead_tv[i].tap[k];
380 sg_set_buf(&sg[k], &xbuf[IDX[k]],
381 aead_tv[i].tap[k]);
382 }
383
384 authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
385 ret = crypto_aead_setauthsize(tfm, authsize);
386 if (ret) {
387 printk(KERN_INFO
388 "failed to set authsize = %u\n",
389 authsize);
390 goto out;
391 }
392
393 if (enc)
394 sg[k - 1].length += authsize;
395
396 sg_init_table(asg, aead_tv[i].anp);
397 for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
398 memcpy(&axbuf[IDX[k]],
399 aead_tv[i].assoc + temp,
400 aead_tv[i].atap[k]);
401 temp += aead_tv[i].atap[k];
402 sg_set_buf(&asg[k], &axbuf[IDX[k]],
403 aead_tv[i].atap[k]);
404 }
405
406 aead_request_set_crypt(req, sg, sg,
407 aead_tv[i].ilen,
408 aead_tv[i].iv);
409
410 aead_request_set_assoc(req, asg, aead_tv[i].alen);
411
412 ret = enc ?
413 crypto_aead_encrypt(req) :
414 crypto_aead_decrypt(req);
415
416 switch (ret) {
417 case 0:
418 break;
419 case -EINPROGRESS:
420 case -EBUSY:
421 ret = wait_for_completion_interruptible(
422 &result.completion);
423 if (!ret && !(ret = result.err)) {
424 INIT_COMPLETION(result.completion);
425 break;
426 }
427 /* fall through */
428 default:
429 printk(KERN_INFO "%s () failed err=%d\n",
430 e, -ret);
431 goto out;
432 }
433
434 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
435 printk(KERN_INFO "page %u\n", k);
436 q = kmap(sg_page(&sg[k])) + sg[k].offset;
437 hexdump(q, aead_tv[i].tap[k]);
438 printk(KERN_INFO "%s\n",
439 memcmp(q, aead_tv[i].result + temp,
440 aead_tv[i].tap[k] -
441 (k < aead_tv[i].np - 1 || enc ?
442 0 : authsize)) ?
443 "fail" : "pass");
444
445 temp += aead_tv[i].tap[k];
446 }
447 }
448 }
449
450out:
451 crypto_free_aead(tfm);
452 aead_request_free(req);
453}
454
218static void test_cipher(char *algo, int enc, 455static void test_cipher(char *algo, int enc,
219 struct cipher_testvec *template, unsigned int tcount) 456 struct cipher_testvec *template, unsigned int tcount)
220{ 457{
@@ -237,15 +474,11 @@ static void test_cipher(char *algo, int enc,
237 printk("\ntesting %s %s\n", algo, e); 474 printk("\ntesting %s %s\n", algo, e);
238 475
239 tsize = sizeof (struct cipher_testvec); 476 tsize = sizeof (struct cipher_testvec);
240 tsize *= tcount;
241
242 if (tsize > TVMEMSIZE) { 477 if (tsize > TVMEMSIZE) {
243 printk("template (%u) too big for tvmem (%u)\n", tsize, 478 printk("template (%u) too big for tvmem (%u)\n", tsize,
244 TVMEMSIZE); 479 TVMEMSIZE);
245 return; 480 return;
246 } 481 }
247
248 memcpy(tvmem, template, tsize);
249 cipher_tv = (void *)tvmem; 482 cipher_tv = (void *)tvmem;
250 483
251 init_completion(&result.completion); 484 init_completion(&result.completion);
@@ -269,33 +502,34 @@ static void test_cipher(char *algo, int enc,
269 502
270 j = 0; 503 j = 0;
271 for (i = 0; i < tcount; i++) { 504 for (i = 0; i < tcount; i++) {
272 if (!(cipher_tv[i].np)) { 505 memcpy(cipher_tv, &template[i], tsize);
506 if (!(cipher_tv->np)) {
273 j++; 507 j++;
274 printk("test %u (%d bit key):\n", 508 printk("test %u (%d bit key):\n",
275 j, cipher_tv[i].klen * 8); 509 j, cipher_tv->klen * 8);
276 510
277 crypto_ablkcipher_clear_flags(tfm, ~0); 511 crypto_ablkcipher_clear_flags(tfm, ~0);
278 if (cipher_tv[i].wk) 512 if (cipher_tv->wk)
279 crypto_ablkcipher_set_flags( 513 crypto_ablkcipher_set_flags(
280 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 514 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
281 key = cipher_tv[i].key; 515 key = cipher_tv->key;
282 516
283 ret = crypto_ablkcipher_setkey(tfm, key, 517 ret = crypto_ablkcipher_setkey(tfm, key,
284 cipher_tv[i].klen); 518 cipher_tv->klen);
285 if (ret) { 519 if (ret) {
286 printk("setkey() failed flags=%x\n", 520 printk("setkey() failed flags=%x\n",
287 crypto_ablkcipher_get_flags(tfm)); 521 crypto_ablkcipher_get_flags(tfm));
288 522
289 if (!cipher_tv[i].fail) 523 if (!cipher_tv->fail)
290 goto out; 524 goto out;
291 } 525 }
292 526
293 sg_init_one(&sg[0], cipher_tv[i].input, 527 sg_init_one(&sg[0], cipher_tv->input,
294 cipher_tv[i].ilen); 528 cipher_tv->ilen);
295 529
296 ablkcipher_request_set_crypt(req, sg, sg, 530 ablkcipher_request_set_crypt(req, sg, sg,
297 cipher_tv[i].ilen, 531 cipher_tv->ilen,
298 cipher_tv[i].iv); 532 cipher_tv->iv);
299 533
300 ret = enc ? 534 ret = enc ?
301 crypto_ablkcipher_encrypt(req) : 535 crypto_ablkcipher_encrypt(req) :
@@ -319,11 +553,11 @@ static void test_cipher(char *algo, int enc,
319 } 553 }
320 554
321 q = kmap(sg_page(&sg[0])) + sg[0].offset; 555 q = kmap(sg_page(&sg[0])) + sg[0].offset;
322 hexdump(q, cipher_tv[i].rlen); 556 hexdump(q, cipher_tv->rlen);
323 557
324 printk("%s\n", 558 printk("%s\n",
325 memcmp(q, cipher_tv[i].result, 559 memcmp(q, cipher_tv->result,
326 cipher_tv[i].rlen) ? "fail" : "pass"); 560 cipher_tv->rlen) ? "fail" : "pass");
327 } 561 }
328 } 562 }
329 563
@@ -332,41 +566,42 @@ static void test_cipher(char *algo, int enc,
332 566
333 j = 0; 567 j = 0;
334 for (i = 0; i < tcount; i++) { 568 for (i = 0; i < tcount; i++) {
335 if (cipher_tv[i].np) { 569 memcpy(cipher_tv, &template[i], tsize);
570 if (cipher_tv->np) {
336 j++; 571 j++;
337 printk("test %u (%d bit key):\n", 572 printk("test %u (%d bit key):\n",
338 j, cipher_tv[i].klen * 8); 573 j, cipher_tv->klen * 8);
339 574
340 crypto_ablkcipher_clear_flags(tfm, ~0); 575 crypto_ablkcipher_clear_flags(tfm, ~0);
341 if (cipher_tv[i].wk) 576 if (cipher_tv->wk)
342 crypto_ablkcipher_set_flags( 577 crypto_ablkcipher_set_flags(
343 tfm, CRYPTO_TFM_REQ_WEAK_KEY); 578 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
344 key = cipher_tv[i].key; 579 key = cipher_tv->key;
345 580
346 ret = crypto_ablkcipher_setkey(tfm, key, 581 ret = crypto_ablkcipher_setkey(tfm, key,
347 cipher_tv[i].klen); 582 cipher_tv->klen);
348 if (ret) { 583 if (ret) {
349 printk("setkey() failed flags=%x\n", 584 printk("setkey() failed flags=%x\n",
350 crypto_ablkcipher_get_flags(tfm)); 585 crypto_ablkcipher_get_flags(tfm));
351 586
352 if (!cipher_tv[i].fail) 587 if (!cipher_tv->fail)
353 goto out; 588 goto out;
354 } 589 }
355 590
356 temp = 0; 591 temp = 0;
357 sg_init_table(sg, cipher_tv[i].np); 592 sg_init_table(sg, cipher_tv->np);
358 for (k = 0; k < cipher_tv[i].np; k++) { 593 for (k = 0; k < cipher_tv->np; k++) {
359 memcpy(&xbuf[IDX[k]], 594 memcpy(&xbuf[IDX[k]],
360 cipher_tv[i].input + temp, 595 cipher_tv->input + temp,
361 cipher_tv[i].tap[k]); 596 cipher_tv->tap[k]);
362 temp += cipher_tv[i].tap[k]; 597 temp += cipher_tv->tap[k];
363 sg_set_buf(&sg[k], &xbuf[IDX[k]], 598 sg_set_buf(&sg[k], &xbuf[IDX[k]],
364 cipher_tv[i].tap[k]); 599 cipher_tv->tap[k]);
365 } 600 }
366 601
367 ablkcipher_request_set_crypt(req, sg, sg, 602 ablkcipher_request_set_crypt(req, sg, sg,
368 cipher_tv[i].ilen, 603 cipher_tv->ilen,
369 cipher_tv[i].iv); 604 cipher_tv->iv);
370 605
371 ret = enc ? 606 ret = enc ?
372 crypto_ablkcipher_encrypt(req) : 607 crypto_ablkcipher_encrypt(req) :
@@ -390,15 +625,15 @@ static void test_cipher(char *algo, int enc,
390 } 625 }
391 626
392 temp = 0; 627 temp = 0;
393 for (k = 0; k < cipher_tv[i].np; k++) { 628 for (k = 0; k < cipher_tv->np; k++) {
394 printk("page %u\n", k); 629 printk("page %u\n", k);
395 q = kmap(sg_page(&sg[k])) + sg[k].offset; 630 q = kmap(sg_page(&sg[k])) + sg[k].offset;
396 hexdump(q, cipher_tv[i].tap[k]); 631 hexdump(q, cipher_tv->tap[k]);
397 printk("%s\n", 632 printk("%s\n",
398 memcmp(q, cipher_tv[i].result + temp, 633 memcmp(q, cipher_tv->result + temp,
399 cipher_tv[i].tap[k]) ? "fail" : 634 cipher_tv->tap[k]) ? "fail" :
400 "pass"); 635 "pass");
401 temp += cipher_tv[i].tap[k]; 636 temp += cipher_tv->tap[k];
402 } 637 }
403 } 638 }
404 } 639 }
@@ -800,7 +1035,8 @@ out:
800 crypto_free_hash(tfm); 1035 crypto_free_hash(tfm);
801} 1036}
802 1037
803static void test_deflate(void) 1038static void test_comp(char *algo, struct comp_testvec *ctemplate,
1039 struct comp_testvec *dtemplate, int ctcount, int dtcount)
804{ 1040{
805 unsigned int i; 1041 unsigned int i;
806 char result[COMP_BUF_SIZE]; 1042 char result[COMP_BUF_SIZE];
@@ -808,25 +1044,26 @@ static void test_deflate(void)
808 struct comp_testvec *tv; 1044 struct comp_testvec *tv;
809 unsigned int tsize; 1045 unsigned int tsize;
810 1046
811 printk("\ntesting deflate compression\n"); 1047 printk("\ntesting %s compression\n", algo);
812 1048
813 tsize = sizeof (deflate_comp_tv_template); 1049 tsize = sizeof(struct comp_testvec);
1050 tsize *= ctcount;
814 if (tsize > TVMEMSIZE) { 1051 if (tsize > TVMEMSIZE) {
815 printk("template (%u) too big for tvmem (%u)\n", tsize, 1052 printk("template (%u) too big for tvmem (%u)\n", tsize,
816 TVMEMSIZE); 1053 TVMEMSIZE);
817 return; 1054 return;
818 } 1055 }
819 1056
820 memcpy(tvmem, deflate_comp_tv_template, tsize); 1057 memcpy(tvmem, ctemplate, tsize);
821 tv = (void *)tvmem; 1058 tv = (void *)tvmem;
822 1059
823 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC); 1060 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
824 if (IS_ERR(tfm)) { 1061 if (IS_ERR(tfm)) {
825 printk("failed to load transform for deflate\n"); 1062 printk("failed to load transform for %s\n", algo);
826 return; 1063 return;
827 } 1064 }
828 1065
829 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { 1066 for (i = 0; i < ctcount; i++) {
830 int ilen, ret, dlen = COMP_BUF_SIZE; 1067 int ilen, ret, dlen = COMP_BUF_SIZE;
831 1068
832 printk("test %u:\n", i + 1); 1069 printk("test %u:\n", i + 1);
@@ -845,19 +1082,20 @@ static void test_deflate(void)
845 ilen, dlen); 1082 ilen, dlen);
846 } 1083 }
847 1084
848 printk("\ntesting deflate decompression\n"); 1085 printk("\ntesting %s decompression\n", algo);
849 1086
850 tsize = sizeof (deflate_decomp_tv_template); 1087 tsize = sizeof(struct comp_testvec);
1088 tsize *= dtcount;
851 if (tsize > TVMEMSIZE) { 1089 if (tsize > TVMEMSIZE) {
852 printk("template (%u) too big for tvmem (%u)\n", tsize, 1090 printk("template (%u) too big for tvmem (%u)\n", tsize,
853 TVMEMSIZE); 1091 TVMEMSIZE);
854 goto out; 1092 goto out;
855 } 1093 }
856 1094
857 memcpy(tvmem, deflate_decomp_tv_template, tsize); 1095 memcpy(tvmem, dtemplate, tsize);
858 tv = (void *)tvmem; 1096 tv = (void *)tvmem;
859 1097
860 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { 1098 for (i = 0; i < dtcount; i++) {
861 int ilen, ret, dlen = COMP_BUF_SIZE; 1099 int ilen, ret, dlen = COMP_BUF_SIZE;
862 1100
863 printk("test %u:\n", i + 1); 1101 printk("test %u:\n", i + 1);
@@ -918,6 +1156,8 @@ static void do_test(void)
918 1156
919 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); 1157 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
920 1158
1159 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1160
921 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); 1161 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
922 1162
923 //BLOWFISH 1163 //BLOWFISH
@@ -969,6 +1209,18 @@ static void do_test(void)
969 AES_XTS_ENC_TEST_VECTORS); 1209 AES_XTS_ENC_TEST_VECTORS);
970 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, 1210 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
971 AES_XTS_DEC_TEST_VECTORS); 1211 AES_XTS_DEC_TEST_VECTORS);
1212 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1213 AES_CTR_ENC_TEST_VECTORS);
1214 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1215 AES_CTR_DEC_TEST_VECTORS);
1216 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1217 AES_GCM_ENC_TEST_VECTORS);
1218 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1219 AES_GCM_DEC_TEST_VECTORS);
1220 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1221 AES_CCM_ENC_TEST_VECTORS);
1222 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1223 AES_CCM_DEC_TEST_VECTORS);
972 1224
973 //CAST5 1225 //CAST5
974 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, 1226 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
@@ -1057,12 +1309,18 @@ static void do_test(void)
1057 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS); 1309 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1058 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS); 1310 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1059 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS); 1311 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1060 test_deflate(); 1312 test_comp("deflate", deflate_comp_tv_template,
1313 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1314 DEFLATE_DECOMP_TEST_VECTORS);
1315 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1316 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1061 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS); 1317 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1062 test_hash("hmac(md5)", hmac_md5_tv_template, 1318 test_hash("hmac(md5)", hmac_md5_tv_template,
1063 HMAC_MD5_TEST_VECTORS); 1319 HMAC_MD5_TEST_VECTORS);
1064 test_hash("hmac(sha1)", hmac_sha1_tv_template, 1320 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1065 HMAC_SHA1_TEST_VECTORS); 1321 HMAC_SHA1_TEST_VECTORS);
1322 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1323 HMAC_SHA224_TEST_VECTORS);
1066 test_hash("hmac(sha256)", hmac_sha256_tv_template, 1324 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1067 HMAC_SHA256_TEST_VECTORS); 1325 HMAC_SHA256_TEST_VECTORS);
1068 test_hash("hmac(sha384)", hmac_sha384_tv_template, 1326 test_hash("hmac(sha384)", hmac_sha384_tv_template,
@@ -1156,6 +1414,10 @@ static void do_test(void)
1156 AES_XTS_ENC_TEST_VECTORS); 1414 AES_XTS_ENC_TEST_VECTORS);
1157 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, 1415 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1158 AES_XTS_DEC_TEST_VECTORS); 1416 AES_XTS_DEC_TEST_VECTORS);
1417 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1418 AES_CTR_ENC_TEST_VECTORS);
1419 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1420 AES_CTR_DEC_TEST_VECTORS);
1159 break; 1421 break;
1160 1422
1161 case 11: 1423 case 11:
@@ -1167,7 +1429,9 @@ static void do_test(void)
1167 break; 1429 break;
1168 1430
1169 case 13: 1431 case 13:
1170 test_deflate(); 1432 test_comp("deflate", deflate_comp_tv_template,
1433 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1434 DEFLATE_DECOMP_TEST_VECTORS);
1171 break; 1435 break;
1172 1436
1173 case 14: 1437 case 14:
@@ -1291,6 +1555,34 @@ static void do_test(void)
1291 camellia_cbc_dec_tv_template, 1555 camellia_cbc_dec_tv_template,
1292 CAMELLIA_CBC_DEC_TEST_VECTORS); 1556 CAMELLIA_CBC_DEC_TEST_VECTORS);
1293 break; 1557 break;
1558 case 33:
1559 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1560 break;
1561
1562 case 34:
1563 test_cipher("salsa20", ENCRYPT,
1564 salsa20_stream_enc_tv_template,
1565 SALSA20_STREAM_ENC_TEST_VECTORS);
1566 break;
1567
1568 case 35:
1569 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1570 AES_GCM_ENC_TEST_VECTORS);
1571 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1572 AES_GCM_DEC_TEST_VECTORS);
1573 break;
1574
1575 case 36:
1576 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1577 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1578 break;
1579
1580 case 37:
1581 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1582 AES_CCM_ENC_TEST_VECTORS);
1583 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1584 AES_CCM_DEC_TEST_VECTORS);
1585 break;
1294 1586
1295 case 100: 1587 case 100:
1296 test_hash("hmac(md5)", hmac_md5_tv_template, 1588 test_hash("hmac(md5)", hmac_md5_tv_template,
@@ -1317,6 +1609,15 @@ static void do_test(void)
1317 HMAC_SHA512_TEST_VECTORS); 1609 HMAC_SHA512_TEST_VECTORS);
1318 break; 1610 break;
1319 1611
1612 case 105:
1613 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1614 HMAC_SHA224_TEST_VECTORS);
1615 break;
1616
1617 case 106:
1618 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1619 XCBC_AES_TEST_VECTORS);
1620 break;
1320 1621
1321 case 200: 1622 case 200:
1322 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 1623 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
@@ -1400,6 +1701,11 @@ static void do_test(void)
1400 camellia_speed_template); 1701 camellia_speed_template);
1401 break; 1702 break;
1402 1703
1704 case 206:
1705 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1706 salsa20_speed_template);
1707 break;
1708
1403 case 300: 1709 case 300:
1404 /* fall through */ 1710 /* fall through */
1405 1711
@@ -1451,6 +1757,10 @@ static void do_test(void)
1451 test_hash_speed("tgr192", sec, generic_hash_speed_template); 1757 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1452 if (mode > 300 && mode < 400) break; 1758 if (mode > 300 && mode < 400) break;
1453 1759
1760 case 313:
1761 test_hash_speed("sha224", sec, generic_hash_speed_template);
1762 if (mode > 300 && mode < 400) break;
1763
1454 case 399: 1764 case 399:
1455 break; 1765 break;
1456 1766
@@ -1467,20 +1777,21 @@ static void do_test(void)
1467 1777
1468static int __init init(void) 1778static int __init init(void)
1469{ 1779{
1780 int err = -ENOMEM;
1781
1470 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); 1782 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1471 if (tvmem == NULL) 1783 if (tvmem == NULL)
1472 return -ENOMEM; 1784 return err;
1473 1785
1474 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL); 1786 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1475 if (xbuf == NULL) { 1787 if (xbuf == NULL)
1476 kfree(tvmem); 1788 goto err_free_tv;
1477 return -ENOMEM;
1478 }
1479 1789
1480 do_test(); 1790 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1791 if (axbuf == NULL)
1792 goto err_free_xbuf;
1481 1793
1482 kfree(xbuf); 1794 do_test();
1483 kfree(tvmem);
1484 1795
1485 /* We intentionaly return -EAGAIN to prevent keeping 1796 /* We intentionaly return -EAGAIN to prevent keeping
1486 * the module. It does all its work from init() 1797 * the module. It does all its work from init()
@@ -1488,7 +1799,15 @@ static int __init init(void)
1488 * => we don't need it in the memory, do we? 1799 * => we don't need it in the memory, do we?
1489 * -- mludvig 1800 * -- mludvig
1490 */ 1801 */
1491 return -EAGAIN; 1802 err = -EAGAIN;
1803
1804 kfree(axbuf);
1805 err_free_xbuf:
1806 kfree(xbuf);
1807 err_free_tv:
1808 kfree(tvmem);
1809
1810 return err;
1492} 1811}
1493 1812
1494/* 1813/*
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index ec861388d9a0..f785e5618e11 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -6,12 +6,15 @@
6 * 6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> 8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9 * Copyright (c) 2007 Nokia Siemens Networks
9 * 10 *
10 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free 12 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option) 13 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version. 14 * any later version.
14 * 15 *
16 * 2007-11-13 Added GCM tests
17 * 2007-11-13 Added AEAD support
15 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests 18 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
16 * 2004-08-09 Cipher speed tests by Reyk Floeter <reyk@vantronix.net> 19 * 2004-08-09 Cipher speed tests by Reyk Floeter <reyk@vantronix.net>
17 * 2003-09-14 Changes by Kartikey Mahendra Bhatt 20 * 2003-09-14 Changes by Kartikey Mahendra Bhatt
@@ -40,14 +43,32 @@ struct hash_testvec {
40struct cipher_testvec { 43struct cipher_testvec {
41 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4))); 44 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4)));
42 char iv[MAX_IVLEN]; 45 char iv[MAX_IVLEN];
46 char input[4100];
47 char result[4100];
48 unsigned char tap[MAX_TAP];
49 int np;
50 unsigned char fail;
51 unsigned char wk; /* weak key flag */
52 unsigned char klen;
53 unsigned short ilen;
54 unsigned short rlen;
55};
56
57struct aead_testvec {
58 char key[MAX_KEYLEN] __attribute__ ((__aligned__(4)));
59 char iv[MAX_IVLEN];
43 char input[512]; 60 char input[512];
61 char assoc[512];
44 char result[512]; 62 char result[512];
45 unsigned char tap[MAX_TAP]; 63 unsigned char tap[MAX_TAP];
64 unsigned char atap[MAX_TAP];
46 int np; 65 int np;
66 int anp;
47 unsigned char fail; 67 unsigned char fail;
48 unsigned char wk; /* weak key flag */ 68 unsigned char wk; /* weak key flag */
49 unsigned char klen; 69 unsigned char klen;
50 unsigned short ilen; 70 unsigned short ilen;
71 unsigned short alen;
51 unsigned short rlen; 72 unsigned short rlen;
52}; 73};
53 74
@@ -173,6 +194,33 @@ static struct hash_testvec sha1_tv_template[] = {
173 } 194 }
174}; 195};
175 196
197
198/*
199 * SHA224 test vectors from from FIPS PUB 180-2
200 */
201#define SHA224_TEST_VECTORS 2
202
203static struct hash_testvec sha224_tv_template[] = {
204 {
205 .plaintext = "abc",
206 .psize = 3,
207 .digest = { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22,
208 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3,
209 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7,
210 0xE3, 0x6C, 0x9D, 0xA7},
211 }, {
212 .plaintext =
213 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
214 .psize = 56,
215 .digest = { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC,
216 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50,
217 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19,
218 0x52, 0x52, 0x25, 0x25 },
219 .np = 2,
220 .tap = { 28, 28 }
221 }
222};
223
176/* 224/*
177 * SHA256 test vectors from from NIST 225 * SHA256 test vectors from from NIST
178 */ 226 */
@@ -817,6 +865,121 @@ static struct hash_testvec hmac_sha1_tv_template[] = {
817 }, 865 },
818}; 866};
819 867
868
869/*
870 * SHA224 HMAC test vectors from RFC4231
871 */
872#define HMAC_SHA224_TEST_VECTORS 4
873
874static struct hash_testvec hmac_sha224_tv_template[] = {
875 {
876 .key = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
877 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
878 0x0b, 0x0b, 0x0b, 0x0b },
879 .ksize = 20,
880 /* ("Hi There") */
881 .plaintext = { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 },
882 .psize = 8,
883 .digest = { 0x89, 0x6f, 0xb1, 0x12, 0x8a, 0xbb, 0xdf, 0x19,
884 0x68, 0x32, 0x10, 0x7c, 0xd4, 0x9d, 0xf3, 0x3f,
885 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f,
886 0x53, 0x68, 0x4b, 0x22},
887 }, {
888 .key = { 0x4a, 0x65, 0x66, 0x65 }, /* ("Jefe") */
889 .ksize = 4,
890 /* ("what do ya want for nothing?") */
891 .plaintext = { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20,
892 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20,
893 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68,
894 0x69, 0x6e, 0x67, 0x3f },
895 .psize = 28,
896 .digest = { 0xa3, 0x0e, 0x01, 0x09, 0x8b, 0xc6, 0xdb, 0xbf,
897 0x45, 0x69, 0x0f, 0x3a, 0x7e, 0x9e, 0x6d, 0x0f,
898 0x8b, 0xbe, 0xa2, 0xa3, 0x9e, 0x61, 0x48, 0x00,
899 0x8f, 0xd0, 0x5e, 0x44 },
900 .np = 4,
901 .tap = { 7, 7, 7, 7 }
902 }, {
903 .key = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
904 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
905 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
906 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
907 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
908 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
909 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
910 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
911 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
912 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
913 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
914 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
915 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
916 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
917 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
918 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
919 0xaa, 0xaa, 0xaa },
920 .ksize = 131,
921 /* ("Test Using Larger Than Block-Size Key - Hash Key First") */
922 .plaintext = { 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x73, 0x69,
923 0x6e, 0x67, 0x20, 0x4c, 0x61, 0x72, 0x67, 0x65,
924 0x72, 0x20, 0x54, 0x68, 0x61, 0x6e, 0x20, 0x42,
925 0x6c, 0x6f, 0x63, 0x6b, 0x2d, 0x53, 0x69, 0x7a,
926 0x65, 0x20, 0x4b, 0x65, 0x79, 0x20, 0x2d, 0x20,
927 0x48, 0x61, 0x73, 0x68, 0x20, 0x4b, 0x65, 0x79,
928 0x20, 0x46, 0x69, 0x72, 0x73, 0x74 },
929 .psize = 54,
930 .digest = { 0x95, 0xe9, 0xa0, 0xdb, 0x96, 0x20, 0x95, 0xad,
931 0xae, 0xbe, 0x9b, 0x2d, 0x6f, 0x0d, 0xbc, 0xe2,
932 0xd4, 0x99, 0xf1, 0x12, 0xf2, 0xd2, 0xb7, 0x27,
933 0x3f, 0xa6, 0x87, 0x0e },
934 }, {
935 .key = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
936 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
937 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
938 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
939 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
940 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
941 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
942 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
943 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
944 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
945 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
946 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
947 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
948 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
949 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
950 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
951 0xaa, 0xaa, 0xaa },
952 .ksize = 131,
953 /* ("This is a test using a larger than block-size key and a")
954 (" larger than block-size data. The key needs to be")
955 (" hashed before being used by the HMAC algorithm.") */
956 .plaintext = { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
957 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x75,
958 0x73, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x6c,
959 0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74, 0x68,
960 0x61, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63, 0x6b,
961 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6b, 0x65,
962 0x79, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x20,
963 0x6c, 0x61, 0x72, 0x67, 0x65, 0x72, 0x20, 0x74,
964 0x68, 0x61, 0x6e, 0x20, 0x62, 0x6c, 0x6f, 0x63,
965 0x6b, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x64,
966 0x61, 0x74, 0x61, 0x2e, 0x20, 0x54, 0x68, 0x65,
967 0x20, 0x6b, 0x65, 0x79, 0x20, 0x6e, 0x65, 0x65,
968 0x64, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65,
969 0x20, 0x68, 0x61, 0x73, 0x68, 0x65, 0x64, 0x20,
970 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x20, 0x62,
971 0x65, 0x69, 0x6e, 0x67, 0x20, 0x75, 0x73, 0x65,
972 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65,
973 0x20, 0x48, 0x4d, 0x41, 0x43, 0x20, 0x61, 0x6c,
974 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x2e },
975 .psize = 152,
976 .digest = { 0x3a, 0x85, 0x41, 0x66, 0xac, 0x5d, 0x9f, 0x02,
977 0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd,
978 0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9,
979 0xf6, 0xf5, 0x65, 0xd1 },
980 },
981};
982
820/* 983/*
821 * HMAC-SHA256 test vectors from 984 * HMAC-SHA256 test vectors from
822 * draft-ietf-ipsec-ciph-sha-256-01.txt 985 * draft-ietf-ipsec-ciph-sha-256-01.txt
@@ -2140,12 +2303,18 @@ static struct cipher_testvec cast6_dec_tv_template[] = {
2140 */ 2303 */
2141#define AES_ENC_TEST_VECTORS 3 2304#define AES_ENC_TEST_VECTORS 3
2142#define AES_DEC_TEST_VECTORS 3 2305#define AES_DEC_TEST_VECTORS 3
2143#define AES_CBC_ENC_TEST_VECTORS 2 2306#define AES_CBC_ENC_TEST_VECTORS 4
2144#define AES_CBC_DEC_TEST_VECTORS 2 2307#define AES_CBC_DEC_TEST_VECTORS 4
2145#define AES_LRW_ENC_TEST_VECTORS 8 2308#define AES_LRW_ENC_TEST_VECTORS 8
2146#define AES_LRW_DEC_TEST_VECTORS 8 2309#define AES_LRW_DEC_TEST_VECTORS 8
2147#define AES_XTS_ENC_TEST_VECTORS 4 2310#define AES_XTS_ENC_TEST_VECTORS 4
2148#define AES_XTS_DEC_TEST_VECTORS 4 2311#define AES_XTS_DEC_TEST_VECTORS 4
2312#define AES_CTR_ENC_TEST_VECTORS 7
2313#define AES_CTR_DEC_TEST_VECTORS 6
2314#define AES_GCM_ENC_TEST_VECTORS 9
2315#define AES_GCM_DEC_TEST_VECTORS 8
2316#define AES_CCM_ENC_TEST_VECTORS 7
2317#define AES_CCM_DEC_TEST_VECTORS 7
2149 2318
2150static struct cipher_testvec aes_enc_tv_template[] = { 2319static struct cipher_testvec aes_enc_tv_template[] = {
2151 { /* From FIPS-197 */ 2320 { /* From FIPS-197 */
@@ -2249,6 +2418,57 @@ static struct cipher_testvec aes_cbc_enc_tv_template[] = {
2249 0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, 2418 0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9,
2250 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 }, 2419 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 },
2251 .rlen = 32, 2420 .rlen = 32,
2421 }, { /* From NIST SP800-38A */
2422 .key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
2423 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
2424 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b },
2425 .klen = 24,
2426 .iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2427 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
2428 .input = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
2429 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
2430 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
2431 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
2432 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
2433 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
2434 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
2435 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
2436 .ilen = 64,
2437 .result = { 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
2438 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
2439 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4,
2440 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a,
2441 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0,
2442 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0,
2443 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81,
2444 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd },
2445 .rlen = 64,
2446 }, {
2447 .key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
2448 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
2449 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
2450 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 },
2451 .klen = 32,
2452 .iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2453 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
2454 .input = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
2455 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
2456 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
2457 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
2458 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
2459 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
2460 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
2461 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
2462 .ilen = 64,
2463 .result = { 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
2464 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
2465 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
2466 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
2467 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
2468 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
2469 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
2470 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b },
2471 .rlen = 64,
2252 }, 2472 },
2253}; 2473};
2254 2474
@@ -2280,6 +2500,57 @@ static struct cipher_testvec aes_cbc_dec_tv_template[] = {
2280 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 2500 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2281 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, 2501 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
2282 .rlen = 32, 2502 .rlen = 32,
2503 }, { /* From NIST SP800-38A */
2504 .key = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
2505 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
2506 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b },
2507 .klen = 24,
2508 .iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2509 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
2510 .input = { 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
2511 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
2512 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4,
2513 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a,
2514 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0,
2515 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0,
2516 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81,
2517 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd },
2518 .ilen = 64,
2519 .result = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
2520 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
2521 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
2522 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
2523 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
2524 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
2525 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
2526 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
2527 .rlen = 64,
2528 }, {
2529 .key = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
2530 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
2531 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
2532 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 },
2533 .klen = 32,
2534 .iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2535 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
2536 .input = { 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
2537 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
2538 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
2539 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
2540 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
2541 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
2542 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
2543 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b },
2544 .ilen = 64,
2545 .result = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
2546 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
2547 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
2548 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
2549 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
2550 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
2551 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
2552 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 },
2553 .rlen = 64,
2283 }, 2554 },
2284}; 2555};
2285 2556
@@ -3180,6 +3451,1843 @@ static struct cipher_testvec aes_xts_dec_tv_template[] = {
3180 } 3451 }
3181}; 3452};
3182 3453
3454
3455static struct cipher_testvec aes_ctr_enc_tv_template[] = {
3456 { /* From RFC 3686 */
3457 .key = { 0xae, 0x68, 0x52, 0xf8, 0x12, 0x10, 0x67, 0xcc,
3458 0x4b, 0xf7, 0xa5, 0x76, 0x55, 0x77, 0xf3, 0x9e,
3459 0x00, 0x00, 0x00, 0x30 },
3460 .klen = 20,
3461 .iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
3462 .input = { "Single block msg" },
3463 .ilen = 16,
3464 .result = { 0xe4, 0x09, 0x5d, 0x4f, 0xb7, 0xa7, 0xb3, 0x79,
3465 0x2d, 0x61, 0x75, 0xa3, 0x26, 0x13, 0x11, 0xb8 },
3466 .rlen = 16,
3467 }, {
3468 .key = { 0x7e, 0x24, 0x06, 0x78, 0x17, 0xfa, 0xe0, 0xd7,
3469 0x43, 0xd6, 0xce, 0x1f, 0x32, 0x53, 0x91, 0x63,
3470 0x00, 0x6c, 0xb6, 0xdb },
3471 .klen = 20,
3472 .iv = { 0xc0, 0x54, 0x3b, 0x59, 0xda, 0x48, 0xd9, 0x0b },
3473 .input = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3474 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3475 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3476 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
3477 .ilen = 32,
3478 .result = { 0x51, 0x04, 0xa1, 0x06, 0x16, 0x8a, 0x72, 0xd9,
3479 0x79, 0x0d, 0x41, 0xee, 0x8e, 0xda, 0xd3, 0x88,
3480 0xeb, 0x2e, 0x1e, 0xfc, 0x46, 0xda, 0x57, 0xc8,
3481 0xfc, 0xe6, 0x30, 0xdf, 0x91, 0x41, 0xbe, 0x28 },
3482 .rlen = 32,
3483 }, {
3484 .key = { 0x16, 0xaf, 0x5b, 0x14, 0x5f, 0xc9, 0xf5, 0x79,
3485 0xc1, 0x75, 0xf9, 0x3e, 0x3b, 0xfb, 0x0e, 0xed,
3486 0x86, 0x3d, 0x06, 0xcc, 0xfd, 0xb7, 0x85, 0x15,
3487 0x00, 0x00, 0x00, 0x48 },
3488 .klen = 28,
3489 .iv = { 0x36, 0x73, 0x3c, 0x14, 0x7d, 0x6d, 0x93, 0xcb },
3490 .input = { "Single block msg" },
3491 .ilen = 16,
3492 .result = { 0x4b, 0x55, 0x38, 0x4f, 0xe2, 0x59, 0xc9, 0xc8,
3493 0x4e, 0x79, 0x35, 0xa0, 0x03, 0xcb, 0xe9, 0x28 },
3494 .rlen = 16,
3495 }, {
3496 .key = { 0x7c, 0x5c, 0xb2, 0x40, 0x1b, 0x3d, 0xc3, 0x3c,
3497 0x19, 0xe7, 0x34, 0x08, 0x19, 0xe0, 0xf6, 0x9c,
3498 0x67, 0x8c, 0x3d, 0xb8, 0xe6, 0xf6, 0xa9, 0x1a,
3499 0x00, 0x96, 0xb0, 0x3b },
3500 .klen = 28,
3501 .iv = { 0x02, 0x0c, 0x6e, 0xad, 0xc2, 0xcb, 0x50, 0x0d },
3502 .input = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3503 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3504 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3505 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
3506 .ilen = 32,
3507 .result = { 0x45, 0x32, 0x43, 0xfc, 0x60, 0x9b, 0x23, 0x32,
3508 0x7e, 0xdf, 0xaa, 0xfa, 0x71, 0x31, 0xcd, 0x9f,
3509 0x84, 0x90, 0x70, 0x1c, 0x5a, 0xd4, 0xa7, 0x9c,
3510 0xfc, 0x1f, 0xe0, 0xff, 0x42, 0xf4, 0xfb, 0x00 },
3511 .rlen = 32,
3512 }, {
3513 .key = { 0x77, 0x6b, 0xef, 0xf2, 0x85, 0x1d, 0xb0, 0x6f,
3514 0x4c, 0x8a, 0x05, 0x42, 0xc8, 0x69, 0x6f, 0x6c,
3515 0x6a, 0x81, 0xaf, 0x1e, 0xec, 0x96, 0xb4, 0xd3,
3516 0x7f, 0xc1, 0xd6, 0x89, 0xe6, 0xc1, 0xc1, 0x04,
3517 0x00, 0x00, 0x00, 0x60 },
3518 .klen = 36,
3519 .iv = { 0xdb, 0x56, 0x72, 0xc9, 0x7a, 0xa8, 0xf0, 0xb2 },
3520 .input = { "Single block msg" },
3521 .ilen = 16,
3522 .result = { 0x14, 0x5a, 0xd0, 0x1d, 0xbf, 0x82, 0x4e, 0xc7,
3523 0x56, 0x08, 0x63, 0xdc, 0x71, 0xe3, 0xe0, 0xc0 },
3524 .rlen = 16,
3525 }, {
3526 .key = { 0xf6, 0xd6, 0x6d, 0x6b, 0xd5, 0x2d, 0x59, 0xbb,
3527 0x07, 0x96, 0x36, 0x58, 0x79, 0xef, 0xf8, 0x86,
3528 0xc6, 0x6d, 0xd5, 0x1a, 0x5b, 0x6a, 0x99, 0x74,
3529 0x4b, 0x50, 0x59, 0x0c, 0x87, 0xa2, 0x38, 0x84,
3530 0x00, 0xfa, 0xac, 0x24 },
3531 .klen = 36,
3532 .iv = { 0xc1, 0x58, 0x5e, 0xf1, 0x5a, 0x43, 0xd8, 0x75 },
3533 .input = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3534 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3535 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3536 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
3537 .ilen = 32,
3538 .result = { 0xf0, 0x5e, 0x23, 0x1b, 0x38, 0x94, 0x61, 0x2c,
3539 0x49, 0xee, 0x00, 0x0b, 0x80, 0x4e, 0xb2, 0xa9,
3540 0xb8, 0x30, 0x6b, 0x50, 0x8f, 0x83, 0x9d, 0x6a,
3541 0x55, 0x30, 0x83, 0x1d, 0x93, 0x44, 0xaf, 0x1c },
3542 .rlen = 32,
3543 }, {
3544 // generated using Crypto++
3545 .key = {
3546 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3547 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3548 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3549 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3550 0x00, 0x00, 0x00, 0x00,
3551 },
3552 .klen = 32 + 4,
3553 .iv = {
3554 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3555 },
3556 .input = {
3557 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
3558 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
3559 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
3560 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
3561 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
3562 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
3563 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
3564 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
3565 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
3566 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
3567 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
3568 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
3569 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
3570 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
3571 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
3572 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
3573 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
3574 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
3575 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
3576 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
3577 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
3578 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
3579 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
3580 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
3581 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
3582 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
3583 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
3584 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
3585 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
3586 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
3587 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
3588 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
3589 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
3590 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a, 0x2d,
3591 0x30, 0x33, 0x36, 0x39, 0x3c, 0x3f, 0x42, 0x45,
3592 0x48, 0x4b, 0x4e, 0x51, 0x54, 0x57, 0x5a, 0x5d,
3593 0x60, 0x63, 0x66, 0x69, 0x6c, 0x6f, 0x72, 0x75,
3594 0x78, 0x7b, 0x7e, 0x81, 0x84, 0x87, 0x8a, 0x8d,
3595 0x90, 0x93, 0x96, 0x99, 0x9c, 0x9f, 0xa2, 0xa5,
3596 0xa8, 0xab, 0xae, 0xb1, 0xb4, 0xb7, 0xba, 0xbd,
3597 0xc0, 0xc3, 0xc6, 0xc9, 0xcc, 0xcf, 0xd2, 0xd5,
3598 0xd8, 0xdb, 0xde, 0xe1, 0xe4, 0xe7, 0xea, 0xed,
3599 0xf0, 0xf3, 0xf6, 0xf9, 0xfc, 0xff, 0x02, 0x05,
3600 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17, 0x1a, 0x1d,
3601 0x20, 0x23, 0x26, 0x29, 0x2c, 0x2f, 0x32, 0x35,
3602 0x38, 0x3b, 0x3e, 0x41, 0x44, 0x47, 0x4a, 0x4d,
3603 0x50, 0x53, 0x56, 0x59, 0x5c, 0x5f, 0x62, 0x65,
3604 0x68, 0x6b, 0x6e, 0x71, 0x74, 0x77, 0x7a, 0x7d,
3605 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x95,
3606 0x98, 0x9b, 0x9e, 0xa1, 0xa4, 0xa7, 0xaa, 0xad,
3607 0xb0, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc2, 0xc5,
3608 0xc8, 0xcb, 0xce, 0xd1, 0xd4, 0xd7, 0xda, 0xdd,
3609 0xe0, 0xe3, 0xe6, 0xe9, 0xec, 0xef, 0xf2, 0xf5,
3610 0xf8, 0xfb, 0xfe, 0x01, 0x04, 0x07, 0x0a, 0x0d,
3611 0x10, 0x13, 0x16, 0x19, 0x1c, 0x1f, 0x22, 0x25,
3612 0x28, 0x2b, 0x2e, 0x31, 0x34, 0x37, 0x3a, 0x3d,
3613 0x40, 0x43, 0x46, 0x49, 0x4c, 0x4f, 0x52, 0x55,
3614 0x58, 0x5b, 0x5e, 0x61, 0x64, 0x67, 0x6a, 0x6d,
3615 0x70, 0x73, 0x76, 0x79, 0x7c, 0x7f, 0x82, 0x85,
3616 0x88, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9d,
3617 0xa0, 0xa3, 0xa6, 0xa9, 0xac, 0xaf, 0xb2, 0xb5,
3618 0xb8, 0xbb, 0xbe, 0xc1, 0xc4, 0xc7, 0xca, 0xcd,
3619 0xd0, 0xd3, 0xd6, 0xd9, 0xdc, 0xdf, 0xe2, 0xe5,
3620 0xe8, 0xeb, 0xee, 0xf1, 0xf4, 0xf7, 0xfa, 0xfd,
3621 0x00, 0x05, 0x0a, 0x0f, 0x14, 0x19, 0x1e, 0x23,
3622 0x28, 0x2d, 0x32, 0x37, 0x3c, 0x41, 0x46, 0x4b,
3623 0x50, 0x55, 0x5a, 0x5f, 0x64, 0x69, 0x6e, 0x73,
3624 0x78, 0x7d, 0x82, 0x87, 0x8c, 0x91, 0x96, 0x9b,
3625 0xa0, 0xa5, 0xaa, 0xaf, 0xb4, 0xb9, 0xbe, 0xc3,
3626 0xc8, 0xcd, 0xd2, 0xd7, 0xdc, 0xe1, 0xe6, 0xeb,
3627 0xf0, 0xf5, 0xfa, 0xff, 0x04, 0x09, 0x0e, 0x13,
3628 0x18, 0x1d, 0x22, 0x27, 0x2c, 0x31, 0x36, 0x3b,
3629 0x40, 0x45, 0x4a, 0x4f, 0x54, 0x59, 0x5e, 0x63,
3630 0x68, 0x6d, 0x72, 0x77, 0x7c, 0x81, 0x86, 0x8b,
3631 0x90, 0x95, 0x9a, 0x9f, 0xa4, 0xa9, 0xae, 0xb3,
3632 0xb8, 0xbd, 0xc2, 0xc7, 0xcc, 0xd1, 0xd6, 0xdb,
3633 0xe0, 0xe5, 0xea, 0xef, 0xf4, 0xf9, 0xfe, 0x03,
3634 0x08, 0x0d, 0x12, 0x17, 0x1c, 0x21, 0x26, 0x2b,
3635 0x30, 0x35, 0x3a, 0x3f, 0x44, 0x49, 0x4e, 0x53,
3636 0x58, 0x5d, 0x62, 0x67, 0x6c, 0x71, 0x76, 0x7b,
3637 0x80, 0x85, 0x8a, 0x8f, 0x94, 0x99, 0x9e, 0xa3,
3638 0xa8, 0xad, 0xb2, 0xb7, 0xbc, 0xc1, 0xc6, 0xcb,
3639 0xd0, 0xd5, 0xda, 0xdf, 0xe4, 0xe9, 0xee, 0xf3,
3640 0xf8, 0xfd, 0x02, 0x07, 0x0c, 0x11, 0x16, 0x1b,
3641 0x20, 0x25, 0x2a, 0x2f, 0x34, 0x39, 0x3e, 0x43,
3642 0x48, 0x4d, 0x52, 0x57, 0x5c, 0x61, 0x66, 0x6b,
3643 0x70, 0x75, 0x7a, 0x7f, 0x84, 0x89, 0x8e, 0x93,
3644 0x98, 0x9d, 0xa2, 0xa7, 0xac, 0xb1, 0xb6, 0xbb,
3645 0xc0, 0xc5, 0xca, 0xcf, 0xd4, 0xd9, 0xde, 0xe3,
3646 0xe8, 0xed, 0xf2, 0xf7, 0xfc, 0x01, 0x06, 0x0b,
3647 0x10, 0x15, 0x1a, 0x1f, 0x24, 0x29, 0x2e, 0x33,
3648 0x38, 0x3d, 0x42, 0x47, 0x4c, 0x51, 0x56, 0x5b,
3649 0x60, 0x65, 0x6a, 0x6f, 0x74, 0x79, 0x7e, 0x83,
3650 0x88, 0x8d, 0x92, 0x97, 0x9c, 0xa1, 0xa6, 0xab,
3651 0xb0, 0xb5, 0xba, 0xbf, 0xc4, 0xc9, 0xce, 0xd3,
3652 0xd8, 0xdd, 0xe2, 0xe7, 0xec, 0xf1, 0xf6, 0xfb,
3653 0x00, 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31,
3654 0x38, 0x3f, 0x46, 0x4d, 0x54, 0x5b, 0x62, 0x69,
3655 0x70, 0x77, 0x7e, 0x85, 0x8c, 0x93, 0x9a, 0xa1,
3656 0xa8, 0xaf, 0xb6, 0xbd, 0xc4, 0xcb, 0xd2, 0xd9,
3657 0xe0, 0xe7, 0xee, 0xf5, 0xfc, 0x03, 0x0a, 0x11,
3658 0x18, 0x1f, 0x26, 0x2d, 0x34, 0x3b, 0x42, 0x49,
3659 0x50, 0x57, 0x5e, 0x65, 0x6c, 0x73, 0x7a, 0x81,
3660 0x88, 0x8f, 0x96, 0x9d, 0xa4, 0xab, 0xb2, 0xb9,
3661 0xc0, 0xc7, 0xce, 0xd5, 0xdc, 0xe3, 0xea, 0xf1,
3662 0xf8, 0xff, 0x06, 0x0d, 0x14, 0x1b, 0x22, 0x29,
3663 0x30, 0x37, 0x3e, 0x45, 0x4c, 0x53, 0x5a, 0x61,
3664 0x68, 0x6f, 0x76, 0x7d, 0x84, 0x8b, 0x92, 0x99,
3665 0xa0, 0xa7, 0xae, 0xb5, 0xbc, 0xc3, 0xca, 0xd1,
3666 0xd8, 0xdf, 0xe6, 0xed, 0xf4, 0xfb, 0x02, 0x09,
3667 0x10, 0x17, 0x1e, 0x25, 0x2c, 0x33, 0x3a, 0x41,
3668 0x48, 0x4f, 0x56, 0x5d, 0x64, 0x6b, 0x72, 0x79,
3669 0x80, 0x87, 0x8e, 0x95, 0x9c, 0xa3, 0xaa, 0xb1,
3670 0xb8, 0xbf, 0xc6, 0xcd, 0xd4, 0xdb, 0xe2, 0xe9,
3671 0xf0, 0xf7, 0xfe, 0x05, 0x0c, 0x13, 0x1a, 0x21,
3672 0x28, 0x2f, 0x36, 0x3d, 0x44, 0x4b, 0x52, 0x59,
3673 0x60, 0x67, 0x6e, 0x75, 0x7c, 0x83, 0x8a, 0x91,
3674 0x98, 0x9f, 0xa6, 0xad, 0xb4, 0xbb, 0xc2, 0xc9,
3675 0xd0, 0xd7, 0xde, 0xe5, 0xec, 0xf3, 0xfa, 0x01,
3676 0x08, 0x0f, 0x16, 0x1d, 0x24, 0x2b, 0x32, 0x39,
3677 0x40, 0x47, 0x4e, 0x55, 0x5c, 0x63, 0x6a, 0x71,
3678 0x78, 0x7f, 0x86, 0x8d, 0x94, 0x9b, 0xa2, 0xa9,
3679 0xb0, 0xb7, 0xbe, 0xc5, 0xcc, 0xd3, 0xda, 0xe1,
3680 0xe8, 0xef, 0xf6, 0xfd, 0x04, 0x0b, 0x12, 0x19,
3681 0x20, 0x27, 0x2e, 0x35, 0x3c, 0x43, 0x4a, 0x51,
3682 0x58, 0x5f, 0x66, 0x6d, 0x74, 0x7b, 0x82, 0x89,
3683 0x90, 0x97, 0x9e, 0xa5, 0xac, 0xb3, 0xba, 0xc1,
3684 0xc8, 0xcf, 0xd6, 0xdd, 0xe4, 0xeb, 0xf2, 0xf9,
3685 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
3686 0x48, 0x51, 0x5a, 0x63, 0x6c, 0x75, 0x7e, 0x87,
3687 0x90, 0x99, 0xa2, 0xab, 0xb4, 0xbd, 0xc6, 0xcf,
3688 0xd8, 0xe1, 0xea, 0xf3, 0xfc, 0x05, 0x0e, 0x17,
3689 0x20, 0x29, 0x32, 0x3b, 0x44, 0x4d, 0x56, 0x5f,
3690 0x68, 0x71, 0x7a, 0x83, 0x8c, 0x95, 0x9e, 0xa7,
3691 0xb0, 0xb9, 0xc2, 0xcb, 0xd4, 0xdd, 0xe6, 0xef,
3692 0xf8, 0x01, 0x0a, 0x13, 0x1c, 0x25, 0x2e, 0x37,
3693 0x40, 0x49, 0x52, 0x5b, 0x64, 0x6d, 0x76, 0x7f,
3694 0x88, 0x91, 0x9a, 0xa3, 0xac, 0xb5, 0xbe, 0xc7,
3695 0xd0, 0xd9, 0xe2, 0xeb, 0xf4, 0xfd, 0x06, 0x0f,
3696 0x18, 0x21, 0x2a, 0x33, 0x3c, 0x45, 0x4e, 0x57,
3697 0x60, 0x69, 0x72, 0x7b, 0x84, 0x8d, 0x96, 0x9f,
3698 0xa8, 0xb1, 0xba, 0xc3, 0xcc, 0xd5, 0xde, 0xe7,
3699 0xf0, 0xf9, 0x02, 0x0b, 0x14, 0x1d, 0x26, 0x2f,
3700 0x38, 0x41, 0x4a, 0x53, 0x5c, 0x65, 0x6e, 0x77,
3701 0x80, 0x89, 0x92, 0x9b, 0xa4, 0xad, 0xb6, 0xbf,
3702 0xc8, 0xd1, 0xda, 0xe3, 0xec, 0xf5, 0xfe, 0x07,
3703 0x10, 0x19, 0x22, 0x2b, 0x34, 0x3d, 0x46, 0x4f,
3704 0x58, 0x61, 0x6a, 0x73, 0x7c, 0x85, 0x8e, 0x97,
3705 0xa0, 0xa9, 0xb2, 0xbb, 0xc4, 0xcd, 0xd6, 0xdf,
3706 0xe8, 0xf1, 0xfa, 0x03, 0x0c, 0x15, 0x1e, 0x27,
3707 0x30, 0x39, 0x42, 0x4b, 0x54, 0x5d, 0x66, 0x6f,
3708 0x78, 0x81, 0x8a, 0x93, 0x9c, 0xa5, 0xae, 0xb7,
3709 0xc0, 0xc9, 0xd2, 0xdb, 0xe4, 0xed, 0xf6, 0xff,
3710 0x08, 0x11, 0x1a, 0x23, 0x2c, 0x35, 0x3e, 0x47,
3711 0x50, 0x59, 0x62, 0x6b, 0x74, 0x7d, 0x86, 0x8f,
3712 0x98, 0xa1, 0xaa, 0xb3, 0xbc, 0xc5, 0xce, 0xd7,
3713 0xe0, 0xe9, 0xf2, 0xfb, 0x04, 0x0d, 0x16, 0x1f,
3714 0x28, 0x31, 0x3a, 0x43, 0x4c, 0x55, 0x5e, 0x67,
3715 0x70, 0x79, 0x82, 0x8b, 0x94, 0x9d, 0xa6, 0xaf,
3716 0xb8, 0xc1, 0xca, 0xd3, 0xdc, 0xe5, 0xee, 0xf7,
3717 0x00, 0x0b, 0x16, 0x21, 0x2c, 0x37, 0x42, 0x4d,
3718 0x58, 0x63, 0x6e, 0x79, 0x84, 0x8f, 0x9a, 0xa5,
3719 0xb0, 0xbb, 0xc6, 0xd1, 0xdc, 0xe7, 0xf2, 0xfd,
3720 0x08, 0x13, 0x1e, 0x29, 0x34, 0x3f, 0x4a, 0x55,
3721 0x60, 0x6b, 0x76, 0x81, 0x8c, 0x97, 0xa2, 0xad,
3722 0xb8, 0xc3, 0xce, 0xd9, 0xe4, 0xef, 0xfa, 0x05,
3723 0x10, 0x1b, 0x26, 0x31, 0x3c, 0x47, 0x52, 0x5d,
3724 0x68, 0x73, 0x7e, 0x89, 0x94, 0x9f, 0xaa, 0xb5,
3725 0xc0, 0xcb, 0xd6, 0xe1, 0xec, 0xf7, 0x02, 0x0d,
3726 0x18, 0x23, 0x2e, 0x39, 0x44, 0x4f, 0x5a, 0x65,
3727 0x70, 0x7b, 0x86, 0x91, 0x9c, 0xa7, 0xb2, 0xbd,
3728 0xc8, 0xd3, 0xde, 0xe9, 0xf4, 0xff, 0x0a, 0x15,
3729 0x20, 0x2b, 0x36, 0x41, 0x4c, 0x57, 0x62, 0x6d,
3730 0x78, 0x83, 0x8e, 0x99, 0xa4, 0xaf, 0xba, 0xc5,
3731 0xd0, 0xdb, 0xe6, 0xf1, 0xfc, 0x07, 0x12, 0x1d,
3732 0x28, 0x33, 0x3e, 0x49, 0x54, 0x5f, 0x6a, 0x75,
3733 0x80, 0x8b, 0x96, 0xa1, 0xac, 0xb7, 0xc2, 0xcd,
3734 0xd8, 0xe3, 0xee, 0xf9, 0x04, 0x0f, 0x1a, 0x25,
3735 0x30, 0x3b, 0x46, 0x51, 0x5c, 0x67, 0x72, 0x7d,
3736 0x88, 0x93, 0x9e, 0xa9, 0xb4, 0xbf, 0xca, 0xd5,
3737 0xe0, 0xeb, 0xf6, 0x01, 0x0c, 0x17, 0x22, 0x2d,
3738 0x38, 0x43, 0x4e, 0x59, 0x64, 0x6f, 0x7a, 0x85,
3739 0x90, 0x9b, 0xa6, 0xb1, 0xbc, 0xc7, 0xd2, 0xdd,
3740 0xe8, 0xf3, 0xfe, 0x09, 0x14, 0x1f, 0x2a, 0x35,
3741 0x40, 0x4b, 0x56, 0x61, 0x6c, 0x77, 0x82, 0x8d,
3742 0x98, 0xa3, 0xae, 0xb9, 0xc4, 0xcf, 0xda, 0xe5,
3743 0xf0, 0xfb, 0x06, 0x11, 0x1c, 0x27, 0x32, 0x3d,
3744 0x48, 0x53, 0x5e, 0x69, 0x74, 0x7f, 0x8a, 0x95,
3745 0xa0, 0xab, 0xb6, 0xc1, 0xcc, 0xd7, 0xe2, 0xed,
3746 0xf8, 0x03, 0x0e, 0x19, 0x24, 0x2f, 0x3a, 0x45,
3747 0x50, 0x5b, 0x66, 0x71, 0x7c, 0x87, 0x92, 0x9d,
3748 0xa8, 0xb3, 0xbe, 0xc9, 0xd4, 0xdf, 0xea, 0xf5,
3749 0x00, 0x0d, 0x1a, 0x27, 0x34, 0x41, 0x4e, 0x5b,
3750 0x68, 0x75, 0x82, 0x8f, 0x9c, 0xa9, 0xb6, 0xc3,
3751 0xd0, 0xdd, 0xea, 0xf7, 0x04, 0x11, 0x1e, 0x2b,
3752 0x38, 0x45, 0x52, 0x5f, 0x6c, 0x79, 0x86, 0x93,
3753 0xa0, 0xad, 0xba, 0xc7, 0xd4, 0xe1, 0xee, 0xfb,
3754 0x08, 0x15, 0x22, 0x2f, 0x3c, 0x49, 0x56, 0x63,
3755 0x70, 0x7d, 0x8a, 0x97, 0xa4, 0xb1, 0xbe, 0xcb,
3756 0xd8, 0xe5, 0xf2, 0xff, 0x0c, 0x19, 0x26, 0x33,
3757 0x40, 0x4d, 0x5a, 0x67, 0x74, 0x81, 0x8e, 0x9b,
3758 0xa8, 0xb5, 0xc2, 0xcf, 0xdc, 0xe9, 0xf6, 0x03,
3759 0x10, 0x1d, 0x2a, 0x37, 0x44, 0x51, 0x5e, 0x6b,
3760 0x78, 0x85, 0x92, 0x9f, 0xac, 0xb9, 0xc6, 0xd3,
3761 0xe0, 0xed, 0xfa, 0x07, 0x14, 0x21, 0x2e, 0x3b,
3762 0x48, 0x55, 0x62, 0x6f, 0x7c, 0x89, 0x96, 0xa3,
3763 0xb0, 0xbd, 0xca, 0xd7, 0xe4, 0xf1, 0xfe, 0x0b,
3764 0x18, 0x25, 0x32, 0x3f, 0x4c, 0x59, 0x66, 0x73,
3765 0x80, 0x8d, 0x9a, 0xa7, 0xb4, 0xc1, 0xce, 0xdb,
3766 0xe8, 0xf5, 0x02, 0x0f, 0x1c, 0x29, 0x36, 0x43,
3767 0x50, 0x5d, 0x6a, 0x77, 0x84, 0x91, 0x9e, 0xab,
3768 0xb8, 0xc5, 0xd2, 0xdf, 0xec, 0xf9, 0x06, 0x13,
3769 0x20, 0x2d, 0x3a, 0x47, 0x54, 0x61, 0x6e, 0x7b,
3770 0x88, 0x95, 0xa2, 0xaf, 0xbc, 0xc9, 0xd6, 0xe3,
3771 0xf0, 0xfd, 0x0a, 0x17, 0x24, 0x31, 0x3e, 0x4b,
3772 0x58, 0x65, 0x72, 0x7f, 0x8c, 0x99, 0xa6, 0xb3,
3773 0xc0, 0xcd, 0xda, 0xe7, 0xf4, 0x01, 0x0e, 0x1b,
3774 0x28, 0x35, 0x42, 0x4f, 0x5c, 0x69, 0x76, 0x83,
3775 0x90, 0x9d, 0xaa, 0xb7, 0xc4, 0xd1, 0xde, 0xeb,
3776 0xf8, 0x05, 0x12, 0x1f, 0x2c, 0x39, 0x46, 0x53,
3777 0x60, 0x6d, 0x7a, 0x87, 0x94, 0xa1, 0xae, 0xbb,
3778 0xc8, 0xd5, 0xe2, 0xef, 0xfc, 0x09, 0x16, 0x23,
3779 0x30, 0x3d, 0x4a, 0x57, 0x64, 0x71, 0x7e, 0x8b,
3780 0x98, 0xa5, 0xb2, 0xbf, 0xcc, 0xd9, 0xe6, 0xf3,
3781 0x00, 0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69,
3782 0x78, 0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1,
3783 0xf0, 0xff, 0x0e, 0x1d, 0x2c, 0x3b, 0x4a, 0x59,
3784 0x68, 0x77, 0x86, 0x95, 0xa4, 0xb3, 0xc2, 0xd1,
3785 0xe0, 0xef, 0xfe, 0x0d, 0x1c, 0x2b, 0x3a, 0x49,
3786 0x58, 0x67, 0x76, 0x85, 0x94, 0xa3, 0xb2, 0xc1,
3787 0xd0, 0xdf, 0xee, 0xfd, 0x0c, 0x1b, 0x2a, 0x39,
3788 0x48, 0x57, 0x66, 0x75, 0x84, 0x93, 0xa2, 0xb1,
3789 0xc0, 0xcf, 0xde, 0xed, 0xfc, 0x0b, 0x1a, 0x29,
3790 0x38, 0x47, 0x56, 0x65, 0x74, 0x83, 0x92, 0xa1,
3791 0xb0, 0xbf, 0xce, 0xdd, 0xec, 0xfb, 0x0a, 0x19,
3792 0x28, 0x37, 0x46, 0x55, 0x64, 0x73, 0x82, 0x91,
3793 0xa0, 0xaf, 0xbe, 0xcd, 0xdc, 0xeb, 0xfa, 0x09,
3794 0x18, 0x27, 0x36, 0x45, 0x54, 0x63, 0x72, 0x81,
3795 0x90, 0x9f, 0xae, 0xbd, 0xcc, 0xdb, 0xea, 0xf9,
3796 0x08, 0x17, 0x26, 0x35, 0x44, 0x53, 0x62, 0x71,
3797 0x80, 0x8f, 0x9e, 0xad, 0xbc, 0xcb, 0xda, 0xe9,
3798 0xf8, 0x07, 0x16, 0x25, 0x34, 0x43, 0x52, 0x61,
3799 0x70, 0x7f, 0x8e, 0x9d, 0xac, 0xbb, 0xca, 0xd9,
3800 0xe8, 0xf7, 0x06, 0x15, 0x24, 0x33, 0x42, 0x51,
3801 0x60, 0x6f, 0x7e, 0x8d, 0x9c, 0xab, 0xba, 0xc9,
3802 0xd8, 0xe7, 0xf6, 0x05, 0x14, 0x23, 0x32, 0x41,
3803 0x50, 0x5f, 0x6e, 0x7d, 0x8c, 0x9b, 0xaa, 0xb9,
3804 0xc8, 0xd7, 0xe6, 0xf5, 0x04, 0x13, 0x22, 0x31,
3805 0x40, 0x4f, 0x5e, 0x6d, 0x7c, 0x8b, 0x9a, 0xa9,
3806 0xb8, 0xc7, 0xd6, 0xe5, 0xf4, 0x03, 0x12, 0x21,
3807 0x30, 0x3f, 0x4e, 0x5d, 0x6c, 0x7b, 0x8a, 0x99,
3808 0xa8, 0xb7, 0xc6, 0xd5, 0xe4, 0xf3, 0x02, 0x11,
3809 0x20, 0x2f, 0x3e, 0x4d, 0x5c, 0x6b, 0x7a, 0x89,
3810 0x98, 0xa7, 0xb6, 0xc5, 0xd4, 0xe3, 0xf2, 0x01,
3811 0x10, 0x1f, 0x2e, 0x3d, 0x4c, 0x5b, 0x6a, 0x79,
3812 0x88, 0x97, 0xa6, 0xb5, 0xc4, 0xd3, 0xe2, 0xf1,
3813 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
3814 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
3815 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87,
3816 0x98, 0xa9, 0xba, 0xcb, 0xdc, 0xed, 0xfe, 0x0f,
3817 0x20, 0x31, 0x42, 0x53, 0x64, 0x75, 0x86, 0x97,
3818 0xa8, 0xb9, 0xca, 0xdb, 0xec, 0xfd, 0x0e, 0x1f,
3819 0x30, 0x41, 0x52, 0x63, 0x74, 0x85, 0x96, 0xa7,
3820 0xb8, 0xc9, 0xda, 0xeb, 0xfc, 0x0d, 0x1e, 0x2f,
3821 0x40, 0x51, 0x62, 0x73, 0x84, 0x95, 0xa6, 0xb7,
3822 0xc8, 0xd9, 0xea, 0xfb, 0x0c, 0x1d, 0x2e, 0x3f,
3823 0x50, 0x61, 0x72, 0x83, 0x94, 0xa5, 0xb6, 0xc7,
3824 0xd8, 0xe9, 0xfa, 0x0b, 0x1c, 0x2d, 0x3e, 0x4f,
3825 0x60, 0x71, 0x82, 0x93, 0xa4, 0xb5, 0xc6, 0xd7,
3826 0xe8, 0xf9, 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f,
3827 0x70, 0x81, 0x92, 0xa3, 0xb4, 0xc5, 0xd6, 0xe7,
3828 0xf8, 0x09, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f,
3829 0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7,
3830 0x08, 0x19, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f,
3831 0x90, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, 0x07,
3832 0x18, 0x29, 0x3a, 0x4b, 0x5c, 0x6d, 0x7e, 0x8f,
3833 0xa0, 0xb1, 0xc2, 0xd3, 0xe4, 0xf5, 0x06, 0x17,
3834 0x28, 0x39, 0x4a, 0x5b, 0x6c, 0x7d, 0x8e, 0x9f,
3835 0xb0, 0xc1, 0xd2, 0xe3, 0xf4, 0x05, 0x16, 0x27,
3836 0x38, 0x49, 0x5a, 0x6b, 0x7c, 0x8d, 0x9e, 0xaf,
3837 0xc0, 0xd1, 0xe2, 0xf3, 0x04, 0x15, 0x26, 0x37,
3838 0x48, 0x59, 0x6a, 0x7b, 0x8c, 0x9d, 0xae, 0xbf,
3839 0xd0, 0xe1, 0xf2, 0x03, 0x14, 0x25, 0x36, 0x47,
3840 0x58, 0x69, 0x7a, 0x8b, 0x9c, 0xad, 0xbe, 0xcf,
3841 0xe0, 0xf1, 0x02, 0x13, 0x24, 0x35, 0x46, 0x57,
3842 0x68, 0x79, 0x8a, 0x9b, 0xac, 0xbd, 0xce, 0xdf,
3843 0xf0, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67,
3844 0x78, 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef,
3845 0x00, 0x13, 0x26, 0x39, 0x4c, 0x5f, 0x72, 0x85,
3846 0x98, 0xab, 0xbe, 0xd1, 0xe4, 0xf7, 0x0a, 0x1d,
3847 0x30, 0x43, 0x56, 0x69, 0x7c, 0x8f, 0xa2, 0xb5,
3848 0xc8, 0xdb, 0xee, 0x01, 0x14, 0x27, 0x3a, 0x4d,
3849 0x60, 0x73, 0x86, 0x99, 0xac, 0xbf, 0xd2, 0xe5,
3850 0xf8, 0x0b, 0x1e, 0x31, 0x44, 0x57, 0x6a, 0x7d,
3851 0x90, 0xa3, 0xb6, 0xc9, 0xdc, 0xef, 0x02, 0x15,
3852 0x28, 0x3b, 0x4e, 0x61, 0x74, 0x87, 0x9a, 0xad,
3853 0xc0, 0xd3, 0xe6, 0xf9, 0x0c, 0x1f, 0x32, 0x45,
3854 0x58, 0x6b, 0x7e, 0x91, 0xa4, 0xb7, 0xca, 0xdd,
3855 0xf0, 0x03, 0x16, 0x29, 0x3c, 0x4f, 0x62, 0x75,
3856 0x88, 0x9b, 0xae, 0xc1, 0xd4, 0xe7, 0xfa, 0x0d,
3857 0x20, 0x33, 0x46, 0x59, 0x6c, 0x7f, 0x92, 0xa5,
3858 0xb8, 0xcb, 0xde, 0xf1, 0x04, 0x17, 0x2a, 0x3d,
3859 0x50, 0x63, 0x76, 0x89, 0x9c, 0xaf, 0xc2, 0xd5,
3860 0xe8, 0xfb, 0x0e, 0x21, 0x34, 0x47, 0x5a, 0x6d,
3861 0x80, 0x93, 0xa6, 0xb9, 0xcc, 0xdf, 0xf2, 0x05,
3862 0x18, 0x2b, 0x3e, 0x51, 0x64, 0x77, 0x8a, 0x9d,
3863 0xb0, 0xc3, 0xd6, 0xe9, 0xfc, 0x0f, 0x22, 0x35,
3864 0x48, 0x5b, 0x6e, 0x81, 0x94, 0xa7, 0xba, 0xcd,
3865 0xe0, 0xf3, 0x06, 0x19, 0x2c, 0x3f, 0x52, 0x65,
3866 0x78, 0x8b, 0x9e, 0xb1, 0xc4, 0xd7, 0xea, 0xfd,
3867 0x10, 0x23, 0x36, 0x49, 0x5c, 0x6f, 0x82, 0x95,
3868 0xa8, 0xbb, 0xce, 0xe1, 0xf4, 0x07, 0x1a, 0x2d,
3869 0x40, 0x53, 0x66, 0x79, 0x8c, 0x9f, 0xb2, 0xc5,
3870 0xd8, 0xeb, 0xfe, 0x11, 0x24, 0x37, 0x4a, 0x5d,
3871 0x70, 0x83, 0x96, 0xa9, 0xbc, 0xcf, 0xe2, 0xf5,
3872 0x08, 0x1b, 0x2e, 0x41, 0x54, 0x67, 0x7a, 0x8d,
3873 0xa0, 0xb3, 0xc6, 0xd9, 0xec, 0xff, 0x12, 0x25,
3874 0x38, 0x4b, 0x5e, 0x71, 0x84, 0x97, 0xaa, 0xbd,
3875 0xd0, 0xe3, 0xf6, 0x09, 0x1c, 0x2f, 0x42, 0x55,
3876 0x68, 0x7b, 0x8e, 0xa1, 0xb4, 0xc7, 0xda, 0xed,
3877 0x00, 0x15, 0x2a, 0x3f, 0x54, 0x69, 0x7e, 0x93,
3878 0xa8, 0xbd, 0xd2, 0xe7, 0xfc, 0x11, 0x26, 0x3b,
3879 0x50, 0x65, 0x7a, 0x8f, 0xa4, 0xb9, 0xce, 0xe3,
3880 0xf8, 0x0d, 0x22, 0x37, 0x4c, 0x61, 0x76, 0x8b,
3881 0xa0, 0xb5, 0xca, 0xdf, 0xf4, 0x09, 0x1e, 0x33,
3882 0x48, 0x5d, 0x72, 0x87, 0x9c, 0xb1, 0xc6, 0xdb,
3883 0xf0, 0x05, 0x1a, 0x2f, 0x44, 0x59, 0x6e, 0x83,
3884 0x98, 0xad, 0xc2, 0xd7, 0xec, 0x01, 0x16, 0x2b,
3885 0x40, 0x55, 0x6a, 0x7f, 0x94, 0xa9, 0xbe, 0xd3,
3886 0xe8, 0xfd, 0x12, 0x27, 0x3c, 0x51, 0x66, 0x7b,
3887 0x90, 0xa5, 0xba, 0xcf, 0xe4, 0xf9, 0x0e, 0x23,
3888 0x38, 0x4d, 0x62, 0x77, 0x8c, 0xa1, 0xb6, 0xcb,
3889 0xe0, 0xf5, 0x0a, 0x1f, 0x34, 0x49, 0x5e, 0x73,
3890 0x88, 0x9d, 0xb2, 0xc7, 0xdc, 0xf1, 0x06, 0x1b,
3891 0x30, 0x45, 0x5a, 0x6f, 0x84, 0x99, 0xae, 0xc3,
3892 0xd8, 0xed, 0x02, 0x17, 0x2c, 0x41, 0x56, 0x6b,
3893 0x80, 0x95, 0xaa, 0xbf, 0xd4, 0xe9, 0xfe, 0x13,
3894 0x28, 0x3d, 0x52, 0x67, 0x7c, 0x91, 0xa6, 0xbb,
3895 0xd0, 0xe5, 0xfa, 0x0f, 0x24, 0x39, 0x4e, 0x63,
3896 0x78, 0x8d, 0xa2, 0xb7, 0xcc, 0xe1, 0xf6, 0x0b,
3897 0x20, 0x35, 0x4a, 0x5f, 0x74, 0x89, 0x9e, 0xb3,
3898 0xc8, 0xdd, 0xf2, 0x07, 0x1c, 0x31, 0x46, 0x5b,
3899 0x70, 0x85, 0x9a, 0xaf, 0xc4, 0xd9, 0xee, 0x03,
3900 0x18, 0x2d, 0x42, 0x57, 0x6c, 0x81, 0x96, 0xab,
3901 0xc0, 0xd5, 0xea, 0xff, 0x14, 0x29, 0x3e, 0x53,
3902 0x68, 0x7d, 0x92, 0xa7, 0xbc, 0xd1, 0xe6, 0xfb,
3903 0x10, 0x25, 0x3a, 0x4f, 0x64, 0x79, 0x8e, 0xa3,
3904 0xb8, 0xcd, 0xe2, 0xf7, 0x0c, 0x21, 0x36, 0x4b,
3905 0x60, 0x75, 0x8a, 0x9f, 0xb4, 0xc9, 0xde, 0xf3,
3906 0x08, 0x1d, 0x32, 0x47, 0x5c, 0x71, 0x86, 0x9b,
3907 0xb0, 0xc5, 0xda, 0xef, 0x04, 0x19, 0x2e, 0x43,
3908 0x58, 0x6d, 0x82, 0x97, 0xac, 0xc1, 0xd6, 0xeb,
3909 0x00, 0x17, 0x2e, 0x45, 0x5c, 0x73, 0x8a, 0xa1,
3910 0xb8, 0xcf, 0xe6, 0xfd, 0x14, 0x2b, 0x42, 0x59,
3911 0x70, 0x87, 0x9e, 0xb5, 0xcc, 0xe3, 0xfa, 0x11,
3912 0x28, 0x3f, 0x56, 0x6d, 0x84, 0x9b, 0xb2, 0xc9,
3913 0xe0, 0xf7, 0x0e, 0x25, 0x3c, 0x53, 0x6a, 0x81,
3914 0x98, 0xaf, 0xc6, 0xdd, 0xf4, 0x0b, 0x22, 0x39,
3915 0x50, 0x67, 0x7e, 0x95, 0xac, 0xc3, 0xda, 0xf1,
3916 0x08, 0x1f, 0x36, 0x4d, 0x64, 0x7b, 0x92, 0xa9,
3917 0xc0, 0xd7, 0xee, 0x05, 0x1c, 0x33, 0x4a, 0x61,
3918 0x78, 0x8f, 0xa6, 0xbd, 0xd4, 0xeb, 0x02, 0x19,
3919 0x30, 0x47, 0x5e, 0x75, 0x8c, 0xa3, 0xba, 0xd1,
3920 0xe8, 0xff, 0x16, 0x2d, 0x44, 0x5b, 0x72, 0x89,
3921 0xa0, 0xb7, 0xce, 0xe5, 0xfc, 0x13, 0x2a, 0x41,
3922 0x58, 0x6f, 0x86, 0x9d, 0xb4, 0xcb, 0xe2, 0xf9,
3923 0x10, 0x27, 0x3e, 0x55, 0x6c, 0x83, 0x9a, 0xb1,
3924 0xc8, 0xdf, 0xf6, 0x0d, 0x24, 0x3b, 0x52, 0x69,
3925 0x80, 0x97, 0xae, 0xc5, 0xdc, 0xf3, 0x0a, 0x21,
3926 0x38, 0x4f, 0x66, 0x7d, 0x94, 0xab, 0xc2, 0xd9,
3927 0xf0, 0x07, 0x1e, 0x35, 0x4c, 0x63, 0x7a, 0x91,
3928 0xa8, 0xbf, 0xd6, 0xed, 0x04, 0x1b, 0x32, 0x49,
3929 0x60, 0x77, 0x8e, 0xa5, 0xbc, 0xd3, 0xea, 0x01,
3930 0x18, 0x2f, 0x46, 0x5d, 0x74, 0x8b, 0xa2, 0xb9,
3931 0xd0, 0xe7, 0xfe, 0x15, 0x2c, 0x43, 0x5a, 0x71,
3932 0x88, 0x9f, 0xb6, 0xcd, 0xe4, 0xfb, 0x12, 0x29,
3933 0x40, 0x57, 0x6e, 0x85, 0x9c, 0xb3, 0xca, 0xe1,
3934 0xf8, 0x0f, 0x26, 0x3d, 0x54, 0x6b, 0x82, 0x99,
3935 0xb0, 0xc7, 0xde, 0xf5, 0x0c, 0x23, 0x3a, 0x51,
3936 0x68, 0x7f, 0x96, 0xad, 0xc4, 0xdb, 0xf2, 0x09,
3937 0x20, 0x37, 0x4e, 0x65, 0x7c, 0x93, 0xaa, 0xc1,
3938 0xd8, 0xef, 0x06, 0x1d, 0x34, 0x4b, 0x62, 0x79,
3939 0x90, 0xa7, 0xbe, 0xd5, 0xec, 0x03, 0x1a, 0x31,
3940 0x48, 0x5f, 0x76, 0x8d, 0xa4, 0xbb, 0xd2, 0xe9,
3941 0x00, 0x19, 0x32, 0x4b, 0x64, 0x7d, 0x96, 0xaf,
3942 0xc8, 0xe1, 0xfa, 0x13, 0x2c, 0x45, 0x5e, 0x77,
3943 0x90, 0xa9, 0xc2, 0xdb, 0xf4, 0x0d, 0x26, 0x3f,
3944 0x58, 0x71, 0x8a, 0xa3, 0xbc, 0xd5, 0xee, 0x07,
3945 0x20, 0x39, 0x52, 0x6b, 0x84, 0x9d, 0xb6, 0xcf,
3946 0xe8, 0x01, 0x1a, 0x33, 0x4c, 0x65, 0x7e, 0x97,
3947 0xb0, 0xc9, 0xe2, 0xfb, 0x14, 0x2d, 0x46, 0x5f,
3948 0x78, 0x91, 0xaa, 0xc3, 0xdc, 0xf5, 0x0e, 0x27,
3949 0x40, 0x59, 0x72, 0x8b, 0xa4, 0xbd, 0xd6, 0xef,
3950 0x08, 0x21, 0x3a, 0x53, 0x6c, 0x85, 0x9e, 0xb7,
3951 0xd0, 0xe9, 0x02, 0x1b, 0x34, 0x4d, 0x66, 0x7f,
3952 0x98, 0xb1, 0xca, 0xe3, 0xfc, 0x15, 0x2e, 0x47,
3953 0x60, 0x79, 0x92, 0xab, 0xc4, 0xdd, 0xf6, 0x0f,
3954 0x28, 0x41, 0x5a, 0x73, 0x8c, 0xa5, 0xbe, 0xd7,
3955 0xf0, 0x09, 0x22, 0x3b, 0x54, 0x6d, 0x86, 0x9f,
3956 0xb8, 0xd1, 0xea, 0x03, 0x1c, 0x35, 0x4e, 0x67,
3957 0x80, 0x99, 0xb2, 0xcb, 0xe4, 0xfd, 0x16, 0x2f,
3958 0x48, 0x61, 0x7a, 0x93, 0xac, 0xc5, 0xde, 0xf7,
3959 0x10, 0x29, 0x42, 0x5b, 0x74, 0x8d, 0xa6, 0xbf,
3960 0xd8, 0xf1, 0x0a, 0x23, 0x3c, 0x55, 0x6e, 0x87,
3961 0xa0, 0xb9, 0xd2, 0xeb, 0x04, 0x1d, 0x36, 0x4f,
3962 0x68, 0x81, 0x9a, 0xb3, 0xcc, 0xe5, 0xfe, 0x17,
3963 0x30, 0x49, 0x62, 0x7b, 0x94, 0xad, 0xc6, 0xdf,
3964 0xf8, 0x11, 0x2a, 0x43, 0x5c, 0x75, 0x8e, 0xa7,
3965 0xc0, 0xd9, 0xf2, 0x0b, 0x24, 0x3d, 0x56, 0x6f,
3966 0x88, 0xa1, 0xba, 0xd3, 0xec, 0x05, 0x1e, 0x37,
3967 0x50, 0x69, 0x82, 0x9b, 0xb4, 0xcd, 0xe6, 0xff,
3968 0x18, 0x31, 0x4a, 0x63, 0x7c, 0x95, 0xae, 0xc7,
3969 0xe0, 0xf9, 0x12, 0x2b, 0x44, 0x5d, 0x76, 0x8f,
3970 0xa8, 0xc1, 0xda, 0xf3, 0x0c, 0x25, 0x3e, 0x57,
3971 0x70, 0x89, 0xa2, 0xbb, 0xd4, 0xed, 0x06, 0x1f,
3972 0x38, 0x51, 0x6a, 0x83, 0x9c, 0xb5, 0xce, 0xe7,
3973 0x00, 0x1b, 0x36, 0x51, 0x6c, 0x87, 0xa2, 0xbd,
3974 0xd8, 0xf3, 0x0e, 0x29, 0x44, 0x5f, 0x7a, 0x95,
3975 0xb0, 0xcb, 0xe6, 0x01, 0x1c, 0x37, 0x52, 0x6d,
3976 0x88, 0xa3, 0xbe, 0xd9, 0xf4, 0x0f, 0x2a, 0x45,
3977 0x60, 0x7b, 0x96, 0xb1, 0xcc, 0xe7, 0x02, 0x1d,
3978 0x38, 0x53, 0x6e, 0x89, 0xa4, 0xbf, 0xda, 0xf5,
3979 0x10, 0x2b, 0x46, 0x61, 0x7c, 0x97, 0xb2, 0xcd,
3980 0xe8, 0x03, 0x1e, 0x39, 0x54, 0x6f, 0x8a, 0xa5,
3981 0xc0, 0xdb, 0xf6, 0x11, 0x2c, 0x47, 0x62, 0x7d,
3982 0x98, 0xb3, 0xce, 0xe9, 0x04, 0x1f, 0x3a, 0x55,
3983 0x70, 0x8b, 0xa6, 0xc1, 0xdc, 0xf7, 0x12, 0x2d,
3984 0x48, 0x63, 0x7e, 0x99, 0xb4, 0xcf, 0xea, 0x05,
3985 0x20, 0x3b, 0x56, 0x71, 0x8c, 0xa7, 0xc2, 0xdd,
3986 0xf8, 0x13, 0x2e, 0x49, 0x64, 0x7f, 0x9a, 0xb5,
3987 0xd0, 0xeb, 0x06, 0x21, 0x3c, 0x57, 0x72, 0x8d,
3988 0xa8, 0xc3, 0xde, 0xf9, 0x14, 0x2f, 0x4a, 0x65,
3989 0x80, 0x9b, 0xb6, 0xd1, 0xec, 0x07, 0x22, 0x3d,
3990 0x58, 0x73, 0x8e, 0xa9, 0xc4, 0xdf, 0xfa, 0x15,
3991 0x30, 0x4b, 0x66, 0x81, 0x9c, 0xb7, 0xd2, 0xed,
3992 0x08, 0x23, 0x3e, 0x59, 0x74, 0x8f, 0xaa, 0xc5,
3993 0xe0, 0xfb, 0x16, 0x31, 0x4c, 0x67, 0x82, 0x9d,
3994 0xb8, 0xd3, 0xee, 0x09, 0x24, 0x3f, 0x5a, 0x75,
3995 0x90, 0xab, 0xc6, 0xe1, 0xfc, 0x17, 0x32, 0x4d,
3996 0x68, 0x83, 0x9e, 0xb9, 0xd4, 0xef, 0x0a, 0x25,
3997 0x40, 0x5b, 0x76, 0x91, 0xac, 0xc7, 0xe2, 0xfd,
3998 0x18, 0x33, 0x4e, 0x69, 0x84, 0x9f, 0xba, 0xd5,
3999 0xf0, 0x0b, 0x26, 0x41, 0x5c, 0x77, 0x92, 0xad,
4000 0xc8, 0xe3, 0xfe, 0x19, 0x34, 0x4f, 0x6a, 0x85,
4001 0xa0, 0xbb, 0xd6, 0xf1, 0x0c, 0x27, 0x42, 0x5d,
4002 0x78, 0x93, 0xae, 0xc9, 0xe4, 0xff, 0x1a, 0x35,
4003 0x50, 0x6b, 0x86, 0xa1, 0xbc, 0xd7, 0xf2, 0x0d,
4004 0x28, 0x43, 0x5e, 0x79, 0x94, 0xaf, 0xca, 0xe5,
4005 0x00, 0x1d, 0x3a, 0x57, 0x74, 0x91, 0xae, 0xcb,
4006 0xe8, 0x05, 0x22, 0x3f, 0x5c, 0x79, 0x96, 0xb3,
4007 0xd0, 0xed, 0x0a, 0x27, 0x44, 0x61, 0x7e, 0x9b,
4008 0xb8, 0xd5, 0xf2, 0x0f, 0x2c, 0x49, 0x66, 0x83,
4009 0xa0, 0xbd, 0xda, 0xf7, 0x14, 0x31, 0x4e, 0x6b,
4010 0x88, 0xa5, 0xc2, 0xdf, 0xfc, 0x19, 0x36, 0x53,
4011 0x70, 0x8d, 0xaa, 0xc7, 0xe4, 0x01, 0x1e, 0x3b,
4012 0x58, 0x75, 0x92, 0xaf, 0xcc, 0xe9, 0x06, 0x23,
4013 0x40, 0x5d, 0x7a, 0x97, 0xb4, 0xd1, 0xee, 0x0b,
4014 0x28, 0x45, 0x62, 0x7f, 0x9c, 0xb9, 0xd6, 0xf3,
4015 0x10, 0x2d, 0x4a, 0x67, 0x84, 0xa1, 0xbe, 0xdb,
4016 0xf8, 0x15, 0x32, 0x4f, 0x6c, 0x89, 0xa6, 0xc3,
4017 0xe0, 0xfd, 0x1a, 0x37, 0x54, 0x71, 0x8e, 0xab,
4018 0xc8, 0xe5, 0x02, 0x1f, 0x3c, 0x59, 0x76, 0x93,
4019 0xb0, 0xcd, 0xea, 0x07, 0x24, 0x41, 0x5e, 0x7b,
4020 0x98, 0xb5, 0xd2, 0xef, 0x0c, 0x29, 0x46, 0x63,
4021 0x80, 0x9d, 0xba, 0xd7, 0xf4, 0x11, 0x2e, 0x4b,
4022 0x68, 0x85, 0xa2, 0xbf, 0xdc, 0xf9, 0x16, 0x33,
4023 0x50, 0x6d, 0x8a, 0xa7, 0xc4, 0xe1, 0xfe, 0x1b,
4024 0x38, 0x55, 0x72, 0x8f, 0xac, 0xc9, 0xe6, 0x03,
4025 0x20, 0x3d, 0x5a, 0x77, 0x94, 0xb1, 0xce, 0xeb,
4026 0x08, 0x25, 0x42, 0x5f, 0x7c, 0x99, 0xb6, 0xd3,
4027 0xf0, 0x0d, 0x2a, 0x47, 0x64, 0x81, 0x9e, 0xbb,
4028 0xd8, 0xf5, 0x12, 0x2f, 0x4c, 0x69, 0x86, 0xa3,
4029 0xc0, 0xdd, 0xfa, 0x17, 0x34, 0x51, 0x6e, 0x8b,
4030 0xa8, 0xc5, 0xe2, 0xff, 0x1c, 0x39, 0x56, 0x73,
4031 0x90, 0xad, 0xca, 0xe7, 0x04, 0x21, 0x3e, 0x5b,
4032 0x78, 0x95, 0xb2, 0xcf, 0xec, 0x09, 0x26, 0x43,
4033 0x60, 0x7d, 0x9a, 0xb7, 0xd4, 0xf1, 0x0e, 0x2b,
4034 0x48, 0x65, 0x82, 0x9f, 0xbc, 0xd9, 0xf6, 0x13,
4035 0x30, 0x4d, 0x6a, 0x87, 0xa4, 0xc1, 0xde, 0xfb,
4036 0x18, 0x35, 0x52, 0x6f, 0x8c, 0xa9, 0xc6, 0xe3,
4037 0x00, 0x1f, 0x3e, 0x5d, 0x7c, 0x9b, 0xba, 0xd9,
4038 0xf8, 0x17, 0x36, 0x55, 0x74, 0x93, 0xb2, 0xd1,
4039 0xf0, 0x0f, 0x2e, 0x4d, 0x6c, 0x8b, 0xaa, 0xc9,
4040 0xe8, 0x07, 0x26, 0x45, 0x64, 0x83, 0xa2, 0xc1,
4041 0xe0, 0xff, 0x1e, 0x3d, 0x5c, 0x7b, 0x9a, 0xb9,
4042 0xd8, 0xf7, 0x16, 0x35, 0x54, 0x73, 0x92, 0xb1,
4043 0xd0, 0xef, 0x0e, 0x2d, 0x4c, 0x6b, 0x8a, 0xa9,
4044 0xc8, 0xe7, 0x06, 0x25, 0x44, 0x63, 0x82, 0xa1,
4045 0xc0, 0xdf, 0xfe, 0x1d, 0x3c, 0x5b, 0x7a, 0x99,
4046 0xb8, 0xd7, 0xf6, 0x15, 0x34, 0x53, 0x72, 0x91,
4047 0xb0, 0xcf, 0xee, 0x0d, 0x2c, 0x4b, 0x6a, 0x89,
4048 0xa8, 0xc7, 0xe6, 0x05, 0x24, 0x43, 0x62, 0x81,
4049 0xa0, 0xbf, 0xde, 0xfd, 0x1c, 0x3b, 0x5a, 0x79,
4050 0x98, 0xb7, 0xd6, 0xf5, 0x14, 0x33, 0x52, 0x71,
4051 0x90, 0xaf, 0xce, 0xed, 0x0c, 0x2b, 0x4a, 0x69,
4052 0x88, 0xa7, 0xc6, 0xe5, 0x04, 0x23, 0x42, 0x61,
4053 0x80, 0x9f, 0xbe, 0xdd, 0xfc, 0x1b, 0x3a, 0x59,
4054 0x78, 0x97, 0xb6, 0xd5, 0xf4, 0x13, 0x32, 0x51,
4055 0x70, 0x8f, 0xae, 0xcd, 0xec, 0x0b, 0x2a, 0x49,
4056 0x68, 0x87, 0xa6, 0xc5, 0xe4, 0x03, 0x22, 0x41,
4057 0x60, 0x7f, 0x9e, 0xbd, 0xdc, 0xfb, 0x1a, 0x39,
4058 0x58, 0x77, 0x96, 0xb5, 0xd4, 0xf3, 0x12, 0x31,
4059 0x50, 0x6f, 0x8e, 0xad, 0xcc, 0xeb, 0x0a, 0x29,
4060 0x48, 0x67, 0x86, 0xa5, 0xc4, 0xe3, 0x02, 0x21,
4061 0x40, 0x5f, 0x7e, 0x9d, 0xbc, 0xdb, 0xfa, 0x19,
4062 0x38, 0x57, 0x76, 0x95, 0xb4, 0xd3, 0xf2, 0x11,
4063 0x30, 0x4f, 0x6e, 0x8d, 0xac, 0xcb, 0xea, 0x09,
4064 0x28, 0x47, 0x66, 0x85, 0xa4, 0xc3, 0xe2, 0x01,
4065 0x20, 0x3f, 0x5e, 0x7d, 0x9c, 0xbb, 0xda, 0xf9,
4066 0x18, 0x37, 0x56, 0x75, 0x94, 0xb3, 0xd2, 0xf1,
4067 0x10, 0x2f, 0x4e, 0x6d, 0x8c, 0xab, 0xca, 0xe9,
4068 0x08, 0x27, 0x46, 0x65, 0x84, 0xa3, 0xc2, 0xe1,
4069 0x00, 0x21, 0x42, 0x63,
4070 },
4071 .ilen = 4100,
4072 .result = {
4073 0xf0, 0x5c, 0x74, 0xad, 0x4e, 0xbc, 0x99, 0xe2,
4074 0xae, 0xff, 0x91, 0x3a, 0x44, 0xcf, 0x38, 0x32,
4075 0x1e, 0xad, 0xa7, 0xcd, 0xa1, 0x39, 0x95, 0xaa,
4076 0x10, 0xb1, 0xb3, 0x2e, 0x04, 0x31, 0x8f, 0x86,
4077 0xf2, 0x62, 0x74, 0x70, 0x0c, 0xa4, 0x46, 0x08,
4078 0xa8, 0xb7, 0x99, 0xa8, 0xe9, 0xd2, 0x73, 0x79,
4079 0x7e, 0x6e, 0xd4, 0x8f, 0x1e, 0xc7, 0x8e, 0x31,
4080 0x0b, 0xfa, 0x4b, 0xce, 0xfd, 0xf3, 0x57, 0x71,
4081 0xe9, 0x46, 0x03, 0xa5, 0x3d, 0x34, 0x00, 0xe2,
4082 0x18, 0xff, 0x75, 0x6d, 0x06, 0x2d, 0x00, 0xab,
4083 0xb9, 0x3e, 0x6c, 0x59, 0xc5, 0x84, 0x06, 0xb5,
4084 0x8b, 0xd0, 0x89, 0x9c, 0x4a, 0x79, 0x16, 0xc6,
4085 0x3d, 0x74, 0x54, 0xfa, 0x44, 0xcd, 0x23, 0x26,
4086 0x5c, 0xcf, 0x7e, 0x28, 0x92, 0x32, 0xbf, 0xdf,
4087 0xa7, 0x20, 0x3c, 0x74, 0x58, 0x2a, 0x9a, 0xde,
4088 0x61, 0x00, 0x1c, 0x4f, 0xff, 0x59, 0xc4, 0x22,
4089 0xac, 0x3c, 0xd0, 0xe8, 0x6c, 0xf9, 0x97, 0x1b,
4090 0x58, 0x9b, 0xad, 0x71, 0xe8, 0xa9, 0xb5, 0x0d,
4091 0xee, 0x2f, 0x04, 0x1f, 0x7f, 0xbc, 0x99, 0xee,
4092 0x84, 0xff, 0x42, 0x60, 0xdc, 0x3a, 0x18, 0xa5,
4093 0x81, 0xf9, 0xef, 0xdc, 0x7a, 0x0f, 0x65, 0x41,
4094 0x2f, 0xa3, 0xd3, 0xf9, 0xc2, 0xcb, 0xc0, 0x4d,
4095 0x8f, 0xd3, 0x76, 0x96, 0xad, 0x49, 0x6d, 0x38,
4096 0x3d, 0x39, 0x0b, 0x6c, 0x80, 0xb7, 0x54, 0x69,
4097 0xf0, 0x2c, 0x90, 0x02, 0x29, 0x0d, 0x1c, 0x12,
4098 0xad, 0x55, 0xc3, 0x8b, 0x68, 0xd9, 0xcc, 0xb3,
4099 0xb2, 0x64, 0x33, 0x90, 0x5e, 0xca, 0x4b, 0xe2,
4100 0xfb, 0x75, 0xdc, 0x63, 0xf7, 0x9f, 0x82, 0x74,
4101 0xf0, 0xc9, 0xaa, 0x7f, 0xe9, 0x2a, 0x9b, 0x33,
4102 0xbc, 0x88, 0x00, 0x7f, 0xca, 0xb2, 0x1f, 0x14,
4103 0xdb, 0xc5, 0x8e, 0x7b, 0x11, 0x3c, 0x3e, 0x08,
4104 0xf3, 0x83, 0xe8, 0xe0, 0x94, 0x86, 0x2e, 0x92,
4105 0x78, 0x6b, 0x01, 0xc9, 0xc7, 0x83, 0xba, 0x21,
4106 0x6a, 0x25, 0x15, 0x33, 0x4e, 0x45, 0x08, 0xec,
4107 0x35, 0xdb, 0xe0, 0x6e, 0x31, 0x51, 0x79, 0xa9,
4108 0x42, 0x44, 0x65, 0xc1, 0xa0, 0xf1, 0xf9, 0x2a,
4109 0x70, 0xd5, 0xb6, 0xc6, 0xc1, 0x8c, 0x39, 0xfc,
4110 0x25, 0xa6, 0x55, 0xd9, 0xdd, 0x2d, 0x4c, 0xec,
4111 0x49, 0xc6, 0xeb, 0x0e, 0xa8, 0x25, 0x2a, 0x16,
4112 0x1b, 0x66, 0x84, 0xda, 0xe2, 0x92, 0xe5, 0xc0,
4113 0xc8, 0x53, 0x07, 0xaf, 0x80, 0x84, 0xec, 0xfd,
4114 0xcd, 0xd1, 0x6e, 0xcd, 0x6f, 0x6a, 0xf5, 0x36,
4115 0xc5, 0x15, 0xe5, 0x25, 0x7d, 0x77, 0xd1, 0x1a,
4116 0x93, 0x36, 0xa9, 0xcf, 0x7c, 0xa4, 0x54, 0x4a,
4117 0x06, 0x51, 0x48, 0x4e, 0xf6, 0x59, 0x87, 0xd2,
4118 0x04, 0x02, 0xef, 0xd3, 0x44, 0xde, 0x76, 0x31,
4119 0xb3, 0x34, 0x17, 0x1b, 0x9d, 0x66, 0x11, 0x9f,
4120 0x1e, 0xcc, 0x17, 0xe9, 0xc7, 0x3c, 0x1b, 0xe7,
4121 0xcb, 0x50, 0x08, 0xfc, 0xdc, 0x2b, 0x24, 0xdb,
4122 0x65, 0x83, 0xd0, 0x3b, 0xe3, 0x30, 0xea, 0x94,
4123 0x6c, 0xe7, 0xe8, 0x35, 0x32, 0xc7, 0xdb, 0x64,
4124 0xb4, 0x01, 0xab, 0x36, 0x2c, 0x77, 0x13, 0xaf,
4125 0xf8, 0x2b, 0x88, 0x3f, 0x54, 0x39, 0xc4, 0x44,
4126 0xfe, 0xef, 0x6f, 0x68, 0x34, 0xbe, 0x0f, 0x05,
4127 0x16, 0x6d, 0xf6, 0x0a, 0x30, 0xe7, 0xe3, 0xed,
4128 0xc4, 0xde, 0x3c, 0x1b, 0x13, 0xd8, 0xdb, 0xfe,
4129 0x41, 0x62, 0xe5, 0x28, 0xd4, 0x8d, 0xa3, 0xc7,
4130 0x93, 0x97, 0xc6, 0x48, 0x45, 0x1d, 0x9f, 0x83,
4131 0xdf, 0x4b, 0x40, 0x3e, 0x42, 0x25, 0x87, 0x80,
4132 0x4c, 0x7d, 0xa8, 0xd4, 0x98, 0x23, 0x95, 0x75,
4133 0x41, 0x8c, 0xda, 0x41, 0x9b, 0xd4, 0xa7, 0x06,
4134 0xb5, 0xf1, 0x71, 0x09, 0x53, 0xbe, 0xca, 0xbf,
4135 0x32, 0x03, 0xed, 0xf0, 0x50, 0x1c, 0x56, 0x39,
4136 0x5b, 0xa4, 0x75, 0x18, 0xf7, 0x9b, 0x58, 0xef,
4137 0x53, 0xfc, 0x2a, 0x38, 0x23, 0x15, 0x75, 0xcd,
4138 0x45, 0xe5, 0x5a, 0x82, 0x55, 0xba, 0x21, 0xfa,
4139 0xd4, 0xbd, 0xc6, 0x94, 0x7c, 0xc5, 0x80, 0x12,
4140 0xf7, 0x4b, 0x32, 0xc4, 0x9a, 0x82, 0xd8, 0x28,
4141 0x8f, 0xd9, 0xc2, 0x0f, 0x60, 0x03, 0xbe, 0x5e,
4142 0x21, 0xd6, 0x5f, 0x58, 0xbf, 0x5c, 0xb1, 0x32,
4143 0x82, 0x8d, 0xa9, 0xe5, 0xf2, 0x66, 0x1a, 0xc0,
4144 0xa0, 0xbc, 0x58, 0x2f, 0x71, 0xf5, 0x2f, 0xed,
4145 0xd1, 0x26, 0xb9, 0xd8, 0x49, 0x5a, 0x07, 0x19,
4146 0x01, 0x7c, 0x59, 0xb0, 0xf8, 0xa4, 0xb7, 0xd3,
4147 0x7b, 0x1a, 0x8c, 0x38, 0xf4, 0x50, 0xa4, 0x59,
4148 0xb0, 0xcc, 0x41, 0x0b, 0x88, 0x7f, 0xe5, 0x31,
4149 0xb3, 0x42, 0xba, 0xa2, 0x7e, 0xd4, 0x32, 0x71,
4150 0x45, 0x87, 0x48, 0xa9, 0xc2, 0xf2, 0x89, 0xb3,
4151 0xe4, 0xa7, 0x7e, 0x52, 0x15, 0x61, 0xfa, 0xfe,
4152 0xc9, 0xdd, 0x81, 0xeb, 0x13, 0xab, 0xab, 0xc3,
4153 0x98, 0x59, 0xd8, 0x16, 0x3d, 0x14, 0x7a, 0x1c,
4154 0x3c, 0x41, 0x9a, 0x16, 0x16, 0x9b, 0xd2, 0xd2,
4155 0x69, 0x3a, 0x29, 0x23, 0xac, 0x86, 0x32, 0xa5,
4156 0x48, 0x9c, 0x9e, 0xf3, 0x47, 0x77, 0x81, 0x70,
4157 0x24, 0xe8, 0x85, 0xd2, 0xf5, 0xb5, 0xfa, 0xff,
4158 0x59, 0x6a, 0xd3, 0x50, 0x59, 0x43, 0x59, 0xde,
4159 0xd9, 0xf1, 0x55, 0xa5, 0x0c, 0xc3, 0x1a, 0x1a,
4160 0x18, 0x34, 0x0d, 0x1a, 0x63, 0x33, 0xed, 0x10,
4161 0xe0, 0x1d, 0x2a, 0x18, 0xd2, 0xc0, 0x54, 0xa8,
4162 0xca, 0xb5, 0x9a, 0xd3, 0xdd, 0xca, 0x45, 0x84,
4163 0x50, 0xe7, 0x0f, 0xfe, 0xa4, 0x99, 0x5a, 0xbe,
4164 0x43, 0x2d, 0x9a, 0xcb, 0x92, 0x3f, 0x5a, 0x1d,
4165 0x85, 0xd8, 0xc9, 0xdf, 0x68, 0xc9, 0x12, 0x80,
4166 0x56, 0x0c, 0xdc, 0x00, 0xdc, 0x3a, 0x7d, 0x9d,
4167 0xa3, 0xa2, 0xe8, 0x4d, 0xbf, 0xf9, 0x70, 0xa0,
4168 0xa4, 0x13, 0x4f, 0x6b, 0xaf, 0x0a, 0x89, 0x7f,
4169 0xda, 0xf0, 0xbf, 0x9b, 0xc8, 0x1d, 0xe5, 0xf8,
4170 0x2e, 0x8b, 0x07, 0xb5, 0x73, 0x1b, 0xcc, 0xa2,
4171 0xa6, 0xad, 0x30, 0xbc, 0x78, 0x3c, 0x5b, 0x10,
4172 0xfa, 0x5e, 0x62, 0x2d, 0x9e, 0x64, 0xb3, 0x33,
4173 0xce, 0xf9, 0x1f, 0x86, 0xe7, 0x8b, 0xa2, 0xb8,
4174 0xe8, 0x99, 0x57, 0x8c, 0x11, 0xed, 0x66, 0xd9,
4175 0x3c, 0x72, 0xb9, 0xc3, 0xe6, 0x4e, 0x17, 0x3a,
4176 0x6a, 0xcb, 0x42, 0x24, 0x06, 0xed, 0x3e, 0x4e,
4177 0xa3, 0xe8, 0x6a, 0x94, 0xda, 0x0d, 0x4e, 0xd5,
4178 0x14, 0x19, 0xcf, 0xb6, 0x26, 0xd8, 0x2e, 0xcc,
4179 0x64, 0x76, 0x38, 0x49, 0x4d, 0xfe, 0x30, 0x6d,
4180 0xe4, 0xc8, 0x8c, 0x7b, 0xc4, 0xe0, 0x35, 0xba,
4181 0x22, 0x6e, 0x76, 0xe1, 0x1a, 0xf2, 0x53, 0xc3,
4182 0x28, 0xa2, 0x82, 0x1f, 0x61, 0x69, 0xad, 0xc1,
4183 0x7b, 0x28, 0x4b, 0x1e, 0x6c, 0x85, 0x95, 0x9b,
4184 0x51, 0xb5, 0x17, 0x7f, 0x12, 0x69, 0x8c, 0x24,
4185 0xd5, 0xc7, 0x5a, 0x5a, 0x11, 0x54, 0xff, 0x5a,
4186 0xf7, 0x16, 0xc3, 0x91, 0xa6, 0xf0, 0xdc, 0x0a,
4187 0xb6, 0xa7, 0x4a, 0x0d, 0x7a, 0x58, 0xfe, 0xa5,
4188 0xf5, 0xcb, 0x8f, 0x7b, 0x0e, 0xea, 0x57, 0xe7,
4189 0xbd, 0x79, 0xd6, 0x1c, 0x88, 0x23, 0x6c, 0xf2,
4190 0x4d, 0x29, 0x77, 0x53, 0x35, 0x6a, 0x00, 0x8d,
4191 0xcd, 0xa3, 0x58, 0xbe, 0x77, 0x99, 0x18, 0xf8,
4192 0xe6, 0xe1, 0x8f, 0xe9, 0x37, 0x8f, 0xe3, 0xe2,
4193 0x5a, 0x8a, 0x93, 0x25, 0xaf, 0xf3, 0x78, 0x80,
4194 0xbe, 0xa6, 0x1b, 0xc6, 0xac, 0x8b, 0x1c, 0x91,
4195 0x58, 0xe1, 0x9f, 0x89, 0x35, 0x9d, 0x1d, 0x21,
4196 0x29, 0x9f, 0xf4, 0x99, 0x02, 0x27, 0x0f, 0xa8,
4197 0x4f, 0x79, 0x94, 0x2b, 0x33, 0x2c, 0xda, 0xa2,
4198 0x26, 0x39, 0x83, 0x94, 0xef, 0x27, 0xd8, 0x53,
4199 0x8f, 0x66, 0x0d, 0xe4, 0x41, 0x7d, 0x34, 0xcd,
4200 0x43, 0x7c, 0x95, 0x0a, 0x53, 0xef, 0x66, 0xda,
4201 0x7e, 0x9b, 0xf3, 0x93, 0xaf, 0xd0, 0x73, 0x71,
4202 0xba, 0x40, 0x9b, 0x74, 0xf8, 0xd7, 0xd7, 0x41,
4203 0x6d, 0xaf, 0x72, 0x9c, 0x8d, 0x21, 0x87, 0x3c,
4204 0xfd, 0x0a, 0x90, 0xa9, 0x47, 0x96, 0x9e, 0xd3,
4205 0x88, 0xee, 0x73, 0xcf, 0x66, 0x2f, 0x52, 0x56,
4206 0x6d, 0xa9, 0x80, 0x4c, 0xe2, 0x6f, 0x62, 0x88,
4207 0x3f, 0x0e, 0x54, 0x17, 0x48, 0x80, 0x5d, 0xd3,
4208 0xc3, 0xda, 0x25, 0x3d, 0xa1, 0xc8, 0xcb, 0x9f,
4209 0x9b, 0x70, 0xb3, 0xa1, 0xeb, 0x04, 0x52, 0xa1,
4210 0xf2, 0x22, 0x0f, 0xfc, 0xc8, 0x18, 0xfa, 0xf9,
4211 0x85, 0x9c, 0xf1, 0xac, 0xeb, 0x0c, 0x02, 0x46,
4212 0x75, 0xd2, 0xf5, 0x2c, 0xe3, 0xd2, 0x59, 0x94,
4213 0x12, 0xf3, 0x3c, 0xfc, 0xd7, 0x92, 0xfa, 0x36,
4214 0xba, 0x61, 0x34, 0x38, 0x7c, 0xda, 0x48, 0x3e,
4215 0x08, 0xc9, 0x39, 0x23, 0x5e, 0x02, 0x2c, 0x1a,
4216 0x18, 0x7e, 0xb4, 0xd9, 0xfd, 0x9e, 0x40, 0x02,
4217 0xb1, 0x33, 0x37, 0x32, 0xe7, 0xde, 0xd6, 0xd0,
4218 0x7c, 0x58, 0x65, 0x4b, 0xf8, 0x34, 0x27, 0x9c,
4219 0x44, 0xb4, 0xbd, 0xe9, 0xe9, 0x4c, 0x78, 0x7d,
4220 0x4b, 0x9f, 0xce, 0xb1, 0xcd, 0x47, 0xa5, 0x37,
4221 0xe5, 0x6d, 0xbd, 0xb9, 0x43, 0x94, 0x0a, 0xd4,
4222 0xd6, 0xf9, 0x04, 0x5f, 0xb5, 0x66, 0x6c, 0x1a,
4223 0x35, 0x12, 0xe3, 0x36, 0x28, 0x27, 0x36, 0x58,
4224 0x01, 0x2b, 0x79, 0xe4, 0xba, 0x6d, 0x10, 0x7d,
4225 0x65, 0xdf, 0x84, 0x95, 0xf4, 0xd5, 0xb6, 0x8f,
4226 0x2b, 0x9f, 0x96, 0x00, 0x86, 0x60, 0xf0, 0x21,
4227 0x76, 0xa8, 0x6a, 0x8c, 0x28, 0x1c, 0xb3, 0x6b,
4228 0x97, 0xd7, 0xb6, 0x53, 0x2a, 0xcc, 0xab, 0x40,
4229 0x9d, 0x62, 0x79, 0x58, 0x52, 0xe6, 0x65, 0xb7,
4230 0xab, 0x55, 0x67, 0x9c, 0x89, 0x7c, 0x03, 0xb0,
4231 0x73, 0x59, 0xc5, 0x81, 0xf5, 0x18, 0x17, 0x5c,
4232 0x89, 0xf3, 0x78, 0x35, 0x44, 0x62, 0x78, 0x72,
4233 0xd0, 0x96, 0xeb, 0x31, 0xe7, 0x87, 0x77, 0x14,
4234 0x99, 0x51, 0xf2, 0x59, 0x26, 0x9e, 0xb5, 0xa6,
4235 0x45, 0xfe, 0x6e, 0xbd, 0x07, 0x4c, 0x94, 0x5a,
4236 0xa5, 0x7d, 0xfc, 0xf1, 0x2b, 0x77, 0xe2, 0xfe,
4237 0x17, 0xd4, 0x84, 0xa0, 0xac, 0xb5, 0xc7, 0xda,
4238 0xa9, 0x1a, 0xb6, 0xf3, 0x74, 0x11, 0xb4, 0x9d,
4239 0xfb, 0x79, 0x2e, 0x04, 0x2d, 0x50, 0x28, 0x83,
4240 0xbf, 0xc6, 0x52, 0xd3, 0x34, 0xd6, 0xe8, 0x7a,
4241 0xb6, 0xea, 0xe7, 0xa8, 0x6c, 0x15, 0x1e, 0x2c,
4242 0x57, 0xbc, 0x48, 0x4e, 0x5f, 0x5c, 0xb6, 0x92,
4243 0xd2, 0x49, 0x77, 0x81, 0x6d, 0x90, 0x70, 0xae,
4244 0x98, 0xa1, 0x03, 0x0d, 0x6b, 0xb9, 0x77, 0x14,
4245 0xf1, 0x4e, 0x23, 0xd3, 0xf8, 0x68, 0xbd, 0xc2,
4246 0xfe, 0x04, 0xb7, 0x5c, 0xc5, 0x17, 0x60, 0x8f,
4247 0x65, 0x54, 0xa4, 0x7a, 0x42, 0xdc, 0x18, 0x0d,
4248 0xb5, 0xcf, 0x0f, 0xd3, 0xc7, 0x91, 0x66, 0x1b,
4249 0x45, 0x42, 0x27, 0x75, 0x50, 0xe5, 0xee, 0xb8,
4250 0x7f, 0x33, 0x2c, 0xba, 0x4a, 0x92, 0x4d, 0x2c,
4251 0x3c, 0xe3, 0x0d, 0x80, 0x01, 0xba, 0x0d, 0x29,
4252 0xd8, 0x3c, 0xe9, 0x13, 0x16, 0x57, 0xe6, 0xea,
4253 0x94, 0x52, 0xe7, 0x00, 0x4d, 0x30, 0xb0, 0x0f,
4254 0x35, 0xb8, 0xb8, 0xa7, 0xb1, 0xb5, 0x3b, 0x44,
4255 0xe1, 0x2f, 0xfd, 0x88, 0xed, 0x43, 0xe7, 0x52,
4256 0x10, 0x93, 0xb3, 0x8a, 0x30, 0x6b, 0x0a, 0xf7,
4257 0x23, 0xc6, 0x50, 0x9d, 0x4a, 0xb0, 0xde, 0xc3,
4258 0xdc, 0x9b, 0x2f, 0x01, 0x56, 0x36, 0x09, 0xc5,
4259 0x2f, 0x6b, 0xfe, 0xf1, 0xd8, 0x27, 0x45, 0x03,
4260 0x30, 0x5e, 0x5c, 0x5b, 0xb4, 0x62, 0x0e, 0x1a,
4261 0xa9, 0x21, 0x2b, 0x92, 0x94, 0x87, 0x62, 0x57,
4262 0x4c, 0x10, 0x74, 0x1a, 0xf1, 0x0a, 0xc5, 0x84,
4263 0x3b, 0x9e, 0x72, 0x02, 0xd7, 0xcc, 0x09, 0x56,
4264 0xbd, 0x54, 0xc1, 0xf0, 0xc3, 0xe3, 0xb3, 0xf8,
4265 0xd2, 0x0d, 0x61, 0xcb, 0xef, 0xce, 0x0d, 0x05,
4266 0xb0, 0x98, 0xd9, 0x8e, 0x4f, 0xf9, 0xbc, 0x93,
4267 0xa6, 0xea, 0xc8, 0xcf, 0x10, 0x53, 0x4b, 0xf1,
4268 0xec, 0xfc, 0x89, 0xf9, 0x64, 0xb0, 0x22, 0xbf,
4269 0x9e, 0x55, 0x46, 0x9f, 0x7c, 0x50, 0x8e, 0x84,
4270 0x54, 0x20, 0x98, 0xd7, 0x6c, 0x40, 0x1e, 0xdb,
4271 0x69, 0x34, 0x78, 0x61, 0x24, 0x21, 0x9c, 0x8a,
4272 0xb3, 0x62, 0x31, 0x8b, 0x6e, 0xf5, 0x2a, 0x35,
4273 0x86, 0x13, 0xb1, 0x6c, 0x64, 0x2e, 0x41, 0xa5,
4274 0x05, 0xf2, 0x42, 0xba, 0xd2, 0x3a, 0x0d, 0x8e,
4275 0x8a, 0x59, 0x94, 0x3c, 0xcf, 0x36, 0x27, 0x82,
4276 0xc2, 0x45, 0xee, 0x58, 0xcd, 0x88, 0xb4, 0xec,
4277 0xde, 0xb2, 0x96, 0x0a, 0xaf, 0x38, 0x6f, 0x88,
4278 0xd7, 0xd8, 0xe1, 0xdf, 0xb9, 0x96, 0xa9, 0x0a,
4279 0xb1, 0x95, 0x28, 0x86, 0x20, 0xe9, 0x17, 0x49,
4280 0xa2, 0x29, 0x38, 0xaa, 0xa5, 0xe9, 0x6e, 0xf1,
4281 0x19, 0x27, 0xc0, 0xd5, 0x2a, 0x22, 0xc3, 0x0b,
4282 0xdb, 0x7c, 0x73, 0x10, 0xb9, 0xba, 0x89, 0x76,
4283 0x54, 0xae, 0x7d, 0x71, 0xb3, 0x93, 0xf6, 0x32,
4284 0xe6, 0x47, 0x43, 0x55, 0xac, 0xa0, 0x0d, 0xc2,
4285 0x93, 0x27, 0x4a, 0x8e, 0x0e, 0x74, 0x15, 0xc7,
4286 0x0b, 0x85, 0xd9, 0x0c, 0xa9, 0x30, 0x7a, 0x3e,
4287 0xea, 0x8f, 0x85, 0x6d, 0x3a, 0x12, 0x4f, 0x72,
4288 0x69, 0x58, 0x7a, 0x80, 0xbb, 0xb5, 0x97, 0xf3,
4289 0xcf, 0x70, 0xd2, 0x5d, 0xdd, 0x4d, 0x21, 0x79,
4290 0x54, 0x4d, 0xe4, 0x05, 0xe8, 0xbd, 0xc2, 0x62,
4291 0xb1, 0x3b, 0x77, 0x1c, 0xd6, 0x5c, 0xf3, 0xa0,
4292 0x79, 0x00, 0xa8, 0x6c, 0x29, 0xd9, 0x18, 0x24,
4293 0x36, 0xa2, 0x46, 0xc0, 0x96, 0x65, 0x7f, 0xbd,
4294 0x2a, 0xed, 0x36, 0x16, 0x0c, 0xaa, 0x9f, 0xf4,
4295 0xc5, 0xb4, 0xe2, 0x12, 0xed, 0x69, 0xed, 0x4f,
4296 0x26, 0x2c, 0x39, 0x52, 0x89, 0x98, 0xe7, 0x2c,
4297 0x99, 0xa4, 0x9e, 0xa3, 0x9b, 0x99, 0x46, 0x7a,
4298 0x3a, 0xdc, 0xa8, 0x59, 0xa3, 0xdb, 0xc3, 0x3b,
4299 0x95, 0x0d, 0x3b, 0x09, 0x6e, 0xee, 0x83, 0x5d,
4300 0x32, 0x4d, 0xed, 0xab, 0xfa, 0x98, 0x14, 0x4e,
4301 0xc3, 0x15, 0x45, 0x53, 0x61, 0xc4, 0x93, 0xbd,
4302 0x90, 0xf4, 0x99, 0x95, 0x4c, 0xe6, 0x76, 0x92,
4303 0x29, 0x90, 0x46, 0x30, 0x92, 0x69, 0x7d, 0x13,
4304 0xf2, 0xa5, 0xcd, 0x69, 0x49, 0x44, 0xb2, 0x0f,
4305 0x63, 0x40, 0x36, 0x5f, 0x09, 0xe2, 0x78, 0xf8,
4306 0x91, 0xe3, 0xe2, 0xfa, 0x10, 0xf7, 0xc8, 0x24,
4307 0xa8, 0x89, 0x32, 0x5c, 0x37, 0x25, 0x1d, 0xb2,
4308 0xea, 0x17, 0x8a, 0x0a, 0xa9, 0x64, 0xc3, 0x7c,
4309 0x3c, 0x7c, 0xbd, 0xc6, 0x79, 0x34, 0xe7, 0xe2,
4310 0x85, 0x8e, 0xbf, 0xf8, 0xde, 0x92, 0xa0, 0xae,
4311 0x20, 0xc4, 0xf6, 0xbb, 0x1f, 0x38, 0x19, 0x0e,
4312 0xe8, 0x79, 0x9c, 0xa1, 0x23, 0xe9, 0x54, 0x7e,
4313 0x37, 0x2f, 0xe2, 0x94, 0x32, 0xaf, 0xa0, 0x23,
4314 0x49, 0xe4, 0xc0, 0xb3, 0xac, 0x00, 0x8f, 0x36,
4315 0x05, 0xc4, 0xa6, 0x96, 0xec, 0x05, 0x98, 0x4f,
4316 0x96, 0x67, 0x57, 0x1f, 0x20, 0x86, 0x1b, 0x2d,
4317 0x69, 0xe4, 0x29, 0x93, 0x66, 0x5f, 0xaf, 0x6b,
4318 0x88, 0x26, 0x2c, 0x67, 0x02, 0x4b, 0x52, 0xd0,
4319 0x83, 0x7a, 0x43, 0x1f, 0xc0, 0x71, 0x15, 0x25,
4320 0x77, 0x65, 0x08, 0x60, 0x11, 0x76, 0x4c, 0x8d,
4321 0xed, 0xa9, 0x27, 0xc6, 0xb1, 0x2a, 0x2c, 0x6a,
4322 0x4a, 0x97, 0xf5, 0xc6, 0xb7, 0x70, 0x42, 0xd3,
4323 0x03, 0xd1, 0x24, 0x95, 0xec, 0x6d, 0xab, 0x38,
4324 0x72, 0xce, 0xe2, 0x8b, 0x33, 0xd7, 0x51, 0x09,
4325 0xdc, 0x45, 0xe0, 0x09, 0x96, 0x32, 0xf3, 0xc4,
4326 0x84, 0xdc, 0x73, 0x73, 0x2d, 0x1b, 0x11, 0x98,
4327 0xc5, 0x0e, 0x69, 0x28, 0x94, 0xc7, 0xb5, 0x4d,
4328 0xc8, 0x8a, 0xd0, 0xaa, 0x13, 0x2e, 0x18, 0x74,
4329 0xdd, 0xd1, 0x1e, 0xf3, 0x90, 0xe8, 0xfc, 0x9a,
4330 0x72, 0x4a, 0x0e, 0xd1, 0xe4, 0xfb, 0x0d, 0x96,
4331 0xd1, 0x0c, 0x79, 0x85, 0x1b, 0x1c, 0xfe, 0xe1,
4332 0x62, 0x8f, 0x7a, 0x73, 0x32, 0xab, 0xc8, 0x18,
4333 0x69, 0xe3, 0x34, 0x30, 0xdf, 0x13, 0xa6, 0xe5,
4334 0xe8, 0x0e, 0x67, 0x7f, 0x81, 0x11, 0xb4, 0x60,
4335 0xc7, 0xbd, 0x79, 0x65, 0x50, 0xdc, 0xc4, 0x5b,
4336 0xde, 0x39, 0xa4, 0x01, 0x72, 0x63, 0xf3, 0xd1,
4337 0x64, 0x4e, 0xdf, 0xfc, 0x27, 0x92, 0x37, 0x0d,
4338 0x57, 0xcd, 0x11, 0x4f, 0x11, 0x04, 0x8e, 0x1d,
4339 0x16, 0xf7, 0xcd, 0x92, 0x9a, 0x99, 0x30, 0x14,
4340 0xf1, 0x7c, 0x67, 0x1b, 0x1f, 0x41, 0x0b, 0xe8,
4341 0x32, 0xe8, 0xb8, 0xc1, 0x4f, 0x54, 0x86, 0x4f,
4342 0xe5, 0x79, 0x81, 0x73, 0xcd, 0x43, 0x59, 0x68,
4343 0x73, 0x02, 0x3b, 0x78, 0x21, 0x72, 0x43, 0x00,
4344 0x49, 0x17, 0xf7, 0x00, 0xaf, 0x68, 0x24, 0x53,
4345 0x05, 0x0a, 0xc3, 0x33, 0xe0, 0x33, 0x3f, 0x69,
4346 0xd2, 0x84, 0x2f, 0x0b, 0xed, 0xde, 0x04, 0xf4,
4347 0x11, 0x94, 0x13, 0x69, 0x51, 0x09, 0x28, 0xde,
4348 0x57, 0x5c, 0xef, 0xdc, 0x9a, 0x49, 0x1c, 0x17,
4349 0x97, 0xf3, 0x96, 0xc1, 0x7f, 0x5d, 0x2e, 0x7d,
4350 0x55, 0xb8, 0xb3, 0x02, 0x09, 0xb3, 0x1f, 0xe7,
4351 0xc9, 0x8d, 0xa3, 0x36, 0x34, 0x8a, 0x77, 0x13,
4352 0x30, 0x63, 0x4c, 0xa5, 0xcd, 0xc3, 0xe0, 0x7e,
4353 0x05, 0xa1, 0x7b, 0x0c, 0xcb, 0x74, 0x47, 0x31,
4354 0x62, 0x03, 0x43, 0xf1, 0x87, 0xb4, 0xb0, 0x85,
4355 0x87, 0x8e, 0x4b, 0x25, 0xc7, 0xcf, 0xae, 0x4b,
4356 0x36, 0x46, 0x3e, 0x62, 0xbc, 0x6f, 0xeb, 0x5f,
4357 0x73, 0xac, 0xe6, 0x07, 0xee, 0xc1, 0xa1, 0xd6,
4358 0xc4, 0xab, 0xc9, 0xd6, 0x89, 0x45, 0xe1, 0xf1,
4359 0x04, 0x4e, 0x1a, 0x6f, 0xbb, 0x4f, 0x3a, 0xa3,
4360 0xa0, 0xcb, 0xa3, 0x0a, 0xd8, 0x71, 0x35, 0x55,
4361 0xe4, 0xbc, 0x2e, 0x04, 0x06, 0xe6, 0xff, 0x5b,
4362 0x1c, 0xc0, 0x11, 0x7c, 0xc5, 0x17, 0xf3, 0x38,
4363 0xcf, 0xe9, 0xba, 0x0f, 0x0e, 0xef, 0x02, 0xc2,
4364 0x8d, 0xc6, 0xbc, 0x4b, 0x67, 0x20, 0x95, 0xd7,
4365 0x2c, 0x45, 0x5b, 0x86, 0x44, 0x8c, 0x6f, 0x2e,
4366 0x7e, 0x9f, 0x1c, 0x77, 0xba, 0x6b, 0x0e, 0xa3,
4367 0x69, 0xdc, 0xab, 0x24, 0x57, 0x60, 0x47, 0xc1,
4368 0xd1, 0xa5, 0x9d, 0x23, 0xe6, 0xb1, 0x37, 0xfe,
4369 0x93, 0xd2, 0x4c, 0x46, 0xf9, 0x0c, 0xc6, 0xfb,
4370 0xd6, 0x9d, 0x99, 0x69, 0xab, 0x7a, 0x07, 0x0c,
4371 0x65, 0xe7, 0xc4, 0x08, 0x96, 0xe2, 0xa5, 0x01,
4372 0x3f, 0x46, 0x07, 0x05, 0x7e, 0xe8, 0x9a, 0x90,
4373 0x50, 0xdc, 0xe9, 0x7a, 0xea, 0xa1, 0x39, 0x6e,
4374 0x66, 0xe4, 0x6f, 0xa5, 0x5f, 0xb2, 0xd9, 0x5b,
4375 0xf5, 0xdb, 0x2a, 0x32, 0xf0, 0x11, 0x6f, 0x7c,
4376 0x26, 0x10, 0x8f, 0x3d, 0x80, 0xe9, 0x58, 0xf7,
4377 0xe0, 0xa8, 0x57, 0xf8, 0xdb, 0x0e, 0xce, 0x99,
4378 0x63, 0x19, 0x3d, 0xd5, 0xec, 0x1b, 0x77, 0x69,
4379 0x98, 0xf6, 0xe4, 0x5f, 0x67, 0x17, 0x4b, 0x09,
4380 0x85, 0x62, 0x82, 0x70, 0x18, 0xe2, 0x9a, 0x78,
4381 0xe2, 0x62, 0xbd, 0xb4, 0xf1, 0x42, 0xc6, 0xfb,
4382 0x08, 0xd0, 0xbd, 0xeb, 0x4e, 0x09, 0xf2, 0xc8,
4383 0x1e, 0xdc, 0x3d, 0x32, 0x21, 0x56, 0x9c, 0x4f,
4384 0x35, 0xf3, 0x61, 0x06, 0x72, 0x84, 0xc4, 0x32,
4385 0xf2, 0xf1, 0xfa, 0x0b, 0x2f, 0xc3, 0xdb, 0x02,
4386 0x04, 0xc2, 0xde, 0x57, 0x64, 0x60, 0x8d, 0xcf,
4387 0xcb, 0x86, 0x5d, 0x97, 0x3e, 0xb1, 0x9c, 0x01,
4388 0xd6, 0x28, 0x8f, 0x99, 0xbc, 0x46, 0xeb, 0x05,
4389 0xaf, 0x7e, 0xb8, 0x21, 0x2a, 0x56, 0x85, 0x1c,
4390 0xb3, 0x71, 0xa0, 0xde, 0xca, 0x96, 0xf1, 0x78,
4391 0x49, 0xa2, 0x99, 0x81, 0x80, 0x5c, 0x01, 0xf5,
4392 0xa0, 0xa2, 0x56, 0x63, 0xe2, 0x70, 0x07, 0xa5,
4393 0x95, 0xd6, 0x85, 0xeb, 0x36, 0x9e, 0xa9, 0x51,
4394 0x66, 0x56, 0x5f, 0x1d, 0x02, 0x19, 0xe2, 0xf6,
4395 0x4f, 0x73, 0x38, 0x09, 0x75, 0x64, 0x48, 0xe0,
4396 0xf1, 0x7e, 0x0e, 0xe8, 0x9d, 0xf9, 0xed, 0x94,
4397 0xfe, 0x16, 0x26, 0x62, 0x49, 0x74, 0xf4, 0xb0,
4398 0xd4, 0xa9, 0x6c, 0xb0, 0xfd, 0x53, 0xe9, 0x81,
4399 0xe0, 0x7a, 0xbf, 0xcf, 0xb5, 0xc4, 0x01, 0x81,
4400 0x79, 0x99, 0x77, 0x01, 0x3b, 0xe9, 0xa2, 0xb6,
4401 0xe6, 0x6a, 0x8a, 0x9e, 0x56, 0x1c, 0x8d, 0x1e,
4402 0x8f, 0x06, 0x55, 0x2c, 0x6c, 0xdc, 0x92, 0x87,
4403 0x64, 0x3b, 0x4b, 0x19, 0xa1, 0x13, 0x64, 0x1d,
4404 0x4a, 0xe9, 0xc0, 0x00, 0xb8, 0x95, 0xef, 0x6b,
4405 0x1a, 0x86, 0x6d, 0x37, 0x52, 0x02, 0xc2, 0xe0,
4406 0xc8, 0xbb, 0x42, 0x0c, 0x02, 0x21, 0x4a, 0xc9,
4407 0xef, 0xa0, 0x54, 0xe4, 0x5e, 0x16, 0x53, 0x81,
4408 0x70, 0x62, 0x10, 0xaf, 0xde, 0xb8, 0xb5, 0xd3,
4409 0xe8, 0x5e, 0x6c, 0xc3, 0x8a, 0x3e, 0x18, 0x07,
4410 0xf2, 0x2f, 0x7d, 0xa7, 0xe1, 0x3d, 0x4e, 0xb4,
4411 0x26, 0xa7, 0xa3, 0x93, 0x86, 0xb2, 0x04, 0x1e,
4412 0x53, 0x5d, 0x86, 0xd6, 0xde, 0x65, 0xca, 0xe3,
4413 0x4e, 0xc1, 0xcf, 0xef, 0xc8, 0x70, 0x1b, 0x83,
4414 0x13, 0xdd, 0x18, 0x8b, 0x0d, 0x76, 0xd2, 0xf6,
4415 0x37, 0x7a, 0x93, 0x7a, 0x50, 0x11, 0x9f, 0x96,
4416 0x86, 0x25, 0xfd, 0xac, 0xdc, 0xbe, 0x18, 0x93,
4417 0x19, 0x6b, 0xec, 0x58, 0x4f, 0xb9, 0x75, 0xa7,
4418 0xdd, 0x3f, 0x2f, 0xec, 0xc8, 0x5a, 0x84, 0xab,
4419 0xd5, 0xe4, 0x8a, 0x07, 0xf6, 0x4d, 0x23, 0xd6,
4420 0x03, 0xfb, 0x03, 0x6a, 0xea, 0x66, 0xbf, 0xd4,
4421 0xb1, 0x34, 0xfb, 0x78, 0xe9, 0x55, 0xdc, 0x7c,
4422 0x3d, 0x9c, 0xe5, 0x9a, 0xac, 0xc3, 0x7a, 0x80,
4423 0x24, 0x6d, 0xa0, 0xef, 0x25, 0x7c, 0xb7, 0xea,
4424 0xce, 0x4d, 0x5f, 0x18, 0x60, 0xce, 0x87, 0x22,
4425 0x66, 0x2f, 0xd5, 0xdd, 0xdd, 0x02, 0x21, 0x75,
4426 0x82, 0xa0, 0x1f, 0x58, 0xc6, 0xd3, 0x62, 0xf7,
4427 0x32, 0xd8, 0xaf, 0x1e, 0x07, 0x77, 0x51, 0x96,
4428 0xd5, 0x6b, 0x1e, 0x7e, 0x80, 0x02, 0xe8, 0x67,
4429 0xea, 0x17, 0x0b, 0x10, 0xd2, 0x3f, 0x28, 0x25,
4430 0x4f, 0x05, 0x77, 0x02, 0x14, 0x69, 0xf0, 0x2c,
4431 0xbe, 0x0c, 0xf1, 0x74, 0x30, 0xd1, 0xb9, 0x9b,
4432 0xfc, 0x8c, 0xbb, 0x04, 0x16, 0xd9, 0xba, 0xc3,
4433 0xbc, 0x91, 0x8a, 0xc4, 0x30, 0xa4, 0xb0, 0x12,
4434 0x4c, 0x21, 0x87, 0xcb, 0xc9, 0x1d, 0x16, 0x96,
4435 0x07, 0x6f, 0x23, 0x54, 0xb9, 0x6f, 0x79, 0xe5,
4436 0x64, 0xc0, 0x64, 0xda, 0xb1, 0xae, 0xdd, 0x60,
4437 0x6c, 0x1a, 0x9d, 0xd3, 0x04, 0x8e, 0x45, 0xb0,
4438 0x92, 0x61, 0xd0, 0x48, 0x81, 0xed, 0x5e, 0x1d,
4439 0xa0, 0xc9, 0xa4, 0x33, 0xc7, 0x13, 0x51, 0x5d,
4440 0x7f, 0x83, 0x73, 0xb6, 0x70, 0x18, 0x65, 0x3e,
4441 0x2f, 0x0e, 0x7a, 0x12, 0x39, 0x98, 0xab, 0xd8,
4442 0x7e, 0x6f, 0xa3, 0xd1, 0xba, 0x56, 0xad, 0xbd,
4443 0xf0, 0x03, 0x01, 0x1c, 0x85, 0x35, 0x9f, 0xeb,
4444 0x19, 0x63, 0xa1, 0xaf, 0xfe, 0x2d, 0x35, 0x50,
4445 0x39, 0xa0, 0x65, 0x7c, 0x95, 0x7e, 0x6b, 0xfe,
4446 0xc1, 0xac, 0x07, 0x7c, 0x98, 0x4f, 0xbe, 0x57,
4447 0xa7, 0x22, 0xec, 0xe2, 0x7e, 0x29, 0x09, 0x53,
4448 0xe8, 0xbf, 0xb4, 0x7e, 0x3f, 0x8f, 0xfc, 0x14,
4449 0xce, 0x54, 0xf9, 0x18, 0x58, 0xb5, 0xff, 0x44,
4450 0x05, 0x9d, 0xce, 0x1b, 0xb6, 0x82, 0x23, 0xc8,
4451 0x2e, 0xbc, 0x69, 0xbb, 0x4a, 0x29, 0x0f, 0x65,
4452 0x94, 0xf0, 0x63, 0x06, 0x0e, 0xef, 0x8c, 0xbd,
4453 0xff, 0xfd, 0xb0, 0x21, 0x6e, 0x57, 0x05, 0x75,
4454 0xda, 0xd5, 0xc4, 0xeb, 0x8d, 0x32, 0xf7, 0x50,
4455 0xd3, 0x6f, 0x22, 0xed, 0x5f, 0x8e, 0xa2, 0x5b,
4456 0x80, 0x8c, 0xc8, 0x78, 0x40, 0x24, 0x4b, 0x89,
4457 0x30, 0xce, 0x7a, 0x97, 0x0e, 0xc4, 0xaf, 0xef,
4458 0x9b, 0xb4, 0xcd, 0x66, 0x74, 0x14, 0x04, 0x2b,
4459 0xf7, 0xce, 0x0b, 0x1c, 0x6e, 0xc2, 0x78, 0x8c,
4460 0xca, 0xc5, 0xd0, 0x1c, 0x95, 0x4a, 0x91, 0x2d,
4461 0xa7, 0x20, 0xeb, 0x86, 0x52, 0xb7, 0x67, 0xd8,
4462 0x0c, 0xd6, 0x04, 0x14, 0xde, 0x51, 0x74, 0x75,
4463 0xe7, 0x11, 0xb4, 0x87, 0xa3, 0x3d, 0x2d, 0xad,
4464 0x4f, 0xef, 0xa0, 0x0f, 0x70, 0x00, 0x6d, 0x13,
4465 0x19, 0x1d, 0x41, 0x50, 0xe9, 0xd8, 0xf0, 0x32,
4466 0x71, 0xbc, 0xd3, 0x11, 0xf2, 0xac, 0xbe, 0xaf,
4467 0x75, 0x46, 0x65, 0x4e, 0x07, 0x34, 0x37, 0xa3,
4468 0x89, 0xfe, 0x75, 0xd4, 0x70, 0x4c, 0xc6, 0x3f,
4469 0x69, 0x24, 0x0e, 0x38, 0x67, 0x43, 0x8c, 0xde,
4470 0x06, 0xb5, 0xb8, 0xe7, 0xc4, 0xf0, 0x41, 0x8f,
4471 0xf0, 0xbd, 0x2f, 0x0b, 0xb9, 0x18, 0xf8, 0xde,
4472 0x64, 0xb1, 0xdb, 0xee, 0x00, 0x50, 0x77, 0xe1,
4473 0xc7, 0xff, 0xa6, 0xfa, 0xdd, 0x70, 0xf4, 0xe3,
4474 0x93, 0xe9, 0x77, 0x35, 0x3d, 0x4b, 0x2f, 0x2b,
4475 0x6d, 0x55, 0xf0, 0xfc, 0x88, 0x54, 0x4e, 0x89,
4476 0xc1, 0x8a, 0x23, 0x31, 0x2d, 0x14, 0x2a, 0xb8,
4477 0x1b, 0x15, 0xdd, 0x9e, 0x6e, 0x7b, 0xda, 0x05,
4478 0x91, 0x7d, 0x62, 0x64, 0x96, 0x72, 0xde, 0xfc,
4479 0xc1, 0xec, 0xf0, 0x23, 0x51, 0x6f, 0xdb, 0x5b,
4480 0x1d, 0x08, 0x57, 0xce, 0x09, 0xb8, 0xf6, 0xcd,
4481 0x8d, 0x95, 0xf2, 0x20, 0xbf, 0x0f, 0x20, 0x57,
4482 0x98, 0x81, 0x84, 0x4f, 0x15, 0x5c, 0x76, 0xe7,
4483 0x3e, 0x0a, 0x3a, 0x6c, 0xc4, 0x8a, 0xbe, 0x78,
4484 0x74, 0x77, 0xc3, 0x09, 0x4b, 0x5d, 0x48, 0xe4,
4485 0xc8, 0xcb, 0x0b, 0xea, 0x17, 0x28, 0xcf, 0xcf,
4486 0x31, 0x32, 0x44, 0xa4, 0xe5, 0x0e, 0x1a, 0x98,
4487 0x94, 0xc4, 0xf0, 0xff, 0xae, 0x3e, 0x44, 0xe8,
4488 0xa5, 0xb3, 0xb5, 0x37, 0x2f, 0xe8, 0xaf, 0x6f,
4489 0x28, 0xc1, 0x37, 0x5f, 0x31, 0xd2, 0xb9, 0x33,
4490 0xb1, 0xb2, 0x52, 0x94, 0x75, 0x2c, 0x29, 0x59,
4491 0x06, 0xc2, 0x25, 0xe8, 0x71, 0x65, 0x4e, 0xed,
4492 0xc0, 0x9c, 0xb1, 0xbb, 0x25, 0xdc, 0x6c, 0xe7,
4493 0x4b, 0xa5, 0x7a, 0x54, 0x7a, 0x60, 0xff, 0x7a,
4494 0xe0, 0x50, 0x40, 0x96, 0x35, 0x63, 0xe4, 0x0b,
4495 0x76, 0xbd, 0xa4, 0x65, 0x00, 0x1b, 0x57, 0x88,
4496 0xae, 0xed, 0x39, 0x88, 0x42, 0x11, 0x3c, 0xed,
4497 0x85, 0x67, 0x7d, 0xb9, 0x68, 0x82, 0xe9, 0x43,
4498 0x3c, 0x47, 0x53, 0xfa, 0xe8, 0xf8, 0x9f, 0x1f,
4499 0x9f, 0xef, 0x0f, 0xf7, 0x30, 0xd9, 0x30, 0x0e,
4500 0xb9, 0x9f, 0x69, 0x18, 0x2f, 0x7e, 0xf8, 0xf8,
4501 0xf8, 0x8c, 0x0f, 0xd4, 0x02, 0x4d, 0xea, 0xcd,
4502 0x0a, 0x9c, 0x6f, 0x71, 0x6d, 0x5a, 0x4c, 0x60,
4503 0xce, 0x20, 0x56, 0x32, 0xc6, 0xc5, 0x99, 0x1f,
4504 0x09, 0xe6, 0x4e, 0x18, 0x1a, 0x15, 0x13, 0xa8,
4505 0x7d, 0xb1, 0x6b, 0xc0, 0xb2, 0x6d, 0xf8, 0x26,
4506 0x66, 0xf8, 0x3d, 0x18, 0x74, 0x70, 0x66, 0x7a,
4507 0x34, 0x17, 0xde, 0xba, 0x47, 0xf1, 0x06, 0x18,
4508 0xcb, 0xaf, 0xeb, 0x4a, 0x1e, 0x8f, 0xa7, 0x77,
4509 0xe0, 0x3b, 0x78, 0x62, 0x66, 0xc9, 0x10, 0xea,
4510 0x1f, 0xb7, 0x29, 0x0a, 0x45, 0xa1, 0x1d, 0x1e,
4511 0x1d, 0xe2, 0x65, 0x61, 0x50, 0x9c, 0xd7, 0x05,
4512 0xf2, 0x0b, 0x5b, 0x12, 0x61, 0x02, 0xc8, 0xe5,
4513 0x63, 0x4f, 0x20, 0x0c, 0x07, 0x17, 0x33, 0x5e,
4514 0x03, 0x9a, 0x53, 0x0f, 0x2e, 0x55, 0xfe, 0x50,
4515 0x43, 0x7d, 0xd0, 0xb6, 0x7e, 0x5a, 0xda, 0xae,
4516 0x58, 0xef, 0x15, 0xa9, 0x83, 0xd9, 0x46, 0xb1,
4517 0x42, 0xaa, 0xf5, 0x02, 0x6c, 0xce, 0x92, 0x06,
4518 0x1b, 0xdb, 0x66, 0x45, 0x91, 0x79, 0xc2, 0x2d,
4519 0xe6, 0x53, 0xd3, 0x14, 0xfd, 0xbb, 0x44, 0x63,
4520 0xc6, 0xd7, 0x3d, 0x7a, 0x0c, 0x75, 0x78, 0x9d,
4521 0x5c, 0xa6, 0x39, 0xb3, 0xe5, 0x63, 0xca, 0x8b,
4522 0xfe, 0xd3, 0xef, 0x60, 0x83, 0xf6, 0x8e, 0x70,
4523 0xb6, 0x67, 0xc7, 0x77, 0xed, 0x23, 0xef, 0x4c,
4524 0xf0, 0xed, 0x2d, 0x07, 0x59, 0x6f, 0xc1, 0x01,
4525 0x34, 0x37, 0x08, 0xab, 0xd9, 0x1f, 0x09, 0xb1,
4526 0xce, 0x5b, 0x17, 0xff, 0x74, 0xf8, 0x9c, 0xd5,
4527 0x2c, 0x56, 0x39, 0x79, 0x0f, 0x69, 0x44, 0x75,
4528 0x58, 0x27, 0x01, 0xc4, 0xbf, 0xa7, 0xa1, 0x1d,
4529 0x90, 0x17, 0x77, 0x86, 0x5a, 0x3f, 0xd9, 0xd1,
4530 0x0e, 0xa0, 0x10, 0xf8, 0xec, 0x1e, 0xa5, 0x7f,
4531 0x5e, 0x36, 0xd1, 0xe3, 0x04, 0x2c, 0x70, 0xf7,
4532 0x8e, 0xc0, 0x98, 0x2f, 0x6c, 0x94, 0x2b, 0x41,
4533 0xb7, 0x60, 0x00, 0xb7, 0x2e, 0xb8, 0x02, 0x8d,
4534 0xb8, 0xb0, 0xd3, 0x86, 0xba, 0x1d, 0xd7, 0x90,
4535 0xd6, 0xb6, 0xe1, 0xfc, 0xd7, 0xd8, 0x28, 0x06,
4536 0x63, 0x9b, 0xce, 0x61, 0x24, 0x79, 0xc0, 0x70,
4537 0x52, 0xd0, 0xb6, 0xd4, 0x28, 0x95, 0x24, 0x87,
4538 0x03, 0x1f, 0xb7, 0x9a, 0xda, 0xa3, 0xfb, 0x52,
4539 0x5b, 0x68, 0xe7, 0x4c, 0x8c, 0x24, 0xe1, 0x42,
4540 0xf7, 0xd5, 0xfd, 0xad, 0x06, 0x32, 0x9f, 0xba,
4541 0xc1, 0xfc, 0xdd, 0xc6, 0xfc, 0xfc, 0xb3, 0x38,
4542 0x74, 0x56, 0x58, 0x40, 0x02, 0x37, 0x52, 0x2c,
4543 0x55, 0xcc, 0xb3, 0x9e, 0x7a, 0xe9, 0xd4, 0x38,
4544 0x41, 0x5e, 0x0c, 0x35, 0xe2, 0x11, 0xd1, 0x13,
4545 0xf8, 0xb7, 0x8d, 0x72, 0x6b, 0x22, 0x2a, 0xb0,
4546 0xdb, 0x08, 0xba, 0x35, 0xb9, 0x3f, 0xc8, 0xd3,
4547 0x24, 0x90, 0xec, 0x58, 0xd2, 0x09, 0xc7, 0x2d,
4548 0xed, 0x38, 0x80, 0x36, 0x72, 0x43, 0x27, 0x49,
4549 0x4a, 0x80, 0x8a, 0xa2, 0xe8, 0xd3, 0xda, 0x30,
4550 0x7d, 0xb6, 0x82, 0x37, 0x86, 0x92, 0x86, 0x3e,
4551 0x08, 0xb2, 0x28, 0x5a, 0x55, 0x44, 0x24, 0x7d,
4552 0x40, 0x48, 0x8a, 0xb6, 0x89, 0x58, 0x08, 0xa0,
4553 0xd6, 0x6d, 0x3a, 0x17, 0xbf, 0xf6, 0x54, 0xa2,
4554 0xf5, 0xd3, 0x8c, 0x0f, 0x78, 0x12, 0x57, 0x8b,
4555 0xd5, 0xc2, 0xfd, 0x58, 0x5b, 0x7f, 0x38, 0xe3,
4556 0xcc, 0xb7, 0x7c, 0x48, 0xb3, 0x20, 0xe8, 0x81,
4557 0x14, 0x32, 0x45, 0x05, 0xe0, 0xdb, 0x9f, 0x75,
4558 0x85, 0xb4, 0x6a, 0xfc, 0x95, 0xe3, 0x54, 0x22,
4559 0x12, 0xee, 0x30, 0xfe, 0xd8, 0x30, 0xef, 0x34,
4560 0x50, 0xab, 0x46, 0x30, 0x98, 0x2f, 0xb7, 0xc0,
4561 0x15, 0xa2, 0x83, 0xb6, 0xf2, 0x06, 0x21, 0xa2,
4562 0xc3, 0x26, 0x37, 0x14, 0xd1, 0x4d, 0xb5, 0x10,
4563 0x52, 0x76, 0x4d, 0x6a, 0xee, 0xb5, 0x2b, 0x15,
4564 0xb7, 0xf9, 0x51, 0xe8, 0x2a, 0xaf, 0xc7, 0xfa,
4565 0x77, 0xaf, 0xb0, 0x05, 0x4d, 0xd1, 0x68, 0x8e,
4566 0x74, 0x05, 0x9f, 0x9d, 0x93, 0xa5, 0x3e, 0x7f,
4567 0x4e, 0x5f, 0x9d, 0xcb, 0x09, 0xc7, 0x83, 0xe3,
4568 0x02, 0x9d, 0x27, 0x1f, 0xef, 0x85, 0x05, 0x8d,
4569 0xec, 0x55, 0x88, 0x0f, 0x0d, 0x7c, 0x4c, 0xe8,
4570 0xa1, 0x75, 0xa0, 0xd8, 0x06, 0x47, 0x14, 0xef,
4571 0xaa, 0x61, 0xcf, 0x26, 0x15, 0xad, 0xd8, 0xa3,
4572 0xaa, 0x75, 0xf2, 0x78, 0x4a, 0x5a, 0x61, 0xdf,
4573 0x8b, 0xc7, 0x04, 0xbc, 0xb2, 0x32, 0xd2, 0x7e,
4574 0x42, 0xee, 0xb4, 0x2f, 0x51, 0xff, 0x7b, 0x2e,
4575 0xd3, 0x02, 0xe8, 0xdc, 0x5d, 0x0d, 0x50, 0xdc,
4576 0xae, 0xb7, 0x46, 0xf9, 0xa8, 0xe6, 0xd0, 0x16,
4577 0xcc, 0xe6, 0x2c, 0x81, 0xc7, 0xad, 0xe9, 0xf0,
4578 0x05, 0x72, 0x6d, 0x3d, 0x0a, 0x7a, 0xa9, 0x02,
4579 0xac, 0x82, 0x93, 0x6e, 0xb6, 0x1c, 0x28, 0xfc,
4580 0x44, 0x12, 0xfb, 0x73, 0x77, 0xd4, 0x13, 0x39,
4581 0x29, 0x88, 0x8a, 0xf3, 0x5c, 0xa6, 0x36, 0xa0,
4582 0x2a, 0xed, 0x7e, 0xb1, 0x1d, 0xd6, 0x4c, 0x6b,
4583 0x41, 0x01, 0x18, 0x5d, 0x5d, 0x07, 0x97, 0xa6,
4584 0x4b, 0xef, 0x31, 0x18, 0xea, 0xac, 0xb1, 0x84,
4585 0x21, 0xed, 0xda, 0x86,
4586 },
4587 .rlen = 4100,
4588 },
4589};
4590
4591static struct cipher_testvec aes_ctr_dec_tv_template[] = {
4592 { /* From RFC 3686 */
4593 .key = { 0xae, 0x68, 0x52, 0xf8, 0x12, 0x10, 0x67, 0xcc,
4594 0x4b, 0xf7, 0xa5, 0x76, 0x55, 0x77, 0xf3, 0x9e,
4595 0x00, 0x00, 0x00, 0x30 },
4596 .klen = 20,
4597 .iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
4598 .input = { 0xe4, 0x09, 0x5d, 0x4f, 0xb7, 0xa7, 0xb3, 0x79,
4599 0x2d, 0x61, 0x75, 0xa3, 0x26, 0x13, 0x11, 0xb8 },
4600 .ilen = 16,
4601 .result = { "Single block msg" },
4602 .rlen = 16,
4603 }, {
4604 .key = { 0x7e, 0x24, 0x06, 0x78, 0x17, 0xfa, 0xe0, 0xd7,
4605 0x43, 0xd6, 0xce, 0x1f, 0x32, 0x53, 0x91, 0x63,
4606 0x00, 0x6c, 0xb6, 0xdb },
4607 .klen = 20,
4608 .iv = { 0xc0, 0x54, 0x3b, 0x59, 0xda, 0x48, 0xd9, 0x0b },
4609 .input = { 0x51, 0x04, 0xa1, 0x06, 0x16, 0x8a, 0x72, 0xd9,
4610 0x79, 0x0d, 0x41, 0xee, 0x8e, 0xda, 0xd3, 0x88,
4611 0xeb, 0x2e, 0x1e, 0xfc, 0x46, 0xda, 0x57, 0xc8,
4612 0xfc, 0xe6, 0x30, 0xdf, 0x91, 0x41, 0xbe, 0x28 },
4613 .ilen = 32,
4614 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4615 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4616 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4617 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
4618 .rlen = 32,
4619 }, {
4620 .key = { 0x16, 0xaf, 0x5b, 0x14, 0x5f, 0xc9, 0xf5, 0x79,
4621 0xc1, 0x75, 0xf9, 0x3e, 0x3b, 0xfb, 0x0e, 0xed,
4622 0x86, 0x3d, 0x06, 0xcc, 0xfd, 0xb7, 0x85, 0x15,
4623 0x00, 0x00, 0x00, 0x48 },
4624 .klen = 28,
4625 .iv = { 0x36, 0x73, 0x3c, 0x14, 0x7d, 0x6d, 0x93, 0xcb },
4626 .input = { 0x4b, 0x55, 0x38, 0x4f, 0xe2, 0x59, 0xc9, 0xc8,
4627 0x4e, 0x79, 0x35, 0xa0, 0x03, 0xcb, 0xe9, 0x28 },
4628 .ilen = 16,
4629 .result = { "Single block msg" },
4630 .rlen = 16,
4631 }, {
4632 .key = { 0x7c, 0x5c, 0xb2, 0x40, 0x1b, 0x3d, 0xc3, 0x3c,
4633 0x19, 0xe7, 0x34, 0x08, 0x19, 0xe0, 0xf6, 0x9c,
4634 0x67, 0x8c, 0x3d, 0xb8, 0xe6, 0xf6, 0xa9, 0x1a,
4635 0x00, 0x96, 0xb0, 0x3b },
4636 .klen = 28,
4637 .iv = { 0x02, 0x0c, 0x6e, 0xad, 0xc2, 0xcb, 0x50, 0x0d },
4638 .input = { 0x45, 0x32, 0x43, 0xfc, 0x60, 0x9b, 0x23, 0x32,
4639 0x7e, 0xdf, 0xaa, 0xfa, 0x71, 0x31, 0xcd, 0x9f,
4640 0x84, 0x90, 0x70, 0x1c, 0x5a, 0xd4, 0xa7, 0x9c,
4641 0xfc, 0x1f, 0xe0, 0xff, 0x42, 0xf4, 0xfb, 0x00 },
4642 .ilen = 32,
4643 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4644 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4645 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4646 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
4647 .rlen = 32,
4648 }, {
4649 .key = { 0x77, 0x6b, 0xef, 0xf2, 0x85, 0x1d, 0xb0, 0x6f,
4650 0x4c, 0x8a, 0x05, 0x42, 0xc8, 0x69, 0x6f, 0x6c,
4651 0x6a, 0x81, 0xaf, 0x1e, 0xec, 0x96, 0xb4, 0xd3,
4652 0x7f, 0xc1, 0xd6, 0x89, 0xe6, 0xc1, 0xc1, 0x04,
4653 0x00, 0x00, 0x00, 0x60 },
4654 .klen = 36,
4655 .iv = { 0xdb, 0x56, 0x72, 0xc9, 0x7a, 0xa8, 0xf0, 0xb2 },
4656 .input = { 0x14, 0x5a, 0xd0, 0x1d, 0xbf, 0x82, 0x4e, 0xc7,
4657 0x56, 0x08, 0x63, 0xdc, 0x71, 0xe3, 0xe0, 0xc0 },
4658 .ilen = 16,
4659 .result = { "Single block msg" },
4660 .rlen = 16,
4661 }, {
4662 .key = { 0xf6, 0xd6, 0x6d, 0x6b, 0xd5, 0x2d, 0x59, 0xbb,
4663 0x07, 0x96, 0x36, 0x58, 0x79, 0xef, 0xf8, 0x86,
4664 0xc6, 0x6d, 0xd5, 0x1a, 0x5b, 0x6a, 0x99, 0x74,
4665 0x4b, 0x50, 0x59, 0x0c, 0x87, 0xa2, 0x38, 0x84,
4666 0x00, 0xfa, 0xac, 0x24 },
4667 .klen = 36,
4668 .iv = { 0xc1, 0x58, 0x5e, 0xf1, 0x5a, 0x43, 0xd8, 0x75 },
4669 .input = { 0xf0, 0x5e, 0x23, 0x1b, 0x38, 0x94, 0x61, 0x2c,
4670 0x49, 0xee, 0x00, 0x0b, 0x80, 0x4e, 0xb2, 0xa9,
4671 0xb8, 0x30, 0x6b, 0x50, 0x8f, 0x83, 0x9d, 0x6a,
4672 0x55, 0x30, 0x83, 0x1d, 0x93, 0x44, 0xaf, 0x1c },
4673 .ilen = 32,
4674 .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
4675 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
4676 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
4677 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
4678 .rlen = 32,
4679 },
4680};
4681
4682static struct aead_testvec aes_gcm_enc_tv_template[] = {
4683 { /* From McGrew & Viega - http://citeseer.ist.psu.edu/656989.html */
4684 .klen = 16,
4685 .result = { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
4686 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a },
4687 .rlen = 16,
4688 }, {
4689 .klen = 16,
4690 .ilen = 16,
4691 .result = { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92,
4692 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78,
4693 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd,
4694 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf },
4695 .rlen = 32,
4696 }, {
4697 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4698 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4699 .klen = 16,
4700 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4701 0xde, 0xca, 0xf8, 0x88 },
4702 .input = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4703 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4704 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4705 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4706 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4707 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4708 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4709 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
4710 .ilen = 64,
4711 .result = { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
4712 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
4713 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
4714 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
4715 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
4716 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
4717 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
4718 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85,
4719 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
4720 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 },
4721 .rlen = 80,
4722 }, {
4723 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4724 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4725 .klen = 16,
4726 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4727 0xde, 0xca, 0xf8, 0x88 },
4728 .input = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4729 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4730 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4731 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4732 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4733 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4734 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4735 0xba, 0x63, 0x7b, 0x39 },
4736 .ilen = 60,
4737 .assoc = { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4738 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4739 0xab, 0xad, 0xda, 0xd2 },
4740 .alen = 20,
4741 .result = { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
4742 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
4743 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
4744 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
4745 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
4746 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
4747 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
4748 0x3d, 0x58, 0xe0, 0x91,
4749 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
4750 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 },
4751 .rlen = 76,
4752 }, {
4753 .klen = 24,
4754 .result = { 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b,
4755 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 },
4756 .rlen = 16,
4757 }, {
4758 .klen = 24,
4759 .ilen = 16,
4760 .result = { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
4761 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00,
4762 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
4763 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb },
4764 .rlen = 32,
4765 }, {
4766 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4767 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
4768 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c },
4769 .klen = 24,
4770 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4771 0xde, 0xca, 0xf8, 0x88 },
4772 .input = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4773 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4774 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4775 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4776 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4777 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4778 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4779 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
4780 .ilen = 64,
4781 .result = { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
4782 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
4783 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
4784 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
4785 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
4786 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
4787 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
4788 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56,
4789 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
4790 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 },
4791 .rlen = 80,
4792 }, {
4793 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4794 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
4795 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c },
4796 .klen = 24,
4797 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4798 0xde, 0xca, 0xf8, 0x88 },
4799 .input = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4800 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4801 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4802 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4803 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4804 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4805 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4806 0xba, 0x63, 0x7b, 0x39 },
4807 .ilen = 60,
4808 .assoc = { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4809 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4810 0xab, 0xad, 0xda, 0xd2 },
4811 .alen = 20,
4812 .result = { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
4813 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
4814 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
4815 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
4816 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
4817 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
4818 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
4819 0xcc, 0xda, 0x27, 0x10,
4820 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
4821 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c },
4822 .rlen = 76,
4823 .np = 2,
4824 .tap = { 32, 28 },
4825 .anp = 2,
4826 .atap = { 8, 12 }
4827 }, {
4828 .klen = 32,
4829 .result = { 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
4830 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b },
4831 .rlen = 16,
4832 }
4833};
4834
4835static struct aead_testvec aes_gcm_dec_tv_template[] = {
4836 { /* From McGrew & Viega - http://citeseer.ist.psu.edu/656989.html */
4837 .klen = 32,
4838 .input = { 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e,
4839 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18,
4840 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0,
4841 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 },
4842 .ilen = 32,
4843 .rlen = 16,
4844 }, {
4845 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4846 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
4847 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4848 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4849 .klen = 32,
4850 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4851 0xde, 0xca, 0xf8, 0x88 },
4852 .input = { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
4853 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
4854 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
4855 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
4856 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
4857 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
4858 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
4859 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad,
4860 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd,
4861 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c },
4862 .ilen = 80,
4863 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4864 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4865 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4866 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4867 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4868 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4869 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4870 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
4871 .rlen = 64,
4872 }, {
4873 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4874 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
4875 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4876 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4877 .klen = 32,
4878 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4879 0xde, 0xca, 0xf8, 0x88 },
4880 .input = { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
4881 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
4882 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
4883 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
4884 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
4885 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
4886 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
4887 0xbc, 0xc9, 0xf6, 0x62,
4888 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
4889 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b },
4890 .ilen = 76,
4891 .assoc = { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4892 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4893 0xab, 0xad, 0xda, 0xd2 },
4894 .alen = 20,
4895 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4896 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4897 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4898 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4899 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4900 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4901 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4902 0xba, 0x63, 0x7b, 0x39 },
4903 .rlen = 60,
4904 .np = 2,
4905 .tap = { 48, 28 },
4906 .anp = 3,
4907 .atap = { 8, 8, 4 }
4908 }, {
4909 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4910 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4911 .klen = 16,
4912 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4913 0xde, 0xca, 0xf8, 0x88 },
4914 .input = { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
4915 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
4916 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
4917 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
4918 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
4919 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
4920 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
4921 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85,
4922 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
4923 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 },
4924 .ilen = 80,
4925 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4926 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4927 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4928 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4929 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4930 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4931 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4932 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
4933 .rlen = 64,
4934 }, {
4935 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4936 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 },
4937 .klen = 16,
4938 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4939 0xde, 0xca, 0xf8, 0x88 },
4940 .input = { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
4941 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
4942 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
4943 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
4944 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
4945 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
4946 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
4947 0x3d, 0x58, 0xe0, 0x91,
4948 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
4949 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 },
4950 .ilen = 76,
4951 .assoc = { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4952 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
4953 0xab, 0xad, 0xda, 0xd2 },
4954 .alen = 20,
4955 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4956 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4957 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4958 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4959 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4960 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4961 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4962 0xba, 0x63, 0x7b, 0x39 },
4963 .rlen = 60,
4964 }, {
4965 .klen = 24,
4966 .input = { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41,
4967 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00,
4968 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab,
4969 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb },
4970 .ilen = 32,
4971 .rlen = 16,
4972 }, {
4973 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
4974 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
4975 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c },
4976 .klen = 24,
4977 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
4978 0xde, 0xca, 0xf8, 0x88 },
4979 .input = { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
4980 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
4981 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
4982 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
4983 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
4984 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
4985 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
4986 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56,
4987 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf,
4988 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 },
4989 .ilen = 80,
4990 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
4991 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
4992 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
4993 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
4994 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
4995 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
4996 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
4997 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 },
4998 .rlen = 64,
4999 }, {
5000 .key = { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
5001 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
5002 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c },
5003 .klen = 24,
5004 .iv = { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
5005 0xde, 0xca, 0xf8, 0x88 },
5006 .input = { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41,
5007 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57,
5008 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84,
5009 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c,
5010 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25,
5011 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47,
5012 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9,
5013 0xcc, 0xda, 0x27, 0x10,
5014 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f,
5015 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c },
5016 .ilen = 76,
5017 .assoc = { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
5018 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
5019 0xab, 0xad, 0xda, 0xd2 },
5020 .alen = 20,
5021 .result = { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
5022 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
5023 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
5024 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
5025 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
5026 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
5027 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
5028 0xba, 0x63, 0x7b, 0x39 },
5029 .rlen = 60,
5030 }
5031};
5032
5033static struct aead_testvec aes_ccm_enc_tv_template[] = {
5034 { /* From RFC 3610 */
5035 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5036 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5037 .klen = 16,
5038 .iv = { 0x01, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
5039 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5040 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
5041 .alen = 8,
5042 .input = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5043 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5044 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e },
5045 .ilen = 23,
5046 .result = { 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
5047 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
5048 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0x17,
5049 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 },
5050 .rlen = 31,
5051 }, {
5052 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5053 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5054 .klen = 16,
5055 .iv = { 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04,
5056 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5057 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5058 0x08, 0x09, 0x0a, 0x0b },
5059 .alen = 12,
5060 .input = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
5061 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
5062 0x1c, 0x1d, 0x1e, 0x1f },
5063 .ilen = 20,
5064 .result = { 0xdc, 0xf1, 0xfb, 0x7b, 0x5d, 0x9e, 0x23, 0xfb,
5065 0x9d, 0x4e, 0x13, 0x12, 0x53, 0x65, 0x8a, 0xd8,
5066 0x6e, 0xbd, 0xca, 0x3e, 0x51, 0xe8, 0x3f, 0x07,
5067 0x7d, 0x9c, 0x2d, 0x93 },
5068 .rlen = 28,
5069 }, {
5070 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5071 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5072 .klen = 16,
5073 .iv = { 0x01, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x09, 0x08,
5074 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5075 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
5076 .alen = 8,
5077 .input = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5078 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5079 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
5080 0x20 },
5081 .ilen = 25,
5082 .result = { 0x82, 0x53, 0x1a, 0x60, 0xcc, 0x24, 0x94, 0x5a,
5083 0x4b, 0x82, 0x79, 0x18, 0x1a, 0xb5, 0xc8, 0x4d,
5084 0xf2, 0x1c, 0xe7, 0xf9, 0xb7, 0x3f, 0x42, 0xe1,
5085 0x97, 0xea, 0x9c, 0x07, 0xe5, 0x6b, 0x5e, 0xb1,
5086 0x7e, 0x5f, 0x4e },
5087 .rlen = 35,
5088 }, {
5089 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5090 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5091 .klen = 16,
5092 .iv = { 0x01, 0x00, 0x00, 0x00, 0x0c, 0x0b, 0x0a, 0x09,
5093 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5094 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5095 0x08, 0x09, 0x0a, 0x0b },
5096 .alen = 12,
5097 .input = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
5098 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
5099 0x1c, 0x1d, 0x1e },
5100 .ilen = 19,
5101 .result = { 0x07, 0x34, 0x25, 0x94, 0x15, 0x77, 0x85, 0x15,
5102 0x2b, 0x07, 0x40, 0x98, 0x33, 0x0a, 0xbb, 0x14,
5103 0x1b, 0x94, 0x7b, 0x56, 0x6a, 0xa9, 0x40, 0x6b,
5104 0x4d, 0x99, 0x99, 0x88, 0xdd },
5105 .rlen = 29,
5106 }, {
5107 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5108 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5109 .klen = 16,
5110 .iv = { 0x01, 0x00, 0x33, 0x56, 0x8e, 0xf7, 0xb2, 0x63,
5111 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5112 .assoc = { 0x63, 0x01, 0x8f, 0x76, 0xdc, 0x8a, 0x1b, 0xcb },
5113 .alen = 8,
5114 .input = { 0x90, 0x20, 0xea, 0x6f, 0x91, 0xbd, 0xd8, 0x5a,
5115 0xfa, 0x00, 0x39, 0xba, 0x4b, 0xaf, 0xf9, 0xbf,
5116 0xb7, 0x9c, 0x70, 0x28, 0x94, 0x9c, 0xd0, 0xec },
5117 .ilen = 24,
5118 .result = { 0x4c, 0xcb, 0x1e, 0x7c, 0xa9, 0x81, 0xbe, 0xfa,
5119 0xa0, 0x72, 0x6c, 0x55, 0xd3, 0x78, 0x06, 0x12,
5120 0x98, 0xc8, 0x5c, 0x92, 0x81, 0x4a, 0xbc, 0x33,
5121 0xc5, 0x2e, 0xe8, 0x1d, 0x7d, 0x77, 0xc0, 0x8a },
5122 .rlen = 32,
5123 }, {
5124 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5125 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5126 .klen = 16,
5127 .iv = { 0x01, 0x00, 0xd5, 0x60, 0x91, 0x2d, 0x3f, 0x70,
5128 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5129 .assoc = { 0xcd, 0x90, 0x44, 0xd2, 0xb7, 0x1f, 0xdb, 0x81,
5130 0x20, 0xea, 0x60, 0xc0 },
5131 .alen = 12,
5132 .input = { 0x64, 0x35, 0xac, 0xba, 0xfb, 0x11, 0xa8, 0x2e,
5133 0x2f, 0x07, 0x1d, 0x7c, 0xa4, 0xa5, 0xeb, 0xd9,
5134 0x3a, 0x80, 0x3b, 0xa8, 0x7f },
5135 .ilen = 21,
5136 .result = { 0x00, 0x97, 0x69, 0xec, 0xab, 0xdf, 0x48, 0x62,
5137 0x55, 0x94, 0xc5, 0x92, 0x51, 0xe6, 0x03, 0x57,
5138 0x22, 0x67, 0x5e, 0x04, 0xc8, 0x47, 0x09, 0x9e,
5139 0x5a, 0xe0, 0x70, 0x45, 0x51 },
5140 .rlen = 29,
5141 }, {
5142 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5143 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5144 .klen = 16,
5145 .iv = { 0x01, 0x00, 0x42, 0xff, 0xf8, 0xf1, 0x95, 0x1c,
5146 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5147 .assoc = { 0xd8, 0x5b, 0xc7, 0xe6, 0x9f, 0x94, 0x4f, 0xb8 },
5148 .alen = 8,
5149 .input = { 0x8a, 0x19, 0xb9, 0x50, 0xbc, 0xf7, 0x1a, 0x01,
5150 0x8e, 0x5e, 0x67, 0x01, 0xc9, 0x17, 0x87, 0x65,
5151 0x98, 0x09, 0xd6, 0x7d, 0xbe, 0xdd, 0x18 },
5152 .ilen = 23,
5153 .result = { 0xbc, 0x21, 0x8d, 0xaa, 0x94, 0x74, 0x27, 0xb6,
5154 0xdb, 0x38, 0x6a, 0x99, 0xac, 0x1a, 0xef, 0x23,
5155 0xad, 0xe0, 0xb5, 0x29, 0x39, 0xcb, 0x6a, 0x63,
5156 0x7c, 0xf9, 0xbe, 0xc2, 0x40, 0x88, 0x97, 0xc6,
5157 0xba },
5158 .rlen = 33,
5159 },
5160};
5161
5162static struct aead_testvec aes_ccm_dec_tv_template[] = {
5163 { /* From RFC 3610 */
5164 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5165 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5166 .klen = 16,
5167 .iv = { 0x01, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00,
5168 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5169 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
5170 .alen = 8,
5171 .input = { 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
5172 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
5173 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0x17,
5174 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 },
5175 .ilen = 31,
5176 .result = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5177 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5178 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e },
5179 .rlen = 23,
5180 }, {
5181 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5182 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5183 .klen = 16,
5184 .iv = { 0x01, 0x00, 0x00, 0x00, 0x07, 0x06, 0x05, 0x04,
5185 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5186 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5187 0x08, 0x09, 0x0a, 0x0b },
5188 .alen = 12,
5189 .input = { 0xdc, 0xf1, 0xfb, 0x7b, 0x5d, 0x9e, 0x23, 0xfb,
5190 0x9d, 0x4e, 0x13, 0x12, 0x53, 0x65, 0x8a, 0xd8,
5191 0x6e, 0xbd, 0xca, 0x3e, 0x51, 0xe8, 0x3f, 0x07,
5192 0x7d, 0x9c, 0x2d, 0x93 },
5193 .ilen = 28,
5194 .result = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
5195 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
5196 0x1c, 0x1d, 0x1e, 0x1f },
5197 .rlen = 20,
5198 }, {
5199 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5200 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5201 .klen = 16,
5202 .iv = { 0x01, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x09, 0x08,
5203 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5204 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
5205 .alen = 8,
5206 .input = { 0x82, 0x53, 0x1a, 0x60, 0xcc, 0x24, 0x94, 0x5a,
5207 0x4b, 0x82, 0x79, 0x18, 0x1a, 0xb5, 0xc8, 0x4d,
5208 0xf2, 0x1c, 0xe7, 0xf9, 0xb7, 0x3f, 0x42, 0xe1,
5209 0x97, 0xea, 0x9c, 0x07, 0xe5, 0x6b, 0x5e, 0xb1,
5210 0x7e, 0x5f, 0x4e },
5211 .ilen = 35,
5212 .result = { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5213 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
5214 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
5215 0x20 },
5216 .rlen = 25,
5217 }, {
5218 .key = { 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
5219 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf },
5220 .klen = 16,
5221 .iv = { 0x01, 0x00, 0x00, 0x00, 0x0c, 0x0b, 0x0a, 0x09,
5222 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x00 },
5223 .assoc = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5224 0x08, 0x09, 0x0a, 0x0b },
5225 .alen = 12,
5226 .input = { 0x07, 0x34, 0x25, 0x94, 0x15, 0x77, 0x85, 0x15,
5227 0x2b, 0x07, 0x40, 0x98, 0x33, 0x0a, 0xbb, 0x14,
5228 0x1b, 0x94, 0x7b, 0x56, 0x6a, 0xa9, 0x40, 0x6b,
5229 0x4d, 0x99, 0x99, 0x88, 0xdd },
5230 .ilen = 29,
5231 .result = { 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
5232 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
5233 0x1c, 0x1d, 0x1e },
5234 .rlen = 19,
5235 }, {
5236 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5237 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5238 .klen = 16,
5239 .iv = { 0x01, 0x00, 0x33, 0x56, 0x8e, 0xf7, 0xb2, 0x63,
5240 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5241 .assoc = { 0x63, 0x01, 0x8f, 0x76, 0xdc, 0x8a, 0x1b, 0xcb },
5242 .alen = 8,
5243 .input = { 0x4c, 0xcb, 0x1e, 0x7c, 0xa9, 0x81, 0xbe, 0xfa,
5244 0xa0, 0x72, 0x6c, 0x55, 0xd3, 0x78, 0x06, 0x12,
5245 0x98, 0xc8, 0x5c, 0x92, 0x81, 0x4a, 0xbc, 0x33,
5246 0xc5, 0x2e, 0xe8, 0x1d, 0x7d, 0x77, 0xc0, 0x8a },
5247 .ilen = 32,
5248 .result = { 0x90, 0x20, 0xea, 0x6f, 0x91, 0xbd, 0xd8, 0x5a,
5249 0xfa, 0x00, 0x39, 0xba, 0x4b, 0xaf, 0xf9, 0xbf,
5250 0xb7, 0x9c, 0x70, 0x28, 0x94, 0x9c, 0xd0, 0xec },
5251 .rlen = 24,
5252 }, {
5253 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5254 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5255 .klen = 16,
5256 .iv = { 0x01, 0x00, 0xd5, 0x60, 0x91, 0x2d, 0x3f, 0x70,
5257 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5258 .assoc = { 0xcd, 0x90, 0x44, 0xd2, 0xb7, 0x1f, 0xdb, 0x81,
5259 0x20, 0xea, 0x60, 0xc0 },
5260 .alen = 12,
5261 .input = { 0x00, 0x97, 0x69, 0xec, 0xab, 0xdf, 0x48, 0x62,
5262 0x55, 0x94, 0xc5, 0x92, 0x51, 0xe6, 0x03, 0x57,
5263 0x22, 0x67, 0x5e, 0x04, 0xc8, 0x47, 0x09, 0x9e,
5264 0x5a, 0xe0, 0x70, 0x45, 0x51 },
5265 .ilen = 29,
5266 .result = { 0x64, 0x35, 0xac, 0xba, 0xfb, 0x11, 0xa8, 0x2e,
5267 0x2f, 0x07, 0x1d, 0x7c, 0xa4, 0xa5, 0xeb, 0xd9,
5268 0x3a, 0x80, 0x3b, 0xa8, 0x7f },
5269 .rlen = 21,
5270 }, {
5271 .key = { 0xd7, 0x82, 0x8d, 0x13, 0xb2, 0xb0, 0xbd, 0xc3,
5272 0x25, 0xa7, 0x62, 0x36, 0xdf, 0x93, 0xcc, 0x6b },
5273 .klen = 16,
5274 .iv = { 0x01, 0x00, 0x42, 0xff, 0xf8, 0xf1, 0x95, 0x1c,
5275 0x3c, 0x96, 0x96, 0x76, 0x6c, 0xfa, 0x00, 0x00 },
5276 .assoc = { 0xd8, 0x5b, 0xc7, 0xe6, 0x9f, 0x94, 0x4f, 0xb8 },
5277 .alen = 8,
5278 .input = { 0xbc, 0x21, 0x8d, 0xaa, 0x94, 0x74, 0x27, 0xb6,
5279 0xdb, 0x38, 0x6a, 0x99, 0xac, 0x1a, 0xef, 0x23,
5280 0xad, 0xe0, 0xb5, 0x29, 0x39, 0xcb, 0x6a, 0x63,
5281 0x7c, 0xf9, 0xbe, 0xc2, 0x40, 0x88, 0x97, 0xc6,
5282 0xba },
5283 .ilen = 33,
5284 .result = { 0x8a, 0x19, 0xb9, 0x50, 0xbc, 0xf7, 0x1a, 0x01,
5285 0x8e, 0x5e, 0x67, 0x01, 0xc9, 0x17, 0x87, 0x65,
5286 0x98, 0x09, 0xd6, 0x7d, 0xbe, 0xdd, 0x18 },
5287 .rlen = 23,
5288 },
5289};
5290
3183/* Cast5 test vectors from RFC 2144 */ 5291/* Cast5 test vectors from RFC 2144 */
3184#define CAST5_ENC_TEST_VECTORS 3 5292#define CAST5_ENC_TEST_VECTORS 3
3185#define CAST5_DEC_TEST_VECTORS 3 5293#define CAST5_DEC_TEST_VECTORS 3
@@ -4317,6 +6425,1211 @@ static struct cipher_testvec seed_dec_tv_template[] = {
4317 } 6425 }
4318}; 6426};
4319 6427
6428#define SALSA20_STREAM_ENC_TEST_VECTORS 5
6429static struct cipher_testvec salsa20_stream_enc_tv_template[] = {
6430 /*
6431 * Testvectors from verified.test-vectors submitted to ECRYPT.
6432 * They are truncated to size 39, 64, 111, 129 to test a variety
6433 * of input length.
6434 */
6435 { /* Set 3, vector 0 */
6436 .key = {
6437 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6438 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
6439 },
6440 .klen = 16,
6441 .iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
6442 .input = {
6443 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6444 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6445 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6446 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6447 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6448 },
6449 .ilen = 39,
6450 .result = {
6451 0x2D, 0xD5, 0xC3, 0xF7, 0xBA, 0x2B, 0x20, 0xF7,
6452 0x68, 0x02, 0x41, 0x0C, 0x68, 0x86, 0x88, 0x89,
6453 0x5A, 0xD8, 0xC1, 0xBD, 0x4E, 0xA6, 0xC9, 0xB1,
6454 0x40, 0xFB, 0x9B, 0x90, 0xE2, 0x10, 0x49, 0xBF,
6455 0x58, 0x3F, 0x52, 0x79, 0x70, 0xEB, 0xC1,
6456 },
6457 .rlen = 39,
6458 }, { /* Set 5, vector 0 */
6459 .key = {
6460 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6462 },
6463 .klen = 16,
6464 .iv = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
6465 .input = {
6466 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6467 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6468 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6469 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6470 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6471 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6472 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6473 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6474 },
6475 .ilen = 64,
6476 .result = {
6477 0xB6, 0x6C, 0x1E, 0x44, 0x46, 0xDD, 0x95, 0x57,
6478 0xE5, 0x78, 0xE2, 0x23, 0xB0, 0xB7, 0x68, 0x01,
6479 0x7B, 0x23, 0xB2, 0x67, 0xBB, 0x02, 0x34, 0xAE,
6480 0x46, 0x26, 0xBF, 0x44, 0x3F, 0x21, 0x97, 0x76,
6481 0x43, 0x6F, 0xB1, 0x9F, 0xD0, 0xE8, 0x86, 0x6F,
6482 0xCD, 0x0D, 0xE9, 0xA9, 0x53, 0x8F, 0x4A, 0x09,
6483 0xCA, 0x9A, 0xC0, 0x73, 0x2E, 0x30, 0xBC, 0xF9,
6484 0x8E, 0x4F, 0x13, 0xE4, 0xB9, 0xE2, 0x01, 0xD9,
6485 },
6486 .rlen = 64,
6487 }, { /* Set 3, vector 27 */
6488 .key = {
6489 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
6490 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
6491 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
6492 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A
6493 },
6494 .klen = 32,
6495 .iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
6496 .input = {
6497 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6498 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6499 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6500 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6501 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6502 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6503 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6504 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6505
6506 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6507 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6508 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6509 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6510 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6511 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6512 },
6513 .ilen = 111,
6514 .result = {
6515 0xAE, 0x39, 0x50, 0x8E, 0xAC, 0x9A, 0xEC, 0xE7,
6516 0xBF, 0x97, 0xBB, 0x20, 0xB9, 0xDE, 0xE4, 0x1F,
6517 0x87, 0xD9, 0x47, 0xF8, 0x28, 0x91, 0x35, 0x98,
6518 0xDB, 0x72, 0xCC, 0x23, 0x29, 0x48, 0x56, 0x5E,
6519 0x83, 0x7E, 0x0B, 0xF3, 0x7D, 0x5D, 0x38, 0x7B,
6520 0x2D, 0x71, 0x02, 0xB4, 0x3B, 0xB5, 0xD8, 0x23,
6521 0xB0, 0x4A, 0xDF, 0x3C, 0xEC, 0xB6, 0xD9, 0x3B,
6522 0x9B, 0xA7, 0x52, 0xBE, 0xC5, 0xD4, 0x50, 0x59,
6523
6524 0x15, 0x14, 0xB4, 0x0E, 0x40, 0xE6, 0x53, 0xD1,
6525 0x83, 0x9C, 0x5B, 0xA0, 0x92, 0x29, 0x6B, 0x5E,
6526 0x96, 0x5B, 0x1E, 0x2F, 0xD3, 0xAC, 0xC1, 0x92,
6527 0xB1, 0x41, 0x3F, 0x19, 0x2F, 0xC4, 0x3B, 0xC6,
6528 0x95, 0x46, 0x45, 0x54, 0xE9, 0x75, 0x03, 0x08,
6529 0x44, 0xAF, 0xE5, 0x8A, 0x81, 0x12, 0x09,
6530 },
6531 .rlen = 111,
6532
6533 }, { /* Set 5, vector 27 */
6534 .key = {
6535 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6536 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6537 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6538 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6539 },
6540 .klen = 32,
6541 .iv = { 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00 },
6542 .input = {
6543 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6544 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6545 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6546 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6547 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6548 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6549 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6550 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6551
6552 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6553 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6554 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6555 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6556 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6557 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6558 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6559 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6560
6561 0x00,
6562 },
6563 .ilen = 129,
6564 .result = {
6565 0xD2, 0xDB, 0x1A, 0x5C, 0xF1, 0xC1, 0xAC, 0xDB,
6566 0xE8, 0x1A, 0x7A, 0x43, 0x40, 0xEF, 0x53, 0x43,
6567 0x5E, 0x7F, 0x4B, 0x1A, 0x50, 0x52, 0x3F, 0x8D,
6568 0x28, 0x3D, 0xCF, 0x85, 0x1D, 0x69, 0x6E, 0x60,
6569 0xF2, 0xDE, 0x74, 0x56, 0x18, 0x1B, 0x84, 0x10,
6570 0xD4, 0x62, 0xBA, 0x60, 0x50, 0xF0, 0x61, 0xF2,
6571 0x1C, 0x78, 0x7F, 0xC1, 0x24, 0x34, 0xAF, 0x58,
6572 0xBF, 0x2C, 0x59, 0xCA, 0x90, 0x77, 0xF3, 0xB0,
6573
6574 0x5B, 0x4A, 0xDF, 0x89, 0xCE, 0x2C, 0x2F, 0xFC,
6575 0x67, 0xF0, 0xE3, 0x45, 0xE8, 0xB3, 0xB3, 0x75,
6576 0xA0, 0x95, 0x71, 0xA1, 0x29, 0x39, 0x94, 0xCA,
6577 0x45, 0x2F, 0xBD, 0xCB, 0x10, 0xB6, 0xBE, 0x9F,
6578 0x8E, 0xF9, 0xB2, 0x01, 0x0A, 0x5A, 0x0A, 0xB7,
6579 0x6B, 0x9D, 0x70, 0x8E, 0x4B, 0xD6, 0x2F, 0xCD,
6580 0x2E, 0x40, 0x48, 0x75, 0xE9, 0xE2, 0x21, 0x45,
6581 0x0B, 0xC9, 0xB6, 0xB5, 0x66, 0xBC, 0x9A, 0x59,
6582
6583 0x5A,
6584 },
6585 .rlen = 129,
6586 }, { /* large test vector generated using Crypto++ */
6587 .key = {
6588 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6589 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6590 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
6591 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
6592 },
6593 .klen = 32,
6594 .iv = {
6595 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6596 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6597 },
6598 .input = {
6599 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6600 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6601 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
6602 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
6603 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
6604 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
6605 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
6606 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
6607 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
6608 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
6609 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
6610 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
6611 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
6612 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
6613 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
6614 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
6615 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
6616 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
6617 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
6618 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
6619 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
6620 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
6621 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
6622 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
6623 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
6624 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
6625 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
6626 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
6627 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
6628 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
6629 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
6630 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
6631 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
6632 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a, 0x2d,
6633 0x30, 0x33, 0x36, 0x39, 0x3c, 0x3f, 0x42, 0x45,
6634 0x48, 0x4b, 0x4e, 0x51, 0x54, 0x57, 0x5a, 0x5d,
6635 0x60, 0x63, 0x66, 0x69, 0x6c, 0x6f, 0x72, 0x75,
6636 0x78, 0x7b, 0x7e, 0x81, 0x84, 0x87, 0x8a, 0x8d,
6637 0x90, 0x93, 0x96, 0x99, 0x9c, 0x9f, 0xa2, 0xa5,
6638 0xa8, 0xab, 0xae, 0xb1, 0xb4, 0xb7, 0xba, 0xbd,
6639 0xc0, 0xc3, 0xc6, 0xc9, 0xcc, 0xcf, 0xd2, 0xd5,
6640 0xd8, 0xdb, 0xde, 0xe1, 0xe4, 0xe7, 0xea, 0xed,
6641 0xf0, 0xf3, 0xf6, 0xf9, 0xfc, 0xff, 0x02, 0x05,
6642 0x08, 0x0b, 0x0e, 0x11, 0x14, 0x17, 0x1a, 0x1d,
6643 0x20, 0x23, 0x26, 0x29, 0x2c, 0x2f, 0x32, 0x35,
6644 0x38, 0x3b, 0x3e, 0x41, 0x44, 0x47, 0x4a, 0x4d,
6645 0x50, 0x53, 0x56, 0x59, 0x5c, 0x5f, 0x62, 0x65,
6646 0x68, 0x6b, 0x6e, 0x71, 0x74, 0x77, 0x7a, 0x7d,
6647 0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x95,
6648 0x98, 0x9b, 0x9e, 0xa1, 0xa4, 0xa7, 0xaa, 0xad,
6649 0xb0, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc2, 0xc5,
6650 0xc8, 0xcb, 0xce, 0xd1, 0xd4, 0xd7, 0xda, 0xdd,
6651 0xe0, 0xe3, 0xe6, 0xe9, 0xec, 0xef, 0xf2, 0xf5,
6652 0xf8, 0xfb, 0xfe, 0x01, 0x04, 0x07, 0x0a, 0x0d,
6653 0x10, 0x13, 0x16, 0x19, 0x1c, 0x1f, 0x22, 0x25,
6654 0x28, 0x2b, 0x2e, 0x31, 0x34, 0x37, 0x3a, 0x3d,
6655 0x40, 0x43, 0x46, 0x49, 0x4c, 0x4f, 0x52, 0x55,
6656 0x58, 0x5b, 0x5e, 0x61, 0x64, 0x67, 0x6a, 0x6d,
6657 0x70, 0x73, 0x76, 0x79, 0x7c, 0x7f, 0x82, 0x85,
6658 0x88, 0x8b, 0x8e, 0x91, 0x94, 0x97, 0x9a, 0x9d,
6659 0xa0, 0xa3, 0xa6, 0xa9, 0xac, 0xaf, 0xb2, 0xb5,
6660 0xb8, 0xbb, 0xbe, 0xc1, 0xc4, 0xc7, 0xca, 0xcd,
6661 0xd0, 0xd3, 0xd6, 0xd9, 0xdc, 0xdf, 0xe2, 0xe5,
6662 0xe8, 0xeb, 0xee, 0xf1, 0xf4, 0xf7, 0xfa, 0xfd,
6663 0x00, 0x05, 0x0a, 0x0f, 0x14, 0x19, 0x1e, 0x23,
6664 0x28, 0x2d, 0x32, 0x37, 0x3c, 0x41, 0x46, 0x4b,
6665 0x50, 0x55, 0x5a, 0x5f, 0x64, 0x69, 0x6e, 0x73,
6666 0x78, 0x7d, 0x82, 0x87, 0x8c, 0x91, 0x96, 0x9b,
6667 0xa0, 0xa5, 0xaa, 0xaf, 0xb4, 0xb9, 0xbe, 0xc3,
6668 0xc8, 0xcd, 0xd2, 0xd7, 0xdc, 0xe1, 0xe6, 0xeb,
6669 0xf0, 0xf5, 0xfa, 0xff, 0x04, 0x09, 0x0e, 0x13,
6670 0x18, 0x1d, 0x22, 0x27, 0x2c, 0x31, 0x36, 0x3b,
6671 0x40, 0x45, 0x4a, 0x4f, 0x54, 0x59, 0x5e, 0x63,
6672 0x68, 0x6d, 0x72, 0x77, 0x7c, 0x81, 0x86, 0x8b,
6673 0x90, 0x95, 0x9a, 0x9f, 0xa4, 0xa9, 0xae, 0xb3,
6674 0xb8, 0xbd, 0xc2, 0xc7, 0xcc, 0xd1, 0xd6, 0xdb,
6675 0xe0, 0xe5, 0xea, 0xef, 0xf4, 0xf9, 0xfe, 0x03,
6676 0x08, 0x0d, 0x12, 0x17, 0x1c, 0x21, 0x26, 0x2b,
6677 0x30, 0x35, 0x3a, 0x3f, 0x44, 0x49, 0x4e, 0x53,
6678 0x58, 0x5d, 0x62, 0x67, 0x6c, 0x71, 0x76, 0x7b,
6679 0x80, 0x85, 0x8a, 0x8f, 0x94, 0x99, 0x9e, 0xa3,
6680 0xa8, 0xad, 0xb2, 0xb7, 0xbc, 0xc1, 0xc6, 0xcb,
6681 0xd0, 0xd5, 0xda, 0xdf, 0xe4, 0xe9, 0xee, 0xf3,
6682 0xf8, 0xfd, 0x02, 0x07, 0x0c, 0x11, 0x16, 0x1b,
6683 0x20, 0x25, 0x2a, 0x2f, 0x34, 0x39, 0x3e, 0x43,
6684 0x48, 0x4d, 0x52, 0x57, 0x5c, 0x61, 0x66, 0x6b,
6685 0x70, 0x75, 0x7a, 0x7f, 0x84, 0x89, 0x8e, 0x93,
6686 0x98, 0x9d, 0xa2, 0xa7, 0xac, 0xb1, 0xb6, 0xbb,
6687 0xc0, 0xc5, 0xca, 0xcf, 0xd4, 0xd9, 0xde, 0xe3,
6688 0xe8, 0xed, 0xf2, 0xf7, 0xfc, 0x01, 0x06, 0x0b,
6689 0x10, 0x15, 0x1a, 0x1f, 0x24, 0x29, 0x2e, 0x33,
6690 0x38, 0x3d, 0x42, 0x47, 0x4c, 0x51, 0x56, 0x5b,
6691 0x60, 0x65, 0x6a, 0x6f, 0x74, 0x79, 0x7e, 0x83,
6692 0x88, 0x8d, 0x92, 0x97, 0x9c, 0xa1, 0xa6, 0xab,
6693 0xb0, 0xb5, 0xba, 0xbf, 0xc4, 0xc9, 0xce, 0xd3,
6694 0xd8, 0xdd, 0xe2, 0xe7, 0xec, 0xf1, 0xf6, 0xfb,
6695 0x00, 0x07, 0x0e, 0x15, 0x1c, 0x23, 0x2a, 0x31,
6696 0x38, 0x3f, 0x46, 0x4d, 0x54, 0x5b, 0x62, 0x69,
6697 0x70, 0x77, 0x7e, 0x85, 0x8c, 0x93, 0x9a, 0xa1,
6698 0xa8, 0xaf, 0xb6, 0xbd, 0xc4, 0xcb, 0xd2, 0xd9,
6699 0xe0, 0xe7, 0xee, 0xf5, 0xfc, 0x03, 0x0a, 0x11,
6700 0x18, 0x1f, 0x26, 0x2d, 0x34, 0x3b, 0x42, 0x49,
6701 0x50, 0x57, 0x5e, 0x65, 0x6c, 0x73, 0x7a, 0x81,
6702 0x88, 0x8f, 0x96, 0x9d, 0xa4, 0xab, 0xb2, 0xb9,
6703 0xc0, 0xc7, 0xce, 0xd5, 0xdc, 0xe3, 0xea, 0xf1,
6704 0xf8, 0xff, 0x06, 0x0d, 0x14, 0x1b, 0x22, 0x29,
6705 0x30, 0x37, 0x3e, 0x45, 0x4c, 0x53, 0x5a, 0x61,
6706 0x68, 0x6f, 0x76, 0x7d, 0x84, 0x8b, 0x92, 0x99,
6707 0xa0, 0xa7, 0xae, 0xb5, 0xbc, 0xc3, 0xca, 0xd1,
6708 0xd8, 0xdf, 0xe6, 0xed, 0xf4, 0xfb, 0x02, 0x09,
6709 0x10, 0x17, 0x1e, 0x25, 0x2c, 0x33, 0x3a, 0x41,
6710 0x48, 0x4f, 0x56, 0x5d, 0x64, 0x6b, 0x72, 0x79,
6711 0x80, 0x87, 0x8e, 0x95, 0x9c, 0xa3, 0xaa, 0xb1,
6712 0xb8, 0xbf, 0xc6, 0xcd, 0xd4, 0xdb, 0xe2, 0xe9,
6713 0xf0, 0xf7, 0xfe, 0x05, 0x0c, 0x13, 0x1a, 0x21,
6714 0x28, 0x2f, 0x36, 0x3d, 0x44, 0x4b, 0x52, 0x59,
6715 0x60, 0x67, 0x6e, 0x75, 0x7c, 0x83, 0x8a, 0x91,
6716 0x98, 0x9f, 0xa6, 0xad, 0xb4, 0xbb, 0xc2, 0xc9,
6717 0xd0, 0xd7, 0xde, 0xe5, 0xec, 0xf3, 0xfa, 0x01,
6718 0x08, 0x0f, 0x16, 0x1d, 0x24, 0x2b, 0x32, 0x39,
6719 0x40, 0x47, 0x4e, 0x55, 0x5c, 0x63, 0x6a, 0x71,
6720 0x78, 0x7f, 0x86, 0x8d, 0x94, 0x9b, 0xa2, 0xa9,
6721 0xb0, 0xb7, 0xbe, 0xc5, 0xcc, 0xd3, 0xda, 0xe1,
6722 0xe8, 0xef, 0xf6, 0xfd, 0x04, 0x0b, 0x12, 0x19,
6723 0x20, 0x27, 0x2e, 0x35, 0x3c, 0x43, 0x4a, 0x51,
6724 0x58, 0x5f, 0x66, 0x6d, 0x74, 0x7b, 0x82, 0x89,
6725 0x90, 0x97, 0x9e, 0xa5, 0xac, 0xb3, 0xba, 0xc1,
6726 0xc8, 0xcf, 0xd6, 0xdd, 0xe4, 0xeb, 0xf2, 0xf9,
6727 0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
6728 0x48, 0x51, 0x5a, 0x63, 0x6c, 0x75, 0x7e, 0x87,
6729 0x90, 0x99, 0xa2, 0xab, 0xb4, 0xbd, 0xc6, 0xcf,
6730 0xd8, 0xe1, 0xea, 0xf3, 0xfc, 0x05, 0x0e, 0x17,
6731 0x20, 0x29, 0x32, 0x3b, 0x44, 0x4d, 0x56, 0x5f,
6732 0x68, 0x71, 0x7a, 0x83, 0x8c, 0x95, 0x9e, 0xa7,
6733 0xb0, 0xb9, 0xc2, 0xcb, 0xd4, 0xdd, 0xe6, 0xef,
6734 0xf8, 0x01, 0x0a, 0x13, 0x1c, 0x25, 0x2e, 0x37,
6735 0x40, 0x49, 0x52, 0x5b, 0x64, 0x6d, 0x76, 0x7f,
6736 0x88, 0x91, 0x9a, 0xa3, 0xac, 0xb5, 0xbe, 0xc7,
6737 0xd0, 0xd9, 0xe2, 0xeb, 0xf4, 0xfd, 0x06, 0x0f,
6738 0x18, 0x21, 0x2a, 0x33, 0x3c, 0x45, 0x4e, 0x57,
6739 0x60, 0x69, 0x72, 0x7b, 0x84, 0x8d, 0x96, 0x9f,
6740 0xa8, 0xb1, 0xba, 0xc3, 0xcc, 0xd5, 0xde, 0xe7,
6741 0xf0, 0xf9, 0x02, 0x0b, 0x14, 0x1d, 0x26, 0x2f,
6742 0x38, 0x41, 0x4a, 0x53, 0x5c, 0x65, 0x6e, 0x77,
6743 0x80, 0x89, 0x92, 0x9b, 0xa4, 0xad, 0xb6, 0xbf,
6744 0xc8, 0xd1, 0xda, 0xe3, 0xec, 0xf5, 0xfe, 0x07,
6745 0x10, 0x19, 0x22, 0x2b, 0x34, 0x3d, 0x46, 0x4f,
6746 0x58, 0x61, 0x6a, 0x73, 0x7c, 0x85, 0x8e, 0x97,
6747 0xa0, 0xa9, 0xb2, 0xbb, 0xc4, 0xcd, 0xd6, 0xdf,
6748 0xe8, 0xf1, 0xfa, 0x03, 0x0c, 0x15, 0x1e, 0x27,
6749 0x30, 0x39, 0x42, 0x4b, 0x54, 0x5d, 0x66, 0x6f,
6750 0x78, 0x81, 0x8a, 0x93, 0x9c, 0xa5, 0xae, 0xb7,
6751 0xc0, 0xc9, 0xd2, 0xdb, 0xe4, 0xed, 0xf6, 0xff,
6752 0x08, 0x11, 0x1a, 0x23, 0x2c, 0x35, 0x3e, 0x47,
6753 0x50, 0x59, 0x62, 0x6b, 0x74, 0x7d, 0x86, 0x8f,
6754 0x98, 0xa1, 0xaa, 0xb3, 0xbc, 0xc5, 0xce, 0xd7,
6755 0xe0, 0xe9, 0xf2, 0xfb, 0x04, 0x0d, 0x16, 0x1f,
6756 0x28, 0x31, 0x3a, 0x43, 0x4c, 0x55, 0x5e, 0x67,
6757 0x70, 0x79, 0x82, 0x8b, 0x94, 0x9d, 0xa6, 0xaf,
6758 0xb8, 0xc1, 0xca, 0xd3, 0xdc, 0xe5, 0xee, 0xf7,
6759 0x00, 0x0b, 0x16, 0x21, 0x2c, 0x37, 0x42, 0x4d,
6760 0x58, 0x63, 0x6e, 0x79, 0x84, 0x8f, 0x9a, 0xa5,
6761 0xb0, 0xbb, 0xc6, 0xd1, 0xdc, 0xe7, 0xf2, 0xfd,
6762 0x08, 0x13, 0x1e, 0x29, 0x34, 0x3f, 0x4a, 0x55,
6763 0x60, 0x6b, 0x76, 0x81, 0x8c, 0x97, 0xa2, 0xad,
6764 0xb8, 0xc3, 0xce, 0xd9, 0xe4, 0xef, 0xfa, 0x05,
6765 0x10, 0x1b, 0x26, 0x31, 0x3c, 0x47, 0x52, 0x5d,
6766 0x68, 0x73, 0x7e, 0x89, 0x94, 0x9f, 0xaa, 0xb5,
6767 0xc0, 0xcb, 0xd6, 0xe1, 0xec, 0xf7, 0x02, 0x0d,
6768 0x18, 0x23, 0x2e, 0x39, 0x44, 0x4f, 0x5a, 0x65,
6769 0x70, 0x7b, 0x86, 0x91, 0x9c, 0xa7, 0xb2, 0xbd,
6770 0xc8, 0xd3, 0xde, 0xe9, 0xf4, 0xff, 0x0a, 0x15,
6771 0x20, 0x2b, 0x36, 0x41, 0x4c, 0x57, 0x62, 0x6d,
6772 0x78, 0x83, 0x8e, 0x99, 0xa4, 0xaf, 0xba, 0xc5,
6773 0xd0, 0xdb, 0xe6, 0xf1, 0xfc, 0x07, 0x12, 0x1d,
6774 0x28, 0x33, 0x3e, 0x49, 0x54, 0x5f, 0x6a, 0x75,
6775 0x80, 0x8b, 0x96, 0xa1, 0xac, 0xb7, 0xc2, 0xcd,
6776 0xd8, 0xe3, 0xee, 0xf9, 0x04, 0x0f, 0x1a, 0x25,
6777 0x30, 0x3b, 0x46, 0x51, 0x5c, 0x67, 0x72, 0x7d,
6778 0x88, 0x93, 0x9e, 0xa9, 0xb4, 0xbf, 0xca, 0xd5,
6779 0xe0, 0xeb, 0xf6, 0x01, 0x0c, 0x17, 0x22, 0x2d,
6780 0x38, 0x43, 0x4e, 0x59, 0x64, 0x6f, 0x7a, 0x85,
6781 0x90, 0x9b, 0xa6, 0xb1, 0xbc, 0xc7, 0xd2, 0xdd,
6782 0xe8, 0xf3, 0xfe, 0x09, 0x14, 0x1f, 0x2a, 0x35,
6783 0x40, 0x4b, 0x56, 0x61, 0x6c, 0x77, 0x82, 0x8d,
6784 0x98, 0xa3, 0xae, 0xb9, 0xc4, 0xcf, 0xda, 0xe5,
6785 0xf0, 0xfb, 0x06, 0x11, 0x1c, 0x27, 0x32, 0x3d,
6786 0x48, 0x53, 0x5e, 0x69, 0x74, 0x7f, 0x8a, 0x95,
6787 0xa0, 0xab, 0xb6, 0xc1, 0xcc, 0xd7, 0xe2, 0xed,
6788 0xf8, 0x03, 0x0e, 0x19, 0x24, 0x2f, 0x3a, 0x45,
6789 0x50, 0x5b, 0x66, 0x71, 0x7c, 0x87, 0x92, 0x9d,
6790 0xa8, 0xb3, 0xbe, 0xc9, 0xd4, 0xdf, 0xea, 0xf5,
6791 0x00, 0x0d, 0x1a, 0x27, 0x34, 0x41, 0x4e, 0x5b,
6792 0x68, 0x75, 0x82, 0x8f, 0x9c, 0xa9, 0xb6, 0xc3,
6793 0xd0, 0xdd, 0xea, 0xf7, 0x04, 0x11, 0x1e, 0x2b,
6794 0x38, 0x45, 0x52, 0x5f, 0x6c, 0x79, 0x86, 0x93,
6795 0xa0, 0xad, 0xba, 0xc7, 0xd4, 0xe1, 0xee, 0xfb,
6796 0x08, 0x15, 0x22, 0x2f, 0x3c, 0x49, 0x56, 0x63,
6797 0x70, 0x7d, 0x8a, 0x97, 0xa4, 0xb1, 0xbe, 0xcb,
6798 0xd8, 0xe5, 0xf2, 0xff, 0x0c, 0x19, 0x26, 0x33,
6799 0x40, 0x4d, 0x5a, 0x67, 0x74, 0x81, 0x8e, 0x9b,
6800 0xa8, 0xb5, 0xc2, 0xcf, 0xdc, 0xe9, 0xf6, 0x03,
6801 0x10, 0x1d, 0x2a, 0x37, 0x44, 0x51, 0x5e, 0x6b,
6802 0x78, 0x85, 0x92, 0x9f, 0xac, 0xb9, 0xc6, 0xd3,
6803 0xe0, 0xed, 0xfa, 0x07, 0x14, 0x21, 0x2e, 0x3b,
6804 0x48, 0x55, 0x62, 0x6f, 0x7c, 0x89, 0x96, 0xa3,
6805 0xb0, 0xbd, 0xca, 0xd7, 0xe4, 0xf1, 0xfe, 0x0b,
6806 0x18, 0x25, 0x32, 0x3f, 0x4c, 0x59, 0x66, 0x73,
6807 0x80, 0x8d, 0x9a, 0xa7, 0xb4, 0xc1, 0xce, 0xdb,
6808 0xe8, 0xf5, 0x02, 0x0f, 0x1c, 0x29, 0x36, 0x43,
6809 0x50, 0x5d, 0x6a, 0x77, 0x84, 0x91, 0x9e, 0xab,
6810 0xb8, 0xc5, 0xd2, 0xdf, 0xec, 0xf9, 0x06, 0x13,
6811 0x20, 0x2d, 0x3a, 0x47, 0x54, 0x61, 0x6e, 0x7b,
6812 0x88, 0x95, 0xa2, 0xaf, 0xbc, 0xc9, 0xd6, 0xe3,
6813 0xf0, 0xfd, 0x0a, 0x17, 0x24, 0x31, 0x3e, 0x4b,
6814 0x58, 0x65, 0x72, 0x7f, 0x8c, 0x99, 0xa6, 0xb3,
6815 0xc0, 0xcd, 0xda, 0xe7, 0xf4, 0x01, 0x0e, 0x1b,
6816 0x28, 0x35, 0x42, 0x4f, 0x5c, 0x69, 0x76, 0x83,
6817 0x90, 0x9d, 0xaa, 0xb7, 0xc4, 0xd1, 0xde, 0xeb,
6818 0xf8, 0x05, 0x12, 0x1f, 0x2c, 0x39, 0x46, 0x53,
6819 0x60, 0x6d, 0x7a, 0x87, 0x94, 0xa1, 0xae, 0xbb,
6820 0xc8, 0xd5, 0xe2, 0xef, 0xfc, 0x09, 0x16, 0x23,
6821 0x30, 0x3d, 0x4a, 0x57, 0x64, 0x71, 0x7e, 0x8b,
6822 0x98, 0xa5, 0xb2, 0xbf, 0xcc, 0xd9, 0xe6, 0xf3,
6823 0x00, 0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69,
6824 0x78, 0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1,
6825 0xf0, 0xff, 0x0e, 0x1d, 0x2c, 0x3b, 0x4a, 0x59,
6826 0x68, 0x77, 0x86, 0x95, 0xa4, 0xb3, 0xc2, 0xd1,
6827 0xe0, 0xef, 0xfe, 0x0d, 0x1c, 0x2b, 0x3a, 0x49,
6828 0x58, 0x67, 0x76, 0x85, 0x94, 0xa3, 0xb2, 0xc1,
6829 0xd0, 0xdf, 0xee, 0xfd, 0x0c, 0x1b, 0x2a, 0x39,
6830 0x48, 0x57, 0x66, 0x75, 0x84, 0x93, 0xa2, 0xb1,
6831 0xc0, 0xcf, 0xde, 0xed, 0xfc, 0x0b, 0x1a, 0x29,
6832 0x38, 0x47, 0x56, 0x65, 0x74, 0x83, 0x92, 0xa1,
6833 0xb0, 0xbf, 0xce, 0xdd, 0xec, 0xfb, 0x0a, 0x19,
6834 0x28, 0x37, 0x46, 0x55, 0x64, 0x73, 0x82, 0x91,
6835 0xa0, 0xaf, 0xbe, 0xcd, 0xdc, 0xeb, 0xfa, 0x09,
6836 0x18, 0x27, 0x36, 0x45, 0x54, 0x63, 0x72, 0x81,
6837 0x90, 0x9f, 0xae, 0xbd, 0xcc, 0xdb, 0xea, 0xf9,
6838 0x08, 0x17, 0x26, 0x35, 0x44, 0x53, 0x62, 0x71,
6839 0x80, 0x8f, 0x9e, 0xad, 0xbc, 0xcb, 0xda, 0xe9,
6840 0xf8, 0x07, 0x16, 0x25, 0x34, 0x43, 0x52, 0x61,
6841 0x70, 0x7f, 0x8e, 0x9d, 0xac, 0xbb, 0xca, 0xd9,
6842 0xe8, 0xf7, 0x06, 0x15, 0x24, 0x33, 0x42, 0x51,
6843 0x60, 0x6f, 0x7e, 0x8d, 0x9c, 0xab, 0xba, 0xc9,
6844 0xd8, 0xe7, 0xf6, 0x05, 0x14, 0x23, 0x32, 0x41,
6845 0x50, 0x5f, 0x6e, 0x7d, 0x8c, 0x9b, 0xaa, 0xb9,
6846 0xc8, 0xd7, 0xe6, 0xf5, 0x04, 0x13, 0x22, 0x31,
6847 0x40, 0x4f, 0x5e, 0x6d, 0x7c, 0x8b, 0x9a, 0xa9,
6848 0xb8, 0xc7, 0xd6, 0xe5, 0xf4, 0x03, 0x12, 0x21,
6849 0x30, 0x3f, 0x4e, 0x5d, 0x6c, 0x7b, 0x8a, 0x99,
6850 0xa8, 0xb7, 0xc6, 0xd5, 0xe4, 0xf3, 0x02, 0x11,
6851 0x20, 0x2f, 0x3e, 0x4d, 0x5c, 0x6b, 0x7a, 0x89,
6852 0x98, 0xa7, 0xb6, 0xc5, 0xd4, 0xe3, 0xf2, 0x01,
6853 0x10, 0x1f, 0x2e, 0x3d, 0x4c, 0x5b, 0x6a, 0x79,
6854 0x88, 0x97, 0xa6, 0xb5, 0xc4, 0xd3, 0xe2, 0xf1,
6855 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
6856 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
6857 0x10, 0x21, 0x32, 0x43, 0x54, 0x65, 0x76, 0x87,
6858 0x98, 0xa9, 0xba, 0xcb, 0xdc, 0xed, 0xfe, 0x0f,
6859 0x20, 0x31, 0x42, 0x53, 0x64, 0x75, 0x86, 0x97,
6860 0xa8, 0xb9, 0xca, 0xdb, 0xec, 0xfd, 0x0e, 0x1f,
6861 0x30, 0x41, 0x52, 0x63, 0x74, 0x85, 0x96, 0xa7,
6862 0xb8, 0xc9, 0xda, 0xeb, 0xfc, 0x0d, 0x1e, 0x2f,
6863 0x40, 0x51, 0x62, 0x73, 0x84, 0x95, 0xa6, 0xb7,
6864 0xc8, 0xd9, 0xea, 0xfb, 0x0c, 0x1d, 0x2e, 0x3f,
6865 0x50, 0x61, 0x72, 0x83, 0x94, 0xa5, 0xb6, 0xc7,
6866 0xd8, 0xe9, 0xfa, 0x0b, 0x1c, 0x2d, 0x3e, 0x4f,
6867 0x60, 0x71, 0x82, 0x93, 0xa4, 0xb5, 0xc6, 0xd7,
6868 0xe8, 0xf9, 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f,
6869 0x70, 0x81, 0x92, 0xa3, 0xb4, 0xc5, 0xd6, 0xe7,
6870 0xf8, 0x09, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e, 0x6f,
6871 0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7,
6872 0x08, 0x19, 0x2a, 0x3b, 0x4c, 0x5d, 0x6e, 0x7f,
6873 0x90, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf6, 0x07,
6874 0x18, 0x29, 0x3a, 0x4b, 0x5c, 0x6d, 0x7e, 0x8f,
6875 0xa0, 0xb1, 0xc2, 0xd3, 0xe4, 0xf5, 0x06, 0x17,
6876 0x28, 0x39, 0x4a, 0x5b, 0x6c, 0x7d, 0x8e, 0x9f,
6877 0xb0, 0xc1, 0xd2, 0xe3, 0xf4, 0x05, 0x16, 0x27,
6878 0x38, 0x49, 0x5a, 0x6b, 0x7c, 0x8d, 0x9e, 0xaf,
6879 0xc0, 0xd1, 0xe2, 0xf3, 0x04, 0x15, 0x26, 0x37,
6880 0x48, 0x59, 0x6a, 0x7b, 0x8c, 0x9d, 0xae, 0xbf,
6881 0xd0, 0xe1, 0xf2, 0x03, 0x14, 0x25, 0x36, 0x47,
6882 0x58, 0x69, 0x7a, 0x8b, 0x9c, 0xad, 0xbe, 0xcf,
6883 0xe0, 0xf1, 0x02, 0x13, 0x24, 0x35, 0x46, 0x57,
6884 0x68, 0x79, 0x8a, 0x9b, 0xac, 0xbd, 0xce, 0xdf,
6885 0xf0, 0x01, 0x12, 0x23, 0x34, 0x45, 0x56, 0x67,
6886 0x78, 0x89, 0x9a, 0xab, 0xbc, 0xcd, 0xde, 0xef,
6887 0x00, 0x13, 0x26, 0x39, 0x4c, 0x5f, 0x72, 0x85,
6888 0x98, 0xab, 0xbe, 0xd1, 0xe4, 0xf7, 0x0a, 0x1d,
6889 0x30, 0x43, 0x56, 0x69, 0x7c, 0x8f, 0xa2, 0xb5,
6890 0xc8, 0xdb, 0xee, 0x01, 0x14, 0x27, 0x3a, 0x4d,
6891 0x60, 0x73, 0x86, 0x99, 0xac, 0xbf, 0xd2, 0xe5,
6892 0xf8, 0x0b, 0x1e, 0x31, 0x44, 0x57, 0x6a, 0x7d,
6893 0x90, 0xa3, 0xb6, 0xc9, 0xdc, 0xef, 0x02, 0x15,
6894 0x28, 0x3b, 0x4e, 0x61, 0x74, 0x87, 0x9a, 0xad,
6895 0xc0, 0xd3, 0xe6, 0xf9, 0x0c, 0x1f, 0x32, 0x45,
6896 0x58, 0x6b, 0x7e, 0x91, 0xa4, 0xb7, 0xca, 0xdd,
6897 0xf0, 0x03, 0x16, 0x29, 0x3c, 0x4f, 0x62, 0x75,
6898 0x88, 0x9b, 0xae, 0xc1, 0xd4, 0xe7, 0xfa, 0x0d,
6899 0x20, 0x33, 0x46, 0x59, 0x6c, 0x7f, 0x92, 0xa5,
6900 0xb8, 0xcb, 0xde, 0xf1, 0x04, 0x17, 0x2a, 0x3d,
6901 0x50, 0x63, 0x76, 0x89, 0x9c, 0xaf, 0xc2, 0xd5,
6902 0xe8, 0xfb, 0x0e, 0x21, 0x34, 0x47, 0x5a, 0x6d,
6903 0x80, 0x93, 0xa6, 0xb9, 0xcc, 0xdf, 0xf2, 0x05,
6904 0x18, 0x2b, 0x3e, 0x51, 0x64, 0x77, 0x8a, 0x9d,
6905 0xb0, 0xc3, 0xd6, 0xe9, 0xfc, 0x0f, 0x22, 0x35,
6906 0x48, 0x5b, 0x6e, 0x81, 0x94, 0xa7, 0xba, 0xcd,
6907 0xe0, 0xf3, 0x06, 0x19, 0x2c, 0x3f, 0x52, 0x65,
6908 0x78, 0x8b, 0x9e, 0xb1, 0xc4, 0xd7, 0xea, 0xfd,
6909 0x10, 0x23, 0x36, 0x49, 0x5c, 0x6f, 0x82, 0x95,
6910 0xa8, 0xbb, 0xce, 0xe1, 0xf4, 0x07, 0x1a, 0x2d,
6911 0x40, 0x53, 0x66, 0x79, 0x8c, 0x9f, 0xb2, 0xc5,
6912 0xd8, 0xeb, 0xfe, 0x11, 0x24, 0x37, 0x4a, 0x5d,
6913 0x70, 0x83, 0x96, 0xa9, 0xbc, 0xcf, 0xe2, 0xf5,
6914 0x08, 0x1b, 0x2e, 0x41, 0x54, 0x67, 0x7a, 0x8d,
6915 0xa0, 0xb3, 0xc6, 0xd9, 0xec, 0xff, 0x12, 0x25,
6916 0x38, 0x4b, 0x5e, 0x71, 0x84, 0x97, 0xaa, 0xbd,
6917 0xd0, 0xe3, 0xf6, 0x09, 0x1c, 0x2f, 0x42, 0x55,
6918 0x68, 0x7b, 0x8e, 0xa1, 0xb4, 0xc7, 0xda, 0xed,
6919 0x00, 0x15, 0x2a, 0x3f, 0x54, 0x69, 0x7e, 0x93,
6920 0xa8, 0xbd, 0xd2, 0xe7, 0xfc, 0x11, 0x26, 0x3b,
6921 0x50, 0x65, 0x7a, 0x8f, 0xa4, 0xb9, 0xce, 0xe3,
6922 0xf8, 0x0d, 0x22, 0x37, 0x4c, 0x61, 0x76, 0x8b,
6923 0xa0, 0xb5, 0xca, 0xdf, 0xf4, 0x09, 0x1e, 0x33,
6924 0x48, 0x5d, 0x72, 0x87, 0x9c, 0xb1, 0xc6, 0xdb,
6925 0xf0, 0x05, 0x1a, 0x2f, 0x44, 0x59, 0x6e, 0x83,
6926 0x98, 0xad, 0xc2, 0xd7, 0xec, 0x01, 0x16, 0x2b,
6927 0x40, 0x55, 0x6a, 0x7f, 0x94, 0xa9, 0xbe, 0xd3,
6928 0xe8, 0xfd, 0x12, 0x27, 0x3c, 0x51, 0x66, 0x7b,
6929 0x90, 0xa5, 0xba, 0xcf, 0xe4, 0xf9, 0x0e, 0x23,
6930 0x38, 0x4d, 0x62, 0x77, 0x8c, 0xa1, 0xb6, 0xcb,
6931 0xe0, 0xf5, 0x0a, 0x1f, 0x34, 0x49, 0x5e, 0x73,
6932 0x88, 0x9d, 0xb2, 0xc7, 0xdc, 0xf1, 0x06, 0x1b,
6933 0x30, 0x45, 0x5a, 0x6f, 0x84, 0x99, 0xae, 0xc3,
6934 0xd8, 0xed, 0x02, 0x17, 0x2c, 0x41, 0x56, 0x6b,
6935 0x80, 0x95, 0xaa, 0xbf, 0xd4, 0xe9, 0xfe, 0x13,
6936 0x28, 0x3d, 0x52, 0x67, 0x7c, 0x91, 0xa6, 0xbb,
6937 0xd0, 0xe5, 0xfa, 0x0f, 0x24, 0x39, 0x4e, 0x63,
6938 0x78, 0x8d, 0xa2, 0xb7, 0xcc, 0xe1, 0xf6, 0x0b,
6939 0x20, 0x35, 0x4a, 0x5f, 0x74, 0x89, 0x9e, 0xb3,
6940 0xc8, 0xdd, 0xf2, 0x07, 0x1c, 0x31, 0x46, 0x5b,
6941 0x70, 0x85, 0x9a, 0xaf, 0xc4, 0xd9, 0xee, 0x03,
6942 0x18, 0x2d, 0x42, 0x57, 0x6c, 0x81, 0x96, 0xab,
6943 0xc0, 0xd5, 0xea, 0xff, 0x14, 0x29, 0x3e, 0x53,
6944 0x68, 0x7d, 0x92, 0xa7, 0xbc, 0xd1, 0xe6, 0xfb,
6945 0x10, 0x25, 0x3a, 0x4f, 0x64, 0x79, 0x8e, 0xa3,
6946 0xb8, 0xcd, 0xe2, 0xf7, 0x0c, 0x21, 0x36, 0x4b,
6947 0x60, 0x75, 0x8a, 0x9f, 0xb4, 0xc9, 0xde, 0xf3,
6948 0x08, 0x1d, 0x32, 0x47, 0x5c, 0x71, 0x86, 0x9b,
6949 0xb0, 0xc5, 0xda, 0xef, 0x04, 0x19, 0x2e, 0x43,
6950 0x58, 0x6d, 0x82, 0x97, 0xac, 0xc1, 0xd6, 0xeb,
6951 0x00, 0x17, 0x2e, 0x45, 0x5c, 0x73, 0x8a, 0xa1,
6952 0xb8, 0xcf, 0xe6, 0xfd, 0x14, 0x2b, 0x42, 0x59,
6953 0x70, 0x87, 0x9e, 0xb5, 0xcc, 0xe3, 0xfa, 0x11,
6954 0x28, 0x3f, 0x56, 0x6d, 0x84, 0x9b, 0xb2, 0xc9,
6955 0xe0, 0xf7, 0x0e, 0x25, 0x3c, 0x53, 0x6a, 0x81,
6956 0x98, 0xaf, 0xc6, 0xdd, 0xf4, 0x0b, 0x22, 0x39,
6957 0x50, 0x67, 0x7e, 0x95, 0xac, 0xc3, 0xda, 0xf1,
6958 0x08, 0x1f, 0x36, 0x4d, 0x64, 0x7b, 0x92, 0xa9,
6959 0xc0, 0xd7, 0xee, 0x05, 0x1c, 0x33, 0x4a, 0x61,
6960 0x78, 0x8f, 0xa6, 0xbd, 0xd4, 0xeb, 0x02, 0x19,
6961 0x30, 0x47, 0x5e, 0x75, 0x8c, 0xa3, 0xba, 0xd1,
6962 0xe8, 0xff, 0x16, 0x2d, 0x44, 0x5b, 0x72, 0x89,
6963 0xa0, 0xb7, 0xce, 0xe5, 0xfc, 0x13, 0x2a, 0x41,
6964 0x58, 0x6f, 0x86, 0x9d, 0xb4, 0xcb, 0xe2, 0xf9,
6965 0x10, 0x27, 0x3e, 0x55, 0x6c, 0x83, 0x9a, 0xb1,
6966 0xc8, 0xdf, 0xf6, 0x0d, 0x24, 0x3b, 0x52, 0x69,
6967 0x80, 0x97, 0xae, 0xc5, 0xdc, 0xf3, 0x0a, 0x21,
6968 0x38, 0x4f, 0x66, 0x7d, 0x94, 0xab, 0xc2, 0xd9,
6969 0xf0, 0x07, 0x1e, 0x35, 0x4c, 0x63, 0x7a, 0x91,
6970 0xa8, 0xbf, 0xd6, 0xed, 0x04, 0x1b, 0x32, 0x49,
6971 0x60, 0x77, 0x8e, 0xa5, 0xbc, 0xd3, 0xea, 0x01,
6972 0x18, 0x2f, 0x46, 0x5d, 0x74, 0x8b, 0xa2, 0xb9,
6973 0xd0, 0xe7, 0xfe, 0x15, 0x2c, 0x43, 0x5a, 0x71,
6974 0x88, 0x9f, 0xb6, 0xcd, 0xe4, 0xfb, 0x12, 0x29,
6975 0x40, 0x57, 0x6e, 0x85, 0x9c, 0xb3, 0xca, 0xe1,
6976 0xf8, 0x0f, 0x26, 0x3d, 0x54, 0x6b, 0x82, 0x99,
6977 0xb0, 0xc7, 0xde, 0xf5, 0x0c, 0x23, 0x3a, 0x51,
6978 0x68, 0x7f, 0x96, 0xad, 0xc4, 0xdb, 0xf2, 0x09,
6979 0x20, 0x37, 0x4e, 0x65, 0x7c, 0x93, 0xaa, 0xc1,
6980 0xd8, 0xef, 0x06, 0x1d, 0x34, 0x4b, 0x62, 0x79,
6981 0x90, 0xa7, 0xbe, 0xd5, 0xec, 0x03, 0x1a, 0x31,
6982 0x48, 0x5f, 0x76, 0x8d, 0xa4, 0xbb, 0xd2, 0xe9,
6983 0x00, 0x19, 0x32, 0x4b, 0x64, 0x7d, 0x96, 0xaf,
6984 0xc8, 0xe1, 0xfa, 0x13, 0x2c, 0x45, 0x5e, 0x77,
6985 0x90, 0xa9, 0xc2, 0xdb, 0xf4, 0x0d, 0x26, 0x3f,
6986 0x58, 0x71, 0x8a, 0xa3, 0xbc, 0xd5, 0xee, 0x07,
6987 0x20, 0x39, 0x52, 0x6b, 0x84, 0x9d, 0xb6, 0xcf,
6988 0xe8, 0x01, 0x1a, 0x33, 0x4c, 0x65, 0x7e, 0x97,
6989 0xb0, 0xc9, 0xe2, 0xfb, 0x14, 0x2d, 0x46, 0x5f,
6990 0x78, 0x91, 0xaa, 0xc3, 0xdc, 0xf5, 0x0e, 0x27,
6991 0x40, 0x59, 0x72, 0x8b, 0xa4, 0xbd, 0xd6, 0xef,
6992 0x08, 0x21, 0x3a, 0x53, 0x6c, 0x85, 0x9e, 0xb7,
6993 0xd0, 0xe9, 0x02, 0x1b, 0x34, 0x4d, 0x66, 0x7f,
6994 0x98, 0xb1, 0xca, 0xe3, 0xfc, 0x15, 0x2e, 0x47,
6995 0x60, 0x79, 0x92, 0xab, 0xc4, 0xdd, 0xf6, 0x0f,
6996 0x28, 0x41, 0x5a, 0x73, 0x8c, 0xa5, 0xbe, 0xd7,
6997 0xf0, 0x09, 0x22, 0x3b, 0x54, 0x6d, 0x86, 0x9f,
6998 0xb8, 0xd1, 0xea, 0x03, 0x1c, 0x35, 0x4e, 0x67,
6999 0x80, 0x99, 0xb2, 0xcb, 0xe4, 0xfd, 0x16, 0x2f,
7000 0x48, 0x61, 0x7a, 0x93, 0xac, 0xc5, 0xde, 0xf7,
7001 0x10, 0x29, 0x42, 0x5b, 0x74, 0x8d, 0xa6, 0xbf,
7002 0xd8, 0xf1, 0x0a, 0x23, 0x3c, 0x55, 0x6e, 0x87,
7003 0xa0, 0xb9, 0xd2, 0xeb, 0x04, 0x1d, 0x36, 0x4f,
7004 0x68, 0x81, 0x9a, 0xb3, 0xcc, 0xe5, 0xfe, 0x17,
7005 0x30, 0x49, 0x62, 0x7b, 0x94, 0xad, 0xc6, 0xdf,
7006 0xf8, 0x11, 0x2a, 0x43, 0x5c, 0x75, 0x8e, 0xa7,
7007 0xc0, 0xd9, 0xf2, 0x0b, 0x24, 0x3d, 0x56, 0x6f,
7008 0x88, 0xa1, 0xba, 0xd3, 0xec, 0x05, 0x1e, 0x37,
7009 0x50, 0x69, 0x82, 0x9b, 0xb4, 0xcd, 0xe6, 0xff,
7010 0x18, 0x31, 0x4a, 0x63, 0x7c, 0x95, 0xae, 0xc7,
7011 0xe0, 0xf9, 0x12, 0x2b, 0x44, 0x5d, 0x76, 0x8f,
7012 0xa8, 0xc1, 0xda, 0xf3, 0x0c, 0x25, 0x3e, 0x57,
7013 0x70, 0x89, 0xa2, 0xbb, 0xd4, 0xed, 0x06, 0x1f,
7014 0x38, 0x51, 0x6a, 0x83, 0x9c, 0xb5, 0xce, 0xe7,
7015 0x00, 0x1b, 0x36, 0x51, 0x6c, 0x87, 0xa2, 0xbd,
7016 0xd8, 0xf3, 0x0e, 0x29, 0x44, 0x5f, 0x7a, 0x95,
7017 0xb0, 0xcb, 0xe6, 0x01, 0x1c, 0x37, 0x52, 0x6d,
7018 0x88, 0xa3, 0xbe, 0xd9, 0xf4, 0x0f, 0x2a, 0x45,
7019 0x60, 0x7b, 0x96, 0xb1, 0xcc, 0xe7, 0x02, 0x1d,
7020 0x38, 0x53, 0x6e, 0x89, 0xa4, 0xbf, 0xda, 0xf5,
7021 0x10, 0x2b, 0x46, 0x61, 0x7c, 0x97, 0xb2, 0xcd,
7022 0xe8, 0x03, 0x1e, 0x39, 0x54, 0x6f, 0x8a, 0xa5,
7023 0xc0, 0xdb, 0xf6, 0x11, 0x2c, 0x47, 0x62, 0x7d,
7024 0x98, 0xb3, 0xce, 0xe9, 0x04, 0x1f, 0x3a, 0x55,
7025 0x70, 0x8b, 0xa6, 0xc1, 0xdc, 0xf7, 0x12, 0x2d,
7026 0x48, 0x63, 0x7e, 0x99, 0xb4, 0xcf, 0xea, 0x05,
7027 0x20, 0x3b, 0x56, 0x71, 0x8c, 0xa7, 0xc2, 0xdd,
7028 0xf8, 0x13, 0x2e, 0x49, 0x64, 0x7f, 0x9a, 0xb5,
7029 0xd0, 0xeb, 0x06, 0x21, 0x3c, 0x57, 0x72, 0x8d,
7030 0xa8, 0xc3, 0xde, 0xf9, 0x14, 0x2f, 0x4a, 0x65,
7031 0x80, 0x9b, 0xb6, 0xd1, 0xec, 0x07, 0x22, 0x3d,
7032 0x58, 0x73, 0x8e, 0xa9, 0xc4, 0xdf, 0xfa, 0x15,
7033 0x30, 0x4b, 0x66, 0x81, 0x9c, 0xb7, 0xd2, 0xed,
7034 0x08, 0x23, 0x3e, 0x59, 0x74, 0x8f, 0xaa, 0xc5,
7035 0xe0, 0xfb, 0x16, 0x31, 0x4c, 0x67, 0x82, 0x9d,
7036 0xb8, 0xd3, 0xee, 0x09, 0x24, 0x3f, 0x5a, 0x75,
7037 0x90, 0xab, 0xc6, 0xe1, 0xfc, 0x17, 0x32, 0x4d,
7038 0x68, 0x83, 0x9e, 0xb9, 0xd4, 0xef, 0x0a, 0x25,
7039 0x40, 0x5b, 0x76, 0x91, 0xac, 0xc7, 0xe2, 0xfd,
7040 0x18, 0x33, 0x4e, 0x69, 0x84, 0x9f, 0xba, 0xd5,
7041 0xf0, 0x0b, 0x26, 0x41, 0x5c, 0x77, 0x92, 0xad,
7042 0xc8, 0xe3, 0xfe, 0x19, 0x34, 0x4f, 0x6a, 0x85,
7043 0xa0, 0xbb, 0xd6, 0xf1, 0x0c, 0x27, 0x42, 0x5d,
7044 0x78, 0x93, 0xae, 0xc9, 0xe4, 0xff, 0x1a, 0x35,
7045 0x50, 0x6b, 0x86, 0xa1, 0xbc, 0xd7, 0xf2, 0x0d,
7046 0x28, 0x43, 0x5e, 0x79, 0x94, 0xaf, 0xca, 0xe5,
7047 0x00, 0x1d, 0x3a, 0x57, 0x74, 0x91, 0xae, 0xcb,
7048 0xe8, 0x05, 0x22, 0x3f, 0x5c, 0x79, 0x96, 0xb3,
7049 0xd0, 0xed, 0x0a, 0x27, 0x44, 0x61, 0x7e, 0x9b,
7050 0xb8, 0xd5, 0xf2, 0x0f, 0x2c, 0x49, 0x66, 0x83,
7051 0xa0, 0xbd, 0xda, 0xf7, 0x14, 0x31, 0x4e, 0x6b,
7052 0x88, 0xa5, 0xc2, 0xdf, 0xfc, 0x19, 0x36, 0x53,
7053 0x70, 0x8d, 0xaa, 0xc7, 0xe4, 0x01, 0x1e, 0x3b,
7054 0x58, 0x75, 0x92, 0xaf, 0xcc, 0xe9, 0x06, 0x23,
7055 0x40, 0x5d, 0x7a, 0x97, 0xb4, 0xd1, 0xee, 0x0b,
7056 0x28, 0x45, 0x62, 0x7f, 0x9c, 0xb9, 0xd6, 0xf3,
7057 0x10, 0x2d, 0x4a, 0x67, 0x84, 0xa1, 0xbe, 0xdb,
7058 0xf8, 0x15, 0x32, 0x4f, 0x6c, 0x89, 0xa6, 0xc3,
7059 0xe0, 0xfd, 0x1a, 0x37, 0x54, 0x71, 0x8e, 0xab,
7060 0xc8, 0xe5, 0x02, 0x1f, 0x3c, 0x59, 0x76, 0x93,
7061 0xb0, 0xcd, 0xea, 0x07, 0x24, 0x41, 0x5e, 0x7b,
7062 0x98, 0xb5, 0xd2, 0xef, 0x0c, 0x29, 0x46, 0x63,
7063 0x80, 0x9d, 0xba, 0xd7, 0xf4, 0x11, 0x2e, 0x4b,
7064 0x68, 0x85, 0xa2, 0xbf, 0xdc, 0xf9, 0x16, 0x33,
7065 0x50, 0x6d, 0x8a, 0xa7, 0xc4, 0xe1, 0xfe, 0x1b,
7066 0x38, 0x55, 0x72, 0x8f, 0xac, 0xc9, 0xe6, 0x03,
7067 0x20, 0x3d, 0x5a, 0x77, 0x94, 0xb1, 0xce, 0xeb,
7068 0x08, 0x25, 0x42, 0x5f, 0x7c, 0x99, 0xb6, 0xd3,
7069 0xf0, 0x0d, 0x2a, 0x47, 0x64, 0x81, 0x9e, 0xbb,
7070 0xd8, 0xf5, 0x12, 0x2f, 0x4c, 0x69, 0x86, 0xa3,
7071 0xc0, 0xdd, 0xfa, 0x17, 0x34, 0x51, 0x6e, 0x8b,
7072 0xa8, 0xc5, 0xe2, 0xff, 0x1c, 0x39, 0x56, 0x73,
7073 0x90, 0xad, 0xca, 0xe7, 0x04, 0x21, 0x3e, 0x5b,
7074 0x78, 0x95, 0xb2, 0xcf, 0xec, 0x09, 0x26, 0x43,
7075 0x60, 0x7d, 0x9a, 0xb7, 0xd4, 0xf1, 0x0e, 0x2b,
7076 0x48, 0x65, 0x82, 0x9f, 0xbc, 0xd9, 0xf6, 0x13,
7077 0x30, 0x4d, 0x6a, 0x87, 0xa4, 0xc1, 0xde, 0xfb,
7078 0x18, 0x35, 0x52, 0x6f, 0x8c, 0xa9, 0xc6, 0xe3,
7079 0x00, 0x1f, 0x3e, 0x5d, 0x7c, 0x9b, 0xba, 0xd9,
7080 0xf8, 0x17, 0x36, 0x55, 0x74, 0x93, 0xb2, 0xd1,
7081 0xf0, 0x0f, 0x2e, 0x4d, 0x6c, 0x8b, 0xaa, 0xc9,
7082 0xe8, 0x07, 0x26, 0x45, 0x64, 0x83, 0xa2, 0xc1,
7083 0xe0, 0xff, 0x1e, 0x3d, 0x5c, 0x7b, 0x9a, 0xb9,
7084 0xd8, 0xf7, 0x16, 0x35, 0x54, 0x73, 0x92, 0xb1,
7085 0xd0, 0xef, 0x0e, 0x2d, 0x4c, 0x6b, 0x8a, 0xa9,
7086 0xc8, 0xe7, 0x06, 0x25, 0x44, 0x63, 0x82, 0xa1,
7087 0xc0, 0xdf, 0xfe, 0x1d, 0x3c, 0x5b, 0x7a, 0x99,
7088 0xb8, 0xd7, 0xf6, 0x15, 0x34, 0x53, 0x72, 0x91,
7089 0xb0, 0xcf, 0xee, 0x0d, 0x2c, 0x4b, 0x6a, 0x89,
7090 0xa8, 0xc7, 0xe6, 0x05, 0x24, 0x43, 0x62, 0x81,
7091 0xa0, 0xbf, 0xde, 0xfd, 0x1c, 0x3b, 0x5a, 0x79,
7092 0x98, 0xb7, 0xd6, 0xf5, 0x14, 0x33, 0x52, 0x71,
7093 0x90, 0xaf, 0xce, 0xed, 0x0c, 0x2b, 0x4a, 0x69,
7094 0x88, 0xa7, 0xc6, 0xe5, 0x04, 0x23, 0x42, 0x61,
7095 0x80, 0x9f, 0xbe, 0xdd, 0xfc, 0x1b, 0x3a, 0x59,
7096 0x78, 0x97, 0xb6, 0xd5, 0xf4, 0x13, 0x32, 0x51,
7097 0x70, 0x8f, 0xae, 0xcd, 0xec, 0x0b, 0x2a, 0x49,
7098 0x68, 0x87, 0xa6, 0xc5, 0xe4, 0x03, 0x22, 0x41,
7099 0x60, 0x7f, 0x9e, 0xbd, 0xdc, 0xfb, 0x1a, 0x39,
7100 0x58, 0x77, 0x96, 0xb5, 0xd4, 0xf3, 0x12, 0x31,
7101 0x50, 0x6f, 0x8e, 0xad, 0xcc, 0xeb, 0x0a, 0x29,
7102 0x48, 0x67, 0x86, 0xa5, 0xc4, 0xe3, 0x02, 0x21,
7103 0x40, 0x5f, 0x7e, 0x9d, 0xbc, 0xdb, 0xfa, 0x19,
7104 0x38, 0x57, 0x76, 0x95, 0xb4, 0xd3, 0xf2, 0x11,
7105 0x30, 0x4f, 0x6e, 0x8d, 0xac, 0xcb, 0xea, 0x09,
7106 0x28, 0x47, 0x66, 0x85, 0xa4, 0xc3, 0xe2, 0x01,
7107 0x20, 0x3f, 0x5e, 0x7d, 0x9c, 0xbb, 0xda, 0xf9,
7108 0x18, 0x37, 0x56, 0x75, 0x94, 0xb3, 0xd2, 0xf1,
7109 0x10, 0x2f, 0x4e, 0x6d, 0x8c, 0xab, 0xca, 0xe9,
7110 0x08, 0x27, 0x46, 0x65, 0x84, 0xa3, 0xc2, 0xe1,
7111 0x00, 0x21, 0x42, 0x63,
7112 },
7113 .ilen = 4100,
7114 .result = {
7115 0xb5, 0x81, 0xf5, 0x64, 0x18, 0x73, 0xe3, 0xf0,
7116 0x4c, 0x13, 0xf2, 0x77, 0x18, 0x60, 0x65, 0x5e,
7117 0x29, 0x01, 0xce, 0x98, 0x55, 0x53, 0xf9, 0x0c,
7118 0x2a, 0x08, 0xd5, 0x09, 0xb3, 0x57, 0x55, 0x56,
7119 0xc5, 0xe9, 0x56, 0x90, 0xcb, 0x6a, 0xa3, 0xc0,
7120 0xff, 0xc4, 0x79, 0xb4, 0xd2, 0x97, 0x5d, 0xc4,
7121 0x43, 0xd1, 0xfe, 0x94, 0x7b, 0x88, 0x06, 0x5a,
7122 0xb2, 0x9e, 0x2c, 0xfc, 0x44, 0x03, 0xb7, 0x90,
7123 0xa0, 0xc1, 0xba, 0x6a, 0x33, 0xb8, 0xc7, 0xb2,
7124 0x9d, 0xe1, 0x12, 0x4f, 0xc0, 0x64, 0xd4, 0x01,
7125 0xfe, 0x8c, 0x7a, 0x66, 0xf7, 0xe6, 0x5a, 0x91,
7126 0xbb, 0xde, 0x56, 0x86, 0xab, 0x65, 0x21, 0x30,
7127 0x00, 0x84, 0x65, 0x24, 0xa5, 0x7d, 0x85, 0xb4,
7128 0xe3, 0x17, 0xed, 0x3a, 0xb7, 0x6f, 0xb4, 0x0b,
7129 0x0b, 0xaf, 0x15, 0xae, 0x5a, 0x8f, 0xf2, 0x0c,
7130 0x2f, 0x27, 0xf4, 0x09, 0xd8, 0xd2, 0x96, 0xb7,
7131 0x71, 0xf2, 0xc5, 0x99, 0x4d, 0x7e, 0x7f, 0x75,
7132 0x77, 0x89, 0x30, 0x8b, 0x59, 0xdb, 0xa2, 0xb2,
7133 0xa0, 0xf3, 0x19, 0x39, 0x2b, 0xc5, 0x7e, 0x3f,
7134 0x4f, 0xd9, 0xd3, 0x56, 0x28, 0x97, 0x44, 0xdc,
7135 0xc0, 0x8b, 0x77, 0x24, 0xd9, 0x52, 0xe7, 0xc5,
7136 0xaf, 0xf6, 0x7d, 0x59, 0xb2, 0x44, 0x05, 0x1d,
7137 0xb1, 0xb0, 0x11, 0xa5, 0x0f, 0xec, 0x33, 0xe1,
7138 0x6d, 0x1b, 0x4e, 0x1f, 0xff, 0x57, 0x91, 0xb4,
7139 0x5b, 0x9a, 0x96, 0xc5, 0x53, 0xbc, 0xae, 0x20,
7140 0x3c, 0xbb, 0x14, 0xe2, 0xe8, 0x22, 0x33, 0xc1,
7141 0x5e, 0x76, 0x9e, 0x46, 0x99, 0xf6, 0x2a, 0x15,
7142 0xc6, 0x97, 0x02, 0xa0, 0x66, 0x43, 0xd1, 0xa6,
7143 0x31, 0xa6, 0x9f, 0xfb, 0xf4, 0xd3, 0x69, 0xe5,
7144 0xcd, 0x76, 0x95, 0xb8, 0x7a, 0x82, 0x7f, 0x21,
7145 0x45, 0xff, 0x3f, 0xce, 0x55, 0xf6, 0x95, 0x10,
7146 0x08, 0x77, 0x10, 0x43, 0xc6, 0xf3, 0x09, 0xe5,
7147 0x68, 0xe7, 0x3c, 0xad, 0x00, 0x52, 0x45, 0x0d,
7148 0xfe, 0x2d, 0xc6, 0xc2, 0x94, 0x8c, 0x12, 0x1d,
7149 0xe6, 0x25, 0xae, 0x98, 0x12, 0x8e, 0x19, 0x9c,
7150 0x81, 0x68, 0xb1, 0x11, 0xf6, 0x69, 0xda, 0xe3,
7151 0x62, 0x08, 0x18, 0x7a, 0x25, 0x49, 0x28, 0xac,
7152 0xba, 0x71, 0x12, 0x0b, 0xe4, 0xa2, 0xe5, 0xc7,
7153 0x5d, 0x8e, 0xec, 0x49, 0x40, 0x21, 0xbf, 0x5a,
7154 0x98, 0xf3, 0x02, 0x68, 0x55, 0x03, 0x7f, 0x8a,
7155 0xe5, 0x94, 0x0c, 0x32, 0x5c, 0x07, 0x82, 0x63,
7156 0xaf, 0x6f, 0x91, 0x40, 0x84, 0x8e, 0x52, 0x25,
7157 0xd0, 0xb0, 0x29, 0x53, 0x05, 0xe2, 0x50, 0x7a,
7158 0x34, 0xeb, 0xc9, 0x46, 0x20, 0xa8, 0x3d, 0xde,
7159 0x7f, 0x16, 0x5f, 0x36, 0xc5, 0x2e, 0xdc, 0xd1,
7160 0x15, 0x47, 0xc7, 0x50, 0x40, 0x6d, 0x91, 0xc5,
7161 0xe7, 0x93, 0x95, 0x1a, 0xd3, 0x57, 0xbc, 0x52,
7162 0x33, 0xee, 0x14, 0x19, 0x22, 0x52, 0x89, 0xa7,
7163 0x4a, 0x25, 0x56, 0x77, 0x4b, 0xca, 0xcf, 0x0a,
7164 0xe1, 0xf5, 0x35, 0x85, 0x30, 0x7e, 0x59, 0x4a,
7165 0xbd, 0x14, 0x5b, 0xdf, 0xe3, 0x46, 0xcb, 0xac,
7166 0x1f, 0x6c, 0x96, 0x0e, 0xf4, 0x81, 0xd1, 0x99,
7167 0xca, 0x88, 0x63, 0x3d, 0x02, 0x58, 0x6b, 0xa9,
7168 0xe5, 0x9f, 0xb3, 0x00, 0xb2, 0x54, 0xc6, 0x74,
7169 0x1c, 0xbf, 0x46, 0xab, 0x97, 0xcc, 0xf8, 0x54,
7170 0x04, 0x07, 0x08, 0x52, 0xe6, 0xc0, 0xda, 0x93,
7171 0x74, 0x7d, 0x93, 0x99, 0x5d, 0x78, 0x68, 0xa6,
7172 0x2e, 0x6b, 0xd3, 0x6a, 0x69, 0xcc, 0x12, 0x6b,
7173 0xd4, 0xc7, 0xa5, 0xc6, 0xe7, 0xf6, 0x03, 0x04,
7174 0x5d, 0xcd, 0x61, 0x5e, 0x17, 0x40, 0xdc, 0xd1,
7175 0x5c, 0xf5, 0x08, 0xdf, 0x5c, 0x90, 0x85, 0xa4,
7176 0xaf, 0xf6, 0x78, 0xbb, 0x0d, 0xf1, 0xf4, 0xa4,
7177 0x54, 0x26, 0x72, 0x9e, 0x61, 0xfa, 0x86, 0xcf,
7178 0xe8, 0x9e, 0xa1, 0xe0, 0xc7, 0x48, 0x23, 0xae,
7179 0x5a, 0x90, 0xae, 0x75, 0x0a, 0x74, 0x18, 0x89,
7180 0x05, 0xb1, 0x92, 0xb2, 0x7f, 0xd0, 0x1b, 0xa6,
7181 0x62, 0x07, 0x25, 0x01, 0xc7, 0xc2, 0x4f, 0xf9,
7182 0xe8, 0xfe, 0x63, 0x95, 0x80, 0x07, 0xb4, 0x26,
7183 0xcc, 0xd1, 0x26, 0xb6, 0xc4, 0x3f, 0x9e, 0xcb,
7184 0x8e, 0x3b, 0x2e, 0x44, 0x16, 0xd3, 0x10, 0x9a,
7185 0x95, 0x08, 0xeb, 0xc8, 0xcb, 0xeb, 0xbf, 0x6f,
7186 0x0b, 0xcd, 0x1f, 0xc8, 0xca, 0x86, 0xaa, 0xec,
7187 0x33, 0xe6, 0x69, 0xf4, 0x45, 0x25, 0x86, 0x3a,
7188 0x22, 0x94, 0x4f, 0x00, 0x23, 0x6a, 0x44, 0xc2,
7189 0x49, 0x97, 0x33, 0xab, 0x36, 0x14, 0x0a, 0x70,
7190 0x24, 0xc3, 0xbe, 0x04, 0x3b, 0x79, 0xa0, 0xf9,
7191 0xb8, 0xe7, 0x76, 0x29, 0x22, 0x83, 0xd7, 0xf2,
7192 0x94, 0xf4, 0x41, 0x49, 0xba, 0x5f, 0x7b, 0x07,
7193 0xb5, 0xfb, 0xdb, 0x03, 0x1a, 0x9f, 0xb6, 0x4c,
7194 0xc2, 0x2e, 0x37, 0x40, 0x49, 0xc3, 0x38, 0x16,
7195 0xe2, 0x4f, 0x77, 0x82, 0xb0, 0x68, 0x4c, 0x71,
7196 0x1d, 0x57, 0x61, 0x9c, 0xd9, 0x4e, 0x54, 0x99,
7197 0x47, 0x13, 0x28, 0x73, 0x3c, 0xbb, 0x00, 0x90,
7198 0xf3, 0x4d, 0xc9, 0x0e, 0xfd, 0xe7, 0xb1, 0x71,
7199 0xd3, 0x15, 0x79, 0xbf, 0xcc, 0x26, 0x2f, 0xbd,
7200 0xad, 0x6c, 0x50, 0x69, 0x6c, 0x3e, 0x6d, 0x80,
7201 0x9a, 0xea, 0x78, 0xaf, 0x19, 0xb2, 0x0d, 0x4d,
7202 0xad, 0x04, 0x07, 0xae, 0x22, 0x90, 0x4a, 0x93,
7203 0x32, 0x0e, 0x36, 0x9b, 0x1b, 0x46, 0xba, 0x3b,
7204 0xb4, 0xac, 0xc6, 0xd1, 0xa2, 0x31, 0x53, 0x3b,
7205 0x2a, 0x3d, 0x45, 0xfe, 0x03, 0x61, 0x10, 0x85,
7206 0x17, 0x69, 0xa6, 0x78, 0xcc, 0x6c, 0x87, 0x49,
7207 0x53, 0xf9, 0x80, 0x10, 0xde, 0x80, 0xa2, 0x41,
7208 0x6a, 0xc3, 0x32, 0x02, 0xad, 0x6d, 0x3c, 0x56,
7209 0x00, 0x71, 0x51, 0x06, 0xa7, 0xbd, 0xfb, 0xef,
7210 0x3c, 0xb5, 0x9f, 0xfc, 0x48, 0x7d, 0x53, 0x7c,
7211 0x66, 0xb0, 0x49, 0x23, 0xc4, 0x47, 0x10, 0x0e,
7212 0xe5, 0x6c, 0x74, 0x13, 0xe6, 0xc5, 0x3f, 0xaa,
7213 0xde, 0xff, 0x07, 0x44, 0xdd, 0x56, 0x1b, 0xad,
7214 0x09, 0x77, 0xfb, 0x5b, 0x12, 0xb8, 0x0d, 0x38,
7215 0x17, 0x37, 0x35, 0x7b, 0x9b, 0xbc, 0xfe, 0xd4,
7216 0x7e, 0x8b, 0xda, 0x7e, 0x5b, 0x04, 0xa7, 0x22,
7217 0xa7, 0x31, 0xa1, 0x20, 0x86, 0xc7, 0x1b, 0x99,
7218 0xdb, 0xd1, 0x89, 0xf4, 0x94, 0xa3, 0x53, 0x69,
7219 0x8d, 0xe7, 0xe8, 0x74, 0x11, 0x8d, 0x74, 0xd6,
7220 0x07, 0x37, 0x91, 0x9f, 0xfd, 0x67, 0x50, 0x3a,
7221 0xc9, 0xe1, 0xf4, 0x36, 0xd5, 0xa0, 0x47, 0xd1,
7222 0xf9, 0xe5, 0x39, 0xa3, 0x31, 0xac, 0x07, 0x36,
7223 0x23, 0xf8, 0x66, 0x18, 0x14, 0x28, 0x34, 0x0f,
7224 0xb8, 0xd0, 0xe7, 0x29, 0xb3, 0x04, 0x4b, 0x55,
7225 0x01, 0x41, 0xb2, 0x75, 0x8d, 0xcb, 0x96, 0x85,
7226 0x3a, 0xfb, 0xab, 0x2b, 0x9e, 0xfa, 0x58, 0x20,
7227 0x44, 0x1f, 0xc0, 0x14, 0x22, 0x75, 0x61, 0xe8,
7228 0xaa, 0x19, 0xcf, 0xf1, 0x82, 0x56, 0xf4, 0xd7,
7229 0x78, 0x7b, 0x3d, 0x5f, 0xb3, 0x9e, 0x0b, 0x8a,
7230 0x57, 0x50, 0xdb, 0x17, 0x41, 0x65, 0x4d, 0xa3,
7231 0x02, 0xc9, 0x9c, 0x9c, 0x53, 0xfb, 0x39, 0x39,
7232 0x9b, 0x1d, 0x72, 0x24, 0xda, 0xb7, 0x39, 0xbe,
7233 0x13, 0x3b, 0xfa, 0x29, 0xda, 0x9e, 0x54, 0x64,
7234 0x6e, 0xba, 0xd8, 0xa1, 0xcb, 0xb3, 0x36, 0xfa,
7235 0xcb, 0x47, 0x85, 0xe9, 0x61, 0x38, 0xbc, 0xbe,
7236 0xc5, 0x00, 0x38, 0x2a, 0x54, 0xf7, 0xc4, 0xb9,
7237 0xb3, 0xd3, 0x7b, 0xa0, 0xa0, 0xf8, 0x72, 0x7f,
7238 0x8c, 0x8e, 0x82, 0x0e, 0xc6, 0x1c, 0x75, 0x9d,
7239 0xca, 0x8e, 0x61, 0x87, 0xde, 0xad, 0x80, 0xd2,
7240 0xf5, 0xf9, 0x80, 0xef, 0x15, 0x75, 0xaf, 0xf5,
7241 0x80, 0xfb, 0xff, 0x6d, 0x1e, 0x25, 0xb7, 0x40,
7242 0x61, 0x6a, 0x39, 0x5a, 0x6a, 0xb5, 0x31, 0xab,
7243 0x97, 0x8a, 0x19, 0x89, 0x44, 0x40, 0xc0, 0xa6,
7244 0xb4, 0x4e, 0x30, 0x32, 0x7b, 0x13, 0xe7, 0x67,
7245 0xa9, 0x8b, 0x57, 0x04, 0xc2, 0x01, 0xa6, 0xf4,
7246 0x28, 0x99, 0xad, 0x2c, 0x76, 0xa3, 0x78, 0xc2,
7247 0x4a, 0xe6, 0xca, 0x5c, 0x50, 0x6a, 0xc1, 0xb0,
7248 0x62, 0x4b, 0x10, 0x8e, 0x7c, 0x17, 0x43, 0xb3,
7249 0x17, 0x66, 0x1c, 0x3e, 0x8d, 0x69, 0xf0, 0x5a,
7250 0x71, 0xf5, 0x97, 0xdc, 0xd1, 0x45, 0xdd, 0x28,
7251 0xf3, 0x5d, 0xdf, 0x53, 0x7b, 0x11, 0xe5, 0xbc,
7252 0x4c, 0xdb, 0x1b, 0x51, 0x6b, 0xe9, 0xfb, 0x3d,
7253 0xc1, 0xc3, 0x2c, 0xb9, 0x71, 0xf5, 0xb6, 0xb2,
7254 0x13, 0x36, 0x79, 0x80, 0x53, 0xe8, 0xd3, 0xa6,
7255 0x0a, 0xaf, 0xfd, 0x56, 0x97, 0xf7, 0x40, 0x8e,
7256 0x45, 0xce, 0xf8, 0xb0, 0x9e, 0x5c, 0x33, 0x82,
7257 0xb0, 0x44, 0x56, 0xfc, 0x05, 0x09, 0xe9, 0x2a,
7258 0xac, 0x26, 0x80, 0x14, 0x1d, 0xc8, 0x3a, 0x35,
7259 0x4c, 0x82, 0x97, 0xfd, 0x76, 0xb7, 0xa9, 0x0a,
7260 0x35, 0x58, 0x79, 0x8e, 0x0f, 0x66, 0xea, 0xaf,
7261 0x51, 0x6c, 0x09, 0xa9, 0x6e, 0x9b, 0xcb, 0x9a,
7262 0x31, 0x47, 0xa0, 0x2f, 0x7c, 0x71, 0xb4, 0x4a,
7263 0x11, 0xaa, 0x8c, 0x66, 0xc5, 0x64, 0xe6, 0x3a,
7264 0x54, 0xda, 0x24, 0x6a, 0xc4, 0x41, 0x65, 0x46,
7265 0x82, 0xa0, 0x0a, 0x0f, 0x5f, 0xfb, 0x25, 0xd0,
7266 0x2c, 0x91, 0xa7, 0xee, 0xc4, 0x81, 0x07, 0x86,
7267 0x75, 0x5e, 0x33, 0x69, 0x97, 0xe4, 0x2c, 0xa8,
7268 0x9d, 0x9f, 0x0b, 0x6a, 0xbe, 0xad, 0x98, 0xda,
7269 0x6d, 0x94, 0x41, 0xda, 0x2c, 0x1e, 0x89, 0xc4,
7270 0xc2, 0xaf, 0x1e, 0x00, 0x05, 0x0b, 0x83, 0x60,
7271 0xbd, 0x43, 0xea, 0x15, 0x23, 0x7f, 0xb9, 0xac,
7272 0xee, 0x4f, 0x2c, 0xaf, 0x2a, 0xf3, 0xdf, 0xd0,
7273 0xf3, 0x19, 0x31, 0xbb, 0x4a, 0x74, 0x84, 0x17,
7274 0x52, 0x32, 0x2c, 0x7d, 0x61, 0xe4, 0xcb, 0xeb,
7275 0x80, 0x38, 0x15, 0x52, 0xcb, 0x6f, 0xea, 0xe5,
7276 0x73, 0x9c, 0xd9, 0x24, 0x69, 0xc6, 0x95, 0x32,
7277 0x21, 0xc8, 0x11, 0xe4, 0xdc, 0x36, 0xd7, 0x93,
7278 0x38, 0x66, 0xfb, 0xb2, 0x7f, 0x3a, 0xb9, 0xaf,
7279 0x31, 0xdd, 0x93, 0x75, 0x78, 0x8a, 0x2c, 0x94,
7280 0x87, 0x1a, 0x58, 0xec, 0x9e, 0x7d, 0x4d, 0xba,
7281 0xe1, 0xe5, 0x4d, 0xfc, 0xbc, 0xa4, 0x2a, 0x14,
7282 0xef, 0xcc, 0xa7, 0xec, 0xab, 0x43, 0x09, 0x18,
7283 0xd3, 0xab, 0x68, 0xd1, 0x07, 0x99, 0x44, 0x47,
7284 0xd6, 0x83, 0x85, 0x3b, 0x30, 0xea, 0xa9, 0x6b,
7285 0x63, 0xea, 0xc4, 0x07, 0xfb, 0x43, 0x2f, 0xa4,
7286 0xaa, 0xb0, 0xab, 0x03, 0x89, 0xce, 0x3f, 0x8c,
7287 0x02, 0x7c, 0x86, 0x54, 0xbc, 0x88, 0xaf, 0x75,
7288 0xd2, 0xdc, 0x63, 0x17, 0xd3, 0x26, 0xf6, 0x96,
7289 0xa9, 0x3c, 0xf1, 0x61, 0x8c, 0x11, 0x18, 0xcc,
7290 0xd6, 0xea, 0x5b, 0xe2, 0xcd, 0xf0, 0xf1, 0xb2,
7291 0xe5, 0x35, 0x90, 0x1f, 0x85, 0x4c, 0x76, 0x5b,
7292 0x66, 0xce, 0x44, 0xa4, 0x32, 0x9f, 0xe6, 0x7b,
7293 0x71, 0x6e, 0x9f, 0x58, 0x15, 0x67, 0x72, 0x87,
7294 0x64, 0x8e, 0x3a, 0x44, 0x45, 0xd4, 0x76, 0xfa,
7295 0xc2, 0xf6, 0xef, 0x85, 0x05, 0x18, 0x7a, 0x9b,
7296 0xba, 0x41, 0x54, 0xac, 0xf0, 0xfc, 0x59, 0x12,
7297 0x3f, 0xdf, 0xa0, 0xe5, 0x8a, 0x65, 0xfd, 0x3a,
7298 0x62, 0x8d, 0x83, 0x2c, 0x03, 0xbe, 0x05, 0x76,
7299 0x2e, 0x53, 0x49, 0x97, 0x94, 0x33, 0xae, 0x40,
7300 0x81, 0x15, 0xdb, 0x6e, 0xad, 0xaa, 0xf5, 0x4b,
7301 0xe3, 0x98, 0x70, 0xdf, 0xe0, 0x7c, 0xcd, 0xdb,
7302 0x02, 0xd4, 0x7d, 0x2f, 0xc1, 0xe6, 0xb4, 0xf3,
7303 0xd7, 0x0d, 0x7a, 0xd9, 0x23, 0x9e, 0x87, 0x2d,
7304 0xce, 0x87, 0xad, 0xcc, 0x72, 0x05, 0x00, 0x29,
7305 0xdc, 0x73, 0x7f, 0x64, 0xc1, 0x15, 0x0e, 0xc2,
7306 0xdf, 0xa7, 0x5f, 0xeb, 0x41, 0xa1, 0xcd, 0xef,
7307 0x5c, 0x50, 0x79, 0x2a, 0x56, 0x56, 0x71, 0x8c,
7308 0xac, 0xc0, 0x79, 0x50, 0x69, 0xca, 0x59, 0x32,
7309 0x65, 0xf2, 0x54, 0xe4, 0x52, 0x38, 0x76, 0xd1,
7310 0x5e, 0xde, 0x26, 0x9e, 0xfb, 0x75, 0x2e, 0x11,
7311 0xb5, 0x10, 0xf4, 0x17, 0x73, 0xf5, 0x89, 0xc7,
7312 0x4f, 0x43, 0x5c, 0x8e, 0x7c, 0xb9, 0x05, 0x52,
7313 0x24, 0x40, 0x99, 0xfe, 0x9b, 0x85, 0x0b, 0x6c,
7314 0x22, 0x3e, 0x8b, 0xae, 0x86, 0xa1, 0xd2, 0x79,
7315 0x05, 0x68, 0x6b, 0xab, 0xe3, 0x41, 0x49, 0xed,
7316 0x15, 0xa1, 0x8d, 0x40, 0x2d, 0x61, 0xdf, 0x1a,
7317 0x59, 0xc9, 0x26, 0x8b, 0xef, 0x30, 0x4c, 0x88,
7318 0x4b, 0x10, 0xf8, 0x8d, 0xa6, 0x92, 0x9f, 0x4b,
7319 0xf3, 0xc4, 0x53, 0x0b, 0x89, 0x5d, 0x28, 0x92,
7320 0xcf, 0x78, 0xb2, 0xc0, 0x5d, 0xed, 0x7e, 0xfc,
7321 0xc0, 0x12, 0x23, 0x5f, 0x5a, 0x78, 0x86, 0x43,
7322 0x6e, 0x27, 0xf7, 0x5a, 0xa7, 0x6a, 0xed, 0x19,
7323 0x04, 0xf0, 0xb3, 0x12, 0xd1, 0xbd, 0x0e, 0x89,
7324 0x6e, 0xbc, 0x96, 0xa8, 0xd8, 0x49, 0x39, 0x9f,
7325 0x7e, 0x67, 0xf0, 0x2e, 0x3e, 0x01, 0xa9, 0xba,
7326 0xec, 0x8b, 0x62, 0x8e, 0xcb, 0x4a, 0x70, 0x43,
7327 0xc7, 0xc2, 0xc4, 0xca, 0x82, 0x03, 0x73, 0xe9,
7328 0x11, 0xdf, 0xcf, 0x54, 0xea, 0xc9, 0xb0, 0x95,
7329 0x51, 0xc0, 0x13, 0x3d, 0x92, 0x05, 0xfa, 0xf4,
7330 0xa9, 0x34, 0xc8, 0xce, 0x6c, 0x3d, 0x54, 0xcc,
7331 0xc4, 0xaf, 0xf1, 0xdc, 0x11, 0x44, 0x26, 0xa2,
7332 0xaf, 0xf1, 0x85, 0x75, 0x7d, 0x03, 0x61, 0x68,
7333 0x4e, 0x78, 0xc6, 0x92, 0x7d, 0x86, 0x7d, 0x77,
7334 0xdc, 0x71, 0x72, 0xdb, 0xc6, 0xae, 0xa1, 0xcb,
7335 0x70, 0x9a, 0x0b, 0x19, 0xbe, 0x4a, 0x6c, 0x2a,
7336 0xe2, 0xba, 0x6c, 0x64, 0x9a, 0x13, 0x28, 0xdf,
7337 0x85, 0x75, 0xe6, 0x43, 0xf6, 0x87, 0x08, 0x68,
7338 0x6e, 0xba, 0x6e, 0x79, 0x9f, 0x04, 0xbc, 0x23,
7339 0x50, 0xf6, 0x33, 0x5c, 0x1f, 0x24, 0x25, 0xbe,
7340 0x33, 0x47, 0x80, 0x45, 0x56, 0xa3, 0xa7, 0xd7,
7341 0x7a, 0xb1, 0x34, 0x0b, 0x90, 0x3c, 0x9c, 0xad,
7342 0x44, 0x5f, 0x9e, 0x0e, 0x9d, 0xd4, 0xbd, 0x93,
7343 0x5e, 0xfa, 0x3c, 0xe0, 0xb0, 0xd9, 0xed, 0xf3,
7344 0xd6, 0x2e, 0xff, 0x24, 0xd8, 0x71, 0x6c, 0xed,
7345 0xaf, 0x55, 0xeb, 0x22, 0xac, 0x93, 0x68, 0x32,
7346 0x05, 0x5b, 0x47, 0xdd, 0xc6, 0x4a, 0xcb, 0xc7,
7347 0x10, 0xe1, 0x3c, 0x92, 0x1a, 0xf3, 0x23, 0x78,
7348 0x2b, 0xa1, 0xd2, 0x80, 0xf4, 0x12, 0xb1, 0x20,
7349 0x8f, 0xff, 0x26, 0x35, 0xdd, 0xfb, 0xc7, 0x4e,
7350 0x78, 0xf1, 0x2d, 0x50, 0x12, 0x77, 0xa8, 0x60,
7351 0x7c, 0x0f, 0xf5, 0x16, 0x2f, 0x63, 0x70, 0x2a,
7352 0xc0, 0x96, 0x80, 0x4e, 0x0a, 0xb4, 0x93, 0x35,
7353 0x5d, 0x1d, 0x3f, 0x56, 0xf7, 0x2f, 0xbb, 0x90,
7354 0x11, 0x16, 0x8f, 0xa2, 0xec, 0x47, 0xbe, 0xac,
7355 0x56, 0x01, 0x26, 0x56, 0xb1, 0x8c, 0xb2, 0x10,
7356 0xf9, 0x1a, 0xca, 0xf5, 0xd1, 0xb7, 0x39, 0x20,
7357 0x63, 0xf1, 0x69, 0x20, 0x4f, 0x13, 0x12, 0x1f,
7358 0x5b, 0x65, 0xfc, 0x98, 0xf7, 0xc4, 0x7a, 0xbe,
7359 0xf7, 0x26, 0x4d, 0x2b, 0x84, 0x7b, 0x42, 0xad,
7360 0xd8, 0x7a, 0x0a, 0xb4, 0xd8, 0x74, 0xbf, 0xc1,
7361 0xf0, 0x6e, 0xb4, 0x29, 0xa3, 0xbb, 0xca, 0x46,
7362 0x67, 0x70, 0x6a, 0x2d, 0xce, 0x0e, 0xa2, 0x8a,
7363 0xa9, 0x87, 0xbf, 0x05, 0xc4, 0xc1, 0x04, 0xa3,
7364 0xab, 0xd4, 0x45, 0x43, 0x8c, 0xb6, 0x02, 0xb0,
7365 0x41, 0xc8, 0xfc, 0x44, 0x3d, 0x59, 0xaa, 0x2e,
7366 0x44, 0x21, 0x2a, 0x8d, 0x88, 0x9d, 0x57, 0xf4,
7367 0xa0, 0x02, 0x77, 0xb8, 0xa6, 0xa0, 0xe6, 0x75,
7368 0x5c, 0x82, 0x65, 0x3e, 0x03, 0x5c, 0x29, 0x8f,
7369 0x38, 0x55, 0xab, 0x33, 0x26, 0xef, 0x9f, 0x43,
7370 0x52, 0xfd, 0x68, 0xaf, 0x36, 0xb4, 0xbb, 0x9a,
7371 0x58, 0x09, 0x09, 0x1b, 0xc3, 0x65, 0x46, 0x46,
7372 0x1d, 0xa7, 0x94, 0x18, 0x23, 0x50, 0x2c, 0xca,
7373 0x2c, 0x55, 0x19, 0x97, 0x01, 0x9d, 0x93, 0x3b,
7374 0x63, 0x86, 0xf2, 0x03, 0x67, 0x45, 0xd2, 0x72,
7375 0x28, 0x52, 0x6c, 0xf4, 0xe3, 0x1c, 0xb5, 0x11,
7376 0x13, 0xf1, 0xeb, 0x21, 0xc7, 0xd9, 0x56, 0x82,
7377 0x2b, 0x82, 0x39, 0xbd, 0x69, 0x54, 0xed, 0x62,
7378 0xc3, 0xe2, 0xde, 0x73, 0xd4, 0x6a, 0x12, 0xae,
7379 0x13, 0x21, 0x7f, 0x4b, 0x5b, 0xfc, 0xbf, 0xe8,
7380 0x2b, 0xbe, 0x56, 0xba, 0x68, 0x8b, 0x9a, 0xb1,
7381 0x6e, 0xfa, 0xbf, 0x7e, 0x5a, 0x4b, 0xf1, 0xac,
7382 0x98, 0x65, 0x85, 0xd1, 0x93, 0x53, 0xd3, 0x7b,
7383 0x09, 0xdd, 0x4b, 0x10, 0x6d, 0x84, 0xb0, 0x13,
7384 0x65, 0xbd, 0xcf, 0x52, 0x09, 0xc4, 0x85, 0xe2,
7385 0x84, 0x74, 0x15, 0x65, 0xb7, 0xf7, 0x51, 0xaf,
7386 0x55, 0xad, 0xa4, 0xd1, 0x22, 0x54, 0x70, 0x94,
7387 0xa0, 0x1c, 0x90, 0x41, 0xfd, 0x99, 0xd7, 0x5a,
7388 0x31, 0xef, 0xaa, 0x25, 0xd0, 0x7f, 0x4f, 0xea,
7389 0x1d, 0x55, 0x42, 0xe5, 0x49, 0xb0, 0xd0, 0x46,
7390 0x62, 0x36, 0x43, 0xb2, 0x82, 0x15, 0x75, 0x50,
7391 0xa4, 0x72, 0xeb, 0x54, 0x27, 0x1f, 0x8a, 0xe4,
7392 0x7d, 0xe9, 0x66, 0xc5, 0xf1, 0x53, 0xa4, 0xd1,
7393 0x0c, 0xeb, 0xb8, 0xf8, 0xbc, 0xd4, 0xe2, 0xe7,
7394 0xe1, 0xf8, 0x4b, 0xcb, 0xa9, 0xa1, 0xaf, 0x15,
7395 0x83, 0xcb, 0x72, 0xd0, 0x33, 0x79, 0x00, 0x2d,
7396 0x9f, 0xd7, 0xf1, 0x2e, 0x1e, 0x10, 0xe4, 0x45,
7397 0xc0, 0x75, 0x3a, 0x39, 0xea, 0x68, 0xf7, 0x5d,
7398 0x1b, 0x73, 0x8f, 0xe9, 0x8e, 0x0f, 0x72, 0x47,
7399 0xae, 0x35, 0x0a, 0x31, 0x7a, 0x14, 0x4d, 0x4a,
7400 0x6f, 0x47, 0xf7, 0x7e, 0x91, 0x6e, 0x74, 0x8b,
7401 0x26, 0x47, 0xf9, 0xc3, 0xf9, 0xde, 0x70, 0xf5,
7402 0x61, 0xab, 0xa9, 0x27, 0x9f, 0x82, 0xe4, 0x9c,
7403 0x89, 0x91, 0x3f, 0x2e, 0x6a, 0xfd, 0xb5, 0x49,
7404 0xe9, 0xfd, 0x59, 0x14, 0x36, 0x49, 0x40, 0x6d,
7405 0x32, 0xd8, 0x85, 0x42, 0xf3, 0xa5, 0xdf, 0x0c,
7406 0xa8, 0x27, 0xd7, 0x54, 0xe2, 0x63, 0x2f, 0xf2,
7407 0x7e, 0x8b, 0x8b, 0xe7, 0xf1, 0x9a, 0x95, 0x35,
7408 0x43, 0xdc, 0x3a, 0xe4, 0xb6, 0xf4, 0xd0, 0xdf,
7409 0x9c, 0xcb, 0x94, 0xf3, 0x21, 0xa0, 0x77, 0x50,
7410 0xe2, 0xc6, 0xc4, 0xc6, 0x5f, 0x09, 0x64, 0x5b,
7411 0x92, 0x90, 0xd8, 0xe1, 0xd1, 0xed, 0x4b, 0x42,
7412 0xd7, 0x37, 0xaf, 0x65, 0x3d, 0x11, 0x39, 0xb6,
7413 0x24, 0x8a, 0x60, 0xae, 0xd6, 0x1e, 0xbf, 0x0e,
7414 0x0d, 0xd7, 0xdc, 0x96, 0x0e, 0x65, 0x75, 0x4e,
7415 0x29, 0x06, 0x9d, 0xa4, 0x51, 0x3a, 0x10, 0x63,
7416 0x8f, 0x17, 0x07, 0xd5, 0x8e, 0x3c, 0xf4, 0x28,
7417 0x00, 0x5a, 0x5b, 0x05, 0x19, 0xd8, 0xc0, 0x6c,
7418 0xe5, 0x15, 0xe4, 0x9c, 0x9d, 0x71, 0x9d, 0x5e,
7419 0x94, 0x29, 0x1a, 0xa7, 0x80, 0xfa, 0x0e, 0x33,
7420 0x03, 0xdd, 0xb7, 0x3e, 0x9a, 0xa9, 0x26, 0x18,
7421 0x37, 0xa9, 0x64, 0x08, 0x4d, 0x94, 0x5a, 0x88,
7422 0xca, 0x35, 0xce, 0x81, 0x02, 0xe3, 0x1f, 0x1b,
7423 0x89, 0x1a, 0x77, 0x85, 0xe3, 0x41, 0x6d, 0x32,
7424 0x42, 0x19, 0x23, 0x7d, 0xc8, 0x73, 0xee, 0x25,
7425 0x85, 0x0d, 0xf8, 0x31, 0x25, 0x79, 0x1b, 0x6f,
7426 0x79, 0x25, 0xd2, 0xd8, 0xd4, 0x23, 0xfd, 0xf7,
7427 0x82, 0x36, 0x6a, 0x0c, 0x46, 0x22, 0x15, 0xe9,
7428 0xff, 0x72, 0x41, 0x91, 0x91, 0x7d, 0x3a, 0xb7,
7429 0xdd, 0x65, 0x99, 0x70, 0xf6, 0x8d, 0x84, 0xf8,
7430 0x67, 0x15, 0x20, 0x11, 0xd6, 0xb2, 0x55, 0x7b,
7431 0xdb, 0x87, 0xee, 0xef, 0x55, 0x89, 0x2a, 0x59,
7432 0x2b, 0x07, 0x8f, 0x43, 0x8a, 0x59, 0x3c, 0x01,
7433 0x8b, 0x65, 0x54, 0xa1, 0x66, 0xd5, 0x38, 0xbd,
7434 0xc6, 0x30, 0xa9, 0xcc, 0x49, 0xb6, 0xa8, 0x1b,
7435 0xb8, 0xc0, 0x0e, 0xe3, 0x45, 0x28, 0xe2, 0xff,
7436 0x41, 0x9f, 0x7e, 0x7c, 0xd1, 0xae, 0x9e, 0x25,
7437 0x3f, 0x4c, 0x7c, 0x7c, 0xf4, 0xa8, 0x26, 0x4d,
7438 0x5c, 0xfd, 0x4b, 0x27, 0x18, 0xf9, 0x61, 0x76,
7439 0x48, 0xba, 0x0c, 0x6b, 0xa9, 0x4d, 0xfc, 0xf5,
7440 0x3b, 0x35, 0x7e, 0x2f, 0x4a, 0xa9, 0xc2, 0x9a,
7441 0xae, 0xab, 0x86, 0x09, 0x89, 0xc9, 0xc2, 0x40,
7442 0x39, 0x2c, 0x81, 0xb3, 0xb8, 0x17, 0x67, 0xc2,
7443 0x0d, 0x32, 0x4a, 0x3a, 0x67, 0x81, 0xd7, 0x1a,
7444 0x34, 0x52, 0xc5, 0xdb, 0x0a, 0xf5, 0x63, 0x39,
7445 0xea, 0x1f, 0xe1, 0x7c, 0xa1, 0x9e, 0xc1, 0x35,
7446 0xe3, 0xb1, 0x18, 0x45, 0x67, 0xf9, 0x22, 0x38,
7447 0x95, 0xd9, 0x34, 0x34, 0x86, 0xc6, 0x41, 0x94,
7448 0x15, 0xf9, 0x5b, 0x41, 0xa6, 0x87, 0x8b, 0xf8,
7449 0xd5, 0xe1, 0x1b, 0xe2, 0x5b, 0xf3, 0x86, 0x10,
7450 0xff, 0xe6, 0xae, 0x69, 0x76, 0xbc, 0x0d, 0xb4,
7451 0x09, 0x90, 0x0c, 0xa2, 0x65, 0x0c, 0xad, 0x74,
7452 0xf5, 0xd7, 0xff, 0xda, 0xc1, 0xce, 0x85, 0xbe,
7453 0x00, 0xa7, 0xff, 0x4d, 0x2f, 0x65, 0xd3, 0x8c,
7454 0x86, 0x2d, 0x05, 0xe8, 0xed, 0x3e, 0x6b, 0x8b,
7455 0x0f, 0x3d, 0x83, 0x8c, 0xf1, 0x1d, 0x5b, 0x96,
7456 0x2e, 0xb1, 0x9c, 0xc2, 0x98, 0xe1, 0x70, 0xb9,
7457 0xba, 0x5c, 0x8a, 0x43, 0xd6, 0x34, 0xa7, 0x2d,
7458 0xc9, 0x92, 0xae, 0xf2, 0xa5, 0x7b, 0x05, 0x49,
7459 0xa7, 0x33, 0x34, 0x86, 0xca, 0xe4, 0x96, 0x23,
7460 0x76, 0x5b, 0xf2, 0xc6, 0xf1, 0x51, 0x28, 0x42,
7461 0x7b, 0xcc, 0x76, 0x8f, 0xfa, 0xa2, 0xad, 0x31,
7462 0xd4, 0xd6, 0x7a, 0x6d, 0x25, 0x25, 0x54, 0xe4,
7463 0x3f, 0x50, 0x59, 0xe1, 0x5c, 0x05, 0xb7, 0x27,
7464 0x48, 0xbf, 0x07, 0xec, 0x1b, 0x13, 0xbe, 0x2b,
7465 0xa1, 0x57, 0x2b, 0xd5, 0xab, 0xd7, 0xd0, 0x4c,
7466 0x1e, 0xcb, 0x71, 0x9b, 0xc5, 0x90, 0x85, 0xd3,
7467 0xde, 0x59, 0xec, 0x71, 0xeb, 0x89, 0xbb, 0xd0,
7468 0x09, 0x50, 0xe1, 0x16, 0x3f, 0xfd, 0x1c, 0x34,
7469 0xc3, 0x1c, 0xa1, 0x10, 0x77, 0x53, 0x98, 0xef,
7470 0xf2, 0xfd, 0xa5, 0x01, 0x59, 0xc2, 0x9b, 0x26,
7471 0xc7, 0x42, 0xd9, 0x49, 0xda, 0x58, 0x2b, 0x6e,
7472 0x9f, 0x53, 0x19, 0x76, 0x7e, 0xd9, 0xc9, 0x0e,
7473 0x68, 0xc8, 0x7f, 0x51, 0x22, 0x42, 0xef, 0x49,
7474 0xa4, 0x55, 0xb6, 0x36, 0xac, 0x09, 0xc7, 0x31,
7475 0x88, 0x15, 0x4b, 0x2e, 0x8f, 0x3a, 0x08, 0xf7,
7476 0xd8, 0xf7, 0xa8, 0xc5, 0xa9, 0x33, 0xa6, 0x45,
7477 0xe4, 0xc4, 0x94, 0x76, 0xf3, 0x0d, 0x8f, 0x7e,
7478 0xc8, 0xf6, 0xbc, 0x23, 0x0a, 0xb6, 0x4c, 0xd3,
7479 0x6a, 0xcd, 0x36, 0xc2, 0x90, 0x5c, 0x5c, 0x3c,
7480 0x65, 0x7b, 0xc2, 0xd6, 0xcc, 0xe6, 0x0d, 0x87,
7481 0x73, 0x2e, 0x71, 0x79, 0x16, 0x06, 0x63, 0x28,
7482 0x09, 0x15, 0xd8, 0x89, 0x38, 0x38, 0x3d, 0xb5,
7483 0x42, 0x1c, 0x08, 0x24, 0xf7, 0x2a, 0xd2, 0x9d,
7484 0xc8, 0xca, 0xef, 0xf9, 0x27, 0xd8, 0x07, 0x86,
7485 0xf7, 0x43, 0x0b, 0x55, 0x15, 0x3f, 0x9f, 0x83,
7486 0xef, 0xdc, 0x49, 0x9d, 0x2a, 0xc1, 0x54, 0x62,
7487 0xbd, 0x9b, 0x66, 0x55, 0x9f, 0xb7, 0x12, 0xf3,
7488 0x1b, 0x4d, 0x9d, 0x2a, 0x5c, 0xed, 0x87, 0x75,
7489 0x87, 0x26, 0xec, 0x61, 0x2c, 0xb4, 0x0f, 0x89,
7490 0xb0, 0xfb, 0x2e, 0x68, 0x5d, 0x15, 0xc7, 0x8d,
7491 0x2e, 0xc0, 0xd9, 0xec, 0xaf, 0x4f, 0xd2, 0x25,
7492 0x29, 0xe8, 0xd2, 0x26, 0x2b, 0x67, 0xe9, 0xfc,
7493 0x2b, 0xa8, 0x67, 0x96, 0x12, 0x1f, 0x5b, 0x96,
7494 0xc6, 0x14, 0x53, 0xaf, 0x44, 0xea, 0xd6, 0xe2,
7495 0x94, 0x98, 0xe4, 0x12, 0x93, 0x4c, 0x92, 0xe0,
7496 0x18, 0xa5, 0x8d, 0x2d, 0xe4, 0x71, 0x3c, 0x47,
7497 0x4c, 0xf7, 0xe6, 0x47, 0x9e, 0xc0, 0x68, 0xdf,
7498 0xd4, 0xf5, 0x5a, 0x74, 0xb1, 0x2b, 0x29, 0x03,
7499 0x19, 0x07, 0xaf, 0x90, 0x62, 0x5c, 0x68, 0x98,
7500 0x48, 0x16, 0x11, 0x02, 0x9d, 0xee, 0xb4, 0x9b,
7501 0xe5, 0x42, 0x7f, 0x08, 0xfd, 0x16, 0x32, 0x0b,
7502 0xd0, 0xb3, 0xfa, 0x2b, 0xb7, 0x99, 0xf9, 0x29,
7503 0xcd, 0x20, 0x45, 0x9f, 0xb3, 0x1a, 0x5d, 0xa2,
7504 0xaf, 0x4d, 0xe0, 0xbd, 0x42, 0x0d, 0xbc, 0x74,
7505 0x99, 0x9c, 0x8e, 0x53, 0x1a, 0xb4, 0x3e, 0xbd,
7506 0xa2, 0x9a, 0x2d, 0xf7, 0xf8, 0x39, 0x0f, 0x67,
7507 0x63, 0xfc, 0x6b, 0xc0, 0xaf, 0xb3, 0x4b, 0x4f,
7508 0x55, 0xc4, 0xcf, 0xa7, 0xc8, 0x04, 0x11, 0x3e,
7509 0x14, 0x32, 0xbb, 0x1b, 0x38, 0x77, 0xd6, 0x7f,
7510 0x54, 0x4c, 0xdf, 0x75, 0xf3, 0x07, 0x2d, 0x33,
7511 0x9b, 0xa8, 0x20, 0xe1, 0x7b, 0x12, 0xb5, 0xf3,
7512 0xef, 0x2f, 0xce, 0x72, 0xe5, 0x24, 0x60, 0xc1,
7513 0x30, 0xe2, 0xab, 0xa1, 0x8e, 0x11, 0x09, 0xa8,
7514 0x21, 0x33, 0x44, 0xfe, 0x7f, 0x35, 0x32, 0x93,
7515 0x39, 0xa7, 0xad, 0x8b, 0x79, 0x06, 0xb2, 0xcb,
7516 0x4e, 0xa9, 0x5f, 0xc7, 0xba, 0x74, 0x29, 0xec,
7517 0x93, 0xa0, 0x4e, 0x54, 0x93, 0xc0, 0xbc, 0x55,
7518 0x64, 0xf0, 0x48, 0xe5, 0x57, 0x99, 0xee, 0x75,
7519 0xd6, 0x79, 0x0f, 0x66, 0xb7, 0xc6, 0x57, 0x76,
7520 0xf7, 0xb7, 0xf3, 0x9c, 0xc5, 0x60, 0xe8, 0x7f,
7521 0x83, 0x76, 0xd6, 0x0e, 0xaa, 0xe6, 0x90, 0x39,
7522 0x1d, 0xa6, 0x32, 0x6a, 0x34, 0xe3, 0x55, 0xf8,
7523 0x58, 0xa0, 0x58, 0x7d, 0x33, 0xe0, 0x22, 0x39,
7524 0x44, 0x64, 0x87, 0x86, 0x5a, 0x2f, 0xa7, 0x7e,
7525 0x0f, 0x38, 0xea, 0xb0, 0x30, 0xcc, 0x61, 0xa5,
7526 0x6a, 0x32, 0xae, 0x1e, 0xf7, 0xe9, 0xd0, 0xa9,
7527 0x0c, 0x32, 0x4b, 0xb5, 0x49, 0x28, 0xab, 0x85,
7528 0x2f, 0x8e, 0x01, 0x36, 0x38, 0x52, 0xd0, 0xba,
7529 0xd6, 0x02, 0x78, 0xf8, 0x0e, 0x3e, 0x9c, 0x8b,
7530 0x6b, 0x45, 0x99, 0x3f, 0x5c, 0xfe, 0x58, 0xf1,
7531 0x5c, 0x94, 0x04, 0xe1, 0xf5, 0x18, 0x6d, 0x51,
7532 0xb2, 0x5d, 0x18, 0x20, 0xb6, 0xc2, 0x9a, 0x42,
7533 0x1d, 0xb3, 0xab, 0x3c, 0xb6, 0x3a, 0x13, 0x03,
7534 0xb2, 0x46, 0x82, 0x4f, 0xfc, 0x64, 0xbc, 0x4f,
7535 0xca, 0xfa, 0x9c, 0xc0, 0xd5, 0xa7, 0xbd, 0x11,
7536 0xb7, 0xe4, 0x5a, 0xf6, 0x6f, 0x4d, 0x4d, 0x54,
7537 0xea, 0xa4, 0x98, 0x66, 0xd4, 0x22, 0x3b, 0xd3,
7538 0x8f, 0x34, 0x47, 0xd9, 0x7c, 0xf4, 0x72, 0x3b,
7539 0x4d, 0x02, 0x77, 0xf6, 0xd6, 0xdd, 0x08, 0x0a,
7540 0x81, 0xe1, 0x86, 0x89, 0x3e, 0x56, 0x10, 0x3c,
7541 0xba, 0xd7, 0x81, 0x8c, 0x08, 0xbc, 0x8b, 0xe2,
7542 0x53, 0xec, 0xa7, 0x89, 0xee, 0xc8, 0x56, 0xb5,
7543 0x36, 0x2c, 0xb2, 0x03, 0xba, 0x99, 0xdd, 0x7c,
7544 0x48, 0xa0, 0xb0, 0xbc, 0x91, 0x33, 0xe9, 0xa8,
7545 0xcb, 0xcd, 0xcf, 0x59, 0x5f, 0x1f, 0x15, 0xe2,
7546 0x56, 0xf5, 0x4e, 0x01, 0x35, 0x27, 0x45, 0x77,
7547 0x47, 0xc8, 0xbc, 0xcb, 0x7e, 0x39, 0xc1, 0x97,
7548 0x28, 0xd3, 0x84, 0xfc, 0x2c, 0x3e, 0xc8, 0xad,
7549 0x9c, 0xf8, 0x8a, 0x61, 0x9c, 0x28, 0xaa, 0xc5,
7550 0x99, 0x20, 0x43, 0x85, 0x9d, 0xa5, 0xe2, 0x8b,
7551 0xb8, 0xae, 0xeb, 0xd0, 0x32, 0x0d, 0x52, 0x78,
7552 0x09, 0x56, 0x3f, 0xc7, 0xd8, 0x7e, 0x26, 0xfc,
7553 0x37, 0xfb, 0x6f, 0x04, 0xfc, 0xfa, 0x92, 0x10,
7554 0xac, 0xf8, 0x3e, 0x21, 0xdc, 0x8c, 0x21, 0x16,
7555 0x7d, 0x67, 0x6e, 0xf6, 0xcd, 0xda, 0xb6, 0x98,
7556 0x23, 0xab, 0x23, 0x3c, 0xb2, 0x10, 0xa0, 0x53,
7557 0x5a, 0x56, 0x9f, 0xc5, 0xd0, 0xff, 0xbb, 0xe4,
7558 0x98, 0x3c, 0x69, 0x1e, 0xdb, 0x38, 0x8f, 0x7e,
7559 0x0f, 0xd2, 0x98, 0x88, 0x81, 0x8b, 0x45, 0x67,
7560 0xea, 0x33, 0xf1, 0xeb, 0xe9, 0x97, 0x55, 0x2e,
7561 0xd9, 0xaa, 0xeb, 0x5a, 0xec, 0xda, 0xe1, 0x68,
7562 0xa8, 0x9d, 0x3c, 0x84, 0x7c, 0x05, 0x3d, 0x62,
7563 0x87, 0x8f, 0x03, 0x21, 0x28, 0x95, 0x0c, 0x89,
7564 0x25, 0x22, 0x4a, 0xb0, 0x93, 0xa9, 0x50, 0xa2,
7565 0x2f, 0x57, 0x6e, 0x18, 0x42, 0x19, 0x54, 0x0c,
7566 0x55, 0x67, 0xc6, 0x11, 0x49, 0xf4, 0x5c, 0xd2,
7567 0xe9, 0x3d, 0xdd, 0x8b, 0x48, 0x71, 0x21, 0x00,
7568 0xc3, 0x9a, 0x6c, 0x85, 0x74, 0x28, 0x83, 0x4a,
7569 0x1b, 0x31, 0x05, 0xe1, 0x06, 0x92, 0xe7, 0xda,
7570 0x85, 0x73, 0x78, 0x45, 0x20, 0x7f, 0xae, 0x13,
7571 0x7c, 0x33, 0x06, 0x22, 0xf4, 0x83, 0xf9, 0x35,
7572 0x3f, 0x6c, 0x71, 0xa8, 0x4e, 0x48, 0xbe, 0x9b,
7573 0xce, 0x8a, 0xba, 0xda, 0xbe, 0x28, 0x08, 0xf7,
7574 0xe2, 0x14, 0x8c, 0x71, 0xea, 0x72, 0xf9, 0x33,
7575 0xf2, 0x88, 0x3f, 0xd7, 0xbb, 0x69, 0x6c, 0x29,
7576 0x19, 0xdc, 0x84, 0xce, 0x1f, 0x12, 0x4f, 0xc8,
7577 0xaf, 0xa5, 0x04, 0xba, 0x5a, 0xab, 0xb0, 0xd9,
7578 0x14, 0x1f, 0x6c, 0x68, 0x98, 0x39, 0x89, 0x7a,
7579 0xd9, 0xd8, 0x2f, 0xdf, 0xa8, 0x47, 0x4a, 0x25,
7580 0xe2, 0xfb, 0x33, 0xf4, 0x59, 0x78, 0xe1, 0x68,
7581 0x85, 0xcf, 0xfe, 0x59, 0x20, 0xd4, 0x05, 0x1d,
7582 0x80, 0x99, 0xae, 0xbc, 0xca, 0xae, 0x0f, 0x2f,
7583 0x65, 0x43, 0x34, 0x8e, 0x7e, 0xac, 0xd3, 0x93,
7584 0x2f, 0xac, 0x6d, 0x14, 0x3d, 0x02, 0x07, 0x70,
7585 0x9d, 0xa4, 0xf3, 0x1b, 0x5c, 0x36, 0xfc, 0x01,
7586 0x73, 0x34, 0x85, 0x0c, 0x6c, 0xd6, 0xf1, 0xbd,
7587 0x3f, 0xdf, 0xee, 0xf5, 0xd9, 0xba, 0x56, 0xef,
7588 0xf4, 0x9b, 0x6b, 0xee, 0x9f, 0x5a, 0x78, 0x6d,
7589 0x32, 0x19, 0xf4, 0xf7, 0xf8, 0x4c, 0x69, 0x0b,
7590 0x4b, 0xbc, 0xbb, 0xb7, 0xf2, 0x85, 0xaf, 0x70,
7591 0x75, 0x24, 0x6c, 0x54, 0xa7, 0x0e, 0x4d, 0x1d,
7592 0x01, 0xbf, 0x08, 0xac, 0xcf, 0x7f, 0x2c, 0xe3,
7593 0x14, 0x89, 0x5e, 0x70, 0x5a, 0x99, 0x92, 0xcd,
7594 0x01, 0x84, 0xc8, 0xd2, 0xab, 0xe5, 0x4f, 0x58,
7595 0xe7, 0x0f, 0x2f, 0x0e, 0xff, 0x68, 0xea, 0xfd,
7596 0x15, 0xb3, 0x17, 0xe6, 0xb0, 0xe7, 0x85, 0xd8,
7597 0x23, 0x2e, 0x05, 0xc7, 0xc9, 0xc4, 0x46, 0x1f,
7598 0xe1, 0x9e, 0x49, 0x20, 0x23, 0x24, 0x4d, 0x7e,
7599 0x29, 0x65, 0xff, 0xf4, 0xb6, 0xfd, 0x1a, 0x85,
7600 0xc4, 0x16, 0xec, 0xfc, 0xea, 0x7b, 0xd6, 0x2c,
7601 0x43, 0xf8, 0xb7, 0xbf, 0x79, 0xc0, 0x85, 0xcd,
7602 0xef, 0xe1, 0x98, 0xd3, 0xa5, 0xf7, 0x90, 0x8c,
7603 0xe9, 0x7f, 0x80, 0x6b, 0xd2, 0xac, 0x4c, 0x30,
7604 0xa7, 0xc6, 0x61, 0x6c, 0xd2, 0xf9, 0x2c, 0xff,
7605 0x30, 0xbc, 0x22, 0x81, 0x7d, 0x93, 0x12, 0xe4,
7606 0x0a, 0xcd, 0xaf, 0xdd, 0xe8, 0xab, 0x0a, 0x1e,
7607 0x13, 0xa4, 0x27, 0xc3, 0x5f, 0xf7, 0x4b, 0xbb,
7608 0x37, 0x09, 0x4b, 0x91, 0x6f, 0x92, 0x4f, 0xaf,
7609 0x52, 0xee, 0xdf, 0xef, 0x09, 0x6f, 0xf7, 0x5c,
7610 0x6e, 0x12, 0x17, 0x72, 0x63, 0x57, 0xc7, 0xba,
7611 0x3b, 0x6b, 0x38, 0x32, 0x73, 0x1b, 0x9c, 0x80,
7612 0xc1, 0x7a, 0xc6, 0xcf, 0xcd, 0x35, 0xc0, 0x6b,
7613 0x31, 0x1a, 0x6b, 0xe9, 0xd8, 0x2c, 0x29, 0x3f,
7614 0x96, 0xfb, 0xb6, 0xcd, 0x13, 0x91, 0x3b, 0xc2,
7615 0xd2, 0xa3, 0x31, 0x8d, 0xa4, 0xcd, 0x57, 0xcd,
7616 0x13, 0x3d, 0x64, 0xfd, 0x06, 0xce, 0xe6, 0xdc,
7617 0x0c, 0x24, 0x43, 0x31, 0x40, 0x57, 0xf1, 0x72,
7618 0x17, 0xe3, 0x3a, 0x63, 0x6d, 0x35, 0xcf, 0x5d,
7619 0x97, 0x40, 0x59, 0xdd, 0xf7, 0x3c, 0x02, 0xf7,
7620 0x1c, 0x7e, 0x05, 0xbb, 0xa9, 0x0d, 0x01, 0xb1,
7621 0x8e, 0xc0, 0x30, 0xa9, 0x53, 0x24, 0xc9, 0x89,
7622 0x84, 0x6d, 0xaa, 0xd0, 0xcd, 0x91, 0xc2, 0x4d,
7623 0x91, 0xb0, 0x89, 0xe2, 0xbf, 0x83, 0x44, 0xaa,
7624 0x28, 0x72, 0x23, 0xa0, 0xc2, 0xad, 0xad, 0x1c,
7625 0xfc, 0x3f, 0x09, 0x7a, 0x0b, 0xdc, 0xc5, 0x1b,
7626 0x87, 0x13, 0xc6, 0x5b, 0x59, 0x8d, 0xf2, 0xc8,
7627 0xaf, 0xdf, 0x11, 0x95,
7628 },
7629 .rlen = 4100,
7630 },
7631};
7632
4320/* 7633/*
4321 * Compression stuff. 7634 * Compression stuff.
4322 */ 7635 */
@@ -4408,6 +7721,88 @@ static struct comp_testvec deflate_decomp_tv_template[] = {
4408}; 7721};
4409 7722
4410/* 7723/*
7724 * LZO test vectors (null-terminated strings).
7725 */
7726#define LZO_COMP_TEST_VECTORS 2
7727#define LZO_DECOMP_TEST_VECTORS 2
7728
7729static struct comp_testvec lzo_comp_tv_template[] = {
7730 {
7731 .inlen = 70,
7732 .outlen = 46,
7733 .input = "Join us now and share the software "
7734 "Join us now and share the software ",
7735 .output = { 0x00, 0x0d, 0x4a, 0x6f, 0x69, 0x6e, 0x20, 0x75,
7736 0x73, 0x20, 0x6e, 0x6f, 0x77, 0x20, 0x61, 0x6e,
7737 0x64, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20,
7738 0x74, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74,
7739 0x77, 0x70, 0x01, 0x01, 0x4a, 0x6f, 0x69, 0x6e,
7740 0x3d, 0x88, 0x00, 0x11, 0x00, 0x00 },
7741 }, {
7742 .inlen = 159,
7743 .outlen = 133,
7744 .input = "This document describes a compression method based on the LZO "
7745 "compression algorithm. This document defines the application of "
7746 "the LZO algorithm used in UBIFS.",
7747 .output = { 0x00, 0x2b, 0x54, 0x68, 0x69, 0x73, 0x20, 0x64,
7748 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20,
7749 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65,
7750 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x70,
7751 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20,
7752 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x20, 0x62,
7753 0x61, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20,
7754 0x74, 0x68, 0x65, 0x20, 0x4c, 0x5a, 0x4f, 0x2b,
7755 0x8c, 0x00, 0x0d, 0x61, 0x6c, 0x67, 0x6f, 0x72,
7756 0x69, 0x74, 0x68, 0x6d, 0x2e, 0x20, 0x20, 0x54,
7757 0x68, 0x69, 0x73, 0x2a, 0x54, 0x01, 0x02, 0x66,
7758 0x69, 0x6e, 0x65, 0x73, 0x94, 0x06, 0x05, 0x61,
7759 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x76,
7760 0x0a, 0x6f, 0x66, 0x88, 0x02, 0x60, 0x09, 0x27,
7761 0xf0, 0x00, 0x0c, 0x20, 0x75, 0x73, 0x65, 0x64,
7762 0x20, 0x69, 0x6e, 0x20, 0x55, 0x42, 0x49, 0x46,
7763 0x53, 0x2e, 0x11, 0x00, 0x00 },
7764 },
7765};
7766
7767static struct comp_testvec lzo_decomp_tv_template[] = {
7768 {
7769 .inlen = 133,
7770 .outlen = 159,
7771 .input = { 0x00, 0x2b, 0x54, 0x68, 0x69, 0x73, 0x20, 0x64,
7772 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20,
7773 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65,
7774 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x70,
7775 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20,
7776 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x20, 0x62,
7777 0x61, 0x73, 0x65, 0x64, 0x20, 0x6f, 0x6e, 0x20,
7778 0x74, 0x68, 0x65, 0x20, 0x4c, 0x5a, 0x4f, 0x2b,
7779 0x8c, 0x00, 0x0d, 0x61, 0x6c, 0x67, 0x6f, 0x72,
7780 0x69, 0x74, 0x68, 0x6d, 0x2e, 0x20, 0x20, 0x54,
7781 0x68, 0x69, 0x73, 0x2a, 0x54, 0x01, 0x02, 0x66,
7782 0x69, 0x6e, 0x65, 0x73, 0x94, 0x06, 0x05, 0x61,
7783 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x76,
7784 0x0a, 0x6f, 0x66, 0x88, 0x02, 0x60, 0x09, 0x27,
7785 0xf0, 0x00, 0x0c, 0x20, 0x75, 0x73, 0x65, 0x64,
7786 0x20, 0x69, 0x6e, 0x20, 0x55, 0x42, 0x49, 0x46,
7787 0x53, 0x2e, 0x11, 0x00, 0x00 },
7788 .output = "This document describes a compression method based on the LZO "
7789 "compression algorithm. This document defines the application of "
7790 "the LZO algorithm used in UBIFS.",
7791 }, {
7792 .inlen = 46,
7793 .outlen = 70,
7794 .input = { 0x00, 0x0d, 0x4a, 0x6f, 0x69, 0x6e, 0x20, 0x75,
7795 0x73, 0x20, 0x6e, 0x6f, 0x77, 0x20, 0x61, 0x6e,
7796 0x64, 0x20, 0x73, 0x68, 0x61, 0x72, 0x65, 0x20,
7797 0x74, 0x68, 0x65, 0x20, 0x73, 0x6f, 0x66, 0x74,
7798 0x77, 0x70, 0x01, 0x01, 0x4a, 0x6f, 0x69, 0x6e,
7799 0x3d, 0x88, 0x00, 0x11, 0x00, 0x00 },
7800 .output = "Join us now and share the software "
7801 "Join us now and share the software ",
7802 },
7803};
7804
7805/*
4411 * Michael MIC test vectors from IEEE 802.11i 7806 * Michael MIC test vectors from IEEE 802.11i
4412 */ 7807 */
4413#define MICHAEL_MIC_TEST_VECTORS 6 7808#define MICHAEL_MIC_TEST_VECTORS 6
@@ -4812,4 +8207,20 @@ static struct cipher_speed camellia_speed_template[] = {
4812 { .klen = 0, .blen = 0, } 8207 { .klen = 0, .blen = 0, }
4813}; 8208};
4814 8209
8210static struct cipher_speed salsa20_speed_template[] = {
8211 { .klen = 16, .blen = 16, },
8212 { .klen = 16, .blen = 64, },
8213 { .klen = 16, .blen = 256, },
8214 { .klen = 16, .blen = 1024, },
8215 { .klen = 16, .blen = 8192, },
8216 { .klen = 32, .blen = 16, },
8217 { .klen = 32, .blen = 64, },
8218 { .klen = 32, .blen = 256, },
8219 { .klen = 32, .blen = 1024, },
8220 { .klen = 32, .blen = 8192, },
8221
8222 /* End marker */
8223 { .klen = 0, .blen = 0, }
8224};
8225
4815#endif /* _CRYPTO_TCRYPT_H */ 8226#endif /* _CRYPTO_TCRYPT_H */
diff --git a/crypto/twofish_common.c b/crypto/twofish_common.c
index b4b9c0c3f4ae..0af216c75d7e 100644
--- a/crypto/twofish_common.c
+++ b/crypto/twofish_common.c
@@ -655,84 +655,48 @@ int twofish_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int key_len)
655 CALC_SB256_2( i, calc_sb_tbl[j], calc_sb_tbl[k] ); 655 CALC_SB256_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
656 } 656 }
657 657
658 /* Calculate whitening and round subkeys. The constants are 658 /* CALC_K256/CALC_K192/CALC_K loops were unrolled.
659 * indices of subkeys, preprocessed through q0 and q1. */ 659 * Unrolling produced x2.5 more code (+18k on i386),
660 CALC_K256 (w, 0, 0xA9, 0x75, 0x67, 0xF3); 660 * and speeded up key setup by 7%:
661 CALC_K256 (w, 2, 0xB3, 0xC6, 0xE8, 0xF4); 661 * unrolled: twofish_setkey/sec: 41128
662 CALC_K256 (w, 4, 0x04, 0xDB, 0xFD, 0x7B); 662 * loop: twofish_setkey/sec: 38148
663 CALC_K256 (w, 6, 0xA3, 0xFB, 0x76, 0xC8); 663 * CALC_K256: ~100 insns each
664 CALC_K256 (k, 0, 0x9A, 0x4A, 0x92, 0xD3); 664 * CALC_K192: ~90 insns
665 CALC_K256 (k, 2, 0x80, 0xE6, 0x78, 0x6B); 665 * CALC_K: ~70 insns
666 CALC_K256 (k, 4, 0xE4, 0x45, 0xDD, 0x7D); 666 */
667 CALC_K256 (k, 6, 0xD1, 0xE8, 0x38, 0x4B); 667 /* Calculate whitening and round subkeys */
668 CALC_K256 (k, 8, 0x0D, 0xD6, 0xC6, 0x32); 668 for ( i = 0; i < 8; i += 2 ) {
669 CALC_K256 (k, 10, 0x35, 0xD8, 0x98, 0xFD); 669 CALC_K256 (w, i, q0[i], q1[i], q0[i+1], q1[i+1]);
670 CALC_K256 (k, 12, 0x18, 0x37, 0xF7, 0x71); 670 }
671 CALC_K256 (k, 14, 0xEC, 0xF1, 0x6C, 0xE1); 671 for ( i = 0; i < 32; i += 2 ) {
672 CALC_K256 (k, 16, 0x43, 0x30, 0x75, 0x0F); 672 CALC_K256 (k, i, q0[i+8], q1[i+8], q0[i+9], q1[i+9]);
673 CALC_K256 (k, 18, 0x37, 0xF8, 0x26, 0x1B); 673 }
674 CALC_K256 (k, 20, 0xFA, 0x87, 0x13, 0xFA);
675 CALC_K256 (k, 22, 0x94, 0x06, 0x48, 0x3F);
676 CALC_K256 (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
677 CALC_K256 (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
678 CALC_K256 (k, 28, 0x84, 0x8A, 0x54, 0x00);
679 CALC_K256 (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
680 } else if (key_len == 24) { /* 192-bit key */ 674 } else if (key_len == 24) { /* 192-bit key */
681 /* Compute the S-boxes. */ 675 /* Compute the S-boxes. */
682 for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) { 676 for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) {
683 CALC_SB192_2( i, calc_sb_tbl[j], calc_sb_tbl[k] ); 677 CALC_SB192_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
684 } 678 }
685 679
686 /* Calculate whitening and round subkeys. The constants are 680 /* Calculate whitening and round subkeys */
687 * indices of subkeys, preprocessed through q0 and q1. */ 681 for ( i = 0; i < 8; i += 2 ) {
688 CALC_K192 (w, 0, 0xA9, 0x75, 0x67, 0xF3); 682 CALC_K192 (w, i, q0[i], q1[i], q0[i+1], q1[i+1]);
689 CALC_K192 (w, 2, 0xB3, 0xC6, 0xE8, 0xF4); 683 }
690 CALC_K192 (w, 4, 0x04, 0xDB, 0xFD, 0x7B); 684 for ( i = 0; i < 32; i += 2 ) {
691 CALC_K192 (w, 6, 0xA3, 0xFB, 0x76, 0xC8); 685 CALC_K192 (k, i, q0[i+8], q1[i+8], q0[i+9], q1[i+9]);
692 CALC_K192 (k, 0, 0x9A, 0x4A, 0x92, 0xD3); 686 }
693 CALC_K192 (k, 2, 0x80, 0xE6, 0x78, 0x6B);
694 CALC_K192 (k, 4, 0xE4, 0x45, 0xDD, 0x7D);
695 CALC_K192 (k, 6, 0xD1, 0xE8, 0x38, 0x4B);
696 CALC_K192 (k, 8, 0x0D, 0xD6, 0xC6, 0x32);
697 CALC_K192 (k, 10, 0x35, 0xD8, 0x98, 0xFD);
698 CALC_K192 (k, 12, 0x18, 0x37, 0xF7, 0x71);
699 CALC_K192 (k, 14, 0xEC, 0xF1, 0x6C, 0xE1);
700 CALC_K192 (k, 16, 0x43, 0x30, 0x75, 0x0F);
701 CALC_K192 (k, 18, 0x37, 0xF8, 0x26, 0x1B);
702 CALC_K192 (k, 20, 0xFA, 0x87, 0x13, 0xFA);
703 CALC_K192 (k, 22, 0x94, 0x06, 0x48, 0x3F);
704 CALC_K192 (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
705 CALC_K192 (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
706 CALC_K192 (k, 28, 0x84, 0x8A, 0x54, 0x00);
707 CALC_K192 (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
708 } else { /* 128-bit key */ 687 } else { /* 128-bit key */
709 /* Compute the S-boxes. */ 688 /* Compute the S-boxes. */
710 for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) { 689 for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) {
711 CALC_SB_2( i, calc_sb_tbl[j], calc_sb_tbl[k] ); 690 CALC_SB_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
712 } 691 }
713 692
714 /* Calculate whitening and round subkeys. The constants are 693 /* Calculate whitening and round subkeys */
715 * indices of subkeys, preprocessed through q0 and q1. */ 694 for ( i = 0; i < 8; i += 2 ) {
716 CALC_K (w, 0, 0xA9, 0x75, 0x67, 0xF3); 695 CALC_K (w, i, q0[i], q1[i], q0[i+1], q1[i+1]);
717 CALC_K (w, 2, 0xB3, 0xC6, 0xE8, 0xF4); 696 }
718 CALC_K (w, 4, 0x04, 0xDB, 0xFD, 0x7B); 697 for ( i = 0; i < 32; i += 2 ) {
719 CALC_K (w, 6, 0xA3, 0xFB, 0x76, 0xC8); 698 CALC_K (k, i, q0[i+8], q1[i+8], q0[i+9], q1[i+9]);
720 CALC_K (k, 0, 0x9A, 0x4A, 0x92, 0xD3); 699 }
721 CALC_K (k, 2, 0x80, 0xE6, 0x78, 0x6B);
722 CALC_K (k, 4, 0xE4, 0x45, 0xDD, 0x7D);
723 CALC_K (k, 6, 0xD1, 0xE8, 0x38, 0x4B);
724 CALC_K (k, 8, 0x0D, 0xD6, 0xC6, 0x32);
725 CALC_K (k, 10, 0x35, 0xD8, 0x98, 0xFD);
726 CALC_K (k, 12, 0x18, 0x37, 0xF7, 0x71);
727 CALC_K (k, 14, 0xEC, 0xF1, 0x6C, 0xE1);
728 CALC_K (k, 16, 0x43, 0x30, 0x75, 0x0F);
729 CALC_K (k, 18, 0x37, 0xF8, 0x26, 0x1B);
730 CALC_K (k, 20, 0xFA, 0x87, 0x13, 0xFA);
731 CALC_K (k, 22, 0x94, 0x06, 0x48, 0x3F);
732 CALC_K (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
733 CALC_K (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
734 CALC_K (k, 28, 0x84, 0x8A, 0x54, 0x00);
735 CALC_K (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
736 } 700 }
737 701
738 return 0; 702 return 0;
diff --git a/crypto/xcbc.c b/crypto/xcbc.c
index ac68f3b62fde..a82959df678c 100644
--- a/crypto/xcbc.c
+++ b/crypto/xcbc.c
@@ -19,6 +19,7 @@
19 * Kazunori Miyazawa <miyazawa@linux-ipv6.org> 19 * Kazunori Miyazawa <miyazawa@linux-ipv6.org>
20 */ 20 */
21 21
22#include <crypto/scatterwalk.h>
22#include <linux/crypto.h> 23#include <linux/crypto.h>
23#include <linux/err.h> 24#include <linux/err.h>
24#include <linux/hardirq.h> 25#include <linux/hardirq.h>
@@ -27,7 +28,6 @@
27#include <linux/rtnetlink.h> 28#include <linux/rtnetlink.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/scatterlist.h> 30#include <linux/scatterlist.h>
30#include "internal.h"
31 31
32static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101, 32static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
33 0x02020202, 0x02020202, 0x02020202, 0x02020202, 33 0x02020202, 0x02020202, 0x02020202, 0x02020202,
@@ -307,7 +307,8 @@ static struct crypto_instance *xcbc_alloc(struct rtattr **tb)
307 case 16: 307 case 16:
308 break; 308 break;
309 default: 309 default:
310 return ERR_PTR(PTR_ERR(alg)); 310 inst = ERR_PTR(-EINVAL);
311 goto out_put_alg;
311 } 312 }
312 313
313 inst = crypto_alloc_instance("xcbc", alg); 314 inst = crypto_alloc_instance("xcbc", alg);
@@ -320,10 +321,7 @@ static struct crypto_instance *xcbc_alloc(struct rtattr **tb)
320 inst->alg.cra_alignmask = alg->cra_alignmask; 321 inst->alg.cra_alignmask = alg->cra_alignmask;
321 inst->alg.cra_type = &crypto_hash_type; 322 inst->alg.cra_type = &crypto_hash_type;
322 323
323 inst->alg.cra_hash.digestsize = 324 inst->alg.cra_hash.digestsize = alg->cra_blocksize;
324 (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
325 CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize :
326 alg->cra_blocksize;
327 inst->alg.cra_ctxsize = sizeof(struct crypto_xcbc_ctx) + 325 inst->alg.cra_ctxsize = sizeof(struct crypto_xcbc_ctx) +
328 ALIGN(inst->alg.cra_blocksize * 3, sizeof(void *)); 326 ALIGN(inst->alg.cra_blocksize * 3, sizeof(void *));
329 inst->alg.cra_init = xcbc_init_tfm; 327 inst->alg.cra_init = xcbc_init_tfm;
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index f4487c38d9f2..1b4cf984b081 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -743,7 +743,7 @@ static int __init acpi_bus_init(void)
743 return -ENODEV; 743 return -ENODEV;
744} 744}
745 745
746decl_subsys(acpi, NULL, NULL); 746struct kobject *acpi_kobj;
747 747
748static int __init acpi_init(void) 748static int __init acpi_init(void)
749{ 749{
@@ -755,10 +755,11 @@ static int __init acpi_init(void)
755 return -ENODEV; 755 return -ENODEV;
756 } 756 }
757 757
758 result = firmware_register(&acpi_subsys); 758 acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
759 if (result < 0) 759 if (!acpi_kobj) {
760 printk(KERN_WARNING "%s: firmware_register error: %d\n", 760 printk(KERN_WARNING "%s: kset create error\n", __FUNCTION__);
761 __FUNCTION__, result); 761 acpi_kobj = NULL;
762 }
762 763
763 result = acpi_bus_init(); 764 result = acpi_bus_init();
764 765
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index c9f526e55392..5400ea173f6f 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -911,7 +911,7 @@ __setup("acpi_irq_balance", acpi_irq_balance_set);
911 911
912/* FIXME: we will remove this interface after all drivers call pci_disable_device */ 912/* FIXME: we will remove this interface after all drivers call pci_disable_device */
913static struct sysdev_class irqrouter_sysdev_class = { 913static struct sysdev_class irqrouter_sysdev_class = {
914 set_kset_name("irqrouter"), 914 .name = "irqrouter",
915 .resume = irqrouter_resume, 915 .resume = irqrouter_resume,
916}; 916};
917 917
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index edee2806e37b..5ffe0ea18967 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -58,7 +58,7 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
58 FS Interface (/sys) 58 FS Interface (/sys)
59 -------------------------------------------------------------------------- */ 59 -------------------------------------------------------------------------- */
60static LIST_HEAD(acpi_table_attr_list); 60static LIST_HEAD(acpi_table_attr_list);
61static struct kobject tables_kobj; 61static struct kobject *tables_kobj;
62 62
63struct acpi_table_attr { 63struct acpi_table_attr {
64 struct bin_attribute attr; 64 struct bin_attribute attr;
@@ -135,11 +135,9 @@ static int acpi_system_sysfs_init(void)
135 int table_index = 0; 135 int table_index = 0;
136 int result; 136 int result;
137 137
138 tables_kobj.parent = &acpi_subsys.kobj; 138 tables_kobj = kobject_create_and_add("tables", acpi_kobj);
139 kobject_set_name(&tables_kobj, "tables"); 139 if (!tables_kobj)
140 result = kobject_register(&tables_kobj); 140 return -ENOMEM;
141 if (result)
142 return result;
143 141
144 do { 142 do {
145 result = acpi_get_table_by_index(table_index, &table_header); 143 result = acpi_get_table_by_index(table_index, &table_header);
@@ -153,7 +151,7 @@ static int acpi_system_sysfs_init(void)
153 151
154 acpi_table_attr_init(table_attr, table_header); 152 acpi_table_attr_init(table_attr, table_header);
155 result = 153 result =
156 sysfs_create_bin_file(&tables_kobj, 154 sysfs_create_bin_file(tables_kobj,
157 &table_attr->attr); 155 &table_attr->attr);
158 if (result) { 156 if (result) {
159 kfree(table_attr); 157 kfree(table_attr);
@@ -163,6 +161,7 @@ static int acpi_system_sysfs_init(void)
163 &acpi_table_attr_list); 161 &acpi_table_attr_list);
164 } 162 }
165 } while (!result); 163 } while (!result);
164 kobject_uevent(tables_kobj, KOBJ_ADD);
166 165
167 return 0; 166 return 0;
168} 167}
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index b39ea3f59c9b..63e09c015ca0 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -11,6 +11,9 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o
11obj-$(CONFIG_NUMA) += node.o 11obj-$(CONFIG_NUMA) += node.o
12obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o 12obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o
13obj-$(CONFIG_SMP) += topology.o 13obj-$(CONFIG_SMP) += topology.o
14ifeq ($(CONFIG_SYSFS),y)
15obj-$(CONFIG_MODULES) += module.o
16endif
14obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o 17obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o
15 18
16ifeq ($(CONFIG_DEBUG_DRIVER),y) 19ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 7370d7cf5988..d4dfb97de3b0 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -61,7 +61,7 @@ attribute_container_classdev_to_container(struct class_device *classdev)
61} 61}
62EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container); 62EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container);
63 63
64static struct list_head attribute_container_list; 64static LIST_HEAD(attribute_container_list);
65 65
66static DEFINE_MUTEX(attribute_container_mutex); 66static DEFINE_MUTEX(attribute_container_mutex);
67 67
@@ -429,10 +429,3 @@ attribute_container_find_class_device(struct attribute_container *cont,
429 return cdev; 429 return cdev;
430} 430}
431EXPORT_SYMBOL_GPL(attribute_container_find_class_device); 431EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
432
433int __init
434attribute_container_init(void)
435{
436 INIT_LIST_HEAD(&attribute_container_list);
437 return 0;
438}
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 10b2fb6c9ce6..c0444146c09a 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -1,6 +1,42 @@
1 1
2/* initialisation functions */ 2/**
3 * struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure.
4 *
5 * @subsys - the struct kset that defines this bus. This is the main kobject
6 * @drivers_kset - the list of drivers associated with this bus
7 * @devices_kset - the list of devices associated with this bus
8 * @klist_devices - the klist to iterate over the @devices_kset
9 * @klist_drivers - the klist to iterate over the @drivers_kset
10 * @bus_notifier - the bus notifier list for anything that cares about things
11 * on this bus.
12 * @bus - pointer back to the struct bus_type that this structure is associated
13 * with.
14 *
15 * This structure is the one that is the actual kobject allowing struct
16 * bus_type to be statically allocated safely. Nothing outside of the driver
17 * core should ever touch these fields.
18 */
19struct bus_type_private {
20 struct kset subsys;
21 struct kset *drivers_kset;
22 struct kset *devices_kset;
23 struct klist klist_devices;
24 struct klist klist_drivers;
25 struct blocking_notifier_head bus_notifier;
26 unsigned int drivers_autoprobe:1;
27 struct bus_type *bus;
28};
29
30struct driver_private {
31 struct kobject kobj;
32 struct klist klist_devices;
33 struct klist_node knode_bus;
34 struct module_kobject *mkobj;
35 struct device_driver *driver;
36};
37#define to_driver(obj) container_of(obj, struct driver_private, kobj)
3 38
39/* initialisation functions */
4extern int devices_init(void); 40extern int devices_init(void);
5extern int buses_init(void); 41extern int buses_init(void);
6extern int classes_init(void); 42extern int classes_init(void);
@@ -13,17 +49,16 @@ static inline int hypervisor_init(void) { return 0; }
13extern int platform_bus_init(void); 49extern int platform_bus_init(void);
14extern int system_bus_init(void); 50extern int system_bus_init(void);
15extern int cpu_dev_init(void); 51extern int cpu_dev_init(void);
16extern int attribute_container_init(void);
17 52
18extern int bus_add_device(struct device * dev); 53extern int bus_add_device(struct device *dev);
19extern void bus_attach_device(struct device * dev); 54extern void bus_attach_device(struct device *dev);
20extern void bus_remove_device(struct device * dev); 55extern void bus_remove_device(struct device *dev);
21 56
22extern int bus_add_driver(struct device_driver *); 57extern int bus_add_driver(struct device_driver *drv);
23extern void bus_remove_driver(struct device_driver *); 58extern void bus_remove_driver(struct device_driver *drv);
24 59
25extern void driver_detach(struct device_driver * drv); 60extern void driver_detach(struct device_driver *drv);
26extern int driver_probe_device(struct device_driver *, struct device *); 61extern int driver_probe_device(struct device_driver *drv, struct device *dev);
27 62
28extern void sysdev_shutdown(void); 63extern void sysdev_shutdown(void);
29extern int sysdev_suspend(pm_message_t state); 64extern int sysdev_suspend(pm_message_t state);
@@ -44,4 +79,13 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
44 79
45extern int devres_release_all(struct device *dev); 80extern int devres_release_all(struct device *dev);
46 81
47extern struct kset devices_subsys; 82extern struct kset *devices_kset;
83
84#if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
85extern void module_add_driver(struct module *mod, struct device_driver *drv);
86extern void module_remove_driver(struct device_driver *drv);
87#else
88static inline void module_add_driver(struct module *mod,
89 struct device_driver *drv) { }
90static inline void module_remove_driver(struct device_driver *drv) { }
91#endif
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 9a19b071c573..f484495b2ad1 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2007 Novell Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 * 10 *
@@ -17,14 +19,13 @@
17#include "power/power.h" 19#include "power/power.h"
18 20
19#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) 21#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
20#define to_bus(obj) container_of(obj, struct bus_type, subsys.kobj) 22#define to_bus(obj) container_of(obj, struct bus_type_private, subsys.kobj)
21 23
22/* 24/*
23 * sysfs bindings for drivers 25 * sysfs bindings for drivers
24 */ 26 */
25 27
26#define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr) 28#define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
27#define to_driver(obj) container_of(obj, struct device_driver, kobj)
28 29
29 30
30static int __must_check bus_rescan_devices_helper(struct device *dev, 31static int __must_check bus_rescan_devices_helper(struct device *dev,
@@ -32,37 +33,40 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
32 33
33static struct bus_type *bus_get(struct bus_type *bus) 34static struct bus_type *bus_get(struct bus_type *bus)
34{ 35{
35 return bus ? container_of(kset_get(&bus->subsys), 36 if (bus) {
36 struct bus_type, subsys) : NULL; 37 kset_get(&bus->p->subsys);
38 return bus;
39 }
40 return NULL;
37} 41}
38 42
39static void bus_put(struct bus_type *bus) 43static void bus_put(struct bus_type *bus)
40{ 44{
41 kset_put(&bus->subsys); 45 if (bus)
46 kset_put(&bus->p->subsys);
42} 47}
43 48
44static ssize_t 49static ssize_t drv_attr_show(struct kobject *kobj, struct attribute *attr,
45drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 50 char *buf)
46{ 51{
47 struct driver_attribute * drv_attr = to_drv_attr(attr); 52 struct driver_attribute *drv_attr = to_drv_attr(attr);
48 struct device_driver * drv = to_driver(kobj); 53 struct driver_private *drv_priv = to_driver(kobj);
49 ssize_t ret = -EIO; 54 ssize_t ret = -EIO;
50 55
51 if (drv_attr->show) 56 if (drv_attr->show)
52 ret = drv_attr->show(drv, buf); 57 ret = drv_attr->show(drv_priv->driver, buf);
53 return ret; 58 return ret;
54} 59}
55 60
56static ssize_t 61static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
57drv_attr_store(struct kobject * kobj, struct attribute * attr, 62 const char *buf, size_t count)
58 const char * buf, size_t count)
59{ 63{
60 struct driver_attribute * drv_attr = to_drv_attr(attr); 64 struct driver_attribute *drv_attr = to_drv_attr(attr);
61 struct device_driver * drv = to_driver(kobj); 65 struct driver_private *drv_priv = to_driver(kobj);
62 ssize_t ret = -EIO; 66 ssize_t ret = -EIO;
63 67
64 if (drv_attr->store) 68 if (drv_attr->store)
65 ret = drv_attr->store(drv, buf, count); 69 ret = drv_attr->store(drv_priv->driver, buf, count);
66 return ret; 70 return ret;
67} 71}
68 72
@@ -71,22 +75,12 @@ static struct sysfs_ops driver_sysfs_ops = {
71 .store = drv_attr_store, 75 .store = drv_attr_store,
72}; 76};
73 77
74 78static void driver_release(struct kobject *kobj)
75static void driver_release(struct kobject * kobj)
76{ 79{
77 /* 80 struct driver_private *drv_priv = to_driver(kobj);
78 * Yes this is an empty release function, it is this way because struct 81
79 * device is always a static object, not a dynamic one. Yes, this is 82 pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__);
80 * not nice and bad, but remember, drivers are code, reference counted 83 kfree(drv_priv);
81 * by the module count, not a device, which is really data. And yes,
82 * in the future I do want to have all drivers be created dynamically,
83 * and am working toward that goal, but it will take a bit longer...
84 *
85 * But do not let this example give _anyone_ the idea that they can
86 * create a release function without any code in it at all, to do that
87 * is almost always wrong. If you have any questions about this,
88 * please send an email to <greg@kroah.com>
89 */
90} 84}
91 85
92static struct kobj_type driver_ktype = { 86static struct kobj_type driver_ktype = {
@@ -94,34 +88,30 @@ static struct kobj_type driver_ktype = {
94 .release = driver_release, 88 .release = driver_release,
95}; 89};
96 90
97
98/* 91/*
99 * sysfs bindings for buses 92 * sysfs bindings for buses
100 */ 93 */
101 94static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr,
102 95 char *buf)
103static ssize_t
104bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
105{ 96{
106 struct bus_attribute * bus_attr = to_bus_attr(attr); 97 struct bus_attribute *bus_attr = to_bus_attr(attr);
107 struct bus_type * bus = to_bus(kobj); 98 struct bus_type_private *bus_priv = to_bus(kobj);
108 ssize_t ret = 0; 99 ssize_t ret = 0;
109 100
110 if (bus_attr->show) 101 if (bus_attr->show)
111 ret = bus_attr->show(bus, buf); 102 ret = bus_attr->show(bus_priv->bus, buf);
112 return ret; 103 return ret;
113} 104}
114 105
115static ssize_t 106static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
116bus_attr_store(struct kobject * kobj, struct attribute * attr, 107 const char *buf, size_t count)
117 const char * buf, size_t count)
118{ 108{
119 struct bus_attribute * bus_attr = to_bus_attr(attr); 109 struct bus_attribute *bus_attr = to_bus_attr(attr);
120 struct bus_type * bus = to_bus(kobj); 110 struct bus_type_private *bus_priv = to_bus(kobj);
121 ssize_t ret = 0; 111 ssize_t ret = 0;
122 112
123 if (bus_attr->store) 113 if (bus_attr->store)
124 ret = bus_attr->store(bus, buf, count); 114 ret = bus_attr->store(bus_priv->bus, buf, count);
125 return ret; 115 return ret;
126} 116}
127 117
@@ -130,24 +120,26 @@ static struct sysfs_ops bus_sysfs_ops = {
130 .store = bus_attr_store, 120 .store = bus_attr_store,
131}; 121};
132 122
133int bus_create_file(struct bus_type * bus, struct bus_attribute * attr) 123int bus_create_file(struct bus_type *bus, struct bus_attribute *attr)
134{ 124{
135 int error; 125 int error;
136 if (bus_get(bus)) { 126 if (bus_get(bus)) {
137 error = sysfs_create_file(&bus->subsys.kobj, &attr->attr); 127 error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr);
138 bus_put(bus); 128 bus_put(bus);
139 } else 129 } else
140 error = -EINVAL; 130 error = -EINVAL;
141 return error; 131 return error;
142} 132}
133EXPORT_SYMBOL_GPL(bus_create_file);
143 134
144void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr) 135void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
145{ 136{
146 if (bus_get(bus)) { 137 if (bus_get(bus)) {
147 sysfs_remove_file(&bus->subsys.kobj, &attr->attr); 138 sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr);
148 bus_put(bus); 139 bus_put(bus);
149 } 140 }
150} 141}
142EXPORT_SYMBOL_GPL(bus_remove_file);
151 143
152static struct kobj_type bus_ktype = { 144static struct kobj_type bus_ktype = {
153 .sysfs_ops = &bus_sysfs_ops, 145 .sysfs_ops = &bus_sysfs_ops,
@@ -166,7 +158,7 @@ static struct kset_uevent_ops bus_uevent_ops = {
166 .filter = bus_uevent_filter, 158 .filter = bus_uevent_filter,
167}; 159};
168 160
169static decl_subsys(bus, &bus_ktype, &bus_uevent_ops); 161static struct kset *bus_kset;
170 162
171 163
172#ifdef CONFIG_HOTPLUG 164#ifdef CONFIG_HOTPLUG
@@ -224,10 +216,13 @@ static ssize_t driver_bind(struct device_driver *drv,
224 if (dev->parent) 216 if (dev->parent)
225 up(&dev->parent->sem); 217 up(&dev->parent->sem);
226 218
227 if (err > 0) /* success */ 219 if (err > 0) {
220 /* success */
228 err = count; 221 err = count;
229 else if (err == 0) /* driver didn't accept device */ 222 } else if (err == 0) {
223 /* driver didn't accept device */
230 err = -ENODEV; 224 err = -ENODEV;
225 }
231 } 226 }
232 put_device(dev); 227 put_device(dev);
233 bus_put(bus); 228 bus_put(bus);
@@ -237,16 +232,16 @@ static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
237 232
238static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) 233static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
239{ 234{
240 return sprintf(buf, "%d\n", bus->drivers_autoprobe); 235 return sprintf(buf, "%d\n", bus->p->drivers_autoprobe);
241} 236}
242 237
243static ssize_t store_drivers_autoprobe(struct bus_type *bus, 238static ssize_t store_drivers_autoprobe(struct bus_type *bus,
244 const char *buf, size_t count) 239 const char *buf, size_t count)
245{ 240{
246 if (buf[0] == '0') 241 if (buf[0] == '0')
247 bus->drivers_autoprobe = 0; 242 bus->p->drivers_autoprobe = 0;
248 else 243 else
249 bus->drivers_autoprobe = 1; 244 bus->p->drivers_autoprobe = 1;
250 return count; 245 return count;
251} 246}
252 247
@@ -264,49 +259,49 @@ static ssize_t store_drivers_probe(struct bus_type *bus,
264} 259}
265#endif 260#endif
266 261
267static struct device * next_device(struct klist_iter * i) 262static struct device *next_device(struct klist_iter *i)
268{ 263{
269 struct klist_node * n = klist_next(i); 264 struct klist_node *n = klist_next(i);
270 return n ? container_of(n, struct device, knode_bus) : NULL; 265 return n ? container_of(n, struct device, knode_bus) : NULL;
271} 266}
272 267
273/** 268/**
274 * bus_for_each_dev - device iterator. 269 * bus_for_each_dev - device iterator.
275 * @bus: bus type. 270 * @bus: bus type.
276 * @start: device to start iterating from. 271 * @start: device to start iterating from.
277 * @data: data for the callback. 272 * @data: data for the callback.
278 * @fn: function to be called for each device. 273 * @fn: function to be called for each device.
279 * 274 *
280 * Iterate over @bus's list of devices, and call @fn for each, 275 * Iterate over @bus's list of devices, and call @fn for each,
281 * passing it @data. If @start is not NULL, we use that device to 276 * passing it @data. If @start is not NULL, we use that device to
282 * begin iterating from. 277 * begin iterating from.
283 * 278 *
284 * We check the return of @fn each time. If it returns anything 279 * We check the return of @fn each time. If it returns anything
285 * other than 0, we break out and return that value. 280 * other than 0, we break out and return that value.
286 * 281 *
287 * NOTE: The device that returns a non-zero value is not retained 282 * NOTE: The device that returns a non-zero value is not retained
288 * in any way, nor is its refcount incremented. If the caller needs 283 * in any way, nor is its refcount incremented. If the caller needs
289 * to retain this data, it should do, and increment the reference 284 * to retain this data, it should do, and increment the reference
290 * count in the supplied callback. 285 * count in the supplied callback.
291 */ 286 */
292 287int bus_for_each_dev(struct bus_type *bus, struct device *start,
293int bus_for_each_dev(struct bus_type * bus, struct device * start, 288 void *data, int (*fn)(struct device *, void *))
294 void * data, int (*fn)(struct device *, void *))
295{ 289{
296 struct klist_iter i; 290 struct klist_iter i;
297 struct device * dev; 291 struct device *dev;
298 int error = 0; 292 int error = 0;
299 293
300 if (!bus) 294 if (!bus)
301 return -EINVAL; 295 return -EINVAL;
302 296
303 klist_iter_init_node(&bus->klist_devices, &i, 297 klist_iter_init_node(&bus->p->klist_devices, &i,
304 (start ? &start->knode_bus : NULL)); 298 (start ? &start->knode_bus : NULL));
305 while ((dev = next_device(&i)) && !error) 299 while ((dev = next_device(&i)) && !error)
306 error = fn(dev, data); 300 error = fn(dev, data);
307 klist_iter_exit(&i); 301 klist_iter_exit(&i);
308 return error; 302 return error;
309} 303}
304EXPORT_SYMBOL_GPL(bus_for_each_dev);
310 305
311/** 306/**
312 * bus_find_device - device iterator for locating a particular device. 307 * bus_find_device - device iterator for locating a particular device.
@@ -323,9 +318,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
323 * if it does. If the callback returns non-zero, this function will 318 * if it does. If the callback returns non-zero, this function will
324 * return to the caller and not iterate over any more devices. 319 * return to the caller and not iterate over any more devices.
325 */ 320 */
326struct device * bus_find_device(struct bus_type *bus, 321struct device *bus_find_device(struct bus_type *bus,
327 struct device *start, void *data, 322 struct device *start, void *data,
328 int (*match)(struct device *, void *)) 323 int (*match)(struct device *dev, void *data))
329{ 324{
330 struct klist_iter i; 325 struct klist_iter i;
331 struct device *dev; 326 struct device *dev;
@@ -333,7 +328,7 @@ struct device * bus_find_device(struct bus_type *bus,
333 if (!bus) 328 if (!bus)
334 return NULL; 329 return NULL;
335 330
336 klist_iter_init_node(&bus->klist_devices, &i, 331 klist_iter_init_node(&bus->p->klist_devices, &i,
337 (start ? &start->knode_bus : NULL)); 332 (start ? &start->knode_bus : NULL));
338 while ((dev = next_device(&i))) 333 while ((dev = next_device(&i)))
339 if (match(dev, data) && get_device(dev)) 334 if (match(dev, data) && get_device(dev))
@@ -341,51 +336,57 @@ struct device * bus_find_device(struct bus_type *bus,
341 klist_iter_exit(&i); 336 klist_iter_exit(&i);
342 return dev; 337 return dev;
343} 338}
339EXPORT_SYMBOL_GPL(bus_find_device);
344 340
345 341static struct device_driver *next_driver(struct klist_iter *i)
346static struct device_driver * next_driver(struct klist_iter * i)
347{ 342{
348 struct klist_node * n = klist_next(i); 343 struct klist_node *n = klist_next(i);
349 return n ? container_of(n, struct device_driver, knode_bus) : NULL; 344 struct driver_private *drv_priv;
345
346 if (n) {
347 drv_priv = container_of(n, struct driver_private, knode_bus);
348 return drv_priv->driver;
349 }
350 return NULL;
350} 351}
351 352
352/** 353/**
353 * bus_for_each_drv - driver iterator 354 * bus_for_each_drv - driver iterator
354 * @bus: bus we're dealing with. 355 * @bus: bus we're dealing with.
355 * @start: driver to start iterating on. 356 * @start: driver to start iterating on.
356 * @data: data to pass to the callback. 357 * @data: data to pass to the callback.
357 * @fn: function to call for each driver. 358 * @fn: function to call for each driver.
358 * 359 *
359 * This is nearly identical to the device iterator above. 360 * This is nearly identical to the device iterator above.
360 * We iterate over each driver that belongs to @bus, and call 361 * We iterate over each driver that belongs to @bus, and call
361 * @fn for each. If @fn returns anything but 0, we break out 362 * @fn for each. If @fn returns anything but 0, we break out
362 * and return it. If @start is not NULL, we use it as the head 363 * and return it. If @start is not NULL, we use it as the head
363 * of the list. 364 * of the list.
364 * 365 *
365 * NOTE: we don't return the driver that returns a non-zero 366 * NOTE: we don't return the driver that returns a non-zero
366 * value, nor do we leave the reference count incremented for that 367 * value, nor do we leave the reference count incremented for that
367 * driver. If the caller needs to know that info, it must set it 368 * driver. If the caller needs to know that info, it must set it
368 * in the callback. It must also be sure to increment the refcount 369 * in the callback. It must also be sure to increment the refcount
369 * so it doesn't disappear before returning to the caller. 370 * so it doesn't disappear before returning to the caller.
370 */ 371 */
371 372int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
372int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, 373 void *data, int (*fn)(struct device_driver *, void *))
373 void * data, int (*fn)(struct device_driver *, void *))
374{ 374{
375 struct klist_iter i; 375 struct klist_iter i;
376 struct device_driver * drv; 376 struct device_driver *drv;
377 int error = 0; 377 int error = 0;
378 378
379 if (!bus) 379 if (!bus)
380 return -EINVAL; 380 return -EINVAL;
381 381
382 klist_iter_init_node(&bus->klist_drivers, &i, 382 klist_iter_init_node(&bus->p->klist_drivers, &i,
383 start ? &start->knode_bus : NULL); 383 start ? &start->p->knode_bus : NULL);
384 while ((drv = next_driver(&i)) && !error) 384 while ((drv = next_driver(&i)) && !error)
385 error = fn(drv, data); 385 error = fn(drv, data);
386 klist_iter_exit(&i); 386 klist_iter_exit(&i);
387 return error; 387 return error;
388} 388}
389EXPORT_SYMBOL_GPL(bus_for_each_drv);
389 390
390static int device_add_attrs(struct bus_type *bus, struct device *dev) 391static int device_add_attrs(struct bus_type *bus, struct device *dev)
391{ 392{
@@ -396,7 +397,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev)
396 return 0; 397 return 0;
397 398
398 for (i = 0; attr_name(bus->dev_attrs[i]); i++) { 399 for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
399 error = device_create_file(dev,&bus->dev_attrs[i]); 400 error = device_create_file(dev, &bus->dev_attrs[i]);
400 if (error) { 401 if (error) {
401 while (--i >= 0) 402 while (--i >= 0)
402 device_remove_file(dev, &bus->dev_attrs[i]); 403 device_remove_file(dev, &bus->dev_attrs[i]);
@@ -406,13 +407,13 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev)
406 return error; 407 return error;
407} 408}
408 409
409static void device_remove_attrs(struct bus_type * bus, struct device * dev) 410static void device_remove_attrs(struct bus_type *bus, struct device *dev)
410{ 411{
411 int i; 412 int i;
412 413
413 if (bus->dev_attrs) { 414 if (bus->dev_attrs) {
414 for (i = 0; attr_name(bus->dev_attrs[i]); i++) 415 for (i = 0; attr_name(bus->dev_attrs[i]); i++)
415 device_remove_file(dev,&bus->dev_attrs[i]); 416 device_remove_file(dev, &bus->dev_attrs[i]);
416 } 417 }
417} 418}
418 419
@@ -420,7 +421,7 @@ static void device_remove_attrs(struct bus_type * bus, struct device * dev)
420static int make_deprecated_bus_links(struct device *dev) 421static int make_deprecated_bus_links(struct device *dev)
421{ 422{
422 return sysfs_create_link(&dev->kobj, 423 return sysfs_create_link(&dev->kobj,
423 &dev->bus->subsys.kobj, "bus"); 424 &dev->bus->p->subsys.kobj, "bus");
424} 425}
425 426
426static void remove_deprecated_bus_links(struct device *dev) 427static void remove_deprecated_bus_links(struct device *dev)
@@ -433,28 +434,28 @@ static inline void remove_deprecated_bus_links(struct device *dev) { }
433#endif 434#endif
434 435
435/** 436/**
436 * bus_add_device - add device to bus 437 * bus_add_device - add device to bus
437 * @dev: device being added 438 * @dev: device being added
438 * 439 *
439 * - Add the device to its bus's list of devices. 440 * - Add the device to its bus's list of devices.
440 * - Create link to device's bus. 441 * - Create link to device's bus.
441 */ 442 */
442int bus_add_device(struct device * dev) 443int bus_add_device(struct device *dev)
443{ 444{
444 struct bus_type * bus = bus_get(dev->bus); 445 struct bus_type *bus = bus_get(dev->bus);
445 int error = 0; 446 int error = 0;
446 447
447 if (bus) { 448 if (bus) {
448 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); 449 pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id);
449 error = device_add_attrs(bus, dev); 450 error = device_add_attrs(bus, dev);
450 if (error) 451 if (error)
451 goto out_put; 452 goto out_put;
452 error = sysfs_create_link(&bus->devices.kobj, 453 error = sysfs_create_link(&bus->p->devices_kset->kobj,
453 &dev->kobj, dev->bus_id); 454 &dev->kobj, dev->bus_id);
454 if (error) 455 if (error)
455 goto out_id; 456 goto out_id;
456 error = sysfs_create_link(&dev->kobj, 457 error = sysfs_create_link(&dev->kobj,
457 &dev->bus->subsys.kobj, "subsystem"); 458 &dev->bus->p->subsys.kobj, "subsystem");
458 if (error) 459 if (error)
459 goto out_subsys; 460 goto out_subsys;
460 error = make_deprecated_bus_links(dev); 461 error = make_deprecated_bus_links(dev);
@@ -466,7 +467,7 @@ int bus_add_device(struct device * dev)
466out_deprecated: 467out_deprecated:
467 sysfs_remove_link(&dev->kobj, "subsystem"); 468 sysfs_remove_link(&dev->kobj, "subsystem");
468out_subsys: 469out_subsys:
469 sysfs_remove_link(&bus->devices.kobj, dev->bus_id); 470 sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id);
470out_id: 471out_id:
471 device_remove_attrs(bus, dev); 472 device_remove_attrs(bus, dev);
472out_put: 473out_put:
@@ -475,56 +476,58 @@ out_put:
475} 476}
476 477
477/** 478/**
478 * bus_attach_device - add device to bus 479 * bus_attach_device - add device to bus
479 * @dev: device tried to attach to a driver 480 * @dev: device tried to attach to a driver
480 * 481 *
481 * - Add device to bus's list of devices. 482 * - Add device to bus's list of devices.
482 * - Try to attach to driver. 483 * - Try to attach to driver.
483 */ 484 */
484void bus_attach_device(struct device * dev) 485void bus_attach_device(struct device *dev)
485{ 486{
486 struct bus_type *bus = dev->bus; 487 struct bus_type *bus = dev->bus;
487 int ret = 0; 488 int ret = 0;
488 489
489 if (bus) { 490 if (bus) {
490 dev->is_registered = 1; 491 dev->is_registered = 1;
491 if (bus->drivers_autoprobe) 492 if (bus->p->drivers_autoprobe)
492 ret = device_attach(dev); 493 ret = device_attach(dev);
493 WARN_ON(ret < 0); 494 WARN_ON(ret < 0);
494 if (ret >= 0) 495 if (ret >= 0)
495 klist_add_tail(&dev->knode_bus, &bus->klist_devices); 496 klist_add_tail(&dev->knode_bus, &bus->p->klist_devices);
496 else 497 else
497 dev->is_registered = 0; 498 dev->is_registered = 0;
498 } 499 }
499} 500}
500 501
501/** 502/**
502 * bus_remove_device - remove device from bus 503 * bus_remove_device - remove device from bus
503 * @dev: device to be removed 504 * @dev: device to be removed
504 * 505 *
505 * - Remove symlink from bus's directory. 506 * - Remove symlink from bus's directory.
506 * - Delete device from bus's list. 507 * - Delete device from bus's list.
507 * - Detach from its driver. 508 * - Detach from its driver.
508 * - Drop reference taken in bus_add_device(). 509 * - Drop reference taken in bus_add_device().
509 */ 510 */
510void bus_remove_device(struct device * dev) 511void bus_remove_device(struct device *dev)
511{ 512{
512 if (dev->bus) { 513 if (dev->bus) {
513 sysfs_remove_link(&dev->kobj, "subsystem"); 514 sysfs_remove_link(&dev->kobj, "subsystem");
514 remove_deprecated_bus_links(dev); 515 remove_deprecated_bus_links(dev);
515 sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); 516 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
517 dev->bus_id);
516 device_remove_attrs(dev->bus, dev); 518 device_remove_attrs(dev->bus, dev);
517 if (dev->is_registered) { 519 if (dev->is_registered) {
518 dev->is_registered = 0; 520 dev->is_registered = 0;
519 klist_del(&dev->knode_bus); 521 klist_del(&dev->knode_bus);
520 } 522 }
521 pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); 523 pr_debug("bus: '%s': remove device %s\n",
524 dev->bus->name, dev->bus_id);
522 device_release_driver(dev); 525 device_release_driver(dev);
523 bus_put(dev->bus); 526 bus_put(dev->bus);
524 } 527 }
525} 528}
526 529
527static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv) 530static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv)
528{ 531{
529 int error = 0; 532 int error = 0;
530 int i; 533 int i;
@@ -533,19 +536,19 @@ static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
533 for (i = 0; attr_name(bus->drv_attrs[i]); i++) { 536 for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
534 error = driver_create_file(drv, &bus->drv_attrs[i]); 537 error = driver_create_file(drv, &bus->drv_attrs[i]);
535 if (error) 538 if (error)
536 goto Err; 539 goto err;
537 } 540 }
538 } 541 }
539 Done: 542done:
540 return error; 543 return error;
541 Err: 544err:
542 while (--i >= 0) 545 while (--i >= 0)
543 driver_remove_file(drv, &bus->drv_attrs[i]); 546 driver_remove_file(drv, &bus->drv_attrs[i]);
544 goto Done; 547 goto done;
545} 548}
546 549
547 550static void driver_remove_attrs(struct bus_type *bus,
548static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv) 551 struct device_driver *drv)
549{ 552{
550 int i; 553 int i;
551 554
@@ -616,39 +619,46 @@ static ssize_t driver_uevent_store(struct device_driver *drv,
616 enum kobject_action action; 619 enum kobject_action action;
617 620
618 if (kobject_action_type(buf, count, &action) == 0) 621 if (kobject_action_type(buf, count, &action) == 0)
619 kobject_uevent(&drv->kobj, action); 622 kobject_uevent(&drv->p->kobj, action);
620 return count; 623 return count;
621} 624}
622static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); 625static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store);
623 626
624/** 627/**
625 * bus_add_driver - Add a driver to the bus. 628 * bus_add_driver - Add a driver to the bus.
626 * @drv: driver. 629 * @drv: driver.
627 *
628 */ 630 */
629int bus_add_driver(struct device_driver *drv) 631int bus_add_driver(struct device_driver *drv)
630{ 632{
631 struct bus_type * bus = bus_get(drv->bus); 633 struct bus_type *bus;
634 struct driver_private *priv;
632 int error = 0; 635 int error = 0;
633 636
637 bus = bus_get(drv->bus);
634 if (!bus) 638 if (!bus)
635 return -EINVAL; 639 return -EINVAL;
636 640
637 pr_debug("bus %s: add driver %s\n", bus->name, drv->name); 641 pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);
638 error = kobject_set_name(&drv->kobj, "%s", drv->name); 642
639 if (error) 643 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
640 goto out_put_bus; 644 if (!priv)
641 drv->kobj.kset = &bus->drivers; 645 return -ENOMEM;
642 error = kobject_register(&drv->kobj); 646
647 klist_init(&priv->klist_devices, NULL, NULL);
648 priv->driver = drv;
649 drv->p = priv;
650 priv->kobj.kset = bus->p->drivers_kset;
651 error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
652 "%s", drv->name);
643 if (error) 653 if (error)
644 goto out_put_bus; 654 goto out_put_bus;
645 655
646 if (drv->bus->drivers_autoprobe) { 656 if (drv->bus->p->drivers_autoprobe) {
647 error = driver_attach(drv); 657 error = driver_attach(drv);
648 if (error) 658 if (error)
649 goto out_unregister; 659 goto out_unregister;
650 } 660 }
651 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); 661 klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers);
652 module_add_driver(drv->owner, drv); 662 module_add_driver(drv->owner, drv);
653 663
654 error = driver_create_file(drv, &driver_attr_uevent); 664 error = driver_create_file(drv, &driver_attr_uevent);
@@ -669,24 +679,24 @@ int bus_add_driver(struct device_driver *drv)
669 __FUNCTION__, drv->name); 679 __FUNCTION__, drv->name);
670 } 680 }
671 681
682 kobject_uevent(&priv->kobj, KOBJ_ADD);
672 return error; 683 return error;
673out_unregister: 684out_unregister:
674 kobject_unregister(&drv->kobj); 685 kobject_put(&priv->kobj);
675out_put_bus: 686out_put_bus:
676 bus_put(bus); 687 bus_put(bus);
677 return error; 688 return error;
678} 689}
679 690
680/** 691/**
681 * bus_remove_driver - delete driver from bus's knowledge. 692 * bus_remove_driver - delete driver from bus's knowledge.
682 * @drv: driver. 693 * @drv: driver.
683 * 694 *
684 * Detach the driver from the devices it controls, and remove 695 * Detach the driver from the devices it controls, and remove
685 * it from its bus's list of drivers. Finally, we drop the reference 696 * it from its bus's list of drivers. Finally, we drop the reference
686 * to the bus we took in bus_add_driver(). 697 * to the bus we took in bus_add_driver().
687 */ 698 */
688 699void bus_remove_driver(struct device_driver *drv)
689void bus_remove_driver(struct device_driver * drv)
690{ 700{
691 if (!drv->bus) 701 if (!drv->bus)
692 return; 702 return;
@@ -694,18 +704,17 @@ void bus_remove_driver(struct device_driver * drv)
694 remove_bind_files(drv); 704 remove_bind_files(drv);
695 driver_remove_attrs(drv->bus, drv); 705 driver_remove_attrs(drv->bus, drv);
696 driver_remove_file(drv, &driver_attr_uevent); 706 driver_remove_file(drv, &driver_attr_uevent);
697 klist_remove(&drv->knode_bus); 707 klist_remove(&drv->p->knode_bus);
698 pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); 708 pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name);
699 driver_detach(drv); 709 driver_detach(drv);
700 module_remove_driver(drv); 710 module_remove_driver(drv);
701 kobject_unregister(&drv->kobj); 711 kobject_put(&drv->p->kobj);
702 bus_put(drv->bus); 712 bus_put(drv->bus);
703} 713}
704 714
705
706/* Helper for bus_rescan_devices's iter */ 715/* Helper for bus_rescan_devices's iter */
707static int __must_check bus_rescan_devices_helper(struct device *dev, 716static int __must_check bus_rescan_devices_helper(struct device *dev,
708 void *data) 717 void *data)
709{ 718{
710 int ret = 0; 719 int ret = 0;
711 720
@@ -727,10 +736,11 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
727 * attached and rescan it against existing drivers to see if it matches 736 * attached and rescan it against existing drivers to see if it matches
728 * any by calling device_attach() for the unbound devices. 737 * any by calling device_attach() for the unbound devices.
729 */ 738 */
730int bus_rescan_devices(struct bus_type * bus) 739int bus_rescan_devices(struct bus_type *bus)
731{ 740{
732 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); 741 return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
733} 742}
743EXPORT_SYMBOL_GPL(bus_rescan_devices);
734 744
735/** 745/**
736 * device_reprobe - remove driver for a device and probe for a new driver 746 * device_reprobe - remove driver for a device and probe for a new driver
@@ -755,55 +765,55 @@ int device_reprobe(struct device *dev)
755EXPORT_SYMBOL_GPL(device_reprobe); 765EXPORT_SYMBOL_GPL(device_reprobe);
756 766
757/** 767/**
758 * find_bus - locate bus by name. 768 * find_bus - locate bus by name.
759 * @name: name of bus. 769 * @name: name of bus.
760 * 770 *
761 * Call kset_find_obj() to iterate over list of buses to 771 * Call kset_find_obj() to iterate over list of buses to
762 * find a bus by name. Return bus if found. 772 * find a bus by name. Return bus if found.
763 * 773 *
764 * Note that kset_find_obj increments bus' reference count. 774 * Note that kset_find_obj increments bus' reference count.
765 */ 775 */
766#if 0 776#if 0
767struct bus_type * find_bus(char * name) 777struct bus_type *find_bus(char *name)
768{ 778{
769 struct kobject * k = kset_find_obj(&bus_subsys.kset, name); 779 struct kobject *k = kset_find_obj(bus_kset, name);
770 return k ? to_bus(k) : NULL; 780 return k ? to_bus(k) : NULL;
771} 781}
772#endif /* 0 */ 782#endif /* 0 */
773 783
774 784
775/** 785/**
776 * bus_add_attrs - Add default attributes for this bus. 786 * bus_add_attrs - Add default attributes for this bus.
777 * @bus: Bus that has just been registered. 787 * @bus: Bus that has just been registered.
778 */ 788 */
779 789
780static int bus_add_attrs(struct bus_type * bus) 790static int bus_add_attrs(struct bus_type *bus)
781{ 791{
782 int error = 0; 792 int error = 0;
783 int i; 793 int i;
784 794
785 if (bus->bus_attrs) { 795 if (bus->bus_attrs) {
786 for (i = 0; attr_name(bus->bus_attrs[i]); i++) { 796 for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
787 error = bus_create_file(bus,&bus->bus_attrs[i]); 797 error = bus_create_file(bus, &bus->bus_attrs[i]);
788 if (error) 798 if (error)
789 goto Err; 799 goto err;
790 } 800 }
791 } 801 }
792 Done: 802done:
793 return error; 803 return error;
794 Err: 804err:
795 while (--i >= 0) 805 while (--i >= 0)
796 bus_remove_file(bus,&bus->bus_attrs[i]); 806 bus_remove_file(bus, &bus->bus_attrs[i]);
797 goto Done; 807 goto done;
798} 808}
799 809
800static void bus_remove_attrs(struct bus_type * bus) 810static void bus_remove_attrs(struct bus_type *bus)
801{ 811{
802 int i; 812 int i;
803 813
804 if (bus->bus_attrs) { 814 if (bus->bus_attrs) {
805 for (i = 0; attr_name(bus->bus_attrs[i]); i++) 815 for (i = 0; attr_name(bus->bus_attrs[i]); i++)
806 bus_remove_file(bus,&bus->bus_attrs[i]); 816 bus_remove_file(bus, &bus->bus_attrs[i]);
807 } 817 }
808} 818}
809 819
@@ -827,32 +837,42 @@ static ssize_t bus_uevent_store(struct bus_type *bus,
827 enum kobject_action action; 837 enum kobject_action action;
828 838
829 if (kobject_action_type(buf, count, &action) == 0) 839 if (kobject_action_type(buf, count, &action) == 0)
830 kobject_uevent(&bus->subsys.kobj, action); 840 kobject_uevent(&bus->p->subsys.kobj, action);
831 return count; 841 return count;
832} 842}
833static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store); 843static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
834 844
835/** 845/**
836 * bus_register - register a bus with the system. 846 * bus_register - register a bus with the system.
837 * @bus: bus. 847 * @bus: bus.
838 * 848 *
839 * Once we have that, we registered the bus with the kobject 849 * Once we have that, we registered the bus with the kobject
840 * infrastructure, then register the children subsystems it has: 850 * infrastructure, then register the children subsystems it has:
841 * the devices and drivers that belong to the bus. 851 * the devices and drivers that belong to the bus.
842 */ 852 */
843int bus_register(struct bus_type * bus) 853int bus_register(struct bus_type *bus)
844{ 854{
845 int retval; 855 int retval;
856 struct bus_type_private *priv;
857
858 priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL);
859 if (!priv)
860 return -ENOMEM;
846 861
847 BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier); 862 priv->bus = bus;
863 bus->p = priv;
848 864
849 retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name); 865 BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier);
866
867 retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name);
850 if (retval) 868 if (retval)
851 goto out; 869 goto out;
852 870
853 bus->subsys.kobj.kset = &bus_subsys; 871 priv->subsys.kobj.kset = bus_kset;
872 priv->subsys.kobj.ktype = &bus_ktype;
873 priv->drivers_autoprobe = 1;
854 874
855 retval = subsystem_register(&bus->subsys); 875 retval = kset_register(&priv->subsys);
856 if (retval) 876 if (retval)
857 goto out; 877 goto out;
858 878
@@ -860,23 +880,23 @@ int bus_register(struct bus_type * bus)
860 if (retval) 880 if (retval)
861 goto bus_uevent_fail; 881 goto bus_uevent_fail;
862 882
863 kobject_set_name(&bus->devices.kobj, "devices"); 883 priv->devices_kset = kset_create_and_add("devices", NULL,
864 bus->devices.kobj.parent = &bus->subsys.kobj; 884 &priv->subsys.kobj);
865 retval = kset_register(&bus->devices); 885 if (!priv->devices_kset) {
866 if (retval) 886 retval = -ENOMEM;
867 goto bus_devices_fail; 887 goto bus_devices_fail;
888 }
868 889
869 kobject_set_name(&bus->drivers.kobj, "drivers"); 890 priv->drivers_kset = kset_create_and_add("drivers", NULL,
870 bus->drivers.kobj.parent = &bus->subsys.kobj; 891 &priv->subsys.kobj);
871 bus->drivers.ktype = &driver_ktype; 892 if (!priv->drivers_kset) {
872 retval = kset_register(&bus->drivers); 893 retval = -ENOMEM;
873 if (retval)
874 goto bus_drivers_fail; 894 goto bus_drivers_fail;
895 }
875 896
876 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); 897 klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put);
877 klist_init(&bus->klist_drivers, NULL, NULL); 898 klist_init(&priv->klist_drivers, NULL, NULL);
878 899
879 bus->drivers_autoprobe = 1;
880 retval = add_probe_files(bus); 900 retval = add_probe_files(bus);
881 if (retval) 901 if (retval)
882 goto bus_probe_files_fail; 902 goto bus_probe_files_fail;
@@ -885,66 +905,73 @@ int bus_register(struct bus_type * bus)
885 if (retval) 905 if (retval)
886 goto bus_attrs_fail; 906 goto bus_attrs_fail;
887 907
888 pr_debug("bus type '%s' registered\n", bus->name); 908 pr_debug("bus: '%s': registered\n", bus->name);
889 return 0; 909 return 0;
890 910
891bus_attrs_fail: 911bus_attrs_fail:
892 remove_probe_files(bus); 912 remove_probe_files(bus);
893bus_probe_files_fail: 913bus_probe_files_fail:
894 kset_unregister(&bus->drivers); 914 kset_unregister(bus->p->drivers_kset);
895bus_drivers_fail: 915bus_drivers_fail:
896 kset_unregister(&bus->devices); 916 kset_unregister(bus->p->devices_kset);
897bus_devices_fail: 917bus_devices_fail:
898 bus_remove_file(bus, &bus_attr_uevent); 918 bus_remove_file(bus, &bus_attr_uevent);
899bus_uevent_fail: 919bus_uevent_fail:
900 subsystem_unregister(&bus->subsys); 920 kset_unregister(&bus->p->subsys);
921 kfree(bus->p);
901out: 922out:
902 return retval; 923 return retval;
903} 924}
925EXPORT_SYMBOL_GPL(bus_register);
904 926
905/** 927/**
906 * bus_unregister - remove a bus from the system 928 * bus_unregister - remove a bus from the system
907 * @bus: bus. 929 * @bus: bus.
908 * 930 *
909 * Unregister the child subsystems and the bus itself. 931 * Unregister the child subsystems and the bus itself.
910 * Finally, we call bus_put() to release the refcount 932 * Finally, we call bus_put() to release the refcount
911 */ 933 */
912void bus_unregister(struct bus_type * bus) 934void bus_unregister(struct bus_type *bus)
913{ 935{
914 pr_debug("bus %s: unregistering\n", bus->name); 936 pr_debug("bus: '%s': unregistering\n", bus->name);
915 bus_remove_attrs(bus); 937 bus_remove_attrs(bus);
916 remove_probe_files(bus); 938 remove_probe_files(bus);
917 kset_unregister(&bus->drivers); 939 kset_unregister(bus->p->drivers_kset);
918 kset_unregister(&bus->devices); 940 kset_unregister(bus->p->devices_kset);
919 bus_remove_file(bus, &bus_attr_uevent); 941 bus_remove_file(bus, &bus_attr_uevent);
920 subsystem_unregister(&bus->subsys); 942 kset_unregister(&bus->p->subsys);
943 kfree(bus->p);
921} 944}
945EXPORT_SYMBOL_GPL(bus_unregister);
922 946
923int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) 947int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
924{ 948{
925 return blocking_notifier_chain_register(&bus->bus_notifier, nb); 949 return blocking_notifier_chain_register(&bus->p->bus_notifier, nb);
926} 950}
927EXPORT_SYMBOL_GPL(bus_register_notifier); 951EXPORT_SYMBOL_GPL(bus_register_notifier);
928 952
929int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb) 953int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
930{ 954{
931 return blocking_notifier_chain_unregister(&bus->bus_notifier, nb); 955 return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb);
932} 956}
933EXPORT_SYMBOL_GPL(bus_unregister_notifier); 957EXPORT_SYMBOL_GPL(bus_unregister_notifier);
934 958
935int __init buses_init(void) 959struct kset *bus_get_kset(struct bus_type *bus)
936{ 960{
937 return subsystem_register(&bus_subsys); 961 return &bus->p->subsys;
938} 962}
963EXPORT_SYMBOL_GPL(bus_get_kset);
939 964
965struct klist *bus_get_device_klist(struct bus_type *bus)
966{
967 return &bus->p->klist_devices;
968}
969EXPORT_SYMBOL_GPL(bus_get_device_klist);
940 970
941EXPORT_SYMBOL_GPL(bus_for_each_dev); 971int __init buses_init(void)
942EXPORT_SYMBOL_GPL(bus_find_device); 972{
943EXPORT_SYMBOL_GPL(bus_for_each_drv); 973 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL);
944 974 if (!bus_kset)
945EXPORT_SYMBOL_GPL(bus_register); 975 return -ENOMEM;
946EXPORT_SYMBOL_GPL(bus_unregister); 976 return 0;
947EXPORT_SYMBOL_GPL(bus_rescan_devices); 977}
948
949EXPORT_SYMBOL_GPL(bus_create_file);
950EXPORT_SYMBOL_GPL(bus_remove_file);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index a863bb091e11..59cf35894cfc 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -17,16 +17,17 @@
17#include <linux/kdev_t.h> 17#include <linux/kdev_t.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/genhd.h>
20#include "base.h" 21#include "base.h"
21 22
22#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) 23#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
23#define to_class(obj) container_of(obj, struct class, subsys.kobj) 24#define to_class(obj) container_of(obj, struct class, subsys.kobj)
24 25
25static ssize_t 26static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
26class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 27 char *buf)
27{ 28{
28 struct class_attribute * class_attr = to_class_attr(attr); 29 struct class_attribute *class_attr = to_class_attr(attr);
29 struct class * dc = to_class(kobj); 30 struct class *dc = to_class(kobj);
30 ssize_t ret = -EIO; 31 ssize_t ret = -EIO;
31 32
32 if (class_attr->show) 33 if (class_attr->show)
@@ -34,12 +35,11 @@ class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
34 return ret; 35 return ret;
35} 36}
36 37
37static ssize_t 38static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
38class_attr_store(struct kobject * kobj, struct attribute * attr, 39 const char *buf, size_t count)
39 const char * buf, size_t count)
40{ 40{
41 struct class_attribute * class_attr = to_class_attr(attr); 41 struct class_attribute *class_attr = to_class_attr(attr);
42 struct class * dc = to_class(kobj); 42 struct class *dc = to_class(kobj);
43 ssize_t ret = -EIO; 43 ssize_t ret = -EIO;
44 44
45 if (class_attr->store) 45 if (class_attr->store)
@@ -47,7 +47,7 @@ class_attr_store(struct kobject * kobj, struct attribute * attr,
47 return ret; 47 return ret;
48} 48}
49 49
50static void class_release(struct kobject * kobj) 50static void class_release(struct kobject *kobj)
51{ 51{
52 struct class *class = to_class(kobj); 52 struct class *class = to_class(kobj);
53 53
@@ -71,20 +71,20 @@ static struct kobj_type class_ktype = {
71}; 71};
72 72
73/* Hotplug events for classes go to the class_obj subsys */ 73/* Hotplug events for classes go to the class_obj subsys */
74static decl_subsys(class, &class_ktype, NULL); 74static struct kset *class_kset;
75 75
76 76
77int class_create_file(struct class * cls, const struct class_attribute * attr) 77int class_create_file(struct class *cls, const struct class_attribute *attr)
78{ 78{
79 int error; 79 int error;
80 if (cls) { 80 if (cls)
81 error = sysfs_create_file(&cls->subsys.kobj, &attr->attr); 81 error = sysfs_create_file(&cls->subsys.kobj, &attr->attr);
82 } else 82 else
83 error = -EINVAL; 83 error = -EINVAL;
84 return error; 84 return error;
85} 85}
86 86
87void class_remove_file(struct class * cls, const struct class_attribute * attr) 87void class_remove_file(struct class *cls, const struct class_attribute *attr)
88{ 88{
89 if (cls) 89 if (cls)
90 sysfs_remove_file(&cls->subsys.kobj, &attr->attr); 90 sysfs_remove_file(&cls->subsys.kobj, &attr->attr);
@@ -93,48 +93,48 @@ void class_remove_file(struct class * cls, const struct class_attribute * attr)
93static struct class *class_get(struct class *cls) 93static struct class *class_get(struct class *cls)
94{ 94{
95 if (cls) 95 if (cls)
96 return container_of(kset_get(&cls->subsys), struct class, subsys); 96 return container_of(kset_get(&cls->subsys),
97 struct class, subsys);
97 return NULL; 98 return NULL;
98} 99}
99 100
100static void class_put(struct class * cls) 101static void class_put(struct class *cls)
101{ 102{
102 if (cls) 103 if (cls)
103 kset_put(&cls->subsys); 104 kset_put(&cls->subsys);
104} 105}
105 106
106 107static int add_class_attrs(struct class *cls)
107static int add_class_attrs(struct class * cls)
108{ 108{
109 int i; 109 int i;
110 int error = 0; 110 int error = 0;
111 111
112 if (cls->class_attrs) { 112 if (cls->class_attrs) {
113 for (i = 0; attr_name(cls->class_attrs[i]); i++) { 113 for (i = 0; attr_name(cls->class_attrs[i]); i++) {
114 error = class_create_file(cls,&cls->class_attrs[i]); 114 error = class_create_file(cls, &cls->class_attrs[i]);
115 if (error) 115 if (error)
116 goto Err; 116 goto error;
117 } 117 }
118 } 118 }
119 Done: 119done:
120 return error; 120 return error;
121 Err: 121error:
122 while (--i >= 0) 122 while (--i >= 0)
123 class_remove_file(cls,&cls->class_attrs[i]); 123 class_remove_file(cls, &cls->class_attrs[i]);
124 goto Done; 124 goto done;
125} 125}
126 126
127static void remove_class_attrs(struct class * cls) 127static void remove_class_attrs(struct class *cls)
128{ 128{
129 int i; 129 int i;
130 130
131 if (cls->class_attrs) { 131 if (cls->class_attrs) {
132 for (i = 0; attr_name(cls->class_attrs[i]); i++) 132 for (i = 0; attr_name(cls->class_attrs[i]); i++)
133 class_remove_file(cls,&cls->class_attrs[i]); 133 class_remove_file(cls, &cls->class_attrs[i]);
134 } 134 }
135} 135}
136 136
137int class_register(struct class * cls) 137int class_register(struct class *cls)
138{ 138{
139 int error; 139 int error;
140 140
@@ -149,9 +149,16 @@ int class_register(struct class * cls)
149 if (error) 149 if (error)
150 return error; 150 return error;
151 151
152 cls->subsys.kobj.kset = &class_subsys; 152#ifdef CONFIG_SYSFS_DEPRECATED
153 /* let the block class directory show up in the root of sysfs */
154 if (cls != &block_class)
155 cls->subsys.kobj.kset = class_kset;
156#else
157 cls->subsys.kobj.kset = class_kset;
158#endif
159 cls->subsys.kobj.ktype = &class_ktype;
153 160
154 error = subsystem_register(&cls->subsys); 161 error = kset_register(&cls->subsys);
155 if (!error) { 162 if (!error) {
156 error = add_class_attrs(class_get(cls)); 163 error = add_class_attrs(class_get(cls));
157 class_put(cls); 164 class_put(cls);
@@ -159,11 +166,11 @@ int class_register(struct class * cls)
159 return error; 166 return error;
160} 167}
161 168
162void class_unregister(struct class * cls) 169void class_unregister(struct class *cls)
163{ 170{
164 pr_debug("device class '%s': unregistering\n", cls->name); 171 pr_debug("device class '%s': unregistering\n", cls->name);
165 remove_class_attrs(cls); 172 remove_class_attrs(cls);
166 subsystem_unregister(&cls->subsys); 173 kset_unregister(&cls->subsys);
167} 174}
168 175
169static void class_create_release(struct class *cls) 176static void class_create_release(struct class *cls)
@@ -241,8 +248,8 @@ void class_destroy(struct class *cls)
241 248
242/* Class Device Stuff */ 249/* Class Device Stuff */
243 250
244int class_device_create_file(struct class_device * class_dev, 251int class_device_create_file(struct class_device *class_dev,
245 const struct class_device_attribute * attr) 252 const struct class_device_attribute *attr)
246{ 253{
247 int error = -EINVAL; 254 int error = -EINVAL;
248 if (class_dev) 255 if (class_dev)
@@ -250,8 +257,8 @@ int class_device_create_file(struct class_device * class_dev,
250 return error; 257 return error;
251} 258}
252 259
253void class_device_remove_file(struct class_device * class_dev, 260void class_device_remove_file(struct class_device *class_dev,
254 const struct class_device_attribute * attr) 261 const struct class_device_attribute *attr)
255{ 262{
256 if (class_dev) 263 if (class_dev)
257 sysfs_remove_file(&class_dev->kobj, &attr->attr); 264 sysfs_remove_file(&class_dev->kobj, &attr->attr);
@@ -273,12 +280,11 @@ void class_device_remove_bin_file(struct class_device *class_dev,
273 sysfs_remove_bin_file(&class_dev->kobj, attr); 280 sysfs_remove_bin_file(&class_dev->kobj, attr);
274} 281}
275 282
276static ssize_t 283static ssize_t class_device_attr_show(struct kobject *kobj,
277class_device_attr_show(struct kobject * kobj, struct attribute * attr, 284 struct attribute *attr, char *buf)
278 char * buf)
279{ 285{
280 struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); 286 struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
281 struct class_device * cd = to_class_dev(kobj); 287 struct class_device *cd = to_class_dev(kobj);
282 ssize_t ret = 0; 288 ssize_t ret = 0;
283 289
284 if (class_dev_attr->show) 290 if (class_dev_attr->show)
@@ -286,12 +292,12 @@ class_device_attr_show(struct kobject * kobj, struct attribute * attr,
286 return ret; 292 return ret;
287} 293}
288 294
289static ssize_t 295static ssize_t class_device_attr_store(struct kobject *kobj,
290class_device_attr_store(struct kobject * kobj, struct attribute * attr, 296 struct attribute *attr,
291 const char * buf, size_t count) 297 const char *buf, size_t count)
292{ 298{
293 struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); 299 struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
294 struct class_device * cd = to_class_dev(kobj); 300 struct class_device *cd = to_class_dev(kobj);
295 ssize_t ret = 0; 301 ssize_t ret = 0;
296 302
297 if (class_dev_attr->store) 303 if (class_dev_attr->store)
@@ -304,10 +310,10 @@ static struct sysfs_ops class_dev_sysfs_ops = {
304 .store = class_device_attr_store, 310 .store = class_device_attr_store,
305}; 311};
306 312
307static void class_dev_release(struct kobject * kobj) 313static void class_dev_release(struct kobject *kobj)
308{ 314{
309 struct class_device *cd = to_class_dev(kobj); 315 struct class_device *cd = to_class_dev(kobj);
310 struct class * cls = cd->class; 316 struct class *cls = cd->class;
311 317
312 pr_debug("device class '%s': release.\n", cd->class_id); 318 pr_debug("device class '%s': release.\n", cd->class_id);
313 319
@@ -316,8 +322,8 @@ static void class_dev_release(struct kobject * kobj)
316 else if (cls->release) 322 else if (cls->release)
317 cls->release(cd); 323 cls->release(cd);
318 else { 324 else {
319 printk(KERN_ERR "Class Device '%s' does not have a release() function, " 325 printk(KERN_ERR "Class Device '%s' does not have a release() "
320 "it is broken and must be fixed.\n", 326 "function, it is broken and must be fixed.\n",
321 cd->class_id); 327 cd->class_id);
322 WARN_ON(1); 328 WARN_ON(1);
323 } 329 }
@@ -428,7 +434,8 @@ static int class_uevent(struct kset *kset, struct kobject *kobj,
428 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); 434 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
429 435
430 if (dev->driver) 436 if (dev->driver)
431 add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); 437 add_uevent_var(env, "PHYSDEVDRIVER=%s",
438 dev->driver->name);
432 } 439 }
433 440
434 if (class_dev->uevent) { 441 if (class_dev->uevent) {
@@ -452,43 +459,49 @@ static struct kset_uevent_ops class_uevent_ops = {
452 .uevent = class_uevent, 459 .uevent = class_uevent,
453}; 460};
454 461
455static decl_subsys(class_obj, &class_device_ktype, &class_uevent_ops); 462/*
456 463 * DO NOT copy how this is created, kset_create_and_add() should be
464 * called, but this is a hold-over from the old-way and will be deleted
465 * entirely soon.
466 */
467static struct kset class_obj_subsys = {
468 .uevent_ops = &class_uevent_ops,
469};
457 470
458static int class_device_add_attrs(struct class_device * cd) 471static int class_device_add_attrs(struct class_device *cd)
459{ 472{
460 int i; 473 int i;
461 int error = 0; 474 int error = 0;
462 struct class * cls = cd->class; 475 struct class *cls = cd->class;
463 476
464 if (cls->class_dev_attrs) { 477 if (cls->class_dev_attrs) {
465 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { 478 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) {
466 error = class_device_create_file(cd, 479 error = class_device_create_file(cd,
467 &cls->class_dev_attrs[i]); 480 &cls->class_dev_attrs[i]);
468 if (error) 481 if (error)
469 goto Err; 482 goto err;
470 } 483 }
471 } 484 }
472 Done: 485done:
473 return error; 486 return error;
474 Err: 487err:
475 while (--i >= 0) 488 while (--i >= 0)
476 class_device_remove_file(cd,&cls->class_dev_attrs[i]); 489 class_device_remove_file(cd, &cls->class_dev_attrs[i]);
477 goto Done; 490 goto done;
478} 491}
479 492
480static void class_device_remove_attrs(struct class_device * cd) 493static void class_device_remove_attrs(struct class_device *cd)
481{ 494{
482 int i; 495 int i;
483 struct class * cls = cd->class; 496 struct class *cls = cd->class;
484 497
485 if (cls->class_dev_attrs) { 498 if (cls->class_dev_attrs) {
486 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) 499 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++)
487 class_device_remove_file(cd,&cls->class_dev_attrs[i]); 500 class_device_remove_file(cd, &cls->class_dev_attrs[i]);
488 } 501 }
489} 502}
490 503
491static int class_device_add_groups(struct class_device * cd) 504static int class_device_add_groups(struct class_device *cd)
492{ 505{
493 int i; 506 int i;
494 int error = 0; 507 int error = 0;
@@ -498,7 +511,8 @@ static int class_device_add_groups(struct class_device * cd)
498 error = sysfs_create_group(&cd->kobj, cd->groups[i]); 511 error = sysfs_create_group(&cd->kobj, cd->groups[i]);
499 if (error) { 512 if (error) {
500 while (--i >= 0) 513 while (--i >= 0)
501 sysfs_remove_group(&cd->kobj, cd->groups[i]); 514 sysfs_remove_group(&cd->kobj,
515 cd->groups[i]);
502 goto out; 516 goto out;
503 } 517 }
504 } 518 }
@@ -507,14 +521,12 @@ out:
507 return error; 521 return error;
508} 522}
509 523
510static void class_device_remove_groups(struct class_device * cd) 524static void class_device_remove_groups(struct class_device *cd)
511{ 525{
512 int i; 526 int i;
513 if (cd->groups) { 527 if (cd->groups)
514 for (i = 0; cd->groups[i]; i++) { 528 for (i = 0; cd->groups[i]; i++)
515 sysfs_remove_group(&cd->kobj, cd->groups[i]); 529 sysfs_remove_group(&cd->kobj, cd->groups[i]);
516 }
517 }
518} 530}
519 531
520static ssize_t show_dev(struct class_device *class_dev, char *buf) 532static ssize_t show_dev(struct class_device *class_dev, char *buf)
@@ -537,8 +549,8 @@ static struct class_device_attribute class_uevent_attr =
537 549
538void class_device_initialize(struct class_device *class_dev) 550void class_device_initialize(struct class_device *class_dev)
539{ 551{
540 kobj_set_kset_s(class_dev, class_obj_subsys); 552 class_dev->kobj.kset = &class_obj_subsys;
541 kobject_init(&class_dev->kobj); 553 kobject_init(&class_dev->kobj, &class_device_ktype);
542 INIT_LIST_HEAD(&class_dev->node); 554 INIT_LIST_HEAD(&class_dev->node);
543} 555}
544 556
@@ -566,16 +578,13 @@ int class_device_add(struct class_device *class_dev)
566 class_dev->class_id); 578 class_dev->class_id);
567 579
568 /* first, register with generic layer. */ 580 /* first, register with generic layer. */
569 error = kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
570 if (error)
571 goto out2;
572
573 if (parent_class_dev) 581 if (parent_class_dev)
574 class_dev->kobj.parent = &parent_class_dev->kobj; 582 class_dev->kobj.parent = &parent_class_dev->kobj;
575 else 583 else
576 class_dev->kobj.parent = &parent_class->subsys.kobj; 584 class_dev->kobj.parent = &parent_class->subsys.kobj;
577 585
578 error = kobject_add(&class_dev->kobj); 586 error = kobject_add(&class_dev->kobj, class_dev->kobj.parent,
587 "%s", class_dev->class_id);
579 if (error) 588 if (error)
580 goto out2; 589 goto out2;
581 590
@@ -642,7 +651,7 @@ int class_device_add(struct class_device *class_dev)
642 out3: 651 out3:
643 kobject_del(&class_dev->kobj); 652 kobject_del(&class_dev->kobj);
644 out2: 653 out2:
645 if(parent_class_dev) 654 if (parent_class_dev)
646 class_device_put(parent_class_dev); 655 class_device_put(parent_class_dev);
647 class_put(parent_class); 656 class_put(parent_class);
648 out1: 657 out1:
@@ -659,9 +668,11 @@ int class_device_register(struct class_device *class_dev)
659/** 668/**
660 * class_device_create - creates a class device and registers it with sysfs 669 * class_device_create - creates a class device and registers it with sysfs
661 * @cls: pointer to the struct class that this device should be registered to. 670 * @cls: pointer to the struct class that this device should be registered to.
662 * @parent: pointer to the parent struct class_device of this new device, if any. 671 * @parent: pointer to the parent struct class_device of this new device, if
672 * any.
663 * @devt: the dev_t for the char device to be added. 673 * @devt: the dev_t for the char device to be added.
664 * @device: a pointer to a struct device that is assiociated with this class device. 674 * @device: a pointer to a struct device that is assiociated with this class
675 * device.
665 * @fmt: string for the class device's name 676 * @fmt: string for the class device's name
666 * 677 *
667 * This function can be used by char device classes. A struct 678 * This function can be used by char device classes. A struct
@@ -785,7 +796,7 @@ void class_device_destroy(struct class *cls, dev_t devt)
785 class_device_unregister(class_dev); 796 class_device_unregister(class_dev);
786} 797}
787 798
788struct class_device * class_device_get(struct class_device *class_dev) 799struct class_device *class_device_get(struct class_device *class_dev)
789{ 800{
790 if (class_dev) 801 if (class_dev)
791 return to_class_dev(kobject_get(&class_dev->kobj)); 802 return to_class_dev(kobject_get(&class_dev->kobj));
@@ -798,6 +809,139 @@ void class_device_put(struct class_device *class_dev)
798 kobject_put(&class_dev->kobj); 809 kobject_put(&class_dev->kobj);
799} 810}
800 811
812/**
813 * class_for_each_device - device iterator
814 * @class: the class we're iterating
815 * @data: data for the callback
816 * @fn: function to be called for each device
817 *
818 * Iterate over @class's list of devices, and call @fn for each,
819 * passing it @data.
820 *
821 * We check the return of @fn each time. If it returns anything
822 * other than 0, we break out and return that value.
823 *
824 * Note, we hold class->sem in this function, so it can not be
825 * re-acquired in @fn, otherwise it will self-deadlocking. For
826 * example, calls to add or remove class members would be verboten.
827 */
828int class_for_each_device(struct class *class, void *data,
829 int (*fn)(struct device *, void *))
830{
831 struct device *dev;
832 int error = 0;
833
834 if (!class)
835 return -EINVAL;
836 down(&class->sem);
837 list_for_each_entry(dev, &class->devices, node) {
838 dev = get_device(dev);
839 if (dev) {
840 error = fn(dev, data);
841 put_device(dev);
842 } else
843 error = -ENODEV;
844 if (error)
845 break;
846 }
847 up(&class->sem);
848
849 return error;
850}
851EXPORT_SYMBOL_GPL(class_for_each_device);
852
853/**
854 * class_find_device - device iterator for locating a particular device
855 * @class: the class we're iterating
856 * @data: data for the match function
857 * @match: function to check device
858 *
859 * This is similar to the class_for_each_dev() function above, but it
860 * returns a reference to a device that is 'found' for later use, as
861 * determined by the @match callback.
862 *
863 * The callback should return 0 if the device doesn't match and non-zero
864 * if it does. If the callback returns non-zero, this function will
865 * return to the caller and not iterate over any more devices.
866
867 * Note, you will need to drop the reference with put_device() after use.
868 *
869 * We hold class->sem in this function, so it can not be
870 * re-acquired in @match, otherwise it will self-deadlocking. For
871 * example, calls to add or remove class members would be verboten.
872 */
873struct device *class_find_device(struct class *class, void *data,
874 int (*match)(struct device *, void *))
875{
876 struct device *dev;
877 int found = 0;
878
879 if (!class)
880 return NULL;
881
882 down(&class->sem);
883 list_for_each_entry(dev, &class->devices, node) {
884 dev = get_device(dev);
885 if (dev) {
886 if (match(dev, data)) {
887 found = 1;
888 break;
889 } else
890 put_device(dev);
891 } else
892 break;
893 }
894 up(&class->sem);
895
896 return found ? dev : NULL;
897}
898EXPORT_SYMBOL_GPL(class_find_device);
899
900/**
901 * class_find_child - device iterator for locating a particular class_device
902 * @class: the class we're iterating
903 * @data: data for the match function
904 * @match: function to check class_device
905 *
906 * This function returns a reference to a class_device that is 'found' for
907 * later use, as determined by the @match callback.
908 *
909 * The callback should return 0 if the class_device doesn't match and non-zero
910 * if it does. If the callback returns non-zero, this function will
911 * return to the caller and not iterate over any more class_devices.
912 *
913 * Note, you will need to drop the reference with class_device_put() after use.
914 *
915 * We hold class->sem in this function, so it can not be
916 * re-acquired in @match, otherwise it will self-deadlocking. For
917 * example, calls to add or remove class members would be verboten.
918 */
919struct class_device *class_find_child(struct class *class, void *data,
920 int (*match)(struct class_device *, void *))
921{
922 struct class_device *dev;
923 int found = 0;
924
925 if (!class)
926 return NULL;
927
928 down(&class->sem);
929 list_for_each_entry(dev, &class->children, node) {
930 dev = class_device_get(dev);
931 if (dev) {
932 if (match(dev, data)) {
933 found = 1;
934 break;
935 } else
936 class_device_put(dev);
937 } else
938 break;
939 }
940 up(&class->sem);
941
942 return found ? dev : NULL;
943}
944EXPORT_SYMBOL_GPL(class_find_child);
801 945
802int class_interface_register(struct class_interface *class_intf) 946int class_interface_register(struct class_interface *class_intf)
803{ 947{
@@ -829,7 +973,7 @@ int class_interface_register(struct class_interface *class_intf)
829 973
830void class_interface_unregister(struct class_interface *class_intf) 974void class_interface_unregister(struct class_interface *class_intf)
831{ 975{
832 struct class * parent = class_intf->class; 976 struct class *parent = class_intf->class;
833 struct class_device *class_dev; 977 struct class_device *class_dev;
834 struct device *dev; 978 struct device *dev;
835 979
@@ -853,15 +997,14 @@ void class_interface_unregister(struct class_interface *class_intf)
853 997
854int __init classes_init(void) 998int __init classes_init(void)
855{ 999{
856 int retval; 1000 class_kset = kset_create_and_add("class", NULL, NULL);
857 1001 if (!class_kset)
858 retval = subsystem_register(&class_subsys); 1002 return -ENOMEM;
859 if (retval)
860 return retval;
861 1003
862 /* ick, this is ugly, the things we go through to keep from showing up 1004 /* ick, this is ugly, the things we go through to keep from showing up
863 * in sysfs... */ 1005 * in sysfs... */
864 kset_init(&class_obj_subsys); 1006 kset_init(&class_obj_subsys);
1007 kobject_set_name(&class_obj_subsys.kobj, "class_obj");
865 if (!class_obj_subsys.kobj.parent) 1008 if (!class_obj_subsys.kobj.parent)
866 class_obj_subsys.kobj.parent = &class_obj_subsys.kobj; 1009 class_obj_subsys.kobj.parent = &class_obj_subsys.kobj;
867 return 0; 1010 return 0;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2683eac30c68..edf3bbeb8d6a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -18,14 +18,14 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/kdev_t.h> 19#include <linux/kdev_t.h>
20#include <linux/notifier.h> 20#include <linux/notifier.h>
21 21#include <linux/genhd.h>
22#include <asm/semaphore.h> 22#include <asm/semaphore.h>
23 23
24#include "base.h" 24#include "base.h"
25#include "power/power.h" 25#include "power/power.h"
26 26
27int (*platform_notify)(struct device * dev) = NULL; 27int (*platform_notify)(struct device *dev) = NULL;
28int (*platform_notify_remove)(struct device * dev) = NULL; 28int (*platform_notify_remove)(struct device *dev) = NULL;
29 29
30/* 30/*
31 * sysfs bindings for devices. 31 * sysfs bindings for devices.
@@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string);
51#define to_dev(obj) container_of(obj, struct device, kobj) 51#define to_dev(obj) container_of(obj, struct device, kobj)
52#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) 52#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
53 53
54static ssize_t 54static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
55dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 55 char *buf)
56{ 56{
57 struct device_attribute * dev_attr = to_dev_attr(attr); 57 struct device_attribute *dev_attr = to_dev_attr(attr);
58 struct device * dev = to_dev(kobj); 58 struct device *dev = to_dev(kobj);
59 ssize_t ret = -EIO; 59 ssize_t ret = -EIO;
60 60
61 if (dev_attr->show) 61 if (dev_attr->show)
@@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
63 return ret; 63 return ret;
64} 64}
65 65
66static ssize_t 66static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
67dev_attr_store(struct kobject * kobj, struct attribute * attr, 67 const char *buf, size_t count)
68 const char * buf, size_t count)
69{ 68{
70 struct device_attribute * dev_attr = to_dev_attr(attr); 69 struct device_attribute *dev_attr = to_dev_attr(attr);
71 struct device * dev = to_dev(kobj); 70 struct device *dev = to_dev(kobj);
72 ssize_t ret = -EIO; 71 ssize_t ret = -EIO;
73 72
74 if (dev_attr->store) 73 if (dev_attr->store)
@@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = {
90 * reaches 0. We forward the call to the device's release 89 * reaches 0. We forward the call to the device's release
91 * method, which should handle actually freeing the structure. 90 * method, which should handle actually freeing the structure.
92 */ 91 */
93static void device_release(struct kobject * kobj) 92static void device_release(struct kobject *kobj)
94{ 93{
95 struct device * dev = to_dev(kobj); 94 struct device *dev = to_dev(kobj);
96 95
97 if (dev->release) 96 if (dev->release)
98 dev->release(dev); 97 dev->release(dev);
@@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj)
101 else if (dev->class && dev->class->dev_release) 100 else if (dev->class && dev->class->dev_release)
102 dev->class->dev_release(dev); 101 dev->class->dev_release(dev);
103 else { 102 else {
104 printk(KERN_ERR "Device '%s' does not have a release() function, " 103 printk(KERN_ERR "Device '%s' does not have a release() "
105 "it is broken and must be fixed.\n", 104 "function, it is broken and must be fixed.\n",
106 dev->bus_id); 105 dev->bus_id);
107 WARN_ON(1); 106 WARN_ON(1);
108 } 107 }
@@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
185 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); 184 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
186 185
187 if (dev->driver) 186 if (dev->driver)
188 add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); 187 add_uevent_var(env, "PHYSDEVDRIVER=%s",
188 dev->driver->name);
189 } 189 }
190#endif 190#endif
191 191
@@ -193,15 +193,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
193 if (dev->bus && dev->bus->uevent) { 193 if (dev->bus && dev->bus->uevent) {
194 retval = dev->bus->uevent(dev, env); 194 retval = dev->bus->uevent(dev, env);
195 if (retval) 195 if (retval)
196 pr_debug ("%s: bus uevent() returned %d\n", 196 pr_debug("device: '%s': %s: bus uevent() returned %d\n",
197 __FUNCTION__, retval); 197 dev->bus_id, __FUNCTION__, retval);
198 } 198 }
199 199
200 /* have the class specific function add its stuff */ 200 /* have the class specific function add its stuff */
201 if (dev->class && dev->class->dev_uevent) { 201 if (dev->class && dev->class->dev_uevent) {
202 retval = dev->class->dev_uevent(dev, env); 202 retval = dev->class->dev_uevent(dev, env);
203 if (retval) 203 if (retval)
204 pr_debug("%s: class uevent() returned %d\n", 204 pr_debug("device: '%s': %s: class uevent() "
205 "returned %d\n", dev->bus_id,
205 __FUNCTION__, retval); 206 __FUNCTION__, retval);
206 } 207 }
207 208
@@ -209,7 +210,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
209 if (dev->type && dev->type->uevent) { 210 if (dev->type && dev->type->uevent) {
210 retval = dev->type->uevent(dev, env); 211 retval = dev->type->uevent(dev, env);
211 if (retval) 212 if (retval)
212 pr_debug("%s: dev_type uevent() returned %d\n", 213 pr_debug("device: '%s': %s: dev_type uevent() "
214 "returned %d\n", dev->bus_id,
213 __FUNCTION__, retval); 215 __FUNCTION__, retval);
214 } 216 }
215 217
@@ -325,7 +327,8 @@ static int device_add_groups(struct device *dev,
325 error = sysfs_create_group(&dev->kobj, groups[i]); 327 error = sysfs_create_group(&dev->kobj, groups[i]);
326 if (error) { 328 if (error) {
327 while (--i >= 0) 329 while (--i >= 0)
328 sysfs_remove_group(&dev->kobj, groups[i]); 330 sysfs_remove_group(&dev->kobj,
331 groups[i]);
329 break; 332 break;
330 } 333 }
331 } 334 }
@@ -401,20 +404,15 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
401static struct device_attribute devt_attr = 404static struct device_attribute devt_attr =
402 __ATTR(dev, S_IRUGO, show_dev, NULL); 405 __ATTR(dev, S_IRUGO, show_dev, NULL);
403 406
404/* 407/* kset to create /sys/devices/ */
405 * devices_subsys - structure to be registered with kobject core. 408struct kset *devices_kset;
406 */
407
408decl_subsys(devices, &device_ktype, &device_uevent_ops);
409
410 409
411/** 410/**
412 * device_create_file - create sysfs attribute file for device. 411 * device_create_file - create sysfs attribute file for device.
413 * @dev: device. 412 * @dev: device.
414 * @attr: device attribute descriptor. 413 * @attr: device attribute descriptor.
415 */ 414 */
416 415int device_create_file(struct device *dev, struct device_attribute *attr)
417int device_create_file(struct device * dev, struct device_attribute * attr)
418{ 416{
419 int error = 0; 417 int error = 0;
420 if (get_device(dev)) { 418 if (get_device(dev)) {
@@ -425,12 +423,11 @@ int device_create_file(struct device * dev, struct device_attribute * attr)
425} 423}
426 424
427/** 425/**
428 * device_remove_file - remove sysfs attribute file. 426 * device_remove_file - remove sysfs attribute file.
429 * @dev: device. 427 * @dev: device.
430 * @attr: device attribute descriptor. 428 * @attr: device attribute descriptor.
431 */ 429 */
432 430void device_remove_file(struct device *dev, struct device_attribute *attr)
433void device_remove_file(struct device * dev, struct device_attribute * attr)
434{ 431{
435 if (get_device(dev)) { 432 if (get_device(dev)) {
436 sysfs_remove_file(&dev->kobj, &attr->attr); 433 sysfs_remove_file(&dev->kobj, &attr->attr);
@@ -511,22 +508,20 @@ static void klist_children_put(struct klist_node *n)
511 put_device(dev); 508 put_device(dev);
512} 509}
513 510
514
515/** 511/**
516 * device_initialize - init device structure. 512 * device_initialize - init device structure.
517 * @dev: device. 513 * @dev: device.
518 * 514 *
519 * This prepares the device for use by other layers, 515 * This prepares the device for use by other layers,
520 * including adding it to the device hierarchy. 516 * including adding it to the device hierarchy.
521 * It is the first half of device_register(), if called by 517 * It is the first half of device_register(), if called by
522 * that, though it can also be called separately, so one 518 * that, though it can also be called separately, so one
523 * may use @dev's fields (e.g. the refcount). 519 * may use @dev's fields (e.g. the refcount).
524 */ 520 */
525
526void device_initialize(struct device *dev) 521void device_initialize(struct device *dev)
527{ 522{
528 kobj_set_kset_s(dev, devices_subsys); 523 dev->kobj.kset = devices_kset;
529 kobject_init(&dev->kobj); 524 kobject_init(&dev->kobj, &device_ktype);
530 klist_init(&dev->klist_children, klist_children_get, 525 klist_init(&dev->klist_children, klist_children_get,
531 klist_children_put); 526 klist_children_put);
532 INIT_LIST_HEAD(&dev->dma_pools); 527 INIT_LIST_HEAD(&dev->dma_pools);
@@ -539,36 +534,39 @@ void device_initialize(struct device *dev)
539} 534}
540 535
541#ifdef CONFIG_SYSFS_DEPRECATED 536#ifdef CONFIG_SYSFS_DEPRECATED
542static struct kobject * get_device_parent(struct device *dev, 537static struct kobject *get_device_parent(struct device *dev,
543 struct device *parent) 538 struct device *parent)
544{ 539{
545 /* 540 /* class devices without a parent live in /sys/class/<classname>/ */
546 * Set the parent to the class, not the parent device
547 * for topmost devices in class hierarchy.
548 * This keeps sysfs from having a symlink to make old
549 * udevs happy
550 */
551 if (dev->class && (!parent || parent->class != dev->class)) 541 if (dev->class && (!parent || parent->class != dev->class))
552 return &dev->class->subsys.kobj; 542 return &dev->class->subsys.kobj;
543 /* all other devices keep their parent */
553 else if (parent) 544 else if (parent)
554 return &parent->kobj; 545 return &parent->kobj;
555 546
556 return NULL; 547 return NULL;
557} 548}
549
550static inline void cleanup_device_parent(struct device *dev) {}
551static inline void cleanup_glue_dir(struct device *dev,
552 struct kobject *glue_dir) {}
558#else 553#else
559static struct kobject *virtual_device_parent(struct device *dev) 554static struct kobject *virtual_device_parent(struct device *dev)
560{ 555{
561 static struct kobject *virtual_dir = NULL; 556 static struct kobject *virtual_dir = NULL;
562 557
563 if (!virtual_dir) 558 if (!virtual_dir)
564 virtual_dir = kobject_add_dir(&devices_subsys.kobj, "virtual"); 559 virtual_dir = kobject_create_and_add("virtual",
560 &devices_kset->kobj);
565 561
566 return virtual_dir; 562 return virtual_dir;
567} 563}
568 564
569static struct kobject * get_device_parent(struct device *dev, 565static struct kobject *get_device_parent(struct device *dev,
570 struct device *parent) 566 struct device *parent)
571{ 567{
568 int retval;
569
572 if (dev->class) { 570 if (dev->class) {
573 struct kobject *kobj = NULL; 571 struct kobject *kobj = NULL;
574 struct kobject *parent_kobj; 572 struct kobject *parent_kobj;
@@ -576,8 +574,8 @@ static struct kobject * get_device_parent(struct device *dev,
576 574
577 /* 575 /*
578 * If we have no parent, we live in "virtual". 576 * If we have no parent, we live in "virtual".
579 * Class-devices with a bus-device as parent, live 577 * Class-devices with a non class-device as parent, live
580 * in a class-directory to prevent namespace collisions. 578 * in a "glue" directory to prevent namespace collisions.
581 */ 579 */
582 if (parent == NULL) 580 if (parent == NULL)
583 parent_kobj = virtual_device_parent(dev); 581 parent_kobj = virtual_device_parent(dev);
@@ -598,25 +596,45 @@ static struct kobject * get_device_parent(struct device *dev,
598 return kobj; 596 return kobj;
599 597
600 /* or create a new class-directory at the parent device */ 598 /* or create a new class-directory at the parent device */
601 return kobject_kset_add_dir(&dev->class->class_dirs, 599 k = kobject_create();
602 parent_kobj, dev->class->name); 600 if (!k)
601 return NULL;
602 k->kset = &dev->class->class_dirs;
603 retval = kobject_add(k, parent_kobj, "%s", dev->class->name);
604 if (retval < 0) {
605 kobject_put(k);
606 return NULL;
607 }
608 /* do not emit an uevent for this simple "glue" directory */
609 return k;
603 } 610 }
604 611
605 if (parent) 612 if (parent)
606 return &parent->kobj; 613 return &parent->kobj;
607 return NULL; 614 return NULL;
608} 615}
616
617static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
618{
619 /* see if we live in a "glue" directory */
620 if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
621 return;
622
623 kobject_put(glue_dir);
624}
625
626static void cleanup_device_parent(struct device *dev)
627{
628 cleanup_glue_dir(dev, dev->kobj.parent);
629}
609#endif 630#endif
610 631
611static int setup_parent(struct device *dev, struct device *parent) 632static void setup_parent(struct device *dev, struct device *parent)
612{ 633{
613 struct kobject *kobj; 634 struct kobject *kobj;
614 kobj = get_device_parent(dev, parent); 635 kobj = get_device_parent(dev, parent);
615 if (IS_ERR(kobj))
616 return PTR_ERR(kobj);
617 if (kobj) 636 if (kobj)
618 dev->kobj.parent = kobj; 637 dev->kobj.parent = kobj;
619 return 0;
620} 638}
621 639
622static int device_add_class_symlinks(struct device *dev) 640static int device_add_class_symlinks(struct device *dev)
@@ -625,65 +643,76 @@ static int device_add_class_symlinks(struct device *dev)
625 643
626 if (!dev->class) 644 if (!dev->class)
627 return 0; 645 return 0;
646
628 error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj, 647 error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
629 "subsystem"); 648 "subsystem");
630 if (error) 649 if (error)
631 goto out; 650 goto out;
632 /* 651
633 * If this is not a "fake" compatible device, then create the 652#ifdef CONFIG_SYSFS_DEPRECATED
634 * symlink from the class to the device. 653 /* stacked class devices need a symlink in the class directory */
635 */ 654 if (dev->kobj.parent != &dev->class->subsys.kobj &&
636 if (dev->kobj.parent != &dev->class->subsys.kobj) { 655 dev->type != &part_type) {
637 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, 656 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
638 dev->bus_id); 657 dev->bus_id);
639 if (error) 658 if (error)
640 goto out_subsys; 659 goto out_subsys;
641 } 660 }
642 if (dev->parent) {
643#ifdef CONFIG_SYSFS_DEPRECATED
644 {
645 struct device *parent = dev->parent;
646 char *class_name;
647
648 /*
649 * In old sysfs stacked class devices had 'device'
650 * link pointing to real device instead of parent
651 */
652 while (parent->class && !parent->bus && parent->parent)
653 parent = parent->parent;
654
655 error = sysfs_create_link(&dev->kobj,
656 &parent->kobj,
657 "device");
658 if (error)
659 goto out_busid;
660 661
661 class_name = make_class_name(dev->class->name, 662 if (dev->parent && dev->type != &part_type) {
662 &dev->kobj); 663 struct device *parent = dev->parent;
663 if (class_name) 664 char *class_name;
664 error = sysfs_create_link(&dev->parent->kobj, 665
665 &dev->kobj, class_name); 666 /*
666 kfree(class_name); 667 * stacked class devices have the 'device' link
667 if (error) 668 * pointing to the bus device instead of the parent
668 goto out_device; 669 */
669 } 670 while (parent->class && !parent->bus && parent->parent)
670#else 671 parent = parent->parent;
671 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, 672
673 error = sysfs_create_link(&dev->kobj,
674 &parent->kobj,
672 "device"); 675 "device");
673 if (error) 676 if (error)
674 goto out_busid; 677 goto out_busid;
675#endif 678
679 class_name = make_class_name(dev->class->name,
680 &dev->kobj);
681 if (class_name)
682 error = sysfs_create_link(&dev->parent->kobj,
683 &dev->kobj, class_name);
684 kfree(class_name);
685 if (error)
686 goto out_device;
676 } 687 }
677 return 0; 688 return 0;
678 689
679#ifdef CONFIG_SYSFS_DEPRECATED
680out_device: 690out_device:
681 if (dev->parent) 691 if (dev->parent && dev->type != &part_type)
682 sysfs_remove_link(&dev->kobj, "device"); 692 sysfs_remove_link(&dev->kobj, "device");
683#endif
684out_busid: 693out_busid:
685 if (dev->kobj.parent != &dev->class->subsys.kobj) 694 if (dev->kobj.parent != &dev->class->subsys.kobj &&
695 dev->type != &part_type)
686 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 696 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
697#else
698 /* link in the class directory pointing to the device */
699 error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
700 dev->bus_id);
701 if (error)
702 goto out_subsys;
703
704 if (dev->parent && dev->type != &part_type) {
705 error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
706 "device");
707 if (error)
708 goto out_busid;
709 }
710 return 0;
711
712out_busid:
713 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
714#endif
715
687out_subsys: 716out_subsys:
688 sysfs_remove_link(&dev->kobj, "subsystem"); 717 sysfs_remove_link(&dev->kobj, "subsystem");
689out: 718out:
@@ -694,8 +723,9 @@ static void device_remove_class_symlinks(struct device *dev)
694{ 723{
695 if (!dev->class) 724 if (!dev->class)
696 return; 725 return;
697 if (dev->parent) { 726
698#ifdef CONFIG_SYSFS_DEPRECATED 727#ifdef CONFIG_SYSFS_DEPRECATED
728 if (dev->parent && dev->type != &part_type) {
699 char *class_name; 729 char *class_name;
700 730
701 class_name = make_class_name(dev->class->name, &dev->kobj); 731 class_name = make_class_name(dev->class->name, &dev->kobj);
@@ -703,45 +733,59 @@ static void device_remove_class_symlinks(struct device *dev)
703 sysfs_remove_link(&dev->parent->kobj, class_name); 733 sysfs_remove_link(&dev->parent->kobj, class_name);
704 kfree(class_name); 734 kfree(class_name);
705 } 735 }
706#endif
707 sysfs_remove_link(&dev->kobj, "device"); 736 sysfs_remove_link(&dev->kobj, "device");
708 } 737 }
709 if (dev->kobj.parent != &dev->class->subsys.kobj) 738
739 if (dev->kobj.parent != &dev->class->subsys.kobj &&
740 dev->type != &part_type)
710 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); 741 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
742#else
743 if (dev->parent && dev->type != &part_type)
744 sysfs_remove_link(&dev->kobj, "device");
745
746 sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
747#endif
748
711 sysfs_remove_link(&dev->kobj, "subsystem"); 749 sysfs_remove_link(&dev->kobj, "subsystem");
712} 750}
713 751
714/** 752/**
715 * device_add - add device to device hierarchy. 753 * device_add - add device to device hierarchy.
716 * @dev: device. 754 * @dev: device.
717 * 755 *
718 * This is part 2 of device_register(), though may be called 756 * This is part 2 of device_register(), though may be called
719 * separately _iff_ device_initialize() has been called separately. 757 * separately _iff_ device_initialize() has been called separately.
720 * 758 *
721 * This adds it to the kobject hierarchy via kobject_add(), adds it 759 * This adds it to the kobject hierarchy via kobject_add(), adds it
722 * to the global and sibling lists for the device, then 760 * to the global and sibling lists for the device, then
723 * adds it to the other relevant subsystems of the driver model. 761 * adds it to the other relevant subsystems of the driver model.
724 */ 762 */
725int device_add(struct device *dev) 763int device_add(struct device *dev)
726{ 764{
727 struct device *parent = NULL; 765 struct device *parent = NULL;
728 struct class_interface *class_intf; 766 struct class_interface *class_intf;
729 int error = -EINVAL; 767 int error;
768
769 error = pm_sleep_lock();
770 if (error) {
771 dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__);
772 dump_stack();
773 return error;
774 }
730 775
731 dev = get_device(dev); 776 dev = get_device(dev);
732 if (!dev || !strlen(dev->bus_id)) 777 if (!dev || !strlen(dev->bus_id)) {
778 error = -EINVAL;
733 goto Error; 779 goto Error;
780 }
734 781
735 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); 782 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
736 783
737 parent = get_device(dev->parent); 784 parent = get_device(dev->parent);
738 error = setup_parent(dev, parent); 785 setup_parent(dev, parent);
739 if (error)
740 goto Error;
741 786
742 /* first, register with generic layer. */ 787 /* first, register with generic layer. */
743 kobject_set_name(&dev->kobj, "%s", dev->bus_id); 788 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
744 error = kobject_add(&dev->kobj);
745 if (error) 789 if (error)
746 goto Error; 790 goto Error;
747 791
@@ -751,7 +795,7 @@ int device_add(struct device *dev)
751 795
752 /* notify clients of device entry (new way) */ 796 /* notify clients of device entry (new way) */
753 if (dev->bus) 797 if (dev->bus)
754 blocking_notifier_call_chain(&dev->bus->bus_notifier, 798 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
755 BUS_NOTIFY_ADD_DEVICE, dev); 799 BUS_NOTIFY_ADD_DEVICE, dev);
756 800
757 error = device_create_file(dev, &uevent_attr); 801 error = device_create_file(dev, &uevent_attr);
@@ -795,13 +839,14 @@ int device_add(struct device *dev)
795 } 839 }
796 Done: 840 Done:
797 put_device(dev); 841 put_device(dev);
842 pm_sleep_unlock();
798 return error; 843 return error;
799 BusError: 844 BusError:
800 device_pm_remove(dev); 845 device_pm_remove(dev);
801 dpm_sysfs_remove(dev); 846 dpm_sysfs_remove(dev);
802 PMError: 847 PMError:
803 if (dev->bus) 848 if (dev->bus)
804 blocking_notifier_call_chain(&dev->bus->bus_notifier, 849 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
805 BUS_NOTIFY_DEL_DEVICE, dev); 850 BUS_NOTIFY_DEL_DEVICE, dev);
806 device_remove_attrs(dev); 851 device_remove_attrs(dev);
807 AttrsError: 852 AttrsError:
@@ -809,124 +854,84 @@ int device_add(struct device *dev)
809 SymlinkError: 854 SymlinkError:
810 if (MAJOR(dev->devt)) 855 if (MAJOR(dev->devt))
811 device_remove_file(dev, &devt_attr); 856 device_remove_file(dev, &devt_attr);
812
813 if (dev->class) {
814 sysfs_remove_link(&dev->kobj, "subsystem");
815 /* If this is not a "fake" compatible device, remove the
816 * symlink from the class to the device. */
817 if (dev->kobj.parent != &dev->class->subsys.kobj)
818 sysfs_remove_link(&dev->class->subsys.kobj,
819 dev->bus_id);
820 if (parent) {
821#ifdef CONFIG_SYSFS_DEPRECATED
822 char *class_name = make_class_name(dev->class->name,
823 &dev->kobj);
824 if (class_name)
825 sysfs_remove_link(&dev->parent->kobj,
826 class_name);
827 kfree(class_name);
828#endif
829 sysfs_remove_link(&dev->kobj, "device");
830 }
831 }
832 ueventattrError: 857 ueventattrError:
833 device_remove_file(dev, &uevent_attr); 858 device_remove_file(dev, &uevent_attr);
834 attrError: 859 attrError:
835 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 860 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
836 kobject_del(&dev->kobj); 861 kobject_del(&dev->kobj);
837 Error: 862 Error:
863 cleanup_device_parent(dev);
838 if (parent) 864 if (parent)
839 put_device(parent); 865 put_device(parent);
840 goto Done; 866 goto Done;
841} 867}
842 868
843
844/** 869/**
845 * device_register - register a device with the system. 870 * device_register - register a device with the system.
846 * @dev: pointer to the device structure 871 * @dev: pointer to the device structure
847 * 872 *
848 * This happens in two clean steps - initialize the device 873 * This happens in two clean steps - initialize the device
849 * and add it to the system. The two steps can be called 874 * and add it to the system. The two steps can be called
850 * separately, but this is the easiest and most common. 875 * separately, but this is the easiest and most common.
851 * I.e. you should only call the two helpers separately if 876 * I.e. you should only call the two helpers separately if
852 * have a clearly defined need to use and refcount the device 877 * have a clearly defined need to use and refcount the device
853 * before it is added to the hierarchy. 878 * before it is added to the hierarchy.
854 */ 879 */
855
856int device_register(struct device *dev) 880int device_register(struct device *dev)
857{ 881{
858 device_initialize(dev); 882 device_initialize(dev);
859 return device_add(dev); 883 return device_add(dev);
860} 884}
861 885
862
863/** 886/**
864 * get_device - increment reference count for device. 887 * get_device - increment reference count for device.
865 * @dev: device. 888 * @dev: device.
866 * 889 *
867 * This simply forwards the call to kobject_get(), though 890 * This simply forwards the call to kobject_get(), though
868 * we do take care to provide for the case that we get a NULL 891 * we do take care to provide for the case that we get a NULL
869 * pointer passed in. 892 * pointer passed in.
870 */ 893 */
871 894struct device *get_device(struct device *dev)
872struct device * get_device(struct device * dev)
873{ 895{
874 return dev ? to_dev(kobject_get(&dev->kobj)) : NULL; 896 return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
875} 897}
876 898
877
878/** 899/**
879 * put_device - decrement reference count. 900 * put_device - decrement reference count.
880 * @dev: device in question. 901 * @dev: device in question.
881 */ 902 */
882void put_device(struct device * dev) 903void put_device(struct device *dev)
883{ 904{
905 /* might_sleep(); */
884 if (dev) 906 if (dev)
885 kobject_put(&dev->kobj); 907 kobject_put(&dev->kobj);
886} 908}
887 909
888
889/** 910/**
890 * device_del - delete device from system. 911 * device_del - delete device from system.
891 * @dev: device. 912 * @dev: device.
892 * 913 *
893 * This is the first part of the device unregistration 914 * This is the first part of the device unregistration
894 * sequence. This removes the device from the lists we control 915 * sequence. This removes the device from the lists we control
895 * from here, has it removed from the other driver model 916 * from here, has it removed from the other driver model
896 * subsystems it was added to in device_add(), and removes it 917 * subsystems it was added to in device_add(), and removes it
897 * from the kobject hierarchy. 918 * from the kobject hierarchy.
898 * 919 *
899 * NOTE: this should be called manually _iff_ device_add() was 920 * NOTE: this should be called manually _iff_ device_add() was
900 * also called manually. 921 * also called manually.
901 */ 922 */
902 923void device_del(struct device *dev)
903void device_del(struct device * dev)
904{ 924{
905 struct device * parent = dev->parent; 925 struct device *parent = dev->parent;
906 struct class_interface *class_intf; 926 struct class_interface *class_intf;
907 927
928 device_pm_remove(dev);
908 if (parent) 929 if (parent)
909 klist_del(&dev->knode_parent); 930 klist_del(&dev->knode_parent);
910 if (MAJOR(dev->devt)) 931 if (MAJOR(dev->devt))
911 device_remove_file(dev, &devt_attr); 932 device_remove_file(dev, &devt_attr);
912 if (dev->class) { 933 if (dev->class) {
913 sysfs_remove_link(&dev->kobj, "subsystem"); 934 device_remove_class_symlinks(dev);
914 /* If this is not a "fake" compatible device, remove the
915 * symlink from the class to the device. */
916 if (dev->kobj.parent != &dev->class->subsys.kobj)
917 sysfs_remove_link(&dev->class->subsys.kobj,
918 dev->bus_id);
919 if (parent) {
920#ifdef CONFIG_SYSFS_DEPRECATED
921 char *class_name = make_class_name(dev->class->name,
922 &dev->kobj);
923 if (class_name)
924 sysfs_remove_link(&dev->parent->kobj,
925 class_name);
926 kfree(class_name);
927#endif
928 sysfs_remove_link(&dev->kobj, "device");
929 }
930 935
931 down(&dev->class->sem); 936 down(&dev->class->sem);
932 /* notify any interfaces that the device is now gone */ 937 /* notify any interfaces that the device is now gone */
@@ -936,31 +941,6 @@ void device_del(struct device * dev)
936 /* remove the device from the class list */ 941 /* remove the device from the class list */
937 list_del_init(&dev->node); 942 list_del_init(&dev->node);
938 up(&dev->class->sem); 943 up(&dev->class->sem);
939
940 /* If we live in a parent class-directory, unreference it */
941 if (dev->kobj.parent->kset == &dev->class->class_dirs) {
942 struct device *d;
943 int other = 0;
944
945 /*
946 * if we are the last child of our class, delete
947 * our class-directory at this parent
948 */
949 down(&dev->class->sem);
950 list_for_each_entry(d, &dev->class->devices, node) {
951 if (d == dev)
952 continue;
953 if (d->kobj.parent == dev->kobj.parent) {
954 other = 1;
955 break;
956 }
957 }
958 if (!other)
959 kobject_del(dev->kobj.parent);
960
961 kobject_put(dev->kobj.parent);
962 up(&dev->class->sem);
963 }
964 } 944 }
965 device_remove_file(dev, &uevent_attr); 945 device_remove_file(dev, &uevent_attr);
966 device_remove_attrs(dev); 946 device_remove_attrs(dev);
@@ -979,57 +959,55 @@ void device_del(struct device * dev)
979 if (platform_notify_remove) 959 if (platform_notify_remove)
980 platform_notify_remove(dev); 960 platform_notify_remove(dev);
981 if (dev->bus) 961 if (dev->bus)
982 blocking_notifier_call_chain(&dev->bus->bus_notifier, 962 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
983 BUS_NOTIFY_DEL_DEVICE, dev); 963 BUS_NOTIFY_DEL_DEVICE, dev);
984 device_pm_remove(dev);
985 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 964 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
965 cleanup_device_parent(dev);
986 kobject_del(&dev->kobj); 966 kobject_del(&dev->kobj);
987 if (parent) 967 put_device(parent);
988 put_device(parent);
989} 968}
990 969
991/** 970/**
992 * device_unregister - unregister device from system. 971 * device_unregister - unregister device from system.
993 * @dev: device going away. 972 * @dev: device going away.
994 * 973 *
995 * We do this in two parts, like we do device_register(). First, 974 * We do this in two parts, like we do device_register(). First,
996 * we remove it from all the subsystems with device_del(), then 975 * we remove it from all the subsystems with device_del(), then
997 * we decrement the reference count via put_device(). If that 976 * we decrement the reference count via put_device(). If that
998 * is the final reference count, the device will be cleaned up 977 * is the final reference count, the device will be cleaned up
999 * via device_release() above. Otherwise, the structure will 978 * via device_release() above. Otherwise, the structure will
1000 * stick around until the final reference to the device is dropped. 979 * stick around until the final reference to the device is dropped.
1001 */ 980 */
1002void device_unregister(struct device * dev) 981void device_unregister(struct device *dev)
1003{ 982{
1004 pr_debug("DEV: Unregistering device. ID = '%s'\n", dev->bus_id); 983 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
1005 device_del(dev); 984 device_del(dev);
1006 put_device(dev); 985 put_device(dev);
1007} 986}
1008 987
1009 988static struct device *next_device(struct klist_iter *i)
1010static struct device * next_device(struct klist_iter * i)
1011{ 989{
1012 struct klist_node * n = klist_next(i); 990 struct klist_node *n = klist_next(i);
1013 return n ? container_of(n, struct device, knode_parent) : NULL; 991 return n ? container_of(n, struct device, knode_parent) : NULL;
1014} 992}
1015 993
1016/** 994/**
1017 * device_for_each_child - device child iterator. 995 * device_for_each_child - device child iterator.
1018 * @parent: parent struct device. 996 * @parent: parent struct device.
1019 * @data: data for the callback. 997 * @data: data for the callback.
1020 * @fn: function to be called for each device. 998 * @fn: function to be called for each device.
1021 * 999 *
1022 * Iterate over @parent's child devices, and call @fn for each, 1000 * Iterate over @parent's child devices, and call @fn for each,
1023 * passing it @data. 1001 * passing it @data.
1024 * 1002 *
1025 * We check the return of @fn each time. If it returns anything 1003 * We check the return of @fn each time. If it returns anything
1026 * other than 0, we break out and return that value. 1004 * other than 0, we break out and return that value.
1027 */ 1005 */
1028int device_for_each_child(struct device * parent, void * data, 1006int device_for_each_child(struct device *parent, void *data,
1029 int (*fn)(struct device *, void *)) 1007 int (*fn)(struct device *dev, void *data))
1030{ 1008{
1031 struct klist_iter i; 1009 struct klist_iter i;
1032 struct device * child; 1010 struct device *child;
1033 int error = 0; 1011 int error = 0;
1034 1012
1035 klist_iter_init(&parent->klist_children, &i); 1013 klist_iter_init(&parent->klist_children, &i);
@@ -1054,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data,
1054 * current device can be obtained, this function will return to the caller 1032 * current device can be obtained, this function will return to the caller
1055 * and not iterate over any more devices. 1033 * and not iterate over any more devices.
1056 */ 1034 */
1057struct device * device_find_child(struct device *parent, void *data, 1035struct device *device_find_child(struct device *parent, void *data,
1058 int (*match)(struct device *, void *)) 1036 int (*match)(struct device *dev, void *data))
1059{ 1037{
1060 struct klist_iter i; 1038 struct klist_iter i;
1061 struct device *child; 1039 struct device *child;
@@ -1073,7 +1051,10 @@ struct device * device_find_child(struct device *parent, void *data,
1073 1051
1074int __init devices_init(void) 1052int __init devices_init(void)
1075{ 1053{
1076 return subsystem_register(&devices_subsys); 1054 devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
1055 if (!devices_kset)
1056 return -ENOMEM;
1057 return 0;
1077} 1058}
1078 1059
1079EXPORT_SYMBOL_GPL(device_for_each_child); 1060EXPORT_SYMBOL_GPL(device_for_each_child);
@@ -1094,7 +1075,7 @@ EXPORT_SYMBOL_GPL(device_remove_file);
1094 1075
1095static void device_create_release(struct device *dev) 1076static void device_create_release(struct device *dev)
1096{ 1077{
1097 pr_debug("%s called for %s\n", __FUNCTION__, dev->bus_id); 1078 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
1098 kfree(dev); 1079 kfree(dev);
1099} 1080}
1100 1081
@@ -1156,14 +1137,11 @@ error:
1156EXPORT_SYMBOL_GPL(device_create); 1137EXPORT_SYMBOL_GPL(device_create);
1157 1138
1158/** 1139/**
1159 * device_destroy - removes a device that was created with device_create() 1140 * find_device - finds a device that was created with device_create()
1160 * @class: pointer to the struct class that this device was registered with 1141 * @class: pointer to the struct class that this device was registered with
1161 * @devt: the dev_t of the device that was previously registered 1142 * @devt: the dev_t of the device that was previously registered
1162 *
1163 * This call unregisters and cleans up a device that was created with a
1164 * call to device_create().
1165 */ 1143 */
1166void device_destroy(struct class *class, dev_t devt) 1144static struct device *find_device(struct class *class, dev_t devt)
1167{ 1145{
1168 struct device *dev = NULL; 1146 struct device *dev = NULL;
1169 struct device *dev_tmp; 1147 struct device *dev_tmp;
@@ -1176,12 +1154,54 @@ void device_destroy(struct class *class, dev_t devt)
1176 } 1154 }
1177 } 1155 }
1178 up(&class->sem); 1156 up(&class->sem);
1157 return dev;
1158}
1159
1160/**
1161 * device_destroy - removes a device that was created with device_create()
1162 * @class: pointer to the struct class that this device was registered with
1163 * @devt: the dev_t of the device that was previously registered
1164 *
1165 * This call unregisters and cleans up a device that was created with a
1166 * call to device_create().
1167 */
1168void device_destroy(struct class *class, dev_t devt)
1169{
1170 struct device *dev;
1179 1171
1172 dev = find_device(class, devt);
1180 if (dev) 1173 if (dev)
1181 device_unregister(dev); 1174 device_unregister(dev);
1182} 1175}
1183EXPORT_SYMBOL_GPL(device_destroy); 1176EXPORT_SYMBOL_GPL(device_destroy);
1184 1177
1178#ifdef CONFIG_PM_SLEEP
1179/**
1180 * destroy_suspended_device - asks the PM core to remove a suspended device
1181 * @class: pointer to the struct class that this device was registered with
1182 * @devt: the dev_t of the device that was previously registered
1183 *
1184 * This call notifies the PM core of the necessity to unregister a suspended
1185 * device created with a call to device_create() (devices cannot be
1186 * unregistered directly while suspended, since the PM core holds their
1187 * semaphores at that time).
1188 *
1189 * It can only be called within the scope of a system sleep transition. In
1190 * practice this means it has to be directly or indirectly invoked either by
1191 * a suspend or resume method, or by the PM core (e.g. via
1192 * disable_nonboot_cpus() or enable_nonboot_cpus()).
1193 */
1194void destroy_suspended_device(struct class *class, dev_t devt)
1195{
1196 struct device *dev;
1197
1198 dev = find_device(class, devt);
1199 if (dev)
1200 device_pm_schedule_removal(dev);
1201}
1202EXPORT_SYMBOL_GPL(destroy_suspended_device);
1203#endif /* CONFIG_PM_SLEEP */
1204
1185/** 1205/**
1186 * device_rename - renames a device 1206 * device_rename - renames a device
1187 * @dev: the pointer to the struct device to be renamed 1207 * @dev: the pointer to the struct device to be renamed
@@ -1198,7 +1218,8 @@ int device_rename(struct device *dev, char *new_name)
1198 if (!dev) 1218 if (!dev)
1199 return -EINVAL; 1219 return -EINVAL;
1200 1220
1201 pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name); 1221 pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id,
1222 __FUNCTION__, new_name);
1202 1223
1203#ifdef CONFIG_SYSFS_DEPRECATED 1224#ifdef CONFIG_SYSFS_DEPRECATED
1204 if ((dev->class) && (dev->parent)) 1225 if ((dev->class) && (dev->parent))
@@ -1279,8 +1300,7 @@ static int device_move_class_links(struct device *dev,
1279 class_name); 1300 class_name);
1280 if (error) 1301 if (error)
1281 sysfs_remove_link(&dev->kobj, "device"); 1302 sysfs_remove_link(&dev->kobj, "device");
1282 } 1303 } else
1283 else
1284 error = 0; 1304 error = 0;
1285out: 1305out:
1286 kfree(class_name); 1306 kfree(class_name);
@@ -1311,16 +1331,13 @@ int device_move(struct device *dev, struct device *new_parent)
1311 return -EINVAL; 1331 return -EINVAL;
1312 1332
1313 new_parent = get_device(new_parent); 1333 new_parent = get_device(new_parent);
1314 new_parent_kobj = get_device_parent (dev, new_parent); 1334 new_parent_kobj = get_device_parent(dev, new_parent);
1315 if (IS_ERR(new_parent_kobj)) { 1335
1316 error = PTR_ERR(new_parent_kobj); 1336 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
1317 put_device(new_parent); 1337 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
1318 goto out;
1319 }
1320 pr_debug("DEVICE: moving '%s' to '%s'\n", dev->bus_id,
1321 new_parent ? new_parent->bus_id : "<NULL>");
1322 error = kobject_move(&dev->kobj, new_parent_kobj); 1338 error = kobject_move(&dev->kobj, new_parent_kobj);
1323 if (error) { 1339 if (error) {
1340 cleanup_glue_dir(dev, new_parent_kobj);
1324 put_device(new_parent); 1341 put_device(new_parent);
1325 goto out; 1342 goto out;
1326 } 1343 }
@@ -1343,6 +1360,7 @@ int device_move(struct device *dev, struct device *new_parent)
1343 klist_add_tail(&dev->knode_parent, 1360 klist_add_tail(&dev->knode_parent,
1344 &old_parent->klist_children); 1361 &old_parent->klist_children);
1345 } 1362 }
1363 cleanup_glue_dir(dev, new_parent_kobj);
1346 put_device(new_parent); 1364 put_device(new_parent);
1347 goto out; 1365 goto out;
1348 } 1366 }
@@ -1352,5 +1370,23 @@ out:
1352 put_device(dev); 1370 put_device(dev);
1353 return error; 1371 return error;
1354} 1372}
1355
1356EXPORT_SYMBOL_GPL(device_move); 1373EXPORT_SYMBOL_GPL(device_move);
1374
1375/**
1376 * device_shutdown - call ->shutdown() on each device to shutdown.
1377 */
1378void device_shutdown(void)
1379{
1380 struct device *dev, *devn;
1381
1382 list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
1383 kobj.entry) {
1384 if (dev->bus && dev->bus->shutdown) {
1385 dev_dbg(dev, "shutdown\n");
1386 dev->bus->shutdown(dev);
1387 } else if (dev->driver && dev->driver->shutdown) {
1388 dev_dbg(dev, "shutdown\n");
1389 dev->driver->shutdown(dev);
1390 }
1391 }
1392}
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 40545071e3c9..c5885f5ce0ac 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -14,7 +14,7 @@
14#include "base.h" 14#include "base.h"
15 15
16struct sysdev_class cpu_sysdev_class = { 16struct sysdev_class cpu_sysdev_class = {
17 set_kset_name("cpu"), 17 .name = "cpu",
18}; 18};
19EXPORT_SYMBOL(cpu_sysdev_class); 19EXPORT_SYMBOL(cpu_sysdev_class);
20 20
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7ac474db88c5..a5cde94bb982 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1,18 +1,20 @@
1/* 1/*
2 * drivers/base/dd.c - The core device/driver interactions. 2 * drivers/base/dd.c - The core device/driver interactions.
3 * 3 *
4 * This file contains the (sometimes tricky) code that controls the 4 * This file contains the (sometimes tricky) code that controls the
5 * interactions between devices and drivers, which primarily includes 5 * interactions between devices and drivers, which primarily includes
6 * driver binding and unbinding. 6 * driver binding and unbinding.
7 * 7 *
8 * All of this code used to exist in drivers/base/bus.c, but was 8 * All of this code used to exist in drivers/base/bus.c, but was
9 * relocated to here in the name of compartmentalization (since it wasn't 9 * relocated to here in the name of compartmentalization (since it wasn't
10 * strictly code just for the 'struct bus_type'. 10 * strictly code just for the 'struct bus_type'.
11 * 11 *
12 * Copyright (c) 2002-5 Patrick Mochel 12 * Copyright (c) 2002-5 Patrick Mochel
13 * Copyright (c) 2002-3 Open Source Development Labs 13 * Copyright (c) 2002-3 Open Source Development Labs
14 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
15 * Copyright (c) 2007 Novell Inc.
14 * 16 *
15 * This file is released under the GPLv2 17 * This file is released under the GPLv2
16 */ 18 */
17 19
18#include <linux/device.h> 20#include <linux/device.h>
@@ -23,8 +25,6 @@
23#include "base.h" 25#include "base.h"
24#include "power/power.h" 26#include "power/power.h"
25 27
26#define to_drv(node) container_of(node, struct device_driver, kobj.entry)
27
28 28
29static void driver_bound(struct device *dev) 29static void driver_bound(struct device *dev)
30{ 30{
@@ -34,27 +34,27 @@ static void driver_bound(struct device *dev)
34 return; 34 return;
35 } 35 }
36 36
37 pr_debug("bound device '%s' to driver '%s'\n", 37 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id,
38 dev->bus_id, dev->driver->name); 38 __FUNCTION__, dev->driver->name);
39 39
40 if (dev->bus) 40 if (dev->bus)
41 blocking_notifier_call_chain(&dev->bus->bus_notifier, 41 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
42 BUS_NOTIFY_BOUND_DRIVER, dev); 42 BUS_NOTIFY_BOUND_DRIVER, dev);
43 43
44 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); 44 klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices);
45} 45}
46 46
47static int driver_sysfs_add(struct device *dev) 47static int driver_sysfs_add(struct device *dev)
48{ 48{
49 int ret; 49 int ret;
50 50
51 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, 51 ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
52 kobject_name(&dev->kobj)); 52 kobject_name(&dev->kobj));
53 if (ret == 0) { 53 if (ret == 0) {
54 ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, 54 ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
55 "driver"); 55 "driver");
56 if (ret) 56 if (ret)
57 sysfs_remove_link(&dev->driver->kobj, 57 sysfs_remove_link(&dev->driver->p->kobj,
58 kobject_name(&dev->kobj)); 58 kobject_name(&dev->kobj));
59 } 59 }
60 return ret; 60 return ret;
@@ -65,24 +65,24 @@ static void driver_sysfs_remove(struct device *dev)
65 struct device_driver *drv = dev->driver; 65 struct device_driver *drv = dev->driver;
66 66
67 if (drv) { 67 if (drv) {
68 sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); 68 sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
69 sysfs_remove_link(&dev->kobj, "driver"); 69 sysfs_remove_link(&dev->kobj, "driver");
70 } 70 }
71} 71}
72 72
73/** 73/**
74 * device_bind_driver - bind a driver to one device. 74 * device_bind_driver - bind a driver to one device.
75 * @dev: device. 75 * @dev: device.
76 * 76 *
77 * Allow manual attachment of a driver to a device. 77 * Allow manual attachment of a driver to a device.
78 * Caller must have already set @dev->driver. 78 * Caller must have already set @dev->driver.
79 * 79 *
80 * Note that this does not modify the bus reference count 80 * Note that this does not modify the bus reference count
81 * nor take the bus's rwsem. Please verify those are accounted 81 * nor take the bus's rwsem. Please verify those are accounted
82 * for before calling this. (It is ok to call with no other effort 82 * for before calling this. (It is ok to call with no other effort
83 * from a driver's probe() method.) 83 * from a driver's probe() method.)
84 * 84 *
85 * This function must be called with @dev->sem held. 85 * This function must be called with @dev->sem held.
86 */ 86 */
87int device_bind_driver(struct device *dev) 87int device_bind_driver(struct device *dev)
88{ 88{
@@ -93,6 +93,7 @@ int device_bind_driver(struct device *dev)
93 driver_bound(dev); 93 driver_bound(dev);
94 return ret; 94 return ret;
95} 95}
96EXPORT_SYMBOL_GPL(device_bind_driver);
96 97
97static atomic_t probe_count = ATOMIC_INIT(0); 98static atomic_t probe_count = ATOMIC_INIT(0);
98static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); 99static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
@@ -102,8 +103,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
102 int ret = 0; 103 int ret = 0;
103 104
104 atomic_inc(&probe_count); 105 atomic_inc(&probe_count);
105 pr_debug("%s: Probing driver %s with device %s\n", 106 pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
106 drv->bus->name, drv->name, dev->bus_id); 107 drv->bus->name, __FUNCTION__, drv->name, dev->bus_id);
107 WARN_ON(!list_empty(&dev->devres_head)); 108 WARN_ON(!list_empty(&dev->devres_head));
108 109
109 dev->driver = drv; 110 dev->driver = drv;
@@ -125,8 +126,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
125 126
126 driver_bound(dev); 127 driver_bound(dev);
127 ret = 1; 128 ret = 1;
128 pr_debug("%s: Bound Device %s to Driver %s\n", 129 pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
129 drv->bus->name, dev->bus_id, drv->name); 130 drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);
130 goto done; 131 goto done;
131 132
132probe_failed: 133probe_failed:
@@ -183,7 +184,7 @@ int driver_probe_done(void)
183 * This function must be called with @dev->sem held. When called for a 184 * This function must be called with @dev->sem held. When called for a
184 * USB interface, @dev->parent->sem must be held as well. 185 * USB interface, @dev->parent->sem must be held as well.
185 */ 186 */
186int driver_probe_device(struct device_driver * drv, struct device * dev) 187int driver_probe_device(struct device_driver *drv, struct device *dev)
187{ 188{
188 int ret = 0; 189 int ret = 0;
189 190
@@ -192,8 +193,8 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
192 if (drv->bus->match && !drv->bus->match(dev, drv)) 193 if (drv->bus->match && !drv->bus->match(dev, drv))
193 goto done; 194 goto done;
194 195
195 pr_debug("%s: Matched Device %s with Driver %s\n", 196 pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
196 drv->bus->name, dev->bus_id, drv->name); 197 drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);
197 198
198 ret = really_probe(dev, drv); 199 ret = really_probe(dev, drv);
199 200
@@ -201,27 +202,27 @@ done:
201 return ret; 202 return ret;
202} 203}
203 204
204static int __device_attach(struct device_driver * drv, void * data) 205static int __device_attach(struct device_driver *drv, void *data)
205{ 206{
206 struct device * dev = data; 207 struct device *dev = data;
207 return driver_probe_device(drv, dev); 208 return driver_probe_device(drv, dev);
208} 209}
209 210
210/** 211/**
211 * device_attach - try to attach device to a driver. 212 * device_attach - try to attach device to a driver.
212 * @dev: device. 213 * @dev: device.
213 * 214 *
214 * Walk the list of drivers that the bus has and call 215 * Walk the list of drivers that the bus has and call
215 * driver_probe_device() for each pair. If a compatible 216 * driver_probe_device() for each pair. If a compatible
216 * pair is found, break out and return. 217 * pair is found, break out and return.
217 * 218 *
218 * Returns 1 if the device was bound to a driver; 219 * Returns 1 if the device was bound to a driver;
219 * 0 if no matching device was found; 220 * 0 if no matching device was found;
220 * -ENODEV if the device is not registered. 221 * -ENODEV if the device is not registered.
221 * 222 *
222 * When called for a USB interface, @dev->parent->sem must be held. 223 * When called for a USB interface, @dev->parent->sem must be held.
223 */ 224 */
224int device_attach(struct device * dev) 225int device_attach(struct device *dev)
225{ 226{
226 int ret = 0; 227 int ret = 0;
227 228
@@ -240,10 +241,11 @@ int device_attach(struct device * dev)
240 up(&dev->sem); 241 up(&dev->sem);
241 return ret; 242 return ret;
242} 243}
244EXPORT_SYMBOL_GPL(device_attach);
243 245
244static int __driver_attach(struct device * dev, void * data) 246static int __driver_attach(struct device *dev, void *data)
245{ 247{
246 struct device_driver * drv = data; 248 struct device_driver *drv = data;
247 249
248 /* 250 /*
249 * Lock device and try to bind to it. We drop the error 251 * Lock device and try to bind to it. We drop the error
@@ -268,35 +270,35 @@ static int __driver_attach(struct device * dev, void * data)
268} 270}
269 271
270/** 272/**
271 * driver_attach - try to bind driver to devices. 273 * driver_attach - try to bind driver to devices.
272 * @drv: driver. 274 * @drv: driver.
273 * 275 *
274 * Walk the list of devices that the bus has on it and try to 276 * Walk the list of devices that the bus has on it and try to
275 * match the driver with each one. If driver_probe_device() 277 * match the driver with each one. If driver_probe_device()
276 * returns 0 and the @dev->driver is set, we've found a 278 * returns 0 and the @dev->driver is set, we've found a
277 * compatible pair. 279 * compatible pair.
278 */ 280 */
279int driver_attach(struct device_driver * drv) 281int driver_attach(struct device_driver *drv)
280{ 282{
281 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); 283 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
282} 284}
285EXPORT_SYMBOL_GPL(driver_attach);
283 286
284/* 287/*
285 * __device_release_driver() must be called with @dev->sem held. 288 * __device_release_driver() must be called with @dev->sem held.
286 * When called for a USB interface, @dev->parent->sem must be held as well. 289 * When called for a USB interface, @dev->parent->sem must be held as well.
287 */ 290 */
288static void __device_release_driver(struct device * dev) 291static void __device_release_driver(struct device *dev)
289{ 292{
290 struct device_driver * drv; 293 struct device_driver *drv;
291 294
292 drv = get_driver(dev->driver); 295 drv = dev->driver;
293 if (drv) { 296 if (drv) {
294 driver_sysfs_remove(dev); 297 driver_sysfs_remove(dev);
295 sysfs_remove_link(&dev->kobj, "driver"); 298 sysfs_remove_link(&dev->kobj, "driver");
296 klist_remove(&dev->knode_driver);
297 299
298 if (dev->bus) 300 if (dev->bus)
299 blocking_notifier_call_chain(&dev->bus->bus_notifier, 301 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
300 BUS_NOTIFY_UNBIND_DRIVER, 302 BUS_NOTIFY_UNBIND_DRIVER,
301 dev); 303 dev);
302 304
@@ -306,18 +308,18 @@ static void __device_release_driver(struct device * dev)
306 drv->remove(dev); 308 drv->remove(dev);
307 devres_release_all(dev); 309 devres_release_all(dev);
308 dev->driver = NULL; 310 dev->driver = NULL;
309 put_driver(drv); 311 klist_remove(&dev->knode_driver);
310 } 312 }
311} 313}
312 314
313/** 315/**
314 * device_release_driver - manually detach device from driver. 316 * device_release_driver - manually detach device from driver.
315 * @dev: device. 317 * @dev: device.
316 * 318 *
317 * Manually detach device from driver. 319 * Manually detach device from driver.
318 * When called for a USB interface, @dev->parent->sem must be held. 320 * When called for a USB interface, @dev->parent->sem must be held.
319 */ 321 */
320void device_release_driver(struct device * dev) 322void device_release_driver(struct device *dev)
321{ 323{
322 /* 324 /*
323 * If anyone calls device_release_driver() recursively from 325 * If anyone calls device_release_driver() recursively from
@@ -328,26 +330,26 @@ void device_release_driver(struct device * dev)
328 __device_release_driver(dev); 330 __device_release_driver(dev);
329 up(&dev->sem); 331 up(&dev->sem);
330} 332}
331 333EXPORT_SYMBOL_GPL(device_release_driver);
332 334
333/** 335/**
334 * driver_detach - detach driver from all devices it controls. 336 * driver_detach - detach driver from all devices it controls.
335 * @drv: driver. 337 * @drv: driver.
336 */ 338 */
337void driver_detach(struct device_driver * drv) 339void driver_detach(struct device_driver *drv)
338{ 340{
339 struct device * dev; 341 struct device *dev;
340 342
341 for (;;) { 343 for (;;) {
342 spin_lock(&drv->klist_devices.k_lock); 344 spin_lock(&drv->p->klist_devices.k_lock);
343 if (list_empty(&drv->klist_devices.k_list)) { 345 if (list_empty(&drv->p->klist_devices.k_list)) {
344 spin_unlock(&drv->klist_devices.k_lock); 346 spin_unlock(&drv->p->klist_devices.k_lock);
345 break; 347 break;
346 } 348 }
347 dev = list_entry(drv->klist_devices.k_list.prev, 349 dev = list_entry(drv->p->klist_devices.k_list.prev,
348 struct device, knode_driver.n_node); 350 struct device, knode_driver.n_node);
349 get_device(dev); 351 get_device(dev);
350 spin_unlock(&drv->klist_devices.k_lock); 352 spin_unlock(&drv->p->klist_devices.k_lock);
351 353
352 if (dev->parent) /* Needed for USB */ 354 if (dev->parent) /* Needed for USB */
353 down(&dev->parent->sem); 355 down(&dev->parent->sem);
@@ -360,9 +362,3 @@ void driver_detach(struct device_driver * drv)
360 put_device(dev); 362 put_device(dev);
361 } 363 }
362} 364}
363
364EXPORT_SYMBOL_GPL(device_bind_driver);
365EXPORT_SYMBOL_GPL(device_release_driver);
366EXPORT_SYMBOL_GPL(device_attach);
367EXPORT_SYMBOL_GPL(driver_attach);
368
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eb11475293ed..a35f04121a00 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2007 Novell Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 * 10 *
@@ -15,46 +17,42 @@
15#include "base.h" 17#include "base.h"
16 18
17#define to_dev(node) container_of(node, struct device, driver_list) 19#define to_dev(node) container_of(node, struct device, driver_list)
18#define to_drv(obj) container_of(obj, struct device_driver, kobj)
19 20
20 21
21static struct device * next_device(struct klist_iter * i) 22static struct device *next_device(struct klist_iter *i)
22{ 23{
23 struct klist_node * n = klist_next(i); 24 struct klist_node *n = klist_next(i);
24 return n ? container_of(n, struct device, knode_driver) : NULL; 25 return n ? container_of(n, struct device, knode_driver) : NULL;
25} 26}
26 27
27/** 28/**
28 * driver_for_each_device - Iterator for devices bound to a driver. 29 * driver_for_each_device - Iterator for devices bound to a driver.
29 * @drv: Driver we're iterating. 30 * @drv: Driver we're iterating.
30 * @start: Device to begin with 31 * @start: Device to begin with
31 * @data: Data to pass to the callback. 32 * @data: Data to pass to the callback.
32 * @fn: Function to call for each device. 33 * @fn: Function to call for each device.
33 * 34 *
34 * Iterate over the @drv's list of devices calling @fn for each one. 35 * Iterate over the @drv's list of devices calling @fn for each one.
35 */ 36 */
36 37int driver_for_each_device(struct device_driver *drv, struct device *start,
37int driver_for_each_device(struct device_driver * drv, struct device * start, 38 void *data, int (*fn)(struct device *, void *))
38 void * data, int (*fn)(struct device *, void *))
39{ 39{
40 struct klist_iter i; 40 struct klist_iter i;
41 struct device * dev; 41 struct device *dev;
42 int error = 0; 42 int error = 0;
43 43
44 if (!drv) 44 if (!drv)
45 return -EINVAL; 45 return -EINVAL;
46 46
47 klist_iter_init_node(&drv->klist_devices, &i, 47 klist_iter_init_node(&drv->p->klist_devices, &i,
48 start ? &start->knode_driver : NULL); 48 start ? &start->knode_driver : NULL);
49 while ((dev = next_device(&i)) && !error) 49 while ((dev = next_device(&i)) && !error)
50 error = fn(dev, data); 50 error = fn(dev, data);
51 klist_iter_exit(&i); 51 klist_iter_exit(&i);
52 return error; 52 return error;
53} 53}
54
55EXPORT_SYMBOL_GPL(driver_for_each_device); 54EXPORT_SYMBOL_GPL(driver_for_each_device);
56 55
57
58/** 56/**
59 * driver_find_device - device iterator for locating a particular device. 57 * driver_find_device - device iterator for locating a particular device.
60 * @drv: The device's driver 58 * @drv: The device's driver
@@ -70,9 +68,9 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
70 * if it does. If the callback returns non-zero, this function will 68 * if it does. If the callback returns non-zero, this function will
71 * return to the caller and not iterate over any more devices. 69 * return to the caller and not iterate over any more devices.
72 */ 70 */
73struct device * driver_find_device(struct device_driver *drv, 71struct device *driver_find_device(struct device_driver *drv,
74 struct device * start, void * data, 72 struct device *start, void *data,
75 int (*match)(struct device *, void *)) 73 int (*match)(struct device *dev, void *data))
76{ 74{
77 struct klist_iter i; 75 struct klist_iter i;
78 struct device *dev; 76 struct device *dev;
@@ -80,7 +78,7 @@ struct device * driver_find_device(struct device_driver *drv,
80 if (!drv) 78 if (!drv)
81 return NULL; 79 return NULL;
82 80
83 klist_iter_init_node(&drv->klist_devices, &i, 81 klist_iter_init_node(&drv->p->klist_devices, &i,
84 (start ? &start->knode_driver : NULL)); 82 (start ? &start->knode_driver : NULL));
85 while ((dev = next_device(&i))) 83 while ((dev = next_device(&i)))
86 if (match(dev, data) && get_device(dev)) 84 if (match(dev, data) && get_device(dev))
@@ -91,111 +89,179 @@ struct device * driver_find_device(struct device_driver *drv,
91EXPORT_SYMBOL_GPL(driver_find_device); 89EXPORT_SYMBOL_GPL(driver_find_device);
92 90
93/** 91/**
94 * driver_create_file - create sysfs file for driver. 92 * driver_create_file - create sysfs file for driver.
95 * @drv: driver. 93 * @drv: driver.
96 * @attr: driver attribute descriptor. 94 * @attr: driver attribute descriptor.
97 */ 95 */
98 96int driver_create_file(struct device_driver *drv,
99int driver_create_file(struct device_driver * drv, struct driver_attribute * attr) 97 struct driver_attribute *attr)
100{ 98{
101 int error; 99 int error;
102 if (get_driver(drv)) { 100 if (get_driver(drv)) {
103 error = sysfs_create_file(&drv->kobj, &attr->attr); 101 error = sysfs_create_file(&drv->p->kobj, &attr->attr);
104 put_driver(drv); 102 put_driver(drv);
105 } else 103 } else
106 error = -EINVAL; 104 error = -EINVAL;
107 return error; 105 return error;
108} 106}
109 107EXPORT_SYMBOL_GPL(driver_create_file);
110 108
111/** 109/**
112 * driver_remove_file - remove sysfs file for driver. 110 * driver_remove_file - remove sysfs file for driver.
113 * @drv: driver. 111 * @drv: driver.
114 * @attr: driver attribute descriptor. 112 * @attr: driver attribute descriptor.
115 */ 113 */
116 114void driver_remove_file(struct device_driver *drv,
117void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr) 115 struct driver_attribute *attr)
118{ 116{
119 if (get_driver(drv)) { 117 if (get_driver(drv)) {
120 sysfs_remove_file(&drv->kobj, &attr->attr); 118 sysfs_remove_file(&drv->p->kobj, &attr->attr);
121 put_driver(drv); 119 put_driver(drv);
122 } 120 }
123} 121}
124 122EXPORT_SYMBOL_GPL(driver_remove_file);
125 123
126/** 124/**
127 * get_driver - increment driver reference count. 125 * driver_add_kobj - add a kobject below the specified driver
128 * @drv: driver. 126 *
127 * You really don't want to do this, this is only here due to one looney
128 * iseries driver, go poke those developers if you are annoyed about
129 * this...
129 */ 130 */
130struct device_driver * get_driver(struct device_driver * drv) 131int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
132 const char *fmt, ...)
131{ 133{
132 return drv ? to_drv(kobject_get(&drv->kobj)) : NULL; 134 va_list args;
135 char *name;
136
137 va_start(args, fmt);
138 name = kvasprintf(GFP_KERNEL, fmt, args);
139 va_end(args);
140
141 if (!name)
142 return -ENOMEM;
143
144 return kobject_add(kobj, &drv->p->kobj, "%s", name);
133} 145}
146EXPORT_SYMBOL_GPL(driver_add_kobj);
147
148/**
149 * get_driver - increment driver reference count.
150 * @drv: driver.
151 */
152struct device_driver *get_driver(struct device_driver *drv)
153{
154 if (drv) {
155 struct driver_private *priv;
156 struct kobject *kobj;
134 157
158 kobj = kobject_get(&drv->p->kobj);
159 priv = to_driver(kobj);
160 return priv->driver;
161 }
162 return NULL;
163}
164EXPORT_SYMBOL_GPL(get_driver);
135 165
136/** 166/**
137 * put_driver - decrement driver's refcount. 167 * put_driver - decrement driver's refcount.
138 * @drv: driver. 168 * @drv: driver.
139 */ 169 */
140void put_driver(struct device_driver * drv) 170void put_driver(struct device_driver *drv)
171{
172 kobject_put(&drv->p->kobj);
173}
174EXPORT_SYMBOL_GPL(put_driver);
175
176static int driver_add_groups(struct device_driver *drv,
177 struct attribute_group **groups)
141{ 178{
142 kobject_put(&drv->kobj); 179 int error = 0;
180 int i;
181
182 if (groups) {
183 for (i = 0; groups[i]; i++) {
184 error = sysfs_create_group(&drv->p->kobj, groups[i]);
185 if (error) {
186 while (--i >= 0)
187 sysfs_remove_group(&drv->p->kobj,
188 groups[i]);
189 break;
190 }
191 }
192 }
193 return error;
194}
195
196static void driver_remove_groups(struct device_driver *drv,
197 struct attribute_group **groups)
198{
199 int i;
200
201 if (groups)
202 for (i = 0; groups[i]; i++)
203 sysfs_remove_group(&drv->p->kobj, groups[i]);
143} 204}
144 205
145/** 206/**
146 * driver_register - register driver with bus 207 * driver_register - register driver with bus
147 * @drv: driver to register 208 * @drv: driver to register
148 * 209 *
149 * We pass off most of the work to the bus_add_driver() call, 210 * We pass off most of the work to the bus_add_driver() call,
150 * since most of the things we have to do deal with the bus 211 * since most of the things we have to do deal with the bus
151 * structures. 212 * structures.
152 */ 213 */
153int driver_register(struct device_driver * drv) 214int driver_register(struct device_driver *drv)
154{ 215{
216 int ret;
217
155 if ((drv->bus->probe && drv->probe) || 218 if ((drv->bus->probe && drv->probe) ||
156 (drv->bus->remove && drv->remove) || 219 (drv->bus->remove && drv->remove) ||
157 (drv->bus->shutdown && drv->shutdown)) { 220 (drv->bus->shutdown && drv->shutdown))
158 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); 221 printk(KERN_WARNING "Driver '%s' needs updating - please use "
159 } 222 "bus_type methods\n", drv->name);
160 klist_init(&drv->klist_devices, NULL, NULL); 223 ret = bus_add_driver(drv);
161 return bus_add_driver(drv); 224 if (ret)
225 return ret;
226 ret = driver_add_groups(drv, drv->groups);
227 if (ret)
228 bus_remove_driver(drv);
229 return ret;
162} 230}
231EXPORT_SYMBOL_GPL(driver_register);
163 232
164/** 233/**
165 * driver_unregister - remove driver from system. 234 * driver_unregister - remove driver from system.
166 * @drv: driver. 235 * @drv: driver.
167 * 236 *
168 * Again, we pass off most of the work to the bus-level call. 237 * Again, we pass off most of the work to the bus-level call.
169 */ 238 */
170 239void driver_unregister(struct device_driver *drv)
171void driver_unregister(struct device_driver * drv)
172{ 240{
241 driver_remove_groups(drv, drv->groups);
173 bus_remove_driver(drv); 242 bus_remove_driver(drv);
174} 243}
244EXPORT_SYMBOL_GPL(driver_unregister);
175 245
176/** 246/**
177 * driver_find - locate driver on a bus by its name. 247 * driver_find - locate driver on a bus by its name.
178 * @name: name of the driver. 248 * @name: name of the driver.
179 * @bus: bus to scan for the driver. 249 * @bus: bus to scan for the driver.
180 * 250 *
181 * Call kset_find_obj() to iterate over list of drivers on 251 * Call kset_find_obj() to iterate over list of drivers on
182 * a bus to find driver by name. Return driver if found. 252 * a bus to find driver by name. Return driver if found.
183 * 253 *
184 * Note that kset_find_obj increments driver's reference count. 254 * Note that kset_find_obj increments driver's reference count.
185 */ 255 */
186struct device_driver *driver_find(const char *name, struct bus_type *bus) 256struct device_driver *driver_find(const char *name, struct bus_type *bus)
187{ 257{
188 struct kobject *k = kset_find_obj(&bus->drivers, name); 258 struct kobject *k = kset_find_obj(bus->p->drivers_kset, name);
189 if (k) 259 struct driver_private *priv;
190 return to_drv(k); 260
261 if (k) {
262 priv = to_driver(k);
263 return priv->driver;
264 }
191 return NULL; 265 return NULL;
192} 266}
193
194EXPORT_SYMBOL_GPL(driver_register);
195EXPORT_SYMBOL_GPL(driver_unregister);
196EXPORT_SYMBOL_GPL(get_driver);
197EXPORT_SYMBOL_GPL(put_driver);
198EXPORT_SYMBOL_GPL(driver_find); 267EXPORT_SYMBOL_GPL(driver_find);
199
200EXPORT_SYMBOL_GPL(driver_create_file);
201EXPORT_SYMBOL_GPL(driver_remove_file);
diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 90c862932169..113815556809 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -3,11 +3,11 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2007 Novell Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 *
9 */ 10 */
10
11#include <linux/kobject.h> 11#include <linux/kobject.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/init.h> 13#include <linux/init.h>
@@ -15,23 +15,13 @@
15 15
16#include "base.h" 16#include "base.h"
17 17
18static decl_subsys(firmware, NULL, NULL); 18struct kobject *firmware_kobj;
19 19EXPORT_SYMBOL_GPL(firmware_kobj);
20int firmware_register(struct kset *s)
21{
22 kobj_set_kset_s(s, firmware_subsys);
23 return subsystem_register(s);
24}
25
26void firmware_unregister(struct kset *s)
27{
28 subsystem_unregister(s);
29}
30 20
31int __init firmware_init(void) 21int __init firmware_init(void)
32{ 22{
33 return subsystem_register(&firmware_subsys); 23 firmware_kobj = kobject_create_and_add("firmware", NULL);
24 if (!firmware_kobj)
25 return -ENOMEM;
26 return 0;
34} 27}
35
36EXPORT_SYMBOL_GPL(firmware_register);
37EXPORT_SYMBOL_GPL(firmware_unregister);
diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c
index 7080b413ddc9..6428cba3aadd 100644
--- a/drivers/base/hypervisor.c
+++ b/drivers/base/hypervisor.c
@@ -2,19 +2,23 @@
2 * hypervisor.c - /sys/hypervisor subsystem. 2 * hypervisor.c - /sys/hypervisor subsystem.
3 * 3 *
4 * Copyright (C) IBM Corp. 2006 4 * Copyright (C) IBM Corp. 2006
5 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de>
6 * Copyright (C) 2007 Novell Inc.
5 * 7 *
6 * This file is released under the GPLv2 8 * This file is released under the GPLv2
7 */ 9 */
8 10
9#include <linux/kobject.h> 11#include <linux/kobject.h>
10#include <linux/device.h> 12#include <linux/device.h>
11
12#include "base.h" 13#include "base.h"
13 14
14decl_subsys(hypervisor, NULL, NULL); 15struct kobject *hypervisor_kobj;
15EXPORT_SYMBOL_GPL(hypervisor_subsys); 16EXPORT_SYMBOL_GPL(hypervisor_kobj);
16 17
17int __init hypervisor_init(void) 18int __init hypervisor_init(void)
18{ 19{
19 return subsystem_register(&hypervisor_subsys); 20 hypervisor_kobj = kobject_create_and_add("hypervisor", NULL);
21 if (!hypervisor_kobj)
22 return -ENOMEM;
23 return 0;
20} 24}
diff --git a/drivers/base/init.c b/drivers/base/init.c
index 37138154f9e8..7bd9b6a5b01f 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -1,10 +1,8 @@
1/* 1/*
2 *
3 * Copyright (c) 2002-3 Patrick Mochel 2 * Copyright (c) 2002-3 Patrick Mochel
4 * Copyright (c) 2002-3 Open Source Development Labs 3 * Copyright (c) 2002-3 Open Source Development Labs
5 * 4 *
6 * This file is released under the GPLv2 5 * This file is released under the GPLv2
7 *
8 */ 6 */
9 7
10#include <linux/device.h> 8#include <linux/device.h>
@@ -14,12 +12,11 @@
14#include "base.h" 12#include "base.h"
15 13
16/** 14/**
17 * driver_init - initialize driver model. 15 * driver_init - initialize driver model.
18 * 16 *
19 * Call the driver model init functions to initialize their 17 * Call the driver model init functions to initialize their
20 * subsystems. Called early from init/main.c. 18 * subsystems. Called early from init/main.c.
21 */ 19 */
22
23void __init driver_init(void) 20void __init driver_init(void)
24{ 21{
25 /* These are the core pieces */ 22 /* These are the core pieces */
@@ -36,5 +33,4 @@ void __init driver_init(void)
36 system_bus_init(); 33 system_bus_init();
37 cpu_dev_init(); 34 cpu_dev_init();
38 memory_dev_init(); 35 memory_dev_init();
39 attribute_container_init();
40} 36}
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 7868707c7eda..7ae413fdd5fc 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -26,7 +26,7 @@
26#define MEMORY_CLASS_NAME "memory" 26#define MEMORY_CLASS_NAME "memory"
27 27
28static struct sysdev_class memory_sysdev_class = { 28static struct sysdev_class memory_sysdev_class = {
29 set_kset_name(MEMORY_CLASS_NAME), 29 .name = MEMORY_CLASS_NAME,
30}; 30};
31 31
32static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj) 32static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
diff --git a/drivers/base/module.c b/drivers/base/module.c
new file mode 100644
index 000000000000..103be9cacb05
--- /dev/null
+++ b/drivers/base/module.c
@@ -0,0 +1,94 @@
1/*
2 * module.c - module sysfs fun for drivers
3 *
4 * This file is released under the GPLv2
5 *
6 */
7#include <linux/device.h>
8#include <linux/module.h>
9#include <linux/errno.h>
10#include <linux/string.h>
11#include "base.h"
12
13static char *make_driver_name(struct device_driver *drv)
14{
15 char *driver_name;
16
17 driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
18 GFP_KERNEL);
19 if (!driver_name)
20 return NULL;
21
22 sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
23 return driver_name;
24}
25
26static void module_create_drivers_dir(struct module_kobject *mk)
27{
28 if (!mk || mk->drivers_dir)
29 return;
30
31 mk->drivers_dir = kobject_create_and_add("drivers", &mk->kobj);
32}
33
34void module_add_driver(struct module *mod, struct device_driver *drv)
35{
36 char *driver_name;
37 int no_warn;
38 struct module_kobject *mk = NULL;
39
40 if (!drv)
41 return;
42
43 if (mod)
44 mk = &mod->mkobj;
45 else if (drv->mod_name) {
46 struct kobject *mkobj;
47
48 /* Lookup built-in module entry in /sys/modules */
49 mkobj = kset_find_obj(module_kset, drv->mod_name);
50 if (mkobj) {
51 mk = container_of(mkobj, struct module_kobject, kobj);
52 /* remember our module structure */
53 drv->p->mkobj = mk;
54 /* kset_find_obj took a reference */
55 kobject_put(mkobj);
56 }
57 }
58
59 if (!mk)
60 return;
61
62 /* Don't check return codes; these calls are idempotent */
63 no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
64 driver_name = make_driver_name(drv);
65 if (driver_name) {
66 module_create_drivers_dir(mk);
67 no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
68 driver_name);
69 kfree(driver_name);
70 }
71}
72
73void module_remove_driver(struct device_driver *drv)
74{
75 struct module_kobject *mk = NULL;
76 char *driver_name;
77
78 if (!drv)
79 return;
80
81 sysfs_remove_link(&drv->p->kobj, "module");
82
83 if (drv->owner)
84 mk = &drv->owner->mkobj;
85 else if (drv->p->mkobj)
86 mk = drv->p->mkobj;
87 if (mk && mk->drivers_dir) {
88 driver_name = make_driver_name(drv);
89 if (driver_name) {
90 sysfs_remove_link(mk->drivers_dir, driver_name);
91 kfree(driver_name);
92 }
93 }
94}
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 88eeed72b5d6..e59861f18ce5 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -15,7 +15,7 @@
15#include <linux/device.h> 15#include <linux/device.h>
16 16
17static struct sysdev_class node_class = { 17static struct sysdev_class node_class = {
18 set_kset_name("node"), 18 .name = "node",
19}; 19};
20 20
21 21
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index fb5609241482..efaf282c438c 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -20,7 +20,8 @@
20 20
21#include "base.h" 21#include "base.h"
22 22
23#define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver)) 23#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
24 driver))
24 25
25struct device platform_bus = { 26struct device platform_bus = {
26 .bus_id = "platform", 27 .bus_id = "platform",
@@ -28,14 +29,13 @@ struct device platform_bus = {
28EXPORT_SYMBOL_GPL(platform_bus); 29EXPORT_SYMBOL_GPL(platform_bus);
29 30
30/** 31/**
31 * platform_get_resource - get a resource for a device 32 * platform_get_resource - get a resource for a device
32 * @dev: platform device 33 * @dev: platform device
33 * @type: resource type 34 * @type: resource type
34 * @num: resource index 35 * @num: resource index
35 */ 36 */
36struct resource * 37struct resource *platform_get_resource(struct platform_device *dev,
37platform_get_resource(struct platform_device *dev, unsigned int type, 38 unsigned int type, unsigned int num)
38 unsigned int num)
39{ 39{
40 int i; 40 int i;
41 41
@@ -43,8 +43,7 @@ platform_get_resource(struct platform_device *dev, unsigned int type,
43 struct resource *r = &dev->resource[i]; 43 struct resource *r = &dev->resource[i];
44 44
45 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| 45 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM|
46 IORESOURCE_IRQ|IORESOURCE_DMA)) 46 IORESOURCE_IRQ|IORESOURCE_DMA)) == type)
47 == type)
48 if (num-- == 0) 47 if (num-- == 0)
49 return r; 48 return r;
50 } 49 }
@@ -53,9 +52,9 @@ platform_get_resource(struct platform_device *dev, unsigned int type,
53EXPORT_SYMBOL_GPL(platform_get_resource); 52EXPORT_SYMBOL_GPL(platform_get_resource);
54 53
55/** 54/**
56 * platform_get_irq - get an IRQ for a device 55 * platform_get_irq - get an IRQ for a device
57 * @dev: platform device 56 * @dev: platform device
58 * @num: IRQ number index 57 * @num: IRQ number index
59 */ 58 */
60int platform_get_irq(struct platform_device *dev, unsigned int num) 59int platform_get_irq(struct platform_device *dev, unsigned int num)
61{ 60{
@@ -66,14 +65,13 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
66EXPORT_SYMBOL_GPL(platform_get_irq); 65EXPORT_SYMBOL_GPL(platform_get_irq);
67 66
68/** 67/**
69 * platform_get_resource_byname - get a resource for a device by name 68 * platform_get_resource_byname - get a resource for a device by name
70 * @dev: platform device 69 * @dev: platform device
71 * @type: resource type 70 * @type: resource type
72 * @name: resource name 71 * @name: resource name
73 */ 72 */
74struct resource * 73struct resource *platform_get_resource_byname(struct platform_device *dev,
75platform_get_resource_byname(struct platform_device *dev, unsigned int type, 74 unsigned int type, char *name)
76 char *name)
77{ 75{
78 int i; 76 int i;
79 77
@@ -90,22 +88,23 @@ platform_get_resource_byname(struct platform_device *dev, unsigned int type,
90EXPORT_SYMBOL_GPL(platform_get_resource_byname); 88EXPORT_SYMBOL_GPL(platform_get_resource_byname);
91 89
92/** 90/**
93 * platform_get_irq - get an IRQ for a device 91 * platform_get_irq - get an IRQ for a device
94 * @dev: platform device 92 * @dev: platform device
95 * @name: IRQ name 93 * @name: IRQ name
96 */ 94 */
97int platform_get_irq_byname(struct platform_device *dev, char *name) 95int platform_get_irq_byname(struct platform_device *dev, char *name)
98{ 96{
99 struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); 97 struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ,
98 name);
100 99
101 return r ? r->start : -ENXIO; 100 return r ? r->start : -ENXIO;
102} 101}
103EXPORT_SYMBOL_GPL(platform_get_irq_byname); 102EXPORT_SYMBOL_GPL(platform_get_irq_byname);
104 103
105/** 104/**
106 * platform_add_devices - add a numbers of platform devices 105 * platform_add_devices - add a numbers of platform devices
107 * @devs: array of platform devices to add 106 * @devs: array of platform devices to add
108 * @num: number of platform devices in array 107 * @num: number of platform devices in array
109 */ 108 */
110int platform_add_devices(struct platform_device **devs, int num) 109int platform_add_devices(struct platform_device **devs, int num)
111{ 110{
@@ -130,12 +129,11 @@ struct platform_object {
130}; 129};
131 130
132/** 131/**
133 * platform_device_put 132 * platform_device_put
134 * @pdev: platform device to free 133 * @pdev: platform device to free
135 * 134 *
136 * Free all memory associated with a platform device. This function 135 * Free all memory associated with a platform device. This function must
137 * must _only_ be externally called in error cases. All other usage 136 * _only_ be externally called in error cases. All other usage is a bug.
138 * is a bug.
139 */ 137 */
140void platform_device_put(struct platform_device *pdev) 138void platform_device_put(struct platform_device *pdev)
141{ 139{
@@ -146,7 +144,8 @@ EXPORT_SYMBOL_GPL(platform_device_put);
146 144
147static void platform_device_release(struct device *dev) 145static void platform_device_release(struct device *dev)
148{ 146{
149 struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev); 147 struct platform_object *pa = container_of(dev, struct platform_object,
148 pdev.dev);
150 149
151 kfree(pa->pdev.dev.platform_data); 150 kfree(pa->pdev.dev.platform_data);
152 kfree(pa->pdev.resource); 151 kfree(pa->pdev.resource);
@@ -154,12 +153,12 @@ static void platform_device_release(struct device *dev)
154} 153}
155 154
156/** 155/**
157 * platform_device_alloc 156 * platform_device_alloc
158 * @name: base name of the device we're adding 157 * @name: base name of the device we're adding
159 * @id: instance id 158 * @id: instance id
160 * 159 *
161 * Create a platform device object which can have other objects attached 160 * Create a platform device object which can have other objects attached
162 * to it, and which will have attached objects freed when it is released. 161 * to it, and which will have attached objects freed when it is released.
163 */ 162 */
164struct platform_device *platform_device_alloc(const char *name, int id) 163struct platform_device *platform_device_alloc(const char *name, int id)
165{ 164{
@@ -179,16 +178,17 @@ struct platform_device *platform_device_alloc(const char *name, int id)
179EXPORT_SYMBOL_GPL(platform_device_alloc); 178EXPORT_SYMBOL_GPL(platform_device_alloc);
180 179
181/** 180/**
182 * platform_device_add_resources 181 * platform_device_add_resources
183 * @pdev: platform device allocated by platform_device_alloc to add resources to 182 * @pdev: platform device allocated by platform_device_alloc to add resources to
184 * @res: set of resources that needs to be allocated for the device 183 * @res: set of resources that needs to be allocated for the device
185 * @num: number of resources 184 * @num: number of resources
186 * 185 *
187 * Add a copy of the resources to the platform device. The memory 186 * Add a copy of the resources to the platform device. The memory
188 * associated with the resources will be freed when the platform 187 * associated with the resources will be freed when the platform device is
189 * device is released. 188 * released.
190 */ 189 */
191int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num) 190int platform_device_add_resources(struct platform_device *pdev,
191 struct resource *res, unsigned int num)
192{ 192{
193 struct resource *r; 193 struct resource *r;
194 194
@@ -203,16 +203,17 @@ int platform_device_add_resources(struct platform_device *pdev, struct resource
203EXPORT_SYMBOL_GPL(platform_device_add_resources); 203EXPORT_SYMBOL_GPL(platform_device_add_resources);
204 204
205/** 205/**
206 * platform_device_add_data 206 * platform_device_add_data
207 * @pdev: platform device allocated by platform_device_alloc to add resources to 207 * @pdev: platform device allocated by platform_device_alloc to add resources to
208 * @data: platform specific data for this platform device 208 * @data: platform specific data for this platform device
209 * @size: size of platform specific data 209 * @size: size of platform specific data
210 * 210 *
211 * Add a copy of platform specific data to the platform device's platform_data 211 * Add a copy of platform specific data to the platform device's
212 * pointer. The memory associated with the platform data will be freed 212 * platform_data pointer. The memory associated with the platform data
213 * when the platform device is released. 213 * will be freed when the platform device is released.
214 */ 214 */
215int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) 215int platform_device_add_data(struct platform_device *pdev, const void *data,
216 size_t size)
216{ 217{
217 void *d; 218 void *d;
218 219
@@ -226,11 +227,11 @@ int platform_device_add_data(struct platform_device *pdev, const void *data, siz
226EXPORT_SYMBOL_GPL(platform_device_add_data); 227EXPORT_SYMBOL_GPL(platform_device_add_data);
227 228
228/** 229/**
229 * platform_device_add - add a platform device to device hierarchy 230 * platform_device_add - add a platform device to device hierarchy
230 * @pdev: platform device we're adding 231 * @pdev: platform device we're adding
231 * 232 *
232 * This is part 2 of platform_device_register(), though may be called 233 * This is part 2 of platform_device_register(), though may be called
233 * separately _iff_ pdev was allocated by platform_device_alloc(). 234 * separately _iff_ pdev was allocated by platform_device_alloc().
234 */ 235 */
235int platform_device_add(struct platform_device *pdev) 236int platform_device_add(struct platform_device *pdev)
236{ 237{
@@ -289,13 +290,12 @@ int platform_device_add(struct platform_device *pdev)
289EXPORT_SYMBOL_GPL(platform_device_add); 290EXPORT_SYMBOL_GPL(platform_device_add);
290 291
291/** 292/**
292 * platform_device_del - remove a platform-level device 293 * platform_device_del - remove a platform-level device
293 * @pdev: platform device we're removing 294 * @pdev: platform device we're removing
294 * 295 *
295 * Note that this function will also release all memory- and port-based 296 * Note that this function will also release all memory- and port-based
296 * resources owned by the device (@dev->resource). This function 297 * resources owned by the device (@dev->resource). This function must
297 * must _only_ be externally called in error cases. All other usage 298 * _only_ be externally called in error cases. All other usage is a bug.
298 * is a bug.
299 */ 299 */
300void platform_device_del(struct platform_device *pdev) 300void platform_device_del(struct platform_device *pdev)
301{ 301{
@@ -314,11 +314,10 @@ void platform_device_del(struct platform_device *pdev)
314EXPORT_SYMBOL_GPL(platform_device_del); 314EXPORT_SYMBOL_GPL(platform_device_del);
315 315
316/** 316/**
317 * platform_device_register - add a platform-level device 317 * platform_device_register - add a platform-level device
318 * @pdev: platform device we're adding 318 * @pdev: platform device we're adding
319 *
320 */ 319 */
321int platform_device_register(struct platform_device * pdev) 320int platform_device_register(struct platform_device *pdev)
322{ 321{
323 device_initialize(&pdev->dev); 322 device_initialize(&pdev->dev);
324 return platform_device_add(pdev); 323 return platform_device_add(pdev);
@@ -326,14 +325,14 @@ int platform_device_register(struct platform_device * pdev)
326EXPORT_SYMBOL_GPL(platform_device_register); 325EXPORT_SYMBOL_GPL(platform_device_register);
327 326
328/** 327/**
329 * platform_device_unregister - unregister a platform-level device 328 * platform_device_unregister - unregister a platform-level device
330 * @pdev: platform device we're unregistering 329 * @pdev: platform device we're unregistering
331 * 330 *
332 * Unregistration is done in 2 steps. First we release all resources 331 * Unregistration is done in 2 steps. First we release all resources
333 * and remove it from the subsystem, then we drop reference count by 332 * and remove it from the subsystem, then we drop reference count by
334 * calling platform_device_put(). 333 * calling platform_device_put().
335 */ 334 */
336void platform_device_unregister(struct platform_device * pdev) 335void platform_device_unregister(struct platform_device *pdev)
337{ 336{
338 platform_device_del(pdev); 337 platform_device_del(pdev);
339 platform_device_put(pdev); 338 platform_device_put(pdev);
@@ -341,27 +340,29 @@ void platform_device_unregister(struct platform_device * pdev)
341EXPORT_SYMBOL_GPL(platform_device_unregister); 340EXPORT_SYMBOL_GPL(platform_device_unregister);
342 341
343/** 342/**
344 * platform_device_register_simple 343 * platform_device_register_simple
345 * @name: base name of the device we're adding 344 * @name: base name of the device we're adding
346 * @id: instance id 345 * @id: instance id
347 * @res: set of resources that needs to be allocated for the device 346 * @res: set of resources that needs to be allocated for the device
348 * @num: number of resources 347 * @num: number of resources
349 * 348 *
350 * This function creates a simple platform device that requires minimal 349 * This function creates a simple platform device that requires minimal
351 * resource and memory management. Canned release function freeing 350 * resource and memory management. Canned release function freeing memory
352 * memory allocated for the device allows drivers using such devices 351 * allocated for the device allows drivers using such devices to be
353 * to be unloaded without waiting for the last reference to the device 352 * unloaded without waiting for the last reference to the device to be
354 * to be dropped. 353 * dropped.
355 * 354 *
356 * This interface is primarily intended for use with legacy drivers 355 * This interface is primarily intended for use with legacy drivers which
357 * which probe hardware directly. Because such drivers create sysfs 356 * probe hardware directly. Because such drivers create sysfs device nodes
358 * device nodes themselves, rather than letting system infrastructure 357 * themselves, rather than letting system infrastructure handle such device
359 * handle such device enumeration tasks, they don't fully conform to 358 * enumeration tasks, they don't fully conform to the Linux driver model.
360 * the Linux driver model. In particular, when such drivers are built 359 * In particular, when such drivers are built as modules, they can't be
361 * as modules, they can't be "hotplugged". 360 * "hotplugged".
362 */ 361 */
363struct platform_device *platform_device_register_simple(char *name, int id, 362struct platform_device *platform_device_register_simple(const char *name,
364 struct resource *res, unsigned int num) 363 int id,
364 struct resource *res,
365 unsigned int num)
365{ 366{
366 struct platform_device *pdev; 367 struct platform_device *pdev;
367 int retval; 368 int retval;
@@ -436,8 +437,8 @@ static int platform_drv_resume(struct device *_dev)
436} 437}
437 438
438/** 439/**
439 * platform_driver_register 440 * platform_driver_register
440 * @drv: platform driver structure 441 * @drv: platform driver structure
441 */ 442 */
442int platform_driver_register(struct platform_driver *drv) 443int platform_driver_register(struct platform_driver *drv)
443{ 444{
@@ -457,8 +458,8 @@ int platform_driver_register(struct platform_driver *drv)
457EXPORT_SYMBOL_GPL(platform_driver_register); 458EXPORT_SYMBOL_GPL(platform_driver_register);
458 459
459/** 460/**
460 * platform_driver_unregister 461 * platform_driver_unregister
461 * @drv: platform driver structure 462 * @drv: platform driver structure
462 */ 463 */
463void platform_driver_unregister(struct platform_driver *drv) 464void platform_driver_unregister(struct platform_driver *drv)
464{ 465{
@@ -497,12 +498,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
497 * if the probe was successful, and make sure any forced probes of 498 * if the probe was successful, and make sure any forced probes of
498 * new devices fail. 499 * new devices fail.
499 */ 500 */
500 spin_lock(&platform_bus_type.klist_drivers.k_lock); 501 spin_lock(&platform_bus_type.p->klist_drivers.k_lock);
501 drv->probe = NULL; 502 drv->probe = NULL;
502 if (code == 0 && list_empty(&drv->driver.klist_devices.k_list)) 503 if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
503 retval = -ENODEV; 504 retval = -ENODEV;
504 drv->driver.probe = platform_drv_probe_fail; 505 drv->driver.probe = platform_drv_probe_fail;
505 spin_unlock(&platform_bus_type.klist_drivers.k_lock); 506 spin_unlock(&platform_bus_type.p->klist_drivers.k_lock);
506 507
507 if (code != retval) 508 if (code != retval)
508 platform_driver_unregister(drv); 509 platform_driver_unregister(drv);
@@ -516,8 +517,8 @@ EXPORT_SYMBOL_GPL(platform_driver_probe);
516 * (b) sysfs attribute lets new-style coldplug recover from hotplug events 517 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
517 * mishandled before system is fully running: "modprobe $(cat modalias)" 518 * mishandled before system is fully running: "modprobe $(cat modalias)"
518 */ 519 */
519static ssize_t 520static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
520modalias_show(struct device *dev, struct device_attribute *a, char *buf) 521 char *buf)
521{ 522{
522 struct platform_device *pdev = to_platform_device(dev); 523 struct platform_device *pdev = to_platform_device(dev);
523 int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name); 524 int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
@@ -538,26 +539,24 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
538 return 0; 539 return 0;
539} 540}
540 541
541
542/** 542/**
543 * platform_match - bind platform device to platform driver. 543 * platform_match - bind platform device to platform driver.
544 * @dev: device. 544 * @dev: device.
545 * @drv: driver. 545 * @drv: driver.
546 * 546 *
547 * Platform device IDs are assumed to be encoded like this: 547 * Platform device IDs are assumed to be encoded like this:
548 * "<name><instance>", where <name> is a short description of the 548 * "<name><instance>", where <name> is a short description of the type of
549 * type of device, like "pci" or "floppy", and <instance> is the 549 * device, like "pci" or "floppy", and <instance> is the enumerated
550 * enumerated instance of the device, like '0' or '42'. 550 * instance of the device, like '0' or '42'. Driver IDs are simply
551 * Driver IDs are simply "<name>". 551 * "<name>". So, extract the <name> from the platform_device structure,
552 * So, extract the <name> from the platform_device structure, 552 * and compare it against the name of the driver. Return whether they match
553 * and compare it against the name of the driver. Return whether 553 * or not.
554 * they match or not.
555 */ 554 */
556 555static int platform_match(struct device *dev, struct device_driver *drv)
557static int platform_match(struct device * dev, struct device_driver * drv)
558{ 556{
559 struct platform_device *pdev = container_of(dev, struct platform_device, dev); 557 struct platform_device *pdev;
560 558
559 pdev = container_of(dev, struct platform_device, dev);
561 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 560 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
562} 561}
563 562
@@ -574,9 +573,10 @@ static int platform_suspend(struct device *dev, pm_message_t mesg)
574static int platform_suspend_late(struct device *dev, pm_message_t mesg) 573static int platform_suspend_late(struct device *dev, pm_message_t mesg)
575{ 574{
576 struct platform_driver *drv = to_platform_driver(dev->driver); 575 struct platform_driver *drv = to_platform_driver(dev->driver);
577 struct platform_device *pdev = container_of(dev, struct platform_device, dev); 576 struct platform_device *pdev;
578 int ret = 0; 577 int ret = 0;
579 578
579 pdev = container_of(dev, struct platform_device, dev);
580 if (dev->driver && drv->suspend_late) 580 if (dev->driver && drv->suspend_late)
581 ret = drv->suspend_late(pdev, mesg); 581 ret = drv->suspend_late(pdev, mesg);
582 582
@@ -586,16 +586,17 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg)
586static int platform_resume_early(struct device *dev) 586static int platform_resume_early(struct device *dev)
587{ 587{
588 struct platform_driver *drv = to_platform_driver(dev->driver); 588 struct platform_driver *drv = to_platform_driver(dev->driver);
589 struct platform_device *pdev = container_of(dev, struct platform_device, dev); 589 struct platform_device *pdev;
590 int ret = 0; 590 int ret = 0;
591 591
592 pdev = container_of(dev, struct platform_device, dev);
592 if (dev->driver && drv->resume_early) 593 if (dev->driver && drv->resume_early)
593 ret = drv->resume_early(pdev); 594 ret = drv->resume_early(pdev);
594 595
595 return ret; 596 return ret;
596} 597}
597 598
598static int platform_resume(struct device * dev) 599static int platform_resume(struct device *dev)
599{ 600{
600 int ret = 0; 601 int ret = 0;
601 602
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 44504e6618fb..06a86fe6a78d 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,4 +1,3 @@
1obj-y := shutdown.o
2obj-$(CONFIG_PM) += sysfs.o 1obj-$(CONFIG_PM) += sysfs.o
3obj-$(CONFIG_PM_SLEEP) += main.o 2obj-$(CONFIG_PM_SLEEP) += main.o
4obj-$(CONFIG_PM_TRACE) += trace.o 3obj-$(CONFIG_PM_TRACE) += trace.o
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 691ffb64cc37..200ed5fafd50 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -24,20 +24,45 @@
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/pm.h> 25#include <linux/pm.h>
26#include <linux/resume-trace.h> 26#include <linux/resume-trace.h>
27#include <linux/rwsem.h>
27 28
28#include "../base.h" 29#include "../base.h"
29#include "power.h" 30#include "power.h"
30 31
32/*
33 * The entries in the dpm_active list are in a depth first order, simply
34 * because children are guaranteed to be discovered after parents, and
35 * are inserted at the back of the list on discovery.
36 *
37 * All the other lists are kept in the same order, for consistency.
38 * However the lists aren't always traversed in the same order.
39 * Semaphores must be acquired from the top (i.e., front) down
40 * and released in the opposite order. Devices must be suspended
41 * from the bottom (i.e., end) up and resumed in the opposite order.
42 * That way no parent will be suspended while it still has an active
43 * child.
44 *
45 * Since device_pm_add() may be called with a device semaphore held,
46 * we must never try to acquire a device semaphore while holding
47 * dpm_list_mutex.
48 */
49
31LIST_HEAD(dpm_active); 50LIST_HEAD(dpm_active);
51static LIST_HEAD(dpm_locked);
32static LIST_HEAD(dpm_off); 52static LIST_HEAD(dpm_off);
33static LIST_HEAD(dpm_off_irq); 53static LIST_HEAD(dpm_off_irq);
54static LIST_HEAD(dpm_destroy);
34 55
35static DEFINE_MUTEX(dpm_mtx);
36static DEFINE_MUTEX(dpm_list_mtx); 56static DEFINE_MUTEX(dpm_list_mtx);
37 57
38int (*platform_enable_wakeup)(struct device *dev, int is_on); 58static DECLARE_RWSEM(pm_sleep_rwsem);
39 59
60int (*platform_enable_wakeup)(struct device *dev, int is_on);
40 61
62/**
63 * device_pm_add - add a device to the list of active devices
64 * @dev: Device to be added to the list
65 */
41void device_pm_add(struct device *dev) 66void device_pm_add(struct device *dev)
42{ 67{
43 pr_debug("PM: Adding info for %s:%s\n", 68 pr_debug("PM: Adding info for %s:%s\n",
@@ -48,8 +73,36 @@ void device_pm_add(struct device *dev)
48 mutex_unlock(&dpm_list_mtx); 73 mutex_unlock(&dpm_list_mtx);
49} 74}
50 75
76/**
77 * device_pm_remove - remove a device from the list of active devices
78 * @dev: Device to be removed from the list
79 *
80 * This function also removes the device's PM-related sysfs attributes.
81 */
51void device_pm_remove(struct device *dev) 82void device_pm_remove(struct device *dev)
52{ 83{
84 /*
85 * If this function is called during a suspend, it will be blocked,
86 * because we're holding the device's semaphore at that time, which may
87 * lead to a deadlock. In that case we want to print a warning.
88 * However, it may also be called by unregister_dropped_devices() with
89 * the device's semaphore released, in which case the warning should
90 * not be printed.
91 */
92 if (down_trylock(&dev->sem)) {
93 if (down_read_trylock(&pm_sleep_rwsem)) {
94 /* No suspend in progress, wait on dev->sem */
95 down(&dev->sem);
96 up_read(&pm_sleep_rwsem);
97 } else {
98 /* Suspend in progress, we may deadlock */
99 dev_warn(dev, "Suspicious %s during suspend\n",
100 __FUNCTION__);
101 dump_stack();
102 /* The user has been warned ... */
103 down(&dev->sem);
104 }
105 }
53 pr_debug("PM: Removing info for %s:%s\n", 106 pr_debug("PM: Removing info for %s:%s\n",
54 dev->bus ? dev->bus->name : "No Bus", 107 dev->bus ? dev->bus->name : "No Bus",
55 kobject_name(&dev->kobj)); 108 kobject_name(&dev->kobj));
@@ -57,25 +110,124 @@ void device_pm_remove(struct device *dev)
57 dpm_sysfs_remove(dev); 110 dpm_sysfs_remove(dev);
58 list_del_init(&dev->power.entry); 111 list_del_init(&dev->power.entry);
59 mutex_unlock(&dpm_list_mtx); 112 mutex_unlock(&dpm_list_mtx);
113 up(&dev->sem);
114}
115
116/**
117 * device_pm_schedule_removal - schedule the removal of a suspended device
118 * @dev: Device to destroy
119 *
120 * Moves the device to the dpm_destroy list for further processing by
121 * unregister_dropped_devices().
122 */
123void device_pm_schedule_removal(struct device *dev)
124{
125 pr_debug("PM: Preparing for removal: %s:%s\n",
126 dev->bus ? dev->bus->name : "No Bus",
127 kobject_name(&dev->kobj));
128 mutex_lock(&dpm_list_mtx);
129 list_move_tail(&dev->power.entry, &dpm_destroy);
130 mutex_unlock(&dpm_list_mtx);
131}
132
133/**
134 * pm_sleep_lock - mutual exclusion for registration and suspend
135 *
136 * Returns 0 if no suspend is underway and device registration
137 * may proceed, otherwise -EBUSY.
138 */
139int pm_sleep_lock(void)
140{
141 if (down_read_trylock(&pm_sleep_rwsem))
142 return 0;
143
144 return -EBUSY;
145}
146
147/**
148 * pm_sleep_unlock - mutual exclusion for registration and suspend
149 *
150 * This routine undoes the effect of device_pm_add_lock
151 * when a device's registration is complete.
152 */
153void pm_sleep_unlock(void)
154{
155 up_read(&pm_sleep_rwsem);
60} 156}
61 157
62 158
63/*------------------------- Resume routines -------------------------*/ 159/*------------------------- Resume routines -------------------------*/
64 160
65/** 161/**
66 * resume_device - Restore state for one device. 162 * resume_device_early - Power on one device (early resume).
67 * @dev: Device. 163 * @dev: Device.
68 * 164 *
165 * Must be called with interrupts disabled.
69 */ 166 */
70 167static int resume_device_early(struct device *dev)
71static int resume_device(struct device * dev)
72{ 168{
73 int error = 0; 169 int error = 0;
74 170
75 TRACE_DEVICE(dev); 171 TRACE_DEVICE(dev);
76 TRACE_RESUME(0); 172 TRACE_RESUME(0);
77 173
78 down(&dev->sem); 174 if (dev->bus && dev->bus->resume_early) {
175 dev_dbg(dev, "EARLY resume\n");
176 error = dev->bus->resume_early(dev);
177 }
178
179 TRACE_RESUME(error);
180 return error;
181}
182
183/**
184 * dpm_power_up - Power on all regular (non-sysdev) devices.
185 *
186 * Walk the dpm_off_irq list and power each device up. This
187 * is used for devices that required they be powered down with
188 * interrupts disabled. As devices are powered on, they are moved
189 * to the dpm_off list.
190 *
191 * Must be called with interrupts disabled and only one CPU running.
192 */
193static void dpm_power_up(void)
194{
195
196 while (!list_empty(&dpm_off_irq)) {
197 struct list_head *entry = dpm_off_irq.next;
198 struct device *dev = to_device(entry);
199
200 list_move_tail(entry, &dpm_off);
201 resume_device_early(dev);
202 }
203}
204
205/**
206 * device_power_up - Turn on all devices that need special attention.
207 *
208 * Power on system devices, then devices that required we shut them down
209 * with interrupts disabled.
210 *
211 * Must be called with interrupts disabled.
212 */
213void device_power_up(void)
214{
215 sysdev_resume();
216 dpm_power_up();
217}
218EXPORT_SYMBOL_GPL(device_power_up);
219
220/**
221 * resume_device - Restore state for one device.
222 * @dev: Device.
223 *
224 */
225static int resume_device(struct device *dev)
226{
227 int error = 0;
228
229 TRACE_DEVICE(dev);
230 TRACE_RESUME(0);
79 231
80 if (dev->bus && dev->bus->resume) { 232 if (dev->bus && dev->bus->resume) {
81 dev_dbg(dev,"resuming\n"); 233 dev_dbg(dev,"resuming\n");
@@ -92,126 +244,94 @@ static int resume_device(struct device * dev)
92 error = dev->class->resume(dev); 244 error = dev->class->resume(dev);
93 } 245 }
94 246
95 up(&dev->sem);
96
97 TRACE_RESUME(error); 247 TRACE_RESUME(error);
98 return error; 248 return error;
99} 249}
100 250
101 251/**
102static int resume_device_early(struct device * dev) 252 * dpm_resume - Resume every device.
103{ 253 *
104 int error = 0; 254 * Resume the devices that have either not gone through
105 255 * the late suspend, or that did go through it but also
106 TRACE_DEVICE(dev); 256 * went through the early resume.
107 TRACE_RESUME(0); 257 *
108 if (dev->bus && dev->bus->resume_early) { 258 * Take devices from the dpm_off_list, resume them,
109 dev_dbg(dev,"EARLY resume\n"); 259 * and put them on the dpm_locked list.
110 error = dev->bus->resume_early(dev);
111 }
112 TRACE_RESUME(error);
113 return error;
114}
115
116/*
117 * Resume the devices that have either not gone through
118 * the late suspend, or that did go through it but also
119 * went through the early resume
120 */ 260 */
121static void dpm_resume(void) 261static void dpm_resume(void)
122{ 262{
123 mutex_lock(&dpm_list_mtx); 263 mutex_lock(&dpm_list_mtx);
124 while(!list_empty(&dpm_off)) { 264 while(!list_empty(&dpm_off)) {
125 struct list_head * entry = dpm_off.next; 265 struct list_head *entry = dpm_off.next;
126 struct device * dev = to_device(entry); 266 struct device *dev = to_device(entry);
127
128 get_device(dev);
129 list_move_tail(entry, &dpm_active);
130 267
268 list_move_tail(entry, &dpm_locked);
131 mutex_unlock(&dpm_list_mtx); 269 mutex_unlock(&dpm_list_mtx);
132 resume_device(dev); 270 resume_device(dev);
133 mutex_lock(&dpm_list_mtx); 271 mutex_lock(&dpm_list_mtx);
134 put_device(dev);
135 } 272 }
136 mutex_unlock(&dpm_list_mtx); 273 mutex_unlock(&dpm_list_mtx);
137} 274}
138 275
139
140/** 276/**
141 * device_resume - Restore state of each device in system. 277 * unlock_all_devices - Release each device's semaphore
142 * 278 *
143 * Walk the dpm_off list, remove each entry, resume the device, 279 * Go through the dpm_off list. Put each device on the dpm_active
144 * then add it to the dpm_active list. 280 * list and unlock it.
145 */ 281 */
146 282static void unlock_all_devices(void)
147void device_resume(void)
148{ 283{
149 might_sleep(); 284 mutex_lock(&dpm_list_mtx);
150 mutex_lock(&dpm_mtx); 285 while (!list_empty(&dpm_locked)) {
151 dpm_resume(); 286 struct list_head *entry = dpm_locked.prev;
152 mutex_unlock(&dpm_mtx); 287 struct device *dev = to_device(entry);
153}
154
155EXPORT_SYMBOL_GPL(device_resume);
156 288
289 list_move(entry, &dpm_active);
290 up(&dev->sem);
291 }
292 mutex_unlock(&dpm_list_mtx);
293}
157 294
158/** 295/**
159 * dpm_power_up - Power on some devices. 296 * unregister_dropped_devices - Unregister devices scheduled for removal
160 *
161 * Walk the dpm_off_irq list and power each device up. This
162 * is used for devices that required they be powered down with
163 * interrupts disabled. As devices are powered on, they are moved
164 * to the dpm_active list.
165 * 297 *
166 * Interrupts must be disabled when calling this. 298 * Unregister all devices on the dpm_destroy list.
167 */ 299 */
168 300static void unregister_dropped_devices(void)
169static void dpm_power_up(void)
170{ 301{
171 while(!list_empty(&dpm_off_irq)) { 302 mutex_lock(&dpm_list_mtx);
172 struct list_head * entry = dpm_off_irq.next; 303 while (!list_empty(&dpm_destroy)) {
173 struct device * dev = to_device(entry); 304 struct list_head *entry = dpm_destroy.next;
305 struct device *dev = to_device(entry);
174 306
175 list_move_tail(entry, &dpm_off); 307 up(&dev->sem);
176 resume_device_early(dev); 308 mutex_unlock(&dpm_list_mtx);
309 /* This also removes the device from the list */
310 device_unregister(dev);
311 mutex_lock(&dpm_list_mtx);
177 } 312 }
313 mutex_unlock(&dpm_list_mtx);
178} 314}
179 315
180
181/** 316/**
182 * device_power_up - Turn on all devices that need special attention. 317 * device_resume - Restore state of each device in system.
183 * 318 *
184 * Power on system devices then devices that required we shut them down 319 * Resume all the devices, unlock them all, and allow new
185 * with interrupts disabled. 320 * devices to be registered once again.
186 * Called with interrupts disabled.
187 */ 321 */
188 322void device_resume(void)
189void device_power_up(void)
190{ 323{
191 sysdev_resume(); 324 might_sleep();
192 dpm_power_up(); 325 dpm_resume();
326 unlock_all_devices();
327 unregister_dropped_devices();
328 up_write(&pm_sleep_rwsem);
193} 329}
194 330EXPORT_SYMBOL_GPL(device_resume);
195EXPORT_SYMBOL_GPL(device_power_up);
196 331
197 332
198/*------------------------- Suspend routines -------------------------*/ 333/*------------------------- Suspend routines -------------------------*/
199 334
200/*
201 * The entries in the dpm_active list are in a depth first order, simply
202 * because children are guaranteed to be discovered after parents, and
203 * are inserted at the back of the list on discovery.
204 *
205 * All list on the suspend path are done in reverse order, so we operate
206 * on the leaves of the device tree (or forests, depending on how you want
207 * to look at it ;) first. As nodes are removed from the back of the list,
208 * they are inserted into the front of their destintation lists.
209 *
210 * Things are the reverse on the resume path - iterations are done in
211 * forward order, and nodes are inserted at the back of their destination
212 * lists. This way, the ancestors will be accessed before their descendents.
213 */
214
215static inline char *suspend_verb(u32 event) 335static inline char *suspend_verb(u32 event)
216{ 336{
217 switch (event) { 337 switch (event) {
@@ -222,7 +342,6 @@ static inline char *suspend_verb(u32 event)
222 } 342 }
223} 343}
224 344
225
226static void 345static void
227suspend_device_dbg(struct device *dev, pm_message_t state, char *info) 346suspend_device_dbg(struct device *dev, pm_message_t state, char *info)
228{ 347{
@@ -232,16 +351,73 @@ suspend_device_dbg(struct device *dev, pm_message_t state, char *info)
232} 351}
233 352
234/** 353/**
235 * suspend_device - Save state of one device. 354 * suspend_device_late - Shut down one device (late suspend).
236 * @dev: Device. 355 * @dev: Device.
237 * @state: Power state device is entering. 356 * @state: Power state device is entering.
357 *
358 * This is called with interrupts off and only a single CPU running.
238 */ 359 */
360static int suspend_device_late(struct device *dev, pm_message_t state)
361{
362 int error = 0;
239 363
240static int suspend_device(struct device * dev, pm_message_t state) 364 if (dev->bus && dev->bus->suspend_late) {
365 suspend_device_dbg(dev, state, "LATE ");
366 error = dev->bus->suspend_late(dev, state);
367 suspend_report_result(dev->bus->suspend_late, error);
368 }
369 return error;
370}
371
372/**
373 * device_power_down - Shut down special devices.
374 * @state: Power state to enter.
375 *
376 * Power down devices that require interrupts to be disabled
377 * and move them from the dpm_off list to the dpm_off_irq list.
378 * Then power down system devices.
379 *
380 * Must be called with interrupts disabled and only one CPU running.
381 */
382int device_power_down(pm_message_t state)
383{
384 int error = 0;
385
386 while (!list_empty(&dpm_off)) {
387 struct list_head *entry = dpm_off.prev;
388 struct device *dev = to_device(entry);
389
390 list_del_init(&dev->power.entry);
391 error = suspend_device_late(dev, state);
392 if (error) {
393 printk(KERN_ERR "Could not power down device %s: "
394 "error %d\n",
395 kobject_name(&dev->kobj), error);
396 if (list_empty(&dev->power.entry))
397 list_add(&dev->power.entry, &dpm_off);
398 break;
399 }
400 if (list_empty(&dev->power.entry))
401 list_add(&dev->power.entry, &dpm_off_irq);
402 }
403
404 if (!error)
405 error = sysdev_suspend(state);
406 if (error)
407 dpm_power_up();
408 return error;
409}
410EXPORT_SYMBOL_GPL(device_power_down);
411
412/**
413 * suspend_device - Save state of one device.
414 * @dev: Device.
415 * @state: Power state device is entering.
416 */
417int suspend_device(struct device *dev, pm_message_t state)
241{ 418{
242 int error = 0; 419 int error = 0;
243 420
244 down(&dev->sem);
245 if (dev->power.power_state.event) { 421 if (dev->power.power_state.event) {
246 dev_dbg(dev, "PM: suspend %d-->%d\n", 422 dev_dbg(dev, "PM: suspend %d-->%d\n",
247 dev->power.power_state.event, state.event); 423 dev->power.power_state.event, state.event);
@@ -264,123 +440,105 @@ static int suspend_device(struct device * dev, pm_message_t state)
264 error = dev->bus->suspend(dev, state); 440 error = dev->bus->suspend(dev, state);
265 suspend_report_result(dev->bus->suspend, error); 441 suspend_report_result(dev->bus->suspend, error);
266 } 442 }
267 up(&dev->sem);
268 return error;
269}
270
271
272/*
273 * This is called with interrupts off, only a single CPU
274 * running. We can't acquire a mutex or semaphore (and we don't
275 * need the protection)
276 */
277static int suspend_device_late(struct device *dev, pm_message_t state)
278{
279 int error = 0;
280
281 if (dev->bus && dev->bus->suspend_late) {
282 suspend_device_dbg(dev, state, "LATE ");
283 error = dev->bus->suspend_late(dev, state);
284 suspend_report_result(dev->bus->suspend_late, error);
285 }
286 return error; 443 return error;
287} 444}
288 445
289/** 446/**
290 * device_suspend - Save state and stop all devices in system. 447 * dpm_suspend - Suspend every device.
291 * @state: Power state to put each device in. 448 * @state: Power state to put each device in.
292 * 449 *
293 * Walk the dpm_active list, call ->suspend() for each device, and move 450 * Walk the dpm_locked list. Suspend each device and move it
294 * it to the dpm_off list. 451 * to the dpm_off list.
295 * 452 *
296 * (For historical reasons, if it returns -EAGAIN, that used to mean 453 * (For historical reasons, if it returns -EAGAIN, that used to mean
297 * that the device would be called again with interrupts disabled. 454 * that the device would be called again with interrupts disabled.
298 * These days, we use the "suspend_late()" callback for that, so we 455 * These days, we use the "suspend_late()" callback for that, so we
299 * print a warning and consider it an error). 456 * print a warning and consider it an error).
300 *
301 * If we get a different error, try and back out.
302 *
303 * If we hit a failure with any of the devices, call device_resume()
304 * above to bring the suspended devices back to life.
305 *
306 */ 457 */
307 458static int dpm_suspend(pm_message_t state)
308int device_suspend(pm_message_t state)
309{ 459{
310 int error = 0; 460 int error = 0;
311 461
312 might_sleep();
313 mutex_lock(&dpm_mtx);
314 mutex_lock(&dpm_list_mtx); 462 mutex_lock(&dpm_list_mtx);
315 while (!list_empty(&dpm_active) && error == 0) { 463 while (!list_empty(&dpm_locked)) {
316 struct list_head * entry = dpm_active.prev; 464 struct list_head *entry = dpm_locked.prev;
317 struct device * dev = to_device(entry); 465 struct device *dev = to_device(entry);
318 466
319 get_device(dev); 467 list_del_init(&dev->power.entry);
320 mutex_unlock(&dpm_list_mtx); 468 mutex_unlock(&dpm_list_mtx);
321
322 error = suspend_device(dev, state); 469 error = suspend_device(dev, state);
323 470 if (error) {
324 mutex_lock(&dpm_list_mtx);
325
326 /* Check if the device got removed */
327 if (!list_empty(&dev->power.entry)) {
328 /* Move it to the dpm_off list */
329 if (!error)
330 list_move(&dev->power.entry, &dpm_off);
331 }
332 if (error)
333 printk(KERN_ERR "Could not suspend device %s: " 471 printk(KERN_ERR "Could not suspend device %s: "
334 "error %d%s\n", 472 "error %d%s\n",
335 kobject_name(&dev->kobj), error, 473 kobject_name(&dev->kobj),
336 error == -EAGAIN ? " (please convert to suspend_late)" : ""); 474 error,
337 put_device(dev); 475 (error == -EAGAIN ?
476 " (please convert to suspend_late)" :
477 ""));
478 mutex_lock(&dpm_list_mtx);
479 if (list_empty(&dev->power.entry))
480 list_add(&dev->power.entry, &dpm_locked);
481 mutex_unlock(&dpm_list_mtx);
482 break;
483 }
484 mutex_lock(&dpm_list_mtx);
485 if (list_empty(&dev->power.entry))
486 list_add(&dev->power.entry, &dpm_off);
338 } 487 }
339 mutex_unlock(&dpm_list_mtx); 488 mutex_unlock(&dpm_list_mtx);
340 if (error)
341 dpm_resume();
342 489
343 mutex_unlock(&dpm_mtx);
344 return error; 490 return error;
345} 491}
346 492
347EXPORT_SYMBOL_GPL(device_suspend);
348
349/** 493/**
350 * device_power_down - Shut down special devices. 494 * lock_all_devices - Acquire every device's semaphore
351 * @state: Power state to enter.
352 * 495 *
353 * Walk the dpm_off_irq list, calling ->power_down() for each device that 496 * Go through the dpm_active list. Carefully lock each device's
354 * couldn't power down the device with interrupts enabled. When we're 497 * semaphore and put it in on the dpm_locked list.
355 * done, power down system devices.
356 */ 498 */
357 499static void lock_all_devices(void)
358int device_power_down(pm_message_t state)
359{ 500{
360 int error = 0; 501 mutex_lock(&dpm_list_mtx);
361 struct device * dev; 502 while (!list_empty(&dpm_active)) {
503 struct list_head *entry = dpm_active.next;
504 struct device *dev = to_device(entry);
362 505
363 while (!list_empty(&dpm_off)) { 506 /* Required locking order is dev->sem first,
364 struct list_head * entry = dpm_off.prev; 507 * then dpm_list_mutex. Hence this awkward code.
508 */
509 get_device(dev);
510 mutex_unlock(&dpm_list_mtx);
511 down(&dev->sem);
512 mutex_lock(&dpm_list_mtx);
365 513
366 dev = to_device(entry); 514 if (list_empty(entry))
367 error = suspend_device_late(dev, state); 515 up(&dev->sem); /* Device was removed */
368 if (error) 516 else
369 goto Error; 517 list_move_tail(entry, &dpm_locked);
370 list_move(&dev->power.entry, &dpm_off_irq); 518 put_device(dev);
371 } 519 }
520 mutex_unlock(&dpm_list_mtx);
521}
522
523/**
524 * device_suspend - Save state and stop all devices in system.
525 *
526 * Prevent new devices from being registered, then lock all devices
527 * and suspend them.
528 */
529int device_suspend(pm_message_t state)
530{
531 int error;
372 532
373 error = sysdev_suspend(state); 533 might_sleep();
374 Done: 534 down_write(&pm_sleep_rwsem);
535 lock_all_devices();
536 error = dpm_suspend(state);
537 if (error)
538 device_resume();
375 return error; 539 return error;
376 Error:
377 printk(KERN_ERR "Could not power down device %s: "
378 "error %d\n", kobject_name(&dev->kobj), error);
379 dpm_power_up();
380 goto Done;
381} 540}
382 541EXPORT_SYMBOL_GPL(device_suspend);
383EXPORT_SYMBOL_GPL(device_power_down);
384 542
385void __suspend_report_result(const char *function, void *fn, int ret) 543void __suspend_report_result(const char *function, void *fn, int ret)
386{ 544{
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 379da4e958e0..6f0dfca8ebdd 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -1,10 +1,3 @@
1/*
2 * shutdown.c
3 */
4
5extern void device_shutdown(void);
6
7
8#ifdef CONFIG_PM_SLEEP 1#ifdef CONFIG_PM_SLEEP
9 2
10/* 3/*
@@ -20,6 +13,9 @@ static inline struct device *to_device(struct list_head *entry)
20 13
21extern void device_pm_add(struct device *); 14extern void device_pm_add(struct device *);
22extern void device_pm_remove(struct device *); 15extern void device_pm_remove(struct device *);
16extern void device_pm_schedule_removal(struct device *);
17extern int pm_sleep_lock(void);
18extern void pm_sleep_unlock(void);
23 19
24#else /* CONFIG_PM_SLEEP */ 20#else /* CONFIG_PM_SLEEP */
25 21
@@ -32,6 +28,15 @@ static inline void device_pm_remove(struct device *dev)
32{ 28{
33} 29}
34 30
31static inline int pm_sleep_lock(void)
32{
33 return 0;
34}
35
36static inline void pm_sleep_unlock(void)
37{
38}
39
35#endif 40#endif
36 41
37#ifdef CONFIG_PM 42#ifdef CONFIG_PM
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
deleted file mode 100644
index 56e8eaaac012..000000000000
--- a/drivers/base/power/shutdown.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * shutdown.c - power management functions for the device tree.
3 *
4 * Copyright (c) 2002-3 Patrick Mochel
5 * 2002-3 Open Source Development Lab
6 *
7 * This file is released under the GPLv2
8 *
9 */
10
11#include <linux/device.h>
12#include <asm/semaphore.h>
13
14#include "../base.h"
15#include "power.h"
16
17#define to_dev(node) container_of(node, struct device, kobj.entry)
18
19
20/**
21 * We handle system devices differently - we suspend and shut them
22 * down last and resume them first. That way, we don't do anything stupid like
23 * shutting down the interrupt controller before any devices..
24 *
25 * Note that there are not different stages for power management calls -
26 * they only get one called once when interrupts are disabled.
27 */
28
29
30/**
31 * device_shutdown - call ->shutdown() on each device to shutdown.
32 */
33void device_shutdown(void)
34{
35 struct device * dev, *devn;
36
37 list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.list,
38 kobj.entry) {
39 if (dev->bus && dev->bus->shutdown) {
40 dev_dbg(dev, "shutdown\n");
41 dev->bus->shutdown(dev);
42 } else if (dev->driver && dev->driver->shutdown) {
43 dev_dbg(dev, "shutdown\n");
44 dev->driver->shutdown(dev);
45 }
46 }
47}
48
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index ac7ff6d0c6e5..2f79c55acdcc 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -25,8 +25,6 @@
25 25
26#include "base.h" 26#include "base.h"
27 27
28extern struct kset devices_subsys;
29
30#define to_sysdev(k) container_of(k, struct sys_device, kobj) 28#define to_sysdev(k) container_of(k, struct sys_device, kobj)
31#define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr) 29#define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr)
32 30
@@ -128,18 +126,17 @@ void sysdev_class_remove_file(struct sysdev_class *c,
128} 126}
129EXPORT_SYMBOL_GPL(sysdev_class_remove_file); 127EXPORT_SYMBOL_GPL(sysdev_class_remove_file);
130 128
131/* 129static struct kset *system_kset;
132 * declare system_subsys
133 */
134static decl_subsys(system, &ktype_sysdev_class, NULL);
135 130
136int sysdev_class_register(struct sysdev_class * cls) 131int sysdev_class_register(struct sysdev_class * cls)
137{ 132{
138 pr_debug("Registering sysdev class '%s'\n", 133 pr_debug("Registering sysdev class '%s'\n",
139 kobject_name(&cls->kset.kobj)); 134 kobject_name(&cls->kset.kobj));
140 INIT_LIST_HEAD(&cls->drivers); 135 INIT_LIST_HEAD(&cls->drivers);
141 cls->kset.kobj.parent = &system_subsys.kobj; 136 cls->kset.kobj.parent = &system_kset->kobj;
142 cls->kset.kobj.kset = &system_subsys; 137 cls->kset.kobj.ktype = &ktype_sysdev_class;
138 cls->kset.kobj.kset = system_kset;
139 kobject_set_name(&cls->kset.kobj, cls->name);
143 return kset_register(&cls->kset); 140 return kset_register(&cls->kset);
144} 141}
145 142
@@ -228,20 +225,15 @@ int sysdev_register(struct sys_device * sysdev)
228 if (!cls) 225 if (!cls)
229 return -EINVAL; 226 return -EINVAL;
230 227
228 pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj));
229
231 /* Make sure the kset is set */ 230 /* Make sure the kset is set */
232 sysdev->kobj.kset = &cls->kset; 231 sysdev->kobj.kset = &cls->kset;
233 232
234 /* But make sure we point to the right type for sysfs translation */
235 sysdev->kobj.ktype = &ktype_sysdev;
236 error = kobject_set_name(&sysdev->kobj, "%s%d",
237 kobject_name(&cls->kset.kobj), sysdev->id);
238 if (error)
239 return error;
240
241 pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj));
242
243 /* Register the object */ 233 /* Register the object */
244 error = kobject_register(&sysdev->kobj); 234 error = kobject_init_and_add(&sysdev->kobj, &ktype_sysdev, NULL,
235 "%s%d", kobject_name(&cls->kset.kobj),
236 sysdev->id);
245 237
246 if (!error) { 238 if (!error) {
247 struct sysdev_driver * drv; 239 struct sysdev_driver * drv;
@@ -258,6 +250,7 @@ int sysdev_register(struct sys_device * sysdev)
258 } 250 }
259 mutex_unlock(&sysdev_drivers_lock); 251 mutex_unlock(&sysdev_drivers_lock);
260 } 252 }
253 kobject_uevent(&sysdev->kobj, KOBJ_ADD);
261 return error; 254 return error;
262} 255}
263 256
@@ -272,7 +265,7 @@ void sysdev_unregister(struct sys_device * sysdev)
272 } 265 }
273 mutex_unlock(&sysdev_drivers_lock); 266 mutex_unlock(&sysdev_drivers_lock);
274 267
275 kobject_unregister(&sysdev->kobj); 268 kobject_put(&sysdev->kobj);
276} 269}
277 270
278 271
@@ -298,8 +291,7 @@ void sysdev_shutdown(void)
298 pr_debug("Shutting Down System Devices\n"); 291 pr_debug("Shutting Down System Devices\n");
299 292
300 mutex_lock(&sysdev_drivers_lock); 293 mutex_lock(&sysdev_drivers_lock);
301 list_for_each_entry_reverse(cls, &system_subsys.list, 294 list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
302 kset.kobj.entry) {
303 struct sys_device * sysdev; 295 struct sys_device * sysdev;
304 296
305 pr_debug("Shutting down type '%s':\n", 297 pr_debug("Shutting down type '%s':\n",
@@ -361,9 +353,7 @@ int sysdev_suspend(pm_message_t state)
361 353
362 pr_debug("Suspending System Devices\n"); 354 pr_debug("Suspending System Devices\n");
363 355
364 list_for_each_entry_reverse(cls, &system_subsys.list, 356 list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
365 kset.kobj.entry) {
366
367 pr_debug("Suspending type '%s':\n", 357 pr_debug("Suspending type '%s':\n",
368 kobject_name(&cls->kset.kobj)); 358 kobject_name(&cls->kset.kobj));
369 359
@@ -414,8 +404,7 @@ aux_driver:
414 } 404 }
415 405
416 /* resume other classes */ 406 /* resume other classes */
417 list_for_each_entry_continue(cls, &system_subsys.list, 407 list_for_each_entry_continue(cls, &system_kset->list, kset.kobj.entry) {
418 kset.kobj.entry) {
419 list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { 408 list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) {
420 pr_debug(" %s\n", kobject_name(&err_dev->kobj)); 409 pr_debug(" %s\n", kobject_name(&err_dev->kobj));
421 __sysdev_resume(err_dev); 410 __sysdev_resume(err_dev);
@@ -440,7 +429,7 @@ int sysdev_resume(void)
440 429
441 pr_debug("Resuming System Devices\n"); 430 pr_debug("Resuming System Devices\n");
442 431
443 list_for_each_entry(cls, &system_subsys.list, kset.kobj.entry) { 432 list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) {
444 struct sys_device * sysdev; 433 struct sys_device * sysdev;
445 434
446 pr_debug("Resuming type '%s':\n", 435 pr_debug("Resuming type '%s':\n",
@@ -458,8 +447,10 @@ int sysdev_resume(void)
458 447
459int __init system_bus_init(void) 448int __init system_bus_init(void)
460{ 449{
461 system_subsys.kobj.parent = &devices_subsys.kobj; 450 system_kset = kset_create_and_add("system", NULL, &devices_kset->kobj);
462 return subsystem_register(&system_subsys); 451 if (!system_kset)
452 return -ENOMEM;
453 return 0;
463} 454}
464 455
465EXPORT_SYMBOL_GPL(sysdev_register); 456EXPORT_SYMBOL_GPL(sysdev_register);
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index ad00b3d94711..826d12381e21 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -15,8 +15,10 @@
15 15
16static struct kmem_cache *buf_pool_cache; 16static struct kmem_cache *buf_pool_cache;
17 17
18static ssize_t aoedisk_show_state(struct gendisk * disk, char *page) 18static ssize_t aoedisk_show_state(struct device *dev,
19 struct device_attribute *attr, char *page)
19{ 20{
21 struct gendisk *disk = dev_to_disk(dev);
20 struct aoedev *d = disk->private_data; 22 struct aoedev *d = disk->private_data;
21 23
22 return snprintf(page, PAGE_SIZE, 24 return snprintf(page, PAGE_SIZE,
@@ -26,50 +28,47 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
26 (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : ""); 28 (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
27 /* I'd rather see nopen exported so we can ditch closewait */ 29 /* I'd rather see nopen exported so we can ditch closewait */
28} 30}
29static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page) 31static ssize_t aoedisk_show_mac(struct device *dev,
32 struct device_attribute *attr, char *page)
30{ 33{
34 struct gendisk *disk = dev_to_disk(dev);
31 struct aoedev *d = disk->private_data; 35 struct aoedev *d = disk->private_data;
32 36
33 return snprintf(page, PAGE_SIZE, "%012llx\n", 37 return snprintf(page, PAGE_SIZE, "%012llx\n",
34 (unsigned long long)mac_addr(d->addr)); 38 (unsigned long long)mac_addr(d->addr));
35} 39}
36static ssize_t aoedisk_show_netif(struct gendisk * disk, char *page) 40static ssize_t aoedisk_show_netif(struct device *dev,
41 struct device_attribute *attr, char *page)
37{ 42{
43 struct gendisk *disk = dev_to_disk(dev);
38 struct aoedev *d = disk->private_data; 44 struct aoedev *d = disk->private_data;
39 45
40 return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name); 46 return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name);
41} 47}
42/* firmware version */ 48/* firmware version */
43static ssize_t aoedisk_show_fwver(struct gendisk * disk, char *page) 49static ssize_t aoedisk_show_fwver(struct device *dev,
50 struct device_attribute *attr, char *page)
44{ 51{
52 struct gendisk *disk = dev_to_disk(dev);
45 struct aoedev *d = disk->private_data; 53 struct aoedev *d = disk->private_data;
46 54
47 return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver); 55 return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver);
48} 56}
49 57
50static struct disk_attribute disk_attr_state = { 58static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL);
51 .attr = {.name = "state", .mode = S_IRUGO }, 59static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL);
52 .show = aoedisk_show_state 60static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL);
53}; 61static struct device_attribute dev_attr_firmware_version = {
54static struct disk_attribute disk_attr_mac = { 62 .attr = { .name = "firmware-version", .mode = S_IRUGO, .owner = THIS_MODULE },
55 .attr = {.name = "mac", .mode = S_IRUGO }, 63 .show = aoedisk_show_fwver,
56 .show = aoedisk_show_mac
57};
58static struct disk_attribute disk_attr_netif = {
59 .attr = {.name = "netif", .mode = S_IRUGO },
60 .show = aoedisk_show_netif
61};
62static struct disk_attribute disk_attr_fwver = {
63 .attr = {.name = "firmware-version", .mode = S_IRUGO },
64 .show = aoedisk_show_fwver
65}; 64};
66 65
67static struct attribute *aoe_attrs[] = { 66static struct attribute *aoe_attrs[] = {
68 &disk_attr_state.attr, 67 &dev_attr_state.attr,
69 &disk_attr_mac.attr, 68 &dev_attr_mac.attr,
70 &disk_attr_netif.attr, 69 &dev_attr_netif.attr,
71 &disk_attr_fwver.attr, 70 &dev_attr_firmware_version.attr,
72 NULL 71 NULL,
73}; 72};
74 73
75static const struct attribute_group attr_group = { 74static const struct attribute_group attr_group = {
@@ -79,12 +78,12 @@ static const struct attribute_group attr_group = {
79static int 78static int
80aoedisk_add_sysfs(struct aoedev *d) 79aoedisk_add_sysfs(struct aoedev *d)
81{ 80{
82 return sysfs_create_group(&d->gd->kobj, &attr_group); 81 return sysfs_create_group(&d->gd->dev.kobj, &attr_group);
83} 82}
84void 83void
85aoedisk_rm_sysfs(struct aoedev *d) 84aoedisk_rm_sysfs(struct aoedev *d)
86{ 85{
87 sysfs_remove_group(&d->gd->kobj, &attr_group); 86 sysfs_remove_group(&d->gd->dev.kobj, &attr_group);
88} 87}
89 88
90static int 89static int
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 39e563ea0878..d5480e34cb22 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -259,9 +259,8 @@ aoechr_init(void)
259 return PTR_ERR(aoe_class); 259 return PTR_ERR(aoe_class);
260 } 260 }
261 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 261 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
262 class_device_create(aoe_class, NULL, 262 device_create(aoe_class, NULL,
263 MKDEV(AOE_MAJOR, chardevs[i].minor), 263 MKDEV(AOE_MAJOR, chardevs[i].minor), chardevs[i].name);
264 NULL, chardevs[i].name);
265 264
266 return 0; 265 return 0;
267} 266}
@@ -272,7 +271,7 @@ aoechr_exit(void)
272 int i; 271 int i;
273 272
274 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 273 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
275 class_device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor)); 274 device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor));
276 class_destroy(aoe_class); 275 class_destroy(aoe_class);
277 unregister_chrdev(AOE_MAJOR, "aoechr"); 276 unregister_chrdev(AOE_MAJOR, "aoechr");
278} 277}
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b4c0888aedc3..ba9b17e507e0 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -375,14 +375,17 @@ harderror:
375 return NULL; 375 return NULL;
376} 376}
377 377
378static ssize_t pid_show(struct gendisk *disk, char *page) 378static ssize_t pid_show(struct device *dev,
379 struct device_attribute *attr, char *buf)
379{ 380{
380 return sprintf(page, "%ld\n", 381 struct gendisk *disk = dev_to_disk(dev);
382
383 return sprintf(buf, "%ld\n",
381 (long) ((struct nbd_device *)disk->private_data)->pid); 384 (long) ((struct nbd_device *)disk->private_data)->pid);
382} 385}
383 386
384static struct disk_attribute pid_attr = { 387static struct device_attribute pid_attr = {
385 .attr = { .name = "pid", .mode = S_IRUGO }, 388 .attr = { .name = "pid", .mode = S_IRUGO, .owner = THIS_MODULE },
386 .show = pid_show, 389 .show = pid_show,
387}; 390};
388 391
@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo)
394 BUG_ON(lo->magic != LO_MAGIC); 397 BUG_ON(lo->magic != LO_MAGIC);
395 398
396 lo->pid = current->pid; 399 lo->pid = current->pid;
397 ret = sysfs_create_file(&lo->disk->kobj, &pid_attr.attr); 400 ret = sysfs_create_file(&lo->disk->dev.kobj, &pid_attr.attr);
398 if (ret) { 401 if (ret) {
399 printk(KERN_ERR "nbd: sysfs_create_file failed!"); 402 printk(KERN_ERR "nbd: sysfs_create_file failed!");
400 return ret; 403 return ret;
@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)
403 while ((req = nbd_read_stat(lo)) != NULL) 406 while ((req = nbd_read_stat(lo)) != NULL)
404 nbd_end_request(req); 407 nbd_end_request(req);
405 408
406 sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr); 409 sysfs_remove_file(&lo->disk->dev.kobj, &pid_attr.attr);
407 return 0; 410 return 0;
408} 411}
409 412
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index d89e7d32a3b6..ab86e23ddc69 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -676,8 +676,8 @@ static int __init pg_init(void)
676 for (unit = 0; unit < PG_UNITS; unit++) { 676 for (unit = 0; unit < PG_UNITS; unit++) {
677 struct pg *dev = &devices[unit]; 677 struct pg *dev = &devices[unit];
678 if (dev->present) 678 if (dev->present)
679 class_device_create(pg_class, NULL, MKDEV(major, unit), 679 device_create(pg_class, NULL, MKDEV(major, unit),
680 NULL, "pg%u", unit); 680 "pg%u", unit);
681 } 681 }
682 err = 0; 682 err = 0;
683 goto out; 683 goto out;
@@ -695,7 +695,7 @@ static void __exit pg_exit(void)
695 for (unit = 0; unit < PG_UNITS; unit++) { 695 for (unit = 0; unit < PG_UNITS; unit++) {
696 struct pg *dev = &devices[unit]; 696 struct pg *dev = &devices[unit];
697 if (dev->present) 697 if (dev->present)
698 class_device_destroy(pg_class, MKDEV(major, unit)); 698 device_destroy(pg_class, MKDEV(major, unit));
699 } 699 }
700 class_destroy(pg_class); 700 class_destroy(pg_class);
701 unregister_chrdev(major, name); 701 unregister_chrdev(major, name);
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index b91accf12656..76096cad798f 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -972,10 +972,10 @@ static int __init pt_init(void)
972 972
973 for (unit = 0; unit < PT_UNITS; unit++) 973 for (unit = 0; unit < PT_UNITS; unit++)
974 if (pt[unit].present) { 974 if (pt[unit].present) {
975 class_device_create(pt_class, NULL, MKDEV(major, unit), 975 device_create(pt_class, NULL, MKDEV(major, unit),
976 NULL, "pt%d", unit); 976 "pt%d", unit);
977 class_device_create(pt_class, NULL, MKDEV(major, unit + 128), 977 device_create(pt_class, NULL, MKDEV(major, unit + 128),
978 NULL, "pt%dn", unit); 978 "pt%dn", unit);
979 } 979 }
980 goto out; 980 goto out;
981 981
@@ -990,8 +990,8 @@ static void __exit pt_exit(void)
990 int unit; 990 int unit;
991 for (unit = 0; unit < PT_UNITS; unit++) 991 for (unit = 0; unit < PT_UNITS; unit++)
992 if (pt[unit].present) { 992 if (pt[unit].present) {
993 class_device_destroy(pt_class, MKDEV(major, unit)); 993 device_destroy(pt_class, MKDEV(major, unit));
994 class_device_destroy(pt_class, MKDEV(major, unit + 128)); 994 device_destroy(pt_class, MKDEV(major, unit + 128));
995 } 995 }
996 class_destroy(pt_class); 996 class_destroy(pt_class);
997 unregister_chrdev(major, name); 997 unregister_chrdev(major, name);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 3535ef896677..e9de1712e5a0 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -110,17 +110,18 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
110 struct kobj_type* ktype) 110 struct kobj_type* ktype)
111{ 111{
112 struct pktcdvd_kobj *p; 112 struct pktcdvd_kobj *p;
113 int error;
114
113 p = kzalloc(sizeof(*p), GFP_KERNEL); 115 p = kzalloc(sizeof(*p), GFP_KERNEL);
114 if (!p) 116 if (!p)
115 return NULL; 117 return NULL;
116 kobject_set_name(&p->kobj, "%s", name);
117 p->kobj.parent = parent;
118 p->kobj.ktype = ktype;
119 p->pd = pd; 118 p->pd = pd;
120 if (kobject_register(&p->kobj) != 0) { 119 error = kobject_init_and_add(&p->kobj, ktype, parent, "%s", name);
120 if (error) {
121 kobject_put(&p->kobj); 121 kobject_put(&p->kobj);
122 return NULL; 122 return NULL;
123 } 123 }
124 kobject_uevent(&p->kobj, KOBJ_ADD);
124 return p; 125 return p;
125} 126}
126/* 127/*
@@ -129,7 +130,7 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
129static void pkt_kobj_remove(struct pktcdvd_kobj *p) 130static void pkt_kobj_remove(struct pktcdvd_kobj *p)
130{ 131{
131 if (p) 132 if (p)
132 kobject_unregister(&p->kobj); 133 kobject_put(&p->kobj);
133} 134}
134/* 135/*
135 * default release function for pktcdvd kernel objects. 136 * default release function for pktcdvd kernel objects.
@@ -301,18 +302,16 @@ static struct kobj_type kobj_pkt_type_wqueue = {
301static void pkt_sysfs_dev_new(struct pktcdvd_device *pd) 302static void pkt_sysfs_dev_new(struct pktcdvd_device *pd)
302{ 303{
303 if (class_pktcdvd) { 304 if (class_pktcdvd) {
304 pd->clsdev = class_device_create(class_pktcdvd, 305 pd->dev = device_create(class_pktcdvd, NULL, pd->pkt_dev, "%s", pd->name);
305 NULL, pd->pkt_dev, 306 if (IS_ERR(pd->dev))
306 NULL, "%s", pd->name); 307 pd->dev = NULL;
307 if (IS_ERR(pd->clsdev))
308 pd->clsdev = NULL;
309 } 308 }
310 if (pd->clsdev) { 309 if (pd->dev) {
311 pd->kobj_stat = pkt_kobj_create(pd, "stat", 310 pd->kobj_stat = pkt_kobj_create(pd, "stat",
312 &pd->clsdev->kobj, 311 &pd->dev->kobj,
313 &kobj_pkt_type_stat); 312 &kobj_pkt_type_stat);
314 pd->kobj_wqueue = pkt_kobj_create(pd, "write_queue", 313 pd->kobj_wqueue = pkt_kobj_create(pd, "write_queue",
315 &pd->clsdev->kobj, 314 &pd->dev->kobj,
316 &kobj_pkt_type_wqueue); 315 &kobj_pkt_type_wqueue);
317 } 316 }
318} 317}
@@ -322,7 +321,7 @@ static void pkt_sysfs_dev_remove(struct pktcdvd_device *pd)
322 pkt_kobj_remove(pd->kobj_stat); 321 pkt_kobj_remove(pd->kobj_stat);
323 pkt_kobj_remove(pd->kobj_wqueue); 322 pkt_kobj_remove(pd->kobj_wqueue);
324 if (class_pktcdvd) 323 if (class_pktcdvd)
325 class_device_destroy(class_pktcdvd, pd->pkt_dev); 324 device_destroy(class_pktcdvd, pd->pkt_dev);
326} 325}
327 326
328 327
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 2e3a0d4bc4c2..466629594776 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -373,6 +373,16 @@ config ISTALLION
373 To compile this driver as a module, choose M here: the 373 To compile this driver as a module, choose M here: the
374 module will be called istallion. 374 module will be called istallion.
375 375
376config NOZOMI
377 tristate "HSDPA Broadband Wireless Data Card - Globe Trotter"
378 depends on PCI && EXPERIMENTAL
379 help
380 If you have a HSDPA driver Broadband Wireless Data Card -
381 Globe Trotter PCMCIA card, say Y here.
382
383 To compile this driver as a module, choose M here, the module
384 will be called nozomi.
385
376config A2232 386config A2232
377 tristate "Commodore A2232 serial support (EXPERIMENTAL)" 387 tristate "Commodore A2232 serial support (EXPERIMENTAL)"
378 depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP 388 depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 07304d50e0cb..96fc01eddefe 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_SERIAL167) += serial167.o
26obj-$(CONFIG_CYCLADES) += cyclades.o 26obj-$(CONFIG_CYCLADES) += cyclades.o
27obj-$(CONFIG_STALLION) += stallion.o 27obj-$(CONFIG_STALLION) += stallion.o
28obj-$(CONFIG_ISTALLION) += istallion.o 28obj-$(CONFIG_ISTALLION) += istallion.o
29obj-$(CONFIG_NOZOMI) += nozomi.o
29obj-$(CONFIG_DIGIEPCA) += epca.o 30obj-$(CONFIG_DIGIEPCA) += epca.o
30obj-$(CONFIG_SPECIALIX) += specialix.o 31obj-$(CONFIG_SPECIALIX) += specialix.o
31obj-$(CONFIG_MOXA_INTELLIO) += moxa.o 32obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 8252f8668538..480fae29c9b2 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -27,7 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/kbd_kern.h> 28#include <linux/kbd_kern.h>
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/kobject.h> 30#include <linux/kref.h>
31#include <linux/kthread.h> 31#include <linux/kthread.h>
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/module.h> 33#include <linux/module.h>
@@ -89,7 +89,7 @@ struct hvc_struct {
89 int irq_requested; 89 int irq_requested;
90 int irq; 90 int irq;
91 struct list_head next; 91 struct list_head next;
92 struct kobject kobj; /* ref count & hvc_struct lifetime */ 92 struct kref kref; /* ref count & hvc_struct lifetime */
93}; 93};
94 94
95/* dynamic list of hvc_struct instances */ 95/* dynamic list of hvc_struct instances */
@@ -110,7 +110,7 @@ static int last_hvc = -1;
110 110
111/* 111/*
112 * Do not call this function with either the hvc_structs_lock or the hvc_struct 112 * Do not call this function with either the hvc_structs_lock or the hvc_struct
113 * lock held. If successful, this function increments the kobject reference 113 * lock held. If successful, this function increments the kref reference
114 * count against the target hvc_struct so it should be released when finished. 114 * count against the target hvc_struct so it should be released when finished.
115 */ 115 */
116static struct hvc_struct *hvc_get_by_index(int index) 116static struct hvc_struct *hvc_get_by_index(int index)
@@ -123,7 +123,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
123 list_for_each_entry(hp, &hvc_structs, next) { 123 list_for_each_entry(hp, &hvc_structs, next) {
124 spin_lock_irqsave(&hp->lock, flags); 124 spin_lock_irqsave(&hp->lock, flags);
125 if (hp->index == index) { 125 if (hp->index == index) {
126 kobject_get(&hp->kobj); 126 kref_get(&hp->kref);
127 spin_unlock_irqrestore(&hp->lock, flags); 127 spin_unlock_irqrestore(&hp->lock, flags);
128 spin_unlock(&hvc_structs_lock); 128 spin_unlock(&hvc_structs_lock);
129 return hp; 129 return hp;
@@ -242,6 +242,23 @@ static int __init hvc_console_init(void)
242} 242}
243console_initcall(hvc_console_init); 243console_initcall(hvc_console_init);
244 244
245/* callback when the kboject ref count reaches zero. */
246static void destroy_hvc_struct(struct kref *kref)
247{
248 struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref);
249 unsigned long flags;
250
251 spin_lock(&hvc_structs_lock);
252
253 spin_lock_irqsave(&hp->lock, flags);
254 list_del(&(hp->next));
255 spin_unlock_irqrestore(&hp->lock, flags);
256
257 spin_unlock(&hvc_structs_lock);
258
259 kfree(hp);
260}
261
245/* 262/*
246 * hvc_instantiate() is an early console discovery method which locates 263 * hvc_instantiate() is an early console discovery method which locates
247 * consoles * prior to the vio subsystem discovering them. Hotplugged 264 * consoles * prior to the vio subsystem discovering them. Hotplugged
@@ -261,7 +278,7 @@ int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
261 /* make sure no no tty has been registered in this index */ 278 /* make sure no no tty has been registered in this index */
262 hp = hvc_get_by_index(index); 279 hp = hvc_get_by_index(index);
263 if (hp) { 280 if (hp) {
264 kobject_put(&hp->kobj); 281 kref_put(&hp->kref, destroy_hvc_struct);
265 return -1; 282 return -1;
266 } 283 }
267 284
@@ -318,9 +335,8 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
318 unsigned long flags; 335 unsigned long flags;
319 int irq = 0; 336 int irq = 0;
320 int rc = 0; 337 int rc = 0;
321 struct kobject *kobjp;
322 338
323 /* Auto increments kobject reference if found. */ 339 /* Auto increments kref reference if found. */
324 if (!(hp = hvc_get_by_index(tty->index))) 340 if (!(hp = hvc_get_by_index(tty->index)))
325 return -ENODEV; 341 return -ENODEV;
326 342
@@ -341,8 +357,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
341 if (irq) 357 if (irq)
342 hp->irq_requested = 1; 358 hp->irq_requested = 1;
343 359
344 kobjp = &hp->kobj;
345
346 spin_unlock_irqrestore(&hp->lock, flags); 360 spin_unlock_irqrestore(&hp->lock, flags);
347 /* check error, fallback to non-irq */ 361 /* check error, fallback to non-irq */
348 if (irq) 362 if (irq)
@@ -352,7 +366,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
352 * If the request_irq() fails and we return an error. The tty layer 366 * If the request_irq() fails and we return an error. The tty layer
353 * will call hvc_close() after a failed open but we don't want to clean 367 * will call hvc_close() after a failed open but we don't want to clean
354 * up there so we'll clean up here and clear out the previously set 368 * up there so we'll clean up here and clear out the previously set
355 * tty fields and return the kobject reference. 369 * tty fields and return the kref reference.
356 */ 370 */
357 if (rc) { 371 if (rc) {
358 spin_lock_irqsave(&hp->lock, flags); 372 spin_lock_irqsave(&hp->lock, flags);
@@ -360,7 +374,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
360 hp->irq_requested = 0; 374 hp->irq_requested = 0;
361 spin_unlock_irqrestore(&hp->lock, flags); 375 spin_unlock_irqrestore(&hp->lock, flags);
362 tty->driver_data = NULL; 376 tty->driver_data = NULL;
363 kobject_put(kobjp); 377 kref_put(&hp->kref, destroy_hvc_struct);
364 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); 378 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
365 } 379 }
366 /* Force wakeup of the polling thread */ 380 /* Force wakeup of the polling thread */
@@ -372,7 +386,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
372static void hvc_close(struct tty_struct *tty, struct file * filp) 386static void hvc_close(struct tty_struct *tty, struct file * filp)
373{ 387{
374 struct hvc_struct *hp; 388 struct hvc_struct *hp;
375 struct kobject *kobjp;
376 int irq = 0; 389 int irq = 0;
377 unsigned long flags; 390 unsigned long flags;
378 391
@@ -382,7 +395,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
382 /* 395 /*
383 * No driver_data means that this close was issued after a failed 396 * No driver_data means that this close was issued after a failed
384 * hvc_open by the tty layer's release_dev() function and we can just 397 * hvc_open by the tty layer's release_dev() function and we can just
385 * exit cleanly because the kobject reference wasn't made. 398 * exit cleanly because the kref reference wasn't made.
386 */ 399 */
387 if (!tty->driver_data) 400 if (!tty->driver_data)
388 return; 401 return;
@@ -390,7 +403,6 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
390 hp = tty->driver_data; 403 hp = tty->driver_data;
391 spin_lock_irqsave(&hp->lock, flags); 404 spin_lock_irqsave(&hp->lock, flags);
392 405
393 kobjp = &hp->kobj;
394 if (--hp->count == 0) { 406 if (--hp->count == 0) {
395 if (hp->irq_requested) 407 if (hp->irq_requested)
396 irq = hp->irq; 408 irq = hp->irq;
@@ -417,7 +429,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
417 spin_unlock_irqrestore(&hp->lock, flags); 429 spin_unlock_irqrestore(&hp->lock, flags);
418 } 430 }
419 431
420 kobject_put(kobjp); 432 kref_put(&hp->kref, destroy_hvc_struct);
421} 433}
422 434
423static void hvc_hangup(struct tty_struct *tty) 435static void hvc_hangup(struct tty_struct *tty)
@@ -426,7 +438,6 @@ static void hvc_hangup(struct tty_struct *tty)
426 unsigned long flags; 438 unsigned long flags;
427 int irq = 0; 439 int irq = 0;
428 int temp_open_count; 440 int temp_open_count;
429 struct kobject *kobjp;
430 441
431 if (!hp) 442 if (!hp)
432 return; 443 return;
@@ -443,7 +454,6 @@ static void hvc_hangup(struct tty_struct *tty)
443 return; 454 return;
444 } 455 }
445 456
446 kobjp = &hp->kobj;
447 temp_open_count = hp->count; 457 temp_open_count = hp->count;
448 hp->count = 0; 458 hp->count = 0;
449 hp->n_outbuf = 0; 459 hp->n_outbuf = 0;
@@ -457,7 +467,7 @@ static void hvc_hangup(struct tty_struct *tty)
457 free_irq(irq, hp); 467 free_irq(irq, hp);
458 while(temp_open_count) { 468 while(temp_open_count) {
459 --temp_open_count; 469 --temp_open_count;
460 kobject_put(kobjp); 470 kref_put(&hp->kref, destroy_hvc_struct);
461 } 471 }
462} 472}
463 473
@@ -729,27 +739,6 @@ static const struct tty_operations hvc_ops = {
729 .chars_in_buffer = hvc_chars_in_buffer, 739 .chars_in_buffer = hvc_chars_in_buffer,
730}; 740};
731 741
732/* callback when the kboject ref count reaches zero. */
733static void destroy_hvc_struct(struct kobject *kobj)
734{
735 struct hvc_struct *hp = container_of(kobj, struct hvc_struct, kobj);
736 unsigned long flags;
737
738 spin_lock(&hvc_structs_lock);
739
740 spin_lock_irqsave(&hp->lock, flags);
741 list_del(&(hp->next));
742 spin_unlock_irqrestore(&hp->lock, flags);
743
744 spin_unlock(&hvc_structs_lock);
745
746 kfree(hp);
747}
748
749static struct kobj_type hvc_kobj_type = {
750 .release = destroy_hvc_struct,
751};
752
753struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq, 742struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
754 struct hv_ops *ops, int outbuf_size) 743 struct hv_ops *ops, int outbuf_size)
755{ 744{
@@ -776,8 +765,7 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
776 hp->outbuf_size = outbuf_size; 765 hp->outbuf_size = outbuf_size;
777 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; 766 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
778 767
779 kobject_init(&hp->kobj); 768 kref_init(&hp->kref);
780 hp->kobj.ktype = &hvc_kobj_type;
781 769
782 spin_lock_init(&hp->lock); 770 spin_lock_init(&hp->lock);
783 spin_lock(&hvc_structs_lock); 771 spin_lock(&hvc_structs_lock);
@@ -806,12 +794,10 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
806int __devexit hvc_remove(struct hvc_struct *hp) 794int __devexit hvc_remove(struct hvc_struct *hp)
807{ 795{
808 unsigned long flags; 796 unsigned long flags;
809 struct kobject *kobjp;
810 struct tty_struct *tty; 797 struct tty_struct *tty;
811 798
812 spin_lock_irqsave(&hp->lock, flags); 799 spin_lock_irqsave(&hp->lock, flags);
813 tty = hp->tty; 800 tty = hp->tty;
814 kobjp = &hp->kobj;
815 801
816 if (hp->index < MAX_NR_HVC_CONSOLES) 802 if (hp->index < MAX_NR_HVC_CONSOLES)
817 vtermnos[hp->index] = -1; 803 vtermnos[hp->index] = -1;
@@ -821,12 +807,12 @@ int __devexit hvc_remove(struct hvc_struct *hp)
821 spin_unlock_irqrestore(&hp->lock, flags); 807 spin_unlock_irqrestore(&hp->lock, flags);
822 808
823 /* 809 /*
824 * We 'put' the instance that was grabbed when the kobject instance 810 * We 'put' the instance that was grabbed when the kref instance
825 * was initialized using kobject_init(). Let the last holder of this 811 * was initialized using kref_init(). Let the last holder of this
826 * kobject cause it to be removed, which will probably be the tty_hangup 812 * kref cause it to be removed, which will probably be the tty_hangup
827 * below. 813 * below.
828 */ 814 */
829 kobject_put(kobjp); 815 kref_put(&hp->kref, destroy_hvc_struct);
830 816
831 /* 817 /*
832 * This function call will auto chain call hvc_hangup. The tty should 818 * This function call will auto chain call hvc_hangup. The tty should
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 69d8866de783..fd7559084b82 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -57,11 +57,7 @@
57 * rescanning partner information upon a user's request. 57 * rescanning partner information upon a user's request.
58 * 58 *
59 * Each vty-server, prior to being exposed to this driver is reference counted 59 * Each vty-server, prior to being exposed to this driver is reference counted
60 * using the 2.6 Linux kernel kobject construct. This kobject is also used by 60 * using the 2.6 Linux kernel kref construct.
61 * the vio bus to provide a vio device sysfs entry that this driver attaches
62 * device specific attributes to, including partner information. The vio bus
63 * framework also provides a sysfs entry for each vio driver. The hvcs driver
64 * provides driver attributes in this entry.
65 * 61 *
66 * For direction on installation and usage of this driver please reference 62 * For direction on installation and usage of this driver please reference
67 * Documentation/powerpc/hvcs.txt. 63 * Documentation/powerpc/hvcs.txt.
@@ -71,7 +67,7 @@
71#include <linux/init.h> 67#include <linux/init.h>
72#include <linux/interrupt.h> 68#include <linux/interrupt.h>
73#include <linux/kernel.h> 69#include <linux/kernel.h>
74#include <linux/kobject.h> 70#include <linux/kref.h>
75#include <linux/kthread.h> 71#include <linux/kthread.h>
76#include <linux/list.h> 72#include <linux/list.h>
77#include <linux/major.h> 73#include <linux/major.h>
@@ -293,12 +289,12 @@ struct hvcs_struct {
293 int chars_in_buffer; 289 int chars_in_buffer;
294 290
295 /* 291 /*
296 * Any variable below the kobject is valid before a tty is connected and 292 * Any variable below the kref is valid before a tty is connected and
297 * stays valid after the tty is disconnected. These shouldn't be 293 * stays valid after the tty is disconnected. These shouldn't be
298 * whacked until the koject refcount reaches zero though some entries 294 * whacked until the koject refcount reaches zero though some entries
299 * may be changed via sysfs initiatives. 295 * may be changed via sysfs initiatives.
300 */ 296 */
301 struct kobject kobj; /* ref count & hvcs_struct lifetime */ 297 struct kref kref; /* ref count & hvcs_struct lifetime */
302 int connected; /* is the vty-server currently connected to a vty? */ 298 int connected; /* is the vty-server currently connected to a vty? */
303 uint32_t p_unit_address; /* partner unit address */ 299 uint32_t p_unit_address; /* partner unit address */
304 uint32_t p_partition_ID; /* partner partition ID */ 300 uint32_t p_partition_ID; /* partner partition ID */
@@ -307,8 +303,8 @@ struct hvcs_struct {
307 struct vio_dev *vdev; 303 struct vio_dev *vdev;
308}; 304};
309 305
310/* Required to back map a kobject to its containing object */ 306/* Required to back map a kref to its containing object */
311#define from_kobj(kobj) container_of(kobj, struct hvcs_struct, kobj) 307#define from_kref(k) container_of(k, struct hvcs_struct, kref)
312 308
313static struct list_head hvcs_structs = LIST_HEAD_INIT(hvcs_structs); 309static struct list_head hvcs_structs = LIST_HEAD_INIT(hvcs_structs);
314static DEFINE_SPINLOCK(hvcs_structs_lock); 310static DEFINE_SPINLOCK(hvcs_structs_lock);
@@ -334,7 +330,6 @@ static void hvcs_partner_free(struct hvcs_struct *hvcsd);
334static int hvcs_enable_device(struct hvcs_struct *hvcsd, 330static int hvcs_enable_device(struct hvcs_struct *hvcsd,
335 uint32_t unit_address, unsigned int irq, struct vio_dev *dev); 331 uint32_t unit_address, unsigned int irq, struct vio_dev *dev);
336 332
337static void destroy_hvcs_struct(struct kobject *kobj);
338static int hvcs_open(struct tty_struct *tty, struct file *filp); 333static int hvcs_open(struct tty_struct *tty, struct file *filp);
339static void hvcs_close(struct tty_struct *tty, struct file *filp); 334static void hvcs_close(struct tty_struct *tty, struct file *filp);
340static void hvcs_hangup(struct tty_struct * tty); 335static void hvcs_hangup(struct tty_struct * tty);
@@ -703,10 +698,10 @@ static void hvcs_return_index(int index)
703 hvcs_index_list[index] = -1; 698 hvcs_index_list[index] = -1;
704} 699}
705 700
706/* callback when the kboject ref count reaches zero */ 701/* callback when the kref ref count reaches zero */
707static void destroy_hvcs_struct(struct kobject *kobj) 702static void destroy_hvcs_struct(struct kref *kref)
708{ 703{
709 struct hvcs_struct *hvcsd = from_kobj(kobj); 704 struct hvcs_struct *hvcsd = from_kref(kref);
710 struct vio_dev *vdev; 705 struct vio_dev *vdev;
711 unsigned long flags; 706 unsigned long flags;
712 707
@@ -743,10 +738,6 @@ static void destroy_hvcs_struct(struct kobject *kobj)
743 kfree(hvcsd); 738 kfree(hvcsd);
744} 739}
745 740
746static struct kobj_type hvcs_kobj_type = {
747 .release = destroy_hvcs_struct,
748};
749
750static int hvcs_get_index(void) 741static int hvcs_get_index(void)
751{ 742{
752 int i; 743 int i;
@@ -791,9 +782,7 @@ static int __devinit hvcs_probe(
791 782
792 spin_lock_init(&hvcsd->lock); 783 spin_lock_init(&hvcsd->lock);
793 /* Automatically incs the refcount the first time */ 784 /* Automatically incs the refcount the first time */
794 kobject_init(&hvcsd->kobj); 785 kref_init(&hvcsd->kref);
795 /* Set up the callback for terminating the hvcs_struct's life */
796 hvcsd->kobj.ktype = &hvcs_kobj_type;
797 786
798 hvcsd->vdev = dev; 787 hvcsd->vdev = dev;
799 dev->dev.driver_data = hvcsd; 788 dev->dev.driver_data = hvcsd;
@@ -844,7 +833,6 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
844{ 833{
845 struct hvcs_struct *hvcsd = dev->dev.driver_data; 834 struct hvcs_struct *hvcsd = dev->dev.driver_data;
846 unsigned long flags; 835 unsigned long flags;
847 struct kobject *kobjp;
848 struct tty_struct *tty; 836 struct tty_struct *tty;
849 837
850 if (!hvcsd) 838 if (!hvcsd)
@@ -856,15 +844,13 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
856 844
857 tty = hvcsd->tty; 845 tty = hvcsd->tty;
858 846
859 kobjp = &hvcsd->kobj;
860
861 spin_unlock_irqrestore(&hvcsd->lock, flags); 847 spin_unlock_irqrestore(&hvcsd->lock, flags);
862 848
863 /* 849 /*
864 * Let the last holder of this object cause it to be removed, which 850 * Let the last holder of this object cause it to be removed, which
865 * would probably be tty_hangup below. 851 * would probably be tty_hangup below.
866 */ 852 */
867 kobject_put (kobjp); 853 kref_put(&hvcsd->kref, destroy_hvcs_struct);
868 854
869 /* 855 /*
870 * The hangup is a scheduled function which will auto chain call 856 * The hangup is a scheduled function which will auto chain call
@@ -1086,7 +1072,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1086} 1072}
1087 1073
1088/* 1074/*
1089 * This always increments the kobject ref count if the call is successful. 1075 * This always increments the kref ref count if the call is successful.
1090 * Please remember to dec when you are done with the instance. 1076 * Please remember to dec when you are done with the instance.
1091 * 1077 *
1092 * NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when 1078 * NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when
@@ -1103,7 +1089,7 @@ static struct hvcs_struct *hvcs_get_by_index(int index)
1103 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1089 list_for_each_entry(hvcsd, &hvcs_structs, next) {
1104 spin_lock_irqsave(&hvcsd->lock, flags); 1090 spin_lock_irqsave(&hvcsd->lock, flags);
1105 if (hvcsd->index == index) { 1091 if (hvcsd->index == index) {
1106 kobject_get(&hvcsd->kobj); 1092 kref_get(&hvcsd->kref);
1107 spin_unlock_irqrestore(&hvcsd->lock, flags); 1093 spin_unlock_irqrestore(&hvcsd->lock, flags);
1108 spin_unlock(&hvcs_structs_lock); 1094 spin_unlock(&hvcs_structs_lock);
1109 return hvcsd; 1095 return hvcsd;
@@ -1129,14 +1115,13 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
1129 unsigned int irq; 1115 unsigned int irq;
1130 struct vio_dev *vdev; 1116 struct vio_dev *vdev;
1131 unsigned long unit_address; 1117 unsigned long unit_address;
1132 struct kobject *kobjp;
1133 1118
1134 if (tty->driver_data) 1119 if (tty->driver_data)
1135 goto fast_open; 1120 goto fast_open;
1136 1121
1137 /* 1122 /*
1138 * Is there a vty-server that shares the same index? 1123 * Is there a vty-server that shares the same index?
1139 * This function increments the kobject index. 1124 * This function increments the kref index.
1140 */ 1125 */
1141 if (!(hvcsd = hvcs_get_by_index(tty->index))) { 1126 if (!(hvcsd = hvcs_get_by_index(tty->index))) {
1142 printk(KERN_WARNING "HVCS: open failed, no device associated" 1127 printk(KERN_WARNING "HVCS: open failed, no device associated"
@@ -1181,7 +1166,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
1181 * and will grab the spinlock and free the connection if it fails. 1166 * and will grab the spinlock and free the connection if it fails.
1182 */ 1167 */
1183 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { 1168 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {
1184 kobject_put(&hvcsd->kobj); 1169 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1185 printk(KERN_WARNING "HVCS: enable device failed.\n"); 1170 printk(KERN_WARNING "HVCS: enable device failed.\n");
1186 return rc; 1171 return rc;
1187 } 1172 }
@@ -1192,17 +1177,11 @@ fast_open:
1192 hvcsd = tty->driver_data; 1177 hvcsd = tty->driver_data;
1193 1178
1194 spin_lock_irqsave(&hvcsd->lock, flags); 1179 spin_lock_irqsave(&hvcsd->lock, flags);
1195 if (!kobject_get(&hvcsd->kobj)) { 1180 kref_get(&hvcsd->kref);
1196 spin_unlock_irqrestore(&hvcsd->lock, flags);
1197 printk(KERN_ERR "HVCS: Kobject of open"
1198 " hvcs doesn't exist.\n");
1199 return -EFAULT; /* Is this the right return value? */
1200 }
1201
1202 hvcsd->open_count++; 1181 hvcsd->open_count++;
1203
1204 hvcsd->todo_mask |= HVCS_SCHED_READ; 1182 hvcsd->todo_mask |= HVCS_SCHED_READ;
1205 spin_unlock_irqrestore(&hvcsd->lock, flags); 1183 spin_unlock_irqrestore(&hvcsd->lock, flags);
1184
1206open_success: 1185open_success:
1207 hvcs_kick(); 1186 hvcs_kick();
1208 1187
@@ -1212,9 +1191,8 @@ open_success:
1212 return 0; 1191 return 0;
1213 1192
1214error_release: 1193error_release:
1215 kobjp = &hvcsd->kobj;
1216 spin_unlock_irqrestore(&hvcsd->lock, flags); 1194 spin_unlock_irqrestore(&hvcsd->lock, flags);
1217 kobject_put(&hvcsd->kobj); 1195 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1218 1196
1219 printk(KERN_WARNING "HVCS: partner connect failed.\n"); 1197 printk(KERN_WARNING "HVCS: partner connect failed.\n");
1220 return retval; 1198 return retval;
@@ -1224,7 +1202,6 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1224{ 1202{
1225 struct hvcs_struct *hvcsd; 1203 struct hvcs_struct *hvcsd;
1226 unsigned long flags; 1204 unsigned long flags;
1227 struct kobject *kobjp;
1228 int irq = NO_IRQ; 1205 int irq = NO_IRQ;
1229 1206
1230 /* 1207 /*
@@ -1245,7 +1222,6 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1245 hvcsd = tty->driver_data; 1222 hvcsd = tty->driver_data;
1246 1223
1247 spin_lock_irqsave(&hvcsd->lock, flags); 1224 spin_lock_irqsave(&hvcsd->lock, flags);
1248 kobjp = &hvcsd->kobj;
1249 if (--hvcsd->open_count == 0) { 1225 if (--hvcsd->open_count == 0) {
1250 1226
1251 vio_disable_interrupts(hvcsd->vdev); 1227 vio_disable_interrupts(hvcsd->vdev);
@@ -1270,7 +1246,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1270 tty->driver_data = NULL; 1246 tty->driver_data = NULL;
1271 1247
1272 free_irq(irq, hvcsd); 1248 free_irq(irq, hvcsd);
1273 kobject_put(kobjp); 1249 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1274 return; 1250 return;
1275 } else if (hvcsd->open_count < 0) { 1251 } else if (hvcsd->open_count < 0) {
1276 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" 1252 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
@@ -1279,7 +1255,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1279 } 1255 }
1280 1256
1281 spin_unlock_irqrestore(&hvcsd->lock, flags); 1257 spin_unlock_irqrestore(&hvcsd->lock, flags);
1282 kobject_put(kobjp); 1258 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1283} 1259}
1284 1260
1285static void hvcs_hangup(struct tty_struct * tty) 1261static void hvcs_hangup(struct tty_struct * tty)
@@ -1287,21 +1263,17 @@ static void hvcs_hangup(struct tty_struct * tty)
1287 struct hvcs_struct *hvcsd = tty->driver_data; 1263 struct hvcs_struct *hvcsd = tty->driver_data;
1288 unsigned long flags; 1264 unsigned long flags;
1289 int temp_open_count; 1265 int temp_open_count;
1290 struct kobject *kobjp;
1291 int irq = NO_IRQ; 1266 int irq = NO_IRQ;
1292 1267
1293 spin_lock_irqsave(&hvcsd->lock, flags); 1268 spin_lock_irqsave(&hvcsd->lock, flags);
1294 /* Preserve this so that we know how many kobject refs to put */ 1269 /* Preserve this so that we know how many kref refs to put */
1295 temp_open_count = hvcsd->open_count; 1270 temp_open_count = hvcsd->open_count;
1296 1271
1297 /* 1272 /*
1298 * Don't kobject put inside the spinlock because the destruction 1273 * Don't kref put inside the spinlock because the destruction
1299 * callback may use the spinlock and it may get called before the 1274 * callback may use the spinlock and it may get called before the
1300 * spinlock has been released. Get a pointer to the kobject and 1275 * spinlock has been released.
1301 * kobject_put on that after releasing the spinlock.
1302 */ 1276 */
1303 kobjp = &hvcsd->kobj;
1304
1305 vio_disable_interrupts(hvcsd->vdev); 1277 vio_disable_interrupts(hvcsd->vdev);
1306 1278
1307 hvcsd->todo_mask = 0; 1279 hvcsd->todo_mask = 0;
@@ -1324,7 +1296,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1324 free_irq(irq, hvcsd); 1296 free_irq(irq, hvcsd);
1325 1297
1326 /* 1298 /*
1327 * We need to kobject_put() for every open_count we have since the 1299 * We need to kref_put() for every open_count we have since the
1328 * tty_hangup() function doesn't invoke a close per open connection on a 1300 * tty_hangup() function doesn't invoke a close per open connection on a
1329 * non-console device. 1301 * non-console device.
1330 */ 1302 */
@@ -1335,7 +1307,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1335 * NOTE: If this hangup was signaled from user space then the 1307 * NOTE: If this hangup was signaled from user space then the
1336 * final put will never happen. 1308 * final put will never happen.
1337 */ 1309 */
1338 kobject_put(kobjp); 1310 kref_put(&hvcsd->kref, destroy_hvcs_struct);
1339 } 1311 }
1340} 1312}
1341 1313
diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
index 556fd81fa815..c422e870dc52 100644
--- a/drivers/char/hw_random/amd-rng.c
+++ b/drivers/char/hw_random/amd-rng.c
@@ -28,6 +28,7 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/hw_random.h> 30#include <linux/hw_random.h>
31#include <linux/delay.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
33 34
@@ -52,11 +53,18 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
52static struct pci_dev *amd_pdev; 53static struct pci_dev *amd_pdev;
53 54
54 55
55static int amd_rng_data_present(struct hwrng *rng) 56static int amd_rng_data_present(struct hwrng *rng, int wait)
56{ 57{
57 u32 pmbase = (u32)rng->priv; 58 u32 pmbase = (u32)rng->priv;
59 int data, i;
58 60
59 return !!(inl(pmbase + 0xF4) & 1); 61 for (i = 0; i < 20; i++) {
62 data = !!(inl(pmbase + 0xF4) & 1);
63 if (data || !wait)
64 break;
65 udelay(10);
66 }
67 return data;
60} 68}
61 69
62static int amd_rng_data_read(struct hwrng *rng, u32 *data) 70static int amd_rng_data_read(struct hwrng *rng, u32 *data)
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 26a860adcb38..0118b9817a95 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -66,11 +66,11 @@ static inline void hwrng_cleanup(struct hwrng *rng)
66 rng->cleanup(rng); 66 rng->cleanup(rng);
67} 67}
68 68
69static inline int hwrng_data_present(struct hwrng *rng) 69static inline int hwrng_data_present(struct hwrng *rng, int wait)
70{ 70{
71 if (!rng->data_present) 71 if (!rng->data_present)
72 return 1; 72 return 1;
73 return rng->data_present(rng); 73 return rng->data_present(rng, wait);
74} 74}
75 75
76static inline int hwrng_data_read(struct hwrng *rng, u32 *data) 76static inline int hwrng_data_read(struct hwrng *rng, u32 *data)
@@ -94,8 +94,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
94{ 94{
95 u32 data; 95 u32 data;
96 ssize_t ret = 0; 96 ssize_t ret = 0;
97 int i, err = 0; 97 int err = 0;
98 int data_present;
99 int bytes_read; 98 int bytes_read;
100 99
101 while (size) { 100 while (size) {
@@ -107,21 +106,10 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
107 err = -ENODEV; 106 err = -ENODEV;
108 goto out; 107 goto out;
109 } 108 }
110 if (filp->f_flags & O_NONBLOCK) { 109
111 data_present = hwrng_data_present(current_rng);
112 } else {
113 /* Some RNG require some time between data_reads to gather
114 * new entropy. Poll it.
115 */
116 for (i = 0; i < 20; i++) {
117 data_present = hwrng_data_present(current_rng);
118 if (data_present)
119 break;
120 udelay(10);
121 }
122 }
123 bytes_read = 0; 110 bytes_read = 0;
124 if (data_present) 111 if (hwrng_data_present(current_rng,
112 !(filp->f_flags & O_NONBLOCK)))
125 bytes_read = hwrng_data_read(current_rng, &data); 113 bytes_read = hwrng_data_read(current_rng, &data);
126 mutex_unlock(&rng_mutex); 114 mutex_unlock(&rng_mutex);
127 115
diff --git a/drivers/char/hw_random/geode-rng.c b/drivers/char/hw_random/geode-rng.c
index 8e8658dcd2e3..fed4ef5569f5 100644
--- a/drivers/char/hw_random/geode-rng.c
+++ b/drivers/char/hw_random/geode-rng.c
@@ -28,6 +28,7 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/hw_random.h> 30#include <linux/hw_random.h>
31#include <linux/delay.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
33 34
@@ -61,11 +62,18 @@ static int geode_rng_data_read(struct hwrng *rng, u32 *data)
61 return 4; 62 return 4;
62} 63}
63 64
64static int geode_rng_data_present(struct hwrng *rng) 65static int geode_rng_data_present(struct hwrng *rng, int wait)
65{ 66{
66 void __iomem *mem = (void __iomem *)rng->priv; 67 void __iomem *mem = (void __iomem *)rng->priv;
68 int data, i;
67 69
68 return !!(readl(mem + GEODE_RNG_STATUS_REG)); 70 for (i = 0; i < 20; i++) {
71 data = !!(readl(mem + GEODE_RNG_STATUS_REG));
72 if (data || !wait)
73 break;
74 udelay(10);
75 }
76 return data;
69} 77}
70 78
71 79
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index 753f46052b87..5cc651ef75eb 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -29,6 +29,7 @@
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/stop_machine.h> 31#include <linux/stop_machine.h>
32#include <linux/delay.h>
32#include <asm/io.h> 33#include <asm/io.h>
33 34
34 35
@@ -162,11 +163,19 @@ static inline u8 hwstatus_set(void __iomem *mem,
162 return hwstatus_get(mem); 163 return hwstatus_get(mem);
163} 164}
164 165
165static int intel_rng_data_present(struct hwrng *rng) 166static int intel_rng_data_present(struct hwrng *rng, int wait)
166{ 167{
167 void __iomem *mem = (void __iomem *)rng->priv; 168 void __iomem *mem = (void __iomem *)rng->priv;
168 169 int data, i;
169 return !!(readb(mem + INTEL_RNG_STATUS) & INTEL_RNG_DATA_PRESENT); 170
171 for (i = 0; i < 20; i++) {
172 data = !!(readb(mem + INTEL_RNG_STATUS) &
173 INTEL_RNG_DATA_PRESENT);
174 if (data || !wait)
175 break;
176 udelay(10);
177 }
178 return data;
170} 179}
171 180
172static int intel_rng_data_read(struct hwrng *rng, u32 *data) 181static int intel_rng_data_read(struct hwrng *rng, u32 *data)
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 3f35a1c562b1..7e319951fa41 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -29,6 +29,7 @@
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/hw_random.h> 31#include <linux/hw_random.h>
32#include <linux/delay.h>
32 33
33#include <asm/io.h> 34#include <asm/io.h>
34 35
@@ -65,9 +66,17 @@ static void omap_rng_write_reg(int reg, u32 val)
65} 66}
66 67
67/* REVISIT: Does the status bit really work on 16xx? */ 68/* REVISIT: Does the status bit really work on 16xx? */
68static int omap_rng_data_present(struct hwrng *rng) 69static int omap_rng_data_present(struct hwrng *rng, int wait)
69{ 70{
70 return omap_rng_read_reg(RNG_STAT_REG) ? 0 : 1; 71 int data, i;
72
73 for (i = 0; i < 20; i++) {
74 data = omap_rng_read_reg(RNG_STAT_REG) ? 0 : 1;
75 if (data || !wait)
76 break;
77 udelay(10);
78 }
79 return data;
71} 80}
72 81
73static int omap_rng_data_read(struct hwrng *rng, u32 *data) 82static int omap_rng_data_read(struct hwrng *rng, u32 *data)
diff --git a/drivers/char/hw_random/pasemi-rng.c b/drivers/char/hw_random/pasemi-rng.c
index fa6040b6c8f2..e2ea210cfa5f 100644
--- a/drivers/char/hw_random/pasemi-rng.c
+++ b/drivers/char/hw_random/pasemi-rng.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/hw_random.h> 25#include <linux/hw_random.h>
26#include <linux/delay.h>
26#include <asm/of_platform.h> 27#include <asm/of_platform.h>
27#include <asm/io.h> 28#include <asm/io.h>
28 29
@@ -41,12 +42,19 @@
41 42
42#define MODULE_NAME "pasemi_rng" 43#define MODULE_NAME "pasemi_rng"
43 44
44static int pasemi_rng_data_present(struct hwrng *rng) 45static int pasemi_rng_data_present(struct hwrng *rng, int wait)
45{ 46{
46 void __iomem *rng_regs = (void __iomem *)rng->priv; 47 void __iomem *rng_regs = (void __iomem *)rng->priv;
47 48 int data, i;
48 return (in_le32(rng_regs + SDCRNG_CTL_REG) 49
49 & SDCRNG_CTL_FVLD_M) ? 1 : 0; 50 for (i = 0; i < 20; i++) {
51 data = (in_le32(rng_regs + SDCRNG_CTL_REG)
52 & SDCRNG_CTL_FVLD_M) ? 1 : 0;
53 if (data || !wait)
54 break;
55 udelay(10);
56 }
57 return data;
50} 58}
51 59
52static int pasemi_rng_data_read(struct hwrng *rng, u32 *data) 60static int pasemi_rng_data_read(struct hwrng *rng, u32 *data)
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index ec435cb25c4f..868e39fd42e4 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -27,6 +27,7 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/hw_random.h> 29#include <linux/hw_random.h>
30#include <linux/delay.h>
30#include <asm/io.h> 31#include <asm/io.h>
31#include <asm/msr.h> 32#include <asm/msr.h>
32#include <asm/cpufeature.h> 33#include <asm/cpufeature.h>
@@ -77,10 +78,11 @@ static inline u32 xstore(u32 *addr, u32 edx_in)
77 return eax_out; 78 return eax_out;
78} 79}
79 80
80static int via_rng_data_present(struct hwrng *rng) 81static int via_rng_data_present(struct hwrng *rng, int wait)
81{ 82{
82 u32 bytes_out; 83 u32 bytes_out;
83 u32 *via_rng_datum = (u32 *)(&rng->priv); 84 u32 *via_rng_datum = (u32 *)(&rng->priv);
85 int i;
84 86
85 /* We choose the recommended 1-byte-per-instruction RNG rate, 87 /* We choose the recommended 1-byte-per-instruction RNG rate,
86 * for greater randomness at the expense of speed. Larger 88 * for greater randomness at the expense of speed. Larger
@@ -95,12 +97,15 @@ static int via_rng_data_present(struct hwrng *rng)
95 * completes. 97 * completes.
96 */ 98 */
97 99
98 *via_rng_datum = 0; /* paranoia, not really necessary */ 100 for (i = 0; i < 20; i++) {
99 bytes_out = xstore(via_rng_datum, VIA_RNG_CHUNK_1); 101 *via_rng_datum = 0; /* paranoia, not really necessary */
100 bytes_out &= VIA_XSTORE_CNT_MASK; 102 bytes_out = xstore(via_rng_datum, VIA_RNG_CHUNK_1);
101 if (bytes_out == 0) 103 bytes_out &= VIA_XSTORE_CNT_MASK;
102 return 0; 104 if (bytes_out || !wait)
103 return 1; 105 break;
106 udelay(10);
107 }
108 return bytes_out ? 1 : 0;
104} 109}
105 110
106static int via_rng_data_read(struct hwrng *rng, u32 *data) 111static int via_rng_data_read(struct hwrng *rng, u32 *data)
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
new file mode 100644
index 000000000000..6076e662886a
--- /dev/null
+++ b/drivers/char/nozomi.c
@@ -0,0 +1,1993 @@
1/*
2 * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
3 *
4 * Written by: Ulf Jakobsson,
5 * Jan �erfeldt,
6 * Stefan Thomasson,
7 *
8 * Maintained by: Paul Hardwick (p.hardwick@option.com)
9 *
10 * Patches:
11 * Locking code changes for Vodafone by Sphere Systems Ltd,
12 * Andrew Bird (ajb@spheresystems.co.uk )
13 * & Phil Sanderson
14 *
15 * Source has been ported from an implementation made by Filip Aben @ Option
16 *
17 * --------------------------------------------------------------------------
18 *
19 * Copyright (c) 2005,2006 Option Wireless Sweden AB
20 * Copyright (c) 2006 Sphere Systems Ltd
21 * Copyright (c) 2006 Option Wireless n/v
22 * All rights Reserved.
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
37 *
38 * --------------------------------------------------------------------------
39 */
40
41/*
42 * CHANGELOG
43 * Version 2.1d
44 * 11-November-2007 Jiri Slaby, Frank Seidel
45 * - Big rework of multicard support by Jiri
46 * - Major cleanups (semaphore to mutex, endianess, no major reservation)
47 * - Optimizations
48 *
49 * Version 2.1c
50 * 30-October-2007 Frank Seidel
51 * - Completed multicard support
52 * - Minor cleanups
53 *
54 * Version 2.1b
55 * 07-August-2007 Frank Seidel
56 * - Minor cleanups
57 * - theoretical multicard support
58 *
59 * Version 2.1
60 * 03-July-2006 Paul Hardwick
61 *
62 * - Stability Improvements. Incorporated spinlock wraps patch.
63 * - Updated for newer 2.6.14+ kernels (tty_buffer_request_room)
64 * - using __devexit macro for tty
65 *
66 *
67 * Version 2.0
68 * 08-feb-2006 15:34:10:Ulf
69 *
70 * -Fixed issue when not waking up line disipine layer, could probably result
71 * in better uplink performance for 2.4.
72 *
73 * -Fixed issue with big endian during initalization, now proper toggle flags
74 * are handled between preloader and maincode.
75 *
76 * -Fixed flow control issue.
77 *
78 * -Added support for setting DTR.
79 *
80 * -For 2.4 kernels, removing temporary buffer that's not needed.
81 *
82 * -Reading CTS only for modem port (only port that supports it).
83 *
84 * -Return 0 in write_room instead of netative value, it's not handled in
85 * upper layer.
86 *
87 * --------------------------------------------------------------------------
88 * Version 1.0
89 *
90 * First version of driver, only tested with card of type F32_2.
91 * Works fine with 2.4 and 2.6 kernels.
92 * Driver also support big endian architecture.
93 */
94
95/* Enable this to have a lot of debug printouts */
96#define DEBUG
97
98#include <linux/kernel.h>
99#include <linux/module.h>
100#include <linux/pci.h>
101#include <linux/ioport.h>
102#include <linux/tty.h>
103#include <linux/tty_driver.h>
104#include <linux/tty_flip.h>
105#include <linux/serial.h>
106#include <linux/interrupt.h>
107#include <linux/kmod.h>
108#include <linux/init.h>
109#include <linux/kfifo.h>
110#include <linux/uaccess.h>
111#include <asm/byteorder.h>
112
113#include <linux/delay.h>
114
115
116#define VERSION_STRING DRIVER_DESC " 2.1d (build date: " \
117 __DATE__ " " __TIME__ ")"
118
119/* Macros definitions */
120
121/* Default debug printout level */
122#define NOZOMI_DEBUG_LEVEL 0x00
123
124#define P_BUF_SIZE 128
125#define NFO(_err_flag_, args...) \
126do { \
127 char tmp[P_BUF_SIZE]; \
128 snprintf(tmp, sizeof(tmp), ##args); \
129 printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \
130 __FUNCTION__, tmp); \
131} while (0)
132
133#define DBG1(args...) D_(0x01, ##args)
134#define DBG2(args...) D_(0x02, ##args)
135#define DBG3(args...) D_(0x04, ##args)
136#define DBG4(args...) D_(0x08, ##args)
137#define DBG5(args...) D_(0x10, ##args)
138#define DBG6(args...) D_(0x20, ##args)
139#define DBG7(args...) D_(0x40, ##args)
140#define DBG8(args...) D_(0x80, ##args)
141
142#ifdef DEBUG
143/* Do we need this settable at runtime? */
144static int debug = NOZOMI_DEBUG_LEVEL;
145
146#define D(lvl, args...) do {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
147 while (0)
148#define D_(lvl, args...) D(lvl, ##args)
149
150/* These printouts are always printed */
151
152#else
153static int debug;
154#define D_(lvl, args...)
155#endif
156
157/* TODO: rewrite to optimize macros... */
158
159#define TMP_BUF_MAX 256
160
161#define DUMP(buf__,len__) \
162 do { \
163 char tbuf[TMP_BUF_MAX] = {0};\
164 if (len__ > 1) {\
165 snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\
166 if (tbuf[len__-2] == '\r') {\
167 tbuf[len__-2] = 'r';\
168 } \
169 DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\
170 } else {\
171 DBG1("SENDING: '%s' (%d)", tbuf, len__);\
172 } \
173} while (0)
174
175/* Defines */
176#define NOZOMI_NAME "nozomi"
177#define NOZOMI_NAME_TTY "nozomi_tty"
178#define DRIVER_DESC "Nozomi driver"
179
180#define NTTY_TTY_MAXMINORS 256
181#define NTTY_FIFO_BUFFER_SIZE 8192
182
183/* Must be power of 2 */
184#define FIFO_BUFFER_SIZE_UL 8192
185
186/* Size of tmp send buffer to card */
187#define SEND_BUF_MAX 1024
188#define RECEIVE_BUF_MAX 4
189
190
191/* Define all types of vendors and devices to support */
192#define VENDOR1 0x1931 /* Vendor Option */
193#define DEVICE1 0x000c /* HSDPA card */
194
195#define R_IIR 0x0000 /* Interrupt Identity Register */
196#define R_FCR 0x0000 /* Flow Control Register */
197#define R_IER 0x0004 /* Interrupt Enable Register */
198
199#define CONFIG_MAGIC 0xEFEFFEFE
200#define TOGGLE_VALID 0x0000
201
202/* Definition of interrupt tokens */
203#define MDM_DL1 0x0001
204#define MDM_UL1 0x0002
205#define MDM_DL2 0x0004
206#define MDM_UL2 0x0008
207#define DIAG_DL1 0x0010
208#define DIAG_DL2 0x0020
209#define DIAG_UL 0x0040
210#define APP1_DL 0x0080
211#define APP1_UL 0x0100
212#define APP2_DL 0x0200
213#define APP2_UL 0x0400
214#define CTRL_DL 0x0800
215#define CTRL_UL 0x1000
216#define RESET 0x8000
217
218#define MDM_DL (MDM_DL1 | MDM_DL2)
219#define MDM_UL (MDM_UL1 | MDM_UL2)
220#define DIAG_DL (DIAG_DL1 | DIAG_DL2)
221
222/* modem signal definition */
223#define CTRL_DSR 0x0001
224#define CTRL_DCD 0x0002
225#define CTRL_RI 0x0004
226#define CTRL_CTS 0x0008
227
228#define CTRL_DTR 0x0001
229#define CTRL_RTS 0x0002
230
231#define MAX_PORT 4
232#define NOZOMI_MAX_PORTS 5
233#define NOZOMI_MAX_CARDS (NTTY_TTY_MAXMINORS / MAX_PORT)
234
235/* Type definitions */
236
237/*
238 * There are two types of nozomi cards,
239 * one with 2048 memory and with 8192 memory
240 */
241enum card_type {
242 F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
243 F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
244};
245
246/* Two different toggle channels exist */
247enum channel_type {
248 CH_A = 0,
249 CH_B = 1,
250};
251
252/* Port definition for the card regarding flow control */
253enum ctrl_port_type {
254 CTRL_CMD = 0,
255 CTRL_MDM = 1,
256 CTRL_DIAG = 2,
257 CTRL_APP1 = 3,
258 CTRL_APP2 = 4,
259 CTRL_ERROR = -1,
260};
261
262/* Ports that the nozomi has */
263enum port_type {
264 PORT_MDM = 0,
265 PORT_DIAG = 1,
266 PORT_APP1 = 2,
267 PORT_APP2 = 3,
268 PORT_CTRL = 4,
269 PORT_ERROR = -1,
270};
271
272#ifdef __BIG_ENDIAN
273/* Big endian */
274
275struct toggles {
276 unsigned enabled:5; /*
277 * Toggle fields are valid if enabled is 0,
278 * else A-channels must always be used.
279 */
280 unsigned diag_dl:1;
281 unsigned mdm_dl:1;
282 unsigned mdm_ul:1;
283} __attribute__ ((packed));
284
285/* Configuration table to read at startup of card */
286/* Is for now only needed during initialization phase */
287struct config_table {
288 u32 signature;
289 u16 product_information;
290 u16 version;
291 u8 pad3[3];
292 struct toggles toggle;
293 u8 pad1[4];
294 u16 dl_mdm_len1; /*
295 * If this is 64, it can hold
296 * 60 bytes + 4 that is length field
297 */
298 u16 dl_start;
299
300 u16 dl_diag_len1;
301 u16 dl_mdm_len2; /*
302 * If this is 64, it can hold
303 * 60 bytes + 4 that is length field
304 */
305 u16 dl_app1_len;
306
307 u16 dl_diag_len2;
308 u16 dl_ctrl_len;
309 u16 dl_app2_len;
310 u8 pad2[16];
311 u16 ul_mdm_len1;
312 u16 ul_start;
313 u16 ul_diag_len;
314 u16 ul_mdm_len2;
315 u16 ul_app1_len;
316 u16 ul_app2_len;
317 u16 ul_ctrl_len;
318} __attribute__ ((packed));
319
320/* This stores all control downlink flags */
321struct ctrl_dl {
322 u8 port;
323 unsigned reserved:4;
324 unsigned CTS:1;
325 unsigned RI:1;
326 unsigned DCD:1;
327 unsigned DSR:1;
328} __attribute__ ((packed));
329
330/* This stores all control uplink flags */
331struct ctrl_ul {
332 u8 port;
333 unsigned reserved:6;
334 unsigned RTS:1;
335 unsigned DTR:1;
336} __attribute__ ((packed));
337
338#else
339/* Little endian */
340
341/* This represents the toggle information */
342struct toggles {
343 unsigned mdm_ul:1;
344 unsigned mdm_dl:1;
345 unsigned diag_dl:1;
346 unsigned enabled:5; /*
347 * Toggle fields are valid if enabled is 0,
348 * else A-channels must always be used.
349 */
350} __attribute__ ((packed));
351
352/* Configuration table to read at startup of card */
353struct config_table {
354 u32 signature;
355 u16 version;
356 u16 product_information;
357 struct toggles toggle;
358 u8 pad1[7];
359 u16 dl_start;
360 u16 dl_mdm_len1; /*
361 * If this is 64, it can hold
362 * 60 bytes + 4 that is length field
363 */
364 u16 dl_mdm_len2;
365 u16 dl_diag_len1;
366 u16 dl_diag_len2;
367 u16 dl_app1_len;
368 u16 dl_app2_len;
369 u16 dl_ctrl_len;
370 u8 pad2[16];
371 u16 ul_start;
372 u16 ul_mdm_len2;
373 u16 ul_mdm_len1;
374 u16 ul_diag_len;
375 u16 ul_app1_len;
376 u16 ul_app2_len;
377 u16 ul_ctrl_len;
378} __attribute__ ((packed));
379
380/* This stores all control downlink flags */
381struct ctrl_dl {
382 unsigned DSR:1;
383 unsigned DCD:1;
384 unsigned RI:1;
385 unsigned CTS:1;
386 unsigned reserverd:4;
387 u8 port;
388} __attribute__ ((packed));
389
390/* This stores all control uplink flags */
391struct ctrl_ul {
392 unsigned DTR:1;
393 unsigned RTS:1;
394 unsigned reserved:6;
395 u8 port;
396} __attribute__ ((packed));
397#endif
398
399/* This holds all information that is needed regarding a port */
400struct port {
401 u8 update_flow_control;
402 struct ctrl_ul ctrl_ul;
403 struct ctrl_dl ctrl_dl;
404 struct kfifo *fifo_ul;
405 void __iomem *dl_addr[2];
406 u32 dl_size[2];
407 u8 toggle_dl;
408 void __iomem *ul_addr[2];
409 u32 ul_size[2];
410 u8 toggle_ul;
411 u16 token_dl;
412
413 struct tty_struct *tty;
414 int tty_open_count;
415 /* mutex to ensure one access patch to this port */
416 struct mutex tty_sem;
417 wait_queue_head_t tty_wait;
418 struct async_icount tty_icount;
419};
420
421/* Private data one for each card in the system */
422struct nozomi {
423 void __iomem *base_addr;
424 unsigned long flip;
425
426 /* Pointers to registers */
427 void __iomem *reg_iir;
428 void __iomem *reg_fcr;
429 void __iomem *reg_ier;
430
431 u16 last_ier;
432 enum card_type card_type;
433 struct config_table config_table; /* Configuration table */
434 struct pci_dev *pdev;
435 struct port port[NOZOMI_MAX_PORTS];
436 u8 *send_buf;
437
438 spinlock_t spin_mutex; /* secures access to registers and tty */
439
440 unsigned int index_start;
441 u32 open_ttys;
442};
443
444/* This is a data packet that is read or written to/from card */
445struct buffer {
446 u32 size; /* size is the length of the data buffer */
447 u8 *data;
448} __attribute__ ((packed));
449
450/* Global variables */
451static struct pci_device_id nozomi_pci_tbl[] = {
452 {PCI_DEVICE(VENDOR1, DEVICE1)},
453 {},
454};
455
456MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
457
458static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
459static struct tty_driver *ntty_driver;
460
461/*
462 * find card by tty_index
463 */
464static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
465{
466 return tty ? ndevs[tty->index / MAX_PORT] : NULL;
467}
468
469static inline struct port *get_port_by_tty(const struct tty_struct *tty)
470{
471 struct nozomi *ndev = get_dc_by_tty(tty);
472 return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL;
473}
474
475/*
476 * TODO:
477 * -Optimize
478 * -Rewrite cleaner
479 */
480
481static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
482 u32 size_bytes)
483{
484 u32 i = 0;
485 const u32 *ptr = (__force u32 *) mem_addr_start;
486 u16 *buf16;
487
488 if (unlikely(!ptr || !buf))
489 goto out;
490
491 /* shortcut for extremely often used cases */
492 switch (size_bytes) {
493 case 2: /* 2 bytes */
494 buf16 = (u16 *) buf;
495 *buf16 = __le16_to_cpu(readw((void __iomem *)ptr));
496 goto out;
497 break;
498 case 4: /* 4 bytes */
499 *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
500 goto out;
501 break;
502 }
503
504 while (i < size_bytes) {
505 if (size_bytes - i == 2) {
506 /* Handle 2 bytes in the end */
507 buf16 = (u16 *) buf;
508 *(buf16) = __le16_to_cpu(readw((void __iomem *)ptr));
509 i += 2;
510 } else {
511 /* Read 4 bytes */
512 *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
513 i += 4;
514 }
515 buf++;
516 ptr++;
517 }
518out:
519 return;
520}
521
522/*
523 * TODO:
524 * -Optimize
525 * -Rewrite cleaner
526 */
527static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
528 u32 size_bytes)
529{
530 u32 i = 0;
531 u32 *ptr = (__force u32 *) mem_addr_start;
532 u16 *buf16;
533
534 if (unlikely(!ptr || !buf))
535 return 0;
536
537 /* shortcut for extremely often used cases */
538 switch (size_bytes) {
539 case 2: /* 2 bytes */
540 buf16 = (u16 *) buf;
541 writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
542 return 2;
543 break;
544 case 1: /*
545 * also needs to write 4 bytes in this case
546 * so falling through..
547 */
548 case 4: /* 4 bytes */
549 writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
550 return 4;
551 break;
552 }
553
554 while (i < size_bytes) {
555 if (size_bytes - i == 2) {
556 /* 2 bytes */
557 buf16 = (u16 *) buf;
558 writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
559 i += 2;
560 } else {
561 /* 4 bytes */
562 writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
563 i += 4;
564 }
565 buf++;
566 ptr++;
567 }
568 return i;
569}
570
571/* Setup pointers to different channels and also setup buffer sizes. */
572static void setup_memory(struct nozomi *dc)
573{
574 void __iomem *offset = dc->base_addr + dc->config_table.dl_start;
575 /* The length reported is including the length field of 4 bytes,
576 * hence subtract with 4.
577 */
578 const u16 buff_offset = 4;
579
580 /* Modem port dl configuration */
581 dc->port[PORT_MDM].dl_addr[CH_A] = offset;
582 dc->port[PORT_MDM].dl_addr[CH_B] =
583 (offset += dc->config_table.dl_mdm_len1);
584 dc->port[PORT_MDM].dl_size[CH_A] =
585 dc->config_table.dl_mdm_len1 - buff_offset;
586 dc->port[PORT_MDM].dl_size[CH_B] =
587 dc->config_table.dl_mdm_len2 - buff_offset;
588
589 /* Diag port dl configuration */
590 dc->port[PORT_DIAG].dl_addr[CH_A] =
591 (offset += dc->config_table.dl_mdm_len2);
592 dc->port[PORT_DIAG].dl_size[CH_A] =
593 dc->config_table.dl_diag_len1 - buff_offset;
594 dc->port[PORT_DIAG].dl_addr[CH_B] =
595 (offset += dc->config_table.dl_diag_len1);
596 dc->port[PORT_DIAG].dl_size[CH_B] =
597 dc->config_table.dl_diag_len2 - buff_offset;
598
599 /* App1 port dl configuration */
600 dc->port[PORT_APP1].dl_addr[CH_A] =
601 (offset += dc->config_table.dl_diag_len2);
602 dc->port[PORT_APP1].dl_size[CH_A] =
603 dc->config_table.dl_app1_len - buff_offset;
604
605 /* App2 port dl configuration */
606 dc->port[PORT_APP2].dl_addr[CH_A] =
607 (offset += dc->config_table.dl_app1_len);
608 dc->port[PORT_APP2].dl_size[CH_A] =
609 dc->config_table.dl_app2_len - buff_offset;
610
611 /* Ctrl dl configuration */
612 dc->port[PORT_CTRL].dl_addr[CH_A] =
613 (offset += dc->config_table.dl_app2_len);
614 dc->port[PORT_CTRL].dl_size[CH_A] =
615 dc->config_table.dl_ctrl_len - buff_offset;
616
617 offset = dc->base_addr + dc->config_table.ul_start;
618
619 /* Modem Port ul configuration */
620 dc->port[PORT_MDM].ul_addr[CH_A] = offset;
621 dc->port[PORT_MDM].ul_size[CH_A] =
622 dc->config_table.ul_mdm_len1 - buff_offset;
623 dc->port[PORT_MDM].ul_addr[CH_B] =
624 (offset += dc->config_table.ul_mdm_len1);
625 dc->port[PORT_MDM].ul_size[CH_B] =
626 dc->config_table.ul_mdm_len2 - buff_offset;
627
628 /* Diag port ul configuration */
629 dc->port[PORT_DIAG].ul_addr[CH_A] =
630 (offset += dc->config_table.ul_mdm_len2);
631 dc->port[PORT_DIAG].ul_size[CH_A] =
632 dc->config_table.ul_diag_len - buff_offset;
633
634 /* App1 port ul configuration */
635 dc->port[PORT_APP1].ul_addr[CH_A] =
636 (offset += dc->config_table.ul_diag_len);
637 dc->port[PORT_APP1].ul_size[CH_A] =
638 dc->config_table.ul_app1_len - buff_offset;
639
640 /* App2 port ul configuration */
641 dc->port[PORT_APP2].ul_addr[CH_A] =
642 (offset += dc->config_table.ul_app1_len);
643 dc->port[PORT_APP2].ul_size[CH_A] =
644 dc->config_table.ul_app2_len - buff_offset;
645
646 /* Ctrl ul configuration */
647 dc->port[PORT_CTRL].ul_addr[CH_A] =
648 (offset += dc->config_table.ul_app2_len);
649 dc->port[PORT_CTRL].ul_size[CH_A] =
650 dc->config_table.ul_ctrl_len - buff_offset;
651}
652
653/* Dump config table under initalization phase */
654#ifdef DEBUG
655static void dump_table(const struct nozomi *dc)
656{
657 DBG3("signature: 0x%08X", dc->config_table.signature);
658 DBG3("version: 0x%04X", dc->config_table.version);
659 DBG3("product_information: 0x%04X", \
660 dc->config_table.product_information);
661 DBG3("toggle enabled: %d", dc->config_table.toggle.enabled);
662 DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul);
663 DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl);
664 DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl);
665
666 DBG3("dl_start: 0x%04X", dc->config_table.dl_start);
667 DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1,
668 dc->config_table.dl_mdm_len1);
669 DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2,
670 dc->config_table.dl_mdm_len2);
671 DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1,
672 dc->config_table.dl_diag_len1);
673 DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2,
674 dc->config_table.dl_diag_len2);
675 DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len,
676 dc->config_table.dl_app1_len);
677 DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len,
678 dc->config_table.dl_app2_len);
679 DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len,
680 dc->config_table.dl_ctrl_len);
681 DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start,
682 dc->config_table.ul_start);
683 DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1,
684 dc->config_table.ul_mdm_len1);
685 DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2,
686 dc->config_table.ul_mdm_len2);
687 DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len,
688 dc->config_table.ul_diag_len);
689 DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len,
690 dc->config_table.ul_app1_len);
691 DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len,
692 dc->config_table.ul_app2_len);
693 DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len,
694 dc->config_table.ul_ctrl_len);
695}
696#else
697static __inline__ void dump_table(const struct nozomi *dc) { }
698#endif
699
700/*
701 * Read configuration table from card under intalization phase
702 * Returns 1 if ok, else 0
703 */
704static int nozomi_read_config_table(struct nozomi *dc)
705{
706 read_mem32((u32 *) &dc->config_table, dc->base_addr + 0,
707 sizeof(struct config_table));
708
709 if (dc->config_table.signature != CONFIG_MAGIC) {
710 dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n",
711 dc->config_table.signature, CONFIG_MAGIC);
712 return 0;
713 }
714
715 if ((dc->config_table.version == 0)
716 || (dc->config_table.toggle.enabled == TOGGLE_VALID)) {
717 int i;
718 DBG1("Second phase, configuring card");
719
720 setup_memory(dc);
721
722 dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul;
723 dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl;
724 dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl;
725 DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
726 dc->port[PORT_MDM].toggle_ul,
727 dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl);
728
729 dump_table(dc);
730
731 for (i = PORT_MDM; i < MAX_PORT; i++) {
732 dc->port[i].fifo_ul =
733 kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
734 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
735 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
736 }
737
738 /* Enable control channel */
739 dc->last_ier = dc->last_ier | CTRL_DL;
740 writew(dc->last_ier, dc->reg_ier);
741
742 dev_info(&dc->pdev->dev, "Initialization OK!\n");
743 return 1;
744 }
745
746 if ((dc->config_table.version > 0)
747 && (dc->config_table.toggle.enabled != TOGGLE_VALID)) {
748 u32 offset = 0;
749 DBG1("First phase: pushing upload buffers, clearing download");
750
751 dev_info(&dc->pdev->dev, "Version of card: %d\n",
752 dc->config_table.version);
753
754 /* Here we should disable all I/O over F32. */
755 setup_memory(dc);
756
757 /*
758 * We should send ALL channel pair tokens back along
759 * with reset token
760 */
761
762 /* push upload modem buffers */
763 write_mem32(dc->port[PORT_MDM].ul_addr[CH_A],
764 (u32 *) &offset, 4);
765 write_mem32(dc->port[PORT_MDM].ul_addr[CH_B],
766 (u32 *) &offset, 4);
767
768 writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr);
769
770 DBG1("First phase done");
771 }
772
773 return 1;
774}
775
776/* Enable uplink interrupts */
777static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
778{
779 u16 mask[NOZOMI_MAX_PORTS] = \
780 {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
781
782 if (port < NOZOMI_MAX_PORTS) {
783 dc->last_ier |= mask[port];
784 writew(dc->last_ier, dc->reg_ier);
785 } else {
786 dev_err(&dc->pdev->dev, "Called with wrong port?\n");
787 }
788}
789
790/* Disable uplink interrupts */
791static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
792{
793 u16 mask[NOZOMI_MAX_PORTS] = \
794 {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
795
796 if (port < NOZOMI_MAX_PORTS) {
797 dc->last_ier &= mask[port];
798 writew(dc->last_ier, dc->reg_ier);
799 } else {
800 dev_err(&dc->pdev->dev, "Called with wrong port?\n");
801 }
802}
803
804/* Enable downlink interrupts */
805static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
806{
807 u16 mask[NOZOMI_MAX_PORTS] = \
808 {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
809
810 if (port < NOZOMI_MAX_PORTS) {
811 dc->last_ier |= mask[port];
812 writew(dc->last_ier, dc->reg_ier);
813 } else {
814 dev_err(&dc->pdev->dev, "Called with wrong port?\n");
815 }
816}
817
818/* Disable downlink interrupts */
819static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
820{
821 u16 mask[NOZOMI_MAX_PORTS] = \
822 {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
823
824 if (port < NOZOMI_MAX_PORTS) {
825 dc->last_ier &= mask[port];
826 writew(dc->last_ier, dc->reg_ier);
827 } else {
828 dev_err(&dc->pdev->dev, "Called with wrong port?\n");
829 }
830}
831
832/*
833 * Return 1 - send buffer to card and ack.
834 * Return 0 - don't ack, don't send buffer to card.
835 */
836static int send_data(enum port_type index, struct nozomi *dc)
837{
838 u32 size = 0;
839 struct port *port = &dc->port[index];
840 u8 toggle = port->toggle_ul;
841 void __iomem *addr = port->ul_addr[toggle];
842 u32 ul_size = port->ul_size[toggle];
843 struct tty_struct *tty = port->tty;
844
845 /* Get data from tty and place in buf for now */
846 size = __kfifo_get(port->fifo_ul, dc->send_buf,
847 ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
848
849 if (size == 0) {
850 DBG4("No more data to send, disable link:");
851 return 0;
852 }
853
854 /* DUMP(buf, size); */
855
856 /* Write length + data */
857 write_mem32(addr, (u32 *) &size, 4);
858 write_mem32(addr + 4, (u32 *) dc->send_buf, size);
859
860 if (tty)
861 tty_wakeup(tty);
862
863 return 1;
864}
865
866/* If all data has been read, return 1, else 0 */
867static int receive_data(enum port_type index, struct nozomi *dc)
868{
869 u8 buf[RECEIVE_BUF_MAX] = { 0 };
870 int size;
871 u32 offset = 4;
872 struct port *port = &dc->port[index];
873 void __iomem *addr = port->dl_addr[port->toggle_dl];
874 struct tty_struct *tty = port->tty;
875 int i;
876
877 if (unlikely(!tty)) {
878 DBG1("tty not open for port: %d?", index);
879 return 1;
880 }
881
882 read_mem32((u32 *) &size, addr, 4);
883 /* DBG1( "%d bytes port: %d", size, index); */
884
885 if (test_bit(TTY_THROTTLED, &tty->flags)) {
886 DBG1("No room in tty, don't read data, don't ack interrupt, "
887 "disable interrupt");
888
889 /* disable interrupt in downlink... */
890 disable_transmit_dl(index, dc);
891 return 0;
892 }
893
894 if (unlikely(size == 0)) {
895 dev_err(&dc->pdev->dev, "size == 0?\n");
896 return 1;
897 }
898
899 tty_buffer_request_room(tty, size);
900
901 while (size > 0) {
902 read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
903
904 if (size == 1) {
905 tty_insert_flip_char(tty, buf[0], TTY_NORMAL);
906 size = 0;
907 } else if (size < RECEIVE_BUF_MAX) {
908 size -= tty_insert_flip_string(tty, (char *) buf, size);
909 } else {
910 i = tty_insert_flip_string(tty, \
911 (char *) buf, RECEIVE_BUF_MAX);
912 size -= i;
913 offset += i;
914 }
915 }
916
917 set_bit(index, &dc->flip);
918
919 return 1;
920}
921
922/* Debug for interrupts */
923#ifdef DEBUG
924static char *interrupt2str(u16 interrupt)
925{
926 static char buf[TMP_BUF_MAX];
927 char *p = buf;
928
929 interrupt & MDM_DL1 ? p += snprintf(p, TMP_BUF_MAX, "MDM_DL1 ") : NULL;
930 interrupt & MDM_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
931 "MDM_DL2 ") : NULL;
932
933 interrupt & MDM_UL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
934 "MDM_UL1 ") : NULL;
935 interrupt & MDM_UL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
936 "MDM_UL2 ") : NULL;
937
938 interrupt & DIAG_DL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
939 "DIAG_DL1 ") : NULL;
940 interrupt & DIAG_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
941 "DIAG_DL2 ") : NULL;
942
943 interrupt & DIAG_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
944 "DIAG_UL ") : NULL;
945
946 interrupt & APP1_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
947 "APP1_DL ") : NULL;
948 interrupt & APP2_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
949 "APP2_DL ") : NULL;
950
951 interrupt & APP1_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
952 "APP1_UL ") : NULL;
953 interrupt & APP2_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
954 "APP2_UL ") : NULL;
955
956 interrupt & CTRL_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
957 "CTRL_DL ") : NULL;
958 interrupt & CTRL_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
959 "CTRL_UL ") : NULL;
960
961 interrupt & RESET ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
962 "RESET ") : NULL;
963
964 return buf;
965}
966#endif
967
968/*
969 * Receive flow control
970 * Return 1 - If ok, else 0
971 */
972static int receive_flow_control(struct nozomi *dc)
973{
974 enum port_type port = PORT_MDM;
975 struct ctrl_dl ctrl_dl;
976 struct ctrl_dl old_ctrl;
977 u16 enable_ier = 0;
978
979 read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2);
980
981 switch (ctrl_dl.port) {
982 case CTRL_CMD:
983 DBG1("The Base Band sends this value as a response to a "
984 "request for IMSI detach sent over the control "
985 "channel uplink (see section 7.6.1).");
986 break;
987 case CTRL_MDM:
988 port = PORT_MDM;
989 enable_ier = MDM_DL;
990 break;
991 case CTRL_DIAG:
992 port = PORT_DIAG;
993 enable_ier = DIAG_DL;
994 break;
995 case CTRL_APP1:
996 port = PORT_APP1;
997 enable_ier = APP1_DL;
998 break;
999 case CTRL_APP2:
1000 port = PORT_APP2;
1001 enable_ier = APP2_DL;
1002 break;
1003 default:
1004 dev_err(&dc->pdev->dev,
1005 "ERROR: flow control received for non-existing port\n");
1006 return 0;
1007 };
1008
1009 DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl),
1010 *((u16 *)&ctrl_dl));
1011
1012 old_ctrl = dc->port[port].ctrl_dl;
1013 dc->port[port].ctrl_dl = ctrl_dl;
1014
1015 if (old_ctrl.CTS == 1 && ctrl_dl.CTS == 0) {
1016 DBG1("Disable interrupt (0x%04X) on port: %d",
1017 enable_ier, port);
1018 disable_transmit_ul(port, dc);
1019
1020 } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
1021
1022 if (__kfifo_len(dc->port[port].fifo_ul)) {
1023 DBG1("Enable interrupt (0x%04X) on port: %d",
1024 enable_ier, port);
1025 DBG1("Data in buffer [%d], enable transmit! ",
1026 __kfifo_len(dc->port[port].fifo_ul));
1027 enable_transmit_ul(port, dc);
1028 } else {
1029 DBG1("No data in buffer...");
1030 }
1031 }
1032
1033 if (*(u16 *)&old_ctrl == *(u16 *)&ctrl_dl) {
1034 DBG1(" No change in mctrl");
1035 return 1;
1036 }
1037 /* Update statistics */
1038 if (old_ctrl.CTS != ctrl_dl.CTS)
1039 dc->port[port].tty_icount.cts++;
1040 if (old_ctrl.DSR != ctrl_dl.DSR)
1041 dc->port[port].tty_icount.dsr++;
1042 if (old_ctrl.RI != ctrl_dl.RI)
1043 dc->port[port].tty_icount.rng++;
1044 if (old_ctrl.DCD != ctrl_dl.DCD)
1045 dc->port[port].tty_icount.dcd++;
1046
1047 wake_up_interruptible(&dc->port[port].tty_wait);
1048
1049 DBG1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
1050 port,
1051 dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts,
1052 dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr);
1053
1054 return 1;
1055}
1056
1057static enum ctrl_port_type port2ctrl(enum port_type port,
1058 const struct nozomi *dc)
1059{
1060 switch (port) {
1061 case PORT_MDM:
1062 return CTRL_MDM;
1063 case PORT_DIAG:
1064 return CTRL_DIAG;
1065 case PORT_APP1:
1066 return CTRL_APP1;
1067 case PORT_APP2:
1068 return CTRL_APP2;
1069 default:
1070 dev_err(&dc->pdev->dev,
1071 "ERROR: send flow control " \
1072 "received for non-existing port\n");
1073 };
1074 return CTRL_ERROR;
1075}
1076
1077/*
1078 * Send flow control, can only update one channel at a time
1079 * Return 0 - If we have updated all flow control
1080 * Return 1 - If we need to update more flow control, ack current enable more
1081 */
1082static int send_flow_control(struct nozomi *dc)
1083{
1084 u32 i, more_flow_control_to_be_updated = 0;
1085 u16 *ctrl;
1086
1087 for (i = PORT_MDM; i < MAX_PORT; i++) {
1088 if (dc->port[i].update_flow_control) {
1089 if (more_flow_control_to_be_updated) {
1090 /* We have more flow control to be updated */
1091 return 1;
1092 }
1093 dc->port[i].ctrl_ul.port = port2ctrl(i, dc);
1094 ctrl = (u16 *)&dc->port[i].ctrl_ul;
1095 write_mem32(dc->port[PORT_CTRL].ul_addr[0], \
1096 (u32 *) ctrl, 2);
1097 dc->port[i].update_flow_control = 0;
1098 more_flow_control_to_be_updated = 1;
1099 }
1100 }
1101 return 0;
1102}
1103
1104/*
1105 * Handle donlink data, ports that are handled are modem and diagnostics
1106 * Return 1 - ok
1107 * Return 0 - toggle fields are out of sync
1108 */
1109static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
1110 u16 read_iir, u16 mask1, u16 mask2)
1111{
1112 if (*toggle == 0 && read_iir & mask1) {
1113 if (receive_data(port, dc)) {
1114 writew(mask1, dc->reg_fcr);
1115 *toggle = !(*toggle);
1116 }
1117
1118 if (read_iir & mask2) {
1119 if (receive_data(port, dc)) {
1120 writew(mask2, dc->reg_fcr);
1121 *toggle = !(*toggle);
1122 }
1123 }
1124 } else if (*toggle == 1 && read_iir & mask2) {
1125 if (receive_data(port, dc)) {
1126 writew(mask2, dc->reg_fcr);
1127 *toggle = !(*toggle);
1128 }
1129
1130 if (read_iir & mask1) {
1131 if (receive_data(port, dc)) {
1132 writew(mask1, dc->reg_fcr);
1133 *toggle = !(*toggle);
1134 }
1135 }
1136 } else {
1137 dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n",
1138 *toggle);
1139 return 0;
1140 }
1141 return 1;
1142}
1143
1144/*
1145 * Handle uplink data, this is currently for the modem port
1146 * Return 1 - ok
1147 * Return 0 - toggle field are out of sync
1148 */
1149static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
1150{
1151 u8 *toggle = &(dc->port[port].toggle_ul);
1152
1153 if (*toggle == 0 && read_iir & MDM_UL1) {
1154 dc->last_ier &= ~MDM_UL;
1155 writew(dc->last_ier, dc->reg_ier);
1156 if (send_data(port, dc)) {
1157 writew(MDM_UL1, dc->reg_fcr);
1158 dc->last_ier = dc->last_ier | MDM_UL;
1159 writew(dc->last_ier, dc->reg_ier);
1160 *toggle = !*toggle;
1161 }
1162
1163 if (read_iir & MDM_UL2) {
1164 dc->last_ier &= ~MDM_UL;
1165 writew(dc->last_ier, dc->reg_ier);
1166 if (send_data(port, dc)) {
1167 writew(MDM_UL2, dc->reg_fcr);
1168 dc->last_ier = dc->last_ier | MDM_UL;
1169 writew(dc->last_ier, dc->reg_ier);
1170 *toggle = !*toggle;
1171 }
1172 }
1173
1174 } else if (*toggle == 1 && read_iir & MDM_UL2) {
1175 dc->last_ier &= ~MDM_UL;
1176 writew(dc->last_ier, dc->reg_ier);
1177 if (send_data(port, dc)) {
1178 writew(MDM_UL2, dc->reg_fcr);
1179 dc->last_ier = dc->last_ier | MDM_UL;
1180 writew(dc->last_ier, dc->reg_ier);
1181 *toggle = !*toggle;
1182 }
1183
1184 if (read_iir & MDM_UL1) {
1185 dc->last_ier &= ~MDM_UL;
1186 writew(dc->last_ier, dc->reg_ier);
1187 if (send_data(port, dc)) {
1188 writew(MDM_UL1, dc->reg_fcr);
1189 dc->last_ier = dc->last_ier | MDM_UL;
1190 writew(dc->last_ier, dc->reg_ier);
1191 *toggle = !*toggle;
1192 }
1193 }
1194 } else {
1195 writew(read_iir & MDM_UL, dc->reg_fcr);
1196 dev_err(&dc->pdev->dev, "port out of sync!\n");
1197 return 0;
1198 }
1199 return 1;
1200}
1201
1202static irqreturn_t interrupt_handler(int irq, void *dev_id)
1203{
1204 struct nozomi *dc = dev_id;
1205 unsigned int a;
1206 u16 read_iir;
1207
1208 if (!dc)
1209 return IRQ_NONE;
1210
1211 spin_lock(&dc->spin_mutex);
1212 read_iir = readw(dc->reg_iir);
1213
1214 /* Card removed */
1215 if (read_iir == (u16)-1)
1216 goto none;
1217 /*
1218 * Just handle interrupt enabled in IER
1219 * (by masking with dc->last_ier)
1220 */
1221 read_iir &= dc->last_ier;
1222
1223 if (read_iir == 0)
1224 goto none;
1225
1226
1227 DBG4("%s irq:0x%04X, prev:0x%04X", interrupt2str(read_iir), read_iir,
1228 dc->last_ier);
1229
1230 if (read_iir & RESET) {
1231 if (unlikely(!nozomi_read_config_table(dc))) {
1232 dc->last_ier = 0x0;
1233 writew(dc->last_ier, dc->reg_ier);
1234 dev_err(&dc->pdev->dev, "Could not read status from "
1235 "card, we should disable interface\n");
1236 } else {
1237 writew(RESET, dc->reg_fcr);
1238 }
1239 /* No more useful info if this was the reset interrupt. */
1240 goto exit_handler;
1241 }
1242 if (read_iir & CTRL_UL) {
1243 DBG1("CTRL_UL");
1244 dc->last_ier &= ~CTRL_UL;
1245 writew(dc->last_ier, dc->reg_ier);
1246 if (send_flow_control(dc)) {
1247 writew(CTRL_UL, dc->reg_fcr);
1248 dc->last_ier = dc->last_ier | CTRL_UL;
1249 writew(dc->last_ier, dc->reg_ier);
1250 }
1251 }
1252 if (read_iir & CTRL_DL) {
1253 receive_flow_control(dc);
1254 writew(CTRL_DL, dc->reg_fcr);
1255 }
1256 if (read_iir & MDM_DL) {
1257 if (!handle_data_dl(dc, PORT_MDM,
1258 &(dc->port[PORT_MDM].toggle_dl), read_iir,
1259 MDM_DL1, MDM_DL2)) {
1260 dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n");
1261 goto exit_handler;
1262 }
1263 }
1264 if (read_iir & MDM_UL) {
1265 if (!handle_data_ul(dc, PORT_MDM, read_iir)) {
1266 dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n");
1267 goto exit_handler;
1268 }
1269 }
1270 if (read_iir & DIAG_DL) {
1271 if (!handle_data_dl(dc, PORT_DIAG,
1272 &(dc->port[PORT_DIAG].toggle_dl), read_iir,
1273 DIAG_DL1, DIAG_DL2)) {
1274 dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n");
1275 goto exit_handler;
1276 }
1277 }
1278 if (read_iir & DIAG_UL) {
1279 dc->last_ier &= ~DIAG_UL;
1280 writew(dc->last_ier, dc->reg_ier);
1281 if (send_data(PORT_DIAG, dc)) {
1282 writew(DIAG_UL, dc->reg_fcr);
1283 dc->last_ier = dc->last_ier | DIAG_UL;
1284 writew(dc->last_ier, dc->reg_ier);
1285 }
1286 }
1287 if (read_iir & APP1_DL) {
1288 if (receive_data(PORT_APP1, dc))
1289 writew(APP1_DL, dc->reg_fcr);
1290 }
1291 if (read_iir & APP1_UL) {
1292 dc->last_ier &= ~APP1_UL;
1293 writew(dc->last_ier, dc->reg_ier);
1294 if (send_data(PORT_APP1, dc)) {
1295 writew(APP1_UL, dc->reg_fcr);
1296 dc->last_ier = dc->last_ier | APP1_UL;
1297 writew(dc->last_ier, dc->reg_ier);
1298 }
1299 }
1300 if (read_iir & APP2_DL) {
1301 if (receive_data(PORT_APP2, dc))
1302 writew(APP2_DL, dc->reg_fcr);
1303 }
1304 if (read_iir & APP2_UL) {
1305 dc->last_ier &= ~APP2_UL;
1306 writew(dc->last_ier, dc->reg_ier);
1307 if (send_data(PORT_APP2, dc)) {
1308 writew(APP2_UL, dc->reg_fcr);
1309 dc->last_ier = dc->last_ier | APP2_UL;
1310 writew(dc->last_ier, dc->reg_ier);
1311 }
1312 }
1313
1314exit_handler:
1315 spin_unlock(&dc->spin_mutex);
1316 for (a = 0; a < NOZOMI_MAX_PORTS; a++)
1317 if (test_and_clear_bit(a, &dc->flip))
1318 tty_flip_buffer_push(dc->port[a].tty);
1319 return IRQ_HANDLED;
1320none:
1321 spin_unlock(&dc->spin_mutex);
1322 return IRQ_NONE;
1323}
1324
1325static void nozomi_get_card_type(struct nozomi *dc)
1326{
1327 int i;
1328 u32 size = 0;
1329
1330 for (i = 0; i < 6; i++)
1331 size += pci_resource_len(dc->pdev, i);
1332
1333 /* Assume card type F32_8 if no match */
1334 dc->card_type = size == 2048 ? F32_2 : F32_8;
1335
1336 dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type);
1337}
1338
1339static void nozomi_setup_private_data(struct nozomi *dc)
1340{
1341 void __iomem *offset = dc->base_addr + dc->card_type / 2;
1342 unsigned int i;
1343
1344 dc->reg_fcr = (void __iomem *)(offset + R_FCR);
1345 dc->reg_iir = (void __iomem *)(offset + R_IIR);
1346 dc->reg_ier = (void __iomem *)(offset + R_IER);
1347 dc->last_ier = 0;
1348 dc->flip = 0;
1349
1350 dc->port[PORT_MDM].token_dl = MDM_DL;
1351 dc->port[PORT_DIAG].token_dl = DIAG_DL;
1352 dc->port[PORT_APP1].token_dl = APP1_DL;
1353 dc->port[PORT_APP2].token_dl = APP2_DL;
1354
1355 for (i = 0; i < MAX_PORT; i++)
1356 init_waitqueue_head(&dc->port[i].tty_wait);
1357}
1358
1359static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
1360 char *buf)
1361{
1362 struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
1363
1364 return sprintf(buf, "%d\n", dc->card_type);
1365}
1366static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
1367
1368static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
1369 char *buf)
1370{
1371 struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
1372
1373 return sprintf(buf, "%u\n", dc->open_ttys);
1374}
1375static DEVICE_ATTR(open_ttys, 0444, open_ttys_show, NULL);
1376
1377static void make_sysfs_files(struct nozomi *dc)
1378{
1379 if (device_create_file(&dc->pdev->dev, &dev_attr_card_type))
1380 dev_err(&dc->pdev->dev,
1381 "Could not create sysfs file for card_type\n");
1382 if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys))
1383 dev_err(&dc->pdev->dev,
1384 "Could not create sysfs file for open_ttys\n");
1385}
1386
1387static void remove_sysfs_files(struct nozomi *dc)
1388{
1389 device_remove_file(&dc->pdev->dev, &dev_attr_card_type);
1390 device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys);
1391}
1392
1393/* Allocate memory for one device */
1394static int __devinit nozomi_card_init(struct pci_dev *pdev,
1395 const struct pci_device_id *ent)
1396{
1397 resource_size_t start;
1398 int ret;
1399 struct nozomi *dc = NULL;
1400 int ndev_idx;
1401 int i;
1402
1403 dev_dbg(&pdev->dev, "Init, new card found\n");
1404
1405 for (ndev_idx = 0; ndev_idx < ARRAY_SIZE(ndevs); ndev_idx++)
1406 if (!ndevs[ndev_idx])
1407 break;
1408
1409 if (ndev_idx >= ARRAY_SIZE(ndevs)) {
1410 dev_err(&pdev->dev, "no free tty range for this card left\n");
1411 ret = -EIO;
1412 goto err;
1413 }
1414
1415 dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL);
1416 if (unlikely(!dc)) {
1417 dev_err(&pdev->dev, "Could not allocate memory\n");
1418 ret = -ENOMEM;
1419 goto err_free;
1420 }
1421
1422 dc->pdev = pdev;
1423
1424 /* Find out what card type it is */
1425 nozomi_get_card_type(dc);
1426
1427 ret = pci_enable_device(dc->pdev);
1428 if (ret) {
1429 dev_err(&pdev->dev, "Failed to enable PCI Device\n");
1430 goto err_free;
1431 }
1432
1433 start = pci_resource_start(dc->pdev, 0);
1434 if (start == 0) {
1435 dev_err(&pdev->dev, "No I/O address for card detected\n");
1436 ret = -ENODEV;
1437 goto err_disable_device;
1438 }
1439
1440 ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
1441 if (ret) {
1442 dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
1443 (int) /* nozomi_private.io_addr */ 0);
1444 goto err_disable_device;
1445 }
1446
1447 dc->base_addr = ioremap(start, dc->card_type);
1448 if (!dc->base_addr) {
1449 dev_err(&pdev->dev, "Unable to map card MMIO\n");
1450 ret = -ENODEV;
1451 goto err_rel_regs;
1452 }
1453
1454 dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
1455 if (!dc->send_buf) {
1456 dev_err(&pdev->dev, "Could not allocate send buffer?\n");
1457 ret = -ENOMEM;
1458 goto err_free_sbuf;
1459 }
1460
1461 spin_lock_init(&dc->spin_mutex);
1462
1463 nozomi_setup_private_data(dc);
1464
1465 /* Disable all interrupts */
1466 dc->last_ier = 0;
1467 writew(dc->last_ier, dc->reg_ier);
1468
1469 ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED,
1470 NOZOMI_NAME, dc);
1471 if (unlikely(ret)) {
1472 dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
1473 goto err_free_sbuf;
1474 }
1475
1476 DBG1("base_addr: %p", dc->base_addr);
1477
1478 make_sysfs_files(dc);
1479
1480 dc->index_start = ndev_idx * MAX_PORT;
1481 ndevs[ndev_idx] = dc;
1482
1483 for (i = 0; i < MAX_PORT; i++) {
1484 mutex_init(&dc->port[i].tty_sem);
1485 dc->port[i].tty_open_count = 0;
1486 dc->port[i].tty = NULL;
1487 tty_register_device(ntty_driver, dc->index_start + i,
1488 &pdev->dev);
1489 }
1490
1491 /* Enable RESET interrupt. */
1492 dc->last_ier = RESET;
1493 writew(dc->last_ier, dc->reg_ier);
1494
1495 pci_set_drvdata(pdev, dc);
1496
1497 return 0;
1498
1499err_free_sbuf:
1500 kfree(dc->send_buf);
1501 iounmap(dc->base_addr);
1502err_rel_regs:
1503 pci_release_regions(pdev);
1504err_disable_device:
1505 pci_disable_device(pdev);
1506err_free:
1507 kfree(dc);
1508err:
1509 return ret;
1510}
1511
1512static void __devexit tty_exit(struct nozomi *dc)
1513{
1514 unsigned int i;
1515
1516 DBG1(" ");
1517
1518 flush_scheduled_work();
1519
1520 for (i = 0; i < MAX_PORT; ++i)
1521 if (dc->port[i].tty && \
1522 list_empty(&dc->port[i].tty->hangup_work.entry))
1523 tty_hangup(dc->port[i].tty);
1524
1525 while (dc->open_ttys)
1526 msleep(1);
1527
1528 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
1529 tty_unregister_device(ntty_driver, i);
1530}
1531
1532/* Deallocate memory for one device */
1533static void __devexit nozomi_card_exit(struct pci_dev *pdev)
1534{
1535 int i;
1536 struct ctrl_ul ctrl;
1537 struct nozomi *dc = pci_get_drvdata(pdev);
1538
1539 /* Disable all interrupts */
1540 dc->last_ier = 0;
1541 writew(dc->last_ier, dc->reg_ier);
1542
1543 tty_exit(dc);
1544
1545 /* Send 0x0001, command card to resend the reset token. */
1546 /* This is to get the reset when the module is reloaded. */
1547 ctrl.port = 0x00;
1548 ctrl.reserved = 0;
1549 ctrl.RTS = 0;
1550 ctrl.DTR = 1;
1551 DBG1("sending flow control 0x%04X", *((u16 *)&ctrl));
1552
1553 /* Setup dc->reg addresses to we can use defines here */
1554 write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2);
1555 writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */
1556
1557 remove_sysfs_files(dc);
1558
1559 free_irq(pdev->irq, dc);
1560
1561 for (i = 0; i < MAX_PORT; i++)
1562 if (dc->port[i].fifo_ul)
1563 kfifo_free(dc->port[i].fifo_ul);
1564
1565 kfree(dc->send_buf);
1566
1567 iounmap(dc->base_addr);
1568
1569 pci_release_regions(pdev);
1570
1571 pci_disable_device(pdev);
1572
1573 ndevs[dc->index_start / MAX_PORT] = NULL;
1574
1575 kfree(dc);
1576}
1577
1578static void set_rts(const struct tty_struct *tty, int rts)
1579{
1580 struct port *port = get_port_by_tty(tty);
1581
1582 port->ctrl_ul.RTS = rts;
1583 port->update_flow_control = 1;
1584 enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
1585}
1586
1587static void set_dtr(const struct tty_struct *tty, int dtr)
1588{
1589 struct port *port = get_port_by_tty(tty);
1590
1591 DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr);
1592
1593 port->ctrl_ul.DTR = dtr;
1594 port->update_flow_control = 1;
1595 enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
1596}
1597
1598/*
1599 * ----------------------------------------------------------------------------
1600 * TTY code
1601 * ----------------------------------------------------------------------------
1602 */
1603
1604/* Called when the userspace process opens the tty, /dev/noz*. */
1605static int ntty_open(struct tty_struct *tty, struct file *file)
1606{
1607 struct port *port = get_port_by_tty(tty);
1608 struct nozomi *dc = get_dc_by_tty(tty);
1609 unsigned long flags;
1610
1611 if (!port || !dc)
1612 return -ENODEV;
1613
1614 if (mutex_lock_interruptible(&port->tty_sem))
1615 return -ERESTARTSYS;
1616
1617 port->tty_open_count++;
1618 dc->open_ttys++;
1619
1620 /* Enable interrupt downlink for channel */
1621 if (port->tty_open_count == 1) {
1622 tty->low_latency = 1;
1623 tty->driver_data = port;
1624 port->tty = tty;
1625 DBG1("open: %d", port->token_dl);
1626 spin_lock_irqsave(&dc->spin_mutex, flags);
1627 dc->last_ier = dc->last_ier | port->token_dl;
1628 writew(dc->last_ier, dc->reg_ier);
1629 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1630 }
1631
1632 mutex_unlock(&port->tty_sem);
1633
1634 return 0;
1635}
1636
1637/* Called when the userspace process close the tty, /dev/noz*. */
1638static void ntty_close(struct tty_struct *tty, struct file *file)
1639{
1640 struct nozomi *dc = get_dc_by_tty(tty);
1641 struct port *port = tty->driver_data;
1642 unsigned long flags;
1643
1644 if (!dc || !port)
1645 return;
1646
1647 if (mutex_lock_interruptible(&port->tty_sem))
1648 return;
1649
1650 if (!port->tty_open_count)
1651 goto exit;
1652
1653 dc->open_ttys--;
1654 port->tty_open_count--;
1655
1656 if (port->tty_open_count == 0) {
1657 DBG1("close: %d", port->token_dl);
1658 spin_lock_irqsave(&dc->spin_mutex, flags);
1659 dc->last_ier &= ~(port->token_dl);
1660 writew(dc->last_ier, dc->reg_ier);
1661 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1662 }
1663
1664exit:
1665 mutex_unlock(&port->tty_sem);
1666}
1667
1668/*
1669 * called when the userspace process writes to the tty (/dev/noz*).
1670 * Data is inserted into a fifo, which is then read and transfered to the modem.
1671 */
1672static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
1673 int count)
1674{
1675 int rval = -EINVAL;
1676 struct nozomi *dc = get_dc_by_tty(tty);
1677 struct port *port = tty->driver_data;
1678 unsigned long flags;
1679
1680 /* DBG1( "WRITEx: %d, index = %d", count, index); */
1681
1682 if (!dc || !port)
1683 return -ENODEV;
1684
1685 if (unlikely(!mutex_trylock(&port->tty_sem))) {
1686 /*
1687 * must test lock as tty layer wraps calls
1688 * to this function with BKL
1689 */
1690 dev_err(&dc->pdev->dev, "Would have deadlocked - "
1691 "return EAGAIN\n");
1692 return -EAGAIN;
1693 }
1694
1695 if (unlikely(!port->tty_open_count)) {
1696 DBG1(" ");
1697 goto exit;
1698 }
1699
1700 rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count);
1701
1702 /* notify card */
1703 if (unlikely(dc == NULL)) {
1704 DBG1("No device context?");
1705 goto exit;
1706 }
1707
1708 spin_lock_irqsave(&dc->spin_mutex, flags);
1709 /* CTS is only valid on the modem channel */
1710 if (port == &(dc->port[PORT_MDM])) {
1711 if (port->ctrl_dl.CTS) {
1712 DBG4("Enable interrupt");
1713 enable_transmit_ul(tty->index % MAX_PORT, dc);
1714 } else {
1715 dev_err(&dc->pdev->dev,
1716 "CTS not active on modem port?\n");
1717 }
1718 } else {
1719 enable_transmit_ul(tty->index % MAX_PORT, dc);
1720 }
1721 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1722
1723exit:
1724 mutex_unlock(&port->tty_sem);
1725 return rval;
1726}
1727
1728/*
1729 * Calculate how much is left in device
1730 * This method is called by the upper tty layer.
1731 * #according to sources N_TTY.c it expects a value >= 0 and
1732 * does not check for negative values.
1733 */
1734static int ntty_write_room(struct tty_struct *tty)
1735{
1736 struct port *port = tty->driver_data;
1737 int room = 0;
1738 struct nozomi *dc = get_dc_by_tty(tty);
1739
1740 if (!dc || !port)
1741 return 0;
1742 if (!mutex_trylock(&port->tty_sem))
1743 return 0;
1744
1745 if (!port->tty_open_count)
1746 goto exit;
1747
1748 room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
1749
1750exit:
1751 mutex_unlock(&port->tty_sem);
1752 return room;
1753}
1754
1755/* Gets io control parameters */
1756static int ntty_tiocmget(struct tty_struct *tty, struct file *file)
1757{
1758 struct port *port = tty->driver_data;
1759 struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
1760 struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
1761
1762 return (ctrl_ul->RTS ? TIOCM_RTS : 0) |
1763 (ctrl_ul->DTR ? TIOCM_DTR : 0) |
1764 (ctrl_dl->DCD ? TIOCM_CAR : 0) |
1765 (ctrl_dl->RI ? TIOCM_RNG : 0) |
1766 (ctrl_dl->DSR ? TIOCM_DSR : 0) |
1767 (ctrl_dl->CTS ? TIOCM_CTS : 0);
1768}
1769
1770/* Sets io controls parameters */
1771static int ntty_tiocmset(struct tty_struct *tty, struct file *file,
1772 unsigned int set, unsigned int clear)
1773{
1774 if (set & TIOCM_RTS)
1775 set_rts(tty, 1);
1776 else if (clear & TIOCM_RTS)
1777 set_rts(tty, 0);
1778
1779 if (set & TIOCM_DTR)
1780 set_dtr(tty, 1);
1781 else if (clear & TIOCM_DTR)
1782 set_dtr(tty, 0);
1783
1784 return 0;
1785}
1786
1787static int ntty_cflags_changed(struct port *port, unsigned long flags,
1788 struct async_icount *cprev)
1789{
1790 struct async_icount cnow = port->tty_icount;
1791 int ret;
1792
1793 ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
1794 ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
1795 ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
1796 ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
1797
1798 *cprev = cnow;
1799
1800 return ret;
1801}
1802
1803static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp)
1804{
1805 struct async_icount cnow = port->tty_icount;
1806 struct serial_icounter_struct icount;
1807
1808 icount.cts = cnow.cts;
1809 icount.dsr = cnow.dsr;
1810 icount.rng = cnow.rng;
1811 icount.dcd = cnow.dcd;
1812 icount.rx = cnow.rx;
1813 icount.tx = cnow.tx;
1814 icount.frame = cnow.frame;
1815 icount.overrun = cnow.overrun;
1816 icount.parity = cnow.parity;
1817 icount.brk = cnow.brk;
1818 icount.buf_overrun = cnow.buf_overrun;
1819
1820 return copy_to_user(argp, &icount, sizeof(icount));
1821}
1822
1823static int ntty_ioctl(struct tty_struct *tty, struct file *file,
1824 unsigned int cmd, unsigned long arg)
1825{
1826 struct port *port = tty->driver_data;
1827 void __user *argp = (void __user *)arg;
1828 int rval = -ENOIOCTLCMD;
1829
1830 DBG1("******** IOCTL, cmd: %d", cmd);
1831
1832 switch (cmd) {
1833 case TIOCMIWAIT: {
1834 struct async_icount cprev = port->tty_icount;
1835
1836 rval = wait_event_interruptible(port->tty_wait,
1837 ntty_cflags_changed(port, arg, &cprev));
1838 break;
1839 } case TIOCGICOUNT:
1840 rval = ntty_ioctl_tiocgicount(port, argp);
1841 break;
1842 default:
1843 DBG1("ERR: 0x%08X, %d", cmd, cmd);
1844 break;
1845 };
1846
1847 return rval;
1848}
1849
1850/*
1851 * Called by the upper tty layer when tty buffers are ready
1852 * to receive data again after a call to throttle.
1853 */
1854static void ntty_unthrottle(struct tty_struct *tty)
1855{
1856 struct nozomi *dc = get_dc_by_tty(tty);
1857 unsigned long flags;
1858
1859 DBG1("UNTHROTTLE");
1860 spin_lock_irqsave(&dc->spin_mutex, flags);
1861 enable_transmit_dl(tty->index % MAX_PORT, dc);
1862 set_rts(tty, 1);
1863
1864 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1865}
1866
1867/*
1868 * Called by the upper tty layer when the tty buffers are almost full.
1869 * The driver should stop send more data.
1870 */
1871static void ntty_throttle(struct tty_struct *tty)
1872{
1873 struct nozomi *dc = get_dc_by_tty(tty);
1874 unsigned long flags;
1875
1876 DBG1("THROTTLE");
1877 spin_lock_irqsave(&dc->spin_mutex, flags);
1878 set_rts(tty, 0);
1879 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1880}
1881
1882/* just to discard single character writes */
1883static void ntty_put_char(struct tty_struct *tty, unsigned char c)
1884{
1885 /* FIXME !!! */
1886 DBG2("PUT CHAR Function: %c", c);
1887}
1888
1889/* Returns number of chars in buffer, called by tty layer */
1890static s32 ntty_chars_in_buffer(struct tty_struct *tty)
1891{
1892 struct port *port = tty->driver_data;
1893 struct nozomi *dc = get_dc_by_tty(tty);
1894 s32 rval;
1895
1896 if (unlikely(!dc || !port)) {
1897 rval = -ENODEV;
1898 goto exit_in_buffer;
1899 }
1900
1901 if (unlikely(!port->tty_open_count)) {
1902 dev_err(&dc->pdev->dev, "No tty open?\n");
1903 rval = -ENODEV;
1904 goto exit_in_buffer;
1905 }
1906
1907 rval = __kfifo_len(port->fifo_ul);
1908
1909exit_in_buffer:
1910 return rval;
1911}
1912
1913static struct tty_operations tty_ops = {
1914 .ioctl = ntty_ioctl,
1915 .open = ntty_open,
1916 .close = ntty_close,
1917 .write = ntty_write,
1918 .write_room = ntty_write_room,
1919 .unthrottle = ntty_unthrottle,
1920 .throttle = ntty_throttle,
1921 .chars_in_buffer = ntty_chars_in_buffer,
1922 .put_char = ntty_put_char,
1923 .tiocmget = ntty_tiocmget,
1924 .tiocmset = ntty_tiocmset,
1925};
1926
1927/* Module initialization */
1928static struct pci_driver nozomi_driver = {
1929 .name = NOZOMI_NAME,
1930 .id_table = nozomi_pci_tbl,
1931 .probe = nozomi_card_init,
1932 .remove = __devexit_p(nozomi_card_exit),
1933};
1934
1935static __init int nozomi_init(void)
1936{
1937 int ret;
1938
1939 printk(KERN_INFO "Initializing %s\n", VERSION_STRING);
1940
1941 ntty_driver = alloc_tty_driver(NTTY_TTY_MAXMINORS);
1942 if (!ntty_driver)
1943 return -ENOMEM;
1944
1945 ntty_driver->owner = THIS_MODULE;
1946 ntty_driver->driver_name = NOZOMI_NAME_TTY;
1947 ntty_driver->name = "noz";
1948 ntty_driver->major = 0;
1949 ntty_driver->type = TTY_DRIVER_TYPE_SERIAL;
1950 ntty_driver->subtype = SERIAL_TYPE_NORMAL;
1951 ntty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1952 ntty_driver->init_termios = tty_std_termios;
1953 ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \
1954 HUPCL | CLOCAL;
1955 ntty_driver->init_termios.c_ispeed = 115200;
1956 ntty_driver->init_termios.c_ospeed = 115200;
1957 tty_set_operations(ntty_driver, &tty_ops);
1958
1959 ret = tty_register_driver(ntty_driver);
1960 if (ret) {
1961 printk(KERN_ERR "Nozomi: failed to register ntty driver\n");
1962 goto free_tty;
1963 }
1964
1965 ret = pci_register_driver(&nozomi_driver);
1966 if (ret) {
1967 printk(KERN_ERR "Nozomi: can't register pci driver\n");
1968 goto unr_tty;
1969 }
1970
1971 return 0;
1972unr_tty:
1973 tty_unregister_driver(ntty_driver);
1974free_tty:
1975 put_tty_driver(ntty_driver);
1976 return ret;
1977}
1978
1979static __exit void nozomi_exit(void)
1980{
1981 printk(KERN_INFO "Unloading %s\n", DRIVER_DESC);
1982 pci_unregister_driver(&nozomi_driver);
1983 tty_unregister_driver(ntty_driver);
1984 put_tty_driver(ntty_driver);
1985}
1986
1987module_init(nozomi_init);
1988module_exit(nozomi_exit);
1989
1990module_param(debug, int, S_IRUGO | S_IWUSR);
1991
1992MODULE_LICENSE("Dual BSD/GPL");
1993MODULE_DESCRIPTION(DRIVER_DESC);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 79581fab82d6..5efd5550f4ca 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -828,11 +828,8 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
828 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); 828 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
829 829
830 /* prepare interface data */ 830 /* prepare interface data */
831 policy->kobj.parent = &sys_dev->kobj; 831 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &sys_dev->kobj,
832 policy->kobj.ktype = &ktype_cpufreq; 832 "cpufreq");
833 kobject_set_name(&policy->kobj, "cpufreq");
834
835 ret = kobject_register(&policy->kobj);
836 if (ret) { 833 if (ret) {
837 unlock_policy_rwsem_write(cpu); 834 unlock_policy_rwsem_write(cpu);
838 goto err_out_driver_exit; 835 goto err_out_driver_exit;
@@ -902,6 +899,7 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
902 goto err_out_unregister; 899 goto err_out_unregister;
903 } 900 }
904 901
902 kobject_uevent(&policy->kobj, KOBJ_ADD);
905 module_put(cpufreq_driver->owner); 903 module_put(cpufreq_driver->owner);
906 dprintk("initialization complete\n"); 904 dprintk("initialization complete\n");
907 cpufreq_debug_enable_ratelimit(); 905 cpufreq_debug_enable_ratelimit();
@@ -915,7 +913,7 @@ err_out_unregister:
915 cpufreq_cpu_data[j] = NULL; 913 cpufreq_cpu_data[j] = NULL;
916 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 914 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
917 915
918 kobject_unregister(&policy->kobj); 916 kobject_put(&policy->kobj);
919 wait_for_completion(&policy->kobj_unregister); 917 wait_for_completion(&policy->kobj_unregister);
920 918
921err_out_driver_exit: 919err_out_driver_exit:
@@ -1032,8 +1030,6 @@ static int __cpufreq_remove_dev (struct sys_device * sys_dev)
1032 1030
1033 unlock_policy_rwsem_write(cpu); 1031 unlock_policy_rwsem_write(cpu);
1034 1032
1035 kobject_unregister(&data->kobj);
1036
1037 kobject_put(&data->kobj); 1033 kobject_put(&data->kobj);
1038 1034
1039 /* we need to make sure that the underlying kobj is actually 1035 /* we need to make sure that the underlying kobj is actually
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 0f3515e77d4b..088ea74edd34 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -277,7 +277,7 @@ static struct kobj_type ktype_state_cpuidle = {
277 277
278static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i) 278static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
279{ 279{
280 kobject_unregister(&device->kobjs[i]->kobj); 280 kobject_put(&device->kobjs[i]->kobj);
281 wait_for_completion(&device->kobjs[i]->kobj_unregister); 281 wait_for_completion(&device->kobjs[i]->kobj_unregister);
282 kfree(device->kobjs[i]); 282 kfree(device->kobjs[i]);
283 device->kobjs[i] = NULL; 283 device->kobjs[i] = NULL;
@@ -300,14 +300,13 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
300 kobj->state = &device->states[i]; 300 kobj->state = &device->states[i];
301 init_completion(&kobj->kobj_unregister); 301 init_completion(&kobj->kobj_unregister);
302 302
303 kobj->kobj.parent = &device->kobj; 303 ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
304 kobj->kobj.ktype = &ktype_state_cpuidle; 304 "state%d", i);
305 kobject_set_name(&kobj->kobj, "state%d", i);
306 ret = kobject_register(&kobj->kobj);
307 if (ret) { 305 if (ret) {
308 kfree(kobj); 306 kfree(kobj);
309 goto error_state; 307 goto error_state;
310 } 308 }
309 kobject_uevent(&kobj->kobj, KOBJ_ADD);
311 device->kobjs[i] = kobj; 310 device->kobjs[i] = kobj;
312 } 311 }
313 312
@@ -339,12 +338,14 @@ int cpuidle_add_sysfs(struct sys_device *sysdev)
339{ 338{
340 int cpu = sysdev->id; 339 int cpu = sysdev->id;
341 struct cpuidle_device *dev; 340 struct cpuidle_device *dev;
341 int error;
342 342
343 dev = per_cpu(cpuidle_devices, cpu); 343 dev = per_cpu(cpuidle_devices, cpu);
344 dev->kobj.parent = &sysdev->kobj; 344 error = kobject_init_and_add(&dev->kobj, &ktype_cpuidle, &sysdev->kobj,
345 dev->kobj.ktype = &ktype_cpuidle; 345 "cpuidle");
346 kobject_set_name(&dev->kobj, "%s", "cpuidle"); 346 if (!error)
347 return kobject_register(&dev->kobj); 347 kobject_uevent(&dev->kobj, KOBJ_ADD);
348 return error;
348} 349}
349 350
350/** 351/**
@@ -357,5 +358,5 @@ void cpuidle_remove_sysfs(struct sys_device *sysdev)
357 struct cpuidle_device *dev; 358 struct cpuidle_device *dev;
358 359
359 dev = per_cpu(cpuidle_devices, cpu); 360 dev = per_cpu(cpuidle_devices, cpu);
360 kobject_unregister(&dev->kobj); 361 kobject_put(&dev->kobj);
361} 362}
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index ddd3a259cea1..74bd599dfb0c 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -83,4 +83,15 @@ config ZCRYPT_MONOLITHIC
83 that contains all parts of the crypto device driver (ap bus, 83 that contains all parts of the crypto device driver (ap bus,
84 request router and all the card drivers). 84 request router and all the card drivers).
85 85
86config CRYPTO_DEV_HIFN_795X
87 tristate "Driver HIFN 795x crypto accelerator chips"
88 select CRYPTO_DES
89 select CRYPTO_ALGAPI
90 select CRYPTO_BLKCIPHER
91 depends on PCI
92 help
93 This option allows you to have support for HIFN 795x crypto adapters.
94
95
96
86endif # CRYPTO_HW 97endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index d070030f7d7e..c0327f0dadc5 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -1,3 +1,4 @@
1obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o 1obj-$(CONFIG_CRYPTO_DEV_PADLOCK_AES) += padlock-aes.o
2obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o 2obj-$(CONFIG_CRYPTO_DEV_PADLOCK_SHA) += padlock-sha.o
3obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o 3obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
4obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
diff --git a/drivers/crypto/geode-aes.c b/drivers/crypto/geode-aes.c
index 711e246e1ef0..4801162919d9 100644
--- a/drivers/crypto/geode-aes.c
+++ b/drivers/crypto/geode-aes.c
@@ -13,44 +13,13 @@
13#include <linux/crypto.h> 13#include <linux/crypto.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <crypto/algapi.h> 15#include <crypto/algapi.h>
16#include <crypto/aes.h>
16 17
17#include <asm/io.h> 18#include <asm/io.h>
18#include <asm/delay.h> 19#include <asm/delay.h>
19 20
20#include "geode-aes.h" 21#include "geode-aes.h"
21 22
22/* Register definitions */
23
24#define AES_CTRLA_REG 0x0000
25
26#define AES_CTRL_START 0x01
27#define AES_CTRL_DECRYPT 0x00
28#define AES_CTRL_ENCRYPT 0x02
29#define AES_CTRL_WRKEY 0x04
30#define AES_CTRL_DCA 0x08
31#define AES_CTRL_SCA 0x10
32#define AES_CTRL_CBC 0x20
33
34#define AES_INTR_REG 0x0008
35
36#define AES_INTRA_PENDING (1 << 16)
37#define AES_INTRB_PENDING (1 << 17)
38
39#define AES_INTR_PENDING (AES_INTRA_PENDING | AES_INTRB_PENDING)
40#define AES_INTR_MASK 0x07
41
42#define AES_SOURCEA_REG 0x0010
43#define AES_DSTA_REG 0x0014
44#define AES_LENA_REG 0x0018
45#define AES_WRITEKEY0_REG 0x0030
46#define AES_WRITEIV0_REG 0x0040
47
48/* A very large counter that is used to gracefully bail out of an
49 * operation in case of trouble
50 */
51
52#define AES_OP_TIMEOUT 0x50000
53
54/* Static structures */ 23/* Static structures */
55 24
56static void __iomem * _iobase; 25static void __iomem * _iobase;
@@ -87,9 +56,10 @@ do_crypt(void *src, void *dst, int len, u32 flags)
87 /* Start the operation */ 56 /* Start the operation */
88 iowrite32(AES_CTRL_START | flags, _iobase + AES_CTRLA_REG); 57 iowrite32(AES_CTRL_START | flags, _iobase + AES_CTRLA_REG);
89 58
90 do 59 do {
91 status = ioread32(_iobase + AES_INTR_REG); 60 status = ioread32(_iobase + AES_INTR_REG);
92 while(!(status & AES_INTRA_PENDING) && --counter); 61 cpu_relax();
62 } while(!(status & AES_INTRA_PENDING) && --counter);
93 63
94 /* Clear the event */ 64 /* Clear the event */
95 iowrite32((status & 0xFF) | AES_INTRA_PENDING, _iobase + AES_INTR_REG); 65 iowrite32((status & 0xFF) | AES_INTRA_PENDING, _iobase + AES_INTR_REG);
@@ -101,6 +71,7 @@ geode_aes_crypt(struct geode_aes_op *op)
101{ 71{
102 u32 flags = 0; 72 u32 flags = 0;
103 unsigned long iflags; 73 unsigned long iflags;
74 int ret;
104 75
105 if (op->len == 0) 76 if (op->len == 0)
106 return 0; 77 return 0;
@@ -129,7 +100,8 @@ geode_aes_crypt(struct geode_aes_op *op)
129 _writefield(AES_WRITEKEY0_REG, op->key); 100 _writefield(AES_WRITEKEY0_REG, op->key);
130 } 101 }
131 102
132 do_crypt(op->src, op->dst, op->len, flags); 103 ret = do_crypt(op->src, op->dst, op->len, flags);
104 BUG_ON(ret);
133 105
134 if (op->mode == AES_MODE_CBC) 106 if (op->mode == AES_MODE_CBC)
135 _readfield(AES_WRITEIV0_REG, op->iv); 107 _readfield(AES_WRITEIV0_REG, op->iv);
@@ -141,18 +113,103 @@ geode_aes_crypt(struct geode_aes_op *op)
141 113
142/* CRYPTO-API Functions */ 114/* CRYPTO-API Functions */
143 115
144static int 116static int geode_setkey_cip(struct crypto_tfm *tfm, const u8 *key,
145geode_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int len) 117 unsigned int len)
146{ 118{
147 struct geode_aes_op *op = crypto_tfm_ctx(tfm); 119 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
120 unsigned int ret;
148 121
149 if (len != AES_KEY_LENGTH) { 122 op->keylen = len;
123
124 if (len == AES_KEYSIZE_128) {
125 memcpy(op->key, key, len);
126 return 0;
127 }
128
129 if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256) {
130 /* not supported at all */
150 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 131 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
151 return -EINVAL; 132 return -EINVAL;
152 } 133 }
153 134
154 memcpy(op->key, key, len); 135 /*
155 return 0; 136 * The requested key size is not supported by HW, do a fallback
137 */
138 op->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK;
139 op->fallback.blk->base.crt_flags |= (tfm->crt_flags & CRYPTO_TFM_REQ_MASK);
140
141 ret = crypto_cipher_setkey(op->fallback.cip, key, len);
142 if (ret) {
143 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
144 tfm->crt_flags |= (op->fallback.blk->base.crt_flags & CRYPTO_TFM_RES_MASK);
145 }
146 return ret;
147}
148
149static int geode_setkey_blk(struct crypto_tfm *tfm, const u8 *key,
150 unsigned int len)
151{
152 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
153 unsigned int ret;
154
155 op->keylen = len;
156
157 if (len == AES_KEYSIZE_128) {
158 memcpy(op->key, key, len);
159 return 0;
160 }
161
162 if (len != AES_KEYSIZE_192 && len != AES_KEYSIZE_256) {
163 /* not supported at all */
164 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
165 return -EINVAL;
166 }
167
168 /*
169 * The requested key size is not supported by HW, do a fallback
170 */
171 op->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK;
172 op->fallback.blk->base.crt_flags |= (tfm->crt_flags & CRYPTO_TFM_REQ_MASK);
173
174 ret = crypto_blkcipher_setkey(op->fallback.blk, key, len);
175 if (ret) {
176 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
177 tfm->crt_flags |= (op->fallback.blk->base.crt_flags & CRYPTO_TFM_RES_MASK);
178 }
179 return ret;
180}
181
182static int fallback_blk_dec(struct blkcipher_desc *desc,
183 struct scatterlist *dst, struct scatterlist *src,
184 unsigned int nbytes)
185{
186 unsigned int ret;
187 struct crypto_blkcipher *tfm;
188 struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
189
190 tfm = desc->tfm;
191 desc->tfm = op->fallback.blk;
192
193 ret = crypto_blkcipher_decrypt_iv(desc, dst, src, nbytes);
194
195 desc->tfm = tfm;
196 return ret;
197}
198static int fallback_blk_enc(struct blkcipher_desc *desc,
199 struct scatterlist *dst, struct scatterlist *src,
200 unsigned int nbytes)
201{
202 unsigned int ret;
203 struct crypto_blkcipher *tfm;
204 struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm);
205
206 tfm = desc->tfm;
207 desc->tfm = op->fallback.blk;
208
209 ret = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes);
210
211 desc->tfm = tfm;
212 return ret;
156} 213}
157 214
158static void 215static void
@@ -160,8 +217,10 @@ geode_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
160{ 217{
161 struct geode_aes_op *op = crypto_tfm_ctx(tfm); 218 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
162 219
163 if ((out == NULL) || (in == NULL)) 220 if (unlikely(op->keylen != AES_KEYSIZE_128)) {
221 crypto_cipher_encrypt_one(op->fallback.cip, out, in);
164 return; 222 return;
223 }
165 224
166 op->src = (void *) in; 225 op->src = (void *) in;
167 op->dst = (void *) out; 226 op->dst = (void *) out;
@@ -179,8 +238,10 @@ geode_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
179{ 238{
180 struct geode_aes_op *op = crypto_tfm_ctx(tfm); 239 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
181 240
182 if ((out == NULL) || (in == NULL)) 241 if (unlikely(op->keylen != AES_KEYSIZE_128)) {
242 crypto_cipher_decrypt_one(op->fallback.cip, out, in);
183 return; 243 return;
244 }
184 245
185 op->src = (void *) in; 246 op->src = (void *) in;
186 op->dst = (void *) out; 247 op->dst = (void *) out;
@@ -192,24 +253,50 @@ geode_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
192 geode_aes_crypt(op); 253 geode_aes_crypt(op);
193} 254}
194 255
256static int fallback_init_cip(struct crypto_tfm *tfm)
257{
258 const char *name = tfm->__crt_alg->cra_name;
259 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
260
261 op->fallback.cip = crypto_alloc_cipher(name, 0,
262 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
263
264 if (IS_ERR(op->fallback.cip)) {
265 printk(KERN_ERR "Error allocating fallback algo %s\n", name);
266 return PTR_ERR(op->fallback.blk);
267 }
268
269 return 0;
270}
271
272static void fallback_exit_cip(struct crypto_tfm *tfm)
273{
274 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
275
276 crypto_free_cipher(op->fallback.cip);
277 op->fallback.cip = NULL;
278}
195 279
196static struct crypto_alg geode_alg = { 280static struct crypto_alg geode_alg = {
197 .cra_name = "aes", 281 .cra_name = "aes",
198 .cra_driver_name = "geode-aes-128", 282 .cra_driver_name = "geode-aes",
199 .cra_priority = 300, 283 .cra_priority = 300,
200 .cra_alignmask = 15, 284 .cra_alignmask = 15,
201 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 285 .cra_flags = CRYPTO_ALG_TYPE_CIPHER |
286 CRYPTO_ALG_NEED_FALLBACK,
287 .cra_init = fallback_init_cip,
288 .cra_exit = fallback_exit_cip,
202 .cra_blocksize = AES_MIN_BLOCK_SIZE, 289 .cra_blocksize = AES_MIN_BLOCK_SIZE,
203 .cra_ctxsize = sizeof(struct geode_aes_op), 290 .cra_ctxsize = sizeof(struct geode_aes_op),
204 .cra_module = THIS_MODULE, 291 .cra_module = THIS_MODULE,
205 .cra_list = LIST_HEAD_INIT(geode_alg.cra_list), 292 .cra_list = LIST_HEAD_INIT(geode_alg.cra_list),
206 .cra_u = { 293 .cra_u = {
207 .cipher = { 294 .cipher = {
208 .cia_min_keysize = AES_KEY_LENGTH, 295 .cia_min_keysize = AES_MIN_KEY_SIZE,
209 .cia_max_keysize = AES_KEY_LENGTH, 296 .cia_max_keysize = AES_MAX_KEY_SIZE,
210 .cia_setkey = geode_setkey, 297 .cia_setkey = geode_setkey_cip,
211 .cia_encrypt = geode_encrypt, 298 .cia_encrypt = geode_encrypt,
212 .cia_decrypt = geode_decrypt 299 .cia_decrypt = geode_decrypt
213 } 300 }
214 } 301 }
215}; 302};
@@ -223,8 +310,12 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
223 struct blkcipher_walk walk; 310 struct blkcipher_walk walk;
224 int err, ret; 311 int err, ret;
225 312
313 if (unlikely(op->keylen != AES_KEYSIZE_128))
314 return fallback_blk_dec(desc, dst, src, nbytes);
315
226 blkcipher_walk_init(&walk, dst, src, nbytes); 316 blkcipher_walk_init(&walk, dst, src, nbytes);
227 err = blkcipher_walk_virt(desc, &walk); 317 err = blkcipher_walk_virt(desc, &walk);
318 op->iv = walk.iv;
228 319
229 while((nbytes = walk.nbytes)) { 320 while((nbytes = walk.nbytes)) {
230 op->src = walk.src.virt.addr, 321 op->src = walk.src.virt.addr,
@@ -233,13 +324,9 @@ geode_cbc_decrypt(struct blkcipher_desc *desc,
233 op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE); 324 op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE);
234 op->dir = AES_DIR_DECRYPT; 325 op->dir = AES_DIR_DECRYPT;
235 326
236 memcpy(op->iv, walk.iv, AES_IV_LENGTH);
237
238 ret = geode_aes_crypt(op); 327 ret = geode_aes_crypt(op);
239 328
240 memcpy(walk.iv, op->iv, AES_IV_LENGTH);
241 nbytes -= ret; 329 nbytes -= ret;
242
243 err = blkcipher_walk_done(desc, &walk, nbytes); 330 err = blkcipher_walk_done(desc, &walk, nbytes);
244 } 331 }
245 332
@@ -255,8 +342,12 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
255 struct blkcipher_walk walk; 342 struct blkcipher_walk walk;
256 int err, ret; 343 int err, ret;
257 344
345 if (unlikely(op->keylen != AES_KEYSIZE_128))
346 return fallback_blk_enc(desc, dst, src, nbytes);
347
258 blkcipher_walk_init(&walk, dst, src, nbytes); 348 blkcipher_walk_init(&walk, dst, src, nbytes);
259 err = blkcipher_walk_virt(desc, &walk); 349 err = blkcipher_walk_virt(desc, &walk);
350 op->iv = walk.iv;
260 351
261 while((nbytes = walk.nbytes)) { 352 while((nbytes = walk.nbytes)) {
262 op->src = walk.src.virt.addr, 353 op->src = walk.src.virt.addr,
@@ -265,8 +356,6 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
265 op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE); 356 op->len = nbytes - (nbytes % AES_MIN_BLOCK_SIZE);
266 op->dir = AES_DIR_ENCRYPT; 357 op->dir = AES_DIR_ENCRYPT;
267 358
268 memcpy(op->iv, walk.iv, AES_IV_LENGTH);
269
270 ret = geode_aes_crypt(op); 359 ret = geode_aes_crypt(op);
271 nbytes -= ret; 360 nbytes -= ret;
272 err = blkcipher_walk_done(desc, &walk, nbytes); 361 err = blkcipher_walk_done(desc, &walk, nbytes);
@@ -275,22 +364,49 @@ geode_cbc_encrypt(struct blkcipher_desc *desc,
275 return err; 364 return err;
276} 365}
277 366
367static int fallback_init_blk(struct crypto_tfm *tfm)
368{
369 const char *name = tfm->__crt_alg->cra_name;
370 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
371
372 op->fallback.blk = crypto_alloc_blkcipher(name, 0,
373 CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK);
374
375 if (IS_ERR(op->fallback.blk)) {
376 printk(KERN_ERR "Error allocating fallback algo %s\n", name);
377 return PTR_ERR(op->fallback.blk);
378 }
379
380 return 0;
381}
382
383static void fallback_exit_blk(struct crypto_tfm *tfm)
384{
385 struct geode_aes_op *op = crypto_tfm_ctx(tfm);
386
387 crypto_free_blkcipher(op->fallback.blk);
388 op->fallback.blk = NULL;
389}
390
278static struct crypto_alg geode_cbc_alg = { 391static struct crypto_alg geode_cbc_alg = {
279 .cra_name = "cbc(aes)", 392 .cra_name = "cbc(aes)",
280 .cra_driver_name = "cbc-aes-geode-128", 393 .cra_driver_name = "cbc-aes-geode",
281 .cra_priority = 400, 394 .cra_priority = 400,
282 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 395 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
396 CRYPTO_ALG_NEED_FALLBACK,
397 .cra_init = fallback_init_blk,
398 .cra_exit = fallback_exit_blk,
283 .cra_blocksize = AES_MIN_BLOCK_SIZE, 399 .cra_blocksize = AES_MIN_BLOCK_SIZE,
284 .cra_ctxsize = sizeof(struct geode_aes_op), 400 .cra_ctxsize = sizeof(struct geode_aes_op),
285 .cra_alignmask = 15, 401 .cra_alignmask = 15,
286 .cra_type = &crypto_blkcipher_type, 402 .cra_type = &crypto_blkcipher_type,
287 .cra_module = THIS_MODULE, 403 .cra_module = THIS_MODULE,
288 .cra_list = LIST_HEAD_INIT(geode_cbc_alg.cra_list), 404 .cra_list = LIST_HEAD_INIT(geode_cbc_alg.cra_list),
289 .cra_u = { 405 .cra_u = {
290 .blkcipher = { 406 .blkcipher = {
291 .min_keysize = AES_KEY_LENGTH, 407 .min_keysize = AES_MIN_KEY_SIZE,
292 .max_keysize = AES_KEY_LENGTH, 408 .max_keysize = AES_MAX_KEY_SIZE,
293 .setkey = geode_setkey, 409 .setkey = geode_setkey_blk,
294 .encrypt = geode_cbc_encrypt, 410 .encrypt = geode_cbc_encrypt,
295 .decrypt = geode_cbc_decrypt, 411 .decrypt = geode_cbc_decrypt,
296 .ivsize = AES_IV_LENGTH, 412 .ivsize = AES_IV_LENGTH,
@@ -307,6 +423,9 @@ geode_ecb_decrypt(struct blkcipher_desc *desc,
307 struct blkcipher_walk walk; 423 struct blkcipher_walk walk;
308 int err, ret; 424 int err, ret;
309 425
426 if (unlikely(op->keylen != AES_KEYSIZE_128))
427 return fallback_blk_dec(desc, dst, src, nbytes);
428
310 blkcipher_walk_init(&walk, dst, src, nbytes); 429 blkcipher_walk_init(&walk, dst, src, nbytes);
311 err = blkcipher_walk_virt(desc, &walk); 430 err = blkcipher_walk_virt(desc, &walk);
312 431
@@ -334,6 +453,9 @@ geode_ecb_encrypt(struct blkcipher_desc *desc,
334 struct blkcipher_walk walk; 453 struct blkcipher_walk walk;
335 int err, ret; 454 int err, ret;
336 455
456 if (unlikely(op->keylen != AES_KEYSIZE_128))
457 return fallback_blk_enc(desc, dst, src, nbytes);
458
337 blkcipher_walk_init(&walk, dst, src, nbytes); 459 blkcipher_walk_init(&walk, dst, src, nbytes);
338 err = blkcipher_walk_virt(desc, &walk); 460 err = blkcipher_walk_virt(desc, &walk);
339 461
@@ -353,28 +475,31 @@ geode_ecb_encrypt(struct blkcipher_desc *desc,
353} 475}
354 476
355static struct crypto_alg geode_ecb_alg = { 477static struct crypto_alg geode_ecb_alg = {
356 .cra_name = "ecb(aes)", 478 .cra_name = "ecb(aes)",
357 .cra_driver_name = "ecb-aes-geode-128", 479 .cra_driver_name = "ecb-aes-geode",
358 .cra_priority = 400, 480 .cra_priority = 400,
359 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, 481 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER |
482 CRYPTO_ALG_NEED_FALLBACK,
483 .cra_init = fallback_init_blk,
484 .cra_exit = fallback_exit_blk,
360 .cra_blocksize = AES_MIN_BLOCK_SIZE, 485 .cra_blocksize = AES_MIN_BLOCK_SIZE,
361 .cra_ctxsize = sizeof(struct geode_aes_op), 486 .cra_ctxsize = sizeof(struct geode_aes_op),
362 .cra_alignmask = 15, 487 .cra_alignmask = 15,
363 .cra_type = &crypto_blkcipher_type, 488 .cra_type = &crypto_blkcipher_type,
364 .cra_module = THIS_MODULE, 489 .cra_module = THIS_MODULE,
365 .cra_list = LIST_HEAD_INIT(geode_ecb_alg.cra_list), 490 .cra_list = LIST_HEAD_INIT(geode_ecb_alg.cra_list),
366 .cra_u = { 491 .cra_u = {
367 .blkcipher = { 492 .blkcipher = {
368 .min_keysize = AES_KEY_LENGTH, 493 .min_keysize = AES_MIN_KEY_SIZE,
369 .max_keysize = AES_KEY_LENGTH, 494 .max_keysize = AES_MAX_KEY_SIZE,
370 .setkey = geode_setkey, 495 .setkey = geode_setkey_blk,
371 .encrypt = geode_ecb_encrypt, 496 .encrypt = geode_ecb_encrypt,
372 .decrypt = geode_ecb_decrypt, 497 .decrypt = geode_ecb_decrypt,
373 } 498 }
374 } 499 }
375}; 500};
376 501
377static void 502static void __devexit
378geode_aes_remove(struct pci_dev *dev) 503geode_aes_remove(struct pci_dev *dev)
379{ 504{
380 crypto_unregister_alg(&geode_alg); 505 crypto_unregister_alg(&geode_alg);
@@ -389,7 +514,7 @@ geode_aes_remove(struct pci_dev *dev)
389} 514}
390 515
391 516
392static int 517static int __devinit
393geode_aes_probe(struct pci_dev *dev, const struct pci_device_id *id) 518geode_aes_probe(struct pci_dev *dev, const struct pci_device_id *id)
394{ 519{
395 int ret; 520 int ret;
@@ -397,7 +522,7 @@ geode_aes_probe(struct pci_dev *dev, const struct pci_device_id *id)
397 if ((ret = pci_enable_device(dev))) 522 if ((ret = pci_enable_device(dev)))
398 return ret; 523 return ret;
399 524
400 if ((ret = pci_request_regions(dev, "geode-aes-128"))) 525 if ((ret = pci_request_regions(dev, "geode-aes")))
401 goto eenable; 526 goto eenable;
402 527
403 _iobase = pci_iomap(dev, 0, 0); 528 _iobase = pci_iomap(dev, 0, 0);
@@ -472,7 +597,6 @@ geode_aes_exit(void)
472MODULE_AUTHOR("Advanced Micro Devices, Inc."); 597MODULE_AUTHOR("Advanced Micro Devices, Inc.");
473MODULE_DESCRIPTION("Geode LX Hardware AES driver"); 598MODULE_DESCRIPTION("Geode LX Hardware AES driver");
474MODULE_LICENSE("GPL"); 599MODULE_LICENSE("GPL");
475MODULE_ALIAS("aes");
476 600
477module_init(geode_aes_init); 601module_init(geode_aes_init);
478module_exit(geode_aes_exit); 602module_exit(geode_aes_exit);
diff --git a/drivers/crypto/geode-aes.h b/drivers/crypto/geode-aes.h
index f47968671ae7..f1855b50da48 100644
--- a/drivers/crypto/geode-aes.h
+++ b/drivers/crypto/geode-aes.h
@@ -9,9 +9,9 @@
9#ifndef _GEODE_AES_H_ 9#ifndef _GEODE_AES_H_
10#define _GEODE_AES_H_ 10#define _GEODE_AES_H_
11 11
12#define AES_KEY_LENGTH 16 12/* driver logic flags */
13#define AES_IV_LENGTH 16 13#define AES_IV_LENGTH 16
14 14#define AES_KEY_LENGTH 16
15#define AES_MIN_BLOCK_SIZE 16 15#define AES_MIN_BLOCK_SIZE 16
16 16
17#define AES_MODE_ECB 0 17#define AES_MODE_ECB 0
@@ -22,6 +22,38 @@
22 22
23#define AES_FLAGS_HIDDENKEY (1 << 0) 23#define AES_FLAGS_HIDDENKEY (1 << 0)
24 24
25/* Register definitions */
26
27#define AES_CTRLA_REG 0x0000
28
29#define AES_CTRL_START 0x01
30#define AES_CTRL_DECRYPT 0x00
31#define AES_CTRL_ENCRYPT 0x02
32#define AES_CTRL_WRKEY 0x04
33#define AES_CTRL_DCA 0x08
34#define AES_CTRL_SCA 0x10
35#define AES_CTRL_CBC 0x20
36
37#define AES_INTR_REG 0x0008
38
39#define AES_INTRA_PENDING (1 << 16)
40#define AES_INTRB_PENDING (1 << 17)
41
42#define AES_INTR_PENDING (AES_INTRA_PENDING | AES_INTRB_PENDING)
43#define AES_INTR_MASK 0x07
44
45#define AES_SOURCEA_REG 0x0010
46#define AES_DSTA_REG 0x0014
47#define AES_LENA_REG 0x0018
48#define AES_WRITEKEY0_REG 0x0030
49#define AES_WRITEIV0_REG 0x0040
50
51/* A very large counter that is used to gracefully bail out of an
52 * operation in case of trouble
53 */
54
55#define AES_OP_TIMEOUT 0x50000
56
25struct geode_aes_op { 57struct geode_aes_op {
26 58
27 void *src; 59 void *src;
@@ -33,7 +65,13 @@ struct geode_aes_op {
33 int len; 65 int len;
34 66
35 u8 key[AES_KEY_LENGTH]; 67 u8 key[AES_KEY_LENGTH];
36 u8 iv[AES_IV_LENGTH]; 68 u8 *iv;
69
70 union {
71 struct crypto_blkcipher *blk;
72 struct crypto_cipher *cip;
73 } fallback;
74 u32 keylen;
37}; 75};
38 76
39#endif 77#endif
diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
new file mode 100644
index 000000000000..16413e57597c
--- /dev/null
+++ b/drivers/crypto/hifn_795x.c
@@ -0,0 +1,2838 @@
1/*
2 * 2007+ Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/mod_devicetable.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include <linux/mm.h>
29#include <linux/dma-mapping.h>
30#include <linux/scatterlist.h>
31#include <linux/highmem.h>
32#include <linux/interrupt.h>
33#include <linux/crypto.h>
34#include <linux/hw_random.h>
35#include <linux/ktime.h>
36
37#include <crypto/algapi.h>
38#include <crypto/des.h>
39
40#include <asm/kmap_types.h>
41
42#undef dprintk
43
44#define HIFN_TEST
45//#define HIFN_DEBUG
46
47#ifdef HIFN_DEBUG
48#define dprintk(f, a...) printk(f, ##a)
49#else
50#define dprintk(f, a...) do {} while (0)
51#endif
52
53static char hifn_pll_ref[sizeof("extNNN")] = "ext";
54module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
55MODULE_PARM_DESC(hifn_pll_ref,
56 "PLL reference clock (pci[freq] or ext[freq], default ext)");
57
58static atomic_t hifn_dev_number;
59
60#define ACRYPTO_OP_DECRYPT 0
61#define ACRYPTO_OP_ENCRYPT 1
62#define ACRYPTO_OP_HMAC 2
63#define ACRYPTO_OP_RNG 3
64
65#define ACRYPTO_MODE_ECB 0
66#define ACRYPTO_MODE_CBC 1
67#define ACRYPTO_MODE_CFB 2
68#define ACRYPTO_MODE_OFB 3
69
70#define ACRYPTO_TYPE_AES_128 0
71#define ACRYPTO_TYPE_AES_192 1
72#define ACRYPTO_TYPE_AES_256 2
73#define ACRYPTO_TYPE_3DES 3
74#define ACRYPTO_TYPE_DES 4
75
76#define PCI_VENDOR_ID_HIFN 0x13A3
77#define PCI_DEVICE_ID_HIFN_7955 0x0020
78#define PCI_DEVICE_ID_HIFN_7956 0x001d
79
80/* I/O region sizes */
81
82#define HIFN_BAR0_SIZE 0x1000
83#define HIFN_BAR1_SIZE 0x2000
84#define HIFN_BAR2_SIZE 0x8000
85
86/* DMA registres */
87
88#define HIFN_DMA_CRA 0x0C /* DMA Command Ring Address */
89#define HIFN_DMA_SDRA 0x1C /* DMA Source Data Ring Address */
90#define HIFN_DMA_RRA 0x2C /* DMA Result Ring Address */
91#define HIFN_DMA_DDRA 0x3C /* DMA Destination Data Ring Address */
92#define HIFN_DMA_STCTL 0x40 /* DMA Status and Control */
93#define HIFN_DMA_INTREN 0x44 /* DMA Interrupt Enable */
94#define HIFN_DMA_CFG1 0x48 /* DMA Configuration #1 */
95#define HIFN_DMA_CFG2 0x6C /* DMA Configuration #2 */
96#define HIFN_CHIP_ID 0x98 /* Chip ID */
97
98/*
99 * Processing Unit Registers (offset from BASEREG0)
100 */
101#define HIFN_0_PUDATA 0x00 /* Processing Unit Data */
102#define HIFN_0_PUCTRL 0x04 /* Processing Unit Control */
103#define HIFN_0_PUISR 0x08 /* Processing Unit Interrupt Status */
104#define HIFN_0_PUCNFG 0x0c /* Processing Unit Configuration */
105#define HIFN_0_PUIER 0x10 /* Processing Unit Interrupt Enable */
106#define HIFN_0_PUSTAT 0x14 /* Processing Unit Status/Chip ID */
107#define HIFN_0_FIFOSTAT 0x18 /* FIFO Status */
108#define HIFN_0_FIFOCNFG 0x1c /* FIFO Configuration */
109#define HIFN_0_SPACESIZE 0x20 /* Register space size */
110
111/* Processing Unit Control Register (HIFN_0_PUCTRL) */
112#define HIFN_PUCTRL_CLRSRCFIFO 0x0010 /* clear source fifo */
113#define HIFN_PUCTRL_STOP 0x0008 /* stop pu */
114#define HIFN_PUCTRL_LOCKRAM 0x0004 /* lock ram */
115#define HIFN_PUCTRL_DMAENA 0x0002 /* enable dma */
116#define HIFN_PUCTRL_RESET 0x0001 /* Reset processing unit */
117
118/* Processing Unit Interrupt Status Register (HIFN_0_PUISR) */
119#define HIFN_PUISR_CMDINVAL 0x8000 /* Invalid command interrupt */
120#define HIFN_PUISR_DATAERR 0x4000 /* Data error interrupt */
121#define HIFN_PUISR_SRCFIFO 0x2000 /* Source FIFO ready interrupt */
122#define HIFN_PUISR_DSTFIFO 0x1000 /* Destination FIFO ready interrupt */
123#define HIFN_PUISR_DSTOVER 0x0200 /* Destination overrun interrupt */
124#define HIFN_PUISR_SRCCMD 0x0080 /* Source command interrupt */
125#define HIFN_PUISR_SRCCTX 0x0040 /* Source context interrupt */
126#define HIFN_PUISR_SRCDATA 0x0020 /* Source data interrupt */
127#define HIFN_PUISR_DSTDATA 0x0010 /* Destination data interrupt */
128#define HIFN_PUISR_DSTRESULT 0x0004 /* Destination result interrupt */
129
130/* Processing Unit Configuration Register (HIFN_0_PUCNFG) */
131#define HIFN_PUCNFG_DRAMMASK 0xe000 /* DRAM size mask */
132#define HIFN_PUCNFG_DSZ_256K 0x0000 /* 256k dram */
133#define HIFN_PUCNFG_DSZ_512K 0x2000 /* 512k dram */
134#define HIFN_PUCNFG_DSZ_1M 0x4000 /* 1m dram */
135#define HIFN_PUCNFG_DSZ_2M 0x6000 /* 2m dram */
136#define HIFN_PUCNFG_DSZ_4M 0x8000 /* 4m dram */
137#define HIFN_PUCNFG_DSZ_8M 0xa000 /* 8m dram */
138#define HIFN_PUNCFG_DSZ_16M 0xc000 /* 16m dram */
139#define HIFN_PUCNFG_DSZ_32M 0xe000 /* 32m dram */
140#define HIFN_PUCNFG_DRAMREFRESH 0x1800 /* DRAM refresh rate mask */
141#define HIFN_PUCNFG_DRFR_512 0x0000 /* 512 divisor of ECLK */
142#define HIFN_PUCNFG_DRFR_256 0x0800 /* 256 divisor of ECLK */
143#define HIFN_PUCNFG_DRFR_128 0x1000 /* 128 divisor of ECLK */
144#define HIFN_PUCNFG_TCALLPHASES 0x0200 /* your guess is as good as mine... */
145#define HIFN_PUCNFG_TCDRVTOTEM 0x0100 /* your guess is as good as mine... */
146#define HIFN_PUCNFG_BIGENDIAN 0x0080 /* DMA big endian mode */
147#define HIFN_PUCNFG_BUS32 0x0040 /* Bus width 32bits */
148#define HIFN_PUCNFG_BUS16 0x0000 /* Bus width 16 bits */
149#define HIFN_PUCNFG_CHIPID 0x0020 /* Allow chipid from PUSTAT */
150#define HIFN_PUCNFG_DRAM 0x0010 /* Context RAM is DRAM */
151#define HIFN_PUCNFG_SRAM 0x0000 /* Context RAM is SRAM */
152#define HIFN_PUCNFG_COMPSING 0x0004 /* Enable single compression context */
153#define HIFN_PUCNFG_ENCCNFG 0x0002 /* Encryption configuration */
154
155/* Processing Unit Interrupt Enable Register (HIFN_0_PUIER) */
156#define HIFN_PUIER_CMDINVAL 0x8000 /* Invalid command interrupt */
157#define HIFN_PUIER_DATAERR 0x4000 /* Data error interrupt */
158#define HIFN_PUIER_SRCFIFO 0x2000 /* Source FIFO ready interrupt */
159#define HIFN_PUIER_DSTFIFO 0x1000 /* Destination FIFO ready interrupt */
160#define HIFN_PUIER_DSTOVER 0x0200 /* Destination overrun interrupt */
161#define HIFN_PUIER_SRCCMD 0x0080 /* Source command interrupt */
162#define HIFN_PUIER_SRCCTX 0x0040 /* Source context interrupt */
163#define HIFN_PUIER_SRCDATA 0x0020 /* Source data interrupt */
164#define HIFN_PUIER_DSTDATA 0x0010 /* Destination data interrupt */
165#define HIFN_PUIER_DSTRESULT 0x0004 /* Destination result interrupt */
166
167/* Processing Unit Status Register/Chip ID (HIFN_0_PUSTAT) */
168#define HIFN_PUSTAT_CMDINVAL 0x8000 /* Invalid command interrupt */
169#define HIFN_PUSTAT_DATAERR 0x4000 /* Data error interrupt */
170#define HIFN_PUSTAT_SRCFIFO 0x2000 /* Source FIFO ready interrupt */
171#define HIFN_PUSTAT_DSTFIFO 0x1000 /* Destination FIFO ready interrupt */
172#define HIFN_PUSTAT_DSTOVER 0x0200 /* Destination overrun interrupt */
173#define HIFN_PUSTAT_SRCCMD 0x0080 /* Source command interrupt */
174#define HIFN_PUSTAT_SRCCTX 0x0040 /* Source context interrupt */
175#define HIFN_PUSTAT_SRCDATA 0x0020 /* Source data interrupt */
176#define HIFN_PUSTAT_DSTDATA 0x0010 /* Destination data interrupt */
177#define HIFN_PUSTAT_DSTRESULT 0x0004 /* Destination result interrupt */
178#define HIFN_PUSTAT_CHIPREV 0x00ff /* Chip revision mask */
179#define HIFN_PUSTAT_CHIPENA 0xff00 /* Chip enabled mask */
180#define HIFN_PUSTAT_ENA_2 0x1100 /* Level 2 enabled */
181#define HIFN_PUSTAT_ENA_1 0x1000 /* Level 1 enabled */
182#define HIFN_PUSTAT_ENA_0 0x3000 /* Level 0 enabled */
183#define HIFN_PUSTAT_REV_2 0x0020 /* 7751 PT6/2 */
184#define HIFN_PUSTAT_REV_3 0x0030 /* 7751 PT6/3 */
185
186/* FIFO Status Register (HIFN_0_FIFOSTAT) */
187#define HIFN_FIFOSTAT_SRC 0x7f00 /* Source FIFO available */
188#define HIFN_FIFOSTAT_DST 0x007f /* Destination FIFO available */
189
190/* FIFO Configuration Register (HIFN_0_FIFOCNFG) */
191#define HIFN_FIFOCNFG_THRESHOLD 0x0400 /* must be written as 1 */
192
193/*
194 * DMA Interface Registers (offset from BASEREG1)
195 */
196#define HIFN_1_DMA_CRAR 0x0c /* DMA Command Ring Address */
197#define HIFN_1_DMA_SRAR 0x1c /* DMA Source Ring Address */
198#define HIFN_1_DMA_RRAR 0x2c /* DMA Result Ring Address */
199#define HIFN_1_DMA_DRAR 0x3c /* DMA Destination Ring Address */
200#define HIFN_1_DMA_CSR 0x40 /* DMA Status and Control */
201#define HIFN_1_DMA_IER 0x44 /* DMA Interrupt Enable */
202#define HIFN_1_DMA_CNFG 0x48 /* DMA Configuration */
203#define HIFN_1_PLL 0x4c /* 795x: PLL config */
204#define HIFN_1_7811_RNGENA 0x60 /* 7811: rng enable */
205#define HIFN_1_7811_RNGCFG 0x64 /* 7811: rng config */
206#define HIFN_1_7811_RNGDAT 0x68 /* 7811: rng data */
207#define HIFN_1_7811_RNGSTS 0x6c /* 7811: rng status */
208#define HIFN_1_7811_MIPSRST 0x94 /* 7811: MIPS reset */
209#define HIFN_1_REVID 0x98 /* Revision ID */
210#define HIFN_1_UNLOCK_SECRET1 0xf4
211#define HIFN_1_UNLOCK_SECRET2 0xfc
212#define HIFN_1_PUB_RESET 0x204 /* Public/RNG Reset */
213#define HIFN_1_PUB_BASE 0x300 /* Public Base Address */
214#define HIFN_1_PUB_OPLEN 0x304 /* Public Operand Length */
215#define HIFN_1_PUB_OP 0x308 /* Public Operand */
216#define HIFN_1_PUB_STATUS 0x30c /* Public Status */
217#define HIFN_1_PUB_IEN 0x310 /* Public Interrupt enable */
218#define HIFN_1_RNG_CONFIG 0x314 /* RNG config */
219#define HIFN_1_RNG_DATA 0x318 /* RNG data */
220#define HIFN_1_PUB_MEM 0x400 /* start of Public key memory */
221#define HIFN_1_PUB_MEMEND 0xbff /* end of Public key memory */
222
223/* DMA Status and Control Register (HIFN_1_DMA_CSR) */
224#define HIFN_DMACSR_D_CTRLMASK 0xc0000000 /* Destinition Ring Control */
225#define HIFN_DMACSR_D_CTRL_NOP 0x00000000 /* Dest. Control: no-op */
226#define HIFN_DMACSR_D_CTRL_DIS 0x40000000 /* Dest. Control: disable */
227#define HIFN_DMACSR_D_CTRL_ENA 0x80000000 /* Dest. Control: enable */
228#define HIFN_DMACSR_D_ABORT 0x20000000 /* Destinition Ring PCIAbort */
229#define HIFN_DMACSR_D_DONE 0x10000000 /* Destinition Ring Done */
230#define HIFN_DMACSR_D_LAST 0x08000000 /* Destinition Ring Last */
231#define HIFN_DMACSR_D_WAIT 0x04000000 /* Destinition Ring Waiting */
232#define HIFN_DMACSR_D_OVER 0x02000000 /* Destinition Ring Overflow */
233#define HIFN_DMACSR_R_CTRL 0x00c00000 /* Result Ring Control */
234#define HIFN_DMACSR_R_CTRL_NOP 0x00000000 /* Result Control: no-op */
235#define HIFN_DMACSR_R_CTRL_DIS 0x00400000 /* Result Control: disable */
236#define HIFN_DMACSR_R_CTRL_ENA 0x00800000 /* Result Control: enable */
237#define HIFN_DMACSR_R_ABORT 0x00200000 /* Result Ring PCI Abort */
238#define HIFN_DMACSR_R_DONE 0x00100000 /* Result Ring Done */
239#define HIFN_DMACSR_R_LAST 0x00080000 /* Result Ring Last */
240#define HIFN_DMACSR_R_WAIT 0x00040000 /* Result Ring Waiting */
241#define HIFN_DMACSR_R_OVER 0x00020000 /* Result Ring Overflow */
242#define HIFN_DMACSR_S_CTRL 0x0000c000 /* Source Ring Control */
243#define HIFN_DMACSR_S_CTRL_NOP 0x00000000 /* Source Control: no-op */
244#define HIFN_DMACSR_S_CTRL_DIS 0x00004000 /* Source Control: disable */
245#define HIFN_DMACSR_S_CTRL_ENA 0x00008000 /* Source Control: enable */
246#define HIFN_DMACSR_S_ABORT 0x00002000 /* Source Ring PCI Abort */
247#define HIFN_DMACSR_S_DONE 0x00001000 /* Source Ring Done */
248#define HIFN_DMACSR_S_LAST 0x00000800 /* Source Ring Last */
249#define HIFN_DMACSR_S_WAIT 0x00000400 /* Source Ring Waiting */
250#define HIFN_DMACSR_ILLW 0x00000200 /* Illegal write (7811 only) */
251#define HIFN_DMACSR_ILLR 0x00000100 /* Illegal read (7811 only) */
252#define HIFN_DMACSR_C_CTRL 0x000000c0 /* Command Ring Control */
253#define HIFN_DMACSR_C_CTRL_NOP 0x00000000 /* Command Control: no-op */
254#define HIFN_DMACSR_C_CTRL_DIS 0x00000040 /* Command Control: disable */
255#define HIFN_DMACSR_C_CTRL_ENA 0x00000080 /* Command Control: enable */
256#define HIFN_DMACSR_C_ABORT 0x00000020 /* Command Ring PCI Abort */
257#define HIFN_DMACSR_C_DONE 0x00000010 /* Command Ring Done */
258#define HIFN_DMACSR_C_LAST 0x00000008 /* Command Ring Last */
259#define HIFN_DMACSR_C_WAIT 0x00000004 /* Command Ring Waiting */
260#define HIFN_DMACSR_PUBDONE 0x00000002 /* Public op done (7951 only) */
261#define HIFN_DMACSR_ENGINE 0x00000001 /* Command Ring Engine IRQ */
262
263/* DMA Interrupt Enable Register (HIFN_1_DMA_IER) */
264#define HIFN_DMAIER_D_ABORT 0x20000000 /* Destination Ring PCIAbort */
265#define HIFN_DMAIER_D_DONE 0x10000000 /* Destination Ring Done */
266#define HIFN_DMAIER_D_LAST 0x08000000 /* Destination Ring Last */
267#define HIFN_DMAIER_D_WAIT 0x04000000 /* Destination Ring Waiting */
268#define HIFN_DMAIER_D_OVER 0x02000000 /* Destination Ring Overflow */
269#define HIFN_DMAIER_R_ABORT 0x00200000 /* Result Ring PCI Abort */
270#define HIFN_DMAIER_R_DONE 0x00100000 /* Result Ring Done */
271#define HIFN_DMAIER_R_LAST 0x00080000 /* Result Ring Last */
272#define HIFN_DMAIER_R_WAIT 0x00040000 /* Result Ring Waiting */
273#define HIFN_DMAIER_R_OVER 0x00020000 /* Result Ring Overflow */
274#define HIFN_DMAIER_S_ABORT 0x00002000 /* Source Ring PCI Abort */
275#define HIFN_DMAIER_S_DONE 0x00001000 /* Source Ring Done */
276#define HIFN_DMAIER_S_LAST 0x00000800 /* Source Ring Last */
277#define HIFN_DMAIER_S_WAIT 0x00000400 /* Source Ring Waiting */
278#define HIFN_DMAIER_ILLW 0x00000200 /* Illegal write (7811 only) */
279#define HIFN_DMAIER_ILLR 0x00000100 /* Illegal read (7811 only) */
280#define HIFN_DMAIER_C_ABORT 0x00000020 /* Command Ring PCI Abort */
281#define HIFN_DMAIER_C_DONE 0x00000010 /* Command Ring Done */
282#define HIFN_DMAIER_C_LAST 0x00000008 /* Command Ring Last */
283#define HIFN_DMAIER_C_WAIT 0x00000004 /* Command Ring Waiting */
284#define HIFN_DMAIER_PUBDONE 0x00000002 /* public op done (7951 only) */
285#define HIFN_DMAIER_ENGINE 0x00000001 /* Engine IRQ */
286
287/* DMA Configuration Register (HIFN_1_DMA_CNFG) */
288#define HIFN_DMACNFG_BIGENDIAN 0x10000000 /* big endian mode */
289#define HIFN_DMACNFG_POLLFREQ 0x00ff0000 /* Poll frequency mask */
290#define HIFN_DMACNFG_UNLOCK 0x00000800
291#define HIFN_DMACNFG_POLLINVAL 0x00000700 /* Invalid Poll Scalar */
292#define HIFN_DMACNFG_LAST 0x00000010 /* Host control LAST bit */
293#define HIFN_DMACNFG_MODE 0x00000004 /* DMA mode */
294#define HIFN_DMACNFG_DMARESET 0x00000002 /* DMA Reset # */
295#define HIFN_DMACNFG_MSTRESET 0x00000001 /* Master Reset # */
296
297/* PLL configuration register */
298#define HIFN_PLL_REF_CLK_HBI 0x00000000 /* HBI reference clock */
299#define HIFN_PLL_REF_CLK_PLL 0x00000001 /* PLL reference clock */
300#define HIFN_PLL_BP 0x00000002 /* Reference clock bypass */
301#define HIFN_PLL_PK_CLK_HBI 0x00000000 /* PK engine HBI clock */
302#define HIFN_PLL_PK_CLK_PLL 0x00000008 /* PK engine PLL clock */
303#define HIFN_PLL_PE_CLK_HBI 0x00000000 /* PE engine HBI clock */
304#define HIFN_PLL_PE_CLK_PLL 0x00000010 /* PE engine PLL clock */
305#define HIFN_PLL_RESERVED_1 0x00000400 /* Reserved bit, must be 1 */
306#define HIFN_PLL_ND_SHIFT 11 /* Clock multiplier shift */
307#define HIFN_PLL_ND_MULT_2 0x00000000 /* PLL clock multiplier 2 */
308#define HIFN_PLL_ND_MULT_4 0x00000800 /* PLL clock multiplier 4 */
309#define HIFN_PLL_ND_MULT_6 0x00001000 /* PLL clock multiplier 6 */
310#define HIFN_PLL_ND_MULT_8 0x00001800 /* PLL clock multiplier 8 */
311#define HIFN_PLL_ND_MULT_10 0x00002000 /* PLL clock multiplier 10 */
312#define HIFN_PLL_ND_MULT_12 0x00002800 /* PLL clock multiplier 12 */
313#define HIFN_PLL_IS_1_8 0x00000000 /* charge pump (mult. 1-8) */
314#define HIFN_PLL_IS_9_12 0x00010000 /* charge pump (mult. 9-12) */
315
316#define HIFN_PLL_FCK_MAX 266 /* Maximum PLL frequency */
317
318/* Public key reset register (HIFN_1_PUB_RESET) */
319#define HIFN_PUBRST_RESET 0x00000001 /* reset public/rng unit */
320
321/* Public base address register (HIFN_1_PUB_BASE) */
322#define HIFN_PUBBASE_ADDR 0x00003fff /* base address */
323
324/* Public operand length register (HIFN_1_PUB_OPLEN) */
325#define HIFN_PUBOPLEN_MOD_M 0x0000007f /* modulus length mask */
326#define HIFN_PUBOPLEN_MOD_S 0 /* modulus length shift */
327#define HIFN_PUBOPLEN_EXP_M 0x0003ff80 /* exponent length mask */
328#define HIFN_PUBOPLEN_EXP_S 7 /* exponent lenght shift */
329#define HIFN_PUBOPLEN_RED_M 0x003c0000 /* reducend length mask */
330#define HIFN_PUBOPLEN_RED_S 18 /* reducend length shift */
331
332/* Public operation register (HIFN_1_PUB_OP) */
333#define HIFN_PUBOP_AOFFSET_M 0x0000007f /* A offset mask */
334#define HIFN_PUBOP_AOFFSET_S 0 /* A offset shift */
335#define HIFN_PUBOP_BOFFSET_M 0x00000f80 /* B offset mask */
336#define HIFN_PUBOP_BOFFSET_S 7 /* B offset shift */
337#define HIFN_PUBOP_MOFFSET_M 0x0003f000 /* M offset mask */
338#define HIFN_PUBOP_MOFFSET_S 12 /* M offset shift */
339#define HIFN_PUBOP_OP_MASK 0x003c0000 /* Opcode: */
340#define HIFN_PUBOP_OP_NOP 0x00000000 /* NOP */
341#define HIFN_PUBOP_OP_ADD 0x00040000 /* ADD */
342#define HIFN_PUBOP_OP_ADDC 0x00080000 /* ADD w/carry */
343#define HIFN_PUBOP_OP_SUB 0x000c0000 /* SUB */
344#define HIFN_PUBOP_OP_SUBC 0x00100000 /* SUB w/carry */
345#define HIFN_PUBOP_OP_MODADD 0x00140000 /* Modular ADD */
346#define HIFN_PUBOP_OP_MODSUB 0x00180000 /* Modular SUB */
347#define HIFN_PUBOP_OP_INCA 0x001c0000 /* INC A */
348#define HIFN_PUBOP_OP_DECA 0x00200000 /* DEC A */
349#define HIFN_PUBOP_OP_MULT 0x00240000 /* MULT */
350#define HIFN_PUBOP_OP_MODMULT 0x00280000 /* Modular MULT */
351#define HIFN_PUBOP_OP_MODRED 0x002c0000 /* Modular RED */
352#define HIFN_PUBOP_OP_MODEXP 0x00300000 /* Modular EXP */
353
354/* Public status register (HIFN_1_PUB_STATUS) */
355#define HIFN_PUBSTS_DONE 0x00000001 /* operation done */
356#define HIFN_PUBSTS_CARRY 0x00000002 /* carry */
357
358/* Public interrupt enable register (HIFN_1_PUB_IEN) */
359#define HIFN_PUBIEN_DONE 0x00000001 /* operation done interrupt */
360
361/* Random number generator config register (HIFN_1_RNG_CONFIG) */
362#define HIFN_RNGCFG_ENA 0x00000001 /* enable rng */
363
364#define HIFN_NAMESIZE 32
365#define HIFN_MAX_RESULT_ORDER 5
366
367#define HIFN_D_CMD_RSIZE 24*4
368#define HIFN_D_SRC_RSIZE 80*4
369#define HIFN_D_DST_RSIZE 80*4
370#define HIFN_D_RES_RSIZE 24*4
371
372#define HIFN_QUEUE_LENGTH HIFN_D_CMD_RSIZE-5
373
374#define AES_MIN_KEY_SIZE 16
375#define AES_MAX_KEY_SIZE 32
376
377#define HIFN_DES_KEY_LENGTH 8
378#define HIFN_3DES_KEY_LENGTH 24
379#define HIFN_MAX_CRYPT_KEY_LENGTH AES_MAX_KEY_SIZE
380#define HIFN_IV_LENGTH 8
381#define HIFN_AES_IV_LENGTH 16
382#define HIFN_MAX_IV_LENGTH HIFN_AES_IV_LENGTH
383
384#define HIFN_MAC_KEY_LENGTH 64
385#define HIFN_MD5_LENGTH 16
386#define HIFN_SHA1_LENGTH 20
387#define HIFN_MAC_TRUNC_LENGTH 12
388
389#define HIFN_MAX_COMMAND (8 + 8 + 8 + 64 + 260)
390#define HIFN_MAX_RESULT (8 + 4 + 4 + 20 + 4)
391#define HIFN_USED_RESULT 12
392
393struct hifn_desc
394{
395 volatile u32 l;
396 volatile u32 p;
397};
398
399struct hifn_dma {
400 struct hifn_desc cmdr[HIFN_D_CMD_RSIZE+1];
401 struct hifn_desc srcr[HIFN_D_SRC_RSIZE+1];
402 struct hifn_desc dstr[HIFN_D_DST_RSIZE+1];
403 struct hifn_desc resr[HIFN_D_RES_RSIZE+1];
404
405 u8 command_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_COMMAND];
406 u8 result_bufs[HIFN_D_CMD_RSIZE][HIFN_MAX_RESULT];
407
408 u64 test_src, test_dst;
409
410 /*
411 * Our current positions for insertion and removal from the descriptor
412 * rings.
413 */
414 volatile int cmdi, srci, dsti, resi;
415 volatile int cmdu, srcu, dstu, resu;
416 int cmdk, srck, dstk, resk;
417};
418
419#define HIFN_FLAG_CMD_BUSY (1<<0)
420#define HIFN_FLAG_SRC_BUSY (1<<1)
421#define HIFN_FLAG_DST_BUSY (1<<2)
422#define HIFN_FLAG_RES_BUSY (1<<3)
423#define HIFN_FLAG_OLD_KEY (1<<4)
424
425#define HIFN_DEFAULT_ACTIVE_NUM 5
426
427struct hifn_device
428{
429 char name[HIFN_NAMESIZE];
430
431 int irq;
432
433 struct pci_dev *pdev;
434 void __iomem *bar[3];
435
436 unsigned long result_mem;
437 dma_addr_t dst;
438
439 void *desc_virt;
440 dma_addr_t desc_dma;
441
442 u32 dmareg;
443
444 void *sa[HIFN_D_RES_RSIZE];
445
446 spinlock_t lock;
447
448 void *priv;
449
450 u32 flags;
451 int active, started;
452 struct delayed_work work;
453 unsigned long reset;
454 unsigned long success;
455 unsigned long prev_success;
456
457 u8 snum;
458
459 struct tasklet_struct tasklet;
460
461 struct crypto_queue queue;
462 struct list_head alg_list;
463
464 unsigned int pk_clk_freq;
465
466#if defined(CONFIG_HW_RANDOM) || defined(CONFIG_HW_RANDOM_MODULE)
467 unsigned int rng_wait_time;
468 ktime_t rngtime;
469 struct hwrng rng;
470#endif
471};
472
473#define HIFN_D_LENGTH 0x0000ffff
474#define HIFN_D_NOINVALID 0x01000000
475#define HIFN_D_MASKDONEIRQ 0x02000000
476#define HIFN_D_DESTOVER 0x04000000
477#define HIFN_D_OVER 0x08000000
478#define HIFN_D_LAST 0x20000000
479#define HIFN_D_JUMP 0x40000000
480#define HIFN_D_VALID 0x80000000
481
482struct hifn_base_command
483{
484 volatile u16 masks;
485 volatile u16 session_num;
486 volatile u16 total_source_count;
487 volatile u16 total_dest_count;
488};
489
490#define HIFN_BASE_CMD_COMP 0x0100 /* enable compression engine */
491#define HIFN_BASE_CMD_PAD 0x0200 /* enable padding engine */
492#define HIFN_BASE_CMD_MAC 0x0400 /* enable MAC engine */
493#define HIFN_BASE_CMD_CRYPT 0x0800 /* enable crypt engine */
494#define HIFN_BASE_CMD_DECODE 0x2000
495#define HIFN_BASE_CMD_SRCLEN_M 0xc000
496#define HIFN_BASE_CMD_SRCLEN_S 14
497#define HIFN_BASE_CMD_DSTLEN_M 0x3000
498#define HIFN_BASE_CMD_DSTLEN_S 12
499#define HIFN_BASE_CMD_LENMASK_HI 0x30000
500#define HIFN_BASE_CMD_LENMASK_LO 0x0ffff
501
502/*
503 * Structure to help build up the command data structure.
504 */
505struct hifn_crypt_command
506{
507 volatile u16 masks;
508 volatile u16 header_skip;
509 volatile u16 source_count;
510 volatile u16 reserved;
511};
512
513#define HIFN_CRYPT_CMD_ALG_MASK 0x0003 /* algorithm: */
514#define HIFN_CRYPT_CMD_ALG_DES 0x0000 /* DES */
515#define HIFN_CRYPT_CMD_ALG_3DES 0x0001 /* 3DES */
516#define HIFN_CRYPT_CMD_ALG_RC4 0x0002 /* RC4 */
517#define HIFN_CRYPT_CMD_ALG_AES 0x0003 /* AES */
518#define HIFN_CRYPT_CMD_MODE_MASK 0x0018 /* Encrypt mode: */
519#define HIFN_CRYPT_CMD_MODE_ECB 0x0000 /* ECB */
520#define HIFN_CRYPT_CMD_MODE_CBC 0x0008 /* CBC */
521#define HIFN_CRYPT_CMD_MODE_CFB 0x0010 /* CFB */
522#define HIFN_CRYPT_CMD_MODE_OFB 0x0018 /* OFB */
523#define HIFN_CRYPT_CMD_CLR_CTX 0x0040 /* clear context */
524#define HIFN_CRYPT_CMD_KSZ_MASK 0x0600 /* AES key size: */
525#define HIFN_CRYPT_CMD_KSZ_128 0x0000 /* 128 bit */
526#define HIFN_CRYPT_CMD_KSZ_192 0x0200 /* 192 bit */
527#define HIFN_CRYPT_CMD_KSZ_256 0x0400 /* 256 bit */
528#define HIFN_CRYPT_CMD_NEW_KEY 0x0800 /* expect new key */
529#define HIFN_CRYPT_CMD_NEW_IV 0x1000 /* expect new iv */
530#define HIFN_CRYPT_CMD_SRCLEN_M 0xc000
531#define HIFN_CRYPT_CMD_SRCLEN_S 14
532
533/*
534 * Structure to help build up the command data structure.
535 */
536struct hifn_mac_command
537{
538 volatile u16 masks;
539 volatile u16 header_skip;
540 volatile u16 source_count;
541 volatile u16 reserved;
542};
543
544#define HIFN_MAC_CMD_ALG_MASK 0x0001
545#define HIFN_MAC_CMD_ALG_SHA1 0x0000
546#define HIFN_MAC_CMD_ALG_MD5 0x0001
547#define HIFN_MAC_CMD_MODE_MASK 0x000c
548#define HIFN_MAC_CMD_MODE_HMAC 0x0000
549#define HIFN_MAC_CMD_MODE_SSL_MAC 0x0004
550#define HIFN_MAC_CMD_MODE_HASH 0x0008
551#define HIFN_MAC_CMD_MODE_FULL 0x0004
552#define HIFN_MAC_CMD_TRUNC 0x0010
553#define HIFN_MAC_CMD_RESULT 0x0020
554#define HIFN_MAC_CMD_APPEND 0x0040
555#define HIFN_MAC_CMD_SRCLEN_M 0xc000
556#define HIFN_MAC_CMD_SRCLEN_S 14
557
558/*
559 * MAC POS IPsec initiates authentication after encryption on encodes
560 * and before decryption on decodes.
561 */
562#define HIFN_MAC_CMD_POS_IPSEC 0x0200
563#define HIFN_MAC_CMD_NEW_KEY 0x0800
564
565struct hifn_comp_command
566{
567 volatile u16 masks;
568 volatile u16 header_skip;
569 volatile u16 source_count;
570 volatile u16 reserved;
571};
572
573#define HIFN_COMP_CMD_SRCLEN_M 0xc000
574#define HIFN_COMP_CMD_SRCLEN_S 14
575#define HIFN_COMP_CMD_ONE 0x0100 /* must be one */
576#define HIFN_COMP_CMD_CLEARHIST 0x0010 /* clear history */
577#define HIFN_COMP_CMD_UPDATEHIST 0x0008 /* update history */
578#define HIFN_COMP_CMD_LZS_STRIP0 0x0004 /* LZS: strip zero */
579#define HIFN_COMP_CMD_MPPC_RESTART 0x0004 /* MPPC: restart */
580#define HIFN_COMP_CMD_ALG_MASK 0x0001 /* compression mode: */
581#define HIFN_COMP_CMD_ALG_MPPC 0x0001 /* MPPC */
582#define HIFN_COMP_CMD_ALG_LZS 0x0000 /* LZS */
583
584struct hifn_base_result
585{
586 volatile u16 flags;
587 volatile u16 session;
588 volatile u16 src_cnt; /* 15:0 of source count */
589 volatile u16 dst_cnt; /* 15:0 of dest count */
590};
591
592#define HIFN_BASE_RES_DSTOVERRUN 0x0200 /* destination overrun */
593#define HIFN_BASE_RES_SRCLEN_M 0xc000 /* 17:16 of source count */
594#define HIFN_BASE_RES_SRCLEN_S 14
595#define HIFN_BASE_RES_DSTLEN_M 0x3000 /* 17:16 of dest count */
596#define HIFN_BASE_RES_DSTLEN_S 12
597
598struct hifn_comp_result
599{
600 volatile u16 flags;
601 volatile u16 crc;
602};
603
604#define HIFN_COMP_RES_LCB_M 0xff00 /* longitudinal check byte */
605#define HIFN_COMP_RES_LCB_S 8
606#define HIFN_COMP_RES_RESTART 0x0004 /* MPPC: restart */
607#define HIFN_COMP_RES_ENDMARKER 0x0002 /* LZS: end marker seen */
608#define HIFN_COMP_RES_SRC_NOTZERO 0x0001 /* source expired */
609
610struct hifn_mac_result
611{
612 volatile u16 flags;
613 volatile u16 reserved;
614 /* followed by 0, 6, 8, or 10 u16's of the MAC, then crypt */
615};
616
617#define HIFN_MAC_RES_MISCOMPARE 0x0002 /* compare failed */
618#define HIFN_MAC_RES_SRC_NOTZERO 0x0001 /* source expired */
619
620struct hifn_crypt_result
621{
622 volatile u16 flags;
623 volatile u16 reserved;
624};
625
626#define HIFN_CRYPT_RES_SRC_NOTZERO 0x0001 /* source expired */
627
628#ifndef HIFN_POLL_FREQUENCY
629#define HIFN_POLL_FREQUENCY 0x1
630#endif
631
632#ifndef HIFN_POLL_SCALAR
633#define HIFN_POLL_SCALAR 0x0
634#endif
635
636#define HIFN_MAX_SEGLEN 0xffff /* maximum dma segment len */
637#define HIFN_MAX_DMALEN 0x3ffff /* maximum dma length */
638
639struct hifn_crypto_alg
640{
641 struct list_head entry;
642 struct crypto_alg alg;
643 struct hifn_device *dev;
644};
645
646#define ASYNC_SCATTERLIST_CACHE 16
647
648#define ASYNC_FLAGS_MISALIGNED (1<<0)
649
650struct ablkcipher_walk
651{
652 struct scatterlist cache[ASYNC_SCATTERLIST_CACHE];
653 u32 flags;
654 int num;
655};
656
657struct hifn_context
658{
659 u8 key[HIFN_MAX_CRYPT_KEY_LENGTH], *iv;
660 struct hifn_device *dev;
661 unsigned int keysize, ivsize;
662 u8 op, type, mode, unused;
663 struct ablkcipher_walk walk;
664 atomic_t sg_num;
665};
666
667#define crypto_alg_to_hifn(a) container_of(a, struct hifn_crypto_alg, alg)
668
669static inline u32 hifn_read_0(struct hifn_device *dev, u32 reg)
670{
671 u32 ret;
672
673 ret = readl((char *)(dev->bar[0]) + reg);
674
675 return ret;
676}
677
678static inline u32 hifn_read_1(struct hifn_device *dev, u32 reg)
679{
680 u32 ret;
681
682 ret = readl((char *)(dev->bar[1]) + reg);
683
684 return ret;
685}
686
687static inline void hifn_write_0(struct hifn_device *dev, u32 reg, u32 val)
688{
689 writel(val, (char *)(dev->bar[0]) + reg);
690}
691
692static inline void hifn_write_1(struct hifn_device *dev, u32 reg, u32 val)
693{
694 writel(val, (char *)(dev->bar[1]) + reg);
695}
696
697static void hifn_wait_puc(struct hifn_device *dev)
698{
699 int i;
700 u32 ret;
701
702 for (i=10000; i > 0; --i) {
703 ret = hifn_read_0(dev, HIFN_0_PUCTRL);
704 if (!(ret & HIFN_PUCTRL_RESET))
705 break;
706
707 udelay(1);
708 }
709
710 if (!i)
711 dprintk("%s: Failed to reset PUC unit.\n", dev->name);
712}
713
714static void hifn_reset_puc(struct hifn_device *dev)
715{
716 hifn_write_0(dev, HIFN_0_PUCTRL, HIFN_PUCTRL_DMAENA);
717 hifn_wait_puc(dev);
718}
719
720static void hifn_stop_device(struct hifn_device *dev)
721{
722 hifn_write_1(dev, HIFN_1_DMA_CSR,
723 HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS |
724 HIFN_DMACSR_S_CTRL_DIS | HIFN_DMACSR_C_CTRL_DIS);
725 hifn_write_0(dev, HIFN_0_PUIER, 0);
726 hifn_write_1(dev, HIFN_1_DMA_IER, 0);
727}
728
729static void hifn_reset_dma(struct hifn_device *dev, int full)
730{
731 hifn_stop_device(dev);
732
733 /*
734 * Setting poll frequency and others to 0.
735 */
736 hifn_write_1(dev, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
737 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
738 mdelay(1);
739
740 /*
741 * Reset DMA.
742 */
743 if (full) {
744 hifn_write_1(dev, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MODE);
745 mdelay(1);
746 } else {
747 hifn_write_1(dev, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MODE |
748 HIFN_DMACNFG_MSTRESET);
749 hifn_reset_puc(dev);
750 }
751
752 hifn_write_1(dev, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
753 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
754
755 hifn_reset_puc(dev);
756}
757
758static u32 hifn_next_signature(u_int32_t a, u_int cnt)
759{
760 int i;
761 u32 v;
762
763 for (i = 0; i < cnt; i++) {
764
765 /* get the parity */
766 v = a & 0x80080125;
767 v ^= v >> 16;
768 v ^= v >> 8;
769 v ^= v >> 4;
770 v ^= v >> 2;
771 v ^= v >> 1;
772
773 a = (v & 1) ^ (a << 1);
774 }
775
776 return a;
777}
778
779static struct pci2id {
780 u_short pci_vendor;
781 u_short pci_prod;
782 char card_id[13];
783} pci2id[] = {
784 {
785 PCI_VENDOR_ID_HIFN,
786 PCI_DEVICE_ID_HIFN_7955,
787 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
788 0x00, 0x00, 0x00, 0x00, 0x00 }
789 },
790 {
791 PCI_VENDOR_ID_HIFN,
792 PCI_DEVICE_ID_HIFN_7956,
793 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
794 0x00, 0x00, 0x00, 0x00, 0x00 }
795 }
796};
797
798#if defined(CONFIG_HW_RANDOM) || defined(CONFIG_HW_RANDOM_MODULE)
799static int hifn_rng_data_present(struct hwrng *rng, int wait)
800{
801 struct hifn_device *dev = (struct hifn_device *)rng->priv;
802 s64 nsec;
803
804 nsec = ktime_to_ns(ktime_sub(ktime_get(), dev->rngtime));
805 nsec -= dev->rng_wait_time;
806 if (nsec <= 0)
807 return 1;
808 if (!wait)
809 return 0;
810 ndelay(nsec);
811 return 1;
812}
813
814static int hifn_rng_data_read(struct hwrng *rng, u32 *data)
815{
816 struct hifn_device *dev = (struct hifn_device *)rng->priv;
817
818 *data = hifn_read_1(dev, HIFN_1_RNG_DATA);
819 dev->rngtime = ktime_get();
820 return 4;
821}
822
823static int hifn_register_rng(struct hifn_device *dev)
824{
825 /*
826 * We must wait at least 256 Pk_clk cycles between two reads of the rng.
827 */
828 dev->rng_wait_time = DIV_ROUND_UP(NSEC_PER_SEC, dev->pk_clk_freq) *
829 256;
830
831 dev->rng.name = dev->name;
832 dev->rng.data_present = hifn_rng_data_present,
833 dev->rng.data_read = hifn_rng_data_read,
834 dev->rng.priv = (unsigned long)dev;
835
836 return hwrng_register(&dev->rng);
837}
838
839static void hifn_unregister_rng(struct hifn_device *dev)
840{
841 hwrng_unregister(&dev->rng);
842}
843#else
844#define hifn_register_rng(dev) 0
845#define hifn_unregister_rng(dev)
846#endif
847
848static int hifn_init_pubrng(struct hifn_device *dev)
849{
850 int i;
851
852 hifn_write_1(dev, HIFN_1_PUB_RESET, hifn_read_1(dev, HIFN_1_PUB_RESET) |
853 HIFN_PUBRST_RESET);
854
855 for (i=100; i > 0; --i) {
856 mdelay(1);
857
858 if ((hifn_read_1(dev, HIFN_1_PUB_RESET) & HIFN_PUBRST_RESET) == 0)
859 break;
860 }
861
862 if (!i)
863 dprintk("Chip %s: Failed to initialise public key engine.\n",
864 dev->name);
865 else {
866 hifn_write_1(dev, HIFN_1_PUB_IEN, HIFN_PUBIEN_DONE);
867 dev->dmareg |= HIFN_DMAIER_PUBDONE;
868 hifn_write_1(dev, HIFN_1_DMA_IER, dev->dmareg);
869
870 dprintk("Chip %s: Public key engine has been sucessfully "
871 "initialised.\n", dev->name);
872 }
873
874 /*
875 * Enable RNG engine.
876 */
877
878 hifn_write_1(dev, HIFN_1_RNG_CONFIG,
879 hifn_read_1(dev, HIFN_1_RNG_CONFIG) | HIFN_RNGCFG_ENA);
880 dprintk("Chip %s: RNG engine has been successfully initialised.\n",
881 dev->name);
882
883#if defined(CONFIG_HW_RANDOM) || defined(CONFIG_HW_RANDOM_MODULE)
884 /* First value must be discarded */
885 hifn_read_1(dev, HIFN_1_RNG_DATA);
886 dev->rngtime = ktime_get();
887#endif
888 return 0;
889}
890
891static int hifn_enable_crypto(struct hifn_device *dev)
892{
893 u32 dmacfg, addr;
894 char *offtbl = NULL;
895 int i;
896
897 for (i = 0; i < sizeof(pci2id)/sizeof(pci2id[0]); i++) {
898 if (pci2id[i].pci_vendor == dev->pdev->vendor &&
899 pci2id[i].pci_prod == dev->pdev->device) {
900 offtbl = pci2id[i].card_id;
901 break;
902 }
903 }
904
905 if (offtbl == NULL) {
906 dprintk("Chip %s: Unknown card!\n", dev->name);
907 return -ENODEV;
908 }
909
910 dmacfg = hifn_read_1(dev, HIFN_1_DMA_CNFG);
911
912 hifn_write_1(dev, HIFN_1_DMA_CNFG,
913 HIFN_DMACNFG_UNLOCK | HIFN_DMACNFG_MSTRESET |
914 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE);
915 mdelay(1);
916 addr = hifn_read_1(dev, HIFN_1_UNLOCK_SECRET1);
917 mdelay(1);
918 hifn_write_1(dev, HIFN_1_UNLOCK_SECRET2, 0);
919 mdelay(1);
920
921 for (i=0; i<12; ++i) {
922 addr = hifn_next_signature(addr, offtbl[i] + 0x101);
923 hifn_write_1(dev, HIFN_1_UNLOCK_SECRET2, addr);
924
925 mdelay(1);
926 }
927 hifn_write_1(dev, HIFN_1_DMA_CNFG, dmacfg);
928
929 dprintk("Chip %s: %s.\n", dev->name, pci_name(dev->pdev));
930
931 return 0;
932}
933
934static void hifn_init_dma(struct hifn_device *dev)
935{
936 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
937 u32 dptr = dev->desc_dma;
938 int i;
939
940 for (i=0; i<HIFN_D_CMD_RSIZE; ++i)
941 dma->cmdr[i].p = __cpu_to_le32(dptr +
942 offsetof(struct hifn_dma, command_bufs[i][0]));
943 for (i=0; i<HIFN_D_RES_RSIZE; ++i)
944 dma->resr[i].p = __cpu_to_le32(dptr +
945 offsetof(struct hifn_dma, result_bufs[i][0]));
946
947 /*
948 * Setup LAST descriptors.
949 */
950 dma->cmdr[HIFN_D_CMD_RSIZE].p = __cpu_to_le32(dptr +
951 offsetof(struct hifn_dma, cmdr[0]));
952 dma->srcr[HIFN_D_SRC_RSIZE].p = __cpu_to_le32(dptr +
953 offsetof(struct hifn_dma, srcr[0]));
954 dma->dstr[HIFN_D_DST_RSIZE].p = __cpu_to_le32(dptr +
955 offsetof(struct hifn_dma, dstr[0]));
956 dma->resr[HIFN_D_RES_RSIZE].p = __cpu_to_le32(dptr +
957 offsetof(struct hifn_dma, resr[0]));
958
959 dma->cmdu = dma->srcu = dma->dstu = dma->resu = 0;
960 dma->cmdi = dma->srci = dma->dsti = dma->resi = 0;
961 dma->cmdk = dma->srck = dma->dstk = dma->resk = 0;
962}
963
964/*
965 * Initialize the PLL. We need to know the frequency of the reference clock
966 * to calculate the optimal multiplier. For PCI we assume 66MHz, since that
967 * allows us to operate without the risk of overclocking the chip. If it
968 * actually uses 33MHz, the chip will operate at half the speed, this can be
969 * overriden by specifying the frequency as module parameter (pci33).
970 *
971 * Unfortunately the PCI clock is not very suitable since the HIFN needs a
972 * stable clock and the PCI clock frequency may vary, so the default is the
973 * external clock. There is no way to find out its frequency, we default to
974 * 66MHz since according to Mike Ham of HiFn, almost every board in existence
975 * has an external crystal populated at 66MHz.
976 */
977static void hifn_init_pll(struct hifn_device *dev)
978{
979 unsigned int freq, m;
980 u32 pllcfg;
981
982 pllcfg = HIFN_1_PLL | HIFN_PLL_RESERVED_1;
983
984 if (strncmp(hifn_pll_ref, "ext", 3) == 0)
985 pllcfg |= HIFN_PLL_REF_CLK_PLL;
986 else
987 pllcfg |= HIFN_PLL_REF_CLK_HBI;
988
989 if (hifn_pll_ref[3] != '\0')
990 freq = simple_strtoul(hifn_pll_ref + 3, NULL, 10);
991 else {
992 freq = 66;
993 printk(KERN_INFO "hifn795x: assuming %uMHz clock speed, "
994 "override with hifn_pll_ref=%.3s<frequency>\n",
995 freq, hifn_pll_ref);
996 }
997
998 m = HIFN_PLL_FCK_MAX / freq;
999
1000 pllcfg |= (m / 2 - 1) << HIFN_PLL_ND_SHIFT;
1001 if (m <= 8)
1002 pllcfg |= HIFN_PLL_IS_1_8;
1003 else
1004 pllcfg |= HIFN_PLL_IS_9_12;
1005
1006 /* Select clock source and enable clock bypass */
1007 hifn_write_1(dev, HIFN_1_PLL, pllcfg |
1008 HIFN_PLL_PK_CLK_HBI | HIFN_PLL_PE_CLK_HBI | HIFN_PLL_BP);
1009
1010 /* Let the chip lock to the input clock */
1011 mdelay(10);
1012
1013 /* Disable clock bypass */
1014 hifn_write_1(dev, HIFN_1_PLL, pllcfg |
1015 HIFN_PLL_PK_CLK_HBI | HIFN_PLL_PE_CLK_HBI);
1016
1017 /* Switch the engines to the PLL */
1018 hifn_write_1(dev, HIFN_1_PLL, pllcfg |
1019 HIFN_PLL_PK_CLK_PLL | HIFN_PLL_PE_CLK_PLL);
1020
1021 /*
1022 * The Fpk_clk runs at half the total speed. Its frequency is needed to
1023 * calculate the minimum time between two reads of the rng. Since 33MHz
1024 * is actually 33.333... we overestimate the frequency here, resulting
1025 * in slightly larger intervals.
1026 */
1027 dev->pk_clk_freq = 1000000 * (freq + 1) * m / 2;
1028}
1029
1030static void hifn_init_registers(struct hifn_device *dev)
1031{
1032 u32 dptr = dev->desc_dma;
1033
1034 /* Initialization magic... */
1035 hifn_write_0(dev, HIFN_0_PUCTRL, HIFN_PUCTRL_DMAENA);
1036 hifn_write_0(dev, HIFN_0_FIFOCNFG, HIFN_FIFOCNFG_THRESHOLD);
1037 hifn_write_0(dev, HIFN_0_PUIER, HIFN_PUIER_DSTOVER);
1038
1039 /* write all 4 ring address registers */
1040 hifn_write_1(dev, HIFN_1_DMA_CRAR, __cpu_to_le32(dptr +
1041 offsetof(struct hifn_dma, cmdr[0])));
1042 hifn_write_1(dev, HIFN_1_DMA_SRAR, __cpu_to_le32(dptr +
1043 offsetof(struct hifn_dma, srcr[0])));
1044 hifn_write_1(dev, HIFN_1_DMA_DRAR, __cpu_to_le32(dptr +
1045 offsetof(struct hifn_dma, dstr[0])));
1046 hifn_write_1(dev, HIFN_1_DMA_RRAR, __cpu_to_le32(dptr +
1047 offsetof(struct hifn_dma, resr[0])));
1048
1049 mdelay(2);
1050#if 0
1051 hifn_write_1(dev, HIFN_1_DMA_CSR,
1052 HIFN_DMACSR_D_CTRL_DIS | HIFN_DMACSR_R_CTRL_DIS |
1053 HIFN_DMACSR_S_CTRL_DIS | HIFN_DMACSR_C_CTRL_DIS |
1054 HIFN_DMACSR_D_ABORT | HIFN_DMACSR_D_DONE | HIFN_DMACSR_D_LAST |
1055 HIFN_DMACSR_D_WAIT | HIFN_DMACSR_D_OVER |
1056 HIFN_DMACSR_R_ABORT | HIFN_DMACSR_R_DONE | HIFN_DMACSR_R_LAST |
1057 HIFN_DMACSR_R_WAIT | HIFN_DMACSR_R_OVER |
1058 HIFN_DMACSR_S_ABORT | HIFN_DMACSR_S_DONE | HIFN_DMACSR_S_LAST |
1059 HIFN_DMACSR_S_WAIT |
1060 HIFN_DMACSR_C_ABORT | HIFN_DMACSR_C_DONE | HIFN_DMACSR_C_LAST |
1061 HIFN_DMACSR_C_WAIT |
1062 HIFN_DMACSR_ENGINE |
1063 HIFN_DMACSR_PUBDONE);
1064#else
1065 hifn_write_1(dev, HIFN_1_DMA_CSR,
1066 HIFN_DMACSR_C_CTRL_ENA | HIFN_DMACSR_S_CTRL_ENA |
1067 HIFN_DMACSR_D_CTRL_ENA | HIFN_DMACSR_R_CTRL_ENA |
1068 HIFN_DMACSR_D_ABORT | HIFN_DMACSR_D_DONE | HIFN_DMACSR_D_LAST |
1069 HIFN_DMACSR_D_WAIT | HIFN_DMACSR_D_OVER |
1070 HIFN_DMACSR_R_ABORT | HIFN_DMACSR_R_DONE | HIFN_DMACSR_R_LAST |
1071 HIFN_DMACSR_R_WAIT | HIFN_DMACSR_R_OVER |
1072 HIFN_DMACSR_S_ABORT | HIFN_DMACSR_S_DONE | HIFN_DMACSR_S_LAST |
1073 HIFN_DMACSR_S_WAIT |
1074 HIFN_DMACSR_C_ABORT | HIFN_DMACSR_C_DONE | HIFN_DMACSR_C_LAST |
1075 HIFN_DMACSR_C_WAIT |
1076 HIFN_DMACSR_ENGINE |
1077 HIFN_DMACSR_PUBDONE);
1078#endif
1079 hifn_read_1(dev, HIFN_1_DMA_CSR);
1080
1081 dev->dmareg |= HIFN_DMAIER_R_DONE | HIFN_DMAIER_C_ABORT |
1082 HIFN_DMAIER_D_OVER | HIFN_DMAIER_R_OVER |
1083 HIFN_DMAIER_S_ABORT | HIFN_DMAIER_D_ABORT | HIFN_DMAIER_R_ABORT |
1084 HIFN_DMAIER_ENGINE;
1085 dev->dmareg &= ~HIFN_DMAIER_C_WAIT;
1086
1087 hifn_write_1(dev, HIFN_1_DMA_IER, dev->dmareg);
1088 hifn_read_1(dev, HIFN_1_DMA_IER);
1089#if 0
1090 hifn_write_0(dev, HIFN_0_PUCNFG, HIFN_PUCNFG_ENCCNFG |
1091 HIFN_PUCNFG_DRFR_128 | HIFN_PUCNFG_TCALLPHASES |
1092 HIFN_PUCNFG_TCDRVTOTEM | HIFN_PUCNFG_BUS32 |
1093 HIFN_PUCNFG_DRAM);
1094#else
1095 hifn_write_0(dev, HIFN_0_PUCNFG, 0x10342);
1096#endif
1097 hifn_init_pll(dev);
1098
1099 hifn_write_0(dev, HIFN_0_PUISR, HIFN_PUISR_DSTOVER);
1100 hifn_write_1(dev, HIFN_1_DMA_CNFG, HIFN_DMACNFG_MSTRESET |
1101 HIFN_DMACNFG_DMARESET | HIFN_DMACNFG_MODE | HIFN_DMACNFG_LAST |
1102 ((HIFN_POLL_FREQUENCY << 16 ) & HIFN_DMACNFG_POLLFREQ) |
1103 ((HIFN_POLL_SCALAR << 8) & HIFN_DMACNFG_POLLINVAL));
1104}
1105
1106static int hifn_setup_base_command(struct hifn_device *dev, u8 *buf,
1107 unsigned dlen, unsigned slen, u16 mask, u8 snum)
1108{
1109 struct hifn_base_command *base_cmd;
1110 u8 *buf_pos = buf;
1111
1112 base_cmd = (struct hifn_base_command *)buf_pos;
1113 base_cmd->masks = __cpu_to_le16(mask);
1114 base_cmd->total_source_count =
1115 __cpu_to_le16(slen & HIFN_BASE_CMD_LENMASK_LO);
1116 base_cmd->total_dest_count =
1117 __cpu_to_le16(dlen & HIFN_BASE_CMD_LENMASK_LO);
1118
1119 dlen >>= 16;
1120 slen >>= 16;
1121 base_cmd->session_num = __cpu_to_le16(snum |
1122 ((slen << HIFN_BASE_CMD_SRCLEN_S) & HIFN_BASE_CMD_SRCLEN_M) |
1123 ((dlen << HIFN_BASE_CMD_DSTLEN_S) & HIFN_BASE_CMD_DSTLEN_M));
1124
1125 return sizeof(struct hifn_base_command);
1126}
1127
1128static int hifn_setup_crypto_command(struct hifn_device *dev,
1129 u8 *buf, unsigned dlen, unsigned slen,
1130 u8 *key, int keylen, u8 *iv, int ivsize, u16 mode)
1131{
1132 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1133 struct hifn_crypt_command *cry_cmd;
1134 u8 *buf_pos = buf;
1135 u16 cmd_len;
1136
1137 cry_cmd = (struct hifn_crypt_command *)buf_pos;
1138
1139 cry_cmd->source_count = __cpu_to_le16(dlen & 0xffff);
1140 dlen >>= 16;
1141 cry_cmd->masks = __cpu_to_le16(mode |
1142 ((dlen << HIFN_CRYPT_CMD_SRCLEN_S) &
1143 HIFN_CRYPT_CMD_SRCLEN_M));
1144 cry_cmd->header_skip = 0;
1145 cry_cmd->reserved = 0;
1146
1147 buf_pos += sizeof(struct hifn_crypt_command);
1148
1149 dma->cmdu++;
1150 if (dma->cmdu > 1) {
1151 dev->dmareg |= HIFN_DMAIER_C_WAIT;
1152 hifn_write_1(dev, HIFN_1_DMA_IER, dev->dmareg);
1153 }
1154
1155 if (keylen) {
1156 memcpy(buf_pos, key, keylen);
1157 buf_pos += keylen;
1158 }
1159 if (ivsize) {
1160 memcpy(buf_pos, iv, ivsize);
1161 buf_pos += ivsize;
1162 }
1163
1164 cmd_len = buf_pos - buf;
1165
1166 return cmd_len;
1167}
1168
1169static int hifn_setup_src_desc(struct hifn_device *dev, struct page *page,
1170 unsigned int offset, unsigned int size)
1171{
1172 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1173 int idx;
1174 dma_addr_t addr;
1175
1176 addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_TODEVICE);
1177
1178 idx = dma->srci;
1179
1180 dma->srcr[idx].p = __cpu_to_le32(addr);
1181 dma->srcr[idx].l = __cpu_to_le32(size) | HIFN_D_VALID |
1182 HIFN_D_MASKDONEIRQ | HIFN_D_NOINVALID | HIFN_D_LAST;
1183
1184 if (++idx == HIFN_D_SRC_RSIZE) {
1185 dma->srcr[idx].l = __cpu_to_le32(HIFN_D_VALID |
1186 HIFN_D_JUMP |
1187 HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
1188 idx = 0;
1189 }
1190
1191 dma->srci = idx;
1192 dma->srcu++;
1193
1194 if (!(dev->flags & HIFN_FLAG_SRC_BUSY)) {
1195 hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_S_CTRL_ENA);
1196 dev->flags |= HIFN_FLAG_SRC_BUSY;
1197 }
1198
1199 return size;
1200}
1201
1202static void hifn_setup_res_desc(struct hifn_device *dev)
1203{
1204 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1205
1206 dma->resr[dma->resi].l = __cpu_to_le32(HIFN_USED_RESULT |
1207 HIFN_D_VALID | HIFN_D_LAST);
1208 /*
1209 * dma->resr[dma->resi].l = __cpu_to_le32(HIFN_MAX_RESULT | HIFN_D_VALID |
1210 * HIFN_D_LAST | HIFN_D_NOINVALID);
1211 */
1212
1213 if (++dma->resi == HIFN_D_RES_RSIZE) {
1214 dma->resr[HIFN_D_RES_RSIZE].l = __cpu_to_le32(HIFN_D_VALID |
1215 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ | HIFN_D_LAST);
1216 dma->resi = 0;
1217 }
1218
1219 dma->resu++;
1220
1221 if (!(dev->flags & HIFN_FLAG_RES_BUSY)) {
1222 hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_R_CTRL_ENA);
1223 dev->flags |= HIFN_FLAG_RES_BUSY;
1224 }
1225}
1226
1227static void hifn_setup_dst_desc(struct hifn_device *dev, struct page *page,
1228 unsigned offset, unsigned size)
1229{
1230 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1231 int idx;
1232 dma_addr_t addr;
1233
1234 addr = pci_map_page(dev->pdev, page, offset, size, PCI_DMA_FROMDEVICE);
1235
1236 idx = dma->dsti;
1237 dma->dstr[idx].p = __cpu_to_le32(addr);
1238 dma->dstr[idx].l = __cpu_to_le32(size | HIFN_D_VALID |
1239 HIFN_D_MASKDONEIRQ | HIFN_D_NOINVALID | HIFN_D_LAST);
1240
1241 if (++idx == HIFN_D_DST_RSIZE) {
1242 dma->dstr[idx].l = __cpu_to_le32(HIFN_D_VALID |
1243 HIFN_D_JUMP | HIFN_D_MASKDONEIRQ |
1244 HIFN_D_LAST | HIFN_D_NOINVALID);
1245 idx = 0;
1246 }
1247 dma->dsti = idx;
1248 dma->dstu++;
1249
1250 if (!(dev->flags & HIFN_FLAG_DST_BUSY)) {
1251 hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_D_CTRL_ENA);
1252 dev->flags |= HIFN_FLAG_DST_BUSY;
1253 }
1254}
1255
1256static int hifn_setup_dma(struct hifn_device *dev, struct page *spage, unsigned int soff,
1257 struct page *dpage, unsigned int doff, unsigned int nbytes, void *priv,
1258 struct hifn_context *ctx)
1259{
1260 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1261 int cmd_len, sa_idx;
1262 u8 *buf, *buf_pos;
1263 u16 mask;
1264
1265 dprintk("%s: spage: %p, soffset: %u, dpage: %p, doffset: %u, nbytes: %u, priv: %p, ctx: %p.\n",
1266 dev->name, spage, soff, dpage, doff, nbytes, priv, ctx);
1267
1268 sa_idx = dma->resi;
1269
1270 hifn_setup_src_desc(dev, spage, soff, nbytes);
1271
1272 buf_pos = buf = dma->command_bufs[dma->cmdi];
1273
1274 mask = 0;
1275 switch (ctx->op) {
1276 case ACRYPTO_OP_DECRYPT:
1277 mask = HIFN_BASE_CMD_CRYPT | HIFN_BASE_CMD_DECODE;
1278 break;
1279 case ACRYPTO_OP_ENCRYPT:
1280 mask = HIFN_BASE_CMD_CRYPT;
1281 break;
1282 case ACRYPTO_OP_HMAC:
1283 mask = HIFN_BASE_CMD_MAC;
1284 break;
1285 default:
1286 goto err_out;
1287 }
1288
1289 buf_pos += hifn_setup_base_command(dev, buf_pos, nbytes,
1290 nbytes, mask, dev->snum);
1291
1292 if (ctx->op == ACRYPTO_OP_ENCRYPT || ctx->op == ACRYPTO_OP_DECRYPT) {
1293 u16 md = 0;
1294
1295 if (ctx->keysize)
1296 md |= HIFN_CRYPT_CMD_NEW_KEY;
1297 if (ctx->iv && ctx->mode != ACRYPTO_MODE_ECB)
1298 md |= HIFN_CRYPT_CMD_NEW_IV;
1299
1300 switch (ctx->mode) {
1301 case ACRYPTO_MODE_ECB:
1302 md |= HIFN_CRYPT_CMD_MODE_ECB;
1303 break;
1304 case ACRYPTO_MODE_CBC:
1305 md |= HIFN_CRYPT_CMD_MODE_CBC;
1306 break;
1307 case ACRYPTO_MODE_CFB:
1308 md |= HIFN_CRYPT_CMD_MODE_CFB;
1309 break;
1310 case ACRYPTO_MODE_OFB:
1311 md |= HIFN_CRYPT_CMD_MODE_OFB;
1312 break;
1313 default:
1314 goto err_out;
1315 }
1316
1317 switch (ctx->type) {
1318 case ACRYPTO_TYPE_AES_128:
1319 if (ctx->keysize != 16)
1320 goto err_out;
1321 md |= HIFN_CRYPT_CMD_KSZ_128 |
1322 HIFN_CRYPT_CMD_ALG_AES;
1323 break;
1324 case ACRYPTO_TYPE_AES_192:
1325 if (ctx->keysize != 24)
1326 goto err_out;
1327 md |= HIFN_CRYPT_CMD_KSZ_192 |
1328 HIFN_CRYPT_CMD_ALG_AES;
1329 break;
1330 case ACRYPTO_TYPE_AES_256:
1331 if (ctx->keysize != 32)
1332 goto err_out;
1333 md |= HIFN_CRYPT_CMD_KSZ_256 |
1334 HIFN_CRYPT_CMD_ALG_AES;
1335 break;
1336 case ACRYPTO_TYPE_3DES:
1337 if (ctx->keysize != 24)
1338 goto err_out;
1339 md |= HIFN_CRYPT_CMD_ALG_3DES;
1340 break;
1341 case ACRYPTO_TYPE_DES:
1342 if (ctx->keysize != 8)
1343 goto err_out;
1344 md |= HIFN_CRYPT_CMD_ALG_DES;
1345 break;
1346 default:
1347 goto err_out;
1348 }
1349
1350 buf_pos += hifn_setup_crypto_command(dev, buf_pos,
1351 nbytes, nbytes, ctx->key, ctx->keysize,
1352 ctx->iv, ctx->ivsize, md);
1353 }
1354
1355 dev->sa[sa_idx] = priv;
1356
1357 cmd_len = buf_pos - buf;
1358 dma->cmdr[dma->cmdi].l = __cpu_to_le32(cmd_len | HIFN_D_VALID |
1359 HIFN_D_LAST | HIFN_D_MASKDONEIRQ);
1360
1361 if (++dma->cmdi == HIFN_D_CMD_RSIZE) {
1362 dma->cmdr[dma->cmdi].l = __cpu_to_le32(HIFN_MAX_COMMAND |
1363 HIFN_D_VALID | HIFN_D_LAST |
1364 HIFN_D_MASKDONEIRQ | HIFN_D_JUMP);
1365 dma->cmdi = 0;
1366 } else
1367 dma->cmdr[dma->cmdi-1].l |= __cpu_to_le32(HIFN_D_VALID);
1368
1369 if (!(dev->flags & HIFN_FLAG_CMD_BUSY)) {
1370 hifn_write_1(dev, HIFN_1_DMA_CSR, HIFN_DMACSR_C_CTRL_ENA);
1371 dev->flags |= HIFN_FLAG_CMD_BUSY;
1372 }
1373
1374 hifn_setup_dst_desc(dev, dpage, doff, nbytes);
1375 hifn_setup_res_desc(dev);
1376
1377 return 0;
1378
1379err_out:
1380 return -EINVAL;
1381}
1382
1383static int ablkcipher_walk_init(struct ablkcipher_walk *w,
1384 int num, gfp_t gfp_flags)
1385{
1386 int i;
1387
1388 num = min(ASYNC_SCATTERLIST_CACHE, num);
1389 sg_init_table(w->cache, num);
1390
1391 w->num = 0;
1392 for (i=0; i<num; ++i) {
1393 struct page *page = alloc_page(gfp_flags);
1394 struct scatterlist *s;
1395
1396 if (!page)
1397 break;
1398
1399 s = &w->cache[i];
1400
1401 sg_set_page(s, page, PAGE_SIZE, 0);
1402 w->num++;
1403 }
1404
1405 return i;
1406}
1407
1408static void ablkcipher_walk_exit(struct ablkcipher_walk *w)
1409{
1410 int i;
1411
1412 for (i=0; i<w->num; ++i) {
1413 struct scatterlist *s = &w->cache[i];
1414
1415 __free_page(sg_page(s));
1416
1417 s->length = 0;
1418 }
1419
1420 w->num = 0;
1421}
1422
1423static int ablkcipher_add(void *daddr, unsigned int *drestp, struct scatterlist *src,
1424 unsigned int size, unsigned int *nbytesp)
1425{
1426 unsigned int copy, drest = *drestp, nbytes = *nbytesp;
1427 int idx = 0;
1428 void *saddr;
1429
1430 if (drest < size || size > nbytes)
1431 return -EINVAL;
1432
1433 while (size) {
1434 copy = min(drest, src->length);
1435
1436 saddr = kmap_atomic(sg_page(src), KM_SOFTIRQ1);
1437 memcpy(daddr, saddr + src->offset, copy);
1438 kunmap_atomic(saddr, KM_SOFTIRQ1);
1439
1440 size -= copy;
1441 drest -= copy;
1442 nbytes -= copy;
1443 daddr += copy;
1444
1445 dprintk("%s: copy: %u, size: %u, drest: %u, nbytes: %u.\n",
1446 __func__, copy, size, drest, nbytes);
1447
1448 src++;
1449 idx++;
1450 }
1451
1452 *nbytesp = nbytes;
1453 *drestp = drest;
1454
1455 return idx;
1456}
1457
1458static int ablkcipher_walk(struct ablkcipher_request *req,
1459 struct ablkcipher_walk *w)
1460{
1461 unsigned blocksize =
1462 crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm(req));
1463 unsigned alignmask =
1464 crypto_ablkcipher_alignmask(crypto_ablkcipher_reqtfm(req));
1465 struct scatterlist *src, *dst, *t;
1466 void *daddr;
1467 unsigned int nbytes = req->nbytes, offset, copy, diff;
1468 int idx, tidx, err;
1469
1470 tidx = idx = 0;
1471 offset = 0;
1472 while (nbytes) {
1473 if (idx >= w->num && (w->flags & ASYNC_FLAGS_MISALIGNED))
1474 return -EINVAL;
1475
1476 src = &req->src[idx];
1477 dst = &req->dst[idx];
1478
1479 dprintk("\n%s: slen: %u, dlen: %u, soff: %u, doff: %u, offset: %u, "
1480 "blocksize: %u, nbytes: %u.\n",
1481 __func__, src->length, dst->length, src->offset,
1482 dst->offset, offset, blocksize, nbytes);
1483
1484 if (src->length & (blocksize - 1) ||
1485 src->offset & (alignmask - 1) ||
1486 dst->length & (blocksize - 1) ||
1487 dst->offset & (alignmask - 1) ||
1488 offset) {
1489 unsigned slen = src->length - offset;
1490 unsigned dlen = PAGE_SIZE;
1491
1492 t = &w->cache[idx];
1493
1494 daddr = kmap_atomic(sg_page(t), KM_SOFTIRQ0);
1495 err = ablkcipher_add(daddr, &dlen, src, slen, &nbytes);
1496 if (err < 0)
1497 goto err_out_unmap;
1498
1499 idx += err;
1500
1501 copy = slen & ~(blocksize - 1);
1502 diff = slen & (blocksize - 1);
1503
1504 if (dlen < nbytes) {
1505 /*
1506 * Destination page does not have enough space
1507 * to put there additional blocksized chunk,
1508 * so we mark that page as containing only
1509 * blocksize aligned chunks:
1510 * t->length = (slen & ~(blocksize - 1));
1511 * and increase number of bytes to be processed
1512 * in next chunk:
1513 * nbytes += diff;
1514 */
1515 nbytes += diff;
1516
1517 /*
1518 * Temporary of course...
1519 * Kick author if you will catch this one.
1520 */
1521 printk(KERN_ERR "%s: dlen: %u, nbytes: %u,"
1522 "slen: %u, offset: %u.\n",
1523 __func__, dlen, nbytes, slen, offset);
1524 printk(KERN_ERR "%s: please contact author to fix this "
1525 "issue, generally you should not catch "
1526 "this path under any condition but who "
1527 "knows how did you use crypto code.\n"
1528 "Thank you.\n", __func__);
1529 BUG();
1530 } else {
1531 copy += diff + nbytes;
1532
1533 src = &req->src[idx];
1534
1535 err = ablkcipher_add(daddr + slen, &dlen, src, nbytes, &nbytes);
1536 if (err < 0)
1537 goto err_out_unmap;
1538
1539 idx += err;
1540 }
1541
1542 t->length = copy;
1543 t->offset = offset;
1544
1545 kunmap_atomic(daddr, KM_SOFTIRQ0);
1546 } else {
1547 nbytes -= src->length;
1548 idx++;
1549 }
1550
1551 tidx++;
1552 }
1553
1554 return tidx;
1555
1556err_out_unmap:
1557 kunmap_atomic(daddr, KM_SOFTIRQ0);
1558 return err;
1559}
1560
1561static int hifn_setup_session(struct ablkcipher_request *req)
1562{
1563 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
1564 struct hifn_device *dev = ctx->dev;
1565 struct page *spage, *dpage;
1566 unsigned long soff, doff, flags;
1567 unsigned int nbytes = req->nbytes, idx = 0, len;
1568 int err = -EINVAL, sg_num;
1569 struct scatterlist *src, *dst, *t;
1570 unsigned blocksize =
1571 crypto_ablkcipher_blocksize(crypto_ablkcipher_reqtfm(req));
1572 unsigned alignmask =
1573 crypto_ablkcipher_alignmask(crypto_ablkcipher_reqtfm(req));
1574
1575 if (ctx->iv && !ctx->ivsize && ctx->mode != ACRYPTO_MODE_ECB)
1576 goto err_out_exit;
1577
1578 ctx->walk.flags = 0;
1579
1580 while (nbytes) {
1581 src = &req->src[idx];
1582 dst = &req->dst[idx];
1583
1584 if (src->length & (blocksize - 1) ||
1585 src->offset & (alignmask - 1) ||
1586 dst->length & (blocksize - 1) ||
1587 dst->offset & (alignmask - 1)) {
1588 ctx->walk.flags |= ASYNC_FLAGS_MISALIGNED;
1589 }
1590
1591 nbytes -= src->length;
1592 idx++;
1593 }
1594
1595 if (ctx->walk.flags & ASYNC_FLAGS_MISALIGNED) {
1596 err = ablkcipher_walk_init(&ctx->walk, idx, GFP_ATOMIC);
1597 if (err < 0)
1598 return err;
1599 }
1600
1601 nbytes = req->nbytes;
1602 idx = 0;
1603
1604 sg_num = ablkcipher_walk(req, &ctx->walk);
1605
1606 atomic_set(&ctx->sg_num, sg_num);
1607
1608 spin_lock_irqsave(&dev->lock, flags);
1609 if (dev->started + sg_num > HIFN_QUEUE_LENGTH) {
1610 err = -EAGAIN;
1611 goto err_out;
1612 }
1613
1614 dev->snum++;
1615 dev->started += sg_num;
1616
1617 while (nbytes) {
1618 src = &req->src[idx];
1619 dst = &req->dst[idx];
1620 t = &ctx->walk.cache[idx];
1621
1622 if (t->length) {
1623 spage = dpage = sg_page(t);
1624 soff = doff = 0;
1625 len = t->length;
1626 } else {
1627 spage = sg_page(src);
1628 soff = src->offset;
1629
1630 dpage = sg_page(dst);
1631 doff = dst->offset;
1632
1633 len = dst->length;
1634 }
1635
1636 idx++;
1637
1638 err = hifn_setup_dma(dev, spage, soff, dpage, doff, nbytes,
1639 req, ctx);
1640 if (err)
1641 goto err_out;
1642
1643 nbytes -= len;
1644 }
1645
1646 dev->active = HIFN_DEFAULT_ACTIVE_NUM;
1647 spin_unlock_irqrestore(&dev->lock, flags);
1648
1649 return 0;
1650
1651err_out:
1652 spin_unlock_irqrestore(&dev->lock, flags);
1653err_out_exit:
1654 if (err && printk_ratelimit())
1655 dprintk("%s: iv: %p [%d], key: %p [%d], mode: %u, op: %u, "
1656 "type: %u, err: %d.\n",
1657 dev->name, ctx->iv, ctx->ivsize,
1658 ctx->key, ctx->keysize,
1659 ctx->mode, ctx->op, ctx->type, err);
1660
1661 return err;
1662}
1663
1664static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
1665{
1666 int n, err;
1667 u8 src[16];
1668 struct hifn_context ctx;
1669 u8 fips_aes_ecb_from_zero[16] = {
1670 0x66, 0xE9, 0x4B, 0xD4,
1671 0xEF, 0x8A, 0x2C, 0x3B,
1672 0x88, 0x4C, 0xFA, 0x59,
1673 0xCA, 0x34, 0x2B, 0x2E};
1674
1675 memset(src, 0, sizeof(src));
1676 memset(ctx.key, 0, sizeof(ctx.key));
1677
1678 ctx.dev = dev;
1679 ctx.keysize = 16;
1680 ctx.ivsize = 0;
1681 ctx.iv = NULL;
1682 ctx.op = (encdec)?ACRYPTO_OP_ENCRYPT:ACRYPTO_OP_DECRYPT;
1683 ctx.mode = ACRYPTO_MODE_ECB;
1684 ctx.type = ACRYPTO_TYPE_AES_128;
1685 atomic_set(&ctx.sg_num, 1);
1686
1687 err = hifn_setup_dma(dev,
1688 virt_to_page(src), offset_in_page(src),
1689 virt_to_page(src), offset_in_page(src),
1690 sizeof(src), NULL, &ctx);
1691 if (err)
1692 goto err_out;
1693
1694 msleep(200);
1695
1696 dprintk("%s: decoded: ", dev->name);
1697 for (n=0; n<sizeof(src); ++n)
1698 dprintk("%02x ", src[n]);
1699 dprintk("\n");
1700 dprintk("%s: FIPS : ", dev->name);
1701 for (n=0; n<sizeof(fips_aes_ecb_from_zero); ++n)
1702 dprintk("%02x ", fips_aes_ecb_from_zero[n]);
1703 dprintk("\n");
1704
1705 if (!memcmp(src, fips_aes_ecb_from_zero, sizeof(fips_aes_ecb_from_zero))) {
1706 printk(KERN_INFO "%s: AES 128 ECB test has been successfully "
1707 "passed.\n", dev->name);
1708 return 0;
1709 }
1710
1711err_out:
1712 printk(KERN_INFO "%s: AES 128 ECB test has been failed.\n", dev->name);
1713 return -1;
1714}
1715
1716static int hifn_start_device(struct hifn_device *dev)
1717{
1718 int err;
1719
1720 hifn_reset_dma(dev, 1);
1721
1722 err = hifn_enable_crypto(dev);
1723 if (err)
1724 return err;
1725
1726 hifn_reset_puc(dev);
1727
1728 hifn_init_dma(dev);
1729
1730 hifn_init_registers(dev);
1731
1732 hifn_init_pubrng(dev);
1733
1734 return 0;
1735}
1736
1737static int ablkcipher_get(void *saddr, unsigned int *srestp, unsigned int offset,
1738 struct scatterlist *dst, unsigned int size, unsigned int *nbytesp)
1739{
1740 unsigned int srest = *srestp, nbytes = *nbytesp, copy;
1741 void *daddr;
1742 int idx = 0;
1743
1744 if (srest < size || size > nbytes)
1745 return -EINVAL;
1746
1747 while (size) {
1748
1749 copy = min(dst->length, srest);
1750
1751 daddr = kmap_atomic(sg_page(dst), KM_IRQ0);
1752 memcpy(daddr + dst->offset + offset, saddr, copy);
1753 kunmap_atomic(daddr, KM_IRQ0);
1754
1755 nbytes -= copy;
1756 size -= copy;
1757 srest -= copy;
1758 saddr += copy;
1759 offset = 0;
1760
1761 dprintk("%s: copy: %u, size: %u, srest: %u, nbytes: %u.\n",
1762 __func__, copy, size, srest, nbytes);
1763
1764 dst++;
1765 idx++;
1766 }
1767
1768 *nbytesp = nbytes;
1769 *srestp = srest;
1770
1771 return idx;
1772}
1773
1774static void hifn_process_ready(struct ablkcipher_request *req, int error)
1775{
1776 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
1777 struct hifn_device *dev;
1778
1779 dprintk("%s: req: %p, ctx: %p.\n", __func__, req, ctx);
1780
1781 dev = ctx->dev;
1782 dprintk("%s: req: %p, started: %d, sg_num: %d.\n",
1783 __func__, req, dev->started, atomic_read(&ctx->sg_num));
1784
1785 if (--dev->started < 0)
1786 BUG();
1787
1788 if (atomic_dec_and_test(&ctx->sg_num)) {
1789 unsigned int nbytes = req->nbytes;
1790 int idx = 0, err;
1791 struct scatterlist *dst, *t;
1792 void *saddr;
1793
1794 if (ctx->walk.flags & ASYNC_FLAGS_MISALIGNED) {
1795 while (nbytes) {
1796 t = &ctx->walk.cache[idx];
1797 dst = &req->dst[idx];
1798
1799 dprintk("\n%s: sg_page(t): %p, t->length: %u, "
1800 "sg_page(dst): %p, dst->length: %u, "
1801 "nbytes: %u.\n",
1802 __func__, sg_page(t), t->length,
1803 sg_page(dst), dst->length, nbytes);
1804
1805 if (!t->length) {
1806 nbytes -= dst->length;
1807 idx++;
1808 continue;
1809 }
1810
1811 saddr = kmap_atomic(sg_page(t), KM_IRQ1);
1812
1813 err = ablkcipher_get(saddr, &t->length, t->offset,
1814 dst, nbytes, &nbytes);
1815 if (err < 0) {
1816 kunmap_atomic(saddr, KM_IRQ1);
1817 break;
1818 }
1819
1820 idx += err;
1821 kunmap_atomic(saddr, KM_IRQ1);
1822 }
1823
1824 ablkcipher_walk_exit(&ctx->walk);
1825 }
1826
1827 req->base.complete(&req->base, error);
1828 }
1829}
1830
1831static void hifn_check_for_completion(struct hifn_device *dev, int error)
1832{
1833 int i;
1834 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1835
1836 for (i=0; i<HIFN_D_RES_RSIZE; ++i) {
1837 struct hifn_desc *d = &dma->resr[i];
1838
1839 if (!(d->l & __cpu_to_le32(HIFN_D_VALID)) && dev->sa[i]) {
1840 dev->success++;
1841 dev->reset = 0;
1842 hifn_process_ready(dev->sa[i], error);
1843 dev->sa[i] = NULL;
1844 }
1845
1846 if (d->l & __cpu_to_le32(HIFN_D_DESTOVER | HIFN_D_OVER))
1847 if (printk_ratelimit())
1848 printk("%s: overflow detected [d: %u, o: %u] "
1849 "at %d resr: l: %08x, p: %08x.\n",
1850 dev->name,
1851 !!(d->l & __cpu_to_le32(HIFN_D_DESTOVER)),
1852 !!(d->l & __cpu_to_le32(HIFN_D_OVER)),
1853 i, d->l, d->p);
1854 }
1855}
1856
1857static void hifn_clear_rings(struct hifn_device *dev)
1858{
1859 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1860 int i, u;
1861
1862 dprintk("%s: ring cleanup 1: i: %d.%d.%d.%d, u: %d.%d.%d.%d, "
1863 "k: %d.%d.%d.%d.\n",
1864 dev->name,
1865 dma->cmdi, dma->srci, dma->dsti, dma->resi,
1866 dma->cmdu, dma->srcu, dma->dstu, dma->resu,
1867 dma->cmdk, dma->srck, dma->dstk, dma->resk);
1868
1869 i = dma->resk; u = dma->resu;
1870 while (u != 0) {
1871 if (dma->resr[i].l & __cpu_to_le32(HIFN_D_VALID))
1872 break;
1873
1874 if (i != HIFN_D_RES_RSIZE)
1875 u--;
1876
1877 if (++i == (HIFN_D_RES_RSIZE + 1))
1878 i = 0;
1879 }
1880 dma->resk = i; dma->resu = u;
1881
1882 i = dma->srck; u = dma->srcu;
1883 while (u != 0) {
1884 if (i == HIFN_D_SRC_RSIZE)
1885 i = 0;
1886 if (dma->srcr[i].l & __cpu_to_le32(HIFN_D_VALID))
1887 break;
1888 i++, u--;
1889 }
1890 dma->srck = i; dma->srcu = u;
1891
1892 i = dma->cmdk; u = dma->cmdu;
1893 while (u != 0) {
1894 if (dma->cmdr[i].l & __cpu_to_le32(HIFN_D_VALID))
1895 break;
1896 if (i != HIFN_D_CMD_RSIZE)
1897 u--;
1898 if (++i == (HIFN_D_CMD_RSIZE + 1))
1899 i = 0;
1900 }
1901 dma->cmdk = i; dma->cmdu = u;
1902
1903 i = dma->dstk; u = dma->dstu;
1904 while (u != 0) {
1905 if (i == HIFN_D_DST_RSIZE)
1906 i = 0;
1907 if (dma->dstr[i].l & __cpu_to_le32(HIFN_D_VALID))
1908 break;
1909 i++, u--;
1910 }
1911 dma->dstk = i; dma->dstu = u;
1912
1913 dprintk("%s: ring cleanup 2: i: %d.%d.%d.%d, u: %d.%d.%d.%d, "
1914 "k: %d.%d.%d.%d.\n",
1915 dev->name,
1916 dma->cmdi, dma->srci, dma->dsti, dma->resi,
1917 dma->cmdu, dma->srcu, dma->dstu, dma->resu,
1918 dma->cmdk, dma->srck, dma->dstk, dma->resk);
1919}
1920
1921static void hifn_work(struct work_struct *work)
1922{
1923 struct delayed_work *dw = container_of(work, struct delayed_work, work);
1924 struct hifn_device *dev = container_of(dw, struct hifn_device, work);
1925 unsigned long flags;
1926 int reset = 0;
1927 u32 r = 0;
1928
1929 spin_lock_irqsave(&dev->lock, flags);
1930 if (dev->active == 0) {
1931 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1932
1933 if (dma->cmdu == 0 && (dev->flags & HIFN_FLAG_CMD_BUSY)) {
1934 dev->flags &= ~HIFN_FLAG_CMD_BUSY;
1935 r |= HIFN_DMACSR_C_CTRL_DIS;
1936 }
1937 if (dma->srcu == 0 && (dev->flags & HIFN_FLAG_SRC_BUSY)) {
1938 dev->flags &= ~HIFN_FLAG_SRC_BUSY;
1939 r |= HIFN_DMACSR_S_CTRL_DIS;
1940 }
1941 if (dma->dstu == 0 && (dev->flags & HIFN_FLAG_DST_BUSY)) {
1942 dev->flags &= ~HIFN_FLAG_DST_BUSY;
1943 r |= HIFN_DMACSR_D_CTRL_DIS;
1944 }
1945 if (dma->resu == 0 && (dev->flags & HIFN_FLAG_RES_BUSY)) {
1946 dev->flags &= ~HIFN_FLAG_RES_BUSY;
1947 r |= HIFN_DMACSR_R_CTRL_DIS;
1948 }
1949 if (r)
1950 hifn_write_1(dev, HIFN_1_DMA_CSR, r);
1951 } else
1952 dev->active--;
1953
1954 if (dev->prev_success == dev->success && dev->started)
1955 reset = 1;
1956 dev->prev_success = dev->success;
1957 spin_unlock_irqrestore(&dev->lock, flags);
1958
1959 if (reset) {
1960 dprintk("%s: r: %08x, active: %d, started: %d, "
1961 "success: %lu: reset: %d.\n",
1962 dev->name, r, dev->active, dev->started,
1963 dev->success, reset);
1964
1965 if (++dev->reset >= 5) {
1966 dprintk("%s: really hard reset.\n", dev->name);
1967 hifn_reset_dma(dev, 1);
1968 hifn_stop_device(dev);
1969 hifn_start_device(dev);
1970 dev->reset = 0;
1971 }
1972
1973 spin_lock_irqsave(&dev->lock, flags);
1974 hifn_check_for_completion(dev, -EBUSY);
1975 hifn_clear_rings(dev);
1976 dev->started = 0;
1977 spin_unlock_irqrestore(&dev->lock, flags);
1978 }
1979
1980 schedule_delayed_work(&dev->work, HZ);
1981}
1982
1983static irqreturn_t hifn_interrupt(int irq, void *data)
1984{
1985 struct hifn_device *dev = (struct hifn_device *)data;
1986 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
1987 u32 dmacsr, restart;
1988
1989 dmacsr = hifn_read_1(dev, HIFN_1_DMA_CSR);
1990
1991 dprintk("%s: 1 dmacsr: %08x, dmareg: %08x, res: %08x [%d], "
1992 "i: %d.%d.%d.%d, u: %d.%d.%d.%d.\n",
1993 dev->name, dmacsr, dev->dmareg, dmacsr & dev->dmareg, dma->cmdi,
1994 dma->cmdu, dma->srcu, dma->dstu, dma->resu,
1995 dma->cmdi, dma->srci, dma->dsti, dma->resi);
1996
1997 if ((dmacsr & dev->dmareg) == 0)
1998 return IRQ_NONE;
1999
2000 hifn_write_1(dev, HIFN_1_DMA_CSR, dmacsr & dev->dmareg);
2001
2002 if (dmacsr & HIFN_DMACSR_ENGINE)
2003 hifn_write_0(dev, HIFN_0_PUISR, hifn_read_0(dev, HIFN_0_PUISR));
2004 if (dmacsr & HIFN_DMACSR_PUBDONE)
2005 hifn_write_1(dev, HIFN_1_PUB_STATUS,
2006 hifn_read_1(dev, HIFN_1_PUB_STATUS) | HIFN_PUBSTS_DONE);
2007
2008 restart = dmacsr & (HIFN_DMACSR_R_OVER | HIFN_DMACSR_D_OVER);
2009 if (restart) {
2010 u32 puisr = hifn_read_0(dev, HIFN_0_PUISR);
2011
2012 if (printk_ratelimit())
2013 printk("%s: overflow: r: %d, d: %d, puisr: %08x, d: %u.\n",
2014 dev->name, !!(dmacsr & HIFN_DMACSR_R_OVER),
2015 !!(dmacsr & HIFN_DMACSR_D_OVER),
2016 puisr, !!(puisr & HIFN_PUISR_DSTOVER));
2017 if (!!(puisr & HIFN_PUISR_DSTOVER))
2018 hifn_write_0(dev, HIFN_0_PUISR, HIFN_PUISR_DSTOVER);
2019 hifn_write_1(dev, HIFN_1_DMA_CSR, dmacsr & (HIFN_DMACSR_R_OVER |
2020 HIFN_DMACSR_D_OVER));
2021 }
2022
2023 restart = dmacsr & (HIFN_DMACSR_C_ABORT | HIFN_DMACSR_S_ABORT |
2024 HIFN_DMACSR_D_ABORT | HIFN_DMACSR_R_ABORT);
2025 if (restart) {
2026 if (printk_ratelimit())
2027 printk("%s: abort: c: %d, s: %d, d: %d, r: %d.\n",
2028 dev->name, !!(dmacsr & HIFN_DMACSR_C_ABORT),
2029 !!(dmacsr & HIFN_DMACSR_S_ABORT),
2030 !!(dmacsr & HIFN_DMACSR_D_ABORT),
2031 !!(dmacsr & HIFN_DMACSR_R_ABORT));
2032 hifn_reset_dma(dev, 1);
2033 hifn_init_dma(dev);
2034 hifn_init_registers(dev);
2035 }
2036
2037 if ((dmacsr & HIFN_DMACSR_C_WAIT) && (dma->cmdu == 0)) {
2038 dprintk("%s: wait on command.\n", dev->name);
2039 dev->dmareg &= ~(HIFN_DMAIER_C_WAIT);
2040 hifn_write_1(dev, HIFN_1_DMA_IER, dev->dmareg);
2041 }
2042
2043 tasklet_schedule(&dev->tasklet);
2044 hifn_clear_rings(dev);
2045
2046 return IRQ_HANDLED;
2047}
2048
2049static void hifn_flush(struct hifn_device *dev)
2050{
2051 unsigned long flags;
2052 struct crypto_async_request *async_req;
2053 struct hifn_context *ctx;
2054 struct ablkcipher_request *req;
2055 struct hifn_dma *dma = (struct hifn_dma *)dev->desc_virt;
2056 int i;
2057
2058 spin_lock_irqsave(&dev->lock, flags);
2059 for (i=0; i<HIFN_D_RES_RSIZE; ++i) {
2060 struct hifn_desc *d = &dma->resr[i];
2061
2062 if (dev->sa[i]) {
2063 hifn_process_ready(dev->sa[i],
2064 (d->l & __cpu_to_le32(HIFN_D_VALID))?-ENODEV:0);
2065 }
2066 }
2067
2068 while ((async_req = crypto_dequeue_request(&dev->queue))) {
2069 ctx = crypto_tfm_ctx(async_req->tfm);
2070 req = container_of(async_req, struct ablkcipher_request, base);
2071
2072 hifn_process_ready(req, -ENODEV);
2073 }
2074 spin_unlock_irqrestore(&dev->lock, flags);
2075}
2076
2077static int hifn_setkey(struct crypto_ablkcipher *cipher, const u8 *key,
2078 unsigned int len)
2079{
2080 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
2081 struct hifn_context *ctx = crypto_tfm_ctx(tfm);
2082 struct hifn_device *dev = ctx->dev;
2083
2084 if (len > HIFN_MAX_CRYPT_KEY_LENGTH) {
2085 crypto_ablkcipher_set_flags(cipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
2086 return -1;
2087 }
2088
2089 if (len == HIFN_DES_KEY_LENGTH) {
2090 u32 tmp[DES_EXPKEY_WORDS];
2091 int ret = des_ekey(tmp, key);
2092
2093 if (unlikely(ret == 0) && (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
2094 tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
2095 return -EINVAL;
2096 }
2097 }
2098
2099 dev->flags &= ~HIFN_FLAG_OLD_KEY;
2100
2101 memcpy(ctx->key, key, len);
2102 ctx->keysize = len;
2103
2104 return 0;
2105}
2106
2107static int hifn_handle_req(struct ablkcipher_request *req)
2108{
2109 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
2110 struct hifn_device *dev = ctx->dev;
2111 int err = -EAGAIN;
2112
2113 if (dev->started + DIV_ROUND_UP(req->nbytes, PAGE_SIZE) <= HIFN_QUEUE_LENGTH)
2114 err = hifn_setup_session(req);
2115
2116 if (err == -EAGAIN) {
2117 unsigned long flags;
2118
2119 spin_lock_irqsave(&dev->lock, flags);
2120 err = ablkcipher_enqueue_request(&dev->queue, req);
2121 spin_unlock_irqrestore(&dev->lock, flags);
2122 }
2123
2124 return err;
2125}
2126
2127static int hifn_setup_crypto_req(struct ablkcipher_request *req, u8 op,
2128 u8 type, u8 mode)
2129{
2130 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
2131 unsigned ivsize;
2132
2133 ivsize = crypto_ablkcipher_ivsize(crypto_ablkcipher_reqtfm(req));
2134
2135 if (req->info && mode != ACRYPTO_MODE_ECB) {
2136 if (type == ACRYPTO_TYPE_AES_128)
2137 ivsize = HIFN_AES_IV_LENGTH;
2138 else if (type == ACRYPTO_TYPE_DES)
2139 ivsize = HIFN_DES_KEY_LENGTH;
2140 else if (type == ACRYPTO_TYPE_3DES)
2141 ivsize = HIFN_3DES_KEY_LENGTH;
2142 }
2143
2144 if (ctx->keysize != 16 && type == ACRYPTO_TYPE_AES_128) {
2145 if (ctx->keysize == 24)
2146 type = ACRYPTO_TYPE_AES_192;
2147 else if (ctx->keysize == 32)
2148 type = ACRYPTO_TYPE_AES_256;
2149 }
2150
2151 ctx->op = op;
2152 ctx->mode = mode;
2153 ctx->type = type;
2154 ctx->iv = req->info;
2155 ctx->ivsize = ivsize;
2156
2157 /*
2158 * HEAVY TODO: needs to kick Herbert XU to write documentation.
2159 * HEAVY TODO: needs to kick Herbert XU to write documentation.
2160 * HEAVY TODO: needs to kick Herbert XU to write documentation.
2161 */
2162
2163 return hifn_handle_req(req);
2164}
2165
2166static int hifn_process_queue(struct hifn_device *dev)
2167{
2168 struct crypto_async_request *async_req;
2169 struct hifn_context *ctx;
2170 struct ablkcipher_request *req;
2171 unsigned long flags;
2172 int err = 0;
2173
2174 while (dev->started < HIFN_QUEUE_LENGTH) {
2175 spin_lock_irqsave(&dev->lock, flags);
2176 async_req = crypto_dequeue_request(&dev->queue);
2177 spin_unlock_irqrestore(&dev->lock, flags);
2178
2179 if (!async_req)
2180 break;
2181
2182 ctx = crypto_tfm_ctx(async_req->tfm);
2183 req = container_of(async_req, struct ablkcipher_request, base);
2184
2185 err = hifn_handle_req(req);
2186 if (err)
2187 break;
2188 }
2189
2190 return err;
2191}
2192
2193static int hifn_setup_crypto(struct ablkcipher_request *req, u8 op,
2194 u8 type, u8 mode)
2195{
2196 int err;
2197 struct hifn_context *ctx = crypto_tfm_ctx(req->base.tfm);
2198 struct hifn_device *dev = ctx->dev;
2199
2200 err = hifn_setup_crypto_req(req, op, type, mode);
2201 if (err)
2202 return err;
2203
2204 if (dev->started < HIFN_QUEUE_LENGTH && dev->queue.qlen)
2205 err = hifn_process_queue(dev);
2206
2207 return err;
2208}
2209
2210/*
2211 * AES ecryption functions.
2212 */
2213static inline int hifn_encrypt_aes_ecb(struct ablkcipher_request *req)
2214{
2215 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2216 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_ECB);
2217}
2218static inline int hifn_encrypt_aes_cbc(struct ablkcipher_request *req)
2219{
2220 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2221 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CBC);
2222}
2223static inline int hifn_encrypt_aes_cfb(struct ablkcipher_request *req)
2224{
2225 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2226 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CFB);
2227}
2228static inline int hifn_encrypt_aes_ofb(struct ablkcipher_request *req)
2229{
2230 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2231 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_OFB);
2232}
2233
2234/*
2235 * AES decryption functions.
2236 */
2237static inline int hifn_decrypt_aes_ecb(struct ablkcipher_request *req)
2238{
2239 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2240 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_ECB);
2241}
2242static inline int hifn_decrypt_aes_cbc(struct ablkcipher_request *req)
2243{
2244 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2245 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CBC);
2246}
2247static inline int hifn_decrypt_aes_cfb(struct ablkcipher_request *req)
2248{
2249 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2250 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_CFB);
2251}
2252static inline int hifn_decrypt_aes_ofb(struct ablkcipher_request *req)
2253{
2254 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2255 ACRYPTO_TYPE_AES_128, ACRYPTO_MODE_OFB);
2256}
2257
2258/*
2259 * DES ecryption functions.
2260 */
2261static inline int hifn_encrypt_des_ecb(struct ablkcipher_request *req)
2262{
2263 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2264 ACRYPTO_TYPE_DES, ACRYPTO_MODE_ECB);
2265}
2266static inline int hifn_encrypt_des_cbc(struct ablkcipher_request *req)
2267{
2268 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2269 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CBC);
2270}
2271static inline int hifn_encrypt_des_cfb(struct ablkcipher_request *req)
2272{
2273 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2274 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CFB);
2275}
2276static inline int hifn_encrypt_des_ofb(struct ablkcipher_request *req)
2277{
2278 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2279 ACRYPTO_TYPE_DES, ACRYPTO_MODE_OFB);
2280}
2281
2282/*
2283 * DES decryption functions.
2284 */
2285static inline int hifn_decrypt_des_ecb(struct ablkcipher_request *req)
2286{
2287 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2288 ACRYPTO_TYPE_DES, ACRYPTO_MODE_ECB);
2289}
2290static inline int hifn_decrypt_des_cbc(struct ablkcipher_request *req)
2291{
2292 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2293 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CBC);
2294}
2295static inline int hifn_decrypt_des_cfb(struct ablkcipher_request *req)
2296{
2297 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2298 ACRYPTO_TYPE_DES, ACRYPTO_MODE_CFB);
2299}
2300static inline int hifn_decrypt_des_ofb(struct ablkcipher_request *req)
2301{
2302 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2303 ACRYPTO_TYPE_DES, ACRYPTO_MODE_OFB);
2304}
2305
2306/*
2307 * 3DES ecryption functions.
2308 */
2309static inline int hifn_encrypt_3des_ecb(struct ablkcipher_request *req)
2310{
2311 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2312 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_ECB);
2313}
2314static inline int hifn_encrypt_3des_cbc(struct ablkcipher_request *req)
2315{
2316 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2317 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CBC);
2318}
2319static inline int hifn_encrypt_3des_cfb(struct ablkcipher_request *req)
2320{
2321 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2322 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CFB);
2323}
2324static inline int hifn_encrypt_3des_ofb(struct ablkcipher_request *req)
2325{
2326 return hifn_setup_crypto(req, ACRYPTO_OP_ENCRYPT,
2327 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_OFB);
2328}
2329
2330/*
2331 * 3DES decryption functions.
2332 */
2333static inline int hifn_decrypt_3des_ecb(struct ablkcipher_request *req)
2334{
2335 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2336 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_ECB);
2337}
2338static inline int hifn_decrypt_3des_cbc(struct ablkcipher_request *req)
2339{
2340 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2341 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CBC);
2342}
2343static inline int hifn_decrypt_3des_cfb(struct ablkcipher_request *req)
2344{
2345 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2346 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_CFB);
2347}
2348static inline int hifn_decrypt_3des_ofb(struct ablkcipher_request *req)
2349{
2350 return hifn_setup_crypto(req, ACRYPTO_OP_DECRYPT,
2351 ACRYPTO_TYPE_3DES, ACRYPTO_MODE_OFB);
2352}
2353
2354struct hifn_alg_template
2355{
2356 char name[CRYPTO_MAX_ALG_NAME];
2357 char drv_name[CRYPTO_MAX_ALG_NAME];
2358 unsigned int bsize;
2359 struct ablkcipher_alg ablkcipher;
2360};
2361
2362static struct hifn_alg_template hifn_alg_templates[] = {
2363 /*
2364 * 3DES ECB, CBC, CFB and OFB modes.
2365 */
2366 {
2367 .name = "cfb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
2368 .ablkcipher = {
2369 .min_keysize = HIFN_3DES_KEY_LENGTH,
2370 .max_keysize = HIFN_3DES_KEY_LENGTH,
2371 .setkey = hifn_setkey,
2372 .encrypt = hifn_encrypt_3des_cfb,
2373 .decrypt = hifn_decrypt_3des_cfb,
2374 },
2375 },
2376 {
2377 .name = "ofb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
2378 .ablkcipher = {
2379 .min_keysize = HIFN_3DES_KEY_LENGTH,
2380 .max_keysize = HIFN_3DES_KEY_LENGTH,
2381 .setkey = hifn_setkey,
2382 .encrypt = hifn_encrypt_3des_ofb,
2383 .decrypt = hifn_decrypt_3des_ofb,
2384 },
2385 },
2386 {
2387 .name = "cbc(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
2388 .ablkcipher = {
2389 .min_keysize = HIFN_3DES_KEY_LENGTH,
2390 .max_keysize = HIFN_3DES_KEY_LENGTH,
2391 .setkey = hifn_setkey,
2392 .encrypt = hifn_encrypt_3des_cbc,
2393 .decrypt = hifn_decrypt_3des_cbc,
2394 },
2395 },
2396 {
2397 .name = "ecb(des3_ede)", .drv_name = "hifn-3des", .bsize = 8,
2398 .ablkcipher = {
2399 .min_keysize = HIFN_3DES_KEY_LENGTH,
2400 .max_keysize = HIFN_3DES_KEY_LENGTH,
2401 .setkey = hifn_setkey,
2402 .encrypt = hifn_encrypt_3des_ecb,
2403 .decrypt = hifn_decrypt_3des_ecb,
2404 },
2405 },
2406
2407 /*
2408 * DES ECB, CBC, CFB and OFB modes.
2409 */
2410 {
2411 .name = "cfb(des)", .drv_name = "hifn-des", .bsize = 8,
2412 .ablkcipher = {
2413 .min_keysize = HIFN_DES_KEY_LENGTH,
2414 .max_keysize = HIFN_DES_KEY_LENGTH,
2415 .setkey = hifn_setkey,
2416 .encrypt = hifn_encrypt_des_cfb,
2417 .decrypt = hifn_decrypt_des_cfb,
2418 },
2419 },
2420 {
2421 .name = "ofb(des)", .drv_name = "hifn-des", .bsize = 8,
2422 .ablkcipher = {
2423 .min_keysize = HIFN_DES_KEY_LENGTH,
2424 .max_keysize = HIFN_DES_KEY_LENGTH,
2425 .setkey = hifn_setkey,
2426 .encrypt = hifn_encrypt_des_ofb,
2427 .decrypt = hifn_decrypt_des_ofb,
2428 },
2429 },
2430 {
2431 .name = "cbc(des)", .drv_name = "hifn-des", .bsize = 8,
2432 .ablkcipher = {
2433 .min_keysize = HIFN_DES_KEY_LENGTH,
2434 .max_keysize = HIFN_DES_KEY_LENGTH,
2435 .setkey = hifn_setkey,
2436 .encrypt = hifn_encrypt_des_cbc,
2437 .decrypt = hifn_decrypt_des_cbc,
2438 },
2439 },
2440 {
2441 .name = "ecb(des)", .drv_name = "hifn-des", .bsize = 8,
2442 .ablkcipher = {
2443 .min_keysize = HIFN_DES_KEY_LENGTH,
2444 .max_keysize = HIFN_DES_KEY_LENGTH,
2445 .setkey = hifn_setkey,
2446 .encrypt = hifn_encrypt_des_ecb,
2447 .decrypt = hifn_decrypt_des_ecb,
2448 },
2449 },
2450
2451 /*
2452 * AES ECB, CBC, CFB and OFB modes.
2453 */
2454 {
2455 .name = "ecb(aes)", .drv_name = "hifn-aes", .bsize = 16,
2456 .ablkcipher = {
2457 .min_keysize = AES_MIN_KEY_SIZE,
2458 .max_keysize = AES_MAX_KEY_SIZE,
2459 .setkey = hifn_setkey,
2460 .encrypt = hifn_encrypt_aes_ecb,
2461 .decrypt = hifn_decrypt_aes_ecb,
2462 },
2463 },
2464 {
2465 .name = "cbc(aes)", .drv_name = "hifn-aes", .bsize = 16,
2466 .ablkcipher = {
2467 .min_keysize = AES_MIN_KEY_SIZE,
2468 .max_keysize = AES_MAX_KEY_SIZE,
2469 .setkey = hifn_setkey,
2470 .encrypt = hifn_encrypt_aes_cbc,
2471 .decrypt = hifn_decrypt_aes_cbc,
2472 },
2473 },
2474 {
2475 .name = "cfb(aes)", .drv_name = "hifn-aes", .bsize = 16,
2476 .ablkcipher = {
2477 .min_keysize = AES_MIN_KEY_SIZE,
2478 .max_keysize = AES_MAX_KEY_SIZE,
2479 .setkey = hifn_setkey,
2480 .encrypt = hifn_encrypt_aes_cfb,
2481 .decrypt = hifn_decrypt_aes_cfb,
2482 },
2483 },
2484 {
2485 .name = "ofb(aes)", .drv_name = "hifn-aes", .bsize = 16,
2486 .ablkcipher = {
2487 .min_keysize = AES_MIN_KEY_SIZE,
2488 .max_keysize = AES_MAX_KEY_SIZE,
2489 .setkey = hifn_setkey,
2490 .encrypt = hifn_encrypt_aes_ofb,
2491 .decrypt = hifn_decrypt_aes_ofb,
2492 },
2493 },
2494};
2495
2496static int hifn_cra_init(struct crypto_tfm *tfm)
2497{
2498 struct crypto_alg *alg = tfm->__crt_alg;
2499 struct hifn_crypto_alg *ha = crypto_alg_to_hifn(alg);
2500 struct hifn_context *ctx = crypto_tfm_ctx(tfm);
2501
2502 ctx->dev = ha->dev;
2503
2504 return 0;
2505}
2506
2507static int hifn_alg_alloc(struct hifn_device *dev, struct hifn_alg_template *t)
2508{
2509 struct hifn_crypto_alg *alg;
2510 int err;
2511
2512 alg = kzalloc(sizeof(struct hifn_crypto_alg), GFP_KERNEL);
2513 if (!alg)
2514 return -ENOMEM;
2515
2516 snprintf(alg->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s", t->name);
2517 snprintf(alg->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", t->drv_name);
2518
2519 alg->alg.cra_priority = 300;
2520 alg->alg.cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC;
2521 alg->alg.cra_blocksize = t->bsize;
2522 alg->alg.cra_ctxsize = sizeof(struct hifn_context);
2523 alg->alg.cra_alignmask = 15;
2524 if (t->bsize == 8)
2525 alg->alg.cra_alignmask = 3;
2526 alg->alg.cra_type = &crypto_ablkcipher_type;
2527 alg->alg.cra_module = THIS_MODULE;
2528 alg->alg.cra_u.ablkcipher = t->ablkcipher;
2529 alg->alg.cra_init = hifn_cra_init;
2530
2531 alg->dev = dev;
2532
2533 list_add_tail(&alg->entry, &dev->alg_list);
2534
2535 err = crypto_register_alg(&alg->alg);
2536 if (err) {
2537 list_del(&alg->entry);
2538 kfree(alg);
2539 }
2540
2541 return err;
2542}
2543
2544static void hifn_unregister_alg(struct hifn_device *dev)
2545{
2546 struct hifn_crypto_alg *a, *n;
2547
2548 list_for_each_entry_safe(a, n, &dev->alg_list, entry) {
2549 list_del(&a->entry);
2550 crypto_unregister_alg(&a->alg);
2551 kfree(a);
2552 }
2553}
2554
2555static int hifn_register_alg(struct hifn_device *dev)
2556{
2557 int i, err;
2558
2559 for (i=0; i<ARRAY_SIZE(hifn_alg_templates); ++i) {
2560 err = hifn_alg_alloc(dev, &hifn_alg_templates[i]);
2561 if (err)
2562 goto err_out_exit;
2563 }
2564
2565 return 0;
2566
2567err_out_exit:
2568 hifn_unregister_alg(dev);
2569 return err;
2570}
2571
2572static void hifn_tasklet_callback(unsigned long data)
2573{
2574 struct hifn_device *dev = (struct hifn_device *)data;
2575
2576 /*
2577 * This is ok to call this without lock being held,
2578 * althogh it modifies some parameters used in parallel,
2579 * (like dev->success), but they are used in process
2580 * context or update is atomic (like setting dev->sa[i] to NULL).
2581 */
2582 hifn_check_for_completion(dev, 0);
2583}
2584
2585static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2586{
2587 int err, i;
2588 struct hifn_device *dev;
2589 char name[8];
2590
2591 err = pci_enable_device(pdev);
2592 if (err)
2593 return err;
2594 pci_set_master(pdev);
2595
2596 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2597 if (err)
2598 goto err_out_disable_pci_device;
2599
2600 snprintf(name, sizeof(name), "hifn%d",
2601 atomic_inc_return(&hifn_dev_number)-1);
2602
2603 err = pci_request_regions(pdev, name);
2604 if (err)
2605 goto err_out_disable_pci_device;
2606
2607 if (pci_resource_len(pdev, 0) < HIFN_BAR0_SIZE ||
2608 pci_resource_len(pdev, 1) < HIFN_BAR1_SIZE ||
2609 pci_resource_len(pdev, 2) < HIFN_BAR2_SIZE) {
2610 dprintk("%s: Broken hardware - I/O regions are too small.\n",
2611 pci_name(pdev));
2612 err = -ENODEV;
2613 goto err_out_free_regions;
2614 }
2615
2616 dev = kzalloc(sizeof(struct hifn_device) + sizeof(struct crypto_alg),
2617 GFP_KERNEL);
2618 if (!dev) {
2619 err = -ENOMEM;
2620 goto err_out_free_regions;
2621 }
2622
2623 INIT_LIST_HEAD(&dev->alg_list);
2624
2625 snprintf(dev->name, sizeof(dev->name), "%s", name);
2626 spin_lock_init(&dev->lock);
2627
2628 for (i=0; i<3; ++i) {
2629 unsigned long addr, size;
2630
2631 addr = pci_resource_start(pdev, i);
2632 size = pci_resource_len(pdev, i);
2633
2634 dev->bar[i] = ioremap_nocache(addr, size);
2635 if (!dev->bar[i])
2636 goto err_out_unmap_bars;
2637 }
2638
2639 dev->result_mem = __get_free_pages(GFP_KERNEL, HIFN_MAX_RESULT_ORDER);
2640 if (!dev->result_mem) {
2641 dprintk("Failed to allocate %d pages for result_mem.\n",
2642 HIFN_MAX_RESULT_ORDER);
2643 goto err_out_unmap_bars;
2644 }
2645 memset((void *)dev->result_mem, 0, PAGE_SIZE*(1<<HIFN_MAX_RESULT_ORDER));
2646
2647 dev->dst = pci_map_single(pdev, (void *)dev->result_mem,
2648 PAGE_SIZE << HIFN_MAX_RESULT_ORDER, PCI_DMA_FROMDEVICE);
2649
2650 dev->desc_virt = pci_alloc_consistent(pdev, sizeof(struct hifn_dma),
2651 &dev->desc_dma);
2652 if (!dev->desc_virt) {
2653 dprintk("Failed to allocate descriptor rings.\n");
2654 goto err_out_free_result_pages;
2655 }
2656 memset(dev->desc_virt, 0, sizeof(struct hifn_dma));
2657
2658 dev->pdev = pdev;
2659 dev->irq = pdev->irq;
2660
2661 for (i=0; i<HIFN_D_RES_RSIZE; ++i)
2662 dev->sa[i] = NULL;
2663
2664 pci_set_drvdata(pdev, dev);
2665
2666 tasklet_init(&dev->tasklet, hifn_tasklet_callback, (unsigned long)dev);
2667
2668 crypto_init_queue(&dev->queue, 1);
2669
2670 err = request_irq(dev->irq, hifn_interrupt, IRQF_SHARED, dev->name, dev);
2671 if (err) {
2672 dprintk("Failed to request IRQ%d: err: %d.\n", dev->irq, err);
2673 dev->irq = 0;
2674 goto err_out_free_desc;
2675 }
2676
2677 err = hifn_start_device(dev);
2678 if (err)
2679 goto err_out_free_irq;
2680
2681 err = hifn_test(dev, 1, 0);
2682 if (err)
2683 goto err_out_stop_device;
2684
2685 err = hifn_register_rng(dev);
2686 if (err)
2687 goto err_out_stop_device;
2688
2689 err = hifn_register_alg(dev);
2690 if (err)
2691 goto err_out_unregister_rng;
2692
2693 INIT_DELAYED_WORK(&dev->work, hifn_work);
2694 schedule_delayed_work(&dev->work, HZ);
2695
2696 dprintk("HIFN crypto accelerator card at %s has been "
2697 "successfully registered as %s.\n",
2698 pci_name(pdev), dev->name);
2699
2700 return 0;
2701
2702err_out_unregister_rng:
2703 hifn_unregister_rng(dev);
2704err_out_stop_device:
2705 hifn_reset_dma(dev, 1);
2706 hifn_stop_device(dev);
2707err_out_free_irq:
2708 free_irq(dev->irq, dev->name);
2709 tasklet_kill(&dev->tasklet);
2710err_out_free_desc:
2711 pci_free_consistent(pdev, sizeof(struct hifn_dma),
2712 dev->desc_virt, dev->desc_dma);
2713
2714err_out_free_result_pages:
2715 pci_unmap_single(pdev, dev->dst, PAGE_SIZE << HIFN_MAX_RESULT_ORDER,
2716 PCI_DMA_FROMDEVICE);
2717 free_pages(dev->result_mem, HIFN_MAX_RESULT_ORDER);
2718
2719err_out_unmap_bars:
2720 for (i=0; i<3; ++i)
2721 if (dev->bar[i])
2722 iounmap(dev->bar[i]);
2723
2724err_out_free_regions:
2725 pci_release_regions(pdev);
2726
2727err_out_disable_pci_device:
2728 pci_disable_device(pdev);
2729
2730 return err;
2731}
2732
2733static void hifn_remove(struct pci_dev *pdev)
2734{
2735 int i;
2736 struct hifn_device *dev;
2737
2738 dev = pci_get_drvdata(pdev);
2739
2740 if (dev) {
2741 cancel_delayed_work(&dev->work);
2742 flush_scheduled_work();
2743
2744 hifn_unregister_rng(dev);
2745 hifn_unregister_alg(dev);
2746 hifn_reset_dma(dev, 1);
2747 hifn_stop_device(dev);
2748
2749 free_irq(dev->irq, dev->name);
2750 tasklet_kill(&dev->tasklet);
2751
2752 hifn_flush(dev);
2753
2754 pci_free_consistent(pdev, sizeof(struct hifn_dma),
2755 dev->desc_virt, dev->desc_dma);
2756 pci_unmap_single(pdev, dev->dst,
2757 PAGE_SIZE << HIFN_MAX_RESULT_ORDER,
2758 PCI_DMA_FROMDEVICE);
2759 free_pages(dev->result_mem, HIFN_MAX_RESULT_ORDER);
2760 for (i=0; i<3; ++i)
2761 if (dev->bar[i])
2762 iounmap(dev->bar[i]);
2763
2764 kfree(dev);
2765 }
2766
2767 pci_release_regions(pdev);
2768 pci_disable_device(pdev);
2769}
2770
2771static struct pci_device_id hifn_pci_tbl[] = {
2772 { PCI_DEVICE(PCI_VENDOR_ID_HIFN, PCI_DEVICE_ID_HIFN_7955) },
2773 { PCI_DEVICE(PCI_VENDOR_ID_HIFN, PCI_DEVICE_ID_HIFN_7956) },
2774 { 0 }
2775};
2776MODULE_DEVICE_TABLE(pci, hifn_pci_tbl);
2777
2778static struct pci_driver hifn_pci_driver = {
2779 .name = "hifn795x",
2780 .id_table = hifn_pci_tbl,
2781 .probe = hifn_probe,
2782 .remove = __devexit_p(hifn_remove),
2783};
2784
2785static int __devinit hifn_init(void)
2786{
2787 unsigned int freq;
2788 int err;
2789
2790 if (strncmp(hifn_pll_ref, "ext", 3) &&
2791 strncmp(hifn_pll_ref, "pci", 3)) {
2792 printk(KERN_ERR "hifn795x: invalid hifn_pll_ref clock, "
2793 "must be pci or ext");
2794 return -EINVAL;
2795 }
2796
2797 /*
2798 * For the 7955/7956 the reference clock frequency must be in the
2799 * range of 20MHz-100MHz. For the 7954 the upper bound is 66.67MHz,
2800 * but this chip is currently not supported.
2801 */
2802 if (hifn_pll_ref[3] != '\0') {
2803 freq = simple_strtoul(hifn_pll_ref + 3, NULL, 10);
2804 if (freq < 20 || freq > 100) {
2805 printk(KERN_ERR "hifn795x: invalid hifn_pll_ref "
2806 "frequency, must be in the range "
2807 "of 20-100");
2808 return -EINVAL;
2809 }
2810 }
2811
2812 err = pci_register_driver(&hifn_pci_driver);
2813 if (err < 0) {
2814 dprintk("Failed to register PCI driver for %s device.\n",
2815 hifn_pci_driver.name);
2816 return -ENODEV;
2817 }
2818
2819 printk(KERN_INFO "Driver for HIFN 795x crypto accelerator chip "
2820 "has been successfully registered.\n");
2821
2822 return 0;
2823}
2824
2825static void __devexit hifn_fini(void)
2826{
2827 pci_unregister_driver(&hifn_pci_driver);
2828
2829 printk(KERN_INFO "Driver for HIFN 795x crypto accelerator chip "
2830 "has been successfully unregistered.\n");
2831}
2832
2833module_init(hifn_init);
2834module_exit(hifn_fini);
2835
2836MODULE_LICENSE("GPL");
2837MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
2838MODULE_DESCRIPTION("Driver for HIFN 795x crypto accelerator chip.");
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index 5f7e71810489..2f3ad3f7dfea 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -44,6 +44,7 @@
44 */ 44 */
45 45
46#include <crypto/algapi.h> 46#include <crypto/algapi.h>
47#include <crypto/aes.h>
47#include <linux/module.h> 48#include <linux/module.h>
48#include <linux/init.h> 49#include <linux/init.h>
49#include <linux/types.h> 50#include <linux/types.h>
@@ -53,9 +54,6 @@
53#include <asm/byteorder.h> 54#include <asm/byteorder.h>
54#include "padlock.h" 55#include "padlock.h"
55 56
56#define AES_MIN_KEY_SIZE 16 /* in uint8_t units */
57#define AES_MAX_KEY_SIZE 32 /* ditto */
58#define AES_BLOCK_SIZE 16 /* ditto */
59#define AES_EXTENDED_KEY_SIZE 64 /* in uint32_t units */ 57#define AES_EXTENDED_KEY_SIZE 64 /* in uint32_t units */
60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t)) 58#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
61 59
@@ -419,6 +417,11 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
419/* ====== Encryption/decryption routines ====== */ 417/* ====== Encryption/decryption routines ====== */
420 418
421/* These are the real call to PadLock. */ 419/* These are the real call to PadLock. */
420static inline void padlock_reset_key(void)
421{
422 asm volatile ("pushfl; popfl");
423}
424
422static inline void padlock_xcrypt(const u8 *input, u8 *output, void *key, 425static inline void padlock_xcrypt(const u8 *input, u8 *output, void *key,
423 void *control_word) 426 void *control_word)
424{ 427{
@@ -439,8 +442,6 @@ static void aes_crypt_copy(const u8 *in, u8 *out, u32 *key, struct cword *cword)
439static inline void aes_crypt(const u8 *in, u8 *out, u32 *key, 442static inline void aes_crypt(const u8 *in, u8 *out, u32 *key,
440 struct cword *cword) 443 struct cword *cword)
441{ 444{
442 asm volatile ("pushfl; popfl");
443
444 /* padlock_xcrypt requires at least two blocks of data. */ 445 /* padlock_xcrypt requires at least two blocks of data. */
445 if (unlikely(!(((unsigned long)in ^ (PAGE_SIZE - AES_BLOCK_SIZE)) & 446 if (unlikely(!(((unsigned long)in ^ (PAGE_SIZE - AES_BLOCK_SIZE)) &
446 (PAGE_SIZE - 1)))) { 447 (PAGE_SIZE - 1)))) {
@@ -459,7 +460,6 @@ static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
459 return; 460 return;
460 } 461 }
461 462
462 asm volatile ("pushfl; popfl"); /* enforce key reload. */
463 asm volatile ("test $1, %%cl;" 463 asm volatile ("test $1, %%cl;"
464 "je 1f;" 464 "je 1f;"
465 "lea -1(%%ecx), %%eax;" 465 "lea -1(%%ecx), %%eax;"
@@ -476,8 +476,6 @@ static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
476static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key, 476static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
477 u8 *iv, void *control_word, u32 count) 477 u8 *iv, void *control_word, u32 count)
478{ 478{
479 /* Enforce key reload. */
480 asm volatile ("pushfl; popfl");
481 /* rep xcryptcbc */ 479 /* rep xcryptcbc */
482 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0" 480 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
483 : "+S" (input), "+D" (output), "+a" (iv) 481 : "+S" (input), "+D" (output), "+a" (iv)
@@ -488,12 +486,14 @@ static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
488static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 486static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
489{ 487{
490 struct aes_ctx *ctx = aes_ctx(tfm); 488 struct aes_ctx *ctx = aes_ctx(tfm);
489 padlock_reset_key();
491 aes_crypt(in, out, ctx->E, &ctx->cword.encrypt); 490 aes_crypt(in, out, ctx->E, &ctx->cword.encrypt);
492} 491}
493 492
494static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 493static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
495{ 494{
496 struct aes_ctx *ctx = aes_ctx(tfm); 495 struct aes_ctx *ctx = aes_ctx(tfm);
496 padlock_reset_key();
497 aes_crypt(in, out, ctx->D, &ctx->cword.decrypt); 497 aes_crypt(in, out, ctx->D, &ctx->cword.decrypt);
498} 498}
499 499
@@ -526,6 +526,8 @@ static int ecb_aes_encrypt(struct blkcipher_desc *desc,
526 struct blkcipher_walk walk; 526 struct blkcipher_walk walk;
527 int err; 527 int err;
528 528
529 padlock_reset_key();
530
529 blkcipher_walk_init(&walk, dst, src, nbytes); 531 blkcipher_walk_init(&walk, dst, src, nbytes);
530 err = blkcipher_walk_virt(desc, &walk); 532 err = blkcipher_walk_virt(desc, &walk);
531 533
@@ -548,6 +550,8 @@ static int ecb_aes_decrypt(struct blkcipher_desc *desc,
548 struct blkcipher_walk walk; 550 struct blkcipher_walk walk;
549 int err; 551 int err;
550 552
553 padlock_reset_key();
554
551 blkcipher_walk_init(&walk, dst, src, nbytes); 555 blkcipher_walk_init(&walk, dst, src, nbytes);
552 err = blkcipher_walk_virt(desc, &walk); 556 err = blkcipher_walk_virt(desc, &walk);
553 557
@@ -592,6 +596,8 @@ static int cbc_aes_encrypt(struct blkcipher_desc *desc,
592 struct blkcipher_walk walk; 596 struct blkcipher_walk walk;
593 int err; 597 int err;
594 598
599 padlock_reset_key();
600
595 blkcipher_walk_init(&walk, dst, src, nbytes); 601 blkcipher_walk_init(&walk, dst, src, nbytes);
596 err = blkcipher_walk_virt(desc, &walk); 602 err = blkcipher_walk_virt(desc, &walk);
597 603
@@ -616,6 +622,8 @@ static int cbc_aes_decrypt(struct blkcipher_desc *desc,
616 struct blkcipher_walk walk; 622 struct blkcipher_walk walk;
617 int err; 623 int err;
618 624
625 padlock_reset_key();
626
619 blkcipher_walk_init(&walk, dst, src, nbytes); 627 blkcipher_walk_init(&walk, dst, src, nbytes);
620 err = blkcipher_walk_virt(desc, &walk); 628 err = blkcipher_walk_virt(desc, &walk);
621 629
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index d59b2f417306..bcf52df30339 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -41,12 +41,12 @@
41 * the definition of dma_event_callback in dmaengine.h. 41 * the definition of dma_event_callback in dmaengine.h.
42 * 42 *
43 * Each device has a kref, which is initialized to 1 when the device is 43 * Each device has a kref, which is initialized to 1 when the device is
44 * registered. A kref_get is done for each class_device registered. When the 44 * registered. A kref_get is done for each device registered. When the
45 * class_device is released, the coresponding kref_put is done in the release 45 * device is released, the coresponding kref_put is done in the release
46 * method. Every time one of the device's channels is allocated to a client, 46 * method. Every time one of the device's channels is allocated to a client,
47 * a kref_get occurs. When the channel is freed, the coresponding kref_put 47 * a kref_get occurs. When the channel is freed, the coresponding kref_put
48 * happens. The device's release function does a completion, so 48 * happens. The device's release function does a completion, so
49 * unregister_device does a remove event, class_device_unregister, a kref_put 49 * unregister_device does a remove event, device_unregister, a kref_put
50 * for the first reference, then waits on the completion for all other 50 * for the first reference, then waits on the completion for all other
51 * references to finish. 51 * references to finish.
52 * 52 *
@@ -77,9 +77,9 @@ static LIST_HEAD(dma_client_list);
77 77
78/* --- sysfs implementation --- */ 78/* --- sysfs implementation --- */
79 79
80static ssize_t show_memcpy_count(struct class_device *cd, char *buf) 80static ssize_t show_memcpy_count(struct device *dev, struct device_attribute *attr, char *buf)
81{ 81{
82 struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); 82 struct dma_chan *chan = to_dma_chan(dev);
83 unsigned long count = 0; 83 unsigned long count = 0;
84 int i; 84 int i;
85 85
@@ -89,9 +89,10 @@ static ssize_t show_memcpy_count(struct class_device *cd, char *buf)
89 return sprintf(buf, "%lu\n", count); 89 return sprintf(buf, "%lu\n", count);
90} 90}
91 91
92static ssize_t show_bytes_transferred(struct class_device *cd, char *buf) 92static ssize_t show_bytes_transferred(struct device *dev, struct device_attribute *attr,
93 char *buf)
93{ 94{
94 struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); 95 struct dma_chan *chan = to_dma_chan(dev);
95 unsigned long count = 0; 96 unsigned long count = 0;
96 int i; 97 int i;
97 98
@@ -101,9 +102,9 @@ static ssize_t show_bytes_transferred(struct class_device *cd, char *buf)
101 return sprintf(buf, "%lu\n", count); 102 return sprintf(buf, "%lu\n", count);
102} 103}
103 104
104static ssize_t show_in_use(struct class_device *cd, char *buf) 105static ssize_t show_in_use(struct device *dev, struct device_attribute *attr, char *buf)
105{ 106{
106 struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); 107 struct dma_chan *chan = to_dma_chan(dev);
107 int in_use = 0; 108 int in_use = 0;
108 109
109 if (unlikely(chan->slow_ref) && 110 if (unlikely(chan->slow_ref) &&
@@ -119,7 +120,7 @@ static ssize_t show_in_use(struct class_device *cd, char *buf)
119 return sprintf(buf, "%d\n", in_use); 120 return sprintf(buf, "%d\n", in_use);
120} 121}
121 122
122static struct class_device_attribute dma_class_attrs[] = { 123static struct device_attribute dma_attrs[] = {
123 __ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL), 124 __ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL),
124 __ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL), 125 __ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL),
125 __ATTR(in_use, S_IRUGO, show_in_use, NULL), 126 __ATTR(in_use, S_IRUGO, show_in_use, NULL),
@@ -128,16 +129,16 @@ static struct class_device_attribute dma_class_attrs[] = {
128 129
129static void dma_async_device_cleanup(struct kref *kref); 130static void dma_async_device_cleanup(struct kref *kref);
130 131
131static void dma_class_dev_release(struct class_device *cd) 132static void dma_dev_release(struct device *dev)
132{ 133{
133 struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); 134 struct dma_chan *chan = to_dma_chan(dev);
134 kref_put(&chan->device->refcount, dma_async_device_cleanup); 135 kref_put(&chan->device->refcount, dma_async_device_cleanup);
135} 136}
136 137
137static struct class dma_devclass = { 138static struct class dma_devclass = {
138 .name = "dma", 139 .name = "dma",
139 .class_dev_attrs = dma_class_attrs, 140 .dev_attrs = dma_attrs,
140 .release = dma_class_dev_release, 141 .dev_release = dma_dev_release,
141}; 142};
142 143
143/* --- client and device registration --- */ 144/* --- client and device registration --- */
@@ -377,12 +378,12 @@ int dma_async_device_register(struct dma_device *device)
377 continue; 378 continue;
378 379
379 chan->chan_id = chancnt++; 380 chan->chan_id = chancnt++;
380 chan->class_dev.class = &dma_devclass; 381 chan->dev.class = &dma_devclass;
381 chan->class_dev.dev = NULL; 382 chan->dev.parent = NULL;
382 snprintf(chan->class_dev.class_id, BUS_ID_SIZE, "dma%dchan%d", 383 snprintf(chan->dev.bus_id, BUS_ID_SIZE, "dma%dchan%d",
383 device->dev_id, chan->chan_id); 384 device->dev_id, chan->chan_id);
384 385
385 rc = class_device_register(&chan->class_dev); 386 rc = device_register(&chan->dev);
386 if (rc) { 387 if (rc) {
387 chancnt--; 388 chancnt--;
388 free_percpu(chan->local); 389 free_percpu(chan->local);
@@ -411,7 +412,7 @@ err_out:
411 if (chan->local == NULL) 412 if (chan->local == NULL)
412 continue; 413 continue;
413 kref_put(&device->refcount, dma_async_device_cleanup); 414 kref_put(&device->refcount, dma_async_device_cleanup);
414 class_device_unregister(&chan->class_dev); 415 device_unregister(&chan->dev);
415 chancnt--; 416 chancnt--;
416 free_percpu(chan->local); 417 free_percpu(chan->local);
417 } 418 }
@@ -445,7 +446,7 @@ void dma_async_device_unregister(struct dma_device *device)
445 446
446 list_for_each_entry(chan, &device->channels, device_node) { 447 list_for_each_entry(chan, &device->channels, device_node) {
447 dma_clients_notify_removed(chan); 448 dma_clients_notify_removed(chan);
448 class_device_unregister(&chan->class_dev); 449 device_unregister(&chan->dev);
449 dma_chan_release(chan); 450 dma_chan_release(chan);
450 } 451 }
451 452
diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 70b837f23c43..53764577035f 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -246,16 +246,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
246 246
247 /* Init the devices's kobject */ 247 /* Init the devices's kobject */
248 memset(&edac_dev->kobj, 0, sizeof(struct kobject)); 248 memset(&edac_dev->kobj, 0, sizeof(struct kobject));
249 edac_dev->kobj.ktype = &ktype_device_ctrl;
250
251 /* set this new device under the edac_class kobject */
252 edac_dev->kobj.parent = &edac_class->kset.kobj;
253
254 /* generate sysfs "..../edac/<name>" */
255 debugf4("%s() set name of kobject to: %s\n", __func__, edac_dev->name);
256 err = kobject_set_name(&edac_dev->kobj, "%s", edac_dev->name);
257 if (err)
258 goto err_out;
259 249
260 /* Record which module 'owns' this control structure 250 /* Record which module 'owns' this control structure
261 * and bump the ref count of the module 251 * and bump the ref count of the module
@@ -268,12 +258,15 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
268 } 258 }
269 259
270 /* register */ 260 /* register */
271 err = kobject_register(&edac_dev->kobj); 261 err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl,
262 &edac_class->kset.kobj,
263 "%s", edac_dev->name);
272 if (err) { 264 if (err) {
273 debugf1("%s()Failed to register '.../edac/%s'\n", 265 debugf1("%s()Failed to register '.../edac/%s'\n",
274 __func__, edac_dev->name); 266 __func__, edac_dev->name);
275 goto err_kobj_reg; 267 goto err_kobj_reg;
276 } 268 }
269 kobject_uevent(&edac_dev->kobj, KOBJ_ADD);
277 270
278 /* At this point, to 'free' the control struct, 271 /* At this point, to 'free' the control struct,
279 * edac_device_unregister_sysfs_main_kobj() must be used 272 * edac_device_unregister_sysfs_main_kobj() must be used
@@ -310,7 +303,7 @@ void edac_device_unregister_sysfs_main_kobj(
310 * a) module_put() this module 303 * a) module_put() this module
311 * b) 'kfree' the memory 304 * b) 'kfree' the memory
312 */ 305 */
313 kobject_unregister(&edac_dev->kobj); 306 kobject_put(&edac_dev->kobj);
314} 307}
315 308
316/* edac_dev -> instance information */ 309/* edac_dev -> instance information */
@@ -533,12 +526,6 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
533 526
534 /* init this block's kobject */ 527 /* init this block's kobject */
535 memset(&block->kobj, 0, sizeof(struct kobject)); 528 memset(&block->kobj, 0, sizeof(struct kobject));
536 block->kobj.parent = &instance->kobj;
537 block->kobj.ktype = &ktype_block_ctrl;
538
539 err = kobject_set_name(&block->kobj, "%s", block->name);
540 if (err)
541 return err;
542 529
543 /* bump the main kobject's reference count for this controller 530 /* bump the main kobject's reference count for this controller
544 * and this instance is dependant on the main 531 * and this instance is dependant on the main
@@ -550,7 +537,9 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
550 } 537 }
551 538
552 /* Add this block's kobject */ 539 /* Add this block's kobject */
553 err = kobject_register(&block->kobj); 540 err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,
541 &instance->kobj,
542 "%s", block->name);
554 if (err) { 543 if (err) {
555 debugf1("%s() Failed to register instance '%s'\n", 544 debugf1("%s() Failed to register instance '%s'\n",
556 __func__, block->name); 545 __func__, block->name);
@@ -579,12 +568,13 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
579 goto err_on_attrib; 568 goto err_on_attrib;
580 } 569 }
581 } 570 }
571 kobject_uevent(&block->kobj, KOBJ_ADD);
582 572
583 return 0; 573 return 0;
584 574
585 /* Error unwind stack */ 575 /* Error unwind stack */
586err_on_attrib: 576err_on_attrib:
587 kobject_unregister(&block->kobj); 577 kobject_put(&block->kobj);
588 578
589err_out: 579err_out:
590 return err; 580 return err;
@@ -615,7 +605,7 @@ static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,
615 /* unregister this block's kobject, SEE: 605 /* unregister this block's kobject, SEE:
616 * edac_device_ctrl_block_release() callback operation 606 * edac_device_ctrl_block_release() callback operation
617 */ 607 */
618 kobject_unregister(&block->kobj); 608 kobject_put(&block->kobj);
619} 609}
620 610
621/* instance ctor/dtor code */ 611/* instance ctor/dtor code */
@@ -637,15 +627,8 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
637 /* Init the instance's kobject */ 627 /* Init the instance's kobject */
638 memset(&instance->kobj, 0, sizeof(struct kobject)); 628 memset(&instance->kobj, 0, sizeof(struct kobject));
639 629
640 /* set this new device under the edac_device main kobject */
641 instance->kobj.parent = &edac_dev->kobj;
642 instance->kobj.ktype = &ktype_instance_ctrl;
643 instance->ctl = edac_dev; 630 instance->ctl = edac_dev;
644 631
645 err = kobject_set_name(&instance->kobj, "%s", instance->name);
646 if (err)
647 goto err_out;
648
649 /* bump the main kobject's reference count for this controller 632 /* bump the main kobject's reference count for this controller
650 * and this instance is dependant on the main 633 * and this instance is dependant on the main
651 */ 634 */
@@ -655,8 +638,9 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
655 goto err_out; 638 goto err_out;
656 } 639 }
657 640
658 /* Formally register this instance's kobject */ 641 /* Formally register this instance's kobject under the edac_device */
659 err = kobject_register(&instance->kobj); 642 err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl,
643 &edac_dev->kobj, "%s", instance->name);
660 if (err != 0) { 644 if (err != 0) {
661 debugf2("%s() Failed to register instance '%s'\n", 645 debugf2("%s() Failed to register instance '%s'\n",
662 __func__, instance->name); 646 __func__, instance->name);
@@ -679,6 +663,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
679 goto err_release_instance_kobj; 663 goto err_release_instance_kobj;
680 } 664 }
681 } 665 }
666 kobject_uevent(&instance->kobj, KOBJ_ADD);
682 667
683 debugf4("%s() Registered instance %d '%s' kobject\n", 668 debugf4("%s() Registered instance %d '%s' kobject\n",
684 __func__, idx, instance->name); 669 __func__, idx, instance->name);
@@ -687,7 +672,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
687 672
688 /* error unwind stack */ 673 /* error unwind stack */
689err_release_instance_kobj: 674err_release_instance_kobj:
690 kobject_unregister(&instance->kobj); 675 kobject_put(&instance->kobj);
691 676
692err_out: 677err_out:
693 return err; 678 return err;
@@ -712,7 +697,7 @@ static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,
712 /* unregister this instance's kobject, SEE: 697 /* unregister this instance's kobject, SEE:
713 * edac_device_ctrl_instance_release() for callback operation 698 * edac_device_ctrl_instance_release() for callback operation
714 */ 699 */
715 kobject_unregister(&instance->kobj); 700 kobject_put(&instance->kobj);
716} 701}
717 702
718/* 703/*
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 3706b2bc0987..9aac88027fb3 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -380,13 +380,6 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
380 /* generate ..../edac/mc/mc<id>/csrow<index> */ 380 /* generate ..../edac/mc/mc<id>/csrow<index> */
381 memset(&csrow->kobj, 0, sizeof(csrow->kobj)); 381 memset(&csrow->kobj, 0, sizeof(csrow->kobj));
382 csrow->mci = mci; /* include container up link */ 382 csrow->mci = mci; /* include container up link */
383 csrow->kobj.parent = kobj_mci;
384 csrow->kobj.ktype = &ktype_csrow;
385
386 /* name this instance of csrow<id> */
387 err = kobject_set_name(&csrow->kobj, "csrow%d", index);
388 if (err)
389 goto err_out;
390 383
391 /* bump the mci instance's kobject's ref count */ 384 /* bump the mci instance's kobject's ref count */
392 kobj = kobject_get(&mci->edac_mci_kobj); 385 kobj = kobject_get(&mci->edac_mci_kobj);
@@ -396,12 +389,13 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
396 } 389 }
397 390
398 /* Instanstiate the csrow object */ 391 /* Instanstiate the csrow object */
399 err = kobject_register(&csrow->kobj); 392 err = kobject_init_and_add(&csrow->kobj, &ktype_csrow, kobj_mci,
393 "csrow%d", index);
400 if (err) 394 if (err)
401 goto err_release_top_kobj; 395 goto err_release_top_kobj;
402 396
403 /* At this point, to release a csrow kobj, one must 397 /* At this point, to release a csrow kobj, one must
404 * call the kobject_unregister and allow that tear down 398 * call the kobject_put and allow that tear down
405 * to work the releasing 399 * to work the releasing
406 */ 400 */
407 401
@@ -412,11 +406,11 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
412 err = edac_create_channel_files(&csrow->kobj, chan); 406 err = edac_create_channel_files(&csrow->kobj, chan);
413 if (err) { 407 if (err) {
414 /* special case the unregister here */ 408 /* special case the unregister here */
415 kobject_unregister(&csrow->kobj); 409 kobject_put(&csrow->kobj);
416 goto err_out; 410 goto err_out;
417 } 411 }
418 } 412 }
419 413 kobject_uevent(&csrow->kobj, KOBJ_ADD);
420 return 0; 414 return 0;
421 415
422 /* error unwind stack */ 416 /* error unwind stack */
@@ -744,7 +738,6 @@ static struct kobj_type ktype_mc_set_attribs = {
744 */ 738 */
745static struct kset mc_kset = { 739static struct kset mc_kset = {
746 .kobj = {.ktype = &ktype_mc_set_attribs }, 740 .kobj = {.ktype = &ktype_mc_set_attribs },
747 .ktype = &ktype_mci,
748}; 741};
749 742
750 743
@@ -765,14 +758,6 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
765 /* Init the mci's kobject */ 758 /* Init the mci's kobject */
766 memset(kobj_mci, 0, sizeof(*kobj_mci)); 759 memset(kobj_mci, 0, sizeof(*kobj_mci));
767 760
768 /* this instance become part of the mc_kset */
769 kobj_mci->kset = &mc_kset;
770
771 /* set the name of the mc<id> object */
772 err = kobject_set_name(kobj_mci, "mc%d", mci->mc_idx);
773 if (err)
774 goto fail_out;
775
776 /* Record which module 'owns' this control structure 761 /* Record which module 'owns' this control structure
777 * and bump the ref count of the module 762 * and bump the ref count of the module
778 */ 763 */
@@ -784,13 +769,18 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
784 goto fail_out; 769 goto fail_out;
785 } 770 }
786 771
772 /* this instance become part of the mc_kset */
773 kobj_mci->kset = &mc_kset;
774
787 /* register the mc<id> kobject to the mc_kset */ 775 /* register the mc<id> kobject to the mc_kset */
788 err = kobject_register(kobj_mci); 776 err = kobject_init_and_add(kobj_mci, &ktype_mci, NULL,
777 "mc%d", mci->mc_idx);
789 if (err) { 778 if (err) {
790 debugf1("%s()Failed to register '.../edac/mc%d'\n", 779 debugf1("%s()Failed to register '.../edac/mc%d'\n",
791 __func__, mci->mc_idx); 780 __func__, mci->mc_idx);
792 goto kobj_reg_fail; 781 goto kobj_reg_fail;
793 } 782 }
783 kobject_uevent(kobj_mci, KOBJ_ADD);
794 784
795 /* At this point, to 'free' the control struct, 785 /* At this point, to 'free' the control struct,
796 * edac_mc_unregister_sysfs_main_kobj() must be used 786 * edac_mc_unregister_sysfs_main_kobj() must be used
@@ -818,7 +808,7 @@ fail_out:
818void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci) 808void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci)
819{ 809{
820 /* delete the kobj from the mc_kset */ 810 /* delete the kobj from the mc_kset */
821 kobject_unregister(&mci->edac_mci_kobj); 811 kobject_put(&mci->edac_mci_kobj);
822} 812}
823 813
824#define EDAC_DEVICE_SYMLINK "device" 814#define EDAC_DEVICE_SYMLINK "device"
@@ -933,7 +923,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
933fail1: 923fail1:
934 for (i--; i >= 0; i--) { 924 for (i--; i >= 0; i--) {
935 if (csrow->nr_pages > 0) { 925 if (csrow->nr_pages > 0) {
936 kobject_unregister(&mci->csrows[i].kobj); 926 kobject_put(&mci->csrows[i].kobj);
937 } 927 }
938 } 928 }
939 929
@@ -960,7 +950,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
960 for (i = 0; i < mci->nr_csrows; i++) { 950 for (i = 0; i < mci->nr_csrows; i++) {
961 if (mci->csrows[i].nr_pages > 0) { 951 if (mci->csrows[i].nr_pages > 0) {
962 debugf0("%s() unreg csrow-%d\n", __func__, i); 952 debugf0("%s() unreg csrow-%d\n", __func__, i);
963 kobject_unregister(&mci->csrows[i].kobj); 953 kobject_put(&mci->csrows[i].kobj);
964 } 954 }
965 } 955 }
966 956
@@ -977,7 +967,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
977 debugf0("%s() unregister this mci kobj\n", __func__); 967 debugf0("%s() unregister this mci kobj\n", __func__);
978 968
979 /* unregister this instance's kobject */ 969 /* unregister this instance's kobject */
980 kobject_unregister(&mci->edac_mci_kobj); 970 kobject_put(&mci->edac_mci_kobj);
981} 971}
982 972
983 973
diff --git a/drivers/edac/edac_module.c b/drivers/edac/edac_module.c
index e0c4a4086055..7e1374afd967 100644
--- a/drivers/edac/edac_module.c
+++ b/drivers/edac/edac_module.c
@@ -31,7 +31,7 @@ struct workqueue_struct *edac_workqueue;
31 * need to export to other files in this modules 31 * need to export to other files in this modules
32 */ 32 */
33static struct sysdev_class edac_class = { 33static struct sysdev_class edac_class = {
34 set_kset_name("edac"), 34 .name = "edac",
35}; 35};
36static int edac_class_valid; 36static int edac_class_valid;
37 37
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index 69f5dddabddf..5b075da99145 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -162,14 +162,6 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
162 162
163 debugf0("%s()\n", __func__); 163 debugf0("%s()\n", __func__);
164 164
165 /* Set the parent and the instance's ktype */
166 pci->kobj.parent = &edac_pci_top_main_kobj;
167 pci->kobj.ktype = &ktype_pci_instance;
168
169 err = kobject_set_name(&pci->kobj, "pci%d", idx);
170 if (err)
171 return err;
172
173 /* First bump the ref count on the top main kobj, which will 165 /* First bump the ref count on the top main kobj, which will
174 * track the number of PCI instances we have, and thus nest 166 * track the number of PCI instances we have, and thus nest
175 * properly on keeping the module loaded 167 * properly on keeping the module loaded
@@ -181,7 +173,8 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
181 } 173 }
182 174
183 /* And now register this new kobject under the main kobj */ 175 /* And now register this new kobject under the main kobj */
184 err = kobject_register(&pci->kobj); 176 err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
177 &edac_pci_top_main_kobj, "pci%d", idx);
185 if (err != 0) { 178 if (err != 0) {
186 debugf2("%s() failed to register instance pci%d\n", 179 debugf2("%s() failed to register instance pci%d\n",
187 __func__, idx); 180 __func__, idx);
@@ -189,6 +182,7 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
189 goto error_out; 182 goto error_out;
190 } 183 }
191 184
185 kobject_uevent(&pci->kobj, KOBJ_ADD);
192 debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx); 186 debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx);
193 187
194 return 0; 188 return 0;
@@ -211,7 +205,7 @@ void edac_pci_unregister_sysfs_instance_kobj(struct edac_pci_ctl_info *pci)
211 * function release the main reference count and then 205 * function release the main reference count and then
212 * kfree the memory 206 * kfree the memory
213 */ 207 */
214 kobject_unregister(&pci->kobj); 208 kobject_put(&pci->kobj);
215} 209}
216 210
217/***************************** EDAC PCI sysfs root **********************/ 211/***************************** EDAC PCI sysfs root **********************/
@@ -364,14 +358,6 @@ int edac_pci_main_kobj_setup(void)
364 goto decrement_count_fail; 358 goto decrement_count_fail;
365 } 359 }
366 360
367 /* Need the kobject hook ups, and name setting */
368 edac_pci_top_main_kobj.ktype = &ktype_edac_pci_main_kobj;
369 edac_pci_top_main_kobj.parent = &edac_class->kset.kobj;
370
371 err = kobject_set_name(&edac_pci_top_main_kobj, "pci");
372 if (err)
373 goto decrement_count_fail;
374
375 /* Bump the reference count on this module to ensure the 361 /* Bump the reference count on this module to ensure the
376 * modules isn't unloaded until we deconstruct the top 362 * modules isn't unloaded until we deconstruct the top
377 * level main kobj for EDAC PCI 363 * level main kobj for EDAC PCI
@@ -383,23 +369,24 @@ int edac_pci_main_kobj_setup(void)
383 } 369 }
384 370
385 /* Instanstiate the pci object */ 371 /* Instanstiate the pci object */
386 /* FIXME: maybe new sysdev_create_subdir() */ 372 err = kobject_init_and_add(&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj,
387 err = kobject_register(&edac_pci_top_main_kobj); 373 &edac_class->kset.kobj, "pci");
388 if (err) { 374 if (err) {
389 debugf1("Failed to register '.../edac/pci'\n"); 375 debugf1("Failed to register '.../edac/pci'\n");
390 goto kobject_register_fail; 376 goto kobject_init_and_add_fail;
391 } 377 }
392 378
393 /* At this point, to 'release' the top level kobject 379 /* At this point, to 'release' the top level kobject
394 * for EDAC PCI, then edac_pci_main_kobj_teardown() 380 * for EDAC PCI, then edac_pci_main_kobj_teardown()
395 * must be used, for resources to be cleaned up properly 381 * must be used, for resources to be cleaned up properly
396 */ 382 */
383 kobject_uevent(&edac_pci_top_main_kobj, KOBJ_ADD);
397 debugf1("Registered '.../edac/pci' kobject\n"); 384 debugf1("Registered '.../edac/pci' kobject\n");
398 385
399 return 0; 386 return 0;
400 387
401 /* Error unwind statck */ 388 /* Error unwind statck */
402kobject_register_fail: 389kobject_init_and_add_fail:
403 module_put(THIS_MODULE); 390 module_put(THIS_MODULE);
404 391
405decrement_count_fail: 392decrement_count_fail:
@@ -424,9 +411,9 @@ static void edac_pci_main_kobj_teardown(void)
424 * main kobj 411 * main kobj
425 */ 412 */
426 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) { 413 if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
427 debugf0("%s() called kobject_unregister on main kobj\n", 414 debugf0("%s() called kobject_put on main kobj\n",
428 __func__); 415 __func__);
429 kobject_unregister(&edac_pci_top_main_kobj); 416 kobject_put(&edac_pci_top_main_kobj);
430 } 417 }
431} 418}
432 419
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 6942e065e609..d168223db159 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -631,7 +631,7 @@ static struct kobj_type edd_ktype = {
631 .default_attrs = def_attrs, 631 .default_attrs = def_attrs,
632}; 632};
633 633
634static decl_subsys(edd, &edd_ktype, NULL); 634static struct kset *edd_kset;
635 635
636 636
637/** 637/**
@@ -693,7 +693,7 @@ edd_create_symlink_to_pcidev(struct edd_device *edev)
693static inline void 693static inline void
694edd_device_unregister(struct edd_device *edev) 694edd_device_unregister(struct edd_device *edev)
695{ 695{
696 kobject_unregister(&edev->kobj); 696 kobject_put(&edev->kobj);
697} 697}
698 698
699static void edd_populate_dir(struct edd_device * edev) 699static void edd_populate_dir(struct edd_device * edev)
@@ -721,12 +721,13 @@ edd_device_register(struct edd_device *edev, int i)
721 if (!edev) 721 if (!edev)
722 return 1; 722 return 1;
723 edd_dev_set_info(edev, i); 723 edd_dev_set_info(edev, i);
724 kobject_set_name(&edev->kobj, "int13_dev%02x", 724 edev->kobj.kset = edd_kset;
725 0x80 + i); 725 error = kobject_init_and_add(&edev->kobj, &edd_ktype, NULL,
726 kobj_set_kset_s(edev,edd_subsys); 726 "int13_dev%02x", 0x80 + i);
727 error = kobject_register(&edev->kobj); 727 if (!error) {
728 if (!error)
729 edd_populate_dir(edev); 728 edd_populate_dir(edev);
729 kobject_uevent(&edev->kobj, KOBJ_ADD);
730 }
730 return error; 731 return error;
731} 732}
732 733
@@ -755,9 +756,9 @@ edd_init(void)
755 return 1; 756 return 1;
756 } 757 }
757 758
758 rc = firmware_register(&edd_subsys); 759 edd_kset = kset_create_and_add("edd", NULL, firmware_kobj);
759 if (rc) 760 if (!edd_kset)
760 return rc; 761 return -ENOMEM;
761 762
762 for (i = 0; i < edd_num_devices() && !rc; i++) { 763 for (i = 0; i < edd_num_devices() && !rc; i++) {
763 edev = kzalloc(sizeof (*edev), GFP_KERNEL); 764 edev = kzalloc(sizeof (*edev), GFP_KERNEL);
@@ -773,7 +774,7 @@ edd_init(void)
773 } 774 }
774 775
775 if (rc) 776 if (rc)
776 firmware_unregister(&edd_subsys); 777 kset_unregister(edd_kset);
777 return rc; 778 return rc;
778} 779}
779 780
@@ -787,7 +788,7 @@ edd_exit(void)
787 if ((edev = edd_devices[i])) 788 if ((edev = edd_devices[i]))
788 edd_device_unregister(edev); 789 edd_device_unregister(edev);
789 } 790 }
790 firmware_unregister(&edd_subsys); 791 kset_unregister(edd_kset);
791} 792}
792 793
793late_initcall(edd_init); 794late_initcall(edd_init);
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 858a7b95933b..f4f709d1370b 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -129,13 +129,6 @@ struct efivar_attribute {
129}; 129};
130 130
131 131
132#define EFI_ATTR(_name, _mode, _show, _store) \
133struct subsys_attribute efi_attr_##_name = { \
134 .attr = {.name = __stringify(_name), .mode = _mode}, \
135 .show = _show, \
136 .store = _store, \
137};
138
139#define EFIVAR_ATTR(_name, _mode, _show, _store) \ 132#define EFIVAR_ATTR(_name, _mode, _show, _store) \
140struct efivar_attribute efivar_attr_##_name = { \ 133struct efivar_attribute efivar_attr_##_name = { \
141 .attr = {.name = __stringify(_name), .mode = _mode}, \ 134 .attr = {.name = __stringify(_name), .mode = _mode}, \
@@ -143,13 +136,6 @@ struct efivar_attribute efivar_attr_##_name = { \
143 .store = _store, \ 136 .store = _store, \
144}; 137};
145 138
146#define VAR_SUBSYS_ATTR(_name, _mode, _show, _store) \
147struct subsys_attribute var_subsys_attr_##_name = { \
148 .attr = {.name = __stringify(_name), .mode = _mode}, \
149 .show = _show, \
150 .store = _store, \
151};
152
153#define to_efivar_attr(_attr) container_of(_attr, struct efivar_attribute, attr) 139#define to_efivar_attr(_attr) container_of(_attr, struct efivar_attribute, attr)
154#define to_efivar_entry(obj) container_of(obj, struct efivar_entry, kobj) 140#define to_efivar_entry(obj) container_of(obj, struct efivar_entry, kobj)
155 141
@@ -408,21 +394,16 @@ static struct kobj_type efivar_ktype = {
408 .default_attrs = def_attrs, 394 .default_attrs = def_attrs,
409}; 395};
410 396
411static ssize_t
412dummy(struct kset *kset, char *buf)
413{
414 return -ENODEV;
415}
416
417static inline void 397static inline void
418efivar_unregister(struct efivar_entry *var) 398efivar_unregister(struct efivar_entry *var)
419{ 399{
420 kobject_unregister(&var->kobj); 400 kobject_put(&var->kobj);
421} 401}
422 402
423 403
424static ssize_t 404static ssize_t efivar_create(struct kobject *kobj,
425efivar_create(struct kset *kset, const char *buf, size_t count) 405 struct bin_attribute *bin_attr,
406 char *buf, loff_t pos, size_t count)
426{ 407{
427 struct efi_variable *new_var = (struct efi_variable *)buf; 408 struct efi_variable *new_var = (struct efi_variable *)buf;
428 struct efivar_entry *search_efivar, *n; 409 struct efivar_entry *search_efivar, *n;
@@ -479,8 +460,9 @@ efivar_create(struct kset *kset, const char *buf, size_t count)
479 return count; 460 return count;
480} 461}
481 462
482static ssize_t 463static ssize_t efivar_delete(struct kobject *kobj,
483efivar_delete(struct kset *kset, const char *buf, size_t count) 464 struct bin_attribute *bin_attr,
465 char *buf, loff_t pos, size_t count)
484{ 466{
485 struct efi_variable *del_var = (struct efi_variable *)buf; 467 struct efi_variable *del_var = (struct efi_variable *)buf;
486 struct efivar_entry *search_efivar, *n; 468 struct efivar_entry *search_efivar, *n;
@@ -537,25 +519,26 @@ efivar_delete(struct kset *kset, const char *buf, size_t count)
537 return count; 519 return count;
538} 520}
539 521
540static VAR_SUBSYS_ATTR(new_var, 0200, dummy, efivar_create); 522static struct bin_attribute var_subsys_attr_new_var = {
541static VAR_SUBSYS_ATTR(del_var, 0200, dummy, efivar_delete); 523 .attr = {.name = "new_var", .mode = 0200},
524 .write = efivar_create,
525};
542 526
543static struct subsys_attribute *var_subsys_attrs[] = { 527static struct bin_attribute var_subsys_attr_del_var = {
544 &var_subsys_attr_new_var, 528 .attr = {.name = "del_var", .mode = 0200},
545 &var_subsys_attr_del_var, 529 .write = efivar_delete,
546 NULL,
547}; 530};
548 531
549/* 532/*
550 * Let's not leave out systab information that snuck into 533 * Let's not leave out systab information that snuck into
551 * the efivars driver 534 * the efivars driver
552 */ 535 */
553static ssize_t 536static ssize_t systab_show(struct kobject *kobj,
554systab_read(struct kset *kset, char *buf) 537 struct kobj_attribute *attr, char *buf)
555{ 538{
556 char *str = buf; 539 char *str = buf;
557 540
558 if (!kset || !buf) 541 if (!kobj || !buf)
559 return -EINVAL; 542 return -EINVAL;
560 543
561 if (efi.mps != EFI_INVALID_TABLE_ADDR) 544 if (efi.mps != EFI_INVALID_TABLE_ADDR)
@@ -576,15 +559,21 @@ systab_read(struct kset *kset, char *buf)
576 return str - buf; 559 return str - buf;
577} 560}
578 561
579static EFI_ATTR(systab, 0400, systab_read, NULL); 562static struct kobj_attribute efi_attr_systab =
563 __ATTR(systab, 0400, systab_show, NULL);
580 564
581static struct subsys_attribute *efi_subsys_attrs[] = { 565static struct attribute *efi_subsys_attrs[] = {
582 &efi_attr_systab, 566 &efi_attr_systab.attr,
583 NULL, /* maybe more in the future? */ 567 NULL, /* maybe more in the future? */
584}; 568};
585 569
586static decl_subsys(vars, &efivar_ktype, NULL); 570static struct attribute_group efi_subsys_attr_group = {
587static decl_subsys(efi, NULL, NULL); 571 .attrs = efi_subsys_attrs,
572};
573
574
575static struct kset *vars_kset;
576static struct kobject *efi_kobj;
588 577
589/* 578/*
590 * efivar_create_sysfs_entry() 579 * efivar_create_sysfs_entry()
@@ -628,15 +617,16 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
628 *(short_name + strlen(short_name)) = '-'; 617 *(short_name + strlen(short_name)) = '-';
629 efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); 618 efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
630 619
631 kobject_set_name(&new_efivar->kobj, "%s", short_name); 620 new_efivar->kobj.kset = vars_kset;
632 kobj_set_kset_s(new_efivar, vars_subsys); 621 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL,
633 i = kobject_register(&new_efivar->kobj); 622 "%s", short_name);
634 if (i) { 623 if (i) {
635 kfree(short_name); 624 kfree(short_name);
636 kfree(new_efivar); 625 kfree(new_efivar);
637 return 1; 626 return 1;
638 } 627 }
639 628
629 kobject_uevent(&new_efivar->kobj, KOBJ_ADD);
640 kfree(short_name); 630 kfree(short_name);
641 short_name = NULL; 631 short_name = NULL;
642 632
@@ -660,9 +650,8 @@ efivars_init(void)
660 efi_status_t status = EFI_NOT_FOUND; 650 efi_status_t status = EFI_NOT_FOUND;
661 efi_guid_t vendor_guid; 651 efi_guid_t vendor_guid;
662 efi_char16_t *variable_name; 652 efi_char16_t *variable_name;
663 struct subsys_attribute *attr;
664 unsigned long variable_name_size = 1024; 653 unsigned long variable_name_size = 1024;
665 int i, error = 0; 654 int error = 0;
666 655
667 if (!efi_enabled) 656 if (!efi_enabled)
668 return -ENODEV; 657 return -ENODEV;
@@ -676,23 +665,18 @@ efivars_init(void)
676 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 665 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
677 EFIVARS_DATE); 666 EFIVARS_DATE);
678 667
679 /* 668 /* For now we'll register the efi directory at /sys/firmware/efi */
680 * For now we'll register the efi subsys within this driver 669 efi_kobj = kobject_create_and_add("efi", firmware_kobj);
681 */ 670 if (!efi_kobj) {
682 671 printk(KERN_ERR "efivars: Firmware registration failed.\n");
683 error = firmware_register(&efi_subsys); 672 error = -ENOMEM;
684
685 if (error) {
686 printk(KERN_ERR "efivars: Firmware registration failed with error %d.\n", error);
687 goto out_free; 673 goto out_free;
688 } 674 }
689 675
690 kobj_set_kset_s(&vars_subsys, efi_subsys); 676 vars_kset = kset_create_and_add("vars", NULL, efi_kobj);
691 677 if (!vars_kset) {
692 error = subsystem_register(&vars_subsys); 678 printk(KERN_ERR "efivars: Subsystem registration failed.\n");
693 679 error = -ENOMEM;
694 if (error) {
695 printk(KERN_ERR "efivars: Subsystem registration failed with error %d.\n", error);
696 goto out_firmware_unregister; 680 goto out_firmware_unregister;
697 } 681 }
698 682
@@ -727,28 +711,28 @@ efivars_init(void)
727 * Now add attributes to allow creation of new vars 711 * Now add attributes to allow creation of new vars
728 * and deletion of existing ones... 712 * and deletion of existing ones...
729 */ 713 */
730 714 error = sysfs_create_bin_file(&vars_kset->kobj,
731 for (i = 0; (attr = var_subsys_attrs[i]) && !error; i++) { 715 &var_subsys_attr_new_var);
732 if (attr->show && attr->store) 716 if (error)
733 error = subsys_create_file(&vars_subsys, attr); 717 printk(KERN_ERR "efivars: unable to create new_var sysfs file"
734 } 718 " due to error %d\n", error);
719 error = sysfs_create_bin_file(&vars_kset->kobj,
720 &var_subsys_attr_del_var);
721 if (error)
722 printk(KERN_ERR "efivars: unable to create del_var sysfs file"
723 " due to error %d\n", error);
735 724
736 /* Don't forget the systab entry */ 725 /* Don't forget the systab entry */
737 726 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
738 for (i = 0; (attr = efi_subsys_attrs[i]) && !error; i++) {
739 if (attr->show)
740 error = subsys_create_file(&efi_subsys, attr);
741 }
742
743 if (error) 727 if (error)
744 printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error); 728 printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
745 else 729 else
746 goto out_free; 730 goto out_free;
747 731
748 subsystem_unregister(&vars_subsys); 732 kset_unregister(vars_kset);
749 733
750out_firmware_unregister: 734out_firmware_unregister:
751 firmware_unregister(&efi_subsys); 735 kobject_put(efi_kobj);
752 736
753out_free: 737out_free:
754 kfree(variable_name); 738 kfree(variable_name);
@@ -768,8 +752,8 @@ efivars_exit(void)
768 efivar_unregister(entry); 752 efivar_unregister(entry);
769 } 753 }
770 754
771 subsystem_unregister(&vars_subsys); 755 kset_unregister(vars_kset);
772 firmware_unregister(&efi_subsys); 756 kobject_put(efi_kobj);
773} 757}
774 758
775module_init(efivars_init); 759module_init(efivars_init);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index b767603a07ba..ebfbb2947ae6 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -259,12 +259,6 @@ static inline const char *state_name(struct isp1301 *isp)
259 return state_string(isp->otg.state); 259 return state_string(isp->otg.state);
260} 260}
261 261
262#ifdef VERBOSE
263#define dev_vdbg dev_dbg
264#else
265#define dev_vdbg(dev, fmt, arg...) do{}while(0)
266#endif
267
268/*-------------------------------------------------------------------------*/ 262/*-------------------------------------------------------------------------*/
269 263
270/* NOTE: some of this ISP1301 setup is specific to H2 boards; 264/* NOTE: some of this ISP1301 setup is specific to H2 boards;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 2994523be7bf..0cb3d2bb3ab9 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
1173{ 1173{
1174 struct gendisk *p = data; 1174 struct gendisk *p = data;
1175 *part &= (1 << PARTN_BITS) - 1; 1175 *part &= (1 << PARTN_BITS) - 1;
1176 return &p->kobj; 1176 return &p->dev.kobj;
1177} 1177}
1178 1178
1179static int exact_lock(dev_t dev, void *data) 1179static int exact_lock(dev_t dev, void *data)
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 7b9181b5469d..1495792d7917 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -4724,10 +4724,8 @@ static void ide_tape_release(struct kref *kref)
4724 4724
4725 drive->dsc_overlap = 0; 4725 drive->dsc_overlap = 0;
4726 drive->driver_data = NULL; 4726 drive->driver_data = NULL;
4727 class_device_destroy(idetape_sysfs_class, 4727 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
4728 MKDEV(IDETAPE_MAJOR, tape->minor)); 4728 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor + 128));
4729 class_device_destroy(idetape_sysfs_class,
4730 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
4731 idetape_devs[tape->minor] = NULL; 4729 idetape_devs[tape->minor] = NULL;
4732 g->private_data = NULL; 4730 g->private_data = NULL;
4733 put_disk(g); 4731 put_disk(g);
@@ -4884,10 +4882,10 @@ static int ide_tape_probe(ide_drive_t *drive)
4884 4882
4885 idetape_setup(drive, tape, minor); 4883 idetape_setup(drive, tape, minor);
4886 4884
4887 class_device_create(idetape_sysfs_class, NULL, 4885 device_create(idetape_sysfs_class, &drive->gendev,
4888 MKDEV(IDETAPE_MAJOR, minor), &drive->gendev, "%s", tape->name); 4886 MKDEV(IDETAPE_MAJOR, minor), "%s", tape->name);
4889 class_device_create(idetape_sysfs_class, NULL, 4887 device_create(idetape_sysfs_class, &drive->gendev,
4890 MKDEV(IDETAPE_MAJOR, minor + 128), &drive->gendev, "n%s", tape->name); 4888 MKDEV(IDETAPE_MAJOR, minor + 128), "n%s", tape->name);
4891 4889
4892 g->fops = &idetape_block_ops; 4890 g->fops = &idetape_block_ops;
4893 ide_register_region(g); 4891 ide_register_region(g);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 90dc75be3418..511e4321c6b6 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -727,33 +727,31 @@ static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
727 727
728static DEFINE_MUTEX(nodemgr_serialize_remove_uds); 728static DEFINE_MUTEX(nodemgr_serialize_remove_uds);
729 729
730static int __match_ne(struct device *dev, void *data)
731{
732 struct unit_directory *ud;
733 struct node_entry *ne = (struct node_entry *)data;
734
735 ud = container_of(dev, struct unit_directory, unit_dev);
736 return ud->ne == ne;
737}
738
730static void nodemgr_remove_uds(struct node_entry *ne) 739static void nodemgr_remove_uds(struct node_entry *ne)
731{ 740{
732 struct device *dev; 741 struct device *dev;
733 struct unit_directory *tmp, *ud; 742 struct unit_directory *ud;
734 743
735 /* Iteration over nodemgr_ud_class.devices has to be protected by 744 /* Use class_find device to iterate the devices. Since this code
736 * nodemgr_ud_class.sem, but device_unregister() will eventually 745 * may be called from other contexts besides the knodemgrds,
737 * take nodemgr_ud_class.sem too. Therefore pick out one ud at a time, 746 * protect it by nodemgr_serialize_remove_uds.
738 * release the semaphore, and then unregister the ud. Since this code
739 * may be called from other contexts besides the knodemgrds, protect the
740 * gap after release of the semaphore by nodemgr_serialize_remove_uds.
741 */ 747 */
742 mutex_lock(&nodemgr_serialize_remove_uds); 748 mutex_lock(&nodemgr_serialize_remove_uds);
743 for (;;) { 749 for (;;) {
744 ud = NULL; 750 dev = class_find_device(&nodemgr_ud_class, ne, __match_ne);
745 down(&nodemgr_ud_class.sem); 751 if (!dev)
746 list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
747 tmp = container_of(dev, struct unit_directory,
748 unit_dev);
749 if (tmp->ne == ne) {
750 ud = tmp;
751 break;
752 }
753 }
754 up(&nodemgr_ud_class.sem);
755 if (ud == NULL)
756 break; 752 break;
753 ud = container_of(dev, struct unit_directory, unit_dev);
754 put_device(dev);
757 device_unregister(&ud->unit_dev); 755 device_unregister(&ud->unit_dev);
758 device_unregister(&ud->device); 756 device_unregister(&ud->device);
759 } 757 }
@@ -882,45 +880,66 @@ fail_alloc:
882 return NULL; 880 return NULL;
883} 881}
884 882
883static int __match_ne_guid(struct device *dev, void *data)
884{
885 struct node_entry *ne;
886 u64 *guid = (u64 *)data;
887
888 ne = container_of(dev, struct node_entry, node_dev);
889 return ne->guid == *guid;
890}
885 891
886static struct node_entry *find_entry_by_guid(u64 guid) 892static struct node_entry *find_entry_by_guid(u64 guid)
887{ 893{
888 struct device *dev; 894 struct device *dev;
889 struct node_entry *ne, *ret_ne = NULL; 895 struct node_entry *ne;
890
891 down(&nodemgr_ne_class.sem);
892 list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
893 ne = container_of(dev, struct node_entry, node_dev);
894 896
895 if (ne->guid == guid) { 897 dev = class_find_device(&nodemgr_ne_class, &guid, __match_ne_guid);
896 ret_ne = ne; 898 if (!dev)
897 break; 899 return NULL;
898 } 900 ne = container_of(dev, struct node_entry, node_dev);
899 } 901 put_device(dev);
900 up(&nodemgr_ne_class.sem);
901 902
902 return ret_ne; 903 return ne;
903} 904}
904 905
906struct match_nodeid_param {
907 struct hpsb_host *host;
908 nodeid_t nodeid;
909};
910
911static int __match_ne_nodeid(struct device *dev, void *data)
912{
913 int found = 0;
914 struct node_entry *ne;
915 struct match_nodeid_param *param = (struct match_nodeid_param *)data;
916
917 if (!dev)
918 goto ret;
919 ne = container_of(dev, struct node_entry, node_dev);
920 if (ne->host == param->host && ne->nodeid == param->nodeid)
921 found = 1;
922ret:
923 return found;
924}
905 925
906static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host, 926static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
907 nodeid_t nodeid) 927 nodeid_t nodeid)
908{ 928{
909 struct device *dev; 929 struct device *dev;
910 struct node_entry *ne, *ret_ne = NULL; 930 struct node_entry *ne;
931 struct match_nodeid_param param;
911 932
912 down(&nodemgr_ne_class.sem); 933 param.host = host;
913 list_for_each_entry(dev, &nodemgr_ne_class.devices, node) { 934 param.nodeid = nodeid;
914 ne = container_of(dev, struct node_entry, node_dev);
915 935
916 if (ne->host == host && ne->nodeid == nodeid) { 936 dev = class_find_device(&nodemgr_ne_class, &param, __match_ne_nodeid);
917 ret_ne = ne; 937 if (!dev)
918 break; 938 return NULL;
919 } 939 ne = container_of(dev, struct node_entry, node_dev);
920 } 940 put_device(dev);
921 up(&nodemgr_ne_class.sem);
922 941
923 return ret_ne; 942 return ne;
924} 943}
925 944
926 945
@@ -1370,107 +1389,109 @@ static void nodemgr_node_scan(struct host_info *hi, int generation)
1370 } 1389 }
1371} 1390}
1372 1391
1373 1392static int __nodemgr_driver_suspend(struct device *dev, void *data)
1374static void nodemgr_suspend_ne(struct node_entry *ne)
1375{ 1393{
1376 struct device *dev;
1377 struct unit_directory *ud; 1394 struct unit_directory *ud;
1378 struct device_driver *drv; 1395 struct device_driver *drv;
1396 struct node_entry *ne = (struct node_entry *)data;
1379 int error; 1397 int error;
1380 1398
1381 HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", 1399 ud = container_of(dev, struct unit_directory, unit_dev);
1382 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); 1400 if (ud->ne == ne) {
1401 drv = get_driver(ud->device.driver);
1402 if (drv) {
1403 error = 1; /* release if suspend is not implemented */
1404 if (drv->suspend) {
1405 down(&ud->device.sem);
1406 error = drv->suspend(&ud->device, PMSG_SUSPEND);
1407 up(&ud->device.sem);
1408 }
1409 if (error)
1410 device_release_driver(&ud->device);
1411 put_driver(drv);
1412 }
1413 }
1383 1414
1384 ne->in_limbo = 1; 1415 return 0;
1385 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo)); 1416}
1386 1417
1387 down(&nodemgr_ud_class.sem); 1418static int __nodemgr_driver_resume(struct device *dev, void *data)
1388 list_for_each_entry(dev, &nodemgr_ud_class.devices, node) { 1419{
1389 ud = container_of(dev, struct unit_directory, unit_dev); 1420 struct unit_directory *ud;
1390 if (ud->ne != ne) 1421 struct device_driver *drv;
1391 continue; 1422 struct node_entry *ne = (struct node_entry *)data;
1392 1423
1424 ud = container_of(dev, struct unit_directory, unit_dev);
1425 if (ud->ne == ne) {
1393 drv = get_driver(ud->device.driver); 1426 drv = get_driver(ud->device.driver);
1394 if (!drv) 1427 if (drv) {
1395 continue; 1428 if (drv->resume) {
1396 1429 down(&ud->device.sem);
1397 error = 1; /* release if suspend is not implemented */ 1430 drv->resume(&ud->device);
1398 if (drv->suspend) { 1431 up(&ud->device.sem);
1399 down(&ud->device.sem); 1432 }
1400 error = drv->suspend(&ud->device, PMSG_SUSPEND); 1433 put_driver(drv);
1401 up(&ud->device.sem);
1402 } 1434 }
1403 if (error)
1404 device_release_driver(&ud->device);
1405 put_driver(drv);
1406 } 1435 }
1407 up(&nodemgr_ud_class.sem);
1408}
1409 1436
1437 return 0;
1438}
1410 1439
1411static void nodemgr_resume_ne(struct node_entry *ne) 1440static void nodemgr_suspend_ne(struct node_entry *ne)
1412{ 1441{
1413 struct device *dev; 1442 HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1414 struct unit_directory *ud; 1443 NODE_BUS_ARGS(ne->host, ne->nodeid),
1415 struct device_driver *drv; 1444 (unsigned long long)ne->guid);
1416 1445
1417 ne->in_limbo = 0; 1446 ne->in_limbo = 1;
1418 device_remove_file(&ne->device, &dev_attr_ne_in_limbo); 1447 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
1419 1448
1420 down(&nodemgr_ud_class.sem); 1449 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend);
1421 list_for_each_entry(dev, &nodemgr_ud_class.devices, node) { 1450}
1422 ud = container_of(dev, struct unit_directory, unit_dev);
1423 if (ud->ne != ne)
1424 continue;
1425 1451
1426 drv = get_driver(ud->device.driver);
1427 if (!drv)
1428 continue;
1429 1452
1430 if (drv->resume) { 1453static void nodemgr_resume_ne(struct node_entry *ne)
1431 down(&ud->device.sem); 1454{
1432 drv->resume(&ud->device); 1455 ne->in_limbo = 0;
1433 up(&ud->device.sem); 1456 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1434 }
1435 put_driver(drv);
1436 }
1437 up(&nodemgr_ud_class.sem);
1438 1457
1458 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume);
1439 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", 1459 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1440 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); 1460 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1441} 1461}
1442 1462
1443 1463static int __nodemgr_update_pdrv(struct device *dev, void *data)
1444static void nodemgr_update_pdrv(struct node_entry *ne)
1445{ 1464{
1446 struct device *dev;
1447 struct unit_directory *ud; 1465 struct unit_directory *ud;
1448 struct device_driver *drv; 1466 struct device_driver *drv;
1449 struct hpsb_protocol_driver *pdrv; 1467 struct hpsb_protocol_driver *pdrv;
1468 struct node_entry *ne = (struct node_entry *)data;
1450 int error; 1469 int error;
1451 1470
1452 down(&nodemgr_ud_class.sem); 1471 ud = container_of(dev, struct unit_directory, unit_dev);
1453 list_for_each_entry(dev, &nodemgr_ud_class.devices, node) { 1472 if (ud->ne == ne) {
1454 ud = container_of(dev, struct unit_directory, unit_dev);
1455 if (ud->ne != ne)
1456 continue;
1457
1458 drv = get_driver(ud->device.driver); 1473 drv = get_driver(ud->device.driver);
1459 if (!drv) 1474 if (drv) {
1460 continue; 1475 error = 0;
1461 1476 pdrv = container_of(drv, struct hpsb_protocol_driver,
1462 error = 0; 1477 driver);
1463 pdrv = container_of(drv, struct hpsb_protocol_driver, driver); 1478 if (pdrv->update) {
1464 if (pdrv->update) { 1479 down(&ud->device.sem);
1465 down(&ud->device.sem); 1480 error = pdrv->update(ud);
1466 error = pdrv->update(ud); 1481 up(&ud->device.sem);
1467 up(&ud->device.sem); 1482 }
1483 if (error)
1484 device_release_driver(&ud->device);
1485 put_driver(drv);
1468 } 1486 }
1469 if (error)
1470 device_release_driver(&ud->device);
1471 put_driver(drv);
1472 } 1487 }
1473 up(&nodemgr_ud_class.sem); 1488
1489 return 0;
1490}
1491
1492static void nodemgr_update_pdrv(struct node_entry *ne)
1493{
1494 class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv);
1474} 1495}
1475 1496
1476 1497
@@ -1529,13 +1550,31 @@ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int ge
1529 put_device(dev); 1550 put_device(dev);
1530} 1551}
1531 1552
1553struct probe_param {
1554 struct host_info *hi;
1555 int generation;
1556};
1557
1558static int __nodemgr_node_probe(struct device *dev, void *data)
1559{
1560 struct probe_param *param = (struct probe_param *)data;
1561 struct node_entry *ne;
1562
1563 ne = container_of(dev, struct node_entry, node_dev);
1564 if (!ne->needs_probe)
1565 nodemgr_probe_ne(param->hi, ne, param->generation);
1566 if (ne->needs_probe)
1567 nodemgr_probe_ne(param->hi, ne, param->generation);
1568 return 0;
1569}
1532 1570
1533static void nodemgr_node_probe(struct host_info *hi, int generation) 1571static void nodemgr_node_probe(struct host_info *hi, int generation)
1534{ 1572{
1535 struct hpsb_host *host = hi->host; 1573 struct hpsb_host *host = hi->host;
1536 struct device *dev; 1574 struct probe_param param;
1537 struct node_entry *ne;
1538 1575
1576 param.hi = hi;
1577 param.generation = generation;
1539 /* Do some processing of the nodes we've probed. This pulls them 1578 /* Do some processing of the nodes we've probed. This pulls them
1540 * into the sysfs layer if needed, and can result in processing of 1579 * into the sysfs layer if needed, and can result in processing of
1541 * unit-directories, or just updating the node and it's 1580 * unit-directories, or just updating the node and it's
@@ -1545,19 +1584,7 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1545 * while probes are time-consuming. (Well, those probes need some 1584 * while probes are time-consuming. (Well, those probes need some
1546 * improvement...) */ 1585 * improvement...) */
1547 1586
1548 down(&nodemgr_ne_class.sem); 1587 class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe);
1549 list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
1550 ne = container_of(dev, struct node_entry, node_dev);
1551 if (!ne->needs_probe)
1552 nodemgr_probe_ne(hi, ne, generation);
1553 }
1554 list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
1555 ne = container_of(dev, struct node_entry, node_dev);
1556 if (ne->needs_probe)
1557 nodemgr_probe_ne(hi, ne, generation);
1558 }
1559 up(&nodemgr_ne_class.sem);
1560
1561 1588
1562 /* If we had a bus reset while we were scanning the bus, it is 1589 /* If we had a bus reset while we were scanning the bus, it is
1563 * possible that we did not probe all nodes. In that case, we 1590 * possible that we did not probe all nodes. In that case, we
@@ -1757,6 +1784,22 @@ exit:
1757 return 0; 1784 return 0;
1758} 1785}
1759 1786
1787struct host_iter_param {
1788 void *data;
1789 int (*cb)(struct hpsb_host *, void *);
1790};
1791
1792static int __nodemgr_for_each_host(struct device *dev, void *data)
1793{
1794 struct hpsb_host *host;
1795 struct host_iter_param *hip = (struct host_iter_param *)data;
1796 int error = 0;
1797
1798 host = container_of(dev, struct hpsb_host, host_dev);
1799 error = hip->cb(host, hip->data);
1800
1801 return error;
1802}
1760/** 1803/**
1761 * nodemgr_for_each_host - call a function for each IEEE 1394 host 1804 * nodemgr_for_each_host - call a function for each IEEE 1394 host
1762 * @data: an address to supply to the callback 1805 * @data: an address to supply to the callback
@@ -1771,18 +1814,13 @@ exit:
1771 */ 1814 */
1772int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *)) 1815int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
1773{ 1816{
1774 struct device *dev; 1817 struct host_iter_param hip;
1775 struct hpsb_host *host; 1818 int error;
1776 int error = 0;
1777
1778 down(&hpsb_host_class.sem);
1779 list_for_each_entry(dev, &hpsb_host_class.devices, node) {
1780 host = container_of(dev, struct hpsb_host, host_dev);
1781 1819
1782 if ((error = cb(host, data))) 1820 hip.cb = cb;
1783 break; 1821 hip.data = data;
1784 } 1822 error = class_for_each_device(&hpsb_host_class, &hip,
1785 up(&hpsb_host_class.sem); 1823 __nodemgr_for_each_host);
1786 1824
1787 return error; 1825 return error;
1788} 1826}
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 3d4050681325..c864ef70fdf9 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -508,19 +508,10 @@ static int add_port(struct ib_device *device, int port_num)
508 508
509 p->ibdev = device; 509 p->ibdev = device;
510 p->port_num = port_num; 510 p->port_num = port_num;
511 p->kobj.ktype = &port_type;
512 511
513 p->kobj.parent = kobject_get(&device->ports_parent); 512 ret = kobject_init_and_add(&p->kobj, &port_type,
514 if (!p->kobj.parent) { 513 kobject_get(device->ports_parent),
515 ret = -EBUSY; 514 "%d", port_num);
516 goto err;
517 }
518
519 ret = kobject_set_name(&p->kobj, "%d", port_num);
520 if (ret)
521 goto err_put;
522
523 ret = kobject_register(&p->kobj);
524 if (ret) 515 if (ret)
525 goto err_put; 516 goto err_put;
526 517
@@ -549,6 +540,7 @@ static int add_port(struct ib_device *device, int port_num)
549 540
550 list_add_tail(&p->kobj.entry, &device->port_list); 541 list_add_tail(&p->kobj.entry, &device->port_list);
551 542
543 kobject_uevent(&p->kobj, KOBJ_ADD);
552 return 0; 544 return 0;
553 545
554err_free_pkey: 546err_free_pkey:
@@ -570,9 +562,7 @@ err_remove_pma:
570 sysfs_remove_group(&p->kobj, &pma_group); 562 sysfs_remove_group(&p->kobj, &pma_group);
571 563
572err_put: 564err_put:
573 kobject_put(&device->ports_parent); 565 kobject_put(device->ports_parent);
574
575err:
576 kfree(p); 566 kfree(p);
577 return ret; 567 return ret;
578} 568}
@@ -694,16 +684,9 @@ int ib_device_register_sysfs(struct ib_device *device)
694 goto err_unregister; 684 goto err_unregister;
695 } 685 }
696 686
697 device->ports_parent.parent = kobject_get(&class_dev->kobj); 687 device->ports_parent = kobject_create_and_add("ports",
698 if (!device->ports_parent.parent) { 688 kobject_get(&class_dev->kobj));
699 ret = -EBUSY; 689 if (!device->ports_parent)
700 goto err_unregister;
701 }
702 ret = kobject_set_name(&device->ports_parent, "ports");
703 if (ret)
704 goto err_put;
705 ret = kobject_register(&device->ports_parent);
706 if (ret)
707 goto err_put; 690 goto err_put;
708 691
709 if (device->node_type == RDMA_NODE_IB_SWITCH) { 692 if (device->node_type == RDMA_NODE_IB_SWITCH) {
@@ -731,7 +714,7 @@ err_put:
731 sysfs_remove_group(p, &pma_group); 714 sysfs_remove_group(p, &pma_group);
732 sysfs_remove_group(p, &port->pkey_group); 715 sysfs_remove_group(p, &port->pkey_group);
733 sysfs_remove_group(p, &port->gid_group); 716 sysfs_remove_group(p, &port->gid_group);
734 kobject_unregister(p); 717 kobject_put(p);
735 } 718 }
736 } 719 }
737 720
@@ -755,10 +738,10 @@ void ib_device_unregister_sysfs(struct ib_device *device)
755 sysfs_remove_group(p, &pma_group); 738 sysfs_remove_group(p, &pma_group);
756 sysfs_remove_group(p, &port->pkey_group); 739 sysfs_remove_group(p, &port->pkey_group);
757 sysfs_remove_group(p, &port->gid_group); 740 sysfs_remove_group(p, &port->gid_group);
758 kobject_unregister(p); 741 kobject_put(p);
759 } 742 }
760 743
761 kobject_unregister(&device->ports_parent); 744 kobject_put(device->ports_parent);
762 class_device_unregister(&device->class_dev); 745 class_device_unregister(&device->class_dev);
763} 746}
764 747
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 6a56d86a2951..c9e32b46387f 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -590,6 +590,11 @@ static struct attribute_group ehca_drv_attr_grp = {
590 .attrs = ehca_drv_attrs 590 .attrs = ehca_drv_attrs
591}; 591};
592 592
593static struct attribute_group *ehca_drv_attr_groups[] = {
594 &ehca_drv_attr_grp,
595 NULL,
596};
597
593#define EHCA_RESOURCE_ATTR(name) \ 598#define EHCA_RESOURCE_ATTR(name) \
594static ssize_t ehca_show_##name(struct device *dev, \ 599static ssize_t ehca_show_##name(struct device *dev, \
595 struct device_attribute *attr, \ 600 struct device_attribute *attr, \
@@ -899,6 +904,9 @@ static struct of_platform_driver ehca_driver = {
899 .match_table = ehca_device_table, 904 .match_table = ehca_device_table,
900 .probe = ehca_probe, 905 .probe = ehca_probe,
901 .remove = ehca_remove, 906 .remove = ehca_remove,
907 .driver = {
908 .groups = ehca_drv_attr_groups,
909 },
902}; 910};
903 911
904void ehca_poll_eqs(unsigned long data) 912void ehca_poll_eqs(unsigned long data)
@@ -957,10 +965,6 @@ int __init ehca_module_init(void)
957 goto module_init2; 965 goto module_init2;
958 } 966 }
959 967
960 ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
961 if (ret) /* only complain; we can live without attributes */
962 ehca_gen_err("Cannot create driver attributes ret=%d", ret);
963
964 if (ehca_poll_all_eqs != 1) { 968 if (ehca_poll_all_eqs != 1) {
965 ehca_gen_err("WARNING!!!"); 969 ehca_gen_err("WARNING!!!");
966 ehca_gen_err("It is possible to lose interrupts."); 970 ehca_gen_err("It is possible to lose interrupts.");
@@ -986,7 +990,6 @@ void __exit ehca_module_exit(void)
986 if (ehca_poll_all_eqs == 1) 990 if (ehca_poll_all_eqs == 1)
987 del_timer_sync(&poll_eqs_timer); 991 del_timer_sync(&poll_eqs_timer);
988 992
989 sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
990 ibmebus_unregister_driver(&ehca_driver); 993 ibmebus_unregister_driver(&ehca_driver);
991 994
992 ehca_destroy_slab_caches(); 995 ehca_destroy_slab_caches();
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
index 1f152ded1e3c..fc355981bbab 100644
--- a/drivers/infiniband/hw/ipath/ipath_driver.c
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -121,6 +121,9 @@ static struct pci_driver ipath_driver = {
121 .probe = ipath_init_one, 121 .probe = ipath_init_one,
122 .remove = __devexit_p(ipath_remove_one), 122 .remove = __devexit_p(ipath_remove_one),
123 .id_table = ipath_pci_tbl, 123 .id_table = ipath_pci_tbl,
124 .driver = {
125 .groups = ipath_driver_attr_groups,
126 },
124}; 127};
125 128
126static void ipath_check_status(struct work_struct *work) 129static void ipath_check_status(struct work_struct *work)
@@ -2217,25 +2220,15 @@ static int __init infinipath_init(void)
2217 goto bail_unit; 2220 goto bail_unit;
2218 } 2221 }
2219 2222
2220 ret = ipath_driver_create_group(&ipath_driver.driver);
2221 if (ret < 0) {
2222 printk(KERN_ERR IPATH_DRV_NAME ": Unable to create driver "
2223 "sysfs entries: error %d\n", -ret);
2224 goto bail_pci;
2225 }
2226
2227 ret = ipath_init_ipathfs(); 2223 ret = ipath_init_ipathfs();
2228 if (ret < 0) { 2224 if (ret < 0) {
2229 printk(KERN_ERR IPATH_DRV_NAME ": Unable to create " 2225 printk(KERN_ERR IPATH_DRV_NAME ": Unable to create "
2230 "ipathfs: error %d\n", -ret); 2226 "ipathfs: error %d\n", -ret);
2231 goto bail_group; 2227 goto bail_pci;
2232 } 2228 }
2233 2229
2234 goto bail; 2230 goto bail;
2235 2231
2236bail_group:
2237 ipath_driver_remove_group(&ipath_driver.driver);
2238
2239bail_pci: 2232bail_pci:
2240 pci_unregister_driver(&ipath_driver); 2233 pci_unregister_driver(&ipath_driver);
2241 2234
@@ -2250,8 +2243,6 @@ static void __exit infinipath_cleanup(void)
2250{ 2243{
2251 ipath_exit_ipathfs(); 2244 ipath_exit_ipathfs();
2252 2245
2253 ipath_driver_remove_group(&ipath_driver.driver);
2254
2255 ipath_cdbg(VERBOSE, "Unregistering pci driver\n"); 2246 ipath_cdbg(VERBOSE, "Unregistering pci driver\n");
2256 pci_unregister_driver(&ipath_driver); 2247 pci_unregister_driver(&ipath_driver);
2257 2248
diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
index 8786dd7922e4..bb1dc075f1d1 100644
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -938,8 +938,7 @@ struct device_driver;
938 938
939extern const char ib_ipath_version[]; 939extern const char ib_ipath_version[];
940 940
941int ipath_driver_create_group(struct device_driver *); 941extern struct attribute_group *ipath_driver_attr_groups[];
942void ipath_driver_remove_group(struct device_driver *);
943 942
944int ipath_device_create_group(struct device *, struct ipath_devdata *); 943int ipath_device_create_group(struct device *, struct ipath_devdata *);
945void ipath_device_remove_group(struct device *, struct ipath_devdata *); 944void ipath_device_remove_group(struct device *, struct ipath_devdata *);
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
index e1ad7cfc21fd..aa27ca9f03b1 100644
--- a/drivers/infiniband/hw/ipath/ipath_sysfs.c
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -683,6 +683,11 @@ static struct attribute_group driver_attr_group = {
683 .attrs = driver_attributes 683 .attrs = driver_attributes
684}; 684};
685 685
686struct attribute_group *ipath_driver_attr_groups[] = {
687 &driver_attr_group,
688 NULL,
689};
690
686static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); 691static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
687static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc); 692static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);
688static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid); 693static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
@@ -753,24 +758,9 @@ int ipath_expose_reset(struct device *dev)
753 return ret; 758 return ret;
754} 759}
755 760
756int ipath_driver_create_group(struct device_driver *drv)
757{
758 int ret;
759
760 ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
761
762 return ret;
763}
764
765void ipath_driver_remove_group(struct device_driver *drv)
766{
767 sysfs_remove_group(&drv->kobj, &driver_attr_group);
768}
769
770int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) 761int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
771{ 762{
772 int ret; 763 int ret;
773 char unit[5];
774 764
775 ret = sysfs_create_group(&dev->kobj, &dev_attr_group); 765 ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
776 if (ret) 766 if (ret)
@@ -780,11 +770,6 @@ int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
780 if (ret) 770 if (ret)
781 goto bail_attrs; 771 goto bail_attrs;
782 772
783 snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
784 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
785 if (ret == 0)
786 goto bail;
787
788 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); 773 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
789bail_attrs: 774bail_attrs:
790 sysfs_remove_group(&dev->kobj, &dev_attr_group); 775 sysfs_remove_group(&dev->kobj, &dev_attr_group);
@@ -794,11 +779,6 @@ bail:
794 779
795void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd) 780void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
796{ 781{
797 char unit[5];
798
799 snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
800 sysfs_remove_link(&dev->driver->kobj, unit);
801
802 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); 782 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
803 sysfs_remove_group(&dev->kobj, &dev_attr_group); 783 sysfs_remove_group(&dev->kobj, &dev_attr_group);
804 784
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index f449daef3eed..23ae66c76d47 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1544,11 +1544,11 @@ static int __init capi_init(void)
1544 return PTR_ERR(capi_class); 1544 return PTR_ERR(capi_class);
1545 } 1545 }
1546 1546
1547 class_device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); 1547 device_create(capi_class, NULL, MKDEV(capi_major, 0), "capi");
1548 1548
1549#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 1549#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1550 if (capinc_tty_init() < 0) { 1550 if (capinc_tty_init() < 0) {
1551 class_device_destroy(capi_class, MKDEV(capi_major, 0)); 1551 device_destroy(capi_class, MKDEV(capi_major, 0));
1552 class_destroy(capi_class); 1552 class_destroy(capi_class);
1553 unregister_chrdev(capi_major, "capi20"); 1553 unregister_chrdev(capi_major, "capi20");
1554 return -ENOMEM; 1554 return -ENOMEM;
@@ -1576,7 +1576,7 @@ static void __exit capi_exit(void)
1576{ 1576{
1577 proc_exit(); 1577 proc_exit();
1578 1578
1579 class_device_destroy(capi_class, MKDEV(capi_major, 0)); 1579 device_destroy(capi_class, MKDEV(capi_major, 0));
1580 class_destroy(capi_class); 1580 class_destroy(capi_class);
1581 unregister_chrdev(capi_major, "capi20"); 1581 unregister_chrdev(capi_major, "capi20");
1582 1582
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index 48c1775ef5b3..cb42b690b45e 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2332,13 +2332,14 @@ static int __init capidrv_init(void)
2332 2332
2333static void __exit capidrv_exit(void) 2333static void __exit capidrv_exit(void)
2334{ 2334{
2335 char rev[10]; 2335 char rev[32];
2336 char *p; 2336 char *p;
2337 2337
2338 if ((p = strchr(revision, ':')) != 0) { 2338 if ((p = strchr(revision, ':')) != 0) {
2339 strcpy(rev, p + 1); 2339 strncpy(rev, p + 1, sizeof(rev));
2340 p = strchr(rev, '$'); 2340 rev[sizeof(rev)-1] = 0;
2341 *p = 0; 2341 if ((p = strchr(rev, '$')) != 0)
2342 *p = 0;
2342 } else { 2343 } else {
2343 strcpy(rev, " ??? "); 2344 strcpy(rev, " ??? ");
2344 } 2345 }
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index a0317abaeb11..02bdaf22d7ea 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -106,12 +106,6 @@ enum debuglevel {
106 activated */ 106 activated */
107}; 107};
108 108
109/* missing from linux/device.h ... */
110#ifndef dev_notice
111#define dev_notice(dev, format, arg...) \
112 dev_printk(KERN_NOTICE , dev , format , ## arg)
113#endif
114
115/* Kernel message macros for situations where dev_printk and friends cannot be 109/* Kernel message macros for situations where dev_printk and friends cannot be
116 * used for lack of reliable access to a device structure. 110 * used for lack of reliable access to a device structure.
117 * linux/usb.h already contains these but in an obsolete form which clutters 111 * linux/usb.h already contains these but in an obsolete form which clutters
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 47c10b8f89b3..c0f372f1d761 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -3451,7 +3451,7 @@ static int kvm_resume(struct sys_device *dev)
3451} 3451}
3452 3452
3453static struct sysdev_class kvm_sysdev_class = { 3453static struct sysdev_class kvm_sysdev_class = {
3454 set_kset_name("kvm"), 3454 .name = "kvm",
3455 .suspend = kvm_suspend, 3455 .suspend = kvm_suspend,
3456 .resume = kvm_resume, 3456 .resume = kvm_resume,
3457}; 3457};
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 5c742a526082..b7adde4324e4 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -875,5 +875,5 @@ adbdev_init(void)
875 adb_dev_class = class_create(THIS_MODULE, "adb"); 875 adb_dev_class = class_create(THIS_MODULE, "adb");
876 if (IS_ERR(adb_dev_class)) 876 if (IS_ERR(adb_dev_class))
877 return; 877 return;
878 class_device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb"); 878 device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), "adb");
879} 879}
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 6123c70153d3..ac420b17e16f 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2796,7 +2796,7 @@ static int pmu_sys_resume(struct sys_device *sysdev)
2796#endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */ 2796#endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */
2797 2797
2798static struct sysdev_class pmu_sysclass = { 2798static struct sysdev_class pmu_sysclass = {
2799 set_kset_name("pmu"), 2799 .name = "pmu",
2800}; 2800};
2801 2801
2802static struct sys_device device_pmu = { 2802static struct sys_device device_pmu = {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 88c0fd657825..f2d24eb3208c 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1109,7 +1109,7 @@ static void event_callback(void *context)
1109 list_splice_init(&md->uevent_list, &uevents); 1109 list_splice_init(&md->uevent_list, &uevents);
1110 spin_unlock_irqrestore(&md->uevent_lock, flags); 1110 spin_unlock_irqrestore(&md->uevent_lock, flags);
1111 1111
1112 dm_send_uevents(&uevents, &md->disk->kobj); 1112 dm_send_uevents(&uevents, &md->disk->dev.kobj);
1113 1113
1114 atomic_inc(&md->event_nr); 1114 atomic_inc(&md->event_nr);
1115 wake_up(&md->eventq); 1115 wake_up(&md->eventq);
@@ -1530,7 +1530,7 @@ out:
1530 *---------------------------------------------------------------*/ 1530 *---------------------------------------------------------------*/
1531void dm_kobject_uevent(struct mapped_device *md) 1531void dm_kobject_uevent(struct mapped_device *md)
1532{ 1532{
1533 kobject_uevent(&md->disk->kobj, KOBJ_CHANGE); 1533 kobject_uevent(&md->disk->dev.kobj, KOBJ_CHANGE);
1534} 1534}
1535 1535
1536uint32_t dm_next_uevent_seq(struct mapped_device *md) 1536uint32_t dm_next_uevent_seq(struct mapped_device *md)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index cef9ebd5a046..c28a120b4161 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -231,7 +231,7 @@ static void mddev_put(mddev_t *mddev)
231 list_del(&mddev->all_mddevs); 231 list_del(&mddev->all_mddevs);
232 spin_unlock(&all_mddevs_lock); 232 spin_unlock(&all_mddevs_lock);
233 blk_cleanup_queue(mddev->queue); 233 blk_cleanup_queue(mddev->queue);
234 kobject_unregister(&mddev->kobj); 234 kobject_put(&mddev->kobj);
235 } else 235 } else
236 spin_unlock(&all_mddevs_lock); 236 spin_unlock(&all_mddevs_lock);
237} 237}
@@ -1383,22 +1383,19 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1383 return -EBUSY; 1383 return -EBUSY;
1384 } 1384 }
1385 bdevname(rdev->bdev,b); 1385 bdevname(rdev->bdev,b);
1386 if (kobject_set_name(&rdev->kobj, "dev-%s", b) < 0) 1386 while ( (s=strchr(b, '/')) != NULL)
1387 return -ENOMEM;
1388 while ( (s=strchr(rdev->kobj.k_name, '/')) != NULL)
1389 *s = '!'; 1387 *s = '!';
1390 1388
1391 rdev->mddev = mddev; 1389 rdev->mddev = mddev;
1392 printk(KERN_INFO "md: bind<%s>\n", b); 1390 printk(KERN_INFO "md: bind<%s>\n", b);
1393 1391
1394 rdev->kobj.parent = &mddev->kobj; 1392 if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
1395 if ((err = kobject_add(&rdev->kobj)))
1396 goto fail; 1393 goto fail;
1397 1394
1398 if (rdev->bdev->bd_part) 1395 if (rdev->bdev->bd_part)
1399 ko = &rdev->bdev->bd_part->kobj; 1396 ko = &rdev->bdev->bd_part->dev.kobj;
1400 else 1397 else
1401 ko = &rdev->bdev->bd_disk->kobj; 1398 ko = &rdev->bdev->bd_disk->dev.kobj;
1402 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { 1399 if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
1403 kobject_del(&rdev->kobj); 1400 kobject_del(&rdev->kobj);
1404 goto fail; 1401 goto fail;
@@ -2036,9 +2033,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2036 if (err) 2033 if (err)
2037 goto abort_free; 2034 goto abort_free;
2038 2035
2039 rdev->kobj.parent = NULL; 2036 kobject_init(&rdev->kobj, &rdev_ktype);
2040 rdev->kobj.ktype = &rdev_ktype;
2041 kobject_init(&rdev->kobj);
2042 2037
2043 rdev->desc_nr = -1; 2038 rdev->desc_nr = -1;
2044 rdev->saved_raid_disk = -1; 2039 rdev->saved_raid_disk = -1;
@@ -3054,6 +3049,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
3054 int partitioned = (MAJOR(dev) != MD_MAJOR); 3049 int partitioned = (MAJOR(dev) != MD_MAJOR);
3055 int shift = partitioned ? MdpMinorShift : 0; 3050 int shift = partitioned ? MdpMinorShift : 0;
3056 int unit = MINOR(dev) >> shift; 3051 int unit = MINOR(dev) >> shift;
3052 int error;
3057 3053
3058 if (!mddev) 3054 if (!mddev)
3059 return NULL; 3055 return NULL;
@@ -3082,12 +3078,13 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
3082 add_disk(disk); 3078 add_disk(disk);
3083 mddev->gendisk = disk; 3079 mddev->gendisk = disk;
3084 mutex_unlock(&disks_mutex); 3080 mutex_unlock(&disks_mutex);
3085 mddev->kobj.parent = &disk->kobj; 3081 error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
3086 kobject_set_name(&mddev->kobj, "%s", "md"); 3082 "%s", "md");
3087 mddev->kobj.ktype = &md_ktype; 3083 if (error)
3088 if (kobject_register(&mddev->kobj))
3089 printk(KERN_WARNING "md: cannot register %s/md - name in use\n", 3084 printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
3090 disk->disk_name); 3085 disk->disk_name);
3086 else
3087 kobject_uevent(&mddev->kobj, KOBJ_ADD);
3091 return NULL; 3088 return NULL;
3092} 3089}
3093 3090
@@ -3359,7 +3356,7 @@ static int do_md_run(mddev_t * mddev)
3359 3356
3360 mddev->changed = 1; 3357 mddev->changed = 1;
3361 md_new_event(mddev); 3358 md_new_event(mddev);
3362 kobject_uevent(&mddev->gendisk->kobj, KOBJ_CHANGE); 3359 kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
3363 return 0; 3360 return 0;
3364} 3361}
3365 3362
diff --git a/drivers/mfd/ucb1x00-assabet.c b/drivers/mfd/ucb1x00-assabet.c
index e325fa71f38b..b7c8e7813865 100644
--- a/drivers/mfd/ucb1x00-assabet.c
+++ b/drivers/mfd/ucb1x00-assabet.c
@@ -20,7 +20,8 @@
20#include "ucb1x00.h" 20#include "ucb1x00.h"
21 21
22#define UCB1X00_ATTR(name,input)\ 22#define UCB1X00_ATTR(name,input)\
23static ssize_t name##_show(struct class_device *dev, char *buf) \ 23static ssize_t name##_show(struct device *dev, struct device_attribute *attr,
24 char *buf) \
24{ \ 25{ \
25 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \ 26 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
26 int val; \ 27 int val; \
@@ -29,7 +30,7 @@ static ssize_t name##_show(struct class_device *dev, char *buf) \
29 ucb1x00_adc_disable(ucb); \ 30 ucb1x00_adc_disable(ucb); \
30 return sprintf(buf, "%d\n", val); \ 31 return sprintf(buf, "%d\n", val); \
31} \ 32} \
32static CLASS_DEVICE_ATTR(name,0444,name##_show,NULL) 33static DEVICE_ATTR(name,0444,name##_show,NULL)
33 34
34UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1); 35UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
35UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0); 36UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
@@ -37,17 +38,17 @@ UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);
37 38
38static int ucb1x00_assabet_add(struct ucb1x00_dev *dev) 39static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
39{ 40{
40 class_device_create_file(&dev->ucb->cdev, &class_device_attr_vbatt); 41 device_create_file(&dev->ucb->dev, &device_attr_vbatt);
41 class_device_create_file(&dev->ucb->cdev, &class_device_attr_vcharger); 42 device_create_file(&dev->ucb->dev, &device_attr_vcharger);
42 class_device_create_file(&dev->ucb->cdev, &class_device_attr_batt_temp); 43 device_create_file(&dev->ucb->dev, &device_attr_batt_temp);
43 return 0; 44 return 0;
44} 45}
45 46
46static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev) 47static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
47{ 48{
48 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_batt_temp); 49 device_remove_file(&dev->ucb->cdev, &device_attr_batt_temp);
49 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vcharger); 50 device_remove_file(&dev->ucb->cdev, &device_attr_vcharger);
50 class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vbatt); 51 device_remove_file(&dev->ucb->cdev, &device_attr_vbatt);
51} 52}
52 53
53static struct ucb1x00_driver ucb1x00_assabet_driver = { 54static struct ucb1x00_driver ucb1x00_assabet_driver = {
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index e03f1bcd4f9f..f6b10dda31fd 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -458,7 +458,7 @@ static int ucb1x00_detect_irq(struct ucb1x00 *ucb)
458 return probe_irq_off(mask); 458 return probe_irq_off(mask);
459} 459}
460 460
461static void ucb1x00_release(struct class_device *dev) 461static void ucb1x00_release(struct device *dev)
462{ 462{
463 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); 463 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev);
464 kfree(ucb); 464 kfree(ucb);
@@ -466,7 +466,7 @@ static void ucb1x00_release(struct class_device *dev)
466 466
467static struct class ucb1x00_class = { 467static struct class ucb1x00_class = {
468 .name = "ucb1x00", 468 .name = "ucb1x00",
469 .release = ucb1x00_release, 469 .dev_release = ucb1x00_release,
470}; 470};
471 471
472static int ucb1x00_probe(struct mcp *mcp) 472static int ucb1x00_probe(struct mcp *mcp)
@@ -490,9 +490,9 @@ static int ucb1x00_probe(struct mcp *mcp)
490 goto err_disable; 490 goto err_disable;
491 491
492 492
493 ucb->cdev.class = &ucb1x00_class; 493 ucb->dev.class = &ucb1x00_class;
494 ucb->cdev.dev = &mcp->attached_device; 494 ucb->dev.parent = &mcp->attached_device;
495 strlcpy(ucb->cdev.class_id, "ucb1x00", sizeof(ucb->cdev.class_id)); 495 strlcpy(ucb->dev.bus_id, "ucb1x00", sizeof(ucb->dev.bus_id));
496 496
497 spin_lock_init(&ucb->lock); 497 spin_lock_init(&ucb->lock);
498 spin_lock_init(&ucb->io_lock); 498 spin_lock_init(&ucb->io_lock);
@@ -517,7 +517,7 @@ static int ucb1x00_probe(struct mcp *mcp)
517 517
518 mcp_set_drvdata(mcp, ucb); 518 mcp_set_drvdata(mcp, ucb);
519 519
520 ret = class_device_register(&ucb->cdev); 520 ret = device_register(&ucb->dev);
521 if (ret) 521 if (ret)
522 goto err_irq; 522 goto err_irq;
523 523
@@ -554,7 +554,7 @@ static void ucb1x00_remove(struct mcp *mcp)
554 mutex_unlock(&ucb1x00_mutex); 554 mutex_unlock(&ucb1x00_mutex);
555 555
556 free_irq(ucb->irq, ucb); 556 free_irq(ucb->irq, ucb);
557 class_device_unregister(&ucb->cdev); 557 device_unregister(&ucb->dev);
558} 558}
559 559
560int ucb1x00_register_driver(struct ucb1x00_driver *drv) 560int ucb1x00_register_driver(struct ucb1x00_driver *drv)
diff --git a/drivers/mfd/ucb1x00.h b/drivers/mfd/ucb1x00.h
index ca8df8072d43..a8ad8a0ed5db 100644
--- a/drivers/mfd/ucb1x00.h
+++ b/drivers/mfd/ucb1x00.h
@@ -120,7 +120,7 @@ struct ucb1x00 {
120 u16 irq_fal_enbl; 120 u16 irq_fal_enbl;
121 u16 irq_ris_enbl; 121 u16 irq_ris_enbl;
122 struct ucb1x00_irq irq_handler[16]; 122 struct ucb1x00_irq irq_handler[16];
123 struct class_device cdev; 123 struct device dev;
124 struct list_head node; 124 struct list_head node;
125 struct list_head devs; 125 struct list_head devs;
126}; 126};
@@ -144,7 +144,7 @@ struct ucb1x00_driver {
144 int (*resume)(struct ucb1x00_dev *dev); 144 int (*resume)(struct ucb1x00_dev *dev);
145}; 145};
146 146
147#define classdev_to_ucb1x00(cd) container_of(cd, struct ucb1x00, cdev) 147#define classdev_to_ucb1x00(cd) container_of(cd, struct ucb1x00, dev)
148 148
149int ucb1x00_register_driver(struct ucb1x00_driver *); 149int ucb1x00_register_driver(struct ucb1x00_driver *);
150void ucb1x00_unregister_driver(struct ucb1x00_driver *); 150void ucb1x00_unregister_driver(struct ucb1x00_driver *);
diff --git a/drivers/misc/ibmasm/command.c b/drivers/misc/ibmasm/command.c
index 6497872df524..1a0e7978226a 100644
--- a/drivers/misc/ibmasm/command.c
+++ b/drivers/misc/ibmasm/command.c
@@ -26,11 +26,6 @@
26#include "lowlevel.h" 26#include "lowlevel.h"
27 27
28static void exec_next_command(struct service_processor *sp); 28static void exec_next_command(struct service_processor *sp);
29static void free_command(struct kobject *kobj);
30
31static struct kobj_type ibmasm_cmd_kobj_type = {
32 .release = free_command,
33};
34 29
35static atomic_t command_count = ATOMIC_INIT(0); 30static atomic_t command_count = ATOMIC_INIT(0);
36 31
@@ -53,8 +48,7 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s
53 } 48 }
54 cmd->buffer_size = buffer_size; 49 cmd->buffer_size = buffer_size;
55 50
56 kobject_init(&cmd->kobj); 51 kref_init(&cmd->kref);
57 cmd->kobj.ktype = &ibmasm_cmd_kobj_type;
58 cmd->lock = &sp->lock; 52 cmd->lock = &sp->lock;
59 53
60 cmd->status = IBMASM_CMD_PENDING; 54 cmd->status = IBMASM_CMD_PENDING;
@@ -67,9 +61,9 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s
67 return cmd; 61 return cmd;
68} 62}
69 63
70static void free_command(struct kobject *kobj) 64void ibmasm_free_command(struct kref *kref)
71{ 65{
72 struct command *cmd = to_command(kobj); 66 struct command *cmd = to_command(kref);
73 67
74 list_del(&cmd->queue_node); 68 list_del(&cmd->queue_node);
75 atomic_dec(&command_count); 69 atomic_dec(&command_count);
diff --git a/drivers/misc/ibmasm/ibmasm.h b/drivers/misc/ibmasm/ibmasm.h
index de860bc6d3f5..4d8a4e248b34 100644
--- a/drivers/misc/ibmasm/ibmasm.h
+++ b/drivers/misc/ibmasm/ibmasm.h
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/kref.h>
34#include <linux/device.h> 35#include <linux/device.h>
35#include <linux/input.h> 36#include <linux/input.h>
36 37
@@ -92,24 +93,25 @@ struct command {
92 unsigned char *buffer; 93 unsigned char *buffer;
93 size_t buffer_size; 94 size_t buffer_size;
94 int status; 95 int status;
95 struct kobject kobj; 96 struct kref kref;
96 spinlock_t *lock; 97 spinlock_t *lock;
97}; 98};
98#define to_command(c) container_of(c, struct command, kobj) 99#define to_command(c) container_of(c, struct command, kref)
99 100
101void ibmasm_free_command(struct kref *kref);
100static inline void command_put(struct command *cmd) 102static inline void command_put(struct command *cmd)
101{ 103{
102 unsigned long flags; 104 unsigned long flags;
103 spinlock_t *lock = cmd->lock; 105 spinlock_t *lock = cmd->lock;
104 106
105 spin_lock_irqsave(lock, flags); 107 spin_lock_irqsave(lock, flags);
106 kobject_put(&cmd->kobj); 108 kref_put(&cmd->kref, ibmasm_free_command);
107 spin_unlock_irqrestore(lock, flags); 109 spin_unlock_irqrestore(lock, flags);
108} 110}
109 111
110static inline void command_get(struct command *cmd) 112static inline void command_get(struct command *cmd)
111{ 113{
112 kobject_get(&cmd->kobj); 114 kref_get(&cmd->kref);
113} 115}
114 116
115 117
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index 2d1b3df95c5b..54380da343a5 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -149,7 +149,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
149 socket_change_set = fm->socket_change_set; 149 socket_change_set = fm->socket_change_set;
150 fm->socket_change_set = 0; 150 fm->socket_change_set = 0;
151 151
152 dev_dbg(fm->cdev.dev, "checking media set %x\n", 152 dev_dbg(fm->dev.parent, "checking media set %x\n",
153 socket_change_set); 153 socket_change_set);
154 154
155 if (!socket_change_set) { 155 if (!socket_change_set) {
@@ -164,7 +164,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
164 if (sock) { 164 if (sock) {
165 printk(KERN_INFO 165 printk(KERN_INFO
166 "%s : demand removing card from socket %u:%u\n", 166 "%s : demand removing card from socket %u:%u\n",
167 fm->cdev.class_id, fm->id, cnt); 167 fm->dev.bus_id, fm->id, cnt);
168 fm->sockets[cnt] = NULL; 168 fm->sockets[cnt] = NULL;
169 sock_addr = sock->addr; 169 sock_addr = sock->addr;
170 spin_unlock_irqrestore(&fm->lock, flags); 170 spin_unlock_irqrestore(&fm->lock, flags);
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c
index 8f77949f93dd..97544052e768 100644
--- a/drivers/misc/tifm_core.c
+++ b/drivers/misc/tifm_core.c
@@ -160,16 +160,16 @@ static struct bus_type tifm_bus_type = {
160 .resume = tifm_device_resume 160 .resume = tifm_device_resume
161}; 161};
162 162
163static void tifm_free(struct class_device *cdev) 163static void tifm_free(struct device *dev)
164{ 164{
165 struct tifm_adapter *fm = container_of(cdev, struct tifm_adapter, cdev); 165 struct tifm_adapter *fm = container_of(dev, struct tifm_adapter, dev);
166 166
167 kfree(fm); 167 kfree(fm);
168} 168}
169 169
170static struct class tifm_adapter_class = { 170static struct class tifm_adapter_class = {
171 .name = "tifm_adapter", 171 .name = "tifm_adapter",
172 .release = tifm_free 172 .dev_release = tifm_free
173}; 173};
174 174
175struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets, 175struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
@@ -180,9 +180,9 @@ struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
180 fm = kzalloc(sizeof(struct tifm_adapter) 180 fm = kzalloc(sizeof(struct tifm_adapter)
181 + sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL); 181 + sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL);
182 if (fm) { 182 if (fm) {
183 fm->cdev.class = &tifm_adapter_class; 183 fm->dev.class = &tifm_adapter_class;
184 fm->cdev.dev = dev; 184 fm->dev.parent = dev;
185 class_device_initialize(&fm->cdev); 185 device_initialize(&fm->dev);
186 spin_lock_init(&fm->lock); 186 spin_lock_init(&fm->lock);
187 fm->num_sockets = num_sockets; 187 fm->num_sockets = num_sockets;
188 } 188 }
@@ -203,8 +203,8 @@ int tifm_add_adapter(struct tifm_adapter *fm)
203 if (rc) 203 if (rc)
204 return rc; 204 return rc;
205 205
206 snprintf(fm->cdev.class_id, BUS_ID_SIZE, "tifm%u", fm->id); 206 snprintf(fm->dev.bus_id, BUS_ID_SIZE, "tifm%u", fm->id);
207 rc = class_device_add(&fm->cdev); 207 rc = device_add(&fm->dev);
208 if (rc) { 208 if (rc) {
209 spin_lock(&tifm_adapter_lock); 209 spin_lock(&tifm_adapter_lock);
210 idr_remove(&tifm_adapter_idr, fm->id); 210 idr_remove(&tifm_adapter_idr, fm->id);
@@ -228,13 +228,13 @@ void tifm_remove_adapter(struct tifm_adapter *fm)
228 spin_lock(&tifm_adapter_lock); 228 spin_lock(&tifm_adapter_lock);
229 idr_remove(&tifm_adapter_idr, fm->id); 229 idr_remove(&tifm_adapter_idr, fm->id);
230 spin_unlock(&tifm_adapter_lock); 230 spin_unlock(&tifm_adapter_lock);
231 class_device_del(&fm->cdev); 231 device_del(&fm->dev);
232} 232}
233EXPORT_SYMBOL(tifm_remove_adapter); 233EXPORT_SYMBOL(tifm_remove_adapter);
234 234
235void tifm_free_adapter(struct tifm_adapter *fm) 235void tifm_free_adapter(struct tifm_adapter *fm)
236{ 236{
237 class_device_put(&fm->cdev); 237 put_device(&fm->dev);
238} 238}
239EXPORT_SYMBOL(tifm_free_adapter); 239EXPORT_SYMBOL(tifm_free_adapter);
240 240
@@ -261,9 +261,9 @@ struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id,
261 sock->card_event = tifm_dummy_event; 261 sock->card_event = tifm_dummy_event;
262 sock->data_event = tifm_dummy_event; 262 sock->data_event = tifm_dummy_event;
263 263
264 sock->dev.parent = fm->cdev.dev; 264 sock->dev.parent = fm->dev.parent;
265 sock->dev.bus = &tifm_bus_type; 265 sock->dev.bus = &tifm_bus_type;
266 sock->dev.dma_mask = fm->cdev.dev->dma_mask; 266 sock->dev.dma_mask = fm->dev.parent->dma_mask;
267 sock->dev.release = tifm_free_device; 267 sock->dev.release = tifm_free_device;
268 268
269 snprintf(sock->dev.bus_id, BUS_ID_SIZE, 269 snprintf(sock->dev.bus_id, BUS_ID_SIZE,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 22ed96c4b7bd..a0cee86464ca 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -27,12 +27,10 @@ static void mtd_notify_add(struct mtd_info* mtd)
27 if (!mtd) 27 if (!mtd)
28 return; 28 return;
29 29
30 class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 30 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index);
31 NULL, "mtd%d", mtd->index);
32 31
33 class_device_create(mtd_class, NULL, 32 device_create(mtd_class, NULL,
34 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 33 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), "mtd%dro", mtd->index);
35 NULL, "mtd%dro", mtd->index);
36} 34}
37 35
38static void mtd_notify_remove(struct mtd_info* mtd) 36static void mtd_notify_remove(struct mtd_info* mtd)
@@ -40,8 +38,8 @@ static void mtd_notify_remove(struct mtd_info* mtd)
40 if (!mtd) 38 if (!mtd)
41 return; 39 return;
42 40
43 class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2)); 41 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
44 class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1)); 42 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
45} 43}
46 44
47static struct mtd_notifier notifier = { 45static struct mtd_notifier notifier = {
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 7d7758f3ad8c..57772bebff56 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1179,13 +1179,15 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_
1179 1179
1180 for(i = 0; i<IbmVethNumBufferPools; i++) { 1180 for(i = 0; i<IbmVethNumBufferPools; i++) {
1181 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj; 1181 struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
1182 int error;
1183
1182 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i, 1184 ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
1183 pool_count[i], pool_size[i], 1185 pool_count[i], pool_size[i],
1184 pool_active[i]); 1186 pool_active[i]);
1185 kobj->parent = &dev->dev.kobj; 1187 error = kobject_init_and_add(kobj, &ktype_veth_pool,
1186 kobject_set_name(kobj, "pool%d", i); 1188 &dev->dev.kobj, "pool%d", i);
1187 kobj->ktype = &ktype_veth_pool; 1189 if (!error)
1188 kobject_register(kobj); 1190 kobject_uevent(kobj, KOBJ_ADD);
1189 } 1191 }
1190 1192
1191 ibmveth_debug_printk("adapter @ 0x%p\n", adapter); 1193 ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
@@ -1234,7 +1236,7 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)
1234 int i; 1236 int i;
1235 1237
1236 for(i = 0; i<IbmVethNumBufferPools; i++) 1238 for(i = 0; i<IbmVethNumBufferPools; i++)
1237 kobject_unregister(&adapter->rx_buff_pool[i].kobj); 1239 kobject_put(&adapter->rx_buff_pool[i].kobj);
1238 1240
1239 unregister_netdev(netdev); 1241 unregister_netdev(netdev);
1240 1242
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 97bd9dc2e52e..419861cbc65e 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -815,7 +815,7 @@ static int veth_init_connection(u8 rlp)
815{ 815{
816 struct veth_lpar_connection *cnx; 816 struct veth_lpar_connection *cnx;
817 struct veth_msg *msgs; 817 struct veth_msg *msgs;
818 int i, rc; 818 int i;
819 819
820 if ( (rlp == this_lp) 820 if ( (rlp == this_lp)
821 || ! HvLpConfig_doLpsCommunicateOnVirtualLan(this_lp, rlp) ) 821 || ! HvLpConfig_doLpsCommunicateOnVirtualLan(this_lp, rlp) )
@@ -844,11 +844,7 @@ static int veth_init_connection(u8 rlp)
844 844
845 /* This gets us 1 reference, which is held on behalf of the driver 845 /* This gets us 1 reference, which is held on behalf of the driver
846 * infrastructure. It's released at module unload. */ 846 * infrastructure. It's released at module unload. */
847 kobject_init(&cnx->kobject); 847 kobject_init(&cnx->kobject, &veth_lpar_connection_ktype);
848 cnx->kobject.ktype = &veth_lpar_connection_ktype;
849 rc = kobject_set_name(&cnx->kobject, "cnx%.2d", rlp);
850 if (rc != 0)
851 return rc;
852 848
853 msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL); 849 msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL);
854 if (! msgs) { 850 if (! msgs) {
@@ -1087,11 +1083,8 @@ static struct net_device * __init veth_probe_one(int vlan,
1087 return NULL; 1083 return NULL;
1088 } 1084 }
1089 1085
1090 kobject_init(&port->kobject); 1086 kobject_init(&port->kobject, &veth_port_ktype);
1091 port->kobject.parent = &dev->dev.kobj; 1087 if (0 != kobject_add(&port->kobject, &dev->dev.kobj, "veth_port"))
1092 port->kobject.ktype = &veth_port_ktype;
1093 kobject_set_name(&port->kobject, "veth_port");
1094 if (0 != kobject_add(&port->kobject))
1095 veth_error("Failed adding port for %s to sysfs.\n", dev->name); 1088 veth_error("Failed adding port for %s to sysfs.\n", dev->name);
1096 1089
1097 veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n", 1090 veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
@@ -1711,9 +1704,9 @@ static int __init veth_module_init(void)
1711 continue; 1704 continue;
1712 1705
1713 kobj = &veth_cnx[i]->kobject; 1706 kobj = &veth_cnx[i]->kobject;
1714 kobj->parent = &veth_driver.driver.kobj;
1715 /* If the add failes, complain but otherwise continue */ 1707 /* If the add failes, complain but otherwise continue */
1716 if (0 != kobject_add(kobj)) 1708 if (0 != driver_add_kobj(&veth_driver.driver, kobj,
1709 "cnx%.2d", veth_cnx[i]->remote_lp))
1717 veth_error("cnx %d: Failed adding to sysfs.\n", i); 1710 veth_error("cnx %d: Failed adding to sysfs.\n", i);
1718 } 1711 }
1719 1712
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index ff37bf437a99..1d706eae3052 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -395,8 +395,7 @@ static int __init cosa_init(void)
395 goto out_chrdev; 395 goto out_chrdev;
396 } 396 }
397 for (i=0; i<nr_cards; i++) { 397 for (i=0; i<nr_cards; i++) {
398 class_device_create(cosa_class, NULL, MKDEV(cosa_major, i), 398 device_create(cosa_class, NULL, MKDEV(cosa_major, i), "cosa%d", i);
399 NULL, "cosa%d", i);
400 } 399 }
401 err = 0; 400 err = 0;
402 goto out; 401 goto out;
@@ -415,7 +414,7 @@ static void __exit cosa_exit(void)
415 printk(KERN_INFO "Unloading the cosa module\n"); 414 printk(KERN_INFO "Unloading the cosa module\n");
416 415
417 for (i=0; i<nr_cards; i++) 416 for (i=0; i<nr_cards; i++)
418 class_device_destroy(cosa_class, MKDEV(cosa_major, i)); 417 device_destroy(cosa_class, MKDEV(cosa_major, i));
419 class_destroy(cosa_class); 418 class_destroy(cosa_class);
420 for (cosa=cosa_cards; nr_cards--; cosa++) { 419 for (cosa=cosa_cards; nr_cards--; cosa++) {
421 /* Clean up the per-channel data */ 420 /* Clean up the per-channel data */
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index ebb09e98d215..de34aa9d3136 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -120,7 +120,7 @@ struct pdcspath_entry pdcspath_entry_##_name = { \
120}; 120};
121 121
122#define PDCS_ATTR(_name, _mode, _show, _store) \ 122#define PDCS_ATTR(_name, _mode, _show, _store) \
123struct subsys_attribute pdcs_attr_##_name = { \ 123struct kobj_attribute pdcs_attr_##_name = { \
124 .attr = {.name = __stringify(_name), .mode = _mode}, \ 124 .attr = {.name = __stringify(_name), .mode = _mode}, \
125 .show = _show, \ 125 .show = _show, \
126 .store = _store, \ 126 .store = _store, \
@@ -523,15 +523,15 @@ static struct pdcspath_entry *pdcspath_entries[] = {
523 523
524/** 524/**
525 * pdcs_size_read - Stable Storage size output. 525 * pdcs_size_read - Stable Storage size output.
526 * @kset: An allocated and populated struct kset. We don't use it tho.
527 * @buf: The output buffer to write to. 526 * @buf: The output buffer to write to.
528 */ 527 */
529static ssize_t 528static ssize_t pdcs_size_read(struct kobject *kobj,
530pdcs_size_read(struct kset *kset, char *buf) 529 struct kobj_attribute *attr,
530 char *buf)
531{ 531{
532 char *out = buf; 532 char *out = buf;
533 533
534 if (!kset || !buf) 534 if (!buf)
535 return -EINVAL; 535 return -EINVAL;
536 536
537 /* show the size of the stable storage */ 537 /* show the size of the stable storage */
@@ -542,17 +542,17 @@ pdcs_size_read(struct kset *kset, char *buf)
542 542
543/** 543/**
544 * pdcs_auto_read - Stable Storage autoboot/search flag output. 544 * pdcs_auto_read - Stable Storage autoboot/search flag output.
545 * @kset: An allocated and populated struct kset. We don't use it tho.
546 * @buf: The output buffer to write to. 545 * @buf: The output buffer to write to.
547 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 546 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
548 */ 547 */
549static ssize_t 548static ssize_t pdcs_auto_read(struct kobject *kobj,
550pdcs_auto_read(struct kset *kset, char *buf, int knob) 549 struct kobj_attribute *attr,
550 char *buf, int knob)
551{ 551{
552 char *out = buf; 552 char *out = buf;
553 struct pdcspath_entry *pathentry; 553 struct pdcspath_entry *pathentry;
554 554
555 if (!kset || !buf) 555 if (!buf)
556 return -EINVAL; 556 return -EINVAL;
557 557
558 /* Current flags are stored in primary boot path entry */ 558 /* Current flags are stored in primary boot path entry */
@@ -568,40 +568,37 @@ pdcs_auto_read(struct kset *kset, char *buf, int knob)
568 568
569/** 569/**
570 * pdcs_autoboot_read - Stable Storage autoboot flag output. 570 * pdcs_autoboot_read - Stable Storage autoboot flag output.
571 * @kset: An allocated and populated struct kset. We don't use it tho.
572 * @buf: The output buffer to write to. 571 * @buf: The output buffer to write to.
573 */ 572 */
574static inline ssize_t 573static ssize_t pdcs_autoboot_read(struct kobject *kobj,
575pdcs_autoboot_read(struct kset *kset, char *buf) 574 struct kobj_attribute *attr, char *buf)
576{ 575{
577 return pdcs_auto_read(kset, buf, PF_AUTOBOOT); 576 return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT);
578} 577}
579 578
580/** 579/**
581 * pdcs_autosearch_read - Stable Storage autoboot flag output. 580 * pdcs_autosearch_read - Stable Storage autoboot flag output.
582 * @kset: An allocated and populated struct kset. We don't use it tho.
583 * @buf: The output buffer to write to. 581 * @buf: The output buffer to write to.
584 */ 582 */
585static inline ssize_t 583static ssize_t pdcs_autosearch_read(struct kobject *kobj,
586pdcs_autosearch_read(struct kset *kset, char *buf) 584 struct kobj_attribute *attr, char *buf)
587{ 585{
588 return pdcs_auto_read(kset, buf, PF_AUTOSEARCH); 586 return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH);
589} 587}
590 588
591/** 589/**
592 * pdcs_timer_read - Stable Storage timer count output (in seconds). 590 * pdcs_timer_read - Stable Storage timer count output (in seconds).
593 * @kset: An allocated and populated struct kset. We don't use it tho.
594 * @buf: The output buffer to write to. 591 * @buf: The output buffer to write to.
595 * 592 *
596 * The value of the timer field correponds to a number of seconds in powers of 2. 593 * The value of the timer field correponds to a number of seconds in powers of 2.
597 */ 594 */
598static ssize_t 595static ssize_t pdcs_timer_read(struct kobject *kobj,
599pdcs_timer_read(struct kset *kset, char *buf) 596 struct kobj_attribute *attr, char *buf)
600{ 597{
601 char *out = buf; 598 char *out = buf;
602 struct pdcspath_entry *pathentry; 599 struct pdcspath_entry *pathentry;
603 600
604 if (!kset || !buf) 601 if (!buf)
605 return -EINVAL; 602 return -EINVAL;
606 603
607 /* Current flags are stored in primary boot path entry */ 604 /* Current flags are stored in primary boot path entry */
@@ -618,15 +615,14 @@ pdcs_timer_read(struct kset *kset, char *buf)
618 615
619/** 616/**
620 * pdcs_osid_read - Stable Storage OS ID register output. 617 * pdcs_osid_read - Stable Storage OS ID register output.
621 * @kset: An allocated and populated struct kset. We don't use it tho.
622 * @buf: The output buffer to write to. 618 * @buf: The output buffer to write to.
623 */ 619 */
624static ssize_t 620static ssize_t pdcs_osid_read(struct kobject *kobj,
625pdcs_osid_read(struct kset *kset, char *buf) 621 struct kobj_attribute *attr, char *buf)
626{ 622{
627 char *out = buf; 623 char *out = buf;
628 624
629 if (!kset || !buf) 625 if (!buf)
630 return -EINVAL; 626 return -EINVAL;
631 627
632 out += sprintf(out, "%s dependent data (0x%.4x)\n", 628 out += sprintf(out, "%s dependent data (0x%.4x)\n",
@@ -637,18 +633,17 @@ pdcs_osid_read(struct kset *kset, char *buf)
637 633
638/** 634/**
639 * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output. 635 * pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output.
640 * @kset: An allocated and populated struct kset. We don't use it tho.
641 * @buf: The output buffer to write to. 636 * @buf: The output buffer to write to.
642 * 637 *
643 * This can hold 16 bytes of OS-Dependent data. 638 * This can hold 16 bytes of OS-Dependent data.
644 */ 639 */
645static ssize_t 640static ssize_t pdcs_osdep1_read(struct kobject *kobj,
646pdcs_osdep1_read(struct kset *kset, char *buf) 641 struct kobj_attribute *attr, char *buf)
647{ 642{
648 char *out = buf; 643 char *out = buf;
649 u32 result[4]; 644 u32 result[4];
650 645
651 if (!kset || !buf) 646 if (!buf)
652 return -EINVAL; 647 return -EINVAL;
653 648
654 if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK) 649 if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK)
@@ -664,18 +659,17 @@ pdcs_osdep1_read(struct kset *kset, char *buf)
664 659
665/** 660/**
666 * pdcs_diagnostic_read - Stable Storage Diagnostic register output. 661 * pdcs_diagnostic_read - Stable Storage Diagnostic register output.
667 * @kset: An allocated and populated struct kset. We don't use it tho.
668 * @buf: The output buffer to write to. 662 * @buf: The output buffer to write to.
669 * 663 *
670 * I have NFC how to interpret the content of that register ;-). 664 * I have NFC how to interpret the content of that register ;-).
671 */ 665 */
672static ssize_t 666static ssize_t pdcs_diagnostic_read(struct kobject *kobj,
673pdcs_diagnostic_read(struct kset *kset, char *buf) 667 struct kobj_attribute *attr, char *buf)
674{ 668{
675 char *out = buf; 669 char *out = buf;
676 u32 result; 670 u32 result;
677 671
678 if (!kset || !buf) 672 if (!buf)
679 return -EINVAL; 673 return -EINVAL;
680 674
681 /* get diagnostic */ 675 /* get diagnostic */
@@ -689,18 +683,17 @@ pdcs_diagnostic_read(struct kset *kset, char *buf)
689 683
690/** 684/**
691 * pdcs_fastsize_read - Stable Storage FastSize register output. 685 * pdcs_fastsize_read - Stable Storage FastSize register output.
692 * @kset: An allocated and populated struct kset. We don't use it tho.
693 * @buf: The output buffer to write to. 686 * @buf: The output buffer to write to.
694 * 687 *
695 * This register holds the amount of system RAM to be tested during boot sequence. 688 * This register holds the amount of system RAM to be tested during boot sequence.
696 */ 689 */
697static ssize_t 690static ssize_t pdcs_fastsize_read(struct kobject *kobj,
698pdcs_fastsize_read(struct kset *kset, char *buf) 691 struct kobj_attribute *attr, char *buf)
699{ 692{
700 char *out = buf; 693 char *out = buf;
701 u32 result; 694 u32 result;
702 695
703 if (!kset || !buf) 696 if (!buf)
704 return -EINVAL; 697 return -EINVAL;
705 698
706 /* get fast-size */ 699 /* get fast-size */
@@ -718,13 +711,12 @@ pdcs_fastsize_read(struct kset *kset, char *buf)
718 711
719/** 712/**
720 * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output. 713 * pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output.
721 * @kset: An allocated and populated struct kset. We don't use it tho.
722 * @buf: The output buffer to write to. 714 * @buf: The output buffer to write to.
723 * 715 *
724 * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available. 716 * This can hold pdcs_size - 224 bytes of OS-Dependent data, when available.
725 */ 717 */
726static ssize_t 718static ssize_t pdcs_osdep2_read(struct kobject *kobj,
727pdcs_osdep2_read(struct kset *kset, char *buf) 719 struct kobj_attribute *attr, char *buf)
728{ 720{
729 char *out = buf; 721 char *out = buf;
730 unsigned long size; 722 unsigned long size;
@@ -736,7 +728,7 @@ pdcs_osdep2_read(struct kset *kset, char *buf)
736 728
737 size = pdcs_size - 224; 729 size = pdcs_size - 224;
738 730
739 if (!kset || !buf) 731 if (!buf)
740 return -EINVAL; 732 return -EINVAL;
741 733
742 for (i=0; i<size; i+=4) { 734 for (i=0; i<size; i+=4) {
@@ -751,7 +743,6 @@ pdcs_osdep2_read(struct kset *kset, char *buf)
751 743
752/** 744/**
753 * pdcs_auto_write - This function handles autoboot/search flag modifying. 745 * pdcs_auto_write - This function handles autoboot/search flag modifying.
754 * @kset: An allocated and populated struct kset. We don't use it tho.
755 * @buf: The input buffer to read from. 746 * @buf: The input buffer to read from.
756 * @count: The number of bytes to be read. 747 * @count: The number of bytes to be read.
757 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag 748 * @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
@@ -760,8 +751,9 @@ pdcs_osdep2_read(struct kset *kset, char *buf)
760 * We expect a precise syntax: 751 * We expect a precise syntax:
761 * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On 752 * \"n\" (n == 0 or 1) to toggle AutoBoot Off or On
762 */ 753 */
763static ssize_t 754static ssize_t pdcs_auto_write(struct kobject *kobj,
764pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob) 755 struct kobj_attribute *attr, const char *buf,
756 size_t count, int knob)
765{ 757{
766 struct pdcspath_entry *pathentry; 758 struct pdcspath_entry *pathentry;
767 unsigned char flags; 759 unsigned char flags;
@@ -771,7 +763,7 @@ pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob)
771 if (!capable(CAP_SYS_ADMIN)) 763 if (!capable(CAP_SYS_ADMIN))
772 return -EACCES; 764 return -EACCES;
773 765
774 if (!kset || !buf || !count) 766 if (!buf || !count)
775 return -EINVAL; 767 return -EINVAL;
776 768
777 /* We'll use a local copy of buf */ 769 /* We'll use a local copy of buf */
@@ -826,7 +818,6 @@ parse_error:
826 818
827/** 819/**
828 * pdcs_autoboot_write - This function handles autoboot flag modifying. 820 * pdcs_autoboot_write - This function handles autoboot flag modifying.
829 * @kset: An allocated and populated struct kset. We don't use it tho.
830 * @buf: The input buffer to read from. 821 * @buf: The input buffer to read from.
831 * @count: The number of bytes to be read. 822 * @count: The number of bytes to be read.
832 * 823 *
@@ -834,15 +825,15 @@ parse_error:
834 * We expect a precise syntax: 825 * We expect a precise syntax:
835 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 826 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
836 */ 827 */
837static inline ssize_t 828static ssize_t pdcs_autoboot_write(struct kobject *kobj,
838pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count) 829 struct kobj_attribute *attr,
830 const char *buf, size_t count)
839{ 831{
840 return pdcs_auto_write(kset, buf, count, PF_AUTOBOOT); 832 return pdcs_auto_write(kset, attr, buf, count, PF_AUTOBOOT);
841} 833}
842 834
843/** 835/**
844 * pdcs_autosearch_write - This function handles autosearch flag modifying. 836 * pdcs_autosearch_write - This function handles autosearch flag modifying.
845 * @kset: An allocated and populated struct kset. We don't use it tho.
846 * @buf: The input buffer to read from. 837 * @buf: The input buffer to read from.
847 * @count: The number of bytes to be read. 838 * @count: The number of bytes to be read.
848 * 839 *
@@ -850,15 +841,15 @@ pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count)
850 * We expect a precise syntax: 841 * We expect a precise syntax:
851 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On 842 * \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
852 */ 843 */
853static inline ssize_t 844static ssize_t pdcs_autosearch_write(struct kobject *kobj,
854pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count) 845 struct kobj_attribute *attr,
846 const char *buf, size_t count)
855{ 847{
856 return pdcs_auto_write(kset, buf, count, PF_AUTOSEARCH); 848 return pdcs_auto_write(kset, attr, buf, count, PF_AUTOSEARCH);
857} 849}
858 850
859/** 851/**
860 * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input. 852 * pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input.
861 * @kset: An allocated and populated struct kset. We don't use it tho.
862 * @buf: The input buffer to read from. 853 * @buf: The input buffer to read from.
863 * @count: The number of bytes to be read. 854 * @count: The number of bytes to be read.
864 * 855 *
@@ -866,15 +857,16 @@ pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count)
866 * write approach. It's up to userspace to deal with it when constructing 857 * write approach. It's up to userspace to deal with it when constructing
867 * its input buffer. 858 * its input buffer.
868 */ 859 */
869static ssize_t 860static ssize_t pdcs_osdep1_write(struct kobject *kobj,
870pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count) 861 struct kobj_attribute *attr,
862 const char *buf, size_t count)
871{ 863{
872 u8 in[16]; 864 u8 in[16];
873 865
874 if (!capable(CAP_SYS_ADMIN)) 866 if (!capable(CAP_SYS_ADMIN))
875 return -EACCES; 867 return -EACCES;
876 868
877 if (!kset || !buf || !count) 869 if (!buf || !count)
878 return -EINVAL; 870 return -EINVAL;
879 871
880 if (unlikely(pdcs_osid != OS_ID_LINUX)) 872 if (unlikely(pdcs_osid != OS_ID_LINUX))
@@ -895,7 +887,6 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)
895 887
896/** 888/**
897 * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input. 889 * pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input.
898 * @kset: An allocated and populated struct kset. We don't use it tho.
899 * @buf: The input buffer to read from. 890 * @buf: The input buffer to read from.
900 * @count: The number of bytes to be read. 891 * @count: The number of bytes to be read.
901 * 892 *
@@ -903,8 +894,9 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)
903 * byte-by-byte write approach. It's up to userspace to deal with it when 894 * byte-by-byte write approach. It's up to userspace to deal with it when
904 * constructing its input buffer. 895 * constructing its input buffer.
905 */ 896 */
906static ssize_t 897static ssize_t pdcs_osdep2_write(struct kobject *kobj,
907pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count) 898 struct kobj_attribute *attr,
899 const char *buf, size_t count)
908{ 900{
909 unsigned long size; 901 unsigned long size;
910 unsigned short i; 902 unsigned short i;
@@ -913,7 +905,7 @@ pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count)
913 if (!capable(CAP_SYS_ADMIN)) 905 if (!capable(CAP_SYS_ADMIN))
914 return -EACCES; 906 return -EACCES;
915 907
916 if (!kset || !buf || !count) 908 if (!buf || !count)
917 return -EINVAL; 909 return -EINVAL;
918 910
919 if (unlikely(pdcs_size <= 224)) 911 if (unlikely(pdcs_size <= 224))
@@ -951,21 +943,25 @@ static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL);
951static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL); 943static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL);
952static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write); 944static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write);
953 945
954static struct subsys_attribute *pdcs_subsys_attrs[] = { 946static struct attribute *pdcs_subsys_attrs[] = {
955 &pdcs_attr_size, 947 &pdcs_attr_size.attr,
956 &pdcs_attr_autoboot, 948 &pdcs_attr_autoboot.attr,
957 &pdcs_attr_autosearch, 949 &pdcs_attr_autosearch.attr,
958 &pdcs_attr_timer, 950 &pdcs_attr_timer.attr,
959 &pdcs_attr_osid, 951 &pdcs_attr_osid.attr,
960 &pdcs_attr_osdep1, 952 &pdcs_attr_osdep1.attr,
961 &pdcs_attr_diagnostic, 953 &pdcs_attr_diagnostic.attr,
962 &pdcs_attr_fastsize, 954 &pdcs_attr_fastsize.attr,
963 &pdcs_attr_osdep2, 955 &pdcs_attr_osdep2.attr,
964 NULL, 956 NULL,
965}; 957};
966 958
967static decl_subsys(paths, &ktype_pdcspath, NULL); 959static struct attribute_group pdcs_attr_group = {
968static decl_subsys(stable, NULL, NULL); 960 .attrs = pdcs_subsys_attrs,
961};
962
963static struct kobject *stable_kobj;
964static struct kset *paths_kset;
969 965
970/** 966/**
971 * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage. 967 * pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
@@ -995,12 +991,12 @@ pdcs_register_pathentries(void)
995 if (err < 0) 991 if (err < 0)
996 continue; 992 continue;
997 993
998 if ((err = kobject_set_name(&entry->kobj, "%s", entry->name))) 994 entry->kobj.kset = paths_kset;
999 return err; 995 err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
1000 kobj_set_kset_s(entry, paths_subsys); 996 "%s", entry->name);
1001 if ((err = kobject_register(&entry->kobj))) 997 if (err)
1002 return err; 998 return err;
1003 999
1004 /* kobject is now registered */ 1000 /* kobject is now registered */
1005 write_lock(&entry->rw_lock); 1001 write_lock(&entry->rw_lock);
1006 entry->ready = 2; 1002 entry->ready = 2;
@@ -1012,6 +1008,7 @@ pdcs_register_pathentries(void)
1012 } 1008 }
1013 1009
1014 write_unlock(&entry->rw_lock); 1010 write_unlock(&entry->rw_lock);
1011 kobject_uevent(&entry->kobj, KOBJ_ADD);
1015 } 1012 }
1016 1013
1017 return 0; 1014 return 0;
@@ -1029,7 +1026,7 @@ pdcs_unregister_pathentries(void)
1029 for (i = 0; (entry = pdcspath_entries[i]); i++) { 1026 for (i = 0; (entry = pdcspath_entries[i]); i++) {
1030 read_lock(&entry->rw_lock); 1027 read_lock(&entry->rw_lock);
1031 if (entry->ready >= 2) 1028 if (entry->ready >= 2)
1032 kobject_unregister(&entry->kobj); 1029 kobject_put(&entry->kobj);
1033 read_unlock(&entry->rw_lock); 1030 read_unlock(&entry->rw_lock);
1034 } 1031 }
1035} 1032}
@@ -1041,8 +1038,7 @@ pdcs_unregister_pathentries(void)
1041static int __init 1038static int __init
1042pdc_stable_init(void) 1039pdc_stable_init(void)
1043{ 1040{
1044 struct subsys_attribute *attr; 1041 int rc = 0, error = 0;
1045 int i, rc = 0, error = 0;
1046 u32 result; 1042 u32 result;
1047 1043
1048 /* find the size of the stable storage */ 1044 /* find the size of the stable storage */
@@ -1062,21 +1058,24 @@ pdc_stable_init(void)
1062 /* the actual result is 16 bits away */ 1058 /* the actual result is 16 bits away */
1063 pdcs_osid = (u16)(result >> 16); 1059 pdcs_osid = (u16)(result >> 16);
1064 1060
1065 /* For now we'll register the stable subsys within this driver */ 1061 /* For now we'll register the directory at /sys/firmware/stable */
1066 if ((rc = firmware_register(&stable_subsys))) 1062 stable_kobj = kobject_create_and_add("stable", firmware_kobj);
1063 if (!stable_kobj) {
1064 rc = -ENOMEM;
1067 goto fail_firmreg; 1065 goto fail_firmreg;
1066 }
1068 1067
1069 /* Don't forget the root entries */ 1068 /* Don't forget the root entries */
1070 for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++) 1069 error = sysfs_create_group(stable_kobj, pdcs_attr_group);
1071 if (attr->show)
1072 error = subsys_create_file(&stable_subsys, attr);
1073
1074 /* register the paths subsys as a subsystem of stable subsys */
1075 kobj_set_kset_s(&paths_subsys, stable_subsys);
1076 if ((rc = subsystem_register(&paths_subsys)))
1077 goto fail_subsysreg;
1078 1070
1079 /* now we create all "files" for the paths subsys */ 1071 /* register the paths kset as a child of the stable kset */
1072 paths_kset = kset_create_and_add("paths", NULL, stable_kobj);
1073 if (!paths_kset) {
1074 rc = -ENOMEM;
1075 goto fail_ksetreg;
1076 }
1077
1078 /* now we create all "files" for the paths kset */
1080 if ((rc = pdcs_register_pathentries())) 1079 if ((rc = pdcs_register_pathentries()))
1081 goto fail_pdcsreg; 1080 goto fail_pdcsreg;
1082 1081
@@ -1084,10 +1083,10 @@ pdc_stable_init(void)
1084 1083
1085fail_pdcsreg: 1084fail_pdcsreg:
1086 pdcs_unregister_pathentries(); 1085 pdcs_unregister_pathentries();
1087 subsystem_unregister(&paths_subsys); 1086 kset_unregister(paths_kset);
1088 1087
1089fail_subsysreg: 1088fail_ksetreg:
1090 firmware_unregister(&stable_subsys); 1089 kobject_put(stable_kobj);
1091 1090
1092fail_firmreg: 1091fail_firmreg:
1093 printk(KERN_INFO PDCS_PREFIX " bailing out\n"); 1092 printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1098,9 +1097,8 @@ static void __exit
1098pdc_stable_exit(void) 1097pdc_stable_exit(void)
1099{ 1098{
1100 pdcs_unregister_pathentries(); 1099 pdcs_unregister_pathentries();
1101 subsystem_unregister(&paths_subsys); 1100 kset_unregister(paths_kset);
1102 1101 kobject_put(stable_kobj);
1103 firmware_unregister(&stable_subsys);
1104} 1102}
1105 1103
1106 1104
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 47d26b65e99a..750ebd7a4c10 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -429,7 +429,7 @@ static int __init ibm_acpiphp_init(void)
429 int retval = 0; 429 int retval = 0;
430 acpi_status status; 430 acpi_status status;
431 struct acpi_device *device; 431 struct acpi_device *device;
432 struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj; 432 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;
433 433
434 dbg("%s\n", __FUNCTION__); 434 dbg("%s\n", __FUNCTION__);
435 435
@@ -476,7 +476,7 @@ init_return:
476static void __exit ibm_acpiphp_exit(void) 476static void __exit ibm_acpiphp_exit(void)
477{ 477{
478 acpi_status status; 478 acpi_status status;
479 struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj; 479 struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;
480 480
481 dbg("%s\n", __FUNCTION__); 481 dbg("%s\n", __FUNCTION__);
482 482
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 01c351c176ac..47bb0e1ff3fa 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -61,7 +61,7 @@ static int debug;
61 61
62static LIST_HEAD(pci_hotplug_slot_list); 62static LIST_HEAD(pci_hotplug_slot_list);
63 63
64struct kset pci_hotplug_slots_subsys; 64struct kset *pci_hotplug_slots_kset;
65 65
66static ssize_t hotplug_slot_attr_show(struct kobject *kobj, 66static ssize_t hotplug_slot_attr_show(struct kobject *kobj,
67 struct attribute *attr, char *buf) 67 struct attribute *attr, char *buf)
@@ -96,8 +96,6 @@ static struct kobj_type hotplug_slot_ktype = {
96 .release = &hotplug_slot_release, 96 .release = &hotplug_slot_release,
97}; 97};
98 98
99decl_subsys_name(pci_hotplug_slots, slots, &hotplug_slot_ktype, NULL);
100
101/* these strings match up with the values in pci_bus_speed */ 99/* these strings match up with the values in pci_bus_speed */
102static char *pci_bus_speed_strings[] = { 100static char *pci_bus_speed_strings[] = {
103 "33 MHz PCI", /* 0x00 */ 101 "33 MHz PCI", /* 0x00 */
@@ -632,18 +630,19 @@ int pci_hp_register (struct hotplug_slot *slot)
632 return -EINVAL; 630 return -EINVAL;
633 } 631 }
634 632
635 kobject_set_name(&slot->kobj, "%s", slot->name);
636 kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
637
638 /* this can fail if we have already registered a slot with the same name */ 633 /* this can fail if we have already registered a slot with the same name */
639 if (kobject_register(&slot->kobj)) { 634 slot->kobj.kset = pci_hotplug_slots_kset;
640 err("Unable to register kobject"); 635 result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL,
636 "%s", slot->name);
637 if (result) {
638 err("Unable to register kobject '%s'", slot->name);
641 return -EINVAL; 639 return -EINVAL;
642 } 640 }
643 641
644 list_add (&slot->slot_list, &pci_hotplug_slot_list); 642 list_add (&slot->slot_list, &pci_hotplug_slot_list);
645 643
646 result = fs_add_slot (slot); 644 result = fs_add_slot (slot);
645 kobject_uevent(&slot->kobj, KOBJ_ADD);
647 dbg ("Added slot %s to the list\n", slot->name); 646 dbg ("Added slot %s to the list\n", slot->name);
648 return result; 647 return result;
649} 648}
@@ -672,7 +671,7 @@ int pci_hp_deregister (struct hotplug_slot *slot)
672 671
673 fs_remove_slot (slot); 672 fs_remove_slot (slot);
674 dbg ("Removed slot %s from the list\n", slot->name); 673 dbg ("Removed slot %s from the list\n", slot->name);
675 kobject_unregister(&slot->kobj); 674 kobject_put(&slot->kobj);
676 return 0; 675 return 0;
677} 676}
678 677
@@ -700,11 +699,15 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
700static int __init pci_hotplug_init (void) 699static int __init pci_hotplug_init (void)
701{ 700{
702 int result; 701 int result;
702 struct kset *pci_bus_kset;
703 703
704 kobj_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys); 704 pci_bus_kset = bus_get_kset(&pci_bus_type);
705 result = subsystem_register(&pci_hotplug_slots_subsys); 705
706 if (result) { 706 pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
707 err("Register subsys with error %d\n", result); 707 &pci_bus_kset->kobj);
708 if (!pci_hotplug_slots_kset) {
709 result = -ENOMEM;
710 err("Register subsys error\n");
708 goto exit; 711 goto exit;
709 } 712 }
710 result = cpci_hotplug_init(debug); 713 result = cpci_hotplug_init(debug);
@@ -715,9 +718,9 @@ static int __init pci_hotplug_init (void)
715 718
716 info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); 719 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
717 goto exit; 720 goto exit;
718 721
719err_subsys: 722err_subsys:
720 subsystem_unregister(&pci_hotplug_slots_subsys); 723 kset_unregister(pci_hotplug_slots_kset);
721exit: 724exit:
722 return result; 725 return result;
723} 726}
@@ -725,7 +728,7 @@ exit:
725static void __exit pci_hotplug_exit (void) 728static void __exit pci_hotplug_exit (void)
726{ 729{
727 cpci_hotplug_exit(); 730 cpci_hotplug_exit();
728 subsystem_unregister(&pci_hotplug_slots_subsys); 731 kset_unregister(pci_hotplug_slots_kset);
729} 732}
730 733
731module_init(pci_hotplug_init); 734module_init(pci_hotplug_init);
@@ -737,7 +740,7 @@ MODULE_LICENSE("GPL");
737module_param(debug, bool, 0644); 740module_param(debug, bool, 0644);
738MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); 741MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
739 742
740EXPORT_SYMBOL_GPL(pci_hotplug_slots_subsys); 743EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset);
741EXPORT_SYMBOL_GPL(pci_hp_register); 744EXPORT_SYMBOL_GPL(pci_hp_register);
742EXPORT_SYMBOL_GPL(pci_hp_deregister); 745EXPORT_SYMBOL_GPL(pci_hp_deregister);
743EXPORT_SYMBOL_GPL(pci_hp_change_slot_info); 746EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index a080fedf0332..e32148a8fa12 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -23,44 +23,13 @@
23 23
24#define MAX_DRC_NAME_LEN 64 24#define MAX_DRC_NAME_LEN 64
25 25
26/* Store return code of dlpar operation in attribute struct */
27struct dlpar_io_attr {
28 int rc;
29 struct attribute attr;
30 ssize_t (*store)(struct dlpar_io_attr *dlpar_attr, const char *buf,
31 size_t nbytes);
32};
33 26
34/* Common show callback for all attrs, display the return code 27static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
35 * of the dlpar op */ 28 const char *buf, size_t nbytes)
36static ssize_t
37dlpar_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
38{
39 struct dlpar_io_attr *dlpar_attr = container_of(attr,
40 struct dlpar_io_attr, attr);
41 return sprintf(buf, "%d\n", dlpar_attr->rc);
42}
43
44static ssize_t
45dlpar_attr_store(struct kobject * kobj, struct attribute * attr,
46 const char *buf, size_t nbytes)
47{
48 struct dlpar_io_attr *dlpar_attr = container_of(attr,
49 struct dlpar_io_attr, attr);
50 return dlpar_attr->store ?
51 dlpar_attr->store(dlpar_attr, buf, nbytes) : -EIO;
52}
53
54static struct sysfs_ops dlpar_attr_sysfs_ops = {
55 .show = dlpar_attr_show,
56 .store = dlpar_attr_store,
57};
58
59static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
60 const char *buf, size_t nbytes)
61{ 29{
62 char drc_name[MAX_DRC_NAME_LEN]; 30 char drc_name[MAX_DRC_NAME_LEN];
63 char *end; 31 char *end;
32 int rc;
64 33
65 if (nbytes >= MAX_DRC_NAME_LEN) 34 if (nbytes >= MAX_DRC_NAME_LEN)
66 return 0; 35 return 0;
@@ -72,15 +41,25 @@ static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
72 end = &drc_name[nbytes]; 41 end = &drc_name[nbytes];
73 *end = '\0'; 42 *end = '\0';
74 43
75 dlpar_attr->rc = dlpar_add_slot(drc_name); 44 rc = dlpar_add_slot(drc_name);
45 if (rc)
46 return rc;
76 47
77 return nbytes; 48 return nbytes;
78} 49}
79 50
80static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr, 51static ssize_t add_slot_show(struct kobject *kobj,
81 const char *buf, size_t nbytes) 52 struct kobj_attribute *attr, char *buf)
53{
54 return sprintf(buf, "0\n");
55}
56
57static ssize_t remove_slot_store(struct kobject *kobj,
58 struct kobj_attribute *attr,
59 const char *buf, size_t nbytes)
82{ 60{
83 char drc_name[MAX_DRC_NAME_LEN]; 61 char drc_name[MAX_DRC_NAME_LEN];
62 int rc;
84 char *end; 63 char *end;
85 64
86 if (nbytes >= MAX_DRC_NAME_LEN) 65 if (nbytes >= MAX_DRC_NAME_LEN)
@@ -93,22 +72,24 @@ static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
93 end = &drc_name[nbytes]; 72 end = &drc_name[nbytes];
94 *end = '\0'; 73 *end = '\0';
95 74
96 dlpar_attr->rc = dlpar_remove_slot(drc_name); 75 rc = dlpar_remove_slot(drc_name);
76 if (rc)
77 return rc;
97 78
98 return nbytes; 79 return nbytes;
99} 80}
100 81
101static struct dlpar_io_attr add_slot_attr = { 82static ssize_t remove_slot_show(struct kobject *kobj,
102 .rc = 0, 83 struct kobj_attribute *attr, char *buf)
103 .attr = { .name = ADD_SLOT_ATTR_NAME, .mode = 0644, }, 84{
104 .store = add_slot_store, 85 return sprintf(buf, "0\n");
105}; 86}
106 87
107static struct dlpar_io_attr remove_slot_attr = { 88static struct kobj_attribute add_slot_attr =
108 .rc = 0, 89 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
109 .attr = { .name = REMOVE_SLOT_ATTR_NAME, .mode = 0644}, 90
110 .store = remove_slot_store, 91static struct kobj_attribute remove_slot_attr =
111}; 92 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
112 93
113static struct attribute *default_attrs[] = { 94static struct attribute *default_attrs[] = {
114 &add_slot_attr.attr, 95 &add_slot_attr.attr,
@@ -116,37 +97,29 @@ static struct attribute *default_attrs[] = {
116 NULL, 97 NULL,
117}; 98};
118 99
119static void dlpar_io_release(struct kobject *kobj) 100static struct attribute_group dlpar_attr_group = {
120{ 101 .attrs = default_attrs,
121 /* noop */
122 return;
123}
124
125struct kobj_type ktype_dlpar_io = {
126 .release = dlpar_io_release,
127 .sysfs_ops = &dlpar_attr_sysfs_ops,
128 .default_attrs = default_attrs,
129}; 102};
130 103
131struct kset dlpar_io_kset = { 104static struct kobject *dlpar_kobj;
132 .kobj = {.ktype = &ktype_dlpar_io,
133 .parent = &pci_hotplug_slots_subsys.kobj},
134 .ktype = &ktype_dlpar_io,
135};
136 105
137int dlpar_sysfs_init(void) 106int dlpar_sysfs_init(void)
138{ 107{
139 kobject_set_name(&dlpar_io_kset.kobj, DLPAR_KOBJ_NAME); 108 int error;
140 if (kset_register(&dlpar_io_kset)) { 109
141 printk(KERN_ERR "rpadlpar_io: cannot register kset for %s\n", 110 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
142 kobject_name(&dlpar_io_kset.kobj)); 111 &pci_hotplug_slots_kset->kobj);
112 if (!dlpar_kobj)
143 return -EINVAL; 113 return -EINVAL;
144 }
145 114
146 return 0; 115 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
116 if (error)
117 kobject_put(dlpar_kobj);
118 return error;
147} 119}
148 120
149void dlpar_sysfs_exit(void) 121void dlpar_sysfs_exit(void)
150{ 122{
151 kset_unregister(&dlpar_io_kset); 123 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
124 kobject_put(dlpar_kobj);
152} 125}
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 6d1a21611818..c4fa35d1dd77 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1,6 +1,11 @@
1/* 1/*
2 * drivers/pci/pci-driver.c 2 * drivers/pci/pci-driver.c
3 * 3 *
4 * (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <greg@kroah.com>
5 * (C) Copyright 2007 Novell Inc.
6 *
7 * Released under the GPL v2 only.
8 *
4 */ 9 */
5 10
6#include <linux/pci.h> 11#include <linux/pci.h>
@@ -96,17 +101,21 @@ pci_create_newid_file(struct pci_driver *drv)
96{ 101{
97 int error = 0; 102 int error = 0;
98 if (drv->probe != NULL) 103 if (drv->probe != NULL)
99 error = sysfs_create_file(&drv->driver.kobj, 104 error = driver_create_file(&drv->driver, &driver_attr_new_id);
100 &driver_attr_new_id.attr);
101 return error; 105 return error;
102} 106}
103 107
108static void pci_remove_newid_file(struct pci_driver *drv)
109{
110 driver_remove_file(&drv->driver, &driver_attr_new_id);
111}
104#else /* !CONFIG_HOTPLUG */ 112#else /* !CONFIG_HOTPLUG */
105static inline void pci_free_dynids(struct pci_driver *drv) {} 113static inline void pci_free_dynids(struct pci_driver *drv) {}
106static inline int pci_create_newid_file(struct pci_driver *drv) 114static inline int pci_create_newid_file(struct pci_driver *drv)
107{ 115{
108 return 0; 116 return 0;
109} 117}
118static inline void pci_remove_newid_file(struct pci_driver *drv) {}
110#endif 119#endif
111 120
112/** 121/**
@@ -352,50 +361,6 @@ static void pci_device_shutdown(struct device *dev)
352 drv->shutdown(pci_dev); 361 drv->shutdown(pci_dev);
353} 362}
354 363
355#define kobj_to_pci_driver(obj) container_of(obj, struct device_driver, kobj)
356#define attr_to_driver_attribute(obj) container_of(obj, struct driver_attribute, attr)
357
358static ssize_t
359pci_driver_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
360{
361 struct device_driver *driver = kobj_to_pci_driver(kobj);
362 struct driver_attribute *dattr = attr_to_driver_attribute(attr);
363 ssize_t ret;
364
365 if (!get_driver(driver))
366 return -ENODEV;
367
368 ret = dattr->show ? dattr->show(driver, buf) : -EIO;
369
370 put_driver(driver);
371 return ret;
372}
373
374static ssize_t
375pci_driver_attr_store(struct kobject * kobj, struct attribute *attr,
376 const char *buf, size_t count)
377{
378 struct device_driver *driver = kobj_to_pci_driver(kobj);
379 struct driver_attribute *dattr = attr_to_driver_attribute(attr);
380 ssize_t ret;
381
382 if (!get_driver(driver))
383 return -ENODEV;
384
385 ret = dattr->store ? dattr->store(driver, buf, count) : -EIO;
386
387 put_driver(driver);
388 return ret;
389}
390
391static struct sysfs_ops pci_driver_sysfs_ops = {
392 .show = pci_driver_attr_show,
393 .store = pci_driver_attr_store,
394};
395static struct kobj_type pci_driver_kobj_type = {
396 .sysfs_ops = &pci_driver_sysfs_ops,
397};
398
399/** 364/**
400 * __pci_register_driver - register a new pci driver 365 * __pci_register_driver - register a new pci driver
401 * @drv: the driver structure to register 366 * @drv: the driver structure to register
@@ -417,7 +382,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
417 drv->driver.bus = &pci_bus_type; 382 drv->driver.bus = &pci_bus_type;
418 drv->driver.owner = owner; 383 drv->driver.owner = owner;
419 drv->driver.mod_name = mod_name; 384 drv->driver.mod_name = mod_name;
420 drv->driver.kobj.ktype = &pci_driver_kobj_type;
421 385
422 spin_lock_init(&drv->dynids.lock); 386 spin_lock_init(&drv->dynids.lock);
423 INIT_LIST_HEAD(&drv->dynids.list); 387 INIT_LIST_HEAD(&drv->dynids.list);
@@ -447,6 +411,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
447void 411void
448pci_unregister_driver(struct pci_driver *drv) 412pci_unregister_driver(struct pci_driver *drv)
449{ 413{
414 pci_remove_newid_file(drv);
450 driver_unregister(&drv->driver); 415 driver_unregister(&drv->driver);
451 pci_free_dynids(drv); 416 pci_free_dynids(drv);
452} 417}
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c5ca3134513a..5fd585293e79 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1210,16 +1210,19 @@ static void __init pci_sort_breadthfirst_klist(void)
1210 struct klist_node *n; 1210 struct klist_node *n;
1211 struct device *dev; 1211 struct device *dev;
1212 struct pci_dev *pdev; 1212 struct pci_dev *pdev;
1213 struct klist *device_klist;
1213 1214
1214 spin_lock(&pci_bus_type.klist_devices.k_lock); 1215 device_klist = bus_get_device_klist(&pci_bus_type);
1215 list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) { 1216
1217 spin_lock(&device_klist->k_lock);
1218 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1216 n = container_of(pos, struct klist_node, n_node); 1219 n = container_of(pos, struct klist_node, n_node);
1217 dev = container_of(n, struct device, knode_bus); 1220 dev = container_of(n, struct device, knode_bus);
1218 pdev = to_pci_dev(dev); 1221 pdev = to_pci_dev(dev);
1219 pci_insertion_sort_klist(pdev, &sorted_devices); 1222 pci_insertion_sort_klist(pdev, &sorted_devices);
1220 } 1223 }
1221 list_splice(&sorted_devices, &pci_bus_type.klist_devices.k_list); 1224 list_splice(&sorted_devices, &device_klist->k_list);
1222 spin_unlock(&pci_bus_type.klist_devices.k_lock); 1225 spin_unlock(&device_klist->k_lock);
1223} 1226}
1224 1227
1225static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list) 1228static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list)
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 5cf89a91da1e..15c18f5246d6 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -312,8 +312,7 @@ pcmcia_create_newid_file(struct pcmcia_driver *drv)
312{ 312{
313 int error = 0; 313 int error = 0;
314 if (drv->probe != NULL) 314 if (drv->probe != NULL)
315 error = sysfs_create_file(&drv->drv.kobj, 315 error = driver_create_file(&drv->drv, &driver_attr_new_id);
316 &driver_attr_new_id.attr);
317 return error; 316 return error;
318} 317}
319 318
diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index bbf3ee10da04..7e29b90a4f63 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -13,6 +13,7 @@
13#include <linux/power_supply.h> 13#include <linux/power_supply.h>
14#include <linux/apm-emulation.h> 14#include <linux/apm-emulation.h>
15 15
16static DEFINE_MUTEX(apm_mutex);
16#define PSY_PROP(psy, prop, val) psy->get_property(psy, \ 17#define PSY_PROP(psy, prop, val) psy->get_property(psy, \
17 POWER_SUPPLY_PROP_##prop, val) 18 POWER_SUPPLY_PROP_##prop, val)
18 19
@@ -23,67 +24,86 @@
23 24
24static struct power_supply *main_battery; 25static struct power_supply *main_battery;
25 26
26static void find_main_battery(void) 27struct find_bat_param {
27{ 28 struct power_supply *main;
28 struct device *dev; 29 struct power_supply *bat;
29 struct power_supply *bat = NULL; 30 struct power_supply *max_charge_bat;
30 struct power_supply *max_charge_bat = NULL; 31 struct power_supply *max_energy_bat;
31 struct power_supply *max_energy_bat = NULL;
32 union power_supply_propval full; 32 union power_supply_propval full;
33 int max_charge = 0; 33 int max_charge;
34 int max_energy = 0; 34 int max_energy;
35};
35 36
36 main_battery = NULL; 37static int __find_main_battery(struct device *dev, void *data)
38{
39 struct find_bat_param *bp = (struct find_bat_param *)data;
37 40
38 list_for_each_entry(dev, &power_supply_class->devices, node) { 41 bp->bat = dev_get_drvdata(dev);
39 bat = dev_get_drvdata(dev);
40 42
41 if (bat->use_for_apm) { 43 if (bp->bat->use_for_apm) {
42 /* nice, we explicitly asked to report this battery. */ 44 /* nice, we explicitly asked to report this battery. */
43 main_battery = bat; 45 bp->main = bp->bat;
44 return; 46 return 1;
45 } 47 }
46 48
47 if (!PSY_PROP(bat, CHARGE_FULL_DESIGN, &full) || 49 if (!PSY_PROP(bp->bat, CHARGE_FULL_DESIGN, &bp->full) ||
48 !PSY_PROP(bat, CHARGE_FULL, &full)) { 50 !PSY_PROP(bp->bat, CHARGE_FULL, &bp->full)) {
49 if (full.intval > max_charge) { 51 if (bp->full.intval > bp->max_charge) {
50 max_charge_bat = bat; 52 bp->max_charge_bat = bp->bat;
51 max_charge = full.intval; 53 bp->max_charge = bp->full.intval;
52 } 54 }
53 } else if (!PSY_PROP(bat, ENERGY_FULL_DESIGN, &full) || 55 } else if (!PSY_PROP(bp->bat, ENERGY_FULL_DESIGN, &bp->full) ||
54 !PSY_PROP(bat, ENERGY_FULL, &full)) { 56 !PSY_PROP(bp->bat, ENERGY_FULL, &bp->full)) {
55 if (full.intval > max_energy) { 57 if (bp->full.intval > bp->max_energy) {
56 max_energy_bat = bat; 58 bp->max_energy_bat = bp->bat;
57 max_energy = full.intval; 59 bp->max_energy = bp->full.intval;
58 }
59 } 60 }
60 } 61 }
62 return 0;
63}
64
65static void find_main_battery(void)
66{
67 struct find_bat_param bp;
68 int error;
69
70 memset(&bp, 0, sizeof(struct find_bat_param));
71 main_battery = NULL;
72 bp.main = main_battery;
73
74 error = class_for_each_device(power_supply_class, &bp,
75 __find_main_battery);
76 if (error) {
77 main_battery = bp.main;
78 return;
79 }
61 80
62 if ((max_energy_bat && max_charge_bat) && 81 if ((bp.max_energy_bat && bp.max_charge_bat) &&
63 (max_energy_bat != max_charge_bat)) { 82 (bp.max_energy_bat != bp.max_charge_bat)) {
64 /* try guess battery with more capacity */ 83 /* try guess battery with more capacity */
65 if (!PSY_PROP(max_charge_bat, VOLTAGE_MAX_DESIGN, &full)) { 84 if (!PSY_PROP(bp.max_charge_bat, VOLTAGE_MAX_DESIGN,
66 if (max_energy > max_charge * full.intval) 85 &bp.full)) {
67 main_battery = max_energy_bat; 86 if (bp.max_energy > bp.max_charge * bp.full.intval)
87 main_battery = bp.max_energy_bat;
68 else 88 else
69 main_battery = max_charge_bat; 89 main_battery = bp.max_charge_bat;
70 } else if (!PSY_PROP(max_energy_bat, VOLTAGE_MAX_DESIGN, 90 } else if (!PSY_PROP(bp.max_energy_bat, VOLTAGE_MAX_DESIGN,
71 &full)) { 91 &bp.full)) {
72 if (max_charge > max_energy / full.intval) 92 if (bp.max_charge > bp.max_energy / bp.full.intval)
73 main_battery = max_charge_bat; 93 main_battery = bp.max_charge_bat;
74 else 94 else
75 main_battery = max_energy_bat; 95 main_battery = bp.max_energy_bat;
76 } else { 96 } else {
77 /* give up, choice any */ 97 /* give up, choice any */
78 main_battery = max_energy_bat; 98 main_battery = bp.max_energy_bat;
79 } 99 }
80 } else if (max_charge_bat) { 100 } else if (bp.max_charge_bat) {
81 main_battery = max_charge_bat; 101 main_battery = bp.max_charge_bat;
82 } else if (max_energy_bat) { 102 } else if (bp.max_energy_bat) {
83 main_battery = max_energy_bat; 103 main_battery = bp.max_energy_bat;
84 } else { 104 } else {
85 /* give up, try the last if any */ 105 /* give up, try the last if any */
86 main_battery = bat; 106 main_battery = bp.bat;
87 } 107 }
88} 108}
89 109
@@ -207,10 +227,10 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
207 union power_supply_propval status; 227 union power_supply_propval status;
208 union power_supply_propval capacity, time_to_full, time_to_empty; 228 union power_supply_propval capacity, time_to_full, time_to_empty;
209 229
210 down(&power_supply_class->sem); 230 mutex_lock(&apm_mutex);
211 find_main_battery(); 231 find_main_battery();
212 if (!main_battery) { 232 if (!main_battery) {
213 up(&power_supply_class->sem); 233 mutex_unlock(&apm_mutex);
214 return; 234 return;
215 } 235 }
216 236
@@ -278,7 +298,7 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
278 } 298 }
279 } 299 }
280 300
281 up(&power_supply_class->sem); 301 mutex_unlock(&apm_mutex);
282} 302}
283 303
284static int __init apm_battery_init(void) 304static int __init apm_battery_init(void)
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index a63b75cf75e2..03d6a38464ef 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -20,28 +20,29 @@
20 20
21struct class *power_supply_class; 21struct class *power_supply_class;
22 22
23static int __power_supply_changed_work(struct device *dev, void *data)
24{
25 struct power_supply *psy = (struct power_supply *)data;
26 struct power_supply *pst = dev_get_drvdata(dev);
27 int i;
28
29 for (i = 0; i < psy->num_supplicants; i++)
30 if (!strcmp(psy->supplied_to[i], pst->name)) {
31 if (pst->external_power_changed)
32 pst->external_power_changed(pst);
33 }
34 return 0;
35}
36
23static void power_supply_changed_work(struct work_struct *work) 37static void power_supply_changed_work(struct work_struct *work)
24{ 38{
25 struct power_supply *psy = container_of(work, struct power_supply, 39 struct power_supply *psy = container_of(work, struct power_supply,
26 changed_work); 40 changed_work);
27 int i;
28 41
29 dev_dbg(psy->dev, "%s\n", __FUNCTION__); 42 dev_dbg(psy->dev, "%s\n", __FUNCTION__);
30 43
31 for (i = 0; i < psy->num_supplicants; i++) { 44 class_for_each_device(power_supply_class, psy,
32 struct device *dev; 45 __power_supply_changed_work);
33
34 down(&power_supply_class->sem);
35 list_for_each_entry(dev, &power_supply_class->devices, node) {
36 struct power_supply *pst = dev_get_drvdata(dev);
37
38 if (!strcmp(psy->supplied_to[i], pst->name)) {
39 if (pst->external_power_changed)
40 pst->external_power_changed(pst);
41 }
42 }
43 up(&power_supply_class->sem);
44 }
45 46
46 power_supply_update_leds(psy); 47 power_supply_update_leds(psy);
47 48
@@ -55,32 +56,35 @@ void power_supply_changed(struct power_supply *psy)
55 schedule_work(&psy->changed_work); 56 schedule_work(&psy->changed_work);
56} 57}
57 58
58int power_supply_am_i_supplied(struct power_supply *psy) 59static int __power_supply_am_i_supplied(struct device *dev, void *data)
59{ 60{
60 union power_supply_propval ret = {0,}; 61 union power_supply_propval ret = {0,};
61 struct device *dev; 62 struct power_supply *psy = (struct power_supply *)data;
62 63 struct power_supply *epsy = dev_get_drvdata(dev);
63 down(&power_supply_class->sem); 64 int i;
64 list_for_each_entry(dev, &power_supply_class->devices, node) { 65
65 struct power_supply *epsy = dev_get_drvdata(dev); 66 for (i = 0; i < epsy->num_supplicants; i++) {
66 int i; 67 if (!strcmp(epsy->supplied_to[i], psy->name)) {
67 68 if (epsy->get_property(epsy,
68 for (i = 0; i < epsy->num_supplicants; i++) { 69 POWER_SUPPLY_PROP_ONLINE, &ret))
69 if (!strcmp(epsy->supplied_to[i], psy->name)) { 70 continue;
70 if (epsy->get_property(epsy, 71 if (ret.intval)
71 POWER_SUPPLY_PROP_ONLINE, &ret)) 72 return ret.intval;
72 continue;
73 if (ret.intval)
74 goto out;
75 }
76 } 73 }
77 } 74 }
78out: 75 return 0;
79 up(&power_supply_class->sem); 76}
77
78int power_supply_am_i_supplied(struct power_supply *psy)
79{
80 int error;
81
82 error = class_for_each_device(power_supply_class, psy,
83 __power_supply_am_i_supplied);
80 84
81 dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, ret.intval); 85 dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, error);
82 86
83 return ret.intval; 87 return error;
84} 88}
85 89
86int power_supply_register(struct device *parent, struct power_supply *psy) 90int power_supply_register(struct device *parent, struct power_supply *psy)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index f1e00ff54ce8..7e3ad4f3b343 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -251,20 +251,23 @@ void rtc_update_irq(struct rtc_device *rtc,
251} 251}
252EXPORT_SYMBOL_GPL(rtc_update_irq); 252EXPORT_SYMBOL_GPL(rtc_update_irq);
253 253
254static int __rtc_match(struct device *dev, void *data)
255{
256 char *name = (char *)data;
257
258 if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0)
259 return 1;
260 return 0;
261}
262
254struct rtc_device *rtc_class_open(char *name) 263struct rtc_device *rtc_class_open(char *name)
255{ 264{
256 struct device *dev; 265 struct device *dev;
257 struct rtc_device *rtc = NULL; 266 struct rtc_device *rtc = NULL;
258 267
259 down(&rtc_class->sem); 268 dev = class_find_device(rtc_class, name, __rtc_match);
260 list_for_each_entry(dev, &rtc_class->devices, node) { 269 if (dev)
261 if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0) { 270 rtc = to_rtc_device(dev);
262 dev = get_device(dev);
263 if (dev)
264 rtc = to_rtc_device(dev);
265 break;
266 }
267 }
268 271
269 if (rtc) { 272 if (rtc) {
270 if (!try_module_get(rtc->owner)) { 273 if (!try_module_get(rtc->owner)) {
@@ -272,7 +275,6 @@ struct rtc_device *rtc_class_open(char *name)
272 rtc = NULL; 275 rtc = NULL;
273 } 276 }
274 } 277 }
275 up(&rtc_class->sem);
276 278
277 return rtc; 279 return rtc;
278} 280}
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index c7ea9381db9f..d6e93f15440e 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -2089,6 +2089,11 @@ static struct attribute_group netiucv_drv_attr_group = {
2089 .attrs = netiucv_drv_attrs, 2089 .attrs = netiucv_drv_attrs,
2090}; 2090};
2091 2091
2092static struct attribute_group *netiucv_drv_attr_groups[] = {
2093 &netiucv_drv_attr_group,
2094 NULL,
2095};
2096
2092static void netiucv_banner(void) 2097static void netiucv_banner(void)
2093{ 2098{
2094 PRINT_INFO("NETIUCV driver initialized\n"); 2099 PRINT_INFO("NETIUCV driver initialized\n");
@@ -2113,7 +2118,6 @@ static void __exit netiucv_exit(void)
2113 netiucv_unregister_device(dev); 2118 netiucv_unregister_device(dev);
2114 } 2119 }
2115 2120
2116 sysfs_remove_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
2117 driver_unregister(&netiucv_driver); 2121 driver_unregister(&netiucv_driver);
2118 iucv_unregister(&netiucv_handler, 1); 2122 iucv_unregister(&netiucv_handler, 1);
2119 iucv_unregister_dbf_views(); 2123 iucv_unregister_dbf_views();
@@ -2133,6 +2137,7 @@ static int __init netiucv_init(void)
2133 if (rc) 2137 if (rc)
2134 goto out_dbf; 2138 goto out_dbf;
2135 IUCV_DBF_TEXT(trace, 3, __FUNCTION__); 2139 IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
2140 netiucv_driver.groups = netiucv_drv_attr_groups;
2136 rc = driver_register(&netiucv_driver); 2141 rc = driver_register(&netiucv_driver);
2137 if (rc) { 2142 if (rc) {
2138 PRINT_ERR("NETIUCV: failed to register driver.\n"); 2143 PRINT_ERR("NETIUCV: failed to register driver.\n");
@@ -2140,18 +2145,9 @@ static int __init netiucv_init(void)
2140 goto out_iucv; 2145 goto out_iucv;
2141 } 2146 }
2142 2147
2143 rc = sysfs_create_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
2144 if (rc) {
2145 PRINT_ERR("NETIUCV: failed to add driver attributes.\n");
2146 IUCV_DBF_TEXT_(setup, 2,
2147 "ret %d - netiucv_drv_attr_group\n", rc);
2148 goto out_driver;
2149 }
2150 netiucv_banner(); 2148 netiucv_banner();
2151 return rc; 2149 return rc;
2152 2150
2153out_driver:
2154 driver_unregister(&netiucv_driver);
2155out_iucv: 2151out_iucv:
2156 iucv_unregister(&netiucv_handler, 1); 2152 iucv_unregister(&netiucv_handler, 1);
2157out_dbf: 2153out_dbf:
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index e01cbf152a81..86c3f6539a7d 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -52,6 +52,9 @@ static struct ccw_driver zfcp_ccw_driver = {
52 .set_offline = zfcp_ccw_set_offline, 52 .set_offline = zfcp_ccw_set_offline,
53 .notify = zfcp_ccw_notify, 53 .notify = zfcp_ccw_notify,
54 .shutdown = zfcp_ccw_shutdown, 54 .shutdown = zfcp_ccw_shutdown,
55 .driver = {
56 .groups = zfcp_driver_attr_groups,
57 },
55}; 58};
56 59
57MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id); 60MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
@@ -251,16 +254,7 @@ zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
251int __init 254int __init
252zfcp_ccw_register(void) 255zfcp_ccw_register(void)
253{ 256{
254 int retval; 257 return ccw_driver_register(&zfcp_ccw_driver);
255
256 retval = ccw_driver_register(&zfcp_ccw_driver);
257 if (retval)
258 goto out;
259 retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
260 if (retval)
261 ccw_driver_unregister(&zfcp_ccw_driver);
262 out:
263 return retval;
264} 258}
265 259
266/** 260/**
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 8534cf09546c..06b1079b7f3d 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -27,8 +27,7 @@
27extern struct zfcp_data zfcp_data; 27extern struct zfcp_data zfcp_data;
28 28
29/******************************** SYSFS *************************************/ 29/******************************** SYSFS *************************************/
30extern int zfcp_sysfs_driver_create_files(struct device_driver *); 30extern struct attribute_group *zfcp_driver_attr_groups[];
31extern void zfcp_sysfs_driver_remove_files(struct device_driver *);
32extern int zfcp_sysfs_adapter_create_files(struct device *); 31extern int zfcp_sysfs_adapter_create_files(struct device *);
33extern void zfcp_sysfs_adapter_remove_files(struct device *); 32extern void zfcp_sysfs_adapter_remove_files(struct device *);
34extern int zfcp_sysfs_port_create_files(struct device *, u32); 33extern int zfcp_sysfs_port_create_files(struct device *, u32);
diff --git a/drivers/s390/scsi/zfcp_sysfs_driver.c b/drivers/s390/scsi/zfcp_sysfs_driver.c
index 005e62f8593b..651edd58906a 100644
--- a/drivers/s390/scsi/zfcp_sysfs_driver.c
+++ b/drivers/s390/scsi/zfcp_sysfs_driver.c
@@ -98,28 +98,9 @@ static struct attribute_group zfcp_driver_attr_group = {
98 .attrs = zfcp_driver_attrs, 98 .attrs = zfcp_driver_attrs,
99}; 99};
100 100
101/** 101struct attribute_group *zfcp_driver_attr_groups[] = {
102 * zfcp_sysfs_create_driver_files - create sysfs driver files 102 &zfcp_driver_attr_group,
103 * @dev: pointer to belonging device 103 NULL,
104 * 104};
105 * Create all sysfs attributes of the zfcp device driver
106 */
107int
108zfcp_sysfs_driver_create_files(struct device_driver *drv)
109{
110 return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
111}
112
113/**
114 * zfcp_sysfs_remove_driver_files - remove sysfs driver files
115 * @dev: pointer to belonging device
116 *
117 * Remove all sysfs attributes of the zfcp device driver
118 */
119void
120zfcp_sysfs_driver_remove_files(struct device_driver *drv)
121{
122 sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
123}
124 105
125#undef ZFCP_LOG_AREA 106#undef ZFCP_LOG_AREA
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 24271a871b8c..6325115e5b3d 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -429,6 +429,15 @@ void scsi_unregister(struct Scsi_Host *shost)
429} 429}
430EXPORT_SYMBOL(scsi_unregister); 430EXPORT_SYMBOL(scsi_unregister);
431 431
432static int __scsi_host_match(struct class_device *cdev, void *data)
433{
434 struct Scsi_Host *p;
435 unsigned short *hostnum = (unsigned short *)data;
436
437 p = class_to_shost(cdev);
438 return p->host_no == *hostnum;
439}
440
432/** 441/**
433 * scsi_host_lookup - get a reference to a Scsi_Host by host no 442 * scsi_host_lookup - get a reference to a Scsi_Host by host no
434 * 443 *
@@ -439,19 +448,12 @@ EXPORT_SYMBOL(scsi_unregister);
439 **/ 448 **/
440struct Scsi_Host *scsi_host_lookup(unsigned short hostnum) 449struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
441{ 450{
442 struct class *class = &shost_class;
443 struct class_device *cdev; 451 struct class_device *cdev;
444 struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p; 452 struct Scsi_Host *shost = ERR_PTR(-ENXIO);
445 453
446 down(&class->sem); 454 cdev = class_find_child(&shost_class, &hostnum, __scsi_host_match);
447 list_for_each_entry(cdev, &class->children, node) { 455 if (cdev)
448 p = class_to_shost(cdev); 456 shost = scsi_host_get(class_to_shost(cdev));
449 if (p->host_no == hostnum) {
450 shost = scsi_host_get(p);
451 break;
452 }
453 }
454 up(&class->sem);
455 457
456 return shost; 458 return shost;
457} 459}
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 7663841eb4cf..a3fdc57e2673 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -464,7 +464,7 @@ int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd)
464 res = sas_phy_reset(phy, 1); 464 res = sas_phy_reset(phy, 1);
465 if (res) 465 if (res)
466 SAS_DPRINTK("Bus reset of %s failed 0x%x\n", 466 SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
467 phy->dev.kobj.k_name, 467 kobject_name(&phy->dev.kobj),
468 res); 468 res);
469 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE) 469 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
470 return SUCCESS; 470 return SUCCESS;
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 9d3105b64a7a..9c2df5c857cf 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -48,7 +48,7 @@
48#include <linux/vmalloc.h> 48#include <linux/vmalloc.h>
49#include <linux/smp.h> 49#include <linux/smp.h>
50#include <linux/spinlock.h> 50#include <linux/spinlock.h>
51#include <linux/kobject.h> 51#include <linux/kref.h>
52#include <linux/firmware.h> 52#include <linux/firmware.h>
53#include <linux/bitops.h> 53#include <linux/bitops.h>
54 54
@@ -65,7 +65,7 @@
65#define ICOM_VERSION_STR "1.3.1" 65#define ICOM_VERSION_STR "1.3.1"
66#define NR_PORTS 128 66#define NR_PORTS 128
67#define ICOM_PORT ((struct icom_port *)port) 67#define ICOM_PORT ((struct icom_port *)port)
68#define to_icom_adapter(d) container_of(d, struct icom_adapter, kobj) 68#define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)
69 69
70static const struct pci_device_id icom_pci_table[] = { 70static const struct pci_device_id icom_pci_table[] = {
71 { 71 {
@@ -141,6 +141,7 @@ static inline void trace(struct icom_port *, char *, unsigned long) {};
141#else 141#else
142static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; 142static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
143#endif 143#endif
144static void icom_kref_release(struct kref *kref);
144 145
145static void free_port_memory(struct icom_port *icom_port) 146static void free_port_memory(struct icom_port *icom_port)
146{ 147{
@@ -1063,11 +1064,11 @@ static int icom_open(struct uart_port *port)
1063{ 1064{
1064 int retval; 1065 int retval;
1065 1066
1066 kobject_get(&ICOM_PORT->adapter->kobj); 1067 kref_get(&ICOM_PORT->adapter->kref);
1067 retval = startup(ICOM_PORT); 1068 retval = startup(ICOM_PORT);
1068 1069
1069 if (retval) { 1070 if (retval) {
1070 kobject_put(&ICOM_PORT->adapter->kobj); 1071 kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
1071 trace(ICOM_PORT, "STARTUP_ERROR", 0); 1072 trace(ICOM_PORT, "STARTUP_ERROR", 0);
1072 return retval; 1073 return retval;
1073 } 1074 }
@@ -1088,7 +1089,7 @@ static void icom_close(struct uart_port *port)
1088 1089
1089 shutdown(ICOM_PORT); 1090 shutdown(ICOM_PORT);
1090 1091
1091 kobject_put(&ICOM_PORT->adapter->kobj); 1092 kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
1092} 1093}
1093 1094
1094static void icom_set_termios(struct uart_port *port, 1095static void icom_set_termios(struct uart_port *port,
@@ -1485,18 +1486,14 @@ static void icom_remove_adapter(struct icom_adapter *icom_adapter)
1485 pci_release_regions(icom_adapter->pci_dev); 1486 pci_release_regions(icom_adapter->pci_dev);
1486} 1487}
1487 1488
1488static void icom_kobj_release(struct kobject *kobj) 1489static void icom_kref_release(struct kref *kref)
1489{ 1490{
1490 struct icom_adapter *icom_adapter; 1491 struct icom_adapter *icom_adapter;
1491 1492
1492 icom_adapter = to_icom_adapter(kobj); 1493 icom_adapter = to_icom_adapter(kref);
1493 icom_remove_adapter(icom_adapter); 1494 icom_remove_adapter(icom_adapter);
1494} 1495}
1495 1496
1496static struct kobj_type icom_kobj_type = {
1497 .release = icom_kobj_release,
1498};
1499
1500static int __devinit icom_probe(struct pci_dev *dev, 1497static int __devinit icom_probe(struct pci_dev *dev,
1501 const struct pci_device_id *ent) 1498 const struct pci_device_id *ent)
1502{ 1499{
@@ -1592,8 +1589,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
1592 } 1589 }
1593 } 1590 }
1594 1591
1595 kobject_init(&icom_adapter->kobj); 1592 kref_init(&icom_adapter->kref);
1596 icom_adapter->kobj.ktype = &icom_kobj_type;
1597 return 0; 1593 return 0;
1598 1594
1599probe_exit2: 1595probe_exit2:
@@ -1619,7 +1615,7 @@ static void __devexit icom_remove(struct pci_dev *dev)
1619 icom_adapter = list_entry(tmp, struct icom_adapter, 1615 icom_adapter = list_entry(tmp, struct icom_adapter,
1620 icom_adapter_entry); 1616 icom_adapter_entry);
1621 if (icom_adapter->pci_dev == dev) { 1617 if (icom_adapter->pci_dev == dev) {
1622 kobject_put(&icom_adapter->kobj); 1618 kref_put(&icom_adapter->kref, icom_kref_release);
1623 return; 1619 return;
1624 } 1620 }
1625 } 1621 }
diff --git a/drivers/serial/icom.h b/drivers/serial/icom.h
index e8578d8cd35e..027455496745 100644
--- a/drivers/serial/icom.h
+++ b/drivers/serial/icom.h
@@ -270,7 +270,7 @@ struct icom_adapter {
270#define V2_ONE_PORT_RVX_ONE_PORT_IMBED_MDM 0x0251 270#define V2_ONE_PORT_RVX_ONE_PORT_IMBED_MDM 0x0251
271 int numb_ports; 271 int numb_ports;
272 struct list_head icom_adapter_entry; 272 struct list_head icom_adapter_entry;
273 struct kobject kobj; 273 struct kref kref;
274}; 274};
275 275
276/* prototype */ 276/* prototype */
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 93e9de46977a..682a6a48fec3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -485,6 +485,15 @@ void spi_unregister_master(struct spi_master *master)
485} 485}
486EXPORT_SYMBOL_GPL(spi_unregister_master); 486EXPORT_SYMBOL_GPL(spi_unregister_master);
487 487
488static int __spi_master_match(struct device *dev, void *data)
489{
490 struct spi_master *m;
491 u16 *bus_num = data;
492
493 m = container_of(dev, struct spi_master, dev);
494 return m->bus_num == *bus_num;
495}
496
488/** 497/**
489 * spi_busnum_to_master - look up master associated with bus_num 498 * spi_busnum_to_master - look up master associated with bus_num
490 * @bus_num: the master's bus number 499 * @bus_num: the master's bus number
@@ -499,17 +508,12 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
499{ 508{
500 struct device *dev; 509 struct device *dev;
501 struct spi_master *master = NULL; 510 struct spi_master *master = NULL;
502 struct spi_master *m; 511
503 512 dev = class_find_device(&spi_master_class, &bus_num,
504 down(&spi_master_class.sem); 513 __spi_master_match);
505 list_for_each_entry(dev, &spi_master_class.children, node) { 514 if (dev)
506 m = container_of(dev, struct spi_master, dev); 515 master = container_of(dev, struct spi_master, dev);
507 if (m->bus_num == bus_num) { 516 /* reference got in class_find_device */
508 master = spi_master_get(m);
509 break;
510 }
511 }
512 up(&spi_master_class.sem);
513 return master; 517 return master;
514} 518}
515EXPORT_SYMBOL_GPL(spi_busnum_to_master); 519EXPORT_SYMBOL_GPL(spi_busnum_to_master);
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 865f32b63b5c..cc246faa3590 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -34,12 +34,12 @@ struct uio_device {
34 wait_queue_head_t wait; 34 wait_queue_head_t wait;
35 int vma_count; 35 int vma_count;
36 struct uio_info *info; 36 struct uio_info *info;
37 struct kset map_attr_kset; 37 struct kobject *map_dir;
38}; 38};
39 39
40static int uio_major; 40static int uio_major;
41static DEFINE_IDR(uio_idr); 41static DEFINE_IDR(uio_idr);
42static struct file_operations uio_fops; 42static const struct file_operations uio_fops;
43 43
44/* UIO class infrastructure */ 44/* UIO class infrastructure */
45static struct uio_class { 45static struct uio_class {
@@ -51,47 +51,48 @@ static struct uio_class {
51 * attributes 51 * attributes
52 */ 52 */
53 53
54static struct attribute attr_addr = { 54struct uio_map {
55 .name = "addr", 55 struct kobject kobj;
56 .mode = S_IRUGO, 56 struct uio_mem *mem;
57}; 57};
58#define to_map(map) container_of(map, struct uio_map, kobj)
58 59
59static struct attribute attr_size = {
60 .name = "size",
61 .mode = S_IRUGO,
62};
63 60
64static struct attribute* map_attrs[] = { 61static ssize_t map_attr_show(struct kobject *kobj, struct kobj_attribute *attr,
65 &attr_addr, &attr_size, NULL
66};
67
68static ssize_t map_attr_show(struct kobject *kobj, struct attribute *attr,
69 char *buf) 62 char *buf)
70{ 63{
71 struct uio_mem *mem = container_of(kobj, struct uio_mem, kobj); 64 struct uio_map *map = to_map(kobj);
65 struct uio_mem *mem = map->mem;
72 66
73 if (strncmp(attr->name,"addr",4) == 0) 67 if (strncmp(attr->attr.name, "addr", 4) == 0)
74 return sprintf(buf, "0x%lx\n", mem->addr); 68 return sprintf(buf, "0x%lx\n", mem->addr);
75 69
76 if (strncmp(attr->name,"size",4) == 0) 70 if (strncmp(attr->attr.name, "size", 4) == 0)
77 return sprintf(buf, "0x%lx\n", mem->size); 71 return sprintf(buf, "0x%lx\n", mem->size);
78 72
79 return -ENODEV; 73 return -ENODEV;
80} 74}
81 75
82static void map_attr_release(struct kobject *kobj) 76static struct kobj_attribute attr_attribute =
83{ 77 __ATTR(addr, S_IRUGO, map_attr_show, NULL);
84 /* TODO ??? */ 78static struct kobj_attribute size_attribute =
85} 79 __ATTR(size, S_IRUGO, map_attr_show, NULL);
86 80
87static struct sysfs_ops map_attr_ops = { 81static struct attribute *attrs[] = {
88 .show = map_attr_show, 82 &attr_attribute.attr,
83 &size_attribute.attr,
84 NULL, /* need to NULL terminate the list of attributes */
89}; 85};
90 86
87static void map_release(struct kobject *kobj)
88{
89 struct uio_map *map = to_map(kobj);
90 kfree(map);
91}
92
91static struct kobj_type map_attr_type = { 93static struct kobj_type map_attr_type = {
92 .release = map_attr_release, 94 .release = map_release,
93 .sysfs_ops = &map_attr_ops, 95 .default_attrs = attrs,
94 .default_attrs = map_attrs,
95}; 96};
96 97
97static ssize_t show_name(struct device *dev, 98static ssize_t show_name(struct device *dev,
@@ -148,6 +149,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
148 int mi; 149 int mi;
149 int map_found = 0; 150 int map_found = 0;
150 struct uio_mem *mem; 151 struct uio_mem *mem;
152 struct uio_map *map;
151 153
152 ret = sysfs_create_group(&idev->dev->kobj, &uio_attr_grp); 154 ret = sysfs_create_group(&idev->dev->kobj, &uio_attr_grp);
153 if (ret) 155 if (ret)
@@ -159,31 +161,34 @@ static int uio_dev_add_attributes(struct uio_device *idev)
159 break; 161 break;
160 if (!map_found) { 162 if (!map_found) {
161 map_found = 1; 163 map_found = 1;
162 kobject_set_name(&idev->map_attr_kset.kobj,"maps"); 164 idev->map_dir = kobject_create_and_add("maps",
163 idev->map_attr_kset.ktype = &map_attr_type; 165 &idev->dev->kobj);
164 idev->map_attr_kset.kobj.parent = &idev->dev->kobj; 166 if (!idev->map_dir)
165 ret = kset_register(&idev->map_attr_kset); 167 goto err;
166 if (ret)
167 goto err_remove_group;
168 } 168 }
169 kobject_init(&mem->kobj); 169 map = kzalloc(sizeof(*map), GFP_KERNEL);
170 kobject_set_name(&mem->kobj,"map%d",mi); 170 if (!map)
171 mem->kobj.parent = &idev->map_attr_kset.kobj; 171 goto err;
172 mem->kobj.kset = &idev->map_attr_kset; 172 kobject_init(&map->kobj, &map_attr_type);
173 ret = kobject_add(&mem->kobj); 173 map->mem = mem;
174 mem->map = map;
175 ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
176 if (ret)
177 goto err;
178 ret = kobject_uevent(&map->kobj, KOBJ_ADD);
174 if (ret) 179 if (ret)
175 goto err_remove_maps; 180 goto err;
176 } 181 }
177 182
178 return 0; 183 return 0;
179 184
180err_remove_maps: 185err:
181 for (mi--; mi>=0; mi--) { 186 for (mi--; mi>=0; mi--) {
182 mem = &idev->info->mem[mi]; 187 mem = &idev->info->mem[mi];
183 kobject_unregister(&mem->kobj); 188 map = mem->map;
189 kobject_put(&map->kobj);
184 } 190 }
185 kset_unregister(&idev->map_attr_kset); /* Needed ? */ 191 kobject_put(idev->map_dir);
186err_remove_group:
187 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp); 192 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
188err_group: 193err_group:
189 dev_err(idev->dev, "error creating sysfs files (%d)\n", ret); 194 dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
@@ -198,9 +203,9 @@ static void uio_dev_del_attributes(struct uio_device *idev)
198 mem = &idev->info->mem[mi]; 203 mem = &idev->info->mem[mi];
199 if (mem->size == 0) 204 if (mem->size == 0)
200 break; 205 break;
201 kobject_unregister(&mem->kobj); 206 kobject_put(&mem->map->kobj);
202 } 207 }
203 kset_unregister(&idev->map_attr_kset); 208 kobject_put(idev->map_dir);
204 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp); 209 sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
205} 210}
206 211
@@ -503,7 +508,7 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
503 } 508 }
504} 509}
505 510
506static struct file_operations uio_fops = { 511static const struct file_operations uio_fops = {
507 .owner = THIS_MODULE, 512 .owner = THIS_MODULE,
508 .open = uio_open, 513 .open = uio_open,
509 .release = uio_release, 514 .release = uio_release,
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index c51f8e9312e0..7c3aaa9c5402 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -91,8 +91,8 @@ static int usb_create_newid_file(struct usb_driver *usb_drv)
91 goto exit; 91 goto exit;
92 92
93 if (usb_drv->probe != NULL) 93 if (usb_drv->probe != NULL)
94 error = sysfs_create_file(&usb_drv->drvwrap.driver.kobj, 94 error = driver_create_file(&usb_drv->drvwrap.driver,
95 &driver_attr_new_id.attr); 95 &driver_attr_new_id);
96exit: 96exit:
97 return error; 97 return error;
98} 98}
@@ -103,8 +103,8 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)
103 return; 103 return;
104 104
105 if (usb_drv->probe != NULL) 105 if (usb_drv->probe != NULL)
106 sysfs_remove_file(&usb_drv->drvwrap.driver.kobj, 106 driver_remove_file(&usb_drv->drvwrap.driver,
107 &driver_attr_new_id.attr); 107 &driver_attr_new_id);
108} 108}
109 109
110static void usb_free_dynids(struct usb_driver *usb_drv) 110static void usb_free_dynids(struct usb_driver *usb_drv)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 993f78c55221..e48a630ae266 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release);
738static struct kobject *bdev_get_kobj(struct block_device *bdev) 738static struct kobject *bdev_get_kobj(struct block_device *bdev)
739{ 739{
740 if (bdev->bd_contains != bdev) 740 if (bdev->bd_contains != bdev)
741 return kobject_get(&bdev->bd_part->kobj); 741 return kobject_get(&bdev->bd_part->dev.kobj);
742 else 742 else
743 return kobject_get(&bdev->bd_disk->kobj); 743 return kobject_get(&bdev->bd_disk->dev.kobj);
744} 744}
745 745
746static struct kobject *bdev_get_holder(struct block_device *bdev) 746static struct kobject *bdev_get_holder(struct block_device *bdev)
@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1176 ret = -ENXIO; 1176 ret = -ENXIO;
1177 goto out_first; 1177 goto out_first;
1178 } 1178 }
1179 kobject_get(&p->kobj); 1179 kobject_get(&p->dev.kobj);
1180 bdev->bd_part = p; 1180 bdev->bd_part = p;
1181 bd_set_size(bdev, (loff_t) p->nr_sects << 9); 1181 bd_set_size(bdev, (loff_t) p->nr_sects << 9);
1182 } 1182 }
@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
1299 module_put(owner); 1299 module_put(owner);
1300 1300
1301 if (bdev->bd_contains != bdev) { 1301 if (bdev->bd_contains != bdev) {
1302 kobject_put(&bdev->bd_part->kobj); 1302 kobject_put(&bdev->bd_part->dev.kobj);
1303 bdev->bd_part = NULL; 1303 bdev->bd_part = NULL;
1304 } 1304 }
1305 bdev->bd_disk = NULL; 1305 bdev->bd_disk = NULL;
diff --git a/fs/char_dev.c b/fs/char_dev.c
index c3bfa76765c4..2c7a8b5b4598 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -510,9 +510,8 @@ struct cdev *cdev_alloc(void)
510{ 510{
511 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL); 511 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
512 if (p) { 512 if (p) {
513 p->kobj.ktype = &ktype_cdev_dynamic;
514 INIT_LIST_HEAD(&p->list); 513 INIT_LIST_HEAD(&p->list);
515 kobject_init(&p->kobj); 514 kobject_init(&p->kobj, &ktype_cdev_dynamic);
516 } 515 }
517 return p; 516 return p;
518} 517}
@@ -529,8 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops)
529{ 528{
530 memset(cdev, 0, sizeof *cdev); 529 memset(cdev, 0, sizeof *cdev);
531 INIT_LIST_HEAD(&cdev->list); 530 INIT_LIST_HEAD(&cdev->list);
532 cdev->kobj.ktype = &ktype_cdev_default; 531 kobject_init(&cdev->kobj, &ktype_cdev_default);
533 kobject_init(&cdev->kobj);
534 cdev->ops = fops; 532 cdev->ops = fops;
535} 533}
536 534
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index dcc6aead70f5..e3eb3556622b 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -362,8 +362,8 @@ static int init_coda_psdev(void)
362 goto out_chrdev; 362 goto out_chrdev;
363 } 363 }
364 for (i = 0; i < MAX_CODADEVS; i++) 364 for (i = 0; i < MAX_CODADEVS; i++)
365 class_device_create(coda_psdev_class, NULL, 365 device_create(coda_psdev_class, NULL,
366 MKDEV(CODA_PSDEV_MAJOR,i), NULL, "cfs%d", i); 366 MKDEV(CODA_PSDEV_MAJOR,i), "cfs%d", i);
367 coda_sysctl_init(); 367 coda_sysctl_init();
368 goto out; 368 goto out;
369 369
@@ -405,7 +405,7 @@ static int __init init_coda(void)
405 return 0; 405 return 0;
406out: 406out:
407 for (i = 0; i < MAX_CODADEVS; i++) 407 for (i = 0; i < MAX_CODADEVS; i++)
408 class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i)); 408 device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
409 class_destroy(coda_psdev_class); 409 class_destroy(coda_psdev_class);
410 unregister_chrdev(CODA_PSDEV_MAJOR, "coda"); 410 unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
411 coda_sysctl_clean(); 411 coda_sysctl_clean();
@@ -424,7 +424,7 @@ static void __exit exit_coda(void)
424 printk("coda: failed to unregister filesystem\n"); 424 printk("coda: failed to unregister filesystem\n");
425 } 425 }
426 for (i = 0; i < MAX_CODADEVS; i++) 426 for (i = 0; i < MAX_CODADEVS; i++)
427 class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i)); 427 device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
428 class_destroy(coda_psdev_class); 428 class_destroy(coda_psdev_class);
429 unregister_chrdev(CODA_PSDEV_MAJOR, "coda"); 429 unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
430 coda_sysctl_clean(); 430 coda_sysctl_clean();
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 3bf0278ea843..de3b31d0a37d 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -128,7 +128,7 @@ void configfs_release_fs(void)
128} 128}
129 129
130 130
131static decl_subsys(config, NULL, NULL); 131static struct kobject *config_kobj;
132 132
133static int __init configfs_init(void) 133static int __init configfs_init(void)
134{ 134{
@@ -140,9 +140,8 @@ static int __init configfs_init(void)
140 if (!configfs_dir_cachep) 140 if (!configfs_dir_cachep)
141 goto out; 141 goto out;
142 142
143 kobj_set_kset_s(&config_subsys, kernel_subsys); 143 config_kobj = kobject_create_and_add("config", kernel_kobj);
144 err = subsystem_register(&config_subsys); 144 if (!config_kobj) {
145 if (err) {
146 kmem_cache_destroy(configfs_dir_cachep); 145 kmem_cache_destroy(configfs_dir_cachep);
147 configfs_dir_cachep = NULL; 146 configfs_dir_cachep = NULL;
148 goto out; 147 goto out;
@@ -151,7 +150,7 @@ static int __init configfs_init(void)
151 err = register_filesystem(&configfs_fs_type); 150 err = register_filesystem(&configfs_fs_type);
152 if (err) { 151 if (err) {
153 printk(KERN_ERR "configfs: Unable to register filesystem!\n"); 152 printk(KERN_ERR "configfs: Unable to register filesystem!\n");
154 subsystem_unregister(&config_subsys); 153 kobject_put(config_kobj);
155 kmem_cache_destroy(configfs_dir_cachep); 154 kmem_cache_destroy(configfs_dir_cachep);
156 configfs_dir_cachep = NULL; 155 configfs_dir_cachep = NULL;
157 goto out; 156 goto out;
@@ -160,7 +159,7 @@ static int __init configfs_init(void)
160 err = configfs_inode_init(); 159 err = configfs_inode_init();
161 if (err) { 160 if (err) {
162 unregister_filesystem(&configfs_fs_type); 161 unregister_filesystem(&configfs_fs_type);
163 subsystem_unregister(&config_subsys); 162 kobject_put(config_kobj);
164 kmem_cache_destroy(configfs_dir_cachep); 163 kmem_cache_destroy(configfs_dir_cachep);
165 configfs_dir_cachep = NULL; 164 configfs_dir_cachep = NULL;
166 } 165 }
@@ -171,7 +170,7 @@ out:
171static void __exit configfs_exit(void) 170static void __exit configfs_exit(void)
172{ 171{
173 unregister_filesystem(&configfs_fs_type); 172 unregister_filesystem(&configfs_fs_type);
174 subsystem_unregister(&config_subsys); 173 kobject_put(config_kobj);
175 kmem_cache_destroy(configfs_dir_cachep); 174 kmem_cache_destroy(configfs_dir_cachep);
176 configfs_dir_cachep = NULL; 175 configfs_dir_cachep = NULL;
177 configfs_inode_exit(); 176 configfs_inode_exit();
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 6a713b33992f..d26e2826ba5b 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -426,20 +426,19 @@ exit:
426} 426}
427EXPORT_SYMBOL_GPL(debugfs_rename); 427EXPORT_SYMBOL_GPL(debugfs_rename);
428 428
429static decl_subsys(debug, NULL, NULL); 429static struct kobject *debug_kobj;
430 430
431static int __init debugfs_init(void) 431static int __init debugfs_init(void)
432{ 432{
433 int retval; 433 int retval;
434 434
435 kobj_set_kset_s(&debug_subsys, kernel_subsys); 435 debug_kobj = kobject_create_and_add("debug", kernel_kobj);
436 retval = subsystem_register(&debug_subsys); 436 if (!debug_kobj)
437 if (retval) 437 return -EINVAL;
438 return retval;
439 438
440 retval = register_filesystem(&debug_fs_type); 439 retval = register_filesystem(&debug_fs_type);
441 if (retval) 440 if (retval)
442 subsystem_unregister(&debug_subsys); 441 kobject_put(debug_kobj);
443 return retval; 442 return retval;
444} 443}
445 444
@@ -447,7 +446,7 @@ static void __exit debugfs_exit(void)
447{ 446{
448 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 447 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
449 unregister_filesystem(&debug_fs_type); 448 unregister_filesystem(&debug_fs_type);
450 subsystem_unregister(&debug_subsys); 449 kobject_put(debug_kobj);
451} 450}
452 451
453core_initcall(debugfs_init); 452core_initcall(debugfs_init);
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 6353a8384520..5c108c49cb8c 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -166,26 +166,7 @@ static struct kobj_type dlm_ktype = {
166 .release = lockspace_kobj_release, 166 .release = lockspace_kobj_release,
167}; 167};
168 168
169static struct kset dlm_kset = { 169static struct kset *dlm_kset;
170 .ktype = &dlm_ktype,
171};
172
173static int kobject_setup(struct dlm_ls *ls)
174{
175 char lsname[DLM_LOCKSPACE_LEN];
176 int error;
177
178 memset(lsname, 0, DLM_LOCKSPACE_LEN);
179 snprintf(lsname, DLM_LOCKSPACE_LEN, "%s", ls->ls_name);
180
181 error = kobject_set_name(&ls->ls_kobj, "%s", lsname);
182 if (error)
183 return error;
184
185 ls->ls_kobj.kset = &dlm_kset;
186 ls->ls_kobj.ktype = &dlm_ktype;
187 return 0;
188}
189 170
190static int do_uevent(struct dlm_ls *ls, int in) 171static int do_uevent(struct dlm_ls *ls, int in)
191{ 172{
@@ -220,24 +201,22 @@ static int do_uevent(struct dlm_ls *ls, int in)
220 201
221int dlm_lockspace_init(void) 202int dlm_lockspace_init(void)
222{ 203{
223 int error;
224
225 ls_count = 0; 204 ls_count = 0;
226 mutex_init(&ls_lock); 205 mutex_init(&ls_lock);
227 INIT_LIST_HEAD(&lslist); 206 INIT_LIST_HEAD(&lslist);
228 spin_lock_init(&lslist_lock); 207 spin_lock_init(&lslist_lock);
229 208
230 kobject_set_name(&dlm_kset.kobj, "dlm"); 209 dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj);
231 kobj_set_kset_s(&dlm_kset, kernel_subsys); 210 if (!dlm_kset) {
232 error = kset_register(&dlm_kset); 211 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
233 if (error) 212 return -ENOMEM;
234 printk("dlm_lockspace_init: cannot register kset %d\n", error); 213 }
235 return error; 214 return 0;
236} 215}
237 216
238void dlm_lockspace_exit(void) 217void dlm_lockspace_exit(void)
239{ 218{
240 kset_unregister(&dlm_kset); 219 kset_unregister(dlm_kset);
241} 220}
242 221
243static int dlm_scand(void *data) 222static int dlm_scand(void *data)
@@ -549,13 +528,12 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
549 goto out_delist; 528 goto out_delist;
550 } 529 }
551 530
552 error = kobject_setup(ls); 531 ls->ls_kobj.kset = dlm_kset;
553 if (error) 532 error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
554 goto out_stop; 533 "%s", ls->ls_name);
555
556 error = kobject_register(&ls->ls_kobj);
557 if (error) 534 if (error)
558 goto out_stop; 535 goto out_stop;
536 kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
559 537
560 /* let kobject handle freeing of ls if there's an error */ 538 /* let kobject handle freeing of ls if there's an error */
561 do_unreg = 1; 539 do_unreg = 1;
@@ -601,7 +579,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
601 kfree(ls->ls_rsbtbl); 579 kfree(ls->ls_rsbtbl);
602 out_lsfree: 580 out_lsfree:
603 if (do_unreg) 581 if (do_unreg)
604 kobject_unregister(&ls->ls_kobj); 582 kobject_put(&ls->ls_kobj);
605 else 583 else
606 kfree(ls); 584 kfree(ls);
607 out: 585 out:
@@ -750,7 +728,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
750 dlm_clear_members(ls); 728 dlm_clear_members(ls);
751 dlm_clear_members_gone(ls); 729 dlm_clear_members_gone(ls);
752 kfree(ls->ls_node_array); 730 kfree(ls->ls_node_array);
753 kobject_unregister(&ls->ls_kobj); 731 kobject_put(&ls->ls_kobj);
754 /* The ls structure will be freed when the kobject is done with */ 732 /* The ls structure will be freed when the kobject is done with */
755 733
756 mutex_lock(&ls_lock); 734 mutex_lock(&ls_lock);
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index e5580bcb923a..0249aa4ae181 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,127 +734,40 @@ static int ecryptfs_init_kmem_caches(void)
734 return 0; 734 return 0;
735} 735}
736 736
737struct ecryptfs_obj { 737static struct kobject *ecryptfs_kobj;
738 char *name;
739 struct list_head slot_list;
740 struct kobject kobj;
741};
742
743struct ecryptfs_attribute {
744 struct attribute attr;
745 ssize_t(*show) (struct ecryptfs_obj *, char *);
746 ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t);
747};
748 738
749static ssize_t 739static ssize_t version_show(struct kobject *kobj,
750ecryptfs_attr_store(struct kobject *kobj, 740 struct kobj_attribute *attr, char *buff)
751 struct attribute *attr, const char *buf, size_t len)
752{ 741{
753 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, 742 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
754 kobj);
755 struct ecryptfs_attribute *attribute =
756 container_of(attr, struct ecryptfs_attribute, attr);
757
758 return (attribute->store ? attribute->store(obj, buf, len) : 0);
759} 743}
760 744
761static ssize_t 745static struct kobj_attribute version_attr = __ATTR_RO(version);
762ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
763{
764 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
765 kobj);
766 struct ecryptfs_attribute *attribute =
767 container_of(attr, struct ecryptfs_attribute, attr);
768
769 return (attribute->show ? attribute->show(obj, buf) : 0);
770}
771 746
772static struct sysfs_ops ecryptfs_sysfs_ops = { 747static struct attribute *attributes[] = {
773 .show = ecryptfs_attr_show, 748 &version_attr.attr,
774 .store = ecryptfs_attr_store 749 NULL,
775}; 750};
776 751
777static struct kobj_type ecryptfs_ktype = { 752static struct attribute_group attr_group = {
778 .sysfs_ops = &ecryptfs_sysfs_ops 753 .attrs = attributes,
779}; 754};
780 755
781static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
782
783static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
784{
785 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
786}
787
788static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
789
790static struct ecryptfs_version_str_map_elem {
791 u32 flag;
792 char *str;
793} ecryptfs_version_str_map[] = {
794 {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
795 {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
796 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
797 {ECRYPTFS_VERSIONING_POLICY, "policy"},
798 {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"},
799 {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
800};
801
802static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
803{
804 int i;
805 int remaining = PAGE_SIZE;
806 int total_written = 0;
807
808 buff[0] = '\0';
809 for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
810 int entry_size;
811
812 if (!(ECRYPTFS_VERSIONING_MASK
813 & ecryptfs_version_str_map[i].flag))
814 continue;
815 entry_size = strlen(ecryptfs_version_str_map[i].str);
816 if ((entry_size + 2) > remaining)
817 goto out;
818 memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
819 buff[entry_size++] = '\n';
820 buff[entry_size] = '\0';
821 buff += entry_size;
822 total_written += entry_size;
823 remaining -= entry_size;
824 }
825out:
826 return total_written;
827}
828
829static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
830
831static int do_sysfs_registration(void) 756static int do_sysfs_registration(void)
832{ 757{
833 int rc; 758 int rc;
834 759
835 rc = subsystem_register(&ecryptfs_subsys); 760 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
836 if (rc) { 761 if (!ecryptfs_kobj) {
837 printk(KERN_ERR 762 printk(KERN_ERR "Unable to create ecryptfs kset\n");
838 "Unable to register ecryptfs sysfs subsystem\n"); 763 rc = -ENOMEM;
839 goto out;
840 }
841 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
842 &sysfs_attr_version.attr);
843 if (rc) {
844 printk(KERN_ERR
845 "Unable to create ecryptfs version attribute\n");
846 subsystem_unregister(&ecryptfs_subsys);
847 goto out; 764 goto out;
848 } 765 }
849 rc = sysfs_create_file(&ecryptfs_subsys.kobj, 766 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
850 &sysfs_attr_version_str.attr);
851 if (rc) { 767 if (rc) {
852 printk(KERN_ERR 768 printk(KERN_ERR
853 "Unable to create ecryptfs version_str attribute\n"); 769 "Unable to create ecryptfs version attributes\n");
854 sysfs_remove_file(&ecryptfs_subsys.kobj, 770 kobject_put(ecryptfs_kobj);
855 &sysfs_attr_version.attr);
856 subsystem_unregister(&ecryptfs_subsys);
857 goto out;
858 } 771 }
859out: 772out:
860 return rc; 773 return rc;
@@ -862,11 +775,8 @@ out:
862 775
863static void do_sysfs_unregistration(void) 776static void do_sysfs_unregistration(void)
864{ 777{
865 sysfs_remove_file(&ecryptfs_subsys.kobj, 778 sysfs_remove_group(ecryptfs_kobj, &attr_group);
866 &sysfs_attr_version.attr); 779 kobject_put(ecryptfs_kobj);
867 sysfs_remove_file(&ecryptfs_subsys.kobj,
868 &sysfs_attr_version_str.attr);
869 subsystem_unregister(&ecryptfs_subsys);
870} 780}
871 781
872static int __init ecryptfs_init(void) 782static int __init ecryptfs_init(void)
@@ -894,7 +804,6 @@ static int __init ecryptfs_init(void)
894 printk(KERN_ERR "Failed to register filesystem\n"); 804 printk(KERN_ERR "Failed to register filesystem\n");
895 goto out_free_kmem_caches; 805 goto out_free_kmem_caches;
896 } 806 }
897 kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
898 rc = do_sysfs_registration(); 807 rc = do_sysfs_registration();
899 if (rc) { 808 if (rc) {
900 printk(KERN_ERR "sysfs registration failed\n"); 809 printk(KERN_ERR "sysfs registration failed\n");
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 84f9f7dfdf5b..e5e80d1a4687 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -744,9 +744,6 @@ static inline void unregister_fuseblk(void)
744} 744}
745#endif 745#endif
746 746
747static decl_subsys(fuse, NULL, NULL);
748static decl_subsys(connections, NULL, NULL);
749
750static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo) 747static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo)
751{ 748{
752 struct inode * inode = foo; 749 struct inode * inode = foo;
@@ -791,32 +788,37 @@ static void fuse_fs_cleanup(void)
791 kmem_cache_destroy(fuse_inode_cachep); 788 kmem_cache_destroy(fuse_inode_cachep);
792} 789}
793 790
791static struct kobject *fuse_kobj;
792static struct kobject *connections_kobj;
793
794static int fuse_sysfs_init(void) 794static int fuse_sysfs_init(void)
795{ 795{
796 int err; 796 int err;
797 797
798 kobj_set_kset_s(&fuse_subsys, fs_subsys); 798 fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
799 err = subsystem_register(&fuse_subsys); 799 if (!fuse_kobj) {
800 if (err) 800 err = -ENOMEM;
801 goto out_err; 801 goto out_err;
802 }
802 803
803 kobj_set_kset_s(&connections_subsys, fuse_subsys); 804 connections_kobj = kobject_create_and_add("connections", fuse_kobj);
804 err = subsystem_register(&connections_subsys); 805 if (!connections_kobj) {
805 if (err) 806 err = -ENOMEM;
806 goto out_fuse_unregister; 807 goto out_fuse_unregister;
808 }
807 809
808 return 0; 810 return 0;
809 811
810 out_fuse_unregister: 812 out_fuse_unregister:
811 subsystem_unregister(&fuse_subsys); 813 kobject_put(fuse_kobj);
812 out_err: 814 out_err:
813 return err; 815 return err;
814} 816}
815 817
816static void fuse_sysfs_cleanup(void) 818static void fuse_sysfs_cleanup(void)
817{ 819{
818 subsystem_unregister(&connections_subsys); 820 kobject_put(connections_kobj);
819 subsystem_unregister(&fuse_subsys); 821 kobject_put(fuse_kobj);
820} 822}
821 823
822static int __init fuse_init(void) 824static int __init fuse_init(void)
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index 04ad0caebedb..8fff11058cee 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -2,7 +2,7 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o lm.o log.o lops.o locking.o main.o meta_io.o \ 3 glops.o inode.o lm.o log.o lops.o locking.o main.o meta_io.o \
4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ 4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \
5 ops_fstype.o ops_inode.o ops_super.o ops_vm.o quota.o \ 5 ops_fstype.o ops_inode.o ops_super.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/ 8obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 93fa427bb5f5..e4effc47abfc 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -59,7 +59,6 @@ struct strip_mine {
59static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, 59static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
60 u64 block, struct page *page) 60 u64 block, struct page *page)
61{ 61{
62 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
63 struct inode *inode = &ip->i_inode; 62 struct inode *inode = &ip->i_inode;
64 struct buffer_head *bh; 63 struct buffer_head *bh;
65 int release = 0; 64 int release = 0;
@@ -95,7 +94,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
95 set_buffer_uptodate(bh); 94 set_buffer_uptodate(bh);
96 if (!gfs2_is_jdata(ip)) 95 if (!gfs2_is_jdata(ip))
97 mark_buffer_dirty(bh); 96 mark_buffer_dirty(bh);
98 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 97 if (!gfs2_is_writeback(ip))
99 gfs2_trans_add_bh(ip->i_gl, bh, 0); 98 gfs2_trans_add_bh(ip->i_gl, bh, 0);
100 99
101 if (release) { 100 if (release) {
@@ -453,8 +452,8 @@ static inline void bmap_unlock(struct inode *inode, int create)
453 * Returns: errno 452 * Returns: errno
454 */ 453 */
455 454
456int gfs2_block_map(struct inode *inode, u64 lblock, int create, 455int gfs2_block_map(struct inode *inode, sector_t lblock,
457 struct buffer_head *bh_map) 456 struct buffer_head *bh_map, int create)
458{ 457{
459 struct gfs2_inode *ip = GFS2_I(inode); 458 struct gfs2_inode *ip = GFS2_I(inode);
460 struct gfs2_sbd *sdp = GFS2_SB(inode); 459 struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -470,6 +469,7 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
470 unsigned int maxlen = bh_map->b_size >> inode->i_blkbits; 469 unsigned int maxlen = bh_map->b_size >> inode->i_blkbits;
471 struct metapath mp; 470 struct metapath mp;
472 u64 size; 471 u64 size;
472 struct buffer_head *dibh = NULL;
473 473
474 BUG_ON(maxlen == 0); 474 BUG_ON(maxlen == 0);
475 475
@@ -500,6 +500,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
500 error = gfs2_meta_inode_buffer(ip, &bh); 500 error = gfs2_meta_inode_buffer(ip, &bh);
501 if (error) 501 if (error)
502 goto out_fail; 502 goto out_fail;
503 dibh = bh;
504 get_bh(dibh);
503 505
504 for (x = 0; x < end_of_metadata; x++) { 506 for (x = 0; x < end_of_metadata; x++) {
505 lookup_block(ip, bh, x, &mp, create, &new, &dblock); 507 lookup_block(ip, bh, x, &mp, create, &new, &dblock);
@@ -518,13 +520,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
518 if (boundary) 520 if (boundary)
519 set_buffer_boundary(bh_map); 521 set_buffer_boundary(bh_map);
520 if (new) { 522 if (new) {
521 struct buffer_head *dibh; 523 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
522 error = gfs2_meta_inode_buffer(ip, &dibh); 524 gfs2_dinode_out(ip, dibh->b_data);
523 if (!error) {
524 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
525 gfs2_dinode_out(ip, dibh->b_data);
526 brelse(dibh);
527 }
528 set_buffer_new(bh_map); 525 set_buffer_new(bh_map);
529 goto out_brelse; 526 goto out_brelse;
530 } 527 }
@@ -545,6 +542,8 @@ out_brelse:
545out_ok: 542out_ok:
546 error = 0; 543 error = 0;
547out_fail: 544out_fail:
545 if (dibh)
546 brelse(dibh);
548 bmap_unlock(inode, create); 547 bmap_unlock(inode, create);
549 return error; 548 return error;
550} 549}
@@ -560,7 +559,7 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi
560 BUG_ON(!new); 559 BUG_ON(!new);
561 560
562 bh.b_size = 1 << (inode->i_blkbits + 5); 561 bh.b_size = 1 << (inode->i_blkbits + 5);
563 ret = gfs2_block_map(inode, lblock, create, &bh); 562 ret = gfs2_block_map(inode, lblock, &bh, create);
564 *extlen = bh.b_size >> inode->i_blkbits; 563 *extlen = bh.b_size >> inode->i_blkbits;
565 *dblock = bh.b_blocknr; 564 *dblock = bh.b_blocknr;
566 if (buffer_new(&bh)) 565 if (buffer_new(&bh))
@@ -684,7 +683,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
684 if (metadata) 683 if (metadata)
685 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; 684 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs;
686 685
687 error = gfs2_rindex_hold(sdp, &ip->i_alloc.al_ri_gh); 686 error = gfs2_rindex_hold(sdp, &ip->i_alloc->al_ri_gh);
688 if (error) 687 if (error)
689 return error; 688 return error;
690 689
@@ -786,7 +785,7 @@ out_rg_gunlock:
786out_rlist: 785out_rlist:
787 gfs2_rlist_free(&rlist); 786 gfs2_rlist_free(&rlist);
788out: 787out:
789 gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh); 788 gfs2_glock_dq_uninit(&ip->i_alloc->al_ri_gh);
790 return error; 789 return error;
791} 790}
792 791
@@ -879,7 +878,6 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
879{ 878{
880 struct inode *inode = mapping->host; 879 struct inode *inode = mapping->host;
881 struct gfs2_inode *ip = GFS2_I(inode); 880 struct gfs2_inode *ip = GFS2_I(inode);
882 struct gfs2_sbd *sdp = GFS2_SB(inode);
883 loff_t from = inode->i_size; 881 loff_t from = inode->i_size;
884 unsigned long index = from >> PAGE_CACHE_SHIFT; 882 unsigned long index = from >> PAGE_CACHE_SHIFT;
885 unsigned offset = from & (PAGE_CACHE_SIZE-1); 883 unsigned offset = from & (PAGE_CACHE_SIZE-1);
@@ -911,7 +909,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
911 err = 0; 909 err = 0;
912 910
913 if (!buffer_mapped(bh)) { 911 if (!buffer_mapped(bh)) {
914 gfs2_get_block(inode, iblock, bh, 0); 912 gfs2_block_map(inode, iblock, bh, 0);
915 /* unmapped? It's a hole - nothing to do */ 913 /* unmapped? It's a hole - nothing to do */
916 if (!buffer_mapped(bh)) 914 if (!buffer_mapped(bh))
917 goto unlock; 915 goto unlock;
@@ -931,7 +929,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
931 err = 0; 929 err = 0;
932 } 930 }
933 931
934 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 932 if (!gfs2_is_writeback(ip))
935 gfs2_trans_add_bh(ip->i_gl, bh, 0); 933 gfs2_trans_add_bh(ip->i_gl, bh, 0);
936 934
937 zero_user_page(page, offset, length, KM_USER0); 935 zero_user_page(page, offset, length, KM_USER0);
@@ -1224,8 +1222,13 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1224 do_div(lblock_stop, bsize); 1222 do_div(lblock_stop, bsize);
1225 } else { 1223 } else {
1226 unsigned int shift = sdp->sd_sb.sb_bsize_shift; 1224 unsigned int shift = sdp->sd_sb.sb_bsize_shift;
1225 u64 end_of_file = (ip->i_di.di_size + sdp->sd_sb.sb_bsize - 1) >> shift;
1227 lblock = offset >> shift; 1226 lblock = offset >> shift;
1228 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; 1227 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
1228 if (lblock_stop > end_of_file) {
1229 *alloc_required = 1;
1230 return 0;
1231 }
1229 } 1232 }
1230 1233
1231 for (; lblock < lblock_stop; lblock += extlen) { 1234 for (; lblock < lblock_stop; lblock += extlen) {
diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index ac2fd04370dc..4e6cde2943bd 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -15,7 +15,7 @@ struct gfs2_inode;
15struct page; 15struct page;
16 16
17int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); 17int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page);
18int gfs2_block_map(struct inode *inode, u64 lblock, int create, struct buffer_head *bh); 18int gfs2_block_map(struct inode *inode, sector_t lblock, struct buffer_head *bh, int create);
19int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); 19int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen);
20 20
21int gfs2_truncatei(struct gfs2_inode *ip, u64 size); 21int gfs2_truncatei(struct gfs2_inode *ip, u64 size);
diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c
index 3731ab0771d5..e51991947d2c 100644
--- a/fs/gfs2/daemon.c
+++ b/fs/gfs2/daemon.c
@@ -83,56 +83,6 @@ int gfs2_recoverd(void *data)
83} 83}
84 84
85/** 85/**
86 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
87 * @sdp: Pointer to GFS2 superblock
88 *
89 * Also, periodically check to make sure that we're using the most recent
90 * journal index.
91 */
92
93int gfs2_logd(void *data)
94{
95 struct gfs2_sbd *sdp = data;
96 struct gfs2_holder ji_gh;
97 unsigned long t;
98 int need_flush;
99
100 while (!kthread_should_stop()) {
101 /* Advance the log tail */
102
103 t = sdp->sd_log_flush_time +
104 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
105
106 gfs2_ail1_empty(sdp, DIO_ALL);
107 gfs2_log_lock(sdp);
108 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
109 gfs2_log_unlock(sdp);
110 if (need_flush || time_after_eq(jiffies, t)) {
111 gfs2_log_flush(sdp, NULL);
112 sdp->sd_log_flush_time = jiffies;
113 }
114
115 /* Check for latest journal index */
116
117 t = sdp->sd_jindex_refresh_time +
118 gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ;
119
120 if (time_after_eq(jiffies, t)) {
121 if (!gfs2_jindex_hold(sdp, &ji_gh))
122 gfs2_glock_dq_uninit(&ji_gh);
123 sdp->sd_jindex_refresh_time = jiffies;
124 }
125
126 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
127 if (freezing(current))
128 refrigerator();
129 schedule_timeout_interruptible(t);
130 }
131
132 return 0;
133}
134
135/**
136 * gfs2_quotad - Write cached quota changes into the quota file 86 * gfs2_quotad - Write cached quota changes into the quota file
137 * @sdp: Pointer to GFS2 superblock 87 * @sdp: Pointer to GFS2 superblock
138 * 88 *
diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h
index 0de9b3557955..4be084fb6a62 100644
--- a/fs/gfs2/daemon.h
+++ b/fs/gfs2/daemon.h
@@ -12,7 +12,6 @@
12 12
13int gfs2_glockd(void *data); 13int gfs2_glockd(void *data);
14int gfs2_recoverd(void *data); 14int gfs2_recoverd(void *data);
15int gfs2_logd(void *data);
16int gfs2_quotad(void *data); 15int gfs2_quotad(void *data);
17 16
18#endif /* __DAEMON_DOT_H__ */ 17#endif /* __DAEMON_DOT_H__ */
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 9949bb746a52..57e2ed932adc 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1876,7 +1876,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
1876 if (error) 1876 if (error)
1877 goto out; 1877 goto out;
1878 1878
1879 error = gfs2_rindex_hold(sdp, &dip->i_alloc.al_ri_gh); 1879 error = gfs2_rindex_hold(sdp, &dip->i_alloc->al_ri_gh);
1880 if (error) 1880 if (error)
1881 goto out_qs; 1881 goto out_qs;
1882 1882
@@ -1949,7 +1949,7 @@ out_rg_gunlock:
1949 gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); 1949 gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
1950out_rlist: 1950out_rlist:
1951 gfs2_rlist_free(&rlist); 1951 gfs2_rlist_free(&rlist);
1952 gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh); 1952 gfs2_glock_dq_uninit(&dip->i_alloc->al_ri_gh);
1953out_qs: 1953out_qs:
1954 gfs2_quota_unhold(dip); 1954 gfs2_quota_unhold(dip);
1955out: 1955out:
diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c
index aa8dbf303f6d..f114ba2b3557 100644
--- a/fs/gfs2/eaops.c
+++ b/fs/gfs2/eaops.c
@@ -56,46 +56,6 @@ unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name)
56 return type; 56 return type;
57} 57}
58 58
59static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
60{
61 struct inode *inode = &ip->i_inode;
62 int error = permission(inode, MAY_READ, NULL);
63 if (error)
64 return error;
65
66 return gfs2_ea_get_i(ip, er);
67}
68
69static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
70{
71 struct inode *inode = &ip->i_inode;
72
73 if (S_ISREG(inode->i_mode) ||
74 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
75 int error = permission(inode, MAY_WRITE, NULL);
76 if (error)
77 return error;
78 } else
79 return -EPERM;
80
81 return gfs2_ea_set_i(ip, er);
82}
83
84static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
85{
86 struct inode *inode = &ip->i_inode;
87
88 if (S_ISREG(inode->i_mode) ||
89 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
90 int error = permission(inode, MAY_WRITE, NULL);
91 if (error)
92 return error;
93 } else
94 return -EPERM;
95
96 return gfs2_ea_remove_i(ip, er);
97}
98
99static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) 59static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
100{ 60{
101 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) && 61 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
@@ -108,8 +68,6 @@ static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
108 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) 68 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
109 return -EOPNOTSUPP; 69 return -EOPNOTSUPP;
110 70
111
112
113 return gfs2_ea_get_i(ip, er); 71 return gfs2_ea_get_i(ip, er);
114} 72}
115 73
@@ -170,40 +128,10 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
170 return gfs2_ea_remove_i(ip, er); 128 return gfs2_ea_remove_i(ip, er);
171} 129}
172 130
173static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
174{
175 struct inode *inode = &ip->i_inode;
176 int error = permission(inode, MAY_READ, NULL);
177 if (error)
178 return error;
179
180 return gfs2_ea_get_i(ip, er);
181}
182
183static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
184{
185 struct inode *inode = &ip->i_inode;
186 int error = permission(inode, MAY_WRITE, NULL);
187 if (error)
188 return error;
189
190 return gfs2_ea_set_i(ip, er);
191}
192
193static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
194{
195 struct inode *inode = &ip->i_inode;
196 int error = permission(inode, MAY_WRITE, NULL);
197 if (error)
198 return error;
199
200 return gfs2_ea_remove_i(ip, er);
201}
202
203static const struct gfs2_eattr_operations gfs2_user_eaops = { 131static const struct gfs2_eattr_operations gfs2_user_eaops = {
204 .eo_get = user_eo_get, 132 .eo_get = gfs2_ea_get_i,
205 .eo_set = user_eo_set, 133 .eo_set = gfs2_ea_set_i,
206 .eo_remove = user_eo_remove, 134 .eo_remove = gfs2_ea_remove_i,
207 .eo_name = "user", 135 .eo_name = "user",
208}; 136};
209 137
@@ -215,9 +143,9 @@ const struct gfs2_eattr_operations gfs2_system_eaops = {
215}; 143};
216 144
217static const struct gfs2_eattr_operations gfs2_security_eaops = { 145static const struct gfs2_eattr_operations gfs2_security_eaops = {
218 .eo_get = security_eo_get, 146 .eo_get = gfs2_ea_get_i,
219 .eo_set = security_eo_set, 147 .eo_set = gfs2_ea_set_i,
220 .eo_remove = security_eo_remove, 148 .eo_remove = gfs2_ea_remove_i,
221 .eo_name = "security", 149 .eo_name = "security",
222}; 150};
223 151
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 2a7435b5c4dc..bee99704ea10 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -1418,7 +1418,7 @@ out:
1418static int ea_dealloc_block(struct gfs2_inode *ip) 1418static int ea_dealloc_block(struct gfs2_inode *ip)
1419{ 1419{
1420 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1420 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1421 struct gfs2_alloc *al = &ip->i_alloc; 1421 struct gfs2_alloc *al = ip->i_alloc;
1422 struct gfs2_rgrpd *rgd; 1422 struct gfs2_rgrpd *rgd;
1423 struct buffer_head *dibh; 1423 struct buffer_head *dibh;
1424 int error; 1424 int error;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index a37efe4aae6f..80e09c50590a 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -217,7 +217,6 @@ int gfs2_glock_put(struct gfs2_glock *gl)
217 if (atomic_dec_and_test(&gl->gl_ref)) { 217 if (atomic_dec_and_test(&gl->gl_ref)) {
218 hlist_del(&gl->gl_list); 218 hlist_del(&gl->gl_list);
219 write_unlock(gl_lock_addr(gl->gl_hash)); 219 write_unlock(gl_lock_addr(gl->gl_hash));
220 BUG_ON(spin_is_locked(&gl->gl_spin));
221 gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED); 220 gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED);
222 gfs2_assert(sdp, list_empty(&gl->gl_reclaim)); 221 gfs2_assert(sdp, list_empty(&gl->gl_reclaim));
223 gfs2_assert(sdp, list_empty(&gl->gl_holders)); 222 gfs2_assert(sdp, list_empty(&gl->gl_holders));
@@ -346,7 +345,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
346 gl->gl_object = NULL; 345 gl->gl_object = NULL;
347 gl->gl_sbd = sdp; 346 gl->gl_sbd = sdp;
348 gl->gl_aspace = NULL; 347 gl->gl_aspace = NULL;
349 lops_init_le(&gl->gl_le, &gfs2_glock_lops);
350 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); 348 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
351 349
352 /* If this glock protects actual on-disk data or metadata blocks, 350 /* If this glock protects actual on-disk data or metadata blocks,
@@ -461,7 +459,6 @@ static void wait_on_holder(struct gfs2_holder *gh)
461 459
462static void gfs2_demote_wake(struct gfs2_glock *gl) 460static void gfs2_demote_wake(struct gfs2_glock *gl)
463{ 461{
464 BUG_ON(!spin_is_locked(&gl->gl_spin));
465 gl->gl_demote_state = LM_ST_EXCLUSIVE; 462 gl->gl_demote_state = LM_ST_EXCLUSIVE;
466 clear_bit(GLF_DEMOTE, &gl->gl_flags); 463 clear_bit(GLF_DEMOTE, &gl->gl_flags);
467 smp_mb__after_clear_bit(); 464 smp_mb__after_clear_bit();
@@ -507,21 +504,12 @@ static int rq_mutex(struct gfs2_holder *gh)
507static int rq_promote(struct gfs2_holder *gh) 504static int rq_promote(struct gfs2_holder *gh)
508{ 505{
509 struct gfs2_glock *gl = gh->gh_gl; 506 struct gfs2_glock *gl = gh->gh_gl;
510 struct gfs2_sbd *sdp = gl->gl_sbd;
511 507
512 if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { 508 if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {
513 if (list_empty(&gl->gl_holders)) { 509 if (list_empty(&gl->gl_holders)) {
514 gl->gl_req_gh = gh; 510 gl->gl_req_gh = gh;
515 set_bit(GLF_LOCK, &gl->gl_flags); 511 set_bit(GLF_LOCK, &gl->gl_flags);
516 spin_unlock(&gl->gl_spin); 512 spin_unlock(&gl->gl_spin);
517
518 if (atomic_read(&sdp->sd_reclaim_count) >
519 gfs2_tune_get(sdp, gt_reclaim_limit) &&
520 !(gh->gh_flags & LM_FLAG_PRIORITY)) {
521 gfs2_reclaim_glock(sdp);
522 gfs2_reclaim_glock(sdp);
523 }
524
525 gfs2_glock_xmote_th(gh->gh_gl, gh); 513 gfs2_glock_xmote_th(gh->gh_gl, gh);
526 spin_lock(&gl->gl_spin); 514 spin_lock(&gl->gl_spin);
527 } 515 }
@@ -567,7 +555,10 @@ static int rq_demote(struct gfs2_glock *gl)
567 gfs2_demote_wake(gl); 555 gfs2_demote_wake(gl);
568 return 0; 556 return 0;
569 } 557 }
558
570 set_bit(GLF_LOCK, &gl->gl_flags); 559 set_bit(GLF_LOCK, &gl->gl_flags);
560 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
561
571 if (gl->gl_demote_state == LM_ST_UNLOCKED || 562 if (gl->gl_demote_state == LM_ST_UNLOCKED ||
572 gl->gl_state != LM_ST_EXCLUSIVE) { 563 gl->gl_state != LM_ST_EXCLUSIVE) {
573 spin_unlock(&gl->gl_spin); 564 spin_unlock(&gl->gl_spin);
@@ -576,7 +567,9 @@ static int rq_demote(struct gfs2_glock *gl)
576 spin_unlock(&gl->gl_spin); 567 spin_unlock(&gl->gl_spin);
577 gfs2_glock_xmote_th(gl, NULL); 568 gfs2_glock_xmote_th(gl, NULL);
578 } 569 }
570
579 spin_lock(&gl->gl_spin); 571 spin_lock(&gl->gl_spin);
572 clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
580 573
581 return 0; 574 return 0;
582} 575}
@@ -598,23 +591,18 @@ static void run_queue(struct gfs2_glock *gl)
598 if (!list_empty(&gl->gl_waiters1)) { 591 if (!list_empty(&gl->gl_waiters1)) {
599 gh = list_entry(gl->gl_waiters1.next, 592 gh = list_entry(gl->gl_waiters1.next,
600 struct gfs2_holder, gh_list); 593 struct gfs2_holder, gh_list);
601 594 blocked = rq_mutex(gh);
602 if (test_bit(HIF_MUTEX, &gh->gh_iflags))
603 blocked = rq_mutex(gh);
604 else
605 gfs2_assert_warn(gl->gl_sbd, 0);
606
607 } else if (test_bit(GLF_DEMOTE, &gl->gl_flags)) { 595 } else if (test_bit(GLF_DEMOTE, &gl->gl_flags)) {
608 blocked = rq_demote(gl); 596 blocked = rq_demote(gl);
597 if (gl->gl_waiters2 && !blocked) {
598 set_bit(GLF_DEMOTE, &gl->gl_flags);
599 gl->gl_demote_state = LM_ST_UNLOCKED;
600 }
601 gl->gl_waiters2 = 0;
609 } else if (!list_empty(&gl->gl_waiters3)) { 602 } else if (!list_empty(&gl->gl_waiters3)) {
610 gh = list_entry(gl->gl_waiters3.next, 603 gh = list_entry(gl->gl_waiters3.next,
611 struct gfs2_holder, gh_list); 604 struct gfs2_holder, gh_list);
612 605 blocked = rq_promote(gh);
613 if (test_bit(HIF_PROMOTE, &gh->gh_iflags))
614 blocked = rq_promote(gh);
615 else
616 gfs2_assert_warn(gl->gl_sbd, 0);
617
618 } else 606 } else
619 break; 607 break;
620 608
@@ -632,27 +620,21 @@ static void run_queue(struct gfs2_glock *gl)
632 620
633static void gfs2_glmutex_lock(struct gfs2_glock *gl) 621static void gfs2_glmutex_lock(struct gfs2_glock *gl)
634{ 622{
635 struct gfs2_holder gh;
636
637 gfs2_holder_init(gl, 0, 0, &gh);
638 set_bit(HIF_MUTEX, &gh.gh_iflags);
639 if (test_and_set_bit(HIF_WAIT, &gh.gh_iflags))
640 BUG();
641
642 spin_lock(&gl->gl_spin); 623 spin_lock(&gl->gl_spin);
643 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { 624 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
625 struct gfs2_holder gh;
626
627 gfs2_holder_init(gl, 0, 0, &gh);
628 set_bit(HIF_WAIT, &gh.gh_iflags);
644 list_add_tail(&gh.gh_list, &gl->gl_waiters1); 629 list_add_tail(&gh.gh_list, &gl->gl_waiters1);
630 spin_unlock(&gl->gl_spin);
631 wait_on_holder(&gh);
632 gfs2_holder_uninit(&gh);
645 } else { 633 } else {
646 gl->gl_owner_pid = current->pid; 634 gl->gl_owner_pid = current->pid;
647 gl->gl_ip = (unsigned long)__builtin_return_address(0); 635 gl->gl_ip = (unsigned long)__builtin_return_address(0);
648 clear_bit(HIF_WAIT, &gh.gh_iflags); 636 spin_unlock(&gl->gl_spin);
649 smp_mb();
650 wake_up_bit(&gh.gh_iflags, HIF_WAIT);
651 } 637 }
652 spin_unlock(&gl->gl_spin);
653
654 wait_on_holder(&gh);
655 gfs2_holder_uninit(&gh);
656} 638}
657 639
658/** 640/**
@@ -691,7 +673,6 @@ static void gfs2_glmutex_unlock(struct gfs2_glock *gl)
691 gl->gl_owner_pid = 0; 673 gl->gl_owner_pid = 0;
692 gl->gl_ip = 0; 674 gl->gl_ip = 0;
693 run_queue(gl); 675 run_queue(gl);
694 BUG_ON(!spin_is_locked(&gl->gl_spin));
695 spin_unlock(&gl->gl_spin); 676 spin_unlock(&gl->gl_spin);
696} 677}
697 678
@@ -722,7 +703,10 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
722 } 703 }
723 } else if (gl->gl_demote_state != LM_ST_UNLOCKED && 704 } else if (gl->gl_demote_state != LM_ST_UNLOCKED &&
724 gl->gl_demote_state != state) { 705 gl->gl_demote_state != state) {
725 gl->gl_demote_state = LM_ST_UNLOCKED; 706 if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags))
707 gl->gl_waiters2 = 1;
708 else
709 gl->gl_demote_state = LM_ST_UNLOCKED;
726 } 710 }
727 spin_unlock(&gl->gl_spin); 711 spin_unlock(&gl->gl_spin);
728} 712}
@@ -943,8 +927,8 @@ static void gfs2_glock_drop_th(struct gfs2_glock *gl)
943 const struct gfs2_glock_operations *glops = gl->gl_ops; 927 const struct gfs2_glock_operations *glops = gl->gl_ops;
944 unsigned int ret; 928 unsigned int ret;
945 929
946 if (glops->go_drop_th) 930 if (glops->go_xmote_th)
947 glops->go_drop_th(gl); 931 glops->go_xmote_th(gl);
948 932
949 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); 933 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
950 gfs2_assert_warn(sdp, list_empty(&gl->gl_holders)); 934 gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
@@ -1156,8 +1140,6 @@ restart:
1156 return -EIO; 1140 return -EIO;
1157 } 1141 }
1158 1142
1159 set_bit(HIF_PROMOTE, &gh->gh_iflags);
1160
1161 spin_lock(&gl->gl_spin); 1143 spin_lock(&gl->gl_spin);
1162 add_to_queue(gh); 1144 add_to_queue(gh);
1163 run_queue(gl); 1145 run_queue(gl);
@@ -1248,12 +1230,11 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1248 list_del_init(&gh->gh_list); 1230 list_del_init(&gh->gh_list);
1249 1231
1250 if (list_empty(&gl->gl_holders)) { 1232 if (list_empty(&gl->gl_holders)) {
1251 spin_unlock(&gl->gl_spin); 1233 if (glops->go_unlock) {
1252 1234 spin_unlock(&gl->gl_spin);
1253 if (glops->go_unlock)
1254 glops->go_unlock(gh); 1235 glops->go_unlock(gh);
1255 1236 spin_lock(&gl->gl_spin);
1256 spin_lock(&gl->gl_spin); 1237 }
1257 gl->gl_stamp = jiffies; 1238 gl->gl_stamp = jiffies;
1258 } 1239 }
1259 1240
@@ -1910,8 +1891,6 @@ static int dump_glock(struct glock_iter *gi, struct gfs2_glock *gl)
1910 print_dbg(gi, " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); 1891 print_dbg(gi, " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no");
1911 print_dbg(gi, " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); 1892 print_dbg(gi, " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count));
1912 print_dbg(gi, " object = %s\n", (gl->gl_object) ? "yes" : "no"); 1893 print_dbg(gi, " object = %s\n", (gl->gl_object) ? "yes" : "no");
1913 print_dbg(gi, " le = %s\n",
1914 (list_empty(&gl->gl_le.le_list)) ? "no" : "yes");
1915 print_dbg(gi, " reclaim = %s\n", 1894 print_dbg(gi, " reclaim = %s\n",
1916 (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); 1895 (list_empty(&gl->gl_reclaim)) ? "no" : "yes");
1917 if (gl->gl_aspace) 1896 if (gl->gl_aspace)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 4670dcb2a877..c663b7a0f410 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -56,7 +56,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
56 bd = list_entry(head->next, struct gfs2_bufdata, 56 bd = list_entry(head->next, struct gfs2_bufdata,
57 bd_ail_gl_list); 57 bd_ail_gl_list);
58 bh = bd->bd_bh; 58 bh = bd->bd_bh;
59 gfs2_remove_from_ail(NULL, bd); 59 gfs2_remove_from_ail(bd);
60 bd->bd_bh = NULL; 60 bd->bd_bh = NULL;
61 bh->b_private = NULL; 61 bh->b_private = NULL;
62 bd->bd_blkno = bh->b_blocknr; 62 bd->bd_blkno = bh->b_blocknr;
@@ -86,15 +86,10 @@ static void gfs2_pte_inval(struct gfs2_glock *gl)
86 if (!ip || !S_ISREG(inode->i_mode)) 86 if (!ip || !S_ISREG(inode->i_mode))
87 return; 87 return;
88 88
89 if (!test_bit(GIF_PAGED, &ip->i_flags))
90 return;
91
92 unmap_shared_mapping_range(inode->i_mapping, 0, 0); 89 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
93
94 if (test_bit(GIF_SW_PAGED, &ip->i_flags)) 90 if (test_bit(GIF_SW_PAGED, &ip->i_flags))
95 set_bit(GLF_DIRTY, &gl->gl_flags); 91 set_bit(GLF_DIRTY, &gl->gl_flags);
96 92
97 clear_bit(GIF_SW_PAGED, &ip->i_flags);
98} 93}
99 94
100/** 95/**
@@ -143,44 +138,34 @@ static void meta_go_inval(struct gfs2_glock *gl, int flags)
143static void inode_go_sync(struct gfs2_glock *gl) 138static void inode_go_sync(struct gfs2_glock *gl)
144{ 139{
145 struct gfs2_inode *ip = gl->gl_object; 140 struct gfs2_inode *ip = gl->gl_object;
141 struct address_space *metamapping = gl->gl_aspace->i_mapping;
142 int error;
143
144 if (gl->gl_state != LM_ST_UNLOCKED)
145 gfs2_pte_inval(gl);
146 if (gl->gl_state != LM_ST_EXCLUSIVE)
147 return;
146 148
147 if (ip && !S_ISREG(ip->i_inode.i_mode)) 149 if (ip && !S_ISREG(ip->i_inode.i_mode))
148 ip = NULL; 150 ip = NULL;
149 151
150 if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 152 if (test_bit(GLF_DIRTY, &gl->gl_flags)) {
151 if (ip && !gfs2_is_jdata(ip))
152 filemap_fdatawrite(ip->i_inode.i_mapping);
153 gfs2_log_flush(gl->gl_sbd, gl); 153 gfs2_log_flush(gl->gl_sbd, gl);
154 if (ip && gfs2_is_jdata(ip)) 154 filemap_fdatawrite(metamapping);
155 filemap_fdatawrite(ip->i_inode.i_mapping);
156 gfs2_meta_sync(gl);
157 if (ip) { 155 if (ip) {
158 struct address_space *mapping = ip->i_inode.i_mapping; 156 struct address_space *mapping = ip->i_inode.i_mapping;
159 int error = filemap_fdatawait(mapping); 157 filemap_fdatawrite(mapping);
158 error = filemap_fdatawait(mapping);
160 mapping_set_error(mapping, error); 159 mapping_set_error(mapping, error);
161 } 160 }
161 error = filemap_fdatawait(metamapping);
162 mapping_set_error(metamapping, error);
162 clear_bit(GLF_DIRTY, &gl->gl_flags); 163 clear_bit(GLF_DIRTY, &gl->gl_flags);
163 gfs2_ail_empty_gl(gl); 164 gfs2_ail_empty_gl(gl);
164 } 165 }
165} 166}
166 167
167/** 168/**
168 * inode_go_xmote_th - promote/demote a glock
169 * @gl: the glock
170 * @state: the requested state
171 * @flags:
172 *
173 */
174
175static void inode_go_xmote_th(struct gfs2_glock *gl)
176{
177 if (gl->gl_state != LM_ST_UNLOCKED)
178 gfs2_pte_inval(gl);
179 if (gl->gl_state == LM_ST_EXCLUSIVE)
180 inode_go_sync(gl);
181}
182
183/**
184 * inode_go_xmote_bh - After promoting/demoting a glock 169 * inode_go_xmote_bh - After promoting/demoting a glock
185 * @gl: the glock 170 * @gl: the glock
186 * 171 *
@@ -201,22 +186,6 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl)
201} 186}
202 187
203/** 188/**
204 * inode_go_drop_th - unlock a glock
205 * @gl: the glock
206 *
207 * Invoked from rq_demote().
208 * Another node needs the lock in EXCLUSIVE mode, or lock (unused for too long)
209 * is being purged from our node's glock cache; we're dropping lock.
210 */
211
212static void inode_go_drop_th(struct gfs2_glock *gl)
213{
214 gfs2_pte_inval(gl);
215 if (gl->gl_state == LM_ST_EXCLUSIVE)
216 inode_go_sync(gl);
217}
218
219/**
220 * inode_go_inval - prepare a inode glock to be released 189 * inode_go_inval - prepare a inode glock to be released
221 * @gl: the glock 190 * @gl: the glock
222 * @flags: 191 * @flags:
@@ -234,10 +203,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
234 set_bit(GIF_INVALID, &ip->i_flags); 203 set_bit(GIF_INVALID, &ip->i_flags);
235 } 204 }
236 205
237 if (ip && S_ISREG(ip->i_inode.i_mode)) { 206 if (ip && S_ISREG(ip->i_inode.i_mode))
238 truncate_inode_pages(ip->i_inode.i_mapping, 0); 207 truncate_inode_pages(ip->i_inode.i_mapping, 0);
239 clear_bit(GIF_PAGED, &ip->i_flags);
240 }
241} 208}
242 209
243/** 210/**
@@ -294,23 +261,6 @@ static int inode_go_lock(struct gfs2_holder *gh)
294} 261}
295 262
296/** 263/**
297 * inode_go_unlock - operation done before an inode lock is unlocked by a
298 * process
299 * @gl: the glock
300 * @flags:
301 *
302 */
303
304static void inode_go_unlock(struct gfs2_holder *gh)
305{
306 struct gfs2_glock *gl = gh->gh_gl;
307 struct gfs2_inode *ip = gl->gl_object;
308
309 if (ip)
310 gfs2_meta_cache_flush(ip);
311}
312
313/**
314 * rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock 264 * rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock
315 * @gl: the glock 265 * @gl: the glock
316 * 266 *
@@ -350,14 +300,14 @@ static void rgrp_go_unlock(struct gfs2_holder *gh)
350} 300}
351 301
352/** 302/**
353 * trans_go_xmote_th - promote/demote the transaction glock 303 * trans_go_sync - promote/demote the transaction glock
354 * @gl: the glock 304 * @gl: the glock
355 * @state: the requested state 305 * @state: the requested state
356 * @flags: 306 * @flags:
357 * 307 *
358 */ 308 */
359 309
360static void trans_go_xmote_th(struct gfs2_glock *gl) 310static void trans_go_sync(struct gfs2_glock *gl)
361{ 311{
362 struct gfs2_sbd *sdp = gl->gl_sbd; 312 struct gfs2_sbd *sdp = gl->gl_sbd;
363 313
@@ -384,7 +334,6 @@ static void trans_go_xmote_bh(struct gfs2_glock *gl)
384 334
385 if (gl->gl_state != LM_ST_UNLOCKED && 335 if (gl->gl_state != LM_ST_UNLOCKED &&
386 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 336 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
387 gfs2_meta_cache_flush(GFS2_I(sdp->sd_jdesc->jd_inode));
388 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 337 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
389 338
390 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 339 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -402,24 +351,6 @@ static void trans_go_xmote_bh(struct gfs2_glock *gl)
402} 351}
403 352
404/** 353/**
405 * trans_go_drop_th - unlock the transaction glock
406 * @gl: the glock
407 *
408 * We want to sync the device even with localcaching. Remember
409 * that localcaching journal replay only marks buffers dirty.
410 */
411
412static void trans_go_drop_th(struct gfs2_glock *gl)
413{
414 struct gfs2_sbd *sdp = gl->gl_sbd;
415
416 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
417 gfs2_meta_syncfs(sdp);
418 gfs2_log_shutdown(sdp);
419 }
420}
421
422/**
423 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock 354 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock
424 * @gl: the glock 355 * @gl: the glock
425 * 356 *
@@ -433,25 +364,21 @@ static int quota_go_demote_ok(struct gfs2_glock *gl)
433 364
434const struct gfs2_glock_operations gfs2_meta_glops = { 365const struct gfs2_glock_operations gfs2_meta_glops = {
435 .go_xmote_th = meta_go_sync, 366 .go_xmote_th = meta_go_sync,
436 .go_drop_th = meta_go_sync,
437 .go_type = LM_TYPE_META, 367 .go_type = LM_TYPE_META,
438}; 368};
439 369
440const struct gfs2_glock_operations gfs2_inode_glops = { 370const struct gfs2_glock_operations gfs2_inode_glops = {
441 .go_xmote_th = inode_go_xmote_th, 371 .go_xmote_th = inode_go_sync,
442 .go_xmote_bh = inode_go_xmote_bh, 372 .go_xmote_bh = inode_go_xmote_bh,
443 .go_drop_th = inode_go_drop_th,
444 .go_inval = inode_go_inval, 373 .go_inval = inode_go_inval,
445 .go_demote_ok = inode_go_demote_ok, 374 .go_demote_ok = inode_go_demote_ok,
446 .go_lock = inode_go_lock, 375 .go_lock = inode_go_lock,
447 .go_unlock = inode_go_unlock,
448 .go_type = LM_TYPE_INODE, 376 .go_type = LM_TYPE_INODE,
449 .go_min_hold_time = HZ / 10, 377 .go_min_hold_time = HZ / 10,
450}; 378};
451 379
452const struct gfs2_glock_operations gfs2_rgrp_glops = { 380const struct gfs2_glock_operations gfs2_rgrp_glops = {
453 .go_xmote_th = meta_go_sync, 381 .go_xmote_th = meta_go_sync,
454 .go_drop_th = meta_go_sync,
455 .go_inval = meta_go_inval, 382 .go_inval = meta_go_inval,
456 .go_demote_ok = rgrp_go_demote_ok, 383 .go_demote_ok = rgrp_go_demote_ok,
457 .go_lock = rgrp_go_lock, 384 .go_lock = rgrp_go_lock,
@@ -461,9 +388,8 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
461}; 388};
462 389
463const struct gfs2_glock_operations gfs2_trans_glops = { 390const struct gfs2_glock_operations gfs2_trans_glops = {
464 .go_xmote_th = trans_go_xmote_th, 391 .go_xmote_th = trans_go_sync,
465 .go_xmote_bh = trans_go_xmote_bh, 392 .go_xmote_bh = trans_go_xmote_bh,
466 .go_drop_th = trans_go_drop_th,
467 .go_type = LM_TYPE_NONDISK, 393 .go_type = LM_TYPE_NONDISK,
468}; 394};
469 395
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index eaddfb5a8e6f..513aaf0dc0ab 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -131,7 +131,6 @@ struct gfs2_bufdata {
131struct gfs2_glock_operations { 131struct gfs2_glock_operations {
132 void (*go_xmote_th) (struct gfs2_glock *gl); 132 void (*go_xmote_th) (struct gfs2_glock *gl);
133 void (*go_xmote_bh) (struct gfs2_glock *gl); 133 void (*go_xmote_bh) (struct gfs2_glock *gl);
134 void (*go_drop_th) (struct gfs2_glock *gl);
135 void (*go_inval) (struct gfs2_glock *gl, int flags); 134 void (*go_inval) (struct gfs2_glock *gl, int flags);
136 int (*go_demote_ok) (struct gfs2_glock *gl); 135 int (*go_demote_ok) (struct gfs2_glock *gl);
137 int (*go_lock) (struct gfs2_holder *gh); 136 int (*go_lock) (struct gfs2_holder *gh);
@@ -141,10 +140,6 @@ struct gfs2_glock_operations {
141}; 140};
142 141
143enum { 142enum {
144 /* Actions */
145 HIF_MUTEX = 0,
146 HIF_PROMOTE = 1,
147
148 /* States */ 143 /* States */
149 HIF_HOLDER = 6, 144 HIF_HOLDER = 6,
150 HIF_FIRST = 7, 145 HIF_FIRST = 7,
@@ -171,6 +166,8 @@ enum {
171 GLF_DEMOTE = 3, 166 GLF_DEMOTE = 3,
172 GLF_PENDING_DEMOTE = 4, 167 GLF_PENDING_DEMOTE = 4,
173 GLF_DIRTY = 5, 168 GLF_DIRTY = 5,
169 GLF_DEMOTE_IN_PROGRESS = 6,
170 GLF_LFLUSH = 7,
174}; 171};
175 172
176struct gfs2_glock { 173struct gfs2_glock {
@@ -190,6 +187,7 @@ struct gfs2_glock {
190 struct list_head gl_holders; 187 struct list_head gl_holders;
191 struct list_head gl_waiters1; /* HIF_MUTEX */ 188 struct list_head gl_waiters1; /* HIF_MUTEX */
192 struct list_head gl_waiters3; /* HIF_PROMOTE */ 189 struct list_head gl_waiters3; /* HIF_PROMOTE */
190 int gl_waiters2; /* GIF_DEMOTE */
193 191
194 const struct gfs2_glock_operations *gl_ops; 192 const struct gfs2_glock_operations *gl_ops;
195 193
@@ -210,7 +208,6 @@ struct gfs2_glock {
210 struct gfs2_sbd *gl_sbd; 208 struct gfs2_sbd *gl_sbd;
211 209
212 struct inode *gl_aspace; 210 struct inode *gl_aspace;
213 struct gfs2_log_element gl_le;
214 struct list_head gl_ail_list; 211 struct list_head gl_ail_list;
215 atomic_t gl_ail_count; 212 atomic_t gl_ail_count;
216 struct delayed_work gl_work; 213 struct delayed_work gl_work;
@@ -239,7 +236,6 @@ struct gfs2_alloc {
239enum { 236enum {
240 GIF_INVALID = 0, 237 GIF_INVALID = 0,
241 GIF_QD_LOCKED = 1, 238 GIF_QD_LOCKED = 1,
242 GIF_PAGED = 2,
243 GIF_SW_PAGED = 3, 239 GIF_SW_PAGED = 3,
244}; 240};
245 241
@@ -268,14 +264,10 @@ struct gfs2_inode {
268 struct gfs2_glock *i_gl; /* Move into i_gh? */ 264 struct gfs2_glock *i_gl; /* Move into i_gh? */
269 struct gfs2_holder i_iopen_gh; 265 struct gfs2_holder i_iopen_gh;
270 struct gfs2_holder i_gh; /* for prepare/commit_write only */ 266 struct gfs2_holder i_gh; /* for prepare/commit_write only */
271 struct gfs2_alloc i_alloc; 267 struct gfs2_alloc *i_alloc;
272 u64 i_last_rg_alloc; 268 u64 i_last_rg_alloc;
273 269
274 spinlock_t i_spin;
275 struct rw_semaphore i_rw_mutex; 270 struct rw_semaphore i_rw_mutex;
276 unsigned long i_last_pfault;
277
278 struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT];
279}; 271};
280 272
281/* 273/*
@@ -287,19 +279,12 @@ static inline struct gfs2_inode *GFS2_I(struct inode *inode)
287 return container_of(inode, struct gfs2_inode, i_inode); 279 return container_of(inode, struct gfs2_inode, i_inode);
288} 280}
289 281
290/* To be removed? */ 282static inline struct gfs2_sbd *GFS2_SB(const struct inode *inode)
291static inline struct gfs2_sbd *GFS2_SB(struct inode *inode)
292{ 283{
293 return inode->i_sb->s_fs_info; 284 return inode->i_sb->s_fs_info;
294} 285}
295 286
296enum {
297 GFF_DID_DIRECT_ALLOC = 0,
298 GFF_EXLOCK = 1,
299};
300
301struct gfs2_file { 287struct gfs2_file {
302 unsigned long f_flags; /* GFF_... */
303 struct mutex f_fl_mutex; 288 struct mutex f_fl_mutex;
304 struct gfs2_holder f_fl_gh; 289 struct gfs2_holder f_fl_gh;
305}; 290};
@@ -373,8 +358,17 @@ struct gfs2_ail {
373 u64 ai_sync_gen; 358 u64 ai_sync_gen;
374}; 359};
375 360
361struct gfs2_journal_extent {
362 struct list_head extent_list;
363
364 unsigned int lblock; /* First logical block */
365 u64 dblock; /* First disk block */
366 u64 blocks;
367};
368
376struct gfs2_jdesc { 369struct gfs2_jdesc {
377 struct list_head jd_list; 370 struct list_head jd_list;
371 struct list_head extent_list;
378 372
379 struct inode *jd_inode; 373 struct inode *jd_inode;
380 unsigned int jd_jid; 374 unsigned int jd_jid;
@@ -421,13 +415,9 @@ struct gfs2_args {
421struct gfs2_tune { 415struct gfs2_tune {
422 spinlock_t gt_spin; 416 spinlock_t gt_spin;
423 417
424 unsigned int gt_ilimit;
425 unsigned int gt_ilimit_tries;
426 unsigned int gt_ilimit_min;
427 unsigned int gt_demote_secs; /* Cache retention for unheld glock */ 418 unsigned int gt_demote_secs; /* Cache retention for unheld glock */
428 unsigned int gt_incore_log_blocks; 419 unsigned int gt_incore_log_blocks;
429 unsigned int gt_log_flush_secs; 420 unsigned int gt_log_flush_secs;
430 unsigned int gt_jindex_refresh_secs; /* Check for new journal index */
431 421
432 unsigned int gt_recoverd_secs; 422 unsigned int gt_recoverd_secs;
433 unsigned int gt_logd_secs; 423 unsigned int gt_logd_secs;
@@ -443,10 +433,8 @@ struct gfs2_tune {
443 unsigned int gt_new_files_jdata; 433 unsigned int gt_new_files_jdata;
444 unsigned int gt_new_files_directio; 434 unsigned int gt_new_files_directio;
445 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ 435 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
446 unsigned int gt_lockdump_size;
447 unsigned int gt_stall_secs; /* Detects trouble! */ 436 unsigned int gt_stall_secs; /* Detects trouble! */
448 unsigned int gt_complain_secs; 437 unsigned int gt_complain_secs;
449 unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */
450 unsigned int gt_statfs_quantum; 438 unsigned int gt_statfs_quantum;
451 unsigned int gt_statfs_slow; 439 unsigned int gt_statfs_slow;
452}; 440};
@@ -539,7 +527,6 @@ struct gfs2_sbd {
539 /* StatFS stuff */ 527 /* StatFS stuff */
540 528
541 spinlock_t sd_statfs_spin; 529 spinlock_t sd_statfs_spin;
542 struct mutex sd_statfs_mutex;
543 struct gfs2_statfs_change_host sd_statfs_master; 530 struct gfs2_statfs_change_host sd_statfs_master;
544 struct gfs2_statfs_change_host sd_statfs_local; 531 struct gfs2_statfs_change_host sd_statfs_local;
545 unsigned long sd_statfs_sync_time; 532 unsigned long sd_statfs_sync_time;
@@ -602,20 +589,18 @@ struct gfs2_sbd {
602 unsigned int sd_log_commited_databuf; 589 unsigned int sd_log_commited_databuf;
603 unsigned int sd_log_commited_revoke; 590 unsigned int sd_log_commited_revoke;
604 591
605 unsigned int sd_log_num_gl;
606 unsigned int sd_log_num_buf; 592 unsigned int sd_log_num_buf;
607 unsigned int sd_log_num_revoke; 593 unsigned int sd_log_num_revoke;
608 unsigned int sd_log_num_rg; 594 unsigned int sd_log_num_rg;
609 unsigned int sd_log_num_databuf; 595 unsigned int sd_log_num_databuf;
610 596
611 struct list_head sd_log_le_gl;
612 struct list_head sd_log_le_buf; 597 struct list_head sd_log_le_buf;
613 struct list_head sd_log_le_revoke; 598 struct list_head sd_log_le_revoke;
614 struct list_head sd_log_le_rg; 599 struct list_head sd_log_le_rg;
615 struct list_head sd_log_le_databuf; 600 struct list_head sd_log_le_databuf;
616 struct list_head sd_log_le_ordered; 601 struct list_head sd_log_le_ordered;
617 602
618 unsigned int sd_log_blks_free; 603 atomic_t sd_log_blks_free;
619 struct mutex sd_log_reserve_mutex; 604 struct mutex sd_log_reserve_mutex;
620 605
621 u64 sd_log_sequence; 606 u64 sd_log_sequence;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 5f6dc32946cd..728d3169e7bd 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -31,7 +31,6 @@
31#include "log.h" 31#include "log.h"
32#include "meta_io.h" 32#include "meta_io.h"
33#include "ops_address.h" 33#include "ops_address.h"
34#include "ops_file.h"
35#include "ops_inode.h" 34#include "ops_inode.h"
36#include "quota.h" 35#include "quota.h"
37#include "rgrp.h" 36#include "rgrp.h"
@@ -132,15 +131,21 @@ static struct inode *gfs2_iget_skip(struct super_block *sb,
132 131
133void gfs2_set_iop(struct inode *inode) 132void gfs2_set_iop(struct inode *inode)
134{ 133{
134 struct gfs2_sbd *sdp = GFS2_SB(inode);
135 umode_t mode = inode->i_mode; 135 umode_t mode = inode->i_mode;
136 136
137 if (S_ISREG(mode)) { 137 if (S_ISREG(mode)) {
138 inode->i_op = &gfs2_file_iops; 138 inode->i_op = &gfs2_file_iops;
139 inode->i_fop = &gfs2_file_fops; 139 if (sdp->sd_args.ar_localflocks)
140 inode->i_mapping->a_ops = &gfs2_file_aops; 140 inode->i_fop = &gfs2_file_fops_nolock;
141 else
142 inode->i_fop = &gfs2_file_fops;
141 } else if (S_ISDIR(mode)) { 143 } else if (S_ISDIR(mode)) {
142 inode->i_op = &gfs2_dir_iops; 144 inode->i_op = &gfs2_dir_iops;
143 inode->i_fop = &gfs2_dir_fops; 145 if (sdp->sd_args.ar_localflocks)
146 inode->i_fop = &gfs2_dir_fops_nolock;
147 else
148 inode->i_fop = &gfs2_dir_fops;
144 } else if (S_ISLNK(mode)) { 149 } else if (S_ISLNK(mode)) {
145 inode->i_op = &gfs2_symlink_iops; 150 inode->i_op = &gfs2_symlink_iops;
146 } else { 151 } else {
@@ -291,12 +296,10 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
291 di->di_entries = be32_to_cpu(str->di_entries); 296 di->di_entries = be32_to_cpu(str->di_entries);
292 297
293 di->di_eattr = be64_to_cpu(str->di_eattr); 298 di->di_eattr = be64_to_cpu(str->di_eattr);
294 return 0; 299 if (S_ISREG(ip->i_inode.i_mode))
295} 300 gfs2_set_aops(&ip->i_inode);
296 301
297static void gfs2_inode_bh(struct gfs2_inode *ip, struct buffer_head *bh) 302 return 0;
298{
299 ip->i_cache[0] = bh;
300} 303}
301 304
302/** 305/**
@@ -366,7 +369,8 @@ int gfs2_dinode_dealloc(struct gfs2_inode *ip)
366 if (error) 369 if (error)
367 goto out_rg_gunlock; 370 goto out_rg_gunlock;
368 371
369 gfs2_trans_add_gl(ip->i_gl); 372 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
373 set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags);
370 374
371 gfs2_free_di(rgd, ip); 375 gfs2_free_di(rgd, ip);
372 376
@@ -707,9 +711,10 @@ static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
707 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 711 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
708 int error; 712 int error;
709 713
710 gfs2_alloc_get(dip); 714 if (gfs2_alloc_get(dip) == NULL)
715 return -ENOMEM;
711 716
712 dip->i_alloc.al_requested = RES_DINODE; 717 dip->i_alloc->al_requested = RES_DINODE;
713 error = gfs2_inplace_reserve(dip); 718 error = gfs2_inplace_reserve(dip);
714 if (error) 719 if (error)
715 goto out; 720 goto out;
@@ -855,7 +860,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
855 860
856 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); 861 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
857 if (alloc_required < 0) 862 if (alloc_required < 0)
858 goto fail; 863 goto fail_quota_locks;
859 if (alloc_required) { 864 if (alloc_required) {
860 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); 865 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
861 if (error) 866 if (error)
@@ -896,7 +901,7 @@ fail_end_trans:
896 gfs2_trans_end(sdp); 901 gfs2_trans_end(sdp);
897 902
898fail_ipreserv: 903fail_ipreserv:
899 if (dip->i_alloc.al_rgd) 904 if (dip->i_alloc->al_rgd)
900 gfs2_inplace_release(dip); 905 gfs2_inplace_release(dip);
901 906
902fail_quota_locks: 907fail_quota_locks:
@@ -966,7 +971,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
966 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; 971 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 };
967 int error; 972 int error;
968 u64 generation; 973 u64 generation;
969 struct buffer_head *bh=NULL; 974 struct buffer_head *bh = NULL;
970 975
971 if (!name->len || name->len > GFS2_FNAMESIZE) 976 if (!name->len || name->len > GFS2_FNAMESIZE)
972 return ERR_PTR(-ENAMETOOLONG); 977 return ERR_PTR(-ENAMETOOLONG);
@@ -1003,8 +1008,6 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
1003 if (IS_ERR(inode)) 1008 if (IS_ERR(inode))
1004 goto fail_gunlock2; 1009 goto fail_gunlock2;
1005 1010
1006 gfs2_inode_bh(GFS2_I(inode), bh);
1007
1008 error = gfs2_inode_refresh(GFS2_I(inode)); 1011 error = gfs2_inode_refresh(GFS2_I(inode));
1009 if (error) 1012 if (error)
1010 goto fail_gunlock2; 1013 goto fail_gunlock2;
@@ -1021,6 +1024,8 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
1021 if (error) 1024 if (error)
1022 goto fail_gunlock2; 1025 goto fail_gunlock2;
1023 1026
1027 if (bh)
1028 brelse(bh);
1024 if (!inode) 1029 if (!inode)
1025 return ERR_PTR(-ENOMEM); 1030 return ERR_PTR(-ENOMEM);
1026 return inode; 1031 return inode;
@@ -1032,6 +1037,8 @@ fail_gunlock2:
1032fail_gunlock: 1037fail_gunlock:
1033 gfs2_glock_dq(ghs); 1038 gfs2_glock_dq(ghs);
1034fail: 1039fail:
1040 if (bh)
1041 brelse(bh);
1035 return ERR_PTR(error); 1042 return ERR_PTR(error);
1036} 1043}
1037 1044
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 351ac87ab384..d44650662615 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -20,6 +20,18 @@ static inline int gfs2_is_jdata(const struct gfs2_inode *ip)
20 return ip->i_di.di_flags & GFS2_DIF_JDATA; 20 return ip->i_di.di_flags & GFS2_DIF_JDATA;
21} 21}
22 22
23static inline int gfs2_is_writeback(const struct gfs2_inode *ip)
24{
25 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
26 return (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK) && !gfs2_is_jdata(ip);
27}
28
29static inline int gfs2_is_ordered(const struct gfs2_inode *ip)
30{
31 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
32 return (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) && !gfs2_is_jdata(ip);
33}
34
23static inline int gfs2_is_dir(const struct gfs2_inode *ip) 35static inline int gfs2_is_dir(const struct gfs2_inode *ip)
24{ 36{
25 return S_ISDIR(ip->i_inode.i_mode); 37 return S_ISDIR(ip->i_inode.i_mode);
diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c
index 41c5b04caaba..f2efff424224 100644
--- a/fs/gfs2/locking/dlm/mount.c
+++ b/fs/gfs2/locking/dlm/mount.c
@@ -67,6 +67,11 @@ static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
67 memset(data, 0, 256); 67 memset(data, 0, 256);
68 strncpy(data, data_arg, 255); 68 strncpy(data, data_arg, 255);
69 69
70 if (!strlen(data)) {
71 log_error("no mount options, (u)mount helpers not installed");
72 return -EINVAL;
73 }
74
70 for (options = data; (x = strsep(&options, ":")); ) { 75 for (options = data; (x = strsep(&options, ":")); ) {
71 if (!*x) 76 if (!*x)
72 continue; 77 continue;
diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c
index 1f7b038530b4..2ebd374b3143 100644
--- a/fs/gfs2/locking/dlm/plock.c
+++ b/fs/gfs2/locking/dlm/plock.c
@@ -89,15 +89,19 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
89 op->info.number = name->ln_number; 89 op->info.number = name->ln_number;
90 op->info.start = fl->fl_start; 90 op->info.start = fl->fl_start;
91 op->info.end = fl->fl_end; 91 op->info.end = fl->fl_end;
92 op->info.owner = (__u64)(long) fl->fl_owner;
93 if (fl->fl_lmops && fl->fl_lmops->fl_grant) { 92 if (fl->fl_lmops && fl->fl_lmops->fl_grant) {
93 /* fl_owner is lockd which doesn't distinguish
94 processes on the nfs client */
95 op->info.owner = (__u64) fl->fl_pid;
94 xop->callback = fl->fl_lmops->fl_grant; 96 xop->callback = fl->fl_lmops->fl_grant;
95 locks_init_lock(&xop->flc); 97 locks_init_lock(&xop->flc);
96 locks_copy_lock(&xop->flc, fl); 98 locks_copy_lock(&xop->flc, fl);
97 xop->fl = fl; 99 xop->fl = fl;
98 xop->file = file; 100 xop->file = file;
99 } else 101 } else {
102 op->info.owner = (__u64)(long) fl->fl_owner;
100 xop->callback = NULL; 103 xop->callback = NULL;
104 }
101 105
102 send_op(op); 106 send_op(op);
103 107
@@ -203,7 +207,10 @@ int gdlm_punlock(void *lockspace, struct lm_lockname *name,
203 op->info.number = name->ln_number; 207 op->info.number = name->ln_number;
204 op->info.start = fl->fl_start; 208 op->info.start = fl->fl_start;
205 op->info.end = fl->fl_end; 209 op->info.end = fl->fl_end;
206 op->info.owner = (__u64)(long) fl->fl_owner; 210 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
211 op->info.owner = (__u64) fl->fl_pid;
212 else
213 op->info.owner = (__u64)(long) fl->fl_owner;
207 214
208 send_op(op); 215 send_op(op);
209 wait_event(recv_wq, (op->done != 0)); 216 wait_event(recv_wq, (op->done != 0));
@@ -242,7 +249,10 @@ int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
242 op->info.number = name->ln_number; 249 op->info.number = name->ln_number;
243 op->info.start = fl->fl_start; 250 op->info.start = fl->fl_start;
244 op->info.end = fl->fl_end; 251 op->info.end = fl->fl_end;
245 op->info.owner = (__u64)(long) fl->fl_owner; 252 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
253 op->info.owner = (__u64) fl->fl_pid;
254 else
255 op->info.owner = (__u64)(long) fl->fl_owner;
246 256
247 send_op(op); 257 send_op(op);
248 wait_event(recv_wq, (op->done != 0)); 258 wait_event(recv_wq, (op->done != 0));
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index ae9e6a25fe2b..a87b09839761 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -189,51 +189,39 @@ static struct kobj_type gdlm_ktype = {
189 .sysfs_ops = &gdlm_attr_ops, 189 .sysfs_ops = &gdlm_attr_ops,
190}; 190};
191 191
192static struct kset gdlm_kset = { 192static struct kset *gdlm_kset;
193 .ktype = &gdlm_ktype,
194};
195 193
196int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) 194int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
197{ 195{
198 int error; 196 int error;
199 197
200 error = kobject_set_name(&ls->kobj, "%s", "lock_module"); 198 ls->kobj.kset = gdlm_kset;
201 if (error) { 199 error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
202 log_error("can't set kobj name %d", error); 200 "lock_module");
203 return error;
204 }
205
206 ls->kobj.kset = &gdlm_kset;
207 ls->kobj.ktype = &gdlm_ktype;
208 ls->kobj.parent = fskobj;
209
210 error = kobject_register(&ls->kobj);
211 if (error) 201 if (error)
212 log_error("can't register kobj %d", error); 202 log_error("can't register kobj %d", error);
203 kobject_uevent(&ls->kobj, KOBJ_ADD);
213 204
214 return error; 205 return error;
215} 206}
216 207
217void gdlm_kobject_release(struct gdlm_ls *ls) 208void gdlm_kobject_release(struct gdlm_ls *ls)
218{ 209{
219 kobject_unregister(&ls->kobj); 210 kobject_put(&ls->kobj);
220} 211}
221 212
222int gdlm_sysfs_init(void) 213int gdlm_sysfs_init(void)
223{ 214{
224 int error; 215 gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
225 216 if (!gdlm_kset) {
226 kobject_set_name(&gdlm_kset.kobj, "lock_dlm"); 217 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
227 kobj_set_kset_s(&gdlm_kset, kernel_subsys); 218 return -ENOMEM;
228 error = kset_register(&gdlm_kset); 219 }
229 if (error) 220 return 0;
230 printk("lock_dlm: cannot register kset %d\n", error);
231
232 return error;
233} 221}
234 222
235void gdlm_sysfs_exit(void) 223void gdlm_sysfs_exit(void)
236{ 224{
237 kset_unregister(&gdlm_kset); 225 kset_unregister(gdlm_kset);
238} 226}
239 227
diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c
index bd938f06481d..521694fc19d6 100644
--- a/fs/gfs2/locking/dlm/thread.c
+++ b/fs/gfs2/locking/dlm/thread.c
@@ -273,18 +273,13 @@ static int gdlm_thread(void *data, int blist)
273 struct gdlm_ls *ls = (struct gdlm_ls *) data; 273 struct gdlm_ls *ls = (struct gdlm_ls *) data;
274 struct gdlm_lock *lp = NULL; 274 struct gdlm_lock *lp = NULL;
275 uint8_t complete, blocking, submit, drop; 275 uint8_t complete, blocking, submit, drop;
276 DECLARE_WAITQUEUE(wait, current);
277 276
278 /* Only thread1 is allowed to do blocking callbacks since gfs 277 /* Only thread1 is allowed to do blocking callbacks since gfs
279 may wait for a completion callback within a blocking cb. */ 278 may wait for a completion callback within a blocking cb. */
280 279
281 while (!kthread_should_stop()) { 280 while (!kthread_should_stop()) {
282 set_current_state(TASK_INTERRUPTIBLE); 281 wait_event_interruptible(ls->thread_wait,
283 add_wait_queue(&ls->thread_wait, &wait); 282 !no_work(ls, blist) || kthread_should_stop());
284 if (no_work(ls, blist))
285 schedule();
286 remove_wait_queue(&ls->thread_wait, &wait);
287 set_current_state(TASK_RUNNING);
288 283
289 complete = blocking = submit = drop = 0; 284 complete = blocking = submit = drop = 0;
290 285
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 7df702473252..161ab6f2058e 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -16,6 +16,8 @@
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h> 17#include <linux/lm_interface.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/kthread.h>
20#include <linux/freezer.h>
19 21
20#include "gfs2.h" 22#include "gfs2.h"
21#include "incore.h" 23#include "incore.h"
@@ -68,14 +70,12 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
68 * 70 *
69 */ 71 */
70 72
71void gfs2_remove_from_ail(struct address_space *mapping, struct gfs2_bufdata *bd) 73void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
72{ 74{
73 bd->bd_ail = NULL; 75 bd->bd_ail = NULL;
74 list_del_init(&bd->bd_ail_st_list); 76 list_del_init(&bd->bd_ail_st_list);
75 list_del_init(&bd->bd_ail_gl_list); 77 list_del_init(&bd->bd_ail_gl_list);
76 atomic_dec(&bd->bd_gl->gl_ail_count); 78 atomic_dec(&bd->bd_gl->gl_ail_count);
77 if (mapping)
78 gfs2_meta_cache_flush(GFS2_I(mapping->host));
79 brelse(bd->bd_bh); 79 brelse(bd->bd_bh);
80} 80}
81 81
@@ -92,8 +92,6 @@ static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
92 struct buffer_head *bh; 92 struct buffer_head *bh;
93 int retry; 93 int retry;
94 94
95 BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
96
97 do { 95 do {
98 retry = 0; 96 retry = 0;
99 97
@@ -210,7 +208,7 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
210 gfs2_log_unlock(sdp); 208 gfs2_log_unlock(sdp);
211} 209}
212 210
213int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) 211static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
214{ 212{
215 struct gfs2_ail *ai, *s; 213 struct gfs2_ail *ai, *s;
216 int ret; 214 int ret;
@@ -248,7 +246,7 @@ static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
248 bd = list_entry(head->prev, struct gfs2_bufdata, 246 bd = list_entry(head->prev, struct gfs2_bufdata,
249 bd_ail_st_list); 247 bd_ail_st_list);
250 gfs2_assert(sdp, bd->bd_ail == ai); 248 gfs2_assert(sdp, bd->bd_ail == ai);
251 gfs2_remove_from_ail(bd->bd_bh->b_page->mapping, bd); 249 gfs2_remove_from_ail(bd);
252 } 250 }
253} 251}
254 252
@@ -303,7 +301,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
303 301
304 mutex_lock(&sdp->sd_log_reserve_mutex); 302 mutex_lock(&sdp->sd_log_reserve_mutex);
305 gfs2_log_lock(sdp); 303 gfs2_log_lock(sdp);
306 while(sdp->sd_log_blks_free <= (blks + reserved_blks)) { 304 while(atomic_read(&sdp->sd_log_blks_free) <= (blks + reserved_blks)) {
307 gfs2_log_unlock(sdp); 305 gfs2_log_unlock(sdp);
308 gfs2_ail1_empty(sdp, 0); 306 gfs2_ail1_empty(sdp, 0);
309 gfs2_log_flush(sdp, NULL); 307 gfs2_log_flush(sdp, NULL);
@@ -312,7 +310,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
312 gfs2_ail1_start(sdp, 0); 310 gfs2_ail1_start(sdp, 0);
313 gfs2_log_lock(sdp); 311 gfs2_log_lock(sdp);
314 } 312 }
315 sdp->sd_log_blks_free -= blks; 313 atomic_sub(blks, &sdp->sd_log_blks_free);
316 gfs2_log_unlock(sdp); 314 gfs2_log_unlock(sdp);
317 mutex_unlock(&sdp->sd_log_reserve_mutex); 315 mutex_unlock(&sdp->sd_log_reserve_mutex);
318 316
@@ -332,27 +330,23 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
332{ 330{
333 331
334 gfs2_log_lock(sdp); 332 gfs2_log_lock(sdp);
335 sdp->sd_log_blks_free += blks; 333 atomic_add(blks, &sdp->sd_log_blks_free);
336 gfs2_assert_withdraw(sdp, 334 gfs2_assert_withdraw(sdp,
337 sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); 335 atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
338 gfs2_log_unlock(sdp); 336 gfs2_log_unlock(sdp);
339 up_read(&sdp->sd_log_flush_lock); 337 up_read(&sdp->sd_log_flush_lock);
340} 338}
341 339
342static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) 340static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
343{ 341{
344 struct inode *inode = sdp->sd_jdesc->jd_inode; 342 struct gfs2_journal_extent *je;
345 int error; 343
346 struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 }; 344 list_for_each_entry(je, &sdp->sd_jdesc->extent_list, extent_list) {
347 345 if (lbn >= je->lblock && lbn < je->lblock + je->blocks)
348 bh_map.b_size = 1 << inode->i_blkbits; 346 return je->dblock + lbn - je->lblock;
349 error = gfs2_block_map(inode, lbn, 0, &bh_map); 347 }
350 if (error || !bh_map.b_blocknr) 348
351 printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, 349 return -1;
352 (unsigned long long)bh_map.b_blocknr, lbn);
353 gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr);
354
355 return bh_map.b_blocknr;
356} 350}
357 351
358/** 352/**
@@ -561,8 +555,8 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
561 ail2_empty(sdp, new_tail); 555 ail2_empty(sdp, new_tail);
562 556
563 gfs2_log_lock(sdp); 557 gfs2_log_lock(sdp);
564 sdp->sd_log_blks_free += dist; 558 atomic_add(dist, &sdp->sd_log_blks_free);
565 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); 559 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
566 gfs2_log_unlock(sdp); 560 gfs2_log_unlock(sdp);
567 561
568 sdp->sd_log_tail = new_tail; 562 sdp->sd_log_tail = new_tail;
@@ -652,7 +646,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
652 get_bh(bh); 646 get_bh(bh);
653 gfs2_log_unlock(sdp); 647 gfs2_log_unlock(sdp);
654 lock_buffer(bh); 648 lock_buffer(bh);
655 if (test_clear_buffer_dirty(bh)) { 649 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
656 bh->b_end_io = end_buffer_write_sync; 650 bh->b_end_io = end_buffer_write_sync;
657 submit_bh(WRITE, bh); 651 submit_bh(WRITE, bh);
658 } else { 652 } else {
@@ -694,20 +688,16 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
694 * 688 *
695 */ 689 */
696 690
697void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) 691void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
698{ 692{
699 struct gfs2_ail *ai; 693 struct gfs2_ail *ai;
700 694
701 down_write(&sdp->sd_log_flush_lock); 695 down_write(&sdp->sd_log_flush_lock);
702 696
703 if (gl) { 697 /* Log might have been flushed while we waited for the flush lock */
704 gfs2_log_lock(sdp); 698 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) {
705 if (list_empty(&gl->gl_le.le_list)) { 699 up_write(&sdp->sd_log_flush_lock);
706 gfs2_log_unlock(sdp); 700 return;
707 up_write(&sdp->sd_log_flush_lock);
708 return;
709 }
710 gfs2_log_unlock(sdp);
711 } 701 }
712 702
713 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); 703 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
@@ -739,7 +729,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
739 log_flush_commit(sdp); 729 log_flush_commit(sdp);
740 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ 730 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
741 gfs2_log_lock(sdp); 731 gfs2_log_lock(sdp);
742 sdp->sd_log_blks_free--; /* Adjust for unreserved buffer */ 732 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
743 gfs2_log_unlock(sdp); 733 gfs2_log_unlock(sdp);
744 log_write_header(sdp, 0, PULL); 734 log_write_header(sdp, 0, PULL);
745 } 735 }
@@ -767,7 +757,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
767static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 757static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
768{ 758{
769 unsigned int reserved; 759 unsigned int reserved;
770 unsigned int old; 760 unsigned int unused;
771 761
772 gfs2_log_lock(sdp); 762 gfs2_log_lock(sdp);
773 763
@@ -779,14 +769,11 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
779 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm; 769 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
780 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); 770 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
781 reserved = calc_reserved(sdp); 771 reserved = calc_reserved(sdp);
782 old = sdp->sd_log_blks_free; 772 unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved;
783 sdp->sd_log_blks_free += tr->tr_reserved - 773 gfs2_assert_withdraw(sdp, unused >= 0);
784 (reserved - sdp->sd_log_blks_reserved); 774 atomic_add(unused, &sdp->sd_log_blks_free);
785 775 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
786 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old);
787 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <=
788 sdp->sd_jdesc->jd_blocks); 776 sdp->sd_jdesc->jd_blocks);
789
790 sdp->sd_log_blks_reserved = reserved; 777 sdp->sd_log_blks_reserved = reserved;
791 778
792 gfs2_log_unlock(sdp); 779 gfs2_log_unlock(sdp);
@@ -825,7 +812,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp)
825 down_write(&sdp->sd_log_flush_lock); 812 down_write(&sdp->sd_log_flush_lock);
826 813
827 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); 814 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
828 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl);
829 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); 815 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
830 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); 816 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
831 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); 817 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
@@ -838,7 +824,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp)
838 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 824 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT,
839 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL); 825 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL);
840 826
841 gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); 827 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
842 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); 828 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
843 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); 829 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
844 830
@@ -866,3 +852,42 @@ void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
866 } 852 }
867} 853}
868 854
855
856/**
857 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
858 * @sdp: Pointer to GFS2 superblock
859 *
860 * Also, periodically check to make sure that we're using the most recent
861 * journal index.
862 */
863
864int gfs2_logd(void *data)
865{
866 struct gfs2_sbd *sdp = data;
867 unsigned long t;
868 int need_flush;
869
870 while (!kthread_should_stop()) {
871 /* Advance the log tail */
872
873 t = sdp->sd_log_flush_time +
874 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
875
876 gfs2_ail1_empty(sdp, DIO_ALL);
877 gfs2_log_lock(sdp);
878 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
879 gfs2_log_unlock(sdp);
880 if (need_flush || time_after_eq(jiffies, t)) {
881 gfs2_log_flush(sdp, NULL);
882 sdp->sd_log_flush_time = jiffies;
883 }
884
885 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
886 if (freezing(current))
887 refrigerator();
888 schedule_timeout_interruptible(t);
889 }
890
891 return 0;
892}
893
diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h
index dae282400627..771152816508 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -48,8 +48,6 @@ static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp,
48unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, 48unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
49 unsigned int ssize); 49 unsigned int ssize);
50 50
51int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags);
52
53int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); 51int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
54void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); 52void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
55void gfs2_log_incr_head(struct gfs2_sbd *sdp); 53void gfs2_log_incr_head(struct gfs2_sbd *sdp);
@@ -57,11 +55,19 @@ void gfs2_log_incr_head(struct gfs2_sbd *sdp);
57struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp); 55struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp);
58struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, 56struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
59 struct buffer_head *real); 57 struct buffer_head *real);
60void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl); 58void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl);
59
60static inline void gfs2_log_flush(struct gfs2_sbd *sbd, struct gfs2_glock *gl)
61{
62 if (!gl || test_bit(GLF_LFLUSH, &gl->gl_flags))
63 __gfs2_log_flush(sbd, gl);
64}
65
61void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); 66void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
62void gfs2_remove_from_ail(struct address_space *mapping, struct gfs2_bufdata *bd); 67void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
63 68
64void gfs2_log_shutdown(struct gfs2_sbd *sdp); 69void gfs2_log_shutdown(struct gfs2_sbd *sdp);
65void gfs2_meta_syncfs(struct gfs2_sbd *sdp); 70void gfs2_meta_syncfs(struct gfs2_sbd *sdp);
71int gfs2_logd(void *data);
66 72
67#endif /* __LOG_DOT_H__ */ 73#endif /* __LOG_DOT_H__ */
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 6c27cea761c6..fae59d69d01a 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -87,6 +87,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
87 } 87 }
88 bd->bd_ail = ai; 88 bd->bd_ail = ai;
89 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); 89 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list);
90 clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
90 gfs2_log_unlock(sdp); 91 gfs2_log_unlock(sdp);
91 unlock_buffer(bh); 92 unlock_buffer(bh);
92} 93}
@@ -124,49 +125,6 @@ static struct buffer_head *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type)
124 return bh; 125 return bh;
125} 126}
126 127
127static void __glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
128{
129 struct gfs2_glock *gl;
130 struct gfs2_trans *tr = current->journal_info;
131
132 tr->tr_touched = 1;
133
134 gl = container_of(le, struct gfs2_glock, gl_le);
135 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl)))
136 return;
137
138 if (!list_empty(&le->le_list))
139 return;
140
141 gfs2_glock_hold(gl);
142 set_bit(GLF_DIRTY, &gl->gl_flags);
143 sdp->sd_log_num_gl++;
144 list_add(&le->le_list, &sdp->sd_log_le_gl);
145}
146
147static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
148{
149 gfs2_log_lock(sdp);
150 __glock_lo_add(sdp, le);
151 gfs2_log_unlock(sdp);
152}
153
154static void glock_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
155{
156 struct list_head *head = &sdp->sd_log_le_gl;
157 struct gfs2_glock *gl;
158
159 while (!list_empty(head)) {
160 gl = list_entry(head->next, struct gfs2_glock, gl_le.le_list);
161 list_del_init(&gl->gl_le.le_list);
162 sdp->sd_log_num_gl--;
163
164 gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl));
165 gfs2_glock_put(gl);
166 }
167 gfs2_assert_warn(sdp, !sdp->sd_log_num_gl);
168}
169
170static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) 128static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
171{ 129{
172 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); 130 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le);
@@ -182,7 +140,8 @@ static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
182 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 140 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
183 if (!list_empty(&le->le_list)) 141 if (!list_empty(&le->le_list))
184 goto out; 142 goto out;
185 __glock_lo_add(sdp, &bd->bd_gl->gl_le); 143 set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
144 set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
186 gfs2_meta_check(sdp, bd->bd_bh); 145 gfs2_meta_check(sdp, bd->bd_bh);
187 gfs2_pin(sdp, bd->bd_bh); 146 gfs2_pin(sdp, bd->bd_bh);
188 sdp->sd_log_num_buf++; 147 sdp->sd_log_num_buf++;
@@ -556,17 +515,20 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
556 515
557 lock_buffer(bd->bd_bh); 516 lock_buffer(bd->bd_bh);
558 gfs2_log_lock(sdp); 517 gfs2_log_lock(sdp);
559 if (!list_empty(&bd->bd_list_tr)) 518 if (tr) {
560 goto out; 519 if (!list_empty(&bd->bd_list_tr))
561 tr->tr_touched = 1; 520 goto out;
562 if (gfs2_is_jdata(ip)) { 521 tr->tr_touched = 1;
563 tr->tr_num_buf++; 522 if (gfs2_is_jdata(ip)) {
564 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 523 tr->tr_num_buf++;
524 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
525 }
565 } 526 }
566 if (!list_empty(&le->le_list)) 527 if (!list_empty(&le->le_list))
567 goto out; 528 goto out;
568 529
569 __glock_lo_add(sdp, &bd->bd_gl->gl_le); 530 set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
531 set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
570 if (gfs2_is_jdata(ip)) { 532 if (gfs2_is_jdata(ip)) {
571 gfs2_pin(sdp, bd->bd_bh); 533 gfs2_pin(sdp, bd->bd_bh);
572 tr->tr_num_databuf_new++; 534 tr->tr_num_databuf_new++;
@@ -773,12 +735,6 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
773} 735}
774 736
775 737
776const struct gfs2_log_operations gfs2_glock_lops = {
777 .lo_add = glock_lo_add,
778 .lo_after_commit = glock_lo_after_commit,
779 .lo_name = "glock",
780};
781
782const struct gfs2_log_operations gfs2_buf_lops = { 738const struct gfs2_log_operations gfs2_buf_lops = {
783 .lo_add = buf_lo_add, 739 .lo_add = buf_lo_add,
784 .lo_incore_commit = buf_lo_incore_commit, 740 .lo_incore_commit = buf_lo_incore_commit,
@@ -816,7 +772,6 @@ const struct gfs2_log_operations gfs2_databuf_lops = {
816}; 772};
817 773
818const struct gfs2_log_operations *gfs2_log_ops[] = { 774const struct gfs2_log_operations *gfs2_log_ops[] = {
819 &gfs2_glock_lops,
820 &gfs2_databuf_lops, 775 &gfs2_databuf_lops,
821 &gfs2_buf_lops, 776 &gfs2_buf_lops,
822 &gfs2_rg_lops, 777 &gfs2_rg_lops,
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 7ecfe0d3a491..9c7765c12d62 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -29,9 +29,8 @@ static void gfs2_init_inode_once(struct kmem_cache *cachep, void *foo)
29 struct gfs2_inode *ip = foo; 29 struct gfs2_inode *ip = foo;
30 30
31 inode_init_once(&ip->i_inode); 31 inode_init_once(&ip->i_inode);
32 spin_lock_init(&ip->i_spin);
33 init_rwsem(&ip->i_rw_mutex); 32 init_rwsem(&ip->i_rw_mutex);
34 memset(ip->i_cache, 0, sizeof(ip->i_cache)); 33 ip->i_alloc = NULL;
35} 34}
36 35
37static void gfs2_init_glock_once(struct kmem_cache *cachep, void *foo) 36static void gfs2_init_glock_once(struct kmem_cache *cachep, void *foo)
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 4da423985e4f..85aea27b4a86 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -50,6 +50,7 @@ static int gfs2_aspace_writepage(struct page *page,
50static const struct address_space_operations aspace_aops = { 50static const struct address_space_operations aspace_aops = {
51 .writepage = gfs2_aspace_writepage, 51 .writepage = gfs2_aspace_writepage,
52 .releasepage = gfs2_releasepage, 52 .releasepage = gfs2_releasepage,
53 .sync_page = block_sync_page,
53}; 54};
54 55
55/** 56/**
@@ -221,13 +222,14 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
221 struct buffer_head **bhp) 222 struct buffer_head **bhp)
222{ 223{
223 *bhp = getbuf(gl, blkno, CREATE); 224 *bhp = getbuf(gl, blkno, CREATE);
224 if (!buffer_uptodate(*bhp)) 225 if (!buffer_uptodate(*bhp)) {
225 ll_rw_block(READ_META, 1, bhp); 226 ll_rw_block(READ_META, 1, bhp);
226 if (flags & DIO_WAIT) { 227 if (flags & DIO_WAIT) {
227 int error = gfs2_meta_wait(gl->gl_sbd, *bhp); 228 int error = gfs2_meta_wait(gl->gl_sbd, *bhp);
228 if (error) { 229 if (error) {
229 brelse(*bhp); 230 brelse(*bhp);
230 return error; 231 return error;
232 }
231 } 233 }
232 } 234 }
233 235
@@ -282,7 +284,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
282 return; 284 return;
283 } 285 }
284 286
285 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), 287 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
286 bd->bd_bh = bh; 288 bd->bd_bh = bh;
287 bd->bd_gl = gl; 289 bd->bd_gl = gl;
288 290
@@ -317,7 +319,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
317 } 319 }
318 if (bd) { 320 if (bd) {
319 if (bd->bd_ail) { 321 if (bd->bd_ail) {
320 gfs2_remove_from_ail(NULL, bd); 322 gfs2_remove_from_ail(bd);
321 bh->b_private = NULL; 323 bh->b_private = NULL;
322 bd->bd_bh = NULL; 324 bd->bd_bh = NULL;
323 bd->bd_blkno = bh->b_blocknr; 325 bd->bd_blkno = bh->b_blocknr;
@@ -358,32 +360,6 @@ void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
358} 360}
359 361
360/** 362/**
361 * gfs2_meta_cache_flush - get rid of any references on buffers for this inode
362 * @ip: The GFS2 inode
363 *
364 * This releases buffers that are in the most-recently-used array of
365 * blocks used for indirect block addressing for this inode.
366 */
367
368void gfs2_meta_cache_flush(struct gfs2_inode *ip)
369{
370 struct buffer_head **bh_slot;
371 unsigned int x;
372
373 spin_lock(&ip->i_spin);
374
375 for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) {
376 bh_slot = &ip->i_cache[x];
377 if (*bh_slot) {
378 brelse(*bh_slot);
379 *bh_slot = NULL;
380 }
381 }
382
383 spin_unlock(&ip->i_spin);
384}
385
386/**
387 * gfs2_meta_indirect_buffer - Get a metadata buffer 363 * gfs2_meta_indirect_buffer - Get a metadata buffer
388 * @ip: The GFS2 inode 364 * @ip: The GFS2 inode
389 * @height: The level of this buf in the metadata (indir addr) tree (if any) 365 * @height: The level of this buf in the metadata (indir addr) tree (if any)
@@ -391,8 +367,6 @@ void gfs2_meta_cache_flush(struct gfs2_inode *ip)
391 * @new: Non-zero if we may create a new buffer 367 * @new: Non-zero if we may create a new buffer
392 * @bhp: the buffer is returned here 368 * @bhp: the buffer is returned here
393 * 369 *
394 * Try to use the gfs2_inode's MRU metadata tree cache.
395 *
396 * Returns: errno 370 * Returns: errno
397 */ 371 */
398 372
@@ -401,58 +375,25 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
401{ 375{
402 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 376 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
403 struct gfs2_glock *gl = ip->i_gl; 377 struct gfs2_glock *gl = ip->i_gl;
404 struct buffer_head *bh = NULL, **bh_slot = ip->i_cache + height; 378 struct buffer_head *bh;
405 int in_cache = 0; 379 int ret = 0;
406
407 BUG_ON(!gl);
408 BUG_ON(!sdp);
409
410 spin_lock(&ip->i_spin);
411 if (*bh_slot && (*bh_slot)->b_blocknr == num) {
412 bh = *bh_slot;
413 get_bh(bh);
414 in_cache = 1;
415 }
416 spin_unlock(&ip->i_spin);
417
418 if (!bh)
419 bh = getbuf(gl, num, CREATE);
420
421 if (!bh)
422 return -ENOBUFS;
423 380
424 if (new) { 381 if (new) {
425 if (gfs2_assert_warn(sdp, height)) 382 BUG_ON(height == 0);
426 goto err; 383 bh = gfs2_meta_new(gl, num);
427 meta_prep_new(bh);
428 gfs2_trans_add_bh(ip->i_gl, bh, 1); 384 gfs2_trans_add_bh(ip->i_gl, bh, 1);
429 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); 385 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
430 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); 386 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
431 } else { 387 } else {
432 u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI; 388 u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI;
433 if (!buffer_uptodate(bh)) { 389 ret = gfs2_meta_read(gl, num, DIO_WAIT, &bh);
434 ll_rw_block(READ_META, 1, &bh); 390 if (ret == 0 && gfs2_metatype_check(sdp, bh, mtype)) {
435 if (gfs2_meta_wait(sdp, bh)) 391 brelse(bh);
436 goto err; 392 ret = -EIO;
437 } 393 }
438 if (gfs2_metatype_check(sdp, bh, mtype))
439 goto err;
440 }
441
442 if (!in_cache) {
443 spin_lock(&ip->i_spin);
444 if (*bh_slot)
445 brelse(*bh_slot);
446 *bh_slot = bh;
447 get_bh(bh);
448 spin_unlock(&ip->i_spin);
449 } 394 }
450
451 *bhp = bh; 395 *bhp = bh;
452 return 0; 396 return ret;
453err:
454 brelse(bh);
455 return -EIO;
456} 397}
457 398
458/** 399/**
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index b7048222ebb4..73e3b1c76fe1 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -56,7 +56,6 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
56 56
57void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen); 57void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen);
58 58
59void gfs2_meta_cache_flush(struct gfs2_inode *ip);
60int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, 59int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
61 int new, struct buffer_head **bhp); 60 int new, struct buffer_head **bhp);
62 61
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 9679f8b9870d..38dbe99a30ed 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -20,6 +20,8 @@
20#include <linux/swap.h> 20#include <linux/swap.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/lm_interface.h> 22#include <linux/lm_interface.h>
23#include <linux/backing-dev.h>
24#include <linux/pagevec.h>
23 25
24#include "gfs2.h" 26#include "gfs2.h"
25#include "incore.h" 27#include "incore.h"
@@ -32,7 +34,6 @@
32#include "quota.h" 34#include "quota.h"
33#include "trans.h" 35#include "trans.h"
34#include "rgrp.h" 36#include "rgrp.h"
35#include "ops_file.h"
36#include "super.h" 37#include "super.h"
37#include "util.h" 38#include "util.h"
38#include "glops.h" 39#include "glops.h"
@@ -58,22 +59,6 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
58} 59}
59 60
60/** 61/**
61 * gfs2_get_block - Fills in a buffer head with details about a block
62 * @inode: The inode
63 * @lblock: The block number to look up
64 * @bh_result: The buffer head to return the result in
65 * @create: Non-zero if we may add block to the file
66 *
67 * Returns: errno
68 */
69
70int gfs2_get_block(struct inode *inode, sector_t lblock,
71 struct buffer_head *bh_result, int create)
72{
73 return gfs2_block_map(inode, lblock, create, bh_result);
74}
75
76/**
77 * gfs2_get_block_noalloc - Fills in a buffer head with details about a block 62 * gfs2_get_block_noalloc - Fills in a buffer head with details about a block
78 * @inode: The inode 63 * @inode: The inode
79 * @lblock: The block number to look up 64 * @lblock: The block number to look up
@@ -88,7 +73,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
88{ 73{
89 int error; 74 int error;
90 75
91 error = gfs2_block_map(inode, lblock, 0, bh_result); 76 error = gfs2_block_map(inode, lblock, bh_result, 0);
92 if (error) 77 if (error)
93 return error; 78 return error;
94 if (!buffer_mapped(bh_result)) 79 if (!buffer_mapped(bh_result))
@@ -99,20 +84,19 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
99static int gfs2_get_block_direct(struct inode *inode, sector_t lblock, 84static int gfs2_get_block_direct(struct inode *inode, sector_t lblock,
100 struct buffer_head *bh_result, int create) 85 struct buffer_head *bh_result, int create)
101{ 86{
102 return gfs2_block_map(inode, lblock, 0, bh_result); 87 return gfs2_block_map(inode, lblock, bh_result, 0);
103} 88}
104 89
105/** 90/**
106 * gfs2_writepage - Write complete page 91 * gfs2_writepage_common - Common bits of writepage
107 * @page: Page to write 92 * @page: The page to be written
93 * @wbc: The writeback control
108 * 94 *
109 * Returns: errno 95 * Returns: 1 if writepage is ok, otherwise an error code or zero if no error.
110 *
111 * Some of this is copied from block_write_full_page() although we still
112 * call it to do most of the work.
113 */ 96 */
114 97
115static int gfs2_writepage(struct page *page, struct writeback_control *wbc) 98static int gfs2_writepage_common(struct page *page,
99 struct writeback_control *wbc)
116{ 100{
117 struct inode *inode = page->mapping->host; 101 struct inode *inode = page->mapping->host;
118 struct gfs2_inode *ip = GFS2_I(inode); 102 struct gfs2_inode *ip = GFS2_I(inode);
@@ -120,41 +104,133 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
120 loff_t i_size = i_size_read(inode); 104 loff_t i_size = i_size_read(inode);
121 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; 105 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
122 unsigned offset; 106 unsigned offset;
123 int error; 107 int ret = -EIO;
124 int done_trans = 0;
125 108
126 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) { 109 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl)))
127 unlock_page(page); 110 goto out;
128 return -EIO; 111 ret = 0;
129 }
130 if (current->journal_info) 112 if (current->journal_info)
131 goto out_ignore; 113 goto redirty;
132
133 /* Is the page fully outside i_size? (truncate in progress) */ 114 /* Is the page fully outside i_size? (truncate in progress) */
134 offset = i_size & (PAGE_CACHE_SIZE-1); 115 offset = i_size & (PAGE_CACHE_SIZE-1);
135 if (page->index > end_index || (page->index == end_index && !offset)) { 116 if (page->index > end_index || (page->index == end_index && !offset)) {
136 page->mapping->a_ops->invalidatepage(page, 0); 117 page->mapping->a_ops->invalidatepage(page, 0);
137 unlock_page(page); 118 goto out;
138 return 0; /* don't care */ 119 }
120 return 1;
121redirty:
122 redirty_page_for_writepage(wbc, page);
123out:
124 unlock_page(page);
125 return 0;
126}
127
128/**
129 * gfs2_writeback_writepage - Write page for writeback mappings
130 * @page: The page
131 * @wbc: The writeback control
132 *
133 */
134
135static int gfs2_writeback_writepage(struct page *page,
136 struct writeback_control *wbc)
137{
138 int ret;
139
140 ret = gfs2_writepage_common(page, wbc);
141 if (ret <= 0)
142 return ret;
143
144 ret = mpage_writepage(page, gfs2_get_block_noalloc, wbc);
145 if (ret == -EAGAIN)
146 ret = block_write_full_page(page, gfs2_get_block_noalloc, wbc);
147 return ret;
148}
149
150/**
151 * gfs2_ordered_writepage - Write page for ordered data files
152 * @page: The page to write
153 * @wbc: The writeback control
154 *
155 */
156
157static int gfs2_ordered_writepage(struct page *page,
158 struct writeback_control *wbc)
159{
160 struct inode *inode = page->mapping->host;
161 struct gfs2_inode *ip = GFS2_I(inode);
162 int ret;
163
164 ret = gfs2_writepage_common(page, wbc);
165 if (ret <= 0)
166 return ret;
167
168 if (!page_has_buffers(page)) {
169 create_empty_buffers(page, inode->i_sb->s_blocksize,
170 (1 << BH_Dirty)|(1 << BH_Uptodate));
139 } 171 }
172 gfs2_page_add_databufs(ip, page, 0, inode->i_sb->s_blocksize-1);
173 return block_write_full_page(page, gfs2_get_block_noalloc, wbc);
174}
140 175
141 if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) && 176/**
142 PageChecked(page)) { 177 * __gfs2_jdata_writepage - The core of jdata writepage
178 * @page: The page to write
179 * @wbc: The writeback control
180 *
181 * This is shared between writepage and writepages and implements the
182 * core of the writepage operation. If a transaction is required then
183 * PageChecked will have been set and the transaction will have
184 * already been started before this is called.
185 */
186
187static int __gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
188{
189 struct inode *inode = page->mapping->host;
190 struct gfs2_inode *ip = GFS2_I(inode);
191 struct gfs2_sbd *sdp = GFS2_SB(inode);
192
193 if (PageChecked(page)) {
143 ClearPageChecked(page); 194 ClearPageChecked(page);
144 error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
145 if (error)
146 goto out_ignore;
147 if (!page_has_buffers(page)) { 195 if (!page_has_buffers(page)) {
148 create_empty_buffers(page, inode->i_sb->s_blocksize, 196 create_empty_buffers(page, inode->i_sb->s_blocksize,
149 (1 << BH_Dirty)|(1 << BH_Uptodate)); 197 (1 << BH_Dirty)|(1 << BH_Uptodate));
150 } 198 }
151 gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); 199 gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1);
200 }
201 return block_write_full_page(page, gfs2_get_block_noalloc, wbc);
202}
203
204/**
205 * gfs2_jdata_writepage - Write complete page
206 * @page: Page to write
207 *
208 * Returns: errno
209 *
210 */
211
212static int gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
213{
214 struct inode *inode = page->mapping->host;
215 struct gfs2_sbd *sdp = GFS2_SB(inode);
216 int error;
217 int done_trans = 0;
218
219 error = gfs2_writepage_common(page, wbc);
220 if (error <= 0)
221 return error;
222
223 if (PageChecked(page)) {
224 if (wbc->sync_mode != WB_SYNC_ALL)
225 goto out_ignore;
226 error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
227 if (error)
228 goto out_ignore;
152 done_trans = 1; 229 done_trans = 1;
153 } 230 }
154 error = block_write_full_page(page, gfs2_get_block_noalloc, wbc); 231 error = __gfs2_jdata_writepage(page, wbc);
155 if (done_trans) 232 if (done_trans)
156 gfs2_trans_end(sdp); 233 gfs2_trans_end(sdp);
157 gfs2_meta_cache_flush(ip);
158 return error; 234 return error;
159 235
160out_ignore: 236out_ignore:
@@ -164,29 +240,190 @@ out_ignore:
164} 240}
165 241
166/** 242/**
167 * gfs2_writepages - Write a bunch of dirty pages back to disk 243 * gfs2_writeback_writepages - Write a bunch of dirty pages back to disk
168 * @mapping: The mapping to write 244 * @mapping: The mapping to write
169 * @wbc: Write-back control 245 * @wbc: Write-back control
170 * 246 *
171 * For journaled files and/or ordered writes this just falls back to the 247 * For the data=writeback case we can already ignore buffer heads
172 * kernel's default writepages path for now. We will probably want to change
173 * that eventually (i.e. when we look at allocate on flush).
174 *
175 * For the data=writeback case though we can already ignore buffer heads
176 * and write whole extents at once. This is a big reduction in the 248 * and write whole extents at once. This is a big reduction in the
177 * number of I/O requests we send and the bmap calls we make in this case. 249 * number of I/O requests we send and the bmap calls we make in this case.
178 */ 250 */
179static int gfs2_writepages(struct address_space *mapping, 251static int gfs2_writeback_writepages(struct address_space *mapping,
180 struct writeback_control *wbc) 252 struct writeback_control *wbc)
253{
254 return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
255}
256
257/**
258 * gfs2_write_jdata_pagevec - Write back a pagevec's worth of pages
259 * @mapping: The mapping
260 * @wbc: The writeback control
261 * @writepage: The writepage function to call for each page
262 * @pvec: The vector of pages
263 * @nr_pages: The number of pages to write
264 *
265 * Returns: non-zero if loop should terminate, zero otherwise
266 */
267
268static int gfs2_write_jdata_pagevec(struct address_space *mapping,
269 struct writeback_control *wbc,
270 struct pagevec *pvec,
271 int nr_pages, pgoff_t end)
181{ 272{
182 struct inode *inode = mapping->host; 273 struct inode *inode = mapping->host;
183 struct gfs2_inode *ip = GFS2_I(inode);
184 struct gfs2_sbd *sdp = GFS2_SB(inode); 274 struct gfs2_sbd *sdp = GFS2_SB(inode);
275 loff_t i_size = i_size_read(inode);
276 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
277 unsigned offset = i_size & (PAGE_CACHE_SIZE-1);
278 unsigned nrblocks = nr_pages * (PAGE_CACHE_SIZE/inode->i_sb->s_blocksize);
279 struct backing_dev_info *bdi = mapping->backing_dev_info;
280 int i;
281 int ret;
282
283 ret = gfs2_trans_begin(sdp, nrblocks, 0);
284 if (ret < 0)
285 return ret;
286
287 for(i = 0; i < nr_pages; i++) {
288 struct page *page = pvec->pages[i];
289
290 lock_page(page);
291
292 if (unlikely(page->mapping != mapping)) {
293 unlock_page(page);
294 continue;
295 }
296
297 if (!wbc->range_cyclic && page->index > end) {
298 ret = 1;
299 unlock_page(page);
300 continue;
301 }
302
303 if (wbc->sync_mode != WB_SYNC_NONE)
304 wait_on_page_writeback(page);
305
306 if (PageWriteback(page) ||
307 !clear_page_dirty_for_io(page)) {
308 unlock_page(page);
309 continue;
310 }
311
312 /* Is the page fully outside i_size? (truncate in progress) */
313 if (page->index > end_index || (page->index == end_index && !offset)) {
314 page->mapping->a_ops->invalidatepage(page, 0);
315 unlock_page(page);
316 continue;
317 }
318
319 ret = __gfs2_jdata_writepage(page, wbc);
320
321 if (ret || (--(wbc->nr_to_write) <= 0))
322 ret = 1;
323 if (wbc->nonblocking && bdi_write_congested(bdi)) {
324 wbc->encountered_congestion = 1;
325 ret = 1;
326 }
327
328 }
329 gfs2_trans_end(sdp);
330 return ret;
331}
332
333/**
334 * gfs2_write_cache_jdata - Like write_cache_pages but different
335 * @mapping: The mapping to write
336 * @wbc: The writeback control
337 * @writepage: The writepage function to call
338 * @data: The data to pass to writepage
339 *
340 * The reason that we use our own function here is that we need to
341 * start transactions before we grab page locks. This allows us
342 * to get the ordering right.
343 */
344
345static int gfs2_write_cache_jdata(struct address_space *mapping,
346 struct writeback_control *wbc)
347{
348 struct backing_dev_info *bdi = mapping->backing_dev_info;
349 int ret = 0;
350 int done = 0;
351 struct pagevec pvec;
352 int nr_pages;
353 pgoff_t index;
354 pgoff_t end;
355 int scanned = 0;
356 int range_whole = 0;
357
358 if (wbc->nonblocking && bdi_write_congested(bdi)) {
359 wbc->encountered_congestion = 1;
360 return 0;
361 }
362
363 pagevec_init(&pvec, 0);
364 if (wbc->range_cyclic) {
365 index = mapping->writeback_index; /* Start from prev offset */
366 end = -1;
367 } else {
368 index = wbc->range_start >> PAGE_CACHE_SHIFT;
369 end = wbc->range_end >> PAGE_CACHE_SHIFT;
370 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
371 range_whole = 1;
372 scanned = 1;
373 }
185 374
186 if (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK && !gfs2_is_jdata(ip)) 375retry:
187 return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc); 376 while (!done && (index <= end) &&
377 (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
378 PAGECACHE_TAG_DIRTY,
379 min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
380 scanned = 1;
381 ret = gfs2_write_jdata_pagevec(mapping, wbc, &pvec, nr_pages, end);
382 if (ret)
383 done = 1;
384 if (ret > 0)
385 ret = 0;
386
387 pagevec_release(&pvec);
388 cond_resched();
389 }
390
391 if (!scanned && !done) {
392 /*
393 * We hit the last page and there is more work to be done: wrap
394 * back to the start of the file
395 */
396 scanned = 1;
397 index = 0;
398 goto retry;
399 }
400
401 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
402 mapping->writeback_index = index;
403 return ret;
404}
405
406
407/**
408 * gfs2_jdata_writepages - Write a bunch of dirty pages back to disk
409 * @mapping: The mapping to write
410 * @wbc: The writeback control
411 *
412 */
188 413
189 return generic_writepages(mapping, wbc); 414static int gfs2_jdata_writepages(struct address_space *mapping,
415 struct writeback_control *wbc)
416{
417 struct gfs2_inode *ip = GFS2_I(mapping->host);
418 struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
419 int ret;
420
421 ret = gfs2_write_cache_jdata(mapping, wbc);
422 if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
423 gfs2_log_flush(sdp, ip->i_gl);
424 ret = gfs2_write_cache_jdata(mapping, wbc);
425 }
426 return ret;
190} 427}
191 428
192/** 429/**
@@ -231,62 +468,107 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
231 468
232 469
233/** 470/**
234 * gfs2_readpage - readpage with locking 471 * __gfs2_readpage - readpage
235 * @file: The file to read a page for. N.B. This may be NULL if we are 472 * @file: The file to read a page for
236 * reading an internal file.
237 * @page: The page to read 473 * @page: The page to read
238 * 474 *
239 * Returns: errno 475 * This is the core of gfs2's readpage. Its used by the internal file
476 * reading code as in that case we already hold the glock. Also its
477 * called by gfs2_readpage() once the required lock has been granted.
478 *
240 */ 479 */
241 480
242static int gfs2_readpage(struct file *file, struct page *page) 481static int __gfs2_readpage(void *file, struct page *page)
243{ 482{
244 struct gfs2_inode *ip = GFS2_I(page->mapping->host); 483 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
245 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); 484 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
246 struct gfs2_file *gf = NULL;
247 struct gfs2_holder gh;
248 int error; 485 int error;
249 int do_unlock = 0;
250
251 if (likely(file != &gfs2_internal_file_sentinel)) {
252 if (file) {
253 gf = file->private_data;
254 if (test_bit(GFF_EXLOCK, &gf->f_flags))
255 /* gfs2_sharewrite_fault has grabbed the ip->i_gl already */
256 goto skip_lock;
257 }
258 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
259 do_unlock = 1;
260 error = gfs2_glock_nq_atime(&gh);
261 if (unlikely(error))
262 goto out_unlock;
263 }
264 486
265skip_lock:
266 if (gfs2_is_stuffed(ip)) { 487 if (gfs2_is_stuffed(ip)) {
267 error = stuffed_readpage(ip, page); 488 error = stuffed_readpage(ip, page);
268 unlock_page(page); 489 unlock_page(page);
269 } else 490 } else {
270 error = mpage_readpage(page, gfs2_get_block); 491 error = mpage_readpage(page, gfs2_block_map);
492 }
271 493
272 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 494 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
273 error = -EIO; 495 return -EIO;
496
497 return error;
498}
499
500/**
501 * gfs2_readpage - read a page of a file
502 * @file: The file to read
503 * @page: The page of the file
504 *
505 * This deals with the locking required. We use a trylock in order to
506 * avoid the page lock / glock ordering problems returning AOP_TRUNCATED_PAGE
507 * in the event that we are unable to get the lock.
508 */
509
510static int gfs2_readpage(struct file *file, struct page *page)
511{
512 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
513 struct gfs2_holder gh;
514 int error;
274 515
275 if (do_unlock) { 516 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
276 gfs2_glock_dq_m(1, &gh); 517 error = gfs2_glock_nq_atime(&gh);
277 gfs2_holder_uninit(&gh); 518 if (unlikely(error)) {
519 unlock_page(page);
520 goto out;
278 } 521 }
522 error = __gfs2_readpage(file, page);
523 gfs2_glock_dq(&gh);
279out: 524out:
280 return error; 525 gfs2_holder_uninit(&gh);
281out_unlock:
282 unlock_page(page);
283 if (error == GLR_TRYFAILED) { 526 if (error == GLR_TRYFAILED) {
284 error = AOP_TRUNCATED_PAGE;
285 yield(); 527 yield();
528 return AOP_TRUNCATED_PAGE;
286 } 529 }
287 if (do_unlock) 530 return error;
288 gfs2_holder_uninit(&gh); 531}
289 goto out; 532
533/**
534 * gfs2_internal_read - read an internal file
535 * @ip: The gfs2 inode
536 * @ra_state: The readahead state (or NULL for no readahead)
537 * @buf: The buffer to fill
538 * @pos: The file position
539 * @size: The amount to read
540 *
541 */
542
543int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
544 char *buf, loff_t *pos, unsigned size)
545{
546 struct address_space *mapping = ip->i_inode.i_mapping;
547 unsigned long index = *pos / PAGE_CACHE_SIZE;
548 unsigned offset = *pos & (PAGE_CACHE_SIZE - 1);
549 unsigned copied = 0;
550 unsigned amt;
551 struct page *page;
552 void *p;
553
554 do {
555 amt = size - copied;
556 if (offset + size > PAGE_CACHE_SIZE)
557 amt = PAGE_CACHE_SIZE - offset;
558 page = read_cache_page(mapping, index, __gfs2_readpage, NULL);
559 if (IS_ERR(page))
560 return PTR_ERR(page);
561 p = kmap_atomic(page, KM_USER0);
562 memcpy(buf + copied, p + offset, amt);
563 kunmap_atomic(p, KM_USER0);
564 mark_page_accessed(page);
565 page_cache_release(page);
566 copied += amt;
567 index++;
568 offset = 0;
569 } while(copied < size);
570 (*pos) += size;
571 return size;
290} 572}
291 573
292/** 574/**
@@ -300,10 +582,9 @@ out_unlock:
300 * Any I/O we ignore at this time will be done via readpage later. 582 * Any I/O we ignore at this time will be done via readpage later.
301 * 2. We don't handle stuffed files here we let readpage do the honours. 583 * 2. We don't handle stuffed files here we let readpage do the honours.
302 * 3. mpage_readpages() does most of the heavy lifting in the common case. 584 * 3. mpage_readpages() does most of the heavy lifting in the common case.
303 * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places. 585 * 4. gfs2_block_map() is relied upon to set BH_Boundary in the right places.
304 * 5. We use LM_FLAG_TRY_1CB here, effectively we then have lock-ahead as
305 * well as read-ahead.
306 */ 586 */
587
307static int gfs2_readpages(struct file *file, struct address_space *mapping, 588static int gfs2_readpages(struct file *file, struct address_space *mapping,
308 struct list_head *pages, unsigned nr_pages) 589 struct list_head *pages, unsigned nr_pages)
309{ 590{
@@ -311,42 +592,20 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
311 struct gfs2_inode *ip = GFS2_I(inode); 592 struct gfs2_inode *ip = GFS2_I(inode);
312 struct gfs2_sbd *sdp = GFS2_SB(inode); 593 struct gfs2_sbd *sdp = GFS2_SB(inode);
313 struct gfs2_holder gh; 594 struct gfs2_holder gh;
314 int ret = 0; 595 int ret;
315 int do_unlock = 0;
316 596
317 if (likely(file != &gfs2_internal_file_sentinel)) { 597 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh);
318 if (file) { 598 ret = gfs2_glock_nq_atime(&gh);
319 struct gfs2_file *gf = file->private_data; 599 if (unlikely(ret))
320 if (test_bit(GFF_EXLOCK, &gf->f_flags)) 600 goto out_uninit;
321 goto skip_lock;
322 }
323 gfs2_holder_init(ip->i_gl, LM_ST_SHARED,
324 LM_FLAG_TRY_1CB|GL_ATIME, &gh);
325 do_unlock = 1;
326 ret = gfs2_glock_nq_atime(&gh);
327 if (ret == GLR_TRYFAILED)
328 goto out_noerror;
329 if (unlikely(ret))
330 goto out_unlock;
331 }
332skip_lock:
333 if (!gfs2_is_stuffed(ip)) 601 if (!gfs2_is_stuffed(ip))
334 ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block); 602 ret = mpage_readpages(mapping, pages, nr_pages, gfs2_block_map);
335 603 gfs2_glock_dq(&gh);
336 if (do_unlock) { 604out_uninit:
337 gfs2_glock_dq_m(1, &gh); 605 gfs2_holder_uninit(&gh);
338 gfs2_holder_uninit(&gh);
339 }
340out:
341 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 606 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
342 ret = -EIO; 607 ret = -EIO;
343 return ret; 608 return ret;
344out_noerror:
345 ret = 0;
346out_unlock:
347 if (do_unlock)
348 gfs2_holder_uninit(&gh);
349 goto out;
350} 609}
351 610
352/** 611/**
@@ -382,20 +641,11 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
382 if (unlikely(error)) 641 if (unlikely(error))
383 goto out_uninit; 642 goto out_uninit;
384 643
385 error = -ENOMEM;
386 page = __grab_cache_page(mapping, index);
387 *pagep = page;
388 if (!page)
389 goto out_unlock;
390
391 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks); 644 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
392
393 error = gfs2_write_alloc_required(ip, pos, len, &alloc_required); 645 error = gfs2_write_alloc_required(ip, pos, len, &alloc_required);
394 if (error) 646 if (error)
395 goto out_putpage; 647 goto out_unlock;
396
397 648
398 ip->i_alloc.al_requested = 0;
399 if (alloc_required) { 649 if (alloc_required) {
400 al = gfs2_alloc_get(ip); 650 al = gfs2_alloc_get(ip);
401 651
@@ -424,40 +674,47 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
424 if (error) 674 if (error)
425 goto out_trans_fail; 675 goto out_trans_fail;
426 676
677 error = -ENOMEM;
678 page = __grab_cache_page(mapping, index);
679 *pagep = page;
680 if (unlikely(!page))
681 goto out_endtrans;
682
427 if (gfs2_is_stuffed(ip)) { 683 if (gfs2_is_stuffed(ip)) {
684 error = 0;
428 if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { 685 if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) {
429 error = gfs2_unstuff_dinode(ip, page); 686 error = gfs2_unstuff_dinode(ip, page);
430 if (error == 0) 687 if (error == 0)
431 goto prepare_write; 688 goto prepare_write;
432 } else if (!PageUptodate(page)) 689 } else if (!PageUptodate(page)) {
433 error = stuffed_readpage(ip, page); 690 error = stuffed_readpage(ip, page);
691 }
434 goto out; 692 goto out;
435 } 693 }
436 694
437prepare_write: 695prepare_write:
438 error = block_prepare_write(page, from, to, gfs2_get_block); 696 error = block_prepare_write(page, from, to, gfs2_block_map);
439
440out: 697out:
441 if (error) { 698 if (error == 0)
442 gfs2_trans_end(sdp); 699 return 0;
700
701 page_cache_release(page);
702 if (pos + len > ip->i_inode.i_size)
703 vmtruncate(&ip->i_inode, ip->i_inode.i_size);
704out_endtrans:
705 gfs2_trans_end(sdp);
443out_trans_fail: 706out_trans_fail:
444 if (alloc_required) { 707 if (alloc_required) {
445 gfs2_inplace_release(ip); 708 gfs2_inplace_release(ip);
446out_qunlock: 709out_qunlock:
447 gfs2_quota_unlock(ip); 710 gfs2_quota_unlock(ip);
448out_alloc_put: 711out_alloc_put:
449 gfs2_alloc_put(ip); 712 gfs2_alloc_put(ip);
450 } 713 }
451out_putpage:
452 page_cache_release(page);
453 if (pos + len > ip->i_inode.i_size)
454 vmtruncate(&ip->i_inode, ip->i_inode.i_size);
455out_unlock: 714out_unlock:
456 gfs2_glock_dq_m(1, &ip->i_gh); 715 gfs2_glock_dq(&ip->i_gh);
457out_uninit: 716out_uninit:
458 gfs2_holder_uninit(&ip->i_gh); 717 gfs2_holder_uninit(&ip->i_gh);
459 }
460
461 return error; 718 return error;
462} 719}
463 720
@@ -565,7 +822,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
565 struct gfs2_inode *ip = GFS2_I(inode); 822 struct gfs2_inode *ip = GFS2_I(inode);
566 struct gfs2_sbd *sdp = GFS2_SB(inode); 823 struct gfs2_sbd *sdp = GFS2_SB(inode);
567 struct buffer_head *dibh; 824 struct buffer_head *dibh;
568 struct gfs2_alloc *al = &ip->i_alloc; 825 struct gfs2_alloc *al = ip->i_alloc;
569 struct gfs2_dinode *di; 826 struct gfs2_dinode *di;
570 unsigned int from = pos & (PAGE_CACHE_SIZE - 1); 827 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
571 unsigned int to = from + len; 828 unsigned int to = from + len;
@@ -585,19 +842,16 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
585 if (gfs2_is_stuffed(ip)) 842 if (gfs2_is_stuffed(ip))
586 return gfs2_stuffed_write_end(inode, dibh, pos, len, copied, page); 843 return gfs2_stuffed_write_end(inode, dibh, pos, len, copied, page);
587 844
588 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 845 if (!gfs2_is_writeback(ip))
589 gfs2_page_add_databufs(ip, page, from, to); 846 gfs2_page_add_databufs(ip, page, from, to);
590 847
591 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); 848 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
592 849
593 if (likely(ret >= 0)) { 850 if (likely(ret >= 0) && (inode->i_size > ip->i_di.di_size)) {
594 copied = ret; 851 di = (struct gfs2_dinode *)dibh->b_data;
595 if ((pos + copied) > inode->i_size) { 852 ip->i_di.di_size = inode->i_size;
596 di = (struct gfs2_dinode *)dibh->b_data; 853 di->di_size = cpu_to_be64(inode->i_size);
597 ip->i_di.di_size = inode->i_size; 854 mark_inode_dirty(inode);
598 di->di_size = cpu_to_be64(inode->i_size);
599 mark_inode_dirty(inode);
600 }
601 } 855 }
602 856
603 if (inode == sdp->sd_rindex) 857 if (inode == sdp->sd_rindex)
@@ -606,7 +860,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
606 brelse(dibh); 860 brelse(dibh);
607 gfs2_trans_end(sdp); 861 gfs2_trans_end(sdp);
608failed: 862failed:
609 if (al->al_requested) { 863 if (al) {
610 gfs2_inplace_release(ip); 864 gfs2_inplace_release(ip);
611 gfs2_quota_unlock(ip); 865 gfs2_quota_unlock(ip);
612 gfs2_alloc_put(ip); 866 gfs2_alloc_put(ip);
@@ -625,11 +879,7 @@ failed:
625 879
626static int gfs2_set_page_dirty(struct page *page) 880static int gfs2_set_page_dirty(struct page *page)
627{ 881{
628 struct gfs2_inode *ip = GFS2_I(page->mapping->host); 882 SetPageChecked(page);
629 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
630
631 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip))
632 SetPageChecked(page);
633 return __set_page_dirty_buffers(page); 883 return __set_page_dirty_buffers(page);
634} 884}
635 885
@@ -653,7 +903,7 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
653 return 0; 903 return 0;
654 904
655 if (!gfs2_is_stuffed(ip)) 905 if (!gfs2_is_stuffed(ip))
656 dblock = generic_block_bmap(mapping, lblock, gfs2_get_block); 906 dblock = generic_block_bmap(mapping, lblock, gfs2_block_map);
657 907
658 gfs2_glock_dq_uninit(&i_gh); 908 gfs2_glock_dq_uninit(&i_gh);
659 909
@@ -719,13 +969,9 @@ static int gfs2_ok_for_dio(struct gfs2_inode *ip, int rw, loff_t offset)
719{ 969{
720 /* 970 /*
721 * Should we return an error here? I can't see that O_DIRECT for 971 * Should we return an error here? I can't see that O_DIRECT for
722 * a journaled file makes any sense. For now we'll silently fall 972 * a stuffed file makes any sense. For now we'll silently fall
723 * back to buffered I/O, likewise we do the same for stuffed 973 * back to buffered I/O
724 * files since they are (a) small and (b) unaligned.
725 */ 974 */
726 if (gfs2_is_jdata(ip))
727 return 0;
728
729 if (gfs2_is_stuffed(ip)) 975 if (gfs2_is_stuffed(ip))
730 return 0; 976 return 0;
731 977
@@ -836,9 +1082,23 @@ cannot_release:
836 return 0; 1082 return 0;
837} 1083}
838 1084
839const struct address_space_operations gfs2_file_aops = { 1085static const struct address_space_operations gfs2_writeback_aops = {
840 .writepage = gfs2_writepage, 1086 .writepage = gfs2_writeback_writepage,
841 .writepages = gfs2_writepages, 1087 .writepages = gfs2_writeback_writepages,
1088 .readpage = gfs2_readpage,
1089 .readpages = gfs2_readpages,
1090 .sync_page = block_sync_page,
1091 .write_begin = gfs2_write_begin,
1092 .write_end = gfs2_write_end,
1093 .bmap = gfs2_bmap,
1094 .invalidatepage = gfs2_invalidatepage,
1095 .releasepage = gfs2_releasepage,
1096 .direct_IO = gfs2_direct_IO,
1097 .migratepage = buffer_migrate_page,
1098};
1099
1100static const struct address_space_operations gfs2_ordered_aops = {
1101 .writepage = gfs2_ordered_writepage,
842 .readpage = gfs2_readpage, 1102 .readpage = gfs2_readpage,
843 .readpages = gfs2_readpages, 1103 .readpages = gfs2_readpages,
844 .sync_page = block_sync_page, 1104 .sync_page = block_sync_page,
@@ -849,5 +1109,34 @@ const struct address_space_operations gfs2_file_aops = {
849 .invalidatepage = gfs2_invalidatepage, 1109 .invalidatepage = gfs2_invalidatepage,
850 .releasepage = gfs2_releasepage, 1110 .releasepage = gfs2_releasepage,
851 .direct_IO = gfs2_direct_IO, 1111 .direct_IO = gfs2_direct_IO,
1112 .migratepage = buffer_migrate_page,
852}; 1113};
853 1114
1115static const struct address_space_operations gfs2_jdata_aops = {
1116 .writepage = gfs2_jdata_writepage,
1117 .writepages = gfs2_jdata_writepages,
1118 .readpage = gfs2_readpage,
1119 .readpages = gfs2_readpages,
1120 .sync_page = block_sync_page,
1121 .write_begin = gfs2_write_begin,
1122 .write_end = gfs2_write_end,
1123 .set_page_dirty = gfs2_set_page_dirty,
1124 .bmap = gfs2_bmap,
1125 .invalidatepage = gfs2_invalidatepage,
1126 .releasepage = gfs2_releasepage,
1127};
1128
1129void gfs2_set_aops(struct inode *inode)
1130{
1131 struct gfs2_inode *ip = GFS2_I(inode);
1132
1133 if (gfs2_is_writeback(ip))
1134 inode->i_mapping->a_ops = &gfs2_writeback_aops;
1135 else if (gfs2_is_ordered(ip))
1136 inode->i_mapping->a_ops = &gfs2_ordered_aops;
1137 else if (gfs2_is_jdata(ip))
1138 inode->i_mapping->a_ops = &gfs2_jdata_aops;
1139 else
1140 BUG();
1141}
1142
diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h
index fa1b5b3d28b9..5da21285bba4 100644
--- a/fs/gfs2/ops_address.h
+++ b/fs/gfs2/ops_address.h
@@ -14,9 +14,10 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16 16
17extern const struct address_space_operations gfs2_file_aops;
18extern int gfs2_get_block(struct inode *inode, sector_t lblock,
19 struct buffer_head *bh_result, int create);
20extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask); 17extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask);
18extern int gfs2_internal_read(struct gfs2_inode *ip,
19 struct file_ra_state *ra_state,
20 char *buf, loff_t *pos, unsigned size);
21extern void gfs2_set_aops(struct inode *inode);
21 22
22#endif /* __OPS_ADDRESS_DOT_H__ */ 23#endif /* __OPS_ADDRESS_DOT_H__ */
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index bb11fd6752d3..f4842f2548cd 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -33,57 +33,12 @@
33#include "lm.h" 33#include "lm.h"
34#include "log.h" 34#include "log.h"
35#include "meta_io.h" 35#include "meta_io.h"
36#include "ops_file.h"
37#include "ops_vm.h"
38#include "quota.h" 36#include "quota.h"
39#include "rgrp.h" 37#include "rgrp.h"
40#include "trans.h" 38#include "trans.h"
41#include "util.h" 39#include "util.h"
42#include "eaops.h" 40#include "eaops.h"
43 41#include "ops_address.h"
44/*
45 * Most fields left uninitialised to catch anybody who tries to
46 * use them. f_flags set to prevent file_accessed() from touching
47 * any other part of this. Its use is purely as a flag so that we
48 * know (in readpage()) whether or not do to locking.
49 */
50struct file gfs2_internal_file_sentinel = {
51 .f_flags = O_NOATIME|O_RDONLY,
52};
53
54static int gfs2_read_actor(read_descriptor_t *desc, struct page *page,
55 unsigned long offset, unsigned long size)
56{
57 char *kaddr;
58 unsigned long count = desc->count;
59
60 if (size > count)
61 size = count;
62
63 kaddr = kmap(page);
64 memcpy(desc->arg.data, kaddr + offset, size);
65 kunmap(page);
66
67 desc->count = count - size;
68 desc->written += size;
69 desc->arg.buf += size;
70 return size;
71}
72
73int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
74 char *buf, loff_t *pos, unsigned size)
75{
76 struct inode *inode = &ip->i_inode;
77 read_descriptor_t desc;
78 desc.written = 0;
79 desc.arg.data = buf;
80 desc.count = size;
81 desc.error = 0;
82 do_generic_mapping_read(inode->i_mapping, ra_state,
83 &gfs2_internal_file_sentinel, pos, &desc,
84 gfs2_read_actor);
85 return desc.written ? desc.written : desc.error;
86}
87 42
88/** 43/**
89 * gfs2_llseek - seek to a location in a file 44 * gfs2_llseek - seek to a location in a file
@@ -214,7 +169,7 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
214 if (put_user(fsflags, ptr)) 169 if (put_user(fsflags, ptr))
215 error = -EFAULT; 170 error = -EFAULT;
216 171
217 gfs2_glock_dq_m(1, &gh); 172 gfs2_glock_dq(&gh);
218 gfs2_holder_uninit(&gh); 173 gfs2_holder_uninit(&gh);
219 return error; 174 return error;
220} 175}
@@ -291,7 +246,16 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
291 if (error) 246 if (error)
292 goto out; 247 goto out;
293 } 248 }
294 249 if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
250 if (flags & GFS2_DIF_JDATA)
251 gfs2_log_flush(sdp, ip->i_gl);
252 error = filemap_fdatawrite(inode->i_mapping);
253 if (error)
254 goto out;
255 error = filemap_fdatawait(inode->i_mapping);
256 if (error)
257 goto out;
258 }
295 error = gfs2_trans_begin(sdp, RES_DINODE, 0); 259 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
296 if (error) 260 if (error)
297 goto out; 261 goto out;
@@ -303,6 +267,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
303 gfs2_dinode_out(ip, bh->b_data); 267 gfs2_dinode_out(ip, bh->b_data);
304 brelse(bh); 268 brelse(bh);
305 gfs2_set_inode_flags(inode); 269 gfs2_set_inode_flags(inode);
270 gfs2_set_aops(inode);
306out_trans_end: 271out_trans_end:
307 gfs2_trans_end(sdp); 272 gfs2_trans_end(sdp);
308out: 273out:
@@ -338,6 +303,128 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
338 return -ENOTTY; 303 return -ENOTTY;
339} 304}
340 305
306/**
307 * gfs2_allocate_page_backing - Use bmap to allocate blocks
308 * @page: The (locked) page to allocate backing for
309 *
310 * We try to allocate all the blocks required for the page in
311 * one go. This might fail for various reasons, so we keep
312 * trying until all the blocks to back this page are allocated.
313 * If some of the blocks are already allocated, thats ok too.
314 */
315
316static int gfs2_allocate_page_backing(struct page *page)
317{
318 struct inode *inode = page->mapping->host;
319 struct buffer_head bh;
320 unsigned long size = PAGE_CACHE_SIZE;
321 u64 lblock = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
322
323 do {
324 bh.b_state = 0;
325 bh.b_size = size;
326 gfs2_block_map(inode, lblock, &bh, 1);
327 if (!buffer_mapped(&bh))
328 return -EIO;
329 size -= bh.b_size;
330 lblock += (bh.b_size >> inode->i_blkbits);
331 } while(size > 0);
332 return 0;
333}
334
335/**
336 * gfs2_page_mkwrite - Make a shared, mmap()ed, page writable
337 * @vma: The virtual memory area
338 * @page: The page which is about to become writable
339 *
340 * When the page becomes writable, we need to ensure that we have
341 * blocks allocated on disk to back that page.
342 */
343
344static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page)
345{
346 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
347 struct gfs2_inode *ip = GFS2_I(inode);
348 struct gfs2_sbd *sdp = GFS2_SB(inode);
349 unsigned long last_index;
350 u64 pos = page->index << (PAGE_CACHE_SIZE - inode->i_blkbits);
351 unsigned int data_blocks, ind_blocks, rblocks;
352 int alloc_required = 0;
353 struct gfs2_holder gh;
354 struct gfs2_alloc *al;
355 int ret;
356
357 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME, &gh);
358 ret = gfs2_glock_nq_atime(&gh);
359 if (ret)
360 goto out;
361
362 set_bit(GIF_SW_PAGED, &ip->i_flags);
363 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
364 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
365 if (ret || !alloc_required)
366 goto out_unlock;
367 ret = -ENOMEM;
368 al = gfs2_alloc_get(ip);
369 if (al == NULL)
370 goto out_unlock;
371
372 ret = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
373 if (ret)
374 goto out_alloc_put;
375 ret = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid);
376 if (ret)
377 goto out_quota_unlock;
378 al->al_requested = data_blocks + ind_blocks;
379 ret = gfs2_inplace_reserve(ip);
380 if (ret)
381 goto out_quota_unlock;
382
383 rblocks = RES_DINODE + ind_blocks;
384 if (gfs2_is_jdata(ip))
385 rblocks += data_blocks ? data_blocks : 1;
386 if (ind_blocks || data_blocks)
387 rblocks += RES_STATFS + RES_QUOTA;
388 ret = gfs2_trans_begin(sdp, rblocks, 0);
389 if (ret)
390 goto out_trans_fail;
391
392 lock_page(page);
393 ret = -EINVAL;
394 last_index = ip->i_inode.i_size >> PAGE_CACHE_SHIFT;
395 if (page->index > last_index)
396 goto out_unlock_page;
397 ret = 0;
398 if (!PageUptodate(page) || page->mapping != ip->i_inode.i_mapping)
399 goto out_unlock_page;
400 if (gfs2_is_stuffed(ip)) {
401 ret = gfs2_unstuff_dinode(ip, page);
402 if (ret)
403 goto out_unlock_page;
404 }
405 ret = gfs2_allocate_page_backing(page);
406
407out_unlock_page:
408 unlock_page(page);
409 gfs2_trans_end(sdp);
410out_trans_fail:
411 gfs2_inplace_release(ip);
412out_quota_unlock:
413 gfs2_quota_unlock(ip);
414out_alloc_put:
415 gfs2_alloc_put(ip);
416out_unlock:
417 gfs2_glock_dq(&gh);
418out:
419 gfs2_holder_uninit(&gh);
420 return ret;
421}
422
423static struct vm_operations_struct gfs2_vm_ops = {
424 .fault = filemap_fault,
425 .page_mkwrite = gfs2_page_mkwrite,
426};
427
341 428
342/** 429/**
343 * gfs2_mmap - 430 * gfs2_mmap -
@@ -360,14 +447,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
360 return error; 447 return error;
361 } 448 }
362 449
363 /* This is VM_MAYWRITE instead of VM_WRITE because a call 450 vma->vm_ops = &gfs2_vm_ops;
364 to mprotect() can turn on VM_WRITE later. */
365
366 if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) ==
367 (VM_MAYSHARE | VM_MAYWRITE))
368 vma->vm_ops = &gfs2_vm_ops_sharewrite;
369 else
370 vma->vm_ops = &gfs2_vm_ops_private;
371 451
372 gfs2_glock_dq_uninit(&i_gh); 452 gfs2_glock_dq_uninit(&i_gh);
373 453
@@ -538,15 +618,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
538 if (__mandatory_lock(&ip->i_inode)) 618 if (__mandatory_lock(&ip->i_inode))
539 return -ENOLCK; 619 return -ENOLCK;
540 620
541 if (sdp->sd_args.ar_localflocks) {
542 if (IS_GETLK(cmd)) {
543 posix_test_lock(file, fl);
544 return 0;
545 } else {
546 return posix_lock_file_wait(file, fl);
547 }
548 }
549
550 if (cmd == F_CANCELLK) { 621 if (cmd == F_CANCELLK) {
551 /* Hack: */ 622 /* Hack: */
552 cmd = F_SETLK; 623 cmd = F_SETLK;
@@ -632,16 +703,12 @@ static void do_unflock(struct file *file, struct file_lock *fl)
632static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) 703static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
633{ 704{
634 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 705 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
635 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
636 706
637 if (!(fl->fl_flags & FL_FLOCK)) 707 if (!(fl->fl_flags & FL_FLOCK))
638 return -ENOLCK; 708 return -ENOLCK;
639 if (__mandatory_lock(&ip->i_inode)) 709 if (__mandatory_lock(&ip->i_inode))
640 return -ENOLCK; 710 return -ENOLCK;
641 711
642 if (sdp->sd_args.ar_localflocks)
643 return flock_lock_file_wait(file, fl);
644
645 if (fl->fl_type == F_UNLCK) { 712 if (fl->fl_type == F_UNLCK) {
646 do_unflock(file, fl); 713 do_unflock(file, fl);
647 return 0; 714 return 0;
@@ -678,3 +745,27 @@ const struct file_operations gfs2_dir_fops = {
678 .flock = gfs2_flock, 745 .flock = gfs2_flock,
679}; 746};
680 747
748const struct file_operations gfs2_file_fops_nolock = {
749 .llseek = gfs2_llseek,
750 .read = do_sync_read,
751 .aio_read = generic_file_aio_read,
752 .write = do_sync_write,
753 .aio_write = generic_file_aio_write,
754 .unlocked_ioctl = gfs2_ioctl,
755 .mmap = gfs2_mmap,
756 .open = gfs2_open,
757 .release = gfs2_close,
758 .fsync = gfs2_fsync,
759 .splice_read = generic_file_splice_read,
760 .splice_write = generic_file_splice_write,
761 .setlease = gfs2_setlease,
762};
763
764const struct file_operations gfs2_dir_fops_nolock = {
765 .readdir = gfs2_readdir,
766 .unlocked_ioctl = gfs2_ioctl,
767 .open = gfs2_open,
768 .release = gfs2_close,
769 .fsync = gfs2_fsync,
770};
771
diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h
deleted file mode 100644
index 7e5d8ec9c846..000000000000
--- a/fs/gfs2/ops_file.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __OPS_FILE_DOT_H__
11#define __OPS_FILE_DOT_H__
12
13#include <linux/fs.h>
14struct gfs2_inode;
15
16extern struct file gfs2_internal_file_sentinel;
17extern int gfs2_internal_read(struct gfs2_inode *ip,
18 struct file_ra_state *ra_state,
19 char *buf, loff_t *pos, unsigned size);
20extern void gfs2_set_inode_flags(struct inode *inode);
21extern const struct file_operations gfs2_file_fops;
22extern const struct file_operations gfs2_dir_fops;
23
24#endif /* __OPS_FILE_DOT_H__ */
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 17de58e83d92..43d511bba52d 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -21,6 +21,7 @@
21 21
22#include "gfs2.h" 22#include "gfs2.h"
23#include "incore.h" 23#include "incore.h"
24#include "bmap.h"
24#include "daemon.h" 25#include "daemon.h"
25#include "glock.h" 26#include "glock.h"
26#include "glops.h" 27#include "glops.h"
@@ -59,7 +60,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
59 60
60 mutex_init(&sdp->sd_inum_mutex); 61 mutex_init(&sdp->sd_inum_mutex);
61 spin_lock_init(&sdp->sd_statfs_spin); 62 spin_lock_init(&sdp->sd_statfs_spin);
62 mutex_init(&sdp->sd_statfs_mutex);
63 63
64 spin_lock_init(&sdp->sd_rindex_spin); 64 spin_lock_init(&sdp->sd_rindex_spin);
65 mutex_init(&sdp->sd_rindex_mutex); 65 mutex_init(&sdp->sd_rindex_mutex);
@@ -77,7 +77,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
77 77
78 spin_lock_init(&sdp->sd_log_lock); 78 spin_lock_init(&sdp->sd_log_lock);
79 79
80 INIT_LIST_HEAD(&sdp->sd_log_le_gl);
81 INIT_LIST_HEAD(&sdp->sd_log_le_buf); 80 INIT_LIST_HEAD(&sdp->sd_log_le_buf);
82 INIT_LIST_HEAD(&sdp->sd_log_le_revoke); 81 INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
83 INIT_LIST_HEAD(&sdp->sd_log_le_rg); 82 INIT_LIST_HEAD(&sdp->sd_log_le_rg);
@@ -303,6 +302,67 @@ out:
303 return error; 302 return error;
304} 303}
305 304
305/**
306 * map_journal_extents - create a reusable "extent" mapping from all logical
307 * blocks to all physical blocks for the given journal. This will save
308 * us time when writing journal blocks. Most journals will have only one
309 * extent that maps all their logical blocks. That's because gfs2.mkfs
310 * arranges the journal blocks sequentially to maximize performance.
311 * So the extent would map the first block for the entire file length.
312 * However, gfs2_jadd can happen while file activity is happening, so
313 * those journals may not be sequential. Less likely is the case where
314 * the users created their own journals by mounting the metafs and
315 * laying it out. But it's still possible. These journals might have
316 * several extents.
317 *
318 * TODO: This should be done in bigger chunks rather than one block at a time,
319 * but since it's only done at mount time, I'm not worried about the
320 * time it takes.
321 */
322static int map_journal_extents(struct gfs2_sbd *sdp)
323{
324 struct gfs2_jdesc *jd = sdp->sd_jdesc;
325 unsigned int lb;
326 u64 db, prev_db; /* logical block, disk block, prev disk block */
327 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
328 struct gfs2_journal_extent *jext = NULL;
329 struct buffer_head bh;
330 int rc = 0;
331
332 prev_db = 0;
333
334 for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) {
335 bh.b_state = 0;
336 bh.b_blocknr = 0;
337 bh.b_size = 1 << ip->i_inode.i_blkbits;
338 rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
339 db = bh.b_blocknr;
340 if (rc || !db) {
341 printk(KERN_INFO "GFS2 journal mapping error %d: lb="
342 "%u db=%llu\n", rc, lb, (unsigned long long)db);
343 break;
344 }
345 if (!prev_db || db != prev_db + 1) {
346 jext = kzalloc(sizeof(struct gfs2_journal_extent),
347 GFP_KERNEL);
348 if (!jext) {
349 printk(KERN_INFO "GFS2 error: out of memory "
350 "mapping journal extents.\n");
351 rc = -ENOMEM;
352 break;
353 }
354 jext->dblock = db;
355 jext->lblock = lb;
356 jext->blocks = 1;
357 list_add_tail(&jext->extent_list, &jd->extent_list);
358 } else {
359 jext->blocks++;
360 }
361 prev_db = db;
362 }
363 return rc;
364}
365
306static int init_journal(struct gfs2_sbd *sdp, int undo) 366static int init_journal(struct gfs2_sbd *sdp, int undo)
307{ 367{
308 struct gfs2_holder ji_gh; 368 struct gfs2_holder ji_gh;
@@ -340,7 +400,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
340 400
341 if (sdp->sd_args.ar_spectator) { 401 if (sdp->sd_args.ar_spectator) {
342 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); 402 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
343 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; 403 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
344 } else { 404 } else {
345 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { 405 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
346 fs_err(sdp, "can't mount journal #%u\n", 406 fs_err(sdp, "can't mount journal #%u\n",
@@ -377,7 +437,10 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
377 sdp->sd_jdesc->jd_jid, error); 437 sdp->sd_jdesc->jd_jid, error);
378 goto fail_jinode_gh; 438 goto fail_jinode_gh;
379 } 439 }
380 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; 440 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
441
442 /* Map the extents for this journal's blocks */
443 map_journal_extents(sdp);
381 } 444 }
382 445
383 if (sdp->sd_lockstruct.ls_first) { 446 if (sdp->sd_lockstruct.ls_first) {
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 291f0c7eaa3b..9f71372c1757 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -61,7 +61,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
61 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); 61 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
62 if (!IS_ERR(inode)) { 62 if (!IS_ERR(inode)) {
63 gfs2_trans_end(sdp); 63 gfs2_trans_end(sdp);
64 if (dip->i_alloc.al_rgd) 64 if (dip->i_alloc->al_rgd)
65 gfs2_inplace_release(dip); 65 gfs2_inplace_release(dip);
66 gfs2_quota_unlock(dip); 66 gfs2_quota_unlock(dip);
67 gfs2_alloc_put(dip); 67 gfs2_alloc_put(dip);
@@ -113,8 +113,18 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
113 if (inode && IS_ERR(inode)) 113 if (inode && IS_ERR(inode))
114 return ERR_PTR(PTR_ERR(inode)); 114 return ERR_PTR(PTR_ERR(inode));
115 115
116 if (inode) 116 if (inode) {
117 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
118 struct gfs2_holder gh;
119 int error;
120 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
121 if (error) {
122 iput(inode);
123 return ERR_PTR(error);
124 }
125 gfs2_glock_dq_uninit(&gh);
117 return d_splice_alias(inode, dentry); 126 return d_splice_alias(inode, dentry);
127 }
118 d_add(dentry, inode); 128 d_add(dentry, inode);
119 129
120 return NULL; 130 return NULL;
@@ -366,7 +376,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
366 } 376 }
367 377
368 gfs2_trans_end(sdp); 378 gfs2_trans_end(sdp);
369 if (dip->i_alloc.al_rgd) 379 if (dip->i_alloc->al_rgd)
370 gfs2_inplace_release(dip); 380 gfs2_inplace_release(dip);
371 gfs2_quota_unlock(dip); 381 gfs2_quota_unlock(dip);
372 gfs2_alloc_put(dip); 382 gfs2_alloc_put(dip);
@@ -442,7 +452,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
442 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ 452 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
443 453
444 gfs2_trans_end(sdp); 454 gfs2_trans_end(sdp);
445 if (dip->i_alloc.al_rgd) 455 if (dip->i_alloc->al_rgd)
446 gfs2_inplace_release(dip); 456 gfs2_inplace_release(dip);
447 gfs2_quota_unlock(dip); 457 gfs2_quota_unlock(dip);
448 gfs2_alloc_put(dip); 458 gfs2_alloc_put(dip);
@@ -548,7 +558,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
548 } 558 }
549 559
550 gfs2_trans_end(sdp); 560 gfs2_trans_end(sdp);
551 if (dip->i_alloc.al_rgd) 561 if (dip->i_alloc->al_rgd)
552 gfs2_inplace_release(dip); 562 gfs2_inplace_release(dip);
553 gfs2_quota_unlock(dip); 563 gfs2_quota_unlock(dip);
554 gfs2_alloc_put(dip); 564 gfs2_alloc_put(dip);
diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h
index 34f0caac1a03..fd8cee231e1d 100644
--- a/fs/gfs2/ops_inode.h
+++ b/fs/gfs2/ops_inode.h
@@ -16,5 +16,11 @@ extern const struct inode_operations gfs2_file_iops;
16extern const struct inode_operations gfs2_dir_iops; 16extern const struct inode_operations gfs2_dir_iops;
17extern const struct inode_operations gfs2_symlink_iops; 17extern const struct inode_operations gfs2_symlink_iops;
18extern const struct inode_operations gfs2_dev_iops; 18extern const struct inode_operations gfs2_dev_iops;
19extern const struct file_operations gfs2_file_fops;
20extern const struct file_operations gfs2_dir_fops;
21extern const struct file_operations gfs2_file_fops_nolock;
22extern const struct file_operations gfs2_dir_fops_nolock;
23
24extern void gfs2_set_inode_flags(struct inode *inode);
19 25
20#endif /* __OPS_INODE_DOT_H__ */ 26#endif /* __OPS_INODE_DOT_H__ */
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
index 950f31460e8b..5e524217944a 100644
--- a/fs/gfs2/ops_super.c
+++ b/fs/gfs2/ops_super.c
@@ -487,7 +487,6 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
487 if (ip) { 487 if (ip) {
488 ip->i_flags = 0; 488 ip->i_flags = 0;
489 ip->i_gl = NULL; 489 ip->i_gl = NULL;
490 ip->i_last_pfault = jiffies;
491 } 490 }
492 return &ip->i_inode; 491 return &ip->i_inode;
493} 492}
diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c
deleted file mode 100644
index 927d739d4685..000000000000
--- a/fs/gfs2/ops_vm.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18
19#include "gfs2.h"
20#include "incore.h"
21#include "bmap.h"
22#include "glock.h"
23#include "inode.h"
24#include "ops_vm.h"
25#include "quota.h"
26#include "rgrp.h"
27#include "trans.h"
28#include "util.h"
29
30static int gfs2_private_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
31{
32 struct gfs2_inode *ip = GFS2_I(vma->vm_file->f_mapping->host);
33
34 set_bit(GIF_PAGED, &ip->i_flags);
35 return filemap_fault(vma, vmf);
36}
37
38static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
39{
40 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
41 unsigned long index = page->index;
42 u64 lblock = index << (PAGE_CACHE_SHIFT -
43 sdp->sd_sb.sb_bsize_shift);
44 unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift;
45 struct gfs2_alloc *al;
46 unsigned int data_blocks, ind_blocks;
47 unsigned int x;
48 int error;
49
50 al = gfs2_alloc_get(ip);
51
52 error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
53 if (error)
54 goto out;
55
56 error = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid);
57 if (error)
58 goto out_gunlock_q;
59
60 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
61
62 al->al_requested = data_blocks + ind_blocks;
63
64 error = gfs2_inplace_reserve(ip);
65 if (error)
66 goto out_gunlock_q;
67
68 error = gfs2_trans_begin(sdp, al->al_rgd->rd_length +
69 ind_blocks + RES_DINODE +
70 RES_STATFS + RES_QUOTA, 0);
71 if (error)
72 goto out_ipres;
73
74 if (gfs2_is_stuffed(ip)) {
75 error = gfs2_unstuff_dinode(ip, NULL);
76 if (error)
77 goto out_trans;
78 }
79
80 for (x = 0; x < blocks; ) {
81 u64 dblock;
82 unsigned int extlen;
83 int new = 1;
84
85 error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
86 if (error)
87 goto out_trans;
88
89 lblock += extlen;
90 x += extlen;
91 }
92
93 gfs2_assert_warn(sdp, al->al_alloced);
94
95out_trans:
96 gfs2_trans_end(sdp);
97out_ipres:
98 gfs2_inplace_release(ip);
99out_gunlock_q:
100 gfs2_quota_unlock(ip);
101out:
102 gfs2_alloc_put(ip);
103 return error;
104}
105
106static int gfs2_sharewrite_fault(struct vm_area_struct *vma,
107 struct vm_fault *vmf)
108{
109 struct file *file = vma->vm_file;
110 struct gfs2_file *gf = file->private_data;
111 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
112 struct gfs2_holder i_gh;
113 int alloc_required;
114 int error;
115 int ret = 0;
116
117 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
118 if (error)
119 goto out;
120
121 set_bit(GIF_PAGED, &ip->i_flags);
122 set_bit(GIF_SW_PAGED, &ip->i_flags);
123
124 error = gfs2_write_alloc_required(ip,
125 (u64)vmf->pgoff << PAGE_CACHE_SHIFT,
126 PAGE_CACHE_SIZE, &alloc_required);
127 if (error) {
128 ret = VM_FAULT_OOM; /* XXX: are these right? */
129 goto out_unlock;
130 }
131
132 set_bit(GFF_EXLOCK, &gf->f_flags);
133 ret = filemap_fault(vma, vmf);
134 clear_bit(GFF_EXLOCK, &gf->f_flags);
135 if (ret & VM_FAULT_ERROR)
136 goto out_unlock;
137
138 if (alloc_required) {
139 /* XXX: do we need to drop page lock around alloc_page_backing?*/
140 error = alloc_page_backing(ip, vmf->page);
141 if (error) {
142 /*
143 * VM_FAULT_LOCKED should always be the case for
144 * filemap_fault, but it may not be in a future
145 * implementation.
146 */
147 if (ret & VM_FAULT_LOCKED)
148 unlock_page(vmf->page);
149 page_cache_release(vmf->page);
150 ret = VM_FAULT_OOM;
151 goto out_unlock;
152 }
153 set_page_dirty(vmf->page);
154 }
155
156out_unlock:
157 gfs2_glock_dq_uninit(&i_gh);
158out:
159 return ret;
160}
161
162struct vm_operations_struct gfs2_vm_ops_private = {
163 .fault = gfs2_private_fault,
164};
165
166struct vm_operations_struct gfs2_vm_ops_sharewrite = {
167 .fault = gfs2_sharewrite_fault,
168};
169
diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h
deleted file mode 100644
index 4ae8f43ed5e3..000000000000
--- a/fs/gfs2/ops_vm.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __OPS_VM_DOT_H__
11#define __OPS_VM_DOT_H__
12
13#include <linux/mm.h>
14
15extern struct vm_operations_struct gfs2_vm_ops_private;
16extern struct vm_operations_struct gfs2_vm_ops_sharewrite;
17
18#endif /* __OPS_VM_DOT_H__ */
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index addb51e0f135..a08dabd6ce90 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -59,7 +59,6 @@
59#include "super.h" 59#include "super.h"
60#include "trans.h" 60#include "trans.h"
61#include "inode.h" 61#include "inode.h"
62#include "ops_file.h"
63#include "ops_address.h" 62#include "ops_address.h"
64#include "util.h" 63#include "util.h"
65 64
@@ -274,10 +273,10 @@ static int bh_get(struct gfs2_quota_data *qd)
274 } 273 }
275 274
276 block = qd->qd_slot / sdp->sd_qc_per_block; 275 block = qd->qd_slot / sdp->sd_qc_per_block;
277 offset = qd->qd_slot % sdp->sd_qc_per_block;; 276 offset = qd->qd_slot % sdp->sd_qc_per_block;
278 277
279 bh_map.b_size = 1 << ip->i_inode.i_blkbits; 278 bh_map.b_size = 1 << ip->i_inode.i_blkbits;
280 error = gfs2_block_map(&ip->i_inode, block, 0, &bh_map); 279 error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0);
281 if (error) 280 if (error)
282 goto fail; 281 goto fail;
283 error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh); 282 error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh);
@@ -454,7 +453,7 @@ static void qdsb_put(struct gfs2_quota_data *qd)
454int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) 453int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
455{ 454{
456 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 455 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
457 struct gfs2_alloc *al = &ip->i_alloc; 456 struct gfs2_alloc *al = ip->i_alloc;
458 struct gfs2_quota_data **qd = al->al_qd; 457 struct gfs2_quota_data **qd = al->al_qd;
459 int error; 458 int error;
460 459
@@ -502,7 +501,7 @@ out:
502void gfs2_quota_unhold(struct gfs2_inode *ip) 501void gfs2_quota_unhold(struct gfs2_inode *ip)
503{ 502{
504 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 503 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
505 struct gfs2_alloc *al = &ip->i_alloc; 504 struct gfs2_alloc *al = ip->i_alloc;
506 unsigned int x; 505 unsigned int x;
507 506
508 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); 507 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
@@ -646,7 +645,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
646 } 645 }
647 646
648 if (!buffer_mapped(bh)) { 647 if (!buffer_mapped(bh)) {
649 gfs2_get_block(inode, iblock, bh, 1); 648 gfs2_block_map(inode, iblock, bh, 1);
650 if (!buffer_mapped(bh)) 649 if (!buffer_mapped(bh))
651 goto unlock; 650 goto unlock;
652 } 651 }
@@ -793,11 +792,9 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
793 struct gfs2_holder i_gh; 792 struct gfs2_holder i_gh;
794 struct gfs2_quota_host q; 793 struct gfs2_quota_host q;
795 char buf[sizeof(struct gfs2_quota)]; 794 char buf[sizeof(struct gfs2_quota)];
796 struct file_ra_state ra_state;
797 int error; 795 int error;
798 struct gfs2_quota_lvb *qlvb; 796 struct gfs2_quota_lvb *qlvb;
799 797
800 file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping);
801restart: 798restart:
802 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); 799 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh);
803 if (error) 800 if (error)
@@ -820,8 +817,8 @@ restart:
820 817
821 memset(buf, 0, sizeof(struct gfs2_quota)); 818 memset(buf, 0, sizeof(struct gfs2_quota));
822 pos = qd2offset(qd); 819 pos = qd2offset(qd);
823 error = gfs2_internal_read(ip, &ra_state, buf, 820 error = gfs2_internal_read(ip, NULL, buf, &pos,
824 &pos, sizeof(struct gfs2_quota)); 821 sizeof(struct gfs2_quota));
825 if (error < 0) 822 if (error < 0)
826 goto fail_gunlock; 823 goto fail_gunlock;
827 824
@@ -856,7 +853,7 @@ fail:
856int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) 853int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
857{ 854{
858 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 855 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
859 struct gfs2_alloc *al = &ip->i_alloc; 856 struct gfs2_alloc *al = ip->i_alloc;
860 unsigned int x; 857 unsigned int x;
861 int error = 0; 858 int error = 0;
862 859
@@ -924,7 +921,7 @@ static int need_sync(struct gfs2_quota_data *qd)
924 921
925void gfs2_quota_unlock(struct gfs2_inode *ip) 922void gfs2_quota_unlock(struct gfs2_inode *ip)
926{ 923{
927 struct gfs2_alloc *al = &ip->i_alloc; 924 struct gfs2_alloc *al = ip->i_alloc;
928 struct gfs2_quota_data *qda[4]; 925 struct gfs2_quota_data *qda[4];
929 unsigned int count = 0; 926 unsigned int count = 0;
930 unsigned int x; 927 unsigned int x;
@@ -972,7 +969,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
972int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) 969int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
973{ 970{
974 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 971 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
975 struct gfs2_alloc *al = &ip->i_alloc; 972 struct gfs2_alloc *al = ip->i_alloc;
976 struct gfs2_quota_data *qd; 973 struct gfs2_quota_data *qd;
977 s64 value; 974 s64 value;
978 unsigned int x; 975 unsigned int x;
@@ -1016,10 +1013,9 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1016void gfs2_quota_change(struct gfs2_inode *ip, s64 change, 1013void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1017 u32 uid, u32 gid) 1014 u32 uid, u32 gid)
1018{ 1015{
1019 struct gfs2_alloc *al = &ip->i_alloc; 1016 struct gfs2_alloc *al = ip->i_alloc;
1020 struct gfs2_quota_data *qd; 1017 struct gfs2_quota_data *qd;
1021 unsigned int x; 1018 unsigned int x;
1022 unsigned int found = 0;
1023 1019
1024 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change)) 1020 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
1025 return; 1021 return;
@@ -1032,7 +1028,6 @@ void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1032 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1028 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1033 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) { 1029 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
1034 do_qc(qd, change); 1030 do_qc(qd, change);
1035 found++;
1036 } 1031 }
1037 } 1032 }
1038} 1033}
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index beb6c7ac0086..b249e294a95b 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -391,7 +391,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header_host *hea
391 lblock = head->lh_blkno; 391 lblock = head->lh_blkno;
392 gfs2_replay_incr_blk(sdp, &lblock); 392 gfs2_replay_incr_blk(sdp, &lblock);
393 bh_map.b_size = 1 << ip->i_inode.i_blkbits; 393 bh_map.b_size = 1 << ip->i_inode.i_blkbits;
394 error = gfs2_block_map(&ip->i_inode, lblock, 0, &bh_map); 394 error = gfs2_block_map(&ip->i_inode, lblock, &bh_map, 0);
395 if (error) 395 if (error)
396 return error; 396 return error;
397 if (!bh_map.b_blocknr) { 397 if (!bh_map.b_blocknr) {
@@ -504,13 +504,21 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
504 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) 504 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
505 ro = 1; 505 ro = 1;
506 } else { 506 } else {
507 if (sdp->sd_vfs->s_flags & MS_RDONLY) 507 if (sdp->sd_vfs->s_flags & MS_RDONLY) {
508 ro = 1; 508 /* check if device itself is read-only */
509 ro = bdev_read_only(sdp->sd_vfs->s_bdev);
510 if (!ro) {
511 fs_info(sdp, "recovery required on "
512 "read-only filesystem.\n");
513 fs_info(sdp, "write access will be "
514 "enabled during recovery.\n");
515 }
516 }
509 } 517 }
510 518
511 if (ro) { 519 if (ro) {
512 fs_warn(sdp, "jid=%u: Can't replay: read-only FS\n", 520 fs_warn(sdp, "jid=%u: Can't replay: read-only block "
513 jd->jd_jid); 521 "device\n", jd->jd_jid);
514 error = -EROFS; 522 error = -EROFS;
515 goto fail_gunlock_tr; 523 goto fail_gunlock_tr;
516 } 524 }
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 708c287e1d0e..3552110b2e5f 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -25,10 +25,10 @@
25#include "rgrp.h" 25#include "rgrp.h"
26#include "super.h" 26#include "super.h"
27#include "trans.h" 27#include "trans.h"
28#include "ops_file.h"
29#include "util.h" 28#include "util.h"
30#include "log.h" 29#include "log.h"
31#include "inode.h" 30#include "inode.h"
31#include "ops_address.h"
32 32
33#define BFITNOENT ((u32)~0) 33#define BFITNOENT ((u32)~0)
34#define NO_BLOCK ((u64)~0) 34#define NO_BLOCK ((u64)~0)
@@ -126,41 +126,43 @@ static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer,
126 * Return: the block number (bitmap buffer scope) that was found 126 * Return: the block number (bitmap buffer scope) that was found
127 */ 127 */
128 128
129static u32 gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, 129static u32 gfs2_bitfit(unsigned char *buffer, unsigned int buflen, u32 goal,
130 unsigned int buflen, u32 goal, 130 unsigned char old_state)
131 unsigned char old_state)
132{ 131{
133 unsigned char *byte, *end, alloc; 132 unsigned char *byte;
134 u32 blk = goal; 133 u32 blk = goal;
135 unsigned int bit; 134 unsigned int bit, bitlong;
135 unsigned long *plong, plong55;
136 136
137 byte = buffer + (goal / GFS2_NBBY); 137 byte = buffer + (goal / GFS2_NBBY);
138 plong = (unsigned long *)(buffer + (goal / GFS2_NBBY));
138 bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; 139 bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE;
139 end = buffer + buflen; 140 bitlong = bit;
140 alloc = (old_state == GFS2_BLKST_FREE) ? 0x55 : 0; 141#if BITS_PER_LONG == 32
141 142 plong55 = 0x55555555;
142 while (byte < end) { 143#else
143 /* If we're looking for a free block we can eliminate all 144 plong55 = 0x5555555555555555;
144 bitmap settings with 0x55, which represents four data 145#endif
145 blocks in a row. If we're looking for a data block, we can 146 while (byte < buffer + buflen) {
146 eliminate 0x00 which corresponds to four free blocks. */ 147
147 if ((*byte & 0x55) == alloc) { 148 if (bitlong == 0 && old_state == 0 && *plong == plong55) {
148 blk += (8 - bit) >> 1; 149 plong++;
149 150 byte += sizeof(unsigned long);
150 bit = 0; 151 blk += sizeof(unsigned long) * GFS2_NBBY;
151 byte++;
152
153 continue; 152 continue;
154 } 153 }
155
156 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) 154 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state)
157 return blk; 155 return blk;
158
159 bit += GFS2_BIT_SIZE; 156 bit += GFS2_BIT_SIZE;
160 if (bit >= 8) { 157 if (bit >= 8) {
161 bit = 0; 158 bit = 0;
162 byte++; 159 byte++;
163 } 160 }
161 bitlong += GFS2_BIT_SIZE;
162 if (bitlong >= sizeof(unsigned long) * 8) {
163 bitlong = 0;
164 plong++;
165 }
164 166
165 blk++; 167 blk++;
166 } 168 }
@@ -817,11 +819,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
817 819
818struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip) 820struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip)
819{ 821{
820 struct gfs2_alloc *al = &ip->i_alloc; 822 BUG_ON(ip->i_alloc != NULL);
821 823 ip->i_alloc = kzalloc(sizeof(struct gfs2_alloc), GFP_KERNEL);
822 /* FIXME: Should assert that the correct locks are held here... */ 824 return ip->i_alloc;
823 memset(al, 0, sizeof(*al));
824 return al;
825} 825}
826 826
827/** 827/**
@@ -1059,26 +1059,34 @@ static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1059 struct inode *inode = NULL; 1059 struct inode *inode = NULL;
1060 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1060 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1061 struct gfs2_rgrpd *rgd, *begin = NULL; 1061 struct gfs2_rgrpd *rgd, *begin = NULL;
1062 struct gfs2_alloc *al = &ip->i_alloc; 1062 struct gfs2_alloc *al = ip->i_alloc;
1063 int flags = LM_FLAG_TRY; 1063 int flags = LM_FLAG_TRY;
1064 int skipped = 0; 1064 int skipped = 0;
1065 int loops = 0; 1065 int loops = 0;
1066 int error; 1066 int error, rg_locked;
1067 1067
1068 /* Try recently successful rgrps */ 1068 /* Try recently successful rgrps */
1069 1069
1070 rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc); 1070 rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc);
1071 1071
1072 while (rgd) { 1072 while (rgd) {
1073 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 1073 rg_locked = 0;
1074 LM_FLAG_TRY, &al->al_rgd_gh); 1074
1075 if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
1076 rg_locked = 1;
1077 error = 0;
1078 } else {
1079 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
1080 LM_FLAG_TRY, &al->al_rgd_gh);
1081 }
1075 switch (error) { 1082 switch (error) {
1076 case 0: 1083 case 0:
1077 if (try_rgrp_fit(rgd, al)) 1084 if (try_rgrp_fit(rgd, al))
1078 goto out; 1085 goto out;
1079 if (rgd->rd_flags & GFS2_RDF_CHECK) 1086 if (rgd->rd_flags & GFS2_RDF_CHECK)
1080 inode = try_rgrp_unlink(rgd, last_unlinked); 1087 inode = try_rgrp_unlink(rgd, last_unlinked);
1081 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1088 if (!rg_locked)
1089 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1082 if (inode) 1090 if (inode)
1083 return inode; 1091 return inode;
1084 rgd = recent_rgrp_next(rgd, 1); 1092 rgd = recent_rgrp_next(rgd, 1);
@@ -1098,15 +1106,23 @@ static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1098 begin = rgd = forward_rgrp_get(sdp); 1106 begin = rgd = forward_rgrp_get(sdp);
1099 1107
1100 for (;;) { 1108 for (;;) {
1101 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags, 1109 rg_locked = 0;
1102 &al->al_rgd_gh); 1110
1111 if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
1112 rg_locked = 1;
1113 error = 0;
1114 } else {
1115 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags,
1116 &al->al_rgd_gh);
1117 }
1103 switch (error) { 1118 switch (error) {
1104 case 0: 1119 case 0:
1105 if (try_rgrp_fit(rgd, al)) 1120 if (try_rgrp_fit(rgd, al))
1106 goto out; 1121 goto out;
1107 if (rgd->rd_flags & GFS2_RDF_CHECK) 1122 if (rgd->rd_flags & GFS2_RDF_CHECK)
1108 inode = try_rgrp_unlink(rgd, last_unlinked); 1123 inode = try_rgrp_unlink(rgd, last_unlinked);
1109 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1124 if (!rg_locked)
1125 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1110 if (inode) 1126 if (inode)
1111 return inode; 1127 return inode;
1112 break; 1128 break;
@@ -1158,7 +1174,7 @@ out:
1158int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) 1174int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
1159{ 1175{
1160 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1176 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1161 struct gfs2_alloc *al = &ip->i_alloc; 1177 struct gfs2_alloc *al = ip->i_alloc;
1162 struct inode *inode; 1178 struct inode *inode;
1163 int error = 0; 1179 int error = 0;
1164 u64 last_unlinked = NO_BLOCK; 1180 u64 last_unlinked = NO_BLOCK;
@@ -1204,7 +1220,7 @@ try_again:
1204void gfs2_inplace_release(struct gfs2_inode *ip) 1220void gfs2_inplace_release(struct gfs2_inode *ip)
1205{ 1221{
1206 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1222 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1207 struct gfs2_alloc *al = &ip->i_alloc; 1223 struct gfs2_alloc *al = ip->i_alloc;
1208 1224
1209 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1) 1225 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
1210 fs_warn(sdp, "al_alloced = %u, al_requested = %u " 1226 fs_warn(sdp, "al_alloced = %u, al_requested = %u "
@@ -1213,7 +1229,8 @@ void gfs2_inplace_release(struct gfs2_inode *ip)
1213 al->al_line); 1229 al->al_line);
1214 1230
1215 al->al_rgd = NULL; 1231 al->al_rgd = NULL;
1216 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1232 if (al->al_rgd_gh.gh_gl)
1233 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1217 if (ip != GFS2_I(sdp->sd_rindex)) 1234 if (ip != GFS2_I(sdp->sd_rindex))
1218 gfs2_glock_dq_uninit(&al->al_ri_gh); 1235 gfs2_glock_dq_uninit(&al->al_ri_gh);
1219} 1236}
@@ -1301,11 +1318,10 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1301 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone 1318 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
1302 bitmaps, so we must search the originals for that. */ 1319 bitmaps, so we must search the originals for that. */
1303 if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone) 1320 if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1304 blk = gfs2_bitfit(rgd, bi->bi_clone + bi->bi_offset, 1321 blk = gfs2_bitfit(bi->bi_clone + bi->bi_offset,
1305 bi->bi_len, goal, old_state); 1322 bi->bi_len, goal, old_state);
1306 else 1323 else
1307 blk = gfs2_bitfit(rgd, 1324 blk = gfs2_bitfit(bi->bi_bh->b_data + bi->bi_offset,
1308 bi->bi_bh->b_data + bi->bi_offset,
1309 bi->bi_len, goal, old_state); 1325 bi->bi_len, goal, old_state);
1310 if (blk != BFITNOENT) 1326 if (blk != BFITNOENT)
1311 break; 1327 break;
@@ -1394,7 +1410,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
1394u64 gfs2_alloc_data(struct gfs2_inode *ip) 1410u64 gfs2_alloc_data(struct gfs2_inode *ip)
1395{ 1411{
1396 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1412 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1397 struct gfs2_alloc *al = &ip->i_alloc; 1413 struct gfs2_alloc *al = ip->i_alloc;
1398 struct gfs2_rgrpd *rgd = al->al_rgd; 1414 struct gfs2_rgrpd *rgd = al->al_rgd;
1399 u32 goal, blk; 1415 u32 goal, blk;
1400 u64 block; 1416 u64 block;
@@ -1439,7 +1455,7 @@ u64 gfs2_alloc_data(struct gfs2_inode *ip)
1439u64 gfs2_alloc_meta(struct gfs2_inode *ip) 1455u64 gfs2_alloc_meta(struct gfs2_inode *ip)
1440{ 1456{
1441 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1457 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1442 struct gfs2_alloc *al = &ip->i_alloc; 1458 struct gfs2_alloc *al = ip->i_alloc;
1443 struct gfs2_rgrpd *rgd = al->al_rgd; 1459 struct gfs2_rgrpd *rgd = al->al_rgd;
1444 u32 goal, blk; 1460 u32 goal, blk;
1445 u64 block; 1461 u64 block;
@@ -1485,7 +1501,7 @@ u64 gfs2_alloc_meta(struct gfs2_inode *ip)
1485u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation) 1501u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation)
1486{ 1502{
1487 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 1503 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1488 struct gfs2_alloc *al = &dip->i_alloc; 1504 struct gfs2_alloc *al = dip->i_alloc;
1489 struct gfs2_rgrpd *rgd = al->al_rgd; 1505 struct gfs2_rgrpd *rgd = al->al_rgd;
1490 u32 blk; 1506 u32 blk;
1491 u64 block; 1507 u64 block;
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index b4c6adfc6f2e..149bb161f4b6 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -32,7 +32,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd);
32struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); 32struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
33static inline void gfs2_alloc_put(struct gfs2_inode *ip) 33static inline void gfs2_alloc_put(struct gfs2_inode *ip)
34{ 34{
35 return; /* So we can see where ip->i_alloc is used */ 35 BUG_ON(ip->i_alloc == NULL);
36 kfree(ip->i_alloc);
37 ip->i_alloc = NULL;
36} 38}
37 39
38int gfs2_inplace_reserve_i(struct gfs2_inode *ip, 40int gfs2_inplace_reserve_i(struct gfs2_inode *ip,
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index dd3e737f528e..ef0562c3bc71 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -51,13 +51,9 @@ void gfs2_tune_init(struct gfs2_tune *gt)
51{ 51{
52 spin_lock_init(&gt->gt_spin); 52 spin_lock_init(&gt->gt_spin);
53 53
54 gt->gt_ilimit = 100;
55 gt->gt_ilimit_tries = 3;
56 gt->gt_ilimit_min = 1;
57 gt->gt_demote_secs = 300; 54 gt->gt_demote_secs = 300;
58 gt->gt_incore_log_blocks = 1024; 55 gt->gt_incore_log_blocks = 1024;
59 gt->gt_log_flush_secs = 60; 56 gt->gt_log_flush_secs = 60;
60 gt->gt_jindex_refresh_secs = 60;
61 gt->gt_recoverd_secs = 60; 57 gt->gt_recoverd_secs = 60;
62 gt->gt_logd_secs = 1; 58 gt->gt_logd_secs = 1;
63 gt->gt_quotad_secs = 5; 59 gt->gt_quotad_secs = 5;
@@ -71,10 +67,8 @@ void gfs2_tune_init(struct gfs2_tune *gt)
71 gt->gt_new_files_jdata = 0; 67 gt->gt_new_files_jdata = 0;
72 gt->gt_new_files_directio = 0; 68 gt->gt_new_files_directio = 0;
73 gt->gt_max_readahead = 1 << 18; 69 gt->gt_max_readahead = 1 << 18;
74 gt->gt_lockdump_size = 131072;
75 gt->gt_stall_secs = 600; 70 gt->gt_stall_secs = 600;
76 gt->gt_complain_secs = 10; 71 gt->gt_complain_secs = 10;
77 gt->gt_reclaim_limit = 5000;
78 gt->gt_statfs_quantum = 30; 72 gt->gt_statfs_quantum = 30;
79 gt->gt_statfs_slow = 0; 73 gt->gt_statfs_slow = 0;
80} 74}
@@ -393,6 +387,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
393 if (!jd) 387 if (!jd)
394 break; 388 break;
395 389
390 INIT_LIST_HEAD(&jd->extent_list);
396 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL); 391 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL);
397 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) { 392 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
398 if (!jd->jd_inode) 393 if (!jd->jd_inode)
@@ -422,8 +417,9 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
422 417
423void gfs2_jindex_free(struct gfs2_sbd *sdp) 418void gfs2_jindex_free(struct gfs2_sbd *sdp)
424{ 419{
425 struct list_head list; 420 struct list_head list, *head;
426 struct gfs2_jdesc *jd; 421 struct gfs2_jdesc *jd;
422 struct gfs2_journal_extent *jext;
427 423
428 spin_lock(&sdp->sd_jindex_spin); 424 spin_lock(&sdp->sd_jindex_spin);
429 list_add(&list, &sdp->sd_jindex_list); 425 list_add(&list, &sdp->sd_jindex_list);
@@ -433,6 +429,14 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp)
433 429
434 while (!list_empty(&list)) { 430 while (!list_empty(&list)) {
435 jd = list_entry(list.next, struct gfs2_jdesc, jd_list); 431 jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
432 head = &jd->extent_list;
433 while (!list_empty(head)) {
434 jext = list_entry(head->next,
435 struct gfs2_journal_extent,
436 extent_list);
437 list_del(&jext->extent_list);
438 kfree(jext);
439 }
436 list_del(&jd->jd_list); 440 list_del(&jd->jd_list);
437 iput(jd->jd_inode); 441 iput(jd->jd_inode);
438 kfree(jd); 442 kfree(jd);
@@ -543,7 +547,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
543 if (error) 547 if (error)
544 return error; 548 return error;
545 549
546 gfs2_meta_cache_flush(ip);
547 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 550 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
548 551
549 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 552 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -686,9 +689,7 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
686 if (error) 689 if (error)
687 return; 690 return;
688 691
689 mutex_lock(&sdp->sd_statfs_mutex);
690 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); 692 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
691 mutex_unlock(&sdp->sd_statfs_mutex);
692 693
693 spin_lock(&sdp->sd_statfs_spin); 694 spin_lock(&sdp->sd_statfs_spin);
694 l_sc->sc_total += total; 695 l_sc->sc_total += total;
@@ -736,9 +737,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp)
736 if (error) 737 if (error)
737 goto out_bh2; 738 goto out_bh2;
738 739
739 mutex_lock(&sdp->sd_statfs_mutex);
740 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); 740 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
741 mutex_unlock(&sdp->sd_statfs_mutex);
742 741
743 spin_lock(&sdp->sd_statfs_spin); 742 spin_lock(&sdp->sd_statfs_spin);
744 m_sc->sc_total += l_sc->sc_total; 743 m_sc->sc_total += l_sc->sc_total;
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 06e0b7768d97..eaa3b7b2f99e 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -32,7 +32,8 @@ spinlock_t gfs2_sys_margs_lock;
32 32
33static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 33static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
34{ 34{
35 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_vfs->s_id); 35 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
36 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
36} 37}
37 38
38static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) 39static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
@@ -221,9 +222,7 @@ static struct kobj_type gfs2_ktype = {
221 .sysfs_ops = &gfs2_attr_ops, 222 .sysfs_ops = &gfs2_attr_ops,
222}; 223};
223 224
224static struct kset gfs2_kset = { 225static struct kset *gfs2_kset;
225 .ktype = &gfs2_ktype,
226};
227 226
228/* 227/*
229 * display struct lm_lockstruct fields 228 * display struct lm_lockstruct fields
@@ -427,13 +426,11 @@ TUNE_ATTR_2(name, name##_store)
427TUNE_ATTR(demote_secs, 0); 426TUNE_ATTR(demote_secs, 0);
428TUNE_ATTR(incore_log_blocks, 0); 427TUNE_ATTR(incore_log_blocks, 0);
429TUNE_ATTR(log_flush_secs, 0); 428TUNE_ATTR(log_flush_secs, 0);
430TUNE_ATTR(jindex_refresh_secs, 0);
431TUNE_ATTR(quota_warn_period, 0); 429TUNE_ATTR(quota_warn_period, 0);
432TUNE_ATTR(quota_quantum, 0); 430TUNE_ATTR(quota_quantum, 0);
433TUNE_ATTR(atime_quantum, 0); 431TUNE_ATTR(atime_quantum, 0);
434TUNE_ATTR(max_readahead, 0); 432TUNE_ATTR(max_readahead, 0);
435TUNE_ATTR(complain_secs, 0); 433TUNE_ATTR(complain_secs, 0);
436TUNE_ATTR(reclaim_limit, 0);
437TUNE_ATTR(statfs_slow, 0); 434TUNE_ATTR(statfs_slow, 0);
438TUNE_ATTR(new_files_jdata, 0); 435TUNE_ATTR(new_files_jdata, 0);
439TUNE_ATTR(new_files_directio, 0); 436TUNE_ATTR(new_files_directio, 0);
@@ -450,13 +447,11 @@ static struct attribute *tune_attrs[] = {
450 &tune_attr_demote_secs.attr, 447 &tune_attr_demote_secs.attr,
451 &tune_attr_incore_log_blocks.attr, 448 &tune_attr_incore_log_blocks.attr,
452 &tune_attr_log_flush_secs.attr, 449 &tune_attr_log_flush_secs.attr,
453 &tune_attr_jindex_refresh_secs.attr,
454 &tune_attr_quota_warn_period.attr, 450 &tune_attr_quota_warn_period.attr,
455 &tune_attr_quota_quantum.attr, 451 &tune_attr_quota_quantum.attr,
456 &tune_attr_atime_quantum.attr, 452 &tune_attr_atime_quantum.attr,
457 &tune_attr_max_readahead.attr, 453 &tune_attr_max_readahead.attr,
458 &tune_attr_complain_secs.attr, 454 &tune_attr_complain_secs.attr,
459 &tune_attr_reclaim_limit.attr,
460 &tune_attr_statfs_slow.attr, 455 &tune_attr_statfs_slow.attr,
461 &tune_attr_quota_simul_sync.attr, 456 &tune_attr_quota_simul_sync.attr,
462 &tune_attr_quota_cache_secs.attr, 457 &tune_attr_quota_cache_secs.attr,
@@ -495,14 +490,9 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
495{ 490{
496 int error; 491 int error;
497 492
498 sdp->sd_kobj.kset = &gfs2_kset; 493 sdp->sd_kobj.kset = gfs2_kset;
499 sdp->sd_kobj.ktype = &gfs2_ktype; 494 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
500 495 "%s", sdp->sd_table_name);
501 error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name);
502 if (error)
503 goto fail;
504
505 error = kobject_register(&sdp->sd_kobj);
506 if (error) 496 if (error)
507 goto fail; 497 goto fail;
508 498
@@ -522,6 +512,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
522 if (error) 512 if (error)
523 goto fail_args; 513 goto fail_args;
524 514
515 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
525 return 0; 516 return 0;
526 517
527fail_args: 518fail_args:
@@ -531,7 +522,7 @@ fail_counters:
531fail_lockstruct: 522fail_lockstruct:
532 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 523 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
533fail_reg: 524fail_reg:
534 kobject_unregister(&sdp->sd_kobj); 525 kobject_put(&sdp->sd_kobj);
535fail: 526fail:
536 fs_err(sdp, "error %d adding sysfs files", error); 527 fs_err(sdp, "error %d adding sysfs files", error);
537 return error; 528 return error;
@@ -543,21 +534,22 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
543 sysfs_remove_group(&sdp->sd_kobj, &args_group); 534 sysfs_remove_group(&sdp->sd_kobj, &args_group);
544 sysfs_remove_group(&sdp->sd_kobj, &counters_group); 535 sysfs_remove_group(&sdp->sd_kobj, &counters_group);
545 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 536 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
546 kobject_unregister(&sdp->sd_kobj); 537 kobject_put(&sdp->sd_kobj);
547} 538}
548 539
549int gfs2_sys_init(void) 540int gfs2_sys_init(void)
550{ 541{
551 gfs2_sys_margs = NULL; 542 gfs2_sys_margs = NULL;
552 spin_lock_init(&gfs2_sys_margs_lock); 543 spin_lock_init(&gfs2_sys_margs_lock);
553 kobject_set_name(&gfs2_kset.kobj, "gfs2"); 544 gfs2_kset = kset_create_and_add("gfs2", NULL, fs_kobj);
554 kobj_set_kset_s(&gfs2_kset, fs_subsys); 545 if (!gfs2_kset)
555 return kset_register(&gfs2_kset); 546 return -ENOMEM;
547 return 0;
556} 548}
557 549
558void gfs2_sys_uninit(void) 550void gfs2_sys_uninit(void)
559{ 551{
560 kfree(gfs2_sys_margs); 552 kfree(gfs2_sys_margs);
561 kset_unregister(&gfs2_kset); 553 kset_unregister(gfs2_kset);
562} 554}
563 555
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 717983e2c2ae..73e5d92a657c 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -114,11 +114,6 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
114 gfs2_log_flush(sdp, NULL); 114 gfs2_log_flush(sdp, NULL);
115} 115}
116 116
117void gfs2_trans_add_gl(struct gfs2_glock *gl)
118{
119 lops_add(gl->gl_sbd, &gl->gl_le);
120}
121
122/** 117/**
123 * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction 118 * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction
124 * @gl: the glock the buffer belongs to 119 * @gl: the glock the buffer belongs to
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index 043d5f4b9c4c..e826f0dab80a 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -30,7 +30,6 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
30 30
31void gfs2_trans_end(struct gfs2_sbd *sdp); 31void gfs2_trans_end(struct gfs2_sbd *sdp);
32 32
33void gfs2_trans_add_gl(struct gfs2_glock *gl);
34void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta); 33void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta);
35void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); 34void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
36void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno); 35void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno);
diff --git a/fs/namespace.c b/fs/namespace.c
index 06083885b21e..61bf376e29e8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -41,8 +41,8 @@ static struct kmem_cache *mnt_cache __read_mostly;
41static struct rw_semaphore namespace_sem; 41static struct rw_semaphore namespace_sem;
42 42
43/* /sys/fs */ 43/* /sys/fs */
44decl_subsys(fs, NULL, NULL); 44struct kobject *fs_kobj;
45EXPORT_SYMBOL_GPL(fs_subsys); 45EXPORT_SYMBOL_GPL(fs_kobj);
46 46
47static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) 47static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
48{ 48{
@@ -1861,10 +1861,9 @@ void __init mnt_init(void)
1861 if (err) 1861 if (err)
1862 printk(KERN_WARNING "%s: sysfs_init error: %d\n", 1862 printk(KERN_WARNING "%s: sysfs_init error: %d\n",
1863 __FUNCTION__, err); 1863 __FUNCTION__, err);
1864 err = subsystem_register(&fs_subsys); 1864 fs_kobj = kobject_create_and_add("fs", NULL);
1865 if (err) 1865 if (!fs_kobj)
1866 printk(KERN_WARNING "%s: subsystem_register error: %d\n", 1866 printk(KERN_WARNING "%s: kobj create error\n", __FUNCTION__);
1867 __FUNCTION__, err);
1868 init_rootfs(); 1867 init_rootfs();
1869 init_mount_tree(); 1868 init_mount_tree();
1870} 1869}
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index a4882c8df945..23c732f27529 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -146,7 +146,7 @@ static struct kset mlog_kset = {
146 .kobj = {.ktype = &mlog_ktype}, 146 .kobj = {.ktype = &mlog_ktype},
147}; 147};
148 148
149int mlog_sys_init(struct kset *o2cb_subsys) 149int mlog_sys_init(struct kset *o2cb_kset)
150{ 150{
151 int i = 0; 151 int i = 0;
152 152
@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys)
157 mlog_attr_ptrs[i] = NULL; 157 mlog_attr_ptrs[i] = NULL;
158 158
159 kobject_set_name(&mlog_kset.kobj, "logmask"); 159 kobject_set_name(&mlog_kset.kobj, "logmask");
160 kobj_set_kset_s(&mlog_kset, *o2cb_subsys); 160 mlog_kset.kobj.kset = o2cb_kset;
161 return kset_register(&mlog_kset); 161 return kset_register(&mlog_kset);
162} 162}
163 163
diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 64f6f378fd09..a4b07730b2e1 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -28,96 +28,55 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/kobject.h> 29#include <linux/kobject.h>
30#include <linux/sysfs.h> 30#include <linux/sysfs.h>
31#include <linux/fs.h>
31 32
32#include "ocfs2_nodemanager.h" 33#include "ocfs2_nodemanager.h"
33#include "masklog.h" 34#include "masklog.h"
34#include "sys.h" 35#include "sys.h"
35 36
36struct o2cb_attribute {
37 struct attribute attr;
38 ssize_t (*show)(char *buf);
39 ssize_t (*store)(const char *buf, size_t count);
40};
41
42#define O2CB_ATTR(_name, _mode, _show, _store) \
43struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
44
45#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
46 37
47static ssize_t o2cb_interface_revision_show(char *buf) 38static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
39 char *buf)
48{ 40{
49 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); 41 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
50} 42}
51 43static struct kobj_attribute attr_version =
52static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL); 44 __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL);
53 45
54static struct attribute *o2cb_attrs[] = { 46static struct attribute *o2cb_attrs[] = {
55 &o2cb_attr_interface_revision.attr, 47 &attr_version.attr,
56 NULL, 48 NULL,
57}; 49};
58 50
59static ssize_t 51static struct attribute_group o2cb_attr_group = {
60o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer); 52 .attrs = o2cb_attrs,
61static ssize_t
62o2cb_store(struct kobject * kobj, struct attribute * attr,
63 const char * buffer, size_t count);
64static struct sysfs_ops o2cb_sysfs_ops = {
65 .show = o2cb_show,
66 .store = o2cb_store,
67}; 53};
68 54
69static struct kobj_type o2cb_subsys_type = { 55static struct kset *o2cb_kset;
70 .default_attrs = o2cb_attrs,
71 .sysfs_ops = &o2cb_sysfs_ops,
72};
73
74/* gives us o2cb_subsys */
75static decl_subsys(o2cb, NULL, NULL);
76
77static ssize_t
78o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
79{
80 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
81 struct kset *sbs = to_kset(kobj);
82
83 BUG_ON(sbs != &o2cb_subsys);
84
85 if (o2cb_attr->show)
86 return o2cb_attr->show(buffer);
87 return -EIO;
88}
89
90static ssize_t
91o2cb_store(struct kobject * kobj, struct attribute * attr,
92 const char * buffer, size_t count)
93{
94 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
95 struct kset *sbs = to_kset(kobj);
96
97 BUG_ON(sbs != &o2cb_subsys);
98
99 if (o2cb_attr->store)
100 return o2cb_attr->store(buffer, count);
101 return -EIO;
102}
103 56
104void o2cb_sys_shutdown(void) 57void o2cb_sys_shutdown(void)
105{ 58{
106 mlog_sys_shutdown(); 59 mlog_sys_shutdown();
107 subsystem_unregister(&o2cb_subsys); 60 kset_unregister(o2cb_kset);
108} 61}
109 62
110int o2cb_sys_init(void) 63int o2cb_sys_init(void)
111{ 64{
112 int ret; 65 int ret;
113 66
114 o2cb_subsys.kobj.ktype = &o2cb_subsys_type; 67 o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
115 ret = subsystem_register(&o2cb_subsys); 68 if (!o2cb_kset)
69 return -ENOMEM;
70
71 ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
116 if (ret) 72 if (ret)
117 return ret; 73 goto error;
118 74
119 ret = mlog_sys_init(&o2cb_subsys); 75 ret = mlog_sys_init(o2cb_kset);
120 if (ret) 76 if (ret)
121 subsystem_unregister(&o2cb_subsys); 77 goto error;
78 return 0;
79error:
80 kset_unregister(o2cb_kset);
122 return ret; 81 return ret;
123} 82}
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 722e12e5acc7..739da701ae7b 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -195,96 +195,45 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
195 return ERR_PTR(res); 195 return ERR_PTR(res);
196} 196}
197 197
198/* 198static ssize_t part_start_show(struct device *dev,
199 * sysfs bindings for partitions 199 struct device_attribute *attr, char *buf)
200 */
201
202struct part_attribute {
203 struct attribute attr;
204 ssize_t (*show)(struct hd_struct *,char *);
205 ssize_t (*store)(struct hd_struct *,const char *, size_t);
206};
207
208static ssize_t
209part_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
210{ 200{
211 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj); 201 struct hd_struct *p = dev_to_part(dev);
212 struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
213 ssize_t ret = 0;
214 if (part_attr->show)
215 ret = part_attr->show(p, page);
216 return ret;
217}
218static ssize_t
219part_attr_store(struct kobject * kobj, struct attribute * attr,
220 const char *page, size_t count)
221{
222 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj);
223 struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
224 ssize_t ret = 0;
225 202
226 if (part_attr->store) 203 return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
227 ret = part_attr->store(p, page, count);
228 return ret;
229} 204}
230 205
231static struct sysfs_ops part_sysfs_ops = { 206static ssize_t part_size_show(struct device *dev,
232 .show = part_attr_show, 207 struct device_attribute *attr, char *buf)
233 .store = part_attr_store,
234};
235
236static ssize_t part_uevent_store(struct hd_struct * p,
237 const char *page, size_t count)
238{ 208{
239 kobject_uevent(&p->kobj, KOBJ_ADD); 209 struct hd_struct *p = dev_to_part(dev);
240 return count; 210 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
241} 211}
242static ssize_t part_dev_read(struct hd_struct * p, char *page) 212
243{ 213static ssize_t part_stat_show(struct device *dev,
244 struct gendisk *disk = container_of(p->kobj.parent,struct gendisk,kobj); 214 struct device_attribute *attr, char *buf)
245 dev_t dev = MKDEV(disk->major, disk->first_minor + p->partno);
246 return print_dev_t(page, dev);
247}
248static ssize_t part_start_read(struct hd_struct * p, char *page)
249{
250 return sprintf(page, "%llu\n",(unsigned long long)p->start_sect);
251}
252static ssize_t part_size_read(struct hd_struct * p, char *page)
253{
254 return sprintf(page, "%llu\n",(unsigned long long)p->nr_sects);
255}
256static ssize_t part_stat_read(struct hd_struct * p, char *page)
257{ 215{
258 return sprintf(page, "%8u %8llu %8u %8llu\n", 216 struct hd_struct *p = dev_to_part(dev);
217
218 return sprintf(buf, "%8u %8llu %8u %8llu\n",
259 p->ios[0], (unsigned long long)p->sectors[0], 219 p->ios[0], (unsigned long long)p->sectors[0],
260 p->ios[1], (unsigned long long)p->sectors[1]); 220 p->ios[1], (unsigned long long)p->sectors[1]);
261} 221}
262static struct part_attribute part_attr_uevent = {
263 .attr = {.name = "uevent", .mode = S_IWUSR },
264 .store = part_uevent_store
265};
266static struct part_attribute part_attr_dev = {
267 .attr = {.name = "dev", .mode = S_IRUGO },
268 .show = part_dev_read
269};
270static struct part_attribute part_attr_start = {
271 .attr = {.name = "start", .mode = S_IRUGO },
272 .show = part_start_read
273};
274static struct part_attribute part_attr_size = {
275 .attr = {.name = "size", .mode = S_IRUGO },
276 .show = part_size_read
277};
278static struct part_attribute part_attr_stat = {
279 .attr = {.name = "stat", .mode = S_IRUGO },
280 .show = part_stat_read
281};
282 222
283#ifdef CONFIG_FAIL_MAKE_REQUEST 223#ifdef CONFIG_FAIL_MAKE_REQUEST
224static ssize_t part_fail_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 struct hd_struct *p = dev_to_part(dev);
284 228
285static ssize_t part_fail_store(struct hd_struct * p, 229 return sprintf(buf, "%d\n", p->make_it_fail);
230}
231
232static ssize_t part_fail_store(struct device *dev,
233 struct device_attribute *attr,
286 const char *buf, size_t count) 234 const char *buf, size_t count)
287{ 235{
236 struct hd_struct *p = dev_to_part(dev);
288 int i; 237 int i;
289 238
290 if (count > 0 && sscanf(buf, "%d", &i) > 0) 239 if (count > 0 && sscanf(buf, "%d", &i) > 0)
@@ -292,50 +241,53 @@ static ssize_t part_fail_store(struct hd_struct * p,
292 241
293 return count; 242 return count;
294} 243}
295static ssize_t part_fail_read(struct hd_struct * p, char *page) 244#endif
296{
297 return sprintf(page, "%d\n", p->make_it_fail);
298}
299static struct part_attribute part_attr_fail = {
300 .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
301 .store = part_fail_store,
302 .show = part_fail_read
303};
304 245
246static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
247static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
248static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
249#ifdef CONFIG_FAIL_MAKE_REQUEST
250static struct device_attribute dev_attr_fail =
251 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
305#endif 252#endif
306 253
307static struct attribute * default_attrs[] = { 254static struct attribute *part_attrs[] = {
308 &part_attr_uevent.attr, 255 &dev_attr_start.attr,
309 &part_attr_dev.attr, 256 &dev_attr_size.attr,
310 &part_attr_start.attr, 257 &dev_attr_stat.attr,
311 &part_attr_size.attr,
312 &part_attr_stat.attr,
313#ifdef CONFIG_FAIL_MAKE_REQUEST 258#ifdef CONFIG_FAIL_MAKE_REQUEST
314 &part_attr_fail.attr, 259 &dev_attr_fail.attr,
315#endif 260#endif
316 NULL, 261 NULL
317}; 262};
318 263
319extern struct kset block_subsys; 264static struct attribute_group part_attr_group = {
265 .attrs = part_attrs,
266};
320 267
321static void part_release(struct kobject *kobj) 268static struct attribute_group *part_attr_groups[] = {
269 &part_attr_group,
270 NULL
271};
272
273static void part_release(struct device *dev)
322{ 274{
323 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj); 275 struct hd_struct *p = dev_to_part(dev);
324 kfree(p); 276 kfree(p);
325} 277}
326 278
327struct kobj_type ktype_part = { 279struct device_type part_type = {
280 .name = "partition",
281 .groups = part_attr_groups,
328 .release = part_release, 282 .release = part_release,
329 .default_attrs = default_attrs,
330 .sysfs_ops = &part_sysfs_ops,
331}; 283};
332 284
333static inline void partition_sysfs_add_subdir(struct hd_struct *p) 285static inline void partition_sysfs_add_subdir(struct hd_struct *p)
334{ 286{
335 struct kobject *k; 287 struct kobject *k;
336 288
337 k = kobject_get(&p->kobj); 289 k = kobject_get(&p->dev.kobj);
338 p->holder_dir = kobject_add_dir(k, "holders"); 290 p->holder_dir = kobject_create_and_add("holders", k);
339 kobject_put(k); 291 kobject_put(k);
340} 292}
341 293
@@ -343,15 +295,16 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
343{ 295{
344 struct kobject *k; 296 struct kobject *k;
345 297
346 k = kobject_get(&disk->kobj); 298 k = kobject_get(&disk->dev.kobj);
347 disk->holder_dir = kobject_add_dir(k, "holders"); 299 disk->holder_dir = kobject_create_and_add("holders", k);
348 disk->slave_dir = kobject_add_dir(k, "slaves"); 300 disk->slave_dir = kobject_create_and_add("slaves", k);
349 kobject_put(k); 301 kobject_put(k);
350} 302}
351 303
352void delete_partition(struct gendisk *disk, int part) 304void delete_partition(struct gendisk *disk, int part)
353{ 305{
354 struct hd_struct *p = disk->part[part-1]; 306 struct hd_struct *p = disk->part[part-1];
307
355 if (!p) 308 if (!p)
356 return; 309 return;
357 if (!p->nr_sects) 310 if (!p->nr_sects)
@@ -361,113 +314,55 @@ void delete_partition(struct gendisk *disk, int part)
361 p->nr_sects = 0; 314 p->nr_sects = 0;
362 p->ios[0] = p->ios[1] = 0; 315 p->ios[0] = p->ios[1] = 0;
363 p->sectors[0] = p->sectors[1] = 0; 316 p->sectors[0] = p->sectors[1] = 0;
364 sysfs_remove_link(&p->kobj, "subsystem"); 317 kobject_put(p->holder_dir);
365 kobject_unregister(p->holder_dir); 318 device_del(&p->dev);
366 kobject_uevent(&p->kobj, KOBJ_REMOVE); 319 put_device(&p->dev);
367 kobject_del(&p->kobj);
368 kobject_put(&p->kobj);
369} 320}
370 321
371void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) 322void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags)
372{ 323{
373 struct hd_struct *p; 324 struct hd_struct *p;
325 int err;
374 326
375 p = kzalloc(sizeof(*p), GFP_KERNEL); 327 p = kzalloc(sizeof(*p), GFP_KERNEL);
376 if (!p) 328 if (!p)
377 return; 329 return;
378 330
379 p->start_sect = start; 331 p->start_sect = start;
380 p->nr_sects = len; 332 p->nr_sects = len;
381 p->partno = part; 333 p->partno = part;
382 p->policy = disk->policy; 334 p->policy = disk->policy;
383 335
384 if (isdigit(disk->kobj.k_name[strlen(disk->kobj.k_name)-1])) 336 if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1]))
385 kobject_set_name(&p->kobj, "%sp%d", 337 snprintf(p->dev.bus_id, BUS_ID_SIZE,
386 kobject_name(&disk->kobj), part); 338 "%sp%d", disk->dev.bus_id, part);
387 else 339 else
388 kobject_set_name(&p->kobj, "%s%d", 340 snprintf(p->dev.bus_id, BUS_ID_SIZE,
389 kobject_name(&disk->kobj),part); 341 "%s%d", disk->dev.bus_id, part);
390 p->kobj.parent = &disk->kobj; 342
391 p->kobj.ktype = &ktype_part; 343 device_initialize(&p->dev);
392 kobject_init(&p->kobj); 344 p->dev.devt = MKDEV(disk->major, disk->first_minor + part);
393 kobject_add(&p->kobj); 345 p->dev.class = &block_class;
394 if (!disk->part_uevent_suppress) 346 p->dev.type = &part_type;
395 kobject_uevent(&p->kobj, KOBJ_ADD); 347 p->dev.parent = &disk->dev;
396 sysfs_create_link(&p->kobj, &block_subsys.kobj, "subsystem"); 348 disk->part[part-1] = p;
349
350 /* delay uevent until 'holders' subdir is created */
351 p->dev.uevent_suppress = 1;
352 device_add(&p->dev);
353 partition_sysfs_add_subdir(p);
354 p->dev.uevent_suppress = 0;
397 if (flags & ADDPART_FLAG_WHOLEDISK) { 355 if (flags & ADDPART_FLAG_WHOLEDISK) {
398 static struct attribute addpartattr = { 356 static struct attribute addpartattr = {
399 .name = "whole_disk", 357 .name = "whole_disk",
400 .mode = S_IRUSR | S_IRGRP | S_IROTH, 358 .mode = S_IRUSR | S_IRGRP | S_IROTH,
401 }; 359 };
402 360 err = sysfs_create_file(&p->dev.kobj, &addpartattr);
403 sysfs_create_file(&p->kobj, &addpartattr);
404 } 361 }
405 partition_sysfs_add_subdir(p);
406 disk->part[part-1] = p;
407}
408 362
409static char *make_block_name(struct gendisk *disk) 363 /* suppress uevent if the disk supresses it */
410{ 364 if (!disk->dev.uevent_suppress)
411 char *name; 365 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
412 static char *block_str = "block:";
413 int size;
414 char *s;
415
416 size = strlen(block_str) + strlen(disk->disk_name) + 1;
417 name = kmalloc(size, GFP_KERNEL);
418 if (!name)
419 return NULL;
420 strcpy(name, block_str);
421 strcat(name, disk->disk_name);
422 /* ewww... some of these buggers have / in name... */
423 s = strchr(name, '/');
424 if (s)
425 *s = '!';
426 return name;
427}
428
429static int disk_sysfs_symlinks(struct gendisk *disk)
430{
431 struct device *target = get_device(disk->driverfs_dev);
432 int err;
433 char *disk_name = NULL;
434
435 if (target) {
436 disk_name = make_block_name(disk);
437 if (!disk_name) {
438 err = -ENOMEM;
439 goto err_out;
440 }
441
442 err = sysfs_create_link(&disk->kobj, &target->kobj, "device");
443 if (err)
444 goto err_out_disk_name;
445
446 err = sysfs_create_link(&target->kobj, &disk->kobj, disk_name);
447 if (err)
448 goto err_out_dev_link;
449 }
450
451 err = sysfs_create_link(&disk->kobj, &block_subsys.kobj,
452 "subsystem");
453 if (err)
454 goto err_out_disk_name_lnk;
455
456 kfree(disk_name);
457
458 return 0;
459
460err_out_disk_name_lnk:
461 if (target) {
462 sysfs_remove_link(&target->kobj, disk_name);
463err_out_dev_link:
464 sysfs_remove_link(&disk->kobj, "device");
465err_out_disk_name:
466 kfree(disk_name);
467err_out:
468 put_device(target);
469 }
470 return err;
471} 366}
472 367
473/* Not exported, helper to add_disk(). */ 368/* Not exported, helper to add_disk(). */
@@ -479,19 +374,29 @@ void register_disk(struct gendisk *disk)
479 struct hd_struct *p; 374 struct hd_struct *p;
480 int err; 375 int err;
481 376
482 kobject_set_name(&disk->kobj, "%s", disk->disk_name); 377 disk->dev.parent = disk->driverfs_dev;
483 /* ewww... some of these buggers have / in name... */ 378 disk->dev.devt = MKDEV(disk->major, disk->first_minor);
484 s = strchr(disk->kobj.k_name, '/'); 379
380 strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN);
381 /* ewww... some of these buggers have / in the name... */
382 s = strchr(disk->dev.bus_id, '/');
485 if (s) 383 if (s)
486 *s = '!'; 384 *s = '!';
487 if ((err = kobject_add(&disk->kobj))) 385
386 /* delay uevents, until we scanned partition table */
387 disk->dev.uevent_suppress = 1;
388
389 if (device_add(&disk->dev))
488 return; 390 return;
489 err = disk_sysfs_symlinks(disk); 391#ifndef CONFIG_SYSFS_DEPRECATED
392 err = sysfs_create_link(block_depr, &disk->dev.kobj,
393 kobject_name(&disk->dev.kobj));
490 if (err) { 394 if (err) {
491 kobject_del(&disk->kobj); 395 device_del(&disk->dev);
492 return; 396 return;
493 } 397 }
494 disk_sysfs_add_subdirs(disk); 398#endif
399 disk_sysfs_add_subdirs(disk);
495 400
496 /* No minors to use for partitions */ 401 /* No minors to use for partitions */
497 if (disk->minors == 1) 402 if (disk->minors == 1)
@@ -505,25 +410,23 @@ void register_disk(struct gendisk *disk)
505 if (!bdev) 410 if (!bdev)
506 goto exit; 411 goto exit;
507 412
508 /* scan partition table, but suppress uevents */
509 bdev->bd_invalidated = 1; 413 bdev->bd_invalidated = 1;
510 disk->part_uevent_suppress = 1;
511 err = blkdev_get(bdev, FMODE_READ, 0); 414 err = blkdev_get(bdev, FMODE_READ, 0);
512 disk->part_uevent_suppress = 0;
513 if (err < 0) 415 if (err < 0)
514 goto exit; 416 goto exit;
515 blkdev_put(bdev); 417 blkdev_put(bdev);
516 418
517exit: 419exit:
518 /* announce disk after possible partitions are already created */ 420 /* announce disk after possible partitions are created */
519 kobject_uevent(&disk->kobj, KOBJ_ADD); 421 disk->dev.uevent_suppress = 0;
422 kobject_uevent(&disk->dev.kobj, KOBJ_ADD);
520 423
521 /* announce possible partitions */ 424 /* announce possible partitions */
522 for (i = 1; i < disk->minors; i++) { 425 for (i = 1; i < disk->minors; i++) {
523 p = disk->part[i-1]; 426 p = disk->part[i-1];
524 if (!p || !p->nr_sects) 427 if (!p || !p->nr_sects)
525 continue; 428 continue;
526 kobject_uevent(&p->kobj, KOBJ_ADD); 429 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
527 } 430 }
528} 431}
529 432
@@ -602,19 +505,11 @@ void del_gendisk(struct gendisk *disk)
602 disk_stat_set_all(disk, 0); 505 disk_stat_set_all(disk, 0);
603 disk->stamp = 0; 506 disk->stamp = 0;
604 507
605 kobject_uevent(&disk->kobj, KOBJ_REMOVE); 508 kobject_put(disk->holder_dir);
606 kobject_unregister(disk->holder_dir); 509 kobject_put(disk->slave_dir);
607 kobject_unregister(disk->slave_dir); 510 disk->driverfs_dev = NULL;
608 if (disk->driverfs_dev) { 511#ifndef CONFIG_SYSFS_DEPRECATED
609 char *disk_name = make_block_name(disk); 512 sysfs_remove_link(block_depr, disk->dev.bus_id);
610 sysfs_remove_link(&disk->kobj, "device"); 513#endif
611 if (disk_name) { 514 device_del(&disk->dev);
612 sysfs_remove_link(&disk->driverfs_dev->kobj, disk_name);
613 kfree(disk_name);
614 }
615 put_device(disk->driverfs_dev);
616 disk->driverfs_dev = NULL;
617 }
618 sysfs_remove_link(&disk->kobj, "subsystem");
619 kobject_del(&disk->kobj);
620} 515}
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index f281cc6584b0..4948d9bc405d 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -440,7 +440,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
440/** 440/**
441 * sysfs_remove_one - remove sysfs_dirent from parent 441 * sysfs_remove_one - remove sysfs_dirent from parent
442 * @acxt: addrm context to use 442 * @acxt: addrm context to use
443 * @sd: sysfs_dirent to be added 443 * @sd: sysfs_dirent to be removed
444 * 444 *
445 * Mark @sd removed and drop nlink of parent inode if @sd is a 445 * Mark @sd removed and drop nlink of parent inode if @sd is a
446 * directory. @sd is unlinked from the children list. 446 * directory. @sd is unlinked from the children list.
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4045bdcc4b33..8acf82bba44c 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -20,43 +20,6 @@
20 20
21#include "sysfs.h" 21#include "sysfs.h"
22 22
23#define to_sattr(a) container_of(a,struct subsys_attribute, attr)
24
25/*
26 * Subsystem file operations.
27 * These operations allow subsystems to have files that can be
28 * read/written.
29 */
30static ssize_t
31subsys_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
32{
33 struct kset *kset = to_kset(kobj);
34 struct subsys_attribute * sattr = to_sattr(attr);
35 ssize_t ret = -EIO;
36
37 if (sattr->show)
38 ret = sattr->show(kset, page);
39 return ret;
40}
41
42static ssize_t
43subsys_attr_store(struct kobject * kobj, struct attribute * attr,
44 const char * page, size_t count)
45{
46 struct kset *kset = to_kset(kobj);
47 struct subsys_attribute * sattr = to_sattr(attr);
48 ssize_t ret = -EIO;
49
50 if (sattr->store)
51 ret = sattr->store(kset, page, count);
52 return ret;
53}
54
55static struct sysfs_ops subsys_sysfs_ops = {
56 .show = subsys_attr_show,
57 .store = subsys_attr_store,
58};
59
60/* 23/*
61 * There's one sysfs_buffer for each open file and one 24 * There's one sysfs_buffer for each open file and one
62 * sysfs_open_dirent for each sysfs_dirent with one or more open 25 * sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -66,7 +29,7 @@ static struct sysfs_ops subsys_sysfs_ops = {
66 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open 29 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open
67 * is protected by sysfs_open_dirent_lock. 30 * is protected by sysfs_open_dirent_lock.
68 */ 31 */
69static spinlock_t sysfs_open_dirent_lock = SPIN_LOCK_UNLOCKED; 32static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
70 33
71struct sysfs_open_dirent { 34struct sysfs_open_dirent {
72 atomic_t refcnt; 35 atomic_t refcnt;
@@ -354,31 +317,23 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
354{ 317{
355 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 318 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
356 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; 319 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
357 struct sysfs_buffer * buffer; 320 struct sysfs_buffer *buffer;
358 struct sysfs_ops * ops = NULL; 321 struct sysfs_ops *ops;
359 int error; 322 int error = -EACCES;
360 323
361 /* need attr_sd for attr and ops, its parent for kobj */ 324 /* need attr_sd for attr and ops, its parent for kobj */
362 if (!sysfs_get_active_two(attr_sd)) 325 if (!sysfs_get_active_two(attr_sd))
363 return -ENODEV; 326 return -ENODEV;
364 327
365 /* if the kobject has no ktype, then we assume that it is a subsystem 328 /* every kobject with an attribute needs a ktype assigned */
366 * itself, and use ops for it. 329 if (kobj->ktype && kobj->ktype->sysfs_ops)
367 */
368 if (kobj->kset && kobj->kset->ktype)
369 ops = kobj->kset->ktype->sysfs_ops;
370 else if (kobj->ktype)
371 ops = kobj->ktype->sysfs_ops; 330 ops = kobj->ktype->sysfs_ops;
372 else 331 else {
373 ops = &subsys_sysfs_ops; 332 printk(KERN_ERR "missing sysfs attribute operations for "
374 333 "kobject: %s\n", kobject_name(kobj));
375 error = -EACCES; 334 WARN_ON(1);
376
377 /* No sysfs operations, either from having no subsystem,
378 * or the subsystem have no operations.
379 */
380 if (!ops)
381 goto err_out; 335 goto err_out;
336 }
382 337
383 /* File needs write support. 338 /* File needs write support.
384 * The inode's perms must say it's ok, 339 * The inode's perms must say it's ok,
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 3eac20c63c41..5f66c4466151 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -19,39 +19,6 @@
19 19
20#include "sysfs.h" 20#include "sysfs.h"
21 21
22static int object_depth(struct sysfs_dirent *sd)
23{
24 int depth = 0;
25
26 for (; sd->s_parent; sd = sd->s_parent)
27 depth++;
28
29 return depth;
30}
31
32static int object_path_length(struct sysfs_dirent * sd)
33{
34 int length = 1;
35
36 for (; sd->s_parent; sd = sd->s_parent)
37 length += strlen(sd->s_name) + 1;
38
39 return length;
40}
41
42static void fill_object_path(struct sysfs_dirent *sd, char *buffer, int length)
43{
44 --length;
45 for (; sd->s_parent; sd = sd->s_parent) {
46 int cur = strlen(sd->s_name);
47
48 /* back up enough to print this bus id with '/' */
49 length -= cur;
50 strncpy(buffer + length, sd->s_name, cur);
51 *(buffer + --length) = '/';
52 }
53}
54
55/** 22/**
56 * sysfs_create_link - create symlink between two objects. 23 * sysfs_create_link - create symlink between two objects.
57 * @kobj: object whose directory we're creating the link in. 24 * @kobj: object whose directory we're creating the link in.
@@ -112,7 +79,6 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
112 return error; 79 return error;
113} 80}
114 81
115
116/** 82/**
117 * sysfs_remove_link - remove symlink in object's directory. 83 * sysfs_remove_link - remove symlink in object's directory.
118 * @kobj: object we're acting for. 84 * @kobj: object we're acting for.
@@ -124,24 +90,54 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
124 sysfs_hash_and_remove(kobj->sd, name); 90 sysfs_hash_and_remove(kobj->sd, name);
125} 91}
126 92
127static int sysfs_get_target_path(struct sysfs_dirent * parent_sd, 93static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
128 struct sysfs_dirent * target_sd, char *path) 94 struct sysfs_dirent *target_sd, char *path)
129{ 95{
130 char * s; 96 struct sysfs_dirent *base, *sd;
131 int depth, size; 97 char *s = path;
98 int len = 0;
99
100 /* go up to the root, stop at the base */
101 base = parent_sd;
102 while (base->s_parent) {
103 sd = target_sd->s_parent;
104 while (sd->s_parent && base != sd)
105 sd = sd->s_parent;
106
107 if (base == sd)
108 break;
109
110 strcpy(s, "../");
111 s += 3;
112 base = base->s_parent;
113 }
114
115 /* determine end of target string for reverse fillup */
116 sd = target_sd;
117 while (sd->s_parent && sd != base) {
118 len += strlen(sd->s_name) + 1;
119 sd = sd->s_parent;
120 }
132 121
133 depth = object_depth(parent_sd); 122 /* check limits */
134 size = object_path_length(target_sd) + depth * 3 - 1; 123 if (len < 2)
135 if (size > PATH_MAX) 124 return -EINVAL;
125 len--;
126 if ((s - path) + len > PATH_MAX)
136 return -ENAMETOOLONG; 127 return -ENAMETOOLONG;
137 128
138 pr_debug("%s: depth = %d, size = %d\n", __FUNCTION__, depth, size); 129 /* reverse fillup of target string from target to base */
130 sd = target_sd;
131 while (sd->s_parent && sd != base) {
132 int slen = strlen(sd->s_name);
139 133
140 for (s = path; depth--; s += 3) 134 len -= slen;
141 strcpy(s,"../"); 135 strncpy(s + len, sd->s_name, slen);
136 if (len)
137 s[--len] = '/';
142 138
143 fill_object_path(target_sd, path, size); 139 sd = sd->s_parent;
144 pr_debug("%s: path = '%s'\n", __FUNCTION__, path); 140 }
145 141
146 return 0; 142 return 0;
147} 143}
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 7b74b60a68a4..fb7171b1bd22 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -319,7 +319,7 @@ struct acpi_bus_event {
319 u32 data; 319 u32 data;
320}; 320};
321 321
322extern struct kset acpi_subsys; 322extern struct kobject *acpi_kobj;
323extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int); 323extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
324/* 324/*
325 * External Functions 325 * External Functions
diff --git a/include/crypto/aead.h b/include/crypto/aead.h
new file mode 100644
index 000000000000..0edf949f6369
--- /dev/null
+++ b/include/crypto/aead.h
@@ -0,0 +1,105 @@
1/*
2 * AEAD: Authenticated Encryption with Associated Data
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_AEAD_H
14#define _CRYPTO_AEAD_H
15
16#include <linux/crypto.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19
20/**
21 * struct aead_givcrypt_request - AEAD request with IV generation
22 * @seq: Sequence number for IV generation
23 * @giv: Space for generated IV
24 * @areq: The AEAD request itself
25 */
26struct aead_givcrypt_request {
27 u64 seq;
28 u8 *giv;
29
30 struct aead_request areq;
31};
32
33static inline struct crypto_aead *aead_givcrypt_reqtfm(
34 struct aead_givcrypt_request *req)
35{
36 return crypto_aead_reqtfm(&req->areq);
37}
38
39static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req)
40{
41 struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
42 return crt->givencrypt(req);
43};
44
45static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req)
46{
47 struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req));
48 return crt->givdecrypt(req);
49};
50
51static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req,
52 struct crypto_aead *tfm)
53{
54 req->areq.base.tfm = crypto_aead_tfm(tfm);
55}
56
57static inline struct aead_givcrypt_request *aead_givcrypt_alloc(
58 struct crypto_aead *tfm, gfp_t gfp)
59{
60 struct aead_givcrypt_request *req;
61
62 req = kmalloc(sizeof(struct aead_givcrypt_request) +
63 crypto_aead_reqsize(tfm), gfp);
64
65 if (likely(req))
66 aead_givcrypt_set_tfm(req, tfm);
67
68 return req;
69}
70
71static inline void aead_givcrypt_free(struct aead_givcrypt_request *req)
72{
73 kfree(req);
74}
75
76static inline void aead_givcrypt_set_callback(
77 struct aead_givcrypt_request *req, u32 flags,
78 crypto_completion_t complete, void *data)
79{
80 aead_request_set_callback(&req->areq, flags, complete, data);
81}
82
83static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req,
84 struct scatterlist *src,
85 struct scatterlist *dst,
86 unsigned int nbytes, void *iv)
87{
88 aead_request_set_crypt(&req->areq, src, dst, nbytes, iv);
89}
90
91static inline void aead_givcrypt_set_assoc(struct aead_givcrypt_request *req,
92 struct scatterlist *assoc,
93 unsigned int assoclen)
94{
95 aead_request_set_assoc(&req->areq, assoc, assoclen);
96}
97
98static inline void aead_givcrypt_set_giv(struct aead_givcrypt_request *req,
99 u8 *giv, u64 seq)
100{
101 req->giv = giv;
102 req->seq = seq;
103}
104
105#endif /* _CRYPTO_AEAD_H */
diff --git a/include/crypto/aes.h b/include/crypto/aes.h
new file mode 100644
index 000000000000..d480b76715a8
--- /dev/null
+++ b/include/crypto/aes.h
@@ -0,0 +1,31 @@
1/*
2 * Common values for AES algorithms
3 */
4
5#ifndef _CRYPTO_AES_H
6#define _CRYPTO_AES_H
7
8#include <linux/types.h>
9#include <linux/crypto.h>
10
11#define AES_MIN_KEY_SIZE 16
12#define AES_MAX_KEY_SIZE 32
13#define AES_KEYSIZE_128 16
14#define AES_KEYSIZE_192 24
15#define AES_KEYSIZE_256 32
16#define AES_BLOCK_SIZE 16
17
18struct crypto_aes_ctx {
19 u32 key_length;
20 u32 key_enc[60];
21 u32 key_dec[60];
22};
23
24extern u32 crypto_ft_tab[4][256];
25extern u32 crypto_fl_tab[4][256];
26extern u32 crypto_it_tab[4][256];
27extern u32 crypto_il_tab[4][256];
28
29int crypto_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
30 unsigned int key_len);
31#endif
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
index b9b05d399d2b..60d06e784be3 100644
--- a/include/crypto/algapi.h
+++ b/include/crypto/algapi.h
@@ -111,8 +111,15 @@ void crypto_drop_spawn(struct crypto_spawn *spawn);
111struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type, 111struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
112 u32 mask); 112 u32 mask);
113 113
114static inline void crypto_set_spawn(struct crypto_spawn *spawn,
115 struct crypto_instance *inst)
116{
117 spawn->inst = inst;
118}
119
114struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb); 120struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
115int crypto_check_attr_type(struct rtattr **tb, u32 type); 121int crypto_check_attr_type(struct rtattr **tb, u32 type);
122const char *crypto_attr_alg_name(struct rtattr *rta);
116struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask); 123struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
117int crypto_attr_u32(struct rtattr *rta, u32 *num); 124int crypto_attr_u32(struct rtattr *rta, u32 *num);
118struct crypto_instance *crypto_alloc_instance(const char *name, 125struct crypto_instance *crypto_alloc_instance(const char *name,
@@ -124,6 +131,10 @@ int crypto_enqueue_request(struct crypto_queue *queue,
124struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue); 131struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue);
125int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm); 132int crypto_tfm_in_queue(struct crypto_queue *queue, struct crypto_tfm *tfm);
126 133
134/* These functions require the input/output to be aligned as u32. */
135void crypto_inc(u8 *a, unsigned int size);
136void crypto_xor(u8 *dst, const u8 *src, unsigned int size);
137
127int blkcipher_walk_done(struct blkcipher_desc *desc, 138int blkcipher_walk_done(struct blkcipher_desc *desc,
128 struct blkcipher_walk *walk, int err); 139 struct blkcipher_walk *walk, int err);
129int blkcipher_walk_virt(struct blkcipher_desc *desc, 140int blkcipher_walk_virt(struct blkcipher_desc *desc,
@@ -187,20 +198,11 @@ static inline struct crypto_instance *crypto_aead_alg_instance(
187 return crypto_tfm_alg_instance(&aead->base); 198 return crypto_tfm_alg_instance(&aead->base);
188} 199}
189 200
190static inline struct crypto_ablkcipher *crypto_spawn_ablkcipher(
191 struct crypto_spawn *spawn)
192{
193 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
194 u32 mask = CRYPTO_ALG_TYPE_MASK;
195
196 return __crypto_ablkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
197}
198
199static inline struct crypto_blkcipher *crypto_spawn_blkcipher( 201static inline struct crypto_blkcipher *crypto_spawn_blkcipher(
200 struct crypto_spawn *spawn) 202 struct crypto_spawn *spawn)
201{ 203{
202 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER; 204 u32 type = CRYPTO_ALG_TYPE_BLKCIPHER;
203 u32 mask = CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; 205 u32 mask = CRYPTO_ALG_TYPE_MASK;
204 206
205 return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask)); 207 return __crypto_blkcipher_cast(crypto_spawn_tfm(spawn, type, mask));
206} 208}
@@ -303,5 +305,14 @@ static inline struct crypto_alg *crypto_get_attr_alg(struct rtattr **tb,
303 return crypto_attr_alg(tb[1], type, mask); 305 return crypto_attr_alg(tb[1], type, mask);
304} 306}
305 307
308/*
309 * Returns CRYPTO_ALG_ASYNC if type/mask requires the use of sync algorithms.
310 * Otherwise returns zero.
311 */
312static inline int crypto_requires_sync(u32 type, u32 mask)
313{
314 return (type ^ CRYPTO_ALG_ASYNC) & mask & CRYPTO_ALG_ASYNC;
315}
316
306#endif /* _CRYPTO_ALGAPI_H */ 317#endif /* _CRYPTO_ALGAPI_H */
307 318
diff --git a/include/crypto/authenc.h b/include/crypto/authenc.h
new file mode 100644
index 000000000000..e47b044929a8
--- /dev/null
+++ b/include/crypto/authenc.h
@@ -0,0 +1,27 @@
1/*
2 * Authenc: Simple AEAD wrapper for IPsec
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12#ifndef _CRYPTO_AUTHENC_H
13#define _CRYPTO_AUTHENC_H
14
15#include <linux/types.h>
16
17enum {
18 CRYPTO_AUTHENC_KEYA_UNSPEC,
19 CRYPTO_AUTHENC_KEYA_PARAM,
20};
21
22struct crypto_authenc_key_param {
23 __be32 enckeylen;
24};
25
26#endif /* _CRYPTO_AUTHENC_H */
27
diff --git a/include/crypto/ctr.h b/include/crypto/ctr.h
new file mode 100644
index 000000000000..4180fc080e3b
--- /dev/null
+++ b/include/crypto/ctr.h
@@ -0,0 +1,20 @@
1/*
2 * CTR: Counter mode
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_CTR_H
14#define _CRYPTO_CTR_H
15
16#define CTR_RFC3686_NONCE_SIZE 4
17#define CTR_RFC3686_IV_SIZE 8
18#define CTR_RFC3686_BLOCK_SIZE 16
19
20#endif /* _CRYPTO_CTR_H */
diff --git a/include/crypto/des.h b/include/crypto/des.h
new file mode 100644
index 000000000000..2971c6304ade
--- /dev/null
+++ b/include/crypto/des.h
@@ -0,0 +1,19 @@
1/*
2 * DES & Triple DES EDE Cipher Algorithms.
3 */
4
5#ifndef __CRYPTO_DES_H
6#define __CRYPTO_DES_H
7
8#define DES_KEY_SIZE 8
9#define DES_EXPKEY_WORDS 32
10#define DES_BLOCK_SIZE 8
11
12#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
13#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
14#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
15
16
17extern unsigned long des_ekey(u32 *pe, const u8 *k);
18
19#endif /* __CRYPTO_DES_H */
diff --git a/include/crypto/internal/aead.h b/include/crypto/internal/aead.h
new file mode 100644
index 000000000000..d838c945575a
--- /dev/null
+++ b/include/crypto/internal/aead.h
@@ -0,0 +1,80 @@
1/*
2 * AEAD: Authenticated Encryption with Associated Data
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_INTERNAL_AEAD_H
14#define _CRYPTO_INTERNAL_AEAD_H
15
16#include <crypto/aead.h>
17#include <crypto/algapi.h>
18#include <linux/types.h>
19
20struct rtattr;
21
22struct crypto_aead_spawn {
23 struct crypto_spawn base;
24};
25
26extern const struct crypto_type crypto_nivaead_type;
27
28static inline void crypto_set_aead_spawn(
29 struct crypto_aead_spawn *spawn, struct crypto_instance *inst)
30{
31 crypto_set_spawn(&spawn->base, inst);
32}
33
34int crypto_grab_aead(struct crypto_aead_spawn *spawn, const char *name,
35 u32 type, u32 mask);
36
37static inline void crypto_drop_aead(struct crypto_aead_spawn *spawn)
38{
39 crypto_drop_spawn(&spawn->base);
40}
41
42static inline struct crypto_alg *crypto_aead_spawn_alg(
43 struct crypto_aead_spawn *spawn)
44{
45 return spawn->base.alg;
46}
47
48static inline struct crypto_aead *crypto_spawn_aead(
49 struct crypto_aead_spawn *spawn)
50{
51 return __crypto_aead_cast(
52 crypto_spawn_tfm(&spawn->base, CRYPTO_ALG_TYPE_AEAD,
53 CRYPTO_ALG_TYPE_MASK));
54}
55
56struct crypto_instance *aead_geniv_alloc(struct crypto_template *tmpl,
57 struct rtattr **tb, u32 type,
58 u32 mask);
59void aead_geniv_free(struct crypto_instance *inst);
60int aead_geniv_init(struct crypto_tfm *tfm);
61void aead_geniv_exit(struct crypto_tfm *tfm);
62
63static inline struct crypto_aead *aead_geniv_base(struct crypto_aead *geniv)
64{
65 return crypto_aead_crt(geniv)->base;
66}
67
68static inline void *aead_givcrypt_reqctx(struct aead_givcrypt_request *req)
69{
70 return aead_request_ctx(&req->areq);
71}
72
73static inline void aead_givcrypt_complete(struct aead_givcrypt_request *req,
74 int err)
75{
76 aead_request_complete(&req->areq, err);
77}
78
79#endif /* _CRYPTO_INTERNAL_AEAD_H */
80
diff --git a/include/crypto/internal/skcipher.h b/include/crypto/internal/skcipher.h
new file mode 100644
index 000000000000..2ba42cd7d6aa
--- /dev/null
+++ b/include/crypto/internal/skcipher.h
@@ -0,0 +1,110 @@
1/*
2 * Symmetric key ciphers.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_INTERNAL_SKCIPHER_H
14#define _CRYPTO_INTERNAL_SKCIPHER_H
15
16#include <crypto/algapi.h>
17#include <crypto/skcipher.h>
18#include <linux/types.h>
19
20struct rtattr;
21
22struct crypto_skcipher_spawn {
23 struct crypto_spawn base;
24};
25
26extern const struct crypto_type crypto_givcipher_type;
27
28static inline void crypto_set_skcipher_spawn(
29 struct crypto_skcipher_spawn *spawn, struct crypto_instance *inst)
30{
31 crypto_set_spawn(&spawn->base, inst);
32}
33
34int crypto_grab_skcipher(struct crypto_skcipher_spawn *spawn, const char *name,
35 u32 type, u32 mask);
36
37static inline void crypto_drop_skcipher(struct crypto_skcipher_spawn *spawn)
38{
39 crypto_drop_spawn(&spawn->base);
40}
41
42static inline struct crypto_alg *crypto_skcipher_spawn_alg(
43 struct crypto_skcipher_spawn *spawn)
44{
45 return spawn->base.alg;
46}
47
48static inline struct crypto_ablkcipher *crypto_spawn_skcipher(
49 struct crypto_skcipher_spawn *spawn)
50{
51 return __crypto_ablkcipher_cast(
52 crypto_spawn_tfm(&spawn->base, crypto_skcipher_type(0),
53 crypto_skcipher_mask(0)));
54}
55
56int skcipher_null_givencrypt(struct skcipher_givcrypt_request *req);
57int skcipher_null_givdecrypt(struct skcipher_givcrypt_request *req);
58const char *crypto_default_geniv(const struct crypto_alg *alg);
59
60struct crypto_instance *skcipher_geniv_alloc(struct crypto_template *tmpl,
61 struct rtattr **tb, u32 type,
62 u32 mask);
63void skcipher_geniv_free(struct crypto_instance *inst);
64int skcipher_geniv_init(struct crypto_tfm *tfm);
65void skcipher_geniv_exit(struct crypto_tfm *tfm);
66
67static inline struct crypto_ablkcipher *skcipher_geniv_cipher(
68 struct crypto_ablkcipher *geniv)
69{
70 return crypto_ablkcipher_crt(geniv)->base;
71}
72
73static inline int skcipher_enqueue_givcrypt(
74 struct crypto_queue *queue, struct skcipher_givcrypt_request *request)
75{
76 return ablkcipher_enqueue_request(queue, &request->creq);
77}
78
79static inline struct skcipher_givcrypt_request *skcipher_dequeue_givcrypt(
80 struct crypto_queue *queue)
81{
82 return container_of(ablkcipher_dequeue_request(queue),
83 struct skcipher_givcrypt_request, creq);
84}
85
86static inline void *skcipher_givcrypt_reqctx(
87 struct skcipher_givcrypt_request *req)
88{
89 return ablkcipher_request_ctx(&req->creq);
90}
91
92static inline void ablkcipher_request_complete(struct ablkcipher_request *req,
93 int err)
94{
95 req->base.complete(&req->base, err);
96}
97
98static inline void skcipher_givcrypt_complete(
99 struct skcipher_givcrypt_request *req, int err)
100{
101 ablkcipher_request_complete(&req->creq, err);
102}
103
104static inline u32 ablkcipher_request_flags(struct ablkcipher_request *req)
105{
106 return req->base.flags;
107}
108
109#endif /* _CRYPTO_INTERNAL_SKCIPHER_H */
110
diff --git a/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 87ed681cceba..224658b8d806 100644
--- a/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -1,9 +1,10 @@
1/* 1/*
2 * Cryptographic API. 2 * Cryptographic scatter and gather helpers.
3 * 3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com> 5 * Copyright (c) 2002 Adam J. Richter <adam@yggdrasil.com>
6 * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com> 6 * Copyright (c) 2004 Jean-Luc Cooke <jlcooke@certainkey.com>
7 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free 10 * under the terms of the GNU General Public License as published by the Free
@@ -15,14 +16,52 @@
15#ifndef _CRYPTO_SCATTERWALK_H 16#ifndef _CRYPTO_SCATTERWALK_H
16#define _CRYPTO_SCATTERWALK_H 17#define _CRYPTO_SCATTERWALK_H
17 18
19#include <asm/kmap_types.h>
20#include <crypto/algapi.h>
21#include <linux/hardirq.h>
22#include <linux/highmem.h>
23#include <linux/kernel.h>
18#include <linux/mm.h> 24#include <linux/mm.h>
19#include <linux/scatterlist.h> 25#include <linux/scatterlist.h>
26#include <linux/sched.h>
20 27
21#include "internal.h" 28static inline enum km_type crypto_kmap_type(int out)
29{
30 enum km_type type;
31
32 if (in_softirq())
33 type = out * (KM_SOFTIRQ1 - KM_SOFTIRQ0) + KM_SOFTIRQ0;
34 else
35 type = out * (KM_USER1 - KM_USER0) + KM_USER0;
36
37 return type;
38}
39
40static inline void *crypto_kmap(struct page *page, int out)
41{
42 return kmap_atomic(page, crypto_kmap_type(out));
43}
44
45static inline void crypto_kunmap(void *vaddr, int out)
46{
47 kunmap_atomic(vaddr, crypto_kmap_type(out));
48}
49
50static inline void crypto_yield(u32 flags)
51{
52 if (flags & CRYPTO_TFM_REQ_MAY_SLEEP)
53 cond_resched();
54}
55
56static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num,
57 struct scatterlist *sg2)
58{
59 sg_set_page(&sg1[num - 1], (void *)sg2, 0, 0);
60}
22 61
23static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg) 62static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg)
24{ 63{
25 return (++sg)->length ? sg : (void *) sg_page(sg); 64 return (++sg)->length ? sg : (void *)sg_page(sg);
26} 65}
27 66
28static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in, 67static inline unsigned long scatterwalk_samebuf(struct scatter_walk *walk_in,
diff --git a/include/crypto/sha.h b/include/crypto/sha.h
index 0686e1f7a24b..c0ccc2b1a2d8 100644
--- a/include/crypto/sha.h
+++ b/include/crypto/sha.h
@@ -8,6 +8,9 @@
8#define SHA1_DIGEST_SIZE 20 8#define SHA1_DIGEST_SIZE 20
9#define SHA1_BLOCK_SIZE 64 9#define SHA1_BLOCK_SIZE 64
10 10
11#define SHA224_DIGEST_SIZE 28
12#define SHA224_BLOCK_SIZE 64
13
11#define SHA256_DIGEST_SIZE 32 14#define SHA256_DIGEST_SIZE 32
12#define SHA256_BLOCK_SIZE 64 15#define SHA256_BLOCK_SIZE 64
13 16
@@ -23,6 +26,15 @@
23#define SHA1_H3 0x10325476UL 26#define SHA1_H3 0x10325476UL
24#define SHA1_H4 0xc3d2e1f0UL 27#define SHA1_H4 0xc3d2e1f0UL
25 28
29#define SHA224_H0 0xc1059ed8UL
30#define SHA224_H1 0x367cd507UL
31#define SHA224_H2 0x3070dd17UL
32#define SHA224_H3 0xf70e5939UL
33#define SHA224_H4 0xffc00b31UL
34#define SHA224_H5 0x68581511UL
35#define SHA224_H6 0x64f98fa7UL
36#define SHA224_H7 0xbefa4fa4UL
37
26#define SHA256_H0 0x6a09e667UL 38#define SHA256_H0 0x6a09e667UL
27#define SHA256_H1 0xbb67ae85UL 39#define SHA256_H1 0xbb67ae85UL
28#define SHA256_H2 0x3c6ef372UL 40#define SHA256_H2 0x3c6ef372UL
diff --git a/include/crypto/skcipher.h b/include/crypto/skcipher.h
new file mode 100644
index 000000000000..25fd6126522d
--- /dev/null
+++ b/include/crypto/skcipher.h
@@ -0,0 +1,110 @@
1/*
2 * Symmetric key ciphers.
3 *
4 * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_SKCIPHER_H
14#define _CRYPTO_SKCIPHER_H
15
16#include <linux/crypto.h>
17#include <linux/kernel.h>
18#include <linux/slab.h>
19
20/**
21 * struct skcipher_givcrypt_request - Crypto request with IV generation
22 * @seq: Sequence number for IV generation
23 * @giv: Space for generated IV
24 * @creq: The crypto request itself
25 */
26struct skcipher_givcrypt_request {
27 u64 seq;
28 u8 *giv;
29
30 struct ablkcipher_request creq;
31};
32
33static inline struct crypto_ablkcipher *skcipher_givcrypt_reqtfm(
34 struct skcipher_givcrypt_request *req)
35{
36 return crypto_ablkcipher_reqtfm(&req->creq);
37}
38
39static inline int crypto_skcipher_givencrypt(
40 struct skcipher_givcrypt_request *req)
41{
42 struct ablkcipher_tfm *crt =
43 crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req));
44 return crt->givencrypt(req);
45};
46
47static inline int crypto_skcipher_givdecrypt(
48 struct skcipher_givcrypt_request *req)
49{
50 struct ablkcipher_tfm *crt =
51 crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req));
52 return crt->givdecrypt(req);
53};
54
55static inline void skcipher_givcrypt_set_tfm(
56 struct skcipher_givcrypt_request *req, struct crypto_ablkcipher *tfm)
57{
58 req->creq.base.tfm = crypto_ablkcipher_tfm(tfm);
59}
60
61static inline struct skcipher_givcrypt_request *skcipher_givcrypt_cast(
62 struct crypto_async_request *req)
63{
64 return container_of(ablkcipher_request_cast(req),
65 struct skcipher_givcrypt_request, creq);
66}
67
68static inline struct skcipher_givcrypt_request *skcipher_givcrypt_alloc(
69 struct crypto_ablkcipher *tfm, gfp_t gfp)
70{
71 struct skcipher_givcrypt_request *req;
72
73 req = kmalloc(sizeof(struct skcipher_givcrypt_request) +
74 crypto_ablkcipher_reqsize(tfm), gfp);
75
76 if (likely(req))
77 skcipher_givcrypt_set_tfm(req, tfm);
78
79 return req;
80}
81
82static inline void skcipher_givcrypt_free(struct skcipher_givcrypt_request *req)
83{
84 kfree(req);
85}
86
87static inline void skcipher_givcrypt_set_callback(
88 struct skcipher_givcrypt_request *req, u32 flags,
89 crypto_completion_t complete, void *data)
90{
91 ablkcipher_request_set_callback(&req->creq, flags, complete, data);
92}
93
94static inline void skcipher_givcrypt_set_crypt(
95 struct skcipher_givcrypt_request *req,
96 struct scatterlist *src, struct scatterlist *dst,
97 unsigned int nbytes, void *iv)
98{
99 ablkcipher_request_set_crypt(&req->creq, src, dst, nbytes, iv);
100}
101
102static inline void skcipher_givcrypt_set_giv(
103 struct skcipher_givcrypt_request *req, u8 *giv, u64 seq)
104{
105 req->giv = giv;
106 req->seq = seq;
107}
108
109#endif /* _CRYPTO_SKCIPHER_H */
110
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index f3110ebe894a..5e02d1b46370 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -33,10 +33,13 @@
33#define CRYPTO_ALG_TYPE_DIGEST 0x00000002 33#define CRYPTO_ALG_TYPE_DIGEST 0x00000002
34#define CRYPTO_ALG_TYPE_HASH 0x00000003 34#define CRYPTO_ALG_TYPE_HASH 0x00000003
35#define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004 35#define CRYPTO_ALG_TYPE_BLKCIPHER 0x00000004
36#define CRYPTO_ALG_TYPE_COMPRESS 0x00000005 36#define CRYPTO_ALG_TYPE_ABLKCIPHER 0x00000005
37#define CRYPTO_ALG_TYPE_AEAD 0x00000006 37#define CRYPTO_ALG_TYPE_GIVCIPHER 0x00000006
38#define CRYPTO_ALG_TYPE_COMPRESS 0x00000008
39#define CRYPTO_ALG_TYPE_AEAD 0x00000009
38 40
39#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e 41#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
42#define CRYPTO_ALG_TYPE_BLKCIPHER_MASK 0x0000000c
40 43
41#define CRYPTO_ALG_LARVAL 0x00000010 44#define CRYPTO_ALG_LARVAL 0x00000010
42#define CRYPTO_ALG_DEAD 0x00000020 45#define CRYPTO_ALG_DEAD 0x00000020
@@ -50,6 +53,12 @@
50#define CRYPTO_ALG_NEED_FALLBACK 0x00000100 53#define CRYPTO_ALG_NEED_FALLBACK 0x00000100
51 54
52/* 55/*
56 * This bit is set for symmetric key ciphers that have already been wrapped
57 * with a generic IV generator to prevent them from being wrapped again.
58 */
59#define CRYPTO_ALG_GENIV 0x00000200
60
61/*
53 * Transform masks and values (for crt_flags). 62 * Transform masks and values (for crt_flags).
54 */ 63 */
55#define CRYPTO_TFM_REQ_MASK 0x000fff00 64#define CRYPTO_TFM_REQ_MASK 0x000fff00
@@ -81,13 +90,11 @@
81#define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN 90#define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN
82#elif defined(ARCH_SLAB_MINALIGN) 91#elif defined(ARCH_SLAB_MINALIGN)
83#define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN 92#define CRYPTO_MINALIGN ARCH_SLAB_MINALIGN
93#else
94#define CRYPTO_MINALIGN __alignof__(unsigned long long)
84#endif 95#endif
85 96
86#ifdef CRYPTO_MINALIGN
87#define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN))) 97#define CRYPTO_MINALIGN_ATTR __attribute__ ((__aligned__(CRYPTO_MINALIGN)))
88#else
89#define CRYPTO_MINALIGN_ATTR
90#endif
91 98
92struct scatterlist; 99struct scatterlist;
93struct crypto_ablkcipher; 100struct crypto_ablkcipher;
@@ -97,6 +104,8 @@ struct crypto_blkcipher;
97struct crypto_hash; 104struct crypto_hash;
98struct crypto_tfm; 105struct crypto_tfm;
99struct crypto_type; 106struct crypto_type;
107struct aead_givcrypt_request;
108struct skcipher_givcrypt_request;
100 109
101typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err); 110typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);
102 111
@@ -176,6 +185,10 @@ struct ablkcipher_alg {
176 unsigned int keylen); 185 unsigned int keylen);
177 int (*encrypt)(struct ablkcipher_request *req); 186 int (*encrypt)(struct ablkcipher_request *req);
178 int (*decrypt)(struct ablkcipher_request *req); 187 int (*decrypt)(struct ablkcipher_request *req);
188 int (*givencrypt)(struct skcipher_givcrypt_request *req);
189 int (*givdecrypt)(struct skcipher_givcrypt_request *req);
190
191 const char *geniv;
179 192
180 unsigned int min_keysize; 193 unsigned int min_keysize;
181 unsigned int max_keysize; 194 unsigned int max_keysize;
@@ -185,11 +198,16 @@ struct ablkcipher_alg {
185struct aead_alg { 198struct aead_alg {
186 int (*setkey)(struct crypto_aead *tfm, const u8 *key, 199 int (*setkey)(struct crypto_aead *tfm, const u8 *key,
187 unsigned int keylen); 200 unsigned int keylen);
201 int (*setauthsize)(struct crypto_aead *tfm, unsigned int authsize);
188 int (*encrypt)(struct aead_request *req); 202 int (*encrypt)(struct aead_request *req);
189 int (*decrypt)(struct aead_request *req); 203 int (*decrypt)(struct aead_request *req);
204 int (*givencrypt)(struct aead_givcrypt_request *req);
205 int (*givdecrypt)(struct aead_givcrypt_request *req);
206
207 const char *geniv;
190 208
191 unsigned int ivsize; 209 unsigned int ivsize;
192 unsigned int authsize; 210 unsigned int maxauthsize;
193}; 211};
194 212
195struct blkcipher_alg { 213struct blkcipher_alg {
@@ -202,6 +220,8 @@ struct blkcipher_alg {
202 struct scatterlist *dst, struct scatterlist *src, 220 struct scatterlist *dst, struct scatterlist *src,
203 unsigned int nbytes); 221 unsigned int nbytes);
204 222
223 const char *geniv;
224
205 unsigned int min_keysize; 225 unsigned int min_keysize;
206 unsigned int max_keysize; 226 unsigned int max_keysize;
207 unsigned int ivsize; 227 unsigned int ivsize;
@@ -317,6 +337,11 @@ struct ablkcipher_tfm {
317 unsigned int keylen); 337 unsigned int keylen);
318 int (*encrypt)(struct ablkcipher_request *req); 338 int (*encrypt)(struct ablkcipher_request *req);
319 int (*decrypt)(struct ablkcipher_request *req); 339 int (*decrypt)(struct ablkcipher_request *req);
340 int (*givencrypt)(struct skcipher_givcrypt_request *req);
341 int (*givdecrypt)(struct skcipher_givcrypt_request *req);
342
343 struct crypto_ablkcipher *base;
344
320 unsigned int ivsize; 345 unsigned int ivsize;
321 unsigned int reqsize; 346 unsigned int reqsize;
322}; 347};
@@ -326,6 +351,11 @@ struct aead_tfm {
326 unsigned int keylen); 351 unsigned int keylen);
327 int (*encrypt)(struct aead_request *req); 352 int (*encrypt)(struct aead_request *req);
328 int (*decrypt)(struct aead_request *req); 353 int (*decrypt)(struct aead_request *req);
354 int (*givencrypt)(struct aead_givcrypt_request *req);
355 int (*givdecrypt)(struct aead_givcrypt_request *req);
356
357 struct crypto_aead *base;
358
329 unsigned int ivsize; 359 unsigned int ivsize;
330 unsigned int authsize; 360 unsigned int authsize;
331 unsigned int reqsize; 361 unsigned int reqsize;
@@ -525,17 +555,23 @@ static inline struct crypto_ablkcipher *__crypto_ablkcipher_cast(
525 return (struct crypto_ablkcipher *)tfm; 555 return (struct crypto_ablkcipher *)tfm;
526} 556}
527 557
528static inline struct crypto_ablkcipher *crypto_alloc_ablkcipher( 558static inline u32 crypto_skcipher_type(u32 type)
529 const char *alg_name, u32 type, u32 mask)
530{ 559{
531 type &= ~CRYPTO_ALG_TYPE_MASK; 560 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
532 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 561 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
533 mask |= CRYPTO_ALG_TYPE_MASK; 562 return type;
563}
534 564
535 return __crypto_ablkcipher_cast( 565static inline u32 crypto_skcipher_mask(u32 mask)
536 crypto_alloc_base(alg_name, type, mask)); 566{
567 mask &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_GENIV);
568 mask |= CRYPTO_ALG_TYPE_BLKCIPHER_MASK;
569 return mask;
537} 570}
538 571
572struct crypto_ablkcipher *crypto_alloc_ablkcipher(const char *alg_name,
573 u32 type, u32 mask);
574
539static inline struct crypto_tfm *crypto_ablkcipher_tfm( 575static inline struct crypto_tfm *crypto_ablkcipher_tfm(
540 struct crypto_ablkcipher *tfm) 576 struct crypto_ablkcipher *tfm)
541{ 577{
@@ -550,11 +586,8 @@ static inline void crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
550static inline int crypto_has_ablkcipher(const char *alg_name, u32 type, 586static inline int crypto_has_ablkcipher(const char *alg_name, u32 type,
551 u32 mask) 587 u32 mask)
552{ 588{
553 type &= ~CRYPTO_ALG_TYPE_MASK; 589 return crypto_has_alg(alg_name, crypto_skcipher_type(type),
554 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 590 crypto_skcipher_mask(mask));
555 mask |= CRYPTO_ALG_TYPE_MASK;
556
557 return crypto_has_alg(alg_name, type, mask);
558} 591}
559 592
560static inline struct ablkcipher_tfm *crypto_ablkcipher_crt( 593static inline struct ablkcipher_tfm *crypto_ablkcipher_crt(
@@ -601,7 +634,9 @@ static inline void crypto_ablkcipher_clear_flags(struct crypto_ablkcipher *tfm,
601static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, 634static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm,
602 const u8 *key, unsigned int keylen) 635 const u8 *key, unsigned int keylen)
603{ 636{
604 return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen); 637 struct ablkcipher_tfm *crt = crypto_ablkcipher_crt(tfm);
638
639 return crt->setkey(crt->base, key, keylen);
605} 640}
606 641
607static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm( 642static inline struct crypto_ablkcipher *crypto_ablkcipher_reqtfm(
@@ -633,7 +668,7 @@ static inline unsigned int crypto_ablkcipher_reqsize(
633static inline void ablkcipher_request_set_tfm( 668static inline void ablkcipher_request_set_tfm(
634 struct ablkcipher_request *req, struct crypto_ablkcipher *tfm) 669 struct ablkcipher_request *req, struct crypto_ablkcipher *tfm)
635{ 670{
636 req->base.tfm = crypto_ablkcipher_tfm(tfm); 671 req->base.tfm = crypto_ablkcipher_tfm(crypto_ablkcipher_crt(tfm)->base);
637} 672}
638 673
639static inline struct ablkcipher_request *ablkcipher_request_cast( 674static inline struct ablkcipher_request *ablkcipher_request_cast(
@@ -686,15 +721,7 @@ static inline struct crypto_aead *__crypto_aead_cast(struct crypto_tfm *tfm)
686 return (struct crypto_aead *)tfm; 721 return (struct crypto_aead *)tfm;
687} 722}
688 723
689static inline struct crypto_aead *crypto_alloc_aead(const char *alg_name, 724struct crypto_aead *crypto_alloc_aead(const char *alg_name, u32 type, u32 mask);
690 u32 type, u32 mask)
691{
692 type &= ~CRYPTO_ALG_TYPE_MASK;
693 type |= CRYPTO_ALG_TYPE_AEAD;
694 mask |= CRYPTO_ALG_TYPE_MASK;
695
696 return __crypto_aead_cast(crypto_alloc_base(alg_name, type, mask));
697}
698 725
699static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm) 726static inline struct crypto_tfm *crypto_aead_tfm(struct crypto_aead *tfm)
700{ 727{
@@ -749,9 +776,13 @@ static inline void crypto_aead_clear_flags(struct crypto_aead *tfm, u32 flags)
749static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key, 776static inline int crypto_aead_setkey(struct crypto_aead *tfm, const u8 *key,
750 unsigned int keylen) 777 unsigned int keylen)
751{ 778{
752 return crypto_aead_crt(tfm)->setkey(tfm, key, keylen); 779 struct aead_tfm *crt = crypto_aead_crt(tfm);
780
781 return crt->setkey(crt->base, key, keylen);
753} 782}
754 783
784int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize);
785
755static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req) 786static inline struct crypto_aead *crypto_aead_reqtfm(struct aead_request *req)
756{ 787{
757 return __crypto_aead_cast(req->base.tfm); 788 return __crypto_aead_cast(req->base.tfm);
@@ -775,7 +806,7 @@ static inline unsigned int crypto_aead_reqsize(struct crypto_aead *tfm)
775static inline void aead_request_set_tfm(struct aead_request *req, 806static inline void aead_request_set_tfm(struct aead_request *req,
776 struct crypto_aead *tfm) 807 struct crypto_aead *tfm)
777{ 808{
778 req->base.tfm = crypto_aead_tfm(tfm); 809 req->base.tfm = crypto_aead_tfm(crypto_aead_crt(tfm)->base);
779} 810}
780 811
781static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm, 812static inline struct aead_request *aead_request_alloc(struct crypto_aead *tfm,
@@ -841,9 +872,9 @@ static inline struct crypto_blkcipher *crypto_blkcipher_cast(
841static inline struct crypto_blkcipher *crypto_alloc_blkcipher( 872static inline struct crypto_blkcipher *crypto_alloc_blkcipher(
842 const char *alg_name, u32 type, u32 mask) 873 const char *alg_name, u32 type, u32 mask)
843{ 874{
844 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 875 type &= ~CRYPTO_ALG_TYPE_MASK;
845 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 876 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
846 mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; 877 mask |= CRYPTO_ALG_TYPE_MASK;
847 878
848 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask)); 879 return __crypto_blkcipher_cast(crypto_alloc_base(alg_name, type, mask));
849} 880}
@@ -861,9 +892,9 @@ static inline void crypto_free_blkcipher(struct crypto_blkcipher *tfm)
861 892
862static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask) 893static inline int crypto_has_blkcipher(const char *alg_name, u32 type, u32 mask)
863{ 894{
864 type &= ~(CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC); 895 type &= ~CRYPTO_ALG_TYPE_MASK;
865 type |= CRYPTO_ALG_TYPE_BLKCIPHER; 896 type |= CRYPTO_ALG_TYPE_BLKCIPHER;
866 mask |= CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_ASYNC; 897 mask |= CRYPTO_ALG_TYPE_MASK;
867 898
868 return crypto_has_alg(alg_name, type, mask); 899 return crypto_has_alg(alg_name, type, mask);
869} 900}
@@ -1081,6 +1112,7 @@ static inline struct crypto_hash *crypto_alloc_hash(const char *alg_name,
1081 u32 type, u32 mask) 1112 u32 type, u32 mask)
1082{ 1113{
1083 type &= ~CRYPTO_ALG_TYPE_MASK; 1114 type &= ~CRYPTO_ALG_TYPE_MASK;
1115 mask &= ~CRYPTO_ALG_TYPE_MASK;
1084 type |= CRYPTO_ALG_TYPE_HASH; 1116 type |= CRYPTO_ALG_TYPE_HASH;
1085 mask |= CRYPTO_ALG_TYPE_HASH_MASK; 1117 mask |= CRYPTO_ALG_TYPE_HASH_MASK;
1086 1118
@@ -1100,6 +1132,7 @@ static inline void crypto_free_hash(struct crypto_hash *tfm)
1100static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask) 1132static inline int crypto_has_hash(const char *alg_name, u32 type, u32 mask)
1101{ 1133{
1102 type &= ~CRYPTO_ALG_TYPE_MASK; 1134 type &= ~CRYPTO_ALG_TYPE_MASK;
1135 mask &= ~CRYPTO_ALG_TYPE_MASK;
1103 type |= CRYPTO_ALG_TYPE_HASH; 1136 type |= CRYPTO_ALG_TYPE_HASH;
1104 mask |= CRYPTO_ALG_TYPE_HASH_MASK; 1137 mask |= CRYPTO_ALG_TYPE_HASH_MASK;
1105 1138
diff --git a/include/linux/device.h b/include/linux/device.h
index 2e15822fe409..1880208964d6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -25,75 +25,69 @@
25#include <asm/device.h> 25#include <asm/device.h>
26 26
27#define DEVICE_NAME_SIZE 50 27#define DEVICE_NAME_SIZE 50
28#define DEVICE_NAME_HALF __stringify(20) /* Less than half to accommodate slop */ 28/* DEVICE_NAME_HALF is really less than half to accommodate slop */
29#define DEVICE_NAME_HALF __stringify(20)
29#define DEVICE_ID_SIZE 32 30#define DEVICE_ID_SIZE 32
30#define BUS_ID_SIZE KOBJ_NAME_LEN 31#define BUS_ID_SIZE KOBJ_NAME_LEN
31 32
32 33
33struct device; 34struct device;
34struct device_driver; 35struct device_driver;
36struct driver_private;
35struct class; 37struct class;
36struct class_device; 38struct class_device;
37struct bus_type; 39struct bus_type;
40struct bus_type_private;
38 41
39struct bus_attribute { 42struct bus_attribute {
40 struct attribute attr; 43 struct attribute attr;
41 ssize_t (*show)(struct bus_type *, char * buf); 44 ssize_t (*show)(struct bus_type *bus, char *buf);
42 ssize_t (*store)(struct bus_type *, const char * buf, size_t count); 45 ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
43}; 46};
44 47
45#define BUS_ATTR(_name,_mode,_show,_store) \ 48#define BUS_ATTR(_name, _mode, _show, _store) \
46struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store) 49struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
47 50
48extern int __must_check bus_create_file(struct bus_type *, 51extern int __must_check bus_create_file(struct bus_type *,
49 struct bus_attribute *); 52 struct bus_attribute *);
50extern void bus_remove_file(struct bus_type *, struct bus_attribute *); 53extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
51 54
52struct bus_type { 55struct bus_type {
53 const char * name; 56 const char *name;
54 struct module * owner; 57 struct bus_attribute *bus_attrs;
58 struct device_attribute *dev_attrs;
59 struct driver_attribute *drv_attrs;
55 60
56 struct kset subsys; 61 int (*match)(struct device *dev, struct device_driver *drv);
57 struct kset drivers; 62 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
58 struct kset devices; 63 int (*probe)(struct device *dev);
59 struct klist klist_devices; 64 int (*remove)(struct device *dev);
60 struct klist klist_drivers; 65 void (*shutdown)(struct device *dev);
61
62 struct blocking_notifier_head bus_notifier;
63
64 struct bus_attribute * bus_attrs;
65 struct device_attribute * dev_attrs;
66 struct driver_attribute * drv_attrs;
67
68 int (*match)(struct device * dev, struct device_driver * drv);
69 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
70 int (*probe)(struct device * dev);
71 int (*remove)(struct device * dev);
72 void (*shutdown)(struct device * dev);
73 66
74 int (*suspend)(struct device * dev, pm_message_t state); 67 int (*suspend)(struct device *dev, pm_message_t state);
75 int (*suspend_late)(struct device * dev, pm_message_t state); 68 int (*suspend_late)(struct device *dev, pm_message_t state);
76 int (*resume_early)(struct device * dev); 69 int (*resume_early)(struct device *dev);
77 int (*resume)(struct device * dev); 70 int (*resume)(struct device *dev);
78 71
79 unsigned int drivers_autoprobe:1; 72 struct bus_type_private *p;
80}; 73};
81 74
82extern int __must_check bus_register(struct bus_type * bus); 75extern int __must_check bus_register(struct bus_type *bus);
83extern void bus_unregister(struct bus_type * bus); 76extern void bus_unregister(struct bus_type *bus);
84 77
85extern int __must_check bus_rescan_devices(struct bus_type * bus); 78extern int __must_check bus_rescan_devices(struct bus_type *bus);
86 79
87/* iterator helpers for buses */ 80/* iterator helpers for buses */
88 81
89int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data, 82int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
90 int (*fn)(struct device *, void *)); 83 int (*fn)(struct device *dev, void *data));
91struct device * bus_find_device(struct bus_type *bus, struct device *start, 84struct device *bus_find_device(struct bus_type *bus, struct device *start,
92 void *data, int (*match)(struct device *, void *)); 85 void *data,
86 int (*match)(struct device *dev, void *data));
93 87
94int __must_check bus_for_each_drv(struct bus_type *bus, 88int __must_check bus_for_each_drv(struct bus_type *bus,
95 struct device_driver *start, void *data, 89 struct device_driver *start, void *data,
96 int (*fn)(struct device_driver *, void *)); 90 int (*fn)(struct device_driver *, void *));
97 91
98/* 92/*
99 * Bus notifiers: Get notified of addition/removal of devices 93 * Bus notifiers: Get notified of addition/removal of devices
@@ -118,111 +112,128 @@ extern int bus_unregister_notifier(struct bus_type *bus,
118#define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be 112#define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be
119 unbound */ 113 unbound */
120 114
115extern struct kset *bus_get_kset(struct bus_type *bus);
116extern struct klist *bus_get_device_klist(struct bus_type *bus);
117
121struct device_driver { 118struct device_driver {
122 const char * name; 119 const char *name;
123 struct bus_type * bus; 120 struct bus_type *bus;
124 121
125 struct kobject kobj; 122 struct module *owner;
126 struct klist klist_devices; 123 const char *mod_name; /* used for built-in modules */
127 struct klist_node knode_bus;
128 124
129 struct module * owner; 125 int (*probe) (struct device *dev);
130 const char * mod_name; /* used for built-in modules */ 126 int (*remove) (struct device *dev);
131 struct module_kobject * mkobj; 127 void (*shutdown) (struct device *dev);
128 int (*suspend) (struct device *dev, pm_message_t state);
129 int (*resume) (struct device *dev);
130 struct attribute_group **groups;
132 131
133 int (*probe) (struct device * dev); 132 struct driver_private *p;
134 int (*remove) (struct device * dev);
135 void (*shutdown) (struct device * dev);
136 int (*suspend) (struct device * dev, pm_message_t state);
137 int (*resume) (struct device * dev);
138}; 133};
139 134
140 135
141extern int __must_check driver_register(struct device_driver * drv); 136extern int __must_check driver_register(struct device_driver *drv);
142extern void driver_unregister(struct device_driver * drv); 137extern void driver_unregister(struct device_driver *drv);
143 138
144extern struct device_driver * get_driver(struct device_driver * drv); 139extern struct device_driver *get_driver(struct device_driver *drv);
145extern void put_driver(struct device_driver * drv); 140extern void put_driver(struct device_driver *drv);
146extern struct device_driver *driver_find(const char *name, struct bus_type *bus); 141extern struct device_driver *driver_find(const char *name,
142 struct bus_type *bus);
147extern int driver_probe_done(void); 143extern int driver_probe_done(void);
148 144
149/* sysfs interface for exporting driver attributes */ 145/* sysfs interface for exporting driver attributes */
150 146
151struct driver_attribute { 147struct driver_attribute {
152 struct attribute attr; 148 struct attribute attr;
153 ssize_t (*show)(struct device_driver *, char * buf); 149 ssize_t (*show)(struct device_driver *driver, char *buf);
154 ssize_t (*store)(struct device_driver *, const char * buf, size_t count); 150 ssize_t (*store)(struct device_driver *driver, const char *buf,
151 size_t count);
155}; 152};
156 153
157#define DRIVER_ATTR(_name,_mode,_show,_store) \ 154#define DRIVER_ATTR(_name, _mode, _show, _store) \
158struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) 155struct driver_attribute driver_attr_##_name = \
156 __ATTR(_name, _mode, _show, _store)
159 157
160extern int __must_check driver_create_file(struct device_driver *, 158extern int __must_check driver_create_file(struct device_driver *driver,
161 struct driver_attribute *); 159 struct driver_attribute *attr);
162extern void driver_remove_file(struct device_driver *, struct driver_attribute *); 160extern void driver_remove_file(struct device_driver *driver,
161 struct driver_attribute *attr);
163 162
164extern int __must_check driver_for_each_device(struct device_driver * drv, 163extern int __must_check driver_add_kobj(struct device_driver *drv,
165 struct device *start, void *data, 164 struct kobject *kobj,
166 int (*fn)(struct device *, void *)); 165 const char *fmt, ...);
167struct device * driver_find_device(struct device_driver *drv, 166
168 struct device *start, void *data, 167extern int __must_check driver_for_each_device(struct device_driver *drv,
169 int (*match)(struct device *, void *)); 168 struct device *start,
169 void *data,
170 int (*fn)(struct device *dev,
171 void *));
172struct device *driver_find_device(struct device_driver *drv,
173 struct device *start, void *data,
174 int (*match)(struct device *dev, void *data));
170 175
171/* 176/*
172 * device classes 177 * device classes
173 */ 178 */
174struct class { 179struct class {
175 const char * name; 180 const char *name;
176 struct module * owner; 181 struct module *owner;
177 182
178 struct kset subsys; 183 struct kset subsys;
179 struct list_head children; 184 struct list_head children;
180 struct list_head devices; 185 struct list_head devices;
181 struct list_head interfaces; 186 struct list_head interfaces;
182 struct kset class_dirs; 187 struct kset class_dirs;
183 struct semaphore sem; /* locks both the children and interfaces lists */ 188 struct semaphore sem; /* locks children, devices, interfaces */
184 189 struct class_attribute *class_attrs;
185 struct class_attribute * class_attrs; 190 struct class_device_attribute *class_dev_attrs;
186 struct class_device_attribute * class_dev_attrs; 191 struct device_attribute *dev_attrs;
187 struct device_attribute * dev_attrs;
188 192
189 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); 193 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
190 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 194 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
191 195
192 void (*release)(struct class_device *dev); 196 void (*release)(struct class_device *dev);
193 void (*class_release)(struct class *class); 197 void (*class_release)(struct class *class);
194 void (*dev_release)(struct device *dev); 198 void (*dev_release)(struct device *dev);
195 199
196 int (*suspend)(struct device *, pm_message_t state); 200 int (*suspend)(struct device *dev, pm_message_t state);
197 int (*resume)(struct device *); 201 int (*resume)(struct device *dev);
198}; 202};
199 203
200extern int __must_check class_register(struct class *); 204extern int __must_check class_register(struct class *class);
201extern void class_unregister(struct class *); 205extern void class_unregister(struct class *class);
206extern int class_for_each_device(struct class *class, void *data,
207 int (*fn)(struct device *dev, void *data));
208extern struct device *class_find_device(struct class *class, void *data,
209 int (*match)(struct device *, void *));
210extern struct class_device *class_find_child(struct class *class, void *data,
211 int (*match)(struct class_device *, void *));
202 212
203 213
204struct class_attribute { 214struct class_attribute {
205 struct attribute attr; 215 struct attribute attr;
206 ssize_t (*show)(struct class *, char * buf); 216 ssize_t (*show)(struct class *class, char *buf);
207 ssize_t (*store)(struct class *, const char * buf, size_t count); 217 ssize_t (*store)(struct class *class, const char *buf, size_t count);
208}; 218};
209 219
210#define CLASS_ATTR(_name,_mode,_show,_store) \ 220#define CLASS_ATTR(_name, _mode, _show, _store) \
211struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store) 221struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
212 222
213extern int __must_check class_create_file(struct class *, 223extern int __must_check class_create_file(struct class *class,
214 const struct class_attribute *); 224 const struct class_attribute *attr);
215extern void class_remove_file(struct class *, const struct class_attribute *); 225extern void class_remove_file(struct class *class,
226 const struct class_attribute *attr);
216 227
217struct class_device_attribute { 228struct class_device_attribute {
218 struct attribute attr; 229 struct attribute attr;
219 ssize_t (*show)(struct class_device *, char * buf); 230 ssize_t (*show)(struct class_device *, char *buf);
220 ssize_t (*store)(struct class_device *, const char * buf, size_t count); 231 ssize_t (*store)(struct class_device *, const char *buf, size_t count);
221}; 232};
222 233
223#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \ 234#define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \
224struct class_device_attribute class_device_attr_##_name = \ 235struct class_device_attribute class_device_attr_##_name = \
225 __ATTR(_name,_mode,_show,_store) 236 __ATTR(_name, _mode, _show, _store)
226 237
227extern int __must_check class_device_create_file(struct class_device *, 238extern int __must_check class_device_create_file(struct class_device *,
228 const struct class_device_attribute *); 239 const struct class_device_attribute *);
@@ -255,26 +266,24 @@ struct class_device {
255 struct list_head node; 266 struct list_head node;
256 267
257 struct kobject kobj; 268 struct kobject kobj;
258 struct class * class; /* required */ 269 struct class *class;
259 dev_t devt; /* dev_t, creates the sysfs "dev" */ 270 dev_t devt;
260 struct device * dev; /* not necessary, but nice to have */ 271 struct device *dev;
261 void * class_data; /* class-specific data */ 272 void *class_data;
262 struct class_device *parent; /* parent of this child device, if there is one */ 273 struct class_device *parent;
263 struct attribute_group ** groups; /* optional groups */ 274 struct attribute_group **groups;
264 275
265 void (*release)(struct class_device *dev); 276 void (*release)(struct class_device *dev);
266 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env); 277 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
267 char class_id[BUS_ID_SIZE]; /* unique to this class */ 278 char class_id[BUS_ID_SIZE];
268}; 279};
269 280
270static inline void * 281static inline void *class_get_devdata(struct class_device *dev)
271class_get_devdata (struct class_device *dev)
272{ 282{
273 return dev->class_data; 283 return dev->class_data;
274} 284}
275 285
276static inline void 286static inline void class_set_devdata(struct class_device *dev, void *data)
277class_set_devdata (struct class_device *dev, void *data)
278{ 287{
279 dev->class_data = data; 288 dev->class_data = data;
280} 289}
@@ -286,10 +295,10 @@ extern void class_device_initialize(struct class_device *);
286extern int __must_check class_device_add(struct class_device *); 295extern int __must_check class_device_add(struct class_device *);
287extern void class_device_del(struct class_device *); 296extern void class_device_del(struct class_device *);
288 297
289extern struct class_device * class_device_get(struct class_device *); 298extern struct class_device *class_device_get(struct class_device *);
290extern void class_device_put(struct class_device *); 299extern void class_device_put(struct class_device *);
291 300
292extern void class_device_remove_file(struct class_device *, 301extern void class_device_remove_file(struct class_device *,
293 const struct class_device_attribute *); 302 const struct class_device_attribute *);
294extern int __must_check class_device_create_bin_file(struct class_device *, 303extern int __must_check class_device_create_bin_file(struct class_device *,
295 struct bin_attribute *); 304 struct bin_attribute *);
@@ -316,7 +325,7 @@ extern struct class_device *class_device_create(struct class *cls,
316 dev_t devt, 325 dev_t devt,
317 struct device *device, 326 struct device *device,
318 const char *fmt, ...) 327 const char *fmt, ...)
319 __attribute__((format(printf,5,6))); 328 __attribute__((format(printf, 5, 6)));
320extern void class_device_destroy(struct class *cls, dev_t devt); 329extern void class_device_destroy(struct class *cls, dev_t devt);
321 330
322/* 331/*
@@ -333,8 +342,8 @@ struct device_type {
333 struct attribute_group **groups; 342 struct attribute_group **groups;
334 int (*uevent)(struct device *dev, struct kobj_uevent_env *env); 343 int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
335 void (*release)(struct device *dev); 344 void (*release)(struct device *dev);
336 int (*suspend)(struct device * dev, pm_message_t state); 345 int (*suspend)(struct device *dev, pm_message_t state);
337 int (*resume)(struct device * dev); 346 int (*resume)(struct device *dev);
338}; 347};
339 348
340/* interface for exporting device attributes */ 349/* interface for exporting device attributes */
@@ -346,18 +355,19 @@ struct device_attribute {
346 const char *buf, size_t count); 355 const char *buf, size_t count);
347}; 356};
348 357
349#define DEVICE_ATTR(_name,_mode,_show,_store) \ 358#define DEVICE_ATTR(_name, _mode, _show, _store) \
350struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store) 359struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
351 360
352extern int __must_check device_create_file(struct device *device, 361extern int __must_check device_create_file(struct device *device,
353 struct device_attribute * entry); 362 struct device_attribute *entry);
354extern void device_remove_file(struct device * dev, struct device_attribute * attr); 363extern void device_remove_file(struct device *dev,
364 struct device_attribute *attr);
355extern int __must_check device_create_bin_file(struct device *dev, 365extern int __must_check device_create_bin_file(struct device *dev,
356 struct bin_attribute *attr); 366 struct bin_attribute *attr);
357extern void device_remove_bin_file(struct device *dev, 367extern void device_remove_bin_file(struct device *dev,
358 struct bin_attribute *attr); 368 struct bin_attribute *attr);
359extern int device_schedule_callback_owner(struct device *dev, 369extern int device_schedule_callback_owner(struct device *dev,
360 void (*func)(struct device *), struct module *owner); 370 void (*func)(struct device *dev), struct module *owner);
361 371
362/* This is a macro to avoid include problems with THIS_MODULE */ 372/* This is a macro to avoid include problems with THIS_MODULE */
363#define device_schedule_callback(dev, func) \ 373#define device_schedule_callback(dev, func) \
@@ -368,21 +378,21 @@ typedef void (*dr_release_t)(struct device *dev, void *res);
368typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); 378typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
369 379
370#ifdef CONFIG_DEBUG_DEVRES 380#ifdef CONFIG_DEBUG_DEVRES
371extern void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp, 381extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
372 const char *name); 382 const char *name);
373#define devres_alloc(release, size, gfp) \ 383#define devres_alloc(release, size, gfp) \
374 __devres_alloc(release, size, gfp, #release) 384 __devres_alloc(release, size, gfp, #release)
375#else 385#else
376extern void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp); 386extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
377#endif 387#endif
378extern void devres_free(void *res); 388extern void devres_free(void *res);
379extern void devres_add(struct device *dev, void *res); 389extern void devres_add(struct device *dev, void *res);
380extern void * devres_find(struct device *dev, dr_release_t release, 390extern void *devres_find(struct device *dev, dr_release_t release,
381 dr_match_t match, void *match_data);
382extern void * devres_get(struct device *dev, void *new_res,
383 dr_match_t match, void *match_data); 391 dr_match_t match, void *match_data);
384extern void * devres_remove(struct device *dev, dr_release_t release, 392extern void *devres_get(struct device *dev, void *new_res,
385 dr_match_t match, void *match_data); 393 dr_match_t match, void *match_data);
394extern void *devres_remove(struct device *dev, dr_release_t release,
395 dr_match_t match, void *match_data);
386extern int devres_destroy(struct device *dev, dr_release_t release, 396extern int devres_destroy(struct device *dev, dr_release_t release,
387 dr_match_t match, void *match_data); 397 dr_match_t match, void *match_data);
388 398
@@ -399,7 +409,7 @@ extern void devm_kfree(struct device *dev, void *p);
399 409
400struct device { 410struct device {
401 struct klist klist_children; 411 struct klist klist_children;
402 struct klist_node knode_parent; /* node in sibling list */ 412 struct klist_node knode_parent; /* node in sibling list */
403 struct klist_node knode_driver; 413 struct klist_node knode_driver;
404 struct klist_node knode_bus; 414 struct klist_node knode_bus;
405 struct device *parent; 415 struct device *parent;
@@ -414,7 +424,7 @@ struct device {
414 * its driver. 424 * its driver.
415 */ 425 */
416 426
417 struct bus_type * bus; /* type of bus device is on */ 427 struct bus_type *bus; /* type of bus device is on */
418 struct device_driver *driver; /* which driver has allocated this 428 struct device_driver *driver; /* which driver has allocated this
419 device */ 429 device */
420 void *driver_data; /* data private to the driver */ 430 void *driver_data; /* data private to the driver */
@@ -445,10 +455,10 @@ struct device {
445 /* class_device migration path */ 455 /* class_device migration path */
446 struct list_head node; 456 struct list_head node;
447 struct class *class; 457 struct class *class;
448 dev_t devt; /* dev_t, creates the sysfs "dev" */ 458 dev_t devt; /* dev_t, creates the sysfs "dev" */
449 struct attribute_group **groups; /* optional groups */ 459 struct attribute_group **groups; /* optional groups */
450 460
451 void (*release)(struct device * dev); 461 void (*release)(struct device *dev);
452}; 462};
453 463
454#ifdef CONFIG_NUMA 464#ifdef CONFIG_NUMA
@@ -470,14 +480,12 @@ static inline void set_dev_node(struct device *dev, int node)
470} 480}
471#endif 481#endif
472 482
473static inline void * 483static inline void *dev_get_drvdata(struct device *dev)
474dev_get_drvdata (struct device *dev)
475{ 484{
476 return dev->driver_data; 485 return dev->driver_data;
477} 486}
478 487
479static inline void 488static inline void dev_set_drvdata(struct device *dev, void *data)
480dev_set_drvdata (struct device *dev, void *data)
481{ 489{
482 dev->driver_data = data; 490 dev->driver_data = data;
483} 491}
@@ -492,15 +500,15 @@ void driver_init(void);
492/* 500/*
493 * High level routines for use by the bus drivers 501 * High level routines for use by the bus drivers
494 */ 502 */
495extern int __must_check device_register(struct device * dev); 503extern int __must_check device_register(struct device *dev);
496extern void device_unregister(struct device * dev); 504extern void device_unregister(struct device *dev);
497extern void device_initialize(struct device * dev); 505extern void device_initialize(struct device *dev);
498extern int __must_check device_add(struct device * dev); 506extern int __must_check device_add(struct device *dev);
499extern void device_del(struct device * dev); 507extern void device_del(struct device *dev);
500extern int device_for_each_child(struct device *, void *, 508extern int device_for_each_child(struct device *dev, void *data,
501 int (*fn)(struct device *, void *)); 509 int (*fn)(struct device *dev, void *data));
502extern struct device *device_find_child(struct device *, void *data, 510extern struct device *device_find_child(struct device *dev, void *data,
503 int (*match)(struct device *, void *)); 511 int (*match)(struct device *dev, void *data));
504extern int device_rename(struct device *dev, char *new_name); 512extern int device_rename(struct device *dev, char *new_name);
505extern int device_move(struct device *dev, struct device *new_parent); 513extern int device_move(struct device *dev, struct device *new_parent);
506 514
@@ -509,8 +517,8 @@ extern int device_move(struct device *dev, struct device *new_parent);
509 * for information on use. 517 * for information on use.
510 */ 518 */
511extern int __must_check device_bind_driver(struct device *dev); 519extern int __must_check device_bind_driver(struct device *dev);
512extern void device_release_driver(struct device * dev); 520extern void device_release_driver(struct device *dev);
513extern int __must_check device_attach(struct device * dev); 521extern int __must_check device_attach(struct device *dev);
514extern int __must_check driver_attach(struct device_driver *drv); 522extern int __must_check driver_attach(struct device_driver *drv);
515extern int __must_check device_reprobe(struct device *dev); 523extern int __must_check device_reprobe(struct device *dev);
516 524
@@ -519,8 +527,16 @@ extern int __must_check device_reprobe(struct device *dev);
519 */ 527 */
520extern struct device *device_create(struct class *cls, struct device *parent, 528extern struct device *device_create(struct class *cls, struct device *parent,
521 dev_t devt, const char *fmt, ...) 529 dev_t devt, const char *fmt, ...)
522 __attribute__((format(printf,4,5))); 530 __attribute__((format(printf, 4, 5)));
523extern void device_destroy(struct class *cls, dev_t devt); 531extern void device_destroy(struct class *cls, dev_t devt);
532#ifdef CONFIG_PM_SLEEP
533extern void destroy_suspended_device(struct class *cls, dev_t devt);
534#else /* !CONFIG_PM_SLEEP */
535static inline void destroy_suspended_device(struct class *cls, dev_t devt)
536{
537 device_destroy(cls, devt);
538}
539#endif /* !CONFIG_PM_SLEEP */
524 540
525/* 541/*
526 * Platform "fixup" functions - allow the platform to have their say 542 * Platform "fixup" functions - allow the platform to have their say
@@ -528,17 +544,17 @@ extern void device_destroy(struct class *cls, dev_t devt);
528 * know about. 544 * know about.
529 */ 545 */
530/* Notify platform of device discovery */ 546/* Notify platform of device discovery */
531extern int (*platform_notify)(struct device * dev); 547extern int (*platform_notify)(struct device *dev);
532 548
533extern int (*platform_notify_remove)(struct device * dev); 549extern int (*platform_notify_remove)(struct device *dev);
534 550
535 551
536/** 552/**
537 * get_device - atomically increment the reference count for the device. 553 * get_device - atomically increment the reference count for the device.
538 * 554 *
539 */ 555 */
540extern struct device * get_device(struct device * dev); 556extern struct device *get_device(struct device *dev);
541extern void put_device(struct device * dev); 557extern void put_device(struct device *dev);
542 558
543 559
544/* drivers/base/power/shutdown.c */ 560/* drivers/base/power/shutdown.c */
@@ -547,22 +563,33 @@ extern void device_shutdown(void);
547/* drivers/base/sys.c */ 563/* drivers/base/sys.c */
548extern void sysdev_shutdown(void); 564extern void sysdev_shutdown(void);
549 565
550
551/* drivers/base/firmware.c */
552extern int __must_check firmware_register(struct kset *);
553extern void firmware_unregister(struct kset *);
554
555/* debugging and troubleshooting/diagnostic helpers. */ 566/* debugging and troubleshooting/diagnostic helpers. */
556extern const char *dev_driver_string(struct device *dev); 567extern const char *dev_driver_string(struct device *dev);
557#define dev_printk(level, dev, format, arg...) \ 568#define dev_printk(level, dev, format, arg...) \
558 printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg) 569 printk(level "%s %s: " format , dev_driver_string(dev) , \
570 (dev)->bus_id , ## arg)
571
572#define dev_emerg(dev, format, arg...) \
573 dev_printk(KERN_EMERG , dev , format , ## arg)
574#define dev_alert(dev, format, arg...) \
575 dev_printk(KERN_ALERT , dev , format , ## arg)
576#define dev_crit(dev, format, arg...) \
577 dev_printk(KERN_CRIT , dev , format , ## arg)
578#define dev_err(dev, format, arg...) \
579 dev_printk(KERN_ERR , dev , format , ## arg)
580#define dev_warn(dev, format, arg...) \
581 dev_printk(KERN_WARNING , dev , format , ## arg)
582#define dev_notice(dev, format, arg...) \
583 dev_printk(KERN_NOTICE , dev , format , ## arg)
584#define dev_info(dev, format, arg...) \
585 dev_printk(KERN_INFO , dev , format , ## arg)
559 586
560#ifdef DEBUG 587#ifdef DEBUG
561#define dev_dbg(dev, format, arg...) \ 588#define dev_dbg(dev, format, arg...) \
562 dev_printk(KERN_DEBUG , dev , format , ## arg) 589 dev_printk(KERN_DEBUG , dev , format , ## arg)
563#else 590#else
564static inline int __attribute__ ((format (printf, 2, 3))) 591static inline int __attribute__ ((format (printf, 2, 3)))
565dev_dbg(struct device * dev, const char * fmt, ...) 592dev_dbg(struct device *dev, const char *fmt, ...)
566{ 593{
567 return 0; 594 return 0;
568} 595}
@@ -572,21 +599,12 @@ dev_dbg(struct device * dev, const char * fmt, ...)
572#define dev_vdbg dev_dbg 599#define dev_vdbg dev_dbg
573#else 600#else
574static inline int __attribute__ ((format (printf, 2, 3))) 601static inline int __attribute__ ((format (printf, 2, 3)))
575dev_vdbg(struct device * dev, const char * fmt, ...) 602dev_vdbg(struct device *dev, const char *fmt, ...)
576{ 603{
577 return 0; 604 return 0;
578} 605}
579#endif 606#endif
580 607
581#define dev_err(dev, format, arg...) \
582 dev_printk(KERN_ERR , dev , format , ## arg)
583#define dev_info(dev, format, arg...) \
584 dev_printk(KERN_INFO , dev , format , ## arg)
585#define dev_warn(dev, format, arg...) \
586 dev_printk(KERN_WARNING , dev , format , ## arg)
587#define dev_notice(dev, format, arg...) \
588 dev_printk(KERN_NOTICE , dev , format , ## arg)
589
590/* Create alias, so I can be autoloaded. */ 608/* Create alias, so I can be autoloaded. */
591#define MODULE_ALIAS_CHARDEV(major,minor) \ 609#define MODULE_ALIAS_CHARDEV(major,minor) \
592 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor)) 610 MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index a3b6035b6c86..55c9a6952f44 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -132,7 +132,7 @@ struct dma_chan {
132 132
133 /* sysfs */ 133 /* sysfs */
134 int chan_id; 134 int chan_id;
135 struct class_device class_dev; 135 struct device dev;
136 136
137 struct kref refcount; 137 struct kref refcount;
138 int slow_ref; 138 int slow_ref;
@@ -142,6 +142,7 @@ struct dma_chan {
142 struct dma_chan_percpu *local; 142 struct dma_chan_percpu *local;
143}; 143};
144 144
145#define to_dma_chan(p) container_of(p, struct dma_chan, dev)
145 146
146void dma_chan_cleanup(struct kref *kref); 147void dma_chan_cleanup(struct kref *kref);
147 148
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b3ec4a496d64..21398a5d688d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1476,7 +1476,7 @@ extern void drop_collected_mounts(struct vfsmount *);
1476extern int vfs_statfs(struct dentry *, struct kstatfs *); 1476extern int vfs_statfs(struct dentry *, struct kstatfs *);
1477 1477
1478/* /sys/fs */ 1478/* /sys/fs */
1479extern struct kset fs_subsys; 1479extern struct kobject *fs_kobj;
1480 1480
1481#define FLOCK_VERIFY_READ 1 1481#define FLOCK_VERIFY_READ 1
1482#define FLOCK_VERIFY_WRITE 2 1482#define FLOCK_VERIFY_WRITE 2
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index a47b8025d399..1dbea0ac5693 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -10,9 +10,19 @@
10 */ 10 */
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/kdev_t.h>
13 14
14#ifdef CONFIG_BLOCK 15#ifdef CONFIG_BLOCK
15 16
17#define kobj_to_dev(k) container_of(k, struct device, kobj)
18#define dev_to_disk(device) container_of(device, struct gendisk, dev)
19#define dev_to_part(device) container_of(device, struct hd_struct, dev)
20
21extern struct device_type disk_type;
22extern struct device_type part_type;
23extern struct kobject *block_depr;
24extern struct class block_class;
25
16enum { 26enum {
17/* These three have identical behaviour; use the second one if DOS FDISK gets 27/* These three have identical behaviour; use the second one if DOS FDISK gets
18 confused about extended/logical partitions starting past cylinder 1023. */ 28 confused about extended/logical partitions starting past cylinder 1023. */
@@ -84,7 +94,7 @@ struct partition {
84struct hd_struct { 94struct hd_struct {
85 sector_t start_sect; 95 sector_t start_sect;
86 sector_t nr_sects; 96 sector_t nr_sects;
87 struct kobject kobj; 97 struct device dev;
88 struct kobject *holder_dir; 98 struct kobject *holder_dir;
89 unsigned ios[2], sectors[2]; /* READs and WRITEs */ 99 unsigned ios[2], sectors[2]; /* READs and WRITEs */
90 int policy, partno; 100 int policy, partno;
@@ -117,15 +127,14 @@ struct gendisk {
117 * disks that can't be partitioned. */ 127 * disks that can't be partitioned. */
118 char disk_name[32]; /* name of major driver */ 128 char disk_name[32]; /* name of major driver */
119 struct hd_struct **part; /* [indexed by minor] */ 129 struct hd_struct **part; /* [indexed by minor] */
120 int part_uevent_suppress;
121 struct block_device_operations *fops; 130 struct block_device_operations *fops;
122 struct request_queue *queue; 131 struct request_queue *queue;
123 void *private_data; 132 void *private_data;
124 sector_t capacity; 133 sector_t capacity;
125 134
126 int flags; 135 int flags;
127 struct device *driverfs_dev; 136 struct device *driverfs_dev; // FIXME: remove
128 struct kobject kobj; 137 struct device dev;
129 struct kobject *holder_dir; 138 struct kobject *holder_dir;
130 struct kobject *slave_dir; 139 struct kobject *slave_dir;
131 140
@@ -143,13 +152,6 @@ struct gendisk {
143 struct work_struct async_notify; 152 struct work_struct async_notify;
144}; 153};
145 154
146/* Structure for sysfs attributes on block devices */
147struct disk_attribute {
148 struct attribute attr;
149 ssize_t (*show)(struct gendisk *, char *);
150 ssize_t (*store)(struct gendisk *, const char *, size_t);
151};
152
153/* 155/*
154 * Macros to operate on percpu disk statistics: 156 * Macros to operate on percpu disk statistics:
155 * 157 *
@@ -411,7 +413,8 @@ struct unixware_disklabel {
411#define ADDPART_FLAG_RAID 1 413#define ADDPART_FLAG_RAID 1
412#define ADDPART_FLAG_WHOLEDISK 2 414#define ADDPART_FLAG_WHOLEDISK 2
413 415
414char *disk_name (struct gendisk *hd, int part, char *buf); 416extern dev_t blk_lookup_devt(const char *name);
417extern char *disk_name (struct gendisk *hd, int part, char *buf);
415 418
416extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); 419extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
417extern void add_partition(struct gendisk *, int, sector_t, sector_t, int); 420extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
@@ -423,12 +426,12 @@ extern struct gendisk *alloc_disk(int minors);
423extern struct kobject *get_disk(struct gendisk *disk); 426extern struct kobject *get_disk(struct gendisk *disk);
424extern void put_disk(struct gendisk *disk); 427extern void put_disk(struct gendisk *disk);
425extern void genhd_media_change_notify(struct gendisk *disk); 428extern void genhd_media_change_notify(struct gendisk *disk);
426extern void blk_register_region(dev_t dev, unsigned long range, 429extern void blk_register_region(dev_t devt, unsigned long range,
427 struct module *module, 430 struct module *module,
428 struct kobject *(*probe)(dev_t, int *, void *), 431 struct kobject *(*probe)(dev_t, int *, void *),
429 int (*lock)(dev_t, void *), 432 int (*lock)(dev_t, void *),
430 void *data); 433 void *data);
431extern void blk_unregister_region(dev_t dev, unsigned long range); 434extern void blk_unregister_region(dev_t devt, unsigned long range);
432 435
433static inline struct block_device *bdget_disk(struct gendisk *disk, int index) 436static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
434{ 437{
@@ -441,6 +444,12 @@ static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
441 444
442static inline void printk_all_partitions(void) { } 445static inline void printk_all_partitions(void) { }
443 446
447static inline dev_t blk_lookup_devt(const char *name)
448{
449 dev_t devt = MKDEV(0, 0);
450 return devt;
451}
452
444#endif /* CONFIG_BLOCK */ 453#endif /* CONFIG_BLOCK */
445 454
446#endif 455#endif
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
index 21ea7610e177..85d11916e9ea 100644
--- a/include/linux/hw_random.h
+++ b/include/linux/hw_random.h
@@ -33,7 +33,7 @@ struct hwrng {
33 const char *name; 33 const char *name;
34 int (*init)(struct hwrng *rng); 34 int (*init)(struct hwrng *rng);
35 void (*cleanup)(struct hwrng *rng); 35 void (*cleanup)(struct hwrng *rng);
36 int (*data_present)(struct hwrng *rng); 36 int (*data_present)(struct hwrng *rng, int wait);
37 int (*data_read)(struct hwrng *rng, u32 *data); 37 int (*data_read)(struct hwrng *rng, u32 *data);
38 unsigned long priv; 38 unsigned long priv;
39 39
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 4a0d27f475d7..caa3f411f15d 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -3,15 +3,14 @@
3 * 3 *
4 * Copyright (c) 2002-2003 Patrick Mochel 4 * Copyright (c) 2002-2003 Patrick Mochel
5 * Copyright (c) 2002-2003 Open Source Development Labs 5 * Copyright (c) 2002-2003 Open Source Development Labs
6 * Copyright (c) 2006-2007 Greg Kroah-Hartman <greg@kroah.com> 6 * Copyright (c) 2006-2008 Greg Kroah-Hartman <greg@kroah.com>
7 * Copyright (c) 2006-2007 Novell Inc. 7 * Copyright (c) 2006-2008 Novell Inc.
8 * 8 *
9 * This file is released under the GPLv2. 9 * This file is released under the GPLv2.
10 * 10 *
11 *
12 * Please read Documentation/kobject.txt before using the kobject 11 * Please read Documentation/kobject.txt before using the kobject
13 * interface, ESPECIALLY the parts about reference counts and object 12 * interface, ESPECIALLY the parts about reference counts and object
14 * destructors. 13 * destructors.
15 */ 14 */
16 15
17#ifndef _KOBJECT_H_ 16#ifndef _KOBJECT_H_
@@ -61,48 +60,54 @@ enum kobject_action {
61}; 60};
62 61
63struct kobject { 62struct kobject {
64 const char * k_name; 63 const char *name;
65 struct kref kref; 64 struct kref kref;
66 struct list_head entry; 65 struct list_head entry;
67 struct kobject * parent; 66 struct kobject *parent;
68 struct kset * kset; 67 struct kset *kset;
69 struct kobj_type * ktype; 68 struct kobj_type *ktype;
70 struct sysfs_dirent * sd; 69 struct sysfs_dirent *sd;
70 unsigned int state_initialized:1;
71 unsigned int state_in_sysfs:1;
72 unsigned int state_add_uevent_sent:1;
73 unsigned int state_remove_uevent_sent:1;
71}; 74};
72 75
73extern int kobject_set_name(struct kobject *, const char *, ...) 76extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
74 __attribute__((format(printf,2,3))); 77 __attribute__((format(printf, 2, 3)));
75 78
76static inline const char * kobject_name(const struct kobject * kobj) 79static inline const char *kobject_name(const struct kobject *kobj)
77{ 80{
78 return kobj->k_name; 81 return kobj->name;
79} 82}
80 83
81extern void kobject_init(struct kobject *); 84extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
82extern void kobject_cleanup(struct kobject *); 85extern int __must_check kobject_add(struct kobject *kobj,
86 struct kobject *parent,
87 const char *fmt, ...);
88extern int __must_check kobject_init_and_add(struct kobject *kobj,
89 struct kobj_type *ktype,
90 struct kobject *parent,
91 const char *fmt, ...);
92
93extern void kobject_del(struct kobject *kobj);
83 94
84extern int __must_check kobject_add(struct kobject *); 95extern struct kobject * __must_check kobject_create(void);
85extern void kobject_del(struct kobject *); 96extern struct kobject * __must_check kobject_create_and_add(const char *name,
97 struct kobject *parent);
86 98
87extern int __must_check kobject_rename(struct kobject *, const char *new_name); 99extern int __must_check kobject_rename(struct kobject *, const char *new_name);
88extern int __must_check kobject_move(struct kobject *, struct kobject *); 100extern int __must_check kobject_move(struct kobject *, struct kobject *);
89 101
90extern int __must_check kobject_register(struct kobject *); 102extern struct kobject *kobject_get(struct kobject *kobj);
91extern void kobject_unregister(struct kobject *); 103extern void kobject_put(struct kobject *kobj);
92
93extern struct kobject * kobject_get(struct kobject *);
94extern void kobject_put(struct kobject *);
95
96extern struct kobject *kobject_kset_add_dir(struct kset *kset,
97 struct kobject *, const char *);
98extern struct kobject *kobject_add_dir(struct kobject *, const char *);
99 104
100extern char * kobject_get_path(struct kobject *, gfp_t); 105extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
101 106
102struct kobj_type { 107struct kobj_type {
103 void (*release)(struct kobject *); 108 void (*release)(struct kobject *kobj);
104 struct sysfs_ops * sysfs_ops; 109 struct sysfs_ops *sysfs_ops;
105 struct attribute ** default_attrs; 110 struct attribute **default_attrs;
106}; 111};
107 112
108struct kobj_uevent_env { 113struct kobj_uevent_env {
@@ -119,6 +124,16 @@ struct kset_uevent_ops {
119 struct kobj_uevent_env *env); 124 struct kobj_uevent_env *env);
120}; 125};
121 126
127struct kobj_attribute {
128 struct attribute attr;
129 ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
130 char *buf);
131 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
132 const char *buf, size_t count);
133};
134
135extern struct sysfs_ops kobj_sysfs_ops;
136
122/** 137/**
123 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. 138 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
124 * 139 *
@@ -128,7 +143,6 @@ struct kset_uevent_ops {
128 * define the attribute callbacks and other common events that happen to 143 * define the attribute callbacks and other common events that happen to
129 * a kobject. 144 * a kobject.
130 * 145 *
131 * @ktype: the struct kobj_type for this specific kset
132 * @list: the list of all kobjects for this kset 146 * @list: the list of all kobjects for this kset
133 * @list_lock: a lock for iterating over the kobjects 147 * @list_lock: a lock for iterating over the kobjects
134 * @kobj: the embedded kobject for this kset (recursion, isn't it fun...) 148 * @kobj: the embedded kobject for this kset (recursion, isn't it fun...)
@@ -138,99 +152,49 @@ struct kset_uevent_ops {
138 * desired. 152 * desired.
139 */ 153 */
140struct kset { 154struct kset {
141 struct kobj_type *ktype; 155 struct list_head list;
142 struct list_head list; 156 spinlock_t list_lock;
143 spinlock_t list_lock; 157 struct kobject kobj;
144 struct kobject kobj; 158 struct kset_uevent_ops *uevent_ops;
145 struct kset_uevent_ops *uevent_ops;
146}; 159};
147 160
161extern void kset_init(struct kset *kset);
162extern int __must_check kset_register(struct kset *kset);
163extern void kset_unregister(struct kset *kset);
164extern struct kset * __must_check kset_create_and_add(const char *name,
165 struct kset_uevent_ops *u,
166 struct kobject *parent_kobj);
148 167
149extern void kset_init(struct kset * k); 168static inline struct kset *to_kset(struct kobject *kobj)
150extern int __must_check kset_add(struct kset * k);
151extern int __must_check kset_register(struct kset * k);
152extern void kset_unregister(struct kset * k);
153
154static inline struct kset * to_kset(struct kobject * kobj)
155{ 169{
156 return kobj ? container_of(kobj,struct kset,kobj) : NULL; 170 return kobj ? container_of(kobj, struct kset, kobj) : NULL;
157} 171}
158 172
159static inline struct kset * kset_get(struct kset * k) 173static inline struct kset *kset_get(struct kset *k)
160{ 174{
161 return k ? to_kset(kobject_get(&k->kobj)) : NULL; 175 return k ? to_kset(kobject_get(&k->kobj)) : NULL;
162} 176}
163 177
164static inline void kset_put(struct kset * k) 178static inline void kset_put(struct kset *k)
165{ 179{
166 kobject_put(&k->kobj); 180 kobject_put(&k->kobj);
167} 181}
168 182
169static inline struct kobj_type * get_ktype(struct kobject * k) 183static inline struct kobj_type *get_ktype(struct kobject *kobj)
170{ 184{
171 if (k->kset && k->kset->ktype) 185 return kobj->ktype;
172 return k->kset->ktype;
173 else
174 return k->ktype;
175} 186}
176 187
177extern struct kobject * kset_find_obj(struct kset *, const char *); 188extern struct kobject *kset_find_obj(struct kset *, const char *);
178
179
180/*
181 * Use this when initializing an embedded kset with no other
182 * fields to initialize.
183 */
184#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }
185
186
187#define decl_subsys(_name,_type,_uevent_ops) \
188struct kset _name##_subsys = { \
189 .kobj = { .k_name = __stringify(_name) }, \
190 .ktype = _type, \
191 .uevent_ops =_uevent_ops, \
192}
193#define decl_subsys_name(_varname,_name,_type,_uevent_ops) \
194struct kset _varname##_subsys = { \
195 .kobj = { .k_name = __stringify(_name) }, \
196 .ktype = _type, \
197 .uevent_ops =_uevent_ops, \
198}
199
200/* The global /sys/kernel/ subsystem for people to chain off of */
201extern struct kset kernel_subsys;
202/* The global /sys/hypervisor/ subsystem */
203extern struct kset hypervisor_subsys;
204
205/*
206 * Helpers for setting the kset of registered objects.
207 * Often, a registered object belongs to a kset embedded in a
208 * subsystem. These do no magic, just make the resulting code
209 * easier to follow.
210 */
211
212/**
213 * kobj_set_kset_s(obj,subsys) - set kset for embedded kobject.
214 * @obj: ptr to some object type.
215 * @subsys: a subsystem object (not a ptr).
216 *
217 * Can be used for any object type with an embedded ->kobj.
218 */
219
220#define kobj_set_kset_s(obj,subsys) \
221 (obj)->kobj.kset = &(subsys)
222
223extern int __must_check subsystem_register(struct kset *);
224extern void subsystem_unregister(struct kset *);
225
226struct subsys_attribute {
227 struct attribute attr;
228 ssize_t (*show)(struct kset *, char *);
229 ssize_t (*store)(struct kset *, const char *, size_t);
230};
231 189
232extern int __must_check subsys_create_file(struct kset *, 190/* The global /sys/kernel/ kobject for people to chain off of */
233 struct subsys_attribute *); 191extern struct kobject *kernel_kobj;
192/* The global /sys/hypervisor/ kobject for people to chain off of */
193extern struct kobject *hypervisor_kobj;
194/* The global /sys/power/ kobject for people to chain off of */
195extern struct kobject *power_kobj;
196/* The global /sys/firmware/ kobject for people to chain off of */
197extern struct kobject *firmware_kobj;
234 198
235#if defined(CONFIG_HOTPLUG) 199#if defined(CONFIG_HOTPLUG)
236int kobject_uevent(struct kobject *kobj, enum kobject_action action); 200int kobject_uevent(struct kobject *kobj, enum kobject_action action);
@@ -243,18 +207,20 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
243int kobject_action_type(const char *buf, size_t count, 207int kobject_action_type(const char *buf, size_t count,
244 enum kobject_action *type); 208 enum kobject_action *type);
245#else 209#else
246static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) 210static inline int kobject_uevent(struct kobject *kobj,
211 enum kobject_action action)
247{ return 0; } 212{ return 0; }
248static inline int kobject_uevent_env(struct kobject *kobj, 213static inline int kobject_uevent_env(struct kobject *kobj,
249 enum kobject_action action, 214 enum kobject_action action,
250 char *envp[]) 215 char *envp[])
251{ return 0; } 216{ return 0; }
252 217
253static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) 218static inline int add_uevent_var(struct kobj_uevent_env *env,
219 const char *format, ...)
254{ return 0; } 220{ return 0; }
255 221
256static inline int kobject_action_type(const char *buf, size_t count, 222static inline int kobject_action_type(const char *buf, size_t count,
257 enum kobject_action *type) 223 enum kobject_action *type)
258{ return -EINVAL; } 224{ return -EINVAL; }
259#endif 225#endif
260 226
diff --git a/include/linux/kref.h b/include/linux/kref.h
index 6fee3539893f..5d185635786e 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -24,6 +24,7 @@ struct kref {
24 atomic_t refcount; 24 atomic_t refcount;
25}; 25};
26 26
27void kref_set(struct kref *kref, int num);
27void kref_init(struct kref *kref); 28void kref_init(struct kref *kref);
28void kref_get(struct kref *kref); 29void kref_get(struct kref *kref);
29int kref_put(struct kref *kref, void (*release) (struct kref *kref)); 30int kref_put(struct kref *kref, void (*release) (struct kref *kref));
diff --git a/include/linux/module.h b/include/linux/module.h
index 2cbc0b87e329..c97bdb7eb957 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -574,7 +574,9 @@ struct device_driver;
574#ifdef CONFIG_SYSFS 574#ifdef CONFIG_SYSFS
575struct module; 575struct module;
576 576
577extern struct kset module_subsys; 577extern struct kset *module_kset;
578extern struct kobj_type module_ktype;
579extern int module_sysfs_initialized;
578 580
579int mod_sysfs_init(struct module *mod); 581int mod_sysfs_init(struct module *mod);
580int mod_sysfs_setup(struct module *mod, 582int mod_sysfs_setup(struct module *mod,
@@ -607,21 +609,6 @@ static inline void module_remove_modinfo_attrs(struct module *mod)
607 609
608#endif /* CONFIG_SYSFS */ 610#endif /* CONFIG_SYSFS */
609 611
610#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
611
612void module_add_driver(struct module *mod, struct device_driver *drv);
613void module_remove_driver(struct device_driver *drv);
614
615#else /* not both CONFIG_SYSFS && CONFIG_MODULES */
616
617static inline void module_add_driver(struct module *mod, struct device_driver *drv)
618{ }
619
620static inline void module_remove_driver(struct device_driver *drv)
621{ }
622
623#endif
624
625#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x) 612#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
626 613
627/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */ 614/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
index ab4cb6ecd47c..8f67e8f2a3cc 100644
--- a/include/linux/pci_hotplug.h
+++ b/include/linux/pci_hotplug.h
@@ -174,7 +174,7 @@ extern int pci_hp_register (struct hotplug_slot *slot);
174extern int pci_hp_deregister (struct hotplug_slot *slot); 174extern int pci_hp_deregister (struct hotplug_slot *slot);
175extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot, 175extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot,
176 struct hotplug_slot_info *info); 176 struct hotplug_slot_info *info);
177extern struct kset pci_hotplug_slots_subsys; 177extern struct kset *pci_hotplug_slots_kset;
178 178
179/* PCI Setting Record (Type 0) */ 179/* PCI Setting Record (Type 0) */
180struct hpp_type0 { 180struct hpp_type0 {
diff --git a/include/linux/pktcdvd.h b/include/linux/pktcdvd.h
index 5ea4f05683f6..04b4d7330e6d 100644
--- a/include/linux/pktcdvd.h
+++ b/include/linux/pktcdvd.h
@@ -290,7 +290,7 @@ struct pktcdvd_device
290 int write_congestion_off; 290 int write_congestion_off;
291 int write_congestion_on; 291 int write_congestion_on;
292 292
293 struct class_device *clsdev; /* sysfs pktcdvd[0-7] class dev */ 293 struct device *dev; /* sysfs pktcdvd[0-7] dev */
294 struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */ 294 struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
295 struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */ 295 struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
296 296
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index e80804316cdb..3261681c82a4 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -35,7 +35,7 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
35extern int platform_get_irq_byname(struct platform_device *, char *); 35extern int platform_get_irq_byname(struct platform_device *, char *);
36extern int platform_add_devices(struct platform_device **, int); 36extern int platform_add_devices(struct platform_device **, int);
37 37
38extern struct platform_device *platform_device_register_simple(char *, int id, 38extern struct platform_device *platform_device_register_simple(const char *, int id,
39 struct resource *, unsigned int); 39 struct resource *, unsigned int);
40 40
41extern struct platform_device *platform_device_alloc(const char *name, int id); 41extern struct platform_device *platform_device_alloc(const char *name, int id);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index cc14656f8682..d6eacda765ca 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -552,18 +552,13 @@ struct user_struct {
552#ifdef CONFIG_FAIR_USER_SCHED 552#ifdef CONFIG_FAIR_USER_SCHED
553 struct task_group *tg; 553 struct task_group *tg;
554#ifdef CONFIG_SYSFS 554#ifdef CONFIG_SYSFS
555 struct kset kset; 555 struct kobject kobj;
556 struct subsys_attribute user_attr;
557 struct work_struct work; 556 struct work_struct work;
558#endif 557#endif
559#endif 558#endif
560}; 559};
561 560
562#ifdef CONFIG_FAIR_USER_SCHED 561extern int uids_sysfs_init(void);
563extern int uids_kobject_init(void);
564#else
565static inline int uids_kobject_init(void) { return 0; }
566#endif
567 562
568extern struct user_struct *find_user(uid_t); 563extern struct user_struct *find_user(uid_t);
569 564
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h
index e285746588d6..f752e73bf977 100644
--- a/include/linux/sysdev.h
+++ b/include/linux/sysdev.h
@@ -29,6 +29,7 @@
29struct sys_device; 29struct sys_device;
30 30
31struct sysdev_class { 31struct sysdev_class {
32 const char *name;
32 struct list_head drivers; 33 struct list_head drivers;
33 34
34 /* Default operations for these types of devices */ 35 /* Default operations for these types of devices */
diff --git a/include/linux/tifm.h b/include/linux/tifm.h
index 6b3a31805c72..2096b76d0cee 100644
--- a/include/linux/tifm.h
+++ b/include/linux/tifm.h
@@ -120,7 +120,7 @@ struct tifm_adapter {
120 struct completion *finish_me; 120 struct completion *finish_me;
121 121
122 struct work_struct media_switcher; 122 struct work_struct media_switcher;
123 struct class_device cdev; 123 struct device dev;
124 124
125 void (*eject)(struct tifm_adapter *fm, 125 void (*eject)(struct tifm_adapter *fm,
126 struct tifm_dev *sock); 126 struct tifm_dev *sock);
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 44c28e94df50..973386d439da 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -18,20 +18,22 @@
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20 20
21struct uio_map;
22
21/** 23/**
22 * struct uio_mem - description of a UIO memory region 24 * struct uio_mem - description of a UIO memory region
23 * @kobj: kobject for this mapping
24 * @addr: address of the device's memory 25 * @addr: address of the device's memory
25 * @size: size of IO 26 * @size: size of IO
26 * @memtype: type of memory addr points to 27 * @memtype: type of memory addr points to
27 * @internal_addr: ioremap-ped version of addr, for driver internal use 28 * @internal_addr: ioremap-ped version of addr, for driver internal use
29 * @map: for use by the UIO core only.
28 */ 30 */
29struct uio_mem { 31struct uio_mem {
30 struct kobject kobj;
31 unsigned long addr; 32 unsigned long addr;
32 unsigned long size; 33 unsigned long size;
33 int memtype; 34 int memtype;
34 void __iomem *internal_addr; 35 void __iomem *internal_addr;
36 struct uio_map *map;
35}; 37};
36 38
37#define MAX_UIO_MAPS 5 39#define MAX_UIO_MAPS 5
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 11f39606e7d9..cfbd38fe2998 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1026,7 +1026,7 @@ struct ib_device {
1026 1026
1027 struct module *owner; 1027 struct module *owner;
1028 struct class_device class_dev; 1028 struct class_device class_dev;
1029 struct kobject ports_parent; 1029 struct kobject *ports_parent;
1030 struct list_head port_list; 1030 struct list_head port_list;
1031 1031
1032 enum { 1032 enum {
diff --git a/init/Kconfig b/init/Kconfig
index b9d11a899b88..f5becd2a12f6 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -363,6 +363,7 @@ config CGROUP_CPUACCT
363 363
364config SYSFS_DEPRECATED 364config SYSFS_DEPRECATED
365 bool "Create deprecated sysfs files" 365 bool "Create deprecated sysfs files"
366 depends on SYSFS
366 default y 367 default y
367 help 368 help
368 This option creates deprecated symlinks such as the 369 This option creates deprecated symlinks such as the
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 4efa1e5385e3..2ae5b8462399 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -55,69 +55,6 @@ static int __init readwrite(char *str)
55__setup("ro", readonly); 55__setup("ro", readonly);
56__setup("rw", readwrite); 56__setup("rw", readwrite);
57 57
58static dev_t try_name(char *name, int part)
59{
60 char path[64];
61 char buf[32];
62 int range;
63 dev_t res;
64 char *s;
65 int len;
66 int fd;
67 unsigned int maj, min;
68
69 /* read device number from .../dev */
70
71 sprintf(path, "/sys/block/%s/dev", name);
72 fd = sys_open(path, 0, 0);
73 if (fd < 0)
74 goto fail;
75 len = sys_read(fd, buf, 32);
76 sys_close(fd);
77 if (len <= 0 || len == 32 || buf[len - 1] != '\n')
78 goto fail;
79 buf[len - 1] = '\0';
80 if (sscanf(buf, "%u:%u", &maj, &min) == 2) {
81 /*
82 * Try the %u:%u format -- see print_dev_t()
83 */
84 res = MKDEV(maj, min);
85 if (maj != MAJOR(res) || min != MINOR(res))
86 goto fail;
87 } else {
88 /*
89 * Nope. Try old-style "0321"
90 */
91 res = new_decode_dev(simple_strtoul(buf, &s, 16));
92 if (*s)
93 goto fail;
94 }
95
96 /* if it's there and we are not looking for a partition - that's it */
97 if (!part)
98 return res;
99
100 /* otherwise read range from .../range */
101 sprintf(path, "/sys/block/%s/range", name);
102 fd = sys_open(path, 0, 0);
103 if (fd < 0)
104 goto fail;
105 len = sys_read(fd, buf, 32);
106 sys_close(fd);
107 if (len <= 0 || len == 32 || buf[len - 1] != '\n')
108 goto fail;
109 buf[len - 1] = '\0';
110 range = simple_strtoul(buf, &s, 10);
111 if (*s)
112 goto fail;
113
114 /* if partition is within range - we got it */
115 if (part < range)
116 return res + part;
117fail:
118 return 0;
119}
120
121/* 58/*
122 * Convert a name into device number. We accept the following variants: 59 * Convert a name into device number. We accept the following variants:
123 * 60 *
@@ -129,12 +66,10 @@ fail:
129 * 5) /dev/<disk_name>p<decimal> - same as the above, that form is 66 * 5) /dev/<disk_name>p<decimal> - same as the above, that form is
130 * used when disk name of partitioned disk ends on a digit. 67 * used when disk name of partitioned disk ends on a digit.
131 * 68 *
132 * If name doesn't have fall into the categories above, we return 0. 69 * If name doesn't have fall into the categories above, we return (0,0).
133 * Sysfs is used to check if something is a disk name - it has 70 * block_class is used to check if something is a disk name. If the disk
134 * all known disks under bus/block/devices. If the disk name 71 * name contains slashes, the device name has them replaced with
135 * contains slashes, name of sysfs node has them replaced with 72 * bangs.
136 * bangs. try_name() does the actual checks, assuming that sysfs
137 * is mounted on rootfs /sys.
138 */ 73 */
139 74
140dev_t name_to_dev_t(char *name) 75dev_t name_to_dev_t(char *name)
@@ -142,13 +77,6 @@ dev_t name_to_dev_t(char *name)
142 char s[32]; 77 char s[32];
143 char *p; 78 char *p;
144 dev_t res = 0; 79 dev_t res = 0;
145 int part;
146
147#ifdef CONFIG_SYSFS
148 int mkdir_err = sys_mkdir("/sys", 0700);
149 if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
150 goto out;
151#endif
152 80
153 if (strncmp(name, "/dev/", 5) != 0) { 81 if (strncmp(name, "/dev/", 5) != 0) {
154 unsigned maj, min; 82 unsigned maj, min;
@@ -164,6 +92,7 @@ dev_t name_to_dev_t(char *name)
164 } 92 }
165 goto done; 93 goto done;
166 } 94 }
95
167 name += 5; 96 name += 5;
168 res = Root_NFS; 97 res = Root_NFS;
169 if (strcmp(name, "nfs") == 0) 98 if (strcmp(name, "nfs") == 0)
@@ -178,35 +107,14 @@ dev_t name_to_dev_t(char *name)
178 for (p = s; *p; p++) 107 for (p = s; *p; p++)
179 if (*p == '/') 108 if (*p == '/')
180 *p = '!'; 109 *p = '!';
181 res = try_name(s, 0); 110 res = blk_lookup_devt(s);
182 if (res) 111 if (res)
183 goto done; 112 goto done;
184 113
185 while (p > s && isdigit(p[-1])) 114fail:
186 p--; 115 return 0;
187 if (p == s || !*p || *p == '0')
188 goto fail;
189 part = simple_strtoul(p, NULL, 10);
190 *p = '\0';
191 res = try_name(s, part);
192 if (res)
193 goto done;
194
195 if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
196 goto fail;
197 p[-1] = '\0';
198 res = try_name(s, part);
199done: 116done:
200#ifdef CONFIG_SYSFS
201 sys_umount("/sys", 0);
202out:
203 if (!mkdir_err)
204 sys_rmdir("/sys");
205#endif
206 return res; 117 return res;
207fail:
208 res = 0;
209 goto done;
210} 118}
211 119
212static int __init root_dev_setup(char *line) 120static int __init root_dev_setup(char *line)
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 65daa5373ca6..e53bc30e9ba5 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -17,30 +17,34 @@
17#include <linux/sched.h> 17#include <linux/sched.h>
18 18
19#define KERNEL_ATTR_RO(_name) \ 19#define KERNEL_ATTR_RO(_name) \
20static struct subsys_attribute _name##_attr = __ATTR_RO(_name) 20static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
21 21
22#define KERNEL_ATTR_RW(_name) \ 22#define KERNEL_ATTR_RW(_name) \
23static struct subsys_attribute _name##_attr = \ 23static struct kobj_attribute _name##_attr = \
24 __ATTR(_name, 0644, _name##_show, _name##_store) 24 __ATTR(_name, 0644, _name##_show, _name##_store)
25 25
26#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 26#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
27/* current uevent sequence number */ 27/* current uevent sequence number */
28static ssize_t uevent_seqnum_show(struct kset *kset, char *page) 28static ssize_t uevent_seqnum_show(struct kobject *kobj,
29 struct kobj_attribute *attr, char *buf)
29{ 30{
30 return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum); 31 return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum);
31} 32}
32KERNEL_ATTR_RO(uevent_seqnum); 33KERNEL_ATTR_RO(uevent_seqnum);
33 34
34/* uevent helper program, used during early boo */ 35/* uevent helper program, used during early boo */
35static ssize_t uevent_helper_show(struct kset *kset, char *page) 36static ssize_t uevent_helper_show(struct kobject *kobj,
37 struct kobj_attribute *attr, char *buf)
36{ 38{
37 return sprintf(page, "%s\n", uevent_helper); 39 return sprintf(buf, "%s\n", uevent_helper);
38} 40}
39static ssize_t uevent_helper_store(struct kset *kset, const char *page, size_t count) 41static ssize_t uevent_helper_store(struct kobject *kobj,
42 struct kobj_attribute *attr,
43 const char *buf, size_t count)
40{ 44{
41 if (count+1 > UEVENT_HELPER_PATH_LEN) 45 if (count+1 > UEVENT_HELPER_PATH_LEN)
42 return -ENOENT; 46 return -ENOENT;
43 memcpy(uevent_helper, page, count); 47 memcpy(uevent_helper, buf, count);
44 uevent_helper[count] = '\0'; 48 uevent_helper[count] = '\0';
45 if (count && uevent_helper[count-1] == '\n') 49 if (count && uevent_helper[count-1] == '\n')
46 uevent_helper[count-1] = '\0'; 50 uevent_helper[count-1] = '\0';
@@ -50,21 +54,24 @@ KERNEL_ATTR_RW(uevent_helper);
50#endif 54#endif
51 55
52#ifdef CONFIG_KEXEC 56#ifdef CONFIG_KEXEC
53static ssize_t kexec_loaded_show(struct kset *kset, char *page) 57static ssize_t kexec_loaded_show(struct kobject *kobj,
58 struct kobj_attribute *attr, char *buf)
54{ 59{
55 return sprintf(page, "%d\n", !!kexec_image); 60 return sprintf(buf, "%d\n", !!kexec_image);
56} 61}
57KERNEL_ATTR_RO(kexec_loaded); 62KERNEL_ATTR_RO(kexec_loaded);
58 63
59static ssize_t kexec_crash_loaded_show(struct kset *kset, char *page) 64static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
65 struct kobj_attribute *attr, char *buf)
60{ 66{
61 return sprintf(page, "%d\n", !!kexec_crash_image); 67 return sprintf(buf, "%d\n", !!kexec_crash_image);
62} 68}
63KERNEL_ATTR_RO(kexec_crash_loaded); 69KERNEL_ATTR_RO(kexec_crash_loaded);
64 70
65static ssize_t vmcoreinfo_show(struct kset *kset, char *page) 71static ssize_t vmcoreinfo_show(struct kobject *kobj,
72 struct kobj_attribute *attr, char *buf)
66{ 73{
67 return sprintf(page, "%lx %x\n", 74 return sprintf(buf, "%lx %x\n",
68 paddr_vmcoreinfo_note(), 75 paddr_vmcoreinfo_note(),
69 (unsigned int)vmcoreinfo_max_size); 76 (unsigned int)vmcoreinfo_max_size);
70} 77}
@@ -94,8 +101,8 @@ static struct bin_attribute notes_attr = {
94 .read = &notes_read, 101 .read = &notes_read,
95}; 102};
96 103
97decl_subsys(kernel, NULL, NULL); 104struct kobject *kernel_kobj;
98EXPORT_SYMBOL_GPL(kernel_subsys); 105EXPORT_SYMBOL_GPL(kernel_kobj);
99 106
100static struct attribute * kernel_attrs[] = { 107static struct attribute * kernel_attrs[] = {
101#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 108#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
@@ -116,24 +123,39 @@ static struct attribute_group kernel_attr_group = {
116 123
117static int __init ksysfs_init(void) 124static int __init ksysfs_init(void)
118{ 125{
119 int error = subsystem_register(&kernel_subsys); 126 int error;
120 if (!error)
121 error = sysfs_create_group(&kernel_subsys.kobj,
122 &kernel_attr_group);
123 127
124 if (!error && notes_size > 0) { 128 kernel_kobj = kobject_create_and_add("kernel", NULL);
125 notes_attr.size = notes_size; 129 if (!kernel_kobj) {
126 error = sysfs_create_bin_file(&kernel_subsys.kobj, 130 error = -ENOMEM;
127 &notes_attr); 131 goto exit;
128 } 132 }
133 error = sysfs_create_group(kernel_kobj, &kernel_attr_group);
134 if (error)
135 goto kset_exit;
129 136
130 /* 137 if (notes_size > 0) {
131 * Create "/sys/kernel/uids" directory and corresponding root user's 138 notes_attr.size = notes_size;
132 * directory under it. 139 error = sysfs_create_bin_file(kernel_kobj, &notes_attr);
133 */ 140 if (error)
134 if (!error) 141 goto group_exit;
135 error = uids_kobject_init(); 142 }
136 143
144 /* create the /sys/kernel/uids/ directory */
145 error = uids_sysfs_init();
146 if (error)
147 goto notes_exit;
148
149 return 0;
150
151notes_exit:
152 if (notes_size > 0)
153 sysfs_remove_bin_file(kernel_kobj, &notes_attr);
154group_exit:
155 sysfs_remove_group(kernel_kobj, &kernel_attr_group);
156kset_exit:
157 kobject_put(kernel_kobj);
158exit:
137 return error; 159 return error;
138} 160}
139 161
diff --git a/kernel/module.c b/kernel/module.c
index c2e3e2e98801..dcb8a2cbf75e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -47,8 +47,6 @@
47#include <asm/cacheflush.h> 47#include <asm/cacheflush.h>
48#include <linux/license.h> 48#include <linux/license.h>
49 49
50extern int module_sysfs_initialized;
51
52#if 0 50#if 0
53#define DEBUGP printk 51#define DEBUGP printk
54#else 52#else
@@ -1122,7 +1120,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
1122 ++loaded; 1120 ++loaded;
1123 } 1121 }
1124 1122
1125 notes_attrs->dir = kobject_add_dir(&mod->mkobj.kobj, "notes"); 1123 notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
1126 if (!notes_attrs->dir) 1124 if (!notes_attrs->dir)
1127 goto out; 1125 goto out;
1128 1126
@@ -1219,15 +1217,16 @@ int mod_sysfs_init(struct module *mod)
1219 err = -EINVAL; 1217 err = -EINVAL;
1220 goto out; 1218 goto out;
1221 } 1219 }
1222 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1223 err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name);
1224 if (err)
1225 goto out;
1226 kobj_set_kset_s(&mod->mkobj, module_subsys);
1227 mod->mkobj.mod = mod; 1220 mod->mkobj.mod = mod;
1228 1221
1229 kobject_init(&mod->mkobj.kobj); 1222 memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
1223 mod->mkobj.kobj.kset = module_kset;
1224 err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
1225 "%s", mod->name);
1226 if (err)
1227 kobject_put(&mod->mkobj.kobj);
1230 1228
1229 /* delay uevent until full sysfs population */
1231out: 1230out:
1232 return err; 1231 return err;
1233} 1232}
@@ -1238,12 +1237,7 @@ int mod_sysfs_setup(struct module *mod,
1238{ 1237{
1239 int err; 1238 int err;
1240 1239
1241 /* delay uevent until full sysfs population */ 1240 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
1242 err = kobject_add(&mod->mkobj.kobj);
1243 if (err)
1244 goto out;
1245
1246 mod->holders_dir = kobject_add_dir(&mod->mkobj.kobj, "holders");
1247 if (!mod->holders_dir) { 1241 if (!mod->holders_dir) {
1248 err = -ENOMEM; 1242 err = -ENOMEM;
1249 goto out_unreg; 1243 goto out_unreg;
@@ -1263,11 +1257,9 @@ int mod_sysfs_setup(struct module *mod,
1263out_unreg_param: 1257out_unreg_param:
1264 module_param_sysfs_remove(mod); 1258 module_param_sysfs_remove(mod);
1265out_unreg_holders: 1259out_unreg_holders:
1266 kobject_unregister(mod->holders_dir); 1260 kobject_put(mod->holders_dir);
1267out_unreg: 1261out_unreg:
1268 kobject_del(&mod->mkobj.kobj);
1269 kobject_put(&mod->mkobj.kobj); 1262 kobject_put(&mod->mkobj.kobj);
1270out:
1271 return err; 1263 return err;
1272} 1264}
1273#endif 1265#endif
@@ -1276,9 +1268,9 @@ static void mod_kobject_remove(struct module *mod)
1276{ 1268{
1277 module_remove_modinfo_attrs(mod); 1269 module_remove_modinfo_attrs(mod);
1278 module_param_sysfs_remove(mod); 1270 module_param_sysfs_remove(mod);
1279 kobject_unregister(mod->mkobj.drivers_dir); 1271 kobject_put(mod->mkobj.drivers_dir);
1280 kobject_unregister(mod->holders_dir); 1272 kobject_put(mod->holders_dir);
1281 kobject_unregister(&mod->mkobj.kobj); 1273 kobject_put(&mod->mkobj.kobj);
1282} 1274}
1283 1275
1284/* 1276/*
@@ -1884,10 +1876,10 @@ static struct module *load_module(void __user *umod,
1884 /* Now we've moved module, initialize linked lists, etc. */ 1876 /* Now we've moved module, initialize linked lists, etc. */
1885 module_unload_init(mod); 1877 module_unload_init(mod);
1886 1878
1887 /* Initialize kobject, so we can reference it. */ 1879 /* add kobject, so we can reference it. */
1888 err = mod_sysfs_init(mod); 1880 err = mod_sysfs_init(mod);
1889 if (err) 1881 if (err)
1890 goto cleanup; 1882 goto free_unload;
1891 1883
1892 /* Set up license info based on the info section */ 1884 /* Set up license info based on the info section */
1893 set_license(mod, get_modinfo(sechdrs, infoindex, "license")); 1885 set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
@@ -2057,6 +2049,9 @@ static struct module *load_module(void __user *umod,
2057 arch_cleanup: 2049 arch_cleanup:
2058 module_arch_cleanup(mod); 2050 module_arch_cleanup(mod);
2059 cleanup: 2051 cleanup:
2052 kobject_del(&mod->mkobj.kobj);
2053 kobject_put(&mod->mkobj.kobj);
2054 free_unload:
2060 module_unload_free(mod); 2055 module_unload_free(mod);
2061 module_free(mod, mod->module_init); 2056 module_free(mod, mod->module_init);
2062 free_core: 2057 free_core:
@@ -2502,93 +2497,6 @@ void print_modules(void)
2502 printk("\n"); 2497 printk("\n");
2503} 2498}
2504 2499
2505#ifdef CONFIG_SYSFS
2506static char *make_driver_name(struct device_driver *drv)
2507{
2508 char *driver_name;
2509
2510 driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
2511 GFP_KERNEL);
2512 if (!driver_name)
2513 return NULL;
2514
2515 sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
2516 return driver_name;
2517}
2518
2519static void module_create_drivers_dir(struct module_kobject *mk)
2520{
2521 if (!mk || mk->drivers_dir)
2522 return;
2523
2524 mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers");
2525}
2526
2527void module_add_driver(struct module *mod, struct device_driver *drv)
2528{
2529 char *driver_name;
2530 int no_warn;
2531 struct module_kobject *mk = NULL;
2532
2533 if (!drv)
2534 return;
2535
2536 if (mod)
2537 mk = &mod->mkobj;
2538 else if (drv->mod_name) {
2539 struct kobject *mkobj;
2540
2541 /* Lookup built-in module entry in /sys/modules */
2542 mkobj = kset_find_obj(&module_subsys, drv->mod_name);
2543 if (mkobj) {
2544 mk = container_of(mkobj, struct module_kobject, kobj);
2545 /* remember our module structure */
2546 drv->mkobj = mk;
2547 /* kset_find_obj took a reference */
2548 kobject_put(mkobj);
2549 }
2550 }
2551
2552 if (!mk)
2553 return;
2554
2555 /* Don't check return codes; these calls are idempotent */
2556 no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
2557 driver_name = make_driver_name(drv);
2558 if (driver_name) {
2559 module_create_drivers_dir(mk);
2560 no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
2561 driver_name);
2562 kfree(driver_name);
2563 }
2564}
2565EXPORT_SYMBOL(module_add_driver);
2566
2567void module_remove_driver(struct device_driver *drv)
2568{
2569 struct module_kobject *mk = NULL;
2570 char *driver_name;
2571
2572 if (!drv)
2573 return;
2574
2575 sysfs_remove_link(&drv->kobj, "module");
2576
2577 if (drv->owner)
2578 mk = &drv->owner->mkobj;
2579 else if (drv->mkobj)
2580 mk = drv->mkobj;
2581 if (mk && mk->drivers_dir) {
2582 driver_name = make_driver_name(drv);
2583 if (driver_name) {
2584 sysfs_remove_link(mk->drivers_dir, driver_name);
2585 kfree(driver_name);
2586 }
2587 }
2588}
2589EXPORT_SYMBOL(module_remove_driver);
2590#endif
2591
2592#ifdef CONFIG_MODVERSIONS 2500#ifdef CONFIG_MODVERSIONS
2593/* Generate the signature for struct module here, too, for modversions. */ 2501/* Generate the signature for struct module here, too, for modversions. */
2594void struct_module(struct module *mod) { return; } 2502void struct_module(struct module *mod) { return; }
diff --git a/kernel/params.c b/kernel/params.c
index 7686417ee00e..b4da9505f4d2 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -560,11 +560,10 @@ static void __init kernel_param_sysfs_setup(const char *name,
560 BUG_ON(!mk); 560 BUG_ON(!mk);
561 561
562 mk->mod = THIS_MODULE; 562 mk->mod = THIS_MODULE;
563 kobj_set_kset_s(mk, module_subsys); 563 mk->kobj.kset = module_kset;
564 kobject_set_name(&mk->kobj, name); 564 ret = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name);
565 kobject_init(&mk->kobj);
566 ret = kobject_add(&mk->kobj);
567 if (ret) { 565 if (ret) {
566 kobject_put(&mk->kobj);
568 printk(KERN_ERR "Module '%s' failed to be added to sysfs, " 567 printk(KERN_ERR "Module '%s' failed to be added to sysfs, "
569 "error number %d\n", name, ret); 568 "error number %d\n", name, ret);
570 printk(KERN_ERR "The system will be unstable now.\n"); 569 printk(KERN_ERR "The system will be unstable now.\n");
@@ -679,8 +678,6 @@ static struct sysfs_ops module_sysfs_ops = {
679 .store = module_attr_store, 678 .store = module_attr_store,
680}; 679};
681 680
682static struct kobj_type module_ktype;
683
684static int uevent_filter(struct kset *kset, struct kobject *kobj) 681static int uevent_filter(struct kset *kset, struct kobject *kobj)
685{ 682{
686 struct kobj_type *ktype = get_ktype(kobj); 683 struct kobj_type *ktype = get_ktype(kobj);
@@ -694,21 +691,11 @@ static struct kset_uevent_ops module_uevent_ops = {
694 .filter = uevent_filter, 691 .filter = uevent_filter,
695}; 692};
696 693
697decl_subsys(module, &module_ktype, &module_uevent_ops); 694struct kset *module_kset;
698int module_sysfs_initialized; 695int module_sysfs_initialized;
699 696
700static void module_release(struct kobject *kobj) 697struct kobj_type module_ktype = {
701{
702 /*
703 * Stupid empty release function to allow the memory for the kobject to
704 * be properly cleaned up. This will not need to be present for 2.6.25
705 * with the upcoming kobject core rework.
706 */
707}
708
709static struct kobj_type module_ktype = {
710 .sysfs_ops = &module_sysfs_ops, 698 .sysfs_ops = &module_sysfs_ops,
711 .release = module_release,
712}; 699};
713 700
714/* 701/*
@@ -716,13 +703,11 @@ static struct kobj_type module_ktype = {
716 */ 703 */
717static int __init param_sysfs_init(void) 704static int __init param_sysfs_init(void)
718{ 705{
719 int ret; 706 module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
720 707 if (!module_kset) {
721 ret = subsystem_register(&module_subsys); 708 printk(KERN_WARNING "%s (%d): error creating kset\n",
722 if (ret < 0) { 709 __FILE__, __LINE__);
723 printk(KERN_WARNING "%s (%d): subsystem_register error: %d\n", 710 return -ENOMEM;
724 __FILE__, __LINE__, ret);
725 return ret;
726 } 711 }
727 module_sysfs_initialized = 1; 712 module_sysfs_initialized = 1;
728 713
@@ -732,14 +717,7 @@ static int __init param_sysfs_init(void)
732} 717}
733subsys_initcall(param_sysfs_init); 718subsys_initcall(param_sysfs_init);
734 719
735#else 720#endif /* CONFIG_SYSFS */
736#if 0
737static struct sysfs_ops module_sysfs_ops = {
738 .show = NULL,
739 .store = NULL,
740};
741#endif
742#endif
743 721
744EXPORT_SYMBOL(param_set_byte); 722EXPORT_SYMBOL(param_set_byte);
745EXPORT_SYMBOL(param_get_byte); 723EXPORT_SYMBOL(param_get_byte);
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 05b64790fe83..b138b431e271 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -567,7 +567,8 @@ static const char * const hibernation_modes[] = {
567 * supports it (as determined by having hibernation_ops). 567 * supports it (as determined by having hibernation_ops).
568 */ 568 */
569 569
570static ssize_t disk_show(struct kset *kset, char *buf) 570static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
571 char *buf)
571{ 572{
572 int i; 573 int i;
573 char *start = buf; 574 char *start = buf;
@@ -597,7 +598,8 @@ static ssize_t disk_show(struct kset *kset, char *buf)
597} 598}
598 599
599 600
600static ssize_t disk_store(struct kset *kset, const char *buf, size_t n) 601static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
602 const char *buf, size_t n)
601{ 603{
602 int error = 0; 604 int error = 0;
603 int i; 605 int i;
@@ -642,13 +644,15 @@ static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)
642 644
643power_attr(disk); 645power_attr(disk);
644 646
645static ssize_t resume_show(struct kset *kset, char *buf) 647static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
648 char *buf)
646{ 649{
647 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device), 650 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
648 MINOR(swsusp_resume_device)); 651 MINOR(swsusp_resume_device));
649} 652}
650 653
651static ssize_t resume_store(struct kset *kset, const char *buf, size_t n) 654static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
655 const char *buf, size_t n)
652{ 656{
653 unsigned int maj, min; 657 unsigned int maj, min;
654 dev_t res; 658 dev_t res;
@@ -674,12 +678,14 @@ static ssize_t resume_store(struct kset *kset, const char *buf, size_t n)
674 678
675power_attr(resume); 679power_attr(resume);
676 680
677static ssize_t image_size_show(struct kset *kset, char *buf) 681static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
682 char *buf)
678{ 683{
679 return sprintf(buf, "%lu\n", image_size); 684 return sprintf(buf, "%lu\n", image_size);
680} 685}
681 686
682static ssize_t image_size_store(struct kset *kset, const char *buf, size_t n) 687static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
688 const char *buf, size_t n)
683{ 689{
684 unsigned long size; 690 unsigned long size;
685 691
@@ -708,7 +714,7 @@ static struct attribute_group attr_group = {
708 714
709static int __init pm_disk_init(void) 715static int __init pm_disk_init(void)
710{ 716{
711 return sysfs_create_group(&power_subsys.kobj, &attr_group); 717 return sysfs_create_group(power_kobj, &attr_group);
712} 718}
713 719
714core_initcall(pm_disk_init); 720core_initcall(pm_disk_init);
diff --git a/kernel/power/main.c b/kernel/power/main.c
index f71c9504a5c5..efc08360e627 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -276,8 +276,7 @@ EXPORT_SYMBOL(pm_suspend);
276 276
277#endif /* CONFIG_SUSPEND */ 277#endif /* CONFIG_SUSPEND */
278 278
279decl_subsys(power,NULL,NULL); 279struct kobject *power_kobj;
280
281 280
282/** 281/**
283 * state - control system power state. 282 * state - control system power state.
@@ -290,7 +289,8 @@ decl_subsys(power,NULL,NULL);
290 * proper enumerated value, and initiates a suspend transition. 289 * proper enumerated value, and initiates a suspend transition.
291 */ 290 */
292 291
293static ssize_t state_show(struct kset *kset, char *buf) 292static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
293 char *buf)
294{ 294{
295 char *s = buf; 295 char *s = buf;
296#ifdef CONFIG_SUSPEND 296#ifdef CONFIG_SUSPEND
@@ -311,7 +311,8 @@ static ssize_t state_show(struct kset *kset, char *buf)
311 return (s - buf); 311 return (s - buf);
312} 312}
313 313
314static ssize_t state_store(struct kset *kset, const char *buf, size_t n) 314static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
315 const char *buf, size_t n)
315{ 316{
316#ifdef CONFIG_SUSPEND 317#ifdef CONFIG_SUSPEND
317 suspend_state_t state = PM_SUSPEND_STANDBY; 318 suspend_state_t state = PM_SUSPEND_STANDBY;
@@ -348,13 +349,15 @@ power_attr(state);
348#ifdef CONFIG_PM_TRACE 349#ifdef CONFIG_PM_TRACE
349int pm_trace_enabled; 350int pm_trace_enabled;
350 351
351static ssize_t pm_trace_show(struct kset *kset, char *buf) 352static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
353 char *buf)
352{ 354{
353 return sprintf(buf, "%d\n", pm_trace_enabled); 355 return sprintf(buf, "%d\n", pm_trace_enabled);
354} 356}
355 357
356static ssize_t 358static ssize_t
357pm_trace_store(struct kset *kset, const char *buf, size_t n) 359pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
360 const char *buf, size_t n)
358{ 361{
359 int val; 362 int val;
360 363
@@ -386,10 +389,10 @@ static struct attribute_group attr_group = {
386 389
387static int __init pm_init(void) 390static int __init pm_init(void)
388{ 391{
389 int error = subsystem_register(&power_subsys); 392 power_kobj = kobject_create_and_add("power", NULL);
390 if (!error) 393 if (!power_kobj)
391 error = sysfs_create_group(&power_subsys.kobj,&attr_group); 394 return -ENOMEM;
392 return error; 395 return sysfs_create_group(power_kobj, &attr_group);
393} 396}
394 397
395core_initcall(pm_init); 398core_initcall(pm_init);
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 195dc4611764..2093c3a9a994 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -54,7 +54,7 @@ extern int pfn_is_nosave(unsigned long);
54extern struct mutex pm_mutex; 54extern struct mutex pm_mutex;
55 55
56#define power_attr(_name) \ 56#define power_attr(_name) \
57static struct subsys_attribute _name##_attr = { \ 57static struct kobj_attribute _name##_attr = { \
58 .attr = { \ 58 .attr = { \
59 .name = __stringify(_name), \ 59 .name = __stringify(_name), \
60 .mode = 0644, \ 60 .mode = 0644, \
@@ -63,8 +63,6 @@ static struct subsys_attribute _name##_attr = { \
63 .store = _name##_store, \ 63 .store = _name##_store, \
64} 64}
65 65
66extern struct kset power_subsys;
67
68/* Preferred image size in bytes (default 500 MB) */ 66/* Preferred image size in bytes (default 500 MB) */
69extern unsigned long image_size; 67extern unsigned long image_size;
70extern int in_suspend; 68extern int in_suspend;
diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
index e3055ba69159..092e4c620af9 100644
--- a/kernel/rtmutex-tester.c
+++ b/kernel/rtmutex-tester.c
@@ -394,7 +394,7 @@ static SYSDEV_ATTR(status, 0600, sysfs_test_status, NULL);
394static SYSDEV_ATTR(command, 0600, NULL, sysfs_test_command); 394static SYSDEV_ATTR(command, 0600, NULL, sysfs_test_command);
395 395
396static struct sysdev_class rttest_sysclass = { 396static struct sysdev_class rttest_sysclass = {
397 set_kset_name("rttest"), 397 .name = "rttest",
398}; 398};
399 399
400static int init_test_thread(int id) 400static int init_test_thread(int id)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index c8a9d13874df..8d6125ad2cf0 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -441,7 +441,7 @@ static SYSDEV_ATTR(available_clocksource, 0600,
441 sysfs_show_available_clocksources, NULL); 441 sysfs_show_available_clocksources, NULL);
442 442
443static struct sysdev_class clocksource_sysclass = { 443static struct sysdev_class clocksource_sysclass = {
444 set_kset_name("clocksource"), 444 .name = "clocksource",
445}; 445};
446 446
447static struct sys_device device_clocksource = { 447static struct sys_device device_clocksource = {
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e5e466b27598..ab46ae8c062b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -335,9 +335,9 @@ static int timekeeping_suspend(struct sys_device *dev, pm_message_t state)
335 335
336/* sysfs resume/suspend bits for timekeeping */ 336/* sysfs resume/suspend bits for timekeeping */
337static struct sysdev_class timekeeping_sysclass = { 337static struct sysdev_class timekeeping_sysclass = {
338 .name = "timekeeping",
338 .resume = timekeeping_resume, 339 .resume = timekeeping_resume,
339 .suspend = timekeeping_suspend, 340 .suspend = timekeeping_suspend,
340 set_kset_name("timekeeping"),
341}; 341};
342 342
343static struct sys_device device_timer = { 343static struct sys_device device_timer = {
diff --git a/kernel/user.c b/kernel/user.c
index 8320a87f3e5a..ab4fd706993b 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -115,7 +115,7 @@ static void sched_switch_user(struct task_struct *p) { }
115 115
116#if defined(CONFIG_FAIR_USER_SCHED) && defined(CONFIG_SYSFS) 116#if defined(CONFIG_FAIR_USER_SCHED) && defined(CONFIG_SYSFS)
117 117
118static struct kobject uids_kobject; /* represents /sys/kernel/uids directory */ 118static struct kset *uids_kset; /* represents the /sys/kernel/uids/ directory */
119static DEFINE_MUTEX(uids_mutex); 119static DEFINE_MUTEX(uids_mutex);
120 120
121static inline void uids_mutex_lock(void) 121static inline void uids_mutex_lock(void)
@@ -128,86 +128,83 @@ static inline void uids_mutex_unlock(void)
128 mutex_unlock(&uids_mutex); 128 mutex_unlock(&uids_mutex);
129} 129}
130 130
131/* return cpu shares held by the user */ 131/* uid directory attributes */
132static ssize_t cpu_shares_show(struct kset *kset, char *buffer) 132static ssize_t cpu_shares_show(struct kobject *kobj,
133 struct kobj_attribute *attr,
134 char *buf)
133{ 135{
134 struct user_struct *up = container_of(kset, struct user_struct, kset); 136 struct user_struct *up = container_of(kobj, struct user_struct, kobj);
135 137
136 return sprintf(buffer, "%lu\n", sched_group_shares(up->tg)); 138 return sprintf(buf, "%lu\n", sched_group_shares(up->tg));
137} 139}
138 140
139/* modify cpu shares held by the user */ 141static ssize_t cpu_shares_store(struct kobject *kobj,
140static ssize_t cpu_shares_store(struct kset *kset, const char *buffer, 142 struct kobj_attribute *attr,
141 size_t size) 143 const char *buf, size_t size)
142{ 144{
143 struct user_struct *up = container_of(kset, struct user_struct, kset); 145 struct user_struct *up = container_of(kobj, struct user_struct, kobj);
144 unsigned long shares; 146 unsigned long shares;
145 int rc; 147 int rc;
146 148
147 sscanf(buffer, "%lu", &shares); 149 sscanf(buf, "%lu", &shares);
148 150
149 rc = sched_group_set_shares(up->tg, shares); 151 rc = sched_group_set_shares(up->tg, shares);
150 152
151 return (rc ? rc : size); 153 return (rc ? rc : size);
152} 154}
153 155
154static void user_attr_init(struct subsys_attribute *sa, char *name, int mode) 156static struct kobj_attribute cpu_share_attr =
157 __ATTR(cpu_share, 0644, cpu_shares_show, cpu_shares_store);
158
159/* default attributes per uid directory */
160static struct attribute *uids_attributes[] = {
161 &cpu_share_attr.attr,
162 NULL
163};
164
165/* the lifetime of user_struct is not managed by the core (now) */
166static void uids_release(struct kobject *kobj)
155{ 167{
156 sa->attr.name = name; 168 return;
157 sa->attr.mode = mode;
158 sa->show = cpu_shares_show;
159 sa->store = cpu_shares_store;
160} 169}
161 170
162/* Create "/sys/kernel/uids/<uid>" directory and 171static struct kobj_type uids_ktype = {
163 * "/sys/kernel/uids/<uid>/cpu_share" file for this user. 172 .sysfs_ops = &kobj_sysfs_ops,
164 */ 173 .default_attrs = uids_attributes,
165static int user_kobject_create(struct user_struct *up) 174 .release = uids_release,
175};
176
177/* create /sys/kernel/uids/<uid>/cpu_share file for this user */
178static int uids_user_create(struct user_struct *up)
166{ 179{
167 struct kset *kset = &up->kset; 180 struct kobject *kobj = &up->kobj;
168 struct kobject *kobj = &kset->kobj;
169 int error; 181 int error;
170 182
171 memset(kset, 0, sizeof(struct kset)); 183 memset(kobj, 0, sizeof(struct kobject));
172 kobj->parent = &uids_kobject; /* create under /sys/kernel/uids dir */ 184 kobj->kset = uids_kset;
173 kobject_set_name(kobj, "%d", up->uid); 185 error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
174 kset_init(kset); 186 if (error) {
175 user_attr_init(&up->user_attr, "cpu_share", 0644); 187 kobject_put(kobj);
176
177 error = kobject_add(kobj);
178 if (error)
179 goto done; 188 goto done;
180 189 }
181 error = sysfs_create_file(kobj, &up->user_attr.attr);
182 if (error)
183 kobject_del(kobj);
184 190
185 kobject_uevent(kobj, KOBJ_ADD); 191 kobject_uevent(kobj, KOBJ_ADD);
186
187done: 192done:
188 return error; 193 return error;
189} 194}
190 195
191/* create these in sysfs filesystem: 196/* create these entries in sysfs:
192 * "/sys/kernel/uids" directory 197 * "/sys/kernel/uids" directory
193 * "/sys/kernel/uids/0" directory (for root user) 198 * "/sys/kernel/uids/0" directory (for root user)
194 * "/sys/kernel/uids/0/cpu_share" file (for root user) 199 * "/sys/kernel/uids/0/cpu_share" file (for root user)
195 */ 200 */
196int __init uids_kobject_init(void) 201int __init uids_sysfs_init(void)
197{ 202{
198 int error; 203 uids_kset = kset_create_and_add("uids", NULL, kernel_kobj);
204 if (!uids_kset)
205 return -ENOMEM;
199 206
200 /* create under /sys/kernel dir */ 207 return uids_user_create(&root_user);
201 uids_kobject.parent = &kernel_subsys.kobj;
202 uids_kobject.kset = &kernel_subsys;
203 kobject_set_name(&uids_kobject, "uids");
204 kobject_init(&uids_kobject);
205
206 error = kobject_add(&uids_kobject);
207 if (!error)
208 error = user_kobject_create(&root_user);
209
210 return error;
211} 208}
212 209
213/* work function to remove sysfs directory for a user and free up 210/* work function to remove sysfs directory for a user and free up
@@ -216,7 +213,6 @@ int __init uids_kobject_init(void)
216static void remove_user_sysfs_dir(struct work_struct *w) 213static void remove_user_sysfs_dir(struct work_struct *w)
217{ 214{
218 struct user_struct *up = container_of(w, struct user_struct, work); 215 struct user_struct *up = container_of(w, struct user_struct, work);
219 struct kobject *kobj = &up->kset.kobj;
220 unsigned long flags; 216 unsigned long flags;
221 int remove_user = 0; 217 int remove_user = 0;
222 218
@@ -238,9 +234,9 @@ static void remove_user_sysfs_dir(struct work_struct *w)
238 if (!remove_user) 234 if (!remove_user)
239 goto done; 235 goto done;
240 236
241 sysfs_remove_file(kobj, &up->user_attr.attr); 237 kobject_uevent(&up->kobj, KOBJ_REMOVE);
242 kobject_uevent(kobj, KOBJ_REMOVE); 238 kobject_del(&up->kobj);
243 kobject_del(kobj); 239 kobject_put(&up->kobj);
244 240
245 sched_destroy_user(up); 241 sched_destroy_user(up);
246 key_put(up->uid_keyring); 242 key_put(up->uid_keyring);
@@ -267,7 +263,8 @@ static inline void free_user(struct user_struct *up, unsigned long flags)
267 263
268#else /* CONFIG_FAIR_USER_SCHED && CONFIG_SYSFS */ 264#else /* CONFIG_FAIR_USER_SCHED && CONFIG_SYSFS */
269 265
270static inline int user_kobject_create(struct user_struct *up) { return 0; } 266int uids_sysfs_init(void) { return 0; }
267static inline int uids_user_create(struct user_struct *up) { return 0; }
271static inline void uids_mutex_lock(void) { } 268static inline void uids_mutex_lock(void) { }
272static inline void uids_mutex_unlock(void) { } 269static inline void uids_mutex_unlock(void) { }
273 270
@@ -324,7 +321,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
324 struct hlist_head *hashent = uidhashentry(ns, uid); 321 struct hlist_head *hashent = uidhashentry(ns, uid);
325 struct user_struct *up; 322 struct user_struct *up;
326 323
327 /* Make uid_hash_find() + user_kobject_create() + uid_hash_insert() 324 /* Make uid_hash_find() + uids_user_create() + uid_hash_insert()
328 * atomic. 325 * atomic.
329 */ 326 */
330 uids_mutex_lock(); 327 uids_mutex_lock();
@@ -370,7 +367,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
370 return NULL; 367 return NULL;
371 } 368 }
372 369
373 if (user_kobject_create(new)) { 370 if (uids_user_create(new)) {
374 sched_destroy_user(new); 371 sched_destroy_user(new);
375 key_put(new->uid_keyring); 372 key_put(new->uid_keyring);
376 key_put(new->session_keyring); 373 key_put(new->session_keyring);
diff --git a/lib/kobject.c b/lib/kobject.c
index 3590f022a609..1d63ead1815e 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -18,58 +18,57 @@
18#include <linux/stat.h> 18#include <linux/stat.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20 20
21/** 21/*
22 * populate_dir - populate directory with attributes. 22 * populate_dir - populate directory with attributes.
23 * @kobj: object we're working on. 23 * @kobj: object we're working on.
24 *
25 * Most subsystems have a set of default attributes that
26 * are associated with an object that registers with them.
27 * This is a helper called during object registration that
28 * loops through the default attributes of the subsystem
29 * and creates attributes files for them in sysfs.
30 * 24 *
25 * Most subsystems have a set of default attributes that are associated
26 * with an object that registers with them. This is a helper called during
27 * object registration that loops through the default attributes of the
28 * subsystem and creates attributes files for them in sysfs.
31 */ 29 */
32 30static int populate_dir(struct kobject *kobj)
33static int populate_dir(struct kobject * kobj)
34{ 31{
35 struct kobj_type * t = get_ktype(kobj); 32 struct kobj_type *t = get_ktype(kobj);
36 struct attribute * attr; 33 struct attribute *attr;
37 int error = 0; 34 int error = 0;
38 int i; 35 int i;
39 36
40 if (t && t->default_attrs) { 37 if (t && t->default_attrs) {
41 for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) { 38 for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) {
42 if ((error = sysfs_create_file(kobj,attr))) 39 error = sysfs_create_file(kobj, attr);
40 if (error)
43 break; 41 break;
44 } 42 }
45 } 43 }
46 return error; 44 return error;
47} 45}
48 46
49static int create_dir(struct kobject * kobj) 47static int create_dir(struct kobject *kobj)
50{ 48{
51 int error = 0; 49 int error = 0;
52 if (kobject_name(kobj)) { 50 if (kobject_name(kobj)) {
53 error = sysfs_create_dir(kobj); 51 error = sysfs_create_dir(kobj);
54 if (!error) { 52 if (!error) {
55 if ((error = populate_dir(kobj))) 53 error = populate_dir(kobj);
54 if (error)
56 sysfs_remove_dir(kobj); 55 sysfs_remove_dir(kobj);
57 } 56 }
58 } 57 }
59 return error; 58 return error;
60} 59}
61 60
62static inline struct kobject * to_kobj(struct list_head * entry) 61static inline struct kobject *to_kobj(struct list_head *entry)
63{ 62{
64 return container_of(entry,struct kobject,entry); 63 return container_of(entry, struct kobject, entry);
65} 64}
66 65
67static int get_kobj_path_length(struct kobject *kobj) 66static int get_kobj_path_length(struct kobject *kobj)
68{ 67{
69 int length = 1; 68 int length = 1;
70 struct kobject * parent = kobj; 69 struct kobject *parent = kobj;
71 70
72 /* walk up the ancestors until we hit the one pointing to the 71 /* walk up the ancestors until we hit the one pointing to the
73 * root. 72 * root.
74 * Add 1 to strlen for leading '/' of each level. 73 * Add 1 to strlen for leading '/' of each level.
75 */ 74 */
@@ -84,18 +83,19 @@ static int get_kobj_path_length(struct kobject *kobj)
84 83
85static void fill_kobj_path(struct kobject *kobj, char *path, int length) 84static void fill_kobj_path(struct kobject *kobj, char *path, int length)
86{ 85{
87 struct kobject * parent; 86 struct kobject *parent;
88 87
89 --length; 88 --length;
90 for (parent = kobj; parent; parent = parent->parent) { 89 for (parent = kobj; parent; parent = parent->parent) {
91 int cur = strlen(kobject_name(parent)); 90 int cur = strlen(kobject_name(parent));
92 /* back up enough to print this name with '/' */ 91 /* back up enough to print this name with '/' */
93 length -= cur; 92 length -= cur;
94 strncpy (path + length, kobject_name(parent), cur); 93 strncpy(path + length, kobject_name(parent), cur);
95 *(path + --length) = '/'; 94 *(path + --length) = '/';
96 } 95 }
97 96
98 pr_debug("%s: path = '%s'\n",__FUNCTION__,path); 97 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
98 kobj, __FUNCTION__, path);
99} 99}
100 100
101/** 101/**
@@ -123,179 +123,286 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
123} 123}
124EXPORT_SYMBOL_GPL(kobject_get_path); 124EXPORT_SYMBOL_GPL(kobject_get_path);
125 125
126/** 126/* add the kobject to its kset's list */
127 * kobject_init - initialize object. 127static void kobj_kset_join(struct kobject *kobj)
128 * @kobj: object in question.
129 */
130void kobject_init(struct kobject * kobj)
131{ 128{
132 if (!kobj) 129 if (!kobj->kset)
133 return; 130 return;
134 kref_init(&kobj->kref); 131
135 INIT_LIST_HEAD(&kobj->entry); 132 kset_get(kobj->kset);
136 kobj->kset = kset_get(kobj->kset); 133 spin_lock(&kobj->kset->list_lock);
134 list_add_tail(&kobj->entry, &kobj->kset->list);
135 spin_unlock(&kobj->kset->list_lock);
137} 136}
138 137
138/* remove the kobject from its kset's list */
139static void kobj_kset_leave(struct kobject *kobj)
140{
141 if (!kobj->kset)
142 return;
139 143
140/** 144 spin_lock(&kobj->kset->list_lock);
141 * unlink - remove kobject from kset list. 145 list_del_init(&kobj->entry);
142 * @kobj: kobject. 146 spin_unlock(&kobj->kset->list_lock);
143 * 147 kset_put(kobj->kset);
144 * Remove the kobject from the kset list and decrement 148}
145 * its parent's refcount.
146 * This is separated out, so we can use it in both
147 * kobject_del() and kobject_add() on error.
148 */
149 149
150static void unlink(struct kobject * kobj) 150static void kobject_init_internal(struct kobject *kobj)
151{ 151{
152 if (kobj->kset) { 152 if (!kobj)
153 spin_lock(&kobj->kset->list_lock); 153 return;
154 list_del_init(&kobj->entry); 154 kref_init(&kobj->kref);
155 spin_unlock(&kobj->kset->list_lock); 155 INIT_LIST_HEAD(&kobj->entry);
156 }
157 kobject_put(kobj);
158} 156}
159 157
160/**
161 * kobject_add - add an object to the hierarchy.
162 * @kobj: object.
163 */
164 158
165int kobject_add(struct kobject * kobj) 159static int kobject_add_internal(struct kobject *kobj)
166{ 160{
167 int error = 0; 161 int error = 0;
168 struct kobject * parent; 162 struct kobject *parent;
169 163
170 if (!(kobj = kobject_get(kobj))) 164 if (!kobj)
171 return -ENOENT; 165 return -ENOENT;
172 if (!kobj->k_name) 166
173 kobject_set_name(kobj, "NO_NAME"); 167 if (!kobj->name || !kobj->name[0]) {
174 if (!*kobj->k_name) { 168 pr_debug("kobject: (%p): attempted to be registered with empty "
175 pr_debug("kobject attempted to be registered with no name!\n"); 169 "name!\n", kobj);
176 WARN_ON(1); 170 WARN_ON(1);
177 kobject_put(kobj);
178 return -EINVAL; 171 return -EINVAL;
179 } 172 }
180 parent = kobject_get(kobj->parent);
181 173
182 pr_debug("kobject %s: registering. parent: %s, set: %s\n", 174 parent = kobject_get(kobj->parent);
183 kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>",
184 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
185 175
176 /* join kset if set, use it as parent if we do not already have one */
186 if (kobj->kset) { 177 if (kobj->kset) {
187 spin_lock(&kobj->kset->list_lock);
188
189 if (!parent) 178 if (!parent)
190 parent = kobject_get(&kobj->kset->kobj); 179 parent = kobject_get(&kobj->kset->kobj);
191 180 kobj_kset_join(kobj);
192 list_add_tail(&kobj->entry,&kobj->kset->list);
193 spin_unlock(&kobj->kset->list_lock);
194 kobj->parent = parent; 181 kobj->parent = parent;
195 } 182 }
196 183
184 pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
185 kobject_name(kobj), kobj, __FUNCTION__,
186 parent ? kobject_name(parent) : "<NULL>",
187 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
188
197 error = create_dir(kobj); 189 error = create_dir(kobj);
198 if (error) { 190 if (error) {
199 /* unlink does the kobject_put() for us */ 191 kobj_kset_leave(kobj);
200 unlink(kobj);
201 kobject_put(parent); 192 kobject_put(parent);
193 kobj->parent = NULL;
202 194
203 /* be noisy on error issues */ 195 /* be noisy on error issues */
204 if (error == -EEXIST) 196 if (error == -EEXIST)
205 printk(KERN_ERR "kobject_add failed for %s with " 197 printk(KERN_ERR "%s failed for %s with "
206 "-EEXIST, don't try to register things with " 198 "-EEXIST, don't try to register things with "
207 "the same name in the same directory.\n", 199 "the same name in the same directory.\n",
208 kobject_name(kobj)); 200 __FUNCTION__, kobject_name(kobj));
209 else 201 else
210 printk(KERN_ERR "kobject_add failed for %s (%d)\n", 202 printk(KERN_ERR "%s failed for %s (%d)\n",
211 kobject_name(kobj), error); 203 __FUNCTION__, kobject_name(kobj), error);
212 dump_stack(); 204 dump_stack();
213 } 205 } else
206 kobj->state_in_sysfs = 1;
214 207
215 return error; 208 return error;
216} 209}
217 210
218/** 211/**
219 * kobject_register - initialize and add an object. 212 * kobject_set_name_vargs - Set the name of an kobject
220 * @kobj: object in question. 213 * @kobj: struct kobject to set the name of
214 * @fmt: format string used to build the name
215 * @vargs: vargs to format the string.
221 */ 216 */
222 217static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
223int kobject_register(struct kobject * kobj) 218 va_list vargs)
224{ 219{
225 int error = -EINVAL; 220 va_list aq;
226 if (kobj) { 221 char *name;
227 kobject_init(kobj); 222
228 error = kobject_add(kobj); 223 va_copy(aq, vargs);
229 if (!error) 224 name = kvasprintf(GFP_KERNEL, fmt, vargs);
230 kobject_uevent(kobj, KOBJ_ADD); 225 va_end(aq);
231 }
232 return error;
233}
234 226
227 if (!name)
228 return -ENOMEM;
229
230 /* Free the old name, if necessary. */
231 kfree(kobj->name);
232
233 /* Now, set the new name */
234 kobj->name = name;
235
236 return 0;
237}
235 238
236/** 239/**
237 * kobject_set_name - Set the name of a kobject 240 * kobject_set_name - Set the name of a kobject
238 * @kobj: kobject to name 241 * @kobj: struct kobject to set the name of
239 * @fmt: format string used to build the name 242 * @fmt: format string used to build the name
240 * 243 *
241 * This sets the name of the kobject. If you have already added the 244 * This sets the name of the kobject. If you have already added the
242 * kobject to the system, you must call kobject_rename() in order to 245 * kobject to the system, you must call kobject_rename() in order to
243 * change the name of the kobject. 246 * change the name of the kobject.
244 */ 247 */
245int kobject_set_name(struct kobject * kobj, const char * fmt, ...) 248int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
246{ 249{
247 int error = 0;
248 int limit;
249 int need;
250 va_list args; 250 va_list args;
251 char *name; 251 int retval;
252 252
253 /* find out how big a buffer we need */
254 name = kmalloc(1024, GFP_KERNEL);
255 if (!name) {
256 error = -ENOMEM;
257 goto done;
258 }
259 va_start(args, fmt); 253 va_start(args, fmt);
260 need = vsnprintf(name, 1024, fmt, args); 254 retval = kobject_set_name_vargs(kobj, fmt, args);
261 va_end(args); 255 va_end(args);
262 kfree(name);
263 256
264 /* Allocate the new space and copy the string in */ 257 return retval;
265 limit = need + 1; 258}
266 name = kmalloc(limit, GFP_KERNEL); 259EXPORT_SYMBOL(kobject_set_name);
267 if (!name) { 260
268 error = -ENOMEM; 261/**
269 goto done; 262 * kobject_init - initialize a kobject structure
263 * @kobj: pointer to the kobject to initialize
264 * @ktype: pointer to the ktype for this kobject.
265 *
266 * This function will properly initialize a kobject such that it can then
267 * be passed to the kobject_add() call.
268 *
269 * After this function is called, the kobject MUST be cleaned up by a call
270 * to kobject_put(), not by a call to kfree directly to ensure that all of
271 * the memory is cleaned up properly.
272 */
273void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
274{
275 char *err_str;
276
277 if (!kobj) {
278 err_str = "invalid kobject pointer!";
279 goto error;
280 }
281 if (!ktype) {
282 err_str = "must have a ktype to be initialized properly!\n";
283 goto error;
284 }
285 if (kobj->state_initialized) {
286 /* do not error out as sometimes we can recover */
287 printk(KERN_ERR "kobject (%p): tried to init an initialized "
288 "object, something is seriously wrong.\n", kobj);
289 dump_stack();
270 } 290 }
271 va_start(args, fmt);
272 need = vsnprintf(name, limit, fmt, args);
273 va_end(args);
274 291
275 /* something wrong with the string we copied? */ 292 kref_init(&kobj->kref);
276 if (need >= limit) { 293 INIT_LIST_HEAD(&kobj->entry);
277 kfree(name); 294 kobj->ktype = ktype;
278 error = -EFAULT; 295 kobj->state_in_sysfs = 0;
279 goto done; 296 kobj->state_add_uevent_sent = 0;
297 kobj->state_remove_uevent_sent = 0;
298 kobj->state_initialized = 1;
299 return;
300
301error:
302 printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
303 dump_stack();
304}
305EXPORT_SYMBOL(kobject_init);
306
307static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
308 const char *fmt, va_list vargs)
309{
310 va_list aq;
311 int retval;
312
313 va_copy(aq, vargs);
314 retval = kobject_set_name_vargs(kobj, fmt, aq);
315 va_end(aq);
316 if (retval) {
317 printk(KERN_ERR "kobject: can not set name properly!\n");
318 return retval;
280 } 319 }
320 kobj->parent = parent;
321 return kobject_add_internal(kobj);
322}
281 323
282 /* Free the old name, if necessary. */ 324/**
283 kfree(kobj->k_name); 325 * kobject_add - the main kobject add function
326 * @kobj: the kobject to add
327 * @parent: pointer to the parent of the kobject.
328 * @fmt: format to name the kobject with.
329 *
330 * The kobject name is set and added to the kobject hierarchy in this
331 * function.
332 *
333 * If @parent is set, then the parent of the @kobj will be set to it.
334 * If @parent is NULL, then the parent of the @kobj will be set to the
335 * kobject associted with the kset assigned to this kobject. If no kset
336 * is assigned to the kobject, then the kobject will be located in the
337 * root of the sysfs tree.
338 *
339 * If this function returns an error, kobject_put() must be called to
340 * properly clean up the memory associated with the object.
341 * Under no instance should the kobject that is passed to this function
342 * be directly freed with a call to kfree(), that can leak memory.
343 *
344 * Note, no "add" uevent will be created with this call, the caller should set
345 * up all of the necessary sysfs files for the object and then call
346 * kobject_uevent() with the UEVENT_ADD parameter to ensure that
347 * userspace is properly notified of this kobject's creation.
348 */
349int kobject_add(struct kobject *kobj, struct kobject *parent,
350 const char *fmt, ...)
351{
352 va_list args;
353 int retval;
284 354
285 /* Now, set the new name */ 355 if (!kobj)
286 kobj->k_name = name; 356 return -EINVAL;
287done: 357
288 return error; 358 if (!kobj->state_initialized) {
359 printk(KERN_ERR "kobject '%s' (%p): tried to add an "
360 "uninitialized object, something is seriously wrong.\n",
361 kobject_name(kobj), kobj);
362 dump_stack();
363 return -EINVAL;
364 }
365 va_start(args, fmt);
366 retval = kobject_add_varg(kobj, parent, fmt, args);
367 va_end(args);
368
369 return retval;
289} 370}
290EXPORT_SYMBOL(kobject_set_name); 371EXPORT_SYMBOL(kobject_add);
291 372
292/** 373/**
293 * kobject_rename - change the name of an object 374 * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
294 * @kobj: object in question. 375 * @kobj: pointer to the kobject to initialize
295 * @new_name: object's new name 376 * @ktype: pointer to the ktype for this kobject.
377 * @parent: pointer to the parent of this kobject.
378 * @fmt: the name of the kobject.
379 *
380 * This function combines the call to kobject_init() and
381 * kobject_add(). The same type of error handling after a call to
382 * kobject_add() and kobject lifetime rules are the same here.
296 */ 383 */
384int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
385 struct kobject *parent, const char *fmt, ...)
386{
387 va_list args;
388 int retval;
389
390 kobject_init(kobj, ktype);
391
392 va_start(args, fmt);
393 retval = kobject_add_varg(kobj, parent, fmt, args);
394 va_end(args);
395
396 return retval;
397}
398EXPORT_SYMBOL_GPL(kobject_init_and_add);
297 399
298int kobject_rename(struct kobject * kobj, const char *new_name) 400/**
401 * kobject_rename - change the name of an object
402 * @kobj: object in question.
403 * @new_name: object's new name
404 */
405int kobject_rename(struct kobject *kobj, const char *new_name)
299{ 406{
300 int error = 0; 407 int error = 0;
301 const char *devpath = NULL; 408 const char *devpath = NULL;
@@ -334,8 +441,6 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
334 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath); 441 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
335 envp[0] = devpath_string; 442 envp[0] = devpath_string;
336 envp[1] = NULL; 443 envp[1] = NULL;
337 /* Note : if we want to send the new name alone, not the full path,
338 * we could probably use kobject_name(kobj); */
339 444
340 error = sysfs_rename_dir(kobj, new_name); 445 error = sysfs_rename_dir(kobj, new_name);
341 446
@@ -354,11 +459,10 @@ out:
354} 459}
355 460
356/** 461/**
357 * kobject_move - move object to another parent 462 * kobject_move - move object to another parent
358 * @kobj: object in question. 463 * @kobj: object in question.
359 * @new_parent: object's new parent (can be NULL) 464 * @new_parent: object's new parent (can be NULL)
360 */ 465 */
361
362int kobject_move(struct kobject *kobj, struct kobject *new_parent) 466int kobject_move(struct kobject *kobj, struct kobject *new_parent)
363{ 467{
364 int error; 468 int error;
@@ -406,68 +510,74 @@ out:
406} 510}
407 511
408/** 512/**
409 * kobject_del - unlink kobject from hierarchy. 513 * kobject_del - unlink kobject from hierarchy.
410 * @kobj: object. 514 * @kobj: object.
411 */ 515 */
412 516void kobject_del(struct kobject *kobj)
413void kobject_del(struct kobject * kobj)
414{ 517{
415 if (!kobj) 518 if (!kobj)
416 return; 519 return;
417 sysfs_remove_dir(kobj);
418 unlink(kobj);
419}
420 520
421/** 521 sysfs_remove_dir(kobj);
422 * kobject_unregister - remove object from hierarchy and decrement refcount. 522 kobj->state_in_sysfs = 0;
423 * @kobj: object going away. 523 kobj_kset_leave(kobj);
424 */ 524 kobject_put(kobj->parent);
425 525 kobj->parent = NULL;
426void kobject_unregister(struct kobject * kobj)
427{
428 if (!kobj)
429 return;
430 pr_debug("kobject %s: unregistering\n",kobject_name(kobj));
431 kobject_uevent(kobj, KOBJ_REMOVE);
432 kobject_del(kobj);
433 kobject_put(kobj);
434} 526}
435 527
436/** 528/**
437 * kobject_get - increment refcount for object. 529 * kobject_get - increment refcount for object.
438 * @kobj: object. 530 * @kobj: object.
439 */ 531 */
440 532struct kobject *kobject_get(struct kobject *kobj)
441struct kobject * kobject_get(struct kobject * kobj)
442{ 533{
443 if (kobj) 534 if (kobj)
444 kref_get(&kobj->kref); 535 kref_get(&kobj->kref);
445 return kobj; 536 return kobj;
446} 537}
447 538
448/** 539/*
449 * kobject_cleanup - free kobject resources. 540 * kobject_cleanup - free kobject resources.
450 * @kobj: object. 541 * @kobj: object to cleanup
451 */ 542 */
452 543static void kobject_cleanup(struct kobject *kobj)
453void kobject_cleanup(struct kobject * kobj)
454{ 544{
455 struct kobj_type * t = get_ktype(kobj); 545 struct kobj_type *t = get_ktype(kobj);
456 struct kset * s = kobj->kset; 546 const char *name = kobj->name;
457 struct kobject * parent = kobj->parent; 547
458 const char *name = kobj->k_name; 548 pr_debug("kobject: '%s' (%p): %s\n",
549 kobject_name(kobj), kobj, __FUNCTION__);
550
551 if (t && !t->release)
552 pr_debug("kobject: '%s' (%p): does not have a release() "
553 "function, it is broken and must be fixed.\n",
554 kobject_name(kobj), kobj);
555
556 /* send "remove" if the caller did not do it but sent "add" */
557 if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) {
558 pr_debug("kobject: '%s' (%p): auto cleanup 'remove' event\n",
559 kobject_name(kobj), kobj);
560 kobject_uevent(kobj, KOBJ_REMOVE);
561 }
562
563 /* remove from sysfs if the caller did not do it */
564 if (kobj->state_in_sysfs) {
565 pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
566 kobject_name(kobj), kobj);
567 kobject_del(kobj);
568 }
459 569
460 pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
461 if (t && t->release) { 570 if (t && t->release) {
571 pr_debug("kobject: '%s' (%p): calling ktype release\n",
572 kobject_name(kobj), kobj);
462 t->release(kobj); 573 t->release(kobj);
463 /* If we have a release function, we can guess that this was 574 }
464 * not a statically allocated kobject, so we should be safe to 575
465 * free the name */ 576 /* free name if we allocated it */
577 if (name) {
578 pr_debug("kobject: '%s': free name\n", name);
466 kfree(name); 579 kfree(name);
467 } 580 }
468 if (s)
469 kset_put(s);
470 kobject_put(parent);
471} 581}
472 582
473static void kobject_release(struct kref *kref) 583static void kobject_release(struct kref *kref)
@@ -476,107 +586,130 @@ static void kobject_release(struct kref *kref)
476} 586}
477 587
478/** 588/**
479 * kobject_put - decrement refcount for object. 589 * kobject_put - decrement refcount for object.
480 * @kobj: object. 590 * @kobj: object.
481 * 591 *
482 * Decrement the refcount, and if 0, call kobject_cleanup(). 592 * Decrement the refcount, and if 0, call kobject_cleanup().
483 */ 593 */
484void kobject_put(struct kobject * kobj) 594void kobject_put(struct kobject *kobj)
485{ 595{
486 if (kobj) 596 if (kobj)
487 kref_put(&kobj->kref, kobject_release); 597 kref_put(&kobj->kref, kobject_release);
488} 598}
489 599
490 600static void dynamic_kobj_release(struct kobject *kobj)
491static void dir_release(struct kobject *kobj)
492{ 601{
602 pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
493 kfree(kobj); 603 kfree(kobj);
494} 604}
495 605
496static struct kobj_type dir_ktype = { 606static struct kobj_type dynamic_kobj_ktype = {
497 .release = dir_release, 607 .release = dynamic_kobj_release,
498 .sysfs_ops = NULL, 608 .sysfs_ops = &kobj_sysfs_ops,
499 .default_attrs = NULL,
500}; 609};
501 610
502/** 611/**
503 * kobject_kset_add_dir - add sub directory of object. 612 * kobject_create - create a struct kobject dynamically
504 * @kset: kset the directory is belongs to.
505 * @parent: object in which a directory is created.
506 * @name: directory name.
507 * 613 *
508 * Add a plain directory object as child of given object. 614 * This function creates a kobject structure dynamically and sets it up
615 * to be a "dynamic" kobject with a default release function set up.
616 *
617 * If the kobject was not able to be created, NULL will be returned.
618 * The kobject structure returned from here must be cleaned up with a
619 * call to kobject_put() and not kfree(), as kobject_init() has
620 * already been called on this structure.
509 */ 621 */
510struct kobject *kobject_kset_add_dir(struct kset *kset, 622struct kobject *kobject_create(void)
511 struct kobject *parent, const char *name)
512{ 623{
513 struct kobject *k; 624 struct kobject *kobj;
514 int ret;
515
516 if (!parent)
517 return NULL;
518
519 k = kzalloc(sizeof(*k), GFP_KERNEL);
520 if (!k)
521 return NULL;
522 625
523 k->kset = kset; 626 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
524 k->parent = parent; 627 if (!kobj)
525 k->ktype = &dir_ktype;
526 kobject_set_name(k, name);
527 ret = kobject_register(k);
528 if (ret < 0) {
529 printk(KERN_WARNING "%s: kobject_register error: %d\n",
530 __func__, ret);
531 kobject_del(k);
532 return NULL; 628 return NULL;
533 }
534 629
535 return k; 630 kobject_init(kobj, &dynamic_kobj_ktype);
631 return kobj;
536} 632}
537 633
538/** 634/**
539 * kobject_add_dir - add sub directory of object. 635 * kobject_create_and_add - create a struct kobject dynamically and register it with sysfs
540 * @parent: object in which a directory is created. 636 *
541 * @name: directory name. 637 * @name: the name for the kset
638 * @parent: the parent kobject of this kobject, if any.
639 *
640 * This function creates a kset structure dynamically and registers it
641 * with sysfs. When you are finished with this structure, call
642 * kobject_put() and the structure will be dynamically freed when
643 * it is no longer being used.
542 * 644 *
543 * Add a plain directory object as child of given object. 645 * If the kobject was not able to be created, NULL will be returned.
544 */ 646 */
545struct kobject *kobject_add_dir(struct kobject *parent, const char *name) 647struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
546{ 648{
547 return kobject_kset_add_dir(NULL, parent, name); 649 struct kobject *kobj;
650 int retval;
651
652 kobj = kobject_create();
653 if (!kobj)
654 return NULL;
655
656 retval = kobject_add(kobj, parent, "%s", name);
657 if (retval) {
658 printk(KERN_WARNING "%s: kobject_add error: %d\n",
659 __FUNCTION__, retval);
660 kobject_put(kobj);
661 kobj = NULL;
662 }
663 return kobj;
548} 664}
665EXPORT_SYMBOL_GPL(kobject_create_and_add);
549 666
550/** 667/**
551 * kset_init - initialize a kset for use 668 * kset_init - initialize a kset for use
552 * @k: kset 669 * @k: kset
553 */ 670 */
554 671void kset_init(struct kset *k)
555void kset_init(struct kset * k)
556{ 672{
557 kobject_init(&k->kobj); 673 kobject_init_internal(&k->kobj);
558 INIT_LIST_HEAD(&k->list); 674 INIT_LIST_HEAD(&k->list);
559 spin_lock_init(&k->list_lock); 675 spin_lock_init(&k->list_lock);
560} 676}
561 677
678/* default kobject attribute operations */
679static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
680 char *buf)
681{
682 struct kobj_attribute *kattr;
683 ssize_t ret = -EIO;
562 684
563/** 685 kattr = container_of(attr, struct kobj_attribute, attr);
564 * kset_add - add a kset object to the hierarchy. 686 if (kattr->show)
565 * @k: kset. 687 ret = kattr->show(kobj, kattr, buf);
566 */ 688 return ret;
689}
567 690
568int kset_add(struct kset * k) 691static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
692 const char *buf, size_t count)
569{ 693{
570 return kobject_add(&k->kobj); 694 struct kobj_attribute *kattr;
695 ssize_t ret = -EIO;
696
697 kattr = container_of(attr, struct kobj_attribute, attr);
698 if (kattr->store)
699 ret = kattr->store(kobj, kattr, buf, count);
700 return ret;
571} 701}
572 702
703struct sysfs_ops kobj_sysfs_ops = {
704 .show = kobj_attr_show,
705 .store = kobj_attr_store,
706};
573 707
574/** 708/**
575 * kset_register - initialize and add a kset. 709 * kset_register - initialize and add a kset.
576 * @k: kset. 710 * @k: kset.
577 */ 711 */
578 712int kset_register(struct kset *k)
579int kset_register(struct kset * k)
580{ 713{
581 int err; 714 int err;
582 715
@@ -584,46 +717,42 @@ int kset_register(struct kset * k)
584 return -EINVAL; 717 return -EINVAL;
585 718
586 kset_init(k); 719 kset_init(k);
587 err = kset_add(k); 720 err = kobject_add_internal(&k->kobj);
588 if (err) 721 if (err)
589 return err; 722 return err;
590 kobject_uevent(&k->kobj, KOBJ_ADD); 723 kobject_uevent(&k->kobj, KOBJ_ADD);
591 return 0; 724 return 0;
592} 725}
593 726
594
595/** 727/**
596 * kset_unregister - remove a kset. 728 * kset_unregister - remove a kset.
597 * @k: kset. 729 * @k: kset.
598 */ 730 */
599 731void kset_unregister(struct kset *k)
600void kset_unregister(struct kset * k)
601{ 732{
602 if (!k) 733 if (!k)
603 return; 734 return;
604 kobject_unregister(&k->kobj); 735 kobject_put(&k->kobj);
605} 736}
606 737
607
608/** 738/**
609 * kset_find_obj - search for object in kset. 739 * kset_find_obj - search for object in kset.
610 * @kset: kset we're looking in. 740 * @kset: kset we're looking in.
611 * @name: object's name. 741 * @name: object's name.
612 * 742 *
613 * Lock kset via @kset->subsys, and iterate over @kset->list, 743 * Lock kset via @kset->subsys, and iterate over @kset->list,
614 * looking for a matching kobject. If matching object is found 744 * looking for a matching kobject. If matching object is found
615 * take a reference and return the object. 745 * take a reference and return the object.
616 */ 746 */
617 747struct kobject *kset_find_obj(struct kset *kset, const char *name)
618struct kobject * kset_find_obj(struct kset * kset, const char * name)
619{ 748{
620 struct list_head * entry; 749 struct list_head *entry;
621 struct kobject * ret = NULL; 750 struct kobject *ret = NULL;
622 751
623 spin_lock(&kset->list_lock); 752 spin_lock(&kset->list_lock);
624 list_for_each(entry,&kset->list) { 753 list_for_each(entry, &kset->list) {
625 struct kobject * k = to_kobj(entry); 754 struct kobject *k = to_kobj(entry);
626 if (kobject_name(k) && !strcmp(kobject_name(k),name)) { 755 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
627 ret = kobject_get(k); 756 ret = kobject_get(k);
628 break; 757 break;
629 } 758 }
@@ -632,47 +761,94 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
632 return ret; 761 return ret;
633} 762}
634 763
635int subsystem_register(struct kset *s) 764static void kset_release(struct kobject *kobj)
636{ 765{
637 return kset_register(s); 766 struct kset *kset = container_of(kobj, struct kset, kobj);
767 pr_debug("kobject: '%s' (%p): %s\n",
768 kobject_name(kobj), kobj, __FUNCTION__);
769 kfree(kset);
638} 770}
639 771
640void subsystem_unregister(struct kset *s) 772static struct kobj_type kset_ktype = {
773 .sysfs_ops = &kobj_sysfs_ops,
774 .release = kset_release,
775};
776
777/**
778 * kset_create - create a struct kset dynamically
779 *
780 * @name: the name for the kset
781 * @uevent_ops: a struct kset_uevent_ops for the kset
782 * @parent_kobj: the parent kobject of this kset, if any.
783 *
784 * This function creates a kset structure dynamically. This structure can
785 * then be registered with the system and show up in sysfs with a call to
786 * kset_register(). When you are finished with this structure, if
787 * kset_register() has been called, call kset_unregister() and the
788 * structure will be dynamically freed when it is no longer being used.
789 *
790 * If the kset was not able to be created, NULL will be returned.
791 */
792static struct kset *kset_create(const char *name,
793 struct kset_uevent_ops *uevent_ops,
794 struct kobject *parent_kobj)
641{ 795{
642 kset_unregister(s); 796 struct kset *kset;
797
798 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
799 if (!kset)
800 return NULL;
801 kobject_set_name(&kset->kobj, name);
802 kset->uevent_ops = uevent_ops;
803 kset->kobj.parent = parent_kobj;
804
805 /*
806 * The kobject of this kset will have a type of kset_ktype and belong to
807 * no kset itself. That way we can properly free it when it is
808 * finished being used.
809 */
810 kset->kobj.ktype = &kset_ktype;
811 kset->kobj.kset = NULL;
812
813 return kset;
643} 814}
644 815
645/** 816/**
646 * subsystem_create_file - export sysfs attribute file. 817 * kset_create_and_add - create a struct kset dynamically and add it to sysfs
647 * @s: subsystem. 818 *
648 * @a: subsystem attribute descriptor. 819 * @name: the name for the kset
820 * @uevent_ops: a struct kset_uevent_ops for the kset
821 * @parent_kobj: the parent kobject of this kset, if any.
822 *
823 * This function creates a kset structure dynamically and registers it
824 * with sysfs. When you are finished with this structure, call
825 * kset_unregister() and the structure will be dynamically freed when it
826 * is no longer being used.
827 *
828 * If the kset was not able to be created, NULL will be returned.
649 */ 829 */
650 830struct kset *kset_create_and_add(const char *name,
651int subsys_create_file(struct kset *s, struct subsys_attribute *a) 831 struct kset_uevent_ops *uevent_ops,
832 struct kobject *parent_kobj)
652{ 833{
653 int error = 0; 834 struct kset *kset;
654 835 int error;
655 if (!s || !a)
656 return -EINVAL;
657 836
658 if (kset_get(s)) { 837 kset = kset_create(name, uevent_ops, parent_kobj);
659 error = sysfs_create_file(&s->kobj, &a->attr); 838 if (!kset)
660 kset_put(s); 839 return NULL;
840 error = kset_register(kset);
841 if (error) {
842 kfree(kset);
843 return NULL;
661 } 844 }
662 return error; 845 return kset;
663} 846}
847EXPORT_SYMBOL_GPL(kset_create_and_add);
664 848
665EXPORT_SYMBOL(kobject_init);
666EXPORT_SYMBOL(kobject_register);
667EXPORT_SYMBOL(kobject_unregister);
668EXPORT_SYMBOL(kobject_get); 849EXPORT_SYMBOL(kobject_get);
669EXPORT_SYMBOL(kobject_put); 850EXPORT_SYMBOL(kobject_put);
670EXPORT_SYMBOL(kobject_add);
671EXPORT_SYMBOL(kobject_del); 851EXPORT_SYMBOL(kobject_del);
672 852
673EXPORT_SYMBOL(kset_register); 853EXPORT_SYMBOL(kset_register);
674EXPORT_SYMBOL(kset_unregister); 854EXPORT_SYMBOL(kset_unregister);
675
676EXPORT_SYMBOL(subsystem_register);
677EXPORT_SYMBOL(subsystem_unregister);
678EXPORT_SYMBOL(subsys_create_file);
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 5886147252d0..5a402e2982af 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -98,7 +98,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
98 int i = 0; 98 int i = 0;
99 int retval = 0; 99 int retval = 0;
100 100
101 pr_debug("%s\n", __FUNCTION__); 101 pr_debug("kobject: '%s' (%p): %s\n",
102 kobject_name(kobj), kobj, __FUNCTION__);
102 103
103 /* search the kset we belong to */ 104 /* search the kset we belong to */
104 top_kobj = kobj; 105 top_kobj = kobj;
@@ -106,7 +107,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
106 top_kobj = top_kobj->parent; 107 top_kobj = top_kobj->parent;
107 108
108 if (!top_kobj->kset) { 109 if (!top_kobj->kset) {
109 pr_debug("kobject attempted to send uevent without kset!\n"); 110 pr_debug("kobject: '%s' (%p): %s: attempted to send uevent "
111 "without kset!\n", kobject_name(kobj), kobj,
112 __FUNCTION__);
110 return -EINVAL; 113 return -EINVAL;
111 } 114 }
112 115
@@ -116,7 +119,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
116 /* skip the event, if the filter returns zero. */ 119 /* skip the event, if the filter returns zero. */
117 if (uevent_ops && uevent_ops->filter) 120 if (uevent_ops && uevent_ops->filter)
118 if (!uevent_ops->filter(kset, kobj)) { 121 if (!uevent_ops->filter(kset, kobj)) {
119 pr_debug("kobject filter function caused the event to drop!\n"); 122 pr_debug("kobject: '%s' (%p): %s: filter function "
123 "caused the event to drop!\n",
124 kobject_name(kobj), kobj, __FUNCTION__);
120 return 0; 125 return 0;
121 } 126 }
122 127
@@ -126,7 +131,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
126 else 131 else
127 subsystem = kobject_name(&kset->kobj); 132 subsystem = kobject_name(&kset->kobj);
128 if (!subsystem) { 133 if (!subsystem) {
129 pr_debug("unset subsystem caused the event to drop!\n"); 134 pr_debug("kobject: '%s' (%p): %s: unset subsystem caused the "
135 "event to drop!\n", kobject_name(kobj), kobj,
136 __FUNCTION__);
130 return 0; 137 return 0;
131 } 138 }
132 139
@@ -166,12 +173,24 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
166 if (uevent_ops && uevent_ops->uevent) { 173 if (uevent_ops && uevent_ops->uevent) {
167 retval = uevent_ops->uevent(kset, kobj, env); 174 retval = uevent_ops->uevent(kset, kobj, env);
168 if (retval) { 175 if (retval) {
169 pr_debug ("%s - uevent() returned %d\n", 176 pr_debug("kobject: '%s' (%p): %s: uevent() returned "
170 __FUNCTION__, retval); 177 "%d\n", kobject_name(kobj), kobj,
178 __FUNCTION__, retval);
171 goto exit; 179 goto exit;
172 } 180 }
173 } 181 }
174 182
183 /*
184 * Mark "add" and "remove" events in the object to ensure proper
185 * events to userspace during automatic cleanup. If the object did
186 * send an "add" event, "remove" will automatically generated by
187 * the core, if not already done by the caller.
188 */
189 if (action == KOBJ_ADD)
190 kobj->state_add_uevent_sent = 1;
191 else if (action == KOBJ_REMOVE)
192 kobj->state_remove_uevent_sent = 1;
193
175 /* we will send an event, so request a new sequence number */ 194 /* we will send an event, so request a new sequence number */
176 spin_lock(&sequence_lock); 195 spin_lock(&sequence_lock);
177 seq = ++uevent_seqnum; 196 seq = ++uevent_seqnum;
@@ -219,11 +238,12 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
219 retval = add_uevent_var(env, "HOME=/"); 238 retval = add_uevent_var(env, "HOME=/");
220 if (retval) 239 if (retval)
221 goto exit; 240 goto exit;
222 retval = add_uevent_var(env, "PATH=/sbin:/bin:/usr/sbin:/usr/bin"); 241 retval = add_uevent_var(env,
242 "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
223 if (retval) 243 if (retval)
224 goto exit; 244 goto exit;
225 245
226 call_usermodehelper (argv[0], argv, env->envp, UMH_WAIT_EXEC); 246 call_usermodehelper(argv[0], argv, env->envp, UMH_WAIT_EXEC);
227 } 247 }
228 248
229exit: 249exit:
@@ -231,7 +251,6 @@ exit:
231 kfree(env); 251 kfree(env);
232 return retval; 252 return retval;
233} 253}
234
235EXPORT_SYMBOL_GPL(kobject_uevent_env); 254EXPORT_SYMBOL_GPL(kobject_uevent_env);
236 255
237/** 256/**
@@ -247,7 +266,6 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action)
247{ 266{
248 return kobject_uevent_env(kobj, action, NULL); 267 return kobject_uevent_env(kobj, action, NULL);
249} 268}
250
251EXPORT_SYMBOL_GPL(kobject_uevent); 269EXPORT_SYMBOL_GPL(kobject_uevent);
252 270
253/** 271/**
diff --git a/lib/kref.c b/lib/kref.c
index a6dc3ec328e0..9ecd6e865610 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -15,13 +15,23 @@
15#include <linux/module.h> 15#include <linux/module.h>
16 16
17/** 17/**
18 * kref_set - initialize object and set refcount to requested number.
19 * @kref: object in question.
20 * @num: initial reference counter
21 */
22void kref_set(struct kref *kref, int num)
23{
24 atomic_set(&kref->refcount, num);
25 smp_mb();
26}
27
28/**
18 * kref_init - initialize object. 29 * kref_init - initialize object.
19 * @kref: object in question. 30 * @kref: object in question.
20 */ 31 */
21void kref_init(struct kref *kref) 32void kref_init(struct kref *kref)
22{ 33{
23 atomic_set(&kref->refcount,1); 34 kref_set(kref, 1);
24 smp_mb();
25} 35}
26 36
27/** 37/**
@@ -61,6 +71,7 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
61 return 0; 71 return 0;
62} 72}
63 73
74EXPORT_SYMBOL(kref_set);
64EXPORT_SYMBOL(kref_init); 75EXPORT_SYMBOL(kref_init);
65EXPORT_SYMBOL(kref_get); 76EXPORT_SYMBOL(kref_get);
66EXPORT_SYMBOL(kref_put); 77EXPORT_SYMBOL(kref_put);
diff --git a/mm/slab.c b/mm/slab.c
index b03b2e46b806..ff31261fd24f 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -304,11 +304,11 @@ struct kmem_list3 {
304/* 304/*
305 * Need this for bootstrapping a per node allocator. 305 * Need this for bootstrapping a per node allocator.
306 */ 306 */
307#define NUM_INIT_LISTS (2 * MAX_NUMNODES + 1) 307#define NUM_INIT_LISTS (3 * MAX_NUMNODES)
308struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS]; 308struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
309#define CACHE_CACHE 0 309#define CACHE_CACHE 0
310#define SIZE_AC 1 310#define SIZE_AC MAX_NUMNODES
311#define SIZE_L3 (1 + MAX_NUMNODES) 311#define SIZE_L3 (2 * MAX_NUMNODES)
312 312
313static int drain_freelist(struct kmem_cache *cache, 313static int drain_freelist(struct kmem_cache *cache,
314 struct kmem_list3 *l3, int tofree); 314 struct kmem_list3 *l3, int tofree);
@@ -1410,6 +1410,22 @@ static void init_list(struct kmem_cache *cachep, struct kmem_list3 *list,
1410} 1410}
1411 1411
1412/* 1412/*
1413 * For setting up all the kmem_list3s for cache whose buffer_size is same as
1414 * size of kmem_list3.
1415 */
1416static void __init set_up_list3s(struct kmem_cache *cachep, int index)
1417{
1418 int node;
1419
1420 for_each_online_node(node) {
1421 cachep->nodelists[node] = &initkmem_list3[index + node];
1422 cachep->nodelists[node]->next_reap = jiffies +
1423 REAPTIMEOUT_LIST3 +
1424 ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
1425 }
1426}
1427
1428/*
1413 * Initialisation. Called after the page allocator have been initialised and 1429 * Initialisation. Called after the page allocator have been initialised and
1414 * before smp_init(). 1430 * before smp_init().
1415 */ 1431 */
@@ -1432,6 +1448,7 @@ void __init kmem_cache_init(void)
1432 if (i < MAX_NUMNODES) 1448 if (i < MAX_NUMNODES)
1433 cache_cache.nodelists[i] = NULL; 1449 cache_cache.nodelists[i] = NULL;
1434 } 1450 }
1451 set_up_list3s(&cache_cache, CACHE_CACHE);
1435 1452
1436 /* 1453 /*
1437 * Fragmentation resistance on low memory - only use bigger 1454 * Fragmentation resistance on low memory - only use bigger
@@ -1587,10 +1604,9 @@ void __init kmem_cache_init(void)
1587 { 1604 {
1588 int nid; 1605 int nid;
1589 1606
1590 /* Replace the static kmem_list3 structures for the boot cpu */
1591 init_list(&cache_cache, &initkmem_list3[CACHE_CACHE], node);
1592
1593 for_each_online_node(nid) { 1607 for_each_online_node(nid) {
1608 init_list(&cache_cache, &initkmem_list3[CACHE_CACHE], nid);
1609
1594 init_list(malloc_sizes[INDEX_AC].cs_cachep, 1610 init_list(malloc_sizes[INDEX_AC].cs_cachep,
1595 &initkmem_list3[SIZE_AC + nid], nid); 1611 &initkmem_list3[SIZE_AC + nid], nid);
1596 1612
@@ -1960,22 +1976,6 @@ static void slab_destroy(struct kmem_cache *cachep, struct slab *slabp)
1960 } 1976 }
1961} 1977}
1962 1978
1963/*
1964 * For setting up all the kmem_list3s for cache whose buffer_size is same as
1965 * size of kmem_list3.
1966 */
1967static void __init set_up_list3s(struct kmem_cache *cachep, int index)
1968{
1969 int node;
1970
1971 for_each_online_node(node) {
1972 cachep->nodelists[node] = &initkmem_list3[index + node];
1973 cachep->nodelists[node]->next_reap = jiffies +
1974 REAPTIMEOUT_LIST3 +
1975 ((unsigned long)cachep) % REAPTIMEOUT_LIST3;
1976 }
1977}
1978
1979static void __kmem_cache_destroy(struct kmem_cache *cachep) 1979static void __kmem_cache_destroy(struct kmem_cache *cachep)
1980{ 1980{
1981 int i; 1981 int i;
@@ -2099,7 +2099,7 @@ static int __init_refok setup_cpu_cache(struct kmem_cache *cachep)
2099 g_cpucache_up = PARTIAL_L3; 2099 g_cpucache_up = PARTIAL_L3;
2100 } else { 2100 } else {
2101 int node; 2101 int node;
2102 for_each_node_state(node, N_NORMAL_MEMORY) { 2102 for_each_online_node(node) {
2103 cachep->nodelists[node] = 2103 cachep->nodelists[node] =
2104 kmalloc_node(sizeof(struct kmem_list3), 2104 kmalloc_node(sizeof(struct kmem_list3),
2105 GFP_KERNEL, node); 2105 GFP_KERNEL, node);
diff --git a/mm/slub.c b/mm/slub.c
index 474945ecd89d..5cc4b7dddb50 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3962,7 +3962,7 @@ static struct kset_uevent_ops slab_uevent_ops = {
3962 .filter = uevent_filter, 3962 .filter = uevent_filter,
3963}; 3963};
3964 3964
3965static decl_subsys(slab, &slab_ktype, &slab_uevent_ops); 3965static struct kset *slab_kset;
3966 3966
3967#define ID_STR_LENGTH 64 3967#define ID_STR_LENGTH 64
3968 3968
@@ -4015,7 +4015,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
4015 * This is typically the case for debug situations. In that 4015 * This is typically the case for debug situations. In that
4016 * case we can catch duplicate names easily. 4016 * case we can catch duplicate names easily.
4017 */ 4017 */
4018 sysfs_remove_link(&slab_subsys.kobj, s->name); 4018 sysfs_remove_link(&slab_kset->kobj, s->name);
4019 name = s->name; 4019 name = s->name;
4020 } else { 4020 } else {
4021 /* 4021 /*
@@ -4025,12 +4025,12 @@ static int sysfs_slab_add(struct kmem_cache *s)
4025 name = create_unique_id(s); 4025 name = create_unique_id(s);
4026 } 4026 }
4027 4027
4028 kobj_set_kset_s(s, slab_subsys); 4028 s->kobj.kset = slab_kset;
4029 kobject_set_name(&s->kobj, name); 4029 err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
4030 kobject_init(&s->kobj); 4030 if (err) {
4031 err = kobject_add(&s->kobj); 4031 kobject_put(&s->kobj);
4032 if (err)
4033 return err; 4032 return err;
4033 }
4034 4034
4035 err = sysfs_create_group(&s->kobj, &slab_attr_group); 4035 err = sysfs_create_group(&s->kobj, &slab_attr_group);
4036 if (err) 4036 if (err)
@@ -4070,9 +4070,8 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
4070 /* 4070 /*
4071 * If we have a leftover link then remove it. 4071 * If we have a leftover link then remove it.
4072 */ 4072 */
4073 sysfs_remove_link(&slab_subsys.kobj, name); 4073 sysfs_remove_link(&slab_kset->kobj, name);
4074 return sysfs_create_link(&slab_subsys.kobj, 4074 return sysfs_create_link(&slab_kset->kobj, &s->kobj, name);
4075 &s->kobj, name);
4076 } 4075 }
4077 4076
4078 al = kmalloc(sizeof(struct saved_alias), GFP_KERNEL); 4077 al = kmalloc(sizeof(struct saved_alias), GFP_KERNEL);
@@ -4091,8 +4090,8 @@ static int __init slab_sysfs_init(void)
4091 struct kmem_cache *s; 4090 struct kmem_cache *s;
4092 int err; 4091 int err;
4093 4092
4094 err = subsystem_register(&slab_subsys); 4093 slab_kset = kset_create_and_add("slab", &slab_uevent_ops, kernel_kobj);
4095 if (err) { 4094 if (!slab_kset) {
4096 printk(KERN_ERR "Cannot register slab subsystem.\n"); 4095 printk(KERN_ERR "Cannot register slab subsystem.\n");
4097 return -ENOSYS; 4096 return -ENOSYS;
4098 } 4097 }
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 935784f736b3..298e0f463c56 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)
133 struct net_bridge *br = p->br; 133 struct net_bridge *br = p->br;
134 struct net_device *dev = p->dev; 134 struct net_device *dev = p->dev;
135 135
136 sysfs_remove_link(&br->ifobj, dev->name); 136 sysfs_remove_link(br->ifobj, dev->name);
137 137
138 dev_set_promiscuity(dev, -1); 138 dev_set_promiscuity(dev, -1);
139 139
@@ -258,12 +258,6 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
258 p->state = BR_STATE_DISABLED; 258 p->state = BR_STATE_DISABLED;
259 br_stp_port_timer_init(p); 259 br_stp_port_timer_init(p);
260 260
261 kobject_init(&p->kobj);
262 kobject_set_name(&p->kobj, SYSFS_BRIDGE_PORT_ATTR);
263 p->kobj.ktype = &brport_ktype;
264 p->kobj.parent = &(dev->dev.kobj);
265 p->kobj.kset = NULL;
266
267 return p; 261 return p;
268} 262}
269 263
@@ -379,7 +373,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
379 if (IS_ERR(p)) 373 if (IS_ERR(p))
380 return PTR_ERR(p); 374 return PTR_ERR(p);
381 375
382 err = kobject_add(&p->kobj); 376 err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj),
377 SYSFS_BRIDGE_PORT_ATTR);
383 if (err) 378 if (err)
384 goto err0; 379 goto err0;
385 380
@@ -416,6 +411,7 @@ err2:
416 br_fdb_delete_by_port(br, p, 1); 411 br_fdb_delete_by_port(br, p, 1);
417err1: 412err1:
418 kobject_del(&p->kobj); 413 kobject_del(&p->kobj);
414 return err;
419err0: 415err0:
420 kobject_put(&p->kobj); 416 kobject_put(&p->kobj);
421 return err; 417 return err;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index f666f7b28ff5..c11b554fd109 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -124,7 +124,7 @@ struct net_bridge
124 struct timer_list tcn_timer; 124 struct timer_list tcn_timer;
125 struct timer_list topology_change_timer; 125 struct timer_list topology_change_timer;
126 struct timer_list gc_timer; 126 struct timer_list gc_timer;
127 struct kobject ifobj; 127 struct kobject *ifobj;
128}; 128};
129 129
130extern struct notifier_block br_device_notifier; 130extern struct notifier_block br_device_notifier;
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 3312e8f2abe4..9cf0538d1717 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev)
426 goto out2; 426 goto out2;
427 } 427 }
428 428
429 429 br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
430 kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR); 430 if (!br->ifobj) {
431 br->ifobj.ktype = NULL;
432 br->ifobj.kset = NULL;
433 br->ifobj.parent = brobj;
434
435 err = kobject_register(&br->ifobj);
436 if (err) {
437 pr_info("%s: can't add kobject (directory) %s/%s\n", 431 pr_info("%s: can't add kobject (directory) %s/%s\n",
438 __FUNCTION__, dev->name, kobject_name(&br->ifobj)); 432 __FUNCTION__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
439 goto out3; 433 goto out3;
440 } 434 }
441 return 0; 435 return 0;
@@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)
453 struct kobject *kobj = &dev->dev.kobj; 447 struct kobject *kobj = &dev->dev.kobj;
454 struct net_bridge *br = netdev_priv(dev); 448 struct net_bridge *br = netdev_priv(dev);
455 449
456 kobject_unregister(&br->ifobj); 450 kobject_put(br->ifobj);
457 sysfs_remove_bin_file(kobj, &bridge_forward); 451 sysfs_remove_bin_file(kobj, &bridge_forward);
458 sysfs_remove_group(kobj, &bridge_group); 452 sysfs_remove_group(kobj, &bridge_group);
459} 453}
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 79db51fcb476..02b2d50cce4d 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p)
229 goto out2; 229 goto out2;
230 } 230 }
231 231
232 err= sysfs_create_link(&br->ifobj, &p->kobj, p->dev->name); 232 err = sysfs_create_link(br->ifobj, &p->kobj, p->dev->name);
233out2: 233out2:
234 return err; 234 return err;
235} 235}
diff --git a/samples/Kconfig b/samples/Kconfig
index 57bb2236952c..74d97cc24787 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -13,4 +13,14 @@ config SAMPLE_MARKERS
13 help 13 help
14 This build markers example modules. 14 This build markers example modules.
15 15
16config SAMPLE_KOBJECT
17 tristate "Build kobject examples"
18 help
19 This config option will allow you to build a number of
20 different kobject sample modules showing how to use kobjects,
21 ksets, and ktypes properly.
22
23 If in doubt, say "N" here.
24
16endif # SAMPLES 25endif # SAMPLES
26
diff --git a/samples/Makefile b/samples/Makefile
index 5a4f0b6bcbed..8652d0f268ad 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,3 +1,3 @@
1# Makefile for Linux samples code 1# Makefile for Linux samples code
2 2
3obj-$(CONFIG_SAMPLES) += markers/ 3obj-$(CONFIG_SAMPLES) += markers/ kobject/
diff --git a/samples/kobject/Makefile b/samples/kobject/Makefile
new file mode 100644
index 000000000000..4a194203c982
--- /dev/null
+++ b/samples/kobject/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o kset-example.o
diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c
new file mode 100644
index 000000000000..08d0d3ff3263
--- /dev/null
+++ b/samples/kobject/kobject-example.c
@@ -0,0 +1,137 @@
1/*
2 * Sample kobject implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *
9 */
10#include <linux/kobject.h>
11#include <linux/string.h>
12#include <linux/sysfs.h>
13#include <linux/module.h>
14#include <linux/init.h>
15
16/*
17 * This module shows how to create a simple subdirectory in sysfs called
18 * /sys/kernel/kobject-example In that directory, 3 files are created:
19 * "foo", "baz", and "bar". If an integer is written to these files, it can be
20 * later read out of it.
21 */
22
23static int foo;
24static int baz;
25static int bar;
26
27/*
28 * The "foo" file where a static variable is read from and written to.
29 */
30static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr,
31 char *buf)
32{
33 return sprintf(buf, "%d\n", foo);
34}
35
36static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
37 const char *buf, size_t count)
38{
39 sscanf(buf, "%du", &foo);
40 return count;
41}
42
43static struct kobj_attribute foo_attribute =
44 __ATTR(foo, 0666, foo_show, foo_store);
45
46/*
47 * More complex function where we determine which varible is being accessed by
48 * looking at the attribute for the "baz" and "bar" files.
49 */
50static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr,
51 char *buf)
52{
53 int var;
54
55 if (strcmp(attr->attr.name, "baz") == 0)
56 var = baz;
57 else
58 var = bar;
59 return sprintf(buf, "%d\n", var);
60}
61
62static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
63 const char *buf, size_t count)
64{
65 int var;
66
67 sscanf(buf, "%du", &var);
68 if (strcmp(attr->attr.name, "baz") == 0)
69 baz = var;
70 else
71 bar = var;
72 return count;
73}
74
75static struct kobj_attribute baz_attribute =
76 __ATTR(baz, 0666, b_show, b_store);
77static struct kobj_attribute bar_attribute =
78 __ATTR(bar, 0666, b_show, b_store);
79
80
81/*
82 * Create a group of attributes so that we can create and destory them all
83 * at once.
84 */
85static struct attribute *attrs[] = {
86 &foo_attribute.attr,
87 &baz_attribute.attr,
88 &bar_attribute.attr,
89 NULL, /* need to NULL terminate the list of attributes */
90};
91
92/*
93 * An unnamed attribute group will put all of the attributes directly in
94 * the kobject directory. If we specify a name, a subdirectory will be
95 * created for the attributes with the directory being the name of the
96 * attribute group.
97 */
98static struct attribute_group attr_group = {
99 .attrs = attrs,
100};
101
102static struct kobject *example_kobj;
103
104static int example_init(void)
105{
106 int retval;
107
108 /*
109 * Create a simple kobject with the name of "kobject_example",
110 * located under /sys/kernel/
111 *
112 * As this is a simple directory, no uevent will be sent to
113 * userspace. That is why this function should not be used for
114 * any type of dynamic kobjects, where the name and number are
115 * not known ahead of time.
116 */
117 example_kobj = kobject_create_and_add("kobject_example", kernel_kobj);
118 if (!example_kobj)
119 return -ENOMEM;
120
121 /* Create the files associated with this kobject */
122 retval = sysfs_create_group(example_kobj, &attr_group);
123 if (retval)
124 kobject_put(example_kobj);
125
126 return retval;
127}
128
129static void example_exit(void)
130{
131 kobject_put(example_kobj);
132}
133
134module_init(example_init);
135module_exit(example_exit);
136MODULE_LICENSE("GPL");
137MODULE_AUTHOR("Greg Kroah-Hartman <greg@kroah.com>");
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
new file mode 100644
index 000000000000..b0a1b4fe6584
--- /dev/null
+++ b/samples/kobject/kset-example.c
@@ -0,0 +1,278 @@
1/*
2 * Sample kset and ktype implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *
9 */
10#include <linux/kobject.h>
11#include <linux/string.h>
12#include <linux/sysfs.h>
13#include <linux/module.h>
14#include <linux/init.h>
15
16/*
17 * This module shows how to create a kset in sysfs called
18 * /sys/kernel/kset-example
19 * Then tree kobjects are created and assigned to this kset, "foo", "baz",
20 * and "bar". In those kobjects, attributes of the same name are also
21 * created and if an integer is written to these files, it can be later
22 * read out of it.
23 */
24
25
26/*
27 * This is our "object" that we will create a few of and register them with
28 * sysfs.
29 */
30struct foo_obj {
31 struct kobject kobj;
32 int foo;
33 int baz;
34 int bar;
35};
36#define to_foo_obj(x) container_of(x, struct foo_obj, kobj)
37
38/* a custom attribute that works just for a struct foo_obj. */
39struct foo_attribute {
40 struct attribute attr;
41 ssize_t (*show)(struct foo_obj *foo, struct foo_attribute *attr, char *buf);
42 ssize_t (*store)(struct foo_obj *foo, struct foo_attribute *attr, const char *buf, size_t count);
43};
44#define to_foo_attr(x) container_of(x, struct foo_attribute, attr)
45
46/*
47 * The default show function that must be passed to sysfs. This will be
48 * called by sysfs for whenever a show function is called by the user on a
49 * sysfs file associated with the kobjects we have registered. We need to
50 * transpose back from a "default" kobject to our custom struct foo_obj and
51 * then call the show function for that specific object.
52 */
53static ssize_t foo_attr_show(struct kobject *kobj,
54 struct attribute *attr,
55 char *buf)
56{
57 struct foo_attribute *attribute;
58 struct foo_obj *foo;
59
60 attribute = to_foo_attr(attr);
61 foo = to_foo_obj(kobj);
62
63 if (!attribute->show)
64 return -EIO;
65
66 return attribute->show(foo, attribute, buf);
67}
68
69/*
70 * Just like the default show function above, but this one is for when the
71 * sysfs "store" is requested (when a value is written to a file.)
72 */
73static ssize_t foo_attr_store(struct kobject *kobj,
74 struct attribute *attr,
75 const char *buf, size_t len)
76{
77 struct foo_attribute *attribute;
78 struct foo_obj *foo;
79
80 attribute = to_foo_attr(attr);
81 foo = to_foo_obj(kobj);
82
83 if (!attribute->store)
84 return -EIO;
85
86 return attribute->store(foo, attribute, buf, len);
87}
88
89/* Our custom sysfs_ops that we will associate with our ktype later on */
90static struct sysfs_ops foo_sysfs_ops = {
91 .show = foo_attr_show,
92 .store = foo_attr_store,
93};
94
95/*
96 * The release function for our object. This is REQUIRED by the kernel to
97 * have. We free the memory held in our object here.
98 *
99 * NEVER try to get away with just a "blank" release function to try to be
100 * smarter than the kernel. Turns out, no one ever is...
101 */
102static void foo_release(struct kobject *kobj)
103{
104 struct foo_obj *foo;
105
106 foo = to_foo_obj(kobj);
107 kfree(foo);
108}
109
110/*
111 * The "foo" file where the .foo variable is read from and written to.
112 */
113static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
114 char *buf)
115{
116 return sprintf(buf, "%d\n", foo_obj->foo);
117}
118
119static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
120 const char *buf, size_t count)
121{
122 sscanf(buf, "%du", &foo_obj->foo);
123 return count;
124}
125
126static struct foo_attribute foo_attribute =
127 __ATTR(foo, 0666, foo_show, foo_store);
128
129/*
130 * More complex function where we determine which varible is being accessed by
131 * looking at the attribute for the "baz" and "bar" files.
132 */
133static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
134 char *buf)
135{
136 int var;
137
138 if (strcmp(attr->attr.name, "baz") == 0)
139 var = foo_obj->baz;
140 else
141 var = foo_obj->bar;
142 return sprintf(buf, "%d\n", var);
143}
144
145static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
146 const char *buf, size_t count)
147{
148 int var;
149
150 sscanf(buf, "%du", &var);
151 if (strcmp(attr->attr.name, "baz") == 0)
152 foo_obj->baz = var;
153 else
154 foo_obj->bar = var;
155 return count;
156}
157
158static struct foo_attribute baz_attribute =
159 __ATTR(baz, 0666, b_show, b_store);
160static struct foo_attribute bar_attribute =
161 __ATTR(bar, 0666, b_show, b_store);
162
163/*
164 * Create a group of attributes so that we can create and destory them all
165 * at once.
166 */
167static struct attribute *foo_default_attrs[] = {
168 &foo_attribute.attr,
169 &baz_attribute.attr,
170 &bar_attribute.attr,
171 NULL, /* need to NULL terminate the list of attributes */
172};
173
174/*
175 * Our own ktype for our kobjects. Here we specify our sysfs ops, the
176 * release function, and the set of default attributes we want created
177 * whenever a kobject of this type is registered with the kernel.
178 */
179static struct kobj_type foo_ktype = {
180 .sysfs_ops = &foo_sysfs_ops,
181 .release = foo_release,
182 .default_attrs = foo_default_attrs,
183};
184
185static struct kset *example_kset;
186static struct foo_obj *foo_obj;
187static struct foo_obj *bar_obj;
188static struct foo_obj *baz_obj;
189
190static struct foo_obj *create_foo_obj(const char *name)
191{
192 struct foo_obj *foo;
193 int retval;
194
195 /* allocate the memory for the whole object */
196 foo = kzalloc(sizeof(*foo), GFP_KERNEL);
197 if (!foo)
198 return NULL;
199
200 /*
201 * As we have a kset for this kobject, we need to set it before calling
202 * the kobject core.
203 */
204 foo->kobj.kset = example_kset;
205
206 /*
207 * Initialize and add the kobject to the kernel. All the default files
208 * will be created here. As we have already specified a kset for this
209 * kobject, we don't have to set a parent for the kobject, the kobject
210 * will be placed beneath that kset automatically.
211 */
212 retval = kobject_init_and_add(&foo->kobj, &foo_ktype, NULL, "%s", name);
213 if (retval) {
214 kfree(foo);
215 return NULL;
216 }
217
218 /*
219 * We are always responsible for sending the uevent that the kobject
220 * was added to the system.
221 */
222 kobject_uevent(&foo->kobj, KOBJ_ADD);
223
224 return foo;
225}
226
227static void destroy_foo_obj(struct foo_obj *foo)
228{
229 kobject_put(&foo->kobj);
230}
231
232static int example_init(void)
233{
234 /*
235 * Create a kset with the name of "kset_example",
236 * located under /sys/kernel/
237 */
238 example_kset = kset_create_and_add("kset_example", NULL, kernel_kobj);
239 if (!example_kset)
240 return -ENOMEM;
241
242 /*
243 * Create three objects and register them with our kset
244 */
245 foo_obj = create_foo_obj("foo");
246 if (!foo_obj)
247 goto foo_error;
248
249 bar_obj = create_foo_obj("bar");
250 if (!bar_obj)
251 goto bar_error;
252
253 baz_obj = create_foo_obj("baz");
254 if (!baz_obj)
255 goto baz_error;
256
257 return 0;
258
259baz_error:
260 destroy_foo_obj(bar_obj);
261bar_error:
262 destroy_foo_obj(foo_obj);
263foo_error:
264 return -EINVAL;
265}
266
267static void example_exit(void)
268{
269 destroy_foo_obj(baz_obj);
270 destroy_foo_obj(bar_obj);
271 destroy_foo_obj(foo_obj);
272 kset_unregister(example_kset);
273}
274
275module_init(example_init);
276module_exit(example_exit);
277MODULE_LICENSE("GPL");
278MODULE_AUTHOR("Greg Kroah-Hartman <greg@kroah.com>");
diff --git a/security/inode.c b/security/inode.c
index b28a8acae34d..acc6cf0d7900 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -315,20 +315,19 @@ void securityfs_remove(struct dentry *dentry)
315} 315}
316EXPORT_SYMBOL_GPL(securityfs_remove); 316EXPORT_SYMBOL_GPL(securityfs_remove);
317 317
318static decl_subsys(security, NULL, NULL); 318static struct kobject *security_kobj;
319 319
320static int __init securityfs_init(void) 320static int __init securityfs_init(void)
321{ 321{
322 int retval; 322 int retval;
323 323
324 kobj_set_kset_s(&security_subsys, kernel_subsys); 324 security_kobj = kobject_create_and_add("security", kernel_kobj);
325 retval = subsystem_register(&security_subsys); 325 if (!security_kobj)
326 if (retval) 326 return -EINVAL;
327 return retval;
328 327
329 retval = register_filesystem(&fs_type); 328 retval = register_filesystem(&fs_type);
330 if (retval) 329 if (retval)
331 subsystem_unregister(&security_subsys); 330 kobject_put(security_kobj);
332 return retval; 331 return retval;
333} 332}
334 333