History

Merge tag 'ata-6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux

Pull ata updates from Niklas Cassel: - ATA PASS-THROUGH sense data cleanups and fixes (Igor Pylypiv) Store the sense data for ATA PASS-THROUGH commands at the correct offset in the sense buffer when using fixed format sense data. Cleanup the logic related to generating sense data for PASS-THROUGH commands. Generating sense data for PASS-THROUGH commands would overwrite any eventual (real) sense data received from the device. Honor the D_SENSE bit when generating sense data for PASS-THROUGH commands. (The D_SENSE bit can be set by the user, and determines if the returned sense data should be in fixed format or descriptor format) - ata port allocation cleanups (me) Assign the ata port print_id at port allocation time, such that the ata_port_* print functions can be used earlier in the init call chain. Change the ata port port print_id to use ida_alloc(), such that print_ids will get reused on rmmod + modprobe, instead of being incremented indefinitely. Remove wrappers that only existed in order to export the internal libata functions which they wrapped, and instead export the libata functions directly. - Update SATA_MOBILE_LPM_POLICY Kconfig default to med_power_with_dipm (Mario Limonciello) Using this default was not always a good idea before, because it would break hot plug support. However, with LPM changes in recent kernels, a port marked as external will not enable LPM (in order to not break hot plug), so it is now safe to change the default value of this Kconfig. All major Linux distros have had SATA_MOBILE_LPM_POLICY set to med_power_with_dipm for quite a long time - Convert ahci-fsl-qoriq device tree binding to yaml format (Frank Li) * tag 'ata-6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/libata/linux: dt-bindings: ata: ahci-fsl-qoriq: add fsl,ls1046a-ahci and fsl,ls1012a-ahci ata: ahci: Add debug print for external port ata,scsi: Remove wrapper ata_sas_port_alloc() ata: libata-core: Reuse available ata_port print_ids ata: libata: Assign print_id at port allocation time ata: libata-core: Remove local_port_no struct member ata: libata-sata: Remove superfluous assignment in ata_sas_port_alloc() ata: libata-core: Remove support for decreasing the number of ports ata: libata: Remove unused function declaration for ata_scsi_detect() ata,scsi: Remove wrappers ata_sas_tport_{add,delete}() ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf ata: libata-core: Set ATA_QCFLAG_RTF_FILLED in fill_result_tf() ata: libata-scsi: Do not pass ATA device id to ata_to_sense_error() ata: libata-scsi: Remove redundant sense_buffer memsets ata: libata-scsi: Honor the D_SENSE bit for CK_COND=1 and no error ata: libata-scsi: Do not overwrite valid sense data when CK_COND=1 ata: libata-scsi: Fix offsets for the fixed format sense data dt-bindings: ata: ahci-fsl-qoriq: convert to yaml format ata: Kconfig: Update SATA_MOBILE_LPM_POLICY default to med_power_with_dipm

Linus Torvalds committed 2 years ago

Commit e2f710f2 parents 01f851a 6739fad14 files · +230 −225Browse files

Unified · Split

14 files
  1. Documentation/devicetree/bindings/ata/ahci-fsl-qoriq.txt +0 −21
  2. Documentation/devicetree/bindings/ata/fsl,ahci.yaml +64 −0
  3. drivers/ata/Kconfig +1 −1
  4. drivers/ata/ahci.c +3 −1
  5. drivers/ata/libahci.c +2 −10
  6. drivers/ata/libata-core.c +23 −26
  7. drivers/ata/libata-sata.c +0 −49
  8. drivers/ata/libata-scsi.c +118 −91
  9. drivers/ata/libata-transport.c +4 −1
  10. drivers/ata/libata-transport.h +0 −3
  11. drivers/ata/libata.h +0 −2
  12. drivers/scsi/libsas/sas_ata.c +10 −12
  13. drivers/scsi/libsas/sas_discover.c +1 −1
  14. include/linux/libata.h +4 −7
