Merge tag 'm68knommu-for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / ata / libata-core.c
index f96cd2f..b8459c5 100644 (file)
@@ -159,6 +159,12 @@ MODULE_DESCRIPTION("Library module for ATA devices");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
 
+static inline bool ata_dev_print_info(struct ata_device *dev)
+{
+       struct ata_eh_context *ehc = &dev->link->eh_context;
+
+       return ehc->i.flags & ATA_EHI_PRINTINFO;
+}
 
 static bool ata_sstatus_online(u32 sstatus)
 {
@@ -706,11 +712,9 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
                if (tf->flags & ATA_TFLAG_FUA)
                        tf->device |= 1 << 7;
 
-               if (dev->flags & ATA_DFLAG_NCQ_PRIO) {
-                       if (class == IOPRIO_CLASS_RT)
-                               tf->hob_nsect |= ATA_PRIO_HIGH <<
-                                                ATA_SHIFT_PRIO;
-               }
+               if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE &&
+                   class == IOPRIO_CLASS_RT)
+                       tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO;
        } else if (dev->flags & ATA_DFLAG_LBA) {
                tf->flags |= ATA_TFLAG_LBA;
 
@@ -1266,8 +1270,7 @@ static int ata_set_max_sectors(struct ata_device *dev, u64 new_sectors)
  */
 static int ata_hpa_resize(struct ata_device *dev)
 {
-       struct ata_eh_context *ehc = &dev->link->eh_context;
-       int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
+       bool print_info = ata_dev_print_info(dev);
        bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA;
        u64 sectors = ata_id_n_sectors(dev->id);
        u64 native_sectors;
@@ -2023,13 +2026,15 @@ retry:
        err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
                                     buf, sectors * ATA_SECT_SIZE, 0);
 
-       if (err_mask && dma) {
-               dev->horkage |= ATA_HORKAGE_NO_DMA_LOG;
-               ata_dev_warn(dev, "READ LOG DMA EXT failed, trying PIO\n");
-               goto retry;
+       if (err_mask) {
+               if (dma) {
+                       dev->horkage |= ATA_HORKAGE_NO_DMA_LOG;
+                       goto retry;
+               }
+               ata_dev_err(dev, "Read log page 0x%02x failed, Emask 0x%x\n",
+                           (unsigned int)page, err_mask);
        }
 
-       DPRINTK("EXIT, err_mask=%x\n", err_mask);
        return err_mask;
 }
 
@@ -2058,12 +2063,8 @@ static bool ata_identify_page_supported(struct ata_device *dev, u8 page)
         */
        err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf,
                                1);
-       if (err) {
-               ata_dev_info(dev,
-                            "failed to get Device Identify Log Emask 0x%x\n",
-                            err);
+       if (err)
                return false;
-       }
 
        for (i = 0; i < ap->sector_buf[8]; i++) {
                if (ap->sector_buf[9 + i] == page)
@@ -2127,11 +2128,7 @@ static void ata_dev_config_ncq_send_recv(struct ata_device *dev)
        }
        err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV,
                                     0, ap->sector_buf, 1);
-       if (err_mask) {
-               ata_dev_dbg(dev,
-                           "failed to get NCQ Send/Recv Log Emask 0x%x\n",
-                           err_mask);
-       } else {
+       if (!err_mask) {
                u8 *cmds = dev->ncq_send_recv_cmds;
 
                dev->flags |= ATA_DFLAG_NCQ_SEND_RECV;
@@ -2157,11 +2154,7 @@ static void ata_dev_config_ncq_non_data(struct ata_device *dev)
        }
        err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA,
                                     0, ap->sector_buf, 1);
