diff options
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/Kconfig | 7 | ||||
-rw-r--r-- | drivers/char/agp/intel-gtt.c | 128 | ||||
-rw-r--r-- | drivers/char/hw_random/exynos-rng.c | 11 | ||||
-rw-r--r-- | drivers/char/hw_random/omap-rng.c | 6 | ||||
-rw-r--r-- | drivers/char/hw_random/tx4939-rng.c | 7 | ||||
-rw-r--r-- | drivers/char/mem.c | 10 | ||||
-rw-r--r-- | drivers/char/pcmcia/Kconfig | 4 | ||||
-rw-r--r-- | drivers/char/pcmcia/synclink_cs.c | 707 | ||||
-rw-r--r-- | drivers/char/random.c | 6 | ||||
-rw-r--r-- | drivers/char/tpm/Kconfig | 12 | ||||
-rw-r--r-- | drivers/char/tpm/Makefile | 1 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.c | 114 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.h | 52 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_acpi.c | 8 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_atmel.c | 7 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_i2c_infineon.c | 7 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_i2c_stm_st33.c | 887 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_i2c_stm_st33.h | 61 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_ibmvtpm.c | 15 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_nsc.c | 7 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_tis.c | 64 |
21 files changed, 1626 insertions, 495 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 72bedad6bf8c..3bb6fa3930be 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -53,7 +53,7 @@ source "drivers/tty/serial/Kconfig" config TTY_PRINTK bool "TTY driver to output user messages via printk" - depends on EXPERT + depends on EXPERT && TTY default n ---help--- If you say Y here, the support for writing user messages (i.e. @@ -159,7 +159,7 @@ source "drivers/tty/hvc/Kconfig" config VIRTIO_CONSOLE tristate "Virtio console" - depends on VIRTIO + depends on VIRTIO && TTY select HVC_DRIVER help Virtio console for use with lguest and other hypervisors. @@ -392,6 +392,7 @@ config XILINX_HWICAP config R3964 tristate "Siemens R3964 line discipline" + depends on TTY ---help--- This driver allows synchronous communication with devices using the Siemens R3964 packet protocol. Unless you are dealing with special @@ -439,7 +440,7 @@ source "drivers/char/pcmcia/Kconfig" config MWAVE tristate "ACP Modem (Mwave) support" - depends on X86 + depends on X86 && TTY select SERIAL_8250 ---help--- The ACP modem (Mwave) for Linux is a WinModem. It is composed of a diff --git a/drivers/char/agp/intel-gtt.c b/drivers/char/agp/intel-gtt.c index dbd901e94ea6..b8e2014cb9cb 100644 --- a/drivers/char/agp/intel-gtt.c +++ b/drivers/char/agp/intel-gtt.c @@ -60,7 +60,6 @@ struct intel_gtt_driver { }; static struct _intel_private { - struct intel_gtt base; const struct intel_gtt_driver *driver; struct pci_dev *pcidev; /* device one */ struct pci_dev *bridge_dev; @@ -75,7 +74,18 @@ static struct _intel_private { struct resource ifp_resource; int resource_valid; struct page *scratch_page; + phys_addr_t scratch_page_dma; int refcount; + /* Whether i915 needs to use the dmar apis or not. */ + unsigned int needs_dmar : 1; + phys_addr_t gma_bus_addr; + /* Size of memory reserved for graphics by the BIOS */ + unsigned int stolen_size; + /* Total number of gtt entries. */ + unsigned int gtt_total_entries; + /* Part of the gtt that is mappable by the cpu, for those chips where + * this is not the full gtt. */ + unsigned int gtt_mappable_entries; } intel_private; #define INTEL_GTT_GEN intel_private.driver->gen @@ -291,15 +301,15 @@ static int intel_gtt_setup_scratch_page(void) get_page(page); set_pages_uc(page, 1); - if (intel_private.base.needs_dmar) { + if (intel_private.needs_dmar) { dma_addr = pci_map_page(intel_private.pcidev, page, 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); if (pci_dma_mapping_error(intel_private.pcidev, dma_addr)) return -EINVAL; - intel_private.base.scratch_page_dma = dma_addr; + intel_private.scratch_page_dma = dma_addr; } else - intel_private.base.scratch_page_dma = page_to_phys(page); + intel_private.scratch_page_dma = page_to_phys(page); intel_private.scratch_page = page; @@ -506,7 +516,7 @@ static unsigned int intel_gtt_total_entries(void) /* On previous hardware, the GTT size was just what was * required to map the aperture. */ - return intel_private.base.gtt_mappable_entries; + return intel_private.gtt_mappable_entries; } } @@ -546,7 +556,7 @@ static unsigned int intel_gtt_mappable_entries(void) static void intel_gtt_teardown_scratch_page(void) { set_pages_wb(intel_private.scratch_page, 1); - pci_unmap_page(intel_private.pcidev, intel_private.base.scratch_page_dma, + pci_unmap_page(intel_private.pcidev, intel_private.scratch_page_dma, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); put_page(intel_private.scratch_page); __free_page(intel_private.scratch_page); @@ -562,6 +572,40 @@ static void intel_gtt_cleanup(void) intel_gtt_teardown_scratch_page(); } +/* Certain Gen5 chipsets require require idling the GPU before + * unmapping anything from the GTT when VT-d is enabled. + */ +static inline int needs_ilk_vtd_wa(void) +{ +#ifdef CONFIG_INTEL_IOMMU + const unsigned short gpu_devid = intel_private.pcidev->device; + + /* Query intel_iommu to see if we need the workaround. Presumably that + * was loaded first. + */ + if ((gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || + gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && + intel_iommu_gfx_mapped) + return 1; +#endif + return 0; +} + +static bool intel_gtt_can_wc(void) +{ + if (INTEL_GTT_GEN <= 2) + return false; + + if (INTEL_GTT_GEN >= 6) + return false; + + /* Reports of major corruption with ILK vt'd enabled */ + if (needs_ilk_vtd_wa()) + return false; + + return true; +} + static int intel_gtt_init(void) { u32 gma_addr; @@ -572,8 +616,8 @@ static int intel_gtt_init(void) if (ret != 0) return ret; - intel_private.base.gtt_mappable_entries = intel_gtt_mappable_entries(); - intel_private.base.gtt_total_entries = intel_gtt_total_entries(); + intel_private.gtt_mappable_entries = intel_gtt_mappable_entries(); + intel_private.gtt_total_entries = intel_gtt_total_entries(); /* save the PGETBL reg for resume */ intel_private.PGETBL_save = @@ -585,13 +629,13 @@ static int intel_gtt_init(void) dev_info(&intel_private.bridge_dev->dev, "detected gtt size: %dK total, %dK mappable\n", - intel_private.base.gtt_total_entries * 4, - intel_private.base.gtt_mappable_entries * 4); + intel_private.gtt_total_entries * 4, + intel_private.gtt_mappable_entries * 4); - gtt_map_size = intel_private.base.gtt_total_entries * 4; + gtt_map_size = intel_private.gtt_total_entries * 4; intel_private.gtt = NULL; - if (INTEL_GTT_GEN < 6 && INTEL_GTT_GEN > 2) + if (intel_gtt_can_wc()) intel_private.gtt = ioremap_wc(intel_private.gtt_bus_addr, gtt_map_size); if (intel_private.gtt == NULL) @@ -602,13 +646,12 @@ static int intel_gtt_init(void) iounmap(intel_private.registers); return -ENOMEM; } - intel_private.base.gtt = intel_private.gtt; global_cache_flush(); /* FIXME: ? */ - intel_private.base.stolen_size = intel_gtt_stolen_size(); + intel_private.stolen_size = intel_gtt_stolen_size(); - intel_private.base.needs_dmar = USE_PCI_DMA_API && INTEL_GTT_GEN > 2; + intel_private.needs_dmar = USE_PCI_DMA_API && INTEL_GTT_GEN > 2; ret = intel_gtt_setup_scratch_page(); if (ret != 0) { @@ -623,7 +666,7 @@ static int intel_gtt_init(void) pci_read_config_dword(intel_private.pcidev, I915_GMADDR, &gma_addr); - intel_private.base.gma_bus_addr = (gma_addr & PCI_BASE_ADDRESS_MEM_MASK); + intel_private.gma_bus_addr = (gma_addr & PCI_BASE_ADDRESS_MEM_MASK); return 0; } @@ -634,8 +677,7 @@ static int intel_fake_agp_fetch_size(void) unsigned int aper_size; int i; - aper_size = (intel_private.base.gtt_mappable_entries << PAGE_SHIFT) - / MB(1); + aper_size = (intel_private.gtt_mappable_entries << PAGE_SHIFT) / MB(1); for (i = 0; i < num_sizes; i++) { if (aper_size == intel_fake_agp_sizes[i].size) { @@ -779,7 +821,7 @@ static int intel_fake_agp_configure(void) return -EIO; intel_private.clear_fake_agp = true; - agp_bridge->gart_bus_addr = intel_private.base.gma_bus_addr; + agp_bridge->gart_bus_addr = intel_private.gma_bus_addr; return 0; } @@ -841,12 +883,9 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, { int ret = -EINVAL; - if (intel_private.base.do_idle_maps) - return -ENODEV; - if (intel_private.clear_fake_agp) { - int start = intel_private.base.stolen_size / PAGE_SIZE; - int end = intel_private.base.gtt_mappable_entries; + int start = intel_private.stolen_size / PAGE_SIZE; + int end = intel_private.gtt_mappable_entries; intel_gtt_clear_range(start, end - start); intel_private.clear_fake_agp = false; } @@ -857,7 +896,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, if (mem->page_count == 0) goto out; - if (pg_start + mem->page_count > intel_private.base.gtt_total_entries) + if (pg_start + mem->page_count > intel_private.gtt_total_entries) goto out_err; if (type != mem->type) @@ -869,7 +908,7 @@ static int intel_fake_agp_insert_entries(struct agp_memory *mem, if (!mem->is_flushed) global_cache_flush(); - if (intel_private.base.needs_dmar) { + if (intel_private.needs_dmar) { struct sg_table st; ret = intel_gtt_map_memory(mem->pages, mem->page_count, &st); @@ -895,7 +934,7 @@ void intel_gtt_clear_range(unsigned int first_entry, unsigned int num_entries) unsigned int i; for (i = first_entry; i < (first_entry + num_entries); i++) { - intel_private.driver->write_entry(intel_private.base.scratch_page_dma, + intel_private.driver->write_entry(intel_private.scratch_page_dma, i, 0); } readl(intel_private.gtt+i-1); @@ -908,12 +947,9 @@ static int intel_fake_agp_remove_entries(struct agp_memory *mem, if (mem->page_count == 0) return 0; - if (intel_private.base.do_idle_maps) - return -ENODEV; - intel_gtt_clear_range(pg_start, mem->page_count); - if (intel_private.base.needs_dmar) { + if (intel_private.needs_dmar) { intel_gtt_unmap_memory(mem->sg_list, mem->num_sg); mem->sg_list = NULL; mem->num_sg = 0; @@ -1070,25 +1106,6 @@ static void i965_write_entry(dma_addr_t addr, writel(addr | pte_flags, intel_private.gtt + entry); } -/* Certain Gen5 chipsets require require idling the GPU before - * unmapping anything from the GTT when VT-d is enabled. - */ -static inline int needs_idle_maps(void) -{ -#ifdef CONFIG_INTEL_IOMMU - const unsigned short gpu_devid = intel_private.pcidev->device; - - /* Query intel_iommu to see if we need the workaround. Presumably that - * was loaded first. - */ - if ((gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || - gpu_devid == PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG) && - intel_iommu_gfx_mapped) - return 1; -#endif - return 0; -} - static int i9xx_setup(void) { u32 reg_addr, gtt_addr; @@ -1116,9 +1133,6 @@ static int i9xx_setup(void) break; } - if (needs_idle_maps()) - intel_private.base.do_idle_maps = 1; - intel_i9xx_setup_flush(); return 0; @@ -1390,9 +1404,13 @@ int intel_gmch_probe(struct pci_dev *bridge_pdev, struct pci_dev *gpu_pdev, } EXPORT_SYMBOL(intel_gmch_probe); -struct intel_gtt *intel_gtt_get(void) +void intel_gtt_get(size_t *gtt_total, size_t *stolen_size, + phys_addr_t *mappable_base, unsigned long *mappable_end) { - return &intel_private.base; + *gtt_total = intel_private.gtt_total_entries << PAGE_SHIFT; + *stolen_size = intel_private.stolen_size; + *mappable_base = intel_private.gma_bus_addr; + *mappable_end = intel_private.gtt_mappable_entries << PAGE_SHIFT; } EXPORT_SYMBOL(intel_gtt_get); diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c index 48bbfeca4b5d..ac47631ab34f 100644 --- a/drivers/char/hw_random/exynos-rng.c +++ b/drivers/char/hw_random/exynos-rng.c @@ -104,6 +104,7 @@ static int exynos_read(struct hwrng *rng, void *buf, static int exynos_rng_probe(struct platform_device *pdev) { struct exynos_rng *exynos_rng; + struct resource *res; exynos_rng = devm_kzalloc(&pdev->dev, sizeof(struct exynos_rng), GFP_KERNEL); @@ -120,10 +121,10 @@ static int exynos_rng_probe(struct platform_device *pdev) return -ENOENT; } - exynos_rng->mem = devm_request_and_ioremap(&pdev->dev, - platform_get_resource(pdev, IORESOURCE_MEM, 0)); - if (!exynos_rng->mem) - return -EBUSY; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + exynos_rng->mem = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(exynos_rng->mem)) + return PTR_ERR(exynos_rng->mem); platform_set_drvdata(pdev, exynos_rng); @@ -162,7 +163,7 @@ static int exynos_rng_runtime_resume(struct device *dev) } -UNIVERSAL_DEV_PM_OPS(exynos_rng_pm_ops, exynos_rng_runtime_suspend, +static UNIVERSAL_DEV_PM_OPS(exynos_rng_pm_ops, exynos_rng_runtime_suspend, exynos_rng_runtime_resume, NULL); static struct platform_driver exynos_rng_driver = { diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c index d8c54e253761..749dc16ca2cc 100644 --- a/drivers/char/hw_random/omap-rng.c +++ b/drivers/char/hw_random/omap-rng.c @@ -124,9 +124,9 @@ static int omap_rng_probe(struct platform_device *pdev) goto err_ioremap; } - priv->base = devm_request_and_ioremap(&pdev->dev, priv->mem_res); - if (!priv->base) { - ret = -ENOMEM; + priv->base = devm_ioremap_resource(&pdev->dev, priv->mem_res); + if (IS_ERR(priv->base)) { + ret = PTR_ERR(priv->base); goto err_ioremap; } dev_set_drvdata(&pdev->dev, priv); diff --git a/drivers/char/hw_random/tx4939-rng.c b/drivers/char/hw_random/tx4939-rng.c index de473ef3882b..30991989d65b 100644 --- a/drivers/char/hw_random/tx4939-rng.c +++ b/drivers/char/hw_random/tx4939-rng.c @@ -7,6 +7,7 @@ * License. See the file "COPYING" in the main directory of this archive * for more details. */ +#include <linux/err.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> @@ -115,9 +116,9 @@ static int __init tx4939_rng_probe(struct platform_device *dev) rngdev = devm_kzalloc(&dev->dev, sizeof(*rngdev), GFP_KERNEL); if (!rngdev) return -ENOMEM; - rngdev->base = devm_request_and_ioremap(&dev->dev, r); - if (!rngdev->base) - return -EBUSY; + rngdev->base = devm_ioremap_resource(&dev->dev, r); + if (IS_ERR(rngdev->base)) + return PTR_ERR(rngdev->base); rngdev->rng.name = dev_name(&dev->dev); rngdev->rng.data_present = tx4939_rng_data_present; diff --git a/drivers/char/mem.c b/drivers/char/mem.c index c6fa3bc2baa8..6f6e92a3102d 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -399,7 +399,7 @@ static ssize_t read_kmem(struct file *file, char __user *buf, { unsigned long p = *ppos; ssize_t low_count, read, sz; - char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */ + char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */ int err = 0; read = 0; @@ -527,7 +527,7 @@ static ssize_t write_kmem(struct file *file, const char __user *buf, unsigned long p = *ppos; ssize_t wrote = 0; ssize_t virtr = 0; - char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ + char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ int err = 0; if (p < (unsigned long) high_memory) { @@ -595,7 +595,7 @@ static ssize_t write_port(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { unsigned long i = *ppos; - const char __user * tmp = buf; + const char __user *tmp = buf; if (!access_ok(VERIFY_READ, buf, count)) return -EFAULT; @@ -729,7 +729,7 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig) return ret; } -static int open_port(struct inode * inode, struct file * filp) +static int open_port(struct inode *inode, struct file *filp) { return capable(CAP_SYS_RAWIO) ? 0 : -EPERM; } @@ -898,7 +898,7 @@ static int __init chr_dev_init(void) continue; /* - * Create /dev/port? + * Create /dev/port? */ if ((minor == DEVPORT_MINOR) && !arch_has_dev_port()) continue; diff --git a/drivers/char/pcmcia/Kconfig b/drivers/char/pcmcia/Kconfig index 6614416a8623..2a166d56738a 100644 --- a/drivers/char/pcmcia/Kconfig +++ b/drivers/char/pcmcia/Kconfig @@ -7,7 +7,7 @@ menu "PCMCIA character devices" config SYNCLINK_CS tristate "SyncLink PC Card support" - depends on PCMCIA + depends on PCMCIA && TTY help Enable support for the SyncLink PC Card serial adapter, running asynchronous and HDLC communications up to 512Kbps. The port is @@ -45,7 +45,7 @@ config CARDMAN_4040 config IPWIRELESS tristate "IPWireless 3G UMTS PCMCIA card support" - depends on PCMCIA && NETDEVICES + depends on PCMCIA && NETDEVICES && TTY select PPP help This is a driver for 3G UMTS PCMCIA card from IPWireless company. In diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index b66eaa04f8cb..5c5cc00ebb07 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -102,8 +102,7 @@ static MGSL_PARAMS default_params = { ASYNC_PARITY_NONE /* unsigned char parity; */ }; -typedef struct -{ +typedef struct { int count; unsigned char status; char data[1]; @@ -210,7 +209,7 @@ typedef struct _mgslpc_info { char testing_irq; unsigned int init_error; /* startup error (DIAGS) */ - char flag_buf[MAX_ASYNC_BUFFER_SIZE]; + char *flag_buf; bool drop_rts_on_tx_done; struct _input_signal_events input_signal_events; @@ -326,10 +325,10 @@ typedef struct _mgslpc_info { #define write_reg16(info, reg, val) outw((val), (info)->io_base + (reg)) #define set_reg_bits(info, reg, mask) \ - write_reg(info, (reg), \ + write_reg(info, (reg), \ (unsigned char) (read_reg(info, (reg)) | (mask))) #define clear_reg_bits(info, reg, mask) \ - write_reg(info, (reg), \ + write_reg(info, (reg), \ (unsigned char) (read_reg(info, (reg)) & ~(mask))) /* * interrupt enable/disable routines @@ -356,10 +355,10 @@ static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short } #define port_irq_disable(info, mask) \ - { info->pim_value |= (mask); write_reg(info, PIM, info->pim_value); } + { info->pim_value |= (mask); write_reg(info, PIM, info->pim_value); } #define port_irq_enable(info, mask) \ - { info->pim_value &= ~(mask); write_reg(info, PIM, info->pim_value); } + { info->pim_value &= ~(mask); write_reg(info, PIM, info->pim_value); } static void rx_start(MGSLPC_INFO *info); static void rx_stop(MGSLPC_INFO *info); @@ -397,7 +396,7 @@ static int adapter_test(MGSLPC_INFO *info); static int claim_resources(MGSLPC_INFO *info); static void release_resources(MGSLPC_INFO *info); -static void mgslpc_add_device(MGSLPC_INFO *info); +static int mgslpc_add_device(MGSLPC_INFO *info); static void mgslpc_remove_device(MGSLPC_INFO *info); static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty); @@ -514,49 +513,56 @@ static const struct tty_port_operations mgslpc_port_ops = { static int mgslpc_probe(struct pcmcia_device *link) { - MGSLPC_INFO *info; - int ret; - - if (debug_level >= DEBUG_LEVEL_INFO) - printk("mgslpc_attach\n"); - - info = kzalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); - if (!info) { - printk("Error can't allocate device instance data\n"); - return -ENOMEM; - } - - info->magic = MGSLPC_MAGIC; - tty_port_init(&info->port); - info->port.ops = &mgslpc_port_ops; - INIT_WORK(&info->task, bh_handler); - info->max_frame_size = 4096; - info->port.close_delay = 5*HZ/10; - info->port.closing_wait = 30*HZ; - init_waitqueue_head(&info->status_event_wait_q); - init_waitqueue_head(&info->event_wait_q); - spin_lock_init(&info->lock); - spin_lock_init(&info->netlock); - memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); - info->idle_mode = HDLC_TXIDLE_FLAGS; - info->imra_value = 0xffff; - info->imrb_value = 0xffff; - info->pim_value = 0xff; - - info->p_dev = link; - link->priv = info; - - /* Initialize the struct pcmcia_device structure */ - - ret = mgslpc_config(link); - if (ret) { - tty_port_destroy(&info->port); - return ret; - } - - mgslpc_add_device(info); - - return 0; + MGSLPC_INFO *info; + int ret; + + if (debug_level >= DEBUG_LEVEL_INFO) + printk("mgslpc_attach\n"); + + info = kzalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); + if (!info) { + printk("Error can't allocate device instance data\n"); + return -ENOMEM; + } + + info->magic = MGSLPC_MAGIC; + tty_port_init(&info->port); + info->port.ops = &mgslpc_port_ops; + INIT_WORK(&info->task, bh_handler); + info->max_frame_size = 4096; + info->port.close_delay = 5*HZ/10; + info->port.closing_wait = 30*HZ; + init_waitqueue_head(&info->status_event_wait_q); + init_waitqueue_head(&info->event_wait_q); + spin_lock_init(&info->lock); + spin_lock_init(&info->netlock); + memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); + info->idle_mode = HDLC_TXIDLE_FLAGS; + info->imra_value = 0xffff; + info->imrb_value = 0xffff; + info->pim_value = 0xff; + + info->p_dev = link; + link->priv = info; + + /* Initialize the struct pcmcia_device structure */ + + ret = mgslpc_config(link); + if (ret != 0) + goto failed; + + ret = mgslpc_add_device(info); + if (ret != 0) + goto failed_release; + + return 0; + +failed_release: + mgslpc_release((u_long)link); +failed: + tty_port_destroy(&info->port); + kfree(info); + return ret; } /* Card has been inserted. @@ -569,35 +575,35 @@ static int mgslpc_ioprobe(struct pcmcia_device *p_dev, void *priv_data) static int mgslpc_config(struct pcmcia_device *link) { - MGSLPC_INFO *info = link->priv; - int ret; + MGSLPC_INFO *info = link->priv; + int ret; - if (debug_level >= DEBUG_LEVEL_INFO) - printk("mgslpc_config(0x%p)\n", link); + if (debug_level >= DEBUG_LEVEL_INFO) + printk("mgslpc_config(0x%p)\n", link); - link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; + link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; - ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL); - if (ret != 0) - goto failed; + ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL); + if (ret != 0) + goto failed; - link->config_index = 8; - link->config_regs = PRESENT_OPTION; + link->config_index = 8; + link->config_regs = PRESENT_OPTION; - ret = pcmcia_request_irq(link, mgslpc_isr); - if (ret) - goto failed; - ret = pcmcia_enable_device(link); - if (ret) - goto failed; + ret = pcmcia_request_irq(link, mgslpc_isr); + if (ret) + goto failed; + ret = pcmcia_enable_device(link); + if (ret) + goto failed; - info->io_base = link->resource[0]->start; - info->irq_level = link->irq; - return 0; + info->io_base = link->resource[0]->start; + info->irq_level = link->irq; + return 0; failed: - mgslpc_release((u_long)link); - return -ENODEV; + mgslpc_release((u_long)link); + return -ENODEV; } /* Card has been removed. @@ -703,12 +709,12 @@ static void tx_pause(struct tty_struct *tty) if (mgslpc_paranoia_check(info, tty->name, "tx_pause")) return; if (debug_level >= DEBUG_LEVEL_INFO) - printk("tx_pause(%s)\n",info->device_name); + printk("tx_pause(%s)\n", info->device_name); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (info->tx_enabled) - tx_stop(info); - spin_unlock_irqrestore(&info->lock,flags); + tx_stop(info); + spin_unlock_irqrestore(&info->lock, flags); } static void tx_release(struct tty_struct *tty) @@ -719,12 +725,12 @@ static void tx_release(struct tty_struct *tty) if (mgslpc_paranoia_check(info, tty->name, "tx_release")) return; if (debug_level >= DEBUG_LEVEL_INFO) - printk("tx_release(%s)\n",info->device_name); + printk("tx_release(%s)\n", info->device_name); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (!info->tx_enabled) - tx_start(info, tty); - spin_unlock_irqrestore(&info->lock,flags); + tx_start(info, tty); + spin_unlock_irqrestore(&info->lock, flags); } /* Return next bottom half action to perform. @@ -735,7 +741,7 @@ static int bh_action(MGSLPC_INFO *info) unsigned long flags; int rc = 0; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (info->pending_bh & BH_RECEIVE) { info->pending_bh &= ~BH_RECEIVE; @@ -754,7 +760,7 @@ static int bh_action(MGSLPC_INFO *info) info->bh_requested = false; } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return rc; } @@ -765,11 +771,8 @@ static void bh_handler(struct work_struct *work) struct tty_struct *tty; int action; - if (!info) - return; - if (debug_level >= DEBUG_LEVEL_BH) - printk( "%s(%d):bh_handler(%s) entry\n", + printk("%s(%d):bh_handler(%s) entry\n", __FILE__,__LINE__,info->device_name); info->bh_running = true; @@ -778,8 +781,8 @@ static void bh_handler(struct work_struct *work) while((action = bh_action(info)) != 0) { /* Process work item */ - if ( debug_level >= DEBUG_LEVEL_BH ) - printk( "%s(%d):bh_handler() work item action=%d\n", + if (debug_level >= DEBUG_LEVEL_BH) + printk("%s(%d):bh_handler() work item action=%d\n", __FILE__,__LINE__,action); switch (action) { @@ -802,7 +805,7 @@ static void bh_handler(struct work_struct *work) tty_kref_put(tty); if (debug_level >= DEBUG_LEVEL_BH) - printk( "%s(%d):bh_handler(%s) exit\n", + printk("%s(%d):bh_handler(%s) exit\n", __FILE__,__LINE__,info->device_name); } @@ -831,7 +834,7 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom) RXBUF *buf = (RXBUF*)(info->rx_buf + (info->rx_put * info->rx_buf_size)); if (debug_level >= DEBUG_LEVEL_ISR) - printk("%s(%d):rx_ready_hdlc(eom=%d)\n",__FILE__,__LINE__,eom); + printk("%s(%d):rx_ready_hdlc(eom=%d)\n", __FILE__, __LINE__, eom); if (!info->rx_enabled) return; @@ -847,7 +850,8 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom) if (eom) { /* end of frame, get FIFO count from RBCL register */ - if (!(fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f))) + fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f); + if (fifo_count == 0) fifo_count = 32; } else fifo_count = 32; @@ -886,20 +890,13 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom) issue_command(info, CHA, CMD_RXFIFO); } -static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty) +static void rx_ready_async(MGSLPC_INFO *info, int tcd) { + struct tty_port *port = &info->port; unsigned char data, status, flag; int fifo_count; int work = 0; - struct mgsl_icount *icount = &info->icount; - - if (!tty) { - /* tty is not available anymore */ - issue_command(info, CHA, CMD_RXRESET); - if (debug_level >= DEBUG_LEVEL_ISR) - printk("%s(%d):rx_ready_async(tty=NULL)\n",__FILE__,__LINE__); - return; - } + struct mgsl_icount *icount = &info->icount; if (tcd) { /* early termination, get FIFO count from RBCL register */ @@ -913,7 +910,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty) } else fifo_count = 32; - tty_buffer_request_room(tty, fifo_count); + tty_buffer_request_room(port, fifo_count); /* Flush received async data to receive data buffer. */ while (fifo_count) { data = read_reg(info, CHA + RXFIFO); @@ -944,7 +941,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty) else if (status & BIT6) flag = TTY_FRAME; } - work += tty_insert_flip_char(tty, data, flag); + work += tty_insert_flip_char(port, data, flag); } issue_command(info, CHA, CMD_RXFIFO); @@ -957,7 +954,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty) } if (work) - tty_flip_buffer_push(tty); + tty_flip_buffer_push(port); } @@ -1004,7 +1001,7 @@ static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty) int c; if (debug_level >= DEBUG_LEVEL_ISR) - printk("%s(%d):tx_ready(%s)\n", __FILE__,__LINE__,info->device_name); + printk("%s(%d):tx_ready(%s)\n", __FILE__, __LINE__, info->device_name); if (info->params.mode == MGSL_MODE_HDLC) { if (!info->tx_active) @@ -1217,7 +1214,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) if (info->params.mode == MGSL_MODE_HDLC) rx_ready_hdlc(info, isr & IRQ_RXEOM); else - rx_ready_async(info, isr & IRQ_RXEOM, tty); + rx_ready_async(info, isr & IRQ_RXEOM); } /* transmit IRQs */ @@ -1249,7 +1246,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id) */ if (info->pending_bh && !info->bh_running && !info->bh_requested) { - if ( debug_level >= DEBUG_LEVEL_ISR ) + if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):%s queueing bh task.\n", __FILE__,__LINE__,info->device_name); schedule_work(&info->task); @@ -1273,7 +1270,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) int retval = 0; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name); + printk("%s(%d):startup(%s)\n", __FILE__, __LINE__, info->device_name); if (info->port.flags & ASYNC_INITIALIZED) return 0; @@ -1283,7 +1280,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) info->tx_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); if (!info->tx_buf) { printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n", - __FILE__,__LINE__,info->device_name); + __FILE__, __LINE__, info->device_name); return -ENOMEM; } } @@ -1298,15 +1295,15 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) retval = claim_resources(info); /* perform existence check and diagnostics */ - if ( !retval ) + if (!retval) retval = adapter_test(info); - if ( retval ) { - if (capable(CAP_SYS_ADMIN) && tty) + if (retval) { + if (capable(CAP_SYS_ADMIN) && tty) set_bit(TTY_IO_ERROR, &tty->flags); release_resources(info); - return retval; - } + return retval; + } /* program hardware for current parameters */ mgslpc_change_params(info, tty); @@ -1330,7 +1327,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_shutdown(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); /* clear status wait queue because status changes */ /* can't happen after shutting down the hardware */ @@ -1344,7 +1341,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) info->tx_buf = NULL; } - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); rx_stop(info); tx_stop(info); @@ -1352,12 +1349,12 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) /* TODO:disable interrupts instead of reset to preserve signal states */ reset_device(info); - if (!tty || tty->termios.c_cflag & HUPCL) { - info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS); + if (!tty || tty->termios.c_cflag & HUPCL) { + info->serial_signals &= ~(SerialSignal_RTS | SerialSignal_DTR); set_signals(info); } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); release_resources(info); @@ -1371,7 +1368,7 @@ static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty) { unsigned long flags; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); rx_stop(info); tx_stop(info); @@ -1396,7 +1393,7 @@ static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty) if (info->netcount || (tty && (tty->termios.c_cflag & CREAD))) rx_start(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); } /* Reconfigure adapter based on new parameters @@ -1411,16 +1408,16 @@ static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_change_params(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); cflag = tty->termios.c_cflag; - /* if B0 rate (hangup) specified then negate DTR and RTS */ - /* otherwise assert DTR and RTS */ - if (cflag & CBAUD) - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + /* if B0 rate (hangup) specified then negate RTS and DTR */ + /* otherwise assert RTS and DTR */ + if (cflag & CBAUD) + info->serial_signals |= SerialSignal_RTS | SerialSignal_DTR; else - info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); + info->serial_signals &= ~(SerialSignal_RTS | SerialSignal_DTR); /* byte size and parity */ @@ -1463,7 +1460,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty) info->params.data_rate = tty_get_baud_rate(tty); } - if ( info->params.data_rate ) { + if (info->params.data_rate) { info->timeout = (32*HZ*bits_per_char) / info->params.data_rate; } @@ -1498,8 +1495,8 @@ static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch) unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) { - printk( "%s(%d):mgslpc_put_char(%d) on %s\n", - __FILE__,__LINE__,ch,info->device_name); + printk("%s(%d):mgslpc_put_char(%d) on %s\n", + __FILE__, __LINE__, ch, info->device_name); } if (mgslpc_paranoia_check(info, tty->name, "mgslpc_put_char")) @@ -1508,7 +1505,7 @@ static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch) if (!info->tx_buf) return 0; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (info->params.mode == MGSL_MODE_ASYNC || !info->tx_active) { if (info->tx_count < TXBUFSIZE - 1) { @@ -1518,7 +1515,7 @@ static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch) } } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 1; } @@ -1531,8 +1528,8 @@ static void mgslpc_flush_chars(struct tty_struct *tty) unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk( "%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n", - __FILE__,__LINE__,info->device_name,info->tx_count); + printk("%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n", + __FILE__, __LINE__, info->device_name, info->tx_count); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars")) return; @@ -1542,13 +1539,13 @@ static void mgslpc_flush_chars(struct tty_struct *tty) return; if (debug_level >= DEBUG_LEVEL_INFO) - printk( "%s(%d):mgslpc_flush_chars() entry on %s starting transmitter\n", - __FILE__,__LINE__,info->device_name); + printk("%s(%d):mgslpc_flush_chars() entry on %s starting transmitter\n", + __FILE__, __LINE__, info->device_name); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (!info->tx_active) - tx_start(info, tty); - spin_unlock_irqrestore(&info->lock,flags); + tx_start(info, tty); + spin_unlock_irqrestore(&info->lock, flags); } /* Send a block of data @@ -1569,8 +1566,8 @@ static int mgslpc_write(struct tty_struct * tty, unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk( "%s(%d):mgslpc_write(%s) count=%d\n", - __FILE__,__LINE__,info->device_name,count); + printk("%s(%d):mgslpc_write(%s) count=%d\n", + __FILE__, __LINE__, info->device_name, count); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_write") || !info->tx_buf) @@ -1596,26 +1593,26 @@ static int mgslpc_write(struct tty_struct * tty, memcpy(info->tx_buf + info->tx_put, buf, c); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); info->tx_put = (info->tx_put + c) & (TXBUFSIZE-1); info->tx_count += c; - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); buf += c; count -= c; ret += c; } start: - if (info->tx_count && !tty->stopped && !tty->hw_stopped) { - spin_lock_irqsave(&info->lock,flags); + if (info->tx_count && !tty->stopped && !tty->hw_stopped) { + spin_lock_irqsave(&info->lock, flags); if (!info->tx_active) - tx_start(info, tty); - spin_unlock_irqrestore(&info->lock,flags); - } + tx_start(info, tty); + spin_unlock_irqrestore(&info->lock, flags); + } cleanup: if (debug_level >= DEBUG_LEVEL_INFO) - printk( "%s(%d):mgslpc_write(%s) returning=%d\n", - __FILE__,__LINE__,info->device_name,ret); + printk("%s(%d):mgslpc_write(%s) returning=%d\n", + __FILE__, __LINE__, info->device_name, ret); return ret; } @@ -1643,7 +1640,7 @@ static int mgslpc_write_room(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_write_room(%s)=%d\n", - __FILE__,__LINE__, info->device_name, ret); + __FILE__, __LINE__, info->device_name, ret); return ret; } @@ -1656,7 +1653,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_chars_in_buffer(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_chars_in_buffer")) return 0; @@ -1668,7 +1665,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n", - __FILE__,__LINE__, info->device_name, rc); + __FILE__, __LINE__, info->device_name, rc); return rc; } @@ -1682,15 +1679,15 @@ static void mgslpc_flush_buffer(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_flush_buffer(%s) entry\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_buffer")) return; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); info->tx_count = info->tx_put = info->tx_get = 0; del_timer(&info->tx_timer); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); wake_up_interruptible(&tty->write_wait); tty_wakeup(tty); @@ -1705,17 +1702,17 @@ static void mgslpc_send_xchar(struct tty_struct *tty, char ch) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_send_xchar(%s,%d)\n", - __FILE__,__LINE__, info->device_name, ch ); + __FILE__, __LINE__, info->device_name, ch); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_send_xchar")) return; info->x_char = ch; if (ch) { - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (!info->tx_enabled) - tx_start(info, tty); - spin_unlock_irqrestore(&info->lock,flags); + tx_start(info, tty); + spin_unlock_irqrestore(&info->lock, flags); } } @@ -1728,7 +1725,7 @@ static void mgslpc_throttle(struct tty_struct * tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_throttle(%s) entry\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_throttle")) return; @@ -1736,11 +1733,11 @@ static void mgslpc_throttle(struct tty_struct * tty) if (I_IXOFF(tty)) mgslpc_send_xchar(tty, STOP_CHAR(tty)); - if (tty->termios.c_cflag & CRTSCTS) { - spin_lock_irqsave(&info->lock,flags); + if (tty->termios.c_cflag & CRTSCTS) { + spin_lock_irqsave(&info->lock, flags); info->serial_signals &= ~SerialSignal_RTS; - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + set_signals(info); + spin_unlock_irqrestore(&info->lock, flags); } } @@ -1753,7 +1750,7 @@ static void mgslpc_unthrottle(struct tty_struct * tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_unthrottle(%s) entry\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_unthrottle")) return; @@ -1765,11 +1762,11 @@ static void mgslpc_unthrottle(struct tty_struct * tty) mgslpc_send_xchar(tty, START_CHAR(tty)); } - if (tty->termios.c_cflag & CRTSCTS) { - spin_lock_irqsave(&info->lock,flags); + if (tty->termios.c_cflag & CRTSCTS) { + spin_lock_irqsave(&info->lock, flags); info->serial_signals |= SerialSignal_RTS; - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + set_signals(info); + spin_unlock_irqrestore(&info->lock, flags); } } @@ -1807,33 +1804,33 @@ static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params) * * Arguments: * - * info pointer to device instance data - * new_params user buffer containing new serial params + * info pointer to device instance data + * new_params user buffer containing new serial params * * Returns: 0 if success, otherwise error code */ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct tty_struct *tty) { - unsigned long flags; + unsigned long flags; MGSL_PARAMS tmp_params; int err; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):set_params %s\n", __FILE__,__LINE__, - info->device_name ); + info->device_name); COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS)); if (err) { - if ( debug_level >= DEBUG_LEVEL_INFO ) - printk( "%s(%d):set_params(%s) user buffer copy failed\n", - __FILE__,__LINE__,info->device_name); + if (debug_level >= DEBUG_LEVEL_INFO) + printk("%s(%d):set_params(%s) user buffer copy failed\n", + __FILE__, __LINE__, info->device_name); return -EFAULT; } - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS)); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); - mgslpc_change_params(info, tty); + mgslpc_change_params(info, tty); return 0; } @@ -1851,13 +1848,13 @@ static int get_txidle(MGSLPC_INFO * info, int __user *idle_mode) static int set_txidle(MGSLPC_INFO * info, int idle_mode) { - unsigned long flags; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("set_txidle(%s,%d)\n", info->device_name, idle_mode); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); info->idle_mode = idle_mode; tx_set_idle(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } @@ -1874,11 +1871,11 @@ static int get_interface(MGSLPC_INFO * info, int __user *if_mode) static int set_interface(MGSLPC_INFO * info, int if_mode) { - unsigned long flags; + unsigned long flags; unsigned char val; if (debug_level >= DEBUG_LEVEL_INFO) printk("set_interface(%s,%d)\n", info->device_name, if_mode); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); info->if_mode = if_mode; val = read_reg(info, PVR) & 0x0f; @@ -1890,18 +1887,18 @@ static int set_interface(MGSLPC_INFO * info, int if_mode) } write_reg(info, PVR, val); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty) { - unsigned long flags; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("set_txenable(%s,%d)\n", info->device_name, enable); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (enable) { if (!info->tx_enabled) tx_start(info, tty); @@ -1909,18 +1906,18 @@ static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty) if (info->tx_enabled) tx_stop(info); } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } static int tx_abort(MGSLPC_INFO * info) { - unsigned long flags; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("tx_abort(%s)\n", info->device_name); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (info->tx_active && info->tx_count && info->params.mode == MGSL_MODE_HDLC) { /* clear data count so FIFO is not filled on next IRQ. @@ -1929,18 +1926,18 @@ static int tx_abort(MGSLPC_INFO * info) info->tx_count = info->tx_put = info->tx_get = 0; info->tx_aborting = true; } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } static int set_rxenable(MGSLPC_INFO * info, int enable) { - unsigned long flags; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("set_rxenable(%s,%d)\n", info->device_name, enable); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (enable) { if (!info->rx_enabled) rx_start(info); @@ -1948,21 +1945,21 @@ static int set_rxenable(MGSLPC_INFO * info, int enable) if (info->rx_enabled) rx_stop(info); } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } /* wait for specified event to occur * - * Arguments: info pointer to device instance data - * mask pointer to bitmask of events to wait for - * Return Value: 0 if successful and bit mask updated with + * Arguments: info pointer to device instance data + * mask pointer to bitmask of events to wait for + * Return Value: 0 if successful and bit mask updated with * of events triggerred, - * otherwise error code + * otherwise error code */ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr) { - unsigned long flags; + unsigned long flags; int s; int rc=0; struct mgsl_icount cprev, cnow; @@ -1978,18 +1975,18 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr) if (debug_level >= DEBUG_LEVEL_INFO) printk("wait_events(%s,%d)\n", info->device_name, mask); - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); /* return immediately if state matches requested events */ get_signals(info); s = info->serial_signals; events = mask & ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) + - ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) + + ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) + ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) + ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) ); if (events) { - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); goto exit; } @@ -2004,7 +2001,7 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr) set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&info->event_wait_q, &wait); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); for(;;) { @@ -2015,11 +2012,11 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr) } /* get current irq counts */ - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); cnow = info->icount; newsigs = info->input_signal_events; set_current_state(TASK_INTERRUPTIBLE); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); /* if no change, wait aborted for some reason */ if (newsigs.dsr_up == oldsigs.dsr_up && @@ -2058,10 +2055,10 @@ static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr) set_current_state(TASK_RUNNING); if (mask & MgslEvent_ExitHuntMode) { - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (!waitqueue_active(&info->event_wait_q)) irq_disable(info, CHA, IRQ_EXITHUNT); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); } exit: if (rc == 0) @@ -2071,17 +2068,17 @@ exit: static int modem_input_wait(MGSLPC_INFO *info,int arg) { - unsigned long flags; + unsigned long flags; int rc; struct mgsl_icount cprev, cnow; DECLARE_WAITQUEUE(wait, current); /* save current irq counts */ - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); cprev = info->icount; add_wait_queue(&info->status_event_wait_q, &wait); set_current_state(TASK_INTERRUPTIBLE); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); for(;;) { schedule(); @@ -2091,10 +2088,10 @@ static int modem_input_wait(MGSLPC_INFO *info,int arg) } /* get new irq counts */ - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); cnow = info->icount; set_current_state(TASK_INTERRUPTIBLE); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); /* if no change, wait aborted for some reason */ if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && @@ -2125,11 +2122,11 @@ static int tiocmget(struct tty_struct *tty) { MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; unsigned int result; - unsigned long flags; + unsigned long flags; - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock, flags); result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) + ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) + @@ -2140,7 +2137,7 @@ static int tiocmget(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s tiocmget() value=%08X\n", - __FILE__,__LINE__, info->device_name, result ); + __FILE__, __LINE__, info->device_name, result); return result; } @@ -2150,11 +2147,11 @@ static int tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) { MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; - unsigned long flags; + unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):%s tiocmset(%x,%x)\n", - __FILE__,__LINE__,info->device_name, set, clear); + __FILE__, __LINE__, info->device_name, set, clear); if (set & TIOCM_RTS) info->serial_signals |= SerialSignal_RTS; @@ -2165,9 +2162,9 @@ static int tiocmset(struct tty_struct *tty, if (clear & TIOCM_DTR) info->serial_signals &= ~SerialSignal_DTR; - spin_lock_irqsave(&info->lock,flags); - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); + set_signals(info); + spin_unlock_irqrestore(&info->lock, flags); return 0; } @@ -2184,17 +2181,17 @@ static int mgslpc_break(struct tty_struct *tty, int break_state) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_break(%s,%d)\n", - __FILE__,__LINE__, info->device_name, break_state); + __FILE__, __LINE__, info->device_name, break_state); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break")) return -EINVAL; - spin_lock_irqsave(&info->lock,flags); - if (break_state == -1) + spin_lock_irqsave(&info->lock, flags); + if (break_state == -1) set_reg_bits(info, CHA+DAFO, BIT6); else clear_reg_bits(info, CHA+DAFO, BIT6); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return 0; } @@ -2205,9 +2202,9 @@ static int mgslpc_get_icount(struct tty_struct *tty, struct mgsl_icount cnow; /* kernel counter temps */ unsigned long flags; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); cnow = info->icount; - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); icount->cts = cnow.cts; icount->dsr = cnow.dsr; @@ -2228,9 +2225,9 @@ static int mgslpc_get_icount(struct tty_struct *tty, * * Arguments: * - * tty pointer to tty instance data - * cmd IOCTL command code - * arg command argument/context + * tty pointer to tty instance data + * cmd IOCTL command code + * arg command argument/context * * Return Value: 0 if success, otherwise error code */ @@ -2241,8 +2238,8 @@ static int mgslpc_ioctl(struct tty_struct *tty, void __user *argp = (void __user *)arg; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__, - info->device_name, cmd ); + printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__, __LINE__, + info->device_name, cmd); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_ioctl")) return -ENODEV; @@ -2288,8 +2285,8 @@ static int mgslpc_ioctl(struct tty_struct *tty, * * Arguments: * - * tty pointer to tty structure - * termios pointer to buffer to hold returned old termios + * tty pointer to tty structure + * termios pointer to buffer to hold returned old termios */ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_termios) { @@ -2297,8 +2294,8 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgslpc_set_termios %s\n", __FILE__,__LINE__, - tty->driver->name ); + printk("%s(%d):mgslpc_set_termios %s\n", __FILE__, __LINE__, + tty->driver->name); /* just return if nothing has changed */ if ((tty->termios.c_cflag == old_termios->c_cflag) @@ -2311,23 +2308,23 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term /* Handle transition to B0 status */ if (old_termios->c_cflag & CBAUD && !(tty->termios.c_cflag & CBAUD)) { - info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR); - spin_lock_irqsave(&info->lock,flags); - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + info->serial_signals &= ~(SerialSignal_RTS | SerialSignal_DTR); + spin_lock_irqsave(&info->lock, flags); + set_signals(info); + spin_unlock_irqrestore(&info->lock, flags); } /* Handle transition away from B0 status */ if (!(old_termios->c_cflag & CBAUD) && tty->termios.c_cflag & CBAUD) { info->serial_signals |= SerialSignal_DTR; - if (!(tty->termios.c_cflag & CRTSCTS) || - !test_bit(TTY_THROTTLED, &tty->flags)) { + if (!(tty->termios.c_cflag & CRTSCTS) || + !test_bit(TTY_THROTTLED, &tty->flags)) { info->serial_signals |= SerialSignal_RTS; - } - spin_lock_irqsave(&info->lock,flags); - set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + } + spin_lock_irqsave(&info->lock, flags); + set_signals(info); + spin_unlock_irqrestore(&info->lock, flags); } /* Handle turning off CRTSCTS */ @@ -2348,15 +2345,15 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_close(%s) entry, count=%d\n", - __FILE__,__LINE__, info->device_name, port->count); + __FILE__, __LINE__, info->device_name, port->count); WARN_ON(!port->count); if (tty_port_close_start(port, tty, filp) == 0) goto cleanup; - if (port->flags & ASYNC_INITIALIZED) - mgslpc_wait_until_sent(tty, info->timeout); + if (port->flags & ASYNC_INITIALIZED) + mgslpc_wait_until_sent(tty, info->timeout); mgslpc_flush_buffer(tty); @@ -2367,7 +2364,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp) tty_port_tty_set(port, NULL); cleanup: if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__, + printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__, tty->driver->name, port->count); } @@ -2378,12 +2375,12 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout) MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; unsigned long orig_jiffies, char_time; - if (!info ) + if (!info) return; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_wait_until_sent(%s) entry\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent")) return; @@ -2399,8 +2396,8 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout) * Note: use tight timings here to satisfy the NIST-PCTS. */ - if ( info->params.data_rate ) { - char_time = info->timeout/(32 * 5); + if (info->params.data_rate) { + char_time = info->timeout/(32 * 5); if (!char_time) char_time++; } else @@ -2431,7 +2428,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout) exit: if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_wait_until_sent(%s) exit\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); } /* Called by tty_hangup() when a hangup is signaled. @@ -2443,7 +2440,7 @@ static void mgslpc_hangup(struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_hangup(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (mgslpc_paranoia_check(info, tty->name, "mgslpc_hangup")) return; @@ -2458,9 +2455,9 @@ static int carrier_raised(struct tty_port *port) MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); unsigned long flags; - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock, flags); if (info->serial_signals & SerialSignal_DCD) return 1; @@ -2472,13 +2469,13 @@ static void dtr_rts(struct tty_port *port, int onoff) MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); unsigned long flags; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (onoff) - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + info->serial_signals |= SerialSignal_RTS | SerialSignal_DTR; else - info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR; + info->serial_signals &= ~(SerialSignal_RTS | SerialSignal_DTR); set_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); } @@ -2486,14 +2483,14 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) { MGSLPC_INFO *info; struct tty_port *port; - int retval, line; - unsigned long flags; + int retval, line; + unsigned long flags; /* verify range of specified line number */ line = tty->index; if (line >= mgslpc_device_count) { printk("%s(%d):mgslpc_open with invalid line #%d.\n", - __FILE__,__LINE__,line); + __FILE__, __LINE__, line); return -ENODEV; } @@ -2510,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_open(%s), old ref count = %d\n", - __FILE__,__LINE__,tty->driver->name, port->count); + __FILE__, __LINE__, tty->driver->name, port->count); /* If port is closing, signal caller to try again */ if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){ @@ -2521,7 +2518,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) goto cleanup; } - tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; + port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; spin_lock_irqsave(&info->netlock, flags); if (info->netcount) { @@ -2545,13 +2542,13 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp) if (retval) { if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):block_til_ready(%s) returned %d\n", - __FILE__,__LINE__, info->device_name, retval); + __FILE__, __LINE__, info->device_name, retval); goto cleanup; } if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_open(%s) success\n", - __FILE__,__LINE__, info->device_name); + __FILE__, __LINE__, info->device_name); retval = 0; cleanup: @@ -2571,9 +2568,9 @@ static inline void line_info(struct seq_file *m, MGSLPC_INFO *info) info->device_name, info->io_base, info->irq_level); /* output current serial signal states */ - spin_lock_irqsave(&info->lock,flags); - get_signals(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); + get_signals(info); + spin_unlock_irqrestore(&info->lock, flags); stat_buf[0] = 0; stat_buf[1] = 0; @@ -2635,7 +2632,7 @@ static int mgslpc_proc_show(struct seq_file *m, void *v) seq_printf(m, "synclink driver:%s\n", driver_version); info = mgslpc_device_list; - while( info ) { + while (info) { line_info(m, info); info = info->next_device; } @@ -2674,6 +2671,14 @@ static int rx_alloc_buffers(MGSLPC_INFO *info) if (info->rx_buf == NULL) return -ENOMEM; + /* unused flag buffer to satisfy receive_buf calling interface */ + info->flag_buf = kzalloc(info->max_frame_size, GFP_KERNEL); + if (!info->flag_buf) { + kfree(info->rx_buf); + info->rx_buf = NULL; + return -ENOMEM; + } + rx_reset_buffers(info); return 0; } @@ -2682,12 +2687,14 @@ static void rx_free_buffers(MGSLPC_INFO *info) { kfree(info->rx_buf); info->rx_buf = NULL; + kfree(info->flag_buf); + info->flag_buf = NULL; } static int claim_resources(MGSLPC_INFO *info) { - if (rx_alloc_buffers(info) < 0 ) { - printk( "Can't allocate rx buffer %s\n", info->device_name); + if (rx_alloc_buffers(info) < 0) { + printk("Can't allocate rx buffer %s\n", info->device_name); release_resources(info); return -ENODEV; } @@ -2706,8 +2713,12 @@ static void release_resources(MGSLPC_INFO *info) * * Arguments: info pointer to device instance data */ -static void mgslpc_add_device(MGSLPC_INFO *info) +static int mgslpc_add_device(MGSLPC_INFO *info) { + MGSLPC_INFO *current_dev = NULL; + struct device *tty_dev; + int ret; + info->next_device = NULL; info->line = mgslpc_device_count; sprintf(info->device_name,"ttySLP%d",info->line); @@ -2722,8 +2733,8 @@ static void mgslpc_add_device(MGSLPC_INFO *info) if (!mgslpc_device_list) mgslpc_device_list = info; else { - MGSLPC_INFO *current_dev = mgslpc_device_list; - while( current_dev->next_device ) + current_dev = mgslpc_device_list; + while (current_dev->next_device) current_dev = current_dev->next_device; current_dev->next_device = info; } @@ -2733,14 +2744,34 @@ static void mgslpc_add_device(MGSLPC_INFO *info) else if (info->max_frame_size > 65535) info->max_frame_size = 65535; - printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n", + printk("SyncLink PC Card %s:IO=%04X IRQ=%d\n", info->device_name, info->io_base, info->irq_level); #if SYNCLINK_GENERIC_HDLC - hdlcdev_init(info); + ret = hdlcdev_init(info); + if (ret != 0) + goto failed; #endif - tty_port_register_device(&info->port, serial_driver, info->line, + + tty_dev = tty_port_register_device(&info->port, serial_driver, info->line, &info->p_dev->dev); + if (IS_ERR(tty_dev)) { + ret = PTR_ERR(tty_dev); +#if SYNCLINK_GENERIC_HDLC + hdlcdev_exit(info); +#endif + goto failed; + } + + return 0; + +failed: + if (current_dev) + current_dev->next_device = NULL; + else + mgslpc_device_list = NULL; + mgslpc_device_count--; + return ret; } static void mgslpc_remove_device(MGSLPC_INFO *remove_info) @@ -3262,7 +3293,7 @@ static void rx_stop(MGSLPC_INFO *info) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):rx_stop(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); /* MODE:03 RAC Receiver Active, 0=inactive */ clear_reg_bits(info, CHA + MODE, BIT3); @@ -3275,7 +3306,7 @@ static void rx_start(MGSLPC_INFO *info) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):rx_start(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); rx_reset_buffers(info); info->rx_enabled = false; @@ -3291,7 +3322,7 @@ static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):tx_start(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); if (info->tx_count) { /* If auto RTS enabled and RTS is inactive, then assert */ @@ -3329,7 +3360,7 @@ static void tx_stop(MGSLPC_INFO *info) { if (debug_level >= DEBUG_LEVEL_ISR) printk("%s(%d):tx_stop(%s)\n", - __FILE__,__LINE__, info->device_name ); + __FILE__, __LINE__, info->device_name); del_timer(&info->tx_timer); @@ -3575,8 +3606,8 @@ static void get_signals(MGSLPC_INFO *info) { unsigned char status = 0; - /* preserve DTR and RTS */ - info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS; + /* preserve RTS and DTR */ + info->serial_signals &= SerialSignal_RTS | SerialSignal_DTR; if (read_reg(info, CHB + VSTR) & BIT7) info->serial_signals |= SerialSignal_DCD; @@ -3590,7 +3621,7 @@ static void get_signals(MGSLPC_INFO *info) info->serial_signals |= SerialSignal_DSR; } -/* Set the state of DTR and RTS based on contents of +/* Set the state of RTS and DTR based on contents of * serial_signals member of device extension. */ static void set_signals(MGSLPC_INFO *info) @@ -3681,7 +3712,7 @@ static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty) if (debug_level >= DEBUG_LEVEL_BH) printk("%s(%d):rx_get_frame(%s) status=%04X size=%d\n", - __FILE__,__LINE__,info->device_name,status,framesize); + __FILE__, __LINE__, info->device_name, status, framesize); if (debug_level >= DEBUG_LEVEL_DATA) trace_block(info, buf->data, framesize, 0); @@ -3709,13 +3740,13 @@ static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty) } } - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); buf->status = buf->count = 0; info->rx_frame_count--; info->rx_get++; if (info->rx_get >= info->rx_buf_count) info->rx_get = 0; - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return true; } @@ -3729,7 +3760,7 @@ static bool register_test(MGSLPC_INFO *info) bool rc = true; unsigned long flags; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); reset_device(info); for (i = 0; i < count; i++) { @@ -3742,7 +3773,7 @@ static bool register_test(MGSLPC_INFO *info) } } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return rc; } @@ -3751,7 +3782,7 @@ static bool irq_test(MGSLPC_INFO *info) unsigned long end_time; unsigned long flags; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); reset_device(info); info->testing_irq = true; @@ -3765,7 +3796,7 @@ static bool irq_test(MGSLPC_INFO *info) write_reg(info, CHA + TIMR, 0); /* 512 cycles */ issue_command(info, CHA, CMD_START_TIMER); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); end_time=100; while(end_time-- && !info->irq_occurred) { @@ -3774,9 +3805,9 @@ static bool irq_test(MGSLPC_INFO *info) info->testing_irq = false; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); reset_device(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return info->irq_occurred; } @@ -3785,21 +3816,21 @@ static int adapter_test(MGSLPC_INFO *info) { if (!register_test(info)) { info->init_error = DiagStatus_AddressFailure; - printk( "%s(%d):Register test failure for device %s Addr=%04X\n", - __FILE__,__LINE__,info->device_name, (unsigned short)(info->io_base) ); + printk("%s(%d):Register test failure for device %s Addr=%04X\n", + __FILE__, __LINE__, info->device_name, (unsigned short)(info->io_base)); return -ENODEV; } if (!irq_test(info)) { info->init_error = DiagStatus_IrqFailure; - printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n", - __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) ); + printk("%s(%d):Interrupt test failure for device %s IRQ=%d\n", + __FILE__, __LINE__, info->device_name, (unsigned short)(info->irq_level)); return -ENODEV; } if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):device %s passed diagnostics\n", - __FILE__,__LINE__,info->device_name); + __FILE__, __LINE__, info->device_name); return 0; } @@ -3808,9 +3839,9 @@ static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit) int i; int linecount; if (xmit) - printk("%s tx data:\n",info->device_name); + printk("%s tx data:\n", info->device_name); else - printk("%s rx data:\n",info->device_name); + printk("%s rx data:\n", info->device_name); while(count) { if (count > 16) @@ -3819,12 +3850,12 @@ static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit) linecount = count; for(i=0;i<linecount;i++) - printk("%02X ",(unsigned char)data[i]); + printk("%02X ", (unsigned char)data[i]); for(;i<17;i++) printk(" "); for(i=0;i<linecount;i++) { if (data[i]>=040 && data[i]<=0176) - printk("%c",data[i]); + printk("%c", data[i]); else printk("."); } @@ -3843,18 +3874,18 @@ static void tx_timeout(unsigned long context) MGSLPC_INFO *info = (MGSLPC_INFO*)context; unsigned long flags; - if ( debug_level >= DEBUG_LEVEL_INFO ) - printk( "%s(%d):tx_timeout(%s)\n", - __FILE__,__LINE__,info->device_name); - if(info->tx_active && - info->params.mode == MGSL_MODE_HDLC) { + if (debug_level >= DEBUG_LEVEL_INFO) + printk("%s(%d):tx_timeout(%s)\n", + __FILE__, __LINE__, info->device_name); + if (info->tx_active && + info->params.mode == MGSL_MODE_HDLC) { info->icount.txtimeout++; } - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); info->tx_active = false; info->tx_count = info->tx_put = info->tx_get = 0; - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); #if SYNCLINK_GENERIC_HDLC if (info->netcount) @@ -3936,7 +3967,7 @@ static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb, unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk(KERN_INFO "%s:hdlc_xmit(%s)\n",__FILE__,dev->name); + printk(KERN_INFO "%s:hdlc_xmit(%s)\n", __FILE__, dev->name); /* stop sending until this frame completes */ netif_stop_queue(dev); @@ -3957,13 +3988,13 @@ static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb, dev->trans_start = jiffies; /* start hardware transmitter if necessary */ - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); if (!info->tx_active) { struct tty_struct *tty = tty_port_tty_get(&info->port); - tx_start(info, tty); - tty_kref_put(tty); + tx_start(info, tty); + tty_kref_put(tty); } - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); return NETDEV_TX_OK; } @@ -3984,10 +4015,11 @@ static int hdlcdev_open(struct net_device *dev) unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s:hdlcdev_open(%s)\n",__FILE__,dev->name); + printk("%s:hdlcdev_open(%s)\n", __FILE__, dev->name); /* generic HDLC layer open processing */ - if ((rc = hdlc_open(dev))) + rc = hdlc_open(dev); + if (rc != 0) return rc; /* arbitrate between network and tty opens */ @@ -4002,15 +4034,16 @@ static int hdlcdev_open(struct net_device *dev) tty = tty_port_tty_get(&info->port); /* claim resources and init adapter */ - if ((rc = startup(info, tty)) != 0) { + rc = startup(info, tty); + if (rc != 0) { tty_kref_put(tty); spin_lock_irqsave(&info->netlock, flags); info->netcount=0; spin_unlock_irqrestore(&info->netlock, flags); return rc; } - /* assert DTR and RTS, apply hardware settings */ - info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; + /* assert RTS and DTR, apply hardware settings */ + info->serial_signals |= SerialSignal_RTS | SerialSignal_DTR; mgslpc_program_hw(info, tty); tty_kref_put(tty); @@ -4044,7 +4077,7 @@ static int hdlcdev_close(struct net_device *dev) unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s:hdlcdev_close(%s)\n",__FILE__,dev->name); + printk("%s:hdlcdev_close(%s)\n", __FILE__, dev->name); netif_stop_queue(dev); @@ -4078,7 +4111,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) unsigned int flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name); + printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name); /* return error if TTY interface open */ if (info->port.count) @@ -4179,14 +4212,14 @@ static void hdlcdev_tx_timeout(struct net_device *dev) unsigned long flags; if (debug_level >= DEBUG_LEVEL_INFO) - printk("hdlcdev_tx_timeout(%s)\n",dev->name); + printk("hdlcdev_tx_timeout(%s)\n", dev->name); dev->stats.tx_errors++; dev->stats.tx_aborted_errors++; - spin_lock_irqsave(&info->lock,flags); + spin_lock_irqsave(&info->lock, flags); tx_stop(info); - spin_unlock_irqrestore(&info->lock,flags); + spin_unlock_irqrestore(&info->lock, flags); netif_wake_queue(dev); } @@ -4217,7 +4250,7 @@ static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size) struct net_device *dev = info->netdev; if (debug_level >= DEBUG_LEVEL_INFO) - printk("hdlcdev_rx(%s)\n",dev->name); + printk("hdlcdev_rx(%s)\n", dev->name); if (skb == NULL) { printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name); @@ -4260,8 +4293,9 @@ static int hdlcdev_init(MGSLPC_INFO *info) /* allocate and initialize network and HDLC layer objects */ - if (!(dev = alloc_hdlcdev(info))) { - printk(KERN_ERR "%s:hdlc device allocation failure\n",__FILE__); + dev = alloc_hdlcdev(info); + if (dev == NULL) { + printk(KERN_ERR "%s:hdlc device allocation failure\n", __FILE__); return -ENOMEM; } @@ -4280,8 +4314,9 @@ static int hdlcdev_init(MGSLPC_INFO *info) hdlc->xmit = hdlcdev_xmit; /* register objects with HDLC layer */ - if ((rc = register_hdlc_device(dev))) { - printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__); + rc = register_hdlc_device(dev); + if (rc) { + printk(KERN_WARNING "%s:unable to register hdlc device\n", __FILE__); free_netdev(dev); return rc; } diff --git a/drivers/char/random.c b/drivers/char/random.c index 85e81ec1451e..594bda9dcfc8 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -445,7 +445,7 @@ static struct entropy_store input_pool = { .poolinfo = &poolinfo_table[0], .name = "input", .limit = 1, - .lock = __SPIN_LOCK_UNLOCKED(&input_pool.lock), + .lock = __SPIN_LOCK_UNLOCKED(input_pool.lock), .pool = input_pool_data }; @@ -454,7 +454,7 @@ static struct entropy_store blocking_pool = { .name = "blocking", .limit = 1, .pull = &input_pool, - .lock = __SPIN_LOCK_UNLOCKED(&blocking_pool.lock), + .lock = __SPIN_LOCK_UNLOCKED(blocking_pool.lock), .pool = blocking_pool_data }; @@ -462,7 +462,7 @@ static struct entropy_store nonblocking_pool = { .poolinfo = &poolinfo_table[1], .name = "nonblocking", .pull = &input_pool, - .lock = __SPIN_LOCK_UNLOCKED(&nonblocking_pool.lock), + .lock = __SPIN_LOCK_UNLOCKED(nonblocking_pool.lock), .pool = nonblocking_pool_data }; diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig index 915875e431d2..dbfd56446c31 100644 --- a/drivers/char/tpm/Kconfig +++ b/drivers/char/tpm/Kconfig @@ -75,10 +75,20 @@ config TCG_INFINEON config TCG_IBMVTPM tristate "IBM VTPM Interface" - depends on PPC64 + depends on PPC_PSERIES ---help--- If you have IBM virtual TPM (VTPM) support say Yes and it will be accessible from within Linux. To compile this driver as a module, choose M here; the module will be called tpm_ibmvtpm. +config TCG_ST33_I2C + tristate "STMicroelectronics ST33 I2C TPM" + depends on I2C + depends on GPIOLIB + ---help--- + If you have a TPM security chip from STMicroelectronics working with + an I2C bus say Yes and it will be accessible from within Linux. + To compile this driver as a module, choose M here; the module will be + called tpm_stm_st33_i2c. + endif # TCG_TPM diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index 5b3fc8bc6c13..a3736c97c65a 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_TCG_NSC) += tpm_nsc.o obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o +obj-$(CONFIG_TCG_ST33_I2C) += tpm_i2c_stm_st33.o diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 93211df52aab..0d2e82f95577 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c @@ -40,8 +40,9 @@ enum tpm_duration { }; #define TPM_MAX_ORDINAL 243 -#define TPM_MAX_PROTECTED_ORDINAL 12 -#define TPM_PROTECTED_ORDINAL_MASK 0xFF +#define TSC_MAX_ORDINAL 12 +#define TPM_PROTECTED_COMMAND 0x00 +#define TPM_CONNECTION_COMMAND 0x40 /* * Bug workaround - some TPM's don't flush the most @@ -65,21 +66,6 @@ static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES); * values of the SHORT, MEDIUM, and LONG durations are retrieved * from the chip during initialization with a call to tpm_get_timeouts. */ -static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = { - TPM_UNDEFINED, /* 0 */ - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_UNDEFINED, /* 5 */ - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_UNDEFINED, - TPM_SHORT, /* 10 */ - TPM_SHORT, -}; - static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = { TPM_UNDEFINED, /* 0 */ TPM_UNDEFINED, @@ -351,14 +337,11 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, { int duration_idx = TPM_UNDEFINED; int duration = 0; + u8 category = (ordinal >> 24) & 0xFF; - if (ordinal < TPM_MAX_ORDINAL) + if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) || + (category == TPM_CONNECTION_COMMAND && ordinal < TSC_MAX_ORDINAL)) duration_idx = tpm_ordinal_duration[ordinal]; - else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) < - TPM_MAX_PROTECTED_ORDINAL) - duration_idx = - tpm_protected_ordinal_duration[ordinal & - TPM_PROTECTED_ORDINAL_MASK]; if (duration_idx != TPM_UNDEFINED) duration = chip->vendor.duration[duration_idx]; @@ -410,7 +393,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, chip->vendor.req_complete_val) goto out_recv; - if ((status == chip->vendor.req_canceled)) { + if (chip->vendor.req_canceled(chip, status)) { dev_err(chip->dev, "Operation Canceled\n"); rc = -ECANCELED; goto out; @@ -468,7 +451,7 @@ static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd, return -EFAULT; err = be32_to_cpu(cmd->header.out.return_code); - if (err != 0) + if (err != 0 && desc) dev_err(chip->dev, "A TPM error (%d) occurred %s\n", err, desc); return err; @@ -528,6 +511,25 @@ void tpm_gen_interrupt(struct tpm_chip *chip) } EXPORT_SYMBOL_GPL(tpm_gen_interrupt); +#define TPM_ORD_STARTUP cpu_to_be32(153) +#define TPM_ST_CLEAR cpu_to_be16(1) +#define TPM_ST_STATE cpu_to_be16(2) +#define TPM_ST_DEACTIVATED cpu_to_be16(3) +static const struct tpm_input_header tpm_startup_header = { + .tag = TPM_TAG_RQU_COMMAND, + .length = cpu_to_be32(12), + .ordinal = TPM_ORD_STARTUP +}; + +static int tpm_startup(struct tpm_chip *chip, __be16 startup_type) +{ + struct tpm_cmd_t start_cmd; + start_cmd.header.in = tpm_startup_header; + start_cmd.params.startup_in.startup_type = startup_type; + return transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE, + "attempting to start the TPM"); +} + int tpm_get_timeouts(struct tpm_chip *chip) { struct tpm_cmd_t tpm_cmd; @@ -541,11 +543,28 @@ int tpm_get_timeouts(struct tpm_chip *chip) tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; + rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL); - rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, - "attempting to determine the timeouts"); - if (rc) + if (rc == TPM_ERR_INVALID_POSTINIT) { + /* The TPM is not started, we are the first to talk to it. + Execute a startup command. */ + dev_info(chip->dev, "Issuing TPM_STARTUP"); + if (tpm_startup(chip, TPM_ST_CLEAR)) + return rc; + + tpm_cmd.header.in = tpm_getcap_header; + tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; + tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); + tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; + rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, + NULL); + } + if (rc) { + dev_err(chip->dev, + "A TPM error (%zd) occurred attempting to determine the timeouts\n", + rc); goto duration; + } if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 || be32_to_cpu(tpm_cmd.header.out.length) @@ -824,7 +843,7 @@ int tpm_do_selftest(struct tpm_chip *chip) { int rc; unsigned int loops; - unsigned int delay_msec = 1000; + unsigned int delay_msec = 100; unsigned long duration; struct tpm_cmd_t cmd; @@ -845,6 +864,14 @@ int tpm_do_selftest(struct tpm_chip *chip) cmd.header.in = pcrread_header; cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0); rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); + /* Some buggy TPMs will not respond to tpm_tis_ready() for + * around 300ms while the self test is ongoing, keep trying + * until the self test duration expires. */ + if (rc == -ETIME) { + dev_info(chip->dev, HW_ERR "TPM command timed out during continue self test"); + msleep(delay_msec); + continue; + } if (rc < TPM_HEADER_SIZE) return -EFAULT; @@ -1075,12 +1102,28 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, } EXPORT_SYMBOL_GPL(tpm_store_cancel); +static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask, bool check_cancel, + bool *canceled) +{ + u8 status = chip->vendor.status(chip); + + *canceled = false; + if ((status & mask) == mask) + return true; + if (check_cancel && chip->vendor.req_canceled(chip, status)) { + *canceled = true; + return true; + } + return false; +} + int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, - wait_queue_head_t *queue) + wait_queue_head_t *queue, bool check_cancel) { unsigned long stop; long rc; u8 status; + bool canceled = false; /* check current status */ status = chip->vendor.status(chip); @@ -1095,11 +1138,14 @@ again: if ((long)timeout <= 0) return -ETIME; rc = wait_event_interruptible_timeout(*queue, - ((chip->vendor.status(chip) - & mask) == mask), - timeout); - if (rc > 0) + wait_for_tpm_stat_cond(chip, mask, check_cancel, + &canceled), + timeout); + if (rc > 0) { + if (canceled) + return -ECANCELED; return 0; + } if (rc == -ERESTARTSYS && freezing(current)) { clear_thread_flag(TIF_SIGPENDING); goto again; diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 8ef7649a50aa..81b52015f669 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -47,6 +47,7 @@ enum tpm_addr { #define TPM_WARN_DOING_SELFTEST 0x802 #define TPM_ERR_DEACTIVATED 0x6 #define TPM_ERR_DISABLED 0x7 +#define TPM_ERR_INVALID_POSTINIT 38 #define TPM_HEADER_SIZE 10 extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr, @@ -77,7 +78,7 @@ struct tpm_chip; struct tpm_vendor_specific { const u8 req_complete_mask; const u8 req_complete_val; - const u8 req_canceled; + bool (*req_canceled)(struct tpm_chip *chip, u8 status); void __iomem *iobase; /* ioremapped address */ unsigned long base; /* TPM base address */ @@ -100,13 +101,19 @@ struct tpm_vendor_specific { bool timeout_adjusted; unsigned long duration[3]; /* jiffies */ bool duration_adjusted; - void *data; + void *priv; wait_queue_head_t read_queue; wait_queue_head_t int_queue; + + u16 manufacturer_id; }; +#define TPM_VPRIV(c) (c)->vendor.priv + #define TPM_VID_INTEL 0x8086 +#define TPM_VID_WINBOND 0x1050 +#define TPM_VID_STM 0x104A struct tpm_chip { struct device *dev; /* Device stuff */ @@ -154,13 +161,13 @@ struct tpm_input_header { __be16 tag; __be32 length; __be32 ordinal; -}__attribute__((packed)); +} __packed; struct tpm_output_header { __be16 tag; __be32 length; __be32 return_code; -}__attribute__((packed)); +} __packed; struct stclear_flags_t { __be16 tag; @@ -169,14 +176,14 @@ struct stclear_flags_t { u8 physicalPresence; u8 physicalPresenceLock; u8 bGlobalLock; -}__attribute__((packed)); +} __packed; struct tpm_version_t { u8 Major; u8 Minor; u8 revMajor; u8 revMinor; -}__attribute__((packed)); +} __packed; struct tpm_version_1_2_t { __be16 tag; @@ -184,20 +191,20 @@ struct tpm_version_1_2_t { u8 Minor; u8 revMajor; u8 revMinor; -}__attribute__((packed)); +} __packed; struct timeout_t { __be32 a; __be32 b; __be32 c; __be32 d; -}__attribute__((packed)); +} __packed; struct duration_t { __be32 tpm_short; __be32 tpm_medium; __be32 tpm_long; -}__attribute__((packed)); +} __packed; struct permanent_flags_t { __be16 tag; @@ -221,7 +228,7 @@ struct permanent_flags_t { u8 tpmEstablished; u8 maintenanceDone; u8 disableFullDALogicInfo; -}__attribute__((packed)); +} __packed; typedef union { struct permanent_flags_t perm_flags; @@ -239,12 +246,12 @@ struct tpm_getcap_params_in { __be32 cap; __be32 subcap_size; __be32 subcap; -}__attribute__((packed)); +} __packed; struct tpm_getcap_params_out { __be32 cap_size; cap_t cap; -}__attribute__((packed)); +} __packed; struct tpm_readpubek_params_out { u8 algorithm[4]; @@ -255,7 +262,7 @@ struct tpm_readpubek_params_out { __be32 keysize; u8 modulus[256]; u8 checksum[20]; -}__attribute__((packed)); +} __packed; typedef union { struct tpm_input_header in; @@ -265,16 +272,16 @@ typedef union { #define TPM_DIGEST_SIZE 20 struct tpm_pcrread_out { u8 pcr_result[TPM_DIGEST_SIZE]; -}__attribute__((packed)); +} __packed; struct tpm_pcrread_in { __be32 pcr_idx; -}__attribute__((packed)); +} __packed; struct tpm_pcrextend_in { __be32 pcr_idx; u8 hash[TPM_DIGEST_SIZE]; -}__attribute__((packed)); +} __packed; /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 * bytes, but 128 is still a relatively large number of random bytes and @@ -285,11 +292,15 @@ struct tpm_pcrextend_in { struct tpm_getrandom_out { __be32 rng_data_len; u8 rng_data[TPM_MAX_RNG_DATA]; -}__attribute__((packed)); +} __packed; struct tpm_getrandom_in { __be32 num_bytes; -}__attribute__((packed)); +} __packed; + +struct tpm_startup_in { + __be16 startup_type; +} __packed; typedef union { struct tpm_getcap_params_out getcap_out; @@ -301,12 +312,13 @@ typedef union { struct tpm_pcrextend_in pcrextend_in; struct tpm_getrandom_in getrandom_in; struct tpm_getrandom_out getrandom_out; + struct tpm_startup_in startup_in; } tpm_cmd_params; struct tpm_cmd_t { tpm_cmd_header header; tpm_cmd_params params; -}__attribute__((packed)); +} __packed; ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *); @@ -326,7 +338,7 @@ extern void tpm_remove_hardware(struct device *); extern int tpm_pm_suspend(struct device *); extern int tpm_pm_resume(struct device *); extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long, - wait_queue_head_t *); + wait_queue_head_t *, bool); #ifdef CONFIG_ACPI extern int tpm_add_ppi(struct kobject *); diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c index 56051d0c97a2..64420b3396a2 100644 --- a/drivers/char/tpm/tpm_acpi.c +++ b/drivers/char/tpm/tpm_acpi.c @@ -33,13 +33,13 @@ struct acpi_tcpa { u16 platform_class; union { struct client_hdr { - u32 log_max_len __attribute__ ((packed)); - u64 log_start_addr __attribute__ ((packed)); + u32 log_max_len __packed; + u64 log_start_addr __packed; } client; struct server_hdr { u16 reserved; - u64 log_max_len __attribute__ ((packed)); - u64 log_start_addr __attribute__ ((packed)); + u64 log_max_len __packed; + u64 log_start_addr __packed; } server; }; }; diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c index 678d57019dc4..99d6820c611d 100644 --- a/drivers/char/tpm/tpm_atmel.c +++ b/drivers/char/tpm/tpm_atmel.c @@ -116,6 +116,11 @@ static u8 tpm_atml_status(struct tpm_chip *chip) return ioread8(chip->vendor.iobase + 1); } +static bool tpm_atml_req_canceled(struct tpm_chip *chip, u8 status) +{ + return (status == ATML_STATUS_READY); +} + static const struct file_operations atmel_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -147,7 +152,7 @@ static const struct tpm_vendor_specific tpm_atmel = { .status = tpm_atml_status, .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL, .req_complete_val = ATML_STATUS_DATA_AVAIL, - .req_canceled = ATML_STATUS_READY, + .req_canceled = tpm_atml_req_canceled, .attr_group = &atmel_attr_grp, .miscdev = { .fops = &atmel_ops, }, }; diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c index fb447bd0cb61..8fe7ac3d095b 100644 --- a/drivers/char/tpm/tpm_i2c_infineon.c +++ b/drivers/char/tpm/tpm_i2c_infineon.c @@ -505,6 +505,11 @@ out_err: return rc; } +static bool tpm_tis_i2c_req_canceled(struct tpm_chip *chip, u8 status) +{ + return (status == TPM_STS_COMMAND_READY); +} + static const struct file_operations tis_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -550,7 +555,7 @@ static struct tpm_vendor_specific tpm_tis_i2c = { .cancel = tpm_tis_i2c_ready, .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, - .req_canceled = TPM_STS_COMMAND_READY, + .req_canceled = tpm_tis_i2c_req_canceled, .attr_group = &tis_attr_grp, .miscdev.fops = &tis_ops, }; diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c new file mode 100644 index 000000000000..1f5f71e14abe --- /dev/null +++ b/drivers/char/tpm/tpm_i2c_stm_st33.c @@ -0,0 +1,887 @@ +/* + * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 + * Copyright (C) 2009, 2010 STMicroelectronics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * STMicroelectronics version 1.2.0, Copyright (C) 2010 + * STMicroelectronics comes with ABSOLUTELY NO WARRANTY. + * This is free software, and you are welcome to redistribute it + * under certain conditions. + * + * @Author: Christophe RICARD tpmsupport@st.com + * + * @File: tpm_stm_st33_i2c.c + * + * @Synopsis: + * 09/15/2010: First shot driver tpm_tis driver for + lpc is used as model. + */ + +#include <linux/pci.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/i2c.h> +#include <linux/fs.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/delay.h> +#include <linux/init.h> +#include <linux/wait.h> +#include <linux/string.h> +#include <linux/interrupt.h> +#include <linux/spinlock.h> +#include <linux/sysfs.h> +#include <linux/gpio.h> +#include <linux/sched.h> +#include <linux/uaccess.h> +#include <linux/io.h> +#include <linux/slab.h> +#include <linux/sched.h> + +#include "tpm.h" +#include "tpm_i2c_stm_st33.h" + +enum stm33zp24_access { + TPM_ACCESS_VALID = 0x80, + TPM_ACCESS_ACTIVE_LOCALITY = 0x20, + TPM_ACCESS_REQUEST_PENDING = 0x04, + TPM_ACCESS_REQUEST_USE = 0x02, +}; + +enum stm33zp24_status { + TPM_STS_VALID = 0x80, + TPM_STS_COMMAND_READY = 0x40, + TPM_STS_GO = 0x20, + TPM_STS_DATA_AVAIL = 0x10, + TPM_STS_DATA_EXPECT = 0x08, +}; + +enum stm33zp24_int_flags { + TPM_GLOBAL_INT_ENABLE = 0x80, + TPM_INTF_CMD_READY_INT = 0x080, + TPM_INTF_FIFO_AVALAIBLE_INT = 0x040, + TPM_INTF_WAKE_UP_READY_INT = 0x020, + TPM_INTF_LOCALITY_CHANGE_INT = 0x004, + TPM_INTF_STS_VALID_INT = 0x002, + TPM_INTF_DATA_AVAIL_INT = 0x001, +}; + +enum tis_defaults { + TIS_SHORT_TIMEOUT = 750, + TIS_LONG_TIMEOUT = 2000, +}; + +/* + * write8_reg + * Send byte to the TIS register according to the ST33ZP24 I2C protocol. + * @param: tpm_register, the tpm tis register where the data should be written + * @param: tpm_data, the tpm_data to write inside the tpm_register + * @param: tpm_size, The length of the data + * @return: Returns negative errno, or else the number of bytes written. + */ +static int write8_reg(struct i2c_client *client, u8 tpm_register, + u8 *tpm_data, u16 tpm_size) +{ + struct st33zp24_platform_data *pin_infos; + + pin_infos = client->dev.platform_data; + + pin_infos->tpm_i2c_buffer[0][0] = tpm_register; + memcpy(&pin_infos->tpm_i2c_buffer[0][1], tpm_data, tpm_size); + return i2c_master_send(client, pin_infos->tpm_i2c_buffer[0], + tpm_size + 1); +} /* write8_reg() */ + +/* + * read8_reg + * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. + * @param: tpm_register, the tpm tis register where the data should be read + * @param: tpm_data, the TPM response + * @param: tpm_size, tpm TPM response size to read. + * @return: number of byte read successfully: should be one if success. + */ +static int read8_reg(struct i2c_client *client, u8 tpm_register, + u8 *tpm_data, int tpm_size) +{ + u8 status = 0; + u8 data; + + data = TPM_DUMMY_BYTE; + status = write8_reg(client, tpm_register, &data, 1); + if (status == 2) + status = i2c_master_recv(client, tpm_data, tpm_size); + return status; +} /* read8_reg() */ + +/* + * I2C_WRITE_DATA + * Send byte to the TIS register according to the ST33ZP24 I2C protocol. + * @param: client, the chip description + * @param: tpm_register, the tpm tis register where the data should be written + * @param: tpm_data, the tpm_data to write inside the tpm_register + * @param: tpm_size, The length of the data + * @return: number of byte written successfully: should be one if success. + */ +#define I2C_WRITE_DATA(client, tpm_register, tpm_data, tpm_size) \ + (write8_reg(client, tpm_register | \ + TPM_WRITE_DIRECTION, tpm_data, tpm_size)) + +/* + * I2C_READ_DATA + * Recv byte from the TIS register according to the ST33ZP24 I2C protocol. + * @param: tpm, the chip description + * @param: tpm_register, the tpm tis register where the data should be read + * @param: tpm_data, the TPM response + * @param: tpm_size, tpm TPM response size to read. + * @return: number of byte read successfully: should be one if success. + */ +#define I2C_READ_DATA(client, tpm_register, tpm_data, tpm_size) \ + (read8_reg(client, tpm_register, tpm_data, tpm_size)) + +/* + * clear_interruption + * clear the TPM interrupt register. + * @param: tpm, the chip description + */ +static void clear_interruption(struct i2c_client *client) +{ + u8 interrupt; + I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1); + I2C_WRITE_DATA(client, TPM_INT_STATUS, &interrupt, 1); + I2C_READ_DATA(client, TPM_INT_STATUS, &interrupt, 1); +} /* clear_interruption() */ + +/* + * _wait_for_interrupt_serirq_timeout + * @param: tpm, the chip description + * @param: timeout, the timeout of the interrupt + * @return: the status of the interruption. + */ +static long _wait_for_interrupt_serirq_timeout(struct tpm_chip *chip, + unsigned long timeout) +{ + long status; + struct i2c_client *client; + struct st33zp24_platform_data *pin_infos; + + client = (struct i2c_client *) TPM_VPRIV(chip); + pin_infos = client->dev.platform_data; + + status = wait_for_completion_interruptible_timeout( + &pin_infos->irq_detection, + timeout); + if (status > 0) + enable_irq(gpio_to_irq(pin_infos->io_serirq)); + gpio_direction_input(pin_infos->io_serirq); + + return status; +} /* wait_for_interrupt_serirq_timeout() */ + +static int wait_for_serirq_timeout(struct tpm_chip *chip, bool condition, + unsigned long timeout) +{ + int status = 2; + struct i2c_client *client; + + client = (struct i2c_client *) TPM_VPRIV(chip); + + status = _wait_for_interrupt_serirq_timeout(chip, timeout); + if (!status) { + status = -EBUSY; + } else{ + clear_interruption(client); + if (condition) + status = 1; + } + return status; +} + +/* + * tpm_stm_i2c_cancel, cancel is not implemented. + * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h + */ +static void tpm_stm_i2c_cancel(struct tpm_chip *chip) +{ + struct i2c_client *client; + u8 data; + + client = (struct i2c_client *) TPM_VPRIV(chip); + + data = TPM_STS_COMMAND_READY; + I2C_WRITE_DATA(client, TPM_STS, &data, 1); + if (chip->vendor.irq) + wait_for_serirq_timeout(chip, 1, chip->vendor.timeout_a); +} /* tpm_stm_i2c_cancel() */ + +/* + * tpm_stm_spi_status return the TPM_STS register + * @param: chip, the tpm chip description + * @return: the TPM_STS register value. + */ +static u8 tpm_stm_i2c_status(struct tpm_chip *chip) +{ + struct i2c_client *client; + u8 data; + client = (struct i2c_client *) TPM_VPRIV(chip); + + I2C_READ_DATA(client, TPM_STS, &data, 1); + return data; +} /* tpm_stm_i2c_status() */ + + +/* + * check_locality if the locality is active + * @param: chip, the tpm chip description + * @return: the active locality or -EACCESS. + */ +static int check_locality(struct tpm_chip *chip) +{ + struct i2c_client *client; + u8 data; + u8 status; + + client = (struct i2c_client *) TPM_VPRIV(chip); + + status = I2C_READ_DATA(client, TPM_ACCESS, &data, 1); + if (status && (data & + (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) == + (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) + return chip->vendor.locality; + + return -EACCES; + +} /* check_locality() */ + +/* + * request_locality request the TPM locality + * @param: chip, the chip description + * @return: the active locality or EACCESS. + */ +static int request_locality(struct tpm_chip *chip) +{ + unsigned long stop; + long rc; + struct i2c_client *client; + u8 data; + + client = (struct i2c_client *) TPM_VPRIV(chip); + + if (check_locality(chip) == chip->vendor.locality) + return chip->vendor.locality; + + data = TPM_ACCESS_REQUEST_USE; + rc = I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1); + if (rc < 0) + goto end; + + if (chip->vendor.irq) { + rc = wait_for_serirq_timeout(chip, (check_locality + (chip) >= 0), + chip->vendor.timeout_a); + if (rc > 0) + return chip->vendor.locality; + } else{ + stop = jiffies + chip->vendor.timeout_a; + do { + if (check_locality(chip) >= 0) + return chip->vendor.locality; + msleep(TPM_TIMEOUT); + } while (time_before(jiffies, stop)); + } + rc = -EACCES; +end: + return rc; +} /* request_locality() */ + +/* + * release_locality release the active locality + * @param: chip, the tpm chip description. + */ +static void release_locality(struct tpm_chip *chip) +{ + struct i2c_client *client; + u8 data; + + client = (struct i2c_client *) TPM_VPRIV(chip); + data = TPM_ACCESS_ACTIVE_LOCALITY; + + I2C_WRITE_DATA(client, TPM_ACCESS, &data, 1); +} + +/* + * get_burstcount return the burstcount address 0x19 0x1A + * @param: chip, the chip description + * return: the burstcount. + */ +static int get_burstcount(struct tpm_chip *chip) +{ + unsigned long stop; + int burstcnt, status; + u8 tpm_reg, temp; + + struct i2c_client *client = (struct i2c_client *) TPM_VPRIV(chip); + + stop = jiffies + chip->vendor.timeout_d; + do { + tpm_reg = TPM_STS + 1; + status = I2C_READ_DATA(client, tpm_reg, &temp, 1); + if (status < 0) + goto end; + + tpm_reg = tpm_reg + 1; + burstcnt = temp; + status = I2C_READ_DATA(client, tpm_reg, &temp, 1); + if (status < 0) + goto end; + + burstcnt |= temp << 8; + if (burstcnt) + return burstcnt; + msleep(TPM_TIMEOUT); + } while (time_before(jiffies, stop)); + +end: + return -EBUSY; +} /* get_burstcount() */ + +/* + * wait_for_stat wait for a TPM_STS value + * @param: chip, the tpm chip description + * @param: mask, the value mask to wait + * @param: timeout, the timeout + * @param: queue, the wait queue. + * @return: the tpm status, 0 if success, -ETIME if timeout is reached. + */ +static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, + wait_queue_head_t *queue) +{ + unsigned long stop; + long rc; + u8 status; + + if (chip->vendor.irq) { + rc = wait_for_serirq_timeout(chip, ((tpm_stm_i2c_status + (chip) & mask) == + mask), timeout); + if (rc > 0) + return 0; + } else{ + stop = jiffies + timeout; + do { + msleep(TPM_TIMEOUT); + status = tpm_stm_i2c_status(chip); + if ((status & mask) == mask) + return 0; + } while (time_before(jiffies, stop)); + } + return -ETIME; +} /* wait_for_stat() */ + +/* + * recv_data receive data + * @param: chip, the tpm chip description + * @param: buf, the buffer where the data are received + * @param: count, the number of data to receive + * @return: the number of bytes read from TPM FIFO. + */ +static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) +{ + int size = 0, burstcnt, len; + struct i2c_client *client; + + client = (struct i2c_client *) TPM_VPRIV(chip); + + while (size < count && + wait_for_stat(chip, + TPM_STS_DATA_AVAIL | TPM_STS_VALID, + chip->vendor.timeout_c, + &chip->vendor.read_queue) + == 0) { + burstcnt = get_burstcount(chip); + len = min_t(int, burstcnt, count - size); + I2C_READ_DATA(client, TPM_DATA_FIFO, buf + size, len); + size += len; + } + return size; +} + +/* + * tpm_ioserirq_handler the serirq irq handler + * @param: irq, the tpm chip description + * @param: dev_id, the description of the chip + * @return: the status of the handler. + */ +static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id) +{ + struct tpm_chip *chip = dev_id; + struct i2c_client *client; + struct st33zp24_platform_data *pin_infos; + + disable_irq_nosync(irq); + + client = (struct i2c_client *) TPM_VPRIV(chip); + pin_infos = client->dev.platform_data; + + complete(&pin_infos->irq_detection); + return IRQ_HANDLED; +} /* tpm_ioserirq_handler() */ + + +/* + * tpm_stm_i2c_send send TPM commands through the I2C bus. + * + * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h + * @param: buf, the buffer to send. + * @param: count, the number of bytes to send. + * @return: In case of success the number of bytes sent. + * In other case, a < 0 value describing the issue. + */ +static int tpm_stm_i2c_send(struct tpm_chip *chip, unsigned char *buf, + size_t len) +{ + u32 status, + burstcnt = 0, i, size; + int ret; + u8 data; + struct i2c_client *client; + + if (chip == NULL) + return -EBUSY; + if (len < TPM_HEADER_SIZE) + return -EBUSY; + + client = (struct i2c_client *)TPM_VPRIV(chip); + + client->flags = 0; + + ret = request_locality(chip); + if (ret < 0) + return ret; + + status = tpm_stm_i2c_status(chip); + if ((status & TPM_STS_COMMAND_READY) == 0) { + tpm_stm_i2c_cancel(chip); + if (wait_for_stat + (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, + &chip->vendor.int_queue) < 0) { + ret = -ETIME; + goto out_err; + } + } + + for (i = 0 ; i < len - 1 ;) { + burstcnt = get_burstcount(chip); + size = min_t(int, len - i - 1, burstcnt); + ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf, size); + if (ret < 0) + goto out_err; + + i += size; + } + + status = tpm_stm_i2c_status(chip); + if ((status & TPM_STS_DATA_EXPECT) == 0) { + ret = -EIO; + goto out_err; + } + + ret = I2C_WRITE_DATA(client, TPM_DATA_FIFO, buf + len - 1, 1); + if (ret < 0) + goto out_err; + + status = tpm_stm_i2c_status(chip); + if ((status & TPM_STS_DATA_EXPECT) != 0) { + ret = -EIO; + goto out_err; + } + + data = TPM_STS_GO; + I2C_WRITE_DATA(client, TPM_STS, &data, 1); + + return len; +out_err: + tpm_stm_i2c_cancel(chip); + release_locality(chip); + return ret; +} + +/* + * tpm_stm_i2c_recv received TPM response through the I2C bus. + * @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h. + * @param: buf, the buffer to store datas. + * @param: count, the number of bytes to send. + * @return: In case of success the number of bytes received. + * In other case, a < 0 value describing the issue. + */ +static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf, + size_t count) +{ + int size = 0; + int expected; + + if (chip == NULL) + return -EBUSY; + + if (count < TPM_HEADER_SIZE) { + size = -EIO; + goto out; + } + + size = recv_data(chip, buf, TPM_HEADER_SIZE); + if (size < TPM_HEADER_SIZE) { + dev_err(chip->dev, "Unable to read header\n"); + goto out; + } + + expected = be32_to_cpu(*(__be32 *) (buf + 2)); + if (expected > count) { + size = -EIO; + goto out; + } + + size += recv_data(chip, &buf[TPM_HEADER_SIZE], + expected - TPM_HEADER_SIZE); + if (size < expected) { + dev_err(chip->dev, "Unable to read remainder of result\n"); + size = -ETIME; + goto out; + } + +out: + chip->vendor.cancel(chip); + release_locality(chip); + return size; +} + +static bool tpm_st33_i2c_req_canceled(struct tpm_chip *chip, u8 status) +{ + return (status == TPM_STS_COMMAND_READY); +} + +static const struct file_operations tpm_st33_i2c_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .read = tpm_read, + .write = tpm_write, + .open = tpm_open, + .release = tpm_release, +}; + +static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); +static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); +static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); +static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL); +static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL); +static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated, NULL); +static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL); +static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel); + +static struct attribute *stm_tpm_attrs[] = { + &dev_attr_pubek.attr, + &dev_attr_pcrs.attr, + &dev_attr_enabled.attr, + &dev_attr_active.attr, + &dev_attr_owned.attr, + &dev_attr_temp_deactivated.attr, + &dev_attr_caps.attr, + &dev_attr_cancel.attr, NULL, +}; + +static struct attribute_group stm_tpm_attr_grp = { + .attrs = stm_tpm_attrs +}; + +static struct tpm_vendor_specific st_i2c_tpm = { + .send = tpm_stm_i2c_send, + .recv = tpm_stm_i2c_recv, + .cancel = tpm_stm_i2c_cancel, + .status = tpm_stm_i2c_status, + .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, + .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, + .req_canceled = tpm_st33_i2c_req_canceled, + .attr_group = &stm_tpm_attr_grp, + .miscdev = {.fops = &tpm_st33_i2c_fops,}, +}; + +static int interrupts ; +module_param(interrupts, int, 0444); +MODULE_PARM_DESC(interrupts, "Enable interrupts"); + +static int power_mgt = 1; +module_param(power_mgt, int, 0444); +MODULE_PARM_DESC(power_mgt, "Power Management"); + +/* + * tpm_st33_i2c_probe initialize the TPM device + * @param: client, the i2c_client drescription (TPM I2C description). + * @param: id, the i2c_device_id struct. + * @return: 0 in case of success. + * -1 in other case. + */ +static int +tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + int err; + u8 intmask; + struct tpm_chip *chip; + struct st33zp24_platform_data *platform_data; + + if (client == NULL) { + pr_info("%s: i2c client is NULL. Device not accessible.\n", + __func__); + err = -ENODEV; + goto end; + } + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_info(&client->dev, "client not i2c capable\n"); + err = -ENODEV; + goto end; + } + + chip = tpm_register_hardware(&client->dev, &st_i2c_tpm); + if (!chip) { + dev_info(&client->dev, "fail chip\n"); + err = -ENODEV; + goto end; + } + + platform_data = client->dev.platform_data; + + if (!platform_data) { + dev_info(&client->dev, "chip not available\n"); + err = -ENODEV; + goto _tpm_clean_answer; + } + + platform_data->tpm_i2c_buffer[0] = + kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); + if (platform_data->tpm_i2c_buffer[0] == NULL) { + err = -ENOMEM; + goto _tpm_clean_answer; + } + platform_data->tpm_i2c_buffer[1] = + kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); + if (platform_data->tpm_i2c_buffer[1] == NULL) { + err = -ENOMEM; + goto _tpm_clean_response1; + } + + TPM_VPRIV(chip) = client; + + chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); + chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + + chip->vendor.locality = LOCALITY0; + + if (power_mgt) { + err = gpio_request(platform_data->io_lpcpd, "TPM IO_LPCPD"); + if (err) + goto _gpio_init1; + gpio_set_value(platform_data->io_lpcpd, 1); + } + + if (interrupts) { + init_completion(&platform_data->irq_detection); + if (request_locality(chip) != LOCALITY0) { + err = -ENODEV; + goto _tpm_clean_response2; + } + err = gpio_request(platform_data->io_serirq, "TPM IO_SERIRQ"); + if (err) + goto _gpio_init2; + + clear_interruption(client); + err = request_irq(gpio_to_irq(platform_data->io_serirq), + &tpm_ioserirq_handler, + IRQF_TRIGGER_HIGH, + "TPM SERIRQ management", chip); + if (err < 0) { + dev_err(chip->dev , "TPM SERIRQ signals %d not available\n", + gpio_to_irq(platform_data->io_serirq)); + goto _irq_set; + } + + err = I2C_READ_DATA(client, TPM_INT_ENABLE, &intmask, 1); + if (err < 0) + goto _irq_set; + + intmask |= TPM_INTF_CMD_READY_INT + | TPM_INTF_FIFO_AVALAIBLE_INT + | TPM_INTF_WAKE_UP_READY_INT + | TPM_INTF_LOCALITY_CHANGE_INT + | TPM_INTF_STS_VALID_INT + | TPM_INTF_DATA_AVAIL_INT; + + err = I2C_WRITE_DATA(client, TPM_INT_ENABLE, &intmask, 1); + if (err < 0) + goto _irq_set; + + intmask = TPM_GLOBAL_INT_ENABLE; + err = I2C_WRITE_DATA(client, (TPM_INT_ENABLE + 3), &intmask, 1); + if (err < 0) + goto _irq_set; + + err = I2C_READ_DATA(client, TPM_INT_STATUS, &intmask, 1); + if (err < 0) + goto _irq_set; + + chip->vendor.irq = interrupts; + + tpm_gen_interrupt(chip); + } + + tpm_get_timeouts(chip); + + i2c_set_clientdata(client, chip); + + dev_info(chip->dev, "TPM I2C Initialized\n"); + return 0; +_irq_set: + free_irq(gpio_to_irq(platform_data->io_serirq), (void *) chip); +_gpio_init2: + if (interrupts) + gpio_free(platform_data->io_serirq); +_gpio_init1: + if (power_mgt) + gpio_free(platform_data->io_lpcpd); +_tpm_clean_response2: + kzfree(platform_data->tpm_i2c_buffer[1]); + platform_data->tpm_i2c_buffer[1] = NULL; +_tpm_clean_response1: + kzfree(platform_data->tpm_i2c_buffer[0]); + platform_data->tpm_i2c_buffer[0] = NULL; +_tpm_clean_answer: + tpm_remove_hardware(chip->dev); +end: + pr_info("TPM I2C initialisation fail\n"); + return err; +} + +/* + * tpm_st33_i2c_remove remove the TPM device + * @param: client, the i2c_client drescription (TPM I2C description). + clear_bit(0, &chip->is_open); + * @return: 0 in case of success. + */ +static int tpm_st33_i2c_remove(struct i2c_client *client) +{ + struct tpm_chip *chip = (struct tpm_chip *)i2c_get_clientdata(client); + struct st33zp24_platform_data *pin_infos = + ((struct i2c_client *) TPM_VPRIV(chip))->dev.platform_data; + + if (pin_infos != NULL) { + free_irq(pin_infos->io_serirq, chip); + + gpio_free(pin_infos->io_serirq); + gpio_free(pin_infos->io_lpcpd); + + tpm_remove_hardware(chip->dev); + + if (pin_infos->tpm_i2c_buffer[1] != NULL) { + kzfree(pin_infos->tpm_i2c_buffer[1]); + pin_infos->tpm_i2c_buffer[1] = NULL; + } + if (pin_infos->tpm_i2c_buffer[0] != NULL) { + kzfree(pin_infos->tpm_i2c_buffer[0]); + pin_infos->tpm_i2c_buffer[0] = NULL; + } + } + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +/* + * tpm_st33_i2c_pm_suspend suspend the TPM device + * Added: Work around when suspend and no tpm application is running, suspend + * may fail because chip->data_buffer is not set (only set in tpm_open in Linux + * TPM core) + * @param: client, the i2c_client drescription (TPM I2C description). + * @param: mesg, the power management message. + * @return: 0 in case of success. + */ +static int tpm_st33_i2c_pm_suspend(struct device *dev) +{ + struct tpm_chip *chip = dev_get_drvdata(dev); + struct st33zp24_platform_data *pin_infos = dev->platform_data; + int ret = 0; + + if (power_mgt) + gpio_set_value(pin_infos->io_lpcpd, 0); + else{ + if (chip->data_buffer == NULL) + chip->data_buffer = pin_infos->tpm_i2c_buffer[0]; + ret = tpm_pm_suspend(dev); + } + return ret; +} /* tpm_st33_i2c_suspend() */ + +/* + * tpm_st33_i2c_pm_resume resume the TPM device + * @param: client, the i2c_client drescription (TPM I2C description). + * @return: 0 in case of success. + */ +static int tpm_st33_i2c_pm_resume(struct device *dev) +{ + struct tpm_chip *chip = dev_get_drvdata(dev); + struct st33zp24_platform_data *pin_infos = dev->platform_data; + + int ret = 0; + + if (power_mgt) { + gpio_set_value(pin_infos->io_lpcpd, 1); + ret = wait_for_serirq_timeout(chip, + (chip->vendor.status(chip) & + TPM_STS_VALID) == TPM_STS_VALID, + chip->vendor.timeout_b); + } else{ + if (chip->data_buffer == NULL) + chip->data_buffer = pin_infos->tpm_i2c_buffer[0]; + ret = tpm_pm_resume(dev); + if (!ret) + tpm_do_selftest(chip); + } + return ret; +} /* tpm_st33_i2c_pm_resume() */ +#endif + +static const struct i2c_device_id tpm_st33_i2c_id[] = { + {TPM_ST33_I2C, 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, tpm_st33_i2c_id); +static SIMPLE_DEV_PM_OPS(tpm_st33_i2c_ops, tpm_st33_i2c_pm_suspend, tpm_st33_i2c_pm_resume); +static struct i2c_driver tpm_st33_i2c_driver = { + .driver = { + .owner = THIS_MODULE, + .name = TPM_ST33_I2C, + .pm = &tpm_st33_i2c_ops, + }, + .probe = tpm_st33_i2c_probe, + .remove = tpm_st33_i2c_remove, + .id_table = tpm_st33_i2c_id +}; + +module_i2c_driver(tpm_st33_i2c_driver); + +MODULE_AUTHOR("Christophe Ricard (tpmsupport@st.com)"); +MODULE_DESCRIPTION("STM TPM I2C ST33 Driver"); +MODULE_VERSION("1.2.0"); +MODULE_LICENSE("GPL"); diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.h b/drivers/char/tpm/tpm_i2c_stm_st33.h new file mode 100644 index 000000000000..439a43249aa6 --- /dev/null +++ b/drivers/char/tpm/tpm_i2c_stm_st33.h @@ -0,0 +1,61 @@ +/* + * STMicroelectronics TPM I2C Linux driver for TPM ST33ZP24 + * Copyright (C) 2009, 2010 STMicroelectronics + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * STMicroelectronics version 1.2.0, Copyright (C) 2010 + * STMicroelectronics comes with ABSOLUTELY NO WARRANTY. + * This is free software, and you are welcome to redistribute it + * under certain conditions. + * + * @Author: Christophe RICARD tpmsupport@st.com + * + * @File: stm_st33_tpm_i2c.h + * + * @Date: 09/15/2010 + */ +#ifndef __STM_ST33_TPM_I2C_MAIN_H__ +#define __STM_ST33_TPM_I2C_MAIN_H__ + +#define TPM_ACCESS (0x0) +#define TPM_STS (0x18) +#define TPM_HASH_END (0x20) +#define TPM_DATA_FIFO (0x24) +#define TPM_HASH_DATA (0x24) +#define TPM_HASH_START (0x28) +#define TPM_INTF_CAPABILITY (0x14) +#define TPM_INT_STATUS (0x10) +#define TPM_INT_ENABLE (0x08) + +#define TPM_DUMMY_BYTE 0xAA +#define TPM_WRITE_DIRECTION 0x80 +#define TPM_HEADER_SIZE 10 +#define TPM_BUFSIZE 2048 + +#define LOCALITY0 0 + +#define TPM_ST33_I2C "st33zp24_i2c" + +struct st33zp24_platform_data { + int io_serirq; + int io_lpcpd; + struct i2c_client *client; + u8 *tpm_i2c_buffer[2]; /* 0 Request 1 Response */ + struct completion irq_detection; + struct mutex lock; +}; + +#endif /* __STM_ST33_TPM_I2C_MAIN_H__ */ diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c index 9978609d93b2..56b07c35a13e 100644 --- a/drivers/char/tpm/tpm_ibmvtpm.c +++ b/drivers/char/tpm/tpm_ibmvtpm.c @@ -64,7 +64,7 @@ static struct ibmvtpm_dev *ibmvtpm_get_data(const struct device *dev) { struct tpm_chip *chip = dev_get_drvdata(dev); if (chip) - return (struct ibmvtpm_dev *)chip->vendor.data; + return (struct ibmvtpm_dev *)TPM_VPRIV(chip); return NULL; } @@ -83,7 +83,7 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count) u16 len; int sig; - ibmvtpm = (struct ibmvtpm_dev *)chip->vendor.data; + ibmvtpm = (struct ibmvtpm_dev *)TPM_VPRIV(chip); if (!ibmvtpm->rtce_buf) { dev_err(ibmvtpm->dev, "ibmvtpm device is not ready\n"); @@ -127,7 +127,7 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count) u64 *word = (u64 *) &crq; int rc; - ibmvtpm = (struct ibmvtpm_dev *)chip->vendor.data; + ibmvtpm = (struct ibmvtpm_dev *)TPM_VPRIV(chip); if (!ibmvtpm->rtce_buf) { dev_err(ibmvtpm->dev, "ibmvtpm device is not ready\n"); @@ -398,6 +398,11 @@ static int tpm_ibmvtpm_resume(struct device *dev) return rc; } +static bool tpm_ibmvtpm_req_canceled(struct tpm_chip *chip, u8 status) +{ + return (status == 0); +} + static const struct file_operations ibmvtpm_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -441,7 +446,7 @@ static const struct tpm_vendor_specific tpm_ibmvtpm = { .status = tpm_ibmvtpm_status, .req_complete_mask = 0, .req_complete_val = 0, - .req_canceled = 0, + .req_canceled = tpm_ibmvtpm_req_canceled, .attr_group = &ibmvtpm_attr_grp, .miscdev = { .fops = &ibmvtpm_ops, }, }; @@ -647,7 +652,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev, ibmvtpm->dev = dev; ibmvtpm->vdev = vio_dev; - chip->vendor.data = (void *)ibmvtpm; + TPM_VPRIV(chip) = (void *)ibmvtpm; spin_lock_init(&ibmvtpm->rtce_lock); diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c index 640c9a427b59..770c46f8eb30 100644 --- a/drivers/char/tpm/tpm_nsc.c +++ b/drivers/char/tpm/tpm_nsc.c @@ -227,6 +227,11 @@ static u8 tpm_nsc_status(struct tpm_chip *chip) return inb(chip->vendor.base + NSC_STATUS); } +static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status) +{ + return (status == NSC_STATUS_RDY); +} + static const struct file_operations nsc_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -258,7 +263,7 @@ static const struct tpm_vendor_specific tpm_nsc = { .status = tpm_nsc_status, .req_complete_mask = NSC_STATUS_OBF, .req_complete_val = NSC_STATUS_OBF, - .req_canceled = NSC_STATUS_RDY, + .req_canceled = tpm_nsc_req_canceled, .attr_group = &nsc_attr_grp, .miscdev = { .fops = &nsc_ops, }, }; diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index ea31dafbcac2..8a41b6be23a0 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -84,6 +84,9 @@ static int is_itpm(struct pnp_dev *dev) struct acpi_device *acpi = pnp_acpi_device(dev); struct acpi_hardware_id *id; + if (!acpi) + return 0; + list_for_each_entry(id, &acpi->pnp.ids, list) { if (!strcmp("INTC0102", id->id)) return 1; @@ -98,6 +101,22 @@ static inline int is_itpm(struct pnp_dev *dev) } #endif +/* Before we attempt to access the TPM we must see that the valid bit is set. + * The specification says that this bit is 0 at reset and remains 0 until the + * 'TPM has gone through its self test and initialization and has established + * correct values in the other bits.' */ +static int wait_startup(struct tpm_chip *chip, int l) +{ + unsigned long stop = jiffies + chip->vendor.timeout_a; + do { + if (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) & + TPM_ACCESS_VALID) + return 0; + msleep(TPM_TIMEOUT); + } while (time_before(jiffies, stop)); + return -1; +} + static int check_locality(struct tpm_chip *chip, int l) { if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) & @@ -198,7 +217,7 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) wait_for_tpm_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, chip->vendor.timeout_c, - &chip->vendor.read_queue) + &chip->vendor.read_queue, true) == 0) { burstcnt = get_burstcount(chip); for (; burstcnt > 0 && size < count; burstcnt--) @@ -241,7 +260,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) } wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, - &chip->vendor.int_queue); + &chip->vendor.int_queue, false); status = tpm_tis_status(chip); if (status & TPM_STS_DATA_AVAIL) { /* retry? */ dev_err(chip->dev, "Error left over data\n"); @@ -277,7 +296,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) tpm_tis_ready(chip); if (wait_for_tpm_stat (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, - &chip->vendor.int_queue) < 0) { + &chip->vendor.int_queue, false) < 0) { rc = -ETIME; goto out_err; } @@ -292,7 +311,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) } wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, - &chip->vendor.int_queue); + &chip->vendor.int_queue, false); status = tpm_tis_status(chip); if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { rc = -EIO; @@ -304,7 +323,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) iowrite8(buf[count], chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality)); wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, - &chip->vendor.int_queue); + &chip->vendor.int_queue, false); status = tpm_tis_status(chip); if ((status & TPM_STS_DATA_EXPECT) != 0) { rc = -EIO; @@ -342,7 +361,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) if (wait_for_tpm_stat (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, tpm_calc_ordinal_duration(chip, ordinal), - &chip->vendor.read_queue) < 0) { + &chip->vendor.read_queue, false) < 0) { rc = -ETIME; goto out_err; } @@ -374,7 +393,7 @@ static int probe_itpm(struct tpm_chip *chip) if (vendor != TPM_VID_INTEL) return 0; - itpm = 0; + itpm = false; rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) @@ -383,7 +402,7 @@ static int probe_itpm(struct tpm_chip *chip) tpm_tis_ready(chip); release_locality(chip, chip->vendor.locality, 0); - itpm = 1; + itpm = true; rc = tpm_tis_send_data(chip, cmd_getticks, len); if (rc == 0) { @@ -400,6 +419,19 @@ out: return rc; } +static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status) +{ + switch (chip->vendor.manufacturer_id) { + case TPM_VID_WINBOND: + return ((status == TPM_STS_VALID) || + (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY))); + case TPM_VID_STM: + return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)); + default: + return (status == TPM_STS_COMMAND_READY); + } +} + static const struct file_operations tis_ops = { .owner = THIS_MODULE, .llseek = no_llseek, @@ -445,7 +477,7 @@ static struct tpm_vendor_specific tpm_tis = { .cancel = tpm_tis_ready, .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID, .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, - .req_canceled = TPM_STS_COMMAND_READY, + .req_canceled = tpm_tis_req_canceled, .attr_group = &tis_attr_grp, .miscdev = { .fops = &tis_ops,}, @@ -502,7 +534,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) return IRQ_HANDLED; } -static bool interrupts = 1; +static bool interrupts = true; module_param(interrupts, bool, 0444); MODULE_PARM_DESC(interrupts, "Enable interrupts"); @@ -528,12 +560,18 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + if (wait_startup(chip, 0) != 0) { + rc = -ENODEV; + goto out_err; + } + if (request_locality(chip, 0) != 0) { rc = -ENODEV; goto out_err; } vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0)); + chip->vendor.manufacturer_id = vendor; dev_info(dev, "1.2 TPM (device-id 0x%X, rev-id %d)\n", @@ -545,7 +583,7 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, rc = -ENODEV; goto out_err; } - itpm = (probe == 0) ? 0 : 1; + itpm = !!probe; } if (itpm) @@ -741,10 +779,10 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, if (pnp_irq_valid(pnp_dev, 0)) irq = pnp_irq(pnp_dev, 0); else - interrupts = 0; + interrupts = false; if (is_itpm(pnp_dev)) - itpm = 1; + itpm = true; return tpm_tis_init(&pnp_dev->dev, start, len, irq); } |