Documentation/devicetree/bindings/ata/ahci-fsl-qoriq.txt+0−21
@@ -1,21 +0,0 @@
1−Binding for Freescale QorIQ AHCI SATA Controller
2−
3−Required properties:
4− - reg: Physical base address and size of the controller's register area.
5− - compatible: Compatibility string. Must be 'fsl,<chip>-ahci', where
6− chip could be ls1021a, ls1043a, ls1046a, ls1088a, ls2080a etc.
7− - clocks: Input clock specifier. Refer to common clock bindings.
8− - interrupts: Interrupt specifier. Refer to interrupt binding.
9−
10−Optional properties:
11− - dma-coherent: Enable AHCI coherent DMA operation.
12− - reg-names: register area names when there are more than 1 register area.
13−
14−Examples:
15− sata@3200000 {
16− compatible = "fsl,ls1021a-ahci";
17− reg = <0x0 0x3200000 0x0 0x10000>;
18− interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
19− clocks = <&platform_clk 1>;
20− dma-coherent;
21− };
Documentation/devicetree/bindings/ata/fsl,ahci.yaml+64−0
@@ -0,0 +1,64 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/ata/fsl,ahci.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Freescale QorIQ AHCI SATA Controller
8+
9+maintainers:
10+ - Frank Li <Frank.Li@nxp.com>
11+
12+properties:
13+ compatible:
14+ oneOf:
15+ - description: SATA controller for ls1012a
16+ items:
17+ - const: fsl,ls1012a-ahci
18+ - const: fsl,ls1043a-ahci
19+ - enum:
20+ - fsl,ls1021a-ahci
21+ - fsl,ls1028a-ahci
22+ - fsl,ls1043a-ahci
23+ - fsl,ls1046a-ahci
24+ - fsl,ls1088a-ahci
25+ - fsl,ls2080a-ahci
26+ - fsl,lx2160a-ahci
27+
28+ reg:
29+ minItems: 1
30+ maxItems: 2
31+
32+ reg-names:
33+ items:
34+ - const: ahci
35+ - const: sata-ecc
36+ minItems: 1
37+
38+ clocks:
39+ maxItems: 1
40+
41+ interrupts:
42+ maxItems: 1
43+
44+ dma-coherent: true
45+
46+required:
47+ - compatible
48+ - reg
49+ - clocks
50+ - interrupts
51+
52+additionalProperties: false
53+
54+examples:
55+ - |
56+ #include <dt-bindings/interrupt-controller/arm-gic.h>
57+
58+ sata@3200000 {
59+ compatible = "fsl,ls1021a-ahci";
60+ reg = <0x3200000 0x10000>;
61+ interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
62+ clocks = <&platform_clk 1>;
63+ dma-coherent;
64+ };
drivers/ata/Kconfig+1−1
@@ -118,7 +118,7 @@ config SATA_AHCI · 117 unmodified lines
118118 config SATA_MOBILE_LPM_POLICY
119119 int "Default SATA Link Power Management policy"
120120 range 0 4
121− default 0
121+ default 3
122122 depends on SATA_AHCI
123123 help
124124 Select the Default SATA Link Power Management (LPM) policy to use
drivers/ata/ahci.c+3−1
@@ -1732,8 +1732,10 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap) · 1731 unmodified lines
17321732 * Management Interaction in AHCI 1.3.1. Therefore, do not enable
17331733 * LPM if the port advertises itself as an external port.
17341734 */
1735− if (ap->pflags & ATA_PFLAG_EXTERNAL)
1735+ if (ap->pflags & ATA_PFLAG_EXTERNAL) {
1736+ ata_port_dbg(ap, "external port, not enabling LPM\n");
17361737 return;
1738+ }
17371739
17381740 /* If no LPM states are supported by the HBA, do not bother with LPM */
17391741 if ((ap->host->flags & ATA_HOST_NO_PART) &&
drivers/ata/libahci.c+2−10
@@ -2075,13 +2075,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) · 2074 unmodified lines
20752075 struct ahci_port_priv *pp = qc->ap->private_data;
20762076 u8 *rx_fis = pp->rx_fis;
20772077
2078− /*
2079− * rtf may already be filled (e.g. for successful NCQ commands).
2080− * If that is the case, we have nothing to do.
2081− */
2082− if (qc->flags & ATA_QCFLAG_RTF_FILLED)
2083− return;
2084−
20852078 if (pp->fbs_enabled)
20862079 rx_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ;
20872080
@@ -2095,7 +2088,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) · 7 unmodified lines
20952088 !(qc->flags & ATA_QCFLAG_EH)) {
20962089 ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf);
20972090 qc->result_tf.status = (rx_fis + RX_FIS_PIO_SETUP)[15];
2098− qc->flags |= ATA_QCFLAG_RTF_FILLED;
20992091 return;
21002092 }
21012093
@@ -2118,12 +2110,10 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) · 16 unmodified lines
21182110 */
21192111 qc->result_tf.status = fis[2];
21202112 qc->result_tf.error = fis[3];
2121− qc->flags |= ATA_QCFLAG_RTF_FILLED;
21222113 return;
21232114 }
21242115
21252116 ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf);
2126− qc->flags |= ATA_QCFLAG_RTF_FILLED;
21272117 }
21282118
21292119 static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask)
@@ -2158,6 +2148,7 @@ static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) · 28 unmodified lines
21582148 if (qc && ata_is_ncq(qc->tf.protocol)) {
21592149 qc->result_tf.status = status;
21602150 qc->result_tf.error = error;
2151+ qc->result_tf.flags = qc->tf.flags;
21612152 qc->flags |= ATA_QCFLAG_RTF_FILLED;
21622153 }
21632154 done_mask &= ~(1ULL << tag);
@@ -2182,6 +2173,7 @@ static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) · 18 unmodified lines
21822173 fis += RX_FIS_SDB;
21832174 qc->result_tf.status = fis[2];
21842175 qc->result_tf.error = fis[3];
2176+ qc->result_tf.flags = qc->tf.flags;
21852177 qc->flags |= ATA_QCFLAG_RTF_FILLED;
21862178 }
21872179 done_mask &= ~(1ULL << tag);
drivers/ata/libata-core.c+23−26
@@ -86,7 +86,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev); · 85 unmodified lines
8686 static void ata_dev_xfermask(struct ata_device *dev);
8787 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
8888
89−atomic_t ata_print_id = ATOMIC_INIT(0);
89+static DEFINE_IDA(ata_ida);
9090
9191 #ifdef CONFIG_ATA_FORCE
9292 struct ata_force_param {
@@ -4800,8 +4800,16 @@ static void fill_result_tf(struct ata_queued_cmd *qc) · 4707 unmodified lines
48004800 {
48014801 struct ata_port *ap = qc->ap;
48024802
4803+ /*
4804+ * rtf may already be filled (e.g. for successful NCQ commands).
4805+ * If that is the case, we have nothing to do.
4806+ */
4807+ if (qc->flags & ATA_QCFLAG_RTF_FILLED)
4808+ return;
4809+
48034810 qc->result_tf.flags = qc->tf.flags;
48044811 ap->ops->qc_fill_rtf(qc);
4812+ qc->flags |= ATA_QCFLAG_RTF_FILLED;
48054813 }
48064814
48074815 static void ata_verify_xfer(struct ata_queued_cmd *qc)
@@ -5455,6 +5463,7 @@ int sata_link_init_spd(struct ata_link *link) · 647 unmodified lines
54555463 struct ata_port *ata_port_alloc(struct ata_host *host)
54565464 {
54575465 struct ata_port *ap;
5466+ int id;
54585467
54595468 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
54605469 if (!ap)
@@ -5462,8 +5471,12 @@ struct ata_port *ata_port_alloc(struct ata_host *host) · 1 unmodified line
54625471
54635472 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN;
54645473 ap->lock = &host->lock;
5465− ap->print_id = -1;
5466− ap->local_port_no = -1;
5474+ id = ida_alloc_min(&ata_ida, 1, GFP_KERNEL);
5475+ if (id < 0) {
5476+ kfree(ap);
5477+ return NULL;
5478+ }
5479+ ap->print_id = id;
54675480 ap->host = host;
54685481 ap->dev = host->dev;
54695482
@@ -5488,6 +5501,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) · 18 unmodified lines
54885501
54895502 return ap;
54905503 }
5504+EXPORT_SYMBOL_GPL(ata_port_alloc);
54915505
54925506 void ata_port_free(struct ata_port *ap)
54935507 {
@@ -5497,6 +5511,7 @@ void ata_port_free(struct ata_port *ap) · 3 unmodified lines
54975511 kfree(ap->pmp_link);
54985512 kfree(ap->slave_link);
54995513 kfree(ap->ncq_sense_buf);
5514+ ida_free(&ata_ida, ap->print_id);
55005515 kfree(ap);
55015516 }
55025517 EXPORT_SYMBOL_GPL(ata_port_free);
@@ -5547,24 +5562,19 @@ EXPORT_SYMBOL_GPL(ata_host_put); · 44 unmodified lines
55475562 /**
55485563 * ata_host_alloc - allocate and init basic ATA host resources
55495564 * @dev: generic device this host is associated with
5550− * @max_ports: maximum number of ATA ports associated with this host
5565+ * @n_ports: the number of ATA ports associated with this host
55515566 *
55525567 * Allocate and initialize basic ATA host resources. LLD calls
55535568 * this function to allocate a host, initializes it fully and
55545569 * attaches it using ata_host_register().
55555570 *
5556− * @max_ports ports are allocated and host->n_ports is
5557− * initialized to @max_ports. The caller is allowed to decrease
5558− * host->n_ports before calling ata_host_register(). The unused
5559− * ports will be automatically freed on registration.
5560− *
55615571 * RETURNS:
55625572 * Allocate ATA host on success, NULL on failure.
55635573 *
55645574 * LOCKING:
55655575 * Inherited from calling layer (may sleep).
55665576 */
5567−struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5577+struct ata_host *ata_host_alloc(struct device *dev, int n_ports)
55685578 {
55695579 struct ata_host *host;
55705580 size_t sz;
@@ -5572,7 +5582,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) · 1 unmodified line
55725582 void *dr;
55735583
55745584 /* alloc a container for our list of ATA ports (buses) */
5575− sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *);
5585+ sz = sizeof(struct ata_host) + n_ports * sizeof(void *);
55765586 host = kzalloc(sz, GFP_KERNEL);
55775587 if (!host)
55785588 return NULL;
@@ -5592,11 +5602,11 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) · 13 unmodified lines
55925602 spin_lock_init(&host->lock);
55935603 mutex_init(&host->eh_mutex);
55945604 host->dev = dev;
5595− host->n_ports = max_ports;
5605+ host->n_ports = n_ports;
55965606 kref_init(&host->kref);
55975607
55985608 /* allocate ports bound to this host */
5599− for (i = 0; i < max_ports; i++) {
5609+ for (i = 0; i < n_ports; i++) {
56005610 struct ata_port *ap;
56015611
56025612 ap = ata_port_alloc(host);
@@ -5905,19 +5915,6 @@ int ata_host_register(struct ata_host *host, const struct scsi_host_template *sh · 302 unmodified lines
59055915 return -EINVAL;
59065916 }
59075917
5908− /* Blow away unused ports. This happens when LLD can't
5909− * determine the exact number of ports to allocate at
5910− * allocation time.
5911− */
5912− for (i = host->n_ports; host->ports[i]; i++)
5913− ata_port_free(host->ports[i]);
5914−
5915− /* give ports names and add SCSI hosts */
5916− for (i = 0; i < host->n_ports; i++) {
5917− host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
5918− host->ports[i]->local_port_no = i + 1;
5919− }
5920−
59215918 /* Create associated sysfs transport objects */
59225919 for (i = 0; i < host->n_ports; i++) {
59235920 rc = ata_tport_add(host->dev,host->ports[i]);
drivers/ata/libata-sata.c+0−49
@@ -1204,55 +1204,6 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth) · 1203 unmodified lines
12041204 }
12051205 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
12061206
1207−/**
1208− * ata_sas_port_alloc - Allocate port for a SAS attached SATA device
1209− * @host: ATA host container for all SAS ports
1210− * @port_info: Information from low-level host driver
1211− * @shost: SCSI host that the scsi device is attached to
1212− *
1213− * LOCKING:
1214− * PCI/etc. bus probe sem.
1215− *
1216− * RETURNS:
1217− * ata_port pointer on success / NULL on failure.
1218− */
1219−
1220−struct ata_port *ata_sas_port_alloc(struct ata_host *host,
1221− struct ata_port_info *port_info,
1222− struct Scsi_Host *shost)
1223−{
1224− struct ata_port *ap;
1225−
1226− ap = ata_port_alloc(host);
1227− if (!ap)
1228− return NULL;
1229−
1230− ap->port_no = 0;
1231− ap->lock = &host->lock;
1232− ap->pio_mask = port_info->pio_mask;
1233− ap->mwdma_mask = port_info->mwdma_mask;
1234− ap->udma_mask = port_info->udma_mask;
1235− ap->flags |= port_info->flags;
1236− ap->ops = port_info->port_ops;
1237− ap->cbl = ATA_CBL_SATA;
1238− ap->print_id = atomic_inc_return(&ata_print_id);
1239−
1240− return ap;
1241−}
1242−EXPORT_SYMBOL_GPL(ata_sas_port_alloc);
1243−
1244−int ata_sas_tport_add(struct device *parent, struct ata_port *ap)
1245−{
1246− return ata_tport_add(parent, ap);
1247−}
1248−EXPORT_SYMBOL_GPL(ata_sas_tport_add);
1249−
1250−void ata_sas_tport_delete(struct ata_port *ap)
1251−{
1252− ata_tport_delete(ap);
1253−}
1254−EXPORT_SYMBOL_GPL(ata_sas_tport_delete);
1255−
12561207 /**
12571208 * ata_sas_device_configure - Default device_configure routine for libata
12581209 * devices
drivers/ata/libata-scsi.c+118−91
@@ -230,6 +230,87 @@ void ata_scsi_set_sense_information(struct ata_device *dev, · 229 unmodified lines
230230 SCSI_SENSE_BUFFERSIZE, information);
231231 }
232232
233+/**
234+ * ata_scsi_set_passthru_sense_fields - Set ATA fields in sense buffer
235+ * @qc: ATA PASS-THROUGH command.
236+ *
237+ * Populates "ATA Status Return sense data descriptor" / "Fixed format
238+ * sense data" with ATA taskfile fields.
239+ *
240+ * LOCKING:
241+ * None.
242+ */
243+static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc)
244+{
245+ struct ata_device *dev = qc->dev;
246+ struct scsi_cmnd *cmd = qc->scsicmd;
247+ struct ata_taskfile *tf = &qc->result_tf;
248+ unsigned char *sb = cmd->sense_buffer;
249+
250+ if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
251+ ata_dev_dbg(dev,
252+ "missing result TF: can't set ATA PT sense fields\n");
253+ return;
254+ }
255+
256+ if ((sb[0] & 0x7f) >= 0x72) {
257+ unsigned char *desc;
258+ u8 len;
259+
260+ /* descriptor format */
261+ len = sb[7];
262+ desc = (char *)scsi_sense_desc_find(sb, len + 8, 9);
263+ if (!desc) {
264+ if (SCSI_SENSE_BUFFERSIZE < len + 14)
265+ return;
266+ sb[7] = len + 14;
267+ desc = sb + 8 + len;
268+ }
269+ desc[0] = 9;
270+ desc[1] = 12;
271+ /*
272+ * Copy registers into sense buffer.
273+ */
274+ desc[2] = 0x00;
275+ desc[3] = tf->error;
276+ desc[5] = tf->nsect;
277+ desc[7] = tf->lbal;
278+ desc[9] = tf->lbam;
279+ desc[11] = tf->lbah;
280+ desc[12] = tf->device;
281+ desc[13] = tf->status;
282+
283+ /*
284+ * Fill in Extend bit, and the high order bytes
285+ * if applicable.
286+ */
287+ if (tf->flags & ATA_TFLAG_LBA48) {
288+ desc[2] |= 0x01;
289+ desc[4] = tf->hob_nsect;
290+ desc[6] = tf->hob_lbal;
291+ desc[8] = tf->hob_lbam;
292+ desc[10] = tf->hob_lbah;
293+ }
294+ } else {
295+ /* Fixed sense format */
296+ sb[0] |= 0x80;
297+ sb[3] = tf->error;
298+ sb[4] = tf->status;
299+ sb[5] = tf->device;
300+ sb[6] = tf->nsect;
301+ if (tf->flags & ATA_TFLAG_LBA48) {
302+ sb[8] |= 0x80;
303+ if (tf->hob_nsect)
304+ sb[8] |= 0x40;
305+ if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
306+ sb[8] |= 0x20;
307+ }
308+ sb[9] = tf->lbal;
309+ sb[10] = tf->lbam;
310+ sb[11] = tf->lbah;
311+ }
312+}
313+
233314 static void ata_scsi_set_invalid_field(struct ata_device *dev,
234315 struct scsi_cmnd *cmd, u16 field, u8 bit)
235316 {
@@ -711,7 +792,6 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) · 475 unmodified lines
711792
712793 /**
713794 * ata_to_sense_error - convert ATA error to SCSI error
714− * @id: ATA device number
715795 * @drv_stat: value contained in ATA status register
716796 * @drv_err: value contained in ATA error register
717797 * @sk: the sense key we'll fill out
@@ -725,8 +805,8 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) · 7 unmodified lines
725805 * LOCKING:
726806 * spin_lock_irqsave(host lock)
727807 */
728−static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk,
729− u8 *asc, u8 *ascq)
808+static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc,
809+ u8 *ascq)
730810 {
731811 int i;
732812
@@ -837,10 +917,8 @@ static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, · 104 unmodified lines
837917 * ata_gen_passthru_sense - Generate check condition sense block.
838918 * @qc: Command that completed.
839919 *
840− * This function is specific to the ATA descriptor format sense
841− * block specified for the ATA pass through commands. Regardless
842− * of whether the command errored or not, return a sense
843− * block. Copy all controller registers into the sense
920+ * This function is specific to the ATA pass through commands.
921+ * Regardless of whether the command errored or not, return a sense
844922 * block. If there was no error, we get the request from an ATA
845923 * passthrough command, so we use the following sense data:
846924 * sk = RECOVERED ERROR
@@ -852,13 +930,16 @@ static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, · 5 unmodified lines
852930 */
853931 static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
854932 {
933+ struct ata_device *dev = qc->dev;
855934 struct scsi_cmnd *cmd = qc->scsicmd;
856935 struct ata_taskfile *tf = &qc->result_tf;
857− unsigned char *sb = cmd->sense_buffer;
858− unsigned char *desc = sb + 8;
859936 u8 sense_key, asc, ascq;
860937
861− memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
938+ if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
939+ ata_dev_dbg(dev,
940+ "missing result TF: can't generate ATA PT sense data\n");
941+ return;
942+ }
862943
863944 /*
864945 * Use ata_to_sense_error() to map status register bits
@@ -866,71 +947,12 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) · 1 unmodified line
866947 */
867948 if (qc->err_mask ||
868949 tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
869− ata_to_sense_error(qc->ap->print_id, tf->status, tf->error,
950+ ata_to_sense_error(tf->status, tf->error,
870951 &sense_key, &asc, &ascq);
871952 ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq);
872953 } else {
873− /*
874− * ATA PASS-THROUGH INFORMATION AVAILABLE
875− * Always in descriptor format sense.
876− */
877− scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
878− }
879−
880− if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
881− u8 len;
882−
883− /* descriptor format */
884− len = sb[7];
885− desc = (char *)scsi_sense_desc_find(sb, len + 8, 9);
886− if (!desc) {
887− if (SCSI_SENSE_BUFFERSIZE < len + 14)
888− return;
889− sb[7] = len + 14;
890− desc = sb + 8 + len;
891− }
892− desc[0] = 9;
893− desc[1] = 12;
894− /*
895− * Copy registers into sense buffer.
896− */
897− desc[2] = 0x00;
898− desc[3] = tf->error;
899− desc[5] = tf->nsect;
900− desc[7] = tf->lbal;
901− desc[9] = tf->lbam;
902− desc[11] = tf->lbah;
903− desc[12] = tf->device;
904− desc[13] = tf->status;
905−
906− /*
907− * Fill in Extend bit, and the high order bytes
908− * if applicable.
909− */
910− if (tf->flags & ATA_TFLAG_LBA48) {
911− desc[2] |= 0x01;
912− desc[4] = tf->hob_nsect;
913− desc[6] = tf->hob_lbal;
914− desc[8] = tf->hob_lbam;
915− desc[10] = tf->hob_lbah;
916− }
917− } else {
918− /* Fixed sense format */
919− desc[0] = tf->error;
920− desc[1] = tf->status;
921− desc[2] = tf->device;
922− desc[3] = tf->nsect;
923− desc[7] = 0;
924− if (tf->flags & ATA_TFLAG_LBA48) {
925− desc[8] |= 0x80;
926− if (tf->hob_nsect)
927− desc[8] |= 0x40;
928− if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah)
929− desc[8] |= 0x20;
930− }
931− desc[9] = tf->lbal;
932− desc[10] = tf->lbam;
933− desc[11] = tf->lbah;
954+ /* ATA PASS-THROUGH INFORMATION AVAILABLE */
955+ ata_scsi_set_sense(qc->dev, cmd, RECOVERED_ERROR, 0, 0x1D);
934956 }
935957 }
936958
@@ -953,20 +975,25 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) · 16 unmodified lines
953975 u64 block;
954976 u8 sense_key, asc, ascq;
955977
956− memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
957−
958978 if (ata_dev_disabled(dev)) {
959979 /* Device disabled after error recovery */
960980 /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */
961981 ata_scsi_set_sense(dev, cmd, NOT_READY, 0x04, 0x21);
962982 return;
963983 }
984+
985+ if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) {
986+ ata_dev_dbg(dev,
987+ "missing result TF: can't generate sense data\n");
988+ return;
989+ }
990+
964991 /* Use ata_to_sense_error() to map status register bits
965992 * onto sense key, asc & ascq.
966993 */
967994 if (qc->err_mask ||
968995 tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
969− ata_to_sense_error(qc->ap->print_id, tf->status, tf->error,
996+ ata_to_sense_error(tf->status, tf->error,
970997 &sense_key, &asc, &ascq);
971998 ata_scsi_set_sense(dev, cmd, sense_key, asc, ascq);
972999 } else {
@@ -1631,26 +1658,32 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) · 658 unmodified lines
16311658 {
16321659 struct scsi_cmnd *cmd = qc->scsicmd;
16331660 u8 *cdb = cmd->cmnd;
1634− int need_sense = (qc->err_mask != 0) &&
1635− !(qc->flags & ATA_QCFLAG_SENSE_VALID);
1661+ bool have_sense = qc->flags & ATA_QCFLAG_SENSE_VALID;
1662+ bool is_ata_passthru = cdb[0] == ATA_16 || cdb[0] == ATA_12;
1663+ bool is_ck_cond_request = cdb[2] & 0x20;
1664+ bool is_error = qc->err_mask != 0;
16361665
16371666 /* For ATA pass thru (SAT) commands, generate a sense block if
16381667 * user mandated it or if there's an error. Note that if we
1639− * generate because the user forced us to [CK_COND =1], a check
1668+ * generate because the user forced us to [CK_COND=1], a check
16401669 * condition is generated and the ATA register values are returned
16411670 * whether the command completed successfully or not. If there
1642− * was no error, we use the following sense data:
1671+ * was no error, and CK_COND=1, we use the following sense data:
16431672 * sk = RECOVERED ERROR
16441673 * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE
16451674 */
1646− if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
1647− ((cdb[2] & 0x20) || need_sense))
1648− ata_gen_passthru_sense(qc);
1649− else if (need_sense)
1675+ if (is_ata_passthru && (is_ck_cond_request || is_error || have_sense)) {
1676+ if (!have_sense)
1677+ ata_gen_passthru_sense(qc);
1678+ ata_scsi_set_passthru_sense_fields(qc);
1679+ if (is_ck_cond_request)
1680+ set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION);
1681+ } else if (is_error && !have_sense) {
16501682 ata_gen_ata_sense(qc);
1651− else
1683+ } else {
16521684 /* Keep the SCSI ML and status byte, clear host byte. */
16531685 cmd->result &= 0x0000ffff;
1686+ }
16541687
16551688 ata_qc_done(qc);
16561689 }
@@ -2589,14 +2622,8 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) · 932 unmodified lines
25892622 /* handle completion from EH */
25902623 if (unlikely(err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID)) {
25912624
2592− if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) {
2593− /* FIXME: not quite right; we don't want the
2594− * translation of taskfile registers into a
2595− * sense descriptors, since that's only
2596− * correct for ATA, not ATAPI
2597− */
2625+ if (!(qc->flags & ATA_QCFLAG_SENSE_VALID))
25982626 ata_gen_passthru_sense(qc);
2599− }
26002627
26012628 /* SCSI EH automatically locks door if sdev->locked is
26022629 * set. Sometimes door lock request continues to
drivers/ata/libata-transport.c+4−1
@@ -217,7 +217,8 @@ static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL) · 216 unmodified lines
217217
218218 ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int);
219219 ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long);
220−ata_port_simple_attr(local_port_no, port_no, "%u\n", unsigned int);
220+/* We want the port_no sysfs attibute to start at 1 (ap->port_no starts at 0) */
221+ata_port_simple_attr(port_no + 1, port_no, "%u\n", unsigned int);
221222
222223 static DECLARE_TRANSPORT_CLASS(ata_port_class,
223224 "ata_port", NULL, NULL, NULL);
@@ -265,6 +266,7 @@ void ata_tport_delete(struct ata_port *ap) · 41 unmodified lines
265266 transport_destroy_device(dev);
266267 put_device(dev);
267268 }
269+EXPORT_SYMBOL_GPL(ata_tport_delete);
268270
269271 static const struct device_type ata_port_sas_type = {
270272 .name = ATA_PORT_TYPE_NAME,
@@ -329,6 +331,7 @@ int ata_tport_add(struct device *parent, · 58 unmodified lines
329331 put_device(dev);
330332 return error;
331333 }
334+EXPORT_SYMBOL_GPL(ata_tport_add);
332335
333336 /**
334337 * ata_port_classify - determine device type based on ATA-spec signature
drivers/ata/libata-transport.h+0−3
@@ -8,9 +8,6 @@ extern struct scsi_transport_template *ata_scsi_transport_template; · 7 unmodified lines
88 int ata_tlink_add(struct ata_link *link);
99 void ata_tlink_delete(struct ata_link *link);
1010
11−int ata_tport_add(struct device *parent, struct ata_port *ap);
12−void ata_tport_delete(struct ata_port *ap);
13−
1411 struct scsi_transport_template *ata_attach_transport(void);
1512 void ata_release_transport(struct scsi_transport_template *t);
1613
drivers/ata/libata.h+0−2
@@ -32,7 +32,6 @@ enum { · 31 unmodified lines
3232
3333 #define ATA_PORT_TYPE_NAME "ata_port"
3434
35−extern atomic_t ata_print_id;
3635 extern int atapi_passthru16;
3736 extern int libata_fua;
3837 extern int libata_noacpi;
@@ -82,7 +81,6 @@ extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp); · 43 unmodified lines
8281 extern int sata_link_init_spd(struct ata_link *link);
8382 extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
8483 extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
85−extern struct ata_port *ata_port_alloc(struct ata_host *host);
8684 extern const char *sata_spd_string(unsigned int spd);
8785 extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
8886 u8 page, void *buf, unsigned int sectors);
drivers/scsi/libsas/sas_ata.c+10−12
@@ -572,15 +572,6 @@ static struct ata_port_operations sas_sata_ops = { · 571 unmodified lines
572572 .end_eh = sas_ata_end_eh,
573573 };
574574
575−static struct ata_port_info sata_port_info = {
576− .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ |
577− ATA_FLAG_SAS_HOST | ATA_FLAG_FPDMA_AUX,
578− .pio_mask = ATA_PIO4,
579− .mwdma_mask = ATA_MWDMA2,
580− .udma_mask = ATA_UDMA6,
581− .port_ops = &sas_sata_ops
582−};
583−
584575 int sas_ata_init(struct domain_device *found_dev)
585576 {
586577 struct sas_ha_struct *ha = found_dev->port->ha;
@@ -597,18 +588,25 @@ int sas_ata_init(struct domain_device *found_dev) · 10 unmodified lines
597588
598589 ata_host_init(ata_host, ha->dev, &sas_sata_ops);
599590
600− ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost);
591+ ap = ata_port_alloc(ata_host);
601592 if (!ap) {
602− pr_err("ata_sas_port_alloc failed.\n");
593+ pr_err("ata_port_alloc failed.\n");
603594 rc = -ENODEV;
604595 goto free_host;
605596 }
606597
598+ ap->port_no = 0;
599+ ap->pio_mask = ATA_PIO4;
600+ ap->mwdma_mask = ATA_MWDMA2;
601+ ap->udma_mask = ATA_UDMA6;
602+ ap->flags |= ATA_FLAG_SATA | ATA_FLAG_PIO_DMA | ATA_FLAG_NCQ |
603+ ATA_FLAG_SAS_HOST | ATA_FLAG_FPDMA_AUX;
604+ ap->ops = &sas_sata_ops;
607605 ap->private_data = found_dev;
608606 ap->cbl = ATA_CBL_SATA;
609607 ap->scsi_host = shost;
610608
611− rc = ata_sas_tport_add(ata_host->dev, ap);
609+ rc = ata_tport_add(ata_host->dev, ap);
612610 if (rc)
613611 goto free_port;
614612
drivers/scsi/libsas/sas_discover.c+1−1
@@ -300,7 +300,7 @@ void sas_free_device(struct kref *kref) · 299 unmodified lines
300300 kfree(dev->ex_dev.ex_phy);
301301
302302 if (dev_is_sata(dev) && dev->sata_dev.ap) {
303− ata_sas_tport_delete(dev->sata_dev.ap);
303+ ata_tport_delete(dev->sata_dev.ap);
304304 ata_port_free(dev->sata_dev.ap);
305305 ata_host_put(dev->sata_dev.ata_host);
306306 dev->sata_dev.ata_host = NULL;
include/linux/libata.h+4−7
@@ -814,7 +814,6 @@ struct ata_port { · 813 unmodified lines
814814 /* Flags that change dynamically, protected by ap->lock */
815815 unsigned int pflags; /* ATA_PFLAG_xxx */
816816 unsigned int print_id; /* user visible unique port ID */
817− unsigned int local_port_no; /* host local port num */
818817 unsigned int port_no; /* 0 based port no. inside the host */
819818
820819 #ifdef CONFIG_ATA_SFF
@@ -1069,7 +1068,7 @@ extern int sata_std_hardreset(struct ata_link *link, unsigned int *class, · 248 unmodified lines
10691068 unsigned long deadline);
10701069 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
10711070
1072−extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
1071+extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports);
10731072 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
10741073 const struct ata_port_info * const * ppi, int n_ports);
10751074 extern void ata_host_get(struct ata_host *host);
@@ -1082,7 +1081,6 @@ extern int ata_host_activate(struct ata_host *host, int irq, · 6 unmodified lines
10821081 const struct scsi_host_template *sht);
10831082 extern void ata_host_detach(struct ata_host *host);
10841083 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
1085−extern int ata_scsi_detect(struct scsi_host_template *sht);
10861084 extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
10871085 void __user *arg);
10881086 #ifdef CONFIG_COMPAT
@@ -1246,12 +1244,11 @@ extern int sata_link_debounce(struct ata_link *link, · 157 unmodified lines
12461244 extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
12471245 bool spm_wakeup);
12481246 extern int ata_slave_link_init(struct ata_port *ap);
1249−extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
1250− struct ata_port_info *, struct Scsi_Host *);
12511247 extern void ata_port_probe(struct ata_port *ap);
1248+extern struct ata_port *ata_port_alloc(struct ata_host *host);
12521249 extern void ata_port_free(struct ata_port *ap);
1253−extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
1254−extern void ata_sas_tport_delete(struct ata_port *ap);
1250+extern int ata_tport_add(struct device *parent, struct ata_port *ap);
1251+extern void ata_tport_delete(struct ata_port *ap);
12551252 int ata_sas_device_configure(struct scsi_device *sdev, struct queue_limits *lim,
12561253 struct ata_port *ap);
12571254 extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t