Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: fix read_id() ata port operation interface

Drivers that need to tweak a device IDENTIFY data implement the
read_id() port operation. The IDENTIFY data buffer is passed as an
argument to the read_id() operation for drivers to use. However, when
this operation is called, the IDENTIFY data is not yet converted to CPU
endian and contains le16 words.

Change the interface of the read_id operation to pass a __le16 * pointer
to the IDENTIFY data buffer to clarify the buffer endianness. Fix the
pata_netcell, pata_it821x, ahci_xgene, ahci_ceva and ahci_brcm drivers
implementation of this operation and modify the code to corretly deal
with identify data words manipulation to avoid sparse warnings such as:

drivers/ata/ahci_xgene.c:262:33: warning: invalid assignment: &=
drivers/ata/ahci_xgene.c:262:33: left side has type unsigned short
drivers/ata/ahci_xgene.c:262:33: right side has type restricted __le16

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>

+24 -24
+1 -1
drivers/ata/ahci_brcm.c
··· 246 246 } 247 247 248 248 static unsigned int brcm_ahci_read_id(struct ata_device *dev, 249 - struct ata_taskfile *tf, u16 *id) 249 + struct ata_taskfile *tf, __le16 *id) 250 250 { 251 251 struct ata_port *ap = dev->link->ap; 252 252 struct ata_host *host = ap->host;
+2 -3
drivers/ata/ahci_ceva.c
··· 92 92 }; 93 93 94 94 static unsigned int ceva_ahci_read_id(struct ata_device *dev, 95 - struct ata_taskfile *tf, u16 *id) 95 + struct ata_taskfile *tf, __le16 *id) 96 96 { 97 - __le16 *__id = (__le16 *)id; 98 97 u32 err_mask; 99 98 100 99 err_mask = ata_do_dev_read_id(dev, tf, id); ··· 103 104 * Since CEVA controller does not support device sleep feature, we 104 105 * need to clear DEVSLP (bit 8) in word78 of the IDENTIFY DEVICE data. 105 106 */ 106 - __id[ATA_ID_FEATURE_SUPP] &= cpu_to_le16(~(1 << 8)); 107 + id[ATA_ID_FEATURE_SUPP] &= cpu_to_le16(~(1 << 8)); 107 108 108 109 return 0; 109 110 }
+1 -1
drivers/ata/ahci_xgene.c
··· 237 237 * does not support DEVSLP. 238 238 */ 239 239 static unsigned int xgene_ahci_read_id(struct ata_device *dev, 240 - struct ata_taskfile *tf, u16 *id) 240 + struct ata_taskfile *tf, __le16 *id) 241 241 { 242 242 u32 err_mask; 243 243
+3 -3
drivers/ata/libata-core.c
··· 1722 1722 * this function is wrapped or replaced by the driver 1723 1723 */ 1724 1724 unsigned int ata_do_dev_read_id(struct ata_device *dev, 1725 - struct ata_taskfile *tf, u16 *id) 1725 + struct ata_taskfile *tf, __le16 *id) 1726 1726 { 1727 1727 return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE, 1728 1728 id, sizeof(id[0]) * ATA_ID_WORDS, 0); ··· 1795 1795 tf.flags |= ATA_TFLAG_POLLING; 1796 1796 1797 1797 if (ap->ops->read_id) 1798 - err_mask = ap->ops->read_id(dev, &tf, id); 1798 + err_mask = ap->ops->read_id(dev, &tf, (__le16 *)id); 1799 1799 else 1800 - err_mask = ata_do_dev_read_id(dev, &tf, id); 1800 + err_mask = ata_do_dev_read_id(dev, &tf, (__le16 *)id); 1801 1801 1802 1802 if (err_mask) { 1803 1803 if (err_mask & AC_ERR_NODEV_HINT) {
+11 -12
drivers/ata/pata_it821x.c
··· 537 537 */ 538 538 539 539 static unsigned int it821x_read_id(struct ata_device *adev, 540 - struct ata_taskfile *tf, u16 *id) 540 + struct ata_taskfile *tf, __le16 *id) 541 541 { 542 542 unsigned int err_mask; 543 543 unsigned char model_num[ATA_ID_PROD_LEN + 1]; ··· 545 545 err_mask = ata_do_dev_read_id(adev, tf, id); 546 546 if (err_mask) 547 547 return err_mask; 548 - ata_id_c_string(id, model_num, ATA_ID_PROD, sizeof(model_num)); 548 + ata_id_c_string((u16 *)id, model_num, ATA_ID_PROD, sizeof(model_num)); 549 549 550 - id[83] &= ~(1 << 12); /* Cache flush is firmware handled */ 551 - id[83] &= ~(1 << 13); /* Ditto for LBA48 flushes */ 552 - id[84] &= ~(1 << 6); /* No FUA */ 553 - id[85] &= ~(1 << 10); /* No HPA */ 554 - id[76] = 0; /* No NCQ/AN etc */ 550 + id[83] &= cpu_to_le16(~(1 << 12)); /* Cache flush is firmware handled */ 551 + id[84] &= cpu_to_le16(~(1 << 6)); /* No FUA */ 552 + id[85] &= cpu_to_le16(~(1 << 10)); /* No HPA */ 553 + id[76] = 0; /* No NCQ/AN etc */ 555 554 556 555 if (strstr(model_num, "Integrated Technology Express")) { 557 556 /* Set feature bits the firmware neglects */ 558 - id[49] |= 0x0300; /* LBA, DMA */ 559 - id[83] &= 0x7FFF; 560 - id[83] |= 0x4400; /* Word 83 is valid and LBA48 */ 561 - id[86] |= 0x0400; /* LBA48 on */ 562 - id[ATA_ID_MAJOR_VER] |= 0x1F; 557 + id[49] |= cpu_to_le16(0x0300); /* LBA, DMA */ 558 + id[83] &= cpu_to_le16(0x7FFF); 559 + id[83] |= cpu_to_le16(0x4400); /* Word 83 is valid and LBA48 */ 560 + id[86] |= cpu_to_le16(0x0400); /* LBA48 on */ 561 + id[ATA_ID_MAJOR_VER] |= cpu_to_le16(0x1F); 563 562 /* Clear the serial number because it's different each boot 564 563 which breaks validation on resume */ 565 564 memset(&id[ATA_ID_SERNO], 0x20, ATA_ID_SERNO_LEN);
+3 -2
drivers/ata/pata_netcell.c
··· 21 21 /* No PIO or DMA methods needed for this device */ 22 22 23 23 static unsigned int netcell_read_id(struct ata_device *adev, 24 - struct ata_taskfile *tf, u16 *id) 24 + struct ata_taskfile *tf, __le16 *id) 25 25 { 26 26 unsigned int err_mask = ata_do_dev_read_id(adev, tf, id); 27 + 27 28 /* Firmware forgets to mark words 85-87 valid */ 28 29 if (err_mask == 0) 29 - id[ATA_ID_CSF_DEFAULT] |= 0x4000; 30 + id[ATA_ID_CSF_DEFAULT] |= cpu_to_le16(0x4000); 30 31 return err_mask; 31 32 } 32 33
+3 -2
include/linux/libata.h
··· 884 884 void (*set_piomode)(struct ata_port *ap, struct ata_device *dev); 885 885 void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev); 886 886 int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev); 887 - unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf, u16 *id); 887 + unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf, 888 + __le16 *id); 888 889 889 890 void (*dev_config)(struct ata_device *dev); 890 891 ··· 1120 1119 extern void ata_id_c_string(const u16 *id, unsigned char *s, 1121 1120 unsigned int ofs, unsigned int len); 1122 1121 extern unsigned int ata_do_dev_read_id(struct ata_device *dev, 1123 - struct ata_taskfile *tf, u16 *id); 1122 + struct ata_taskfile *tf, __le16 *id); 1124 1123 extern void ata_qc_complete(struct ata_queued_cmd *qc); 1125 1124 extern u64 ata_qc_get_active(struct ata_port *ap); 1126 1125 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);