Skip to content

Commit 633273a

Browse files
htejunJeff Garzik
authored and
Jeff Garzik
committed
libata-pmp: hook PMP support and enable it
Hook PMP support into libata and enable it. Connect SCR and probing functions, and update ata_dev_classify() to detect PMP. Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Jeff Garzik <[email protected]>
1 parent 3af9a77 commit 633273a

File tree

3 files changed

+96
-35
lines changed

3 files changed

+96
-35
lines changed

drivers/ata/libata-core.c

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -670,29 +670,49 @@ static unsigned int ata_devchk(struct ata_port *ap, unsigned int device)
670670
* None.
671671
*
672672
* RETURNS:
673-
* Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, or %ATA_DEV_UNKNOWN
674-
* the event of failure.
673+
* Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP or
674+
* %ATA_DEV_UNKNOWN the event of failure.
675675
*/
676-
677676
unsigned int ata_dev_classify(const struct ata_taskfile *tf)
678677
{
679678
/* Apple's open source Darwin code hints that some devices only
680679
* put a proper signature into the LBA mid/high registers,
681680
* So, we only check those. It's sufficient for uniqueness.
681+
*
682+
* ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate
683+
* signatures for ATA and ATAPI devices attached on SerialATA,
684+
* 0x3c/0xc3 and 0x69/0x96 respectively. However, SerialATA
685+
* spec has never mentioned about using different signatures
686+
* for ATA/ATAPI devices. Then, Serial ATA II: Port
687+
* Multiplier specification began to use 0x69/0x96 to identify
688+
* port multpliers and 0x3c/0xc3 to identify SEMB device.
689+
* ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and
690+
* 0x69/0x96 shortly and described them as reserved for
691+
* SerialATA.
692+
*
693+
* We follow the current spec and consider that 0x69/0x96
694+
* identifies a port multiplier and 0x3c/0xc3 a SEMB device.
682695
*/
683-
684-
if (((tf->lbam == 0) && (tf->lbah == 0)) ||
685-
((tf->lbam == 0x3c) && (tf->lbah == 0xc3))) {
696+
if ((tf->lbam == 0) && (tf->lbah == 0)) {
686697
DPRINTK("found ATA device by sig\n");
687698
return ATA_DEV_ATA;
688699
}
689700

690-
if (((tf->lbam == 0x14) && (tf->lbah == 0xeb)) ||
691-
((tf->lbam == 0x69) && (tf->lbah == 0x96))) {
701+
if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) {
692702
DPRINTK("found ATAPI device by sig\n");
693703
return ATA_DEV_ATAPI;
694704
}
695705

706+
if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) {
707+
DPRINTK("found PMP device by sig\n");
708+
return ATA_DEV_PMP;
709+
}
710+
711+
if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) {
712+
printk("ata: SEMB device ignored\n");
713+
return ATA_DEV_SEMB_UNSUP; /* not yet */
714+
}
715+
696716
DPRINTK("unknown device\n");
697717
return ATA_DEV_UNKNOWN;
698718
}
@@ -3426,6 +3446,12 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline)
34263446
(link->flags & ATA_LFLAG_HRST_TO_RESUME))
34273447
ehc->i.action |= ATA_EH_HARDRESET;
34283448

