aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ata/Kconfig10
-rw-r--r--drivers/ata/ata_piix.c2
-rw-r--r--drivers/ata/libata-core.c74
-rw-r--r--drivers/ata/libata-eh.c96
-rw-r--r--drivers/ata/libata-sff.c288
-rw-r--r--drivers/ata/pata_hpt3x3.c93
-rw-r--r--drivers/ata/pata_mpc52xx.c18
-rw-r--r--drivers/ata/pata_scc.c54
-rw-r--r--drivers/ata/pata_sis.c3
-rw-r--r--drivers/ata/sata_mv.c887
-rw-r--r--drivers/ata/sata_nv.c2
-rw-r--r--drivers/ata/sata_promise.c41
-rw-r--r--drivers/ata/sata_sis.c2
-rw-r--r--drivers/ata/sata_uli.c2
-rw-r--r--drivers/ata/sata_via.c2
-rw-r--r--drivers/base/attribute_container.c1
-rw-r--r--drivers/base/base.h2
-rw-r--r--drivers/base/bus.c24
-rw-r--r--drivers/base/class.c46
-rw-r--r--drivers/base/core.c58
-rw-r--r--drivers/base/dd.c21
-rw-r--r--drivers/base/devres.c2
-rw-r--r--drivers/base/firmware_class.c6
-rw-r--r--drivers/base/power/main.c44
-rw-r--r--drivers/base/power/power.h4
-rw-r--r--drivers/base/power/resume.c23
-rw-r--r--drivers/base/power/runtime.c12
-rw-r--r--drivers/base/power/suspend.c72
-rw-r--r--drivers/base/sys.c24
-rw-r--r--drivers/block/pktcdvd.c3
-rw-r--r--drivers/bluetooth/hci_usb.c88
-rw-r--r--drivers/bluetooth/hci_usb.h5
-rw-r--r--drivers/bluetooth/hci_vhci.c6
-rw-r--r--drivers/char/Kconfig2
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c10
-rw-r--r--drivers/char/vr41xx_giu.c132
-rw-r--r--drivers/cpufreq/cpufreq_stats.c3
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c2
-rw-r--r--drivers/cpufreq/freq_table.c1
-rw-r--r--drivers/firmware/Kconfig9
-rw-r--r--drivers/firmware/Makefile1
-rw-r--r--drivers/firmware/dcdbas.c10
-rw-r--r--drivers/firmware/dcdbas.h3
-rw-r--r--drivers/firmware/dell_rbu.c31
-rw-r--r--drivers/firmware/dmi-id.c222
-rw-r--r--drivers/firmware/dmi_scan.c73
-rw-r--r--drivers/firmware/edd.c2
-rw-r--r--drivers/firmware/efivars.c6
-rw-r--r--drivers/i2c/algos/Kconfig4
-rw-r--r--drivers/i2c/busses/Kconfig31
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-gpio.c12
-rw-r--r--drivers/i2c/busses/i2c-i801.c249
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c3
-rw-r--r--drivers/i2c/busses/i2c-mpc.c26
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c3
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c44
-rw-r--r--drivers/i2c/busses/i2c-piix4.c4
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c653
-rw-r--r--drivers/i2c/busses/i2c-powermac.c3
-rw-r--r--drivers/i2c/busses/i2c-pxa.c9
-rw-r--r--drivers/i2c/busses/i2c-rpx.c101
-rw-r--r--drivers/i2c/busses/i2c-savage4.c21
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c27
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c330
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c16
-rw-r--r--drivers/i2c/chips/Kconfig35
-rw-r--r--drivers/i2c/chips/Makefile2
-rw-r--r--drivers/i2c/chips/ds1682.c259
-rw-r--r--drivers/i2c/chips/eeprom.c10
-rw-r--r--drivers/i2c/chips/max6875.c7
-rw-r--r--drivers/i2c/chips/tsl2550.c460
-rw-r--r--drivers/i2c/i2c-core.c25
-rw-r--r--drivers/i2c/i2c-dev.c9
-rw-r--r--drivers/ide/legacy/hd.c73
-rw-r--r--drivers/infiniband/core/sysfs.c1
-rw-r--r--drivers/input/mouse/psmouse.h1
-rw-r--r--drivers/macintosh/windfarm_core.c2
-rw-r--r--drivers/macintosh/windfarm_smu_sat.c28
-rw-r--r--drivers/misc/asus-laptop.c3
-rw-r--r--drivers/misc/msi-laptop.c44
-rw-r--r--drivers/net/3c523.c2
-rw-r--r--drivers/net/7990.c4
-rw-r--r--drivers/net/8139too.c2
-rw-r--r--drivers/net/Kconfig23
-rw-r--r--drivers/net/Makefile1
-rw-r--r--drivers/net/a2065.c4
-rw-r--r--drivers/net/ariadne.c2
-rw-r--r--drivers/net/arm/ep93xx_eth.c2
-rw-r--r--drivers/net/au1000_eth.c4
-rw-r--r--drivers/net/bnx2.c503
-rw-r--r--drivers/net/bnx2.h66
-rw-r--r--drivers/net/dl2k.c4
-rw-r--r--drivers/net/dm9000.c17
-rw-r--r--drivers/net/dummy.c82
-rw-r--r--drivers/net/eepro100.c2
-rw-r--r--drivers/net/epic100.c2
-rw-r--r--drivers/net/fealnx.c4
-rw-r--r--drivers/net/fec.c2
-rw-r--r--drivers/net/hamachi.c4
-rw-r--r--drivers/net/ibmveth.c2
-rw-r--r--drivers/net/ifb.c78
-rw-r--r--drivers/net/irda/kingsun-sir.c4
-rw-r--r--drivers/net/irda/vlsi_ir.c27
-rw-r--r--drivers/net/irda/vlsi_ir.h2
-rw-r--r--drivers/net/ixp2000/ixpdev.c2
-rw-r--r--drivers/net/lance.c4
-rw-r--r--drivers/net/natsemi.c4
-rw-r--r--drivers/net/ni52.c2
-rw-r--r--drivers/net/ni65.c4
-rw-r--r--drivers/net/pci-skeleton.c2
-rw-r--r--drivers/net/pcnet32.c4
-rw-r--r--drivers/net/pppol2tp.c2486
-rw-r--r--drivers/net/saa9730.c4
-rw-r--r--drivers/net/sgiseeq.c2
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/starfire.c2
-rw-r--r--drivers/net/sun3_82586.c2
-rw-r--r--drivers/net/sun3lance.c5
-rw-r--r--drivers/net/sunbmac.c2
-rw-r--r--drivers/net/sundance.c2
-rw-r--r--drivers/net/sunlance.c4
-rw-r--r--drivers/net/sunqe.c4
-rw-r--r--drivers/net/tg3.c140
-rw-r--r--drivers/net/tg3.h9
-rw-r--r--drivers/net/tulip/interrupt.c8
-rw-r--r--drivers/net/tulip/winbond-840.c2
-rw-r--r--drivers/net/tulip/xircom_cb.c2
-rw-r--r--drivers/net/tulip/xircom_tulip_cb.c4
-rw-r--r--drivers/net/tun.c15
-rw-r--r--drivers/net/typhoon.c2
-rw-r--r--drivers/net/usb/catc.c2
-rw-r--r--drivers/net/usb/kaweth.c2
-rw-r--r--drivers/net/via-rhine.c4
-rw-r--r--drivers/net/wireless/wl3501_cs.c2
-rw-r--r--drivers/net/yellowfin.c2
-rw-r--r--drivers/parisc/pdc_stable.c4
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c7
-rw-r--r--drivers/pci/pci-sysfs.c22
-rw-r--r--drivers/pci/probe.c2
-rw-r--r--drivers/pcmcia/socket_sysfs.c10
-rw-r--r--drivers/rapidio/rio-sysfs.c7
-rw-r--r--drivers/rtc/rtc-ds1553.c11
-rw-r--r--drivers/rtc/rtc-ds1742.c11
-rw-r--r--drivers/rtc/rtc-vr41xx.c186
-rw-r--r--drivers/rtc/rtc-x1205.c5
-rw-r--r--drivers/s390/cio/chp.c12
-rw-r--r--drivers/s390/net/qeth_sys.c2
-rw-r--r--drivers/scsi/arcmsr/arcmsr_attr.c18
-rw-r--r--drivers/scsi/ipr.c18
-rw-r--r--drivers/scsi/libsas/sas_expander.c17
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c14
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c56
-rw-r--r--drivers/serial/Kconfig48
-rw-r--r--drivers/serial/bfin_5xx.c182
-rw-r--r--drivers/serial/vr41xx_siu.c143
-rw-r--r--drivers/spi/at25.c7
-rw-r--r--drivers/tc/zs.c22
-rw-r--r--drivers/usb/core/hub.c5
-rw-r--r--drivers/video/aty/radeon_base.c10
-rw-r--r--drivers/video/backlight/backlight.c2
-rw-r--r--drivers/video/backlight/lcd.c2
-rw-r--r--drivers/video/console/Kconfig2
-rw-r--r--drivers/video/matrox/matroxfb_crtc2.h2
-rw-r--r--drivers/w1/slaves/w1_ds2433.c11
-rw-r--r--drivers/w1/slaves/w1_therm.c8
-rw-r--r--drivers/w1/w1.c14
-rw-r--r--drivers/zorro/zorro-sysfs.c6
169 files changed, 7304 insertions, 2158 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 4ad8675f5a16..d8046a113c37 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -309,7 +309,7 @@ config PATA_HPT3X2N
309 If unsure, say N. 309 If unsure, say N.
310 310
311config PATA_HPT3X3 311config PATA_HPT3X3
312 tristate "HPT 343/363 PATA support (Experimental)" 312 tristate "HPT 343/363 PATA support"
313 depends on PCI 313 depends on PCI
314 help 314 help
315 This option enables support for the HPT 343/363 315 This option enables support for the HPT 343/363
@@ -317,6 +317,14 @@ config PATA_HPT3X3
317 317
318 If unsure, say N. 318 If unsure, say N.
319 319
320config PATA_HPT3X3_DMA
321 bool "HPT 343/363 DMA support (Experimental)"
322 depends on PATA_HPT3X3
323 help
324 This option enables DMA support for the HPT343/363
325 controllers. Enable with care as there are still some
326 problems with DMA on this chipset.
327
320config PATA_ISAPNP 328config PATA_ISAPNP
321 tristate "ISA Plug and Play PATA support (Experimental)" 329 tristate "ISA Plug and Play PATA support (Experimental)"
322 depends on EXPERIMENTAL && ISAPNP 330 depends on EXPERIMENTAL && ISAPNP
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 2610db75f984..d9fa329fd157 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -414,7 +414,7 @@ static const struct piix_map_db ich6m_map_db = {
414 */ 414 */
415 .map = { 415 .map = {
416 /* PM PS SM SS MAP */ 416 /* PM PS SM SS MAP */
417 { P0, P2, RV, RV }, /* 00b */ 417 { P0, P2, NA, NA }, /* 00b */
418 { IDE, IDE, P1, P3 }, /* 01b */ 418 { IDE, IDE, P1, P3 }, /* 01b */
419 { P0, P2, IDE, IDE }, /* 10b */ 419 { P0, P2, IDE, IDE }, /* 10b */
420 { RV, RV, RV, RV }, 420 { RV, RV, RV, RV },
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 5b25311ba885..88e2dd0983b5 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -71,6 +71,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
71 u16 heads, u16 sectors); 71 u16 heads, u16 sectors);
72static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 72static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
73static void ata_dev_xfermask(struct ata_device *dev); 73static void ata_dev_xfermask(struct ata_device *dev);
74static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
74 75
75unsigned int ata_print_id = 1; 76unsigned int ata_print_id = 1;
76static struct workqueue_struct *ata_wq; 77static struct workqueue_struct *ata_wq;
@@ -1283,18 +1284,11 @@ static unsigned int ata_id_xfermask(const u16 *id)
1283void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data, 1284void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
1284 unsigned long delay) 1285 unsigned long delay)
1285{ 1286{
1286 int rc;
1287
1288 if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
1289 return;
1290
1291 PREPARE_DELAYED_WORK(&ap->port_task, fn); 1287 PREPARE_DELAYED_WORK(&ap->port_task, fn);
1292 ap->port_task_data = data; 1288 ap->port_task_data = data;
1293 1289
1294 rc = queue_delayed_work(ata_wq, &ap->port_task, delay); 1290 /* may fail if ata_port_flush_task() in progress */
1295 1291 queue_delayed_work(ata_wq, &ap->port_task, delay);
1296 /* rc == 0 means that another user is using port task */
1297 WARN_ON(rc == 0);
1298} 1292}
1299 1293
1300/** 1294/**
@@ -1309,32 +1303,9 @@ void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
1309 */ 1303 */
1310void ata_port_flush_task(struct ata_port *ap) 1304void ata_port_flush_task(struct ata_port *ap)
1311{ 1305{
1312 unsigned long flags;
1313
1314 DPRINTK("ENTER\n"); 1306 DPRINTK("ENTER\n");
1315 1307
1316 spin_lock_irqsave(ap->lock, flags); 1308 cancel_rearming_delayed_work(&ap->port_task);
1317 ap->pflags |= ATA_PFLAG_FLUSH_PORT_TASK;
1318 spin_unlock_irqrestore(ap->lock, flags);
1319
1320 DPRINTK("flush #1\n");
1321 cancel_work_sync(&ap->port_task.work); /* akpm: seems unneeded */
1322
1323 /*
1324 * At this point, if a task is running, it's guaranteed to see
1325 * the FLUSH flag; thus, it will never queue pio tasks again.
1326 * Cancel and flush.
1327 */
1328 if (!cancel_delayed_work(&ap->port_task)) {
1329 if (ata_msg_ctl(ap))
1330 ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
1331 __FUNCTION__);
1332 cancel_work_sync(&ap->port_task.work);
1333 }
1334
1335 spin_lock_irqsave(ap->lock, flags);
1336 ap->pflags &= ~ATA_PFLAG_FLUSH_PORT_TASK;
1337 spin_unlock_irqrestore(ap->lock, flags);
1338 1309
1339 if (ata_msg_ctl(ap)) 1310 if (ata_msg_ctl(ap))
1340 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__); 1311 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__);
@@ -1814,7 +1785,7 @@ static void ata_dev_config_ncq(struct ata_device *dev,
1814 desc[0] = '\0'; 1785 desc[0] = '\0';
1815 return; 1786 return;
1816 } 1787 }
1817 if (ata_device_blacklisted(dev) & ATA_HORKAGE_NONCQ) { 1788 if (dev->horkage & ATA_HORKAGE_NONCQ) {
1818 snprintf(desc, desc_sz, "NCQ (not used)"); 1789 snprintf(desc, desc_sz, "NCQ (not used)");
1819 return; 1790 return;
1820 } 1791 }
@@ -1863,6 +1834,9 @@ int ata_dev_configure(struct ata_device *dev)
1863 if (ata_msg_probe(ap)) 1834 if (ata_msg_probe(ap))
1864 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__); 1835 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
1865 1836
1837 /* set horkage */
1838 dev->horkage |= ata_dev_blacklisted(dev);
1839
1866 /* let ACPI work its magic */ 1840 /* let ACPI work its magic */
1867 rc = ata_acpi_on_devcfg(dev); 1841 rc = ata_acpi_on_devcfg(dev);
1868 if (rc) 1842 if (rc)
@@ -2038,7 +2012,7 @@ int ata_dev_configure(struct ata_device *dev)
2038 dev->max_sectors = ATA_MAX_SECTORS; 2012 dev->max_sectors = ATA_MAX_SECTORS;
2039 } 2013 }
2040 2014
2041 if (ata_device_blacklisted(dev) & ATA_HORKAGE_MAX_SEC_128) 2015 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128)
2042 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, 2016 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
2043 dev->max_sectors); 2017 dev->max_sectors);
2044 2018
@@ -3190,9 +3164,6 @@ void ata_bus_reset(struct ata_port *ap)
3190 if ((slave_possible) && (err != 0x81)) 3164 if ((slave_possible) && (err != 0x81))
3191 ap->device[1].class = ata_dev_try_classify(ap, 1, &err); 3165 ap->device[1].class = ata_dev_try_classify(ap, 1, &err);
3192 3166
3193 /* re-enable interrupts */
3194 ap->ops->irq_on(ap);
3195
3196 /* is double-select really necessary? */ 3167 /* is double-select really necessary? */
3197 if (ap->device[1].class != ATA_DEV_NONE) 3168 if (ap->device[1].class != ATA_DEV_NONE)
3198 ap->ops->dev_select(ap, 1); 3169 ap->ops->dev_select(ap, 1);
@@ -3577,10 +3548,6 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
3577 if (sata_scr_read(ap, SCR_ERROR, &serror) == 0) 3548 if (sata_scr_read(ap, SCR_ERROR, &serror) == 0)
3578 sata_scr_write(ap, SCR_ERROR, serror); 3549 sata_scr_write(ap, SCR_ERROR, serror);
3579 3550
3580 /* re-enable interrupts */
3581 if (!ap->ops->error_handler)
3582 ap->ops->irq_on(ap);
3583
3584 /* is double-select really necessary? */ 3551 /* is double-select really necessary? */
3585 if (classes[0] != ATA_DEV_NONE) 3552 if (classes[0] != ATA_DEV_NONE)
3586 ap->ops->dev_select(ap, 1); 3553 ap->ops->dev_select(ap, 1);
@@ -3770,6 +3737,8 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3770 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA }, 3737 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA },
3771 { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA }, 3738 { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA },
3772 { "IOMEGA ZIP 250 ATAPI", NULL, ATA_HORKAGE_NODMA }, /* temporary fix */ 3739 { "IOMEGA ZIP 250 ATAPI", NULL, ATA_HORKAGE_NODMA }, /* temporary fix */
3740 { "IOMEGA ZIP 250 ATAPI Floppy",
3741 NULL, ATA_HORKAGE_NODMA },
3773 3742
3774 /* Weird ATAPI devices */ 3743 /* Weird ATAPI devices */
3775 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 }, 3744 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 },
@@ -3783,7 +3752,10 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3783 { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ }, 3752 { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ },
3784 /* NCQ is broken */ 3753 /* NCQ is broken */
3785 { "Maxtor 6L250S0", "BANC1G10", ATA_HORKAGE_NONCQ }, 3754 { "Maxtor 6L250S0", "BANC1G10", ATA_HORKAGE_NONCQ },
3755 { "Maxtor 6B200M0", "BANC1BM0", ATA_HORKAGE_NONCQ },
3786 { "Maxtor 6B200M0", "BANC1B10", ATA_HORKAGE_NONCQ }, 3756 { "Maxtor 6B200M0", "BANC1B10", ATA_HORKAGE_NONCQ },
3757 { "HITACHI HDS7250SASUN500G 0621KTAWSD", "K2AOAJ0AHITACHI",
3758 ATA_HORKAGE_NONCQ },
3787 /* NCQ hard hangs device under heavier load, needs hard power cycle */ 3759 /* NCQ hard hangs device under heavier load, needs hard power cycle */
3788 { "Maxtor 6B250S0", "BANC1B70", ATA_HORKAGE_NONCQ }, 3760 { "Maxtor 6B250S0", "BANC1B70", ATA_HORKAGE_NONCQ },
3789 /* Blacklist entries taken from Silicon Image 3124/3132 3761 /* Blacklist entries taken from Silicon Image 3124/3132
@@ -3796,6 +3768,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3796 { "HTS541612J9SA00", "SBDIC7JP", ATA_HORKAGE_NONCQ, }, 3768 { "HTS541612J9SA00", "SBDIC7JP", ATA_HORKAGE_NONCQ, },
3797 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, }, 3769 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
3798 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, 3770 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, },
3771 { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, },
3799 3772
3800 /* Devices with NCQ limits */ 3773 /* Devices with NCQ limits */
3801 3774
@@ -3803,7 +3776,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3803 { } 3776 { }
3804}; 3777};
3805 3778
3806unsigned long ata_device_blacklisted(const struct ata_device *dev) 3779static unsigned long ata_dev_blacklisted(const struct ata_device *dev)
3807{ 3780{
3808 unsigned char model_num[ATA_ID_PROD_LEN + 1]; 3781 unsigned char model_num[ATA_ID_PROD_LEN + 1];
3809 unsigned char model_rev[ATA_ID_FW_REV_LEN + 1]; 3782 unsigned char model_rev[ATA_ID_FW_REV_LEN + 1];
@@ -3833,7 +3806,7 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
3833 if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) && 3806 if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) &&
3834 (dev->flags & ATA_DFLAG_CDB_INTR)) 3807 (dev->flags & ATA_DFLAG_CDB_INTR))
3835 return 1; 3808 return 1;
3836 return (ata_device_blacklisted(dev) & ATA_HORKAGE_NODMA) ? 1 : 0; 3809 return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0;
3837} 3810}
3838 3811
3839/** 3812/**
@@ -6557,13 +6530,7 @@ void ata_port_detach(struct ata_port *ap)
6557 spin_unlock_irqrestore(ap->lock, flags); 6530 spin_unlock_irqrestore(ap->lock, flags);
6558 6531
6559 ata_port_wait_eh(ap); 6532 ata_port_wait_eh(ap);
6560 6533 cancel_rearming_delayed_work(&ap->hotplug_task);
6561 /* Flush hotplug task. The sequence is similar to
6562 * ata_port_flush_task().
6563 */
6564 cancel_work_sync(&ap->hotplug_task.work); /* akpm: why? */
6565 cancel_delayed_work(&ap->hotplug_task);
6566 cancel_work_sync(&ap->hotplug_task.work);
6567 6534
6568 skip_eh: 6535 skip_eh:
6569 /* remove the associated SCSI host */ 6536 /* remove the associated SCSI host */
@@ -6952,7 +6919,6 @@ EXPORT_SYMBOL_GPL(ata_host_resume);
6952EXPORT_SYMBOL_GPL(ata_id_string); 6919EXPORT_SYMBOL_GPL(ata_id_string);
6953EXPORT_SYMBOL_GPL(ata_id_c_string); 6920EXPORT_SYMBOL_GPL(ata_id_c_string);
6954EXPORT_SYMBOL_GPL(ata_id_to_dma_mode); 6921EXPORT_SYMBOL_GPL(ata_id_to_dma_mode);
6955EXPORT_SYMBOL_GPL(ata_device_blacklisted);
6956EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6922EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6957 6923
6958EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 6924EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
@@ -6961,9 +6927,9 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
6961 6927
6962#ifdef CONFIG_PCI 6928#ifdef CONFIG_PCI
6963EXPORT_SYMBOL_GPL(pci_test_config_bits); 6929EXPORT_SYMBOL_GPL(pci_test_config_bits);
6964EXPORT_SYMBOL_GPL(ata_pci_init_native_host); 6930EXPORT_SYMBOL_GPL(ata_pci_init_sff_host);
6965EXPORT_SYMBOL_GPL(ata_pci_init_bmdma); 6931EXPORT_SYMBOL_GPL(ata_pci_init_bmdma);
6966EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host); 6932EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host);
6967EXPORT_SYMBOL_GPL(ata_pci_init_one); 6933EXPORT_SYMBOL_GPL(ata_pci_init_one);
6968EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6934EXPORT_SYMBOL_GPL(ata_pci_remove_one);
6969#ifdef CONFIG_PM 6935#ifdef CONFIG_PM
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 9ee0a8c08d96..9aa62a0754f6 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1897,6 +1897,57 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
1897 return 1; 1897 return 1;
1898} 1898}
1899 1899
1900static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
1901{
1902 struct ata_port *ap = dev->ap;
1903 struct ata_eh_context *ehc = &ap->eh_context;
1904
1905 ehc->tries[dev->devno]--;
1906
1907 switch (err) {
1908 case -ENODEV:
1909 /* device missing or wrong IDENTIFY data, schedule probing */
1910 ehc->i.probe_mask |= (1 << dev->devno);
1911 case -EINVAL:
1912 /* give it just one more chance */
1913 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
1914 case -EIO:
1915 if (ehc->tries[dev->devno] == 1) {
1916 /* This is the last chance, better to slow
1917 * down than lose it.
1918 */
1919 sata_down_spd_limit(ap);
1920 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
1921 }
1922 }
1923
1924 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
1925 /* disable device if it has used up all its chances */
1926 ata_dev_disable(dev);
1927
1928 /* detach if offline */
1929 if (ata_port_offline(ap))
1930 ata_eh_detach_dev(dev);
1931
1932 /* probe if requested */
1933 if ((ehc->i.probe_mask & (1 << dev->devno)) &&
1934 !(ehc->did_probe_mask & (1 << dev->devno))) {
1935 ata_eh_detach_dev(dev);
1936 ata_dev_init(dev);
1937
1938 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
1939 ehc->did_probe_mask |= (1 << dev->devno);
1940 ehc->i.action |= ATA_EH_SOFTRESET;
1941 }
1942 } else {
1943 /* soft didn't work? be haaaaard */
1944 if (ehc->i.flags & ATA_EHI_DID_RESET)
1945 ehc->i.action |= ATA_EH_HARDRESET;
1946 else
1947 ehc->i.action |= ATA_EH_SOFTRESET;
1948 }
1949}
1950
1900/** 1951/**
1901 * ata_eh_recover - recover host port after error 1952 * ata_eh_recover - recover host port after error
1902 * @ap: host port to recover 1953 * @ap: host port to recover
@@ -1997,50 +2048,7 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1997 goto out; 2048 goto out;
1998 2049
1999 dev_fail: 2050 dev_fail:
2000 ehc->tries[dev->devno]--; 2051 ata_eh_handle_dev_fail(dev, rc);
2001
2002 switch (rc) {
2003 case -ENODEV:
2004 /* device missing or wrong IDENTIFY data, schedule probing */
2005 ehc->i.probe_mask |= (1 << dev->devno);
2006 case -EINVAL:
2007 /* give it just one more chance */
2008 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
2009 case -EIO:
2010 if (ehc->tries[dev->devno] == 1) {
2011 /* This is the last chance, better to slow
2012 * down than lose it.
2013 */
2014 sata_down_spd_limit(ap);
2015 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
2016 }
2017 }
2018
2019 if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
2020 /* disable device if it has used up all its chances */
2021 ata_dev_disable(dev);
2022
2023 /* detach if offline */
2024 if (ata_port_offline(ap))
2025 ata_eh_detach_dev(dev);
2026
2027 /* probe if requested */
2028 if ((ehc->i.probe_mask & (1 << dev->devno)) &&
2029 !(ehc->did_probe_mask & (1 << dev->devno))) {
2030 ata_eh_detach_dev(dev);
2031 ata_dev_init(dev);
2032
2033 ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
2034 ehc->did_probe_mask |= (1 << dev->devno);
2035 ehc->i.action |= ATA_EH_SOFTRESET;
2036 }
2037 } else {
2038 /* soft didn't work? be haaaaard */
2039 if (ehc->i.flags & ATA_EHI_DID_RESET)
2040 ehc->i.action |= ATA_EH_HARDRESET;
2041 else
2042 ehc->i.action |= ATA_EH_SOFTRESET;
2043 }
2044 2052
2045 if (ata_port_nr_enabled(ap)) { 2053 if (ata_port_nr_enabled(ap)) {
2046 ata_port_printk(ap, KERN_WARNING, "failed to recover some " 2054 ata_port_printk(ap, KERN_WARNING, "failed to recover some "
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index fa1c22c7b38f..ca7d2245d684 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -604,13 +604,17 @@ int ata_pci_init_bmdma(struct ata_host *host)
604} 604}
605 605
606/** 606/**
607 * ata_pci_init_native_host - acquire native ATA resources and init host 607 * ata_pci_init_sff_host - acquire native PCI ATA resources and init host
608 * @host: target ATA host 608 * @host: target ATA host
609 * 609 *
610 * Acquire native PCI ATA resources for @host and initialize the 610 * Acquire native PCI ATA resources for @host and initialize the
611 * first two ports of @host accordingly. Ports marked dummy are 611 * first two ports of @host accordingly. Ports marked dummy are
612 * skipped and allocation failure makes the port dummy. 612 * skipped and allocation failure makes the port dummy.
613 * 613 *
614 * Note that native PCI resources are valid even for legacy hosts
615 * as we fix up pdev resources array early in boot, so this
616 * function can be used for both native and legacy SFF hosts.
617 *
614 * LOCKING: 618 * LOCKING:
615 * Inherited from calling layer (may sleep). 619 * Inherited from calling layer (may sleep).
616 * 620 *
@@ -618,7 +622,7 @@ int ata_pci_init_bmdma(struct ata_host *host)
618 * 0 if at least one port is initialized, -ENODEV if no port is 622 * 0 if at least one port is initialized, -ENODEV if no port is
619 * available. 623 * available.
620 */ 624 */
621int ata_pci_init_native_host(struct ata_host *host) 625int ata_pci_init_sff_host(struct ata_host *host)
622{ 626{
623 struct device *gdev = host->dev; 627 struct device *gdev = host->dev;
624 struct pci_dev *pdev = to_pci_dev(gdev); 628 struct pci_dev *pdev = to_pci_dev(gdev);
@@ -673,7 +677,7 @@ int ata_pci_init_native_host(struct ata_host *host)
673} 677}
674 678
675/** 679/**
676 * ata_pci_prepare_native_host - helper to prepare native PCI ATA host 680 * ata_pci_prepare_sff_host - helper to prepare native PCI ATA host
677 * @pdev: target PCI device 681 * @pdev: target PCI device
678 * @ppi: array of port_info, must be enough for two ports 682 * @ppi: array of port_info, must be enough for two ports
679 * @r_host: out argument for the initialized ATA host 683 * @r_host: out argument for the initialized ATA host
@@ -687,9 +691,9 @@ int ata_pci_init_native_host(struct ata_host *host)
687 * RETURNS: 691 * RETURNS:
688 * 0 on success, -errno otherwise. 692 * 0 on success, -errno otherwise.
689 */ 693 */
690int ata_pci_prepare_native_host(struct pci_dev *pdev, 694int ata_pci_prepare_sff_host(struct pci_dev *pdev,
691 const struct ata_port_info * const * ppi, 695 const struct ata_port_info * const * ppi,
692 struct ata_host **r_host) 696 struct ata_host **r_host)
693{ 697{
694 struct ata_host *host; 698 struct ata_host *host;
695 int rc; 699 int rc;
@@ -705,7 +709,7 @@ int ata_pci_prepare_native_host(struct pci_dev *pdev,
705 goto err_out; 709 goto err_out;
706 } 710 }
707 711
708 rc = ata_pci_init_native_host(host); 712 rc = ata_pci_init_sff_host(host);
709 if (rc) 713 if (rc)
710 goto err_out; 714 goto err_out;
711 715
@@ -730,221 +734,6 @@ int ata_pci_prepare_native_host(struct pci_dev *pdev,
730 return rc; 734 return rc;
731} 735}
732 736
733struct ata_legacy_devres {
734 unsigned int mask;
735 unsigned long cmd_port[2];
736 void __iomem * cmd_addr[2];
737 void __iomem * ctl_addr[2];
738 unsigned int irq[2];
739 void * irq_dev_id[2];
740};
741
742static void ata_legacy_free_irqs(struct ata_legacy_devres *legacy_dr)
743{
744 int i;
745
746 for (i = 0; i < 2; i++) {
747 if (!legacy_dr->irq[i])
748 continue;
749
750 free_irq(legacy_dr->irq[i], legacy_dr->irq_dev_id[i]);
751 legacy_dr->irq[i] = 0;
752 legacy_dr->irq_dev_id[i] = NULL;
753 }
754}
755
756static void ata_legacy_release(struct device *gdev, void *res)
757{
758 struct ata_legacy_devres *this = res;
759 int i;
760
761 ata_legacy_free_irqs(this);
762
763 for (i = 0; i < 2; i++) {
764 if (this->cmd_addr[i])
765 ioport_unmap(this->cmd_addr[i]);
766 if (this->ctl_addr[i])
767 ioport_unmap(this->ctl_addr[i]);
768 if (this->cmd_port[i])
769 release_region(this->cmd_port[i], 8);
770 }
771}
772
773static int ata_init_legacy_port(struct ata_port *ap,
774 struct ata_legacy_devres *legacy_dr)
775{
776 struct ata_host *host = ap->host;
777 int port_no = ap->port_no;
778 unsigned long cmd_port, ctl_port;
779
780 if (port_no == 0) {
781 cmd_port = ATA_PRIMARY_CMD;
782 ctl_port = ATA_PRIMARY_CTL;
783 } else {
784 cmd_port = ATA_SECONDARY_CMD;
785 ctl_port = ATA_SECONDARY_CTL;
786 }
787
788 /* request cmd_port */
789 if (request_region(cmd_port, 8, "libata"))
790 legacy_dr->cmd_port[port_no] = cmd_port;
791 else {
792 dev_printk(KERN_WARNING, host->dev,
793 "0x%0lX IDE port busy\n", cmd_port);
794 return -EBUSY;
795 }
796
797 /* iomap cmd and ctl ports */
798 legacy_dr->cmd_addr[port_no] = ioport_map(cmd_port, 8);
799 legacy_dr->ctl_addr[port_no] = ioport_map(ctl_port, 1);
800 if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no]) {
801 dev_printk(KERN_WARNING, host->dev,
802 "failed to map cmd/ctl ports\n");
803 return -ENOMEM;
804 }
805
806 /* init IO addresses */
807 ap->ioaddr.cmd_addr = legacy_dr->cmd_addr[port_no];
808 ap->ioaddr.altstatus_addr = legacy_dr->ctl_addr[port_no];
809 ap->ioaddr.ctl_addr = legacy_dr->ctl_addr[port_no];
810 ata_std_ports(&ap->ioaddr);
811
812 return 0;
813}
814
815/**
816 * ata_init_legacy_host - acquire legacy ATA resources and init ATA host
817 * @host: target ATA host
818 * @was_busy: out parameter, indicates whether any port was busy
819 *
820 * Acquire legacy ATA resources for the first two ports of @host
821 * and initialize it accordingly. Ports marked dummy are skipped
822 * and resource acquistion failure makes the port dummy.
823 *
824 * LOCKING:
825 * Inherited from calling layer (may sleep).
826 *
827 * RETURNS:
828 * 0 if at least one port is initialized, -ENODEV if no port is
829 * available.
830 */
831static int ata_init_legacy_host(struct ata_host *host, int *was_busy)
832{
833 struct device *gdev = host->dev;
834 struct ata_legacy_devres *legacy_dr;
835 int i, rc;
836
837 if (!devres_open_group(gdev, NULL, GFP_KERNEL))
838 return -ENOMEM;
839
840 rc = -ENOMEM;
841 legacy_dr = devres_alloc(ata_legacy_release, sizeof(*legacy_dr),
842 GFP_KERNEL);
843 if (!legacy_dr)
844 goto err_out;
845 devres_add(gdev, legacy_dr);
846
847 for (i = 0; i < 2; i++) {
848 if (ata_port_is_dummy(host->ports[i]))
849 continue;
850
851 rc = ata_init_legacy_port(host->ports[i], legacy_dr);
852 if (rc == 0)
853 legacy_dr->mask |= 1 << i;
854 else {
855 if (rc == -EBUSY)
856 (*was_busy)++;
857 host->ports[i]->ops = &ata_dummy_port_ops;
858 }
859 }
860
861 if (!legacy_dr->mask) {
862 dev_printk(KERN_ERR, gdev, "no available legacy port\n");
863 return -ENODEV;
864 }
865
866 devres_remove_group(gdev, NULL);
867 return 0;
868
869 err_out:
870 devres_release_group(gdev, NULL);
871 return rc;
872}
873
874/**
875 * ata_request_legacy_irqs - request legacy ATA IRQs
876 * @host: target ATA host
877 * @handler: array of IRQ handlers
878 * @irq_flags: array of IRQ flags
879 * @dev_id: array of IRQ dev_ids
880 *
881 * Request legacy IRQs for non-dummy legacy ports in @host. All
882 * IRQ parameters are passed as array to allow ports to have
883 * separate IRQ handlers.
884 *
885 * LOCKING:
886 * Inherited from calling layer (may sleep).
887 *
888 * RETURNS:
889 * 0 on success, -errno otherwise.
890 */
891static int ata_request_legacy_irqs(struct ata_host *host,
892 irq_handler_t const *handler,
893 const unsigned int *irq_flags,
894 void * const *dev_id)
895{
896 struct device *gdev = host->dev;
897 struct ata_legacy_devres *legacy_dr;
898 int i, rc;
899
900 legacy_dr = devres_find(host->dev, ata_legacy_release, NULL, NULL);
901 BUG_ON(!legacy_dr);
902
903 for (i = 0; i < 2; i++) {
904 unsigned int irq;
905
906 /* FIXME: ATA_*_IRQ() should take generic device not pci_dev */
907 if (i == 0)
908 irq = ATA_PRIMARY_IRQ(to_pci_dev(gdev));
909 else
910 irq = ATA_SECONDARY_IRQ(to_pci_dev(gdev));
911
912 if (!(legacy_dr->mask & (1 << i)))
913 continue;
914
915 if (!handler[i]) {
916 dev_printk(KERN_ERR, gdev,
917 "NULL handler specified for port %d\n", i);
918 rc = -EINVAL;
919 goto err_out;
920 }
921
922 rc = request_irq(irq, handler[i], irq_flags[i], DRV_NAME,
923 dev_id[i]);
924 if (rc) {
925 dev_printk(KERN_ERR, gdev,
926 "irq %u request failed (errno=%d)\n", irq, rc);
927 goto err_out;
928 }
929
930 /* record irq allocation in legacy_dr */
931 legacy_dr->irq[i] = irq;
932 legacy_dr->irq_dev_id[i] = dev_id[i];
933
934 /* only used to print info */
935 if (i == 0)
936 host->irq = irq;
937 else
938 host->irq2 = irq;
939 }
940
941 return 0;
942
943 err_out:
944 ata_legacy_free_irqs(legacy_dr);
945 return rc;
946}
947
948/** 737/**
949 * ata_pci_init_one - Initialize/register PCI IDE host controller 738 * ata_pci_init_one - Initialize/register PCI IDE host controller
950 * @pdev: Controller to be initialized 739 * @pdev: Controller to be initialized
@@ -1029,35 +818,11 @@ int ata_pci_init_one(struct pci_dev *pdev,
1029#endif 818#endif
1030 } 819 }
1031 820
1032 /* alloc and init host */ 821 /* prepare host */
1033 host = ata_host_alloc_pinfo(dev, ppi, 2); 822 rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
1034 if (!host) { 823 if (rc)
1035 dev_printk(KERN_ERR, &pdev->dev,
1036 "failed to allocate ATA host\n");
1037 rc = -ENOMEM;
1038 goto err_out; 824 goto err_out;
1039 }
1040 825
1041 if (!legacy_mode) {
1042 rc = ata_pci_init_native_host(host);
1043 if (rc)
1044 goto err_out;
1045 } else {
1046 int was_busy = 0;
1047
1048 rc = ata_init_legacy_host(host, &was_busy);
1049 if (was_busy)
1050 pcim_pin_device(pdev);
1051 if (rc)
1052 goto err_out;
1053
1054 /* request respective PCI regions, may fail */
1055 rc = pci_request_region(pdev, 1, DRV_NAME);
1056 rc = pci_request_region(pdev, 3, DRV_NAME);
1057 }
1058
1059 /* init BMDMA, may fail */
1060 ata_pci_init_bmdma(host);
1061 pci_set_master(pdev); 826 pci_set_master(pdev);
1062 827
1063 /* start host and request IRQ */ 828 /* start host and request IRQ */
@@ -1068,17 +833,28 @@ int ata_pci_init_one(struct pci_dev *pdev,
1068 if (!legacy_mode) { 833 if (!legacy_mode) {
1069 rc = devm_request_irq(dev, pdev->irq, pi->port_ops->irq_handler, 834 rc = devm_request_irq(dev, pdev->irq, pi->port_ops->irq_handler,
1070 IRQF_SHARED, DRV_NAME, host); 835 IRQF_SHARED, DRV_NAME, host);
836 if (rc)
837 goto err_out;
1071 host->irq = pdev->irq; 838 host->irq = pdev->irq;
1072 } else { 839 } else {
1073 irq_handler_t handler[2] = { host->ops->irq_handler, 840 if (!ata_port_is_dummy(host->ports[0])) {
1074 host->ops->irq_handler }; 841 host->irq = ATA_PRIMARY_IRQ(pdev);
1075 unsigned int irq_flags[2] = { IRQF_SHARED, IRQF_SHARED }; 842 rc = devm_request_irq(dev, host->irq,
1076 void *dev_id[2] = { host, host }; 843 pi->port_ops->irq_handler,
844 IRQF_SHARED, DRV_NAME, host);
845 if (rc)
846 goto err_out;
847 }
1077 848
1078 rc = ata_request_legacy_irqs(host, handler, irq_flags, dev_id); 849 if (!ata_port_is_dummy(host->ports[1])) {
850 host->irq2 = ATA_SECONDARY_IRQ(pdev);
851 rc = devm_request_irq(dev, host->irq2,
852 pi->port_ops->irq_handler,
853 IRQF_SHARED, DRV_NAME, host);
854 if (rc)
855 goto err_out;
856 }
1079 } 857 }
1080 if (rc)
1081 goto err_out;
1082 858
1083 /* register */ 859 /* register */
1084 rc = ata_host_register(host, pi->sht); 860 rc = ata_host_register(host, pi->sht);
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index d928c9105034..be0f05efac6d 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -23,7 +23,7 @@
23#include <linux/libata.h> 23#include <linux/libata.h>
24 24
25#define DRV_NAME "pata_hpt3x3" 25#define DRV_NAME "pata_hpt3x3"
26#define DRV_VERSION "0.4.3" 26#define DRV_VERSION "0.5.3"
27 27
28/** 28/**
29 * hpt3x3_set_piomode - PIO setup 29 * hpt3x3_set_piomode - PIO setup
@@ -52,6 +52,7 @@ static void hpt3x3_set_piomode(struct ata_port *ap, struct ata_device *adev)
52 pci_write_config_dword(pdev, 0x48, r2); 52 pci_write_config_dword(pdev, 0x48, r2);
53} 53}
54 54
55#if defined(CONFIG_PATA_HPT3X3_DMA)
55/** 56/**
56 * hpt3x3_set_dmamode - DMA timing setup 57 * hpt3x3_set_dmamode - DMA timing setup
57 * @ap: ATA interface 58 * @ap: ATA interface
@@ -59,6 +60,9 @@ static void hpt3x3_set_piomode(struct ata_port *ap, struct ata_device *adev)
59 * 60 *
60 * Set up the channel for MWDMA or UDMA modes. Much the same as with 61 * Set up the channel for MWDMA or UDMA modes. Much the same as with
61 * PIO, load the mode number and then set MWDMA or UDMA flag. 62 * PIO, load the mode number and then set MWDMA or UDMA flag.
63 *
64 * 0x44 : bit 0-2 master mode, 3-5 slave mode, etc
65 * 0x48 : bit 4/0 DMA/UDMA bit 5/1 for slave etc
62 */ 66 */
63 67
64static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev) 68static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
@@ -76,13 +80,26 @@ static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
76 r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */ 80 r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */
77 81
78 if (adev->dma_mode >= XFER_UDMA_0) 82 if (adev->dma_mode >= XFER_UDMA_0)
79 r2 |= 0x01 << dn; /* Ultra mode */ 83 r2 |= (0x10 << dn); /* Ultra mode */
80 else 84 else
81 r2 |= 0x10 << dn; /* MWDMA */ 85 r2 |= (0x01 << dn); /* MWDMA */
82 86
83 pci_write_config_dword(pdev, 0x44, r1); 87 pci_write_config_dword(pdev, 0x44, r1);
84 pci_write_config_dword(pdev, 0x48, r2); 88 pci_write_config_dword(pdev, 0x48, r2);
85} 89}
90#endif /* CONFIG_PATA_HPT3X3_DMA */
91
92/**
93 * hpt3x3_atapi_dma - ATAPI DMA check
94 * @qc: Queued command
95 *
96 * Just say no - we don't do ATAPI DMA
97 */
98
99static int hpt3x3_atapi_dma(struct ata_queued_cmd *qc)
100{
101 return 1;
102}
86 103
87static struct scsi_host_template hpt3x3_sht = { 104static struct scsi_host_template hpt3x3_sht = {
88 .module = THIS_MODULE, 105 .module = THIS_MODULE,
@@ -105,7 +122,9 @@ static struct scsi_host_template hpt3x3_sht = {
105static struct ata_port_operations hpt3x3_port_ops = { 122static struct ata_port_operations hpt3x3_port_ops = {
106 .port_disable = ata_port_disable, 123 .port_disable = ata_port_disable,
107 .set_piomode = hpt3x3_set_piomode, 124 .set_piomode = hpt3x3_set_piomode,
125#if defined(CONFIG_PATA_HPT3X3_DMA)
108 .set_dmamode = hpt3x3_set_dmamode, 126 .set_dmamode = hpt3x3_set_dmamode,
127#endif
109 .mode_filter = ata_pci_default_filter, 128 .mode_filter = ata_pci_default_filter,
110 129
111 .tf_load = ata_tf_load, 130 .tf_load = ata_tf_load,
@@ -124,6 +143,7 @@ static struct ata_port_operations hpt3x3_port_ops = {
124 .bmdma_start = ata_bmdma_start, 143 .bmdma_start = ata_bmdma_start,
125 .bmdma_stop = ata_bmdma_stop, 144 .bmdma_stop = ata_bmdma_stop,
126 .bmdma_status = ata_bmdma_status, 145 .bmdma_status = ata_bmdma_status,
146 .check_atapi_dma= hpt3x3_atapi_dma,
127 147
128 .qc_prep = ata_qc_prep, 148 .qc_prep = ata_qc_prep,
129 .qc_issue = ata_qc_issue_prot, 149 .qc_issue = ata_qc_issue_prot,
@@ -158,32 +178,79 @@ static void hpt3x3_init_chipset(struct pci_dev *dev)
158 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 178 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
159} 179}
160 180
161
162/** 181/**
163 * hpt3x3_init_one - Initialise an HPT343/363 182 * hpt3x3_init_one - Initialise an HPT343/363
164 * @dev: PCI device 183 * @pdev: PCI device
165 * @id: Entry in match table 184 * @id: Entry in match table
166 * 185 *
167 * Perform basic initialisation. The chip has a quirk that it won't 186 * Perform basic initialisation. We set the device up so we access all
168 * function unless it is at XX00. The old ATA driver touched this up 187 * ports via BAR4. This is neccessary to work around errata.
169 * but we leave it for pci quirks to do properly.
170 */ 188 */
171 189
172static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id) 190static int hpt3x3_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
173{ 191{
192 static int printed_version;
174 static const struct ata_port_info info = { 193 static const struct ata_port_info info = {
175 .sht = &hpt3x3_sht, 194 .sht = &hpt3x3_sht,
176 .flags = ATA_FLAG_SLAVE_POSS, 195 .flags = ATA_FLAG_SLAVE_POSS,
177 .pio_mask = 0x1f, 196 .pio_mask = 0x1f,
197#if defined(CONFIG_PATA_HPT3X3_DMA)
198 /* Further debug needed */
178 .mwdma_mask = 0x07, 199 .mwdma_mask = 0x07,
179 .udma_mask = 0x07, 200 .udma_mask = 0x07,
201#endif
180 .port_ops = &hpt3x3_port_ops 202 .port_ops = &hpt3x3_port_ops
181 }; 203 };
204 /* Register offsets of taskfiles in BAR4 area */
205 static const u8 offset_cmd[2] = { 0x20, 0x28 };
206 static const u8 offset_ctl[2] = { 0x36, 0x3E };
182 const struct ata_port_info *ppi[] = { &info, NULL }; 207 const struct ata_port_info *ppi[] = { &info, NULL };
183 208 struct ata_host *host;
184 hpt3x3_init_chipset(dev); 209 int i, rc;
185 /* Now kick off ATA set up */ 210 void __iomem *base;
186 return ata_pci_init_one(dev, ppi); 211
212 hpt3x3_init_chipset(pdev);
213
214 if (!printed_version++)
215 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
216
217 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
218 if (!host)
219 return -ENOMEM;
220 /* acquire resources and fill host */
221 rc = pcim_enable_device(pdev);
222 if (rc)
223 return rc;
224
225 /* Everything is relative to BAR4 if we set up this way */
226 rc = pcim_iomap_regions(pdev, 1 << 4, DRV_NAME);
227 if (rc == -EBUSY)
228 pcim_pin_device(pdev);
229 if (rc)
230 return rc;
231 host->iomap = pcim_iomap_table(pdev);
232 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
233 if (rc)
234 return rc;
235 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
236 if (rc)
237 return rc;
238
239 base = host->iomap[4]; /* Bus mastering base */
240
241 for (i = 0; i < host->n_ports; i++) {
242 struct ata_ioports *ioaddr = &host->ports[i]->ioaddr;
243
244 ioaddr->cmd_addr = base + offset_cmd[i];
245 ioaddr->altstatus_addr =
246 ioaddr->ctl_addr = base + offset_ctl[i];
247 ioaddr->scr_addr = NULL;
248 ata_std_ports(ioaddr);
249 ioaddr->bmdma_addr = base + 8 * i;
250 }
251 pci_set_master(pdev);
252 return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
253 &hpt3x3_sht);
187} 254}
188 255
189#ifdef CONFIG_PM 256#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 368fac7d168b..182e83c9047b 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -467,13 +467,27 @@ mpc52xx_ata_remove(struct of_device *op)
467static int 467static int
468mpc52xx_ata_suspend(struct of_device *op, pm_message_t state) 468mpc52xx_ata_suspend(struct of_device *op, pm_message_t state)
469{ 469{
470 return 0; /* FIXME : What to do here ? */ 470 struct ata_host *host = dev_get_drvdata(&op->dev);
471
472 return ata_host_suspend(host, state);
471} 473}
472 474
473static int 475static int
474mpc52xx_ata_resume(struct of_device *op) 476mpc52xx_ata_resume(struct of_device *op)
475{ 477{
476 return 0; /* FIXME : What to do here ? */ 478 struct ata_host *host = dev_get_drvdata(&op->dev);
479 struct mpc52xx_ata_priv *priv = host->private_data;
480 int rv;
481
482 rv = mpc52xx_ata_hw_init(priv);
483 if (rv) {
484 printk(KERN_ERR DRV_NAME ": Error during HW init\n");
485 return rv;
486 }
487
488 ata_host_resume(host);
489
490 return 0;
477} 491}
478 492
479#endif 493#endif
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index 61502bc7bf1d..c55667e0eb65 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -238,6 +238,12 @@ static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
238 else 238 else
239 offset = 0; /* 100MHz */ 239 offset = 0; /* 100MHz */
240 240
241 /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */
242 if (adev->class == ATA_DEV_ATAPI && speed > XFER_UDMA_4) {
243 printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
244 speed = XFER_UDMA_4;
245 }
246
241 if (speed >= XFER_UDMA_0) 247 if (speed >= XFER_UDMA_0)
242 idx = speed - XFER_UDMA_0; 248 idx = speed - XFER_UDMA_0;
243 else 249 else
@@ -724,22 +730,36 @@ static void scc_bmdma_stop (struct ata_queued_cmd *qc)
724 730
725static u8 scc_bmdma_status (struct ata_port *ap) 731static u8 scc_bmdma_status (struct ata_port *ap)
726{ 732{
727 u8 host_stat;
728 void __iomem *mmio = ap->ioaddr.bmdma_addr; 733 void __iomem *mmio = ap->ioaddr.bmdma_addr;
729 734 u8 host_stat = in_be32(mmio + SCC_DMA_STATUS);
730 host_stat = in_be32(mmio + SCC_DMA_STATUS); 735 u32 int_status = in_be32(mmio + SCC_DMA_INTST);
731 736 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
732 /* Workaround for PTERADD: emulate DMA_INTR when 737 static int retry = 0;
733 * - IDE_STATUS[ERR] = 1 738
734 * - INT_STATUS[INTRQ] = 1 739 /* return if IOS_SS is cleared */
735 * - DMA_STATUS[IORACTA] = 1 740 if (!(in_be32(mmio + SCC_DMA_CMD) & ATA_DMA_START))
736 */ 741 return host_stat;
737 if (!(host_stat & ATA_DMA_INTR)) { 742
738 u32 int_status = in_be32(mmio + SCC_DMA_INTST); 743 /* errata A252,A308 workaround: Step4 */
739 if (ata_altstatus(ap) & ATA_ERR && 744 if (ata_altstatus(ap) & ATA_ERR && int_status & INTSTS_INTRQ)
740 int_status & INTSTS_INTRQ && 745 return (host_stat | ATA_DMA_INTR);
741 host_stat & ATA_DMA_ACTIVE) 746
742 host_stat |= ATA_DMA_INTR; 747 /* errata A308 workaround Step5 */
748 if (int_status & INTSTS_IOIRQS) {
749 host_stat |= ATA_DMA_INTR;
750
751 /* We don't check ATAPI DMA because it is limited to UDMA4 */
752 if ((qc->tf.protocol == ATA_PROT_DMA &&
753 qc->dev->xfer_mode > XFER_UDMA_4)) {
754 if (!(int_status & INTSTS_ACTEINT)) {
755 printk(KERN_WARNING "ata%u: data lost occurred. (ACTEINT==0, retry:%d)\n",
756 ap->print_id, retry);
757 host_stat |= ATA_DMA_ERR;
758 if (retry++)
759 ap->udma_mask >>= 1;
760 } else
761 retry = 0;
762 }
743 } 763 }
744 764
745 return host_stat; 765 return host_stat;
@@ -892,10 +912,6 @@ static void scc_std_postreset (struct ata_port *ap, unsigned int *classes)
892{ 912{
893 DPRINTK("ENTER\n"); 913 DPRINTK("ENTER\n");
894 914
895 /* re-enable interrupts */
896 if (!ap->ops->error_handler)
897 ap->ops->irq_on(ap);
898
899 /* is double-select really necessary? */ 915 /* is double-select really necessary? */
900 if (classes[0] != ATA_DEV_NONE) 916 if (classes[0] != ATA_DEV_NONE)
901 ap->ops->dev_select(ap, 1); 917 ap->ops->dev_select(ap, 1);
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 74a021124f3c..9a829a7cbc60 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -149,6 +149,9 @@ static int sis_pre_reset(struct ata_port *ap, unsigned long deadline)
149 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) 149 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
150 return -ENOENT; 150 return -ENOENT;
151 151
152 /* Clear the FIFO settings. We can't enable the FIFO until
153 we know we are poking at a disk */
154 pci_write_config_byte(pdev, 0x4B, 0);
152 return ata_std_prereset(ap, deadline); 155 return ata_std_prereset(ap, deadline);
153} 156}
154 157
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 6dcfc628aab1..5d576435fccc 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -29,11 +29,6 @@
29 I distinctly remember a couple workarounds (one related to PCI-X) 29 I distinctly remember a couple workarounds (one related to PCI-X)
30 are still needed. 30 are still needed.
31 31
32 2) Convert to LibATA new EH. Required for hotplug, NCQ, and sane
33 probing/error handling in general. MUST HAVE.
34
35 3) Add hotplug support (easy, once new-EH support appears)
36
37 4) Add NCQ support (easy to intermediate, once new-EH support appears) 32 4) Add NCQ support (easy to intermediate, once new-EH support appears)
38 33
39 5) Investigate problems with PCI Message Signalled Interrupts (MSI). 34 5) Investigate problems with PCI Message Signalled Interrupts (MSI).
@@ -108,8 +103,6 @@ enum {
108 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 103 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
109 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 104 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
110 105
111 MV_USE_Q_DEPTH = ATA_DEF_QUEUE,
112
113 MV_MAX_Q_DEPTH = 32, 106 MV_MAX_Q_DEPTH = 32,
114 MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, 107 MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
115 108
@@ -133,18 +126,22 @@ enum {
133 /* Host Flags */ 126 /* Host Flags */
134 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 127 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
135 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 128 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
136 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 129 MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
137 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 130 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
138 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING), 131 ATA_FLAG_PIO_POLLING,
139 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 132 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
140 133
141 CRQB_FLAG_READ = (1 << 0), 134 CRQB_FLAG_READ = (1 << 0),
142 CRQB_TAG_SHIFT = 1, 135 CRQB_TAG_SHIFT = 1,
136 CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */
137 CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */
143 CRQB_CMD_ADDR_SHIFT = 8, 138 CRQB_CMD_ADDR_SHIFT = 8,
144 CRQB_CMD_CS = (0x2 << 11), 139 CRQB_CMD_CS = (0x2 << 11),
145 CRQB_CMD_LAST = (1 << 15), 140 CRQB_CMD_LAST = (1 << 15),
146 141
147 CRPB_FLAG_STATUS_SHIFT = 8, 142 CRPB_FLAG_STATUS_SHIFT = 8,
143 CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */
144 CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */
148 145
149 EPRD_FLAG_END_OF_TBL = (1 << 31), 146 EPRD_FLAG_END_OF_TBL = (1 << 31),
150 147
@@ -236,8 +233,10 @@ enum {
236 EDMA_ERR_DEV_DCON = (1 << 3), 233 EDMA_ERR_DEV_DCON = (1 << 3),
237 EDMA_ERR_DEV_CON = (1 << 4), 234 EDMA_ERR_DEV_CON = (1 << 4),
238 EDMA_ERR_SERR = (1 << 5), 235 EDMA_ERR_SERR = (1 << 5),
239 EDMA_ERR_SELF_DIS = (1 << 7), 236 EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */
237 EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */
240 EDMA_ERR_BIST_ASYNC = (1 << 8), 238 EDMA_ERR_BIST_ASYNC = (1 << 8),
239 EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */
241 EDMA_ERR_CRBQ_PAR = (1 << 9), 240 EDMA_ERR_CRBQ_PAR = (1 << 9),
242 EDMA_ERR_CRPB_PAR = (1 << 10), 241 EDMA_ERR_CRPB_PAR = (1 << 10),
243 EDMA_ERR_INTRL_PAR = (1 << 11), 242 EDMA_ERR_INTRL_PAR = (1 << 11),
@@ -248,13 +247,33 @@ enum {
248 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), 247 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21),
249 EDMA_ERR_LNK_DATA_TX = (0x1f << 26), 248 EDMA_ERR_LNK_DATA_TX = (0x1f << 26),
250 EDMA_ERR_TRANS_PROTO = (1 << 31), 249 EDMA_ERR_TRANS_PROTO = (1 << 31),
251 EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 250 EDMA_ERR_OVERRUN_5 = (1 << 5),
252 EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR | 251 EDMA_ERR_UNDERRUN_5 = (1 << 6),
253 EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR | 252 EDMA_EH_FREEZE = EDMA_ERR_D_PAR |
254 EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 | 253 EDMA_ERR_PRD_PAR |
255 EDMA_ERR_LNK_DATA_RX | 254 EDMA_ERR_DEV_DCON |
256 EDMA_ERR_LNK_DATA_TX | 255 EDMA_ERR_DEV_CON |
257 EDMA_ERR_TRANS_PROTO), 256 EDMA_ERR_SERR |
257 EDMA_ERR_SELF_DIS |
258 EDMA_ERR_CRBQ_PAR |
259 EDMA_ERR_CRPB_PAR |
260 EDMA_ERR_INTRL_PAR |
261 EDMA_ERR_IORDY |
262 EDMA_ERR_LNK_CTRL_RX_2 |
263 EDMA_ERR_LNK_DATA_RX |
264 EDMA_ERR_LNK_DATA_TX |
265 EDMA_ERR_TRANS_PROTO,
266 EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR |
267 EDMA_ERR_PRD_PAR |
268 EDMA_ERR_DEV_DCON |
269 EDMA_ERR_DEV_CON |
270 EDMA_ERR_OVERRUN_5 |
271 EDMA_ERR_UNDERRUN_5 |
272 EDMA_ERR_SELF_DIS_5 |
273 EDMA_ERR_CRBQ_PAR |
274 EDMA_ERR_CRPB_PAR |
275 EDMA_ERR_INTRL_PAR |
276 EDMA_ERR_IORDY,
258 277
259 EDMA_REQ_Q_BASE_HI_OFS = 0x10, 278 EDMA_REQ_Q_BASE_HI_OFS = 0x10,
260 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ 279 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
@@ -282,18 +301,18 @@ enum {
282 MV_HP_ERRATA_60X1B2 = (1 << 3), 301 MV_HP_ERRATA_60X1B2 = (1 << 3),
283 MV_HP_ERRATA_60X1C0 = (1 << 4), 302 MV_HP_ERRATA_60X1C0 = (1 << 4),
284 MV_HP_ERRATA_XX42A0 = (1 << 5), 303 MV_HP_ERRATA_XX42A0 = (1 << 5),
285 MV_HP_50XX = (1 << 6), 304 MV_HP_GEN_I = (1 << 6),
286 MV_HP_GEN_IIE = (1 << 7), 305 MV_HP_GEN_II = (1 << 7),
306 MV_HP_GEN_IIE = (1 << 8),
287 307
288 /* Port private flags (pp_flags) */ 308 /* Port private flags (pp_flags) */
289 MV_PP_FLAG_EDMA_EN = (1 << 0), 309 MV_PP_FLAG_EDMA_EN = (1 << 0),
290 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), 310 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1),
311 MV_PP_FLAG_HAD_A_RESET = (1 << 2),
291}; 312};
292 313
293#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX) 314#define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I)
294#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0) 315#define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II)
295#define IS_GEN_I(hpriv) IS_50XX(hpriv)
296#define IS_GEN_II(hpriv) IS_60XX(hpriv)
297#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 316#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
298 317
299enum { 318enum {
@@ -352,6 +371,10 @@ struct mv_port_priv {
352 dma_addr_t crpb_dma; 371 dma_addr_t crpb_dma;
353 struct mv_sg *sg_tbl; 372 struct mv_sg *sg_tbl;
354 dma_addr_t sg_tbl_dma; 373 dma_addr_t sg_tbl_dma;
374
375 unsigned int req_idx;
376 unsigned int resp_idx;
377
355 u32 pp_flags; 378 u32 pp_flags;
356}; 379};
357 380
@@ -384,14 +407,15 @@ static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
384static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 407static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
385static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 408static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
386static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 409static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
387static void mv_phy_reset(struct ata_port *ap);
388static void __mv_phy_reset(struct ata_port *ap, int can_sleep);
389static int mv_port_start(struct ata_port *ap); 410static int mv_port_start(struct ata_port *ap);
390static void mv_port_stop(struct ata_port *ap); 411static void mv_port_stop(struct ata_port *ap);
391static void mv_qc_prep(struct ata_queued_cmd *qc); 412static void mv_qc_prep(struct ata_queued_cmd *qc);
392static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 413static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
393static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 414static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
394static void mv_eng_timeout(struct ata_port *ap); 415static void mv_error_handler(struct ata_port *ap);
416static void mv_post_int_cmd(struct ata_queued_cmd *qc);
417static void mv_eh_freeze(struct ata_port *ap);
418static void mv_eh_thaw(struct ata_port *ap);
395static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 419static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
396 420
397static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 421static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
@@ -415,14 +439,31 @@ static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
415static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio); 439static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio);
416static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 440static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
417 unsigned int port_no); 441 unsigned int port_no);
418static void mv_stop_and_reset(struct ata_port *ap);
419 442
420static struct scsi_host_template mv_sht = { 443static struct scsi_host_template mv5_sht = {
444 .module = THIS_MODULE,
445 .name = DRV_NAME,
446 .ioctl = ata_scsi_ioctl,
447 .queuecommand = ata_scsi_queuecmd,
448 .can_queue = ATA_DEF_QUEUE,
449 .this_id = ATA_SHT_THIS_ID,
450 .sg_tablesize = MV_MAX_SG_CT,
451 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
452 .emulated = ATA_SHT_EMULATED,
453 .use_clustering = 1,
454 .proc_name = DRV_NAME,
455 .dma_boundary = MV_DMA_BOUNDARY,
456 .slave_configure = ata_scsi_slave_config,
457 .slave_destroy = ata_scsi_slave_destroy,
458 .bios_param = ata_std_bios_param,
459};
460
461static struct scsi_host_template mv6_sht = {
421 .module = THIS_MODULE, 462 .module = THIS_MODULE,
422 .name = DRV_NAME, 463 .name = DRV_NAME,
423 .ioctl = ata_scsi_ioctl, 464 .ioctl = ata_scsi_ioctl,
424 .queuecommand = ata_scsi_queuecmd, 465 .queuecommand = ata_scsi_queuecmd,
425 .can_queue = MV_USE_Q_DEPTH, 466 .can_queue = ATA_DEF_QUEUE,
426 .this_id = ATA_SHT_THIS_ID, 467 .this_id = ATA_SHT_THIS_ID,
427 .sg_tablesize = MV_MAX_SG_CT, 468 .sg_tablesize = MV_MAX_SG_CT,
428 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 469 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
@@ -444,19 +485,21 @@ static const struct ata_port_operations mv5_ops = {
444 .exec_command = ata_exec_command, 485 .exec_command = ata_exec_command,
445 .dev_select = ata_std_dev_select, 486 .dev_select = ata_std_dev_select,
446 487
447 .phy_reset = mv_phy_reset,
448 .cable_detect = ata_cable_sata, 488 .cable_detect = ata_cable_sata,
449 489
450 .qc_prep = mv_qc_prep, 490 .qc_prep = mv_qc_prep,
451 .qc_issue = mv_qc_issue, 491 .qc_issue = mv_qc_issue,
452 .data_xfer = ata_data_xfer, 492 .data_xfer = ata_data_xfer,
453 493
454 .eng_timeout = mv_eng_timeout,
455
456 .irq_clear = mv_irq_clear, 494 .irq_clear = mv_irq_clear,
457 .irq_on = ata_irq_on, 495 .irq_on = ata_irq_on,
458 .irq_ack = ata_irq_ack, 496 .irq_ack = ata_irq_ack,
459 497
498 .error_handler = mv_error_handler,
499 .post_internal_cmd = mv_post_int_cmd,
500 .freeze = mv_eh_freeze,
501 .thaw = mv_eh_thaw,
502
460 .scr_read = mv5_scr_read, 503 .scr_read = mv5_scr_read,
461 .scr_write = mv5_scr_write, 504 .scr_write = mv5_scr_write,
462 505
@@ -473,19 +516,21 @@ static const struct ata_port_operations mv6_ops = {
473 .exec_command = ata_exec_command, 516 .exec_command = ata_exec_command,
474 .dev_select = ata_std_dev_select, 517 .dev_select = ata_std_dev_select,
475 518
476 .phy_reset = mv_phy_reset,
477 .cable_detect = ata_cable_sata, 519 .cable_detect = ata_cable_sata,
478 520
479 .qc_prep = mv_qc_prep, 521 .qc_prep = mv_qc_prep,
480 .qc_issue = mv_qc_issue, 522 .qc_issue = mv_qc_issue,
481 .data_xfer = ata_data_xfer, 523 .data_xfer = ata_data_xfer,
482 524
483 .eng_timeout = mv_eng_timeout,
484
485 .irq_clear = mv_irq_clear, 525 .irq_clear = mv_irq_clear,
486 .irq_on = ata_irq_on, 526 .irq_on = ata_irq_on,
487 .irq_ack = ata_irq_ack, 527 .irq_ack = ata_irq_ack,
488 528
529 .error_handler = mv_error_handler,
530 .post_internal_cmd = mv_post_int_cmd,
531 .freeze = mv_eh_freeze,
532 .thaw = mv_eh_thaw,
533
489 .scr_read = mv_scr_read, 534 .scr_read = mv_scr_read,
490 .scr_write = mv_scr_write, 535 .scr_write = mv_scr_write,
491 536
@@ -502,19 +547,21 @@ static const struct ata_port_operations mv_iie_ops = {
502 .exec_command = ata_exec_command, 547 .exec_command = ata_exec_command,
503 .dev_select = ata_std_dev_select, 548 .dev_select = ata_std_dev_select,
504 549
505 .phy_reset = mv_phy_reset,
506 .cable_detect = ata_cable_sata, 550 .cable_detect = ata_cable_sata,
507 551
508 .qc_prep = mv_qc_prep_iie, 552 .qc_prep = mv_qc_prep_iie,
509 .qc_issue = mv_qc_issue, 553 .qc_issue = mv_qc_issue,
510 .data_xfer = ata_data_xfer, 554 .data_xfer = ata_data_xfer,
511 555
512 .eng_timeout = mv_eng_timeout,
513
514 .irq_clear = mv_irq_clear, 556 .irq_clear = mv_irq_clear,
515 .irq_on = ata_irq_on, 557 .irq_on = ata_irq_on,
516 .irq_ack = ata_irq_ack, 558 .irq_ack = ata_irq_ack,
517 559
560 .error_handler = mv_error_handler,
561 .post_internal_cmd = mv_post_int_cmd,
562 .freeze = mv_eh_freeze,
563 .thaw = mv_eh_thaw,
564
518 .scr_read = mv_scr_read, 565 .scr_read = mv_scr_read,
519 .scr_write = mv_scr_write, 566 .scr_write = mv_scr_write,
520 567
@@ -530,38 +577,38 @@ static const struct ata_port_info mv_port_info[] = {
530 .port_ops = &mv5_ops, 577 .port_ops = &mv5_ops,
531 }, 578 },
532 { /* chip_508x */ 579 { /* chip_508x */
533 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 580 .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
534 .pio_mask = 0x1f, /* pio0-4 */ 581 .pio_mask = 0x1f, /* pio0-4 */
535 .udma_mask = ATA_UDMA6, 582 .udma_mask = ATA_UDMA6,
536 .port_ops = &mv5_ops, 583 .port_ops = &mv5_ops,
537 }, 584 },
538 { /* chip_5080 */ 585 { /* chip_5080 */
539 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 586 .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
540 .pio_mask = 0x1f, /* pio0-4 */ 587 .pio_mask = 0x1f, /* pio0-4 */
541 .udma_mask = ATA_UDMA6, 588 .udma_mask = ATA_UDMA6,
542 .port_ops = &mv5_ops, 589 .port_ops = &mv5_ops,
543 }, 590 },
544 { /* chip_604x */ 591 { /* chip_604x */
545 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 592 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
546 .pio_mask = 0x1f, /* pio0-4 */ 593 .pio_mask = 0x1f, /* pio0-4 */
547 .udma_mask = ATA_UDMA6, 594 .udma_mask = ATA_UDMA6,
548 .port_ops = &mv6_ops, 595 .port_ops = &mv6_ops,
549 }, 596 },
550 { /* chip_608x */ 597 { /* chip_608x */
551 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | 598 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
552 MV_FLAG_DUAL_HC), 599 MV_FLAG_DUAL_HC,
553 .pio_mask = 0x1f, /* pio0-4 */ 600 .pio_mask = 0x1f, /* pio0-4 */
554 .udma_mask = ATA_UDMA6, 601 .udma_mask = ATA_UDMA6,
555 .port_ops = &mv6_ops, 602 .port_ops = &mv6_ops,
556 }, 603 },
557 { /* chip_6042 */ 604 { /* chip_6042 */
558 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 605 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
559 .pio_mask = 0x1f, /* pio0-4 */ 606 .pio_mask = 0x1f, /* pio0-4 */
560 .udma_mask = ATA_UDMA6, 607 .udma_mask = ATA_UDMA6,
561 .port_ops = &mv_iie_ops, 608 .port_ops = &mv_iie_ops,
562 }, 609 },
563 { /* chip_7042 */ 610 { /* chip_7042 */
564 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 611 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
565 .pio_mask = 0x1f, /* pio0-4 */ 612 .pio_mask = 0x1f, /* pio0-4 */
566 .udma_mask = ATA_UDMA6, 613 .udma_mask = ATA_UDMA6,
567 .port_ops = &mv_iie_ops, 614 .port_ops = &mv_iie_ops,
@@ -709,6 +756,46 @@ static void mv_irq_clear(struct ata_port *ap)
709{ 756{
710} 757}
711 758
759static void mv_set_edma_ptrs(void __iomem *port_mmio,
760 struct mv_host_priv *hpriv,
761 struct mv_port_priv *pp)
762{
763 u32 index;
764
765 /*
766 * initialize request queue
767 */
768 index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT;
769
770 WARN_ON(pp->crqb_dma & 0x3ff);
771 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
772 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index,
773 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
774
775 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
776 writelfl((pp->crqb_dma & 0xffffffff) | index,
777 port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
778 else
779 writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
780
781 /*
782 * initialize response queue
783 */
784 index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT;
785
786 WARN_ON(pp->crpb_dma & 0xff);
787 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
788
789 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
790 writelfl((pp->crpb_dma & 0xffffffff) | index,
791 port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
792 else
793 writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
794
795 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index,
796 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
797}
798
712/** 799/**
713 * mv_start_dma - Enable eDMA engine 800 * mv_start_dma - Enable eDMA engine
714 * @base: port base address 801 * @base: port base address
@@ -720,9 +807,15 @@ static void mv_irq_clear(struct ata_port *ap)
720 * LOCKING: 807 * LOCKING:
721 * Inherited from caller. 808 * Inherited from caller.
722 */ 809 */
723static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp) 810static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv,
811 struct mv_port_priv *pp)
724{ 812{
725 if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) { 813 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
814 /* clear EDMA event indicators, if any */
815 writelfl(0, base + EDMA_ERR_IRQ_CAUSE_OFS);
816
817 mv_set_edma_ptrs(base, hpriv, pp);
818
726 writelfl(EDMA_EN, base + EDMA_CMD_OFS); 819 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
727 pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 820 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
728 } 821 }
@@ -739,14 +832,14 @@ static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
739 * LOCKING: 832 * LOCKING:
740 * Inherited from caller. 833 * Inherited from caller.
741 */ 834 */
742static void mv_stop_dma(struct ata_port *ap) 835static int mv_stop_dma(struct ata_port *ap)
743{ 836{
744 void __iomem *port_mmio = mv_ap_base(ap); 837 void __iomem *port_mmio = mv_ap_base(ap);
745 struct mv_port_priv *pp = ap->private_data; 838 struct mv_port_priv *pp = ap->private_data;
746 u32 reg; 839 u32 reg;
747 int i; 840 int i, err = 0;
748 841
749 if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) { 842 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
750 /* Disable EDMA if active. The disable bit auto clears. 843 /* Disable EDMA if active. The disable bit auto clears.
751 */ 844 */
752 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 845 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
@@ -758,16 +851,18 @@ static void mv_stop_dma(struct ata_port *ap)
758 /* now properly wait for the eDMA to stop */ 851 /* now properly wait for the eDMA to stop */
759 for (i = 1000; i > 0; i--) { 852 for (i = 1000; i > 0; i--) {
760 reg = readl(port_mmio + EDMA_CMD_OFS); 853 reg = readl(port_mmio + EDMA_CMD_OFS);
761 if (!(EDMA_EN & reg)) { 854 if (!(reg & EDMA_EN))
762 break; 855 break;
763 } 856
764 udelay(100); 857 udelay(100);
765 } 858 }
766 859
767 if (EDMA_EN & reg) { 860 if (reg & EDMA_EN) {
768 ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 861 ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n");
769 /* FIXME: Consider doing a reset here to recover */ 862 err = -EIO;
770 } 863 }
864
865 return err;
771} 866}
772 867
773#ifdef ATA_DEBUG 868#ifdef ATA_DEBUG
@@ -884,12 +979,13 @@ static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
884 writelfl(val, mv_ap_base(ap) + ofs); 979 writelfl(val, mv_ap_base(ap) + ofs);
885} 980}
886 981
887static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) 982static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv,
983 void __iomem *port_mmio)
888{ 984{
889 u32 cfg = readl(port_mmio + EDMA_CFG_OFS); 985 u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
890 986
891 /* set up non-NCQ EDMA configuration */ 987 /* set up non-NCQ EDMA configuration */
892 cfg &= ~(1 << 9); /* disable equeue */ 988 cfg &= ~(1 << 9); /* disable eQue */
893 989
894 if (IS_GEN_I(hpriv)) { 990 if (IS_GEN_I(hpriv)) {
895 cfg &= ~0x1f; /* clear queue depth */ 991 cfg &= ~0x1f; /* clear queue depth */
@@ -909,7 +1005,7 @@ static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
909 cfg |= (1 << 18); /* enab early completion */ 1005 cfg |= (1 << 18); /* enab early completion */
910 cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ 1006 cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */
911 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */ 1007 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */
912 cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */ 1008 cfg &= ~(EDMA_CFG_NCQ); /* clear NCQ */
913 } 1009 }
914 1010
915 writelfl(cfg, port_mmio + EDMA_CFG_OFS); 1011 writelfl(cfg, port_mmio + EDMA_CFG_OFS);
@@ -971,28 +1067,9 @@ static int mv_port_start(struct ata_port *ap)
971 pp->sg_tbl = mem; 1067 pp->sg_tbl = mem;
972 pp->sg_tbl_dma = mem_dma; 1068 pp->sg_tbl_dma = mem_dma;
973 1069
974 mv_edma_cfg(hpriv, port_mmio); 1070 mv_edma_cfg(ap, hpriv, port_mmio);
975 1071
976 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 1072 mv_set_edma_ptrs(port_mmio, hpriv, pp);
977 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
978 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
979
980 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
981 writelfl(pp->crqb_dma & 0xffffffff,
982 port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
983 else
984 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
985
986 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
987
988 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
989 writelfl(pp->crpb_dma & 0xffffffff,
990 port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
991 else
992 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
993
994 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
995 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
996 1073
997 /* Don't turn on EDMA here...do it before DMA commands only. Else 1074 /* Don't turn on EDMA here...do it before DMA commands only. Else
998 * we'll be unable to send non-data, PIO, etc due to restricted access 1075 * we'll be unable to send non-data, PIO, etc due to restricted access
@@ -1055,11 +1132,6 @@ static unsigned int mv_fill_sg(struct ata_queued_cmd *qc)
1055 return n_sg; 1132 return n_sg;
1056} 1133}
1057 1134
1058static inline unsigned mv_inc_q_index(unsigned index)
1059{
1060 return (index + 1) & MV_MAX_Q_DEPTH_MASK;
1061}
1062
1063static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1135static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
1064{ 1136{
1065 u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 1137 u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
@@ -1088,7 +1160,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
1088 u16 flags = 0; 1160 u16 flags = 0;
1089 unsigned in_index; 1161 unsigned in_index;
1090 1162
1091 if (ATA_PROT_DMA != qc->tf.protocol) 1163 if (qc->tf.protocol != ATA_PROT_DMA)
1092 return; 1164 return;
1093 1165
1094 /* Fill in command request block 1166 /* Fill in command request block
@@ -1097,10 +1169,10 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
1097 flags |= CRQB_FLAG_READ; 1169 flags |= CRQB_FLAG_READ;
1098 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1170 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
1099 flags |= qc->tag << CRQB_TAG_SHIFT; 1171 flags |= qc->tag << CRQB_TAG_SHIFT;
1172 flags |= qc->tag << CRQB_IOID_SHIFT; /* 50xx appears to ignore this*/
1100 1173
1101 /* get current queue index from hardware */ 1174 /* get current queue index from software */
1102 in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) 1175 in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
1103 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1104 1176
1105 pp->crqb[in_index].sg_addr = 1177 pp->crqb[in_index].sg_addr =
1106 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); 1178 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
@@ -1180,7 +1252,7 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1180 unsigned in_index; 1252 unsigned in_index;
1181 u32 flags = 0; 1253 u32 flags = 0;
1182 1254
1183 if (ATA_PROT_DMA != qc->tf.protocol) 1255 if (qc->tf.protocol != ATA_PROT_DMA)
1184 return; 1256 return;
1185 1257
1186 /* Fill in Gen IIE command request block 1258 /* Fill in Gen IIE command request block
@@ -1190,10 +1262,11 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1190 1262
1191 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1263 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
1192 flags |= qc->tag << CRQB_TAG_SHIFT; 1264 flags |= qc->tag << CRQB_TAG_SHIFT;
1265 flags |= qc->tag << CRQB_IOID_SHIFT; /* "I/O Id" is -really-
1266 what we use as our tag */
1193 1267
1194 /* get current queue index from hardware */ 1268 /* get current queue index from software */
1195 in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) 1269 in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
1196 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1197 1270
1198 crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1271 crqb = (struct mv_crqb_iie *) &pp->crqb[in_index];
1199 crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); 1272 crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
@@ -1241,83 +1314,41 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1241 */ 1314 */
1242static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 1315static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1243{ 1316{
1244 void __iomem *port_mmio = mv_ap_base(qc->ap); 1317 struct ata_port *ap = qc->ap;
1245 struct mv_port_priv *pp = qc->ap->private_data; 1318 void __iomem *port_mmio = mv_ap_base(ap);
1246 unsigned in_index; 1319 struct mv_port_priv *pp = ap->private_data;
1247 u32 in_ptr; 1320 struct mv_host_priv *hpriv = ap->host->private_data;
1321 u32 in_index;
1248 1322
1249 if (ATA_PROT_DMA != qc->tf.protocol) { 1323 if (qc->tf.protocol != ATA_PROT_DMA) {
1250 /* We're about to send a non-EDMA capable command to the 1324 /* We're about to send a non-EDMA capable command to the
1251 * port. Turn off EDMA so there won't be problems accessing 1325 * port. Turn off EDMA so there won't be problems accessing
1252 * shadow block, etc registers. 1326 * shadow block, etc registers.
1253 */ 1327 */
1254 mv_stop_dma(qc->ap); 1328 mv_stop_dma(ap);
1255 return ata_qc_issue_prot(qc); 1329 return ata_qc_issue_prot(qc);
1256 } 1330 }
1257 1331
1258 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1332 mv_start_dma(port_mmio, hpriv, pp);
1259 in_index = (in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1333
1334 in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
1260 1335
1261 /* until we do queuing, the queue should be empty at this point */ 1336 /* until we do queuing, the queue should be empty at this point */
1262 WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) 1337 WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS)
1263 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); 1338 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
1264 1339
1265 in_index = mv_inc_q_index(in_index); /* now incr producer index */ 1340 pp->req_idx++;
1266 1341
1267 mv_start_dma(port_mmio, pp); 1342 in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT;
1268 1343
1269 /* and write the request in pointer to kick the EDMA to life */ 1344 /* and write the request in pointer to kick the EDMA to life */
1270 in_ptr &= EDMA_REQ_Q_BASE_LO_MASK; 1345 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index,
1271 in_ptr |= in_index << EDMA_REQ_Q_PTR_SHIFT; 1346 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1272 writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1273 1347
1274 return 0; 1348 return 0;
1275} 1349}
1276 1350
1277/** 1351/**
1278 * mv_get_crpb_status - get status from most recently completed cmd
1279 * @ap: ATA channel to manipulate
1280 *
1281 * This routine is for use when the port is in DMA mode, when it
1282 * will be using the CRPB (command response block) method of
1283 * returning command completion information. We check indices
1284 * are good, grab status, and bump the response consumer index to
1285 * prove that we're up to date.
1286 *
1287 * LOCKING:
1288 * Inherited from caller.
1289 */
1290static u8 mv_get_crpb_status(struct ata_port *ap)
1291{
1292 void __iomem *port_mmio = mv_ap_base(ap);
1293 struct mv_port_priv *pp = ap->private_data;
1294 unsigned out_index;
1295 u32 out_ptr;
1296 u8 ata_status;
1297
1298 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1299 out_index = (out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1300
1301 ata_status = le16_to_cpu(pp->crpb[out_index].flags)
1302 >> CRPB_FLAG_STATUS_SHIFT;
1303
1304 /* increment our consumer index... */
1305 out_index = mv_inc_q_index(out_index);
1306
1307 /* and, until we do NCQ, there should only be 1 CRPB waiting */
1308 WARN_ON(out_index != ((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
1309 >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
1310
1311 /* write out our inc'd consumer index so EDMA knows we're caught up */
1312 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
1313 out_ptr |= out_index << EDMA_RSP_Q_PTR_SHIFT;
1314 writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1315
1316 /* Return ATA status register for completed CRPB */
1317 return ata_status;
1318}
1319
1320/**
1321 * mv_err_intr - Handle error interrupts on the port 1352 * mv_err_intr - Handle error interrupts on the port
1322 * @ap: ATA channel to manipulate 1353 * @ap: ATA channel to manipulate
1323 * @reset_allowed: bool: 0 == don't trigger from reset here 1354 * @reset_allowed: bool: 0 == don't trigger from reset here
@@ -1331,30 +1362,191 @@ static u8 mv_get_crpb_status(struct ata_port *ap)
1331 * LOCKING: 1362 * LOCKING:
1332 * Inherited from caller. 1363 * Inherited from caller.
1333 */ 1364 */
1334static void mv_err_intr(struct ata_port *ap, int reset_allowed) 1365static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1335{ 1366{
1336 void __iomem *port_mmio = mv_ap_base(ap); 1367 void __iomem *port_mmio = mv_ap_base(ap);
1337 u32 edma_err_cause, serr = 0; 1368 u32 edma_err_cause, eh_freeze_mask, serr = 0;
1369 struct mv_port_priv *pp = ap->private_data;
1370 struct mv_host_priv *hpriv = ap->host->private_data;
1371 unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN);
1372 unsigned int action = 0, err_mask = 0;
1373 struct ata_eh_info *ehi = &ap->eh_info;
1338 1374
1339 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1375 ata_ehi_clear_desc(ehi);
1340 1376
1341 if (EDMA_ERR_SERR & edma_err_cause) { 1377 if (!edma_enabled) {
1378 /* just a guess: do we need to do this? should we
1379 * expand this, and do it in all cases?
1380 */
1342 sata_scr_read(ap, SCR_ERROR, &serr); 1381 sata_scr_read(ap, SCR_ERROR, &serr);
1343 sata_scr_write_flush(ap, SCR_ERROR, serr); 1382 sata_scr_write_flush(ap, SCR_ERROR, serr);
1344 } 1383 }
1345 if (EDMA_ERR_SELF_DIS & edma_err_cause) { 1384
1346 struct mv_port_priv *pp = ap->private_data; 1385 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1347 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1386
1387 ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause);
1388
1389 /*
1390 * all generations share these EDMA error cause bits
1391 */
1392
1393 if (edma_err_cause & EDMA_ERR_DEV)
1394 err_mask |= AC_ERR_DEV;
1395 if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
1396 EDMA_ERR_CRBQ_PAR | EDMA_ERR_CRPB_PAR |
1397 EDMA_ERR_INTRL_PAR)) {
1398 err_mask |= AC_ERR_ATA_BUS;
1399 action |= ATA_EH_HARDRESET;
1400 ata_ehi_push_desc(ehi, ", parity error");
1401 }
1402 if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) {
1403 ata_ehi_hotplugged(ehi);
1404 ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ?
1405 ", dev disconnect" : ", dev connect");
1406 }
1407
1408 if (IS_GEN_I(hpriv)) {
1409 eh_freeze_mask = EDMA_EH_FREEZE_5;
1410
1411 if (edma_err_cause & EDMA_ERR_SELF_DIS_5) {
1412 struct mv_port_priv *pp = ap->private_data;
1413 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1414 ata_ehi_push_desc(ehi, ", EDMA self-disable");
1415 }
1416 } else {
1417 eh_freeze_mask = EDMA_EH_FREEZE;
1418
1419 if (edma_err_cause & EDMA_ERR_SELF_DIS) {
1420 struct mv_port_priv *pp = ap->private_data;
1421 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1422 ata_ehi_push_desc(ehi, ", EDMA self-disable");
1423 }
1424
1425 if (edma_err_cause & EDMA_ERR_SERR) {
1426 sata_scr_read(ap, SCR_ERROR, &serr);
1427 sata_scr_write_flush(ap, SCR_ERROR, serr);
1428 err_mask = AC_ERR_ATA_BUS;
1429 action |= ATA_EH_HARDRESET;
1430 }
1348 } 1431 }
1349 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
1350 "SERR: 0x%08x\n", ap->print_id, edma_err_cause, serr);
1351 1432
1352 /* Clear EDMA now that SERR cleanup done */ 1433 /* Clear EDMA now that SERR cleanup done */
1353 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1434 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1354 1435
1355 /* check for fatal here and recover if needed */ 1436 if (!err_mask) {
1356 if (reset_allowed && (EDMA_ERR_FATAL & edma_err_cause)) 1437 err_mask = AC_ERR_OTHER;
1357 mv_stop_and_reset(ap); 1438 action |= ATA_EH_HARDRESET;
1439 }
1440
1441 ehi->serror |= serr;
1442 ehi->action |= action;
1443
1444 if (qc)
1445 qc->err_mask |= err_mask;
1446 else
1447 ehi->err_mask |= err_mask;
1448
1449 if (edma_err_cause & eh_freeze_mask)
1450 ata_port_freeze(ap);
1451 else
1452 ata_port_abort(ap);
1453}
1454
1455static void mv_intr_pio(struct ata_port *ap)
1456{
1457 struct ata_queued_cmd *qc;
1458 u8 ata_status;
1459
1460 /* ignore spurious intr if drive still BUSY */
1461 ata_status = readb(ap->ioaddr.status_addr);
1462 if (unlikely(ata_status & ATA_BUSY))
1463 return;
1464
1465 /* get active ATA command */
1466 qc = ata_qc_from_tag(ap, ap->active_tag);
1467 if (unlikely(!qc)) /* no active tag */
1468 return;
1469 if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */
1470 return;
1471
1472 /* and finally, complete the ATA command */
1473 qc->err_mask |= ac_err_mask(ata_status);
1474 ata_qc_complete(qc);
1475}
1476
1477static void mv_intr_edma(struct ata_port *ap)
1478{
1479 void __iomem *port_mmio = mv_ap_base(ap);
1480 struct mv_host_priv *hpriv = ap->host->private_data;
1481 struct mv_port_priv *pp = ap->private_data;
1482 struct ata_queued_cmd *qc;
1483 u32 out_index, in_index;
1484 bool work_done = false;
1485
1486 /* get h/w response queue pointer */
1487 in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
1488 >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1489
1490 while (1) {
1491 u16 status;
1492
1493 /* get s/w response queue last-read pointer, and compare */
1494 out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK;
1495 if (in_index == out_index)
1496 break;
1497
1498
1499 /* 50xx: get active ATA command */
1500 if (IS_GEN_I(hpriv))
1501 qc = ata_qc_from_tag(ap, ap->active_tag);
1502
1503 /* 60xx: get active ATA command via tag, to enable support
1504 * for queueing. this works transparently for queued and
1505 * non-queued modes.
1506 */
1507 else {
1508 unsigned int tag;
1509
1510 if (IS_GEN_II(hpriv))
1511 tag = (le16_to_cpu(pp->crpb[out_index].id)
1512 >> CRPB_IOID_SHIFT_6) & 0x3f;
1513 else
1514 tag = (le16_to_cpu(pp->crpb[out_index].id)
1515 >> CRPB_IOID_SHIFT_7) & 0x3f;
1516
1517 qc = ata_qc_from_tag(ap, tag);
1518 }
1519
1520 /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS
1521 * bits (WARNING: might not necessarily be associated
1522 * with this command), which -should- be clear
1523 * if all is well
1524 */
1525 status = le16_to_cpu(pp->crpb[out_index].flags);
1526 if (unlikely(status & 0xff)) {
1527 mv_err_intr(ap, qc);
1528 return;
1529 }
1530
1531 /* and finally, complete the ATA command */
1532 if (qc) {
1533 qc->err_mask |=
1534 ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT);
1535 ata_qc_complete(qc);
1536 }
1537
1538 /* advance software response queue pointer, to
1539 * indicate (after the loop completes) to hardware
1540 * that we have consumed a response queue entry.
1541 */
1542 work_done = true;
1543 pp->resp_idx++;
1544 }
1545
1546 if (work_done)
1547 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
1548 (out_index << EDMA_RSP_Q_PTR_SHIFT),
1549 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1358} 1550}
1359 1551
1360/** 1552/**
@@ -1377,10 +1569,8 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1377{ 1569{
1378 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1570 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
1379 void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1571 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1380 struct ata_queued_cmd *qc;
1381 u32 hc_irq_cause; 1572 u32 hc_irq_cause;
1382 int shift, port, port0, hard_port, handled; 1573 int port, port0;
1383 unsigned int err_mask;
1384 1574
1385 if (hc == 0) 1575 if (hc == 0)
1386 port0 = 0; 1576 port0 = 0;
@@ -1389,79 +1579,95 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1389 1579
1390 /* we'll need the HC success int register in most cases */ 1580 /* we'll need the HC success int register in most cases */
1391 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1581 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1392 if (hc_irq_cause) 1582 if (!hc_irq_cause)
1393 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1583 return;
1584
1585 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
1394 1586
1395 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1587 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1396 hc,relevant,hc_irq_cause); 1588 hc,relevant,hc_irq_cause);
1397 1589
1398 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1590 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
1399 u8 ata_status = 0;
1400 struct ata_port *ap = host->ports[port]; 1591 struct ata_port *ap = host->ports[port];
1401 struct mv_port_priv *pp = ap->private_data; 1592 struct mv_port_priv *pp = ap->private_data;
1593 int have_err_bits, hard_port, shift;
1594
1595 if ((!ap) || (ap->flags & ATA_FLAG_DISABLED))
1596 continue;
1597
1598 shift = port << 1; /* (port * 2) */
1599 if (port >= MV_PORTS_PER_HC) {
1600 shift++; /* skip bit 8 in the HC Main IRQ reg */
1601 }
1602 have_err_bits = ((PORT0_ERR << shift) & relevant);
1603
1604 if (unlikely(have_err_bits)) {
1605 struct ata_queued_cmd *qc;
1606
1607 qc = ata_qc_from_tag(ap, ap->active_tag);
1608 if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
1609 continue;
1610
1611 mv_err_intr(ap, qc);
1612 continue;
1613 }
1402 1614
1403 hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1615 hard_port = mv_hardport_from_port(port); /* range 0..3 */
1404 handled = 0; /* ensure ata_status is set if handled++ */
1405 1616
1406 /* Note that DEV_IRQ might happen spuriously during EDMA,
1407 * and should be ignored in such cases.
1408 * The cause of this is still under investigation.
1409 */
1410 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1617 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
1411 /* EDMA: check for response queue interrupt */ 1618 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause)
1412 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) { 1619 mv_intr_edma(ap);
1413 ata_status = mv_get_crpb_status(ap);
1414 handled = 1;
1415 }
1416 } else { 1620 } else {
1417 /* PIO: check for device (drive) interrupt */ 1621 if ((DEV_IRQ << hard_port) & hc_irq_cause)
1418 if ((DEV_IRQ << hard_port) & hc_irq_cause) { 1622 mv_intr_pio(ap);
1419 ata_status = readb(ap->ioaddr.status_addr);
1420 handled = 1;
1421 /* ignore spurious intr if drive still BUSY */
1422 if (ata_status & ATA_BUSY) {
1423 ata_status = 0;
1424 handled = 0;
1425 }
1426 }
1427 } 1623 }
1624 }
1625 VPRINTK("EXIT\n");
1626}
1428 1627
1429 if (ap && (ap->flags & ATA_FLAG_DISABLED)) 1628static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
1430 continue; 1629{
1630 struct ata_port *ap;
1631 struct ata_queued_cmd *qc;
1632 struct ata_eh_info *ehi;
1633 unsigned int i, err_mask, printed = 0;
1634 u32 err_cause;
1431 1635
1432 err_mask = ac_err_mask(ata_status); 1636 err_cause = readl(mmio + PCI_IRQ_CAUSE_OFS);
1433 1637
1434 shift = port << 1; /* (port * 2) */ 1638 dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n",
1435 if (port >= MV_PORTS_PER_HC) { 1639 err_cause);
1436 shift++; /* skip bit 8 in the HC Main IRQ reg */ 1640
1437 } 1641 DPRINTK("All regs @ PCI error\n");
1438 if ((PORT0_ERR << shift) & relevant) { 1642 mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
1439 mv_err_intr(ap, 1); 1643
1440 err_mask |= AC_ERR_OTHER; 1644 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1441 handled = 1;
1442 }
1443 1645
1444 if (handled) { 1646 for (i = 0; i < host->n_ports; i++) {
1647 ap = host->ports[i];
1648 if (!ata_port_offline(ap)) {
1649 ehi = &ap->eh_info;
1650 ata_ehi_clear_desc(ehi);
1651 if (!printed++)
1652 ata_ehi_push_desc(ehi,
1653 "PCI err cause 0x%08x", err_cause);
1654 err_mask = AC_ERR_HOST_BUS;
1655 ehi->action = ATA_EH_HARDRESET;
1445 qc = ata_qc_from_tag(ap, ap->active_tag); 1656 qc = ata_qc_from_tag(ap, ap->active_tag);
1446 if (qc && (qc->flags & ATA_QCFLAG_ACTIVE)) { 1657 if (qc)
1447 VPRINTK("port %u IRQ found for qc, " 1658 qc->err_mask |= err_mask;
1448 "ata_status 0x%x\n", port,ata_status); 1659 else
1449 /* mark qc status appropriately */ 1660 ehi->err_mask |= err_mask;
1450 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) { 1661
1451 qc->err_mask |= err_mask; 1662 ata_port_freeze(ap);
1452 ata_qc_complete(qc);
1453 }
1454 }
1455 } 1663 }
1456 } 1664 }
1457 VPRINTK("EXIT\n");
1458} 1665}
1459 1666
1460/** 1667/**
1461 * mv_interrupt - 1668 * mv_interrupt - Main interrupt event handler
1462 * @irq: unused 1669 * @irq: unused
1463 * @dev_instance: private data; in this case the host structure 1670 * @dev_instance: private data; in this case the host structure
1464 * @regs: unused
1465 * 1671 *
1466 * Read the read only register to determine if any host 1672 * Read the read only register to determine if any host
1467 * controllers have pending interrupts. If so, call lower level 1673 * controllers have pending interrupts. If so, call lower level
@@ -1477,7 +1683,6 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
1477 struct ata_host *host = dev_instance; 1683 struct ata_host *host = dev_instance;
1478 unsigned int hc, handled = 0, n_hcs; 1684 unsigned int hc, handled = 0, n_hcs;
1479 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1685 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
1480 struct mv_host_priv *hpriv;
1481 u32 irq_stat; 1686 u32 irq_stat;
1482 1687
1483 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); 1688 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
@@ -1491,34 +1696,21 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
1491 n_hcs = mv_get_hc_count(host->ports[0]->flags); 1696 n_hcs = mv_get_hc_count(host->ports[0]->flags);
1492 spin_lock(&host->lock); 1697 spin_lock(&host->lock);
1493 1698
1699 if (unlikely(irq_stat & PCI_ERR)) {
1700 mv_pci_error(host, mmio);
1701 handled = 1;
1702 goto out_unlock; /* skip all other HC irq handling */
1703 }
1704
1494 for (hc = 0; hc < n_hcs; hc++) { 1705 for (hc = 0; hc < n_hcs; hc++) {
1495 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1706 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
1496 if (relevant) { 1707 if (relevant) {
1497 mv_host_intr(host, relevant, hc); 1708 mv_host_intr(host, relevant, hc);
1498 handled++; 1709 handled = 1;
1499 }
1500 }
1501
1502 hpriv = host->private_data;
1503 if (IS_60XX(hpriv)) {
1504 /* deal with the interrupt coalescing bits */
1505 if (irq_stat & (TRAN_LO_DONE | TRAN_HI_DONE | PORTS_0_7_COAL_DONE)) {
1506 writelfl(0, mmio + MV_IRQ_COAL_CAUSE_LO);
1507 writelfl(0, mmio + MV_IRQ_COAL_CAUSE_HI);
1508 writelfl(0, mmio + MV_IRQ_COAL_CAUSE);
1509 } 1710 }
1510 } 1711 }
1511 1712
1512 if (PCI_ERR & irq_stat) { 1713out_unlock:
1513 printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n",
1514 readl(mmio + PCI_IRQ_CAUSE_OFS));
1515
1516 DPRINTK("All regs @ PCI error\n");
1517 mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
1518
1519 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1520 handled++;
1521 }
1522 spin_unlock(&host->lock); 1714 spin_unlock(&host->lock);
1523 1715
1524 return IRQ_RETVAL(handled); 1716 return IRQ_RETVAL(handled);
@@ -1904,7 +2096,7 @@ static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1904 2096
1905 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); 2097 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
1906 2098
1907 if (IS_60XX(hpriv)) { 2099 if (IS_GEN_II(hpriv)) {
1908 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2100 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
1909 ifctl |= (1 << 7); /* enable gen2i speed */ 2101 ifctl |= (1 << 7); /* enable gen2i speed */
1910 ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2102 ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */
@@ -1920,32 +2112,12 @@ static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1920 2112
1921 hpriv->ops->phy_errata(hpriv, mmio, port_no); 2113 hpriv->ops->phy_errata(hpriv, mmio, port_no);
1922 2114
1923 if (IS_50XX(hpriv)) 2115 if (IS_GEN_I(hpriv))
1924 mdelay(1); 2116 mdelay(1);
1925} 2117}
1926 2118
1927static void mv_stop_and_reset(struct ata_port *ap)
1928{
1929 struct mv_host_priv *hpriv = ap->host->private_data;
1930 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1931
1932 mv_stop_dma(ap);
1933
1934 mv_channel_reset(hpriv, mmio, ap->port_no);
1935
1936 __mv_phy_reset(ap, 0);
1937}
1938
1939static inline void __msleep(unsigned int msec, int can_sleep)
1940{
1941 if (can_sleep)
1942 msleep(msec);
1943 else
1944 mdelay(msec);
1945}
1946
1947/** 2119/**
1948 * __mv_phy_reset - Perform eDMA reset followed by COMRESET 2120 * mv_phy_reset - Perform eDMA reset followed by COMRESET
1949 * @ap: ATA channel to manipulate 2121 * @ap: ATA channel to manipulate
1950 * 2122 *
1951 * Part of this is taken from __sata_phy_reset and modified to 2123 * Part of this is taken from __sata_phy_reset and modified to
@@ -1955,14 +2127,12 @@ static inline void __msleep(unsigned int msec, int can_sleep)
1955 * Inherited from caller. This is coded to safe to call at 2127 * Inherited from caller. This is coded to safe to call at
1956 * interrupt level, i.e. it does not sleep. 2128 * interrupt level, i.e. it does not sleep.
1957 */ 2129 */
1958static void __mv_phy_reset(struct ata_port *ap, int can_sleep) 2130static void mv_phy_reset(struct ata_port *ap, unsigned int *class,
2131 unsigned long deadline)
1959{ 2132{
1960 struct mv_port_priv *pp = ap->private_data; 2133 struct mv_port_priv *pp = ap->private_data;
1961 struct mv_host_priv *hpriv = ap->host->private_data; 2134 struct mv_host_priv *hpriv = ap->host->private_data;
1962 void __iomem *port_mmio = mv_ap_base(ap); 2135 void __iomem *port_mmio = mv_ap_base(ap);
1963 struct ata_taskfile tf;
1964 struct ata_device *dev = &ap->device[0];
1965 unsigned long timeout;
1966 int retry = 5; 2136 int retry = 5;
1967 u32 sstatus; 2137 u32 sstatus;
1968 2138
@@ -1975,22 +2145,21 @@ static void __mv_phy_reset(struct ata_port *ap, int can_sleep)
1975 /* Issue COMRESET via SControl */ 2145 /* Issue COMRESET via SControl */
1976comreset_retry: 2146comreset_retry:
1977 sata_scr_write_flush(ap, SCR_CONTROL, 0x301); 2147 sata_scr_write_flush(ap, SCR_CONTROL, 0x301);
1978 __msleep(1, can_sleep); 2148 msleep(1);
1979 2149
1980 sata_scr_write_flush(ap, SCR_CONTROL, 0x300); 2150 sata_scr_write_flush(ap, SCR_CONTROL, 0x300);
1981 __msleep(20, can_sleep); 2151 msleep(20);
1982 2152
1983 timeout = jiffies + msecs_to_jiffies(200);
1984 do { 2153 do {
1985 sata_scr_read(ap, SCR_STATUS, &sstatus); 2154 sata_scr_read(ap, SCR_STATUS, &sstatus);
1986 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 2155 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0))
1987 break; 2156 break;
1988 2157
1989 __msleep(1, can_sleep); 2158 msleep(1);
1990 } while (time_before(jiffies, timeout)); 2159 } while (time_before(jiffies, deadline));
1991 2160
1992 /* work around errata */ 2161 /* work around errata */
1993 if (IS_60XX(hpriv) && 2162 if (IS_GEN_II(hpriv) &&
1994 (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && 2163 (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) &&
1995 (retry-- > 0)) 2164 (retry-- > 0))
1996 goto comreset_retry; 2165 goto comreset_retry;
@@ -1999,13 +2168,8 @@ comreset_retry:
1999 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 2168 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
2000 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 2169 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
2001 2170
2002 if (ata_port_online(ap)) { 2171 if (ata_port_offline(ap)) {
2003 ata_port_probe(ap); 2172 *class = ATA_DEV_NONE;
2004 } else {
2005 sata_scr_read(ap, SCR_STATUS, &sstatus);
2006 ata_port_printk(ap, KERN_INFO,
2007 "no device found (phy stat %08x)\n", sstatus);
2008 ata_port_disable(ap);
2009 return; 2173 return;
2010 } 2174 }
2011 2175
@@ -2019,68 +2183,152 @@ comreset_retry:
2019 u8 drv_stat = ata_check_status(ap); 2183 u8 drv_stat = ata_check_status(ap);
2020 if ((drv_stat != 0x80) && (drv_stat != 0x7f)) 2184 if ((drv_stat != 0x80) && (drv_stat != 0x7f))
2021 break; 2185 break;
2022 __msleep(500, can_sleep); 2186 msleep(500);
2023 if (retry-- <= 0) 2187 if (retry-- <= 0)
2024 break; 2188 break;
2189 if (time_after(jiffies, deadline))
2190 break;
2025 } 2191 }
2026 2192
2027 tf.lbah = readb(ap->ioaddr.lbah_addr); 2193 /* FIXME: if we passed the deadline, the following
2028 tf.lbam = readb(ap->ioaddr.lbam_addr); 2194 * code probably produces an invalid result
2029 tf.lbal = readb(ap->ioaddr.lbal_addr); 2195 */
2030 tf.nsect = readb(ap->ioaddr.nsect_addr);
2031 2196
2032 dev->class = ata_dev_classify(&tf); 2197 /* finally, read device signature from TF registers */
2033 if (!ata_dev_enabled(dev)) { 2198 *class = ata_dev_try_classify(ap, 0, NULL);
2034 VPRINTK("Port disabled post-sig: No device present.\n");
2035 ata_port_disable(ap);
2036 }
2037 2199
2038 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2200 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
2039 2201
2040 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 2202 WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN);
2041 2203
2042 VPRINTK("EXIT\n"); 2204 VPRINTK("EXIT\n");
2043} 2205}
2044 2206
2045static void mv_phy_reset(struct ata_port *ap) 2207static int mv_prereset(struct ata_port *ap, unsigned long deadline)
2046{ 2208{
2047 __mv_phy_reset(ap, 1); 2209 struct mv_port_priv *pp = ap->private_data;
2210 struct ata_eh_context *ehc = &ap->eh_context;
2211 int rc;
2212
2213 rc = mv_stop_dma(ap);
2214 if (rc)
2215 ehc->i.action |= ATA_EH_HARDRESET;
2216
2217 if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) {
2218 pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET;
2219 ehc->i.action |= ATA_EH_HARDRESET;
2220 }
2221
2222 /* if we're about to do hardreset, nothing more to do */
2223 if (ehc->i.action & ATA_EH_HARDRESET)
2224 return 0;
2225
2226 if (ata_port_online(ap))
2227 rc = ata_wait_ready(ap, deadline);
2228 else
2229 rc = -ENODEV;
2230
2231 return rc;
2048} 2232}
2049 2233
2050/** 2234static int mv_hardreset(struct ata_port *ap, unsigned int *class,
2051 * mv_eng_timeout - Routine called by libata when SCSI times out I/O 2235 unsigned long deadline)
2052 * @ap: ATA channel to manipulate
2053 *
2054 * Intent is to clear all pending error conditions, reset the
2055 * chip/bus, fail the command, and move on.
2056 *
2057 * LOCKING:
2058 * This routine holds the host lock while failing the command.
2059 */
2060static void mv_eng_timeout(struct ata_port *ap)
2061{ 2236{
2237 struct mv_host_priv *hpriv = ap->host->private_data;
2062 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 2238 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
2063 struct ata_queued_cmd *qc;
2064 unsigned long flags;
2065 2239
2066 ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n"); 2240 mv_stop_dma(ap);
2067 DPRINTK("All regs @ start of eng_timeout\n");
2068 mv_dump_all_regs(mmio, ap->port_no, to_pci_dev(ap->host->dev));
2069 2241
2070 qc = ata_qc_from_tag(ap, ap->active_tag); 2242 mv_channel_reset(hpriv, mmio, ap->port_no);
2071 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
2072 mmio, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd);
2073 2243
2074 spin_lock_irqsave(&ap->host->lock, flags); 2244 mv_phy_reset(ap, class, deadline);
2075 mv_err_intr(ap, 0); 2245
2076 mv_stop_and_reset(ap); 2246 return 0;
2077 spin_unlock_irqrestore(&ap->host->lock, flags); 2247}
2248
2249static void mv_postreset(struct ata_port *ap, unsigned int *classes)
2250{
2251 u32 serr;
2252
2253 /* print link status */
2254 sata_print_link_status(ap);
2255
2256 /* clear SError */
2257 sata_scr_read(ap, SCR_ERROR, &serr);
2258 sata_scr_write_flush(ap, SCR_ERROR, serr);
2078 2259
2079 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); 2260 /* bail out if no device is present */
2080 if (qc->flags & ATA_QCFLAG_ACTIVE) { 2261 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
2081 qc->err_mask |= AC_ERR_TIMEOUT; 2262 DPRINTK("EXIT, no device\n");
2082 ata_eh_qc_complete(qc); 2263 return;
2083 } 2264 }
2265
2266 /* set up device control */
2267 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
2268}
2269
2270static void mv_error_handler(struct ata_port *ap)
2271{
2272 ata_do_eh(ap, mv_prereset, ata_std_softreset,
2273 mv_hardreset, mv_postreset);
2274}
2275
2276static void mv_post_int_cmd(struct ata_queued_cmd *qc)
2277{
2278 mv_stop_dma(qc->ap);
2279}
2280
2281static void mv_eh_freeze(struct ata_port *ap)
2282{
2283 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
2284 unsigned int hc = (ap->port_no > 3) ? 1 : 0;
2285 u32 tmp, mask;
2286 unsigned int shift;
2287
2288 /* FIXME: handle coalescing completion events properly */
2289
2290 shift = ap->port_no * 2;
2291 if (hc > 0)
2292 shift++;
2293
2294 mask = 0x3 << shift;
2295
2296 /* disable assertion of portN err, done events */
2297 tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
2298 writelfl(tmp & ~mask, mmio + HC_MAIN_IRQ_MASK_OFS);
2299}
2300
2301static void mv_eh_thaw(struct ata_port *ap)
2302{
2303 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
2304 unsigned int hc = (ap->port_no > 3) ? 1 : 0;
2305 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
2306 void __iomem *port_mmio = mv_ap_base(ap);
2307 u32 tmp, mask, hc_irq_cause;
2308 unsigned int shift, hc_port_no = ap->port_no;
2309
2310 /* FIXME: handle coalescing completion events properly */
2311
2312 shift = ap->port_no * 2;
2313 if (hc > 0) {
2314 shift++;
2315 hc_port_no -= 4;
2316 }
2317
2318 mask = 0x3 << shift;
2319
2320 /* clear EDMA errors on this port */
2321 writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
2322
2323 /* clear pending irq events */
2324 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
2325 hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */
2326 hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */
2327 writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
2328
2329 /* enable assertion of portN err, done events */
2330 tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
2331 writelfl(tmp | mask, mmio + HC_MAIN_IRQ_MASK_OFS);
2084} 2332}
2085 2333
2086/** 2334/**
@@ -2141,7 +2389,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2141 switch(board_idx) { 2389 switch(board_idx) {
2142 case chip_5080: 2390 case chip_5080:
2143 hpriv->ops = &mv5xxx_ops; 2391 hpriv->ops = &mv5xxx_ops;
2144 hp_flags |= MV_HP_50XX; 2392 hp_flags |= MV_HP_GEN_I;
2145 2393
2146 switch (pdev->revision) { 2394 switch (pdev->revision) {
2147 case 0x1: 2395 case 0x1:
@@ -2161,7 +2409,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2161 case chip_504x: 2409 case chip_504x:
2162 case chip_508x: 2410 case chip_508x:
2163 hpriv->ops = &mv5xxx_ops; 2411 hpriv->ops = &mv5xxx_ops;
2164 hp_flags |= MV_HP_50XX; 2412 hp_flags |= MV_HP_GEN_I;
2165 2413
2166 switch (pdev->revision) { 2414 switch (pdev->revision) {
2167 case 0x0: 2415 case 0x0:
@@ -2181,6 +2429,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2181 case chip_604x: 2429 case chip_604x:
2182 case chip_608x: 2430 case chip_608x:
2183 hpriv->ops = &mv6xxx_ops; 2431 hpriv->ops = &mv6xxx_ops;
2432 hp_flags |= MV_HP_GEN_II;
2184 2433
2185 switch (pdev->revision) { 2434 switch (pdev->revision) {
2186 case 0x7: 2435 case 0x7:
@@ -2200,7 +2449,6 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
2200 case chip_7042: 2449 case chip_7042:
2201 case chip_6042: 2450 case chip_6042:
2202 hpriv->ops = &mv6xxx_ops; 2451 hpriv->ops = &mv6xxx_ops;
2203
2204 hp_flags |= MV_HP_GEN_IIE; 2452 hp_flags |= MV_HP_GEN_IIE;
2205 2453
2206 switch (pdev->revision) { 2454 switch (pdev->revision) {
@@ -2267,7 +2515,7 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2267 hpriv->ops->enable_leds(hpriv, mmio); 2515 hpriv->ops->enable_leds(hpriv, mmio);
2268 2516
2269 for (port = 0; port < host->n_ports; port++) { 2517 for (port = 0; port < host->n_ports; port++) {
2270 if (IS_60XX(hpriv)) { 2518 if (IS_GEN_II(hpriv)) {
2271 void __iomem *port_mmio = mv_port_base(mmio, port); 2519 void __iomem *port_mmio = mv_port_base(mmio, port);
2272 2520
2273 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2521 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
@@ -2302,7 +2550,7 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
2302 /* and unmask interrupt generation for host regs */ 2550 /* and unmask interrupt generation for host regs */
2303 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); 2551 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
2304 2552
2305 if (IS_50XX(hpriv)) 2553 if (IS_GEN_I(hpriv))
2306 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS); 2554 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
2307 else 2555 else
2308 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); 2556 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
@@ -2418,8 +2666,9 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2418 mv_print_info(host); 2666 mv_print_info(host);
2419 2667
2420 pci_set_master(pdev); 2668 pci_set_master(pdev);
2669 pci_set_mwi(pdev);
2421 return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, 2670 return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED,
2422 &mv_sht); 2671 IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht);
2423} 2672}
2424 2673
2425static int __init mv_init(void) 2674static int __init mv_init(void)
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index b2656867c647..db81e3efa5ec 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -1560,7 +1560,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1560 } 1560 }
1561 1561
1562 ppi[0] = &nv_port_info[type]; 1562 ppi[0] = &nv_port_info[type];
1563 rc = ata_pci_prepare_native_host(pdev, ppi, &host); 1563 rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
1564 if (rc) 1564 if (rc)
1565 return rc; 1565 return rc;
1566 1566
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 2ad5872fe90c..d2fcb9a6bec2 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -45,7 +45,7 @@
45#include "sata_promise.h" 45#include "sata_promise.h"
46 46
47#define DRV_NAME "sata_promise" 47#define DRV_NAME "sata_promise"
48#define DRV_VERSION "2.08" 48#define DRV_VERSION "2.09"
49 49
50enum { 50enum {
51 PDC_MAX_PORTS = 4, 51 PDC_MAX_PORTS = 4,
@@ -716,6 +716,9 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
716 unsigned int i, tmp; 716 unsigned int i, tmp;
717 unsigned int handled = 0; 717 unsigned int handled = 0;
718 void __iomem *mmio_base; 718 void __iomem *mmio_base;
719 unsigned int hotplug_offset, ata_no;
720 u32 hotplug_status;
721 int is_sataii_tx4;
719 722
720 VPRINTK("ENTER\n"); 723 VPRINTK("ENTER\n");
721 724
@@ -726,10 +729,20 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
726 729
727 mmio_base = host->iomap[PDC_MMIO_BAR]; 730 mmio_base = host->iomap[PDC_MMIO_BAR];
728 731
732 /* read and clear hotplug flags for all ports */
733 if (host->ports[0]->flags & PDC_FLAG_GEN_II)
734 hotplug_offset = PDC2_SATA_PLUG_CSR;
735 else
736 hotplug_offset = PDC_SATA_PLUG_CSR;
737 hotplug_status = readl(mmio_base + hotplug_offset);
738 if (hotplug_status & 0xff)
739 writel(hotplug_status | 0xff, mmio_base + hotplug_offset);
740 hotplug_status &= 0xff; /* clear uninteresting bits */
741
729 /* reading should also clear interrupts */ 742 /* reading should also clear interrupts */
730 mask = readl(mmio_base + PDC_INT_SEQMASK); 743 mask = readl(mmio_base + PDC_INT_SEQMASK);
731 744
732 if (mask == 0xffffffff) { 745 if (mask == 0xffffffff && hotplug_status == 0) {
733 VPRINTK("QUICK EXIT 2\n"); 746 VPRINTK("QUICK EXIT 2\n");
734 return IRQ_NONE; 747 return IRQ_NONE;
735 } 748 }
@@ -737,16 +750,34 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
737 spin_lock(&host->lock); 750 spin_lock(&host->lock);
738 751
739 mask &= 0xffff; /* only 16 tags possible */ 752 mask &= 0xffff; /* only 16 tags possible */
740 if (!mask) { 753 if (mask == 0 && hotplug_status == 0) {
741 VPRINTK("QUICK EXIT 3\n"); 754 VPRINTK("QUICK EXIT 3\n");
742 goto done_irq; 755 goto done_irq;
743 } 756 }
744 757
745 writel(mask, mmio_base + PDC_INT_SEQMASK); 758 writel(mask, mmio_base + PDC_INT_SEQMASK);
746 759
760 is_sataii_tx4 = pdc_is_sataii_tx4(host->ports[0]->flags);
761
747 for (i = 0; i < host->n_ports; i++) { 762 for (i = 0; i < host->n_ports; i++) {
748 VPRINTK("port %u\n", i); 763 VPRINTK("port %u\n", i);
749 ap = host->ports[i]; 764 ap = host->ports[i];
765
766 /* check for a plug or unplug event */
767 ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
768 tmp = hotplug_status & (0x11 << ata_no);
769 if (tmp && ap &&
770 !(ap->flags & ATA_FLAG_DISABLED)) {
771 struct ata_eh_info *ehi = &ap->eh_info;
772 ata_ehi_clear_desc(ehi);
773 ata_ehi_hotplugged(ehi);
774 ata_ehi_push_desc(ehi, "hotplug_status %#x", tmp);
775 ata_port_freeze(ap);
776 ++handled;
777 continue;
778 }
779
780 /* check for a packet interrupt */
750 tmp = mask & (1 << (i + 1)); 781 tmp = mask & (1 << (i + 1));
751 if (tmp && ap && 782 if (tmp && ap &&
752 !(ap->flags & ATA_FLAG_DISABLED)) { 783 !(ap->flags & ATA_FLAG_DISABLED)) {
@@ -902,9 +933,9 @@ static void pdc_host_init(struct ata_host *host)
902 tmp = readl(mmio + hotplug_offset); 933 tmp = readl(mmio + hotplug_offset);
903 writel(tmp | 0xff, mmio + hotplug_offset); 934 writel(tmp | 0xff, mmio + hotplug_offset);
904 935
905 /* mask plug/unplug ints */ 936 /* unmask plug/unplug ints */
906 tmp = readl(mmio + hotplug_offset); 937 tmp = readl(mmio + hotplug_offset);
907 writel(tmp | 0xff0000, mmio + hotplug_offset); 938 writel(tmp & ~0xff0000, mmio + hotplug_offset);
908 939
909 /* don't initialise TBG or SLEW on 2nd generation chips */ 940 /* don't initialise TBG or SLEW on 2nd generation chips */
910 if (is_gen2) 941 if (is_gen2)
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index fd80bcf1b236..33716b00c6b7 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -334,7 +334,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
334 break; 334 break;
335 } 335 }
336 336
337 rc = ata_pci_prepare_native_host(pdev, ppi, &host); 337 rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
338 if (rc) 338 if (rc)
339 return rc; 339 return rc;
340 340
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index aca71819f6e8..b52f83ab056a 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -213,7 +213,7 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
213 host->private_data = hpriv; 213 host->private_data = hpriv;
214 214
215 /* the first two ports are standard SFF */ 215 /* the first two ports are standard SFF */
216 rc = ata_pci_init_native_host(host); 216 rc = ata_pci_init_sff_host(host);
217 if (rc) 217 if (rc)
218 return rc; 218 return rc;
219 219
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index a4c0832033d8..c4124475f754 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -412,7 +412,7 @@ static int vt6420_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
412 struct ata_host *host; 412 struct ata_host *host;
413 int rc; 413 int rc;
414 414
415 rc = ata_pci_prepare_native_host(pdev, ppi, &host); 415 rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
416 if (rc) 416 if (rc)
417 return rc; 417 return rc;
418 *r_host = host; 418 *r_host = host;
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 1ec0654665cf..7370d7cf5988 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/list.h> 19#include <linux/list.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/mutex.h>
21 22
22#include "base.h" 23#include "base.h"
23 24
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 5512d84452f2..47eb02d9f1af 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -44,6 +44,6 @@ struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
44 44
45extern char *make_class_name(const char *name, struct kobject *kobj); 45extern char *make_class_name(const char *name, struct kobject *kobj);
46 46
47extern void devres_release_all(struct device *dev); 47extern int devres_release_all(struct device *dev);
48 48
49extern struct kset devices_subsys; 49extern struct kset devices_subsys;
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index dca734819e50..61c67526a656 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -138,12 +138,24 @@ void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
138 } 138 }
139} 139}
140 140
141static struct kobj_type ktype_bus = { 141static struct kobj_type bus_ktype = {
142 .sysfs_ops = &bus_sysfs_ops, 142 .sysfs_ops = &bus_sysfs_ops,
143};
144
145static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
146{
147 struct kobj_type *ktype = get_ktype(kobj);
143 148
149 if (ktype == &bus_ktype)
150 return 1;
151 return 0;
152}
153
154static struct kset_uevent_ops bus_uevent_ops = {
155 .filter = bus_uevent_filter,
144}; 156};
145 157
146static decl_subsys(bus, &ktype_bus, NULL); 158static decl_subsys(bus, &bus_ktype, &bus_uevent_ops);
147 159
148 160
149#ifdef CONFIG_HOTPLUG 161#ifdef CONFIG_HOTPLUG
@@ -562,7 +574,6 @@ static int add_probe_files(struct bus_type *bus)
562 574
563 bus->drivers_probe_attr.attr.name = "drivers_probe"; 575 bus->drivers_probe_attr.attr.name = "drivers_probe";
564 bus->drivers_probe_attr.attr.mode = S_IWUSR; 576 bus->drivers_probe_attr.attr.mode = S_IWUSR;
565 bus->drivers_probe_attr.attr.owner = bus->owner;
566 bus->drivers_probe_attr.store = store_drivers_probe; 577 bus->drivers_probe_attr.store = store_drivers_probe;
567 retval = bus_create_file(bus, &bus->drivers_probe_attr); 578 retval = bus_create_file(bus, &bus->drivers_probe_attr);
568 if (retval) 579 if (retval)
@@ -570,7 +581,6 @@ static int add_probe_files(struct bus_type *bus)
570 581
571 bus->drivers_autoprobe_attr.attr.name = "drivers_autoprobe"; 582 bus->drivers_autoprobe_attr.attr.name = "drivers_autoprobe";
572 bus->drivers_autoprobe_attr.attr.mode = S_IWUSR | S_IRUGO; 583 bus->drivers_autoprobe_attr.attr.mode = S_IWUSR | S_IRUGO;
573 bus->drivers_autoprobe_attr.attr.owner = bus->owner;
574 bus->drivers_autoprobe_attr.show = show_drivers_autoprobe; 584 bus->drivers_autoprobe_attr.show = show_drivers_autoprobe;
575 bus->drivers_autoprobe_attr.store = store_drivers_autoprobe; 585 bus->drivers_autoprobe_attr.store = store_drivers_autoprobe;
576 retval = bus_create_file(bus, &bus->drivers_autoprobe_attr); 586 retval = bus_create_file(bus, &bus->drivers_autoprobe_attr);
@@ -610,7 +620,8 @@ int bus_add_driver(struct device_driver *drv)
610 if (error) 620 if (error)
611 goto out_put_bus; 621 goto out_put_bus;
612 drv->kobj.kset = &bus->drivers; 622 drv->kobj.kset = &bus->drivers;
613 if ((error = kobject_register(&drv->kobj))) 623 error = kobject_register(&drv->kobj);
624 if (error)
614 goto out_put_bus; 625 goto out_put_bus;
615 626
616 if (drv->bus->drivers_autoprobe) { 627 if (drv->bus->drivers_autoprobe) {
@@ -760,7 +771,8 @@ static int bus_add_attrs(struct bus_type * bus)
760 771
761 if (bus->bus_attrs) { 772 if (bus->bus_attrs) {
762 for (i = 0; attr_name(bus->bus_attrs[i]); i++) { 773 for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
763 if ((error = bus_create_file(bus,&bus->bus_attrs[i]))) 774 error = bus_create_file(bus,&bus->bus_attrs[i]);
775 if (error)
764 goto Err; 776 goto Err;
765 } 777 }
766 } 778 }
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8c506dbe3913..4d2222618b78 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -312,9 +312,6 @@ static void class_dev_release(struct kobject * kobj)
312 312
313 pr_debug("device class '%s': release.\n", cd->class_id); 313 pr_debug("device class '%s': release.\n", cd->class_id);
314 314
315 kfree(cd->devt_attr);
316 cd->devt_attr = NULL;
317
318 if (cd->release) 315 if (cd->release)
319 cd->release(cd); 316 cd->release(cd);
320 else if (cls->release) 317 else if (cls->release)
@@ -547,6 +544,9 @@ static ssize_t show_dev(struct class_device *class_dev, char *buf)
547 return print_dev_t(buf, class_dev->devt); 544 return print_dev_t(buf, class_dev->devt);
548} 545}
549 546
547static struct class_device_attribute class_devt_attr =
548 __ATTR(dev, S_IRUGO, show_dev, NULL);
549
550static ssize_t store_uevent(struct class_device *class_dev, 550static ssize_t store_uevent(struct class_device *class_dev,
551 const char *buf, size_t count) 551 const char *buf, size_t count)
552{ 552{
@@ -554,6 +554,9 @@ static ssize_t store_uevent(struct class_device *class_dev,
554 return count; 554 return count;
555} 555}
556 556
557static struct class_device_attribute class_uevent_attr =
558 __ATTR(uevent, S_IWUSR, NULL, store_uevent);
559
557void class_device_initialize(struct class_device *class_dev) 560void class_device_initialize(struct class_device *class_dev)
558{ 561{
559 kobj_set_kset_s(class_dev, class_obj_subsys); 562 kobj_set_kset_s(class_dev, class_obj_subsys);
@@ -603,32 +606,15 @@ int class_device_add(struct class_device *class_dev)
603 &parent_class->subsys.kobj, "subsystem"); 606 &parent_class->subsys.kobj, "subsystem");
604 if (error) 607 if (error)
605 goto out3; 608 goto out3;
606 class_dev->uevent_attr.attr.name = "uevent"; 609
607 class_dev->uevent_attr.attr.mode = S_IWUSR; 610 error = class_device_create_file(class_dev, &class_uevent_attr);
608 class_dev->uevent_attr.attr.owner = parent_class->owner;
609 class_dev->uevent_attr.store = store_uevent;
610 error = class_device_create_file(class_dev, &class_dev->uevent_attr);
611 if (error) 611 if (error)
612 goto out3; 612 goto out3;
613 613
614 if (MAJOR(class_dev->devt)) { 614 if (MAJOR(class_dev->devt)) {
615 struct class_device_attribute *attr; 615 error = class_device_create_file(class_dev, &class_devt_attr);
616 attr = kzalloc(sizeof(*attr), GFP_KERNEL); 616 if (error)
617 if (!attr) {
618 error = -ENOMEM;
619 goto out4;
620 }
621 attr->attr.name = "dev";
622 attr->attr.mode = S_IRUGO;
623 attr->attr.owner = parent_class->owner;
624 attr->show = show_dev;
625 error = class_device_create_file(class_dev, attr);
626 if (error) {
627 kfree(attr);
628 goto out4; 617 goto out4;
629 }
630
631 class_dev->devt_attr = attr;
632 } 618 }
633 619
634 error = class_device_add_attrs(class_dev); 620 error = class_device_add_attrs(class_dev);
@@ -671,10 +657,10 @@ int class_device_add(struct class_device *class_dev)
671 out6: 657 out6:
672 class_device_remove_attrs(class_dev); 658 class_device_remove_attrs(class_dev);
673 out5: 659 out5:
674 if (class_dev->devt_attr) 660 if (MAJOR(class_dev->devt))
675 class_device_remove_file(class_dev, class_dev->devt_attr); 661 class_device_remove_file(class_dev, &class_devt_attr);
676 out4: 662 out4:
677 class_device_remove_file(class_dev, &class_dev->uevent_attr); 663 class_device_remove_file(class_dev, &class_uevent_attr);
678 out3: 664 out3:
679 kobject_del(&class_dev->kobj); 665 kobject_del(&class_dev->kobj);
680 out2: 666 out2:
@@ -774,9 +760,9 @@ void class_device_del(struct class_device *class_dev)
774 sysfs_remove_link(&class_dev->kobj, "device"); 760 sysfs_remove_link(&class_dev->kobj, "device");
775 } 761 }
776 sysfs_remove_link(&class_dev->kobj, "subsystem"); 762 sysfs_remove_link(&class_dev->kobj, "subsystem");
777 class_device_remove_file(class_dev, &class_dev->uevent_attr); 763 class_device_remove_file(class_dev, &class_uevent_attr);
778 if (class_dev->devt_attr) 764 if (MAJOR(class_dev->devt))
779 class_device_remove_file(class_dev, class_dev->devt_attr); 765 class_device_remove_file(class_dev, &class_devt_attr);
780 class_device_remove_attrs(class_dev); 766 class_device_remove_attrs(class_dev);
781 class_device_remove_groups(class_dev); 767 class_device_remove_groups(class_dev);
782 768
diff --git a/drivers/base/core.c b/drivers/base/core.c
index dd40d78a023d..0455aa78fa13 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -310,6 +310,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
310 return count; 310 return count;
311} 311}
312 312
313static struct device_attribute uevent_attr =
314 __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
315
313static int device_add_attributes(struct device *dev, 316static int device_add_attributes(struct device *dev,
314 struct device_attribute *attrs) 317 struct device_attribute *attrs)
315{ 318{
@@ -423,6 +426,9 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
423 return print_dev_t(buf, dev->devt); 426 return print_dev_t(buf, dev->devt);
424} 427}
425 428
429static struct device_attribute devt_attr =
430 __ATTR(dev, S_IRUGO, show_dev, NULL);
431
426/* 432/*
427 * devices_subsys - structure to be registered with kobject core. 433 * devices_subsys - structure to be registered with kobject core.
428 */ 434 */
@@ -681,35 +687,14 @@ int device_add(struct device *dev)
681 blocking_notifier_call_chain(&dev->bus->bus_notifier, 687 blocking_notifier_call_chain(&dev->bus->bus_notifier,
682 BUS_NOTIFY_ADD_DEVICE, dev); 688 BUS_NOTIFY_ADD_DEVICE, dev);
683 689
684 dev->uevent_attr.attr.name = "uevent"; 690 error = device_create_file(dev, &uevent_attr);
685 dev->uevent_attr.attr.mode = S_IRUGO | S_IWUSR;
686 if (dev->driver)
687 dev->uevent_attr.attr.owner = dev->driver->owner;
688 dev->uevent_attr.store = store_uevent;
689 dev->uevent_attr.show = show_uevent;
690 error = device_create_file(dev, &dev->uevent_attr);
691 if (error) 691 if (error)
692 goto attrError; 692 goto attrError;
693 693
694 if (MAJOR(dev->devt)) { 694 if (MAJOR(dev->devt)) {
695 struct device_attribute *attr; 695 error = device_create_file(dev, &devt_attr);
696 attr = kzalloc(sizeof(*attr), GFP_KERNEL); 696 if (error)
697 if (!attr) {
698 error = -ENOMEM;
699 goto ueventattrError;
700 }
701 attr->attr.name = "dev";
702 attr->attr.mode = S_IRUGO;
703 if (dev->driver)
704 attr->attr.owner = dev->driver->owner;
705 attr->show = show_dev;
706 error = device_create_file(dev, attr);
707 if (error) {
708 kfree(attr);
709 goto ueventattrError; 697 goto ueventattrError;
710 }
711
712 dev->devt_attr = attr;
713 } 698 }
714 699
715 if (dev->class) { 700 if (dev->class) {
@@ -733,11 +718,14 @@ int device_add(struct device *dev)
733 } 718 }
734 } 719 }
735 720
736 if ((error = device_add_attrs(dev))) 721 error = device_add_attrs(dev);
722 if (error)
737 goto AttrsError; 723 goto AttrsError;
738 if ((error = device_pm_add(dev))) 724 error = device_pm_add(dev);
725 if (error)
739 goto PMError; 726 goto PMError;
740 if ((error = bus_add_device(dev))) 727 error = bus_add_device(dev);
728 if (error)
741 goto BusError; 729 goto BusError;
742 kobject_uevent(&dev->kobj, KOBJ_ADD); 730 kobject_uevent(&dev->kobj, KOBJ_ADD);
743 bus_attach_device(dev); 731 bus_attach_device(dev);
@@ -767,10 +755,8 @@ int device_add(struct device *dev)
767 BUS_NOTIFY_DEL_DEVICE, dev); 755 BUS_NOTIFY_DEL_DEVICE, dev);
768 device_remove_attrs(dev); 756 device_remove_attrs(dev);
769 AttrsError: 757 AttrsError:
770 if (dev->devt_attr) { 758 if (MAJOR(dev->devt))
771 device_remove_file(dev, dev->devt_attr); 759 device_remove_file(dev, &devt_attr);
772 kfree(dev->devt_attr);
773 }
774 760
775 if (dev->class) { 761 if (dev->class) {
776 sysfs_remove_link(&dev->kobj, "subsystem"); 762 sysfs_remove_link(&dev->kobj, "subsystem");
@@ -792,7 +778,7 @@ int device_add(struct device *dev)
792 } 778 }
793 } 779 }
794 ueventattrError: 780 ueventattrError:
795 device_remove_file(dev, &dev->uevent_attr); 781 device_remove_file(dev, &uevent_attr);
796 attrError: 782 attrError:
797 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 783 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
798 kobject_del(&dev->kobj); 784 kobject_del(&dev->kobj);
@@ -869,10 +855,8 @@ void device_del(struct device * dev)
869 855
870 if (parent) 856 if (parent)
871 klist_del(&dev->knode_parent); 857 klist_del(&dev->knode_parent);
872 if (dev->devt_attr) { 858 if (MAJOR(dev->devt))
873 device_remove_file(dev, dev->devt_attr); 859 device_remove_file(dev, &devt_attr);
874 kfree(dev->devt_attr);
875 }
876 if (dev->class) { 860 if (dev->class) {
877 sysfs_remove_link(&dev->kobj, "subsystem"); 861 sysfs_remove_link(&dev->kobj, "subsystem");
878 /* If this is not a "fake" compatible device, remove the 862 /* If this is not a "fake" compatible device, remove the
@@ -926,7 +910,7 @@ void device_del(struct device * dev)
926 up(&dev->class->sem); 910 up(&dev->class->sem);
927 } 911 }
928 } 912 }
929 device_remove_file(dev, &dev->uevent_attr); 913 device_remove_file(dev, &uevent_attr);
930 device_remove_attrs(dev); 914 device_remove_attrs(dev);
931 bus_remove_device(dev); 915 bus_remove_device(dev);
932 916
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index b0088b0efecd..7ac474db88c5 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -281,24 +281,16 @@ int driver_attach(struct device_driver * drv)
281 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); 281 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
282} 282}
283 283
284/** 284/*
285 * device_release_driver - manually detach device from driver.
286 * @dev: device.
287 *
288 * Manually detach device from driver.
289 *
290 * __device_release_driver() must be called with @dev->sem held. 285 * __device_release_driver() must be called with @dev->sem held.
291 * When called for a USB interface, @dev->parent->sem must be held 286 * When called for a USB interface, @dev->parent->sem must be held as well.
292 * as well.
293 */ 287 */
294
295static void __device_release_driver(struct device * dev) 288static void __device_release_driver(struct device * dev)
296{ 289{
297 struct device_driver * drv; 290 struct device_driver * drv;
298 291
299 drv = dev->driver; 292 drv = get_driver(dev->driver);
300 if (drv) { 293 if (drv) {
301 get_driver(drv);
302 driver_sysfs_remove(dev); 294 driver_sysfs_remove(dev);
303 sysfs_remove_link(&dev->kobj, "driver"); 295 sysfs_remove_link(&dev->kobj, "driver");
304 klist_remove(&dev->knode_driver); 296 klist_remove(&dev->knode_driver);
@@ -318,6 +310,13 @@ static void __device_release_driver(struct device * dev)
318 } 310 }
319} 311}
320 312
313/**
314 * device_release_driver - manually detach device from driver.
315 * @dev: device.
316 *
317 * Manually detach device from driver.
318 * When called for a USB interface, @dev->parent->sem must be held.
319 */
321void device_release_driver(struct device * dev) 320void device_release_driver(struct device * dev)
322{ 321{
323 /* 322 /*
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index e1c0730a3b99..e8beb8e5b626 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -10,6 +10,8 @@
10#include <linux/device.h> 10#include <linux/device.h>
11#include <linux/module.h> 11#include <linux/module.h>
12 12
13#include "base.h"
14
13struct devres_node { 15struct devres_node {
14 struct list_head entry; 16 struct list_head entry;
15 dr_release_t release; 17 dr_release_t release;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 89a5f4a54913..53f0ee6f3016 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -175,7 +175,7 @@ static ssize_t firmware_loading_store(struct device *dev,
175static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store); 175static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
176 176
177static ssize_t 177static ssize_t
178firmware_data_read(struct kobject *kobj, 178firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
179 char *buffer, loff_t offset, size_t count) 179 char *buffer, loff_t offset, size_t count)
180{ 180{
181 struct device *dev = to_dev(kobj); 181 struct device *dev = to_dev(kobj);
@@ -240,7 +240,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
240 * the driver as a firmware image. 240 * the driver as a firmware image.
241 **/ 241 **/
242static ssize_t 242static ssize_t
243firmware_data_write(struct kobject *kobj, 243firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr,
244 char *buffer, loff_t offset, size_t count) 244 char *buffer, loff_t offset, size_t count)
245{ 245{
246 struct device *dev = to_dev(kobj); 246 struct device *dev = to_dev(kobj);
@@ -271,7 +271,7 @@ out:
271} 271}
272 272
273static struct bin_attribute firmware_attr_data_tmpl = { 273static struct bin_attribute firmware_attr_data_tmpl = {
274 .attr = {.name = "data", .mode = 0644, .owner = THIS_MODULE}, 274 .attr = {.name = "data", .mode = 0644},
275 .size = 0, 275 .size = 0,
276 .read = firmware_data_read, 276 .read = firmware_data_read,
277 .write = firmware_data_write, 277 .write = firmware_data_write,
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 05dc8764e765..eb9f38d0aa58 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -20,64 +20,44 @@
20 */ 20 */
21 21
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/mutex.h>
24
23#include "power.h" 25#include "power.h"
24 26
25LIST_HEAD(dpm_active); 27LIST_HEAD(dpm_active);
26LIST_HEAD(dpm_off); 28LIST_HEAD(dpm_off);
27LIST_HEAD(dpm_off_irq); 29LIST_HEAD(dpm_off_irq);
28 30
29DECLARE_MUTEX(dpm_sem); 31DEFINE_MUTEX(dpm_mtx);
30DECLARE_MUTEX(dpm_list_sem); 32DEFINE_MUTEX(dpm_list_mtx);
31 33
32int (*platform_enable_wakeup)(struct device *dev, int is_on); 34int (*platform_enable_wakeup)(struct device *dev, int is_on);
33 35
34 36int device_pm_add(struct device *dev)
35/**
36 * device_pm_set_parent - Specify power dependency.
37 * @dev: Device who needs power.
38 * @parent: Device that supplies power.
39 *
40 * This function is used to manually describe a power-dependency
41 * relationship. It may be used to specify a transversal relationship
42 * (where the power supplier is not the physical (or electrical)
43 * ancestor of a specific device.
44 * The effect of this is that the supplier will not be powered down
45 * before the power dependent.
46 */
47
48void device_pm_set_parent(struct device * dev, struct device * parent)
49{
50 put_device(dev->power.pm_parent);
51 dev->power.pm_parent = get_device(parent);
52}
53EXPORT_SYMBOL_GPL(device_pm_set_parent);
54
55int device_pm_add(struct device * dev)
56{ 37{
57 int error; 38 int error;
58 39
59 pr_debug("PM: Adding info for %s:%s\n", 40 pr_debug("PM: Adding info for %s:%s\n",
60 dev->bus ? dev->bus->name : "No Bus", 41 dev->bus ? dev->bus->name : "No Bus",
61 kobject_name(&dev->kobj)); 42 kobject_name(&dev->kobj));
62 down(&dpm_list_sem); 43 mutex_lock(&dpm_list_mtx);
63 list_add_tail(&dev->power.entry, &dpm_active); 44 list_add_tail(&dev->power.entry, &dpm_active);
64 device_pm_set_parent(dev, dev->parent); 45 error = dpm_sysfs_add(dev);
65 if ((error = dpm_sysfs_add(dev))) 46 if (error)
66 list_del(&dev->power.entry); 47 list_del(&dev->power.entry);
67 up(&dpm_list_sem); 48 mutex_unlock(&dpm_list_mtx);
68 return error; 49 return error;
69} 50}
70 51
71void device_pm_remove(struct device * dev) 52void device_pm_remove(struct device *dev)
72{ 53{
73 pr_debug("PM: Removing info for %s:%s\n", 54 pr_debug("PM: Removing info for %s:%s\n",
74 dev->bus ? dev->bus->name : "No Bus", 55 dev->bus ? dev->bus->name : "No Bus",
75 kobject_name(&dev->kobj)); 56 kobject_name(&dev->kobj));
76 down(&dpm_list_sem); 57 mutex_lock(&dpm_list_mtx);
77 dpm_sysfs_remove(dev); 58 dpm_sysfs_remove(dev);
78 put_device(dev->power.pm_parent);
79 list_del_init(&dev->power.entry); 59 list_del_init(&dev->power.entry);
80 up(&dpm_list_sem); 60 mutex_unlock(&dpm_list_mtx);
81} 61}
82 62
83 63
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index fb3d35a9e101..2760f25b3ac5 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -14,12 +14,12 @@ extern void device_shutdown(void);
14/* 14/*
15 * Used to synchronize global power management operations. 15 * Used to synchronize global power management operations.
16 */ 16 */
17extern struct semaphore dpm_sem; 17extern struct mutex dpm_mtx;
18 18
19/* 19/*
20 * Used to serialize changes to the dpm_* lists. 20 * Used to serialize changes to the dpm_* lists.
21 */ 21 */
22extern struct semaphore dpm_list_sem; 22extern struct mutex dpm_list_mtx;
23 23
24/* 24/*
25 * The PM lists. 25 * The PM lists.
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index a2c64188d713..00fd84ae6e66 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -29,14 +29,6 @@ int resume_device(struct device * dev)
29 29
30 down(&dev->sem); 30 down(&dev->sem);
31 31
32 if (dev->power.pm_parent
33 && dev->power.pm_parent->power.power_state.event) {
34 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
35 dev->power.power_state.event,
36 dev->power.pm_parent->bus_id,
37 dev->power.pm_parent->power.power_state.event);
38 }
39
40 if (dev->bus && dev->bus->resume) { 32 if (dev->bus && dev->bus->resume) {
41 dev_dbg(dev,"resuming\n"); 33 dev_dbg(dev,"resuming\n");
42 error = dev->bus->resume(dev); 34 error = dev->bus->resume(dev);
@@ -80,7 +72,7 @@ static int resume_device_early(struct device * dev)
80 */ 72 */
81void dpm_resume(void) 73void dpm_resume(void)
82{ 74{
83 down(&dpm_list_sem); 75 mutex_lock(&dpm_list_mtx);
84 while(!list_empty(&dpm_off)) { 76 while(!list_empty(&dpm_off)) {
85 struct list_head * entry = dpm_off.next; 77 struct list_head * entry = dpm_off.next;
86 struct device * dev = to_device(entry); 78 struct device * dev = to_device(entry);
@@ -88,13 +80,12 @@ void dpm_resume(void)
88 get_device(dev); 80 get_device(dev);
89 list_move_tail(entry, &dpm_active); 81 list_move_tail(entry, &dpm_active);
90 82
91 up(&dpm_list_sem); 83 mutex_unlock(&dpm_list_mtx);
92 if (!dev->power.prev_state.event) 84 resume_device(dev);
93 resume_device(dev); 85 mutex_lock(&dpm_list_mtx);
94 down(&dpm_list_sem);
95 put_device(dev); 86 put_device(dev);
96 } 87 }
97 up(&dpm_list_sem); 88 mutex_unlock(&dpm_list_mtx);
98} 89}
99 90
100 91
@@ -108,9 +99,9 @@ void dpm_resume(void)
108void device_resume(void) 99void device_resume(void)
109{ 100{
110 might_sleep(); 101 might_sleep();
111 down(&dpm_sem); 102 mutex_lock(&dpm_mtx);
112 dpm_resume(); 103 dpm_resume();
113 up(&dpm_sem); 104 mutex_unlock(&dpm_mtx);
114} 105}
115 106
116EXPORT_SYMBOL_GPL(device_resume); 107EXPORT_SYMBOL_GPL(device_resume);
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 96370ec1d673..df6174d85866 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -32,9 +32,9 @@ static void runtime_resume(struct device * dev)
32 32
33void dpm_runtime_resume(struct device * dev) 33void dpm_runtime_resume(struct device * dev)
34{ 34{
35 down(&dpm_sem); 35 mutex_lock(&dpm_mtx);
36 runtime_resume(dev); 36 runtime_resume(dev);
37 up(&dpm_sem); 37 mutex_unlock(&dpm_mtx);
38} 38}
39EXPORT_SYMBOL(dpm_runtime_resume); 39EXPORT_SYMBOL(dpm_runtime_resume);
40 40
@@ -49,7 +49,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
49{ 49{
50 int error = 0; 50 int error = 0;
51 51
52 down(&dpm_sem); 52 mutex_lock(&dpm_mtx);
53 if (dev->power.power_state.event == state.event) 53 if (dev->power.power_state.event == state.event)
54 goto Done; 54 goto Done;
55 55
@@ -59,7 +59,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
59 if (!(error = suspend_device(dev, state))) 59 if (!(error = suspend_device(dev, state)))
60 dev->power.power_state = state; 60 dev->power.power_state = state;
61 Done: 61 Done:
62 up(&dpm_sem); 62 mutex_unlock(&dpm_mtx);
63 return error; 63 return error;
64} 64}
65EXPORT_SYMBOL(dpm_runtime_suspend); 65EXPORT_SYMBOL(dpm_runtime_suspend);
@@ -78,8 +78,8 @@ EXPORT_SYMBOL(dpm_runtime_suspend);
78 */ 78 */
79void dpm_set_power_state(struct device * dev, pm_message_t state) 79void dpm_set_power_state(struct device * dev, pm_message_t state)
80{ 80{
81 down(&dpm_sem); 81 mutex_lock(&dpm_mtx);
82 dev->power.power_state = state; 82 dev->power.power_state = state;
83 up(&dpm_sem); 83 mutex_unlock(&dpm_mtx);
84} 84}
85#endif /* 0 */ 85#endif /* 0 */
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index 42d2b86ba765..26df9b231737 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -40,6 +40,14 @@ static inline char *suspend_verb(u32 event)
40} 40}
41 41
42 42
43static void
44suspend_device_dbg(struct device *dev, pm_message_t state, char *info)
45{
46 dev_dbg(dev, "%s%s%s\n", info, suspend_verb(state.event),
47 ((state.event == PM_EVENT_SUSPEND) && device_may_wakeup(dev)) ?
48 ", may wakeup" : "");
49}
50
43/** 51/**
44 * suspend_device - Save state of one device. 52 * suspend_device - Save state of one device.
45 * @dev: Device. 53 * @dev: Device.
@@ -55,49 +63,21 @@ int suspend_device(struct device * dev, pm_message_t state)
55 dev_dbg(dev, "PM: suspend %d-->%d\n", 63 dev_dbg(dev, "PM: suspend %d-->%d\n",
56 dev->power.power_state.event, state.event); 64 dev->power.power_state.event, state.event);
57 } 65 }
58 if (dev->power.pm_parent
59 && dev->power.pm_parent->power.power_state.event) {
60 dev_err(dev,
61 "PM: suspend %d->%d, parent %s already %d\n",
62 dev->power.power_state.event, state.event,
63 dev->power.pm_parent->bus_id,
64 dev->power.pm_parent->power.power_state.event);
65 }
66
67 dev->power.prev_state = dev->power.power_state;
68 66
69 if (dev->class && dev->class->suspend && !dev->power.power_state.event) { 67 if (dev->class && dev->class->suspend) {
70 dev_dbg(dev, "class %s%s\n", 68 suspend_device_dbg(dev, state, "class ");
71 suspend_verb(state.event),
72 ((state.event == PM_EVENT_SUSPEND)
73 && device_may_wakeup(dev))
74 ? ", may wakeup"
75 : ""
76 );
77 error = dev->class->suspend(dev, state); 69 error = dev->class->suspend(dev, state);
78 suspend_report_result(dev->class->suspend, error); 70 suspend_report_result(dev->class->suspend, error);
79 } 71 }
80 72
81 if (!error && dev->type && dev->type->suspend && !dev->power.power_state.event) { 73 if (!error && dev->type && dev->type->suspend) {
82 dev_dbg(dev, "%s%s\n", 74 suspend_device_dbg(dev, state, "type ");
83 suspend_verb(state.event),
84 ((state.event == PM_EVENT_SUSPEND)
85 && device_may_wakeup(dev))
86 ? ", may wakeup"
87 : ""
88 );
89 error = dev->type->suspend(dev, state); 75 error = dev->type->suspend(dev, state);
90 suspend_report_result(dev->type->suspend, error); 76 suspend_report_result(dev->type->suspend, error);
91 } 77 }
92 78
93 if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) { 79 if (!error && dev->bus && dev->bus->suspend) {
94 dev_dbg(dev, "%s%s\n", 80 suspend_device_dbg(dev, state, "");
95 suspend_verb(state.event),
96 ((state.event == PM_EVENT_SUSPEND)
97 && device_may_wakeup(dev))
98 ? ", may wakeup"
99 : ""
100 );
101 error = dev->bus->suspend(dev, state); 81 error = dev->bus->suspend(dev, state);
102 suspend_report_result(dev->bus->suspend, error); 82 suspend_report_result(dev->bus->suspend, error);
103 } 83 }
@@ -108,21 +88,15 @@ int suspend_device(struct device * dev, pm_message_t state)
108 88
109/* 89/*
110 * This is called with interrupts off, only a single CPU 90 * This is called with interrupts off, only a single CPU
111 * running. We can't do down() on a semaphore (and we don't 91 * running. We can't acquire a mutex or semaphore (and we don't
112 * need the protection) 92 * need the protection)
113 */ 93 */
114static int suspend_device_late(struct device *dev, pm_message_t state) 94static int suspend_device_late(struct device *dev, pm_message_t state)
115{ 95{
116 int error = 0; 96 int error = 0;
117 97
118 if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) { 98 if (dev->bus && dev->bus->suspend_late) {
119 dev_dbg(dev, "LATE %s%s\n", 99 suspend_device_dbg(dev, state, "LATE ");
120 suspend_verb(state.event),
121 ((state.event == PM_EVENT_SUSPEND)
122 && device_may_wakeup(dev))
123 ? ", may wakeup"
124 : ""
125 );
126 error = dev->bus->suspend_late(dev, state); 100 error = dev->bus->suspend_late(dev, state);
127 suspend_report_result(dev->bus->suspend_late, error); 101 suspend_report_result(dev->bus->suspend_late, error);
128 } 102 }
@@ -153,18 +127,18 @@ int device_suspend(pm_message_t state)
153 int error = 0; 127 int error = 0;
154 128
155 might_sleep(); 129 might_sleep();
156 down(&dpm_sem); 130 mutex_lock(&dpm_mtx);
157 down(&dpm_list_sem); 131 mutex_lock(&dpm_list_mtx);
158 while (!list_empty(&dpm_active) && error == 0) { 132 while (!list_empty(&dpm_active) && error == 0) {
159 struct list_head * entry = dpm_active.prev; 133 struct list_head * entry = dpm_active.prev;
160 struct device * dev = to_device(entry); 134 struct device * dev = to_device(entry);
161 135
162 get_device(dev); 136 get_device(dev);
163 up(&dpm_list_sem); 137 mutex_unlock(&dpm_list_mtx);
164 138
165 error = suspend_device(dev, state); 139 error = suspend_device(dev, state);
166 140
167 down(&dpm_list_sem); 141 mutex_lock(&dpm_list_mtx);
168 142
169 /* Check if the device got removed */ 143 /* Check if the device got removed */
170 if (!list_empty(&dev->power.entry)) { 144 if (!list_empty(&dev->power.entry)) {
@@ -179,11 +153,11 @@ int device_suspend(pm_message_t state)
179 error == -EAGAIN ? " (please convert to suspend_late)" : ""); 153 error == -EAGAIN ? " (please convert to suspend_late)" : "");
180 put_device(dev); 154 put_device(dev);
181 } 155 }
182 up(&dpm_list_sem); 156 mutex_unlock(&dpm_list_mtx);
183 if (error) 157 if (error)
184 dpm_resume(); 158 dpm_resume();
185 159
186 up(&dpm_sem); 160 mutex_unlock(&dpm_mtx);
187 return error; 161 return error;
188} 162}
189 163
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 29f1291966c1..18febe26caa1 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -21,7 +21,7 @@
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/device.h> 23#include <linux/device.h>
24#include <asm/semaphore.h> 24#include <linux/mutex.h>
25 25
26#include "base.h" 26#include "base.h"
27 27
@@ -155,7 +155,7 @@ EXPORT_SYMBOL_GPL(sysdev_class_unregister);
155 155
156 156
157static LIST_HEAD(sysdev_drivers); 157static LIST_HEAD(sysdev_drivers);
158static DECLARE_MUTEX(sysdev_drivers_lock); 158static DEFINE_MUTEX(sysdev_drivers_lock);
159 159
160/** 160/**
161 * sysdev_driver_register - Register auxillary driver 161 * sysdev_driver_register - Register auxillary driver
@@ -172,7 +172,7 @@ static DECLARE_MUTEX(sysdev_drivers_lock);
172int sysdev_driver_register(struct sysdev_class * cls, 172int sysdev_driver_register(struct sysdev_class * cls,
173 struct sysdev_driver * drv) 173 struct sysdev_driver * drv)
174{ 174{
175 down(&sysdev_drivers_lock); 175 mutex_lock(&sysdev_drivers_lock);
176 if (cls && kset_get(&cls->kset)) { 176 if (cls && kset_get(&cls->kset)) {
177 list_add_tail(&drv->entry, &cls->drivers); 177 list_add_tail(&drv->entry, &cls->drivers);
178 178
@@ -184,7 +184,7 @@ int sysdev_driver_register(struct sysdev_class * cls,
184 } 184 }
185 } else 185 } else
186 list_add_tail(&drv->entry, &sysdev_drivers); 186 list_add_tail(&drv->entry, &sysdev_drivers);
187 up(&sysdev_drivers_lock); 187 mutex_unlock(&sysdev_drivers_lock);
188 return 0; 188 return 0;
189} 189}
190 190
@@ -197,7 +197,7 @@ int sysdev_driver_register(struct sysdev_class * cls,
197void sysdev_driver_unregister(struct sysdev_class * cls, 197void sysdev_driver_unregister(struct sysdev_class * cls,
198 struct sysdev_driver * drv) 198 struct sysdev_driver * drv)
199{ 199{
200 down(&sysdev_drivers_lock); 200 mutex_lock(&sysdev_drivers_lock);
201 list_del_init(&drv->entry); 201 list_del_init(&drv->entry);
202 if (cls) { 202 if (cls) {
203 if (drv->remove) { 203 if (drv->remove) {
@@ -207,7 +207,7 @@ void sysdev_driver_unregister(struct sysdev_class * cls,
207 } 207 }
208 kset_put(&cls->kset); 208 kset_put(&cls->kset);
209 } 209 }
210 up(&sysdev_drivers_lock); 210 mutex_unlock(&sysdev_drivers_lock);
211} 211}
212 212
213EXPORT_SYMBOL_GPL(sysdev_driver_register); 213EXPORT_SYMBOL_GPL(sysdev_driver_register);
@@ -246,7 +246,7 @@ int sysdev_register(struct sys_device * sysdev)
246 if (!error) { 246 if (!error) {
247 struct sysdev_driver * drv; 247 struct sysdev_driver * drv;
248 248
249 down(&sysdev_drivers_lock); 249 mutex_lock(&sysdev_drivers_lock);
250 /* Generic notification is implicit, because it's that 250 /* Generic notification is implicit, because it's that
251 * code that should have called us. 251 * code that should have called us.
252 */ 252 */
@@ -262,7 +262,7 @@ int sysdev_register(struct sys_device * sysdev)
262 if (drv->add) 262 if (drv->add)
263 drv->add(sysdev); 263 drv->add(sysdev);
264 } 264 }
265 up(&sysdev_drivers_lock); 265 mutex_unlock(&sysdev_drivers_lock);
266 } 266 }
267 return error; 267 return error;
268} 268}
@@ -271,7 +271,7 @@ void sysdev_unregister(struct sys_device * sysdev)
271{ 271{
272 struct sysdev_driver * drv; 272 struct sysdev_driver * drv;
273 273
274 down(&sysdev_drivers_lock); 274 mutex_lock(&sysdev_drivers_lock);
275 list_for_each_entry(drv, &sysdev_drivers, entry) { 275 list_for_each_entry(drv, &sysdev_drivers, entry) {
276 if (drv->remove) 276 if (drv->remove)
277 drv->remove(sysdev); 277 drv->remove(sysdev);
@@ -281,7 +281,7 @@ void sysdev_unregister(struct sys_device * sysdev)
281 if (drv->remove) 281 if (drv->remove)
282 drv->remove(sysdev); 282 drv->remove(sysdev);
283 } 283 }
284 up(&sysdev_drivers_lock); 284 mutex_unlock(&sysdev_drivers_lock);
285 285
286 kobject_unregister(&sysdev->kobj); 286 kobject_unregister(&sysdev->kobj);
287} 287}
@@ -308,7 +308,7 @@ void sysdev_shutdown(void)
308 308
309 pr_debug("Shutting Down System Devices\n"); 309 pr_debug("Shutting Down System Devices\n");
310 310
311 down(&sysdev_drivers_lock); 311 mutex_lock(&sysdev_drivers_lock);
312 list_for_each_entry_reverse(cls, &system_subsys.list, 312 list_for_each_entry_reverse(cls, &system_subsys.list,
313 kset.kobj.entry) { 313 kset.kobj.entry) {
314 struct sys_device * sysdev; 314 struct sys_device * sysdev;
@@ -337,7 +337,7 @@ void sysdev_shutdown(void)
337 cls->shutdown(sysdev); 337 cls->shutdown(sysdev);
338 } 338 }
339 } 339 }
340 up(&sysdev_drivers_lock); 340 mutex_unlock(&sysdev_drivers_lock);
341} 341}
342 342
343static void __sysdev_resume(struct sys_device *dev) 343static void __sysdev_resume(struct sys_device *dev)
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index f1b9dd7d47d6..ce64e86d6ffb 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -146,8 +146,7 @@ static void pkt_kobj_release(struct kobject *kobj)
146 **********************************************************/ 146 **********************************************************/
147 147
148#define DEF_ATTR(_obj,_name,_mode) \ 148#define DEF_ATTR(_obj,_name,_mode) \
149 static struct attribute _obj = { \ 149 static struct attribute _obj = { .name = _name, .mode = _mode }
150 .name = _name, .owner = THIS_MODULE, .mode = _mode }
151 150
152/********************************************************** 151/**********************************************************
153 /sys/class/pktcdvd/pktcdvd[0-7]/ 152 /sys/class/pktcdvd/pktcdvd[0-7]/
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index 7e04dd69f609..59b054810ed0 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -199,7 +199,6 @@ static void hci_usb_tx_complete(struct urb *urb);
199#define __pending_q(husb, type) (&husb->pending_q[type-1]) 199#define __pending_q(husb, type) (&husb->pending_q[type-1])
200#define __completed_q(husb, type) (&husb->completed_q[type-1]) 200#define __completed_q(husb, type) (&husb->completed_q[type-1])
201#define __transmit_q(husb, type) (&husb->transmit_q[type-1]) 201#define __transmit_q(husb, type) (&husb->transmit_q[type-1])
202#define __reassembly(husb, type) (husb->reassembly[type-1])
203 202
204static inline struct _urb *__get_completed(struct hci_usb *husb, int type) 203static inline struct _urb *__get_completed(struct hci_usb *husb, int type)
205{ 204{
@@ -429,12 +428,6 @@ static void hci_usb_unlink_urbs(struct hci_usb *husb)
429 kfree(urb->transfer_buffer); 428 kfree(urb->transfer_buffer);
430 _urb_free(_urb); 429 _urb_free(_urb);
431 } 430 }
432
433 /* Release reassembly buffers */
434 if (husb->reassembly[i]) {
435 kfree_skb(husb->reassembly[i]);
436 husb->reassembly[i] = NULL;
437 }
438 } 431 }
439} 432}
440 433
@@ -671,83 +664,6 @@ static int hci_usb_send_frame(struct sk_buff *skb)
671 return 0; 664 return 0;
672} 665}
673 666
674static inline int __recv_frame(struct hci_usb *husb, int type, void *data, int count)
675{
676 BT_DBG("%s type %d data %p count %d", husb->hdev->name, type, data, count);
677
678 husb->hdev->stat.byte_rx += count;
679
680 while (count) {
681 struct sk_buff *skb = __reassembly(husb, type);
682 struct { int expect; } *scb;
683 int len = 0;
684
685 if (!skb) {
686 /* Start of the frame */
687
688 switch (type) {
689 case HCI_EVENT_PKT:
690 if (count >= HCI_EVENT_HDR_SIZE) {
691 struct hci_event_hdr *h = data;
692 len = HCI_EVENT_HDR_SIZE + h->plen;
693 } else
694 return -EILSEQ;
695 break;
696
697 case HCI_ACLDATA_PKT:
698 if (count >= HCI_ACL_HDR_SIZE) {
699 struct hci_acl_hdr *h = data;
700 len = HCI_ACL_HDR_SIZE + __le16_to_cpu(h->dlen);
701 } else
702 return -EILSEQ;
703 break;
704#ifdef CONFIG_BT_HCIUSB_SCO
705 case HCI_SCODATA_PKT:
706 if (count >= HCI_SCO_HDR_SIZE) {
707 struct hci_sco_hdr *h = data;
708 len = HCI_SCO_HDR_SIZE + h->dlen;
709 } else
710 return -EILSEQ;
711 break;
712#endif
713 }
714 BT_DBG("new packet len %d", len);
715
716 skb = bt_skb_alloc(len, GFP_ATOMIC);
717 if (!skb) {
718 BT_ERR("%s no memory for the packet", husb->hdev->name);
719 return -ENOMEM;
720 }
721 skb->dev = (void *) husb->hdev;
722 bt_cb(skb)->pkt_type = type;
723
724 __reassembly(husb, type) = skb;
725
726 scb = (void *) skb->cb;
727 scb->expect = len;
728 } else {
729 /* Continuation */
730 scb = (void *) skb->cb;
731 len = scb->expect;
732 }
733
734 len = min(len, count);
735
736 memcpy(skb_put(skb, len), data, len);
737
738 scb->expect -= len;
739 if (!scb->expect) {
740 /* Complete frame */
741 __reassembly(husb, type) = NULL;
742 bt_cb(skb)->pkt_type = type;
743 hci_recv_frame(skb);
744 }
745
746 count -= len; data += len;
747 }
748 return 0;
749}
750
751static void hci_usb_rx_complete(struct urb *urb) 667static void hci_usb_rx_complete(struct urb *urb)
752{ 668{
753 struct _urb *_urb = container_of(urb, struct _urb, urb); 669 struct _urb *_urb = container_of(urb, struct _urb, urb);
@@ -776,7 +692,7 @@ static void hci_usb_rx_complete(struct urb *urb)
776 urb->iso_frame_desc[i].actual_length); 692 urb->iso_frame_desc[i].actual_length);
777 693
778 if (!urb->iso_frame_desc[i].status) 694 if (!urb->iso_frame_desc[i].status)
779 __recv_frame(husb, _urb->type, 695 hci_recv_fragment(husb->hdev, _urb->type,
780 urb->transfer_buffer + urb->iso_frame_desc[i].offset, 696 urb->transfer_buffer + urb->iso_frame_desc[i].offset,
781 urb->iso_frame_desc[i].actual_length); 697 urb->iso_frame_desc[i].actual_length);
782 } 698 }
@@ -784,7 +700,7 @@ static void hci_usb_rx_complete(struct urb *urb)
784 ; 700 ;
785#endif 701#endif
786 } else { 702 } else {
787 err = __recv_frame(husb, _urb->type, urb->transfer_buffer, count); 703 err = hci_recv_fragment(husb->hdev, _urb->type, urb->transfer_buffer, count);
788 if (err < 0) { 704 if (err < 0) {
789 BT_ERR("%s corrupted packet: type %d count %d", 705 BT_ERR("%s corrupted packet: type %d count %d",
790 husb->hdev->name, _urb->type, count); 706 husb->hdev->name, _urb->type, count);
diff --git a/drivers/bluetooth/hci_usb.h b/drivers/bluetooth/hci_usb.h
index 963fc55cdc85..56cd3a92ceca 100644
--- a/drivers/bluetooth/hci_usb.h
+++ b/drivers/bluetooth/hci_usb.h
@@ -102,9 +102,9 @@ struct hci_usb {
102 struct hci_dev *hdev; 102 struct hci_dev *hdev;
103 103
104 unsigned long state; 104 unsigned long state;
105 105
106 struct usb_device *udev; 106 struct usb_device *udev;
107 107
108 struct usb_host_endpoint *bulk_in_ep; 108 struct usb_host_endpoint *bulk_in_ep;
109 struct usb_host_endpoint *bulk_out_ep; 109 struct usb_host_endpoint *bulk_out_ep;
110 struct usb_host_endpoint *intr_in_ep; 110 struct usb_host_endpoint *intr_in_ep;
@@ -116,7 +116,6 @@ struct hci_usb {
116 __u8 ctrl_req; 116 __u8 ctrl_req;
117 117
118 struct sk_buff_head transmit_q[4]; 118 struct sk_buff_head transmit_q[4];
119 struct sk_buff *reassembly[4]; /* Reassembly buffers */
120 119
121 rwlock_t completion_lock; 120 rwlock_t completion_lock;
122 121
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index b71a5ccc587f..0638730a4a19 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -180,11 +180,6 @@ static inline ssize_t vhci_put_user(struct vhci_data *data,
180 return total; 180 return total;
181} 181}
182 182
183static loff_t vhci_llseek(struct file *file, loff_t offset, int origin)
184{
185 return -ESPIPE;
186}
187
188static ssize_t vhci_read(struct file *file, 183static ssize_t vhci_read(struct file *file,
189 char __user *buf, size_t count, loff_t *pos) 184 char __user *buf, size_t count, loff_t *pos)
190{ 185{
@@ -334,7 +329,6 @@ static int vhci_fasync(int fd, struct file *file, int on)
334 329
335static const struct file_operations vhci_fops = { 330static const struct file_operations vhci_fops = {
336 .owner = THIS_MODULE, 331 .owner = THIS_MODULE,
337 .llseek = vhci_llseek,
338 .read = vhci_read, 332 .read = vhci_read,
339 .write = vhci_write, 333 .write = vhci_write,
340 .poll = vhci_poll, 334 .poll = vhci_poll,
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index ef683ebd367c..a31c6d2c061f 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -815,7 +815,7 @@ config SGI_IP27_RTC
815 815
816config GEN_RTC 816config GEN_RTC
817 tristate "Generic /dev/rtc emulation" 817 tristate "Generic /dev/rtc emulation"
818 depends on RTC!=y && !IA64 && !ARM && !M32R && !SPARC && !FRV && !S390 && !SUPERH 818 depends on RTC!=y && !IA64 && !ARM && !M32R && !MIPS && !SPARC && !FRV && !S390 && !SUPERH
819 ---help--- 819 ---help---
820 If you say Y here and create a character special file /dev/rtc with 820 If you say Y here and create a character special file /dev/rtc with
821 major number 10 and minor number 135 using mknod ("man mknod"), you 821 major number 10 and minor number 135 using mknod ("man mknod"), you
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 8e222f2b80cc..b5df7e61aeb2 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2171,52 +2171,42 @@ static int create_files(struct bmc_device *bmc)
2171 int err; 2171 int err;
2172 2172
2173 bmc->device_id_attr.attr.name = "device_id"; 2173 bmc->device_id_attr.attr.name = "device_id";
2174 bmc->device_id_attr.attr.owner = THIS_MODULE;
2175 bmc->device_id_attr.attr.mode = S_IRUGO; 2174 bmc->device_id_attr.attr.mode = S_IRUGO;
2176 bmc->device_id_attr.show = device_id_show; 2175 bmc->device_id_attr.show = device_id_show;
2177 2176
2178 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; 2177 bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs";
2179 bmc->provides_dev_sdrs_attr.attr.owner = THIS_MODULE;
2180 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; 2178 bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO;
2181 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; 2179 bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show;
2182 2180
2183 bmc->revision_attr.attr.name = "revision"; 2181 bmc->revision_attr.attr.name = "revision";
2184 bmc->revision_attr.attr.owner = THIS_MODULE;
2185 bmc->revision_attr.attr.mode = S_IRUGO; 2182 bmc->revision_attr.attr.mode = S_IRUGO;
2186 bmc->revision_attr.show = revision_show; 2183 bmc->revision_attr.show = revision_show;
2187 2184
2188 bmc->firmware_rev_attr.attr.name = "firmware_revision"; 2185 bmc->firmware_rev_attr.attr.name = "firmware_revision";
2189 bmc->firmware_rev_attr.attr.owner = THIS_MODULE;
2190 bmc->firmware_rev_attr.attr.mode = S_IRUGO; 2186 bmc->firmware_rev_attr.attr.mode = S_IRUGO;
2191 bmc->firmware_rev_attr.show = firmware_rev_show; 2187 bmc->firmware_rev_attr.show = firmware_rev_show;
2192 2188
2193 bmc->version_attr.attr.name = "ipmi_version"; 2189 bmc->version_attr.attr.name = "ipmi_version";
2194 bmc->version_attr.attr.owner = THIS_MODULE;
2195 bmc->version_attr.attr.mode = S_IRUGO; 2190 bmc->version_attr.attr.mode = S_IRUGO;
2196 bmc->version_attr.show = ipmi_version_show; 2191 bmc->version_attr.show = ipmi_version_show;
2197 2192
2198 bmc->add_dev_support_attr.attr.name = "additional_device_support"; 2193 bmc->add_dev_support_attr.attr.name = "additional_device_support";
2199 bmc->add_dev_support_attr.attr.owner = THIS_MODULE;
2200 bmc->add_dev_support_attr.attr.mode = S_IRUGO; 2194 bmc->add_dev_support_attr.attr.mode = S_IRUGO;
2201 bmc->add_dev_support_attr.show = add_dev_support_show; 2195 bmc->add_dev_support_attr.show = add_dev_support_show;
2202 2196
2203 bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; 2197 bmc->manufacturer_id_attr.attr.name = "manufacturer_id";
2204 bmc->manufacturer_id_attr.attr.owner = THIS_MODULE;
2205 bmc->manufacturer_id_attr.attr.mode = S_IRUGO; 2198 bmc->manufacturer_id_attr.attr.mode = S_IRUGO;
2206 bmc->manufacturer_id_attr.show = manufacturer_id_show; 2199 bmc->manufacturer_id_attr.show = manufacturer_id_show;
2207 2200
2208 bmc->product_id_attr.attr.name = "product_id"; 2201 bmc->product_id_attr.attr.name = "product_id";
2209 bmc->product_id_attr.attr.owner = THIS_MODULE;
2210 bmc->product_id_attr.attr.mode = S_IRUGO; 2202 bmc->product_id_attr.attr.mode = S_IRUGO;
2211 bmc->product_id_attr.show = product_id_show; 2203 bmc->product_id_attr.show = product_id_show;
2212 2204
2213 bmc->guid_attr.attr.name = "guid"; 2205 bmc->guid_attr.attr.name = "guid";
2214 bmc->guid_attr.attr.owner = THIS_MODULE;
2215 bmc->guid_attr.attr.mode = S_IRUGO; 2206 bmc->guid_attr.attr.mode = S_IRUGO;
2216 bmc->guid_attr.show = guid_show; 2207 bmc->guid_attr.show = guid_show;
2217 2208
2218 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; 2209 bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision";
2219 bmc->aux_firmware_rev_attr.attr.owner = THIS_MODULE;
2220 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; 2210 bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO;
2221 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; 2211 bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show;
2222 2212
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 0cea8d4907df..e5ed09192be8 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -19,18 +19,17 @@
19 * along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22#include <linux/platform_device.h>
23#include <linux/errno.h> 22#include <linux/errno.h>
24#include <linux/fs.h> 23#include <linux/fs.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/irq.h>
27#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/irq.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/types.h> 31#include <linux/types.h>
32 32
33#include <asm/cpu.h>
34#include <asm/io.h> 33#include <asm/io.h>
35#include <asm/vr41xx/giu.h> 34#include <asm/vr41xx/giu.h>
36#include <asm/vr41xx/irq.h> 35#include <asm/vr41xx/irq.h>
@@ -44,18 +43,6 @@ static int major; /* default is dynamic major device number */
44module_param(major, int, 0); 43module_param(major, int, 0);
45MODULE_PARM_DESC(major, "Major device number"); 44MODULE_PARM_DESC(major, "Major device number");
46 45
47#define GIU_TYPE1_START 0x0b000100UL
48#define GIU_TYPE1_SIZE 0x20UL
49
50#define GIU_TYPE2_START 0x0f000140UL
51#define GIU_TYPE2_SIZE 0x20UL
52
53#define GIU_TYPE3_START 0x0f000140UL
54#define GIU_TYPE3_SIZE 0x28UL
55
56#define GIU_PULLUPDOWN_START 0x0b0002e0UL
57#define GIU_PULLUPDOWN_SIZE 0x04UL
58
59#define GIUIOSELL 0x00 46#define GIUIOSELL 0x00
60#define GIUIOSELH 0x02 47#define GIUIOSELH 0x02
61#define GIUPIODL 0x04 48#define GIUPIODL 0x04
@@ -89,8 +76,6 @@ MODULE_PARM_DESC(major, "Major device number");
89#define GPIO_HAS_INTERRUPT_EDGE_SELECT 0x0100 76#define GPIO_HAS_INTERRUPT_EDGE_SELECT 0x0100
90 77
91static spinlock_t giu_lock; 78static spinlock_t giu_lock;
92static struct resource *giu_resource1;
93static struct resource *giu_resource2;
94static unsigned long giu_flags; 79static unsigned long giu_flags;
95static unsigned int giu_nr_pins; 80static unsigned int giu_nr_pins;
96 81
@@ -234,7 +219,7 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
234 giu_set(GIUINTHTSELL, mask); 219 giu_set(GIUINTHTSELL, mask);
235 else 220 else
236 giu_clear(GIUINTHTSELL, mask); 221 giu_clear(GIUINTHTSELL, mask);
237 if (current_cpu_data.cputype == CPU_VR4133) { 222 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
238 switch (trigger) { 223 switch (trigger) {
239 case IRQ_TRIGGER_EDGE_FALLING: 224 case IRQ_TRIGGER_EDGE_FALLING:
240 giu_set(GIUFEDGEINHL, mask); 225 giu_set(GIUFEDGEINHL, mask);
@@ -269,7 +254,7 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
269 giu_set(GIUINTHTSELH, mask); 254 giu_set(GIUINTHTSELH, mask);
270 else 255 else
271 giu_clear(GIUINTHTSELH, mask); 256 giu_clear(GIUINTHTSELH, mask);
272 if (current_cpu_data.cputype == CPU_VR4133) { 257 if (giu_flags & GPIO_HAS_INTERRUPT_EDGE_SELECT) {
273 switch (trigger) { 258 switch (trigger) {
274 case IRQ_TRIGGER_EDGE_FALLING: 259 case IRQ_TRIGGER_EDGE_FALLING:
275 giu_set(GIUFEDGEINHH, mask); 260 giu_set(GIUFEDGEINHH, mask);
@@ -298,7 +283,6 @@ void vr41xx_set_irq_trigger(unsigned int pin, irq_trigger_t trigger, irq_signal_
298 giu_write(GIUINTSTATH, mask); 283 giu_write(GIUINTSTATH, mask);
299 } 284 }
300} 285}
301
302EXPORT_SYMBOL_GPL(vr41xx_set_irq_trigger); 286EXPORT_SYMBOL_GPL(vr41xx_set_irq_trigger);
303 287
304void vr41xx_set_irq_level(unsigned int pin, irq_level_t level) 288void vr41xx_set_irq_level(unsigned int pin, irq_level_t level)
@@ -321,7 +305,6 @@ void vr41xx_set_irq_level(unsigned int pin, irq_level_t level)
321 giu_write(GIUINTSTATH, mask); 305 giu_write(GIUINTSTATH, mask);
322 } 306 }
323} 307}
324
325EXPORT_SYMBOL_GPL(vr41xx_set_irq_level); 308EXPORT_SYMBOL_GPL(vr41xx_set_irq_level);
326 309
327gpio_data_t vr41xx_gpio_get_pin(unsigned int pin) 310gpio_data_t vr41xx_gpio_get_pin(unsigned int pin)
@@ -350,7 +333,6 @@ gpio_data_t vr41xx_gpio_get_pin(unsigned int pin)
350 333
351 return GPIO_DATA_LOW; 334 return GPIO_DATA_LOW;
352} 335}
353
354EXPORT_SYMBOL_GPL(vr41xx_gpio_get_pin); 336EXPORT_SYMBOL_GPL(vr41xx_gpio_get_pin);
355 337
356int vr41xx_gpio_set_pin(unsigned int pin, gpio_data_t data) 338int vr41xx_gpio_set_pin(unsigned int pin, gpio_data_t data)
@@ -388,7 +370,6 @@ int vr41xx_gpio_set_pin(unsigned int pin, gpio_data_t data)
388 370
389 return 0; 371 return 0;
390} 372}
391
392EXPORT_SYMBOL_GPL(vr41xx_gpio_set_pin); 373EXPORT_SYMBOL_GPL(vr41xx_gpio_set_pin);
393 374
394int vr41xx_gpio_set_direction(unsigned int pin, gpio_direction_t dir) 375int vr41xx_gpio_set_direction(unsigned int pin, gpio_direction_t dir)
@@ -438,7 +419,6 @@ int vr41xx_gpio_set_direction(unsigned int pin, gpio_direction_t dir)
438 419
439 return 0; 420 return 0;
440} 421}
441
442EXPORT_SYMBOL_GPL(vr41xx_gpio_set_direction); 422EXPORT_SYMBOL_GPL(vr41xx_gpio_set_direction);
443 423
444int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull) 424int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull)
@@ -477,7 +457,6 @@ int vr41xx_gpio_pullupdown(unsigned int pin, gpio_pull_t pull)
477 457
478 return 0; 458 return 0;
479} 459}
480
481EXPORT_SYMBOL_GPL(vr41xx_gpio_pullupdown); 460EXPORT_SYMBOL_GPL(vr41xx_gpio_pullupdown);
482 461
483static ssize_t gpio_read(struct file *file, char __user *buf, size_t len, 462static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
@@ -596,61 +575,40 @@ static const struct file_operations gpio_fops = {
596 575
597static int __devinit giu_probe(struct platform_device *dev) 576static int __devinit giu_probe(struct platform_device *dev)
598{ 577{
599 unsigned long start, size, flags = 0; 578 struct resource *res;
600 unsigned int nr_pins = 0, trigger, i, pin; 579 unsigned int trigger, i, pin;
601 struct resource *res1, *res2 = NULL;
602 void *base;
603 struct irq_chip *chip; 580 struct irq_chip *chip;
604 int retval; 581 int irq, retval;
605 582
606 switch (current_cpu_data.cputype) { 583 switch (dev->id) {
607 case CPU_VR4111: 584 case GPIO_50PINS_PULLUPDOWN:
608 case CPU_VR4121: 585 giu_flags = GPIO_HAS_PULLUPDOWN_IO;
609 start = GIU_TYPE1_START; 586 giu_nr_pins = 50;
610 size = GIU_TYPE1_SIZE;
611 flags = GPIO_HAS_PULLUPDOWN_IO;
612 nr_pins = 50;
613 break; 587 break;
614 case CPU_VR4122: 588 case GPIO_36PINS:
615 case CPU_VR4131: 589 giu_nr_pins = 36;
616 start = GIU_TYPE2_START;
617 size = GIU_TYPE2_SIZE;
618 nr_pins = 36;
619 break; 590 break;
620 case CPU_VR4133: 591 case GPIO_48PINS_EDGE_SELECT:
621 start = GIU_TYPE3_START; 592 giu_flags = GPIO_HAS_INTERRUPT_EDGE_SELECT;
622 size = GIU_TYPE3_SIZE; 593 giu_nr_pins = 48;
623 flags = GPIO_HAS_INTERRUPT_EDGE_SELECT;
624 nr_pins = 48;
625 break; 594 break;
626 default: 595 default:
596 printk(KERN_ERR "GIU: unknown ID %d\n", dev->id);
627 return -ENODEV; 597 return -ENODEV;
628 } 598 }
629 599
630 res1 = request_mem_region(start, size, "GIU"); 600 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
631 if (res1 == NULL) 601 if (!res)
632 return -EBUSY; 602 return -EBUSY;
633 603
634 base = ioremap(start, size); 604 giu_base = ioremap(res->start, res->end - res->start + 1);
635 if (base == NULL) { 605 if (!giu_base)
636 release_resource(res1);
637 return -ENOMEM; 606 return -ENOMEM;
638 }
639
640 if (flags & GPIO_HAS_PULLUPDOWN_IO) {
641 res2 = request_mem_region(GIU_PULLUPDOWN_START, GIU_PULLUPDOWN_SIZE, "GIU");
642 if (res2 == NULL) {
643 iounmap(base);
644 release_resource(res1);
645 return -EBUSY;
646 }
647 }
648 607
649 retval = register_chrdev(major, "GIU", &gpio_fops); 608 retval = register_chrdev(major, "GIU", &gpio_fops);
650 if (retval < 0) { 609 if (retval < 0) {
651 iounmap(base); 610 iounmap(giu_base);
652 release_resource(res1); 611 giu_base = NULL;
653 release_resource(res2);
654 return retval; 612 return retval;
655 } 613 }
656 614
@@ -660,11 +618,6 @@ static int __devinit giu_probe(struct platform_device *dev)
660 } 618 }
661 619
662 spin_lock_init(&giu_lock); 620 spin_lock_init(&giu_lock);
663 giu_base = base;
664 giu_resource1 = res1;
665 giu_resource2 = res2;
666 giu_flags = flags;
667 giu_nr_pins = nr_pins;
668 621
669 giu_write(GIUINTENL, 0); 622 giu_write(GIUINTENL, 0);
670 giu_write(GIUINTENH, 0); 623 giu_write(GIUINTENH, 0);
@@ -685,22 +638,23 @@ static int __devinit giu_probe(struct platform_device *dev)
685 638
686 } 639 }
687 640
688 return cascade_irq(GIUINT_IRQ, giu_get_irq); 641 irq = platform_get_irq(dev, 0);
642 if (irq < 0 || irq >= NR_IRQS)
643 return -EBUSY;
644
645 return cascade_irq(irq, giu_get_irq);
689} 646}
690 647
691static int __devexit giu_remove(struct platform_device *dev) 648static int __devexit giu_remove(struct platform_device *dev)
692{ 649{
693 iounmap(giu_base); 650 if (giu_base) {
694 651 iounmap(giu_base);
695 release_resource(giu_resource1); 652 giu_base = NULL;
696 if (giu_flags & GPIO_HAS_PULLUPDOWN_IO) 653 }
697 release_resource(giu_resource2);
698 654
699 return 0; 655 return 0;
700} 656}
701 657
702static struct platform_device *giu_platform_device;
703
704static struct platform_driver giu_device_driver = { 658static struct platform_driver giu_device_driver = {
705 .probe = giu_probe, 659 .probe = giu_probe,
706 .remove = __devexit_p(giu_remove), 660 .remove = __devexit_p(giu_remove),
@@ -712,30 +666,12 @@ static struct platform_driver giu_device_driver = {
712 666
713static int __init vr41xx_giu_init(void) 667static int __init vr41xx_giu_init(void)
714{ 668{
715 int retval; 669 return platform_driver_register(&giu_device_driver);
716
717 giu_platform_device = platform_device_alloc("GIU", -1);
718 if (!giu_platform_device)
719 return -ENOMEM;
720
721 retval = platform_device_add(giu_platform_device);
722 if (retval < 0) {
723 platform_device_put(giu_platform_device);
724 return retval;
725 }
726
727 retval = platform_driver_register(&giu_device_driver);
728 if (retval < 0)
729 platform_device_unregister(giu_platform_device);
730
731 return retval;
732} 670}
733 671
734static void __exit vr41xx_giu_exit(void) 672static void __exit vr41xx_giu_exit(void)
735{ 673{
736 platform_driver_unregister(&giu_device_driver); 674 platform_driver_unregister(&giu_device_driver);
737
738 platform_device_unregister(giu_platform_device);
739} 675}
740 676
741module_init(vr41xx_giu_init); 677module_init(vr41xx_giu_init);
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index d2f0cbd8b8f3..917b9bab9ccb 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -25,8 +25,7 @@ static spinlock_t cpufreq_stats_lock;
25 25
26#define CPUFREQ_STATDEVICE_ATTR(_name,_mode,_show) \ 26#define CPUFREQ_STATDEVICE_ATTR(_name,_mode,_show) \
27static struct freq_attr _attr_##_name = {\ 27static struct freq_attr _attr_##_name = {\
28 .attr = {.name = __stringify(_name), .owner = THIS_MODULE, \ 28 .attr = {.name = __stringify(_name), .mode = _mode, }, \
29 .mode = _mode, }, \
30 .show = _show,\ 29 .show = _show,\
31}; 30};
32 31
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 860345c7799a..a648970338b0 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -120,7 +120,7 @@ store_speed (struct cpufreq_policy *policy, const char *buf, size_t count)
120 120
121static struct freq_attr freq_attr_scaling_setspeed = 121static struct freq_attr freq_attr_scaling_setspeed =
122{ 122{
123 .attr = { .name = "scaling_setspeed", .mode = 0644, .owner = THIS_MODULE }, 123 .attr = { .name = "scaling_setspeed", .mode = 0644 },
124 .show = show_speed, 124 .show = show_speed,
125 .store = store_speed, 125 .store = store_speed,
126}; 126};
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index e7490925fdcf..5409f3afb3f8 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -199,7 +199,6 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
199struct freq_attr cpufreq_freq_attr_scaling_available_freqs = { 199struct freq_attr cpufreq_freq_attr_scaling_available_freqs = {
200 .attr = { .name = "scaling_available_frequencies", 200 .attr = { .name = "scaling_available_frequencies",
201 .mode = 0444, 201 .mode = 0444,
202 .owner=THIS_MODULE
203 }, 202 },
204 .show = show_available_freqs, 203 .show = show_available_freqs,
205}; 204};
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 88f462122a30..05f02a326f1c 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -84,4 +84,13 @@ config DCDBAS
84 Say Y or M here to enable the driver for use by Dell systems 84 Say Y or M here to enable the driver for use by Dell systems
85 management software such as Dell OpenManage. 85 management software such as Dell OpenManage.
86 86
87config DMIID
88 bool "Export DMI identification via sysfs to userspace"
89 depends on DMI
90 default y
91 help
92 Say Y here if you want to query SMBIOS/DMI system identification
93 information from userspace through /sys/class/dmi/id/ or if you want
94 DMI-based module auto-loading.
95
87endmenu 96endmenu
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 98e395f4bb29..8d4ebc805a50 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_EFI_VARS) += efivars.o
7obj-$(CONFIG_EFI_PCDP) += pcdp.o 7obj-$(CONFIG_EFI_PCDP) += pcdp.o
8obj-$(CONFIG_DELL_RBU) += dell_rbu.o 8obj-$(CONFIG_DELL_RBU) += dell_rbu.o
9obj-$(CONFIG_DCDBAS) += dcdbas.o 9obj-$(CONFIG_DCDBAS) += dcdbas.o
10obj-$(CONFIG_DMIID) += dmi-id.o
diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c
index 1865b56fb141..18cdcb3ae1ca 100644
--- a/drivers/firmware/dcdbas.c
+++ b/drivers/firmware/dcdbas.c
@@ -149,8 +149,9 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
149 return count; 149 return count;
150} 150}
151 151
152static ssize_t smi_data_read(struct kobject *kobj, char *buf, loff_t pos, 152static ssize_t smi_data_read(struct kobject *kobj,
153 size_t count) 153 struct bin_attribute *bin_attr,
154 char *buf, loff_t pos, size_t count)
154{ 155{
155 size_t max_read; 156 size_t max_read;
156 ssize_t ret; 157 ssize_t ret;
@@ -170,8 +171,9 @@ out:
170 return ret; 171 return ret;
171} 172}
172 173
173static ssize_t smi_data_write(struct kobject *kobj, char *buf, loff_t pos, 174static ssize_t smi_data_write(struct kobject *kobj,
174 size_t count) 175 struct bin_attribute *bin_attr,
176 char *buf, loff_t pos, size_t count)
175{ 177{
176 ssize_t ret; 178 ssize_t ret;
177 179
diff --git a/drivers/firmware/dcdbas.h b/drivers/firmware/dcdbas.h
index 58a85182b3e8..dcdba0f1b32c 100644
--- a/drivers/firmware/dcdbas.h
+++ b/drivers/firmware/dcdbas.h
@@ -67,8 +67,7 @@
67#define DCDBAS_BIN_ATTR_RW(_name) \ 67#define DCDBAS_BIN_ATTR_RW(_name) \
68struct bin_attribute bin_attr_##_name = { \ 68struct bin_attribute bin_attr_##_name = { \
69 .attr = { .name = __stringify(_name), \ 69 .attr = { .name = __stringify(_name), \
70 .mode = 0600, \ 70 .mode = 0600 }, \
71 .owner = THIS_MODULE }, \
72 .read = _name##_read, \ 71 .read = _name##_read, \
73 .write = _name##_write, \ 72 .write = _name##_write, \
74} 73}
diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
index fc702e40bd43..477a3d0e3caf 100644
--- a/drivers/firmware/dell_rbu.c
+++ b/drivers/firmware/dell_rbu.c
@@ -543,8 +543,9 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
543 return ret_count; 543 return ret_count;
544} 544}
545 545
546static ssize_t read_rbu_data(struct kobject *kobj, char *buffer, 546static ssize_t read_rbu_data(struct kobject *kobj,
547 loff_t pos, size_t count) 547 struct bin_attribute *bin_attr,
548 char *buffer, loff_t pos, size_t count)
548{ 549{
549 ssize_t ret_count = 0; 550 ssize_t ret_count = 0;
550 551
@@ -591,8 +592,9 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
591 spin_unlock(&rbu_data.lock); 592 spin_unlock(&rbu_data.lock);
592} 593}
593 594
594static ssize_t read_rbu_image_type(struct kobject *kobj, char *buffer, 595static ssize_t read_rbu_image_type(struct kobject *kobj,
595 loff_t pos, size_t count) 596 struct bin_attribute *bin_attr,
597 char *buffer, loff_t pos, size_t count)
596{ 598{
597 int size = 0; 599 int size = 0;
598 if (!pos) 600 if (!pos)
@@ -600,8 +602,9 @@ static ssize_t read_rbu_image_type(struct kobject *kobj, char *buffer,
600 return size; 602 return size;
601} 603}
602 604
603static ssize_t write_rbu_image_type(struct kobject *kobj, char *buffer, 605static ssize_t write_rbu_image_type(struct kobject *kobj,
604 loff_t pos, size_t count) 606 struct bin_attribute *bin_attr,
607 char *buffer, loff_t pos, size_t count)
605{ 608{
606 int rc = count; 609 int rc = count;
607 int req_firm_rc = 0; 610 int req_firm_rc = 0;
@@ -660,8 +663,9 @@ static ssize_t write_rbu_image_type(struct kobject *kobj, char *buffer,
660 return rc; 663 return rc;
661} 664}
662 665
663static ssize_t read_rbu_packet_size(struct kobject *kobj, char *buffer, 666static ssize_t read_rbu_packet_size(struct kobject *kobj,
664 loff_t pos, size_t count) 667 struct bin_attribute *bin_attr,
668 char *buffer, loff_t pos, size_t count)
665{ 669{
666 int size = 0; 670 int size = 0;
667 if (!pos) { 671 if (!pos) {
@@ -672,8 +676,9 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj, char *buffer,
672 return size; 676 return size;
673} 677}
674 678
675static ssize_t write_rbu_packet_size(struct kobject *kobj, char *buffer, 679static ssize_t write_rbu_packet_size(struct kobject *kobj,
676 loff_t pos, size_t count) 680 struct bin_attribute *bin_attr,
681 char *buffer, loff_t pos, size_t count)
677{ 682{
678 unsigned long temp; 683 unsigned long temp;
679 spin_lock(&rbu_data.lock); 684 spin_lock(&rbu_data.lock);
@@ -687,18 +692,18 @@ static ssize_t write_rbu_packet_size(struct kobject *kobj, char *buffer,
687} 692}
688 693
689static struct bin_attribute rbu_data_attr = { 694static struct bin_attribute rbu_data_attr = {
690 .attr = {.name = "data",.owner = THIS_MODULE,.mode = 0444}, 695 .attr = {.name = "data", .mode = 0444},
691 .read = read_rbu_data, 696 .read = read_rbu_data,
692}; 697};
693 698
694static struct bin_attribute rbu_image_type_attr = { 699static struct bin_attribute rbu_image_type_attr = {
695 .attr = {.name = "image_type",.owner = THIS_MODULE,.mode = 0644}, 700 .attr = {.name = "image_type", .mode = 0644},
696 .read = read_rbu_image_type, 701 .read = read_rbu_image_type,
697 .write = write_rbu_image_type, 702 .write = write_rbu_image_type,
698}; 703};
699 704
700static struct bin_attribute rbu_packet_size_attr = { 705static struct bin_attribute rbu_packet_size_attr = {
701 .attr = {.name = "packet_size",.owner = THIS_MODULE,.mode = 0644}, 706 .attr = {.name = "packet_size", .mode = 0644},
702 .read = read_rbu_packet_size, 707 .read = read_rbu_packet_size,
703 .write = write_rbu_packet_size, 708 .write = write_rbu_packet_size,
704}; 709};
diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
new file mode 100644
index 000000000000..59c3b5aa89f4
--- /dev/null
+++ b/drivers/firmware/dmi-id.c
@@ -0,0 +1,222 @@
1/*
2 * Export SMBIOS/DMI info via sysfs to userspace
3 *
4 * Copyright 2007, Lennart Poettering
5 *
6 * Licensed under GPLv2
7 */
8
9#include <linux/module.h>
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/dmi.h>
13#include <linux/device.h>
14#include <linux/autoconf.h>
15
16#define DEFINE_DMI_ATTR(_name, _mode, _show) \
17static struct device_attribute sys_dmi_##_name##_attr = \
18 __ATTR(_name, _mode, _show, NULL);
19
20#define DEFINE_DMI_ATTR_WITH_SHOW(_name, _mode, _field) \
21static ssize_t sys_dmi_##_name##_show(struct device *dev, \
22 struct device_attribute *attr, \
23 char *page) \
24{ \
25 ssize_t len; \
26 len = scnprintf(page, PAGE_SIZE, "%s\n", dmi_get_system_info(_field)); \
27 page[len-1] = '\n'; \
28 return len; \
29} \
30DEFINE_DMI_ATTR(_name, _mode, sys_dmi_##_name##_show);
31
32DEFINE_DMI_ATTR_WITH_SHOW(bios_vendor, 0444, DMI_BIOS_VENDOR);
33DEFINE_DMI_ATTR_WITH_SHOW(bios_version, 0444, DMI_BIOS_VERSION);
34DEFINE_DMI_ATTR_WITH_SHOW(bios_date, 0444, DMI_BIOS_DATE);
35DEFINE_DMI_ATTR_WITH_SHOW(sys_vendor, 0444, DMI_SYS_VENDOR);
36DEFINE_DMI_ATTR_WITH_SHOW(product_name, 0444, DMI_PRODUCT_NAME);
37DEFINE_DMI_ATTR_WITH_SHOW(product_version, 0444, DMI_PRODUCT_VERSION);
38DEFINE_DMI_ATTR_WITH_SHOW(product_serial, 0400, DMI_PRODUCT_SERIAL);
39DEFINE_DMI_ATTR_WITH_SHOW(product_uuid, 0400, DMI_PRODUCT_UUID);
40DEFINE_DMI_ATTR_WITH_SHOW(board_vendor, 0444, DMI_BOARD_VENDOR);
41DEFINE_DMI_ATTR_WITH_SHOW(board_name, 0444, DMI_BOARD_NAME);
42DEFINE_DMI_ATTR_WITH_SHOW(board_version, 0444, DMI_BOARD_VERSION);
43DEFINE_DMI_ATTR_WITH_SHOW(board_serial, 0400, DMI_BOARD_SERIAL);
44DEFINE_DMI_ATTR_WITH_SHOW(board_asset_tag, 0444, DMI_BOARD_ASSET_TAG);
45DEFINE_DMI_ATTR_WITH_SHOW(chassis_vendor, 0444, DMI_CHASSIS_VENDOR);
46DEFINE_DMI_ATTR_WITH_SHOW(chassis_type, 0444, DMI_CHASSIS_TYPE);
47DEFINE_DMI_ATTR_WITH_SHOW(chassis_version, 0444, DMI_CHASSIS_VERSION);
48DEFINE_DMI_ATTR_WITH_SHOW(chassis_serial, 0400, DMI_CHASSIS_SERIAL);
49DEFINE_DMI_ATTR_WITH_SHOW(chassis_asset_tag, 0444, DMI_CHASSIS_ASSET_TAG);
50
51static void ascii_filter(char *d, const char *s)
52{
53 /* Filter out characters we don't want to see in the modalias string */
54 for (; *s; s++)
55 if (*s > ' ' && *s < 127 && *s != ':')
56 *(d++) = *s;
57
58 *d = 0;
59}
60
61static ssize_t get_modalias(char *buffer, size_t buffer_size)
62{
63 static const struct mafield {
64 const char *prefix;
65 int field;
66 } fields[] = {
67 { "bvn", DMI_BIOS_VENDOR },
68 { "bvr", DMI_BIOS_VERSION },
69 { "bd", DMI_BIOS_DATE },
70 { "svn", DMI_SYS_VENDOR },
71 { "pn", DMI_PRODUCT_NAME },
72 { "pvr", DMI_PRODUCT_VERSION },
73 { "rvn", DMI_BOARD_VENDOR },
74 { "rn", DMI_BOARD_NAME },
75 { "rvr", DMI_BOARD_VERSION },
76 { "cvn", DMI_CHASSIS_VENDOR },
77 { "ct", DMI_CHASSIS_TYPE },
78 { "cvr", DMI_CHASSIS_VERSION },
79 { NULL, DMI_NONE }
80 };
81
82 ssize_t l, left;
83 char *p;
84 const struct mafield *f;
85
86 strcpy(buffer, "dmi");
87 p = buffer + 3; left = buffer_size - 4;
88
89 for (f = fields; f->prefix && left > 0; f++) {
90 const char *c;
91 char *t;
92
93 c = dmi_get_system_info(f->field);
94 if (!c)
95 continue;
96
97 t = kmalloc(strlen(c) + 1, GFP_KERNEL);
98 if (!t)
99 break;
100 ascii_filter(t, c);
101 l = scnprintf(p, left, ":%s%s", f->prefix, t);
102 kfree(t);
103
104 p += l;
105 left -= l;
106 }
107
108 p[0] = ':';
109 p[1] = 0;
110
111 return p - buffer + 1;
112}
113
114static ssize_t sys_dmi_modalias_show(struct device *dev,
115 struct device_attribute *attr, char *page)
116{
117 ssize_t r;
118 r = get_modalias(page, PAGE_SIZE-1);
119 page[r] = '\n';
120 page[r+1] = 0;
121 return r+1;
122}
123
124DEFINE_DMI_ATTR(modalias, 0444, sys_dmi_modalias_show);
125
126static struct attribute *sys_dmi_attributes[DMI_STRING_MAX+2];
127
128static struct attribute_group sys_dmi_attribute_group = {
129 .attrs = sys_dmi_attributes,
130};
131
132static struct attribute_group* sys_dmi_attribute_groups[] = {
133 &sys_dmi_attribute_group,
134 NULL
135};
136
137static int dmi_dev_uevent(struct device *dev, char **envp,
138 int num_envp, char *buffer, int buffer_size)
139{
140 strcpy(buffer, "MODALIAS=");
141 get_modalias(buffer+9, buffer_size-9);
142 envp[0] = buffer;
143 envp[1] = NULL;
144
145 return 0;
146}
147
148static struct class dmi_class = {
149 .name = "dmi",
150 .dev_release = (void(*)(struct device *)) kfree,
151 .dev_uevent = dmi_dev_uevent,
152};
153
154static struct device *dmi_dev;
155
156/* Initialization */
157
158#define ADD_DMI_ATTR(_name, _field) \
159 if (dmi_get_system_info(_field)) \
160 sys_dmi_attributes[i++] = & sys_dmi_##_name##_attr.attr;
161
162extern int dmi_available;
163
164static int __init dmi_id_init(void)
165{
166 int ret, i;
167
168 if (!dmi_available)
169 return -ENODEV;
170
171 /* Not necessarily all DMI fields are available on all
172 * systems, hence let's built an attribute table of just
173 * what's available */
174 i = 0;
175 ADD_DMI_ATTR(bios_vendor, DMI_BIOS_VENDOR);
176 ADD_DMI_ATTR(bios_version, DMI_BIOS_VERSION);
177 ADD_DMI_ATTR(bios_date, DMI_BIOS_DATE);
178 ADD_DMI_ATTR(sys_vendor, DMI_SYS_VENDOR);
179 ADD_DMI_ATTR(product_name, DMI_PRODUCT_NAME);
180 ADD_DMI_ATTR(product_version, DMI_PRODUCT_VERSION);
181 ADD_DMI_ATTR(product_serial, DMI_PRODUCT_SERIAL);
182 ADD_DMI_ATTR(product_uuid, DMI_PRODUCT_UUID);
183 ADD_DMI_ATTR(board_vendor, DMI_BOARD_VENDOR);
184 ADD_DMI_ATTR(board_name, DMI_BOARD_NAME);
185 ADD_DMI_ATTR(board_version, DMI_BOARD_VERSION);
186 ADD_DMI_ATTR(board_serial, DMI_BOARD_SERIAL);
187 ADD_DMI_ATTR(board_asset_tag, DMI_BOARD_ASSET_TAG);
188 ADD_DMI_ATTR(chassis_vendor, DMI_CHASSIS_VENDOR);
189 ADD_DMI_ATTR(chassis_type, DMI_CHASSIS_TYPE);
190 ADD_DMI_ATTR(chassis_version, DMI_CHASSIS_VERSION);
191 ADD_DMI_ATTR(chassis_serial, DMI_CHASSIS_SERIAL);
192 ADD_DMI_ATTR(chassis_asset_tag, DMI_CHASSIS_ASSET_TAG);
193 sys_dmi_attributes[i++] = &sys_dmi_modalias_attr.attr;
194
195 ret = class_register(&dmi_class);
196 if (ret)
197 return ret;
198
199 dmi_dev = kzalloc(sizeof(*dmi_dev), GFP_KERNEL);
200 if (!dmi_dev) {
201 ret = -ENOMEM;
202 goto fail_class_unregister;
203 }
204
205 dmi_dev->class = &dmi_class;
206 strcpy(dmi_dev->bus_id, "id");
207 dmi_dev->groups = sys_dmi_attribute_groups;
208
209 ret = device_register(dmi_dev);
210 if (ret)
211 goto fail_class_unregister;
212
213 return 0;
214
215fail_class_unregister:
216
217 class_unregister(&dmi_class);
218
219 return ret;
220}
221
222arch_initcall(dmi_id_init);
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 37deee6c0c1c..f7318b3b51f2 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -84,6 +84,7 @@ static int __init dmi_checksum(u8 *buf)
84 84
85static char *dmi_ident[DMI_STRING_MAX]; 85static char *dmi_ident[DMI_STRING_MAX];
86static LIST_HEAD(dmi_devices); 86static LIST_HEAD(dmi_devices);
87int dmi_available;
87 88
88/* 89/*
89 * Save a DMI string 90 * Save a DMI string
@@ -102,6 +103,51 @@ static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
102 dmi_ident[slot] = p; 103 dmi_ident[slot] = p;
103} 104}
104 105
106static void __init dmi_save_uuid(struct dmi_header *dm, int slot, int index)
107{
108 u8 *d = (u8*) dm + index;
109 char *s;
110 int is_ff = 1, is_00 = 1, i;
111
112 if (dmi_ident[slot])
113 return;
114
115 for (i = 0; i < 16 && (is_ff || is_00); i++) {
116 if(d[i] != 0x00) is_ff = 0;
117 if(d[i] != 0xFF) is_00 = 0;
118 }
119
120 if (is_ff || is_00)
121 return;
122
123 s = dmi_alloc(16*2+4+1);
124 if (!s)
125 return;
126
127 sprintf(s,
128 "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
129 d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
130 d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
131
132 dmi_ident[slot] = s;
133}
134
135static void __init dmi_save_type(struct dmi_header *dm, int slot, int index)
136{
137 u8 *d = (u8*) dm + index;
138 char *s;
139
140 if (dmi_ident[slot])
141 return;
142
143 s = dmi_alloc(4);
144 if (!s)
145 return;
146
147 sprintf(s, "%u", *d & 0x7F);
148 dmi_ident[slot] = s;
149}
150
105static void __init dmi_save_devices(struct dmi_header *dm) 151static void __init dmi_save_devices(struct dmi_header *dm)
106{ 152{
107 int i, count = (dm->length - sizeof(struct dmi_header)) / 2; 153 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
@@ -192,11 +238,21 @@ static void __init dmi_decode(struct dmi_header *dm)
192 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); 238 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
193 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); 239 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
194 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); 240 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
241 dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
195 break; 242 break;
196 case 2: /* Base Board Information */ 243 case 2: /* Base Board Information */
197 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); 244 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
198 dmi_save_ident(dm, DMI_BOARD_NAME, 5); 245 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
199 dmi_save_ident(dm, DMI_BOARD_VERSION, 6); 246 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
247 dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
248 dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
249 break;
250 case 3: /* Chassis Information */
251 dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
252 dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
253 dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
254 dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
255 dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
200 break; 256 break;
201 case 10: /* Onboard Devices Information */ 257 case 10: /* Onboard Devices Information */
202 dmi_save_devices(dm); 258 dmi_save_devices(dm);
@@ -243,18 +299,20 @@ void __init dmi_scan_machine(void)
243 if (efi.smbios == EFI_INVALID_TABLE_ADDR) 299 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
244 goto out; 300 goto out;
245 301
246 /* This is called as a core_initcall() because it isn't 302 /* This is called as a core_initcall() because it isn't
247 * needed during early boot. This also means we can 303 * needed during early boot. This also means we can
248 * iounmap the space when we're done with it. 304 * iounmap the space when we're done with it.
249 */ 305 */
250 p = dmi_ioremap(efi.smbios, 32); 306 p = dmi_ioremap(efi.smbios, 32);
251 if (p == NULL) 307 if (p == NULL)
252 goto out; 308 goto out;
253 309
254 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */ 310 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
255 dmi_iounmap(p, 32); 311 dmi_iounmap(p, 32);
256 if (!rc) 312 if (!rc) {
313 dmi_available = 1;
257 return; 314 return;
315 }
258 } 316 }
259 else { 317 else {
260 /* 318 /*
@@ -268,8 +326,10 @@ void __init dmi_scan_machine(void)
268 326
269 for (q = p; q < p + 0x10000; q += 16) { 327 for (q = p; q < p + 0x10000; q += 16) {
270 rc = dmi_present(q); 328 rc = dmi_present(q);
271 if (!rc) 329 if (!rc) {
330 dmi_available = 1;
272 return; 331 return;
332 }
273 } 333 }
274 } 334 }
275 out: printk(KERN_INFO "DMI not present or invalid.\n"); 335 out: printk(KERN_INFO "DMI not present or invalid.\n");
@@ -404,3 +464,4 @@ int dmi_get_year(int field)
404 464
405 return year; 465 return year;
406} 466}
467
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index d8806e4f1829..15232271d848 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -74,7 +74,7 @@ static struct edd_device *edd_devices[EDD_MBR_SIG_MAX];
74 74
75#define EDD_DEVICE_ATTR(_name,_mode,_show,_test) \ 75#define EDD_DEVICE_ATTR(_name,_mode,_show,_test) \
76struct edd_attribute edd_attr_##_name = { \ 76struct edd_attribute edd_attr_##_name = { \
77 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \ 77 .attr = {.name = __stringify(_name), .mode = _mode }, \
78 .show = _show, \ 78 .show = _show, \
79 .test = _test, \ 79 .test = _test, \
80}; 80};
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 1324984a4c35..bfd2d67df689 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -131,21 +131,21 @@ struct efivar_attribute {
131 131
132#define EFI_ATTR(_name, _mode, _show, _store) \ 132#define EFI_ATTR(_name, _mode, _show, _store) \
133struct subsys_attribute efi_attr_##_name = { \ 133struct subsys_attribute efi_attr_##_name = { \
134 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 134 .attr = {.name = __stringify(_name), .mode = _mode}, \
135 .show = _show, \ 135 .show = _show, \
136 .store = _store, \ 136 .store = _store, \
137}; 137};
138 138
139#define EFIVAR_ATTR(_name, _mode, _show, _store) \ 139#define EFIVAR_ATTR(_name, _mode, _show, _store) \
140struct efivar_attribute efivar_attr_##_name = { \ 140struct efivar_attribute efivar_attr_##_name = { \
141 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 141 .attr = {.name = __stringify(_name), .mode = _mode}, \
142 .show = _show, \ 142 .show = _show, \
143 .store = _store, \ 143 .store = _store, \
144}; 144};
145 145
146#define VAR_SUBSYS_ATTR(_name, _mode, _show, _store) \ 146#define VAR_SUBSYS_ATTR(_name, _mode, _show, _store) \
147struct subsys_attribute var_subsys_attr_##_name = { \ 147struct subsys_attribute var_subsys_attr_##_name = { \
148 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 148 .attr = {.name = __stringify(_name), .mode = _mode}, \
149 .show = _show, \ 149 .show = _show, \
150 .store = _store, \ 150 .store = _store, \
151}; 151};
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index 58899078810b..014dfa575be7 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -34,10 +34,6 @@ config I2C_ALGOPCA
34 This support is also available as a module. If so, the module 34 This support is also available as a module. If so, the module
35 will be called i2c-algo-pca. 35 will be called i2c-algo-pca.
36 36
37config I2C_ALGO8XX
38 tristate "MPC8xx CPM I2C interface"
39 depends on 8xx
40
41config I2C_ALGO_SGI 37config I2C_ALGO_SGI
42 tristate "I2C SGI interfaces" 38 tristate "I2C SGI interfaces"
43 depends on SGI_IP22 || SGI_IP32 || X86_VISWS 39 depends on SGI_IP22 || SGI_IP32 || X86_VISWS
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 838dc1c19d61..fcde9bab5b96 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -207,6 +207,7 @@ config I2C_PIIX4
207 ATI IXP300 207 ATI IXP300
208 ATI IXP400 208 ATI IXP400
209 ATI SB600 209 ATI SB600
210 ATI SB700
210 Serverworks OSB4 211 Serverworks OSB4
211 Serverworks CSB5 212 Serverworks CSB5
212 Serverworks CSB6 213 Serverworks CSB6
@@ -390,11 +391,6 @@ config I2C_PROSAVAGE
390 This support is also available as a module. If so, the module 391 This support is also available as a module. If so, the module
391 will be called i2c-prosavage. 392 will be called i2c-prosavage.
392 393
393config I2C_RPXLITE
394 tristate "Embedded Planet RPX Lite/Classic support"
395 depends on RPXLITE || RPXCLASSIC
396 select I2C_ALGO8XX
397
398config I2C_S3C2410 394config I2C_S3C2410
399 tristate "S3C2410 I2C Driver" 395 tristate "S3C2410 I2C Driver"
400 depends on ARCH_S3C2410 396 depends on ARCH_S3C2410
@@ -512,6 +508,22 @@ config I2C_SIS96X
512 This driver can also be built as a module. If so, the module 508 This driver can also be built as a module. If so, the module
513 will be called i2c-sis96x. 509 will be called i2c-sis96x.
514 510
511config I2C_TAOS_EVM
512 tristate "TAOS evaluation module"
513 depends on EXPERIMENTAL
514 select SERIO
515 select SERIO_SERPORT
516 default n
517 help
518 This supports TAOS evaluation modules on serial port. In order to
519 use this driver, you will need the inputattach tool, which is part
520 of the input-utils package.
521
522 If unsure, say N.
523
524 This support is also available as a module. If so, the module
525 will be called i2c-taos-evm.
526
515config I2C_STUB 527config I2C_STUB
516 tristate "I2C/SMBus Test Stub" 528 tristate "I2C/SMBus Test Stub"
517 depends on EXPERIMENTAL && m 529 depends on EXPERIMENTAL && m
@@ -635,4 +647,13 @@ config I2C_PNX
635 This driver can also be built as a module. If so, the module 647 This driver can also be built as a module. If so, the module
636 will be called i2c-pnx. 648 will be called i2c-pnx.
637 649
650config I2C_PMCMSP
651 tristate "PMC MSP I2C TWI Controller"
652 depends on PMC_MSP
653 help
654 This driver supports the PMC TWI controller on MSP devices.
655
656 This driver can also be built as module. If so, the module
657 will be called i2c-pmcmsp.
658
638endmenu 659endmenu
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 14d1432f698b..a6db4e38bda8 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -32,10 +32,10 @@ obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
32obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o 32obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
33obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 33obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
34obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o 34obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
35obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o
35obj-$(CONFIG_I2C_PNX) += i2c-pnx.o 36obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
36obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o 37obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o
37obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 38obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
38obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o 40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
41obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 41obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
@@ -44,6 +44,7 @@ obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
44obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 44obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
45obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 45obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
46obj-$(CONFIG_I2C_STUB) += i2c-stub.o 46obj-$(CONFIG_I2C_STUB) += i2c-stub.o
47obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o
47obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o 48obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
48obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 49obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
49obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 50obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index a7dd54654a9a..025f19423faf 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -63,14 +63,14 @@ static void i2c_gpio_setscl_val(void *data, int state)
63 gpio_set_value(pdata->scl_pin, state); 63 gpio_set_value(pdata->scl_pin, state);
64} 64}
65 65
66int i2c_gpio_getsda(void *data) 66static int i2c_gpio_getsda(void *data)
67{ 67{
68 struct i2c_gpio_platform_data *pdata = data; 68 struct i2c_gpio_platform_data *pdata = data;
69 69
70 return gpio_get_value(pdata->sda_pin); 70 return gpio_get_value(pdata->sda_pin);
71} 71}
72 72
73int i2c_gpio_getscl(void *data) 73static int i2c_gpio_getscl(void *data)
74{ 74{
75 struct i2c_gpio_platform_data *pdata = data; 75 struct i2c_gpio_platform_data *pdata = data;
76 76
@@ -142,7 +142,13 @@ static int __init i2c_gpio_probe(struct platform_device *pdev)
142 adap->algo_data = bit_data; 142 adap->algo_data = bit_data;
143 adap->dev.parent = &pdev->dev; 143 adap->dev.parent = &pdev->dev;
144 144
145 ret = i2c_bit_add_bus(adap); 145 /*
146 * If "dev->id" is negative we consider it as zero.
147 * The reason to do so is to avoid sysfs names that only make
148 * sense when there are multiple adapters.
149 */
150 adap->nr = pdev->id >= 0 ? pdev->id : 0;
151 ret = i2c_bit_add_numbered_bus(adap);
146 if (ret) 152 if (ret)
147 goto err_add_bus; 153 goto err_add_bus;
148 154
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 611b57192c96..8f5c686123b8 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -22,12 +22,12 @@
22 22
23/* 23/*
24 SUPPORTED DEVICES PCI ID 24 SUPPORTED DEVICES PCI ID
25 82801AA 2413 25 82801AA 2413
26 82801AB 2423 26 82801AB 2423
27 82801BA 2443 27 82801BA 2443
28 82801CA/CAM 2483 28 82801CA/CAM 2483
29 82801DB 24C3 (HW PEC supported, 32 byte buffer not supported) 29 82801DB 24C3 (HW PEC supported)
30 82801EB 24D3 (HW PEC supported, 32 byte buffer not supported) 30 82801EB 24D3 (HW PEC supported)
31 6300ESB 25A4 31 6300ESB 25A4
32 ICH6 266A 32 ICH6 266A
33 ICH7 27DA 33 ICH7 27DA
@@ -74,6 +74,13 @@
74#define SMBHSTCFG_SMB_SMI_EN 2 74#define SMBHSTCFG_SMB_SMI_EN 2
75#define SMBHSTCFG_I2C_EN 4 75#define SMBHSTCFG_I2C_EN 4
76 76
77/* Auxillary control register bits, ICH4+ only */
78#define SMBAUXCTL_CRC 1
79#define SMBAUXCTL_E32B 2
80
81/* kill bit for SMBHSTCNT */
82#define SMBHSTCNT_KILL 2
83
77/* Other settings */ 84/* Other settings */
78#define MAX_TIMEOUT 100 85#define MAX_TIMEOUT 100
79#define ENABLE_INT9 0 /* set to 0x01 to enable - untested */ 86#define ENABLE_INT9 0 /* set to 0x01 to enable - untested */
@@ -91,10 +98,15 @@
91#define I801_START 0x40 98#define I801_START 0x40
92#define I801_PEC_EN 0x80 /* ICH4 only */ 99#define I801_PEC_EN 0x80 /* ICH4 only */
93 100
94 101/* I801 Hosts Status register bits */
95static int i801_transaction(void); 102#define SMBHSTSTS_BYTE_DONE 0x80
96static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 103#define SMBHSTSTS_INUSE_STS 0x40
97 int command, int hwpec); 104#define SMBHSTSTS_SMBALERT_STS 0x20
105#define SMBHSTSTS_FAILED 0x10
106#define SMBHSTSTS_BUS_ERR 0x08
107#define SMBHSTSTS_DEV_ERR 0x04
108#define SMBHSTSTS_INTR 0x02
109#define SMBHSTSTS_HOST_BUSY 0x01
98 110
99static unsigned long i801_smba; 111static unsigned long i801_smba;
100static unsigned char i801_original_hstcfg; 112static unsigned char i801_original_hstcfg;
@@ -102,7 +114,7 @@ static struct pci_driver i801_driver;
102static struct pci_dev *I801_dev; 114static struct pci_dev *I801_dev;
103static int isich4; 115static int isich4;
104 116
105static int i801_transaction(void) 117static int i801_transaction(int xact)
106{ 118{
107 int temp; 119 int temp;
108 int result = 0; 120 int result = 0;
@@ -127,33 +139,40 @@ static int i801_transaction(void)
127 } 139 }
128 } 140 }
129 141
130 outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); 142 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
143 * INTREN, SMBSCMD are passed in xact */
144 outb_p(xact | I801_START, SMBHSTCNT);
131 145
132 /* We will always wait for a fraction of a second! */ 146 /* We will always wait for a fraction of a second! */
133 do { 147 do {
134 msleep(1); 148 msleep(1);
135 temp = inb_p(SMBHSTSTS); 149 temp = inb_p(SMBHSTSTS);
136 } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); 150 } while ((temp & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
137 151
138 /* If the SMBus is still busy, we give up */ 152 /* If the SMBus is still busy, we give up */
139 if (timeout >= MAX_TIMEOUT) { 153 if (timeout >= MAX_TIMEOUT) {
140 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 154 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
141 result = -1; 155 result = -1;
156 /* try to stop the current command */
157 dev_dbg(&I801_dev->dev, "Terminating the current operation\n");
158 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
159 msleep(1);
160 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT);
142 } 161 }
143 162
144 if (temp & 0x10) { 163 if (temp & SMBHSTSTS_FAILED) {
145 result = -1; 164 result = -1;
146 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n"); 165 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n");
147 } 166 }
148 167
149 if (temp & 0x08) { 168 if (temp & SMBHSTSTS_BUS_ERR) {
150 result = -1; 169 result = -1;
151 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked " 170 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked "
152 "until next hard reset. (sorry!)\n"); 171 "until next hard reset. (sorry!)\n");
153 /* Clock stops and slave is stuck in mid-transmission */ 172 /* Clock stops and slave is stuck in mid-transmission */
154 } 173 }
155 174
156 if (temp & 0x04) { 175 if (temp & SMBHSTSTS_DEV_ERR) {
157 result = -1; 176 result = -1;
158 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 177 dev_dbg(&I801_dev->dev, "Error: no response!\n");
159 } 178 }
@@ -172,44 +191,70 @@ static int i801_transaction(void)
172 return result; 191 return result;
173} 192}
174 193
175/* All-inclusive block transaction function */ 194/* wait for INTR bit as advised by Intel */
176static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 195static void i801_wait_hwpec(void)
177 int command, int hwpec) 196{
197 int timeout = 0;
198 int temp;
199
200 do {
201 msleep(1);
202 temp = inb_p(SMBHSTSTS);
203 } while ((!(temp & SMBHSTSTS_INTR))
204 && (timeout++ < MAX_TIMEOUT));
205
206 if (timeout >= MAX_TIMEOUT) {
207 dev_dbg(&I801_dev->dev, "PEC Timeout!\n");
208 }
209 outb_p(temp, SMBHSTSTS);
210}
211
212static int i801_block_transaction_by_block(union i2c_smbus_data *data,
213 char read_write, int hwpec)
214{
215 int i, len;
216
217 inb_p(SMBHSTCNT); /* reset the data buffer index */
218
219 /* Use 32-byte buffer to process this transaction */
220 if (read_write == I2C_SMBUS_WRITE) {
221 len = data->block[0];
222 outb_p(len, SMBHSTDAT0);
223 for (i = 0; i < len; i++)
224 outb_p(data->block[i+1], SMBBLKDAT);
225 }
226
227 if (i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 |
228 I801_PEC_EN * hwpec))
229 return -1;
230
231 if (read_write == I2C_SMBUS_READ) {
232 len = inb_p(SMBHSTDAT0);
233 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
234 return -1;
235
236 data->block[0] = len;
237 for (i = 0; i < len; i++)
238 data->block[i + 1] = inb_p(SMBBLKDAT);
239 }
240 return 0;
241}
242
243static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
244 char read_write, int hwpec)
178{ 245{
179 int i, len; 246 int i, len;
180 int smbcmd; 247 int smbcmd;
181 int temp; 248 int temp;
182 int result = 0; 249 int result = 0;
183 int timeout; 250 int timeout;
184 unsigned char hostc, errmask; 251 unsigned char errmask;
185 252
186 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 253 len = data->block[0];
187 if (read_write == I2C_SMBUS_WRITE) {
188 /* set I2C_EN bit in configuration register */
189 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc);
190 pci_write_config_byte(I801_dev, SMBHSTCFG,
191 hostc | SMBHSTCFG_I2C_EN);
192 } else {
193 dev_err(&I801_dev->dev,
194 "I2C_SMBUS_I2C_BLOCK_READ not DB!\n");
195 return -1;
196 }
197 }
198 254
199 if (read_write == I2C_SMBUS_WRITE) { 255 if (read_write == I2C_SMBUS_WRITE) {
200 len = data->block[0];
201 if (len < 1)
202 len = 1;
203 if (len > 32)
204 len = 32;
205 outb_p(len, SMBHSTDAT0); 256 outb_p(len, SMBHSTDAT0);
206 outb_p(data->block[1], SMBBLKDAT); 257 outb_p(data->block[1], SMBBLKDAT);
207 } else {
208 len = 32; /* max for reads */
209 }
210
211 if(isich4 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
212 /* set 32 byte buffer */
213 } 258 }
214 259
215 for (i = 1; i <= len; i++) { 260 for (i = 1; i <= len; i++) {
@@ -227,13 +272,13 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
227 /* Make sure the SMBus host is ready to start transmitting */ 272 /* Make sure the SMBus host is ready to start transmitting */
228 temp = inb_p(SMBHSTSTS); 273 temp = inb_p(SMBHSTSTS);
229 if (i == 1) { 274 if (i == 1) {
230 /* Erronenous conditions before transaction: 275 /* Erronenous conditions before transaction:
231 * Byte_Done, Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ 276 * Byte_Done, Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
232 errmask=0x9f; 277 errmask = 0x9f;
233 } else { 278 } else {
234 /* Erronenous conditions during transaction: 279 /* Erronenous conditions during transaction:
235 * Failed, Bus_Err, Dev_Err, Intr */ 280 * Failed, Bus_Err, Dev_Err, Intr */
236 errmask=0x1e; 281 errmask = 0x1e;
237 } 282 }
238 if (temp & errmask) { 283 if (temp & errmask) {
239 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). " 284 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
@@ -242,14 +287,11 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
242 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 287 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
243 dev_err(&I801_dev->dev, 288 dev_err(&I801_dev->dev,
244 "Reset failed! (%02x)\n", temp); 289 "Reset failed! (%02x)\n", temp);
245 result = -1; 290 return -1;
246 goto END;
247 } 291 }
248 if (i != 1) { 292 if (i != 1)
249 /* if die in middle of block transaction, fail */ 293 /* if die in middle of block transaction, fail */
250 result = -1; 294 return -1;
251 goto END;
252 }
253 } 295 }
254 296
255 if (i == 1) 297 if (i == 1)
@@ -261,33 +303,38 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
261 msleep(1); 303 msleep(1);
262 temp = inb_p(SMBHSTSTS); 304 temp = inb_p(SMBHSTSTS);
263 } 305 }
264 while ((!(temp & 0x80)) 306 while ((!(temp & SMBHSTSTS_BYTE_DONE))
265 && (timeout++ < MAX_TIMEOUT)); 307 && (timeout++ < MAX_TIMEOUT));
266 308
267 /* If the SMBus is still busy, we give up */ 309 /* If the SMBus is still busy, we give up */
268 if (timeout >= MAX_TIMEOUT) { 310 if (timeout >= MAX_TIMEOUT) {
311 /* try to stop the current command */
312 dev_dbg(&I801_dev->dev, "Terminating the current "
313 "operation\n");
314 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
315 msleep(1);
316 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL),
317 SMBHSTCNT);
269 result = -1; 318 result = -1;
270 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 319 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
271 } 320 }
272 321
273 if (temp & 0x10) { 322 if (temp & SMBHSTSTS_FAILED) {
274 result = -1; 323 result = -1;
275 dev_dbg(&I801_dev->dev, 324 dev_dbg(&I801_dev->dev,
276 "Error: Failed bus transaction\n"); 325 "Error: Failed bus transaction\n");
277 } else if (temp & 0x08) { 326 } else if (temp & SMBHSTSTS_BUS_ERR) {
278 result = -1; 327 result = -1;
279 dev_err(&I801_dev->dev, "Bus collision!\n"); 328 dev_err(&I801_dev->dev, "Bus collision!\n");
280 } else if (temp & 0x04) { 329 } else if (temp & SMBHSTSTS_DEV_ERR) {
281 result = -1; 330 result = -1;
282 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 331 dev_dbg(&I801_dev->dev, "Error: no response!\n");
283 } 332 }
284 333
285 if (i == 1 && read_write == I2C_SMBUS_READ) { 334 if (i == 1 && read_write == I2C_SMBUS_READ) {
286 len = inb_p(SMBHSTDAT0); 335 len = inb_p(SMBHSTDAT0);
287 if (len < 1) 336 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
288 len = 1; 337 return -1;
289 if (len > 32)
290 len = 32;
291 data->block[0] = len; 338 data->block[0] = len;
292 } 339 }
293 340
@@ -310,25 +357,58 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
310 inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT)); 357 inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT));
311 358
312 if (result < 0) 359 if (result < 0)
313 goto END; 360 return result;
314 } 361 }
362 return result;
363}
315 364
316 if (hwpec) { 365static int i801_set_block_buffer_mode(void)
317 /* wait for INTR bit as advised by Intel */ 366{
318 timeout = 0; 367 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL);
319 do { 368 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0)
320 msleep(1); 369 return -1;
321 temp = inb_p(SMBHSTSTS); 370 return 0;
322 } while ((!(temp & 0x02)) 371}
323 && (timeout++ < MAX_TIMEOUT));
324 372
325 if (timeout >= MAX_TIMEOUT) { 373/* Block transaction function */
326 dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); 374static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
375 int command, int hwpec)
376{
377 int result = 0;
378 unsigned char hostc;
379
380 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
381 if (read_write == I2C_SMBUS_WRITE) {
382 /* set I2C_EN bit in configuration register */
383 pci_read_config_byte(I801_dev, SMBHSTCFG, &hostc);
384 pci_write_config_byte(I801_dev, SMBHSTCFG,
385 hostc | SMBHSTCFG_I2C_EN);
386 } else {
387 dev_err(&I801_dev->dev,
388 "I2C_SMBUS_I2C_BLOCK_READ not DB!\n");
389 return -1;
327 } 390 }
328 outb_p(temp, SMBHSTSTS);
329 } 391 }
330 result = 0; 392
331END: 393 if (read_write == I2C_SMBUS_WRITE) {
394 if (data->block[0] < 1)
395 data->block[0] = 1;
396 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
397 data->block[0] = I2C_SMBUS_BLOCK_MAX;
398 } else {
399 data->block[0] = 32; /* max for reads */
400 }
401
402 if (isich4 && i801_set_block_buffer_mode() == 0 )
403 result = i801_block_transaction_by_block(data, read_write,
404 hwpec);
405 else
406 result = i801_block_transaction_byte_by_byte(data, read_write,
407 hwpec);
408
409 if (result == 0 && hwpec)
410 i801_wait_hwpec();
411
332 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 412 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
333 /* restore saved configuration register value */ 413 /* restore saved configuration register value */
334 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc); 414 pci_write_config_byte(I801_dev, SMBHSTCFG, hostc);
@@ -393,19 +473,22 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
393 return -1; 473 return -1;
394 } 474 }
395 475
396 outb_p(hwpec, SMBAUXCTL); /* enable/disable hardware PEC */ 476 if (hwpec) /* enable/disable hardware PEC */
477 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_CRC, SMBAUXCTL);
478 else
479 outb_p(inb_p(SMBAUXCTL) & (~SMBAUXCTL_CRC), SMBAUXCTL);
397 480
398 if(block) 481 if(block)
399 ret = i801_block_transaction(data, read_write, size, hwpec); 482 ret = i801_block_transaction(data, read_write, size, hwpec);
400 else { 483 else
401 outb_p(xact | ENABLE_INT9, SMBHSTCNT); 484 ret = i801_transaction(xact | ENABLE_INT9);
402 ret = i801_transaction();
403 }
404 485
405 /* Some BIOSes don't like it when PEC is enabled at reboot or resume 486 /* Some BIOSes don't like it when PEC is enabled at reboot or resume
406 time, so we forcibly disable it after every transaction. */ 487 time, so we forcibly disable it after every transaction. Turn off
488 E32B for the same reason. */
407 if (hwpec) 489 if (hwpec)
408 outb_p(0, SMBAUXCTL); 490 outb_p(inb_p(SMBAUXCTL) & ~(SMBAUXCTL_CRC | SMBAUXCTL_E32B),
491 SMBAUXCTL);
409 492
410 if(block) 493 if(block)
411 return ret; 494 return ret;
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 90e2d9350c1b..440342bc62e1 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -491,6 +491,7 @@ iop3xx_i2c_probe(struct platform_device *pdev)
491 new_adapter->id = I2C_HW_IOP3XX; 491 new_adapter->id = I2C_HW_IOP3XX;
492 new_adapter->owner = THIS_MODULE; 492 new_adapter->owner = THIS_MODULE;
493 new_adapter->dev.parent = &pdev->dev; 493 new_adapter->dev.parent = &pdev->dev;
494 new_adapter->nr = pdev->id;
494 495
495 /* 496 /*
496 * Default values...should these come in from board code? 497 * Default values...should these come in from board code?
@@ -508,7 +509,7 @@ iop3xx_i2c_probe(struct platform_device *pdev)
508 platform_set_drvdata(pdev, new_adapter); 509 platform_set_drvdata(pdev, new_adapter);
509 new_adapter->algo_data = adapter_data; 510 new_adapter->algo_data = adapter_data;
510 511
511 i2c_add_adapter(new_adapter); 512 i2c_add_numbered_adapter(new_adapter);
512 513
513 return 0; 514 return 0;
514 515
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index c6b6898592b1..851c3ed513d0 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -74,6 +74,25 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id)
74 return IRQ_HANDLED; 74 return IRQ_HANDLED;
75} 75}
76 76
77/* Sometimes 9th clock pulse isn't generated, and slave doesn't release
78 * the bus, because it wants to send ACK.
79 * Following sequence of enabling/disabling and sending start/stop generates
80 * the pulse, so it's all OK.
81 */
82static void mpc_i2c_fixup(struct mpc_i2c *i2c)
83{
84 writeccr(i2c, 0);
85 udelay(30);
86 writeccr(i2c, CCR_MEN);
87 udelay(30);
88 writeccr(i2c, CCR_MSTA | CCR_MTX);
89 udelay(30);
90 writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN);
91 udelay(30);
92 writeccr(i2c, CCR_MEN);
93 udelay(30);
94}
95
77static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing) 96static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
78{ 97{
79 unsigned long orig_jiffies = jiffies; 98 unsigned long orig_jiffies = jiffies;
@@ -153,6 +172,7 @@ static void mpc_i2c_start(struct mpc_i2c *i2c)
153static void mpc_i2c_stop(struct mpc_i2c *i2c) 172static void mpc_i2c_stop(struct mpc_i2c *i2c)
154{ 173{
155 writeccr(i2c, CCR_MEN); 174 writeccr(i2c, CCR_MEN);
175 writeccr(i2c, 0);
156} 176}
157 177
158static int mpc_write(struct mpc_i2c *i2c, int target, 178static int mpc_write(struct mpc_i2c *i2c, int target,
@@ -245,6 +265,9 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
245 } 265 }
246 if (time_after(jiffies, orig_jiffies + HZ)) { 266 if (time_after(jiffies, orig_jiffies + HZ)) {
247 pr_debug("I2C: timeout\n"); 267 pr_debug("I2C: timeout\n");
268 if (readb(i2c->base + MPC_I2C_SR) ==
269 (CSR_MCF | CSR_MBB | CSR_RXAK))
270 mpc_i2c_fixup(i2c);
248 return -EIO; 271 return -EIO;
249 } 272 }
250 schedule(); 273 schedule();
@@ -327,9 +350,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
327 platform_set_drvdata(pdev, i2c); 350 platform_set_drvdata(pdev, i2c);
328 351
329 i2c->adap = mpc_ops; 352 i2c->adap = mpc_ops;
353 i2c->adap.nr = pdev->id;
330 i2c_set_adapdata(&i2c->adap, i2c); 354 i2c_set_adapdata(&i2c->adap, i2c);
331 i2c->adap.dev.parent = &pdev->dev; 355 i2c->adap.dev.parent = &pdev->dev;
332 if ((result = i2c_add_adapter(&i2c->adap)) < 0) { 356 if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
333 printk(KERN_ERR "i2c-mpc - failed to add adapter\n"); 357 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
334 goto fail_add; 358 goto fail_add;
335 } 359 }
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a55b3335d1be..251154ae5d97 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -527,6 +527,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
527 drv_data->adapter.class = I2C_CLASS_HWMON; 527 drv_data->adapter.class = I2C_CLASS_HWMON;
528 drv_data->adapter.timeout = pdata->timeout; 528 drv_data->adapter.timeout = pdata->timeout;
529 drv_data->adapter.retries = pdata->retries; 529 drv_data->adapter.retries = pdata->retries;
530 drv_data->adapter.nr = pd->id;
530 platform_set_drvdata(pd, drv_data); 531 platform_set_drvdata(pd, drv_data);
531 i2c_set_adapdata(&drv_data->adapter, drv_data); 532 i2c_set_adapdata(&drv_data->adapter, drv_data);
532 533
@@ -539,7 +540,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
539 drv_data->irq); 540 drv_data->irq);
540 rc = -EINVAL; 541 rc = -EINVAL;
541 goto exit_unmap_regs; 542 goto exit_unmap_regs;
542 } else if ((rc = i2c_add_adapter(&drv_data->adapter)) != 0) { 543 } else if ((rc = i2c_add_numbered_adapter(&drv_data->adapter)) != 0) {
543 dev_err(&drv_data->adapter.dev, 544 dev_err(&drv_data->adapter.dev,
544 "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc); 545 "mv64xxx: Can't add i2c adapter, rc: %d\n", -rc);
545 goto exit_free_irq; 546 goto exit_free_irq;
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 3cd0d63e7b50..c48140f782d0 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -61,6 +61,7 @@ struct nforce2_smbus {
61 struct i2c_adapter adapter; 61 struct i2c_adapter adapter;
62 int base; 62 int base;
63 int size; 63 int size;
64 int blockops;
64}; 65};
65 66
66 67
@@ -80,6 +81,8 @@ struct nforce2_smbus {
80#define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */ 81#define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */
81#define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */ 82#define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */
82#define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */ 83#define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */
84#define NVIDIA_SMB_BCNT (smbus->base + 0x24) /* number of data
85 bytes */
83 86
84#define NVIDIA_SMB_STS_DONE 0x80 87#define NVIDIA_SMB_STS_DONE 0x80
85#define NVIDIA_SMB_STS_ALRM 0x40 88#define NVIDIA_SMB_STS_ALRM 0x40
@@ -92,6 +95,7 @@ struct nforce2_smbus {
92#define NVIDIA_SMB_PRTCL_BYTE 0x04 95#define NVIDIA_SMB_PRTCL_BYTE 0x04
93#define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06 96#define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06
94#define NVIDIA_SMB_PRTCL_WORD_DATA 0x08 97#define NVIDIA_SMB_PRTCL_WORD_DATA 0x08
98#define NVIDIA_SMB_PRTCL_BLOCK_DATA 0x0a
95#define NVIDIA_SMB_PRTCL_PEC 0x80 99#define NVIDIA_SMB_PRTCL_PEC 0x80
96 100
97static struct pci_driver nforce2_driver; 101static struct pci_driver nforce2_driver;
@@ -103,6 +107,8 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
103{ 107{
104 struct nforce2_smbus *smbus = adap->algo_data; 108 struct nforce2_smbus *smbus = adap->algo_data;
105 unsigned char protocol, pec, temp; 109 unsigned char protocol, pec, temp;
110 u8 len;
111 int i;
106 112
107 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 113 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
108 NVIDIA_SMB_PRTCL_WRITE; 114 NVIDIA_SMB_PRTCL_WRITE;
@@ -137,6 +143,25 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
137 protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; 143 protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec;
138 break; 144 break;
139 145
146 case I2C_SMBUS_BLOCK_DATA:
147 outb_p(command, NVIDIA_SMB_CMD);
148 if (read_write == I2C_SMBUS_WRITE) {
149 len = data->block[0];
150 if ((len == 0) || (len > I2C_SMBUS_BLOCK_MAX)) {
151 dev_err(&adap->dev,
152 "Transaction failed "
153 "(requested block size: %d)\n",
154 len);
155 return -1;
156 }
157 outb_p(len, NVIDIA_SMB_BCNT);
158 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
159 outb_p(data->block[i + 1],
160 NVIDIA_SMB_DATA+i);
161 }
162 protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec;
163 break;
164
140 default: 165 default:
141 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 166 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
142 return -1; 167 return -1;
@@ -174,6 +199,14 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
174 case I2C_SMBUS_WORD_DATA: 199 case I2C_SMBUS_WORD_DATA:
175 data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8); 200 data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8);
176 break; 201 break;
202
203 case I2C_SMBUS_BLOCK_DATA:
204 len = inb_p(NVIDIA_SMB_BCNT);
205 len = min_t(u8, len, I2C_SMBUS_BLOCK_MAX);
206 for (i = 0; i < len; i++)
207 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i);
208 data->block[0] = len;
209 break;
177 } 210 }
178 211
179 return 0; 212 return 0;
@@ -184,7 +217,9 @@ static u32 nforce2_func(struct i2c_adapter *adapter)
184{ 217{
185 /* other functionality might be possible, but is not tested */ 218 /* other functionality might be possible, but is not tested */
186 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 219 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
187 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 220 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
221 (((struct nforce2_smbus*)adapter->algo_data)->blockops ?
222 I2C_FUNC_SMBUS_BLOCK_DATA : 0);
188} 223}
189 224
190static struct i2c_algorithm smbus_algorithm = { 225static struct i2c_algorithm smbus_algorithm = {
@@ -268,6 +303,13 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
268 return -ENOMEM; 303 return -ENOMEM;
269 pci_set_drvdata(dev, smbuses); 304 pci_set_drvdata(dev, smbuses);
270 305
306 switch(dev->device) {
307 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS:
308 case PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS:
309 smbuses[0].blockops = 1;
310 smbuses[1].blockops = 1;
311 }
312
271 /* SMBus adapter 1 */ 313 /* SMBus adapter 1 */
272 res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1"); 314 res1 = nforce2_probe_smb(dev, 4, NFORCE_PCI_SMB1, &smbuses[0], "SMB1");
273 if (res1 < 0) { 315 if (res1 < 0) {
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 5a52bf5e3fb0..debc76cd2161 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -23,7 +23,7 @@
23 Supports: 23 Supports:
24 Intel PIIX4, 440MX 24 Intel PIIX4, 440MX
25 Serverworks OSB4, CSB5, CSB6, HT-1000 25 Serverworks OSB4, CSB5, CSB6, HT-1000
26 ATI IXP200, IXP300, IXP400, SB600 26 ATI IXP200, IXP300, IXP400, SB600, SB700
27 SMSC Victory66 27 SMSC Victory66
28 28
29 Note: we assume there can only be one device, with one SMBus interface. 29 Note: we assume there can only be one device, with one SMBus interface.
@@ -399,6 +399,8 @@ static struct pci_device_id piix4_ids[] = {
399 .driver_data = 0 }, 399 .driver_data = 0 },
400 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SMBUS), 400 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SMBUS),
401 .driver_data = 0 }, 401 .driver_data = 0 },
402 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SMBUS),
403 .driver_data = 0 },
402 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4), 404 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4),
403 .driver_data = 0 }, 405 .driver_data = 0 },
404 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5), 406 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5),
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
new file mode 100644
index 000000000000..03188d277af1
--- /dev/null
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -0,0 +1,653 @@
1/*
2 * Specific bus support for PMC-TWI compliant implementation on MSP71xx.
3 *
4 * Copyright 2005-2007 PMC-Sierra, Inc.
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
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
14 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/platform_device.h>
31#include <linux/i2c.h>
32#include <linux/interrupt.h>
33#include <linux/completion.h>
34#include <linux/mutex.h>
35#include <linux/delay.h>
36#include <asm/io.h>
37
38#define DRV_NAME "pmcmsptwi"
39
40#define MSP_TWI_SF_CLK_REG_OFFSET 0x00
41#define MSP_TWI_HS_CLK_REG_OFFSET 0x04
42#define MSP_TWI_CFG_REG_OFFSET 0x08
43#define MSP_TWI_CMD_REG_OFFSET 0x0c
44#define MSP_TWI_ADD_REG_OFFSET 0x10
45#define MSP_TWI_DAT_0_REG_OFFSET 0x14
46#define MSP_TWI_DAT_1_REG_OFFSET 0x18
47#define MSP_TWI_INT_STS_REG_OFFSET 0x1c
48#define MSP_TWI_INT_MSK_REG_OFFSET 0x20
49#define MSP_TWI_BUSY_REG_OFFSET 0x24
50
51#define MSP_TWI_INT_STS_DONE (1 << 0)
52#define MSP_TWI_INT_STS_LOST_ARBITRATION (1 << 1)
53#define MSP_TWI_INT_STS_NO_RESPONSE (1 << 2)
54#define MSP_TWI_INT_STS_DATA_COLLISION (1 << 3)
55#define MSP_TWI_INT_STS_BUSY (1 << 4)
56#define MSP_TWI_INT_STS_ALL 0x1f
57
58#define MSP_MAX_BYTES_PER_RW 8
59#define MSP_MAX_POLL 5
60#define MSP_POLL_DELAY 10
61#define MSP_IRQ_TIMEOUT (MSP_MAX_POLL * MSP_POLL_DELAY)
62
63/* IO Operation macros */
64#define pmcmsptwi_readl __raw_readl
65#define pmcmsptwi_writel __raw_writel
66
67/* TWI command type */
68enum pmcmsptwi_cmd_type {
69 MSP_TWI_CMD_WRITE = 0, /* Write only */
70 MSP_TWI_CMD_READ = 1, /* Read only */
71 MSP_TWI_CMD_WRITE_READ = 2, /* Write then Read */
72};
73
74/* The possible results of the xferCmd */
75enum pmcmsptwi_xfer_result {
76 MSP_TWI_XFER_OK = 0,
77 MSP_TWI_XFER_TIMEOUT,
78 MSP_TWI_XFER_BUSY,
79 MSP_TWI_XFER_DATA_COLLISION,
80 MSP_TWI_XFER_NO_RESPONSE,
81 MSP_TWI_XFER_LOST_ARBITRATION,
82};
83
84/* Corresponds to a PMCTWI clock configuration register */
85struct pmcmsptwi_clock {
86 u8 filter; /* Bits 15:12, default = 0x03 */
87 u16 clock; /* Bits 9:0, default = 0x001f */
88};
89
90struct pmcmsptwi_clockcfg {
91 struct pmcmsptwi_clock standard; /* The standard/fast clock config */
92 struct pmcmsptwi_clock highspeed; /* The highspeed clock config */
93};
94
95/* Corresponds to the main TWI configuration register */
96struct pmcmsptwi_cfg {
97 u8 arbf; /* Bits 15:12, default=0x03 */
98 u8 nak; /* Bits 11:8, default=0x03 */
99 u8 add10; /* Bit 7, default=0x00 */
100 u8 mst_code; /* Bits 6:4, default=0x00 */
101 u8 arb; /* Bit 1, default=0x01 */
102 u8 highspeed; /* Bit 0, default=0x00 */
103};
104
105/* A single pmctwi command to issue */
106struct pmcmsptwi_cmd {
107 u16 addr; /* The slave address (7 or 10 bits) */
108 enum pmcmsptwi_cmd_type type; /* The command type */
109 u8 write_len; /* Number of bytes in the write buffer */
110 u8 read_len; /* Number of bytes in the read buffer */
111 u8 *write_data; /* Buffer of characters to send */
112 u8 *read_data; /* Buffer to fill with incoming data */
113};
114
115/* The private data */
116struct pmcmsptwi_data {
117 void __iomem *iobase; /* iomapped base for IO */
118 int irq; /* IRQ to use (0 disables) */
119 struct completion wait; /* Completion for xfer */
120 struct mutex lock; /* Used for threadsafeness */
121 enum pmcmsptwi_xfer_result last_result; /* result of last xfer */
122};
123
124/* The default settings */
125const static struct pmcmsptwi_clockcfg pmcmsptwi_defclockcfg = {
126 .standard = {
127 .filter = 0x3,
128 .clock = 0x1f,
129 },
130 .highspeed = {
131 .filter = 0x3,
132 .clock = 0x1f,
133 },
134};
135
136const static struct pmcmsptwi_cfg pmcmsptwi_defcfg = {
137 .arbf = 0x03,
138 .nak = 0x03,
139 .add10 = 0x00,
140 .mst_code = 0x00,
141 .arb = 0x01,
142 .highspeed = 0x00,
143};
144
145static struct pmcmsptwi_data pmcmsptwi_data;
146
147static struct i2c_adapter pmcmsptwi_adapter;
148
149/* inline helper functions */
150static inline u32 pmcmsptwi_clock_to_reg(
151 const struct pmcmsptwi_clock *clock)
152{
153 return ((clock->filter & 0xf) << 12) | (clock->clock & 0x03ff);
154}
155
156static inline void pmcmsptwi_reg_to_clock(
157 u32 reg, struct pmcmsptwi_clock *clock)
158{
159 clock->filter = (reg >> 12) & 0xf;
160 clock->clock = reg & 0x03ff;
161}
162
163static inline u32 pmcmsptwi_cfg_to_reg(const struct pmcmsptwi_cfg *cfg)
164{
165 return ((cfg->arbf & 0xf) << 12) |
166 ((cfg->nak & 0xf) << 8) |
167 ((cfg->add10 & 0x1) << 7) |
168 ((cfg->mst_code & 0x7) << 4) |
169 ((cfg->arb & 0x1) << 1) |
170 (cfg->highspeed & 0x1);
171}
172
173static inline void pmcmsptwi_reg_to_cfg(u32 reg, struct pmcmsptwi_cfg *cfg)
174{
175 cfg->arbf = (reg >> 12) & 0xf;
176 cfg->nak = (reg >> 8) & 0xf;
177 cfg->add10 = (reg >> 7) & 0x1;
178 cfg->mst_code = (reg >> 4) & 0x7;
179 cfg->arb = (reg >> 1) & 0x1;
180 cfg->highspeed = reg & 0x1;
181}
182
183/*
184 * Sets the current clock configuration
185 */
186static void pmcmsptwi_set_clock_config(const struct pmcmsptwi_clockcfg *cfg,
187 struct pmcmsptwi_data *data)
188{
189 mutex_lock(&data->lock);
190 pmcmsptwi_writel(pmcmsptwi_clock_to_reg(&cfg->standard),
191 data->iobase + MSP_TWI_SF_CLK_REG_OFFSET);
192 pmcmsptwi_writel(pmcmsptwi_clock_to_reg(&cfg->highspeed),
193 data->iobase + MSP_TWI_HS_CLK_REG_OFFSET);
194 mutex_unlock(&data->lock);
195}
196
197/*
198 * Gets the current TWI bus configuration
199 */
200static void pmcmsptwi_get_twi_config(struct pmcmsptwi_cfg *cfg,
201 struct pmcmsptwi_data *data)
202{
203 mutex_lock(&data->lock);
204 pmcmsptwi_reg_to_cfg(pmcmsptwi_readl(
205 data->iobase + MSP_TWI_CFG_REG_OFFSET), cfg);
206 mutex_unlock(&data->lock);
207}
208
209/*
210 * Sets the current TWI bus configuration
211 */
212static void pmcmsptwi_set_twi_config(const struct pmcmsptwi_cfg *cfg,
213 struct pmcmsptwi_data *data)
214{
215 mutex_lock(&data->lock);
216 pmcmsptwi_writel(pmcmsptwi_cfg_to_reg(cfg),
217 data->iobase + MSP_TWI_CFG_REG_OFFSET);
218 mutex_unlock(&data->lock);
219}
220
221/*
222 * Parses the 'int_sts' register and returns a well-defined error code
223 */
224static enum pmcmsptwi_xfer_result pmcmsptwi_get_result(u32 reg)
225{
226 if (reg & MSP_TWI_INT_STS_LOST_ARBITRATION) {
227 dev_dbg(&pmcmsptwi_adapter.dev,
228 "Result: Lost arbitration\n");
229 return MSP_TWI_XFER_LOST_ARBITRATION;
230 } else if (reg & MSP_TWI_INT_STS_NO_RESPONSE) {
231 dev_dbg(&pmcmsptwi_adapter.dev,
232 "Result: No response\n");
233 return MSP_TWI_XFER_NO_RESPONSE;
234 } else if (reg & MSP_TWI_INT_STS_DATA_COLLISION) {
235 dev_dbg(&pmcmsptwi_adapter.dev,
236 "Result: Data collision\n");
237 return MSP_TWI_XFER_DATA_COLLISION;
238 } else if (reg & MSP_TWI_INT_STS_BUSY) {
239 dev_dbg(&pmcmsptwi_adapter.dev,
240 "Result: Bus busy\n");
241 return MSP_TWI_XFER_BUSY;
242 }
243
244 dev_dbg(&pmcmsptwi_adapter.dev, "Result: Operation succeeded\n");
245 return MSP_TWI_XFER_OK;
246}
247
248/*
249 * In interrupt mode, handle the interrupt.
250 * NOTE: Assumes data->lock is held.
251 */
252static irqreturn_t pmcmsptwi_interrupt(int irq, void *ptr)
253{
254 struct pmcmsptwi_data *data = ptr;
255
256 u32 reason = pmcmsptwi_readl(data->iobase +
257 MSP_TWI_INT_STS_REG_OFFSET);
258 pmcmsptwi_writel(reason, data->iobase + MSP_TWI_INT_STS_REG_OFFSET);
259
260 dev_dbg(&pmcmsptwi_adapter.dev, "Got interrupt 0x%08x\n", reason);
261 if (!(reason & MSP_TWI_INT_STS_DONE))
262 return IRQ_NONE;
263
264 data->last_result = pmcmsptwi_get_result(reason);
265 complete(&data->wait);
266
267 return IRQ_HANDLED;
268}
269
270/*
271 * Probe for and register the device and return 0 if there is one.
272 */
273static int __devinit pmcmsptwi_probe(struct platform_device *pldev)
274{
275 struct resource *res;
276 int rc = -ENODEV;
277
278 /* get the static platform resources */
279 res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
280 if (!res) {
281 dev_err(&pldev->dev, "IOMEM resource not found\n");
282 goto ret_err;
283 }
284
285 /* reserve the memory region */
286 if (!request_mem_region(res->start, res->end - res->start + 1,
287 pldev->name)) {
288 dev_err(&pldev->dev,
289 "Unable to get memory/io address region 0x%08x\n",
290 res->start);
291 rc = -EBUSY;
292 goto ret_err;
293 }
294
295 /* remap the memory */
296 pmcmsptwi_data.iobase = ioremap_nocache(res->start,
297 res->end - res->start + 1);
298 if (!pmcmsptwi_data.iobase) {
299 dev_err(&pldev->dev,
300 "Unable to ioremap address 0x%08x\n", res->start);
301 rc = -EIO;
302 goto ret_unreserve;
303 }
304
305 /* request the irq */
306 pmcmsptwi_data.irq = platform_get_irq(pldev, 0);
307 if (pmcmsptwi_data.irq) {
308 rc = request_irq(pmcmsptwi_data.irq, &pmcmsptwi_interrupt,
309 IRQF_SHARED | IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
310 pldev->name, &pmcmsptwi_data);
311 if (rc == 0) {
312 /*
313 * Enable 'DONE' interrupt only.
314 *
315 * If you enable all interrupts, you will get one on
316 * error and another when the operation completes.
317 * This way you only have to handle one interrupt,
318 * but you can still check all result flags.
319 */
320 pmcmsptwi_writel(MSP_TWI_INT_STS_DONE,
321 pmcmsptwi_data.iobase +
322 MSP_TWI_INT_MSK_REG_OFFSET);
323 } else {
324 dev_warn(&pldev->dev,
325 "Could not assign TWI IRQ handler "
326 "to irq %d (continuing with poll)\n",
327 pmcmsptwi_data.irq);
328 pmcmsptwi_data.irq = 0;
329 }
330 }
331
332 init_completion(&pmcmsptwi_data.wait);
333 mutex_init(&pmcmsptwi_data.lock);
334
335 pmcmsptwi_set_clock_config(&pmcmsptwi_defclockcfg, &pmcmsptwi_data);
336 pmcmsptwi_set_twi_config(&pmcmsptwi_defcfg, &pmcmsptwi_data);
337
338 printk(KERN_INFO DRV_NAME ": Registering MSP71xx I2C adapter\n");
339
340 pmcmsptwi_adapter.dev.parent = &pldev->dev;
341 platform_set_drvdata(pldev, &pmcmsptwi_adapter);
342 i2c_set_adapdata(&pmcmsptwi_adapter, &pmcmsptwi_data);
343
344 rc = i2c_add_adapter(&pmcmsptwi_adapter);
345 if (rc) {
346 dev_err(&pldev->dev, "Unable to register I2C adapter\n");
347 goto ret_unmap;
348 }
349
350 return 0;
351
352ret_unmap:
353 platform_set_drvdata(pldev, NULL);
354 if (pmcmsptwi_data.irq) {
355 pmcmsptwi_writel(0,
356 pmcmsptwi_data.iobase + MSP_TWI_INT_MSK_REG_OFFSET);
357 free_irq(pmcmsptwi_data.irq, &pmcmsptwi_data);
358 }
359
360 iounmap(pmcmsptwi_data.iobase);
361
362ret_unreserve:
363 release_mem_region(res->start, res->end - res->start + 1);
364
365ret_err:
366 return rc;
367}
368
369/*
370 * Release the device and return 0 if there is one.
371 */
372static int __devexit pmcmsptwi_remove(struct platform_device *pldev)
373{
374 struct resource *res;
375
376 i2c_del_adapter(&pmcmsptwi_adapter);
377
378 platform_set_drvdata(pldev, NULL);
379 if (pmcmsptwi_data.irq) {
380 pmcmsptwi_writel(0,
381 pmcmsptwi_data.iobase + MSP_TWI_INT_MSK_REG_OFFSET);
382 free_irq(pmcmsptwi_data.irq, &pmcmsptwi_data);
383 }
384
385 iounmap(pmcmsptwi_data.iobase);
386
387 res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
388 release_mem_region(res->start, res->end - res->start + 1);
389
390 return 0;
391}
392
393/*
394 * Polls the 'busy' register until the command is complete.
395 * NOTE: Assumes data->lock is held.
396 */
397static void pmcmsptwi_poll_complete(struct pmcmsptwi_data *data)
398{
399 int i;
400
401 for (i = 0; i < MSP_MAX_POLL; i++) {
402 u32 val = pmcmsptwi_readl(data->iobase +
403 MSP_TWI_BUSY_REG_OFFSET);
404 if (val == 0) {
405 u32 reason = pmcmsptwi_readl(data->iobase +
406 MSP_TWI_INT_STS_REG_OFFSET);
407 pmcmsptwi_writel(reason, data->iobase +
408 MSP_TWI_INT_STS_REG_OFFSET);
409 data->last_result = pmcmsptwi_get_result(reason);
410 return;
411 }
412 udelay(MSP_POLL_DELAY);
413 }
414
415 dev_dbg(&pmcmsptwi_adapter.dev, "Result: Poll timeout\n");
416 data->last_result = MSP_TWI_XFER_TIMEOUT;
417}
418
419/*
420 * Do the transfer (low level):
421 * May use interrupt-driven or polling, depending on if an IRQ is
422 * presently registered.
423 * NOTE: Assumes data->lock is held.
424 */
425static enum pmcmsptwi_xfer_result pmcmsptwi_do_xfer(
426 u32 reg, struct pmcmsptwi_data *data)
427{
428 dev_dbg(&pmcmsptwi_adapter.dev, "Writing cmd reg 0x%08x\n", reg);
429 pmcmsptwi_writel(reg, data->iobase + MSP_TWI_CMD_REG_OFFSET);
430 if (data->irq) {
431 unsigned long timeleft = wait_for_completion_timeout(
432 &data->wait, MSP_IRQ_TIMEOUT);
433 if (timeleft == 0) {
434 dev_dbg(&pmcmsptwi_adapter.dev,
435 "Result: IRQ timeout\n");
436 complete(&data->wait);
437 data->last_result = MSP_TWI_XFER_TIMEOUT;
438 }
439 } else
440 pmcmsptwi_poll_complete(data);
441
442 return data->last_result;
443}
444
445/*
446 * Helper routine, converts 'pmctwi_cmd' struct to register format
447 */
448static inline u32 pmcmsptwi_cmd_to_reg(const struct pmcmsptwi_cmd *cmd)
449{
450 return ((cmd->type & 0x3) << 8) |
451 (((cmd->write_len - 1) & 0x7) << 4) |
452 ((cmd->read_len - 1) & 0x7);
453}
454
455/*
456 * Do the transfer (high level)
457 */
458static enum pmcmsptwi_xfer_result pmcmsptwi_xfer_cmd(
459 struct pmcmsptwi_cmd *cmd,
460 struct pmcmsptwi_data *data)
461{
462 enum pmcmsptwi_xfer_result retval;
463
464 if ((cmd->type == MSP_TWI_CMD_WRITE && cmd->write_len == 0) ||
465 (cmd->type == MSP_TWI_CMD_READ && cmd->read_len == 0) ||
466 (cmd->type == MSP_TWI_CMD_WRITE_READ &&
467 (cmd->read_len == 0 || cmd->write_len == 0))) {
468 dev_err(&pmcmsptwi_adapter.dev,
469 "%s: Cannot transfer less than 1 byte\n",
470 __FUNCTION__);
471 return -EINVAL;
472 }
473
474 if (cmd->read_len > MSP_MAX_BYTES_PER_RW ||
475 cmd->write_len > MSP_MAX_BYTES_PER_RW) {
476 dev_err(&pmcmsptwi_adapter.dev,
477 "%s: Cannot transfer more than %d bytes\n",
478 __FUNCTION__, MSP_MAX_BYTES_PER_RW);
479 return -EINVAL;
480 }
481
482 mutex_lock(&data->lock);
483 dev_dbg(&pmcmsptwi_adapter.dev,
484 "Setting address to 0x%04x\n", cmd->addr);
485 pmcmsptwi_writel(cmd->addr, data->iobase + MSP_TWI_ADD_REG_OFFSET);
486
487 if (cmd->type == MSP_TWI_CMD_WRITE ||
488 cmd->type == MSP_TWI_CMD_WRITE_READ) {
489 __be64 tmp = cpu_to_be64p((u64 *)cmd->write_data);
490 tmp >>= (MSP_MAX_BYTES_PER_RW - cmd->write_len) * 8;
491 dev_dbg(&pmcmsptwi_adapter.dev, "Writing 0x%016llx\n", tmp);
492 pmcmsptwi_writel(tmp & 0x00000000ffffffffLL,
493 data->iobase + MSP_TWI_DAT_0_REG_OFFSET);
494 if (cmd->write_len > 4)
495 pmcmsptwi_writel(tmp >> 32,
496 data->iobase + MSP_TWI_DAT_1_REG_OFFSET);
497 }
498
499 retval = pmcmsptwi_do_xfer(pmcmsptwi_cmd_to_reg(cmd), data);
500 if (retval != MSP_TWI_XFER_OK)
501 goto xfer_err;
502
503 if (cmd->type == MSP_TWI_CMD_READ ||
504 cmd->type == MSP_TWI_CMD_WRITE_READ) {
505 int i;
506 u64 rmsk = ~(0xffffffffffffffffLL << (cmd->read_len * 8));
507 u64 tmp = (u64)pmcmsptwi_readl(data->iobase +
508 MSP_TWI_DAT_0_REG_OFFSET);
509 if (cmd->read_len > 4)
510 tmp |= (u64)pmcmsptwi_readl(data->iobase +
511 MSP_TWI_DAT_1_REG_OFFSET) << 32;
512 tmp &= rmsk;
513 dev_dbg(&pmcmsptwi_adapter.dev, "Read 0x%016llx\n", tmp);
514
515 for (i = 0; i < cmd->read_len; i++)
516 cmd->read_data[i] = tmp >> i;
517 }
518
519xfer_err:
520 mutex_unlock(&data->lock);
521
522 return retval;
523}
524
525/* -- Algorithm functions -- */
526
527/*
528 * Sends an i2c command out on the adapter
529 */
530static int pmcmsptwi_master_xfer(struct i2c_adapter *adap,
531 struct i2c_msg *msg, int num)
532{
533 struct pmcmsptwi_data *data = i2c_get_adapdata(adap);
534 struct pmcmsptwi_cmd cmd;
535 struct pmcmsptwi_cfg oldcfg, newcfg;
536 int ret;
537
538 if (num > 2) {
539 dev_dbg(&adap->dev, "%d messages unsupported\n", num);
540 return -EINVAL;
541 } else if (num == 2) {
542 /* Check for a dual write-then-read command */
543 struct i2c_msg *nextmsg = msg + 1;
544 if (!(msg->flags & I2C_M_RD) &&
545 (nextmsg->flags & I2C_M_RD) &&
546 msg->addr == nextmsg->addr) {
547 cmd.type = MSP_TWI_CMD_WRITE_READ;
548 cmd.write_len = msg->len;
549 cmd.write_data = msg->buf;
550 cmd.read_len = nextmsg->len;
551 cmd.read_data = nextmsg->buf;
552 } else {
553 dev_dbg(&adap->dev,
554 "Non write-read dual messages unsupported\n");
555 return -EINVAL;
556 }
557 } else if (msg->flags & I2C_M_RD) {
558 cmd.type = MSP_TWI_CMD_READ;
559 cmd.read_len = msg->len;
560 cmd.read_data = msg->buf;
561 cmd.write_len = 0;
562 cmd.write_data = NULL;
563 } else {
564 cmd.type = MSP_TWI_CMD_WRITE;
565 cmd.read_len = 0;
566 cmd.read_data = NULL;
567 cmd.write_len = msg->len;
568 cmd.write_data = msg->buf;
569 }
570
571 if (msg->len == 0) {
572 dev_err(&adap->dev, "Zero-byte messages unsupported\n");
573 return -EINVAL;
574 }
575
576 cmd.addr = msg->addr;
577
578 if (msg->flags & I2C_M_TEN) {
579 pmcmsptwi_get_twi_config(&newcfg, data);
580 memcpy(&oldcfg, &newcfg, sizeof(oldcfg));
581
582 /* Set the special 10-bit address flag */
583 newcfg.add10 = 1;
584
585 pmcmsptwi_set_twi_config(&newcfg, data);
586 }
587
588 /* Execute the command */
589 ret = pmcmsptwi_xfer_cmd(&cmd, data);
590
591 if (msg->flags & I2C_M_TEN)
592 pmcmsptwi_set_twi_config(&oldcfg, data);
593
594 dev_dbg(&adap->dev, "I2C %s of %d bytes ",
595 (msg->flags & I2C_M_RD) ? "read" : "write", msg->len);
596 if (ret != MSP_TWI_XFER_OK) {
597 /*
598 * TODO: We could potentially loop and retry in the case
599 * of MSP_TWI_XFER_TIMEOUT.
600 */
601 dev_dbg(&adap->dev, "failed\n");
602 return -1;
603 }
604
605 dev_dbg(&adap->dev, "succeeded\n");
606 return 0;
607}
608
609static u32 pmcmsptwi_i2c_func(struct i2c_adapter *adapter)
610{
611 return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR |
612 I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA |
613 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_PROC_CALL;
614}
615
616/* -- Initialization -- */
617
618static struct i2c_algorithm pmcmsptwi_algo = {
619 .master_xfer = pmcmsptwi_master_xfer,
620 .functionality = pmcmsptwi_i2c_func,
621};
622
623static struct i2c_adapter pmcmsptwi_adapter = {
624 .owner = THIS_MODULE,
625 .class = I2C_CLASS_HWMON,
626 .algo = &pmcmsptwi_algo,
627 .name = DRV_NAME,
628};
629
630static struct platform_driver pmcmsptwi_driver = {
631 .probe = pmcmsptwi_probe,
632 .remove = __devexit_p(pmcmsptwi_remove),
633 .driver {
634 .name = DRV_NAME,
635 .owner = THIS_MODULE,
636 },
637};
638
639static int __init pmcmsptwi_init(void)
640{
641 return platform_driver_register(&pmcmsptwi_driver);
642}
643
644static void __exit pmcmsptwi_exit(void)
645{
646 platform_driver_unregister(&pmcmsptwi_driver);
647}
648
649MODULE_DESCRIPTION("PMC MSP TWI/SMBus/I2C driver");
650MODULE_LICENSE("GPL");
651
652module_init(pmcmsptwi_init);
653module_exit(pmcmsptwi_exit);
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 1425d2245c82..0ab4f2627c26 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -121,8 +121,7 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap,
121 if (rc) 121 if (rc)
122 goto bail; 122 goto bail;
123 rc = pmac_i2c_xfer(bus, addrdir, 1, command, 123 rc = pmac_i2c_xfer(bus, addrdir, 1, command,
124 read ? data->block : &data->block[1], 124 &data->block[1], data->block[0]);
125 data->block[0]);
126 break; 125 break;
127 126
128 default: 127 default:
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 28e7b91a4553..9d6b790d4321 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -921,7 +921,14 @@ static int i2c_pxa_probe(struct platform_device *dev)
921 i2c->adap.class = plat->class; 921 i2c->adap.class = plat->class;
922 } 922 }
923 923
924 ret = i2c_add_adapter(&i2c->adap); 924 /*
925 * If "dev->id" is negative we consider it as zero.
926 * The reason to do so is to avoid sysfs names that only make
927 * sense when there are multiple adapters.
928 */
929 i2c->adap.nr = dev->id >= 0 ? dev->id : 0;
930
931 ret = i2c_add_numbered_adapter(&i2c->adap);
925 if (ret < 0) { 932 if (ret < 0) {
926 printk(KERN_INFO "I2C: Failed to add bus\n"); 933 printk(KERN_INFO "I2C: Failed to add bus\n");
927 goto eadapt; 934 goto eadapt;
diff --git a/drivers/i2c/busses/i2c-rpx.c b/drivers/i2c/busses/i2c-rpx.c
deleted file mode 100644
index 8764df06f51d..000000000000
--- a/drivers/i2c/busses/i2c-rpx.c
+++ /dev/null
@@ -1,101 +0,0 @@
1/*
2 * Embedded Planet RPX Lite MPC8xx CPM I2C interface.
3 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
4 *
5 * moved into proper i2c interface;
6 * Brad Parker (brad@heeltoe.com)
7 *
8 * RPX lite specific parts of the i2c interface
9 * Update: There actually isn't anything RPXLite-specific about this module.
10 * This should work for most any 8xx board. The console messages have been
11 * changed to eliminate RPXLite references.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/stddef.h>
18#include <linux/i2c.h>
19#include <linux/i2c-algo-8xx.h>
20#include <asm/mpc8xx.h>
21#include <asm/commproc.h>
22
23
24static void
25rpx_iic_init(struct i2c_algo_8xx_data *data)
26{
27 volatile cpm8xx_t *cp;
28 volatile immap_t *immap;
29
30 cp = cpmp; /* Get pointer to Communication Processor */
31 immap = (immap_t *)IMAP_ADDR; /* and to internal registers */
32
33 data->iip = (iic_t *)&cp->cp_dparam[PROFF_IIC];
34
35 /* Check for and use a microcode relocation patch.
36 */
37 if ((data->reloc = data->iip->iic_rpbase))
38 data->iip = (iic_t *)&cp->cp_dpmem[data->iip->iic_rpbase];
39
40 data->i2c = (i2c8xx_t *)&(immap->im_i2c);
41 data->cp = cp;
42
43 /* Initialize Port B IIC pins.
44 */
45 cp->cp_pbpar |= 0x00000030;
46 cp->cp_pbdir |= 0x00000030;
47 cp->cp_pbodr |= 0x00000030;
48
49 /* Allocate space for two transmit and two receive buffer
50 * descriptors in the DP ram.
51 */
52 data->dp_addr = cpm_dpalloc(sizeof(cbd_t) * 4, 8);
53
54 /* ptr to i2c area */
55 data->i2c = (i2c8xx_t *)&(((immap_t *)IMAP_ADDR)->im_i2c);
56}
57
58static int rpx_install_isr(int irq, void (*func)(void *), void *data)
59{
60 /* install interrupt handler */
61 cpm_install_handler(irq, func, data);
62
63 return 0;
64}
65
66static struct i2c_algo_8xx_data rpx_data = {
67 .setisr = rpx_install_isr
68};
69
70static struct i2c_adapter rpx_ops = {
71 .owner = THIS_MODULE,
72 .name = "m8xx",
73 .id = I2C_HW_MPC8XX_EPON,
74 .algo_data = &rpx_data,
75};
76
77int __init i2c_rpx_init(void)
78{
79 printk(KERN_INFO "i2c-rpx: i2c MPC8xx driver\n");
80
81 /* reset hardware to sane state */
82 rpx_iic_init(&rpx_data);
83
84 if (i2c_8xx_add_bus(&rpx_ops) < 0) {
85 printk(KERN_ERR "i2c-rpx: Unable to register with I2C\n");
86 return -ENODEV;
87 }
88
89 return 0;
90}
91
92void __exit i2c_rpx_exit(void)
93{
94 i2c_8xx_del_bus(&rpx_ops);
95}
96
97MODULE_AUTHOR("Dan Malek <dmalek@jlc.net>");
98MODULE_DESCRIPTION("I2C-Bus adapter routines for MPC8xx boards");
99
100module_init(i2c_rpx_init);
101module_exit(i2c_rpx_exit);
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index b7fb65c30112..8adf4abaa035 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -25,8 +25,6 @@
25/* This interfaces to the I2C bus of the Savage4 to gain access to 25/* This interfaces to the I2C bus of the Savage4 to gain access to
26 the BT869 and possibly other I2C devices. The DDC bus is not 26 the BT869 and possibly other I2C devices. The DDC bus is not
27 yet supported because its register is not memory-mapped. 27 yet supported because its register is not memory-mapped.
28 However we leave the DDC code here, commented out, to make
29 it easier to add later.
30*/ 28*/
31 29
32#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -37,36 +35,19 @@
37#include <linux/i2c-algo-bit.h> 35#include <linux/i2c-algo-bit.h>
38#include <asm/io.h> 36#include <asm/io.h>
39 37
40/* 3DFX defines */ 38/* device IDs */
41#define PCI_CHIP_SAVAGE3D 0x8A20
42#define PCI_CHIP_SAVAGE3D_MV 0x8A21
43#define PCI_CHIP_SAVAGE4 0x8A22 39#define PCI_CHIP_SAVAGE4 0x8A22
44#define PCI_CHIP_SAVAGE2000 0x9102 40#define PCI_CHIP_SAVAGE2000 0x9102
45#define PCI_CHIP_PROSAVAGE_PM 0x8A25
46#define PCI_CHIP_PROSAVAGE_KM 0x8A26
47#define PCI_CHIP_SAVAGE_MX_MV 0x8c10
48#define PCI_CHIP_SAVAGE_MX 0x8c11
49#define PCI_CHIP_SAVAGE_IX_MV 0x8c12
50#define PCI_CHIP_SAVAGE_IX 0x8c13
51 41
52#define REG 0xff20 /* Serial Port 1 Register */ 42#define REG 0xff20 /* Serial Port 1 Register */
53 43
54/* bit locations in the register */ 44/* bit locations in the register */
55#define DDC_ENAB 0x00040000
56#define DDC_SCL_OUT 0x00080000
57#define DDC_SDA_OUT 0x00100000
58#define DDC_SCL_IN 0x00200000
59#define DDC_SDA_IN 0x00400000
60#define I2C_ENAB 0x00000020 45#define I2C_ENAB 0x00000020
61#define I2C_SCL_OUT 0x00000001 46#define I2C_SCL_OUT 0x00000001
62#define I2C_SDA_OUT 0x00000002 47#define I2C_SDA_OUT 0x00000002
63#define I2C_SCL_IN 0x00000008 48#define I2C_SCL_IN 0x00000008
64#define I2C_SDA_IN 0x00000010 49#define I2C_SDA_IN 0x00000010
65 50
66/* initialization states */
67#define INIT2 0x20
68#define INIT3 0x04
69
70/* delays */ 51/* delays */
71#define CYCLE_DELAY 10 52#define CYCLE_DELAY 10
72#define TIMEOUT (HZ / 2) 53#define TIMEOUT (HZ / 2)
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index a6feed449dbe..283769cecee2 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -129,6 +129,7 @@ MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller"
129 129
130static struct pci_driver sis5595_driver; 130static struct pci_driver sis5595_driver;
131static unsigned short sis5595_base; 131static unsigned short sis5595_base;
132static struct pci_dev *sis5595_pdev;
132 133
133static u8 sis5595_read(u8 reg) 134static u8 sis5595_read(u8 reg)
134{ 135{
@@ -379,6 +380,8 @@ MODULE_DEVICE_TABLE (pci, sis5595_ids);
379 380
380static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_id *id) 381static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_id *id)
381{ 382{
383 int err;
384
382 if (sis5595_setup(dev)) { 385 if (sis5595_setup(dev)) {
383 dev_err(&dev->dev, "SIS5595 not detected, module not inserted.\n"); 386 dev_err(&dev->dev, "SIS5595 not detected, module not inserted.\n");
384 return -ENODEV; 387 return -ENODEV;
@@ -389,20 +392,24 @@ static int __devinit sis5595_probe(struct pci_dev *dev, const struct pci_device_
389 392
390 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x", 393 sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x",
391 sis5595_base + SMB_INDEX); 394 sis5595_base + SMB_INDEX);
392 return i2c_add_adapter(&sis5595_adapter); 395 err = i2c_add_adapter(&sis5595_adapter);
393} 396 if (err) {
397 release_region(sis5595_base + SMB_INDEX, 2);
398 return err;
399 }
394 400
395static void __devexit sis5595_remove(struct pci_dev *dev) 401 /* Always return failure here. This is to allow other drivers to bind
396{ 402 * to this pci device. We don't really want to have control over the
397 i2c_del_adapter(&sis5595_adapter); 403 * pci device, we only wanted to read as few register values from it.
398 release_region(sis5595_base + SMB_INDEX, 2); 404 */
405 sis5595_pdev = pci_dev_get(dev);
406 return -ENODEV;
399} 407}
400 408
401static struct pci_driver sis5595_driver = { 409static struct pci_driver sis5595_driver = {
402 .name = "sis5595_smbus", 410 .name = "sis5595_smbus",
403 .id_table = sis5595_ids, 411 .id_table = sis5595_ids,
404 .probe = sis5595_probe, 412 .probe = sis5595_probe,
405 .remove = __devexit_p(sis5595_remove),
406}; 413};
407 414
408static int __init i2c_sis5595_init(void) 415static int __init i2c_sis5595_init(void)
@@ -413,6 +420,12 @@ static int __init i2c_sis5595_init(void)
413static void __exit i2c_sis5595_exit(void) 420static void __exit i2c_sis5595_exit(void)
414{ 421{
415 pci_unregister_driver(&sis5595_driver); 422 pci_unregister_driver(&sis5595_driver);
423 if (sis5595_pdev) {
424 i2c_del_adapter(&sis5595_adapter);
425 release_region(sis5595_base + SMB_INDEX, 2);
426 pci_dev_put(sis5595_pdev);
427 sis5595_pdev = NULL;
428 }
416} 429}
417 430
418MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 431MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
new file mode 100644
index 000000000000..1b0cfd5472fd
--- /dev/null
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -0,0 +1,330 @@
1/*
2 * Driver for the TAOS evaluation modules
3 * These devices include an I2C master which can be controlled over the
4 * serial port.
5 *
6 * Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
7 *
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
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/delay.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26#include <linux/input.h>
27#include <linux/serio.h>
28#include <linux/init.h>
29#include <linux/i2c.h>
30
31#define TAOS_BUFFER_SIZE 63
32
33#define TAOS_STATE_INIT 0
34#define TAOS_STATE_IDLE 1
35#define TAOS_STATE_SEND 2
36#define TAOS_STATE_RECV 3
37
38#define TAOS_CMD_RESET 0x12
39
40static DECLARE_WAIT_QUEUE_HEAD(wq);
41
42struct taos_data {
43 struct i2c_adapter adapter;
44 struct i2c_client *client;
45 int state;
46 u8 addr; /* last used address */
47 unsigned char buffer[TAOS_BUFFER_SIZE];
48 unsigned int pos; /* position inside the buffer */
49};
50
51/* TAOS TSL2550 EVM */
52static struct i2c_board_info tsl2550_info = {
53 I2C_BOARD_INFO("tsl2550", 0x39),
54 .type = "tsl2550",
55};
56
57/* Instantiate i2c devices based on the adapter name */
58static struct i2c_client *taos_instantiate_device(struct i2c_adapter *adapter)
59{
60 if (!strncmp(adapter->name, "TAOS TSL2550 EVM", 16)) {
61 dev_info(&adapter->dev, "Instantiating device %s at 0x%02x\n",
62 tsl2550_info.driver_name, tsl2550_info.addr);
63 return i2c_new_device(adapter, &tsl2550_info);
64 }
65
66 return NULL;
67}
68
69static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
70 unsigned short flags, char read_write, u8 command,
71 int size, union i2c_smbus_data *data)
72{
73 struct serio *serio = adapter->algo_data;
74 struct taos_data *taos = serio_get_drvdata(serio);
75 char *p;
76
77 /* Encode our transaction. "@" is for the device address, "$" for the
78 SMBus command and "#" for the data. */
79 p = taos->buffer;
80
81 /* The device remembers the last used address, no need to send it
82 again if it's the same */
83 if (addr != taos->addr)
84 p += sprintf(p, "@%02X", addr);
85
86 switch (size) {
87 case I2C_SMBUS_BYTE:
88 if (read_write == I2C_SMBUS_WRITE)
89 sprintf(p, "$#%02X", command);
90 else
91 sprintf(p, "$");
92 break;
93 case I2C_SMBUS_BYTE_DATA:
94 if (read_write == I2C_SMBUS_WRITE)
95 sprintf(p, "$%02X#%02X", command, data->byte);
96 else
97 sprintf(p, "$%02X", command);
98 break;
99 default:
100 dev_dbg(&adapter->dev, "Unsupported transaction size %d\n",
101 size);
102 return -EINVAL;
103 }
104
105 /* Send the transaction to the TAOS EVM */
106 dev_dbg(&adapter->dev, "Command buffer: %s\n", taos->buffer);
107 taos->pos = 0;
108 taos->state = TAOS_STATE_SEND;
109 serio_write(serio, taos->buffer[0]);
110 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
111 msecs_to_jiffies(250));
112 if (taos->state != TAOS_STATE_IDLE) {
113 dev_err(&adapter->dev, "Transaction failed "
114 "(state=%d, pos=%d)\n", taos->state, taos->pos);
115 taos->addr = 0;
116 return -EIO;
117 }
118 taos->addr = addr;
119
120 /* Start the transaction and read the answer */
121 taos->pos = 0;
122 taos->state = TAOS_STATE_RECV;
123 serio_write(serio, read_write == I2C_SMBUS_WRITE ? '>' : '<');
124 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
125 msecs_to_jiffies(150));
126 if (taos->state != TAOS_STATE_IDLE
127 || taos->pos != 6) {
128 dev_err(&adapter->dev, "Transaction timeout (pos=%d)\n",
129 taos->pos);
130 return -EIO;
131 }
132 dev_dbg(&adapter->dev, "Answer buffer: %s\n", taos->buffer);
133
134 /* Interpret the returned string */
135 p = taos->buffer + 2;
136 p[3] = '\0';
137 if (!strcmp(p, "NAK"))
138 return -ENODEV;
139
140 if (read_write == I2C_SMBUS_WRITE) {
141 if (!strcmp(p, "ACK"))
142 return 0;
143 } else {
144 if (p[0] == 'x') {
145 data->byte = simple_strtol(p + 1, NULL, 16);
146 return 0;
147 }
148 }
149
150 return -EIO;
151}
152
153static u32 taos_smbus_func(struct i2c_adapter *adapter)
154{
155 return I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA;
156}
157
158static const struct i2c_algorithm taos_algorithm = {
159 .smbus_xfer = taos_smbus_xfer,
160 .functionality = taos_smbus_func,
161};
162
163static irqreturn_t taos_interrupt(struct serio *serio, unsigned char data,
164 unsigned int flags)
165{
166 struct taos_data *taos = serio_get_drvdata(serio);
167
168 switch (taos->state) {
169 case TAOS_STATE_INIT:
170 taos->buffer[taos->pos++] = data;
171 if (data == ':'
172 || taos->pos == TAOS_BUFFER_SIZE - 1) {
173 taos->buffer[taos->pos] = '\0';
174 taos->state = TAOS_STATE_IDLE;
175 wake_up_interruptible(&wq);
176 }
177 break;
178 case TAOS_STATE_SEND:
179 if (taos->buffer[++taos->pos])
180 serio_write(serio, taos->buffer[taos->pos]);
181 else {
182 taos->state = TAOS_STATE_IDLE;
183 wake_up_interruptible(&wq);
184 }
185 break;
186 case TAOS_STATE_RECV:
187 taos->buffer[taos->pos++] = data;
188 if (data == ']') {
189 taos->buffer[taos->pos] = '\0';
190 taos->state = TAOS_STATE_IDLE;
191 wake_up_interruptible(&wq);
192 }
193 break;
194 }
195
196 return IRQ_HANDLED;
197}
198
199/* Extract the adapter name from the buffer received after reset.
200 The buffer is modified and a pointer inside the buffer is returned. */
201static char *taos_adapter_name(char *buffer)
202{
203 char *start, *end;
204
205 start = strstr(buffer, "TAOS ");
206 if (!start)
207 return NULL;
208
209 end = strchr(start, '\r');
210 if (!end)
211 return NULL;
212 *end = '\0';
213
214 return start;
215}
216
217static int taos_connect(struct serio *serio, struct serio_driver *drv)
218{
219 struct taos_data *taos;
220 struct i2c_adapter *adapter;
221 char *name;
222 int err;
223
224 taos = kzalloc(sizeof(struct taos_data), GFP_KERNEL);
225 if (!taos) {
226 err = -ENOMEM;
227 goto exit;
228 }
229 taos->state = TAOS_STATE_INIT;
230 serio_set_drvdata(serio, taos);
231
232 err = serio_open(serio, drv);
233 if (err)
234 goto exit_kfree;
235
236 adapter = &taos->adapter;
237 adapter->owner = THIS_MODULE;
238 adapter->algo = &taos_algorithm;
239 adapter->algo_data = serio;
240 adapter->dev.parent = &serio->dev;
241
242 /* Reset the TAOS evaluation module to identify it */
243 serio_write(serio, TAOS_CMD_RESET);
244 wait_event_interruptible_timeout(wq, taos->state == TAOS_STATE_IDLE,
245 msecs_to_jiffies(2000));
246
247 if (taos->state != TAOS_STATE_IDLE) {
248 err = -ENODEV;
249 dev_dbg(&serio->dev, "TAOS EVM reset failed (state=%d, "
250 "pos=%d)\n", taos->state, taos->pos);
251 goto exit_close;
252 }
253
254 name = taos_adapter_name(taos->buffer);
255 if (!name) {
256 err = -ENODEV;
257 dev_err(&serio->dev, "TAOS EVM identification failed\n");
258 goto exit_close;
259 }
260 strlcpy(adapter->name, name, sizeof(adapter->name));
261
262 err = i2c_add_adapter(adapter);
263 if (err)
264 goto exit_close;
265 dev_dbg(&serio->dev, "Connected to TAOS EVM\n");
266
267 taos->client = taos_instantiate_device(adapter);
268 return 0;
269
270 exit_close:
271 serio_close(serio);
272 exit_kfree:
273 serio_set_drvdata(serio, NULL);
274 kfree(taos);
275 exit:
276 return err;
277}
278
279static void taos_disconnect(struct serio *serio)
280{
281 struct taos_data *taos = serio_get_drvdata(serio);
282
283 if (taos->client)
284 i2c_unregister_device(taos->client);
285 i2c_del_adapter(&taos->adapter);
286 serio_close(serio);
287 serio_set_drvdata(serio, NULL);
288 kfree(taos);
289
290 dev_dbg(&serio->dev, "Disconnected from TAOS EVM\n");
291}
292
293static struct serio_device_id taos_serio_ids[] = {
294 {
295 .type = SERIO_RS232,
296 .proto = SERIO_TAOSEVM,
297 .id = SERIO_ANY,
298 .extra = SERIO_ANY,
299 },
300 { 0 }
301};
302MODULE_DEVICE_TABLE(serio, taos_serio_ids);
303
304static struct serio_driver taos_drv = {
305 .driver = {
306 .name = "taos-evm",
307 },
308 .description = "TAOS evaluation module driver",
309 .id_table = taos_serio_ids,
310 .connect = taos_connect,
311 .disconnect = taos_disconnect,
312 .interrupt = taos_interrupt,
313};
314
315static int __init taos_init(void)
316{
317 return serio_register_driver(&taos_drv);
318}
319
320static void __exit taos_exit(void)
321{
322 serio_unregister_driver(&taos_drv);
323}
324
325MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
326MODULE_DESCRIPTION("TAOS evaluation module driver");
327MODULE_LICENSE("GPL");
328
329module_init(taos_init);
330module_exit(taos_exit);
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 1d76b9e5207a..edc275002f80 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -235,7 +235,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
235 if (!(vt596_features & FEATURE_I2CBLOCK)) 235 if (!(vt596_features & FEATURE_I2CBLOCK))
236 goto exit_unsupported; 236 goto exit_unsupported;
237 if (read_write == I2C_SMBUS_READ) 237 if (read_write == I2C_SMBUS_READ)
238 outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0); 238 outb_p(data->block[0], SMBHSTDAT0);
239 /* Fall through */ 239 /* Fall through */
240 case I2C_SMBUS_BLOCK_DATA: 240 case I2C_SMBUS_BLOCK_DATA:
241 outb_p(command, SMBHSTCMD); 241 outb_p(command, SMBHSTCMD);
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0d6bd4f7b7fa..e6c4a2b762ec 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -310,8 +310,6 @@ static s32 scx200_acb_smbus_xfer(struct i2c_adapter *adapter,
310 break; 310 break;
311 311
312 case I2C_SMBUS_I2C_BLOCK_DATA: 312 case I2C_SMBUS_I2C_BLOCK_DATA:
313 if (rw == I2C_SMBUS_READ)
314 data->block[0] = I2C_SMBUS_BLOCK_MAX; /* For now */
315 len = data->block[0]; 313 len = data->block[0];
316 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) 314 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
317 return -EINVAL; 315 return -EINVAL;
@@ -388,7 +386,7 @@ static const struct i2c_algorithm scx200_acb_algorithm = {
388}; 386};
389 387
390static struct scx200_acb_iface *scx200_acb_list; 388static struct scx200_acb_iface *scx200_acb_list;
391static DECLARE_MUTEX(scx200_acb_list_mutex); 389static DEFINE_MUTEX(scx200_acb_list_mutex);
392 390
393static __init int scx200_acb_probe(struct scx200_acb_iface *iface) 391static __init int scx200_acb_probe(struct scx200_acb_iface *iface)
394{ 392{
@@ -472,10 +470,10 @@ static int __init scx200_acb_create(struct scx200_acb_iface *iface)
472 return -ENODEV; 470 return -ENODEV;
473 } 471 }
474 472
475 down(&scx200_acb_list_mutex); 473 mutex_lock(&scx200_acb_list_mutex);
476 iface->next = scx200_acb_list; 474 iface->next = scx200_acb_list;
477 scx200_acb_list = iface; 475 scx200_acb_list = iface;
478 up(&scx200_acb_list_mutex); 476 mutex_unlock(&scx200_acb_list_mutex);
479 477
480 return 0; 478 return 0;
481} 479}
@@ -633,10 +631,10 @@ static void __exit scx200_acb_cleanup(void)
633{ 631{
634 struct scx200_acb_iface *iface; 632 struct scx200_acb_iface *iface;
635 633
636 down(&scx200_acb_list_mutex); 634 mutex_lock(&scx200_acb_list_mutex);
637 while ((iface = scx200_acb_list) != NULL) { 635 while ((iface = scx200_acb_list) != NULL) {
638 scx200_acb_list = iface->next; 636 scx200_acb_list = iface->next;
639 up(&scx200_acb_list_mutex); 637 mutex_unlock(&scx200_acb_list_mutex);
640 638
641 i2c_del_adapter(&iface->adapter); 639 i2c_del_adapter(&iface->adapter);
642 640
@@ -648,9 +646,9 @@ static void __exit scx200_acb_cleanup(void)
648 release_region(iface->base, 8); 646 release_region(iface->base, 8);
649 647
650 kfree(iface); 648 kfree(iface);
651 down(&scx200_acb_list_mutex); 649 mutex_lock(&scx200_acb_list_mutex);
652 } 650 }
653 up(&scx200_acb_list_mutex); 651 mutex_unlock(&scx200_acb_list_mutex);
654} 652}
655 653
656module_init(scx200_acb_init); 654module_init(scx200_acb_init);
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index ea085a006ead..3944e889cb21 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -5,7 +5,7 @@
5menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
6 6
7config SENSORS_DS1337 7config SENSORS_DS1337
8 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" 8 tristate "Dallas DS1337 and DS1339 Real Time Clock (DEPRECATED)"
9 depends on EXPERIMENTAL 9 depends on EXPERIMENTAL
10 help 10 help
11 If you say yes here you get support for Dallas Semiconductor 11 If you say yes here you get support for Dallas Semiconductor
@@ -14,8 +14,11 @@ config SENSORS_DS1337
14 This driver can also be built as a module. If so, the module 14 This driver can also be built as a module. If so, the module
15 will be called ds1337. 15 will be called ds1337.
16 16
17 This driver is deprecated and will be dropped soon. Use
18 rtc-ds1307 instead.
19
17config SENSORS_DS1374 20config SENSORS_DS1374
18 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" 21 tristate "Dallas DS1374 Real Time Clock (DEPRECATED)"
19 depends on EXPERIMENTAL 22 depends on EXPERIMENTAL
20 help 23 help
21 If you say yes here you get support for Dallas Semiconductor 24 If you say yes here you get support for Dallas Semiconductor
@@ -24,6 +27,19 @@ config SENSORS_DS1374
24 This driver can also be built as a module. If so, the module 27 This driver can also be built as a module. If so, the module
25 will be called ds1374. 28 will be called ds1374.
26 29
30 This driver is deprecated and will be dropped soon. Use
31 rtc-ds1374 instead.
32
33config DS1682
34 tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm"
35 depends on EXPERIMENTAL
36 help
37 If you say yes here you get support for Dallas Semiconductor
38 DS1682 Total Elapsed Time Recorder.
39
40 This driver can also be built as a module. If so, the module
41 will be called ds1682.
42
27config SENSORS_EEPROM 43config SENSORS_EEPROM
28 tristate "EEPROM reader" 44 tristate "EEPROM reader"
29 depends on EXPERIMENTAL 45 depends on EXPERIMENTAL
@@ -101,7 +117,7 @@ config TPS65010
101 will be called tps65010. 117 will be called tps65010.
102 118
103config SENSORS_M41T00 119config SENSORS_M41T00
104 tristate "ST M41T00 RTC chip" 120 tristate "ST M41T00 RTC chip (DEPRECATED)"
105 depends on PPC32 121 depends on PPC32
106 help 122 help
107 If you say yes here you get support for the ST M41T00 RTC chip. 123 If you say yes here you get support for the ST M41T00 RTC chip.
@@ -109,6 +125,9 @@ config SENSORS_M41T00
109 This driver can also be built as a module. If so, the module 125 This driver can also be built as a module. If so, the module
110 will be called m41t00. 126 will be called m41t00.
111 127
128 This driver is deprecated and will be dropped soon. Use
129 rtc-ds1307 or rtc-m41t80 instead.
130
112config SENSORS_MAX6875 131config SENSORS_MAX6875
113 tristate "Maxim MAX6875 Power supply supervisor" 132 tristate "Maxim MAX6875 Power supply supervisor"
114 depends on EXPERIMENTAL 133 depends on EXPERIMENTAL
@@ -124,4 +143,14 @@ config SENSORS_MAX6875
124 This driver can also be built as a module. If so, the module 143 This driver can also be built as a module. If so, the module
125 will be called max6875. 144 will be called max6875.
126 145
146config SENSORS_TSL2550
147 tristate "Taos TSL2550 ambient light sensor"
148 depends on EXPERIMENTAL
149 help
150 If you say yes here you get support for the Taos TSL2550
151 ambient light sensor.
152
153 This driver can also be built as a module. If so, the module
154 will be called tsl2550.
155
127endmenu 156endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 779868ef2e26..d8cbeb3f4b63 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o 5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o
6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o 6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o
7obj-$(CONFIG_DS1682) += ds1682.o
7obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 8obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
8obj-$(CONFIG_SENSORS_MAX6875) += max6875.o 9obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
9obj-$(CONFIG_SENSORS_M41T00) += m41t00.o 10obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
@@ -12,6 +13,7 @@ obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 13obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
13obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
14obj-$(CONFIG_TPS65010) += tps65010.o 15obj-$(CONFIG_TPS65010) += tps65010.o
16obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
15 17
16ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 18ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
17EXTRA_CFLAGS += -DDEBUG 19EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c
new file mode 100644
index 000000000000..25fd4676fb17
--- /dev/null
+++ b/drivers/i2c/chips/ds1682.c
@@ -0,0 +1,259 @@
1/*
2 * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
3 *
4 * Written by: Grant Likely <grant.likely@secretlab.ca>
5 *
6 * Copyright (C) 2007 Secret Lab Technologies Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13/*
14 * The DS1682 elapsed timer recorder is a simple device that implements
15 * one elapsed time counter, one event counter, an alarm signal and 10
16 * bytes of general purpose EEPROM.
17 *
18 * This driver provides access to the DS1682 counters and user data via
19 * the sysfs. The following attributes are added to the device node:
20 * elapsed_time (u32): Total elapsed event time in ms resolution
21 * alarm_time (u32): When elapsed time exceeds the value in alarm_time,
22 * then the alarm pin is asserted.
23 * event_count (u16): number of times the event pin has gone low.
24 * eeprom (u8[10]): general purpose EEPROM
25 *
26 * Counter registers and user data are both read/write unless the device
27 * has been write protected. This driver does not support turning off write
28 * protection. Once write protection is turned on, it is impossible to
29 * turn it off again, so I have left the feature out of this driver to avoid
30 * accidental enabling, but it is trivial to add write protect support.
31 *
32 */
33
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/i2c.h>
38#include <linux/string.h>
39#include <linux/list.h>
40#include <linux/sysfs.h>
41#include <linux/ctype.h>
42#include <linux/hwmon-sysfs.h>
43
44/* Device registers */
45#define DS1682_REG_CONFIG 0x00
46#define DS1682_REG_ALARM 0x01
47#define DS1682_REG_ELAPSED 0x05
48#define DS1682_REG_EVT_CNTR 0x09
49#define DS1682_REG_EEPROM 0x0b
50#define DS1682_REG_RESET 0x1d
51#define DS1682_REG_WRITE_DISABLE 0x1e
52#define DS1682_REG_WRITE_MEM_DISABLE 0x1f
53
54#define DS1682_EEPROM_SIZE 10
55
56/*
57 * Generic counter attributes
58 */
59static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
60 char *buf)
61{
62 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
63 struct i2c_client *client = to_i2c_client(dev);
64 __le32 val = 0;
65 int rc;
66
67 dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
68
69 /* Read the register */
70 rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
71 (u8 *) & val);
72 if (rc < 0)
73 return -EIO;
74
75 /* Special case: the 32 bit regs are time values with 1/4s
76 * resolution, scale them up to milliseconds */
77 if (sattr->nr == 4)
78 return sprintf(buf, "%llu\n", ((u64) le32_to_cpu(val)) * 250);
79
80 /* Format the output string and return # of bytes */
81 return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
82}
83
84static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
85 const char *buf, size_t count)
86{
87 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
88 struct i2c_client *client = to_i2c_client(dev);
89 char *endp;
90 u64 val;
91 __le32 val_le;
92 int rc;
93
94 dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
95
96 /* Decode input */
97 val = simple_strtoull(buf, &endp, 0);
98 if (buf == endp) {
99 dev_dbg(dev, "input string not a number\n");
100 return -EINVAL;
101 }
102
103 /* Special case: the 32 bit regs are time values with 1/4s
104 * resolution, scale input down to quarter-seconds */
105 if (sattr->nr == 4)
106 do_div(val, 250);
107
108 /* write out the value */
109 val_le = cpu_to_le32(val);
110 rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
111 (u8 *) & val_le);
112 if (rc < 0) {
113 dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
114 sattr->index, sattr->nr);
115 return -EIO;
116 }
117
118 return count;
119}
120
121/*
122 * Simple register attributes
123 */
124static SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show,
125 ds1682_store, 4, DS1682_REG_ELAPSED);
126static SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show,
127 ds1682_store, 4, DS1682_REG_ALARM);
128static SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show,
129 ds1682_store, 2, DS1682_REG_EVT_CNTR);
130
131static const struct attribute_group ds1682_group = {
132 .attrs = (struct attribute *[]) {
133 &sensor_dev_attr_elapsed_time.dev_attr.attr,
134 &sensor_dev_attr_alarm_time.dev_attr.attr,
135 &sensor_dev_attr_event_count.dev_attr.attr,
136 NULL,
137 },
138};
139
140/*
141 * User data attribute
142 */
143static ssize_t ds1682_eeprom_read(struct kobject *kobj, char *buf, loff_t off,
144 size_t count)
145{
146 struct i2c_client *client = kobj_to_i2c_client(kobj);
147 int rc;
148
149 dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
150 buf, off, count);
151
152 if (off >= DS1682_EEPROM_SIZE)
153 return 0;
154
155 if (off + count > DS1682_EEPROM_SIZE)
156 count = DS1682_EEPROM_SIZE - off;
157
158 rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
159 count, buf);
160 if (rc < 0)
161 return -EIO;
162
163 return count;
164}
165
166static ssize_t ds1682_eeprom_write(struct kobject *kobj, char *buf, loff_t off,
167 size_t count)
168{
169 struct i2c_client *client = kobj_to_i2c_client(kobj);
170
171 dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
172 buf, off, count);
173
174 if (off >= DS1682_EEPROM_SIZE)
175 return -ENOSPC;
176
177 if (off + count > DS1682_EEPROM_SIZE)
178 count = DS1682_EEPROM_SIZE - off;
179
180 /* Write out to the device */
181 if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
182 count, buf) < 0)
183 return -EIO;
184
185 return count;
186}
187
188static struct bin_attribute ds1682_eeprom_attr = {
189 .attr = {
190 .name = "eeprom",
191 .mode = S_IRUGO | S_IWUSR,
192 .owner = THIS_MODULE,
193 },
194 .size = DS1682_EEPROM_SIZE,
195 .read = ds1682_eeprom_read,
196 .write = ds1682_eeprom_write,
197};
198
199/*
200 * Called when a ds1682 device is matched with this driver
201 */
202static int ds1682_probe(struct i2c_client *client)
203{
204 int rc;
205
206 if (!i2c_check_functionality(client->adapter,
207 I2C_FUNC_SMBUS_I2C_BLOCK)) {
208 dev_err(&client->dev, "i2c bus does not support the ds1682\n");
209 rc = -ENODEV;
210 goto exit;
211 }
212
213 rc = sysfs_create_group(&client->dev.kobj, &ds1682_group);
214 if (rc)
215 goto exit;
216
217 rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
218 if (rc)
219 goto exit_bin_attr;
220
221 return 0;
222
223 exit_bin_attr:
224 sysfs_remove_group(&client->dev.kobj, &ds1682_group);
225 exit:
226 return rc;
227}
228
229static int ds1682_remove(struct i2c_client *client)
230{
231 sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
232 sysfs_remove_group(&client->dev.kobj, &ds1682_group);
233 return 0;
234}
235
236static struct i2c_driver ds1682_driver = {
237 .driver = {
238 .name = "ds1682",
239 },
240 .probe = ds1682_probe,
241 .remove = ds1682_remove,
242};
243
244static int __init ds1682_init(void)
245{
246 return i2c_add_driver(&ds1682_driver);
247}
248
249static void __exit ds1682_exit(void)
250{
251 i2c_del_driver(&ds1682_driver);
252}
253
254MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
255MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver");
256MODULE_LICENSE("GPL");
257
258module_init(ds1682_init);
259module_exit(ds1682_exit);
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index bfce13c8f1ff..d3da1fb05b9b 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -88,8 +88,10 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); 88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice);
89 89
90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
91 for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_BLOCK_MAX) 91 for (i = slice << 5; i < (slice + 1) << 5; i += 32)
92 if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_BLOCK_MAX) 92 if (i2c_smbus_read_i2c_block_data(client, i,
93 32, data->data + i)
94 != 32)
93 goto exit; 95 goto exit;
94 } else { 96 } else {
95 if (i2c_smbus_write_byte(client, slice << 5)) { 97 if (i2c_smbus_write_byte(client, slice << 5)) {
@@ -110,7 +112,8 @@ exit:
110 mutex_unlock(&data->update_lock); 112 mutex_unlock(&data->update_lock);
111} 113}
112 114
113static ssize_t eeprom_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 115static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
114{ 117{
115 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); 118 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
116 struct eeprom_data *data = i2c_get_clientdata(client); 119 struct eeprom_data *data = i2c_get_clientdata(client);
@@ -143,7 +146,6 @@ static struct bin_attribute eeprom_attr = {
143 .attr = { 146 .attr = {
144 .name = "eeprom", 147 .name = "eeprom",
145 .mode = S_IRUGO, 148 .mode = S_IRUGO,
146 .owner = THIS_MODULE,
147 }, 149 },
148 .size = EEPROM_SIZE, 150 .size = EEPROM_SIZE,
149 .read = eeprom_read, 151 .read = eeprom_read,
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 76645c142977..64692f666372 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -106,6 +106,7 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
106 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 106 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
107 if (i2c_smbus_read_i2c_block_data(client, 107 if (i2c_smbus_read_i2c_block_data(client,
108 MAX6875_CMD_BLK_READ, 108 MAX6875_CMD_BLK_READ,
109 SLICE_SIZE,
109 buf) != SLICE_SIZE) { 110 buf) != SLICE_SIZE) {
110 goto exit_up; 111 goto exit_up;
111 } 112 }
@@ -125,8 +126,9 @@ exit_up:
125 mutex_unlock(&data->update_lock); 126 mutex_unlock(&data->update_lock);
126} 127}
127 128
128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, 129static ssize_t max6875_read(struct kobject *kobj,
129 size_t count) 130 struct bin_attribute *bin_attr,
131 char *buf, loff_t off, size_t count)
130{ 132{
131 struct i2c_client *client = kobj_to_i2c_client(kobj); 133 struct i2c_client *client = kobj_to_i2c_client(kobj);
132 struct max6875_data *data = i2c_get_clientdata(client); 134 struct max6875_data *data = i2c_get_clientdata(client);
@@ -152,7 +154,6 @@ static struct bin_attribute user_eeprom_attr = {
152 .attr = { 154 .attr = {
153 .name = "eeprom", 155 .name = "eeprom",
154 .mode = S_IRUGO, 156 .mode = S_IRUGO,
155 .owner = THIS_MODULE,
156 }, 157 },
157 .size = USER_EEPROM_SIZE, 158 .size = USER_EEPROM_SIZE,
158 .read = max6875_read, 159 .read = max6875_read,
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
new file mode 100644
index 000000000000..3de4b19ba08f
--- /dev/null
+++ b/drivers/i2c/chips/tsl2550.c
@@ -0,0 +1,460 @@
1/*
2 * tsl2550.c - Linux kernel modules for ambient light sensor
3 *
4 * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (C) 2007 Eurotech S.p.A. <info@eurotech.it>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/i2c.h>
26#include <linux/mutex.h>
27#include <linux/delay.h>
28
29#define TSL2550_DRV_NAME "tsl2550"
30#define DRIVER_VERSION "1.1.1"
31
32/*
33 * Defines
34 */
35
36#define TSL2550_POWER_DOWN 0x00
37#define TSL2550_POWER_UP 0x03
38#define TSL2550_STANDARD_RANGE 0x18
39#define TSL2550_EXTENDED_RANGE 0x1d
40#define TSL2550_READ_ADC0 0x43
41#define TSL2550_READ_ADC1 0x83
42
43/*
44 * Structs
45 */
46
47struct tsl2550_data {
48 struct i2c_client *client;
49 struct mutex update_lock;
50
51 unsigned int power_state : 1;
52 unsigned int operating_mode : 1;
53};
54
55/*
56 * Global data
57 */
58
59static const u8 TSL2550_MODE_RANGE[2] = {
60 TSL2550_STANDARD_RANGE, TSL2550_EXTENDED_RANGE,
61};
62
63/*
64 * Management functions
65 */
66
67static int tsl2550_set_operating_mode(struct i2c_client *client, int mode)
68{
69 struct tsl2550_data *data = i2c_get_clientdata(client);
70
71 int ret = i2c_smbus_write_byte(client, TSL2550_MODE_RANGE[mode]);
72
73 data->operating_mode = mode;
74
75 return ret;
76}
77
78static int tsl2550_set_power_state(struct i2c_client *client, int state)
79{
80 struct tsl2550_data *data = i2c_get_clientdata(client);
81 int ret;
82
83 if (state == 0)
84 ret = i2c_smbus_write_byte(client, TSL2550_POWER_DOWN);
85 else {
86 ret = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
87
88 /* On power up we should reset operating mode also... */
89 tsl2550_set_operating_mode(client, data->operating_mode);
90 }
91
92 data->power_state = state;
93
94 return ret;
95}
96
97static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd)
98{
99 unsigned long end;
100 int loop = 0, ret = 0;
101
102 /*
103 * Read ADC channel waiting at most 400ms (see data sheet for further
104 * info).
105 * To avoid long busy wait we spin for few milliseconds then
106 * start sleeping.
107 */
108 end = jiffies + msecs_to_jiffies(400);
109 while (time_before(jiffies, end)) {
110 i2c_smbus_write_byte(client, cmd);
111
112 if (loop++ < 5)
113 mdelay(1);
114 else
115 msleep(1);
116
117 ret = i2c_smbus_read_byte(client);
118 if (ret < 0)
119 return ret;
120 else if (ret & 0x0080)
121 break;
122 }
123 if (!(ret & 0x80))
124 return -EIO;
125 return ret & 0x7f; /* remove the "valid" bit */
126}
127
128/*
129 * LUX calculation
130 */
131
132#define TSL2550_MAX_LUX 1846
133
134static const u8 ratio_lut[] = {
135 100, 100, 100, 100, 100, 100, 100, 100,
136 100, 100, 100, 100, 100, 100, 99, 99,
137 99, 99, 99, 99, 99, 99, 99, 99,
138 99, 99, 99, 98, 98, 98, 98, 98,
139 98, 98, 97, 97, 97, 97, 97, 96,
140 96, 96, 96, 95, 95, 95, 94, 94,
141 93, 93, 93, 92, 92, 91, 91, 90,
142 89, 89, 88, 87, 87, 86, 85, 84,
143 83, 82, 81, 80, 79, 78, 77, 75,
144 74, 73, 71, 69, 68, 66, 64, 62,
145 60, 58, 56, 54, 52, 49, 47, 44,
146 42, 41, 40, 40, 39, 39, 38, 38,
147 37, 37, 37, 36, 36, 36, 35, 35,
148 35, 35, 34, 34, 34, 34, 33, 33,
149 33, 33, 32, 32, 32, 32, 32, 31,
150 31, 31, 31, 31, 30, 30, 30, 30,
151 30,
152};
153
154static const u16 count_lut[] = {
155 0, 1, 2, 3, 4, 5, 6, 7,
156 8, 9, 10, 11, 12, 13, 14, 15,
157 16, 18, 20, 22, 24, 26, 28, 30,
158 32, 34, 36, 38, 40, 42, 44, 46,
159 49, 53, 57, 61, 65, 69, 73, 77,
160 81, 85, 89, 93, 97, 101, 105, 109,
161 115, 123, 131, 139, 147, 155, 163, 171,
162 179, 187, 195, 203, 211, 219, 227, 235,
163 247, 263, 279, 295, 311, 327, 343, 359,
164 375, 391, 407, 423, 439, 455, 471, 487,
165 511, 543, 575, 607, 639, 671, 703, 735,
166 767, 799, 831, 863, 895, 927, 959, 991,
167 1039, 1103, 1167, 1231, 1295, 1359, 1423, 1487,
168 1551, 1615, 1679, 1743, 1807, 1871, 1935, 1999,
169 2095, 2223, 2351, 2479, 2607, 2735, 2863, 2991,
170 3119, 3247, 3375, 3503, 3631, 3759, 3887, 4015,
171};
172
173/*
174 * This function is described into Taos TSL2550 Designer's Notebook
175 * pages 2, 3.
176 */
177static int tsl2550_calculate_lux(u8 ch0, u8 ch1)
178{
179 unsigned int lux;
180
181 /* Look up count from channel values */
182 u16 c0 = count_lut[ch0];
183 u16 c1 = count_lut[ch1];
184
185 /*
186 * Calculate ratio.
187 * Note: the "128" is a scaling factor
188 */
189 u8 r = 128;
190
191 /* Avoid division by 0 and count 1 cannot be greater than count 0 */
192 if (c0 && (c1 <= c0))
193 r = c1 * 128 / c0;
194 else
195 return -1;
196
197 /* Calculate LUX */
198 lux = ((c0 - c1) * ratio_lut[r]) / 256;
199
200 /* LUX range check */
201 return lux > TSL2550_MAX_LUX ? TSL2550_MAX_LUX : lux;
202}
203
204/*
205 * SysFS support
206 */
207
208static ssize_t tsl2550_show_power_state(struct device *dev,
209 struct device_attribute *attr, char *buf)
210{
211 struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev));
212
213 return sprintf(buf, "%u\n", data->power_state);
214}
215
216static ssize_t tsl2550_store_power_state(struct device *dev,
217 struct device_attribute *attr, const char *buf, size_t count)
218{
219 struct i2c_client *client = to_i2c_client(dev);
220 struct tsl2550_data *data = i2c_get_clientdata(client);
221 unsigned long val = simple_strtoul(buf, NULL, 10);
222 int ret;
223
224 if (val < 0 || val > 1)
225 return -EINVAL;
226
227 mutex_lock(&data->update_lock);
228 ret = tsl2550_set_power_state(client, val);
229 mutex_unlock(&data->update_lock);
230
231 if (ret < 0)
232 return ret;
233
234 return count;
235}
236
237static DEVICE_ATTR(power_state, S_IWUSR | S_IRUGO,
238 tsl2550_show_power_state, tsl2550_store_power_state);
239
240static ssize_t tsl2550_show_operating_mode(struct device *dev,
241 struct device_attribute *attr, char *buf)
242{
243 struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev));
244
245 return sprintf(buf, "%u\n", data->operating_mode);
246}
247
248static ssize_t tsl2550_store_operating_mode(struct device *dev,
249 struct device_attribute *attr, const char *buf, size_t count)
250{
251 struct i2c_client *client = to_i2c_client(dev);
252 struct tsl2550_data *data = i2c_get_clientdata(client);
253 unsigned long val = simple_strtoul(buf, NULL, 10);
254 int ret;
255
256 if (val < 0 || val > 1)
257 return -EINVAL;
258
259 if (data->power_state == 0)
260 return -EBUSY;
261
262 mutex_lock(&data->update_lock);
263 ret = tsl2550_set_operating_mode(client, val);
264 mutex_unlock(&data->update_lock);
265
266 if (ret < 0)
267 return ret;
268
269 return count;
270}
271
272static DEVICE_ATTR(operating_mode, S_IWUSR | S_IRUGO,
273 tsl2550_show_operating_mode, tsl2550_store_operating_mode);
274
275static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
276{
277 u8 ch0, ch1;
278 int ret;
279
280 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC0);
281 if (ret < 0)
282 return ret;
283 ch0 = ret;
284
285 mdelay(1);
286
287 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1);
288 if (ret < 0)
289 return ret;
290 ch1 = ret;
291
292 /* Do the job */
293 ret = tsl2550_calculate_lux(ch0, ch1);
294 if (ret < 0)
295 return ret;
296
297 return sprintf(buf, "%d\n", ret);
298}
299
300static ssize_t tsl2550_show_lux1_input(struct device *dev,
301 struct device_attribute *attr, char *buf)
302{
303 struct i2c_client *client = to_i2c_client(dev);
304 struct tsl2550_data *data = i2c_get_clientdata(client);
305 int ret;
306
307 /* No LUX data if not operational */
308 if (!data->power_state)
309 return -EBUSY;
310
311 mutex_lock(&data->update_lock);
312 ret = __tsl2550_show_lux(client, buf);
313 mutex_unlock(&data->update_lock);
314
315 return ret;
316}
317
318static DEVICE_ATTR(lux1_input, S_IRUGO,
319 tsl2550_show_lux1_input, NULL);
320
321static struct attribute *tsl2550_attributes[] = {
322 &dev_attr_power_state.attr,
323 &dev_attr_operating_mode.attr,
324 &dev_attr_lux1_input.attr,
325 NULL
326};
327
328static const struct attribute_group tsl2550_attr_group = {
329 .attrs = tsl2550_attributes,
330};
331
332/*
333 * Initialization function
334 */
335
336static int tsl2550_init_client(struct i2c_client *client)
337{
338 struct tsl2550_data *data = i2c_get_clientdata(client);
339 int err;
340
341 /*
342 * Probe the chip. To do so we try to power up the device and then to
343 * read back the 0x03 code
344 */
345 err = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
346 if (err < 0)
347 return err;
348 mdelay(1);
349 if (i2c_smbus_read_byte(client) != TSL2550_POWER_UP)
350 return -ENODEV;
351 data->power_state = 1;
352
353 /* Set the default operating mode */
354 err = i2c_smbus_write_byte(client,
355 TSL2550_MODE_RANGE[data->operating_mode]);
356 if (err < 0)
357 return err;
358
359 return 0;
360}
361
362/*
363 * I2C init/probing/exit functions
364 */
365
366static struct i2c_driver tsl2550_driver;
367static int __devinit tsl2550_probe(struct i2c_client *client)
368{
369 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
370 struct tsl2550_data *data;
371 int *opmode, err = 0;
372
373 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) {
374 err = -EIO;
375 goto exit;
376 }
377
378 data = kzalloc(sizeof(struct tsl2550_data), GFP_KERNEL);
379 if (!data) {
380 err = -ENOMEM;
381 goto exit;
382 }
383 data->client = client;
384 i2c_set_clientdata(client, data);
385
386 /* Check platform data */
387 opmode = client->dev.platform_data;
388 if (opmode) {
389 if (*opmode < 0 || *opmode > 1) {
390 dev_err(&client->dev, "invalid operating_mode (%d)\n",
391 *opmode);
392 err = -EINVAL;
393 goto exit_kfree;
394 }
395 data->operating_mode = *opmode;
396 } else
397 data->operating_mode = 0; /* default mode is standard */
398 dev_info(&client->dev, "%s operating mode\n",
399 data->operating_mode ? "extended" : "standard");
400
401 mutex_init(&data->update_lock);
402
403 /* Initialize the TSL2550 chip */
404 err = tsl2550_init_client(client);
405 if (err)
406 goto exit_kfree;
407
408 /* Register sysfs hooks */
409 err = sysfs_create_group(&client->dev.kobj, &tsl2550_attr_group);
410 if (err)
411 goto exit_kfree;
412
413 dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
414
415 return 0;
416
417exit_kfree:
418 kfree(data);
419exit:
420 return err;
421}
422
423static int __devexit tsl2550_remove(struct i2c_client *client)
424{
425 sysfs_remove_group(&client->dev.kobj, &tsl2550_attr_group);
426
427 /* Power down the device */
428 tsl2550_set_power_state(client, 0);
429
430 kfree(i2c_get_clientdata(client));
431
432 return 0;
433}
434
435static struct i2c_driver tsl2550_driver = {
436 .driver = {
437 .name = TSL2550_DRV_NAME,
438 .owner = THIS_MODULE,
439 },
440 .probe = tsl2550_probe,
441 .remove = __devexit_p(tsl2550_remove),
442};
443
444static int __init tsl2550_init(void)
445{
446 return i2c_add_driver(&tsl2550_driver);
447}
448
449static void __exit tsl2550_exit(void)
450{
451 i2c_del_driver(&tsl2550_driver);
452}
453
454MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
455MODULE_DESCRIPTION("TSL2550 ambient light sensor driver");
456MODULE_LICENSE("GPL");
457MODULE_VERSION(DRIVER_VERSION);
458
459module_init(tsl2550_init);
460module_exit(tsl2550_exit);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 435925eba437..6971a62397db 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -207,6 +207,7 @@ EXPORT_SYMBOL_GPL(i2c_bus_type);
207 * i2c_new_device - instantiate an i2c device for use with a new style driver 207 * i2c_new_device - instantiate an i2c device for use with a new style driver
208 * @adap: the adapter managing the device 208 * @adap: the adapter managing the device
209 * @info: describes one I2C device; bus_num is ignored 209 * @info: describes one I2C device; bus_num is ignored
210 * Context: can sleep
210 * 211 *
211 * Create a device to work with a new style i2c driver, where binding is 212 * Create a device to work with a new style i2c driver, where binding is
212 * handled through driver model probe()/remove() methods. This call is not 213 * handled through driver model probe()/remove() methods. This call is not
@@ -255,6 +256,7 @@ EXPORT_SYMBOL_GPL(i2c_new_device);
255/** 256/**
256 * i2c_unregister_device - reverse effect of i2c_new_device() 257 * i2c_unregister_device - reverse effect of i2c_new_device()
257 * @client: value returned from i2c_new_device() 258 * @client: value returned from i2c_new_device()
259 * Context: can sleep
258 */ 260 */
259void i2c_unregister_device(struct i2c_client *client) 261void i2c_unregister_device(struct i2c_client *client)
260{ 262{
@@ -379,6 +381,7 @@ out_list:
379/** 381/**
380 * i2c_add_adapter - declare i2c adapter, use dynamic bus number 382 * i2c_add_adapter - declare i2c adapter, use dynamic bus number
381 * @adapter: the adapter to add 383 * @adapter: the adapter to add
384 * Context: can sleep
382 * 385 *
383 * This routine is used to declare an I2C adapter when its bus number 386 * This routine is used to declare an I2C adapter when its bus number
384 * doesn't matter. Examples: for I2C adapters dynamically added by 387 * doesn't matter. Examples: for I2C adapters dynamically added by
@@ -416,6 +419,7 @@ EXPORT_SYMBOL(i2c_add_adapter);
416/** 419/**
417 * i2c_add_numbered_adapter - declare i2c adapter, use static bus number 420 * i2c_add_numbered_adapter - declare i2c adapter, use static bus number
418 * @adap: the adapter to register (with adap->nr initialized) 421 * @adap: the adapter to register (with adap->nr initialized)
422 * Context: can sleep
419 * 423 *
420 * This routine is used to declare an I2C adapter when its bus number 424 * This routine is used to declare an I2C adapter when its bus number
421 * matters. Example: for I2C adapters from system-on-chip CPUs, or 425 * matters. Example: for I2C adapters from system-on-chip CPUs, or
@@ -463,6 +467,14 @@ retry:
463} 467}
464EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); 468EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
465 469
470/**
471 * i2c_del_adapter - unregister I2C adapter
472 * @adap: the adapter being unregistered
473 * Context: can sleep
474 *
475 * This unregisters an I2C adapter which was previously registered
476 * by @i2c_add_adapter or @i2c_add_numbered_adapter.
477 */
466int i2c_del_adapter(struct i2c_adapter *adap) 478int i2c_del_adapter(struct i2c_adapter *adap)
467{ 479{
468 struct list_head *item, *_n; 480 struct list_head *item, *_n;
@@ -598,6 +610,7 @@ EXPORT_SYMBOL(i2c_register_driver);
598/** 610/**
599 * i2c_del_driver - unregister I2C driver 611 * i2c_del_driver - unregister I2C driver
600 * @driver: the driver being unregistered 612 * @driver: the driver being unregistered
613 * Context: can sleep
601 */ 614 */
602void i2c_del_driver(struct i2c_driver *driver) 615void i2c_del_driver(struct i2c_driver *driver)
603{ 616{
@@ -1331,10 +1344,14 @@ s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1331EXPORT_SYMBOL(i2c_smbus_write_block_data); 1344EXPORT_SYMBOL(i2c_smbus_write_block_data);
1332 1345
1333/* Returns the number of read bytes */ 1346/* Returns the number of read bytes */
1334s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, u8 *values) 1347s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
1348 u8 length, u8 *values)
1335{ 1349{
1336 union i2c_smbus_data data; 1350 union i2c_smbus_data data;
1337 1351
1352 if (length > I2C_SMBUS_BLOCK_MAX)
1353 length = I2C_SMBUS_BLOCK_MAX;
1354 data.block[0] = length;
1338 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1355 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags,
1339 I2C_SMBUS_READ,command, 1356 I2C_SMBUS_READ,command,
1340 I2C_SMBUS_I2C_BLOCK_DATA,&data)) 1357 I2C_SMBUS_I2C_BLOCK_DATA,&data))
@@ -1455,7 +1472,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1455 break; 1472 break;
1456 case I2C_SMBUS_I2C_BLOCK_DATA: 1473 case I2C_SMBUS_I2C_BLOCK_DATA:
1457 if (read_write == I2C_SMBUS_READ) { 1474 if (read_write == I2C_SMBUS_READ) {
1458 msg[1].len = I2C_SMBUS_BLOCK_MAX; 1475 msg[1].len = data->block[0];
1459 } else { 1476 } else {
1460 msg[0].len = data->block[0] + 1; 1477 msg[0].len = data->block[0] + 1;
1461 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) { 1478 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) {
@@ -1511,9 +1528,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1511 data->word = msgbuf1[0] | (msgbuf1[1] << 8); 1528 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
1512 break; 1529 break;
1513 case I2C_SMBUS_I2C_BLOCK_DATA: 1530 case I2C_SMBUS_I2C_BLOCK_DATA:
1514 /* fixed at 32 for now */ 1531 for (i = 0; i < data->block[0]; i++)
1515 data->block[0] = I2C_SMBUS_BLOCK_MAX;
1516 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
1517 data->block[i+1] = msgbuf1[i]; 1532 data->block[i+1] = msgbuf1[i];
1518 break; 1533 break;
1519 case I2C_SMBUS_BLOCK_DATA: 1534 case I2C_SMBUS_BLOCK_DATA:
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index e7a709710592..64eee9551b22 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -283,6 +283,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
283 (data_arg.size != I2C_SMBUS_WORD_DATA) && 283 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
284 (data_arg.size != I2C_SMBUS_PROC_CALL) && 284 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
285 (data_arg.size != I2C_SMBUS_BLOCK_DATA) && 285 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
286 (data_arg.size != I2C_SMBUS_I2C_BLOCK_BROKEN) &&
286 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) && 287 (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA) &&
287 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) { 288 (data_arg.size != I2C_SMBUS_BLOCK_PROC_CALL)) {
288 dev_dbg(&client->adapter->dev, 289 dev_dbg(&client->adapter->dev,
@@ -329,10 +330,18 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
329 330
330 if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 331 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
331 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 332 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
333 (data_arg.size == I2C_SMBUS_I2C_BLOCK_DATA) ||
332 (data_arg.read_write == I2C_SMBUS_WRITE)) { 334 (data_arg.read_write == I2C_SMBUS_WRITE)) {
333 if (copy_from_user(&temp, data_arg.data, datasize)) 335 if (copy_from_user(&temp, data_arg.data, datasize))
334 return -EFAULT; 336 return -EFAULT;
335 } 337 }
338 if (data_arg.size == I2C_SMBUS_I2C_BLOCK_BROKEN) {
339 /* Convert old I2C block commands to the new
340 convention. This preserves binary compatibility. */
341 data_arg.size = I2C_SMBUS_I2C_BLOCK_DATA;
342 if (data_arg.read_write == I2C_SMBUS_READ)
343 temp.block[0] = I2C_SMBUS_BLOCK_MAX;
344 }
336 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, 345 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags,
337 data_arg.read_write, 346 data_arg.read_write,
338 data_arg.command,data_arg.size,&temp); 347 data_arg.command,data_arg.size,&temp);
diff --git a/drivers/ide/legacy/hd.c b/drivers/ide/legacy/hd.c
index 7f4c0a5050a1..8f2db8dd35f7 100644
--- a/drivers/ide/legacy/hd.c
+++ b/drivers/ide/legacy/hd.c
@@ -719,74 +719,25 @@ static int __init hd_init(void)
719 device_timer.function = hd_times_out; 719 device_timer.function = hd_times_out;
720 blk_queue_hardsect_size(hd_queue, 512); 720 blk_queue_hardsect_size(hd_queue, 512);
721 721
722#ifdef __i386__
723 if (!NR_HD) { 722 if (!NR_HD) {
724 extern struct drive_info drive_info; 723 /*
725 unsigned char *BIOS = (unsigned char *) &drive_info; 724 * We don't know anything about the drive. This means
726 unsigned long flags;
727 int cmos_disks;
728
729 for (drive=0 ; drive<2 ; drive++) {
730 hd_info[drive].cyl = *(unsigned short *) BIOS;
731 hd_info[drive].head = *(2+BIOS);
732 hd_info[drive].wpcom = *(unsigned short *) (5+BIOS);
733 hd_info[drive].ctl = *(8+BIOS);
734 hd_info[drive].lzone = *(unsigned short *) (12+BIOS);
735 hd_info[drive].sect = *(14+BIOS);
736#ifdef does_not_work_for_everybody_with_scsi_but_helps_ibm_vp
737 if (hd_info[drive].cyl && NR_HD == drive)
738 NR_HD++;
739#endif
740 BIOS += 16;
741 }
742
743 /*
744 We query CMOS about hard disks : it could be that
745 we have a SCSI/ESDI/etc controller that is BIOS
746 compatible with ST-506, and thus showing up in our
747 BIOS table, but not register compatible, and therefore
748 not present in CMOS.
749
750 Furthermore, we will assume that our ST-506 drives
751 <if any> are the primary drives in the system, and
752 the ones reflected as drive 1 or 2.
753
754 The first drive is stored in the high nibble of CMOS
755 byte 0x12, the second in the low nibble. This will be
756 either a 4 bit drive type or 0xf indicating use byte 0x19
757 for an 8 bit type, drive 1, 0x1a for drive 2 in CMOS.
758
759 Needless to say, a non-zero value means we have
760 an AT controller hard disk for that drive.
761
762 Currently the rtc_lock is a bit academic since this
763 driver is non-modular, but someday... ? Paul G.
764 */
765
766 spin_lock_irqsave(&rtc_lock, flags);
767 cmos_disks = CMOS_READ(0x12);
768 spin_unlock_irqrestore(&rtc_lock, flags);
769
770 if (cmos_disks & 0xf0) {
771 if (cmos_disks & 0x0f)
772 NR_HD = 2;
773 else
774 NR_HD = 1;
775 }
776 }
777#endif /* __i386__ */
778#ifdef __arm__
779 if (!NR_HD) {
780 /* We don't know anything about the drive. This means
781 * that you *MUST* specify the drive parameters to the 725 * that you *MUST* specify the drive parameters to the
782 * kernel yourself. 726 * kernel yourself.
727 *
728 * If we were on an i386, we used to read this info from
729 * the BIOS or CMOS. This doesn't work all that well,
730 * since this assumes that this is a primary or secondary
731 * drive, and if we're using this legacy driver, it's
732 * probably an auxilliary controller added to recover
733 * legacy data off an ST-506 drive. Either way, it's
734 * definitely safest to have the user explicitly specify
735 * the information.
783 */ 736 */
784 printk("hd: no drives specified - use hd=cyl,head,sectors" 737 printk("hd: no drives specified - use hd=cyl,head,sectors"
785 " on kernel command line\n"); 738 " on kernel command line\n");
786 }
787#endif
788 if (!NR_HD)
789 goto out; 739 goto out;
740 }
790 741
791 for (drive=0 ; drive < NR_HD ; drive++) { 742 for (drive=0 ; drive < NR_HD ; drive++) {
792 struct gendisk *disk = alloc_disk(64); 743 struct gendisk *disk = alloc_disk(64);
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 08c299ebf4a8..bf9b99292048 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -479,7 +479,6 @@ alloc_group_attrs(ssize_t (*show)(struct ib_port *,
479 479
480 element->attr.attr.name = element->name; 480 element->attr.attr.name = element->name;
481 element->attr.attr.mode = S_IRUGO; 481 element->attr.attr.mode = S_IRUGO;
482 element->attr.attr.owner = THIS_MODULE;
483 element->attr.show = show; 482 element->attr.show = show;
484 element->index = i; 483 element->index = i;
485 484
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 27a68835b5ba..1317bdd8cc7c 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -119,7 +119,6 @@ static struct psmouse_attribute psmouse_attr_##_name = { \
119 .attr = { \ 119 .attr = { \
120 .name = __stringify(_name), \ 120 .name = __stringify(_name), \
121 .mode = _mode, \ 121 .mode = _mode, \
122 .owner = THIS_MODULE, \
123 }, \ 122 }, \
124 .show = psmouse_attr_show_helper, \ 123 .show = psmouse_attr_show_helper, \
125 .store = psmouse_attr_set_helper, \ 124 .store = psmouse_attr_set_helper, \
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c
index 11ced17f438a..4fcb245ba184 100644
--- a/drivers/macintosh/windfarm_core.c
+++ b/drivers/macintosh/windfarm_core.c
@@ -212,7 +212,6 @@ int wf_register_control(struct wf_control *new_ct)
212 list_add(&new_ct->link, &wf_controls); 212 list_add(&new_ct->link, &wf_controls);
213 213
214 new_ct->attr.attr.name = new_ct->name; 214 new_ct->attr.attr.name = new_ct->name;
215 new_ct->attr.attr.owner = THIS_MODULE;
216 new_ct->attr.attr.mode = 0644; 215 new_ct->attr.attr.mode = 0644;
217 new_ct->attr.show = wf_show_control; 216 new_ct->attr.show = wf_show_control;
218 new_ct->attr.store = wf_store_control; 217 new_ct->attr.store = wf_store_control;
@@ -325,7 +324,6 @@ int wf_register_sensor(struct wf_sensor *new_sr)
325 list_add(&new_sr->link, &wf_sensors); 324 list_add(&new_sr->link, &wf_sensors);
326 325
327 new_sr->attr.attr.name = new_sr->name; 326 new_sr->attr.attr.name = new_sr->name;
328 new_sr->attr.attr.owner = THIS_MODULE;
329 new_sr->attr.attr.mode = 0444; 327 new_sr->attr.attr.mode = 0444;
330 new_sr->attr.show = wf_show_sensor; 328 new_sr->attr.show = wf_show_sensor;
331 new_sr->attr.store = NULL; 329 new_sr->attr.store = NULL;
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
index 1043b39aa123..351982bcec1b 100644
--- a/drivers/macintosh/windfarm_smu_sat.c
+++ b/drivers/macintosh/windfarm_smu_sat.c
@@ -67,26 +67,6 @@ static struct i2c_driver wf_sat_driver = {
67 .detach_client = wf_sat_detach, 67 .detach_client = wf_sat_detach,
68}; 68};
69 69
70/*
71 * XXX i2c_smbus_read_i2c_block_data doesn't pass the requested
72 * length down to the low-level driver, so we use this, which
73 * works well enough with the SMU i2c driver code...
74 */
75static int sat_read_block(struct i2c_client *client, u8 command,
76 u8 *values, int len)
77{
78 union i2c_smbus_data data;
79 int err;
80
81 data.block[0] = len;
82 err = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
83 I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA,
84 &data);
85 if (!err)
86 memcpy(values, data.block, len);
87 return err;
88}
89
90struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id, 70struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
91 unsigned int *size) 71 unsigned int *size)
92{ 72{
@@ -124,8 +104,8 @@ struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
124 return NULL; 104 return NULL;
125 105
126 for (i = 0; i < len; i += 4) { 106 for (i = 0; i < len; i += 4) {
127 err = sat_read_block(&sat->i2c, 0xa, data, 4); 107 err = i2c_smbus_read_i2c_block_data(&sat->i2c, 0xa, 4, data);
128 if (err) { 108 if (err < 0) {
129 printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n", 109 printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n",
130 err); 110 err);
131 goto fail; 111 goto fail;
@@ -157,8 +137,8 @@ static int wf_sat_read_cache(struct wf_sat *sat)
157{ 137{
158 int err; 138 int err;
159 139
160 err = sat_read_block(&sat->i2c, 0x3f, sat->cache, 16); 140 err = i2c_smbus_read_i2c_block_data(&sat->i2c, 0x3f, 16, sat->cache);
161 if (err) 141 if (err < 0)
162 return err; 142 return err;
163 sat->last_read = jiffies; 143 sat->last_read = jiffies;
164#ifdef LOTSA_DEBUG 144#ifdef LOTSA_DEBUG
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index 4f9060a2a2f2..7798f590e5aa 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -737,8 +737,7 @@ static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
737 struct device_attribute dev_attr_##_name = { \ 737 struct device_attribute dev_attr_##_name = { \
738 .attr = { \ 738 .attr = { \
739 .name = __stringify(_name), \ 739 .name = __stringify(_name), \
740 .mode = 0, \ 740 .mode = 0 }, \
741 .owner = THIS_MODULE }, \
742 .show = NULL, \ 741 .show = NULL, \
743 .store = NULL, \ 742 .store = NULL, \
744 } 743 }
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
index 41e901f53e7c..932a415197b3 100644
--- a/drivers/misc/msi-laptop.c
+++ b/drivers/misc/msi-laptop.c
@@ -23,6 +23,8 @@
23 * msi-laptop.c - MSI S270 laptop support. This laptop is sold under 23 * msi-laptop.c - MSI S270 laptop support. This laptop is sold under
24 * various brands, including "Cytron/TCM/Medion/Tchibo MD96100". 24 * various brands, including "Cytron/TCM/Medion/Tchibo MD96100".
25 * 25 *
26 * Driver also supports S271, S420 models.
27 *
26 * This driver exports a few files in /sys/devices/platform/msi-laptop-pf/: 28 * This driver exports a few files in /sys/devices/platform/msi-laptop-pf/:
27 * 29 *
28 * lcd_level - Screen brightness: contains a single integer in the 30 * lcd_level - Screen brightness: contains a single integer in the
@@ -281,25 +283,56 @@ static struct platform_device *msipf_device;
281 283
282/* Initialization */ 284/* Initialization */
283 285
286static int dmi_check_cb(struct dmi_system_id *id)
287{
288 printk("msi-laptop: Identified laptop model '%s'.\n", id->ident);
289 return 0;
290}
291
284static struct dmi_system_id __initdata msi_dmi_table[] = { 292static struct dmi_system_id __initdata msi_dmi_table[] = {
285 { 293 {
286 .ident = "MSI S270", 294 .ident = "MSI S270",
287 .matches = { 295 .matches = {
288 DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD"), 296 DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD"),
289 DMI_MATCH(DMI_PRODUCT_NAME, "MS-1013"), 297 DMI_MATCH(DMI_PRODUCT_NAME, "MS-1013"),
290 } 298 DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
299 DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
300 },
301 .callback = dmi_check_cb
302 },
303 {
304 .ident = "MSI S271",
305 .matches = {
306 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
307 DMI_MATCH(DMI_PRODUCT_NAME, "MS-1058"),
308 DMI_MATCH(DMI_PRODUCT_VERSION, "0581"),
309 DMI_MATCH(DMI_BOARD_NAME, "MS-1058")
310 },
311 .callback = dmi_check_cb
312 },
313 {
314 .ident = "MSI S420",
315 .matches = {
316 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
317 DMI_MATCH(DMI_PRODUCT_NAME, "MS-1412"),
318 DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
319 DMI_MATCH(DMI_BOARD_NAME, "MS-1412")
320 },
321 .callback = dmi_check_cb
291 }, 322 },
292 { 323 {
293 .ident = "Medion MD96100", 324 .ident = "Medion MD96100",
294 .matches = { 325 .matches = {
295 DMI_MATCH(DMI_SYS_VENDOR, "NOTEBOOK"), 326 DMI_MATCH(DMI_SYS_VENDOR, "NOTEBOOK"),
296 DMI_MATCH(DMI_PRODUCT_NAME, "SAM2000"), 327 DMI_MATCH(DMI_PRODUCT_NAME, "SAM2000"),
297 } 328 DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
329 DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
330 },
331 .callback = dmi_check_cb
298 }, 332 },
299 { } 333 { }
300}; 334};
301 335
302
303static int __init msi_init(void) 336static int __init msi_init(void)
304{ 337{
305 int ret; 338 int ret;
@@ -394,3 +427,8 @@ MODULE_AUTHOR("Lennart Poettering");
394MODULE_DESCRIPTION("MSI Laptop Support"); 427MODULE_DESCRIPTION("MSI Laptop Support");
395MODULE_VERSION(MSI_DRIVER_VERSION); 428MODULE_VERSION(MSI_DRIVER_VERSION);
396MODULE_LICENSE("GPL"); 429MODULE_LICENSE("GPL");
430
431MODULE_ALIAS("dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
432MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
433MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
434MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index da1a22c13865..ab18343e58ef 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -990,7 +990,7 @@ static void elmc_rcv_int(struct net_device *dev)
990 if (skb != NULL) { 990 if (skb != NULL) {
991 skb_reserve(skb, 2); /* 16 byte alignment */ 991 skb_reserve(skb, 2); /* 16 byte alignment */
992 skb_put(skb,totlen); 992 skb_put(skb,totlen);
993 eth_copy_and_sum(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen,0); 993 skb_copy_to_linear_data(skb, (char *) p->base+(unsigned long) rbd->buffer,totlen);
994 skb->protocol = eth_type_trans(skb, dev); 994 skb->protocol = eth_type_trans(skb, dev);
995 netif_rx(skb); 995 netif_rx(skb);
996 dev->last_rx = jiffies; 996 dev->last_rx = jiffies;
diff --git a/drivers/net/7990.c b/drivers/net/7990.c
index 0877fc372f4b..e89ace109a5d 100644
--- a/drivers/net/7990.c
+++ b/drivers/net/7990.c
@@ -333,9 +333,9 @@ static int lance_rx (struct net_device *dev)
333 333
334 skb_reserve (skb, 2); /* 16 byte align */ 334 skb_reserve (skb, 2); /* 16 byte align */
335 skb_put (skb, len); /* make room */ 335 skb_put (skb, len); /* make room */
336 eth_copy_and_sum(skb, 336 skb_copy_to_linear_data(skb,
337 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), 337 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
338 len, 0); 338 len);
339 skb->protocol = eth_type_trans (skb, dev); 339 skb->protocol = eth_type_trans (skb, dev);
340 netif_rx (skb); 340 netif_rx (skb);
341 dev->last_rx = jiffies; 341 dev->last_rx = jiffies;
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 77457c7c6ac2..327eaa7b4999 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -2014,7 +2014,7 @@ no_early_rx:
2014#if RX_BUF_IDX == 3 2014#if RX_BUF_IDX == 3
2015 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size); 2015 wrap_copy(skb, rx_ring, ring_offset+4, pkt_size);
2016#else 2016#else
2017 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); 2017 skb_copy_to_linear_data (skb, &rx_ring[ring_offset + 4], pkt_size);
2018#endif 2018#endif
2019 skb_put (skb, pkt_size); 2019 skb_put (skb, pkt_size);
2020 2020
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index b941c74a06c4..ba314adf68b8 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -25,6 +25,14 @@ menuconfig NETDEVICES
25# that for each of the symbols. 25# that for each of the symbols.
26if NETDEVICES 26if NETDEVICES
27 27
28config NETDEVICES_MULTIQUEUE
29 bool "Netdevice multiple hardware queue support"
30 ---help---
31 Say Y here if you want to allow the network stack to use multiple
32 hardware TX queues on an ethernet device.
33
34 Most people will say N here.
35
28config IFB 36config IFB
29 tristate "Intermediate Functional Block support" 37 tristate "Intermediate Functional Block support"
30 depends on NET_CLS_ACT 38 depends on NET_CLS_ACT
@@ -877,7 +885,7 @@ config NET_NETX
877 885
878config DM9000 886config DM9000
879 tristate "DM9000 support" 887 tristate "DM9000 support"
880 depends on ARM || MIPS 888 depends on ARM || BLACKFIN || MIPS
881 select CRC32 889 select CRC32
882 select MII 890 select MII
883 ---help--- 891 ---help---
@@ -2784,6 +2792,19 @@ config PPPOATM
2784 which can lead to bad results if the ATM peer loses state and 2792 which can lead to bad results if the ATM peer loses state and
2785 changes its encapsulation unilaterally. 2793 changes its encapsulation unilaterally.
2786 2794
2795config PPPOL2TP
2796 tristate "PPP over L2TP (EXPERIMENTAL)"
2797 depends on EXPERIMENTAL && PPP
2798 help
2799 Support for PPP-over-L2TP socket family. L2TP is a protocol
2800 used by ISPs and enterprises to tunnel PPP traffic over UDP
2801 tunnels. L2TP is replacing PPTP for VPN uses.
2802
2803 This kernel component handles only L2TP data packets: a
2804 userland daemon handles L2TP the control protocol (tunnel
2805 and session setup). One such daemon is OpenL2TP
2806 (http://openl2tp.sourceforge.net/).
2807
2787config SLIP 2808config SLIP
2788 tristate "SLIP (serial line) support" 2809 tristate "SLIP (serial line) support"
2789 ---help--- 2810 ---help---
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 1bbcbedad04a..a2241e6e1457 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -121,6 +121,7 @@ obj-$(CONFIG_PPP_DEFLATE) += ppp_deflate.o
121obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o 121obj-$(CONFIG_PPP_BSDCOMP) += bsd_comp.o
122obj-$(CONFIG_PPP_MPPE) += ppp_mppe.o 122obj-$(CONFIG_PPP_MPPE) += ppp_mppe.o
123obj-$(CONFIG_PPPOE) += pppox.o pppoe.o 123obj-$(CONFIG_PPPOE) += pppox.o pppoe.o
124obj-$(CONFIG_PPPOL2TP) += pppox.o pppol2tp.o
124 125
125obj-$(CONFIG_SLIP) += slip.o 126obj-$(CONFIG_SLIP) += slip.o
126obj-$(CONFIG_SLHC) += slhc.o 127obj-$(CONFIG_SLHC) += slhc.o
diff --git a/drivers/net/a2065.c b/drivers/net/a2065.c
index 81d5a374042a..a45de6975bfe 100644
--- a/drivers/net/a2065.c
+++ b/drivers/net/a2065.c
@@ -322,9 +322,9 @@ static int lance_rx (struct net_device *dev)
322 322
323 skb_reserve (skb, 2); /* 16 byte align */ 323 skb_reserve (skb, 2); /* 16 byte align */
324 skb_put (skb, len); /* make room */ 324 skb_put (skb, len); /* make room */
325 eth_copy_and_sum(skb, 325 skb_copy_to_linear_data(skb,
326 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]), 326 (unsigned char *)&(ib->rx_buf [lp->rx_new][0]),
327 len, 0); 327 len);
328 skb->protocol = eth_type_trans (skb, dev); 328 skb->protocol = eth_type_trans (skb, dev);
329 netif_rx (skb); 329 netif_rx (skb);
330 dev->last_rx = jiffies; 330 dev->last_rx = jiffies;
diff --git a/drivers/net/ariadne.c b/drivers/net/ariadne.c
index a241ae7855a3..bc5a38a6705f 100644
--- a/drivers/net/ariadne.c
+++ b/drivers/net/ariadne.c
@@ -746,7 +746,7 @@ static int ariadne_rx(struct net_device *dev)
746 746
747 skb_reserve(skb,2); /* 16 byte align */ 747 skb_reserve(skb,2); /* 16 byte align */
748 skb_put(skb,pkt_len); /* Make room */ 748 skb_put(skb,pkt_len); /* Make room */
749 eth_copy_and_sum(skb, (char *)priv->rx_buff[entry], pkt_len,0); 749 skb_copy_to_linear_data(skb, (char *)priv->rx_buff[entry], pkt_len);
750 skb->protocol=eth_type_trans(skb,dev); 750 skb->protocol=eth_type_trans(skb,dev);
751#if 0 751#if 0
752 printk(KERN_DEBUG "RX pkt type 0x%04x from ", 752 printk(KERN_DEBUG "RX pkt type 0x%04x from ",
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 2438c5bff237..f6ece1d43f6e 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -258,7 +258,7 @@ static int ep93xx_rx(struct net_device *dev, int *budget)
258 skb_reserve(skb, 2); 258 skb_reserve(skb, 2);
259 dma_sync_single(NULL, ep->descs->rdesc[entry].buf_addr, 259 dma_sync_single(NULL, ep->descs->rdesc[entry].buf_addr,
260 length, DMA_FROM_DEVICE); 260 length, DMA_FROM_DEVICE);
261 eth_copy_and_sum(skb, ep->rx_buf[entry], length, 0); 261 skb_copy_to_linear_data(skb, ep->rx_buf[entry], length);
262 skb_put(skb, length); 262 skb_put(skb, length);
263 skb->protocol = eth_type_trans(skb, dev); 263 skb->protocol = eth_type_trans(skb, dev);
264 264
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index c27cfcef45fa..e86b3691765b 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -1205,8 +1205,8 @@ static int au1000_rx(struct net_device *dev)
1205 continue; 1205 continue;
1206 } 1206 }
1207 skb_reserve(skb, 2); /* 16 byte IP header align */ 1207 skb_reserve(skb, 2); /* 16 byte IP header align */
1208 eth_copy_and_sum(skb, 1208 skb_copy_to_linear_data(skb,
1209 (unsigned char *)pDB->vaddr, frmlen, 0); 1209 (unsigned char *)pDB->vaddr, frmlen);
1210 skb_put(skb, frmlen); 1210 skb_put(skb, frmlen);
1211 skb->protocol = eth_type_trans(skb, dev); 1211 skb->protocol = eth_type_trans(skb, dev);
1212 netif_rx(skb); /* pass the packet to upper layers */ 1212 netif_rx(skb); /* pass the packet to upper layers */
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 23958f73c421..02e994b1b028 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -40,7 +40,6 @@
40#define BCM_VLAN 1 40#define BCM_VLAN 1
41#endif 41#endif
42#include <net/ip.h> 42#include <net/ip.h>
43#include <net/tcp.h>
44#include <net/checksum.h> 43#include <net/checksum.h>
45#include <linux/workqueue.h> 44#include <linux/workqueue.h>
46#include <linux/crc32.h> 45#include <linux/crc32.h>
@@ -54,8 +53,8 @@
54 53
55#define DRV_MODULE_NAME "bnx2" 54#define DRV_MODULE_NAME "bnx2"
56#define PFX DRV_MODULE_NAME ": " 55#define PFX DRV_MODULE_NAME ": "
57#define DRV_MODULE_VERSION "1.5.11" 56#define DRV_MODULE_VERSION "1.6.2"
58#define DRV_MODULE_RELDATE "June 4, 2007" 57#define DRV_MODULE_RELDATE "July 6, 2007"
59 58
60#define RUN_AT(x) (jiffies + (x)) 59#define RUN_AT(x) (jiffies + (x))
61 60
@@ -550,6 +549,9 @@ bnx2_report_fw_link(struct bnx2 *bp)
550{ 549{
551 u32 fw_link_status = 0; 550 u32 fw_link_status = 0;
552 551
552 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
553 return;
554
553 if (bp->link_up) { 555 if (bp->link_up) {
554 u32 bmsr; 556 u32 bmsr;
555 557
@@ -601,12 +603,21 @@ bnx2_report_fw_link(struct bnx2 *bp)
601 REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status); 603 REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
602} 604}
603 605
606static char *
607bnx2_xceiver_str(struct bnx2 *bp)
608{
609 return ((bp->phy_port == PORT_FIBRE) ? "SerDes" :
610 ((bp->phy_flags & PHY_SERDES_FLAG) ? "Remote Copper" :
611 "Copper"));
612}
613
604static void 614static void
605bnx2_report_link(struct bnx2 *bp) 615bnx2_report_link(struct bnx2 *bp)
606{ 616{
607 if (bp->link_up) { 617 if (bp->link_up) {
608 netif_carrier_on(bp->dev); 618 netif_carrier_on(bp->dev);
609 printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name); 619 printk(KERN_INFO PFX "%s NIC %s Link is Up, ", bp->dev->name,
620 bnx2_xceiver_str(bp));
610 621
611 printk("%d Mbps ", bp->line_speed); 622 printk("%d Mbps ", bp->line_speed);
612 623
@@ -630,7 +641,8 @@ bnx2_report_link(struct bnx2 *bp)
630 } 641 }
631 else { 642 else {
632 netif_carrier_off(bp->dev); 643 netif_carrier_off(bp->dev);
633 printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name); 644 printk(KERN_ERR PFX "%s NIC %s Link is Down\n", bp->dev->name,
645 bnx2_xceiver_str(bp));
634 } 646 }
635 647
636 bnx2_report_fw_link(bp); 648 bnx2_report_fw_link(bp);
@@ -1100,6 +1112,9 @@ bnx2_set_link(struct bnx2 *bp)
1100 return 0; 1112 return 0;
1101 } 1113 }
1102 1114
1115 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1116 return 0;
1117
1103 link_up = bp->link_up; 1118 link_up = bp->link_up;
1104 1119
1105 bnx2_enable_bmsr1(bp); 1120 bnx2_enable_bmsr1(bp);
@@ -1210,12 +1225,74 @@ bnx2_phy_get_pause_adv(struct bnx2 *bp)
1210 return adv; 1225 return adv;
1211} 1226}
1212 1227
1228static int bnx2_fw_sync(struct bnx2 *, u32, int);
1229
1213static int 1230static int
1214bnx2_setup_serdes_phy(struct bnx2 *bp) 1231bnx2_setup_remote_phy(struct bnx2 *bp, u8 port)
1232{
1233 u32 speed_arg = 0, pause_adv;
1234
1235 pause_adv = bnx2_phy_get_pause_adv(bp);
1236
1237 if (bp->autoneg & AUTONEG_SPEED) {
1238 speed_arg |= BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG;
1239 if (bp->advertising & ADVERTISED_10baseT_Half)
1240 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10HALF;
1241 if (bp->advertising & ADVERTISED_10baseT_Full)
1242 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_10FULL;
1243 if (bp->advertising & ADVERTISED_100baseT_Half)
1244 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100HALF;
1245 if (bp->advertising & ADVERTISED_100baseT_Full)
1246 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_100FULL;
1247 if (bp->advertising & ADVERTISED_1000baseT_Full)
1248 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
1249 if (bp->advertising & ADVERTISED_2500baseX_Full)
1250 speed_arg |= BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
1251 } else {
1252 if (bp->req_line_speed == SPEED_2500)
1253 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_2G5FULL;
1254 else if (bp->req_line_speed == SPEED_1000)
1255 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_1GFULL;
1256 else if (bp->req_line_speed == SPEED_100) {
1257 if (bp->req_duplex == DUPLEX_FULL)
1258 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100FULL;
1259 else
1260 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_100HALF;
1261 } else if (bp->req_line_speed == SPEED_10) {
1262 if (bp->req_duplex == DUPLEX_FULL)
1263 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10FULL;
1264 else
1265 speed_arg = BNX2_NETLINK_SET_LINK_SPEED_10HALF;
1266 }
1267 }
1268
1269 if (pause_adv & (ADVERTISE_1000XPAUSE | ADVERTISE_PAUSE_CAP))
1270 speed_arg |= BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE;
1271 if (pause_adv & (ADVERTISE_1000XPSE_ASYM | ADVERTISE_1000XPSE_ASYM))
1272 speed_arg |= BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE;
1273
1274 if (port == PORT_TP)
1275 speed_arg |= BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE |
1276 BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED;
1277
1278 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB_ARG0, speed_arg);
1279
1280 spin_unlock_bh(&bp->phy_lock);
1281 bnx2_fw_sync(bp, BNX2_DRV_MSG_CODE_CMD_SET_LINK, 0);
1282 spin_lock_bh(&bp->phy_lock);
1283
1284 return 0;
1285}
1286
1287static int
1288bnx2_setup_serdes_phy(struct bnx2 *bp, u8 port)
1215{ 1289{
1216 u32 adv, bmcr; 1290 u32 adv, bmcr;
1217 u32 new_adv = 0; 1291 u32 new_adv = 0;
1218 1292
1293 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1294 return (bnx2_setup_remote_phy(bp, port));
1295
1219 if (!(bp->autoneg & AUTONEG_SPEED)) { 1296 if (!(bp->autoneg & AUTONEG_SPEED)) {
1220 u32 new_bmcr; 1297 u32 new_bmcr;
1221 int force_link_down = 0; 1298 int force_link_down = 0;
@@ -1323,7 +1400,9 @@ bnx2_setup_serdes_phy(struct bnx2 *bp)
1323} 1400}
1324 1401
1325#define ETHTOOL_ALL_FIBRE_SPEED \ 1402#define ETHTOOL_ALL_FIBRE_SPEED \
1326 (ADVERTISED_1000baseT_Full) 1403 (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) ? \
1404 (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
1405 (ADVERTISED_1000baseT_Full)
1327 1406
1328#define ETHTOOL_ALL_COPPER_SPEED \ 1407#define ETHTOOL_ALL_COPPER_SPEED \
1329 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \ 1408 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
@@ -1335,6 +1414,188 @@ bnx2_setup_serdes_phy(struct bnx2 *bp)
1335 1414
1336#define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL) 1415#define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
1337 1416
1417static void
1418bnx2_set_default_remote_link(struct bnx2 *bp)
1419{
1420 u32 link;
1421
1422 if (bp->phy_port == PORT_TP)
1423 link = REG_RD_IND(bp, bp->shmem_base + BNX2_RPHY_COPPER_LINK);
1424 else
1425 link = REG_RD_IND(bp, bp->shmem_base + BNX2_RPHY_SERDES_LINK);
1426
1427 if (link & BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG) {
1428 bp->req_line_speed = 0;
1429 bp->autoneg |= AUTONEG_SPEED;
1430 bp->advertising = ADVERTISED_Autoneg;
1431 if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
1432 bp->advertising |= ADVERTISED_10baseT_Half;
1433 if (link & BNX2_NETLINK_SET_LINK_SPEED_10FULL)
1434 bp->advertising |= ADVERTISED_10baseT_Full;
1435 if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
1436 bp->advertising |= ADVERTISED_100baseT_Half;
1437 if (link & BNX2_NETLINK_SET_LINK_SPEED_100FULL)
1438 bp->advertising |= ADVERTISED_100baseT_Full;
1439 if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
1440 bp->advertising |= ADVERTISED_1000baseT_Full;
1441 if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
1442 bp->advertising |= ADVERTISED_2500baseX_Full;
1443 } else {
1444 bp->autoneg = 0;
1445 bp->advertising = 0;
1446 bp->req_duplex = DUPLEX_FULL;
1447 if (link & BNX2_NETLINK_SET_LINK_SPEED_10) {
1448 bp->req_line_speed = SPEED_10;
1449 if (link & BNX2_NETLINK_SET_LINK_SPEED_10HALF)
1450 bp->req_duplex = DUPLEX_HALF;
1451 }
1452 if (link & BNX2_NETLINK_SET_LINK_SPEED_100) {
1453 bp->req_line_speed = SPEED_100;
1454 if (link & BNX2_NETLINK_SET_LINK_SPEED_100HALF)
1455 bp->req_duplex = DUPLEX_HALF;
1456 }
1457 if (link & BNX2_NETLINK_SET_LINK_SPEED_1GFULL)
1458 bp->req_line_speed = SPEED_1000;
1459 if (link & BNX2_NETLINK_SET_LINK_SPEED_2G5FULL)
1460 bp->req_line_speed = SPEED_2500;
1461 }
1462}
1463
1464static void
1465bnx2_set_default_link(struct bnx2 *bp)
1466{
1467 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1468 return bnx2_set_default_remote_link(bp);
1469
1470 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
1471 bp->req_line_speed = 0;
1472 if (bp->phy_flags & PHY_SERDES_FLAG) {
1473 u32 reg;
1474
1475 bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
1476
1477 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
1478 reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
1479 if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
1480 bp->autoneg = 0;
1481 bp->req_line_speed = bp->line_speed = SPEED_1000;
1482 bp->req_duplex = DUPLEX_FULL;
1483 }
1484 } else
1485 bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
1486}
1487
1488static void
1489bnx2_send_heart_beat(struct bnx2 *bp)
1490{
1491 u32 msg;
1492 u32 addr;
1493
1494 spin_lock(&bp->indirect_lock);
1495 msg = (u32) (++bp->fw_drv_pulse_wr_seq & BNX2_DRV_PULSE_SEQ_MASK);
1496 addr = bp->shmem_base + BNX2_DRV_PULSE_MB;
1497 REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, addr);
1498 REG_WR(bp, BNX2_PCICFG_REG_WINDOW, msg);
1499 spin_unlock(&bp->indirect_lock);
1500}
1501
1502static void
1503bnx2_remote_phy_event(struct bnx2 *bp)
1504{
1505 u32 msg;
1506 u8 link_up = bp->link_up;
1507 u8 old_port;
1508
1509 msg = REG_RD_IND(bp, bp->shmem_base + BNX2_LINK_STATUS);
1510
1511 if (msg & BNX2_LINK_STATUS_HEART_BEAT_EXPIRED)
1512 bnx2_send_heart_beat(bp);
1513
1514 msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
1515
1516 if ((msg & BNX2_LINK_STATUS_LINK_UP) == BNX2_LINK_STATUS_LINK_DOWN)
1517 bp->link_up = 0;
1518 else {
1519 u32 speed;
1520
1521 bp->link_up = 1;
1522 speed = msg & BNX2_LINK_STATUS_SPEED_MASK;
1523 bp->duplex = DUPLEX_FULL;
1524 switch (speed) {
1525 case BNX2_LINK_STATUS_10HALF:
1526 bp->duplex = DUPLEX_HALF;
1527 case BNX2_LINK_STATUS_10FULL:
1528 bp->line_speed = SPEED_10;
1529 break;
1530 case BNX2_LINK_STATUS_100HALF:
1531 bp->duplex = DUPLEX_HALF;
1532 case BNX2_LINK_STATUS_100BASE_T4:
1533 case BNX2_LINK_STATUS_100FULL:
1534 bp->line_speed = SPEED_100;
1535 break;
1536 case BNX2_LINK_STATUS_1000HALF:
1537 bp->duplex = DUPLEX_HALF;
1538 case BNX2_LINK_STATUS_1000FULL:
1539 bp->line_speed = SPEED_1000;
1540 break;
1541 case BNX2_LINK_STATUS_2500HALF:
1542 bp->duplex = DUPLEX_HALF;
1543 case BNX2_LINK_STATUS_2500FULL:
1544 bp->line_speed = SPEED_2500;
1545 break;
1546 default:
1547 bp->line_speed = 0;
1548 break;
1549 }
1550
1551 spin_lock(&bp->phy_lock);
1552 bp->flow_ctrl = 0;
1553 if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
1554 (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
1555 if (bp->duplex == DUPLEX_FULL)
1556 bp->flow_ctrl = bp->req_flow_ctrl;
1557 } else {
1558 if (msg & BNX2_LINK_STATUS_TX_FC_ENABLED)
1559 bp->flow_ctrl |= FLOW_CTRL_TX;
1560 if (msg & BNX2_LINK_STATUS_RX_FC_ENABLED)
1561 bp->flow_ctrl |= FLOW_CTRL_RX;
1562 }
1563
1564 old_port = bp->phy_port;
1565 if (msg & BNX2_LINK_STATUS_SERDES_LINK)
1566 bp->phy_port = PORT_FIBRE;
1567 else
1568 bp->phy_port = PORT_TP;
1569
1570 if (old_port != bp->phy_port)
1571 bnx2_set_default_link(bp);
1572
1573 spin_unlock(&bp->phy_lock);
1574 }
1575 if (bp->link_up != link_up)
1576 bnx2_report_link(bp);
1577
1578 bnx2_set_mac_link(bp);
1579}
1580
1581static int
1582bnx2_set_remote_link(struct bnx2 *bp)
1583{
1584 u32 evt_code;
1585
1586 evt_code = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_EVT_CODE_MB);
1587 switch (evt_code) {
1588 case BNX2_FW_EVT_CODE_LINK_EVENT:
1589 bnx2_remote_phy_event(bp);
1590 break;
1591 case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT:
1592 default:
1593 bnx2_send_heart_beat(bp);
1594 break;
1595 }
1596 return 0;
1597}
1598
1338static int 1599static int
1339bnx2_setup_copper_phy(struct bnx2 *bp) 1600bnx2_setup_copper_phy(struct bnx2 *bp)
1340{ 1601{
@@ -1433,13 +1694,13 @@ bnx2_setup_copper_phy(struct bnx2 *bp)
1433} 1694}
1434 1695
1435static int 1696static int
1436bnx2_setup_phy(struct bnx2 *bp) 1697bnx2_setup_phy(struct bnx2 *bp, u8 port)
1437{ 1698{
1438 if (bp->loopback == MAC_LOOPBACK) 1699 if (bp->loopback == MAC_LOOPBACK)
1439 return 0; 1700 return 0;
1440 1701
1441 if (bp->phy_flags & PHY_SERDES_FLAG) { 1702 if (bp->phy_flags & PHY_SERDES_FLAG) {
1442 return (bnx2_setup_serdes_phy(bp)); 1703 return (bnx2_setup_serdes_phy(bp, port));
1443 } 1704 }
1444 else { 1705 else {
1445 return (bnx2_setup_copper_phy(bp)); 1706 return (bnx2_setup_copper_phy(bp));
@@ -1659,6 +1920,9 @@ bnx2_init_phy(struct bnx2 *bp)
1659 1920
1660 REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK); 1921 REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
1661 1922
1923 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
1924 goto setup_phy;
1925
1662 bnx2_read_phy(bp, MII_PHYSID1, &val); 1926 bnx2_read_phy(bp, MII_PHYSID1, &val);
1663 bp->phy_id = val << 16; 1927 bp->phy_id = val << 16;
1664 bnx2_read_phy(bp, MII_PHYSID2, &val); 1928 bnx2_read_phy(bp, MII_PHYSID2, &val);
@@ -1676,7 +1940,9 @@ bnx2_init_phy(struct bnx2 *bp)
1676 rc = bnx2_init_copper_phy(bp); 1940 rc = bnx2_init_copper_phy(bp);
1677 } 1941 }
1678 1942
1679 bnx2_setup_phy(bp); 1943setup_phy:
1944 if (!rc)
1945 rc = bnx2_setup_phy(bp, bp->phy_port);
1680 1946
1681 return rc; 1947 return rc;
1682} 1948}
@@ -1984,6 +2250,9 @@ bnx2_phy_int(struct bnx2 *bp)
1984 bnx2_set_link(bp); 2250 bnx2_set_link(bp);
1985 spin_unlock(&bp->phy_lock); 2251 spin_unlock(&bp->phy_lock);
1986 } 2252 }
2253 if (bnx2_phy_event_is_set(bp, STATUS_ATTN_BITS_TIMER_ABORT))
2254 bnx2_set_remote_link(bp);
2255
1987} 2256}
1988 2257
1989static void 2258static void
@@ -2297,6 +2566,7 @@ bnx2_interrupt(int irq, void *dev_instance)
2297{ 2566{
2298 struct net_device *dev = dev_instance; 2567 struct net_device *dev = dev_instance;
2299 struct bnx2 *bp = netdev_priv(dev); 2568 struct bnx2 *bp = netdev_priv(dev);
2569 struct status_block *sblk = bp->status_blk;
2300 2570
2301 /* When using INTx, it is possible for the interrupt to arrive 2571 /* When using INTx, it is possible for the interrupt to arrive
2302 * at the CPU before the status block posted prior to the 2572 * at the CPU before the status block posted prior to the
@@ -2304,7 +2574,7 @@ bnx2_interrupt(int irq, void *dev_instance)
2304 * When using MSI, the MSI message will always complete after 2574 * When using MSI, the MSI message will always complete after
2305 * the status block write. 2575 * the status block write.
2306 */ 2576 */
2307 if ((bp->status_blk->status_idx == bp->last_status_idx) && 2577 if ((sblk->status_idx == bp->last_status_idx) &&
2308 (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) & 2578 (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
2309 BNX2_PCICFG_MISC_STATUS_INTA_VALUE)) 2579 BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
2310 return IRQ_NONE; 2580 return IRQ_NONE;
@@ -2313,16 +2583,25 @@ bnx2_interrupt(int irq, void *dev_instance)
2313 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM | 2583 BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
2314 BNX2_PCICFG_INT_ACK_CMD_MASK_INT); 2584 BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
2315 2585
2586 /* Read back to deassert IRQ immediately to avoid too many
2587 * spurious interrupts.
2588 */
2589 REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
2590
2316 /* Return here if interrupt is shared and is disabled. */ 2591 /* Return here if interrupt is shared and is disabled. */
2317 if (unlikely(atomic_read(&bp->intr_sem) != 0)) 2592 if (unlikely(atomic_read(&bp->intr_sem) != 0))
2318 return IRQ_HANDLED; 2593 return IRQ_HANDLED;
2319 2594
2320 netif_rx_schedule(dev); 2595 if (netif_rx_schedule_prep(dev)) {
2596 bp->last_status_idx = sblk->status_idx;
2597 __netif_rx_schedule(dev);
2598 }
2321 2599
2322 return IRQ_HANDLED; 2600 return IRQ_HANDLED;
2323} 2601}
2324 2602
2325#define STATUS_ATTN_EVENTS STATUS_ATTN_BITS_LINK_STATE 2603#define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
2604 STATUS_ATTN_BITS_TIMER_ABORT)
2326 2605
2327static inline int 2606static inline int
2328bnx2_has_work(struct bnx2 *bp) 2607bnx2_has_work(struct bnx2 *bp)
@@ -3562,6 +3841,36 @@ nvram_write_end:
3562 return rc; 3841 return rc;
3563} 3842}
3564 3843
3844static void
3845bnx2_init_remote_phy(struct bnx2 *bp)
3846{
3847 u32 val;
3848
3849 bp->phy_flags &= ~REMOTE_PHY_CAP_FLAG;
3850 if (!(bp->phy_flags & PHY_SERDES_FLAG))
3851 return;
3852
3853 val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_CAP_MB);
3854 if ((val & BNX2_FW_CAP_SIGNATURE_MASK) != BNX2_FW_CAP_SIGNATURE)
3855 return;
3856
3857 if (val & BNX2_FW_CAP_REMOTE_PHY_CAPABLE) {
3858 if (netif_running(bp->dev)) {
3859 val = BNX2_DRV_ACK_CAP_SIGNATURE |
3860 BNX2_FW_CAP_REMOTE_PHY_CAPABLE;
3861 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_ACK_CAP_MB,
3862 val);
3863 }
3864 bp->phy_flags |= REMOTE_PHY_CAP_FLAG;
3865
3866 val = REG_RD_IND(bp, bp->shmem_base + BNX2_LINK_STATUS);
3867 if (val & BNX2_LINK_STATUS_SERDES_LINK)
3868 bp->phy_port = PORT_FIBRE;
3869 else
3870 bp->phy_port = PORT_TP;
3871 }
3872}
3873
3565static int 3874static int
3566bnx2_reset_chip(struct bnx2 *bp, u32 reset_code) 3875bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
3567{ 3876{
@@ -3642,6 +3951,12 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
3642 if (rc) 3951 if (rc)
3643 return rc; 3952 return rc;
3644 3953
3954 spin_lock_bh(&bp->phy_lock);
3955 bnx2_init_remote_phy(bp);
3956 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
3957 bnx2_set_default_remote_link(bp);
3958 spin_unlock_bh(&bp->phy_lock);
3959
3645 if (CHIP_ID(bp) == CHIP_ID_5706_A0) { 3960 if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
3646 /* Adjust the voltage regular to two steps lower. The default 3961 /* Adjust the voltage regular to two steps lower. The default
3647 * of this register is 0x0000000e. */ 3962 * of this register is 0x0000000e. */
@@ -3826,7 +4141,7 @@ bnx2_init_chip(struct bnx2 *bp)
3826 rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET, 4141 rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
3827 0); 4142 0);
3828 4143
3829 REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff); 4144 REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, BNX2_MISC_ENABLE_DEFAULT);
3830 REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS); 4145 REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
3831 4146
3832 udelay(20); 4147 udelay(20);
@@ -4069,8 +4384,8 @@ bnx2_init_nic(struct bnx2 *bp)
4069 4384
4070 spin_lock_bh(&bp->phy_lock); 4385 spin_lock_bh(&bp->phy_lock);
4071 bnx2_init_phy(bp); 4386 bnx2_init_phy(bp);
4072 spin_unlock_bh(&bp->phy_lock);
4073 bnx2_set_link(bp); 4387 bnx2_set_link(bp);
4388 spin_unlock_bh(&bp->phy_lock);
4074 return 0; 4389 return 0;
4075} 4390}
4076 4391
@@ -4600,6 +4915,9 @@ bnx2_5706_serdes_timer(struct bnx2 *bp)
4600static void 4915static void
4601bnx2_5708_serdes_timer(struct bnx2 *bp) 4916bnx2_5708_serdes_timer(struct bnx2 *bp)
4602{ 4917{
4918 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
4919 return;
4920
4603 if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) { 4921 if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) {
4604 bp->serdes_an_pending = 0; 4922 bp->serdes_an_pending = 0;
4605 return; 4923 return;
@@ -4631,7 +4949,6 @@ static void
4631bnx2_timer(unsigned long data) 4949bnx2_timer(unsigned long data)
4632{ 4950{
4633 struct bnx2 *bp = (struct bnx2 *) data; 4951 struct bnx2 *bp = (struct bnx2 *) data;
4634 u32 msg;
4635 4952
4636 if (!netif_running(bp->dev)) 4953 if (!netif_running(bp->dev))
4637 return; 4954 return;
@@ -4639,8 +4956,7 @@ bnx2_timer(unsigned long data)
4639 if (atomic_read(&bp->intr_sem) != 0) 4956 if (atomic_read(&bp->intr_sem) != 0)
4640 goto bnx2_restart_timer; 4957 goto bnx2_restart_timer;
4641 4958
4642 msg = (u32) ++bp->fw_drv_pulse_wr_seq; 4959 bnx2_send_heart_beat(bp);
4643 REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
4644 4960
4645 bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT); 4961 bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
4646 4962
@@ -5083,17 +5399,25 @@ static int
5083bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 5399bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5084{ 5400{
5085 struct bnx2 *bp = netdev_priv(dev); 5401 struct bnx2 *bp = netdev_priv(dev);
5402 int support_serdes = 0, support_copper = 0;
5086 5403
5087 cmd->supported = SUPPORTED_Autoneg; 5404 cmd->supported = SUPPORTED_Autoneg;
5088 if (bp->phy_flags & PHY_SERDES_FLAG) { 5405 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
5406 support_serdes = 1;
5407 support_copper = 1;
5408 } else if (bp->phy_port == PORT_FIBRE)
5409 support_serdes = 1;
5410 else
5411 support_copper = 1;
5412
5413 if (support_serdes) {
5089 cmd->supported |= SUPPORTED_1000baseT_Full | 5414 cmd->supported |= SUPPORTED_1000baseT_Full |
5090 SUPPORTED_FIBRE; 5415 SUPPORTED_FIBRE;
5091 if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) 5416 if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
5092 cmd->supported |= SUPPORTED_2500baseX_Full; 5417 cmd->supported |= SUPPORTED_2500baseX_Full;
5093 5418
5094 cmd->port = PORT_FIBRE;
5095 } 5419 }
5096 else { 5420 if (support_copper) {
5097 cmd->supported |= SUPPORTED_10baseT_Half | 5421 cmd->supported |= SUPPORTED_10baseT_Half |
5098 SUPPORTED_10baseT_Full | 5422 SUPPORTED_10baseT_Full |
5099 SUPPORTED_100baseT_Half | 5423 SUPPORTED_100baseT_Half |
@@ -5101,9 +5425,10 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5101 SUPPORTED_1000baseT_Full | 5425 SUPPORTED_1000baseT_Full |
5102 SUPPORTED_TP; 5426 SUPPORTED_TP;
5103 5427
5104 cmd->port = PORT_TP;
5105 } 5428 }
5106 5429
5430 spin_lock_bh(&bp->phy_lock);
5431 cmd->port = bp->phy_port;
5107 cmd->advertising = bp->advertising; 5432 cmd->advertising = bp->advertising;
5108 5433
5109 if (bp->autoneg & AUTONEG_SPEED) { 5434 if (bp->autoneg & AUTONEG_SPEED) {
@@ -5121,6 +5446,7 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5121 cmd->speed = -1; 5446 cmd->speed = -1;
5122 cmd->duplex = -1; 5447 cmd->duplex = -1;
5123 } 5448 }
5449 spin_unlock_bh(&bp->phy_lock);
5124 5450
5125 cmd->transceiver = XCVR_INTERNAL; 5451 cmd->transceiver = XCVR_INTERNAL;
5126 cmd->phy_address = bp->phy_addr; 5452 cmd->phy_address = bp->phy_addr;
@@ -5136,6 +5462,15 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5136 u8 req_duplex = bp->req_duplex; 5462 u8 req_duplex = bp->req_duplex;
5137 u16 req_line_speed = bp->req_line_speed; 5463 u16 req_line_speed = bp->req_line_speed;
5138 u32 advertising = bp->advertising; 5464 u32 advertising = bp->advertising;
5465 int err = -EINVAL;
5466
5467 spin_lock_bh(&bp->phy_lock);
5468
5469 if (cmd->port != PORT_TP && cmd->port != PORT_FIBRE)
5470 goto err_out_unlock;
5471
5472 if (cmd->port != bp->phy_port && !(bp->phy_flags & REMOTE_PHY_CAP_FLAG))
5473 goto err_out_unlock;
5139 5474
5140 if (cmd->autoneg == AUTONEG_ENABLE) { 5475 if (cmd->autoneg == AUTONEG_ENABLE) {
5141 autoneg |= AUTONEG_SPEED; 5476 autoneg |= AUTONEG_SPEED;
@@ -5148,44 +5483,41 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5148 (cmd->advertising == ADVERTISED_100baseT_Half) || 5483 (cmd->advertising == ADVERTISED_100baseT_Half) ||
5149 (cmd->advertising == ADVERTISED_100baseT_Full)) { 5484 (cmd->advertising == ADVERTISED_100baseT_Full)) {
5150 5485
5151 if (bp->phy_flags & PHY_SERDES_FLAG) 5486 if (cmd->port == PORT_FIBRE)
5152 return -EINVAL; 5487 goto err_out_unlock;
5153 5488
5154 advertising = cmd->advertising; 5489 advertising = cmd->advertising;
5155 5490
5156 } else if (cmd->advertising == ADVERTISED_2500baseX_Full) { 5491 } else if (cmd->advertising == ADVERTISED_2500baseX_Full) {
5157 if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)) 5492 if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) ||
5158 return -EINVAL; 5493 (cmd->port == PORT_TP))
5159 } else if (cmd->advertising == ADVERTISED_1000baseT_Full) { 5494 goto err_out_unlock;
5495 } else if (cmd->advertising == ADVERTISED_1000baseT_Full)
5160 advertising = cmd->advertising; 5496 advertising = cmd->advertising;
5161 } 5497 else if (cmd->advertising == ADVERTISED_1000baseT_Half)
5162 else if (cmd->advertising == ADVERTISED_1000baseT_Half) { 5498 goto err_out_unlock;
5163 return -EINVAL;
5164 }
5165 else { 5499 else {
5166 if (bp->phy_flags & PHY_SERDES_FLAG) { 5500 if (cmd->port == PORT_FIBRE)
5167 advertising = ETHTOOL_ALL_FIBRE_SPEED; 5501 advertising = ETHTOOL_ALL_FIBRE_SPEED;
5168 } 5502 else
5169 else {
5170 advertising = ETHTOOL_ALL_COPPER_SPEED; 5503 advertising = ETHTOOL_ALL_COPPER_SPEED;
5171 }
5172 } 5504 }
5173 advertising |= ADVERTISED_Autoneg; 5505 advertising |= ADVERTISED_Autoneg;
5174 } 5506 }
5175 else { 5507 else {
5176 if (bp->phy_flags & PHY_SERDES_FLAG) { 5508 if (cmd->port == PORT_FIBRE) {
5177 if ((cmd->speed != SPEED_1000 && 5509 if ((cmd->speed != SPEED_1000 &&
5178 cmd->speed != SPEED_2500) || 5510 cmd->speed != SPEED_2500) ||
5179 (cmd->duplex != DUPLEX_FULL)) 5511 (cmd->duplex != DUPLEX_FULL))
5180 return -EINVAL; 5512 goto err_out_unlock;
5181 5513
5182 if (cmd->speed == SPEED_2500 && 5514 if (cmd->speed == SPEED_2500 &&
5183 !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)) 5515 !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
5184 return -EINVAL; 5516 goto err_out_unlock;
5185 }
5186 else if (cmd->speed == SPEED_1000) {
5187 return -EINVAL;
5188 } 5517 }
5518 else if (cmd->speed == SPEED_1000 || cmd->speed == SPEED_2500)
5519 goto err_out_unlock;
5520
5189 autoneg &= ~AUTONEG_SPEED; 5521 autoneg &= ~AUTONEG_SPEED;
5190 req_line_speed = cmd->speed; 5522 req_line_speed = cmd->speed;
5191 req_duplex = cmd->duplex; 5523 req_duplex = cmd->duplex;
@@ -5197,13 +5529,12 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
5197 bp->req_line_speed = req_line_speed; 5529 bp->req_line_speed = req_line_speed;
5198 bp->req_duplex = req_duplex; 5530 bp->req_duplex = req_duplex;
5199 5531
5200 spin_lock_bh(&bp->phy_lock); 5532 err = bnx2_setup_phy(bp, cmd->port);
5201
5202 bnx2_setup_phy(bp);
5203 5533
5534err_out_unlock:
5204 spin_unlock_bh(&bp->phy_lock); 5535 spin_unlock_bh(&bp->phy_lock);
5205 5536
5206 return 0; 5537 return err;
5207} 5538}
5208 5539
5209static void 5540static void
@@ -5214,11 +5545,7 @@ bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
5214 strcpy(info->driver, DRV_MODULE_NAME); 5545 strcpy(info->driver, DRV_MODULE_NAME);
5215 strcpy(info->version, DRV_MODULE_VERSION); 5546 strcpy(info->version, DRV_MODULE_VERSION);
5216 strcpy(info->bus_info, pci_name(bp->pdev)); 5547 strcpy(info->bus_info, pci_name(bp->pdev));
5217 info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0'; 5548 strcpy(info->fw_version, bp->fw_version);
5218 info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
5219 info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
5220 info->fw_version[1] = info->fw_version[3] = '.';
5221 info->fw_version[5] = 0;
5222} 5549}
5223 5550
5224#define BNX2_REGDUMP_LEN (32 * 1024) 5551#define BNX2_REGDUMP_LEN (32 * 1024)
@@ -5330,6 +5657,14 @@ bnx2_nway_reset(struct net_device *dev)
5330 5657
5331 spin_lock_bh(&bp->phy_lock); 5658 spin_lock_bh(&bp->phy_lock);
5332 5659
5660 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
5661 int rc;
5662
5663 rc = bnx2_setup_remote_phy(bp, bp->phy_port);
5664 spin_unlock_bh(&bp->phy_lock);
5665 return rc;
5666 }
5667
5333 /* Force a link down visible on the other side */ 5668 /* Force a link down visible on the other side */
5334 if (bp->phy_flags & PHY_SERDES_FLAG) { 5669 if (bp->phy_flags & PHY_SERDES_FLAG) {
5335 bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK); 5670 bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
@@ -5543,7 +5878,7 @@ bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
5543 5878
5544 spin_lock_bh(&bp->phy_lock); 5879 spin_lock_bh(&bp->phy_lock);
5545 5880
5546 bnx2_setup_phy(bp); 5881 bnx2_setup_phy(bp, bp->phy_port);
5547 5882
5548 spin_unlock_bh(&bp->phy_lock); 5883 spin_unlock_bh(&bp->phy_lock);
5549 5884
@@ -5939,6 +6274,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5939 case SIOCGMIIREG: { 6274 case SIOCGMIIREG: {
5940 u32 mii_regval; 6275 u32 mii_regval;
5941 6276
6277 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
6278 return -EOPNOTSUPP;
6279
5942 if (!netif_running(dev)) 6280 if (!netif_running(dev))
5943 return -EAGAIN; 6281 return -EAGAIN;
5944 6282
@@ -5955,6 +6293,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
5955 if (!capable(CAP_NET_ADMIN)) 6293 if (!capable(CAP_NET_ADMIN))
5956 return -EPERM; 6294 return -EPERM;
5957 6295
6296 if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
6297 return -EOPNOTSUPP;
6298
5958 if (!netif_running(dev)) 6299 if (!netif_running(dev))
5959 return -EAGAIN; 6300 return -EAGAIN;
5960 6301
@@ -6116,7 +6457,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6116{ 6457{
6117 struct bnx2 *bp; 6458 struct bnx2 *bp;
6118 unsigned long mem_len; 6459 unsigned long mem_len;
6119 int rc; 6460 int rc, i, j;
6120 u32 reg; 6461 u32 reg;
6121 u64 dma_mask, persist_dma_mask; 6462 u64 dma_mask, persist_dma_mask;
6122 6463
@@ -6273,7 +6614,35 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6273 goto err_out_unmap; 6614 goto err_out_unmap;
6274 } 6615 }
6275 6616
6276 bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV); 6617 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
6618 for (i = 0, j = 0; i < 3; i++) {
6619 u8 num, k, skip0;
6620
6621 num = (u8) (reg >> (24 - (i * 8)));
6622 for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
6623 if (num >= k || !skip0 || k == 1) {
6624 bp->fw_version[j++] = (num / k) + '0';
6625 skip0 = 0;
6626 }
6627 }
6628 if (i != 2)
6629 bp->fw_version[j++] = '.';
6630 }
6631 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_BC_STATE_CONDITION);
6632 reg &= BNX2_CONDITION_MFW_RUN_MASK;
6633 if (reg != BNX2_CONDITION_MFW_RUN_UNKNOWN &&
6634 reg != BNX2_CONDITION_MFW_RUN_NONE) {
6635 int i;
6636 u32 addr = REG_RD_IND(bp, bp->shmem_base + BNX2_MFW_VER_PTR);
6637
6638 bp->fw_version[j++] = ' ';
6639 for (i = 0; i < 3; i++) {
6640 reg = REG_RD_IND(bp, addr + i * 4);
6641 reg = swab32(reg);
6642 memcpy(&bp->fw_version[j], &reg, 4);
6643 j += 4;
6644 }
6645 }
6277 6646
6278 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER); 6647 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
6279 bp->mac_addr[0] = (u8) (reg >> 8); 6648 bp->mac_addr[0] = (u8) (reg >> 8);
@@ -6315,7 +6684,9 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6315 else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) 6684 else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
6316 bp->phy_flags |= PHY_SERDES_FLAG; 6685 bp->phy_flags |= PHY_SERDES_FLAG;
6317 6686
6687 bp->phy_port = PORT_TP;
6318 if (bp->phy_flags & PHY_SERDES_FLAG) { 6688 if (bp->phy_flags & PHY_SERDES_FLAG) {
6689 bp->phy_port = PORT_FIBRE;
6319 bp->flags |= NO_WOL_FLAG; 6690 bp->flags |= NO_WOL_FLAG;
6320 if (CHIP_NUM(bp) != CHIP_NUM_5706) { 6691 if (CHIP_NUM(bp) != CHIP_NUM_5706) {
6321 bp->phy_addr = 2; 6692 bp->phy_addr = 2;
@@ -6324,6 +6695,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6324 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G) 6695 if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
6325 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG; 6696 bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
6326 } 6697 }
6698 bnx2_init_remote_phy(bp);
6699
6327 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 || 6700 } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
6328 CHIP_NUM(bp) == CHIP_NUM_5708) 6701 CHIP_NUM(bp) == CHIP_NUM_5708)
6329 bp->phy_flags |= PHY_CRC_FIX_FLAG; 6702 bp->phy_flags |= PHY_CRC_FIX_FLAG;
@@ -6373,23 +6746,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
6373 } 6746 }
6374 } 6747 }
6375 6748
6376 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL; 6749 bnx2_set_default_link(bp);
6377 bp->req_line_speed = 0;
6378 if (bp->phy_flags & PHY_SERDES_FLAG) {
6379 bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
6380
6381 reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
6382 reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
6383 if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
6384 bp->autoneg = 0;
6385 bp->req_line_speed = bp->line_speed = SPEED_1000;
6386 bp->req_duplex = DUPLEX_FULL;
6387 }
6388 }
6389 else {
6390 bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
6391 }
6392
6393 bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX; 6750 bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
6394 6751
6395 init_timer(&bp->timer); 6752 init_timer(&bp->timer);
@@ -6489,10 +6846,10 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
6489 memcpy(dev->perm_addr, bp->mac_addr, 6); 6846 memcpy(dev->perm_addr, bp->mac_addr, 6);
6490 bp->name = board_info[ent->driver_data].name; 6847 bp->name = board_info[ent->driver_data].name;
6491 6848
6849 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
6492 if (CHIP_NUM(bp) == CHIP_NUM_5709) 6850 if (CHIP_NUM(bp) == CHIP_NUM_5709)
6493 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG; 6851 dev->features |= NETIF_F_IPV6_CSUM;
6494 else 6852
6495 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
6496#ifdef BCM_VLAN 6853#ifdef BCM_VLAN
6497 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; 6854 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
6498#endif 6855#endif
diff --git a/drivers/net/bnx2.h b/drivers/net/bnx2.h
index 49a5de253b17..d8cd1afeb23d 100644
--- a/drivers/net/bnx2.h
+++ b/drivers/net/bnx2.h
@@ -6338,6 +6338,8 @@ struct l2_fhdr {
6338 6338
6339#define RX_COPY_THRESH 92 6339#define RX_COPY_THRESH 92
6340 6340
6341#define BNX2_MISC_ENABLE_DEFAULT 0x7ffffff
6342
6341#define DMA_READ_CHANS 5 6343#define DMA_READ_CHANS 5
6342#define DMA_WRITE_CHANS 3 6344#define DMA_WRITE_CHANS 3
6343 6345
@@ -6537,6 +6539,7 @@ struct bnx2 {
6537#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100 6539#define PHY_INT_MODE_AUTO_POLLING_FLAG 0x100
6538#define PHY_INT_MODE_LINK_READY_FLAG 0x200 6540#define PHY_INT_MODE_LINK_READY_FLAG 0x200
6539#define PHY_DIS_EARLY_DAC_FLAG 0x400 6541#define PHY_DIS_EARLY_DAC_FLAG 0x400
6542#define REMOTE_PHY_CAP_FLAG 0x800
6540 6543
6541 u32 mii_bmcr; 6544 u32 mii_bmcr;
6542 u32 mii_bmsr; 6545 u32 mii_bmsr;
@@ -6625,6 +6628,7 @@ struct bnx2 {
6625 u16 req_line_speed; 6628 u16 req_line_speed;
6626 u8 req_duplex; 6629 u8 req_duplex;
6627 6630
6631 u8 phy_port;
6628 u8 link_up; 6632 u8 link_up;
6629 6633
6630 u16 line_speed; 6634 u16 line_speed;
@@ -6656,7 +6660,7 @@ struct bnx2 {
6656 6660
6657 u32 shmem_base; 6661 u32 shmem_base;
6658 6662
6659 u32 fw_ver; 6663 char fw_version[32];
6660 6664
6661 int pm_cap; 6665 int pm_cap;
6662 int pcix_cap; 6666 int pcix_cap;
@@ -6770,7 +6774,7 @@ struct fw_info {
6770 * the firmware has timed out, the driver will assume there is no firmware 6774 * the firmware has timed out, the driver will assume there is no firmware
6771 * running and there won't be any firmware-driver synchronization during a 6775 * running and there won't be any firmware-driver synchronization during a
6772 * driver reset. */ 6776 * driver reset. */
6773#define FW_ACK_TIME_OUT_MS 100 6777#define FW_ACK_TIME_OUT_MS 1000
6774 6778
6775 6779
6776#define BNX2_DRV_RESET_SIGNATURE 0x00000000 6780#define BNX2_DRV_RESET_SIGNATURE 0x00000000
@@ -6788,6 +6792,7 @@ struct fw_info {
6788#define BNX2_DRV_MSG_CODE_DIAG 0x07000000 6792#define BNX2_DRV_MSG_CODE_DIAG 0x07000000
6789#define BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL 0x09000000 6793#define BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL 0x09000000
6790#define BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN 0x0b000000 6794#define BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN 0x0b000000
6795#define BNX2_DRV_MSG_CODE_CMD_SET_LINK 0x10000000
6791 6796
6792#define BNX2_DRV_MSG_DATA 0x00ff0000 6797#define BNX2_DRV_MSG_DATA 0x00ff0000
6793#define BNX2_DRV_MSG_DATA_WAIT0 0x00010000 6798#define BNX2_DRV_MSG_DATA_WAIT0 0x00010000
@@ -6836,6 +6841,7 @@ struct fw_info {
6836#define BNX2_LINK_STATUS_SERDES_LINK (1<<20) 6841#define BNX2_LINK_STATUS_SERDES_LINK (1<<20)
6837#define BNX2_LINK_STATUS_PARTNER_AD_2500FULL (1<<21) 6842#define BNX2_LINK_STATUS_PARTNER_AD_2500FULL (1<<21)
6838#define BNX2_LINK_STATUS_PARTNER_AD_2500HALF (1<<22) 6843#define BNX2_LINK_STATUS_PARTNER_AD_2500HALF (1<<22)
6844#define BNX2_LINK_STATUS_HEART_BEAT_EXPIRED (1<<31)
6839 6845
6840#define BNX2_DRV_PULSE_MB 0x00000010 6846#define BNX2_DRV_PULSE_MB 0x00000010
6841#define BNX2_DRV_PULSE_SEQ_MASK 0x00007fff 6847#define BNX2_DRV_PULSE_SEQ_MASK 0x00007fff
@@ -6845,6 +6851,30 @@ struct fw_info {
6845 * This is used for debugging. */ 6851 * This is used for debugging. */
6846#define BNX2_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE 0x00080000 6852#define BNX2_DRV_MSG_DATA_PULSE_CODE_ALWAYS_ALIVE 0x00080000
6847 6853
6854#define BNX2_DRV_MB_ARG0 0x00000014
6855#define BNX2_NETLINK_SET_LINK_SPEED_10HALF (1<<0)
6856#define BNX2_NETLINK_SET_LINK_SPEED_10FULL (1<<1)
6857#define BNX2_NETLINK_SET_LINK_SPEED_10 \
6858 (BNX2_NETLINK_SET_LINK_SPEED_10HALF | \
6859 BNX2_NETLINK_SET_LINK_SPEED_10FULL)
6860#define BNX2_NETLINK_SET_LINK_SPEED_100HALF (1<<2)
6861#define BNX2_NETLINK_SET_LINK_SPEED_100FULL (1<<3)
6862#define BNX2_NETLINK_SET_LINK_SPEED_100 \
6863 (BNX2_NETLINK_SET_LINK_SPEED_100HALF | \
6864 BNX2_NETLINK_SET_LINK_SPEED_100FULL)
6865#define BNX2_NETLINK_SET_LINK_SPEED_1GHALF (1<<4)
6866#define BNX2_NETLINK_SET_LINK_SPEED_1GFULL (1<<5)
6867#define BNX2_NETLINK_SET_LINK_SPEED_2G5HALF (1<<6)
6868#define BNX2_NETLINK_SET_LINK_SPEED_2G5FULL (1<<7)
6869#define BNX2_NETLINK_SET_LINK_SPEED_10GHALF (1<<8)
6870#define BNX2_NETLINK_SET_LINK_SPEED_10GFULL (1<<9)
6871#define BNX2_NETLINK_SET_LINK_ENABLE_AUTONEG (1<<10)
6872#define BNX2_NETLINK_SET_LINK_PHY_APP_REMOTE (1<<11)
6873#define BNX2_NETLINK_SET_LINK_FC_SYM_PAUSE (1<<12)
6874#define BNX2_NETLINK_SET_LINK_FC_ASYM_PAUSE (1<<13)
6875#define BNX2_NETLINK_SET_LINK_ETH_AT_WIRESPEED (1<<14)
6876#define BNX2_NETLINK_SET_LINK_PHY_RESET (1<<15)
6877
6848#define BNX2_DEV_INFO_SIGNATURE 0x00000020 6878#define BNX2_DEV_INFO_SIGNATURE 0x00000020
6849#define BNX2_DEV_INFO_SIGNATURE_MAGIC 0x44564900 6879#define BNX2_DEV_INFO_SIGNATURE_MAGIC 0x44564900
6850#define BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK 0xffffff00 6880#define BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK 0xffffff00
@@ -7006,6 +7036,8 @@ struct fw_info {
7006#define BNX2_PORT_FEATURE_MBA_VLAN_TAG_MASK 0xffff 7036#define BNX2_PORT_FEATURE_MBA_VLAN_TAG_MASK 0xffff
7007#define BNX2_PORT_FEATURE_MBA_VLAN_ENABLE 0x10000 7037#define BNX2_PORT_FEATURE_MBA_VLAN_ENABLE 0x10000
7008 7038
7039#define BNX2_MFW_VER_PTR 0x00000014c
7040
7009#define BNX2_BC_STATE_RESET_TYPE 0x000001c0 7041#define BNX2_BC_STATE_RESET_TYPE 0x000001c0
7010#define BNX2_BC_STATE_RESET_TYPE_SIG 0x00005254 7042#define BNX2_BC_STATE_RESET_TYPE_SIG 0x00005254
7011#define BNX2_BC_STATE_RESET_TYPE_SIG_MASK 0x0000ffff 7043#define BNX2_BC_STATE_RESET_TYPE_SIG_MASK 0x0000ffff
@@ -7059,12 +7091,42 @@ struct fw_info {
7059#define BNX2_BC_STATE_ERR_NO_RXP (BNX2_BC_STATE_SIGN | 0x0600) 7091#define BNX2_BC_STATE_ERR_NO_RXP (BNX2_BC_STATE_SIGN | 0x0600)
7060#define BNX2_BC_STATE_ERR_TOO_MANY_RBUF (BNX2_BC_STATE_SIGN | 0x0700) 7092#define BNX2_BC_STATE_ERR_TOO_MANY_RBUF (BNX2_BC_STATE_SIGN | 0x0700)
7061 7093
7094#define BNX2_BC_STATE_CONDITION 0x000001c8
7095#define BNX2_CONDITION_MFW_RUN_UNKNOWN 0x00000000
7096#define BNX2_CONDITION_MFW_RUN_IPMI 0x00002000
7097#define BNX2_CONDITION_MFW_RUN_UMP 0x00004000
7098#define BNX2_CONDITION_MFW_RUN_NCSI 0x00006000
7099#define BNX2_CONDITION_MFW_RUN_NONE 0x0000e000
7100#define BNX2_CONDITION_MFW_RUN_MASK 0x0000e000
7101
7062#define BNX2_BC_STATE_DEBUG_CMD 0x1dc 7102#define BNX2_BC_STATE_DEBUG_CMD 0x1dc
7063#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000 7103#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE 0x42440000
7064#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE_MASK 0xffff0000 7104#define BNX2_BC_STATE_BC_DBG_CMD_SIGNATURE_MASK 0xffff0000
7065#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_CNT_MASK 0xffff 7105#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_CNT_MASK 0xffff
7066#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_INFINITE 0xffff 7106#define BNX2_BC_STATE_BC_DBG_CMD_LOOP_INFINITE 0xffff
7067 7107
7108#define BNX2_FW_EVT_CODE_MB 0x354
7109#define BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT 0x00000000
7110#define BNX2_FW_EVT_CODE_LINK_EVENT 0x00000001
7111
7112#define BNX2_DRV_ACK_CAP_MB 0x364
7113#define BNX2_DRV_ACK_CAP_SIGNATURE 0x35450000
7114#define BNX2_CAPABILITY_SIGNATURE_MASK 0xFFFF0000
7115
7116#define BNX2_FW_CAP_MB 0x368
7117#define BNX2_FW_CAP_SIGNATURE 0xaa550000
7118#define BNX2_FW_ACK_DRV_SIGNATURE 0x52500000
7119#define BNX2_FW_CAP_SIGNATURE_MASK 0xffff0000
7120#define BNX2_FW_CAP_REMOTE_PHY_CAPABLE 0x00000001
7121#define BNX2_FW_CAP_REMOTE_PHY_PRESENT 0x00000002
7122
7123#define BNX2_RPHY_SIGNATURE 0x36c
7124#define BNX2_RPHY_LOAD_SIGNATURE 0x5a5a5a5a
7125
7126#define BNX2_RPHY_FLAGS 0x370
7127#define BNX2_RPHY_SERDES_LINK 0x374
7128#define BNX2_RPHY_COPPER_LINK 0x378
7129
7068#define HOST_VIEW_SHMEM_BASE 0x167c00 7130#define HOST_VIEW_SHMEM_BASE 0x167c00
7069 7131
7070#endif 7132#endif
diff --git a/drivers/net/dl2k.c b/drivers/net/dl2k.c
index fab4fc9f7fd0..04e3710c9082 100644
--- a/drivers/net/dl2k.c
+++ b/drivers/net/dl2k.c
@@ -865,9 +865,9 @@ receive_packet (struct net_device *dev)
865 PCI_DMA_FROMDEVICE); 865 PCI_DMA_FROMDEVICE);
866 /* 16 byte align the IP header */ 866 /* 16 byte align the IP header */
867 skb_reserve (skb, 2); 867 skb_reserve (skb, 2);
868 eth_copy_and_sum (skb, 868 skb_copy_to_linear_data (skb,
869 np->rx_skbuff[entry]->data, 869 np->rx_skbuff[entry]->data,
870 pkt_len, 0); 870 pkt_len);
871 skb_put (skb, pkt_len); 871 skb_put (skb, pkt_len);
872 pci_dma_sync_single_for_device(np->pdev, 872 pci_dma_sync_single_for_device(np->pdev,
873 desc->fraginfo & 873 desc->fraginfo &
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 264fa0e2e075..c3de81bf090a 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -104,6 +104,18 @@
104#define PRINTK(args...) printk(KERN_DEBUG args) 104#define PRINTK(args...) printk(KERN_DEBUG args)
105#endif 105#endif
106 106
107#ifdef CONFIG_BLACKFIN
108#define readsb insb
109#define readsw insw
110#define readsl insl
111#define writesb outsb
112#define writesw outsw
113#define writesl outsl
114#define DM9000_IRQ_FLAGS (IRQF_SHARED | IRQF_TRIGGER_HIGH)
115#else
116#define DM9000_IRQ_FLAGS IRQF_SHARED
117#endif
118
107/* 119/*
108 * Transmit timeout, default 5 seconds. 120 * Transmit timeout, default 5 seconds.
109 */ 121 */
@@ -431,6 +443,9 @@ dm9000_probe(struct platform_device *pdev)
431 db->io_addr = (void __iomem *)base; 443 db->io_addr = (void __iomem *)base;
432 db->io_data = (void __iomem *)(base + 4); 444 db->io_data = (void __iomem *)(base + 4);
433 445
446 /* ensure at least we have a default set of IO routines */
447 dm9000_set_io(db, 2);
448
434 } else { 449 } else {
435 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 450 db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
436 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 451 db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -614,7 +629,7 @@ dm9000_open(struct net_device *dev)
614 629
615 PRINTK2("entering dm9000_open\n"); 630 PRINTK2("entering dm9000_open\n");
616 631
617 if (request_irq(dev->irq, &dm9000_interrupt, IRQF_SHARED, dev->name, dev)) 632 if (request_irq(dev->irq, &dm9000_interrupt, DM9000_IRQ_FLAGS, dev->name, dev))
618 return -EAGAIN; 633 return -EAGAIN;
619 634
620 /* Initialize DM9000 board */ 635 /* Initialize DM9000 board */
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 60673bc292c0..756a6bcb038d 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -34,11 +34,12 @@
34#include <linux/etherdevice.h> 34#include <linux/etherdevice.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/moduleparam.h> 36#include <linux/moduleparam.h>
37#include <linux/rtnetlink.h>
38#include <net/rtnetlink.h>
37 39
38static int numdummies = 1; 40static int numdummies = 1;
39 41
40static int dummy_xmit(struct sk_buff *skb, struct net_device *dev); 42static int dummy_xmit(struct sk_buff *skb, struct net_device *dev);
41static struct net_device_stats *dummy_get_stats(struct net_device *dev);
42 43
43static int dummy_set_address(struct net_device *dev, void *p) 44static int dummy_set_address(struct net_device *dev, void *p)
44{ 45{
@@ -56,13 +57,13 @@ static void set_multicast_list(struct net_device *dev)
56{ 57{
57} 58}
58 59
59static void __init dummy_setup(struct net_device *dev) 60static void dummy_setup(struct net_device *dev)
60{ 61{
61 /* Initialize the device structure. */ 62 /* Initialize the device structure. */
62 dev->get_stats = dummy_get_stats;
63 dev->hard_start_xmit = dummy_xmit; 63 dev->hard_start_xmit = dummy_xmit;
64 dev->set_multicast_list = set_multicast_list; 64 dev->set_multicast_list = set_multicast_list;
65 dev->set_mac_address = dummy_set_address; 65 dev->set_mac_address = dummy_set_address;
66 dev->destructor = free_netdev;
66 67
67 /* Fill in device structure with ethernet-generic values. */ 68 /* Fill in device structure with ethernet-generic values. */
68 ether_setup(dev); 69 ether_setup(dev);
@@ -76,77 +77,80 @@ static void __init dummy_setup(struct net_device *dev)
76 77
77static int dummy_xmit(struct sk_buff *skb, struct net_device *dev) 78static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
78{ 79{
79 struct net_device_stats *stats = netdev_priv(dev); 80 dev->stats.tx_packets++;
80 81 dev->stats.tx_bytes += skb->len;
81 stats->tx_packets++;
82 stats->tx_bytes+=skb->len;
83 82
84 dev_kfree_skb(skb); 83 dev_kfree_skb(skb);
85 return 0; 84 return 0;
86} 85}
87 86
88static struct net_device_stats *dummy_get_stats(struct net_device *dev) 87static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
89{ 88{
90 return netdev_priv(dev); 89 if (tb[IFLA_ADDRESS]) {
90 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
91 return -EINVAL;
92 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
93 return -EADDRNOTAVAIL;
94 }
95 return 0;
91} 96}
92 97
93static struct net_device **dummies; 98static struct rtnl_link_ops dummy_link_ops __read_mostly = {
99 .kind = "dummy",
100 .setup = dummy_setup,
101 .validate = dummy_validate,
102};
94 103
95/* Number of dummy devices to be set up by this module. */ 104/* Number of dummy devices to be set up by this module. */
96module_param(numdummies, int, 0); 105module_param(numdummies, int, 0);
97MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices"); 106MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");
98 107
99static int __init dummy_init_one(int index) 108static int __init dummy_init_one(void)
100{ 109{
101 struct net_device *dev_dummy; 110 struct net_device *dev_dummy;
102 int err; 111 int err;
103 112
104 dev_dummy = alloc_netdev(sizeof(struct net_device_stats), 113 dev_dummy = alloc_netdev(0, "dummy%d", dummy_setup);
105 "dummy%d", dummy_setup);
106
107 if (!dev_dummy) 114 if (!dev_dummy)
108 return -ENOMEM; 115 return -ENOMEM;
109 116
110 if ((err = register_netdev(dev_dummy))) { 117 err = dev_alloc_name(dev_dummy, dev_dummy->name);
111 free_netdev(dev_dummy); 118 if (err < 0)
112 dev_dummy = NULL; 119 goto err;
113 } else {
114 dummies[index] = dev_dummy;
115 }
116 120
117 return err; 121 dev_dummy->rtnl_link_ops = &dummy_link_ops;
118} 122 err = register_netdevice(dev_dummy);
123 if (err < 0)
124 goto err;
125 return 0;
119 126
120static void dummy_free_one(int index) 127err:
121{ 128 free_netdev(dev_dummy);
122 unregister_netdev(dummies[index]); 129 return err;
123 free_netdev(dummies[index]);
124} 130}
125 131
126static int __init dummy_init_module(void) 132static int __init dummy_init_module(void)
127{ 133{
128 int i, err = 0; 134 int i, err = 0;
129 dummies = kmalloc(numdummies * sizeof(void *), GFP_KERNEL); 135
130 if (!dummies) 136 rtnl_lock();
131 return -ENOMEM; 137 err = __rtnl_link_register(&dummy_link_ops);
138
132 for (i = 0; i < numdummies && !err; i++) 139 for (i = 0; i < numdummies && !err; i++)
133 err = dummy_init_one(i); 140 err = dummy_init_one();
134 if (err) { 141 if (err < 0)
135 i--; 142 __rtnl_link_unregister(&dummy_link_ops);
136 while (--i >= 0) 143 rtnl_unlock();
137 dummy_free_one(i); 144
138 }
139 return err; 145 return err;
140} 146}
141 147
142static void __exit dummy_cleanup_module(void) 148static void __exit dummy_cleanup_module(void)
143{ 149{
144 int i; 150 rtnl_link_unregister(&dummy_link_ops);
145 for (i = 0; i < numdummies; i++)
146 dummy_free_one(i);
147 kfree(dummies);
148} 151}
149 152
150module_init(dummy_init_module); 153module_init(dummy_init_module);
151module_exit(dummy_cleanup_module); 154module_exit(dummy_cleanup_module);
152MODULE_LICENSE("GPL"); 155MODULE_LICENSE("GPL");
156MODULE_ALIAS_RTNL_LINK("dummy");
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 9800341956a2..9afa47edfc58 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -1801,7 +1801,7 @@ speedo_rx(struct net_device *dev)
1801 1801
1802#if 1 || USE_IP_CSUM 1802#if 1 || USE_IP_CSUM
1803 /* Packet is in one chunk -- we can copy + cksum. */ 1803 /* Packet is in one chunk -- we can copy + cksum. */
1804 eth_copy_and_sum(skb, sp->rx_skbuff[entry]->data, pkt_len, 0); 1804 skb_copy_to_linear_data(skb, sp->rx_skbuff[entry]->data, pkt_len);
1805 skb_put(skb, pkt_len); 1805 skb_put(skb, pkt_len);
1806#else 1806#else
1807 skb_copy_from_linear_data(sp->rx_skbuff[entry], 1807 skb_copy_from_linear_data(sp->rx_skbuff[entry],
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 5e517946f46a..119778401e48 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -1201,7 +1201,7 @@ static int epic_rx(struct net_device *dev, int budget)
1201 ep->rx_ring[entry].bufaddr, 1201 ep->rx_ring[entry].bufaddr,
1202 ep->rx_buf_sz, 1202 ep->rx_buf_sz,
1203 PCI_DMA_FROMDEVICE); 1203 PCI_DMA_FROMDEVICE);
1204 eth_copy_and_sum(skb, ep->rx_skbuff[entry]->data, pkt_len, 0); 1204 skb_copy_to_linear_data(skb, ep->rx_skbuff[entry]->data, pkt_len);
1205 skb_put(skb, pkt_len); 1205 skb_put(skb, pkt_len);
1206 pci_dma_sync_single_for_device(ep->pci_dev, 1206 pci_dma_sync_single_for_device(ep->pci_dev,
1207 ep->rx_ring[entry].bufaddr, 1207 ep->rx_ring[entry].bufaddr,
diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
index abe9b089c610..ff9f177d7157 100644
--- a/drivers/net/fealnx.c
+++ b/drivers/net/fealnx.c
@@ -1727,8 +1727,8 @@ static int netdev_rx(struct net_device *dev)
1727 /* Call copy + cksum if available. */ 1727 /* Call copy + cksum if available. */
1728 1728
1729#if ! defined(__alpha__) 1729#if ! defined(__alpha__)
1730 eth_copy_and_sum(skb, 1730 skb_copy_to_linear_data(skb,
1731 np->cur_rx->skbuff->data, pkt_len, 0); 1731 np->cur_rx->skbuff->data, pkt_len);
1732 skb_put(skb, pkt_len); 1732 skb_put(skb, pkt_len);
1733#else 1733#else
1734 memcpy(skb_put(skb, pkt_len), 1734 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 255b09124e11..03023dd17829 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -648,7 +648,7 @@ while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
648 fep->stats.rx_dropped++; 648 fep->stats.rx_dropped++;
649 } else { 649 } else {
650 skb_put(skb,pkt_len-4); /* Make room */ 650 skb_put(skb,pkt_len-4); /* Make room */
651 eth_copy_and_sum(skb, data, pkt_len-4, 0); 651 skb_copy_to_linear_data(skb, data, pkt_len-4);
652 skb->protocol=eth_type_trans(skb,dev); 652 skb->protocol=eth_type_trans(skb,dev);
653 netif_rx(skb); 653 netif_rx(skb);
654 } 654 }
diff --git a/drivers/net/hamachi.c b/drivers/net/hamachi.c
index 2521b111b3a5..15254dc7876a 100644
--- a/drivers/net/hamachi.c
+++ b/drivers/net/hamachi.c
@@ -1575,8 +1575,8 @@ static int hamachi_rx(struct net_device *dev)
1575 PCI_DMA_FROMDEVICE); 1575 PCI_DMA_FROMDEVICE);
1576 /* Call copy + cksum if available. */ 1576 /* Call copy + cksum if available. */
1577#if 1 || USE_IP_COPYSUM 1577#if 1 || USE_IP_COPYSUM
1578 eth_copy_and_sum(skb, 1578 skb_copy_to_linear_data(skb,
1579 hmp->rx_skbuff[entry]->data, pkt_len, 0); 1579 hmp->rx_skbuff[entry]->data, pkt_len);
1580 skb_put(skb, pkt_len); 1580 skb_put(skb, pkt_len);
1581#else 1581#else
1582 memcpy(skb_put(skb, pkt_len), hmp->rx_ring_dma 1582 memcpy(skb_put(skb, pkt_len), hmp->rx_ring_dma
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 6ec3d500f334..d96eb7229548 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1337,7 +1337,7 @@ const char * buf, size_t count)
1337 1337
1338#define ATTR(_name, _mode) \ 1338#define ATTR(_name, _mode) \
1339 struct attribute veth_##_name##_attr = { \ 1339 struct attribute veth_##_name##_attr = { \
1340 .name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE \ 1340 .name = __stringify(_name), .mode = _mode, \
1341 }; 1341 };
1342 1342
1343static ATTR(active, 0644); 1343static ATTR(active, 0644);
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index 07b4c0d7a75c..f5c3598e59af 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -136,13 +136,14 @@ resched:
136 136
137} 137}
138 138
139static void __init ifb_setup(struct net_device *dev) 139static void ifb_setup(struct net_device *dev)
140{ 140{
141 /* Initialize the device structure. */ 141 /* Initialize the device structure. */
142 dev->get_stats = ifb_get_stats; 142 dev->get_stats = ifb_get_stats;
143 dev->hard_start_xmit = ifb_xmit; 143 dev->hard_start_xmit = ifb_xmit;
144 dev->open = &ifb_open; 144 dev->open = &ifb_open;
145 dev->stop = &ifb_close; 145 dev->stop = &ifb_close;
146 dev->destructor = free_netdev;
146 147
147 /* Fill in device structure with ethernet-generic values. */ 148 /* Fill in device structure with ethernet-generic values. */
148 ether_setup(dev); 149 ether_setup(dev);
@@ -197,12 +198,6 @@ static struct net_device_stats *ifb_get_stats(struct net_device *dev)
197 return stats; 198 return stats;
198} 199}
199 200
200static struct net_device **ifbs;
201
202/* Number of ifb devices to be set up by this module. */
203module_param(numifbs, int, 0);
204MODULE_PARM_DESC(numifbs, "Number of ifb devices");
205
206static int ifb_close(struct net_device *dev) 201static int ifb_close(struct net_device *dev)
207{ 202{
208 struct ifb_private *dp = netdev_priv(dev); 203 struct ifb_private *dp = netdev_priv(dev);
@@ -226,6 +221,28 @@ static int ifb_open(struct net_device *dev)
226 return 0; 221 return 0;
227} 222}
228 223
224static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
225{
226 if (tb[IFLA_ADDRESS]) {
227 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
228 return -EINVAL;
229 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
230 return -EADDRNOTAVAIL;
231 }
232 return 0;
233}
234
235static struct rtnl_link_ops ifb_link_ops __read_mostly = {
236 .kind = "ifb",
237 .priv_size = sizeof(struct ifb_private),
238 .setup = ifb_setup,
239 .validate = ifb_validate,
240};
241
242/* Number of ifb devices to be set up by this module. */
243module_param(numifbs, int, 0);
244MODULE_PARM_DESC(numifbs, "Number of ifb devices");
245
229static int __init ifb_init_one(int index) 246static int __init ifb_init_one(int index)
230{ 247{
231 struct net_device *dev_ifb; 248 struct net_device *dev_ifb;
@@ -237,49 +254,44 @@ static int __init ifb_init_one(int index)
237 if (!dev_ifb) 254 if (!dev_ifb)
238 return -ENOMEM; 255 return -ENOMEM;
239 256
240 if ((err = register_netdev(dev_ifb))) { 257 err = dev_alloc_name(dev_ifb, dev_ifb->name);
241 free_netdev(dev_ifb); 258 if (err < 0)
242 dev_ifb = NULL; 259 goto err;
243 } else {
244 ifbs[index] = dev_ifb;
245 }
246 260
247 return err; 261 dev_ifb->rtnl_link_ops = &ifb_link_ops;
248} 262 err = register_netdevice(dev_ifb);
263 if (err < 0)
264 goto err;
265 return 0;
249 266
250static void ifb_free_one(int index) 267err:
251{ 268 free_netdev(dev_ifb);
252 unregister_netdev(ifbs[index]); 269 return err;
253 free_netdev(ifbs[index]);
254} 270}
255 271
256static int __init ifb_init_module(void) 272static int __init ifb_init_module(void)
257{ 273{
258 int i, err = 0; 274 int i, err;
259 ifbs = kmalloc(numifbs * sizeof(void *), GFP_KERNEL); 275
260 if (!ifbs) 276 rtnl_lock();
261 return -ENOMEM; 277 err = __rtnl_link_register(&ifb_link_ops);
278
262 for (i = 0; i < numifbs && !err; i++) 279 for (i = 0; i < numifbs && !err; i++)
263 err = ifb_init_one(i); 280 err = ifb_init_one(i);
264 if (err) { 281 if (err)
265 i--; 282 __rtnl_link_unregister(&ifb_link_ops);
266 while (--i >= 0) 283 rtnl_unlock();
267 ifb_free_one(i);
268 }
269 284
270 return err; 285 return err;
271} 286}
272 287
273static void __exit ifb_cleanup_module(void) 288static void __exit ifb_cleanup_module(void)
274{ 289{
275 int i; 290 rtnl_link_unregister(&ifb_link_ops);
276
277 for (i = 0; i < numifbs; i++)
278 ifb_free_one(i);
279 kfree(ifbs);
280} 291}
281 292
282module_init(ifb_init_module); 293module_init(ifb_init_module);
283module_exit(ifb_cleanup_module); 294module_exit(ifb_cleanup_module);
284MODULE_LICENSE("GPL"); 295MODULE_LICENSE("GPL");
285MODULE_AUTHOR("Jamal Hadi Salim"); 296MODULE_AUTHOR("Jamal Hadi Salim");
297MODULE_ALIAS_RTNL_LINK("ifb");
diff --git a/drivers/net/irda/kingsun-sir.c b/drivers/net/irda/kingsun-sir.c
index 217429122e79..bdd5c979bead 100644
--- a/drivers/net/irda/kingsun-sir.c
+++ b/drivers/net/irda/kingsun-sir.c
@@ -4,7 +4,7 @@
4* Version: 0.1.1 4* Version: 0.1.1
5* Description: Irda KingSun/DonShine USB Dongle 5* Description: Irda KingSun/DonShine USB Dongle
6* Status: Experimental 6* Status: Experimental
7* Author: Alex Villac�s Lasso <a_villacis@palosanto.com> 7* Author: Alex Villacís Lasso <a_villacis@palosanto.com>
8* 8*
9* Based on stir4200 and mcs7780 drivers, with (strange?) differences 9* Based on stir4200 and mcs7780 drivers, with (strange?) differences
10* 10*
@@ -652,6 +652,6 @@ static void __exit kingsun_cleanup(void)
652} 652}
653module_exit(kingsun_cleanup); 653module_exit(kingsun_cleanup);
654 654
655MODULE_AUTHOR("Alex Villac�s Lasso <a_villacis@palosanto.com>"); 655MODULE_AUTHOR("Alex Villacís Lasso <a_villacis@palosanto.com>");
656MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine"); 656MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine");
657MODULE_LICENSE("GPL"); 657MODULE_LICENSE("GPL");
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index bf78ef1120ad..0538ca9ce058 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -44,6 +44,7 @@ MODULE_LICENSE("GPL");
44#include <linux/time.h> 44#include <linux/time.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/mutex.h>
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48#include <asm/byteorder.h> 49#include <asm/byteorder.h>
49 50
@@ -1660,8 +1661,8 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1660 idev = ndev->priv; 1661 idev = ndev->priv;
1661 1662
1662 spin_lock_init(&idev->lock); 1663 spin_lock_init(&idev->lock);
1663 init_MUTEX(&idev->sem); 1664 mutex_init(&idev->mtx);
1664 down(&idev->sem); 1665 mutex_lock(&idev->mtx);
1665 idev->pdev = pdev; 1666 idev->pdev = pdev;
1666 1667
1667 if (vlsi_irda_init(ndev) < 0) 1668 if (vlsi_irda_init(ndev) < 0)
@@ -1689,12 +1690,12 @@ vlsi_irda_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1689 IRDA_MESSAGE("%s: registered device %s\n", drivername, ndev->name); 1690 IRDA_MESSAGE("%s: registered device %s\n", drivername, ndev->name);
1690 1691
1691 pci_set_drvdata(pdev, ndev); 1692 pci_set_drvdata(pdev, ndev);
1692 up(&idev->sem); 1693 mutex_unlock(&idev->mtx);
1693 1694
1694 return 0; 1695 return 0;
1695 1696
1696out_freedev: 1697out_freedev:
1697 up(&idev->sem); 1698 mutex_unlock(&idev->mtx);
1698 free_netdev(ndev); 1699 free_netdev(ndev);
1699out_disable: 1700out_disable:
1700 pci_disable_device(pdev); 1701 pci_disable_device(pdev);
@@ -1716,12 +1717,12 @@ static void __devexit vlsi_irda_remove(struct pci_dev *pdev)
1716 unregister_netdev(ndev); 1717 unregister_netdev(ndev);
1717 1718
1718 idev = ndev->priv; 1719 idev = ndev->priv;
1719 down(&idev->sem); 1720 mutex_lock(&idev->mtx);
1720 if (idev->proc_entry) { 1721 if (idev->proc_entry) {
1721 remove_proc_entry(ndev->name, vlsi_proc_root); 1722 remove_proc_entry(ndev->name, vlsi_proc_root);
1722 idev->proc_entry = NULL; 1723 idev->proc_entry = NULL;
1723 } 1724 }
1724 up(&idev->sem); 1725 mutex_unlock(&idev->mtx);
1725 1726
1726 free_netdev(ndev); 1727 free_netdev(ndev);
1727 1728
@@ -1751,7 +1752,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1751 return 0; 1752 return 0;
1752 } 1753 }
1753 idev = ndev->priv; 1754 idev = ndev->priv;
1754 down(&idev->sem); 1755 mutex_lock(&idev->mtx);
1755 if (pdev->current_state != 0) { /* already suspended */ 1756 if (pdev->current_state != 0) { /* already suspended */
1756 if (state.event > pdev->current_state) { /* simply go deeper */ 1757 if (state.event > pdev->current_state) { /* simply go deeper */
1757 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1758 pci_set_power_state(pdev, pci_choose_state(pdev, state));
@@ -1759,7 +1760,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1759 } 1760 }
1760 else 1761 else
1761 IRDA_ERROR("%s - %s: invalid suspend request %u -> %u\n", __FUNCTION__, pci_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);
1762 up(&idev->sem); 1763 mutex_unlock(&idev->mtx);
1763 return 0; 1764 return 0;
1764 } 1765 }
1765 1766
@@ -1775,7 +1776,7 @@ static int vlsi_irda_suspend(struct pci_dev *pdev, pm_message_t state)
1775 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 1776 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1776 pdev->current_state = state.event; 1777 pdev->current_state = state.event;
1777 idev->resume_ok = 1; 1778 idev->resume_ok = 1;
1778 up(&idev->sem); 1779 mutex_unlock(&idev->mtx);
1779 return 0; 1780 return 0;
1780} 1781}
1781 1782
@@ -1790,9 +1791,9 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1790 return 0; 1791 return 0;
1791 } 1792 }
1792 idev = ndev->priv; 1793 idev = ndev->priv;
1793 down(&idev->sem); 1794 mutex_lock(&idev->mtx);
1794 if (pdev->current_state == 0) { 1795 if (pdev->current_state == 0) {
1795 up(&idev->sem); 1796 mutex_unlock(&idev->mtx);
1796 IRDA_WARNING("%s - %s: already resumed\n", 1797 IRDA_WARNING("%s - %s: already resumed\n",
1797 __FUNCTION__, pci_name(pdev)); 1798 __FUNCTION__, pci_name(pdev));
1798 return 0; 1799 return 0;
@@ -1814,7 +1815,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1814 * device and independently resume_ok should catch any garbage config. 1815 * device and independently resume_ok should catch any garbage config.
1815 */ 1816 */
1816 IRDA_WARNING("%s - hm, nothing to resume?\n", __FUNCTION__); 1817 IRDA_WARNING("%s - hm, nothing to resume?\n", __FUNCTION__);
1817 up(&idev->sem); 1818 mutex_unlock(&idev->mtx);
1818 return 0; 1819 return 0;
1819 } 1820 }
1820 1821
@@ -1824,7 +1825,7 @@ static int vlsi_irda_resume(struct pci_dev *pdev)
1824 netif_device_attach(ndev); 1825 netif_device_attach(ndev);
1825 } 1826 }
1826 idev->resume_ok = 0; 1827 idev->resume_ok = 0;
1827 up(&idev->sem); 1828 mutex_unlock(&idev->mtx);
1828 return 0; 1829 return 0;
1829} 1830}
1830 1831
diff --git a/drivers/net/irda/vlsi_ir.h b/drivers/net/irda/vlsi_ir.h
index 2d3b773d8e35..ca12a6096419 100644
--- a/drivers/net/irda/vlsi_ir.h
+++ b/drivers/net/irda/vlsi_ir.h
@@ -728,7 +728,7 @@ typedef struct vlsi_irda_dev {
728 struct timeval last_rx; 728 struct timeval last_rx;
729 729
730 spinlock_t lock; 730 spinlock_t lock;
731 struct semaphore sem; 731 struct mutex mtx;
732 732
733 u8 resume_ok; 733 u8 resume_ok;
734 struct proc_dir_entry *proc_entry; 734 struct proc_dir_entry *proc_entry;
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
index d5f694fc4a21..d9ce1aef148a 100644
--- a/drivers/net/ixp2000/ixpdev.c
+++ b/drivers/net/ixp2000/ixpdev.c
@@ -111,7 +111,7 @@ static int ixpdev_rx(struct net_device *dev, int *budget)
111 skb = dev_alloc_skb(desc->pkt_length + 2); 111 skb = dev_alloc_skb(desc->pkt_length + 2);
112 if (likely(skb != NULL)) { 112 if (likely(skb != NULL)) {
113 skb_reserve(skb, 2); 113 skb_reserve(skb, 2);
114 eth_copy_and_sum(skb, buf, desc->pkt_length, 0); 114 skb_copy_to_linear_data(skb, buf, desc->pkt_length);
115 skb_put(skb, desc->pkt_length); 115 skb_put(skb, desc->pkt_length);
116 skb->protocol = eth_type_trans(skb, nds[desc->channel]); 116 skb->protocol = eth_type_trans(skb, nds[desc->channel]);
117 117
diff --git a/drivers/net/lance.c b/drivers/net/lance.c
index 0fe96c85828b..a2f37e52b928 100644
--- a/drivers/net/lance.c
+++ b/drivers/net/lance.c
@@ -1186,9 +1186,9 @@ lance_rx(struct net_device *dev)
1186 } 1186 }
1187 skb_reserve(skb,2); /* 16 byte align */ 1187 skb_reserve(skb,2); /* 16 byte align */
1188 skb_put(skb,pkt_len); /* Make room */ 1188 skb_put(skb,pkt_len); /* Make room */
1189 eth_copy_and_sum(skb, 1189 skb_copy_to_linear_data(skb,
1190 (unsigned char *)isa_bus_to_virt((lp->rx_ring[entry].base & 0x00ffffff)), 1190 (unsigned char *)isa_bus_to_virt((lp->rx_ring[entry].base & 0x00ffffff)),
1191 pkt_len,0); 1191 pkt_len);
1192 skb->protocol=eth_type_trans(skb,dev); 1192 skb->protocol=eth_type_trans(skb,dev);
1193 netif_rx(skb); 1193 netif_rx(skb);
1194 dev->last_rx = jiffies; 1194 dev->last_rx = jiffies;
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index 460a08718c69..3450051ae56b 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -2357,8 +2357,8 @@ static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do)
2357 np->rx_dma[entry], 2357 np->rx_dma[entry],
2358 buflen, 2358 buflen,
2359 PCI_DMA_FROMDEVICE); 2359 PCI_DMA_FROMDEVICE);
2360 eth_copy_and_sum(skb, 2360 skb_copy_to_linear_data(skb,
2361 np->rx_skbuff[entry]->data, pkt_len, 0); 2361 np->rx_skbuff[entry]->data, pkt_len);
2362 skb_put(skb, pkt_len); 2362 skb_put(skb, pkt_len);
2363 pci_dma_sync_single_for_device(np->pci_dev, 2363 pci_dma_sync_single_for_device(np->pci_dev,
2364 np->rx_dma[entry], 2364 np->rx_dma[entry],
diff --git a/drivers/net/ni52.c b/drivers/net/ni52.c
index 8dbd6d1900b5..5e7999db2096 100644
--- a/drivers/net/ni52.c
+++ b/drivers/net/ni52.c
@@ -936,7 +936,7 @@ static void ni52_rcv_int(struct net_device *dev)
936 { 936 {
937 skb_reserve(skb,2); 937 skb_reserve(skb,2);
938 skb_put(skb,totlen); 938 skb_put(skb,totlen);
939 eth_copy_and_sum(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen,0); 939 skb_copy_to_linear_data(skb,(char *) p->base+(unsigned long) rbd->buffer,totlen);
940 skb->protocol=eth_type_trans(skb,dev); 940 skb->protocol=eth_type_trans(skb,dev);
941 netif_rx(skb); 941 netif_rx(skb);
942 dev->last_rx = jiffies; 942 dev->last_rx = jiffies;
diff --git a/drivers/net/ni65.c b/drivers/net/ni65.c
index 3818edf0ac18..4ef5fe345191 100644
--- a/drivers/net/ni65.c
+++ b/drivers/net/ni65.c
@@ -1096,7 +1096,7 @@ static void ni65_recv_intr(struct net_device *dev,int csr0)
1096#ifdef RCV_VIA_SKB 1096#ifdef RCV_VIA_SKB
1097 if( (unsigned long) (skb->data + R_BUF_SIZE) > 0x1000000) { 1097 if( (unsigned long) (skb->data + R_BUF_SIZE) > 0x1000000) {
1098 skb_put(skb,len); 1098 skb_put(skb,len);
1099 eth_copy_and_sum(skb, (unsigned char *)(p->recv_skb[p->rmdnum]->data),len,0); 1099 skb_copy_to_linear_data(skb, (unsigned char *)(p->recv_skb[p->rmdnum]->data),len);
1100 } 1100 }
1101 else { 1101 else {
1102 struct sk_buff *skb1 = p->recv_skb[p->rmdnum]; 1102 struct sk_buff *skb1 = p->recv_skb[p->rmdnum];
@@ -1108,7 +1108,7 @@ static void ni65_recv_intr(struct net_device *dev,int csr0)
1108 } 1108 }
1109#else 1109#else
1110 skb_put(skb,len); 1110 skb_put(skb,len);
1111 eth_copy_and_sum(skb, (unsigned char *) p->recvbounce[p->rmdnum],len,0); 1111 skb_copy_to_linear_data(skb, (unsigned char *) p->recvbounce[p->rmdnum],len);
1112#endif 1112#endif
1113 p->stats.rx_packets++; 1113 p->stats.rx_packets++;
1114 p->stats.rx_bytes += len; 1114 p->stats.rx_bytes += len;
diff --git a/drivers/net/pci-skeleton.c b/drivers/net/pci-skeleton.c
index df8998b4f37e..3cdbe118200b 100644
--- a/drivers/net/pci-skeleton.c
+++ b/drivers/net/pci-skeleton.c
@@ -1567,7 +1567,7 @@ static void netdrv_rx_interrupt (struct net_device *dev,
1567 if (skb) { 1567 if (skb) {
1568 skb_reserve (skb, 2); /* 16 byte align the IP fields. */ 1568 skb_reserve (skb, 2); /* 16 byte align the IP fields. */
1569 1569
1570 eth_copy_and_sum (skb, &rx_ring[ring_offset + 4], pkt_size, 0); 1570 skb_copy_to_linear_data (skb, &rx_ring[ring_offset + 4], pkt_size);
1571 skb_put (skb, pkt_size); 1571 skb_put (skb, pkt_size);
1572 1572
1573 skb->protocol = eth_type_trans (skb, dev); 1573 skb->protocol = eth_type_trans (skb, dev);
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 9c171a7390e2..465485a3fbc6 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -1235,9 +1235,9 @@ static void pcnet32_rx_entry(struct net_device *dev,
1235 lp->rx_dma_addr[entry], 1235 lp->rx_dma_addr[entry],
1236 pkt_len, 1236 pkt_len,
1237 PCI_DMA_FROMDEVICE); 1237 PCI_DMA_FROMDEVICE);
1238 eth_copy_and_sum(skb, 1238 skb_copy_to_linear_data(skb,
1239 (unsigned char *)(lp->rx_skbuff[entry]->data), 1239 (unsigned char *)(lp->rx_skbuff[entry]->data),
1240 pkt_len, 0); 1240 pkt_len);
1241 pci_dma_sync_single_for_device(lp->pci_dev, 1241 pci_dma_sync_single_for_device(lp->pci_dev,
1242 lp->rx_dma_addr[entry], 1242 lp->rx_dma_addr[entry],
1243 pkt_len, 1243 pkt_len,
diff --git a/drivers/net/pppol2tp.c b/drivers/net/pppol2tp.c
new file mode 100644
index 000000000000..5891a0fbdc8b
--- /dev/null
+++ b/drivers/net/pppol2tp.c
@@ -0,0 +1,2486 @@
1/*****************************************************************************
2 * Linux PPP over L2TP (PPPoX/PPPoL2TP) Sockets
3 *
4 * PPPoX --- Generic PPP encapsulation socket family
5 * PPPoL2TP --- PPP over L2TP (RFC 2661)
6 *
7 * Version: 1.0.0
8 *
9 * Authors: Martijn van Oosterhout <kleptog@svana.org>
10 * James Chapman (jchapman@katalix.com)
11 * Contributors:
12 * Michal Ostrowski <mostrows@speakeasy.net>
13 * Arnaldo Carvalho de Melo <acme@xconectiva.com.br>
14 * David S. Miller (davem@redhat.com)
15 *
16 * License:
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 *
22 */
23
24/* This driver handles only L2TP data frames; control frames are handled by a
25 * userspace application.
26 *
27 * To send data in an L2TP session, userspace opens a PPPoL2TP socket and
28 * attaches it to a bound UDP socket with local tunnel_id / session_id and
29 * peer tunnel_id / session_id set. Data can then be sent or received using
30 * regular socket sendmsg() / recvmsg() calls. Kernel parameters of the socket
31 * can be read or modified using ioctl() or [gs]etsockopt() calls.
32 *
33 * When a PPPoL2TP socket is connected with local and peer session_id values
34 * zero, the socket is treated as a special tunnel management socket.
35 *
36 * Here's example userspace code to create a socket for sending/receiving data
37 * over an L2TP session:-
38 *
39 * struct sockaddr_pppol2tp sax;
40 * int fd;
41 * int session_fd;
42 *
43 * fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
44 *
45 * sax.sa_family = AF_PPPOX;
46 * sax.sa_protocol = PX_PROTO_OL2TP;
47 * sax.pppol2tp.fd = tunnel_fd; // bound UDP socket
48 * sax.pppol2tp.addr.sin_addr.s_addr = addr->sin_addr.s_addr;
49 * sax.pppol2tp.addr.sin_port = addr->sin_port;
50 * sax.pppol2tp.addr.sin_family = AF_INET;
51 * sax.pppol2tp.s_tunnel = tunnel_id;
52 * sax.pppol2tp.s_session = session_id;
53 * sax.pppol2tp.d_tunnel = peer_tunnel_id;
54 * sax.pppol2tp.d_session = peer_session_id;
55 *
56 * session_fd = connect(fd, (struct sockaddr *)&sax, sizeof(sax));
57 *
58 * A pppd plugin that allows PPP traffic to be carried over L2TP using
59 * this driver is available from the OpenL2TP project at
60 * http://openl2tp.sourceforge.net.
61 */
62
63#include <linux/module.h>
64#include <linux/version.h>
65#include <linux/string.h>
66#include <linux/list.h>
67#include <asm/uaccess.h>
68
69#include <linux/kernel.h>
70#include <linux/spinlock.h>
71#include <linux/kthread.h>
72#include <linux/sched.h>
73#include <linux/slab.h>
74#include <linux/errno.h>
75#include <linux/jiffies.h>
76
77#include <linux/netdevice.h>
78#include <linux/net.h>
79#include <linux/inetdevice.h>
80#include <linux/skbuff.h>
81#include <linux/init.h>
82#include <linux/ip.h>
83#include <linux/udp.h>
84#include <linux/if_pppox.h>
85#include <linux/if_pppol2tp.h>
86#include <net/sock.h>
87#include <linux/ppp_channel.h>
88#include <linux/ppp_defs.h>
89#include <linux/if_ppp.h>
90#include <linux/file.h>
91#include <linux/hash.h>
92#include <linux/sort.h>
93#include <linux/proc_fs.h>
94#include <net/dst.h>
95#include <net/ip.h>
96#include <net/udp.h>
97#include <net/xfrm.h>
98
99#include <asm/byteorder.h>
100#include <asm/atomic.h>
101
102
103#define PPPOL2TP_DRV_VERSION "V1.0"
104
105/* L2TP header constants */
106#define L2TP_HDRFLAG_T 0x8000
107#define L2TP_HDRFLAG_L 0x4000
108#define L2TP_HDRFLAG_S 0x0800
109#define L2TP_HDRFLAG_O 0x0200
110#define L2TP_HDRFLAG_P 0x0100
111
112#define L2TP_HDR_VER_MASK 0x000F
113#define L2TP_HDR_VER 0x0002
114
115/* Space for UDP, L2TP and PPP headers */
116#define PPPOL2TP_HEADER_OVERHEAD 40
117
118/* Just some random numbers */
119#define L2TP_TUNNEL_MAGIC 0x42114DDA
120#define L2TP_SESSION_MAGIC 0x0C04EB7D
121
122#define PPPOL2TP_HASH_BITS 4
123#define PPPOL2TP_HASH_SIZE (1 << PPPOL2TP_HASH_BITS)
124
125/* Default trace flags */
126#define PPPOL2TP_DEFAULT_DEBUG_FLAGS 0
127
128#define PRINTK(_mask, _type, _lvl, _fmt, args...) \
129 do { \
130 if ((_mask) & (_type)) \
131 printk(_lvl "PPPOL2TP: " _fmt, ##args); \
132 } while(0)
133
134/* Number of bytes to build transmit L2TP headers.
135 * Unfortunately the size is different depending on whether sequence numbers
136 * are enabled.
137 */
138#define PPPOL2TP_L2TP_HDR_SIZE_SEQ 10
139#define PPPOL2TP_L2TP_HDR_SIZE_NOSEQ 6
140
141struct pppol2tp_tunnel;
142
143/* Describes a session. It is the sk_user_data field in the PPPoL2TP
144 * socket. Contains information to determine incoming packets and transmit
145 * outgoing ones.
146 */
147struct pppol2tp_session
148{
149 int magic; /* should be
150 * L2TP_SESSION_MAGIC */
151 int owner; /* pid that opened the socket */
152
153 struct sock *sock; /* Pointer to the session
154 * PPPoX socket */
155 struct sock *tunnel_sock; /* Pointer to the tunnel UDP
156 * socket */
157
158 struct pppol2tp_addr tunnel_addr; /* Description of tunnel */
159
160 struct pppol2tp_tunnel *tunnel; /* back pointer to tunnel
161 * context */
162
163 char name[20]; /* "sess xxxxx/yyyyy", where
164 * x=tunnel_id, y=session_id */
165 int mtu;
166 int mru;
167 int flags; /* accessed by PPPIOCGFLAGS.
168 * Unused. */
169 unsigned recv_seq:1; /* expect receive packets with
170 * sequence numbers? */
171 unsigned send_seq:1; /* send packets with sequence
172 * numbers? */
173 unsigned lns_mode:1; /* behave as LNS? LAC enables
174 * sequence numbers under
175 * control of LNS. */
176 int debug; /* bitmask of debug message
177 * categories */
178 int reorder_timeout; /* configured reorder timeout
179 * (in jiffies) */
180 u16 nr; /* session NR state (receive) */
181 u16 ns; /* session NR state (send) */
182 struct sk_buff_head reorder_q; /* receive reorder queue */
183 struct pppol2tp_ioc_stats stats;
184 struct hlist_node hlist; /* Hash list node */
185};
186
187/* The sk_user_data field of the tunnel's UDP socket. It contains info to track
188 * all the associated sessions so incoming packets can be sorted out
189 */
190struct pppol2tp_tunnel
191{
192 int magic; /* Should be L2TP_TUNNEL_MAGIC */
193 rwlock_t hlist_lock; /* protect session_hlist */
194 struct hlist_head session_hlist[PPPOL2TP_HASH_SIZE];
195 /* hashed list of sessions,
196 * hashed by id */
197 int debug; /* bitmask of debug message
198 * categories */
199 char name[12]; /* "tunl xxxxx" */
200 struct pppol2tp_ioc_stats stats;
201
202 void (*old_sk_destruct)(struct sock *);
203
204 struct sock *sock; /* Parent socket */
205 struct list_head list; /* Keep a list of all open
206 * prepared sockets */
207
208 atomic_t ref_count;
209};
210
211/* Private data stored for received packets in the skb.
212 */
213struct pppol2tp_skb_cb {
214 u16 ns;
215 u16 nr;
216 u16 has_seq;
217 u16 length;
218 unsigned long expires;
219};
220
221#define PPPOL2TP_SKB_CB(skb) ((struct pppol2tp_skb_cb *) &skb->cb[sizeof(struct inet_skb_parm)])
222
223static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb);
224static void pppol2tp_tunnel_free(struct pppol2tp_tunnel *tunnel);
225
226static atomic_t pppol2tp_tunnel_count;
227static atomic_t pppol2tp_session_count;
228static struct ppp_channel_ops pppol2tp_chan_ops = { pppol2tp_xmit , NULL };
229static struct proto_ops pppol2tp_ops;
230static LIST_HEAD(pppol2tp_tunnel_list);
231static DEFINE_RWLOCK(pppol2tp_tunnel_list_lock);
232
233/* Helpers to obtain tunnel/session contexts from sockets.
234 */
235static inline struct pppol2tp_session *pppol2tp_sock_to_session(struct sock *sk)
236{
237 struct pppol2tp_session *session;
238
239 if (sk == NULL)
240 return NULL;
241
242 session = (struct pppol2tp_session *)(sk->sk_user_data);
243 if (session == NULL)
244 return NULL;
245
246 BUG_ON(session->magic != L2TP_SESSION_MAGIC);
247
248 return session;
249}
250
251static inline struct pppol2tp_tunnel *pppol2tp_sock_to_tunnel(struct sock *sk)
252{
253 struct pppol2tp_tunnel *tunnel;
254
255 if (sk == NULL)
256 return NULL;
257
258 tunnel = (struct pppol2tp_tunnel *)(sk->sk_user_data);
259 if (tunnel == NULL)
260 return NULL;
261
262 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
263
264 return tunnel;
265}
266
267/* Tunnel reference counts. Incremented per session that is added to
268 * the tunnel.
269 */
270static inline void pppol2tp_tunnel_inc_refcount(struct pppol2tp_tunnel *tunnel)
271{
272 atomic_inc(&tunnel->ref_count);
273}
274
275static inline void pppol2tp_tunnel_dec_refcount(struct pppol2tp_tunnel *tunnel)
276{
277 if (atomic_dec_and_test(&tunnel->ref_count))
278 pppol2tp_tunnel_free(tunnel);
279}
280
281/* Session hash list.
282 * The session_id SHOULD be random according to RFC2661, but several
283 * L2TP implementations (Cisco and Microsoft) use incrementing
284 * session_ids. So we do a real hash on the session_id, rather than a
285 * simple bitmask.
286 */
287static inline struct hlist_head *
288pppol2tp_session_id_hash(struct pppol2tp_tunnel *tunnel, u16 session_id)
289{
290 unsigned long hash_val = (unsigned long) session_id;
291 return &tunnel->session_hlist[hash_long(hash_val, PPPOL2TP_HASH_BITS)];
292}
293
294/* Lookup a session by id
295 */
296static struct pppol2tp_session *
297pppol2tp_session_find(struct pppol2tp_tunnel *tunnel, u16 session_id)
298{
299 struct hlist_head *session_list =
300 pppol2tp_session_id_hash(tunnel, session_id);
301 struct pppol2tp_session *session;
302 struct hlist_node *walk;
303
304 read_lock(&tunnel->hlist_lock);
305 hlist_for_each_entry(session, walk, session_list, hlist) {
306 if (session->tunnel_addr.s_session == session_id) {
307 read_unlock(&tunnel->hlist_lock);
308 return session;
309 }
310 }
311 read_unlock(&tunnel->hlist_lock);
312
313 return NULL;
314}
315
316/* Lookup a tunnel by id
317 */
318static struct pppol2tp_tunnel *pppol2tp_tunnel_find(u16 tunnel_id)
319{
320 struct pppol2tp_tunnel *tunnel = NULL;
321
322 read_lock(&pppol2tp_tunnel_list_lock);
323 list_for_each_entry(tunnel, &pppol2tp_tunnel_list, list) {
324 if (tunnel->stats.tunnel_id == tunnel_id) {
325 read_unlock(&pppol2tp_tunnel_list_lock);
326 return tunnel;
327 }
328 }
329 read_unlock(&pppol2tp_tunnel_list_lock);
330
331 return NULL;
332}
333
334/*****************************************************************************
335 * Receive data handling
336 *****************************************************************************/
337
338/* Queue a skb in order. We come here only if the skb has an L2TP sequence
339 * number.
340 */
341static void pppol2tp_recv_queue_skb(struct pppol2tp_session *session, struct sk_buff *skb)
342{
343 struct sk_buff *skbp;
344 u16 ns = PPPOL2TP_SKB_CB(skb)->ns;
345
346 spin_lock(&session->reorder_q.lock);
347 skb_queue_walk(&session->reorder_q, skbp) {
348 if (PPPOL2TP_SKB_CB(skbp)->ns > ns) {
349 __skb_insert(skb, skbp->prev, skbp, &session->reorder_q);
350 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
351 "%s: pkt %hu, inserted before %hu, reorder_q len=%d\n",
352 session->name, ns, PPPOL2TP_SKB_CB(skbp)->ns,
353 skb_queue_len(&session->reorder_q));
354 session->stats.rx_oos_packets++;
355 goto out;
356 }
357 }
358
359 __skb_queue_tail(&session->reorder_q, skb);
360
361out:
362 spin_unlock(&session->reorder_q.lock);
363}
364
365/* Dequeue a single skb.
366 */
367static void pppol2tp_recv_dequeue_skb(struct pppol2tp_session *session, struct sk_buff *skb)
368{
369 struct pppol2tp_tunnel *tunnel = session->tunnel;
370 int length = PPPOL2TP_SKB_CB(skb)->length;
371 struct sock *session_sock = NULL;
372
373 /* We're about to requeue the skb, so unlink it and return resources
374 * to its current owner (a socket receive buffer).
375 */
376 skb_unlink(skb, &session->reorder_q);
377 skb_orphan(skb);
378
379 tunnel->stats.rx_packets++;
380 tunnel->stats.rx_bytes += length;
381 session->stats.rx_packets++;
382 session->stats.rx_bytes += length;
383
384 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
385 /* Bump our Nr */
386 session->nr++;
387 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
388 "%s: updated nr to %hu\n", session->name, session->nr);
389 }
390
391 /* If the socket is bound, send it in to PPP's input queue. Otherwise
392 * queue it on the session socket.
393 */
394 session_sock = session->sock;
395 if (session_sock->sk_state & PPPOX_BOUND) {
396 struct pppox_sock *po;
397 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
398 "%s: recv %d byte data frame, passing to ppp\n",
399 session->name, length);
400
401 /* We need to forget all info related to the L2TP packet
402 * gathered in the skb as we are going to reuse the same
403 * skb for the inner packet.
404 * Namely we need to:
405 * - reset xfrm (IPSec) information as it applies to
406 * the outer L2TP packet and not to the inner one
407 * - release the dst to force a route lookup on the inner
408 * IP packet since skb->dst currently points to the dst
409 * of the UDP tunnel
410 * - reset netfilter information as it doesn't apply
411 * to the inner packet either
412 */
413 secpath_reset(skb);
414 dst_release(skb->dst);
415 skb->dst = NULL;
416 nf_reset(skb);
417
418 po = pppox_sk(session_sock);
419 ppp_input(&po->chan, skb);
420 } else {
421 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
422 "%s: socket not bound\n", session->name);
423
424 /* Not bound. Nothing we can do, so discard. */
425 session->stats.rx_errors++;
426 kfree_skb(skb);
427 }
428
429 sock_put(session->sock);
430}
431
432/* Dequeue skbs from the session's reorder_q, subject to packet order.
433 * Skbs that have been in the queue for too long are simply discarded.
434 */
435static void pppol2tp_recv_dequeue(struct pppol2tp_session *session)
436{
437 struct sk_buff *skb;
438 struct sk_buff *tmp;
439
440 /* If the pkt at the head of the queue has the nr that we
441 * expect to send up next, dequeue it and any other
442 * in-sequence packets behind it.
443 */
444 spin_lock(&session->reorder_q.lock);
445 skb_queue_walk_safe(&session->reorder_q, skb, tmp) {
446 if (time_after(jiffies, PPPOL2TP_SKB_CB(skb)->expires)) {
447 session->stats.rx_seq_discards++;
448 session->stats.rx_errors++;
449 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
450 "%s: oos pkt %hu len %d discarded (too old), "
451 "waiting for %hu, reorder_q_len=%d\n",
452 session->name, PPPOL2TP_SKB_CB(skb)->ns,
453 PPPOL2TP_SKB_CB(skb)->length, session->nr,
454 skb_queue_len(&session->reorder_q));
455 __skb_unlink(skb, &session->reorder_q);
456 kfree_skb(skb);
457 continue;
458 }
459
460 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
461 if (PPPOL2TP_SKB_CB(skb)->ns != session->nr) {
462 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
463 "%s: holding oos pkt %hu len %d, "
464 "waiting for %hu, reorder_q_len=%d\n",
465 session->name, PPPOL2TP_SKB_CB(skb)->ns,
466 PPPOL2TP_SKB_CB(skb)->length, session->nr,
467 skb_queue_len(&session->reorder_q));
468 goto out;
469 }
470 }
471 spin_unlock(&session->reorder_q.lock);
472 pppol2tp_recv_dequeue_skb(session, skb);
473 spin_lock(&session->reorder_q.lock);
474 }
475
476out:
477 spin_unlock(&session->reorder_q.lock);
478}
479
480/* Internal receive frame. Do the real work of receiving an L2TP data frame
481 * here. The skb is not on a list when we get here.
482 * Returns 0 if the packet was a data packet and was successfully passed on.
483 * Returns 1 if the packet was not a good data packet and could not be
484 * forwarded. All such packets are passed up to userspace to deal with.
485 */
486static int pppol2tp_recv_core(struct sock *sock, struct sk_buff *skb)
487{
488 struct pppol2tp_session *session = NULL;
489 struct pppol2tp_tunnel *tunnel;
490 unsigned char *ptr;
491 u16 hdrflags;
492 u16 tunnel_id, session_id;
493 int length;
494 struct udphdr *uh;
495
496 tunnel = pppol2tp_sock_to_tunnel(sock);
497 if (tunnel == NULL)
498 goto error;
499
500 /* Short packet? */
501 if (skb->len < sizeof(struct udphdr)) {
502 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
503 "%s: recv short packet (len=%d)\n", tunnel->name, skb->len);
504 goto error;
505 }
506
507 /* Point to L2TP header */
508 ptr = skb->data + sizeof(struct udphdr);
509
510 /* Get L2TP header flags */
511 hdrflags = ntohs(*(__be16*)ptr);
512
513 /* Trace packet contents, if enabled */
514 if (tunnel->debug & PPPOL2TP_MSG_DATA) {
515 printk(KERN_DEBUG "%s: recv: ", tunnel->name);
516
517 for (length = 0; length < 16; length++)
518 printk(" %02X", ptr[length]);
519 printk("\n");
520 }
521
522 /* Get length of L2TP packet */
523 uh = (struct udphdr *) skb_transport_header(skb);
524 length = ntohs(uh->len) - sizeof(struct udphdr);
525
526 /* Too short? */
527 if (length < 12) {
528 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
529 "%s: recv short L2TP packet (len=%d)\n", tunnel->name, length);
530 goto error;
531 }
532
533 /* If type is control packet, it is handled by userspace. */
534 if (hdrflags & L2TP_HDRFLAG_T) {
535 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
536 "%s: recv control packet, len=%d\n", tunnel->name, length);
537 goto error;
538 }
539
540 /* Skip flags */
541 ptr += 2;
542
543 /* If length is present, skip it */
544 if (hdrflags & L2TP_HDRFLAG_L)
545 ptr += 2;
546
547 /* Extract tunnel and session ID */
548 tunnel_id = ntohs(*(__be16 *) ptr);
549 ptr += 2;
550 session_id = ntohs(*(__be16 *) ptr);
551 ptr += 2;
552
553 /* Find the session context */
554 session = pppol2tp_session_find(tunnel, session_id);
555 if (!session) {
556 /* Not found? Pass to userspace to deal with */
557 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_INFO,
558 "%s: no socket found (%hu/%hu). Passing up.\n",
559 tunnel->name, tunnel_id, session_id);
560 goto error;
561 }
562 sock_hold(session->sock);
563
564 /* The ref count on the socket was increased by the above call since
565 * we now hold a pointer to the session. Take care to do sock_put()
566 * when exiting this function from now on...
567 */
568
569 /* Handle the optional sequence numbers. If we are the LAC,
570 * enable/disable sequence numbers under the control of the LNS. If
571 * no sequence numbers present but we were expecting them, discard
572 * frame.
573 */
574 if (hdrflags & L2TP_HDRFLAG_S) {
575 u16 ns, nr;
576 ns = ntohs(*(__be16 *) ptr);
577 ptr += 2;
578 nr = ntohs(*(__be16 *) ptr);
579 ptr += 2;
580
581 /* Received a packet with sequence numbers. If we're the LNS,
582 * check if we sre sending sequence numbers and if not,
583 * configure it so.
584 */
585 if ((!session->lns_mode) && (!session->send_seq)) {
586 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_INFO,
587 "%s: requested to enable seq numbers by LNS\n",
588 session->name);
589 session->send_seq = -1;
590 }
591
592 /* Store L2TP info in the skb */
593 PPPOL2TP_SKB_CB(skb)->ns = ns;
594 PPPOL2TP_SKB_CB(skb)->nr = nr;
595 PPPOL2TP_SKB_CB(skb)->has_seq = 1;
596
597 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
598 "%s: recv data ns=%hu, nr=%hu, session nr=%hu\n",
599 session->name, ns, nr, session->nr);
600 } else {
601 /* No sequence numbers.
602 * If user has configured mandatory sequence numbers, discard.
603 */
604 if (session->recv_seq) {
605 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_WARNING,
606 "%s: recv data has no seq numbers when required. "
607 "Discarding\n", session->name);
608 session->stats.rx_seq_discards++;
609 session->stats.rx_errors++;
610 goto discard;
611 }
612
613 /* If we're the LAC and we're sending sequence numbers, the
614 * LNS has requested that we no longer send sequence numbers.
615 * If we're the LNS and we're sending sequence numbers, the
616 * LAC is broken. Discard the frame.
617 */
618 if ((!session->lns_mode) && (session->send_seq)) {
619 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_INFO,
620 "%s: requested to disable seq numbers by LNS\n",
621 session->name);
622 session->send_seq = 0;
623 } else if (session->send_seq) {
624 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_WARNING,
625 "%s: recv data has no seq numbers when required. "
626 "Discarding\n", session->name);
627 session->stats.rx_seq_discards++;
628 session->stats.rx_errors++;
629 goto discard;
630 }
631
632 /* Store L2TP info in the skb */
633 PPPOL2TP_SKB_CB(skb)->has_seq = 0;
634 }
635
636 /* If offset bit set, skip it. */
637 if (hdrflags & L2TP_HDRFLAG_O)
638 ptr += 2 + ntohs(*(__be16 *) ptr);
639
640 skb_pull(skb, ptr - skb->data);
641
642 /* Skip PPP header, if present. In testing, Microsoft L2TP clients
643 * don't send the PPP header (PPP header compression enabled), but
644 * other clients can include the header. So we cope with both cases
645 * here. The PPP header is always FF03 when using L2TP.
646 *
647 * Note that skb->data[] isn't dereferenced from a u16 ptr here since
648 * the field may be unaligned.
649 */
650 if ((skb->data[0] == 0xff) && (skb->data[1] == 0x03))
651 skb_pull(skb, 2);
652
653 /* Prepare skb for adding to the session's reorder_q. Hold
654 * packets for max reorder_timeout or 1 second if not
655 * reordering.
656 */
657 PPPOL2TP_SKB_CB(skb)->length = length;
658 PPPOL2TP_SKB_CB(skb)->expires = jiffies +
659 (session->reorder_timeout ? session->reorder_timeout : HZ);
660
661 /* Add packet to the session's receive queue. Reordering is done here, if
662 * enabled. Saved L2TP protocol info is stored in skb->sb[].
663 */
664 if (PPPOL2TP_SKB_CB(skb)->has_seq) {
665 if (session->reorder_timeout != 0) {
666 /* Packet reordering enabled. Add skb to session's
667 * reorder queue, in order of ns.
668 */
669 pppol2tp_recv_queue_skb(session, skb);
670 } else {
671 /* Packet reordering disabled. Discard out-of-sequence
672 * packets
673 */
674 if (PPPOL2TP_SKB_CB(skb)->ns != session->nr) {
675 session->stats.rx_seq_discards++;
676 session->stats.rx_errors++;
677 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
678 "%s: oos pkt %hu len %d discarded, "
679 "waiting for %hu, reorder_q_len=%d\n",
680 session->name, PPPOL2TP_SKB_CB(skb)->ns,
681 PPPOL2TP_SKB_CB(skb)->length, session->nr,
682 skb_queue_len(&session->reorder_q));
683 goto discard;
684 }
685 skb_queue_tail(&session->reorder_q, skb);
686 }
687 } else {
688 /* No sequence numbers. Add the skb to the tail of the
689 * reorder queue. This ensures that it will be
690 * delivered after all previous sequenced skbs.
691 */
692 skb_queue_tail(&session->reorder_q, skb);
693 }
694
695 /* Try to dequeue as many skbs from reorder_q as we can. */
696 pppol2tp_recv_dequeue(session);
697
698 return 0;
699
700discard:
701 kfree_skb(skb);
702 sock_put(session->sock);
703
704 return 0;
705
706error:
707 return 1;
708}
709
710/* UDP encapsulation receive handler. See net/ipv4/udp.c.
711 * Return codes:
712 * 0 : success.
713 * <0: error
714 * >0: skb should be passed up to userspace as UDP.
715 */
716static int pppol2tp_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
717{
718 struct pppol2tp_tunnel *tunnel;
719
720 tunnel = pppol2tp_sock_to_tunnel(sk);
721 if (tunnel == NULL)
722 goto pass_up;
723
724 PRINTK(tunnel->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
725 "%s: received %d bytes\n", tunnel->name, skb->len);
726
727 if (pppol2tp_recv_core(sk, skb))
728 goto pass_up;
729
730 return 0;
731
732pass_up:
733 return 1;
734}
735
736/* Receive message. This is the recvmsg for the PPPoL2TP socket.
737 */
738static int pppol2tp_recvmsg(struct kiocb *iocb, struct socket *sock,
739 struct msghdr *msg, size_t len,
740 int flags)
741{
742 int err;
743 struct sk_buff *skb;
744 struct sock *sk = sock->sk;
745
746 err = -EIO;
747 if (sk->sk_state & PPPOX_BOUND)
748 goto end;
749
750 msg->msg_namelen = 0;
751
752 err = 0;
753 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
754 flags & MSG_DONTWAIT, &err);
755 if (skb) {
756 err = memcpy_toiovec(msg->msg_iov, (unsigned char *) skb->data,
757 skb->len);
758 if (err < 0)
759 goto do_skb_free;
760 err = skb->len;
761 }
762do_skb_free:
763 kfree_skb(skb);
764end:
765 return err;
766}
767
768/************************************************************************
769 * Transmit handling
770 ***********************************************************************/
771
772/* Tell how big L2TP headers are for a particular session. This
773 * depends on whether sequence numbers are being used.
774 */
775static inline int pppol2tp_l2tp_header_len(struct pppol2tp_session *session)
776{
777 if (session->send_seq)
778 return PPPOL2TP_L2TP_HDR_SIZE_SEQ;
779
780 return PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
781}
782
783/* Build an L2TP header for the session into the buffer provided.
784 */
785static void pppol2tp_build_l2tp_header(struct pppol2tp_session *session,
786 void *buf)
787{
788 __be16 *bufp = buf;
789 u16 flags = L2TP_HDR_VER;
790
791 if (session->send_seq)
792 flags |= L2TP_HDRFLAG_S;
793
794 /* Setup L2TP header.
795 * FIXME: Can this ever be unaligned? Is direct dereferencing of
796 * 16-bit header fields safe here for all architectures?
797 */
798 *bufp++ = htons(flags);
799 *bufp++ = htons(session->tunnel_addr.d_tunnel);
800 *bufp++ = htons(session->tunnel_addr.d_session);
801 if (session->send_seq) {
802 *bufp++ = htons(session->ns);
803 *bufp++ = 0;
804 session->ns++;
805 PRINTK(session->debug, PPPOL2TP_MSG_SEQ, KERN_DEBUG,
806 "%s: updated ns to %hu\n", session->name, session->ns);
807 }
808}
809
810/* This is the sendmsg for the PPPoL2TP pppol2tp_session socket. We come here
811 * when a user application does a sendmsg() on the session socket. L2TP and
812 * PPP headers must be inserted into the user's data.
813 */
814static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
815 size_t total_len)
816{
817 static const unsigned char ppph[2] = { 0xff, 0x03 };
818 struct sock *sk = sock->sk;
819 struct inet_sock *inet;
820 __wsum csum = 0;
821 struct sk_buff *skb;
822 int error;
823 int hdr_len;
824 struct pppol2tp_session *session;
825 struct pppol2tp_tunnel *tunnel;
826 struct udphdr *uh;
827
828 error = -ENOTCONN;
829 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
830 goto error;
831
832 /* Get session and tunnel contexts */
833 error = -EBADF;
834 session = pppol2tp_sock_to_session(sk);
835 if (session == NULL)
836 goto error;
837
838 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
839 if (tunnel == NULL)
840 goto error;
841
842 /* What header length is configured for this session? */
843 hdr_len = pppol2tp_l2tp_header_len(session);
844
845 /* Allocate a socket buffer */
846 error = -ENOMEM;
847 skb = sock_wmalloc(sk, NET_SKB_PAD + sizeof(struct iphdr) +
848 sizeof(struct udphdr) + hdr_len +
849 sizeof(ppph) + total_len,
850 0, GFP_KERNEL);
851 if (!skb)
852 goto error;
853
854 /* Reserve space for headers. */
855 skb_reserve(skb, NET_SKB_PAD);
856 skb_reset_network_header(skb);
857 skb_reserve(skb, sizeof(struct iphdr));
858 skb_reset_transport_header(skb);
859
860 /* Build UDP header */
861 inet = inet_sk(session->tunnel_sock);
862 uh = (struct udphdr *) skb->data;
863 uh->source = inet->sport;
864 uh->dest = inet->dport;
865 uh->len = htons(hdr_len + sizeof(ppph) + total_len);
866 uh->check = 0;
867 skb_put(skb, sizeof(struct udphdr));
868
869 /* Build L2TP header */
870 pppol2tp_build_l2tp_header(session, skb->data);
871 skb_put(skb, hdr_len);
872
873 /* Add PPP header */
874 skb->data[0] = ppph[0];
875 skb->data[1] = ppph[1];
876 skb_put(skb, 2);
877
878 /* Copy user data into skb */
879 error = memcpy_fromiovec(skb->data, m->msg_iov, total_len);
880 if (error < 0) {
881 kfree_skb(skb);
882 goto error;
883 }
884 skb_put(skb, total_len);
885
886 /* Calculate UDP checksum if configured to do so */
887 if (session->tunnel_sock->sk_no_check != UDP_CSUM_NOXMIT)
888 csum = udp_csum_outgoing(sk, skb);
889
890 /* Debug */
891 if (session->send_seq)
892 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
893 "%s: send %Zd bytes, ns=%hu\n", session->name,
894 total_len, session->ns - 1);
895 else
896 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
897 "%s: send %Zd bytes\n", session->name, total_len);
898
899 if (session->debug & PPPOL2TP_MSG_DATA) {
900 int i;
901 unsigned char *datap = skb->data;
902
903 printk(KERN_DEBUG "%s: xmit:", session->name);
904 for (i = 0; i < total_len; i++) {
905 printk(" %02X", *datap++);
906 if (i == 15) {
907 printk(" ...");
908 break;
909 }
910 }
911 printk("\n");
912 }
913
914 /* Queue the packet to IP for output */
915 error = ip_queue_xmit(skb, 1);
916
917 /* Update stats */
918 if (error >= 0) {
919 tunnel->stats.tx_packets++;
920 tunnel->stats.tx_bytes += skb->len;
921 session->stats.tx_packets++;
922 session->stats.tx_bytes += skb->len;
923 } else {
924 tunnel->stats.tx_errors++;
925 session->stats.tx_errors++;
926 }
927
928error:
929 return error;
930}
931
932/* Transmit function called by generic PPP driver. Sends PPP frame
933 * over PPPoL2TP socket.
934 *
935 * This is almost the same as pppol2tp_sendmsg(), but rather than
936 * being called with a msghdr from userspace, it is called with a skb
937 * from the kernel.
938 *
939 * The supplied skb from ppp doesn't have enough headroom for the
940 * insertion of L2TP, UDP and IP headers so we need to allocate more
941 * headroom in the skb. This will create a cloned skb. But we must be
942 * careful in the error case because the caller will expect to free
943 * the skb it supplied, not our cloned skb. So we take care to always
944 * leave the original skb unfreed if we return an error.
945 */
946static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
947{
948 static const u8 ppph[2] = { 0xff, 0x03 };
949 struct sock *sk = (struct sock *) chan->private;
950 struct sock *sk_tun;
951 int hdr_len;
952 struct pppol2tp_session *session;
953 struct pppol2tp_tunnel *tunnel;
954 int rc;
955 int headroom;
956 int data_len = skb->len;
957 struct inet_sock *inet;
958 __wsum csum = 0;
959 struct sk_buff *skb2 = NULL;
960 struct udphdr *uh;
961
962 if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED))
963 goto abort;
964
965 /* Get session and tunnel contexts from the socket */
966 session = pppol2tp_sock_to_session(sk);
967 if (session == NULL)
968 goto abort;
969
970 sk_tun = session->tunnel_sock;
971 if (sk_tun == NULL)
972 goto abort;
973 tunnel = pppol2tp_sock_to_tunnel(sk_tun);
974 if (tunnel == NULL)
975 goto abort;
976
977 /* What header length is configured for this session? */
978 hdr_len = pppol2tp_l2tp_header_len(session);
979
980 /* Check that there's enough headroom in the skb to insert IP,
981 * UDP and L2TP and PPP headers. If not enough, expand it to
982 * make room. Note that a new skb (or a clone) is
983 * allocated. If we return an error from this point on, make
984 * sure we free the new skb but do not free the original skb
985 * since that is done by the caller for the error case.
986 */
987 headroom = NET_SKB_PAD + sizeof(struct iphdr) +
988 sizeof(struct udphdr) + hdr_len + sizeof(ppph);
989 if (skb_headroom(skb) < headroom) {
990 skb2 = skb_realloc_headroom(skb, headroom);
991 if (skb2 == NULL)
992 goto abort;
993 } else
994 skb2 = skb;
995
996 /* Check that the socket has room */
997 if (atomic_read(&sk_tun->sk_wmem_alloc) < sk_tun->sk_sndbuf)
998 skb_set_owner_w(skb2, sk_tun);
999 else
1000 goto discard;
1001
1002 /* Setup PPP header */
1003 skb_push(skb2, sizeof(ppph));
1004 skb2->data[0] = ppph[0];
1005 skb2->data[1] = ppph[1];
1006
1007 /* Setup L2TP header */
1008 skb_push(skb2, hdr_len);
1009 pppol2tp_build_l2tp_header(session, skb2->data);
1010
1011 /* Setup UDP header */
1012 inet = inet_sk(sk_tun);
1013 skb_push(skb2, sizeof(struct udphdr));
1014 skb_reset_transport_header(skb2);
1015 uh = (struct udphdr *) skb2->data;
1016 uh->source = inet->sport;
1017 uh->dest = inet->dport;
1018 uh->len = htons(sizeof(struct udphdr) + hdr_len + sizeof(ppph) + data_len);
1019 uh->check = 0;
1020
1021 /* Calculate UDP checksum if configured to do so */
1022 if (sk_tun->sk_no_check != UDP_CSUM_NOXMIT)
1023 csum = udp_csum_outgoing(sk_tun, skb2);
1024
1025 /* Debug */
1026 if (session->send_seq)
1027 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
1028 "%s: send %d bytes, ns=%hu\n", session->name,
1029 data_len, session->ns - 1);
1030 else
1031 PRINTK(session->debug, PPPOL2TP_MSG_DATA, KERN_DEBUG,
1032 "%s: send %d bytes\n", session->name, data_len);
1033
1034 if (session->debug & PPPOL2TP_MSG_DATA) {
1035 int i;
1036 unsigned char *datap = skb2->data;
1037
1038 printk(KERN_DEBUG "%s: xmit:", session->name);
1039 for (i = 0; i < data_len; i++) {
1040 printk(" %02X", *datap++);
1041 if (i == 31) {
1042 printk(" ...");
1043 break;
1044 }
1045 }
1046 printk("\n");
1047 }
1048
1049 /* Get routing info from the tunnel socket */
1050 skb2->dst = sk_dst_get(sk_tun);
1051
1052 /* Queue the packet to IP for output */
1053 rc = ip_queue_xmit(skb2, 1);
1054
1055 /* Update stats */
1056 if (rc >= 0) {
1057 tunnel->stats.tx_packets++;
1058 tunnel->stats.tx_bytes += skb2->len;
1059 session->stats.tx_packets++;
1060 session->stats.tx_bytes += skb2->len;
1061 } else {
1062 tunnel->stats.tx_errors++;
1063 session->stats.tx_errors++;
1064 }
1065
1066 /* Free the original skb */
1067 kfree_skb(skb);
1068
1069 return 1;
1070
1071discard:
1072 /* Free the new skb. Caller will free original skb. */
1073 if (skb2 != skb)
1074 kfree_skb(skb2);
1075abort:
1076 return 0;
1077}
1078
1079/*****************************************************************************
1080 * Session (and tunnel control) socket create/destroy.
1081 *****************************************************************************/
1082
1083/* When the tunnel UDP socket is closed, all the attached sockets need to go
1084 * too.
1085 */
1086static void pppol2tp_tunnel_closeall(struct pppol2tp_tunnel *tunnel)
1087{
1088 int hash;
1089 struct hlist_node *walk;
1090 struct hlist_node *tmp;
1091 struct pppol2tp_session *session;
1092 struct sock *sk;
1093
1094 if (tunnel == NULL)
1095 BUG();
1096
1097 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1098 "%s: closing all sessions...\n", tunnel->name);
1099
1100 write_lock(&tunnel->hlist_lock);
1101 for (hash = 0; hash < PPPOL2TP_HASH_SIZE; hash++) {
1102again:
1103 hlist_for_each_safe(walk, tmp, &tunnel->session_hlist[hash]) {
1104 session = hlist_entry(walk, struct pppol2tp_session, hlist);
1105
1106 sk = session->sock;
1107
1108 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1109 "%s: closing session\n", session->name);
1110
1111 hlist_del_init(&session->hlist);
1112
1113 /* Since we should hold the sock lock while
1114 * doing any unbinding, we need to release the
1115 * lock we're holding before taking that lock.
1116 * Hold a reference to the sock so it doesn't
1117 * disappear as we're jumping between locks.
1118 */
1119 sock_hold(sk);
1120 write_unlock(&tunnel->hlist_lock);
1121 lock_sock(sk);
1122
1123 if (sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) {
1124 pppox_unbind_sock(sk);
1125 sk->sk_state = PPPOX_DEAD;
1126 sk->sk_state_change(sk);
1127 }
1128
1129 /* Purge any queued data */
1130 skb_queue_purge(&sk->sk_receive_queue);
1131 skb_queue_purge(&sk->sk_write_queue);
1132 skb_queue_purge(&session->reorder_q);
1133
1134 release_sock(sk);
1135 sock_put(sk);
1136
1137 /* Now restart from the beginning of this hash
1138 * chain. We always remove a session from the
1139 * list so we are guaranteed to make forward
1140 * progress.
1141 */
1142 write_lock(&tunnel->hlist_lock);
1143 goto again;
1144 }
1145 }
1146 write_unlock(&tunnel->hlist_lock);
1147}
1148
1149/* Really kill the tunnel.
1150 * Come here only when all sessions have been cleared from the tunnel.
1151 */
1152static void pppol2tp_tunnel_free(struct pppol2tp_tunnel *tunnel)
1153{
1154 /* Remove from socket list */
1155 write_lock(&pppol2tp_tunnel_list_lock);
1156 list_del_init(&tunnel->list);
1157 write_unlock(&pppol2tp_tunnel_list_lock);
1158
1159 atomic_dec(&pppol2tp_tunnel_count);
1160 kfree(tunnel);
1161}
1162
1163/* Tunnel UDP socket destruct hook.
1164 * The tunnel context is deleted only when all session sockets have been
1165 * closed.
1166 */
1167static void pppol2tp_tunnel_destruct(struct sock *sk)
1168{
1169 struct pppol2tp_tunnel *tunnel;
1170
1171 tunnel = pppol2tp_sock_to_tunnel(sk);
1172 if (tunnel == NULL)
1173 goto end;
1174
1175 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1176 "%s: closing...\n", tunnel->name);
1177
1178 /* Close all sessions */
1179 pppol2tp_tunnel_closeall(tunnel);
1180
1181 /* No longer an encapsulation socket. See net/ipv4/udp.c */
1182 (udp_sk(sk))->encap_type = 0;
1183 (udp_sk(sk))->encap_rcv = NULL;
1184
1185 /* Remove hooks into tunnel socket */
1186 tunnel->sock = NULL;
1187 sk->sk_destruct = tunnel->old_sk_destruct;
1188 sk->sk_user_data = NULL;
1189
1190 /* Call original (UDP) socket descructor */
1191 if (sk->sk_destruct != NULL)
1192 (*sk->sk_destruct)(sk);
1193
1194 pppol2tp_tunnel_dec_refcount(tunnel);
1195
1196end:
1197 return;
1198}
1199
1200/* Really kill the session socket. (Called from sock_put() if
1201 * refcnt == 0.)
1202 */
1203static void pppol2tp_session_destruct(struct sock *sk)
1204{
1205 struct pppol2tp_session *session = NULL;
1206
1207 if (sk->sk_user_data != NULL) {
1208 struct pppol2tp_tunnel *tunnel;
1209
1210 session = pppol2tp_sock_to_session(sk);
1211 if (session == NULL)
1212 goto out;
1213
1214 /* Don't use pppol2tp_sock_to_tunnel() here to
1215 * get the tunnel context because the tunnel
1216 * socket might have already been closed (its
1217 * sk->sk_user_data will be NULL) so use the
1218 * session's private tunnel ptr instead.
1219 */
1220 tunnel = session->tunnel;
1221 if (tunnel != NULL) {
1222 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1223
1224 /* If session_id is zero, this is a null
1225 * session context, which was created for a
1226 * socket that is being used only to manage
1227 * tunnels.
1228 */
1229 if (session->tunnel_addr.s_session != 0) {
1230 /* Delete the session socket from the
1231 * hash
1232 */
1233 write_lock(&tunnel->hlist_lock);
1234 hlist_del_init(&session->hlist);
1235 write_unlock(&tunnel->hlist_lock);
1236
1237 atomic_dec(&pppol2tp_session_count);
1238 }
1239
1240 /* This will delete the tunnel context if this
1241 * is the last session on the tunnel.
1242 */
1243 session->tunnel = NULL;
1244 session->tunnel_sock = NULL;
1245 pppol2tp_tunnel_dec_refcount(tunnel);
1246 }
1247 }
1248
1249 kfree(session);
1250out:
1251 return;
1252}
1253
1254/* Called when the PPPoX socket (session) is closed.
1255 */
1256static int pppol2tp_release(struct socket *sock)
1257{
1258 struct sock *sk = sock->sk;
1259 int error;
1260
1261 if (!sk)
1262 return 0;
1263
1264 error = -EBADF;
1265 lock_sock(sk);
1266 if (sock_flag(sk, SOCK_DEAD) != 0)
1267 goto error;
1268
1269 pppox_unbind_sock(sk);
1270
1271 /* Signal the death of the socket. */
1272 sk->sk_state = PPPOX_DEAD;
1273 sock_orphan(sk);
1274 sock->sk = NULL;
1275
1276 /* Purge any queued data */
1277 skb_queue_purge(&sk->sk_receive_queue);
1278 skb_queue_purge(&sk->sk_write_queue);
1279
1280 release_sock(sk);
1281
1282 /* This will delete the session context via
1283 * pppol2tp_session_destruct() if the socket's refcnt drops to
1284 * zero.
1285 */
1286 sock_put(sk);
1287
1288 return 0;
1289
1290error:
1291 release_sock(sk);
1292 return error;
1293}
1294
1295/* Internal function to prepare a tunnel (UDP) socket to have PPPoX
1296 * sockets attached to it.
1297 */
1298static struct sock *pppol2tp_prepare_tunnel_socket(int fd, u16 tunnel_id,
1299 int *error)
1300{
1301 int err;
1302 struct socket *sock = NULL;
1303 struct sock *sk;
1304 struct pppol2tp_tunnel *tunnel;
1305 struct sock *ret = NULL;
1306
1307 /* Get the tunnel UDP socket from the fd, which was opened by
1308 * the userspace L2TP daemon.
1309 */
1310 err = -EBADF;
1311 sock = sockfd_lookup(fd, &err);
1312 if (!sock) {
1313 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1314 "tunl %hu: sockfd_lookup(fd=%d) returned %d\n",
1315 tunnel_id, fd, err);
1316 goto err;
1317 }
1318
1319 /* Quick sanity checks */
1320 err = -ESOCKTNOSUPPORT;
1321 if (sock->type != SOCK_DGRAM) {
1322 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1323 "tunl %hu: fd %d wrong type, got %d, expected %d\n",
1324 tunnel_id, fd, sock->type, SOCK_DGRAM);
1325 goto err;
1326 }
1327 err = -EAFNOSUPPORT;
1328 if (sock->ops->family != AF_INET) {
1329 PRINTK(-1, PPPOL2TP_MSG_CONTROL, KERN_ERR,
1330 "tunl %hu: fd %d wrong family, got %d, expected %d\n",
1331 tunnel_id, fd, sock->ops->family, AF_INET);
1332 goto err;
1333 }
1334
1335 err = -ENOTCONN;
1336 sk = sock->sk;
1337
1338 /* Check if this socket has already been prepped */
1339 tunnel = (struct pppol2tp_tunnel *)sk->sk_user_data;
1340 if (tunnel != NULL) {
1341 /* User-data field already set */
1342 err = -EBUSY;
1343 BUG_ON(tunnel->magic != L2TP_TUNNEL_MAGIC);
1344
1345 /* This socket has already been prepped */
1346 ret = tunnel->sock;
1347 goto out;
1348 }
1349
1350 /* This socket is available and needs prepping. Create a new tunnel
1351 * context and init it.
1352 */
1353 sk->sk_user_data = tunnel = kzalloc(sizeof(struct pppol2tp_tunnel), GFP_KERNEL);
1354 if (sk->sk_user_data == NULL) {
1355 err = -ENOMEM;
1356 goto err;
1357 }
1358
1359 tunnel->magic = L2TP_TUNNEL_MAGIC;
1360 sprintf(&tunnel->name[0], "tunl %hu", tunnel_id);
1361
1362 tunnel->stats.tunnel_id = tunnel_id;
1363 tunnel->debug = PPPOL2TP_DEFAULT_DEBUG_FLAGS;
1364
1365 /* Hook on the tunnel socket destructor so that we can cleanup
1366 * if the tunnel socket goes away.
1367 */
1368 tunnel->old_sk_destruct = sk->sk_destruct;
1369 sk->sk_destruct = &pppol2tp_tunnel_destruct;
1370
1371 tunnel->sock = sk;
1372 sk->sk_allocation = GFP_ATOMIC;
1373
1374 /* Misc init */
1375 rwlock_init(&tunnel->hlist_lock);
1376
1377 /* Add tunnel to our list */
1378 INIT_LIST_HEAD(&tunnel->list);
1379 write_lock(&pppol2tp_tunnel_list_lock);
1380 list_add(&tunnel->list, &pppol2tp_tunnel_list);
1381 write_unlock(&pppol2tp_tunnel_list_lock);
1382 atomic_inc(&pppol2tp_tunnel_count);
1383
1384 /* Bump the reference count. The tunnel context is deleted
1385 * only when this drops to zero.
1386 */
1387 pppol2tp_tunnel_inc_refcount(tunnel);
1388
1389 /* Mark socket as an encapsulation socket. See net/ipv4/udp.c */
1390 (udp_sk(sk))->encap_type = UDP_ENCAP_L2TPINUDP;
1391 (udp_sk(sk))->encap_rcv = pppol2tp_udp_encap_recv;
1392
1393 ret = tunnel->sock;
1394
1395 *error = 0;
1396out:
1397 if (sock)
1398 sockfd_put(sock);
1399
1400 return ret;
1401
1402err:
1403 *error = err;
1404 goto out;
1405}
1406
1407static struct proto pppol2tp_sk_proto = {
1408 .name = "PPPOL2TP",
1409 .owner = THIS_MODULE,
1410 .obj_size = sizeof(struct pppox_sock),
1411};
1412
1413/* socket() handler. Initialize a new struct sock.
1414 */
1415static int pppol2tp_create(struct socket *sock)
1416{
1417 int error = -ENOMEM;
1418 struct sock *sk;
1419
1420 sk = sk_alloc(PF_PPPOX, GFP_KERNEL, &pppol2tp_sk_proto, 1);
1421 if (!sk)
1422 goto out;
1423
1424 sock_init_data(sock, sk);
1425
1426 sock->state = SS_UNCONNECTED;
1427 sock->ops = &pppol2tp_ops;
1428
1429 sk->sk_backlog_rcv = pppol2tp_recv_core;
1430 sk->sk_protocol = PX_PROTO_OL2TP;
1431 sk->sk_family = PF_PPPOX;
1432 sk->sk_state = PPPOX_NONE;
1433 sk->sk_type = SOCK_STREAM;
1434 sk->sk_destruct = pppol2tp_session_destruct;
1435
1436 error = 0;
1437
1438out:
1439 return error;
1440}
1441
1442/* connect() handler. Attach a PPPoX socket to a tunnel UDP socket
1443 */
1444static int pppol2tp_connect(struct socket *sock, struct sockaddr *uservaddr,
1445 int sockaddr_len, int flags)
1446{
1447 struct sock *sk = sock->sk;
1448 struct sockaddr_pppol2tp *sp = (struct sockaddr_pppol2tp *) uservaddr;
1449 struct pppox_sock *po = pppox_sk(sk);
1450 struct sock *tunnel_sock = NULL;
1451 struct pppol2tp_session *session = NULL;
1452 struct pppol2tp_tunnel *tunnel;
1453 struct dst_entry *dst;
1454 int error = 0;
1455
1456 lock_sock(sk);
1457
1458 error = -EINVAL;
1459 if (sp->sa_protocol != PX_PROTO_OL2TP)
1460 goto end;
1461
1462 /* Check for already bound sockets */
1463 error = -EBUSY;
1464 if (sk->sk_state & PPPOX_CONNECTED)
1465 goto end;
1466
1467 /* We don't supporting rebinding anyway */
1468 error = -EALREADY;
1469 if (sk->sk_user_data)
1470 goto end; /* socket is already attached */
1471
1472 /* Don't bind if s_tunnel is 0 */
1473 error = -EINVAL;
1474 if (sp->pppol2tp.s_tunnel == 0)
1475 goto end;
1476
1477 /* Special case: prepare tunnel socket if s_session and
1478 * d_session is 0. Otherwise look up tunnel using supplied
1479 * tunnel id.
1480 */
1481 if ((sp->pppol2tp.s_session == 0) && (sp->pppol2tp.d_session == 0)) {
1482 tunnel_sock = pppol2tp_prepare_tunnel_socket(sp->pppol2tp.fd,
1483 sp->pppol2tp.s_tunnel,
1484 &error);
1485 if (tunnel_sock == NULL)
1486 goto end;
1487
1488 tunnel = tunnel_sock->sk_user_data;
1489 } else {
1490 tunnel = pppol2tp_tunnel_find(sp->pppol2tp.s_tunnel);
1491
1492 /* Error if we can't find the tunnel */
1493 error = -ENOENT;
1494 if (tunnel == NULL)
1495 goto end;
1496
1497 tunnel_sock = tunnel->sock;
1498 }
1499
1500 /* Check that this session doesn't already exist */
1501 error = -EEXIST;
1502 session = pppol2tp_session_find(tunnel, sp->pppol2tp.s_session);
1503 if (session != NULL)
1504 goto end;
1505
1506 /* Allocate and initialize a new session context. */
1507 session = kzalloc(sizeof(struct pppol2tp_session), GFP_KERNEL);
1508 if (session == NULL) {
1509 error = -ENOMEM;
1510 goto end;
1511 }
1512
1513 skb_queue_head_init(&session->reorder_q);
1514
1515 session->magic = L2TP_SESSION_MAGIC;
1516 session->owner = current->pid;
1517 session->sock = sk;
1518 session->tunnel = tunnel;
1519 session->tunnel_sock = tunnel_sock;
1520 session->tunnel_addr = sp->pppol2tp;
1521 sprintf(&session->name[0], "sess %hu/%hu",
1522 session->tunnel_addr.s_tunnel,
1523 session->tunnel_addr.s_session);
1524
1525 session->stats.tunnel_id = session->tunnel_addr.s_tunnel;
1526 session->stats.session_id = session->tunnel_addr.s_session;
1527
1528 INIT_HLIST_NODE(&session->hlist);
1529
1530 /* Inherit debug options from tunnel */
1531 session->debug = tunnel->debug;
1532
1533 /* Default MTU must allow space for UDP/L2TP/PPP
1534 * headers.
1535 */
1536 session->mtu = session->mru = 1500 - PPPOL2TP_HEADER_OVERHEAD;
1537
1538 /* If PMTU discovery was enabled, use the MTU that was discovered */
1539 dst = sk_dst_get(sk);
1540 if (dst != NULL) {
1541 u32 pmtu = dst_mtu(__sk_dst_get(sk));
1542 if (pmtu != 0)
1543 session->mtu = session->mru = pmtu -
1544 PPPOL2TP_HEADER_OVERHEAD;
1545 dst_release(dst);
1546 }
1547
1548 /* Special case: if source & dest session_id == 0x0000, this socket is
1549 * being created to manage the tunnel. Don't add the session to the
1550 * session hash list, just set up the internal context for use by
1551 * ioctl() and sockopt() handlers.
1552 */
1553 if ((session->tunnel_addr.s_session == 0) &&
1554 (session->tunnel_addr.d_session == 0)) {
1555 error = 0;
1556 sk->sk_user_data = session;
1557 goto out_no_ppp;
1558 }
1559
1560 /* Get tunnel context from the tunnel socket */
1561 tunnel = pppol2tp_sock_to_tunnel(tunnel_sock);
1562 if (tunnel == NULL) {
1563 error = -EBADF;
1564 goto end;
1565 }
1566
1567 /* Right now, because we don't have a way to push the incoming skb's
1568 * straight through the UDP layer, the only header we need to worry
1569 * about is the L2TP header. This size is different depending on
1570 * whether sequence numbers are enabled for the data channel.
1571 */
1572 po->chan.hdrlen = PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1573
1574 po->chan.private = sk;
1575 po->chan.ops = &pppol2tp_chan_ops;
1576 po->chan.mtu = session->mtu;
1577
1578 error = ppp_register_channel(&po->chan);
1579 if (error)
1580 goto end;
1581
1582 /* This is how we get the session context from the socket. */
1583 sk->sk_user_data = session;
1584
1585 /* Add session to the tunnel's hash list */
1586 write_lock(&tunnel->hlist_lock);
1587 hlist_add_head(&session->hlist,
1588 pppol2tp_session_id_hash(tunnel,
1589 session->tunnel_addr.s_session));
1590 write_unlock(&tunnel->hlist_lock);
1591
1592 atomic_inc(&pppol2tp_session_count);
1593
1594out_no_ppp:
1595 pppol2tp_tunnel_inc_refcount(tunnel);
1596 sk->sk_state = PPPOX_CONNECTED;
1597 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1598 "%s: created\n", session->name);
1599
1600end:
1601 release_sock(sk);
1602
1603 if (error != 0)
1604 PRINTK(session ? session->debug : -1, PPPOL2TP_MSG_CONTROL, KERN_WARNING,
1605 "%s: connect failed: %d\n", session->name, error);
1606
1607 return error;
1608}
1609
1610/* getname() support.
1611 */
1612static int pppol2tp_getname(struct socket *sock, struct sockaddr *uaddr,
1613 int *usockaddr_len, int peer)
1614{
1615 int len = sizeof(struct sockaddr_pppol2tp);
1616 struct sockaddr_pppol2tp sp;
1617 int error = 0;
1618 struct pppol2tp_session *session;
1619
1620 error = -ENOTCONN;
1621 if (sock->sk->sk_state != PPPOX_CONNECTED)
1622 goto end;
1623
1624 session = pppol2tp_sock_to_session(sock->sk);
1625 if (session == NULL) {
1626 error = -EBADF;
1627 goto end;
1628 }
1629
1630 sp.sa_family = AF_PPPOX;
1631 sp.sa_protocol = PX_PROTO_OL2TP;
1632 memcpy(&sp.pppol2tp, &session->tunnel_addr,
1633 sizeof(struct pppol2tp_addr));
1634
1635 memcpy(uaddr, &sp, len);
1636
1637 *usockaddr_len = len;
1638
1639 error = 0;
1640
1641end:
1642 return error;
1643}
1644
1645/****************************************************************************
1646 * ioctl() handlers.
1647 *
1648 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1649 * sockets. However, in order to control kernel tunnel features, we allow
1650 * userspace to create a special "tunnel" PPPoX socket which is used for
1651 * control only. Tunnel PPPoX sockets have session_id == 0 and simply allow
1652 * the user application to issue L2TP setsockopt(), getsockopt() and ioctl()
1653 * calls.
1654 ****************************************************************************/
1655
1656/* Session ioctl helper.
1657 */
1658static int pppol2tp_session_ioctl(struct pppol2tp_session *session,
1659 unsigned int cmd, unsigned long arg)
1660{
1661 struct ifreq ifr;
1662 int err = 0;
1663 struct sock *sk = session->sock;
1664 int val = (int) arg;
1665
1666 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1667 "%s: pppol2tp_session_ioctl(cmd=%#x, arg=%#lx)\n",
1668 session->name, cmd, arg);
1669
1670 sock_hold(sk);
1671
1672 switch (cmd) {
1673 case SIOCGIFMTU:
1674 err = -ENXIO;
1675 if (!(sk->sk_state & PPPOX_CONNECTED))
1676 break;
1677
1678 err = -EFAULT;
1679 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1680 break;
1681 ifr.ifr_mtu = session->mtu;
1682 if (copy_to_user((void __user *) arg, &ifr, sizeof(struct ifreq)))
1683 break;
1684
1685 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1686 "%s: get mtu=%d\n", session->name, session->mtu);
1687 err = 0;
1688 break;
1689
1690 case SIOCSIFMTU:
1691 err = -ENXIO;
1692 if (!(sk->sk_state & PPPOX_CONNECTED))
1693 break;
1694
1695 err = -EFAULT;
1696 if (copy_from_user(&ifr, (void __user *) arg, sizeof(struct ifreq)))
1697 break;
1698
1699 session->mtu = ifr.ifr_mtu;
1700
1701 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1702 "%s: set mtu=%d\n", session->name, session->mtu);
1703 err = 0;
1704 break;
1705
1706 case PPPIOCGMRU:
1707 err = -ENXIO;
1708 if (!(sk->sk_state & PPPOX_CONNECTED))
1709 break;
1710
1711 err = -EFAULT;
1712 if (put_user(session->mru, (int __user *) arg))
1713 break;
1714
1715 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1716 "%s: get mru=%d\n", session->name, session->mru);
1717 err = 0;
1718 break;
1719
1720 case PPPIOCSMRU:
1721 err = -ENXIO;
1722 if (!(sk->sk_state & PPPOX_CONNECTED))
1723 break;
1724
1725 err = -EFAULT;
1726 if (get_user(val,(int __user *) arg))
1727 break;
1728
1729 session->mru = val;
1730 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1731 "%s: set mru=%d\n", session->name, session->mru);
1732 err = 0;
1733 break;
1734
1735 case PPPIOCGFLAGS:
1736 err = -EFAULT;
1737 if (put_user(session->flags, (int __user *) arg))
1738 break;
1739
1740 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1741 "%s: get flags=%d\n", session->name, session->flags);
1742 err = 0;
1743 break;
1744
1745 case PPPIOCSFLAGS:
1746 err = -EFAULT;
1747 if (get_user(val, (int __user *) arg))
1748 break;
1749 session->flags = val;
1750 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1751 "%s: set flags=%d\n", session->name, session->flags);
1752 err = 0;
1753 break;
1754
1755 case PPPIOCGL2TPSTATS:
1756 err = -ENXIO;
1757 if (!(sk->sk_state & PPPOX_CONNECTED))
1758 break;
1759
1760 if (copy_to_user((void __user *) arg, &session->stats,
1761 sizeof(session->stats)))
1762 break;
1763 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1764 "%s: get L2TP stats\n", session->name);
1765 err = 0;
1766 break;
1767
1768 default:
1769 err = -ENOSYS;
1770 break;
1771 }
1772
1773 sock_put(sk);
1774
1775 return err;
1776}
1777
1778/* Tunnel ioctl helper.
1779 *
1780 * Note the special handling for PPPIOCGL2TPSTATS below. If the ioctl data
1781 * specifies a session_id, the session ioctl handler is called. This allows an
1782 * application to retrieve session stats via a tunnel socket.
1783 */
1784static int pppol2tp_tunnel_ioctl(struct pppol2tp_tunnel *tunnel,
1785 unsigned int cmd, unsigned long arg)
1786{
1787 int err = 0;
1788 struct sock *sk = tunnel->sock;
1789 struct pppol2tp_ioc_stats stats_req;
1790
1791 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_DEBUG,
1792 "%s: pppol2tp_tunnel_ioctl(cmd=%#x, arg=%#lx)\n", tunnel->name,
1793 cmd, arg);
1794
1795 sock_hold(sk);
1796
1797 switch (cmd) {
1798 case PPPIOCGL2TPSTATS:
1799 err = -ENXIO;
1800 if (!(sk->sk_state & PPPOX_CONNECTED))
1801 break;
1802
1803 if (copy_from_user(&stats_req, (void __user *) arg,
1804 sizeof(stats_req))) {
1805 err = -EFAULT;
1806 break;
1807 }
1808 if (stats_req.session_id != 0) {
1809 /* resend to session ioctl handler */
1810 struct pppol2tp_session *session =
1811 pppol2tp_session_find(tunnel, stats_req.session_id);
1812 if (session != NULL)
1813 err = pppol2tp_session_ioctl(session, cmd, arg);
1814 else
1815 err = -EBADR;
1816 break;
1817 }
1818#ifdef CONFIG_XFRM
1819 tunnel->stats.using_ipsec = (sk->sk_policy[0] || sk->sk_policy[1]) ? 1 : 0;
1820#endif
1821 if (copy_to_user((void __user *) arg, &tunnel->stats,
1822 sizeof(tunnel->stats))) {
1823 err = -EFAULT;
1824 break;
1825 }
1826 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1827 "%s: get L2TP stats\n", tunnel->name);
1828 err = 0;
1829 break;
1830
1831 default:
1832 err = -ENOSYS;
1833 break;
1834 }
1835
1836 sock_put(sk);
1837
1838 return err;
1839}
1840
1841/* Main ioctl() handler.
1842 * Dispatch to tunnel or session helpers depending on the socket.
1843 */
1844static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd,
1845 unsigned long arg)
1846{
1847 struct sock *sk = sock->sk;
1848 struct pppol2tp_session *session;
1849 struct pppol2tp_tunnel *tunnel;
1850 int err;
1851
1852 if (!sk)
1853 return 0;
1854
1855 err = -EBADF;
1856 if (sock_flag(sk, SOCK_DEAD) != 0)
1857 goto end;
1858
1859 err = -ENOTCONN;
1860 if ((sk->sk_user_data == NULL) ||
1861 (!(sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND))))
1862 goto end;
1863
1864 /* Get session context from the socket */
1865 err = -EBADF;
1866 session = pppol2tp_sock_to_session(sk);
1867 if (session == NULL)
1868 goto end;
1869
1870 /* Special case: if session's session_id is zero, treat ioctl as a
1871 * tunnel ioctl
1872 */
1873 if ((session->tunnel_addr.s_session == 0) &&
1874 (session->tunnel_addr.d_session == 0)) {
1875 err = -EBADF;
1876 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
1877 if (tunnel == NULL)
1878 goto end;
1879
1880 err = pppol2tp_tunnel_ioctl(tunnel, cmd, arg);
1881 goto end;
1882 }
1883
1884 err = pppol2tp_session_ioctl(session, cmd, arg);
1885
1886end:
1887 return err;
1888}
1889
1890/*****************************************************************************
1891 * setsockopt() / getsockopt() support.
1892 *
1893 * The PPPoX socket is created for L2TP sessions: tunnels have their own UDP
1894 * sockets. In order to control kernel tunnel features, we allow userspace to
1895 * create a special "tunnel" PPPoX socket which is used for control only.
1896 * Tunnel PPPoX sockets have session_id == 0 and simply allow the user
1897 * application to issue L2TP setsockopt(), getsockopt() and ioctl() calls.
1898 *****************************************************************************/
1899
1900/* Tunnel setsockopt() helper.
1901 */
1902static int pppol2tp_tunnel_setsockopt(struct sock *sk,
1903 struct pppol2tp_tunnel *tunnel,
1904 int optname, int val)
1905{
1906 int err = 0;
1907
1908 switch (optname) {
1909 case PPPOL2TP_SO_DEBUG:
1910 tunnel->debug = val;
1911 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1912 "%s: set debug=%x\n", tunnel->name, tunnel->debug);
1913 break;
1914
1915 default:
1916 err = -ENOPROTOOPT;
1917 break;
1918 }
1919
1920 return err;
1921}
1922
1923/* Session setsockopt helper.
1924 */
1925static int pppol2tp_session_setsockopt(struct sock *sk,
1926 struct pppol2tp_session *session,
1927 int optname, int val)
1928{
1929 int err = 0;
1930
1931 switch (optname) {
1932 case PPPOL2TP_SO_RECVSEQ:
1933 if ((val != 0) && (val != 1)) {
1934 err = -EINVAL;
1935 break;
1936 }
1937 session->recv_seq = val ? -1 : 0;
1938 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1939 "%s: set recv_seq=%d\n", session->name,
1940 session->recv_seq);
1941 break;
1942
1943 case PPPOL2TP_SO_SENDSEQ:
1944 if ((val != 0) && (val != 1)) {
1945 err = -EINVAL;
1946 break;
1947 }
1948 session->send_seq = val ? -1 : 0;
1949 {
1950 struct sock *ssk = session->sock;
1951 struct pppox_sock *po = pppox_sk(ssk);
1952 po->chan.hdrlen = val ? PPPOL2TP_L2TP_HDR_SIZE_SEQ :
1953 PPPOL2TP_L2TP_HDR_SIZE_NOSEQ;
1954 }
1955 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1956 "%s: set send_seq=%d\n", session->name, session->send_seq);
1957 break;
1958
1959 case PPPOL2TP_SO_LNSMODE:
1960 if ((val != 0) && (val != 1)) {
1961 err = -EINVAL;
1962 break;
1963 }
1964 session->lns_mode = val ? -1 : 0;
1965 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1966 "%s: set lns_mode=%d\n", session->name,
1967 session->lns_mode);
1968 break;
1969
1970 case PPPOL2TP_SO_DEBUG:
1971 session->debug = val;
1972 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1973 "%s: set debug=%x\n", session->name, session->debug);
1974 break;
1975
1976 case PPPOL2TP_SO_REORDERTO:
1977 session->reorder_timeout = msecs_to_jiffies(val);
1978 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
1979 "%s: set reorder_timeout=%d\n", session->name,
1980 session->reorder_timeout);
1981 break;
1982
1983 default:
1984 err = -ENOPROTOOPT;
1985 break;
1986 }
1987
1988 return err;
1989}
1990
1991/* Main setsockopt() entry point.
1992 * Does API checks, then calls either the tunnel or session setsockopt
1993 * handler, according to whether the PPPoL2TP socket is a for a regular
1994 * session or the special tunnel type.
1995 */
1996static int pppol2tp_setsockopt(struct socket *sock, int level, int optname,
1997 char __user *optval, int optlen)
1998{
1999 struct sock *sk = sock->sk;
2000 struct pppol2tp_session *session = sk->sk_user_data;
2001 struct pppol2tp_tunnel *tunnel;
2002 int val;
2003 int err;
2004
2005 if (level != SOL_PPPOL2TP)
2006 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
2007
2008 if (optlen < sizeof(int))
2009 return -EINVAL;
2010
2011 if (get_user(val, (int __user *)optval))
2012 return -EFAULT;
2013
2014 err = -ENOTCONN;
2015 if (sk->sk_user_data == NULL)
2016 goto end;
2017
2018 /* Get session context from the socket */
2019 err = -EBADF;
2020 session = pppol2tp_sock_to_session(sk);
2021 if (session == NULL)
2022 goto end;
2023
2024 /* Special case: if session_id == 0x0000, treat as operation on tunnel
2025 */
2026 if ((session->tunnel_addr.s_session == 0) &&
2027 (session->tunnel_addr.d_session == 0)) {
2028 err = -EBADF;
2029 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
2030 if (tunnel == NULL)
2031 goto end;
2032
2033 err = pppol2tp_tunnel_setsockopt(sk, tunnel, optname, val);
2034 } else
2035 err = pppol2tp_session_setsockopt(sk, session, optname, val);
2036
2037 err = 0;
2038
2039end:
2040 return err;
2041}
2042
2043/* Tunnel getsockopt helper. Called with sock locked.
2044 */
2045static int pppol2tp_tunnel_getsockopt(struct sock *sk,
2046 struct pppol2tp_tunnel *tunnel,
2047 int optname, int __user *val)
2048{
2049 int err = 0;
2050
2051 switch (optname) {
2052 case PPPOL2TP_SO_DEBUG:
2053 *val = tunnel->debug;
2054 PRINTK(tunnel->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2055 "%s: get debug=%x\n", tunnel->name, tunnel->debug);
2056 break;
2057
2058 default:
2059 err = -ENOPROTOOPT;
2060 break;
2061 }
2062
2063 return err;
2064}
2065
2066/* Session getsockopt helper. Called with sock locked.
2067 */
2068static int pppol2tp_session_getsockopt(struct sock *sk,
2069 struct pppol2tp_session *session,
2070 int optname, int __user *val)
2071{
2072 int err = 0;
2073
2074 switch (optname) {
2075 case PPPOL2TP_SO_RECVSEQ:
2076 *val = session->recv_seq;
2077 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2078 "%s: get recv_seq=%d\n", session->name, *val);
2079 break;
2080
2081 case PPPOL2TP_SO_SENDSEQ:
2082 *val = session->send_seq;
2083 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2084 "%s: get send_seq=%d\n", session->name, *val);
2085 break;
2086
2087 case PPPOL2TP_SO_LNSMODE:
2088 *val = session->lns_mode;
2089 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2090 "%s: get lns_mode=%d\n", session->name, *val);
2091 break;
2092
2093 case PPPOL2TP_SO_DEBUG:
2094 *val = session->debug;
2095 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2096 "%s: get debug=%d\n", session->name, *val);
2097 break;
2098
2099 case PPPOL2TP_SO_REORDERTO:
2100 *val = (int) jiffies_to_msecs(session->reorder_timeout);
2101 PRINTK(session->debug, PPPOL2TP_MSG_CONTROL, KERN_INFO,
2102 "%s: get reorder_timeout=%d\n", session->name, *val);
2103 break;
2104
2105 default:
2106 err = -ENOPROTOOPT;
2107 }
2108
2109 return err;
2110}
2111
2112/* Main getsockopt() entry point.
2113 * Does API checks, then calls either the tunnel or session getsockopt
2114 * handler, according to whether the PPPoX socket is a for a regular session
2115 * or the special tunnel type.
2116 */
2117static int pppol2tp_getsockopt(struct socket *sock, int level,
2118 int optname, char __user *optval, int __user *optlen)
2119{
2120 struct sock *sk = sock->sk;
2121 struct pppol2tp_session *session = sk->sk_user_data;
2122 struct pppol2tp_tunnel *tunnel;
2123 int val, len;
2124 int err;
2125
2126 if (level != SOL_PPPOL2TP)
2127 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
2128
2129 if (get_user(len, (int __user *) optlen))
2130 return -EFAULT;
2131
2132 len = min_t(unsigned int, len, sizeof(int));
2133
2134 if (len < 0)
2135 return -EINVAL;
2136
2137 err = -ENOTCONN;
2138 if (sk->sk_user_data == NULL)
2139 goto end;
2140
2141 /* Get the session context */
2142 err = -EBADF;
2143 session = pppol2tp_sock_to_session(sk);
2144 if (session == NULL)
2145 goto end;
2146
2147 /* Special case: if session_id == 0x0000, treat as operation on tunnel */
2148 if ((session->tunnel_addr.s_session == 0) &&
2149 (session->tunnel_addr.d_session == 0)) {
2150 err = -EBADF;
2151 tunnel = pppol2tp_sock_to_tunnel(session->tunnel_sock);
2152 if (tunnel == NULL)
2153 goto end;
2154
2155 err = pppol2tp_tunnel_getsockopt(sk, tunnel, optname, &val);
2156 } else
2157 err = pppol2tp_session_getsockopt(sk, session, optname, &val);
2158
2159 err = -EFAULT;
2160 if (put_user(len, (int __user *) optlen))
2161 goto end;
2162
2163 if (copy_to_user((void __user *) optval, &val, len))
2164 goto end;
2165
2166 err = 0;
2167end:
2168 return err;
2169}
2170
2171/*****************************************************************************
2172 * /proc filesystem for debug
2173 *****************************************************************************/
2174
2175#ifdef CONFIG_PROC_FS
2176
2177#include <linux/seq_file.h>
2178
2179struct pppol2tp_seq_data {
2180 struct pppol2tp_tunnel *tunnel; /* current tunnel */
2181 struct pppol2tp_session *session; /* NULL means get first session in tunnel */
2182};
2183
2184static struct pppol2tp_session *next_session(struct pppol2tp_tunnel *tunnel, struct pppol2tp_session *curr)
2185{
2186 struct pppol2tp_session *session = NULL;
2187 struct hlist_node *walk;
2188 int found = 0;
2189 int next = 0;
2190 int i;
2191
2192 read_lock(&tunnel->hlist_lock);
2193 for (i = 0; i < PPPOL2TP_HASH_SIZE; i++) {
2194 hlist_for_each_entry(session, walk, &tunnel->session_hlist[i], hlist) {
2195 if (curr == NULL) {
2196 found = 1;
2197 goto out;
2198 }
2199 if (session == curr) {
2200 next = 1;
2201 continue;
2202 }
2203 if (next) {
2204 found = 1;
2205 goto out;
2206 }
2207 }
2208 }
2209out:
2210 read_unlock(&tunnel->hlist_lock);
2211 if (!found)
2212 session = NULL;
2213
2214 return session;
2215}
2216
2217static struct pppol2tp_tunnel *next_tunnel(struct pppol2tp_tunnel *curr)
2218{
2219 struct pppol2tp_tunnel *tunnel = NULL;
2220
2221 read_lock(&pppol2tp_tunnel_list_lock);
2222 if (list_is_last(&curr->list, &pppol2tp_tunnel_list)) {
2223 goto out;
2224 }
2225 tunnel = list_entry(curr->list.next, struct pppol2tp_tunnel, list);
2226out:
2227 read_unlock(&pppol2tp_tunnel_list_lock);
2228
2229 return tunnel;
2230}
2231
2232static void *pppol2tp_seq_start(struct seq_file *m, loff_t *offs)
2233{
2234 struct pppol2tp_seq_data *pd = SEQ_START_TOKEN;
2235 loff_t pos = *offs;
2236
2237 if (!pos)
2238 goto out;
2239
2240 BUG_ON(m->private == NULL);
2241 pd = m->private;
2242
2243 if (pd->tunnel == NULL) {
2244 if (!list_empty(&pppol2tp_tunnel_list))
2245 pd->tunnel = list_entry(pppol2tp_tunnel_list.next, struct pppol2tp_tunnel, list);
2246 } else {
2247 pd->session = next_session(pd->tunnel, pd->session);
2248 if (pd->session == NULL) {
2249 pd->tunnel = next_tunnel(pd->tunnel);
2250 }
2251 }
2252
2253 /* NULL tunnel and session indicates end of list */
2254 if ((pd->tunnel == NULL) && (pd->session == NULL))
2255 pd = NULL;
2256
2257out:
2258 return pd;
2259}
2260
2261static void *pppol2tp_seq_next(struct seq_file *m, void *v, loff_t *pos)
2262{
2263 (*pos)++;
2264 return NULL;
2265}
2266
2267static void pppol2tp_seq_stop(struct seq_file *p, void *v)
2268{
2269 /* nothing to do */
2270}
2271
2272static void pppol2tp_seq_tunnel_show(struct seq_file *m, void *v)
2273{
2274 struct pppol2tp_tunnel *tunnel = v;
2275
2276 seq_printf(m, "\nTUNNEL '%s', %c %d\n",
2277 tunnel->name,
2278 (tunnel == tunnel->sock->sk_user_data) ? 'Y':'N',
2279 atomic_read(&tunnel->ref_count) - 1);
2280 seq_printf(m, " %08x %llu/%llu/%llu %llu/%llu/%llu\n",
2281 tunnel->debug,
2282 tunnel->stats.tx_packets, tunnel->stats.tx_bytes,
2283 tunnel->stats.tx_errors,
2284 tunnel->stats.rx_packets, tunnel->stats.rx_bytes,
2285 tunnel->stats.rx_errors);
2286}
2287
2288static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
2289{
2290 struct pppol2tp_session *session = v;
2291
2292 seq_printf(m, " SESSION '%s' %08X/%d %04X/%04X -> "
2293 "%04X/%04X %d %c\n",
2294 session->name,
2295 ntohl(session->tunnel_addr.addr.sin_addr.s_addr),
2296 ntohs(session->tunnel_addr.addr.sin_port),
2297 session->tunnel_addr.s_tunnel,
2298 session->tunnel_addr.s_session,
2299 session->tunnel_addr.d_tunnel,
2300 session->tunnel_addr.d_session,
2301 session->sock->sk_state,
2302 (session == session->sock->sk_user_data) ?
2303 'Y' : 'N');
2304 seq_printf(m, " %d/%d/%c/%c/%s %08x %u\n",
2305 session->mtu, session->mru,
2306 session->recv_seq ? 'R' : '-',
2307 session->send_seq ? 'S' : '-',
2308 session->lns_mode ? "LNS" : "LAC",
2309 session->debug,
2310 jiffies_to_msecs(session->reorder_timeout));
2311 seq_printf(m, " %hu/%hu %llu/%llu/%llu %llu/%llu/%llu\n",
2312 session->nr, session->ns,
2313 session->stats.tx_packets,
2314 session->stats.tx_bytes,
2315 session->stats.tx_errors,
2316 session->stats.rx_packets,
2317 session->stats.rx_bytes,
2318 session->stats.rx_errors);
2319}
2320
2321static int pppol2tp_seq_show(struct seq_file *m, void *v)
2322{
2323 struct pppol2tp_seq_data *pd = v;
2324
2325 /* display header on line 1 */
2326 if (v == SEQ_START_TOKEN) {
2327 seq_puts(m, "PPPoL2TP driver info, " PPPOL2TP_DRV_VERSION "\n");
2328 seq_puts(m, "TUNNEL name, user-data-ok session-count\n");
2329 seq_puts(m, " debug tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
2330 seq_puts(m, " SESSION name, addr/port src-tid/sid "
2331 "dest-tid/sid state user-data-ok\n");
2332 seq_puts(m, " mtu/mru/rcvseq/sendseq/lns debug reorderto\n");
2333 seq_puts(m, " nr/ns tx-pkts/bytes/errs rx-pkts/bytes/errs\n");
2334 goto out;
2335 }
2336
2337 /* Show the tunnel or session context.
2338 */
2339 if (pd->session == NULL)
2340 pppol2tp_seq_tunnel_show(m, pd->tunnel);
2341 else
2342 pppol2tp_seq_session_show(m, pd->session);
2343
2344out:
2345 return 0;
2346}
2347
2348static struct seq_operations pppol2tp_seq_ops = {
2349 .start = pppol2tp_seq_start,
2350 .next = pppol2tp_seq_next,
2351 .stop = pppol2tp_seq_stop,
2352 .show = pppol2tp_seq_show,
2353};
2354
2355/* Called when our /proc file is opened. We allocate data for use when
2356 * iterating our tunnel / session contexts and store it in the private
2357 * data of the seq_file.
2358 */
2359static int pppol2tp_proc_open(struct inode *inode, struct file *file)
2360{
2361 struct seq_file *m;
2362 struct pppol2tp_seq_data *pd;
2363 int ret = 0;
2364
2365 ret = seq_open(file, &pppol2tp_seq_ops);
2366 if (ret < 0)
2367 goto out;
2368
2369 m = file->private_data;
2370
2371 /* Allocate and fill our proc_data for access later */
2372 ret = -ENOMEM;
2373 m->private = kzalloc(sizeof(struct pppol2tp_seq_data), GFP_KERNEL);
2374 if (m->private == NULL)
2375 goto out;
2376
2377 pd = m->private;
2378 ret = 0;
2379
2380out:
2381 return ret;
2382}
2383
2384/* Called when /proc file access completes.
2385 */
2386static int pppol2tp_proc_release(struct inode *inode, struct file *file)
2387{
2388 struct seq_file *m = (struct seq_file *)file->private_data;
2389
2390 kfree(m->private);
2391 m->private = NULL;
2392
2393 return seq_release(inode, file);
2394}
2395
2396static struct file_operations pppol2tp_proc_fops = {
2397 .owner = THIS_MODULE,
2398 .open = pppol2tp_proc_open,
2399 .read = seq_read,
2400 .llseek = seq_lseek,
2401 .release = pppol2tp_proc_release,
2402};
2403
2404static struct proc_dir_entry *pppol2tp_proc;
2405
2406#endif /* CONFIG_PROC_FS */
2407
2408/*****************************************************************************
2409 * Init and cleanup
2410 *****************************************************************************/
2411
2412static struct proto_ops pppol2tp_ops = {
2413 .family = AF_PPPOX,
2414 .owner = THIS_MODULE,
2415 .release = pppol2tp_release,
2416 .bind = sock_no_bind,
2417 .connect = pppol2tp_connect,
2418 .socketpair = sock_no_socketpair,
2419 .accept = sock_no_accept,
2420 .getname = pppol2tp_getname,
2421 .poll = datagram_poll,
2422 .listen = sock_no_listen,
2423 .shutdown = sock_no_shutdown,
2424 .setsockopt = pppol2tp_setsockopt,
2425 .getsockopt = pppol2tp_getsockopt,
2426 .sendmsg = pppol2tp_sendmsg,
2427 .recvmsg = pppol2tp_recvmsg,
2428 .mmap = sock_no_mmap,
2429 .ioctl = pppox_ioctl,
2430};
2431
2432static struct pppox_proto pppol2tp_proto = {
2433 .create = pppol2tp_create,
2434 .ioctl = pppol2tp_ioctl
2435};
2436
2437static int __init pppol2tp_init(void)
2438{
2439 int err;
2440
2441 err = proto_register(&pppol2tp_sk_proto, 0);
2442 if (err)
2443 goto out;
2444 err = register_pppox_proto(PX_PROTO_OL2TP, &pppol2tp_proto);
2445 if (err)
2446 goto out_unregister_pppol2tp_proto;
2447
2448#ifdef CONFIG_PROC_FS
2449 pppol2tp_proc = create_proc_entry("pppol2tp", 0, proc_net);
2450 if (!pppol2tp_proc) {
2451 err = -ENOMEM;
2452 goto out_unregister_pppox_proto;
2453 }
2454 pppol2tp_proc->proc_fops = &pppol2tp_proc_fops;
2455#endif /* CONFIG_PROC_FS */
2456 printk(KERN_INFO "PPPoL2TP kernel driver, %s\n",
2457 PPPOL2TP_DRV_VERSION);
2458
2459out:
2460 return err;
2461
2462out_unregister_pppox_proto:
2463 unregister_pppox_proto(PX_PROTO_OL2TP);
2464out_unregister_pppol2tp_proto:
2465 proto_unregister(&pppol2tp_sk_proto);
2466 goto out;
2467}
2468
2469static void __exit pppol2tp_exit(void)
2470{
2471 unregister_pppox_proto(PX_PROTO_OL2TP);
2472
2473#ifdef CONFIG_PROC_FS
2474 remove_proc_entry("pppol2tp", proc_net);
2475#endif
2476 proto_unregister(&pppol2tp_sk_proto);
2477}
2478
2479module_init(pppol2tp_init);
2480module_exit(pppol2tp_exit);
2481
2482MODULE_AUTHOR("Martijn van Oosterhout <kleptog@svana.org>,"
2483 "James Chapman <jchapman@katalix.com>");
2484MODULE_DESCRIPTION("PPP over L2TP over UDP");
2485MODULE_LICENSE("GPL");
2486MODULE_VERSION(PPPOL2TP_DRV_VERSION);
diff --git a/drivers/net/saa9730.c b/drivers/net/saa9730.c
index ad94358ece89..451486b32f23 100644
--- a/drivers/net/saa9730.c
+++ b/drivers/net/saa9730.c
@@ -690,9 +690,9 @@ static int lan_saa9730_rx(struct net_device *dev)
690 lp->stats.rx_packets++; 690 lp->stats.rx_packets++;
691 skb_reserve(skb, 2); /* 16 byte align */ 691 skb_reserve(skb, 2); /* 16 byte align */
692 skb_put(skb, len); /* make room */ 692 skb_put(skb, len); /* make room */
693 eth_copy_and_sum(skb, 693 skb_copy_to_linear_data(skb,
694 (unsigned char *) pData, 694 (unsigned char *) pData,
695 len, 0); 695 len);
696 skb->protocol = eth_type_trans(skb, dev); 696 skb->protocol = eth_type_trans(skb, dev);
697 netif_rx(skb); 697 netif_rx(skb);
698 dev->last_rx = jiffies; 698 dev->last_rx = jiffies;
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 2106becf6990..384b4685e977 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -320,7 +320,7 @@ static inline void sgiseeq_rx(struct net_device *dev, struct sgiseeq_private *sp
320 skb_put(skb, len); 320 skb_put(skb, len);
321 321
322 /* Copy out of kseg1 to avoid silly cache flush. */ 322 /* Copy out of kseg1 to avoid silly cache flush. */
323 eth_copy_and_sum(skb, pkt_pointer + 2, len, 0); 323 skb_copy_to_linear_data(skb, pkt_pointer + 2, len);
324 skb->protocol = eth_type_trans(skb, dev); 324 skb->protocol = eth_type_trans(skb, dev);
325 325
326 /* We don't want to receive our own packets */ 326 /* We don't want to receive our own packets */
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index bc8de48da313..ec2ad9f0efa2 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -548,7 +548,7 @@ static inline int sis190_try_rx_copy(struct sk_buff **sk_buff, int pkt_size,
548 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); 548 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN);
549 if (skb) { 549 if (skb) {
550 skb_reserve(skb, NET_IP_ALIGN); 550 skb_reserve(skb, NET_IP_ALIGN);
551 eth_copy_and_sum(skb, sk_buff[0]->data, pkt_size, 0); 551 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
552 *sk_buff = skb; 552 *sk_buff = skb;
553 sis190_give_to_asic(desc, rx_buf_sz); 553 sis190_give_to_asic(desc, rx_buf_sz);
554 ret = 0; 554 ret = 0;
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 2f69d5c5dfa6..8b6478663a56 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -1456,7 +1456,7 @@ static int __netdev_rx(struct net_device *dev, int *quota)
1456 pci_dma_sync_single_for_cpu(np->pci_dev, 1456 pci_dma_sync_single_for_cpu(np->pci_dev,
1457 np->rx_info[entry].mapping, 1457 np->rx_info[entry].mapping,
1458 pkt_len, PCI_DMA_FROMDEVICE); 1458 pkt_len, PCI_DMA_FROMDEVICE);
1459 eth_copy_and_sum(skb, np->rx_info[entry].skb->data, pkt_len, 0); 1459 skb_copy_to_linear_data(skb, np->rx_info[entry].skb->data, pkt_len);
1460 pci_dma_sync_single_for_device(np->pci_dev, 1460 pci_dma_sync_single_for_device(np->pci_dev,
1461 np->rx_info[entry].mapping, 1461 np->rx_info[entry].mapping,
1462 pkt_len, PCI_DMA_FROMDEVICE); 1462 pkt_len, PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/sun3_82586.c b/drivers/net/sun3_82586.c
index a123ea87893b..b77ab6e8fd35 100644
--- a/drivers/net/sun3_82586.c
+++ b/drivers/net/sun3_82586.c
@@ -777,7 +777,7 @@ static void sun3_82586_rcv_int(struct net_device *dev)
777 { 777 {
778 skb_reserve(skb,2); 778 skb_reserve(skb,2);
779 skb_put(skb,totlen); 779 skb_put(skb,totlen);
780 eth_copy_and_sum(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen,0); 780 skb_copy_to_linear_data(skb,(char *) p->base+swab32((unsigned long) rbd->buffer),totlen);
781 skb->protocol=eth_type_trans(skb,dev); 781 skb->protocol=eth_type_trans(skb,dev);
782 netif_rx(skb); 782 netif_rx(skb);
783 p->stats.rx_packets++; 783 p->stats.rx_packets++;
diff --git a/drivers/net/sun3lance.c b/drivers/net/sun3lance.c
index 791e081fdc15..f1548c033327 100644
--- a/drivers/net/sun3lance.c
+++ b/drivers/net/sun3lance.c
@@ -853,10 +853,9 @@ static int lance_rx( struct net_device *dev )
853 853
854 skb_reserve( skb, 2 ); /* 16 byte align */ 854 skb_reserve( skb, 2 ); /* 16 byte align */
855 skb_put( skb, pkt_len ); /* Make room */ 855 skb_put( skb, pkt_len ); /* Make room */
856// skb_copy_to_linear_data(skb, PKTBUF_ADDR(head), pkt_len); 856 skb_copy_to_linear_data(skb,
857 eth_copy_and_sum(skb,
858 PKTBUF_ADDR(head), 857 PKTBUF_ADDR(head),
859 pkt_len, 0); 858 pkt_len);
860 859
861 skb->protocol = eth_type_trans( skb, dev ); 860 skb->protocol = eth_type_trans( skb, dev );
862 netif_rx( skb ); 861 netif_rx( skb );
diff --git a/drivers/net/sunbmac.c b/drivers/net/sunbmac.c
index 2ad8d58dee3b..b3e0158def4f 100644
--- a/drivers/net/sunbmac.c
+++ b/drivers/net/sunbmac.c
@@ -860,7 +860,7 @@ static void bigmac_rx(struct bigmac *bp)
860 sbus_dma_sync_single_for_cpu(bp->bigmac_sdev, 860 sbus_dma_sync_single_for_cpu(bp->bigmac_sdev,
861 this->rx_addr, len, 861 this->rx_addr, len,
862 SBUS_DMA_FROMDEVICE); 862 SBUS_DMA_FROMDEVICE);
863 eth_copy_and_sum(copy_skb, (unsigned char *)skb->data, len, 0); 863 skb_copy_to_linear_data(copy_skb, (unsigned char *)skb->data, len);
864 sbus_dma_sync_single_for_device(bp->bigmac_sdev, 864 sbus_dma_sync_single_for_device(bp->bigmac_sdev,
865 this->rx_addr, len, 865 this->rx_addr, len,
866 SBUS_DMA_FROMDEVICE); 866 SBUS_DMA_FROMDEVICE);
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index c9f7b7aa5556..af0c9831074c 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -1310,7 +1310,7 @@ static void rx_poll(unsigned long data)
1310 np->rx_buf_sz, 1310 np->rx_buf_sz,
1311 PCI_DMA_FROMDEVICE); 1311 PCI_DMA_FROMDEVICE);
1312 1312
1313 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0); 1313 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len);
1314 pci_dma_sync_single_for_device(np->pci_dev, 1314 pci_dma_sync_single_for_device(np->pci_dev,
1315 desc->frag[0].addr, 1315 desc->frag[0].addr,
1316 np->rx_buf_sz, 1316 np->rx_buf_sz,
diff --git a/drivers/net/sunlance.c b/drivers/net/sunlance.c
index 42722530ab24..053b7cb0d944 100644
--- a/drivers/net/sunlance.c
+++ b/drivers/net/sunlance.c
@@ -549,9 +549,9 @@ static void lance_rx_dvma(struct net_device *dev)
549 549
550 skb_reserve(skb, 2); /* 16 byte align */ 550 skb_reserve(skb, 2); /* 16 byte align */
551 skb_put(skb, len); /* make room */ 551 skb_put(skb, len); /* make room */
552 eth_copy_and_sum(skb, 552 skb_copy_to_linear_data(skb,
553 (unsigned char *)&(ib->rx_buf [entry][0]), 553 (unsigned char *)&(ib->rx_buf [entry][0]),
554 len, 0); 554 len);
555 skb->protocol = eth_type_trans(skb, dev); 555 skb->protocol = eth_type_trans(skb, dev);
556 netif_rx(skb); 556 netif_rx(skb);
557 dev->last_rx = jiffies; 557 dev->last_rx = jiffies;
diff --git a/drivers/net/sunqe.c b/drivers/net/sunqe.c
index fa70e0b78af7..1b65ae8a1c7c 100644
--- a/drivers/net/sunqe.c
+++ b/drivers/net/sunqe.c
@@ -439,8 +439,8 @@ static void qe_rx(struct sunqe *qep)
439 } else { 439 } else {
440 skb_reserve(skb, 2); 440 skb_reserve(skb, 2);
441 skb_put(skb, len); 441 skb_put(skb, len);
442 eth_copy_and_sum(skb, (unsigned char *) this_qbuf, 442 skb_copy_to_linear_data(skb, (unsigned char *) this_qbuf,
443 len, 0); 443 len);
444 skb->protocol = eth_type_trans(skb, qep->dev); 444 skb->protocol = eth_type_trans(skb, qep->dev);
445 netif_rx(skb); 445 netif_rx(skb);
446 qep->dev->last_rx = jiffies; 446 qep->dev->last_rx = jiffies;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index b148d57ec571..32e4037dcb50 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -64,8 +64,8 @@
64 64
65#define DRV_MODULE_NAME "tg3" 65#define DRV_MODULE_NAME "tg3"
66#define PFX DRV_MODULE_NAME ": " 66#define PFX DRV_MODULE_NAME ": "
67#define DRV_MODULE_VERSION "3.77" 67#define DRV_MODULE_VERSION "3.78"
68#define DRV_MODULE_RELDATE "May 31, 2007" 68#define DRV_MODULE_RELDATE "July 11, 2007"
69 69
70#define TG3_DEF_MAC_MODE 0 70#define TG3_DEF_MAC_MODE 0
71#define TG3_DEF_RX_MODE 0 71#define TG3_DEF_RX_MODE 0
@@ -721,6 +721,44 @@ static int tg3_writephy(struct tg3 *tp, int reg, u32 val)
721 return ret; 721 return ret;
722} 722}
723 723
724static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable)
725{
726 u32 phy;
727
728 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ||
729 (tp->tg3_flags2 & TG3_FLG2_ANY_SERDES))
730 return;
731
732 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
733 u32 ephy;
734
735 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &ephy)) {
736 tg3_writephy(tp, MII_TG3_EPHY_TEST,
737 ephy | MII_TG3_EPHY_SHADOW_EN);
738 if (!tg3_readphy(tp, MII_TG3_EPHYTST_MISCCTRL, &phy)) {
739 if (enable)
740 phy |= MII_TG3_EPHYTST_MISCCTRL_MDIX;
741 else
742 phy &= ~MII_TG3_EPHYTST_MISCCTRL_MDIX;
743 tg3_writephy(tp, MII_TG3_EPHYTST_MISCCTRL, phy);
744 }
745 tg3_writephy(tp, MII_TG3_EPHY_TEST, ephy);
746 }
747 } else {
748 phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC |
749 MII_TG3_AUXCTL_SHDWSEL_MISC;
750 if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) &&
751 !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) {
752 if (enable)
753 phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
754 else
755 phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX;
756 phy |= MII_TG3_AUXCTL_MISC_WREN;
757 tg3_writephy(tp, MII_TG3_AUX_CTRL, phy);
758 }
759 }
760}
761
724static void tg3_phy_set_wirespeed(struct tg3 *tp) 762static void tg3_phy_set_wirespeed(struct tg3 *tp)
725{ 763{
726 u32 val; 764 u32 val;
@@ -1045,23 +1083,11 @@ out:
1045 } 1083 }
1046 1084
1047 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { 1085 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1048 u32 phy_reg;
1049
1050 /* adjust output voltage */ 1086 /* adjust output voltage */
1051 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12); 1087 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x12);
1052
1053 if (!tg3_readphy(tp, MII_TG3_EPHY_TEST, &phy_reg)) {
1054 u32 phy_reg2;
1055
1056 tg3_writephy(tp, MII_TG3_EPHY_TEST,
1057 phy_reg | MII_TG3_EPHY_SHADOW_EN);
1058 /* Enable auto-MDIX */
1059 if (!tg3_readphy(tp, 0x10, &phy_reg2))
1060 tg3_writephy(tp, 0x10, phy_reg2 | 0x4000);
1061 tg3_writephy(tp, MII_TG3_EPHY_TEST, phy_reg);
1062 }
1063 } 1088 }
1064 1089
1090 tg3_phy_toggle_automdix(tp, 1);
1065 tg3_phy_set_wirespeed(tp); 1091 tg3_phy_set_wirespeed(tp);
1066 return 0; 1092 return 0;
1067} 1093}
@@ -1162,6 +1188,19 @@ static void tg3_frob_aux_power(struct tg3 *tp)
1162 } 1188 }
1163} 1189}
1164 1190
1191static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed)
1192{
1193 if (tp->led_ctrl == LED_CTRL_MODE_PHY_2)
1194 return 1;
1195 else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411) {
1196 if (speed != SPEED_10)
1197 return 1;
1198 } else if (speed == SPEED_10)
1199 return 1;
1200
1201 return 0;
1202}
1203
1165static int tg3_setup_phy(struct tg3 *, int); 1204static int tg3_setup_phy(struct tg3 *, int);
1166 1205
1167#define RESET_KIND_SHUTDOWN 0 1206#define RESET_KIND_SHUTDOWN 0
@@ -1320,9 +1359,17 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1320 else 1359 else
1321 mac_mode = MAC_MODE_PORT_MODE_MII; 1360 mac_mode = MAC_MODE_PORT_MODE_MII;
1322 1361
1323 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 || 1362 mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY;
1324 !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB)) 1363 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
1325 mac_mode |= MAC_MODE_LINK_POLARITY; 1364 ASIC_REV_5700) {
1365 u32 speed = (tp->tg3_flags &
1366 TG3_FLAG_WOL_SPEED_100MB) ?
1367 SPEED_100 : SPEED_10;
1368 if (tg3_5700_link_polarity(tp, speed))
1369 mac_mode |= MAC_MODE_LINK_POLARITY;
1370 else
1371 mac_mode &= ~MAC_MODE_LINK_POLARITY;
1372 }
1326 } else { 1373 } else {
1327 mac_mode = MAC_MODE_PORT_MODE_TBI; 1374 mac_mode = MAC_MODE_PORT_MODE_TBI;
1328 } 1375 }
@@ -1990,15 +2037,12 @@ relink:
1990 if (tp->link_config.active_duplex == DUPLEX_HALF) 2037 if (tp->link_config.active_duplex == DUPLEX_HALF)
1991 tp->mac_mode |= MAC_MODE_HALF_DUPLEX; 2038 tp->mac_mode |= MAC_MODE_HALF_DUPLEX;
1992 2039
1993 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
1994 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { 2040 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
1995 if ((tp->led_ctrl == LED_CTRL_MODE_PHY_2) || 2041 if (current_link_up == 1 &&
1996 (current_link_up == 1 && 2042 tg3_5700_link_polarity(tp, tp->link_config.active_speed))
1997 tp->link_config.active_speed == SPEED_10))
1998 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
1999 } else {
2000 if (current_link_up == 1)
2001 tp->mac_mode |= MAC_MODE_LINK_POLARITY; 2043 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
2044 else
2045 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2002 } 2046 }
2003 2047
2004 /* ??? Without this setting Netgear GA302T PHY does not 2048 /* ??? Without this setting Netgear GA302T PHY does not
@@ -2639,6 +2683,9 @@ static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status)
2639 2683
2640 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); 2684 tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS));
2641 udelay(40); 2685 udelay(40);
2686
2687 tw32_f(MAC_MODE, tp->mac_mode);
2688 udelay(40);
2642 } 2689 }
2643 2690
2644out: 2691out:
@@ -2698,10 +2745,6 @@ static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset)
2698 else 2745 else
2699 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); 2746 current_link_up = tg3_setup_fiber_by_hand(tp, mac_status);
2700 2747
2701 tp->mac_mode &= ~MAC_MODE_LINK_POLARITY;
2702 tw32_f(MAC_MODE, tp->mac_mode);
2703 udelay(40);
2704
2705 tp->hw_status->status = 2748 tp->hw_status->status =
2706 (SD_STATUS_UPDATED | 2749 (SD_STATUS_UPDATED |
2707 (tp->hw_status->status & ~SD_STATUS_LINK_CHG)); 2750 (tp->hw_status->status & ~SD_STATUS_LINK_CHG));
@@ -3512,9 +3555,9 @@ static inline int tg3_irq_sync(struct tg3 *tp)
3512 */ 3555 */
3513static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) 3556static inline void tg3_full_lock(struct tg3 *tp, int irq_sync)
3514{ 3557{
3558 spin_lock_bh(&tp->lock);
3515 if (irq_sync) 3559 if (irq_sync)
3516 tg3_irq_quiesce(tp); 3560 tg3_irq_quiesce(tp);
3517 spin_lock_bh(&tp->lock);
3518} 3561}
3519 3562
3520static inline void tg3_full_unlock(struct tg3 *tp) 3563static inline void tg3_full_unlock(struct tg3 *tp)
@@ -6444,6 +6487,10 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
6444 6487
6445 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | 6488 tp->mac_mode = MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE |
6446 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; 6489 MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE;
6490 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) &&
6491 !(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) &&
6492 GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)
6493 tp->mac_mode |= MAC_MODE_LINK_POLARITY;
6447 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); 6494 tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR);
6448 udelay(40); 6495 udelay(40);
6449 6496
@@ -8805,7 +8852,9 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8805 return 0; 8852 return 0;
8806 8853
8807 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8854 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8808 MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY; 8855 MAC_MODE_PORT_INT_LPBACK;
8856 if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS))
8857 mac_mode |= MAC_MODE_LINK_POLARITY;
8809 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY) 8858 if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
8810 mac_mode |= MAC_MODE_PORT_MODE_MII; 8859 mac_mode |= MAC_MODE_PORT_MODE_MII;
8811 else 8860 else
@@ -8824,19 +8873,18 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8824 phytest | MII_TG3_EPHY_SHADOW_EN); 8873 phytest | MII_TG3_EPHY_SHADOW_EN);
8825 if (!tg3_readphy(tp, 0x1b, &phy)) 8874 if (!tg3_readphy(tp, 0x1b, &phy))
8826 tg3_writephy(tp, 0x1b, phy & ~0x20); 8875 tg3_writephy(tp, 0x1b, phy & ~0x20);
8827 if (!tg3_readphy(tp, 0x10, &phy))
8828 tg3_writephy(tp, 0x10, phy & ~0x4000);
8829 tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest); 8876 tg3_writephy(tp, MII_TG3_EPHY_TEST, phytest);
8830 } 8877 }
8831 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; 8878 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100;
8832 } else 8879 } else
8833 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; 8880 val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
8834 8881
8882 tg3_phy_toggle_automdix(tp, 0);
8883
8835 tg3_writephy(tp, MII_BMCR, val); 8884 tg3_writephy(tp, MII_BMCR, val);
8836 udelay(40); 8885 udelay(40);
8837 8886
8838 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8887 mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK;
8839 MAC_MODE_LINK_POLARITY;
8840 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { 8888 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
8841 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800); 8889 tg3_writephy(tp, MII_TG3_EPHY_PTEST, 0x1800);
8842 mac_mode |= MAC_MODE_PORT_MODE_MII; 8890 mac_mode |= MAC_MODE_PORT_MODE_MII;
@@ -8849,8 +8897,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8849 udelay(10); 8897 udelay(10);
8850 tw32_f(MAC_RX_MODE, tp->rx_mode); 8898 tw32_f(MAC_RX_MODE, tp->rx_mode);
8851 } 8899 }
8852 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) { 8900 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) {
8853 mac_mode &= ~MAC_MODE_LINK_POLARITY; 8901 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401)
8902 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8903 else if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411)
8904 mac_mode |= MAC_MODE_LINK_POLARITY;
8854 tg3_writephy(tp, MII_TG3_EXT_CTRL, 8905 tg3_writephy(tp, MII_TG3_EXT_CTRL,
8855 MII_TG3_EXT_CTRL_LNK3_LED_MODE); 8906 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
8856 } 8907 }
@@ -9116,10 +9167,10 @@ static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
9116 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ 9167 /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */
9117 __tg3_set_rx_mode(dev); 9168 __tg3_set_rx_mode(dev);
9118 9169
9119 tg3_full_unlock(tp);
9120
9121 if (netif_running(dev)) 9170 if (netif_running(dev))
9122 tg3_netif_start(tp); 9171 tg3_netif_start(tp);
9172
9173 tg3_full_unlock(tp);
9123} 9174}
9124#endif 9175#endif
9125 9176
@@ -9410,11 +9461,13 @@ static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
9410 case FLASH_5755VENDOR_ATMEL_FLASH_1: 9461 case FLASH_5755VENDOR_ATMEL_FLASH_1:
9411 case FLASH_5755VENDOR_ATMEL_FLASH_2: 9462 case FLASH_5755VENDOR_ATMEL_FLASH_2:
9412 case FLASH_5755VENDOR_ATMEL_FLASH_3: 9463 case FLASH_5755VENDOR_ATMEL_FLASH_3:
9464 case FLASH_5755VENDOR_ATMEL_FLASH_5:
9413 tp->nvram_jedecnum = JEDEC_ATMEL; 9465 tp->nvram_jedecnum = JEDEC_ATMEL;
9414 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; 9466 tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED;
9415 tp->tg3_flags2 |= TG3_FLG2_FLASH; 9467 tp->tg3_flags2 |= TG3_FLG2_FLASH;
9416 tp->nvram_pagesize = 264; 9468 tp->nvram_pagesize = 264;
9417 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1) 9469 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
9470 nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
9418 tp->nvram_size = (protect ? 0x3e200 : 0x80000); 9471 tp->nvram_size = (protect ? 0x3e200 : 0x80000);
9419 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) 9472 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
9420 tp->nvram_size = (protect ? 0x1f200 : 0x40000); 9473 tp->nvram_size = (protect ? 0x1f200 : 0x40000);
@@ -11940,12 +11993,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11940 * checksumming. 11993 * checksumming.
11941 */ 11994 */
11942 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) { 11995 if ((tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) == 0) {
11996 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
11943 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || 11997 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
11944 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) 11998 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
11945 dev->features |= NETIF_F_HW_CSUM; 11999 dev->features |= NETIF_F_IPV6_CSUM;
11946 else 12000
11947 dev->features |= NETIF_F_IP_CSUM;
11948 dev->features |= NETIF_F_SG;
11949 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; 12001 tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS;
11950 } else 12002 } else
11951 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; 12003 tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS;
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index bd9f4f428e5b..d84e75e7365d 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -1467,6 +1467,7 @@
1467#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002 1467#define FLASH_5755VENDOR_ATMEL_FLASH_2 0x03400002
1468#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000 1468#define FLASH_5755VENDOR_ATMEL_FLASH_3 0x03400000
1469#define FLASH_5755VENDOR_ATMEL_FLASH_4 0x00000003 1469#define FLASH_5755VENDOR_ATMEL_FLASH_4 0x00000003
1470#define FLASH_5755VENDOR_ATMEL_FLASH_5 0x02000003
1470#define FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ 0x03c00003 1471#define FLASH_5755VENDOR_ATMEL_EEPROM_64KHZ 0x03c00003
1471#define FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ 0x03c00002 1472#define FLASH_5755VENDOR_ATMEL_EEPROM_376KHZ 0x03c00002
1472#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003 1473#define FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ 0x03000003
@@ -1642,6 +1643,11 @@
1642 1643
1643#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */ 1644#define MII_TG3_AUX_CTRL 0x18 /* auxilliary control register */
1644 1645
1646#define MII_TG3_AUXCTL_MISC_WREN 0x8000
1647#define MII_TG3_AUXCTL_MISC_FORCE_AMDIX 0x0200
1648#define MII_TG3_AUXCTL_MISC_RDSEL_MISC 0x7000
1649#define MII_TG3_AUXCTL_SHDWSEL_MISC 0x0007
1650
1645#define MII_TG3_AUX_STAT 0x19 /* auxilliary status register */ 1651#define MII_TG3_AUX_STAT 0x19 /* auxilliary status register */
1646#define MII_TG3_AUX_STAT_LPASS 0x0004 1652#define MII_TG3_AUX_STAT_LPASS 0x0004
1647#define MII_TG3_AUX_STAT_SPDMASK 0x0700 1653#define MII_TG3_AUX_STAT_SPDMASK 0x0700
@@ -1667,6 +1673,9 @@
1667#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */ 1673#define MII_TG3_EPHY_TEST 0x1f /* 5906 PHY register */
1668#define MII_TG3_EPHY_SHADOW_EN 0x80 1674#define MII_TG3_EPHY_SHADOW_EN 0x80
1669 1675
1676#define MII_TG3_EPHYTST_MISCCTRL 0x10 /* 5906 EPHY misc ctrl shadow register */
1677#define MII_TG3_EPHYTST_MISCCTRL_MDIX 0x4000
1678
1670#define MII_TG3_TEST1 0x1e 1679#define MII_TG3_TEST1 0x1e
1671#define MII_TG3_TEST1_TRIM_EN 0x0010 1680#define MII_TG3_TEST1_TRIM_EN 0x0010
1672#define MII_TG3_TEST1_CRC_EN 0x8000 1681#define MII_TG3_TEST1_CRC_EN 0x8000
diff --git a/drivers/net/tulip/interrupt.c b/drivers/net/tulip/interrupt.c
index ea896777bcaf..53efd6694e75 100644
--- a/drivers/net/tulip/interrupt.c
+++ b/drivers/net/tulip/interrupt.c
@@ -197,8 +197,8 @@ int tulip_poll(struct net_device *dev, int *budget)
197 tp->rx_buffers[entry].mapping, 197 tp->rx_buffers[entry].mapping,
198 pkt_len, PCI_DMA_FROMDEVICE); 198 pkt_len, PCI_DMA_FROMDEVICE);
199#if ! defined(__alpha__) 199#if ! defined(__alpha__)
200 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data, 200 skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
201 pkt_len, 0); 201 pkt_len);
202 skb_put(skb, pkt_len); 202 skb_put(skb, pkt_len);
203#else 203#else
204 memcpy(skb_put(skb, pkt_len), 204 memcpy(skb_put(skb, pkt_len),
@@ -420,8 +420,8 @@ static int tulip_rx(struct net_device *dev)
420 tp->rx_buffers[entry].mapping, 420 tp->rx_buffers[entry].mapping,
421 pkt_len, PCI_DMA_FROMDEVICE); 421 pkt_len, PCI_DMA_FROMDEVICE);
422#if ! defined(__alpha__) 422#if ! defined(__alpha__)
423 eth_copy_and_sum(skb, tp->rx_buffers[entry].skb->data, 423 skb_copy_to_linear_data(skb, tp->rx_buffers[entry].skb->data,
424 pkt_len, 0); 424 pkt_len);
425 skb_put(skb, pkt_len); 425 skb_put(skb, pkt_len);
426#else 426#else
427 memcpy(skb_put(skb, pkt_len), 427 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index 38f3b99716b8..5824f6a35495 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -1232,7 +1232,7 @@ static int netdev_rx(struct net_device *dev)
1232 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry], 1232 pci_dma_sync_single_for_cpu(np->pci_dev,np->rx_addr[entry],
1233 np->rx_skbuff[entry]->len, 1233 np->rx_skbuff[entry]->len,
1234 PCI_DMA_FROMDEVICE); 1234 PCI_DMA_FROMDEVICE);
1235 eth_copy_and_sum(skb, np->rx_skbuff[entry]->data, pkt_len, 0); 1235 skb_copy_to_linear_data(skb, np->rx_skbuff[entry]->data, pkt_len);
1236 skb_put(skb, pkt_len); 1236 skb_put(skb, pkt_len);
1237 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry], 1237 pci_dma_sync_single_for_device(np->pci_dev,np->rx_addr[entry],
1238 np->rx_skbuff[entry]->len, 1238 np->rx_skbuff[entry]->len,
diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c
index 79943cdd6337..16a54e6b8d4f 100644
--- a/drivers/net/tulip/xircom_cb.c
+++ b/drivers/net/tulip/xircom_cb.c
@@ -1205,7 +1205,7 @@ static void investigate_read_descriptor(struct net_device *dev,struct xircom_pri
1205 goto out; 1205 goto out;
1206 } 1206 }
1207 skb_reserve(skb, 2); 1207 skb_reserve(skb, 2);
1208 eth_copy_and_sum(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len, 0); 1208 skb_copy_to_linear_data(skb, (unsigned char*)&card->rx_buffer[bufferoffset / 4], pkt_len);
1209 skb_put(skb, pkt_len); 1209 skb_put(skb, pkt_len);
1210 skb->protocol = eth_type_trans(skb, dev); 1210 skb->protocol = eth_type_trans(skb, dev);
1211 netif_rx(skb); 1211 netif_rx(skb);
diff --git a/drivers/net/tulip/xircom_tulip_cb.c b/drivers/net/tulip/xircom_tulip_cb.c
index 83d69f11892f..fc439f333350 100644
--- a/drivers/net/tulip/xircom_tulip_cb.c
+++ b/drivers/net/tulip/xircom_tulip_cb.c
@@ -1240,8 +1240,8 @@ xircom_rx(struct net_device *dev)
1240 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) { 1240 && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) {
1241 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1241 skb_reserve(skb, 2); /* 16 byte align the IP header */
1242#if ! defined(__alpha__) 1242#if ! defined(__alpha__)
1243 eth_copy_and_sum(skb, bus_to_virt(tp->rx_ring[entry].buffer1), 1243 skb_copy_to_linear_data(skb, bus_to_virt(tp->rx_ring[entry].buffer1),
1244 pkt_len, 0); 1244 pkt_len);
1245 skb_put(skb, pkt_len); 1245 skb_put(skb, pkt_len);
1246#else 1246#else
1247 memcpy(skb_put(skb, pkt_len), 1247 memcpy(skb_put(skb, pkt_len),
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index a2c6caaaae93..62b2b3005019 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -432,6 +432,7 @@ static void tun_setup(struct net_device *dev)
432 init_waitqueue_head(&tun->read_wait); 432 init_waitqueue_head(&tun->read_wait);
433 433
434 tun->owner = -1; 434 tun->owner = -1;
435 tun->group = -1;
435 436
436 SET_MODULE_OWNER(dev); 437 SET_MODULE_OWNER(dev);
437 dev->open = tun_net_open; 438 dev->open = tun_net_open;
@@ -467,8 +468,11 @@ static int tun_set_iff(struct file *file, struct ifreq *ifr)
467 return -EBUSY; 468 return -EBUSY;
468 469
469 /* Check permissions */ 470 /* Check permissions */
470 if (tun->owner != -1 && 471 if (((tun->owner != -1 &&
471 current->euid != tun->owner && !capable(CAP_NET_ADMIN)) 472 current->euid != tun->owner) ||
473 (tun->group != -1 &&
474 current->egid != tun->group)) &&
475 !capable(CAP_NET_ADMIN))
472 return -EPERM; 476 return -EPERM;
473 } 477 }
474 else if (__dev_get_by_name(ifr->ifr_name)) 478 else if (__dev_get_by_name(ifr->ifr_name))
@@ -610,6 +614,13 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
610 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner); 614 DBG(KERN_INFO "%s: owner set to %d\n", tun->dev->name, tun->owner);
611 break; 615 break;
612 616
617 case TUNSETGROUP:
618 /* Set group of the device */
619 tun->group= (gid_t) arg;
620
621 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
622 break;
623
613 case TUNSETLINK: 624 case TUNSETLINK:
614 /* Only allow setting the type when the interface is down */ 625 /* Only allow setting the type when the interface is down */
615 if (tun->dev->flags & IFF_UP) { 626 if (tun->dev->flags & IFF_UP) {
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index 0f2c0610ed71..03587205546e 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -1703,7 +1703,7 @@ typhoon_rx(struct typhoon *tp, struct basic_ring *rxRing, volatile u32 * ready,
1703 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, 1703 pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
1704 PKT_BUF_SZ, 1704 PKT_BUF_SZ,
1705 PCI_DMA_FROMDEVICE); 1705 PCI_DMA_FROMDEVICE);
1706 eth_copy_and_sum(new_skb, skb->data, pkt_len, 0); 1706 skb_copy_to_linear_data(new_skb, skb->data, pkt_len);
1707 pci_dma_sync_single_for_device(tp->pdev, dma_addr, 1707 pci_dma_sync_single_for_device(tp->pdev, dma_addr,
1708 PKT_BUF_SZ, 1708 PKT_BUF_SZ,
1709 PCI_DMA_FROMDEVICE); 1709 PCI_DMA_FROMDEVICE);
diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index 86e90c59d551..76752d84a30f 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -255,7 +255,7 @@ static void catc_rx_done(struct urb *urb)
255 if (!(skb = dev_alloc_skb(pkt_len))) 255 if (!(skb = dev_alloc_skb(pkt_len)))
256 return; 256 return;
257 257
258 eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0); 258 skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
259 skb_put(skb, pkt_len); 259 skb_put(skb, pkt_len);
260 260
261 skb->protocol = eth_type_trans(skb, catc->netdev); 261 skb->protocol = eth_type_trans(skb, catc->netdev);
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 60d29440f316..524dc5f5e46d 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -635,7 +635,7 @@ static void kaweth_usb_receive(struct urb *urb)
635 635
636 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */ 636 skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
637 637
638 eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0); 638 skb_copy_to_linear_data(skb, kaweth->rx_buf + 2, pkt_len);
639 639
640 skb_put(skb, pkt_len); 640 skb_put(skb, pkt_len);
641 641
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 73e9c3dcddde..f51c2c138f10 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -1489,9 +1489,9 @@ static int rhine_rx(struct net_device *dev, int limit)
1489 rp->rx_buf_sz, 1489 rp->rx_buf_sz,
1490 PCI_DMA_FROMDEVICE); 1490 PCI_DMA_FROMDEVICE);
1491 1491
1492 eth_copy_and_sum(skb, 1492 skb_copy_to_linear_data(skb,
1493 rp->rx_skbuff[entry]->data, 1493 rp->rx_skbuff[entry]->data,
1494 pkt_len, 0); 1494 pkt_len);
1495 skb_put(skb, pkt_len); 1495 skb_put(skb, pkt_len);
1496 pci_dma_sync_single_for_device(rp->pdev, 1496 pci_dma_sync_single_for_device(rp->pdev,
1497 rp->rx_skbuff_dma[entry], 1497 rp->rx_skbuff_dma[entry],
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index ce9230b2f630..c8b5c2271938 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1011,7 +1011,7 @@ static inline void wl3501_md_ind_interrupt(struct net_device *dev,
1011 } else { 1011 } else {
1012 skb->dev = dev; 1012 skb->dev = dev;
1013 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */ 1013 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
1014 eth_copy_and_sum(skb, (unsigned char *)&sig.daddr, 12, 0); 1014 skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
1015 wl3501_receive(this, skb->data, pkt_len); 1015 wl3501_receive(this, skb->data, pkt_len);
1016 skb_put(skb, pkt_len); 1016 skb_put(skb, pkt_len);
1017 skb->protocol = eth_type_trans(skb, dev); 1017 skb->protocol = eth_type_trans(skb, dev);
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index f2a90a7fa2d6..870c5393c21a 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -1137,7 +1137,7 @@ static int yellowfin_rx(struct net_device *dev)
1137 if (skb == NULL) 1137 if (skb == NULL)
1138 break; 1138 break;
1139 skb_reserve(skb, 2); /* 16 byte align the IP header */ 1139 skb_reserve(skb, 2); /* 16 byte align the IP header */
1140 eth_copy_and_sum(skb, rx_skb->data, pkt_len, 0); 1140 skb_copy_to_linear_data(skb, rx_skb->data, pkt_len);
1141 skb_put(skb, pkt_len); 1141 skb_put(skb, pkt_len);
1142 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr, 1142 pci_dma_sync_single_for_device(yp->pci_dev, desc->addr,
1143 yp->rx_buf_sz, 1143 yp->rx_buf_sz,
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 924ef0609460..fc4bde259dc7 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -121,14 +121,14 @@ struct pdcspath_entry pdcspath_entry_##_name = { \
121 121
122#define PDCS_ATTR(_name, _mode, _show, _store) \ 122#define PDCS_ATTR(_name, _mode, _show, _store) \
123struct subsys_attribute pdcs_attr_##_name = { \ 123struct subsys_attribute pdcs_attr_##_name = { \
124 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 124 .attr = {.name = __stringify(_name), .mode = _mode}, \
125 .show = _show, \ 125 .show = _show, \
126 .store = _store, \ 126 .store = _store, \
127}; 127};
128 128
129#define PATHS_ATTR(_name, _mode, _show, _store) \ 129#define PATHS_ATTR(_name, _mode, _show, _store) \
130struct pdcspath_attribute paths_attr_##_name = { \ 130struct pdcspath_attribute paths_attr_##_name = { \
131 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE}, \ 131 .attr = {.name = __stringify(_name), .mode = _mode}, \
132 .show = _show, \ 132 .show = _show, \
133 .store = _store, \ 133 .store = _store, \
134}; 134};
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index e7322c25d377..70db38c0ced9 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -106,7 +106,8 @@ static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status);
106static void ibm_handle_events(acpi_handle handle, u32 event, void *context); 106static void ibm_handle_events(acpi_handle handle, u32 event, void *context);
107static int ibm_get_table_from_acpi(char **bufp); 107static int ibm_get_table_from_acpi(char **bufp);
108static ssize_t ibm_read_apci_table(struct kobject *kobj, 108static ssize_t ibm_read_apci_table(struct kobject *kobj,
109 char *buffer, loff_t pos, size_t size); 109 struct bin_attribute *bin_attr,
110 char *buffer, loff_t pos, size_t size);
110static acpi_status __init ibm_find_acpi_device(acpi_handle handle, 111static acpi_status __init ibm_find_acpi_device(acpi_handle handle,
111 u32 lvl, void *context, void **rv); 112 u32 lvl, void *context, void **rv);
112static int __init ibm_acpiphp_init(void); 113static int __init ibm_acpiphp_init(void);
@@ -117,7 +118,6 @@ static struct notification ibm_note;
117static struct bin_attribute ibm_apci_table_attr = { 118static struct bin_attribute ibm_apci_table_attr = {
118 .attr = { 119 .attr = {
119 .name = "apci_table", 120 .name = "apci_table",
120 .owner = THIS_MODULE,
121 .mode = S_IRUGO, 121 .mode = S_IRUGO,
122 }, 122 },
123 .read = ibm_read_apci_table, 123 .read = ibm_read_apci_table,
@@ -358,7 +358,8 @@ read_table_done:
358 * our solution is to only allow reading the table in all at once 358 * our solution is to only allow reading the table in all at once
359 **/ 359 **/
360static ssize_t ibm_read_apci_table(struct kobject *kobj, 360static ssize_t ibm_read_apci_table(struct kobject *kobj,
361 char *buffer, loff_t pos, size_t size) 361 struct bin_attribute *bin_attr,
362 char *buffer, loff_t pos, size_t size)
362{ 363{
363 int bytes_read = -EINVAL; 364 int bytes_read = -EINVAL;
364 char *table = NULL; 365 char *table = NULL;
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 9c4a123eacd1..10dbdec80416 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -213,7 +213,8 @@ struct device_attribute pci_dev_attrs[] = {
213}; 213};
214 214
215static ssize_t 215static ssize_t
216pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count) 216pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
217 char *buf, loff_t off, size_t count)
217{ 218{
218 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); 219 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
219 unsigned int size = 64; 220 unsigned int size = 64;
@@ -285,7 +286,8 @@ pci_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
285} 286}
286 287
287static ssize_t 288static ssize_t
288pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count) 289pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
290 char *buf, loff_t off, size_t count)
289{ 291{
290 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); 292 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
291 unsigned int size = count; 293 unsigned int size = count;
@@ -352,7 +354,8 @@ pci_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
352 * callback routine (pci_legacy_read). 354 * callback routine (pci_legacy_read).
353 */ 355 */
354ssize_t 356ssize_t
355pci_read_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count) 357pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
358 char *buf, loff_t off, size_t count)
356{ 359{
357 struct pci_bus *bus = to_pci_bus(container_of(kobj, 360 struct pci_bus *bus = to_pci_bus(container_of(kobj,
358 struct class_device, 361 struct class_device,
@@ -376,7 +379,8 @@ pci_read_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count)
376 * callback routine (pci_legacy_write). 379 * callback routine (pci_legacy_write).
377 */ 380 */
378ssize_t 381ssize_t
379pci_write_legacy_io(struct kobject *kobj, char *buf, loff_t off, size_t count) 382pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
383 char *buf, loff_t off, size_t count)
380{ 384{
381 struct pci_bus *bus = to_pci_bus(container_of(kobj, 385 struct pci_bus *bus = to_pci_bus(container_of(kobj,
382 struct class_device, 386 struct class_device,
@@ -499,7 +503,6 @@ static int pci_create_resource_files(struct pci_dev *pdev)
499 sprintf(res_attr_name, "resource%d", i); 503 sprintf(res_attr_name, "resource%d", i);
500 res_attr->attr.name = res_attr_name; 504 res_attr->attr.name = res_attr_name;
501 res_attr->attr.mode = S_IRUSR | S_IWUSR; 505 res_attr->attr.mode = S_IRUSR | S_IWUSR;
502 res_attr->attr.owner = THIS_MODULE;
503 res_attr->size = pci_resource_len(pdev, i); 506 res_attr->size = pci_resource_len(pdev, i);
504 res_attr->mmap = pci_mmap_resource; 507 res_attr->mmap = pci_mmap_resource;
505 res_attr->private = &pdev->resource[i]; 508 res_attr->private = &pdev->resource[i];
@@ -529,7 +532,8 @@ static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
529 * writing anything except 0 enables it 532 * writing anything except 0 enables it
530 */ 533 */
531static ssize_t 534static ssize_t
532pci_write_rom(struct kobject *kobj, char *buf, loff_t off, size_t count) 535pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
536 char *buf, loff_t off, size_t count)
533{ 537{
534 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); 538 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
535 539
@@ -552,7 +556,8 @@ pci_write_rom(struct kobject *kobj, char *buf, loff_t off, size_t count)
552 * device corresponding to @kobj. 556 * device corresponding to @kobj.
553 */ 557 */
554static ssize_t 558static ssize_t
555pci_read_rom(struct kobject *kobj, char *buf, loff_t off, size_t count) 559pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
560 char *buf, loff_t off, size_t count)
556{ 561{
557 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); 562 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
558 void __iomem *rom; 563 void __iomem *rom;
@@ -582,7 +587,6 @@ static struct bin_attribute pci_config_attr = {
582 .attr = { 587 .attr = {
583 .name = "config", 588 .name = "config",
584 .mode = S_IRUGO | S_IWUSR, 589 .mode = S_IRUGO | S_IWUSR,
585 .owner = THIS_MODULE,
586 }, 590 },
587 .size = 256, 591 .size = 256,
588 .read = pci_read_config, 592 .read = pci_read_config,
@@ -593,7 +597,6 @@ static struct bin_attribute pcie_config_attr = {
593 .attr = { 597 .attr = {
594 .name = "config", 598 .name = "config",
595 .mode = S_IRUGO | S_IWUSR, 599 .mode = S_IRUGO | S_IWUSR,
596 .owner = THIS_MODULE,
597 }, 600 },
598 .size = 4096, 601 .size = 4096,
599 .read = pci_read_config, 602 .read = pci_read_config,
@@ -633,7 +636,6 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
633 rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE); 636 rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
634 rom_attr->attr.name = "rom"; 637 rom_attr->attr.name = "rom";
635 rom_attr->attr.mode = S_IRUSR; 638 rom_attr->attr.mode = S_IRUSR;
636 rom_attr->attr.owner = THIS_MODULE;
637 rom_attr->read = pci_read_rom; 639 rom_attr->read = pci_read_rom;
638 rom_attr->write = pci_write_rom; 640 rom_attr->write = pci_write_rom;
639 retval = sysfs_create_bin_file(&pdev->dev.kobj, rom_attr); 641 retval = sysfs_create_bin_file(&pdev->dev.kobj, rom_attr);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8802fcb4aaf0..a7bce75c6732 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -39,7 +39,6 @@ static void pci_create_legacy_files(struct pci_bus *b)
39 b->legacy_io->attr.name = "legacy_io"; 39 b->legacy_io->attr.name = "legacy_io";
40 b->legacy_io->size = 0xffff; 40 b->legacy_io->size = 0xffff;
41 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; 41 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
42 b->legacy_io->attr.owner = THIS_MODULE;
43 b->legacy_io->read = pci_read_legacy_io; 42 b->legacy_io->read = pci_read_legacy_io;
44 b->legacy_io->write = pci_write_legacy_io; 43 b->legacy_io->write = pci_write_legacy_io;
45 class_device_create_bin_file(&b->class_dev, b->legacy_io); 44 class_device_create_bin_file(&b->class_dev, b->legacy_io);
@@ -49,7 +48,6 @@ static void pci_create_legacy_files(struct pci_bus *b)
49 b->legacy_mem->attr.name = "legacy_mem"; 48 b->legacy_mem->attr.name = "legacy_mem";
50 b->legacy_mem->size = 1024*1024; 49 b->legacy_mem->size = 1024*1024;
51 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; 50 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
52 b->legacy_mem->attr.owner = THIS_MODULE;
53 b->legacy_mem->mmap = pci_mmap_legacy_mem; 51 b->legacy_mem->mmap = pci_mmap_legacy_mem;
54 class_device_create_bin_file(&b->class_dev, b->legacy_mem); 52 class_device_create_bin_file(&b->class_dev, b->legacy_mem);
55 } 53 }
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index a2bb46526b56..b4409002b7f8 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -283,7 +283,9 @@ static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off
283 return (ret); 283 return (ret);
284} 284}
285 285
286static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size_t count) 286static ssize_t pccard_show_cis(struct kobject *kobj,
287 struct bin_attribute *bin_attr,
288 char *buf, loff_t off, size_t count)
287{ 289{
288 unsigned int size = 0x200; 290 unsigned int size = 0x200;
289 291
@@ -311,7 +313,9 @@ static ssize_t pccard_show_cis(struct kobject *kobj, char *buf, loff_t off, size
311 return (count); 313 return (count);
312} 314}
313 315
314static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, size_t count) 316static ssize_t pccard_store_cis(struct kobject *kobj,
317 struct bin_attribute *bin_attr,
318 char *buf, loff_t off, size_t count)
315{ 319{
316 struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); 320 struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj));
317 cisdump_t *cis; 321 cisdump_t *cis;
@@ -366,7 +370,7 @@ static struct device_attribute *pccard_socket_attributes[] = {
366}; 370};
367 371
368static struct bin_attribute pccard_cis_attr = { 372static struct bin_attribute pccard_cis_attr = {
369 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR, .owner = THIS_MODULE}, 373 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
370 .size = 0x200, 374 .size = 0x200,
371 .read = pccard_show_cis, 375 .read = pccard_show_cis,
372 .write = pccard_store_cis, 376 .write = pccard_store_cis,
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index eed91434417d..659e31164cf0 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -67,7 +67,8 @@ struct device_attribute rio_dev_attrs[] = {
67}; 67};
68 68
69static ssize_t 69static ssize_t
70rio_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count) 70rio_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
71 char *buf, loff_t off, size_t count)
71{ 72{
72 struct rio_dev *dev = 73 struct rio_dev *dev =
73 to_rio_dev(container_of(kobj, struct device, kobj)); 74 to_rio_dev(container_of(kobj, struct device, kobj));
@@ -137,7 +138,8 @@ rio_read_config(struct kobject *kobj, char *buf, loff_t off, size_t count)
137} 138}
138 139
139static ssize_t 140static ssize_t
140rio_write_config(struct kobject *kobj, char *buf, loff_t off, size_t count) 141rio_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
142 char *buf, loff_t off, size_t count)
141{ 143{
142 struct rio_dev *dev = 144 struct rio_dev *dev =
143 to_rio_dev(container_of(kobj, struct device, kobj)); 145 to_rio_dev(container_of(kobj, struct device, kobj));
@@ -197,7 +199,6 @@ static struct bin_attribute rio_config_attr = {
197 .attr = { 199 .attr = {
198 .name = "config", 200 .name = "config",
199 .mode = S_IRUGO | S_IWUSR, 201 .mode = S_IRUGO | S_IWUSR,
200 .owner = THIS_MODULE,
201 }, 202 },
202 .size = 0x200000, 203 .size = 0x200000,
203 .read = rio_read_config, 204 .read = rio_read_config,
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index afa64c7fa2e2..f98a83a11aae 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -258,8 +258,9 @@ static const struct rtc_class_ops ds1553_rtc_ops = {
258 .ioctl = ds1553_rtc_ioctl, 258 .ioctl = ds1553_rtc_ioctl,
259}; 259};
260 260
261static ssize_t ds1553_nvram_read(struct kobject *kobj, char *buf, 261static ssize_t ds1553_nvram_read(struct kobject *kobj,
262 loff_t pos, size_t size) 262 struct bin_attribute *bin_attr,
263 char *buf, loff_t pos, size_t size)
263{ 264{
264 struct platform_device *pdev = 265 struct platform_device *pdev =
265 to_platform_device(container_of(kobj, struct device, kobj)); 266 to_platform_device(container_of(kobj, struct device, kobj));
@@ -272,8 +273,9 @@ static ssize_t ds1553_nvram_read(struct kobject *kobj, char *buf,
272 return count; 273 return count;
273} 274}
274 275
275static ssize_t ds1553_nvram_write(struct kobject *kobj, char *buf, 276static ssize_t ds1553_nvram_write(struct kobject *kobj,
276 loff_t pos, size_t size) 277 struct bin_attribute *bin_attr,
278 char *buf, loff_t pos, size_t size)
277{ 279{
278 struct platform_device *pdev = 280 struct platform_device *pdev =
279 to_platform_device(container_of(kobj, struct device, kobj)); 281 to_platform_device(container_of(kobj, struct device, kobj));
@@ -290,7 +292,6 @@ static struct bin_attribute ds1553_nvram_attr = {
290 .attr = { 292 .attr = {
291 .name = "nvram", 293 .name = "nvram",
292 .mode = S_IRUGO | S_IWUGO, 294 .mode = S_IRUGO | S_IWUGO,
293 .owner = THIS_MODULE,
294 }, 295 },
295 .size = RTC_OFFSET, 296 .size = RTC_OFFSET,
296 .read = ds1553_nvram_read, 297 .read = ds1553_nvram_read,
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index d68288b389dc..d1778ae8bca5 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -127,8 +127,9 @@ static const struct rtc_class_ops ds1742_rtc_ops = {
127 .set_time = ds1742_rtc_set_time, 127 .set_time = ds1742_rtc_set_time,
128}; 128};
129 129
130static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf, 130static ssize_t ds1742_nvram_read(struct kobject *kobj,
131 loff_t pos, size_t size) 131 struct bin_attribute *bin_attr,
132 char *buf, loff_t pos, size_t size)
132{ 133{
133 struct platform_device *pdev = 134 struct platform_device *pdev =
134 to_platform_device(container_of(kobj, struct device, kobj)); 135 to_platform_device(container_of(kobj, struct device, kobj));
@@ -141,8 +142,9 @@ static ssize_t ds1742_nvram_read(struct kobject *kobj, char *buf,
141 return count; 142 return count;
142} 143}
143 144
144static ssize_t ds1742_nvram_write(struct kobject *kobj, char *buf, 145static ssize_t ds1742_nvram_write(struct kobject *kobj,
145 loff_t pos, size_t size) 146 struct bin_attribute *bin_attr,
147 char *buf, loff_t pos, size_t size)
146{ 148{
147 struct platform_device *pdev = 149 struct platform_device *pdev =
148 to_platform_device(container_of(kobj, struct device, kobj)); 150 to_platform_device(container_of(kobj, struct device, kobj));
@@ -159,7 +161,6 @@ static struct bin_attribute ds1742_nvram_attr = {
159 .attr = { 161 .attr = {
160 .name = "nvram", 162 .name = "nvram",
161 .mode = S_IRUGO | S_IWUGO, 163 .mode = S_IRUGO | S_IWUGO,
162 .owner = THIS_MODULE,
163 }, 164 },
164 .read = ds1742_nvram_read, 165 .read = ds1742_nvram_read,
165 .write = ds1742_nvram_write, 166 .write = ds1742_nvram_write,
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index af7596ef29e2..ce2f78de7a80 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -17,10 +17,11 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#include <linux/err.h>
20#include <linux/fs.h> 21#include <linux/fs.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/ioport.h> 23#include <linux/ioport.h>
23#include <linux/irq.h> 24#include <linux/interrupt.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/rtc.h> 27#include <linux/rtc.h>
@@ -30,25 +31,11 @@
30#include <asm/div64.h> 31#include <asm/div64.h>
31#include <asm/io.h> 32#include <asm/io.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include <asm/vr41xx/irq.h>
34 34
35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>"); 35MODULE_AUTHOR("Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>");
36MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 36MODULE_DESCRIPTION("NEC VR4100 series RTC driver");
37MODULE_LICENSE("GPL"); 37MODULE_LICENSE("GPL");
38 38
39#define RTC1_TYPE1_START 0x0b0000c0UL
40#define RTC1_TYPE1_END 0x0b0000dfUL
41#define RTC2_TYPE1_START 0x0b0001c0UL
42#define RTC2_TYPE1_END 0x0b0001dfUL
43
44#define RTC1_TYPE2_START 0x0f000100UL
45#define RTC1_TYPE2_END 0x0f00011fUL
46#define RTC2_TYPE2_START 0x0f000120UL
47#define RTC2_TYPE2_END 0x0f00013fUL
48
49#define RTC1_SIZE 0x20
50#define RTC2_SIZE 0x20
51
52/* RTC 1 registers */ 39/* RTC 1 registers */
53#define ETIMELREG 0x00 40#define ETIMELREG 0x00
54#define ETIMEMREG 0x02 41#define ETIMEMREG 0x02
@@ -98,13 +85,8 @@ static char rtc_name[] = "RTC";
98static unsigned long periodic_frequency; 85static unsigned long periodic_frequency;
99static unsigned long periodic_count; 86static unsigned long periodic_count;
100static unsigned int alarm_enabled; 87static unsigned int alarm_enabled;
101 88static int aie_irq = -1;
102struct resource rtc_resource[2] = { 89static int pie_irq = -1;
103 { .name = rtc_name,
104 .flags = IORESOURCE_MEM, },
105 { .name = rtc_name,
106 .flags = IORESOURCE_MEM, },
107};
108 90
109static inline unsigned long read_elapsed_second(void) 91static inline unsigned long read_elapsed_second(void)
110{ 92{
@@ -150,8 +132,8 @@ static void vr41xx_rtc_release(struct device *dev)
150 132
151 spin_unlock_irq(&rtc_lock); 133 spin_unlock_irq(&rtc_lock);
152 134
153 disable_irq(ELAPSEDTIME_IRQ); 135 disable_irq(aie_irq);
154 disable_irq(RTCLONG1_IRQ); 136 disable_irq(pie_irq);
155} 137}
156 138
157static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) 139static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time)
@@ -209,14 +191,14 @@ static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
209 spin_lock_irq(&rtc_lock); 191 spin_lock_irq(&rtc_lock);
210 192
211 if (alarm_enabled) 193 if (alarm_enabled)
212 disable_irq(ELAPSEDTIME_IRQ); 194 disable_irq(aie_irq);
213 195
214 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15)); 196 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15));
215 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1)); 197 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1));
216 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17)); 198 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17));
217 199
218 if (wkalrm->enabled) 200 if (wkalrm->enabled)
219 enable_irq(ELAPSEDTIME_IRQ); 201 enable_irq(aie_irq);
220 202
221 alarm_enabled = wkalrm->enabled; 203 alarm_enabled = wkalrm->enabled;
222 204
@@ -234,7 +216,7 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
234 spin_lock_irq(&rtc_lock); 216 spin_lock_irq(&rtc_lock);
235 217
236 if (!alarm_enabled) { 218 if (!alarm_enabled) {
237 enable_irq(ELAPSEDTIME_IRQ); 219 enable_irq(aie_irq);
238 alarm_enabled = 1; 220 alarm_enabled = 1;
239 } 221 }
240 222
@@ -244,17 +226,17 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
244 spin_lock_irq(&rtc_lock); 226 spin_lock_irq(&rtc_lock);
245 227
246 if (alarm_enabled) { 228 if (alarm_enabled) {
247 disable_irq(ELAPSEDTIME_IRQ); 229 disable_irq(aie_irq);
248 alarm_enabled = 0; 230 alarm_enabled = 0;
249 } 231 }
250 232
251 spin_unlock_irq(&rtc_lock); 233 spin_unlock_irq(&rtc_lock);
252 break; 234 break;
253 case RTC_PIE_ON: 235 case RTC_PIE_ON:
254 enable_irq(RTCLONG1_IRQ); 236 enable_irq(pie_irq);
255 break; 237 break;
256 case RTC_PIE_OFF: 238 case RTC_PIE_OFF:
257 disable_irq(RTCLONG1_IRQ); 239 disable_irq(pie_irq);
258 break; 240 break;
259 case RTC_IRQP_READ: 241 case RTC_IRQP_READ:
260 return put_user(periodic_frequency, (unsigned long __user *)arg); 242 return put_user(periodic_frequency, (unsigned long __user *)arg);
@@ -331,31 +313,37 @@ static const struct rtc_class_ops vr41xx_rtc_ops = {
331 313
332static int __devinit rtc_probe(struct platform_device *pdev) 314static int __devinit rtc_probe(struct platform_device *pdev)
333{ 315{
316 struct resource *res;
334 struct rtc_device *rtc; 317 struct rtc_device *rtc;
335 unsigned int irq;
336 int retval; 318 int retval;
337 319
338 if (pdev->num_resources != 2) 320 if (pdev->num_resources != 4)
339 return -EBUSY; 321 return -EBUSY;
340 322
341 rtc1_base = ioremap(pdev->resource[0].start, RTC1_SIZE); 323 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
342 if (rtc1_base == NULL) 324 if (!res)
343 return -EBUSY; 325 return -EBUSY;
344 326
345 rtc2_base = ioremap(pdev->resource[1].start, RTC2_SIZE); 327 rtc1_base = ioremap(res->start, res->end - res->start + 1);
346 if (rtc2_base == NULL) { 328 if (!rtc1_base)
347 iounmap(rtc1_base);
348 rtc1_base = NULL;
349 return -EBUSY; 329 return -EBUSY;
330
331 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
332 if (!res) {
333 retval = -EBUSY;
334 goto err_rtc1_iounmap;
335 }
336
337 rtc2_base = ioremap(res->start, res->end - res->start + 1);
338 if (!rtc2_base) {
339 retval = -EBUSY;
340 goto err_rtc1_iounmap;
350 } 341 }
351 342
352 rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE); 343 rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE);
353 if (IS_ERR(rtc)) { 344 if (IS_ERR(rtc)) {
354 iounmap(rtc1_base); 345 retval = PTR_ERR(rtc);
355 iounmap(rtc2_base); 346 goto err_iounmap_all;
356 rtc1_base = NULL;
357 rtc2_base = NULL;
358 return PTR_ERR(rtc);
359 } 347 }
360 348
361 spin_lock_irq(&rtc_lock); 349 spin_lock_irq(&rtc_lock);
@@ -368,35 +356,50 @@ static int __devinit rtc_probe(struct platform_device *pdev)
368 356
369 spin_unlock_irq(&rtc_lock); 357 spin_unlock_irq(&rtc_lock);
370 358
371 irq = ELAPSEDTIME_IRQ; 359 aie_irq = platform_get_irq(pdev, 0);
372 retval = request_irq(irq, elapsedtime_interrupt, IRQF_DISABLED, 360 if (aie_irq < 0 || aie_irq >= NR_IRQS) {
373 "elapsed_time", pdev); 361 retval = -EBUSY;
374 if (retval == 0) { 362 goto err_device_unregister;
375 irq = RTCLONG1_IRQ;
376 retval = request_irq(irq, rtclong1_interrupt, IRQF_DISABLED,
377 "rtclong1", pdev);
378 } 363 }
379 364
380 if (retval < 0) { 365 retval = request_irq(aie_irq, elapsedtime_interrupt, IRQF_DISABLED,
381 printk(KERN_ERR "rtc: IRQ%d is busy\n", irq); 366 "elapsed_time", pdev);
382 rtc_device_unregister(rtc); 367 if (retval < 0)
383 if (irq == RTCLONG1_IRQ) 368 goto err_device_unregister;
384 free_irq(ELAPSEDTIME_IRQ, NULL); 369
385 iounmap(rtc1_base); 370 pie_irq = platform_get_irq(pdev, 1);
386 iounmap(rtc2_base); 371 if (pie_irq < 0 || pie_irq >= NR_IRQS)
387 rtc1_base = NULL; 372 goto err_free_irq;
388 rtc2_base = NULL; 373
389 return retval; 374 retval = request_irq(pie_irq, rtclong1_interrupt, IRQF_DISABLED,
390 } 375 "rtclong1", pdev);
376 if (retval < 0)
377 goto err_free_irq;
391 378
392 platform_set_drvdata(pdev, rtc); 379 platform_set_drvdata(pdev, rtc);
393 380
394 disable_irq(ELAPSEDTIME_IRQ); 381 disable_irq(aie_irq);
395 disable_irq(RTCLONG1_IRQ); 382 disable_irq(pie_irq);
396 383
397 printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n"); 384 printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n");
398 385
399 return 0; 386 return 0;
387
388err_free_irq:
389 free_irq(aie_irq, pdev);
390
391err_device_unregister:
392 rtc_device_unregister(rtc);
393
394err_iounmap_all:
395 iounmap(rtc2_base);
396 rtc2_base = NULL;
397
398err_rtc1_iounmap:
399 iounmap(rtc1_base);
400 rtc1_base = NULL;
401
402 return retval;
400} 403}
401 404
402static int __devexit rtc_remove(struct platform_device *pdev) 405static int __devexit rtc_remove(struct platform_device *pdev)
@@ -404,23 +407,21 @@ static int __devexit rtc_remove(struct platform_device *pdev)
404 struct rtc_device *rtc; 407 struct rtc_device *rtc;
405 408
406 rtc = platform_get_drvdata(pdev); 409 rtc = platform_get_drvdata(pdev);
407 if (rtc != NULL) 410 if (rtc)
408 rtc_device_unregister(rtc); 411 rtc_device_unregister(rtc);
409 412
410 platform_set_drvdata(pdev, NULL); 413 platform_set_drvdata(pdev, NULL);
411 414
412 free_irq(ELAPSEDTIME_IRQ, NULL); 415 free_irq(aie_irq, pdev);
413 free_irq(RTCLONG1_IRQ, NULL); 416 free_irq(pie_irq, pdev);
414 if (rtc1_base != NULL) 417 if (rtc1_base)
415 iounmap(rtc1_base); 418 iounmap(rtc1_base);
416 if (rtc2_base != NULL) 419 if (rtc2_base)
417 iounmap(rtc2_base); 420 iounmap(rtc2_base);
418 421
419 return 0; 422 return 0;
420} 423}
421 424
422static struct platform_device *rtc_platform_device;
423
424static struct platform_driver rtc_platform_driver = { 425static struct platform_driver rtc_platform_driver = {
425 .probe = rtc_probe, 426 .probe = rtc_probe,
426 .remove = __devexit_p(rtc_remove), 427 .remove = __devexit_p(rtc_remove),
@@ -432,55 +433,12 @@ static struct platform_driver rtc_platform_driver = {
432 433
433static int __init vr41xx_rtc_init(void) 434static int __init vr41xx_rtc_init(void)
434{ 435{
435 int retval; 436 return platform_driver_register(&rtc_platform_driver);
436
437 switch (current_cpu_data.cputype) {
438 case CPU_VR4111:
439 case CPU_VR4121:
440 rtc_resource[0].start = RTC1_TYPE1_START;
441 rtc_resource[0].end = RTC1_TYPE1_END;
442 rtc_resource[1].start = RTC2_TYPE1_START;
443 rtc_resource[1].end = RTC2_TYPE1_END;
444 break;
445 case CPU_VR4122:
446 case CPU_VR4131:
447 case CPU_VR4133:
448 rtc_resource[0].start = RTC1_TYPE2_START;
449 rtc_resource[0].end = RTC1_TYPE2_END;
450 rtc_resource[1].start = RTC2_TYPE2_START;
451 rtc_resource[1].end = RTC2_TYPE2_END;
452 break;
453 default:
454 return -ENODEV;
455 break;
456 }
457
458 rtc_platform_device = platform_device_alloc("RTC", -1);
459 if (rtc_platform_device == NULL)
460 return -ENOMEM;
461
462 retval = platform_device_add_resources(rtc_platform_device,
463 rtc_resource, ARRAY_SIZE(rtc_resource));
464
465 if (retval == 0)
466 retval = platform_device_add(rtc_platform_device);
467
468 if (retval < 0) {
469 platform_device_put(rtc_platform_device);
470 return retval;
471 }
472
473 retval = platform_driver_register(&rtc_platform_driver);
474 if (retval < 0)
475 platform_device_unregister(rtc_platform_device);
476
477 return retval;
478} 437}
479 438
480static void __exit vr41xx_rtc_exit(void) 439static void __exit vr41xx_rtc_exit(void)
481{ 440{
482 platform_driver_unregister(&rtc_platform_driver); 441 platform_driver_unregister(&rtc_platform_driver);
483 platform_device_unregister(rtc_platform_device);
484} 442}
485 443
486module_init(vr41xx_rtc_init); 444module_init(vr41xx_rtc_init);
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 513d1a611aab..b3fae357ca49 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -9,6 +9,9 @@
9 * 9 *
10 * based on a lot of other RTC drivers. 10 * based on a lot of other RTC drivers.
11 * 11 *
12 * Information and datasheet:
13 * http://www.intersil.com/cda/deviceinfo/0,1477,X1205,00.html
14 *
12 * This program is free software; you can redistribute it and/or modify 15 * 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 16 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. 17 * published by the Free Software Foundation.
@@ -26,7 +29,7 @@
26 * Two bytes need to be written to read a single register, 29 * Two bytes need to be written to read a single register,
27 * while most other chips just require one and take the second 30 * while most other chips just require one and take the second
28 * one as the data to be written. To prevent corrupting 31 * one as the data to be written. To prevent corrupting
29 * unknown chips, the user must explicitely set the probe parameter. 32 * unknown chips, the user must explicitly set the probe parameter.
30 */ 33 */
31 34
32static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 35static unsigned short normal_i2c[] = { I2C_CLIENT_END };
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index ac289e6eadfe..b57d93d986c0 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -141,8 +141,9 @@ static int s390_vary_chpid(struct chp_id chpid, int on)
141/* 141/*
142 * Channel measurement related functions 142 * Channel measurement related functions
143 */ 143 */
144static ssize_t chp_measurement_chars_read(struct kobject *kobj, char *buf, 144static ssize_t chp_measurement_chars_read(struct kobject *kobj,
145 loff_t off, size_t count) 145 struct bin_attribute *bin_attr,
146 char *buf, loff_t off, size_t count)
146{ 147{
147 struct channel_path *chp; 148 struct channel_path *chp;
148 unsigned int size; 149 unsigned int size;
@@ -165,7 +166,6 @@ static struct bin_attribute chp_measurement_chars_attr = {
165 .attr = { 166 .attr = {
166 .name = "measurement_chars", 167 .name = "measurement_chars",
167 .mode = S_IRUSR, 168 .mode = S_IRUSR,
168 .owner = THIS_MODULE,
169 }, 169 },
170 .size = sizeof(struct cmg_chars), 170 .size = sizeof(struct cmg_chars),
171 .read = chp_measurement_chars_read, 171 .read = chp_measurement_chars_read,
@@ -193,8 +193,9 @@ static void chp_measurement_copy_block(struct cmg_entry *buf,
193 } while (reference_buf.values[0] != buf->values[0]); 193 } while (reference_buf.values[0] != buf->values[0]);
194} 194}
195 195
196static ssize_t chp_measurement_read(struct kobject *kobj, char *buf, 196static ssize_t chp_measurement_read(struct kobject *kobj,
197 loff_t off, size_t count) 197 struct bin_attribute *bin_attr,
198 char *buf, loff_t off, size_t count)
198{ 199{
199 struct channel_path *chp; 200 struct channel_path *chp;
200 struct channel_subsystem *css; 201 struct channel_subsystem *css;
@@ -217,7 +218,6 @@ static struct bin_attribute chp_measurement_attr = {
217 .attr = { 218 .attr = {
218 .name = "measurement", 219 .name = "measurement",
219 .mode = S_IRUSR, 220 .mode = S_IRUSR,
220 .owner = THIS_MODULE,
221 }, 221 },
222 .size = sizeof(struct cmg_entry), 222 .size = sizeof(struct cmg_entry),
223 .read = chp_measurement_read, 223 .read = chp_measurement_read,
diff --git a/drivers/s390/net/qeth_sys.c b/drivers/s390/net/qeth_sys.c
index 65ffc21afc37..bb0287ad1aac 100644
--- a/drivers/s390/net/qeth_sys.c
+++ b/drivers/s390/net/qeth_sys.c
@@ -991,7 +991,7 @@ static struct attribute_group qeth_osn_device_attr_group = {
991 991
992#define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \ 992#define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
993struct device_attribute dev_attr_##_id = { \ 993struct device_attribute dev_attr_##_id = { \
994 .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\ 994 .attr = {.name=__stringify(_name), .mode=_mode, },\
995 .show = _show, \ 995 .show = _show, \
996 .store = _store, \ 996 .store = _store, \
997}; 997};
diff --git a/drivers/scsi/arcmsr/arcmsr_attr.c b/drivers/scsi/arcmsr/arcmsr_attr.c
index 03bfed61bffc..06c0dce3b839 100644
--- a/drivers/scsi/arcmsr/arcmsr_attr.c
+++ b/drivers/scsi/arcmsr/arcmsr_attr.c
@@ -59,8 +59,9 @@
59struct class_device_attribute *arcmsr_host_attrs[]; 59struct class_device_attribute *arcmsr_host_attrs[];
60 60
61static ssize_t 61static ssize_t
62arcmsr_sysfs_iop_message_read(struct kobject *kobj, char *buf, loff_t off, 62arcmsr_sysfs_iop_message_read(struct kobject *kobj,
63 size_t count) 63 struct bin_attribute *bin_attr,
64 char *buf, loff_t off, size_t count)
64{ 65{
65 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 66 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
66 struct Scsi_Host *host = class_to_shost(cdev); 67 struct Scsi_Host *host = class_to_shost(cdev);
@@ -105,8 +106,9 @@ arcmsr_sysfs_iop_message_read(struct kobject *kobj, char *buf, loff_t off,
105} 106}
106 107
107static ssize_t 108static ssize_t
108arcmsr_sysfs_iop_message_write(struct kobject *kobj, char *buf, loff_t off, 109arcmsr_sysfs_iop_message_write(struct kobject *kobj,
109 size_t count) 110 struct bin_attribute *bin_attr,
111 char *buf, loff_t off, size_t count)
110{ 112{
111 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 113 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
112 struct Scsi_Host *host = class_to_shost(cdev); 114 struct Scsi_Host *host = class_to_shost(cdev);
@@ -152,8 +154,9 @@ arcmsr_sysfs_iop_message_write(struct kobject *kobj, char *buf, loff_t off,
152} 154}
153 155
154static ssize_t 156static ssize_t
155arcmsr_sysfs_iop_message_clear(struct kobject *kobj, char *buf, loff_t off, 157arcmsr_sysfs_iop_message_clear(struct kobject *kobj,
156 size_t count) 158 struct bin_attribute *bin_attr,
159 char *buf, loff_t off, size_t count)
157{ 160{
158 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 161 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
159 struct Scsi_Host *host = class_to_shost(cdev); 162 struct Scsi_Host *host = class_to_shost(cdev);
@@ -188,7 +191,6 @@ static struct bin_attribute arcmsr_sysfs_message_read_attr = {
188 .attr = { 191 .attr = {
189 .name = "mu_read", 192 .name = "mu_read",
190 .mode = S_IRUSR , 193 .mode = S_IRUSR ,
191 .owner = THIS_MODULE,
192 }, 194 },
193 .size = 1032, 195 .size = 1032,
194 .read = arcmsr_sysfs_iop_message_read, 196 .read = arcmsr_sysfs_iop_message_read,
@@ -198,7 +200,6 @@ static struct bin_attribute arcmsr_sysfs_message_write_attr = {
198 .attr = { 200 .attr = {
199 .name = "mu_write", 201 .name = "mu_write",
200 .mode = S_IWUSR, 202 .mode = S_IWUSR,
201 .owner = THIS_MODULE,
202 }, 203 },
203 .size = 1032, 204 .size = 1032,
204 .write = arcmsr_sysfs_iop_message_write, 205 .write = arcmsr_sysfs_iop_message_write,
@@ -208,7 +209,6 @@ static struct bin_attribute arcmsr_sysfs_message_clear_attr = {
208 .attr = { 209 .attr = {
209 .name = "mu_clear", 210 .name = "mu_clear",
210 .mode = S_IWUSR, 211 .mode = S_IWUSR,
211 .owner = THIS_MODULE,
212 }, 212 },
213 .size = 1, 213 .size = 1,
214 .write = arcmsr_sysfs_iop_message_clear, 214 .write = arcmsr_sysfs_iop_message_clear,
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 81330712048c..b3bf77f1ec05 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -2465,6 +2465,7 @@ restart:
2465/** 2465/**
2466 * ipr_read_trace - Dump the adapter trace 2466 * ipr_read_trace - Dump the adapter trace
2467 * @kobj: kobject struct 2467 * @kobj: kobject struct
2468 * @bin_attr: bin_attribute struct
2468 * @buf: buffer 2469 * @buf: buffer
2469 * @off: offset 2470 * @off: offset
2470 * @count: buffer size 2471 * @count: buffer size
@@ -2472,8 +2473,9 @@ restart:
2472 * Return value: 2473 * Return value:
2473 * number of bytes printed to buffer 2474 * number of bytes printed to buffer
2474 **/ 2475 **/
2475static ssize_t ipr_read_trace(struct kobject *kobj, char *buf, 2476static ssize_t ipr_read_trace(struct kobject *kobj,
2476 loff_t off, size_t count) 2477 struct bin_attribute *bin_attr,
2478 char *buf, loff_t off, size_t count)
2477{ 2479{
2478 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 2480 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
2479 struct Scsi_Host *shost = class_to_shost(cdev); 2481 struct Scsi_Host *shost = class_to_shost(cdev);
@@ -3166,6 +3168,7 @@ static struct class_device_attribute *ipr_ioa_attrs[] = {
3166/** 3168/**
3167 * ipr_read_dump - Dump the adapter 3169 * ipr_read_dump - Dump the adapter
3168 * @kobj: kobject struct 3170 * @kobj: kobject struct
3171 * @bin_attr: bin_attribute struct
3169 * @buf: buffer 3172 * @buf: buffer
3170 * @off: offset 3173 * @off: offset
3171 * @count: buffer size 3174 * @count: buffer size
@@ -3173,8 +3176,9 @@ static struct class_device_attribute *ipr_ioa_attrs[] = {
3173 * Return value: 3176 * Return value:
3174 * number of bytes printed to buffer 3177 * number of bytes printed to buffer
3175 **/ 3178 **/
3176static ssize_t ipr_read_dump(struct kobject *kobj, char *buf, 3179static ssize_t ipr_read_dump(struct kobject *kobj,
3177 loff_t off, size_t count) 3180 struct bin_attribute *bin_attr,
3181 char *buf, loff_t off, size_t count)
3178{ 3182{
3179 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 3183 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3180 struct Scsi_Host *shost = class_to_shost(cdev); 3184 struct Scsi_Host *shost = class_to_shost(cdev);
@@ -3327,6 +3331,7 @@ static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3327/** 3331/**
3328 * ipr_write_dump - Setup dump state of adapter 3332 * ipr_write_dump - Setup dump state of adapter
3329 * @kobj: kobject struct 3333 * @kobj: kobject struct
3334 * @bin_attr: bin_attribute struct
3330 * @buf: buffer 3335 * @buf: buffer
3331 * @off: offset 3336 * @off: offset
3332 * @count: buffer size 3337 * @count: buffer size
@@ -3334,8 +3339,9 @@ static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3334 * Return value: 3339 * Return value:
3335 * number of bytes printed to buffer 3340 * number of bytes printed to buffer
3336 **/ 3341 **/
3337static ssize_t ipr_write_dump(struct kobject *kobj, char *buf, 3342static ssize_t ipr_write_dump(struct kobject *kobj,
3338 loff_t off, size_t count) 3343 struct bin_attribute *bin_attr,
3344 char *buf, loff_t off, size_t count)
3339{ 3345{
3340 struct class_device *cdev = container_of(kobj,struct class_device,kobj); 3346 struct class_device *cdev = container_of(kobj,struct class_device,kobj);
3341 struct Scsi_Host *shost = class_to_shost(cdev); 3347 struct Scsi_Host *shost = class_to_shost(cdev);
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index e34442e405e8..23e90c5f8f35 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -38,8 +38,10 @@ static int sas_disable_routing(struct domain_device *dev, u8 *sas_addr);
38 38
39#if 0 39#if 0
40/* FIXME: smp needs to migrate into the sas class */ 40/* FIXME: smp needs to migrate into the sas class */
41static ssize_t smp_portal_read(struct kobject *, char *, loff_t, size_t); 41static ssize_t smp_portal_read(struct kobject *, struct bin_attribute *,
42static ssize_t smp_portal_write(struct kobject *, char *, loff_t, size_t); 42 char *, loff_t, size_t);
43static ssize_t smp_portal_write(struct kobject *, struct bin_attribute *,
44 char *, loff_t, size_t);
43#endif 45#endif
44 46
45/* ---------- SMP task management ---------- */ 47/* ---------- SMP task management ---------- */
@@ -1368,7 +1370,6 @@ static void sas_ex_smp_hook(struct domain_device *dev)
1368 memset(bin_attr, 0, sizeof(*bin_attr)); 1370 memset(bin_attr, 0, sizeof(*bin_attr));
1369 1371
1370 bin_attr->attr.name = SMP_BIN_ATTR_NAME; 1372 bin_attr->attr.name = SMP_BIN_ATTR_NAME;
1371 bin_attr->attr.owner = THIS_MODULE;
1372 bin_attr->attr.mode = 0600; 1373 bin_attr->attr.mode = 0600;
1373 1374
1374 bin_attr->size = 0; 1375 bin_attr->size = 0;
@@ -1846,8 +1847,9 @@ out:
1846#if 0 1847#if 0
1847/* ---------- SMP portal ---------- */ 1848/* ---------- SMP portal ---------- */
1848 1849
1849static ssize_t smp_portal_write(struct kobject *kobj, char *buf, loff_t offs, 1850static ssize_t smp_portal_write(struct kobject *kobj,
1850 size_t size) 1851 struct bin_attribute *bin_attr,
1852 char *buf, loff_t offs, size_t size)
1851{ 1853{
1852 struct domain_device *dev = to_dom_device(kobj); 1854 struct domain_device *dev = to_dom_device(kobj);
1853 struct expander_device *ex = &dev->ex_dev; 1855 struct expander_device *ex = &dev->ex_dev;
@@ -1873,8 +1875,9 @@ static ssize_t smp_portal_write(struct kobject *kobj, char *buf, loff_t offs,
1873 return size; 1875 return size;
1874} 1876}
1875 1877
1876static ssize_t smp_portal_read(struct kobject *kobj, char *buf, loff_t offs, 1878static ssize_t smp_portal_read(struct kobject *kobj,
1877 size_t size) 1879 struct bin_attribute *bin_attr,
1880 char *buf, loff_t offs, size_t size)
1878{ 1881{
1879 struct domain_device *dev = to_dom_device(kobj); 1882 struct domain_device *dev = to_dom_device(kobj);
1880 struct expander_device *ex = &dev->ex_dev; 1883 struct expander_device *ex = &dev->ex_dev;
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 95fe77e816f8..5dfda9778c80 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1133,7 +1133,8 @@ struct class_device_attribute *lpfc_host_attrs[] = {
1133}; 1133};
1134 1134
1135static ssize_t 1135static ssize_t
1136sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 1136sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1137 char *buf, loff_t off, size_t count)
1137{ 1138{
1138 size_t buf_off; 1139 size_t buf_off;
1139 struct Scsi_Host *host = class_to_shost(container_of(kobj, 1140 struct Scsi_Host *host = class_to_shost(container_of(kobj,
@@ -1165,7 +1166,8 @@ sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1165} 1166}
1166 1167
1167static ssize_t 1168static ssize_t
1168sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 1169sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1170 char *buf, loff_t off, size_t count)
1169{ 1171{
1170 size_t buf_off; 1172 size_t buf_off;
1171 uint32_t * tmp_ptr; 1173 uint32_t * tmp_ptr;
@@ -1200,7 +1202,6 @@ static struct bin_attribute sysfs_ctlreg_attr = {
1200 .attr = { 1202 .attr = {
1201 .name = "ctlreg", 1203 .name = "ctlreg",
1202 .mode = S_IRUSR | S_IWUSR, 1204 .mode = S_IRUSR | S_IWUSR,
1203 .owner = THIS_MODULE,
1204 }, 1205 },
1205 .size = 256, 1206 .size = 256,
1206 .read = sysfs_ctlreg_read, 1207 .read = sysfs_ctlreg_read,
@@ -1222,7 +1223,8 @@ sysfs_mbox_idle (struct lpfc_hba * phba)
1222} 1223}
1223 1224
1224static ssize_t 1225static ssize_t
1225sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 1226sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1227 char *buf, loff_t off, size_t count)
1226{ 1228{
1227 struct Scsi_Host * host = 1229 struct Scsi_Host * host =
1228 class_to_shost(container_of(kobj, struct class_device, kobj)); 1230 class_to_shost(container_of(kobj, struct class_device, kobj));
@@ -1274,7 +1276,8 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1274} 1276}
1275 1277
1276static ssize_t 1278static ssize_t
1277sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 1279sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1280 char *buf, loff_t off, size_t count)
1278{ 1281{
1279 struct Scsi_Host *host = 1282 struct Scsi_Host *host =
1280 class_to_shost(container_of(kobj, struct class_device, 1283 class_to_shost(container_of(kobj, struct class_device,
@@ -1422,7 +1425,6 @@ static struct bin_attribute sysfs_mbox_attr = {
1422 .attr = { 1425 .attr = {
1423 .name = "mbox", 1426 .name = "mbox",
1424 .mode = S_IRUSR | S_IWUSR, 1427 .mode = S_IRUSR | S_IWUSR,
1425 .owner = THIS_MODULE,
1426 }, 1428 },
1427 .size = MAILBOX_CMD_SIZE, 1429 .size = MAILBOX_CMD_SIZE,
1428 .read = sysfs_mbox_read, 1430 .read = sysfs_mbox_read,
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 8081b637d97e..942db9de785e 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -11,8 +11,9 @@
11/* SYSFS attributes --------------------------------------------------------- */ 11/* SYSFS attributes --------------------------------------------------------- */
12 12
13static ssize_t 13static ssize_t
14qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off, 14qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
15 size_t count) 15 struct bin_attribute *bin_attr,
16 char *buf, loff_t off, size_t count)
16{ 17{
17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 18 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
18 struct device, kobj))); 19 struct device, kobj)));
@@ -31,8 +32,9 @@ qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
31} 32}
32 33
33static ssize_t 34static ssize_t
34qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off, 35qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
35 size_t count) 36 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
36{ 38{
37 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 39 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
38 struct device, kobj))); 40 struct device, kobj)));
@@ -73,7 +75,6 @@ static struct bin_attribute sysfs_fw_dump_attr = {
73 .attr = { 75 .attr = {
74 .name = "fw_dump", 76 .name = "fw_dump",
75 .mode = S_IRUSR | S_IWUSR, 77 .mode = S_IRUSR | S_IWUSR,
76 .owner = THIS_MODULE,
77 }, 78 },
78 .size = 0, 79 .size = 0,
79 .read = qla2x00_sysfs_read_fw_dump, 80 .read = qla2x00_sysfs_read_fw_dump,
@@ -81,8 +82,9 @@ static struct bin_attribute sysfs_fw_dump_attr = {
81}; 82};
82 83
83static ssize_t 84static ssize_t
84qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off, 85qla2x00_sysfs_read_nvram(struct kobject *kobj,
85 size_t count) 86 struct bin_attribute *bin_attr,
87 char *buf, loff_t off, size_t count)
86{ 88{
87 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 89 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
88 struct device, kobj))); 90 struct device, kobj)));
@@ -101,8 +103,9 @@ qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
101} 103}
102 104
103static ssize_t 105static ssize_t
104qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off, 106qla2x00_sysfs_write_nvram(struct kobject *kobj,
105 size_t count) 107 struct bin_attribute *bin_attr,
108 char *buf, loff_t off, size_t count)
106{ 109{
107 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 110 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
108 struct device, kobj))); 111 struct device, kobj)));
@@ -149,7 +152,6 @@ static struct bin_attribute sysfs_nvram_attr = {
149 .attr = { 152 .attr = {
150 .name = "nvram", 153 .name = "nvram",
151 .mode = S_IRUSR | S_IWUSR, 154 .mode = S_IRUSR | S_IWUSR,
152 .owner = THIS_MODULE,
153 }, 155 },
154 .size = 512, 156 .size = 512,
155 .read = qla2x00_sysfs_read_nvram, 157 .read = qla2x00_sysfs_read_nvram,
@@ -157,8 +159,9 @@ static struct bin_attribute sysfs_nvram_attr = {
157}; 159};
158 160
159static ssize_t 161static ssize_t
160qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off, 162qla2x00_sysfs_read_optrom(struct kobject *kobj,
161 size_t count) 163 struct bin_attribute *bin_attr,
164 char *buf, loff_t off, size_t count)
162{ 165{
163 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 166 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
164 struct device, kobj))); 167 struct device, kobj)));
@@ -176,8 +179,9 @@ qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
176} 179}
177 180
178static ssize_t 181static ssize_t
179qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off, 182qla2x00_sysfs_write_optrom(struct kobject *kobj,
180 size_t count) 183 struct bin_attribute *bin_attr,
184 char *buf, loff_t off, size_t count)
181{ 185{
182 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 186 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
183 struct device, kobj))); 187 struct device, kobj)));
@@ -198,7 +202,6 @@ static struct bin_attribute sysfs_optrom_attr = {
198 .attr = { 202 .attr = {
199 .name = "optrom", 203 .name = "optrom",
200 .mode = S_IRUSR | S_IWUSR, 204 .mode = S_IRUSR | S_IWUSR,
201 .owner = THIS_MODULE,
202 }, 205 },
203 .size = OPTROM_SIZE_24XX, 206 .size = OPTROM_SIZE_24XX,
204 .read = qla2x00_sysfs_read_optrom, 207 .read = qla2x00_sysfs_read_optrom,
@@ -206,8 +209,9 @@ static struct bin_attribute sysfs_optrom_attr = {
206}; 209};
207 210
208static ssize_t 211static ssize_t
209qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off, 212qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
210 size_t count) 213 struct bin_attribute *bin_attr,
214 char *buf, loff_t off, size_t count)
211{ 215{
212 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 216 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
213 struct device, kobj))); 217 struct device, kobj)));
@@ -279,15 +283,15 @@ static struct bin_attribute sysfs_optrom_ctl_attr = {
279 .attr = { 283 .attr = {
280 .name = "optrom_ctl", 284 .name = "optrom_ctl",
281 .mode = S_IWUSR, 285 .mode = S_IWUSR,
282 .owner = THIS_MODULE,
283 }, 286 },
284 .size = 0, 287 .size = 0,
285 .write = qla2x00_sysfs_write_optrom_ctl, 288 .write = qla2x00_sysfs_write_optrom_ctl,
286}; 289};
287 290
288static ssize_t 291static ssize_t
289qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off, 292qla2x00_sysfs_read_vpd(struct kobject *kobj,
290 size_t count) 293 struct bin_attribute *bin_attr,
294 char *buf, loff_t off, size_t count)
291{ 295{
292 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 296 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
293 struct device, kobj))); 297 struct device, kobj)));
@@ -305,8 +309,9 @@ qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
305} 309}
306 310
307static ssize_t 311static ssize_t
308qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off, 312qla2x00_sysfs_write_vpd(struct kobject *kobj,
309 size_t count) 313 struct bin_attribute *bin_attr,
314 char *buf, loff_t off, size_t count)
310{ 315{
311 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 316 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
312 struct device, kobj))); 317 struct device, kobj)));
@@ -327,7 +332,6 @@ static struct bin_attribute sysfs_vpd_attr = {
327 .attr = { 332 .attr = {
328 .name = "vpd", 333 .name = "vpd",
329 .mode = S_IRUSR | S_IWUSR, 334 .mode = S_IRUSR | S_IWUSR,
330 .owner = THIS_MODULE,
331 }, 335 },
332 .size = 0, 336 .size = 0,
333 .read = qla2x00_sysfs_read_vpd, 337 .read = qla2x00_sysfs_read_vpd,
@@ -335,8 +339,9 @@ static struct bin_attribute sysfs_vpd_attr = {
335}; 339};
336 340
337static ssize_t 341static ssize_t
338qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off, 342qla2x00_sysfs_read_sfp(struct kobject *kobj,
339 size_t count) 343 struct bin_attribute *bin_attr,
344 char *buf, loff_t off, size_t count)
340{ 345{
341 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj, 346 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
342 struct device, kobj))); 347 struct device, kobj)));
@@ -375,7 +380,6 @@ static struct bin_attribute sysfs_sfp_attr = {
375 .attr = { 380 .attr = {
376 .name = "sfp", 381 .name = "sfp",
377 .mode = S_IRUSR | S_IWUSR, 382 .mode = S_IRUSR | S_IWUSR,
378 .owner = THIS_MODULE,
379 }, 383 },
380 .size = SFP_DEV_SIZE * 2, 384 .size = SFP_DEV_SIZE * 2,
381 .read = qla2x00_sysfs_read_sfp, 385 .read = qla2x00_sysfs_read_sfp,
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 315ea9916456..2adbed4e10f3 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -556,7 +556,7 @@ choice
556 556
557config SERIAL_BFIN_DMA 557config SERIAL_BFIN_DMA
558 bool "DMA mode" 558 bool "DMA mode"
559 depends on DMA_UNCACHED_1M 559 depends on DMA_UNCACHED_1M && !KGDB_UART
560 help 560 help
561 This driver works under DMA mode. If this option is selected, the 561 This driver works under DMA mode. If this option is selected, the
562 blackfin simple dma driver is also enabled. 562 blackfin simple dma driver is also enabled.
@@ -599,7 +599,7 @@ config UART0_RTS_PIN
599 599
600config SERIAL_BFIN_UART1 600config SERIAL_BFIN_UART1
601 bool "Enable UART1" 601 bool "Enable UART1"
602 depends on SERIAL_BFIN && (BF534 || BF536 || BF537) 602 depends on SERIAL_BFIN && (BF534 || BF536 || BF537 || BF54x)
603 help 603 help
604 Enable UART1 604 Enable UART1
605 605
@@ -612,18 +612,58 @@ config BFIN_UART1_CTSRTS
612 612
613config UART1_CTS_PIN 613config UART1_CTS_PIN
614 int "UART1 CTS pin" 614 int "UART1 CTS pin"
615 depends on BFIN_UART1_CTSRTS 615 depends on BFIN_UART1_CTSRTS && (BF53x || BF561)
616 default -1 616 default -1
617 help 617 help
618 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map. 618 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map.
619 619
620config UART1_RTS_PIN 620config UART1_RTS_PIN
621 int "UART1 RTS pin" 621 int "UART1 RTS pin"
622 depends on BFIN_UART1_CTSRTS 622 depends on BFIN_UART1_CTSRTS && (BF53x || BF561)
623 default -1 623 default -1
624 help 624 help
625 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map. 625 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map.
626 626
627config SERIAL_BFIN_UART2
628 bool "Enable UART2"
629 depends on SERIAL_BFIN && (BF54x)
630 help
631 Enable UART2
632
633config BFIN_UART2_CTSRTS
634 bool "Enable UART2 hardware flow control"
635 depends on SERIAL_BFIN_UART2
636 help
637 Enable hardware flow control in the driver. Using GPIO emulate the CTS/RTS
638 signal.
639
640config UART2_CTS_PIN
641 int "UART2 CTS pin"
642 depends on BFIN_UART2_CTSRTS
643 default -1
644 help
645 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map.
646
647config UART2_RTS_PIN
648 int "UART2 RTS pin"
649 depends on BFIN_UART2_CTSRTS
650 default -1
651 help
652 Refer to ./include/asm-blackfin/gpio.h to see the GPIO map.
653
654config SERIAL_BFIN_UART3
655 bool "Enable UART3"
656 depends on SERIAL_BFIN && (BF54x)
657 help
658 Enable UART3
659
660config BFIN_UART3_CTSRTS
661 bool "Enable UART3 hardware flow control"
662 depends on SERIAL_BFIN_UART3
663 help
664 Enable hardware flow control in the driver. Using GPIO emulate the CTS/RTS
665 signal.
666
627config SERIAL_IMX 667config SERIAL_IMX
628 bool "IMX serial port support" 668 bool "IMX serial port support"
629 depends on ARM && ARCH_IMX 669 depends on ARM && ARCH_IMX
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 22569bd5d821..66c92bc36f3d 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -41,6 +41,11 @@
41#include <linux/tty_flip.h> 41#include <linux/tty_flip.h>
42#include <linux/serial_core.h> 42#include <linux/serial_core.h>
43 43
44#ifdef CONFIG_KGDB_UART
45#include <linux/kgdb.h>
46#include <asm/irq_regs.h>
47#endif
48
44#include <asm/gpio.h> 49#include <asm/gpio.h>
45#include <asm/mach/bfin_serial_5xx.h> 50#include <asm/mach/bfin_serial_5xx.h>
46 51
@@ -81,15 +86,29 @@ static void bfin_serial_stop_tx(struct uart_port *port)
81{ 86{
82 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 87 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
83 88
89#ifdef CONFIG_BF54x
90 while (!(UART_GET_LSR(uart) & TEMT))
91 continue;
92#endif
93
84#ifdef CONFIG_SERIAL_BFIN_DMA 94#ifdef CONFIG_SERIAL_BFIN_DMA
85 disable_dma(uart->tx_dma_channel); 95 disable_dma(uart->tx_dma_channel);
86#else 96#else
97#ifdef CONFIG_BF54x
98 /* Waiting for Transmission Finished */
99 while (!(UART_GET_LSR(uart) & TFI))
100 continue;
101 /* Clear TFI bit */
102 UART_PUT_LSR(uart, TFI);
103 UART_CLEAR_IER(uart, ETBEI);
104#else
87 unsigned short ier; 105 unsigned short ier;
88 106
89 ier = UART_GET_IER(uart); 107 ier = UART_GET_IER(uart);
90 ier &= ~ETBEI; 108 ier &= ~ETBEI;
91 UART_PUT_IER(uart, ier); 109 UART_PUT_IER(uart, ier);
92#endif 110#endif
111#endif
93} 112}
94 113
95/* 114/*
@@ -102,12 +121,16 @@ static void bfin_serial_start_tx(struct uart_port *port)
102#ifdef CONFIG_SERIAL_BFIN_DMA 121#ifdef CONFIG_SERIAL_BFIN_DMA
103 bfin_serial_dma_tx_chars(uart); 122 bfin_serial_dma_tx_chars(uart);
104#else 123#else
124#ifdef CONFIG_BF54x
125 UART_SET_IER(uart, ETBEI);
126#else
105 unsigned short ier; 127 unsigned short ier;
106 ier = UART_GET_IER(uart); 128 ier = UART_GET_IER(uart);
107 ier |= ETBEI; 129 ier |= ETBEI;
108 UART_PUT_IER(uart, ier); 130 UART_PUT_IER(uart, ier);
109 bfin_serial_tx_chars(uart); 131 bfin_serial_tx_chars(uart);
110#endif 132#endif
133#endif
111} 134}
112 135
113/* 136/*
@@ -116,11 +139,18 @@ static void bfin_serial_start_tx(struct uart_port *port)
116static void bfin_serial_stop_rx(struct uart_port *port) 139static void bfin_serial_stop_rx(struct uart_port *port)
117{ 140{
118 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 141 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
142#ifdef CONFIG_BF54x
143 UART_CLEAR_IER(uart, ERBFI);
144#else
119 unsigned short ier; 145 unsigned short ier;
120 146
121 ier = UART_GET_IER(uart); 147 ier = UART_GET_IER(uart);
148#ifdef CONFIG_KGDB_UART
149 if (uart->port.line != CONFIG_KGDB_UART_PORT)
150#endif
122 ier &= ~ERBFI; 151 ier &= ~ERBFI;
123 UART_PUT_IER(uart, ier); 152 UART_PUT_IER(uart, ier);
153#endif
124} 154}
125 155
126/* 156/*
@@ -130,6 +160,49 @@ static void bfin_serial_enable_ms(struct uart_port *port)
130{ 160{
131} 161}
132 162
163#ifdef CONFIG_KGDB_UART
164static int kgdb_entry_state;
165
166void kgdb_put_debug_char(int chr)
167{
168 struct bfin_serial_port *uart;
169
170 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
171 uart = &bfin_serial_ports[0];
172 else
173 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
174
175 while (!(UART_GET_LSR(uart) & THRE)) {
176 __builtin_bfin_ssync();
177 }
178 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
179 __builtin_bfin_ssync();
180 UART_PUT_CHAR(uart, (unsigned char)chr);
181 __builtin_bfin_ssync();
182}
183
184int kgdb_get_debug_char(void)
185{
186 struct bfin_serial_port *uart;
187 unsigned char chr;
188
189 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
190 uart = &bfin_serial_ports[0];
191 else
192 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
193
194 while(!(UART_GET_LSR(uart) & DR)) {
195 __builtin_bfin_ssync();
196 }
197 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
198 __builtin_bfin_ssync();
199 chr = UART_GET_CHAR(uart);
200 __builtin_bfin_ssync();
201
202 return chr;
203}
204#endif
205
133#ifdef CONFIG_SERIAL_BFIN_PIO 206#ifdef CONFIG_SERIAL_BFIN_PIO
134static void local_put_char(struct bfin_serial_port *uart, char ch) 207static void local_put_char(struct bfin_serial_port *uart, char ch)
135{ 208{
@@ -152,6 +225,9 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
152{ 225{
153 struct tty_struct *tty = uart->port.info->tty; 226 struct tty_struct *tty = uart->port.info->tty;
154 unsigned int status, ch, flg; 227 unsigned int status, ch, flg;
228#ifdef CONFIG_KGDB_UART
229 struct pt_regs *regs = get_irq_regs();
230#endif
155#ifdef BF533_FAMILY 231#ifdef BF533_FAMILY
156 static int in_break = 0; 232 static int in_break = 0;
157#endif 233#endif
@@ -160,6 +236,27 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
160 ch = UART_GET_CHAR(uart); 236 ch = UART_GET_CHAR(uart);
161 uart->port.icount.rx++; 237 uart->port.icount.rx++;
162 238
239#ifdef CONFIG_KGDB_UART
240 if (uart->port.line == CONFIG_KGDB_UART_PORT) {
241 if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */
242 kgdb_breakkey_pressed(regs);
243 return;
244 } else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
245 kgdb_entry_state = 1;
246 } else if (kgdb_entry_state == 1 && ch == 'q') {
247 kgdb_entry_state = 0;
248 kgdb_breakkey_pressed(regs);
249 return;
250 } else if (ch == 0x3) {/* Ctrl + C */
251 kgdb_entry_state = 0;
252 kgdb_breakkey_pressed(regs);
253 return;
254 } else {
255 kgdb_entry_state = 0;
256 }
257 }
258#endif
259
163#ifdef BF533_FAMILY 260#ifdef BF533_FAMILY
164 /* The BF533 family of processors have a nice misbehavior where 261 /* The BF533 family of processors have a nice misbehavior where
165 * they continuously generate characters for a "single" break. 262 * they continuously generate characters for a "single" break.
@@ -250,10 +347,21 @@ static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
250{ 347{
251 struct bfin_serial_port *uart = dev_id; 348 struct bfin_serial_port *uart = dev_id;
252 349
350#ifdef CONFIG_BF54x
351 unsigned short status;
352 spin_lock(&uart->port.lock);
353 status = UART_GET_LSR(uart);
354 while ((UART_GET_IER(uart) & ERBFI) && (status & DR)) {
355 bfin_serial_rx_chars(uart);
356 status = UART_GET_LSR(uart);
357 }
358 spin_unlock(&uart->port.lock);
359#else
253 spin_lock(&uart->port.lock); 360 spin_lock(&uart->port.lock);
254 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_RX_READY) 361 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_RX_READY)
255 bfin_serial_rx_chars(uart); 362 bfin_serial_rx_chars(uart);
256 spin_unlock(&uart->port.lock); 363 spin_unlock(&uart->port.lock);
364#endif
257 return IRQ_HANDLED; 365 return IRQ_HANDLED;
258} 366}
259 367
@@ -261,10 +369,21 @@ static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
261{ 369{
262 struct bfin_serial_port *uart = dev_id; 370 struct bfin_serial_port *uart = dev_id;
263 371
372#ifdef CONFIG_BF54x
373 unsigned short status;
374 spin_lock(&uart->port.lock);
375 status = UART_GET_LSR(uart);
376 while ((UART_GET_IER(uart) & ETBEI) && (status & THRE)) {
377 bfin_serial_tx_chars(uart);
378 status = UART_GET_LSR(uart);
379 }
380 spin_unlock(&uart->port.lock);
381#else
264 spin_lock(&uart->port.lock); 382 spin_lock(&uart->port.lock);
265 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_TX_READY) 383 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_TX_READY)
266 bfin_serial_tx_chars(uart); 384 bfin_serial_tx_chars(uart);
267 spin_unlock(&uart->port.lock); 385 spin_unlock(&uart->port.lock);
386#endif
268 return IRQ_HANDLED; 387 return IRQ_HANDLED;
269} 388}
270 389
@@ -275,7 +394,6 @@ static void bfin_serial_do_work(struct work_struct *work)
275 394
276 bfin_serial_mctrl_check(uart); 395 bfin_serial_mctrl_check(uart);
277} 396}
278
279#endif 397#endif
280 398
281#ifdef CONFIG_SERIAL_BFIN_DMA 399#ifdef CONFIG_SERIAL_BFIN_DMA
@@ -324,9 +442,13 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
324 set_dma_x_count(uart->tx_dma_channel, uart->tx_count); 442 set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
325 set_dma_x_modify(uart->tx_dma_channel, 1); 443 set_dma_x_modify(uart->tx_dma_channel, 1);
326 enable_dma(uart->tx_dma_channel); 444 enable_dma(uart->tx_dma_channel);
445#ifdef CONFIG_BF54x
446 UART_SET_IER(uart, ETBEI);
447#else
327 ier = UART_GET_IER(uart); 448 ier = UART_GET_IER(uart);
328 ier |= ETBEI; 449 ier |= ETBEI;
329 UART_PUT_IER(uart, ier); 450 UART_PUT_IER(uart, ier);
451#endif
330 spin_unlock_irqrestore(&uart->port.lock, flags); 452 spin_unlock_irqrestore(&uart->port.lock, flags);
331} 453}
332 454
@@ -406,9 +528,13 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
406 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { 528 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
407 clear_dma_irqstat(uart->tx_dma_channel); 529 clear_dma_irqstat(uart->tx_dma_channel);
408 disable_dma(uart->tx_dma_channel); 530 disable_dma(uart->tx_dma_channel);
531#ifdef CONFIG_BF54x
532 UART_CLEAR_IER(uart, ETBEI);
533#else
409 ier = UART_GET_IER(uart); 534 ier = UART_GET_IER(uart);
410 ier &= ~ETBEI; 535 ier &= ~ETBEI;
411 UART_PUT_IER(uart, ier); 536 UART_PUT_IER(uart, ier);
537#endif
412 xmit->tail = (xmit->tail+uart->tx_count) &(UART_XMIT_SIZE -1); 538 xmit->tail = (xmit->tail+uart->tx_count) &(UART_XMIT_SIZE -1);
413 uart->port.icount.tx+=uart->tx_count; 539 uart->port.icount.tx+=uart->tx_count;
414 540
@@ -571,7 +697,11 @@ static int bfin_serial_startup(struct uart_port *port)
571 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 697 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
572 add_timer(&(uart->rx_dma_timer)); 698 add_timer(&(uart->rx_dma_timer));
573#else 699#else
700# ifdef CONFIG_KGDB_UART
701 if (uart->port.line != CONFIG_KGDB_UART_PORT && request_irq
702# else
574 if (request_irq 703 if (request_irq
704# endif
575 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, 705 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
576 "BFIN_UART_RX", uart)) { 706 "BFIN_UART_RX", uart)) {
577 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 707 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
@@ -586,7 +716,11 @@ static int bfin_serial_startup(struct uart_port *port)
586 return -EBUSY; 716 return -EBUSY;
587 } 717 }
588#endif 718#endif
719#ifdef CONFIG_BF54x
720 UART_SET_IER(uart, ERBFI);
721#else
589 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI); 722 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI);
723#endif
590 return 0; 724 return 0;
591} 725}
592 726
@@ -601,6 +735,9 @@ static void bfin_serial_shutdown(struct uart_port *port)
601 free_dma(uart->rx_dma_channel); 735 free_dma(uart->rx_dma_channel);
602 del_timer(&(uart->rx_dma_timer)); 736 del_timer(&(uart->rx_dma_timer));
603#else 737#else
738#ifdef CONFIG_KGDB_UART
739 if (uart->port.line != CONFIG_KGDB_UART_PORT)
740#endif
604 free_irq(uart->port.irq, uart); 741 free_irq(uart->port.irq, uart);
605 free_irq(uart->port.irq+1, uart); 742 free_irq(uart->port.irq+1, uart);
606#endif 743#endif
@@ -674,29 +811,41 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
674 811
675 /* Disable UART */ 812 /* Disable UART */
676 ier = UART_GET_IER(uart); 813 ier = UART_GET_IER(uart);
814#ifdef CONFIG_BF54x
815 UART_CLEAR_IER(uart, 0xF);
816#else
677 UART_PUT_IER(uart, 0); 817 UART_PUT_IER(uart, 0);
818#endif
678 819
820#ifndef CONFIG_BF54x
679 /* Set DLAB in LCR to Access DLL and DLH */ 821 /* Set DLAB in LCR to Access DLL and DLH */
680 val = UART_GET_LCR(uart); 822 val = UART_GET_LCR(uart);
681 val |= DLAB; 823 val |= DLAB;
682 UART_PUT_LCR(uart, val); 824 UART_PUT_LCR(uart, val);
683 SSYNC(); 825 SSYNC();
826#endif
684 827
685 UART_PUT_DLL(uart, quot & 0xFF); 828 UART_PUT_DLL(uart, quot & 0xFF);
686 SSYNC(); 829 SSYNC();
687 UART_PUT_DLH(uart, (quot >> 8) & 0xFF); 830 UART_PUT_DLH(uart, (quot >> 8) & 0xFF);
688 SSYNC(); 831 SSYNC();
689 832
833#ifndef CONFIG_BF54x
690 /* Clear DLAB in LCR to Access THR RBR IER */ 834 /* Clear DLAB in LCR to Access THR RBR IER */
691 val = UART_GET_LCR(uart); 835 val = UART_GET_LCR(uart);
692 val &= ~DLAB; 836 val &= ~DLAB;
693 UART_PUT_LCR(uart, val); 837 UART_PUT_LCR(uart, val);
694 SSYNC(); 838 SSYNC();
839#endif
695 840
696 UART_PUT_LCR(uart, lcr); 841 UART_PUT_LCR(uart, lcr);
697 842
698 /* Enable UART */ 843 /* Enable UART */
844#ifdef CONFIG_BF54x
845 UART_SET_IER(uart, ier);
846#else
699 UART_PUT_IER(uart, ier); 847 UART_PUT_IER(uart, ier);
848#endif
700 849
701 val = UART_GET_GCTL(uart); 850 val = UART_GET_GCTL(uart);
702 val |= UCEN; 851 val |= UCEN;
@@ -808,15 +957,15 @@ static void __init bfin_serial_init_ports(void)
808 bfin_serial_resource[i].uart_rts_pin; 957 bfin_serial_resource[i].uart_rts_pin;
809#endif 958#endif
810 bfin_serial_hw_init(&bfin_serial_ports[i]); 959 bfin_serial_hw_init(&bfin_serial_ports[i]);
811
812 } 960 }
961
813} 962}
814 963
815#ifdef CONFIG_SERIAL_BFIN_CONSOLE 964#ifdef CONFIG_SERIAL_BFIN_CONSOLE
816static void bfin_serial_console_putchar(struct uart_port *port, int ch) 965static void bfin_serial_console_putchar(struct uart_port *port, int ch)
817{ 966{
818 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 967 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
819 while (!(UART_GET_LSR(uart))) 968 while (!(UART_GET_LSR(uart) & THRE))
820 barrier(); 969 barrier();
821 UART_PUT_CHAR(uart, ch); 970 UART_PUT_CHAR(uart, ch);
822 SSYNC(); 971 SSYNC();
@@ -868,18 +1017,22 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
868 case 2: *bits = 7; break; 1017 case 2: *bits = 7; break;
869 case 3: *bits = 8; break; 1018 case 3: *bits = 8; break;
870 } 1019 }
1020#ifndef CONFIG_BF54x
871 /* Set DLAB in LCR to Access DLL and DLH */ 1021 /* Set DLAB in LCR to Access DLL and DLH */
872 val = UART_GET_LCR(uart); 1022 val = UART_GET_LCR(uart);
873 val |= DLAB; 1023 val |= DLAB;
874 UART_PUT_LCR(uart, val); 1024 UART_PUT_LCR(uart, val);
1025#endif
875 1026
876 dll = UART_GET_DLL(uart); 1027 dll = UART_GET_DLL(uart);
877 dlh = UART_GET_DLH(uart); 1028 dlh = UART_GET_DLH(uart);
878 1029
1030#ifndef CONFIG_BF54x
879 /* Clear DLAB in LCR to Access THR RBR IER */ 1031 /* Clear DLAB in LCR to Access THR RBR IER */
880 val = UART_GET_LCR(uart); 1032 val = UART_GET_LCR(uart);
881 val &= ~DLAB; 1033 val &= ~DLAB;
882 UART_PUT_LCR(uart, val); 1034 UART_PUT_LCR(uart, val);
1035#endif
883 1036
884 *baud = get_sclk() / (16*(dll | dlh << 8)); 1037 *baud = get_sclk() / (16*(dll | dlh << 8));
885 } 1038 }
@@ -931,6 +1084,10 @@ static int __init bfin_serial_rs_console_init(void)
931{ 1084{
932 bfin_serial_init_ports(); 1085 bfin_serial_init_ports();
933 register_console(&bfin_serial_console); 1086 register_console(&bfin_serial_console);
1087#ifdef CONFIG_KGDB_UART
1088 kgdb_entry_state = 0;
1089 init_kgdb_uart();
1090#endif
934 return 0; 1091 return 0;
935} 1092}
936console_initcall(bfin_serial_rs_console_init); 1093console_initcall(bfin_serial_rs_console_init);
@@ -1023,6 +1180,10 @@ static struct platform_driver bfin_serial_driver = {
1023static int __init bfin_serial_init(void) 1180static int __init bfin_serial_init(void)
1024{ 1181{
1025 int ret; 1182 int ret;
1183#ifdef CONFIG_KGDB_UART
1184 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
1185 struct termios t;
1186#endif
1026 1187
1027 pr_info("Serial: Blackfin serial driver\n"); 1188 pr_info("Serial: Blackfin serial driver\n");
1028 1189
@@ -1036,6 +1197,21 @@ static int __init bfin_serial_init(void)
1036 uart_unregister_driver(&bfin_serial_reg); 1197 uart_unregister_driver(&bfin_serial_reg);
1037 } 1198 }
1038 } 1199 }
1200#ifdef CONFIG_KGDB_UART
1201 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
1202 request_irq(uart->port.irq, bfin_serial_int,
1203 IRQF_DISABLED, "BFIN_UART_RX", uart);
1204 pr_info("Request irq for kgdb uart port\n");
1205 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI);
1206 __builtin_bfin_ssync();
1207 t.c_cflag = CS8|B57600;
1208 t.c_iflag = 0;
1209 t.c_oflag = 0;
1210 t.c_lflag = ICANON;
1211 t.c_line = CONFIG_KGDB_UART_PORT;
1212 bfin_serial_set_termios(&uart->port, &t, &t);
1213 }
1214#endif
1039 return ret; 1215 return ret;
1040} 1216}
1041 1217
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index cf0e663b42ed..85309acb75f6 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for NEC VR4100 series Serial Interface Unit. 2 * Driver for NEC VR4100 series Serial Interface Unit.
3 * 3 *
4 * Copyright (C) 2004-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2004-2007 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
5 * 5 *
6 * Based on drivers/serial/8250.c, by Russell King. 6 * Based on drivers/serial/8250.c, by Russell King.
7 * 7 *
@@ -25,12 +25,12 @@
25#endif 25#endif
26 26
27#include <linux/console.h> 27#include <linux/console.h>
28#include <linux/platform_device.h> 28#include <linux/errno.h>
29#include <linux/err.h>
30#include <linux/ioport.h>
31#include <linux/init.h> 29#include <linux/init.h>
32#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/ioport.h>
33#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/platform_device.h>
34#include <linux/serial.h> 34#include <linux/serial.h>
35#include <linux/serial_core.h> 35#include <linux/serial_core.h>
36#include <linux/serial_reg.h> 36#include <linux/serial_reg.h>
@@ -38,11 +38,9 @@
38#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
39 39
40#include <asm/io.h> 40#include <asm/io.h>
41#include <asm/vr41xx/irq.h>
42#include <asm/vr41xx/siu.h> 41#include <asm/vr41xx/siu.h>
43#include <asm/vr41xx/vr41xx.h> 42#include <asm/vr41xx/vr41xx.h>
44 43
45#define SIU_PORTS_MAX 2
46#define SIU_BAUD_BASE 1152000 44#define SIU_BAUD_BASE 1152000
47#define SIU_MAJOR 204 45#define SIU_MAJOR 204
48#define SIU_MINOR_BASE 82 46#define SIU_MINOR_BASE 82
@@ -60,32 +58,13 @@
60 #define IRUSESEL 0x02 58 #define IRUSESEL 0x02
61 #define SIRSEL 0x01 59 #define SIRSEL 0x01
62 60
63struct siu_port { 61static struct uart_port siu_uart_ports[SIU_PORTS_MAX] = {
64 unsigned int type; 62 [0 ... SIU_PORTS_MAX-1] = {
65 unsigned int irq; 63 .lock = __SPIN_LOCK_UNLOCKED(siu_uart_ports->lock),
66 unsigned long start; 64 .irq = -1,
67}; 65 },
68
69static const struct siu_port siu_type1_ports[] = {
70 { .type = PORT_VR41XX_SIU,
71 .irq = SIU_IRQ,
72 .start = 0x0c000000UL, },
73};
74
75#define SIU_TYPE1_NR_PORTS (sizeof(siu_type1_ports) / sizeof(struct siu_port))
76
77static const struct siu_port siu_type2_ports[] = {
78 { .type = PORT_VR41XX_SIU,
79 .irq = SIU_IRQ,
80 .start = 0x0f000800UL, },
81 { .type = PORT_VR41XX_DSIU,
82 .irq = DSIU_IRQ,
83 .start = 0x0f000820UL, },
84}; 66};
85 67
86#define SIU_TYPE2_NR_PORTS (sizeof(siu_type2_ports) / sizeof(struct siu_port))
87
88static struct uart_port siu_uart_ports[SIU_PORTS_MAX];
89static uint8_t lsr_break_flag[SIU_PORTS_MAX]; 68static uint8_t lsr_break_flag[SIU_PORTS_MAX];
90 69
91#define siu_read(port, offset) readb((port)->membase + (offset)) 70#define siu_read(port, offset) readb((port)->membase + (offset))
@@ -110,7 +89,6 @@ void vr41xx_select_siu_interface(siu_interface_t interface)
110 89
111 spin_unlock_irqrestore(&port->lock, flags); 90 spin_unlock_irqrestore(&port->lock, flags);
112} 91}
113
114EXPORT_SYMBOL_GPL(vr41xx_select_siu_interface); 92EXPORT_SYMBOL_GPL(vr41xx_select_siu_interface);
115 93
116void vr41xx_use_irda(irda_use_t use) 94void vr41xx_use_irda(irda_use_t use)
@@ -132,7 +110,6 @@ void vr41xx_use_irda(irda_use_t use)
132 110
133 spin_unlock_irqrestore(&port->lock, flags); 111 spin_unlock_irqrestore(&port->lock, flags);
134} 112}
135
136EXPORT_SYMBOL_GPL(vr41xx_use_irda); 113EXPORT_SYMBOL_GPL(vr41xx_use_irda);
137 114
138void vr41xx_select_irda_module(irda_module_t module, irda_speed_t speed) 115void vr41xx_select_irda_module(irda_module_t module, irda_speed_t speed)
@@ -166,7 +143,6 @@ void vr41xx_select_irda_module(irda_module_t module, irda_speed_t speed)
166 143
167 spin_unlock_irqrestore(&port->lock, flags); 144 spin_unlock_irqrestore(&port->lock, flags);
168} 145}
169
170EXPORT_SYMBOL_GPL(vr41xx_select_irda_module); 146EXPORT_SYMBOL_GPL(vr41xx_select_irda_module);
171 147
172static inline void siu_clear_fifo(struct uart_port *port) 148static inline void siu_clear_fifo(struct uart_port *port)
@@ -177,21 +153,6 @@ static inline void siu_clear_fifo(struct uart_port *port)
177 siu_write(port, UART_FCR, 0); 153 siu_write(port, UART_FCR, 0);
178} 154}
179 155
180static inline int siu_probe_ports(void)
181{
182 switch (current_cpu_data.cputype) {
183 case CPU_VR4111:
184 case CPU_VR4121:
185 return SIU_TYPE1_NR_PORTS;
186 case CPU_VR4122:
187 case CPU_VR4131:
188 case CPU_VR4133:
189 return SIU_TYPE2_NR_PORTS;
190 }
191
192 return 0;
193}
194
195static inline unsigned long siu_port_size(struct uart_port *port) 156static inline unsigned long siu_port_size(struct uart_port *port)
196{ 157{
197 switch (port->type) { 158 switch (port->type) {
@@ -206,21 +167,10 @@ static inline unsigned long siu_port_size(struct uart_port *port)
206 167
207static inline unsigned int siu_check_type(struct uart_port *port) 168static inline unsigned int siu_check_type(struct uart_port *port)
208{ 169{
209 switch (current_cpu_data.cputype) { 170 if (port->line == 0)
210 case CPU_VR4111: 171 return PORT_VR41XX_SIU;
211 case CPU_VR4121: 172 if (port->line == 1 && port->irq != -1)
212 if (port->line == 0) 173 return PORT_VR41XX_DSIU;
213 return PORT_VR41XX_SIU;
214 break;
215 case CPU_VR4122:
216 case CPU_VR4131:
217 case CPU_VR4133:
218 if (port->line == 0)
219 return PORT_VR41XX_SIU;
220 else if (port->line == 1)
221 return PORT_VR41XX_DSIU;
222 break;
223 }
224 174
225 return PORT_UNKNOWN; 175 return PORT_UNKNOWN;
226} 176}
@@ -751,44 +701,34 @@ static struct uart_ops siu_uart_ops = {
751 .verify_port = siu_verify_port, 701 .verify_port = siu_verify_port,
752}; 702};
753 703
754static int siu_init_ports(void) 704static int siu_init_ports(struct platform_device *pdev)
755{ 705{
756 const struct siu_port *siu;
757 struct uart_port *port; 706 struct uart_port *port;
758 int i, num; 707 struct resource *res;
708 int *type = pdev->dev.platform_data;
709 int i;
759 710
760 switch (current_cpu_data.cputype) { 711 if (!type)
761 case CPU_VR4111:
762 case CPU_VR4121:
763 siu = siu_type1_ports;
764 break;
765 case CPU_VR4122:
766 case CPU_VR4131:
767 case CPU_VR4133:
768 siu = siu_type2_ports;
769 break;
770 default:
771 return 0; 712 return 0;
772 }
773 713
774 port = siu_uart_ports; 714 port = siu_uart_ports;
775 num = siu_probe_ports(); 715 for (i = 0; i < SIU_PORTS_MAX; i++) {
776 for (i = 0; i < num; i++) { 716 port->type = type[i];
777 spin_lock_init(&port->lock); 717 if (port->type == PORT_UNKNOWN)
778 port->irq = siu->irq; 718 continue;
719 port->irq = platform_get_irq(pdev, i);
779 port->uartclk = SIU_BAUD_BASE * 16; 720 port->uartclk = SIU_BAUD_BASE * 16;
780 port->fifosize = 16; 721 port->fifosize = 16;
781 port->regshift = 0; 722 port->regshift = 0;
782 port->iotype = UPIO_MEM; 723 port->iotype = UPIO_MEM;
783 port->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 724 port->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
784 port->type = siu->type;
785 port->line = i; 725 port->line = i;
786 port->mapbase = siu->start; 726 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
787 siu++; 727 port->mapbase = res->start;
788 port++; 728 port++;
789 } 729 }
790 730
791 return num; 731 return i;
792} 732}
793 733
794#ifdef CONFIG_SERIAL_VR41XX_CONSOLE 734#ifdef CONFIG_SERIAL_VR41XX_CONSOLE
@@ -883,13 +823,9 @@ static struct console siu_console = {
883static int __devinit siu_console_init(void) 823static int __devinit siu_console_init(void)
884{ 824{
885 struct uart_port *port; 825 struct uart_port *port;
886 int num, i; 826 int i;
887
888 num = siu_init_ports();
889 if (num <= 0)
890 return -ENODEV;
891 827
892 for (i = 0; i < num; i++) { 828 for (i = 0; i < SIU_PORTS_MAX; i++) {
893 port = &siu_uart_ports[i]; 829 port = &siu_uart_ports[i];
894 port->ops = &siu_uart_ops; 830 port->ops = &siu_uart_ops;
895 } 831 }
@@ -920,7 +856,7 @@ static int __devinit siu_probe(struct platform_device *dev)
920 struct uart_port *port; 856 struct uart_port *port;
921 int num, i, retval; 857 int num, i, retval;
922 858
923 num = siu_init_ports(); 859 num = siu_init_ports(dev);
924 if (num <= 0) 860 if (num <= 0)
925 return -ENODEV; 861 return -ENODEV;
926 862
@@ -998,8 +934,6 @@ static int siu_resume(struct platform_device *dev)
998 return 0; 934 return 0;
999} 935}
1000 936
1001static struct platform_device *siu_platform_device;
1002
1003static struct platform_driver siu_device_driver = { 937static struct platform_driver siu_device_driver = {
1004 .probe = siu_probe, 938 .probe = siu_probe,
1005 .remove = __devexit_p(siu_remove), 939 .remove = __devexit_p(siu_remove),
@@ -1013,29 +947,12 @@ static struct platform_driver siu_device_driver = {
1013 947
1014static int __init vr41xx_siu_init(void) 948static int __init vr41xx_siu_init(void)
1015{ 949{
1016 int retval; 950 return platform_driver_register(&siu_device_driver);
1017
1018 siu_platform_device = platform_device_alloc("SIU", -1);
1019 if (!siu_platform_device)
1020 return -ENOMEM;
1021
1022 retval = platform_device_add(siu_platform_device);
1023 if (retval < 0) {
1024 platform_device_put(siu_platform_device);
1025 return retval;
1026 }
1027
1028 retval = platform_driver_register(&siu_device_driver);
1029 if (retval < 0)
1030 platform_device_unregister(siu_platform_device);
1031
1032 return retval;
1033} 951}
1034 952
1035static void __exit vr41xx_siu_exit(void) 953static void __exit vr41xx_siu_exit(void)
1036{ 954{
1037 platform_driver_unregister(&siu_device_driver); 955 platform_driver_unregister(&siu_device_driver);
1038 platform_device_unregister(siu_platform_device);
1039} 956}
1040 957
1041module_init(vr41xx_siu_init); 958module_init(vr41xx_siu_init);
diff --git a/drivers/spi/at25.c b/drivers/spi/at25.c
index 8efa07e8b8c2..e007833cca59 100644
--- a/drivers/spi/at25.c
+++ b/drivers/spi/at25.c
@@ -111,7 +111,8 @@ at25_ee_read(
111} 111}
112 112
113static ssize_t 113static ssize_t
114at25_bin_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 114at25_bin_read(struct kobject *kobj, struct bin_attribute *bin_attr,
115 char *buf, loff_t off, size_t count)
115{ 116{
116 struct device *dev; 117 struct device *dev;
117 struct at25_data *at25; 118 struct at25_data *at25;
@@ -236,7 +237,8 @@ at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
236} 237}
237 238
238static ssize_t 239static ssize_t
239at25_bin_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 240at25_bin_write(struct kobject *kobj, struct bin_attribute *bin_attr,
241 char *buf, loff_t off, size_t count)
240{ 242{
241 struct device *dev; 243 struct device *dev;
242 struct at25_data *at25; 244 struct at25_data *at25;
@@ -314,7 +316,6 @@ static int at25_probe(struct spi_device *spi)
314 */ 316 */
315 at25->bin.attr.name = "eeprom"; 317 at25->bin.attr.name = "eeprom";
316 at25->bin.attr.mode = S_IRUSR; 318 at25->bin.attr.mode = S_IRUSR;
317 at25->bin.attr.owner = THIS_MODULE;
318 at25->bin.read = at25_bin_read; 319 at25->bin.read = at25_bin_read;
319 320
320 at25->bin.size = at25->chip.byte_len; 321 at25->bin.size = at25->chip.byte_len;
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index 4fff61b32dcb..ed979f13908a 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -136,14 +136,14 @@ struct dec_serial *zs_chain; /* list of all channels */
136struct tty_struct zs_ttys[NUM_CHANNELS]; 136struct tty_struct zs_ttys[NUM_CHANNELS];
137 137
138#ifdef CONFIG_SERIAL_DEC_CONSOLE 138#ifdef CONFIG_SERIAL_DEC_CONSOLE
139static struct console sercons; 139static struct console zs_console;
140#endif 140#endif
141#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \ 141#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
142 !defined(MODULE) 142 !defined(MODULE)
143static unsigned long break_pressed; /* break, really ... */ 143static unsigned long break_pressed; /* break, really ... */
144#endif 144#endif
145 145
146static unsigned char zs_init_regs[16] = { 146static unsigned char zs_init_regs[16] __initdata = {
147 0, /* write 0 */ 147 0, /* write 0 */
148 0, /* write 1 */ 148 0, /* write 1 */
149 0, /* write 2 */ 149 0, /* write 2 */
@@ -383,7 +383,7 @@ static void receive_chars(struct dec_serial *info)
383 383
384#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \ 384#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
385 !defined(MODULE) 385 !defined(MODULE)
386 if (break_pressed && info->line == sercons.index) { 386 if (break_pressed && info->line == zs_console.index) {
387 /* Ignore the null char got when BREAK is removed. */ 387 /* Ignore the null char got when BREAK is removed. */
388 if (ch == 0) 388 if (ch == 0)
389 continue; 389 continue;
@@ -446,7 +446,7 @@ static void status_handle(struct dec_serial *info)
446 if ((stat & BRK_ABRT) && !(info->read_reg_zero & BRK_ABRT)) { 446 if ((stat & BRK_ABRT) && !(info->read_reg_zero & BRK_ABRT)) {
447#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \ 447#if defined(CONFIG_SERIAL_DEC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && \
448 !defined(MODULE) 448 !defined(MODULE)
449 if (info->line == sercons.index) { 449 if (info->line == zs_console.index) {
450 if (!break_pressed) 450 if (!break_pressed)
451 break_pressed = jiffies; 451 break_pressed = jiffies;
452 } else 452 } else
@@ -1557,9 +1557,9 @@ static int rs_open(struct tty_struct *tty, struct file * filp)
1557 } 1557 }
1558 1558
1559#ifdef CONFIG_SERIAL_DEC_CONSOLE 1559#ifdef CONFIG_SERIAL_DEC_CONSOLE
1560 if (sercons.cflag && sercons.index == line) { 1560 if (zs_console.cflag && zs_console.index == line) {
1561 tty->termios->c_cflag = sercons.cflag; 1561 tty->termios->c_cflag = zs_console.cflag;
1562 sercons.cflag = 0; 1562 zs_console.cflag = 0;
1563 change_speed(info); 1563 change_speed(info);
1564 } 1564 }
1565#endif 1565#endif
@@ -1581,7 +1581,7 @@ static void __init show_serial_version(void)
1581/* Initialize Z8530s zs_channels 1581/* Initialize Z8530s zs_channels
1582 */ 1582 */
1583 1583
1584static void probe_sccs(void) 1584static void __init probe_sccs(void)
1585{ 1585{
1586 struct dec_serial **pp; 1586 struct dec_serial **pp;
1587 int i, n, n_chips = 0, n_channels, chip, channel; 1587 int i, n, n_chips = 0, n_channels, chip, channel;
@@ -1923,7 +1923,7 @@ static struct tty_driver *serial_console_device(struct console *c, int *index)
1923 * - initialize the serial port 1923 * - initialize the serial port
1924 * Return non-zero if we didn't find a serial port. 1924 * Return non-zero if we didn't find a serial port.
1925 */ 1925 */
1926static int serial_console_setup(struct console *co, char *options) 1926static int __init serial_console_setup(struct console *co, char *options)
1927{ 1927{
1928 struct dec_serial *info; 1928 struct dec_serial *info;
1929 int baud = 9600; 1929 int baud = 9600;
@@ -2069,7 +2069,7 @@ static int serial_console_setup(struct console *co, char *options)
2069 return 0; 2069 return 0;
2070} 2070}
2071 2071
2072static struct console sercons = { 2072static struct console zs_console = {
2073 .name = "ttyS", 2073 .name = "ttyS",
2074 .write = serial_console_write, 2074 .write = serial_console_write,
2075 .device = serial_console_device, 2075 .device = serial_console_device,
@@ -2083,7 +2083,7 @@ static struct console sercons = {
2083 */ 2083 */
2084void __init zs_serial_console_init(void) 2084void __init zs_serial_console_init(void)
2085{ 2085{
2086 register_console(&sercons); 2086 register_console(&zs_console);
2087} 2087}
2088#endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */ 2088#endif /* ifdef CONFIG_SERIAL_DEC_CONSOLE */
2089 2089
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 24f10a19dbdb..a9cf8b30bccc 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1109,11 +1109,6 @@ void usb_root_hub_lost_power(struct usb_device *rhdev)
1109 1109
1110 dev_warn(&rhdev->dev, "root hub lost power or was reset\n"); 1110 dev_warn(&rhdev->dev, "root hub lost power or was reset\n");
1111 1111
1112 /* Make sure no potential wakeup events get lost,
1113 * by forcing the root hub to be resumed.
1114 */
1115 rhdev->dev.power.prev_state.event = PM_EVENT_ON;
1116
1117 spin_lock_irqsave(&device_state_lock, flags); 1112 spin_lock_irqsave(&device_state_lock, flags);
1118 hub = hdev_to_hub(rhdev); 1113 hub = hdev_to_hub(rhdev);
1119 for (port1 = 1; port1 <= rhdev->maxchild; ++port1) { 1114 for (port1 = 1; port1 <= rhdev->maxchild; ++port1) {
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 2ce050193018..2349e71b0083 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -2102,7 +2102,9 @@ static ssize_t radeon_show_one_edid(char *buf, loff_t off, size_t count, const u
2102} 2102}
2103 2103
2104 2104
2105static ssize_t radeon_show_edid1(struct kobject *kobj, char *buf, loff_t off, size_t count) 2105static ssize_t radeon_show_edid1(struct kobject *kobj,
2106 struct bin_attribute *bin_attr,
2107 char *buf, loff_t off, size_t count)
2106{ 2108{
2107 struct device *dev = container_of(kobj, struct device, kobj); 2109 struct device *dev = container_of(kobj, struct device, kobj);
2108 struct pci_dev *pdev = to_pci_dev(dev); 2110 struct pci_dev *pdev = to_pci_dev(dev);
@@ -2113,7 +2115,9 @@ static ssize_t radeon_show_edid1(struct kobject *kobj, char *buf, loff_t off, si
2113} 2115}
2114 2116
2115 2117
2116static ssize_t radeon_show_edid2(struct kobject *kobj, char *buf, loff_t off, size_t count) 2118static ssize_t radeon_show_edid2(struct kobject *kobj,
2119 struct bin_attribute *bin_attr,
2120 char *buf, loff_t off, size_t count)
2117{ 2121{
2118 struct device *dev = container_of(kobj, struct device, kobj); 2122 struct device *dev = container_of(kobj, struct device, kobj);
2119 struct pci_dev *pdev = to_pci_dev(dev); 2123 struct pci_dev *pdev = to_pci_dev(dev);
@@ -2126,7 +2130,6 @@ static ssize_t radeon_show_edid2(struct kobject *kobj, char *buf, loff_t off, si
2126static struct bin_attribute edid1_attr = { 2130static struct bin_attribute edid1_attr = {
2127 .attr = { 2131 .attr = {
2128 .name = "edid1", 2132 .name = "edid1",
2129 .owner = THIS_MODULE,
2130 .mode = 0444, 2133 .mode = 0444,
2131 }, 2134 },
2132 .size = EDID_LENGTH, 2135 .size = EDID_LENGTH,
@@ -2136,7 +2139,6 @@ static struct bin_attribute edid1_attr = {
2136static struct bin_attribute edid2_attr = { 2139static struct bin_attribute edid2_attr = {
2137 .attr = { 2140 .attr = {
2138 .name = "edid2", 2141 .name = "edid2",
2139 .owner = THIS_MODULE,
2140 .mode = 0444, 2142 .mode = 0444,
2141 }, 2143 },
2142 .size = EDID_LENGTH, 2144 .size = EDID_LENGTH,
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index c65e81ff3578..7e06223bca94 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -172,7 +172,7 @@ static struct class backlight_class = {
172 172
173#define DECLARE_ATTR(_name,_mode,_show,_store) \ 173#define DECLARE_ATTR(_name,_mode,_show,_store) \
174{ \ 174{ \
175 .attr = { .name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \ 175 .attr = { .name = __stringify(_name), .mode = _mode }, \
176 .show = _show, \ 176 .show = _show, \
177 .store = _store, \ 177 .store = _store, \
178} 178}
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 6ef8f0a7a137..648b53c1fdea 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -157,7 +157,7 @@ static struct class lcd_class = {
157 157
158#define DECLARE_ATTR(_name,_mode,_show,_store) \ 158#define DECLARE_ATTR(_name,_mode,_show,_store) \
159{ \ 159{ \
160 .attr = { .name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \ 160 .attr = { .name = __stringify(_name), .mode = _mode }, \
161 .show = _show, \ 161 .show = _show, \
162 .store = _store, \ 162 .store = _store, \
163} 163}
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index 63b85bf81a65..d3b8a6be2916 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -6,7 +6,7 @@ menu "Console display driver support"
6 6
7config VGA_CONSOLE 7config VGA_CONSOLE
8 bool "VGA text console" if EMBEDDED || !X86 8 bool "VGA text console" if EMBEDDED || !X86
9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH 9 depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BFIN
10 default y 10 default y
11 help 11 help
12 Saying Y here will allow you to use Linux in text mode through a 12 Saying Y here will allow you to use Linux in text mode through a
diff --git a/drivers/video/matrox/matroxfb_crtc2.h b/drivers/video/matrox/matroxfb_crtc2.h
index 608e40bb20e9..177177609be7 100644
--- a/drivers/video/matrox/matroxfb_crtc2.h
+++ b/drivers/video/matrox/matroxfb_crtc2.h
@@ -2,8 +2,6 @@
2#define __MATROXFB_CRTC2_H__ 2#define __MATROXFB_CRTC2_H__
3 3
4#include <linux/ioctl.h> 4#include <linux/ioctl.h>
5#include <linux/i2c.h>
6#include <linux/i2c-algo-bit.h>
7#include "matroxfb_base.h" 5#include "matroxfb_base.h"
8 6
9struct matroxfb_dh_fb_info { 7struct matroxfb_dh_fb_info {
diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c
index 8ea17a53eed8..cab56005dd49 100644
--- a/drivers/w1/slaves/w1_ds2433.c
+++ b/drivers/w1/slaves/w1_ds2433.c
@@ -91,8 +91,9 @@ static int w1_f23_refresh_block(struct w1_slave *sl, struct w1_f23_data *data,
91} 91}
92#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ 92#endif /* CONFIG_W1_SLAVE_DS2433_CRC */
93 93
94static ssize_t w1_f23_read_bin(struct kobject *kobj, char *buf, loff_t off, 94static ssize_t w1_f23_read_bin(struct kobject *kobj,
95 size_t count) 95 struct bin_attribute *bin_attr,
96 char *buf, loff_t off, size_t count)
96{ 97{
97 struct w1_slave *sl = kobj_to_w1_slave(kobj); 98 struct w1_slave *sl = kobj_to_w1_slave(kobj);
98#ifdef CONFIG_W1_SLAVE_DS2433_CRC 99#ifdef CONFIG_W1_SLAVE_DS2433_CRC
@@ -199,8 +200,9 @@ static int w1_f23_write(struct w1_slave *sl, int addr, int len, const u8 *data)
199 return 0; 200 return 0;
200} 201}
201 202
202static ssize_t w1_f23_write_bin(struct kobject *kobj, char *buf, loff_t off, 203static ssize_t w1_f23_write_bin(struct kobject *kobj,
203 size_t count) 204 struct bin_attribute *bin_attr,
205 char *buf, loff_t off, size_t count)
204{ 206{
205 struct w1_slave *sl = kobj_to_w1_slave(kobj); 207 struct w1_slave *sl = kobj_to_w1_slave(kobj);
206 int addr, len, idx; 208 int addr, len, idx;
@@ -252,7 +254,6 @@ static struct bin_attribute w1_f23_bin_attr = {
252 .attr = { 254 .attr = {
253 .name = "eeprom", 255 .name = "eeprom",
254 .mode = S_IRUGO | S_IWUSR, 256 .mode = S_IRUGO | S_IWUSR,
255 .owner = THIS_MODULE,
256 }, 257 },
257 .size = W1_EEPROM_SIZE, 258 .size = W1_EEPROM_SIZE,
258 .read = w1_f23_read_bin, 259 .read = w1_f23_read_bin,
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 1a6937dc190b..4318935678c5 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -42,13 +42,13 @@ static u8 bad_roms[][9] = {
42 {} 42 {}
43 }; 43 };
44 44
45static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t); 45static ssize_t w1_therm_read_bin(struct kobject *, struct bin_attribute *,
46 char *, loff_t, size_t);
46 47
47static struct bin_attribute w1_therm_bin_attr = { 48static struct bin_attribute w1_therm_bin_attr = {
48 .attr = { 49 .attr = {
49 .name = "w1_slave", 50 .name = "w1_slave",
50 .mode = S_IRUGO, 51 .mode = S_IRUGO,
51 .owner = THIS_MODULE,
52 }, 52 },
53 .size = W1_SLAVE_DATA_SIZE, 53 .size = W1_SLAVE_DATA_SIZE,
54 .read = w1_therm_read_bin, 54 .read = w1_therm_read_bin,
@@ -159,7 +159,9 @@ static int w1_therm_check_rom(u8 rom[9])
159 return 0; 159 return 0;
160} 160}
161 161
162static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) 162static ssize_t w1_therm_read_bin(struct kobject *kobj,
163 struct bin_attribute *bin_attr,
164 char *buf, loff_t off, size_t count)
163{ 165{
164 struct w1_slave *sl = kobj_to_w1_slave(kobj); 166 struct w1_slave *sl = kobj_to_w1_slave(kobj);
165 struct w1_master *dev = sl->master; 167 struct w1_master *dev = sl->master;
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 7d6876dbcc96..f5c5b760ed7b 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -105,7 +105,9 @@ static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *a
105 return sprintf(buf, "%s\n", sl->name); 105 return sprintf(buf, "%s\n", sl->name);
106} 106}
107 107
108static ssize_t w1_slave_read_id(struct kobject *kobj, char *buf, loff_t off, size_t count) 108static ssize_t w1_slave_read_id(struct kobject *kobj,
109 struct bin_attribute *bin_attr,
110 char *buf, loff_t off, size_t count)
109{ 111{
110 struct w1_slave *sl = kobj_to_w1_slave(kobj); 112 struct w1_slave *sl = kobj_to_w1_slave(kobj);
111 113
@@ -128,7 +130,6 @@ static struct bin_attribute w1_slave_attr_bin_id = {
128 .attr = { 130 .attr = {
129 .name = "id", 131 .name = "id",
130 .mode = S_IRUGO, 132 .mode = S_IRUGO,
131 .owner = THIS_MODULE,
132 }, 133 },
133 .size = 8, 134 .size = 8,
134 .read = w1_slave_read_id, 135 .read = w1_slave_read_id,
@@ -136,7 +137,9 @@ static struct bin_attribute w1_slave_attr_bin_id = {
136 137
137/* Default family */ 138/* Default family */
138 139
139static ssize_t w1_default_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 140static ssize_t w1_default_write(struct kobject *kobj,
141 struct bin_attribute *bin_attr,
142 char *buf, loff_t off, size_t count)
140{ 143{
141 struct w1_slave *sl = kobj_to_w1_slave(kobj); 144 struct w1_slave *sl = kobj_to_w1_slave(kobj);
142 145
@@ -153,7 +156,9 @@ out_up:
153 return count; 156 return count;
154} 157}
155 158
156static ssize_t w1_default_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 159static ssize_t w1_default_read(struct kobject *kobj,
160 struct bin_attribute *bin_attr,
161 char *buf, loff_t off, size_t count)
157{ 162{
158 struct w1_slave *sl = kobj_to_w1_slave(kobj); 163 struct w1_slave *sl = kobj_to_w1_slave(kobj);
159 164
@@ -167,7 +172,6 @@ static struct bin_attribute w1_default_attr = {
167 .attr = { 172 .attr = {
168 .name = "rw", 173 .name = "rw",
169 .mode = S_IRUGO | S_IWUSR, 174 .mode = S_IRUGO | S_IWUSR,
170 .owner = THIS_MODULE,
171 }, 175 },
172 .size = PAGE_SIZE, 176 .size = PAGE_SIZE,
173 .read = w1_default_read, 177 .read = w1_default_read,
diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c
index c3ba0ec334c4..9130f1c12c26 100644
--- a/drivers/zorro/zorro-sysfs.c
+++ b/drivers/zorro/zorro-sysfs.c
@@ -49,8 +49,9 @@ static ssize_t zorro_show_resource(struct device *dev, struct device_attribute *
49 49
50static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL); 50static DEVICE_ATTR(resource, S_IRUGO, zorro_show_resource, NULL);
51 51
52static ssize_t zorro_read_config(struct kobject *kobj, char *buf, loff_t off, 52static ssize_t zorro_read_config(struct kobject *kobj,
53 size_t count) 53 struct bin_attribute *bin_attr,
54 char *buf, loff_t off, size_t count)
54{ 55{
55 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device, 56 struct zorro_dev *z = to_zorro_dev(container_of(kobj, struct device,
56 kobj)); 57 kobj));
@@ -78,7 +79,6 @@ static struct bin_attribute zorro_config_attr = {
78 .attr = { 79 .attr = {
79 .name = "config", 80 .name = "config",
80 .mode = S_IRUGO | S_IWUSR, 81 .mode = S_IRUGO | S_IWUSR,
81 .owner = THIS_MODULE
82 }, 82 },
83 .size = sizeof(struct ConfigDev), 83 .size = sizeof(struct ConfigDev),
84 .read = zorro_read_config, 84 .read = zorro_read_config,