^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Xilinx SystemACE device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2007 Secret Lab Technologies Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * The SystemACE chip is designed to configure FPGAs by loading an FPGA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * bitstream from a file on a CF card and squirting it into FPGAs connected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * to the SystemACE JTAG chain. It also has the advantage of providing an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * MPU interface which can be used to control the FPGA configuration process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * and to use the attached CF card for general purpose storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * This driver is a block device driver for the SystemACE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Initialization:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * The driver registers itself as a platform_device driver at module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * load time. The platform bus will take care of calling the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * ace_probe() method for all SystemACE instances in the system. Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * number of SystemACE instances are supported. ace_probe() calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * ace_setup() which initialized all data structures, reads the CF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * id structure and registers the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Processing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Just about all of the heavy lifting in this driver is performed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * a Finite State Machine (FSM). The driver needs to wait on a number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * of events; some raised by interrupts, some which need to be polled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * for. Describing all of the behaviour in a FSM seems to be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * easiest way to keep the complexity low and make it easy to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * understand what the driver is doing. If the block ops or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * request function need to interact with the hardware, then they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * simply need to flag the request and kick of FSM processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * The FSM itself is atomic-safe code which can be run from any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * context. The general process flow is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * 1. obtain the ace->lock spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * 2. loop on ace_fsm_dostate() until the ace->fsm_continue flag is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * 3. release the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Individual states do not sleep in any way. If a condition needs to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * be waited for then the state much clear the fsm_continue flag and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * either schedule the FSM to be run again at a later time, or expect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * an interrupt to call the FSM when the desired condition is met.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * In normal operation, the FSM is processed at interrupt context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * either when the driver's tasklet is scheduled, or when an irq is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * raised by the hardware. The tasklet can be scheduled at any time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * The request method in particular schedules the tasklet when a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * request has been indicated by the block layer. Once started, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * FSM proceeds as far as it can processing the request until it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * needs on a hardware event. At this point, it must yield execution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * A state has two options when yielding execution:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * 1. ace_fsm_yield()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * - Call if need to poll for event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * - clears the fsm_continue flag to exit the processing loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * - reschedules the tasklet to run again as soon as possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * 2. ace_fsm_yieldirq()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * - Call if an irq is expected from the HW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * - clears the fsm_continue flag to exit the processing loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * - does not reschedule the tasklet so the FSM will not be processed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * again until an irq is received.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * After calling a yield function, the state must return control back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * to the FSM main loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Additionally, the driver maintains a kernel timer which can process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * the FSM. If the FSM gets stalled, typically due to a missed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * interrupt, then the kernel timer will expire and the driver can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * continue where it left off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * To Do:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * - Add FPGA configuration control interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * - Request major number from lanana
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #include <linux/ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) MODULE_DESCRIPTION("Xilinx SystemACE device driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* SystemACE register definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define ACE_BUSMODE (0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define ACE_STATUS (0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define ACE_STATUS_CFGLOCK (0x00000001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define ACE_STATUS_MPULOCK (0x00000002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define ACE_STATUS_CFGERROR (0x00000004) /* config controller error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define ACE_STATUS_CFCERROR (0x00000008) /* CF controller error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define ACE_STATUS_CFDETECT (0x00000010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define ACE_STATUS_DATABUFRDY (0x00000020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define ACE_STATUS_DATABUFMODE (0x00000040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define ACE_STATUS_CFGDONE (0x00000080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define ACE_STATUS_RDYFORCFCMD (0x00000100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define ACE_STATUS_CFGMODEPIN (0x00000200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define ACE_STATUS_CFGADDR_MASK (0x0000e000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define ACE_STATUS_CFBSY (0x00020000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define ACE_STATUS_CFRDY (0x00040000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define ACE_STATUS_CFDWF (0x00080000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define ACE_STATUS_CFDSC (0x00100000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define ACE_STATUS_CFDRQ (0x00200000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define ACE_STATUS_CFCORR (0x00400000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define ACE_STATUS_CFERR (0x00800000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define ACE_ERROR (0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define ACE_CFGLBA (0x0c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define ACE_MPULBA (0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define ACE_SECCNTCMD (0x14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #define ACE_SECCNTCMD_RESET (0x0100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define ACE_SECCNTCMD_IDENTIFY (0x0200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define ACE_SECCNTCMD_READ_DATA (0x0300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define ACE_SECCNTCMD_WRITE_DATA (0x0400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define ACE_SECCNTCMD_ABORT (0x0600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define ACE_VERSION (0x16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define ACE_VERSION_REVISION_MASK (0x00FF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define ACE_VERSION_MINOR_MASK (0x0F00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define ACE_VERSION_MAJOR_MASK (0xF000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define ACE_CTRL (0x18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define ACE_CTRL_FORCELOCKREQ (0x0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define ACE_CTRL_LOCKREQ (0x0002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define ACE_CTRL_FORCECFGADDR (0x0004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define ACE_CTRL_FORCECFGMODE (0x0008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define ACE_CTRL_CFGMODE (0x0010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define ACE_CTRL_CFGSTART (0x0020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define ACE_CTRL_CFGSEL (0x0040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define ACE_CTRL_CFGRESET (0x0080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define ACE_CTRL_DATABUFRDYIRQ (0x0100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define ACE_CTRL_ERRORIRQ (0x0200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define ACE_CTRL_CFGDONEIRQ (0x0400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define ACE_CTRL_RESETIRQ (0x0800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define ACE_CTRL_CFGPROG (0x1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define ACE_CTRL_CFGADDR_MASK (0xe000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define ACE_FATSTAT (0x1c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define ACE_NUM_MINORS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define ACE_SECTOR_SIZE (512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #define ACE_FIFO_SIZE (32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #define ACE_BUS_WIDTH_8 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define ACE_BUS_WIDTH_16 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct ace_reg_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ace_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* driver state data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int media_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int users;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* finite state machine data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct tasklet_struct fsm_tasklet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) uint fsm_task; /* Current activity (ACE_TASK_*) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) uint fsm_state; /* Current state (ACE_FSM_STATE_*) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) uint fsm_continue_flag; /* cleared to exit FSM mainloop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) uint fsm_iter_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct timer_list stall_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Transfer state/result, use for both id and block request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct request *req; /* request being processed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void *data_ptr; /* pointer to I/O buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int data_count; /* number of buffers remaining */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int data_result; /* Result of transfer; 0 := success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int id_req_count; /* count of id requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int id_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct completion id_completion; /* used when id req finishes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int in_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* Details of hardware device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) resource_size_t physaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) void __iomem *baseaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int bus_width; /* 0 := 8 bit; 1 := 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct ace_reg_ops *reg_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int lock_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Block device data structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct request_queue *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct gendisk *gd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct blk_mq_tag_set tag_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct list_head rq_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Inserted CF card parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) u16 cf_id[ATA_ID_WORDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static DEFINE_MUTEX(xsysace_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int ace_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * Low level register access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct ace_reg_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) u16(*in) (struct ace_device * ace, int reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) void (*out) (struct ace_device * ace, int reg, u16 val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) void (*datain) (struct ace_device * ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void (*dataout) (struct ace_device * ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* 8 Bit bus width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static u16 ace_in_8(struct ace_device *ace, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void __iomem *r = ace->baseaddr + reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return in_8(r) | (in_8(r + 1) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static void ace_out_8(struct ace_device *ace, int reg, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void __iomem *r = ace->baseaddr + reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) out_8(r, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) out_8(r + 1, val >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static void ace_datain_8(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) void __iomem *r = ace->baseaddr + 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u8 *dst = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int i = ACE_FIFO_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) *dst++ = in_8(r++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ace->data_ptr = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void ace_dataout_8(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void __iomem *r = ace->baseaddr + 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) u8 *src = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int i = ACE_FIFO_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) out_8(r++, *src++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) ace->data_ptr = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static struct ace_reg_ops ace_reg_8_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .in = ace_in_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .out = ace_out_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .datain = ace_datain_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .dataout = ace_dataout_8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* 16 bit big endian bus attachment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static u16 ace_in_be16(struct ace_device *ace, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return in_be16(ace->baseaddr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static void ace_out_be16(struct ace_device *ace, int reg, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) out_be16(ace->baseaddr + reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static void ace_datain_be16(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int i = ACE_FIFO_SIZE / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u16 *dst = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *dst++ = in_le16(ace->baseaddr + 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ace->data_ptr = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static void ace_dataout_be16(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int i = ACE_FIFO_SIZE / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) u16 *src = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) out_le16(ace->baseaddr + 0x40, *src++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ace->data_ptr = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* 16 bit little endian bus attachment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static u16 ace_in_le16(struct ace_device *ace, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return in_le16(ace->baseaddr + reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void ace_out_le16(struct ace_device *ace, int reg, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) out_le16(ace->baseaddr + reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static void ace_datain_le16(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int i = ACE_FIFO_SIZE / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) u16 *dst = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) *dst++ = in_be16(ace->baseaddr + 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) ace->data_ptr = dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static void ace_dataout_le16(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) int i = ACE_FIFO_SIZE / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u16 *src = ace->data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) out_be16(ace->baseaddr + 0x40, *src++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) ace->data_ptr = src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) static struct ace_reg_ops ace_reg_be16_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .in = ace_in_be16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .out = ace_out_be16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .datain = ace_datain_be16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .dataout = ace_dataout_be16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static struct ace_reg_ops ace_reg_le16_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .in = ace_in_le16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .out = ace_out_le16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .datain = ace_datain_le16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .dataout = ace_dataout_le16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static inline u16 ace_in(struct ace_device *ace, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return ace->reg_ops->in(ace, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) static inline u32 ace_in32(struct ace_device *ace, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return ace_in(ace, reg) | (ace_in(ace, reg + 2) << 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static inline void ace_out(struct ace_device *ace, int reg, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) ace->reg_ops->out(ace, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) static inline void ace_out32(struct ace_device *ace, int reg, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) ace_out(ace, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ace_out(ace, reg + 2, val >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * Debug support functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #if defined(DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static void ace_dump_mem(void *base, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) const char *ptr = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) for (i = 0; i < len; i += 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) printk(KERN_INFO "%.8x:", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) for (j = 0; j < 16; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!(j % 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) printk(" ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) printk("%.2x", ptr[i + j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) printk(" ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) for (j = 0; j < 16; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) printk("%c", isprint(ptr[i + j]) ? ptr[i + j] : '.');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static inline void ace_dump_mem(void *base, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static void ace_dump_regs(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) dev_info(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) " ctrl: %.8x seccnt/cmd: %.4x ver:%.4x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) " status:%.8x mpu_lba:%.8x busmode:%4x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) " error: %.8x cfg_lba:%.8x fatstat:%.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) ace_in32(ace, ACE_CTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ace_in(ace, ACE_SECCNTCMD),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ace_in(ace, ACE_VERSION),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ace_in32(ace, ACE_STATUS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ace_in32(ace, ACE_MPULBA),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ace_in(ace, ACE_BUSMODE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ace_in32(ace, ACE_ERROR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ace_in32(ace, ACE_CFGLBA), ace_in(ace, ACE_FATSTAT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static void ace_fix_driveid(u16 *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #if defined(__BIG_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* All half words have wrong byte order; swap the bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) for (i = 0; i < ATA_ID_WORDS; i++, id++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) *id = le16_to_cpu(*id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * Finite State Machine (FSM) implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* FSM tasks; used to direct state transitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) #define ACE_TASK_IDLE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #define ACE_TASK_IDENTIFY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) #define ACE_TASK_READ 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) #define ACE_TASK_WRITE 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) #define ACE_FSM_NUM_TASKS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) /* FSM state definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #define ACE_FSM_STATE_IDLE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) #define ACE_FSM_STATE_REQ_LOCK 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) #define ACE_FSM_STATE_WAIT_LOCK 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) #define ACE_FSM_STATE_WAIT_CFREADY 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #define ACE_FSM_STATE_IDENTIFY_PREPARE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) #define ACE_FSM_STATE_IDENTIFY_TRANSFER 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #define ACE_FSM_STATE_IDENTIFY_COMPLETE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) #define ACE_FSM_STATE_REQ_PREPARE 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #define ACE_FSM_STATE_REQ_TRANSFER 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #define ACE_FSM_STATE_REQ_COMPLETE 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) #define ACE_FSM_STATE_ERROR 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) #define ACE_FSM_NUM_STATES 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* Set flag to exit FSM loop and reschedule tasklet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static inline void ace_fsm_yieldpoll(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) tasklet_schedule(&ace->fsm_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) ace->fsm_continue_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline void ace_fsm_yield(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) dev_dbg(ace->dev, "%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) ace_fsm_yieldpoll(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* Set flag to exit FSM loop and wait for IRQ to reschedule tasklet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static inline void ace_fsm_yieldirq(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) dev_dbg(ace->dev, "ace_fsm_yieldirq()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (ace->irq > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ace->fsm_continue_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) ace_fsm_yieldpoll(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static bool ace_has_next_request(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct ace_device *ace = q->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return !list_empty(&ace->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* Get the next read/write request; ending requests that we don't handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static struct request *ace_get_next_request(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct ace_device *ace = q->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) rq = list_first_entry_or_null(&ace->rq_list, struct request, queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (rq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) list_del_init(&rq->queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) blk_mq_start_request(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void ace_fsm_dostate(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) u32 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) #if defined(DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) dev_dbg(ace->dev, "fsm_state=%i, id_req_count=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ace->fsm_state, ace->id_req_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) /* Verify that there is actually a CF in the slot. If not, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * bail out back to the idle state and wake up all the waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) status = ace_in32(ace, ACE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if ((status & ACE_STATUS_CFDETECT) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ace->media_change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) set_capacity(ace->gd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) dev_info(ace->dev, "No CF in slot\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* Drop all in-flight and pending requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (ace->req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) blk_mq_end_request(ace->req, BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) ace->req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) while ((req = ace_get_next_request(ace->queue)) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) blk_mq_end_request(req, BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* Drop back to IDLE state and notify waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) ace->id_result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) while (ace->id_req_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) complete(&ace->id_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) ace->id_req_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) switch (ace->fsm_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) case ACE_FSM_STATE_IDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* See if there is anything to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (ace->id_req_count || ace_has_next_request(ace->queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) ace->fsm_iter_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) ace->fsm_state = ACE_FSM_STATE_REQ_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) mod_timer(&ace->stall_timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (!timer_pending(&ace->stall_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) add_timer(&ace->stall_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) del_timer(&ace->stall_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) ace->fsm_continue_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) case ACE_FSM_STATE_REQ_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (ace_in(ace, ACE_STATUS) & ACE_STATUS_MPULOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Already have the lock, jump to next state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ace->fsm_state = ACE_FSM_STATE_WAIT_CFREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* Request the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) val = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) ace_out(ace, ACE_CTRL, val | ACE_CTRL_LOCKREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ace->fsm_state = ACE_FSM_STATE_WAIT_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) case ACE_FSM_STATE_WAIT_LOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (ace_in(ace, ACE_STATUS) & ACE_STATUS_MPULOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* got the lock; move to next state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ace->fsm_state = ACE_FSM_STATE_WAIT_CFREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /* wait a bit for the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) ace_fsm_yield(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) case ACE_FSM_STATE_WAIT_CFREADY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) status = ace_in32(ace, ACE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!(status & ACE_STATUS_RDYFORCFCMD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) (status & ACE_STATUS_CFBSY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) /* CF card isn't ready; it needs to be polled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ace_fsm_yield(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* Device is ready for command; determine what to do next */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (ace->id_req_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) ace->fsm_state = ACE_FSM_STATE_IDENTIFY_PREPARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ace->fsm_state = ACE_FSM_STATE_REQ_PREPARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) case ACE_FSM_STATE_IDENTIFY_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* Send identify command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) ace->fsm_task = ACE_TASK_IDENTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ace->data_ptr = ace->cf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ace->data_count = ACE_BUF_PER_SECTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ace_out(ace, ACE_SECCNTCMD, ACE_SECCNTCMD_IDENTIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* As per datasheet, put config controller in reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) val = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) ace_out(ace, ACE_CTRL, val | ACE_CTRL_CFGRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /* irq handler takes over from this point; wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * transfer to complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) ace->fsm_state = ACE_FSM_STATE_IDENTIFY_TRANSFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) ace_fsm_yieldirq(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) case ACE_FSM_STATE_IDENTIFY_TRANSFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* Check that the sysace is ready to receive data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) status = ace_in32(ace, ACE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (status & ACE_STATUS_CFBSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) dev_dbg(ace->dev, "CFBSY set; t=%i iter=%i dc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) ace->fsm_task, ace->fsm_iter_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ace->data_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) ace_fsm_yield(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (!(status & ACE_STATUS_DATABUFRDY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) ace_fsm_yield(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /* Transfer the next buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ace->reg_ops->datain(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) ace->data_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* If there are still buffers to be transfers; jump out here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (ace->data_count != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) ace_fsm_yieldirq(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* transfer finished; kick state machine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) dev_dbg(ace->dev, "identify finished\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ace->fsm_state = ACE_FSM_STATE_IDENTIFY_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) case ACE_FSM_STATE_IDENTIFY_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ace_fix_driveid(ace->cf_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) ace_dump_mem(ace->cf_id, 512); /* Debug: Dump out disk ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (ace->data_result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* Error occurred, disable the disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) ace->media_change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) set_capacity(ace->gd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) dev_err(ace->dev, "error fetching CF id (%i)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) ace->data_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) ace->media_change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* Record disk parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) set_capacity(ace->gd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) ata_id_u32(ace->cf_id, ATA_ID_LBA_CAPACITY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) dev_info(ace->dev, "capacity: %i sectors\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) ata_id_u32(ace->cf_id, ATA_ID_LBA_CAPACITY));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* We're done, drop to IDLE state and notify waiters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) ace->id_result = ace->data_result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) while (ace->id_req_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) complete(&ace->id_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) ace->id_req_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) case ACE_FSM_STATE_REQ_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) req = ace_get_next_request(ace->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) /* Okay, it's a data request, set it up for transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) dev_dbg(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) "request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) (unsigned long long)blk_rq_pos(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) blk_rq_sectors(req), blk_rq_cur_sectors(req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) rq_data_dir(req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) ace->req = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ace->data_ptr = bio_data(req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) ace->data_count = blk_rq_cur_sectors(req) * ACE_BUF_PER_SECTOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) ace_out32(ace, ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) count = blk_rq_sectors(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (rq_data_dir(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) /* Kick off write request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) dev_dbg(ace->dev, "write data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ace->fsm_task = ACE_TASK_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ace_out(ace, ACE_SECCNTCMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) count | ACE_SECCNTCMD_WRITE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Kick off read request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) dev_dbg(ace->dev, "read data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) ace->fsm_task = ACE_TASK_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) ace_out(ace, ACE_SECCNTCMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) count | ACE_SECCNTCMD_READ_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* As per datasheet, put config controller in reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) val = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ace_out(ace, ACE_CTRL, val | ACE_CTRL_CFGRESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* Move to the transfer state. The systemace will raise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) * an interrupt once there is something to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) ace->fsm_state = ACE_FSM_STATE_REQ_TRANSFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (ace->fsm_task == ACE_TASK_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) ace_fsm_yieldirq(ace); /* wait for data ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) case ACE_FSM_STATE_REQ_TRANSFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /* Check that the sysace is ready to receive data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) status = ace_in32(ace, ACE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (status & ACE_STATUS_CFBSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) dev_dbg(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) ace->fsm_task, ace->fsm_iter_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) blk_rq_cur_sectors(ace->req) * 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ace->data_count, ace->in_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) ace_fsm_yield(ace); /* need to poll CFBSY bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!(status & ACE_STATUS_DATABUFRDY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) dev_dbg(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) ace->fsm_task, ace->fsm_iter_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) blk_rq_cur_sectors(ace->req) * 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) ace->data_count, ace->in_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ace_fsm_yieldirq(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* Transfer the next buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (ace->fsm_task == ACE_TASK_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) ace->reg_ops->dataout(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) ace->reg_ops->datain(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) ace->data_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /* If there are still buffers to be transfers; jump out here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (ace->data_count != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ace_fsm_yieldirq(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* bio finished; is there another one? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (blk_update_request(ace->req, BLK_STS_OK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) blk_rq_cur_bytes(ace->req))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * blk_rq_sectors(ace->req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * blk_rq_cur_sectors(ace->req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) ace->data_ptr = bio_data(ace->req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) ace->data_count = blk_rq_cur_sectors(ace->req) * 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) ace_fsm_yieldirq(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) ace->fsm_state = ACE_FSM_STATE_REQ_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) case ACE_FSM_STATE_REQ_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) ace->req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* Finished request; go to idle state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) ace->fsm_state = ACE_FSM_STATE_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) static void ace_fsm_tasklet(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) struct ace_device *ace = (void *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) spin_lock_irqsave(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* Loop over state machine until told to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ace->fsm_continue_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) while (ace->fsm_continue_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) ace_fsm_dostate(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) spin_unlock_irqrestore(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static void ace_stall_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct ace_device *ace = from_timer(ace, t, stall_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) dev_warn(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) "kicking stalled fsm; state=%i task=%i iter=%i dc=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ace->fsm_state, ace->fsm_task, ace->fsm_iter_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) ace->data_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) spin_lock_irqsave(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* Rearm the stall timer *before* entering FSM (which may then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * delete the timer) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) mod_timer(&ace->stall_timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) /* Loop over state machine until told to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) ace->fsm_continue_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) while (ace->fsm_continue_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ace_fsm_dostate(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) spin_unlock_irqrestore(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * Interrupt handling routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static int ace_interrupt_checkstate(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) u32 sreg = ace_in32(ace, ACE_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) u16 creg = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) /* Check for error occurrence */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) if ((sreg & (ACE_STATUS_CFGERROR | ACE_STATUS_CFCERROR)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) (creg & ACE_CTRL_ERRORIRQ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) dev_err(ace->dev, "transfer failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) ace_dump_regs(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static irqreturn_t ace_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) u16 creg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct ace_device *ace = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) /* be safe and get the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) spin_lock(&ace->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) ace->in_irq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) /* clear the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) creg = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ace_out(ace, ACE_CTRL, creg | ACE_CTRL_RESETIRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) ace_out(ace, ACE_CTRL, creg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* check for IO failures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (ace_interrupt_checkstate(ace))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ace->data_result = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (ace->fsm_task == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) dev_err(ace->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) "spurious irq; stat=%.8x ctrl=%.8x cmd=%.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) ace_in32(ace, ACE_STATUS), ace_in32(ace, ACE_CTRL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) ace_in(ace, ACE_SECCNTCMD));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dev_err(ace->dev, "fsm_task=%i fsm_state=%i data_count=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) ace->fsm_task, ace->fsm_state, ace->data_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /* Loop over state machine until told to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ace->fsm_continue_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) while (ace->fsm_continue_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) ace_fsm_dostate(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /* done with interrupt; drop the lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) ace->in_irq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) spin_unlock(&ace->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) * Block ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) static blk_status_t ace_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) const struct blk_mq_queue_data *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) struct ace_device *ace = hctx->queue->queuedata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct request *req = bd->rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (blk_rq_is_passthrough(req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) blk_mq_start_request(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) spin_lock_irq(&ace->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) list_add_tail(&req->queuelist, &ace->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) spin_unlock_irq(&ace->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) tasklet_schedule(&ace->fsm_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) static unsigned int ace_check_events(struct gendisk *gd, unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct ace_device *ace = gd->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) dev_dbg(ace->dev, "ace_check_events(): %i\n", ace->media_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return ace->media_change ? DISK_EVENT_MEDIA_CHANGE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) static void ace_media_changed(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) dev_dbg(ace->dev, "requesting cf id and scheduling tasklet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) spin_lock_irqsave(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) ace->id_req_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) spin_unlock_irqrestore(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) tasklet_schedule(&ace->fsm_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) wait_for_completion(&ace->id_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) dev_dbg(ace->dev, "revalidate complete\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static int ace_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) struct ace_device *ace = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) mutex_lock(&xsysace_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) spin_lock_irqsave(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) ace->users++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) spin_unlock_irqrestore(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (bdev_check_media_change(bdev) && ace->media_change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) ace_media_changed(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) mutex_unlock(&xsysace_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) static void ace_release(struct gendisk *disk, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) struct ace_device *ace = disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) mutex_lock(&xsysace_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) spin_lock_irqsave(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ace->users--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (ace->users == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) val = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) spin_unlock_irqrestore(&ace->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) mutex_unlock(&xsysace_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) static int ace_getgeo(struct block_device *bdev, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) struct ace_device *ace = bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) u16 *cf_id = ace->cf_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) dev_dbg(ace->dev, "ace_getgeo()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) geo->heads = cf_id[ATA_ID_HEADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) geo->sectors = cf_id[ATA_ID_SECTORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) geo->cylinders = cf_id[ATA_ID_CYLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) static const struct block_device_operations ace_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) .open = ace_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) .release = ace_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) .check_events = ace_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .getgeo = ace_getgeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) static const struct blk_mq_ops ace_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) .queue_rq = ace_queue_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) /* --------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * SystemACE device setup/teardown code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) static int ace_setup(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) u16 version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) u16 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) dev_dbg(ace->dev, "ace_setup(ace=0x%p)\n", ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) dev_dbg(ace->dev, "physaddr=0x%llx irq=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) (unsigned long long)ace->physaddr, ace->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) spin_lock_init(&ace->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) init_completion(&ace->id_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) INIT_LIST_HEAD(&ace->rq_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * Map the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) ace->baseaddr = ioremap(ace->physaddr, 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!ace->baseaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) goto err_ioremap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * Initialize the state machine tasklet and stall timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) tasklet_init(&ace->fsm_tasklet, ace_fsm_tasklet, (unsigned long)ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) timer_setup(&ace->stall_timer, ace_stall_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * Initialize the request queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) ace->queue = blk_mq_init_sq_queue(&ace->tag_set, &ace_mq_ops, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) BLK_MQ_F_SHOULD_MERGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (IS_ERR(ace->queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) rc = PTR_ERR(ace->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ace->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) goto err_blk_initq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) ace->queue->queuedata = ace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) blk_queue_logical_block_size(ace->queue, 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) blk_queue_bounce_limit(ace->queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * Allocate and initialize GD structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) ace->gd = alloc_disk(ACE_NUM_MINORS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (!ace->gd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) goto err_alloc_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) ace->gd->major = ace_major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) ace->gd->first_minor = ace->id * ACE_NUM_MINORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) ace->gd->fops = &ace_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) ace->gd->events = DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) ace->gd->queue = ace->queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) ace->gd->private_data = ace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) snprintf(ace->gd->disk_name, 32, "xs%c", ace->id + 'a');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /* set bus width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (ace->bus_width == ACE_BUS_WIDTH_16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /* 0x0101 should work regardless of endianess */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) ace_out_le16(ace, ACE_BUSMODE, 0x0101);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) /* read it back to determine endianess */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (ace_in_le16(ace, ACE_BUSMODE) == 0x0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) ace->reg_ops = &ace_reg_le16_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) ace->reg_ops = &ace_reg_be16_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) ace_out_8(ace, ACE_BUSMODE, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) ace->reg_ops = &ace_reg_8_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) /* Make sure version register is sane */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) version = ace_in(ace, ACE_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) if ((version == 0) || (version == 0xFFFF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) goto err_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) /* Put sysace in a sane state by clearing most control reg bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) ace_out(ace, ACE_CTRL, ACE_CTRL_FORCECFGMODE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /* Now we can hook up the irq handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) if (ace->irq > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) /* Failure - fall back to polled mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) dev_err(ace->dev, "request_irq failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) ace->irq = rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /* Enable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) val = ace_in(ace, ACE_CTRL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) ace_out(ace, ACE_CTRL, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) /* Print the identification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) dev_info(ace->dev, "Xilinx SystemACE revision %i.%i.%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) (version >> 12) & 0xf, (version >> 8) & 0x0f, version & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) dev_dbg(ace->dev, "physaddr 0x%llx, mapped to 0x%p, irq=%i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) (unsigned long long) ace->physaddr, ace->baseaddr, ace->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) ace->media_change = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) ace_media_changed(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) /* Make the sysace device 'live' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) add_disk(ace->gd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) err_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) /* prevent double queue cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) ace->gd->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) put_disk(ace->gd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) err_alloc_disk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) blk_cleanup_queue(ace->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) blk_mq_free_tag_set(&ace->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) err_blk_initq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) iounmap(ace->baseaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) err_ioremap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) dev_info(ace->dev, "xsysace: error initializing device at 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) (unsigned long long) ace->physaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) static void ace_teardown(struct ace_device *ace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) if (ace->gd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) del_gendisk(ace->gd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) put_disk(ace->gd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) if (ace->queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) blk_cleanup_queue(ace->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) blk_mq_free_tag_set(&ace->tag_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) tasklet_kill(&ace->fsm_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (ace->irq > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) free_irq(ace->irq, ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) iounmap(ace->baseaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static int ace_alloc(struct device *dev, int id, resource_size_t physaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) int irq, int bus_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) struct ace_device *ace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) dev_dbg(dev, "ace_alloc(%p)\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) /* Allocate and initialize the ace device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if (!ace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) ace->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) ace->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) ace->physaddr = physaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) ace->irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) ace->bus_width = bus_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) /* Call the setup code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) rc = ace_setup(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) goto err_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) dev_set_drvdata(dev, ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) err_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) dev_set_drvdata(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) kfree(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) dev_err(dev, "could not initialize device, err=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static void ace_free(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) struct ace_device *ace = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) dev_dbg(dev, "ace_free(%p)\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (ace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) ace_teardown(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) dev_set_drvdata(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) kfree(ace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) * Platform Bus Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) static int ace_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) resource_size_t physaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) u32 id = dev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /* device id and bus width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (of_property_read_u32(dev->dev.of_node, "port-number", &id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (of_find_property(dev->dev.of_node, "8-bit", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) bus_width = ACE_BUS_WIDTH_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) res = platform_get_resource(dev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) physaddr = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) if (!physaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) irq = platform_get_irq_optional(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) /* Call the bus-independent setup code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) * Platform bus remove() method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) static int ace_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) ace_free(&dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) /* Match table for of_platform binding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) static const struct of_device_id ace_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) { .compatible = "xlnx,opb-sysace-1.00.b", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) { .compatible = "xlnx,opb-sysace-1.00.c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) { .compatible = "xlnx,xps-sysace-1.00.a", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) { .compatible = "xlnx,sysace", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) MODULE_DEVICE_TABLE(of, ace_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) #else /* CONFIG_OF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) #define ace_of_match NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) #endif /* CONFIG_OF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) static struct platform_driver ace_platform_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) .probe = ace_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) .remove = ace_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) .name = "xsysace",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) .of_match_table = ace_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) /* ---------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) * Module init/exit routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) static int __init ace_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) ace_major = register_blkdev(ace_major, "xsysace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (ace_major <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) goto err_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) rc = platform_driver_register(&ace_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) goto err_plat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) pr_info("Xilinx SystemACE device driver, major=%i\n", ace_major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) err_plat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) unregister_blkdev(ace_major, "xsysace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) err_blk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) printk(KERN_ERR "xsysace: registration failed; err=%i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) module_init(ace_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static void __exit ace_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) pr_debug("Unregistering Xilinx SystemACE driver\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) platform_driver_unregister(&ace_platform_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) unregister_blkdev(ace_major, "xsysace");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) module_exit(ace_exit);