]> err.no Git - linux-2.6/blobdiff - drivers/scsi/libata-core.c
[PATCH] md: Set/get state of array via sysfs
[linux-2.6] / drivers / scsi / libata-core.c
index ddaad1a4f1f132c1f0ae9b65fd79edb9bf09d1b7..6c66877be2bffe069b7663fc756fb176ed092003 100644 (file)
@@ -418,7 +418,7 @@ static const char *sata_spd_string(unsigned int spd)
 
 void ata_dev_disable(struct ata_device *dev)
 {
-       if (ata_dev_enabled(dev)) {
+       if (ata_dev_enabled(dev) && ata_msg_drv(dev->ap)) {
                ata_dev_printk(dev, KERN_WARNING, "disabled\n");
                dev->class++;
        }
@@ -777,8 +777,11 @@ void ata_std_dev_select (struct ata_port *ap, unsigned int device)
 void ata_dev_select(struct ata_port *ap, unsigned int device,
                           unsigned int wait, unsigned int can_sleep)
 {
-       VPRINTK("ENTER, ata%u: device %u, wait %u\n",
-               ap->id, device, wait);
+       if (ata_msg_probe(ap)) {
+               ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, ata%u: "
+                               "device %u, wait %u\n",
+                               ap->id, device, wait);
+       }
 
        if (wait)
                ata_wait_idle(ap);
@@ -933,9 +936,9 @@ void ata_port_flush_task(struct ata_port *ap)
 
        DPRINTK("ENTER\n");
 
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
        ap->flags |= ATA_FLAG_FLUSH_PORT_TASK;
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        DPRINTK("flush #1\n");
        flush_workqueue(ata_wq);
@@ -946,15 +949,17 @@ void ata_port_flush_task(struct ata_port *ap)
         * Cancel and flush.
         */
        if (!cancel_delayed_work(&ap->port_task)) {
-               DPRINTK("flush #2\n");
+               if (ata_msg_ctl(ap))
+                       ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n", __FUNCTION__);
                flush_workqueue(ata_wq);
        }
 
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
        ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK;
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
-       DPRINTK("EXIT\n");
+       if (ata_msg_ctl(ap))
+               ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__);
 }
 
 void ata_qc_complete_internal(struct ata_queued_cmd *qc)
@@ -981,8 +986,10 @@ void ata_qc_complete_internal(struct ata_queued_cmd *qc)
  *
  *     LOCKING:
  *     None.  Should be called with kernel context, might sleep.
+ *
+ *     RETURNS:
+ *     Zero on success, AC_ERR_* mask on failure
  */
-
 unsigned ata_exec_internal(struct ata_device *dev,
                           struct ata_taskfile *tf, const u8 *cdb,
                           int dma_dir, void *buf, unsigned int buflen)
