aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/sata_promise.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
commit48c871c1f6a7c7044dd76774fb469e65c7e2e4e8 (patch)
treeda3aa535c98cc0957851354ceb0fbff7482d7a9d /drivers/ata/sata_promise.c
parent1a1689344add3333d28d1b5495d8043a3877d01c (diff)
parent4409d28140d9a6e6e3f4f1fdaf7234c4b965d954 (diff)
Merge branch 'gfar' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc into upstream
Diffstat (limited to 'drivers/ata/sata_promise.c')
-rw-r--r--drivers/ata/sata_promise.c379
1 files changed, 263 insertions, 116 deletions
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index f055874a6ec5..3be4cc338d7b 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -39,10 +39,10 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h> 41#include <linux/device.h>
42#include <scsi/scsi.h>
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <scsi/scsi_cmnd.h> 44#include <scsi/scsi_cmnd.h>
44#include <linux/libata.h> 45#include <linux/libata.h>
45#include <asm/io.h>
46#include "sata_promise.h" 46#include "sata_promise.h"
47 47
48#define DRV_NAME "sata_promise" 48#define DRV_NAME "sata_promise"
@@ -50,6 +50,17 @@
50 50
51 51
52enum { 52enum {
53 PDC_MMIO_BAR = 3,
54
55 /* register offsets */
56 PDC_FEATURE = 0x04, /* Feature/Error reg (per port) */
57 PDC_SECTOR_COUNT = 0x08, /* Sector count reg (per port) */
58 PDC_SECTOR_NUMBER = 0x0C, /* Sector number reg (per port) */
59 PDC_CYLINDER_LOW = 0x10, /* Cylinder low reg (per port) */
60 PDC_CYLINDER_HIGH = 0x14, /* Cylinder high reg (per port) */
61 PDC_DEVICE = 0x18, /* Device/Head reg (per port) */
62 PDC_COMMAND = 0x1C, /* Command/status reg (per port) */
63 PDC_ALTSTATUS = 0x38, /* Alternate-status/device-control reg (per port) */
53 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */ 64 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
54 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */ 65 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
55 PDC_FLASH_CTL = 0x44, /* Flash control register */ 66 PDC_FLASH_CTL = 0x44, /* Flash control register */
@@ -71,13 +82,23 @@ enum {
71 82
72 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */ 83 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
73 84
85 /* Sequence counter control registers bit definitions */
86 PDC_SEQCNTRL_INT_MASK = (1 << 5), /* Sequence Interrupt Mask */
87
88 /* Feature register values */
89 PDC_FEATURE_ATAPI_PIO = 0x00, /* ATAPI data xfer by PIO */
90 PDC_FEATURE_ATAPI_DMA = 0x01, /* ATAPI data xfer by DMA */
91
92 /* Device/Head register values */
93 PDC_DEVICE_SATA = 0xE0, /* Device/Head value for SATA devices */
94
74 /* PDC_CTLSTAT bit definitions */ 95 /* PDC_CTLSTAT bit definitions */
75 PDC_DMA_ENABLE = (1 << 7), 96 PDC_DMA_ENABLE = (1 << 7),
76 PDC_IRQ_DISABLE = (1 << 10), 97 PDC_IRQ_DISABLE = (1 << 10),
77 PDC_RESET = (1 << 11), /* HDMA reset */ 98 PDC_RESET = (1 << 11), /* HDMA reset */
78 99
79 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | 100 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY |
80 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | 101 ATA_FLAG_MMIO |
81 ATA_FLAG_PIO_POLLING, 102 ATA_FLAG_PIO_POLLING,
82 103
83 /* hp->flags bits */ 104 /* hp->flags bits */
@@ -92,6 +113,7 @@ struct pdc_port_priv {
92 113
93struct pdc_host_priv { 114struct pdc_host_priv {
94 unsigned long flags; 115 unsigned long flags;
116 unsigned long port_flags[ATA_MAX_PORTS];
95}; 117};
96 118
97static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 119static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
@@ -100,14 +122,14 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
100static irqreturn_t pdc_interrupt (int irq, void *dev_instance); 122static irqreturn_t pdc_interrupt (int irq, void *dev_instance);
101static void pdc_eng_timeout(struct ata_port *ap); 123static void pdc_eng_timeout(struct ata_port *ap);
102static int pdc_port_start(struct ata_port *ap); 124static int pdc_port_start(struct ata_port *ap);
103static void pdc_port_stop(struct ata_port *ap);
104static void pdc_pata_phy_reset(struct ata_port *ap); 125static void pdc_pata_phy_reset(struct ata_port *ap);
105static void pdc_qc_prep(struct ata_queued_cmd *qc); 126static void pdc_qc_prep(struct ata_queued_cmd *qc);
106static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 127static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
107static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 128static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
129static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
130static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc);
108static void pdc_irq_clear(struct ata_port *ap); 131static void pdc_irq_clear(struct ata_port *ap);
109static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 132static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
110static void pdc_host_stop(struct ata_host *host);
111static void pdc_freeze(struct ata_port *ap); 133static void pdc_freeze(struct ata_port *ap);
112static void pdc_thaw(struct ata_port *ap); 134static void pdc_thaw(struct ata_port *ap);
113static void pdc_error_handler(struct ata_port *ap); 135static void pdc_error_handler(struct ata_port *ap);
@@ -139,6 +161,34 @@ static const struct ata_port_operations pdc_sata_ops = {
139 .check_status = ata_check_status, 161 .check_status = ata_check_status,
140 .exec_command = pdc_exec_command_mmio, 162 .exec_command = pdc_exec_command_mmio,
141 .dev_select = ata_std_dev_select, 163 .dev_select = ata_std_dev_select,
164 .check_atapi_dma = pdc_check_atapi_dma,
165
166 .qc_prep = pdc_qc_prep,
167 .qc_issue = pdc_qc_issue_prot,
168 .freeze = pdc_freeze,
169 .thaw = pdc_thaw,
170 .error_handler = pdc_error_handler,
171 .post_internal_cmd = pdc_post_internal_cmd,
172 .data_xfer = ata_data_xfer,
173 .irq_handler = pdc_interrupt,
174 .irq_clear = pdc_irq_clear,
175 .irq_on = ata_irq_on,
176 .irq_ack = ata_irq_ack,
177
178 .scr_read = pdc_sata_scr_read,
179 .scr_write = pdc_sata_scr_write,
180 .port_start = pdc_port_start,
181};
182
183/* First-generation chips need a more restrictive ->check_atapi_dma op */
184static const struct ata_port_operations pdc_old_sata_ops = {
185 .port_disable = ata_port_disable,
186 .tf_load = pdc_tf_load_mmio,
187 .tf_read = ata_tf_read,
188 .check_status = ata_check_status,
189 .exec_command = pdc_exec_command_mmio,
190 .dev_select = ata_std_dev_select,
191 .check_atapi_dma = pdc_old_check_atapi_dma,
142 192
143 .qc_prep = pdc_qc_prep, 193 .qc_prep = pdc_qc_prep,
144 .qc_issue = pdc_qc_issue_prot, 194 .qc_issue = pdc_qc_issue_prot,
@@ -146,15 +196,15 @@ static const struct ata_port_operations pdc_sata_ops = {
146 .thaw = pdc_thaw, 196 .thaw = pdc_thaw,
147 .error_handler = pdc_error_handler, 197 .error_handler = pdc_error_handler,
148 .post_internal_cmd = pdc_post_internal_cmd, 198 .post_internal_cmd = pdc_post_internal_cmd,
149 .data_xfer = ata_mmio_data_xfer, 199 .data_xfer = ata_data_xfer,
150 .irq_handler = pdc_interrupt, 200 .irq_handler = pdc_interrupt,
151 .irq_clear = pdc_irq_clear, 201 .irq_clear = pdc_irq_clear,
202 .irq_on = ata_irq_on,
203 .irq_ack = ata_irq_ack,
152 204
153 .scr_read = pdc_sata_scr_read, 205 .scr_read = pdc_sata_scr_read,
154 .scr_write = pdc_sata_scr_write, 206 .scr_write = pdc_sata_scr_write,
155 .port_start = pdc_port_start, 207 .port_start = pdc_port_start,
156 .port_stop = pdc_port_stop,
157 .host_stop = pdc_host_stop,
158}; 208};
159 209
160static const struct ata_port_operations pdc_pata_ops = { 210static const struct ata_port_operations pdc_pata_ops = {
@@ -164,30 +214,31 @@ static const struct ata_port_operations pdc_pata_ops = {
164 .check_status = ata_check_status, 214 .check_status = ata_check_status,
165 .exec_command = pdc_exec_command_mmio, 215 .exec_command = pdc_exec_command_mmio,
166 .dev_select = ata_std_dev_select, 216 .dev_select = ata_std_dev_select,
217 .check_atapi_dma = pdc_check_atapi_dma,
167 218
168 .phy_reset = pdc_pata_phy_reset, 219 .phy_reset = pdc_pata_phy_reset,
169 220
170 .qc_prep = pdc_qc_prep, 221 .qc_prep = pdc_qc_prep,
171 .qc_issue = pdc_qc_issue_prot, 222 .qc_issue = pdc_qc_issue_prot,
172 .data_xfer = ata_mmio_data_xfer, 223 .data_xfer = ata_data_xfer,
173 .eng_timeout = pdc_eng_timeout, 224 .eng_timeout = pdc_eng_timeout,
174 .irq_handler = pdc_interrupt, 225 .irq_handler = pdc_interrupt,
175 .irq_clear = pdc_irq_clear, 226 .irq_clear = pdc_irq_clear,
227 .irq_on = ata_irq_on,
228 .irq_ack = ata_irq_ack,
176 229
177 .port_start = pdc_port_start, 230 .port_start = pdc_port_start,
178 .port_stop = pdc_port_stop,
179 .host_stop = pdc_host_stop,
180}; 231};
181 232
182static const struct ata_port_info pdc_port_info[] = { 233static const struct ata_port_info pdc_port_info[] = {
183 /* board_2037x */ 234 /* board_2037x */
184 { 235 {
185 .sht = &pdc_ata_sht, 236 .sht = &pdc_ata_sht,
186 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 237 .flags = PDC_COMMON_FLAGS,
187 .pio_mask = 0x1f, /* pio0-4 */ 238 .pio_mask = 0x1f, /* pio0-4 */
188 .mwdma_mask = 0x07, /* mwdma0-2 */ 239 .mwdma_mask = 0x07, /* mwdma0-2 */
189 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 240 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
190 .port_ops = &pdc_sata_ops, 241 .port_ops = &pdc_old_sata_ops,
191 }, 242 },
192 243
193 /* board_20319 */ 244 /* board_20319 */
@@ -197,7 +248,7 @@ static const struct ata_port_info pdc_port_info[] = {
197 .pio_mask = 0x1f, /* pio0-4 */ 248 .pio_mask = 0x1f, /* pio0-4 */
198 .mwdma_mask = 0x07, /* mwdma0-2 */ 249 .mwdma_mask = 0x07, /* mwdma0-2 */
199 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 250 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
200 .port_ops = &pdc_sata_ops, 251 .port_ops = &pdc_old_sata_ops,
201 }, 252 },
202 253
203 /* board_20619 */ 254 /* board_20619 */
@@ -213,7 +264,7 @@ static const struct ata_port_info pdc_port_info[] = {
213 /* board_2057x */ 264 /* board_2057x */
214 { 265 {
215 .sht = &pdc_ata_sht, 266 .sht = &pdc_ata_sht,
216 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 267 .flags = PDC_COMMON_FLAGS,
217 .pio_mask = 0x1f, /* pio0-4 */ 268 .pio_mask = 0x1f, /* pio0-4 */
218 .mwdma_mask = 0x07, /* mwdma0-2 */ 269 .mwdma_mask = 0x07, /* mwdma0-2 */
219 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 270 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -271,21 +322,22 @@ static int pdc_port_start(struct ata_port *ap)
271 struct pdc_port_priv *pp; 322 struct pdc_port_priv *pp;
272 int rc; 323 int rc;
273 324
325 /* fix up port flags and cable type for SATA+PATA chips */
326 ap->flags |= hp->port_flags[ap->port_no];
327 if (ap->flags & ATA_FLAG_SATA)
328 ap->cbl = ATA_CBL_SATA;
329
274 rc = ata_port_start(ap); 330 rc = ata_port_start(ap);
275 if (rc) 331 if (rc)
276 return rc; 332 return rc;
277 333
278 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 334 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
279 if (!pp) { 335 if (!pp)
280 rc = -ENOMEM; 336 return -ENOMEM;
281 goto err_out;
282 }
283 337
284 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); 338 pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
285 if (!pp->pkt) { 339 if (!pp->pkt)
286 rc = -ENOMEM; 340 return -ENOMEM;
287 goto err_out_kfree;
288 }
289 341
290 ap->private_data = pp; 342 ap->private_data = pp;
291 343
@@ -300,40 +352,11 @@ static int pdc_port_start(struct ata_port *ap)
300 } 352 }
301 353
302 return 0; 354 return 0;
303
304err_out_kfree:
305 kfree(pp);
306err_out:
307 ata_port_stop(ap);
308 return rc;
309}
310
311
312static void pdc_port_stop(struct ata_port *ap)
313{
314 struct device *dev = ap->host->dev;
315 struct pdc_port_priv *pp = ap->private_data;
316
317 ap->private_data = NULL;
318 dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
319 kfree(pp);
320 ata_port_stop(ap);
321} 355}
322 356
323
324static void pdc_host_stop(struct ata_host *host)
325{
326 struct pdc_host_priv *hp = host->private_data;
327
328 ata_pci_host_stop(host);
329
330 kfree(hp);
331}
332
333
334static void pdc_reset_port(struct ata_port *ap) 357static void pdc_reset_port(struct ata_port *ap)
335{ 358{
336 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; 359 void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
337 unsigned int i; 360 unsigned int i;
338 u32 tmp; 361 u32 tmp;
339 362
@@ -377,18 +400,102 @@ static void pdc_pata_phy_reset(struct ata_port *ap)
377 400
378static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 401static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
379{ 402{
380 if (sc_reg > SCR_CONTROL) 403 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA)
381 return 0xffffffffU; 404 return 0xffffffffU;
382 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 405 return readl(ap->ioaddr.scr_addr + (sc_reg * 4));
383} 406}
384 407
385 408
386static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 409static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
387 u32 val) 410 u32 val)
388{ 411{
389 if (sc_reg > SCR_CONTROL) 412 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA)
390 return; 413 return;
391 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 414 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
415}
416
417static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
418{
419 struct ata_port *ap = qc->ap;
420 dma_addr_t sg_table = ap->prd_dma;
421 unsigned int cdb_len = qc->dev->cdb_len;
422 u8 *cdb = qc->cdb;
423 struct pdc_port_priv *pp = ap->private_data;
424 u8 *buf = pp->pkt;
425 u32 *buf32 = (u32 *) buf;
426 unsigned int dev_sel, feature, nbytes;
427
428 /* set control bits (byte 0), zero delay seq id (byte 3),
429 * and seq id (byte 2)
430 */
431 switch (qc->tf.protocol) {
432 case ATA_PROT_ATAPI_DMA:
433 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
434 buf32[0] = cpu_to_le32(PDC_PKT_READ);
435 else
436 buf32[0] = 0;
437 break;
438 case ATA_PROT_ATAPI_NODATA:
439 buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
440 break;
441 default:
442 BUG();
443 break;
444 }
445 buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
446 buf32[2] = 0; /* no next-packet */
447
448 /* select drive */
449 if (sata_scr_valid(ap)) {
450 dev_sel = PDC_DEVICE_SATA;
451 } else {
452 dev_sel = ATA_DEVICE_OBS;
453 if (qc->dev->devno != 0)
454 dev_sel |= ATA_DEV1;
455 }
456 buf[12] = (1 << 5) | ATA_REG_DEVICE;
457 buf[13] = dev_sel;
458 buf[14] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_CLEAR_BSY;
459 buf[15] = dev_sel; /* once more, waiting for BSY to clear */
460
461 buf[16] = (1 << 5) | ATA_REG_NSECT;
462 buf[17] = 0x00;
463 buf[18] = (1 << 5) | ATA_REG_LBAL;
464 buf[19] = 0x00;
465
466 /* set feature and byte counter registers */
467 if (qc->tf.protocol != ATA_PROT_ATAPI_DMA) {
468 feature = PDC_FEATURE_ATAPI_PIO;
469 /* set byte counter register to real transfer byte count */
470 nbytes = qc->nbytes;
471 if (nbytes > 0xffff)
472 nbytes = 0xffff;
473 } else {
474 feature = PDC_FEATURE_ATAPI_DMA;
475 /* set byte counter register to 0 */
476 nbytes = 0;
477 }
478 buf[20] = (1 << 5) | ATA_REG_FEATURE;
479 buf[21] = feature;
480 buf[22] = (1 << 5) | ATA_REG_BYTEL;
481 buf[23] = nbytes & 0xFF;
482 buf[24] = (1 << 5) | ATA_REG_BYTEH;
483 buf[25] = (nbytes >> 8) & 0xFF;
484
485 /* send ATAPI packet command 0xA0 */
486 buf[26] = (1 << 5) | ATA_REG_CMD;
487 buf[27] = ATA_CMD_PACKET;
488
489 /* select drive and check DRQ */
490 buf[28] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_WAIT_DRDY;
491 buf[29] = dev_sel;
492
493 /* we can represent cdb lengths 2/4/6/8/10/12/14/16 */
494 BUG_ON(cdb_len & ~0x1E);
495
496 /* append the CDB as the final part */
497 buf[30] = (((cdb_len >> 1) & 7) << 5) | ATA_REG_DATA | PDC_LAST_REG;
498 memcpy(buf+31, cdb, cdb_len);
392} 499}
393 500
394static void pdc_qc_prep(struct ata_queued_cmd *qc) 501static void pdc_qc_prep(struct ata_queued_cmd *qc)
@@ -415,6 +522,17 @@ static void pdc_qc_prep(struct ata_queued_cmd *qc)
415 pdc_pkt_footer(&qc->tf, pp->pkt, i); 522 pdc_pkt_footer(&qc->tf, pp->pkt, i);
416 break; 523 break;
417 524
525 case ATA_PROT_ATAPI:
526 ata_qc_prep(qc);
527 break;
528
529 case ATA_PROT_ATAPI_DMA:
530 ata_qc_prep(qc);
531 /*FALLTHROUGH*/
532 case ATA_PROT_ATAPI_NODATA:
533 pdc_atapi_pkt(qc);
534 break;
535
418 default: 536 default:
419 break; 537 break;
420 } 538 }
@@ -517,7 +635,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
517{ 635{
518 unsigned int handled = 0; 636 unsigned int handled = 0;
519 u32 tmp; 637 u32 tmp;
520 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 638 void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
521 639
522 tmp = readl(mmio); 640 tmp = readl(mmio);
523 if (tmp & PDC_ERR_MASK) { 641 if (tmp & PDC_ERR_MASK) {
@@ -528,6 +646,8 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
528 switch (qc->tf.protocol) { 646 switch (qc->tf.protocol) {
529 case ATA_PROT_DMA: 647 case ATA_PROT_DMA:
530 case ATA_PROT_NODATA: 648 case ATA_PROT_NODATA:
649 case ATA_PROT_ATAPI_DMA:
650 case ATA_PROT_ATAPI_NODATA:
531 qc->err_mask |= ac_err_mask(ata_wait_idle(ap)); 651 qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
532 ata_qc_complete(qc); 652 ata_qc_complete(qc);
533 handled = 1; 653 handled = 1;
@@ -544,7 +664,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
544static void pdc_irq_clear(struct ata_port *ap) 664static void pdc_irq_clear(struct ata_port *ap)
545{ 665{
546 struct ata_host *host = ap->host; 666 struct ata_host *host = ap->host;
547 void __iomem *mmio = host->mmio_base; 667 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
548 668
549 readl(mmio + PDC_INT_SEQMASK); 669 readl(mmio + PDC_INT_SEQMASK);
550} 670}
@@ -560,12 +680,12 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
560 680
561 VPRINTK("ENTER\n"); 681 VPRINTK("ENTER\n");
562 682
563 if (!host || !host->mmio_base) { 683 if (!host || !host->iomap[PDC_MMIO_BAR]) {
564 VPRINTK("QUICK EXIT\n"); 684 VPRINTK("QUICK EXIT\n");
565 return IRQ_NONE; 685 return IRQ_NONE;
566 } 686 }
567 687
568 mmio_base = host->mmio_base; 688 mmio_base = host->iomap[PDC_MMIO_BAR];
569 689
570 /* reading should also clear interrupts */ 690 /* reading should also clear interrupts */
571 mask = readl(mmio_base + PDC_INT_SEQMASK); 691 mask = readl(mmio_base + PDC_INT_SEQMASK);
@@ -610,32 +730,34 @@ static inline void pdc_packet_start(struct ata_queued_cmd *qc)
610{ 730{
611 struct ata_port *ap = qc->ap; 731 struct ata_port *ap = qc->ap;
612 struct pdc_port_priv *pp = ap->private_data; 732 struct pdc_port_priv *pp = ap->private_data;
733 void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
613 unsigned int port_no = ap->port_no; 734 unsigned int port_no = ap->port_no;
614 u8 seq = (u8) (port_no + 1); 735 u8 seq = (u8) (port_no + 1);
615 736
616 VPRINTK("ENTER, ap %p\n", ap); 737 VPRINTK("ENTER, ap %p\n", ap);
617 738
618 writel(0x00000001, ap->host->mmio_base + (seq * 4)); 739 writel(0x00000001, mmio + (seq * 4));
619 readl(ap->host->mmio_base + (seq * 4)); /* flush */ 740 readl(mmio + (seq * 4)); /* flush */
620 741
621 pp->pkt[2] = seq; 742 pp->pkt[2] = seq;
622 wmb(); /* flush PRD, pkt writes */ 743 wmb(); /* flush PRD, pkt writes */
623 writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 744 writel(pp->pkt_dma, ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
624 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ 745 readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
625} 746}
626 747
627static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) 748static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
628{ 749{
629 switch (qc->tf.protocol) { 750 switch (qc->tf.protocol) {
751 case ATA_PROT_ATAPI_NODATA:
752 if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
753 break;
754 /*FALLTHROUGH*/
755 case ATA_PROT_ATAPI_DMA:
630 case ATA_PROT_DMA: 756 case ATA_PROT_DMA:
631 case ATA_PROT_NODATA: 757 case ATA_PROT_NODATA:
632 pdc_packet_start(qc); 758 pdc_packet_start(qc);
633 return 0; 759 return 0;
634 760
635 case ATA_PROT_ATAPI_DMA:
636 BUG();
637 break;
638
639 default: 761 default:
640 break; 762 break;
641 } 763 }
@@ -658,8 +780,44 @@ static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile
658 ata_exec_command(ap, tf); 780 ata_exec_command(ap, tf);
659} 781}
660 782
783static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
784{
785 u8 *scsicmd = qc->scsicmd->cmnd;
786 int pio = 1; /* atapi dma off by default */
787
788 /* Whitelist commands that may use DMA. */
789 switch (scsicmd[0]) {
790 case WRITE_12:
791 case WRITE_10:
792 case WRITE_6:
793 case READ_12:
794 case READ_10:
795 case READ_6:
796 case 0xad: /* READ_DVD_STRUCTURE */
797 case 0xbe: /* READ_CD */
798 pio = 0;
799 }
800 /* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
801 if (scsicmd[0] == WRITE_10) {
802 unsigned int lba;
803 lba = (scsicmd[2] << 24) | (scsicmd[3] << 16) | (scsicmd[4] << 8) | scsicmd[5];
804 if (lba >= 0xFFFF4FA2)
805 pio = 1;
806 }
807 return pio;
808}
661 809
662static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base) 810static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc)
811{
812 struct ata_port *ap = qc->ap;
813
814 /* First generation chips cannot use ATAPI DMA on SATA ports */
815 if (sata_scr_valid(ap))
816 return 1;
817 return pdc_check_atapi_dma(qc);
818}
819
820static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
663{ 821{
664 port->cmd_addr = base; 822 port->cmd_addr = base;
665 port->data_addr = base; 823 port->data_addr = base;
@@ -679,7 +837,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
679 837
680static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 838static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
681{ 839{
682 void __iomem *mmio = pe->mmio_base; 840 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
683 struct pdc_host_priv *hp = pe->private_data; 841 struct pdc_host_priv *hp = pe->private_data;
684 int hotplug_offset; 842 int hotplug_offset;
685 u32 tmp; 843 u32 tmp;
@@ -733,55 +891,43 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
733static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 891static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
734{ 892{
735 static int printed_version; 893 static int printed_version;
736 struct ata_probe_ent *probe_ent = NULL; 894 struct ata_probe_ent *probe_ent;
737 struct pdc_host_priv *hp; 895 struct pdc_host_priv *hp;
738 unsigned long base; 896 void __iomem *base;
739 void __iomem *mmio_base;
740 unsigned int board_idx = (unsigned int) ent->driver_data; 897 unsigned int board_idx = (unsigned int) ent->driver_data;
741 int pci_dev_busy = 0;
742 int rc; 898 int rc;
899 u8 tmp;
743 900
744 if (!printed_version++) 901 if (!printed_version++)
745 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 902 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
746 903
747 rc = pci_enable_device(pdev); 904 rc = pcim_enable_device(pdev);
748 if (rc) 905 if (rc)
749 return rc; 906 return rc;
750 907
751 rc = pci_request_regions(pdev, DRV_NAME); 908 rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
752 if (rc) { 909 if (rc == -EBUSY)
753 pci_dev_busy = 1; 910 pcim_pin_device(pdev);
754 goto err_out; 911 if (rc)
755 } 912 return rc;
756 913
757 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 914 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
758 if (rc) 915 if (rc)
759 goto err_out_regions; 916 return rc;
760 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 917 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
761 if (rc) 918 if (rc)
762 goto err_out_regions; 919 return rc;
763 920
764 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 921 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
765 if (probe_ent == NULL) { 922 if (probe_ent == NULL)
766 rc = -ENOMEM; 923 return -ENOMEM;
767 goto err_out_regions;
768 }
769 924
770 probe_ent->dev = pci_dev_to_dev(pdev); 925 probe_ent->dev = pci_dev_to_dev(pdev);
771 INIT_LIST_HEAD(&probe_ent->node); 926 INIT_LIST_HEAD(&probe_ent->node);
772 927
773 mmio_base = pci_iomap(pdev, 3, 0); 928 hp = devm_kzalloc(&pdev->dev, sizeof(*hp), GFP_KERNEL);
774 if (mmio_base == NULL) { 929 if (hp == NULL)
775 rc = -ENOMEM; 930 return -ENOMEM;
776 goto err_out_free_ent;
777 }
778 base = (unsigned long) mmio_base;
779
780 hp = kzalloc(sizeof(*hp), GFP_KERNEL);
781 if (hp == NULL) {
782 rc = -ENOMEM;
783 goto err_out_free_ent;
784 }
785 931
786 probe_ent->private_data = hp; 932 probe_ent->private_data = hp;
787 933
@@ -794,7 +940,9 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
794 940
795 probe_ent->irq = pdev->irq; 941 probe_ent->irq = pdev->irq;
796 probe_ent->irq_flags = IRQF_SHARED; 942 probe_ent->irq_flags = IRQF_SHARED;
797 probe_ent->mmio_base = mmio_base; 943 probe_ent->iomap = pcim_iomap_table(pdev);
944
945 base = probe_ent->iomap[PDC_MMIO_BAR];
798 946
799 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200); 947 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
800 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280); 948 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
@@ -820,7 +968,17 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
820 hp->flags |= PDC_FLAG_GEN_II; 968 hp->flags |= PDC_FLAG_GEN_II;
821 /* Fall through */ 969 /* Fall through */
822 case board_2037x: 970 case board_2037x:
823 probe_ent->n_ports = 2; 971 /* TX2plus boards also have a PATA port */
972 tmp = readb(base + PDC_FLASH_CTL+1);
973 if (!(tmp & 0x80)) {
974 probe_ent->n_ports = 3;
975 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
976 hp->port_flags[2] = ATA_FLAG_SLAVE_POSS;
977 printk(KERN_INFO DRV_NAME " PATA port found\n");
978 } else
979 probe_ent->n_ports = 2;
980 hp->port_flags[0] = ATA_FLAG_SATA;
981 hp->port_flags[1] = ATA_FLAG_SATA;
824 break; 982 break;
825 case board_20619: 983 case board_20619:
826 probe_ent->n_ports = 4; 984 probe_ent->n_ports = 4;
@@ -841,22 +999,11 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
841 /* initialize adapter */ 999 /* initialize adapter */
842 pdc_host_init(board_idx, probe_ent); 1000 pdc_host_init(board_idx, probe_ent);
843 1001
844 /* FIXME: Need any other frees than hp? */
845 if (!ata_device_add(probe_ent)) 1002 if (!ata_device_add(probe_ent))
846 kfree(hp); 1003 return -ENODEV;
847
848 kfree(probe_ent);
849 1004
1005 devm_kfree(&pdev->dev, probe_ent);
850 return 0; 1006 return 0;
851
852err_out_free_ent:
853 kfree(probe_ent);
854err_out_regions:
855 pci_release_regions(pdev);
856err_out:
857 if (!pci_dev_busy)
858 pci_disable_device(pdev);
859 return rc;
860} 1007}
861 1008
862 1009