3449+
/* Some PMPs don't work with only SRST, force hardreset if PMP
3450+
* is supported.
3451+
*/
3452+
if (ap->flags & ATA_FLAG_PMP)
3453+
ehc->i.action |= ATA_EH_HARDRESET;
3454+
34293455
/* if we're about to do hardreset, nothing more to do */
34303456
if (ehc->i.action & ATA_EH_HARDRESET)
34313457
return 0;
@@ -3616,6 +3642,16 @@ int sata_std_hardreset(struct ata_link *link, unsigned int *class,
36163642
/* wait a while before checking status, see SRST for more info */
36173643
msleep(150);
36183644

3645+
/* If PMP is supported, we have to do follow-up SRST. Note
3646+
* that some PMPs don't send D2H Reg FIS after hardreset at
3647+
* all if the first port is empty. Wait for it just for a
3648+
* second and request follow-up SRST.
3649+
*/
3650+
if (ap->flags & ATA_FLAG_PMP) {
3651+
ata_wait_ready(ap, jiffies + HZ);
3652+
return -EAGAIN;
3653+
}
3654+
36193655
rc = ata_wait_ready(ap, deadline);
36203656
/* link occupied, -ENODEV too is an error */
36213657
if (rc) {
@@ -5966,22 +6002,26 @@ int sata_scr_valid(struct ata_link *link)
59666002
* @val: Place to store read value
59676003
*
59686004
* Read SCR register @reg of @link into *@val. This function is
5969-
* guaranteed to succeed if the cable type of the port is SATA
5970-
* and the port implements ->scr_read.
6005+
* guaranteed to succeed if @link is ap->link, the cable type of
6006+
* the port is SATA and the port implements ->scr_read.
59716007
*
59726008
* LOCKING:
5973-
* None.
6009+
* None if @link is ap->link. Kernel thread context otherwise.
59746010
*
59756011
* RETURNS:
59766012
* 0 on success, negative errno on failure.
59776013
*/
59786014
int sata_scr_read(struct ata_link *link, int reg, u32 *val)
59796015
{
5980-
struct ata_port *ap = link->ap;
6016+
if (ata_is_host_link(link)) {
6017+
struct ata_port *ap = link->ap;
59816018

5982-
if (sata_scr_valid(link))
5983-
return ap->ops->scr_read(ap, reg, val);
5984-
return -EOPNOTSUPP;
6019+
if (sata_scr_valid(link))
6020+
return ap->ops->scr_read(ap, reg, val);
6021+
return -EOPNOTSUPP;
6022+
}
6023+
6024+
return sata_pmp_scr_read(link, reg, val);
59856025
}
59866026

59876027
/**
@@ -5991,22 +6031,26 @@ int sata_scr_read(struct ata_link *link, int reg, u32 *val)
59916031
* @val: value to write
59926032
*
59936033
* Write @val to SCR register @reg of @link. This function is
5994-
* guaranteed to succeed if the cable type of the port is SATA
5995-
* and the port implements ->scr_read.
6034+
* guaranteed to succeed if @link is ap->link, the cable type of
6035+
* the port is SATA and the port implements ->scr_read.
59966036
*
59976037
* LOCKING:
5998-
* None.
6038+
* None if @link is ap->link. Kernel thread context otherwise.
59996039
*
60006040
* RETURNS:
60016041
* 0 on success, negative errno on failure.
60026042
*/
60036043
int sata_scr_write(struct ata_link *link, int reg, u32 val)
60046044
{
6005-
struct ata_port *ap = link->ap;
6045+
if (ata_is_host_link(link)) {
6046+
struct ata_port *ap = link->ap;
60066047

6007-
if (sata_scr_valid(link))
6008-
return ap->ops->scr_write(ap, reg, val);
6009-
return -EOPNOTSUPP;
6048+
if (sata_scr_valid(link))
6049+
return ap->ops->scr_write(ap, reg, val);
6050+
return -EOPNOTSUPP;
6051+
}
6052+
6053+
return sata_pmp_scr_write(link, reg, val);
60106054
}
60116055

60126056
/**
@@ -6019,23 +6063,27 @@ int sata_scr_write(struct ata_link *link, int reg, u32 val)
60196063
* function performs flush after writing to the register.
60206064
*
60216065
* LOCKING:
6022-
* None.
6066+
* None if @link is ap->link. Kernel thread context otherwise.
60236067
*
60246068
* RETURNS:
60256069
* 0 on success, negative errno on failure.
60266070
*/
60276071
int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
60286072
{
6029-
struct ata_port *ap = link->ap;
6030-
int rc;
6073+
if (ata_is_host_link(link)) {
6074+
struct ata_port *ap = link->ap;
6075+
int rc;
60316076

6032-
if (sata_scr_valid(link)) {
6033-
rc = ap->ops->scr_write(ap, reg, val);
6034-
if (rc == 0)
6035-
rc = ap->ops->scr_read(ap, reg, &val);
6036-
return rc;
6077+
if (sata_scr_valid(link)) {
6078+
rc = ap->ops->scr_write(ap, reg, val);
6079+
if (rc == 0)
6080+
rc = ap->ops->scr_read(ap, reg, &val);
6081+
return rc;
6082+
}
6083+
return -EOPNOTSUPP;
60376084
}
6038-
return -EOPNOTSUPP;
6085+
6086+
return sata_pmp_scr_write(link, reg, val);
60396087
}
60406088

60416089
/**
@@ -6424,6 +6472,7 @@ static void ata_host_release(struct device *gendev, void *res)
64246472
if (ap->scsi_host)
64256473
scsi_host_put(ap->scsi_host);
64266474

6475+
kfree(ap->pmp_link);
64276476
kfree(ap);
64286477
host->ports[i] = NULL;
64296478
}

drivers/ata/libata-eh.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,6 +2209,8 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
22092209
readid_flags |= ATA_READID_POSTRESET;
22102210

22112211
if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
2212+
WARN_ON(dev->class == ATA_DEV_PMP);
2213+
22122214
if (ata_link_offline(link)) {
22132215
rc = -EIO;
22142216
goto err;
@@ -2234,8 +2236,11 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
22342236
ata_class_enabled(ehc->classes[dev->devno])) {
22352237
dev->class = ehc->classes[dev->devno];
22362238

2237-
rc = ata_dev_read_id(dev, &dev->class, readid_flags,
2238-
dev->id);
2239+
if (dev->class == ATA_DEV_PMP)
2240+
rc = sata_pmp_attach(dev);
2241+
else
2242+
rc = ata_dev_read_id(dev, &dev->class,
2243+
readid_flags, dev->id);
22392244
switch (rc) {
22402245
case 0:
22412246
new_mask |= 1 << dev->devno;
@@ -2264,7 +2269,8 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
22642269
* device detection messages backwards.
22652270
*/
22662271
ata_link_for_each_dev(dev, link) {
2267-
if (!(new_mask & (1 << dev->devno)))
2272+
if (!(new_mask & (1 << dev->devno)) ||
2273+
dev->class == ATA_DEV_PMP)
22682274
continue;
22692275

22702276
ehc->i.flags |= ATA_EHI_PRINTINFO;
@@ -2521,6 +2527,12 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
25212527
if (rc)
25222528
goto dev_fail;
25232529

2530+
/* if PMP got attached, return, pmp EH will take care of it */
2531+
if (link->device->class == ATA_DEV_PMP) {
2532+
ehc->i.action = 0;
2533+
return 0;
2534+
}
2535+
25242536
/* configure transfer mode if necessary */
25252537
if (ehc->i.flags & ATA_EHI_SETMODE) {
25262538
rc = ata_set_mode(link, &dev);

drivers/ata/libata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define __LIBATA_H__
3030

3131
#define DRV_NAME "libata"
32-
#define DRV_VERSION "2.21" /* must be exactly four chars */
32+
#define DRV_VERSION "3.00" /* must be exactly four chars */
3333

3434
struct ata_scsi_args {
3535
struct ata_device *dev;

0 commit comments

Comments
 (0)