pata_jmicron: drop unnecessary device programming in [re]init
PATCH 1/3 pata_jmicron: drop unnecessary device programming in [re]init
Channel redirect and AHCI mode enable programmings are done via PCI quirk for both probe and resume paths. Drop duplicate and possibly unsafe device programming from pata_jmicron().
--- drivers/ata/pata_jmicron.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-)
drivers/ata/pata_jmicron.c +1 -31
@@ -202,43 +202,13 @@ static int jmicron_init_one (struct pci_ };struct ata_port_info *port_info[2 ] = { &info, &info }; -u32 reg; -/* PATA controller is fn 1, AHCI is fn 0 */ if (id->driver_data !=368 &&PCI_FUNC (pdev->devfn) !=1 )return -ENODEV ; -/* The 365/66 have two PATA channels, redirect the second */ -if (id->driver_data ==365 || id->driver_data ==366 ) { -pci_read_config_dword (pdev,0x80 , ®); - reg |= (1 <<24 );/* IDE1 to PATA IDE secondary */ -pci_write_config_dword (pdev,0x80 , reg); - } -return ata_pci_init_one (pdev, port_info,2 ); } -static int jmicron_reinit_one (struct pci_dev *pdev) -{ -u32 reg; - -switch (pdev->device) { -case PCI_DEVICE_ID_JMICRON_JMB368 : -break ; -case PCI_DEVICE_ID_JMICRON_JMB365 : -case PCI_DEVICE_ID_JMICRON_JMB366 : -/* Restore mapping or disks swap and boy does it get ugly */ -pci_read_config_dword (pdev,0x80 , ®); - reg |= (1 <<24 );/* IDE1 to PATA IDE secondary */ -pci_write_config_dword (pdev,0x80 , reg); -/* Fall through */ -default : -/* Make sure AHCI is turned back on */ -pci_write_config_byte (pdev,0x41 ,0xa1 ); - } -return ata_pci_device_resume (pdev); -} -static const struct pci_device_id jmicron_pci_tbl[] = { {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 ),361 }, {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB363 ),363 },
@@ -255,7 +225,7 @@ static struct pci_driver jmicron_pci_dri .probe = jmicron_init_one, .remove = ata_pci_remove_one, .suspend = ata_pci_device_suspend, - .resume = jmicron_reinit_one, + .resume = ata_pci_device_resume, };static int __init jmicron_init (void )
PATCH 2/3 jmicron ATA: reimplement jmicron ATA quirk
Reimplement jmicron ATA quirk.
* renamed to quirk_jmicron_ata()
* quirk is invoked only for the affected controllers
* programming is stricter. e.g. conf5 bit24 is cleared if unnecessary.
* code factored for readability
* JMB360 and JMB368 are programmed into proper mode
Verified on JMB360, 363 and 368.
--- drivers/pci/quirks.c | 80 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 30 deletions(-)
drivers/pci/quirks.c +50 -30
@@ -1218,45 +1218,65 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_V* do this early on to make the additional device appear during * the PCI scanning. */ - -static void quirk_jmicron_dualfn (struct pci_dev *pdev) +static void quirk_jmicron_ata (struct pci_dev *pdev) { -u32 conf; +u32 conf1, conf5;u8 hdr;/* Only poke fn 0 */ if (PCI_FUNC (pdev->devfn))return ; -switch (pdev->device) { -case PCI_DEVICE_ID_JMICRON_JMB365 : -case PCI_DEVICE_ID_JMICRON_JMB366 : -/* Redirect IDE second PATA port to the right spot */ -pci_read_config_dword (pdev,0x80 , &conf); - conf |= (1 <<24 ); -/* Fall through */ -pci_write_config_dword (pdev,0x80 , conf); -case PCI_DEVICE_ID_JMICRON_JMB361 : -case PCI_DEVICE_ID_JMICRON_JMB363 : -pci_read_config_dword (pdev,0x40 , &conf); -/* Enable dual function mode, AHCI on fn 0, IDE fn1 */ -/* Set the class codes correctly and then direct IDE 0 */ - conf &= ~0x000FF200 ;/* Clear bit 9 and 12-19 */ - conf |=0x00C2A102 ;/* Set 1, 8, 13, 15, 17, 22, 23 */ -pci_write_config_dword (pdev,0x40 , conf); - -/* Reconfigure so that the PCI scanner discovers the -device is now multifunction */ - -pci_read_config_byte (pdev,PCI_HEADER_TYPE , &hdr); - pdev->hdr_type = hdr &0x7f ; - pdev->multifunction = !!(hdr &0x80 ); +pci_read_config_dword (pdev,0x40 , &conf1); +pci_read_config_dword (pdev,0x80 , &conf5); + + conf1 &= ~0x00CFF302 ;/* Clear bit 1, 8, 9, 12-19, 22, 23 */ + conf5 &= ~(1 <<24 );/* Clear bit 24 */ + +switch (pdev->device) { +case PCI_DEVICE_ID_JMICRON_JMB360 : +/* The controller should be in single function ahci mode */ + conf1 |=0x0002A100 ;/* Set 8, 13, 15, 17 */ +break ; -break ; +case PCI_DEVICE_ID_JMICRON_JMB365 : +case PCI_DEVICE_ID_JMICRON_JMB366 : +/* Redirect IDE second PATA port to the right spot */ + conf5 |= (1 <<24 ); +/* Fall through */ +case PCI_DEVICE_ID_JMICRON_JMB361 : +case PCI_DEVICE_ID_JMICRON_JMB363 : +/* Enable dual function mode, AHCI on fn 0, IDE fn1 */ +/* Set the class codes correctly and then direct IDE 0 */ + conf1 |=0x00C2A102 ;/* Set 1, 8, 13, 15, 17, 22, 23 */ +break ; + +case PCI_DEVICE_ID_JMICRON_JMB368 : +/* The controller should be in single function IDE mode */ + conf1 |=0x00C00000 ;/* Set 22, 23 */ +break ; } -} -DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_ANY_ID , quirk_jmicron_dualfn); -DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_ANY_ID , quirk_jmicron_dualfn); + +pci_write_config_dword (pdev,0x40 , conf1); +pci_write_config_dword (pdev,0x80 , conf5); + +/* Update pdev accordingly */ +pci_read_config_byte (pdev,PCI_HEADER_TYPE , &hdr); + pdev->hdr_type = hdr &0x7f ; + pdev->multifunction = !!(hdr &0x80 ); +} +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB360 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB363 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB365 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB366 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB368 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB360 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB363 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB365 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB366 , quirk_jmicron_ata); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB368 , quirk_jmicron_ata);#endif
PATCH 3/3 ahci/pata_jmicron: match class not function number
Make jmiron_ata quirk update pdev->class after programming the device and update ahci and pata_jmicron such that they match class code instead of checking function number manually. For ahci, it matches for vendor and class. For pata_jmicron, it matches vendor, device and class as IDE class isn't as well defined as AHCI class.
This makes jmicron device matching more conventional and script friendly.
--- drivers/ata/ahci.c | 16 +++------------- drivers/ata/pata_jmicron.c | 19 ++++++++++--------- drivers/pci/quirks.c | 5 ++++- 3 files changed, 17 insertions(+), 23 deletions(-)
drivers/pci/quirks.c +4 -1
@@ -1220,7 +1220,7 @@ DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_V*/ static void quirk_jmicron_ata (struct pci_dev *pdev) { -u32 conf1, conf5; +u32 conf1, conf5, class;u8 hdr;/* Only poke fn 0 */
@@ -1264,6 +1264,9 @@ static void quirk_jmicron_ata(struct pcipci_read_config_byte (pdev,PCI_HEADER_TYPE , &hdr); pdev->hdr_type = hdr &0x7f ; pdev->multifunction = !!(hdr &0x80 ); + +pci_read_config_dword (pdev,PCI_CLASS_REVISION , &class); + pdev->class = class >>8 ; }DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB360 , quirk_jmicron_ata);DECLARE_PCI_FIXUP_EARLY (PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 , quirk_jmicron_ata);
drivers/ata/ahci.c +3 -13
@@ -385,12 +385,9 @@ static const struct pci_device_id ahci_p { PCI_VDEVICE(INTEL, 0x294d), board_ahci_pi }, /* ICH9 */ { PCI_VDEVICE(INTEL, 0x294e), board_ahci_pi }, /* ICH9M */ -/* JMicron */ - { PCI_VDEVICE(JMICRON, 0x2360), board_ahci_ign_iferr }, /* JMB360 */ - { PCI_VDEVICE(JMICRON, 0x2361), board_ahci_ign_iferr }, /* JMB361 */ - { PCI_VDEVICE(JMICRON, 0x2363), board_ahci_ign_iferr }, /* JMB363 */ - { PCI_VDEVICE(JMICRON, 0x2365), board_ahci_ign_iferr }, /* JMB365 */ - { PCI_VDEVICE(JMICRON, 0x2366), board_ahci_ign_iferr }, /* JMB366 */ +/* JMicron 360/1/3/5/6, match class to avoid IDE function */ + { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci_ign_iferr },/* ATI */ { PCI_VDEVICE(ATI, 0x4380), board_ahci }, /* ATI SB600 non-raid */
@@ -1665,13 +1662,6 @@ static int ahci_init_one(struct pci_devif (!printed_version++)dev_printk (KERN_DEBUG , &pdev->dev,"version " DRV_VERSION "\n" ); -if (pdev->vendor ==PCI_VENDOR_ID_JMICRON ) { -/* Function 1 is the PATA controller except on the 368, where -we are not AHCI anyway */ -if (PCI_FUNC (pdev->devfn)) -return -ENODEV ; - } - rc =pcim_enable_device (pdev);if (rc)return rc;
drivers/ata/pata_jmicron.c +10 -9
@@ -202,19 +202,20 @@ static int jmicron_init_one (struct pci_ };struct ata_port_info *port_info[2 ] = { &info, &info }; -/* PATA controller is fn 1, AHCI is fn 0 */ -if (id->driver_data !=368 &&PCI_FUNC (pdev->devfn) !=1 ) -return -ENODEV ; -return ata_pci_init_one (pdev, port_info,2 ); }static const struct pci_device_id jmicron_pci_tbl[] = { - {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 ),361 }, - {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB363 ),363 }, - {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB365 ),365 }, - {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB366 ),366 }, - {PCI_VDEVICE (JMICRON ,PCI_DEVICE_ID_JMICRON_JMB368 ),368 }, + {PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB361 , +PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_STORAGE_IDE <<8 ,0xffff00 ,361 }, + {PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB363 , +PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_STORAGE_IDE <<8 ,0xffff00 ,363 }, + {PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB365 , +PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_STORAGE_IDE <<8 ,0xffff00 ,365 }, + {PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB366 , +PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_STORAGE_IDE <<8 ,0xffff00 ,366 }, + {PCI_VENDOR_ID_JMICRON ,PCI_DEVICE_ID_JMICRON_JMB368 , +PCI_ANY_ID ,PCI_ANY_ID ,PCI_CLASS_STORAGE_IDE <<8 ,0xffff00 ,368 }, { }/* terminate list */ };
Quoted 8 lines · Tejun Heo
Channel redirect and AHCI mode enable programmings are done via PCI quirk for both probe and resume paths. Drop duplicate and possibly unsafe device programming from
pata_jmicron().Signed-off-by Tejun Heo <[email protected]>--- drivers/ata/pata_jmicron.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-)
applied 1-3