@@ -997,11 +1004,11 @@ unsigned ata_exec_internal(struct ata_device *dev,
        unsigned int err_mask;
        int rc;
 
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
 
        /* no internal command while frozen */
        if (ap->flags & ATA_FLAG_FROZEN) {
-               spin_unlock_irqrestore(&ap->host_set->lock, flags);
+               spin_unlock_irqrestore(ap->lock, flags);
                return AC_ERR_SYSTEM;
        }
 
@@ -1050,14 +1057,14 @@ unsigned ata_exec_internal(struct ata_device *dev,
 
        ata_qc_issue(qc);
 
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        rc = wait_for_completion_timeout(&wait, ATA_TMOUT_INTERNAL);
 
        ata_port_flush_task(ap);
 
        if (!rc) {
-               spin_lock_irqsave(&ap->host_set->lock, flags);
+               spin_lock_irqsave(ap->lock, flags);
 
                /* We're racing with irq here.  If we lose, the
                 * following test prevents us from completing the qc
@@ -1072,11 +1079,12 @@ unsigned ata_exec_internal(struct ata_device *dev,
                        else
                                ata_qc_complete(qc);
 
-                       ata_dev_printk(dev, KERN_WARNING,
+                       if (ata_msg_warn(ap))
+                               ata_dev_printk(dev, KERN_WARNING,
                                       "qc timeout (cmd 0x%x)\n", command);
                }
 
-               spin_unlock_irqrestore(&ap->host_set->lock, flags);
+               spin_unlock_irqrestore(ap->lock, flags);
        }
 
        /* do post_internal_cmd */
@@ -1084,13 +1092,15 @@ unsigned ata_exec_internal(struct ata_device *dev,
                ap->ops->post_internal_cmd(qc);
 
        if (qc->flags & ATA_QCFLAG_FAILED && !qc->err_mask) {
-               ata_dev_printk(dev, KERN_WARNING, "zero err_mask for failed "
+               if (ata_msg_warn(ap))
+                       ata_dev_printk(dev, KERN_WARNING, 
+                               "zero err_mask for failed "
                               "internal command, assuming AC_ERR_OTHER\n");
                qc->err_mask |= AC_ERR_OTHER;
        }
 
        /* finish up */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
 
        *tf = qc->result_tf;
        err_mask = qc->err_mask;
@@ -1116,7 +1126,7 @@ unsigned ata_exec_internal(struct ata_device *dev,
                ata_port_probe(ap);
        }
 
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        return err_mask;
 }
@@ -1182,7 +1192,9 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        const char *reason;
        int rc;
 
-       DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
+       if (ata_msg_ctl(ap))
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 
+                               __FUNCTION__, ap->id, dev->devno);
 
        ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
 
@@ -1251,7 +1263,8 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        return 0;
 
  err_out:
-       ata_dev_printk(dev, KERN_WARNING, "failed to IDENTIFY "
+       if (ata_msg_warn(ap)) 
+               ata_dev_printk(dev, KERN_WARNING, "failed to IDENTIFY "
                       "(%s, err_mask=0x%x)\n", reason, err_mask);
        return rc;
 }
@@ -1304,18 +1317,21 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
        unsigned int xfer_mask;
        int i, rc;
 
-       if (!ata_dev_enabled(dev)) {
-               DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n",
-                       ap->id, dev->devno);
+       if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
+               ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT (host %u, dev %u) -- nodev\n",
+                       __FUNCTION__, ap->id, dev->devno);
                return 0;
        }
 
-       DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
+       if (ata_msg_probe(ap))
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n", 
+                       __FUNCTION__, ap->id, dev->devno);
 
        /* print device capabilities */
-       if (print_info)
-               ata_dev_printk(dev, KERN_DEBUG, "cfg 49:%04x 82:%04x 83:%04x "
+       if (ata_msg_probe(ap))
+               ata_dev_printk(dev, KERN_DEBUG, "%s: cfg 49:%04x 82:%04x 83:%04x "
                               "84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n",
+                              __FUNCTION__,
                               id[49], id[82], id[83], id[84],
                               id[85], id[86], id[87], id[88]);
 
@@ -1335,7 +1351,8 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
        /* find max transfer mode; for printk only */
        xfer_mask = ata_id_xfermask(id);
 
-       ata_dump_id(id);
+       if (ata_msg_probe(ap))
+               ata_dump_id(id);
 
        /* ATA-specific feature tests */
        if (dev->class == ATA_DEV_ATA) {
@@ -1356,7 +1373,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                        ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
 
                        /* print device info to dmesg */
-                       if (print_info)
+                       if (ata_msg_info(ap))
                                ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
                                        "max %s, %Lu sectors: %s %s\n",
                                        ata_id_major_version(id),
@@ -1379,7 +1396,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                        }
 
                        /* print device info to dmesg */
-                       if (print_info)
+                       if (ata_msg_info(ap))
                                ata_dev_printk(dev, KERN_INFO, "ATA-%d, "
                                        "max %s, %Lu sectors: CHS %u/%u/%u\n",
                                        ata_id_major_version(id),
@@ -1390,7 +1407,8 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
 
                if (dev->id[59] & 0x100) {
                        dev->multi_count = dev->id[59] & 0xff;
-                       DPRINTK("ata%u: dev %u multi count %u\n",
+                       if (ata_msg_info(ap))
+                               ata_dev_printk(dev, KERN_INFO, "ata%u: dev %u multi count %u\n",
                                ap->id, dev->devno, dev->multi_count);
                }
 
@@ -1403,8 +1421,9 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
 
                rc = atapi_cdb_len(id);
                if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
-                       ata_dev_printk(dev, KERN_WARNING,
-                                      "unsupported CDB len\n");
+                       if (ata_msg_warn(ap))
+                               ata_dev_printk(dev, KERN_WARNING, 
+                                       "unsupported CDB len\n");
                        rc = -EINVAL;
                        goto err_out_nosup;
                }
@@ -1416,7 +1435,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
                }
 
                /* print device info to dmesg */
-               if (print_info)
+               if (ata_msg_info(ap))
                        ata_dev_printk(dev, KERN_INFO, "ATAPI, max %s%s\n",
                                       ata_mode_string(xfer_mask),
                                       cdb_intr_string);
@@ -1430,7 +1449,7 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
 
        /* limit bridge transfers to udma5, 200 sectors */
        if (ata_dev_knobble(dev)) {
-               if (print_info)
+               if (ata_msg_info(ap))
                        ata_dev_printk(dev, KERN_INFO,
                                       "applying bridge limits\n");
                dev->udma_mask &= ATA_UDMA5;
@@ -1440,11 +1459,15 @@ int ata_dev_configure(struct ata_device *dev, int print_info)
        if (ap->ops->dev_config)
                ap->ops->dev_config(ap, dev);
 
-       DPRINTK("EXIT, drv_stat = 0x%x\n", ata_chk_status(ap));
+       if (ata_msg_probe(ap))
+               ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n",
+                       __FUNCTION__, ata_chk_status(ap));
        return 0;
 
 err_out_nosup:
-       DPRINTK("EXIT, err\n");
+       if (ata_msg_probe(ap))
+               ata_dev_printk(dev, KERN_DEBUG, 
+                               "%s: EXIT, err\n", __FUNCTION__);
        return rc;
 }
 
