Changes in 4.9.337 mm/khugepaged: fix GUP-fast interaction by sending IPI mm/khugepaged: invoke MMU notifiers in shmem/file collapse paths block: unhash blkdev part inode when the part is deleted ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx() can: sja1000: fix size of OCR_MODE_MASK define ASoC: ops: Correct bounds check for second channel on SX controls udf: Discard preallocation before extending file with a hole udf: Drop unused arguments of udf_delete_aext() udf: Fix preallocation discarding at indirect extent boundary udf: Do not bother looking for prealloc extents if i_lenExtents matches i_size udf: Fix extending file within last block usb: gadget: uvc: Prevent buffer overflow in setup handler USB: serial: cp210x: add Kamstrup RF sniffer PIDs Bluetooth: L2CAP: Fix u8 overflow net: loopback: use NET_NAME_PREDICTABLE for name_assign_type drivers: soc: ti: knav_qmss_queue: Mark knav_acc_firmwares as static arm: dts: spear600: Fix clcd interrupt soc: ti: smartreflex: Fix PM disable depth imbalance in omap_sr_probe ARM: dts: dove: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-370: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-xp: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-375: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-38x: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-39x: Fix assigned-addresses for every PCIe Root Port ARM: mmp: fix timer_read delay pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP cpuidle: dt: Return the correct numbers of parsed idle states alpha: fix syscall entry in !AUDUT_SYSCALL case PM: hibernate: Fix mistake in kerneldoc comment fs: don't audit the capability check in simple_xattr_list() perf: Fix possible memleak in pmu_dev_alloc() timerqueue: Use rb_entry_safe() in timerqueue_getnext() ocfs2: fix memory leak in ocfs2_stack_glue_init() MIPS: vpe-mt: fix possible memory leak while module exiting MIPS: vpe-cmp: fix possible memory leak while module exiting PNP: fix name memory leak in pnp_alloc_dev() irqchip: gic-pm: Use pm_runtime_resume_and_get() in gic_probe() libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value lib/notifier-error-inject: fix error when writing -errno to debugfs file rapidio: fix possible name leaks when rio_add_device() fails rapidio: rio: fix possible name leak in rio_register_mport() ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() uprobes/x86: Allow to probe a NOP instruction with 0x66 prefix x86/xen: Fix memory leak in xen_init_lock_cpu() MIPS: BCM63xx: Add check for NULL for clk in clk_enable fs: sysv: Fix sysv_nblocks() returns wrong value rapidio: fix possible UAF when kfifo_alloc() fails eventfd: change int to __u64 in eventfd_signal() ifndef CONFIG_EVENTFD hfs: Fix OOB Write in hfs_asc2mac rapidio: devices: fix missing put_device in mport_cdev_open wifi: ath9k: hif_usb: fix memory leak of urbs in ath9k_hif_usb_dealloc_tx_urbs() wifi: ath9k: hif_usb: Fix use-after-free in ath9k_hif_usb_reg_in_cb() media: i2c: ad5820: Fix error path media: vivid: fix compose size exceed boundary mtd: Fix device name leak when register device failed in add_mtd_device() ASoC: pxa: fix null-pointer dereference in filter() regulator: core: fix unbalanced of node refcount in regulator_dev_lookup() ima: Fix misuse of dereference of pointer in template_desc_init_fields() wifi: ath10k: Fix return value in ath10k_pci_init() mtd: lpddr2_nvm: Fix possible null-ptr-deref Input: elants_i2c - properly handle the reset GPIO when power is off media: solo6x10: fix possible memory leak in solo_sysfs_init() media: platform: exynos4-is: Fix error handling in fimc_md_init() HID: hid-sensor-custom: set fixed size for custom attributes ALSA: seq: fix undefined behavior in bit shift for SNDRV_SEQ_FILTER_USE_EVENT clk: rockchip: Fix memory leak in rockchip_clk_register_pll() mtd: maps: pxa2xx-flash: fix memory leak in probe media: imon: fix a race condition in send_packet() pinctrl: pinconf-generic: add missing of_node_put() media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer() NFSv4.2: Fix a memory stomp in decode_attr_security_label NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn ALSA: asihpi: fix missing pci_disable_device() drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios() drm/amdgpu: Fix PCI device refcount leak in amdgpu_atrm_get_bios() ASoC: pcm512x: Fix PM disable depth imbalance in pcm512x_probe bonding: uninitialized variable in bond_miimon_inspect() regulator: core: fix module refcount leak in set_supply() media: saa7164: fix missing pci_disable_device() ALSA: mts64: fix possible null-ptr-defer in snd_mts64_interrupt SUNRPC: Fix missing release socket in rpc_sockname() mmc: moxart: fix return value check of mmc_add_host() mmc: mxcmmc: fix return value check of mmc_add_host() mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host() mmc: toshsd: fix return value check of mmc_add_host() mmc: vub300: fix return value check of mmc_add_host() mmc: via-sdmmc: fix return value check of mmc_add_host() mmc: wbsd: fix return value check of mmc_add_host() mmc: mmci: fix return value check of mmc_add_host() media: c8sectpfe: Add of_node_put() when breaking out of loop media: coda: Add check for dcoda_iram_alloc media: coda: Add check for kmalloc wifi: rtl8xxxu: Add __packed to struct rtl8723bu_c2h wifi: brcmfmac: Fix error return code in brcmf_sdio_download_firmware() blktrace: Fix output non-blktrace event when blk_classic option enabled net: vmw_vsock: vmci: Check memcpy_from_msg() net: defxx: Fix missing err handling in dfx_init() drivers: net: qlcnic: Fix potential memory leak in qlcnic_sriov_init() ethernet: s2io: don't call dev_kfree_skb() under spin_lock_irqsave() net: farsync: Fix kmemleak when rmmods farsync net/tunnel: wait until all sk_user_data reader finish before releasing the sock net: apple: mace: don't call dev_kfree_skb() under spin_lock_irqsave() net: apple: bmac: don't call dev_kfree_skb() under spin_lock_irqsave() net: emaclite: don't call dev_kfree_skb() under spin_lock_irqsave() net: ethernet: dnet: don't call dev_kfree_skb() under spin_lock_irqsave() hamradio: don't call dev_kfree_skb() under spin_lock_irqsave() net: amd: lance: don't call dev_kfree_skb() under spin_lock_irqsave() ntb_netdev: Use dev_kfree_skb_any() in interrupt context Bluetooth: btusb: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_qca: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_h5: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_bcsp: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_core: don't call kfree_skb() under spin_lock_irqsave() stmmac: fix potential division by 0 scsi: hpsa: Fix error handling in hpsa_add_sas_host() scsi: hpsa: Fix possible memory leak in hpsa_add_sas_device() scsi: fcoe: Fix possible name leak when device_register() fails scsi: ipr: Fix WARNING in ipr_init() scsi: fcoe: Fix transport not deattached when fcoe_if_init() fails scsi: snic: Fix possible UAF in snic_tgt_create() orangefs: Fix sysfs not cleanup when dev init failed crypto: img-hash - Fix variable dereferenced before check 'hdev->req' hwrng: amd - Fix PCI device refcount leak hwrng: geode - Fix PCI device refcount leak IB/IPoIB: Fix queue count inconsistency for PKEY child interfaces drivers: dio: fix possible memory leak in dio_init() vfio: platform: Do not pass return buffer to ACPI _RST method uio: uio_dmem_genirq: Fix missing unlock in irq configuration uio: uio_dmem_genirq: Fix deadlock between irq config and handling usb: fotg210-udc: Fix ages old endianness issues staging: vme_user: Fix possible UAF in tsi148_dma_list_add serial: amba-pl011: avoid SBSA UART accessing DMACR register serial: pch: Fix PCI device refcount leak in pch_request_dma() serial: sunsab: Fix error handling in sunsab_init() misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter() cxl: fix possible null-ptr-deref in cxl_pci_init_afu|adapter() drivers: mcb: fix resource leak in mcb_probe() mcb: mcb-parse: fix error handing in chameleon_parse_gdd() chardev: fix error handling in cdev_device_add() i2c: pxa-pci: fix missing pci_disable_device() on error in ce4100_i2c_probe staging: rtl8192u: Fix use after free in ieee80211_rx() staging: rtl8192e: Fix potential use-after-free in rtllib_rx_Monitor() vme: Fix error not catched in fake_init() i2c: ismt: Fix an out-of-bounds bug in ismt_access() usb: storage: Add check for kcalloc fbdev: ssd1307fb: Drop optional dependency fbdev: pm2fb: fix missing pci_disable_device() fbdev: via: Fix error in via_core_init() fbdev: vermilion: decrease reference count in error path fbdev: uvesafb: Fixes an error handling path in uvesafb_probe() HSI: omap_ssi_core: fix unbalanced pm_runtime_disable() HSI: omap_ssi_core: fix possible memory leak in ssi_probe() power: supply: fix residue sysfs file in error handle route of __power_supply_register() HSI: omap_ssi_core: Fix error handling in ssi_init() include/uapi/linux/swab: Fix potentially missing __always_inline rtc: snvs: Allow a time difference on clock register read iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe() macintosh: fix possible memory leak in macio_add_one_device() macintosh/macio-adb: check the return value of ioremap() powerpc/52xx: Fix a resource leak in an error handling path powerpc/perf: callchain validate kernel stack pointer bounds powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe() powerpc/hv-gpci: Fix hv_gpci event list selftests/powerpc: Fix resource leaks rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe() nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure mISDN: hfcsusb: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcpci: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcmulti: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() nfc: pn533: Clear nfc_target before being used r6040: Fix kmemleak in probe and remove openvswitch: Fix flow lookup to use unmasked key skbuff: Account for tail adjustment during pull operations net_sched: reject TCF_EM_SIMPLE case for complex ematch module myri10ge: Fix an error handling path in myri10ge_probe() net: stream: purge sk_error_queue in sk_stream_kill_queues() binfmt_misc: fix shift-out-of-bounds in check_special_flags fs: jfs: fix shift-out-of-bounds in dbAllocAG udf: Avoid double brelse() in udf_rename() fs: jfs: fix shift-out-of-bounds in dbDiscardAG ACPICA: Fix error code path in acpi_ds_call_control_method() nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset() acct: fix potential integer overflow in encode_comp_t() hfs: fix OOB Read in __hfs_brec_find wifi: ath9k: verify the expected usb_endpoints are present wifi: ar5523: Fix use-after-free on ar5523_cmd() timed out ipmi: fix memleak when unload ipmi driver net: ethernet: ti: Fix return type of netcp_ndo_start_xmit() hamradio: baycom_epp: Fix return type of baycom_send_packet() wifi: brcmfmac: Fix potential shift-out-of-bounds in brcmf_fw_alloc_request() igb: Do not free q_vector unless new one was allocated s390/ctcm: Fix return type of ctc{mp,}m_tx() s390/netiucv: Fix return type of netiucv_tx() s390/lcs: Fix return type of lcs_start_xmit() drm/sti: Use drm_mode_copy() md/raid1: stop mdx_raid1 thread when raid1 array run failed mrp: introduce active flags to prevent UAF when applicant uninit ppp: associate skb with a device at tx media: dvb-frontends: fix leak of memory fw media: dvb-usb: fix memory leak in dvb_usb_adapter_init() blk-mq: fix possible memleak when register 'hctx' failed mmc: f-sdh30: Add quirks for broken timeout clock capability media: si470x: Fix use-after-free in si470x_int_in_callback() clk: st: Fix memory leak in st_of_quadfs_setup() drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid() drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid() orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string() ASoC: mediatek: mt8173-rt5650-rt5514: fix refcount leak in mt8173_rt5650_rt5514_dev_probe() ASoC: wm8994: Fix potential deadlock ASoC: rockchip: spdif: Add missing clk_disable_unprepare() in rk_spdif_runtime_resume() ASoC: rt5670: Remove unbalanced pm_runtime_put() HID: wacom: Ensure bootloader PID is usable in hidraw mode reiserfs: Add missing calls to reiserfs_security_free() iio: adc: ad_sigma_delta: do not use internal iio_dev lock gcov: add support for checksum field powerpc/rtas: avoid scheduling in rtas_os_term() HID: plantronics: Additional PIDs for double volume key presses quirk hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount ALSA: line6: correct midi status byte when receiving data from podxt ALSA: line6: fix stack overflow in line6_midi_transmit pnode: terminate at peers of source md: fix a crash in mempool_free mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING media: stv0288: use explicitly signed char ktest.pl minconfig: Unset configs instead of just removing them ARM: ux500: do not directly dereference __iomem dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort dm thin: Use last transaction's pmd->root when commit failed dm thin: Fix UAF in run_timer_softirq() dm cache: Fix UAF in destroy() dm cache: set needs_check flag after aborting metadata tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod media: dvb-core: Fix double free in dvb_register_device() cifs: fix confusing debug message PCI/sysfs: Fix double free in error path crypto: n2 - add missing hash statesize iommu/amd: Fix ivrs_acpihid cmdline parsing code parisc: led: Fix potential null-ptr-deref in start_task() device_cgroup: Roll back to original exceptions after copy failure drm/connector: send hotplug uevent on connector cleanup drm/vmwgfx: Validate the box size for the snooped cursor ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop ext4: fix undefined behavior in bit shift for ext4_check_flag_values ext4: fix bug_on in __es_tree_search caused by bad boot loader inode ext4: init quota for 'old.inode' in 'ext4_rename' ext4: fix error code return to user-space in ext4_get_branch() ext4: avoid BUG_ON when creating xattrs ext4: initialize quota before expanding inode in setproject ioctl Linux 4.9.337 Change-Id: I923e3fef499ae1688b25c70a1a805b55a9f4f027 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
961 lines
27 KiB
C
961 lines
27 KiB
C
/*
|
|
* This file is provided under a dual BSD/GPLv2 license. When using or
|
|
* redistributing this file, you may do so under either license.
|
|
*
|
|
* Copyright(c) 2012 Intel Corporation. All rights reserved.
|
|
*
|
|
* GPL LICENSE SUMMARY
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of version 2 of the GNU General Public License as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* 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.
|
|
* The full GNU General Public License is included in this distribution
|
|
* in the file called LICENSE.GPL.
|
|
*
|
|
* BSD LICENSE
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
* contributors may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
/*
|
|
* Supports the SMBus Message Transport (SMT) in the Intel Atom Processor
|
|
* S12xx Product Family.
|
|
*
|
|
* Features supported by this driver:
|
|
* Hardware PEC yes
|
|
* Block buffer yes
|
|
* Block process call transaction no
|
|
* Slave mode no
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/completion.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io-64-nonatomic-lo-hi.h>
|
|
|
|
/* PCI Address Constants */
|
|
#define SMBBAR 0
|
|
|
|
/* PCI DIDs for the Intel SMBus Message Transport (SMT) Devices */
|
|
#define PCI_DEVICE_ID_INTEL_S1200_SMT0 0x0c59
|
|
#define PCI_DEVICE_ID_INTEL_S1200_SMT1 0x0c5a
|
|
#define PCI_DEVICE_ID_INTEL_DNV_SMT 0x19ac
|
|
#define PCI_DEVICE_ID_INTEL_AVOTON_SMT 0x1f15
|
|
|
|
#define ISMT_DESC_ENTRIES 2 /* number of descriptor entries */
|
|
#define ISMT_MAX_RETRIES 3 /* number of SMBus retries to attempt */
|
|
|
|
/* Hardware Descriptor Constants - Control Field */
|
|
#define ISMT_DESC_CWRL 0x01 /* Command/Write Length */
|
|
#define ISMT_DESC_BLK 0X04 /* Perform Block Transaction */
|
|
#define ISMT_DESC_FAIR 0x08 /* Set fairness flag upon successful arbit. */
|
|
#define ISMT_DESC_PEC 0x10 /* Packet Error Code */
|
|
#define ISMT_DESC_I2C 0x20 /* I2C Enable */
|
|
#define ISMT_DESC_INT 0x40 /* Interrupt */
|
|
#define ISMT_DESC_SOE 0x80 /* Stop On Error */
|
|
|
|
/* Hardware Descriptor Constants - Status Field */
|
|
#define ISMT_DESC_SCS 0x01 /* Success */
|
|
#define ISMT_DESC_DLTO 0x04 /* Data Low Time Out */
|
|
#define ISMT_DESC_NAK 0x08 /* NAK Received */
|
|
#define ISMT_DESC_CRC 0x10 /* CRC Error */
|
|
#define ISMT_DESC_CLTO 0x20 /* Clock Low Time Out */
|
|
#define ISMT_DESC_COL 0x40 /* Collisions */
|
|
#define ISMT_DESC_LPR 0x80 /* Large Packet Received */
|
|
|
|
/* Macros */
|
|
#define ISMT_DESC_ADDR_RW(addr, rw) (((addr) << 1) | (rw))
|
|
|
|
/* iSMT General Register address offsets (SMBBAR + <addr>) */
|
|
#define ISMT_GR_GCTRL 0x000 /* General Control */
|
|
#define ISMT_GR_SMTICL 0x008 /* SMT Interrupt Cause Location */
|
|
#define ISMT_GR_ERRINTMSK 0x010 /* Error Interrupt Mask */
|
|
#define ISMT_GR_ERRAERMSK 0x014 /* Error AER Mask */
|
|
#define ISMT_GR_ERRSTS 0x018 /* Error Status */
|
|
#define ISMT_GR_ERRINFO 0x01c /* Error Information */
|
|
|
|
/* iSMT Master Registers */
|
|
#define ISMT_MSTR_MDBA 0x100 /* Master Descriptor Base Address */
|
|
#define ISMT_MSTR_MCTRL 0x108 /* Master Control */
|
|
#define ISMT_MSTR_MSTS 0x10c /* Master Status */
|
|
#define ISMT_MSTR_MDS 0x110 /* Master Descriptor Size */
|
|
#define ISMT_MSTR_RPOLICY 0x114 /* Retry Policy */
|
|
|
|
/* iSMT Miscellaneous Registers */
|
|
#define ISMT_SPGT 0x300 /* SMBus PHY Global Timing */
|
|
|
|
/* General Control Register (GCTRL) bit definitions */
|
|
#define ISMT_GCTRL_TRST 0x04 /* Target Reset */
|
|
#define ISMT_GCTRL_KILL 0x08 /* Kill */
|
|
#define ISMT_GCTRL_SRST 0x40 /* Soft Reset */
|
|
|
|
/* Master Control Register (MCTRL) bit definitions */
|
|
#define ISMT_MCTRL_SS 0x01 /* Start/Stop */
|
|
#define ISMT_MCTRL_MEIE 0x10 /* Master Error Interrupt Enable */
|
|
#define ISMT_MCTRL_FMHP 0x00ff0000 /* Firmware Master Head Ptr (FMHP) */
|
|
|
|
/* Master Status Register (MSTS) bit definitions */
|
|
#define ISMT_MSTS_HMTP 0xff0000 /* HW Master Tail Pointer (HMTP) */
|
|
#define ISMT_MSTS_MIS 0x20 /* Master Interrupt Status (MIS) */
|
|
#define ISMT_MSTS_MEIS 0x10 /* Master Error Int Status (MEIS) */
|
|
#define ISMT_MSTS_IP 0x01 /* In Progress */
|
|
|
|
/* Master Descriptor Size (MDS) bit definitions */
|
|
#define ISMT_MDS_MASK 0xff /* Master Descriptor Size mask (MDS) */
|
|
|
|
/* SMBus PHY Global Timing Register (SPGT) bit definitions */
|
|
#define ISMT_SPGT_SPD_MASK 0xc0000000 /* SMBus Speed mask */
|
|
#define ISMT_SPGT_SPD_80K 0x00 /* 80 kHz */
|
|
#define ISMT_SPGT_SPD_100K (0x1 << 30) /* 100 kHz */
|
|
#define ISMT_SPGT_SPD_400K (0x2 << 30) /* 400 kHz */
|
|
#define ISMT_SPGT_SPD_1M (0x3 << 30) /* 1 MHz */
|
|
|
|
|
|
/* MSI Control Register (MSICTL) bit definitions */
|
|
#define ISMT_MSICTL_MSIE 0x01 /* MSI Enable */
|
|
|
|
/* iSMT Hardware Descriptor */
|
|
struct ismt_desc {
|
|
u8 tgtaddr_rw; /* target address & r/w bit */
|
|
u8 wr_len_cmd; /* write length in bytes or a command */
|
|
u8 rd_len; /* read length */
|
|
u8 control; /* control bits */
|
|
u8 status; /* status bits */
|
|
u8 retry; /* collision retry and retry count */
|
|
u8 rxbytes; /* received bytes */
|
|
u8 txbytes; /* transmitted bytes */
|
|
u32 dptr_low; /* lower 32 bit of the data pointer */
|
|
u32 dptr_high; /* upper 32 bit of the data pointer */
|
|
} __packed;
|
|
|
|
struct ismt_priv {
|
|
struct i2c_adapter adapter;
|
|
void __iomem *smba; /* PCI BAR */
|
|
struct pci_dev *pci_dev;
|
|
struct ismt_desc *hw; /* descriptor virt base addr */
|
|
dma_addr_t io_rng_dma; /* descriptor HW base addr */
|
|
u8 head; /* ring buffer head pointer */
|
|
struct completion cmp; /* interrupt completion */
|
|
u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* temp R/W data buffer */
|
|
};
|
|
|
|
/**
|
|
* ismt_ids - PCI device IDs supported by this driver
|
|
*/
|
|
static const struct pci_device_id ismt_ids[] = {
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT0) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_S1200_SMT1) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_DNV_SMT) },
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_AVOTON_SMT) },
|
|
{ 0, }
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, ismt_ids);
|
|
|
|
/* Bus speed control bits for slow debuggers - refer to the docs for usage */
|
|
static unsigned int bus_speed;
|
|
module_param(bus_speed, uint, S_IRUGO);
|
|
MODULE_PARM_DESC(bus_speed, "Bus Speed in kHz (0 = BIOS default)");
|
|
|
|
/**
|
|
* __ismt_desc_dump() - dump the contents of a specific descriptor
|
|
*/
|
|
static void __ismt_desc_dump(struct device *dev, const struct ismt_desc *desc)
|
|
{
|
|
|
|
dev_dbg(dev, "Descriptor struct: %p\n", desc);
|
|
dev_dbg(dev, "\ttgtaddr_rw=0x%02X\n", desc->tgtaddr_rw);
|
|
dev_dbg(dev, "\twr_len_cmd=0x%02X\n", desc->wr_len_cmd);
|
|
dev_dbg(dev, "\trd_len= 0x%02X\n", desc->rd_len);
|
|
dev_dbg(dev, "\tcontrol= 0x%02X\n", desc->control);
|
|
dev_dbg(dev, "\tstatus= 0x%02X\n", desc->status);
|
|
dev_dbg(dev, "\tretry= 0x%02X\n", desc->retry);
|
|
dev_dbg(dev, "\trxbytes= 0x%02X\n", desc->rxbytes);
|
|
dev_dbg(dev, "\ttxbytes= 0x%02X\n", desc->txbytes);
|
|
dev_dbg(dev, "\tdptr_low= 0x%08X\n", desc->dptr_low);
|
|
dev_dbg(dev, "\tdptr_high= 0x%08X\n", desc->dptr_high);
|
|
}
|
|
/**
|
|
* ismt_desc_dump() - dump the contents of a descriptor for debug purposes
|
|
* @priv: iSMT private data
|
|
*/
|
|
static void ismt_desc_dump(struct ismt_priv *priv)
|
|
{
|
|
struct device *dev = &priv->pci_dev->dev;
|
|
struct ismt_desc *desc = &priv->hw[priv->head];
|
|
|
|
dev_dbg(dev, "Dump of the descriptor struct: 0x%X\n", priv->head);
|
|
__ismt_desc_dump(dev, desc);
|
|
}
|
|
|
|
/**
|
|
* ismt_gen_reg_dump() - dump the iSMT General Registers
|
|
* @priv: iSMT private data
|
|
*/
|
|
static void ismt_gen_reg_dump(struct ismt_priv *priv)
|
|
{
|
|
struct device *dev = &priv->pci_dev->dev;
|
|
|
|
dev_dbg(dev, "Dump of the iSMT General Registers\n");
|
|
dev_dbg(dev, " GCTRL.... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_GR_GCTRL,
|
|
readl(priv->smba + ISMT_GR_GCTRL));
|
|
dev_dbg(dev, " SMTICL... : (0x%p)=0x%016llX\n",
|
|
priv->smba + ISMT_GR_SMTICL,
|
|
(long long unsigned int)readq(priv->smba + ISMT_GR_SMTICL));
|
|
dev_dbg(dev, " ERRINTMSK : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_GR_ERRINTMSK,
|
|
readl(priv->smba + ISMT_GR_ERRINTMSK));
|
|
dev_dbg(dev, " ERRAERMSK : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_GR_ERRAERMSK,
|
|
readl(priv->smba + ISMT_GR_ERRAERMSK));
|
|
dev_dbg(dev, " ERRSTS... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_GR_ERRSTS,
|
|
readl(priv->smba + ISMT_GR_ERRSTS));
|
|
dev_dbg(dev, " ERRINFO.. : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_GR_ERRINFO,
|
|
readl(priv->smba + ISMT_GR_ERRINFO));
|
|
}
|
|
|
|
/**
|
|
* ismt_mstr_reg_dump() - dump the iSMT Master Registers
|
|
* @priv: iSMT private data
|
|
*/
|
|
static void ismt_mstr_reg_dump(struct ismt_priv *priv)
|
|
{
|
|
struct device *dev = &priv->pci_dev->dev;
|
|
|
|
dev_dbg(dev, "Dump of the iSMT Master Registers\n");
|
|
dev_dbg(dev, " MDBA..... : (0x%p)=0x%016llX\n",
|
|
priv->smba + ISMT_MSTR_MDBA,
|
|
(long long unsigned int)readq(priv->smba + ISMT_MSTR_MDBA));
|
|
dev_dbg(dev, " MCTRL.... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_MSTR_MCTRL,
|
|
readl(priv->smba + ISMT_MSTR_MCTRL));
|
|
dev_dbg(dev, " MSTS..... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_MSTR_MSTS,
|
|
readl(priv->smba + ISMT_MSTR_MSTS));
|
|
dev_dbg(dev, " MDS...... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_MSTR_MDS,
|
|
readl(priv->smba + ISMT_MSTR_MDS));
|
|
dev_dbg(dev, " RPOLICY.. : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_MSTR_RPOLICY,
|
|
readl(priv->smba + ISMT_MSTR_RPOLICY));
|
|
dev_dbg(dev, " SPGT..... : (0x%p)=0x%X\n",
|
|
priv->smba + ISMT_SPGT,
|
|
readl(priv->smba + ISMT_SPGT));
|
|
}
|
|
|
|
/**
|
|
* ismt_submit_desc() - add a descriptor to the ring
|
|
* @priv: iSMT private data
|
|
*/
|
|
static void ismt_submit_desc(struct ismt_priv *priv)
|
|
{
|
|
uint fmhp;
|
|
uint val;
|
|
|
|
ismt_desc_dump(priv);
|
|
ismt_gen_reg_dump(priv);
|
|
ismt_mstr_reg_dump(priv);
|
|
|
|
/* Set the FMHP (Firmware Master Head Pointer)*/
|
|
fmhp = ((priv->head + 1) % ISMT_DESC_ENTRIES) << 16;
|
|
val = readl(priv->smba + ISMT_MSTR_MCTRL);
|
|
writel((val & ~ISMT_MCTRL_FMHP) | fmhp,
|
|
priv->smba + ISMT_MSTR_MCTRL);
|
|
|
|
/* Set the start bit */
|
|
val = readl(priv->smba + ISMT_MSTR_MCTRL);
|
|
writel(val | ISMT_MCTRL_SS,
|
|
priv->smba + ISMT_MSTR_MCTRL);
|
|
}
|
|
|
|
/**
|
|
* ismt_process_desc() - handle the completion of the descriptor
|
|
* @desc: the iSMT hardware descriptor
|
|
* @data: data buffer from the upper layer
|
|
* @priv: ismt_priv struct holding our dma buffer
|
|
* @size: SMBus transaction type
|
|
* @read_write: flag to indicate if this is a read or write
|
|
*/
|
|
static int ismt_process_desc(const struct ismt_desc *desc,
|
|
union i2c_smbus_data *data,
|
|
struct ismt_priv *priv, int size,
|
|
char read_write)
|
|
{
|
|
u8 *dma_buffer = priv->dma_buffer;
|
|
|
|
dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n");
|
|
__ismt_desc_dump(&priv->pci_dev->dev, desc);
|
|
|
|
if (desc->status & ISMT_DESC_SCS) {
|
|
if (read_write == I2C_SMBUS_WRITE &&
|
|
size != I2C_SMBUS_PROC_CALL)
|
|
return 0;
|
|
|
|
switch (size) {
|
|
case I2C_SMBUS_BYTE:
|
|
case I2C_SMBUS_BYTE_DATA:
|
|
data->byte = dma_buffer[0];
|
|
break;
|
|
case I2C_SMBUS_WORD_DATA:
|
|
case I2C_SMBUS_PROC_CALL:
|
|
data->word = dma_buffer[0] | (dma_buffer[1] << 8);
|
|
break;
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
if (desc->rxbytes != dma_buffer[0] + 1)
|
|
return -EMSGSIZE;
|
|
|
|
memcpy(data->block, dma_buffer, desc->rxbytes);
|
|
break;
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
|
memcpy(&data->block[1], dma_buffer, desc->rxbytes);
|
|
data->block[0] = desc->rxbytes;
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
if (likely(desc->status & ISMT_DESC_NAK))
|
|
return -ENXIO;
|
|
|
|
if (desc->status & ISMT_DESC_CRC)
|
|
return -EBADMSG;
|
|
|
|
if (desc->status & ISMT_DESC_COL)
|
|
return -EAGAIN;
|
|
|
|
if (desc->status & ISMT_DESC_LPR)
|
|
return -EPROTO;
|
|
|
|
if (desc->status & (ISMT_DESC_DLTO | ISMT_DESC_CLTO))
|
|
return -ETIMEDOUT;
|
|
|
|
return -EIO;
|
|
}
|
|
|
|
/**
|
|
* ismt_access() - process an SMBus command
|
|
* @adap: the i2c host adapter
|
|
* @addr: address of the i2c/SMBus target
|
|
* @flags: command options
|
|
* @read_write: read from or write to device
|
|
* @command: the i2c/SMBus command to issue
|
|
* @size: SMBus transaction type
|
|
* @data: read/write data buffer
|
|
*/
|
|
static int ismt_access(struct i2c_adapter *adap, u16 addr,
|
|
unsigned short flags, char read_write, u8 command,
|
|
int size, union i2c_smbus_data *data)
|
|
{
|
|
int ret;
|
|
unsigned long time_left;
|
|
dma_addr_t dma_addr = 0; /* address of the data buffer */
|
|
u8 dma_size = 0;
|
|
enum dma_data_direction dma_direction = 0;
|
|
struct ismt_desc *desc;
|
|
struct ismt_priv *priv = i2c_get_adapdata(adap);
|
|
struct device *dev = &priv->pci_dev->dev;
|
|
|
|
desc = &priv->hw[priv->head];
|
|
|
|
/* Initialize the DMA buffer */
|
|
memset(priv->dma_buffer, 0, sizeof(priv->dma_buffer));
|
|
|
|
/* Initialize the descriptor */
|
|
memset(desc, 0, sizeof(struct ismt_desc));
|
|
desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write);
|
|
|
|
/* Initialize common control bits */
|
|
if (likely(pci_dev_msi_enabled(priv->pci_dev)))
|
|
desc->control = ISMT_DESC_INT | ISMT_DESC_FAIR;
|
|
else
|
|
desc->control = ISMT_DESC_FAIR;
|
|
|
|
if ((flags & I2C_CLIENT_PEC) && (size != I2C_SMBUS_QUICK)
|
|
&& (size != I2C_SMBUS_I2C_BLOCK_DATA))
|
|
desc->control |= ISMT_DESC_PEC;
|
|
|
|
switch (size) {
|
|
case I2C_SMBUS_QUICK:
|
|
dev_dbg(dev, "I2C_SMBUS_QUICK\n");
|
|
break;
|
|
|
|
case I2C_SMBUS_BYTE:
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
/*
|
|
* Send Byte
|
|
* The command field contains the write data
|
|
*/
|
|
dev_dbg(dev, "I2C_SMBUS_BYTE: WRITE\n");
|
|
desc->control |= ISMT_DESC_CWRL;
|
|
desc->wr_len_cmd = command;
|
|
} else {
|
|
/* Receive Byte */
|
|
dev_dbg(dev, "I2C_SMBUS_BYTE: READ\n");
|
|
dma_size = 1;
|
|
dma_direction = DMA_FROM_DEVICE;
|
|
desc->rd_len = 1;
|
|
}
|
|
break;
|
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
/*
|
|
* Write Byte
|
|
* Command plus 1 data byte
|
|
*/
|
|
dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: WRITE\n");
|
|
desc->wr_len_cmd = 2;
|
|
dma_size = 2;
|
|
dma_direction = DMA_TO_DEVICE;
|
|
priv->dma_buffer[0] = command;
|
|
priv->dma_buffer[1] = data->byte;
|
|
} else {
|
|
/* Read Byte */
|
|
dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: READ\n");
|
|
desc->control |= ISMT_DESC_CWRL;
|
|
desc->wr_len_cmd = command;
|
|
desc->rd_len = 1;
|
|
dma_size = 1;
|
|
dma_direction = DMA_FROM_DEVICE;
|
|
}
|
|
break;
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
/* Write Word */
|
|
dev_dbg(dev, "I2C_SMBUS_WORD_DATA: WRITE\n");
|
|
desc->wr_len_cmd = 3;
|
|
dma_size = 3;
|
|
dma_direction = DMA_TO_DEVICE;
|
|
priv->dma_buffer[0] = command;
|
|
priv->dma_buffer[1] = data->word & 0xff;
|
|
priv->dma_buffer[2] = data->word >> 8;
|
|
} else {
|
|
/* Read Word */
|
|
dev_dbg(dev, "I2C_SMBUS_WORD_DATA: READ\n");
|
|
desc->wr_len_cmd = command;
|
|
desc->control |= ISMT_DESC_CWRL;
|
|
desc->rd_len = 2;
|
|
dma_size = 2;
|
|
dma_direction = DMA_FROM_DEVICE;
|
|
}
|
|
break;
|
|
|
|
case I2C_SMBUS_PROC_CALL:
|
|
dev_dbg(dev, "I2C_SMBUS_PROC_CALL\n");
|
|
desc->wr_len_cmd = 3;
|
|
desc->rd_len = 2;
|
|
dma_size = 3;
|
|
dma_direction = DMA_BIDIRECTIONAL;
|
|
priv->dma_buffer[0] = command;
|
|
priv->dma_buffer[1] = data->word & 0xff;
|
|
priv->dma_buffer[2] = data->word >> 8;
|
|
break;
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
/* Block Write */
|
|
dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: WRITE\n");
|
|
if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
|
|
return -EINVAL;
|
|
|
|
dma_size = data->block[0] + 1;
|
|
dma_direction = DMA_TO_DEVICE;
|
|
desc->wr_len_cmd = dma_size;
|
|
desc->control |= ISMT_DESC_BLK;
|
|
priv->dma_buffer[0] = command;
|
|
memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1);
|
|
} else {
|
|
/* Block Read */
|
|
dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: READ\n");
|
|
dma_size = I2C_SMBUS_BLOCK_MAX;
|
|
dma_direction = DMA_FROM_DEVICE;
|
|
desc->rd_len = dma_size;
|
|
desc->wr_len_cmd = command;
|
|
desc->control |= (ISMT_DESC_BLK | ISMT_DESC_CWRL);
|
|
}
|
|
break;
|
|
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
|
/* Make sure the length is valid */
|
|
if (data->block[0] < 1)
|
|
data->block[0] = 1;
|
|
|
|
if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
|
|
data->block[0] = I2C_SMBUS_BLOCK_MAX;
|
|
|
|
if (read_write == I2C_SMBUS_WRITE) {
|
|
/* i2c Block Write */
|
|
dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA: WRITE\n");
|
|
dma_size = data->block[0] + 1;
|
|
dma_direction = DMA_TO_DEVICE;
|
|
desc->wr_len_cmd = dma_size;
|
|
desc->control |= ISMT_DESC_I2C;
|
|
priv->dma_buffer[0] = command;
|
|
memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1);
|
|
} else {
|
|
/* i2c Block Read */
|
|
dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA: READ\n");
|
|
dma_size = data->block[0];
|
|
dma_direction = DMA_FROM_DEVICE;
|
|
desc->rd_len = dma_size;
|
|
desc->wr_len_cmd = command;
|
|
desc->control |= (ISMT_DESC_I2C | ISMT_DESC_CWRL);
|
|
/*
|
|
* Per the "Table 15-15. I2C Commands",
|
|
* in the External Design Specification (EDS),
|
|
* (Document Number: 508084, Revision: 2.0),
|
|
* the _rw bit must be 0
|
|
*/
|
|
desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, 0);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
dev_err(dev, "Unsupported transaction %d\n",
|
|
size);
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
/* map the data buffer */
|
|
if (dma_size != 0) {
|
|
dev_dbg(dev, " dev=%p\n", dev);
|
|
dev_dbg(dev, " data=%p\n", data);
|
|
dev_dbg(dev, " dma_buffer=%p\n", priv->dma_buffer);
|
|
dev_dbg(dev, " dma_size=%d\n", dma_size);
|
|
dev_dbg(dev, " dma_direction=%d\n", dma_direction);
|
|
|
|
dma_addr = dma_map_single(dev,
|
|
priv->dma_buffer,
|
|
dma_size,
|
|
dma_direction);
|
|
|
|
if (dma_mapping_error(dev, dma_addr)) {
|
|
dev_err(dev, "Error in mapping dma buffer %p\n",
|
|
priv->dma_buffer);
|
|
return -EIO;
|
|
}
|
|
|
|
dev_dbg(dev, " dma_addr = 0x%016llX\n",
|
|
(unsigned long long)dma_addr);
|
|
|
|
desc->dptr_low = lower_32_bits(dma_addr);
|
|
desc->dptr_high = upper_32_bits(dma_addr);
|
|
}
|
|
|
|
reinit_completion(&priv->cmp);
|
|
|
|
/* Add the descriptor */
|
|
ismt_submit_desc(priv);
|
|
|
|
/* Now we wait for interrupt completion, 1s */
|
|
time_left = wait_for_completion_timeout(&priv->cmp, HZ*1);
|
|
|
|
/* unmap the data buffer */
|
|
if (dma_size != 0)
|
|
dma_unmap_single(dev, dma_addr, dma_size, dma_direction);
|
|
|
|
if (unlikely(!time_left)) {
|
|
dev_err(dev, "completion wait timed out\n");
|
|
ret = -ETIMEDOUT;
|
|
goto out;
|
|
}
|
|
|
|
/* do any post processing of the descriptor here */
|
|
ret = ismt_process_desc(desc, data, priv, size, read_write);
|
|
|
|
out:
|
|
/* Update the ring pointer */
|
|
priv->head++;
|
|
priv->head %= ISMT_DESC_ENTRIES;
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* ismt_func() - report which i2c commands are supported by this adapter
|
|
* @adap: the i2c host adapter
|
|
*/
|
|
static u32 ismt_func(struct i2c_adapter *adap)
|
|
{
|
|
return I2C_FUNC_SMBUS_QUICK |
|
|
I2C_FUNC_SMBUS_BYTE |
|
|
I2C_FUNC_SMBUS_BYTE_DATA |
|
|
I2C_FUNC_SMBUS_WORD_DATA |
|
|
I2C_FUNC_SMBUS_PROC_CALL |
|
|
I2C_FUNC_SMBUS_BLOCK_DATA |
|
|
I2C_FUNC_SMBUS_I2C_BLOCK |
|
|
I2C_FUNC_SMBUS_PEC;
|
|
}
|
|
|
|
/**
|
|
* smbus_algorithm - the adapter algorithm and supported functionality
|
|
* @smbus_xfer: the adapter algorithm
|
|
* @functionality: functionality supported by the adapter
|
|
*/
|
|
static const struct i2c_algorithm smbus_algorithm = {
|
|
.smbus_xfer = ismt_access,
|
|
.functionality = ismt_func,
|
|
};
|
|
|
|
/**
|
|
* ismt_handle_isr() - interrupt handler bottom half
|
|
* @priv: iSMT private data
|
|
*/
|
|
static irqreturn_t ismt_handle_isr(struct ismt_priv *priv)
|
|
{
|
|
complete(&priv->cmp);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
|
|
/**
|
|
* ismt_do_interrupt() - IRQ interrupt handler
|
|
* @vec: interrupt vector
|
|
* @data: iSMT private data
|
|
*/
|
|
static irqreturn_t ismt_do_interrupt(int vec, void *data)
|
|
{
|
|
u32 val;
|
|
struct ismt_priv *priv = data;
|
|
|
|
/*
|
|
* check to see it's our interrupt, return IRQ_NONE if not ours
|
|
* since we are sharing interrupt
|
|
*/
|
|
val = readl(priv->smba + ISMT_MSTR_MSTS);
|
|
|
|
if (!(val & (ISMT_MSTS_MIS | ISMT_MSTS_MEIS)))
|
|
return IRQ_NONE;
|
|
else
|
|
writel(val | ISMT_MSTS_MIS | ISMT_MSTS_MEIS,
|
|
priv->smba + ISMT_MSTR_MSTS);
|
|
|
|
return ismt_handle_isr(priv);
|
|
}
|
|
|
|
/**
|
|
* ismt_do_msi_interrupt() - MSI interrupt handler
|
|
* @vec: interrupt vector
|
|
* @data: iSMT private data
|
|
*/
|
|
static irqreturn_t ismt_do_msi_interrupt(int vec, void *data)
|
|
{
|
|
return ismt_handle_isr(data);
|
|
}
|
|
|
|
/**
|
|
* ismt_hw_init() - initialize the iSMT hardware
|
|
* @priv: iSMT private data
|
|
*/
|
|
static void ismt_hw_init(struct ismt_priv *priv)
|
|
{
|
|
u32 val;
|
|
struct device *dev = &priv->pci_dev->dev;
|
|
|
|
/* initialize the Master Descriptor Base Address (MDBA) */
|
|
writeq(priv->io_rng_dma, priv->smba + ISMT_MSTR_MDBA);
|
|
|
|
/* initialize the Master Control Register (MCTRL) */
|
|
writel(ISMT_MCTRL_MEIE, priv->smba + ISMT_MSTR_MCTRL);
|
|
|
|
/* initialize the Master Status Register (MSTS) */
|
|
writel(0, priv->smba + ISMT_MSTR_MSTS);
|
|
|
|
/* initialize the Master Descriptor Size (MDS) */
|
|
val = readl(priv->smba + ISMT_MSTR_MDS);
|
|
writel((val & ~ISMT_MDS_MASK) | (ISMT_DESC_ENTRIES - 1),
|
|
priv->smba + ISMT_MSTR_MDS);
|
|
|
|
/*
|
|
* Set the SMBus speed (could use this for slow HW debuggers)
|
|
*/
|
|
|
|
val = readl(priv->smba + ISMT_SPGT);
|
|
|
|
switch (bus_speed) {
|
|
case 0:
|
|
break;
|
|
|
|
case 80:
|
|
dev_dbg(dev, "Setting SMBus clock to 80 kHz\n");
|
|
writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_80K),
|
|
priv->smba + ISMT_SPGT);
|
|
break;
|
|
|
|
case 100:
|
|
dev_dbg(dev, "Setting SMBus clock to 100 kHz\n");
|
|
writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_100K),
|
|
priv->smba + ISMT_SPGT);
|
|
break;
|
|
|
|
case 400:
|
|
dev_dbg(dev, "Setting SMBus clock to 400 kHz\n");
|
|
writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_400K),
|
|
priv->smba + ISMT_SPGT);
|
|
break;
|
|
|
|
case 1000:
|
|
dev_dbg(dev, "Setting SMBus clock to 1000 kHz\n");
|
|
writel(((val & ~ISMT_SPGT_SPD_MASK) | ISMT_SPGT_SPD_1M),
|
|
priv->smba + ISMT_SPGT);
|
|
break;
|
|
|
|
default:
|
|
dev_warn(dev, "Invalid SMBus clock speed, only 0, 80, 100, 400, and 1000 are valid\n");
|
|
break;
|
|
}
|
|
|
|
val = readl(priv->smba + ISMT_SPGT);
|
|
|
|
switch (val & ISMT_SPGT_SPD_MASK) {
|
|
case ISMT_SPGT_SPD_80K:
|
|
bus_speed = 80;
|
|
break;
|
|
case ISMT_SPGT_SPD_100K:
|
|
bus_speed = 100;
|
|
break;
|
|
case ISMT_SPGT_SPD_400K:
|
|
bus_speed = 400;
|
|
break;
|
|
case ISMT_SPGT_SPD_1M:
|
|
bus_speed = 1000;
|
|
break;
|
|
}
|
|
dev_dbg(dev, "SMBus clock is running at %d kHz\n", bus_speed);
|
|
}
|
|
|
|
/**
|
|
* ismt_dev_init() - initialize the iSMT data structures
|
|
* @priv: iSMT private data
|
|
*/
|
|
static int ismt_dev_init(struct ismt_priv *priv)
|
|
{
|
|
/* allocate memory for the descriptor */
|
|
priv->hw = dmam_alloc_coherent(&priv->pci_dev->dev,
|
|
(ISMT_DESC_ENTRIES
|
|
* sizeof(struct ismt_desc)),
|
|
&priv->io_rng_dma,
|
|
GFP_KERNEL);
|
|
if (!priv->hw)
|
|
return -ENOMEM;
|
|
|
|
memset(priv->hw, 0, (ISMT_DESC_ENTRIES * sizeof(struct ismt_desc)));
|
|
|
|
priv->head = 0;
|
|
init_completion(&priv->cmp);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* ismt_int_init() - initialize interrupts
|
|
* @priv: iSMT private data
|
|
*/
|
|
static int ismt_int_init(struct ismt_priv *priv)
|
|
{
|
|
int err;
|
|
|
|
/* Try using MSI interrupts */
|
|
err = pci_enable_msi(priv->pci_dev);
|
|
if (err)
|
|
goto intx;
|
|
|
|
err = devm_request_irq(&priv->pci_dev->dev,
|
|
priv->pci_dev->irq,
|
|
ismt_do_msi_interrupt,
|
|
0,
|
|
"ismt-msi",
|
|
priv);
|
|
if (err) {
|
|
pci_disable_msi(priv->pci_dev);
|
|
goto intx;
|
|
}
|
|
|
|
return 0;
|
|
|
|
/* Try using legacy interrupts */
|
|
intx:
|
|
dev_warn(&priv->pci_dev->dev,
|
|
"Unable to use MSI interrupts, falling back to legacy\n");
|
|
|
|
err = devm_request_irq(&priv->pci_dev->dev,
|
|
priv->pci_dev->irq,
|
|
ismt_do_interrupt,
|
|
IRQF_SHARED,
|
|
"ismt-intx",
|
|
priv);
|
|
if (err) {
|
|
dev_err(&priv->pci_dev->dev, "no usable interrupts\n");
|
|
return err;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct pci_driver ismt_driver;
|
|
|
|
/**
|
|
* ismt_probe() - probe for iSMT devices
|
|
* @pdev: PCI-Express device
|
|
* @id: PCI-Express device ID
|
|
*/
|
|
static int
|
|
ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|
{
|
|
int err;
|
|
struct ismt_priv *priv;
|
|
unsigned long start, len;
|
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
pci_set_drvdata(pdev, priv);
|
|
|
|
i2c_set_adapdata(&priv->adapter, priv);
|
|
priv->adapter.owner = THIS_MODULE;
|
|
priv->adapter.class = I2C_CLASS_HWMON;
|
|
priv->adapter.algo = &smbus_algorithm;
|
|
priv->adapter.dev.parent = &pdev->dev;
|
|
ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&pdev->dev));
|
|
priv->adapter.retries = ISMT_MAX_RETRIES;
|
|
|
|
priv->pci_dev = pdev;
|
|
|
|
err = pcim_enable_device(pdev);
|
|
if (err) {
|
|
dev_err(&pdev->dev, "Failed to enable SMBus PCI device (%d)\n",
|
|
err);
|
|
return err;
|
|
}
|
|
|
|
/* enable bus mastering */
|
|
pci_set_master(pdev);
|
|
|
|
/* Determine the address of the SMBus area */
|
|
start = pci_resource_start(pdev, SMBBAR);
|
|
len = pci_resource_len(pdev, SMBBAR);
|
|
if (!start || !len) {
|
|
dev_err(&pdev->dev,
|
|
"SMBus base address uninitialized, upgrade BIOS\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
snprintf(priv->adapter.name, sizeof(priv->adapter.name),
|
|
"SMBus iSMT adapter at %lx", start);
|
|
|
|
dev_dbg(&priv->pci_dev->dev, " start=0x%lX\n", start);
|
|
dev_dbg(&priv->pci_dev->dev, " len=0x%lX\n", len);
|
|
|
|
err = acpi_check_resource_conflict(&pdev->resource[SMBBAR]);
|
|
if (err) {
|
|
dev_err(&pdev->dev, "ACPI resource conflict!\n");
|
|
return err;
|
|
}
|
|
|
|
err = pci_request_region(pdev, SMBBAR, ismt_driver.name);
|
|
if (err) {
|
|
dev_err(&pdev->dev,
|
|
"Failed to request SMBus region 0x%lx-0x%lx\n",
|
|
start, start + len);
|
|
return err;
|
|
}
|
|
|
|
priv->smba = pcim_iomap(pdev, SMBBAR, len);
|
|
if (!priv->smba) {
|
|
dev_err(&pdev->dev, "Unable to ioremap SMBus BAR\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) ||
|
|
(pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) {
|
|
if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) ||
|
|
(pci_set_consistent_dma_mask(pdev,
|
|
DMA_BIT_MASK(32)) != 0)) {
|
|
dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n",
|
|
pdev);
|
|
return -ENODEV;
|
|
}
|
|
}
|
|
|
|
err = ismt_dev_init(priv);
|
|
if (err)
|
|
return err;
|
|
|
|
ismt_hw_init(priv);
|
|
|
|
err = ismt_int_init(priv);
|
|
if (err)
|
|
return err;
|
|
|
|
err = i2c_add_adapter(&priv->adapter);
|
|
if (err)
|
|
return -ENODEV;
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* ismt_remove() - release driver resources
|
|
* @pdev: PCI-Express device
|
|
*/
|
|
static void ismt_remove(struct pci_dev *pdev)
|
|
{
|
|
struct ismt_priv *priv = pci_get_drvdata(pdev);
|
|
|
|
i2c_del_adapter(&priv->adapter);
|
|
}
|
|
|
|
static struct pci_driver ismt_driver = {
|
|
.name = "ismt_smbus",
|
|
.id_table = ismt_ids,
|
|
.probe = ismt_probe,
|
|
.remove = ismt_remove,
|
|
};
|
|
|
|
module_pci_driver(ismt_driver);
|
|
|
|
MODULE_LICENSE("Dual BSD/GPL");
|
|
MODULE_AUTHOR("Bill E. Brown <bill.e.brown@intel.com>");
|
|
MODULE_DESCRIPTION("Intel SMBus Message Transport (iSMT) driver");
|