83 #include <linux/module.h>
84 #include <linux/ctype.h>
87 #include <linux/errno.h>
88 #include <linux/kernel.h>
90 #include <linux/slab.h>
96 #if defined(CONFIG_OF)
107 #define ACE_BUSMODE (0x00)
109 #define ACE_STATUS (0x04)
110 #define ACE_STATUS_CFGLOCK (0x00000001)
111 #define ACE_STATUS_MPULOCK (0x00000002)
112 #define ACE_STATUS_CFGERROR (0x00000004)
113 #define ACE_STATUS_CFCERROR (0x00000008)
114 #define ACE_STATUS_CFDETECT (0x00000010)
115 #define ACE_STATUS_DATABUFRDY (0x00000020)
116 #define ACE_STATUS_DATABUFMODE (0x00000040)
117 #define ACE_STATUS_CFGDONE (0x00000080)
118 #define ACE_STATUS_RDYFORCFCMD (0x00000100)
119 #define ACE_STATUS_CFGMODEPIN (0x00000200)
120 #define ACE_STATUS_CFGADDR_MASK (0x0000e000)
121 #define ACE_STATUS_CFBSY (0x00020000)
122 #define ACE_STATUS_CFRDY (0x00040000)
123 #define ACE_STATUS_CFDWF (0x00080000)
124 #define ACE_STATUS_CFDSC (0x00100000)
125 #define ACE_STATUS_CFDRQ (0x00200000)
126 #define ACE_STATUS_CFCORR (0x00400000)
127 #define ACE_STATUS_CFERR (0x00800000)
129 #define ACE_ERROR (0x08)
130 #define ACE_CFGLBA (0x0c)
131 #define ACE_MPULBA (0x10)
133 #define ACE_SECCNTCMD (0x14)
134 #define ACE_SECCNTCMD_RESET (0x0100)
135 #define ACE_SECCNTCMD_IDENTIFY (0x0200)
136 #define ACE_SECCNTCMD_READ_DATA (0x0300)
137 #define ACE_SECCNTCMD_WRITE_DATA (0x0400)
138 #define ACE_SECCNTCMD_ABORT (0x0600)
140 #define ACE_VERSION (0x16)
141 #define ACE_VERSION_REVISION_MASK (0x00FF)
142 #define ACE_VERSION_MINOR_MASK (0x0F00)
143 #define ACE_VERSION_MAJOR_MASK (0xF000)
145 #define ACE_CTRL (0x18)
146 #define ACE_CTRL_FORCELOCKREQ (0x0001)
147 #define ACE_CTRL_LOCKREQ (0x0002)
148 #define ACE_CTRL_FORCECFGADDR (0x0004)
149 #define ACE_CTRL_FORCECFGMODE (0x0008)
150 #define ACE_CTRL_CFGMODE (0x0010)
151 #define ACE_CTRL_CFGSTART (0x0020)
152 #define ACE_CTRL_CFGSEL (0x0040)
153 #define ACE_CTRL_CFGRESET (0x0080)
154 #define ACE_CTRL_DATABUFRDYIRQ (0x0100)
155 #define ACE_CTRL_ERRORIRQ (0x0200)
156 #define ACE_CTRL_CFGDONEIRQ (0x0400)
157 #define ACE_CTRL_RESETIRQ (0x0800)
158 #define ACE_CTRL_CFGPROG (0x1000)
159 #define ACE_CTRL_CFGADDR_MASK (0xe000)
161 #define ACE_FATSTAT (0x1c)
163 #define ACE_NUM_MINORS 16
164 #define ACE_SECTOR_SIZE (512)
165 #define ACE_FIFO_SIZE (32)
166 #define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE)
168 #define ACE_BUS_WIDTH_8 0
169 #define ACE_BUS_WIDTH_16 1
218 static int ace_major;
235 return in_8(r) | (
in_8(r + 1) << 8);
242 out_8(r + 1, val >> 8);
245 static void ace_datain_8(
struct ace_device *ace)
255 static void ace_dataout_8(
struct ace_device *ace)
268 .datain = ace_datain_8,
269 .dataout = ace_dataout_8,
283 static void ace_datain_be16(
struct ace_device *ace)
292 static void ace_dataout_be16(
struct ace_device *ace)
312 static void ace_datain_le16(
struct ace_device *ace)
321 static void ace_dataout_le16(
struct ace_device *ace)
333 .datain = ace_datain_be16,
334 .dataout = ace_dataout_be16,
340 .datain = ace_datain_le16,
341 .dataout = ace_dataout_le16,
346 return ace->
reg_ops->in(ace, reg);
351 return ace_in(ace, reg) | (ace_in(ace, reg + 2) << 16);
356 ace->
reg_ops->out(ace, reg, val);
359 static inline void ace_out32(
struct ace_device *ace,
int reg,
u32 val)
361 ace_out(ace, reg, val);
362 ace_out(ace, reg + 2, val >> 16);
370 static void ace_dump_mem(
void *base,
int len)
372 const char *
ptr = base;
375 for (i = 0; i < len; i += 16) {
377 for (j = 0; j < 16; j++) {
380 printk(
"%.2x", ptr[i + j]);
383 for (j = 0; j < 16; j++)
389 static inline void ace_dump_mem(
void *base,
int len)
394 static void ace_dump_regs(
struct ace_device *ace)
397 " ctrl: %.8x seccnt/cmd: %.4x ver:%.4x\n"
398 " status:%.8x mpu_lba:%.8x busmode:%4x\n"
399 " error: %.8x cfg_lba:%.8x fatstat:%.4x\n",
412 #if defined(__BIG_ENDIAN)
426 #define ACE_TASK_IDLE 0
427 #define ACE_TASK_IDENTIFY 1
428 #define ACE_TASK_READ 2
429 #define ACE_TASK_WRITE 3
430 #define ACE_FSM_NUM_TASKS 4
433 #define ACE_FSM_STATE_IDLE 0
434 #define ACE_FSM_STATE_REQ_LOCK 1
435 #define ACE_FSM_STATE_WAIT_LOCK 2
436 #define ACE_FSM_STATE_WAIT_CFREADY 3
437 #define ACE_FSM_STATE_IDENTIFY_PREPARE 4
438 #define ACE_FSM_STATE_IDENTIFY_TRANSFER 5
439 #define ACE_FSM_STATE_IDENTIFY_COMPLETE 6
440 #define ACE_FSM_STATE_REQ_PREPARE 7
441 #define ACE_FSM_STATE_REQ_TRANSFER 8
442 #define ACE_FSM_STATE_REQ_COMPLETE 9
443 #define ACE_FSM_STATE_ERROR 10
444 #define ACE_FSM_NUM_STATES 11
447 static inline void ace_fsm_yield(
struct ace_device *ace)
455 static inline void ace_fsm_yieldirq(
struct ace_device *ace)
471 if (req->cmd_type == REQ_TYPE_FS)
479 static void ace_fsm_dostate(
struct ace_device *ace)
487 dev_dbg(ace->
dev,
"fsm_state=%i, id_req_count=%i\n",
497 set_capacity(ace->
gd, 0);
546 if (ace_in(ace,
ACE_STATUS) & ACE_STATUS_MPULOCK) {
586 ace_fsm_yieldirq(ace);
592 if (status & ACE_STATUS_CFBSY) {
593 dev_dbg(ace->
dev,
"CFBSY set; t=%i iter=%i dc=%i\n",
610 ace_fsm_yieldirq(ace);
621 ace_dump_mem(ace->
cf_id, 512);
626 set_capacity(ace->
gd, 0);
627 dev_err(ace->
dev,
"error fetching CF id (%i)\n",
633 set_capacity(ace->
gd,
658 "request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
659 (
unsigned long long)blk_rq_pos(req),
660 blk_rq_sectors(req), blk_rq_cur_sectors(req),
666 ace_out32(ace,
ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
668 count = blk_rq_sectors(req);
669 if (rq_data_dir(req)) {
692 ace_fsm_yieldirq(ace);
698 if (status & ACE_STATUS_CFBSY) {
700 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
702 blk_rq_cur_sectors(ace->
req) * 16,
707 if (!(status & ACE_STATUS_DATABUFRDY)) {
709 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
711 blk_rq_cur_sectors(ace->
req) * 16,
713 ace_fsm_yieldirq(ace);
726 ace_fsm_yieldirq(ace);
738 ace_fsm_yieldirq(ace);
758 static void ace_fsm_tasklet(
unsigned long data)
768 ace_fsm_dostate(ace);
770 spin_unlock_irqrestore(&ace->
lock, flags);
773 static void ace_stall_timer(
unsigned long data)
779 "kicking stalled fsm; state=%i task=%i iter=%i dc=%i\n",
791 ace_fsm_dostate(ace);
793 spin_unlock_irqrestore(&ace->
lock, flags);
799 static int ace_interrupt_checkstate(
struct ace_device *ace)
821 spin_lock(&ace->
lock);
830 if (ace_interrupt_checkstate(ace))
835 "spurious irq; stat=%.8x ctrl=%.8x cmd=%.4x\n",
838 dev_err(ace->
dev,
"fsm_task=%i fsm_state=%i data_count=%i\n",
845 ace_fsm_dostate(ace);
849 spin_unlock(&ace->
lock);
865 ace = req->rq_disk->private_data;
870 static unsigned int ace_check_events(
struct gendisk *
gd,
unsigned int clearing)
878 static int ace_revalidate_disk(
struct gendisk *
gd)
886 dev_dbg(ace->
dev,
"requesting cf id and scheduling tasklet\n");
890 spin_unlock_irqrestore(&ace->
lock, flags);
910 spin_unlock_irqrestore(&ace->
lock, flags);
918 static int ace_release(
struct gendisk *disk,
fmode_t mode)
929 if (ace->
users == 0) {
933 spin_unlock_irqrestore(&ace->
lock, flags);
952 static const struct block_device_operations ace_fops = {
955 .release = ace_release,
956 .check_events = ace_check_events,
957 .revalidate_disk = ace_revalidate_disk,
958 .getgeo = ace_getgeo,
970 dev_dbg(ace->
dev,
"ace_setup(ace=0x%p)\n", ace);
1003 goto err_alloc_disk;
1005 ace->
gd->major = ace_major;
1007 ace->
gd->fops = &ace_fops;
1009 ace->
gd->private_data = ace;
1010 snprintf(ace->
gd->disk_name, 32,
"xs%c", ace->
id +
'a');
1019 ace->
reg_ops = &ace_reg_le16_ops;
1021 ace->
reg_ops = &ace_reg_be16_ops;
1024 ace->
reg_ops = &ace_reg_8_ops;
1029 if ((version == 0) || (version == 0xFFFF))
1052 dev_info(ace->
dev,
"Xilinx SystemACE revision %i.%i.%i\n",
1053 (version >> 12) & 0xf, (version >> 8) & 0x0f, version & 0xff);
1054 dev_dbg(ace->
dev,
"physaddr 0x%llx, mapped to 0x%p, irq=%i\n",
1058 ace_revalidate_disk(ace->
gd);
1072 dev_info(ace->
dev,
"xsysace: error initializing device at 0x%llx\n",
1073 (
unsigned long long) ace->
physaddr);
1101 dev_dbg(dev,
"ace_alloc(%p)\n", dev);
1122 rc = ace_setup(ace);
1134 dev_err(dev,
"could not initialize device, err=%i\n", rc);
1141 dev_dbg(dev,
"ace_free(%p)\n", dev);
1165 of_property_read_u32(dev->
dev.of_node,
"port-number", &
id);
1179 return ace_alloc(&dev->
dev,
id, physaddr, irq, bus_width);
1187 ace_free(&dev->
dev);
1191 #if defined(CONFIG_OF)
1194 { .compatible =
"xlnx,opb-sysace-1.00.b", },
1195 { .compatible =
"xlnx,opb-sysace-1.00.c", },
1196 { .compatible =
"xlnx,xps-sysace-1.00.a", },
1197 { .compatible =
"xlnx,sysace", },
1202 #define ace_of_match NULL
1218 static int __init ace_init(
void)
1223 if (ace_major <= 0) {
1232 pr_info(
"Xilinx SystemACE device driver, major=%i\n", ace_major);
1243 static void __exit ace_exit(
void)
1245 pr_debug(
"Unregistering Xilinx SystemACE driver\n");