@@ -2941,6 +2964,14 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
        unsigned int nlen, rlen;
        int i;
 
+       /* We don't support polling DMA.
+        * DMA blacklist those ATAPI devices with CDB-intr (and use PIO)
+        * if the LLDD handles only interrupts in the HSM_ST_LAST state.
+        */
+       if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) &&
+           (dev->flags & ATA_DFLAG_CDB_INTR))
+               return 1;
+
        ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS,
                          sizeof(model_num));
        ata_id_string(dev->id, model_rev, ATA_ID_FW_REV_OFS,
@@ -3233,15 +3264,6 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
        if (ap->ops->check_atapi_dma)
                rc = ap->ops->check_atapi_dma(qc);
 
-       /* We don't support polling DMA.
-        * Use PIO if the LLDD handles only interrupts in
-        * the HSM_ST_LAST state and the ATAPI device
-        * generates CDB interrupts.
-        */
-       if ((ap->flags & ATA_FLAG_PIO_POLLING) &&
-           (qc->dev->flags & ATA_DFLAG_CDB_INTR))
-               rc = 1;
-
        return rc;
 }
 /**
@@ -3494,7 +3516,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
 
 /**
  *     ata_mmio_data_xfer - Transfer data by MMIO
- *     @dev: device for this I/O
+ *     @adev: device for this I/O
  *     @buf: data buffer
  *     @buflen: buffer length
  *     @write_data: read/write
@@ -3911,7 +3933,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
 
        if (ap->ops->error_handler) {
                if (in_wq) {
-                       spin_lock_irqsave(&ap->host_set->lock, flags);
+                       spin_lock_irqsave(ap->lock, flags);
 
                        /* EH might have kicked in while host_set lock
                         * is released.
@@ -3925,7 +3947,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
                                        ata_port_freeze(ap);
                        }
 
-                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+                       spin_unlock_irqrestore(ap->lock, flags);
                } else {
                        if (likely(!(qc->err_mask & AC_ERR_HSM)))
                                ata_qc_complete(qc);
@@ -3934,10 +3956,10 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
                }
        } else {
                if (in_wq) {
-                       spin_lock_irqsave(&ap->host_set->lock, flags);
+                       spin_lock_irqsave(ap->lock, flags);
                        ata_irq_on(ap);
                        ata_qc_complete(qc);
-                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+                       spin_unlock_irqrestore(ap->lock, flags);
                } else
                        ata_qc_complete(qc);
        }
@@ -4017,7 +4039,7 @@ fsm_start:
                 * hsm_task_state is changed. Hence, the following locking.
                 */
                if (in_wq)