-       if (err_mask) {
-               ata_dev_dbg(dev,
-                           "failed to get NCQ Non-Data Log Emask 0x%x\n",
-                           err_mask);
-       } else {
+       if (!err_mask) {
                u8 *cmds = dev->ncq_non_data_cmds;
 
                memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE);
@@ -2173,30 +2166,24 @@ static void ata_dev_config_ncq_prio(struct ata_device *dev)
        struct ata_port *ap = dev->link->ap;
        unsigned int err_mask;
 
-       if (!(dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE)) {
-               dev->flags &= ~ATA_DFLAG_NCQ_PRIO;
-               return;
-       }
-
        err_mask = ata_read_log_page(dev,
                                     ATA_LOG_IDENTIFY_DEVICE,
                                     ATA_LOG_SATA_SETTINGS,
                                     ap->sector_buf,
                                     1);
-       if (err_mask) {
-               ata_dev_dbg(dev,
-                           "failed to get Identify Device data, Emask 0x%x\n",
-                           err_mask);
-               return;
-       }
+       if (err_mask)
+               goto not_supported;
 
-       if (ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)) {
-               dev->flags |= ATA_DFLAG_NCQ_PRIO;
-       } else {
-               dev->flags &= ~ATA_DFLAG_NCQ_PRIO;
-               ata_dev_dbg(dev, "SATA page does not support priority\n");
-       }
+       if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3)))
+               goto not_supported;
+
+       dev->flags |= ATA_DFLAG_NCQ_PRIO;
+
+       return;
 
+not_supported:
+       dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE;
+       dev->flags &= ~ATA_DFLAG_NCQ_PRIO;
 }
 
 static int ata_dev_config_ncq(struct ata_device *dev,
@@ -2346,11 +2333,8 @@ static void ata_dev_config_trusted(struct ata_device *dev)
 
        err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, ATA_LOG_SECURITY,
                        ap->sector_buf, 1);
-       if (err) {
-               ata_dev_dbg(dev,
-                           "failed to read Security Log, Emask 0x%x\n", err);
+       if (err)
                return;
-       }
 
        trusted_cap = get_unaligned_le64(&ap->sector_buf[40]);
        if (!(trusted_cap & (1ULL << 63))) {
@@ -2363,6 +2347,65 @@ static void ata_dev_config_trusted(struct ata_device *dev)
                dev->flags |= ATA_DFLAG_TRUSTED;
 }
 
+static int ata_dev_config_lba(struct ata_device *dev)
+{
+       struct ata_port *ap = dev->link->ap;
+       const u16 *id = dev->id;
+       const char *lba_desc;
+       char ncq_desc[24];
+       int ret;
+
+       dev->flags |= ATA_DFLAG_LBA;
+
+       if (ata_id_has_lba48(id)) {
+               lba_desc = "LBA48";
+               dev->flags |= ATA_DFLAG_LBA48;
+               if (dev->n_sectors >= (1UL << 28) &&
+                   ata_id_has_flush_ext(id))
+                       dev->flags |= ATA_DFLAG_FLUSH_EXT;
+       } else {
+               lba_desc = "LBA";
+       }
+
+       /* config NCQ */
+       ret = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
+
+       /* print device info to dmesg */
+       if (ata_msg_drv(ap) && ata_dev_print_info(dev))
+               ata_dev_info(dev,
+                            "%llu sectors, multi %u: %s %s\n",
+                            (unsigned long long)dev->n_sectors,
+                            dev->multi_count, lba_desc, ncq_desc);
+
+       return ret;
+}
+
+static void ata_dev_config_chs(struct ata_device *dev)
+{
+       struct ata_port *ap = dev->link->ap;
+       const u16 *id = dev->id;
+
+       if (ata_id_current_chs_valid(id)) {
+               /* Current CHS translation is valid. */
+               dev->cylinders = id[54];
+               dev->heads     = id[55];
+               dev->sectors   = id[56];
+       } else {
+               /* Default translation */
+               dev->cylinders  = id[1];
+               dev->heads      = id[3];
+               dev->sectors    = id[6];
+       }
+
+       /* print device info to dmesg */
+       if (ata_msg_drv(ap) && ata_dev_print_info(dev))
+               ata_dev_info(dev,
+                            "%llu sectors, multi %u, CHS %u/%u/%u\n",
+                            (unsigned long long)dev->n_sectors,
+                            dev->multi_count, dev->cylinders,
+                            dev->heads, dev->sectors);
+}
+
 static void ata_dev_config_devslp(struct ata_device *dev)
 {
        u8 *sata_setting = dev->link->ap->sector_buf;
@@ -2380,12 +2423,8 @@ static void ata_dev_config_devslp(struct ata_device *dev)
                                     ATA_LOG_IDENTIFY_DEVICE,
                                     ATA_LOG_SATA_SETTINGS,
                                     sata_setting, 1);
