Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 1 | /* |
| 2 | * sata_inic162x.c - Driver for Initio 162x SATA controllers |
| 3 | * |
| 4 | * Copyright 2006 SUSE Linux Products GmbH |
| 5 | * Copyright 2006 Tejun Heo <teheo@novell.com> |
| 6 | * |
| 7 | * This file is released under GPL v2. |
| 8 | * |
| 9 | * This controller is eccentric and easily locks up if something isn't |
| 10 | * right. Documentation is available at initio's website but it only |
| 11 | * documents registers (not programming model). |
| 12 | * |
| 13 | * - ATA disks work. |
| 14 | * - Hotplug works. |
| 15 | * - ATAPI read works but burning doesn't. This thing is really |
| 16 | * peculiar about ATAPI and I couldn't figure out how ATAPI PIO and |
| 17 | * ATAPI DMA WRITE should be programmed. If you've got a clue, be |
| 18 | * my guest. |
| 19 | * - Both STR and STD work. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/pci.h> |
| 25 | #include <scsi/scsi_host.h> |
| 26 | #include <linux/libata.h> |
| 27 | #include <linux/blkdev.h> |
| 28 | #include <scsi/scsi_device.h> |
| 29 | |
| 30 | #define DRV_NAME "sata_inic162x" |
Jeff Garzik | 2a3103c | 2007-08-31 04:54:06 -0400 | [diff] [blame] | 31 | #define DRV_VERSION "0.3" |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 32 | |
| 33 | enum { |
| 34 | MMIO_BAR = 5, |
| 35 | |
| 36 | NR_PORTS = 2, |
| 37 | |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 38 | HOST_ACTRL = 0x08, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 39 | HOST_CTL = 0x7c, |
| 40 | HOST_STAT = 0x7e, |
| 41 | HOST_IRQ_STAT = 0xbc, |
| 42 | HOST_IRQ_MASK = 0xbe, |
| 43 | |
| 44 | PORT_SIZE = 0x40, |
| 45 | |
| 46 | /* registers for ATA TF operation */ |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 47 | PORT_TF_DATA = 0x00, |
| 48 | PORT_TF_FEATURE = 0x01, |
| 49 | PORT_TF_NSECT = 0x02, |
| 50 | PORT_TF_LBAL = 0x03, |
| 51 | PORT_TF_LBAM = 0x04, |
| 52 | PORT_TF_LBAH = 0x05, |
| 53 | PORT_TF_DEVICE = 0x06, |
| 54 | PORT_TF_COMMAND = 0x07, |
| 55 | PORT_TF_ALT_STAT = 0x08, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 56 | PORT_IRQ_STAT = 0x09, |
| 57 | PORT_IRQ_MASK = 0x0a, |
| 58 | PORT_PRD_CTL = 0x0b, |
| 59 | PORT_PRD_ADDR = 0x0c, |
| 60 | PORT_PRD_XFERLEN = 0x10, |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 61 | PORT_CPB_CPBLAR = 0x18, |
| 62 | PORT_CPB_PTQFIFO = 0x1c, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 63 | |
| 64 | /* IDMA register */ |
| 65 | PORT_IDMA_CTL = 0x14, |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 66 | PORT_IDMA_STAT = 0x16, |
| 67 | |
| 68 | PORT_RPQ_FIFO = 0x1e, |
| 69 | PORT_RPQ_CNT = 0x1f, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 70 | |
| 71 | PORT_SCR = 0x20, |
| 72 | |
| 73 | /* HOST_CTL bits */ |
| 74 | HCTL_IRQOFF = (1 << 8), /* global IRQ off */ |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 75 | HCTL_FTHD0 = (1 << 10), /* fifo threshold 0 */ |
| 76 | HCTL_FTHD1 = (1 << 11), /* fifo threshold 1*/ |
| 77 | HCTL_PWRDWN = (1 << 12), /* power down PHYs */ |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 78 | HCTL_SOFTRST = (1 << 13), /* global reset (no phy reset) */ |
| 79 | HCTL_RPGSEL = (1 << 15), /* register page select */ |
| 80 | |
| 81 | HCTL_KNOWN_BITS = HCTL_IRQOFF | HCTL_PWRDWN | HCTL_SOFTRST | |
| 82 | HCTL_RPGSEL, |
| 83 | |
| 84 | /* HOST_IRQ_(STAT|MASK) bits */ |
| 85 | HIRQ_PORT0 = (1 << 0), |
| 86 | HIRQ_PORT1 = (1 << 1), |
| 87 | HIRQ_SOFT = (1 << 14), |
| 88 | HIRQ_GLOBAL = (1 << 15), /* STAT only */ |
| 89 | |
| 90 | /* PORT_IRQ_(STAT|MASK) bits */ |
| 91 | PIRQ_OFFLINE = (1 << 0), /* device unplugged */ |
| 92 | PIRQ_ONLINE = (1 << 1), /* device plugged */ |
| 93 | PIRQ_COMPLETE = (1 << 2), /* completion interrupt */ |
| 94 | PIRQ_FATAL = (1 << 3), /* fatal error */ |
| 95 | PIRQ_ATA = (1 << 4), /* ATA interrupt */ |
| 96 | PIRQ_REPLY = (1 << 5), /* reply FIFO not empty */ |
| 97 | PIRQ_PENDING = (1 << 7), /* port IRQ pending (STAT only) */ |
| 98 | |
| 99 | PIRQ_ERR = PIRQ_OFFLINE | PIRQ_ONLINE | PIRQ_FATAL, |
| 100 | |
| 101 | PIRQ_MASK_DMA_READ = PIRQ_REPLY | PIRQ_ATA, |
| 102 | PIRQ_MASK_OTHER = PIRQ_REPLY | PIRQ_COMPLETE, |
| 103 | PIRQ_MASK_FREEZE = 0xff, |
| 104 | |
| 105 | /* PORT_PRD_CTL bits */ |
| 106 | PRD_CTL_START = (1 << 0), |
| 107 | PRD_CTL_WR = (1 << 3), |
| 108 | PRD_CTL_DMAEN = (1 << 7), /* DMA enable */ |
| 109 | |
| 110 | /* PORT_IDMA_CTL bits */ |
| 111 | IDMA_CTL_RST_ATA = (1 << 2), /* hardreset ATA bus */ |
| 112 | IDMA_CTL_RST_IDMA = (1 << 5), /* reset IDMA machinary */ |
| 113 | IDMA_CTL_GO = (1 << 7), /* IDMA mode go */ |
| 114 | IDMA_CTL_ATA_NIEN = (1 << 8), /* ATA IRQ disable */ |
Tejun Heo | b0dd9b8 | 2008-04-30 16:35:09 +0900 | [diff] [blame^] | 115 | |
| 116 | /* PORT_IDMA_STAT bits */ |
| 117 | IDMA_STAT_PERR = (1 << 0), /* PCI ERROR MODE */ |
| 118 | IDMA_STAT_CPBERR = (1 << 1), /* ADMA CPB error */ |
| 119 | IDMA_STAT_LGCY = (1 << 3), /* ADMA legacy */ |
| 120 | IDMA_STAT_UIRQ = (1 << 4), /* ADMA unsolicited irq */ |
| 121 | IDMA_STAT_STPD = (1 << 5), /* ADMA stopped */ |
| 122 | IDMA_STAT_PSD = (1 << 6), /* ADMA pause */ |
| 123 | IDMA_STAT_DONE = (1 << 7), /* ADMA done */ |
| 124 | |
| 125 | IDMA_STAT_ERR = IDMA_STAT_PERR | IDMA_STAT_CPBERR, |
| 126 | |
| 127 | /* CPB Control Flags*/ |
| 128 | CPB_CTL_VALID = (1 << 0), /* CPB valid */ |
| 129 | CPB_CTL_QUEUED = (1 << 1), /* queued command */ |
| 130 | CPB_CTL_DATA = (1 << 2), /* data, rsvd in datasheet */ |
| 131 | CPB_CTL_IEN = (1 << 3), /* PCI interrupt enable */ |
| 132 | CPB_CTL_DEVDIR = (1 << 4), /* device direction control */ |
| 133 | |
| 134 | /* CPB Response Flags */ |
| 135 | CPB_RESP_DONE = (1 << 0), /* ATA command complete */ |
| 136 | CPB_RESP_REL = (1 << 1), /* ATA release */ |
| 137 | CPB_RESP_IGNORED = (1 << 2), /* CPB ignored */ |
| 138 | CPB_RESP_ATA_ERR = (1 << 3), /* ATA command error */ |
| 139 | CPB_RESP_SPURIOUS = (1 << 4), /* ATA spurious interrupt error */ |
| 140 | CPB_RESP_UNDERFLOW = (1 << 5), /* APRD deficiency length error */ |
| 141 | CPB_RESP_OVERFLOW = (1 << 6), /* APRD exccess length error */ |
| 142 | CPB_RESP_CPB_ERR = (1 << 7), /* CPB error flag */ |
| 143 | |
| 144 | /* PRD Control Flags */ |
| 145 | PRD_DRAIN = (1 << 1), /* ignore data excess */ |
| 146 | PRD_CDB = (1 << 2), /* atapi packet command pointer */ |
| 147 | PRD_DIRECT_INTR = (1 << 3), /* direct interrupt */ |
| 148 | PRD_DMA = (1 << 4), /* data transfer method */ |
| 149 | PRD_WRITE = (1 << 5), /* data dir, rsvd in datasheet */ |
| 150 | PRD_IOM = (1 << 6), /* io/memory transfer */ |
| 151 | PRD_END = (1 << 7), /* APRD chain end */ |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | struct inic_host_priv { |
Tejun Heo | 36f674d | 2008-04-30 16:35:08 +0900 | [diff] [blame] | 155 | u16 cached_hctl; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | struct inic_port_priv { |
Tejun Heo | 36f674d | 2008-04-30 16:35:08 +0900 | [diff] [blame] | 159 | u8 dfl_prdctl; |
| 160 | u8 cached_prdctl; |
| 161 | u8 cached_pirq_mask; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 162 | }; |
| 163 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 164 | static struct scsi_host_template inic_sht = { |
Tejun Heo | 68d1d07 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 165 | ATA_BMDMA_SHT(DRV_NAME), |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | static const int scr_map[] = { |
| 169 | [SCR_STATUS] = 0, |
| 170 | [SCR_ERROR] = 1, |
| 171 | [SCR_CONTROL] = 2, |
| 172 | }; |
| 173 | |
Jeff Garzik | 5796d1c | 2007-10-26 00:03:37 -0400 | [diff] [blame] | 174 | static void __iomem *inic_port_base(struct ata_port *ap) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 175 | { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 176 | return ap->host->iomap[MMIO_BAR] + ap->port_no * PORT_SIZE; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static void __inic_set_pirq_mask(struct ata_port *ap, u8 mask) |
| 180 | { |
| 181 | void __iomem *port_base = inic_port_base(ap); |
| 182 | struct inic_port_priv *pp = ap->private_data; |
| 183 | |
| 184 | writeb(mask, port_base + PORT_IRQ_MASK); |
| 185 | pp->cached_pirq_mask = mask; |
| 186 | } |
| 187 | |
| 188 | static void inic_set_pirq_mask(struct ata_port *ap, u8 mask) |
| 189 | { |
| 190 | struct inic_port_priv *pp = ap->private_data; |
| 191 | |
| 192 | if (pp->cached_pirq_mask != mask) |
| 193 | __inic_set_pirq_mask(ap, mask); |
| 194 | } |
| 195 | |
| 196 | static void inic_reset_port(void __iomem *port_base) |
| 197 | { |
| 198 | void __iomem *idma_ctl = port_base + PORT_IDMA_CTL; |
| 199 | u16 ctl; |
| 200 | |
| 201 | ctl = readw(idma_ctl); |
| 202 | ctl &= ~(IDMA_CTL_RST_IDMA | IDMA_CTL_ATA_NIEN | IDMA_CTL_GO); |
| 203 | |
| 204 | /* mask IRQ and assert reset */ |
| 205 | writew(ctl | IDMA_CTL_RST_IDMA | IDMA_CTL_ATA_NIEN, idma_ctl); |
| 206 | readw(idma_ctl); /* flush */ |
| 207 | |
| 208 | /* give it some time */ |
| 209 | msleep(1); |
| 210 | |
| 211 | /* release reset */ |
| 212 | writew(ctl | IDMA_CTL_ATA_NIEN, idma_ctl); |
| 213 | |
| 214 | /* clear irq */ |
| 215 | writeb(0xff, port_base + PORT_IRQ_STAT); |
| 216 | |
| 217 | /* reenable ATA IRQ, turn off IDMA mode */ |
| 218 | writew(ctl, idma_ctl); |
| 219 | } |
| 220 | |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 221 | static int inic_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 222 | { |
Jeff Garzik | 59f9988 | 2007-05-28 07:07:20 -0400 | [diff] [blame] | 223 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 224 | void __iomem *addr; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 225 | |
| 226 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 227 | return -EINVAL; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 228 | |
| 229 | addr = scr_addr + scr_map[sc_reg] * 4; |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 230 | *val = readl(scr_addr + scr_map[sc_reg] * 4); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 231 | |
| 232 | /* this controller has stuck DIAG.N, ignore it */ |
| 233 | if (sc_reg == SCR_ERROR) |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 234 | *val &= ~SERR_PHYRDY_CHG; |
| 235 | return 0; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 236 | } |
| 237 | |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 238 | static int inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 239 | { |
Jeff Garzik | 59f9988 | 2007-05-28 07:07:20 -0400 | [diff] [blame] | 240 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 241 | |
| 242 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 243 | return -EINVAL; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 244 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 245 | writel(val, scr_addr + scr_map[sc_reg] * 4); |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 246 | return 0; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* |
| 250 | * In TF mode, inic162x is very similar to SFF device. TF registers |
| 251 | * function the same. DMA engine behaves similary using the same PRD |
| 252 | * format as BMDMA but different command register, interrupt and event |
| 253 | * notification methods are used. The following inic_bmdma_*() |
| 254 | * functions do the impedance matching. |
| 255 | */ |
| 256 | static void inic_bmdma_setup(struct ata_queued_cmd *qc) |
| 257 | { |
| 258 | struct ata_port *ap = qc->ap; |
| 259 | struct inic_port_priv *pp = ap->private_data; |
| 260 | void __iomem *port_base = inic_port_base(ap); |
| 261 | int rw = qc->tf.flags & ATA_TFLAG_WRITE; |
| 262 | |
| 263 | /* make sure device sees PRD table writes */ |
| 264 | wmb(); |
| 265 | |
| 266 | /* load transfer length */ |
| 267 | writel(qc->nbytes, port_base + PORT_PRD_XFERLEN); |
| 268 | |
| 269 | /* turn on DMA and specify data direction */ |
| 270 | pp->cached_prdctl = pp->dfl_prdctl | PRD_CTL_DMAEN; |
| 271 | if (!rw) |
| 272 | pp->cached_prdctl |= PRD_CTL_WR; |
| 273 | writeb(pp->cached_prdctl, port_base + PORT_PRD_CTL); |
| 274 | |
| 275 | /* issue r/w command */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 276 | ap->ops->sff_exec_command(ap, &qc->tf); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void inic_bmdma_start(struct ata_queued_cmd *qc) |
| 280 | { |
| 281 | struct ata_port *ap = qc->ap; |
| 282 | struct inic_port_priv *pp = ap->private_data; |
| 283 | void __iomem *port_base = inic_port_base(ap); |
| 284 | |
| 285 | /* start host DMA transaction */ |
| 286 | pp->cached_prdctl |= PRD_CTL_START; |
| 287 | writeb(pp->cached_prdctl, port_base + PORT_PRD_CTL); |
| 288 | } |
| 289 | |
| 290 | static void inic_bmdma_stop(struct ata_queued_cmd *qc) |
| 291 | { |
| 292 | struct ata_port *ap = qc->ap; |
| 293 | struct inic_port_priv *pp = ap->private_data; |
| 294 | void __iomem *port_base = inic_port_base(ap); |
| 295 | |
| 296 | /* stop DMA engine */ |
| 297 | writeb(pp->dfl_prdctl, port_base + PORT_PRD_CTL); |
| 298 | } |
| 299 | |
| 300 | static u8 inic_bmdma_status(struct ata_port *ap) |
| 301 | { |
| 302 | /* event is already verified by the interrupt handler */ |
| 303 | return ATA_DMA_INTR; |
| 304 | } |
| 305 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 306 | static void inic_host_intr(struct ata_port *ap) |
| 307 | { |
| 308 | void __iomem *port_base = inic_port_base(ap); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 309 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 310 | u8 irq_stat; |
| 311 | |
| 312 | /* fetch and clear irq */ |
| 313 | irq_stat = readb(port_base + PORT_IRQ_STAT); |
| 314 | writeb(irq_stat, port_base + PORT_IRQ_STAT); |
| 315 | |
| 316 | if (likely(!(irq_stat & PIRQ_ERR))) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 317 | struct ata_queued_cmd *qc = |
| 318 | ata_qc_from_tag(ap, ap->link.active_tag); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 319 | |
| 320 | if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 321 | ap->ops->sff_check_status(ap); /* clear ATA interrupt */ |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 325 | if (likely(ata_sff_host_intr(ap, qc))) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 326 | return; |
| 327 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 328 | ap->ops->sff_check_status(ap); /* clear ATA interrupt */ |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 329 | ata_port_printk(ap, KERN_WARNING, "unhandled " |
| 330 | "interrupt, irq_stat=%x\n", irq_stat); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | /* error */ |
| 335 | ata_ehi_push_desc(ehi, "irq_stat=0x%x", irq_stat); |
| 336 | |
| 337 | if (irq_stat & (PIRQ_OFFLINE | PIRQ_ONLINE)) { |
| 338 | ata_ehi_hotplugged(ehi); |
| 339 | ata_port_freeze(ap); |
| 340 | } else |
| 341 | ata_port_abort(ap); |
| 342 | } |
| 343 | |
| 344 | static irqreturn_t inic_interrupt(int irq, void *dev_instance) |
| 345 | { |
| 346 | struct ata_host *host = dev_instance; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 347 | void __iomem *mmio_base = host->iomap[MMIO_BAR]; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 348 | u16 host_irq_stat; |
| 349 | int i, handled = 0;; |
| 350 | |
| 351 | host_irq_stat = readw(mmio_base + HOST_IRQ_STAT); |
| 352 | |
| 353 | if (unlikely(!(host_irq_stat & HIRQ_GLOBAL))) |
| 354 | goto out; |
| 355 | |
| 356 | spin_lock(&host->lock); |
| 357 | |
| 358 | for (i = 0; i < NR_PORTS; i++) { |
| 359 | struct ata_port *ap = host->ports[i]; |
| 360 | |
| 361 | if (!(host_irq_stat & (HIRQ_PORT0 << i))) |
| 362 | continue; |
| 363 | |
| 364 | if (likely(ap && !(ap->flags & ATA_FLAG_DISABLED))) { |
| 365 | inic_host_intr(ap); |
| 366 | handled++; |
| 367 | } else { |
| 368 | if (ata_ratelimit()) |
| 369 | dev_printk(KERN_ERR, host->dev, "interrupt " |
| 370 | "from disabled port %d (0x%x)\n", |
| 371 | i, host_irq_stat); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | spin_unlock(&host->lock); |
| 376 | |
| 377 | out: |
| 378 | return IRQ_RETVAL(handled); |
| 379 | } |
| 380 | |
| 381 | static unsigned int inic_qc_issue(struct ata_queued_cmd *qc) |
| 382 | { |
| 383 | struct ata_port *ap = qc->ap; |
| 384 | |
| 385 | /* ATA IRQ doesn't wait for DMA transfer completion and vice |
| 386 | * versa. Mask IRQ selectively to detect command completion. |
| 387 | * Without it, ATA DMA read command can cause data corruption. |
| 388 | * |
| 389 | * Something similar might be needed for ATAPI writes. I |
| 390 | * tried a lot of combinations but couldn't find the solution. |
| 391 | */ |
| 392 | if (qc->tf.protocol == ATA_PROT_DMA && |
| 393 | !(qc->tf.flags & ATA_TFLAG_WRITE)) |
| 394 | inic_set_pirq_mask(ap, PIRQ_MASK_DMA_READ); |
| 395 | else |
| 396 | inic_set_pirq_mask(ap, PIRQ_MASK_OTHER); |
| 397 | |
| 398 | /* Issuing a command to yet uninitialized port locks up the |
| 399 | * controller. Most of the time, this happens for the first |
| 400 | * command after reset which are ATA and ATAPI IDENTIFYs. |
| 401 | * Fast fail if stat is 0x7f or 0xff for those commands. |
| 402 | */ |
| 403 | if (unlikely(qc->tf.command == ATA_CMD_ID_ATA || |
| 404 | qc->tf.command == ATA_CMD_ID_ATAPI)) { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 405 | u8 stat = ap->ops->sff_check_status(ap); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 406 | if (stat == 0x7f || stat == 0xff) |
| 407 | return AC_ERR_HSM; |
| 408 | } |
| 409 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 410 | return ata_sff_qc_issue(qc); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static void inic_freeze(struct ata_port *ap) |
| 414 | { |
| 415 | void __iomem *port_base = inic_port_base(ap); |
| 416 | |
| 417 | __inic_set_pirq_mask(ap, PIRQ_MASK_FREEZE); |
| 418 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 419 | ap->ops->sff_check_status(ap); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 420 | writeb(0xff, port_base + PORT_IRQ_STAT); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void inic_thaw(struct ata_port *ap) |
| 424 | { |
| 425 | void __iomem *port_base = inic_port_base(ap); |
| 426 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 427 | ap->ops->sff_check_status(ap); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 428 | writeb(0xff, port_base + PORT_IRQ_STAT); |
| 429 | |
| 430 | __inic_set_pirq_mask(ap, PIRQ_MASK_OTHER); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * SRST and SControl hardreset don't give valid signature on this |
| 435 | * controller. Only controller specific hardreset mechanism works. |
| 436 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 437 | static int inic_hardreset(struct ata_link *link, unsigned int *class, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 438 | unsigned long deadline) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 439 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 440 | struct ata_port *ap = link->ap; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 441 | void __iomem *port_base = inic_port_base(ap); |
| 442 | void __iomem *idma_ctl = port_base + PORT_IDMA_CTL; |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 443 | const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 444 | u16 val; |
| 445 | int rc; |
| 446 | |
| 447 | /* hammer it into sane state */ |
| 448 | inic_reset_port(port_base); |
| 449 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 450 | val = readw(idma_ctl); |
| 451 | writew(val | IDMA_CTL_RST_ATA, idma_ctl); |
| 452 | readw(idma_ctl); /* flush */ |
| 453 | msleep(1); |
| 454 | writew(val & ~IDMA_CTL_RST_ATA, idma_ctl); |
| 455 | |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 456 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 457 | if (rc) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 458 | ata_link_printk(link, KERN_WARNING, "failed to resume " |
Tejun Heo | fe33460 | 2007-02-02 15:29:52 +0900 | [diff] [blame] | 459 | "link after reset (errno=%d)\n", rc); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 460 | return rc; |
| 461 | } |
| 462 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 463 | *class = ATA_DEV_NONE; |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 464 | if (ata_link_online(link)) { |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 465 | struct ata_taskfile tf; |
| 466 | |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 467 | /* wait for link to become ready */ |
| 468 | rc = ata_sff_wait_after_reset(link, 1, deadline); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 469 | /* link occupied, -ENODEV too is an error */ |
| 470 | if (rc) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 471 | ata_link_printk(link, KERN_WARNING, "device not ready " |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 472 | "after hardreset (errno=%d)\n", rc); |
| 473 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 474 | } |
| 475 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 476 | ata_sff_tf_read(ap, &tf); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 477 | *class = ata_dev_classify(&tf); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | static void inic_error_handler(struct ata_port *ap) |
| 484 | { |
| 485 | void __iomem *port_base = inic_port_base(ap); |
| 486 | struct inic_port_priv *pp = ap->private_data; |
| 487 | unsigned long flags; |
| 488 | |
| 489 | /* reset PIO HSM and stop DMA engine */ |
| 490 | inic_reset_port(port_base); |
| 491 | |
| 492 | spin_lock_irqsave(ap->lock, flags); |
| 493 | ap->hsm_task_state = HSM_ST_IDLE; |
| 494 | writeb(pp->dfl_prdctl, port_base + PORT_PRD_CTL); |
| 495 | spin_unlock_irqrestore(ap->lock, flags); |
| 496 | |
| 497 | /* PIO and DMA engines have been stopped, perform recovery */ |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 498 | ata_std_error_handler(ap); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static void inic_post_internal_cmd(struct ata_queued_cmd *qc) |
| 502 | { |
| 503 | /* make DMA engine forget about the failed command */ |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 504 | if (qc->flags & ATA_QCFLAG_FAILED) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 505 | inic_reset_port(inic_port_base(qc->ap)); |
| 506 | } |
| 507 | |
Alan | cd0d3bb | 2007-03-02 00:56:15 +0000 | [diff] [blame] | 508 | static void inic_dev_config(struct ata_device *dev) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 509 | { |
| 510 | /* inic can only handle upto LBA28 max sectors */ |
| 511 | if (dev->max_sectors > ATA_MAX_SECTORS) |
| 512 | dev->max_sectors = ATA_MAX_SECTORS; |
Tejun Heo | 90c9378 | 2007-06-29 11:33:08 +0900 | [diff] [blame] | 513 | |
| 514 | if (dev->n_sectors >= 1 << 28) { |
| 515 | ata_dev_printk(dev, KERN_ERR, |
| 516 | "ERROR: This driver doesn't support LBA48 yet and may cause\n" |
| 517 | " data corruption on such devices. Disabling.\n"); |
| 518 | ata_dev_disable(dev); |
| 519 | } |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | static void init_port(struct ata_port *ap) |
| 523 | { |
| 524 | void __iomem *port_base = inic_port_base(ap); |
| 525 | |
| 526 | /* Setup PRD address */ |
| 527 | writel(ap->prd_dma, port_base + PORT_PRD_ADDR); |
| 528 | } |
| 529 | |
| 530 | static int inic_port_resume(struct ata_port *ap) |
| 531 | { |
| 532 | init_port(ap); |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static int inic_port_start(struct ata_port *ap) |
| 537 | { |
| 538 | void __iomem *port_base = inic_port_base(ap); |
| 539 | struct inic_port_priv *pp; |
| 540 | u8 tmp; |
| 541 | int rc; |
| 542 | |
| 543 | /* alloc and initialize private data */ |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 544 | pp = devm_kzalloc(ap->host->dev, sizeof(*pp), GFP_KERNEL); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 545 | if (!pp) |
| 546 | return -ENOMEM; |
| 547 | ap->private_data = pp; |
| 548 | |
| 549 | /* default PRD_CTL value, DMAEN, WR and START off */ |
| 550 | tmp = readb(port_base + PORT_PRD_CTL); |
| 551 | tmp &= ~(PRD_CTL_DMAEN | PRD_CTL_WR | PRD_CTL_START); |
| 552 | pp->dfl_prdctl = tmp; |
| 553 | |
| 554 | /* Alloc resources */ |
| 555 | rc = ata_port_start(ap); |
Tejun Heo | 36f674d | 2008-04-30 16:35:08 +0900 | [diff] [blame] | 556 | if (rc) |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 557 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 558 | |
| 559 | init_port(ap); |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 564 | static struct ata_port_operations inic_port_ops = { |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 565 | .inherits = &ata_sff_port_ops, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 566 | |
| 567 | .bmdma_setup = inic_bmdma_setup, |
| 568 | .bmdma_start = inic_bmdma_start, |
| 569 | .bmdma_stop = inic_bmdma_stop, |
| 570 | .bmdma_status = inic_bmdma_status, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 571 | .qc_issue = inic_qc_issue, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 572 | |
| 573 | .freeze = inic_freeze, |
| 574 | .thaw = inic_thaw, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 575 | .softreset = ATA_OP_NULL, /* softreset is broken */ |
| 576 | .hardreset = inic_hardreset, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 577 | .error_handler = inic_error_handler, |
| 578 | .post_internal_cmd = inic_post_internal_cmd, |
| 579 | .dev_config = inic_dev_config, |
| 580 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 581 | .scr_read = inic_scr_read, |
| 582 | .scr_write = inic_scr_write, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 583 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 584 | .port_resume = inic_port_resume, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 585 | .port_start = inic_port_start, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | static struct ata_port_info inic_port_info = { |
Tejun Heo | 0dc3688 | 2007-12-18 16:34:43 -0500 | [diff] [blame] | 589 | /* For some reason, ATAPI_PROT_PIO is broken on this |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 590 | * controller, and no, PIO_POLLING does't fix it. It somehow |
| 591 | * manages to report the wrong ireason and ignoring ireason |
| 592 | * results in machine lock up. Tell libata to always prefer |
| 593 | * DMA. |
| 594 | */ |
| 595 | .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA, |
| 596 | .pio_mask = 0x1f, /* pio0-4 */ |
| 597 | .mwdma_mask = 0x07, /* mwdma0-2 */ |
Jeff Garzik | bf6263a | 2007-07-09 12:16:50 -0400 | [diff] [blame] | 598 | .udma_mask = ATA_UDMA6, |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 599 | .port_ops = &inic_port_ops |
| 600 | }; |
| 601 | |
| 602 | static int init_controller(void __iomem *mmio_base, u16 hctl) |
| 603 | { |
| 604 | int i; |
| 605 | u16 val; |
| 606 | |
| 607 | hctl &= ~HCTL_KNOWN_BITS; |
| 608 | |
| 609 | /* Soft reset whole controller. Spec says reset duration is 3 |
| 610 | * PCI clocks, be generous and give it 10ms. |
| 611 | */ |
| 612 | writew(hctl | HCTL_SOFTRST, mmio_base + HOST_CTL); |
| 613 | readw(mmio_base + HOST_CTL); /* flush */ |
| 614 | |
| 615 | for (i = 0; i < 10; i++) { |
| 616 | msleep(1); |
| 617 | val = readw(mmio_base + HOST_CTL); |
| 618 | if (!(val & HCTL_SOFTRST)) |
| 619 | break; |
| 620 | } |
| 621 | |
| 622 | if (val & HCTL_SOFTRST) |
| 623 | return -EIO; |
| 624 | |
| 625 | /* mask all interrupts and reset ports */ |
| 626 | for (i = 0; i < NR_PORTS; i++) { |
| 627 | void __iomem *port_base = mmio_base + i * PORT_SIZE; |
| 628 | |
| 629 | writeb(0xff, port_base + PORT_IRQ_MASK); |
| 630 | inic_reset_port(port_base); |
| 631 | } |
| 632 | |
| 633 | /* port IRQ is masked now, unmask global IRQ */ |
| 634 | writew(hctl & ~HCTL_IRQOFF, mmio_base + HOST_CTL); |
| 635 | val = readw(mmio_base + HOST_IRQ_MASK); |
| 636 | val &= ~(HIRQ_PORT0 | HIRQ_PORT1); |
| 637 | writew(val, mmio_base + HOST_IRQ_MASK); |
| 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 642 | #ifdef CONFIG_PM |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 643 | static int inic_pci_device_resume(struct pci_dev *pdev) |
| 644 | { |
| 645 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
| 646 | struct inic_host_priv *hpriv = host->private_data; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 647 | void __iomem *mmio_base = host->iomap[MMIO_BAR]; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 648 | int rc; |
| 649 | |
Dmitriy Monakhov | 5aea408 | 2007-03-06 02:37:54 -0800 | [diff] [blame] | 650 | rc = ata_pci_device_do_resume(pdev); |
| 651 | if (rc) |
| 652 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 653 | |
| 654 | if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 655 | rc = init_controller(mmio_base, hpriv->cached_hctl); |
| 656 | if (rc) |
| 657 | return rc; |
| 658 | } |
| 659 | |
| 660 | ata_host_resume(host); |
| 661 | |
| 662 | return 0; |
| 663 | } |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 664 | #endif |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 665 | |
| 666 | static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 667 | { |
| 668 | static int printed_version; |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 669 | const struct ata_port_info *ppi[] = { &inic_port_info, NULL }; |
| 670 | struct ata_host *host; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 671 | struct inic_host_priv *hpriv; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 672 | void __iomem * const *iomap; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 673 | int i, rc; |
| 674 | |
| 675 | if (!printed_version++) |
| 676 | dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); |
| 677 | |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 678 | /* alloc host */ |
| 679 | host = ata_host_alloc_pinfo(&pdev->dev, ppi, NR_PORTS); |
| 680 | hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); |
| 681 | if (!host || !hpriv) |
| 682 | return -ENOMEM; |
| 683 | |
| 684 | host->private_data = hpriv; |
| 685 | |
| 686 | /* acquire resources and fill host */ |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 687 | rc = pcim_enable_device(pdev); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 688 | if (rc) |
| 689 | return rc; |
| 690 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 691 | rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME); |
| 692 | if (rc) |
| 693 | return rc; |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 694 | host->iomap = iomap = pcim_iomap_table(pdev); |
| 695 | |
| 696 | for (i = 0; i < NR_PORTS; i++) { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 697 | struct ata_port *ap = host->ports[i]; |
| 698 | struct ata_ioports *port = &ap->ioaddr; |
| 699 | unsigned int offset = i * PORT_SIZE; |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 700 | |
| 701 | port->cmd_addr = iomap[2 * i]; |
| 702 | port->altstatus_addr = |
| 703 | port->ctl_addr = (void __iomem *) |
| 704 | ((unsigned long)iomap[2 * i + 1] | ATA_PCI_CTL_OFS); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 705 | port->scr_addr = iomap[MMIO_BAR] + offset + PORT_SCR; |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 706 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 707 | ata_sff_std_ports(port); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 708 | |
| 709 | ata_port_pbar_desc(ap, MMIO_BAR, -1, "mmio"); |
| 710 | ata_port_pbar_desc(ap, MMIO_BAR, offset, "port"); |
| 711 | ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", |
| 712 | (unsigned long long)pci_resource_start(pdev, 2 * i), |
| 713 | (unsigned long long)pci_resource_start(pdev, (2 * i + 1)) | |
| 714 | ATA_PCI_CTL_OFS); |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | hpriv->cached_hctl = readw(iomap[MMIO_BAR] + HOST_CTL); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 718 | |
| 719 | /* Set dma_mask. This devices doesn't support 64bit addressing. */ |
| 720 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 721 | if (rc) { |
| 722 | dev_printk(KERN_ERR, &pdev->dev, |
| 723 | "32-bit DMA enable failed\n"); |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 724 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 728 | if (rc) { |
| 729 | dev_printk(KERN_ERR, &pdev->dev, |
| 730 | "32-bit consistent DMA enable failed\n"); |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 731 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 732 | } |
| 733 | |
FUJITA Tomonori | b7d8629 | 2008-02-04 22:28:05 -0800 | [diff] [blame] | 734 | /* |
| 735 | * This controller is braindamaged. dma_boundary is 0xffff |
| 736 | * like others but it will lock up the whole machine HARD if |
| 737 | * 65536 byte PRD entry is fed. Reduce maximum segment size. |
| 738 | */ |
| 739 | rc = pci_set_dma_max_seg_size(pdev, 65536 - 512); |
| 740 | if (rc) { |
| 741 | dev_printk(KERN_ERR, &pdev->dev, |
| 742 | "failed to set the maximum segment size.\n"); |
| 743 | return rc; |
| 744 | } |
| 745 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 746 | rc = init_controller(iomap[MMIO_BAR], hpriv->cached_hctl); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 747 | if (rc) { |
| 748 | dev_printk(KERN_ERR, &pdev->dev, |
| 749 | "failed to initialize controller\n"); |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 750 | return rc; |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | pci_set_master(pdev); |
Tejun Heo | 4447d35 | 2007-04-17 23:44:08 +0900 | [diff] [blame] | 754 | return ata_host_activate(host, pdev->irq, inic_interrupt, IRQF_SHARED, |
| 755 | &inic_sht); |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static const struct pci_device_id inic_pci_tbl[] = { |
| 759 | { PCI_VDEVICE(INIT, 0x1622), }, |
| 760 | { }, |
| 761 | }; |
| 762 | |
| 763 | static struct pci_driver inic_pci_driver = { |
| 764 | .name = DRV_NAME, |
| 765 | .id_table = inic_pci_tbl, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 766 | #ifdef CONFIG_PM |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 767 | .suspend = ata_pci_device_suspend, |
| 768 | .resume = inic_pci_device_resume, |
Tejun Heo | 438ac6d | 2007-03-02 17:31:26 +0900 | [diff] [blame] | 769 | #endif |
Tejun Heo | 1fd7a69 | 2007-01-03 17:32:45 +0900 | [diff] [blame] | 770 | .probe = inic_init_one, |
| 771 | .remove = ata_pci_remove_one, |
| 772 | }; |
| 773 | |
| 774 | static int __init inic_init(void) |
| 775 | { |
| 776 | return pci_register_driver(&inic_pci_driver); |
| 777 | } |
| 778 | |
| 779 | static void __exit inic_exit(void) |
| 780 | { |
| 781 | pci_unregister_driver(&inic_pci_driver); |
| 782 | } |
| 783 | |
| 784 | MODULE_AUTHOR("Tejun Heo"); |
| 785 | MODULE_DESCRIPTION("low-level driver for Initio 162x SATA"); |
| 786 | MODULE_LICENSE("GPL v2"); |
| 787 | MODULE_DEVICE_TABLE(pci, inic_pci_tbl); |
| 788 | MODULE_VERSION(DRV_VERSION); |
| 789 | |
| 790 | module_init(inic_init); |
| 791 | module_exit(inic_exit); |