-                       spin_lock_irqsave(&ap->host_set->lock, flags);
+                       spin_lock_irqsave(ap->lock, flags);
 
                if (qc->tf.protocol == ATA_PROT_PIO) {
                        /* PIO data out protocol.
@@ -4036,7 +4058,7 @@ fsm_start:
                        atapi_send_cdb(ap, qc);
 
                if (in_wq)
-                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+                       spin_unlock_irqrestore(ap->lock, flags);
 
                /* if polling, ata_pio_task() handles the rest.
                 * otherwise, interrupt handler takes over from here.
@@ -4549,7 +4571,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
                        break;
                case ATA_PROT_ATAPI_DMA:
                        if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
-                               /* see ata_check_atapi_dma() */
+                               /* see ata_dma_blacklisted() */
                                BUG();
                        break;
                default:
@@ -4988,6 +5010,7 @@ int ata_device_resume(struct ata_device *dev)
        if (ap->flags & ATA_FLAG_SUSPENDED) {
                struct ata_device *failed_dev;
 
+               ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
                ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 200000);
 
                ap->flags &= ~ATA_FLAG_SUSPENDED;
@@ -5128,9 +5151,9 @@ void ata_dev_init(struct ata_device *dev)
         * requests which occur asynchronously.  Synchronize using
         * host_set lock.
         */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
        dev->flags &= ~ATA_DFLAG_INIT_MASK;
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        memset((void *)dev + ATA_DEVICE_CLEAR_OFFSET, 0,
               sizeof(*dev) - ATA_DEVICE_CLEAR_OFFSET);
@@ -5165,6 +5188,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
        host->unique_id = ata_unique_id++;
        host->max_cmd_len = 12;
 
+       ap->lock = &host_set->lock;
        ap->flags = ATA_FLAG_DISABLED;
        ap->id = host->unique_id;
        ap->host = host;
@@ -5189,7 +5213,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
 #elif defined(ATA_DEBUG)
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_INFO | ATA_MSG_CTL | ATA_MSG_WARN | ATA_MSG_ERR;
 #else 
-       ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR;
+       ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
        INIT_WORK(&ap->port_task, NULL, NULL);
@@ -5386,7 +5410,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
                        ata_port_probe(ap);
 
                        /* kick EH for boot probing */
-                       spin_lock_irqsave(&ap->host_set->lock, flags);
+                       spin_lock_irqsave(ap->lock, flags);
 
                        ap->eh_info.probe_mask = (1 << ATA_MAX_DEVICES) - 1;
                        ap->eh_info.action |= ATA_EH_SOFTRESET;
@@ -5394,7 +5418,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
                        ap->flags |= ATA_FLAG_LOADING;
                        ata_port_schedule_eh(ap);
 
-                       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+                       spin_unlock_irqrestore(ap->lock, flags);
 
                        /* wait for EH to finish */
                        ata_port_wait_eh(ap);
@@ -5458,29 +5482,29 @@ void ata_port_detach(struct ata_port *ap)
                return;
 
        /* tell EH we're leaving & flush EH */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
        ap->flags |= ATA_FLAG_UNLOADING;
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        ata_port_wait_eh(ap);
 
        /* EH is now guaranteed to see UNLOADING, so no new device
         * will be attached.  Disable all existing devices.
         */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
 
        for (i = 0; i < ATA_MAX_DEVICES; i++)
                ata_dev_disable(&ap->device[i]);
 
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        /* Final freeze & EH.  All in-flight commands are aborted.  EH
         * will be skipped and retrials will be terminated with bad
         * target.
         */
-       spin_lock_irqsave(&ap->host_set->lock, flags);
+       spin_lock_irqsave(ap->lock, flags);
        ata_port_freeze(ap);    /* won't be thawed */
-       spin_unlock_irqrestore(&ap->host_set->lock, flags);
+       spin_unlock_irqrestore(ap->lock, flags);
 
        ata_port_wait_eh(ap);
 
@@ -5619,8 +5643,12 @@ void ata_pci_remove_one (struct pci_dev *pdev)
 {
        struct device *dev = pci_dev_to_dev(pdev);
        struct ata_host_set *host_set = dev_get_drvdata(dev);
+       struct ata_host_set *host_set2 = host_set->next;
 
        ata_host_set_remove(host_set);
+       if (host_set2)
+               ata_host_set_remove(host_set2);
+
        pci_release_regions(pdev);
        pci_disable_device(pdev);
        dev_set_drvdata(dev, NULL);