10 #include <linux/kernel.h>
11 #include <linux/export.h>
13 #include <linux/slab.h>
44 unsigned int err_mask;
46 ata_tf_init(pmp_dev, &
tf);
51 tf.device = link->
pmp;
58 *r_val =
tf.nsect |
tf.lbal << 8 |
tf.lbam << 16 |
tf.lbah << 24;
76 static unsigned int sata_pmp_write(
struct ata_link *link,
int reg,
u32 val)
82 ata_tf_init(pmp_dev, &
tf);
87 tf.device = link->
pmp;
88 tf.nsect = val & 0xff;
89 tf.lbal = (val >> 8) & 0xff;
90 tf.lbam = (val >> 16) & 0xff;
91 tf.lbah = (val >> 24) & 0xff;
144 unsigned int err_mask;
149 err_mask = sata_pmp_read(link, reg, r_val);
175 unsigned int err_mask;
180 err_mask = sata_pmp_write(link, reg, val);
226 static const int gscr_to_read[] = { 0, 1, 2, 32, 33, 64, 96 };
229 for (i = 0; i <
ARRAY_SIZE(gscr_to_read); i++) {
230 int reg = gscr_to_read[
i];
231 unsigned int err_mask;
233 err_mask = sata_pmp_read(dev->
link, reg, &gscr[reg]);
235 ata_dev_err(dev,
"failed to read PMP GSCR[%d] (Emask=0x%x)\n",
244 static const char *sata_pmp_spec_rev_str(
const u32 *gscr)
257 #define PMP_GSCR_SII_POL 129
265 unsigned int err_mask = 0;
273 reason =
"invalid nr_ports";
286 reason =
"failed to write GSCR_ERROR_EN";
296 if (vendor == 0x1095 && devid == 0x3726) {
302 reason =
"failed to read Sil3726 Private Register";
309 reason =
"failed to write Sil3726 Private Register";
316 "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
317 sata_pmp_spec_rev_str(gscr), vendor, devid,
324 "Asynchronous notification not supported, "
325 "hotplug won't work on fan-out ports. Use warm-plug instead.\n");
332 "failed to configure Port Multiplier (%s, Emask=0x%x)\n",
337 static int sata_pmp_init_links (
struct ata_port *ap,
int nr_ports)
361 for (i = 0; i < nr_ports; i++) {
379 static void sata_pmp_quirks(
struct ata_port *ap)
381 u32 *gscr = ap->
link.device->gscr;
386 if (vendor == 0x1095 && devid == 0x3726) {
401 }
else if (vendor == 0x1095 && devid == 0x4723) {
416 }
else if (vendor == 0x1095 && devid == 0x4726) {
438 }
else if (vendor == 0x1095 && (devid == 0x5723 || devid == 0x5733 ||
439 devid == 0x5734 || devid == 0x5744)) {
449 }
else if (vendor == 0x197b && devid == 0x2352) {
484 if (!sata_pmp_supported(ap)) {
485 ata_dev_err(dev,
"host does not support Port Multiplier\n");
489 if (!ata_is_host_link(link)) {
490 ata_dev_err(dev,
"Port Multipliers cannot be nested\n");
495 ata_dev_err(dev,
"Port Multiplier must be the first device\n");
503 rc = sata_pmp_read_gscr(dev, dev->
gscr);
508 rc = sata_pmp_configure(dev, 1);
522 spin_unlock_irqrestore(ap->
lock, flags);
526 if (ap->
ops->pmp_attach)
527 ap->
ops->pmp_attach(ap);
549 static void sata_pmp_detach(
struct ata_device *dev)
561 if (ap->
ops->pmp_detach)
562 ap->
ops->pmp_detach(ap);
568 ap->nr_pmp_links = 0;
570 spin_unlock_irqrestore(ap->lock, flags);
589 const u32 *old_gscr = dev->gscr;
590 u16 old_vendor, new_vendor, old_devid, new_devid;
591 int old_nr_ports, new_nr_ports;
600 if (old_vendor != new_vendor) {
602 "Port Multiplier vendor mismatch '0x%x' != '0x%x'\n",
603 old_vendor, new_vendor);
607 if (old_devid != new_devid) {
609 "Port Multiplier device ID mismatch '0x%x' != '0x%x'\n",
610 old_devid, new_devid);
614 if (old_nr_ports != new_nr_ports) {
616 "Port Multiplier nr_ports mismatch '0x%x' != '0x%x'\n",
617 old_nr_ports, new_nr_ports);
638 static int sata_pmp_revalidate(
struct ata_device *dev,
unsigned int new_class)
642 u32 *gscr = (
void *)ap->sector_buf;
649 if (!ata_dev_enabled(dev)) {
655 if (ata_class_enabled(new_class) && new_class !=
ATA_DEV_PMP) {
661 rc = sata_pmp_read_gscr(dev, gscr);
666 if (!sata_pmp_same_pmp(dev, gscr)) {
673 rc = sata_pmp_configure(dev, 0);
683 ata_dev_err(dev,
"PMP revalidation failed (errno=%d)\n",
rc);
700 static int sata_pmp_revalidate_quick(
struct ata_device *dev)
702 unsigned int err_mask;
708 "failed to read PMP product ID (Emask=0x%x)\n",
741 static int sata_pmp_eh_recover_pmp(
struct ata_port *ap,
749 int detach = 0,
rc = 0;
750 int reval_failed = 0;
786 rc = sata_pmp_revalidate(dev, ehc->
classes[0]);
788 rc = sata_pmp_revalidate_quick(dev);
797 tries =
min(tries, 2);
811 "failed to recover PMP after %d tries, giving up\n",
824 sata_pmp_detach(dev);
834 static int sata_pmp_eh_handle_disabled_links(
struct ata_port *ap)
846 spin_unlock_irqrestore(ap->
lock, flags);
859 "failed to clear SError.N (errno=%d)\n",
867 spin_unlock_irqrestore(ap->
lock, flags);
872 static int sata_pmp_handle_link_fail(
struct ata_link *link,
int *link_tries)
877 if (link_tries[link->
pmp] && --link_tries[link->
pmp])
883 "failed to recover link after %d tries, disabling\n",
888 spin_unlock_irqrestore(ap->
lock, flags);
912 static int sata_pmp_eh_recover(
struct ata_port *ap)
922 unsigned int err_mask;
923 u32 gscr_error, sntf;
932 if (!sata_pmp_attached(ap)) {
946 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
952 rc = sata_pmp_eh_recover_pmp(ap, ops->prereset, ops->softreset,
953 ops->hardreset, ops->postreset);
967 "failed to disable NOTIFY (err_mask=0x%x)\n",
974 rc = sata_pmp_eh_handle_disabled_links(ap);
1011 "failed to write PMP_FEAT_EN (Emask=0x%x)\n",
1022 "failed to read PMP_GSCR_ERROR (Emask=0x%x)\n",
1030 if (!(gscr_error & (1 << link->pmp)))
1033 if (sata_pmp_handle_link_fail(link, link_tries)) {
1034 ata_ehi_hotplugged(&link->eh_context.i);
1038 "PHY status changed but maxed out on retries, giving up\n");
1040 "Manually issue scan to resume this link\n");
1046 "PMP SError.N set for some ports, repeating recovery\n");
1053 if (sata_pmp_handle_link_fail(link, link_tries)) {
1066 if (!sata_pmp_attached(ap))
1074 ata_port_err(ap,
"failed to recover PMP after %d tries, giving up\n",
1076 sata_pmp_detach(pmp_dev);
1096 sata_pmp_eh_recover(ap);