aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/processor_perflib.c4
-rw-r--r--drivers/acpi/video.c2
-rw-r--r--drivers/ata/Kconfig4
-rw-r--r--drivers/ata/ahci.c101
-rw-r--r--drivers/ata/ata_generic.c6
-rw-r--r--drivers/ata/libata-core.c16
-rw-r--r--drivers/ata/libata-eh.c6
-rw-r--r--drivers/ata/libata-scsi.c62
-rw-r--r--drivers/ata/libata-sff.c21
-rw-r--r--drivers/ata/pata_cmd64x.c23
-rw-r--r--drivers/ata/pata_hpt3x2n.c6
-rw-r--r--drivers/ata/pata_it821x.c4
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c5
-rw-r--r--drivers/ata/pata_legacy.c4
-rw-r--r--drivers/ata/pata_platform.c3
-rw-r--r--drivers/ata/pata_rz1000.c6
-rw-r--r--drivers/ata/pata_sil680.c2
-rw-r--r--drivers/ata/pata_via.c1
-rw-r--r--drivers/ata/sata_mv.c5
-rw-r--r--drivers/ata/sata_nv.c14
-rw-r--r--drivers/ata/sata_uli.c3
-rw-r--r--drivers/ata/sata_via.c13
-rw-r--r--drivers/atm/horizon.c2
-rw-r--r--drivers/char/agp/amd-k7-agp.c5
-rw-r--r--drivers/char/agp/amd64-agp.c2
-rw-r--r--drivers/char/agp/ati-agp.c36
-rw-r--r--drivers/char/agp/intel-agp.c9
-rw-r--r--drivers/char/agp/via-agp.c21
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c3
-rw-r--r--drivers/char/mem.c4
-rw-r--r--drivers/char/tlclk.c43
-rw-r--r--drivers/char/vr41xx_giu.c114
-rw-r--r--drivers/cpufreq/cpufreq.c17
-rw-r--r--drivers/firmware/efivars.c29
-rw-r--r--drivers/hid/hid-core.c7
-rw-r--r--drivers/hid/hid-input.c33
-rw-r--r--drivers/hwmon/hwmon-vid.c2
-rw-r--r--drivers/hwmon/w83793.c127
-rw-r--r--drivers/ide/ide-pnp.c5
-rw-r--r--drivers/ide/ide.c5
-rw-r--r--drivers/ide/pci/aec62xx.c2
-rw-r--r--drivers/ide/pci/alim15x3.c2
-rw-r--r--drivers/ide/pci/amd74xx.c2
-rw-r--r--drivers/ide/pci/atiixp.c42
-rw-r--r--drivers/ide/pci/cmd64x.c2
-rw-r--r--drivers/ide/pci/cs5520.c2
-rw-r--r--drivers/ide/pci/cs5530.c2
-rw-r--r--drivers/ide/pci/cy82c693.c2
-rw-r--r--drivers/ide/pci/generic.c37
-rw-r--r--drivers/ide/pci/hpt34x.c2
-rw-r--r--drivers/ide/pci/hpt366.c2
-rw-r--r--drivers/ide/pci/jmicron.c17
-rw-r--r--drivers/ide/pci/ns87415.c2
-rw-r--r--drivers/ide/pci/opti621.c2
-rw-r--r--drivers/ide/pci/pdc202xx_new.c2
-rw-r--r--drivers/ide/pci/pdc202xx_old.c2
-rw-r--r--drivers/ide/pci/rz1000.c2
-rw-r--r--drivers/ide/pci/sc1200.c2
-rw-r--r--drivers/ide/pci/serverworks.c2
-rw-r--r--drivers/ide/pci/sgiioc4.c3
-rw-r--r--drivers/ide/pci/siimage.c2
-rw-r--r--drivers/ide/pci/sis5513.c2
-rw-r--r--drivers/ide/pci/sl82c105.c2
-rw-r--r--drivers/ide/pci/slc90e66.c2
-rw-r--r--drivers/ide/pci/triflex.c2
-rw-r--r--drivers/ide/pci/trm290.c2
-rw-r--r--drivers/ide/pci/via82cxxx.c5
-rw-r--r--drivers/infiniband/hw/ehca/ehca_cq.c5
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c3
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c20
-rw-r--r--drivers/isdn/gigaset/common.c61
-rw-r--r--drivers/kvm/kvm.h1
-rw-r--r--drivers/kvm/kvm_main.c19
-rw-r--r--drivers/kvm/mmu.c16
-rw-r--r--drivers/kvm/paging_tmpl.h79
-rw-r--r--drivers/kvm/svm.c28
-rw-r--r--drivers/kvm/vmx.c5
-rw-r--r--drivers/kvm/x86_emulate.c98
-rw-r--r--drivers/md/bitmap.c12
-rw-r--r--drivers/md/dm.c27
-rw-r--r--drivers/md/md.c32
-rw-r--r--drivers/md/raid1.c7
-rw-r--r--drivers/md/raid5.c5
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c2
-rw-r--r--drivers/media/video/ks0127.c8
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c14
-rw-r--r--drivers/media/video/tveeprom.c2
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.h14
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c3
-rw-r--r--drivers/media/video/v4l2-common.c9
-rw-r--r--drivers/media/video/video-buf.c3
-rw-r--r--drivers/media/video/vivi.c7
-rw-r--r--drivers/message/fusion/mptbase.c3
-rw-r--r--drivers/message/fusion/mptbase.h10
-rw-r--r--drivers/message/fusion/mptctl.c5
-rw-r--r--drivers/message/fusion/mptctl.h2
-rw-r--r--drivers/message/fusion/mptfc.c3
-rw-r--r--drivers/message/fusion/mptlan.c4
-rw-r--r--drivers/message/fusion/mptlan.h2
-rw-r--r--drivers/message/fusion/mptsas.c38
-rw-r--r--drivers/message/fusion/mptscsih.c19
-rw-r--r--drivers/message/fusion/mptscsih.h2
-rw-r--r--drivers/message/fusion/mptspi.c3
-rw-r--r--drivers/mmc/imxmmc.c3
-rw-r--r--drivers/mmc/omap.c15
-rw-r--r--drivers/mmc/pxamci.c2
-rw-r--r--drivers/mmc/tifm_sd.c3
-rw-r--r--drivers/mtd/Kconfig15
-rw-r--r--drivers/mtd/Makefile15
-rw-r--r--drivers/mtd/afs.c3
-rw-r--r--drivers/mtd/chips/amd_flash.c3
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c5
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c11
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c3
-rw-r--r--drivers/mtd/chips/gen_probe.c5
-rw-r--r--drivers/mtd/chips/jedec.c3
-rw-r--r--drivers/mtd/chips/jedec_probe.c17
-rw-r--r--drivers/mtd/chips/map_absent.c4
-rw-r--r--drivers/mtd/chips/map_ram.c4
-rw-r--r--drivers/mtd/chips/map_rom.c4
-rw-r--r--drivers/mtd/chips/sharp.c7
-rw-r--r--drivers/mtd/cmdlinepart.c5
-rw-r--r--drivers/mtd/devices/block2mtd.c3
-rw-r--r--drivers/mtd/devices/ms02-nv.c18
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c2
-rw-r--r--drivers/mtd/devices/phram.c4
-rw-r--r--drivers/mtd/devices/slram.c7
-rw-r--r--drivers/mtd/ftl.c7
-rw-r--r--drivers/mtd/inftlcore.c12
-rw-r--r--drivers/mtd/maps/Kconfig71
-rw-r--r--drivers/mtd/maps/Makefile4
-rw-r--r--drivers/mtd/maps/amd76xrom.c34
-rw-r--r--drivers/mtd/maps/bast-flash.c2
-rw-r--r--drivers/mtd/maps/ceiva.c3
-rw-r--r--drivers/mtd/maps/ck804xrom.c356
-rw-r--r--drivers/mtd/maps/cstm_mips_ixx.c283
-rw-r--r--drivers/mtd/maps/esb2rom.c450
-rw-r--r--drivers/mtd/maps/integrator-flash.c4
-rw-r--r--drivers/mtd/maps/nettel.c5
-rw-r--r--drivers/mtd/maps/omap_nor.c4
-rw-r--r--drivers/mtd/maps/pcmciamtd.c3
-rw-r--r--drivers/mtd/maps/physmap.c5
-rw-r--r--drivers/mtd/maps/physmap_of.c255
-rw-r--r--drivers/mtd/maps/plat-ram.c3
-rw-r--r--drivers/mtd/maps/sa1100-flash.c4
-rw-r--r--drivers/mtd/maps/tqm834x.c8
-rw-r--r--drivers/mtd/maps/tqm8xxl.c3
-rw-r--r--drivers/mtd/mtd_blkdevs.c19
-rw-r--r--drivers/mtd/mtdblock.c10
-rw-r--r--drivers/mtd/mtdblock_ro.c7
-rw-r--r--drivers/mtd/mtdchar.c23
-rw-r--r--drivers/mtd/mtdconcat.c43
-rw-r--r--drivers/mtd/mtdcore.c93
-rw-r--r--drivers/mtd/mtdpart.c8
-rw-r--r--drivers/mtd/nand/Kconfig16
-rw-r--r--drivers/mtd/nand/Makefile5
-rw-r--r--drivers/mtd/nand/at91_nand.c223
-rw-r--r--drivers/mtd/nand/cafe.c771
-rw-r--r--drivers/mtd/nand/cafe_ecc.c1381
-rw-r--r--drivers/mtd/nand/cs553x_nand.c4
-rw-r--r--drivers/mtd/nand/diskonchip.c3
-rw-r--r--drivers/mtd/nand/nand_base.c133
-rw-r--r--drivers/mtd/nand/nand_bbt.c11
-rw-r--r--drivers/mtd/nand/nand_ecc.c4
-rw-r--r--drivers/mtd/nand/nandsim.c243
-rw-r--r--drivers/mtd/nand/ndfc.c2
-rw-r--r--drivers/mtd/nand/rtc_from4.c46
-rw-r--r--drivers/mtd/nand/s3c2410.c2
-rw-r--r--drivers/mtd/nftlcore.c12
-rw-r--r--drivers/mtd/onenand/generic.c5
-rw-r--r--drivers/mtd/onenand/onenand_base.c374
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c14
-rw-r--r--drivers/mtd/redboot.c30
-rw-r--r--drivers/mtd/rfd_ftl.c3
-rw-r--r--drivers/mtd/ssfdc.c7
-rw-r--r--drivers/net/8139cp.c7
-rw-r--r--drivers/net/82596.c7
-rw-r--r--drivers/net/b44.c52
-rw-r--r--drivers/net/bnx2.c12
-rw-r--r--drivers/net/bonding/bonding.h7
-rw-r--r--drivers/net/e100.c2
-rw-r--r--drivers/net/ehea/ehea.h2
-rw-r--r--drivers/net/ehea/ehea_main.c87
-rw-r--r--drivers/net/ehea/ehea_phyp.c10
-rw-r--r--drivers/net/fs_enet/mac-fec.c13
-rw-r--r--drivers/net/fs_enet/mac-scc.c6
-rw-r--r--drivers/net/irda/irda-usb.c45
-rw-r--r--drivers/net/irda/irda-usb.h1
-rw-r--r--drivers/net/irda/stir4200.c2
-rw-r--r--drivers/net/irda/vlsi_ir.c16
-rw-r--r--drivers/net/irda/vlsi_ir.h33
-rw-r--r--drivers/net/mv643xx_eth.c11
-rw-r--r--drivers/net/myri10ge/myri10ge.c23
-rw-r--r--drivers/net/netxen/netxen_nic.h7
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c3
-rw-r--r--drivers/net/netxen/netxen_nic_main.c2
-rw-r--r--drivers/net/pcmcia/3c589_cs.c7
-rw-r--r--drivers/net/phy/fixed.c2
-rw-r--r--drivers/net/phy/phy.c3
-rw-r--r--drivers/net/s2io.c3
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/skge.c2
-rw-r--r--drivers/net/sky2.c27
-rw-r--r--drivers/net/ucc_geth.c12
-rw-r--r--drivers/net/ucc_geth_phy.c134
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c11
-rw-r--r--drivers/pci/pci-driver.c3
-rw-r--r--drivers/pci/quirks.c83
-rw-r--r--drivers/rtc/rtc-sh.c12
-rw-r--r--drivers/rtc/rtc-sysfs.c2
-rw-r--r--drivers/scsi/3w-xxxx.c60
-rw-r--r--drivers/scsi/3w-xxxx.h2
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/aacraid/linit.c20
-rw-r--r--drivers/scsi/advansys.c3
-rw-r--r--drivers/scsi/iscsi_tcp.c12
-rw-r--r--drivers/scsi/libiscsi.c6
-rw-r--r--drivers/scsi/lpfc/lpfc_mem.c6
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c6
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c2
-rw-r--r--drivers/scsi/qla1280.c6
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h1
-rw-r--r--drivers/scsi/qla2xxx/qla_gs.c24
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c76
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c15
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c12
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c59
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h2
-rw-r--r--drivers/scsi/scsi_scan.c33
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--drivers/scsi/scsi_transport_spi.c2
-rw-r--r--drivers/scsi/seagate.c5
-rw-r--r--drivers/scsi/sr.c2
-rw-r--r--drivers/serial/amba-pl010.c2
-rw-r--r--drivers/serial/amba-pl011.c2
-rw-r--r--drivers/serial/atmel_serial.c7
-rw-r--r--drivers/serial/atmel_serial.h2
-rw-r--r--drivers/spi/pxa2xx_spi.c5
-rw-r--r--drivers/spi/spi.c23
-rw-r--r--drivers/spi/spi_s3c24xx.c28
-rw-r--r--drivers/usb/core/Kconfig16
-rw-r--r--drivers/usb/core/hub.c9
-rw-r--r--drivers/usb/host/ohci-ep93xx.c2
-rw-r--r--drivers/usb/input/Kconfig2
-rw-r--r--drivers/usb/input/hid-core.c50
-rw-r--r--drivers/usb/input/hid-ff.c5
-rw-r--r--drivers/usb/input/hiddev.c2
-rw-r--r--drivers/usb/input/usbhid.h3
-rw-r--r--drivers/usb/input/usbtouchscreen.c98
-rw-r--r--drivers/usb/net/asix.c18
-rw-r--r--drivers/usb/net/rndis_host.c23
-rw-r--r--drivers/usb/serial/funsoft.c2
-rw-r--r--drivers/usb/serial/option.c3
-rw-r--r--drivers/usb/storage/unusual_devs.h19
255 files changed, 6015 insertions, 1980 deletions
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 5207f9e4b443..cbb6f0814ce2 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -322,10 +322,6 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
322 if (result) 322 if (result)
323 return result; 323 return result;
324 324
325 result = acpi_processor_get_platform_limit(pr);
326 if (result)
327 return result;
328
329 return 0; 325 return 0;
330} 326}
331 327
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 36b37d755dbc..3d54680d0333 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -1677,8 +1677,6 @@ static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1677 struct acpi_video_device *video_device = data; 1677 struct acpi_video_device *video_device = data;
1678 struct acpi_device *device = NULL; 1678 struct acpi_device *device = NULL;
1679 1679
1680
1681 printk("video device notify\n");
1682 if (!video_device) 1680 if (!video_device)
1683 return; 1681 return;
1684 1682
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index da21552d2b1c..1c94b43d2c9b 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -19,6 +19,10 @@ config ATA
19 19
20if ATA 20if ATA
21 21
22config ATA_NONSTANDARD
23 bool
24 default n
25
22config SATA_AHCI 26config SATA_AHCI
23 tristate "AHCI SATA support" 27 tristate "AHCI SATA support"
24 depends on PCI 28 depends on PCI
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index b517d2493551..48616c6fee9d 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -75,6 +75,7 @@ enum {
75 AHCI_CMD_CLR_BUSY = (1 << 10), 75 AHCI_CMD_CLR_BUSY = (1 << 10),
76 76
77 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ 77 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */
78 RX_FIS_SDB = 0x58, /* offset of SDB FIS data */
78 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */ 79 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */
79 80
80 board_ahci = 0, 81 board_ahci = 0,
@@ -202,6 +203,10 @@ struct ahci_port_priv {
202 dma_addr_t cmd_tbl_dma; 203 dma_addr_t cmd_tbl_dma;
203 void *rx_fis; 204 void *rx_fis;
204 dma_addr_t rx_fis_dma; 205 dma_addr_t rx_fis_dma;
206 /* for NCQ spurious interrupt analysis */
207 int ncq_saw_spurious_sdb_cnt;
208 unsigned int ncq_saw_d2h:1;
209 unsigned int ncq_saw_dmas:1;
205}; 210};
206 211
207static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 212static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
@@ -361,7 +366,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
361 { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */ 366 { PCI_VDEVICE(INTEL, 0x27c1), board_ahci }, /* ICH7 */
362 { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */ 367 { PCI_VDEVICE(INTEL, 0x27c5), board_ahci }, /* ICH7M */
363 { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */ 368 { PCI_VDEVICE(INTEL, 0x27c3), board_ahci }, /* ICH7R */
364 { PCI_VDEVICE(AL, 0x5288), board_ahci }, /* ULi M5288 */ 369 { PCI_VDEVICE(AL, 0x5288), board_ahci_ign_iferr }, /* ULi M5288 */
365 { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */ 370 { PCI_VDEVICE(INTEL, 0x2681), board_ahci }, /* ESB2 */
366 { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */ 371 { PCI_VDEVICE(INTEL, 0x2682), board_ahci }, /* ESB2 */
367 { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */ 372 { PCI_VDEVICE(INTEL, 0x2683), board_ahci }, /* ESB2 */
@@ -586,35 +591,18 @@ static void ahci_power_down(void __iomem *port_mmio, u32 cap)
586{ 591{
587 u32 cmd, scontrol; 592 u32 cmd, scontrol;
588 593
589 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK; 594 if (!(cap & HOST_CAP_SSS))
590 595 return;
591 if (cap & HOST_CAP_SSC) {
592 /* enable transitions to slumber mode */
593 scontrol = readl(port_mmio + PORT_SCR_CTL);
594 if ((scontrol & 0x0f00) > 0x100) {
595 scontrol &= ~0xf00;
596 writel(scontrol, port_mmio + PORT_SCR_CTL);
597 }
598
599 /* put device into slumber mode */
600 writel(cmd | PORT_CMD_ICC_SLUMBER, port_mmio + PORT_CMD);
601
602 /* wait for the transition to complete */
603 ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_ICC_SLUMBER,
604 PORT_CMD_ICC_SLUMBER, 1, 50);
605 }
606 596
607 /* put device into listen mode */ 597 /* put device into listen mode, first set PxSCTL.DET to 0 */
608 if (cap & HOST_CAP_SSS) { 598 scontrol = readl(port_mmio + PORT_SCR_CTL);
609 /* first set PxSCTL.DET to 0 */ 599 scontrol &= ~0xf;
610 scontrol = readl(port_mmio + PORT_SCR_CTL); 600 writel(scontrol, port_mmio + PORT_SCR_CTL);
611 scontrol &= ~0xf;
612 writel(scontrol, port_mmio + PORT_SCR_CTL);
613 601
614 /* then set PxCMD.SUD to 0 */ 602 /* then set PxCMD.SUD to 0 */
615 cmd &= ~PORT_CMD_SPIN_UP; 603 cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
616 writel(cmd, port_mmio + PORT_CMD); 604 cmd &= ~PORT_CMD_SPIN_UP;
617 } 605 writel(cmd, port_mmio + PORT_CMD);
618} 606}
619 607
620static void ahci_init_port(void __iomem *port_mmio, u32 cap, 608static void ahci_init_port(void __iomem *port_mmio, u32 cap,
@@ -915,7 +903,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
915 903
916 /* clear D2H reception area to properly wait for D2H FIS */ 904 /* clear D2H reception area to properly wait for D2H FIS */
917 ata_tf_init(ap->device, &tf); 905 ata_tf_init(ap->device, &tf);
918 tf.command = 0xff; 906 tf.command = 0x80;
919 ata_tf_to_fis(&tf, d2h_fis, 0); 907 ata_tf_to_fis(&tf, d2h_fis, 0);
920 908
921 rc = sata_std_hardreset(ap, class); 909 rc = sata_std_hardreset(ap, class);
@@ -1126,8 +1114,9 @@ static void ahci_host_intr(struct ata_port *ap)
1126 void __iomem *mmio = ap->host->mmio_base; 1114 void __iomem *mmio = ap->host->mmio_base;
1127 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1115 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1128 struct ata_eh_info *ehi = &ap->eh_info; 1116 struct ata_eh_info *ehi = &ap->eh_info;
1117 struct ahci_port_priv *pp = ap->private_data;
1129 u32 status, qc_active; 1118 u32 status, qc_active;
1130 int rc; 1119 int rc, known_irq = 0;
1131 1120
1132 status = readl(port_mmio + PORT_IRQ_STAT); 1121 status = readl(port_mmio + PORT_IRQ_STAT);
1133 writel(status, port_mmio + PORT_IRQ_STAT); 1122 writel(status, port_mmio + PORT_IRQ_STAT);
@@ -1154,17 +1143,53 @@ static void ahci_host_intr(struct ata_port *ap)
1154 1143
1155 /* hmmm... a spurious interupt */ 1144 /* hmmm... a spurious interupt */
1156 1145
1157 /* some devices send D2H reg with I bit set during NCQ command phase */ 1146 /* if !NCQ, ignore. No modern ATA device has broken HSM
1158 if (ap->sactive && (status & PORT_IRQ_D2H_REG_FIS)) 1147 * implementation for non-NCQ commands.
1148 */
1149 if (!ap->sactive)
1159 return; 1150 return;
1160 1151
1161 /* ignore interim PIO setup fis interrupts */ 1152 if (status & PORT_IRQ_D2H_REG_FIS) {
1162 if (ata_tag_valid(ap->active_tag) && (status & PORT_IRQ_PIOS_FIS)) 1153 if (!pp->ncq_saw_d2h)
1163 return; 1154 ata_port_printk(ap, KERN_INFO,
1155 "D2H reg with I during NCQ, "
1156 "this message won't be printed again\n");
1157 pp->ncq_saw_d2h = 1;
1158 known_irq = 1;
1159 }
1160
1161 if (status & PORT_IRQ_DMAS_FIS) {
1162 if (!pp->ncq_saw_dmas)
1163 ata_port_printk(ap, KERN_INFO,
1164 "DMAS FIS during NCQ, "
1165 "this message won't be printed again\n");
1166 pp->ncq_saw_dmas = 1;
1167 known_irq = 1;
1168 }
1169
1170 if (status & PORT_IRQ_SDB_FIS &&
1171 pp->ncq_saw_spurious_sdb_cnt < 10) {
1172 /* SDB FIS containing spurious completions might be
1173 * dangerous, we need to know more about them. Print
1174 * more of it.
1175 */
1176 const u32 *f = pp->rx_fis + RX_FIS_SDB;
1177
1178 ata_port_printk(ap, KERN_INFO, "Spurious SDB FIS during NCQ "
1179 "issue=0x%x SAct=0x%x FIS=%08x:%08x%s\n",
1180 readl(port_mmio + PORT_CMD_ISSUE),
1181 readl(port_mmio + PORT_SCR_ACT),
1182 le32_to_cpu(f[0]), le32_to_cpu(f[1]),
1183 pp->ncq_saw_spurious_sdb_cnt < 10 ?
1184 "" : ", shutting up");
1185
1186 pp->ncq_saw_spurious_sdb_cnt++;
1187 known_irq = 1;
1188 }
1164 1189
1165 if (ata_ratelimit()) 1190 if (!known_irq)
1166 ata_port_printk(ap, KERN_INFO, "spurious interrupt " 1191 ata_port_printk(ap, KERN_INFO, "spurious interrupt "
1167 "(irq_stat 0x%x active_tag %d sactive 0x%x)\n", 1192 "(irq_stat 0x%x active_tag 0x%x sactive 0x%x)\n",
1168 status, ap->active_tag, ap->sactive); 1193 status, ap->active_tag, ap->sactive);
1169} 1194}
1170 1195
@@ -1257,7 +1282,7 @@ static void ahci_thaw(struct ata_port *ap)
1257 /* clear IRQ */ 1282 /* clear IRQ */
1258 tmp = readl(port_mmio + PORT_IRQ_STAT); 1283 tmp = readl(port_mmio + PORT_IRQ_STAT);
1259 writel(tmp, port_mmio + PORT_IRQ_STAT); 1284 writel(tmp, port_mmio + PORT_IRQ_STAT);
1260 writel(1 << ap->id, mmio + HOST_IRQ_STAT); 1285 writel(1 << ap->port_no, mmio + HOST_IRQ_STAT);
1261 1286
1262 /* turn IRQ back on */ 1287 /* turn IRQ back on */
1263 writel(DEF_PORT_IRQ, port_mmio + PORT_IRQ_MASK); 1288 writel(DEF_PORT_IRQ, port_mmio + PORT_IRQ_MASK);
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 908751d27e76..24af56081b5d 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -64,6 +64,7 @@ static void generic_error_handler(struct ata_port *ap)
64/** 64/**
65 * generic_set_mode - mode setting 65 * generic_set_mode - mode setting
66 * @ap: interface to set up 66 * @ap: interface to set up
67 * @unused: returned device on error
67 * 68 *
68 * Use a non standard set_mode function. We don't want to be tuned. 69 * Use a non standard set_mode function. We don't want to be tuned.
69 * The BIOS configured everything. Our job is not to fiddle. We 70 * The BIOS configured everything. Our job is not to fiddle. We
@@ -71,7 +72,7 @@ static void generic_error_handler(struct ata_port *ap)
71 * and respect them. 72 * and respect them.
72 */ 73 */
73 74
74static void generic_set_mode(struct ata_port *ap) 75static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
75{ 76{
76 int dma_enabled = 0; 77 int dma_enabled = 0;
77 int i; 78 int i;
@@ -82,7 +83,7 @@ static void generic_set_mode(struct ata_port *ap)
82 83
83 for (i = 0; i < ATA_MAX_DEVICES; i++) { 84 for (i = 0; i < ATA_MAX_DEVICES; i++) {
84 struct ata_device *dev = &ap->device[i]; 85 struct ata_device *dev = &ap->device[i];
85 if (ata_dev_enabled(dev)) { 86 if (ata_dev_ready(dev)) {
86 /* We don't really care */ 87 /* We don't really care */
87 dev->pio_mode = XFER_PIO_0; 88 dev->pio_mode = XFER_PIO_0;
88 dev->dma_mode = XFER_MW_DMA_0; 89 dev->dma_mode = XFER_MW_DMA_0;
@@ -99,6 +100,7 @@ static void generic_set_mode(struct ata_port *ap)
99 } 100 }
100 } 101 }
101 } 102 }
103 return 0;
102} 104}
103 105
104static struct scsi_host_template generic_sht = { 106static struct scsi_host_template generic_sht = {
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 0d51d13b16bf..cf707029352e 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1037,7 +1037,7 @@ static unsigned int ata_id_xfermask(const u16 *id)
1037 * the PIO timing number for the maximum. Turn it into 1037 * the PIO timing number for the maximum. Turn it into
1038 * a mask. 1038 * a mask.
1039 */ 1039 */
1040 u8 mode = id[ATA_ID_OLD_PIO_MODES] & 0xFF; 1040 u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF;
1041 if (mode < 5) /* Valid PIO range */ 1041 if (mode < 5) /* Valid PIO range */
1042 pio_mask = (2 << mode) - 1; 1042 pio_mask = (2 << mode) - 1;
1043 else 1043 else
@@ -2431,18 +2431,8 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2431 int i, rc = 0, used_dma = 0, found = 0; 2431 int i, rc = 0, used_dma = 0, found = 0;
2432 2432
2433 /* has private set_mode? */ 2433 /* has private set_mode? */
2434 if (ap->ops->set_mode) { 2434 if (ap->ops->set_mode)
2435 /* FIXME: make ->set_mode handle no device case and 2435 return ap->ops->set_mode(ap, r_failed_dev);
2436 * return error code and failing device on failure.
2437 */
2438 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2439 if (ata_dev_ready(&ap->device[i])) {
2440 ap->ops->set_mode(ap);
2441 break;
2442 }
2443 }
2444 return 0;
2445 }
2446 2436
2447 /* step 1: calculate xfer_mask */ 2437 /* step 1: calculate xfer_mask */
2448 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2438 for (i = 0; i < ATA_MAX_DEVICES; i++) {
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 08ad44b3e48f..748435807d68 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1796,7 +1796,7 @@ static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1796 *r_failed_dev = dev; 1796 *r_failed_dev = dev;
1797 1797
1798 DPRINTK("EXIT\n"); 1798 DPRINTK("EXIT\n");
1799 return 0; 1799 return rc;
1800} 1800}
1801 1801
1802/** 1802/**
@@ -1979,6 +1979,10 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1979 1979
1980 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; 1980 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
1981 1981
1982 /* collect port action mask recorded in dev actions */
1983 ehc->i.action |= ehc->i.dev_action[i] & ~ATA_EH_PERDEV_MASK;
1984 ehc->i.dev_action[i] &= ATA_EH_PERDEV_MASK;
1985
1982 /* process hotplug request */ 1986 /* process hotplug request */
1983 if (dev->flags & ATA_DFLAG_DETACH) 1987 if (dev->flags & ATA_DFLAG_DETACH)
1984 ata_eh_detach_dev(dev); 1988 ata_eh_detach_dev(dev);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 836947da5b14..73902d335767 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -273,8 +273,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
273{ 273{
274 int rc = 0; 274 int rc = 0;
275 u8 scsi_cmd[MAX_COMMAND_SIZE]; 275 u8 scsi_cmd[MAX_COMMAND_SIZE];
276 u8 args[7]; 276 u8 args[7], *sensebuf = NULL;
277 struct scsi_sense_hdr sshdr; 277 int cmd_result;
278 278
279 if (arg == NULL) 279 if (arg == NULL)
280 return -EINVAL; 280 return -EINVAL;
@@ -282,10 +282,14 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
282 if (copy_from_user(args, arg, sizeof(args))) 282 if (copy_from_user(args, arg, sizeof(args)))
283 return -EFAULT; 283 return -EFAULT;
284 284
285 sensebuf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
286 if (!sensebuf)
287 return -ENOMEM;
288
285 memset(scsi_cmd, 0, sizeof(scsi_cmd)); 289 memset(scsi_cmd, 0, sizeof(scsi_cmd));
286 scsi_cmd[0] = ATA_16; 290 scsi_cmd[0] = ATA_16;
287 scsi_cmd[1] = (3 << 1); /* Non-data */ 291 scsi_cmd[1] = (3 << 1); /* Non-data */
288 /* scsi_cmd[2] is already 0 -- no off.line, cc, or data xfer */ 292 scsi_cmd[2] = 0x20; /* cc but no off.line or data xfer */
289 scsi_cmd[4] = args[1]; 293 scsi_cmd[4] = args[1];
290 scsi_cmd[6] = args[2]; 294 scsi_cmd[6] = args[2];
291 scsi_cmd[8] = args[3]; 295 scsi_cmd[8] = args[3];
@@ -295,11 +299,46 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
295 299
296 /* Good values for timeout and retries? Values below 300 /* Good values for timeout and retries? Values below
297 from scsi_ioctl_send_command() for default case... */ 301 from scsi_ioctl_send_command() for default case... */
298 if (scsi_execute_req(scsidev, scsi_cmd, DMA_NONE, NULL, 0, &sshdr, 302 cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
299 (10*HZ), 5)) 303 sensebuf, (10*HZ), 5, 0);
304
305 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
306 u8 *desc = sensebuf + 8;
307 cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
308
309 /* If we set cc then ATA pass-through will cause a
310 * check condition even if no error. Filter that. */
311 if (cmd_result & SAM_STAT_CHECK_CONDITION) {
312 struct scsi_sense_hdr sshdr;
313 scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE,
314 &sshdr);
315 if (sshdr.sense_key==0 &&
316 sshdr.asc==0 && sshdr.ascq==0)
317 cmd_result &= ~SAM_STAT_CHECK_CONDITION;
318 }
319
320 /* Send userspace ATA registers */
321 if (sensebuf[0] == 0x72 && /* format is "descriptor" */
322 desc[0] == 0x09) {/* code is "ATA Descriptor" */
323 args[0] = desc[13]; /* status */
324 args[1] = desc[3]; /* error */
325 args[2] = desc[5]; /* sector count (0:7) */
326 args[3] = desc[7]; /* lbal */
327 args[4] = desc[9]; /* lbam */
328 args[5] = desc[11]; /* lbah */
329 args[6] = desc[12]; /* select */
330 if (copy_to_user(arg, args, sizeof(args)))
331 rc = -EFAULT;
332 }
333 }
334
335 if (cmd_result) {
300 rc = -EIO; 336 rc = -EIO;
337 goto error;
338 }
301 339
302 /* Need code to retrieve data from check condition? */ 340 error:
341 kfree(sensebuf);
303 return rc; 342 return rc;
304} 343}
305 344
@@ -372,7 +411,7 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
372 if (cmd->use_sg) { 411 if (cmd->use_sg) {
373 qc->__sg = (struct scatterlist *) cmd->request_buffer; 412 qc->__sg = (struct scatterlist *) cmd->request_buffer;
374 qc->n_elem = cmd->use_sg; 413 qc->n_elem = cmd->use_sg;
375 } else { 414 } else if (cmd->request_bufflen) {
376 qc->__sg = &qc->sgent; 415 qc->__sg = &qc->sgent;
377 qc->n_elem = 1; 416 qc->n_elem = 1;
378 } 417 }
@@ -983,11 +1022,10 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
983 } 1022 }
984 1023
985 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 1024 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */
986 } else { 1025 } else
987 tf->nsect = 0; /* time period value (0 implies now) */ 1026 /* Issue ATA STANDBY IMMEDIATE command */
988 tf->command = ATA_CMD_STANDBY; 1027 tf->command = ATA_CMD_STANDBYNOW1;
989 /* Consider: ATA STANDBY IMMEDIATE command */ 1028
990 }
991 /* 1029 /*
992 * Standby and Idle condition timers could be implemented but that 1030 * Standby and Idle condition timers could be implemented but that
993 * would require libata to implement the Power condition mode page 1031 * would require libata to implement the Power condition mode page
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 623cec914c9b..12c88c588039 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -827,7 +827,8 @@ void ata_bmdma_error_handler(struct ata_port *ap)
827 */ 827 */
828void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc) 828void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
829{ 829{
830 ata_bmdma_stop(qc); 830 if (qc->ap->ioaddr.bmdma_addr)
831 ata_bmdma_stop(qc);
831} 832}
832 833
833#ifdef CONFIG_PCI 834#ifdef CONFIG_PCI
@@ -870,7 +871,8 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
870 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 871 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
871 bmdma = pci_resource_start(pdev, 4); 872 bmdma = pci_resource_start(pdev, 4);
872 if (bmdma) { 873 if (bmdma) {
873 if (inb(bmdma + 2) & 0x80) 874 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
875 (inb(bmdma + 2) & 0x80))
874 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 876 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
875 probe_ent->port[p].bmdma_addr = bmdma; 877 probe_ent->port[p].bmdma_addr = bmdma;
876 } 878 }
@@ -886,7 +888,8 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
886 bmdma = pci_resource_start(pdev, 4); 888 bmdma = pci_resource_start(pdev, 4);
887 if (bmdma) { 889 if (bmdma) {
888 bmdma += 8; 890 bmdma += 8;
889 if(inb(bmdma + 2) & 0x80) 891 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
892 (inb(bmdma + 2) & 0x80))
890 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 893 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
891 probe_ent->port[p].bmdma_addr = bmdma; 894 probe_ent->port[p].bmdma_addr = bmdma;
892 } 895 }
@@ -914,13 +917,14 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
914 probe_ent->irq_flags = IRQF_SHARED; 917 probe_ent->irq_flags = IRQF_SHARED;
915 918
916 if (port_mask & ATA_PORT_PRIMARY) { 919 if (port_mask & ATA_PORT_PRIMARY) {
917 probe_ent->irq = ATA_PRIMARY_IRQ; 920 probe_ent->irq = ATA_PRIMARY_IRQ(pdev);
918 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD; 921 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD;
919 probe_ent->port[0].altstatus_addr = 922 probe_ent->port[0].altstatus_addr =
920 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL; 923 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL;
921 if (bmdma) { 924 if (bmdma) {
922 probe_ent->port[0].bmdma_addr = bmdma; 925 probe_ent->port[0].bmdma_addr = bmdma;
923 if (inb(bmdma + 2) & 0x80) 926 if ((!(port[0]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
927 (inb(bmdma + 2) & 0x80))
924 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 928 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
925 } 929 }
926 ata_std_ports(&probe_ent->port[0]); 930 ata_std_ports(&probe_ent->port[0]);
@@ -929,15 +933,16 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
929 933
930 if (port_mask & ATA_PORT_SECONDARY) { 934 if (port_mask & ATA_PORT_SECONDARY) {
931 if (probe_ent->irq) 935 if (probe_ent->irq)
932 probe_ent->irq2 = ATA_SECONDARY_IRQ; 936 probe_ent->irq2 = ATA_SECONDARY_IRQ(pdev);
933 else 937 else
934 probe_ent->irq = ATA_SECONDARY_IRQ; 938 probe_ent->irq = ATA_SECONDARY_IRQ(pdev);
935 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD; 939 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD;
936 probe_ent->port[1].altstatus_addr = 940 probe_ent->port[1].altstatus_addr =
937 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL; 941 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL;
938 if (bmdma) { 942 if (bmdma) {
939 probe_ent->port[1].bmdma_addr = bmdma + 8; 943 probe_ent->port[1].bmdma_addr = bmdma + 8;
940 if (inb(bmdma + 10) & 0x80) 944 if ((!(port[1]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
945 (inb(bmdma + 10) & 0x80))
941 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 946 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
942 } 947 }
943 ata_std_ports(&probe_ent->port[1]); 948 ata_std_ports(&probe_ent->port[1]);
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 15841a563694..449162cbf93e 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -197,7 +197,7 @@ static void cmd64x_set_piomode(struct ata_port *ap, struct ata_device *adev)
197static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev) 197static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
198{ 198{
199 static const u8 udma_data[] = { 199 static const u8 udma_data[] = {
200 0x31, 0x21, 0x11, 0x25, 0x15, 0x05 200 0x30, 0x20, 0x10, 0x20, 0x10, 0x00
201 }; 201 };
202 static const u8 mwdma_data[] = { 202 static const u8 mwdma_data[] = {
203 0x30, 0x20, 0x10 203 0x30, 0x20, 0x10
@@ -213,12 +213,21 @@ static void cmd64x_set_dmamode(struct ata_port *ap, struct ata_device *adev)
213 pci_read_config_byte(pdev, pciD, &regD); 213 pci_read_config_byte(pdev, pciD, &regD);
214 pci_read_config_byte(pdev, pciU, &regU); 214 pci_read_config_byte(pdev, pciU, &regU);
215 215
216 regD &= ~(0x20 << shift); 216 /* DMA bits off */
217 regU &= ~(0x35 << shift); 217 regD &= ~(0x20 << adev->devno);
218 /* DMA control bits */
219 regU &= ~(0x30 << shift);
220 /* DMA timing bits */
221 regU &= ~(0x05 << adev->devno);
218 222
219 if (adev->dma_mode >= XFER_UDMA_0) 223 if (adev->dma_mode >= XFER_UDMA_0) {
224 /* Merge thge timing value */
220 regU |= udma_data[adev->dma_mode - XFER_UDMA_0] << shift; 225 regU |= udma_data[adev->dma_mode - XFER_UDMA_0] << shift;
221 else 226 /* Merge the control bits */
227 regU |= 1 << adev->devno; /* UDMA on */
228 if (adev->dma_mode > 2) /* 15nS timing */
229 regU |= 4 << adev->devno;
230 } else
222 regD |= mwdma_data[adev->dma_mode - XFER_MW_DMA_0] << shift; 231 regD |= mwdma_data[adev->dma_mode - XFER_MW_DMA_0] << shift;
223 232
224 regD |= 0x20 << adev->devno; 233 regD |= 0x20 << adev->devno;
@@ -239,8 +248,8 @@ static void cmd648_bmdma_stop(struct ata_queued_cmd *qc)
239 struct ata_port *ap = qc->ap; 248 struct ata_port *ap = qc->ap;
240 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 249 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
241 u8 dma_intr; 250 u8 dma_intr;
242 int dma_reg = ap->port_no ? ARTTIM23_INTR_CH1 : CFR_INTR_CH0; 251 int dma_mask = ap->port_no ? ARTTIM23_INTR_CH1 : CFR_INTR_CH0;
243 int dma_mask = ap->port_no ? ARTTIM2 : CFR; 252 int dma_reg = ap->port_no ? ARTTIM2 : CFR;
244 253
245 ata_bmdma_stop(qc); 254 ata_bmdma_stop(qc);
246 255
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index f6817b4093a4..886fab9aa62c 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -25,7 +25,7 @@
25#include <linux/libata.h> 25#include <linux/libata.h>
26 26
27#define DRV_NAME "pata_hpt3x2n" 27#define DRV_NAME "pata_hpt3x2n"
28#define DRV_VERSION "0.3" 28#define DRV_VERSION "0.3.2"
29 29
30enum { 30enum {
31 HPT_PCI_FAST = (1 << 31), 31 HPT_PCI_FAST = (1 << 31),
@@ -297,11 +297,11 @@ static int hpt3x2n_pair_idle(struct ata_port *ap)
297 return 0; 297 return 0;
298} 298}
299 299
300static int hpt3x2n_use_dpll(struct ata_port *ap, int reading) 300static int hpt3x2n_use_dpll(struct ata_port *ap, int writing)
301{ 301{
302 long flags = (long)ap->host->private_data; 302 long flags = (long)ap->host->private_data;
303 /* See if we should use the DPLL */ 303 /* See if we should use the DPLL */
304 if (reading == 0) 304 if (writing)
305 return USE_DPLL; /* Needed for write */ 305 return USE_DPLL; /* Needed for write */
306 if (flags & PCI66) 306 if (flags & PCI66)
307 return USE_DPLL; /* Needed at 66Mhz */ 307 return USE_DPLL; /* Needed at 66Mhz */
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 0b56ff3d1cfe..e8afd486434a 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -476,6 +476,7 @@ static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc)
476/** 476/**
477 * it821x_smart_set_mode - mode setting 477 * it821x_smart_set_mode - mode setting
478 * @ap: interface to set up 478 * @ap: interface to set up
479 * @unused: device that failed (error only)
479 * 480 *
480 * Use a non standard set_mode function. We don't want to be tuned. 481 * Use a non standard set_mode function. We don't want to be tuned.
481 * The BIOS configured everything. Our job is not to fiddle. We 482 * The BIOS configured everything. Our job is not to fiddle. We
@@ -483,7 +484,7 @@ static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc)
483 * and respect them. 484 * and respect them.
484 */ 485 */
485 486
486static void it821x_smart_set_mode(struct ata_port *ap) 487static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused)
487{ 488{
488 int dma_enabled = 0; 489 int dma_enabled = 0;
489 int i; 490 int i;
@@ -512,6 +513,7 @@ static void it821x_smart_set_mode(struct ata_port *ap)
512 } 513 }
513 } 514 }
514 } 515 }
516 return 0;
515} 517}
516 518
517/** 519/**
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index cb8924109f59..23b8aab3ebd8 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -23,9 +23,9 @@
23#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
24 24
25#define DRV_NAME "pata_ixp4xx_cf" 25#define DRV_NAME "pata_ixp4xx_cf"
26#define DRV_VERSION "0.1.1" 26#define DRV_VERSION "0.1.1ac1"
27 27
28static void ixp4xx_set_mode(struct ata_port *ap) 28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device *adev)
29{ 29{
30 int i; 30 int i;
31 31
@@ -38,6 +38,7 @@ static void ixp4xx_set_mode(struct ata_port *ap)
38 dev->flags |= ATA_DFLAG_PIO; 38 dev->flags |= ATA_DFLAG_PIO;
39 } 39 }
40 } 40 }
41 return 0;
41} 42}
42 43
43static void ixp4xx_phy_reset(struct ata_port *ap) 44static void ixp4xx_phy_reset(struct ata_port *ap)
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index e7bf9d89c8ee..581cb33c6f45 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -96,6 +96,7 @@ static int pio_mask = 0x1F; /* PIO range for autospeed devices */
96/** 96/**
97 * legacy_set_mode - mode setting 97 * legacy_set_mode - mode setting
98 * @ap: IDE interface 98 * @ap: IDE interface
99 * @unused: Device that failed when error is returned
99 * 100 *
100 * Use a non standard set_mode function. We don't want to be tuned. 101 * Use a non standard set_mode function. We don't want to be tuned.
101 * 102 *
@@ -105,7 +106,7 @@ static int pio_mask = 0x1F; /* PIO range for autospeed devices */
105 * expand on this as per hdparm in the base kernel. 106 * expand on this as per hdparm in the base kernel.
106 */ 107 */
107 108
108static void legacy_set_mode(struct ata_port *ap) 109static int legacy_set_mode(struct ata_port *ap, struct ata_device **unused)
109{ 110{
110 int i; 111 int i;
111 112
@@ -118,6 +119,7 @@ static void legacy_set_mode(struct ata_port *ap)
118 dev->flags |= ATA_DFLAG_PIO; 119 dev->flags |= ATA_DFLAG_PIO;
119 } 120 }
120 } 121 }
122 return 0;
121} 123}
122 124
123static struct scsi_host_template legacy_sht = { 125static struct scsi_host_template legacy_sht = {
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 443b1d85c6c4..40ae11cbfda4 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -30,7 +30,7 @@ static int pio_mask = 1;
30 * Provide our own set_mode() as we don't want to change anything that has 30 * Provide our own set_mode() as we don't want to change anything that has
31 * already been configured.. 31 * already been configured..
32 */ 32 */
33static void pata_platform_set_mode(struct ata_port *ap) 33static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unused)
34{ 34{
35 int i; 35 int i;
36 36
@@ -44,6 +44,7 @@ static void pata_platform_set_mode(struct ata_port *ap)
44 dev->flags |= ATA_DFLAG_PIO; 44 dev->flags |= ATA_DFLAG_PIO;
45 } 45 }
46 } 46 }
47 return 0;
47} 48}
48 49
49static void pata_platform_host_stop(struct ata_host *host) 50static void pata_platform_host_stop(struct ata_host *host)
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index adf4cc134f25..cec0729225e1 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -52,19 +52,20 @@ static void rz1000_error_handler(struct ata_port *ap)
52/** 52/**
53 * rz1000_set_mode - mode setting function 53 * rz1000_set_mode - mode setting function
54 * @ap: ATA interface 54 * @ap: ATA interface
55 * @unused: returned device on set_mode failure
55 * 56 *
56 * Use a non standard set_mode function. We don't want to be tuned. We 57 * Use a non standard set_mode function. We don't want to be tuned. We
57 * would prefer to be BIOS generic but for the fact our hardware is 58 * would prefer to be BIOS generic but for the fact our hardware is
58 * whacked out. 59 * whacked out.
59 */ 60 */
60 61
61static void rz1000_set_mode(struct ata_port *ap) 62static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused)
62{ 63{
63 int i; 64 int i;
64 65
65 for (i = 0; i < ATA_MAX_DEVICES; i++) { 66 for (i = 0; i < ATA_MAX_DEVICES; i++) {
66 struct ata_device *dev = &ap->device[i]; 67 struct ata_device *dev = &ap->device[i];
67 if (ata_dev_enabled(dev)) { 68 if (ata_dev_ready(dev)) {
68 /* We don't really care */ 69 /* We don't really care */
69 dev->pio_mode = XFER_PIO_0; 70 dev->pio_mode = XFER_PIO_0;
70 dev->xfer_mode = XFER_PIO_0; 71 dev->xfer_mode = XFER_PIO_0;
@@ -72,6 +73,7 @@ static void rz1000_set_mode(struct ata_port *ap)
72 dev->flags |= ATA_DFLAG_PIO; 73 dev->flags |= ATA_DFLAG_PIO;
73 } 74 }
74 } 75 }
76 return 0;
75} 77}
76 78
77 79
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 32cf0bfa8921..e8dfd8fc3ff7 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -135,7 +135,7 @@ static void sil680_error_handler(struct ata_port *ap)
135static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev) 135static void sil680_set_piomode(struct ata_port *ap, struct ata_device *adev)
136{ 136{
137 static u16 speed_p[5] = { 0x328A, 0x2283, 0x1104, 0x10C3, 0x10C1 }; 137 static u16 speed_p[5] = { 0x328A, 0x2283, 0x1104, 0x10C3, 0x10C1 };
138 static u16 speed_t[5] = { 0x328A, 0x1281, 0x1281, 0x10C3, 0x10C1 }; 138 static u16 speed_t[5] = { 0x328A, 0x2283, 0x1281, 0x10C3, 0x10C1 };
139 139
140 unsigned long tfaddr = sil680_selreg(ap, 0x02); 140 unsigned long tfaddr = sil680_selreg(ap, 0x02);
141 unsigned long addr = sil680_seldev(ap, adev, 0x04); 141 unsigned long addr = sil680_seldev(ap, adev, 0x04);
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index f0d4f7e9ed31..0219419cae97 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -95,6 +95,7 @@ static const struct via_isa_bridge {
95 u8 rev_max; 95 u8 rev_max;
96 u16 flags; 96 u16 flags;
97} via_isa_bridges[] = { 97} via_isa_bridges[] = {
98 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
98 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 99 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
99 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 100 { "cx700", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
100 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES}, 101 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST | VIA_NO_ENABLES},
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 1b8e0eb9e032..aae0b5201c1e 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -523,8 +523,7 @@ static const struct ata_port_info mv_port_info[] = {
523 }, 523 },
524 { /* chip_7042 */ 524 { /* chip_7042 */
525 .sht = &mv_sht, 525 .sht = &mv_sht,
526 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | 526 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
527 MV_FLAG_DUAL_HC),
528 .pio_mask = 0x1f, /* pio0-4 */ 527 .pio_mask = 0x1f, /* pio0-4 */
529 .udma_mask = 0x7f, /* udma0-6 */ 528 .udma_mask = 0x7f, /* udma0-6 */
530 .port_ops = &mv_iie_ops, 529 .port_ops = &mv_iie_ops,
@@ -545,6 +544,8 @@ static const struct pci_device_id mv_pci_tbl[] = {
545 544
546 { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 545 { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x },
547 546
547 { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
548
548 { } /* terminate list */ 549 { } /* terminate list */
549}; 550};
550 551
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index f6d498e1cf80..f7a963eb1f02 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -700,7 +700,6 @@ static void nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
700static int nv_host_intr(struct ata_port *ap, u8 irq_stat) 700static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
701{ 701{
702 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag); 702 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
703 int handled;
704 703
705 /* freeze if hotplugged */ 704 /* freeze if hotplugged */
706 if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) { 705 if (unlikely(irq_stat & (NV_INT_ADDED | NV_INT_REMOVED))) {
@@ -719,13 +718,7 @@ static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
719 } 718 }
720 719
721 /* handle interrupt */ 720 /* handle interrupt */
722 handled = ata_host_intr(ap, qc); 721 return ata_host_intr(ap, qc);
723 if (unlikely(!handled)) {
724 /* spurious, clear it */
725 ata_check_status(ap);
726 }
727
728 return 1;
729} 722}
730 723
731static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) 724static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
@@ -752,6 +745,11 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
752 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) { 745 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
753 u8 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804) 746 u8 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804)
754 >> (NV_INT_PORT_SHIFT * i); 747 >> (NV_INT_PORT_SHIFT * i);
748 if(ata_tag_valid(ap->active_tag))
749 /** NV_INT_DEV indication seems unreliable at times
750 at least in ADMA mode. Force it on always when a
751 command is active, to prevent losing interrupts. */
752 irq_stat |= NV_INT_DEV;
755 handled += nv_host_intr(ap, irq_stat); 753 handled += nv_host_intr(ap, irq_stat);
756 continue; 754 continue;
757 } 755 }
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 5c603ca3a50a..a43aec62d505 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -128,7 +128,8 @@ static const struct ata_port_operations uli_ops = {
128 128
129static struct ata_port_info uli_port_info = { 129static struct ata_port_info uli_port_info = {
130 .sht = &uli_sht, 130 .sht = &uli_sht,
131 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 131 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
132 ATA_FLAG_IGN_SIMPLEX,
132 .pio_mask = 0x1f, /* pio0-4 */ 133 .pio_mask = 0x1f, /* pio0-4 */
133 .udma_mask = 0x7f, /* udma0-6 */ 134 .udma_mask = 0x7f, /* udma0-6 */
134 .port_ops = &uli_ops, 135 .port_ops = &uli_ops,
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 1c7f19aecc25..d3d5c0d57032 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -74,9 +74,11 @@ enum {
74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg); 75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void svia_noop_freeze(struct ata_port *ap);
77static void vt6420_error_handler(struct ata_port *ap); 78static void vt6420_error_handler(struct ata_port *ap);
78 79
79static const struct pci_device_id svia_pci_tbl[] = { 80static const struct pci_device_id svia_pci_tbl[] = {
81 { PCI_VDEVICE(VIA, 0x5337), vt6420 },
80 { PCI_VDEVICE(VIA, 0x0591), vt6420 }, 82 { PCI_VDEVICE(VIA, 0x0591), vt6420 },
81 { PCI_VDEVICE(VIA, 0x3149), vt6420 }, 83 { PCI_VDEVICE(VIA, 0x3149), vt6420 },
82 { PCI_VDEVICE(VIA, 0x3249), vt6421 }, 84 { PCI_VDEVICE(VIA, 0x3249), vt6421 },
@@ -127,7 +129,7 @@ static const struct ata_port_operations vt6420_sata_ops = {
127 .qc_issue = ata_qc_issue_prot, 129 .qc_issue = ata_qc_issue_prot,
128 .data_xfer = ata_pio_data_xfer, 130 .data_xfer = ata_pio_data_xfer,
129 131
130 .freeze = ata_bmdma_freeze, 132 .freeze = svia_noop_freeze,
131 .thaw = ata_bmdma_thaw, 133 .thaw = ata_bmdma_thaw,
132 .error_handler = vt6420_error_handler, 134 .error_handler = vt6420_error_handler,
133 .post_internal_cmd = ata_bmdma_post_internal_cmd, 135 .post_internal_cmd = ata_bmdma_post_internal_cmd,
@@ -203,6 +205,15 @@ static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
203 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 205 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg));
204} 206}
205 207
208static void svia_noop_freeze(struct ata_port *ap)
209{
210 /* Some VIA controllers choke if ATA_NIEN is manipulated in
211 * certain way. Leave it alone and just clear pending IRQ.
212 */
213 ata_chk_status(ap);
214 ata_bmdma_irq_clear(ap);
215}
216
206/** 217/**
207 * vt6420_prereset - prereset for vt6420 218 * vt6420_prereset - prereset for vt6420
208 * @ap: target ATA port 219 * @ap: target ATA port
diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
index 4dc10105d610..f96446c358ba 100644
--- a/drivers/atm/horizon.c
+++ b/drivers/atm/horizon.c
@@ -1845,7 +1845,7 @@ static u16 __devinit read_bia (const hrz_dev * dev, u16 addr)
1845 1845
1846/********** initialise a card **********/ 1846/********** initialise a card **********/
1847 1847
1848static int __init hrz_init (hrz_dev * dev) { 1848static int __devinit hrz_init (hrz_dev * dev) {
1849 int onefivefive; 1849 int onefivefive;
1850 1850
1851 u16 chan; 1851 u16 chan;
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 51d0d562d01e..c85c8cadb6df 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -101,6 +101,11 @@ static int amd_create_gatt_pages(int nr_tables)
101 for (i = 0; i < nr_tables; i++) { 101 for (i = 0; i < nr_tables; i++) {
102 entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL); 102 entry = kzalloc(sizeof(struct amd_page_map), GFP_KERNEL);
103 if (entry == NULL) { 103 if (entry == NULL) {
104 while (i > 0) {
105 kfree(tables[i-1]);
106 i--;
107 }
108 kfree(tables);
104 retval = -ENOMEM; 109 retval = -ENOMEM;
105 break; 110 break;
106 } 111 }
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 979300405c0e..93d2209fee4c 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -655,7 +655,7 @@ static struct pci_device_id agp_amd64_pci_table[] = {
655 .class = (PCI_CLASS_BRIDGE_HOST << 8), 655 .class = (PCI_CLASS_BRIDGE_HOST << 8),
656 .class_mask = ~0, 656 .class_mask = ~0,
657 .vendor = PCI_VENDOR_ID_VIA, 657 .vendor = PCI_VENDOR_ID_VIA,
658 .device = PCI_DEVICE_ID_VIA_K8M890CE, 658 .device = PCI_DEVICE_ID_VIA_VT3336,
659 .subvendor = PCI_ANY_ID, 659 .subvendor = PCI_ANY_ID,
660 .subdevice = PCI_ANY_ID, 660 .subdevice = PCI_ANY_ID,
661 }, 661 },
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index f244c6682738..9987dc2e0c3f 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -41,18 +41,18 @@ static struct gatt_mask ati_generic_masks[] =
41}; 41};
42 42
43 43
44typedef struct _ati_page_map { 44struct ati_page_map {
45 unsigned long *real; 45 unsigned long *real;
46 unsigned long __iomem *remapped; 46 unsigned long __iomem *remapped;
47} ati_page_map; 47};
48 48
49static struct _ati_generic_private { 49static struct _ati_generic_private {
50 volatile u8 __iomem *registers; 50 volatile u8 __iomem *registers;
51 ati_page_map **gatt_pages; 51 struct ati_page_map **gatt_pages;
52 int num_tables; 52 int num_tables;
53} ati_generic_private; 53} ati_generic_private;
54 54
55static int ati_create_page_map(ati_page_map *page_map) 55static int ati_create_page_map(struct ati_page_map *page_map)
56{ 56{
57 int i, err = 0; 57 int i, err = 0;
58 58
@@ -82,7 +82,7 @@ static int ati_create_page_map(ati_page_map *page_map)
82} 82}
83 83
84 84
85static void ati_free_page_map(ati_page_map *page_map) 85static void ati_free_page_map(struct ati_page_map *page_map)
86{ 86{
87 unmap_page_from_agp(virt_to_page(page_map->real)); 87 unmap_page_from_agp(virt_to_page(page_map->real));
88 iounmap(page_map->remapped); 88 iounmap(page_map->remapped);
@@ -94,8 +94,8 @@ static void ati_free_page_map(ati_page_map *page_map)
94static void ati_free_gatt_pages(void) 94static void ati_free_gatt_pages(void)
95{ 95{
96 int i; 96 int i;
97 ati_page_map **tables; 97 struct ati_page_map **tables;
98 ati_page_map *entry; 98 struct ati_page_map *entry;
99 99
100 tables = ati_generic_private.gatt_pages; 100 tables = ati_generic_private.gatt_pages;
101 for (i = 0; i < ati_generic_private.num_tables; i++) { 101 for (i = 0; i < ati_generic_private.num_tables; i++) {
@@ -112,30 +112,30 @@ static void ati_free_gatt_pages(void)
112 112
113static int ati_create_gatt_pages(int nr_tables) 113static int ati_create_gatt_pages(int nr_tables)
114{ 114{
115 ati_page_map **tables; 115 struct ati_page_map **tables;
116 ati_page_map *entry; 116 struct ati_page_map *entry;
117 int retval = 0; 117 int retval = 0;
118 int i; 118 int i;
119 119
120 tables = kzalloc((nr_tables + 1) * sizeof(ati_page_map *),GFP_KERNEL); 120 tables = kzalloc((nr_tables + 1) * sizeof(struct ati_page_map *),GFP_KERNEL);
121 if (tables == NULL) 121 if (tables == NULL)
122 return -ENOMEM; 122 return -ENOMEM;
123 123
124 for (i = 0; i < nr_tables; i++) { 124 for (i = 0; i < nr_tables; i++) {
125 entry = kzalloc(sizeof(ati_page_map), GFP_KERNEL); 125 entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL);
126 if (entry == NULL) { 126 if (entry == NULL) {
127 while (i>0) { 127 while (i > 0) {
128 kfree (tables[i-1]); 128 kfree(tables[i-1]);
129 i--; 129 i--;
130 } 130 }
131 kfree (tables); 131 kfree(tables);
132 tables = NULL;
133 retval = -ENOMEM; 132 retval = -ENOMEM;
134 break; 133 break;
135 } 134 }
136 tables[i] = entry; 135 tables[i] = entry;
137 retval = ati_create_page_map(entry); 136 retval = ati_create_page_map(entry);
138 if (retval != 0) break; 137 if (retval != 0)
138 break;
139 } 139 }
140 ati_generic_private.num_tables = nr_tables; 140 ati_generic_private.num_tables = nr_tables;
141 ati_generic_private.gatt_pages = tables; 141 ati_generic_private.gatt_pages = tables;
@@ -340,7 +340,7 @@ static int ati_remove_memory(struct agp_memory * mem, off_t pg_start,
340static int ati_create_gatt_table(struct agp_bridge_data *bridge) 340static int ati_create_gatt_table(struct agp_bridge_data *bridge)
341{ 341{
342 struct aper_size_info_lvl2 *value; 342 struct aper_size_info_lvl2 *value;
343 ati_page_map page_dir; 343 struct ati_page_map page_dir;
344 unsigned long addr; 344 unsigned long addr;
345 int retval; 345 int retval;
346 u32 temp; 346 u32 temp;
@@ -400,7 +400,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
400 400
401static int ati_free_gatt_table(struct agp_bridge_data *bridge) 401static int ati_free_gatt_table(struct agp_bridge_data *bridge)
402{ 402{
403 ati_page_map page_dir; 403 struct ati_page_map page_dir;
404 404
405 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real; 405 page_dir.real = (unsigned long *)agp_bridge->gatt_table_real;
406 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table; 406 page_dir.remapped = (unsigned long __iomem *)agp_bridge->gatt_table;
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index ab0a9c0ad7c0..a3011de51f7c 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -1955,6 +1955,15 @@ static int agp_intel_resume(struct pci_dev *pdev)
1955 1955
1956 pci_restore_state(pdev); 1956 pci_restore_state(pdev);
1957 1957
1958 /* We should restore our graphics device's config space,
1959 * as host bridge (00:00) resumes before graphics device (02:00),
1960 * then our access to its pci space can work right.
1961 */
1962 if (intel_i810_private.i810_dev)
1963 pci_restore_state(intel_i810_private.i810_dev);
1964 if (intel_i830_private.i830_dev)
1965 pci_restore_state(intel_i830_private.i830_dev);
1966
1958 if (bridge->driver == &intel_generic_driver) 1967 if (bridge->driver == &intel_generic_driver)
1959 intel_configure(); 1968 intel_configure();
1960 else if (bridge->driver == &intel_850_driver) 1969 else if (bridge->driver == &intel_850_driver)
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index c149ac9ce9a7..2ded7a280d7f 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -380,9 +380,23 @@ static struct agp_device_ids via_agp_device_ids[] __devinitdata =
380 /* P4M800CE */ 380 /* P4M800CE */
381 { 381 {
382 .device_id = PCI_DEVICE_ID_VIA_P4M800CE, 382 .device_id = PCI_DEVICE_ID_VIA_P4M800CE,
383 .chipset_name = "P4M800CE", 383 .chipset_name = "VT3314",
384 },
385 /* CX700 */
386 {
387 .device_id = PCI_DEVICE_ID_VIA_CX700,
388 .chipset_name = "CX700",
389 },
390 /* VT3336 */
391 {
392 .device_id = PCI_DEVICE_ID_VIA_VT3336,
393 .chipset_name = "VT3336",
394 },
395 /* P4M890 */
396 {
397 .device_id = PCI_DEVICE_ID_VIA_P4M890,
398 .chipset_name = "P4M890",
384 }, 399 },
385
386 { }, /* dummy final entry, always present */ 400 { }, /* dummy final entry, always present */
387}; 401};
388 402
@@ -524,6 +538,9 @@ static const struct pci_device_id agp_via_pci_table[] = {
524 ID(PCI_DEVICE_ID_VIA_83_87XX_1), 538 ID(PCI_DEVICE_ID_VIA_83_87XX_1),
525 ID(PCI_DEVICE_ID_VIA_3296_0), 539 ID(PCI_DEVICE_ID_VIA_3296_0),
526 ID(PCI_DEVICE_ID_VIA_P4M800CE), 540 ID(PCI_DEVICE_ID_VIA_P4M800CE),
541 ID(PCI_DEVICE_ID_VIA_CX700),
542 ID(PCI_DEVICE_ID_VIA_VT3336),
543 ID(PCI_DEVICE_ID_VIA_P4M890),
527 { } 544 { }
528}; 545};
529 546
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 4e4691a53890..53582b53da95 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -3649,8 +3649,6 @@ static void ipmi_timeout_handler(long timeout_period)
3649 unsigned long flags; 3649 unsigned long flags;
3650 int i; 3650 int i;
3651 3651
3652 INIT_LIST_HEAD(&timeouts);
3653
3654 rcu_read_lock(); 3652 rcu_read_lock();
3655 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 3653 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
3656 /* See if any waiting messages need to be processed. */ 3654 /* See if any waiting messages need to be processed. */
@@ -3671,6 +3669,7 @@ static void ipmi_timeout_handler(long timeout_period)
3671 /* Go through the seq table and find any messages that 3669 /* Go through the seq table and find any messages that
3672 have timed out, putting them in the timeouts 3670 have timed out, putting them in the timeouts
3673 list. */ 3671 list. */
3672 INIT_LIST_HEAD(&timeouts);
3674 spin_lock_irqsave(&intf->seq_lock, flags); 3673 spin_lock_irqsave(&intf->seq_lock, flags);
3675 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) 3674 for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
3676 check_msg_timeout(intf, &(intf->seq_table[i]), 3675 check_msg_timeout(intf, &(intf->seq_table[i]),
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 4f1813e04754..f5c160caf9f4 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -293,8 +293,8 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
293{ 293{
294 unsigned long pfn; 294 unsigned long pfn;
295 295
296 /* Turn a pfn offset into an absolute pfn */ 296 /* Turn a kernel-virtual address into a physical page frame */
297 pfn = PFN_DOWN(virt_to_phys((void *)PAGE_OFFSET)) + vma->vm_pgoff; 297 pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
298 298
299 /* 299 /*
300 * RED-PEN: on some architectures there is more mapped memory 300 * RED-PEN: on some architectures there is more mapped memory
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 448d5083c381..4fac2bdf6215 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -186,6 +186,7 @@ static int got_event; /* if events processing have been done */
186static void switchover_timeout(unsigned long data); 186static void switchover_timeout(unsigned long data);
187static struct timer_list switchover_timer = 187static struct timer_list switchover_timer =
188 TIMER_INITIALIZER(switchover_timeout , 0, 0); 188 TIMER_INITIALIZER(switchover_timeout , 0, 0);
189static unsigned long tlclk_timer_data;
189 190
190static struct tlclk_alarms *alarm_events; 191static struct tlclk_alarms *alarm_events;
191 192
@@ -197,10 +198,19 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id);
197 198
198static DECLARE_WAIT_QUEUE_HEAD(wq); 199static DECLARE_WAIT_QUEUE_HEAD(wq);
199 200
201static unsigned long useflags;
202static DEFINE_MUTEX(tlclk_mutex);
203
200static int tlclk_open(struct inode *inode, struct file *filp) 204static int tlclk_open(struct inode *inode, struct file *filp)
201{ 205{
202 int result; 206 int result;
203 207
208 if (test_and_set_bit(0, &useflags))
209 return -EBUSY;
210 /* this legacy device is always one per system and it doesn't
211 * know how to handle multiple concurrent clients.
212 */
213
204 /* Make sure there is no interrupt pending while 214 /* Make sure there is no interrupt pending while
205 * initialising interrupt handler */ 215 * initialising interrupt handler */
206 inb(TLCLK_REG6); 216 inb(TLCLK_REG6);
@@ -221,6 +231,7 @@ static int tlclk_open(struct inode *inode, struct file *filp)
221static int tlclk_release(struct inode *inode, struct file *filp) 231static int tlclk_release(struct inode *inode, struct file *filp)
222{ 232{
223 free_irq(telclk_interrupt, tlclk_interrupt); 233 free_irq(telclk_interrupt, tlclk_interrupt);
234 clear_bit(0, &useflags);
224 235
225 return 0; 236 return 0;
226} 237}
@@ -230,26 +241,25 @@ static ssize_t tlclk_read(struct file *filp, char __user *buf, size_t count,
230{ 241{
231 if (count < sizeof(struct tlclk_alarms)) 242 if (count < sizeof(struct tlclk_alarms))
232 return -EIO; 243 return -EIO;
244 if (mutex_lock_interruptible(&tlclk_mutex))
245 return -EINTR;
246
233 247
234 wait_event_interruptible(wq, got_event); 248 wait_event_interruptible(wq, got_event);
235 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) 249 if (copy_to_user(buf, alarm_events, sizeof(struct tlclk_alarms))) {
250 mutex_unlock(&tlclk_mutex);
236 return -EFAULT; 251 return -EFAULT;
252 }
237 253
238 memset(alarm_events, 0, sizeof(struct tlclk_alarms)); 254 memset(alarm_events, 0, sizeof(struct tlclk_alarms));
239 got_event = 0; 255 got_event = 0;
240 256
257 mutex_unlock(&tlclk_mutex);
241 return sizeof(struct tlclk_alarms); 258 return sizeof(struct tlclk_alarms);
242} 259}
243 260
244static ssize_t tlclk_write(struct file *filp, const char __user *buf, size_t count,
245 loff_t *f_pos)
246{
247 return 0;
248}
249
250static const struct file_operations tlclk_fops = { 261static const struct file_operations tlclk_fops = {
251 .read = tlclk_read, 262 .read = tlclk_read,
252 .write = tlclk_write,
253 .open = tlclk_open, 263 .open = tlclk_open,
254 .release = tlclk_release, 264 .release = tlclk_release,
255 265
@@ -540,7 +550,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
540 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7); 550 SET_PORT_BITS(TLCLK_REG3, 0xf8, 0x7);
541 switch (val) { 551 switch (val) {
542 case CLK_8_592MHz: 552 case CLK_8_592MHz:
543 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1); 553 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2);
544 break; 554 break;
545 case CLK_11_184MHz: 555 case CLK_11_184MHz:
546 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0); 556 SET_PORT_BITS(TLCLK_REG0, 0xfc, 0);
@@ -549,7 +559,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
549 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3); 559 SET_PORT_BITS(TLCLK_REG0, 0xfc, 3);
550 break; 560 break;
551 case CLK_44_736MHz: 561 case CLK_44_736MHz:
552 SET_PORT_BITS(TLCLK_REG0, 0xfc, 2); 562 SET_PORT_BITS(TLCLK_REG0, 0xfc, 1);
553 break; 563 break;
554 } 564 }
555 } else 565 } else
@@ -839,11 +849,13 @@ static void __exit tlclk_cleanup(void)
839 849
840static void switchover_timeout(unsigned long data) 850static void switchover_timeout(unsigned long data)
841{ 851{
842 if ((data & 1)) { 852 unsigned long flags = *(unsigned long *) data;
843 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08)) 853
854 if ((flags & 1)) {
855 if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
844 alarm_events->switchover_primary++; 856 alarm_events->switchover_primary++;
845 } else { 857 } else {
846 if ((inb(TLCLK_REG1) & 0x08) != (data & 0x08)) 858 if ((inb(TLCLK_REG1) & 0x08) != (flags & 0x08))
847 alarm_events->switchover_secondary++; 859 alarm_events->switchover_secondary++;
848 } 860 }
849 861
@@ -901,8 +913,9 @@ static irqreturn_t tlclk_interrupt(int irq, void *dev_id)
901 913
902 /* TIMEOUT in ~10ms */ 914 /* TIMEOUT in ~10ms */
903 switchover_timer.expires = jiffies + msecs_to_jiffies(10); 915 switchover_timer.expires = jiffies + msecs_to_jiffies(10);
904 switchover_timer.data = inb(TLCLK_REG1); 916 tlclk_timer_data = inb(TLCLK_REG1);
905 add_timer(&switchover_timer); 917 switchover_timer.data = (unsigned long) &tlclk_timer_data;
918 mod_timer(&switchover_timer, switchover_timer.expires);
906 } else { 919 } else {
907 got_event = 1; 920 got_event = 1;
908 wake_up(&wq); 921 wake_up(&wq);
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index a744dad9cf45..0cea8d4907df 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2002 MontaVista Software Inc. 4 * Copyright (C) 2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com> 5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
6 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 6 * Copyright (C) 2003-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -125,30 +125,17 @@ static inline uint16_t giu_clear(uint16_t offset, uint16_t clear)
125 return data; 125 return data;
126} 126}
127 127
128static unsigned int startup_giuint_low_irq(unsigned int irq) 128static void ack_giuint_low(unsigned int irq)
129{ 129{
130 unsigned int pin; 130 giu_write(GIUINTSTATL, 1 << GPIO_PIN_OF_IRQ(irq));
131
132 pin = GPIO_PIN_OF_IRQ(irq);
133 giu_write(GIUINTSTATL, 1 << pin);
134 giu_set(GIUINTENL, 1 << pin);
135
136 return 0;
137} 131}
138 132
139static void shutdown_giuint_low_irq(unsigned int irq) 133static void mask_giuint_low(unsigned int irq)
140{ 134{
141 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq)); 135 giu_clear(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
142} 136}
143 137
144static void enable_giuint_low_irq(unsigned int irq) 138static void mask_ack_giuint_low(unsigned int irq)
145{
146 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
147}
148
149#define disable_giuint_low_irq shutdown_giuint_low_irq
150
151static void ack_giuint_low_irq(unsigned int irq)
152{ 139{
153 unsigned int pin; 140 unsigned int pin;
154 141
@@ -157,46 +144,30 @@ static void ack_giuint_low_irq(unsigned int irq)
157 giu_write(GIUINTSTATL, 1 << pin); 144 giu_write(GIUINTSTATL, 1 << pin);
158} 145}
159 146
160static void end_giuint_low_irq(unsigned int irq) 147static void unmask_giuint_low(unsigned int irq)
161{ 148{
162 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) 149 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
163 giu_set(GIUINTENL, 1 << GPIO_PIN_OF_IRQ(irq));
164} 150}
165 151
166static struct hw_interrupt_type giuint_low_irq_type = { 152static struct irq_chip giuint_low_irq_chip = {
167 .typename = "GIUINTL", 153 .name = "GIUINTL",
168 .startup = startup_giuint_low_irq, 154 .ack = ack_giuint_low,
169 .shutdown = shutdown_giuint_low_irq, 155 .mask = mask_giuint_low,
170 .enable = enable_giuint_low_irq, 156 .mask_ack = mask_ack_giuint_low,
171 .disable = disable_giuint_low_irq, 157 .unmask = unmask_giuint_low,
172 .ack = ack_giuint_low_irq,
173 .end = end_giuint_low_irq,
174}; 158};
175 159
176static unsigned int startup_giuint_high_irq(unsigned int irq) 160static void ack_giuint_high(unsigned int irq)
177{ 161{
178 unsigned int pin; 162 giu_write(GIUINTSTATH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
179
180 pin = GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET;
181 giu_write(GIUINTSTATH, 1 << pin);
182 giu_set(GIUINTENH, 1 << pin);
183
184 return 0;
185} 163}
186 164
187static void shutdown_giuint_high_irq(unsigned int irq) 165static void mask_giuint_high(unsigned int irq)
188{ 166{
189 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET)); 167 giu_clear(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
190} 168}
191 169
192static void enable_giuint_high_irq(unsigned int irq) 170static void mask_ack_giuint_high(unsigned int irq)
193{
194 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
195}
196
197#define disable_giuint_high_irq shutdown_giuint_high_irq
198
199static void ack_giuint_high_irq(unsigned int irq)
200{ 171{
201 unsigned int pin; 172 unsigned int pin;
202 173
@@ -205,20 +176,17 @@ static void ack_giuint_high_irq(unsigned int irq)
205 giu_write(GIUINTSTATH, 1 << pin); 176 giu_write(GIUINTSTATH, 1 << pin);
206} 177}
207 178
208static void end_giuint_high_irq(unsigned int irq) 179static void unmask_giuint_high(unsigned int irq)
209{ 180{
210 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) 181 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
211 giu_set(GIUINTENH, 1 << (GPIO_PIN_OF_IRQ(irq) - GIUINT_HIGH_OFFSET));
212} 182}
213 183
214static struct hw_interrupt_type giuint_high_irq_type = { 184static struct irq_chip giuint_high_irq_chip = {
215 .typename = "GIUINTH", 185 .name = "GIUINTH",
216 .startup = startup_giuint_high_irq, 186 .ack = ack_giuint_high,
217 .shutdown = shutdown_giuint_high_irq, 187 .mask = mask_giuint_high,
218 .enable = enable_giuint_high_irq, 188 .mask_ack = mask_ack_giuint_high,
219 .disable = disable_giuint_high_irq, 189 .unmask = unmask_giuint_high,
220 .ack = ack_giuint_high_irq,
221 .end = end_giuint_high_irq,
222}; 190};
223 191
224static int giu_get_irq(unsigned int irq) 192static int giu_get_irq(unsigned int irq)
@@ -282,9 +250,15 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
282 break; 250 break;
283 } 251 }
284 } 252 }
253 set_irq_chip_and_handler(GIU_IRQ(pin),
254 &giuint_low_irq_chip,
255 handle_edge_irq);
285 } else { 256 } else {
286 giu_clear(GIUINTTYPL, mask); 257 giu_clear(GIUINTTYPL, mask);
287 giu_clear(GIUINTHTSELL, mask); 258 giu_clear(GIUINTHTSELL, mask);
259 set_irq_chip_and_handler(GIU_IRQ(pin),
260 &giuint_low_irq_chip,
261 handle_level_irq);
288 } 262 }
289 giu_write(GIUINTSTATL, mask); 263 giu_write(GIUINTSTATL, mask);
290 } else if (pin < GIUINT_HIGH_MAX) { 264 } else if (pin < GIUINT_HIGH_MAX) {
@@ -311,9 +285,15 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
311 break; 285 break;
312 } 286 }
313 } 287 }
288 set_irq_chip_and_handler(GIU_IRQ(pin),
289 &giuint_high_irq_chip,
290 handle_edge_irq);
314 } else { 291 } else {
315 giu_clear(GIUINTTYPH, mask); 292 giu_clear(GIUINTTYPH, mask);
316 giu_clear(GIUINTHTSELH, mask); 293 giu_clear(GIUINTHTSELH, mask);
294 set_irq_chip_and_handler(GIU_IRQ(pin),
295 &giuint_high_irq_chip,
296 handle_level_irq);
317 } 297 }
318 giu_write(GIUINTSTATH, mask); 298 giu_write(GIUINTSTATH, mask);
319 } 299 }
@@ -617,10 +597,11 @@ static const struct file_operations gpio_fops = {
617static int __devinit giu_probe(struct platform_device *dev) 597static int __devinit giu_probe(struct platform_device *dev)
618{ 598{
619 unsigned long start, size, flags = 0; 599 unsigned long start, size, flags = 0;
620 unsigned int nr_pins = 0; 600 unsigned int nr_pins = 0, trigger, i, pin;
621 struct resource *res1, *res2 = NULL; 601 struct resource *res1, *res2 = NULL;
622 void *base; 602 void *base;
623 int retval, i; 603 struct irq_chip *chip;
604 int retval;
624 605
625 switch (current_cpu_data.cputype) { 606 switch (current_cpu_data.cputype) {
626 case CPU_VR4111: 607 case CPU_VR4111:
@@ -688,11 +669,20 @@ static int __devinit giu_probe(struct platform_device *dev)
688 giu_write(GIUINTENL, 0); 669 giu_write(GIUINTENL, 0);
689 giu_write(GIUINTENH, 0); 670 giu_write(GIUINTENH, 0);
690 671
672 trigger = giu_read(GIUINTTYPH) << 16;
673 trigger |= giu_read(GIUINTTYPL);
691 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) { 674 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) {
692 if (i < GIU_IRQ(GIUINT_HIGH_OFFSET)) 675 pin = GPIO_PIN_OF_IRQ(i);
693 irq_desc[i].chip = &giuint_low_irq_type; 676 if (pin < GIUINT_HIGH_OFFSET)
677 chip = &giuint_low_irq_chip;
694 else 678 else
695 irq_desc[i].chip = &giuint_high_irq_type; 679 chip = &giuint_high_irq_chip;
680
681 if (trigger & (1 << pin))
682 set_irq_chip_and_handler(i, chip, handle_edge_irq);
683 else
684 set_irq_chip_and_handler(i, chip, handle_level_irq);
685
696 } 686 }
697 687
698 return cascade_irq(GIUINT_IRQ, giu_get_irq); 688 return cascade_irq(GIUINT_IRQ, giu_get_irq);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d91330432ba2..a45cc89e387a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -722,8 +722,13 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
722 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 722 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
723 723
724 dprintk("CPU already managed, adding link\n"); 724 dprintk("CPU already managed, adding link\n");
725 sysfs_create_link(&sys_dev->kobj, 725 ret = sysfs_create_link(&sys_dev->kobj,
726 &managed_policy->kobj, "cpufreq"); 726 &managed_policy->kobj,
727 "cpufreq");
728 if (ret) {
729 mutex_unlock(&policy->lock);
730 goto err_out_driver_exit;
731 }
727 732
728 cpufreq_debug_enable_ratelimit(); 733 cpufreq_debug_enable_ratelimit();
729 mutex_unlock(&policy->lock); 734 mutex_unlock(&policy->lock);
@@ -770,8 +775,12 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
770 dprintk("CPU %u already managed, adding link\n", j); 775 dprintk("CPU %u already managed, adding link\n", j);
771 cpufreq_cpu_get(cpu); 776 cpufreq_cpu_get(cpu);
772 cpu_sys_dev = get_cpu_sysdev(j); 777 cpu_sys_dev = get_cpu_sysdev(j);
773 sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, 778 ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
774 "cpufreq"); 779 "cpufreq");
780 if (ret) {
781 mutex_unlock(&policy->lock);
782 goto err_out_unregister;
783 }
775 } 784 }
776 785
777 policy->governor = NULL; /* to assure that the starting sequence is 786 policy->governor = NULL; /* to assure that the starting sequence is
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 5ab5e393b882..c6281ccd4fe7 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -122,8 +122,6 @@ struct efivar_entry {
122 struct kobject kobj; 122 struct kobject kobj;
123}; 123};
124 124
125#define get_efivar_entry(n) list_entry(n, struct efivar_entry, list)
126
127struct efivar_attribute { 125struct efivar_attribute {
128 struct attribute attr; 126 struct attribute attr;
129 ssize_t (*show) (struct efivar_entry *entry, char *buf); 127 ssize_t (*show) (struct efivar_entry *entry, char *buf);
@@ -386,9 +384,6 @@ static struct sysfs_ops efivar_attr_ops = {
386static void efivar_release(struct kobject *kobj) 384static void efivar_release(struct kobject *kobj)
387{ 385{
388 struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj); 386 struct efivar_entry *var = container_of(kobj, struct efivar_entry, kobj);
389 spin_lock(&efivars_lock);
390 list_del(&var->list);
391 spin_unlock(&efivars_lock);
392 kfree(var); 387 kfree(var);
393} 388}
394 389
@@ -430,9 +425,8 @@ static ssize_t
430efivar_create(struct subsystem *sub, const char *buf, size_t count) 425efivar_create(struct subsystem *sub, const char *buf, size_t count)
431{ 426{
432 struct efi_variable *new_var = (struct efi_variable *)buf; 427 struct efi_variable *new_var = (struct efi_variable *)buf;
433 struct efivar_entry *search_efivar = NULL; 428 struct efivar_entry *search_efivar, *n;
434 unsigned long strsize1, strsize2; 429 unsigned long strsize1, strsize2;
435 struct list_head *pos, *n;
436 efi_status_t status = EFI_NOT_FOUND; 430 efi_status_t status = EFI_NOT_FOUND;
437 int found = 0; 431 int found = 0;
438 432
@@ -444,8 +438,7 @@ efivar_create(struct subsystem *sub, const char *buf, size_t count)
444 /* 438 /*
445 * Does this variable already exist? 439 * Does this variable already exist?
446 */ 440 */
447 list_for_each_safe(pos, n, &efivar_list) { 441 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) {
448 search_efivar = get_efivar_entry(pos);
449 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 442 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
450 strsize2 = utf8_strsize(new_var->VariableName, 1024); 443 strsize2 = utf8_strsize(new_var->VariableName, 1024);
451 if (strsize1 == strsize2 && 444 if (strsize1 == strsize2 &&
@@ -490,9 +483,8 @@ static ssize_t
490efivar_delete(struct subsystem *sub, const char *buf, size_t count) 483efivar_delete(struct subsystem *sub, const char *buf, size_t count)
491{ 484{
492 struct efi_variable *del_var = (struct efi_variable *)buf; 485 struct efi_variable *del_var = (struct efi_variable *)buf;
493 struct efivar_entry *search_efivar = NULL; 486 struct efivar_entry *search_efivar, *n;
494 unsigned long strsize1, strsize2; 487 unsigned long strsize1, strsize2;
495 struct list_head *pos, *n;
496 efi_status_t status = EFI_NOT_FOUND; 488 efi_status_t status = EFI_NOT_FOUND;
497 int found = 0; 489 int found = 0;
498 490
@@ -504,8 +496,7 @@ efivar_delete(struct subsystem *sub, const char *buf, size_t count)
504 /* 496 /*
505 * Does this variable already exist? 497 * Does this variable already exist?
506 */ 498 */
507 list_for_each_safe(pos, n, &efivar_list) { 499 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) {
508 search_efivar = get_efivar_entry(pos);
509 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 500 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
510 strsize2 = utf8_strsize(del_var->VariableName, 1024); 501 strsize2 = utf8_strsize(del_var->VariableName, 1024);
511 if (strsize1 == strsize2 && 502 if (strsize1 == strsize2 &&
@@ -537,9 +528,9 @@ efivar_delete(struct subsystem *sub, const char *buf, size_t count)
537 spin_unlock(&efivars_lock); 528 spin_unlock(&efivars_lock);
538 return -EIO; 529 return -EIO;
539 } 530 }
531 list_del(&search_efivar->list);
540 /* We need to release this lock before unregistering. */ 532 /* We need to release this lock before unregistering. */
541 spin_unlock(&efivars_lock); 533 spin_unlock(&efivars_lock);
542
543 efivar_unregister(search_efivar); 534 efivar_unregister(search_efivar);
544 535
545 /* It's dead Jim.... */ 536 /* It's dead Jim.... */
@@ -768,10 +759,14 @@ out_free:
768static void __exit 759static void __exit
769efivars_exit(void) 760efivars_exit(void)
770{ 761{
771 struct list_head *pos, *n; 762 struct efivar_entry *entry, *n;
772 763
773 list_for_each_safe(pos, n, &efivar_list) 764 list_for_each_entry_safe(entry, n, &efivar_list, list) {
774 efivar_unregister(get_efivar_entry(pos)); 765 spin_lock(&efivars_lock);
766 list_del(&entry->list);
767 spin_unlock(&efivars_lock);
768 efivar_unregister(entry);
769 }
775 770
776 subsystem_unregister(&vars_subsys); 771 subsystem_unregister(&vars_subsys);
777 firmware_unregister(&efi_subsys); 772 firmware_unregister(&efi_subsys);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 1e1a7770a6b9..49f18f5b2514 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -543,6 +543,7 @@ void hid_free_device(struct hid_device *device)
543 } 543 }
544 544
545 kfree(device->rdesc); 545 kfree(device->rdesc);
546 kfree(device->collection);
546 kfree(device); 547 kfree(device);
547} 548}
548EXPORT_SYMBOL_GPL(hid_free_device); 549EXPORT_SYMBOL_GPL(hid_free_device);
@@ -880,6 +881,10 @@ static void hid_output_field(struct hid_field *field, __u8 *data)
880 unsigned size = field->report_size; 881 unsigned size = field->report_size;
881 unsigned n; 882 unsigned n;
882 883
884 /* make sure the unused bits in the last byte are zeros */
885 if (count > 0 && size > 0)
886 data[(count*size-1)/8] = 0;
887
883 for (n = 0; n < count; n++) { 888 for (n = 0; n < count; n++) {
884 if (field->logical_minimum < 0) /* signed values */ 889 if (field->logical_minimum < 0) /* signed values */
885 implement(data, offset + n * size, size, s32ton(field->value[n], size)); 890 implement(data, offset + n * size, size, s32ton(field->value[n], size));
@@ -947,7 +952,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
947 } 952 }
948 953
949#ifdef DEBUG_DATA 954#ifdef DEBUG_DATA
950 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un"); 955 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
951#endif 956#endif
952 957
953 n = 0; /* Normally report number is 0 */ 958 n = 0; /* Normally report number is 0 */
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 28689e3eb552..c7a6833f6821 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -30,12 +30,16 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/usb/input.h>
34 33
35#undef DEBUG 34#undef DEBUG
36 35
37#include <linux/hid.h> 36#include <linux/hid.h>
38 37
38static int hid_pb_fnmode = 1;
39module_param_named(pb_fnmode, hid_pb_fnmode, int, 0644);
40MODULE_PARM_DESC(pb_fnmode,
41 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
42
39#define unk KEY_UNKNOWN 43#define unk KEY_UNKNOWN
40 44
41static const unsigned char hid_keyboard[256] = { 45static const unsigned char hid_keyboard[256] = {
@@ -155,7 +159,7 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
155 return 1; 159 return 1;
156 } 160 }
157 161
158 if (hid->pb_fnmode) { 162 if (hid_pb_fnmode) {
159 int do_translate; 163 int do_translate;
160 164
161 trans = find_translation(powerbook_fn_keys, usage->code); 165 trans = find_translation(powerbook_fn_keys, usage->code);
@@ -164,8 +168,8 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
164 do_translate = 1; 168 do_translate = 1;
165 else if (trans->flags & POWERBOOK_FLAG_FKEY) 169 else if (trans->flags & POWERBOOK_FLAG_FKEY)
166 do_translate = 170 do_translate =
167 (hid->pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) || 171 (hid_pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
168 (hid->pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)); 172 (hid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
169 else 173 else
170 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON); 174 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
171 175
@@ -364,9 +368,22 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
364 break; 368 break;
365 369
366 case HID_UP_LED: 370 case HID_UP_LED:
367 if (((usage->hid - 1) & 0xffff) >= LED_MAX) 371
368 goto ignore; 372 switch (usage->hid & 0xffff) { /* HID-Value: */
369 map_led((usage->hid - 1) & 0xffff); 373 case 0x01: map_led (LED_NUML); break; /* "Num Lock" */
374 case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */
375 case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */
376 case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */
377 case 0x05: map_led (LED_KANA); break; /* "Kana" */
378 case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */
379 case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */
380 case 0x09: map_led (LED_MUTE); break; /* "Mute" */
381 case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */
382 case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */
383 case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */
384
385 default: goto ignore;
386 }
370 break; 387 break;
371 388
372 case HID_UP_DIGITIZER: 389 case HID_UP_DIGITIZER:
@@ -419,6 +436,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
419 case 0x040: map_key_clear(KEY_MENU); break; 436 case 0x040: map_key_clear(KEY_MENU); break;
420 case 0x045: map_key_clear(KEY_RADIO); break; 437 case 0x045: map_key_clear(KEY_RADIO); break;
421 438
439 case 0x083: map_key_clear(KEY_LAST); break;
422 case 0x088: map_key_clear(KEY_PC); break; 440 case 0x088: map_key_clear(KEY_PC); break;
423 case 0x089: map_key_clear(KEY_TV); break; 441 case 0x089: map_key_clear(KEY_TV); break;
424 case 0x08a: map_key_clear(KEY_WWW); break; 442 case 0x08a: map_key_clear(KEY_WWW); break;
@@ -436,6 +454,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
436 case 0x096: map_key_clear(KEY_TAPE); break; 454 case 0x096: map_key_clear(KEY_TAPE); break;
437 case 0x097: map_key_clear(KEY_TV2); break; 455 case 0x097: map_key_clear(KEY_TV2); break;
438 case 0x098: map_key_clear(KEY_SAT); break; 456 case 0x098: map_key_clear(KEY_SAT); break;
457 case 0x09a: map_key_clear(KEY_PVR); break;
439 458
440 case 0x09c: map_key_clear(KEY_CHANNELUP); break; 459 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
441 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; 460 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index 31c42002708f..b80f6ed5acfc 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -93,7 +93,7 @@ int vid_from_reg(int val, u8 vrm)
93 case 110: /* Intel Conroe */ 93 case 110: /* Intel Conroe */
94 /* compute in uV, round to mV */ 94 /* compute in uV, round to mV */
95 val &= 0xff; 95 val &= 0xff;
96 if(((val & 0x7e) == 0xfe) || (!(val & 0x7e))) 96 if (val < 0x02 || val > 0xb2)
97 return 0; 97 return 0;
98 return((1600000 - (val - 2) * 6250 + 500) / 1000); 98 return((1600000 - (val - 2) * 6250 + 500) / 1000);
99 case 24: /* Opteron processor */ 99 case 24: /* Opteron processor */
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index c12ac5abc2bb..253ffaf1568a 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -117,6 +117,7 @@ static const u16 W83793_REG_IN[][3] = {
117/* Low Bits of Vcore A/B Vtt Read/High/Low */ 117/* Low Bits of Vcore A/B Vtt Read/High/Low */
118static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 }; 118static const u16 W83793_REG_IN_LOW_BITS[] = { 0x1b, 0x68, 0x69 };
119static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 }; 119static u8 scale_in[] = { 2, 2, 2, 16, 16, 16, 8, 24, 24, 16 };
120static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
120 121
121#define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */ 122#define W83793_REG_FAN(index) (0x23 + 2 * (index)) /* High byte */
122#define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */ 123#define W83793_REG_FAN_MIN(index) (0x90 + 2 * (index)) /* High byte */
@@ -203,6 +204,8 @@ struct w83793_data {
203 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */ 204 u8 temp_fan_map[6]; /* Temp controls which pwm fan, bit field */
204 205
205 u8 has_pwm; 206 u8 has_pwm;
207 u8 has_temp;
208 u8 has_vid;
206 u8 pwm_enable; /* Register value, each Temp has 1 bit */ 209 u8 pwm_enable; /* Register value, each Temp has 1 bit */
207 u8 pwm_uptime; /* Register value */ 210 u8 pwm_uptime; /* Register value */
208 u8 pwm_downtime; /* Register value */ 211 u8 pwm_downtime; /* Register value */
@@ -500,7 +503,7 @@ store_temp(struct device *dev, struct device_attribute *attr,
500 each has 4 mode:(2 bits) 503 each has 4 mode:(2 bits)
501 0: Stop monitor 504 0: Stop monitor
502 1: Use internal temp sensor(default) 505 1: Use internal temp sensor(default)
503 2: Use sensor in AMD CPU and get result by AMDSI 506 2: Reserved
504 3: Use sensor in Intel CPU and get result by PECI 507 3: Use sensor in Intel CPU and get result by PECI
505 508
506 TR1-TR2 509 TR1-TR2
@@ -509,8 +512,8 @@ store_temp(struct device *dev, struct device_attribute *attr,
509 1: To enable temp sensors monitor 512 1: To enable temp sensors monitor
510*/ 513*/
511 514
512/* 0 disable, 5 AMDSI, 6 PECI */ 515/* 0 disable, 6 PECI */
513static u8 TO_TEMP_MODE[] = { 0, 0, 5, 6 }; 516static u8 TO_TEMP_MODE[] = { 0, 0, 0, 6 };
514 517
515static ssize_t 518static ssize_t
516show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) 519show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
@@ -550,11 +553,10 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
550 u8 val = simple_strtoul(buf, NULL, 10); 553 u8 val = simple_strtoul(buf, NULL, 10);
551 554
552 /* transform the sysfs interface values into table above */ 555 /* transform the sysfs interface values into table above */
553 if ((val == 5 || val == 6) && (index < 4)) { 556 if ((val == 6) && (index < 4)) {
554 val -= 3; 557 val -= 3;
555 } else if ((val == 3 && index < 4) 558 } else if ((val == 3 && index < 4)
556 || (val == 4 && index >= 4) 559 || (val == 4 && index >= 4)) {
557 || val == 0) {
558 /* transform diode or thermistor into internal enable */ 560 /* transform diode or thermistor into internal enable */
559 val = !!val; 561 val = !!val;
560 } else { 562 } else {
@@ -839,7 +841,9 @@ show_in(struct device *dev, struct device_attribute *attr, char *buf)
839 val <<= 2; 841 val <<= 2;
840 val += (data->in_low_bits[nr] >> (index * 2)) & 0x3; 842 val += (data->in_low_bits[nr] >> (index * 2)) & 0x3;
841 } 843 }
842 return sprintf(buf, "%d\n", val * scale_in[index]); 844 /* voltage inputs 5VDD and 5VSB needs 150mV offset */
845 val = val * scale_in[index] + scale_in_add[index];
846 return sprintf(buf, "%d\n", val);
843} 847}
844 848
845static ssize_t 849static ssize_t
@@ -859,6 +863,10 @@ store_in(struct device *dev, struct device_attribute *attr,
859 scale_in[index] / 2) / scale_in[index]; 863 scale_in[index] / 2) / scale_in[index];
860 mutex_lock(&data->update_lock); 864 mutex_lock(&data->update_lock);
861 if (index > 2) { 865 if (index > 2) {
866 /* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
867 if (1 == nr || 2 == nr) {
868 val -= scale_in_add[index] / scale_in[index];
869 }
862 val = SENSORS_LIMIT(val, 0, 255); 870 val = SENSORS_LIMIT(val, 0, 255);
863 } else { 871 } else {
864 val = SENSORS_LIMIT(val, 0, 0x3FF); 872 val = SENSORS_LIMIT(val, 0, 0x3FF);
@@ -979,12 +987,6 @@ static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
979 SENSOR_ATTR_IN(7), 987 SENSOR_ATTR_IN(7),
980 SENSOR_ATTR_IN(8), 988 SENSOR_ATTR_IN(8),
981 SENSOR_ATTR_IN(9), 989 SENSOR_ATTR_IN(9),
982 SENSOR_ATTR_TEMP(1),
983 SENSOR_ATTR_TEMP(2),
984 SENSOR_ATTR_TEMP(3),
985 SENSOR_ATTR_TEMP(4),
986 SENSOR_ATTR_TEMP(5),
987 SENSOR_ATTR_TEMP(6),
988 SENSOR_ATTR_FAN(1), 990 SENSOR_ATTR_FAN(1),
989 SENSOR_ATTR_FAN(2), 991 SENSOR_ATTR_FAN(2),
990 SENSOR_ATTR_FAN(3), 992 SENSOR_ATTR_FAN(3),
@@ -995,6 +997,15 @@ static struct sensor_device_attribute_2 w83793_sensor_attr_2[] = {
995 SENSOR_ATTR_PWM(3), 997 SENSOR_ATTR_PWM(3),
996}; 998};
997 999
1000static struct sensor_device_attribute_2 w83793_temp[] = {
1001 SENSOR_ATTR_TEMP(1),
1002 SENSOR_ATTR_TEMP(2),
1003 SENSOR_ATTR_TEMP(3),
1004 SENSOR_ATTR_TEMP(4),
1005 SENSOR_ATTR_TEMP(5),
1006 SENSOR_ATTR_TEMP(6),
1007};
1008
998/* Fan6-Fan12 */ 1009/* Fan6-Fan12 */
999static struct sensor_device_attribute_2 w83793_left_fan[] = { 1010static struct sensor_device_attribute_2 w83793_left_fan[] = {
1000 SENSOR_ATTR_FAN(6), 1011 SENSOR_ATTR_FAN(6),
@@ -1015,9 +1026,12 @@ static struct sensor_device_attribute_2 w83793_left_pwm[] = {
1015 SENSOR_ATTR_PWM(8), 1026 SENSOR_ATTR_PWM(8),
1016}; 1027};
1017 1028
1018static struct sensor_device_attribute_2 sda_single_files[] = { 1029static struct sensor_device_attribute_2 w83793_vid[] = {
1019 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0), 1030 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0),
1020 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1), 1031 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1),
1032};
1033
1034static struct sensor_device_attribute_2 sda_single_files[] = {
1021 SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm, 1035 SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm,
1022 NOT_USED, NOT_USED), 1036 NOT_USED, NOT_USED),
1023 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, 1037 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
@@ -1070,11 +1084,17 @@ static int w83793_detach_client(struct i2c_client *client)
1070 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) 1084 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1071 device_remove_file(dev, &sda_single_files[i].dev_attr); 1085 device_remove_file(dev, &sda_single_files[i].dev_attr);
1072 1086
1087 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
1088 device_remove_file(dev, &w83793_vid[i].dev_attr);
1089
1073 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) 1090 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1074 device_remove_file(dev, &w83793_left_fan[i].dev_attr); 1091 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1075 1092
1076 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) 1093 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1077 device_remove_file(dev, &w83793_left_pwm[i].dev_attr); 1094 device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1095
1096 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1097 device_remove_file(dev, &w83793_temp[i].dev_attr);
1078 } 1098 }
1079 1099
1080 if ((err = i2c_detach_client(client))) 1100 if ((err = i2c_detach_client(client)))
@@ -1187,6 +1207,7 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1187 struct w83793_data *data; 1207 struct w83793_data *data;
1188 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7; 1208 int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
1189 int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5; 1209 int files_pwm = ARRAY_SIZE(w83793_left_pwm) / 5;
1210 int files_temp = ARRAY_SIZE(w83793_temp) / 6;
1190 int err = 0; 1211 int err = 0;
1191 1212
1192 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1213 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -1313,6 +1334,44 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1313 data->has_pwm |= 0x80; 1334 data->has_pwm |= 0x80;
1314 } 1335 }
1315 1336
1337 tmp = w83793_read_value(client, W83793_REG_FANIN_SEL);
1338 if ((tmp & 0x01) && (val & 0x08)) { /* fan 9, second location */
1339 data->has_fan |= 0x100;
1340 }
1341 if ((tmp & 0x02) && (val & 0x10)) { /* fan 10, second location */
1342 data->has_fan |= 0x200;
1343 }
1344 if ((tmp & 0x04) && (val & 0x20)) { /* fan 11, second location */
1345 data->has_fan |= 0x400;
1346 }
1347 if ((tmp & 0x08) && (val & 0x40)) { /* fan 12, second location */
1348 data->has_fan |= 0x800;
1349 }
1350
1351 /* check the temp1-6 mode, ignore former AMDSI selected inputs */
1352 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[0]);
1353 if (tmp & 0x01)
1354 data->has_temp |= 0x01;
1355 if (tmp & 0x04)
1356 data->has_temp |= 0x02;
1357 if (tmp & 0x10)
1358 data->has_temp |= 0x04;
1359 if (tmp & 0x40)
1360 data->has_temp |= 0x08;
1361
1362 tmp = w83793_read_value(client,W83793_REG_TEMP_MODE[1]);
1363 if (tmp & 0x01)
1364 data->has_temp |= 0x10;
1365 if (tmp & 0x02)
1366 data->has_temp |= 0x20;
1367
1368 /* Detect the VID usage and ignore unused input */
1369 tmp = w83793_read_value(client, W83793_REG_MFC);
1370 if (!(tmp & 0x29))
1371 data->has_vid |= 0x1; /* has VIDA */
1372 if (tmp & 0x80)
1373 data->has_vid |= 0x2; /* has VIDB */
1374
1316 /* Register sysfs hooks */ 1375 /* Register sysfs hooks */
1317 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) { 1376 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) {
1318 err = device_create_file(dev, 1377 err = device_create_file(dev,
@@ -1321,6 +1380,14 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1321 goto exit_remove; 1380 goto exit_remove;
1322 } 1381 }
1323 1382
1383 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) {
1384 if (!(data->has_vid & (1 << i)))
1385 continue;
1386 err = device_create_file(dev, &w83793_vid[i].dev_attr);
1387 if (err)
1388 goto exit_remove;
1389 }
1390
1324 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { 1391 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1325 err = device_create_file(dev, &sda_single_files[i].dev_attr); 1392 err = device_create_file(dev, &sda_single_files[i].dev_attr);
1326 if (err) 1393 if (err)
@@ -1328,6 +1395,19 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1328 1395
1329 } 1396 }
1330 1397
1398 for (i = 0; i < 6; i++) {
1399 int j;
1400 if (!(data->has_temp & (1 << i)))
1401 continue;
1402 for (j = 0; j < files_temp; j++) {
1403 err = device_create_file(dev,
1404 &w83793_temp[(i) * files_temp
1405 + j].dev_attr);
1406 if (err)
1407 goto exit_remove;
1408 }
1409 }
1410
1331 for (i = 5; i < 12; i++) { 1411 for (i = 5; i < 12; i++) {
1332 int j; 1412 int j;
1333 if (!(data->has_fan & (1 << i))) 1413 if (!(data->has_fan & (1 << i)))
@@ -1371,12 +1451,18 @@ exit_remove:
1371 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) 1451 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++)
1372 device_remove_file(dev, &sda_single_files[i].dev_attr); 1452 device_remove_file(dev, &sda_single_files[i].dev_attr);
1373 1453
1454 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
1455 device_remove_file(dev, &w83793_vid[i].dev_attr);
1456
1374 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) 1457 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1375 device_remove_file(dev, &w83793_left_fan[i].dev_attr); 1458 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
1376 1459
1377 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++) 1460 for (i = 0; i < ARRAY_SIZE(w83793_left_pwm); i++)
1378 device_remove_file(dev, &w83793_left_pwm[i].dev_attr); 1461 device_remove_file(dev, &w83793_left_pwm[i].dev_attr);
1379 1462
1463 for (i = 0; i < ARRAY_SIZE(w83793_temp); i++)
1464 device_remove_file(dev, &w83793_temp[i].dev_attr);
1465
1380 if (data->lm75[0] != NULL) { 1466 if (data->lm75[0] != NULL) {
1381 i2c_detach_client(data->lm75[0]); 1467 i2c_detach_client(data->lm75[0]);
1382 kfree(data->lm75[0]); 1468 kfree(data->lm75[0]);
@@ -1428,6 +1514,8 @@ static void w83793_update_nonvolatile(struct device *dev)
1428 } 1514 }
1429 1515
1430 for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) { 1516 for (i = 0; i < ARRAY_SIZE(data->temp_fan_map); i++) {
1517 if (!(data->has_temp & (1 << i)))
1518 continue;
1431 data->temp_fan_map[i] = 1519 data->temp_fan_map[i] =
1432 w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i)); 1520 w83793_read_value(client, W83793_REG_TEMP_FAN_MAP(i));
1433 for (j = 1; j < 5; j++) { 1521 for (j = 1; j < 5; j++) {
@@ -1510,9 +1598,12 @@ static struct w83793_data *w83793_update_device(struct device *dev)
1510 w83793_read_value(client, W83793_REG_FAN(i) + 1); 1598 w83793_read_value(client, W83793_REG_FAN(i) + 1);
1511 } 1599 }
1512 1600
1513 for (i = 0; i < ARRAY_SIZE(data->temp); i++) 1601 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
1602 if (!(data->has_temp & (1 << i)))
1603 continue;
1514 data->temp[i][TEMP_READ] = 1604 data->temp[i][TEMP_READ] =
1515 w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]); 1605 w83793_read_value(client, W83793_REG_TEMP[i][TEMP_READ]);
1606 }
1516 1607
1517 data->temp_low_bits = 1608 data->temp_low_bits =
1518 w83793_read_value(client, W83793_REG_TEMP_LOW_BITS); 1609 w83793_read_value(client, W83793_REG_TEMP_LOW_BITS);
@@ -1527,8 +1618,10 @@ static struct w83793_data *w83793_update_device(struct device *dev)
1527 for (i = 0; i < ARRAY_SIZE(data->alarms); i++) 1618 for (i = 0; i < ARRAY_SIZE(data->alarms); i++)
1528 data->alarms[i] = 1619 data->alarms[i] =
1529 w83793_read_value(client, W83793_REG_ALARM(i)); 1620 w83793_read_value(client, W83793_REG_ALARM(i));
1530 data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA); 1621 if (data->has_vid & 0x01)
1531 data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB); 1622 data->vid[0] = w83793_read_value(client, W83793_REG_VID_INA);
1623 if (data->has_vid & 0x02)
1624 data->vid[1] = w83793_read_value(client, W83793_REG_VID_INB);
1532 w83793_update_nonvolatile(dev); 1625 w83793_update_nonvolatile(dev);
1533 data->last_updated = jiffies; 1626 data->last_updated = jiffies;
1534 data->valid = 1; 1627 data->valid = 1;
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index df7d1504f84e..98410ca044cf 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -73,3 +73,8 @@ void __init pnpide_init(void)
73{ 73{
74 pnp_register_driver(&idepnp_driver); 74 pnp_register_driver(&idepnp_driver);
75} 75}
76
77void __exit pnpide_exit(void)
78{
79 pnp_unregister_driver(&idepnp_driver);
80}
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 16890769dca6..3b334af0c7b9 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -1782,6 +1782,7 @@ done:
1782} 1782}
1783 1783
1784extern void pnpide_init(void); 1784extern void pnpide_init(void);
1785extern void pnpide_exit(void);
1785extern void h8300_ide_init(void); 1786extern void h8300_ide_init(void);
1786 1787
1787/* 1788/*
@@ -2094,6 +2095,10 @@ void cleanup_module (void)
2094 for (index = 0; index < MAX_HWIFS; ++index) 2095 for (index = 0; index < MAX_HWIFS; ++index)
2095 ide_unregister(index); 2096 ide_unregister(index);
2096 2097
2098#ifdef CONFIG_BLK_DEV_IDEPNP
2099 pnpide_exit();
2100#endif
2101
2097#ifdef CONFIG_PROC_FS 2102#ifdef CONFIG_PROC_FS
2098 proc_ide_destroy(); 2103 proc_ide_destroy();
2099#endif 2104#endif
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index f286079d233f..d261bfbad222 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -441,7 +441,7 @@ static struct pci_driver driver = {
441 .probe = aec62xx_init_one, 441 .probe = aec62xx_init_one,
442}; 442};
443 443
444static int aec62xx_ide_init(void) 444static int __init aec62xx_ide_init(void)
445{ 445{
446 return ide_pci_register_driver(&driver); 446 return ide_pci_register_driver(&driver);
447} 447}
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 89109be5162c..68df77ec502b 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -907,7 +907,7 @@ static struct pci_driver driver = {
907 .probe = alim15x3_init_one, 907 .probe = alim15x3_init_one,
908}; 908};
909 909
910static int ali15x3_ide_init(void) 910static int __init ali15x3_ide_init(void)
911{ 911{
912 return ide_pci_register_driver(&driver); 912 return ide_pci_register_driver(&driver);
913} 913}
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 753fe0e21456..a4336995a410 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -544,7 +544,7 @@ static struct pci_driver driver = {
544 .probe = amd74xx_probe, 544 .probe = amd74xx_probe,
545}; 545};
546 546
547static int amd74xx_ide_init(void) 547static int __init amd74xx_ide_init(void)
548{ 548{
549 return ide_pci_register_driver(&driver); 549 return ide_pci_register_driver(&driver);
550} 550}
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 524e65de4398..982ac31fa995 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -291,8 +291,12 @@ fast_ata_pio:
291 291
292static void __devinit init_hwif_atiixp(ide_hwif_t *hwif) 292static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
293{ 293{
294 u8 udma_mode = 0;
295 u8 ch = hwif->channel;
296 struct pci_dev *pdev = hwif->pci_dev;
297
294 if (!hwif->irq) 298 if (!hwif->irq)
295 hwif->irq = hwif->channel ? 15 : 14; 299 hwif->irq = ch ? 15 : 14;
296 300
297 hwif->autodma = 0; 301 hwif->autodma = 0;
298 hwif->tuneproc = &atiixp_tuneproc; 302 hwif->tuneproc = &atiixp_tuneproc;
@@ -308,8 +312,12 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
308 hwif->mwdma_mask = 0x06; 312 hwif->mwdma_mask = 0x06;
309 hwif->swdma_mask = 0x04; 313 hwif->swdma_mask = 0x04;
310 314
311 /* FIXME: proper cable detection needed */ 315 pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ch, &udma_mode);
312 hwif->udma_four = 1; 316 if ((udma_mode & 0x07) >= 0x04 || (udma_mode & 0x70) >= 0x40)
317 hwif->udma_four = 1;
318 else
319 hwif->udma_four = 0;
320
313 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on; 321 hwif->ide_dma_host_on = &atiixp_ide_dma_host_on;
314 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off; 322 hwif->ide_dma_host_off = &atiixp_ide_dma_host_off;
315 hwif->ide_dma_check = &atiixp_dma_check; 323 hwif->ide_dma_check = &atiixp_dma_check;
@@ -320,19 +328,6 @@ static void __devinit init_hwif_atiixp(ide_hwif_t *hwif)
320 hwif->drives[0].autodma = hwif->autodma; 328 hwif->drives[0].autodma = hwif->autodma;
321} 329}
322 330
323static void __devinit init_hwif_sb600_legacy(ide_hwif_t *hwif)
324{
325
326 hwif->atapi_dma = 1;
327 hwif->ultra_mask = 0x7f;
328 hwif->mwdma_mask = 0x07;
329 hwif->swdma_mask = 0x07;
330
331 if (!noautodma)
332 hwif->autodma = 1;
333 hwif->drives[0].autodma = hwif->autodma;
334 hwif->drives[1].autodma = hwif->autodma;
335}
336 331
337static ide_pci_device_t atiixp_pci_info[] __devinitdata = { 332static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
338 { /* 0 */ 333 { /* 0 */
@@ -343,12 +338,13 @@ static ide_pci_device_t atiixp_pci_info[] __devinitdata = {
343 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 338 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
344 .bootable = ON_BOARD, 339 .bootable = ON_BOARD,
345 },{ /* 1 */ 340 },{ /* 1 */
346 .name = "ATI SB600 SATA Legacy IDE", 341 .name = "SB600_PATA",
347 .init_hwif = init_hwif_sb600_legacy, 342 .init_hwif = init_hwif_atiixp,
348 .channels = 2, 343 .channels = 1,
349 .autodma = AUTODMA, 344 .autodma = AUTODMA,
350 .bootable = ON_BOARD, 345 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
351 } 346 .bootable = ON_BOARD,
347 },
352}; 348};
353 349
354/** 350/**
@@ -369,7 +365,7 @@ static struct pci_device_id atiixp_pci_tbl[] = {
369 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 365 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
370 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 366 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
371 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 367 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
372 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
373 { 0, }, 369 { 0, },
374}; 370};
375MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 371MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
@@ -380,7 +376,7 @@ static struct pci_driver driver = {
380 .probe = atiixp_init_one, 376 .probe = atiixp_init_one,
381}; 377};
382 378
383static int atiixp_ide_init(void) 379static int __init atiixp_ide_init(void)
384{ 380{
385 return ide_pci_register_driver(&driver); 381 return ide_pci_register_driver(&driver);
386} 382}
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 20c32716bbc4..aee947e8fc38 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -793,7 +793,7 @@ static struct pci_driver driver = {
793 .probe = cmd64x_init_one, 793 .probe = cmd64x_init_one,
794}; 794};
795 795
796static int cmd64x_ide_init(void) 796static int __init cmd64x_ide_init(void)
797{ 797{
798 return ide_pci_register_driver(&driver); 798 return ide_pci_register_driver(&driver);
799} 799}
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 079f7c86726b..ba6786aabf3b 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -260,7 +260,7 @@ static struct pci_driver driver = {
260 .probe = cs5520_init_one, 260 .probe = cs5520_init_one,
261}; 261};
262 262
263static int cs5520_ide_init(void) 263static int __init cs5520_ide_init(void)
264{ 264{
265 return ide_pci_register_driver(&driver); 265 return ide_pci_register_driver(&driver);
266} 266}
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index ae405fa32236..9bf5fdfc5b1f 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -374,7 +374,7 @@ static struct pci_driver driver = {
374 .probe = cs5530_init_one, 374 .probe = cs5530_init_one,
375}; 375};
376 376
377static int cs5530_ide_init(void) 377static int __init cs5530_ide_init(void)
378{ 378{
379 return ide_pci_register_driver(&driver); 379 return ide_pci_register_driver(&driver);
380} 380}
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 64330c459bd4..9eafcbf444f4 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -519,7 +519,7 @@ static struct pci_driver driver = {
519 .probe = cy82c693_init_one, 519 .probe = cy82c693_init_one,
520}; 520};
521 521
522static int cy82c693_ide_init(void) 522static int __init cy82c693_ide_init(void)
523{ 523{
524 return ide_pci_register_driver(&driver); 524 return ide_pci_register_driver(&driver);
525} 525}
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 9f306880491a..b408c6c517ea 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -185,36 +185,6 @@ static ide_pci_device_t generic_chipsets[] __devinitdata = {
185 .channels = 2, 185 .channels = 2,
186 .autodma = AUTODMA, 186 .autodma = AUTODMA,
187 .bootable = OFF_BOARD, 187 .bootable = OFF_BOARD,
188 },{ /* 15 */
189 .name = "JMB361",
190 .init_hwif = init_hwif_generic,
191 .channels = 2,
192 .autodma = AUTODMA,
193 .bootable = OFF_BOARD,
194 },{ /* 16 */
195 .name = "JMB363",
196 .init_hwif = init_hwif_generic,
197 .channels = 2,
198 .autodma = AUTODMA,
199 .bootable = OFF_BOARD,
200 },{ /* 17 */
201 .name = "JMB365",
202 .init_hwif = init_hwif_generic,
203 .channels = 2,
204 .autodma = AUTODMA,
205 .bootable = OFF_BOARD,
206 },{ /* 18 */
207 .name = "JMB366",
208 .init_hwif = init_hwif_generic,
209 .channels = 2,
210 .autodma = AUTODMA,
211 .bootable = OFF_BOARD,
212 },{ /* 19 */
213 .name = "JMB368",
214 .init_hwif = init_hwif_generic,
215 .channels = 2,
216 .autodma = AUTODMA,
217 .bootable = OFF_BOARD,
218 } 188 }
219}; 189};
220 190
@@ -281,11 +251,6 @@ static struct pci_device_id generic_pci_tbl[] = {
281 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12}, 251 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12},
282 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13}, 252 { PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13},
283 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14}, 253 { PCI_VENDOR_ID_NETCELL,PCI_DEVICE_ID_REVOLUTION, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14},
284 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15},
285 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16},
286 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 17},
287 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 18},
288 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 19},
289 /* Must come last. If you add entries adjust this table appropriately and the init_one code */ 254 /* Must come last. If you add entries adjust this table appropriately and the init_one code */
290 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0}, 255 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 0},
291 { 0, }, 256 { 0, },
@@ -298,7 +263,7 @@ static struct pci_driver driver = {
298 .probe = generic_init_one, 263 .probe = generic_init_one,
299}; 264};
300 265
301static int generic_ide_init(void) 266static int __init generic_ide_init(void)
302{ 267{
303 return ide_pci_register_driver(&driver); 268 return ide_pci_register_driver(&driver);
304} 269}
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index b46cb042290a..ce7b08f08a09 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -265,7 +265,7 @@ static struct pci_driver driver = {
265 .probe = hpt34x_init_one, 265 .probe = hpt34x_init_one,
266}; 266};
267 267
268static int hpt34x_ide_init(void) 268static int __init hpt34x_ide_init(void)
269{ 269{
270 return ide_pci_register_driver(&driver); 270 return ide_pci_register_driver(&driver);
271} 271}
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 08119da06d54..b486442dd5d7 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -1613,7 +1613,7 @@ static struct pci_driver driver = {
1613 .probe = hpt366_init_one, 1613 .probe = hpt366_init_one,
1614}; 1614};
1615 1615
1616static int hpt366_ide_init(void) 1616static int __init hpt366_ide_init(void)
1617{ 1617{
1618 return ide_pci_register_driver(&driver); 1618 return ide_pci_register_driver(&driver);
1619} 1619}
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index c1cec236ecf0..f07bbbed1778 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -86,15 +86,16 @@ static int __devinit ata66_jmicron(ide_hwif_t *hwif)
86 { 86 {
87 case PORT_PATA0: 87 case PORT_PATA0:
88 if (control & (1 << 3)) /* 40/80 pin primary */ 88 if (control & (1 << 3)) /* 40/80 pin primary */
89 return 1; 89 return 0;
90 return 0; 90 return 1;
91 case PORT_PATA1: 91 case PORT_PATA1:
92 if (control5 & (1 << 19)) /* 40/80 pin secondary */ 92 if (control5 & (1 << 19)) /* 40/80 pin secondary */
93 return 0; 93 return 0;
94 return 1; 94 return 1;
95 case PORT_SATA: 95 case PORT_SATA:
96 return 1; 96 break;
97 } 97 }
98 return 1; /* Avoid bogus "control reaches end of non-void function" */
98} 99}
99 100
100static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted) 101static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
@@ -240,11 +241,11 @@ static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_devi
240} 241}
241 242
242static struct pci_device_id jmicron_pci_tbl[] = { 243static struct pci_device_id jmicron_pci_tbl[] = {
243 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361), 0}, 244 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
244 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363), 1}, 245 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
245 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365), 2}, 246 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
246 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366), 3}, 247 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
247 { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368), 4}, 248 { PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
248 { 0, }, 249 { 0, },
249}; 250};
250 251
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index d95714bcee4e..8aaea4ea5549 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -302,7 +302,7 @@ static struct pci_driver driver = {
302 .probe = ns87415_init_one, 302 .probe = ns87415_init_one,
303}; 303};
304 304
305static int ns87415_ide_init(void) 305static int __init ns87415_ide_init(void)
306{ 306{
307 return ide_pci_register_driver(&driver); 307 return ide_pci_register_driver(&driver);
308} 308}
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 7a7c2ef78ac2..22bbf613f948 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -382,7 +382,7 @@ static struct pci_driver driver = {
382 .probe = opti621_init_one, 382 .probe = opti621_init_one,
383}; 383};
384 384
385static int opti621_ide_init(void) 385static int __init opti621_ide_init(void)
386{ 386{
387 return ide_pci_register_driver(&driver); 387 return ide_pci_register_driver(&driver);
388} 388}
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 7cb48576e479..77a9aaa7dab9 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -756,7 +756,7 @@ static struct pci_driver driver = {
756 .probe = pdc202new_init_one, 756 .probe = pdc202new_init_one,
757}; 757};
758 758
759static int pdc202new_ide_init(void) 759static int __init pdc202new_ide_init(void)
760{ 760{
761 return ide_pci_register_driver(&driver); 761 return ide_pci_register_driver(&driver);
762} 762}
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index 184cdacddeb6..143239c093d5 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -719,7 +719,7 @@ static struct pci_driver driver = {
719 .probe = pdc202xx_init_one, 719 .probe = pdc202xx_init_one,
720}; 720};
721 721
722static int pdc202xx_ide_init(void) 722static int __init pdc202xx_ide_init(void)
723{ 723{
724 return ide_pci_register_driver(&driver); 724 return ide_pci_register_driver(&driver);
725} 725}
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index 5f6950c2d1d1..c1855311052b 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -77,7 +77,7 @@ static struct pci_driver driver = {
77 .probe = rz1000_init_one, 77 .probe = rz1000_init_one,
78}; 78};
79 79
80static int rz1000_ide_init(void) 80static int __init rz1000_ide_init(void)
81{ 81{
82 return ide_pci_register_driver(&driver); 82 return ide_pci_register_driver(&driver);
83} 83}
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index ff80937d94dd..8d762d323f8b 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -507,7 +507,7 @@ static struct pci_driver driver = {
507#endif 507#endif
508}; 508};
509 509
510static int sc1200_ide_init(void) 510static int __init sc1200_ide_init(void)
511{ 511{
512 return ide_pci_register_driver(&driver); 512 return ide_pci_register_driver(&driver);
513} 513}
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 057548d07205..ea9a28a45853 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -666,7 +666,7 @@ static struct pci_driver driver = {
666 .probe = svwks_init_one, 666 .probe = svwks_init_one,
667}; 667};
668 668
669static int svwks_ide_init(void) 669static int __init svwks_ide_init(void)
670{ 670{
671 return ide_pci_register_driver(&driver); 671 return ide_pci_register_driver(&driver);
672} 672}
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index cfad09accf52..b0bf01809279 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -762,8 +762,7 @@ static struct ioc4_submodule ioc4_ide_submodule = {
762/* .is_remove = ioc4_ide_remove_one, */ 762/* .is_remove = ioc4_ide_remove_one, */
763}; 763};
764 764
765static int __devinit 765static int __init ioc4_ide_init(void)
766ioc4_ide_init(void)
767{ 766{
768 return ioc4_register_submodule(&ioc4_ide_submodule); 767 return ioc4_register_submodule(&ioc4_ide_submodule);
769} 768}
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 697f566fb90a..4ff89c7d990a 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -1096,7 +1096,7 @@ static struct pci_driver driver = {
1096 .probe = siimage_init_one, 1096 .probe = siimage_init_one,
1097}; 1097};
1098 1098
1099static int siimage_ide_init(void) 1099static int __init siimage_ide_init(void)
1100{ 1100{
1101 return ide_pci_register_driver(&driver); 1101 return ide_pci_register_driver(&driver);
1102} 1102}
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 6b313139b5e4..1afff659ab55 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -968,7 +968,7 @@ static struct pci_driver driver = {
968 .probe = sis5513_init_one, 968 .probe = sis5513_init_one,
969}; 969};
970 970
971static int sis5513_ide_init(void) 971static int __init sis5513_ide_init(void)
972{ 972{
973 return ide_pci_register_driver(&driver); 973 return ide_pci_register_driver(&driver);
974} 974}
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 5afefe8692fe..170a26199050 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -492,7 +492,7 @@ static struct pci_driver driver = {
492 .probe = sl82c105_init_one, 492 .probe = sl82c105_init_one,
493}; 493};
494 494
495static int sl82c105_ide_init(void) 495static int __init sl82c105_ide_init(void)
496{ 496{
497 return ide_pci_register_driver(&driver); 497 return ide_pci_register_driver(&driver);
498} 498}
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 9be7e49cba0e..90e79c0844d2 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -253,7 +253,7 @@ static struct pci_driver driver = {
253 .probe = slc90e66_init_one, 253 .probe = slc90e66_init_one,
254}; 254};
255 255
256static int slc90e66_ide_init(void) 256static int __init slc90e66_ide_init(void)
257{ 257{
258 return ide_pci_register_driver(&driver); 258 return ide_pci_register_driver(&driver);
259} 259}
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 56d84931d6de..b13cce1fd1a6 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -173,7 +173,7 @@ static struct pci_driver driver = {
173 .probe = triflex_init_one, 173 .probe = triflex_init_one,
174}; 174};
175 175
176static int triflex_ide_init(void) 176static int __init triflex_ide_init(void)
177{ 177{
178 return ide_pci_register_driver(&driver); 178 return ide_pci_register_driver(&driver);
179} 179}
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 2a282529bfc1..174b88c4780e 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -355,7 +355,7 @@ static struct pci_driver driver = {
355 .probe = trm290_init_one, 355 .probe = trm290_init_one,
356}; 356};
357 357
358static int trm290_ide_init(void) 358static int __init trm290_ide_init(void)
359{ 359{
360 return ide_pci_register_driver(&driver); 360 return ide_pci_register_driver(&driver);
361} 361}
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index 381cc6f101ce..a98b4d38b9dd 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -78,6 +78,8 @@ static struct via_isa_bridge {
78 u8 rev_max; 78 u8 rev_max;
79 u16 flags; 79 u16 flags;
80} via_isa_bridges[] = { 80} via_isa_bridges[] = {
81 { "cx7000", PCI_DEVICE_ID_VIA_CX700, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
82 { "vt8237s", PCI_DEVICE_ID_VIA_8237S, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
81 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 83 { "vt6410", PCI_DEVICE_ID_VIA_6410, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
82 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 84 { "vt8251", PCI_DEVICE_ID_VIA_8251, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
83 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST }, 85 { "vt8237", PCI_DEVICE_ID_VIA_8237, 0x00, 0x2f, VIA_UDMA_133 | VIA_BAD_AST },
@@ -504,6 +506,7 @@ static struct pci_device_id via_pci_tbl[] = {
504 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 506 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
505 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 507 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
506 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_6410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1}, 508 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_6410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
509 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_SATA_EIDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
507 { 0, }, 510 { 0, },
508}; 511};
509MODULE_DEVICE_TABLE(pci, via_pci_tbl); 512MODULE_DEVICE_TABLE(pci, via_pci_tbl);
@@ -514,7 +517,7 @@ static struct pci_driver driver = {
514 .probe = via_init_one, 517 .probe = via_init_one,
515}; 518};
516 519
517static int via_ide_init(void) 520static int __init via_ide_init(void)
518{ 521{
519 return ide_pci_register_driver(&driver); 522 return ide_pci_register_driver(&driver);
520} 523}
diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c
index 93995b658d94..6074c897f51c 100644
--- a/drivers/infiniband/hw/ehca/ehca_cq.c
+++ b/drivers/infiniband/hw/ehca/ehca_cq.c
@@ -344,8 +344,11 @@ int ehca_destroy_cq(struct ib_cq *cq)
344 unsigned long flags; 344 unsigned long flags;
345 345
346 spin_lock_irqsave(&ehca_cq_idr_lock, flags); 346 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
347 while (my_cq->nr_callbacks) 347 while (my_cq->nr_callbacks) {
348 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
348 yield(); 349 yield();
350 spin_lock_irqsave(&ehca_cq_idr_lock, flags);
351 }
349 352
350 idr_remove(&ehca_cq_idr, my_cq->token); 353 idr_remove(&ehca_cq_idr, my_cq->token);
351 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags); 354 spin_unlock_irqrestore(&ehca_cq_idr_lock, flags);
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index e7209afb4250..c069be8cbcb2 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -440,7 +440,8 @@ void ehca_tasklet_eq(unsigned long data)
440 cq = idr_find(&ehca_cq_idr, token); 440 cq = idr_find(&ehca_cq_idr, token);
441 441
442 if (cq == NULL) { 442 if (cq == NULL) {
443 spin_unlock(&ehca_cq_idr_lock); 443 spin_unlock_irqrestore(&ehca_cq_idr_lock,
444 flags);
444 break; 445 break;
445 } 446 }
446 447
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index cdecbf5911c8..72611fd15103 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1621,18 +1621,30 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1621 switch (token) { 1621 switch (token) {
1622 case SRP_OPT_ID_EXT: 1622 case SRP_OPT_ID_EXT:
1623 p = match_strdup(args); 1623 p = match_strdup(args);
1624 if (!p) {
1625 ret = -ENOMEM;
1626 goto out;
1627 }
1624 target->id_ext = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1628 target->id_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
1625 kfree(p); 1629 kfree(p);
1626 break; 1630 break;
1627 1631
1628 case SRP_OPT_IOC_GUID: 1632 case SRP_OPT_IOC_GUID:
1629 p = match_strdup(args); 1633 p = match_strdup(args);
1634 if (!p) {
1635 ret = -ENOMEM;
1636 goto out;
1637 }
1630 target->ioc_guid = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1638 target->ioc_guid = cpu_to_be64(simple_strtoull(p, NULL, 16));
1631 kfree(p); 1639 kfree(p);
1632 break; 1640 break;
1633 1641
1634 case SRP_OPT_DGID: 1642 case SRP_OPT_DGID:
1635 p = match_strdup(args); 1643 p = match_strdup(args);
1644 if (!p) {
1645 ret = -ENOMEM;
1646 goto out;
1647 }
1636 if (strlen(p) != 32) { 1648 if (strlen(p) != 32) {
1637 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p); 1649 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p);
1638 kfree(p); 1650 kfree(p);
@@ -1656,6 +1668,10 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1656 1668
1657 case SRP_OPT_SERVICE_ID: 1669 case SRP_OPT_SERVICE_ID:
1658 p = match_strdup(args); 1670 p = match_strdup(args);
1671 if (!p) {
1672 ret = -ENOMEM;
1673 goto out;
1674 }
1659 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1675 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16));
1660 kfree(p); 1676 kfree(p);
1661 break; 1677 break;
@@ -1693,6 +1709,10 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1693 1709
1694 case SRP_OPT_INITIATOR_EXT: 1710 case SRP_OPT_INITIATOR_EXT:
1695 p = match_strdup(args); 1711 p = match_strdup(args);
1712 if (!p) {
1713 ret = -ENOMEM;
1714 goto out;
1715 }
1696 target->initiator_ext = cpu_to_be64(simple_strtoull(p, NULL, 16)); 1716 target->initiator_ext = cpu_to_be64(simple_strtoull(p, NULL, 16));
1697 kfree(p); 1717 kfree(p);
1698 break; 1718 break;
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 95eff3b2917a..4f75cce6fdff 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -356,16 +356,17 @@ static struct cardstate *alloc_cs(struct gigaset_driver *drv)
356{ 356{
357 unsigned long flags; 357 unsigned long flags;
358 unsigned i; 358 unsigned i;
359 static struct cardstate *ret = NULL; 359 struct cardstate *ret = NULL;
360 360
361 spin_lock_irqsave(&drv->lock, flags); 361 spin_lock_irqsave(&drv->lock, flags);
362 for (i = 0; i < drv->minors; ++i) { 362 for (i = 0; i < drv->minors; ++i) {
363 if (!(drv->flags[i] & VALID_MINOR)) { 363 if (!(drv->flags[i] & VALID_MINOR)) {
364 drv->flags[i] = VALID_MINOR; 364 if (try_module_get(drv->owner)) {
365 ret = drv->cs + i; 365 drv->flags[i] = VALID_MINOR;
366 } 366 ret = drv->cs + i;
367 if (ret) 367 }
368 break; 368 break;
369 }
369 } 370 }
370 spin_unlock_irqrestore(&drv->lock, flags); 371 spin_unlock_irqrestore(&drv->lock, flags);
371 return ret; 372 return ret;
@@ -376,6 +377,8 @@ static void free_cs(struct cardstate *cs)
376 unsigned long flags; 377 unsigned long flags;
377 struct gigaset_driver *drv = cs->driver; 378 struct gigaset_driver *drv = cs->driver;
378 spin_lock_irqsave(&drv->lock, flags); 379 spin_lock_irqsave(&drv->lock, flags);
380 if (drv->flags[cs->minor_index] & VALID_MINOR)
381 module_put(drv->owner);
379 drv->flags[cs->minor_index] = 0; 382 drv->flags[cs->minor_index] = 0;
380 spin_unlock_irqrestore(&drv->lock, flags); 383 spin_unlock_irqrestore(&drv->lock, flags);
381} 384}
@@ -579,7 +582,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
579 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 582 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
580 skb_reserve(bcs->skb, HW_HDR_LEN); 583 skb_reserve(bcs->skb, HW_HDR_LEN);
581 else { 584 else {
582 warn("could not allocate skb\n"); 585 warn("could not allocate skb");
583 bcs->inputstate |= INS_skip_frame; 586 bcs->inputstate |= INS_skip_frame;
584 } 587 }
585 588
@@ -632,17 +635,25 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
632 int i; 635 int i;
633 636
634 gig_dbg(DEBUG_INIT, "allocating cs"); 637 gig_dbg(DEBUG_INIT, "allocating cs");
635 cs = alloc_cs(drv); 638 if (!(cs = alloc_cs(drv))) {
636 if (!cs) 639 err("maximum number of devices exceeded");
637 goto error; 640 return NULL;
641 }
642 mutex_init(&cs->mutex);
643 mutex_lock(&cs->mutex);
644
638 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); 645 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
639 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); 646 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
640 if (!cs->bcs) 647 if (!cs->bcs) {
648 err("out of memory");
641 goto error; 649 goto error;
650 }
642 gig_dbg(DEBUG_INIT, "allocating inbuf"); 651 gig_dbg(DEBUG_INIT, "allocating inbuf");
643 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); 652 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
644 if (!cs->inbuf) 653 if (!cs->inbuf) {
654 err("out of memory");
645 goto error; 655 goto error;
656 }
646 657
647 cs->cs_init = 0; 658 cs->cs_init = 0;
648 cs->channels = channels; 659 cs->channels = channels;
@@ -654,8 +665,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
654 spin_lock_init(&cs->ev_lock); 665 spin_lock_init(&cs->ev_lock);
655 cs->ev_tail = 0; 666 cs->ev_tail = 0;
656 cs->ev_head = 0; 667 cs->ev_head = 0;
657 mutex_init(&cs->mutex);
658 mutex_lock(&cs->mutex);
659 668
660 tasklet_init(&cs->event_tasklet, &gigaset_handle_event, 669 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
661 (unsigned long) cs); 670 (unsigned long) cs);
@@ -684,8 +693,10 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
684 693
685 for (i = 0; i < channels; ++i) { 694 for (i = 0; i < channels; ++i) {
686 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i); 695 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
687 if (!gigaset_initbcs(cs->bcs + i, cs, i)) 696 if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
697 err("could not allocate channel %d data", i);
688 goto error; 698 goto error;
699 }
689 } 700 }
690 701
691 ++cs->cs_init; 702 ++cs->cs_init;
@@ -720,8 +731,10 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
720 make_valid(cs, VALID_ID); 731 make_valid(cs, VALID_ID);
721 ++cs->cs_init; 732 ++cs->cs_init;
722 gig_dbg(DEBUG_INIT, "setting up hw"); 733 gig_dbg(DEBUG_INIT, "setting up hw");
723 if (!cs->ops->initcshw(cs)) 734 if (!cs->ops->initcshw(cs)) {
735 err("could not allocate device specific data");
724 goto error; 736 goto error;
737 }
725 738
726 ++cs->cs_init; 739 ++cs->cs_init;
727 740
@@ -743,8 +756,8 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
743 mutex_unlock(&cs->mutex); 756 mutex_unlock(&cs->mutex);
744 return cs; 757 return cs;
745 758
746error: if (cs) 759error:
747 mutex_unlock(&cs->mutex); 760 mutex_unlock(&cs->mutex);
748 gig_dbg(DEBUG_INIT, "failed"); 761 gig_dbg(DEBUG_INIT, "failed");
749 gigaset_freecs(cs); 762 gigaset_freecs(cs);
750 return NULL; 763 return NULL;
@@ -1040,7 +1053,6 @@ void gigaset_freedriver(struct gigaset_driver *drv)
1040 spin_unlock_irqrestore(&driver_lock, flags); 1053 spin_unlock_irqrestore(&driver_lock, flags);
1041 1054
1042 gigaset_if_freedriver(drv); 1055 gigaset_if_freedriver(drv);
1043 module_put(drv->owner);
1044 1056
1045 kfree(drv->cs); 1057 kfree(drv->cs);
1046 kfree(drv->flags); 1058 kfree(drv->flags);
@@ -1072,10 +1084,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1072 if (!drv) 1084 if (!drv)
1073 return NULL; 1085 return NULL;
1074 1086
1075 if (!try_module_get(owner))
1076 goto out1;
1077
1078 drv->cs = NULL;
1079 drv->have_tty = 0; 1087 drv->have_tty = 0;
1080 drv->minor = minor; 1088 drv->minor = minor;
1081 drv->minors = minors; 1089 drv->minors = minors;
@@ -1087,11 +1095,11 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1087 1095
1088 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL); 1096 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1089 if (!drv->cs) 1097 if (!drv->cs)
1090 goto out2; 1098 goto error;
1091 1099
1092 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL); 1100 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
1093 if (!drv->flags) 1101 if (!drv->flags)
1094 goto out3; 1102 goto error;
1095 1103
1096 for (i = 0; i < minors; ++i) { 1104 for (i = 0; i < minors; ++i) {
1097 drv->flags[i] = 0; 1105 drv->flags[i] = 0;
@@ -1108,11 +1116,8 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1108 1116
1109 return drv; 1117 return drv;
1110 1118
1111out3: 1119error:
1112 kfree(drv->cs); 1120 kfree(drv->cs);
1113out2:
1114 module_put(owner);
1115out1:
1116 kfree(drv); 1121 kfree(drv);
1117 return NULL; 1122 return NULL;
1118} 1123}
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 91e0c75aca8f..2db1ca4c6800 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -242,6 +242,7 @@ struct kvm_vcpu {
242 u64 pdptrs[4]; /* pae */ 242 u64 pdptrs[4]; /* pae */
243 u64 shadow_efer; 243 u64 shadow_efer;
244 u64 apic_base; 244 u64 apic_base;
245 u64 ia32_misc_enable_msr;
245 int nmsrs; 246 int nmsrs;
246 struct vmx_msr_entry *guest_msrs; 247 struct vmx_msr_entry *guest_msrs;
247 struct vmx_msr_entry *host_msrs; 248 struct vmx_msr_entry *host_msrs;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 67c1154960f0..b10972ed0c9f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -272,7 +272,9 @@ static void kvm_free_physmem(struct kvm *kvm)
272 272
273static void kvm_free_vcpu(struct kvm_vcpu *vcpu) 273static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
274{ 274{
275 vcpu_load(vcpu->kvm, vcpu_slot(vcpu));
275 kvm_mmu_destroy(vcpu); 276 kvm_mmu_destroy(vcpu);
277 vcpu_put(vcpu);
276 kvm_arch_ops->vcpu_free(vcpu); 278 kvm_arch_ops->vcpu_free(vcpu);
277} 279}
278 280
@@ -1224,6 +1226,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1224 case MSR_IA32_APICBASE: 1226 case MSR_IA32_APICBASE:
1225 data = vcpu->apic_base; 1227 data = vcpu->apic_base;
1226 break; 1228 break;
1229 case MSR_IA32_MISC_ENABLE:
1230 data = vcpu->ia32_misc_enable_msr;
1231 break;
1227#ifdef CONFIG_X86_64 1232#ifdef CONFIG_X86_64
1228 case MSR_EFER: 1233 case MSR_EFER:
1229 data = vcpu->shadow_efer; 1234 data = vcpu->shadow_efer;
@@ -1295,6 +1300,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1295 case MSR_IA32_APICBASE: 1300 case MSR_IA32_APICBASE:
1296 vcpu->apic_base = data; 1301 vcpu->apic_base = data;
1297 break; 1302 break;
1303 case MSR_IA32_MISC_ENABLE:
1304 vcpu->ia32_misc_enable_msr = data;
1305 break;
1298 default: 1306 default:
1299 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr); 1307 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr);
1300 return 1; 1308 return 1;
@@ -1598,6 +1606,10 @@ static u32 msrs_to_save[] = {
1598 1606
1599static unsigned num_msrs_to_save; 1607static unsigned num_msrs_to_save;
1600 1608
1609static u32 emulated_msrs[] = {
1610 MSR_IA32_MISC_ENABLE,
1611};
1612
1601static __init void kvm_init_msr_list(void) 1613static __init void kvm_init_msr_list(void)
1602{ 1614{
1603 u32 dummy[2]; 1615 u32 dummy[2];
@@ -1923,7 +1935,7 @@ static long kvm_dev_ioctl(struct file *filp,
1923 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list)) 1935 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
1924 goto out; 1936 goto out;
1925 n = msr_list.nmsrs; 1937 n = msr_list.nmsrs;
1926 msr_list.nmsrs = num_msrs_to_save; 1938 msr_list.nmsrs = num_msrs_to_save + ARRAY_SIZE(emulated_msrs);
1927 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list)) 1939 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
1928 goto out; 1940 goto out;
1929 r = -E2BIG; 1941 r = -E2BIG;
@@ -1933,6 +1945,11 @@ static long kvm_dev_ioctl(struct file *filp,
1933 if (copy_to_user(user_msr_list->indices, &msrs_to_save, 1945 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
1934 num_msrs_to_save * sizeof(u32))) 1946 num_msrs_to_save * sizeof(u32)))
1935 goto out; 1947 goto out;
1948 if (copy_to_user(user_msr_list->indices
1949 + num_msrs_to_save * sizeof(u32),
1950 &emulated_msrs,
1951 ARRAY_SIZE(emulated_msrs) * sizeof(u32)))
1952 goto out;
1936 r = 0; 1953 r = 0;
1937 break; 1954 break;
1938 } 1955 }
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index c6f972914f08..22c426cd8cb2 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -143,6 +143,7 @@ static int dbg = 1;
143#define PFERR_PRESENT_MASK (1U << 0) 143#define PFERR_PRESENT_MASK (1U << 0)
144#define PFERR_WRITE_MASK (1U << 1) 144#define PFERR_WRITE_MASK (1U << 1)
145#define PFERR_USER_MASK (1U << 2) 145#define PFERR_USER_MASK (1U << 2)
146#define PFERR_FETCH_MASK (1U << 4)
146 147
147#define PT64_ROOT_LEVEL 4 148#define PT64_ROOT_LEVEL 4
148#define PT32_ROOT_LEVEL 2 149#define PT32_ROOT_LEVEL 2
@@ -168,6 +169,11 @@ static int is_cpuid_PSE36(void)
168 return 1; 169 return 1;
169} 170}
170 171
172static int is_nx(struct kvm_vcpu *vcpu)
173{
174 return vcpu->shadow_efer & EFER_NX;
175}
176
171static int is_present_pte(unsigned long pte) 177static int is_present_pte(unsigned long pte)
172{ 178{
173 return pte & PT_PRESENT_MASK; 179 return pte & PT_PRESENT_MASK;
@@ -992,16 +998,6 @@ static inline int fix_read_pf(u64 *shadow_ent)
992 return 0; 998 return 0;
993} 999}
994 1000
995static int may_access(u64 pte, int write, int user)
996{
997
998 if (user && !(pte & PT_USER_MASK))
999 return 0;
1000 if (write && !(pte & PT_WRITABLE_MASK))
1001 return 0;
1002 return 1;
1003}
1004
1005static void paging_free(struct kvm_vcpu *vcpu) 1001static void paging_free(struct kvm_vcpu *vcpu)
1006{ 1002{
1007 nonpaging_free(vcpu); 1003 nonpaging_free(vcpu);
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 2dbf4307ed9e..149fa45fd9a5 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -63,13 +63,15 @@ struct guest_walker {
63 pt_element_t *ptep; 63 pt_element_t *ptep;
64 pt_element_t inherited_ar; 64 pt_element_t inherited_ar;
65 gfn_t gfn; 65 gfn_t gfn;
66 u32 error_code;
66}; 67};
67 68
68/* 69/*
69 * Fetch a guest pte for a guest virtual address 70 * Fetch a guest pte for a guest virtual address
70 */ 71 */
71static void FNAME(walk_addr)(struct guest_walker *walker, 72static int FNAME(walk_addr)(struct guest_walker *walker,
72 struct kvm_vcpu *vcpu, gva_t addr) 73 struct kvm_vcpu *vcpu, gva_t addr,
74 int write_fault, int user_fault, int fetch_fault)
73{ 75{
74 hpa_t hpa; 76 hpa_t hpa;
75 struct kvm_memory_slot *slot; 77 struct kvm_memory_slot *slot;
@@ -86,7 +88,7 @@ static void FNAME(walk_addr)(struct guest_walker *walker,
86 walker->ptep = &vcpu->pdptrs[(addr >> 30) & 3]; 88 walker->ptep = &vcpu->pdptrs[(addr >> 30) & 3];
87 root = *walker->ptep; 89 root = *walker->ptep;
88 if (!(root & PT_PRESENT_MASK)) 90 if (!(root & PT_PRESENT_MASK))
89 return; 91 goto not_present;
90 --walker->level; 92 --walker->level;
91 } 93 }
92#endif 94#endif
@@ -111,11 +113,23 @@ static void FNAME(walk_addr)(struct guest_walker *walker,
111 ASSERT(((unsigned long)walker->table & PAGE_MASK) == 113 ASSERT(((unsigned long)walker->table & PAGE_MASK) ==
112 ((unsigned long)ptep & PAGE_MASK)); 114 ((unsigned long)ptep & PAGE_MASK));
113 115
114 if (is_present_pte(*ptep) && !(*ptep & PT_ACCESSED_MASK))
115 *ptep |= PT_ACCESSED_MASK;
116
117 if (!is_present_pte(*ptep)) 116 if (!is_present_pte(*ptep))
118 break; 117 goto not_present;
118
119 if (write_fault && !is_writeble_pte(*ptep))
120 if (user_fault || is_write_protection(vcpu))
121 goto access_error;
122
123 if (user_fault && !(*ptep & PT_USER_MASK))
124 goto access_error;
125
126#if PTTYPE == 64
127 if (fetch_fault && is_nx(vcpu) && (*ptep & PT64_NX_MASK))
128 goto access_error;
129#endif
130
131 if (!(*ptep & PT_ACCESSED_MASK))
132 *ptep |= PT_ACCESSED_MASK; /* avoid rmw */
119 133
120 if (walker->level == PT_PAGE_TABLE_LEVEL) { 134 if (walker->level == PT_PAGE_TABLE_LEVEL) {
121 walker->gfn = (*ptep & PT_BASE_ADDR_MASK) 135 walker->gfn = (*ptep & PT_BASE_ADDR_MASK)
@@ -146,6 +160,23 @@ static void FNAME(walk_addr)(struct guest_walker *walker,
146 } 160 }
147 walker->ptep = ptep; 161 walker->ptep = ptep;
148 pgprintk("%s: pte %llx\n", __FUNCTION__, (u64)*ptep); 162 pgprintk("%s: pte %llx\n", __FUNCTION__, (u64)*ptep);
163 return 1;
164
165not_present:
166 walker->error_code = 0;
167 goto err;
168
169access_error:
170 walker->error_code = PFERR_PRESENT_MASK;
171
172err:
173 if (write_fault)
174 walker->error_code |= PFERR_WRITE_MASK;
175 if (user_fault)
176 walker->error_code |= PFERR_USER_MASK;
177 if (fetch_fault)
178 walker->error_code |= PFERR_FETCH_MASK;
179 return 0;
149} 180}
150 181
151static void FNAME(release_walker)(struct guest_walker *walker) 182static void FNAME(release_walker)(struct guest_walker *walker)
@@ -274,7 +305,7 @@ static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
274 struct kvm_mmu_page *page; 305 struct kvm_mmu_page *page;
275 306
276 if (is_writeble_pte(*shadow_ent)) 307 if (is_writeble_pte(*shadow_ent))
277 return 0; 308 return !user || (*shadow_ent & PT_USER_MASK);
278 309
279 writable_shadow = *shadow_ent & PT_SHADOW_WRITABLE_MASK; 310 writable_shadow = *shadow_ent & PT_SHADOW_WRITABLE_MASK;
280 if (user) { 311 if (user) {
@@ -347,8 +378,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
347 u32 error_code) 378 u32 error_code)
348{ 379{
349 int write_fault = error_code & PFERR_WRITE_MASK; 380 int write_fault = error_code & PFERR_WRITE_MASK;
350 int pte_present = error_code & PFERR_PRESENT_MASK;
351 int user_fault = error_code & PFERR_USER_MASK; 381 int user_fault = error_code & PFERR_USER_MASK;
382 int fetch_fault = error_code & PFERR_FETCH_MASK;
352 struct guest_walker walker; 383 struct guest_walker walker;
353 u64 *shadow_pte; 384 u64 *shadow_pte;
354 int fixed; 385 int fixed;
@@ -365,19 +396,20 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
365 /* 396 /*
366 * Look up the shadow pte for the faulting address. 397 * Look up the shadow pte for the faulting address.
367 */ 398 */
368 FNAME(walk_addr)(&walker, vcpu, addr); 399 r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault,
369 shadow_pte = FNAME(fetch)(vcpu, addr, &walker); 400 fetch_fault);
370 401
371 /* 402 /*
372 * The page is not mapped by the guest. Let the guest handle it. 403 * The page is not mapped by the guest. Let the guest handle it.
373 */ 404 */
374 if (!shadow_pte) { 405 if (!r) {
375 pgprintk("%s: not mapped\n", __FUNCTION__); 406 pgprintk("%s: guest page fault\n", __FUNCTION__);
376 inject_page_fault(vcpu, addr, error_code); 407 inject_page_fault(vcpu, addr, walker.error_code);
377 FNAME(release_walker)(&walker); 408 FNAME(release_walker)(&walker);
378 return 0; 409 return 0;
379 } 410 }
380 411
412 shadow_pte = FNAME(fetch)(vcpu, addr, &walker);
381 pgprintk("%s: shadow pte %p %llx\n", __FUNCTION__, 413 pgprintk("%s: shadow pte %p %llx\n", __FUNCTION__,
382 shadow_pte, *shadow_pte); 414 shadow_pte, *shadow_pte);
383 415
@@ -399,22 +431,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
399 * mmio: emulate if accessible, otherwise its a guest fault. 431 * mmio: emulate if accessible, otherwise its a guest fault.
400 */ 432 */
401 if (is_io_pte(*shadow_pte)) { 433 if (is_io_pte(*shadow_pte)) {
402 if (may_access(*shadow_pte, write_fault, user_fault)) 434 return 1;
403 return 1;
404 pgprintk("%s: io work, no access\n", __FUNCTION__);
405 inject_page_fault(vcpu, addr,
406 error_code | PFERR_PRESENT_MASK);
407 kvm_mmu_audit(vcpu, "post page fault (io)");
408 return 0;
409 }
410
411 /*
412 * pte not present, guest page fault.
413 */
414 if (pte_present && !fixed && !write_pt) {
415 inject_page_fault(vcpu, addr, error_code);
416 kvm_mmu_audit(vcpu, "post page fault (guest)");
417 return 0;
418 } 435 }
419 436
420 ++kvm_stat.pf_fixed; 437 ++kvm_stat.pf_fixed;
@@ -429,7 +446,7 @@ static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
429 pt_element_t guest_pte; 446 pt_element_t guest_pte;
430 gpa_t gpa; 447 gpa_t gpa;
431 448
432 FNAME(walk_addr)(&walker, vcpu, vaddr); 449 FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
433 guest_pte = *walker.ptep; 450 guest_pte = *walker.ptep;
434 FNAME(release_walker)(&walker); 451 FNAME(release_walker)(&walker);
435 452
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 714f6a7841cd..c79df79307ed 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -502,6 +502,7 @@ static void init_vmcb(struct vmcb *vmcb)
502 (1ULL << INTERCEPT_IOIO_PROT) | 502 (1ULL << INTERCEPT_IOIO_PROT) |
503 (1ULL << INTERCEPT_MSR_PROT) | 503 (1ULL << INTERCEPT_MSR_PROT) |
504 (1ULL << INTERCEPT_TASK_SWITCH) | 504 (1ULL << INTERCEPT_TASK_SWITCH) |
505 (1ULL << INTERCEPT_SHUTDOWN) |
505 (1ULL << INTERCEPT_VMRUN) | 506 (1ULL << INTERCEPT_VMRUN) |
506 (1ULL << INTERCEPT_VMMCALL) | 507 (1ULL << INTERCEPT_VMMCALL) |
507 (1ULL << INTERCEPT_VMLOAD) | 508 (1ULL << INTERCEPT_VMLOAD) |
@@ -680,14 +681,14 @@ static void svm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
680 681
681static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 682static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
682{ 683{
683 dt->limit = vcpu->svm->vmcb->save.ldtr.limit; 684 dt->limit = vcpu->svm->vmcb->save.idtr.limit;
684 dt->base = vcpu->svm->vmcb->save.ldtr.base; 685 dt->base = vcpu->svm->vmcb->save.idtr.base;
685} 686}
686 687
687static void svm_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 688static void svm_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
688{ 689{
689 vcpu->svm->vmcb->save.ldtr.limit = dt->limit; 690 vcpu->svm->vmcb->save.idtr.limit = dt->limit;
690 vcpu->svm->vmcb->save.ldtr.base = dt->base ; 691 vcpu->svm->vmcb->save.idtr.base = dt->base ;
691} 692}
692 693
693static void svm_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt) 694static void svm_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
@@ -892,6 +893,19 @@ static int pf_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
892 return 0; 893 return 0;
893} 894}
894 895
896static int shutdown_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
897{
898 /*
899 * VMCB is undefined after a SHUTDOWN intercept
900 * so reinitialize it.
901 */
902 memset(vcpu->svm->vmcb, 0, PAGE_SIZE);
903 init_vmcb(vcpu->svm->vmcb);
904
905 kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
906 return 0;
907}
908
895static int io_get_override(struct kvm_vcpu *vcpu, 909static int io_get_override(struct kvm_vcpu *vcpu,
896 struct vmcb_seg **seg, 910 struct vmcb_seg **seg,
897 int *addr_override) 911 int *addr_override)
@@ -1149,7 +1163,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1149 case MSR_K6_STAR: 1163 case MSR_K6_STAR:
1150 vcpu->svm->vmcb->save.star = data; 1164 vcpu->svm->vmcb->save.star = data;
1151 break; 1165 break;
1152#ifdef CONFIG_X86_64_ 1166#ifdef CONFIG_X86_64
1153 case MSR_LSTAR: 1167 case MSR_LSTAR:
1154 vcpu->svm->vmcb->save.lstar = data; 1168 vcpu->svm->vmcb->save.lstar = data;
1155 break; 1169 break;
@@ -1249,6 +1263,7 @@ static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1249 [SVM_EXIT_IOIO] = io_interception, 1263 [SVM_EXIT_IOIO] = io_interception,
1250 [SVM_EXIT_MSR] = msr_interception, 1264 [SVM_EXIT_MSR] = msr_interception,
1251 [SVM_EXIT_TASK_SWITCH] = task_switch_interception, 1265 [SVM_EXIT_TASK_SWITCH] = task_switch_interception,
1266 [SVM_EXIT_SHUTDOWN] = shutdown_interception,
1252 [SVM_EXIT_VMRUN] = invalid_op_interception, 1267 [SVM_EXIT_VMRUN] = invalid_op_interception,
1253 [SVM_EXIT_VMMCALL] = invalid_op_interception, 1268 [SVM_EXIT_VMMCALL] = invalid_op_interception,
1254 [SVM_EXIT_VMLOAD] = invalid_op_interception, 1269 [SVM_EXIT_VMLOAD] = invalid_op_interception,
@@ -1407,7 +1422,8 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1407 int r; 1422 int r;
1408 1423
1409again: 1424again:
1410 do_interrupt_requests(vcpu, kvm_run); 1425 if (!vcpu->mmio_read_completed)
1426 do_interrupt_requests(vcpu, kvm_run);
1411 1427
1412 clgi(); 1428 clgi();
1413 1429
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index ce219e3f557f..27f2751c3baa 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1717,7 +1717,8 @@ again:
1717 vmcs_writel(HOST_GS_BASE, segment_base(gs_sel)); 1717 vmcs_writel(HOST_GS_BASE, segment_base(gs_sel));
1718#endif 1718#endif
1719 1719
1720 do_interrupt_requests(vcpu, kvm_run); 1720 if (!vcpu->mmio_read_completed)
1721 do_interrupt_requests(vcpu, kvm_run);
1721 1722
1722 if (vcpu->guest_debug.enabled) 1723 if (vcpu->guest_debug.enabled)
1723 kvm_guest_debug_pre(vcpu); 1724 kvm_guest_debug_pre(vcpu);
@@ -1824,7 +1825,7 @@ again:
1824#endif 1825#endif
1825 "setbe %0 \n\t" 1826 "setbe %0 \n\t"
1826 "popf \n\t" 1827 "popf \n\t"
1827 : "=g" (fail) 1828 : "=q" (fail)
1828 : "r"(vcpu->launched), "d"((unsigned long)HOST_RSP), 1829 : "r"(vcpu->launched), "d"((unsigned long)HOST_RSP),
1829 "c"(vcpu), 1830 "c"(vcpu),
1830 [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])), 1831 [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])),
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index be70795b4822..7513cddb929f 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -61,6 +61,7 @@
61#define ModRM (1<<6) 61#define ModRM (1<<6)
62/* Destination is only written; never read. */ 62/* Destination is only written; never read. */
63#define Mov (1<<7) 63#define Mov (1<<7)
64#define BitOp (1<<8)
64 65
65static u8 opcode_table[256] = { 66static u8 opcode_table[256] = {
66 /* 0x00 - 0x07 */ 67 /* 0x00 - 0x07 */
@@ -148,7 +149,7 @@ static u8 opcode_table[256] = {
148 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM 149 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM
149}; 150};
150 151
151static u8 twobyte_table[256] = { 152static u16 twobyte_table[256] = {
152 /* 0x00 - 0x0F */ 153 /* 0x00 - 0x0F */
153 0, SrcMem | ModRM | DstReg, 0, 0, 0, 0, ImplicitOps, 0, 154 0, SrcMem | ModRM | DstReg, 0, 0, 0, 0, ImplicitOps, 0,
154 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0, 155 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0,
@@ -180,16 +181,16 @@ static u8 twobyte_table[256] = {
180 /* 0x90 - 0x9F */ 181 /* 0x90 - 0x9F */
181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 182 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182 /* 0xA0 - 0xA7 */ 183 /* 0xA0 - 0xA7 */
183 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0, 184 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
184 /* 0xA8 - 0xAF */ 185 /* 0xA8 - 0xAF */
185 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0, 186 0, 0, 0, DstMem | SrcReg | ModRM | BitOp, 0, 0, 0, 0,
186 /* 0xB0 - 0xB7 */ 187 /* 0xB0 - 0xB7 */
187 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0, 188 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0,
188 DstMem | SrcReg | ModRM, 189 DstMem | SrcReg | ModRM | BitOp,
189 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov, 190 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
190 DstReg | SrcMem16 | ModRM | Mov, 191 DstReg | SrcMem16 | ModRM | Mov,
191 /* 0xB8 - 0xBF */ 192 /* 0xB8 - 0xBF */
192 0, 0, DstMem | SrcImmByte | ModRM, DstMem | SrcReg | ModRM, 193 0, 0, DstMem | SrcImmByte | ModRM, DstMem | SrcReg | ModRM | BitOp,
193 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov, 194 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
194 DstReg | SrcMem16 | ModRM | Mov, 195 DstReg | SrcMem16 | ModRM | Mov,
195 /* 0xC0 - 0xCF */ 196 /* 0xC0 - 0xCF */
@@ -469,7 +470,8 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt,
469int 470int
470x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) 471x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
471{ 472{
472 u8 b, d, sib, twobyte = 0, rex_prefix = 0; 473 unsigned d;
474 u8 b, sib, twobyte = 0, rex_prefix = 0;
473 u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0; 475 u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
474 unsigned long *override_base = NULL; 476 unsigned long *override_base = NULL;
475 unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i; 477 unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
@@ -726,46 +728,6 @@ done_prefixes:
726 ; 728 ;
727 } 729 }
728 730
729 /* Decode and fetch the destination operand: register or memory. */
730 switch (d & DstMask) {
731 case ImplicitOps:
732 /* Special instructions do their own operand decoding. */
733 goto special_insn;
734 case DstReg:
735 dst.type = OP_REG;
736 if ((d & ByteOp)
737 && !(twobyte_table && (b == 0xb6 || b == 0xb7))) {
738 dst.ptr = decode_register(modrm_reg, _regs,
739 (rex_prefix == 0));
740 dst.val = *(u8 *) dst.ptr;
741 dst.bytes = 1;
742 } else {
743 dst.ptr = decode_register(modrm_reg, _regs, 0);
744 switch ((dst.bytes = op_bytes)) {
745 case 2:
746 dst.val = *(u16 *)dst.ptr;
747 break;
748 case 4:
749 dst.val = *(u32 *)dst.ptr;
750 break;
751 case 8:
752 dst.val = *(u64 *)dst.ptr;
753 break;
754 }
755 }
756 break;
757 case DstMem:
758 dst.type = OP_MEM;
759 dst.ptr = (unsigned long *)cr2;
760 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
761 if (!(d & Mov) && /* optimisation - avoid slow emulated read */
762 ((rc = ops->read_emulated((unsigned long)dst.ptr,
763 &dst.val, dst.bytes, ctxt)) != 0))
764 goto done;
765 break;
766 }
767 dst.orig_val = dst.val;
768
769 /* 731 /*
770 * Decode and fetch the source operand: register, memory 732 * Decode and fetch the source operand: register, memory
771 * or immediate. 733 * or immediate.
@@ -838,6 +800,50 @@ done_prefixes:
838 break; 800 break;
839 } 801 }
840 802
803 /* Decode and fetch the destination operand: register or memory. */
804 switch (d & DstMask) {
805 case ImplicitOps:
806 /* Special instructions do their own operand decoding. */
807 goto special_insn;
808 case DstReg:
809 dst.type = OP_REG;
810 if ((d & ByteOp)
811 && !(twobyte_table && (b == 0xb6 || b == 0xb7))) {
812 dst.ptr = decode_register(modrm_reg, _regs,
813 (rex_prefix == 0));
814 dst.val = *(u8 *) dst.ptr;
815 dst.bytes = 1;
816 } else {
817 dst.ptr = decode_register(modrm_reg, _regs, 0);
818 switch ((dst.bytes = op_bytes)) {
819 case 2:
820 dst.val = *(u16 *)dst.ptr;
821 break;
822 case 4:
823 dst.val = *(u32 *)dst.ptr;
824 break;
825 case 8:
826 dst.val = *(u64 *)dst.ptr;
827 break;
828 }
829 }
830 break;
831 case DstMem:
832 dst.type = OP_MEM;
833 dst.ptr = (unsigned long *)cr2;
834 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
835 if (d & BitOp) {
836 dst.ptr += src.val / BITS_PER_LONG;
837 dst.bytes = sizeof(long);
838 }
839 if (!(d & Mov) && /* optimisation - avoid slow emulated read */
840 ((rc = ops->read_emulated((unsigned long)dst.ptr,
841 &dst.val, dst.bytes, ctxt)) != 0))
842 goto done;
843 break;
844 }
845 dst.orig_val = dst.val;
846
841 if (twobyte) 847 if (twobyte)
842 goto twobyte_insn; 848 goto twobyte_insn;
843 849
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 5432d07c074d..11108165e264 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -479,9 +479,12 @@ static int bitmap_read_sb(struct bitmap *bitmap)
479 int err = -EINVAL; 479 int err = -EINVAL;
480 480
481 /* page 0 is the superblock, read it... */ 481 /* page 0 is the superblock, read it... */
482 if (bitmap->file) 482 if (bitmap->file) {
483 bitmap->sb_page = read_page(bitmap->file, 0, bitmap, PAGE_SIZE); 483 loff_t isize = i_size_read(bitmap->file->f_mapping->host);
484 else { 484 int bytes = isize > PAGE_SIZE ? PAGE_SIZE : isize;
485
486 bitmap->sb_page = read_page(bitmap->file, 0, bitmap, bytes);
487 } else {
485 bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 0); 488 bitmap->sb_page = read_sb_page(bitmap->mddev, bitmap->offset, 0);
486 } 489 }
487 if (IS_ERR(bitmap->sb_page)) { 490 if (IS_ERR(bitmap->sb_page)) {
@@ -877,7 +880,8 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
877 int count; 880 int count;
878 /* unmap the old page, we're done with it */ 881 /* unmap the old page, we're done with it */
879 if (index == num_pages-1) 882 if (index == num_pages-1)
880 count = bytes - index * PAGE_SIZE; 883 count = bytes + sizeof(bitmap_super_t)
884 - index * PAGE_SIZE;
881 else 885 else
882 count = PAGE_SIZE; 886 count = PAGE_SIZE;
883 if (index == 0) { 887 if (index == 0) {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index fe7c56e10435..3668b170ea68 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1116,7 +1116,8 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
1116 if (size != get_capacity(md->disk)) 1116 if (size != get_capacity(md->disk))
1117 memset(&md->geometry, 0, sizeof(md->geometry)); 1117 memset(&md->geometry, 0, sizeof(md->geometry));
1118 1118
1119 __set_size(md, size); 1119 if (md->suspended_bdev)
1120 __set_size(md, size);
1120 if (size == 0) 1121 if (size == 0)
1121 return 0; 1122 return 0;
1122 1123
@@ -1264,6 +1265,11 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table)
1264 if (!dm_suspended(md)) 1265 if (!dm_suspended(md))
1265 goto out; 1266 goto out;
1266 1267
1268 /* without bdev, the device size cannot be changed */
1269 if (!md->suspended_bdev)
1270 if (get_capacity(md->disk) != dm_table_get_size(table))
1271 goto out;
1272
1267 __unbind(md); 1273 __unbind(md);
1268 r = __bind(md, table); 1274 r = __bind(md, table);
1269 1275
@@ -1341,11 +1347,14 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1341 /* This does not get reverted if there's an error later. */ 1347 /* This does not get reverted if there's an error later. */
1342 dm_table_presuspend_targets(map); 1348 dm_table_presuspend_targets(map);
1343 1349
1344 md->suspended_bdev = bdget_disk(md->disk, 0); 1350 /* bdget() can stall if the pending I/Os are not flushed */
1345 if (!md->suspended_bdev) { 1351 if (!noflush) {
1346 DMWARN("bdget failed in dm_suspend"); 1352 md->suspended_bdev = bdget_disk(md->disk, 0);
1347 r = -ENOMEM; 1353 if (!md->suspended_bdev) {
1348 goto flush_and_out; 1354 DMWARN("bdget failed in dm_suspend");
1355 r = -ENOMEM;
1356 goto flush_and_out;
1357 }
1349 } 1358 }
1350 1359
1351 /* 1360 /*
@@ -1473,8 +1482,10 @@ int dm_resume(struct mapped_device *md)
1473 1482
1474 unlock_fs(md); 1483 unlock_fs(md);
1475 1484
1476 bdput(md->suspended_bdev); 1485 if (md->suspended_bdev) {
1477 md->suspended_bdev = NULL; 1486 bdput(md->suspended_bdev);
1487 md->suspended_bdev = NULL;
1488 }
1478 1489
1479 clear_bit(DMF_SUSPENDED, &md->flags); 1490 clear_bit(DMF_SUSPENDED, &md->flags);
1480 1491
diff --git a/drivers/md/md.c b/drivers/md/md.c
index d1cb45f6d6a9..e8807ea5377d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1633,7 +1633,8 @@ repeat:
1633 * and 'events' is odd, we can roll back to the previous clean state */ 1633 * and 'events' is odd, we can roll back to the previous clean state */
1634 if (nospares 1634 if (nospares
1635 && (mddev->in_sync && mddev->recovery_cp == MaxSector) 1635 && (mddev->in_sync && mddev->recovery_cp == MaxSector)
1636 && (mddev->events & 1)) 1636 && (mddev->events & 1)
1637 && mddev->events != 1)
1637 mddev->events--; 1638 mddev->events--;
1638 else { 1639 else {
1639 /* otherwise we have to go forward and ... */ 1640 /* otherwise we have to go forward and ... */
@@ -3563,6 +3564,8 @@ static int get_bitmap_file(mddev_t * mddev, void __user * arg)
3563 char *ptr, *buf = NULL; 3564 char *ptr, *buf = NULL;
3564 int err = -ENOMEM; 3565 int err = -ENOMEM;
3565 3566
3567 md_allow_write(mddev);
3568
3566 file = kmalloc(sizeof(*file), GFP_KERNEL); 3569 file = kmalloc(sizeof(*file), GFP_KERNEL);
3567 if (!file) 3570 if (!file)
3568 goto out; 3571 goto out;
@@ -5031,6 +5034,33 @@ void md_write_end(mddev_t *mddev)
5031 } 5034 }
5032} 5035}
5033 5036
5037/* md_allow_write(mddev)
5038 * Calling this ensures that the array is marked 'active' so that writes
5039 * may proceed without blocking. It is important to call this before
5040 * attempting a GFP_KERNEL allocation while holding the mddev lock.
5041 * Must be called with mddev_lock held.
5042 */
5043void md_allow_write(mddev_t *mddev)
5044{
5045 if (!mddev->pers)
5046 return;
5047 if (mddev->ro)
5048 return;
5049
5050 spin_lock_irq(&mddev->write_lock);
5051 if (mddev->in_sync) {
5052 mddev->in_sync = 0;
5053 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5054 if (mddev->safemode_delay &&
5055 mddev->safemode == 0)
5056 mddev->safemode = 1;
5057 spin_unlock_irq(&mddev->write_lock);
5058 md_update_sb(mddev, 0);
5059 } else
5060 spin_unlock_irq(&mddev->write_lock);
5061}
5062EXPORT_SYMBOL_GPL(md_allow_write);
5063
5034static DECLARE_WAIT_QUEUE_HEAD(resync_wait); 5064static DECLARE_WAIT_QUEUE_HEAD(resync_wait);
5035 5065
5036#define SYNC_MARKS 10 5066#define SYNC_MARKS 10
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 164b25dca101..97ee870b265d 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1266,6 +1266,11 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
1266 sbio->bi_sector = r1_bio->sector + 1266 sbio->bi_sector = r1_bio->sector +
1267 conf->mirrors[i].rdev->data_offset; 1267 conf->mirrors[i].rdev->data_offset;
1268 sbio->bi_bdev = conf->mirrors[i].rdev->bdev; 1268 sbio->bi_bdev = conf->mirrors[i].rdev->bdev;
1269 for (j = 0; j < vcnt ; j++)
1270 memcpy(page_address(sbio->bi_io_vec[j].bv_page),
1271 page_address(pbio->bi_io_vec[j].bv_page),
1272 PAGE_SIZE);
1273
1269 } 1274 }
1270 } 1275 }
1271 } 1276 }
@@ -2099,6 +2104,8 @@ static int raid1_reshape(mddev_t *mddev)
2099 return -EINVAL; 2104 return -EINVAL;
2100 } 2105 }
2101 2106
2107 md_allow_write(mddev);
2108
2102 raid_disks = mddev->raid_disks + mddev->delta_disks; 2109 raid_disks = mddev->raid_disks + mddev->delta_disks;
2103 2110
2104 if (raid_disks < conf->raid_disks) { 2111 if (raid_disks < conf->raid_disks) {
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index be008f034ada..467c16982d02 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -405,6 +405,8 @@ static int resize_stripes(raid5_conf_t *conf, int newsize)
405 if (newsize <= conf->pool_size) 405 if (newsize <= conf->pool_size)
406 return 0; /* never bother to shrink */ 406 return 0; /* never bother to shrink */
407 407
408 md_allow_write(conf->mddev);
409
408 /* Step 1 */ 410 /* Step 1 */
409 sc = kmem_cache_create(conf->cache_name[1-conf->active_name], 411 sc = kmem_cache_create(conf->cache_name[1-conf->active_name],
410 sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), 412 sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev),
@@ -2678,7 +2680,7 @@ static int chunk_aligned_read(request_queue_t *q, struct bio * raid_bio)
2678 mdk_rdev_t *rdev; 2680 mdk_rdev_t *rdev;
2679 2681
2680 if (!in_chunk_boundary(mddev, raid_bio)) { 2682 if (!in_chunk_boundary(mddev, raid_bio)) {
2681 printk("chunk_aligned_read : non aligned\n"); 2683 PRINTK("chunk_aligned_read : non aligned\n");
2682 return 0; 2684 return 0;
2683 } 2685 }
2684 /* 2686 /*
@@ -3250,6 +3252,7 @@ raid5_store_stripe_cache_size(mddev_t *mddev, const char *page, size_t len)
3250 else 3252 else
3251 break; 3253 break;
3252 } 3254 }
3255 md_allow_write(mddev);
3253 while (new > conf->max_nr_stripes) { 3256 while (new > conf->max_nr_stripes) {
3254 if (grow_one_stripe(conf)) 3257 if (grow_one_stripe(conf))
3255 conf->max_nr_stripes++; 3258 conf->max_nr_stripes++;
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 3482e0114d43..2bd84d351a18 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleparam.h> 39#include <linux/moduleparam.h>
40#include <linux/errno.h> 40#include <linux/errno.h>
41#include <linux/freezer.h>
41#include <linux/kernel.h> 42#include <linux/kernel.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43#include <linux/mm.h> 44#include <linux/mm.h>
@@ -961,6 +962,7 @@ int cx88_audio_thread(void *data)
961 msleep_interruptible(1000); 962 msleep_interruptible(1000);
962 if (kthread_should_stop()) 963 if (kthread_should_stop())
963 break; 964 break;
965 try_to_freeze();
964 966
965 /* just monitor the audio status for now ... */ 967 /* just monitor the audio status for now ... */
966 memset(&t, 0, sizeof(t)); 968 memset(&t, 0, sizeof(t));
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
index c1a377f797d9..b6cd21e6dab9 100644
--- a/drivers/media/video/ks0127.c
+++ b/drivers/media/video/ks0127.c
@@ -712,13 +712,13 @@ static int ks0127_command(struct i2c_client *client,
712 *iarg = 0; 712 *iarg = 0;
713 status = ks0127_read(ks, KS_STAT); 713 status = ks0127_read(ks, KS_STAT);
714 if (!(status & 0x20)) /* NOVID not set */ 714 if (!(status & 0x20)) /* NOVID not set */
715 *iarg = (*iarg & DECODER_STATUS_GOOD); 715 *iarg = (*iarg | DECODER_STATUS_GOOD);
716 if ((status & 0x01)) /* CLOCK set */ 716 if ((status & 0x01)) /* CLOCK set */
717 *iarg = (*iarg & DECODER_STATUS_COLOR); 717 *iarg = (*iarg | DECODER_STATUS_COLOR);
718 if ((status & 0x08)) /* PALDET set */ 718 if ((status & 0x08)) /* PALDET set */
719 *iarg = (*iarg & DECODER_STATUS_PAL); 719 *iarg = (*iarg | DECODER_STATUS_PAL);
720 else 720 else
721 *iarg = (*iarg & DECODER_STATUS_NTSC); 721 *iarg = (*iarg | DECODER_STATUS_NTSC);
722 break; 722 break;
723 723
724 //Catch any unknown command 724 //Catch any unknown command
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 4dead84aff46..ae984bbe36b6 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -2570,6 +2570,7 @@ struct saa7134_board saa7134_boards[] = {
2570 .radio_type = UNSET, 2570 .radio_type = UNSET,
2571 .tuner_addr = ADDR_UNSET, 2571 .tuner_addr = ADDR_UNSET,
2572 .radio_addr = ADDR_UNSET, 2572 .radio_addr = ADDR_UNSET,
2573 .gpiomask = 1 << 21,
2573 .inputs = {{ 2574 .inputs = {{
2574 .name = name_tv, 2575 .name = name_tv,
2575 .vmux = 1, 2576 .vmux = 1,
@@ -2578,15 +2579,20 @@ struct saa7134_board saa7134_boards[] = {
2578 },{ 2579 },{
2579 .name = name_comp1, 2580 .name = name_comp1,
2580 .vmux = 3, 2581 .vmux = 3,
2581 .amux = LINE1, 2582 .amux = LINE2, /* unconfirmed, taken from Philips driver */
2583 },{
2584 .name = name_comp2,
2585 .vmux = 0, /* untested, Composite over S-Video */
2586 .amux = LINE2,
2582 },{ 2587 },{
2583 .name = name_svideo, 2588 .name = name_svideo,
2584 .vmux = 0, 2589 .vmux = 8,
2585 .amux = LINE1, 2590 .amux = LINE2,
2586 }}, 2591 }},
2587 .radio = { 2592 .radio = {
2588 .name = name_radio, 2593 .name = name_radio,
2589 .amux = LINE1, 2594 .amux = TV,
2595 .gpio = 0x0200000,
2590 }, 2596 },
2591 }, 2597 },
2592 [SAA7134_BOARD_CINERGY250PCI] = { 2598 [SAA7134_BOARD_CINERGY250PCI] = {
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 2624e3f7dd29..4e7c1fa668d3 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -184,7 +184,7 @@ hauppauge_tuner[] =
184 { TUNER_ABSENT, "Thompson DTT757"}, 184 { TUNER_ABSENT, "Thompson DTT757"},
185 /* 80-89 */ 185 /* 80-89 */
186 { TUNER_ABSENT, "Philips FQ1216LME MK3"}, 186 { TUNER_ABSENT, "Philips FQ1216LME MK3"},
187 { TUNER_ABSENT, "LG TAPC G701D"}, 187 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"},
188 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"}, 188 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"},
189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"}, 189 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"},
190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"}, 190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"},
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.h b/drivers/media/video/usbvideo/quickcam_messenger.h
index baab9c081b52..17ace394d981 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.h
+++ b/drivers/media/video/usbvideo/quickcam_messenger.h
@@ -35,27 +35,13 @@ struct rgb {
35}; 35};
36 36
37struct bayL0 { 37struct bayL0 {
38#ifdef __BIG_ENDIAN
39 u8 r;
40 u8 g;
41#elif __LITTLE_ENDIAN
42 u8 g; 38 u8 g;
43 u8 r; 39 u8 r;
44#else
45#error not byte order defined
46#endif
47}; 40};
48 41
49struct bayL1 { 42struct bayL1 {
50#ifdef __BIG_ENDIAN
51 u8 g;
52 u8 b;
53#elif __LITTLE_ENDIAN
54 u8 b; 43 u8 b;
55 u8 g; 44 u8 g;
56#else
57#error not byte order defined
58#endif
59}; 45};
60 46
61struct cam_size { 47struct cam_size {
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 8c7eba2a728e..7243337b771a 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -1080,7 +1080,6 @@ static ssize_t usbvision_v4l2_read(struct file *file, char *buf,
1080 int noblock = file->f_flags & O_NONBLOCK; 1080 int noblock = file->f_flags & O_NONBLOCK;
1081 unsigned long lock_flags; 1081 unsigned long lock_flags;
1082 1082
1083 int frmx = -1;
1084 int ret,i; 1083 int ret,i;
1085 struct usbvision_frame *frame; 1084 struct usbvision_frame *frame;
1086 1085
@@ -1155,7 +1154,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char *buf,
1155 frame->bytes_read = 0; 1154 frame->bytes_read = 0;
1156 1155
1157 /* Mark it as available to be used again. */ 1156 /* Mark it as available to be used again. */
1158 usbvision->frame[frmx].grabstate = FrameState_Unused; 1157 frame->grabstate = FrameState_Unused;
1159/* } */ 1158/* } */
1160 1159
1161 return count; 1160 return count;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 752c82c37f55..b87d571e0463 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -90,8 +90,15 @@ MODULE_LICENSE("GPL");
90char *v4l2_norm_to_name(v4l2_std_id id) 90char *v4l2_norm_to_name(v4l2_std_id id)
91{ 91{
92 char *name; 92 char *name;
93 u32 myid = id;
93 94
94 switch (id) { 95 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
96 64 bit comparations. So, on that architecture, with some gcc variants,
97 compilation fails. Currently, the max value is 30bit wide.
98 */
99 BUG_ON(myid != id);
100
101 switch (myid) {
95 case V4L2_STD_PAL: 102 case V4L2_STD_PAL:
96 name="PAL"; break; 103 name="PAL"; break;
97 case V4L2_STD_PAL_BG: 104 case V4L2_STD_PAL_BG:
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index f429f49901b9..6504a5866849 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -700,6 +700,7 @@ videobuf_qbuf(struct videobuf_queue *q,
700 goto done; 700 goto done;
701 } 701 }
702 if (buf->state == STATE_QUEUED || 702 if (buf->state == STATE_QUEUED ||
703 buf->state == STATE_PREPARED ||
703 buf->state == STATE_ACTIVE) { 704 buf->state == STATE_ACTIVE) {
704 dprintk(1,"qbuf: buffer is already queued or active.\n"); 705 dprintk(1,"qbuf: buffer is already queued or active.\n");
705 goto done; 706 goto done;
@@ -1229,7 +1230,7 @@ videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
1229 vaddr,vma->vm_start,vma->vm_end); 1230 vaddr,vma->vm_start,vma->vm_end);
1230 if (vaddr > vma->vm_end) 1231 if (vaddr > vma->vm_end)
1231 return NOPAGE_SIGBUS; 1232 return NOPAGE_SIGBUS;
1232 page = alloc_page(GFP_USER); 1233 page = alloc_page(GFP_USER | __GFP_DMA32);
1233 if (!page) 1234 if (!page)
1234 return NOPAGE_OOM; 1235 return NOPAGE_OOM;
1235 clear_user_page(page_address(page), vaddr, page); 1236 clear_user_page(page_address(page), vaddr, page);
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index bacb311b4f24..d4cf55666731 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -270,10 +270,15 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
270 char *p,*s,*basep; 270 char *p,*s,*basep;
271 struct page *pg; 271 struct page *pg;
272 u8 chr,r,g,b,color; 272 u8 chr,r,g,b,color;
273 unsigned long flags;
274 spinlock_t spinlock;
275
276 spin_lock_init(&spinlock);
273 277
274 /* Get first addr pointed to pixel position */ 278 /* Get first addr pointed to pixel position */
275 oldpg=get_addr_pos(pos,pages,to_addr); 279 oldpg=get_addr_pos(pos,pages,to_addr);
276 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT); 280 pg=pfn_to_page(sg_dma_address(to_addr[oldpg].sg) >> PAGE_SHIFT);
281 spin_lock_irqsave(&spinlock,flags);
277 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset; 282 basep = kmap_atomic(pg, KM_BOUNCE_READ)+to_addr[oldpg].sg->offset;
278 283
279 /* We will just duplicate the second pixel at the packet */ 284 /* We will just duplicate the second pixel at the packet */
@@ -376,6 +381,8 @@ static void gen_line(struct sg_to_addr to_addr[],int inipos,int pages,int wmax,
376 381
377end: 382end:
378 kunmap_atomic(basep, KM_BOUNCE_READ); 383 kunmap_atomic(basep, KM_BOUNCE_READ);
384 spin_unlock_irqrestore(&spinlock,flags);
385
379} 386}
380static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf) 387static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
381{ 388{
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 6e068cf1049b..b3f28a03b6a9 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -5,7 +5,7 @@
5 * For use with LSI Logic PCI chip/adapter(s) 5 * For use with LSI Logic PCI chip/adapter(s)
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
@@ -73,6 +73,7 @@
73MODULE_AUTHOR(MODULEAUTHOR); 73MODULE_AUTHOR(MODULEAUTHOR);
74MODULE_DESCRIPTION(my_NAME); 74MODULE_DESCRIPTION(my_NAME);
75MODULE_LICENSE("GPL"); 75MODULE_LICENSE("GPL");
76MODULE_VERSION(my_VERSION);
76 77
77/* 78/*
78 * cmd line parameters 79 * cmd line parameters
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index a4afad4ecab2..e316708f76bd 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
@@ -72,11 +72,11 @@
72#endif 72#endif
73 73
74#ifndef COPYRIGHT 74#ifndef COPYRIGHT
75#define COPYRIGHT "Copyright (c) 1999-2005 " MODULEAUTHOR 75#define COPYRIGHT "Copyright (c) 1999-2007 " MODULEAUTHOR
76#endif 76#endif
77 77
78#define MPT_LINUX_VERSION_COMMON "3.04.02" 78#define MPT_LINUX_VERSION_COMMON "3.04.03"
79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.02" 79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.03"
80#define WHAT_MAGIC_STRING "@" "(" "#" ")" 80#define WHAT_MAGIC_STRING "@" "(" "#" ")"
81 81
82#define show_mptmod_ver(s,ver) \ 82#define show_mptmod_ver(s,ver) \
@@ -1059,7 +1059,7 @@ extern int mpt_stm_index; /* needed by mptstm.c */
1059/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1059/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1060#endif /* } __KERNEL__ */ 1060#endif /* } __KERNEL__ */
1061 1061
1062#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__) 1062#if defined(__alpha__) || defined(__sparc_v9__) || defined(__ia64__) || defined(__x86_64__) || defined(__powerpc__)
1063#define CAST_U32_TO_PTR(x) ((void *)(u64)x) 1063#define CAST_U32_TO_PTR(x) ((void *)(u64)x)
1064#define CAST_PTR_TO_U32(x) ((u32)(u64)x) 1064#define CAST_PTR_TO_U32(x) ((u32)(u64)x)
1065#else 1065#else
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 30975ccd9947..504632da4347 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -4,7 +4,7 @@
4 * For use with LSI Logic PCI chip/adapters 4 * For use with LSI Logic PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 1999-2005 LSI Logic Corporation 7 * Copyright (c) 1999-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsil.com) 8 * (mailto:mpt_linux_developer@lsil.com)
9 * 9 *
10 */ 10 */
@@ -66,7 +66,7 @@
66#include <scsi/scsi_host.h> 66#include <scsi/scsi_host.h>
67#include <scsi/scsi_tcq.h> 67#include <scsi/scsi_tcq.h>
68 68
69#define COPYRIGHT "Copyright (c) 1999-2005 LSI Logic Corporation" 69#define COPYRIGHT "Copyright (c) 1999-2007 LSI Logic Corporation"
70#define MODULEAUTHOR "LSI Logic Corporation" 70#define MODULEAUTHOR "LSI Logic Corporation"
71#include "mptbase.h" 71#include "mptbase.h"
72#include "mptctl.h" 72#include "mptctl.h"
@@ -79,6 +79,7 @@
79MODULE_AUTHOR(MODULEAUTHOR); 79MODULE_AUTHOR(MODULEAUTHOR);
80MODULE_DESCRIPTION(my_NAME); 80MODULE_DESCRIPTION(my_NAME);
81MODULE_LICENSE("GPL"); 81MODULE_LICENSE("GPL");
82MODULE_VERSION(my_VERSION);
82 83
83/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
84 85
diff --git a/drivers/message/fusion/mptctl.h b/drivers/message/fusion/mptctl.h
index 043941882c6e..e65a1cf5eb0b 100644
--- a/drivers/message/fusion/mptctl.h
+++ b/drivers/message/fusion/mptctl.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index ca2f9107f145..c819c23b55b1 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -75,6 +75,7 @@
75MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
76MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78MODULE_VERSION(my_VERSION);
78 79
79/* Command line args */ 80/* Command line args */
80#define MPTFC_DEV_LOSS_TMO (60) 81#define MPTFC_DEV_LOSS_TMO (60)
diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index b7c4407c5e3f..2936204d8ad6 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -4,7 +4,7 @@
4 * For use with LSI Logic Fibre Channel PCI chip/adapters 4 * For use with LSI Logic Fibre Channel PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2005 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -56,9 +56,11 @@
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/fs.h> 57#include <linux/fs.h>
58 58
59#define my_VERSION MPT_LINUX_VERSION_COMMON
59#define MYNAM "mptlan" 60#define MYNAM "mptlan"
60 61
61MODULE_LICENSE("GPL"); 62MODULE_LICENSE("GPL");
63MODULE_VERSION(my_VERSION);
62 64
63/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 65/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
64/* 66/*
diff --git a/drivers/message/fusion/mptlan.h b/drivers/message/fusion/mptlan.h
index 3726ecba5707..70ab75e7c263 100644
--- a/drivers/message/fusion/mptlan.h
+++ b/drivers/message/fusion/mptlan.h
@@ -4,7 +4,7 @@
4 * For use with LSI Logic Fibre Channel PCI chip/adapters 4 * For use with LSI Logic Fibre Channel PCI chip/adapters
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2005 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 4f0c530e47b0..09e9a9d96410 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -3,9 +3,9 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * Copyright (c) 2005-2006 Dell 8 * Copyright (c) 2005-2007 Dell
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11/* 11/*
@@ -75,6 +75,7 @@
75MODULE_AUTHOR(MODULEAUTHOR); 75MODULE_AUTHOR(MODULEAUTHOR);
76MODULE_DESCRIPTION(my_NAME); 76MODULE_DESCRIPTION(my_NAME);
77MODULE_LICENSE("GPL"); 77MODULE_LICENSE("GPL");
78MODULE_VERSION(my_VERSION);
78 79
79static int mpt_pt_clear; 80static int mpt_pt_clear;
80module_param(mpt_pt_clear, int, 0); 81module_param(mpt_pt_clear, int, 0);
@@ -245,7 +246,8 @@ static void mptsas_print_device_pg0(SasDevicePage0_t *pg0)
245 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle)); 246 printk("Parent Handle=0x%X\n" ,le16_to_cpu(pg0->ParentDevHandle));
246 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle)); 247 printk("Enclosure Handle=0x%X\n", le16_to_cpu(pg0->EnclosureHandle));
247 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot)); 248 printk("Slot=0x%X\n", le16_to_cpu(pg0->Slot));
248 printk("SAS Address=0x%llX\n", le64_to_cpu(sas_address)); 249 printk("SAS Address=0x%llX\n", (unsigned long long)
250 le64_to_cpu(sas_address));
249 printk("Target ID=0x%X\n", pg0->TargetID); 251 printk("Target ID=0x%X\n", pg0->TargetID);
250 printk("Bus=0x%X\n", pg0->Bus); 252 printk("Bus=0x%X\n", pg0->Bus);
251 /* The PhyNum field specifies the PHY number of the parent 253 /* The PhyNum field specifies the PHY number of the parent
@@ -349,9 +351,9 @@ mptsas_port_delete(struct mptsas_portinfo_details * port_details)
349 phy_info = port_info->phy_info; 351 phy_info = port_info->phy_info;
350 352
351 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d " 353 dsaswideprintk((KERN_DEBUG "%s: [%p]: num_phys=%02d "
352 "bitmask=0x%016llX\n", 354 "bitmask=0x%016llX\n", __FUNCTION__, port_details,
353 __FUNCTION__, port_details, port_details->num_phys, 355 port_details->num_phys, (unsigned long long)
354 port_details->phy_bitmask)); 356 port_details->phy_bitmask));
355 357
356 for (i = 0; i < port_info->num_phys; i++, phy_info++) { 358 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
357 if(phy_info->port_details != port_details) 359 if(phy_info->port_details != port_details)
@@ -476,7 +478,7 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
476 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) { 478 for (i = 0 ; i < port_info->num_phys ; i++, phy_info++) {
477 sas_address = phy_info->attached.sas_address; 479 sas_address = phy_info->attached.sas_address;
478 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n", 480 dsaswideprintk((KERN_DEBUG "phy_id=%d sas_address=0x%018llX\n",
479 i, sas_address)); 481 i, (unsigned long long)sas_address));
480 if (!sas_address) 482 if (!sas_address)
481 continue; 483 continue;
482 port_details = phy_info->port_details; 484 port_details = phy_info->port_details;
@@ -495,8 +497,8 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
495 (1 << phy_info->phy_id); 497 (1 << phy_info->phy_id);
496 phy_info->sas_port_add_phy=1; 498 phy_info->sas_port_add_phy=1;
497 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t" 499 dsaswideprintk((KERN_DEBUG "\t\tForming port\n\t\t"
498 "phy_id=%d sas_address=0x%018llX\n", 500 "phy_id=%d sas_address=0x%018llX\n",
499 i, sas_address)); 501 i, (unsigned long long)sas_address));
500 phy_info->port_details = port_details; 502 phy_info->port_details = port_details;
501 } 503 }
502 504
@@ -512,8 +514,9 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
512 if (phy_info_cmp->port_details == port_details ) 514 if (phy_info_cmp->port_details == port_details )
513 continue; 515 continue;
514 dsaswideprintk((KERN_DEBUG 516 dsaswideprintk((KERN_DEBUG
515 "\t\tphy_id=%d sas_address=0x%018llX\n", 517 "\t\tphy_id=%d sas_address=0x%018llX\n",
516 j, phy_info_cmp->attached.sas_address)); 518 j, (unsigned long long)
519 phy_info_cmp->attached.sas_address));
517 if (phy_info_cmp->port_details) { 520 if (phy_info_cmp->port_details) {
518 port_details->rphy = 521 port_details->rphy =
519 mptsas_get_rphy(phy_info_cmp); 522 mptsas_get_rphy(phy_info_cmp);
@@ -546,11 +549,10 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
546 if (!port_details) 549 if (!port_details)
547 continue; 550 continue;
548 dsaswideprintk((KERN_DEBUG 551 dsaswideprintk((KERN_DEBUG
549 "%s: [%p]: phy_id=%02d num_phys=%02d " 552 "%s: [%p]: phy_id=%02d num_phys=%02d "
550 "bitmask=0x%016llX\n", 553 "bitmask=0x%016llX\n", __FUNCTION__,
551 __FUNCTION__, 554 port_details, i, port_details->num_phys,
552 port_details, i, port_details->num_phys, 555 (unsigned long long)port_details->phy_bitmask));
553 port_details->phy_bitmask));
554 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n", 556 dsaswideprintk((KERN_DEBUG"\t\tport = %p rphy=%p\n",
555 port_details->port, port_details->rphy)); 557 port_details->port, port_details->rphy));
556 } 558 }
@@ -2079,8 +2081,10 @@ mptsas_persist_clear_table(struct work_struct *work)
2079static void 2081static void
2080mptsas_reprobe_lun(struct scsi_device *sdev, void *data) 2082mptsas_reprobe_lun(struct scsi_device *sdev, void *data)
2081{ 2083{
2084 int rc;
2085
2082 sdev->no_uld_attach = data ? 1 : 0; 2086 sdev->no_uld_attach = data ? 1 : 0;
2083 scsi_device_reprobe(sdev); 2087 rc = scsi_device_reprobe(sdev);
2084} 2088}
2085 2089
2086static void 2090static void
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 2c72c36b8171..f0cca3ea93b2 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -76,6 +76,7 @@
76MODULE_AUTHOR(MODULEAUTHOR); 76MODULE_AUTHOR(MODULEAUTHOR);
77MODULE_DESCRIPTION(my_NAME); 77MODULE_DESCRIPTION(my_NAME);
78MODULE_LICENSE("GPL"); 78MODULE_LICENSE("GPL");
79MODULE_VERSION(my_VERSION);
79 80
80/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 81/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
81 82
@@ -701,6 +702,17 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
701 break; 702 break;
702 } 703 }
703 } 704 }
705 } else if (ioc->bus_type == FC) {
706 /*
707 * The FC IOC may kill a request for variety of
708 * reasons, some of which may be recovered by a
709 * retry, some which are unlikely to be
710 * recovered. Return DID_ERROR instead of
711 * DID_RESET to permit retry of the command,
712 * just not an infinite number of them
713 */
714 sc->result = DID_ERROR << 16;
715 break;
704 } 716 }
705 717
706 /* 718 /*
@@ -2688,7 +2700,8 @@ mptscsih_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
2688 struct scsi_device *sdev) 2700 struct scsi_device *sdev)
2689{ 2701{
2690 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n", 2702 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
2691 hd->ioc->name, vtarget->bus_id, vtarget->target_id, lun, hd)); 2703 hd->ioc->name, vtarget->bus_id, vtarget->target_id,
2704 sdev->lun, hd));
2692 2705
2693 /* Is LUN supported? If so, upper 2 bits will be 0 2706 /* Is LUN supported? If so, upper 2 bits will be 0
2694 * in first byte of inquiry data. 2707 * in first byte of inquiry data.
@@ -2770,7 +2783,7 @@ mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
2770 else { 2783 else {
2771 factor = MPT_ULTRA320; 2784 factor = MPT_ULTRA320;
2772 if (scsi_device_qas(sdev)) { 2785 if (scsi_device_qas(sdev)) {
2773 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id)); 2786 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", scsi_device_qas(sdev), id));
2774 noQas = 0; 2787 noQas = 0;
2775 } 2788 }
2776 if (sdev->type == TYPE_TAPE && 2789 if (sdev->type == TYPE_TAPE &&
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index 14a5b6c2e2bd..187c8af0890b 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -5,7 +5,7 @@
5 * LSIFC9xx/LSI409xx Fibre Channel 5 * LSIFC9xx/LSI409xx Fibre Channel
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2005 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsil.com)
10 * 10 *
11 */ 11 */
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 36641da59289..203c661d2c79 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -3,7 +3,7 @@
3 * For use with LSI Logic PCI chip/adapter(s) 3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsil.com)
8 * 8 *
9 */ 9 */
@@ -77,6 +77,7 @@
77MODULE_AUTHOR(MODULEAUTHOR); 77MODULE_AUTHOR(MODULEAUTHOR);
78MODULE_DESCRIPTION(my_NAME); 78MODULE_DESCRIPTION(my_NAME);
79MODULE_LICENSE("GPL"); 79MODULE_LICENSE("GPL");
80MODULE_VERSION(my_VERSION);
80 81
81/* Command line args */ 82/* Command line args */
82static int mpt_saf_te = MPTSCSIH_SAF_TE; 83static int mpt_saf_te = MPTSCSIH_SAF_TE;
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
index 06e7fcd19221..bfb9ff693208 100644
--- a/drivers/mmc/imxmmc.c
+++ b/drivers/mmc/imxmmc.c
@@ -351,9 +351,6 @@ static void imxmci_start_cmd(struct imxmci_host *host, struct mmc_command *cmd,
351 case MMC_RSP_R3: /* short */ 351 case MMC_RSP_R3: /* short */
352 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3; 352 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3;
353 break; 353 break;
354 case MMC_RSP_R6: /* short CRC */
355 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R6;
356 break;
357 default: 354 default:
358 break; 355 break;
359 } 356 }
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c
index 9488408308fb..d30540b27614 100644
--- a/drivers/mmc/omap.c
+++ b/drivers/mmc/omap.c
@@ -91,7 +91,6 @@
91 91
92 92
93#define DRIVER_NAME "mmci-omap" 93#define DRIVER_NAME "mmci-omap"
94#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
95 94
96/* Specifies how often in millisecs to poll for card status changes 95/* Specifies how often in millisecs to poll for card status changes
97 * when the cover switch is open */ 96 * when the cover switch is open */
@@ -204,18 +203,22 @@ mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd)
204 cmdtype = 0; 203 cmdtype = 0;
205 204
206 /* Our hardware needs to know exact type */ 205 /* Our hardware needs to know exact type */
207 switch (RSP_TYPE(mmc_resp_type(cmd))) { 206 switch (mmc_resp_type(cmd)) {
208 case RSP_TYPE(MMC_RSP_R1): 207 case MMC_RSP_NONE:
209 /* resp 1, resp 1b */ 208 break;
209 case MMC_RSP_R1:
210 case MMC_RSP_R1B:
211 /* resp 1, 1b, 6, 7 */
210 resptype = 1; 212 resptype = 1;
211 break; 213 break;
212 case RSP_TYPE(MMC_RSP_R2): 214 case MMC_RSP_R2:
213 resptype = 2; 215 resptype = 2;
214 break; 216 break;
215 case RSP_TYPE(MMC_RSP_R3): 217 case MMC_RSP_R3:
216 resptype = 3; 218 resptype = 3;
217 break; 219 break;
218 default: 220 default:
221 dev_err(mmc_dev(host->mmc), "Invalid response type: %04x\n", mmc_resp_type(cmd));
219 break; 222 break;
220 } 223 }
221 224
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index 45a9283ce498..6073d998b11f 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -171,7 +171,7 @@ static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd,
171 171
172#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE)) 172#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
173 switch (RSP_TYPE(mmc_resp_type(cmd))) { 173 switch (RSP_TYPE(mmc_resp_type(cmd))) {
174 case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6 */ 174 case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6, r7 */
175 cmdat |= CMDAT_RESP_SHORT; 175 cmdat |= CMDAT_RESP_SHORT;
176 break; 176 break;
177 case RSP_TYPE(MMC_RSP_R3): 177 case RSP_TYPE(MMC_RSP_R3):
diff --git a/drivers/mmc/tifm_sd.c b/drivers/mmc/tifm_sd.c
index f18ad998b3cb..fa4a52886b97 100644
--- a/drivers/mmc/tifm_sd.c
+++ b/drivers/mmc/tifm_sd.c
@@ -173,9 +173,6 @@ static unsigned int tifm_sd_op_flags(struct mmc_command *cmd)
173 case MMC_RSP_R3: 173 case MMC_RSP_R3:
174 rc |= TIFM_MMCSD_RSP_R3; 174 rc |= TIFM_MMCSD_RSP_R3;
175 break; 175 break;
176 case MMC_RSP_R6:
177 rc |= TIFM_MMCSD_RSP_R6;
178 break;
179 default: 176 default:
180 BUG(); 177 BUG();
181 } 178 }
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index a304b34c2632..26f75c299440 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -164,9 +164,15 @@ config MTD_CHAR
164 memory chips, and also use ioctl() to obtain information about 164 memory chips, and also use ioctl() to obtain information about
165 the device, or to erase parts of it. 165 the device, or to erase parts of it.
166 166
167config MTD_BLKDEVS
168 tristate "Common interface to block layer for MTD 'translation layers'"
169 depends on MTD && BLOCK
170 default n
171
167config MTD_BLOCK 172config MTD_BLOCK
168 tristate "Caching block device access to MTD devices" 173 tristate "Caching block device access to MTD devices"
169 depends on MTD && BLOCK 174 depends on MTD && BLOCK
175 select MTD_BLKDEVS
170 ---help--- 176 ---help---
171 Although most flash chips have an erase size too large to be useful 177 Although most flash chips have an erase size too large to be useful
172 as block devices, it is possible to use MTD devices which are based 178 as block devices, it is possible to use MTD devices which are based
@@ -189,6 +195,7 @@ config MTD_BLOCK
189config MTD_BLOCK_RO 195config MTD_BLOCK_RO
190 tristate "Readonly block device access to MTD devices" 196 tristate "Readonly block device access to MTD devices"
191 depends on MTD_BLOCK!=y && MTD && BLOCK 197 depends on MTD_BLOCK!=y && MTD && BLOCK
198 select MTD_BLKDEVS
192 help 199 help
193 This allows you to mount read-only file systems (such as cramfs) 200 This allows you to mount read-only file systems (such as cramfs)
194 from an MTD device, without the overhead (and danger) of the caching 201 from an MTD device, without the overhead (and danger) of the caching
@@ -200,6 +207,7 @@ config MTD_BLOCK_RO
200config FTL 207config FTL
201 tristate "FTL (Flash Translation Layer) support" 208 tristate "FTL (Flash Translation Layer) support"
202 depends on MTD && BLOCK 209 depends on MTD && BLOCK
210 select MTD_BLKDEVS
203 ---help--- 211 ---help---
204 This provides support for the original Flash Translation Layer which 212 This provides support for the original Flash Translation Layer which
205 is part of the PCMCIA specification. It uses a kind of pseudo- 213 is part of the PCMCIA specification. It uses a kind of pseudo-
@@ -216,6 +224,7 @@ config FTL
216config NFTL 224config NFTL
217 tristate "NFTL (NAND Flash Translation Layer) support" 225 tristate "NFTL (NAND Flash Translation Layer) support"
218 depends on MTD && BLOCK 226 depends on MTD && BLOCK
227 select MTD_BLKDEVS
219 ---help--- 228 ---help---
220 This provides support for the NAND Flash Translation Layer which is 229 This provides support for the NAND Flash Translation Layer which is
221 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo- 230 used on M-Systems' DiskOnChip devices. It uses a kind of pseudo-
@@ -239,6 +248,7 @@ config NFTL_RW
239config INFTL 248config INFTL
240 tristate "INFTL (Inverse NAND Flash Translation Layer) support" 249 tristate "INFTL (Inverse NAND Flash Translation Layer) support"
241 depends on MTD && BLOCK 250 depends on MTD && BLOCK
251 select MTD_BLKDEVS
242 ---help--- 252 ---help---
243 This provides support for the Inverse NAND Flash Translation 253 This provides support for the Inverse NAND Flash Translation
244 Layer which is used on M-Systems' newer DiskOnChip devices. It 254 Layer which is used on M-Systems' newer DiskOnChip devices. It
@@ -256,6 +266,7 @@ config INFTL
256config RFD_FTL 266config RFD_FTL
257 tristate "Resident Flash Disk (Flash Translation Layer) support" 267 tristate "Resident Flash Disk (Flash Translation Layer) support"
258 depends on MTD && BLOCK 268 depends on MTD && BLOCK
269 select MTD_BLKDEVS
259 ---help--- 270 ---help---
260 This provides support for the flash translation layer known 271 This provides support for the flash translation layer known
261 as the Resident Flash Disk (RFD), as used by the Embedded BIOS 272 as the Resident Flash Disk (RFD), as used by the Embedded BIOS
@@ -265,8 +276,8 @@ config RFD_FTL
265 276
266config SSFDC 277config SSFDC
267 tristate "NAND SSFDC (SmartMedia) read only translation layer" 278 tristate "NAND SSFDC (SmartMedia) read only translation layer"
268 depends on MTD 279 depends on MTD && BLOCK
269 default n 280 select MTD_BLKDEVS
270 help 281 help
271 This enables read only access to SmartMedia formatted NAND 282 This enables read only access to SmartMedia formatted NAND
272 flash. You can mount it with FAT file system. 283 flash. You can mount it with FAT file system.
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 1e36b9aed98b..c130e6261adf 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -15,13 +15,14 @@ obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
15 15
16# 'Users' - code which presents functionality to userspace. 16# 'Users' - code which presents functionality to userspace.
17obj-$(CONFIG_MTD_CHAR) += mtdchar.o 17obj-$(CONFIG_MTD_CHAR) += mtdchar.o
18obj-$(CONFIG_MTD_BLOCK) += mtdblock.o mtd_blkdevs.o 18obj-$(CONFIG_MTD_BLKDEVS) += mtd_blkdevs.o
19obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o mtd_blkdevs.o 19obj-$(CONFIG_MTD_BLOCK) += mtdblock.o
20obj-$(CONFIG_FTL) += ftl.o mtd_blkdevs.o 20obj-$(CONFIG_MTD_BLOCK_RO) += mtdblock_ro.o
21obj-$(CONFIG_NFTL) += nftl.o mtd_blkdevs.o 21obj-$(CONFIG_FTL) += ftl.o
22obj-$(CONFIG_INFTL) += inftl.o mtd_blkdevs.o 22obj-$(CONFIG_NFTL) += nftl.o
23obj-$(CONFIG_RFD_FTL) += rfd_ftl.o mtd_blkdevs.o 23obj-$(CONFIG_INFTL) += inftl.o
24obj-$(CONFIG_SSFDC) += ssfdc.o mtd_blkdevs.o 24obj-$(CONFIG_RFD_FTL) += rfd_ftl.o
25obj-$(CONFIG_SSFDC) += ssfdc.o
25 26
26nftl-objs := nftlcore.o nftlmount.o 27nftl-objs := nftlcore.o nftlmount.o
27inftl-objs := inftlcore.o inftlmount.o 28inftl-objs := inftlcore.o inftlmount.o
diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
index 6a45be04564b..52d51eb91c16 100644
--- a/drivers/mtd/afs.c
+++ b/drivers/mtd/afs.c
@@ -207,11 +207,10 @@ static int parse_afs_partitions(struct mtd_info *mtd,
207 if (!sz) 207 if (!sz)
208 return ret; 208 return ret;
209 209
210 parts = kmalloc(sz, GFP_KERNEL); 210 parts = kzalloc(sz, GFP_KERNEL);
211 if (!parts) 211 if (!parts)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 memset(parts, 0, sz);
215 str = (char *)(parts + idx); 214 str = (char *)(parts + idx);
216 215
217 /* 216 /*
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index 16eaca69fb5a..e7999f15d85a 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -643,13 +643,12 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
643 int reg_idx; 643 int reg_idx;
644 int offset; 644 int offset;
645 645
646 mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL); 646 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
647 if (!mtd) { 647 if (!mtd) {
648 printk(KERN_WARNING 648 printk(KERN_WARNING
649 "%s: kmalloc failed for info structure\n", map->name); 649 "%s: kmalloc failed for info structure\n", map->name);
650 return NULL; 650 return NULL;
651 } 651 }
652 memset(mtd, 0, sizeof(*mtd));
653 mtd->priv = map; 652 mtd->priv = map;
654 653
655 memset(&temp, 0, sizeof(temp)); 654 memset(&temp, 0, sizeof(temp));
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 296159ec5189..f69184a92eb2 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -337,12 +337,11 @@ struct mtd_info *cfi_cmdset_0001(struct map_info *map, int primary)
337 struct mtd_info *mtd; 337 struct mtd_info *mtd;
338 int i; 338 int i;
339 339
340 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 340 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
341 if (!mtd) { 341 if (!mtd) {
342 printk(KERN_ERR "Failed to allocate memory for MTD device\n"); 342 printk(KERN_ERR "Failed to allocate memory for MTD device\n");
343 return NULL; 343 return NULL;
344 } 344 }
345 memset(mtd, 0, sizeof(*mtd));
346 mtd->priv = map; 345 mtd->priv = map;
347 mtd->type = MTD_NORFLASH; 346 mtd->type = MTD_NORFLASH;
348 347
@@ -2224,6 +2223,8 @@ static int cfi_intelext_suspend(struct mtd_info *mtd)
2224 case FL_CFI_QUERY: 2223 case FL_CFI_QUERY:
2225 case FL_JEDEC_QUERY: 2224 case FL_JEDEC_QUERY:
2226 if (chip->oldstate == FL_READY) { 2225 if (chip->oldstate == FL_READY) {
2226 /* place the chip in a known state before suspend */
2227 map_write(map, CMD(0xFF), cfi->chips[i].start);
2227 chip->oldstate = chip->state; 2228 chip->oldstate = chip->state;
2228 chip->state = FL_PM_SUSPENDED; 2229 chip->state = FL_PM_SUSPENDED;
2229 /* No need to wake_up() on this state change - 2230 /* No need to wake_up() on this state change -
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 702ae4cd8691..e3acd398fb37 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -48,6 +48,7 @@
48#define MANUFACTURER_ATMEL 0x001F 48#define MANUFACTURER_ATMEL 0x001F
49#define MANUFACTURER_SST 0x00BF 49#define MANUFACTURER_SST 0x00BF
50#define SST49LF004B 0x0060 50#define SST49LF004B 0x0060
51#define SST49LF040B 0x0050
51#define SST49LF008A 0x005a 52#define SST49LF008A 0x005a
52#define AT49BV6416 0x00d6 53#define AT49BV6416 0x00d6
53 54
@@ -233,6 +234,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
233}; 234};
234static struct cfi_fixup jedec_fixup_table[] = { 235static struct cfi_fixup jedec_fixup_table[] = {
235 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, }, 236 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, },
237 { MANUFACTURER_SST, SST49LF040B, fixup_use_fwh_lock, NULL, },
236 { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, }, 238 { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, },
237 { 0, 0, NULL, NULL } 239 { 0, 0, NULL, NULL }
238}; 240};
@@ -255,12 +257,11 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
255 struct mtd_info *mtd; 257 struct mtd_info *mtd;
256 int i; 258 int i;
257 259
258 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 260 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
259 if (!mtd) { 261 if (!mtd) {
260 printk(KERN_WARNING "Failed to allocate memory for MTD device\n"); 262 printk(KERN_WARNING "Failed to allocate memory for MTD device\n");
261 return NULL; 263 return NULL;
262 } 264 }
263 memset(mtd, 0, sizeof(*mtd));
264 mtd->priv = map; 265 mtd->priv = map;
265 mtd->type = MTD_NORFLASH; 266 mtd->type = MTD_NORFLASH;
266 267
@@ -519,10 +520,12 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
519 if (mode == FL_WRITING) /* FIXME: Erase-suspend-program appears broken. */ 520 if (mode == FL_WRITING) /* FIXME: Erase-suspend-program appears broken. */
520 goto sleep; 521 goto sleep;
521 522
522 if (!(mode == FL_READY || mode == FL_POINT 523 if (!( mode == FL_READY
524 || mode == FL_POINT
523 || !cfip 525 || !cfip
524 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)) 526 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x2))
525 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x1)))) 527 || (mode == FL_WRITING && (cfip->EraseSuspend & 0x1)
528 )))
526 goto sleep; 529 goto sleep;
527 530
528 /* We could check to see if we're trying to access the sector 531 /* We could check to see if we're trying to access the sector
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index fae70a5db540..d56849f5f107 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -172,7 +172,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
172 int i,j; 172 int i,j;
173 unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave; 173 unsigned long devsize = (1<<cfi->cfiq->DevSize) * cfi->interleave;
174 174
175 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 175 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
176 //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips); 176 //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
177 177
178 if (!mtd) { 178 if (!mtd) {
@@ -181,7 +181,6 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
181 return NULL; 181 return NULL;
182 } 182 }
183 183
184 memset(mtd, 0, sizeof(*mtd));
185 mtd->priv = map; 184 mtd->priv = map;
186 mtd->type = MTD_NORFLASH; 185 mtd->type = MTD_NORFLASH;
187 mtd->size = devsize * cfi->numchips; 186 mtd->size = devsize * cfi->numchips;
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index cdb0f590b40c..2eb696d7b97b 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -40,7 +40,7 @@ struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp)
40 if (mtd) { 40 if (mtd) {
41 if (mtd->size > map->size) { 41 if (mtd->size > map->size) {
42 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n", 42 printk(KERN_WARNING "Reducing visibility of %ldKiB chip to %ldKiB\n",
43 (unsigned long)mtd->size >> 10, 43 (unsigned long)mtd->size >> 10,
44 (unsigned long)map->size >> 10); 44 (unsigned long)map->size >> 10);
45 mtd->size = map->size; 45 mtd->size = map->size;
46 } 46 }
@@ -113,13 +113,12 @@ static struct cfi_private *genprobe_ident_chips(struct map_info *map, struct chi
113 } 113 }
114 114
115 mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG; 115 mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG;
116 chip_map = kmalloc(mapsize, GFP_KERNEL); 116 chip_map = kzalloc(mapsize, GFP_KERNEL);
117 if (!chip_map) { 117 if (!chip_map) {
118 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name); 118 printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
119 kfree(cfi.cfiq); 119 kfree(cfi.cfiq);
120 return NULL; 120 return NULL;
121 } 121 }
122 memset (chip_map, 0, mapsize);
123 122
124 set_bit(0, chip_map); /* Mark first chip valid */ 123 set_bit(0, chip_map); /* Mark first chip valid */
125 124
diff --git a/drivers/mtd/chips/jedec.c b/drivers/mtd/chips/jedec.c
index 2c3f019197c1..14e57b2bf842 100644
--- a/drivers/mtd/chips/jedec.c
+++ b/drivers/mtd/chips/jedec.c
@@ -116,11 +116,10 @@ static struct mtd_info *jedec_probe(struct map_info *map)
116 char Part[200]; 116 char Part[200];
117 memset(&priv,0,sizeof(priv)); 117 memset(&priv,0,sizeof(priv));
118 118
119 MTD = kmalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL); 119 MTD = kzalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
120 if (!MTD) 120 if (!MTD)
121 return NULL; 121 return NULL;
122 122
123 memset(MTD, 0, sizeof(struct mtd_info) + sizeof(struct jedec_private));
124 priv = (struct jedec_private *)&MTD[1]; 123 priv = (struct jedec_private *)&MTD[1];
125 124
126 my_bank_size = map->size; 125 my_bank_size = map->size;
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 1154dac715aa..58e561e87699 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -154,6 +154,7 @@
154#define SST39SF010A 0x00B5 154#define SST39SF010A 0x00B5
155#define SST39SF020A 0x00B6 155#define SST39SF020A 0x00B6
156#define SST49LF004B 0x0060 156#define SST49LF004B 0x0060
157#define SST49LF040B 0x0050
157#define SST49LF008A 0x005a 158#define SST49LF008A 0x005a
158#define SST49LF030A 0x001C 159#define SST49LF030A 0x001C
159#define SST49LF040A 0x0051 160#define SST49LF040A 0x0051
@@ -1401,6 +1402,20 @@ static const struct amd_flash_info jedec_table[] = {
1401 } 1402 }
1402 }, { 1403 }, {
1403 .mfr_id = MANUFACTURER_SST, 1404 .mfr_id = MANUFACTURER_SST,
1405 .dev_id = SST49LF040B,
1406 .name = "SST 49LF040B",
1407 .uaddr = {
1408 [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */
1409 },
1410 .DevSize = SIZE_512KiB,
1411 .CmdSet = P_ID_AMD_STD,
1412 .NumEraseRegions= 1,
1413 .regions = {
1414 ERASEINFO(0x01000,128),
1415 }
1416 }, {
1417
1418 .mfr_id = MANUFACTURER_SST,
1404 .dev_id = SST49LF004B, 1419 .dev_id = SST49LF004B,
1405 .name = "SST 49LF004B", 1420 .name = "SST 49LF004B",
1406 .uaddr = { 1421 .uaddr = {
@@ -1874,7 +1889,7 @@ static int cfi_jedec_setup(struct cfi_private *p_cfi, int index)
1874 1889
1875 1890
1876/* 1891/*
1877 * There is a BIG problem properly ID'ing the JEDEC devic and guaranteeing 1892 * There is a BIG problem properly ID'ing the JEDEC device and guaranteeing
1878 * the mapped address, unlock addresses, and proper chip ID. This function 1893 * the mapped address, unlock addresses, and proper chip ID. This function
1879 * attempts to minimize errors. It is doubtfull that this probe will ever 1894 * attempts to minimize errors. It is doubtfull that this probe will ever
1880 * be perfect - consequently there should be some module parameters that 1895 * be perfect - consequently there should be some module parameters that
diff --git a/drivers/mtd/chips/map_absent.c b/drivers/mtd/chips/map_absent.c
index ac01a949b687..fc478c0f93f5 100644
--- a/drivers/mtd/chips/map_absent.c
+++ b/drivers/mtd/chips/map_absent.c
@@ -47,13 +47,11 @@ static struct mtd_info *map_absent_probe(struct map_info *map)
47{ 47{
48 struct mtd_info *mtd; 48 struct mtd_info *mtd;
49 49
50 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 50 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
51 if (!mtd) { 51 if (!mtd) {
52 return NULL; 52 return NULL;
53 } 53 }
54 54
55 memset(mtd, 0, sizeof(*mtd));
56
57 map->fldrv = &map_absent_chipdrv; 55 map->fldrv = &map_absent_chipdrv;
58 mtd->priv = map; 56 mtd->priv = map;
59 mtd->name = map->name; 57 mtd->name = map->name;
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 3a66680abfd0..5cb6d5263661 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -55,12 +55,10 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
55#endif 55#endif
56 /* OK. It seems to be RAM. */ 56 /* OK. It seems to be RAM. */
57 57
58 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 58 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
59 if (!mtd) 59 if (!mtd)
60 return NULL; 60 return NULL;
61 61
62 memset(mtd, 0, sizeof(*mtd));
63
64 map->fldrv = &mapram_chipdrv; 62 map->fldrv = &mapram_chipdrv;
65 mtd->priv = map; 63 mtd->priv = map;
66 mtd->name = map->name; 64 mtd->name = map->name;
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index 1b328b1378fd..cb27f855074c 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -31,12 +31,10 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
31{ 31{
32 struct mtd_info *mtd; 32 struct mtd_info *mtd;
33 33
34 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 34 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
35 if (!mtd) 35 if (!mtd)
36 return NULL; 36 return NULL;
37 37
38 memset(mtd, 0, sizeof(*mtd));
39
40 map->fldrv = &maprom_chipdrv; 38 map->fldrv = &maprom_chipdrv;
41 mtd->priv = map; 39 mtd->priv = map;
42 mtd->name = map->name; 40 mtd->name = map->name;
diff --git a/drivers/mtd/chips/sharp.c b/drivers/mtd/chips/sharp.c
index 967abbecdff9..c9cd3d21ccfa 100644
--- a/drivers/mtd/chips/sharp.c
+++ b/drivers/mtd/chips/sharp.c
@@ -112,18 +112,16 @@ static struct mtd_info *sharp_probe(struct map_info *map)
112 struct sharp_info *sharp = NULL; 112 struct sharp_info *sharp = NULL;
113 int width; 113 int width;
114 114
115 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 115 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
116 if(!mtd) 116 if(!mtd)
117 return NULL; 117 return NULL;
118 118
119 sharp = kmalloc(sizeof(*sharp), GFP_KERNEL); 119 sharp = kzalloc(sizeof(*sharp), GFP_KERNEL);
120 if(!sharp) { 120 if(!sharp) {
121 kfree(mtd); 121 kfree(mtd);
122 return NULL; 122 return NULL;
123 } 123 }
124 124
125 memset(mtd, 0, sizeof(*mtd));
126
127 width = sharp_probe_map(map,mtd); 125 width = sharp_probe_map(map,mtd);
128 if(!width){ 126 if(!width){
129 kfree(mtd); 127 kfree(mtd);
@@ -143,7 +141,6 @@ static struct mtd_info *sharp_probe(struct map_info *map)
143 mtd->writesize = 1; 141 mtd->writesize = 1;
144 mtd->name = map->name; 142 mtd->name = map->name;
145 143
146 memset(sharp, 0, sizeof(*sharp));
147 sharp->chipshift = 23; 144 sharp->chipshift = 23;
148 sharp->numchips = 1; 145 sharp->numchips = 1;
149 sharp->chips[0].start = 0; 146 sharp->chips[0].start = 0;
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index a7a7bfe33879..23fab14f1637 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -163,13 +163,12 @@ static struct mtd_partition * newpart(char *s,
163 *num_parts = this_part + 1; 163 *num_parts = this_part + 1;
164 alloc_size = *num_parts * sizeof(struct mtd_partition) + 164 alloc_size = *num_parts * sizeof(struct mtd_partition) +
165 extra_mem_size; 165 extra_mem_size;
166 parts = kmalloc(alloc_size, GFP_KERNEL); 166 parts = kzalloc(alloc_size, GFP_KERNEL);
167 if (!parts) 167 if (!parts)
168 { 168 {
169 printk(KERN_ERR ERRP "out of memory\n"); 169 printk(KERN_ERR ERRP "out of memory\n");
170 return NULL; 170 return NULL;
171 } 171 }
172 memset(parts, 0, alloc_size);
173 extra_mem = (unsigned char *)(parts + *num_parts); 172 extra_mem = (unsigned char *)(parts + *num_parts);
174 } 173 }
175 /* enter this partition (offset will be calculated later if it is zero at this point) */ 174 /* enter this partition (offset will be calculated later if it is zero at this point) */
@@ -346,7 +345,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
346 * 345 *
347 * This function needs to be visible for bootloaders. 346 * This function needs to be visible for bootloaders.
348 */ 347 */
349int mtdpart_setup(char *s) 348static int mtdpart_setup(char *s)
350{ 349{
351 cmdline = s; 350 cmdline = s;
352 return 1; 351 return 1;
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 401c6a294baa..6d917a4daa9d 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -295,10 +295,9 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
295 if (!devname) 295 if (!devname)
296 return NULL; 296 return NULL;
297 297
298 dev = kmalloc(sizeof(struct block2mtd_dev), GFP_KERNEL); 298 dev = kzalloc(sizeof(struct block2mtd_dev), GFP_KERNEL);
299 if (!dev) 299 if (!dev)
300 return NULL; 300 return NULL;
301 memset(dev, 0, sizeof(*dev));
302 301
303 /* Get a handle on the device */ 302 /* Get a handle on the device */
304 bdev = open_bdev_excl(devname, O_RDWR, NULL); 303 bdev = open_bdev_excl(devname, O_RDWR, NULL);
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 08dfb899b272..9cff119a2024 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -131,11 +131,10 @@ static int __init ms02nv_init_one(ulong addr)
131 int ret = -ENODEV; 131 int ret = -ENODEV;
132 132
133 /* The module decodes 8MiB of address space. */ 133 /* The module decodes 8MiB of address space. */
134 mod_res = kmalloc(sizeof(*mod_res), GFP_KERNEL); 134 mod_res = kzalloc(sizeof(*mod_res), GFP_KERNEL);
135 if (!mod_res) 135 if (!mod_res)
136 return -ENOMEM; 136 return -ENOMEM;
137 137
138 memset(mod_res, 0, sizeof(*mod_res));
139 mod_res->name = ms02nv_name; 138 mod_res->name = ms02nv_name;
140 mod_res->start = addr; 139 mod_res->start = addr;
141 mod_res->end = addr + MS02NV_SLOT_SIZE - 1; 140 mod_res->end = addr + MS02NV_SLOT_SIZE - 1;
@@ -153,24 +152,21 @@ static int __init ms02nv_init_one(ulong addr)
153 } 152 }
154 153
155 ret = -ENOMEM; 154 ret = -ENOMEM;
156 mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); 155 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
157 if (!mtd) 156 if (!mtd)
158 goto err_out_mod_res_rel; 157 goto err_out_mod_res_rel;
159 memset(mtd, 0, sizeof(*mtd)); 158 mp = kzalloc(sizeof(*mp), GFP_KERNEL);
160 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
161 if (!mp) 159 if (!mp)
162 goto err_out_mtd; 160 goto err_out_mtd;
163 memset(mp, 0, sizeof(*mp));
164 161
165 mtd->priv = mp; 162 mtd->priv = mp;
166 mp->resource.module = mod_res; 163 mp->resource.module = mod_res;
167 164
168 /* Firmware's diagnostic NVRAM area. */ 165 /* Firmware's diagnostic NVRAM area. */
169 diag_res = kmalloc(sizeof(*diag_res), GFP_KERNEL); 166 diag_res = kzalloc(sizeof(*diag_res), GFP_KERNEL);
170 if (!diag_res) 167 if (!diag_res)
171 goto err_out_mp; 168 goto err_out_mp;
172 169
173 memset(diag_res, 0, sizeof(*diag_res));
174 diag_res->name = ms02nv_res_diag_ram; 170 diag_res->name = ms02nv_res_diag_ram;
175 diag_res->start = addr; 171 diag_res->start = addr;
176 diag_res->end = addr + MS02NV_RAM - 1; 172 diag_res->end = addr + MS02NV_RAM - 1;
@@ -180,11 +176,10 @@ static int __init ms02nv_init_one(ulong addr)
180 mp->resource.diag_ram = diag_res; 176 mp->resource.diag_ram = diag_res;
181 177
182 /* User-available general-purpose NVRAM area. */ 178 /* User-available general-purpose NVRAM area. */
183 user_res = kmalloc(sizeof(*user_res), GFP_KERNEL); 179 user_res = kzalloc(sizeof(*user_res), GFP_KERNEL);
184 if (!user_res) 180 if (!user_res)
185 goto err_out_diag_res; 181 goto err_out_diag_res;
186 182
187 memset(user_res, 0, sizeof(*user_res));
188 user_res->name = ms02nv_res_user_ram; 183 user_res->name = ms02nv_res_user_ram;
189 user_res->start = addr + MS02NV_RAM; 184 user_res->start = addr + MS02NV_RAM;
190 user_res->end = addr + size - 1; 185 user_res->end = addr + size - 1;
@@ -194,11 +189,10 @@ static int __init ms02nv_init_one(ulong addr)
194 mp->resource.user_ram = user_res; 189 mp->resource.user_ram = user_res;
195 190
196 /* Control and status register. */ 191 /* Control and status register. */
197 csr_res = kmalloc(sizeof(*csr_res), GFP_KERNEL); 192 csr_res = kzalloc(sizeof(*csr_res), GFP_KERNEL);
198 if (!csr_res) 193 if (!csr_res)
199 goto err_out_user_res; 194 goto err_out_user_res;
200 195
201 memset(csr_res, 0, sizeof(*csr_res));
202 csr_res->name = ms02nv_res_csr; 196 csr_res->name = ms02nv_res_csr;
203 csr_res->start = addr + MS02NV_CSR; 197 csr_res->start = addr + MS02NV_CSR;
204 csr_res->end = addr + MS02NV_CSR + 3; 198 csr_res->end = addr + MS02NV_CSR + 3;
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 910e4061dfd2..a987e917f4e0 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -480,7 +480,7 @@ add_dataflash(struct spi_device *spi, char *name,
480 device->writesize = pagesize; 480 device->writesize = pagesize;
481 device->owner = THIS_MODULE; 481 device->owner = THIS_MODULE;
482 device->type = MTD_DATAFLASH; 482 device->type = MTD_DATAFLASH;
483 device->flags = MTD_CAP_NORFLASH; 483 device->flags = MTD_WRITEABLE;
484 device->erase = dataflash_erase; 484 device->erase = dataflash_erase;
485 device->read = dataflash_read; 485 device->read = dataflash_read;
486 device->write = dataflash_write; 486 device->write = dataflash_write;
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 6c7337f9ebbb..56cc1ca7ffd5 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -126,12 +126,10 @@ static int register_device(char *name, unsigned long start, unsigned long len)
126 struct phram_mtd_list *new; 126 struct phram_mtd_list *new;
127 int ret = -ENOMEM; 127 int ret = -ENOMEM;
128 128
129 new = kmalloc(sizeof(*new), GFP_KERNEL); 129 new = kzalloc(sizeof(*new), GFP_KERNEL);
130 if (!new) 130 if (!new)
131 goto out0; 131 goto out0;
132 132
133 memset(new, 0, sizeof(*new));
134
135 ret = -EIO; 133 ret = -EIO;
136 new->mtd.priv = ioremap(start, len); 134 new->mtd.priv = ioremap(start, len);
137 if (!new->mtd.priv) { 135 if (!new->mtd.priv) {
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 542a0c009006..5f49248a4856 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -168,19 +168,16 @@ static int register_device(char *name, unsigned long start, unsigned long length
168 E("slram: Cannot allocate new MTD device.\n"); 168 E("slram: Cannot allocate new MTD device.\n");
169 return(-ENOMEM); 169 return(-ENOMEM);
170 } 170 }
171 (*curmtd)->mtdinfo = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 171 (*curmtd)->mtdinfo = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
172 (*curmtd)->next = NULL; 172 (*curmtd)->next = NULL;
173 173
174 if ((*curmtd)->mtdinfo) { 174 if ((*curmtd)->mtdinfo) {
175 memset((char *)(*curmtd)->mtdinfo, 0, sizeof(struct mtd_info));
176 (*curmtd)->mtdinfo->priv = 175 (*curmtd)->mtdinfo->priv =
177 kmalloc(sizeof(slram_priv_t), GFP_KERNEL); 176 kzalloc(sizeof(slram_priv_t), GFP_KERNEL);
178 177
179 if (!(*curmtd)->mtdinfo->priv) { 178 if (!(*curmtd)->mtdinfo->priv) {
180 kfree((*curmtd)->mtdinfo); 179 kfree((*curmtd)->mtdinfo);
181 (*curmtd)->mtdinfo = NULL; 180 (*curmtd)->mtdinfo = NULL;
182 } else {
183 memset((*curmtd)->mtdinfo->priv,0,sizeof(slram_priv_t));
184 } 181 }
185 } 182 }
186 183
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index 8a878b34eca0..24235d4f1d23 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -1033,7 +1033,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1033{ 1033{
1034 partition_t *partition; 1034 partition_t *partition;
1035 1035
1036 partition = kmalloc(sizeof(partition_t), GFP_KERNEL); 1036 partition = kzalloc(sizeof(partition_t), GFP_KERNEL);
1037 1037
1038 if (!partition) { 1038 if (!partition) {
1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n", 1039 printk(KERN_WARNING "No memory to scan for FTL on %s\n",
@@ -1041,8 +1041,6 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1041 return; 1041 return;
1042 } 1042 }
1043 1043
1044 memset(partition, 0, sizeof(partition_t));
1045
1046 partition->mbd.mtd = mtd; 1044 partition->mbd.mtd = mtd;
1047 1045
1048 if ((scan_header(partition) == 0) && 1046 if ((scan_header(partition) == 0) &&
@@ -1054,7 +1052,7 @@ static void ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1054 le32_to_cpu(partition->header.FormattedSize) >> 10); 1052 le32_to_cpu(partition->header.FormattedSize) >> 10);
1055#endif 1053#endif
1056 partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9; 1054 partition->mbd.size = le32_to_cpu(partition->header.FormattedSize) >> 9;
1057 partition->mbd.blksize = SECTOR_SIZE; 1055
1058 partition->mbd.tr = tr; 1056 partition->mbd.tr = tr;
1059 partition->mbd.devnum = -1; 1057 partition->mbd.devnum = -1;
1060 if (!add_mtd_blktrans_dev((void *)partition)) 1058 if (!add_mtd_blktrans_dev((void *)partition))
@@ -1076,6 +1074,7 @@ struct mtd_blktrans_ops ftl_tr = {
1076 .name = "ftl", 1074 .name = "ftl",
1077 .major = FTL_MAJOR, 1075 .major = FTL_MAJOR,
1078 .part_bits = PART_BITS, 1076 .part_bits = PART_BITS,
1077 .blksize = SECTOR_SIZE,
1079 .readsect = ftl_readsect, 1078 .readsect = ftl_readsect,
1080 .writesect = ftl_writesect, 1079 .writesect = ftl_writesect,
1081 .getgeo = ftl_getgeo, 1080 .getgeo = ftl_getgeo,
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 4116535805f1..b0e396504e67 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -67,17 +67,16 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
67 67
68 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name); 68 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: add_mtd for %s\n", mtd->name);
69 69
70 inftl = kmalloc(sizeof(*inftl), GFP_KERNEL); 70 inftl = kzalloc(sizeof(*inftl), GFP_KERNEL);
71 71
72 if (!inftl) { 72 if (!inftl) {
73 printk(KERN_WARNING "INFTL: Out of memory for data structures\n"); 73 printk(KERN_WARNING "INFTL: Out of memory for data structures\n");
74 return; 74 return;
75 } 75 }
76 memset(inftl, 0, sizeof(*inftl));
77 76
78 inftl->mbd.mtd = mtd; 77 inftl->mbd.mtd = mtd;
79 inftl->mbd.devnum = -1; 78 inftl->mbd.devnum = -1;
80 inftl->mbd.blksize = 512; 79
81 inftl->mbd.tr = tr; 80 inftl->mbd.tr = tr;
82 81
83 if (INFTL_mount(inftl) < 0) { 82 if (INFTL_mount(inftl) < 0) {
@@ -163,10 +162,9 @@ int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
163 ops.ooblen = len; 162 ops.ooblen = len;
164 ops.oobbuf = buf; 163 ops.oobbuf = buf;
165 ops.datbuf = NULL; 164 ops.datbuf = NULL;
166 ops.len = len;
167 165
168 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 166 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
169 *retlen = ops.retlen; 167 *retlen = ops.oobretlen;
170 return res; 168 return res;
171} 169}
172 170
@@ -184,10 +182,9 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
184 ops.ooblen = len; 182 ops.ooblen = len;
185 ops.oobbuf = buf; 183 ops.oobbuf = buf;
186 ops.datbuf = NULL; 184 ops.datbuf = NULL;
187 ops.len = len;
188 185
189 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 186 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
190 *retlen = ops.retlen; 187 *retlen = ops.oobretlen;
191 return res; 188 return res;
192} 189}
193 190
@@ -945,6 +942,7 @@ static struct mtd_blktrans_ops inftl_tr = {
945 .name = "inftl", 942 .name = "inftl",
946 .major = INFTL_MAJOR, 943 .major = INFTL_MAJOR,
947 .part_bits = INFTL_PARTN_BITS, 944 .part_bits = INFTL_PARTN_BITS,
945 .blksize = 512,
948 .getgeo = inftl_getgeo, 946 .getgeo = inftl_getgeo,
949 .readsect = inftl_readblock, 947 .readsect = inftl_readblock,
950 .writesect = inftl_writeblock, 948 .writesect = inftl_writeblock,
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index d132ed571f13..f457315579db 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -60,6 +60,15 @@ config MTD_PHYSMAP_BANKWIDTH
60 Ignore this option if you use run-time physmap configuration 60 Ignore this option if you use run-time physmap configuration
61 (i.e., run-time calling physmap_configure()). 61 (i.e., run-time calling physmap_configure()).
62 62
63config MTD_PHYSMAP_OF
64 tristate "Flash device in physical memory map based on OF descirption"
65 depends on PPC_OF && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM)
66 help
67 This provides a 'mapping' driver which allows the NOR Flash and
68 ROM driver code to communicate with chips which are mapped
69 physically into the CPU's memory. The mapping description here is
70 taken from OF device tree.
71
63config MTD_SUN_UFLASH 72config MTD_SUN_UFLASH
64 tristate "Sun Microsystems userflash support" 73 tristate "Sun Microsystems userflash support"
65 depends on SPARC && MTD_CFI 74 depends on SPARC && MTD_CFI
@@ -184,6 +193,24 @@ config MTD_ICHXROM
184 193
185 BE VERY CAREFUL. 194 BE VERY CAREFUL.
186 195
196config MTD_ESB2ROM
197 tristate "BIOS flash chip on Intel ESB Controller Hub 2"
198 depends on X86 && MTD_JEDECPROBE && PCI
199 help
200 Support for treating the BIOS flash chip on ESB2 motherboards
201 as an MTD device - with this you can reprogram your BIOS.
202
203 BE VERY CAREFUL.
204
205config MTD_CK804XROM
206 tristate "BIOS flash chip on Nvidia CK804"
207 depends on X86 && MTD_JEDECPROBE
208 help
209 Support for treating the BIOS flash chip on nvidia motherboards
210 as an MTD device - with this you can reprogram your BIOS.
211
212 BE VERY CAREFUL.
213
187config MTD_SCB2_FLASH 214config MTD_SCB2_FLASH
188 tristate "BIOS flash chip on Intel SCB2 boards" 215 tristate "BIOS flash chip on Intel SCB2 boards"
189 depends on X86 && MTD_JEDECPROBE 216 depends on X86 && MTD_JEDECPROBE
@@ -355,50 +382,6 @@ config MTD_TQM834x
355 TQ Components TQM834x boards. If you have one of these boards 382 TQ Components TQM834x boards. If you have one of these boards
356 and would like to use the flash chips on it, say 'Y'. 383 and would like to use the flash chips on it, say 'Y'.
357 384
358config MTD_CSTM_MIPS_IXX
359 tristate "Flash chip mapping on ITE QED-4N-S01B, Globespan IVR or custom board"
360 depends on MIPS && MTD_CFI && MTD_JEDECPROBE && MTD_PARTITIONS
361 help
362 This provides a mapping driver for the Integrated Technology
363 Express, Inc (ITE) QED-4N-S01B eval board and the Globespan IVR
364 Reference Board. It provides the necessary addressing, length,
365 buswidth, vpp code and addition setup of the flash device for
366 these boards. In addition, this mapping driver can be used for
367 other boards via setting of the CONFIG_MTD_CSTM_MIPS_IXX_START/
368 LEN/BUSWIDTH parameters. This mapping will provide one mtd device
369 using one partition. The start address can be offset from the
370 beginning of flash and the len can be less than the total flash
371 device size to allow a window into the flash. Both CFI and JEDEC
372 probes are called.
373
374config MTD_CSTM_MIPS_IXX_START
375 hex "Physical start address of flash mapping"
376 depends on MTD_CSTM_MIPS_IXX
377 default "0x8000000"
378 help
379 This is the physical memory location that the MTD driver will
380 use for the flash chips on your particular target board.
381 Refer to the memory map which should hopefully be in the
382 documentation for your board.
383
384config MTD_CSTM_MIPS_IXX_LEN
385 hex "Physical length of flash mapping"
386 depends on MTD_CSTM_MIPS_IXX
387 default "0x4000000"
388 help
389 This is the total length that the MTD driver will use for the
390 flash chips on your particular board. Refer to the memory
391 map which should hopefully be in the documentation for your
392 board.
393
394config MTD_CSTM_MIPS_IXX_BUSWIDTH
395 int "Bus width in octets"
396 depends on MTD_CSTM_MIPS_IXX
397 default "2"
398 help
399 This is the total bus width of the mapping of the flash chips
400 on your particular board.
401
402config MTD_OCELOT 385config MTD_OCELOT
403 tristate "Momenco Ocelot boot flash device" 386 tristate "Momenco Ocelot boot flash device"
404 depends on MIPS && MOMENCO_OCELOT 387 depends on MIPS && MOMENCO_OCELOT
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 191c1928bbec..071d0bf922b6 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -12,12 +12,13 @@ obj-$(CONFIG_MTD_CDB89712) += cdb89712.o
12obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o 12obj-$(CONFIG_MTD_ARM_INTEGRATOR)+= integrator-flash.o
13obj-$(CONFIG_MTD_BAST) += bast-flash.o 13obj-$(CONFIG_MTD_BAST) += bast-flash.o
14obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o 14obj-$(CONFIG_MTD_CFI_FLAGADM) += cfi_flagadm.o
15obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o
16obj-$(CONFIG_MTD_DC21285) += dc21285.o 15obj-$(CONFIG_MTD_DC21285) += dc21285.o
17obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o 16obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o
18obj-$(CONFIG_MTD_L440GX) += l440gx.o 17obj-$(CONFIG_MTD_L440GX) += l440gx.o
19obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o 18obj-$(CONFIG_MTD_AMD76XROM) += amd76xrom.o
19obj-$(CONFIG_MTD_ESB2ROM) += esb2rom.o
20obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o 20obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o
21obj-$(CONFIG_MTD_CK804XROM) += ck804xrom.o
21obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 22obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o
22obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o 23obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o
23obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o 24obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o
@@ -25,6 +26,7 @@ obj-$(CONFIG_MTD_MBX860) += mbx860.o
25obj-$(CONFIG_MTD_CEIVA) += ceiva.o 26obj-$(CONFIG_MTD_CEIVA) += ceiva.o
26obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o 27obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o
27obj-$(CONFIG_MTD_PHYSMAP) += physmap.o 28obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
29obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o
28obj-$(CONFIG_MTD_PNC2000) += pnc2000.o 30obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
29obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o 31obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
30obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o 32obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 797caffb20b1..78b671172bb2 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/version.h>
10#include <linux/kernel.h> 11#include <linux/kernel.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <asm/io.h> 13#include <asm/io.h>
@@ -44,6 +45,23 @@ struct amd76xrom_map_info {
44 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN]; 45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
45}; 46};
46 47
48/* The 2 bits controlling the window size are often set to allow reading
49 * the BIOS, but too small to allow writing, since the lock registers are
50 * 4MiB lower in the address space than the data.
51 *
52 * This is intended to prevent flashing the bios, perhaps accidentally.
53 *
54 * This parameter allows the normal driver to over-ride the BIOS settings.
55 *
56 * The bits are 6 and 7. If both bits are set, it is a 5MiB window.
57 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
58 * 64KiB window.
59 *
60 */
61static uint win_size_bits;
62module_param(win_size_bits, uint, 0);
63MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x43 byte, normally set by BIOS.");
64
47static struct amd76xrom_window amd76xrom_window = { 65static struct amd76xrom_window amd76xrom_window = {
48 .maps = LIST_HEAD_INIT(amd76xrom_window.maps), 66 .maps = LIST_HEAD_INIT(amd76xrom_window.maps),
49}; 67};
@@ -95,6 +113,16 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
95 /* Remember the pci dev I find the window in - already have a ref */ 113 /* Remember the pci dev I find the window in - already have a ref */
96 window->pdev = pdev; 114 window->pdev = pdev;
97 115
116 /* Enable the selected rom window. This is often incorrectly
117 * set up by the BIOS, and the 4MiB offset for the lock registers
118 * requires the full 5MiB of window space.
119 *
120 * This 'write, then read' approach leaves the bits for
121 * other uses of the hardware info.
122 */
123 pci_read_config_byte(pdev, 0x43, &byte);
124 pci_write_config_byte(pdev, 0x43, byte | win_size_bits );
125
98 /* Assume the rom window is properly setup, and find it's size */ 126 /* Assume the rom window is properly setup, and find it's size */
99 pci_read_config_byte(pdev, 0x43, &byte); 127 pci_read_config_byte(pdev, 0x43, &byte);
100 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) { 128 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) {
@@ -129,12 +157,6 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
129 (unsigned long long)window->rsrc.end); 157 (unsigned long long)window->rsrc.end);
130 } 158 }
131 159
132#if 0
133
134 /* Enable the selected rom window */
135 pci_read_config_byte(pdev, 0x43, &byte);
136 pci_write_config_byte(pdev, 0x43, byte | rwindow->segen_bits);
137#endif
138 160
139 /* Enable writes through the rom window */ 161 /* Enable writes through the rom window */
140 pci_read_config_byte(pdev, 0x40, &byte); 162 pci_read_config_byte(pdev, 0x40, &byte);
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index e074bb6787d2..fc3b2672d1e2 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -131,7 +131,7 @@ static int bast_flash_probe(struct platform_device *pdev)
131 131
132 info->map.phys = res->start; 132 info->map.phys = res->start;
133 info->map.size = res->end - res->start + 1; 133 info->map.size = res->end - res->start + 1;
134 info->map.name = pdev->dev.bus_id; 134 info->map.name = pdev->dev.bus_id;
135 info->map.bankwidth = 2; 135 info->map.bankwidth = 2;
136 136
137 if (info->map.size > AREA_MAXSIZE) 137 if (info->map.size > AREA_MAXSIZE)
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
index 0402c21e291d..629e6e2641a8 100644
--- a/drivers/mtd/maps/ceiva.c
+++ b/drivers/mtd/maps/ceiva.c
@@ -122,10 +122,9 @@ static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info
122 /* 122 /*
123 * Allocate the map_info structs in one go. 123 * Allocate the map_info structs in one go.
124 */ 124 */
125 maps = kmalloc(sizeof(struct map_info) * nr, GFP_KERNEL); 125 maps = kzalloc(sizeof(struct map_info) * nr, GFP_KERNEL);
126 if (!maps) 126 if (!maps)
127 return -ENOMEM; 127 return -ENOMEM;
128 memset(maps, 0, sizeof(struct map_info) * nr);
129 /* 128 /*
130 * Claim and then map the memory regions. 129 * Claim and then map the memory regions.
131 */ 130 */
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
new file mode 100644
index 000000000000..238d42e88ec5
--- /dev/null
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -0,0 +1,356 @@
1/*
2 * ck804xrom.c
3 *
4 * Normal mappings of chips in physical memory
5 *
6 * Dave Olsen <dolsen@lnxi.com>
7 * Ryan Jackson <rjackson@lnxi.com>
8 */
9
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/version.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <asm/io.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h>
18#include <linux/mtd/cfi.h>
19#include <linux/mtd/flashchip.h>
20#include <linux/pci.h>
21#include <linux/pci_ids.h>
22#include <linux/list.h>
23
24
25#define MOD_NAME KBUILD_BASENAME
26
27#define ADDRESS_NAME_LEN 18
28
29#define ROM_PROBE_STEP_SIZE (64*1024)
30
31struct ck804xrom_window {
32 void __iomem *virt;
33 unsigned long phys;
34 unsigned long size;
35 struct list_head maps;
36 struct resource rsrc;
37 struct pci_dev *pdev;
38};
39
40struct ck804xrom_map_info {
41 struct list_head list;
42 struct map_info map;
43 struct mtd_info *mtd;
44 struct resource rsrc;
45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
46};
47
48
49/* The 2 bits controlling the window size are often set to allow reading
50 * the BIOS, but too small to allow writing, since the lock registers are
51 * 4MiB lower in the address space than the data.
52 *
53 * This is intended to prevent flashing the bios, perhaps accidentally.
54 *
55 * This parameter allows the normal driver to override the BIOS settings.
56 *
57 * The bits are 6 and 7. If both bits are set, it is a 5MiB window.
58 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
59 * 64KiB window.
60 *
61 */
62static uint win_size_bits = 0;
63module_param(win_size_bits, uint, 0);
64MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x88 byte, normally set by BIOS.");
65
66static struct ck804xrom_window ck804xrom_window = {
67 .maps = LIST_HEAD_INIT(ck804xrom_window.maps),
68};
69
70static void ck804xrom_cleanup(struct ck804xrom_window *window)
71{
72 struct ck804xrom_map_info *map, *scratch;
73 u8 byte;
74
75 if (window->pdev) {
76 /* Disable writes through the rom window */
77 pci_read_config_byte(window->pdev, 0x6d, &byte);
78 pci_write_config_byte(window->pdev, 0x6d, byte & ~1);
79 }
80
81 /* Free all of the mtd devices */
82 list_for_each_entry_safe(map, scratch, &window->maps, list) {
83 if (map->rsrc.parent)
84 release_resource(&map->rsrc);
85
86 del_mtd_device(map->mtd);
87 map_destroy(map->mtd);
88 list_del(&map->list);
89 kfree(map);
90 }
91 if (window->rsrc.parent)
92 release_resource(&window->rsrc);
93
94 if (window->virt) {
95 iounmap(window->virt);
96 window->virt = NULL;
97 window->phys = 0;
98 window->size = 0;
99 }
100 pci_dev_put(window->pdev);
101}
102
103
104static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
105 const struct pci_device_id *ent)
106{
107 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
108 u8 byte;
109 struct ck804xrom_window *window = &ck804xrom_window;
110 struct ck804xrom_map_info *map = NULL;
111 unsigned long map_top;
112
113 /* Remember the pci dev I find the window in */
114 window->pdev = pci_dev_get(pdev);
115
116 /* Enable the selected rom window. This is often incorrectly
117 * set up by the BIOS, and the 4MiB offset for the lock registers
118 * requires the full 5MiB of window space.
119 *
120 * This 'write, then read' approach leaves the bits for
121 * other uses of the hardware info.
122 */
123 pci_read_config_byte(pdev, 0x88, &byte);
124 pci_write_config_byte(pdev, 0x88, byte | win_size_bits );
125
126
127 /* Assume the rom window is properly setup, and find it's size */
128 pci_read_config_byte(pdev, 0x88, &byte);
129
130 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6)))
131 window->phys = 0xffb00000; /* 5MiB */
132 else if ((byte & (1<<7)) == (1<<7))
133 window->phys = 0xffc00000; /* 4MiB */
134 else
135 window->phys = 0xffff0000; /* 64KiB */
136
137 window->size = 0xffffffffUL - window->phys + 1UL;
138
139 /*
140 * Try to reserve the window mem region. If this fails then
141 * it is likely due to a fragment of the window being
142 * "reserved" by the BIOS. In the case that the
143 * request_mem_region() fails then once the rom size is
144 * discovered we will try to reserve the unreserved fragment.
145 */
146 window->rsrc.name = MOD_NAME;
147 window->rsrc.start = window->phys;
148 window->rsrc.end = window->phys + window->size - 1;
149 window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
150 if (request_resource(&iomem_resource, &window->rsrc)) {
151 window->rsrc.parent = NULL;
152 printk(KERN_ERR MOD_NAME
153 " %s(): Unable to register resource"
154 " 0x%.016llx-0x%.016llx - kernel bug?\n",
155 __func__,
156 (unsigned long long)window->rsrc.start,
157 (unsigned long long)window->rsrc.end);
158 }
159
160
161 /* Enable writes through the rom window */
162 pci_read_config_byte(pdev, 0x6d, &byte);
163 pci_write_config_byte(pdev, 0x6d, byte | 1);
164
165 /* FIXME handle registers 0x80 - 0x8C the bios region locks */
166
167 /* For write accesses caches are useless */
168 window->virt = ioremap_nocache(window->phys, window->size);
169 if (!window->virt) {
170 printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
171 window->phys, window->size);
172 goto out;
173 }
174
175 /* Get the first address to look for a rom chip at */
176 map_top = window->phys;
177#if 1
178 /* The probe sequence run over the firmware hub lock
179 * registers sets them to 0x7 (no access).
180 * Probe at most the last 4MiB of the address space.
181 */
182 if (map_top < 0xffc00000)
183 map_top = 0xffc00000;
184#endif
185 /* Loop through and look for rom chips. Since we don't know the
186 * starting address for each chip, probe every ROM_PROBE_STEP_SIZE
187 * bytes from the starting address of the window.
188 */
189 while((map_top - 1) < 0xffffffffUL) {
190 struct cfi_private *cfi;
191 unsigned long offset;
192 int i;
193
194 if (!map)
195 map = kmalloc(sizeof(*map), GFP_KERNEL);
196
197 if (!map) {
198 printk(KERN_ERR MOD_NAME ": kmalloc failed");
199 goto out;
200 }
201 memset(map, 0, sizeof(*map));
202 INIT_LIST_HEAD(&map->list);
203 map->map.name = map->map_name;
204 map->map.phys = map_top;
205 offset = map_top - window->phys;
206 map->map.virt = (void __iomem *)
207 (((unsigned long)(window->virt)) + offset);
208 map->map.size = 0xffffffffUL - map_top + 1UL;
209 /* Set the name of the map to the address I am trying */
210 sprintf(map->map_name, "%s @%08lx",
211 MOD_NAME, map->map.phys);
212
213 /* There is no generic VPP support */
214 for(map->map.bankwidth = 32; map->map.bankwidth;
215 map->map.bankwidth >>= 1)
216 {
217 char **probe_type;
218 /* Skip bankwidths that are not supported */
219 if (!map_bankwidth_supported(map->map.bankwidth))
220 continue;
221
222 /* Setup the map methods */
223 simple_map_init(&map->map);
224
225 /* Try all of the probe methods */
226 probe_type = rom_probe_types;
227 for(; *probe_type; probe_type++) {
228 map->mtd = do_map_probe(*probe_type, &map->map);
229 if (map->mtd)
230 goto found;
231 }
232 }
233 map_top += ROM_PROBE_STEP_SIZE;
234 continue;
235 found:
236 /* Trim the size if we are larger than the map */
237 if (map->mtd->size > map->map.size) {
238 printk(KERN_WARNING MOD_NAME
239 " rom(%u) larger than window(%lu). fixing...\n",
240 map->mtd->size, map->map.size);
241 map->mtd->size = map->map.size;
242 }
243 if (window->rsrc.parent) {
244 /*
245 * Registering the MTD device in iomem may not be possible
246 * if there is a BIOS "reserved" and BUSY range. If this
247 * fails then continue anyway.
248 */
249 map->rsrc.name = map->map_name;
250 map->rsrc.start = map->map.phys;
251 map->rsrc.end = map->map.phys + map->mtd->size - 1;
252 map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
253 if (request_resource(&window->rsrc, &map->rsrc)) {
254 printk(KERN_ERR MOD_NAME
255 ": cannot reserve MTD resource\n");
256 map->rsrc.parent = NULL;
257 }
258 }
259
260 /* Make the whole region visible in the map */
261 map->map.virt = window->virt;
262 map->map.phys = window->phys;
263 cfi = map->map.fldrv_priv;
264 for(i = 0; i < cfi->numchips; i++)
265 cfi->chips[i].start += offset;
266
267 /* Now that the mtd devices is complete claim and export it */
268 map->mtd->owner = THIS_MODULE;
269 if (add_mtd_device(map->mtd)) {
270 map_destroy(map->mtd);
271 map->mtd = NULL;
272 goto out;
273 }
274
275
276 /* Calculate the new value of map_top */
277 map_top += map->mtd->size;
278
279 /* File away the map structure */
280 list_add(&map->list, &window->maps);
281 map = NULL;
282 }
283
284 out:
285 /* Free any left over map structures */
286 if (map)
287 kfree(map);
288
289 /* See if I have any map structures */
290 if (list_empty(&window->maps)) {
291 ck804xrom_cleanup(window);
292 return -ENODEV;
293 }
294 return 0;
295}
296
297
298static void __devexit ck804xrom_remove_one (struct pci_dev *pdev)
299{
300 struct ck804xrom_window *window = &ck804xrom_window;
301
302 ck804xrom_cleanup(window);
303}
304
305static struct pci_device_id ck804xrom_pci_tbl[] = {
306 { PCI_VENDOR_ID_NVIDIA, 0x0051,
307 PCI_ANY_ID, PCI_ANY_ID, }, /* nvidia ck804 */
308 { 0, }
309};
310
311MODULE_DEVICE_TABLE(pci, ck804xrom_pci_tbl);
312
313#if 0
314static struct pci_driver ck804xrom_driver = {
315 .name = MOD_NAME,
316 .id_table = ck804xrom_pci_tbl,
317 .probe = ck804xrom_init_one,
318 .remove = ck804xrom_remove_one,
319};
320#endif
321
322static int __init init_ck804xrom(void)
323{
324 struct pci_dev *pdev;
325 struct pci_device_id *id;
326 int retVal;
327 pdev = NULL;
328
329 for(id = ck804xrom_pci_tbl; id->vendor; id++) {
330 pdev = pci_find_device(id->vendor, id->device, NULL);
331 if (pdev)
332 break;
333 }
334 if (pdev) {
335 retVal = ck804xrom_init_one(pdev, &ck804xrom_pci_tbl[0]);
336 pci_dev_put(pdev);
337 return retVal;
338 }
339 return -ENXIO;
340#if 0
341 return pci_module_init(&ck804xrom_driver);
342#endif
343}
344
345static void __exit cleanup_ck804xrom(void)
346{
347 ck804xrom_remove_one(ck804xrom_window.pdev);
348}
349
350module_init(init_ck804xrom);
351module_exit(cleanup_ck804xrom);
352
353MODULE_LICENSE("GPL");
354MODULE_AUTHOR("Eric Biederman <ebiederman@lnxi.com>, Dave Olsen <dolsen@lnxi.com>");
355MODULE_DESCRIPTION("MTD map driver for BIOS chips on the Nvidia ck804 southbridge");
356
diff --git a/drivers/mtd/maps/cstm_mips_ixx.c b/drivers/mtd/maps/cstm_mips_ixx.c
deleted file mode 100644
index df2c38ef105a..000000000000
--- a/drivers/mtd/maps/cstm_mips_ixx.c
+++ /dev/null
@@ -1,283 +0,0 @@
1/*
2 * $Id: cstm_mips_ixx.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 *
4 * Mapping of a custom board with both AMD CFI and JEDEC flash in partitions.
5 * Config with both CFI and JEDEC device support.
6 *
7 * Basically physmap.c with the addition of partitions and
8 * an array of mapping info to accomodate more than one flash type per board.
9 *
10 * Copyright 2000 MontaVista Software Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/module.h>
34#include <linux/types.h>
35#include <linux/kernel.h>
36#include <linux/init.h>
37#include <asm/io.h>
38#include <linux/mtd/mtd.h>
39#include <linux/mtd/map.h>
40#include <linux/mtd/partitions.h>
41#include <linux/delay.h>
42
43#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
44#define CC_GCR 0xB4013818
45#define CC_GPBCR 0xB401380A
46#define CC_GPBDR 0xB4013808
47#define CC_M68K_DEVICE 1
48#define CC_M68K_FUNCTION 6
49#define CC_CONFADDR 0xB8004000
50#define CC_CONFDATA 0xB8004004
51#define CC_FC_FCR 0xB8002004
52#define CC_FC_DCR 0xB8002008
53#define CC_GPACR 0xB4013802
54#define CC_GPAICR 0xB4013804
55#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
56
57#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
58void cstm_mips_ixx_set_vpp(struct map_info *map,int vpp)
59{
60 static DEFINE_SPINLOCK(vpp_lock);
61 static int vpp_count = 0;
62 unsigned long flags;
63
64 spin_lock_irqsave(&vpp_lock, flags);
65
66 if (vpp) {
67 if (!vpp_count++) {
68 __u16 data;
69 __u8 data1;
70 static u8 first = 1;
71
72 // Set GPIO port B pin3 to high
73 data = *(__u16 *)(CC_GPBCR);
74 data = (data & 0xff0f) | 0x0040;
75 *(__u16 *)CC_GPBCR = data;
76 *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) | 0x08;
77 if (first) {
78 first = 0;
79 /* need to have this delay for first
80 enabling vpp after powerup */
81 udelay(40);
82 }
83 }
84 } else {
85 if (!--vpp_count) {
86 __u16 data;
87
88 // Set GPIO port B pin3 to high
89 data = *(__u16 *)(CC_GPBCR);
90 data = (data & 0xff3f) | 0x0040;
91 *(__u16 *)CC_GPBCR = data;
92 *(__u8 *)CC_GPBDR = (*(__u8*)CC_GPBDR) & 0xf7;
93 }
94 }
95 spin_unlock_irqrestore(&vpp_lock, flags);
96}
97#endif
98
99/* board and partition description */
100
101#define MAX_PHYSMAP_PARTITIONS 8
102struct cstm_mips_ixx_info {
103 char *name;
104 unsigned long window_addr;
105 unsigned long window_size;
106 int bankwidth;
107 int num_partitions;
108};
109
110#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
111#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
112const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
113{
114 { // 28F128J3A in 2x16 configuration
115 "big flash", // name
116 0x08000000, // window_addr
117 0x02000000, // window_size
118 4, // bankwidth
119 1, // num_partitions
120 }
121
122};
123static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
124{ // 28F128J3A in 2x16 configuration
125 {
126 .name = "main partition ",
127 .size = 0x02000000, // 128 x 2 x 128k byte sectors
128 .offset = 0,
129 },
130},
131};
132#else /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
133#define PHYSMAP_NUMBER 1 // number of board desc structs needed, one per contiguous flash type
134const struct cstm_mips_ixx_info cstm_mips_ixx_board_desc[PHYSMAP_NUMBER] =
135{
136 {
137 "MTD flash", // name
138 CONFIG_MTD_CSTM_MIPS_IXX_START, // window_addr
139 CONFIG_MTD_CSTM_MIPS_IXX_LEN, // window_size
140 CONFIG_MTD_CSTM_MIPS_IXX_BUSWIDTH, // bankwidth
141 1, // num_partitions
142 },
143
144};
145static struct mtd_partition cstm_mips_ixx_partitions[PHYSMAP_NUMBER][MAX_PHYSMAP_PARTITIONS] = {
146{
147 {
148 .name = "main partition",
149 .size = CONFIG_MTD_CSTM_MIPS_IXX_LEN,
150 .offset = 0,
151 },
152},
153};
154#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
155
156struct map_info cstm_mips_ixx_map[PHYSMAP_NUMBER];
157
158int __init init_cstm_mips_ixx(void)
159{
160 int i;
161 int jedec;
162 struct mtd_info *mymtd;
163 struct mtd_partition *parts;
164
165 /* Initialize mapping */
166 for (i=0;i<PHYSMAP_NUMBER;i++) {
167 printk(KERN_NOTICE "cstm_mips_ixx flash device: 0x%lx at 0x%lx\n",
168 cstm_mips_ixx_board_desc[i].window_size, cstm_mips_ixx_board_desc[i].window_addr);
169
170
171 cstm_mips_ixx_map[i].phys = cstm_mips_ixx_board_desc[i].window_addr;
172 cstm_mips_ixx_map[i].virt = ioremap(cstm_mips_ixx_board_desc[i].window_addr, cstm_mips_ixx_board_desc[i].window_size);
173 if (!cstm_mips_ixx_map[i].virt) {
174 int j = 0;
175 printk(KERN_WARNING "Failed to ioremap\n");
176 for (j = 0; j < i; j++) {
177 if (cstm_mips_ixx_map[j].virt) {
178 iounmap(cstm_mips_ixx_map[j].virt);
179 cstm_mips_ixx_map[j].virt = NULL;
180 }
181 }
182 return -EIO;
183 }
184 cstm_mips_ixx_map[i].name = cstm_mips_ixx_board_desc[i].name;
185 cstm_mips_ixx_map[i].size = cstm_mips_ixx_board_desc[i].window_size;
186 cstm_mips_ixx_map[i].bankwidth = cstm_mips_ixx_board_desc[i].bankwidth;
187#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
188 cstm_mips_ixx_map[i].set_vpp = cstm_mips_ixx_set_vpp;
189#endif
190 simple_map_init(&cstm_mips_ixx_map[i]);
191 //printk(KERN_NOTICE "cstm_mips_ixx: ioremap is %x\n",(unsigned int)(cstm_mips_ixx_map[i].virt));
192 }
193
194#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
195 setup_ITE_IVR_flash();
196#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
197
198 for (i=0;i<PHYSMAP_NUMBER;i++) {
199 parts = &cstm_mips_ixx_partitions[i][0];
200 jedec = 0;
201 mymtd = (struct mtd_info *)do_map_probe("cfi_probe", &cstm_mips_ixx_map[i]);
202 //printk(KERN_NOTICE "phymap %d cfi_probe: mymtd is %x\n",i,(unsigned int)mymtd);
203 if (!mymtd) {
204 jedec = 1;
205 mymtd = (struct mtd_info *)do_map_probe("jedec", &cstm_mips_ixx_map[i]);
206 printk(KERN_NOTICE "cstm_mips_ixx %d jedec: mymtd is %x\n",i,(unsigned int)mymtd);
207 }
208 if (mymtd) {
209 mymtd->owner = THIS_MODULE;
210
211 cstm_mips_ixx_map[i].map_priv_2 = (unsigned long)mymtd;
212 add_mtd_partitions(mymtd, parts, cstm_mips_ixx_board_desc[i].num_partitions);
213 }
214 else {
215 for (i = 0; i < PHYSMAP_NUMBER; i++) {
216 if (cstm_mips_ixx_map[i].virt) {
217 iounmap(cstm_mips_ixx_map[i].virt);
218 cstm_mips_ixx_map[i].virt = NULL;
219 }
220 }
221 return -ENXIO;
222 }
223 }
224 return 0;
225}
226
227static void __exit cleanup_cstm_mips_ixx(void)
228{
229 int i;
230 struct mtd_info *mymtd;
231
232 for (i=0;i<PHYSMAP_NUMBER;i++) {
233 mymtd = (struct mtd_info *)cstm_mips_ixx_map[i].map_priv_2;
234 if (mymtd) {
235 del_mtd_partitions(mymtd);
236 map_destroy(mymtd);
237 }
238 if (cstm_mips_ixx_map[i].virt) {
239 iounmap((void *)cstm_mips_ixx_map[i].virt);
240 cstm_mips_ixx_map[i].virt = 0;
241 }
242 }
243}
244#if defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR)
245void PCISetULongByOffset(__u32 DevNumber, __u32 FuncNumber, __u32 Offset, __u32 data)
246{
247 __u32 offset;
248
249 offset = ( unsigned long )( 0x80000000 | ( DevNumber << 11 ) + ( FuncNumber << 8 ) + Offset) ;
250
251 *(__u32 *)CC_CONFADDR = offset;
252 *(__u32 *)CC_CONFDATA = data;
253}
254void setup_ITE_IVR_flash()
255{
256 __u32 size, base;
257
258 size = 0x0e000000; // 32MiB
259 base = (0x08000000) >> 8 >>1; // Bug: we must shift one more bit
260
261 /* need to set ITE flash to 32 bits instead of default 8 */
262#ifdef CONFIG_MIPS_IVR
263 *(__u32 *)CC_FC_FCR = 0x55;
264 *(__u32 *)CC_GPACR = 0xfffc;
265#else
266 *(__u32 *)CC_FC_FCR = 0x77;
267#endif
268 /* turn bursting off */
269 *(__u32 *)CC_FC_DCR = 0x0;
270
271 /* setup for one chip 4 byte PCI access */
272 PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x60, size | base);
273 PCISetULongByOffset(CC_M68K_DEVICE, CC_M68K_FUNCTION, 0x64, 0x02);
274}
275#endif /* defined(CONFIG_MIPS_ITE8172) || defined(CONFIG_MIPS_IVR) */
276
277module_init(init_cstm_mips_ixx);
278module_exit(cleanup_cstm_mips_ixx);
279
280
281MODULE_LICENSE("GPL");
282MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>");
283MODULE_DESCRIPTION("MTD map driver for ITE 8172G and Globespan IVR boards");
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
new file mode 100644
index 000000000000..a9d808a617c9
--- /dev/null
+++ b/drivers/mtd/maps/esb2rom.c
@@ -0,0 +1,450 @@
1/*
2 * esb2rom.c
3 *
4 * Normal mappings of flash chips in physical memory
5 * through the Intel ESB2 Southbridge.
6 *
7 * This was derived from ichxrom.c in May 2006 by
8 * Lew Glendenning <lglendenning@lnxi.com>
9 *
10 * Eric Biederman, of course, was a major help in this effort.
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/version.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <asm/io.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/cfi.h>
22#include <linux/mtd/flashchip.h>
23#include <linux/pci.h>
24#include <linux/pci_ids.h>
25#include <linux/list.h>
26
27#define MOD_NAME KBUILD_BASENAME
28
29#define ADDRESS_NAME_LEN 18
30
31#define ROM_PROBE_STEP_SIZE (64*1024) /* 64KiB */
32
33#define BIOS_CNTL 0xDC
34#define BIOS_LOCK_ENABLE 0x02
35#define BIOS_WRITE_ENABLE 0x01
36
37/* This became a 16-bit register, and EN2 has disappeared */
38#define FWH_DEC_EN1 0xD8
39#define FWH_F8_EN 0x8000
40#define FWH_F0_EN 0x4000
41#define FWH_E8_EN 0x2000
42#define FWH_E0_EN 0x1000
43#define FWH_D8_EN 0x0800
44#define FWH_D0_EN 0x0400
45#define FWH_C8_EN 0x0200
46#define FWH_C0_EN 0x0100
47#define FWH_LEGACY_F_EN 0x0080
48#define FWH_LEGACY_E_EN 0x0040
49/* reserved 0x0020 and 0x0010 */
50#define FWH_70_EN 0x0008
51#define FWH_60_EN 0x0004
52#define FWH_50_EN 0x0002
53#define FWH_40_EN 0x0001
54
55/* these are 32-bit values */
56#define FWH_SEL1 0xD0
57#define FWH_SEL2 0xD4
58
59#define FWH_8MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
60 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
61 FWH_70_EN | FWH_60_EN | FWH_50_EN | FWH_40_EN)
62
63#define FWH_7MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
64 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
65 FWH_70_EN | FWH_60_EN | FWH_50_EN)
66
67#define FWH_6MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
68 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
69 FWH_70_EN | FWH_60_EN)
70
71#define FWH_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
72 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN | \
73 FWH_70_EN)
74
75#define FWH_4MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
76 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN | FWH_C0_EN)
77
78#define FWH_3_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
79 FWH_D8_EN | FWH_D0_EN | FWH_C8_EN)
80
81#define FWH_3MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
82 FWH_D8_EN | FWH_D0_EN)
83
84#define FWH_2_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN | \
85 FWH_D8_EN)
86
87#define FWH_2MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN | FWH_E0_EN)
88
89#define FWH_1_5MiB (FWH_F8_EN | FWH_F0_EN | FWH_E8_EN)
90
91#define FWH_1MiB (FWH_F8_EN | FWH_F0_EN)
92
93#define FWH_0_5MiB (FWH_F8_EN)
94
95
96struct esb2rom_window {
97 void __iomem* virt;
98 unsigned long phys;
99 unsigned long size;
100 struct list_head maps;
101 struct resource rsrc;
102 struct pci_dev *pdev;
103};
104
105struct esb2rom_map_info {
106 struct list_head list;
107 struct map_info map;
108 struct mtd_info *mtd;
109 struct resource rsrc;
110 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
111};
112
113static struct esb2rom_window esb2rom_window = {
114 .maps = LIST_HEAD_INIT(esb2rom_window.maps),
115};
116
117static void esb2rom_cleanup(struct esb2rom_window *window)
118{
119 struct esb2rom_map_info *map, *scratch;
120 u8 byte;
121
122 /* Disable writes through the rom window */
123 pci_read_config_byte(window->pdev, BIOS_CNTL, &byte);
124 pci_write_config_byte(window->pdev, BIOS_CNTL,
125 byte & ~BIOS_WRITE_ENABLE);
126
127 /* Free all of the mtd devices */
128 list_for_each_entry_safe(map, scratch, &window->maps, list) {
129 if (map->rsrc.parent)
130 release_resource(&map->rsrc);
131 del_mtd_device(map->mtd);
132 map_destroy(map->mtd);
133 list_del(&map->list);
134 kfree(map);
135 }
136 if (window->rsrc.parent)
137 release_resource(&window->rsrc);
138 if (window->virt) {
139 iounmap(window->virt);
140 window->virt = NULL;
141 window->phys = 0;
142 window->size = 0;
143 }
144 pci_dev_put(window->pdev);
145}
146
147static int __devinit esb2rom_init_one(struct pci_dev *pdev,
148 const struct pci_device_id *ent)
149{
150 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
151 struct esb2rom_window *window = &esb2rom_window;
152 struct esb2rom_map_info *map = NULL;
153 unsigned long map_top;
154 u8 byte;
155 u16 word;
156
157 /* For now I just handle the ecb2 and I assume there
158 * are not a lot of resources up at the top of the address
159 * space. It is possible to handle other devices in the
160 * top 16MiB but it is very painful. Also since
161 * you can only really attach a FWH to an ICHX there
162 * a number of simplifications you can make.
163 *
164 * Also you can page firmware hubs if an 8MiB window isn't enough
165 * but don't currently handle that case either.
166 */
167 window->pdev = pci_dev_get(pdev);
168
169 /* RLG: experiment 2. Force the window registers to the widest values */
170
171/*
172 pci_read_config_word(pdev, FWH_DEC_EN1, &word);
173 printk(KERN_DEBUG "Original FWH_DEC_EN1 : %x\n", word);
174 pci_write_config_byte(pdev, FWH_DEC_EN1, 0xff);
175 pci_read_config_byte(pdev, FWH_DEC_EN1, &byte);
176 printk(KERN_DEBUG "New FWH_DEC_EN1 : %x\n", byte);
177
178 pci_read_config_byte(pdev, FWH_DEC_EN2, &byte);
179 printk(KERN_DEBUG "Original FWH_DEC_EN2 : %x\n", byte);
180 pci_write_config_byte(pdev, FWH_DEC_EN2, 0x0f);
181 pci_read_config_byte(pdev, FWH_DEC_EN2, &byte);
182 printk(KERN_DEBUG "New FWH_DEC_EN2 : %x\n", byte);
183*/
184
185 /* Find a region continuous to the end of the ROM window */
186 window->phys = 0;
187 pci_read_config_word(pdev, FWH_DEC_EN1, &word);
188 printk(KERN_DEBUG "pci_read_config_byte : %x\n", word);
189
190 if ((word & FWH_8MiB) == FWH_8MiB)
191 window->phys = 0xff400000;
192 else if ((word & FWH_7MiB) == FWH_7MiB)
193 window->phys = 0xff500000;
194 else if ((word & FWH_6MiB) == FWH_6MiB)
195 window->phys = 0xff600000;
196 else if ((word & FWH_5MiB) == FWH_5MiB)
197 window->phys = 0xFF700000;
198 else if ((word & FWH_4MiB) == FWH_4MiB)
199 window->phys = 0xffc00000;
200 else if ((word & FWH_3_5MiB) == FWH_3_5MiB)
201 window->phys = 0xffc80000;
202 else if ((word & FWH_3MiB) == FWH_3MiB)
203 window->phys = 0xffd00000;
204 else if ((word & FWH_2_5MiB) == FWH_2_5MiB)
205 window->phys = 0xffd80000;
206 else if ((word & FWH_2MiB) == FWH_2MiB)
207 window->phys = 0xffe00000;
208 else if ((word & FWH_1_5MiB) == FWH_1_5MiB)
209 window->phys = 0xffe80000;
210 else if ((word & FWH_1MiB) == FWH_1MiB)
211 window->phys = 0xfff00000;
212 else if ((word & FWH_0_5MiB) == FWH_0_5MiB)
213 window->phys = 0xfff80000;
214
215 /* reserved 0x0020 and 0x0010 */
216 window->phys -= 0x400000UL;
217 window->size = (0xffffffffUL - window->phys) + 1UL;
218
219 /* Enable writes through the rom window */
220 pci_read_config_byte(pdev, BIOS_CNTL, &byte);
221 if (!(byte & BIOS_WRITE_ENABLE) && (byte & (BIOS_LOCK_ENABLE))) {
222 /* The BIOS will generate an error if I enable
223 * this device, so don't even try.
224 */
225 printk(KERN_ERR MOD_NAME ": firmware access control, I can't enable writes\n");
226 goto out;
227 }
228 pci_write_config_byte(pdev, BIOS_CNTL, byte | BIOS_WRITE_ENABLE);
229
230 /*
231 * Try to reserve the window mem region. If this fails then
232 * it is likely due to the window being "reseved" by the BIOS.
233 */
234 window->rsrc.name = MOD_NAME;
235 window->rsrc.start = window->phys;
236 window->rsrc.end = window->phys + window->size - 1;
237 window->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
238 if (request_resource(&iomem_resource, &window->rsrc)) {
239 window->rsrc.parent = NULL;
240 printk(KERN_DEBUG MOD_NAME
241 ": %s(): Unable to register resource"
242 " 0x%.08llx-0x%.08llx - kernel bug?\n",
243 __func__,
244 (unsigned long long)window->rsrc.start,
245 (unsigned long long)window->rsrc.end);
246 }
247
248 /* Map the firmware hub into my address space. */
249 window->virt = ioremap_nocache(window->phys, window->size);
250 if (!window->virt) {
251 printk(KERN_ERR MOD_NAME ": ioremap(%08lx, %08lx) failed\n",
252 window->phys, window->size);
253 goto out;
254 }
255
256 /* Get the first address to look for an rom chip at */
257 map_top = window->phys;
258 if ((window->phys & 0x3fffff) != 0) {
259 /* if not aligned on 4MiB, look 4MiB lower in address space */
260 map_top = window->phys + 0x400000;
261 }
262#if 1
263 /* The probe sequence run over the firmware hub lock
264 * registers sets them to 0x7 (no access).
265 * (Insane hardware design, but most copied Intel's.)
266 * ==> Probe at most the last 4M of the address space.
267 */
268 if (map_top < 0xffc00000)
269 map_top = 0xffc00000;
270#endif
271 /* Loop through and look for rom chips */
272 while ((map_top - 1) < 0xffffffffUL) {
273 struct cfi_private *cfi;
274 unsigned long offset;
275 int i;
276
277 if (!map)
278 map = kmalloc(sizeof(*map), GFP_KERNEL);
279 if (!map) {
280 printk(KERN_ERR MOD_NAME ": kmalloc failed");
281 goto out;
282 }
283 memset(map, 0, sizeof(*map));
284 INIT_LIST_HEAD(&map->list);
285 map->map.name = map->map_name;
286 map->map.phys = map_top;
287 offset = map_top - window->phys;
288 map->map.virt = (void __iomem *)
289 (((unsigned long)(window->virt)) + offset);
290 map->map.size = 0xffffffffUL - map_top + 1UL;
291 /* Set the name of the map to the address I am trying */
292 sprintf(map->map_name, "%s @%08lx",
293 MOD_NAME, map->map.phys);
294
295 /* Firmware hubs only use vpp when being programmed
296 * in a factory setting. So in-place programming
297 * needs to use a different method.
298 */
299 for(map->map.bankwidth = 32; map->map.bankwidth;
300 map->map.bankwidth >>= 1) {
301 char **probe_type;
302 /* Skip bankwidths that are not supported */
303 if (!map_bankwidth_supported(map->map.bankwidth))
304 continue;
305
306 /* Setup the map methods */
307 simple_map_init(&map->map);
308
309 /* Try all of the probe methods */
310 probe_type = rom_probe_types;
311 for(; *probe_type; probe_type++) {
312 map->mtd = do_map_probe(*probe_type, &map->map);
313 if (map->mtd)
314 goto found;
315 }
316 }
317 map_top += ROM_PROBE_STEP_SIZE;
318 continue;
319 found:
320 /* Trim the size if we are larger than the map */
321 if (map->mtd->size > map->map.size) {
322 printk(KERN_WARNING MOD_NAME
323 " rom(%u) larger than window(%lu). fixing...\n",
324 map->mtd->size, map->map.size);
325 map->mtd->size = map->map.size;
326 }
327 if (window->rsrc.parent) {
328 /*
329 * Registering the MTD device in iomem may not be possible
330 * if there is a BIOS "reserved" and BUSY range. If this
331 * fails then continue anyway.
332 */
333 map->rsrc.name = map->map_name;
334 map->rsrc.start = map->map.phys;
335 map->rsrc.end = map->map.phys + map->mtd->size - 1;
336 map->rsrc.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
337 if (request_resource(&window->rsrc, &map->rsrc)) {
338 printk(KERN_ERR MOD_NAME
339 ": cannot reserve MTD resource\n");
340 map->rsrc.parent = NULL;
341 }
342 }
343
344 /* Make the whole region visible in the map */
345 map->map.virt = window->virt;
346 map->map.phys = window->phys;
347 cfi = map->map.fldrv_priv;
348 for(i = 0; i < cfi->numchips; i++)
349 cfi->chips[i].start += offset;
350
351 /* Now that the mtd devices is complete claim and export it */
352 map->mtd->owner = THIS_MODULE;
353 if (add_mtd_device(map->mtd)) {
354 map_destroy(map->mtd);
355 map->mtd = NULL;
356 goto out;
357 }
358
359 /* Calculate the new value of map_top */
360 map_top += map->mtd->size;
361
362 /* File away the map structure */
363 list_add(&map->list, &window->maps);
364 map = NULL;
365 }
366
367 out:
368 /* Free any left over map structures */
369 kfree(map);
370
371 /* See if I have any map structures */
372 if (list_empty(&window->maps)) {
373 esb2rom_cleanup(window);
374 return -ENODEV;
375 }
376 return 0;
377}
378
379static void __devexit esb2rom_remove_one (struct pci_dev *pdev)
380{
381 struct esb2rom_window *window = &esb2rom_window;
382 esb2rom_cleanup(window);
383}
384
385static struct pci_device_id esb2rom_pci_tbl[] __devinitdata = {
386 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0,
387 PCI_ANY_ID, PCI_ANY_ID, },
388 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
389 PCI_ANY_ID, PCI_ANY_ID, },
390 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
391 PCI_ANY_ID, PCI_ANY_ID, },
392 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
393 PCI_ANY_ID, PCI_ANY_ID, },
394 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
395 PCI_ANY_ID, PCI_ANY_ID, },
396 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
397 PCI_ANY_ID, PCI_ANY_ID, },
398 { 0, },
399};
400
401#if 0
402MODULE_DEVICE_TABLE(pci, esb2rom_pci_tbl);
403
404static struct pci_driver esb2rom_driver = {
405 .name = MOD_NAME,
406 .id_table = esb2rom_pci_tbl,
407 .probe = esb2rom_init_one,
408 .remove = esb2rom_remove_one,
409};
410#endif
411
412static int __init init_esb2rom(void)
413{
414 struct pci_dev *pdev;
415 struct pci_device_id *id;
416 int retVal;
417
418 pdev = NULL;
419 for (id = esb2rom_pci_tbl; id->vendor; id++) {
420 printk(KERN_DEBUG "device id = %x\n", id->device);
421 pdev = pci_get_device(id->vendor, id->device, NULL);
422 if (pdev) {
423 printk(KERN_DEBUG "matched device = %x\n", id->device);
424 break;
425 }
426 }
427 if (pdev) {
428 printk(KERN_DEBUG "matched device id %x\n", id->device);
429 retVal = esb2rom_init_one(pdev, &esb2rom_pci_tbl[0]);
430 pci_dev_put(pdev);
431 printk(KERN_DEBUG "retVal = %d\n", retVal);
432 return retVal;
433 }
434 return -ENXIO;
435#if 0
436 return pci_register_driver(&esb2rom_driver);
437#endif
438}
439
440static void __exit cleanup_esb2rom(void)
441{
442 esb2rom_remove_one(esb2rom_window.pdev);
443}
444
445module_init(init_esb2rom);
446module_exit(cleanup_esb2rom);
447
448MODULE_LICENSE("GPL");
449MODULE_AUTHOR("Lew Glendenning <lglendenning@lnxi.com>");
450MODULE_DESCRIPTION("MTD map driver for BIOS chips on the ESB2 southbridge");
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index c8db01b3e45f..6946d802e6f6 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -75,14 +75,12 @@ static int armflash_probe(struct platform_device *dev)
75 int err; 75 int err;
76 void __iomem *base; 76 void __iomem *base;
77 77
78 info = kmalloc(sizeof(struct armflash_info), GFP_KERNEL); 78 info = kzalloc(sizeof(struct armflash_info), GFP_KERNEL);
79 if (!info) { 79 if (!info) {
80 err = -ENOMEM; 80 err = -ENOMEM;
81 goto out; 81 goto out;
82 } 82 }
83 83
84 memset(info, 0, sizeof(struct armflash_info));
85
86 info->plat = plat; 84 info->plat = plat;
87 if (plat && plat->init) { 85 if (plat && plat->init) {
88 err = plat->init(); 86 err = plat->init();
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index f9e8e5bcbc33..9f53c655af3a 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -20,6 +20,7 @@
20#include <linux/mtd/partitions.h> 20#include <linux/mtd/partitions.h>
21#include <linux/mtd/cfi.h> 21#include <linux/mtd/cfi.h>
22#include <linux/reboot.h> 22#include <linux/reboot.h>
23#include <linux/err.h>
23#include <linux/kdev_t.h> 24#include <linux/kdev_t.h>
24#include <linux/root_dev.h> 25#include <linux/root_dev.h>
25#include <asm/io.h> 26#include <asm/io.h>
@@ -178,7 +179,7 @@ int nettel_eraseconfig(void)
178 179
179 init_waitqueue_head(&wait_q); 180 init_waitqueue_head(&wait_q);
180 mtd = get_mtd_device(NULL, 2); 181 mtd = get_mtd_device(NULL, 2);
181 if (mtd) { 182 if (!IS_ERR(mtd)) {
182 nettel_erase.mtd = mtd; 183 nettel_erase.mtd = mtd;
183 nettel_erase.callback = nettel_erasecallback; 184 nettel_erase.callback = nettel_erasecallback;
184 nettel_erase.callback = NULL; 185 nettel_erase.callback = NULL;
@@ -471,7 +472,7 @@ out_unmap2:
471 iounmap(nettel_amd_map.virt); 472 iounmap(nettel_amd_map.virt);
472 473
473 return(rc); 474 return(rc);
474 475
475} 476}
476 477
477/****************************************************************************/ 478/****************************************************************************/
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index 418afffb2d80..e8d9ae535673 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -78,12 +78,10 @@ static int __devinit omapflash_probe(struct platform_device *pdev)
78 struct resource *res = pdev->resource; 78 struct resource *res = pdev->resource;
79 unsigned long size = res->end - res->start + 1; 79 unsigned long size = res->end - res->start + 1;
80 80
81 info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL); 81 info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL);
82 if (!info) 82 if (!info)
83 return -ENOMEM; 83 return -ENOMEM;
84 84
85 memset(info, 0, sizeof(struct omapflash_info));
86
87 if (!request_mem_region(res->start, size, "flash")) { 85 if (!request_mem_region(res->start, size, "flash")) {
88 err = -EBUSY; 86 err = -EBUSY;
89 goto out_free_info; 87 goto out_free_info;
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 995347b1beba..eaeb56a4070a 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -735,11 +735,10 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
735 struct pcmciamtd_dev *dev; 735 struct pcmciamtd_dev *dev;
736 736
737 /* Create new memory card device */ 737 /* Create new memory card device */
738 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 738 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
739 if (!dev) return -ENOMEM; 739 if (!dev) return -ENOMEM;
740 DEBUG(1, "dev=0x%p", dev); 740 DEBUG(1, "dev=0x%p", dev);
741 741
742 memset(dev, 0, sizeof(*dev));
743 dev->p_dev = link; 742 dev->p_dev = link;
744 link->priv = dev; 743 link->priv = dev;
745 744
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index d1717763f719..28c5ffd75233 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -89,15 +89,14 @@ static int physmap_flash_probe(struct platform_device *dev)
89 return -ENODEV; 89 return -ENODEV;
90 90
91 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n", 91 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
92 (unsigned long long)dev->resource->end - dev->resource->start + 1, 92 (unsigned long long)(dev->resource->end - dev->resource->start + 1),
93 (unsigned long long)dev->resource->start); 93 (unsigned long long)dev->resource->start);
94 94
95 info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL); 95 info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
96 if (info == NULL) { 96 if (info == NULL) {
97 err = -ENOMEM; 97 err = -ENOMEM;
98 goto err_out; 98 goto err_out;
99 } 99 }
100 memset(info, 0, sizeof(*info));
101 100
102 platform_set_drvdata(dev, info); 101 platform_set_drvdata(dev, info);
103 102
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
new file mode 100644
index 000000000000..7efe744ad31e
--- /dev/null
+++ b/drivers/mtd/maps/physmap_of.c
@@ -0,0 +1,255 @@
1/*
2 * Normal mappings of chips in physical memory for OF devices
3 *
4 * Copyright (C) 2006 MontaVista Software Inc.
5 * Author: Vitaly Wool <vwool@ru.mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/device.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/map.h>
21#include <linux/mtd/partitions.h>
22#include <linux/mtd/physmap.h>
23#include <asm/io.h>
24#include <asm/prom.h>
25#include <asm/of_device.h>
26#include <asm/of_platform.h>
27
28struct physmap_flash_info {
29 struct mtd_info *mtd;
30 struct map_info map;
31 struct resource *res;
32#ifdef CONFIG_MTD_PARTITIONS
33 int nr_parts;
34 struct mtd_partition *parts;
35#endif
36};
37
38static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
39#ifdef CONFIG_MTD_PARTITIONS
40static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
41#endif
42
43#ifdef CONFIG_MTD_PARTITIONS
44static int parse_flash_partitions(struct device_node *node,
45 struct mtd_partition **parts)
46{
47 int i, plen, retval = -ENOMEM;
48 const u32 *part;
49 const char *name;
50
51 part = get_property(node, "partitions", &plen);
52 if (part == NULL)
53 goto err;
54
55 retval = plen / (2 * sizeof(u32));
56 *parts = kzalloc(retval * sizeof(struct mtd_partition), GFP_KERNEL);
57 if (*parts == NULL) {
58 printk(KERN_ERR "Can't allocate the flash partition data!\n");
59 goto err;
60 }
61
62 name = get_property(node, "partition-names", &plen);
63
64 for (i = 0; i < retval; i++) {
65 (*parts)[i].offset = *part++;
66 (*parts)[i].size = *part & ~1;
67 if (*part++ & 1) /* bit 0 set signifies read only partition */
68 (*parts)[i].mask_flags = MTD_WRITEABLE;
69
70 if (name != NULL && plen > 0) {
71 int len = strlen(name) + 1;
72
73 (*parts)[i].name = (char *)name;
74 plen -= len;
75 name += len;
76 } else
77 (*parts)[i].name = "unnamed";
78 }
79err:
80 return retval;
81}
82#endif
83
84static int of_physmap_remove(struct of_device *dev)
85{
86 struct physmap_flash_info *info;
87
88 info = dev_get_drvdata(&dev->dev);
89 if (info == NULL)
90 return 0;
91 dev_set_drvdata(&dev->dev, NULL);
92
93 if (info->mtd != NULL) {
94#ifdef CONFIG_MTD_PARTITIONS
95 if (info->nr_parts) {
96 del_mtd_partitions(info->mtd);
97 kfree(info->parts);
98 } else {
99 del_mtd_device(info->mtd);
100 }
101#else
102 del_mtd_device(info->mtd);
103#endif
104 map_destroy(info->mtd);
105 }
106
107 if (info->map.virt != NULL)
108 iounmap(info->map.virt);
109
110 if (info->res != NULL) {
111 release_resource(info->res);
112 kfree(info->res);
113 }
114
115 return 0;
116}
117
118static int __devinit of_physmap_probe(struct of_device *dev, const struct of_device_id *match)
119{
120 struct device_node *dp = dev->node;
121 struct resource res;
122 struct physmap_flash_info *info;
123 const char **probe_type;
124 const char *of_probe;
125 const u32 *width;
126 int err;
127
128
129 if (of_address_to_resource(dp, 0, &res)) {
130 dev_err(&dev->dev, "Can't get the flash mapping!\n");
131 err = -EINVAL;
132 goto err_out;
133 }
134
135 dev_dbg(&dev->dev, "physmap flash device: %.8llx at %.8llx\n",
136 (unsigned long long)res.end - res.start + 1,
137 (unsigned long long)res.start);
138
139 info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
140 if (info == NULL) {
141 err = -ENOMEM;
142 goto err_out;
143 }
144 memset(info, 0, sizeof(*info));
145
146 dev_set_drvdata(&dev->dev, info);
147
148 info->res = request_mem_region(res.start, res.end - res.start + 1,
149 dev->dev.bus_id);
150 if (info->res == NULL) {
151 dev_err(&dev->dev, "Could not reserve memory region\n");
152 err = -ENOMEM;
153 goto err_out;
154 }
155
156 width = get_property(dp, "bank-width", NULL);
157 if (width == NULL) {
158 dev_err(&dev->dev, "Can't get the flash bank width!\n");
159 err = -EINVAL;
160 goto err_out;
161 }
162
163 info->map.name = dev->dev.bus_id;
164 info->map.phys = res.start;
165 info->map.size = res.end - res.start + 1;
166 info->map.bankwidth = *width;
167
168 info->map.virt = ioremap(info->map.phys, info->map.size);
169 if (info->map.virt == NULL) {
170 dev_err(&dev->dev, "Failed to ioremap flash region\n");
171 err = EIO;
172 goto err_out;
173 }
174
175 simple_map_init(&info->map);
176
177 of_probe = get_property(dp, "probe-type", NULL);
178 if (of_probe == NULL) {
179 probe_type = rom_probe_types;
180 for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
181 info->mtd = do_map_probe(*probe_type, &info->map);
182 } else if (!strcmp(of_probe, "CFI"))
183 info->mtd = do_map_probe("cfi_probe", &info->map);
184 else if (!strcmp(of_probe, "JEDEC"))
185 info->mtd = do_map_probe("jedec_probe", &info->map);
186 else {
187 if (strcmp(of_probe, "ROM"))
188 dev_dbg(&dev->dev, "map_probe: don't know probe type "
189 "'%s', mapping as rom\n");
190 info->mtd = do_map_probe("mtd_rom", &info->map);
191 }
192 if (info->mtd == NULL) {
193 dev_err(&dev->dev, "map_probe failed\n");
194 err = -ENXIO;
195 goto err_out;
196 }
197 info->mtd->owner = THIS_MODULE;
198
199#ifdef CONFIG_MTD_PARTITIONS
200 err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
201 if (err > 0) {
202 add_mtd_partitions(info->mtd, info->parts, err);
203 } else if ((err = parse_flash_partitions(dp, &info->parts)) > 0) {
204 dev_info(&dev->dev, "Using OF partition information\n");
205 add_mtd_partitions(info->mtd, info->parts, err);
206 info->nr_parts = err;
207 } else
208#endif
209
210 add_mtd_device(info->mtd);
211 return 0;
212
213err_out:
214 of_physmap_remove(dev);
215 return err;
216
217 return 0;
218
219
220}
221
222static struct of_device_id of_physmap_match[] = {
223 {
224 .type = "rom",
225 .compatible = "direct-mapped"
226 },
227 { },
228};
229
230MODULE_DEVICE_TABLE(of, of_physmap_match);
231
232
233static struct of_platform_driver of_physmap_flash_driver = {
234 .name = "physmap-flash",
235 .match_table = of_physmap_match,
236 .probe = of_physmap_probe,
237 .remove = of_physmap_remove,
238};
239
240static int __init of_physmap_init(void)
241{
242 return of_register_platform_driver(&of_physmap_flash_driver);
243}
244
245static void __exit of_physmap_exit(void)
246{
247 of_unregister_platform_driver(&of_physmap_flash_driver);
248}
249
250module_init(of_physmap_init);
251module_exit(of_physmap_exit);
252
253MODULE_LICENSE("GPL");
254MODULE_AUTHOR("Vitaly Wool <vwool@ru.mvista.com>");
255MODULE_DESCRIPTION("Configurable MTD map driver for OF");
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 5d3c75451ca2..2b6504ecbbd1 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -147,14 +147,13 @@ static int platram_probe(struct platform_device *pdev)
147 147
148 pdata = pdev->dev.platform_data; 148 pdata = pdev->dev.platform_data;
149 149
150 info = kmalloc(sizeof(*info), GFP_KERNEL); 150 info = kzalloc(sizeof(*info), GFP_KERNEL);
151 if (info == NULL) { 151 if (info == NULL) {
152 dev_err(&pdev->dev, "no memory for flash info\n"); 152 dev_err(&pdev->dev, "no memory for flash info\n");
153 err = -ENOMEM; 153 err = -ENOMEM;
154 goto exit_error; 154 goto exit_error;
155 } 155 }
156 156
157 memset(info, 0, sizeof(*info));
158 platform_set_drvdata(pdev, info); 157 platform_set_drvdata(pdev, info);
159 158
160 info->dev = &pdev->dev; 159 info->dev = &pdev->dev;
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 950bf1c57841..f904e6bd02e0 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -273,14 +273,12 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
273 /* 273 /*
274 * Allocate the map_info structs in one go. 274 * Allocate the map_info structs in one go.
275 */ 275 */
276 info = kmalloc(size, GFP_KERNEL); 276 info = kzalloc(size, GFP_KERNEL);
277 if (!info) { 277 if (!info) {
278 ret = -ENOMEM; 278 ret = -ENOMEM;
279 goto out; 279 goto out;
280 } 280 }
281 281
282 memset(info, 0, size);
283
284 if (plat->init) { 282 if (plat->init) {
285 ret = plat->init(); 283 ret = plat->init();
286 if (ret) 284 if (ret)
diff --git a/drivers/mtd/maps/tqm834x.c b/drivers/mtd/maps/tqm834x.c
index 58e5912bd381..9adc970e55e6 100644
--- a/drivers/mtd/maps/tqm834x.c
+++ b/drivers/mtd/maps/tqm834x.c
@@ -132,20 +132,16 @@ static int __init init_tqm834x_mtd(void)
132 132
133 pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx); 133 pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx);
134 134
135 map_banks[idx] = 135 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
136 (struct map_info *)kmalloc(sizeof(struct map_info),
137 GFP_KERNEL);
138 if (map_banks[idx] == NULL) { 136 if (map_banks[idx] == NULL) {
139 ret = -ENOMEM; 137 ret = -ENOMEM;
140 goto error_mem; 138 goto error_mem;
141 } 139 }
142 memset((void *)map_banks[idx], 0, sizeof(struct map_info)); 140 map_banks[idx]->name = kzalloc(16, GFP_KERNEL);
143 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
144 if (map_banks[idx]->name == NULL) { 141 if (map_banks[idx]->name == NULL) {
145 ret = -ENOMEM; 142 ret = -ENOMEM;
146 goto error_mem; 143 goto error_mem;
147 } 144 }
148 memset((void *)map_banks[idx]->name, 0, 16);
149 145
150 sprintf(map_banks[idx]->name, "TQM834x-%d", idx); 146 sprintf(map_banks[idx]->name, "TQM834x-%d", idx);
151 map_banks[idx]->size = flash_size; 147 map_banks[idx]->size = flash_size;
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 19578ba84ee8..37e4ded9b600 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -134,14 +134,13 @@ int __init init_tqm_mtd(void)
134 134
135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); 135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx);
136 136
137 map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL); 137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
138 if(map_banks[idx] == NULL) { 138 if(map_banks[idx] == NULL) {
139 ret = -ENOMEM; 139 ret = -ENOMEM;
140 /* FIXME: What if some MTD devices were probed already? */ 140 /* FIXME: What if some MTD devices were probed already? */
141 goto error_mem; 141 goto error_mem;
142 } 142 }
143 143
144 memset((void *)map_banks[idx], 0, sizeof(struct map_info));
145 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL); 144 map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
146 145
147 if (!map_banks[idx]->name) { 146 if (!map_banks[idx]->name) {
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 178b53b56be9..b879a66daa9e 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -42,19 +42,20 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
42 unsigned long block, nsect; 42 unsigned long block, nsect;
43 char *buf; 43 char *buf;
44 44
45 block = req->sector; 45 block = req->sector << 9 >> tr->blkshift;
46 nsect = req->current_nr_sectors; 46 nsect = req->current_nr_sectors << 9 >> tr->blkshift;
47
47 buf = req->buffer; 48 buf = req->buffer;
48 49
49 if (!blk_fs_request(req)) 50 if (!blk_fs_request(req))
50 return 0; 51 return 0;
51 52
52 if (block + nsect > get_capacity(req->rq_disk)) 53 if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk))
53 return 0; 54 return 0;
54 55
55 switch(rq_data_dir(req)) { 56 switch(rq_data_dir(req)) {
56 case READ: 57 case READ:
57 for (; nsect > 0; nsect--, block++, buf += 512) 58 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
58 if (tr->readsect(dev, block, buf)) 59 if (tr->readsect(dev, block, buf))
59 return 0; 60 return 0;
60 return 1; 61 return 1;
@@ -63,7 +64,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
63 if (!tr->writesect) 64 if (!tr->writesect)
64 return 0; 65 return 0;
65 66
66 for (; nsect > 0; nsect--, block++, buf += 512) 67 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
67 if (tr->writesect(dev, block, buf)) 68 if (tr->writesect(dev, block, buf))
68 return 0; 69 return 0;
69 return 1; 70 return 1;
@@ -297,7 +298,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
297 298
298 /* 2.5 has capacity in units of 512 bytes while still 299 /* 2.5 has capacity in units of 512 bytes while still
299 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */ 300 having BLOCK_SIZE_BITS set to 10. Just to keep us amused. */
300 set_capacity(gd, (new->size * new->blksize) >> 9); 301 set_capacity(gd, (new->size * tr->blksize) >> 9);
301 302
302 gd->private_data = new; 303 gd->private_data = new;
303 new->blkcore_priv = gd; 304 new->blkcore_priv = gd;
@@ -372,12 +373,10 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
372 if (!blktrans_notifier.list.next) 373 if (!blktrans_notifier.list.next)
373 register_mtd_user(&blktrans_notifier); 374 register_mtd_user(&blktrans_notifier);
374 375
375 tr->blkcore_priv = kmalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL); 376 tr->blkcore_priv = kzalloc(sizeof(*tr->blkcore_priv), GFP_KERNEL);
376 if (!tr->blkcore_priv) 377 if (!tr->blkcore_priv)
377 return -ENOMEM; 378 return -ENOMEM;
378 379
379 memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
380
381 mutex_lock(&mtd_table_mutex); 380 mutex_lock(&mtd_table_mutex);
382 381
383 ret = register_blkdev(tr->major, tr->name); 382 ret = register_blkdev(tr->major, tr->name);
@@ -401,6 +400,8 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
401 } 400 }
402 401
403 tr->blkcore_priv->rq->queuedata = tr; 402 tr->blkcore_priv->rq->queuedata = tr;
403 blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize);
404 tr->blkshift = ffs(tr->blksize) - 1;
404 405
405 ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL); 406 ret = kernel_thread(mtd_blktrans_thread, tr, CLONE_KERNEL);
406 if (ret < 0) { 407 if (ret < 0) {
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 04ed34694b14..952da30b1745 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -278,11 +278,10 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
278 } 278 }
279 279
280 /* OK, it's not open. Create cache info for it */ 280 /* OK, it's not open. Create cache info for it */
281 mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); 281 mtdblk = kzalloc(sizeof(struct mtdblk_dev), GFP_KERNEL);
282 if (!mtdblk) 282 if (!mtdblk)
283 return -ENOMEM; 283 return -ENOMEM;
284 284
285 memset(mtdblk, 0, sizeof(*mtdblk));
286 mtdblk->count = 1; 285 mtdblk->count = 1;
287 mtdblk->mtd = mtd; 286 mtdblk->mtd = mtd;
288 287
@@ -339,16 +338,14 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
339 338
340static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 339static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
341{ 340{
342 struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); 341 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
343 342
344 if (!dev) 343 if (!dev)
345 return; 344 return;
346 345
347 memset(dev, 0, sizeof(*dev));
348
349 dev->mtd = mtd; 346 dev->mtd = mtd;
350 dev->devnum = mtd->index; 347 dev->devnum = mtd->index;
351 dev->blksize = 512; 348
352 dev->size = mtd->size >> 9; 349 dev->size = mtd->size >> 9;
353 dev->tr = tr; 350 dev->tr = tr;
354 351
@@ -368,6 +365,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
368 .name = "mtdblock", 365 .name = "mtdblock",
369 .major = 31, 366 .major = 31,
370 .part_bits = 0, 367 .part_bits = 0,
368 .blksize = 512,
371 .open = mtdblock_open, 369 .open = mtdblock_open,
372 .flush = mtdblock_flush, 370 .flush = mtdblock_flush,
373 .release = mtdblock_release, 371 .release = mtdblock_release,
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 29563ed258a4..f79dbb49b1a2 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -33,16 +33,14 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
33 33
34static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 34static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
35{ 35{
36 struct mtd_blktrans_dev *dev = kmalloc(sizeof(*dev), GFP_KERNEL); 36 struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
37 37
38 if (!dev) 38 if (!dev)
39 return; 39 return;
40 40
41 memset(dev, 0, sizeof(*dev));
42
43 dev->mtd = mtd; 41 dev->mtd = mtd;
44 dev->devnum = mtd->index; 42 dev->devnum = mtd->index;
45 dev->blksize = 512; 43
46 dev->size = mtd->size >> 9; 44 dev->size = mtd->size >> 9;
47 dev->tr = tr; 45 dev->tr = tr;
48 dev->readonly = 1; 46 dev->readonly = 1;
@@ -60,6 +58,7 @@ static struct mtd_blktrans_ops mtdblock_tr = {
60 .name = "mtdblock", 58 .name = "mtdblock",
61 .major = 31, 59 .major = 31,
62 .part_bits = 0, 60 .part_bits = 0,
61 .blksize = 512,
63 .readsect = mtdblock_readsect, 62 .readsect = mtdblock_readsect,
64 .writesect = mtdblock_writesect, 63 .writesect = mtdblock_writesect,
65 .add_mtd = mtdblock_add_mtd, 64 .add_mtd = mtdblock_add_mtd,
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 5b6acfcb2b88..3013d0883b97 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/fs.h> 9#include <linux/fs.h>
10#include <linux/err.h>
10#include <linux/init.h> 11#include <linux/init.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
12#include <linux/module.h> 13#include <linux/module.h>
@@ -100,8 +101,8 @@ static int mtd_open(struct inode *inode, struct file *file)
100 101
101 mtd = get_mtd_device(NULL, devnum); 102 mtd = get_mtd_device(NULL, devnum);
102 103
103 if (!mtd) 104 if (IS_ERR(mtd))
104 return -ENODEV; 105 return PTR_ERR(mtd);
105 106
106 if (MTD_ABSENT == mtd->type) { 107 if (MTD_ABSENT == mtd->type) {
107 put_mtd_device(mtd); 108 put_mtd_device(mtd);
@@ -431,7 +432,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
431 if(!(file->f_mode & 2)) 432 if(!(file->f_mode & 2))
432 return -EPERM; 433 return -EPERM;
433 434
434 erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL); 435 erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
435 if (!erase) 436 if (!erase)
436 ret = -ENOMEM; 437 ret = -ENOMEM;
437 else { 438 else {
@@ -440,7 +441,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
440 441
441 init_waitqueue_head(&waitq); 442 init_waitqueue_head(&waitq);
442 443
443 memset (erase,0,sizeof(struct erase_info));
444 if (copy_from_user(&erase->addr, argp, 444 if (copy_from_user(&erase->addr, argp,
445 sizeof(struct erase_info_user))) { 445 sizeof(struct erase_info_user))) {
446 kfree(erase); 446 kfree(erase);
@@ -499,13 +499,12 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
499 if (ret) 499 if (ret)
500 return ret; 500 return ret;
501 501
502 ops.len = buf.length;
503 ops.ooblen = buf.length; 502 ops.ooblen = buf.length;
504 ops.ooboffs = buf.start & (mtd->oobsize - 1); 503 ops.ooboffs = buf.start & (mtd->oobsize - 1);
505 ops.datbuf = NULL; 504 ops.datbuf = NULL;
506 ops.mode = MTD_OOB_PLACE; 505 ops.mode = MTD_OOB_PLACE;
507 506
508 if (ops.ooboffs && ops.len > (mtd->oobsize - ops.ooboffs)) 507 if (ops.ooboffs && ops.ooblen > (mtd->oobsize - ops.ooboffs))
509 return -EINVAL; 508 return -EINVAL;
510 509
511 ops.oobbuf = kmalloc(buf.length, GFP_KERNEL); 510 ops.oobbuf = kmalloc(buf.length, GFP_KERNEL);
@@ -520,7 +519,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
520 buf.start &= ~(mtd->oobsize - 1); 519 buf.start &= ~(mtd->oobsize - 1);
521 ret = mtd->write_oob(mtd, buf.start, &ops); 520 ret = mtd->write_oob(mtd, buf.start, &ops);
522 521
523 if (copy_to_user(argp + sizeof(uint32_t), &ops.retlen, 522 if (copy_to_user(argp + sizeof(uint32_t), &ops.oobretlen,
524 sizeof(uint32_t))) 523 sizeof(uint32_t)))
525 ret = -EFAULT; 524 ret = -EFAULT;
526 525
@@ -548,7 +547,6 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
548 if (ret) 547 if (ret)
549 return ret; 548 return ret;
550 549
551 ops.len = buf.length;
552 ops.ooblen = buf.length; 550 ops.ooblen = buf.length;
553 ops.ooboffs = buf.start & (mtd->oobsize - 1); 551 ops.ooboffs = buf.start & (mtd->oobsize - 1);
554 ops.datbuf = NULL; 552 ops.datbuf = NULL;
@@ -564,10 +562,10 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
564 buf.start &= ~(mtd->oobsize - 1); 562 buf.start &= ~(mtd->oobsize - 1);
565 ret = mtd->read_oob(mtd, buf.start, &ops); 563 ret = mtd->read_oob(mtd, buf.start, &ops);
566 564
567 if (put_user(ops.retlen, (uint32_t __user *)argp)) 565 if (put_user(ops.oobretlen, (uint32_t __user *)argp))
568 ret = -EFAULT; 566 ret = -EFAULT;
569 else if (ops.retlen && copy_to_user(buf.ptr, ops.oobbuf, 567 else if (ops.oobretlen && copy_to_user(buf.ptr, ops.oobbuf,
570 ops.retlen)) 568 ops.oobretlen))
571 ret = -EFAULT; 569 ret = -EFAULT;
572 570
573 kfree(ops.oobbuf); 571 kfree(ops.oobbuf);
@@ -616,6 +614,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
616 memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos)); 614 memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
617 memcpy(&oi.oobfree, mtd->ecclayout->oobfree, 615 memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
618 sizeof(oi.oobfree)); 616 sizeof(oi.oobfree));
617 oi.eccbytes = mtd->ecclayout->eccbytes;
619 618
620 if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo))) 619 if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
621 return -EFAULT; 620 return -EFAULT;
@@ -715,7 +714,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
715 if (!mtd->ecclayout) 714 if (!mtd->ecclayout)
716 return -EOPNOTSUPP; 715 return -EOPNOTSUPP;
717 716
718 if (copy_to_user(argp, &mtd->ecclayout, 717 if (copy_to_user(argp, mtd->ecclayout,
719 sizeof(struct nand_ecclayout))) 718 sizeof(struct nand_ecclayout)))
720 return -EFAULT; 719 return -EFAULT;
721 break; 720 break;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 1fea631b5852..06902683bc2a 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -247,7 +247,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
247 struct mtd_oob_ops devops = *ops; 247 struct mtd_oob_ops devops = *ops;
248 int i, err, ret = 0; 248 int i, err, ret = 0;
249 249
250 ops->retlen = 0; 250 ops->retlen = ops->oobretlen = 0;
251 251
252 for (i = 0; i < concat->num_subdev; i++) { 252 for (i = 0; i < concat->num_subdev; i++) {
253 struct mtd_info *subdev = concat->subdev[i]; 253 struct mtd_info *subdev = concat->subdev[i];
@@ -263,6 +263,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
263 263
264 err = subdev->read_oob(subdev, from, &devops); 264 err = subdev->read_oob(subdev, from, &devops);
265 ops->retlen += devops.retlen; 265 ops->retlen += devops.retlen;
266 ops->oobretlen += devops.oobretlen;
266 267
267 /* Save information about bitflips! */ 268 /* Save information about bitflips! */
268 if (unlikely(err)) { 269 if (unlikely(err)) {
@@ -278,14 +279,18 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
278 return err; 279 return err;
279 } 280 }
280 281
281 devops.len = ops->len - ops->retlen; 282 if (devops.datbuf) {
282 if (!devops.len) 283 devops.len = ops->len - ops->retlen;
283 return ret; 284 if (!devops.len)
284 285 return ret;
285 if (devops.datbuf)
286 devops.datbuf += devops.retlen; 286 devops.datbuf += devops.retlen;
287 if (devops.oobbuf) 287 }
288 devops.oobbuf += devops.ooblen; 288 if (devops.oobbuf) {
289 devops.ooblen = ops->ooblen - ops->oobretlen;
290 if (!devops.ooblen)
291 return ret;
292 devops.oobbuf += ops->oobretlen;
293 }
289 294
290 from = 0; 295 from = 0;
291 } 296 }
@@ -321,14 +326,18 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
321 if (err) 326 if (err)
322 return err; 327 return err;
323 328
324 devops.len = ops->len - ops->retlen; 329 if (devops.datbuf) {
325 if (!devops.len) 330 devops.len = ops->len - ops->retlen;
326 return 0; 331 if (!devops.len)
327 332 return 0;
328 if (devops.datbuf)
329 devops.datbuf += devops.retlen; 333 devops.datbuf += devops.retlen;
330 if (devops.oobbuf) 334 }
331 devops.oobbuf += devops.ooblen; 335 if (devops.oobbuf) {
336 devops.ooblen = ops->ooblen - ops->oobretlen;
337 if (!devops.ooblen)
338 return 0;
339 devops.oobbuf += devops.oobretlen;
340 }
332 to = 0; 341 to = 0;
333 } 342 }
334 return -EINVAL; 343 return -EINVAL;
@@ -699,14 +708,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
699 708
700 /* allocate the device structure */ 709 /* allocate the device structure */
701 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs); 710 size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
702 concat = kmalloc(size, GFP_KERNEL); 711 concat = kzalloc(size, GFP_KERNEL);
703 if (!concat) { 712 if (!concat) {
704 printk 713 printk
705 ("memory allocation error while creating concatenated device \"%s\"\n", 714 ("memory allocation error while creating concatenated device \"%s\"\n",
706 name); 715 name);
707 return NULL; 716 return NULL;
708 } 717 }
709 memset(concat, 0, size);
710 concat->subdev = (struct mtd_info **) (concat + 1); 718 concat->subdev = (struct mtd_info **) (concat + 1);
711 719
712 /* 720 /*
@@ -764,6 +772,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
764 concat->mtd.ecc_stats.badblocks += 772 concat->mtd.ecc_stats.badblocks +=
765 subdev[i]->ecc_stats.badblocks; 773 subdev[i]->ecc_stats.badblocks;
766 if (concat->mtd.writesize != subdev[i]->writesize || 774 if (concat->mtd.writesize != subdev[i]->writesize ||
775 concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
767 concat->mtd.oobsize != subdev[i]->oobsize || 776 concat->mtd.oobsize != subdev[i]->oobsize ||
768 concat->mtd.ecctype != subdev[i]->ecctype || 777 concat->mtd.ecctype != subdev[i]->ecctype ||
769 concat->mtd.eccsize != subdev[i]->eccsize || 778 concat->mtd.eccsize != subdev[i]->eccsize ||
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c4d26de74349..7070110aba2a 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -15,6 +15,7 @@
15#include <linux/timer.h> 15#include <linux/timer.h>
16#include <linux/major.h> 16#include <linux/major.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/err.h>
18#include <linux/ioctl.h> 19#include <linux/ioctl.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/mtd/compatmac.h> 21#include <linux/mtd/compatmac.h>
@@ -192,14 +193,14 @@ int unregister_mtd_user (struct mtd_notifier *old)
192 * Given a number and NULL address, return the num'th entry in the device 193 * Given a number and NULL address, return the num'th entry in the device
193 * table, if any. Given an address and num == -1, search the device table 194 * table, if any. Given an address and num == -1, search the device table
194 * for a device with that address and return if it's still present. Given 195 * for a device with that address and return if it's still present. Given
195 * both, return the num'th driver only if its address matches. Return NULL 196 * both, return the num'th driver only if its address matches. Return
196 * if not. 197 * error code if not.
197 */ 198 */
198 199
199struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) 200struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
200{ 201{
201 struct mtd_info *ret = NULL; 202 struct mtd_info *ret = NULL;
202 int i; 203 int i, err = -ENODEV;
203 204
204 mutex_lock(&mtd_table_mutex); 205 mutex_lock(&mtd_table_mutex);
205 206
@@ -213,14 +214,73 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
213 ret = NULL; 214 ret = NULL;
214 } 215 }
215 216
216 if (ret && !try_module_get(ret->owner)) 217 if (!ret)
217 ret = NULL; 218 goto out_unlock;
219
220 if (!try_module_get(ret->owner))
221 goto out_unlock;
218 222
219 if (ret) 223 if (ret->get_device) {
220 ret->usecount++; 224 err = ret->get_device(ret);
225 if (err)
226 goto out_put;
227 }
221 228
229 ret->usecount++;
222 mutex_unlock(&mtd_table_mutex); 230 mutex_unlock(&mtd_table_mutex);
223 return ret; 231 return ret;
232
233out_put:
234 module_put(ret->owner);
235out_unlock:
236 mutex_unlock(&mtd_table_mutex);
237 return ERR_PTR(err);
238}
239
240/**
241 * get_mtd_device_nm - obtain a validated handle for an MTD device by
242 * device name
243 * @name: MTD device name to open
244 *
245 * This function returns MTD device description structure in case of
246 * success and an error code in case of failure.
247 */
248
249struct mtd_info *get_mtd_device_nm(const char *name)
250{
251 int i, err = -ENODEV;
252 struct mtd_info *mtd = NULL;
253
254 mutex_lock(&mtd_table_mutex);
255
256 for (i = 0; i < MAX_MTD_DEVICES; i++) {
257 if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) {
258 mtd = mtd_table[i];
259 break;
260 }
261 }
262
263 if (!mtd)
264 goto out_unlock;
265
266 if (!try_module_get(mtd->owner))
267 goto out_unlock;
268
269 if (mtd->get_device) {
270 err = mtd->get_device(mtd);
271 if (err)
272 goto out_put;
273 }
274
275 mtd->usecount++;
276 mutex_unlock(&mtd_table_mutex);
277 return mtd;
278
279out_put:
280 module_put(mtd->owner);
281out_unlock:
282 mutex_unlock(&mtd_table_mutex);
283 return ERR_PTR(err);
224} 284}
225 285
226void put_mtd_device(struct mtd_info *mtd) 286void put_mtd_device(struct mtd_info *mtd)
@@ -229,6 +289,8 @@ void put_mtd_device(struct mtd_info *mtd)
229 289
230 mutex_lock(&mtd_table_mutex); 290 mutex_lock(&mtd_table_mutex);
231 c = --mtd->usecount; 291 c = --mtd->usecount;
292 if (mtd->put_device)
293 mtd->put_device(mtd);
232 mutex_unlock(&mtd_table_mutex); 294 mutex_unlock(&mtd_table_mutex);
233 BUG_ON(c < 0); 295 BUG_ON(c < 0);
234 296
@@ -236,7 +298,7 @@ void put_mtd_device(struct mtd_info *mtd)
236} 298}
237 299
238/* default_mtd_writev - default mtd writev method for MTD devices that 300/* default_mtd_writev - default mtd writev method for MTD devices that
239 * dont implement their own 301 * don't implement their own
240 */ 302 */
241 303
242int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, 304int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
@@ -264,13 +326,14 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
264 return ret; 326 return ret;
265} 327}
266 328
267EXPORT_SYMBOL(add_mtd_device); 329EXPORT_SYMBOL_GPL(add_mtd_device);
268EXPORT_SYMBOL(del_mtd_device); 330EXPORT_SYMBOL_GPL(del_mtd_device);
269EXPORT_SYMBOL(get_mtd_device); 331EXPORT_SYMBOL_GPL(get_mtd_device);
270EXPORT_SYMBOL(put_mtd_device); 332EXPORT_SYMBOL_GPL(get_mtd_device_nm);
271EXPORT_SYMBOL(register_mtd_user); 333EXPORT_SYMBOL_GPL(put_mtd_device);
272EXPORT_SYMBOL(unregister_mtd_user); 334EXPORT_SYMBOL_GPL(register_mtd_user);
273EXPORT_SYMBOL(default_mtd_writev); 335EXPORT_SYMBOL_GPL(unregister_mtd_user);
336EXPORT_SYMBOL_GPL(default_mtd_writev);
274 337
275#ifdef CONFIG_PROC_FS 338#ifdef CONFIG_PROC_FS
276 339
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 06a930372b7a..bafd2fba87bd 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -94,7 +94,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from,
94 94
95 if (from >= mtd->size) 95 if (from >= mtd->size)
96 return -EINVAL; 96 return -EINVAL;
97 if (from + ops->len > mtd->size) 97 if (ops->datbuf && from + ops->len > mtd->size)
98 return -EINVAL; 98 return -EINVAL;
99 res = part->master->read_oob(part->master, from + part->offset, ops); 99 res = part->master->read_oob(part->master, from + part->offset, ops);
100 100
@@ -161,7 +161,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to,
161 161
162 if (to >= mtd->size) 162 if (to >= mtd->size)
163 return -EINVAL; 163 return -EINVAL;
164 if (to + ops->len > mtd->size) 164 if (ops->datbuf && to + ops->len > mtd->size)
165 return -EINVAL; 165 return -EINVAL;
166 return part->master->write_oob(part->master, to + part->offset, ops); 166 return part->master->write_oob(part->master, to + part->offset, ops);
167} 167}
@@ -323,14 +323,13 @@ int add_mtd_partitions(struct mtd_info *master,
323 for (i = 0; i < nbparts; i++) { 323 for (i = 0; i < nbparts; i++) {
324 324
325 /* allocate the partition structure */ 325 /* allocate the partition structure */
326 slave = kmalloc (sizeof(*slave), GFP_KERNEL); 326 slave = kzalloc (sizeof(*slave), GFP_KERNEL);
327 if (!slave) { 327 if (!slave) {
328 printk ("memory allocation error while creating partitions for \"%s\"\n", 328 printk ("memory allocation error while creating partitions for \"%s\"\n",
329 master->name); 329 master->name);
330 del_mtd_partitions(master); 330 del_mtd_partitions(master);
331 return -ENOMEM; 331 return -ENOMEM;
332 } 332 }
333 memset(slave, 0, sizeof(*slave));
334 list_add(&slave->list, &mtd_partitions); 333 list_add(&slave->list, &mtd_partitions);
335 334
336 /* set up the MTD object for this partition */ 335 /* set up the MTD object for this partition */
@@ -341,6 +340,7 @@ int add_mtd_partitions(struct mtd_info *master,
341 slave->mtd.oobsize = master->oobsize; 340 slave->mtd.oobsize = master->oobsize;
342 slave->mtd.ecctype = master->ecctype; 341 slave->mtd.ecctype = master->ecctype;
343 slave->mtd.eccsize = master->eccsize; 342 slave->mtd.eccsize = master->eccsize;
343 slave->mtd.subpage_sft = master->subpage_sft;
344 344
345 slave->mtd.name = parts[i].name; 345 slave->mtd.name = parts[i].name;
346 slave->mtd.bank_size = master->bank_size; 346 slave->mtd.bank_size = master->bank_size;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1831340e5f51..358f55a82dbe 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -90,6 +90,7 @@ config MTD_NAND_RTC_FROM4
90 depends on MTD_NAND && SH_SOLUTION_ENGINE 90 depends on MTD_NAND && SH_SOLUTION_ENGINE
91 select REED_SOLOMON 91 select REED_SOLOMON
92 select REED_SOLOMON_DEC8 92 select REED_SOLOMON_DEC8
93 select BITREVERSE
93 help 94 help
94 This enables the driver for the Renesas Technology AG-AND 95 This enables the driver for the Renesas Technology AG-AND
95 flash interface board (FROM_BOARD4) 96 flash interface board (FROM_BOARD4)
@@ -132,6 +133,7 @@ config MTD_NAND_S3C2410_HWECC
132config MTD_NAND_NDFC 133config MTD_NAND_NDFC
133 tristate "NDFC NanD Flash Controller" 134 tristate "NDFC NanD Flash Controller"
134 depends on MTD_NAND && 44x 135 depends on MTD_NAND && 44x
136 select MTD_NAND_ECC_SMC
135 help 137 help
136 NDFC Nand Flash Controllers are integrated in EP44x SoCs 138 NDFC Nand Flash Controllers are integrated in EP44x SoCs
137 139
@@ -219,6 +221,13 @@ config MTD_NAND_SHARPSL
219 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" 221 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
220 depends on MTD_NAND && ARCH_PXA 222 depends on MTD_NAND && ARCH_PXA
221 223
224config MTD_NAND_CAFE
225 tristate "NAND support for OLPC CAFÉ chip"
226 depends on PCI
227 help
228 Use NAND flash attached to the CAFÉ chip designed for the $100
229 laptop.
230
222config MTD_NAND_CS553X 231config MTD_NAND_CS553X
223 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)" 232 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)"
224 depends on MTD_NAND && X86_32 && (X86_PC || X86_GENERICARCH) 233 depends on MTD_NAND && X86_32 && (X86_PC || X86_GENERICARCH)
@@ -232,6 +241,13 @@ config MTD_NAND_CS553X
232 241
233 If you say "m", the module will be called "cs553x_nand.ko". 242 If you say "m", the module will be called "cs553x_nand.ko".
234 243
244config MTD_NAND_AT91
245 bool "Support for NAND Flash / SmartMedia on AT91"
246 depends on MTD_NAND && ARCH_AT91
247 help
248 Enables support for NAND Flash / Smart Media Card interface
249 on Atmel AT91 processors.
250
235config MTD_NAND_NANDSIM 251config MTD_NAND_NANDSIM
236 tristate "Support for NAND Flash Simulator" 252 tristate "Support for NAND Flash Simulator"
237 depends on MTD_NAND && MTD_PARTITIONS 253 depends on MTD_NAND && MTD_PARTITIONS
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index f74759351c91..f7a53f0b7017 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -6,6 +6,7 @@
6obj-$(CONFIG_MTD_NAND) += nand.o nand_ecc.o 6obj-$(CONFIG_MTD_NAND) += nand.o nand_ecc.o
7obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o 7obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o
8 8
9obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o
9obj-$(CONFIG_MTD_NAND_SPIA) += spia.o 10obj-$(CONFIG_MTD_NAND_SPIA) += spia.o
10obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o 11obj-$(CONFIG_MTD_NAND_AMS_DELTA) += ams-delta.o
11obj-$(CONFIG_MTD_NAND_TOTO) += toto.o 12obj-$(CONFIG_MTD_NAND_TOTO) += toto.o
@@ -22,5 +23,7 @@ obj-$(CONFIG_MTD_NAND_TS7250) += ts7250.o
22obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o 23obj-$(CONFIG_MTD_NAND_NANDSIM) += nandsim.o
23obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o 24obj-$(CONFIG_MTD_NAND_CS553X) += cs553x_nand.o
24obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o 25obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
25 27
26nand-objs = nand_base.o nand_bbt.o 28nand-objs := nand_base.o nand_bbt.o
29cafe_nand-objs := cafe.o cafe_ecc.o
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
new file mode 100644
index 000000000000..14b80cc90a7b
--- /dev/null
+++ b/drivers/mtd/nand/at91_nand.c
@@ -0,0 +1,223 @@
1/*
2 * drivers/mtd/nand/at91_nand.c
3 *
4 * Copyright (C) 2003 Rick Bronson
5 *
6 * Derived from drivers/mtd/nand/autcpu12.c
7 * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
8 *
9 * Derived from drivers/mtd/spia.c
10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <linux/mtd/mtd.h>
22#include <linux/mtd/nand.h>
23#include <linux/mtd/partitions.h>
24
25#include <asm/io.h>
26#include <asm/sizes.h>
27
28#include <asm/hardware.h>
29#include <asm/arch/board.h>
30#include <asm/arch/gpio.h>
31
32struct at91_nand_host {
33 struct nand_chip nand_chip;
34 struct mtd_info mtd;
35 void __iomem *io_base;
36 struct at91_nand_data *board;
37};
38
39/*
40 * Hardware specific access to control-lines
41 */
42static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
43{
44 struct nand_chip *nand_chip = mtd->priv;
45 struct at91_nand_host *host = nand_chip->priv;
46
47 if (cmd == NAND_CMD_NONE)
48 return;
49
50 if (ctrl & NAND_CLE)
51 writeb(cmd, host->io_base + (1 << host->board->cle));
52 else
53 writeb(cmd, host->io_base + (1 << host->board->ale));
54}
55
56/*
57 * Read the Device Ready pin.
58 */
59static int at91_nand_device_ready(struct mtd_info *mtd)
60{
61 struct nand_chip *nand_chip = mtd->priv;
62 struct at91_nand_host *host = nand_chip->priv;
63
64 return at91_get_gpio_value(host->board->rdy_pin);
65}
66
67/*
68 * Enable NAND.
69 */
70static void at91_nand_enable(struct at91_nand_host *host)
71{
72 if (host->board->enable_pin)
73 at91_set_gpio_value(host->board->enable_pin, 0);
74}
75
76/*
77 * Disable NAND.
78 */
79static void at91_nand_disable(struct at91_nand_host *host)
80{
81 if (host->board->enable_pin)
82 at91_set_gpio_value(host->board->enable_pin, 1);
83}
84
85/*
86 * Probe for the NAND device.
87 */
88static int __init at91_nand_probe(struct platform_device *pdev)
89{
90 struct at91_nand_host *host;
91 struct mtd_info *mtd;
92 struct nand_chip *nand_chip;
93 int res;
94
95#ifdef CONFIG_MTD_PARTITIONS
96 struct mtd_partition *partitions = NULL;
97 int num_partitions = 0;
98#endif
99
100 /* Allocate memory for the device structure (and zero it) */
101 host = kzalloc(sizeof(struct at91_nand_host), GFP_KERNEL);
102 if (!host) {
103 printk(KERN_ERR "at91_nand: failed to allocate device structure.\n");
104 return -ENOMEM;
105 }
106
107 host->io_base = ioremap(pdev->resource[0].start,
108 pdev->resource[0].end - pdev->resource[0].start + 1);
109 if (host->io_base == NULL) {
110 printk(KERN_ERR "at91_nand: ioremap failed\n");
111 kfree(host);
112 return -EIO;
113 }
114
115 mtd = &host->mtd;
116 nand_chip = &host->nand_chip;
117 host->board = pdev->dev.platform_data;
118
119 nand_chip->priv = host; /* link the private data structures */
120 mtd->priv = nand_chip;
121 mtd->owner = THIS_MODULE;
122
123 /* Set address of NAND IO lines */
124 nand_chip->IO_ADDR_R = host->io_base;
125 nand_chip->IO_ADDR_W = host->io_base;
126 nand_chip->cmd_ctrl = at91_nand_cmd_ctrl;
127 nand_chip->dev_ready = at91_nand_device_ready;
128 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */
129 nand_chip->chip_delay = 20; /* 20us command delay time */
130
131 if (host->board->bus_width_16) /* 16-bit bus width */
132 nand_chip->options |= NAND_BUSWIDTH_16;
133
134 platform_set_drvdata(pdev, host);
135 at91_nand_enable(host);
136
137 if (host->board->det_pin) {
138 if (at91_get_gpio_value(host->board->det_pin)) {
139 printk ("No SmartMedia card inserted.\n");
140 res = ENXIO;
141 goto out;
142 }
143 }
144
145 /* Scan to find existance of the device */
146 if (nand_scan(mtd, 1)) {
147 res = -ENXIO;
148 goto out;
149 }
150
151#ifdef CONFIG_MTD_PARTITIONS
152 if (host->board->partition_info)
153 partitions = host->board->partition_info(mtd->size, &num_partitions);
154
155 if ((!partitions) || (num_partitions == 0)) {
156 printk(KERN_ERR "at91_nand: No parititions defined, or unsupported device.\n");
157 res = ENXIO;
158 goto release;
159 }
160
161 res = add_mtd_partitions(mtd, partitions, num_partitions);
162#else
163 res = add_mtd_device(mtd);
164#endif
165
166 if (!res)
167 return res;
168
169release:
170 nand_release(mtd);
171out:
172 at91_nand_disable(host);
173 platform_set_drvdata(pdev, NULL);
174 iounmap(host->io_base);
175 kfree(host);
176 return res;
177}
178
179/*
180 * Remove a NAND device.
181 */
182static int __devexit at91_nand_remove(struct platform_device *pdev)
183{
184 struct at91_nand_host *host = platform_get_drvdata(pdev);
185 struct mtd_info *mtd = &host->mtd;
186
187 nand_release(mtd);
188
189 at91_nand_disable(host);
190
191 iounmap(host->io_base);
192 kfree(host);
193
194 return 0;
195}
196
197static struct platform_driver at91_nand_driver = {
198 .probe = at91_nand_probe,
199 .remove = at91_nand_remove,
200 .driver = {
201 .name = "at91_nand",
202 .owner = THIS_MODULE,
203 },
204};
205
206static int __init at91_nand_init(void)
207{
208 return platform_driver_register(&at91_nand_driver);
209}
210
211
212static void __exit at91_nand_exit(void)
213{
214 platform_driver_unregister(&at91_nand_driver);
215}
216
217
218module_init(at91_nand_init);
219module_exit(at91_nand_exit);
220
221MODULE_LICENSE("GPL");
222MODULE_AUTHOR("Rick Bronson");
223MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200");
diff --git a/drivers/mtd/nand/cafe.c b/drivers/mtd/nand/cafe.c
new file mode 100644
index 000000000000..65f9bd3ceebf
--- /dev/null
+++ b/drivers/mtd/nand/cafe.c
@@ -0,0 +1,771 @@
1/*
2 * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01
3 *
4 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org>
6 */
7
8#define DEBUG
9
10#include <linux/device.h>
11#undef DEBUG
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/nand.h>
14#include <linux/pci.h>
15#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/dma-mapping.h>
18#include <asm/io.h>
19
20#define CAFE_NAND_CTRL1 0x00
21#define CAFE_NAND_CTRL2 0x04
22#define CAFE_NAND_CTRL3 0x08
23#define CAFE_NAND_STATUS 0x0c
24#define CAFE_NAND_IRQ 0x10
25#define CAFE_NAND_IRQ_MASK 0x14
26#define CAFE_NAND_DATA_LEN 0x18
27#define CAFE_NAND_ADDR1 0x1c
28#define CAFE_NAND_ADDR2 0x20
29#define CAFE_NAND_TIMING1 0x24
30#define CAFE_NAND_TIMING2 0x28
31#define CAFE_NAND_TIMING3 0x2c
32#define CAFE_NAND_NONMEM 0x30
33#define CAFE_NAND_ECC_RESULT 0x3C
34#define CAFE_NAND_DMA_CTRL 0x40
35#define CAFE_NAND_DMA_ADDR0 0x44
36#define CAFE_NAND_DMA_ADDR1 0x48
37#define CAFE_NAND_ECC_SYN01 0x50
38#define CAFE_NAND_ECC_SYN23 0x54
39#define CAFE_NAND_ECC_SYN45 0x58
40#define CAFE_NAND_ECC_SYN67 0x5c
41#define CAFE_NAND_READ_DATA 0x1000
42#define CAFE_NAND_WRITE_DATA 0x2000
43
44#define CAFE_GLOBAL_CTRL 0x3004
45#define CAFE_GLOBAL_IRQ 0x3008
46#define CAFE_GLOBAL_IRQ_MASK 0x300c
47#define CAFE_NAND_RESET 0x3034
48
49int cafe_correct_ecc(unsigned char *buf,
50 unsigned short *chk_syndrome_list);
51
52struct cafe_priv {
53 struct nand_chip nand;
54 struct pci_dev *pdev;
55 void __iomem *mmio;
56 uint32_t ctl1;
57 uint32_t ctl2;
58 int datalen;
59 int nr_data;
60 int data_pos;
61 int page_addr;
62 dma_addr_t dmaaddr;
63 unsigned char *dmabuf;
64};
65
66static int usedma = 1;
67module_param(usedma, int, 0644);
68
69static int skipbbt = 0;
70module_param(skipbbt, int, 0644);
71
72static int debug = 0;
73module_param(debug, int, 0644);
74
75static int regdebug = 0;
76module_param(regdebug, int, 0644);
77
78static int checkecc = 1;
79module_param(checkecc, int, 0644);
80
81static int slowtiming = 0;
82module_param(slowtiming, int, 0644);
83
84/* Hrm. Why isn't this already conditional on something in the struct device? */
85#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
86
87/* Make it easier to switch to PIO if we need to */
88#define cafe_readl(cafe, addr) readl((cafe)->mmio + CAFE_##addr)
89#define cafe_writel(cafe, datum, addr) writel(datum, (cafe)->mmio + CAFE_##addr)
90
91static int cafe_device_ready(struct mtd_info *mtd)
92{
93 struct cafe_priv *cafe = mtd->priv;
94 int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
95 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
96
97 cafe_writel(cafe, irqs, NAND_IRQ);
98
99 cafe_dev_dbg(&cafe->pdev->dev, "NAND device is%s ready, IRQ %x (%x) (%x,%x)\n",
100 result?"":" not", irqs, cafe_readl(cafe, NAND_IRQ),
101 cafe_readl(cafe, GLOBAL_IRQ), cafe_readl(cafe, GLOBAL_IRQ_MASK));
102
103 return result;
104}
105
106
107static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
108{
109 struct cafe_priv *cafe = mtd->priv;
110
111 if (usedma)
112 memcpy(cafe->dmabuf + cafe->datalen, buf, len);
113 else
114 memcpy_toio(cafe->mmio + CAFE_NAND_WRITE_DATA + cafe->datalen, buf, len);
115
116 cafe->datalen += len;
117
118 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes to write buffer. datalen 0x%x\n",
119 len, cafe->datalen);
120}
121
122static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
123{
124 struct cafe_priv *cafe = mtd->priv;
125
126 if (usedma)
127 memcpy(buf, cafe->dmabuf + cafe->datalen, len);
128 else
129 memcpy_fromio(buf, cafe->mmio + CAFE_NAND_READ_DATA + cafe->datalen, len);
130
131 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes from position 0x%x in read buffer.\n",
132 len, cafe->datalen);
133 cafe->datalen += len;
134}
135
136static uint8_t cafe_read_byte(struct mtd_info *mtd)
137{
138 struct cafe_priv *cafe = mtd->priv;
139 uint8_t d;
140
141 cafe_read_buf(mtd, &d, 1);
142 cafe_dev_dbg(&cafe->pdev->dev, "Read %02x\n", d);
143
144 return d;
145}
146
147static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
148 int column, int page_addr)
149{
150 struct cafe_priv *cafe = mtd->priv;
151 int adrbytes = 0;
152 uint32_t ctl1;
153 uint32_t doneint = 0x80000000;
154
155 cafe_dev_dbg(&cafe->pdev->dev, "cmdfunc %02x, 0x%x, 0x%x\n",
156 command, column, page_addr);
157
158 if (command == NAND_CMD_ERASE2 || command == NAND_CMD_PAGEPROG) {
159 /* Second half of a command we already calculated */
160 cafe_writel(cafe, cafe->ctl2 | 0x100 | command, NAND_CTRL2);
161 ctl1 = cafe->ctl1;
162 cafe->ctl2 &= ~(1<<30);
163 cafe_dev_dbg(&cafe->pdev->dev, "Continue command, ctl1 %08x, #data %d\n",
164 cafe->ctl1, cafe->nr_data);
165 goto do_command;
166 }
167 /* Reset ECC engine */
168 cafe_writel(cafe, 0, NAND_CTRL2);
169
170 /* Emulate NAND_CMD_READOOB on large-page chips */
171 if (mtd->writesize > 512 &&
172 command == NAND_CMD_READOOB) {
173 column += mtd->writesize;
174 command = NAND_CMD_READ0;
175 }
176
177 /* FIXME: Do we need to send read command before sending data
178 for small-page chips, to position the buffer correctly? */
179
180 if (column != -1) {
181 cafe_writel(cafe, column, NAND_ADDR1);
182 adrbytes = 2;
183 if (page_addr != -1)
184 goto write_adr2;
185 } else if (page_addr != -1) {
186 cafe_writel(cafe, page_addr & 0xffff, NAND_ADDR1);
187 page_addr >>= 16;
188 write_adr2:
189 cafe_writel(cafe, page_addr, NAND_ADDR2);
190 adrbytes += 2;
191 if (mtd->size > mtd->writesize << 16)
192 adrbytes++;
193 }
194
195 cafe->data_pos = cafe->datalen = 0;
196
197 /* Set command valid bit */
198 ctl1 = 0x80000000 | command;
199
200 /* Set RD or WR bits as appropriate */
201 if (command == NAND_CMD_READID || command == NAND_CMD_STATUS) {
202 ctl1 |= (1<<26); /* rd */
203 /* Always 5 bytes, for now */
204 cafe->datalen = 4;
205 /* And one address cycle -- even for STATUS, since the controller doesn't work without */
206 adrbytes = 1;
207 } else if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 ||
208 command == NAND_CMD_READOOB || command == NAND_CMD_RNDOUT) {
209 ctl1 |= 1<<26; /* rd */
210 /* For now, assume just read to end of page */
211 cafe->datalen = mtd->writesize + mtd->oobsize - column;
212 } else if (command == NAND_CMD_SEQIN)
213 ctl1 |= 1<<25; /* wr */
214
215 /* Set number of address bytes */
216 if (adrbytes)
217 ctl1 |= ((adrbytes-1)|8) << 27;
218
219 if (command == NAND_CMD_SEQIN || command == NAND_CMD_ERASE1) {
220 /* Ignore the first command of a pair; the hardware
221 deals with them both at once, later */
222 cafe->ctl1 = ctl1;
223 cafe_dev_dbg(&cafe->pdev->dev, "Setup for delayed command, ctl1 %08x, dlen %x\n",
224 cafe->ctl1, cafe->datalen);
225 return;
226 }
227 /* RNDOUT and READ0 commands need a following byte */
228 if (command == NAND_CMD_RNDOUT)
229 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_RNDOUTSTART, NAND_CTRL2);
230 else if (command == NAND_CMD_READ0 && mtd->writesize > 512)
231 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_READSTART, NAND_CTRL2);
232
233 do_command:
234 cafe_dev_dbg(&cafe->pdev->dev, "dlen %x, ctl1 %x, ctl2 %x\n",
235 cafe->datalen, ctl1, cafe_readl(cafe, NAND_CTRL2));
236
237 /* NB: The datasheet lies -- we really should be subtracting 1 here */
238 cafe_writel(cafe, cafe->datalen, NAND_DATA_LEN);
239 cafe_writel(cafe, 0x90000000, NAND_IRQ);
240 if (usedma && (ctl1 & (3<<25))) {
241 uint32_t dmactl = 0xc0000000 + cafe->datalen;
242 /* If WR or RD bits set, set up DMA */
243 if (ctl1 & (1<<26)) {
244 /* It's a read */
245 dmactl |= (1<<29);
246 /* ... so it's done when the DMA is done, not just
247 the command. */
248 doneint = 0x10000000;
249 }
250 cafe_writel(cafe, dmactl, NAND_DMA_CTRL);
251 }
252 cafe->datalen = 0;
253
254 if (unlikely(regdebug)) {
255 int i;
256 printk("About to write command %08x to register 0\n", ctl1);
257 for (i=4; i< 0x5c; i+=4)
258 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
259 }
260
261 cafe_writel(cafe, ctl1, NAND_CTRL1);
262 /* Apply this short delay always to ensure that we do wait tWB in
263 * any case on any machine. */
264 ndelay(100);
265
266 if (1) {
267 int c = 500000;
268 uint32_t irqs;
269
270 while (c--) {
271 irqs = cafe_readl(cafe, NAND_IRQ);
272 if (irqs & doneint)
273 break;
274 udelay(1);
275 if (!(c % 100000))
276 cafe_dev_dbg(&cafe->pdev->dev, "Wait for ready, IRQ %x\n", irqs);
277 cpu_relax();
278 }
279 cafe_writel(cafe, doneint, NAND_IRQ);
280 cafe_dev_dbg(&cafe->pdev->dev, "Command %x completed after %d usec, irqs %x (%x)\n",
281 command, 500000-c, irqs, cafe_readl(cafe, NAND_IRQ));
282 }
283
284 WARN_ON(cafe->ctl2 & (1<<30));
285
286 switch (command) {
287
288 case NAND_CMD_CACHEDPROG:
289 case NAND_CMD_PAGEPROG:
290 case NAND_CMD_ERASE1:
291 case NAND_CMD_ERASE2:
292 case NAND_CMD_SEQIN:
293 case NAND_CMD_RNDIN:
294 case NAND_CMD_STATUS:
295 case NAND_CMD_DEPLETE1:
296 case NAND_CMD_RNDOUT:
297 case NAND_CMD_STATUS_ERROR:
298 case NAND_CMD_STATUS_ERROR0:
299 case NAND_CMD_STATUS_ERROR1:
300 case NAND_CMD_STATUS_ERROR2:
301 case NAND_CMD_STATUS_ERROR3:
302 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
303 return;
304 }
305 nand_wait_ready(mtd);
306 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
307}
308
309static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
310{
311 //struct cafe_priv *cafe = mtd->priv;
312 // cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr);
313}
314
315static int cafe_nand_interrupt(int irq, void *id)
316{
317 struct mtd_info *mtd = id;
318 struct cafe_priv *cafe = mtd->priv;
319 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
320 cafe_writel(cafe, irqs & ~0x90000000, NAND_IRQ);
321 if (!irqs)
322 return IRQ_NONE;
323
324 cafe_dev_dbg(&cafe->pdev->dev, "irq, bits %x (%x)\n", irqs, cafe_readl(cafe, NAND_IRQ));
325 return IRQ_HANDLED;
326}
327
328static void cafe_nand_bug(struct mtd_info *mtd)
329{
330 BUG();
331}
332
333static int cafe_nand_write_oob(struct mtd_info *mtd,
334 struct nand_chip *chip, int page)
335{
336 int status = 0;
337
338 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page);
339 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
340 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
341 status = chip->waitfunc(mtd, chip);
342
343 return status & NAND_STATUS_FAIL ? -EIO : 0;
344}
345
346/* Don't use -- use nand_read_oob_std for now */
347static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
348 int page, int sndcmd)
349{
350 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
351 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
352 return 1;
353}
354/**
355 * cafe_nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read
356 * @mtd: mtd info structure
357 * @chip: nand chip info structure
358 * @buf: buffer to store read data
359 *
360 * The hw generator calculates the error syndrome automatically. Therefor
361 * we need a special oob layout and handling.
362 */
363static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
364 uint8_t *buf)
365{
366 struct cafe_priv *cafe = mtd->priv;
367
368 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
369 cafe_readl(cafe, NAND_ECC_RESULT),
370 cafe_readl(cafe, NAND_ECC_SYN01));
371
372 chip->read_buf(mtd, buf, mtd->writesize);
373 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
374
375 if (checkecc && cafe_readl(cafe, NAND_ECC_RESULT) & (1<<18)) {
376 unsigned short syn[8];
377 int i;
378
379 for (i=0; i<8; i+=2) {
380 uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2));
381 syn[i] = tmp & 0xfff;
382 syn[i+1] = (tmp >> 16) & 0xfff;
383 }
384
385 if ((i = cafe_correct_ecc(buf, syn)) < 0) {
386 dev_dbg(&cafe->pdev->dev, "Failed to correct ECC at %08x\n",
387 cafe_readl(cafe, NAND_ADDR2) * 2048);
388 for (i=0; i< 0x5c; i+=4)
389 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
390 mtd->ecc_stats.failed++;
391 } else {
392 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", i);
393 mtd->ecc_stats.corrected += i;
394 }
395 }
396
397
398 return 0;
399}
400
401static struct nand_ecclayout cafe_oobinfo_2048 = {
402 .eccbytes = 14,
403 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
404 .oobfree = {{14, 50}}
405};
406
407/* Ick. The BBT code really ought to be able to work this bit out
408 for itself from the above, at least for the 2KiB case */
409static uint8_t cafe_bbt_pattern_2048[] = { 'B', 'b', 't', '0' };
410static uint8_t cafe_mirror_pattern_2048[] = { '1', 't', 'b', 'B' };
411
412static uint8_t cafe_bbt_pattern_512[] = { 0xBB };
413static uint8_t cafe_mirror_pattern_512[] = { 0xBC };
414
415
416static struct nand_bbt_descr cafe_bbt_main_descr_2048 = {
417 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
418 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
419 .offs = 14,
420 .len = 4,
421 .veroffs = 18,
422 .maxblocks = 4,
423 .pattern = cafe_bbt_pattern_2048
424};
425
426static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = {
427 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
428 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
429 .offs = 14,
430 .len = 4,
431 .veroffs = 18,
432 .maxblocks = 4,
433 .pattern = cafe_mirror_pattern_2048
434};
435
436static struct nand_ecclayout cafe_oobinfo_512 = {
437 .eccbytes = 14,
438 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
439 .oobfree = {{14, 2}}
440};
441
442static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
443 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
444 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
445 .offs = 14,
446 .len = 1,
447 .veroffs = 15,
448 .maxblocks = 4,
449 .pattern = cafe_bbt_pattern_512
450};
451
452static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
453 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
454 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
455 .offs = 14,
456 .len = 1,
457 .veroffs = 15,
458 .maxblocks = 4,
459 .pattern = cafe_mirror_pattern_512
460};
461
462
463static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
464 struct nand_chip *chip, const uint8_t *buf)
465{
466 struct cafe_priv *cafe = mtd->priv;
467
468 chip->write_buf(mtd, buf, mtd->writesize);
469 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
470
471 /* Set up ECC autogeneration */
472 cafe->ctl2 |= (1<<30);
473}
474
475static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
476 const uint8_t *buf, int page, int cached, int raw)
477{
478 int status;
479
480 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
481
482 if (unlikely(raw))
483 chip->ecc.write_page_raw(mtd, chip, buf);
484 else
485 chip->ecc.write_page(mtd, chip, buf);
486
487 /*
488 * Cached progamming disabled for now, Not sure if its worth the
489 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s)
490 */
491 cached = 0;
492
493 if (!cached || !(chip->options & NAND_CACHEPRG)) {
494
495 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
496 status = chip->waitfunc(mtd, chip);
497 /*
498 * See if operation failed and additional status checks are
499 * available
500 */
501 if ((status & NAND_STATUS_FAIL) && (chip->errstat))
502 status = chip->errstat(mtd, chip, FL_WRITING, status,
503 page);
504
505 if (status & NAND_STATUS_FAIL)
506 return -EIO;
507 } else {
508 chip->cmdfunc(mtd, NAND_CMD_CACHEDPROG, -1, -1);
509 status = chip->waitfunc(mtd, chip);
510 }
511
512#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
513 /* Send command to read back the data */
514 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
515
516 if (chip->verify_buf(mtd, buf, mtd->writesize))
517 return -EIO;
518#endif
519 return 0;
520}
521
522static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
523{
524 return 0;
525}
526
527static int __devinit cafe_nand_probe(struct pci_dev *pdev,
528 const struct pci_device_id *ent)
529{
530 struct mtd_info *mtd;
531 struct cafe_priv *cafe;
532 uint32_t ctrl;
533 int err = 0;
534
535 err = pci_enable_device(pdev);
536 if (err)
537 return err;
538
539 pci_set_master(pdev);
540
541 mtd = kzalloc(sizeof(*mtd) + sizeof(struct cafe_priv), GFP_KERNEL);
542 if (!mtd) {
543 dev_warn(&pdev->dev, "failed to alloc mtd_info\n");
544 return -ENOMEM;
545 }
546 cafe = (void *)(&mtd[1]);
547
548 mtd->priv = cafe;
549 mtd->owner = THIS_MODULE;
550
551 cafe->pdev = pdev;
552 cafe->mmio = pci_iomap(pdev, 0, 0);
553 if (!cafe->mmio) {
554 dev_warn(&pdev->dev, "failed to iomap\n");
555 err = -ENOMEM;
556 goto out_free_mtd;
557 }
558 cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev, 2112 + sizeof(struct nand_buffers),
559 &cafe->dmaaddr, GFP_KERNEL);
560 if (!cafe->dmabuf) {
561 err = -ENOMEM;
562 goto out_ior;
563 }
564 cafe->nand.buffers = (void *)cafe->dmabuf + 2112;
565
566 cafe->nand.cmdfunc = cafe_nand_cmdfunc;
567 cafe->nand.dev_ready = cafe_device_ready;
568 cafe->nand.read_byte = cafe_read_byte;
569 cafe->nand.read_buf = cafe_read_buf;
570 cafe->nand.write_buf = cafe_write_buf;
571 cafe->nand.select_chip = cafe_select_chip;
572
573 cafe->nand.chip_delay = 0;
574
575 /* Enable the following for a flash based bad block table */
576 cafe->nand.options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR | NAND_OWN_BUFFERS;
577
578 if (skipbbt) {
579 cafe->nand.options |= NAND_SKIP_BBTSCAN;
580 cafe->nand.block_bad = cafe_nand_block_bad;
581 }
582
583 /* Start off by resetting the NAND controller completely */
584 cafe_writel(cafe, 1, NAND_RESET);
585 cafe_writel(cafe, 0, NAND_RESET);
586
587 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
588
589 /* Timings from Marvell's test code (not verified or calculated by us) */
590 if (!slowtiming) {
591 cafe_writel(cafe, 0x01010a0a, NAND_TIMING1);
592 cafe_writel(cafe, 0x24121212, NAND_TIMING2);
593 cafe_writel(cafe, 0x11000000, NAND_TIMING3);
594 } else {
595 cafe_writel(cafe, 0xffffffff, NAND_TIMING1);
596 cafe_writel(cafe, 0xffffffff, NAND_TIMING2);
597 cafe_writel(cafe, 0xffffffff, NAND_TIMING3);
598 }
599 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
600 err = request_irq(pdev->irq, &cafe_nand_interrupt, SA_SHIRQ, "CAFE NAND", mtd);
601 if (err) {
602 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq);
603
604 goto out_free_dma;
605 }
606#if 1
607 /* Disable master reset, enable NAND clock */
608 ctrl = cafe_readl(cafe, GLOBAL_CTRL);
609 ctrl &= 0xffffeff0;
610 ctrl |= 0x00007000;
611 cafe_writel(cafe, ctrl | 0x05, GLOBAL_CTRL);
612 cafe_writel(cafe, ctrl | 0x0a, GLOBAL_CTRL);
613 cafe_writel(cafe, 0, NAND_DMA_CTRL);
614
615 cafe_writel(cafe, 0x7006, GLOBAL_CTRL);
616 cafe_writel(cafe, 0x700a, GLOBAL_CTRL);
617
618 /* Set up DMA address */
619 cafe_writel(cafe, cafe->dmaaddr & 0xffffffff, NAND_DMA_ADDR0);
620 if (sizeof(cafe->dmaaddr) > 4)
621 /* Shift in two parts to shut the compiler up */
622 cafe_writel(cafe, (cafe->dmaaddr >> 16) >> 16, NAND_DMA_ADDR1);
623 else
624 cafe_writel(cafe, 0, NAND_DMA_ADDR1);
625
626 cafe_dev_dbg(&cafe->pdev->dev, "Set DMA address to %x (virt %p)\n",
627 cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
628
629 /* Enable NAND IRQ in global IRQ mask register */
630 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK);
631 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n",
632 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
633#endif
634#if 1
635 mtd->writesize=2048;
636 mtd->oobsize = 0x40;
637 memset(cafe->dmabuf, 0x5a, 2112);
638 cafe->nand.cmdfunc(mtd, NAND_CMD_READID, 0, -1);
639 cafe->nand.read_byte(mtd);
640 cafe->nand.read_byte(mtd);
641 cafe->nand.read_byte(mtd);
642 cafe->nand.read_byte(mtd);
643 cafe->nand.read_byte(mtd);
644#endif
645#if 0
646 cafe->nand.cmdfunc(mtd, NAND_CMD_READ0, 0, 0);
647 // nand_wait_ready(mtd);
648 cafe->nand.read_byte(mtd);
649 cafe->nand.read_byte(mtd);
650 cafe->nand.read_byte(mtd);
651 cafe->nand.read_byte(mtd);
652#endif
653#if 0
654 writel(0x84600070, cafe->mmio);
655 udelay(10);
656 cafe_dev_dbg(&cafe->pdev->dev, "Status %x\n", cafe_readl(cafe, NAND_NONMEM));
657#endif
658 /* Scan to find existance of the device */
659 if (nand_scan_ident(mtd, 1)) {
660 err = -ENXIO;
661 goto out_irq;
662 }
663
664 cafe->ctl2 = 1<<27; /* Reed-Solomon ECC */
665 if (mtd->writesize == 2048)
666 cafe->ctl2 |= 1<<29; /* 2KiB page size */
667
668 /* Set up ECC according to the type of chip we found */
669 if (mtd->writesize == 2048) {
670 cafe->nand.ecc.layout = &cafe_oobinfo_2048;
671 cafe->nand.bbt_td = &cafe_bbt_main_descr_2048;
672 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_2048;
673 } else if (mtd->writesize == 512) {
674 cafe->nand.ecc.layout = &cafe_oobinfo_512;
675 cafe->nand.bbt_td = &cafe_bbt_main_descr_512;
676 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_512;
677 } else {
678 printk(KERN_WARNING "Unexpected NAND flash writesize %d. Aborting\n",
679 mtd->writesize);
680 goto out_irq;
681 }
682 cafe->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
683 cafe->nand.ecc.size = mtd->writesize;
684 cafe->nand.ecc.bytes = 14;
685 cafe->nand.ecc.hwctl = (void *)cafe_nand_bug;
686 cafe->nand.ecc.calculate = (void *)cafe_nand_bug;
687 cafe->nand.ecc.correct = (void *)cafe_nand_bug;
688 cafe->nand.write_page = cafe_nand_write_page;
689 cafe->nand.ecc.write_page = cafe_nand_write_page_lowlevel;
690 cafe->nand.ecc.write_oob = cafe_nand_write_oob;
691 cafe->nand.ecc.read_page = cafe_nand_read_page;
692 cafe->nand.ecc.read_oob = cafe_nand_read_oob;
693
694 err = nand_scan_tail(mtd);
695 if (err)
696 goto out_irq;
697
698 pci_set_drvdata(pdev, mtd);
699 add_mtd_device(mtd);
700 goto out;
701
702 out_irq:
703 /* Disable NAND IRQ in global IRQ mask register */
704 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
705 free_irq(pdev->irq, mtd);
706 out_free_dma:
707 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
708 out_ior:
709 pci_iounmap(pdev, cafe->mmio);
710 out_free_mtd:
711 kfree(mtd);
712 out:
713 return err;
714}
715
716static void __devexit cafe_nand_remove(struct pci_dev *pdev)
717{
718 struct mtd_info *mtd = pci_get_drvdata(pdev);
719 struct cafe_priv *cafe = mtd->priv;
720
721 del_mtd_device(mtd);
722 /* Disable NAND IRQ in global IRQ mask register */
723 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
724 free_irq(pdev->irq, mtd);
725 nand_release(mtd);
726 pci_iounmap(pdev, cafe->mmio);
727 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
728 kfree(mtd);
729}
730
731static struct pci_device_id cafe_nand_tbl[] = {
732 { 0x11ab, 0x4100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MEMORY_FLASH << 8, 0xFFFF0 }
733};
734
735MODULE_DEVICE_TABLE(pci, cafe_nand_tbl);
736
737static struct pci_driver cafe_nand_pci_driver = {
738 .name = "CAFÉ NAND",
739 .id_table = cafe_nand_tbl,
740 .probe = cafe_nand_probe,
741 .remove = __devexit_p(cafe_nand_remove),
742#ifdef CONFIG_PMx
743 .suspend = cafe_nand_suspend,
744 .resume = cafe_nand_resume,
745#endif
746};
747
748static int cafe_nand_init(void)
749{
750 return pci_register_driver(&cafe_nand_pci_driver);
751}
752
753static void cafe_nand_exit(void)
754{
755 pci_unregister_driver(&cafe_nand_pci_driver);
756}
757module_init(cafe_nand_init);
758module_exit(cafe_nand_exit);
759
760MODULE_LICENSE("GPL");
761MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
762MODULE_DESCRIPTION("NAND flash driver for OLPC CAFE chip");
763
764/* Correct ECC for 2048 bytes of 0xff:
765 41 a0 71 65 54 27 f3 93 ec a9 be ed 0b a1 */
766
767/* dwmw2's B-test board, in case of completely screwing it:
768Bad eraseblock 2394 at 0x12b40000
769Bad eraseblock 2627 at 0x14860000
770Bad eraseblock 3349 at 0x1a2a0000
771*/
diff --git a/drivers/mtd/nand/cafe_ecc.c b/drivers/mtd/nand/cafe_ecc.c
new file mode 100644
index 000000000000..1b9fa05a4474
--- /dev/null
+++ b/drivers/mtd/nand/cafe_ecc.c
@@ -0,0 +1,1381 @@
1/* Error correction for CAFÉ NAND controller
2 *
3 * © 2006 Marvell, Inc.
4 * Author: Tom Chiou
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/errno.h>
24
25static unsigned short gf4096_mul(unsigned short, unsigned short);
26static unsigned short gf64_mul(unsigned short, unsigned short);
27static unsigned short gf4096_inv(unsigned short);
28static unsigned short err_pos(unsigned short);
29static void find_4bit_err_coefs(unsigned short, unsigned short, unsigned short,
30 unsigned short, unsigned short, unsigned short,
31 unsigned short, unsigned short, unsigned short *);
32static void zero_4x5_col3(unsigned short[4][5]);
33static void zero_4x5_col2(unsigned short[4][5]);
34static void zero_4x5_col1(unsigned short[4][5]);
35static void swap_4x5_rows(unsigned short[4][5], int, int, int);
36static void swap_2x3_rows(unsigned short m[2][3]);
37static void solve_4x5(unsigned short m[4][5], unsigned short *, int *);
38static void sort_coefs(int *, unsigned short *, int);
39static void find_4bit_err_pats(unsigned short, unsigned short, unsigned short,
40 unsigned short, unsigned short, unsigned short,
41 unsigned short, unsigned short, unsigned short *);
42static void find_3bit_err_coefs(unsigned short, unsigned short, unsigned short,
43 unsigned short, unsigned short, unsigned short,
44 unsigned short *);
45static void zero_3x4_col2(unsigned short[3][4]);
46static void zero_3x4_col1(unsigned short[3][4]);
47static void swap_3x4_rows(unsigned short[3][4], int, int, int);
48static void solve_3x4(unsigned short[3][4], unsigned short *, int *);
49static void find_3bit_err_pats(unsigned short, unsigned short, unsigned short,
50 unsigned short, unsigned short, unsigned short,
51 unsigned short *);
52
53static void find_2bit_err_pats(unsigned short, unsigned short, unsigned short,
54 unsigned short, unsigned short *);
55static void find_2x2_soln(unsigned short, unsigned short, unsigned short,
56 unsigned short, unsigned short, unsigned short,
57 unsigned short *);
58static void solve_2x3(unsigned short[2][3], unsigned short *);
59static int chk_no_err_only(unsigned short *, unsigned short *);
60static int chk_1_err_only(unsigned short *, unsigned short *);
61static int chk_2_err_only(unsigned short *, unsigned short *);
62static int chk_3_err_only(unsigned short *, unsigned short *);
63static int chk_4_err_only(unsigned short *, unsigned short *);
64
65static unsigned short gf64_mul(unsigned short a, unsigned short b)
66{
67 unsigned short tmp1, tmp2, tmp3, tmp4, tmp5;
68 unsigned short c_bit0, c_bit1, c_bit2, c_bit3, c_bit4, c_bit5, c;
69
70 tmp1 = ((a) ^ (a >> 5));
71 tmp2 = ((a >> 4) ^ (a >> 5));
72 tmp3 = ((a >> 3) ^ (a >> 4));
73 tmp4 = ((a >> 2) ^ (a >> 3));
74 tmp5 = ((a >> 1) ^ (a >> 2));
75
76 c_bit0 = ((a & b) ^ ((a >> 5) & (b >> 1)) ^ ((a >> 4) & (b >> 2)) ^
77 ((a >> 3) & (b >> 3)) ^ ((a >> 2) & (b >> 4)) ^ ((a >> 1) & (b >> 5))) & 0x1;
78
79 c_bit1 = (((a >> 1) & b) ^ (tmp1 & (b >> 1)) ^ (tmp2 & (b >> 2)) ^
80 (tmp3 & (b >> 3)) ^ (tmp4 & (b >> 4)) ^ (tmp5 & (b >> 5))) & 0x1;
81
82 c_bit2 = (((a >> 2) & b) ^ ((a >> 1) & (b >> 1)) ^ (tmp1 & (b >> 2)) ^
83 (tmp2 & (b >> 3)) ^ (tmp3 & (b >> 4)) ^ (tmp4 & (b >> 5))) & 0x1;
84
85 c_bit3 = (((a >> 3) & b) ^ ((a >> 2) & (b >> 1)) ^ ((a >> 1) & (b >> 2)) ^
86 (tmp1 & (b >> 3)) ^ (tmp2 & (b >> 4)) ^ (tmp3 & (b >> 5))) & 0x1;
87
88 c_bit4 = (((a >> 4) & b) ^ ((a >> 3) & (b >> 1)) ^ ((a >> 2) & (b >> 2)) ^
89 ((a >> 1) & (b >> 3)) ^ (tmp1 & (b >> 4)) ^ (tmp2 & (b >> 5))) & 0x1;
90
91 c_bit5 = (((a >> 5) & b) ^ ((a >> 4) & (b >> 1)) ^ ((a >> 3) & (b >> 2)) ^
92 ((a >> 2) & (b >> 3)) ^ ((a >> 1) & (b >> 4)) ^ (tmp1 & (b >> 5))) & 0x1;
93
94 c = c_bit0 | (c_bit1 << 1) | (c_bit2 << 2) | (c_bit3 << 3) | (c_bit4 << 4) | (c_bit5 << 5);
95
96 return c;
97}
98
99static unsigned short gf4096_mul(unsigned short a, unsigned short b)
100{
101 unsigned short ah, al, bh, bl, alxah, blxbh, ablh, albl, ahbh, ahbhB, c;
102
103 ah = (a >> 6) & 0x3f;
104 al = a & 0x3f;
105 bh = (b >> 6) & 0x3f;
106 bl = b & 0x3f;
107 alxah = al ^ ah;
108 blxbh = bl ^ bh;
109
110 ablh = gf64_mul(alxah, blxbh);
111 albl = gf64_mul(al, bl);
112 ahbh = gf64_mul(ah, bh);
113
114 ahbhB = ((ahbh & 0x1) << 5) |
115 ((ahbh & 0x20) >> 1) |
116 ((ahbh & 0x10) >> 1) | ((ahbh & 0x8) >> 1) | ((ahbh & 0x4) >> 1) | (((ahbh >> 1) ^ ahbh) & 0x1);
117
118 c = ((ablh ^ albl) << 6) | (ahbhB ^ albl);
119 return c;
120}
121
122static void find_2bit_err_pats(unsigned short s0, unsigned short s1, unsigned short r0, unsigned short r1, unsigned short *pats)
123{
124 find_2x2_soln(0x1, 0x1, r0, r1, s0, s1, pats);
125}
126
127static void find_3bit_err_coefs(unsigned short s0, unsigned short s1,
128 unsigned short s2, unsigned short s3, unsigned short s4, unsigned short s5, unsigned short *coefs)
129{
130 unsigned short m[3][4];
131 int row_order[3];
132
133 row_order[0] = 0;
134 row_order[1] = 1;
135 row_order[2] = 2;
136 m[0][0] = s2;
137 m[0][1] = s1;
138 m[0][2] = s0;
139 m[0][3] = s3;
140 m[1][0] = s3;
141 m[1][1] = s2;
142 m[1][2] = s1;
143 m[1][3] = s4;
144 m[2][0] = s4;
145 m[2][1] = s3;
146 m[2][2] = s2;
147 m[2][3] = s5;
148
149 if (m[0][2] != 0x0) {
150 zero_3x4_col2(m);
151 } else if (m[1][2] != 0x0) {
152 swap_3x4_rows(m, 0, 1, 4);
153 zero_3x4_col2(m);
154 } else if (m[2][2] != 0x0) {
155 swap_3x4_rows(m, 0, 2, 4);
156 zero_3x4_col2(m);
157 } else {
158 printk(KERN_ERR "Error: find_3bit_err_coefs, s0,s1,s2 all zeros!\n");
159 }
160
161 if (m[1][1] != 0x0) {
162 zero_3x4_col1(m);
163 } else if (m[2][1] != 0x0) {
164 swap_3x4_rows(m, 1, 2, 4);
165 zero_3x4_col1(m);
166 } else {
167 printk(KERN_ERR "Error: find_3bit_err_coefs, cannot resolve col 1!\n");
168 }
169
170 /* solve coefs */
171 solve_3x4(m, coefs, row_order);
172}
173
174static void zero_3x4_col2(unsigned short m[3][4])
175{
176 unsigned short minv1, minv2;
177
178 minv1 = gf4096_mul(m[1][2], gf4096_inv(m[0][2]));
179 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[0][2]));
180 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
181 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
182 m[1][3] = m[1][3] ^ gf4096_mul(m[0][3], minv1);
183 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
184 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
185 m[2][3] = m[2][3] ^ gf4096_mul(m[0][3], minv2);
186}
187
188static void zero_3x4_col1(unsigned short m[3][4])
189{
190 unsigned short minv;
191 minv = gf4096_mul(m[2][1], gf4096_inv(m[1][1]));
192 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv);
193 m[2][3] = m[2][3] ^ gf4096_mul(m[1][3], minv);
194}
195
196static void swap_3x4_rows(unsigned short m[3][4], int i, int j, int col_width)
197{
198 unsigned short tmp0;
199 int cnt;
200 for (cnt = 0; cnt < col_width; cnt++) {
201 tmp0 = m[i][cnt];
202 m[i][cnt] = m[j][cnt];
203 m[j][cnt] = tmp0;
204 }
205}
206
207static void solve_3x4(unsigned short m[3][4], unsigned short *coefs, int *row_order)
208{
209 unsigned short tmp[3];
210 tmp[0] = gf4096_mul(m[2][3], gf4096_inv(m[2][0]));
211 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ m[1][3]), gf4096_inv(m[1][1]));
212 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^ gf4096_mul(tmp[1], m[0][1]) ^ m[0][3]), gf4096_inv(m[0][2]));
213 sort_coefs(row_order, tmp, 3);
214 coefs[0] = tmp[0];
215 coefs[1] = tmp[1];
216 coefs[2] = tmp[2];
217}
218
219static void find_3bit_err_pats(unsigned short s0, unsigned short s1,
220 unsigned short s2, unsigned short r0,
221 unsigned short r1, unsigned short r2,
222 unsigned short *pats)
223{
224 find_2x2_soln(r0 ^ r2, r1 ^ r2,
225 gf4096_mul(r0, r0 ^ r2), gf4096_mul(r1, r1 ^ r2),
226 gf4096_mul(s0, r2) ^ s1, gf4096_mul(s1, r2) ^ s2, pats);
227 pats[2] = s0 ^ pats[0] ^ pats[1];
228}
229
230static void find_4bit_err_coefs(unsigned short s0, unsigned short s1,
231 unsigned short s2, unsigned short s3,
232 unsigned short s4, unsigned short s5,
233 unsigned short s6, unsigned short s7,
234 unsigned short *coefs)
235{
236 unsigned short m[4][5];
237 int row_order[4];
238
239 row_order[0] = 0;
240 row_order[1] = 1;
241 row_order[2] = 2;
242 row_order[3] = 3;
243
244 m[0][0] = s3;
245 m[0][1] = s2;
246 m[0][2] = s1;
247 m[0][3] = s0;
248 m[0][4] = s4;
249 m[1][0] = s4;
250 m[1][1] = s3;
251 m[1][2] = s2;
252 m[1][3] = s1;
253 m[1][4] = s5;
254 m[2][0] = s5;
255 m[2][1] = s4;
256 m[2][2] = s3;
257 m[2][3] = s2;
258 m[2][4] = s6;
259 m[3][0] = s6;
260 m[3][1] = s5;
261 m[3][2] = s4;
262 m[3][3] = s3;
263 m[3][4] = s7;
264
265 if (m[0][3] != 0x0) {
266 zero_4x5_col3(m);
267 } else if (m[1][3] != 0x0) {
268 swap_4x5_rows(m, 0, 1, 5);
269 zero_4x5_col3(m);
270 } else if (m[2][3] != 0x0) {
271 swap_4x5_rows(m, 0, 2, 5);
272 zero_4x5_col3(m);
273 } else if (m[3][3] != 0x0) {
274 swap_4x5_rows(m, 0, 3, 5);
275 zero_4x5_col3(m);
276 } else {
277 printk(KERN_ERR "Error: find_4bit_err_coefs, s0,s1,s2,s3 all zeros!\n");
278 }
279
280 if (m[1][2] != 0x0) {
281 zero_4x5_col2(m);
282 } else if (m[2][2] != 0x0) {
283 swap_4x5_rows(m, 1, 2, 5);
284 zero_4x5_col2(m);
285 } else if (m[3][2] != 0x0) {
286 swap_4x5_rows(m, 1, 3, 5);
287 zero_4x5_col2(m);
288 } else {
289 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 2!\n");
290 }
291
292 if (m[2][1] != 0x0) {
293 zero_4x5_col1(m);
294 } else if (m[3][1] != 0x0) {
295 swap_4x5_rows(m, 2, 3, 5);
296 zero_4x5_col1(m);
297 } else {
298 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 1!\n");
299 }
300
301 solve_4x5(m, coefs, row_order);
302}
303
304static void zero_4x5_col3(unsigned short m[4][5])
305{
306 unsigned short minv1, minv2, minv3;
307
308 minv1 = gf4096_mul(m[1][3], gf4096_inv(m[0][3]));
309 minv2 = gf4096_mul(m[2][3], gf4096_inv(m[0][3]));
310 minv3 = gf4096_mul(m[3][3], gf4096_inv(m[0][3]));
311
312 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
313 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
314 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv1);
315 m[1][4] = m[1][4] ^ gf4096_mul(m[0][4], minv1);
316 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
317 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
318 m[2][2] = m[2][2] ^ gf4096_mul(m[0][2], minv2);
319 m[2][4] = m[2][4] ^ gf4096_mul(m[0][4], minv2);
320 m[3][0] = m[3][0] ^ gf4096_mul(m[0][0], minv3);
321 m[3][1] = m[3][1] ^ gf4096_mul(m[0][1], minv3);
322 m[3][2] = m[3][2] ^ gf4096_mul(m[0][2], minv3);
323 m[3][4] = m[3][4] ^ gf4096_mul(m[0][4], minv3);
324}
325
326static void zero_4x5_col2(unsigned short m[4][5])
327{
328 unsigned short minv2, minv3;
329
330 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[1][2]));
331 minv3 = gf4096_mul(m[3][2], gf4096_inv(m[1][2]));
332
333 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv2);
334 m[2][1] = m[2][1] ^ gf4096_mul(m[1][1], minv2);
335 m[2][4] = m[2][4] ^ gf4096_mul(m[1][4], minv2);
336 m[3][0] = m[3][0] ^ gf4096_mul(m[1][0], minv3);
337 m[3][1] = m[3][1] ^ gf4096_mul(m[1][1], minv3);
338 m[3][4] = m[3][4] ^ gf4096_mul(m[1][4], minv3);
339}
340
341static void zero_4x5_col1(unsigned short m[4][5])
342{
343 unsigned short minv;
344
345 minv = gf4096_mul(m[3][1], gf4096_inv(m[2][1]));
346
347 m[3][0] = m[3][0] ^ gf4096_mul(m[2][0], minv);
348 m[3][4] = m[3][4] ^ gf4096_mul(m[2][4], minv);
349}
350
351static void swap_4x5_rows(unsigned short m[4][5], int i, int j, int col_width)
352{
353 unsigned short tmp0;
354 int cnt;
355
356 for (cnt = 0; cnt < col_width; cnt++) {
357 tmp0 = m[i][cnt];
358 m[i][cnt] = m[j][cnt];
359 m[j][cnt] = tmp0;
360 }
361}
362
363static void solve_4x5(unsigned short m[4][5], unsigned short *coefs, int *row_order)
364{
365 unsigned short tmp[4];
366
367 tmp[0] = gf4096_mul(m[3][4], gf4096_inv(m[3][0]));
368 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[2][0]) ^ m[2][4]), gf4096_inv(m[2][1]));
369 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ gf4096_mul(tmp[1], m[1][1]) ^ m[1][4]), gf4096_inv(m[1][2]));
370 tmp[3] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^
371 gf4096_mul(tmp[1], m[0][1]) ^ gf4096_mul(tmp[2], m[0][2]) ^ m[0][4]), gf4096_inv(m[0][3]));
372 sort_coefs(row_order, tmp, 4);
373 coefs[0] = tmp[0];
374 coefs[1] = tmp[1];
375 coefs[2] = tmp[2];
376 coefs[3] = tmp[3];
377}
378
379static void sort_coefs(int *order, unsigned short *soln, int len)
380{
381 int cnt, start_cnt, least_ord, least_cnt;
382 unsigned short tmp0;
383 for (start_cnt = 0; start_cnt < len; start_cnt++) {
384 for (cnt = start_cnt; cnt < len; cnt++) {
385 if (cnt == start_cnt) {
386 least_ord = order[cnt];
387 least_cnt = start_cnt;
388 } else {
389 if (least_ord > order[cnt]) {
390 least_ord = order[cnt];
391 least_cnt = cnt;
392 }
393 }
394 }
395 if (least_cnt != start_cnt) {
396 tmp0 = order[least_cnt];
397 order[least_cnt] = order[start_cnt];
398 order[start_cnt] = tmp0;
399 tmp0 = soln[least_cnt];
400 soln[least_cnt] = soln[start_cnt];
401 soln[start_cnt] = tmp0;
402 }
403 }
404}
405
406static void find_4bit_err_pats(unsigned short s0, unsigned short s1,
407 unsigned short s2, unsigned short s3,
408 unsigned short z1, unsigned short z2,
409 unsigned short z3, unsigned short z4,
410 unsigned short *pats)
411{
412 unsigned short z4_z1, z3z4_z3z3, z4_z2, s0z4_s1, z1z4_z1z1,
413 z4_z3, z2z4_z2z2, s1z4_s2, z3z3z4_z3z3z3, z1z1z4_z1z1z1, z2z2z4_z2z2z2, s2z4_s3;
414 unsigned short tmp0, tmp1, tmp2, tmp3;
415
416 z4_z1 = z4 ^ z1;
417 z3z4_z3z3 = gf4096_mul(z3, z4) ^ gf4096_mul(z3, z3);
418 z4_z2 = z4 ^ z2;
419 s0z4_s1 = gf4096_mul(s0, z4) ^ s1;
420 z1z4_z1z1 = gf4096_mul(z1, z4) ^ gf4096_mul(z1, z1);
421 z4_z3 = z4 ^ z3;
422 z2z4_z2z2 = gf4096_mul(z2, z4) ^ gf4096_mul(z2, z2);
423 s1z4_s2 = gf4096_mul(s1, z4) ^ s2;
424 z3z3z4_z3z3z3 = gf4096_mul(gf4096_mul(z3, z3), z4) ^ gf4096_mul(gf4096_mul(z3, z3), z3);
425 z1z1z4_z1z1z1 = gf4096_mul(gf4096_mul(z1, z1), z4) ^ gf4096_mul(gf4096_mul(z1, z1), z1);
426 z2z2z4_z2z2z2 = gf4096_mul(gf4096_mul(z2, z2), z4) ^ gf4096_mul(gf4096_mul(z2, z2), z2);
427 s2z4_s3 = gf4096_mul(s2, z4) ^ s3;
428
429 //find err pat 0,1
430 find_2x2_soln(gf4096_mul(z4_z1, z3z4_z3z3) ^
431 gf4096_mul(z1z4_z1z1, z4_z3), gf4096_mul(z4_z2,
432 z3z4_z3z3) ^
433 gf4096_mul(z2z4_z2z2, z4_z3), gf4096_mul(z1z4_z1z1,
434 z3z3z4_z3z3z3) ^
435 gf4096_mul(z1z1z4_z1z1z1, z3z4_z3z3),
436 gf4096_mul(z2z4_z2z2,
437 z3z3z4_z3z3z3) ^ gf4096_mul(z2z2z4_z2z2z2,
438 z3z4_z3z3),
439 gf4096_mul(s0z4_s1, z3z4_z3z3) ^ gf4096_mul(s1z4_s2,
440 z4_z3),
441 gf4096_mul(s1z4_s2, z3z3z4_z3z3z3) ^ gf4096_mul(s2z4_s3, z3z4_z3z3), pats);
442 tmp0 = pats[0];
443 tmp1 = pats[1];
444 tmp2 = pats[0] ^ pats[1] ^ s0;
445 tmp3 = gf4096_mul(pats[0], z1) ^ gf4096_mul(pats[1], z2) ^ s1;
446
447 //find err pat 2,3
448 find_2x2_soln(0x1, 0x1, z3, z4, tmp2, tmp3, pats);
449 pats[2] = pats[0];
450 pats[3] = pats[1];
451 pats[0] = tmp0;
452 pats[1] = tmp1;
453}
454
455static void find_2x2_soln(unsigned short c00, unsigned short c01,
456 unsigned short c10, unsigned short c11,
457 unsigned short lval0, unsigned short lval1,
458 unsigned short *soln)
459{
460 unsigned short m[2][3];
461 m[0][0] = c00;
462 m[0][1] = c01;
463 m[0][2] = lval0;
464 m[1][0] = c10;
465 m[1][1] = c11;
466 m[1][2] = lval1;
467
468 if (m[0][1] != 0x0) {
469 /* */
470 } else if (m[1][1] != 0x0) {
471 swap_2x3_rows(m);
472 } else {
473 printk(KERN_ERR "Warning: find_2bit_err_coefs, s0,s1 all zeros!\n");
474 }
475
476 solve_2x3(m, soln);
477}
478
479static void swap_2x3_rows(unsigned short m[2][3])
480{
481 unsigned short tmp0;
482 int cnt;
483
484 for (cnt = 0; cnt < 3; cnt++) {
485 tmp0 = m[0][cnt];
486 m[0][cnt] = m[1][cnt];
487 m[1][cnt] = tmp0;
488 }
489}
490
491static void solve_2x3(unsigned short m[2][3], unsigned short *coefs)
492{
493 unsigned short minv;
494
495 minv = gf4096_mul(m[1][1], gf4096_inv(m[0][1]));
496 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv);
497 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv);
498 coefs[0] = gf4096_mul(m[1][2], gf4096_inv(m[1][0]));
499 coefs[1] = gf4096_mul((gf4096_mul(coefs[0], m[0][0]) ^ m[0][2]), gf4096_inv(m[0][1]));
500}
501
502static unsigned char gf64_inv[64] = {
503 0, 1, 33, 62, 49, 43, 31, 44, 57, 37, 52, 28, 46, 40, 22, 25,
504 61, 54, 51, 39, 26, 35, 14, 24, 23, 15, 20, 34, 11, 53, 45, 6,
505 63, 2, 27, 21, 56, 9, 50, 19, 13, 47, 48, 5, 7, 30, 12, 41,
506 42, 4, 38, 18, 10, 29, 17, 60, 36, 8, 59, 58, 55, 16, 3, 32
507};
508
509static unsigned short gf4096_inv(unsigned short din)
510{
511 unsigned short alahxal, ah2B, deno, inv, bl, bh;
512 unsigned short ah, al, ahxal;
513 unsigned short dout;
514
515 ah = (din >> 6) & 0x3f;
516 al = din & 0x3f;
517 ahxal = ah ^ al;
518 ah2B = (((ah ^ (ah >> 3)) & 0x1) << 5) |
519 ((ah >> 1) & 0x10) |
520 ((((ah >> 5) ^ (ah >> 2)) & 0x1) << 3) |
521 ((ah >> 2) & 0x4) | ((((ah >> 4) ^ (ah >> 1)) & 0x1) << 1) | (ah & 0x1);
522 alahxal = gf64_mul(ahxal, al);
523 deno = alahxal ^ ah2B;
524 inv = gf64_inv[deno];
525 bl = gf64_mul(inv, ahxal);
526 bh = gf64_mul(inv, ah);
527 dout = ((bh & 0x3f) << 6) | (bl & 0x3f);
528 return (((bh & 0x3f) << 6) | (bl & 0x3f));
529}
530
531static unsigned short err_pos_lut[4096] = {
532 0xfff, 0x000, 0x451, 0xfff, 0xfff, 0x3cf, 0xfff, 0x041,
533 0xfff, 0xfff, 0xfff, 0xfff, 0x28a, 0xfff, 0x492, 0xfff,
534 0x145, 0xfff, 0xfff, 0x514, 0xfff, 0x082, 0xfff, 0xfff,
535 0xfff, 0x249, 0x38e, 0x410, 0xfff, 0x104, 0x208, 0x1c7,
536 0xfff, 0xfff, 0xfff, 0xfff, 0x2cb, 0xfff, 0xfff, 0xfff,
537 0x0c3, 0x34d, 0x4d3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
538 0xfff, 0xfff, 0xfff, 0x186, 0xfff, 0xfff, 0xfff, 0xfff,
539 0xfff, 0x30c, 0x555, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
540 0xfff, 0xfff, 0xfff, 0x166, 0xfff, 0xfff, 0xfff, 0xfff,
541 0x385, 0x14e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e1,
542 0xfff, 0xfff, 0xfff, 0xfff, 0x538, 0xfff, 0x16d, 0xfff,
543 0xfff, 0xfff, 0x45b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
544 0xfff, 0xfff, 0xfff, 0x29c, 0x2cc, 0x30b, 0x2b3, 0xfff,
545 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0b3, 0xfff, 0x2f7,
546 0xfff, 0x32b, 0xfff, 0xfff, 0xfff, 0xfff, 0x0a7, 0xfff,
547 0xfff, 0x2da, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
548 0xfff, 0x07e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
549 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x11c, 0xfff, 0xfff,
550 0xfff, 0xfff, 0xfff, 0x22f, 0xfff, 0x1f4, 0xfff, 0xfff,
551 0x2b0, 0x504, 0xfff, 0x114, 0xfff, 0xfff, 0xfff, 0x21d,
552 0xfff, 0xfff, 0xfff, 0xfff, 0x00d, 0x3c4, 0x340, 0x10f,
553 0xfff, 0xfff, 0x266, 0x02e, 0xfff, 0xfff, 0xfff, 0x4f8,
554 0x337, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
555 0xfff, 0xfff, 0xfff, 0x07b, 0x168, 0xfff, 0xfff, 0x0fe,
556 0xfff, 0xfff, 0x51a, 0xfff, 0x458, 0xfff, 0x36d, 0xfff,
557 0xfff, 0xfff, 0xfff, 0x073, 0x37d, 0x415, 0x550, 0xfff,
558 0xfff, 0xfff, 0x23b, 0x4b4, 0xfff, 0xfff, 0xfff, 0x1a1,
559 0xfff, 0xfff, 0x3aa, 0xfff, 0x117, 0x04d, 0x341, 0xfff,
560 0xfff, 0xfff, 0xfff, 0x518, 0x03e, 0x0f2, 0xfff, 0xfff,
561 0xfff, 0xfff, 0xfff, 0x363, 0xfff, 0x0b9, 0xfff, 0xfff,
562 0x241, 0xfff, 0xfff, 0x049, 0xfff, 0xfff, 0xfff, 0xfff,
563 0x15f, 0x52d, 0xfff, 0xfff, 0xfff, 0x29e, 0xfff, 0xfff,
564 0xfff, 0xfff, 0x4cf, 0x0fc, 0xfff, 0x36f, 0x3d3, 0xfff,
565 0x228, 0xfff, 0xfff, 0x45e, 0xfff, 0xfff, 0xfff, 0xfff,
566 0x238, 0xfff, 0xfff, 0xfff, 0xfff, 0x47f, 0xfff, 0xfff,
567 0x43a, 0x265, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e8,
568 0xfff, 0xfff, 0x01a, 0xfff, 0xfff, 0xfff, 0xfff, 0x21e,
569 0x1fc, 0x40b, 0xfff, 0xfff, 0xfff, 0x2d0, 0x159, 0xfff,
570 0xfff, 0x313, 0xfff, 0xfff, 0x05c, 0x4cc, 0xfff, 0xfff,
571 0x0f6, 0x3d5, 0xfff, 0xfff, 0xfff, 0x54f, 0xfff, 0xfff,
572 0xfff, 0x172, 0x1e4, 0x07c, 0xfff, 0xfff, 0xfff, 0xfff,
573 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x53c, 0x1ad, 0x535,
574 0x19b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
575 0xfff, 0xfff, 0x092, 0xfff, 0x2be, 0xfff, 0xfff, 0x482,
576 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0e6, 0xfff, 0xfff,
577 0xfff, 0xfff, 0xfff, 0x476, 0xfff, 0x51d, 0xfff, 0xfff,
578 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
579 0xfff, 0xfff, 0x342, 0x2b5, 0x22e, 0x09a, 0xfff, 0x08d,
580 0x44f, 0x3ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d1, 0xfff,
581 0xfff, 0x543, 0xfff, 0x48f, 0xfff, 0x3d2, 0xfff, 0x0d5,
582 0x113, 0x0ec, 0x427, 0xfff, 0xfff, 0xfff, 0x4c4, 0xfff,
583 0xfff, 0x50a, 0xfff, 0x144, 0xfff, 0x105, 0x39f, 0x294,
584 0x164, 0xfff, 0x31a, 0xfff, 0xfff, 0x49a, 0xfff, 0x130,
585 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
586 0x1be, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
587 0xfff, 0xfff, 0x49e, 0x371, 0xfff, 0xfff, 0xfff, 0xfff,
588 0xfff, 0xfff, 0xfff, 0xfff, 0x0e8, 0x49c, 0x0f4, 0xfff,
589 0x338, 0x1a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
590 0xfff, 0x36c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
591 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
592 0xfff, 0x1ae, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
593 0xfff, 0x31b, 0xfff, 0xfff, 0x2dd, 0x522, 0xfff, 0xfff,
594 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f4,
595 0x3c6, 0x30d, 0xfff, 0xfff, 0xfff, 0xfff, 0x34c, 0x18f,
596 0x30a, 0xfff, 0x01f, 0x079, 0xfff, 0xfff, 0x54d, 0x46b,
597 0x28c, 0x37f, 0xfff, 0xfff, 0xfff, 0xfff, 0x355, 0xfff,
598 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x14f, 0xfff, 0xfff,
599 0xfff, 0xfff, 0xfff, 0x359, 0x3fe, 0x3c5, 0xfff, 0xfff,
600 0xfff, 0xfff, 0x423, 0xfff, 0xfff, 0x34a, 0x22c, 0xfff,
601 0x25a, 0xfff, 0xfff, 0x4ad, 0xfff, 0x28d, 0xfff, 0xfff,
602 0xfff, 0xfff, 0xfff, 0x547, 0xfff, 0xfff, 0xfff, 0xfff,
603 0x2e2, 0xfff, 0xfff, 0x1d5, 0xfff, 0x2a8, 0xfff, 0xfff,
604 0x03f, 0xfff, 0xfff, 0xfff, 0xfff, 0x3eb, 0x0fa, 0xfff,
605 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x55b, 0xfff,
606 0x08e, 0xfff, 0x3ae, 0xfff, 0x3a4, 0xfff, 0x282, 0x158,
607 0xfff, 0x382, 0xfff, 0xfff, 0x499, 0xfff, 0xfff, 0x08a,
608 0xfff, 0xfff, 0xfff, 0x456, 0x3be, 0xfff, 0x1e2, 0xfff,
609 0xfff, 0xfff, 0xfff, 0xfff, 0x559, 0xfff, 0x1a0, 0xfff,
610 0xfff, 0x0b4, 0xfff, 0xfff, 0xfff, 0x2df, 0xfff, 0xfff,
611 0xfff, 0x07f, 0x4f5, 0xfff, 0xfff, 0x27c, 0x133, 0x017,
612 0xfff, 0x3fd, 0xfff, 0xfff, 0xfff, 0x44d, 0x4cd, 0x17a,
613 0x0d7, 0x537, 0xfff, 0xfff, 0x353, 0xfff, 0xfff, 0x351,
614 0x366, 0xfff, 0x44a, 0xfff, 0x1a6, 0xfff, 0xfff, 0xfff,
615 0x291, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1e3,
616 0xfff, 0xfff, 0xfff, 0xfff, 0x389, 0xfff, 0x07a, 0xfff,
617 0x1b6, 0x2ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x24e, 0x074,
618 0xfff, 0xfff, 0x3dc, 0xfff, 0x4e3, 0xfff, 0xfff, 0xfff,
619 0xfff, 0x4eb, 0xfff, 0xfff, 0x3b8, 0x4de, 0xfff, 0x19c,
620 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x262,
621 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x076, 0x4e8, 0x3da,
622 0xfff, 0x531, 0xfff, 0xfff, 0x14a, 0xfff, 0x0a2, 0x433,
623 0x3df, 0x1e9, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e7, 0x285,
624 0x2d8, 0xfff, 0xfff, 0xfff, 0x349, 0x18d, 0x098, 0xfff,
625 0x0df, 0x4bf, 0xfff, 0xfff, 0x0b2, 0xfff, 0x346, 0x24d,
626 0xfff, 0xfff, 0xfff, 0x24f, 0x4fa, 0x2f9, 0xfff, 0xfff,
627 0x3c9, 0xfff, 0x2b4, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
628 0xfff, 0x056, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
629 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
630 0xfff, 0x179, 0xfff, 0x0e9, 0x3f0, 0x33d, 0xfff, 0xfff,
631 0xfff, 0xfff, 0xfff, 0x1fd, 0xfff, 0xfff, 0x526, 0xfff,
632 0xfff, 0xfff, 0x53d, 0xfff, 0xfff, 0xfff, 0x170, 0x331,
633 0xfff, 0x068, 0xfff, 0xfff, 0xfff, 0x3f7, 0xfff, 0x3d8,
634 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
635 0xfff, 0x09f, 0x556, 0xfff, 0xfff, 0x02d, 0xfff, 0xfff,
636 0x553, 0xfff, 0xfff, 0xfff, 0x1f0, 0xfff, 0xfff, 0x4d6,
637 0x41e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d5, 0xfff, 0xfff,
638 0xfff, 0xfff, 0xfff, 0x248, 0xfff, 0xfff, 0xfff, 0x0a3,
639 0xfff, 0x217, 0xfff, 0xfff, 0xfff, 0x4f1, 0x209, 0xfff,
640 0xfff, 0x475, 0x234, 0x52b, 0x398, 0xfff, 0x08b, 0xfff,
641 0xfff, 0xfff, 0xfff, 0x2c2, 0xfff, 0xfff, 0xfff, 0xfff,
642 0xfff, 0xfff, 0x268, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
643 0xfff, 0x4a3, 0xfff, 0x0aa, 0xfff, 0x1d9, 0xfff, 0xfff,
644 0xfff, 0xfff, 0x155, 0xfff, 0xfff, 0xfff, 0xfff, 0x0bf,
645 0x539, 0xfff, 0xfff, 0x2f1, 0x545, 0xfff, 0xfff, 0xfff,
646 0xfff, 0xfff, 0xfff, 0x2a7, 0x06f, 0xfff, 0x378, 0xfff,
647 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x25e, 0xfff,
648 0xfff, 0xfff, 0xfff, 0x15d, 0x02a, 0xfff, 0xfff, 0x0bc,
649 0x235, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
650 0x150, 0xfff, 0x1a9, 0xfff, 0xfff, 0xfff, 0xfff, 0x381,
651 0xfff, 0x04e, 0x270, 0x13f, 0xfff, 0xfff, 0x405, 0xfff,
652 0x3cd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
653 0xfff, 0x2ef, 0xfff, 0x06a, 0xfff, 0xfff, 0xfff, 0x34f,
654 0x212, 0xfff, 0xfff, 0x0e2, 0xfff, 0x083, 0x298, 0xfff,
655 0xfff, 0xfff, 0x0c2, 0xfff, 0xfff, 0x52e, 0xfff, 0x488,
656 0xfff, 0xfff, 0xfff, 0x36b, 0xfff, 0xfff, 0xfff, 0x442,
657 0x091, 0xfff, 0x41c, 0xfff, 0xfff, 0x3a5, 0xfff, 0x4e6,
658 0xfff, 0xfff, 0x40d, 0x31d, 0xfff, 0xfff, 0xfff, 0x4c1,
659 0x053, 0xfff, 0x418, 0x13c, 0xfff, 0x350, 0xfff, 0x0ae,
660 0xfff, 0xfff, 0x41f, 0xfff, 0x470, 0xfff, 0x4ca, 0xfff,
661 0xfff, 0xfff, 0x02b, 0x450, 0xfff, 0x1f8, 0xfff, 0xfff,
662 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x293, 0xfff,
663 0xfff, 0xfff, 0xfff, 0x411, 0xfff, 0xfff, 0xfff, 0xfff,
664 0xfff, 0xfff, 0xfff, 0xfff, 0x0b8, 0xfff, 0xfff, 0xfff,
665 0x3e1, 0xfff, 0xfff, 0xfff, 0xfff, 0x43c, 0xfff, 0x2b2,
666 0x2ab, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ec,
667 0xfff, 0xfff, 0xfff, 0x3f8, 0x034, 0xfff, 0xfff, 0xfff,
668 0xfff, 0xfff, 0xfff, 0x11a, 0xfff, 0x541, 0x45c, 0x134,
669 0x1cc, 0xfff, 0xfff, 0xfff, 0x469, 0xfff, 0xfff, 0x44b,
670 0x161, 0xfff, 0xfff, 0xfff, 0x055, 0xfff, 0xfff, 0xfff,
671 0xfff, 0x307, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d1, 0xfff,
672 0xfff, 0xfff, 0x124, 0x37b, 0x26b, 0x336, 0xfff, 0xfff,
673 0x2e4, 0x3cb, 0xfff, 0xfff, 0x0f8, 0x3c8, 0xfff, 0xfff,
674 0xfff, 0x461, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4b5,
675 0x2cf, 0xfff, 0xfff, 0xfff, 0x20f, 0xfff, 0x35a, 0xfff,
676 0x490, 0xfff, 0x185, 0xfff, 0xfff, 0xfff, 0xfff, 0x42e,
677 0xfff, 0xfff, 0xfff, 0xfff, 0x54b, 0xfff, 0xfff, 0xfff,
678 0x146, 0xfff, 0x412, 0xfff, 0xfff, 0xfff, 0x1ff, 0xfff,
679 0xfff, 0x3e0, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d5, 0xfff,
680 0x4df, 0x505, 0xfff, 0x413, 0xfff, 0x1a5, 0xfff, 0x3b2,
681 0xfff, 0xfff, 0xfff, 0x35b, 0xfff, 0x116, 0xfff, 0xfff,
682 0x171, 0x4d0, 0xfff, 0x154, 0x12d, 0xfff, 0xfff, 0xfff,
683 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x468, 0x4db, 0xfff,
684 0xfff, 0x1df, 0xfff, 0xfff, 0xfff, 0xfff, 0x05a, 0xfff,
685 0x0f1, 0x403, 0xfff, 0x22b, 0x2e0, 0xfff, 0xfff, 0xfff,
686 0x2b7, 0x373, 0xfff, 0xfff, 0xfff, 0xfff, 0x13e, 0xfff,
687 0xfff, 0xfff, 0x0d0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
688 0x329, 0x1d2, 0x3fa, 0x047, 0xfff, 0x2f2, 0xfff, 0xfff,
689 0x141, 0x0ac, 0x1d7, 0xfff, 0x07d, 0xfff, 0xfff, 0xfff,
690 0x1c1, 0xfff, 0x487, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
691 0xfff, 0xfff, 0xfff, 0x045, 0xfff, 0xfff, 0xfff, 0xfff,
692 0x288, 0x0cd, 0xfff, 0xfff, 0xfff, 0xfff, 0x226, 0x1d8,
693 0xfff, 0x153, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4cb,
694 0x528, 0xfff, 0xfff, 0xfff, 0x20a, 0x343, 0x3a1, 0xfff,
695 0xfff, 0xfff, 0x2d7, 0x2d3, 0x1aa, 0x4c5, 0xfff, 0xfff,
696 0xfff, 0x42b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
697 0xfff, 0xfff, 0xfff, 0xfff, 0x3e9, 0xfff, 0x20b, 0x260,
698 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x37c, 0x2fd,
699 0xfff, 0xfff, 0x2c8, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
700 0xfff, 0x31e, 0xfff, 0x335, 0xfff, 0xfff, 0xfff, 0xfff,
701 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
702 0xfff, 0xfff, 0x135, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
703 0xfff, 0xfff, 0x35c, 0x4dd, 0x129, 0xfff, 0xfff, 0xfff,
704 0xfff, 0xfff, 0x1ef, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
705 0xfff, 0x34e, 0xfff, 0xfff, 0xfff, 0xfff, 0x407, 0xfff,
706 0xfff, 0xfff, 0xfff, 0xfff, 0x3ad, 0xfff, 0xfff, 0xfff,
707 0x379, 0xfff, 0xfff, 0x1d0, 0x38d, 0xfff, 0xfff, 0x1e8,
708 0x184, 0x3c1, 0x1c4, 0xfff, 0x1f9, 0xfff, 0xfff, 0x424,
709 0xfff, 0xfff, 0xfff, 0xfff, 0x1d3, 0x0d4, 0xfff, 0x4e9,
710 0xfff, 0xfff, 0xfff, 0x530, 0x107, 0xfff, 0x106, 0x04f,
711 0xfff, 0xfff, 0x4c7, 0x503, 0xfff, 0xfff, 0xfff, 0xfff,
712 0xfff, 0x15c, 0xfff, 0x23f, 0xfff, 0xfff, 0xfff, 0xfff,
713 0xfff, 0xfff, 0xfff, 0xfff, 0x4f3, 0xfff, 0xfff, 0x3c7,
714 0xfff, 0x278, 0xfff, 0xfff, 0x0a6, 0xfff, 0xfff, 0xfff,
715 0x122, 0x1cf, 0xfff, 0x327, 0xfff, 0x2e5, 0xfff, 0x29d,
716 0xfff, 0xfff, 0x3f1, 0xfff, 0xfff, 0x48d, 0xfff, 0xfff,
717 0xfff, 0xfff, 0x054, 0xfff, 0xfff, 0xfff, 0xfff, 0x178,
718 0x27e, 0x4e0, 0x352, 0x02f, 0x09c, 0xfff, 0x2a0, 0xfff,
719 0xfff, 0x46a, 0x457, 0xfff, 0xfff, 0x501, 0xfff, 0x2ba,
720 0xfff, 0xfff, 0xfff, 0x54e, 0x2e7, 0xfff, 0xfff, 0xfff,
721 0xfff, 0xfff, 0x551, 0xfff, 0xfff, 0x1db, 0x2aa, 0xfff,
722 0xfff, 0x4bc, 0xfff, 0xfff, 0x395, 0xfff, 0x0de, 0xfff,
723 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x455, 0xfff, 0x17e,
724 0xfff, 0x221, 0x4a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
725 0x388, 0xfff, 0xfff, 0xfff, 0x308, 0xfff, 0xfff, 0xfff,
726 0x20e, 0x4b9, 0xfff, 0x273, 0x20c, 0x09e, 0xfff, 0x057,
727 0xfff, 0xfff, 0xfff, 0xfff, 0x3f2, 0xfff, 0x1a8, 0x3a6,
728 0x14c, 0xfff, 0xfff, 0x071, 0xfff, 0xfff, 0x53a, 0xfff,
729 0xfff, 0xfff, 0xfff, 0x109, 0xfff, 0xfff, 0x399, 0xfff,
730 0x061, 0x4f0, 0x39e, 0x244, 0xfff, 0x035, 0xfff, 0xfff,
731 0x305, 0x47e, 0x297, 0xfff, 0xfff, 0x2b8, 0xfff, 0xfff,
732 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1bc, 0xfff, 0x2fc,
733 0xfff, 0xfff, 0x554, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b6,
734 0xfff, 0xfff, 0xfff, 0x515, 0x397, 0xfff, 0xfff, 0x12f,
735 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e5,
736 0xfff, 0x4fc, 0xfff, 0xfff, 0x05e, 0xfff, 0xfff, 0xfff,
737 0xfff, 0xfff, 0x0a8, 0x3af, 0x015, 0xfff, 0xfff, 0xfff,
738 0xfff, 0x138, 0xfff, 0xfff, 0xfff, 0x540, 0xfff, 0xfff,
739 0xfff, 0x027, 0x523, 0x2f0, 0xfff, 0xfff, 0xfff, 0xfff,
740 0xfff, 0xfff, 0x16c, 0xfff, 0x27d, 0xfff, 0xfff, 0xfff,
741 0xfff, 0x04c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4dc,
742 0xfff, 0xfff, 0x059, 0x301, 0xfff, 0xfff, 0xfff, 0xfff,
743 0xfff, 0xfff, 0xfff, 0x1a3, 0xfff, 0x15a, 0xfff, 0xfff,
744 0x0a5, 0xfff, 0x435, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
745 0xfff, 0x051, 0xfff, 0xfff, 0x131, 0xfff, 0x4f4, 0xfff,
746 0xfff, 0xfff, 0xfff, 0x441, 0xfff, 0x4fb, 0xfff, 0x03b,
747 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ed, 0x274,
748 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d3, 0x55e, 0x1b3,
749 0xfff, 0x0bd, 0xfff, 0xfff, 0xfff, 0xfff, 0x225, 0xfff,
750 0xfff, 0xfff, 0xfff, 0xfff, 0x4b7, 0xfff, 0xfff, 0x2ff,
751 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c3, 0xfff,
752 0x383, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f6,
753 0xfff, 0xfff, 0x1ee, 0xfff, 0x03d, 0xfff, 0xfff, 0xfff,
754 0xfff, 0xfff, 0x26f, 0x1dc, 0xfff, 0x0db, 0xfff, 0xfff,
755 0xfff, 0xfff, 0xfff, 0x0ce, 0xfff, 0xfff, 0x127, 0x03a,
756 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x311, 0xfff,
757 0xfff, 0x13d, 0x09d, 0x47b, 0x2a6, 0x50d, 0x510, 0x19a,
758 0xfff, 0x354, 0x414, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
759 0xfff, 0xfff, 0x44c, 0x3b0, 0xfff, 0x23d, 0x429, 0xfff,
760 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
761 0x4c0, 0x416, 0xfff, 0x05b, 0xfff, 0xfff, 0x137, 0xfff,
762 0x25f, 0x49f, 0xfff, 0x279, 0x013, 0xfff, 0xfff, 0xfff,
763 0x269, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
764 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d0, 0xfff, 0xfff,
765 0xfff, 0xfff, 0xfff, 0xfff, 0x077, 0xfff, 0xfff, 0x3fb,
766 0xfff, 0xfff, 0xfff, 0xfff, 0x271, 0x3a0, 0xfff, 0xfff,
767 0x40f, 0xfff, 0xfff, 0x3de, 0xfff, 0xfff, 0xfff, 0xfff,
768 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ab, 0x26a,
769 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x489, 0xfff, 0xfff,
770 0x252, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b7, 0x42f, 0xfff,
771 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b7,
772 0xfff, 0x2bb, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
773 0xfff, 0xfff, 0xfff, 0x0f7, 0x01d, 0xfff, 0x067, 0xfff,
774 0xfff, 0xfff, 0xfff, 0x4e2, 0xfff, 0xfff, 0x4bb, 0xfff,
775 0xfff, 0xfff, 0x17b, 0xfff, 0x0ee, 0xfff, 0xfff, 0xfff,
776 0xfff, 0xfff, 0x36e, 0xfff, 0xfff, 0xfff, 0x533, 0xfff,
777 0xfff, 0xfff, 0x4d4, 0x356, 0xfff, 0xfff, 0x375, 0xfff,
778 0xfff, 0xfff, 0xfff, 0x4a4, 0x513, 0xfff, 0xfff, 0xfff,
779 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4ff, 0xfff, 0x2af,
780 0xfff, 0xfff, 0x026, 0xfff, 0x0ad, 0xfff, 0xfff, 0xfff,
781 0xfff, 0x26e, 0xfff, 0xfff, 0xfff, 0xfff, 0x493, 0xfff,
782 0x463, 0x4d2, 0x4be, 0xfff, 0xfff, 0xfff, 0xfff, 0x4f2,
783 0x0b6, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
784 0xfff, 0x32d, 0x315, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
785 0xfff, 0x13a, 0x4a1, 0xfff, 0x27a, 0xfff, 0xfff, 0xfff,
786 0x47a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
787 0x334, 0xfff, 0xfff, 0xfff, 0xfff, 0x54c, 0xfff, 0xfff,
788 0xfff, 0x0c9, 0x007, 0xfff, 0xfff, 0x12e, 0xfff, 0x0ff,
789 0xfff, 0xfff, 0x3f5, 0x509, 0xfff, 0xfff, 0xfff, 0xfff,
790 0x1c3, 0x2ad, 0xfff, 0xfff, 0x47c, 0x261, 0xfff, 0xfff,
791 0xfff, 0xfff, 0xfff, 0x152, 0xfff, 0xfff, 0xfff, 0x339,
792 0xfff, 0x243, 0x1c0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
793 0x063, 0xfff, 0xfff, 0x254, 0xfff, 0xfff, 0x173, 0xfff,
794 0x0c7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
795 0xfff, 0x362, 0x259, 0x485, 0x374, 0x0dc, 0x3ab, 0xfff,
796 0x1c5, 0x534, 0x544, 0xfff, 0xfff, 0x508, 0xfff, 0x402,
797 0x408, 0xfff, 0x0e7, 0xfff, 0xfff, 0x00a, 0x205, 0xfff,
798 0xfff, 0x2b9, 0xfff, 0xfff, 0xfff, 0x465, 0xfff, 0xfff,
799 0xfff, 0xfff, 0xfff, 0xfff, 0x23a, 0xfff, 0xfff, 0xfff,
800 0xfff, 0x147, 0x19d, 0x115, 0x214, 0xfff, 0x090, 0x368,
801 0xfff, 0x210, 0xfff, 0xfff, 0x280, 0x52a, 0x163, 0x148,
802 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x326, 0xfff, 0xfff,
803 0xfff, 0xfff, 0xfff, 0x2de, 0xfff, 0xfff, 0xfff, 0xfff,
804 0x206, 0x2c1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
805 0x189, 0xfff, 0xfff, 0xfff, 0xfff, 0x367, 0xfff, 0x1a4,
806 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x443, 0xfff, 0x27b,
807 0xfff, 0xfff, 0x251, 0x549, 0xfff, 0xfff, 0xfff, 0xfff,
808 0xfff, 0xfff, 0x188, 0x04b, 0xfff, 0xfff, 0xfff, 0x31f,
809 0x4a6, 0xfff, 0x246, 0x1de, 0x156, 0xfff, 0xfff, 0xfff,
810 0x3a9, 0xfff, 0xfff, 0xfff, 0x2fa, 0xfff, 0x128, 0x0d1,
811 0x449, 0x255, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
812 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
813 0xfff, 0xfff, 0xfff, 0xfff, 0x258, 0xfff, 0xfff, 0xfff,
814 0x532, 0xfff, 0xfff, 0xfff, 0x303, 0x517, 0xfff, 0xfff,
815 0x2a9, 0x24a, 0xfff, 0xfff, 0x231, 0xfff, 0xfff, 0xfff,
816 0xfff, 0xfff, 0x4b6, 0x516, 0xfff, 0xfff, 0x0e4, 0x0eb,
817 0xfff, 0x4e4, 0xfff, 0x275, 0xfff, 0xfff, 0x031, 0xfff,
818 0xfff, 0xfff, 0xfff, 0xfff, 0x025, 0x21a, 0xfff, 0x0cc,
819 0x45f, 0x3d9, 0x289, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
820 0xfff, 0xfff, 0x23e, 0xfff, 0xfff, 0xfff, 0x438, 0x097,
821 0x419, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
822 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
823 0xfff, 0xfff, 0x0a9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
824 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
825 0x37e, 0x0e0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x431,
826 0x372, 0xfff, 0xfff, 0xfff, 0x1ba, 0x06e, 0xfff, 0x1b1,
827 0xfff, 0xfff, 0x12a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
828 0xfff, 0xfff, 0x193, 0xfff, 0xfff, 0xfff, 0xfff, 0x10a,
829 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x048, 0x1b4,
830 0xfff, 0xfff, 0xfff, 0xfff, 0x295, 0x140, 0x108, 0xfff,
831 0xfff, 0xfff, 0xfff, 0x16f, 0xfff, 0x0a4, 0x37a, 0xfff,
832 0x29a, 0xfff, 0x284, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c6,
833 0x2a2, 0x3a3, 0xfff, 0x201, 0xfff, 0xfff, 0xfff, 0x4bd,
834 0x005, 0x54a, 0x3b5, 0x204, 0x2ee, 0x11d, 0x436, 0xfff,
835 0xfff, 0xfff, 0xfff, 0xfff, 0x3ec, 0xfff, 0xfff, 0xfff,
836 0xfff, 0xfff, 0xfff, 0xfff, 0x11f, 0x498, 0x21c, 0xfff,
837 0xfff, 0xfff, 0x3d6, 0xfff, 0x4ab, 0xfff, 0x432, 0x2eb,
838 0x542, 0x4fd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
839 0xfff, 0xfff, 0xfff, 0x4ce, 0xfff, 0xfff, 0x2fb, 0xfff,
840 0xfff, 0x2e1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
841 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b9, 0x037, 0x0dd,
842 0xfff, 0xfff, 0xfff, 0x2bf, 0x521, 0x496, 0x095, 0xfff,
843 0xfff, 0x328, 0x070, 0x1bf, 0xfff, 0x393, 0xfff, 0xfff,
844 0x102, 0xfff, 0xfff, 0x21b, 0xfff, 0x142, 0x263, 0x519,
845 0xfff, 0x2a5, 0x177, 0xfff, 0x14d, 0x471, 0x4ae, 0xfff,
846 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
847 0x1f6, 0xfff, 0x481, 0xfff, 0xfff, 0xfff, 0x151, 0xfff,
848 0xfff, 0xfff, 0x085, 0x33f, 0xfff, 0xfff, 0xfff, 0x084,
849 0xfff, 0xfff, 0xfff, 0x345, 0x3a2, 0xfff, 0xfff, 0x0a0,
850 0x0da, 0x024, 0xfff, 0xfff, 0xfff, 0x1bd, 0xfff, 0x55c,
851 0x467, 0x445, 0xfff, 0xfff, 0xfff, 0x052, 0xfff, 0xfff,
852 0xfff, 0xfff, 0x51e, 0xfff, 0xfff, 0x39d, 0xfff, 0x35f,
853 0xfff, 0x376, 0x3ee, 0xfff, 0xfff, 0xfff, 0xfff, 0x448,
854 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x16a,
855 0xfff, 0x036, 0x38f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
856 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x211,
857 0xfff, 0xfff, 0xfff, 0x230, 0xfff, 0xfff, 0x3ba, 0xfff,
858 0xfff, 0xfff, 0x3ce, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
859 0xfff, 0xfff, 0xfff, 0x229, 0xfff, 0x176, 0xfff, 0xfff,
860 0xfff, 0xfff, 0xfff, 0x00b, 0xfff, 0x162, 0x018, 0xfff,
861 0xfff, 0x233, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
862 0x400, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
863 0xfff, 0xfff, 0xfff, 0x12b, 0xfff, 0xfff, 0xfff, 0xfff,
864 0xfff, 0x3f4, 0xfff, 0x0f0, 0xfff, 0x1ac, 0xfff, 0xfff,
865 0x119, 0xfff, 0x2c0, 0xfff, 0xfff, 0xfff, 0x49b, 0xfff,
866 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x23c, 0xfff,
867 0x4b3, 0x010, 0x064, 0xfff, 0xfff, 0x4ba, 0xfff, 0xfff,
868 0xfff, 0xfff, 0xfff, 0x3c2, 0xfff, 0xfff, 0xfff, 0xfff,
869 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x006, 0x196, 0xfff,
870 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x100, 0x191, 0xfff,
871 0x1ea, 0x29f, 0xfff, 0xfff, 0xfff, 0x276, 0xfff, 0xfff,
872 0x2b1, 0x3b9, 0xfff, 0x03c, 0xfff, 0xfff, 0xfff, 0x180,
873 0xfff, 0x08f, 0xfff, 0xfff, 0x19e, 0x019, 0xfff, 0x0b0,
874 0x0fd, 0x332, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
875 0xfff, 0x06b, 0x2e8, 0xfff, 0x446, 0xfff, 0xfff, 0x004,
876 0x247, 0x197, 0xfff, 0x112, 0x169, 0x292, 0xfff, 0x302,
877 0xfff, 0xfff, 0x33b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
878 0xfff, 0xfff, 0xfff, 0x287, 0x21f, 0xfff, 0x3ea, 0xfff,
879 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e7, 0xfff, 0xfff,
880 0xfff, 0xfff, 0xfff, 0x3a8, 0xfff, 0xfff, 0x2bc, 0xfff,
881 0x484, 0x296, 0xfff, 0x1c9, 0x08c, 0x1e5, 0x48a, 0xfff,
882 0x360, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
883 0x1ca, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
884 0xfff, 0xfff, 0xfff, 0x10d, 0xfff, 0xfff, 0xfff, 0xfff,
885 0xfff, 0xfff, 0x066, 0x2ea, 0x28b, 0x25b, 0xfff, 0x072,
886 0xfff, 0xfff, 0xfff, 0xfff, 0x2b6, 0xfff, 0xfff, 0x272,
887 0xfff, 0xfff, 0x525, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
888 0x2ca, 0xfff, 0xfff, 0xfff, 0x299, 0xfff, 0xfff, 0xfff,
889 0x558, 0x41a, 0xfff, 0x4f7, 0x557, 0xfff, 0x4a0, 0x344,
890 0x12c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x125,
891 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
892 0x40e, 0xfff, 0xfff, 0x502, 0xfff, 0x103, 0x3e6, 0xfff,
893 0x527, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
894 0xfff, 0xfff, 0xfff, 0x45d, 0xfff, 0xfff, 0xfff, 0xfff,
895 0x44e, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d2, 0x4c9, 0x35e,
896 0x459, 0x2d9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x17d,
897 0x0c4, 0xfff, 0xfff, 0xfff, 0x3ac, 0x390, 0x094, 0xfff,
898 0x483, 0x0ab, 0xfff, 0x253, 0xfff, 0x391, 0xfff, 0xfff,
899 0xfff, 0xfff, 0x123, 0x0ef, 0xfff, 0xfff, 0xfff, 0x330,
900 0x38c, 0xfff, 0xfff, 0x2ae, 0xfff, 0xfff, 0xfff, 0x042,
901 0x012, 0x06d, 0xfff, 0xfff, 0xfff, 0x32a, 0x3db, 0x364,
902 0x2dc, 0xfff, 0x30f, 0x3d7, 0x4a5, 0x050, 0xfff, 0xfff,
903 0x029, 0xfff, 0xfff, 0xfff, 0xfff, 0x1d1, 0xfff, 0xfff,
904 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x480, 0xfff,
905 0x4ed, 0x081, 0x0a1, 0xfff, 0xfff, 0xfff, 0x30e, 0x52f,
906 0x257, 0xfff, 0xfff, 0x447, 0xfff, 0xfff, 0xfff, 0xfff,
907 0xfff, 0xfff, 0xfff, 0x401, 0x3cc, 0xfff, 0xfff, 0x0fb,
908 0x2c9, 0x42a, 0x314, 0x33e, 0x3bd, 0x318, 0xfff, 0x10e,
909 0x2a1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x24c,
910 0x506, 0xfff, 0x267, 0xfff, 0xfff, 0x219, 0xfff, 0x1eb,
911 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
912 0x309, 0x3e2, 0x46c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
913 0x384, 0xfff, 0xfff, 0xfff, 0xfff, 0x50c, 0xfff, 0x24b,
914 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x038,
915 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x194,
916 0x143, 0x3e3, 0xfff, 0xfff, 0xfff, 0x4c2, 0xfff, 0xfff,
917 0x0e1, 0x25c, 0xfff, 0x237, 0xfff, 0x1fe, 0xfff, 0xfff,
918 0xfff, 0x065, 0x2a4, 0xfff, 0x386, 0x55a, 0x11b, 0xfff,
919 0xfff, 0x192, 0xfff, 0x183, 0x00e, 0xfff, 0xfff, 0xfff,
920 0xfff, 0xfff, 0xfff, 0x4b2, 0x18e, 0xfff, 0xfff, 0xfff,
921 0xfff, 0x486, 0x4ef, 0x0c6, 0x380, 0xfff, 0x4a8, 0xfff,
922 0x0c5, 0xfff, 0xfff, 0xfff, 0xfff, 0x093, 0x1b8, 0xfff,
923 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e6,
924 0xfff, 0x0f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
925 0x28e, 0xfff, 0x53b, 0x420, 0x22a, 0x33a, 0xfff, 0x387,
926 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2a3, 0xfff, 0xfff,
927 0xfff, 0x428, 0x500, 0xfff, 0xfff, 0x120, 0x2c6, 0x290,
928 0x2f5, 0x0e3, 0xfff, 0x0b7, 0xfff, 0x319, 0x474, 0xfff,
929 0xfff, 0xfff, 0x529, 0x014, 0xfff, 0x41b, 0x40a, 0x18b,
930 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d9,
931 0xfff, 0x38a, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ce, 0xfff,
932 0xfff, 0xfff, 0xfff, 0xfff, 0x3b1, 0xfff, 0xfff, 0x05d,
933 0x2c4, 0xfff, 0xfff, 0x4af, 0xfff, 0x030, 0xfff, 0xfff,
934 0x203, 0xfff, 0x277, 0x256, 0xfff, 0xfff, 0xfff, 0x4f9,
935 0xfff, 0x2c7, 0xfff, 0x466, 0x016, 0x1cd, 0xfff, 0x167,
936 0xfff, 0xfff, 0x0c8, 0xfff, 0x43d, 0xfff, 0xfff, 0x020,
937 0xfff, 0xfff, 0x232, 0x1cb, 0x1e0, 0xfff, 0xfff, 0x347,
938 0xfff, 0x478, 0xfff, 0x365, 0xfff, 0xfff, 0xfff, 0xfff,
939 0x358, 0xfff, 0x10b, 0xfff, 0x35d, 0xfff, 0xfff, 0xfff,
940 0xfff, 0xfff, 0x452, 0x22d, 0xfff, 0xfff, 0x47d, 0xfff,
941 0x2f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x460, 0xfff,
942 0xfff, 0xfff, 0x50b, 0xfff, 0xfff, 0xfff, 0x2ec, 0xfff,
943 0xfff, 0xfff, 0xfff, 0xfff, 0x4b1, 0x422, 0xfff, 0xfff,
944 0xfff, 0x2d4, 0xfff, 0x239, 0xfff, 0xfff, 0xfff, 0x439,
945 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
946 0xfff, 0x491, 0x075, 0xfff, 0xfff, 0xfff, 0x06c, 0xfff,
947 0xfff, 0x0f9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
948 0xfff, 0x139, 0xfff, 0x4f6, 0xfff, 0xfff, 0x409, 0xfff,
949 0xfff, 0x15b, 0xfff, 0xfff, 0x348, 0xfff, 0xfff, 0xfff,
950 0xfff, 0x4a2, 0x49d, 0xfff, 0x033, 0x175, 0xfff, 0x039,
951 0xfff, 0x312, 0x40c, 0xfff, 0xfff, 0x325, 0xfff, 0xfff,
952 0xfff, 0xfff, 0xfff, 0xfff, 0x4aa, 0xfff, 0xfff, 0xfff,
953 0xfff, 0xfff, 0xfff, 0x165, 0x3bc, 0x48c, 0x310, 0x096,
954 0xfff, 0xfff, 0x250, 0x1a2, 0xfff, 0xfff, 0xfff, 0xfff,
955 0x20d, 0x2ac, 0xfff, 0xfff, 0x39b, 0xfff, 0x377, 0xfff,
956 0x512, 0x495, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
957 0xfff, 0xfff, 0xfff, 0xfff, 0x357, 0x4ea, 0xfff, 0xfff,
958 0xfff, 0xfff, 0x198, 0xfff, 0xfff, 0xfff, 0x434, 0x04a,
959 0xfff, 0xfff, 0xfff, 0xfff, 0x062, 0xfff, 0x1d6, 0x1c8,
960 0xfff, 0x1f3, 0x281, 0xfff, 0x462, 0xfff, 0xfff, 0xfff,
961 0x4b0, 0xfff, 0x207, 0xfff, 0xfff, 0xfff, 0xfff, 0x3dd,
962 0xfff, 0xfff, 0x55d, 0xfff, 0x552, 0x494, 0x1af, 0xfff,
963 0xfff, 0xfff, 0xfff, 0xfff, 0x227, 0xfff, 0xfff, 0x069,
964 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x43e,
965 0x0b5, 0xfff, 0x524, 0x2d2, 0xfff, 0xfff, 0xfff, 0x28f,
966 0xfff, 0x01b, 0x50e, 0xfff, 0xfff, 0x1bb, 0xfff, 0xfff,
967 0x41d, 0xfff, 0x32e, 0x48e, 0xfff, 0x1f7, 0x224, 0xfff,
968 0xfff, 0xfff, 0xfff, 0xfff, 0x394, 0xfff, 0xfff, 0xfff,
969 0xfff, 0x52c, 0xfff, 0xfff, 0xfff, 0x392, 0xfff, 0x1e7,
970 0xfff, 0xfff, 0x3f9, 0x3a7, 0xfff, 0x51f, 0xfff, 0x0bb,
971 0x118, 0x3ca, 0xfff, 0x1dd, 0xfff, 0x48b, 0xfff, 0xfff,
972 0xfff, 0xfff, 0x50f, 0xfff, 0x0d6, 0xfff, 0x1fa, 0xfff,
973 0x11e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d7, 0xfff, 0x078,
974 0x008, 0xfff, 0x25d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
975 0x032, 0x33c, 0xfff, 0x4d9, 0x160, 0xfff, 0xfff, 0x300,
976 0x0b1, 0xfff, 0x322, 0xfff, 0x4ec, 0xfff, 0xfff, 0x200,
977 0x00c, 0x369, 0x473, 0xfff, 0xfff, 0x32c, 0xfff, 0xfff,
978 0xfff, 0xfff, 0xfff, 0xfff, 0x53e, 0x3d4, 0x417, 0xfff,
979 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
980 0x34b, 0x001, 0x39a, 0x02c, 0xfff, 0xfff, 0x2ce, 0x00f,
981 0xfff, 0x0ba, 0xfff, 0xfff, 0xfff, 0xfff, 0x060, 0xfff,
982 0x406, 0xfff, 0xfff, 0xfff, 0x4ee, 0x4ac, 0xfff, 0x43f,
983 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x29b, 0xfff, 0xfff,
984 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x216,
985 0x190, 0xfff, 0x396, 0x464, 0xfff, 0xfff, 0x323, 0xfff,
986 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e9, 0xfff, 0x26d,
987 0x2cd, 0x040, 0xfff, 0xfff, 0xfff, 0xfff, 0x38b, 0x3c0,
988 0xfff, 0xfff, 0xfff, 0x1f2, 0xfff, 0x0ea, 0xfff, 0xfff,
989 0x472, 0xfff, 0x1fb, 0xfff, 0xfff, 0x0af, 0x27f, 0xfff,
990 0xfff, 0xfff, 0x479, 0x023, 0xfff, 0x0d8, 0x3b3, 0xfff,
991 0xfff, 0xfff, 0x121, 0xfff, 0xfff, 0x3bf, 0xfff, 0xfff,
992 0x16b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
993 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
994 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
995 0x45a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
996 0xfff, 0x0be, 0xfff, 0xfff, 0xfff, 0x111, 0xfff, 0x220,
997 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
998 0xfff, 0xfff, 0x09b, 0x218, 0xfff, 0x022, 0x202, 0xfff,
999 0x4c8, 0xfff, 0x0ed, 0xfff, 0xfff, 0x182, 0xfff, 0xfff,
1000 0xfff, 0x17f, 0x213, 0xfff, 0x321, 0x36a, 0xfff, 0x086,
1001 0xfff, 0xfff, 0xfff, 0x43b, 0x088, 0xfff, 0xfff, 0xfff,
1002 0xfff, 0x26c, 0xfff, 0x2f8, 0x3b4, 0xfff, 0xfff, 0xfff,
1003 0x132, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x333, 0x444,
1004 0x0c1, 0x4d8, 0x46d, 0x264, 0xfff, 0xfff, 0xfff, 0xfff,
1005 0x426, 0xfff, 0xfff, 0xfff, 0xfff, 0x2fe, 0xfff, 0xfff,
1006 0xfff, 0xfff, 0x011, 0xfff, 0x05f, 0xfff, 0xfff, 0xfff,
1007 0xfff, 0x10c, 0x101, 0xfff, 0xfff, 0xfff, 0xfff, 0x110,
1008 0xfff, 0x044, 0x304, 0x361, 0x404, 0xfff, 0x51b, 0x099,
1009 0xfff, 0x440, 0xfff, 0xfff, 0xfff, 0x222, 0xfff, 0xfff,
1010 0xfff, 0xfff, 0x1b5, 0xfff, 0x136, 0x430, 0xfff, 0x1da,
1011 0xfff, 0xfff, 0xfff, 0x043, 0xfff, 0x17c, 0xfff, 0xfff,
1012 0xfff, 0x01c, 0xfff, 0xfff, 0xfff, 0x425, 0x236, 0xfff,
1013 0x317, 0xfff, 0xfff, 0x437, 0x3fc, 0xfff, 0x1f1, 0xfff,
1014 0x324, 0xfff, 0xfff, 0x0ca, 0x306, 0xfff, 0x548, 0xfff,
1015 0x46e, 0xfff, 0xfff, 0xfff, 0x4b8, 0x1c2, 0x286, 0xfff,
1016 0xfff, 0x087, 0x18a, 0x19f, 0xfff, 0xfff, 0xfff, 0xfff,
1017 0x18c, 0xfff, 0x215, 0xfff, 0xfff, 0xfff, 0xfff, 0x283,
1018 0xfff, 0xfff, 0xfff, 0x126, 0xfff, 0xfff, 0x370, 0xfff,
1019 0x53f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x31c, 0xfff,
1020 0x4d1, 0xfff, 0xfff, 0xfff, 0x021, 0xfff, 0x157, 0xfff,
1021 0xfff, 0x028, 0x16e, 0xfff, 0x421, 0xfff, 0x1c6, 0xfff,
1022 0xfff, 0x511, 0xfff, 0xfff, 0x39c, 0x46f, 0x1b2, 0xfff,
1023 0xfff, 0x316, 0xfff, 0xfff, 0x009, 0xfff, 0xfff, 0x195,
1024 0xfff, 0x240, 0x546, 0xfff, 0xfff, 0x520, 0xfff, 0xfff,
1025 0xfff, 0xfff, 0xfff, 0xfff, 0x454, 0xfff, 0xfff, 0xfff,
1026 0x3f3, 0xfff, 0xfff, 0x187, 0xfff, 0x4a9, 0xfff, 0xfff,
1027 0xfff, 0xfff, 0xfff, 0xfff, 0x51c, 0x453, 0x1e6, 0xfff,
1028 0xfff, 0xfff, 0x1b0, 0xfff, 0x477, 0xfff, 0xfff, 0xfff,
1029 0x4fe, 0xfff, 0x32f, 0xfff, 0xfff, 0x15e, 0x1d4, 0xfff,
1030 0x0e5, 0xfff, 0xfff, 0xfff, 0x242, 0x14b, 0x046, 0xfff,
1031 0x3f6, 0x3bb, 0x3e4, 0xfff, 0xfff, 0x2e3, 0xfff, 0x245,
1032 0xfff, 0x149, 0xfff, 0xfff, 0xfff, 0x2db, 0xfff, 0xfff,
1033 0x181, 0xfff, 0x089, 0x2c5, 0xfff, 0x1f5, 0xfff, 0x2d6,
1034 0x507, 0xfff, 0x42d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1035 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1036 0x080, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1037 0xfff, 0xfff, 0xfff, 0xfff, 0x3c3, 0x320, 0xfff, 0x1e1,
1038 0xfff, 0x0f5, 0x13b, 0xfff, 0xfff, 0xfff, 0x003, 0x4da,
1039 0xfff, 0xfff, 0xfff, 0x42c, 0xfff, 0xfff, 0x0cb, 0xfff,
1040 0x536, 0x2c3, 0xfff, 0xfff, 0xfff, 0xfff, 0x199, 0xfff,
1041 0xfff, 0x0c0, 0xfff, 0x01e, 0x497, 0xfff, 0xfff, 0x3e5,
1042 0xfff, 0xfff, 0xfff, 0x0cf, 0xfff, 0x2bd, 0xfff, 0x223,
1043 0xfff, 0x3ff, 0xfff, 0x058, 0x174, 0x3ef, 0xfff, 0x002
1044};
1045
1046static unsigned short err_pos(unsigned short din)
1047{
1048 BUG_ON(din > 4096);
1049 return err_pos_lut[din];
1050}
1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1052{
1053 if ((chk_syndrome_list[0] | chk_syndrome_list[1] |
1054 chk_syndrome_list[2] | chk_syndrome_list[3] |
1055 chk_syndrome_list[4] | chk_syndrome_list[5] |
1056 chk_syndrome_list[6] | chk_syndrome_list[7]) != 0x0) {
1057 return -EINVAL;
1058 } else {
1059 err_info[0] = 0x0;
1060 return 0;
1061 }
1062}
1063static int chk_1_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1064{
1065 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
1066 tmp0 = gf4096_mul(chk_syndrome_list[1], gf4096_inv(chk_syndrome_list[0]));
1067 tmp1 = gf4096_mul(chk_syndrome_list[2], gf4096_inv(chk_syndrome_list[1]));
1068 tmp2 = gf4096_mul(chk_syndrome_list[3], gf4096_inv(chk_syndrome_list[2]));
1069 tmp3 = gf4096_mul(chk_syndrome_list[4], gf4096_inv(chk_syndrome_list[3]));
1070 tmp4 = gf4096_mul(chk_syndrome_list[5], gf4096_inv(chk_syndrome_list[4]));
1071 tmp5 = gf4096_mul(chk_syndrome_list[6], gf4096_inv(chk_syndrome_list[5]));
1072 tmp6 = gf4096_mul(chk_syndrome_list[7], gf4096_inv(chk_syndrome_list[6]));
1073 if ((tmp0 == tmp1) & (tmp1 == tmp2) & (tmp2 == tmp3) & (tmp3 == tmp4) & (tmp4 == tmp5) & (tmp5 == tmp6)) {
1074 err_info[0] = 0x1; // encode 1-symbol error as 0x1
1075 err_info[1] = err_pos(tmp0);
1076 err_info[1] = (unsigned short)(0x55e - err_info[1]);
1077 err_info[5] = chk_syndrome_list[0];
1078 return 0;
1079 } else
1080 return -EINVAL;
1081}
1082static int chk_2_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1083{
1084 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1085 unsigned short coefs[4];
1086 unsigned short err_pats[4];
1087 int found_num_root = 0;
1088 unsigned short bit2_root0, bit2_root1;
1089 unsigned short bit2_root0_inv, bit2_root1_inv;
1090 unsigned short err_loc_eqn, test_root;
1091 unsigned short bit2_loc0, bit2_loc1;
1092 unsigned short bit2_pat0, bit2_pat1;
1093
1094 find_2x2_soln(chk_syndrome_list[1],
1095 chk_syndrome_list[0],
1096 chk_syndrome_list[2], chk_syndrome_list[1], chk_syndrome_list[2], chk_syndrome_list[3], coefs);
1097 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1098 err_loc_eqn =
1099 gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1100 if (err_loc_eqn == 0x0) {
1101 if (found_num_root == 0) {
1102 bit2_root0 = test_root;
1103 found_num_root = 1;
1104 } else if (found_num_root == 1) {
1105 bit2_root1 = test_root;
1106 found_num_root = 2;
1107 break;
1108 }
1109 }
1110 }
1111 if (found_num_root != 2)
1112 return -EINVAL;
1113 else {
1114 bit2_root0_inv = gf4096_inv(bit2_root0);
1115 bit2_root1_inv = gf4096_inv(bit2_root1);
1116 find_2bit_err_pats(chk_syndrome_list[0],
1117 chk_syndrome_list[1], bit2_root0_inv, bit2_root1_inv, err_pats);
1118 bit2_pat0 = err_pats[0];
1119 bit2_pat1 = err_pats[1];
1120 //for(x+1)
1121 tmp0 = gf4096_mul(gf4096_mul(bit2_root0_inv, bit2_root0_inv), gf4096_mul(bit2_root0_inv, bit2_root0_inv)); //rinv0^4
1122 tmp1 = gf4096_mul(bit2_root0_inv, tmp0); //rinv0^5
1123 tmp2 = gf4096_mul(bit2_root0_inv, tmp1); //rinv0^6
1124 tmp3 = gf4096_mul(bit2_root0_inv, tmp2); //rinv0^7
1125 tmp4 = gf4096_mul(gf4096_mul(bit2_root1_inv, bit2_root1_inv), gf4096_mul(bit2_root1_inv, bit2_root1_inv)); //rinv1^4
1126 tmp5 = gf4096_mul(bit2_root1_inv, tmp4); //rinv1^5
1127 tmp6 = gf4096_mul(bit2_root1_inv, tmp5); //rinv1^6
1128 tmp7 = gf4096_mul(bit2_root1_inv, tmp6); //rinv1^7
1129 //check if only 2-bit error
1130 if ((chk_syndrome_list[4] ==
1131 (gf4096_mul(bit2_pat0, tmp0) ^
1132 gf4096_mul(bit2_pat1,
1133 tmp4))) & (chk_syndrome_list[5] ==
1134 (gf4096_mul(bit2_pat0, tmp1) ^
1135 gf4096_mul(bit2_pat1,
1136 tmp5))) &
1137 (chk_syndrome_list[6] ==
1138 (gf4096_mul(bit2_pat0, tmp2) ^
1139 gf4096_mul(bit2_pat1,
1140 tmp6))) & (chk_syndrome_list[7] ==
1141 (gf4096_mul(bit2_pat0, tmp3) ^ gf4096_mul(bit2_pat1, tmp7)))) {
1142 if ((err_pos(bit2_root0_inv) == 0xfff) | (err_pos(bit2_root1_inv) == 0xfff)) {
1143 return -EINVAL;
1144 } else {
1145 bit2_loc0 = 0x55e - err_pos(bit2_root0_inv);
1146 bit2_loc1 = 0x55e - err_pos(bit2_root1_inv);
1147 err_info[0] = 0x2; // encode 2-symbol error as 0x2
1148 err_info[1] = bit2_loc0;
1149 err_info[2] = bit2_loc1;
1150 err_info[5] = bit2_pat0;
1151 err_info[6] = bit2_pat1;
1152 return 0;
1153 }
1154 } else
1155 return -EINVAL;
1156 }
1157}
1158static int chk_3_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1159{
1160 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
1161 unsigned short coefs[4];
1162 unsigned short err_pats[4];
1163 int found_num_root = 0;
1164 unsigned short bit3_root0, bit3_root1, bit3_root2;
1165 unsigned short bit3_root0_inv, bit3_root1_inv, bit3_root2_inv;
1166 unsigned short err_loc_eqn, test_root;
1167
1168 find_3bit_err_coefs(chk_syndrome_list[0], chk_syndrome_list[1],
1169 chk_syndrome_list[2], chk_syndrome_list[3],
1170 chk_syndrome_list[4], chk_syndrome_list[5], coefs);
1171
1172 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1173 err_loc_eqn = gf4096_mul(coefs[2],
1174 gf4096_mul(gf4096_mul(test_root, test_root),
1175 test_root)) ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root))
1176 ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1177
1178 if (err_loc_eqn == 0x0) {
1179 if (found_num_root == 0) {
1180 bit3_root0 = test_root;
1181 found_num_root = 1;
1182 } else if (found_num_root == 1) {
1183 bit3_root1 = test_root;
1184 found_num_root = 2;
1185 } else if (found_num_root == 2) {
1186 bit3_root2 = test_root;
1187 found_num_root = 3;
1188 break;
1189 }
1190 }
1191 }
1192 if (found_num_root != 3)
1193 return -EINVAL;
1194 else {
1195 bit3_root0_inv = gf4096_inv(bit3_root0);
1196 bit3_root1_inv = gf4096_inv(bit3_root1);
1197 bit3_root2_inv = gf4096_inv(bit3_root2);
1198
1199 find_3bit_err_pats(chk_syndrome_list[0], chk_syndrome_list[1],
1200 chk_syndrome_list[2], bit3_root0_inv,
1201 bit3_root1_inv, bit3_root2_inv, err_pats);
1202
1203 //check if only 3-bit error
1204 tmp0 = gf4096_mul(bit3_root0_inv, bit3_root0_inv);
1205 tmp0 = gf4096_mul(tmp0, tmp0);
1206 tmp0 = gf4096_mul(tmp0, bit3_root0_inv);
1207 tmp0 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^6
1208 tmp1 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^7
1209 tmp2 = gf4096_mul(bit3_root1_inv, bit3_root1_inv);
1210 tmp2 = gf4096_mul(tmp2, tmp2);
1211 tmp2 = gf4096_mul(tmp2, bit3_root1_inv);
1212 tmp2 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^6
1213 tmp3 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^7
1214 tmp4 = gf4096_mul(bit3_root2_inv, bit3_root2_inv);
1215 tmp4 = gf4096_mul(tmp4, tmp4);
1216 tmp4 = gf4096_mul(tmp4, bit3_root2_inv);
1217 tmp4 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^6
1218 tmp5 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^7
1219
1220 //check if only 3 errors
1221 if ((chk_syndrome_list[6] == (gf4096_mul(err_pats[0], tmp0) ^
1222 gf4096_mul(err_pats[1], tmp2) ^
1223 gf4096_mul(err_pats[2], tmp4))) &
1224 (chk_syndrome_list[7] == (gf4096_mul(err_pats[0], tmp1) ^
1225 gf4096_mul(err_pats[1], tmp3) ^ gf4096_mul(err_pats[2], tmp5)))) {
1226 if ((err_pos(bit3_root0_inv) == 0xfff) |
1227 (err_pos(bit3_root1_inv) == 0xfff) | (err_pos(bit3_root2_inv) == 0xfff)) {
1228 return -EINVAL;
1229 } else {
1230 err_info[0] = 0x3;
1231 err_info[1] = (0x55e - err_pos(bit3_root0_inv));
1232 err_info[2] = (0x55e - err_pos(bit3_root1_inv));
1233 err_info[3] = (0x55e - err_pos(bit3_root2_inv));
1234 err_info[5] = err_pats[0];
1235 err_info[6] = err_pats[1];
1236 err_info[7] = err_pats[2];
1237 return 0;
1238 }
1239 } else
1240 return -EINVAL;
1241 }
1242}
1243static int chk_4_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1244{
1245 unsigned short coefs[4];
1246 unsigned short err_pats[4];
1247 int found_num_root = 0;
1248 unsigned short bit4_root0, bit4_root1, bit4_root2, bit4_root3;
1249 unsigned short bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv;
1250 unsigned short err_loc_eqn, test_root;
1251
1252 find_4bit_err_coefs(chk_syndrome_list[0],
1253 chk_syndrome_list[1],
1254 chk_syndrome_list[2],
1255 chk_syndrome_list[3],
1256 chk_syndrome_list[4],
1257 chk_syndrome_list[5], chk_syndrome_list[6], chk_syndrome_list[7], coefs);
1258
1259 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1260 err_loc_eqn =
1261 gf4096_mul(coefs[3],
1262 gf4096_mul(gf4096_mul
1263 (gf4096_mul(test_root, test_root),
1264 test_root),
1265 test_root)) ^ gf4096_mul(coefs[2],
1266 gf4096_mul
1267 (gf4096_mul(test_root, test_root), test_root))
1268 ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root)
1269 ^ 0x1;
1270 if (err_loc_eqn == 0x0) {
1271 if (found_num_root == 0) {
1272 bit4_root0 = test_root;
1273 found_num_root = 1;
1274 } else if (found_num_root == 1) {
1275 bit4_root1 = test_root;
1276 found_num_root = 2;
1277 } else if (found_num_root == 2) {
1278 bit4_root2 = test_root;
1279 found_num_root = 3;
1280 } else {
1281 found_num_root = 4;
1282 bit4_root3 = test_root;
1283 break;
1284 }
1285 }
1286 }
1287 if (found_num_root != 4) {
1288 return -EINVAL;
1289 } else {
1290 bit4_root0_inv = gf4096_inv(bit4_root0);
1291 bit4_root1_inv = gf4096_inv(bit4_root1);
1292 bit4_root2_inv = gf4096_inv(bit4_root2);
1293 bit4_root3_inv = gf4096_inv(bit4_root3);
1294 find_4bit_err_pats(chk_syndrome_list[0],
1295 chk_syndrome_list[1],
1296 chk_syndrome_list[2],
1297 chk_syndrome_list[3],
1298 bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv, err_pats);
1299 err_info[0] = 0x4;
1300 err_info[1] = (0x55e - err_pos(bit4_root0_inv));
1301 err_info[2] = (0x55e - err_pos(bit4_root1_inv));
1302 err_info[3] = (0x55e - err_pos(bit4_root2_inv));
1303 err_info[4] = (0x55e - err_pos(bit4_root3_inv));
1304 err_info[5] = err_pats[0];
1305 err_info[6] = err_pats[1];
1306 err_info[7] = err_pats[2];
1307 err_info[8] = err_pats[3];
1308 return 0;
1309 }
1310}
1311
1312void correct_12bit_symbol(unsigned char *buf, unsigned short sym,
1313 unsigned short val)
1314{
1315 if (unlikely(sym > 1366)) {
1316 printk(KERN_ERR "Error: symbol %d out of range; cannot correct\n", sym);
1317 } else if (sym == 0) {
1318 buf[0] ^= val;
1319 } else if (sym & 1) {
1320 buf[1+(3*(sym-1))/2] ^= (val >> 4);
1321 buf[2+(3*(sym-1))/2] ^= ((val & 0xf) << 4);
1322 } else {
1323 buf[2+(3*(sym-2))/2] ^= (val >> 8);
1324 buf[3+(3*(sym-2))/2] ^= (val & 0xff);
1325 }
1326}
1327
1328static int debugecc = 0;
1329module_param(debugecc, int, 0644);
1330
1331int cafe_correct_ecc(unsigned char *buf,
1332 unsigned short *chk_syndrome_list)
1333{
1334 unsigned short err_info[9];
1335 int i;
1336
1337 if (debugecc) {
1338 printk(KERN_WARNING "cafe_correct_ecc invoked. Syndromes %x %x %x %x %x %x %x %x\n",
1339 chk_syndrome_list[0], chk_syndrome_list[1],
1340 chk_syndrome_list[2], chk_syndrome_list[3],
1341 chk_syndrome_list[4], chk_syndrome_list[5],
1342 chk_syndrome_list[6], chk_syndrome_list[7]);
1343 for (i=0; i < 2048; i+=16) {
1344 printk(KERN_WARNING "D %04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1345 i,
1346 buf[i], buf[i+1], buf[i+2], buf[i+3],
1347 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1348 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1349 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1350 }
1351 for ( ; i < 2112; i+=16) {
1352 printk(KERN_WARNING "O %02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1353 i - 2048,
1354 buf[i], buf[i+1], buf[i+2], buf[i+3],
1355 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1356 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1357 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1358 }
1359 }
1360
1361
1362
1363 if (chk_no_err_only(chk_syndrome_list, err_info) &&
1364 chk_1_err_only(chk_syndrome_list, err_info) &&
1365 chk_2_err_only(chk_syndrome_list, err_info) &&
1366 chk_3_err_only(chk_syndrome_list, err_info) &&
1367 chk_4_err_only(chk_syndrome_list, err_info)) {
1368 return -EIO;
1369 }
1370
1371 for (i=0; i < err_info[0]; i++) {
1372 if (debugecc)
1373 printk(KERN_WARNING "Correct symbol %d with 0x%03x\n",
1374 err_info[1+i], err_info[5+i]);
1375
1376 correct_12bit_symbol(buf, err_info[1+i], err_info[5+i]);
1377 }
1378
1379 return err_info[0];
1380}
1381
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 94924d52a9b9..8296305c8297 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -11,7 +11,7 @@
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 * 12 *
13 * Overview: 13 * Overview:
14 * This is a device driver for the NAND flash controller found on 14 * This is a device driver for the NAND flash controller found on
15 * the AMD CS5535/CS5536 companion chipsets for the Geode processor. 15 * the AMD CS5535/CS5536 companion chipsets for the Geode processor.
16 * 16 *
17 */ 17 */
@@ -303,7 +303,7 @@ static int __init cs553x_init(void)
303 err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF); 303 err = cs553x_init_one(i, !!(val & FLSH_MEM_IO), val & 0xFFFFFFFF);
304 } 304 }
305 305
306 /* Register all devices together here. This means we can easily hack it to 306 /* Register all devices together here. This means we can easily hack it to
307 do mtdconcat etc. if we want to. */ 307 do mtdconcat etc. if we want to. */
308 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) { 308 for (i = 0; i < NR_CS553X_CONTROLLERS; i++) {
309 if (cs553x_mtd[i]) { 309 if (cs553x_mtd[i]) {
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 6107f532855b..12608c13cce5 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1635,13 +1635,12 @@ static int __init doc_probe(unsigned long physadr)
1635 1635
1636 len = sizeof(struct mtd_info) + 1636 len = sizeof(struct mtd_info) +
1637 sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr)); 1637 sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr));
1638 mtd = kmalloc(len, GFP_KERNEL); 1638 mtd = kzalloc(len, GFP_KERNEL);
1639 if (!mtd) { 1639 if (!mtd) {
1640 printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len); 1640 printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len);
1641 ret = -ENOMEM; 1641 ret = -ENOMEM;
1642 goto fail; 1642 goto fail;
1643 } 1643 }
1644 memset(mtd, 0, len);
1645 1644
1646 nand = (struct nand_chip *) (mtd + 1); 1645 nand = (struct nand_chip *) (mtd + 1);
1647 doc = (struct doc_priv *) (nand + 1); 1646 doc = (struct doc_priv *) (nand + 1);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 41bfcae1fbf4..dfe56e03e48b 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -362,7 +362,7 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
362 * access 362 * access
363 */ 363 */
364 ofs += mtd->oobsize; 364 ofs += mtd->oobsize;
365 chip->ops.len = 2; 365 chip->ops.len = chip->ops.ooblen = 2;
366 chip->ops.datbuf = NULL; 366 chip->ops.datbuf = NULL;
367 chip->ops.oobbuf = buf; 367 chip->ops.oobbuf = buf;
368 chip->ops.ooboffs = chip->badblockpos & ~0x01; 368 chip->ops.ooboffs = chip->badblockpos & ~0x01;
@@ -755,7 +755,7 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
755} 755}
756 756
757/** 757/**
758 * nand_read_page_swecc - {REPLACABLE] software ecc based page read function 758 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function
759 * @mtd: mtd info structure 759 * @mtd: mtd info structure
760 * @chip: nand chip info structure 760 * @chip: nand chip info structure
761 * @buf: buffer to store read data 761 * @buf: buffer to store read data
@@ -795,7 +795,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
795} 795}
796 796
797/** 797/**
798 * nand_read_page_hwecc - {REPLACABLE] hardware ecc based page read function 798 * nand_read_page_hwecc - [REPLACABLE] hardware ecc based page read function
799 * @mtd: mtd info structure 799 * @mtd: mtd info structure
800 * @chip: nand chip info structure 800 * @chip: nand chip info structure
801 * @buf: buffer to store read data 801 * @buf: buffer to store read data
@@ -839,7 +839,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
839} 839}
840 840
841/** 841/**
842 * nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read 842 * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read
843 * @mtd: mtd info structure 843 * @mtd: mtd info structure
844 * @chip: nand chip info structure 844 * @chip: nand chip info structure
845 * @buf: buffer to store read data 845 * @buf: buffer to store read data
@@ -897,12 +897,11 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
897 * @chip: nand chip structure 897 * @chip: nand chip structure
898 * @oob: oob destination address 898 * @oob: oob destination address
899 * @ops: oob ops structure 899 * @ops: oob ops structure
900 * @len: size of oob to transfer
900 */ 901 */
901static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, 902static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
902 struct mtd_oob_ops *ops) 903 struct mtd_oob_ops *ops, size_t len)
903{ 904{
904 size_t len = ops->ooblen;
905
906 switch(ops->mode) { 905 switch(ops->mode) {
907 906
908 case MTD_OOB_PLACE: 907 case MTD_OOB_PLACE:
@@ -960,6 +959,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
960 int sndcmd = 1; 959 int sndcmd = 1;
961 int ret = 0; 960 int ret = 0;
962 uint32_t readlen = ops->len; 961 uint32_t readlen = ops->len;
962 uint32_t oobreadlen = ops->ooblen;
963 uint8_t *bufpoi, *oob, *buf; 963 uint8_t *bufpoi, *oob, *buf;
964 964
965 stats = mtd->ecc_stats; 965 stats = mtd->ecc_stats;
@@ -971,7 +971,6 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
971 page = realpage & chip->pagemask; 971 page = realpage & chip->pagemask;
972 972
973 col = (int)(from & (mtd->writesize - 1)); 973 col = (int)(from & (mtd->writesize - 1));
974 chip->oob_poi = chip->buffers->oobrbuf;
975 974
976 buf = ops->datbuf; 975 buf = ops->datbuf;
977 oob = ops->oobbuf; 976 oob = ops->oobbuf;
@@ -1007,10 +1006,17 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1007 1006
1008 if (unlikely(oob)) { 1007 if (unlikely(oob)) {
1009 /* Raw mode does data:oob:data:oob */ 1008 /* Raw mode does data:oob:data:oob */
1010 if (ops->mode != MTD_OOB_RAW) 1009 if (ops->mode != MTD_OOB_RAW) {
1011 oob = nand_transfer_oob(chip, oob, ops); 1010 int toread = min(oobreadlen,
1012 else 1011 chip->ecc.layout->oobavail);
1013 buf = nand_transfer_oob(chip, buf, ops); 1012 if (toread) {
1013 oob = nand_transfer_oob(chip,
1014 oob, ops, toread);
1015 oobreadlen -= toread;
1016 }
1017 } else
1018 buf = nand_transfer_oob(chip,
1019 buf, ops, mtd->oobsize);
1014 } 1020 }
1015 1021
1016 if (!(chip->options & NAND_NO_READRDY)) { 1022 if (!(chip->options & NAND_NO_READRDY)) {
@@ -1057,6 +1063,8 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
1057 } 1063 }
1058 1064
1059 ops->retlen = ops->len - (size_t) readlen; 1065 ops->retlen = ops->len - (size_t) readlen;
1066 if (oob)
1067 ops->oobretlen = ops->ooblen - oobreadlen;
1060 1068
1061 if (ret) 1069 if (ret)
1062 return ret; 1070 return ret;
@@ -1257,12 +1265,18 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1257 int page, realpage, chipnr, sndcmd = 1; 1265 int page, realpage, chipnr, sndcmd = 1;
1258 struct nand_chip *chip = mtd->priv; 1266 struct nand_chip *chip = mtd->priv;
1259 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1; 1267 int blkcheck = (1 << (chip->phys_erase_shift - chip->page_shift)) - 1;
1260 int readlen = ops->len; 1268 int readlen = ops->ooblen;
1269 int len;
1261 uint8_t *buf = ops->oobbuf; 1270 uint8_t *buf = ops->oobbuf;
1262 1271
1263 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n", 1272 DEBUG(MTD_DEBUG_LEVEL3, "nand_read_oob: from = 0x%08Lx, len = %i\n",
1264 (unsigned long long)from, readlen); 1273 (unsigned long long)from, readlen);
1265 1274
1275 if (ops->mode == MTD_OOB_RAW)
1276 len = mtd->oobsize;
1277 else
1278 len = chip->ecc.layout->oobavail;
1279
1266 chipnr = (int)(from >> chip->chip_shift); 1280 chipnr = (int)(from >> chip->chip_shift);
1267 chip->select_chip(mtd, chipnr); 1281 chip->select_chip(mtd, chipnr);
1268 1282
@@ -1270,11 +1284,11 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1270 realpage = (int)(from >> chip->page_shift); 1284 realpage = (int)(from >> chip->page_shift);
1271 page = realpage & chip->pagemask; 1285 page = realpage & chip->pagemask;
1272 1286
1273 chip->oob_poi = chip->buffers->oobrbuf;
1274
1275 while(1) { 1287 while(1) {
1276 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd); 1288 sndcmd = chip->ecc.read_oob(mtd, chip, page, sndcmd);
1277 buf = nand_transfer_oob(chip, buf, ops); 1289
1290 len = min(len, readlen);
1291 buf = nand_transfer_oob(chip, buf, ops, len);
1278 1292
1279 if (!(chip->options & NAND_NO_READRDY)) { 1293 if (!(chip->options & NAND_NO_READRDY)) {
1280 /* 1294 /*
@@ -1289,7 +1303,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1289 nand_wait_ready(mtd); 1303 nand_wait_ready(mtd);
1290 } 1304 }
1291 1305
1292 readlen -= ops->ooblen; 1306 readlen -= len;
1293 if (!readlen) 1307 if (!readlen)
1294 break; 1308 break;
1295 1309
@@ -1311,7 +1325,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
1311 sndcmd = 1; 1325 sndcmd = 1;
1312 } 1326 }
1313 1327
1314 ops->retlen = ops->len; 1328 ops->oobretlen = ops->ooblen;
1315 return 0; 1329 return 0;
1316} 1330}
1317 1331
@@ -1332,7 +1346,7 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1332 ops->retlen = 0; 1346 ops->retlen = 0;
1333 1347
1334 /* Do not allow reads past end of device */ 1348 /* Do not allow reads past end of device */
1335 if ((from + ops->len) > mtd->size) { 1349 if (ops->datbuf && (from + ops->len) > mtd->size) {
1336 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1350 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1337 "Attempt read beyond end of device\n"); 1351 "Attempt read beyond end of device\n");
1338 return -EINVAL; 1352 return -EINVAL;
@@ -1375,7 +1389,7 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1375} 1389}
1376 1390
1377/** 1391/**
1378 * nand_write_page_swecc - {REPLACABLE] software ecc based page write function 1392 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function
1379 * @mtd: mtd info structure 1393 * @mtd: mtd info structure
1380 * @chip: nand chip info structure 1394 * @chip: nand chip info structure
1381 * @buf: data buffer 1395 * @buf: data buffer
@@ -1401,7 +1415,7 @@ static void nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
1401} 1415}
1402 1416
1403/** 1417/**
1404 * nand_write_page_hwecc - {REPLACABLE] hardware ecc based page write function 1418 * nand_write_page_hwecc - [REPLACABLE] hardware ecc based page write function
1405 * @mtd: mtd info structure 1419 * @mtd: mtd info structure
1406 * @chip: nand chip info structure 1420 * @chip: nand chip info structure
1407 * @buf: data buffer 1421 * @buf: data buffer
@@ -1429,7 +1443,7 @@ static void nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
1429} 1443}
1430 1444
1431/** 1445/**
1432 * nand_write_page_syndrome - {REPLACABLE] hardware ecc syndrom based page write 1446 * nand_write_page_syndrome - [REPLACABLE] hardware ecc syndrom based page write
1433 * @mtd: mtd info structure 1447 * @mtd: mtd info structure
1434 * @chip: nand chip info structure 1448 * @chip: nand chip info structure
1435 * @buf: data buffer 1449 * @buf: data buffer
@@ -1577,7 +1591,7 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob,
1577 return NULL; 1591 return NULL;
1578} 1592}
1579 1593
1580#define NOTALIGNED(x) (x & (mtd->writesize-1)) != 0 1594#define NOTALIGNED(x) (x & (chip->subpagesize - 1)) != 0
1581 1595
1582/** 1596/**
1583 * nand_do_write_ops - [Internal] NAND write with ECC 1597 * nand_do_write_ops - [Internal] NAND write with ECC
@@ -1590,15 +1604,16 @@ static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob,
1590static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, 1604static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1591 struct mtd_oob_ops *ops) 1605 struct mtd_oob_ops *ops)
1592{ 1606{
1593 int chipnr, realpage, page, blockmask; 1607 int chipnr, realpage, page, blockmask, column;
1594 struct nand_chip *chip = mtd->priv; 1608 struct nand_chip *chip = mtd->priv;
1595 uint32_t writelen = ops->len; 1609 uint32_t writelen = ops->len;
1596 uint8_t *oob = ops->oobbuf; 1610 uint8_t *oob = ops->oobbuf;
1597 uint8_t *buf = ops->datbuf; 1611 uint8_t *buf = ops->datbuf;
1598 int bytes = mtd->writesize; 1612 int ret, subpage;
1599 int ret;
1600 1613
1601 ops->retlen = 0; 1614 ops->retlen = 0;
1615 if (!writelen)
1616 return 0;
1602 1617
1603 /* reject writes, which are not page aligned */ 1618 /* reject writes, which are not page aligned */
1604 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) { 1619 if (NOTALIGNED(to) || NOTALIGNED(ops->len)) {
@@ -1607,8 +1622,11 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1607 return -EINVAL; 1622 return -EINVAL;
1608 } 1623 }
1609 1624
1610 if (!writelen) 1625 column = to & (mtd->writesize - 1);
1611 return 0; 1626 subpage = column || (writelen & (mtd->writesize - 1));
1627
1628 if (subpage && oob)
1629 return -EINVAL;
1612 1630
1613 chipnr = (int)(to >> chip->chip_shift); 1631 chipnr = (int)(to >> chip->chip_shift);
1614 chip->select_chip(mtd, chipnr); 1632 chip->select_chip(mtd, chipnr);
@@ -1626,15 +1644,29 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1626 (chip->pagebuf << chip->page_shift) < (to + ops->len)) 1644 (chip->pagebuf << chip->page_shift) < (to + ops->len))
1627 chip->pagebuf = -1; 1645 chip->pagebuf = -1;
1628 1646
1629 chip->oob_poi = chip->buffers->oobwbuf; 1647 /* If we're not given explicit OOB data, let it be 0xFF */
1648 if (likely(!oob))
1649 memset(chip->oob_poi, 0xff, mtd->oobsize);
1630 1650
1631 while(1) { 1651 while(1) {
1652 int bytes = mtd->writesize;
1632 int cached = writelen > bytes && page != blockmask; 1653 int cached = writelen > bytes && page != blockmask;
1654 uint8_t *wbuf = buf;
1655
1656 /* Partial page write ? */
1657 if (unlikely(column || writelen < (mtd->writesize - 1))) {
1658 cached = 0;
1659 bytes = min_t(int, bytes - column, (int) writelen);
1660 chip->pagebuf = -1;
1661 memset(chip->buffers->databuf, 0xff, mtd->writesize);
1662 memcpy(&chip->buffers->databuf[column], buf, bytes);
1663 wbuf = chip->buffers->databuf;
1664 }
1633 1665
1634 if (unlikely(oob)) 1666 if (unlikely(oob))
1635 oob = nand_fill_oob(chip, oob, ops); 1667 oob = nand_fill_oob(chip, oob, ops);
1636 1668
1637 ret = chip->write_page(mtd, chip, buf, page, cached, 1669 ret = chip->write_page(mtd, chip, wbuf, page, cached,
1638 (ops->mode == MTD_OOB_RAW)); 1670 (ops->mode == MTD_OOB_RAW));
1639 if (ret) 1671 if (ret)
1640 break; 1672 break;
@@ -1643,6 +1675,7 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1643 if (!writelen) 1675 if (!writelen)
1644 break; 1676 break;
1645 1677
1678 column = 0;
1646 buf += bytes; 1679 buf += bytes;
1647 realpage++; 1680 realpage++;
1648 1681
@@ -1655,10 +1688,9 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to,
1655 } 1688 }
1656 } 1689 }
1657 1690
1658 if (unlikely(oob))
1659 memset(chip->oob_poi, 0xff, mtd->oobsize);
1660
1661 ops->retlen = ops->len - writelen; 1691 ops->retlen = ops->len - writelen;
1692 if (unlikely(oob))
1693 ops->oobretlen = ops->ooblen;
1662 return ret; 1694 return ret;
1663} 1695}
1664 1696
@@ -1714,10 +1746,10 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1714 struct nand_chip *chip = mtd->priv; 1746 struct nand_chip *chip = mtd->priv;
1715 1747
1716 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n", 1748 DEBUG(MTD_DEBUG_LEVEL3, "nand_write_oob: to = 0x%08x, len = %i\n",
1717 (unsigned int)to, (int)ops->len); 1749 (unsigned int)to, (int)ops->ooblen);
1718 1750
1719 /* Do not allow write past end of page */ 1751 /* Do not allow write past end of page */
1720 if ((ops->ooboffs + ops->len) > mtd->oobsize) { 1752 if ((ops->ooboffs + ops->ooblen) > mtd->oobsize) {
1721 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: " 1753 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1722 "Attempt to write past end of page\n"); 1754 "Attempt to write past end of page\n");
1723 return -EINVAL; 1755 return -EINVAL;
@@ -1745,7 +1777,6 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1745 if (page == chip->pagebuf) 1777 if (page == chip->pagebuf)
1746 chip->pagebuf = -1; 1778 chip->pagebuf = -1;
1747 1779
1748 chip->oob_poi = chip->buffers->oobwbuf;
1749 memset(chip->oob_poi, 0xff, mtd->oobsize); 1780 memset(chip->oob_poi, 0xff, mtd->oobsize);
1750 nand_fill_oob(chip, ops->oobbuf, ops); 1781 nand_fill_oob(chip, ops->oobbuf, ops);
1751 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); 1782 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask);
@@ -1754,7 +1785,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1754 if (status) 1785 if (status)
1755 return status; 1786 return status;
1756 1787
1757 ops->retlen = ops->len; 1788 ops->oobretlen = ops->ooblen;
1758 1789
1759 return 0; 1790 return 0;
1760} 1791}
@@ -1774,7 +1805,7 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1774 ops->retlen = 0; 1805 ops->retlen = 0;
1775 1806
1776 /* Do not allow writes past end of device */ 1807 /* Do not allow writes past end of device */
1777 if ((to + ops->len) > mtd->size) { 1808 if (ops->datbuf && (to + ops->len) > mtd->size) {
1778 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1809 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
1779 "Attempt read beyond end of device\n"); 1810 "Attempt read beyond end of device\n");
1780 return -EINVAL; 1811 return -EINVAL;
@@ -2188,8 +2219,8 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2188 /* Newer devices have all the information in additional id bytes */ 2219 /* Newer devices have all the information in additional id bytes */
2189 if (!type->pagesize) { 2220 if (!type->pagesize) {
2190 int extid; 2221 int extid;
2191 /* The 3rd id byte contains non relevant data ATM */ 2222 /* The 3rd id byte holds MLC / multichip data */
2192 extid = chip->read_byte(mtd); 2223 chip->cellinfo = chip->read_byte(mtd);
2193 /* The 4th id byte is the important one */ 2224 /* The 4th id byte is the important one */
2194 extid = chip->read_byte(mtd); 2225 extid = chip->read_byte(mtd);
2195 /* Calc pagesize */ 2226 /* Calc pagesize */
@@ -2349,8 +2380,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2349 if (!chip->buffers) 2380 if (!chip->buffers)
2350 return -ENOMEM; 2381 return -ENOMEM;
2351 2382
2352 /* Preset the internal oob write buffer */ 2383 /* Set the internal oob buffer location, just after the page data */
2353 memset(chip->buffers->oobwbuf, 0xff, mtd->oobsize); 2384 chip->oob_poi = chip->buffers->databuf + mtd->writesize;
2354 2385
2355 /* 2386 /*
2356 * If no default placement scheme is given, select an appropriate one 2387 * If no default placement scheme is given, select an appropriate one
@@ -2469,6 +2500,24 @@ int nand_scan_tail(struct mtd_info *mtd)
2469 } 2500 }
2470 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes; 2501 chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
2471 2502
2503 /*
2504 * Allow subpage writes up to ecc.steps. Not possible for MLC
2505 * FLASH.
2506 */
2507 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
2508 !(chip->cellinfo & NAND_CI_CELLTYPE_MSK)) {
2509 switch(chip->ecc.steps) {
2510 case 2:
2511 mtd->subpage_sft = 1;
2512 break;
2513 case 4:
2514 case 8:
2515 mtd->subpage_sft = 2;
2516 break;
2517 }
2518 }
2519 chip->subpagesize = mtd->writesize >> mtd->subpage_sft;
2520
2472 /* Initialize state */ 2521 /* Initialize state */
2473 chip->state = FL_READY; 2522 chip->state = FL_READY;
2474 2523
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 9402653eb09b..5e121ceaa598 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -333,7 +333,6 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
333 struct mtd_oob_ops ops; 333 struct mtd_oob_ops ops;
334 int j, ret; 334 int j, ret;
335 335
336 ops.len = mtd->oobsize;
337 ops.ooblen = mtd->oobsize; 336 ops.ooblen = mtd->oobsize;
338 ops.oobbuf = buf; 337 ops.oobbuf = buf;
339 ops.ooboffs = 0; 338 ops.ooboffs = 0;
@@ -676,10 +675,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
676 "bad block table\n"); 675 "bad block table\n");
677 } 676 }
678 /* Read oob data */ 677 /* Read oob data */
679 ops.len = (len >> this->page_shift) * mtd->oobsize; 678 ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
680 ops.oobbuf = &buf[len]; 679 ops.oobbuf = &buf[len];
681 res = mtd->read_oob(mtd, to + mtd->writesize, &ops); 680 res = mtd->read_oob(mtd, to + mtd->writesize, &ops);
682 if (res < 0 || ops.retlen != ops.len) 681 if (res < 0 || ops.oobretlen != ops.ooblen)
683 goto outerr; 682 goto outerr;
684 683
685 /* Calc the byte offset in the buffer */ 684 /* Calc the byte offset in the buffer */
@@ -961,14 +960,12 @@ int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
961 struct nand_bbt_descr *md = this->bbt_md; 960 struct nand_bbt_descr *md = this->bbt_md;
962 961
963 len = mtd->size >> (this->bbt_erase_shift + 2); 962 len = mtd->size >> (this->bbt_erase_shift + 2);
964 /* Allocate memory (2bit per block) */ 963 /* Allocate memory (2bit per block) and clear the memory bad block table */
965 this->bbt = kmalloc(len, GFP_KERNEL); 964 this->bbt = kzalloc(len, GFP_KERNEL);
966 if (!this->bbt) { 965 if (!this->bbt) {
967 printk(KERN_ERR "nand_scan_bbt: Out of memory\n"); 966 printk(KERN_ERR "nand_scan_bbt: Out of memory\n");
968 return -ENOMEM; 967 return -ENOMEM;
969 } 968 }
970 /* Clear the memory bad block table */
971 memset(this->bbt, 0x00, len);
972 969
973 /* If no primary table decriptor is given, scan the device 970 /* If no primary table decriptor is given, scan the device
974 * to build a memory based bad block table 971 * to build a memory based bad block table
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c
index dd438ca47d9a..fde593e5e634 100644
--- a/drivers/mtd/nand/nand_ecc.c
+++ b/drivers/mtd/nand/nand_ecc.c
@@ -112,7 +112,7 @@ int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
112 tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */ 112 tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */
113 113
114 /* Calculate final ECC code */ 114 /* Calculate final ECC code */
115#ifdef CONFIG_NAND_ECC_SMC 115#ifdef CONFIG_MTD_NAND_ECC_SMC
116 ecc_code[0] = ~tmp2; 116 ecc_code[0] = ~tmp2;
117 ecc_code[1] = ~tmp1; 117 ecc_code[1] = ~tmp1;
118#else 118#else
@@ -148,7 +148,7 @@ int nand_correct_data(struct mtd_info *mtd, u_char *dat,
148{ 148{
149 uint8_t s0, s1, s2; 149 uint8_t s0, s1, s2;
150 150
151#ifdef CONFIG_NAND_ECC_SMC 151#ifdef CONFIG_MTD_NAND_ECC_SMC
152 s0 = calc_ecc[0] ^ read_ecc[0]; 152 s0 = calc_ecc[0] ^ read_ecc[0];
153 s1 = calc_ecc[1] ^ read_ecc[1]; 153 s1 = calc_ecc[1] ^ read_ecc[1];
154 s2 = calc_ecc[2] ^ read_ecc[2]; 154 s2 = calc_ecc[2] ^ read_ecc[2];
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 545ff252d81e..c3bca9590ad2 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -37,10 +37,6 @@
37#include <linux/mtd/nand.h> 37#include <linux/mtd/nand.h>
38#include <linux/mtd/partitions.h> 38#include <linux/mtd/partitions.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#ifdef CONFIG_NS_ABS_POS
41#include <asm/io.h>
42#endif
43
44 40
45/* Default simulator parameters values */ 41/* Default simulator parameters values */
46#if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \ 42#if !defined(CONFIG_NANDSIM_FIRST_ID_BYTE) || \
@@ -164,7 +160,7 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
164/* After a command is input, the simulator goes to one of the following states */ 160/* After a command is input, the simulator goes to one of the following states */
165#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */ 161#define STATE_CMD_READ0 0x00000001 /* read data from the beginning of page */
166#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */ 162#define STATE_CMD_READ1 0x00000002 /* read data from the second half of page */
167#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */ 163#define STATE_CMD_READSTART 0x00000003 /* read data second command (large page devices) */
168#define STATE_CMD_PAGEPROG 0x00000004 /* start page programm */ 164#define STATE_CMD_PAGEPROG 0x00000004 /* start page programm */
169#define STATE_CMD_READOOB 0x00000005 /* read OOB area */ 165#define STATE_CMD_READOOB 0x00000005 /* read OOB area */
170#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */ 166#define STATE_CMD_ERASE1 0x00000006 /* sector erase first command */
@@ -231,6 +227,14 @@ MODULE_PARM_DESC(dbg, "Output debug information if not zero");
231#define NS_MAX_PREVSTATES 1 227#define NS_MAX_PREVSTATES 1
232 228
233/* 229/*
230 * A union to represent flash memory contents and flash buffer.
231 */
232union ns_mem {
233 u_char *byte; /* for byte access */
234 uint16_t *word; /* for 16-bit word access */
235};
236
237/*
234 * The structure which describes all the internal simulator data. 238 * The structure which describes all the internal simulator data.
235 */ 239 */
236struct nandsim { 240struct nandsim {
@@ -247,17 +251,11 @@ struct nandsim {
247 uint16_t npstates; /* number of previous states saved */ 251 uint16_t npstates; /* number of previous states saved */
248 uint16_t stateidx; /* current state index */ 252 uint16_t stateidx; /* current state index */
249 253
250 /* The simulated NAND flash image */ 254 /* The simulated NAND flash pages array */
251 union flash_media { 255 union ns_mem *pages;
252 u_char *byte;
253 uint16_t *word;
254 } mem;
255 256
256 /* Internal buffer of page + OOB size bytes */ 257 /* Internal buffer of page + OOB size bytes */
257 union internal_buffer { 258 union ns_mem buf;
258 u_char *byte; /* for byte access */
259 uint16_t *word; /* for 16-bit word access */
260 } buf;
261 259
262 /* NAND flash "geometry" */ 260 /* NAND flash "geometry" */
263 struct nandsin_geometry { 261 struct nandsin_geometry {
@@ -346,12 +344,49 @@ static struct mtd_info *nsmtd;
346static u_char ns_verify_buf[NS_LARGEST_PAGE_SIZE]; 344static u_char ns_verify_buf[NS_LARGEST_PAGE_SIZE];
347 345
348/* 346/*
347 * Allocate array of page pointers and initialize the array to NULL
348 * pointers.
349 *
350 * RETURNS: 0 if success, -ENOMEM if memory alloc fails.
351 */
352static int alloc_device(struct nandsim *ns)
353{
354 int i;
355
356 ns->pages = vmalloc(ns->geom.pgnum * sizeof(union ns_mem));
357 if (!ns->pages) {
358 NS_ERR("alloc_map: unable to allocate page array\n");
359 return -ENOMEM;
360 }
361 for (i = 0; i < ns->geom.pgnum; i++) {
362 ns->pages[i].byte = NULL;
363 }
364
365 return 0;
366}
367
368/*
369 * Free any allocated pages, and free the array of page pointers.
370 */
371static void free_device(struct nandsim *ns)
372{
373 int i;
374
375 if (ns->pages) {
376 for (i = 0; i < ns->geom.pgnum; i++) {
377 if (ns->pages[i].byte)
378 kfree(ns->pages[i].byte);
379 }
380 vfree(ns->pages);
381 }
382}
383
384/*
349 * Initialize the nandsim structure. 385 * Initialize the nandsim structure.
350 * 386 *
351 * RETURNS: 0 if success, -ERRNO if failure. 387 * RETURNS: 0 if success, -ERRNO if failure.
352 */ 388 */
353static int 389static int init_nandsim(struct mtd_info *mtd)
354init_nandsim(struct mtd_info *mtd)
355{ 390{
356 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 391 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
357 struct nandsim *ns = (struct nandsim *)(chip->priv); 392 struct nandsim *ns = (struct nandsim *)(chip->priv);
@@ -405,7 +440,7 @@ init_nandsim(struct mtd_info *mtd)
405 } 440 }
406 } else { 441 } else {
407 if (ns->geom.totsz <= (128 << 20)) { 442 if (ns->geom.totsz <= (128 << 20)) {
408 ns->geom.pgaddrbytes = 5; 443 ns->geom.pgaddrbytes = 4;
409 ns->geom.secaddrbytes = 2; 444 ns->geom.secaddrbytes = 2;
410 } else { 445 } else {
411 ns->geom.pgaddrbytes = 5; 446 ns->geom.pgaddrbytes = 5;
@@ -439,23 +474,8 @@ init_nandsim(struct mtd_info *mtd)
439 printk("sector address bytes: %u\n", ns->geom.secaddrbytes); 474 printk("sector address bytes: %u\n", ns->geom.secaddrbytes);
440 printk("options: %#x\n", ns->options); 475 printk("options: %#x\n", ns->options);
441 476
442 /* Map / allocate and initialize the flash image */ 477 if (alloc_device(ns) != 0)
443#ifdef CONFIG_NS_ABS_POS 478 goto error;
444 ns->mem.byte = ioremap(CONFIG_NS_ABS_POS, ns->geom.totszoob);
445 if (!ns->mem.byte) {
446 NS_ERR("init_nandsim: failed to map the NAND flash image at address %p\n",
447 (void *)CONFIG_NS_ABS_POS);
448 return -ENOMEM;
449 }
450#else
451 ns->mem.byte = vmalloc(ns->geom.totszoob);
452 if (!ns->mem.byte) {
453 NS_ERR("init_nandsim: unable to allocate %u bytes for flash image\n",
454 ns->geom.totszoob);
455 return -ENOMEM;
456 }
457 memset(ns->mem.byte, 0xFF, ns->geom.totszoob);
458#endif
459 479
460 /* Allocate / initialize the internal buffer */ 480 /* Allocate / initialize the internal buffer */
461 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); 481 ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
@@ -474,11 +494,7 @@ init_nandsim(struct mtd_info *mtd)
474 return 0; 494 return 0;
475 495
476error: 496error:
477#ifdef CONFIG_NS_ABS_POS 497 free_device(ns);
478 iounmap(ns->mem.byte);
479#else
480 vfree(ns->mem.byte);
481#endif
482 498
483 return -ENOMEM; 499 return -ENOMEM;
484} 500}
@@ -486,16 +502,10 @@ error:
486/* 502/*
487 * Free the nandsim structure. 503 * Free the nandsim structure.
488 */ 504 */
489static void 505static void free_nandsim(struct nandsim *ns)
490free_nandsim(struct nandsim *ns)
491{ 506{
492 kfree(ns->buf.byte); 507 kfree(ns->buf.byte);
493 508 free_device(ns);
494#ifdef CONFIG_NS_ABS_POS
495 iounmap(ns->mem.byte);
496#else
497 vfree(ns->mem.byte);
498#endif
499 509
500 return; 510 return;
501} 511}
@@ -503,8 +513,7 @@ free_nandsim(struct nandsim *ns)
503/* 513/*
504 * Returns the string representation of 'state' state. 514 * Returns the string representation of 'state' state.
505 */ 515 */
506static char * 516static char *get_state_name(uint32_t state)
507get_state_name(uint32_t state)
508{ 517{
509 switch (NS_STATE(state)) { 518 switch (NS_STATE(state)) {
510 case STATE_CMD_READ0: 519 case STATE_CMD_READ0:
@@ -562,8 +571,7 @@ get_state_name(uint32_t state)
562 * 571 *
563 * RETURNS: 1 if wrong command, 0 if right. 572 * RETURNS: 1 if wrong command, 0 if right.
564 */ 573 */
565static int 574static int check_command(int cmd)
566check_command(int cmd)
567{ 575{
568 switch (cmd) { 576 switch (cmd) {
569 577
@@ -589,8 +597,7 @@ check_command(int cmd)
589/* 597/*
590 * Returns state after command is accepted by command number. 598 * Returns state after command is accepted by command number.
591 */ 599 */
592static uint32_t 600static uint32_t get_state_by_command(unsigned command)
593get_state_by_command(unsigned command)
594{ 601{
595 switch (command) { 602 switch (command) {
596 case NAND_CMD_READ0: 603 case NAND_CMD_READ0:
@@ -626,8 +633,7 @@ get_state_by_command(unsigned command)
626/* 633/*
627 * Move an address byte to the correspondent internal register. 634 * Move an address byte to the correspondent internal register.
628 */ 635 */
629static inline void 636static inline void accept_addr_byte(struct nandsim *ns, u_char bt)
630accept_addr_byte(struct nandsim *ns, u_char bt)
631{ 637{
632 uint byte = (uint)bt; 638 uint byte = (uint)bt;
633 639
@@ -645,8 +651,7 @@ accept_addr_byte(struct nandsim *ns, u_char bt)
645/* 651/*
646 * Switch to STATE_READY state. 652 * Switch to STATE_READY state.
647 */ 653 */
648static inline void 654static inline void switch_to_ready_state(struct nandsim *ns, u_char status)
649switch_to_ready_state(struct nandsim *ns, u_char status)
650{ 655{
651 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY)); 656 NS_DBG("switch_to_ready_state: switch to %s state\n", get_state_name(STATE_READY));
652 657
@@ -705,8 +710,7 @@ switch_to_ready_state(struct nandsim *ns, u_char status)
705 * -1 - several matches. 710 * -1 - several matches.
706 * 0 - operation is found. 711 * 0 - operation is found.
707 */ 712 */
708static int 713static int find_operation(struct nandsim *ns, uint32_t flag)
709find_operation(struct nandsim *ns, uint32_t flag)
710{ 714{
711 int opsfound = 0; 715 int opsfound = 0;
712 int i, j, idx = 0; 716 int i, j, idx = 0;
@@ -791,14 +795,93 @@ find_operation(struct nandsim *ns, uint32_t flag)
791} 795}
792 796
793/* 797/*
798 * Returns a pointer to the current page.
799 */
800static inline union ns_mem *NS_GET_PAGE(struct nandsim *ns)
801{
802 return &(ns->pages[ns->regs.row]);
803}
804
805/*
806 * Retuns a pointer to the current byte, within the current page.
807 */
808static inline u_char *NS_PAGE_BYTE_OFF(struct nandsim *ns)
809{
810 return NS_GET_PAGE(ns)->byte + ns->regs.column + ns->regs.off;
811}
812
813/*
814 * Fill the NAND buffer with data read from the specified page.
815 */
816static void read_page(struct nandsim *ns, int num)
817{
818 union ns_mem *mypage;
819
820 mypage = NS_GET_PAGE(ns);
821 if (mypage->byte == NULL) {
822 NS_DBG("read_page: page %d not allocated\n", ns->regs.row);
823 memset(ns->buf.byte, 0xFF, num);
824 } else {
825 NS_DBG("read_page: page %d allocated, reading from %d\n",
826 ns->regs.row, ns->regs.column + ns->regs.off);
827 memcpy(ns->buf.byte, NS_PAGE_BYTE_OFF(ns), num);
828 }
829}
830
831/*
832 * Erase all pages in the specified sector.
833 */
834static void erase_sector(struct nandsim *ns)
835{
836 union ns_mem *mypage;
837 int i;
838
839 mypage = NS_GET_PAGE(ns);
840 for (i = 0; i < ns->geom.pgsec; i++) {
841 if (mypage->byte != NULL) {
842 NS_DBG("erase_sector: freeing page %d\n", ns->regs.row+i);
843 kfree(mypage->byte);
844 mypage->byte = NULL;
845 }
846 mypage++;
847 }
848}
849
850/*
851 * Program the specified page with the contents from the NAND buffer.
852 */
853static int prog_page(struct nandsim *ns, int num)
854{
855 int i;
856 union ns_mem *mypage;
857 u_char *pg_off;
858
859 mypage = NS_GET_PAGE(ns);
860 if (mypage->byte == NULL) {
861 NS_DBG("prog_page: allocating page %d\n", ns->regs.row);
862 mypage->byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
863 if (mypage->byte == NULL) {
864 NS_ERR("prog_page: error allocating memory for page %d\n", ns->regs.row);
865 return -1;
866 }
867 memset(mypage->byte, 0xFF, ns->geom.pgszoob);
868 }
869
870 pg_off = NS_PAGE_BYTE_OFF(ns);
871 for (i = 0; i < num; i++)
872 pg_off[i] &= ns->buf.byte[i];
873
874 return 0;
875}
876
877/*
794 * If state has any action bit, perform this action. 878 * If state has any action bit, perform this action.
795 * 879 *
796 * RETURNS: 0 if success, -1 if error. 880 * RETURNS: 0 if success, -1 if error.
797 */ 881 */
798static int 882static int do_state_action(struct nandsim *ns, uint32_t action)
799do_state_action(struct nandsim *ns, uint32_t action)
800{ 883{
801 int i, num; 884 int num;
802 int busdiv = ns->busw == 8 ? 1 : 2; 885 int busdiv = ns->busw == 8 ? 1 : 2;
803 886
804 action &= ACTION_MASK; 887 action &= ACTION_MASK;
@@ -822,7 +905,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
822 break; 905 break;
823 } 906 }
824 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column; 907 num = ns->geom.pgszoob - ns->regs.off - ns->regs.column;
825 memcpy(ns->buf.byte, ns->mem.byte + NS_RAW_OFFSET(ns) + ns->regs.off, num); 908 read_page(ns, num);
826 909
827 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n", 910 NS_DBG("do_state_action: (ACTION_CPY:) copy %d bytes to int buf, raw offset %d\n",
828 num, NS_RAW_OFFSET(ns) + ns->regs.off); 911 num, NS_RAW_OFFSET(ns) + ns->regs.off);
@@ -863,7 +946,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
863 ns->regs.row, NS_RAW_OFFSET(ns)); 946 ns->regs.row, NS_RAW_OFFSET(ns));
864 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift)); 947 NS_LOG("erase sector %d\n", ns->regs.row >> (ns->geom.secshift - ns->geom.pgshift));
865 948
866 memset(ns->mem.byte + NS_RAW_OFFSET(ns), 0xFF, ns->geom.secszoob); 949 erase_sector(ns);
867 950
868 NS_MDELAY(erase_delay); 951 NS_MDELAY(erase_delay);
869 952
@@ -886,8 +969,8 @@ do_state_action(struct nandsim *ns, uint32_t action)
886 return -1; 969 return -1;
887 } 970 }
888 971
889 for (i = 0; i < num; i++) 972 if (prog_page(ns, num) == -1)
890 ns->mem.byte[NS_RAW_OFFSET(ns) + ns->regs.off + i] &= ns->buf.byte[i]; 973 return -1;
891 974
892 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n", 975 NS_DBG("do_state_action: copy %d bytes from int buf to (%#x, %#x), raw off = %d\n",
893 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off); 976 num, ns->regs.row, ns->regs.column, NS_RAW_OFFSET(ns) + ns->regs.off);
@@ -928,8 +1011,7 @@ do_state_action(struct nandsim *ns, uint32_t action)
928/* 1011/*
929 * Switch simulator's state. 1012 * Switch simulator's state.
930 */ 1013 */
931static void 1014static void switch_state(struct nandsim *ns)
932switch_state(struct nandsim *ns)
933{ 1015{
934 if (ns->op) { 1016 if (ns->op) {
935 /* 1017 /*
@@ -1070,8 +1152,7 @@ switch_state(struct nandsim *ns)
1070 } 1152 }
1071} 1153}
1072 1154
1073static u_char 1155static u_char ns_nand_read_byte(struct mtd_info *mtd)
1074ns_nand_read_byte(struct mtd_info *mtd)
1075{ 1156{
1076 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1157 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1077 u_char outb = 0x00; 1158 u_char outb = 0x00;
@@ -1144,8 +1225,7 @@ ns_nand_read_byte(struct mtd_info *mtd)
1144 return outb; 1225 return outb;
1145} 1226}
1146 1227
1147static void 1228static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1148ns_nand_write_byte(struct mtd_info *mtd, u_char byte)
1149{ 1229{
1150 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1230 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1151 1231
@@ -1308,15 +1388,13 @@ static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask)
1308 ns_nand_write_byte(mtd, cmd); 1388 ns_nand_write_byte(mtd, cmd);
1309} 1389}
1310 1390
1311static int 1391static int ns_device_ready(struct mtd_info *mtd)
1312ns_device_ready(struct mtd_info *mtd)
1313{ 1392{
1314 NS_DBG("device_ready\n"); 1393 NS_DBG("device_ready\n");
1315 return 1; 1394 return 1;
1316} 1395}
1317 1396
1318static uint16_t 1397static uint16_t ns_nand_read_word(struct mtd_info *mtd)
1319ns_nand_read_word(struct mtd_info *mtd)
1320{ 1398{
1321 struct nand_chip *chip = (struct nand_chip *)mtd->priv; 1399 struct nand_chip *chip = (struct nand_chip *)mtd->priv;
1322 1400
@@ -1325,8 +1403,7 @@ ns_nand_read_word(struct mtd_info *mtd)
1325 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8); 1403 return chip->read_byte(mtd) | (chip->read_byte(mtd) << 8);
1326} 1404}
1327 1405
1328static void 1406static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1329ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1330{ 1407{
1331 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1408 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1332 1409
@@ -1353,8 +1430,7 @@ ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
1353 } 1430 }
1354} 1431}
1355 1432
1356static void 1433static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1357ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1358{ 1434{
1359 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv; 1435 struct nandsim *ns = (struct nandsim *)((struct nand_chip *)mtd->priv)->priv;
1360 1436
@@ -1407,8 +1483,7 @@ ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
1407 return; 1483 return;
1408} 1484}
1409 1485
1410static int 1486static int ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1411ns_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
1412{ 1487{
1413 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len); 1488 ns_nand_read_buf(mtd, (u_char *)&ns_verify_buf[0], len);
1414 1489
@@ -1436,14 +1511,12 @@ static int __init ns_init_module(void)
1436 } 1511 }
1437 1512
1438 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ 1513 /* Allocate and initialize mtd_info, nand_chip and nandsim structures */
1439 nsmtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) 1514 nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip)
1440 + sizeof(struct nandsim), GFP_KERNEL); 1515 + sizeof(struct nandsim), GFP_KERNEL);
1441 if (!nsmtd) { 1516 if (!nsmtd) {
1442 NS_ERR("unable to allocate core structures.\n"); 1517 NS_ERR("unable to allocate core structures.\n");
1443 return -ENOMEM; 1518 return -ENOMEM;
1444 } 1519 }
1445 memset(nsmtd, 0, sizeof(struct mtd_info) + sizeof(struct nand_chip) +
1446 sizeof(struct nandsim));
1447 chip = (struct nand_chip *)(nsmtd + 1); 1520 chip = (struct nand_chip *)(nsmtd + 1);
1448 nsmtd->priv = (void *)chip; 1521 nsmtd->priv = (void *)chip;
1449 nand = (struct nandsim *)(chip + 1); 1522 nand = (struct nandsim *)(chip + 1);
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 039c759cfbfc..fd7a8d5ba29a 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -56,7 +56,7 @@ static void ndfc_select_chip(struct mtd_info *mtd, int chip)
56 ccr |= NDFC_CCR_BS(chip + pchip->chip_offset); 56 ccr |= NDFC_CCR_BS(chip + pchip->chip_offset);
57 } else 57 } else
58 ccr |= NDFC_CCR_RESET_CE; 58 ccr |= NDFC_CCR_RESET_CE;
59 writel(ccr, ndfc->ndfcbase + NDFC_CCR); 59 __raw_writel(ccr, ndfc->ndfcbase + NDFC_CCR);
60} 60}
61 61
62static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 62static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index f8c49645324d..9189ec8f243e 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/rslib.h> 26#include <linux/rslib.h>
27#include <linux/bitrev.h>
27#include <linux/module.h> 28#include <linux/module.h>
28#include <linux/mtd/compatmac.h> 29#include <linux/mtd/compatmac.h>
29#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
@@ -152,47 +153,6 @@ static struct nand_ecclayout rtc_from4_nand_oobinfo = {
152 .oobfree = {{32, 32}} 153 .oobfree = {{32, 32}}
153}; 154};
154 155
155/* Aargh. I missed the reversed bit order, when I
156 * was talking to Renesas about the FPGA.
157 *
158 * The table is used for bit reordering and inversion
159 * of the ecc byte which we get from the FPGA
160 */
161static uint8_t revbits[256] = {
162 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
163 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
164 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
165 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
166 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
167 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
168 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
169 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
170 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
171 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
172 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
173 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
174 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
175 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
176 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
177 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
178 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
179 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
180 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
181 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
182 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
183 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
184 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
185 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
186 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
187 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
188 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
189 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
190 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
191 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
192 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
193 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
194};
195
196#endif 156#endif
197 157
198/* 158/*
@@ -397,7 +357,7 @@ static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_cha
397 /* Read the syndrom pattern from the FPGA and correct the bitorder */ 357 /* Read the syndrom pattern from the FPGA and correct the bitorder */
398 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC); 358 rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC);
399 for (i = 0; i < 8; i++) { 359 for (i = 0; i < 8; i++) {
400 ecc[i] = revbits[(*rs_ecc) & 0xFF]; 360 ecc[i] = bitrev8(*rs_ecc);
401 rs_ecc++; 361 rs_ecc++;
402 } 362 }
403 363
@@ -496,7 +456,7 @@ static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this,
496 rtn = nand_do_read(mtd, page, len, &retlen, buf); 456 rtn = nand_do_read(mtd, page, len, &retlen, buf);
497 457
498 /* if read failed or > 1-bit error corrected */ 458 /* if read failed or > 1-bit error corrected */
499 if (rtn || (mtd->ecc_stats.corrected - corrected) > 1) { 459 if (rtn || (mtd->ecc_stats.corrected - corrected) > 1)
500 er_stat |= 1 << 1; 460 er_stat |= 1 << 1;
501 kfree(buf); 461 kfree(buf);
502 } 462 }
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index ff5cef24d5bb..8b3203571eeb 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -283,7 +283,7 @@ static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd,
283 unsigned int ctrl) 283 unsigned int ctrl)
284{ 284{
285 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 285 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
286 286
287 if (cmd == NAND_CMD_NONE) 287 if (cmd == NAND_CMD_NONE)
288 return; 288 return;
289 289
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index b5a5f8da4722..4b1ba4fcfcd3 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -57,17 +57,16 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
57 57
58 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name); 58 DEBUG(MTD_DEBUG_LEVEL1, "NFTL: add_mtd for %s\n", mtd->name);
59 59
60 nftl = kmalloc(sizeof(struct NFTLrecord), GFP_KERNEL); 60 nftl = kzalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
61 61
62 if (!nftl) { 62 if (!nftl) {
63 printk(KERN_WARNING "NFTL: out of memory for data structures\n"); 63 printk(KERN_WARNING "NFTL: out of memory for data structures\n");
64 return; 64 return;
65 } 65 }
66 memset(nftl, 0, sizeof(*nftl));
67 66
68 nftl->mbd.mtd = mtd; 67 nftl->mbd.mtd = mtd;
69 nftl->mbd.devnum = -1; 68 nftl->mbd.devnum = -1;
70 nftl->mbd.blksize = 512; 69
71 nftl->mbd.tr = tr; 70 nftl->mbd.tr = tr;
72 71
73 if (NFTL_mount(nftl) < 0) { 72 if (NFTL_mount(nftl) < 0) {
@@ -147,10 +146,9 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
147 ops.ooblen = len; 146 ops.ooblen = len;
148 ops.oobbuf = buf; 147 ops.oobbuf = buf;
149 ops.datbuf = NULL; 148 ops.datbuf = NULL;
150 ops.len = len;
151 149
152 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 150 res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
153 *retlen = ops.retlen; 151 *retlen = ops.oobretlen;
154 return res; 152 return res;
155} 153}
156 154
@@ -168,10 +166,9 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
168 ops.ooblen = len; 166 ops.ooblen = len;
169 ops.oobbuf = buf; 167 ops.oobbuf = buf;
170 ops.datbuf = NULL; 168 ops.datbuf = NULL;
171 ops.len = len;
172 169
173 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); 170 res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops);
174 *retlen = ops.retlen; 171 *retlen = ops.oobretlen;
175 return res; 172 return res;
176} 173}
177 174
@@ -797,6 +794,7 @@ static struct mtd_blktrans_ops nftl_tr = {
797 .name = "nftl", 794 .name = "nftl",
798 .major = NFTL_MAJOR, 795 .major = NFTL_MAJOR,
799 .part_bits = NFTL_PARTN_BITS, 796 .part_bits = NFTL_PARTN_BITS,
797 .blksize = 512,
800 .getgeo = nftl_getgeo, 798 .getgeo = nftl_getgeo,
801 .readsect = nftl_readblock, 799 .readsect = nftl_readblock,
802#ifdef CONFIG_NFTL_RW 800#ifdef CONFIG_NFTL_RW
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
index af06a80f44de..3d44d040a47d 100644
--- a/drivers/mtd/onenand/generic.c
+++ b/drivers/mtd/onenand/generic.c
@@ -45,12 +45,10 @@ static int __devinit generic_onenand_probe(struct device *dev)
45 unsigned long size = res->end - res->start + 1; 45 unsigned long size = res->end - res->start + 1;
46 int err; 46 int err;
47 47
48 info = kmalloc(sizeof(struct onenand_info), GFP_KERNEL); 48 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
49 if (!info) 49 if (!info)
50 return -ENOMEM; 50 return -ENOMEM;
51 51
52 memset(info, 0, sizeof(struct onenand_info));
53
54 if (!request_mem_region(res->start, size, dev->driver->name)) { 52 if (!request_mem_region(res->start, size, dev->driver->name)) {
55 err = -EBUSY; 53 err = -EBUSY;
56 goto out_free_info; 54 goto out_free_info;
@@ -63,6 +61,7 @@ static int __devinit generic_onenand_probe(struct device *dev)
63 } 61 }
64 62
65 info->onenand.mmcontrol = pdata->mmcontrol; 63 info->onenand.mmcontrol = pdata->mmcontrol;
64 info->onenand.irq = platform_get_irq(pdev, 0);
66 65
67 info->mtd.name = pdev->dev.bus_id; 66 info->mtd.name = pdev->dev.bus_id;
68 info->mtd.priv = &info->onenand; 67 info->mtd.priv = &info->onenand;
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 8ed68b28afe3..2da6bb26353e 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/interrupt.h>
16#include <linux/jiffies.h> 17#include <linux/jiffies.h>
17#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
18#include <linux/mtd/onenand.h> 19#include <linux/mtd/onenand.h>
@@ -191,8 +192,6 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
191 struct onenand_chip *this = mtd->priv; 192 struct onenand_chip *this = mtd->priv;
192 int value, readcmd = 0, block_cmd = 0; 193 int value, readcmd = 0, block_cmd = 0;
193 int block, page; 194 int block, page;
194 /* Now we use page size operation */
195 int sectors = 4, count = 4;
196 195
197 /* Address translation */ 196 /* Address translation */
198 switch (cmd) { 197 switch (cmd) {
@@ -244,6 +243,8 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le
244 } 243 }
245 244
246 if (page != -1) { 245 if (page != -1) {
246 /* Now we use page size operation */
247 int sectors = 4, count = 4;
247 int dataram; 248 int dataram;
248 249
249 switch (cmd) { 250 switch (cmd) {
@@ -297,7 +298,7 @@ static int onenand_wait(struct mtd_info *mtd, int state)
297 unsigned long timeout; 298 unsigned long timeout;
298 unsigned int flags = ONENAND_INT_MASTER; 299 unsigned int flags = ONENAND_INT_MASTER;
299 unsigned int interrupt = 0; 300 unsigned int interrupt = 0;
300 unsigned int ctrl, ecc; 301 unsigned int ctrl;
301 302
302 /* The 20 msec is enough */ 303 /* The 20 msec is enough */
303 timeout = jiffies + msecs_to_jiffies(20); 304 timeout = jiffies + msecs_to_jiffies(20);
@@ -309,7 +310,6 @@ static int onenand_wait(struct mtd_info *mtd, int state)
309 310
310 if (state != FL_READING) 311 if (state != FL_READING)
311 cond_resched(); 312 cond_resched();
312 touch_softlockup_watchdog();
313 } 313 }
314 /* To get correct interrupt status in timeout case */ 314 /* To get correct interrupt status in timeout case */
315 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); 315 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
@@ -317,28 +317,126 @@ static int onenand_wait(struct mtd_info *mtd, int state)
317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); 317 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
318 318
319 if (ctrl & ONENAND_CTRL_ERROR) { 319 if (ctrl & ONENAND_CTRL_ERROR) {
320 /* It maybe occur at initial bad block */
321 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl); 320 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x\n", ctrl);
322 /* Clear other interrupt bits for preventing ECC error */ 321 if (ctrl & ONENAND_CTRL_LOCK)
323 interrupt &= ONENAND_INT_MASTER; 322 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error.\n");
324 } 323 return ctrl;
325
326 if (ctrl & ONENAND_CTRL_LOCK) {
327 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error = 0x%04x\n", ctrl);
328 return -EACCES;
329 } 324 }
330 325
331 if (interrupt & ONENAND_INT_READ) { 326 if (interrupt & ONENAND_INT_READ) {
332 ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS); 327 int ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
333 if (ecc & ONENAND_ECC_2BIT_ALL) { 328 if (ecc) {
334 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc); 329 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x\n", ecc);
335 return -EBADMSG; 330 if (ecc & ONENAND_ECC_2BIT_ALL) {
331 mtd->ecc_stats.failed++;
332 return ecc;
333 } else if (ecc & ONENAND_ECC_1BIT_ALL)
334 mtd->ecc_stats.corrected++;
336 } 335 }
337 } 336 }
338 337
339 return 0; 338 return 0;
340} 339}
341 340
341/*
342 * onenand_interrupt - [DEFAULT] onenand interrupt handler
343 * @param irq onenand interrupt number
344 * @param dev_id interrupt data
345 *
346 * complete the work
347 */
348static irqreturn_t onenand_interrupt(int irq, void *data)
349{
350 struct onenand_chip *this = (struct onenand_chip *) data;
351
352 /* To handle shared interrupt */
353 if (!this->complete.done)
354 complete(&this->complete);
355
356 return IRQ_HANDLED;
357}
358
359/*
360 * onenand_interrupt_wait - [DEFAULT] wait until the command is done
361 * @param mtd MTD device structure
362 * @param state state to select the max. timeout value
363 *
364 * Wait for command done.
365 */
366static int onenand_interrupt_wait(struct mtd_info *mtd, int state)
367{
368 struct onenand_chip *this = mtd->priv;
369
370 wait_for_completion(&this->complete);
371
372 return onenand_wait(mtd, state);
373}
374
375/*
376 * onenand_try_interrupt_wait - [DEFAULT] try interrupt wait
377 * @param mtd MTD device structure
378 * @param state state to select the max. timeout value
379 *
380 * Try interrupt based wait (It is used one-time)
381 */
382static int onenand_try_interrupt_wait(struct mtd_info *mtd, int state)
383{
384 struct onenand_chip *this = mtd->priv;
385 unsigned long remain, timeout;
386
387 /* We use interrupt wait first */
388 this->wait = onenand_interrupt_wait;
389
390 timeout = msecs_to_jiffies(100);
391 remain = wait_for_completion_timeout(&this->complete, timeout);
392 if (!remain) {
393 printk(KERN_INFO "OneNAND: There's no interrupt. "
394 "We use the normal wait\n");
395
396 /* Release the irq */
397 free_irq(this->irq, this);
398
399 this->wait = onenand_wait;
400 }
401
402 return onenand_wait(mtd, state);
403}
404
405/*
406 * onenand_setup_wait - [OneNAND Interface] setup onenand wait method
407 * @param mtd MTD device structure
408 *
409 * There's two method to wait onenand work
410 * 1. polling - read interrupt status register
411 * 2. interrupt - use the kernel interrupt method
412 */
413static void onenand_setup_wait(struct mtd_info *mtd)
414{
415 struct onenand_chip *this = mtd->priv;
416 int syscfg;
417
418 init_completion(&this->complete);
419
420 if (this->irq <= 0) {
421 this->wait = onenand_wait;
422 return;
423 }
424
425 if (request_irq(this->irq, &onenand_interrupt,
426 IRQF_SHARED, "onenand", this)) {
427 /* If we can't get irq, use the normal wait */
428 this->wait = onenand_wait;
429 return;
430 }
431
432 /* Enable interrupt */
433 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1);
434 syscfg |= ONENAND_SYS_CFG1_IOBE;
435 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1);
436
437 this->wait = onenand_try_interrupt_wait;
438}
439
342/** 440/**
343 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset 441 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
344 * @param mtd MTD data structure 442 * @param mtd MTD data structure
@@ -609,9 +707,10 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
609 size_t *retlen, u_char *buf) 707 size_t *retlen, u_char *buf)
610{ 708{
611 struct onenand_chip *this = mtd->priv; 709 struct onenand_chip *this = mtd->priv;
710 struct mtd_ecc_stats stats;
612 int read = 0, column; 711 int read = 0, column;
613 int thislen; 712 int thislen;
614 int ret = 0; 713 int ret = 0, boundary = 0;
615 714
616 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); 715 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
617 716
@@ -627,38 +726,61 @@ static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
627 726
628 /* TODO handling oob */ 727 /* TODO handling oob */
629 728
630 while (read < len) { 729 stats = mtd->ecc_stats;
631 thislen = min_t(int, mtd->writesize, len - read); 730
632 731 /* Read-while-load method */
633 column = from & (mtd->writesize - 1); 732
634 if (column + thislen > mtd->writesize) 733 /* Do first load to bufferRAM */
635 thislen = mtd->writesize - column; 734 if (read < len) {
636 735 if (!onenand_check_bufferram(mtd, from)) {
637 if (!onenand_check_bufferram(mtd, from)) { 736 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize);
638 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize); 737 ret = this->wait(mtd, FL_READING);
639 738 onenand_update_bufferram(mtd, from, !ret);
640 ret = this->wait(mtd, FL_READING); 739 }
641 /* First copy data and check return value for ECC handling */ 740 }
642 onenand_update_bufferram(mtd, from, 1); 741
643 } 742 thislen = min_t(int, mtd->writesize, len - read);
644 743 column = from & (mtd->writesize - 1);
645 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); 744 if (column + thislen > mtd->writesize)
646 745 thislen = mtd->writesize - column;
647 read += thislen; 746
648 747 while (!ret) {
649 if (read == len) 748 /* If there is more to load then start next load */
650 break; 749 from += thislen;
651 750 if (read + thislen < len) {
652 if (ret) { 751 this->command(mtd, ONENAND_CMD_READ, from, mtd->writesize);
653 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read: read failed = %d\n", ret); 752 /*
654 goto out; 753 * Chip boundary handling in DDP
655 } 754 * Now we issued chip 1 read and pointed chip 1
656 755 * bufferam so we have to point chip 0 bufferam.
657 from += thislen; 756 */
658 buf += thislen; 757 if (this->device_id & ONENAND_DEVICE_IS_DDP &&
659 } 758 unlikely(from == (this->chipsize >> 1))) {
759 this->write_word(0, this->base + ONENAND_REG_START_ADDRESS2);
760 boundary = 1;
761 } else
762 boundary = 0;
763 ONENAND_SET_PREV_BUFFERRAM(this);
764 }
765 /* While load is going, read from last bufferRAM */
766 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen);
767 /* See if we are done */
768 read += thislen;
769 if (read == len)
770 break;
771 /* Set up for next read from bufferRAM */
772 if (unlikely(boundary))
773 this->write_word(0x8000, this->base + ONENAND_REG_START_ADDRESS2);
774 ONENAND_SET_NEXT_BUFFERRAM(this);
775 buf += thislen;
776 thislen = min_t(int, mtd->writesize, len - read);
777 column = 0;
778 cond_resched();
779 /* Now wait for load */
780 ret = this->wait(mtd, FL_READING);
781 onenand_update_bufferram(mtd, from, !ret);
782 }
660 783
661out:
662 /* Deselect and wake up anyone waiting on the device */ 784 /* Deselect and wake up anyone waiting on the device */
663 onenand_release_device(mtd); 785 onenand_release_device(mtd);
664 786
@@ -668,7 +790,14 @@ out:
668 * retlen == desired len and result == -EBADMSG 790 * retlen == desired len and result == -EBADMSG
669 */ 791 */
670 *retlen = read; 792 *retlen = read;
671 return ret; 793
794 if (mtd->ecc_stats.failed - stats.failed)
795 return -EBADMSG;
796
797 if (ret)
798 return ret;
799
800 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0;
672} 801}
673 802
674/** 803/**
@@ -705,6 +834,8 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
705 column = from & (mtd->oobsize - 1); 834 column = from & (mtd->oobsize - 1);
706 835
707 while (read < len) { 836 while (read < len) {
837 cond_resched();
838
708 thislen = mtd->oobsize - column; 839 thislen = mtd->oobsize - column;
709 thislen = min_t(int, thislen, len); 840 thislen = min_t(int, thislen, len);
710 841
@@ -717,16 +848,16 @@ int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
717 848
718 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); 849 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
719 850
851 if (ret) {
852 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = 0x%x\n", ret);
853 goto out;
854 }
855
720 read += thislen; 856 read += thislen;
721 857
722 if (read == len) 858 if (read == len)
723 break; 859 break;
724 860
725 if (ret) {
726 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = %d\n", ret);
727 goto out;
728 }
729
730 buf += thislen; 861 buf += thislen;
731 862
732 /* Read more? */ 863 /* Read more? */
@@ -756,8 +887,8 @@ static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
756{ 887{
757 BUG_ON(ops->mode != MTD_OOB_PLACE); 888 BUG_ON(ops->mode != MTD_OOB_PLACE);
758 889
759 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->len, 890 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->ooblen,
760 &ops->retlen, ops->oobbuf); 891 &ops->oobretlen, ops->oobbuf);
761} 892}
762 893
763#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 894#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
@@ -804,6 +935,10 @@ static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr)
804 void __iomem *dataram0, *dataram1; 935 void __iomem *dataram0, *dataram1;
805 int ret = 0; 936 int ret = 0;
806 937
938 /* In partial page write, just skip it */
939 if ((addr & (mtd->writesize - 1)) != 0)
940 return 0;
941
807 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize); 942 this->command(mtd, ONENAND_CMD_READ, addr, mtd->writesize);
808 943
809 ret = this->wait(mtd, FL_READING); 944 ret = this->wait(mtd, FL_READING);
@@ -826,7 +961,7 @@ static int onenand_verify_page(struct mtd_info *mtd, u_char *buf, loff_t addr)
826#define onenand_verify_oob(...) (0) 961#define onenand_verify_oob(...) (0)
827#endif 962#endif
828 963
829#define NOTALIGNED(x) ((x & (mtd->writesize - 1)) != 0) 964#define NOTALIGNED(x) ((x & (this->subpagesize - 1)) != 0)
830 965
831/** 966/**
832 * onenand_write - [MTD Interface] write buffer to FLASH 967 * onenand_write - [MTD Interface] write buffer to FLASH
@@ -844,6 +979,7 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
844 struct onenand_chip *this = mtd->priv; 979 struct onenand_chip *this = mtd->priv;
845 int written = 0; 980 int written = 0;
846 int ret = 0; 981 int ret = 0;
982 int column, subpage;
847 983
848 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); 984 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
849 985
@@ -862,45 +998,63 @@ static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
862 return -EINVAL; 998 return -EINVAL;
863 } 999 }
864 1000
1001 column = to & (mtd->writesize - 1);
1002 subpage = column || (len & (mtd->writesize - 1));
1003
865 /* Grab the lock and see if the device is available */ 1004 /* Grab the lock and see if the device is available */
866 onenand_get_device(mtd, FL_WRITING); 1005 onenand_get_device(mtd, FL_WRITING);
867 1006
868 /* Loop until all data write */ 1007 /* Loop until all data write */
869 while (written < len) { 1008 while (written < len) {
870 int thislen = min_t(int, mtd->writesize, len - written); 1009 int bytes = mtd->writesize;
871 1010 int thislen = min_t(int, bytes, len - written);
872 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->writesize); 1011 u_char *wbuf = (u_char *) buf;
1012
1013 cond_resched();
1014
1015 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, bytes);
1016
1017 /* Partial page write */
1018 if (subpage) {
1019 bytes = min_t(int, bytes - column, (int) len);
1020 memset(this->page_buf, 0xff, mtd->writesize);
1021 memcpy(this->page_buf + column, buf, bytes);
1022 wbuf = this->page_buf;
1023 /* Even though partial write, we need page size */
1024 thislen = mtd->writesize;
1025 }
873 1026
874 this->write_bufferram(mtd, ONENAND_DATARAM, buf, 0, thislen); 1027 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, thislen);
875 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize); 1028 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
876 1029
877 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); 1030 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
878 1031
879 onenand_update_bufferram(mtd, to, 1); 1032 /* In partial page write we don't update bufferram */
1033 onenand_update_bufferram(mtd, to, !subpage);
880 1034
881 ret = this->wait(mtd, FL_WRITING); 1035 ret = this->wait(mtd, FL_WRITING);
882 if (ret) { 1036 if (ret) {
883 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret); 1037 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: write filaed %d\n", ret);
884 goto out; 1038 break;
885 } 1039 }
886 1040
887 written += thislen;
888
889 /* Only check verify write turn on */ 1041 /* Only check verify write turn on */
890 ret = onenand_verify_page(mtd, (u_char *) buf, to); 1042 ret = onenand_verify_page(mtd, (u_char *) wbuf, to);
891 if (ret) { 1043 if (ret) {
892 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret); 1044 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write: verify failed %d\n", ret);
893 goto out; 1045 break;
894 } 1046 }
895 1047
1048 written += thislen;
1049
896 if (written == len) 1050 if (written == len)
897 break; 1051 break;
898 1052
1053 column = 0;
899 to += thislen; 1054 to += thislen;
900 buf += thislen; 1055 buf += thislen;
901 } 1056 }
902 1057
903out:
904 /* Deselect and wake up anyone waiting on the device */ 1058 /* Deselect and wake up anyone waiting on the device */
905 onenand_release_device(mtd); 1059 onenand_release_device(mtd);
906 1060
@@ -944,6 +1098,8 @@ static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
944 while (written < len) { 1098 while (written < len) {
945 int thislen = min_t(int, mtd->oobsize, len - written); 1099 int thislen = min_t(int, mtd->oobsize, len - written);
946 1100
1101 cond_resched();
1102
947 column = to & (mtd->oobsize - 1); 1103 column = to & (mtd->oobsize - 1);
948 1104
949 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); 1105 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
@@ -999,8 +1155,8 @@ static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
999{ 1155{
1000 BUG_ON(ops->mode != MTD_OOB_PLACE); 1156 BUG_ON(ops->mode != MTD_OOB_PLACE);
1001 1157
1002 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->len, 1158 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->ooblen,
1003 &ops->retlen, ops->oobbuf); 1159 &ops->oobretlen, ops->oobbuf);
1004} 1160}
1005 1161
1006/** 1162/**
@@ -1071,6 +1227,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1071 instr->state = MTD_ERASING; 1227 instr->state = MTD_ERASING;
1072 1228
1073 while (len) { 1229 while (len) {
1230 cond_resched();
1074 1231
1075 /* Check if we have a bad block, we do not erase bad blocks */ 1232 /* Check if we have a bad block, we do not erase bad blocks */
1076 if (onenand_block_checkbad(mtd, addr, 0, 0)) { 1233 if (onenand_block_checkbad(mtd, addr, 0, 0)) {
@@ -1084,10 +1241,7 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1084 ret = this->wait(mtd, FL_ERASING); 1241 ret = this->wait(mtd, FL_ERASING);
1085 /* Check, if it is write protected */ 1242 /* Check, if it is write protected */
1086 if (ret) { 1243 if (ret) {
1087 if (ret == -EPERM) 1244 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1088 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Device is write protected!!!\n");
1089 else
1090 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1091 instr->state = MTD_ERASE_FAILED; 1245 instr->state = MTD_ERASE_FAILED;
1092 instr->fail_addr = addr; 1246 instr->fail_addr = addr;
1093 goto erase_exit; 1247 goto erase_exit;
@@ -1129,7 +1283,6 @@ static void onenand_sync(struct mtd_info *mtd)
1129 onenand_release_device(mtd); 1283 onenand_release_device(mtd);
1130} 1284}
1131 1285
1132
1133/** 1286/**
1134 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad 1287 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
1135 * @param mtd MTD device structure 1288 * @param mtd MTD device structure
@@ -1196,32 +1349,38 @@ static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
1196} 1349}
1197 1350
1198/** 1351/**
1199 * onenand_unlock - [MTD Interface] Unlock block(s) 1352 * onenand_do_lock_cmd - [OneNAND Interface] Lock or unlock block(s)
1200 * @param mtd MTD device structure 1353 * @param mtd MTD device structure
1201 * @param ofs offset relative to mtd start 1354 * @param ofs offset relative to mtd start
1202 * @param len number of bytes to unlock 1355 * @param len number of bytes to lock or unlock
1203 * 1356 *
1204 * Unlock one or more blocks 1357 * Lock or unlock one or more blocks
1205 */ 1358 */
1206static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len) 1359static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int cmd)
1207{ 1360{
1208 struct onenand_chip *this = mtd->priv; 1361 struct onenand_chip *this = mtd->priv;
1209 int start, end, block, value, status; 1362 int start, end, block, value, status;
1363 int wp_status_mask;
1210 1364
1211 start = ofs >> this->erase_shift; 1365 start = ofs >> this->erase_shift;
1212 end = len >> this->erase_shift; 1366 end = len >> this->erase_shift;
1213 1367
1368 if (cmd == ONENAND_CMD_LOCK)
1369 wp_status_mask = ONENAND_WP_LS;
1370 else
1371 wp_status_mask = ONENAND_WP_US;
1372
1214 /* Continuous lock scheme */ 1373 /* Continuous lock scheme */
1215 if (this->options & ONENAND_HAS_CONT_LOCK) { 1374 if (this->options & ONENAND_HAS_CONT_LOCK) {
1216 /* Set start block address */ 1375 /* Set start block address */
1217 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS); 1376 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1218 /* Set end block address */ 1377 /* Set end block address */
1219 this->write_word(start + end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS); 1378 this->write_word(start + end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS);
1220 /* Write unlock command */ 1379 /* Write lock command */
1221 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); 1380 this->command(mtd, cmd, 0, 0);
1222 1381
1223 /* There's no return value */ 1382 /* There's no return value */
1224 this->wait(mtd, FL_UNLOCKING); 1383 this->wait(mtd, FL_LOCKING);
1225 1384
1226 /* Sanity check */ 1385 /* Sanity check */
1227 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1386 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1230,7 +1389,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1230 1389
1231 /* Check lock status */ 1390 /* Check lock status */
1232 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 1391 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1233 if (!(status & ONENAND_WP_US)) 1392 if (!(status & wp_status_mask))
1234 printk(KERN_ERR "wp status = 0x%x\n", status); 1393 printk(KERN_ERR "wp status = 0x%x\n", status);
1235 1394
1236 return 0; 1395 return 0;
@@ -1246,11 +1405,11 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1246 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); 1405 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
1247 /* Set start block address */ 1406 /* Set start block address */
1248 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS); 1407 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1249 /* Write unlock command */ 1408 /* Write lock command */
1250 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0); 1409 this->command(mtd, cmd, 0, 0);
1251 1410
1252 /* There's no return value */ 1411 /* There's no return value */
1253 this->wait(mtd, FL_UNLOCKING); 1412 this->wait(mtd, FL_LOCKING);
1254 1413
1255 /* Sanity check */ 1414 /* Sanity check */
1256 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1415 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1259,7 +1418,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1259 1418
1260 /* Check lock status */ 1419 /* Check lock status */
1261 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 1420 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1262 if (!(status & ONENAND_WP_US)) 1421 if (!(status & wp_status_mask))
1263 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); 1422 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
1264 } 1423 }
1265 1424
@@ -1267,6 +1426,32 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1267} 1426}
1268 1427
1269/** 1428/**
1429 * onenand_lock - [MTD Interface] Lock block(s)
1430 * @param mtd MTD device structure
1431 * @param ofs offset relative to mtd start
1432 * @param len number of bytes to unlock
1433 *
1434 * Lock one or more blocks
1435 */
1436static int onenand_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
1437{
1438 return onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_LOCK);
1439}
1440
1441/**
1442 * onenand_unlock - [MTD Interface] Unlock block(s)
1443 * @param mtd MTD device structure
1444 * @param ofs offset relative to mtd start
1445 * @param len number of bytes to unlock
1446 *
1447 * Unlock one or more blocks
1448 */
1449static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1450{
1451 return onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
1452}
1453
1454/**
1270 * onenand_check_lock_status - [OneNAND Interface] Check lock status 1455 * onenand_check_lock_status - [OneNAND Interface] Check lock status
1271 * @param this onenand chip data structure 1456 * @param this onenand chip data structure
1272 * 1457 *
@@ -1310,7 +1495,7 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1310 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); 1495 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0);
1311 1496
1312 /* There's no return value */ 1497 /* There's no return value */
1313 this->wait(mtd, FL_UNLOCKING); 1498 this->wait(mtd, FL_LOCKING);
1314 1499
1315 /* Sanity check */ 1500 /* Sanity check */
1316 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) 1501 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
@@ -1334,7 +1519,7 @@ static int onenand_unlock_all(struct mtd_info *mtd)
1334 return 0; 1519 return 0;
1335 } 1520 }
1336 1521
1337 mtd->unlock(mtd, 0x0, this->chipsize); 1522 onenand_unlock(mtd, 0x0, this->chipsize);
1338 1523
1339 return 0; 1524 return 0;
1340} 1525}
@@ -1762,7 +1947,7 @@ static int onenand_probe(struct mtd_info *mtd)
1762 /* Read manufacturer and device IDs from Register */ 1947 /* Read manufacturer and device IDs from Register */
1763 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); 1948 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
1764 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); 1949 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
1765 ver_id= this->read_word(this->base + ONENAND_REG_VERSION_ID); 1950 ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
1766 1951
1767 /* Check OneNAND device */ 1952 /* Check OneNAND device */
1768 if (maf_id != bram_maf_id || dev_id != bram_dev_id) 1953 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
@@ -1846,7 +2031,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1846 if (!this->command) 2031 if (!this->command)
1847 this->command = onenand_command; 2032 this->command = onenand_command;
1848 if (!this->wait) 2033 if (!this->wait)
1849 this->wait = onenand_wait; 2034 onenand_setup_wait(mtd);
1850 2035
1851 if (!this->read_bufferram) 2036 if (!this->read_bufferram)
1852 this->read_bufferram = onenand_read_bufferram; 2037 this->read_bufferram = onenand_read_bufferram;
@@ -1883,23 +2068,30 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1883 init_waitqueue_head(&this->wq); 2068 init_waitqueue_head(&this->wq);
1884 spin_lock_init(&this->chip_lock); 2069 spin_lock_init(&this->chip_lock);
1885 2070
2071 /*
2072 * Allow subpage writes up to oobsize.
2073 */
1886 switch (mtd->oobsize) { 2074 switch (mtd->oobsize) {
1887 case 64: 2075 case 64:
1888 this->ecclayout = &onenand_oob_64; 2076 this->ecclayout = &onenand_oob_64;
2077 mtd->subpage_sft = 2;
1889 break; 2078 break;
1890 2079
1891 case 32: 2080 case 32:
1892 this->ecclayout = &onenand_oob_32; 2081 this->ecclayout = &onenand_oob_32;
2082 mtd->subpage_sft = 1;
1893 break; 2083 break;
1894 2084
1895 default: 2085 default:
1896 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n", 2086 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n",
1897 mtd->oobsize); 2087 mtd->oobsize);
2088 mtd->subpage_sft = 0;
1898 /* To prevent kernel oops */ 2089 /* To prevent kernel oops */
1899 this->ecclayout = &onenand_oob_32; 2090 this->ecclayout = &onenand_oob_32;
1900 break; 2091 break;
1901 } 2092 }
1902 2093
2094 this->subpagesize = mtd->writesize >> mtd->subpage_sft;
1903 mtd->ecclayout = this->ecclayout; 2095 mtd->ecclayout = this->ecclayout;
1904 2096
1905 /* Fill in remaining MTD driver data */ 2097 /* Fill in remaining MTD driver data */
@@ -1922,7 +2114,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
1922 mtd->lock_user_prot_reg = onenand_lock_user_prot_reg; 2114 mtd->lock_user_prot_reg = onenand_lock_user_prot_reg;
1923#endif 2115#endif
1924 mtd->sync = onenand_sync; 2116 mtd->sync = onenand_sync;
1925 mtd->lock = NULL; 2117 mtd->lock = onenand_lock;
1926 mtd->unlock = onenand_unlock; 2118 mtd->unlock = onenand_unlock;
1927 mtd->suspend = onenand_suspend; 2119 mtd->suspend = onenand_suspend;
1928 mtd->resume = onenand_resume; 2120 mtd->resume = onenand_resume;
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 1b00dac3d7d6..98f8fd1c6375 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -93,13 +93,15 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs, 93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs,
94 readlen, &retlen, &buf[0]); 94 readlen, &retlen, &buf[0]);
95 95
96 if (ret) 96 /* If it is a initial bad block, just ignore it */
97 if (ret && !(ret & ONENAND_CTRL_LOAD))
97 return ret; 98 return ret;
98 99
99 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) { 100 if (check_short_pattern(&buf[j * scanlen], scanlen, mtd->writesize, bd)) {
100 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6); 101 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6);
101 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 102 printk(KERN_WARNING "Bad eraseblock %d at 0x%08x\n",
102 i >> 1, (unsigned int) from); 103 i >> 1, (unsigned int) from);
104 mtd->ecc_stats.badblocks++;
103 break; 105 break;
104 } 106 }
105 } 107 }
@@ -177,14 +179,12 @@ int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
177 int len, ret = 0; 179 int len, ret = 0;
178 180
179 len = mtd->size >> (this->erase_shift + 2); 181 len = mtd->size >> (this->erase_shift + 2);
180 /* Allocate memory (2bit per block) */ 182 /* Allocate memory (2bit per block) and clear the memory bad block table */
181 bbm->bbt = kmalloc(len, GFP_KERNEL); 183 bbm->bbt = kzalloc(len, GFP_KERNEL);
182 if (!bbm->bbt) { 184 if (!bbm->bbt) {
183 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n"); 185 printk(KERN_ERR "onenand_scan_bbt: Out of memory\n");
184 return -ENOMEM; 186 return -ENOMEM;
185 } 187 }
186 /* Clear the memory bad block table */
187 memset(bbm->bbt, 0x00, len);
188 188
189 /* Set the bad block position */ 189 /* Set the bad block position */
190 bbm->badblockpos = ONENAND_BADBLOCK_POS; 190 bbm->badblockpos = ONENAND_BADBLOCK_POS;
@@ -230,14 +230,12 @@ int onenand_default_bbt(struct mtd_info *mtd)
230 struct onenand_chip *this = mtd->priv; 230 struct onenand_chip *this = mtd->priv;
231 struct bbm_info *bbm; 231 struct bbm_info *bbm;
232 232
233 this->bbm = kmalloc(sizeof(struct bbm_info), GFP_KERNEL); 233 this->bbm = kzalloc(sizeof(struct bbm_info), GFP_KERNEL);
234 if (!this->bbm) 234 if (!this->bbm)
235 return -ENOMEM; 235 return -ENOMEM;
236 236
237 bbm = this->bbm; 237 bbm = this->bbm;
238 238
239 memset(bbm, 0, sizeof(struct bbm_info));
240
241 /* 1KB page has same configuration as 2KB page */ 239 /* 1KB page has same configuration as 2KB page */
242 if (!bbm->badblock_pattern) 240 if (!bbm->badblock_pattern)
243 bbm->badblock_pattern = &largepage_memorybased; 241 bbm->badblock_pattern = &largepage_memorybased;
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 5b58523e4d4e..035cd9b0cc08 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -96,7 +96,19 @@ static int parse_redboot_partitions(struct mtd_info *master,
96 */ 96 */
97 if (swab32(buf[i].size) == master->erasesize) { 97 if (swab32(buf[i].size) == master->erasesize) {
98 int j; 98 int j;
99 for (j = 0; j < numslots && buf[j].name[0] != 0xff; ++j) { 99 for (j = 0; j < numslots; ++j) {
100
101 /* A single 0xff denotes a deleted entry.
102 * Two of them in a row is the end of the table.
103 */
104 if (buf[j].name[0] == 0xff) {
105 if (buf[j].name[1] == 0xff) {
106 break;
107 } else {
108 continue;
109 }
110 }
111
100 /* The unsigned long fields were written with the 112 /* The unsigned long fields were written with the
101 * wrong byte sex, name and pad have no byte sex. 113 * wrong byte sex, name and pad have no byte sex.
102 */ 114 */
@@ -110,6 +122,9 @@ static int parse_redboot_partitions(struct mtd_info *master,
110 } 122 }
111 } 123 }
112 break; 124 break;
125 } else {
126 /* re-calculate of real numslots */
127 numslots = buf[i].size / sizeof(struct fis_image_desc);
113 } 128 }
114 } 129 }
115 if (i == numslots) { 130 if (i == numslots) {
@@ -123,8 +138,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
123 for (i = 0; i < numslots; i++) { 138 for (i = 0; i < numslots; i++) {
124 struct fis_list *new_fl, **prev; 139 struct fis_list *new_fl, **prev;
125 140
126 if (buf[i].name[0] == 0xff) 141 if (buf[i].name[0] == 0xff) {
127 continue; 142 if (buf[i].name[1] == 0xff) {
143 break;
144 } else {
145 continue;
146 }
147 }
128 if (!redboot_checksum(&buf[i])) 148 if (!redboot_checksum(&buf[i]))
129 break; 149 break;
130 150
@@ -165,15 +185,13 @@ static int parse_redboot_partitions(struct mtd_info *master,
165 } 185 }
166 } 186 }
167#endif 187#endif
168 parts = kmalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL); 188 parts = kzalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
169 189
170 if (!parts) { 190 if (!parts) {
171 ret = -ENOMEM; 191 ret = -ENOMEM;
172 goto out; 192 goto out;
173 } 193 }
174 194
175 memset(parts, 0, sizeof(*parts)*nrparts + nulllen + namelen);
176
177 nullname = (char *)&parts[nrparts]; 195 nullname = (char *)&parts[nrparts];
178#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED 196#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
179 if (nulllen > 0) { 197 if (nulllen > 0) {
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 0f3baa5d9c2a..d4b1ba8f23ef 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -787,7 +787,6 @@ static void rfd_ftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
787 787
788 if (scan_header(part) == 0) { 788 if (scan_header(part) == 0) {
789 part->mbd.size = part->sector_count; 789 part->mbd.size = part->sector_count;
790 part->mbd.blksize = SECTOR_SIZE;
791 part->mbd.tr = tr; 790 part->mbd.tr = tr;
792 part->mbd.devnum = -1; 791 part->mbd.devnum = -1;
793 if (!(mtd->flags & MTD_WRITEABLE)) 792 if (!(mtd->flags & MTD_WRITEABLE))
@@ -829,6 +828,8 @@ struct mtd_blktrans_ops rfd_ftl_tr = {
829 .name = "rfd", 828 .name = "rfd",
830 .major = RFD_FTL_MAJOR, 829 .major = RFD_FTL_MAJOR,
831 .part_bits = PART_BITS, 830 .part_bits = PART_BITS,
831 .blksize = SECTOR_SIZE,
832
832 .readsect = rfd_ftl_readsect, 833 .readsect = rfd_ftl_readsect,
833 .writesect = rfd_ftl_writesect, 834 .writesect = rfd_ftl_writesect,
834 .getgeo = rfd_ftl_getgeo, 835 .getgeo = rfd_ftl_getgeo,
diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c
index 79d3bb659bfe..a5f3d60047d4 100644
--- a/drivers/mtd/ssfdc.c
+++ b/drivers/mtd/ssfdc.c
@@ -172,13 +172,12 @@ static int read_raw_oob(struct mtd_info *mtd, loff_t offs, uint8_t *buf)
172 172
173 ops.mode = MTD_OOB_RAW; 173 ops.mode = MTD_OOB_RAW;
174 ops.ooboffs = 0; 174 ops.ooboffs = 0;
175 ops.ooblen = mtd->oobsize; 175 ops.ooblen = OOB_SIZE;
176 ops.len = OOB_SIZE;
177 ops.oobbuf = buf; 176 ops.oobbuf = buf;
178 ops.datbuf = NULL; 177 ops.datbuf = NULL;
179 178
180 ret = mtd->read_oob(mtd, offs, &ops); 179 ret = mtd->read_oob(mtd, offs, &ops);
181 if (ret < 0 || ops.retlen != OOB_SIZE) 180 if (ret < 0 || ops.oobretlen != OOB_SIZE)
182 return -1; 181 return -1;
183 182
184 return 0; 183 return 0;
@@ -312,7 +311,6 @@ static void ssfdcr_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
312 311
313 ssfdc->mbd.mtd = mtd; 312 ssfdc->mbd.mtd = mtd;
314 ssfdc->mbd.devnum = -1; 313 ssfdc->mbd.devnum = -1;
315 ssfdc->mbd.blksize = SECTOR_SIZE;
316 ssfdc->mbd.tr = tr; 314 ssfdc->mbd.tr = tr;
317 ssfdc->mbd.readonly = 1; 315 ssfdc->mbd.readonly = 1;
318 316
@@ -447,6 +445,7 @@ static struct mtd_blktrans_ops ssfdcr_tr = {
447 .name = "ssfdc", 445 .name = "ssfdc",
448 .major = SSFDCR_MAJOR, 446 .major = SSFDCR_MAJOR,
449 .part_bits = SSFDCR_PARTN_BITS, 447 .part_bits = SSFDCR_PARTN_BITS,
448 .blksize = SECTOR_SIZE,
450 .getgeo = ssfdcr_getgeo, 449 .getgeo = ssfdcr_getgeo,
451 .readsect = ssfdcr_readsect, 450 .readsect = ssfdcr_readsect,
452 .add_mtd = ssfdcr_add_mtd, 451 .add_mtd = ssfdcr_add_mtd,
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index e2cb19b582a1..6f93a765e564 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -765,17 +765,18 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
765 struct cp_private *cp = netdev_priv(dev); 765 struct cp_private *cp = netdev_priv(dev);
766 unsigned entry; 766 unsigned entry;
767 u32 eor, flags; 767 u32 eor, flags;
768 unsigned long intr_flags;
768#if CP_VLAN_TAG_USED 769#if CP_VLAN_TAG_USED
769 u32 vlan_tag = 0; 770 u32 vlan_tag = 0;
770#endif 771#endif
771 int mss = 0; 772 int mss = 0;
772 773
773 spin_lock_irq(&cp->lock); 774 spin_lock_irqsave(&cp->lock, intr_flags);
774 775
775 /* This is a hard error, log it. */ 776 /* This is a hard error, log it. */
776 if (TX_BUFFS_AVAIL(cp) <= (skb_shinfo(skb)->nr_frags + 1)) { 777 if (TX_BUFFS_AVAIL(cp) <= (skb_shinfo(skb)->nr_frags + 1)) {
777 netif_stop_queue(dev); 778 netif_stop_queue(dev);
778 spin_unlock_irq(&cp->lock); 779 spin_unlock_irqrestore(&cp->lock, intr_flags);
779 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n", 780 printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
780 dev->name); 781 dev->name);
781 return 1; 782 return 1;
@@ -908,7 +909,7 @@ static int cp_start_xmit (struct sk_buff *skb, struct net_device *dev)
908 if (TX_BUFFS_AVAIL(cp) <= (MAX_SKB_FRAGS + 1)) 909 if (TX_BUFFS_AVAIL(cp) <= (MAX_SKB_FRAGS + 1))
909 netif_stop_queue(dev); 910 netif_stop_queue(dev);
910 911
911 spin_unlock_irq(&cp->lock); 912 spin_unlock_irqrestore(&cp->lock, intr_flags);
912 913
913 cpw8(TxPoll, NormalTxPoll); 914 cpw8(TxPoll, NormalTxPoll);
914 dev->trans_start = jiffies; 915 dev->trans_start = jiffies;
diff --git a/drivers/net/82596.c b/drivers/net/82596.c
index 8236f26ffd46..640d7ca2ebcf 100644
--- a/drivers/net/82596.c
+++ b/drivers/net/82596.c
@@ -1066,8 +1066,8 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1066 short length = skb->len; 1066 short length = skb->len;
1067 dev->trans_start = jiffies; 1067 dev->trans_start = jiffies;
1068 1068
1069 DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%x) called\n", dev->name, 1069 DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n",
1070 skb->len, (unsigned int)skb->data)); 1070 dev->name, skb->len, skb->data));
1071 1071
1072 if (skb->len < ETH_ZLEN) { 1072 if (skb->len < ETH_ZLEN) {
1073 if (skb_padto(skb, ETH_ZLEN)) 1073 if (skb_padto(skb, ETH_ZLEN))
@@ -1246,7 +1246,8 @@ struct net_device * __init i82596_probe(int unit)
1246 dev->priv = (void *)(dev->mem_start); 1246 dev->priv = (void *)(dev->mem_start);
1247 1247
1248 lp = dev->priv; 1248 lp = dev->priv;
1249 DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n", 1249 DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%zd bytes), "
1250 "lp->scb at 0x%08lx\n",
1250 dev->name, (unsigned long)lp, 1251 dev->name, (unsigned long)lp,
1251 sizeof(struct i596_private), (unsigned long)&lp->scb)); 1252 sizeof(struct i596_private), (unsigned long)&lp->scb));
1252 memset((void *) lp, 0, sizeof(struct i596_private)); 1253 memset((void *) lp, 0, sizeof(struct i596_private));
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 5eb2ec68393f..303a8d94ad4b 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -110,6 +110,11 @@ MODULE_DEVICE_TABLE(pci, b44_pci_tbl);
110 110
111static void b44_halt(struct b44 *); 111static void b44_halt(struct b44 *);
112static void b44_init_rings(struct b44 *); 112static void b44_init_rings(struct b44 *);
113
114#define B44_FULL_RESET 1
115#define B44_FULL_RESET_SKIP_PHY 2
116#define B44_PARTIAL_RESET 3
117
113static void b44_init_hw(struct b44 *, int); 118static void b44_init_hw(struct b44 *, int);
114 119
115static int dma_desc_align_mask; 120static int dma_desc_align_mask;
@@ -752,7 +757,7 @@ static void b44_recycle_rx(struct b44 *bp, int src_idx, u32 dest_idx_unmasked)
752 dest_idx * sizeof(dest_desc), 757 dest_idx * sizeof(dest_desc),
753 DMA_BIDIRECTIONAL); 758 DMA_BIDIRECTIONAL);
754 759
755 pci_dma_sync_single_for_device(bp->pdev, src_desc->addr, 760 pci_dma_sync_single_for_device(bp->pdev, le32_to_cpu(src_desc->addr),
756 RX_PKT_BUF_SZ, 761 RX_PKT_BUF_SZ,
757 PCI_DMA_FROMDEVICE); 762 PCI_DMA_FROMDEVICE);
758} 763}
@@ -884,7 +889,7 @@ static int b44_poll(struct net_device *netdev, int *budget)
884 spin_lock_irqsave(&bp->lock, flags); 889 spin_lock_irqsave(&bp->lock, flags);
885 b44_halt(bp); 890 b44_halt(bp);
886 b44_init_rings(bp); 891 b44_init_rings(bp);
887 b44_init_hw(bp, 1); 892 b44_init_hw(bp, B44_FULL_RESET_SKIP_PHY);
888 netif_wake_queue(bp->dev); 893 netif_wake_queue(bp->dev);
889 spin_unlock_irqrestore(&bp->lock, flags); 894 spin_unlock_irqrestore(&bp->lock, flags);
890 done = 1; 895 done = 1;
@@ -954,7 +959,7 @@ static void b44_tx_timeout(struct net_device *dev)
954 959
955 b44_halt(bp); 960 b44_halt(bp);
956 b44_init_rings(bp); 961 b44_init_rings(bp);
957 b44_init_hw(bp, 1); 962 b44_init_hw(bp, B44_FULL_RESET);
958 963
959 spin_unlock_irq(&bp->lock); 964 spin_unlock_irq(&bp->lock);
960 965
@@ -1071,7 +1076,7 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
1071 b44_halt(bp); 1076 b44_halt(bp);
1072 dev->mtu = new_mtu; 1077 dev->mtu = new_mtu;
1073 b44_init_rings(bp); 1078 b44_init_rings(bp);
1074 b44_init_hw(bp, 1); 1079 b44_init_hw(bp, B44_FULL_RESET);
1075 spin_unlock_irq(&bp->lock); 1080 spin_unlock_irq(&bp->lock);
1076 1081
1077 b44_enable_ints(bp); 1082 b44_enable_ints(bp);
@@ -1368,12 +1373,12 @@ static int b44_set_mac_addr(struct net_device *dev, void *p)
1368 * packet processing. Invoked with bp->lock held. 1373 * packet processing. Invoked with bp->lock held.
1369 */ 1374 */
1370static void __b44_set_rx_mode(struct net_device *); 1375static void __b44_set_rx_mode(struct net_device *);
1371static void b44_init_hw(struct b44 *bp, int full_reset) 1376static void b44_init_hw(struct b44 *bp, int reset_kind)
1372{ 1377{
1373 u32 val; 1378 u32 val;
1374 1379
1375 b44_chip_reset(bp); 1380 b44_chip_reset(bp);
1376 if (full_reset) { 1381 if (reset_kind == B44_FULL_RESET) {
1377 b44_phy_reset(bp); 1382 b44_phy_reset(bp);
1378 b44_setup_phy(bp); 1383 b44_setup_phy(bp);
1379 } 1384 }
@@ -1390,7 +1395,10 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
1390 bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN); 1395 bw32(bp, B44_TXMAXLEN, bp->dev->mtu + ETH_HLEN + 8 + RX_HEADER_LEN);
1391 1396
1392 bw32(bp, B44_TX_WMARK, 56); /* XXX magic */ 1397 bw32(bp, B44_TX_WMARK, 56); /* XXX magic */
1393 if (full_reset) { 1398 if (reset_kind == B44_PARTIAL_RESET) {
1399 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
1400 (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
1401 } else {
1394 bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE); 1402 bw32(bp, B44_DMATX_CTRL, DMATX_CTRL_ENABLE);
1395 bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset); 1403 bw32(bp, B44_DMATX_ADDR, bp->tx_ring_dma + bp->dma_offset);
1396 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE | 1404 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
@@ -1401,9 +1409,6 @@ static void b44_init_hw(struct b44 *bp, int full_reset)
1401 bp->rx_prod = bp->rx_pending; 1409 bp->rx_prod = bp->rx_pending;
1402 1410
1403 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ); 1411 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
1404 } else {
1405 bw32(bp, B44_DMARX_CTRL, (DMARX_CTRL_ENABLE |
1406 (bp->rx_offset << DMARX_CTRL_ROSHIFT)));
1407 } 1412 }
1408 1413
1409 val = br32(bp, B44_ENET_CTRL); 1414 val = br32(bp, B44_ENET_CTRL);
@@ -1420,7 +1425,7 @@ static int b44_open(struct net_device *dev)
1420 goto out; 1425 goto out;
1421 1426
1422 b44_init_rings(bp); 1427 b44_init_rings(bp);
1423 b44_init_hw(bp, 1); 1428 b44_init_hw(bp, B44_FULL_RESET);
1424 1429
1425 b44_check_phy(bp); 1430 b44_check_phy(bp);
1426 1431
@@ -1629,7 +1634,7 @@ static int b44_close(struct net_device *dev)
1629 netif_poll_enable(dev); 1634 netif_poll_enable(dev);
1630 1635
1631 if (bp->flags & B44_FLAG_WOL_ENABLE) { 1636 if (bp->flags & B44_FLAG_WOL_ENABLE) {
1632 b44_init_hw(bp, 0); 1637 b44_init_hw(bp, B44_PARTIAL_RESET);
1633 b44_setup_wol(bp); 1638 b44_setup_wol(bp);
1634 } 1639 }
1635 1640
@@ -1905,7 +1910,7 @@ static int b44_set_ringparam(struct net_device *dev,
1905 1910
1906 b44_halt(bp); 1911 b44_halt(bp);
1907 b44_init_rings(bp); 1912 b44_init_rings(bp);
1908 b44_init_hw(bp, 1); 1913 b44_init_hw(bp, B44_FULL_RESET);
1909 netif_wake_queue(bp->dev); 1914 netif_wake_queue(bp->dev);
1910 spin_unlock_irq(&bp->lock); 1915 spin_unlock_irq(&bp->lock);
1911 1916
@@ -1948,7 +1953,7 @@ static int b44_set_pauseparam(struct net_device *dev,
1948 if (bp->flags & B44_FLAG_PAUSE_AUTO) { 1953 if (bp->flags & B44_FLAG_PAUSE_AUTO) {
1949 b44_halt(bp); 1954 b44_halt(bp);
1950 b44_init_rings(bp); 1955 b44_init_rings(bp);
1951 b44_init_hw(bp, 1); 1956 b44_init_hw(bp, B44_FULL_RESET);
1952 } else { 1957 } else {
1953 __b44_set_flow_ctrl(bp, bp->flags); 1958 __b44_set_flow_ctrl(bp, bp->flags);
1954 } 1959 }
@@ -2304,7 +2309,7 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
2304 2309
2305 free_irq(dev->irq, dev); 2310 free_irq(dev->irq, dev);
2306 if (bp->flags & B44_FLAG_WOL_ENABLE) { 2311 if (bp->flags & B44_FLAG_WOL_ENABLE) {
2307 b44_init_hw(bp, 0); 2312 b44_init_hw(bp, B44_PARTIAL_RESET);
2308 b44_setup_wol(bp); 2313 b44_setup_wol(bp);
2309 } 2314 }
2310 pci_disable_device(pdev); 2315 pci_disable_device(pdev);
@@ -2315,21 +2320,32 @@ static int b44_resume(struct pci_dev *pdev)
2315{ 2320{
2316 struct net_device *dev = pci_get_drvdata(pdev); 2321 struct net_device *dev = pci_get_drvdata(pdev);
2317 struct b44 *bp = netdev_priv(dev); 2322 struct b44 *bp = netdev_priv(dev);
2323 int rc = 0;
2318 2324
2319 pci_restore_state(pdev); 2325 pci_restore_state(pdev);
2320 pci_enable_device(pdev); 2326 rc = pci_enable_device(pdev);
2327 if (rc) {
2328 printk(KERN_ERR PFX "%s: pci_enable_device failed\n",
2329 dev->name);
2330 return rc;
2331 }
2332
2321 pci_set_master(pdev); 2333 pci_set_master(pdev);
2322 2334
2323 if (!netif_running(dev)) 2335 if (!netif_running(dev))
2324 return 0; 2336 return 0;
2325 2337
2326 if (request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev)) 2338 rc = request_irq(dev->irq, b44_interrupt, IRQF_SHARED, dev->name, dev);
2339 if (rc) {
2327 printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name); 2340 printk(KERN_ERR PFX "%s: request_irq failed\n", dev->name);
2341 pci_disable_device(pdev);
2342 return rc;
2343 }
2328 2344
2329 spin_lock_irq(&bp->lock); 2345 spin_lock_irq(&bp->lock);
2330 2346
2331 b44_init_rings(bp); 2347 b44_init_rings(bp);
2332 b44_init_hw(bp, 1); 2348 b44_init_hw(bp, B44_FULL_RESET);
2333 netif_device_attach(bp->dev); 2349 netif_device_attach(bp->dev);
2334 spin_unlock_irq(&bp->lock); 2350 spin_unlock_irq(&bp->lock);
2335 2351
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index ca5acc4736df..953808efe551 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -57,8 +57,8 @@
57 57
58#define DRV_MODULE_NAME "bnx2" 58#define DRV_MODULE_NAME "bnx2"
59#define PFX DRV_MODULE_NAME ": " 59#define PFX DRV_MODULE_NAME ": "
60#define DRV_MODULE_VERSION "1.5.3" 60#define DRV_MODULE_VERSION "1.5.4"
61#define DRV_MODULE_RELDATE "January 8, 2007" 61#define DRV_MODULE_RELDATE "January 24, 2007"
62 62
63#define RUN_AT(x) (jiffies + (x)) 63#define RUN_AT(x) (jiffies + (x))
64 64
@@ -5845,9 +5845,11 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
5845 reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE); 5845 reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
5846 5846
5847 if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) == 5847 if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
5848 BNX2_SHM_HDR_SIGNATURE_SIG) 5848 BNX2_SHM_HDR_SIGNATURE_SIG) {
5849 bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0); 5849 u32 off = PCI_FUNC(pdev->devfn) << 2;
5850 else 5850
5851 bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0 + off);
5852 } else
5851 bp->shmem_base = HOST_VIEW_SHMEM_BASE; 5853 bp->shmem_base = HOST_VIEW_SHMEM_BASE;
5852 5854
5853 /* Get the permanent MAC address. First we need to make sure the 5855 /* Get the permanent MAC address. First we need to make sure the
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index dc434fb6da85..0978c9ac6d2b 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -151,8 +151,8 @@ struct slave {
151 struct slave *next; 151 struct slave *next;
152 struct slave *prev; 152 struct slave *prev;
153 int delay; 153 int delay;
154 u32 jiffies; 154 unsigned long jiffies;
155 u32 last_arp_rx; 155 unsigned long last_arp_rx;
156 s8 link; /* one of BOND_LINK_XXXX */ 156 s8 link; /* one of BOND_LINK_XXXX */
157 s8 state; /* one of BOND_STATE_XXXX */ 157 s8 state; /* one of BOND_STATE_XXXX */
158 u32 original_flags; 158 u32 original_flags;
@@ -242,7 +242,8 @@ extern inline int slave_do_arp_validate(struct bonding *bond, struct slave *slav
242 return bond->params.arp_validate & (1 << slave->state); 242 return bond->params.arp_validate & (1 << slave->state);
243} 243}
244 244
245extern inline u32 slave_last_rx(struct bonding *bond, struct slave *slave) 245extern inline unsigned long slave_last_rx(struct bonding *bond,
246 struct slave *slave)
246{ 247{
247 if (slave_do_arp_validate(bond, slave)) 248 if (slave_do_arp_validate(bond, slave))
248 return slave->last_arp_rx; 249 return slave->last_arp_rx;
diff --git a/drivers/net/e100.c b/drivers/net/e100.c
index c2ae2a24629b..3208dac29168 100644
--- a/drivers/net/e100.c
+++ b/drivers/net/e100.c
@@ -2725,6 +2725,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2725 del_timer_sync(&nic->watchdog); 2725 del_timer_sync(&nic->watchdog);
2726 netif_carrier_off(nic->netdev); 2726 netif_carrier_off(nic->netdev);
2727 2727
2728 netif_device_detach(netdev);
2728 pci_save_state(pdev); 2729 pci_save_state(pdev);
2729 2730
2730 if ((nic->flags & wol_magic) | e100_asf(nic)) { 2731 if ((nic->flags & wol_magic) | e100_asf(nic)) {
@@ -2736,6 +2737,7 @@ static int e100_suspend(struct pci_dev *pdev, pm_message_t state)
2736 } 2737 }
2737 2738
2738 pci_disable_device(pdev); 2739 pci_disable_device(pdev);
2740 free_irq(pdev->irq, netdev);
2739 pci_set_power_state(pdev, PCI_D3hot); 2741 pci_set_power_state(pdev, PCI_D3hot);
2740 2742
2741 return 0; 2743 return 0;
diff --git a/drivers/net/ehea/ehea.h b/drivers/net/ehea/ehea.h
index 39ad9f73d1ec..272e1ec51aa2 100644
--- a/drivers/net/ehea/ehea.h
+++ b/drivers/net/ehea/ehea.h
@@ -39,7 +39,7 @@
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41#define DRV_NAME "ehea" 41#define DRV_NAME "ehea"
42#define DRV_VERSION "EHEA_0043" 42#define DRV_VERSION "EHEA_0045"
43 43
44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \ 44#define EHEA_MSG_DEFAULT (NETIF_MSG_LINK | NETIF_MSG_TIMER \
45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR) 45 | NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index 83fa32f72398..9de2d38a5321 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -558,12 +558,12 @@ static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
558 u32 qp_token; 558 u32 qp_token;
559 559
560 eqe = ehea_poll_eq(port->qp_eq); 560 eqe = ehea_poll_eq(port->qp_eq);
561 ehea_debug("eqe=%p", eqe); 561
562 while (eqe) { 562 while (eqe) {
563 ehea_debug("*eqe=%lx", *(u64*)eqe);
564 eqe = ehea_poll_eq(port->qp_eq);
565 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry); 563 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
566 ehea_debug("next eqe=%p", eqe); 564 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
565 eqe->entry, qp_token);
566 eqe = ehea_poll_eq(port->qp_eq);
567 } 567 }
568 568
569 return IRQ_HANDLED; 569 return IRQ_HANDLED;
@@ -575,8 +575,9 @@ static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
575 int i; 575 int i;
576 576
577 for (i = 0; i < adapter->num_ports; i++) 577 for (i = 0; i < adapter->num_ports; i++)
578 if (adapter->port[i]->logical_port_id == logical_port) 578 if (adapter->port[i])
579 return adapter->port[i]; 579 if (adapter->port[i]->logical_port_id == logical_port)
580 return adapter->port[i];
580 return NULL; 581 return NULL;
581} 582}
582 583
@@ -642,6 +643,8 @@ int ehea_sense_port_attr(struct ehea_port *port)
642 break; 643 break;
643 } 644 }
644 645
646 port->autoneg = 1;
647
645 /* Number of default QPs */ 648 /* Number of default QPs */
646 port->num_def_qps = cb0->num_default_qps; 649 port->num_def_qps = cb0->num_default_qps;
647 650
@@ -728,10 +731,7 @@ int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
728 } 731 }
729 } else { 732 } else {
730 if (hret == H_AUTHORITY) { 733 if (hret == H_AUTHORITY) {
731 ehea_info("Hypervisor denied setting port speed. Either" 734 ehea_info("Hypervisor denied setting port speed");
732 " this partition is not authorized to set "
733 "port speed or another partition has modified"
734 " port speed first.");
735 ret = -EPERM; 735 ret = -EPERM;
736 } else { 736 } else {
737 ret = -EIO; 737 ret = -EIO;
@@ -998,7 +998,7 @@ static int ehea_configure_port(struct ehea_port *port)
998 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1); 998 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
999 999
1000 for (i = 0; i < port->num_def_qps; i++) 1000 for (i = 0; i < port->num_def_qps; i++)
1001 cb0->default_qpn_arr[i] = port->port_res[i].qp->init_attr.qp_nr; 1001 cb0->default_qpn_arr[i] = port->port_res[0].qp->init_attr.qp_nr;
1002 1002
1003 if (netif_msg_ifup(port)) 1003 if (netif_msg_ifup(port))
1004 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port"); 1004 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
@@ -1485,11 +1485,12 @@ out:
1485 1485
1486static void ehea_promiscuous_error(u64 hret, int enable) 1486static void ehea_promiscuous_error(u64 hret, int enable)
1487{ 1487{
1488 ehea_info("Hypervisor denied %sabling promiscuous mode.%s", 1488 if (hret == H_AUTHORITY)
1489 enable == 1 ? "en" : "dis", 1489 ehea_info("Hypervisor denied %sabling promiscuous mode",
1490 hret != H_AUTHORITY ? "" : " Another partition owning a " 1490 enable == 1 ? "en" : "dis");
1491 "logical port on the same physical port might have altered " 1491 else
1492 "promiscuous mode first."); 1492 ehea_error("failed %sabling promiscuous mode",
1493 enable == 1 ? "en" : "dis");
1493} 1494}
1494 1495
1495static void ehea_promiscuous(struct net_device *dev, int enable) 1496static void ehea_promiscuous(struct net_device *dev, int enable)
@@ -2267,6 +2268,8 @@ static void ehea_tx_watchdog(struct net_device *dev)
2267int ehea_sense_adapter_attr(struct ehea_adapter *adapter) 2268int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2268{ 2269{
2269 struct hcp_query_ehea *cb; 2270 struct hcp_query_ehea *cb;
2271 struct device_node *lhea_dn = NULL;
2272 struct device_node *eth_dn = NULL;
2270 u64 hret; 2273 u64 hret;
2271 int ret; 2274 int ret;
2272 2275
@@ -2283,7 +2286,18 @@ int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2283 goto out_herr; 2286 goto out_herr;
2284 } 2287 }
2285 2288
2286 adapter->num_ports = cb->num_ports; 2289 /* Determine the number of available logical ports
2290 * by counting the child nodes of the lhea OFDT entry
2291 */
2292 adapter->num_ports = 0;
2293 lhea_dn = of_find_node_by_name(lhea_dn, "lhea");
2294 do {
2295 eth_dn = of_get_next_child(lhea_dn, eth_dn);
2296 if (eth_dn)
2297 adapter->num_ports++;
2298 } while ( eth_dn );
2299 of_node_put(lhea_dn);
2300
2287 adapter->max_mc_mac = cb->max_mc_mac - 1; 2301 adapter->max_mc_mac = cb->max_mc_mac - 1;
2288 ret = 0; 2302 ret = 0;
2289 2303
@@ -2302,6 +2316,7 @@ static int ehea_setup_single_port(struct ehea_port *port,
2302 struct ehea_adapter *adapter = port->adapter; 2316 struct ehea_adapter *adapter = port->adapter;
2303 struct hcp_ehea_port_cb4 *cb4; 2317 struct hcp_ehea_port_cb4 *cb4;
2304 u32 *dn_log_port_id; 2318 u32 *dn_log_port_id;
2319 int jumbo = 0;
2305 2320
2306 sema_init(&port->port_lock, 1); 2321 sema_init(&port->port_lock, 1);
2307 port->state = EHEA_PORT_DOWN; 2322 port->state = EHEA_PORT_DOWN;
@@ -2334,8 +2349,6 @@ static int ehea_setup_single_port(struct ehea_port *port,
2334 2349
2335 INIT_LIST_HEAD(&port->mc_list->list); 2350 INIT_LIST_HEAD(&port->mc_list->list);
2336 2351
2337 ehea_set_portspeed(port, EHEA_SPEED_AUTONEG);
2338
2339 ret = ehea_sense_port_attr(port); 2352 ret = ehea_sense_port_attr(port);
2340 if (ret) 2353 if (ret)
2341 goto out; 2354 goto out;
@@ -2345,13 +2358,25 @@ static int ehea_setup_single_port(struct ehea_port *port,
2345 if (!cb4) { 2358 if (!cb4) {
2346 ehea_error("no mem for cb4"); 2359 ehea_error("no mem for cb4");
2347 } else { 2360 } else {
2348 cb4->jumbo_frame = 1; 2361 hret = ehea_h_query_ehea_port(adapter->handle,
2349 hret = ehea_h_modify_ehea_port(adapter->handle, 2362 port->logical_port_id,
2350 port->logical_port_id, 2363 H_PORT_CB4,
2351 H_PORT_CB4, H_PORT_CB4_JUMBO, 2364 H_PORT_CB4_JUMBO, cb4);
2352 cb4); 2365
2353 if (hret != H_SUCCESS) { 2366 if (hret == H_SUCCESS) {
2354 ehea_info("Jumbo frames not activated"); 2367 if (cb4->jumbo_frame)
2368 jumbo = 1;
2369 else {
2370 cb4->jumbo_frame = 1;
2371 hret = ehea_h_modify_ehea_port(adapter->handle,
2372 port->
2373 logical_port_id,
2374 H_PORT_CB4,
2375 H_PORT_CB4_JUMBO,
2376 cb4);
2377 if (hret == H_SUCCESS)
2378 jumbo = 1;
2379 }
2355 } 2380 }
2356 kfree(cb4); 2381 kfree(cb4);
2357 } 2382 }
@@ -2390,6 +2415,9 @@ static int ehea_setup_single_port(struct ehea_port *port,
2390 goto out_free; 2415 goto out_free;
2391 } 2416 }
2392 2417
2418 ehea_info("%s: Jumbo frames are %sabled", dev->name,
2419 jumbo == 1 ? "en" : "dis");
2420
2393 port->netdev = dev; 2421 port->netdev = dev;
2394 ret = 0; 2422 ret = 0;
2395 goto out; 2423 goto out;
@@ -2471,14 +2499,16 @@ static int __devinit ehea_probe(struct ibmebus_dev *dev,
2471 2499
2472 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle", 2500 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle",
2473 NULL); 2501 NULL);
2474 if (!adapter_handle) { 2502 if (adapter_handle)
2503 adapter->handle = *adapter_handle;
2504
2505 if (!adapter->handle) {
2475 dev_err(&dev->ofdev.dev, "failed getting handle for adapter" 2506 dev_err(&dev->ofdev.dev, "failed getting handle for adapter"
2476 " '%s'\n", dev->ofdev.node->full_name); 2507 " '%s'\n", dev->ofdev.node->full_name);
2477 ret = -ENODEV; 2508 ret = -ENODEV;
2478 goto out_free_ad; 2509 goto out_free_ad;
2479 } 2510 }
2480 2511
2481 adapter->handle = *adapter_handle;
2482 adapter->pd = EHEA_PD_ID; 2512 adapter->pd = EHEA_PD_ID;
2483 2513
2484 dev->ofdev.dev.driver_data = adapter; 2514 dev->ofdev.dev.driver_data = adapter;
@@ -2568,6 +2598,7 @@ static int __devexit ehea_remove(struct ibmebus_dev *dev)
2568 destroy_workqueue(adapter->ehea_wq); 2598 destroy_workqueue(adapter->ehea_wq);
2569 2599
2570 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter); 2600 ibmebus_free_irq(NULL, adapter->neq->attr.ist1, adapter);
2601 tasklet_kill(&adapter->neq_tasklet);
2571 2602
2572 ehea_destroy_eq(adapter->neq); 2603 ehea_destroy_eq(adapter->neq);
2573 2604
diff --git a/drivers/net/ehea/ehea_phyp.c b/drivers/net/ehea/ehea_phyp.c
index 0cfc2bc1a27b..37716e05e808 100644
--- a/drivers/net/ehea/ehea_phyp.c
+++ b/drivers/net/ehea/ehea_phyp.c
@@ -94,6 +94,7 @@ static long ehea_plpar_hcall9(unsigned long opcode,
94{ 94{
95 long ret; 95 long ret;
96 int i, sleep_msecs; 96 int i, sleep_msecs;
97 u8 cb_cat;
97 98
98 for (i = 0; i < 5; i++) { 99 for (i = 0; i < 5; i++) {
99 ret = plpar_hcall9(opcode, outs, 100 ret = plpar_hcall9(opcode, outs,
@@ -106,7 +107,13 @@ static long ehea_plpar_hcall9(unsigned long opcode,
106 continue; 107 continue;
107 } 108 }
108 109
109 if (ret < H_SUCCESS) 110 cb_cat = EHEA_BMASK_GET(H_MEHEAPORT_CAT, arg2);
111
112 if ((ret < H_SUCCESS) && !(((ret == H_AUTHORITY)
113 && (opcode == H_MODIFY_HEA_PORT))
114 && (((cb_cat == H_PORT_CB4) && ((arg3 == H_PORT_CB4_JUMBO)
115 || (arg3 == H_PORT_CB4_SPEED))) || ((cb_cat == H_PORT_CB7)
116 && (arg3 == H_PORT_CB7_DUCQPN)))))
110 ehea_error("opcode=%lx ret=%lx" 117 ehea_error("opcode=%lx ret=%lx"
111 " arg1=%lx arg2=%lx arg3=%lx arg4=%lx" 118 " arg1=%lx arg2=%lx arg3=%lx arg4=%lx"
112 " arg5=%lx arg6=%lx arg7=%lx arg8=%lx" 119 " arg5=%lx arg6=%lx arg7=%lx arg8=%lx"
@@ -120,7 +127,6 @@ static long ehea_plpar_hcall9(unsigned long opcode,
120 outs[0], outs[1], outs[2], outs[3], 127 outs[0], outs[1], outs[2], outs[3],
121 outs[4], outs[5], outs[6], outs[7], 128 outs[4], outs[5], outs[6], outs[7],
122 outs[8]); 129 outs[8]);
123
124 return ret; 130 return ret;
125 } 131 }
126 132
diff --git a/drivers/net/fs_enet/mac-fec.c b/drivers/net/fs_enet/mac-fec.c
index c2c5fd419bd0..ff6839477306 100644
--- a/drivers/net/fs_enet/mac-fec.c
+++ b/drivers/net/fs_enet/mac-fec.c
@@ -104,9 +104,9 @@ static int do_pd_setup(struct fs_enet_private *fep)
104 fep->interrupt = platform_get_irq_byname(pdev,"interrupt"); 104 fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
105 if (fep->interrupt < 0) 105 if (fep->interrupt < 0)
106 return -EINVAL; 106 return -EINVAL;
107 107
108 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 108 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
109 fep->fec.fecp =(void*)r->start; 109 fep->fec.fecp = ioremap(r->start, r->end - r->start + 1);
110 110
111 if(fep->fec.fecp == NULL) 111 if(fep->fec.fecp == NULL)
112 return -EINVAL; 112 return -EINVAL;
@@ -319,11 +319,14 @@ static void restart(struct net_device *dev)
319 * Clear any outstanding interrupt. 319 * Clear any outstanding interrupt.
320 */ 320 */
321 FW(fecp, ievent, 0xffc0); 321 FW(fecp, ievent, 0xffc0);
322#ifndef CONFIG_PPC_MERGE
322 FW(fecp, ivec, (fep->interrupt / 2) << 29); 323 FW(fecp, ivec, (fep->interrupt / 2) << 29);
323 324#else
325 FW(fecp, ivec, (virq_to_hw(fep->interrupt) / 2) << 29);
326#endif
324 327
325 /* 328 /*
326 * adjust to speed (only for DUET & RMII) 329 * adjust to speed (only for DUET & RMII)
327 */ 330 */
328#ifdef CONFIG_DUET 331#ifdef CONFIG_DUET
329 if (fpi->use_rmii) { 332 if (fpi->use_rmii) {
@@ -418,6 +421,7 @@ static void stop(struct net_device *dev)
418 421
419static void pre_request_irq(struct net_device *dev, int irq) 422static void pre_request_irq(struct net_device *dev, int irq)
420{ 423{
424#ifndef CONFIG_PPC_MERGE
421 immap_t *immap = fs_enet_immap; 425 immap_t *immap = fs_enet_immap;
422 u32 siel; 426 u32 siel;
423 427
@@ -431,6 +435,7 @@ static void pre_request_irq(struct net_device *dev, int irq)
431 siel &= ~(0x80000000 >> (irq & ~1)); 435 siel &= ~(0x80000000 >> (irq & ~1));
432 out_be32(&immap->im_siu_conf.sc_siel, siel); 436 out_be32(&immap->im_siu_conf.sc_siel, siel);
433 } 437 }
438#endif
434} 439}
435 440
436static void post_free_irq(struct net_device *dev, int irq) 441static void post_free_irq(struct net_device *dev, int irq)
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index 95ec5872c507..afd7fca7c6c4 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -121,13 +121,13 @@ static int do_pd_setup(struct fs_enet_private *fep)
121 return -EINVAL; 121 return -EINVAL;
122 122
123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); 123 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
124 fep->scc.sccp = (void *)r->start; 124 fep->scc.sccp = ioremap(r->start, r->end - r->start + 1);
125 125
126 if (fep->scc.sccp == NULL) 126 if (fep->scc.sccp == NULL)
127 return -EINVAL; 127 return -EINVAL;
128 128
129 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram"); 129 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pram");
130 fep->scc.ep = (void *)r->start; 130 fep->scc.ep = ioremap(r->start, r->end - r->start + 1);
131 131
132 if (fep->scc.ep == NULL) 132 if (fep->scc.ep == NULL)
133 return -EINVAL; 133 return -EINVAL;
@@ -397,6 +397,7 @@ static void stop(struct net_device *dev)
397 397
398static void pre_request_irq(struct net_device *dev, int irq) 398static void pre_request_irq(struct net_device *dev, int irq)
399{ 399{
400#ifndef CONFIG_PPC_MERGE
400 immap_t *immap = fs_enet_immap; 401 immap_t *immap = fs_enet_immap;
401 u32 siel; 402 u32 siel;
402 403
@@ -410,6 +411,7 @@ static void pre_request_irq(struct net_device *dev, int irq)
410 siel &= ~(0x80000000 >> (irq & ~1)); 411 siel &= ~(0x80000000 >> (irq & ~1));
411 out_be32(&immap->im_siu_conf.sc_siel, siel); 412 out_be32(&immap->im_siu_conf.sc_siel, siel);
412 } 413 }
414#endif
413} 415}
414 416
415static void post_free_irq(struct net_device *dev, int irq) 417static void post_free_irq(struct net_device *dev, int irq)
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 3ca1082ec776..340ee99652eb 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -441,25 +441,13 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
441 goto drop; 441 goto drop;
442 } 442 }
443 443
444 /* Make sure there is room for IrDA-USB header. The actual 444 memcpy(self->tx_buff + self->header_length, skb->data, skb->len);
445 * allocation will be done lower in skb_push().
446 * Also, we don't use directly skb_cow(), because it require
447 * headroom >= 16, which force unnecessary copies - Jean II */
448 if (skb_headroom(skb) < self->header_length) {
449 IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__);
450 if (skb_cow(skb, self->header_length)) {
451 IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
452 goto drop;
453 }
454 }
455 445
456 /* Change setting for next frame */ 446 /* Change setting for next frame */
457
458 if (self->capability & IUC_STIR421X) { 447 if (self->capability & IUC_STIR421X) {
459 __u8 turnaround_time; 448 __u8 turnaround_time;
460 __u8* frame; 449 __u8* frame = self->tx_buff;
461 turnaround_time = get_turnaround_time( skb ); 450 turnaround_time = get_turnaround_time( skb );
462 frame= skb_push(skb, self->header_length);
463 irda_usb_build_header(self, frame, 0); 451 irda_usb_build_header(self, frame, 0);
464 frame[2] = turnaround_time; 452 frame[2] = turnaround_time;
465 if ((skb->len != 0) && 453 if ((skb->len != 0) &&
@@ -472,17 +460,17 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
472 frame[1] = 0; 460 frame[1] = 0;
473 } 461 }
474 } else { 462 } else {
475 irda_usb_build_header(self, skb_push(skb, self->header_length), 0); 463 irda_usb_build_header(self, self->tx_buff, 0);
476 } 464 }
477 465
478 /* FIXME: Make macro out of this one */ 466 /* FIXME: Make macro out of this one */
479 ((struct irda_skb_cb *)skb->cb)->context = self; 467 ((struct irda_skb_cb *)skb->cb)->context = self;
480 468
481 usb_fill_bulk_urb(urb, self->usbdev, 469 usb_fill_bulk_urb(urb, self->usbdev,
482 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep), 470 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
483 skb->data, IRDA_SKB_MAX_MTU, 471 self->tx_buff, skb->len + self->header_length,
484 write_bulk_callback, skb); 472 write_bulk_callback, skb);
485 urb->transfer_buffer_length = skb->len; 473
486 /* This flag (URB_ZERO_PACKET) indicates that what we send is not 474 /* This flag (URB_ZERO_PACKET) indicates that what we send is not
487 * a continuous stream of data but separate packets. 475 * a continuous stream of data but separate packets.
488 * In this case, the USB layer will insert an empty USB frame (TD) 476 * In this case, the USB layer will insert an empty USB frame (TD)
@@ -1455,6 +1443,9 @@ static inline void irda_usb_close(struct irda_usb_cb *self)
1455 /* Remove the speed buffer */ 1443 /* Remove the speed buffer */
1456 kfree(self->speed_buff); 1444 kfree(self->speed_buff);
1457 self->speed_buff = NULL; 1445 self->speed_buff = NULL;
1446
1447 kfree(self->tx_buff);
1448 self->tx_buff = NULL;
1458} 1449}
1459 1450
1460/********************** USB CONFIG SUBROUTINES **********************/ 1451/********************** USB CONFIG SUBROUTINES **********************/
@@ -1524,8 +1515,6 @@ static inline int irda_usb_parse_endpoints(struct irda_usb_cb *self, struct usb_
1524 1515
1525 IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n", 1516 IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",
1526 __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep); 1517 __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);
1527 /* Should be 8, 16, 32 or 64 bytes */
1528 IRDA_ASSERT(self->bulk_out_mtu == 64, ;);
1529 1518
1530 return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0)); 1519 return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0));
1531} 1520}
@@ -1753,9 +1742,14 @@ static int irda_usb_probe(struct usb_interface *intf,
1753 1742
1754 memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU); 1743 memset(self->speed_buff, 0, IRDA_USB_SPEED_MTU);
1755 1744
1745 self->tx_buff = kzalloc(IRDA_SKB_MAX_MTU + self->header_length,
1746 GFP_KERNEL);
1747 if (self->tx_buff == NULL)
1748 goto err_out_4;
1749
1756 ret = irda_usb_open(self); 1750 ret = irda_usb_open(self);
1757 if (ret) 1751 if (ret)
1758 goto err_out_4; 1752 goto err_out_5;
1759 1753
1760 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name); 1754 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name);
1761 usb_set_intfdata(intf, self); 1755 usb_set_intfdata(intf, self);
@@ -1766,14 +1760,14 @@ static int irda_usb_probe(struct usb_interface *intf,
1766 self->needspatch = (ret < 0); 1760 self->needspatch = (ret < 0);
1767 if (self->needspatch) { 1761 if (self->needspatch) {
1768 IRDA_ERROR("STIR421X: Couldn't upload patch\n"); 1762 IRDA_ERROR("STIR421X: Couldn't upload patch\n");
1769 goto err_out_5; 1763 goto err_out_6;
1770 } 1764 }
1771 1765
1772 /* replace IrDA class descriptor with what patched device is now reporting */ 1766 /* replace IrDA class descriptor with what patched device is now reporting */
1773 irda_desc = irda_usb_find_class_desc (self->usbintf); 1767 irda_desc = irda_usb_find_class_desc (self->usbintf);
1774 if (irda_desc == NULL) { 1768 if (irda_desc == NULL) {
1775 ret = -ENODEV; 1769 ret = -ENODEV;
1776 goto err_out_5; 1770 goto err_out_6;
1777 } 1771 }
1778 if (self->irda_desc) 1772 if (self->irda_desc)
1779 kfree (self->irda_desc); 1773 kfree (self->irda_desc);
@@ -1782,9 +1776,10 @@ static int irda_usb_probe(struct usb_interface *intf,
1782 } 1776 }
1783 1777
1784 return 0; 1778 return 0;
1785 1779err_out_6:
1786err_out_5:
1787 unregister_netdev(self->netdev); 1780 unregister_netdev(self->netdev);
1781err_out_5:
1782 kfree(self->tx_buff);
1788err_out_4: 1783err_out_4:
1789 kfree(self->speed_buff); 1784 kfree(self->speed_buff);
1790err_out_3: 1785err_out_3:
diff --git a/drivers/net/irda/irda-usb.h b/drivers/net/irda/irda-usb.h
index 6b2271f18e77..e846c38224a3 100644
--- a/drivers/net/irda/irda-usb.h
+++ b/drivers/net/irda/irda-usb.h
@@ -156,6 +156,7 @@ struct irda_usb_cb {
156 struct irlap_cb *irlap; /* The link layer we are binded to */ 156 struct irlap_cb *irlap; /* The link layer we are binded to */
157 struct qos_info qos; 157 struct qos_info qos;
158 char *speed_buff; /* Buffer for speed changes */ 158 char *speed_buff; /* Buffer for speed changes */
159 char *tx_buff;
159 160
160 struct timeval stamp; 161 struct timeval stamp;
161 struct timeval now; 162 struct timeval now;
diff --git a/drivers/net/irda/stir4200.c b/drivers/net/irda/stir4200.c
index c14a74634fd5..20d306fea4cb 100644
--- a/drivers/net/irda/stir4200.c
+++ b/drivers/net/irda/stir4200.c
@@ -59,7 +59,7 @@
59#include <asm/byteorder.h> 59#include <asm/byteorder.h>
60#include <asm/unaligned.h> 60#include <asm/unaligned.h>
61 61
62MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 62MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
63MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200"); 63MODULE_DESCRIPTION("IrDA-USB Dongle Driver for SigmaTel STIr4200");
64MODULE_LICENSE("GPL"); 64MODULE_LICENSE("GPL");
65 65
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index 18c68193bf14..e2b1af618450 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -166,7 +166,7 @@ static void vlsi_proc_pdev(struct seq_file *seq, struct pci_dev *pdev)
166 unsigned i; 166 unsigned i;
167 167
168 seq_printf(seq, "\n%s (vid/did: %04x/%04x)\n", 168 seq_printf(seq, "\n%s (vid/did: %04x/%04x)\n",
169 PCIDEV_NAME(pdev), (int)pdev->vendor, (int)pdev->device); 169 pci_name(pdev), (int)pdev->vendor, (int)pdev->device);
170 seq_printf(seq, "pci-power-state: %u\n", (unsigned) pdev->current_state); 170 seq_printf(seq, "pci-power-state: %u\n", (unsigned) pdev->current_state);
171 seq_printf(seq, "resources: irq=%u / io=0x%04x / dma_mask=0x%016Lx\n", 171 seq_printf(seq, "resources: irq=%u / io=0x%04x / dma_mask=0x%016Lx\n",
172 pdev->irq, (unsigned)pci_resource_start(pdev, 0), (unsigned long long)pdev->dma_mask); 172 pdev->irq, (unsigned)pci_resource_start(pdev, 0), (unsigned long long)pdev->dma_mask);
@@ -1401,7 +1401,7 @@ static void vlsi_tx_timeout(struct net_device *ndev)
1401 1401
1402 if (vlsi_start_hw(idev)) 1402 if (vlsi_start_hw(idev))
1403 IRDA_ERROR("%s: failed to restart hw - %s(%s) unusable!\n", 1403 IRDA_ERROR("%s: failed to restart hw - %s(%s) unusable!\n",
1404 __FUNCTION__, PCIDEV_NAME(idev->pdev), ndev->name); 1404 __FUNCTION__, pci_name(idev->pdev), ndev->name);
1405 else 1405 else
1406 netif_start_queue(ndev); 1406 netif_start_queue(ndev);
1407} 1407}
@@ -1643,7 +1643,7 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1643 pdev->current_state = 0; /* hw must be running now */ 1643 pdev->current_state = 0; /* hw must be running now */
1644 1644
1645 IRDA_MESSAGE("%s: IrDA PCI controller %s detected\n", 1645 IRDA_MESSAGE("%s: IrDA PCI controller %s detected\n",
1646 drivername, PCIDEV_NAME(pdev)); 1646 drivername, pci_name(pdev));
1647 1647
1648 if ( !pci_resource_start(pdev,0) 1648 if ( !pci_resource_start(pdev,0)
1649 || !(pci_resource_flags(pdev,0) & IORESOURCE_IO) ) { 1649 || !(pci_resource_flags(pdev,0) & IORESOURCE_IO) ) {
@@ -1728,7 +1728,7 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)
1728 1728
1729 pci_set_drvdata(pdev, NULL); 1729 pci_set_drvdata(pdev, NULL);
1730 1730
1731 IRDA_MESSAGE("%s: %s removed\n", drivername, PCIDEV_NAME(pdev)); 1731 IRDA_MESSAGE("%s: %s removed\n", drivername, pci_name(pdev));
1732} 1732}
1733 1733
1734#ifdef CONFIG_PM 1734#ifdef CONFIG_PM
@@ -1748,7 +1748,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1748 1748
1749 if (!ndev) { 1749 if (!ndev) {
1750 IRDA_ERROR("%s - %s: no netdevice \n", 1750 IRDA_ERROR("%s - %s: no netdevice \n",
1751 __FUNCTION__, PCIDEV_NAME(pdev)); 1751 __FUNCTION__, pci_name(pdev));
1752 return 0; 1752 return 0;
1753 } 1753 }
1754 idev = ndev->priv; 1754 idev = ndev->priv;
@@ -1759,7 +1759,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1759 pdev->current_state = state.event; 1759 pdev->current_state = state.event;
1760 } 1760 }
1761 else 1761 else
1762 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, PCIDEV_NAME(pdev), pdev->current_state, state.event); 1762 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, pci_name(pdev), pdev->current_state, state.event);
1763 up(&idev->sem); 1763 up(&idev->sem);
1764 return 0; 1764 return 0;
1765 } 1765 }
@@ -1787,7 +1787,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1787 1787
1788 if (!ndev) { 1788 if (!ndev) {
1789 IRDA_ERROR("%s - %s: no netdevice \n", 1789 IRDA_ERROR("%s - %s: no netdevice \n",
1790 __FUNCTION__, PCIDEV_NAME(pdev)); 1790 __FUNCTION__, pci_name(pdev));
1791 return 0; 1791 return 0;
1792 } 1792 }
1793 idev = ndev->priv; 1793 idev = ndev->priv;
@@ -1795,7 +1795,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1795 if (pdev->current_state == 0) { 1795 if (pdev->current_state == 0) {
1796 up(&idev->sem); 1796 up(&idev->sem);
1797 IRDA_WARNING("%s - %s: already resumed\n", 1797 IRDA_WARNING("%s - %s: already resumed\n",
1798 __FUNCTION__, PCIDEV_NAME(pdev)); 1798 __FUNCTION__, pci_name(pdev));
1799 return 0; 1799 return 0;
1800 } 1800 }
1801 1801
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h
index c37f0bc4c7f9..2d3b773d8e35 100644
--- a/drivers/net/irda/vlsi_ir.h
+++ b/drivers/net/irda/vlsi_ir.h
@@ -41,39 +41,6 @@
41#define PCI_CLASS_SUBCLASS_MASK 0xffff 41#define PCI_CLASS_SUBCLASS_MASK 0xffff
42#endif 42#endif
43 43
44/* in recent 2.5 interrupt handlers have non-void return value */
45#ifndef IRQ_RETVAL
46typedef void irqreturn_t;
47#define IRQ_NONE
48#define IRQ_HANDLED
49#define IRQ_RETVAL(x)
50#endif
51
52/* some stuff need to check kernelversion. Not all 2.5 stuff was present
53 * in early 2.5.x - the test is merely to separate 2.4 from 2.5
54 */
55#include <linux/version.h>
56
57#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
58
59/* PDE() introduced in 2.5.4 */
60#ifdef CONFIG_PROC_FS
61#define PDE(inode) ((inode)->i_private)
62#endif
63
64/* irda crc16 calculation exported in 2.5.42 */
65#define irda_calc_crc16(fcs,buf,len) (GOOD_FCS)
66
67/* we use this for unified pci device name access */
68#define PCIDEV_NAME(pdev) ((pdev)->name)
69
70#else /* 2.5 or later */
71
72/* whatever we get from the associated struct device - bus:slot:dev.fn id */
73#define PCIDEV_NAME(pdev) (pci_name(pdev))
74
75#endif
76
77/* ================================================================ */ 44/* ================================================================ */
78 45
79/* non-standard PCI registers */ 46/* non-standard PCI registers */
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index c41ae4286eea..b3bf86422734 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -314,6 +314,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
314 314
315 while (mp->tx_desc_count > 0) { 315 while (mp->tx_desc_count > 0) {
316 spin_lock_irqsave(&mp->lock, flags); 316 spin_lock_irqsave(&mp->lock, flags);
317
318 /* tx_desc_count might have changed before acquiring the lock */
319 if (mp->tx_desc_count <= 0) {
320 spin_unlock_irqrestore(&mp->lock, flags);
321 return released;
322 }
323
317 tx_index = mp->tx_used_desc_q; 324 tx_index = mp->tx_used_desc_q;
318 desc = &mp->p_tx_desc_area[tx_index]; 325 desc = &mp->p_tx_desc_area[tx_index];
319 cmd_sts = desc->cmd_sts; 326 cmd_sts = desc->cmd_sts;
@@ -332,13 +339,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
332 if (skb) 339 if (skb)
333 mp->tx_skb[tx_index] = NULL; 340 mp->tx_skb[tx_index] = NULL;
334 341
335 spin_unlock_irqrestore(&mp->lock, flags);
336
337 if (cmd_sts & ETH_ERROR_SUMMARY) { 342 if (cmd_sts & ETH_ERROR_SUMMARY) {
338 printk("%s: Error in TX\n", dev->name); 343 printk("%s: Error in TX\n", dev->name);
339 mp->stats.tx_errors++; 344 mp->stats.tx_errors++;
340 } 345 }
341 346
347 spin_unlock_irqrestore(&mp->lock, flags);
348
342 if (cmd_sts & ETH_TX_FIRST_DESC) 349 if (cmd_sts & ETH_TX_FIRST_DESC)
343 dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE); 350 dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
344 else 351 else
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 07cf574197e5..61cbd4a60446 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -71,7 +71,7 @@
71#include "myri10ge_mcp.h" 71#include "myri10ge_mcp.h"
72#include "myri10ge_mcp_gen_header.h" 72#include "myri10ge_mcp_gen_header.h"
73 73
74#define MYRI10GE_VERSION_STR "1.1.0" 74#define MYRI10GE_VERSION_STR "1.2.0"
75 75
76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); 76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
77MODULE_AUTHOR("Maintainer: help@myri.com"); 77MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -274,6 +274,10 @@ static int myri10ge_fill_thresh = 256;
274module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR); 274module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
275MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n"); 275MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
276 276
277static int myri10ge_wcfifo = 1;
278module_param(myri10ge_wcfifo, int, S_IRUGO);
279MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
280
277#define MYRI10GE_FW_OFFSET 1024*1024 281#define MYRI10GE_FW_OFFSET 1024*1024
278#define MYRI10GE_HIGHPART_TO_U32(X) \ 282#define MYRI10GE_HIGHPART_TO_U32(X) \
279(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0) 283(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
@@ -1714,7 +1718,7 @@ static int myri10ge_open(struct net_device *dev)
1714 goto abort_with_irq; 1718 goto abort_with_irq;
1715 } 1719 }
1716 1720
1717 if (mgp->mtrr >= 0) { 1721 if (myri10ge_wcfifo && mgp->mtrr >= 0) {
1718 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4; 1722 mgp->tx.wc_fifo = (u8 __iomem *) mgp->sram + MXGEFW_ETH_SEND_4;
1719 mgp->rx_small.wc_fifo = 1723 mgp->rx_small.wc_fifo =
1720 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL; 1724 (u8 __iomem *) mgp->sram + MXGEFW_ETH_RECV_SMALL;
@@ -2878,7 +2882,6 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2878 netdev->hard_start_xmit = myri10ge_xmit; 2882 netdev->hard_start_xmit = myri10ge_xmit;
2879 netdev->get_stats = myri10ge_get_stats; 2883 netdev->get_stats = myri10ge_get_stats;
2880 netdev->base_addr = mgp->iomem_base; 2884 netdev->base_addr = mgp->iomem_base;
2881 netdev->irq = pdev->irq;
2882 netdev->change_mtu = myri10ge_change_mtu; 2885 netdev->change_mtu = myri10ge_change_mtu;
2883 netdev->set_multicast_list = myri10ge_set_multicast_list; 2886 netdev->set_multicast_list = myri10ge_set_multicast_list;
2884 netdev->set_mac_address = myri10ge_set_mac_address; 2887 netdev->set_mac_address = myri10ge_set_mac_address;
@@ -2888,6 +2891,15 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2888 netdev->poll = myri10ge_poll; 2891 netdev->poll = myri10ge_poll;
2889 netdev->weight = myri10ge_napi_weight; 2892 netdev->weight = myri10ge_napi_weight;
2890 2893
2894 /* make sure we can get an irq, and that MSI can be
2895 * setup (if available). Also ensure netdev->irq
2896 * is set to correct value if MSI is enabled */
2897 status = myri10ge_request_irq(mgp);
2898 if (status != 0)
2899 goto abort_with_firmware;
2900 netdev->irq = pdev->irq;
2901 myri10ge_free_irq(mgp);
2902
2891 /* Save configuration space to be restored if the 2903 /* Save configuration space to be restored if the
2892 * nic resets due to a parity error */ 2904 * nic resets due to a parity error */
2893 pci_save_state(pdev); 2905 pci_save_state(pdev);
@@ -2903,8 +2915,9 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2903 dev_err(&pdev->dev, "register_netdev failed: %d\n", status); 2915 dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
2904 goto abort_with_state; 2916 goto abort_with_state;
2905 } 2917 }
2906 dev_info(dev, "%d, tx bndry %d, fw %s, WC %s\n", 2918 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n",
2907 pdev->irq, mgp->tx.boundary, mgp->fw_name, 2919 (mgp->msi_enabled ? "MSI" : "xPIC"),
2920 netdev->irq, mgp->tx.boundary, mgp->fw_name,
2908 (mgp->mtrr >= 0 ? "Enabled" : "Disabled")); 2921 (mgp->mtrr >= 0 ? "Enabled" : "Disabled"));
2909 2922
2910 return 0; 2923 return 0;
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index 6490acf05305..59324b1693d6 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -63,12 +63,11 @@
63 63
64#include "netxen_nic_hw.h" 64#include "netxen_nic_hw.h"
65 65
66#define NETXEN_NIC_BUILD_NO "4" 66#define NETXEN_NIC_BUILD_NO "2"
67#define _NETXEN_NIC_LINUX_MAJOR 3 67#define _NETXEN_NIC_LINUX_MAJOR 3
68#define _NETXEN_NIC_LINUX_MINOR 3 68#define _NETXEN_NIC_LINUX_MINOR 3
69#define _NETXEN_NIC_LINUX_SUBVERSION 2 69#define _NETXEN_NIC_LINUX_SUBVERSION 3
70#define NETXEN_NIC_LINUX_VERSIONID "3.3.2" "-" NETXEN_NIC_BUILD_NO 70#define NETXEN_NIC_LINUX_VERSIONID "3.3.3" "-" NETXEN_NIC_BUILD_NO
71#define NETXEN_NIC_FW_VERSIONID "3.3.2"
72 71
73#define RCV_DESC_RINGSIZE \ 72#define RCV_DESC_RINGSIZE \
74 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count) 73 (sizeof(struct rcv_desc) * adapter->max_rx_desc_count)
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index c0c31d1914a7..191e2336e323 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -984,7 +984,8 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
984 _NETXEN_NIC_LINUX_MAJOR, fw_major); 984 _NETXEN_NIC_LINUX_MAJOR, fw_major);
985 adapter->driver_mismatch = 1; 985 adapter->driver_mismatch = 1;
986 } 986 }
987 if (fw_minor != _NETXEN_NIC_LINUX_MINOR) { 987 if (fw_minor != _NETXEN_NIC_LINUX_MINOR &&
988 fw_minor != (_NETXEN_NIC_LINUX_MINOR + 1)) {
988 printk(KERN_ERR "The mismatch in driver version and firmware " 989 printk(KERN_ERR "The mismatch in driver version and firmware "
989 "version minor number\n" 990 "version minor number\n"
990 "Driver version minor number = %d \t" 991 "Driver version minor number = %d \t"
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 8a5792fea774..96e1bee19ba0 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -1144,7 +1144,7 @@ static int __init netxen_init_module(void)
1144 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0) 1144 if ((netxen_workq = create_singlethread_workqueue("netxen")) == 0)
1145 return -ENOMEM; 1145 return -ENOMEM;
1146 1146
1147 return pci_module_init(&netxen_driver); 1147 return pci_register_driver(&netxen_driver);
1148} 1148}
1149 1149
1150module_init(netxen_init_module); 1150module_init(netxen_init_module);
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 342f4062de0b..461e8274ef69 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -606,11 +606,14 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
606{ 606{
607 kio_addr_t ioaddr = dev->base_addr; 607 kio_addr_t ioaddr = dev->base_addr;
608 struct el3_private *priv = netdev_priv(dev); 608 struct el3_private *priv = netdev_priv(dev);
609 unsigned long flags;
609 610
610 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, " 611 DEBUG(3, "%s: el3_start_xmit(length = %ld) called, "
611 "status %4.4x.\n", dev->name, (long)skb->len, 612 "status %4.4x.\n", dev->name, (long)skb->len,
612 inw(ioaddr + EL3_STATUS)); 613 inw(ioaddr + EL3_STATUS));
613 614
615 spin_lock_irqsave(&priv->lock, flags);
616
614 priv->stats.tx_bytes += skb->len; 617 priv->stats.tx_bytes += skb->len;
615 618
616 /* Put out the doubleword header... */ 619 /* Put out the doubleword header... */
@@ -628,6 +631,7 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
628 631
629 dev_kfree_skb(skb); 632 dev_kfree_skb(skb);
630 pop_tx_status(dev); 633 pop_tx_status(dev);
634 spin_unlock_irqrestore(&priv->lock, flags);
631 635
632 return 0; 636 return 0;
633} 637}
@@ -729,14 +733,13 @@ static void media_check(unsigned long arg)
729 733
730 if (!netif_device_present(dev)) goto reschedule; 734 if (!netif_device_present(dev)) goto reschedule;
731 735
732 EL3WINDOW(1);
733 /* Check for pending interrupt with expired latency timer: with 736 /* Check for pending interrupt with expired latency timer: with
734 this, we can limp along even if the interrupt is blocked */ 737 this, we can limp along even if the interrupt is blocked */
735 if ((inw(ioaddr + EL3_STATUS) & IntLatch) && 738 if ((inw(ioaddr + EL3_STATUS) & IntLatch) &&
736 (inb(ioaddr + EL3_TIMER) == 0xff)) { 739 (inb(ioaddr + EL3_TIMER) == 0xff)) {
737 if (!lp->fast_poll) 740 if (!lp->fast_poll)
738 printk(KERN_WARNING "%s: interrupt(s) dropped!\n", dev->name); 741 printk(KERN_WARNING "%s: interrupt(s) dropped!\n", dev->name);
739 el3_interrupt(dev->irq, lp); 742 el3_interrupt(dev->irq, dev);
740 lp->fast_poll = HZ; 743 lp->fast_poll = HZ;
741 } 744 }
742 if (lp->fast_poll) { 745 if (lp->fast_poll) {
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 096d4a100bf2..86135397f430 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -349,7 +349,7 @@ static int __init fixed_init(void)
349 fixed_mdio_register_device(0, 100, 1); 349 fixed_mdio_register_device(0, 100, 1);
350#endif 350#endif
351 351
352#ifdef CONFIX_FIXED_MII_10_FDX 352#ifdef CONFIG_FIXED_MII_10_FDX
353 fixed_mdio_register_device(0, 10, 1); 353 fixed_mdio_register_device(0, 10, 1);
354#endif 354#endif
355 return 0; 355 return 0;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e175f3910b18..9765fa661467 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -286,6 +286,7 @@ int phy_ethtool_sset(struct phy_device *phydev, struct ethtool_cmd *cmd)
286 286
287 return 0; 287 return 0;
288} 288}
289EXPORT_SYMBOL(phy_ethtool_sset);
289 290
290int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd) 291int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
291{ 292{
@@ -302,7 +303,7 @@ int phy_ethtool_gset(struct phy_device *phydev, struct ethtool_cmd *cmd)
302 303
303 return 0; 304 return 0;
304} 305}
305 306EXPORT_SYMBOL(phy_ethtool_gset);
306 307
307/* Note that this function is currently incompatible with the 308/* Note that this function is currently incompatible with the
308 * PHYCONTROL layer. It changes registers without regard to 309 * PHYCONTROL layer. It changes registers without regard to
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 250cdbeefdfd..1dd66b8ea0fa 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -556,10 +556,9 @@ static int init_shared_mem(struct s2io_nic *nic)
556 } 556 }
557 } 557 }
558 558
559 nic->ufo_in_band_v = kmalloc((sizeof(u64) * size), GFP_KERNEL); 559 nic->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL);
560 if (!nic->ufo_in_band_v) 560 if (!nic->ufo_in_band_v)
561 return -ENOMEM; 561 return -ENOMEM;
562 memset(nic->ufo_in_band_v, 0, size);
563 562
564 /* Allocation and initialization of RXDs in Rings */ 563 /* Allocation and initialization of RXDs in Rings */
565 size = 0; 564 size = 0;
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index b70ed79d4121..45d91b159100 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -1562,7 +1562,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
1562 for (i = 0; i < MAC_ADDR_LEN / 2; i++) { 1562 for (i = 0; i < MAC_ADDR_LEN / 2; i++) {
1563 __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i); 1563 __le16 w = sis190_read_eeprom(ioaddr, EEPROMMACAddr + i);
1564 1564
1565 ((u16 *)dev->dev_addr)[0] = le16_to_cpu(w); 1565 ((u16 *)dev->dev_addr)[i] = le16_to_cpu(w);
1566 } 1566 }
1567 1567
1568 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo)); 1568 sis190_set_rgmii(tp, sis190_read_eeprom(ioaddr, EEPROMInfo));
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index deedfd5f8226..45283f3f95e4 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -60,7 +60,7 @@
60#define LINK_HZ (HZ/2) 60#define LINK_HZ (HZ/2)
61 61
62MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver"); 62MODULE_DESCRIPTION("SysKonnect Gigabit Ethernet driver");
63MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 63MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
64MODULE_LICENSE("GPL"); 64MODULE_LICENSE("GPL");
65MODULE_VERSION(DRV_VERSION); 65MODULE_VERSION(DRV_VERSION);
66 66
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index a6601e8d423c..822dd0b13133 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -3639,29 +3639,6 @@ static int sky2_resume(struct pci_dev *pdev)
3639out: 3639out:
3640 return err; 3640 return err;
3641} 3641}
3642
3643/* BIOS resume runs after device (it's a bug in PM)
3644 * as a temporary workaround on suspend/resume leave MSI disabled
3645 */
3646static int sky2_suspend_late(struct pci_dev *pdev, pm_message_t state)
3647{
3648 struct sky2_hw *hw = pci_get_drvdata(pdev);
3649
3650 free_irq(pdev->irq, hw);
3651 if (hw->msi) {
3652 pci_disable_msi(pdev);
3653 hw->msi = 0;
3654 }
3655 return 0;
3656}
3657
3658static int sky2_resume_early(struct pci_dev *pdev)
3659{
3660 struct sky2_hw *hw = pci_get_drvdata(pdev);
3661 struct net_device *dev = hw->dev[0];
3662
3663 return request_irq(pdev->irq, sky2_intr, IRQF_SHARED, dev->name, hw);
3664}
3665#endif 3642#endif
3666 3643
3667static struct pci_driver sky2_driver = { 3644static struct pci_driver sky2_driver = {
@@ -3672,8 +3649,6 @@ static struct pci_driver sky2_driver = {
3672#ifdef CONFIG_PM 3649#ifdef CONFIG_PM
3673 .suspend = sky2_suspend, 3650 .suspend = sky2_suspend,
3674 .resume = sky2_resume, 3651 .resume = sky2_resume,
3675 .suspend_late = sky2_suspend_late,
3676 .resume_early = sky2_resume_early,
3677#endif 3652#endif
3678}; 3653};
3679 3654
@@ -3691,6 +3666,6 @@ module_init(sky2_init_module);
3691module_exit(sky2_cleanup_module); 3666module_exit(sky2_cleanup_module);
3692 3667
3693MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver"); 3668MODULE_DESCRIPTION("Marvell Yukon 2 Gigabit Ethernet driver");
3694MODULE_AUTHOR("Stephen Hemminger <shemminger@osdl.org>"); 3669MODULE_AUTHOR("Stephen Hemminger <shemminger@linux-foundation.org>");
3695MODULE_LICENSE("GPL"); 3670MODULE_LICENSE("GPL");
3696MODULE_VERSION(DRV_VERSION); 3671MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150f5b05..7e4b23c7c1ba 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -29,6 +29,7 @@
29#include <linux/fsl_devices.h> 29#include <linux/fsl_devices.h>
30#include <linux/ethtool.h> 30#include <linux/ethtool.h>
31#include <linux/mii.h> 31#include <linux/mii.h>
32#include <linux/workqueue.h>
32 33
33#include <asm/of_platform.h> 34#include <asm/of_platform.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -472,7 +473,7 @@ static void put_enet_addr_container(struct enet_addr_container *enet_addr_cont)
472 kfree(enet_addr_cont); 473 kfree(enet_addr_cont);
473} 474}
474 475
475static int set_mac_addr(__be16 __iomem *reg, u8 *mac) 476static void set_mac_addr(__be16 __iomem *reg, u8 *mac)
476{ 477{
477 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]); 478 out_be16(&reg[0], ((u16)mac[5] << 8) | mac[4]);
478 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]); 479 out_be16(&reg[1], ((u16)mac[3] << 8) | mac[2]);
@@ -3920,10 +3921,11 @@ static irqreturn_t phy_interrupt(int irq, void *dev_id)
3920} 3921}
3921 3922
3922/* Scheduled by the phy_interrupt/timer to handle PHY changes */ 3923/* Scheduled by the phy_interrupt/timer to handle PHY changes */
3923static void ugeth_phy_change(void *data) 3924static void ugeth_phy_change(struct work_struct *work)
3924{ 3925{
3925 struct net_device *dev = (struct net_device *)data; 3926 struct ucc_geth_private *ugeth =
3926 struct ucc_geth_private *ugeth = netdev_priv(dev); 3927 container_of(work, struct ucc_geth_private, tq);
3928 struct net_device *dev = ugeth->dev;
3927 struct ucc_geth *ug_regs; 3929 struct ucc_geth *ug_regs;
3928 int result = 0; 3930 int result = 0;
3929 3931
@@ -4080,7 +4082,7 @@ static int ucc_geth_open(struct net_device *dev)
4080#endif /* CONFIG_UGETH_NAPI */ 4082#endif /* CONFIG_UGETH_NAPI */
4081 4083
4082 /* Set up the PHY change work queue */ 4084 /* Set up the PHY change work queue */
4083 INIT_WORK(&ugeth->tq, ugeth_phy_change, dev); 4085 INIT_WORK(&ugeth->tq, ugeth_phy_change);
4084 4086
4085 init_timer(&ugeth->phy_info_timer); 4087 init_timer(&ugeth->phy_info_timer);
4086 ugeth->phy_info_timer.function = &ugeth_phy_startup_timer; 4088 ugeth->phy_info_timer.function = &ugeth_phy_startup_timer;
diff --git a/drivers/net/ucc_geth_phy.c b/drivers/net/ucc_geth_phy.c
index 5360ec05eaa3..3c86592ce03c 100644
--- a/drivers/net/ucc_geth_phy.c
+++ b/drivers/net/ucc_geth_phy.c
@@ -68,8 +68,31 @@ static int gbit_config_aneg(struct ugeth_mii_info *mii_info);
68static int genmii_config_aneg(struct ugeth_mii_info *mii_info); 68static int genmii_config_aneg(struct ugeth_mii_info *mii_info);
69static int genmii_update_link(struct ugeth_mii_info *mii_info); 69static int genmii_update_link(struct ugeth_mii_info *mii_info);
70static int genmii_read_status(struct ugeth_mii_info *mii_info); 70static int genmii_read_status(struct ugeth_mii_info *mii_info);
71u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum); 71
72void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val); 72static u16 ucc_geth_phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
73{
74 u16 retval;
75 unsigned long flags;
76
77 ugphy_vdbg("%s: IN", __FUNCTION__);
78
79 spin_lock_irqsave(&mii_info->mdio_lock, flags);
80 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
81 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
82
83 return retval;
84}
85
86static void ucc_geth_phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
87{
88 unsigned long flags;
89
90 ugphy_vdbg("%s: IN", __FUNCTION__);
91
92 spin_lock_irqsave(&mii_info->mdio_lock, flags);
93 mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
94 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
95}
73 96
74/* Write value to the PHY for this device to the register at regnum, */ 97/* Write value to the PHY for this device to the register at regnum, */
75/* waiting until the write is done before it returns. All PHY */ 98/* waiting until the write is done before it returns. All PHY */
@@ -184,7 +207,7 @@ static void config_genmii_advert(struct ugeth_mii_info *mii_info)
184 advertise = mii_info->advertising; 207 advertise = mii_info->advertising;
185 208
186 /* Setup standard advertisement */ 209 /* Setup standard advertisement */
187 adv = phy_read(mii_info, MII_ADVERTISE); 210 adv = ucc_geth_phy_read(mii_info, MII_ADVERTISE);
188 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); 211 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
189 if (advertise & ADVERTISED_10baseT_Half) 212 if (advertise & ADVERTISED_10baseT_Half)
190 adv |= ADVERTISE_10HALF; 213 adv |= ADVERTISE_10HALF;
@@ -194,7 +217,7 @@ static void config_genmii_advert(struct ugeth_mii_info *mii_info)
194 adv |= ADVERTISE_100HALF; 217 adv |= ADVERTISE_100HALF;
195 if (advertise & ADVERTISED_100baseT_Full) 218 if (advertise & ADVERTISED_100baseT_Full)
196 adv |= ADVERTISE_100FULL; 219 adv |= ADVERTISE_100FULL;
197 phy_write(mii_info, MII_ADVERTISE, adv); 220 ucc_geth_phy_write(mii_info, MII_ADVERTISE, adv);
198} 221}
199 222
200static void genmii_setup_forced(struct ugeth_mii_info *mii_info) 223static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
@@ -204,7 +227,7 @@ static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
204 227
205 ugphy_vdbg("%s: IN", __FUNCTION__); 228 ugphy_vdbg("%s: IN", __FUNCTION__);
206 229
207 ctrl = phy_read(mii_info, MII_BMCR); 230 ctrl = ucc_geth_phy_read(mii_info, MII_BMCR);
208 231
209 ctrl &= 232 ctrl &=
210 ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE); 233 ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_SPEED1000 | BMCR_ANENABLE);
@@ -234,7 +257,7 @@ static void genmii_setup_forced(struct ugeth_mii_info *mii_info)
234 break; 257 break;
235 } 258 }
236 259
237 phy_write(mii_info, MII_BMCR, ctrl); 260 ucc_geth_phy_write(mii_info, MII_BMCR, ctrl);
238} 261}
239 262
240/* Enable and Restart Autonegotiation */ 263/* Enable and Restart Autonegotiation */
@@ -244,9 +267,9 @@ static void genmii_restart_aneg(struct ugeth_mii_info *mii_info)
244 267
245 ugphy_vdbg("%s: IN", __FUNCTION__); 268 ugphy_vdbg("%s: IN", __FUNCTION__);
246 269
247 ctl = phy_read(mii_info, MII_BMCR); 270 ctl = ucc_geth_phy_read(mii_info, MII_BMCR);
248 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 271 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART);
249 phy_write(mii_info, MII_BMCR, ctl); 272 ucc_geth_phy_write(mii_info, MII_BMCR, ctl);
250} 273}
251 274
252static int gbit_config_aneg(struct ugeth_mii_info *mii_info) 275static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
@@ -261,14 +284,14 @@ static int gbit_config_aneg(struct ugeth_mii_info *mii_info)
261 config_genmii_advert(mii_info); 284 config_genmii_advert(mii_info);
262 advertise = mii_info->advertising; 285 advertise = mii_info->advertising;
263 286
264 adv = phy_read(mii_info, MII_1000BASETCONTROL); 287 adv = ucc_geth_phy_read(mii_info, MII_1000BASETCONTROL);
265 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP | 288 adv &= ~(MII_1000BASETCONTROL_FULLDUPLEXCAP |
266 MII_1000BASETCONTROL_HALFDUPLEXCAP); 289 MII_1000BASETCONTROL_HALFDUPLEXCAP);
267 if (advertise & SUPPORTED_1000baseT_Half) 290 if (advertise & SUPPORTED_1000baseT_Half)
268 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP; 291 adv |= MII_1000BASETCONTROL_HALFDUPLEXCAP;
269 if (advertise & SUPPORTED_1000baseT_Full) 292 if (advertise & SUPPORTED_1000baseT_Full)
270 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP; 293 adv |= MII_1000BASETCONTROL_FULLDUPLEXCAP;
271 phy_write(mii_info, MII_1000BASETCONTROL, adv); 294 ucc_geth_phy_write(mii_info, MII_1000BASETCONTROL, adv);
272 295
273 /* Start/Restart aneg */ 296 /* Start/Restart aneg */
274 genmii_restart_aneg(mii_info); 297 genmii_restart_aneg(mii_info);
@@ -298,10 +321,10 @@ static int genmii_update_link(struct ugeth_mii_info *mii_info)
298 ugphy_vdbg("%s: IN", __FUNCTION__); 321 ugphy_vdbg("%s: IN", __FUNCTION__);
299 322
300 /* Do a fake read */ 323 /* Do a fake read */
301 phy_read(mii_info, MII_BMSR); 324 ucc_geth_phy_read(mii_info, MII_BMSR);
302 325
303 /* Read link and autonegotiation status */ 326 /* Read link and autonegotiation status */
304 status = phy_read(mii_info, MII_BMSR); 327 status = ucc_geth_phy_read(mii_info, MII_BMSR);
305 if ((status & BMSR_LSTATUS) == 0) 328 if ((status & BMSR_LSTATUS) == 0)
306 mii_info->link = 0; 329 mii_info->link = 0;
307 else 330 else
@@ -329,7 +352,7 @@ static int genmii_read_status(struct ugeth_mii_info *mii_info)
329 return err; 352 return err;
330 353
331 if (mii_info->autoneg) { 354 if (mii_info->autoneg) {
332 status = phy_read(mii_info, MII_LPA); 355 status = ucc_geth_phy_read(mii_info, MII_LPA);
333 356
334 if (status & (LPA_10FULL | LPA_100FULL)) 357 if (status & (LPA_10FULL | LPA_100FULL))
335 mii_info->duplex = DUPLEX_FULL; 358 mii_info->duplex = DUPLEX_FULL;
@@ -352,9 +375,9 @@ static int marvell_init(struct ugeth_mii_info *mii_info)
352{ 375{
353 ugphy_vdbg("%s: IN", __FUNCTION__); 376 ugphy_vdbg("%s: IN", __FUNCTION__);
354 377
355 phy_write(mii_info, 0x14, 0x0cd2); 378 ucc_geth_phy_write(mii_info, 0x14, 0x0cd2);
356 phy_write(mii_info, MII_BMCR, 379 ucc_geth_phy_write(mii_info, MII_BMCR,
357 phy_read(mii_info, MII_BMCR) | BMCR_RESET); 380 ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
358 msleep(4000); 381 msleep(4000);
359 382
360 return 0; 383 return 0;
@@ -367,13 +390,13 @@ static int marvell_config_aneg(struct ugeth_mii_info *mii_info)
367 /* The Marvell PHY has an errata which requires 390 /* The Marvell PHY has an errata which requires
368 * that certain registers get written in order 391 * that certain registers get written in order
369 * to restart autonegotiation */ 392 * to restart autonegotiation */
370 phy_write(mii_info, MII_BMCR, BMCR_RESET); 393 ucc_geth_phy_write(mii_info, MII_BMCR, BMCR_RESET);
371 394
372 phy_write(mii_info, 0x1d, 0x1f); 395 ucc_geth_phy_write(mii_info, 0x1d, 0x1f);
373 phy_write(mii_info, 0x1e, 0x200c); 396 ucc_geth_phy_write(mii_info, 0x1e, 0x200c);
374 phy_write(mii_info, 0x1d, 0x5); 397 ucc_geth_phy_write(mii_info, 0x1d, 0x5);
375 phy_write(mii_info, 0x1e, 0); 398 ucc_geth_phy_write(mii_info, 0x1e, 0);
376 phy_write(mii_info, 0x1e, 0x100); 399 ucc_geth_phy_write(mii_info, 0x1e, 0x100);
377 400
378 gbit_config_aneg(mii_info); 401 gbit_config_aneg(mii_info);
379 402
@@ -398,7 +421,7 @@ static int marvell_read_status(struct ugeth_mii_info *mii_info)
398 * are as set */ 421 * are as set */
399 if (mii_info->autoneg && mii_info->link) { 422 if (mii_info->autoneg && mii_info->link) {
400 int speed; 423 int speed;
401 status = phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS); 424 status = ucc_geth_phy_read(mii_info, MII_M1011_PHY_SPEC_STATUS);
402 425
403 /* Get the duplexity */ 426 /* Get the duplexity */
404 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX) 427 if (status & MII_M1011_PHY_SPEC_STATUS_FULLDUPLEX)
@@ -430,7 +453,7 @@ static int marvell_ack_interrupt(struct ugeth_mii_info *mii_info)
430 ugphy_vdbg("%s: IN", __FUNCTION__); 453 ugphy_vdbg("%s: IN", __FUNCTION__);
431 454
432 /* Clear the interrupts by reading the reg */ 455 /* Clear the interrupts by reading the reg */
433 phy_read(mii_info, MII_M1011_IEVENT); 456 ucc_geth_phy_read(mii_info, MII_M1011_IEVENT);
434 457
435 return 0; 458 return 0;
436} 459}
@@ -440,9 +463,9 @@ static int marvell_config_intr(struct ugeth_mii_info *mii_info)
440 ugphy_vdbg("%s: IN", __FUNCTION__); 463 ugphy_vdbg("%s: IN", __FUNCTION__);
441 464
442 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 465 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
443 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT); 466 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_INIT);
444 else 467 else
445 phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR); 468 ucc_geth_phy_write(mii_info, MII_M1011_IMASK, MII_M1011_IMASK_CLEAR);
446 469
447 return 0; 470 return 0;
448} 471}
@@ -451,9 +474,9 @@ static int cis820x_init(struct ugeth_mii_info *mii_info)
451{ 474{
452 ugphy_vdbg("%s: IN", __FUNCTION__); 475 ugphy_vdbg("%s: IN", __FUNCTION__);
453 476
454 phy_write(mii_info, MII_CIS8201_AUX_CONSTAT, 477 ucc_geth_phy_write(mii_info, MII_CIS8201_AUX_CONSTAT,
455 MII_CIS8201_AUXCONSTAT_INIT); 478 MII_CIS8201_AUXCONSTAT_INIT);
456 phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT); 479 ucc_geth_phy_write(mii_info, MII_CIS8201_EXT_CON1, MII_CIS8201_EXTCON1_INIT);
457 480
458 return 0; 481 return 0;
459} 482}
@@ -477,7 +500,7 @@ static int cis820x_read_status(struct ugeth_mii_info *mii_info)
477 if (mii_info->autoneg && mii_info->link) { 500 if (mii_info->autoneg && mii_info->link) {
478 int speed; 501 int speed;
479 502
480 status = phy_read(mii_info, MII_CIS8201_AUX_CONSTAT); 503 status = ucc_geth_phy_read(mii_info, MII_CIS8201_AUX_CONSTAT);
481 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX) 504 if (status & MII_CIS8201_AUXCONSTAT_DUPLEX)
482 mii_info->duplex = DUPLEX_FULL; 505 mii_info->duplex = DUPLEX_FULL;
483 else 506 else
@@ -505,7 +528,7 @@ static int cis820x_ack_interrupt(struct ugeth_mii_info *mii_info)
505{ 528{
506 ugphy_vdbg("%s: IN", __FUNCTION__); 529 ugphy_vdbg("%s: IN", __FUNCTION__);
507 530
508 phy_read(mii_info, MII_CIS8201_ISTAT); 531 ucc_geth_phy_read(mii_info, MII_CIS8201_ISTAT);
509 532
510 return 0; 533 return 0;
511} 534}
@@ -515,9 +538,9 @@ static int cis820x_config_intr(struct ugeth_mii_info *mii_info)
515 ugphy_vdbg("%s: IN", __FUNCTION__); 538 ugphy_vdbg("%s: IN", __FUNCTION__);
516 539
517 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 540 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
518 phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK); 541 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, MII_CIS8201_IMASK_MASK);
519 else 542 else
520 phy_write(mii_info, MII_CIS8201_IMASK, 0); 543 ucc_geth_phy_write(mii_info, MII_CIS8201_IMASK, 0);
521 544
522 return 0; 545 return 0;
523} 546}
@@ -541,7 +564,7 @@ static int dm9161_read_status(struct ugeth_mii_info *mii_info)
541 /* If we aren't autonegotiating, assume speeds 564 /* If we aren't autonegotiating, assume speeds
542 * are as set */ 565 * are as set */
543 if (mii_info->autoneg && mii_info->link) { 566 if (mii_info->autoneg && mii_info->link) {
544 status = phy_read(mii_info, MII_DM9161_SCSR); 567 status = ucc_geth_phy_read(mii_info, MII_DM9161_SCSR);
545 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H)) 568 if (status & (MII_DM9161_SCSR_100F | MII_DM9161_SCSR_100H))
546 mii_info->speed = SPEED_100; 569 mii_info->speed = SPEED_100;
547 else 570 else
@@ -572,7 +595,7 @@ static void dm9161_timer(unsigned long data)
572{ 595{
573 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data; 596 struct ugeth_mii_info *mii_info = (struct ugeth_mii_info *)data;
574 struct dm9161_private *priv = mii_info->priv; 597 struct dm9161_private *priv = mii_info->priv;
575 u16 status = phy_read(mii_info, MII_BMSR); 598 u16 status = ucc_geth_phy_read(mii_info, MII_BMSR);
576 599
577 ugphy_vdbg("%s: IN", __FUNCTION__); 600 ugphy_vdbg("%s: IN", __FUNCTION__);
578 601
@@ -599,11 +622,11 @@ static int dm9161_init(struct ugeth_mii_info *mii_info)
599 /* Reset is not done yet */ 622 /* Reset is not done yet */
600 priv->resetdone = 0; 623 priv->resetdone = 0;
601 624
602 phy_write(mii_info, MII_BMCR, 625 ucc_geth_phy_write(mii_info, MII_BMCR,
603 phy_read(mii_info, MII_BMCR) | BMCR_RESET); 626 ucc_geth_phy_read(mii_info, MII_BMCR) | BMCR_RESET);
604 627
605 phy_write(mii_info, MII_BMCR, 628 ucc_geth_phy_write(mii_info, MII_BMCR,
606 phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE); 629 ucc_geth_phy_read(mii_info, MII_BMCR) & ~BMCR_ISOLATE);
607 630
608 config_genmii_advert(mii_info); 631 config_genmii_advert(mii_info);
609 /* Start/Restart aneg */ 632 /* Start/Restart aneg */
@@ -634,7 +657,7 @@ static int dm9161_ack_interrupt(struct ugeth_mii_info *mii_info)
634 ugphy_vdbg("%s: IN", __FUNCTION__); 657 ugphy_vdbg("%s: IN", __FUNCTION__);
635 658
636 /* Clear the interrupts by reading the reg */ 659 /* Clear the interrupts by reading the reg */
637 phy_read(mii_info, MII_DM9161_INTR); 660 ucc_geth_phy_read(mii_info, MII_DM9161_INTR);
638 661
639 662
640 return 0; 663 return 0;
@@ -645,9 +668,9 @@ static int dm9161_config_intr(struct ugeth_mii_info *mii_info)
645 ugphy_vdbg("%s: IN", __FUNCTION__); 668 ugphy_vdbg("%s: IN", __FUNCTION__);
646 669
647 if (mii_info->interrupts == MII_INTERRUPT_ENABLED) 670 if (mii_info->interrupts == MII_INTERRUPT_ENABLED)
648 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT); 671 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_INIT);
649 else 672 else
650 phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP); 673 ucc_geth_phy_write(mii_info, MII_DM9161_INTR, MII_DM9161_INTR_STOP);
651 674
652 return 0; 675 return 0;
653} 676}
@@ -718,31 +741,6 @@ static struct phy_info *phy_info[] = {
718 NULL 741 NULL
719}; 742};
720 743
721u16 phy_read(struct ugeth_mii_info *mii_info, u16 regnum)
722{
723 u16 retval;
724 unsigned long flags;
725
726 ugphy_vdbg("%s: IN", __FUNCTION__);
727
728 spin_lock_irqsave(&mii_info->mdio_lock, flags);
729 retval = mii_info->mdio_read(mii_info->dev, mii_info->mii_id, regnum);
730 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
731
732 return retval;
733}
734
735void phy_write(struct ugeth_mii_info *mii_info, u16 regnum, u16 val)
736{
737 unsigned long flags;
738
739 ugphy_vdbg("%s: IN", __FUNCTION__);
740
741 spin_lock_irqsave(&mii_info->mdio_lock, flags);
742 mii_info->mdio_write(mii_info->dev, mii_info->mii_id, regnum, val);
743 spin_unlock_irqrestore(&mii_info->mdio_lock, flags);
744}
745
746/* Use the PHY ID registers to determine what type of PHY is attached 744/* Use the PHY ID registers to determine what type of PHY is attached
747 * to device dev. return a struct phy_info structure describing that PHY 745 * to device dev. return a struct phy_info structure describing that PHY
748 */ 746 */
@@ -757,11 +755,11 @@ struct phy_info *get_phy_info(struct ugeth_mii_info *mii_info)
757 ugphy_vdbg("%s: IN", __FUNCTION__); 755 ugphy_vdbg("%s: IN", __FUNCTION__);
758 756
759 /* Grab the bits from PHYIR1, and put them in the upper half */ 757 /* Grab the bits from PHYIR1, and put them in the upper half */
760 phy_reg = phy_read(mii_info, MII_PHYSID1); 758 phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID1);
761 phy_ID = (phy_reg & 0xffff) << 16; 759 phy_ID = (phy_reg & 0xffff) << 16;
762 760
763 /* Grab the bits from PHYIR2, and put them in the lower half */ 761 /* Grab the bits from PHYIR2, and put them in the lower half */
764 phy_reg = phy_read(mii_info, MII_PHYSID2); 762 phy_reg = ucc_geth_phy_read(mii_info, MII_PHYSID2);
765 phy_ID |= (phy_reg & 0xffff); 763 phy_ID |= (phy_reg & 0xffff);
766 764
767 /* loop through all the known PHY types, and find one that */ 765 /* loop through all the known PHY types, and find one that */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 2ec2e5afce67..91b752e3d07e 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -2701,8 +2701,8 @@ static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2701 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI); 2701 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2702 2702
2703 /* extract core_id, core_rev, core_vendor */ 2703 /* extract core_id, core_rev, core_vendor */
2704 core_id = (sb_id_hi & 0xFFF0) >> 4; 2704 core_id = (sb_id_hi & 0x8FF0) >> 4;
2705 core_rev = (sb_id_hi & 0xF); 2705 core_rev = ((sb_id_hi & 0xF) | ((sb_id_hi & 0x7000) >> 8));
2706 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16; 2706 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2707 2707
2708 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x\n", 2708 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x\n",
@@ -2873,7 +2873,10 @@ static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm,
2873 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW); 2873 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
2874 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK; 2874 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
2875 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK; 2875 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
2876 sbimconfiglow |= 0x32; 2876 if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
2877 sbimconfiglow |= 0x32;
2878 else
2879 sbimconfiglow |= 0x53;
2877 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow); 2880 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
2878 } 2881 }
2879 2882
@@ -3077,7 +3080,7 @@ static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
3077 if (err) 3080 if (err)
3078 goto out; 3081 goto out;
3079 3082
3080 if (bcm->current_core->rev < 6 || 3083 if (bcm->current_core->rev < 6 &&
3081 bcm->current_core->id == BCM43xx_COREID_PCI) { 3084 bcm->current_core->id == BCM43xx_COREID_PCI) {
3082 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC); 3085 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
3083 value |= (1 << backplane_flag_nr); 3086 value |= (1 << backplane_flag_nr);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index b8d2385e29bc..92d5e8db0de7 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -150,8 +150,7 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
150} 150}
151 151
152/** 152/**
153 * pci_match_device - Tell if a PCI device structure has a matching 153 * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure
154 * PCI device id structure
155 * @drv: the PCI driver to match against 154 * @drv: the PCI driver to match against
156 * @dev: the PCI device structure to match against 155 * @dev: the PCI device structure to match against
157 * 156 *
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 0a70943f8bb6..16945c2ba2ca 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -654,19 +654,40 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vi
654 * VIA bridges which have VLink 654 * VIA bridges which have VLink
655 */ 655 */
656 656
657static const struct pci_device_id via_vlink_fixup_tbl[] = { 657static int via_vlink_dev_lo = -1, via_vlink_dev_hi = 18;
658 /* Internal devices need IRQ line routing, pre VLink */ 658
659 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686), 0 }, 659static void quirk_via_bridge(struct pci_dev *dev)
660 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8231), 17 }, 660{
661 /* Devices with VLink */ 661 /* See what bridge we have and find the device ranges */
662 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_0), 17}, 662 switch (dev->device) {
663 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233A), 17 }, 663 case PCI_DEVICE_ID_VIA_82C686:
664 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233C_0), 17 }, 664 /* 82C686 is special */
665 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8235), 16 }, 665 via_vlink_dev_lo = 7;
666 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237), 15 }, 666 via_vlink_dev_hi = 7;
667 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237A), 15 }, 667 break;
668 { 0, }, 668 case PCI_DEVICE_ID_VIA_8237:
669}; 669 case PCI_DEVICE_ID_VIA_8237A:
670 via_vlink_dev_lo = 15;
671 break;
672 case PCI_DEVICE_ID_VIA_8235:
673 via_vlink_dev_lo = 16;
674 break;
675 case PCI_DEVICE_ID_VIA_8231:
676 case PCI_DEVICE_ID_VIA_8233_0:
677 case PCI_DEVICE_ID_VIA_8233A:
678 case PCI_DEVICE_ID_VIA_8233C_0:
679 via_vlink_dev_lo = 17;
680 break;
681 }
682}
683DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_bridge);
684DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, quirk_via_bridge);
685DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_0, quirk_via_bridge);
686DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233A, quirk_via_bridge);
687DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233C_0, quirk_via_bridge);
688DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_bridge);
689DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_bridge);
690DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A, quirk_via_bridge);
670 691
671/** 692/**
672 * quirk_via_vlink - VIA VLink IRQ number update 693 * quirk_via_vlink - VIA VLink IRQ number update
@@ -675,35 +696,20 @@ static const struct pci_device_id via_vlink_fixup_tbl[] = {
675 * If the device we are dealing with is on a PIC IRQ we need to 696 * If the device we are dealing with is on a PIC IRQ we need to
676 * ensure that the IRQ line register which usually is not relevant 697 * ensure that the IRQ line register which usually is not relevant
677 * for PCI cards, is actually written so that interrupts get sent 698 * for PCI cards, is actually written so that interrupts get sent
678 * to the right place 699 * to the right place.
700 * We only do this on systems where a VIA south bridge was detected,
701 * and only for VIA devices on the motherboard (see quirk_via_bridge
702 * above).
679 */ 703 */
680 704
681static void quirk_via_vlink(struct pci_dev *dev) 705static void quirk_via_vlink(struct pci_dev *dev)
682{ 706{
683 const struct pci_device_id *via_vlink_fixup;
684 static int dev_lo = -1, dev_hi = 18;
685 u8 irq, new_irq; 707 u8 irq, new_irq;
686 708
687 /* Check if we have VLink and cache the result */ 709 /* Check if we have VLink at all */
688 710 if (via_vlink_dev_lo == -1)
689 /* Checked already - no */
690 if (dev_lo == -2)
691 return; 711 return;
692 712
693 /* Not checked - see what bridge we have and find the device
694 ranges */
695
696 if (dev_lo == -1) {
697 via_vlink_fixup = pci_find_present(via_vlink_fixup_tbl);
698 if (via_vlink_fixup == NULL) {
699 dev_lo = -2;
700 return;
701 }
702 dev_lo = via_vlink_fixup->driver_data;
703 /* 82C686 is special - 0/0 */
704 if (dev_lo == 0)
705 dev_hi = 0;
706 }
707 new_irq = dev->irq; 713 new_irq = dev->irq;
708 714
709 /* Don't quirk interrupts outside the legacy IRQ range */ 715 /* Don't quirk interrupts outside the legacy IRQ range */
@@ -711,8 +717,8 @@ static void quirk_via_vlink(struct pci_dev *dev)
711 return; 717 return;
712 718
713 /* Internal device ? */ 719 /* Internal device ? */
714 if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > dev_hi || 720 if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > via_vlink_dev_hi ||
715 PCI_SLOT(dev->devfn) < dev_lo) 721 PCI_SLOT(dev->devfn) < via_vlink_dev_lo)
716 return; 722 return;
717 723
718 /* This is an internal VLink device on a PIC interrupt. The BIOS 724 /* This is an internal VLink device on a PIC interrupt. The BIOS
@@ -1002,6 +1008,11 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
1002 case 0x186a: /* M6Ne notebook */ 1008 case 0x186a: /* M6Ne notebook */
1003 asus_hides_smbus = 1; 1009 asus_hides_smbus = 1;
1004 } 1010 }
1011 if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
1012 switch (dev->subsystem_device) {
1013 case 0x80f2: /* P4P800-X */
1014 asus_hides_smbus = 1;
1015 }
1005 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) { 1016 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) {
1006 switch (dev->subsystem_device) { 1017 switch (dev->subsystem_device) {
1007 case 0x1882: /* M6V notebook */ 1018 case 0x1882: /* M6V notebook */
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index e9e0934380b8..198b9f22fbff 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -492,10 +492,10 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
492 492
493 spin_lock_irq(&rtc->lock); 493 spin_lock_irq(&rtc->lock);
494 494
495 /* disable alarm interrupt and clear flag */ 495 /* disable alarm interrupt and clear the alarm flag */
496 rcr1 = readb(rtc->regbase + RCR1); 496 rcr1 = readb(rtc->regbase + RCR1);
497 rcr1 &= ~RCR1_AF; 497 rcr1 &= ~(RCR1_AF|RCR1_AIE);
498 writeb(rcr1 & ~RCR1_AIE, rtc->regbase + RCR1); 498 writeb(rcr1, rtc->regbase + RCR1);
499 499
500 rtc->rearm_aie = 0; 500 rtc->rearm_aie = 0;
501 501
@@ -510,8 +510,10 @@ static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
510 mon += 1; 510 mon += 1;
511 sh_rtc_write_alarm_value(rtc, mon, RMONAR); 511 sh_rtc_write_alarm_value(rtc, mon, RMONAR);
512 512
513 /* Restore interrupt activation status */ 513 if (wkalrm->enabled) {
514 writeb(rcr1, rtc->regbase + RCR1); 514 rcr1 |= RCR1_AIE;
515 writeb(rcr1, rtc->regbase + RCR1);
516 }
515 517
516 spin_unlock_irq(&rtc->lock); 518 spin_unlock_irq(&rtc->lock);
517 519
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 9418a59fb368..2ddd0cf07140 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -78,7 +78,7 @@ static struct attribute_group rtc_attr_group = {
78 .attrs = rtc_attrs, 78 .attrs = rtc_attrs,
79}; 79};
80 80
81static int __devinit rtc_sysfs_add_device(struct class_device *class_dev, 81static int rtc_sysfs_add_device(struct class_device *class_dev,
82 struct class_interface *class_intf) 82 struct class_interface *class_intf)
83{ 83{
84 int err; 84 int err;
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 99a259c5a0c0..e1b44d6c0c32 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -6,7 +6,7 @@
6 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 Brad Strand <linux@3ware.com> 7 Brad Strand <linux@3ware.com>
8 8
9 Copyright (C) 1999-2005 3ware Inc. 9 Copyright (C) 1999-2007 3ware Inc.
10 10
11 Kernel compatiblity By: Andre Hedrick <andre@suse.com> 11 Kernel compatiblity By: Andre Hedrick <andre@suse.com>
12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> 12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
@@ -191,6 +191,9 @@
191 before shutting down card. 191 before shutting down card.
192 Change to new 'change_queue_depth' api. 192 Change to new 'change_queue_depth' api.
193 Fix 'handled=1' ISR usage, remove bogus IRQ check. 193 Fix 'handled=1' ISR usage, remove bogus IRQ check.
194 1.26.02.002 - Free irq handler in __tw_shutdown().
195 Turn on RCD bit for caching mode page.
196 Serialize reset code.
194*/ 197*/
195 198
196#include <linux/module.h> 199#include <linux/module.h>
@@ -214,7 +217,7 @@
214#include "3w-xxxx.h" 217#include "3w-xxxx.h"
215 218
216/* Globals */ 219/* Globals */
217#define TW_DRIVER_VERSION "1.26.02.001" 220#define TW_DRIVER_VERSION "1.26.02.002"
218static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT]; 221static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT];
219static int tw_device_extension_count = 0; 222static int tw_device_extension_count = 0;
220static int twe_major = -1; 223static int twe_major = -1;
@@ -226,7 +229,7 @@ MODULE_LICENSE("GPL");
226MODULE_VERSION(TW_DRIVER_VERSION); 229MODULE_VERSION(TW_DRIVER_VERSION);
227 230
228/* Function prototypes */ 231/* Function prototypes */
229static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset); 232static int tw_reset_device_extension(TW_Device_Extension *tw_dev);
230 233
231/* Functions */ 234/* Functions */
232 235
@@ -984,24 +987,12 @@ static int tw_chrdev_ioctl(struct inode *inode, struct file *file, unsigned int
984 /* Now wait for the command to complete */ 987 /* Now wait for the command to complete */
985 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout); 988 timeout = wait_event_timeout(tw_dev->ioctl_wqueue, tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE, timeout);
986 989
987 /* See if we reset while waiting for the ioctl to complete */
988 if (test_bit(TW_IN_RESET, &tw_dev->flags)) {
989 clear_bit(TW_IN_RESET, &tw_dev->flags);
990 retval = -ERESTARTSYS;
991 goto out2;
992 }
993
994 /* We timed out, and didn't get an interrupt */ 990 /* We timed out, and didn't get an interrupt */
995 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) { 991 if (tw_dev->chrdev_request_id != TW_IOCTL_CHRDEV_FREE) {
996 /* Now we need to reset the board */ 992 /* Now we need to reset the board */
997 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd); 993 printk(KERN_WARNING "3w-xxxx: scsi%d: Character ioctl (0x%x) timed out, resetting card.\n", tw_dev->host->host_no, cmd);
998 retval = -EIO; 994 retval = -EIO;
999 spin_lock_irqsave(tw_dev->host->host_lock, flags); 995 if (tw_reset_device_extension(tw_dev)) {
1000 tw_dev->state[request_id] = TW_S_COMPLETED;
1001 tw_state_request_finish(tw_dev, request_id);
1002 tw_dev->posted_request_count--;
1003 spin_unlock_irqrestore(tw_dev->host->host_lock, flags);
1004 if (tw_reset_device_extension(tw_dev, 1)) {
1005 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no); 996 printk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl(): Reset failed for card %d.\n", tw_dev->host->host_no);
1006 } 997 }
1007 goto out2; 998 goto out2;
@@ -1336,7 +1327,7 @@ static void tw_unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
1336} /* End tw_unmap_scsi_data() */ 1327} /* End tw_unmap_scsi_data() */
1337 1328
1338/* This function will reset a device extension */ 1329/* This function will reset a device extension */
1339static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_reset) 1330static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
1340{ 1331{
1341 int i = 0; 1332 int i = 0;
1342 struct scsi_cmnd *srb; 1333 struct scsi_cmnd *srb;
@@ -1382,15 +1373,10 @@ static int tw_reset_device_extension(TW_Device_Extension *tw_dev, int ioctl_rese
1382 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no); 1373 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset sequence failed.\n", tw_dev->host->host_no);
1383 return 1; 1374 return 1;
1384 } 1375 }
1385 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1386 1376
1387 /* Wake up any ioctl that was pending before the reset */ 1377 TW_ENABLE_AND_CLEAR_INTERRUPTS(tw_dev);
1388 if ((tw_dev->chrdev_request_id == TW_IOCTL_CHRDEV_FREE) || (ioctl_reset)) { 1378 clear_bit(TW_IN_RESET, &tw_dev->flags);
1389 clear_bit(TW_IN_RESET, &tw_dev->flags); 1379 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1390 } else {
1391 tw_dev->chrdev_request_id = TW_IOCTL_CHRDEV_FREE;
1392 wake_up(&tw_dev->ioctl_wqueue);
1393 }
1394 1380
1395 return 0; 1381 return 0;
1396} /* End tw_reset_device_extension() */ 1382} /* End tw_reset_device_extension() */
@@ -1437,14 +1423,18 @@ static int tw_scsi_eh_reset(struct scsi_cmnd *SCpnt)
1437 "WARNING: Command (0x%x) timed out, resetting card.\n", 1423 "WARNING: Command (0x%x) timed out, resetting card.\n",
1438 SCpnt->cmnd[0]); 1424 SCpnt->cmnd[0]);
1439 1425
1426 /* Make sure we are not issuing an ioctl or resetting from ioctl */
1427 mutex_lock(&tw_dev->ioctl_lock);
1428
1440 /* Now reset the card and some of the device extension data */ 1429 /* Now reset the card and some of the device extension data */
1441 if (tw_reset_device_extension(tw_dev, 0)) { 1430 if (tw_reset_device_extension(tw_dev)) {
1442 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no); 1431 printk(KERN_WARNING "3w-xxxx: scsi%d: Reset failed.\n", tw_dev->host->host_no);
1443 goto out; 1432 goto out;
1444 } 1433 }
1445 1434
1446 retval = SUCCESS; 1435 retval = SUCCESS;
1447out: 1436out:
1437 mutex_unlock(&tw_dev->ioctl_lock);
1448 return retval; 1438 return retval;
1449} /* End tw_scsi_eh_reset() */ 1439} /* End tw_scsi_eh_reset() */
1450 1440
@@ -1660,9 +1650,9 @@ static int tw_scsiop_mode_sense_complete(TW_Device_Extension *tw_dev, int reques
1660 request_buffer[4] = 0x8; /* caching page */ 1650 request_buffer[4] = 0x8; /* caching page */
1661 request_buffer[5] = 0xa; /* page length */ 1651 request_buffer[5] = 0xa; /* page length */
1662 if (*flags & 0x1) 1652 if (*flags & 0x1)
1663 request_buffer[6] = 0x4; /* WCE on */ 1653 request_buffer[6] = 0x5; /* WCE on, RCD on */
1664 else 1654 else
1665 request_buffer[6] = 0x0; /* WCE off */ 1655 request_buffer[6] = 0x1; /* WCE off, RCD on */
1666 tw_transfer_internal(tw_dev, request_id, request_buffer, 1656 tw_transfer_internal(tw_dev, request_id, request_buffer,
1667 sizeof(request_buffer)); 1657 sizeof(request_buffer));
1668 1658
@@ -2012,6 +2002,10 @@ static int tw_scsi_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd
2012 int retval = 1; 2002 int retval = 1;
2013 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata; 2003 TW_Device_Extension *tw_dev = (TW_Device_Extension *)SCpnt->device->host->hostdata;
2014 2004
2005 /* If we are resetting due to timed out ioctl, report as busy */
2006 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2007 return SCSI_MLQUEUE_HOST_BUSY;
2008
2015 /* Save done function into Scsi_Cmnd struct */ 2009 /* Save done function into Scsi_Cmnd struct */
2016 SCpnt->scsi_done = done; 2010 SCpnt->scsi_done = done;
2017 2011
@@ -2100,6 +2094,10 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance)
2100 2094
2101 handled = 1; 2095 handled = 1;
2102 2096
2097 /* If we are resetting, bail */
2098 if (test_bit(TW_IN_RESET, &tw_dev->flags))
2099 goto tw_interrupt_bail;
2100
2103 /* Check controller for errors */ 2101 /* Check controller for errors */
2104 if (tw_check_bits(status_reg_value)) { 2102 if (tw_check_bits(status_reg_value)) {
2105 dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Unexpected bits.\n"); 2103 dprintk(KERN_WARNING "3w-xxxx: tw_interrupt(): Unexpected bits.\n");
@@ -2276,6 +2274,9 @@ static void __tw_shutdown(TW_Device_Extension *tw_dev)
2276 /* Disable interrupts */ 2274 /* Disable interrupts */
2277 TW_DISABLE_INTERRUPTS(tw_dev); 2275 TW_DISABLE_INTERRUPTS(tw_dev);
2278 2276
2277 /* Free up the IRQ */
2278 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2279
2279 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no); 2280 printk(KERN_WARNING "3w-xxxx: Shutting down host %d.\n", tw_dev->host->host_no);
2280 2281
2281 /* Tell the card we are shutting down */ 2282 /* Tell the card we are shutting down */
@@ -2444,9 +2445,6 @@ static void tw_remove(struct pci_dev *pdev)
2444 twe_major = -1; 2445 twe_major = -1;
2445 } 2446 }
2446 2447
2447 /* Free up the IRQ */
2448 free_irq(tw_dev->tw_pci_dev->irq, tw_dev);
2449
2450 /* Shutdown the card */ 2448 /* Shutdown the card */
2451 __tw_shutdown(tw_dev); 2449 __tw_shutdown(tw_dev);
2452 2450
diff --git a/drivers/scsi/3w-xxxx.h b/drivers/scsi/3w-xxxx.h
index bbd654a2b9b1..0742e6846656 100644
--- a/drivers/scsi/3w-xxxx.h
+++ b/drivers/scsi/3w-xxxx.h
@@ -6,7 +6,7 @@
6 Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 Brad Strand <linux@3ware.com> 7 Brad Strand <linux@3ware.com>
8 8
9 Copyright (C) 1999-2005 3ware Inc. 9 Copyright (C) 1999-2007 3ware Inc.
10 10
11 Kernel compatiblity By: Andre Hedrick <andre@suse.com> 11 Kernel compatiblity By: Andre Hedrick <andre@suse.com>
12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com> 12 Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 0133f3a6977d..5bf3f07870ba 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1312,7 +1312,7 @@ config SCSI_LPFC
1312 1312
1313config SCSI_SEAGATE 1313config SCSI_SEAGATE
1314 tristate "Seagate ST-02 and Future Domain TMC-8xx SCSI support" 1314 tristate "Seagate ST-02 and Future Domain TMC-8xx SCSI support"
1315 depends on X86 && ISA && SCSI && BROKEN 1315 depends on X86 && ISA && SCSI
1316 ---help--- 1316 ---help---
1317 These are 8-bit SCSI controllers; the ST-01 is also supported by 1317 These are 8-bit SCSI controllers; the ST-01 is also supported by
1318 this driver. It is explained in section 3.9 of the SCSI-HOWTO, 1318 this driver. It is explained in section 3.9 of the SCSI-HOWTO,
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 1feda449aedc..a9734e08fe28 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -117,8 +117,8 @@ static struct pci_device_id aac_pci_tbl[] = {
117 { 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */ 117 { 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */
118 { 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */ 118 { 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */
119 { 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */ 119 { 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */
120 { 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024R0 (Lancer) */ 120 { 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024RO (Lancer) */
121 { 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014R0 (Lancer) */ 121 { 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014RO (Lancer) */
122 { 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */ 122 { 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */
123 { 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */ 123 { 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */
124 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5445AU (Hurricane44) */ 124 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5445AU (Hurricane44) */
@@ -137,15 +137,15 @@ static struct pci_device_id aac_pci_tbl[] = {
137 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */ 137 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
138 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */ 138 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */
139 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */ 139 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */
140 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005SAS */ 140 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005 */
141 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */ 141 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */
142 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */ 142 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */
143 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */ 143 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */
144 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */ 144 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */
145 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000SAS (BlackBird) */ 145 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000 (BlackBird) */
146 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */ 146 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */
147 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */ 147 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */
148 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-3800SAS (Hurricane44) */ 148 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-3800 (Hurricane44) */
149 149
150 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/ 150 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/
151 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/ 151 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/
@@ -194,8 +194,8 @@ static struct aac_driver_ident aac_drivers[] = {
194 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2820SA ", 1 }, /* AAR-2820SA (Intruder) */ 194 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2820SA ", 1 }, /* AAR-2820SA (Intruder) */
195 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2620SA ", 1 }, /* AAR-2620SA (Intruder) */ 195 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2620SA ", 1 }, /* AAR-2620SA (Intruder) */
196 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2420SA ", 1 }, /* AAR-2420SA (Intruder) */ 196 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2420SA ", 1 }, /* AAR-2420SA (Intruder) */
197 { aac_rkt_init, "aacraid", "ICP ", "ICP9024R0 ", 2 }, /* ICP9024R0 (Lancer) */ 197 { aac_rkt_init, "aacraid", "ICP ", "ICP9024RO ", 2 }, /* ICP9024RO (Lancer) */
198 { aac_rkt_init, "aacraid", "ICP ", "ICP9014R0 ", 1 }, /* ICP9014R0 (Lancer) */ 198 { aac_rkt_init, "aacraid", "ICP ", "ICP9014RO ", 1 }, /* ICP9014RO (Lancer) */
199 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */ 199 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */
200 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */ 200 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */
201 { aac_rkt_init, "aacraid", "ICP ", "ICP5445AU ", 1 }, /* ICP5445AU (Hurricane44) */ 201 { aac_rkt_init, "aacraid", "ICP ", "ICP5445AU ", 1 }, /* ICP5445AU (Hurricane44) */
@@ -213,14 +213,14 @@ static struct aac_driver_ident aac_drivers[] = {
213 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2026ZCR ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */ 213 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2026ZCR ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
214 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2610SA ", 1 }, /* SATA 6Ch (Bearcat) */ 214 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2610SA ", 1 }, /* SATA 6Ch (Bearcat) */
215 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */ 215 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */
216 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005SAS ", 1 }, /* ASR-4005SAS */ 216 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005 ", 1 }, /* ASR-4005 */
217 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */ 217 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */
218 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */ 218 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */
219 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */ 219 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */
220 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000SAS ", 1 }, /* ASR-4000SAS (BlackBird & AvonPark) */ 220 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000 ", 1 }, /* ASR-4000 (BlackBird & AvonPark) */
221 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */ 221 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */
222 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */ 222 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */
223 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-3800SAS ", 1 }, /* ASR-3800SAS (Hurricane44) */ 223 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-3800 ", 1 }, /* ASR-3800 (Hurricane44) */
224 224
225 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/ 225 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
226 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/ 226 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 2b344356a29e..306bec355e45 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -18215,6 +18215,7 @@ AdvInquiryHandling(
18215} 18215}
18216MODULE_LICENSE("Dual BSD/GPL"); 18216MODULE_LICENSE("Dual BSD/GPL");
18217 18217
18218#ifdef CONFIG_PCI
18218/* PCI Devices supported by this driver */ 18219/* PCI Devices supported by this driver */
18219static struct pci_device_id advansys_pci_tbl[] __devinitdata = { 18220static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
18220 { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A, 18221 { PCI_VENDOR_ID_ASP, PCI_DEVICE_ID_ASP_1200A,
@@ -18232,4 +18233,4 @@ static struct pci_device_id advansys_pci_tbl[] __devinitdata = {
18232 { } 18233 { }
18233}; 18234};
18234MODULE_DEVICE_TABLE(pci, advansys_pci_tbl); 18235MODULE_DEVICE_TABLE(pci, advansys_pci_tbl);
18235 18236#endif /* CONFIG_PCI */
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index d0b139cccbbc..437684084377 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -749,7 +749,7 @@ static int iscsi_scsi_data_in(struct iscsi_conn *conn)
749 if (!offset) 749 if (!offset)
750 crypto_hash_update( 750 crypto_hash_update(
751 &tcp_conn->rx_hash, 751 &tcp_conn->rx_hash,
752 &sg[i], 1); 752 &sg[i], sg[i].length);
753 else 753 else
754 partial_sg_digest_update( 754 partial_sg_digest_update(
755 &tcp_conn->rx_hash, 755 &tcp_conn->rx_hash,
@@ -1777,13 +1777,13 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1777 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1777 tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1778 CRYPTO_ALG_ASYNC); 1778 CRYPTO_ALG_ASYNC);
1779 tcp_conn->tx_hash.flags = 0; 1779 tcp_conn->tx_hash.flags = 0;
1780 if (!tcp_conn->tx_hash.tfm) 1780 if (IS_ERR(tcp_conn->tx_hash.tfm))
1781 goto free_tcp_conn; 1781 goto free_tcp_conn;
1782 1782
1783 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0, 1783 tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0,
1784 CRYPTO_ALG_ASYNC); 1784 CRYPTO_ALG_ASYNC);
1785 tcp_conn->rx_hash.flags = 0; 1785 tcp_conn->rx_hash.flags = 0;
1786 if (!tcp_conn->rx_hash.tfm) 1786 if (IS_ERR(tcp_conn->rx_hash.tfm))
1787 goto free_tx_tfm; 1787 goto free_tx_tfm;
1788 1788
1789 return cls_conn; 1789 return cls_conn;
@@ -2044,13 +2044,11 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
2044 sk = tcp_conn->sock->sk; 2044 sk = tcp_conn->sock->sk;
2045 if (sk->sk_family == PF_INET) { 2045 if (sk->sk_family == PF_INET) {
2046 inet = inet_sk(sk); 2046 inet = inet_sk(sk);
2047 len = sprintf(buf, "%u.%u.%u.%u\n", 2047 len = sprintf(buf, NIPQUAD_FMT "\n",
2048 NIPQUAD(inet->daddr)); 2048 NIPQUAD(inet->daddr));
2049 } else { 2049 } else {
2050 np = inet6_sk(sk); 2050 np = inet6_sk(sk);
2051 len = sprintf(buf, 2051 len = sprintf(buf, NIP6_FMT "\n", NIP6(np->daddr));
2052 "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
2053 NIP6(np->daddr));
2054 } 2052 }
2055 mutex_unlock(&conn->xmitmutex); 2053 mutex_unlock(&conn->xmitmutex);
2056 break; 2054 break;
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index e11b23c641e2..d37048c96eab 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -260,7 +260,7 @@ static int iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
260 } 260 }
261 261
262 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) { 262 if (rhdr->cmd_status == SAM_STAT_CHECK_CONDITION) {
263 int senselen; 263 uint16_t senselen;
264 264
265 if (datalen < 2) { 265 if (datalen < 2) {
266invalid_datalen: 266invalid_datalen:
@@ -270,12 +270,12 @@ invalid_datalen:
270 goto out; 270 goto out;
271 } 271 }
272 272
273 senselen = (data[0] << 8) | data[1]; 273 senselen = be16_to_cpu(*(uint16_t *)data);
274 if (datalen < senselen) 274 if (datalen < senselen)
275 goto invalid_datalen; 275 goto invalid_datalen;
276 276
277 memcpy(sc->sense_buffer, data + 2, 277 memcpy(sc->sense_buffer, data + 2,
278 min(senselen, SCSI_SENSE_BUFFERSIZE)); 278 min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
279 debug_scsi("copied %d bytes of sense\n", 279 debug_scsi("copied %d bytes of sense\n",
280 min(senselen, SCSI_SENSE_BUFFERSIZE)); 280 min(senselen, SCSI_SENSE_BUFFERSIZE));
281 } 281 }
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c
index 066292d3995a..ec3bbbde6f7a 100644
--- a/drivers/scsi/lpfc/lpfc_mem.c
+++ b/drivers/scsi/lpfc/lpfc_mem.c
@@ -56,6 +56,9 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
56 56
57 pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) * 57 pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
58 LPFC_MBUF_POOL_SIZE, GFP_KERNEL); 58 LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
59 if (!pool->elements)
60 goto fail_free_lpfc_mbuf_pool;
61
59 pool->max_count = 0; 62 pool->max_count = 0;
60 pool->current_count = 0; 63 pool->current_count = 0;
61 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) { 64 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
@@ -82,10 +85,11 @@ lpfc_mem_alloc(struct lpfc_hba * phba)
82 fail_free_mbox_pool: 85 fail_free_mbox_pool:
83 mempool_destroy(phba->mbox_mem_pool); 86 mempool_destroy(phba->mbox_mem_pool);
84 fail_free_mbuf_pool: 87 fail_free_mbuf_pool:
85 while (--i) 88 while (i--)
86 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt, 89 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
87 pool->elements[i].phys); 90 pool->elements[i].phys);
88 kfree(pool->elements); 91 kfree(pool->elements);
92 fail_free_lpfc_mbuf_pool:
89 pci_pool_destroy(phba->lpfc_mbuf_pool); 93 pci_pool_destroy(phba->lpfc_mbuf_pool);
90 fail_free_dma_buf_pool: 94 fail_free_dma_buf_pool:
91 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool); 95 pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool);
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 046223b4ae57..b5bdd0d7a8bf 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -13,8 +13,8 @@
13 * Version : v00.00.03.05 13 * Version : v00.00.03.05
14 * 14 *
15 * Authors: 15 * Authors:
16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> 16 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
17 * Sumant Patro <Sumant.Patro@lsil.com> 17 * Sumant Patro <Sumant.Patro@lsi.com>
18 * 18 *
19 * List of supported controllers 19 * List of supported controllers
20 * 20 *
@@ -45,7 +45,7 @@
45 45
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_VERSION(MEGASAS_VERSION); 47MODULE_VERSION(MEGASAS_VERSION);
48MODULE_AUTHOR("sreenivas.bagalkote@lsil.com"); 48MODULE_AUTHOR("megaraidlinux@lsi.com");
49MODULE_DESCRIPTION("LSI Logic MegaRAID SAS Driver"); 49MODULE_DESCRIPTION("LSI Logic MegaRAID SAS Driver");
50 50
51/* 51/*
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 9fb0ea5c1fb9..5b458d2478f7 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -545,8 +545,6 @@ SYM53C500_release(struct pcmcia_device *link)
545 */ 545 */
546 if (shost->irq) 546 if (shost->irq)
547 free_irq(shost->irq, shost); 547 free_irq(shost->irq, shost);
548 if (shost->dma_channel != 0xff)
549 free_dma(shost->dma_channel);
550 if (shost->io_port && shost->n_io_port) 548 if (shost->io_port && shost->n_io_port)
551 release_region(shost->io_port, shost->n_io_port); 549 release_region(shost->io_port, shost->n_io_port);
552 550
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 16af5b79e587..1548d42a3b43 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1341,7 +1341,7 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1341 int host_status = DID_ERROR; 1341 int host_status = DID_ERROR;
1342 uint16_t comp_status = le16_to_cpu(sts->comp_status); 1342 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1343 uint16_t state_flags = le16_to_cpu(sts->state_flags); 1343 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1344 uint16_t residual_length = le32_to_cpu(sts->residual_length); 1344 uint32_t residual_length = le32_to_cpu(sts->residual_length);
1345 uint16_t scsi_status = le16_to_cpu(sts->scsi_status); 1345 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1346#if DEBUG_QLA1280_INTR 1346#if DEBUG_QLA1280_INTR
1347 static char *reason[] = { 1347 static char *reason[] = {
@@ -1413,8 +1413,10 @@ qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1413 "scsi: Underflow detected - retrying " 1413 "scsi: Underflow detected - retrying "
1414 "command.\n"); 1414 "command.\n");
1415 host_status = DID_ERROR; 1415 host_status = DID_ERROR;
1416 } else 1416 } else {
1417 cp->resid = residual_length;
1417 host_status = DID_OK; 1418 host_status = DID_OK;
1419 }
1418 break; 1420 break;
1419 1421
1420 default: 1422 default:
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index e83e4a34725a..05f4f2a378eb 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -1602,6 +1602,7 @@ typedef struct fc_port {
1602 1602
1603#define CT_REJECT_RESPONSE 0x8001 1603#define CT_REJECT_RESPONSE 0x8001
1604#define CT_ACCEPT_RESPONSE 0x8002 1604#define CT_ACCEPT_RESPONSE 0x8002
1605#define CT_REASON_INVALID_COMMAND_CODE 0x01
1605#define CT_REASON_CANNOT_PERFORM 0x09 1606#define CT_REASON_CANNOT_PERFORM 0x09
1606#define CT_EXPL_ALREADY_REGISTERED 0x10 1607#define CT_EXPL_ALREADY_REGISTERED 0x10
1607 1608
@@ -2103,6 +2104,7 @@ typedef struct scsi_qla_host {
2103 uint32_t msi_enabled :1; 2104 uint32_t msi_enabled :1;
2104 uint32_t msix_enabled :1; 2105 uint32_t msix_enabled :1;
2105 uint32_t disable_serdes :1; 2106 uint32_t disable_serdes :1;
2107 uint32_t gpsc_supported :1;
2106 } flags; 2108 } flags;
2107 2109
2108 atomic_t loop_state; 2110 atomic_t loop_state;
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index f8bddec4fe85..74544ae4b0e2 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -45,7 +45,6 @@ extern void qla2x00_update_fcports(scsi_qla_host_t *);
45extern int qla2x00_abort_isp(scsi_qla_host_t *); 45extern int qla2x00_abort_isp(scsi_qla_host_t *);
46 46
47extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *); 47extern void qla2x00_update_fcport(scsi_qla_host_t *, fc_port_t *);
48extern void qla2x00_reg_remote_port(scsi_qla_host_t *, fc_port_t *);
49 48
50extern void qla2x00_alloc_fw_dump(scsi_qla_host_t *); 49extern void qla2x00_alloc_fw_dump(scsi_qla_host_t *);
51extern void qla2x00_try_to_stop_firmware(scsi_qla_host_t *); 50extern void qla2x00_try_to_stop_firmware(scsi_qla_host_t *);
diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c
index 97fbc62ec669..ec5b2dd90d6a 100644
--- a/drivers/scsi/qla2xxx/qla_gs.c
+++ b/drivers/scsi/qla2xxx/qla_gs.c
@@ -127,8 +127,8 @@ qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
127 ha->host_no, routine, ms_pkt->entry_status)); 127 ha->host_no, routine, ms_pkt->entry_status));
128 } else { 128 } else {
129 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) 129 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
130 comp_status = 130 comp_status = le16_to_cpu(
131 ((struct ct_entry_24xx *)ms_pkt)->comp_status; 131 ((struct ct_entry_24xx *)ms_pkt)->comp_status);
132 else 132 else
133 comp_status = le16_to_cpu(ms_pkt->status); 133 comp_status = le16_to_cpu(ms_pkt->status);
134 switch (comp_status) { 134 switch (comp_status) {
@@ -143,6 +143,7 @@ qla2x00_chk_ms_status(scsi_qla_host_t *ha, ms_iocb_entry_t *ms_pkt,
143 DEBUG2_3(qla2x00_dump_buffer( 143 DEBUG2_3(qla2x00_dump_buffer(
144 (uint8_t *)&ct_rsp->header, 144 (uint8_t *)&ct_rsp->header,
145 sizeof(struct ct_rsp_hdr))); 145 sizeof(struct ct_rsp_hdr)));
146 rval = QLA_INVALID_COMMAND;
146 } else 147 } else
147 rval = QLA_SUCCESS; 148 rval = QLA_SUCCESS;
148 break; 149 break;
@@ -1683,7 +1684,7 @@ qla2x00_gfpn_id(scsi_qla_host_t *ha, sw_info_t *list)
1683 memset(list[i].fabric_port_name, 0, WWN_SIZE); 1684 memset(list[i].fabric_port_name, 0, WWN_SIZE);
1684 1685
1685 /* Prepare common MS IOCB */ 1686 /* Prepare common MS IOCB */
1686 ms_pkt = qla2x00_prep_ms_iocb(ha, GFPN_ID_REQ_SIZE, 1687 ms_pkt = ha->isp_ops.prep_ms_iocb(ha, GFPN_ID_REQ_SIZE,
1687 GFPN_ID_RSP_SIZE); 1688 GFPN_ID_RSP_SIZE);
1688 1689
1689 /* Prepare CT request */ 1690 /* Prepare CT request */
@@ -1784,6 +1785,8 @@ qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
1784 1785
1785 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) 1786 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
1786 return QLA_FUNCTION_FAILED; 1787 return QLA_FUNCTION_FAILED;
1788 if (!ha->flags.gpsc_supported)
1789 return QLA_FUNCTION_FAILED;
1787 1790
1788 rval = qla2x00_mgmt_svr_login(ha); 1791 rval = qla2x00_mgmt_svr_login(ha);
1789 if (rval) 1792 if (rval)
@@ -1813,8 +1816,19 @@ qla2x00_gpsc(scsi_qla_host_t *ha, sw_info_t *list)
1813 /*EMPTY*/ 1816 /*EMPTY*/
1814 DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB " 1817 DEBUG2_3(printk("scsi(%ld): GPSC issue IOCB "
1815 "failed (%d).\n", ha->host_no, rval)); 1818 "failed (%d).\n", ha->host_no, rval));
1816 } else if (qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp, 1819 } else if ((rval = qla2x00_chk_ms_status(ha, ms_pkt, ct_rsp,
1817 "GPSC") != QLA_SUCCESS) { 1820 "GPSC")) != QLA_SUCCESS) {
1821 /* FM command unsupported? */
1822 if (rval == QLA_INVALID_COMMAND &&
1823 ct_rsp->header.reason_code ==
1824 CT_REASON_INVALID_COMMAND_CODE) {
1825 DEBUG2(printk("scsi(%ld): GPSC command "
1826 "unsupported, disabling query...\n",
1827 ha->host_no));
1828 ha->flags.gpsc_supported = 0;
1829 rval = QLA_FUNCTION_FAILED;
1830 break;
1831 }
1818 rval = QLA_FUNCTION_FAILED; 1832 rval = QLA_FUNCTION_FAILED;
1819 } else { 1833 } else {
1820 /* Save portname */ 1834 /* Save portname */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index ef87d81935d2..98c01cd5e1a8 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -2065,40 +2065,7 @@ qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2065 } 2065 }
2066} 2066}
2067 2067
2068/* 2068static void
2069 * qla2x00_update_fcport
2070 * Updates device on list.
2071 *
2072 * Input:
2073 * ha = adapter block pointer.
2074 * fcport = port structure pointer.
2075 *
2076 * Return:
2077 * 0 - Success
2078 * BIT_0 - error
2079 *
2080 * Context:
2081 * Kernel context.
2082 */
2083void
2084qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2085{
2086 fcport->ha = ha;
2087 fcport->login_retry = 0;
2088 fcport->port_login_retry_count = ha->port_down_retry_count *
2089 PORT_RETRY_TIME;
2090 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2091 PORT_RETRY_TIME);
2092 fcport->flags &= ~FCF_LOGIN_NEEDED;
2093
2094 qla2x00_iidma_fcport(ha, fcport);
2095
2096 atomic_set(&fcport->state, FCS_ONLINE);
2097
2098 qla2x00_reg_remote_port(ha, fcport);
2099}
2100
2101void
2102qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport) 2069qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2103{ 2070{
2104 struct fc_rport_identifiers rport_ids; 2071 struct fc_rport_identifiers rport_ids;
@@ -2141,6 +2108,39 @@ qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2141} 2108}
2142 2109
2143/* 2110/*
2111 * qla2x00_update_fcport
2112 * Updates device on list.
2113 *
2114 * Input:
2115 * ha = adapter block pointer.
2116 * fcport = port structure pointer.
2117 *
2118 * Return:
2119 * 0 - Success
2120 * BIT_0 - error
2121 *
2122 * Context:
2123 * Kernel context.
2124 */
2125void
2126qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2127{
2128 fcport->ha = ha;
2129 fcport->login_retry = 0;
2130 fcport->port_login_retry_count = ha->port_down_retry_count *
2131 PORT_RETRY_TIME;
2132 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
2133 PORT_RETRY_TIME);
2134 fcport->flags &= ~FCF_LOGIN_NEEDED;
2135
2136 qla2x00_iidma_fcport(ha, fcport);
2137
2138 atomic_set(&fcport->state, FCS_ONLINE);
2139
2140 qla2x00_reg_remote_port(ha, fcport);
2141}
2142
2143/*
2144 * qla2x00_configure_fabric 2144 * qla2x00_configure_fabric
2145 * Setup SNS devices with loop ID's. 2145 * Setup SNS devices with loop ID's.
2146 * 2146 *
@@ -3380,9 +3380,11 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3380 3380
3381 /* Set host adapter parameters. */ 3381 /* Set host adapter parameters. */
3382 ha->flags.disable_risc_code_load = 0; 3382 ha->flags.disable_risc_code_load = 0;
3383 ha->flags.enable_lip_reset = 1; 3383 ha->flags.enable_lip_reset = 0;
3384 ha->flags.enable_lip_full_login = 1; 3384 ha->flags.enable_lip_full_login =
3385 ha->flags.enable_target_reset = 1; 3385 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3386 ha->flags.enable_target_reset =
3387 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
3386 ha->flags.enable_led_scheme = 0; 3388 ha->flags.enable_led_scheme = 0;
3387 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; 3389 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
3388 3390
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index c948a8ce7232..d4885616cd39 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -130,11 +130,11 @@ qla2300_intr_handler(int irq, void *dev_id)
130 if (stat & HSR_RISC_PAUSED) { 130 if (stat & HSR_RISC_PAUSED) {
131 hccr = RD_REG_WORD(&reg->hccr); 131 hccr = RD_REG_WORD(&reg->hccr);
132 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8)) 132 if (hccr & (BIT_15 | BIT_13 | BIT_11 | BIT_8))
133 qla_printk(KERN_INFO, ha, 133 qla_printk(KERN_INFO, ha, "Parity error -- "
134 "Parity error -- HCCR=%x.\n", hccr); 134 "HCCR=%x, Dumping firmware!\n", hccr);
135 else 135 else
136 qla_printk(KERN_INFO, ha, 136 qla_printk(KERN_INFO, ha, "RISC paused -- "
137 "RISC paused -- HCCR=%x.\n", hccr); 137 "HCCR=%x, Dumping firmware!\n", hccr);
138 138
139 /* 139 /*
140 * Issue a "HARD" reset in order for the RISC 140 * Issue a "HARD" reset in order for the RISC
@@ -143,6 +143,8 @@ qla2300_intr_handler(int irq, void *dev_id)
143 */ 143 */
144 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC); 144 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
145 RD_REG_WORD(&reg->hccr); 145 RD_REG_WORD(&reg->hccr);
146
147 ha->isp_ops.fw_dump(ha, 1);
146 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); 148 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
147 break; 149 break;
148 } else if ((stat & HSR_RISC_INT) == 0) 150 } else if ((stat & HSR_RISC_INT) == 0)
@@ -467,6 +469,8 @@ qla2x00_async_event(scsi_qla_host_t *ha, uint16_t *mb)
467 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 469 set_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
468 } 470 }
469 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); 471 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
472
473 ha->flags.gpsc_supported = 1;
470 break; 474 break;
471 475
472 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */ 476 case MBA_CHG_IN_CONNECTION: /* Change in connection mode */
@@ -1444,8 +1448,7 @@ qla24xx_intr_handler(int irq, void *dev_id)
1444 1448
1445 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, " 1449 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1446 "Dumping firmware!\n", hccr); 1450 "Dumping firmware!\n", hccr);
1447 qla24xx_fw_dump(ha, 1); 1451 ha->isp_ops.fw_dump(ha, 1);
1448
1449 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); 1452 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1450 break; 1453 break;
1451 } else if ((stat & HSRX_RISC_INT) == 0) 1454 } else if ((stat & HSRX_RISC_INT) == 0)
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index c6f0cdf4cdc4..83376f6ac3db 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -1323,9 +1323,9 @@ qla2x00_lip_reset(scsi_qla_host_t *ha)
1323 1323
1324 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 1324 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1325 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1325 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1326 mcp->mb[1] = BIT_0; 1326 mcp->mb[1] = BIT_6;
1327 mcp->mb[2] = 0xff; 1327 mcp->mb[2] = 0;
1328 mcp->mb[3] = 0; 1328 mcp->mb[3] = ha->loop_reset_delay;
1329 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; 1329 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1330 } else { 1330 } else {
1331 mcp->mb[0] = MBC_LIP_RESET; 1331 mcp->mb[0] = MBC_LIP_RESET;
@@ -1807,8 +1807,8 @@ qla2x00_full_login_lip(scsi_qla_host_t *ha)
1807 ha->host_no)); 1807 ha->host_no));
1808 1808
1809 mcp->mb[0] = MBC_LIP_FULL_LOGIN; 1809 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1810 mcp->mb[1] = 0; 1810 mcp->mb[1] = IS_QLA24XX(ha) || IS_QLA54XX(ha) ? BIT_3: 0;
1811 mcp->mb[2] = 0xff; 1811 mcp->mb[2] = 0;
1812 mcp->mb[3] = 0; 1812 mcp->mb[3] = 0;
1813 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; 1813 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1814 mcp->in_mb = MBX_0; 1814 mcp->in_mb = MBX_0;
@@ -2470,7 +2470,7 @@ qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2470 mcp->mb[4] = LSW(MSD(eft_dma)); 2470 mcp->mb[4] = LSW(MSD(eft_dma));
2471 mcp->mb[5] = MSW(MSD(eft_dma)); 2471 mcp->mb[5] = MSW(MSD(eft_dma));
2472 mcp->mb[6] = buffers; 2472 mcp->mb[6] = buffers;
2473 mcp->mb[7] = buffers; 2473 mcp->mb[7] = 0;
2474 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2; 2474 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2475 } 2475 }
2476 mcp->tov = 30; 2476 mcp->tov = 30;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 6f161d3f661b..68f5d24b938b 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1037,48 +1037,49 @@ eh_host_reset_lock:
1037static int 1037static int
1038qla2x00_loop_reset(scsi_qla_host_t *ha) 1038qla2x00_loop_reset(scsi_qla_host_t *ha)
1039{ 1039{
1040 int status = QLA_SUCCESS; 1040 int ret;
1041 struct fc_port *fcport; 1041 struct fc_port *fcport;
1042 1042
1043 if (ha->flags.enable_lip_full_login) {
1044 ret = qla2x00_full_login_lip(ha);
1045 if (ret != QLA_SUCCESS) {
1046 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1047 "full_login_lip=%d.\n", __func__, ha->host_no,
1048 ret));
1049 }
1050 atomic_set(&ha->loop_state, LOOP_DOWN);
1051 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
1052 qla2x00_mark_all_devices_lost(ha, 0);
1053 qla2x00_wait_for_loop_ready(ha);
1054 }
1055
1043 if (ha->flags.enable_lip_reset) { 1056 if (ha->flags.enable_lip_reset) {
1044 status = qla2x00_lip_reset(ha); 1057 ret = qla2x00_lip_reset(ha);
1058 if (ret != QLA_SUCCESS) {
1059 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1060 "lip_reset=%d.\n", __func__, ha->host_no, ret));
1061 }
1062 qla2x00_wait_for_loop_ready(ha);
1045 } 1063 }
1046 1064
1047 if (status == QLA_SUCCESS && ha->flags.enable_target_reset) { 1065 if (ha->flags.enable_target_reset) {
1048 list_for_each_entry(fcport, &ha->fcports, list) { 1066 list_for_each_entry(fcport, &ha->fcports, list) {
1049 if (fcport->port_type != FCT_TARGET) 1067 if (fcport->port_type != FCT_TARGET)
1050 continue; 1068 continue;
1051 1069
1052 status = qla2x00_device_reset(ha, fcport); 1070 ret = qla2x00_device_reset(ha, fcport);
1053 if (status != QLA_SUCCESS) 1071 if (ret != QLA_SUCCESS) {
1054 break; 1072 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1073 "target_reset=%d d_id=%x.\n", __func__,
1074 ha->host_no, ret, fcport->d_id.b24));
1075 }
1055 } 1076 }
1056 } 1077 }
1057 1078
1058 if (status == QLA_SUCCESS &&
1059 ((!ha->flags.enable_target_reset &&
1060 !ha->flags.enable_lip_reset) ||
1061 ha->flags.enable_lip_full_login)) {
1062
1063 status = qla2x00_full_login_lip(ha);
1064 }
1065
1066 /* Issue marker command only when we are going to start the I/O */ 1079 /* Issue marker command only when we are going to start the I/O */
1067 ha->marker_needed = 1; 1080 ha->marker_needed = 1;
1068 1081
1069 if (status) { 1082 return QLA_SUCCESS;
1070 /* Empty */
1071 DEBUG2_3(printk("%s(%ld): **** FAILED ****\n",
1072 __func__,
1073 ha->host_no));
1074 } else {
1075 /* Empty */
1076 DEBUG3(printk("%s(%ld): exiting normally.\n",
1077 __func__,
1078 ha->host_no));
1079 }
1080
1081 return(status);
1082} 1083}
1083 1084
1084/* 1085/*
@@ -1413,7 +1414,9 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1413 1414
1414 sht = &qla2x00_driver_template; 1415 sht = &qla2x00_driver_template;
1415 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 || 1416 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1416 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432) 1417 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
1418 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1419 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432)
1417 sht = &qla24xx_driver_template; 1420 sht = &qla24xx_driver_template;
1418 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); 1421 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
1419 if (host == NULL) { 1422 if (host == NULL) {
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 1fa0bce6b24e..459e0d6bd2b4 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.01.07-k3" 10#define QLA2XXX_VERSION "8.01.07-k4"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 1 13#define QLA_DRIVER_MINOR_VER 1
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index b8f0cab57813..8160c00d1092 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -133,12 +133,10 @@ struct async_scan_data {
133/** 133/**
134 * scsi_complete_async_scans - Wait for asynchronous scans to complete 134 * scsi_complete_async_scans - Wait for asynchronous scans to complete
135 * 135 *
136 * Asynchronous scans add themselves to the scanning_hosts list. Once 136 * When this function returns, any host which started scanning before
137 * that list is empty, we know that the scans are complete. Rather than 137 * this function was called will have finished its scan. Hosts which
138 * waking up periodically to check the state of the list, we pretend to be 138 * started scanning after this function was called may or may not have
139 * a scanning task by adding ourselves at the end of the list and going to 139 * finished.
140 * sleep. When the task before us wakes us up, we take ourselves off the
141 * list and return.
142 */ 140 */
143int scsi_complete_async_scans(void) 141int scsi_complete_async_scans(void)
144{ 142{
@@ -171,6 +169,11 @@ int scsi_complete_async_scans(void)
171 169
172 spin_lock(&async_scan_lock); 170 spin_lock(&async_scan_lock);
173 list_del(&data->list); 171 list_del(&data->list);
172 if (!list_empty(&scanning_hosts)) {
173 struct async_scan_data *next = list_entry(scanning_hosts.next,
174 struct async_scan_data, list);
175 complete(&next->prev_finished);
176 }
174 done: 177 done:
175 spin_unlock(&async_scan_lock); 178 spin_unlock(&async_scan_lock);
176 179
@@ -739,6 +742,14 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
739 sdev->no_uld_attach = 1; 742 sdev->no_uld_attach = 1;
740 743
741 switch (sdev->type = (inq_result[0] & 0x1f)) { 744 switch (sdev->type = (inq_result[0] & 0x1f)) {
745 case TYPE_RBC:
746 /* RBC devices can return SCSI-3 compliance and yet
747 * still not support REPORT LUNS, so make them act as
748 * BLIST_NOREPORTLUN unless BLIST_REPORTLUN2 is
749 * specifically set */
750 if ((*bflags & BLIST_REPORTLUN2) == 0)
751 *bflags |= BLIST_NOREPORTLUN;
752 /* fall through */
742 case TYPE_TAPE: 753 case TYPE_TAPE:
743 case TYPE_DISK: 754 case TYPE_DISK:
744 case TYPE_PRINTER: 755 case TYPE_PRINTER:
@@ -749,11 +760,17 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
749 case TYPE_ENCLOSURE: 760 case TYPE_ENCLOSURE:
750 case TYPE_COMM: 761 case TYPE_COMM:
751 case TYPE_RAID: 762 case TYPE_RAID:
752 case TYPE_RBC:
753 sdev->writeable = 1; 763 sdev->writeable = 1;
754 break; 764 break;
755 case TYPE_WORM:
756 case TYPE_ROM: 765 case TYPE_ROM:
766 /* MMC devices can return SCSI-3 compliance and yet
767 * still not support REPORT LUNS, so make them act as
768 * BLIST_NOREPORTLUN unless BLIST_REPORTLUN2 is
769 * specifically set */
770 if ((*bflags & BLIST_REPORTLUN2) == 0)
771 *bflags |= BLIST_NOREPORTLUN;
772 /* fall through */
773 case TYPE_WORM:
757 sdev->writeable = 0; 774 sdev->writeable = 0;
758 break; 775 break;
759 default: 776 default:
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 9c22f1342715..ce0d14af33c8 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1416,7 +1416,7 @@ static __init int iscsi_transport_init(void)
1416{ 1416{
1417 int err; 1417 int err;
1418 1418
1419 printk(KERN_INFO "Loading iSCSI transport class v%s.", 1419 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
1420 ISCSI_TRANSPORT_VERSION); 1420 ISCSI_TRANSPORT_VERSION);
1421 1421
1422 err = class_register(&iscsi_transport_class); 1422 err = class_register(&iscsi_transport_class);
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 3fded4831460..014d7fea1ff3 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -122,7 +122,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
122 if (!sshdr) 122 if (!sshdr)
123 sshdr = &sshdr_tmp; 123 sshdr = &sshdr_tmp;
124 124
125 if (scsi_normalize_sense(sense, sizeof(*sense), 125 if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE,
126 sshdr) 126 sshdr)
127 && sshdr->sense_key == UNIT_ATTENTION) 127 && sshdr->sense_key == UNIT_ATTENTION)
128 continue; 128 continue;
diff --git a/drivers/scsi/seagate.c b/drivers/scsi/seagate.c
index 5ffec2721b28..ff62e9708e1c 100644
--- a/drivers/scsi/seagate.c
+++ b/drivers/scsi/seagate.c
@@ -114,6 +114,7 @@
114#define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0) 114#define DPRINTK( when, msg... ) do { if ( (DEBUG & (when)) == (when) ) printk( msg ); } while (0)
115#else 115#else
116#define DPRINTK( when, msg... ) do { } while (0) 116#define DPRINTK( when, msg... ) do { } while (0)
117#define DEBUG 0
117#endif 118#endif
118#define DANY( msg... ) DPRINTK( 0xffff, msg ); 119#define DANY( msg... ) DPRINTK( 0xffff, msg );
119 120
@@ -523,7 +524,7 @@ int __init seagate_st0x_detect (struct scsi_host_template * tpnt)
523#ifdef ARBITRATE 524#ifdef ARBITRATE
524 " ARBITRATE" 525 " ARBITRATE"
525#endif 526#endif
526#ifdef DEBUG 527#if DEBUG
527 " DEBUG" 528 " DEBUG"
528#endif 529#endif
529#ifdef FAST 530#ifdef FAST
@@ -733,7 +734,7 @@ static int internal_command (unsigned char target, unsigned char lun,
733 unsigned char *data = NULL; 734 unsigned char *data = NULL;
734 struct scatterlist *buffer = NULL; 735 struct scatterlist *buffer = NULL;
735 int clock, temp, nobuffs = 0, done = 0, len = 0; 736 int clock, temp, nobuffs = 0, done = 0, len = 0;
736#ifdef DEBUG 737#if DEBUG
737 int transfered = 0, phase = 0, newphase; 738 int transfered = 0, phase = 0, newphase;
738#endif 739#endif
739 register unsigned char status_read; 740 register unsigned char status_read;
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index fae6e95a6298..89e9b36b1788 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -468,7 +468,7 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
468 } 468 }
469 469
470 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg); 470 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg);
471 if (ret != ENOSYS) 471 if (ret != -ENOSYS)
472 return ret; 472 return ret;
473 473
474 /* 474 /*
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 61db6973755a..f69bd097166e 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -589,6 +589,8 @@ static int __init pl010_console_setup(struct console *co, char *options)
589 */ 589 */
590 if (co->index >= UART_NR) 590 if (co->index >= UART_NR)
591 co->index = 0; 591 co->index = 0;
592 if (!amba_ports[co->index])
593 return -ENODEV;
592 port = &amba_ports[co->index]->port; 594 port = &amba_ports[co->index]->port;
593 595
594 if (options) 596 if (options)
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index 9a3b374b2a08..44639e71372a 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -661,6 +661,8 @@ static int __init pl011_console_setup(struct console *co, char *options)
661 if (co->index >= UART_NR) 661 if (co->index >= UART_NR)
662 co->index = 0; 662 co->index = 0;
663 uap = amba_ports[co->index]; 663 uap = amba_ports[co->index];
664 if (!uap)
665 return -ENODEV;
664 666
665 uap->port.uartclk = clk_get_rate(uap->clk); 667 uap->port.uartclk = clk_get_rate(uap->clk);
666 668
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index ed7f7209ea59..881f886b91c6 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -689,9 +689,9 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, struct
689 struct atmel_uart_data *data = pdev->dev.platform_data; 689 struct atmel_uart_data *data = pdev->dev.platform_data;
690 690
691 port->iotype = UPIO_MEM; 691 port->iotype = UPIO_MEM;
692 port->flags = UPF_BOOT_AUTOCONF; 692 port->flags = UPF_BOOT_AUTOCONF;
693 port->ops = &atmel_pops; 693 port->ops = &atmel_pops;
694 port->fifosize = 1; 694 port->fifosize = 1;
695 port->line = pdev->id; 695 port->line = pdev->id;
696 port->dev = &pdev->dev; 696 port->dev = &pdev->dev;
697 697
@@ -890,7 +890,6 @@ static int atmel_serial_suspend(struct platform_device *pdev, pm_message_t state
890 if (device_may_wakeup(&pdev->dev) && !at91_suspend_entering_slow_clock()) 890 if (device_may_wakeup(&pdev->dev) && !at91_suspend_entering_slow_clock())
891 enable_irq_wake(port->irq); 891 enable_irq_wake(port->irq);
892 else { 892 else {
893 disable_irq_wake(port->irq);
894 uart_suspend_port(&atmel_uart, port); 893 uart_suspend_port(&atmel_uart, port);
895 atmel_port->suspended = 1; 894 atmel_port->suspended = 1;
896 } 895 }
@@ -907,6 +906,8 @@ static int atmel_serial_resume(struct platform_device *pdev)
907 uart_resume_port(&atmel_uart, port); 906 uart_resume_port(&atmel_uart, port);
908 atmel_port->suspended = 0; 907 atmel_port->suspended = 0;
909 } 908 }
909 else
910 disable_irq_wake(port->irq);
910 911
911 return 0; 912 return 0;
912} 913}
diff --git a/drivers/serial/atmel_serial.h b/drivers/serial/atmel_serial.h
index fe1763b2a6d5..11b44360e108 100644
--- a/drivers/serial/atmel_serial.h
+++ b/drivers/serial/atmel_serial.h
@@ -106,7 +106,7 @@
106#define ATMEL_US_CSR 0x14 /* Channel Status Register */ 106#define ATMEL_US_CSR 0x14 /* Channel Status Register */
107#define ATMEL_US_RHR 0x18 /* Receiver Holding Register */ 107#define ATMEL_US_RHR 0x18 /* Receiver Holding Register */
108#define ATMEL_US_THR 0x1c /* Transmitter Holding Register */ 108#define ATMEL_US_THR 0x1c /* Transmitter Holding Register */
109#define ATMEL_US_SYNH (1 << 15) /* Transmit/Receive Sync [SAM9 only] */ 109#define ATMEL_US_SYNH (1 << 15) /* Transmit/Receive Sync [AT91SAM9261 only] */
110 110
111#define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */ 111#define ATMEL_US_BRGR 0x20 /* Baud Rate Generator Register */
112#define ATMEL_US_CD (0xffff << 0) /* Clock Divider */ 112#define ATMEL_US_CD (0xffff << 0) /* Clock Divider */
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 6ed3f1da9296..8b41f9cc2560 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1169,8 +1169,9 @@ static int setup(struct spi_device *spi)
1169 spi->bits_per_word - 16 : spi->bits_per_word) 1169 spi->bits_per_word - 16 : spi->bits_per_word)
1170 | SSCR0_SSE 1170 | SSCR0_SSE
1171 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0); 1171 | (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
1172 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) << 4) 1172 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1173 | (((spi->mode & SPI_CPOL) != 0) << 3); 1173 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1174 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
1174 1175
1175 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1176 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1176 if (drv_data->ssp_type != PXA25x_SSP) 1177 if (drv_data->ssp_type != PXA25x_SSP)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 270e6211c2e3..6307428d2c94 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -366,7 +366,6 @@ spi_alloc_master(struct device *dev, unsigned size)
366 366
367 class_device_initialize(&master->cdev); 367 class_device_initialize(&master->cdev);
368 master->cdev.class = &spi_master_class; 368 master->cdev.class = &spi_master_class;
369 kobj_set_kset_s(&master->cdev, spi_master_class.subsys);
370 master->cdev.dev = get_device(dev); 369 master->cdev.dev = get_device(dev);
371 spi_master_set_devdata(master, &master[1]); 370 spi_master_set_devdata(master, &master[1]);
372 371
@@ -466,14 +465,20 @@ EXPORT_SYMBOL_GPL(spi_unregister_master);
466 */ 465 */
467struct spi_master *spi_busnum_to_master(u16 bus_num) 466struct spi_master *spi_busnum_to_master(u16 bus_num)
468{ 467{
469 char name[9]; 468 struct class_device *cdev;
470 struct kobject *bus; 469 struct spi_master *master = NULL;
471 470 struct spi_master *m;
472 snprintf(name, sizeof name, "spi%u", bus_num); 471
473 bus = kset_find_obj(&spi_master_class.subsys.kset, name); 472 down(&spi_master_class.sem);
474 if (bus) 473 list_for_each_entry(cdev, &spi_master_class.children, node) {
475 return container_of(bus, struct spi_master, cdev.kobj); 474 m = container_of(cdev, struct spi_master, cdev);
476 return NULL; 475 if (m->bus_num == bus_num) {
476 master = spi_master_get(m);
477 break;
478 }
479 }
480 up(&spi_master_class.sem);
481 return master;
477} 482}
478EXPORT_SYMBOL_GPL(spi_busnum_to_master); 483EXPORT_SYMBOL_GPL(spi_busnum_to_master);
479 484
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 8ca08713528e..651379c51ae6 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -10,9 +10,6 @@
10 * 10 *
11*/ 11*/
12 12
13
14//#define DEBUG
15
16#include <linux/init.h> 13#include <linux/init.h>
17#include <linux/spinlock.h> 14#include <linux/spinlock.h>
18#include <linux/workqueue.h> 15#include <linux/workqueue.h>
@@ -44,6 +41,9 @@ struct s3c24xx_spi {
44 int len; 41 int len;
45 int count; 42 int count;
46 43
44 int (*set_cs)(struct s3c2410_spi_info *spi,
45 int cs, int pol);
46
47 /* data buffers */ 47 /* data buffers */
48 const unsigned char *tx; 48 const unsigned char *tx;
49 unsigned char *rx; 49 unsigned char *rx;
@@ -64,6 +64,11 @@ static inline struct s3c24xx_spi *to_hw(struct spi_device *sdev)
64 return spi_master_get_devdata(sdev->master); 64 return spi_master_get_devdata(sdev->master);
65} 65}
66 66
67static void s3c24xx_spi_gpiocs(struct s3c2410_spi_info *spi, int cs, int pol)
68{
69 s3c2410_gpio_setpin(spi->pin_cs, pol);
70}
71
67static void s3c24xx_spi_chipsel(struct spi_device *spi, int value) 72static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
68{ 73{
69 struct s3c24xx_spi *hw = to_hw(spi); 74 struct s3c24xx_spi *hw = to_hw(spi);
@@ -72,10 +77,7 @@ static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
72 77
73 switch (value) { 78 switch (value) {
74 case BITBANG_CS_INACTIVE: 79 case BITBANG_CS_INACTIVE:
75 if (hw->pdata->set_cs) 80 hw->pdata->set_cs(hw->pdata, spi->chip_select, cspol^1);
76 hw->pdata->set_cs(hw->pdata, value, cspol);
77 else
78 s3c2410_gpio_setpin(hw->pdata->pin_cs, cspol ^ 1);
79 break; 81 break;
80 82
81 case BITBANG_CS_ACTIVE: 83 case BITBANG_CS_ACTIVE:
@@ -96,14 +98,9 @@ static void s3c24xx_spi_chipsel(struct spi_device *spi, int value)
96 /* write new configration */ 98 /* write new configration */
97 99
98 writeb(spcon, hw->regs + S3C2410_SPCON); 100 writeb(spcon, hw->regs + S3C2410_SPCON);
99 101 hw->pdata->set_cs(hw->pdata, spi->chip_select, cspol);
100 if (hw->pdata->set_cs)
101 hw->pdata->set_cs(hw->pdata, value, cspol);
102 else
103 s3c2410_gpio_setpin(hw->pdata->pin_cs, cspol);
104 102
105 break; 103 break;
106
107 } 104 }
108} 105}
109 106
@@ -330,9 +327,12 @@ static int s3c24xx_spi_probe(struct platform_device *pdev)
330 /* setup any gpio we can */ 327 /* setup any gpio we can */
331 328
332 if (!hw->pdata->set_cs) { 329 if (!hw->pdata->set_cs) {
330 hw->set_cs = s3c24xx_spi_gpiocs;
331
333 s3c2410_gpio_setpin(hw->pdata->pin_cs, 1); 332 s3c2410_gpio_setpin(hw->pdata->pin_cs, 1);
334 s3c2410_gpio_cfgpin(hw->pdata->pin_cs, S3C2410_GPIO_OUTPUT); 333 s3c2410_gpio_cfgpin(hw->pdata->pin_cs, S3C2410_GPIO_OUTPUT);
335 } 334 } else
335 hw->set_cs = hw->pdata->set_cs;
336 336
337 /* register our spi controller */ 337 /* register our spi controller */
338 338
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index f8324d8d06ac..3e66b2a9974a 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -72,22 +72,6 @@ config USB_SUSPEND
72 72
73 If you are unsure about this, say N here. 73 If you are unsure about this, say N here.
74 74
75config USB_MULTITHREAD_PROBE
76 bool "USB Multi-threaded probe (EXPERIMENTAL)"
77 depends on USB && EXPERIMENTAL
78 default n
79 help
80 Say Y here if you want the USB core to spawn a new thread for
81 every USB device that is probed. This can cause a small speedup
82 in boot times on systems with a lot of different USB devices.
83
84 This option should be safe to enable, but if any odd probing
85 problems are found, please disable it, or dynamically turn it
86 off in the /sys/module/usbcore/parameters/multithread_probe
87 file
88
89 When in doubt, say N.
90
91config USB_OTG 75config USB_OTG
92 bool 76 bool
93 depends on USB && EXPERIMENTAL 77 depends on USB && EXPERIMENTAL
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2651c2e2a89f..1988224b362b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -88,14 +88,7 @@ static DECLARE_WAIT_QUEUE_HEAD(khubd_wait);
88static struct task_struct *khubd_task; 88static struct task_struct *khubd_task;
89 89
90/* multithreaded probe logic */ 90/* multithreaded probe logic */
91static int multithread_probe = 91static int multithread_probe = 0;
92#ifdef CONFIG_USB_MULTITHREAD_PROBE
93 1;
94#else
95 0;
96#endif
97module_param(multithread_probe, bool, S_IRUGO);
98MODULE_PARM_DESC(multithread_probe, "Run each USB device probe in a new thread");
99 92
100/* cycle leds on hubs that aren't blinking for attention */ 93/* cycle leds on hubs that aren't blinking for attention */
101static int blinkenlights = 0; 94static int blinkenlights = 0;
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 43ae696b2ec2..3348b07f0fe5 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -169,7 +169,7 @@ static int ohci_hcd_ep93xx_drv_remove(struct platform_device *pdev)
169static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state) 169static int ohci_hcd_ep93xx_drv_suspend(struct platform_device *pdev, pm_message_t state)
170{ 170{
171 struct usb_hcd *hcd = platform_get_drvdata(pdev); 171 struct usb_hcd *hcd = platform_get_drvdata(pdev);
172 struct ochi_hcd *ohci = hcd_to_ohci(hcd); 172 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
173 173
174 if (time_before(jiffies, ohci->next_statechange)) 174 if (time_before(jiffies, ohci->next_statechange))
175 msleep(5); 175 msleep(5);
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 258a5d09d3dc..c7d887540d8d 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -7,7 +7,7 @@ comment "USB Input Devices"
7config USB_HID 7config USB_HID
8 tristate "USB Human Interface Device (full HID) support" 8 tristate "USB Human Interface Device (full HID) support"
9 default y 9 default y
10 depends on USB 10 depends on USB && INPUT
11 select HID 11 select HID
12 ---help--- 12 ---help---
13 Say Y here if you want full HID support to connect USB keyboards, 13 Say Y here if you want full HID support to connect USB keyboards,
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 89fa6885709b..c6c9e72e5fd9 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -56,11 +56,6 @@ static unsigned int hid_mousepoll_interval;
56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); 56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
57MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); 57MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
58 58
59static int usbhid_pb_fnmode = 1;
60module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
61MODULE_PARM_DESC(pb_fnmode,
62 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
63
64/* 59/*
65 * Input submission and I/O error handler. 60 * Input submission and I/O error handler.
66 */ 61 */
@@ -106,18 +101,18 @@ static void hid_reset(struct work_struct *work)
106 101
107 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) { 102 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
108 dev_dbg(&usbhid->intf->dev, "clear halt\n"); 103 dev_dbg(&usbhid->intf->dev, "clear halt\n");
109 rc = usb_clear_halt(to_usb_device(hid->dev), usbhid->urbin->pipe); 104 rc = usb_clear_halt(hid_to_usb_dev(hid), usbhid->urbin->pipe);
110 clear_bit(HID_CLEAR_HALT, &usbhid->iofl); 105 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
111 hid_start_in(hid); 106 hid_start_in(hid);
112 } 107 }
113 108
114 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) { 109 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
115 dev_dbg(&usbhid->intf->dev, "resetting device\n"); 110 dev_dbg(&usbhid->intf->dev, "resetting device\n");
116 rc = rc_lock = usb_lock_device_for_reset(to_usb_device(hid->dev), usbhid->intf); 111 rc = rc_lock = usb_lock_device_for_reset(hid_to_usb_dev(hid), usbhid->intf);
117 if (rc_lock >= 0) { 112 if (rc_lock >= 0) {
118 rc = usb_reset_composite_device(to_usb_device(hid->dev), usbhid->intf); 113 rc = usb_reset_composite_device(hid_to_usb_dev(hid), usbhid->intf);
119 if (rc_lock) 114 if (rc_lock)
120 usb_unlock_device(to_usb_device(hid->dev)); 115 usb_unlock_device(hid_to_usb_dev(hid));
121 } 116 }
122 clear_bit(HID_RESET_PENDING, &usbhid->iofl); 117 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
123 } 118 }
@@ -129,8 +124,8 @@ static void hid_reset(struct work_struct *work)
129 break; 124 break;
130 default: 125 default:
131 err("can't reset device, %s-%s/input%d, status %d", 126 err("can't reset device, %s-%s/input%d, status %d",
132 to_usb_device(hid->dev)->bus->bus_name, 127 hid_to_usb_dev(hid)->bus->bus_name,
133 to_usb_device(hid->dev)->devpath, 128 hid_to_usb_dev(hid)->devpath,
134 usbhid->ifnum, rc); 129 usbhid->ifnum, rc);
135 /* FALLTHROUGH */ 130 /* FALLTHROUGH */
136 case -EHOSTUNREACH: 131 case -EHOSTUNREACH:
@@ -217,8 +212,8 @@ static void hid_irq_in(struct urb *urb)
217 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 212 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
218 if (status != -EPERM) { 213 if (status != -EPERM) {
219 err("can't resubmit intr, %s-%s/input%d, status %d", 214 err("can't resubmit intr, %s-%s/input%d, status %d",
220 to_usb_device(hid->dev)->bus->bus_name, 215 hid_to_usb_dev(hid)->bus->bus_name,
221 to_usb_device(hid->dev)->devpath, 216 hid_to_usb_dev(hid)->devpath,
222 usbhid->ifnum, status); 217 usbhid->ifnum, status);
223 hid_io_error(hid); 218 hid_io_error(hid);
224 } 219 }
@@ -251,7 +246,7 @@ static int hid_submit_out(struct hid_device *hid)
251 246
252 hid_output_report(report, usbhid->outbuf); 247 hid_output_report(report, usbhid->outbuf);
253 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); 248 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
254 usbhid->urbout->dev = to_usb_device(hid->dev); 249 usbhid->urbout->dev = hid_to_usb_dev(hid);
255 250
256 dbg("submitting out urb"); 251 dbg("submitting out urb");
257 252
@@ -276,13 +271,13 @@ static int hid_submit_ctrl(struct hid_device *hid)
276 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 271 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
277 if (dir == USB_DIR_OUT) { 272 if (dir == USB_DIR_OUT) {
278 hid_output_report(report, usbhid->ctrlbuf); 273 hid_output_report(report, usbhid->ctrlbuf);
279 usbhid->urbctrl->pipe = usb_sndctrlpipe(to_usb_device(hid->dev), 0); 274 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
280 usbhid->urbctrl->transfer_buffer_length = len; 275 usbhid->urbctrl->transfer_buffer_length = len;
281 } else { 276 } else {
282 int maxpacket, padlen; 277 int maxpacket, padlen;
283 278
284 usbhid->urbctrl->pipe = usb_rcvctrlpipe(to_usb_device(hid->dev), 0); 279 usbhid->urbctrl->pipe = usb_rcvctrlpipe(hid_to_usb_dev(hid), 0);
285 maxpacket = usb_maxpacket(to_usb_device(hid->dev), usbhid->urbctrl->pipe, 0); 280 maxpacket = usb_maxpacket(hid_to_usb_dev(hid), usbhid->urbctrl->pipe, 0);
286 if (maxpacket > 0) { 281 if (maxpacket > 0) {
287 padlen = (len + maxpacket - 1) / maxpacket; 282 padlen = (len + maxpacket - 1) / maxpacket;
288 padlen *= maxpacket; 283 padlen *= maxpacket;
@@ -292,7 +287,7 @@ static int hid_submit_ctrl(struct hid_device *hid)
292 padlen = 0; 287 padlen = 0;
293 usbhid->urbctrl->transfer_buffer_length = padlen; 288 usbhid->urbctrl->transfer_buffer_length = padlen;
294 } 289 }
295 usbhid->urbctrl->dev = to_usb_device(hid->dev); 290 usbhid->urbctrl->dev = hid_to_usb_dev(hid);
296 291
297 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; 292 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
298 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; 293 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
@@ -582,6 +577,7 @@ void usbhid_init_reports(struct hid_device *hid)
582} 577}
583 578
584#define USB_VENDOR_ID_GTCO 0x078c 579#define USB_VENDOR_ID_GTCO 0x078c
580#define USB_VENDOR_ID_GTCO_IPANEL_2 0x5543
585#define USB_DEVICE_ID_GTCO_90 0x0090 581#define USB_DEVICE_ID_GTCO_90 0x0090
586#define USB_DEVICE_ID_GTCO_100 0x0100 582#define USB_DEVICE_ID_GTCO_100 0x0100
587#define USB_DEVICE_ID_GTCO_101 0x0101 583#define USB_DEVICE_ID_GTCO_101 0x0101
@@ -627,6 +623,8 @@ void usbhid_init_reports(struct hid_device *hid)
627#define USB_DEVICE_ID_GTCO_1004 0x1004 623#define USB_DEVICE_ID_GTCO_1004 0x1004
628#define USB_DEVICE_ID_GTCO_1005 0x1005 624#define USB_DEVICE_ID_GTCO_1005 0x1005
629#define USB_DEVICE_ID_GTCO_1006 0x1006 625#define USB_DEVICE_ID_GTCO_1006 0x1006
626#define USB_DEVICE_ID_GTCO_8 0x0008
627#define USB_DEVICE_ID_GTCO_d 0x000d
630 628
631#define USB_VENDOR_ID_WACOM 0x056a 629#define USB_VENDOR_ID_WACOM 0x056a
632 630
@@ -791,6 +789,9 @@ void usbhid_init_reports(struct hid_device *hid)
791#define USB_VENDOR_ID_LOGITECH 0x046d 789#define USB_VENDOR_ID_LOGITECH 0x046d
792#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101 790#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101
793 791
792#define USB_VENDOR_ID_IMATION 0x0718
793#define USB_DEVICE_ID_DISC_STAKKA 0xd000
794
794/* 795/*
795 * Alphabetically sorted blacklist by quirk type. 796 * Alphabetically sorted blacklist by quirk type.
796 */ 797 */
@@ -875,6 +876,9 @@ static const struct hid_blacklist {
875 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE }, 876 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
876 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE }, 877 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
877 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE }, 878 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
879 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_8, HID_QUIRK_IGNORE },
880 { USB_VENDOR_ID_GTCO_IPANEL_2, USB_DEVICE_ID_GTCO_d, HID_QUIRK_IGNORE },
881 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
878 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE }, 882 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
879 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE }, 883 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
880 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE }, 884 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
@@ -951,7 +955,7 @@ static const struct hid_blacklist {
951 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD}, 955 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
952 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN }, 956 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
953 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN }, 957 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
954 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN }, 958 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
955 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN }, 959 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
956 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN }, 960 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
957 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN }, 961 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
@@ -1187,7 +1191,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1187 1191
1188 hid->version = le16_to_cpu(hdesc->bcdHID); 1192 hid->version = le16_to_cpu(hdesc->bcdHID);
1189 hid->country = hdesc->bCountryCode; 1193 hid->country = hdesc->bCountryCode;
1190 hid->dev = &dev->dev; 1194 hid->dev = &intf->dev;
1191 usbhid->intf = intf; 1195 usbhid->intf = intf;
1192 usbhid->ifnum = interface->desc.bInterfaceNumber; 1196 usbhid->ifnum = interface->desc.bInterfaceNumber;
1193 1197
@@ -1237,10 +1241,6 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1237 hid->hiddev_hid_event = hiddev_hid_event; 1241 hid->hiddev_hid_event = hiddev_hid_event;
1238 hid->hiddev_report_event = hiddev_report_event; 1242 hid->hiddev_report_event = hiddev_report_event;
1239#endif 1243#endif
1240#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
1241 hid->pb_fnmode = usbhid_pb_fnmode;
1242#endif
1243
1244 return hid; 1244 return hid;
1245 1245
1246fail: 1246fail:
@@ -1282,7 +1282,7 @@ static void hid_disconnect(struct usb_interface *intf)
1282 usb_free_urb(usbhid->urbctrl); 1282 usb_free_urb(usbhid->urbctrl);
1283 usb_free_urb(usbhid->urbout); 1283 usb_free_urb(usbhid->urbout);
1284 1284
1285 hid_free_buffers(to_usb_device(hid->dev), hid); 1285 hid_free_buffers(hid_to_usb_dev(hid), hid);
1286 hid_free_device(hid); 1286 hid_free_device(hid);
1287} 1287}
1288 1288
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index f8f660ee3fac..59ed65e7a621 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -33,6 +33,7 @@
33#include <linux/usb.h> 33#include <linux/usb.h>
34 34
35#include <linux/hid.h> 35#include <linux/hid.h>
36#include "usbhid.h"
36 37
37/* 38/*
38 * This table contains pointers to initializers. To add support for new 39 * This table contains pointers to initializers. To add support for new
@@ -70,8 +71,8 @@ static struct hid_ff_initializer inits[] = {
70int hid_ff_init(struct hid_device* hid) 71int hid_ff_init(struct hid_device* hid)
71{ 72{
72 struct hid_ff_initializer *init; 73 struct hid_ff_initializer *init;
73 int vendor = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idVendor); 74 int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor);
74 int product = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idProduct); 75 int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct);
75 76
76 for (init = inits; init->idVendor; init++) 77 for (init = inits; init->idVendor; init++)
77 if (init->idVendor == vendor && init->idProduct == product) 78 if (init->idVendor == vendor && init->idProduct == product)
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 114d6c9f64b1..a8b3d66cd498 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -384,7 +384,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
384 struct hiddev_list *list = file->private_data; 384 struct hiddev_list *list = file->private_data;
385 struct hiddev *hiddev = list->hiddev; 385 struct hiddev *hiddev = list->hiddev;
386 struct hid_device *hid = hiddev->hid; 386 struct hid_device *hid = hiddev->hid;
387 struct usb_device *dev = to_usb_device(hid->dev); 387 struct usb_device *dev = hid_to_usb_dev(hid);
388 struct hiddev_collection_info cinfo; 388 struct hiddev_collection_info cinfo;
389 struct hiddev_report_info rinfo; 389 struct hiddev_report_info rinfo;
390 struct hiddev_field_info finfo; 390 struct hiddev_field_info finfo;
diff --git a/drivers/usb/input/usbhid.h b/drivers/usb/input/usbhid.h
index 830107e5251f..0023f96d4294 100644
--- a/drivers/usb/input/usbhid.h
+++ b/drivers/usb/input/usbhid.h
@@ -80,5 +80,8 @@ struct usbhid_device {
80 80
81}; 81};
82 82
83#define hid_to_usb_dev(hid_dev) \
84 container_of(hid_dev->dev->parent, struct usb_device, dev)
85
83#endif 86#endif
84 87
diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c
index 7f3c57da9bc0..86e37a20f8e5 100644
--- a/drivers/usb/input/usbtouchscreen.c
+++ b/drivers/usb/input/usbtouchscreen.c
@@ -66,7 +66,7 @@ struct usbtouch_device_info {
66 66
67 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len); 67 void (*process_pkt) (struct usbtouch_usb *usbtouch, unsigned char *pkt, int len);
68 int (*get_pkt_len) (unsigned char *pkt, int len); 68 int (*get_pkt_len) (unsigned char *pkt, int len);
69 int (*read_data) (unsigned char *pkt, int *x, int *y, int *touch, int *press); 69 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
70 int (*init) (struct usbtouch_usb *usbtouch); 70 int (*init) (struct usbtouch_usb *usbtouch);
71}; 71};
72 72
@@ -85,6 +85,9 @@ struct usbtouch_usb {
85 struct usbtouch_device_info *type; 85 struct usbtouch_device_info *type;
86 char name[128]; 86 char name[128];
87 char phys[64]; 87 char phys[64];
88
89 int x, y;
90 int touch, press;
88}; 91};
89 92
90 93
@@ -161,14 +164,14 @@ static struct usb_device_id usbtouch_devices[] = {
161#define EGALAX_PKT_TYPE_REPT 0x80 164#define EGALAX_PKT_TYPE_REPT 0x80
162#define EGALAX_PKT_TYPE_DIAG 0x0A 165#define EGALAX_PKT_TYPE_DIAG 0x0A
163 166
164static int egalax_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 167static int egalax_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
165{ 168{
166 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT) 169 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
167 return 0; 170 return 0;
168 171
169 *x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F); 172 dev->x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
170 *y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F); 173 dev->y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
171 *touch = pkt[0] & 0x01; 174 dev->touch = pkt[0] & 0x01;
172 175
173 return 1; 176 return 1;
174} 177}
@@ -195,11 +198,11 @@ static int egalax_get_pkt_len(unsigned char *buf, int len)
195 * PanJit Part 198 * PanJit Part
196 */ 199 */
197#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT 200#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
198static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 201static int panjit_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
199{ 202{
200 *x = ((pkt[2] & 0x0F) << 8) | pkt[1]; 203 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1];
201 *y = ((pkt[4] & 0x0F) << 8) | pkt[3]; 204 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3];
202 *touch = pkt[0] & 0x01; 205 dev->touch = pkt[0] & 0x01;
203 206
204 return 1; 207 return 1;
205} 208}
@@ -215,11 +218,11 @@ static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
215#define MTOUCHUSB_RESET 7 218#define MTOUCHUSB_RESET 7
216#define MTOUCHUSB_REQ_CTRLLR_ID 10 219#define MTOUCHUSB_REQ_CTRLLR_ID 10
217 220
218static int mtouch_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 221static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
219{ 222{
220 *x = (pkt[8] << 8) | pkt[7]; 223 dev->x = (pkt[8] << 8) | pkt[7];
221 *y = (pkt[10] << 8) | pkt[9]; 224 dev->y = (pkt[10] << 8) | pkt[9];
222 *touch = (pkt[2] & 0x40) ? 1 : 0; 225 dev->touch = (pkt[2] & 0x40) ? 1 : 0;
223 226
224 return 1; 227 return 1;
225} 228}
@@ -260,14 +263,32 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
260 * ITM Part 263 * ITM Part
261 */ 264 */
262#ifdef CONFIG_USB_TOUCHSCREEN_ITM 265#ifdef CONFIG_USB_TOUCHSCREEN_ITM
263static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 266static int itm_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
264{ 267{
265 *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F); 268 int touch;
266 *y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F); 269 /*
267 *press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F); 270 * ITM devices report invalid x/y data if not touched.
268 *touch = ~pkt[7] & 0x20; 271 * if the screen was touched before but is not touched any more
272 * report touch as 0 with the last valid x/y data once. then stop
273 * reporting data until touched again.
274 */
275 dev->press = ((pkt[2] & 0x01) << 7) | (pkt[5] & 0x7F);
276
277 touch = ~pkt[7] & 0x20;
278 if (!touch) {
279 if (dev->touch) {
280 dev->touch = 0;
281 return 1;
282 }
269 283
270 return *touch; 284 return 0;
285 }
286
287 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
288 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
289 dev->touch = touch;
290
291 return 1;
271} 292}
272#endif 293#endif
273 294
@@ -276,7 +297,7 @@ static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *pr
276 * eTurboTouch part 297 * eTurboTouch part
277 */ 298 */
278#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO 299#ifdef CONFIG_USB_TOUCHSCREEN_ETURBO
279static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 300static int eturbo_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
280{ 301{
281 unsigned int shift; 302 unsigned int shift;
282 303
@@ -285,9 +306,9 @@ static int eturbo_read_data(unsigned char *pkt, int *x, int *y, int *touch, int
285 return 0; 306 return 0;
286 307
287 shift = (6 - (pkt[0] & 0x03)); 308 shift = (6 - (pkt[0] & 0x03));
288 *x = ((pkt[3] << 7) | pkt[4]) >> shift; 309 dev->x = ((pkt[3] << 7) | pkt[4]) >> shift;
289 *y = ((pkt[1] << 7) | pkt[2]) >> shift; 310 dev->y = ((pkt[1] << 7) | pkt[2]) >> shift;
290 *touch = (pkt[0] & 0x10) ? 1 : 0; 311 dev->touch = (pkt[0] & 0x10) ? 1 : 0;
291 312
292 return 1; 313 return 1;
293} 314}
@@ -307,14 +328,14 @@ static int eturbo_get_pkt_len(unsigned char *buf, int len)
307 * Gunze part 328 * Gunze part
308 */ 329 */
309#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE 330#ifdef CONFIG_USB_TOUCHSCREEN_GUNZE
310static int gunze_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 331static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
311{ 332{
312 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80)) 333 if (!(pkt[0] & 0x80) || ((pkt[1] | pkt[2] | pkt[3]) & 0x80))
313 return 0; 334 return 0;
314 335
315 *x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F); 336 dev->x = ((pkt[0] & 0x1F) << 7) | (pkt[2] & 0x7F);
316 *y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F); 337 dev->y = ((pkt[1] & 0x1F) << 7) | (pkt[3] & 0x7F);
317 *touch = pkt[0] & 0x20; 338 dev->touch = pkt[0] & 0x20;
318 339
319 return 1; 340 return 1;
320} 341}
@@ -383,11 +404,11 @@ static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
383} 404}
384 405
385 406
386static int dmc_tsc10_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press) 407static int dmc_tsc10_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
387{ 408{
388 *x = ((pkt[2] & 0x03) << 8) | pkt[1]; 409 dev->x = ((pkt[2] & 0x03) << 8) | pkt[1];
389 *y = ((pkt[4] & 0x03) << 8) | pkt[3]; 410 dev->y = ((pkt[4] & 0x03) << 8) | pkt[3];
390 *touch = pkt[0] & 0x01; 411 dev->touch = pkt[0] & 0x01;
391 412
392 return 1; 413 return 1;
393} 414}
@@ -492,23 +513,22 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
492static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch, 513static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
493 unsigned char *pkt, int len) 514 unsigned char *pkt, int len)
494{ 515{
495 int x, y, touch, press;
496 struct usbtouch_device_info *type = usbtouch->type; 516 struct usbtouch_device_info *type = usbtouch->type;
497 517
498 if (!type->read_data(pkt, &x, &y, &touch, &press)) 518 if (!type->read_data(usbtouch, pkt))
499 return; 519 return;
500 520
501 input_report_key(usbtouch->input, BTN_TOUCH, touch); 521 input_report_key(usbtouch->input, BTN_TOUCH, usbtouch->touch);
502 522
503 if (swap_xy) { 523 if (swap_xy) {
504 input_report_abs(usbtouch->input, ABS_X, y); 524 input_report_abs(usbtouch->input, ABS_X, usbtouch->y);
505 input_report_abs(usbtouch->input, ABS_Y, x); 525 input_report_abs(usbtouch->input, ABS_Y, usbtouch->x);
506 } else { 526 } else {
507 input_report_abs(usbtouch->input, ABS_X, x); 527 input_report_abs(usbtouch->input, ABS_X, usbtouch->x);
508 input_report_abs(usbtouch->input, ABS_Y, y); 528 input_report_abs(usbtouch->input, ABS_Y, usbtouch->y);
509 } 529 }
510 if (type->max_press) 530 if (type->max_press)
511 input_report_abs(usbtouch->input, ABS_PRESSURE, press); 531 input_report_abs(usbtouch->input, ABS_PRESSURE, usbtouch->press);
512 input_sync(usbtouch->input); 532 input_sync(usbtouch->input);
513} 533}
514 534
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index f538013965b0..896449f0cf85 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -898,7 +898,7 @@ static int ax88772_link_reset(struct usbnet *dev)
898 898
899static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 899static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
900{ 900{
901 int ret; 901 int ret, embd_phy;
902 void *buf; 902 void *buf;
903 u16 rx_ctl; 903 u16 rx_ctl;
904 struct asix_data *data = (struct asix_data *)&dev->data; 904 struct asix_data *data = (struct asix_data *)&dev->data;
@@ -919,13 +919,15 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
919 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0) 919 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5)) < 0)
920 goto out2; 920 goto out2;
921 921
922 /* 0x10 is the phy id of the embedded 10/100 ethernet phy */
923 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
922 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 924 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
923 1, 0, 0, buf)) < 0) { 925 embd_phy, 0, 0, buf)) < 0) {
924 dbg("Select PHY #1 failed: %d", ret); 926 dbg("Select PHY #1 failed: %d", ret);
925 goto out2; 927 goto out2;
926 } 928 }
927 929
928 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD)) < 0) 930 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL)) < 0)
929 goto out2; 931 goto out2;
930 932
931 msleep(150); 933 msleep(150);
@@ -933,8 +935,14 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
933 goto out2; 935 goto out2;
934 936
935 msleep(150); 937 msleep(150);
936 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0) 938 if (embd_phy) {
937 goto out2; 939 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL)) < 0)
940 goto out2;
941 }
942 else {
943 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRTE)) < 0)
944 goto out2;
945 }
938 946
939 msleep(150); 947 msleep(150);
940 rx_ctl = asix_read_rx_ctl(dev); 948 rx_ctl = asix_read_rx_ctl(dev);
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c
index ea5f44de3de2..a322a16d9cf8 100644
--- a/drivers/usb/net/rndis_host.c
+++ b/drivers/usb/net/rndis_host.c
@@ -379,6 +379,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
379{ 379{
380 int retval; 380 int retval;
381 struct net_device *net = dev->net; 381 struct net_device *net = dev->net;
382 struct cdc_state *info = (void *) &dev->data;
382 union { 383 union {
383 void *buf; 384 void *buf;
384 struct rndis_msg_hdr *header; 385 struct rndis_msg_hdr *header;
@@ -397,7 +398,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
397 return -ENOMEM; 398 return -ENOMEM;
398 retval = usbnet_generic_cdc_bind(dev, intf); 399 retval = usbnet_generic_cdc_bind(dev, intf);
399 if (retval < 0) 400 if (retval < 0)
400 goto done; 401 goto fail;
401 402
402 net->hard_header_len += sizeof (struct rndis_data_hdr); 403 net->hard_header_len += sizeof (struct rndis_data_hdr);
403 404
@@ -412,10 +413,7 @@ static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
412 if (unlikely(retval < 0)) { 413 if (unlikely(retval < 0)) {
413 /* it might not even be an RNDIS device!! */ 414 /* it might not even be an RNDIS device!! */
414 dev_err(&intf->dev, "RNDIS init failed, %d\n", retval); 415 dev_err(&intf->dev, "RNDIS init failed, %d\n", retval);
415fail: 416 goto fail_and_release;
416 usb_driver_release_interface(driver_of(intf),
417 ((struct cdc_state *)&(dev->data))->data);
418 goto done;
419 } 417 }
420 dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size); 418 dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size);
421 /* REVISIT: peripheral "alignment" request is ignored ... */ 419 /* REVISIT: peripheral "alignment" request is ignored ... */
@@ -431,7 +429,7 @@ fail:
431 retval = rndis_command(dev, u.header); 429 retval = rndis_command(dev, u.header);
432 if (unlikely(retval < 0)) { 430 if (unlikely(retval < 0)) {
433 dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval); 431 dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval);
434 goto fail; 432 goto fail_and_release;
435 } 433 }
436 tmp = le32_to_cpu(u.get_c->offset); 434 tmp = le32_to_cpu(u.get_c->offset);
437 if (unlikely((tmp + 8) > (1024 - ETH_ALEN) 435 if (unlikely((tmp + 8) > (1024 - ETH_ALEN)
@@ -439,7 +437,7 @@ fail:
439 dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n", 437 dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n",
440 tmp, le32_to_cpu(u.get_c->len)); 438 tmp, le32_to_cpu(u.get_c->len));
441 retval = -EDOM; 439 retval = -EDOM;
442 goto fail; 440 goto fail_and_release;
443 } 441 }
444 memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN); 442 memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN);
445 443
@@ -455,11 +453,18 @@ fail:
455 retval = rndis_command(dev, u.header); 453 retval = rndis_command(dev, u.header);
456 if (unlikely(retval < 0)) { 454 if (unlikely(retval < 0)) {
457 dev_err(&intf->dev, "rndis set packet filter, %d\n", retval); 455 dev_err(&intf->dev, "rndis set packet filter, %d\n", retval);
458 goto fail; 456 goto fail_and_release;
459 } 457 }
460 458
461 retval = 0; 459 retval = 0;
462done: 460
461 kfree(u.buf);
462 return retval;
463
464fail_and_release:
465 usb_set_intfdata(info->data, NULL);
466 usb_driver_release_interface(driver_of(intf), info->data);
467fail:
463 kfree(u.buf); 468 kfree(u.buf);
464 return retval; 469 return retval;
465} 470}
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index 31501c9361b9..2bebd63d5ed1 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -27,7 +27,7 @@ MODULE_DEVICE_TABLE(usb, id_table);
27static int funsoft_ioctl(struct usb_serial_port *port, struct file *file, 27static int funsoft_ioctl(struct usb_serial_port *port, struct file *file,
28 unsigned int cmd, unsigned long arg) 28 unsigned int cmd, unsigned long arg)
29{ 29{
30 struct termios t; 30 struct ktermios t;
31 31
32 dbg("%s - port %d, cmd 0x%04x", __FUNCTION__, port->number, cmd); 32 dbg("%s - port %d, cmd 0x%04x", __FUNCTION__, port->number, cmd);
33 33
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 5ca04e82ea19..0fed43a96871 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -78,6 +78,7 @@ static int option_send_setup(struct usb_serial_port *port);
78#define OPTION_PRODUCT_FUSION2 0x6300 78#define OPTION_PRODUCT_FUSION2 0x6300
79#define OPTION_PRODUCT_COBRA 0x6500 79#define OPTION_PRODUCT_COBRA 0x6500
80#define OPTION_PRODUCT_COBRA2 0x6600 80#define OPTION_PRODUCT_COBRA2 0x6600
81#define OPTION_PRODUCT_GTMAX36 0x6701
81#define HUAWEI_PRODUCT_E600 0x1001 82#define HUAWEI_PRODUCT_E600 0x1001
82#define HUAWEI_PRODUCT_E220 0x1003 83#define HUAWEI_PRODUCT_E220 0x1003
83#define AUDIOVOX_PRODUCT_AIRCARD 0x0112 84#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
@@ -90,6 +91,7 @@ static struct usb_device_id option_ids[] = {
90 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 93 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
94 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
93 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 95 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
94 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 96 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
95 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 97 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
@@ -104,6 +106,7 @@ static struct usb_device_id option_ids1[] = {
104 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) }, 106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
105 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 107 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 108 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
109 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_GTMAX36) },
107 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 110 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
108 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) }, 111 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
109 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 112 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index cddef3efba0a..b49f2a78189e 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -197,6 +197,13 @@ UNUSUAL_DEV( 0x0421, 0x047c, 0x0370, 0x0370,
197 US_SC_DEVICE, US_PR_DEVICE, NULL, 197 US_SC_DEVICE, US_PR_DEVICE, NULL,
198 US_FL_MAX_SECTORS_64 ), 198 US_FL_MAX_SECTORS_64 ),
199 199
200/* Reported by Manuel Osdoba <manuel.osdoba@tu-ilmenau.de> */
201UNUSUAL_DEV( 0x0421, 0x0492, 0x0452, 0x0452,
202 "Nokia",
203 "Nokia 6233",
204 US_SC_DEVICE, US_PR_DEVICE, NULL,
205 US_FL_MAX_SECTORS_64 ),
206
200/* Reported by Alex Corcoles <alex@corcoles.net> */ 207/* Reported by Alex Corcoles <alex@corcoles.net> */
201UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370, 208UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
202 "Nokia", 209 "Nokia",
@@ -254,6 +261,18 @@ UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
254 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0), 261 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
255#endif 262#endif
256 263
264/*
265 * This virtual floppy is found in Sun equipment (x4600, x4200m2, etc.)
266 * Reported by Pete Zaitcev <zaitcev@redhat.com>
267 * This device chokes on both version of MODE SENSE which we have, so
268 * use_10_for_ms is not effective, and we use US_FL_NO_WP_DETECT.
269 */
270UNUSUAL_DEV( 0x046b, 0xff40, 0x0100, 0x0100,
271 "AMI",
272 "Virtual Floppy",
273 US_SC_DEVICE, US_PR_DEVICE, NULL,
274 US_FL_NO_WP_DETECT),
275
257/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 276/* Patch submitted by Philipp Friedrich <philipp@void.at> */
258UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 277UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100,
259 "Kyocera", 278 "Kyocera",