aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ata/libata-core.c38
-rw-r--r--drivers/ata/libata-eh.c148
-rw-r--r--drivers/ata/libata-scsi.c10
-rw-r--r--drivers/ata/sata_fsl.c159
-rw-r--r--drivers/ata/sata_promise.c2
-rw-r--r--drivers/base/dmapool.c1
-rw-r--r--drivers/char/drm/radeon_cp.c5
-rw-r--r--drivers/char/drm/radeon_drv.h1
-rw-r--r--drivers/char/drm/sis_mm.c1
-rw-r--r--drivers/ieee1394/dma.c3
-rw-r--r--drivers/ieee1394/sbp2.c2
-rw-r--r--drivers/md/dm-table.c7
-rw-r--r--drivers/media/video/bt8xx/bttvp.h2
-rw-r--r--drivers/mmc/core/core.c1
-rw-r--r--drivers/mmc/core/mmc_ops.c1
-rw-r--r--drivers/mmc/core/sd_ops.c1
-rw-r--r--drivers/mmc/core/sdio_ops.c1
-rw-r--r--drivers/net/meth.c1
-rw-r--r--drivers/rtc/rtc-cmos.c3
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c19
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c5
-rw-r--r--drivers/scsi/osst.c6
-rw-r--r--drivers/scsi/scsi_lib.c138
-rw-r--r--drivers/scsi/scsi_scan.c3
-rw-r--r--drivers/scsi/scsi_sysfs.c47
-rw-r--r--drivers/sh/maple/maple.c3
-rw-r--r--drivers/usb/core/buffer.c1
-rw-r--r--drivers/usb/core/hcd.c1
-rw-r--r--drivers/usb/core/usb.c2
29 files changed, 375 insertions, 237 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 63035d71a6..164c7d9514 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -704,8 +704,8 @@ static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy)
704 704
705/** 705/**
706 * ata_dev_enable_pm - enable SATA interface power management 706 * ata_dev_enable_pm - enable SATA interface power management
707 * @device - device to enable ipm for 707 * @dev: device to enable power management
708 * @policy - the link power management policy 708 * @policy: the link power management policy
709 * 709 *
710 * Enable SATA Interface power management. This will enable 710 * Enable SATA Interface power management. This will enable
711 * Device Interface Power Management (DIPM) for min_power 711 * Device Interface Power Management (DIPM) for min_power
@@ -735,9 +735,10 @@ enable_pm_out:
735 return /* rc */; /* hopefully we can use 'rc' eventually */ 735 return /* rc */; /* hopefully we can use 'rc' eventually */
736} 736}
737 737
738#ifdef CONFIG_PM
738/** 739/**
739 * ata_dev_disable_pm - disable SATA interface power management 740 * ata_dev_disable_pm - disable SATA interface power management
740 * @device - device to enable ipm for 741 * @dev: device to disable power management
741 * 742 *
742 * Disable SATA Interface power management. This will disable 743 * Disable SATA Interface power management. This will disable
743 * Device Interface Power Management (DIPM) without changing 744 * Device Interface Power Management (DIPM) without changing
@@ -755,6 +756,7 @@ static void ata_dev_disable_pm(struct ata_device *dev)
755 if (ap->ops->disable_pm) 756 if (ap->ops->disable_pm)
756 ap->ops->disable_pm(ap); 757 ap->ops->disable_pm(ap);
757} 758}
759#endif /* CONFIG_PM */
758 760
759void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy) 761void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy)
760{ 762{
@@ -764,6 +766,7 @@ void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy)
764 ata_port_schedule_eh(ap); 766 ata_port_schedule_eh(ap);
765} 767}
766 768
769#ifdef CONFIG_PM
767static void ata_lpm_enable(struct ata_host *host) 770static void ata_lpm_enable(struct ata_host *host)
768{ 771{
769 struct ata_link *link; 772 struct ata_link *link;
@@ -789,6 +792,7 @@ static void ata_lpm_disable(struct ata_host *host)
789 ata_lpm_schedule(ap, ap->pm_policy); 792 ata_lpm_schedule(ap, ap->pm_policy);
790 } 793 }
791} 794}
795#endif /* CONFIG_PM */
792 796
793 797
794/** 798/**
@@ -2300,6 +2304,10 @@ int ata_dev_configure(struct ata_device *dev)
2300 dev->max_sectors = ATA_MAX_SECTORS; 2304 dev->max_sectors = ATA_MAX_SECTORS;
2301 } 2305 }
2302 2306
2307 if ((dev->class == ATA_DEV_ATAPI) &&
2308 (atapi_command_packet_set(id) == TYPE_TAPE))
2309 dev->max_sectors = ATA_MAX_SECTORS_TAPE;
2310
2303 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) 2311 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128)
2304 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, 2312 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
2305 dev->max_sectors); 2313 dev->max_sectors);
@@ -2743,17 +2751,27 @@ int sata_down_spd_limit(struct ata_link *link)
2743 2751
2744static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol) 2752static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
2745{ 2753{
2746 u32 spd, limit; 2754 struct ata_link *host_link = &link->ap->link;
2755 u32 limit, target, spd;
2756
2757 limit = link->sata_spd_limit;
2747 2758
2748 if (link->sata_spd_limit == UINT_MAX) 2759 /* Don't configure downstream link faster than upstream link.
2749 limit = 0; 2760 * It doesn't speed up anything and some PMPs choke on such
2761 * configuration.
2762 */
2763 if (!ata_is_host_link(link) && host_link->sata_spd)
2764 limit &= (1 << host_link->sata_spd) - 1;
2765
2766 if (limit == UINT_MAX)
2767 target = 0;
2750 else 2768 else
2751 limit = fls(link->sata_spd_limit); 2769 target = fls(limit);
2752 2770
2753 spd = (*scontrol >> 4) & 0xf; 2771 spd = (*scontrol >> 4) & 0xf;
2754 *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4); 2772 *scontrol = (*scontrol & ~0xf0) | ((target & 0xf) << 4);
2755 2773
2756 return spd != limit; 2774 return spd != target;
2757} 2775}
2758 2776
2759/** 2777/**
@@ -2776,7 +2794,7 @@ int sata_set_spd_needed(struct ata_link *link)
2776 u32 scontrol; 2794 u32 scontrol;
2777 2795
2778 if (sata_scr_read(link, SCR_CONTROL, &scontrol)) 2796 if (sata_scr_read(link, SCR_CONTROL, &scontrol))
2779 return 0; 2797 return 1;
2780 2798
2781 return __sata_set_spd_needed(link, &scontrol); 2799 return __sata_set_spd_needed(link, &scontrol);
2782} 2800}
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 8d64f8fd8f..ed8813b222 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1747,6 +1747,7 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1747{ 1747{
1748 struct ata_port *ap = link->ap; 1748 struct ata_port *ap = link->ap;
1749 struct ata_eh_context *ehc = &link->eh_context; 1749 struct ata_eh_context *ehc = &link->eh_context;
1750 struct ata_device *dev;
1750 unsigned int all_err_mask = 0; 1751 unsigned int all_err_mask = 0;
1751 int tag, is_io = 0; 1752 int tag, is_io = 0;
1752 u32 serror; 1753 u32 serror;
@@ -1818,18 +1819,24 @@ static void ata_eh_link_autopsy(struct ata_link *link)
1818 (!is_io && (all_err_mask & ~AC_ERR_DEV))) 1819 (!is_io && (all_err_mask & ~AC_ERR_DEV)))
1819 ehc->i.action |= ATA_EH_REVALIDATE; 1820 ehc->i.action |= ATA_EH_REVALIDATE;
1820 1821
1821 /* if we have offending qcs and the associated failed device */ 1822 /* If we have offending qcs and the associated failed device,
1823 * perform per-dev EH action only on the offending device.
1824 */
1822 if (ehc->i.dev) { 1825 if (ehc->i.dev) {
1823 /* speed down */
1824 ehc->i.action |= ata_eh_speed_down(ehc->i.dev, is_io,
1825 all_err_mask);
1826
1827 /* perform per-dev EH action only on the offending device */
1828 ehc->i.dev_action[ehc->i.dev->devno] |= 1826 ehc->i.dev_action[ehc->i.dev->devno] |=
1829 ehc->i.action & ATA_EH_PERDEV_MASK; 1827 ehc->i.action & ATA_EH_PERDEV_MASK;
1830 ehc->i.action &= ~ATA_EH_PERDEV_MASK; 1828 ehc->i.action &= ~ATA_EH_PERDEV_MASK;
1831 } 1829 }
1832 1830
1831 /* consider speeding down */
1832 dev = ehc->i.dev;
1833 if (!dev && ata_link_max_devices(link) == 1 &&
1834 ata_dev_enabled(link->device))
1835 dev = link->device;
1836
1837 if (dev)
1838 ehc->i.action |= ata_eh_speed_down(dev, is_io, all_err_mask);
1839
1833 DPRINTK("EXIT\n"); 1840 DPRINTK("EXIT\n");
1834} 1841}
1835 1842
@@ -2065,16 +2072,19 @@ int ata_eh_reset(struct ata_link *link, int classify,
2065 ata_prereset_fn_t prereset, ata_reset_fn_t softreset, 2072 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
2066 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) 2073 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
2067{ 2074{
2075 const int max_tries = ARRAY_SIZE(ata_eh_reset_timeouts);
2068 struct ata_port *ap = link->ap; 2076 struct ata_port *ap = link->ap;
2069 struct ata_eh_context *ehc = &link->eh_context; 2077 struct ata_eh_context *ehc = &link->eh_context;
2070 unsigned int *classes = ehc->classes; 2078 unsigned int *classes = ehc->classes;
2079 unsigned int lflags = link->flags;
2071 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); 2080 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
2072 int try = 0; 2081 int try = 0;
2073 struct ata_device *dev; 2082 struct ata_device *dev;
2074 unsigned long deadline; 2083 unsigned long deadline, now;
2075 unsigned int tmp_action; 2084 unsigned int tmp_action;
2076 ata_reset_fn_t reset; 2085 ata_reset_fn_t reset;
2077 unsigned long flags; 2086 unsigned long flags;
2087 u32 sstatus;
2078 int rc; 2088 int rc;
2079 2089
2080 /* about to reset */ 2090 /* about to reset */
@@ -2106,7 +2116,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2106 /* Determine which reset to use and record in ehc->i.action. 2116 /* Determine which reset to use and record in ehc->i.action.
2107 * prereset() may examine and modify it. 2117 * prereset() may examine and modify it.
2108 */ 2118 */
2109 if (softreset && (!hardreset || (!(link->flags & ATA_LFLAG_NO_SRST) && 2119 if (softreset && (!hardreset || (!(lflags & ATA_LFLAG_NO_SRST) &&
2110 !sata_set_spd_needed(link) && 2120 !sata_set_spd_needed(link) &&
2111 !(ehc->i.action & ATA_EH_HARDRESET)))) 2121 !(ehc->i.action & ATA_EH_HARDRESET))))
2112 tmp_action = ATA_EH_SOFTRESET; 2122 tmp_action = ATA_EH_SOFTRESET;
@@ -2181,82 +2191,64 @@ int ata_eh_reset(struct ata_link *link, int classify,
2181 "follow-up softreset required " 2191 "follow-up softreset required "
2182 "but no softreset avaliable\n"); 2192 "but no softreset avaliable\n");
2183 rc = -EINVAL; 2193 rc = -EINVAL;
2184 goto out; 2194 goto fail;
2185 } 2195 }
2186 2196
2187 ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK); 2197 ata_eh_about_to_do(link, NULL, ATA_EH_RESET_MASK);
2188 rc = ata_do_reset(link, reset, classes, deadline); 2198 rc = ata_do_reset(link, reset, classes, deadline);
2189
2190 if (rc == 0 && classify && classes[0] == ATA_DEV_UNKNOWN &&
2191 !(link->flags & ATA_LFLAG_ASSUME_CLASS)) {
2192 ata_link_printk(link, KERN_ERR,
2193 "classification failed\n");
2194 rc = -EINVAL;
2195 goto out;
2196 }
2197 } 2199 }
2198 2200
2199 /* if we skipped follow-up srst, clear rc */ 2201 /* -EAGAIN can happen if we skipped followup SRST */
2200 if (rc == -EAGAIN) 2202 if (rc && rc != -EAGAIN)
2201 rc = 0; 2203 goto fail;
2202
2203 if (rc && rc != -ERESTART && try < ARRAY_SIZE(ata_eh_reset_timeouts)) {
2204 unsigned long now = jiffies;
2205
2206 if (time_before(now, deadline)) {
2207 unsigned long delta = deadline - jiffies;
2208
2209 ata_link_printk(link, KERN_WARNING, "reset failed "
2210 "(errno=%d), retrying in %u secs\n",
2211 rc, (jiffies_to_msecs(delta) + 999) / 1000);
2212 2204
2213 while (delta) 2205 /* was classification successful? */
2214 delta = schedule_timeout_uninterruptible(delta); 2206 if (classify && classes[0] == ATA_DEV_UNKNOWN &&
2207 !(lflags & ATA_LFLAG_ASSUME_CLASS)) {
2208 if (try < max_tries) {
2209 ata_link_printk(link, KERN_WARNING,
2210 "classification failed\n");
2211 rc = -EINVAL;
2212 goto fail;
2215 } 2213 }
2216 2214
2217 if (rc == -EPIPE || 2215 ata_link_printk(link, KERN_WARNING,
2218 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) 2216 "classfication failed, assuming ATA\n");
2219 sata_down_spd_limit(link); 2217 lflags |= ATA_LFLAG_ASSUME_ATA;
2220 if (hardreset)
2221 reset = hardreset;
2222 goto retry;
2223 } 2218 }
2224 2219
2225 if (rc == 0) { 2220 ata_link_for_each_dev(dev, link) {
2226 u32 sstatus; 2221 /* After the reset, the device state is PIO 0 and the
2222 * controller state is undefined. Reset also wakes up
2223 * drives from sleeping mode.
2224 */
2225 dev->pio_mode = XFER_PIO_0;
2226 dev->flags &= ~ATA_DFLAG_SLEEPING;
2227 2227
2228 ata_link_for_each_dev(dev, link) { 2228 if (ata_link_offline(link))
2229 /* After the reset, the device state is PIO 0 2229 continue;
2230 * and the controller state is undefined.
2231 * Reset also wakes up drives from sleeping
2232 * mode.
2233 */
2234 dev->pio_mode = XFER_PIO_0;
2235 dev->flags &= ~ATA_DFLAG_SLEEPING;
2236 2230
2237 if (ata_link_offline(link)) 2231 /* apply class override and convert UNKNOWN to NONE */
2238 continue; 2232 if (lflags & ATA_LFLAG_ASSUME_ATA)
2233 classes[dev->devno] = ATA_DEV_ATA;
2234 else if (lflags & ATA_LFLAG_ASSUME_SEMB)
2235 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */
2236 else if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2237 classes[dev->devno] = ATA_DEV_NONE;
2238 }
2239 2239
2240 /* apply class override and convert UNKNOWN to NONE */ 2240 /* record current link speed */
2241 if (link->flags & ATA_LFLAG_ASSUME_ATA) 2241 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
2242 classes[dev->devno] = ATA_DEV_ATA; 2242 link->sata_spd = (sstatus >> 4) & 0xf;
2243 else if (link->flags & ATA_LFLAG_ASSUME_SEMB)
2244 classes[dev->devno] = ATA_DEV_SEMB_UNSUP; /* not yet */
2245 else if (classes[dev->devno] == ATA_DEV_UNKNOWN)
2246 classes[dev->devno] = ATA_DEV_NONE;
2247 }
2248 2243
2249 /* record current link speed */ 2244 if (postreset)
2250 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0) 2245 postreset(link, classes);
2251 link->sata_spd = (sstatus >> 4) & 0xf;
2252 2246
2253 if (postreset) 2247 /* reset successful, schedule revalidation */
2254 postreset(link, classes); 2248 ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
2249 ehc->i.action |= ATA_EH_REVALIDATE;
2255 2250
2256 /* reset successful, schedule revalidation */ 2251 rc = 0;
2257 ata_eh_done(link, NULL, ehc->i.action & ATA_EH_RESET_MASK);
2258 ehc->i.action |= ATA_EH_REVALIDATE;
2259 }
2260 out: 2252 out:
2261 /* clear hotplug flag */ 2253 /* clear hotplug flag */
2262 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; 2254 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
@@ -2266,6 +2258,28 @@ int ata_eh_reset(struct ata_link *link, int classify,
2266 spin_unlock_irqrestore(ap->lock, flags); 2258 spin_unlock_irqrestore(ap->lock, flags);
2267 2259
2268 return rc; 2260 return rc;
2261
2262 fail:
2263 if (rc == -ERESTART || try >= max_tries)
2264 goto out;
2265
2266 now = jiffies;
2267 if (time_before(now, deadline)) {
2268 unsigned long delta = deadline - now;
2269
2270 ata_link_printk(link, KERN_WARNING, "reset failed "
2271 "(errno=%d), retrying in %u secs\n",
2272 rc, (jiffies_to_msecs(delta) + 999) / 1000);
2273
2274 while (delta)
2275 delta = schedule_timeout_uninterruptible(delta);
2276 }
2277
2278 if (rc == -EPIPE || try == max_tries - 1)
2279 sata_down_spd_limit(link);
2280 if (hardreset)
2281 reset = hardreset;
2282 goto retry;
2269} 2283}
2270 2284
2271static int ata_eh_revalidate_and_attach(struct ata_link *link, 2285static int ata_eh_revalidate_and_attach(struct ata_link *link,
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index fc89590d37..94144ed50a 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -120,7 +120,7 @@ static const struct {
120 { MEDIUM_POWER, "medium_power" }, 120 { MEDIUM_POWER, "medium_power" },
121}; 121};
122 122
123const char *ata_scsi_lpm_get(enum link_pm policy) 123static const char *ata_scsi_lpm_get(enum link_pm policy)
124{ 124{
125 int i; 125 int i;
126 126
@@ -841,6 +841,9 @@ static void ata_scsi_dev_config(struct scsi_device *sdev,
841 blk_queue_max_hw_segments(q, q->max_hw_segments - 1); 841 blk_queue_max_hw_segments(q, q->max_hw_segments - 1);
842 } 842 }
843 843
844 if (dev->flags & ATA_DFLAG_AN)
845 set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events);
846
844 if (dev->flags & ATA_DFLAG_NCQ) { 847 if (dev->flags & ATA_DFLAG_NCQ) {
845 int depth; 848 int depth;
846 849
@@ -3296,10 +3299,9 @@ static void ata_scsi_handle_link_detach(struct ata_link *link)
3296 */ 3299 */
3297void ata_scsi_media_change_notify(struct ata_device *dev) 3300void ata_scsi_media_change_notify(struct ata_device *dev)
3298{ 3301{
3299#ifdef OTHER_AN_PATCHES_HAVE_BEEN_APPLIED
3300 if (dev->sdev) 3302 if (dev->sdev)
3301 scsi_device_event_notify(dev->sdev, SDEV_MEDIA_CHANGE); 3303 sdev_evt_send_simple(dev->sdev, SDEV_EVT_MEDIA_CHANGE,
3302#endif 3304 GFP_ATOMIC);
3303} 3305}
3304 3306
3305/** 3307/**
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index b4c37b9e41..d015b4adcf 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -34,7 +34,8 @@ enum {
34 34
35 SATA_FSL_HOST_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 35 SATA_FSL_HOST_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
36 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 36 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
37 ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY), 37 ATA_FLAG_NCQ),
38 SATA_FSL_HOST_LFLAGS = ATA_LFLAG_SKIP_D2H_BSY,
38 39
39 SATA_FSL_MAX_CMDS = SATA_FSL_QUEUE_DEPTH, 40 SATA_FSL_MAX_CMDS = SATA_FSL_QUEUE_DEPTH,
40 SATA_FSL_CMD_HDR_SIZE = 16, /* 4 DWORDS */ 41 SATA_FSL_CMD_HDR_SIZE = 16, /* 4 DWORDS */
@@ -264,10 +265,11 @@ struct sata_fsl_host_priv {
264 void __iomem *hcr_base; 265 void __iomem *hcr_base;
265 void __iomem *ssr_base; 266 void __iomem *ssr_base;
266 void __iomem *csr_base; 267 void __iomem *csr_base;
268 int irq;
267}; 269};
268 270
269static inline unsigned int sata_fsl_tag(unsigned int tag, 271static inline unsigned int sata_fsl_tag(unsigned int tag,
270 void __iomem * hcr_base) 272 void __iomem *hcr_base)
271{ 273{
272 /* We let libATA core do actual (queue) tag allocation */ 274 /* We let libATA core do actual (queue) tag allocation */
273 275
@@ -306,7 +308,7 @@ static void sata_fsl_setup_cmd_hdr_entry(struct sata_fsl_port_priv *pp,
306 pp->cmdslot[tag].prde_fis_len = 308 pp->cmdslot[tag].prde_fis_len =
307 cpu_to_le32((num_prde << 16) | (fis_len << 2)); 309 cpu_to_le32((num_prde << 16) | (fis_len << 2));
308 pp->cmdslot[tag].ttl = cpu_to_le32(data_xfer_len & ~0x03); 310 pp->cmdslot[tag].ttl = cpu_to_le32(data_xfer_len & ~0x03);
309 pp->cmdslot[tag].desc_info = cpu_to_le32((desc_info | (tag & 0x1F))); 311 pp->cmdslot[tag].desc_info = cpu_to_le32(desc_info | (tag & 0x1F));
310 312
311 VPRINTK("cda=0x%x, prde_fis_len=0x%x, ttl=0x%x, di=0x%x\n", 313 VPRINTK("cda=0x%x, prde_fis_len=0x%x, ttl=0x%x, di=0x%x\n",
312 pp->cmdslot[tag].cda, 314 pp->cmdslot[tag].cda,
@@ -316,7 +318,7 @@ static void sata_fsl_setup_cmd_hdr_entry(struct sata_fsl_port_priv *pp,
316} 318}
317 319
318static unsigned int sata_fsl_fill_sg(struct ata_queued_cmd *qc, void *cmd_desc, 320static unsigned int sata_fsl_fill_sg(struct ata_queued_cmd *qc, void *cmd_desc,
319 u32 * ttl, dma_addr_t cmd_desc_paddr) 321 u32 *ttl, dma_addr_t cmd_desc_paddr)
320{ 322{
321 struct scatterlist *sg; 323 struct scatterlist *sg;
322 unsigned int num_prde = 0; 324 unsigned int num_prde = 0;
@@ -353,7 +355,7 @@ static unsigned int sata_fsl_fill_sg(struct ata_queued_cmd *qc, void *cmd_desc,
353 "s/g len unaligned : 0x%x\n", sg_len); 355 "s/g len unaligned : 0x%x\n", sg_len);
354 356
355 if ((num_prde == (SATA_FSL_MAX_PRD_DIRECT - 1)) && 357 if ((num_prde == (SATA_FSL_MAX_PRD_DIRECT - 1)) &&
356 !ata_sg_is_last(sg, qc)) { 358 (qc->n_iter + 1 != qc->n_elem)) {
357 VPRINTK("setting indirect prde\n"); 359 VPRINTK("setting indirect prde\n");
358 prd_ptr_to_indirect_ext = prd; 360 prd_ptr_to_indirect_ext = prd;
359 prd->dba = cpu_to_le32(indirect_ext_segment_paddr); 361 prd->dba = cpu_to_le32(indirect_ext_segment_paddr);
@@ -404,7 +406,7 @@ static void sata_fsl_qc_prep(struct ata_queued_cmd *qc)
404 cd = (struct command_desc *)pp->cmdentry + tag; 406 cd = (struct command_desc *)pp->cmdentry + tag;
405 cd_paddr = pp->cmdentry_paddr + tag * SATA_FSL_CMD_DESC_SIZE; 407 cd_paddr = pp->cmdentry_paddr + tag * SATA_FSL_CMD_DESC_SIZE;
406 408
407 ata_tf_to_fis(&qc->tf, 0, 1, (u8 *) & cd->cfis); 409 ata_tf_to_fis(&qc->tf, 0, 1, (u8 *) &cd->cfis);
408 410
409 VPRINTK("Dumping cfis : 0x%x, 0x%x, 0x%x\n", 411 VPRINTK("Dumping cfis : 0x%x, 0x%x, 0x%x\n",
410 cd->cfis[0], cd->cfis[1], cd->cfis[2]); 412 cd->cfis[0], cd->cfis[1], cd->cfis[2]);
@@ -470,16 +472,10 @@ static int sata_fsl_scr_write(struct ata_port *ap, unsigned int sc_reg_in,
470 472
471 switch (sc_reg_in) { 473 switch (sc_reg_in) {
472 case SCR_STATUS: 474 case SCR_STATUS:
473 sc_reg = 0;
474 break;
475 case SCR_ERROR: 475 case SCR_ERROR:
476 sc_reg = 1;
477 break;
478 case SCR_CONTROL: 476 case SCR_CONTROL:
479 sc_reg = 2;
480 break;
481 case SCR_ACTIVE: 477 case SCR_ACTIVE:
482 sc_reg = 3; 478 sc_reg = sc_reg_in;
483 break; 479 break;
484 default: 480 default:
485 return -EINVAL; 481 return -EINVAL;
@@ -487,7 +483,7 @@ static int sata_fsl_scr_write(struct ata_port *ap, unsigned int sc_reg_in,
487 483
488 VPRINTK("xx_scr_write, reg_in = %d\n", sc_reg); 484 VPRINTK("xx_scr_write, reg_in = %d\n", sc_reg);
489 485
490 iowrite32(val, (void __iomem *)ssr_base + (sc_reg * 4)); 486 iowrite32(val, ssr_base + (sc_reg * 4));
491 return 0; 487 return 0;
492} 488}
493 489
@@ -500,16 +496,10 @@ static int sata_fsl_scr_read(struct ata_port *ap, unsigned int sc_reg_in,
500 496
501 switch (sc_reg_in) { 497 switch (sc_reg_in) {
502 case SCR_STATUS: 498 case SCR_STATUS:
503 sc_reg = 0;
504 break;
505 case SCR_ERROR: 499 case SCR_ERROR:
506 sc_reg = 1;
507 break;
508 case SCR_CONTROL: 500 case SCR_CONTROL:
509 sc_reg = 2;
510 break;
511 case SCR_ACTIVE: 501 case SCR_ACTIVE:
512 sc_reg = 3; 502 sc_reg = sc_reg_in;
513 break; 503 break;
514 default: 504 default:
515 return -EINVAL; 505 return -EINVAL;
@@ -517,7 +507,7 @@ static int sata_fsl_scr_read(struct ata_port *ap, unsigned int sc_reg_in,
517 507
518 VPRINTK("xx_scr_read, reg_in = %d\n", sc_reg); 508 VPRINTK("xx_scr_read, reg_in = %d\n", sc_reg);
519 509
520 *val = ioread32((void __iomem *)ssr_base + (sc_reg * 4)); 510 *val = ioread32(ssr_base + (sc_reg * 4));
521 return 0; 511 return 0;
522} 512}
523 513
@@ -571,7 +561,6 @@ static inline void sata_fsl_cache_taskfile_from_d2h_fis(struct ata_queued_cmd
571 struct ata_port *ap) 561 struct ata_port *ap)
572{ 562{
573 struct sata_fsl_port_priv *pp = ap->private_data; 563 struct sata_fsl_port_priv *pp = ap->private_data;
574 u8 fis[6 * 4];
575 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 564 struct sata_fsl_host_priv *host_priv = ap->host->private_data;
576 void __iomem *hcr_base = host_priv->hcr_base; 565 void __iomem *hcr_base = host_priv->hcr_base;
577 unsigned int tag = sata_fsl_tag(qc->tag, hcr_base); 566 unsigned int tag = sata_fsl_tag(qc->tag, hcr_base);
@@ -579,8 +568,7 @@ static inline void sata_fsl_cache_taskfile_from_d2h_fis(struct ata_queued_cmd
579 568
580 cd = pp->cmdentry + tag; 569 cd = pp->cmdentry + tag;
581 570
582 memcpy(fis, &cd->sfis, 6 * 4); /* should we use memcpy_from_io() */ 571 ata_tf_from_fis(cd->sfis, &pp->tf);
583 ata_tf_from_fis(fis, &pp->tf);
584} 572}
585 573
586static u8 sata_fsl_check_status(struct ata_port *ap) 574static u8 sata_fsl_check_status(struct ata_port *ap)
@@ -664,6 +652,7 @@ static int sata_fsl_port_start(struct ata_port *ap)
664 VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL)); 652 VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));
665 VPRINTK("CHBA = 0x%x\n", ioread32(hcr_base + CHBA)); 653 VPRINTK("CHBA = 0x%x\n", ioread32(hcr_base + CHBA));
666 654
655#ifdef CONFIG_MPC8315_DS
667 /* 656 /*
668 * Workaround for 8315DS board 3gbps link-up issue, 657 * Workaround for 8315DS board 3gbps link-up issue,
669 * currently limit SATA port to GEN1 speed 658 * currently limit SATA port to GEN1 speed
@@ -676,6 +665,7 @@ static int sata_fsl_port_start(struct ata_port *ap)
676 sata_fsl_scr_read(ap, SCR_CONTROL, &temp); 665 sata_fsl_scr_read(ap, SCR_CONTROL, &temp);
677 dev_printk(KERN_WARNING, dev, "scr_control, speed limited to %x\n", 666 dev_printk(KERN_WARNING, dev, "scr_control, speed limited to %x\n",
678 temp); 667 temp);
668#endif
679 669
680 return 0; 670 return 0;
681} 671}
@@ -728,9 +718,10 @@ static unsigned int sata_fsl_dev_classify(struct ata_port *ap)
728 return ata_dev_classify(&tf); 718 return ata_dev_classify(&tf);
729} 719}
730 720
731static int sata_fsl_softreset(struct ata_port *ap, unsigned int *class, 721static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
732 unsigned long deadline) 722 unsigned long deadline)
733{ 723{
724 struct ata_port *ap = link->ap;
734 struct sata_fsl_port_priv *pp = ap->private_data; 725 struct sata_fsl_port_priv *pp = ap->private_data;
735 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 726 struct sata_fsl_host_priv *host_priv = ap->host->private_data;
736 void __iomem *hcr_base = host_priv->hcr_base; 727 void __iomem *hcr_base = host_priv->hcr_base;
@@ -739,10 +730,6 @@ static int sata_fsl_softreset(struct ata_port *ap, unsigned int *class,
739 u8 *cfis; 730 u8 *cfis;
740 u32 Serror; 731 u32 Serror;
741 int i = 0; 732 int i = 0;
742 struct ata_queued_cmd qc;
743 u8 *buf;
744 dma_addr_t dma_address;
745 struct scatterlist *sg;
746 unsigned long start_jiffies; 733 unsigned long start_jiffies;
747 734
748 DPRINTK("in xx_softreset\n"); 735 DPRINTK("in xx_softreset\n");
@@ -811,7 +798,7 @@ try_offline_again:
811 */ 798 */
812 799
813 temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500); 800 temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500);
814 if ((!(temp & 0x10)) || ata_port_offline(ap)) { 801 if ((!(temp & 0x10)) || ata_link_offline(link)) {
815 ata_port_printk(ap, KERN_WARNING, 802 ata_port_printk(ap, KERN_WARNING,
816 "No Device OR PHYRDY change,Hstatus = 0x%x\n", 803 "No Device OR PHYRDY change,Hstatus = 0x%x\n",
817 ioread32(hcr_base + HSTATUS)); 804 ioread32(hcr_base + HSTATUS));
@@ -842,13 +829,10 @@ try_offline_again:
842 * reached here, we can send a command to the target device 829 * reached here, we can send a command to the target device
843 */ 830 */
844 831
845 if (ap->sactive)
846 goto skip_srst_do_ncq_error_handling;
847
848 DPRINTK("Sending SRST/device reset\n"); 832 DPRINTK("Sending SRST/device reset\n");
849 833
850 ata_tf_init(ap->device, &tf); 834 ata_tf_init(link->device, &tf);
851 cfis = (u8 *) & pp->cmdentry->cfis; 835 cfis = (u8 *) &pp->cmdentry->cfis;
852 836
853 /* device reset/SRST is a control register update FIS, uses tag0 */ 837 /* device reset/SRST is a control register update FIS, uses tag0 */
854 sata_fsl_setup_cmd_hdr_entry(pp, 0, 838 sata_fsl_setup_cmd_hdr_entry(pp, 0,
@@ -912,76 +896,13 @@ try_offline_again:
912 * command bit of the CCreg 896 * command bit of the CCreg
913 */ 897 */
914 iowrite32(0x01, CC + hcr_base); /* We know it will be cmd#0 always */ 898 iowrite32(0x01, CC + hcr_base); /* We know it will be cmd#0 always */
915 goto check_device_signature;
916
917skip_srst_do_ncq_error_handling:
918
919 VPRINTK("Sending read log ext(10h) command\n");
920
921 memset(&qc, 0, sizeof(struct ata_queued_cmd));
922 ata_tf_init(ap->device, &tf);
923
924 tf.command = ATA_CMD_READ_LOG_EXT;
925 tf.lbal = ATA_LOG_SATA_NCQ;
926 tf.nsect = 1;
927 tf.hob_nsect = 0;
928 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE;
929 tf.protocol = ATA_PROT_PIO;
930
931 qc.tag = ATA_TAG_INTERNAL;
932 qc.scsicmd = NULL;
933 qc.ap = ap;
934 qc.dev = ap->device;
935
936 qc.tf = tf;
937 qc.flags |= ATA_QCFLAG_RESULT_TF;
938 qc.dma_dir = DMA_FROM_DEVICE;
939
940 buf = ap->sector_buf;
941 ata_sg_init_one(&qc, buf, 1 * ATA_SECT_SIZE);
942
943 /*
944 * Need to DMA-map the memory buffer associated with the command
945 */
946
947 sg = qc.__sg;
948 dma_address = dma_map_single(ap->dev, qc.buf_virt,
949 sg->length, DMA_FROM_DEVICE);
950
951 sg_dma_address(sg) = dma_address;
952 sg_dma_len(sg) = sg->length;
953
954 VPRINTK("EH, addr = 0x%x, len = 0x%x\n", dma_address, sg->length);
955
956 sata_fsl_qc_prep(&qc);
957 sata_fsl_qc_issue(&qc);
958
959 temp = ata_wait_register(CQ + hcr_base, 0x1, 0x1, 1, 5000);
960 if (temp & 0x1) {
961 VPRINTK("READ_LOG_EXT_10H issue failed\n");
962
963 VPRINTK("READ_LOG@5000,CQ=0x%x,CA=0x%x,CC=0x%x\n",
964 ioread32(CQ + hcr_base),
965 ioread32(CA + hcr_base), ioread32(CC + hcr_base));
966
967 sata_fsl_scr_read(ap, SCR_ERROR, &Serror);
968
969 VPRINTK("HStatus = 0x%x\n", ioread32(hcr_base + HSTATUS));
970 VPRINTK("HControl = 0x%x\n", ioread32(hcr_base + HCONTROL));
971 VPRINTK("Serror = 0x%x\n", Serror);
972 goto err;
973 }
974
975 iowrite32(0x01, CC + hcr_base); /* We know it will be cmd#0 always */
976
977 check_device_signature:
978 899
979 DPRINTK("SATA FSL : Now checking device signature\n"); 900 DPRINTK("SATA FSL : Now checking device signature\n");
980 901
981 *class = ATA_DEV_NONE; 902 *class = ATA_DEV_NONE;
982 903
983 /* Verify if SStatus indicates device presence */ 904 /* Verify if SStatus indicates device presence */
984 if (ata_port_online(ap)) { 905 if (ata_link_online(link)) {
985 /* 906 /*
986 * if we are here, device presence has been detected, 907 * if we are here, device presence has been detected,
987 * 1st D2H FIS would have been received, but sfis in 908 * 1st D2H FIS would have been received, but sfis in
@@ -1002,25 +923,13 @@ err:
1002 return -EIO; 923 return -EIO;
1003} 924}
1004 925
1005static int sata_fsl_hardreset(struct ata_port *ap, unsigned int *class,
1006 unsigned long deadline)
1007{
1008 int retval;
1009
1010 retval = sata_std_hardreset(ap, class, deadline);
1011
1012 DPRINTK("SATA FSL : in xx_hardreset, retval = 0x%d\n", retval);
1013
1014 return retval;
1015}
1016
1017static void sata_fsl_error_handler(struct ata_port *ap) 926static void sata_fsl_error_handler(struct ata_port *ap)
1018{ 927{
1019 928
1020 DPRINTK("in xx_error_handler\n"); 929 DPRINTK("in xx_error_handler\n");
1021 930
1022 /* perform recovery */ 931 /* perform recovery */
1023 ata_do_eh(ap, ata_std_prereset, sata_fsl_softreset, sata_fsl_hardreset, 932 ata_do_eh(ap, ata_std_prereset, sata_fsl_softreset, sata_std_hardreset,
1024 ata_std_postreset); 933 ata_std_postreset);
1025} 934}
1026 935
@@ -1042,7 +951,8 @@ static void sata_fsl_irq_clear(struct ata_port *ap)
1042 951
1043static void sata_fsl_error_intr(struct ata_port *ap) 952static void sata_fsl_error_intr(struct ata_port *ap)
1044{ 953{
1045 struct ata_eh_info *ehi = &ap->eh_info; 954 struct ata_link *link = &ap->link;
955 struct ata_eh_info *ehi = &link->eh_info;
1046 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 956 struct sata_fsl_host_priv *host_priv = ap->host->private_data;
1047 void __iomem *hcr_base = host_priv->hcr_base; 957 void __iomem *hcr_base = host_priv->hcr_base;
1048 u32 hstatus, dereg, cereg = 0, SError = 0; 958 u32 hstatus, dereg, cereg = 0, SError = 0;
@@ -1111,7 +1021,7 @@ static void sata_fsl_error_intr(struct ata_port *ap)
1111 } 1021 }
1112 1022
1113 /* record error info */ 1023 /* record error info */
1114 qc = ata_qc_from_tag(ap, ap->active_tag); 1024 qc = ata_qc_from_tag(ap, link->active_tag);
1115 1025
1116 if (qc) { 1026 if (qc) {
1117 sata_fsl_cache_taskfile_from_d2h_fis(qc, qc->ap); 1027 sata_fsl_cache_taskfile_from_d2h_fis(qc, qc->ap);
@@ -1139,6 +1049,7 @@ static void sata_fsl_qc_complete(struct ata_queued_cmd *qc)
1139 1049
1140static void sata_fsl_host_intr(struct ata_port *ap) 1050static void sata_fsl_host_intr(struct ata_port *ap)
1141{ 1051{
1052 struct ata_link *link = &ap->link;
1142 struct sata_fsl_host_priv *host_priv = ap->host->private_data; 1053 struct sata_fsl_host_priv *host_priv = ap->host->private_data;
1143 void __iomem *hcr_base = host_priv->hcr_base; 1054 void __iomem *hcr_base = host_priv->hcr_base;
1144 u32 hstatus, qc_active = 0; 1055 u32 hstatus, qc_active = 0;
@@ -1161,7 +1072,7 @@ static void sata_fsl_host_intr(struct ata_port *ap)
1161 return; 1072 return;
1162 } 1073 }
1163 1074
1164 if (ap->sactive) { /* only true for NCQ commands */ 1075 if (link->sactive) { /* only true for NCQ commands */
1165 int i; 1076 int i;
1166 /* Read command completed register */ 1077 /* Read command completed register */
1167 qc_active = ioread32(hcr_base + CC); 1078 qc_active = ioread32(hcr_base + CC);
@@ -1190,10 +1101,10 @@ static void sata_fsl_host_intr(struct ata_port *ap)
1190 1101
1191 } else if (ap->qc_active) { 1102 } else if (ap->qc_active) {
1192 iowrite32(1, hcr_base + CC); 1103 iowrite32(1, hcr_base + CC);
1193 qc = ata_qc_from_tag(ap, ap->active_tag); 1104 qc = ata_qc_from_tag(ap, link->active_tag);
1194 1105
1195 DPRINTK("completing non-ncq cmd, tag=%d,CC=0x%x\n", 1106 DPRINTK("completing non-ncq cmd, tag=%d,CC=0x%x\n",
1196 ap->active_tag, ioread32(hcr_base + CC)); 1107 link->active_tag, ioread32(hcr_base + CC));
1197 1108
1198 if (qc) { 1109 if (qc) {
1199 sata_fsl_qc_complete(qc); 1110 sata_fsl_qc_complete(qc);
@@ -1312,15 +1223,9 @@ static struct scsi_host_template sata_fsl_sht = {
1312 .slave_configure = ata_scsi_slave_config, 1223 .slave_configure = ata_scsi_slave_config,
1313 .slave_destroy = ata_scsi_slave_destroy, 1224 .slave_destroy = ata_scsi_slave_destroy,
1314 .bios_param = ata_std_bios_param, 1225 .bios_param = ata_std_bios_param,
1315#ifdef CONFIG_PM
1316 .suspend = ata_scsi_device_suspend,
1317 .resume = ata_scsi_device_resume,
1318#endif
1319}; 1226};
1320 1227
1321static const struct ata_port_operations sata_fsl_ops = { 1228static const struct ata_port_operations sata_fsl_ops = {
1322 .port_disable = ata_port_disable,
1323
1324 .check_status = sata_fsl_check_status, 1229 .check_status = sata_fsl_check_status,
1325 .check_altstatus = sata_fsl_check_status, 1230 .check_altstatus = sata_fsl_check_status,
1326 .dev_select = ata_noop_dev_select, 1231 .dev_select = ata_noop_dev_select,
@@ -1330,8 +1235,6 @@ static const struct ata_port_operations sata_fsl_ops = {
1330 .qc_prep = sata_fsl_qc_prep, 1235 .qc_prep = sata_fsl_qc_prep,
1331 .qc_issue = sata_fsl_qc_issue, 1236 .qc_issue = sata_fsl_qc_issue,
1332 .irq_clear = sata_fsl_irq_clear, 1237 .irq_clear = sata_fsl_irq_clear,
1333 .irq_on = ata_dummy_irq_on,
1334 .irq_ack = ata_dummy_irq_ack,
1335 1238
1336 .scr_read = sata_fsl_scr_read, 1239 .scr_read = sata_fsl_scr_read,
1337 .scr_write = sata_fsl_scr_write, 1240 .scr_write = sata_fsl_scr_write,
@@ -1348,6 +1251,7 @@ static const struct ata_port_operations sata_fsl_ops = {
1348static const struct ata_port_info sata_fsl_port_info[] = { 1251static const struct ata_port_info sata_fsl_port_info[] = {
1349 { 1252 {
1350 .flags = SATA_FSL_HOST_FLAGS, 1253 .flags = SATA_FSL_HOST_FLAGS,
1254 .link_flags = SATA_FSL_HOST_LFLAGS,
1351 .pio_mask = 0x1f, /* pio 0-4 */ 1255 .pio_mask = 0x1f, /* pio 0-4 */
1352 .udma_mask = 0x7f, /* udma 0-6 */ 1256 .udma_mask = 0x7f, /* udma 0-6 */
1353 .port_ops = &sata_fsl_ops, 1257 .port_ops = &sata_fsl_ops,
@@ -1398,6 +1302,7 @@ static int sata_fsl_probe(struct of_device *ofdev,
1398 dev_printk(KERN_ERR, &ofdev->dev, "invalid irq from platform\n"); 1302 dev_printk(KERN_ERR, &ofdev->dev, "invalid irq from platform\n");
1399 goto error_exit_with_cleanup; 1303 goto error_exit_with_cleanup;
1400 } 1304 }
1305 host_priv->irq = irq;
1401 1306
1402 /* allocate host structure */ 1307 /* allocate host structure */
1403 host = ata_host_alloc_pinfo(&ofdev->dev, ppi, SATA_FSL_MAX_PORTS); 1308 host = ata_host_alloc_pinfo(&ofdev->dev, ppi, SATA_FSL_MAX_PORTS);
@@ -1444,7 +1349,7 @@ static int sata_fsl_remove(struct of_device *ofdev)
1444 1349
1445 dev_set_drvdata(&ofdev->dev, NULL); 1350 dev_set_drvdata(&ofdev->dev, NULL);
1446 1351
1447 irq_dispose_mapping(host->irq); 1352 irq_dispose_mapping(host_priv->irq);
1448 iounmap(host_priv->hcr_base); 1353 iounmap(host_priv->hcr_base);
1449 kfree(host_priv); 1354 kfree(host_priv);
1450 1355
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 825e717bce..7914def54f 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -587,7 +587,7 @@ static void pdc_fill_sg(struct ata_queued_cmd *qc)
587 VPRINTK("Splitting last PRD.\n"); 587 VPRINTK("Splitting last PRD.\n");
588 588
589 addr = le32_to_cpu(ap->prd[idx - 1].addr); 589 addr = le32_to_cpu(ap->prd[idx - 1].addr);
590 ap->prd[idx - 1].flags_len -= cpu_to_le32(SG_COUNT_ASIC_BUG); 590 ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
591 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG); 591 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG);
592 592
593 addr = addr + len - SG_COUNT_ASIC_BUG; 593 addr = addr + len - SG_COUNT_ASIC_BUG;
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index 5beddc322e..b5034dc72a 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -2,7 +2,6 @@
2#include <linux/device.h> 2#include <linux/device.h>
3#include <linux/mm.h> 3#include <linux/mm.h>
4#include <asm/io.h> /* Needed for i386 to build */ 4#include <asm/io.h> /* Needed for i386 to build */
5#include <asm/scatterlist.h> /* Needed for i386 to build */
6#include <linux/dma-mapping.h> 5#include <linux/dma-mapping.h>
7#include <linux/dmapool.h> 6#include <linux/dmapool.h>
8#include <linux/slab.h> 7#include <linux/slab.h>
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 335423c5c1..24fca8ec13 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -1679,7 +1679,7 @@ static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
1679 dev_priv->gart_info.bus_addr = 1679 dev_priv->gart_info.bus_addr =
1680 dev_priv->pcigart_offset + dev_priv->fb_location; 1680 dev_priv->pcigart_offset + dev_priv->fb_location;
1681 dev_priv->gart_info.mapping.offset = 1681 dev_priv->gart_info.mapping.offset =
1682 dev_priv->gart_info.bus_addr; 1682 dev_priv->pcigart_offset + dev_priv->fb_aper_offset;
1683 dev_priv->gart_info.mapping.size = 1683 dev_priv->gart_info.mapping.size =
1684 dev_priv->gart_info.table_size; 1684 dev_priv->gart_info.table_size;
1685 1685
@@ -2275,7 +2275,8 @@ int radeon_driver_firstopen(struct drm_device *dev)
2275 if (ret != 0) 2275 if (ret != 0)
2276 return ret; 2276 return ret;
2277 2277
2278 ret = drm_addmap(dev, drm_get_resource_start(dev, 0), 2278 dev_priv->fb_aper_offset = drm_get_resource_start(dev, 0);
2279 ret = drm_addmap(dev, dev_priv->fb_aper_offset,
2279 drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER, 2280 drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
2280 _DRM_WRITE_COMBINING, &map); 2281 _DRM_WRITE_COMBINING, &map);
2281 if (ret != 0) 2282 if (ret != 0)
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index e4077bc212..bfbb60a929 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -293,6 +293,7 @@ typedef struct drm_radeon_private {
293 293
294 /* starting from here on, data is preserved accross an open */ 294 /* starting from here on, data is preserved accross an open */
295 uint32_t flags; /* see radeon_chip_flags */ 295 uint32_t flags; /* see radeon_chip_flags */
296 unsigned long fb_aper_offset;
296} drm_radeon_private_t; 297} drm_radeon_private_t;
297 298
298typedef struct drm_radeon_buf_priv { 299typedef struct drm_radeon_buf_priv {
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c
index 6be1c57575..a6b7ccdaf7 100644
--- a/drivers/char/drm/sis_mm.c
+++ b/drivers/char/drm/sis_mm.c
@@ -134,6 +134,7 @@ static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file_priv,
134 dev_priv->agp_initialized)) { 134 dev_priv->agp_initialized)) {
135 DRM_ERROR 135 DRM_ERROR
136 ("Attempt to allocate from uninitialized memory manager.\n"); 136 ("Attempt to allocate from uninitialized memory manager.\n");
137 mutex_unlock(&dev->struct_mutex);
137 return -EINVAL; 138 return -EINVAL;
138 } 139 }
139 140
diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c
index f5f4983dfb..7c4eb39b70 100644
--- a/drivers/ieee1394/dma.c
+++ b/drivers/ieee1394/dma.c
@@ -103,8 +103,7 @@ int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
103 goto err; 103 goto err;
104 } 104 }
105 105
106 /* just to be safe - this will become unnecessary once sglist->address goes away */ 106 sg_init_table(dma->sglist, dma->n_pages);
107 memset(dma->sglist, 0, dma->n_pages * sizeof(*dma->sglist));
108 107
109 /* fill scatter/gather list with pages */ 108 /* fill scatter/gather list with pages */
110 for (i = 0; i < dma->n_pages; i++) { 109 for (i = 0; i < dma->n_pages; i++) {
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index d5dfe11aa5..b83d254bc8 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -71,11 +71,11 @@
71#include <linux/types.h> 71#include <linux/types.h>
72#include <linux/wait.h> 72#include <linux/wait.h>
73#include <linux/workqueue.h> 73#include <linux/workqueue.h>
74#include <linux/scatterlist.h>
74 75
75#include <asm/byteorder.h> 76#include <asm/byteorder.h>
76#include <asm/errno.h> 77#include <asm/errno.h>
77#include <asm/param.h> 78#include <asm/param.h>
78#include <asm/scatterlist.h>
79#include <asm/system.h> 79#include <asm/system.h>
80#include <asm/types.h> 80#include <asm/types.h>
81 81
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 8939e61050..5a7eb65018 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -102,6 +102,8 @@ static void combine_restrictions_low(struct io_restrictions *lhs,
102 lhs->seg_boundary_mask = 102 lhs->seg_boundary_mask =
103 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask); 103 min_not_zero(lhs->seg_boundary_mask, rhs->seg_boundary_mask);
104 104
105 lhs->bounce_pfn = min_not_zero(lhs->bounce_pfn, rhs->bounce_pfn);
106
105 lhs->no_cluster |= rhs->no_cluster; 107 lhs->no_cluster |= rhs->no_cluster;
106} 108}
107 109
@@ -566,6 +568,8 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
566 min_not_zero(rs->seg_boundary_mask, 568 min_not_zero(rs->seg_boundary_mask,
567 q->seg_boundary_mask); 569 q->seg_boundary_mask);
568 570
571 rs->bounce_pfn = min_not_zero(rs->bounce_pfn, q->bounce_pfn);
572
569 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags); 573 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
570} 574}
571EXPORT_SYMBOL_GPL(dm_set_device_limits); 575EXPORT_SYMBOL_GPL(dm_set_device_limits);
@@ -707,6 +711,8 @@ static void check_for_valid_limits(struct io_restrictions *rs)
707 rs->max_segment_size = MAX_SEGMENT_SIZE; 711 rs->max_segment_size = MAX_SEGMENT_SIZE;
708 if (!rs->seg_boundary_mask) 712 if (!rs->seg_boundary_mask)
709 rs->seg_boundary_mask = -1; 713 rs->seg_boundary_mask = -1;
714 if (!rs->bounce_pfn)
715 rs->bounce_pfn = -1;
710} 716}
711 717
712int dm_table_add_target(struct dm_table *t, const char *type, 718int dm_table_add_target(struct dm_table *t, const char *type,
@@ -891,6 +897,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
891 q->hardsect_size = t->limits.hardsect_size; 897 q->hardsect_size = t->limits.hardsect_size;
892 q->max_segment_size = t->limits.max_segment_size; 898 q->max_segment_size = t->limits.max_segment_size;
893 q->seg_boundary_mask = t->limits.seg_boundary_mask; 899 q->seg_boundary_mask = t->limits.seg_boundary_mask;
900 q->bounce_pfn = t->limits.bounce_pfn;
894 if (t->limits.no_cluster) 901 if (t->limits.no_cluster)
895 q->queue_flags &= ~(1 << QUEUE_FLAG_CLUSTER); 902 q->queue_flags &= ~(1 << QUEUE_FLAG_CLUSTER);
896 else 903 else
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 0b92c35a84..d4ac4c4b49 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -36,7 +36,7 @@
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/input.h> 37#include <linux/input.h>
38#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include <asm/scatterlist.h> 39#include <linux/scatterlist.h>
40#include <asm/io.h> 40#include <asm/io.h>
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42 42
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 09435e0ec6..b96667448e 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -19,7 +19,6 @@
19#include <linux/pagemap.h> 19#include <linux/pagemap.h>
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/leds.h> 21#include <linux/leds.h>
22#include <asm/scatterlist.h>
23#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
24 23
25#include <linux/mmc/card.h> 24#include <linux/mmc/card.h>
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 7471d49909..64b05c6270 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <asm/scatterlist.h>
14#include <linux/scatterlist.h> 13#include <linux/scatterlist.h>
15 14
16#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index a6dafe62b9..0d96080d44 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <asm/scatterlist.h>
14#include <linux/scatterlist.h> 13#include <linux/scatterlist.h>
15 14
16#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
index 4d289b2750..e1fca588e3 100644
--- a/drivers/mmc/core/sdio_ops.c
+++ b/drivers/mmc/core/sdio_ops.c
@@ -9,7 +9,6 @@
9 * your option) any later version. 9 * your option) any later version.
10 */ 10 */
11 11
12#include <asm/scatterlist.h>
13#include <linux/scatterlist.h> 12#include <linux/scatterlist.h>
14 13
15#include <linux/mmc/host.h> 14#include <linux/mmc/host.h>
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index e25dbab673..0c89b028a8 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -33,7 +33,6 @@
33#include <asm/ip32/ip32_ints.h> 33#include <asm/ip32/ip32_ints.h>
34 34
35#include <asm/io.h> 35#include <asm/io.h>
36#include <asm/scatterlist.h>
37 36
38#include "meth.h" 37#include "meth.h"
39 38
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index e3fe83a23c..29cf1457ca 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -120,7 +120,8 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
120 t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM); 120 t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM);
121 121
122 if (cmos->day_alrm) { 122 if (cmos->day_alrm) {
123 t->time.tm_mday = CMOS_READ(cmos->day_alrm); 123 /* ignore upper bits on readback per ACPI spec */
124 t->time.tm_mday = CMOS_READ(cmos->day_alrm) & 0x3f;
124 if (!t->time.tm_mday) 125 if (!t->time.tm_mday)
125 t->time.tm_mday = -1; 126 t->time.tm_mday = -1;
126 127
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 22d91ee173..5f2396c039 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -556,7 +556,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
556 unsigned long timeout) 556 unsigned long timeout)
557{ 557{
558 u64 *crq_as_u64 = (u64 *) &evt_struct->crq; 558 u64 *crq_as_u64 = (u64 *) &evt_struct->crq;
559 int request_status; 559 int request_status = 0;
560 int rc; 560 int rc;
561 561
562 /* If we have exhausted our request limit, just fail this request, 562 /* If we have exhausted our request limit, just fail this request,
@@ -574,6 +574,13 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
574 if (request_status < -1) 574 if (request_status < -1)
575 goto send_error; 575 goto send_error;
576 /* Otherwise, we may have run out of requests. */ 576 /* Otherwise, we may have run out of requests. */
577 /* If request limit was 0 when we started the adapter is in the
578 * process of performing a login with the server adapter, or
579 * we may have run out of requests.
580 */
581 else if (request_status == -1 &&
582 evt_struct->iu.srp.login_req.opcode != SRP_LOGIN_REQ)
583 goto send_busy;
577 /* Abort and reset calls should make it through. 584 /* Abort and reset calls should make it through.
578 * Nothing except abort and reset should use the last two 585 * Nothing except abort and reset should use the last two
579 * slots unless we had two or less to begin with. 586 * slots unless we had two or less to begin with.
@@ -633,7 +640,8 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
633 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev); 640 unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
634 641
635 free_event_struct(&hostdata->pool, evt_struct); 642 free_event_struct(&hostdata->pool, evt_struct);
636 atomic_inc(&hostdata->request_limit); 643 if (request_status != -1)
644 atomic_inc(&hostdata->request_limit);
637 return SCSI_MLQUEUE_HOST_BUSY; 645 return SCSI_MLQUEUE_HOST_BUSY;
638 646
639 send_error: 647 send_error:
@@ -927,10 +935,11 @@ static int send_srp_login(struct ibmvscsi_host_data *hostdata)
927 login->req_buf_fmt = SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT; 935 login->req_buf_fmt = SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT;
928 936
929 spin_lock_irqsave(hostdata->host->host_lock, flags); 937 spin_lock_irqsave(hostdata->host->host_lock, flags);
930 /* Start out with a request limit of 1, since this is negotiated in 938 /* Start out with a request limit of 0, since this is negotiated in
931 * the login request we are just sending 939 * the login request we are just sending and login requests always
940 * get sent by the driver regardless of request_limit.
932 */ 941 */
933 atomic_set(&hostdata->request_limit, 1); 942 atomic_set(&hostdata->request_limit, 0);
934 943
935 rc = ibmvscsi_send_srp_event(evt_struct, hostdata, init_timeout * 2); 944 rc = ibmvscsi_send_srp_event(evt_struct, hostdata, init_timeout * 2);
936 spin_unlock_irqrestore(hostdata->host->host_lock, flags); 945 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index c0755565fa..4e46045dea 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -682,6 +682,7 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
682 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; 682 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
683 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); 683 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
684 int datadir = scsi_cmnd->sc_data_direction; 684 int datadir = scsi_cmnd->sc_data_direction;
685 char tag[2];
685 686
686 lpfc_cmd->fcp_rsp->rspSnsLen = 0; 687 lpfc_cmd->fcp_rsp->rspSnsLen = 0;
687 /* clear task management bits */ 688 /* clear task management bits */
@@ -692,8 +693,8 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
692 693
693 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16); 694 memcpy(&fcp_cmnd->fcpCdb[0], scsi_cmnd->cmnd, 16);
694 695
695 if (scsi_cmnd->device->tagged_supported) { 696 if (scsi_populate_tag_msg(scsi_cmnd, tag)) {
696 switch (scsi_cmnd->tag) { 697 switch (tag[0]) {
697 case HEAD_OF_QUEUE_TAG: 698 case HEAD_OF_QUEUE_TAG:
698 fcp_cmnd->fcpCntl1 = HEAD_OF_Q; 699 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
699 break; 700 break;
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 4652ad2251..abef7048f2 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -593,10 +593,11 @@ static int osst_verify_frame(struct osst_tape * STp, int frame_seq_number, int q
593 if (aux->frame_type != OS_FRAME_TYPE_DATA && 593 if (aux->frame_type != OS_FRAME_TYPE_DATA &&
594 aux->frame_type != OS_FRAME_TYPE_EOD && 594 aux->frame_type != OS_FRAME_TYPE_EOD &&
595 aux->frame_type != OS_FRAME_TYPE_MARKER) { 595 aux->frame_type != OS_FRAME_TYPE_MARKER) {
596 if (!quiet) 596 if (!quiet) {
597#if DEBUG 597#if DEBUG
598 printk(OSST_DEB_MSG "%s:D: Skipping frame, frame type %x\n", name, aux->frame_type); 598 printk(OSST_DEB_MSG "%s:D: Skipping frame, frame type %x\n", name, aux->frame_type);
599#endif 599#endif
600 }
600 goto err_out; 601 goto err_out;
601 } 602 }
602 if (aux->frame_type == OS_FRAME_TYPE_EOD && 603 if (aux->frame_type == OS_FRAME_TYPE_EOD &&
@@ -606,11 +607,12 @@ static int osst_verify_frame(struct osst_tape * STp, int frame_seq_number, int q
606 goto err_out; 607 goto err_out;
607 } 608 }
608 if (frame_seq_number != -1 && ntohl(aux->frame_seq_num) != frame_seq_number) { 609 if (frame_seq_number != -1 && ntohl(aux->frame_seq_num) != frame_seq_number) {
609 if (!quiet) 610 if (!quiet) {
610#if DEBUG 611#if DEBUG
611 printk(OSST_DEB_MSG "%s:D: Skipping frame, sequence number %u (expected %d)\n", 612 printk(OSST_DEB_MSG "%s:D: Skipping frame, sequence number %u (expected %d)\n",
612 name, ntohl(aux->frame_seq_num), frame_seq_number); 613 name, ntohl(aux->frame_seq_num), frame_seq_number);
613#endif 614#endif
615 }
614 goto err_out; 616 goto err_out;
615 } 617 }
616 if (aux->frame_type == OS_FRAME_TYPE_MARKER) { 618 if (aux->frame_type == OS_FRAME_TYPE_MARKER) {
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 61fdaf02f2..0e81e4cf88 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -785,7 +785,7 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
785 * end-of-list 785 * end-of-list
786 */ 786 */
787 if (!left) 787 if (!left)
788 sg_mark_end(sgl, this); 788 sg_mark_end(&sgl[this - 1]);
789 789
790 /* 790 /*
791 * don't allow subsequent mempool allocs to sleep, it would 791 * don't allow subsequent mempool allocs to sleep, it would
@@ -2115,6 +2115,142 @@ scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state)
2115EXPORT_SYMBOL(scsi_device_set_state); 2115EXPORT_SYMBOL(scsi_device_set_state);
2116 2116
2117/** 2117/**
2118 * sdev_evt_emit - emit a single SCSI device uevent
2119 * @sdev: associated SCSI device
2120 * @evt: event to emit
2121 *
2122 * Send a single uevent (scsi_event) to the associated scsi_device.
2123 */
2124static void scsi_evt_emit(struct scsi_device *sdev, struct scsi_event *evt)
2125{
2126 int idx = 0;
2127 char *envp[3];
2128
2129 switch (evt->evt_type) {
2130 case SDEV_EVT_MEDIA_CHANGE:
2131 envp[idx++] = "SDEV_MEDIA_CHANGE=1";
2132 break;
2133
2134 default:
2135 /* do nothing */
2136 break;
2137 }
2138
2139 envp[idx++] = NULL;
2140
2141 kobject_uevent_env(&sdev->sdev_gendev.kobj, KOBJ_CHANGE, envp);
2142}
2143
2144/**
2145 * sdev_evt_thread - send a uevent for each scsi event
2146 * @work: work struct for scsi_device
2147 *
2148 * Dispatch queued events to their associated scsi_device kobjects
2149 * as uevents.
2150 */
2151void scsi_evt_thread(struct work_struct *work)
2152{
2153 struct scsi_device *sdev;
2154 LIST_HEAD(event_list);
2155
2156 sdev = container_of(work, struct scsi_device, event_work);
2157
2158 while (1) {
2159 struct scsi_event *evt;
2160 struct list_head *this, *tmp;
2161 unsigned long flags;
2162
2163 spin_lock_irqsave(&sdev->list_lock, flags);
2164 list_splice_init(&sdev->event_list, &event_list);
2165 spin_unlock_irqrestore(&sdev->list_lock, flags);
2166
2167 if (list_empty(&event_list))
2168 break;
2169
2170 list_for_each_safe(this, tmp, &event_list) {
2171 evt = list_entry(this, struct scsi_event, node);
2172 list_del(&evt->node);
2173 scsi_evt_emit(sdev, evt);
2174 kfree(evt);
2175 }
2176 }
2177}
2178
2179/**
2180 * sdev_evt_send - send asserted event to uevent thread
2181 * @sdev: scsi_device event occurred on
2182 * @evt: event to send
2183 *
2184 * Assert scsi device event asynchronously.
2185 */
2186void sdev_evt_send(struct scsi_device *sdev, struct scsi_event *evt)
2187{
2188 unsigned long flags;
2189
2190 if (!test_bit(evt->evt_type, sdev->supported_events)) {
2191 kfree(evt);
2192 return;
2193 }
2194
2195 spin_lock_irqsave(&sdev->list_lock, flags);
2196 list_add_tail(&evt->node, &sdev->event_list);
2197 schedule_work(&sdev->event_work);
2198 spin_unlock_irqrestore(&sdev->list_lock, flags);
2199}
2200EXPORT_SYMBOL_GPL(sdev_evt_send);
2201
2202/**
2203 * sdev_evt_alloc - allocate a new scsi event
2204 * @evt_type: type of event to allocate
2205 * @gfpflags: GFP flags for allocation
2206 *
2207 * Allocates and returns a new scsi_event.
2208 */
2209struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type,
2210 gfp_t gfpflags)
2211{
2212 struct scsi_event *evt = kzalloc(sizeof(struct scsi_event), gfpflags);
2213 if (!evt)
2214 return NULL;
2215
2216 evt->evt_type = evt_type;
2217 INIT_LIST_HEAD(&evt->node);
2218
2219 /* evt_type-specific initialization, if any */
2220 switch (evt_type) {
2221 case SDEV_EVT_MEDIA_CHANGE:
2222 default:
2223 /* do nothing */
2224 break;
2225 }
2226
2227 return evt;
2228}
2229EXPORT_SYMBOL_GPL(sdev_evt_alloc);
2230
2231/**
2232 * sdev_evt_send_simple - send asserted event to uevent thread
2233 * @sdev: scsi_device event occurred on
2234 * @evt_type: type of event to send
2235 * @gfpflags: GFP flags for allocation
2236 *
2237 * Assert scsi device event asynchronously, given an event type.
2238 */
2239void sdev_evt_send_simple(struct scsi_device *sdev,
2240 enum scsi_device_event evt_type, gfp_t gfpflags)
2241{
2242 struct scsi_event *evt = sdev_evt_alloc(evt_type, gfpflags);
2243 if (!evt) {
2244 sdev_printk(KERN_ERR, sdev, "event %d eaten due to OOM\n",
2245 evt_type);
2246 return;
2247 }
2248
2249 sdev_evt_send(sdev, evt);
2250}
2251EXPORT_SYMBOL_GPL(sdev_evt_send_simple);
2252
2253/**
2118 * scsi_device_quiesce - Block user issued commands. 2254 * scsi_device_quiesce - Block user issued commands.
2119 * @sdev: scsi device to quiesce. 2255 * @sdev: scsi device to quiesce.
2120 * 2256 *
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index b53c5f67e3..40ea71cd2c 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -236,6 +236,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
236 struct scsi_device *sdev; 236 struct scsi_device *sdev;
237 int display_failure_msg = 1, ret; 237 int display_failure_msg = 1, ret;
238 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 238 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
239 extern void scsi_evt_thread(struct work_struct *work);
239 240
240 sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size, 241 sdev = kzalloc(sizeof(*sdev) + shost->transportt->device_size,
241 GFP_ATOMIC); 242 GFP_ATOMIC);
@@ -254,7 +255,9 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
254 INIT_LIST_HEAD(&sdev->same_target_siblings); 255 INIT_LIST_HEAD(&sdev->same_target_siblings);
255 INIT_LIST_HEAD(&sdev->cmd_list); 256 INIT_LIST_HEAD(&sdev->cmd_list);
256 INIT_LIST_HEAD(&sdev->starved_entry); 257 INIT_LIST_HEAD(&sdev->starved_entry);
258 INIT_LIST_HEAD(&sdev->event_list);
257 spin_lock_init(&sdev->list_lock); 259 spin_lock_init(&sdev->list_lock);
260 INIT_WORK(&sdev->event_work, scsi_evt_thread);
258 261
259 sdev->sdev_gendev.parent = get_device(&starget->dev); 262 sdev->sdev_gendev.parent = get_device(&starget->dev);
260 sdev->sdev_target = starget; 263 sdev->sdev_target = starget;
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index d531ceeb0d..f374fdcb68 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -268,6 +268,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
268 struct scsi_device *sdev; 268 struct scsi_device *sdev;
269 struct device *parent; 269 struct device *parent;
270 struct scsi_target *starget; 270 struct scsi_target *starget;
271 struct list_head *this, *tmp;
271 unsigned long flags; 272 unsigned long flags;
272 273
273 sdev = container_of(work, struct scsi_device, ew.work); 274 sdev = container_of(work, struct scsi_device, ew.work);
@@ -282,6 +283,16 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
282 list_del(&sdev->starved_entry); 283 list_del(&sdev->starved_entry);
283 spin_unlock_irqrestore(sdev->host->host_lock, flags); 284 spin_unlock_irqrestore(sdev->host->host_lock, flags);
284 285
286 cancel_work_sync(&sdev->event_work);
287
288 list_for_each_safe(this, tmp, &sdev->event_list) {
289 struct scsi_event *evt;
290
291 evt = list_entry(this, struct scsi_event, node);
292 list_del(&evt->node);
293 kfree(evt);
294 }
295
285 if (sdev->request_queue) { 296 if (sdev->request_queue) {
286 sdev->request_queue->queuedata = NULL; 297 sdev->request_queue->queuedata = NULL;
287 /* user context needed to free queue */ 298 /* user context needed to free queue */
@@ -614,6 +625,41 @@ sdev_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
614} 625}
615static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL); 626static DEVICE_ATTR(modalias, S_IRUGO, sdev_show_modalias, NULL);
616 627
628#define DECLARE_EVT_SHOW(name, Cap_name) \
629static ssize_t \
630sdev_show_evt_##name(struct device *dev, struct device_attribute *attr, \
631 char *buf) \
632{ \
633 struct scsi_device *sdev = to_scsi_device(dev); \
634 int val = test_bit(SDEV_EVT_##Cap_name, sdev->supported_events);\
635 return snprintf(buf, 20, "%d\n", val); \
636}
637
638#define DECLARE_EVT_STORE(name, Cap_name) \
639static ssize_t \
640sdev_store_evt_##name(struct device *dev, struct device_attribute *attr, \
641 const char *buf, size_t count) \
642{ \
643 struct scsi_device *sdev = to_scsi_device(dev); \
644 int val = simple_strtoul(buf, NULL, 0); \
645 if (val == 0) \
646 clear_bit(SDEV_EVT_##Cap_name, sdev->supported_events); \
647 else if (val == 1) \
648 set_bit(SDEV_EVT_##Cap_name, sdev->supported_events); \
649 else \
650 return -EINVAL; \
651 return count; \
652}
653
654#define DECLARE_EVT(name, Cap_name) \
655 DECLARE_EVT_SHOW(name, Cap_name) \
656 DECLARE_EVT_STORE(name, Cap_name) \
657 static DEVICE_ATTR(evt_##name, S_IRUGO, sdev_show_evt_##name, \
658 sdev_store_evt_##name);
659#define REF_EVT(name) &dev_attr_evt_##name.attr
660
661DECLARE_EVT(media_change, MEDIA_CHANGE)
662
617/* Default template for device attributes. May NOT be modified */ 663/* Default template for device attributes. May NOT be modified */
618static struct attribute *scsi_sdev_attrs[] = { 664static struct attribute *scsi_sdev_attrs[] = {
619 &dev_attr_device_blocked.attr, 665 &dev_attr_device_blocked.attr,
@@ -631,6 +677,7 @@ static struct attribute *scsi_sdev_attrs[] = {
631 &dev_attr_iodone_cnt.attr, 677 &dev_attr_iodone_cnt.attr,
632 &dev_attr_ioerr_cnt.attr, 678 &dev_attr_ioerr_cnt.attr,
633 &dev_attr_modalias.attr, 679 &dev_attr_modalias.attr,
680 REF_EVT(media_change),
634 NULL 681 NULL
635}; 682};
636 683
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 161d1021b7..e52a6296ca 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -601,8 +601,7 @@ static int match_maple_bus_driver(struct device *devptr,
601 return 0; 601 return 0;
602} 602}
603 603
604static int maple_bus_uevent(struct device *dev, char **envp, 604static int maple_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
605 int num_envp, char *buffer, int buffer_size)
606{ 605{
607 return 0; 606 return 0;
608} 607}
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index ead2475406..28d4972f7a 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -11,7 +11,6 @@
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/mm.h> 12#include <linux/mm.h>
13#include <asm/io.h> 13#include <asm/io.h>
14#include <asm/scatterlist.h>
15#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
16#include <linux/dmapool.h> 15#include <linux/dmapool.h>
17#include <linux/usb.h> 16#include <linux/usb.h>
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 3dd997df85..fea8256a18 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -30,7 +30,6 @@
30#include <linux/utsname.h> 30#include <linux/utsname.h>
31#include <linux/mm.h> 31#include <linux/mm.h>
32#include <asm/io.h> 32#include <asm/io.h>
33#include <asm/scatterlist.h>
34#include <linux/device.h> 33#include <linux/device.h>
35#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
36#include <linux/mutex.h> 35#include <linux/mutex.h>
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 69aa68287d..c4a6f1095b 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -36,7 +36,7 @@
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37 37
38#include <asm/io.h> 38#include <asm/io.h>
39#include <asm/scatterlist.h> 39#include <linux/scatterlist.h>
40#include <linux/mm.h> 40#include <linux/mm.h>
41#include <linux/dma-mapping.h> 41#include <linux/dma-mapping.h>
42 42