pata_sis fixes and driver cleanup
v2 cover pata_sis fixes and driver cleanup
This started as just two patches to use the correct UDMA 100 timings on chipsets not supporting UDMA 133 but has grown a bit. This resubmit fixes the following issues, much of them pointed out by Sergei Shtylyov:
* Ensure 0xC0 is used to mask, not 0xE0
* Move all 'static const' changes to separate patch
* Formatting cleanups- don't introduce new formatting issues, and add a patch to fix existing ones
* Comment referred to bit 14, but it is bit 30 as we grab a word, not two bytes
* Use dev_info(), not printk() directly
* Adjust commit message to include old commit summary
The first two patches are the critical ones that fix a regression between the old IDE stack and the new (P)ATA one.
Dan McGee (5):
pata_sis: extract a sis_port_base() method
pata_sis: add mode_filter method for certain sis5513 chipsets
pata_sis: enable MWDMA for UDMA 133 chipset
pata_sis: mark most const data static as well
pata_sis: code style cleanups for consistency
drivers/ata/pata_sis.c | 154 +++++++++++++++++++++++++++++++----------------- 1 files changed, 99 insertions(+), 55 deletions(-)
$ python2 scripts/bloat-o-meter pata_sis.ko.old drivers/ata/pata_sis.ko add/remove: 8/0 grow/shrink: 5/6 up/down: 313/-251 (62) function old new delta static.sis_port_base - 83 +83 sis_133_mode_filter - 82 +82 static.udma_bits 7 31 +24 sis_init_one 695 719 +24 static.timing133 - 20 +20 static.timing100 - 20 +20 static.timing_u133 28 40 +12 static.timing_u100 28 40 +12 static.mwdma_bits - 12 +12 sis_133_set_dmamode 195 204 +9 static.recovery - 5 +5 static.actrec - 5 +5 static.active - 5 +5 sis_100_set_piomode 129 111 -18 sis_old_set_dmamode 192 171 -21 sis_100_set_dmamode 156 134 -22 sis_old_set_piomode 229 193 -36 sis_66_set_dmamode 216 171 -45 sis_133_set_piomode 265 156 -109
$ size pata_sis.ko.old drivers/ata/pata_sis.ko text data bss dec hex filename 4524 2724 4 7252 1c54 pata_sis.ko.old 4649 2724 4 7377 1cd1 drivers/ata/pata_sis.ko
Signature · 1 line
1.7.6.1
PATCH v2 1/5 pata_sis: extract a sis_port_base() method
This is similar to the existing sis_old_port_base() method. We do this same calculation and logic in multiple places (with one more to come in a future patch), so extracting it into a method makes sense.
--- drivers/ata/pata_sis.c | 46 ++++++++++++++++++++++++++++------------------ 1 files changed, 28 insertions(+), 18 deletions(-)
drivers/ata/pata_sis.c +28 -18
@@ -89,6 +89,29 @@ static int sis_old_port_base(struct ata_device *adev) }/** +* sis_port_base - return PCI configuration base for dev +* @adev: device +* +* Returns the base of the PCI configuration registers for this port +* number. +*/ + +static int sis_port_base (struct ata_device *adev) +{ +struct ata_port *ap = adev->link->ap; +struct pci_dev *pdev =to_pci_dev (ap->host->dev); +int port =0x40 ; +u32 reg54; + +/* If bit 30 is set then the registers are mapped at 0x70 not 0x40 */ +pci_read_config_dword (pdev,0x54 , ®54); +if (reg54 &0x40000000 ) + port =0x70 ; + +return port + (8 * ap->port_no) + (4 * adev->devno); +} + +/** * sis_133_cable_detect - check for 40/80 pin * @ap: Port * @deadline: deadline jiffies for the operation
@@ -266,9 +289,8 @@ static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)static void sis_133_set_piomode (struct ata_port *ap,struct ata_device *adev) {struct pci_dev *pdev =to_pci_dev (ap->host->dev); -int port =0x40 ; +int port;u32 t1; -u32 reg54;int speed = adev->pio_mode -XFER_PIO_0 ;const u32 timing133[] = {
@@ -288,12 +310,7 @@ static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)sis_set_fifo (ap, adev); -/* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ -pci_read_config_dword (pdev,0x54 , ®54); -if (reg54 &0x40000000 ) - port =0x70 ; - port +=8 * ap->port_no +4 * adev->devno; - + port =sis_port_base (adev);pci_read_config_dword (pdev, port, &t1); t1 &=0xC0C00FFF ;/* Mask out timing */
@@ -465,21 +482,14 @@ static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *astatic void sis_133_set_dmamode (struct ata_port *ap,struct ata_device *adev) {struct pci_dev *pdev =to_pci_dev (ap->host->dev); -int speed = adev->dma_mode -XFER_MW_DMA_0 ; -int port =0x40 ; +int port;u32 t1; -u32 reg54;/* bits 4- cycle time 8 - cvs time */ static const u32 timing_u100[] = {0x6B0 ,0x470 ,0x350 ,0x140 ,0x120 ,0x110 ,0x000 };static const u32 timing_u133[] = {0x9F0 ,0x6A0 ,0x470 ,0x250 ,0x230 ,0x220 ,0x210 }; -/* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ -pci_read_config_dword (pdev,0x54 , ®54); -if (reg54 &0x40000000 ) - port =0x70 ; - port += (8 * ap->port_no) + (4 * adev->devno); - + port =sis_port_base (adev);pci_read_config_dword (pdev, port, &t1);if (adev->dma_mode <XFER_UDMA_0 ) {
@@ -487,7 +497,7 @@ static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)/* FIXME: need data sheet to add MWDMA here. Also lacking on ide/pci driver */ }else { - speed = adev->dma_mode -XFER_UDMA_0 ; +int speed = adev->dma_mode -XFER_UDMA_0 ;/* if & 8 no UDMA133 - need info for ... */ t1 &= ~0x00000FF0 ; t1 |=0x00000004 ;
Signature · 1 line
1.7.6.1
PATCH v2 2/5 pata_sis: add mode_filter method for certain sis5513 chipsets
In reply to Dan McGeeThis mirrors a very old commit (3160d5416f39da9d9, "sis5513: add ->udma_filter method for chipset_family >= ATA_133") to the old sis5513 IDE driver that prevents certain setups from working.
UDMA6 (ATA/133) is not supported on some chipsets and we need to ensure this mode is not chosen even if a connected drive supports it. Port this old patch forward to the new PATA driver to ensure UDMA5 is the highest mode used if that is what is supported.
Kernel bugzilla #41582.
--- drivers/ata/pata_sis.c | 27 ++++++++++++++++++++++++++- 1 files changed, 26 insertions(+), 1 deletions(-)
drivers/ata/pata_sis.c +26 -1
@@ -509,6 +509,27 @@ static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)pci_write_config_dword (pdev, port, t1); } +/** +* sis_133_mode_filter - mode selection filter +* @adev: ATA device +* +* Block UDMA6 on devices that do not support it. +*/ + +static unsigned long sis_133_mode_filter (struct ata_device *adev,unsigned long mask) +{ +struct ata_port *ap = adev->link->ap; +struct pci_dev *pdev =to_pci_dev (ap->host->dev); +int port =sis_port_base (adev); +u32 t1; + +pci_read_config_dword (pdev, port, &t1); +/* if ATA133 is disabled, mask it out */ +if (!(t1 &0x08 )) + mask &= ~(0xC0 <<ATA_SHIFT_UDMA ); +return mask; +} +static struct scsi_host_template sis_sht = {ATA_BMDMA_SHT (DRV_NAME ), };
@@ -530,6 +551,7 @@ static struct ata_port_operations sis_133_ops = { .set_piomode = sis_133_set_piomode, .set_dmamode = sis_133_set_dmamode, .cable_detect = sis_133_cable_detect, + .mode_filter = sis_133_mode_filter, };static struct ata_port_operations sis_133_early_ops = {
@@ -779,10 +801,13 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)switch (trueid) {case 0x5518 :/* SIS 962/963 */ +dev_info (&pdev->dev, +"SiS 962/963 MuTIOL IDE UDMA133 controller\n" ); chipset = &sis133;if ((idemisc &0x40000000 ) ==0 ) {pci_write_config_dword (pdev,0x54 , idemisc |0x40000000 ); -printk (KERN_INFO "SIS5513: Switching to 5513 register mapping\n" ); +dev_info (&pdev->dev, +"Switching to 5513 register mapping\n" ); }break ;case 0x0180 :/* SIS 965/965L */
Signature · 1 line
1.7.6.1
PATCH v2 3/5 pata_sis: enable MWDMA for UDMA 133 chipset
In reply to Dan McGeeThis ports the timing values over from the old IDE driver into the new PATA-based one. The comment was lying when it stated the old driver was not MWDMA capable.
Boot tested on actual hardware using 'libata.force=mwdma2'.
--- drivers/ata/pata_sis.c | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-)
drivers/ata/pata_sis.c +17 -8
@@ -485,21 +485,30 @@ static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)int port;u32 t1; -/* bits 4- cycle time 8 - cvs time */ -static const u32 timing_u100[] = {0x6B0 ,0x470 ,0x350 ,0x140 ,0x120 ,0x110 ,0x000 }; -static const u32 timing_u133[] = {0x9F0 ,0x6A0 ,0x470 ,0x250 ,0x230 ,0x220 ,0x210 }; - port =sis_port_base (adev);pci_read_config_dword (pdev, port, &t1);if (adev->dma_mode <XFER_UDMA_0 ) { +/* Recovery << 24 | Act << 16 | Ini << 12, like PIO modes */ +static const u32 timing_u100[] = {0x19154000 ,0x06072000 ,0x04062000 }; +static const u32 timing_u133[] = {0x221C6000 ,0x0C0A3000 ,0x05093000 }; +int speed = adev->dma_mode -XFER_MW_DMA_0 ; + + t1 &=0xC0C00FFF ; +/* disable UDMA */ t1 &= ~0x00000004 ; -/* FIXME: need data sheet to add MWDMA here. Also lacking on -ide/pci driver */ +if (t1 &0x08 ) + t1 |= timing_u133[speed]; +else + t1 |= timing_u100[speed]; }else { +/* bits 4- cycle time 8 - cvs time */ +static const u32 timing_u100[] = {0x6B0 ,0x470 ,0x350 ,0x140 ,0x120 ,0x110 ,0x000 }; +static const u32 timing_u133[] = {0x9F0 ,0x6A0 ,0x470 ,0x250 ,0x230 ,0x220 ,0x210 };int speed = adev->dma_mode -XFER_UDMA_0 ; -/* if & 8 no UDMA133 - need info for ... */ + t1 &= ~0x00000FF0 ; +/* enable UDMA */ t1 |=0x00000004 ;if (t1 &0x08 ) t1 |= timing_u133[speed];
@@ -620,7 +629,7 @@ static const struct ata_port_info sis_info100_early = {static const struct ata_port_info sis_info133 = { .flags =ATA_FLAG_SLAVE_POSS , .pio_mask =ATA_PIO4 , -/* No MWDMA */ + .mwdma_mask =ATA_MWDMA2 , .udma_mask =ATA_UDMA6 , .port_ops = &sis_133_ops, };
Signature · 1 line
1.7.6.1
PATCH v2 4/5 pata_sis: mark most const data static as well
In reply to Dan McGeeThis pushes timing and other values into preinitialized read-only data sections rather than being inlined into the code. None of these functions are called more than a handful of times, so reducing code size makes sense.
--- drivers/ata/pata_sis.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
drivers/ata/pata_sis.c +10 -10
@@ -231,8 +231,8 @@ static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)u8 t1, t2;int speed = adev->pio_mode -XFER_PIO_0 ; -const u8 active[] = {0x00 ,0x07 ,0x04 ,0x03 ,0x01 }; -const u8 recovery[] = {0x00 ,0x06 ,0x04 ,0x03 ,0x03 }; +static const u8 active[] = {0x00 ,0x07 ,0x04 ,0x03 ,0x01 }; +static const u8 recovery[] = {0x00 ,0x06 ,0x04 ,0x03 ,0x03 };sis_set_fifo (ap, adev);
@@ -267,7 +267,7 @@ static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)int port =sis_old_port_base (adev);int speed = adev->pio_mode -XFER_PIO_0 ; -const u8 actrec[] = {0x00 ,0x67 ,0x44 ,0x33 ,0x31 }; +static const u8 actrec[] = {0x00 ,0x67 ,0x44 ,0x33 ,0x31 };sis_set_fifo (ap, adev);
@@ -293,14 +293,14 @@ static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)u32 t1;int speed = adev->pio_mode -XFER_PIO_0 ; -const u32 timing133[] = { +static const u32 timing133[] = {0x28269000 ,/* Recovery << 24 | Act << 16 | Ini << 12 */ 0x0C266000 ,0x04263000 ,0x0C0A3000 ,0x05093000 }; -const u32 timing100[] = { +static const u32 timing100[] = {0x1E1C6000 ,/* Recovery << 24 | Act << 16 | Ini << 12 */ 0x091C4000 ,0x031C2000 ,
@@ -341,8 +341,8 @@ static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)int drive_pci =sis_old_port_base (adev);u16 timing; -const u16 mwdma_bits[] = {0x008 ,0x302 ,0x301 }; -const u16 udma_bits[] = {0xE000 ,0xC000 ,0xA000 }; +static const u16 mwdma_bits[] = {0x008 ,0x302 ,0x301 }; +static const u16 udma_bits[] = {0xE000 ,0xC000 ,0xA000 };pci_read_config_word (pdev, drive_pci, &timing);
@@ -381,8 +381,8 @@ static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)u16 timing;/* MWDMA 0-2 and UDMA 0-5 */ -const u16 mwdma_bits[] = {0x008 ,0x302 ,0x301 }; -const u16 udma_bits[] = {0xF000 ,0xD000 ,0xB000 ,0xA000 ,0x9000 ,0x8000 }; +static const u16 mwdma_bits[] = {0x008 ,0x302 ,0x301 }; +static const u16 udma_bits[] = {0xF000 ,0xD000 ,0xB000 ,0xA000 ,0x9000 ,0x8000 };pci_read_config_word (pdev, drive_pci, &timing);
@@ -419,7 +419,7 @@ static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)int drive_pci =sis_old_port_base (adev);u8 timing; -const u8 udma_bits[] = {0x8B ,0x87 ,0x85 ,0x83 ,0x82 ,0x81 }; +static const u8 udma_bits[] = {0x8B ,0x87 ,0x85 ,0x83 ,0x82 ,0x81 };pci_read_config_byte (pdev, drive_pci +1 , &timing);
Signature · 1 line
1.7.6.1
PATCH v2 5/5 pata_sis: code style cleanups for consistency
In reply to Dan McGeeRemove a lot of ' ' (double spaces) as well as ensuring use of tabs vs. spaces is appropriate and consistent.
--- drivers/ata/pata_sis.c | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-)
drivers/ata/pata_sis.c +19 -19
@@ -55,7 +55,7 @@ static const struct sis_laptop sis_laptop[] = {/* devid, subvendor, subdev */ { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */ - { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */ + { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 *//* end marker */ { 0, } };
@@ -76,7 +76,7 @@ static int sis_short_ata40(struct pci_dev *dev) }/** -* sis_old_port_base - return PCI configuration base for dev +* sis_old_port_base - return PCI configuration base for dev * @adev: device * * Returns the base of the PCI configuration registers for this port
@@ -85,11 +85,11 @@ static int sis_short_ata40(struct pci_dev *dev)static int sis_old_port_base (struct ata_device *adev) { -return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno); +return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno); }/** -* sis_port_base - return PCI configuration base for dev +* sis_port_base - return PCI configuration base for dev * @adev: device * * Returns the base of the PCI configuration registers for this port
@@ -112,7 +112,7 @@ static int sis_port_base(struct ata_device *adev) }/** -* sis_133_cable_detect - check for 40/80 pin +* sis_133_cable_detect - check for 40/80 pin * @ap: Port * @deadline: deadline jiffies for the operation *
@@ -133,7 +133,7 @@ static int sis_133_cable_detect(struct ata_port *ap) }/** -* sis_66_cable_detect - check for 40/80 pin +* sis_66_cable_detect - check for 40/80 pin * @ap: Port * * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
@@ -155,7 +155,7 @@ static int sis_66_cable_detect(struct ata_port *ap)/** -* sis_pre_reset - probe begin +* sis_pre_reset - probe begin * @link: ATA link * @deadline: deadline jiffies for the operation *
@@ -183,7 +183,7 @@ static int sis_pre_reset(struct ata_link *link, unsigned long deadline)/** -* sis_set_fifo - Set RWP fifo bits for this device +* sis_set_fifo - Set RWP fifo bits for this device * @ap: Port * @adev: Device *
@@ -226,7 +226,7 @@ static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)static void sis_old_set_piomode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int port =sis_old_port_base (adev);u8 t1, t2;int speed = adev->pio_mode -XFER_PIO_0 ;
@@ -263,7 +263,7 @@ static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)static void sis_100_set_piomode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int port =sis_old_port_base (adev);int speed = adev->pio_mode -XFER_PIO_0 ;
@@ -288,7 +288,7 @@ static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)static void sis_133_set_piomode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int port;u32 t1;int speed = adev->pio_mode -XFER_PIO_0 ;
@@ -336,7 +336,7 @@ static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)static void sis_old_set_dmamode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int speed = adev->dma_mode -XFER_MW_DMA_0 ;int drive_pci =sis_old_port_base (adev);u16 timing;
@@ -375,7 +375,7 @@ static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)static void sis_66_set_dmamode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int speed = adev->dma_mode -XFER_MW_DMA_0 ;int drive_pci =sis_old_port_base (adev);u16 timing;
@@ -414,7 +414,7 @@ static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)static void sis_100_set_dmamode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int speed = adev->dma_mode -XFER_MW_DMA_0 ;int drive_pci =sis_old_port_base (adev);u8 timing;
@@ -448,7 +448,7 @@ static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)static void sis_133_early_set_dmamode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int speed = adev->dma_mode -XFER_MW_DMA_0 ;int drive_pci =sis_old_port_base (adev);u8 timing;
@@ -481,7 +481,7 @@ static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *astatic void sis_133_set_dmamode (struct ata_port *ap,struct ata_device *adev) { -struct pci_dev *pdev =to_pci_dev (ap->host->dev); +struct pci_dev *pdev =to_pci_dev (ap->host->dev);int port;u32 t1;
@@ -710,7 +710,7 @@ static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)* @pdev: PCI device to register * @ent: Entry in sis_pci_tbl matching with @pdev * -* Called from kernel PCI layer. We probe for combined mode (sigh), +* Called from kernel PCI layer. We probe for combined mode (sigh), * and then hand over control to libata, for it to do the rest. * * LOCKING:
@@ -820,10 +820,10 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) }break ;case 0x0180 :/* SIS 965/965L */ - chipset = &sis133; + chipset = &sis133;break ;case 0x1180 :/* SIS 966/966L */ - chipset = &sis133; + chipset = &sis133;break ; } }
Signature · 1 line
1.7.6.1