-       if (err_mask) {
-               ata_dev_dbg(dev,
-                           "failed to get SATA Settings Log, Emask 0x%x\n",
-                           err_mask);
+       if (err_mask)
                return;
-       }
 
        dev->flags |= ATA_DFLAG_DEVSLP;
        for (i = 0; i < ATA_LOG_DEVSLP_SIZE; i++) {
@@ -2394,6 +2433,20 @@ static void ata_dev_config_devslp(struct ata_device *dev)
        }
 }
 
+static void ata_dev_print_features(struct ata_device *dev)
+{
+       if (!(dev->flags & ATA_DFLAG_FEATURES_MASK))
+               return;
+
+       ata_dev_info(dev,
+                    "Features:%s%s%s%s%s\n",
+                    dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "",
+                    dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "",
+                    dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "",
+                    dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "",
+                    dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "");
+}
+
 /**
  *     ata_dev_configure - Configure the specified ATA/ATAPI device
  *     @dev: Target device to configure
@@ -2410,8 +2463,7 @@ static void ata_dev_config_devslp(struct ata_device *dev)
 int ata_dev_configure(struct ata_device *dev)
 {
        struct ata_port *ap = dev->link->ap;
-       struct ata_eh_context *ehc = &dev->link->eh_context;
-       int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
+       bool print_info = ata_dev_print_info(dev);
        const u16 *id = dev->id;
        unsigned long xfer_mask;
        unsigned int err_mask;
@@ -2538,62 +2590,18 @@ int ata_dev_configure(struct ata_device *dev)
                                        dev->multi_count = cnt;
                }
 
-               if (ata_id_has_lba(id)) {
-                       const char *lba_desc;
-                       char ncq_desc[24];
-
-                       lba_desc = "LBA";
-                       dev->flags |= ATA_DFLAG_LBA;
-                       if (ata_id_has_lba48(id)) {
-                               dev->flags |= ATA_DFLAG_LBA48;
-                               lba_desc = "LBA48";
-
-                               if (dev->n_sectors >= (1UL << 28) &&
-                                   ata_id_has_flush_ext(id))
-                                       dev->flags |= ATA_DFLAG_FLUSH_EXT;
-                       }
+               /* print device info to dmesg */
+               if (ata_msg_drv(ap) && print_info)
+                       ata_dev_info(dev, "%s: %s, %s, max %s\n",
+                                    revbuf, modelbuf, fwrevbuf,
+                                    ata_mode_string(xfer_mask));
 
-                       /* config NCQ */
-                       rc = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
+               if (ata_id_has_lba(id)) {
+                       rc = ata_dev_config_lba(dev);
                        if (rc)
                                return rc;
-
-                       /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info) {
-                               ata_dev_info(dev, "%s: %s, %s, max %s\n",
-                                            revbuf, modelbuf, fwrevbuf,
-                                            ata_mode_string(xfer_mask));
-                               ata_dev_info(dev,
-                                            "%llu sectors, multi %u: %s %s\n",
-                                       (unsigned long long)dev->n_sectors,
-                                       dev->multi_count, lba_desc, ncq_desc);
-                       }
                } else {
-                       /* CHS */
-
-                       /* Default translation */
-                       dev->cylinders  = id[1];
-                       dev->heads      = id[3];
-                       dev->sectors    = id[6];
-
-                       if (ata_id_current_chs_valid(id)) {
-                               /* Current CHS translation is valid. */
-                               dev->cylinders = id[54];
-                               dev->heads     = id[55];
-                               dev->sectors   = id[56];
-                       }
-
-                       /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info) {
-                               ata_dev_info(dev, "%s: %s, %s, max %s\n",
-                                            revbuf,    modelbuf, fwrevbuf,
-                                            ata_mode_string(xfer_mask));
-                               ata_dev_info(dev,
-                                            "%llu sectors, multi %u, CHS %u/%u/%u\n",
-                                            (unsigned long long)dev->n_sectors,
-                                            dev->multi_count, dev->cylinders,
-                                            dev->heads, dev->sectors);
-                       }
+                       ata_dev_config_chs(dev);
                }
 
                ata_dev_config_devslp(dev);
@@ -2601,6 +2609,9 @@ int ata_dev_configure(struct ata_device *dev)
                ata_dev_config_zac(dev);
                ata_dev_config_trusted(dev);
                dev->cdb_len = 32;
+
+               if (ata_msg_drv(ap) && print_info)
+                       ata_dev_print_features(dev);
        }
 
        /* ATAPI-specific feature tests */