Changes in 4.9.238 af_key: pfkey_dump needs parameter validation KVM: fix memory leak in kvm_io_bus_unregister_dev() kprobes: fix kill kprobe which has been marked as gone RDMA/ucma: ucma_context reference leak in error path mtd: Fix comparison in map_word_andequal() hdlc_ppp: add range checks in ppp_cp_parse_cr() ip: fix tos reflection in ack and reset packets tipc: use skb_unshare() instead in tipc_buf_append() bnxt_en: Protect bnxt_set_eee() and bnxt_set_pauseparam() with mutex. net: phy: Avoid NPD upon phy_detach() when driver is unbound net/hsr: Check skb_put_padto() return value net: add __must_check to skb_put_padto() serial: 8250: Avoid error message on reprobe scsi: aacraid: fix illegal IO beyond last LBA m68k: q40: Fix info-leak in rtc_ioctl gma/gma500: fix a memory disclosure bug due to uninitialized bytes ASoC: kirkwood: fix IRQ error handling ALSA: usb-audio: Add delay quirk for H570e USB headsets PM / devfreq: tegra30: Fix integer overflow on CPU's freq max out clk/ti/adpll: allocate room for terminating null mtd: cfi_cmdset_0002: don't free cfi->cfiq in error path of cfi_amdstd_setup() mfd: mfd-core: Protect against NULL call-back function pointer tracing: Adding NULL checks for trace_array descriptor pointer bcache: fix a lost wake-up problem caused by mca_cannibalize_lock RDMA/i40iw: Fix potential use after free xfs: fix attr leaf header freemap.size underflow RDMA/iw_cgxb4: Fix an error handling path in 'c4iw_connect()' debugfs: Fix !DEBUG_FS debugfs_create_automount CIFS: Properly process SMB3 lease breaks kernel/sys.c: avoid copying possible padding bytes in copy_to_user neigh_stat_seq_next() should increase position index rt_cpu_seq_next should increase position index seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier media: ti-vpe: cal: Restrict DMA to avoid memory corruption ACPI: EC: Reference count query handlers under lock dmaengine: zynqmp_dma: fix burst length configuration tracing: Set kernel_stack's caller size properly ar5523: Add USB ID of SMCWUSBT-G2 wireless adapter Bluetooth: Fix refcount use-after-free issue mm: pagewalk: fix termination condition in walk_pte_range() Bluetooth: prefetch channel before killing sock KVM: fix overflow of zero page refcount with ksm running ALSA: hda: Clear RIRB status before reading WP skbuff: fix a data race in skb_queue_len() audit: CONFIG_CHANGE don't log internal bookkeeping as an event selinux: sel_avc_get_stat_idx should increase position index scsi: lpfc: Fix RQ buffer leakage when no IOCBs available scsi: lpfc: Fix coverity errors in fmdi attribute handling drm/omap: fix possible object reference leak RDMA/rxe: Fix configuration of atomic queue pair attributes KVM: x86: fix incorrect comparison in trace event x86/pkeys: Add check for pkey "overflow" bpf: Remove recursion prevention from rcu free callback dmaengine: tegra-apb: Prevent race conditions on channel's freeing media: go7007: Fix URB type for interrupt handling Bluetooth: guard against controllers sending zero'd events timekeeping: Prevent 32bit truncation in scale64_check_overflow() drm/amdgpu: increase atombios cmd timeout Bluetooth: L2CAP: handle l2cap config request during open state media: tda10071: fix unsigned sign extension overflow xfs: don't ever return a stale pointer from __xfs_dir3_free_read tpm: ibmvtpm: Wait for buffer to be set before proceeding tracing: Use address-of operator on section symbols serial: 8250_port: Don't service RX FIFO if throttled serial: 8250_omap: Fix sleeping function called from invalid context during probe serial: 8250: 8250_omap: Terminate DMA before pushing data on RX timeout cpufreq: powernv: Fix frame-size-overflow in powernv_cpufreq_work_fn tools: gpio-hammer: Avoid potential overflow in main SUNRPC: Fix a potential buffer overflow in 'svc_print_xprts()' svcrdma: Fix leak of transport addresses ubifs: Fix out-of-bounds memory access caused by abnormal value of node_len ALSA: usb-audio: Fix case when USB MIDI interface has more than one extra endpoint descriptor mm/filemap.c: clear page error before actual read mm/mmap.c: initialize align_offset explicitly for vm_unmapped_area KVM: Remove CREATE_IRQCHIP/SET_PIT2 race bdev: Reduce time holding bd_mutex in sync in blkdev_close() drivers: char: tlclk.c: Avoid data race between init and interrupt handler dt-bindings: sound: wm8994: Correct required supplies based on actual implementaion atm: fix a memory leak of vcc->user_back phy: samsung: s5pv210-usb2: Add delay after reset Bluetooth: Handle Inquiry Cancel error after Inquiry Complete USB: EHCI: ehci-mv: fix error handling in mv_ehci_probe() tty: serial: samsung: Correct clock selection logic ALSA: hda: Fix potential race in unsol event handler fuse: don't check refcount after stealing page USB: EHCI: ehci-mv: fix less than zero comparison of an unsigned int e1000: Do not perform reset in reset_task if we are already down printk: handle blank console arguments passed in. btrfs: don't force read-only after error in drop snapshot vfio/pci: fix memory leaks of eventfd ctx perf util: Fix memory leak of prefix_if_not_in perf kcore_copy: Fix module map when there are no modules loaded mtd: rawnand: omap_elm: Fix runtime PM imbalance on error ceph: fix potential race in ceph_check_caps mtd: parser: cmdline: Support MTD names containing one or more colons x86/speculation/mds: Mark mds_user_clear_cpu_buffers() __always_inline vfio/pci: Clear error and request eventfd ctx after releasing cifs: Fix double add page to memcg when cifs_readpages selftests/x86/syscall_nt: Clear weird flags after each test vfio/pci: fix racy on error and request eventfd ctx s390/init: add missing __init annotations i2c: core: Call i2c_acpi_install_space_handler() before i2c_acpi_register_devices() objtool: Fix noreturn detection for ignored functions ieee802154/adf7242: check status of adf7242_read_reg clocksource/drivers/h8300_timer8: Fix wrong return value in h8300_8timer_init() mwifiex: Increase AES key storage size to 256 bits batman-adv: bla: fix type misuse for backbone_gw hash indexing atm: eni: fix the missed pci_disable_device() for eni_init_one() batman-adv: mcast/TT: fix wrongly dropped or rerouted packets mac802154: tx: fix use-after-free batman-adv: Add missing include for in_interrupt() batman-adv: mcast: fix duplicate mcast packets in BLA backbone from mesh ALSA: asihpi: fix iounmap in error handler MIPS: Add the missing 'CPU_1074K' into __get_cpu_type() kprobes: Fix to check probe enabled before disarm_kprobe_ftrace() lib/string.c: implement stpcpy ata: define AC_ERR_OK ata: make qc_prep return ata_completion_errors ata: sata_mv, avoid trigerrable BUG_ON Linux 4.9.238 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I799877db3bc49e473bbc023ab948cd241755beff
347 lines
8.8 KiB
C
347 lines
8.8 KiB
C
/*
|
|
* Generic PXA PATA driver
|
|
*
|
|
* Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
|
|
*
|
|
* 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, 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; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/ata.h>
|
|
#include <linux/libata.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/dmaengine.h>
|
|
#include <linux/dma/pxa-dma.h>
|
|
#include <linux/gpio.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/completion.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <linux/platform_data/ata-pxa.h>
|
|
|
|
#define DRV_NAME "pata_pxa"
|
|
#define DRV_VERSION "0.1"
|
|
|
|
struct pata_pxa_data {
|
|
struct dma_chan *dma_chan;
|
|
dma_cookie_t dma_cookie;
|
|
struct completion dma_done;
|
|
};
|
|
|
|
/*
|
|
* DMA interrupt handler.
|
|
*/
|
|
static void pxa_ata_dma_irq(void *d)
|
|
{
|
|
struct pata_pxa_data *pd = d;
|
|
enum dma_status status;
|
|
|
|
status = dmaengine_tx_status(pd->dma_chan, pd->dma_cookie, NULL);
|
|
if (status == DMA_ERROR || status == DMA_COMPLETE)
|
|
complete(&pd->dma_done);
|
|
}
|
|
|
|
/*
|
|
* Prepare taskfile for submission.
|
|
*/
|
|
static enum ata_completion_errors pxa_qc_prep(struct ata_queued_cmd *qc)
|
|
{
|
|
struct pata_pxa_data *pd = qc->ap->private_data;
|
|
struct dma_async_tx_descriptor *tx;
|
|
enum dma_transfer_direction dir;
|
|
|
|
if (!(qc->flags & ATA_QCFLAG_DMAMAP))
|
|
return AC_ERR_OK;
|
|
|
|
dir = (qc->dma_dir == DMA_TO_DEVICE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM);
|
|
tx = dmaengine_prep_slave_sg(pd->dma_chan, qc->sg, qc->n_elem, dir,
|
|
DMA_PREP_INTERRUPT);
|
|
if (!tx) {
|
|
ata_dev_err(qc->dev, "prep_slave_sg() failed\n");
|
|
return AC_ERR_OK;
|
|
}
|
|
tx->callback = pxa_ata_dma_irq;
|
|
tx->callback_param = pd;
|
|
pd->dma_cookie = dmaengine_submit(tx);
|
|
|
|
return AC_ERR_OK;
|
|
}
|
|
|
|
/*
|
|
* Configure the DMA controller, load the DMA descriptors, but don't start the
|
|
* DMA controller yet. Only issue the ATA command.
|
|
*/
|
|
static void pxa_bmdma_setup(struct ata_queued_cmd *qc)
|
|
{
|
|
qc->ap->ops->sff_exec_command(qc->ap, &qc->tf);
|
|
}
|
|
|
|
/*
|
|
* Execute the DMA transfer.
|
|
*/
|
|
static void pxa_bmdma_start(struct ata_queued_cmd *qc)
|
|
{
|
|
struct pata_pxa_data *pd = qc->ap->private_data;
|
|
init_completion(&pd->dma_done);
|
|
dma_async_issue_pending(pd->dma_chan);
|
|
}
|
|
|
|
/*
|
|
* Wait until the DMA transfer completes, then stop the DMA controller.
|
|
*/
|
|
static void pxa_bmdma_stop(struct ata_queued_cmd *qc)
|
|
{
|
|
struct pata_pxa_data *pd = qc->ap->private_data;
|
|
enum dma_status status;
|
|
|
|
status = dmaengine_tx_status(pd->dma_chan, pd->dma_cookie, NULL);
|
|
if (status != DMA_ERROR && status != DMA_COMPLETE &&
|
|
wait_for_completion_timeout(&pd->dma_done, HZ))
|
|
ata_dev_err(qc->dev, "Timeout waiting for DMA completion!");
|
|
|
|
dmaengine_terminate_all(pd->dma_chan);
|
|
}
|
|
|
|
/*
|
|
* Read DMA status. The bmdma_stop() will take care of properly finishing the
|
|
* DMA transfer so we always have DMA-complete interrupt here.
|
|
*/
|
|
static unsigned char pxa_bmdma_status(struct ata_port *ap)
|
|
{
|
|
struct pata_pxa_data *pd = ap->private_data;
|
|
unsigned char ret = ATA_DMA_INTR;
|
|
struct dma_tx_state state;
|
|
enum dma_status status;
|
|
|
|
status = dmaengine_tx_status(pd->dma_chan, pd->dma_cookie, &state);
|
|
if (status != DMA_COMPLETE)
|
|
ret |= ATA_DMA_ERR;
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* No IRQ register present so we do nothing.
|
|
*/
|
|
static void pxa_irq_clear(struct ata_port *ap)
|
|
{
|
|
}
|
|
|
|
/*
|
|
* Check for ATAPI DMA. ATAPI DMA is unsupported by this driver. It's still
|
|
* unclear why ATAPI has DMA issues.
|
|
*/
|
|
static int pxa_check_atapi_dma(struct ata_queued_cmd *qc)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static struct scsi_host_template pxa_ata_sht = {
|
|
ATA_BMDMA_SHT(DRV_NAME),
|
|
};
|
|
|
|
static struct ata_port_operations pxa_ata_port_ops = {
|
|
.inherits = &ata_bmdma_port_ops,
|
|
.cable_detect = ata_cable_40wire,
|
|
|
|
.bmdma_setup = pxa_bmdma_setup,
|
|
.bmdma_start = pxa_bmdma_start,
|
|
.bmdma_stop = pxa_bmdma_stop,
|
|
.bmdma_status = pxa_bmdma_status,
|
|
|
|
.check_atapi_dma = pxa_check_atapi_dma,
|
|
|
|
.sff_irq_clear = pxa_irq_clear,
|
|
|
|
.qc_prep = pxa_qc_prep,
|
|
};
|
|
|
|
static int pxa_ata_probe(struct platform_device *pdev)
|
|
{
|
|
struct ata_host *host;
|
|
struct ata_port *ap;
|
|
struct pata_pxa_data *data;
|
|
struct resource *cmd_res;
|
|
struct resource *ctl_res;
|
|
struct resource *dma_res;
|
|
struct resource *irq_res;
|
|
struct pata_pxa_pdata *pdata = dev_get_platdata(&pdev->dev);
|
|
struct dma_slave_config config;
|
|
dma_cap_mask_t mask;
|
|
struct pxad_param param;
|
|
int ret = 0;
|
|
|
|
/*
|
|
* Resource validation, three resources are needed:
|
|
* - CMD port base address
|
|
* - CTL port base address
|
|
* - DMA port base address
|
|
* - IRQ pin
|
|
*/
|
|
if (pdev->num_resources != 4) {
|
|
dev_err(&pdev->dev, "invalid number of resources\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/*
|
|
* CMD port base address
|
|
*/
|
|
cmd_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (unlikely(cmd_res == NULL))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* CTL port base address
|
|
*/
|
|
ctl_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
if (unlikely(ctl_res == NULL))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* DMA port base address
|
|
*/
|
|
dma_res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
|
|
if (unlikely(dma_res == NULL))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* IRQ pin
|
|
*/
|
|
irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
if (unlikely(irq_res == NULL))
|
|
return -EINVAL;
|
|
|
|
/*
|
|
* Allocate the host
|
|
*/
|
|
host = ata_host_alloc(&pdev->dev, 1);
|
|
if (!host)
|
|
return -ENOMEM;
|
|
|
|
ap = host->ports[0];
|
|
ap->ops = &pxa_ata_port_ops;
|
|
ap->pio_mask = ATA_PIO4;
|
|
ap->mwdma_mask = ATA_MWDMA2;
|
|
|
|
ap->ioaddr.cmd_addr = devm_ioremap(&pdev->dev, cmd_res->start,
|
|
resource_size(cmd_res));
|
|
ap->ioaddr.ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
|
|
resource_size(ctl_res));
|
|
ap->ioaddr.bmdma_addr = devm_ioremap(&pdev->dev, dma_res->start,
|
|
resource_size(dma_res));
|
|
|
|
/*
|
|
* Adjust register offsets
|
|
*/
|
|
ap->ioaddr.altstatus_addr = ap->ioaddr.ctl_addr;
|
|
ap->ioaddr.data_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_DATA << pdata->reg_shift);
|
|
ap->ioaddr.error_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_ERR << pdata->reg_shift);
|
|
ap->ioaddr.feature_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_FEATURE << pdata->reg_shift);
|
|
ap->ioaddr.nsect_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_NSECT << pdata->reg_shift);
|
|
ap->ioaddr.lbal_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_LBAL << pdata->reg_shift);
|
|
ap->ioaddr.lbam_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_LBAM << pdata->reg_shift);
|
|
ap->ioaddr.lbah_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_LBAH << pdata->reg_shift);
|
|
ap->ioaddr.device_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_DEVICE << pdata->reg_shift);
|
|
ap->ioaddr.status_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_STATUS << pdata->reg_shift);
|
|
ap->ioaddr.command_addr = ap->ioaddr.cmd_addr +
|
|
(ATA_REG_CMD << pdata->reg_shift);
|
|
|
|
/*
|
|
* Allocate and load driver's internal data structure
|
|
*/
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct pata_pxa_data),
|
|
GFP_KERNEL);
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
ap->private_data = data;
|
|
|
|
dma_cap_zero(mask);
|
|
dma_cap_set(DMA_SLAVE, mask);
|
|
param.prio = PXAD_PRIO_LOWEST;
|
|
param.drcmr = pdata->dma_dreq;
|
|
memset(&config, 0, sizeof(config));
|
|
config.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
|
config.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
|
config.src_addr = dma_res->start;
|
|
config.dst_addr = dma_res->start;
|
|
config.src_maxburst = 32;
|
|
config.dst_maxburst = 32;
|
|
|
|
/*
|
|
* Request the DMA channel
|
|
*/
|
|
data->dma_chan =
|
|
dma_request_slave_channel_compat(mask, pxad_filter_fn,
|
|
¶m, &pdev->dev, "data");
|
|
if (!data->dma_chan)
|
|
return -EBUSY;
|
|
ret = dmaengine_slave_config(data->dma_chan, &config);
|
|
if (ret < 0) {
|
|
dev_err(&pdev->dev, "dma configuration failed: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Activate the ATA host
|
|
*/
|
|
ret = ata_host_activate(host, irq_res->start, ata_sff_interrupt,
|
|
pdata->irq_flags, &pxa_ata_sht);
|
|
if (ret)
|
|
dma_release_channel(data->dma_chan);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int pxa_ata_remove(struct platform_device *pdev)
|
|
{
|
|
struct ata_host *host = platform_get_drvdata(pdev);
|
|
struct pata_pxa_data *data = host->ports[0]->private_data;
|
|
|
|
dma_release_channel(data->dma_chan);
|
|
|
|
ata_host_detach(host);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver pxa_ata_driver = {
|
|
.probe = pxa_ata_probe,
|
|
.remove = pxa_ata_remove,
|
|
.driver = {
|
|
.name = DRV_NAME,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(pxa_ata_driver);
|
|
|
|
MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
|
|
MODULE_DESCRIPTION("DMA-capable driver for PATA on PXA CPU");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_VERSION(DRV_VERSION);
|
|
MODULE_ALIAS("platform:" DRV_NAME);
|