aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libsas
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2006-10-18 17:43:37 -0400
committerJames Bottomley <jejb@mulgrave.localdomain>2007-07-18 12:14:40 -0400
commit338ec57003ff9d7bc1471677e61872455977a5de (patch)
treeb6500d501ec6f6f9db504d5e643c799f69777277 /drivers/scsi/libsas
parent0281e02c5671f50701924465744edd3e2feb5d6f (diff)
[SCSI] Migrate libsas ATA code into a separate file
This is a respin of my earlier patch that migrates the ATA support code into a separate file. For now, the controversial linking bits have been removed per James Bottomley's request for a patch that contains only the migration diffs, which means that libsas continues to require libata. I intend to address that problem in a separate patch. This patch is against the aic94xx-sas-2.6 git tree, and it has been sanity tested on my x206m with Seagate SATA and SAS disks without uncovering any new problems. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/libsas')
-rw-r--r--drivers/scsi/libsas/Makefile3
-rw-r--r--drivers/scsi/libsas/sas_ata.c339
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c313
3 files changed, 347 insertions, 308 deletions
diff --git a/drivers/scsi/libsas/Makefile b/drivers/scsi/libsas/Makefile
index 44d972a3b4bd..6383eb58d890 100644
--- a/drivers/scsi/libsas/Makefile
+++ b/drivers/scsi/libsas/Makefile
@@ -33,4 +33,5 @@ libsas-y += sas_init.o \
33 sas_dump.o \ 33 sas_dump.o \
34 sas_discover.o \ 34 sas_discover.o \
35 sas_expander.o \ 35 sas_expander.o \
36 sas_scsi_host.o 36 sas_scsi_host.o \
37 sas_ata.o
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
new file mode 100644
index 000000000000..de42b5b801cd
--- /dev/null
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -0,0 +1,339 @@
1/*
2 * Support for SATA devices on Serial Attached SCSI (SAS) controllers
3 *
4 * Copyright (C) 2006 IBM Corporation
5 *
6 * Written by: Darrick J. Wong <djwong@us.ibm.com>, IBM Corporation
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 */
23
24#include <scsi/sas_ata.h>
25#include "sas_internal.h"
26#include <scsi/scsi_host.h>
27#include <scsi/scsi_device.h>
28#include <scsi/scsi_tcq.h>
29#include <scsi/scsi.h>
30#include <scsi/scsi_transport.h>
31#include <scsi/scsi_transport_sas.h>
32#include "../scsi_sas_internal.h"
33
34static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts)
35{
36 /* Cheesy attempt to translate SAS errors into ATA. Hah! */
37
38 /* transport error */
39 if (ts->resp == SAS_TASK_UNDELIVERED)
40 return AC_ERR_ATA_BUS;
41
42 /* ts->resp == SAS_TASK_COMPLETE */
43 /* task delivered, what happened afterwards? */
44 switch (ts->stat) {
45 case SAS_DEV_NO_RESPONSE:
46 return AC_ERR_TIMEOUT;
47
48 case SAS_INTERRUPTED:
49 case SAS_PHY_DOWN:
50 case SAS_NAK_R_ERR:
51 return AC_ERR_ATA_BUS;
52
53
54 case SAS_DATA_UNDERRUN:
55 /*
56 * Some programs that use the taskfile interface
57 * (smartctl in particular) can cause underrun
58 * problems. Ignore these errors, perhaps at our
59 * peril.
60 */
61 return 0;
62
63 case SAS_DATA_OVERRUN:
64 case SAS_QUEUE_FULL:
65 case SAS_DEVICE_UNKNOWN:
66 case SAS_SG_ERR:
67 return AC_ERR_INVALID;
68
69 case SAM_CHECK_COND:
70 case SAS_OPEN_TO:
71 case SAS_OPEN_REJECT:
72 SAS_DPRINTK("%s: Saw error %d. What to do?\n",
73 __FUNCTION__, ts->stat);
74 return AC_ERR_OTHER;
75
76 case SAS_ABORTED_TASK:
77 return AC_ERR_DEV;
78
79 case SAS_PROTO_RESPONSE:
80 /* This means the ending_fis has the error
81 * value; return 0 here to collect it */
82 return 0;
83 default:
84 return 0;
85 }
86}
87
88static void sas_ata_task_done(struct sas_task *task)
89{
90 struct ata_queued_cmd *qc = task->uldd_task;
91 struct domain_device *dev = qc->ap->private_data;
92 struct task_status_struct *stat = &task->task_status;
93 struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
94 enum ata_completion_errors ac;
95
96 if (stat->stat == SAS_PROTO_RESPONSE) {
97 ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf);
98 qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command);
99 dev->sata_dev.sstatus = resp->sstatus;
100 dev->sata_dev.serror = resp->serror;
101 dev->sata_dev.scontrol = resp->scontrol;
102 dev->sata_dev.ap->sactive = resp->sactive;
103 } else if (stat->stat != SAM_STAT_GOOD) {
104 ac = sas_to_ata_err(stat);
105 if (ac) {
106 SAS_DPRINTK("%s: SAS error %x\n", __FUNCTION__,
107 stat->stat);
108 /* We saw a SAS error. Send a vague error. */
109 qc->err_mask = ac;
110 dev->sata_dev.tf.feature = 0x04; /* status err */
111 dev->sata_dev.tf.command = ATA_ERR;
112 }
113 }
114
115 ata_qc_complete(qc);
116 list_del_init(&task->list);
117 sas_free_task(task);
118}
119
120static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
121{
122 int res = -ENOMEM;
123 struct sas_task *task;
124 struct domain_device *dev = qc->ap->private_data;
125 struct sas_ha_struct *sas_ha = dev->port->ha;
126 struct Scsi_Host *host = sas_ha->core.shost;
127 struct sas_internal *i = to_sas_internal(host->transportt);
128 struct scatterlist *sg;
129 unsigned int num = 0;
130 unsigned int xfer = 0;
131
132 task = sas_alloc_task(GFP_ATOMIC);
133 if (!task)
134 goto out;
135 task->dev = dev;
136 task->task_proto = SAS_PROTOCOL_STP;
137 task->task_done = sas_ata_task_done;
138
139 if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
140 qc->tf.command == ATA_CMD_FPDMA_READ) {
141 /* Need to zero out the tag libata assigned us */
142 qc->tf.nsect = 0;
143 }
144
145 ata_tf_to_fis(&qc->tf, (u8*)&task->ata_task.fis, 0);
146 task->uldd_task = qc;
147 if (is_atapi_taskfile(&qc->tf)) {
148 memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
149 task->total_xfer_len = qc->nbytes + qc->pad_len;
150 task->num_scatter = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
151 } else {
152 ata_for_each_sg(sg, qc) {
153 num++;
154 xfer += sg->length;
155 }
156
157 task->total_xfer_len = xfer;
158 task->num_scatter = num;
159 }
160
161 task->data_dir = qc->dma_dir;
162 task->scatter = qc->__sg;
163 task->ata_task.retry_count = 1;
164 task->task_state_flags = SAS_TASK_STATE_PENDING;
165
166 switch (qc->tf.protocol) {
167 case ATA_PROT_NCQ:
168 task->ata_task.use_ncq = 1;
169 /* fall through */
170 case ATA_PROT_ATAPI_DMA:
171 case ATA_PROT_DMA:
172 task->ata_task.dma_xfer = 1;
173 break;
174 }
175
176 if (sas_ha->lldd_max_execute_num < 2)
177 res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
178 else
179 res = sas_queue_up(task);
180
181 /* Examine */
182 if (res) {
183 SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
184
185 sas_free_task(task);
186 if (res == -SAS_QUEUE_FULL)
187 return -ENOMEM;
188 }
189
190out:
191 return res;
192}
193
194static u8 sas_ata_check_status(struct ata_port *ap)
195{
196 struct domain_device *dev = ap->private_data;
197 return dev->sata_dev.tf.command;
198}
199
200static void sas_ata_phy_reset(struct ata_port *ap)
201{
202 struct domain_device *dev = ap->private_data;
203 struct sas_internal *i =
204 to_sas_internal(dev->port->ha->core.shost->transportt);
205 int res = 0;
206
207 if (i->dft->lldd_I_T_nexus_reset)
208 res = i->dft->lldd_I_T_nexus_reset(dev);
209
210 if (res)
211 SAS_DPRINTK("%s: Unable to reset I T nexus?\n", __FUNCTION__);
212
213 switch (dev->sata_dev.command_set) {
214 case ATA_COMMAND_SET:
215 SAS_DPRINTK("%s: Found ATA device.\n", __FUNCTION__);
216 ap->device[0].class = ATA_DEV_ATA;
217 break;
218 case ATAPI_COMMAND_SET:
219 SAS_DPRINTK("%s: Found ATAPI device.\n", __FUNCTION__);
220 ap->device[0].class = ATA_DEV_ATAPI;
221 break;
222 default:
223 SAS_DPRINTK("%s: Unknown SATA command set: %d.\n",
224 __FUNCTION__,
225 dev->sata_dev.command_set);
226 ap->device[0].class = ATA_DEV_ATA;
227 break;
228 }
229
230 ap->cbl = ATA_CBL_SATA;
231}
232
233static void sas_ata_post_internal(struct ata_queued_cmd *qc)
234{
235 if (qc->flags & ATA_QCFLAG_FAILED)
236 qc->err_mask |= AC_ERR_OTHER;
237
238 if (qc->err_mask)
239 SAS_DPRINTK("%s: Failure; reset phy!\n", __FUNCTION__);
240}
241
242static void sas_ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
243{
244 struct domain_device *dev = ap->private_data;
245 memcpy(tf, &dev->sata_dev.tf, sizeof (*tf));
246}
247
248static void sas_ata_scr_write(struct ata_port *ap, unsigned int sc_reg_in,
249 u32 val)
250{
251 struct domain_device *dev = ap->private_data;
252
253 SAS_DPRINTK("STUB %s\n", __FUNCTION__);
254 switch (sc_reg_in) {
255 case SCR_STATUS:
256 dev->sata_dev.sstatus = val;
257 break;
258 case SCR_CONTROL:
259 dev->sata_dev.scontrol = val;
260 break;
261 case SCR_ERROR:
262 dev->sata_dev.serror = val;
263 break;
264 case SCR_ACTIVE:
265 dev->sata_dev.ap->sactive = val;
266 break;
267 }
268}
269
270static u32 sas_ata_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
271{
272 struct domain_device *dev = ap->private_data;
273
274 SAS_DPRINTK("STUB %s\n", __FUNCTION__);
275 switch (sc_reg_in) {
276 case SCR_STATUS:
277 return dev->sata_dev.sstatus;
278 case SCR_CONTROL:
279 return dev->sata_dev.scontrol;
280 case SCR_ERROR:
281 return dev->sata_dev.serror;
282 case SCR_ACTIVE:
283 return dev->sata_dev.ap->sactive;
284 default:
285 return 0xffffffffU;
286 }
287}
288
289static struct ata_port_operations sas_sata_ops = {
290 .port_disable = ata_port_disable,
291 .check_status = sas_ata_check_status,
292 .check_altstatus = sas_ata_check_status,
293 .dev_select = ata_noop_dev_select,
294 .phy_reset = sas_ata_phy_reset,
295 .post_internal_cmd = sas_ata_post_internal,
296 .tf_read = sas_ata_tf_read,
297 .qc_prep = ata_noop_qc_prep,
298 .qc_issue = sas_ata_qc_issue,
299 .port_start = ata_sas_port_start,
300 .port_stop = ata_sas_port_stop,
301 .scr_read = sas_ata_scr_read,
302 .scr_write = sas_ata_scr_write
303};
304
305static struct ata_port_info sata_port_info = {
306 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
307 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ,
308 .pio_mask = 0x1f, /* PIO0-4 */
309 .mwdma_mask = 0x07, /* MWDMA0-2 */
310 .udma_mask = ATA_UDMA6,
311 .port_ops = &sas_sata_ops
312};
313
314int sas_ata_init_host_and_port(struct domain_device *found_dev,
315 struct scsi_target *starget)
316{
317 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
318 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
319 struct ata_port *ap;
320
321 ata_host_init(&found_dev->sata_dev.ata_host,
322 &ha->pcidev->dev,
323 sata_port_info.flags,
324 &sas_sata_ops);
325 ap = ata_sas_port_alloc(&found_dev->sata_dev.ata_host,
326 &sata_port_info,
327 shost);
328 if (!ap) {
329 SAS_DPRINTK("ata_sas_port_alloc failed.\n");
330 return -ENODEV;
331 }
332
333 ap->private_data = found_dev;
334 ap->cbl = ATA_CBL_SATA;
335 ap->scsi_host = shost;
336 found_dev->sata_dev.ap = ap;
337
338 return 0;
339}
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 0dc7c02b3837..dbc2a912114f 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -34,6 +34,7 @@
34#include <scsi/scsi_eh.h> 34#include <scsi/scsi_eh.h>
35#include <scsi/scsi_transport.h> 35#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_sas.h> 36#include <scsi/scsi_transport_sas.h>
37#include <scsi/sas_ata.h>
37#include "../scsi_sas_internal.h" 38#include "../scsi_sas_internal.h"
38#include "../scsi_transport_api.h" 39#include "../scsi_transport_api.h"
39#include "../scsi_priv.h" 40#include "../scsi_priv.h"
@@ -173,7 +174,7 @@ static struct sas_task *sas_create_task(struct scsi_cmnd *cmd,
173 return task; 174 return task;
174} 175}
175 176
176static int sas_queue_up(struct sas_task *task) 177int sas_queue_up(struct sas_task *task)
177{ 178{
178 struct sas_ha_struct *sas_ha = task->dev->port->ha; 179 struct sas_ha_struct *sas_ha = task->dev->port->ha;
179 struct scsi_core *core = &sas_ha->core; 180 struct scsi_core *core = &sas_ha->core;
@@ -193,11 +194,6 @@ static int sas_queue_up(struct sas_task *task)
193 return 0; 194 return 0;
194} 195}
195 196
196static inline int dev_is_sata(struct domain_device *dev)
197{
198 return (dev->rphy->identify.target_port_protocols & SAS_PROTOCOL_SATA);
199}
200
201/** 197/**
202 * sas_queuecommand -- Enqueue a command for processing 198 * sas_queuecommand -- Enqueue a command for processing
203 * @parameters: See SCSI Core documentation 199 * @parameters: See SCSI Core documentation
@@ -696,93 +692,6 @@ enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
696 return EH_NOT_HANDLED; 692 return EH_NOT_HANDLED;
697} 693}
698 694
699
700static enum ata_completion_errors sas_to_ata_err(struct task_status_struct *ts)
701{
702 /* Cheesy attempt to translate SAS errors into ATA. Hah! */
703
704 /* transport error */
705 if (ts->resp == SAS_TASK_UNDELIVERED)
706 return AC_ERR_ATA_BUS;
707
708 /* ts->resp == SAS_TASK_COMPLETE */
709 /* task delivered, what happened afterwards? */
710 switch (ts->stat) {
711 case SAS_DEV_NO_RESPONSE:
712 return AC_ERR_TIMEOUT;
713
714 case SAS_INTERRUPTED:
715 case SAS_PHY_DOWN:
716 case SAS_NAK_R_ERR:
717 return AC_ERR_ATA_BUS;
718
719
720 case SAS_DATA_UNDERRUN:
721 /*
722 * Some programs that use the taskfile interface
723 * (smartctl in particular) can cause underrun
724 * problems. Ignore these errors, perhaps at our
725 * peril.
726 */
727 return 0;
728
729 case SAS_DATA_OVERRUN:
730 case SAS_QUEUE_FULL:
731 case SAS_DEVICE_UNKNOWN:
732 case SAS_SG_ERR:
733 return AC_ERR_INVALID;
734
735 case SAM_CHECK_COND:
736 case SAS_OPEN_TO:
737 case SAS_OPEN_REJECT:
738 SAS_DPRINTK("%s: Saw error %d. What to do?\n",
739 __FUNCTION__, ts->stat);
740 return AC_ERR_OTHER;
741
742 case SAS_ABORTED_TASK:
743 return AC_ERR_DEV;
744
745 case SAS_PROTO_RESPONSE:
746 /* This means the ending_fis has the error
747 * value; return 0 here to collect it */
748 return 0;
749 default:
750 return 0;
751 }
752}
753
754static void sas_ata_task_done(struct sas_task *task)
755{
756 struct ata_queued_cmd *qc = task->uldd_task;
757 struct domain_device *dev = qc->ap->private_data;
758 struct task_status_struct *stat = &task->task_status;
759 struct ata_task_resp *resp = (struct ata_task_resp *)stat->buf;
760 enum ata_completion_errors ac;
761
762 if (stat->stat == SAS_PROTO_RESPONSE) {
763 ata_tf_from_fis(resp->ending_fis, &dev->sata_dev.tf);
764 qc->err_mask |= ac_err_mask(dev->sata_dev.tf.command);
765 dev->sata_dev.sstatus = resp->sstatus;
766 dev->sata_dev.serror = resp->serror;
767 dev->sata_dev.scontrol = resp->scontrol;
768 dev->sata_dev.ap->sactive = resp->sactive;
769 } else if (stat->stat != SAM_STAT_GOOD) {
770 ac = sas_to_ata_err(stat);
771 if (ac) {
772 SAS_DPRINTK("%s: SAS error %x\n", __FUNCTION__,
773 stat->stat);
774 /* We saw a SAS error. Send a vague error. */
775 qc->err_mask = ac;
776 dev->sata_dev.tf.feature = 0x04; /* status err */
777 dev->sata_dev.tf.command = ATA_ERR;
778 }
779 }
780
781 ata_qc_complete(qc);
782 list_del_init(&task->list);
783 sas_free_task(task);
784}
785
786int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg) 695int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
787{ 696{
788 struct domain_device *dev = sdev_to_domain_dev(sdev); 697 struct domain_device *dev = sdev_to_domain_dev(sdev);
@@ -793,200 +702,6 @@ int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
793 return -EINVAL; 702 return -EINVAL;
794} 703}
795 704
796static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
797{
798 int res = -ENOMEM;
799 struct sas_task *task;
800 struct domain_device *dev = qc->ap->private_data;
801 struct sas_ha_struct *sas_ha = dev->port->ha;
802 struct Scsi_Host *host = sas_ha->core.shost;
803 struct sas_internal *i = to_sas_internal(host->transportt);
804 struct scatterlist *sg;
805 unsigned int num = 0;
806 unsigned int xfer = 0;
807
808 task = sas_alloc_task(GFP_ATOMIC);
809 if (!task)
810 goto out;
811 task->dev = dev;
812 task->task_proto = SAS_PROTOCOL_STP;
813 task->task_done = sas_ata_task_done;
814
815 if (qc->tf.command == ATA_CMD_FPDMA_WRITE ||
816 qc->tf.command == ATA_CMD_FPDMA_READ) {
817 /* Need to zero out the tag libata assigned us */
818 qc->tf.nsect = 0;
819 }
820
821 ata_tf_to_fis(&qc->tf, (u8*)&task->ata_task.fis, 0);
822 task->uldd_task = qc;
823 if (is_atapi_taskfile(&qc->tf)) {
824 memcpy(task->ata_task.atapi_packet, qc->cdb, qc->dev->cdb_len);
825 task->total_xfer_len = qc->nbytes + qc->pad_len;
826 task->num_scatter = qc->pad_len ? qc->n_elem + 1 : qc->n_elem;
827 } else {
828 ata_for_each_sg(sg, qc) {
829 num++;
830 xfer += sg->length;
831 }
832
833 task->total_xfer_len = xfer;
834 task->num_scatter = num;
835 }
836
837 task->data_dir = qc->dma_dir;
838 task->scatter = qc->__sg;
839 task->ata_task.retry_count = 1;
840 task->task_state_flags = SAS_TASK_STATE_PENDING;
841
842 switch (qc->tf.protocol) {
843 case ATA_PROT_NCQ:
844 task->ata_task.use_ncq = 1;
845 /* fall through */
846 case ATA_PROT_ATAPI_DMA:
847 case ATA_PROT_DMA:
848 task->ata_task.dma_xfer = 1;
849 break;
850 }
851
852 if (sas_ha->lldd_max_execute_num < 2)
853 res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
854 else
855 res = sas_queue_up(task);
856
857 /* Examine */
858 if (res) {
859 SAS_DPRINTK("lldd_execute_task returned: %d\n", res);
860
861 sas_free_task(task);
862 if (res == -SAS_QUEUE_FULL)
863 return -ENOMEM;
864 }
865
866out:
867 return res;
868}
869
870static u8 sas_ata_check_status(struct ata_port *ap)
871{
872 struct domain_device *dev = ap->private_data;
873 return dev->sata_dev.tf.command;
874}
875
876static void sas_ata_phy_reset(struct ata_port *ap)
877{
878 struct domain_device *dev = ap->private_data;
879 struct sas_internal *i =
880 to_sas_internal(dev->port->ha->core.shost->transportt);
881 int res = 0;
882
883 if (i->dft->lldd_I_T_nexus_reset)
884 res = i->dft->lldd_I_T_nexus_reset(dev);
885
886 if (res)
887 SAS_DPRINTK("%s: Unable to reset I T nexus?\n", __FUNCTION__);
888
889 switch (dev->sata_dev.command_set) {
890 case ATA_COMMAND_SET:
891 SAS_DPRINTK("%s: Found ATA device.\n", __FUNCTION__);
892 ap->device[0].class = ATA_DEV_ATA;
893 break;
894 case ATAPI_COMMAND_SET:
895 SAS_DPRINTK("%s: Found ATAPI device.\n", __FUNCTION__);
896 ap->device[0].class = ATA_DEV_ATAPI;
897 break;
898 default:
899 SAS_DPRINTK("%s: Unknown SATA command set: %d.\n",
900 __FUNCTION__,
901 dev->sata_dev.command_set);
902 ap->device[0].class = ATA_DEV_ATA;
903 break;
904 }
905
906 ap->cbl = ATA_CBL_SATA;
907}
908
909static void sas_ata_post_internal(struct ata_queued_cmd *qc)
910{
911 if (qc->flags & ATA_QCFLAG_FAILED)
912 qc->err_mask |= AC_ERR_OTHER;
913
914 if (qc->err_mask)
915 SAS_DPRINTK("%s: Failure; reset phy!\n", __FUNCTION__);
916}
917
918static void sas_ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
919{
920 struct domain_device *dev = ap->private_data;
921 memcpy(tf, &dev->sata_dev.tf, sizeof (*tf));
922}
923
924static void sas_ata_scr_write(struct ata_port *ap, unsigned int sc_reg_in,
925 u32 val)
926{
927 struct domain_device *dev = ap->private_data;
928
929 SAS_DPRINTK("STUB %s\n", __FUNCTION__);
930 switch (sc_reg_in) {
931 case SCR_STATUS:
932 dev->sata_dev.sstatus = val;
933 break;
934 case SCR_CONTROL:
935 dev->sata_dev.scontrol = val;
936 break;
937 case SCR_ERROR:
938 dev->sata_dev.serror = val;
939 break;
940 case SCR_ACTIVE:
941 dev->sata_dev.ap->sactive = val;
942 break;
943 }
944}
945
946static u32 sas_ata_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
947{
948 struct domain_device *dev = ap->private_data;
949
950 SAS_DPRINTK("STUB %s\n", __FUNCTION__);
951 switch (sc_reg_in) {
952 case SCR_STATUS:
953 return dev->sata_dev.sstatus;
954 case SCR_CONTROL:
955 return dev->sata_dev.scontrol;
956 case SCR_ERROR:
957 return dev->sata_dev.serror;
958 case SCR_ACTIVE:
959 return dev->sata_dev.ap->sactive;
960 default:
961 return 0xffffffffU;
962 }
963}
964
965static struct ata_port_operations sas_sata_ops = {
966 .port_disable = ata_port_disable,
967 .check_status = sas_ata_check_status,
968 .check_altstatus = sas_ata_check_status,
969 .dev_select = ata_noop_dev_select,
970 .phy_reset = sas_ata_phy_reset,
971 .post_internal_cmd = sas_ata_post_internal,
972 .tf_read = sas_ata_tf_read,
973 .qc_prep = ata_noop_qc_prep,
974 .qc_issue = sas_ata_qc_issue,
975 .port_start = ata_sas_port_start,
976 .port_stop = ata_sas_port_stop,
977 .scr_read = sas_ata_scr_read,
978 .scr_write = sas_ata_scr_write
979};
980
981static struct ata_port_info sata_port_info = {
982 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
983 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ,
984 .pio_mask = 0x1f, /* PIO0-4 */
985 .mwdma_mask = 0x07, /* MWDMA0-2 */
986 .udma_mask = ATA_UDMA6,
987 .port_ops = &sas_sata_ops
988};
989
990struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy) 705struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
991{ 706{
992 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent); 707 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent);
@@ -1025,32 +740,16 @@ static inline struct domain_device *sas_find_target(struct scsi_target *starget)
1025 740
1026int sas_target_alloc(struct scsi_target *starget) 741int sas_target_alloc(struct scsi_target *starget)
1027{ 742{
1028 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
1029 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
1030 struct domain_device *found_dev = sas_find_target(starget); 743 struct domain_device *found_dev = sas_find_target(starget);
744 int res;
1031 745
1032 if (!found_dev) 746 if (!found_dev)
1033 return -ENODEV; 747 return -ENODEV;
1034 748
1035 if (dev_is_sata(found_dev)) { 749 if (dev_is_sata(found_dev)) {
1036 struct ata_port *ap; 750 res = sas_ata_init_host_and_port(found_dev, starget);
1037 751 if (res)
1038 ata_host_init(&found_dev->sata_dev.ata_host, 752 return res;
1039 &ha->pcidev->dev,
1040 sata_port_info.flags,
1041 &sas_sata_ops);
1042 ap = ata_sas_port_alloc(&found_dev->sata_dev.ata_host,
1043 &sata_port_info,
1044 shost);
1045 if (!ap) {
1046 SAS_DPRINTK("ata_sas_port_alloc failed.\n");
1047 return -ENODEV;
1048 }
1049
1050 ap->private_data = found_dev;
1051 ap->cbl = ATA_CBL_SATA;
1052 ap->scsi_host = shost;
1053 found_dev->sata_dev.ap = ap;
1054 } 753 }
1055 754
1056 starget->hostdata = found_dev; 755 starget->hostdata = found_dev;