aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/ahci.c659
-rw-r--r--drivers/scsi/ata_piix.c18
-rw-r--r--drivers/scsi/libata-bmdma.c160
-rw-r--r--drivers/scsi/libata-core.c299
-rw-r--r--drivers/scsi/libata-scsi.c157
-rw-r--r--drivers/scsi/libata.h5
-rw-r--r--drivers/scsi/sata_sil.c4
7 files changed, 852 insertions, 450 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 904c25fb4ba4..68fd7667a082 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -92,7 +92,9 @@ enum {
92 HOST_AHCI_EN = (1 << 31), /* AHCI enabled */ 92 HOST_AHCI_EN = (1 << 31), /* AHCI enabled */
93 93
94 /* HOST_CAP bits */ 94 /* HOST_CAP bits */
95 HOST_CAP_SSC = (1 << 14), /* Slumber capable */
95 HOST_CAP_CLO = (1 << 24), /* Command List Override support */ 96 HOST_CAP_CLO = (1 << 24), /* Command List Override support */
97 HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */
96 HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */ 98 HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */
97 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ 99 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */
98 100
@@ -155,6 +157,7 @@ enum {
155 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ 157 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */
156 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ 158 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */
157 159
160 PORT_CMD_ICC_MASK = (0xf << 28), /* i/f ICC state mask */
158 PORT_CMD_ICC_ACTIVE = (0x1 << 28), /* Put i/f in active state */ 161 PORT_CMD_ICC_ACTIVE = (0x1 << 28), /* Put i/f in active state */
159 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */ 162 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */
160 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */ 163 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */
@@ -212,6 +215,10 @@ static void ahci_freeze(struct ata_port *ap);
212static void ahci_thaw(struct ata_port *ap); 215static void ahci_thaw(struct ata_port *ap);
213static void ahci_error_handler(struct ata_port *ap); 216static void ahci_error_handler(struct ata_port *ap);
214static void ahci_post_internal_cmd(struct ata_queued_cmd *qc); 217static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
218static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
219static int ahci_port_resume(struct ata_port *ap);
220static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
221static int ahci_pci_device_resume(struct pci_dev *pdev);
215static void ahci_remove_one (struct pci_dev *pdev); 222static void ahci_remove_one (struct pci_dev *pdev);
216 223
217static struct scsi_host_template ahci_sht = { 224static struct scsi_host_template ahci_sht = {
@@ -231,6 +238,8 @@ static struct scsi_host_template ahci_sht = {
231 .slave_configure = ata_scsi_slave_config, 238 .slave_configure = ata_scsi_slave_config,
232 .slave_destroy = ata_scsi_slave_destroy, 239 .slave_destroy = ata_scsi_slave_destroy,
233 .bios_param = ata_std_bios_param, 240 .bios_param = ata_std_bios_param,
241 .suspend = ata_scsi_device_suspend,
242 .resume = ata_scsi_device_resume,
234}; 243};
235 244
236static const struct ata_port_operations ahci_ops = { 245static const struct ata_port_operations ahci_ops = {
@@ -257,6 +266,9 @@ static const struct ata_port_operations ahci_ops = {
257 .error_handler = ahci_error_handler, 266 .error_handler = ahci_error_handler,
258 .post_internal_cmd = ahci_post_internal_cmd, 267 .post_internal_cmd = ahci_post_internal_cmd,
259 268
269 .port_suspend = ahci_port_suspend,
270 .port_resume = ahci_port_resume,
271
260 .port_start = ahci_port_start, 272 .port_start = ahci_port_start,
261 .port_stop = ahci_port_stop, 273 .port_stop = ahci_port_stop,
262}; 274};
@@ -350,6 +362,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
350 { PCI_VENDOR_ID_NVIDIA, 0x044f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 362 { PCI_VENDOR_ID_NVIDIA, 0x044f, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
351 board_ahci }, /* MCP65 */ 363 board_ahci }, /* MCP65 */
352 364
365 /* SiS */
366 { PCI_VENDOR_ID_SI, 0x1184, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
367 board_ahci }, /* SiS 966 */
368 { PCI_VENDOR_ID_SI, 0x1185, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
369 board_ahci }, /* SiS 966 */
370 { PCI_VENDOR_ID_SI, 0x0186, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
371 board_ahci }, /* SiS 968 */
372
353 { } /* terminate list */ 373 { } /* terminate list */
354}; 374};
355 375
@@ -358,6 +378,8 @@ static struct pci_driver ahci_pci_driver = {
358 .name = DRV_NAME, 378 .name = DRV_NAME,
359 .id_table = ahci_pci_tbl, 379 .id_table = ahci_pci_tbl,
360 .probe = ahci_init_one, 380 .probe = ahci_init_one,
381 .suspend = ahci_pci_device_suspend,
382 .resume = ahci_pci_device_resume,
361 .remove = ahci_remove_one, 383 .remove = ahci_remove_one,
362}; 384};
363 385
@@ -372,177 +394,288 @@ static inline void __iomem *ahci_port_base (void __iomem *base, unsigned int por
372 return (void __iomem *) ahci_port_base_ul((unsigned long)base, port); 394 return (void __iomem *) ahci_port_base_ul((unsigned long)base, port);
373} 395}
374 396
375static int ahci_port_start(struct ata_port *ap) 397static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
376{ 398{
377 struct device *dev = ap->host_set->dev; 399 unsigned int sc_reg;
378 struct ahci_host_priv *hpriv = ap->host_set->private_data;
379 struct ahci_port_priv *pp;
380 void __iomem *mmio = ap->host_set->mmio_base;
381 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
382 void *mem;
383 dma_addr_t mem_dma;
384 int rc;
385
386 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
387 if (!pp)
388 return -ENOMEM;
389 memset(pp, 0, sizeof(*pp));
390 400
391 rc = ata_pad_alloc(ap, dev); 401 switch (sc_reg_in) {
392 if (rc) { 402 case SCR_STATUS: sc_reg = 0; break;
393 kfree(pp); 403 case SCR_CONTROL: sc_reg = 1; break;
394 return rc; 404 case SCR_ERROR: sc_reg = 2; break;
405 case SCR_ACTIVE: sc_reg = 3; break;
406 default:
407 return 0xffffffffU;
395 } 408 }
396 409
397 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 410 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
398 if (!mem) { 411}
399 ata_pad_free(ap, dev);
400 kfree(pp);
401 return -ENOMEM;
402 }
403 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
404 412
405 /*
406 * First item in chunk of DMA memory: 32-slot command table,
407 * 32 bytes each in size
408 */
409 pp->cmd_slot = mem;
410 pp->cmd_slot_dma = mem_dma;
411 413
412 mem += AHCI_CMD_SLOT_SZ; 414static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
413 mem_dma += AHCI_CMD_SLOT_SZ; 415 u32 val)
416{
417 unsigned int sc_reg;
414 418
415 /* 419 switch (sc_reg_in) {
416 * Second item: Received-FIS area 420 case SCR_STATUS: sc_reg = 0; break;
417 */ 421 case SCR_CONTROL: sc_reg = 1; break;
418 pp->rx_fis = mem; 422 case SCR_ERROR: sc_reg = 2; break;
419 pp->rx_fis_dma = mem_dma; 423 case SCR_ACTIVE: sc_reg = 3; break;
424 default:
425 return;
426 }
420 427
421 mem += AHCI_RX_FIS_SZ; 428 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
422 mem_dma += AHCI_RX_FIS_SZ; 429}
423 430
424 /* 431static void ahci_start_engine(void __iomem *port_mmio)
425 * Third item: data area for storing a single command 432{
426 * and its scatter-gather table 433 u32 tmp;
427 */
428 pp->cmd_tbl = mem;
429 pp->cmd_tbl_dma = mem_dma;
430 434
431 ap->private_data = pp; 435 /* start DMA */
436 tmp = readl(port_mmio + PORT_CMD);
437 tmp |= PORT_CMD_START;
438 writel(tmp, port_mmio + PORT_CMD);
439 readl(port_mmio + PORT_CMD); /* flush */
440}
432 441
433 if (hpriv->cap & HOST_CAP_64) 442static int ahci_stop_engine(void __iomem *port_mmio)
434 writel((pp->cmd_slot_dma >> 16) >> 16, port_mmio + PORT_LST_ADDR_HI); 443{
435 writel(pp->cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR); 444 u32 tmp;
436 readl(port_mmio + PORT_LST_ADDR); /* flush */
437 445
438 if (hpriv->cap & HOST_CAP_64) 446 tmp = readl(port_mmio + PORT_CMD);
439 writel((pp->rx_fis_dma >> 16) >> 16, port_mmio + PORT_FIS_ADDR_HI);
440 writel(pp->rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
441 readl(port_mmio + PORT_FIS_ADDR); /* flush */
442 447
443 writel(PORT_CMD_ICC_ACTIVE | PORT_CMD_FIS_RX | 448 /* check if the HBA is idle */
444 PORT_CMD_POWER_ON | PORT_CMD_SPIN_UP | 449 if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0)
445 PORT_CMD_START, port_mmio + PORT_CMD); 450 return 0;
446 readl(port_mmio + PORT_CMD); /* flush */ 451
452 /* setting HBA to idle */
453 tmp &= ~PORT_CMD_START;
454 writel(tmp, port_mmio + PORT_CMD);
455
456 /* wait for engine to stop. This could be as long as 500 msec */
457 tmp = ata_wait_register(port_mmio + PORT_CMD,
458 PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
459 if (tmp & PORT_CMD_LIST_ON)
460 return -EIO;
447 461
448 return 0; 462 return 0;
449} 463}
450 464
465static void ahci_start_fis_rx(void __iomem *port_mmio, u32 cap,
466 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma)
467{
468 u32 tmp;
469
470 /* set FIS registers */
471 if (cap & HOST_CAP_64)
472 writel((cmd_slot_dma >> 16) >> 16, port_mmio + PORT_LST_ADDR_HI);
473 writel(cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR);
451 474
452static void ahci_port_stop(struct ata_port *ap) 475 if (cap & HOST_CAP_64)
476 writel((rx_fis_dma >> 16) >> 16, port_mmio + PORT_FIS_ADDR_HI);
477 writel(rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
478
479 /* enable FIS reception */
480 tmp = readl(port_mmio + PORT_CMD);
481 tmp |= PORT_CMD_FIS_RX;
482 writel(tmp, port_mmio + PORT_CMD);
483
484 /* flush */
485 readl(port_mmio + PORT_CMD);
486}
487
488static int ahci_stop_fis_rx(void __iomem *port_mmio)
453{ 489{
454 struct device *dev = ap->host_set->dev;
455 struct ahci_port_priv *pp = ap->private_data;
456 void __iomem *mmio = ap->host_set->mmio_base;
457 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
458 u32 tmp; 490 u32 tmp;
459 491
492 /* disable FIS reception */
460 tmp = readl(port_mmio + PORT_CMD); 493 tmp = readl(port_mmio + PORT_CMD);
461 tmp &= ~(PORT_CMD_START | PORT_CMD_FIS_RX); 494 tmp &= ~PORT_CMD_FIS_RX;
462 writel(tmp, port_mmio + PORT_CMD); 495 writel(tmp, port_mmio + PORT_CMD);
463 readl(port_mmio + PORT_CMD); /* flush */
464 496
465 /* spec says 500 msecs for each PORT_CMD_{START,FIS_RX} bit, so 497 /* wait for completion, spec says 500ms, give it 1000 */
466 * this is slightly incorrect. 498 tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
467 */ 499 PORT_CMD_FIS_ON, 10, 1000);
468 msleep(500); 500 if (tmp & PORT_CMD_FIS_ON)
501 return -EBUSY;
469 502
470 ap->private_data = NULL; 503 return 0;
471 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
472 pp->cmd_slot, pp->cmd_slot_dma);
473 ata_pad_free(ap, dev);
474 kfree(pp);
475} 504}
476 505
477static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 506static void ahci_power_up(void __iomem *port_mmio, u32 cap)
478{ 507{
479 unsigned int sc_reg; 508 u32 cmd;
480 509
481 switch (sc_reg_in) { 510 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
482 case SCR_STATUS: sc_reg = 0; break; 511
483 case SCR_CONTROL: sc_reg = 1; break; 512 /* spin up device */
484 case SCR_ERROR: sc_reg = 2; break; 513 if (cap & HOST_CAP_SSS) {
485 case SCR_ACTIVE: sc_reg = 3; break; 514 cmd |= PORT_CMD_SPIN_UP;
486 default: 515 writel(cmd, port_mmio + PORT_CMD);
487 return 0xffffffffU;
488 } 516 }
489 517
490 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 518 /* wake up link */
519 writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD);
491} 520}
492 521
522static void ahci_power_down(void __iomem *port_mmio, u32 cap)
523{
524 u32 cmd, scontrol;
493 525
494static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in, 526 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
495 u32 val) 527
528 if (cap & HOST_CAP_SSC) {
529 /* enable transitions to slumber mode */
530 scontrol = readl(port_mmio + PORT_SCR_CTL);
531 if ((scontrol & 0x0f00) > 0x100) {
532 scontrol &= ~0xf00;
533 writel(scontrol, port_mmio + PORT_SCR_CTL);
534 }
535
536 /* put device into slumber mode */
537 writel(cmd | PORT_CMD_ICC_SLUMBER, port_mmio + PORT_CMD);
538
539 /* wait for the transition to complete */
540 ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_ICC_SLUMBER,
541 PORT_CMD_ICC_SLUMBER, 1, 50);
542 }
543
544 /* put device into listen mode */
545 if (cap & HOST_CAP_SSS) {
546 /* first set PxSCTL.DET to 0 */
547 scontrol = readl(port_mmio + PORT_SCR_CTL);
548 scontrol &= ~0xf;
549 writel(scontrol, port_mmio + PORT_SCR_CTL);
550
551 /* then set PxCMD.SUD to 0 */
552 cmd &= ~PORT_CMD_SPIN_UP;
553 writel(cmd, port_mmio + PORT_CMD);
554 }
555}
556
557static void ahci_init_port(void __iomem *port_mmio, u32 cap,
558 dma_addr_t cmd_slot_dma, dma_addr_t rx_fis_dma)
496{ 559{
497 unsigned int sc_reg; 560 /* power up */
561 ahci_power_up(port_mmio, cap);
498 562
499 switch (sc_reg_in) { 563 /* enable FIS reception */
500 case SCR_STATUS: sc_reg = 0; break; 564 ahci_start_fis_rx(port_mmio, cap, cmd_slot_dma, rx_fis_dma);
501 case SCR_CONTROL: sc_reg = 1; break; 565
502 case SCR_ERROR: sc_reg = 2; break; 566 /* enable DMA */
503 case SCR_ACTIVE: sc_reg = 3; break; 567 ahci_start_engine(port_mmio);
504 default: 568}
505 return; 569
570static int ahci_deinit_port(void __iomem *port_mmio, u32 cap, const char **emsg)
571{
572 int rc;
573
574 /* disable DMA */
575 rc = ahci_stop_engine(port_mmio);
576 if (rc) {
577 *emsg = "failed to stop engine";
578 return rc;
506 } 579 }
507 580
508 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 581 /* disable FIS reception */
582 rc = ahci_stop_fis_rx(port_mmio);
583 if (rc) {
584 *emsg = "failed stop FIS RX";
585 return rc;
586 }
587
588 /* put device into slumber mode */
589 ahci_power_down(port_mmio, cap);
590
591 return 0;
509} 592}
510 593
511static int ahci_stop_engine(struct ata_port *ap) 594static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
512{ 595{
513 void __iomem *mmio = ap->host_set->mmio_base; 596 u32 cap_save, tmp;
514 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
515 int work;
516 u32 tmp;
517 597
518 tmp = readl(port_mmio + PORT_CMD); 598 cap_save = readl(mmio + HOST_CAP);
519 tmp &= ~PORT_CMD_START; 599 cap_save &= ( (1<<28) | (1<<17) );
520 writel(tmp, port_mmio + PORT_CMD); 600 cap_save |= (1 << 27);
521 601
522 /* wait for engine to stop. TODO: this could be 602 /* global controller reset */
523 * as long as 500 msec 603 tmp = readl(mmio + HOST_CTL);
604 if ((tmp & HOST_RESET) == 0) {
605 writel(tmp | HOST_RESET, mmio + HOST_CTL);
606 readl(mmio + HOST_CTL); /* flush */
607 }
608
609 /* reset must complete within 1 second, or
610 * the hardware should be considered fried.
524 */ 611 */
525 work = 1000; 612 ssleep(1);
526 while (work-- > 0) { 613
527 tmp = readl(port_mmio + PORT_CMD); 614 tmp = readl(mmio + HOST_CTL);
528 if ((tmp & PORT_CMD_LIST_ON) == 0) 615 if (tmp & HOST_RESET) {
529 return 0; 616 dev_printk(KERN_ERR, &pdev->dev,
530 udelay(10); 617 "controller reset failed (0x%x)\n", tmp);
618 return -EIO;
531 } 619 }
532 620
533 return -EIO; 621 writel(HOST_AHCI_EN, mmio + HOST_CTL);
622 (void) readl(mmio + HOST_CTL); /* flush */
623 writel(cap_save, mmio + HOST_CAP);
624 writel(0xf, mmio + HOST_PORTS_IMPL);
625 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */
626
627 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
628 u16 tmp16;
629
630 /* configure PCS */
631 pci_read_config_word(pdev, 0x92, &tmp16);
632 tmp16 |= 0xf;
633 pci_write_config_word(pdev, 0x92, tmp16);
634 }
635
636 return 0;
534} 637}
535 638
536static void ahci_start_engine(struct ata_port *ap) 639static void ahci_init_controller(void __iomem *mmio, struct pci_dev *pdev,
640 int n_ports, u32 cap)
537{ 641{
538 void __iomem *mmio = ap->host_set->mmio_base; 642 int i, rc;
539 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
540 u32 tmp; 643 u32 tmp;
541 644
542 tmp = readl(port_mmio + PORT_CMD); 645 for (i = 0; i < n_ports; i++) {
543 tmp |= PORT_CMD_START; 646 void __iomem *port_mmio = ahci_port_base(mmio, i);
544 writel(tmp, port_mmio + PORT_CMD); 647 const char *emsg = NULL;
545 readl(port_mmio + PORT_CMD); /* flush */ 648
649#if 0 /* BIOSen initialize this incorrectly */
650 if (!(hpriv->port_map & (1 << i)))
651 continue;
652#endif
653
654 /* make sure port is not active */
655 rc = ahci_deinit_port(port_mmio, cap, &emsg);
656 if (rc)
657 dev_printk(KERN_WARNING, &pdev->dev,
658 "%s (%d)\n", emsg, rc);
659
660 /* clear SError */
661 tmp = readl(port_mmio + PORT_SCR_ERR);
662 VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
663 writel(tmp, port_mmio + PORT_SCR_ERR);
664
665 /* clear port IRQ */
666 tmp = readl(port_mmio + PORT_IRQ_STAT);
667 VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
668 if (tmp)
669 writel(tmp, port_mmio + PORT_IRQ_STAT);
670
671 writel(1 << i, mmio + HOST_IRQ_STAT);
672 }
673
674 tmp = readl(mmio + HOST_CTL);
675 VPRINTK("HOST_CTL 0x%x\n", tmp);
676 writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
677 tmp = readl(mmio + HOST_CTL);
678 VPRINTK("HOST_CTL 0x%x\n", tmp);
546} 679}
547 680
548static unsigned int ahci_dev_classify(struct ata_port *ap) 681static unsigned int ahci_dev_classify(struct ata_port *ap)
@@ -626,7 +759,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
626 } 759 }
627 760
628 /* prepare for SRST (AHCI-1.1 10.4.1) */ 761 /* prepare for SRST (AHCI-1.1 10.4.1) */
629 rc = ahci_stop_engine(ap); 762 rc = ahci_stop_engine(port_mmio);
630 if (rc) { 763 if (rc) {
631 reason = "failed to stop engine"; 764 reason = "failed to stop engine";
632 goto fail_restart; 765 goto fail_restart;
@@ -647,7 +780,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
647 } 780 }
648 781
649 /* restart engine */ 782 /* restart engine */
650 ahci_start_engine(ap); 783 ahci_start_engine(port_mmio);
651 784
652 ata_tf_init(ap->device, &tf); 785 ata_tf_init(ap->device, &tf);
653 fis = pp->cmd_tbl; 786 fis = pp->cmd_tbl;
@@ -706,7 +839,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
706 return 0; 839 return 0;
707 840
708 fail_restart: 841 fail_restart:
709 ahci_start_engine(ap); 842 ahci_start_engine(port_mmio);
710 fail: 843 fail:
711 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason); 844 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason);
712 return rc; 845 return rc;
@@ -717,11 +850,13 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
717 struct ahci_port_priv *pp = ap->private_data; 850 struct ahci_port_priv *pp = ap->private_data;
718 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 851 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
719 struct ata_taskfile tf; 852 struct ata_taskfile tf;
853 void __iomem *mmio = ap->host_set->mmio_base;
854 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
720 int rc; 855 int rc;
721 856
722 DPRINTK("ENTER\n"); 857 DPRINTK("ENTER\n");
723 858
724 ahci_stop_engine(ap); 859 ahci_stop_engine(port_mmio);
725 860
726 /* clear D2H reception area to properly wait for D2H FIS */ 861 /* clear D2H reception area to properly wait for D2H FIS */
727 ata_tf_init(ap->device, &tf); 862 ata_tf_init(ap->device, &tf);
@@ -730,7 +865,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
730 865
731 rc = sata_std_hardreset(ap, class); 866 rc = sata_std_hardreset(ap, class);
732 867
733 ahci_start_engine(ap); 868 ahci_start_engine(port_mmio);
734 869
735 if (rc == 0 && ata_port_online(ap)) 870 if (rc == 0 && ata_port_online(ap))
736 *class = ahci_dev_classify(ap); 871 *class = ahci_dev_classify(ap);
@@ -1046,10 +1181,13 @@ static void ahci_thaw(struct ata_port *ap)
1046 1181
1047static void ahci_error_handler(struct ata_port *ap) 1182static void ahci_error_handler(struct ata_port *ap)
1048{ 1183{
1184 void __iomem *mmio = ap->host_set->mmio_base;
1185 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1186
1049 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 1187 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
1050 /* restart engine */ 1188 /* restart engine */
1051 ahci_stop_engine(ap); 1189 ahci_stop_engine(port_mmio);
1052 ahci_start_engine(ap); 1190 ahci_start_engine(port_mmio);
1053 } 1191 }
1054 1192
1055 /* perform recovery */ 1193 /* perform recovery */
@@ -1060,15 +1198,176 @@ static void ahci_error_handler(struct ata_port *ap)
1060static void ahci_post_internal_cmd(struct ata_queued_cmd *qc) 1198static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
1061{ 1199{
1062 struct ata_port *ap = qc->ap; 1200 struct ata_port *ap = qc->ap;
1201 void __iomem *mmio = ap->host_set->mmio_base;
1202 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1063 1203
1064 if (qc->flags & ATA_QCFLAG_FAILED) 1204 if (qc->flags & ATA_QCFLAG_FAILED)
1065 qc->err_mask |= AC_ERR_OTHER; 1205 qc->err_mask |= AC_ERR_OTHER;
1066 1206
1067 if (qc->err_mask) { 1207 if (qc->err_mask) {
1068 /* make DMA engine forget about the failed command */ 1208 /* make DMA engine forget about the failed command */
1069 ahci_stop_engine(ap); 1209 ahci_stop_engine(port_mmio);
1070 ahci_start_engine(ap); 1210 ahci_start_engine(port_mmio);
1211 }
1212}
1213
1214static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1215{
1216 struct ahci_host_priv *hpriv = ap->host_set->private_data;
1217 struct ahci_port_priv *pp = ap->private_data;
1218 void __iomem *mmio = ap->host_set->mmio_base;
1219 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1220 const char *emsg = NULL;
1221 int rc;
1222
1223 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg);
1224 if (rc) {
1225 ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc);
1226 ahci_init_port(port_mmio, hpriv->cap,
1227 pp->cmd_slot_dma, pp->rx_fis_dma);
1071 } 1228 }
1229
1230 return rc;
1231}
1232
1233static int ahci_port_resume(struct ata_port *ap)
1234{
1235 struct ahci_port_priv *pp = ap->private_data;
1236 struct ahci_host_priv *hpriv = ap->host_set->private_data;
1237 void __iomem *mmio = ap->host_set->mmio_base;
1238 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1239
1240 ahci_init_port(port_mmio, hpriv->cap, pp->cmd_slot_dma, pp->rx_fis_dma);
1241
1242 return 0;
1243}
1244
1245static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
1246{
1247 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
1248 void __iomem *mmio = host_set->mmio_base;
1249 u32 ctl;
1250
1251 if (mesg.event == PM_EVENT_SUSPEND) {
1252 /* AHCI spec rev1.1 section 8.3.3:
1253 * Software must disable interrupts prior to requesting a
1254 * transition of the HBA to D3 state.
1255 */
1256 ctl = readl(mmio + HOST_CTL);
1257 ctl &= ~HOST_IRQ_EN;
1258 writel(ctl, mmio + HOST_CTL);
1259 readl(mmio + HOST_CTL); /* flush */
1260 }
1261
1262 return ata_pci_device_suspend(pdev, mesg);
1263}
1264
1265static int ahci_pci_device_resume(struct pci_dev *pdev)
1266{
1267 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
1268 struct ahci_host_priv *hpriv = host_set->private_data;
1269 void __iomem *mmio = host_set->mmio_base;
1270 int rc;
1271
1272 ata_pci_device_do_resume(pdev);
1273
1274 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
1275 rc = ahci_reset_controller(mmio, pdev);
1276 if (rc)
1277 return rc;
1278
1279 ahci_init_controller(mmio, pdev, host_set->n_ports, hpriv->cap);
1280 }
1281
1282 ata_host_set_resume(host_set);
1283
1284 return 0;
1285}
1286
1287static int ahci_port_start(struct ata_port *ap)
1288{
1289 struct device *dev = ap->host_set->dev;
1290 struct ahci_host_priv *hpriv = ap->host_set->private_data;
1291 struct ahci_port_priv *pp;
1292 void __iomem *mmio = ap->host_set->mmio_base;
1293 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1294 void *mem;
1295 dma_addr_t mem_dma;
1296 int rc;
1297
1298 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
1299 if (!pp)
1300 return -ENOMEM;
1301 memset(pp, 0, sizeof(*pp));
1302
1303 rc = ata_pad_alloc(ap, dev);
1304 if (rc) {
1305 kfree(pp);
1306 return rc;
1307 }
1308
1309 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL);
1310 if (!mem) {
1311 ata_pad_free(ap, dev);
1312 kfree(pp);
1313 return -ENOMEM;
1314 }
1315 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
1316
1317 /*
1318 * First item in chunk of DMA memory: 32-slot command table,
1319 * 32 bytes each in size
1320 */
1321 pp->cmd_slot = mem;
1322 pp->cmd_slot_dma = mem_dma;
1323
1324 mem += AHCI_CMD_SLOT_SZ;
1325 mem_dma += AHCI_CMD_SLOT_SZ;
1326
1327 /*
1328 * Second item: Received-FIS area
1329 */
1330 pp->rx_fis = mem;
1331 pp->rx_fis_dma = mem_dma;
1332
1333 mem += AHCI_RX_FIS_SZ;
1334 mem_dma += AHCI_RX_FIS_SZ;
1335
1336 /*
1337 * Third item: data area for storing a single command
1338 * and its scatter-gather table
1339 */
1340 pp->cmd_tbl = mem;
1341 pp->cmd_tbl_dma = mem_dma;
1342
1343 ap->private_data = pp;
1344
1345 /* initialize port */
1346 ahci_init_port(port_mmio, hpriv->cap, pp->cmd_slot_dma, pp->rx_fis_dma);
1347
1348 return 0;
1349}
1350
1351static void ahci_port_stop(struct ata_port *ap)
1352{
1353 struct device *dev = ap->host_set->dev;
1354 struct ahci_host_priv *hpriv = ap->host_set->private_data;
1355 struct ahci_port_priv *pp = ap->private_data;
1356 void __iomem *mmio = ap->host_set->mmio_base;
1357 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1358 const char *emsg = NULL;
1359 int rc;
1360
1361 /* de-initialize port */
1362 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg);
1363 if (rc)
1364 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
1365
1366 ap->private_data = NULL;
1367 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
1368 pp->cmd_slot, pp->cmd_slot_dma);
1369 ata_pad_free(ap, dev);
1370 kfree(pp);
1072} 1371}
1073 1372
1074static void ahci_setup_port(struct ata_ioports *port, unsigned long base, 1373static void ahci_setup_port(struct ata_ioports *port, unsigned long base,
@@ -1089,47 +1388,12 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
1089 struct ahci_host_priv *hpriv = probe_ent->private_data; 1388 struct ahci_host_priv *hpriv = probe_ent->private_data;
1090 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1389 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1091 void __iomem *mmio = probe_ent->mmio_base; 1390 void __iomem *mmio = probe_ent->mmio_base;
1092 u32 tmp, cap_save; 1391 unsigned int i, using_dac;
1093 unsigned int i, j, using_dac;
1094 int rc; 1392 int rc;
1095 void __iomem *port_mmio;
1096 1393
1097 cap_save = readl(mmio + HOST_CAP); 1394 rc = ahci_reset_controller(mmio, pdev);
1098 cap_save &= ( (1<<28) | (1<<17) ); 1395 if (rc)
1099 cap_save |= (1 << 27); 1396 return rc;
1100
1101 /* global controller reset */
1102 tmp = readl(mmio + HOST_CTL);
1103 if ((tmp & HOST_RESET) == 0) {
1104 writel(tmp | HOST_RESET, mmio + HOST_CTL);
1105 readl(mmio + HOST_CTL); /* flush */
1106 }
1107
1108 /* reset must complete within 1 second, or
1109 * the hardware should be considered fried.
1110 */
1111 ssleep(1);
1112
1113 tmp = readl(mmio + HOST_CTL);
1114 if (tmp & HOST_RESET) {
1115 dev_printk(KERN_ERR, &pdev->dev,
1116 "controller reset failed (0x%x)\n", tmp);
1117 return -EIO;
1118 }
1119
1120 writel(HOST_AHCI_EN, mmio + HOST_CTL);
1121 (void) readl(mmio + HOST_CTL); /* flush */
1122 writel(cap_save, mmio + HOST_CAP);
1123 writel(0xf, mmio + HOST_PORTS_IMPL);
1124 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */
1125
1126 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
1127 u16 tmp16;
1128
1129 pci_read_config_word(pdev, 0x92, &tmp16);
1130 tmp16 |= 0xf;
1131 pci_write_config_word(pdev, 0x92, tmp16);
1132 }
1133 1397
1134 hpriv->cap = readl(mmio + HOST_CAP); 1398 hpriv->cap = readl(mmio + HOST_CAP);
1135 hpriv->port_map = readl(mmio + HOST_PORTS_IMPL); 1399 hpriv->port_map = readl(mmio + HOST_PORTS_IMPL);
@@ -1165,63 +1429,10 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
1165 } 1429 }
1166 } 1430 }
1167 1431
1168 for (i = 0; i < probe_ent->n_ports; i++) { 1432 for (i = 0; i < probe_ent->n_ports; i++)
1169#if 0 /* BIOSen initialize this incorrectly */ 1433 ahci_setup_port(&probe_ent->port[i], (unsigned long) mmio, i);
1170 if (!(hpriv->port_map & (1 << i)))
1171 continue;
1172#endif
1173
1174 port_mmio = ahci_port_base(mmio, i);
1175 VPRINTK("mmio %p port_mmio %p\n", mmio, port_mmio);
1176
1177 ahci_setup_port(&probe_ent->port[i],
1178 (unsigned long) mmio, i);
1179
1180 /* make sure port is not active */
1181 tmp = readl(port_mmio + PORT_CMD);
1182 VPRINTK("PORT_CMD 0x%x\n", tmp);
1183 if (tmp & (PORT_CMD_LIST_ON | PORT_CMD_FIS_ON |
1184 PORT_CMD_FIS_RX | PORT_CMD_START)) {
1185 tmp &= ~(PORT_CMD_LIST_ON | PORT_CMD_FIS_ON |
1186 PORT_CMD_FIS_RX | PORT_CMD_START);
1187 writel(tmp, port_mmio + PORT_CMD);
1188 readl(port_mmio + PORT_CMD); /* flush */
1189
1190 /* spec says 500 msecs for each bit, so
1191 * this is slightly incorrect.
1192 */
1193 msleep(500);
1194 }
1195
1196 writel(PORT_CMD_SPIN_UP, port_mmio + PORT_CMD);
1197
1198 j = 0;
1199 while (j < 100) {
1200 msleep(10);
1201 tmp = readl(port_mmio + PORT_SCR_STAT);
1202 if ((tmp & 0xf) == 0x3)
1203 break;
1204 j++;
1205 }
1206
1207 tmp = readl(port_mmio + PORT_SCR_ERR);
1208 VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
1209 writel(tmp, port_mmio + PORT_SCR_ERR);
1210 1434
1211 /* ack any pending irq events for this port */ 1435 ahci_init_controller(mmio, pdev, probe_ent->n_ports, hpriv->cap);
1212 tmp = readl(port_mmio + PORT_IRQ_STAT);
1213 VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
1214 if (tmp)
1215 writel(tmp, port_mmio + PORT_IRQ_STAT);
1216
1217 writel(1 << i, mmio + HOST_IRQ_STAT);
1218 }
1219
1220 tmp = readl(mmio + HOST_CTL);
1221 VPRINTK("HOST_CTL 0x%x\n", tmp);
1222 writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
1223 tmp = readl(mmio + HOST_CTL);
1224 VPRINTK("HOST_CTL 0x%x\n", tmp);
1225 1436
1226 pci_set_master(pdev); 1437 pci_set_master(pdev);
1227 1438
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 5e8afc876980..501755a606ed 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -487,7 +487,7 @@ static void piix_pata_cbl_detect(struct ata_port *ap)
487 goto cbl40; 487 goto cbl40;
488 488
489 /* check BIOS cable detect results */ 489 /* check BIOS cable detect results */
490 mask = ap->hard_port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC; 490 mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
491 pci_read_config_byte(pdev, PIIX_IOCFG, &tmp); 491 pci_read_config_byte(pdev, PIIX_IOCFG, &tmp);
492 if ((tmp & mask) == 0) 492 if ((tmp & mask) == 0)
493 goto cbl40; 493 goto cbl40;
@@ -513,7 +513,7 @@ static int piix_pata_prereset(struct ata_port *ap)
513{ 513{
514 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev); 514 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
515 515
516 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->hard_port_no])) { 516 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) {
517 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n"); 517 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
518 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK; 518 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
519 return 0; 519 return 0;
@@ -550,7 +550,7 @@ static int piix_sata_prereset(struct ata_port *ap)
550 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev); 550 struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
551 struct piix_host_priv *hpriv = ap->host_set->private_data; 551 struct piix_host_priv *hpriv = ap->host_set->private_data;
552 const unsigned int *map = hpriv->map; 552 const unsigned int *map = hpriv->map;
553 int base = 2 * ap->hard_port_no; 553 int base = 2 * ap->port_no;
554 unsigned int present = 0; 554 unsigned int present = 0;
555 int port, i; 555 int port, i;
556 u16 pcs; 556 u16 pcs;
@@ -601,7 +601,7 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
601 unsigned int pio = adev->pio_mode - XFER_PIO_0; 601 unsigned int pio = adev->pio_mode - XFER_PIO_0;
602 struct pci_dev *dev = to_pci_dev(ap->host_set->dev); 602 struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
603 unsigned int is_slave = (adev->devno != 0); 603 unsigned int is_slave = (adev->devno != 0);
604 unsigned int master_port= ap->hard_port_no ? 0x42 : 0x40; 604 unsigned int master_port= ap->port_no ? 0x42 : 0x40;
605 unsigned int slave_port = 0x44; 605 unsigned int slave_port = 0x44;
606 u16 master_data; 606 u16 master_data;
607 u8 slave_data; 607 u8 slave_data;
@@ -619,10 +619,10 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
619 /* enable PPE, IE and TIME */ 619 /* enable PPE, IE and TIME */
620 master_data |= 0x0070; 620 master_data |= 0x0070;
621 pci_read_config_byte(dev, slave_port, &slave_data); 621 pci_read_config_byte(dev, slave_port, &slave_data);
622 slave_data &= (ap->hard_port_no ? 0x0f : 0xf0); 622 slave_data &= (ap->port_no ? 0x0f : 0xf0);
623 slave_data |= 623 slave_data |=
624 (timings[pio][0] << 2) | 624 (timings[pio][0] << 2) |
625 (timings[pio][1] << (ap->hard_port_no ? 4 : 0)); 625 (timings[pio][1] << (ap->port_no ? 4 : 0));
626 } else { 626 } else {
627 master_data &= 0xccf8; 627 master_data &= 0xccf8;
628 /* enable PPE, IE and TIME */ 628 /* enable PPE, IE and TIME */
@@ -652,9 +652,9 @@ static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
652{ 652{
653 unsigned int udma = adev->dma_mode; /* FIXME: MWDMA too */ 653 unsigned int udma = adev->dma_mode; /* FIXME: MWDMA too */
654 struct pci_dev *dev = to_pci_dev(ap->host_set->dev); 654 struct pci_dev *dev = to_pci_dev(ap->host_set->dev);
655 u8 maslave = ap->hard_port_no ? 0x42 : 0x40; 655 u8 maslave = ap->port_no ? 0x42 : 0x40;
656 u8 speed = udma; 656 u8 speed = udma;
657 unsigned int drive_dn = (ap->hard_port_no ? 2 : 0) + adev->devno; 657 unsigned int drive_dn = (ap->port_no ? 2 : 0) + adev->devno;
658 int a_speed = 3 << (drive_dn * 4); 658 int a_speed = 3 << (drive_dn * 4);
659 int u_flag = 1 << drive_dn; 659 int u_flag = 1 << drive_dn;
660 int v_flag = 0x01 << drive_dn; 660 int v_flag = 0x01 << drive_dn;
@@ -932,8 +932,6 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
932 932
933static void piix_host_stop(struct ata_host_set *host_set) 933static void piix_host_stop(struct ata_host_set *host_set)
934{ 934{
935 if (host_set->next == NULL)
936 kfree(host_set->private_data);
937 ata_host_stop(host_set); 935 ata_host_stop(host_set);
938} 936}
939 937
diff --git a/drivers/scsi/libata-bmdma.c b/drivers/scsi/libata-bmdma.c
index 9ce221f25954..158f62dbf21b 100644
--- a/drivers/scsi/libata-bmdma.c
+++ b/drivers/scsi/libata-bmdma.c
@@ -797,32 +797,6 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
797} 797}
798 798
799#ifdef CONFIG_PCI 799#ifdef CONFIG_PCI
800static struct ata_probe_ent *
801ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
802{
803 struct ata_probe_ent *probe_ent;
804
805 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
806 if (!probe_ent) {
807 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
808 kobject_name(&(dev->kobj)));
809 return NULL;
810 }
811
812 INIT_LIST_HEAD(&probe_ent->node);
813 probe_ent->dev = dev;
814
815 probe_ent->sht = port->sht;
816 probe_ent->host_flags = port->host_flags;
817 probe_ent->pio_mask = port->pio_mask;
818 probe_ent->mwdma_mask = port->mwdma_mask;
819 probe_ent->udma_mask = port->udma_mask;
820 probe_ent->port_ops = port->port_ops;
821
822 return probe_ent;
823}
824
825
826/** 800/**
827 * ata_pci_init_native_mode - Initialize native-mode driver 801 * ata_pci_init_native_mode - Initialize native-mode driver
828 * @pdev: pci device to be initialized 802 * @pdev: pci device to be initialized
@@ -880,7 +854,7 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
880 if (bmdma) { 854 if (bmdma) {
881 bmdma += 8; 855 bmdma += 8;
882 if(inb(bmdma + 2) & 0x80) 856 if(inb(bmdma + 2) & 0x80)
883 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX; 857 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
884 probe_ent->port[p].bmdma_addr = bmdma; 858 probe_ent->port[p].bmdma_addr = bmdma;
885 } 859 }
886 ata_std_ports(&probe_ent->port[p]); 860 ata_std_ports(&probe_ent->port[p]);
@@ -893,44 +867,48 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
893 867
894 868
895static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, 869static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
896 struct ata_port_info *port, int port_num) 870 struct ata_port_info **port, int port_mask)
897{ 871{
898 struct ata_probe_ent *probe_ent; 872 struct ata_probe_ent *probe_ent;
899 unsigned long bmdma; 873 unsigned long bmdma = pci_resource_start(pdev, 4);
900 874
901 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port); 875 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
902 if (!probe_ent) 876 if (!probe_ent)
903 return NULL; 877 return NULL;
904 878
905 probe_ent->legacy_mode = 1; 879 probe_ent->n_ports = 2;
906 probe_ent->n_ports = 1; 880 probe_ent->private_data = port[0]->private_data;
907 probe_ent->hard_port_no = port_num;
908 probe_ent->private_data = port->private_data;
909
910 switch(port_num)
911 {
912 case 0:
913 probe_ent->irq = 14;
914 probe_ent->port[0].cmd_addr = 0x1f0;
915 probe_ent->port[0].altstatus_addr =
916 probe_ent->port[0].ctl_addr = 0x3f6;
917 break;
918 case 1:
919 probe_ent->irq = 15;
920 probe_ent->port[0].cmd_addr = 0x170;
921 probe_ent->port[0].altstatus_addr =
922 probe_ent->port[0].ctl_addr = 0x376;
923 break;
924 }
925 881
926 bmdma = pci_resource_start(pdev, 4); 882 if (port_mask & ATA_PORT_PRIMARY) {
927 if (bmdma != 0) { 883 probe_ent->irq = 14;
928 bmdma += 8 * port_num; 884 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD;
929 probe_ent->port[0].bmdma_addr = bmdma; 885 probe_ent->port[0].altstatus_addr =
930 if (inb(bmdma + 2) & 0x80) 886 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL;
931 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX; 887 if (bmdma) {
932 } 888 probe_ent->port[0].bmdma_addr = bmdma;
933 ata_std_ports(&probe_ent->port[0]); 889 if (inb(bmdma + 2) & 0x80)
890 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
891 }
892 ata_std_ports(&probe_ent->port[0]);
893 } else
894 probe_ent->dummy_port_mask |= ATA_PORT_PRIMARY;
895
896 if (port_mask & ATA_PORT_SECONDARY) {
897 if (probe_ent->irq)
898 probe_ent->irq2 = 15;
899 else
900 probe_ent->irq = 15;
901 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD;
902 probe_ent->port[1].altstatus_addr =
903 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL;
904 if (bmdma) {
905 probe_ent->port[1].bmdma_addr = bmdma + 8;
906 if (inb(bmdma + 10) & 0x80)
907 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
908 }
909 ata_std_ports(&probe_ent->port[1]);
910 } else
911 probe_ent->dummy_port_mask |= ATA_PORT_SECONDARY;
934 912
935 return probe_ent; 913 return probe_ent;
936} 914}
@@ -950,6 +928,10 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
950 * regions, sets the dma mask, enables bus master mode, and calls 928 * regions, sets the dma mask, enables bus master mode, and calls
951 * ata_device_add() 929 * ata_device_add()
952 * 930 *
931 * ASSUMPTION:
932 * Nobody makes a single channel controller that appears solely as
933 * the secondary legacy port on PCI.
934 *
953 * LOCKING: 935 * LOCKING:
954 * Inherited from PCI layer (may sleep). 936 * Inherited from PCI layer (may sleep).
955 * 937 *
@@ -960,7 +942,7 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
960int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, 942int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
961 unsigned int n_ports) 943 unsigned int n_ports)
962{ 944{
963 struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL; 945 struct ata_probe_ent *probe_ent = NULL;
964 struct ata_port_info *port[2]; 946 struct ata_port_info *port[2];
965 u8 tmp8, mask; 947 u8 tmp8, mask;
966 unsigned int legacy_mode = 0; 948 unsigned int legacy_mode = 0;
@@ -1009,35 +991,34 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1009 goto err_out; 991 goto err_out;
1010 } 992 }
1011 993
1012 /* FIXME: Should use platform specific mappers for legacy port ranges */
1013 if (legacy_mode) { 994 if (legacy_mode) {
1014 if (!request_region(0x1f0, 8, "libata")) { 995 if (!request_region(ATA_PRIMARY_CMD, 8, "libata")) {
1015 struct resource *conflict, res; 996 struct resource *conflict, res;
1016 res.start = 0x1f0; 997 res.start = ATA_PRIMARY_CMD;
1017 res.end = 0x1f0 + 8 - 1; 998 res.end = ATA_PRIMARY_CMD + 8 - 1;
1018 conflict = ____request_resource(&ioport_resource, &res); 999 conflict = ____request_resource(&ioport_resource, &res);
1019 if (!strcmp(conflict->name, "libata")) 1000 if (!strcmp(conflict->name, "libata"))
1020 legacy_mode |= (1 << 0); 1001 legacy_mode |= ATA_PORT_PRIMARY;
1021 else { 1002 else {
1022 disable_dev_on_err = 0; 1003 disable_dev_on_err = 0;
1023 printk(KERN_WARNING "ata: 0x1f0 IDE port busy\n"); 1004 printk(KERN_WARNING "ata: 0x%0X IDE port busy\n", ATA_PRIMARY_CMD);
1024 } 1005 }
1025 } else 1006 } else
1026 legacy_mode |= (1 << 0); 1007 legacy_mode |= ATA_PORT_PRIMARY;
1027 1008
1028 if (!request_region(0x170, 8, "libata")) { 1009 if (!request_region(ATA_SECONDARY_CMD, 8, "libata")) {
1029 struct resource *conflict, res; 1010 struct resource *conflict, res;
1030 res.start = 0x170; 1011 res.start = ATA_SECONDARY_CMD;
1031 res.end = 0x170 + 8 - 1; 1012 res.end = ATA_SECONDARY_CMD + 8 - 1;
1032 conflict = ____request_resource(&ioport_resource, &res); 1013 conflict = ____request_resource(&ioport_resource, &res);
1033 if (!strcmp(conflict->name, "libata")) 1014 if (!strcmp(conflict->name, "libata"))
1034 legacy_mode |= (1 << 1); 1015 legacy_mode |= ATA_PORT_SECONDARY;
1035 else { 1016 else {
1036 disable_dev_on_err = 0; 1017 disable_dev_on_err = 0;
1037 printk(KERN_WARNING "ata: 0x170 IDE port busy\n"); 1018 printk(KERN_WARNING "ata: 0x%X IDE port busy\n", ATA_SECONDARY_CMD);
1038 } 1019 }
1039 } else 1020 } else
1040 legacy_mode |= (1 << 1); 1021 legacy_mode |= ATA_PORT_SECONDARY;
1041 } 1022 }
1042 1023
1043 /* we have legacy mode, but all ports are unavailable */ 1024 /* we have legacy mode, but all ports are unavailable */
@@ -1055,17 +1036,14 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1055 goto err_out_regions; 1036 goto err_out_regions;
1056 1037
1057 if (legacy_mode) { 1038 if (legacy_mode) {
1058 if (legacy_mode & (1 << 0)) 1039 probe_ent = ata_pci_init_legacy_port(pdev, port, legacy_mode);
1059 probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
1060 if (legacy_mode & (1 << 1))
1061 probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
1062 } else { 1040 } else {
1063 if (n_ports == 2) 1041 if (n_ports == 2)
1064 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 1042 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
1065 else 1043 else
1066 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY); 1044 probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY);
1067 } 1045 }
1068 if (!probe_ent && !probe_ent2) { 1046 if (!probe_ent) {
1069 rc = -ENOMEM; 1047 rc = -ENOMEM;
1070 goto err_out_regions; 1048 goto err_out_regions;
1071 } 1049 }
@@ -1073,35 +1051,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1073 pci_set_master(pdev); 1051 pci_set_master(pdev);
1074 1052
1075 /* FIXME: check ata_device_add return */ 1053 /* FIXME: check ata_device_add return */
1076 if (legacy_mode) { 1054 ata_device_add(probe_ent);
1077 struct device *dev = &pdev->dev;
1078 struct ata_host_set *host_set = NULL;
1079
1080 if (legacy_mode & (1 << 0)) {
1081 ata_device_add(probe_ent);
1082 host_set = dev_get_drvdata(dev);
1083 }
1084
1085 if (legacy_mode & (1 << 1)) {
1086 ata_device_add(probe_ent2);
1087 if (host_set) {
1088 host_set->next = dev_get_drvdata(dev);
1089 dev_set_drvdata(dev, host_set);
1090 }
1091 }
1092 } else
1093 ata_device_add(probe_ent);
1094 1055
1095 kfree(probe_ent); 1056 kfree(probe_ent);
1096 kfree(probe_ent2);
1097 1057
1098 return 0; 1058 return 0;
1099 1059
1100err_out_regions: 1060err_out_regions:
1101 if (legacy_mode & (1 << 0)) 1061 if (legacy_mode & ATA_PORT_PRIMARY)
1102 release_region(0x1f0, 8); 1062 release_region(ATA_PRIMARY_CMD, 8);
1103 if (legacy_mode & (1 << 1)) 1063 if (legacy_mode & ATA_PORT_SECONDARY)
1104 release_region(0x170, 8); 1064 release_region(ATA_SECONDARY_CMD, 8);
1105 pci_release_regions(pdev); 1065 pci_release_regions(pdev);
1106err_out: 1066err_out:
1107 if (disable_dev_on_err) 1067 if (disable_dev_on_err)
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 16fc2dd8f2f7..3f963f206d4a 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -1528,7 +1528,7 @@ err_out_nosup:
1528 * Zero on success, negative errno otherwise. 1528 * Zero on success, negative errno otherwise.
1529 */ 1529 */
1530 1530
1531static int ata_bus_probe(struct ata_port *ap) 1531int ata_bus_probe(struct ata_port *ap)
1532{ 1532{
1533 unsigned int classes[ATA_MAX_DEVICES]; 1533 unsigned int classes[ATA_MAX_DEVICES];
1534 int tries[ATA_MAX_DEVICES]; 1534 int tries[ATA_MAX_DEVICES];
@@ -3040,10 +3040,6 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
3040 * known limits including host controller limits, device 3040 * known limits including host controller limits, device
3041 * blacklist, etc... 3041 * blacklist, etc...
3042 * 3042 *
3043 * FIXME: The current implementation limits all transfer modes to
3044 * the fastest of the lowested device on the port. This is not
3045 * required on most controllers.
3046 *
3047 * LOCKING: 3043 * LOCKING:
3048 * None. 3044 * None.
3049 */ 3045 */
@@ -3052,8 +3048,8 @@ static void ata_dev_xfermask(struct ata_device *dev)
3052 struct ata_port *ap = dev->ap; 3048 struct ata_port *ap = dev->ap;
3053 struct ata_host_set *hs = ap->host_set; 3049 struct ata_host_set *hs = ap->host_set;
3054 unsigned long xfer_mask; 3050 unsigned long xfer_mask;
3055 int i;
3056 3051
3052 /* controller modes available */
3057 xfer_mask = ata_pack_xfermask(ap->pio_mask, 3053 xfer_mask = ata_pack_xfermask(ap->pio_mask,
3058 ap->mwdma_mask, ap->udma_mask); 3054 ap->mwdma_mask, ap->udma_mask);
3059 3055
@@ -3063,34 +3059,20 @@ static void ata_dev_xfermask(struct ata_device *dev)
3063 if (ap->cbl == ATA_CBL_PATA40) 3059 if (ap->cbl == ATA_CBL_PATA40)
3064 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); 3060 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
3065 3061
3066 /* FIXME: Use port-wide xfermask for now */ 3062 xfer_mask &= ata_pack_xfermask(dev->pio_mask,
3067 for (i = 0; i < ATA_MAX_DEVICES; i++) { 3063 dev->mwdma_mask, dev->udma_mask);
3068 struct ata_device *d = &ap->device[i]; 3064 xfer_mask &= ata_id_xfermask(dev->id);
3069
3070 if (ata_dev_absent(d))
3071 continue;
3072
3073 if (ata_dev_disabled(d)) {
3074 /* to avoid violating device selection timing */
3075 xfer_mask &= ata_pack_xfermask(d->pio_mask,
3076 UINT_MAX, UINT_MAX);
3077 continue;
3078 }
3079
3080 xfer_mask &= ata_pack_xfermask(d->pio_mask,
3081 d->mwdma_mask, d->udma_mask);
3082 xfer_mask &= ata_id_xfermask(d->id);
3083 if (ata_dma_blacklisted(d))
3084 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
3085 }
3086 3065
3087 if (ata_dma_blacklisted(dev)) 3066 if (ata_dma_blacklisted(dev)) {
3067 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
3088 ata_dev_printk(dev, KERN_WARNING, 3068 ata_dev_printk(dev, KERN_WARNING,
3089 "device is on DMA blacklist, disabling DMA\n"); 3069 "device is on DMA blacklist, disabling DMA\n");
3070 }
3090 3071
3091 if (hs->flags & ATA_HOST_SIMPLEX) { 3072 if ((hs->flags & ATA_HOST_SIMPLEX) && hs->simplex_claimed) {
3092 if (hs->simplex_claimed) 3073 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
3093 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 3074 ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by "
3075 "other device, disabling DMA\n");
3094 } 3076 }
3095 3077
3096 if (ap->ops->mode_filter) 3078 if (ap->ops->mode_filter)
@@ -5218,41 +5200,29 @@ void ata_dev_init(struct ata_device *dev)
5218} 5200}
5219 5201
5220/** 5202/**
5221 * ata_host_init - Initialize an ata_port structure 5203 * ata_port_init - Initialize an ata_port structure
5222 * @ap: Structure to initialize 5204 * @ap: Structure to initialize
5223 * @host: associated SCSI mid-layer structure
5224 * @host_set: Collection of hosts to which @ap belongs 5205 * @host_set: Collection of hosts to which @ap belongs
5225 * @ent: Probe information provided by low-level driver 5206 * @ent: Probe information provided by low-level driver
5226 * @port_no: Port number associated with this ata_port 5207 * @port_no: Port number associated with this ata_port
5227 * 5208 *
5228 * Initialize a new ata_port structure, and its associated 5209 * Initialize a new ata_port structure.
5229 * scsi_host.
5230 * 5210 *
5231 * LOCKING: 5211 * LOCKING:
5232 * Inherited from caller. 5212 * Inherited from caller.
5233 */ 5213 */
5234static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, 5214void ata_port_init(struct ata_port *ap, struct ata_host_set *host_set,
5235 struct ata_host_set *host_set, 5215 const struct ata_probe_ent *ent, unsigned int port_no)
5236 const struct ata_probe_ent *ent, unsigned int port_no)
5237{ 5216{
5238 unsigned int i; 5217 unsigned int i;
5239 5218
5240 host->max_id = 16;
5241 host->max_lun = 1;
5242 host->max_channel = 1;
5243 host->unique_id = ata_unique_id++;
5244 host->max_cmd_len = 12;
5245
5246 ap->lock = &host_set->lock; 5219 ap->lock = &host_set->lock;
5247 ap->flags = ATA_FLAG_DISABLED; 5220 ap->flags = ATA_FLAG_DISABLED;
5248 ap->id = host->unique_id; 5221 ap->id = ata_unique_id++;
5249 ap->host = host;
5250 ap->ctl = ATA_DEVCTL_OBS; 5222 ap->ctl = ATA_DEVCTL_OBS;
5251 ap->host_set = host_set; 5223 ap->host_set = host_set;
5252 ap->dev = ent->dev; 5224 ap->dev = ent->dev;
5253 ap->port_no = port_no; 5225 ap->port_no = port_no;
5254 ap->hard_port_no =
5255 ent->legacy_mode ? ent->hard_port_no : port_no;
5256 ap->pio_mask = ent->pio_mask; 5226 ap->pio_mask = ent->pio_mask;
5257 ap->mwdma_mask = ent->mwdma_mask; 5227 ap->mwdma_mask = ent->mwdma_mask;
5258 ap->udma_mask = ent->udma_mask; 5228 ap->udma_mask = ent->udma_mask;
@@ -5298,7 +5268,28 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
5298} 5268}
5299 5269
5300/** 5270/**
5301 * ata_host_add - Attach low-level ATA driver to system 5271 * ata_port_init_shost - Initialize SCSI host associated with ATA port
5272 * @ap: ATA port to initialize SCSI host for
5273 * @shost: SCSI host associated with @ap
5274 *
5275 * Initialize SCSI host @shost associated with ATA port @ap.
5276 *
5277 * LOCKING:
5278 * Inherited from caller.
5279 */
5280static void ata_port_init_shost(struct ata_port *ap, struct Scsi_Host *shost)
5281{
5282 ap->host = shost;
5283
5284 shost->unique_id = ap->id;
5285 shost->max_id = 16;
5286 shost->max_lun = 1;
5287 shost->max_channel = 1;
5288 shost->max_cmd_len = 12;
5289}
5290
5291/**
5292 * ata_port_add - Attach low-level ATA driver to system
5302 * @ent: Information provided by low-level driver 5293 * @ent: Information provided by low-level driver
5303 * @host_set: Collections of ports to which we add 5294 * @host_set: Collections of ports to which we add
5304 * @port_no: Port number associated with this host 5295 * @port_no: Port number associated with this host
@@ -5311,14 +5302,12 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
5311 * RETURNS: 5302 * RETURNS:
5312 * New ata_port on success, for NULL on error. 5303 * New ata_port on success, for NULL on error.
5313 */ 5304 */
5314 5305static struct ata_port * ata_port_add(const struct ata_probe_ent *ent,
5315static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
5316 struct ata_host_set *host_set, 5306 struct ata_host_set *host_set,
5317 unsigned int port_no) 5307 unsigned int port_no)
5318{ 5308{
5319 struct Scsi_Host *host; 5309 struct Scsi_Host *shost;
5320 struct ata_port *ap; 5310 struct ata_port *ap;
5321 int rc;
5322 5311
5323 DPRINTK("ENTER\n"); 5312 DPRINTK("ENTER\n");
5324 5313
@@ -5329,25 +5318,40 @@ static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
5329 return NULL; 5318 return NULL;
5330 } 5319 }
5331 5320
5332 host = scsi_host_alloc(ent->sht, sizeof(struct ata_port)); 5321 shost = scsi_host_alloc(ent->sht, sizeof(struct ata_port));
5333 if (!host) 5322 if (!shost)
5334 return NULL; 5323 return NULL;
5335 5324
5336 host->transportt = &ata_scsi_transport_template; 5325 shost->transportt = &ata_scsi_transport_template;
5337 5326
5338 ap = ata_shost_to_port(host); 5327 ap = ata_shost_to_port(shost);
5339 5328
5340 ata_host_init(ap, host, host_set, ent, port_no); 5329 ata_port_init(ap, host_set, ent, port_no);
5341 5330 ata_port_init_shost(ap, shost);
5342 rc = ap->ops->port_start(ap);
5343 if (rc)
5344 goto err_out;
5345 5331
5346 return ap; 5332 return ap;
5333}
5347 5334
5348err_out: 5335/**
5349 scsi_host_put(host); 5336 * ata_sas_host_init - Initialize a host_set struct
5350 return NULL; 5337 * @host_set: host_set to initialize
5338 * @dev: device host_set is attached to
5339 * @flags: host_set flags
5340 * @ops: port_ops
5341 *
5342 * LOCKING:
5343 * PCI/etc. bus probe sem.
5344 *
5345 */
5346
5347void ata_host_set_init(struct ata_host_set *host_set,
5348 struct device *dev, unsigned long flags,
5349 const struct ata_port_operations *ops)
5350{
5351 spin_lock_init(&host_set->lock);
5352 host_set->dev = dev;
5353 host_set->flags = flags;
5354 host_set->ops = ops;
5351} 5355}
5352 5356
5353/** 5357/**
@@ -5370,7 +5374,7 @@ err_out:
5370 */ 5374 */
5371int ata_device_add(const struct ata_probe_ent *ent) 5375int ata_device_add(const struct ata_probe_ent *ent)
5372{ 5376{
5373 unsigned int count = 0, i; 5377 unsigned int i;
5374 struct device *dev = ent->dev; 5378 struct device *dev = ent->dev;
5375 struct ata_host_set *host_set; 5379 struct ata_host_set *host_set;
5376 int rc; 5380 int rc;
@@ -5381,50 +5385,65 @@ int ata_device_add(const struct ata_probe_ent *ent)
5381 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 5385 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
5382 if (!host_set) 5386 if (!host_set)
5383 return 0; 5387 return 0;
5384 spin_lock_init(&host_set->lock);
5385 5388
5386 host_set->dev = dev; 5389 ata_host_set_init(host_set, dev, ent->host_set_flags, ent->port_ops);
5387 host_set->n_ports = ent->n_ports; 5390 host_set->n_ports = ent->n_ports;
5388 host_set->irq = ent->irq; 5391 host_set->irq = ent->irq;
5392 host_set->irq2 = ent->irq2;
5389 host_set->mmio_base = ent->mmio_base; 5393 host_set->mmio_base = ent->mmio_base;
5390 host_set->private_data = ent->private_data; 5394 host_set->private_data = ent->private_data;
5391 host_set->ops = ent->port_ops;
5392 host_set->flags = ent->host_set_flags;
5393 5395
5394 /* register each port bound to this device */ 5396 /* register each port bound to this device */
5395 for (i = 0; i < ent->n_ports; i++) { 5397 for (i = 0; i < host_set->n_ports; i++) {
5396 struct ata_port *ap; 5398 struct ata_port *ap;
5397 unsigned long xfer_mode_mask; 5399 unsigned long xfer_mode_mask;
5400 int irq_line = ent->irq;
5398 5401
5399 ap = ata_host_add(ent, host_set, i); 5402 ap = ata_port_add(ent, host_set, i);
5400 if (!ap) 5403 if (!ap)
5401 goto err_out; 5404 goto err_out;
5402 5405
5403 host_set->ports[i] = ap; 5406 host_set->ports[i] = ap;
5407
5408 /* dummy? */
5409 if (ent->dummy_port_mask & (1 << i)) {
5410 ata_port_printk(ap, KERN_INFO, "DUMMY\n");
5411 ap->ops = &ata_dummy_port_ops;
5412 continue;
5413 }
5414
5415 /* start port */
5416 rc = ap->ops->port_start(ap);
5417 if (rc) {
5418 host_set->ports[i] = NULL;
5419 scsi_host_put(ap->host);
5420 goto err_out;
5421 }
5422
5423 /* Report the secondary IRQ for second channel legacy */
5424 if (i == 1 && ent->irq2)
5425 irq_line = ent->irq2;
5426
5404 xfer_mode_mask =(ap->udma_mask << ATA_SHIFT_UDMA) | 5427 xfer_mode_mask =(ap->udma_mask << ATA_SHIFT_UDMA) |
5405 (ap->mwdma_mask << ATA_SHIFT_MWDMA) | 5428 (ap->mwdma_mask << ATA_SHIFT_MWDMA) |
5406 (ap->pio_mask << ATA_SHIFT_PIO); 5429 (ap->pio_mask << ATA_SHIFT_PIO);
5407 5430
5408 /* print per-port info to dmesg */ 5431 /* print per-port info to dmesg */
5409 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%lX " 5432 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%lX "
5410 "ctl 0x%lX bmdma 0x%lX irq %lu\n", 5433 "ctl 0x%lX bmdma 0x%lX irq %d\n",
5411 ap->flags & ATA_FLAG_SATA ? 'S' : 'P', 5434 ap->flags & ATA_FLAG_SATA ? 'S' : 'P',
5412 ata_mode_string(xfer_mode_mask), 5435 ata_mode_string(xfer_mode_mask),
5413 ap->ioaddr.cmd_addr, 5436 ap->ioaddr.cmd_addr,
5414 ap->ioaddr.ctl_addr, 5437 ap->ioaddr.ctl_addr,
5415 ap->ioaddr.bmdma_addr, 5438 ap->ioaddr.bmdma_addr,
5416 ent->irq); 5439 irq_line);
5417 5440
5418 ata_chk_status(ap); 5441 ata_chk_status(ap);
5419 host_set->ops->irq_clear(ap); 5442 host_set->ops->irq_clear(ap);
5420 ata_eh_freeze_port(ap); /* freeze port before requesting IRQ */ 5443 ata_eh_freeze_port(ap); /* freeze port before requesting IRQ */
5421 count++;
5422 } 5444 }
5423 5445
5424 if (!count) 5446 /* obtain irq, that may be shared between channels */
5425 goto err_free_ret;
5426
5427 /* obtain irq, that is shared between channels */
5428 rc = request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags, 5447 rc = request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags,
5429 DRV_NAME, host_set); 5448 DRV_NAME, host_set);
5430 if (rc) { 5449 if (rc) {
@@ -5433,15 +5452,28 @@ int ata_device_add(const struct ata_probe_ent *ent)
5433 goto err_out; 5452 goto err_out;
5434 } 5453 }
5435 5454
5455 /* do we have a second IRQ for the other channel, eg legacy mode */
5456 if (ent->irq2) {
5457 /* We will get weird core code crashes later if this is true
5458 so trap it now */
5459 BUG_ON(ent->irq == ent->irq2);
5460
5461 rc = request_irq(ent->irq2, ent->port_ops->irq_handler, ent->irq_flags,
5462 DRV_NAME, host_set);
5463 if (rc) {
5464 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n",
5465 ent->irq2, rc);
5466 goto err_out_free_irq;
5467 }
5468 }
5469
5436 /* perform each probe synchronously */ 5470 /* perform each probe synchronously */
5437 DPRINTK("probe begin\n"); 5471 DPRINTK("probe begin\n");
5438 for (i = 0; i < count; i++) { 5472 for (i = 0; i < host_set->n_ports; i++) {
5439 struct ata_port *ap; 5473 struct ata_port *ap = host_set->ports[i];
5440 u32 scontrol; 5474 u32 scontrol;
5441 int rc; 5475 int rc;
5442 5476
5443 ap = host_set->ports[i];
5444
5445 /* init sata_spd_limit to the current value */ 5477 /* init sata_spd_limit to the current value */
5446 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) { 5478 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) {
5447 int spd = (scontrol >> 4) & 0xf; 5479 int spd = (scontrol >> 4) & 0xf;
@@ -5497,7 +5529,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
5497 5529
5498 /* probes are done, now scan each port's disk(s) */ 5530 /* probes are done, now scan each port's disk(s) */
5499 DPRINTK("host probe begin\n"); 5531 DPRINTK("host probe begin\n");
5500 for (i = 0; i < count; i++) { 5532 for (i = 0; i < host_set->n_ports; i++) {
5501 struct ata_port *ap = host_set->ports[i]; 5533 struct ata_port *ap = host_set->ports[i];
5502 5534
5503 ata_scsi_scan_host(ap); 5535 ata_scsi_scan_host(ap);
@@ -5508,15 +5540,17 @@ int ata_device_add(const struct ata_probe_ent *ent)
5508 VPRINTK("EXIT, returning %u\n", ent->n_ports); 5540 VPRINTK("EXIT, returning %u\n", ent->n_ports);
5509 return ent->n_ports; /* success */ 5541 return ent->n_ports; /* success */
5510 5542
5543err_out_free_irq:
5544 free_irq(ent->irq, host_set);
5511err_out: 5545err_out:
5512 for (i = 0; i < count; i++) { 5546 for (i = 0; i < host_set->n_ports; i++) {
5513 struct ata_port *ap = host_set->ports[i]; 5547 struct ata_port *ap = host_set->ports[i];
5514 if (ap) { 5548 if (ap) {
5515 ap->ops->port_stop(ap); 5549 ap->ops->port_stop(ap);
5516 scsi_host_put(ap->host); 5550 scsi_host_put(ap->host);
5517 } 5551 }
5518 } 5552 }
5519err_free_ret: 5553
5520 kfree(host_set); 5554 kfree(host_set);
5521 VPRINTK("EXIT, returning 0\n"); 5555 VPRINTK("EXIT, returning 0\n");
5522 return 0; 5556 return 0;
@@ -5599,6 +5633,8 @@ void ata_host_set_remove(struct ata_host_set *host_set)
5599 ata_port_detach(host_set->ports[i]); 5633 ata_port_detach(host_set->ports[i]);
5600 5634
5601 free_irq(host_set->irq, host_set); 5635 free_irq(host_set->irq, host_set);
5636 if (host_set->irq2)
5637 free_irq(host_set->irq2, host_set);
5602 5638
5603 for (i = 0; i < host_set->n_ports; i++) { 5639 for (i = 0; i < host_set->n_ports; i++) {
5604 struct ata_port *ap = host_set->ports[i]; 5640 struct ata_port *ap = host_set->ports[i];
@@ -5608,10 +5644,11 @@ void ata_host_set_remove(struct ata_host_set *host_set)
5608 if ((ap->flags & ATA_FLAG_NO_LEGACY) == 0) { 5644 if ((ap->flags & ATA_FLAG_NO_LEGACY) == 0) {
5609 struct ata_ioports *ioaddr = &ap->ioaddr; 5645 struct ata_ioports *ioaddr = &ap->ioaddr;
5610 5646
5611 if (ioaddr->cmd_addr == 0x1f0) 5647 /* FIXME: Add -ac IDE pci mods to remove these special cases */
5612 release_region(0x1f0, 8); 5648 if (ioaddr->cmd_addr == ATA_PRIMARY_CMD)
5613 else if (ioaddr->cmd_addr == 0x170) 5649 release_region(ATA_PRIMARY_CMD, 8);
5614 release_region(0x170, 8); 5650 else if (ioaddr->cmd_addr == ATA_SECONDARY_CMD)
5651 release_region(ATA_SECONDARY_CMD, 8);
5615 } 5652 }
5616 5653
5617 scsi_host_put(ap->host); 5654 scsi_host_put(ap->host);
@@ -5650,6 +5687,31 @@ int ata_scsi_release(struct Scsi_Host *host)
5650 return 1; 5687 return 1;
5651} 5688}
5652 5689
5690struct ata_probe_ent *
5691ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
5692{
5693 struct ata_probe_ent *probe_ent;
5694
5695 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
5696 if (!probe_ent) {
5697 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
5698 kobject_name(&(dev->kobj)));
5699 return NULL;
5700 }
5701
5702 INIT_LIST_HEAD(&probe_ent->node);
5703 probe_ent->dev = dev;
5704
5705 probe_ent->sht = port->sht;
5706 probe_ent->host_flags = port->host_flags;
5707 probe_ent->pio_mask = port->pio_mask;
5708 probe_ent->mwdma_mask = port->mwdma_mask;
5709 probe_ent->udma_mask = port->udma_mask;
5710 probe_ent->port_ops = port->port_ops;
5711
5712 return probe_ent;
5713}
5714
5653/** 5715/**
5654 * ata_std_ports - initialize ioaddr with standard port offsets. 5716 * ata_std_ports - initialize ioaddr with standard port offsets.
5655 * @ioaddr: IO address structure to be initialized 5717 * @ioaddr: IO address structure to be initialized
@@ -5704,11 +5766,8 @@ void ata_pci_remove_one (struct pci_dev *pdev)
5704{ 5766{
5705 struct device *dev = pci_dev_to_dev(pdev); 5767 struct device *dev = pci_dev_to_dev(pdev);
5706 struct ata_host_set *host_set = dev_get_drvdata(dev); 5768 struct ata_host_set *host_set = dev_get_drvdata(dev);
5707 struct ata_host_set *host_set2 = host_set->next;
5708 5769
5709 ata_host_set_remove(host_set); 5770 ata_host_set_remove(host_set);
5710 if (host_set2)
5711 ata_host_set_remove(host_set2);
5712 5771
5713 pci_release_regions(pdev); 5772 pci_release_regions(pdev);
5714 pci_disable_device(pdev); 5773 pci_disable_device(pdev);
@@ -5749,11 +5808,11 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
5749 return (tmp == bits->val) ? 1 : 0; 5808 return (tmp == bits->val) ? 1 : 0;
5750} 5809}
5751 5810
5752void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t state) 5811void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
5753{ 5812{
5754 pci_save_state(pdev); 5813 pci_save_state(pdev);
5755 5814
5756 if (state.event == PM_EVENT_SUSPEND) { 5815 if (mesg.event == PM_EVENT_SUSPEND) {
5757 pci_disable_device(pdev); 5816 pci_disable_device(pdev);
5758 pci_set_power_state(pdev, PCI_D3hot); 5817 pci_set_power_state(pdev, PCI_D3hot);
5759 } 5818 }
@@ -5767,24 +5826,16 @@ void ata_pci_device_do_resume(struct pci_dev *pdev)
5767 pci_set_master(pdev); 5826 pci_set_master(pdev);
5768} 5827}
5769 5828
5770int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) 5829int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
5771{ 5830{
5772 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev); 5831 struct ata_host_set *host_set = dev_get_drvdata(&pdev->dev);
5773 int rc = 0; 5832 int rc = 0;
5774 5833
5775 rc = ata_host_set_suspend(host_set, state); 5834 rc = ata_host_set_suspend(host_set, mesg);
5776 if (rc) 5835 if (rc)
5777 return rc; 5836 return rc;
5778 5837
5779 if (host_set->next) { 5838 ata_pci_device_do_suspend(pdev, mesg);
5780 rc = ata_host_set_suspend(host_set->next, state);
5781 if (rc) {
5782 ata_host_set_resume(host_set);
5783 return rc;
5784 }
5785 }
5786
5787 ata_pci_device_do_suspend(pdev, state);
5788 5839
5789 return 0; 5840 return 0;
5790} 5841}
@@ -5795,9 +5846,6 @@ int ata_pci_device_resume(struct pci_dev *pdev)
5795 5846
5796 ata_pci_device_do_resume(pdev); 5847 ata_pci_device_do_resume(pdev);
5797 ata_host_set_resume(host_set); 5848 ata_host_set_resume(host_set);
5798 if (host_set->next)
5799 ata_host_set_resume(host_set->next);
5800
5801 return 0; 5849 return 0;
5802} 5850}
5803#endif /* CONFIG_PCI */ 5851#endif /* CONFIG_PCI */
@@ -5897,6 +5945,39 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5897} 5945}
5898 5946
5899/* 5947/*
5948 * Dummy port_ops
5949 */
5950static void ata_dummy_noret(struct ata_port *ap) { }
5951static int ata_dummy_ret0(struct ata_port *ap) { return 0; }
5952static void ata_dummy_qc_noret(struct ata_queued_cmd *qc) { }
5953
5954static u8 ata_dummy_check_status(struct ata_port *ap)
5955{
5956 return ATA_DRDY;
5957}
5958
5959static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd *qc)
5960{
5961 return AC_ERR_SYSTEM;
5962}
5963
5964const struct ata_port_operations ata_dummy_port_ops = {
5965 .port_disable = ata_port_disable,
5966 .check_status = ata_dummy_check_status,
5967 .check_altstatus = ata_dummy_check_status,
5968 .dev_select = ata_noop_dev_select,
5969 .qc_prep = ata_noop_qc_prep,
5970 .qc_issue = ata_dummy_qc_issue,
5971 .freeze = ata_dummy_noret,
5972 .thaw = ata_dummy_noret,
5973 .error_handler = ata_dummy_noret,
5974 .post_internal_cmd = ata_dummy_qc_noret,
5975 .irq_clear = ata_dummy_noret,
5976 .port_start = ata_dummy_ret0,
5977 .port_stop = ata_dummy_noret,
5978};
5979
5980/*
5900 * libata is essentially a library of internal helper functions for 5981 * libata is essentially a library of internal helper functions for
5901 * low-level ATA host controller drivers. As such, the API/ABI is 5982 * low-level ATA host controller drivers. As such, the API/ABI is
5902 * likely to change as new drivers are added and updated. 5983 * likely to change as new drivers are added and updated.
@@ -5906,8 +5987,10 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
5906EXPORT_SYMBOL_GPL(sata_deb_timing_normal); 5987EXPORT_SYMBOL_GPL(sata_deb_timing_normal);
5907EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); 5988EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug);
5908EXPORT_SYMBOL_GPL(sata_deb_timing_long); 5989EXPORT_SYMBOL_GPL(sata_deb_timing_long);
5990EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
5909EXPORT_SYMBOL_GPL(ata_std_bios_param); 5991EXPORT_SYMBOL_GPL(ata_std_bios_param);
5910EXPORT_SYMBOL_GPL(ata_std_ports); 5992EXPORT_SYMBOL_GPL(ata_std_ports);
5993EXPORT_SYMBOL_GPL(ata_host_set_init);
5911EXPORT_SYMBOL_GPL(ata_device_add); 5994EXPORT_SYMBOL_GPL(ata_device_add);
5912EXPORT_SYMBOL_GPL(ata_port_detach); 5995EXPORT_SYMBOL_GPL(ata_port_detach);
5913EXPORT_SYMBOL_GPL(ata_host_set_remove); 5996EXPORT_SYMBOL_GPL(ata_host_set_remove);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index e92c31d698ff..d168e3413661 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -400,7 +400,7 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
400/** 400/**
401 * ata_scsi_device_suspend - suspend ATA device associated with sdev 401 * ata_scsi_device_suspend - suspend ATA device associated with sdev
402 * @sdev: the SCSI device to suspend 402 * @sdev: the SCSI device to suspend
403 * @state: target power management state 403 * @mesg: target power management message
404 * 404 *
405 * Request suspend EH action on the ATA device associated with 405 * Request suspend EH action on the ATA device associated with
406 * @sdev and wait for the operation to complete. 406 * @sdev and wait for the operation to complete.
@@ -411,7 +411,7 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
411 * RETURNS: 411 * RETURNS:
412 * 0 on success, -errno otherwise. 412 * 0 on success, -errno otherwise.
413 */ 413 */
414int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) 414int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t mesg)
415{ 415{
416 struct ata_port *ap = ata_shost_to_port(sdev->host); 416 struct ata_port *ap = ata_shost_to_port(sdev->host);
417 struct ata_device *dev = ata_scsi_find_dev(ap, sdev); 417 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
@@ -438,7 +438,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
438 438
439 /* request suspend */ 439 /* request suspend */
440 action = ATA_EH_SUSPEND; 440 action = ATA_EH_SUSPEND;
441 if (state.event != PM_EVENT_SUSPEND) 441 if (mesg.event != PM_EVENT_SUSPEND)
442 action |= ATA_EH_PM_FREEZE; 442 action |= ATA_EH_PM_FREEZE;
443 ap->eh_info.dev_action[dev->devno] |= action; 443 ap->eh_info.dev_action[dev->devno] |= action;
444 ap->eh_info.flags |= ATA_EHI_QUIET; 444 ap->eh_info.flags |= ATA_EHI_QUIET;
@@ -463,7 +463,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
463 spin_unlock_irqrestore(ap->lock, flags); 463 spin_unlock_irqrestore(ap->lock, flags);
464 out: 464 out:
465 if (rc == 0) 465 if (rc == 0)
466 sdev->sdev_gendev.power.power_state = state; 466 sdev->sdev_gendev.power.power_state = mesg;
467 return rc; 467 return rc;
468} 468}
469 469
@@ -3171,3 +3171,152 @@ void ata_scsi_dev_rescan(void *data)
3171 scsi_rescan_device(&(dev->sdev->sdev_gendev)); 3171 scsi_rescan_device(&(dev->sdev->sdev_gendev));
3172 } 3172 }
3173} 3173}
3174
3175/**
3176 * ata_sas_port_alloc - Allocate port for a SAS attached SATA device
3177 * @pdev: PCI device that the scsi device is attached to
3178 * @port_info: Information from low-level host driver
3179 * @host: SCSI host that the scsi device is attached to
3180 *
3181 * LOCKING:
3182 * PCI/etc. bus probe sem.
3183 *
3184 * RETURNS:
3185 * ata_port pointer on success / NULL on failure.
3186 */
3187
3188struct ata_port *ata_sas_port_alloc(struct ata_host_set *host_set,
3189 struct ata_port_info *port_info,
3190 struct Scsi_Host *host)
3191{
3192 struct ata_port *ap = kzalloc(sizeof(*ap), GFP_KERNEL);
3193 struct ata_probe_ent *ent;
3194
3195 if (!ap)
3196 return NULL;
3197
3198 ent = ata_probe_ent_alloc(host_set->dev, port_info);
3199 if (!ent) {
3200 kfree(ap);
3201 return NULL;
3202 }
3203
3204 ata_port_init(ap, host_set, ent, 0);
3205 ap->lock = host->host_lock;
3206 kfree(ent);
3207 return ap;
3208}
3209EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
3210
3211/**
3212 * ata_sas_port_start - Set port up for dma.
3213 * @ap: Port to initialize
3214 *
3215 * Called just after data structures for each port are
3216 * initialized. Allocates DMA pad.
3217 *
3218 * May be used as the port_start() entry in ata_port_operations.
3219 *
3220 * LOCKING:
3221 * Inherited from caller.
3222 */
3223int ata_sas_port_start(struct ata_port *ap)
3224{
3225 return ata_pad_alloc(ap, ap->dev);
3226}
3227EXPORT_SYMBOL_GPL(ata_sas_port_start);
3228
3229/**
3230 * ata_port_stop - Undo ata_sas_port_start()
3231 * @ap: Port to shut down
3232 *
3233 * Frees the DMA pad.
3234 *
3235 * May be used as the port_stop() entry in ata_port_operations.
3236 *
3237 * LOCKING:
3238 * Inherited from caller.
3239 */
3240
3241void ata_sas_port_stop(struct ata_port *ap)
3242{
3243 ata_pad_free(ap, ap->dev);
3244}
3245EXPORT_SYMBOL_GPL(ata_sas_port_stop);
3246
3247/**
3248 * ata_sas_port_init - Initialize a SATA device
3249 * @ap: SATA port to initialize
3250 *
3251 * LOCKING:
3252 * PCI/etc. bus probe sem.
3253 *
3254 * RETURNS:
3255 * Zero on success, non-zero on error.
3256 */
3257
3258int ata_sas_port_init(struct ata_port *ap)
3259{
3260 int rc = ap->ops->port_start(ap);
3261
3262 if (!rc)
3263 rc = ata_bus_probe(ap);
3264
3265 return rc;
3266}
3267EXPORT_SYMBOL_GPL(ata_sas_port_init);
3268
3269/**
3270 * ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
3271 * @ap: SATA port to destroy
3272 *
3273 */
3274
3275void ata_sas_port_destroy(struct ata_port *ap)
3276{
3277 ap->ops->port_stop(ap);
3278 kfree(ap);
3279}
3280EXPORT_SYMBOL_GPL(ata_sas_port_destroy);
3281
3282/**
3283 * ata_sas_slave_configure - Default slave_config routine for libata devices
3284 * @sdev: SCSI device to configure
3285 * @ap: ATA port to which SCSI device is attached
3286 *
3287 * RETURNS:
3288 * Zero.
3289 */
3290
3291int ata_sas_slave_configure(struct scsi_device *sdev, struct ata_port *ap)
3292{
3293 ata_scsi_sdev_config(sdev);
3294 ata_scsi_dev_config(sdev, ap->device);
3295 return 0;
3296}
3297EXPORT_SYMBOL_GPL(ata_sas_slave_configure);
3298
3299/**
3300 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
3301 * @cmd: SCSI command to be sent
3302 * @done: Completion function, called when command is complete
3303 * @ap: ATA port to which the command is being sent
3304 *
3305 * RETURNS:
3306 * Zero.
3307 */
3308
3309int ata_sas_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *),
3310 struct ata_port *ap)
3311{
3312 ata_scsi_dump_cdb(ap, cmd);
3313
3314 if (likely(ata_scsi_dev_enabled(ap->device)))
3315 __ata_scsi_queuecmd(cmd, done, ap->device);
3316 else {
3317 cmd->result = (DID_BAD_TARGET << 16);
3318 done(cmd);
3319 }
3320 return 0;
3321}
3322EXPORT_SYMBOL_GPL(ata_sas_queuecmd);
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index c325679d9b54..d4a4f82360ec 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -69,6 +69,10 @@ extern int ata_flush_cache(struct ata_device *dev);
69extern void ata_dev_init(struct ata_device *dev); 69extern void ata_dev_init(struct ata_device *dev);
70extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); 70extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
71extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); 71extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
72extern void ata_port_init(struct ata_port *ap, struct ata_host_set *host_set,
73 const struct ata_probe_ent *ent, unsigned int port_no);
74extern struct ata_probe_ent *ata_probe_ent_alloc(struct device *dev,
75 const struct ata_port_info *port);
72 76
73 77
74/* libata-scsi.c */ 78/* libata-scsi.c */
@@ -107,6 +111,7 @@ extern void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
107 u8 *rbuf, unsigned int buflen)); 111 u8 *rbuf, unsigned int buflen));
108extern void ata_schedule_scsi_eh(struct Scsi_Host *shost); 112extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);
109extern void ata_scsi_dev_rescan(void *data); 113extern void ata_scsi_dev_rescan(void *data);
114extern int ata_bus_probe(struct ata_port *ap);
110 115
111/* libata-eh.c */ 116/* libata-eh.c */
112extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); 117extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index d0a85073ebf7..f4e262b06cf2 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -141,12 +141,8 @@ static const struct sil_drivelist {
141 { "ST330013AS", SIL_QUIRK_MOD15WRITE }, 141 { "ST330013AS", SIL_QUIRK_MOD15WRITE },
142 { "ST340017AS", SIL_QUIRK_MOD15WRITE }, 142 { "ST340017AS", SIL_QUIRK_MOD15WRITE },
143 { "ST360015AS", SIL_QUIRK_MOD15WRITE }, 143 { "ST360015AS", SIL_QUIRK_MOD15WRITE },
144 { "ST380013AS", SIL_QUIRK_MOD15WRITE },
145 { "ST380023AS", SIL_QUIRK_MOD15WRITE }, 144 { "ST380023AS", SIL_QUIRK_MOD15WRITE },
146 { "ST3120023AS", SIL_QUIRK_MOD15WRITE }, 145 { "ST3120023AS", SIL_QUIRK_MOD15WRITE },
147 { "ST3160023AS", SIL_QUIRK_MOD15WRITE },
148 { "ST3120026AS", SIL_QUIRK_MOD15WRITE },
149 { "ST3200822AS", SIL_QUIRK_MOD15WRITE },
150 { "ST340014ASL", SIL_QUIRK_MOD15WRITE }, 146 { "ST340014ASL", SIL_QUIRK_MOD15WRITE },
151 { "ST360014ASL", SIL_QUIRK_MOD15WRITE }, 147 { "ST360014ASL", SIL_QUIRK_MOD15WRITE },
152 { "ST380011ASL", SIL_QUIRK_MOD15WRITE }, 148 { "ST380011ASL", SIL_QUIRK_MOD15WRITE },