blob: b4cbc9d6be1b9a4f7e2bc401bdca417caf0143d7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sata_promise.c - Promise SATA
3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
6 * on emails.
7 *
8 * Copyright 2003-2004 Red Hat, Inc.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Jeff Garzikaf36d7f2005-08-28 20:18:39 -040011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *
26 * libata documentation is available via 'make {ps|pdf}docs',
27 * as Documentation/DocBook/libata.*
28 *
29 * Hardware information only available under NDA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
31 */
32
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/pci.h>
36#include <linux/init.h>
37#include <linux/blkdev.h>
38#include <linux/delay.h>
39#include <linux/interrupt.h>
40#include <linux/sched.h>
Jeff Garzika9524a72005-10-30 14:39:11 -050041#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <scsi/scsi_host.h>
Jeff Garzik193515d2005-11-07 00:59:37 -050043#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/libata.h>
45#include <asm/io.h>
46#include "sata_promise.h"
47
48#define DRV_NAME "sata_promise"
Jeff Garzik7bdd7202005-11-16 11:06:59 -050049#define DRV_VERSION "1.03"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51
52enum {
53 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
54 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
55 PDC_TBG_MODE = 0x41, /* TBG mode */
56 PDC_FLASH_CTL = 0x44, /* Flash control register */
57 PDC_PCI_CTL = 0x48, /* PCI control and status register */
58 PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */
59 PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */
60 PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */
61 PDC_SLEW_CTL = 0x470, /* slew rate control reg */
62
63 PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) |
64 (1<<8) | (1<<9) | (1<<10),
65
66 board_2037x = 0, /* FastTrak S150 TX2plus */
67 board_20319 = 1, /* FastTrak S150 TX4 */
Tobias Lorenzf497ba72005-05-12 15:51:01 -040068 board_20619 = 2, /* FastTrak TX4000 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */
71
72 PDC_RESET = (1 << 11), /* HDMA reset */
73};
74
75
76struct pdc_port_priv {
77 u8 *pkt;
78 dma_addr_t pkt_dma;
79};
80
81static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
82static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
83static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
84static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
85static void pdc_eng_timeout(struct ata_port *ap);
86static int pdc_port_start(struct ata_port *ap);
87static void pdc_port_stop(struct ata_port *ap);
Jeff Garzik2cba5822005-08-29 05:12:30 -040088static void pdc_pata_phy_reset(struct ata_port *ap);
89static void pdc_sata_phy_reset(struct ata_port *ap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static void pdc_qc_prep(struct ata_queued_cmd *qc);
Jeff Garzik057ace52005-10-22 14:27:05 -040091static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
92static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static void pdc_irq_clear(struct ata_port *ap);
94static int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
95
Jeff Garzik374b1872005-08-30 05:42:52 -040096
Jeff Garzik193515d2005-11-07 00:59:37 -050097static struct scsi_host_template pdc_ata_sht = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .module = THIS_MODULE,
99 .name = DRV_NAME,
100 .ioctl = ata_scsi_ioctl,
101 .queuecommand = ata_scsi_queuecmd,
102 .eh_strategy_handler = ata_scsi_error,
103 .can_queue = ATA_DEF_QUEUE,
104 .this_id = ATA_SHT_THIS_ID,
105 .sg_tablesize = LIBATA_MAX_PRD,
106 .max_sectors = ATA_MAX_SECTORS,
107 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
108 .emulated = ATA_SHT_EMULATED,
109 .use_clustering = ATA_SHT_USE_CLUSTERING,
110 .proc_name = DRV_NAME,
111 .dma_boundary = ATA_DMA_BOUNDARY,
112 .slave_configure = ata_scsi_slave_config,
113 .bios_param = ata_std_bios_param,
114 .ordered_flush = 1,
115};
116
Jeff Garzik057ace52005-10-22 14:27:05 -0400117static const struct ata_port_operations pdc_sata_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .port_disable = ata_port_disable,
119 .tf_load = pdc_tf_load_mmio,
120 .tf_read = ata_tf_read,
121 .check_status = ata_check_status,
122 .exec_command = pdc_exec_command_mmio,
123 .dev_select = ata_std_dev_select,
Jeff Garzik2cba5822005-08-29 05:12:30 -0400124
125 .phy_reset = pdc_sata_phy_reset,
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .qc_prep = pdc_qc_prep,
128 .qc_issue = pdc_qc_issue_prot,
129 .eng_timeout = pdc_eng_timeout,
130 .irq_handler = pdc_interrupt,
131 .irq_clear = pdc_irq_clear,
Jeff Garzik2cba5822005-08-29 05:12:30 -0400132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .scr_read = pdc_sata_scr_read,
134 .scr_write = pdc_sata_scr_write,
135 .port_start = pdc_port_start,
136 .port_stop = pdc_port_stop,
Jeff Garzik374b1872005-08-30 05:42:52 -0400137 .host_stop = ata_pci_host_stop,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138};
139
Jeff Garzik057ace52005-10-22 14:27:05 -0400140static const struct ata_port_operations pdc_pata_ops = {
Jeff Garzik2cba5822005-08-29 05:12:30 -0400141 .port_disable = ata_port_disable,
142 .tf_load = pdc_tf_load_mmio,
143 .tf_read = ata_tf_read,
144 .check_status = ata_check_status,
145 .exec_command = pdc_exec_command_mmio,
146 .dev_select = ata_std_dev_select,
147
148 .phy_reset = pdc_pata_phy_reset,
149
150 .qc_prep = pdc_qc_prep,
151 .qc_issue = pdc_qc_issue_prot,
152 .eng_timeout = pdc_eng_timeout,
153 .irq_handler = pdc_interrupt,
154 .irq_clear = pdc_irq_clear,
155
156 .port_start = pdc_port_start,
157 .port_stop = pdc_port_stop,
Jeff Garzik374b1872005-08-30 05:42:52 -0400158 .host_stop = ata_pci_host_stop,
Jeff Garzik2cba5822005-08-29 05:12:30 -0400159};
160
Arjan van de Ven98ac62d2005-11-28 10:06:23 +0100161static const struct ata_port_info pdc_port_info[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* board_2037x */
163 {
164 .sht = &pdc_ata_sht,
165 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
Albert Leee50362e2005-09-27 17:39:50 +0800166 ATA_FLAG_SRST | ATA_FLAG_MMIO |
167 ATA_FLAG_PIO_POLLING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 .pio_mask = 0x1f, /* pio0-4 */
169 .mwdma_mask = 0x07, /* mwdma0-2 */
170 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400171 .port_ops = &pdc_sata_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 },
173
174 /* board_20319 */
175 {
176 .sht = &pdc_ata_sht,
177 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
Albert Leee50362e2005-09-27 17:39:50 +0800178 ATA_FLAG_SRST | ATA_FLAG_MMIO |
179 ATA_FLAG_PIO_POLLING,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .pio_mask = 0x1f, /* pio0-4 */
181 .mwdma_mask = 0x07, /* mwdma0-2 */
182 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400183 .port_ops = &pdc_sata_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 },
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400185
186 /* board_20619 */
187 {
188 .sht = &pdc_ata_sht,
189 .host_flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST |
Albert Leee50362e2005-09-27 17:39:50 +0800190 ATA_FLAG_MMIO | ATA_FLAG_SLAVE_POSS |
191 ATA_FLAG_PIO_POLLING,
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400192 .pio_mask = 0x1f, /* pio0-4 */
193 .mwdma_mask = 0x07, /* mwdma0-2 */
194 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
Jeff Garzik2cba5822005-08-29 05:12:30 -0400195 .port_ops = &pdc_pata_ops,
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400196 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500199static const struct pci_device_id pdc_ata_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 { PCI_VENDOR_ID_PROMISE, 0x3371, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
201 board_2037x },
Jeff Garzik07c1da22005-10-28 17:00:31 -0400202 { PCI_VENDOR_ID_PROMISE, 0x3570, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
203 board_2037x },
Francisco Javier4c3a53d2005-05-25 19:29:37 -0400204 { PCI_VENDOR_ID_PROMISE, 0x3571, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
205 board_2037x },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 { PCI_VENDOR_ID_PROMISE, 0x3373, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
207 board_2037x },
208 { PCI_VENDOR_ID_PROMISE, 0x3375, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
209 board_2037x },
210 { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
211 board_2037x },
212 { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
213 board_2037x },
214 { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
215 board_2037x },
Ed Kearc45154a2005-07-16 23:32:19 -0400216 { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
217 board_2037x },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 { PCI_VENDOR_ID_PROMISE, 0x3318, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
220 board_20319 },
221 { PCI_VENDOR_ID_PROMISE, 0x3319, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
222 board_20319 },
Daniel Drake93090492005-08-22 14:59:23 +0100223 { PCI_VENDOR_ID_PROMISE, 0x3519, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
224 board_20319 },
Otto Meier08b791c02005-08-22 14:58:57 +0100225 { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
226 board_20319 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
228 board_20319 },
229
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400230 { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
231 board_20619 },
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 { } /* terminate list */
234};
235
236
237static struct pci_driver pdc_ata_pci_driver = {
238 .name = DRV_NAME,
239 .id_table = pdc_ata_pci_tbl,
240 .probe = pdc_ata_init_one,
241 .remove = ata_pci_remove_one,
242};
243
244
245static int pdc_port_start(struct ata_port *ap)
246{
247 struct device *dev = ap->host_set->dev;
248 struct pdc_port_priv *pp;
249 int rc;
250
251 rc = ata_port_start(ap);
252 if (rc)
253 return rc;
254
255 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
256 if (!pp) {
257 rc = -ENOMEM;
258 goto err_out;
259 }
260 memset(pp, 0, sizeof(*pp));
261
262 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
263 if (!pp->pkt) {
264 rc = -ENOMEM;
265 goto err_out_kfree;
266 }
267
268 ap->private_data = pp;
269
270 return 0;
271
272err_out_kfree:
273 kfree(pp);
274err_out:
275 ata_port_stop(ap);
276 return rc;
277}
278
279
280static void pdc_port_stop(struct ata_port *ap)
281{
282 struct device *dev = ap->host_set->dev;
283 struct pdc_port_priv *pp = ap->private_data;
284
285 ap->private_data = NULL;
286 dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
287 kfree(pp);
288 ata_port_stop(ap);
289}
290
291
292static void pdc_reset_port(struct ata_port *ap)
293{
Jeff Garzikea6ba102005-08-30 05:18:18 -0400294 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 unsigned int i;
296 u32 tmp;
297
298 for (i = 11; i > 0; i--) {
299 tmp = readl(mmio);
300 if (tmp & PDC_RESET)
301 break;
302
303 udelay(100);
304
305 tmp |= PDC_RESET;
306 writel(tmp, mmio);
307 }
308
309 tmp &= ~PDC_RESET;
310 writel(tmp, mmio);
311 readl(mmio); /* flush */
312}
313
Jeff Garzik2cba5822005-08-29 05:12:30 -0400314static void pdc_sata_phy_reset(struct ata_port *ap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 pdc_reset_port(ap);
317 sata_phy_reset(ap);
318}
319
Jeff Garzik2cba5822005-08-29 05:12:30 -0400320static void pdc_pata_phy_reset(struct ata_port *ap)
321{
322 /* FIXME: add cable detect. Don't assume 40-pin cable */
323 ap->cbl = ATA_CBL_PATA40;
324 ap->udma_mask &= ATA_UDMA_MASK_40C;
325
326 pdc_reset_port(ap);
327 ata_port_probe(ap);
328 ata_bus_reset(ap);
329}
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
332{
333 if (sc_reg > SCR_CONTROL)
334 return 0xffffffffU;
Al Virob181d3b2005-10-21 06:46:02 +0100335 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338
339static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
340 u32 val)
341{
342 if (sc_reg > SCR_CONTROL)
343 return;
Al Virob181d3b2005-10-21 06:46:02 +0100344 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347static void pdc_qc_prep(struct ata_queued_cmd *qc)
348{
349 struct pdc_port_priv *pp = qc->ap->private_data;
350 unsigned int i;
351
352 VPRINTK("ENTER\n");
353
354 switch (qc->tf.protocol) {
355 case ATA_PROT_DMA:
356 ata_qc_prep(qc);
357 /* fall through */
358
359 case ATA_PROT_NODATA:
360 i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
361 qc->dev->devno, pp->pkt);
362
363 if (qc->tf.flags & ATA_TFLAG_LBA48)
364 i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
365 else
366 i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
367
368 pdc_pkt_footer(&qc->tf, pp->pkt, i);
369 break;
370
371 default:
372 break;
373 }
374}
375
376static void pdc_eng_timeout(struct ata_port *ap)
377{
Jeff Garzikb8f61532005-08-25 22:01:20 -0400378 struct ata_host_set *host_set = ap->host_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 u8 drv_stat;
380 struct ata_queued_cmd *qc;
Jeff Garzikb8f61532005-08-25 22:01:20 -0400381 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 DPRINTK("ENTER\n");
384
Jeff Garzikb8f61532005-08-25 22:01:20 -0400385 spin_lock_irqsave(&host_set->lock, flags);
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 qc = ata_qc_from_tag(ap, ap->active_tag);
388 if (!qc) {
389 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
390 ap->id);
391 goto out;
392 }
393
394 /* hack alert! We cannot use the supplied completion
395 * function from inside the ->eh_strategy_handler() thread.
396 * libata is the only user of ->eh_strategy_handler() in
397 * any kernel, so the default scsi_done() assumes it is
398 * not being called from the SCSI EH.
399 */
400 qc->scsidone = scsi_finish_command;
401
402 switch (qc->tf.protocol) {
403 case ATA_PROT_DMA:
404 case ATA_PROT_NODATA:
405 printk(KERN_ERR "ata%u: command timeout\n", ap->id);
Jeff Garzika7dac442005-10-30 04:44:42 -0500406 drv_stat = ata_wait_idle(ap);
Albert Leea22e2eb2005-12-05 15:38:02 +0800407 qc->err_mask |= __ac_err_mask(drv_stat);
408 ata_qc_complete(qc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 break;
410
411 default:
412 drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
413
414 printk(KERN_ERR "ata%u: unknown timeout, cmd 0x%x stat 0x%x\n",
415 ap->id, qc->tf.command, drv_stat);
416
Albert Leea22e2eb2005-12-05 15:38:02 +0800417 qc->err_mask |= ac_err_mask(drv_stat);
418 ata_qc_complete(qc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 break;
420 }
421
422out:
Jeff Garzikb8f61532005-08-25 22:01:20 -0400423 spin_unlock_irqrestore(&host_set->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 DPRINTK("EXIT\n");
425}
426
427static inline unsigned int pdc_host_intr( struct ata_port *ap,
428 struct ata_queued_cmd *qc)
429{
Albert Leea22e2eb2005-12-05 15:38:02 +0800430 unsigned int handled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 u32 tmp;
Jeff Garzikea6ba102005-08-30 05:18:18 -0400432 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 tmp = readl(mmio);
435 if (tmp & PDC_ERR_MASK) {
Albert Leea22e2eb2005-12-05 15:38:02 +0800436 qc->err_mask |= AC_ERR_DEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 pdc_reset_port(ap);
438 }
439
440 switch (qc->tf.protocol) {
441 case ATA_PROT_DMA:
442 case ATA_PROT_NODATA:
Albert Leea22e2eb2005-12-05 15:38:02 +0800443 qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
444 ata_qc_complete(qc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 handled = 1;
446 break;
447
448 default:
Albert Leeee500aa2005-09-27 17:34:38 +0800449 ap->stats.idle_irq++;
450 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
452
Albert Leeee500aa2005-09-27 17:34:38 +0800453 return handled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
456static void pdc_irq_clear(struct ata_port *ap)
457{
458 struct ata_host_set *host_set = ap->host_set;
Jeff Garzikea6ba102005-08-30 05:18:18 -0400459 void __iomem *mmio = host_set->mmio_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 readl(mmio + PDC_INT_SEQMASK);
462}
463
464static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *regs)
465{
466 struct ata_host_set *host_set = dev_instance;
467 struct ata_port *ap;
468 u32 mask = 0;
469 unsigned int i, tmp;
470 unsigned int handled = 0;
Jeff Garzikea6ba102005-08-30 05:18:18 -0400471 void __iomem *mmio_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 VPRINTK("ENTER\n");
474
475 if (!host_set || !host_set->mmio_base) {
476 VPRINTK("QUICK EXIT\n");
477 return IRQ_NONE;
478 }
479
480 mmio_base = host_set->mmio_base;
481
482 /* reading should also clear interrupts */
483 mask = readl(mmio_base + PDC_INT_SEQMASK);
484
485 if (mask == 0xffffffff) {
486 VPRINTK("QUICK EXIT 2\n");
487 return IRQ_NONE;
488 }
489 mask &= 0xffff; /* only 16 tags possible */
490 if (!mask) {
491 VPRINTK("QUICK EXIT 3\n");
492 return IRQ_NONE;
493 }
494
495 spin_lock(&host_set->lock);
496
497 writel(mask, mmio_base + PDC_INT_SEQMASK);
498
499 for (i = 0; i < host_set->n_ports; i++) {
500 VPRINTK("port %u\n", i);
501 ap = host_set->ports[i];
502 tmp = mask & (1 << (i + 1));
Tejun Heoc1389502005-08-22 14:59:24 +0900503 if (tmp && ap &&
Albert Leee50362e2005-09-27 17:39:50 +0800504 !(ap->flags & ATA_FLAG_PORT_DISABLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 struct ata_queued_cmd *qc;
506
507 qc = ata_qc_from_tag(ap, ap->active_tag);
Albert Leee50362e2005-09-27 17:39:50 +0800508 if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 handled += pdc_host_intr(ap, qc);
510 }
511 }
512
513 spin_unlock(&host_set->lock);
514
515 VPRINTK("EXIT\n");
516
517 return IRQ_RETVAL(handled);
518}
519
520static inline void pdc_packet_start(struct ata_queued_cmd *qc)
521{
522 struct ata_port *ap = qc->ap;
523 struct pdc_port_priv *pp = ap->private_data;
524 unsigned int port_no = ap->port_no;
525 u8 seq = (u8) (port_no + 1);
526
527 VPRINTK("ENTER, ap %p\n", ap);
528
529 writel(0x00000001, ap->host_set->mmio_base + (seq * 4));
530 readl(ap->host_set->mmio_base + (seq * 4)); /* flush */
531
532 pp->pkt[2] = seq;
533 wmb(); /* flush PRD, pkt writes */
Al Virob181d3b2005-10-21 06:46:02 +0100534 writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
535 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
538static int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
539{
540 switch (qc->tf.protocol) {
541 case ATA_PROT_DMA:
542 case ATA_PROT_NODATA:
543 pdc_packet_start(qc);
544 return 0;
545
546 case ATA_PROT_ATAPI_DMA:
547 BUG();
548 break;
549
550 default:
551 break;
552 }
553
554 return ata_qc_issue_prot(qc);
555}
556
Jeff Garzik057ace52005-10-22 14:27:05 -0400557static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558{
559 WARN_ON (tf->protocol == ATA_PROT_DMA ||
560 tf->protocol == ATA_PROT_NODATA);
561 ata_tf_load(ap, tf);
562}
563
564
Jeff Garzik057ace52005-10-22 14:27:05 -0400565static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
567 WARN_ON (tf->protocol == ATA_PROT_DMA ||
568 tf->protocol == ATA_PROT_NODATA);
569 ata_exec_command(ap, tf);
570}
571
572
573static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
574{
575 port->cmd_addr = base;
576 port->data_addr = base;
577 port->feature_addr =
578 port->error_addr = base + 0x4;
579 port->nsect_addr = base + 0x8;
580 port->lbal_addr = base + 0xc;
581 port->lbam_addr = base + 0x10;
582 port->lbah_addr = base + 0x14;
583 port->device_addr = base + 0x18;
584 port->command_addr =
585 port->status_addr = base + 0x1c;
586 port->altstatus_addr =
587 port->ctl_addr = base + 0x38;
588}
589
590
591static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
592{
Jeff Garzikea6ba102005-08-30 05:18:18 -0400593 void __iomem *mmio = pe->mmio_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 u32 tmp;
595
596 /*
597 * Except for the hotplug stuff, this is voodoo from the
598 * Promise driver. Label this entire section
599 * "TODO: figure out why we do this"
600 */
601
602 /* change FIFO_SHD to 8 dwords, enable BMR_BURST */
603 tmp = readl(mmio + PDC_FLASH_CTL);
604 tmp |= 0x12000; /* bit 16 (fifo 8 dw) and 13 (bmr burst?) */
605 writel(tmp, mmio + PDC_FLASH_CTL);
606
607 /* clear plug/unplug flags for all ports */
608 tmp = readl(mmio + PDC_SATA_PLUG_CSR);
609 writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR);
610
611 /* mask plug/unplug ints */
612 tmp = readl(mmio + PDC_SATA_PLUG_CSR);
613 writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR);
614
615 /* reduce TBG clock to 133 Mhz. */
616 tmp = readl(mmio + PDC_TBG_MODE);
617 tmp &= ~0x30000; /* clear bit 17, 16*/
618 tmp |= 0x10000; /* set bit 17:16 = 0:1 */
619 writel(tmp, mmio + PDC_TBG_MODE);
620
621 readl(mmio + PDC_TBG_MODE); /* flush */
622 msleep(10);
623
624 /* adjust slew rate control register. */
625 tmp = readl(mmio + PDC_SLEW_CTL);
626 tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
627 tmp |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
628 writel(tmp, mmio + PDC_SLEW_CTL);
629}
630
631static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
632{
633 static int printed_version;
634 struct ata_probe_ent *probe_ent = NULL;
635 unsigned long base;
Jeff Garzikea6ba102005-08-30 05:18:18 -0400636 void __iomem *mmio_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 unsigned int board_idx = (unsigned int) ent->driver_data;
638 int pci_dev_busy = 0;
639 int rc;
640
641 if (!printed_version++)
Jeff Garzika9524a72005-10-30 14:39:11 -0500642 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 /*
645 * If this driver happens to only be useful on Apple's K2, then
646 * we should check that here as it has a normal Serverworks ID
647 */
648 rc = pci_enable_device(pdev);
649 if (rc)
650 return rc;
651
652 rc = pci_request_regions(pdev, DRV_NAME);
653 if (rc) {
654 pci_dev_busy = 1;
655 goto err_out;
656 }
657
658 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
659 if (rc)
660 goto err_out_regions;
661 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
662 if (rc)
663 goto err_out_regions;
664
665 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
666 if (probe_ent == NULL) {
667 rc = -ENOMEM;
668 goto err_out_regions;
669 }
670
671 memset(probe_ent, 0, sizeof(*probe_ent));
672 probe_ent->dev = pci_dev_to_dev(pdev);
673 INIT_LIST_HEAD(&probe_ent->node);
674
Jeff Garzik374b1872005-08-30 05:42:52 -0400675 mmio_base = pci_iomap(pdev, 3, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if (mmio_base == NULL) {
677 rc = -ENOMEM;
678 goto err_out_free_ent;
679 }
680 base = (unsigned long) mmio_base;
681
682 probe_ent->sht = pdc_port_info[board_idx].sht;
683 probe_ent->host_flags = pdc_port_info[board_idx].host_flags;
684 probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask;
685 probe_ent->mwdma_mask = pdc_port_info[board_idx].mwdma_mask;
686 probe_ent->udma_mask = pdc_port_info[board_idx].udma_mask;
687 probe_ent->port_ops = pdc_port_info[board_idx].port_ops;
688
689 probe_ent->irq = pdev->irq;
690 probe_ent->irq_flags = SA_SHIRQ;
691 probe_ent->mmio_base = mmio_base;
692
693 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
694 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
695
696 probe_ent->port[0].scr_addr = base + 0x400;
697 probe_ent->port[1].scr_addr = base + 0x500;
698
699 /* notice 4-port boards */
700 switch (board_idx) {
701 case board_20319:
702 probe_ent->n_ports = 4;
703
704 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
705 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
706
707 probe_ent->port[2].scr_addr = base + 0x600;
708 probe_ent->port[3].scr_addr = base + 0x700;
709 break;
710 case board_2037x:
Jeff Garzik6c9e5eb2005-11-30 16:42:55 -0500711 probe_ent->n_ports = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 break;
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400713 case board_20619:
714 probe_ent->n_ports = 4;
715
716 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
717 pdc_ata_setup_port(&probe_ent->port[3], base + 0x380);
718
719 probe_ent->port[2].scr_addr = base + 0x600;
720 probe_ent->port[3].scr_addr = base + 0x700;
Jeff Garzik6c9e5eb2005-11-30 16:42:55 -0500721 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 default:
723 BUG();
724 break;
725 }
726
727 pci_set_master(pdev);
728
729 /* initialize adapter */
730 pdc_host_init(board_idx, probe_ent);
731
732 /* FIXME: check ata_device_add return value */
733 ata_device_add(probe_ent);
734 kfree(probe_ent);
735
736 return 0;
737
738err_out_free_ent:
739 kfree(probe_ent);
740err_out_regions:
741 pci_release_regions(pdev);
742err_out:
743 if (!pci_dev_busy)
744 pci_disable_device(pdev);
745 return rc;
746}
747
748
749static int __init pdc_ata_init(void)
750{
751 return pci_module_init(&pdc_ata_pci_driver);
752}
753
754
755static void __exit pdc_ata_exit(void)
756{
757 pci_unregister_driver(&pdc_ata_pci_driver);
758}
759
760
761MODULE_AUTHOR("Jeff Garzik");
Tobias Lorenzf497ba72005-05-12 15:51:01 -0400762MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763MODULE_LICENSE("GPL");
764MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
765MODULE_VERSION(DRV_VERSION);
766
767module_init(pdc_ata_init);
768module_exit(pdc_ata_exit);