]> err.no Git - linux-2.6/blobdiff - drivers/scsi/libsas/sas_expander.c
Merge git://git.infradead.org/~kmpark/onenand-mtd-2.6
[linux-2.6] / drivers / scsi / libsas / sas_expander.c
index eca83e8d8c0d29f5dbf5d1be39db11067afbf66e..aefd865a578862e3bf17b4a8d6a7f8a4a8aaffef 100644 (file)
@@ -96,7 +96,7 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
                }
 
                wait_for_completion(&task->completion);
-               res = -ETASK;
+               res = -ECOMM;
                if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
                        SAS_DPRINTK("smp task timed out or aborted\n");
                        i->dft->lldd_abort_task(task);
@@ -109,6 +109,16 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
                    task->task_status.stat == SAM_GOOD) {
                        res = 0;
                        break;
+               } if (task->task_status.resp == SAS_TASK_COMPLETE &&
+                     task->task_status.stat == SAS_DATA_UNDERRUN) {
+                       /* no error, but return the number of bytes of
+                        * underrun */
+                       res = task->task_status.residual;
+                       break;
+               } if (task->task_status.resp == SAS_TASK_COMPLETE &&
+                     task->task_status.stat == SAS_DATA_OVERRUN) {
+                       res = -EMSGSIZE;
+                       break;
                } else {
                        SAS_DPRINTK("%s: task to dev %016llx response: 0x%x "
                                    "status 0x%x\n", __FUNCTION__,
@@ -507,13 +517,20 @@ static int sas_dev_present_in_domain(struct asd_sas_port *port,
 int sas_smp_get_phy_events(struct sas_phy *phy)
 {
        int res;
+       u8 *req;
+       u8 *resp;
        struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
        struct domain_device *dev = sas_find_dev_by_rphy(rphy);
-       u8 *req = alloc_smp_req(RPEL_REQ_SIZE);
-       u8 *resp = kzalloc(RPEL_RESP_SIZE, GFP_KERNEL);
 
-       if (!resp)
+       req = alloc_smp_req(RPEL_REQ_SIZE);
+       if (!req)
+               return -ENOMEM;
+
+       resp = alloc_smp_resp(RPEL_RESP_SIZE);
+       if (!resp) {
+               kfree(req);
                return -ENOMEM;
+       }
 
        req[1] = SMP_REPORT_PHY_ERR_LOG;
        req[9] = phy->number;
@@ -535,6 +552,8 @@ int sas_smp_get_phy_events(struct sas_phy *phy)
 
 }
 
+#ifdef CONFIG_SCSI_SAS_ATA
+
 #define RPS_REQ_SIZE  16
 #define RPS_RESP_SIZE 60
 
@@ -578,6 +597,7 @@ static int sas_get_report_phy_sata(struct domain_device *dev,
        kfree(rps_req);
        return res;
 }
+#endif
 
 static void sas_ex_get_linkrate(struct domain_device *parent,
                                       struct domain_device *child,
@@ -645,9 +665,10 @@ static struct domain_device *sas_ex_discover_end_dev(
        }
        sas_ex_get_linkrate(parent, child, phy);
 
-       if ((phy->attached_tproto & SAS_PROTO_STP) || phy->attached_sata_dev) {
+#ifdef CONFIG_SCSI_SAS_ATA
+       if ((phy->attached_tproto & SAS_PROTOCOL_STP) || phy->attached_sata_dev) {
                child->dev_type = SATA_DEV;
-               if (phy->attached_tproto & SAS_PROTO_STP)
+               if (phy->attached_tproto & SAS_PROTOCOL_STP)
                        child->tproto = phy->attached_tproto;
                if (phy->attached_sata_dev)
                        child->tproto |= SATA_DEV;
@@ -682,7 +703,9 @@ static struct domain_device *sas_ex_discover_end_dev(
                                    SAS_ADDR(parent->sas_addr), phy_id, res);
                        goto out_list_del;
                }
-       } else if (phy->attached_tproto & SAS_PROTO_SSP) {
+       } else
+#endif
+         if (phy->attached_tproto & SAS_PROTOCOL_SSP) {
                child->dev_type = SAS_END_DEV;
                rphy = sas_end_device_alloc(phy->port);
                /* FIXME: error handling */
@@ -710,6 +733,7 @@ static struct domain_device *sas_ex_discover_end_dev(
                SAS_DPRINTK("target proto 0x%x at %016llx:0x%x not handled\n",
                            phy->attached_tproto, SAS_ADDR(parent->sas_addr),
                            phy_id);
+               goto out_free;
        }
 
        list_add_tail(&child->siblings, &parent_ex->children);
@@ -1872,7 +1896,7 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
                    struct request *req)
 {
        struct domain_device *dev;
-       int ret, type = rphy->identify.device_type;
+       int ret, type;
        struct request *rsp = req->next_rq;
 
        if (!rsp) {
@@ -1881,12 +1905,11 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
                return -EINVAL;
        }
 
-       /* seems aic94xx doesn't support */
-       if (!rphy) {
-               printk("%s: can we send a smp request to a host?\n",
-                      __FUNCTION__);
-               return -EINVAL;
-       }
+       /* no rphy means no smp target support (ie aic94xx host) */
+       if (!rphy)
+               return sas_smp_host_handler(shost, req, rsp);
+
+       type = rphy->identify.device_type;
 
        if (type != SAS_EDGE_EXPANDER_DEVICE &&
            type != SAS_FANOUT_EXPANDER_DEVICE) {
@@ -1911,6 +1934,15 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
 
        ret = smp_execute_task(dev, bio_data(req->bio), req->data_len,
                               bio_data(rsp->bio), rsp->data_len);
+       if (ret > 0) {
+               /* positive number is the untransferred residual */
+               rsp->data_len = ret;
+               req->data_len = 0;
+               ret = 0;
+       } else if (ret == 0) {
+               rsp->data_len = 0;
+               req->data_len = 0;
+       }
 
        return ret;
 }