aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/atm/Makefile3
-rw-r--r--drivers/atm/fore200e.c6
-rw-r--r--drivers/atm/he.c6
-rw-r--r--drivers/atm/nicstar.c20
-rw-r--r--drivers/atm/zatm.c11
-rw-r--r--drivers/block/cfq-iosched.c9
-rw-r--r--drivers/block/elevator.c9
-rw-r--r--drivers/block/ub.c598
-rw-r--r--drivers/char/agp/agp.h2
-rw-r--r--drivers/char/agp/ali-agp.c4
-rw-r--r--drivers/char/agp/amd-k7-agp.c6
-rw-r--r--drivers/char/agp/amd64-agp.c4
-rw-r--r--drivers/char/agp/ati-agp.c6
-rw-r--r--drivers/char/agp/backend.c6
-rw-r--r--drivers/char/agp/efficeon-agp.c2
-rw-r--r--drivers/char/agp/generic.c36
-rw-r--r--drivers/char/agp/hp-agp.c4
-rw-r--r--drivers/char/agp/i460-agp.c4
-rw-r--r--drivers/char/agp/intel-agp.c21
-rw-r--r--drivers/char/agp/sgi-agp.c12
-rw-r--r--drivers/char/agp/sworks-agp.c8
-rw-r--r--drivers/char/agp/uninorth-agp.c2
-rw-r--r--drivers/char/drm/drm_pciids.h1
-rw-r--r--drivers/char/drm/radeon_irq.c5
-rw-r--r--drivers/char/mxser.c38
-rw-r--r--drivers/ieee1394/sbp2.c3
-rw-r--r--drivers/input/keyboard/atkbd.c2
-rw-r--r--drivers/input/mouse/alps.c2
-rw-r--r--drivers/macintosh/via-pmu.c6
-rw-r--r--drivers/md/dm-mpath.c3
-rw-r--r--drivers/message/i2o/i2o_block.c1
-rw-r--r--drivers/net/hamradio/baycom_epp.c126
-rw-r--r--drivers/net/irda/Kconfig2
-rw-r--r--drivers/net/iseries_veth.c9
-rw-r--r--drivers/net/pcmcia/3c574_cs.c3
-rw-r--r--drivers/net/r8169.c33
-rw-r--r--drivers/net/shaper.c86
-rw-r--r--drivers/net/tg3.c39
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_core.c2
-rw-r--r--drivers/pci/hotplug/cpci_hotplug_pci.c5
-rw-r--r--drivers/pci/pci-driver.c5
-rw-r--r--drivers/pci/pci.ids1
-rw-r--r--drivers/pci/probe.c2
-rw-r--r--drivers/pci/quirks.c41
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/ata_piix.c16
-rw-r--r--drivers/scsi/libata-core.c474
-rw-r--r--drivers/scsi/libata-scsi.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c24
-rw-r--r--drivers/scsi/sata_sil.c8
-rw-r--r--drivers/scsi/scsi_scan.c1
-rw-r--r--drivers/serial/sa1100.c2
-rw-r--r--drivers/serial/vr41xx_siu.c66
-rw-r--r--drivers/usb/core/sysfs.c22
-rw-r--r--drivers/usb/host/ehci-hub.c5
-rw-r--r--drivers/usb/input/hid-core.c18
-rw-r--r--drivers/usb/media/pwc/ChangeLog143
-rw-r--r--drivers/usb/media/pwc/pwc-if.c4
-rw-r--r--drivers/usb/net/kaweth.c2
-rw-r--r--drivers/usb/net/usbnet.c2
-rw-r--r--drivers/usb/serial/Kconfig11
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/cp2101.c363
-rw-r--r--drivers/usb/serial/ftdi_sio.c118
-rw-r--r--drivers/usb/serial/option.c729
-rw-r--r--drivers/usb/storage/unusual_devs.h9
-rw-r--r--drivers/video/aty/radeon_base.c7
-rw-r--r--drivers/video/fbsysfs.c2
-rw-r--r--drivers/video/macmodes.c1
69 files changed, 2250 insertions, 976 deletions
diff --git a/drivers/atm/Makefile b/drivers/atm/Makefile
index d1dcd8eae3c9..5b77188527a9 100644
--- a/drivers/atm/Makefile
+++ b/drivers/atm/Makefile
@@ -39,7 +39,8 @@ ifeq ($(CONFIG_ATM_FORE200E_PCA),y)
39 fore_200e-objs += fore200e_pca_fw.o 39 fore_200e-objs += fore200e_pca_fw.o
40 # guess the target endianess to choose the right PCA-200E firmware image 40 # guess the target endianess to choose the right PCA-200E firmware image
41 ifeq ($(CONFIG_ATM_FORE200E_PCA_DEFAULT_FW),y) 41 ifeq ($(CONFIG_ATM_FORE200E_PCA_DEFAULT_FW),y)
42 CONFIG_ATM_FORE200E_PCA_FW = $(shell if test -n "`$(CC) -E -dM $(src)/../../include/asm/byteorder.h | grep ' __LITTLE_ENDIAN '`"; then echo $(obj)/pca200e.bin; else echo $(obj)/pca200e_ecd.bin2; fi) 42 byteorder.h := include$(if $(patsubst $(srctree),,$(objtree)),2)/asm/byteorder.h
43 CONFIG_ATM_FORE200E_PCA_FW := $(obj)/pca200e$(if $(shell $(CC) -E -dM $(byteorder.h) | grep ' __LITTLE_ENDIAN '),.bin,_ecd.bin2)
43 endif 44 endif
44endif 45endif
45 46
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index 9e65bfb85ba3..5f702199543a 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -383,8 +383,7 @@ fore200e_shutdown(struct fore200e* fore200e)
383 switch(fore200e->state) { 383 switch(fore200e->state) {
384 384
385 case FORE200E_STATE_COMPLETE: 385 case FORE200E_STATE_COMPLETE:
386 if (fore200e->stats) 386 kfree(fore200e->stats);
387 kfree(fore200e->stats);
388 387
389 case FORE200E_STATE_IRQ: 388 case FORE200E_STATE_IRQ:
390 free_irq(fore200e->irq, fore200e->atm_dev); 389 free_irq(fore200e->irq, fore200e->atm_dev);
@@ -963,8 +962,7 @@ fore200e_tx_irq(struct fore200e* fore200e)
963 entry, txq->tail, entry->vc_map, entry->skb); 962 entry, txq->tail, entry->vc_map, entry->skb);
964 963
965 /* free copy of misaligned data */ 964 /* free copy of misaligned data */
966 if (entry->data) 965 kfree(entry->data);
967 kfree(entry->data);
968 966
969 /* remove DMA mapping */ 967 /* remove DMA mapping */
970 fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length, 968 fore200e->bus->dma_unmap(fore200e, entry->tpd->tsd[ 0 ].buffer, entry->tpd->tsd[ 0 ].length,
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index 3022c548a132..df2c83fd5496 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -412,8 +412,7 @@ he_init_one(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent)
412init_one_failure: 412init_one_failure:
413 if (atm_dev) 413 if (atm_dev)
414 atm_dev_deregister(atm_dev); 414 atm_dev_deregister(atm_dev);
415 if (he_dev) 415 kfree(he_dev);
416 kfree(he_dev);
417 pci_disable_device(pci_dev); 416 pci_disable_device(pci_dev);
418 return err; 417 return err;
419} 418}
@@ -2534,8 +2533,7 @@ he_open(struct atm_vcc *vcc)
2534open_failed: 2533open_failed:
2535 2534
2536 if (err) { 2535 if (err) {
2537 if (he_vcc) 2536 kfree(he_vcc);
2538 kfree(he_vcc);
2539 clear_bit(ATM_VF_ADDR, &vcc->flags); 2537 clear_bit(ATM_VF_ADDR, &vcc->flags);
2540 } 2538 }
2541 else 2539 else
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 85bf5c8442b0..b2a7b754fd14 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -676,10 +676,10 @@ static int __devinit ns_init_card(int i, struct pci_dev *pcidev)
676 PRINTK("nicstar%d: RSQ base at 0x%x.\n", i, (u32) card->rsq.base); 676 PRINTK("nicstar%d: RSQ base at 0x%x.\n", i, (u32) card->rsq.base);
677 677
678 /* Initialize SCQ0, the only VBR SCQ used */ 678 /* Initialize SCQ0, the only VBR SCQ used */
679 card->scq1 = (scq_info *) NULL; 679 card->scq1 = NULL;
680 card->scq2 = (scq_info *) NULL; 680 card->scq2 = NULL;
681 card->scq0 = get_scq(VBR_SCQSIZE, NS_VRSCD0); 681 card->scq0 = get_scq(VBR_SCQSIZE, NS_VRSCD0);
682 if (card->scq0 == (scq_info *) NULL) 682 if (card->scq0 == NULL)
683 { 683 {
684 printk("nicstar%d: can't get SCQ0.\n", i); 684 printk("nicstar%d: can't get SCQ0.\n", i);
685 error = 12; 685 error = 12;
@@ -993,24 +993,24 @@ static scq_info *get_scq(int size, u32 scd)
993 int i; 993 int i;
994 994
995 if (size != VBR_SCQSIZE && size != CBR_SCQSIZE) 995 if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
996 return (scq_info *) NULL; 996 return NULL;
997 997
998 scq = (scq_info *) kmalloc(sizeof(scq_info), GFP_KERNEL); 998 scq = (scq_info *) kmalloc(sizeof(scq_info), GFP_KERNEL);
999 if (scq == (scq_info *) NULL) 999 if (scq == NULL)
1000 return (scq_info *) NULL; 1000 return NULL;
1001 scq->org = kmalloc(2 * size, GFP_KERNEL); 1001 scq->org = kmalloc(2 * size, GFP_KERNEL);
1002 if (scq->org == NULL) 1002 if (scq->org == NULL)
1003 { 1003 {
1004 kfree(scq); 1004 kfree(scq);
1005 return (scq_info *) NULL; 1005 return NULL;
1006 } 1006 }
1007 scq->skb = (struct sk_buff **) kmalloc(sizeof(struct sk_buff *) * 1007 scq->skb = (struct sk_buff **) kmalloc(sizeof(struct sk_buff *) *
1008 (size / NS_SCQE_SIZE), GFP_KERNEL); 1008 (size / NS_SCQE_SIZE), GFP_KERNEL);
1009 if (scq->skb == (struct sk_buff **) NULL) 1009 if (scq->skb == NULL)
1010 { 1010 {
1011 kfree(scq->org); 1011 kfree(scq->org);
1012 kfree(scq); 1012 kfree(scq);
1013 return (scq_info *) NULL; 1013 return NULL;
1014 } 1014 }
1015 scq->num_entries = size / NS_SCQE_SIZE; 1015 scq->num_entries = size / NS_SCQE_SIZE;
1016 scq->base = (ns_scqe *) ALIGN_ADDRESS(scq->org, size); 1016 scq->base = (ns_scqe *) ALIGN_ADDRESS(scq->org, size);
@@ -1498,7 +1498,7 @@ static int ns_open(struct atm_vcc *vcc)
1498 vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE; 1498 vc->cbr_scd = NS_FRSCD + frscdi * NS_FRSCD_SIZE;
1499 1499
1500 scq = get_scq(CBR_SCQSIZE, vc->cbr_scd); 1500 scq = get_scq(CBR_SCQSIZE, vc->cbr_scd);
1501 if (scq == (scq_info *) NULL) 1501 if (scq == NULL)
1502 { 1502 {
1503 PRINTK("nicstar%d: can't get fixed rate SCQ.\n", card->index); 1503 PRINTK("nicstar%d: can't get fixed rate SCQ.\n", card->index);
1504 card->scd2vc[frscdi] = NULL; 1504 card->scd2vc[frscdi] = NULL;
diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
index 47a800519ad0..8d5e65cb9755 100644
--- a/drivers/atm/zatm.c
+++ b/drivers/atm/zatm.c
@@ -902,7 +902,7 @@ static void close_tx(struct atm_vcc *vcc)
902 zatm_dev->tx_bw += vcc->qos.txtp.min_pcr; 902 zatm_dev->tx_bw += vcc->qos.txtp.min_pcr;
903 dealloc_shaper(vcc->dev,zatm_vcc->shaper); 903 dealloc_shaper(vcc->dev,zatm_vcc->shaper);
904 } 904 }
905 if (zatm_vcc->ring) kfree(zatm_vcc->ring); 905 kfree(zatm_vcc->ring);
906} 906}
907 907
908 908
@@ -1339,12 +1339,9 @@ static int __init zatm_start(struct atm_dev *dev)
1339 return 0; 1339 return 0;
1340 out: 1340 out:
1341 for (i = 0; i < NR_MBX; i++) 1341 for (i = 0; i < NR_MBX; i++)
1342 if (zatm_dev->mbx_start[i] != 0) 1342 kfree(zatm_dev->mbx_start[i]);
1343 kfree((void *) zatm_dev->mbx_start[i]); 1343 kfree(zatm_dev->rx_map);
1344 if (zatm_dev->rx_map != NULL) 1344 kfree(zatm_dev->tx_map);
1345 kfree(zatm_dev->rx_map);
1346 if (zatm_dev->tx_map != NULL)
1347 kfree(zatm_dev->tx_map);
1348 free_irq(zatm_dev->irq, dev); 1345 free_irq(zatm_dev->irq, dev);
1349 return error; 1346 return error;
1350} 1347}
diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c
index 0ef7a0065ece..2210bacad56a 100644
--- a/drivers/block/cfq-iosched.c
+++ b/drivers/block/cfq-iosched.c
@@ -1202,13 +1202,16 @@ retry:
1202 if (new_cfqq) { 1202 if (new_cfqq) {
1203 cfqq = new_cfqq; 1203 cfqq = new_cfqq;
1204 new_cfqq = NULL; 1204 new_cfqq = NULL;
1205 } else if (gfp_mask & __GFP_WAIT) { 1205 } else {
1206 spin_unlock_irq(cfqd->queue->queue_lock); 1206 spin_unlock_irq(cfqd->queue->queue_lock);
1207 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask); 1207 new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask);
1208 spin_lock_irq(cfqd->queue->queue_lock); 1208 spin_lock_irq(cfqd->queue->queue_lock);
1209
1210 if (!new_cfqq && !(gfp_mask & __GFP_WAIT))
1211 goto out;
1212
1209 goto retry; 1213 goto retry;
1210 } else 1214 }
1211 goto out;
1212 1215
1213 memset(cfqq, 0, sizeof(*cfqq)); 1216 memset(cfqq, 0, sizeof(*cfqq));
1214 1217
diff --git a/drivers/block/elevator.c b/drivers/block/elevator.c
index 6b79b4314622..89982925f9e2 100644
--- a/drivers/block/elevator.c
+++ b/drivers/block/elevator.c
@@ -220,11 +220,6 @@ void elevator_exit(elevator_t *e)
220 kfree(e); 220 kfree(e);
221} 221}
222 222
223static int elevator_global_init(void)
224{
225 return 0;
226}
227
228int elv_merge(request_queue_t *q, struct request **req, struct bio *bio) 223int elv_merge(request_queue_t *q, struct request **req, struct bio *bio)
229{ 224{
230 elevator_t *e = q->elevator; 225 elevator_t *e = q->elevator;
@@ -322,7 +317,7 @@ void __elv_add_request(request_queue_t *q, struct request *rq, int where,
322 int nrq = q->rq.count[READ] + q->rq.count[WRITE] 317 int nrq = q->rq.count[READ] + q->rq.count[WRITE]
323 - q->in_flight; 318 - q->in_flight;
324 319
325 if (nrq == q->unplug_thresh) 320 if (nrq >= q->unplug_thresh)
326 __generic_unplug_device(q); 321 __generic_unplug_device(q);
327 } 322 }
328 } else 323 } else
@@ -692,8 +687,6 @@ ssize_t elv_iosched_show(request_queue_t *q, char *name)
692 return len; 687 return len;
693} 688}
694 689
695module_init(elevator_global_init);
696
697EXPORT_SYMBOL(elv_add_request); 690EXPORT_SYMBOL(elv_add_request);
698EXPORT_SYMBOL(__elv_add_request); 691EXPORT_SYMBOL(__elv_add_request);
699EXPORT_SYMBOL(elv_requeue_request); 692EXPORT_SYMBOL(elv_requeue_request);
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index ce42889f98fb..19c5e59bcfa8 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -8,13 +8,12 @@
8 * and is not licensed separately. See file COPYING for details. 8 * and is not licensed separately. See file COPYING for details.
9 * 9 *
10 * TODO (sorted by decreasing priority) 10 * TODO (sorted by decreasing priority)
11 * -- Kill first_open (Al Viro fixed the block layer now)
11 * -- Do resets with usb_device_reset (needs a thread context, use khubd) 12 * -- Do resets with usb_device_reset (needs a thread context, use khubd)
12 * -- set readonly flag for CDs, set removable flag for CF readers 13 * -- set readonly flag for CDs, set removable flag for CF readers
13 * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) 14 * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch)
14 * -- support pphaneuf's SDDR-75 with two LUNs (also broken capacity...)
15 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries 15 * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries
16 * -- verify the 13 conditions and do bulk resets 16 * -- verify the 13 conditions and do bulk resets
17 * -- normal pool of commands instead of cmdv[]?
18 * -- kill last_pipe and simply do two-state clearing on both pipes 17 * -- kill last_pipe and simply do two-state clearing on both pipes
19 * -- verify protocol (bulk) from USB descriptors (maybe...) 18 * -- verify protocol (bulk) from USB descriptors (maybe...)
20 * -- highmem and sg 19 * -- highmem and sg
@@ -49,7 +48,14 @@
49#define US_SC_SCSI 0x06 /* Transparent */ 48#define US_SC_SCSI 0x06 /* Transparent */
50 49
51/* 50/*
51 * This many LUNs per USB device.
52 * Every one of them takes a host, see UB_MAX_HOSTS.
52 */ 53 */
54#define UB_MAX_LUNS 9
55
56/*
57 */
58
53#define UB_MINORS_PER_MAJOR 8 59#define UB_MINORS_PER_MAJOR 8
54 60
55#define UB_MAX_CDB_SIZE 16 /* Corresponds to Bulk */ 61#define UB_MAX_CDB_SIZE 16 /* Corresponds to Bulk */
@@ -65,7 +71,7 @@ struct bulk_cb_wrap {
65 u32 Tag; /* unique per command id */ 71 u32 Tag; /* unique per command id */
66 __le32 DataTransferLength; /* size of data */ 72 __le32 DataTransferLength; /* size of data */
67 u8 Flags; /* direction in bit 0 */ 73 u8 Flags; /* direction in bit 0 */
68 u8 Lun; /* LUN normally 0 */ 74 u8 Lun; /* LUN */
69 u8 Length; /* of of the CDB */ 75 u8 Length; /* of of the CDB */
70 u8 CDB[UB_MAX_CDB_SIZE]; /* max command */ 76 u8 CDB[UB_MAX_CDB_SIZE]; /* max command */
71}; 77};
@@ -168,6 +174,7 @@ struct ub_scsi_cmd {
168 unsigned int len; /* Requested length */ 174 unsigned int len; /* Requested length */
169 // struct scatterlist sgv[UB_MAX_REQ_SG]; 175 // struct scatterlist sgv[UB_MAX_REQ_SG];
170 176
177 struct ub_lun *lun;
171 void (*done)(struct ub_dev *, struct ub_scsi_cmd *); 178 void (*done)(struct ub_dev *, struct ub_scsi_cmd *);
172 void *back; 179 void *back;
173}; 180};
@@ -252,25 +259,47 @@ struct ub_scsi_cmd_queue {
252}; 259};
253 260
254/* 261/*
255 * The UB device instance. 262 * The block device instance (one per LUN).
263 */
264struct ub_lun {
265 struct ub_dev *udev;
266 struct list_head link;
267 struct gendisk *disk;
268 int id; /* Host index */
269 int num; /* LUN number */
270 char name[16];
271
272 int changed; /* Media was changed */
273 int removable;
274 int readonly;
275 int first_open; /* Kludge. See ub_bd_open. */
276
277 /* Use Ingo's mempool if or when we have more than one command. */
278 /*
279 * Currently we never need more than one command for the whole device.
280 * However, giving every LUN a command is a cheap and automatic way
281 * to enforce fairness between them.
282 */
283 int cmda[1];
284 struct ub_scsi_cmd cmdv[1];
285
286 struct ub_capacity capacity;
287};
288
289/*
290 * The USB device instance.
256 */ 291 */
257struct ub_dev { 292struct ub_dev {
258 spinlock_t lock; 293 spinlock_t lock;
259 int id; /* Number among ub's */
260 atomic_t poison; /* The USB device is disconnected */ 294 atomic_t poison; /* The USB device is disconnected */
261 int openc; /* protected by ub_lock! */ 295 int openc; /* protected by ub_lock! */
262 /* kref is too implicit for our taste */ 296 /* kref is too implicit for our taste */
263 unsigned int tagcnt; 297 unsigned int tagcnt;
264 int changed; /* Media was changed */ 298 char name[12];
265 int removable;
266 int readonly;
267 int first_open; /* Kludge. See ub_bd_open. */
268 char name[8];
269 struct usb_device *dev; 299 struct usb_device *dev;
270 struct usb_interface *intf; 300 struct usb_interface *intf;
271 301
272 struct ub_capacity capacity; 302 struct list_head luns;
273 struct gendisk *disk;
274 303
275 unsigned int send_bulk_pipe; /* cached pipe values */ 304 unsigned int send_bulk_pipe; /* cached pipe values */
276 unsigned int recv_bulk_pipe; 305 unsigned int recv_bulk_pipe;
@@ -279,10 +308,6 @@ struct ub_dev {
279 308
280 struct tasklet_struct tasklet; 309 struct tasklet_struct tasklet;
281 310
282 /* XXX Use Ingo's mempool (once we have more than one) */
283 int cmda[1];
284 struct ub_scsi_cmd cmdv[1];
285
286 struct ub_scsi_cmd_queue cmd_queue; 311 struct ub_scsi_cmd_queue cmd_queue;
287 struct ub_scsi_cmd top_rqs_cmd; /* REQUEST SENSE */ 312 struct ub_scsi_cmd top_rqs_cmd; /* REQUEST SENSE */
288 unsigned char top_sense[UB_SENSE_SIZE]; 313 unsigned char top_sense[UB_SENSE_SIZE];
@@ -301,9 +326,9 @@ struct ub_dev {
301/* 326/*
302 */ 327 */
303static void ub_cleanup(struct ub_dev *sc); 328static void ub_cleanup(struct ub_dev *sc);
304static int ub_bd_rq_fn_1(struct ub_dev *sc, struct request *rq); 329static int ub_bd_rq_fn_1(struct ub_lun *lun, struct request *rq);
305static int ub_cmd_build_block(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 330static int ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
306 struct request *rq); 331 struct ub_scsi_cmd *cmd, struct request *rq);
307static int ub_cmd_build_packet(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 332static int ub_cmd_build_packet(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
308 struct request *rq); 333 struct request *rq);
309static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 334static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
@@ -320,8 +345,10 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
320static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 345static int ub_submit_clear_stall(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
321 int stalled_pipe); 346 int stalled_pipe);
322static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd); 347static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd);
323static int ub_sync_tur(struct ub_dev *sc); 348static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun);
324static int ub_sync_read_cap(struct ub_dev *sc, struct ub_capacity *ret); 349static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
350 struct ub_capacity *ret);
351static int ub_probe_lun(struct ub_dev *sc, int lnum);
325 352
326/* 353/*
327 */ 354 */
@@ -342,6 +369,7 @@ MODULE_DEVICE_TABLE(usb, ub_usb_ids);
342 */ 369 */
343#define UB_MAX_HOSTS 26 370#define UB_MAX_HOSTS 26
344static char ub_hostv[UB_MAX_HOSTS]; 371static char ub_hostv[UB_MAX_HOSTS];
372
345static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ 373static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */
346 374
347/* 375/*
@@ -406,6 +434,8 @@ static ssize_t ub_diag_show(struct device *dev, char *page)
406{ 434{
407 struct usb_interface *intf; 435 struct usb_interface *intf;
408 struct ub_dev *sc; 436 struct ub_dev *sc;
437 struct list_head *p;
438 struct ub_lun *lun;
409 int cnt; 439 int cnt;
410 unsigned long flags; 440 unsigned long flags;
411 int nc, nh; 441 int nc, nh;
@@ -421,9 +451,15 @@ static ssize_t ub_diag_show(struct device *dev, char *page)
421 spin_lock_irqsave(&sc->lock, flags); 451 spin_lock_irqsave(&sc->lock, flags);
422 452
423 cnt += sprintf(page + cnt, 453 cnt += sprintf(page + cnt,
424 "qlen %d qmax %d changed %d removable %d readonly %d\n", 454 "qlen %d qmax %d\n",
425 sc->cmd_queue.qlen, sc->cmd_queue.qmax, 455 sc->cmd_queue.qlen, sc->cmd_queue.qmax);
426 sc->changed, sc->removable, sc->readonly); 456
457 list_for_each (p, &sc->luns) {
458 lun = list_entry(p, struct ub_lun, link);
459 cnt += sprintf(page + cnt,
460 "lun %u changed %d removable %d readonly %d\n",
461 lun->num, lun->changed, lun->removable, lun->readonly);
462 }
427 463
428 if ((nc = sc->tr.cur + 1) == SCMD_TRACE_SZ) nc = 0; 464 if ((nc = sc->tr.cur + 1) == SCMD_TRACE_SZ) nc = 0;
429 for (j = 0; j < SCMD_TRACE_SZ; j++) { 465 for (j = 0; j < SCMD_TRACE_SZ; j++) {
@@ -523,53 +559,63 @@ static void ub_put(struct ub_dev *sc)
523 */ 559 */
524static void ub_cleanup(struct ub_dev *sc) 560static void ub_cleanup(struct ub_dev *sc)
525{ 561{
562 struct list_head *p;
563 struct ub_lun *lun;
526 request_queue_t *q; 564 request_queue_t *q;
527 565
528 /* I don't think queue can be NULL. But... Stolen from sx8.c */ 566 while (!list_empty(&sc->luns)) {
529 if ((q = sc->disk->queue) != NULL) 567 p = sc->luns.next;
530 blk_cleanup_queue(q); 568 lun = list_entry(p, struct ub_lun, link);
569 list_del(p);
531 570
532 /* 571 /* I don't think queue can be NULL. But... Stolen from sx8.c */
533 * If we zero disk->private_data BEFORE put_disk, we have to check 572 if ((q = lun->disk->queue) != NULL)
534 * for NULL all over the place in open, release, check_media and 573 blk_cleanup_queue(q);
535 * revalidate, because the block level semaphore is well inside the 574 /*
536 * put_disk. But we cannot zero after the call, because *disk is gone. 575 * If we zero disk->private_data BEFORE put_disk, we have
537 * The sd.c is blatantly racy in this area. 576 * to check for NULL all over the place in open, release,
538 */ 577 * check_media and revalidate, because the block level
539 /* disk->private_data = NULL; */ 578 * semaphore is well inside the put_disk.
540 put_disk(sc->disk); 579 * But we cannot zero after the call, because *disk is gone.
541 sc->disk = NULL; 580 * The sd.c is blatantly racy in this area.
581 */
582 /* disk->private_data = NULL; */
583 put_disk(lun->disk);
584 lun->disk = NULL;
585
586 ub_id_put(lun->id);
587 kfree(lun);
588 }
542 589
543 ub_id_put(sc->id);
544 kfree(sc); 590 kfree(sc);
545} 591}
546 592
547/* 593/*
548 * The "command allocator". 594 * The "command allocator".
549 */ 595 */
550static struct ub_scsi_cmd *ub_get_cmd(struct ub_dev *sc) 596static struct ub_scsi_cmd *ub_get_cmd(struct ub_lun *lun)
551{ 597{
552 struct ub_scsi_cmd *ret; 598 struct ub_scsi_cmd *ret;
553 599
554 if (sc->cmda[0]) 600 if (lun->cmda[0])
555 return NULL; 601 return NULL;
556 ret = &sc->cmdv[0]; 602 ret = &lun->cmdv[0];
557 sc->cmda[0] = 1; 603 lun->cmda[0] = 1;
558 return ret; 604 return ret;
559} 605}
560 606
561static void ub_put_cmd(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 607static void ub_put_cmd(struct ub_lun *lun, struct ub_scsi_cmd *cmd)
562{ 608{
563 if (cmd != &sc->cmdv[0]) { 609 if (cmd != &lun->cmdv[0]) {
564 printk(KERN_WARNING "%s: releasing a foreign cmd %p\n", 610 printk(KERN_WARNING "%s: releasing a foreign cmd %p\n",
565 sc->name, cmd); 611 lun->name, cmd);
566 return; 612 return;
567 } 613 }
568 if (!sc->cmda[0]) { 614 if (!lun->cmda[0]) {
569 printk(KERN_WARNING "%s: releasing a free cmd\n", sc->name); 615 printk(KERN_WARNING "%s: releasing a free cmd\n", lun->name);
570 return; 616 return;
571 } 617 }
572 sc->cmda[0] = 0; 618 lun->cmda[0] = 0;
573} 619}
574 620
575/* 621/*
@@ -630,29 +676,30 @@ static struct ub_scsi_cmd *ub_cmdq_pop(struct ub_dev *sc)
630 676
631static void ub_bd_rq_fn(request_queue_t *q) 677static void ub_bd_rq_fn(request_queue_t *q)
632{ 678{
633 struct ub_dev *sc = q->queuedata; 679 struct ub_lun *lun = q->queuedata;
634 struct request *rq; 680 struct request *rq;
635 681
636 while ((rq = elv_next_request(q)) != NULL) { 682 while ((rq = elv_next_request(q)) != NULL) {
637 if (ub_bd_rq_fn_1(sc, rq) != 0) { 683 if (ub_bd_rq_fn_1(lun, rq) != 0) {
638 blk_stop_queue(q); 684 blk_stop_queue(q);
639 break; 685 break;
640 } 686 }
641 } 687 }
642} 688}
643 689
644static int ub_bd_rq_fn_1(struct ub_dev *sc, struct request *rq) 690static int ub_bd_rq_fn_1(struct ub_lun *lun, struct request *rq)
645{ 691{
692 struct ub_dev *sc = lun->udev;
646 struct ub_scsi_cmd *cmd; 693 struct ub_scsi_cmd *cmd;
647 int rc; 694 int rc;
648 695
649 if (atomic_read(&sc->poison) || sc->changed) { 696 if (atomic_read(&sc->poison) || lun->changed) {
650 blkdev_dequeue_request(rq); 697 blkdev_dequeue_request(rq);
651 ub_end_rq(rq, 0); 698 ub_end_rq(rq, 0);
652 return 0; 699 return 0;
653 } 700 }
654 701
655 if ((cmd = ub_get_cmd(sc)) == NULL) 702 if ((cmd = ub_get_cmd(lun)) == NULL)
656 return -1; 703 return -1;
657 memset(cmd, 0, sizeof(struct ub_scsi_cmd)); 704 memset(cmd, 0, sizeof(struct ub_scsi_cmd));
658 705
@@ -661,32 +708,30 @@ static int ub_bd_rq_fn_1(struct ub_dev *sc, struct request *rq)
661 if (blk_pc_request(rq)) { 708 if (blk_pc_request(rq)) {
662 rc = ub_cmd_build_packet(sc, cmd, rq); 709 rc = ub_cmd_build_packet(sc, cmd, rq);
663 } else { 710 } else {
664 rc = ub_cmd_build_block(sc, cmd, rq); 711 rc = ub_cmd_build_block(sc, lun, cmd, rq);
665 } 712 }
666 if (rc != 0) { 713 if (rc != 0) {
667 ub_put_cmd(sc, cmd); 714 ub_put_cmd(lun, cmd);
668 ub_end_rq(rq, 0); 715 ub_end_rq(rq, 0);
669 blk_start_queue(sc->disk->queue);
670 return 0; 716 return 0;
671 } 717 }
672
673 cmd->state = UB_CMDST_INIT; 718 cmd->state = UB_CMDST_INIT;
719 cmd->lun = lun;
674 cmd->done = ub_rw_cmd_done; 720 cmd->done = ub_rw_cmd_done;
675 cmd->back = rq; 721 cmd->back = rq;
676 722
677 cmd->tag = sc->tagcnt++; 723 cmd->tag = sc->tagcnt++;
678 if ((rc = ub_submit_scsi(sc, cmd)) != 0) { 724 if ((rc = ub_submit_scsi(sc, cmd)) != 0) {
679 ub_put_cmd(sc, cmd); 725 ub_put_cmd(lun, cmd);
680 ub_end_rq(rq, 0); 726 ub_end_rq(rq, 0);
681 blk_start_queue(sc->disk->queue);
682 return 0; 727 return 0;
683 } 728 }
684 729
685 return 0; 730 return 0;
686} 731}
687 732
688static int ub_cmd_build_block(struct ub_dev *sc, struct ub_scsi_cmd *cmd, 733static int ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
689 struct request *rq) 734 struct ub_scsi_cmd *cmd, struct request *rq)
690{ 735{
691 int ub_dir; 736 int ub_dir;
692#if 0 /* We use rq->buffer for now */ 737#if 0 /* We use rq->buffer for now */
@@ -707,7 +752,7 @@ static int ub_cmd_build_block(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
707 sg = &cmd->sgv[0]; 752 sg = &cmd->sgv[0];
708 n_elem = blk_rq_map_sg(q, rq, sg); 753 n_elem = blk_rq_map_sg(q, rq, sg);
709 if (n_elem <= 0) { 754 if (n_elem <= 0) {
710 ub_put_cmd(sc, cmd); 755 ub_put_cmd(lun, cmd);
711 ub_end_rq(rq, 0); 756 ub_end_rq(rq, 0);
712 blk_start_queue(q); 757 blk_start_queue(q);
713 return 0; /* request with no s/g entries? */ 758 return 0; /* request with no s/g entries? */
@@ -716,7 +761,7 @@ static int ub_cmd_build_block(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
716 if (n_elem != 1) { /* Paranoia */ 761 if (n_elem != 1) { /* Paranoia */
717 printk(KERN_WARNING "%s: request with %d segments\n", 762 printk(KERN_WARNING "%s: request with %d segments\n",
718 sc->name, n_elem); 763 sc->name, n_elem);
719 ub_put_cmd(sc, cmd); 764 ub_put_cmd(lun, cmd);
720 ub_end_rq(rq, 0); 765 ub_end_rq(rq, 0);
721 blk_start_queue(q); 766 blk_start_queue(q);
722 return 0; 767 return 0;
@@ -748,8 +793,8 @@ static int ub_cmd_build_block(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
748 * The call to blk_queue_hardsect_size() guarantees that request 793 * The call to blk_queue_hardsect_size() guarantees that request
749 * is aligned, but it is given in terms of 512 byte units, always. 794 * is aligned, but it is given in terms of 512 byte units, always.
750 */ 795 */
751 block = rq->sector >> sc->capacity.bshift; 796 block = rq->sector >> lun->capacity.bshift;
752 nblks = rq->nr_sectors >> sc->capacity.bshift; 797 nblks = rq->nr_sectors >> lun->capacity.bshift;
753 798
754 cmd->cdb[0] = (ub_dir == UB_DIR_READ)? READ_10: WRITE_10; 799 cmd->cdb[0] = (ub_dir == UB_DIR_READ)? READ_10: WRITE_10;
755 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */ 800 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */
@@ -803,7 +848,8 @@ static int ub_cmd_build_packet(struct ub_dev *sc, struct ub_scsi_cmd *cmd,
803static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 848static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
804{ 849{
805 struct request *rq = cmd->back; 850 struct request *rq = cmd->back;
806 struct gendisk *disk = sc->disk; 851 struct ub_lun *lun = cmd->lun;
852 struct gendisk *disk = lun->disk;
807 request_queue_t *q = disk->queue; 853 request_queue_t *q = disk->queue;
808 int uptodate; 854 int uptodate;
809 855
@@ -818,7 +864,7 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
818 else 864 else
819 uptodate = 0; 865 uptodate = 0;
820 866
821 ub_put_cmd(sc, cmd); 867 ub_put_cmd(lun, cmd);
822 ub_end_rq(rq, uptodate); 868 ub_end_rq(rq, uptodate);
823 blk_start_queue(q); 869 blk_start_queue(q);
824} 870}
@@ -887,7 +933,7 @@ static int ub_scsi_cmd_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
887 bcb->Tag = cmd->tag; /* Endianness is not important */ 933 bcb->Tag = cmd->tag; /* Endianness is not important */
888 bcb->DataTransferLength = cpu_to_le32(cmd->len); 934 bcb->DataTransferLength = cpu_to_le32(cmd->len);
889 bcb->Flags = (cmd->dir == UB_DIR_READ) ? 0x80 : 0; 935 bcb->Flags = (cmd->dir == UB_DIR_READ) ? 0x80 : 0;
890 bcb->Lun = 0; /* No multi-LUN yet */ 936 bcb->Lun = (cmd->lun != NULL) ? cmd->lun->num : 0;
891 bcb->Length = cmd->cdb_len; 937 bcb->Length = cmd->cdb_len;
892 938
893 /* copy the command payload */ 939 /* copy the command payload */
@@ -1002,9 +1048,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1002 * The control pipe clears itself - nothing to do. 1048 * The control pipe clears itself - nothing to do.
1003 * XXX Might try to reset the device here and retry. 1049 * XXX Might try to reset the device here and retry.
1004 */ 1050 */
1005 printk(KERN_NOTICE "%s: " 1051 printk(KERN_NOTICE "%s: stall on control pipe\n",
1006 "stall on control pipe for device %u\n", 1052 sc->name);
1007 sc->name, sc->dev->devnum);
1008 goto Bad_End; 1053 goto Bad_End;
1009 } 1054 }
1010 1055
@@ -1025,9 +1070,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1025 * The control pipe clears itself - nothing to do. 1070 * The control pipe clears itself - nothing to do.
1026 * XXX Might try to reset the device here and retry. 1071 * XXX Might try to reset the device here and retry.
1027 */ 1072 */
1028 printk(KERN_NOTICE "%s: " 1073 printk(KERN_NOTICE "%s: stall on control pipe\n",
1029 "stall on control pipe for device %u\n", 1074 sc->name);
1030 sc->name, sc->dev->devnum);
1031 goto Bad_End; 1075 goto Bad_End;
1032 } 1076 }
1033 1077
@@ -1046,9 +1090,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1046 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe); 1090 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe);
1047 if (rc != 0) { 1091 if (rc != 0) {
1048 printk(KERN_NOTICE "%s: " 1092 printk(KERN_NOTICE "%s: "
1049 "unable to submit clear for device %u" 1093 "unable to submit clear (%d)\n",
1050 " (code %d)\n", 1094 sc->name, rc);
1051 sc->name, sc->dev->devnum, rc);
1052 /* 1095 /*
1053 * This is typically ENOMEM or some other such shit. 1096 * This is typically ENOMEM or some other such shit.
1054 * Retrying is pointless. Just do Bad End on it... 1097 * Retrying is pointless. Just do Bad End on it...
@@ -1107,9 +1150,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1107 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe); 1150 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe);
1108 if (rc != 0) { 1151 if (rc != 0) {
1109 printk(KERN_NOTICE "%s: " 1152 printk(KERN_NOTICE "%s: "
1110 "unable to submit clear for device %u" 1153 "unable to submit clear (%d)\n",
1111 " (code %d)\n", 1154 sc->name, rc);
1112 sc->name, sc->dev->devnum, rc);
1113 /* 1155 /*
1114 * This is typically ENOMEM or some other such shit. 1156 * This is typically ENOMEM or some other such shit.
1115 * Retrying is pointless. Just do Bad End on it... 1157 * Retrying is pointless. Just do Bad End on it...
@@ -1140,9 +1182,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1140 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe); 1182 rc = ub_submit_clear_stall(sc, cmd, sc->last_pipe);
1141 if (rc != 0) { 1183 if (rc != 0) {
1142 printk(KERN_NOTICE "%s: " 1184 printk(KERN_NOTICE "%s: "
1143 "unable to submit clear for device %u" 1185 "unable to submit clear (%d)\n",
1144 " (code %d)\n", 1186 sc->name, rc);
1145 sc->name, sc->dev->devnum, rc);
1146 /* 1187 /*
1147 * This is typically ENOMEM or some other such shit. 1188 * This is typically ENOMEM or some other such shit.
1148 * Retrying is pointless. Just do Bad End on it... 1189 * Retrying is pointless. Just do Bad End on it...
@@ -1164,9 +1205,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1164 * encounter such a thing, try to read the CSW again. 1205 * encounter such a thing, try to read the CSW again.
1165 */ 1206 */
1166 if (++cmd->stat_count >= 4) { 1207 if (++cmd->stat_count >= 4) {
1167 printk(KERN_NOTICE "%s: " 1208 printk(KERN_NOTICE "%s: unable to get CSW\n",
1168 "unable to get CSW on device %u\n", 1209 sc->name);
1169 sc->name, sc->dev->devnum);
1170 goto Bad_End; 1210 goto Bad_End;
1171 } 1211 }
1172 __ub_state_stat(sc, cmd); 1212 __ub_state_stat(sc, cmd);
@@ -1207,10 +1247,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1207 */ 1247 */
1208 if (++cmd->stat_count >= 4) { 1248 if (++cmd->stat_count >= 4) {
1209 printk(KERN_NOTICE "%s: " 1249 printk(KERN_NOTICE "%s: "
1210 "tag mismatch orig 0x%x reply 0x%x " 1250 "tag mismatch orig 0x%x reply 0x%x\n",
1211 "on device %u\n", 1251 sc->name, cmd->tag, bcs->Tag);
1212 sc->name, cmd->tag, bcs->Tag,
1213 sc->dev->devnum);
1214 goto Bad_End; 1252 goto Bad_End;
1215 } 1253 }
1216 __ub_state_stat(sc, cmd); 1254 __ub_state_stat(sc, cmd);
@@ -1244,8 +1282,8 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1244 1282
1245 } else { 1283 } else {
1246 printk(KERN_WARNING "%s: " 1284 printk(KERN_WARNING "%s: "
1247 "wrong command state %d on device %u\n", 1285 "wrong command state %d\n",
1248 sc->name, cmd->state, sc->dev->devnum); 1286 sc->name, cmd->state);
1249 goto Bad_End; 1287 goto Bad_End;
1250 } 1288 }
1251 return; 1289 return;
@@ -1288,7 +1326,6 @@ static void __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1288 1326
1289 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) { 1327 if ((rc = usb_submit_urb(&sc->work_urb, GFP_ATOMIC)) != 0) {
1290 /* XXX Clear stalls */ 1328 /* XXX Clear stalls */
1291 printk("%s: CSW #%d submit failed (%d)\n", sc->name, cmd->tag, rc); /* P3 */
1292 ub_complete(&sc->work_done); 1329 ub_complete(&sc->work_done);
1293 ub_state_done(sc, cmd, rc); 1330 ub_state_done(sc, cmd, rc);
1294 return; 1331 return;
@@ -1333,6 +1370,7 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1333 scmd->state = UB_CMDST_INIT; 1370 scmd->state = UB_CMDST_INIT;
1334 scmd->data = sc->top_sense; 1371 scmd->data = sc->top_sense;
1335 scmd->len = UB_SENSE_SIZE; 1372 scmd->len = UB_SENSE_SIZE;
1373 scmd->lun = cmd->lun;
1336 scmd->done = ub_top_sense_done; 1374 scmd->done = ub_top_sense_done;
1337 scmd->back = cmd; 1375 scmd->back = cmd;
1338 1376
@@ -1411,14 +1449,14 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1411 } 1449 }
1412 if (cmd != scmd->back) { 1450 if (cmd != scmd->back) {
1413 printk(KERN_WARNING "%s: " 1451 printk(KERN_WARNING "%s: "
1414 "sense done for wrong command 0x%x on device %u\n", 1452 "sense done for wrong command 0x%x\n",
1415 sc->name, cmd->tag, sc->dev->devnum); 1453 sc->name, cmd->tag);
1416 return; 1454 return;
1417 } 1455 }
1418 if (cmd->state != UB_CMDST_SENSE) { 1456 if (cmd->state != UB_CMDST_SENSE) {
1419 printk(KERN_WARNING "%s: " 1457 printk(KERN_WARNING "%s: "
1420 "sense done with bad cmd state %d on device %u\n", 1458 "sense done with bad cmd state %d\n",
1421 sc->name, cmd->state, sc->dev->devnum); 1459 sc->name, cmd->state);
1422 return; 1460 return;
1423 } 1461 }
1424 1462
@@ -1429,68 +1467,32 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1429 ub_scsi_urb_compl(sc, cmd); 1467 ub_scsi_urb_compl(sc, cmd);
1430} 1468}
1431 1469
1432#if 0
1433/* Determine what the maximum LUN supported is */
1434int usb_stor_Bulk_max_lun(struct us_data *us)
1435{
1436 int result;
1437
1438 /* issue the command */
1439 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
1440 US_BULK_GET_MAX_LUN,
1441 USB_DIR_IN | USB_TYPE_CLASS |
1442 USB_RECIP_INTERFACE,
1443 0, us->ifnum, us->iobuf, 1, HZ);
1444
1445 /*
1446 * Some devices (i.e. Iomega Zip100) need this -- apparently
1447 * the bulk pipes get STALLed when the GetMaxLUN request is
1448 * processed. This is, in theory, harmless to all other devices
1449 * (regardless of if they stall or not).
1450 */
1451 if (result < 0) {
1452 usb_stor_clear_halt(us, us->recv_bulk_pipe);
1453 usb_stor_clear_halt(us, us->send_bulk_pipe);
1454 }
1455
1456 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n",
1457 result, us->iobuf[0]);
1458
1459 /* if we have a successful request, return the result */
1460 if (result == 1)
1461 return us->iobuf[0];
1462
1463 /* return the default -- no LUNs */
1464 return 0;
1465}
1466#endif
1467
1468/* 1470/*
1469 * This is called from a process context. 1471 * This is called from a process context.
1470 */ 1472 */
1471static void ub_revalidate(struct ub_dev *sc) 1473static void ub_revalidate(struct ub_dev *sc, struct ub_lun *lun)
1472{ 1474{
1473 1475
1474 sc->readonly = 0; /* XXX Query this from the device */ 1476 lun->readonly = 0; /* XXX Query this from the device */
1475 1477
1476 sc->capacity.nsec = 0; 1478 lun->capacity.nsec = 0;
1477 sc->capacity.bsize = 512; 1479 lun->capacity.bsize = 512;
1478 sc->capacity.bshift = 0; 1480 lun->capacity.bshift = 0;
1479 1481
1480 if (ub_sync_tur(sc) != 0) 1482 if (ub_sync_tur(sc, lun) != 0)
1481 return; /* Not ready */ 1483 return; /* Not ready */
1482 sc->changed = 0; 1484 lun->changed = 0;
1483 1485
1484 if (ub_sync_read_cap(sc, &sc->capacity) != 0) { 1486 if (ub_sync_read_cap(sc, lun, &lun->capacity) != 0) {
1485 /* 1487 /*
1486 * The retry here means something is wrong, either with the 1488 * The retry here means something is wrong, either with the
1487 * device, with the transport, or with our code. 1489 * device, with the transport, or with our code.
1488 * We keep this because sd.c has retries for capacity. 1490 * We keep this because sd.c has retries for capacity.
1489 */ 1491 */
1490 if (ub_sync_read_cap(sc, &sc->capacity) != 0) { 1492 if (ub_sync_read_cap(sc, lun, &lun->capacity) != 0) {
1491 sc->capacity.nsec = 0; 1493 lun->capacity.nsec = 0;
1492 sc->capacity.bsize = 512; 1494 lun->capacity.bsize = 512;
1493 sc->capacity.bshift = 0; 1495 lun->capacity.bshift = 0;
1494 } 1496 }
1495 } 1497 }
1496} 1498}
@@ -1503,12 +1505,15 @@ static void ub_revalidate(struct ub_dev *sc)
1503static int ub_bd_open(struct inode *inode, struct file *filp) 1505static int ub_bd_open(struct inode *inode, struct file *filp)
1504{ 1506{
1505 struct gendisk *disk = inode->i_bdev->bd_disk; 1507 struct gendisk *disk = inode->i_bdev->bd_disk;
1508 struct ub_lun *lun;
1506 struct ub_dev *sc; 1509 struct ub_dev *sc;
1507 unsigned long flags; 1510 unsigned long flags;
1508 int rc; 1511 int rc;
1509 1512
1510 if ((sc = disk->private_data) == NULL) 1513 if ((lun = disk->private_data) == NULL)
1511 return -ENXIO; 1514 return -ENXIO;
1515 sc = lun->udev;
1516
1512 spin_lock_irqsave(&ub_lock, flags); 1517 spin_lock_irqsave(&ub_lock, flags);
1513 if (atomic_read(&sc->poison)) { 1518 if (atomic_read(&sc->poison)) {
1514 spin_unlock_irqrestore(&ub_lock, flags); 1519 spin_unlock_irqrestore(&ub_lock, flags);
@@ -1529,15 +1534,15 @@ static int ub_bd_open(struct inode *inode, struct file *filp)
1529 * The bottom line is, Al Viro says that we should not allow 1534 * The bottom line is, Al Viro says that we should not allow
1530 * bdev->bd_invalidated to be set when doing add_disk no matter what. 1535 * bdev->bd_invalidated to be set when doing add_disk no matter what.
1531 */ 1536 */
1532 if (sc->first_open) { 1537 if (lun->first_open) {
1533 if (sc->changed) { 1538 lun->first_open = 0;
1534 sc->first_open = 0; 1539 if (lun->changed) {
1535 rc = -ENOMEDIUM; 1540 rc = -ENOMEDIUM;
1536 goto err_open; 1541 goto err_open;
1537 } 1542 }
1538 } 1543 }
1539 1544
1540 if (sc->removable || sc->readonly) 1545 if (lun->removable || lun->readonly)
1541 check_disk_change(inode->i_bdev); 1546 check_disk_change(inode->i_bdev);
1542 1547
1543 /* 1548 /*
@@ -1545,12 +1550,12 @@ static int ub_bd_open(struct inode *inode, struct file *filp)
1545 * under some pretty murky conditions (a failure of READ CAPACITY). 1550 * under some pretty murky conditions (a failure of READ CAPACITY).
1546 * We may need it one day. 1551 * We may need it one day.
1547 */ 1552 */
1548 if (sc->removable && sc->changed && !(filp->f_flags & O_NDELAY)) { 1553 if (lun->removable && lun->changed && !(filp->f_flags & O_NDELAY)) {
1549 rc = -ENOMEDIUM; 1554 rc = -ENOMEDIUM;
1550 goto err_open; 1555 goto err_open;
1551 } 1556 }
1552 1557
1553 if (sc->readonly && (filp->f_mode & FMODE_WRITE)) { 1558 if (lun->readonly && (filp->f_mode & FMODE_WRITE)) {
1554 rc = -EROFS; 1559 rc = -EROFS;
1555 goto err_open; 1560 goto err_open;
1556 } 1561 }
@@ -1567,7 +1572,8 @@ err_open:
1567static int ub_bd_release(struct inode *inode, struct file *filp) 1572static int ub_bd_release(struct inode *inode, struct file *filp)
1568{ 1573{
1569 struct gendisk *disk = inode->i_bdev->bd_disk; 1574 struct gendisk *disk = inode->i_bdev->bd_disk;
1570 struct ub_dev *sc = disk->private_data; 1575 struct ub_lun *lun = disk->private_data;
1576 struct ub_dev *sc = lun->udev;
1571 1577
1572 ub_put(sc); 1578 ub_put(sc);
1573 return 0; 1579 return 0;
@@ -1597,20 +1603,14 @@ static int ub_bd_ioctl(struct inode *inode, struct file *filp,
1597 */ 1603 */
1598static int ub_bd_revalidate(struct gendisk *disk) 1604static int ub_bd_revalidate(struct gendisk *disk)
1599{ 1605{
1600 struct ub_dev *sc = disk->private_data; 1606 struct ub_lun *lun = disk->private_data;
1601 1607
1602 ub_revalidate(sc); 1608 ub_revalidate(lun->udev, lun);
1603 /* This is pretty much a long term P3 */
1604 if (!atomic_read(&sc->poison)) { /* Cover sc->dev */
1605 printk(KERN_INFO "%s: device %u capacity nsec %ld bsize %u\n",
1606 sc->name, sc->dev->devnum,
1607 sc->capacity.nsec, sc->capacity.bsize);
1608 }
1609 1609
1610 /* XXX Support sector size switching like in sr.c */ 1610 /* XXX Support sector size switching like in sr.c */
1611 blk_queue_hardsect_size(disk->queue, sc->capacity.bsize); 1611 blk_queue_hardsect_size(disk->queue, lun->capacity.bsize);
1612 set_capacity(disk, sc->capacity.nsec); 1612 set_capacity(disk, lun->capacity.nsec);
1613 // set_disk_ro(sdkp->disk, sc->readonly); 1613 // set_disk_ro(sdkp->disk, lun->readonly);
1614 1614
1615 return 0; 1615 return 0;
1616} 1616}
@@ -1626,9 +1626,9 @@ static int ub_bd_revalidate(struct gendisk *disk)
1626 */ 1626 */
1627static int ub_bd_media_changed(struct gendisk *disk) 1627static int ub_bd_media_changed(struct gendisk *disk)
1628{ 1628{
1629 struct ub_dev *sc = disk->private_data; 1629 struct ub_lun *lun = disk->private_data;
1630 1630
1631 if (!sc->removable) 1631 if (!lun->removable)
1632 return 0; 1632 return 0;
1633 1633
1634 /* 1634 /*
@@ -1640,12 +1640,12 @@ static int ub_bd_media_changed(struct gendisk *disk)
1640 * will fail, then block layer discards the data. Since we never 1640 * will fail, then block layer discards the data. Since we never
1641 * spin drives up, such devices simply cannot be used with ub anyway. 1641 * spin drives up, such devices simply cannot be used with ub anyway.
1642 */ 1642 */
1643 if (ub_sync_tur(sc) != 0) { 1643 if (ub_sync_tur(lun->udev, lun) != 0) {
1644 sc->changed = 1; 1644 lun->changed = 1;
1645 return 1; 1645 return 1;
1646 } 1646 }
1647 1647
1648 return sc->changed; 1648 return lun->changed;
1649} 1649}
1650 1650
1651static struct block_device_operations ub_bd_fops = { 1651static struct block_device_operations ub_bd_fops = {
@@ -1669,7 +1669,7 @@ static void ub_probe_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1669/* 1669/*
1670 * Test if the device has a check condition on it, synchronously. 1670 * Test if the device has a check condition on it, synchronously.
1671 */ 1671 */
1672static int ub_sync_tur(struct ub_dev *sc) 1672static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun)
1673{ 1673{
1674 struct ub_scsi_cmd *cmd; 1674 struct ub_scsi_cmd *cmd;
1675 enum { ALLOC_SIZE = sizeof(struct ub_scsi_cmd) }; 1675 enum { ALLOC_SIZE = sizeof(struct ub_scsi_cmd) };
@@ -1688,6 +1688,7 @@ static int ub_sync_tur(struct ub_dev *sc)
1688 cmd->cdb_len = 6; 1688 cmd->cdb_len = 6;
1689 cmd->dir = UB_DIR_NONE; 1689 cmd->dir = UB_DIR_NONE;
1690 cmd->state = UB_CMDST_INIT; 1690 cmd->state = UB_CMDST_INIT;
1691 cmd->lun = lun; /* This may be NULL, but that's ok */
1691 cmd->done = ub_probe_done; 1692 cmd->done = ub_probe_done;
1692 cmd->back = &compl; 1693 cmd->back = &compl;
1693 1694
@@ -1718,7 +1719,8 @@ err_alloc:
1718/* 1719/*
1719 * Read the SCSI capacity synchronously (for probing). 1720 * Read the SCSI capacity synchronously (for probing).
1720 */ 1721 */
1721static int ub_sync_read_cap(struct ub_dev *sc, struct ub_capacity *ret) 1722static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
1723 struct ub_capacity *ret)
1722{ 1724{
1723 struct ub_scsi_cmd *cmd; 1725 struct ub_scsi_cmd *cmd;
1724 char *p; 1726 char *p;
@@ -1743,6 +1745,7 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_capacity *ret)
1743 cmd->state = UB_CMDST_INIT; 1745 cmd->state = UB_CMDST_INIT;
1744 cmd->data = p; 1746 cmd->data = p;
1745 cmd->len = 8; 1747 cmd->len = 8;
1748 cmd->lun = lun;
1746 cmd->done = ub_probe_done; 1749 cmd->done = ub_probe_done;
1747 cmd->back = &compl; 1750 cmd->back = &compl;
1748 1751
@@ -1812,6 +1815,90 @@ static void ub_probe_timeout(unsigned long arg)
1812} 1815}
1813 1816
1814/* 1817/*
1818 * Get number of LUNs by the way of Bulk GetMaxLUN command.
1819 */
1820static int ub_sync_getmaxlun(struct ub_dev *sc)
1821{
1822 int ifnum = sc->intf->cur_altsetting->desc.bInterfaceNumber;
1823 unsigned char *p;
1824 enum { ALLOC_SIZE = 1 };
1825 struct usb_ctrlrequest *cr;
1826 struct completion compl;
1827 struct timer_list timer;
1828 int nluns;
1829 int rc;
1830
1831 init_completion(&compl);
1832
1833 rc = -ENOMEM;
1834 if ((p = kmalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL)
1835 goto err_alloc;
1836 *p = 55;
1837
1838 cr = &sc->work_cr;
1839 cr->bRequestType = USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
1840 cr->bRequest = US_BULK_GET_MAX_LUN;
1841 cr->wValue = cpu_to_le16(0);
1842 cr->wIndex = cpu_to_le16(ifnum);
1843 cr->wLength = cpu_to_le16(1);
1844
1845 usb_fill_control_urb(&sc->work_urb, sc->dev, sc->recv_ctrl_pipe,
1846 (unsigned char*) cr, p, 1, ub_probe_urb_complete, &compl);
1847 sc->work_urb.transfer_flags = 0;
1848 sc->work_urb.actual_length = 0;
1849 sc->work_urb.error_count = 0;
1850 sc->work_urb.status = 0;
1851
1852 if ((rc = usb_submit_urb(&sc->work_urb, GFP_KERNEL)) != 0) {
1853 if (rc == -EPIPE) {
1854 printk("%s: Stall at GetMaxLUN, using 1 LUN\n",
1855 sc->name); /* P3 */
1856 } else {
1857 printk(KERN_WARNING
1858 "%s: Unable to submit GetMaxLUN (%d)\n",
1859 sc->name, rc);
1860 }
1861 goto err_submit;
1862 }
1863
1864 init_timer(&timer);
1865 timer.function = ub_probe_timeout;
1866 timer.data = (unsigned long) &compl;
1867 timer.expires = jiffies + UB_CTRL_TIMEOUT;
1868 add_timer(&timer);
1869
1870 wait_for_completion(&compl);
1871
1872 del_timer_sync(&timer);
1873 usb_kill_urb(&sc->work_urb);
1874
1875 if (sc->work_urb.actual_length != 1) {
1876 printk("%s: GetMaxLUN returned %d bytes\n", sc->name,
1877 sc->work_urb.actual_length); /* P3 */
1878 nluns = 0;
1879 } else {
1880 if ((nluns = *p) == 55) {
1881 nluns = 0;
1882 } else {
1883 /* GetMaxLUN returns the maximum LUN number */
1884 nluns += 1;
1885 if (nluns > UB_MAX_LUNS)
1886 nluns = UB_MAX_LUNS;
1887 }
1888 printk("%s: GetMaxLUN returned %d, using %d LUNs\n", sc->name,
1889 *p, nluns); /* P3 */
1890 }
1891
1892 kfree(p);
1893 return nluns;
1894
1895err_submit:
1896 kfree(p);
1897err_alloc:
1898 return rc;
1899}
1900
1901/*
1815 * Clear initial stalls. 1902 * Clear initial stalls.
1816 */ 1903 */
1817static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe) 1904static int ub_probe_clear_stall(struct ub_dev *sc, int stalled_pipe)
@@ -1897,8 +1984,8 @@ static int ub_get_pipes(struct ub_dev *sc, struct usb_device *dev,
1897 } 1984 }
1898 1985
1899 if (ep_in == NULL || ep_out == NULL) { 1986 if (ep_in == NULL || ep_out == NULL) {
1900 printk(KERN_NOTICE "%s: device %u failed endpoint check\n", 1987 printk(KERN_NOTICE "%s: failed endpoint check\n",
1901 sc->name, sc->dev->devnum); 1988 sc->name);
1902 return -EIO; 1989 return -EIO;
1903 } 1990 }
1904 1991
@@ -1921,8 +2008,7 @@ static int ub_probe(struct usb_interface *intf,
1921 const struct usb_device_id *dev_id) 2008 const struct usb_device_id *dev_id)
1922{ 2009{
1923 struct ub_dev *sc; 2010 struct ub_dev *sc;
1924 request_queue_t *q; 2011 int nluns;
1925 struct gendisk *disk;
1926 int rc; 2012 int rc;
1927 int i; 2013 int i;
1928 2014
@@ -1931,6 +2017,7 @@ static int ub_probe(struct usb_interface *intf,
1931 goto err_core; 2017 goto err_core;
1932 memset(sc, 0, sizeof(struct ub_dev)); 2018 memset(sc, 0, sizeof(struct ub_dev));
1933 spin_lock_init(&sc->lock); 2019 spin_lock_init(&sc->lock);
2020 INIT_LIST_HEAD(&sc->luns);
1934 usb_init_urb(&sc->work_urb); 2021 usb_init_urb(&sc->work_urb);
1935 tasklet_init(&sc->tasklet, ub_scsi_action, (unsigned long)sc); 2022 tasklet_init(&sc->tasklet, ub_scsi_action, (unsigned long)sc);
1936 atomic_set(&sc->poison, 0); 2023 atomic_set(&sc->poison, 0);
@@ -1942,19 +2029,16 @@ static int ub_probe(struct usb_interface *intf,
1942 ub_init_completion(&sc->work_done); 2029 ub_init_completion(&sc->work_done);
1943 sc->work_done.done = 1; /* A little yuk, but oh well... */ 2030 sc->work_done.done = 1; /* A little yuk, but oh well... */
1944 2031
1945 rc = -ENOSR;
1946 if ((sc->id = ub_id_get()) == -1)
1947 goto err_id;
1948 snprintf(sc->name, 8, DRV_NAME "%c", sc->id + 'a');
1949
1950 sc->dev = interface_to_usbdev(intf); 2032 sc->dev = interface_to_usbdev(intf);
1951 sc->intf = intf; 2033 sc->intf = intf;
1952 // sc->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 2034 // sc->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
1953
1954 usb_set_intfdata(intf, sc); 2035 usb_set_intfdata(intf, sc);
1955 usb_get_dev(sc->dev); 2036 usb_get_dev(sc->dev);
1956 // usb_get_intf(sc->intf); /* Do we need this? */ 2037 // usb_get_intf(sc->intf); /* Do we need this? */
1957 2038
2039 snprintf(sc->name, 12, DRV_NAME "(%d.%d)",
2040 sc->dev->bus->busnum, sc->dev->devnum);
2041
1958 /* XXX Verify that we can handle the device (from descriptors) */ 2042 /* XXX Verify that we can handle the device (from descriptors) */
1959 2043
1960 ub_get_pipes(sc, sc->dev, intf); 2044 ub_get_pipes(sc, sc->dev, intf);
@@ -1992,35 +2076,88 @@ static int ub_probe(struct usb_interface *intf,
1992 * In any case it's not our business how revaliadation is implemented. 2076 * In any case it's not our business how revaliadation is implemented.
1993 */ 2077 */
1994 for (i = 0; i < 3; i++) { /* Retries for benh's key */ 2078 for (i = 0; i < 3; i++) { /* Retries for benh's key */
1995 if ((rc = ub_sync_tur(sc)) <= 0) break; 2079 if ((rc = ub_sync_tur(sc, NULL)) <= 0) break;
1996 if (rc != 0x6) break; 2080 if (rc != 0x6) break;
1997 msleep(10); 2081 msleep(10);
1998 } 2082 }
1999 2083
2000 sc->removable = 1; /* XXX Query this from the device */ 2084 nluns = 1;
2001 sc->changed = 1; /* ub_revalidate clears only */ 2085 for (i = 0; i < 3; i++) {
2002 sc->first_open = 1; 2086 if ((rc = ub_sync_getmaxlun(sc)) < 0) {
2087 /*
2088 * Some devices (i.e. Iomega Zip100) need this --
2089 * apparently the bulk pipes get STALLed when the
2090 * GetMaxLUN request is processed.
2091 * XXX I have a ZIP-100, verify it does this.
2092 */
2093 if (rc == -EPIPE) {
2094 ub_probe_clear_stall(sc, sc->recv_bulk_pipe);
2095 ub_probe_clear_stall(sc, sc->send_bulk_pipe);
2096 }
2097 break;
2098 }
2099 if (rc != 0) {
2100 nluns = rc;
2101 break;
2102 }
2103 msleep(100);
2104 }
2003 2105
2004 ub_revalidate(sc); 2106 for (i = 0; i < nluns; i++) {
2005 /* This is pretty much a long term P3 */ 2107 ub_probe_lun(sc, i);
2006 printk(KERN_INFO "%s: device %u capacity nsec %ld bsize %u\n", 2108 }
2007 sc->name, sc->dev->devnum, sc->capacity.nsec, sc->capacity.bsize); 2109 return 0;
2110
2111 /* device_remove_file(&sc->intf->dev, &dev_attr_diag); */
2112err_diag:
2113 usb_set_intfdata(intf, NULL);
2114 // usb_put_intf(sc->intf);
2115 usb_put_dev(sc->dev);
2116 kfree(sc);
2117err_core:
2118 return rc;
2119}
2120
2121static int ub_probe_lun(struct ub_dev *sc, int lnum)
2122{
2123 struct ub_lun *lun;
2124 request_queue_t *q;
2125 struct gendisk *disk;
2126 int rc;
2127
2128 rc = -ENOMEM;
2129 if ((lun = kmalloc(sizeof(struct ub_lun), GFP_KERNEL)) == NULL)
2130 goto err_alloc;
2131 memset(lun, 0, sizeof(struct ub_lun));
2132 lun->num = lnum;
2133
2134 rc = -ENOSR;
2135 if ((lun->id = ub_id_get()) == -1)
2136 goto err_id;
2137
2138 lun->udev = sc;
2139 list_add(&lun->link, &sc->luns);
2140
2141 snprintf(lun->name, 16, DRV_NAME "%c(%d.%d.%d)",
2142 lun->id + 'a', sc->dev->bus->busnum, sc->dev->devnum, lun->num);
2143
2144 lun->removable = 1; /* XXX Query this from the device */
2145 lun->changed = 1; /* ub_revalidate clears only */
2146 lun->first_open = 1;
2147 ub_revalidate(sc, lun);
2008 2148
2009 /*
2010 * Just one disk per sc currently, but maybe more.
2011 */
2012 rc = -ENOMEM; 2149 rc = -ENOMEM;
2013 if ((disk = alloc_disk(UB_MINORS_PER_MAJOR)) == NULL) 2150 if ((disk = alloc_disk(UB_MINORS_PER_MAJOR)) == NULL)
2014 goto err_diskalloc; 2151 goto err_diskalloc;
2015 2152
2016 sc->disk = disk; 2153 lun->disk = disk;
2017 sprintf(disk->disk_name, DRV_NAME "%c", sc->id + 'a'); 2154 sprintf(disk->disk_name, DRV_NAME "%c", lun->id + 'a');
2018 sprintf(disk->devfs_name, DEVFS_NAME "/%c", sc->id + 'a'); 2155 sprintf(disk->devfs_name, DEVFS_NAME "/%c", lun->id + 'a');
2019 disk->major = UB_MAJOR; 2156 disk->major = UB_MAJOR;
2020 disk->first_minor = sc->id * UB_MINORS_PER_MAJOR; 2157 disk->first_minor = lun->id * UB_MINORS_PER_MAJOR;
2021 disk->fops = &ub_bd_fops; 2158 disk->fops = &ub_bd_fops;
2022 disk->private_data = sc; 2159 disk->private_data = lun;
2023 disk->driverfs_dev = &intf->dev; 2160 disk->driverfs_dev = &sc->intf->dev; /* XXX Many to one ok? */
2024 2161
2025 rc = -ENOMEM; 2162 rc = -ENOMEM;
2026 if ((q = blk_init_queue(ub_bd_rq_fn, &sc->lock)) == NULL) 2163 if ((q = blk_init_queue(ub_bd_rq_fn, &sc->lock)) == NULL)
@@ -2028,28 +2165,17 @@ static int ub_probe(struct usb_interface *intf,
2028 2165
2029 disk->queue = q; 2166 disk->queue = q;
2030 2167
2031 // blk_queue_bounce_limit(q, hba[i]->pdev->dma_mask); 2168 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH);
2032 blk_queue_max_hw_segments(q, UB_MAX_REQ_SG); 2169 blk_queue_max_hw_segments(q, UB_MAX_REQ_SG);
2033 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG); 2170 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG);
2034 // blk_queue_segment_boundary(q, CARM_SG_BOUNDARY); 2171 blk_queue_segment_boundary(q, 0xffffffff); /* Dubious. */
2035 blk_queue_max_sectors(q, UB_MAX_SECTORS); 2172 blk_queue_max_sectors(q, UB_MAX_SECTORS);
2036 blk_queue_hardsect_size(q, sc->capacity.bsize); 2173 blk_queue_hardsect_size(q, lun->capacity.bsize);
2037
2038 /*
2039 * This is a serious infraction, caused by a deficiency in the
2040 * USB sg interface (usb_sg_wait()). We plan to remove this once
2041 * we get mileage on the driver and can justify a change to USB API.
2042 * See blk_queue_bounce_limit() to understand this part.
2043 *
2044 * XXX And I still need to be aware of the DMA mask in the HC.
2045 */
2046 q->bounce_pfn = blk_max_low_pfn;
2047 q->bounce_gfp = GFP_NOIO;
2048 2174
2049 q->queuedata = sc; 2175 q->queuedata = lun;
2050 2176
2051 set_capacity(disk, sc->capacity.nsec); 2177 set_capacity(disk, lun->capacity.nsec);
2052 if (sc->removable) 2178 if (lun->removable)
2053 disk->flags |= GENHD_FL_REMOVABLE; 2179 disk->flags |= GENHD_FL_REMOVABLE;
2054 2180
2055 add_disk(disk); 2181 add_disk(disk);
@@ -2059,22 +2185,20 @@ static int ub_probe(struct usb_interface *intf,
2059err_blkqinit: 2185err_blkqinit:
2060 put_disk(disk); 2186 put_disk(disk);
2061err_diskalloc: 2187err_diskalloc:
2062 device_remove_file(&sc->intf->dev, &dev_attr_diag); 2188 list_del(&lun->link);
2063err_diag: 2189 ub_id_put(lun->id);
2064 usb_set_intfdata(intf, NULL);
2065 // usb_put_intf(sc->intf);
2066 usb_put_dev(sc->dev);
2067 ub_id_put(sc->id);
2068err_id: 2190err_id:
2069 kfree(sc); 2191 kfree(lun);
2070err_core: 2192err_alloc:
2071 return rc; 2193 return rc;
2072} 2194}
2073 2195
2074static void ub_disconnect(struct usb_interface *intf) 2196static void ub_disconnect(struct usb_interface *intf)
2075{ 2197{
2076 struct ub_dev *sc = usb_get_intfdata(intf); 2198 struct ub_dev *sc = usb_get_intfdata(intf);
2077 struct gendisk *disk = sc->disk; 2199 struct list_head *p;
2200 struct ub_lun *lun;
2201 struct gendisk *disk;
2078 unsigned long flags; 2202 unsigned long flags;
2079 2203
2080 /* 2204 /*
@@ -2124,14 +2248,18 @@ static void ub_disconnect(struct usb_interface *intf)
2124 /* 2248 /*
2125 * Unregister the upper layer. 2249 * Unregister the upper layer.
2126 */ 2250 */
2127 if (disk->flags & GENHD_FL_UP) 2251 list_for_each (p, &sc->luns) {
2128 del_gendisk(disk); 2252 lun = list_entry(p, struct ub_lun, link);
2129 /* 2253 disk = lun->disk;
2130 * I wish I could do: 2254 if (disk->flags & GENHD_FL_UP)
2131 * set_bit(QUEUE_FLAG_DEAD, &q->queue_flags); 2255 del_gendisk(disk);
2132 * As it is, we rely on our internal poisoning and let 2256 /*
2133 * the upper levels to spin furiously failing all the I/O. 2257 * I wish I could do:
2134 */ 2258 * set_bit(QUEUE_FLAG_DEAD, &q->queue_flags);
2259 * As it is, we rely on our internal poisoning and let
2260 * the upper levels to spin furiously failing all the I/O.
2261 */
2262 }
2135 2263
2136 /* 2264 /*
2137 * Taking a lock on a structure which is about to be freed 2265 * Taking a lock on a structure which is about to be freed
@@ -2182,8 +2310,8 @@ static int __init ub_init(void)
2182{ 2310{
2183 int rc; 2311 int rc;
2184 2312
2185 /* P3 */ printk("ub: sizeof ub_scsi_cmd %zu ub_dev %zu\n", 2313 /* P3 */ printk("ub: sizeof ub_scsi_cmd %zu ub_dev %zu ub_lun %zu\n",
2186 sizeof(struct ub_scsi_cmd), sizeof(struct ub_dev)); 2314 sizeof(struct ub_scsi_cmd), sizeof(struct ub_dev), sizeof(struct ub_lun));
2187 2315
2188 if ((rc = register_blkdev(UB_MAJOR, DRV_NAME)) != 0) 2316 if ((rc = register_blkdev(UB_MAJOR, DRV_NAME)) != 0)
2189 goto err_regblkdev; 2317 goto err_regblkdev;
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index ad9c11391d81..c1fe013c64f3 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -278,6 +278,8 @@ void agp3_generic_cleanup(void);
278#define AGP_GENERIC_SIZES_ENTRIES 11 278#define AGP_GENERIC_SIZES_ENTRIES 11
279extern struct aper_size_info_16 agp3_generic_sizes[]; 279extern struct aper_size_info_16 agp3_generic_sizes[];
280 280
281#define virt_to_gart(x) (phys_to_gart(virt_to_phys(x)))
282#define gart_to_virt(x) (phys_to_virt(gart_to_phys(x)))
281 283
282extern int agp_off; 284extern int agp_off;
283extern int agp_try_unsupported_boot; 285extern int agp_try_unsupported_boot;
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index 0212febda654..9c9c9c2247ce 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -150,7 +150,7 @@ static void *m1541_alloc_page(struct agp_bridge_data *bridge)
150 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp); 150 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
151 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, 151 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
152 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) | 152 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
153 virt_to_phys(addr)) | ALI_CACHE_FLUSH_EN )); 153 virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN ));
154 return addr; 154 return addr;
155} 155}
156 156
@@ -174,7 +174,7 @@ static void m1541_destroy_page(void * addr)
174 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp); 174 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
175 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, 175 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
176 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) | 176 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
177 virt_to_phys(addr)) | ALI_CACHE_FLUSH_EN)); 177 virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN));
178 agp_generic_destroy_page(addr); 178 agp_generic_destroy_page(addr);
179} 179}
180 180
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index e62a3c2c44a9..3a41672e4d66 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -43,7 +43,7 @@ static int amd_create_page_map(struct amd_page_map *page_map)
43 43
44 SetPageReserved(virt_to_page(page_map->real)); 44 SetPageReserved(virt_to_page(page_map->real));
45 global_cache_flush(); 45 global_cache_flush();
46 page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real), 46 page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real),
47 PAGE_SIZE); 47 PAGE_SIZE);
48 if (page_map->remapped == NULL) { 48 if (page_map->remapped == NULL) {
49 ClearPageReserved(virt_to_page(page_map->real)); 49 ClearPageReserved(virt_to_page(page_map->real));
@@ -154,7 +154,7 @@ static int amd_create_gatt_table(struct agp_bridge_data *bridge)
154 154
155 agp_bridge->gatt_table_real = (u32 *)page_dir.real; 155 agp_bridge->gatt_table_real = (u32 *)page_dir.real;
156 agp_bridge->gatt_table = (u32 __iomem *)page_dir.remapped; 156 agp_bridge->gatt_table = (u32 __iomem *)page_dir.remapped;
157 agp_bridge->gatt_bus_addr = virt_to_phys(page_dir.real); 157 agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real);
158 158
159 /* Get the address for the gart region. 159 /* Get the address for the gart region.
160 * This is a bus address even on the alpha, b/c its 160 * This is a bus address even on the alpha, b/c its
@@ -167,7 +167,7 @@ static int amd_create_gatt_table(struct agp_bridge_data *bridge)
167 167
168 /* Calculate the agp offset */ 168 /* Calculate the agp offset */
169 for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) { 169 for (i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
170 writel(virt_to_phys(amd_irongate_private.gatt_pages[i]->real) | 1, 170 writel(virt_to_gart(amd_irongate_private.gatt_pages[i]->real) | 1,
171 page_dir.remapped+GET_PAGE_DIR_OFF(addr)); 171 page_dir.remapped+GET_PAGE_DIR_OFF(addr));
172 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */ 172 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
173 } 173 }
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 399c042f68f0..1407945a5892 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -219,7 +219,7 @@ static struct aper_size_info_32 amd_8151_sizes[7] =
219 219
220static int amd_8151_configure(void) 220static int amd_8151_configure(void)
221{ 221{
222 unsigned long gatt_bus = virt_to_phys(agp_bridge->gatt_table_real); 222 unsigned long gatt_bus = virt_to_gart(agp_bridge->gatt_table_real);
223 223
224 /* Configure AGP regs in each x86-64 host bridge. */ 224 /* Configure AGP regs in each x86-64 host bridge. */
225 for_each_nb() { 225 for_each_nb() {
@@ -591,7 +591,7 @@ static void __devexit agp_amd64_remove(struct pci_dev *pdev)
591{ 591{
592 struct agp_bridge_data *bridge = pci_get_drvdata(pdev); 592 struct agp_bridge_data *bridge = pci_get_drvdata(pdev);
593 593
594 release_mem_region(virt_to_phys(bridge->gatt_table_real), 594 release_mem_region(virt_to_gart(bridge->gatt_table_real),
595 amd64_aperture_sizes[bridge->aperture_size_idx].size); 595 amd64_aperture_sizes[bridge->aperture_size_idx].size);
596 agp_remove_bridge(bridge); 596 agp_remove_bridge(bridge);
597 agp_put_bridge(bridge); 597 agp_put_bridge(bridge);
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index a65f8827c283..e572ced9100a 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -61,7 +61,7 @@ static int ati_create_page_map(ati_page_map *page_map)
61 61
62 SetPageReserved(virt_to_page(page_map->real)); 62 SetPageReserved(virt_to_page(page_map->real));
63 err = map_page_into_agp(virt_to_page(page_map->real)); 63 err = map_page_into_agp(virt_to_page(page_map->real));
64 page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real), 64 page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real),
65 PAGE_SIZE); 65 PAGE_SIZE);
66 if (page_map->remapped == NULL || err) { 66 if (page_map->remapped == NULL || err) {
67 ClearPageReserved(virt_to_page(page_map->real)); 67 ClearPageReserved(virt_to_page(page_map->real));
@@ -343,7 +343,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
343 343
344 agp_bridge->gatt_table_real = (u32 *)page_dir.real; 344 agp_bridge->gatt_table_real = (u32 *)page_dir.real;
345 agp_bridge->gatt_table = (u32 __iomem *) page_dir.remapped; 345 agp_bridge->gatt_table = (u32 __iomem *) page_dir.remapped;
346 agp_bridge->gatt_bus_addr = virt_to_bus(page_dir.real); 346 agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real);
347 347
348 /* Write out the size register */ 348 /* Write out the size register */
349 current_size = A_SIZE_LVL2(agp_bridge->current_size); 349 current_size = A_SIZE_LVL2(agp_bridge->current_size);
@@ -373,7 +373,7 @@ static int ati_create_gatt_table(struct agp_bridge_data *bridge)
373 373
374 /* Calculate the agp offset */ 374 /* Calculate the agp offset */
375 for(i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) { 375 for(i = 0; i < value->num_entries / 1024; i++, addr += 0x00400000) {
376 writel(virt_to_bus(ati_generic_private.gatt_pages[i]->real) | 1, 376 writel(virt_to_gart(ati_generic_private.gatt_pages[i]->real) | 1,
377 page_dir.remapped+GET_PAGE_DIR_OFF(addr)); 377 page_dir.remapped+GET_PAGE_DIR_OFF(addr));
378 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */ 378 readl(page_dir.remapped+GET_PAGE_DIR_OFF(addr)); /* PCI Posting. */
379 } 379 }
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 2f3dfb63bdc6..4d4e602fdc7e 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -148,7 +148,7 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
148 return -ENOMEM; 148 return -ENOMEM;
149 } 149 }
150 150
151 bridge->scratch_page_real = virt_to_phys(addr); 151 bridge->scratch_page_real = virt_to_gart(addr);
152 bridge->scratch_page = 152 bridge->scratch_page =
153 bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0); 153 bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0);
154 } 154 }
@@ -189,7 +189,7 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
189err_out: 189err_out:
190 if (bridge->driver->needs_scratch_page) 190 if (bridge->driver->needs_scratch_page)
191 bridge->driver->agp_destroy_page( 191 bridge->driver->agp_destroy_page(
192 phys_to_virt(bridge->scratch_page_real)); 192 gart_to_virt(bridge->scratch_page_real));
193 if (got_gatt) 193 if (got_gatt)
194 bridge->driver->free_gatt_table(bridge); 194 bridge->driver->free_gatt_table(bridge);
195 if (got_keylist) { 195 if (got_keylist) {
@@ -214,7 +214,7 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
214 if (bridge->driver->agp_destroy_page && 214 if (bridge->driver->agp_destroy_page &&
215 bridge->driver->needs_scratch_page) 215 bridge->driver->needs_scratch_page)
216 bridge->driver->agp_destroy_page( 216 bridge->driver->agp_destroy_page(
217 phys_to_virt(bridge->scratch_page_real)); 217 gart_to_virt(bridge->scratch_page_real));
218} 218}
219 219
220/* When we remove the global variable agp_bridge from all drivers 220/* When we remove the global variable agp_bridge from all drivers
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index 1383c3165ea1..ac19fdcd21c1 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -219,7 +219,7 @@ static int efficeon_create_gatt_table(struct agp_bridge_data *bridge)
219 219
220 efficeon_private.l1_table[index] = page; 220 efficeon_private.l1_table[index] = page;
221 221
222 value = __pa(page) | pati | present | index; 222 value = virt_to_gart(page) | pati | present | index;
223 223
224 pci_write_config_dword(agp_bridge->dev, 224 pci_write_config_dword(agp_bridge->dev,
225 EFFICEON_ATTPAGE, value); 225 EFFICEON_ATTPAGE, value);
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index c321a924e38a..f0079e991bdc 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -153,7 +153,7 @@ void agp_free_memory(struct agp_memory *curr)
153 } 153 }
154 if (curr->page_count != 0) { 154 if (curr->page_count != 0) {
155 for (i = 0; i < curr->page_count; i++) { 155 for (i = 0; i < curr->page_count; i++) {
156 curr->bridge->driver->agp_destroy_page(phys_to_virt(curr->memory[i])); 156 curr->bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[i]));
157 } 157 }
158 } 158 }
159 agp_free_key(curr->key); 159 agp_free_key(curr->key);
@@ -209,7 +209,7 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
209 agp_free_memory(new); 209 agp_free_memory(new);
210 return NULL; 210 return NULL;
211 } 211 }
212 new->memory[i] = virt_to_phys(addr); 212 new->memory[i] = virt_to_gart(addr);
213 new->page_count++; 213 new->page_count++;
214 } 214 }
215 new->bridge = bridge; 215 new->bridge = bridge;
@@ -295,19 +295,6 @@ int agp_num_entries(void)
295EXPORT_SYMBOL_GPL(agp_num_entries); 295EXPORT_SYMBOL_GPL(agp_num_entries);
296 296
297 297
298static int check_bridge_mode(struct pci_dev *dev)
299{
300 u32 agp3;
301 u8 cap_ptr;
302
303 cap_ptr = pci_find_capability(dev, PCI_CAP_ID_AGP);
304 pci_read_config_dword(dev, cap_ptr+AGPSTAT, &agp3);
305 if (agp3 & AGPSTAT_MODE_3_0)
306 return 1;
307 return 0;
308}
309
310
311/** 298/**
312 * agp_copy_info - copy bridge state information 299 * agp_copy_info - copy bridge state information
313 * 300 *
@@ -328,7 +315,7 @@ int agp_copy_info(struct agp_bridge_data *bridge, struct agp_kern_info *info)
328 info->version.minor = bridge->version->minor; 315 info->version.minor = bridge->version->minor;
329 info->chipset = SUPPORTED; 316 info->chipset = SUPPORTED;
330 info->device = bridge->dev; 317 info->device = bridge->dev;
331 if (check_bridge_mode(bridge->dev)) 318 if (bridge->mode & AGPSTAT_MODE_3_0)
332 info->mode = bridge->mode & ~AGP3_RESERVED_MASK; 319 info->mode = bridge->mode & ~AGP3_RESERVED_MASK;
333 else 320 else
334 info->mode = bridge->mode & ~AGP2_RESERVED_MASK; 321 info->mode = bridge->mode & ~AGP2_RESERVED_MASK;
@@ -661,7 +648,7 @@ u32 agp_collect_device_status(struct agp_bridge_data *bridge, u32 requested_mode
661 bridge_agpstat &= ~AGPSTAT_FW; 648 bridge_agpstat &= ~AGPSTAT_FW;
662 649
663 /* Check to see if we are operating in 3.0 mode */ 650 /* Check to see if we are operating in 3.0 mode */
664 if (check_bridge_mode(agp_bridge->dev)) 651 if (agp_bridge->mode & AGPSTAT_MODE_3_0)
665 agp_v3_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat); 652 agp_v3_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
666 else 653 else
667 agp_v2_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat); 654 agp_v2_parse_one(&requested_mode, &bridge_agpstat, &vga_agpstat);
@@ -732,7 +719,7 @@ void agp_generic_enable(struct agp_bridge_data *bridge, u32 requested_mode)
732 719
733 /* Do AGP version specific frobbing. */ 720 /* Do AGP version specific frobbing. */
734 if (bridge->major_version >= 3) { 721 if (bridge->major_version >= 3) {
735 if (check_bridge_mode(bridge->dev)) { 722 if (bridge->mode & AGPSTAT_MODE_3_0) {
736 /* If we have 3.5, we can do the isoch stuff. */ 723 /* If we have 3.5, we can do the isoch stuff. */
737 if (bridge->minor_version >= 5) 724 if (bridge->minor_version >= 5)
738 agp_3_5_enable(bridge); 725 agp_3_5_enable(bridge);
@@ -806,8 +793,7 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
806 break; 793 break;
807 } 794 }
808 795
809 table = (char *) __get_free_pages(GFP_KERNEL, 796 table = alloc_gatt_pages(page_order);
810 page_order);
811 797
812 if (table == NULL) { 798 if (table == NULL) {
813 i++; 799 i++;
@@ -838,7 +824,7 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
838 size = ((struct aper_size_info_fixed *) temp)->size; 824 size = ((struct aper_size_info_fixed *) temp)->size;
839 page_order = ((struct aper_size_info_fixed *) temp)->page_order; 825 page_order = ((struct aper_size_info_fixed *) temp)->page_order;
840 num_entries = ((struct aper_size_info_fixed *) temp)->num_entries; 826 num_entries = ((struct aper_size_info_fixed *) temp)->num_entries;
841 table = (char *) __get_free_pages(GFP_KERNEL, page_order); 827 table = alloc_gatt_pages(page_order);
842 } 828 }
843 829
844 if (table == NULL) 830 if (table == NULL)
@@ -853,7 +839,7 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
853 agp_gatt_table = (void *)table; 839 agp_gatt_table = (void *)table;
854 840
855 bridge->driver->cache_flush(); 841 bridge->driver->cache_flush();
856 bridge->gatt_table = ioremap_nocache(virt_to_phys(table), 842 bridge->gatt_table = ioremap_nocache(virt_to_gart(table),
857 (PAGE_SIZE * (1 << page_order))); 843 (PAGE_SIZE * (1 << page_order)));
858 bridge->driver->cache_flush(); 844 bridge->driver->cache_flush();
859 845
@@ -861,11 +847,11 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
861 for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) 847 for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
862 ClearPageReserved(page); 848 ClearPageReserved(page);
863 849
864 free_pages((unsigned long) table, page_order); 850 free_gatt_pages(table, page_order);
865 851
866 return -ENOMEM; 852 return -ENOMEM;
867 } 853 }
868 bridge->gatt_bus_addr = virt_to_phys(bridge->gatt_table_real); 854 bridge->gatt_bus_addr = virt_to_gart(bridge->gatt_table_real);
869 855
870 /* AK: bogus, should encode addresses > 4GB */ 856 /* AK: bogus, should encode addresses > 4GB */
871 for (i = 0; i < num_entries; i++) { 857 for (i = 0; i < num_entries; i++) {
@@ -919,7 +905,7 @@ int agp_generic_free_gatt_table(struct agp_bridge_data *bridge)
919 for (page = virt_to_page(table); page <= virt_to_page(table_end); page++) 905 for (page = virt_to_page(table); page <= virt_to_page(table_end); page++)
920 ClearPageReserved(page); 906 ClearPageReserved(page);
921 907
922 free_pages((unsigned long) bridge->gatt_table_real, page_order); 908 free_gatt_pages(bridge->gatt_table_real, page_order);
923 909
924 agp_gatt_table = NULL; 910 agp_gatt_table = NULL;
925 bridge->gatt_table = NULL; 911 bridge->gatt_table = NULL;
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index 6052bfa04c72..99762b6c19ae 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -110,7 +110,7 @@ static int __init hp_zx1_ioc_shared(void)
110 hp->gart_size = HP_ZX1_GART_SIZE; 110 hp->gart_size = HP_ZX1_GART_SIZE;
111 hp->gatt_entries = hp->gart_size / hp->io_page_size; 111 hp->gatt_entries = hp->gart_size / hp->io_page_size;
112 112
113 hp->io_pdir = phys_to_virt(readq(hp->ioc_regs+HP_ZX1_PDIR_BASE)); 113 hp->io_pdir = gart_to_virt(readq(hp->ioc_regs+HP_ZX1_PDIR_BASE));
114 hp->gatt = &hp->io_pdir[HP_ZX1_IOVA_TO_PDIR(hp->gart_base)]; 114 hp->gatt = &hp->io_pdir[HP_ZX1_IOVA_TO_PDIR(hp->gart_base)];
115 115
116 if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) { 116 if (hp->gatt[0] != HP_ZX1_SBA_IOMMU_COOKIE) {
@@ -248,7 +248,7 @@ hp_zx1_configure (void)
248 agp_bridge->mode = readl(hp->lba_regs+hp->lba_cap_offset+PCI_AGP_STATUS); 248 agp_bridge->mode = readl(hp->lba_regs+hp->lba_cap_offset+PCI_AGP_STATUS);
249 249
250 if (hp->io_pdir_owner) { 250 if (hp->io_pdir_owner) {
251 writel(virt_to_phys(hp->io_pdir), hp->ioc_regs+HP_ZX1_PDIR_BASE); 251 writel(virt_to_gart(hp->io_pdir), hp->ioc_regs+HP_ZX1_PDIR_BASE);
252 readl(hp->ioc_regs+HP_ZX1_PDIR_BASE); 252 readl(hp->ioc_regs+HP_ZX1_PDIR_BASE);
253 writel(hp->io_tlb_ps, hp->ioc_regs+HP_ZX1_TCNFG); 253 writel(hp->io_tlb_ps, hp->ioc_regs+HP_ZX1_TCNFG);
254 readl(hp->ioc_regs+HP_ZX1_TCNFG); 254 readl(hp->ioc_regs+HP_ZX1_TCNFG);
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index adbea896c0d2..94943298c03e 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -372,7 +372,7 @@ static int i460_alloc_large_page (struct lp_desc *lp)
372 } 372 }
373 memset(lp->alloced_map, 0, map_size); 373 memset(lp->alloced_map, 0, map_size);
374 374
375 lp->paddr = virt_to_phys(lpage); 375 lp->paddr = virt_to_gart(lpage);
376 lp->refcount = 0; 376 lp->refcount = 0;
377 atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp); 377 atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
378 return 0; 378 return 0;
@@ -383,7 +383,7 @@ static void i460_free_large_page (struct lp_desc *lp)
383 kfree(lp->alloced_map); 383 kfree(lp->alloced_map);
384 lp->alloced_map = NULL; 384 lp->alloced_map = NULL;
385 385
386 free_pages((unsigned long) phys_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT); 386 free_pages((unsigned long) gart_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT);
387 atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp); 387 atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
388} 388}
389 389
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 8c7d727432bb..51266d6b4d78 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -286,7 +286,7 @@ static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
286 if (new == NULL) 286 if (new == NULL)
287 return NULL; 287 return NULL;
288 288
289 new->memory[0] = virt_to_phys(addr); 289 new->memory[0] = virt_to_gart(addr);
290 if (pg_count == 4) { 290 if (pg_count == 4) {
291 /* kludge to get 4 physical pages for ARGB cursor */ 291 /* kludge to get 4 physical pages for ARGB cursor */
292 new->memory[1] = new->memory[0] + PAGE_SIZE; 292 new->memory[1] = new->memory[0] + PAGE_SIZE;
@@ -329,10 +329,10 @@ static void intel_i810_free_by_type(struct agp_memory *curr)
329 agp_free_key(curr->key); 329 agp_free_key(curr->key);
330 if(curr->type == AGP_PHYS_MEMORY) { 330 if(curr->type == AGP_PHYS_MEMORY) {
331 if (curr->page_count == 4) 331 if (curr->page_count == 4)
332 i8xx_destroy_pages(phys_to_virt(curr->memory[0])); 332 i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
333 else 333 else
334 agp_bridge->driver->agp_destroy_page( 334 agp_bridge->driver->agp_destroy_page(
335 phys_to_virt(curr->memory[0])); 335 gart_to_virt(curr->memory[0]));
336 vfree(curr->memory); 336 vfree(curr->memory);
337 } 337 }
338 kfree(curr); 338 kfree(curr);
@@ -418,7 +418,8 @@ static void intel_i830_init_gtt_entries(void)
418 case I915_GMCH_GMS_STOLEN_48M: 418 case I915_GMCH_GMS_STOLEN_48M:
419 /* Check it's really I915G */ 419 /* Check it's really I915G */
420 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || 420 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
421 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) 421 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
422 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB)
422 gtt_entries = MB(48) - KB(size); 423 gtt_entries = MB(48) - KB(size);
423 else 424 else
424 gtt_entries = 0; 425 gtt_entries = 0;
@@ -426,7 +427,8 @@ static void intel_i830_init_gtt_entries(void)
426 case I915_GMCH_GMS_STOLEN_64M: 427 case I915_GMCH_GMS_STOLEN_64M:
427 /* Check it's really I915G */ 428 /* Check it's really I915G */
428 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB || 429 if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915G_HB ||
429 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) 430 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB ||
431 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82945G_HB)
430 gtt_entries = MB(64) - KB(size); 432 gtt_entries = MB(64) - KB(size);
431 else 433 else
432 gtt_entries = 0; 434 gtt_entries = 0;
@@ -1662,6 +1664,14 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev,
1662 } 1664 }
1663 name = "915GM"; 1665 name = "915GM";
1664 break; 1666 break;
1667 case PCI_DEVICE_ID_INTEL_82945G_HB:
1668 if (find_i830(PCI_DEVICE_ID_INTEL_82945G_IG)) {
1669 bridge->driver = &intel_915_driver;
1670 } else {
1671 bridge->driver = &intel_845_driver;
1672 }
1673 name = "945G";
1674 break;
1665 case PCI_DEVICE_ID_INTEL_7505_0: 1675 case PCI_DEVICE_ID_INTEL_7505_0:
1666 bridge->driver = &intel_7505_driver; 1676 bridge->driver = &intel_7505_driver;
1667 name = "E7505"; 1677 name = "E7505";
@@ -1801,6 +1811,7 @@ static struct pci_device_id agp_intel_pci_table[] = {
1801 ID(PCI_DEVICE_ID_INTEL_7205_0), 1811 ID(PCI_DEVICE_ID_INTEL_7205_0),
1802 ID(PCI_DEVICE_ID_INTEL_82915G_HB), 1812 ID(PCI_DEVICE_ID_INTEL_82915G_HB),
1803 ID(PCI_DEVICE_ID_INTEL_82915GM_HB), 1813 ID(PCI_DEVICE_ID_INTEL_82915GM_HB),
1814 ID(PCI_DEVICE_ID_INTEL_82945G_HB),
1804 { } 1815 { }
1805}; 1816};
1806 1817
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index 4b3eda267976..d3aa159c9dec 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -133,11 +133,14 @@ static int sgi_tioca_insert_memory(struct agp_memory *mem, off_t pg_start,
133 off_t j; 133 off_t j;
134 void *temp; 134 void *temp;
135 struct agp_bridge_data *bridge; 135 struct agp_bridge_data *bridge;
136 u64 *table;
136 137
137 bridge = mem->bridge; 138 bridge = mem->bridge;
138 if (!bridge) 139 if (!bridge)
139 return -EINVAL; 140 return -EINVAL;
140 141
142 table = (u64 *)bridge->gatt_table;
143
141 temp = bridge->current_size; 144 temp = bridge->current_size;
142 145
143 switch (bridge->driver->size_type) { 146 switch (bridge->driver->size_type) {
@@ -175,7 +178,7 @@ static int sgi_tioca_insert_memory(struct agp_memory *mem, off_t pg_start,
175 j = pg_start; 178 j = pg_start;
176 179
177 while (j < (pg_start + mem->page_count)) { 180 while (j < (pg_start + mem->page_count)) {
178 if (*(bridge->gatt_table + j)) 181 if (table[j])
179 return -EBUSY; 182 return -EBUSY;
180 j++; 183 j++;
181 } 184 }
@@ -186,7 +189,7 @@ static int sgi_tioca_insert_memory(struct agp_memory *mem, off_t pg_start,
186 } 189 }
187 190
188 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 191 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
189 *(bridge->gatt_table + j) = 192 table[j] =
190 bridge->driver->mask_memory(bridge, mem->memory[i], 193 bridge->driver->mask_memory(bridge, mem->memory[i],
191 mem->type); 194 mem->type);
192 } 195 }
@@ -200,6 +203,7 @@ static int sgi_tioca_remove_memory(struct agp_memory *mem, off_t pg_start,
200{ 203{
201 size_t i; 204 size_t i;
202 struct agp_bridge_data *bridge; 205 struct agp_bridge_data *bridge;
206 u64 *table;
203 207
204 bridge = mem->bridge; 208 bridge = mem->bridge;
205 if (!bridge) 209 if (!bridge)
@@ -209,8 +213,10 @@ static int sgi_tioca_remove_memory(struct agp_memory *mem, off_t pg_start,
209 return -EINVAL; 213 return -EINVAL;
210 } 214 }
211 215
216 table = (u64 *)bridge->gatt_table;
217
212 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 218 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
213 *(bridge->gatt_table + i) = 0; 219 table[i] = 0;
214 } 220 }
215 221
216 bridge->driver->tlb_flush(mem); 222 bridge->driver->tlb_flush(mem);
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 10c23302dd84..a9fb12c20eb7 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -51,7 +51,7 @@ static int serverworks_create_page_map(struct serverworks_page_map *page_map)
51 } 51 }
52 SetPageReserved(virt_to_page(page_map->real)); 52 SetPageReserved(virt_to_page(page_map->real));
53 global_cache_flush(); 53 global_cache_flush();
54 page_map->remapped = ioremap_nocache(virt_to_phys(page_map->real), 54 page_map->remapped = ioremap_nocache(virt_to_gart(page_map->real),
55 PAGE_SIZE); 55 PAGE_SIZE);
56 if (page_map->remapped == NULL) { 56 if (page_map->remapped == NULL) {
57 ClearPageReserved(virt_to_page(page_map->real)); 57 ClearPageReserved(virt_to_page(page_map->real));
@@ -162,7 +162,7 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
162 /* Create a fake scratch directory */ 162 /* Create a fake scratch directory */
163 for(i = 0; i < 1024; i++) { 163 for(i = 0; i < 1024; i++) {
164 writel(agp_bridge->scratch_page, serverworks_private.scratch_dir.remapped+i); 164 writel(agp_bridge->scratch_page, serverworks_private.scratch_dir.remapped+i);
165 writel(virt_to_phys(serverworks_private.scratch_dir.real) | 1, page_dir.remapped+i); 165 writel(virt_to_gart(serverworks_private.scratch_dir.real) | 1, page_dir.remapped+i);
166 } 166 }
167 167
168 retval = serverworks_create_gatt_pages(value->num_entries / 1024); 168 retval = serverworks_create_gatt_pages(value->num_entries / 1024);
@@ -174,7 +174,7 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
174 174
175 agp_bridge->gatt_table_real = (u32 *)page_dir.real; 175 agp_bridge->gatt_table_real = (u32 *)page_dir.real;
176 agp_bridge->gatt_table = (u32 __iomem *)page_dir.remapped; 176 agp_bridge->gatt_table = (u32 __iomem *)page_dir.remapped;
177 agp_bridge->gatt_bus_addr = virt_to_phys(page_dir.real); 177 agp_bridge->gatt_bus_addr = virt_to_gart(page_dir.real);
178 178
179 /* Get the address for the gart region. 179 /* Get the address for the gart region.
180 * This is a bus address even on the alpha, b/c its 180 * This is a bus address even on the alpha, b/c its
@@ -187,7 +187,7 @@ static int serverworks_create_gatt_table(struct agp_bridge_data *bridge)
187 /* Calculate the agp offset */ 187 /* Calculate the agp offset */
188 188
189 for(i = 0; i < value->num_entries / 1024; i++) 189 for(i = 0; i < value->num_entries / 1024; i++)
190 writel(virt_to_phys(serverworks_private.gatt_pages[i]->real)|1, page_dir.remapped+i); 190 writel(virt_to_gart(serverworks_private.gatt_pages[i]->real)|1, page_dir.remapped+i);
191 191
192 return 0; 192 return 0;
193} 193}
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index a673971f2a90..c8255312b8c1 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -407,7 +407,7 @@ static int uninorth_create_gatt_table(struct agp_bridge_data *bridge)
407 407
408 bridge->gatt_table_real = (u32 *) table; 408 bridge->gatt_table_real = (u32 *) table;
409 bridge->gatt_table = (u32 *)table; 409 bridge->gatt_table = (u32 *)table;
410 bridge->gatt_bus_addr = virt_to_phys(table); 410 bridge->gatt_bus_addr = virt_to_gart(table);
411 411
412 for (i = 0; i < num_entries; i++) 412 for (i = 0; i < num_entries; i++)
413 bridge->gatt_table[i] = 0; 413 bridge->gatt_table[i] = 0;
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index 54a2914e3a32..11c6950158b3 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -220,5 +220,6 @@
220 {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 220 {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
221 {0x8086, 0x2582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 221 {0x8086, 0x2582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
222 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \ 222 {0x8086, 0x2592, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
223 {0x8086, 0x2772, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
223 {0, 0, 0} 224 {0, 0, 0}
224 225
diff --git a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
index 5b18bee6492e..cd25f28e26a3 100644
--- a/drivers/char/drm/radeon_irq.c
+++ b/drivers/char/drm/radeon_irq.c
@@ -123,11 +123,6 @@ static int radeon_wait_irq(drm_device_t *dev, int swi_nr)
123 123
124 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; 124 dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
125 125
126 /* This is a hack to work around mysterious freezes on certain
127 * systems:
128 */
129 radeon_acknowledge_irqs( dev_priv );
130
131 DRM_WAIT_ON( ret, dev_priv->swi_queue, 3 * DRM_HZ, 126 DRM_WAIT_ON( ret, dev_priv->swi_queue, 3 * DRM_HZ,
132 RADEON_READ( RADEON_LAST_SWI_REG ) >= swi_nr ); 127 RADEON_READ( RADEON_LAST_SWI_REG ) >= swi_nr );
133 128
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 7a245068e3e5..f022f0944434 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -1995,9 +1995,6 @@ static void mxser_receive_chars(struct mxser_struct *info, int *status)
1995 unsigned char ch, gdl; 1995 unsigned char ch, gdl;
1996 int ignored = 0; 1996 int ignored = 0;
1997 int cnt = 0; 1997 int cnt = 0;
1998 unsigned char *cp;
1999 char *fp;
2000 int count;
2001 int recv_room; 1998 int recv_room;
2002 int max = 256; 1999 int max = 256;
2003 unsigned long flags; 2000 unsigned long flags;
@@ -2011,10 +2008,6 @@ static void mxser_receive_chars(struct mxser_struct *info, int *status)
2011 //return; 2008 //return;
2012 } 2009 }
2013 2010
2014 cp = tty->flip.char_buf;
2015 fp = tty->flip.flag_buf;
2016 count = 0;
2017
2018 // following add by Victor Yu. 09-02-2002 2011 // following add by Victor Yu. 09-02-2002
2019 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) { 2012 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2020 2013
@@ -2041,12 +2034,10 @@ static void mxser_receive_chars(struct mxser_struct *info, int *status)
2041 } 2034 }
2042 while (gdl--) { 2035 while (gdl--) {
2043 ch = inb(info->base + UART_RX); 2036 ch = inb(info->base + UART_RX);
2044 count++; 2037 tty_insert_flip_char(tty, ch, 0);
2045 *cp++ = ch;
2046 *fp++ = 0;
2047 cnt++; 2038 cnt++;
2048 /* 2039 /*
2049 if((count>=HI_WATER) && (info->stop_rx==0)){ 2040 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2050 mxser_stoprx(tty); 2041 mxser_stoprx(tty);
2051 info->stop_rx=1; 2042 info->stop_rx=1;
2052 break; 2043 break;
@@ -2061,7 +2052,7 @@ intr_old:
2061 if (max-- < 0) 2052 if (max-- < 0)
2062 break; 2053 break;
2063 /* 2054 /*
2064 if((count>=HI_WATER) && (info->stop_rx==0)){ 2055 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2065 mxser_stoprx(tty); 2056 mxser_stoprx(tty);
2066 info->stop_rx=1; 2057 info->stop_rx=1;
2067 break; 2058 break;
@@ -2078,36 +2069,33 @@ intr_old:
2078 if (++ignored > 100) 2069 if (++ignored > 100)
2079 break; 2070 break;
2080 } else { 2071 } else {
2081 count++; 2072 char flag = 0;
2082 if (*status & UART_LSR_SPECIAL) { 2073 if (*status & UART_LSR_SPECIAL) {
2083 if (*status & UART_LSR_BI) { 2074 if (*status & UART_LSR_BI) {
2084 *fp++ = TTY_BREAK; 2075 flag = TTY_BREAK;
2085/* added by casper 1/11/2000 */ 2076/* added by casper 1/11/2000 */
2086 info->icount.brk++; 2077 info->icount.brk++;
2087
2088/* */ 2078/* */
2089 if (info->flags & ASYNC_SAK) 2079 if (info->flags & ASYNC_SAK)
2090 do_SAK(tty); 2080 do_SAK(tty);
2091 } else if (*status & UART_LSR_PE) { 2081 } else if (*status & UART_LSR_PE) {
2092 *fp++ = TTY_PARITY; 2082 flag = TTY_PARITY;
2093/* added by casper 1/11/2000 */ 2083/* added by casper 1/11/2000 */
2094 info->icount.parity++; 2084 info->icount.parity++;
2095/* */ 2085/* */
2096 } else if (*status & UART_LSR_FE) { 2086 } else if (*status & UART_LSR_FE) {
2097 *fp++ = TTY_FRAME; 2087 flag = TTY_FRAME;
2098/* added by casper 1/11/2000 */ 2088/* added by casper 1/11/2000 */
2099 info->icount.frame++; 2089 info->icount.frame++;
2100/* */ 2090/* */
2101 } else if (*status & UART_LSR_OE) { 2091 } else if (*status & UART_LSR_OE) {
2102 *fp++ = TTY_OVERRUN; 2092 flag = TTY_OVERRUN;
2103/* added by casper 1/11/2000 */ 2093/* added by casper 1/11/2000 */
2104 info->icount.overrun++; 2094 info->icount.overrun++;
2105/* */ 2095/* */
2106 } else 2096 }
2107 *fp++ = 0; 2097 }
2108 } else 2098 tty_insert_flip_char(tty, ch, flag);
2109 *fp++ = 0;
2110 *cp++ = ch;
2111 cnt++; 2099 cnt++;
2112 if (cnt >= recv_room) { 2100 if (cnt >= recv_room) {
2113 if (!info->ldisc_stop_rx) { 2101 if (!info->ldisc_stop_rx) {
@@ -2132,13 +2120,13 @@ intr_old:
2132 // above add by Victor Yu. 09-02-2002 2120 // above add by Victor Yu. 09-02-2002
2133 } while (*status & UART_LSR_DR); 2121 } while (*status & UART_LSR_DR);
2134 2122
2135 end_intr: // add by Victor Yu. 09-02-2002 2123end_intr: // add by Victor Yu. 09-02-2002
2136 2124
2137 mxvar_log.rxcnt[info->port] += cnt; 2125 mxvar_log.rxcnt[info->port] += cnt;
2138 info->mon_data.rxcnt += cnt; 2126 info->mon_data.rxcnt += cnt;
2139 info->mon_data.up_rxcnt += cnt; 2127 info->mon_data.up_rxcnt += cnt;
2140 spin_unlock_irqrestore(&info->slock, flags); 2128 spin_unlock_irqrestore(&info->slock, flags);
2141 2129
2142 tty_flip_buffer_push(tty); 2130 tty_flip_buffer_push(tty);
2143} 2131}
2144 2132
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 00c7b958361a..ab82d6addd7f 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -745,7 +745,8 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
745 list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids); 745 list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids);
746 746
747 /* Register our host with the SCSI stack. */ 747 /* Register our host with the SCSI stack. */
748 scsi_host = scsi_host_alloc(&scsi_driver_template, 0); 748 scsi_host = scsi_host_alloc(&scsi_driver_template,
749 sizeof (unsigned long));
749 if (!scsi_host) { 750 if (!scsi_host) {
750 SBP2_ERR("failed to register scsi host"); 751 SBP2_ERR("failed to register scsi host");
751 goto failed_alloc; 752 goto failed_alloc;
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index af0446c6de82..48fdf1e517cf 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -54,7 +54,7 @@ static int atkbd_softraw = 1;
54module_param_named(softraw, atkbd_softraw, bool, 0); 54module_param_named(softraw, atkbd_softraw, bool, 0);
55MODULE_PARM_DESC(softraw, "Use software generated rawmode"); 55MODULE_PARM_DESC(softraw, "Use software generated rawmode");
56 56
57static int atkbd_scroll = 1; 57static int atkbd_scroll = 0;
58module_param_named(scroll, atkbd_scroll, bool, 0); 58module_param_named(scroll, atkbd_scroll, bool, 0);
59MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards"); 59MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards");
60 60
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 42a9f7f6f8cb..7bf4be733e9a 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -352,7 +352,7 @@ static int alps_reconnect(struct psmouse *psmouse)
352 if (alps_get_status(psmouse, param)) 352 if (alps_get_status(psmouse, param))
353 return -1; 353 return -1;
354 354
355 if (param[0] & 0x04) 355 if (!(param[0] & 0x04))
356 alps_tap_mode(psmouse, 1); 356 alps_tap_mode(psmouse, 1);
357 357
358 if (alps_absolute_mode(psmouse)) { 358 if (alps_absolute_mode(psmouse)) {
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index bb9f4044c74d..b941ee220997 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2593,6 +2593,9 @@ powerbook_sleep_Core99(void)
2593 /* Restore VIA */ 2593 /* Restore VIA */
2594 restore_via_state(); 2594 restore_via_state();
2595 2595
2596 /* tweak LPJ before cpufreq is there */
2597 loops_per_jiffy *= 2;
2598
2596 /* Restore video */ 2599 /* Restore video */
2597 pmac_call_early_video_resume(); 2600 pmac_call_early_video_resume();
2598 2601
@@ -2613,6 +2616,9 @@ powerbook_sleep_Core99(void)
2613 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); 2616 pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
2614 pmu_wait_complete(&req); 2617 pmu_wait_complete(&req);
2615 2618
2619 /* Restore LPJ, cpufreq will adjust the cpu frequency */
2620 loops_per_jiffy /= 2;
2621
2616 pmac_wakeup_devices(); 2622 pmac_wakeup_devices();
2617 2623
2618 return 0; 2624 return 0;
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 1e97b3c12bd5..0c1b8520ef86 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -985,6 +985,9 @@ static int do_end_io(struct multipath *m, struct bio *bio,
985 if (!error) 985 if (!error)
986 return 0; /* I/O complete */ 986 return 0; /* I/O complete */
987 987
988 if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
989 return error;
990
988 spin_lock(&m->lock); 991 spin_lock(&m->lock);
989 if (!m->nr_valid_paths) { 992 if (!m->nr_valid_paths) {
990 if (!m->queue_if_no_path || m->suspended) { 993 if (!m->queue_if_no_path || m->suspended) {
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index 7b74c87b569e..4830b7759061 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -573,6 +573,7 @@ static int i2o_block_reply(struct i2o_controller *c, u32 m,
573static void i2o_block_event(struct i2o_event *evt) 573static void i2o_block_event(struct i2o_event *evt)
574{ 574{
575 osm_info("block-osm: event received\n"); 575 osm_info("block-osm: event received\n");
576 kfree(evt);
576}; 577};
577 578
578/* 579/*
diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c
index 1c563f905a59..a7f15d9f13e5 100644
--- a/drivers/net/hamradio/baycom_epp.c
+++ b/drivers/net/hamradio/baycom_epp.c
@@ -374,29 +374,6 @@ static inline void do_kiss_params(struct baycom_state *bc,
374} 374}
375 375
376/* --------------------------------------------------------------------- */ 376/* --------------------------------------------------------------------- */
377/*
378 * high performance HDLC encoder
379 * yes, it's ugly, but generates pretty good code
380 */
381
382#define ENCODEITERA(j) \
383({ \
384 if (!(notbitstream & (0x1f0 << j))) \
385 goto stuff##j; \
386 encodeend##j: ; \
387})
388
389#define ENCODEITERB(j) \
390({ \
391 stuff##j: \
392 bitstream &= ~(0x100 << j); \
393 bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) | \
394 ((bitbuf & ~(((2 << j) << numbit) - 1)) << 1); \
395 numbit++; \
396 notbitstream = ~bitstream; \
397 goto encodeend##j; \
398})
399
400 377
401static void encode_hdlc(struct baycom_state *bc) 378static void encode_hdlc(struct baycom_state *bc)
402{ 379{
@@ -405,6 +382,7 @@ static void encode_hdlc(struct baycom_state *bc)
405 int pkt_len; 382 int pkt_len;
406 unsigned bitstream, notbitstream, bitbuf, numbit, crc; 383 unsigned bitstream, notbitstream, bitbuf, numbit, crc;
407 unsigned char crcarr[2]; 384 unsigned char crcarr[2];
385 int j;
408 386
409 if (bc->hdlctx.bufcnt > 0) 387 if (bc->hdlctx.bufcnt > 0)
410 return; 388 return;
@@ -429,24 +407,14 @@ static void encode_hdlc(struct baycom_state *bc)
429 pkt_len--; 407 pkt_len--;
430 if (!pkt_len) 408 if (!pkt_len)
431 bp = crcarr; 409 bp = crcarr;
432 ENCODEITERA(0); 410 for (j = 0; j < 8; j++)
433 ENCODEITERA(1); 411 if (unlikely(!(notbitstream & (0x1f0 << j)))) {
434 ENCODEITERA(2); 412 bitstream &= ~(0x100 << j);
435 ENCODEITERA(3); 413 bitbuf = (bitbuf & (((2 << j) << numbit) - 1)) |
436 ENCODEITERA(4); 414 ((bitbuf & ~(((2 << j) << numbit) - 1)) << 1);
437 ENCODEITERA(5); 415 numbit++;
438 ENCODEITERA(6); 416 notbitstream = ~bitstream;
439 ENCODEITERA(7); 417 }
440 goto enditer;
441 ENCODEITERB(0);
442 ENCODEITERB(1);
443 ENCODEITERB(2);
444 ENCODEITERB(3);
445 ENCODEITERB(4);
446 ENCODEITERB(5);
447 ENCODEITERB(6);
448 ENCODEITERB(7);
449 enditer:
450 numbit += 8; 418 numbit += 8;
451 while (numbit >= 8) { 419 while (numbit >= 8) {
452 *wp++ = bitbuf; 420 *wp++ = bitbuf;
@@ -610,37 +578,6 @@ static void do_rxpacket(struct net_device *dev)
610 bc->stats.rx_packets++; 578 bc->stats.rx_packets++;
611} 579}
612 580
613#define DECODEITERA(j) \
614({ \
615 if (!(notbitstream & (0x0fc << j))) /* flag or abort */ \
616 goto flgabrt##j; \
617 if ((bitstream & (0x1f8 << j)) == (0xf8 << j)) /* stuffed bit */ \
618 goto stuff##j; \
619 enditer##j: ; \
620})
621
622#define DECODEITERB(j) \
623({ \
624 flgabrt##j: \
625 if (!(notbitstream & (0x1fc << j))) { /* abort received */ \
626 state = 0; \
627 goto enditer##j; \
628 } \
629 if ((bitstream & (0x1fe << j)) != (0x0fc << j)) /* flag received */ \
630 goto enditer##j; \
631 if (state) \
632 do_rxpacket(dev); \
633 bc->hdlcrx.bufcnt = 0; \
634 bc->hdlcrx.bufptr = bc->hdlcrx.buf; \
635 state = 1; \
636 numbits = 7-j; \
637 goto enditer##j; \
638 stuff##j: \
639 numbits--; \
640 bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1); \
641 goto enditer##j; \
642})
643
644static int receive(struct net_device *dev, int cnt) 581static int receive(struct net_device *dev, int cnt)
645{ 582{
646 struct baycom_state *bc = netdev_priv(dev); 583 struct baycom_state *bc = netdev_priv(dev);
@@ -649,6 +586,7 @@ static int receive(struct net_device *dev, int cnt)
649 unsigned char tmp[128]; 586 unsigned char tmp[128];
650 unsigned char *cp; 587 unsigned char *cp;
651 int cnt2, ret = 0; 588 int cnt2, ret = 0;
589 int j;
652 590
653 numbits = bc->hdlcrx.numbits; 591 numbits = bc->hdlcrx.numbits;
654 state = bc->hdlcrx.state; 592 state = bc->hdlcrx.state;
@@ -669,24 +607,32 @@ static int receive(struct net_device *dev, int cnt)
669 bitbuf |= (*cp) << 8; 607 bitbuf |= (*cp) << 8;
670 numbits += 8; 608 numbits += 8;
671 notbitstream = ~bitstream; 609 notbitstream = ~bitstream;
672 DECODEITERA(0); 610 for (j = 0; j < 8; j++) {
673 DECODEITERA(1); 611
674 DECODEITERA(2); 612 /* flag or abort */
675 DECODEITERA(3); 613 if (unlikely(!(notbitstream & (0x0fc << j)))) {
676 DECODEITERA(4); 614
677 DECODEITERA(5); 615 /* abort received */
678 DECODEITERA(6); 616 if (!(notbitstream & (0x1fc << j)))
679 DECODEITERA(7); 617 state = 0;
680 goto enddec; 618
681 DECODEITERB(0); 619 /* not flag received */
682 DECODEITERB(1); 620 else if (!(bitstream & (0x1fe << j)) != (0x0fc << j)) {
683 DECODEITERB(2); 621 if (state)
684 DECODEITERB(3); 622 do_rxpacket(dev);
685 DECODEITERB(4); 623 bc->hdlcrx.bufcnt = 0;
686 DECODEITERB(5); 624 bc->hdlcrx.bufptr = bc->hdlcrx.buf;
687 DECODEITERB(6); 625 state = 1;
688 DECODEITERB(7); 626 numbits = 7-j;
689 enddec: 627 }
628 }
629
630 /* stuffed bit */
631 else if (unlikely((bitstream & (0x1f8 << j)) == (0xf8 << j))) {
632 numbits--;
633 bitbuf = (bitbuf & ((~0xff) << j)) | ((bitbuf & ~((~0xff) << j)) << 1);
634 }
635 }
690 while (state && numbits >= 8) { 636 while (state && numbits >= 8) {
691 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) { 637 if (bc->hdlcrx.bufcnt >= TXBUFFER_SIZE) {
692 state = 0; 638 state = 0;
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index 1c553d7efdd9..ca5914091d3a 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -389,7 +389,7 @@ config VIA_FIR
389 help 389 help
390 Say Y here if you want to build support for the VIA VT8231 390 Say Y here if you want to build support for the VIA VT8231
391 and VIA VT1211 IrDA controllers, found on the motherboards using 391 and VIA VT1211 IrDA controllers, found on the motherboards using
392 those those VIA chipsets. To use this controller, you will need 392 those VIA chipsets. To use this controller, you will need
393 to plug a specific 5 pins FIR IrDA dongle in the specific 393 to plug a specific 5 pins FIR IrDA dongle in the specific
394 motherboard connector. The driver provides support for SIR, MIR 394 motherboard connector. The driver provides support for SIR, MIR
395 and FIR (4Mbps) speeds. 395 and FIR (4Mbps) speeds.
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 13ed8dc1e91d..55af32e9bf08 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -802,13 +802,14 @@ static void veth_tx_timeout(struct net_device *dev)
802 802
803 spin_lock_irqsave(&port->pending_gate, flags); 803 spin_lock_irqsave(&port->pending_gate, flags);
804 804
805 if (!port->pending_lpmask) {
806 spin_unlock_irqrestore(&port->pending_gate, flags);
807 return;
808 }
809
805 printk(KERN_WARNING "%s: Tx timeout! Resetting lp connections: %08x\n", 810 printk(KERN_WARNING "%s: Tx timeout! Resetting lp connections: %08x\n",
806 dev->name, port->pending_lpmask); 811 dev->name, port->pending_lpmask);
807 812
808 /* If we've timed out the queue must be stopped, which should
809 * only ever happen when there is a pending packet. */
810 WARN_ON(! port->pending_lpmask);
811
812 for (i = 0; i < HVMAXARCHITECTEDLPS; i++) { 813 for (i = 0; i < HVMAXARCHITECTEDLPS; i++) {
813 struct veth_lpar_connection *cnx = veth_cnx[i]; 814 struct veth_lpar_connection *cnx = veth_cnx[i];
814 815
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 41e517114807..c6e8b25f9685 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -1274,6 +1274,9 @@ static int el3_close(struct net_device *dev)
1274 spin_lock_irqsave(&lp->window_lock, flags); 1274 spin_lock_irqsave(&lp->window_lock, flags);
1275 update_stats(dev); 1275 update_stats(dev);
1276 spin_unlock_irqrestore(&lp->window_lock, flags); 1276 spin_unlock_irqrestore(&lp->window_lock, flags);
1277
1278 /* force interrupts off */
1279 outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
1277 } 1280 }
1278 1281
1279 link->open--; 1282 link->open--;
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index c59507f8a76b..d6d0e43dab65 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -415,7 +415,7 @@ struct rtl8169_private {
415 struct work_struct task; 415 struct work_struct task;
416}; 416};
417 417
418MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@oss.sgi.com>"); 418MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
419MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); 419MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver");
420module_param_array(media, int, &num_media, 0); 420module_param_array(media, int, &num_media, 0);
421module_param(rx_copybreak, int, 0); 421module_param(rx_copybreak, int, 0);
@@ -1585,8 +1585,8 @@ rtl8169_hw_start(struct net_device *dev)
1585 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); 1585 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
1586 RTL_W8(EarlyTxThres, EarlyTxThld); 1586 RTL_W8(EarlyTxThres, EarlyTxThld);
1587 1587
1588 /* For gigabit rtl8169, MTU + header + CRC + VLAN */ 1588 /* Low hurts. Let's disable the filtering. */
1589 RTL_W16(RxMaxSize, tp->rx_buf_sz); 1589 RTL_W16(RxMaxSize, 16383);
1590 1590
1591 /* Set Rx Config register */ 1591 /* Set Rx Config register */
1592 i = rtl8169_rx_config | 1592 i = rtl8169_rx_config |
@@ -2127,6 +2127,11 @@ rtl8169_tx_interrupt(struct net_device *dev, struct rtl8169_private *tp,
2127 } 2127 }
2128} 2128}
2129 2129
2130static inline int rtl8169_fragmented_frame(u32 status)
2131{
2132 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag);
2133}
2134
2130static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc) 2135static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc)
2131{ 2136{
2132 u32 opts1 = le32_to_cpu(desc->opts1); 2137 u32 opts1 = le32_to_cpu(desc->opts1);
@@ -2177,27 +2182,41 @@ rtl8169_rx_interrupt(struct net_device *dev, struct rtl8169_private *tp,
2177 2182
2178 while (rx_left > 0) { 2183 while (rx_left > 0) {
2179 unsigned int entry = cur_rx % NUM_RX_DESC; 2184 unsigned int entry = cur_rx % NUM_RX_DESC;
2185 struct RxDesc *desc = tp->RxDescArray + entry;
2180 u32 status; 2186 u32 status;
2181 2187
2182 rmb(); 2188 rmb();
2183 status = le32_to_cpu(tp->RxDescArray[entry].opts1); 2189 status = le32_to_cpu(desc->opts1);
2184 2190
2185 if (status & DescOwn) 2191 if (status & DescOwn)
2186 break; 2192 break;
2187 if (status & RxRES) { 2193 if (status & RxRES) {
2188 printk(KERN_INFO "%s: Rx ERROR!!!\n", dev->name); 2194 printk(KERN_INFO "%s: Rx ERROR. status = %08x\n",
2195 dev->name, status);
2189 tp->stats.rx_errors++; 2196 tp->stats.rx_errors++;
2190 if (status & (RxRWT | RxRUNT)) 2197 if (status & (RxRWT | RxRUNT))
2191 tp->stats.rx_length_errors++; 2198 tp->stats.rx_length_errors++;
2192 if (status & RxCRC) 2199 if (status & RxCRC)
2193 tp->stats.rx_crc_errors++; 2200 tp->stats.rx_crc_errors++;
2201 rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
2194 } else { 2202 } else {
2195 struct RxDesc *desc = tp->RxDescArray + entry;
2196 struct sk_buff *skb = tp->Rx_skbuff[entry]; 2203 struct sk_buff *skb = tp->Rx_skbuff[entry];
2197 int pkt_size = (status & 0x00001FFF) - 4; 2204 int pkt_size = (status & 0x00001FFF) - 4;
2198 void (*pci_action)(struct pci_dev *, dma_addr_t, 2205 void (*pci_action)(struct pci_dev *, dma_addr_t,
2199 size_t, int) = pci_dma_sync_single_for_device; 2206 size_t, int) = pci_dma_sync_single_for_device;
2200 2207
2208 /*
2209 * The driver does not support incoming fragmented
2210 * frames. They are seen as a symptom of over-mtu
2211 * sized frames.
2212 */
2213 if (unlikely(rtl8169_fragmented_frame(status))) {
2214 tp->stats.rx_dropped++;
2215 tp->stats.rx_length_errors++;
2216 rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
2217 goto move_on;
2218 }
2219
2201 rtl8169_rx_csum(skb, desc); 2220 rtl8169_rx_csum(skb, desc);
2202 2221
2203 pci_dma_sync_single_for_cpu(tp->pci_dev, 2222 pci_dma_sync_single_for_cpu(tp->pci_dev,
@@ -2224,7 +2243,7 @@ rtl8169_rx_interrupt(struct net_device *dev, struct rtl8169_private *tp,
2224 tp->stats.rx_bytes += pkt_size; 2243 tp->stats.rx_bytes += pkt_size;
2225 tp->stats.rx_packets++; 2244 tp->stats.rx_packets++;
2226 } 2245 }
2227 2246move_on:
2228 cur_rx++; 2247 cur_rx++;
2229 rx_left--; 2248 rx_left--;
2230 } 2249 }
diff --git a/drivers/net/shaper.c b/drivers/net/shaper.c
index e68cf5fb4920..20edeb345792 100644
--- a/drivers/net/shaper.c
+++ b/drivers/net/shaper.c
@@ -100,35 +100,8 @@ static int sh_debug; /* Debug flag */
100 100
101#define SHAPER_BANNER "CymruNet Traffic Shaper BETA 0.04 for Linux 2.1\n" 101#define SHAPER_BANNER "CymruNet Traffic Shaper BETA 0.04 for Linux 2.1\n"
102 102
103/*
104 * Locking
105 */
106
107static int shaper_lock(struct shaper *sh)
108{
109 /*
110 * Lock in an interrupt must fail
111 */
112 while (test_and_set_bit(0, &sh->locked))
113 {
114 if (!in_interrupt())
115 sleep_on(&sh->wait_queue);
116 else
117 return 0;
118
119 }
120 return 1;
121}
122
123static void shaper_kick(struct shaper *sh); 103static void shaper_kick(struct shaper *sh);
124 104
125static void shaper_unlock(struct shaper *sh)
126{
127 clear_bit(0, &sh->locked);
128 wake_up(&sh->wait_queue);
129 shaper_kick(sh);
130}
131
132/* 105/*
133 * Compute clocks on a buffer 106 * Compute clocks on a buffer
134 */ 107 */
@@ -157,17 +130,15 @@ static void shaper_setspeed(struct shaper *shaper, int bitspersec)
157 * Throw a frame at a shaper. 130 * Throw a frame at a shaper.
158 */ 131 */
159 132
160static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb) 133
134static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
161{ 135{
136 struct shaper *shaper = dev->priv;
162 struct sk_buff *ptr; 137 struct sk_buff *ptr;
163 138
164 /* 139 if (down_trylock(&shaper->sem))
165 * Get ready to work on this shaper. Lock may fail if its 140 return -1;
166 * an interrupt and locked. 141
167 */
168
169 if(!shaper_lock(shaper))
170 return -1;
171 ptr=shaper->sendq.prev; 142 ptr=shaper->sendq.prev;
172 143
173 /* 144 /*
@@ -260,7 +231,8 @@ static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb)
260 dev_kfree_skb(ptr); 231 dev_kfree_skb(ptr);
261 shaper->stats.collisions++; 232 shaper->stats.collisions++;
262 } 233 }
263 shaper_unlock(shaper); 234 shaper_kick(shaper);
235 up(&shaper->sem);
264 return 0; 236 return 0;
265} 237}
266 238
@@ -297,8 +269,13 @@ static void shaper_queue_xmit(struct shaper *shaper, struct sk_buff *skb)
297 269
298static void shaper_timer(unsigned long data) 270static void shaper_timer(unsigned long data)
299{ 271{
300 struct shaper *sh=(struct shaper *)data; 272 struct shaper *shaper = (struct shaper *)data;
301 shaper_kick(sh); 273
274 if (!down_trylock(&shaper->sem)) {
275 shaper_kick(shaper);
276 up(&shaper->sem);
277 } else
278 mod_timer(&shaper->timer, jiffies);
302} 279}
303 280
304/* 281/*
@@ -311,19 +288,6 @@ static void shaper_kick(struct shaper *shaper)
311 struct sk_buff *skb; 288 struct sk_buff *skb;
312 289
313 /* 290 /*
314 * Shaper unlock will kick
315 */
316
317 if (test_and_set_bit(0, &shaper->locked))
318 {
319 if(sh_debug)
320 printk("Shaper locked.\n");
321 mod_timer(&shaper->timer, jiffies);
322 return;
323 }
324
325
326 /*
327 * Walk the list (may be empty) 291 * Walk the list (may be empty)
328 */ 292 */
329 293
@@ -364,8 +328,6 @@ static void shaper_kick(struct shaper *shaper)
364 328
365 if(skb!=NULL) 329 if(skb!=NULL)
366 mod_timer(&shaper->timer, SHAPERCB(skb)->shapeclock); 330 mod_timer(&shaper->timer, SHAPERCB(skb)->shapeclock);
367
368 clear_bit(0, &shaper->locked);
369} 331}
370 332
371 333
@@ -376,14 +338,12 @@ static void shaper_kick(struct shaper *shaper)
376static void shaper_flush(struct shaper *shaper) 338static void shaper_flush(struct shaper *shaper)
377{ 339{
378 struct sk_buff *skb; 340 struct sk_buff *skb;
379 if(!shaper_lock(shaper)) 341
380 { 342 down(&shaper->sem);
381 printk(KERN_ERR "shaper: shaper_flush() called by an irq!\n");
382 return;
383 }
384 while((skb=skb_dequeue(&shaper->sendq))!=NULL) 343 while((skb=skb_dequeue(&shaper->sendq))!=NULL)
385 dev_kfree_skb(skb); 344 dev_kfree_skb(skb);
386 shaper_unlock(shaper); 345 shaper_kick(shaper);
346 up(&shaper->sem);
387} 347}
388 348
389/* 349/*
@@ -426,13 +386,6 @@ static int shaper_close(struct net_device *dev)
426 * ARP and other resolutions and not before. 386 * ARP and other resolutions and not before.
427 */ 387 */
428 388
429
430static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
431{
432 struct shaper *sh=dev->priv;
433 return shaper_qframe(sh, skb);
434}
435
436static struct net_device_stats *shaper_get_stats(struct net_device *dev) 389static struct net_device_stats *shaper_get_stats(struct net_device *dev)
437{ 390{
438 struct shaper *sh=dev->priv; 391 struct shaper *sh=dev->priv;
@@ -623,7 +576,6 @@ static void shaper_init_priv(struct net_device *dev)
623 init_timer(&sh->timer); 576 init_timer(&sh->timer);
624 sh->timer.function=shaper_timer; 577 sh->timer.function=shaper_timer;
625 sh->timer.data=(unsigned long)sh; 578 sh->timer.data=(unsigned long)sh;
626 init_waitqueue_head(&sh->wait_queue);
627} 579}
628 580
629/* 581/*
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index fc9b5cd957aa..a0b8848049c9 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -7,7 +7,12 @@
7 * Copyright (C) 2005 Broadcom Corporation. 7 * Copyright (C) 2005 Broadcom Corporation.
8 * 8 *
9 * Firmware is: 9 * Firmware is:
10 * Copyright (C) 2000-2003 Broadcom Corporation. 10 * Derived from proprietary unpublished source code,
11 * Copyright (C) 2000-2003 Broadcom Corporation.
12 *
13 * Permission is hereby granted for the distribution of this firmware
14 * data in hexadecimal or equivalent format, provided this copyright
15 * notice is accompanying it.
11 */ 16 */
12 17
13#include <linux/config.h> 18#include <linux/config.h>
@@ -61,8 +66,8 @@
61 66
62#define DRV_MODULE_NAME "tg3" 67#define DRV_MODULE_NAME "tg3"
63#define PFX DRV_MODULE_NAME ": " 68#define PFX DRV_MODULE_NAME ": "
64#define DRV_MODULE_VERSION "3.29" 69#define DRV_MODULE_VERSION "3.31"
65#define DRV_MODULE_RELDATE "May 23, 2005" 70#define DRV_MODULE_RELDATE "June 8, 2005"
66 71
67#define TG3_DEF_MAC_MODE 0 72#define TG3_DEF_MAC_MODE 0
68#define TG3_DEF_RX_MODE 0 73#define TG3_DEF_RX_MODE 0
@@ -8555,6 +8560,16 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
8555 8560
8556 case NIC_SRAM_DATA_CFG_LED_MODE_MAC: 8561 case NIC_SRAM_DATA_CFG_LED_MODE_MAC:
8557 tp->led_ctrl = LED_CTRL_MODE_MAC; 8562 tp->led_ctrl = LED_CTRL_MODE_MAC;
8563
8564 /* Default to PHY_1_MODE if 0 (MAC_MODE) is
8565 * read on some older 5700/5701 bootcode.
8566 */
8567 if (GET_ASIC_REV(tp->pci_chip_rev_id) ==
8568 ASIC_REV_5700 ||
8569 GET_ASIC_REV(tp->pci_chip_rev_id) ==
8570 ASIC_REV_5701)
8571 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
8572
8558 break; 8573 break;
8559 8574
8560 case SHASTA_EXT_LED_SHARED: 8575 case SHASTA_EXT_LED_SHARED:
@@ -9680,10 +9695,24 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
9680 } 9695 }
9681 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != 9696 if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
9682 DMA_RWCTRL_WRITE_BNDRY_16) { 9697 DMA_RWCTRL_WRITE_BNDRY_16) {
9698 static struct pci_device_id dma_wait_state_chipsets[] = {
9699 { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
9700 PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
9701 { },
9702 };
9703
9683 /* DMA test passed without adjusting DMA boundary, 9704 /* DMA test passed without adjusting DMA boundary,
9684 * just restore the calculated DMA boundary 9705 * now look for chipsets that are known to expose the
9706 * DMA bug without failing the test.
9685 */ 9707 */
9686 tp->dma_rwctrl = saved_dma_rwctrl; 9708 if (pci_dev_present(dma_wait_state_chipsets)) {
9709 tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
9710 tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
9711 }
9712 else
9713 /* Safe to use the calculated DMA boundary. */
9714 tp->dma_rwctrl = saved_dma_rwctrl;
9715
9687 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); 9716 tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl);
9688 } 9717 }
9689 9718
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index 8132d946c384..30af105271a2 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -217,6 +217,8 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
217 kfree(slot->hotplug_slot->info); 217 kfree(slot->hotplug_slot->info);
218 kfree(slot->hotplug_slot->name); 218 kfree(slot->hotplug_slot->name);
219 kfree(slot->hotplug_slot); 219 kfree(slot->hotplug_slot);
220 if (slot->dev)
221 pci_dev_put(slot->dev);
220 kfree(slot); 222 kfree(slot);
221} 223}
222 224
diff --git a/drivers/pci/hotplug/cpci_hotplug_pci.c b/drivers/pci/hotplug/cpci_hotplug_pci.c
index c878028ad215..225b5e551dd6 100644
--- a/drivers/pci/hotplug/cpci_hotplug_pci.c
+++ b/drivers/pci/hotplug/cpci_hotplug_pci.c
@@ -315,9 +315,12 @@ int cpci_unconfigure_slot(struct slot* slot)
315 PCI_DEVFN(PCI_SLOT(slot->devfn), i)); 315 PCI_DEVFN(PCI_SLOT(slot->devfn), i));
316 if (dev) { 316 if (dev) {
317 pci_remove_bus_device(dev); 317 pci_remove_bus_device(dev);
318 slot->dev = NULL; 318 pci_dev_put(dev);
319 } 319 }
320 } 320 }
321 pci_dev_put(slot->dev);
322 slot->dev = NULL;
323
321 dbg("%s - exit", __FUNCTION__); 324 dbg("%s - exit", __FUNCTION__);
322 return 0; 325 return 0;
323} 326}
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index fe98553c978f..f315df2005bc 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -393,7 +393,10 @@ int pci_register_driver(struct pci_driver *drv)
393 drv->driver.bus = &pci_bus_type; 393 drv->driver.bus = &pci_bus_type;
394 drv->driver.probe = pci_device_probe; 394 drv->driver.probe = pci_device_probe;
395 drv->driver.remove = pci_device_remove; 395 drv->driver.remove = pci_device_remove;
396 drv->driver.shutdown = pci_device_shutdown, 396 /* FIXME, once all of the existing PCI drivers have been fixed to set
397 * the pci shutdown function, this test can go away. */
398 if (!drv->driver.shutdown)
399 drv->driver.shutdown = pci_device_shutdown,
397 drv->driver.owner = drv->owner; 400 drv->driver.owner = drv->owner;
398 drv->driver.kobj.ktype = &pci_driver_kobj_type; 401 drv->driver.kobj.ktype = &pci_driver_kobj_type;
399 pci_init_dynids(&drv->dynids); 402 pci_init_dynids(&drv->dynids);
diff --git a/drivers/pci/pci.ids b/drivers/pci/pci.ids
index 93481b41b613..1d2ef1e2ffc6 100644
--- a/drivers/pci/pci.ids
+++ b/drivers/pci/pci.ids
@@ -7173,6 +7173,7 @@
7173 080f Sentry5 DDR/SDR RAM Controller 7173 080f Sentry5 DDR/SDR RAM Controller
7174 0811 Sentry5 External Interface Core 7174 0811 Sentry5 External Interface Core
7175 0816 BCM3302 Sentry5 MIPS32 CPU 7175 0816 BCM3302 Sentry5 MIPS32 CPU
7176 1600 NetXtreme BCM5752 Gigabit Ethernet PCI Express
7176 1644 NetXtreme BCM5700 Gigabit Ethernet 7177 1644 NetXtreme BCM5700 Gigabit Ethernet
7177 1014 0277 Broadcom Vigil B5700 1000Base-T 7178 1014 0277 Broadcom Vigil B5700 1000Base-T
7178 1028 00d1 Broadcom BCM5700 7179 1028 00d1 Broadcom BCM5700
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index b7ae87823c69..fd48b201eb53 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -125,7 +125,7 @@ static inline unsigned int pci_calc_resource_flags(unsigned int flags)
125/* 125/*
126 * Find the extent of a PCI decode.. 126 * Find the extent of a PCI decode..
127 */ 127 */
128static u32 pci_size(u32 base, u32 maxbase, unsigned long mask) 128static u32 pci_size(u32 base, u32 maxbase, u32 mask)
129{ 129{
130 u32 size = mask & maxbase; /* Find the significant bits */ 130 u32 size = mask & maxbase; /* Find the significant bits */
131 if (!size) 131 if (!size)
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 637e9493034b..968033fd29f0 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -456,21 +456,16 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
456} 456}
457DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_APIC, quirk_amd_8131_ioapic ); 457DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_APIC, quirk_amd_8131_ioapic );
458 458
459static void __init quirk_svw_msi(struct pci_dev *dev)
460{
461 pci_msi_quirk = 1;
462 printk(KERN_WARNING "PCI: MSI quirk detected. pci_msi_quirk set.\n");
463}
464DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_svw_msi );
459#endif /* CONFIG_X86_IO_APIC */ 465#endif /* CONFIG_X86_IO_APIC */
460 466
461 467
462/* 468/*
463 * Via 686A/B: The PCI_INTERRUPT_LINE register for the on-chip
464 * devices, USB0/1, AC97, MC97, and ACPI, has an unusual feature:
465 * when written, it makes an internal connection to the PIC.
466 * For these devices, this register is defined to be 4 bits wide.
467 * Normally this is fine. However for IO-APIC motherboards, or
468 * non-x86 architectures (yes Via exists on PPC among other places),
469 * we must mask the PCI_INTERRUPT_LINE value versus 0xf to get
470 * interrupts delivered properly.
471 */
472
473/*
474 * FIXME: it is questionable that quirk_via_acpi 469 * FIXME: it is questionable that quirk_via_acpi
475 * is needed. It shows up as an ISA bridge, and does not 470 * is needed. It shows up as an ISA bridge, and does not
476 * support the PCI_INTERRUPT_LINE register at all. Therefore 471 * support the PCI_INTERRUPT_LINE register at all. Therefore
@@ -492,28 +487,30 @@ static void __devinit quirk_via_acpi(struct pci_dev *d)
492DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi ); 487DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi );
493DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi ); 488DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi );
494 489
495static void quirk_via_irqpic(struct pci_dev *dev) 490/*
491 * Via 686A/B: The PCI_INTERRUPT_LINE register for the on-chip
492 * devices, USB0/1, AC97, MC97, and ACPI, has an unusual feature:
493 * when written, it makes an internal connection to the PIC.
494 * For these devices, this register is defined to be 4 bits wide.
495 * Normally this is fine. However for IO-APIC motherboards, or
496 * non-x86 architectures (yes Via exists on PPC among other places),
497 * we must mask the PCI_INTERRUPT_LINE value versus 0xf to get
498 * interrupts delivered properly.
499 */
500static void quirk_via_irq(struct pci_dev *dev)
496{ 501{
497 u8 irq, new_irq; 502 u8 irq, new_irq;
498 503
499#ifdef CONFIG_X86_IO_APIC
500 if (nr_ioapics && !skip_ioapic_setup)
501 return;
502#endif
503#ifdef CONFIG_ACPI
504 if (acpi_irq_model != ACPI_IRQ_MODEL_PIC)
505 return;
506#endif
507 new_irq = dev->irq & 0xf; 504 new_irq = dev->irq & 0xf;
508 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); 505 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
509 if (new_irq != irq) { 506 if (new_irq != irq) {
510 printk(KERN_INFO "PCI: Via PIC IRQ fixup for %s, from %d to %d\n", 507 printk(KERN_INFO "PCI: Via IRQ fixup for %s, from %d to %d\n",
511 pci_name(dev), irq, new_irq); 508 pci_name(dev), irq, new_irq);
512 udelay(15); /* unknown if delay really needed */ 509 udelay(15); /* unknown if delay really needed */
513 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq); 510 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
514 } 511 }
515} 512}
516DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irqpic); 513DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq);
517 514
518/* 515/*
519 * PIIX3 USB: We have to disable USB interrupts that are 516 * PIIX3 USB: We have to disable USB interrupts that are
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 1811cb240315..27fec8a5eb5b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1752,7 +1752,7 @@ config SCSI_NCR53C7xx_FAST
1752 1752
1753config SUN3_SCSI 1753config SUN3_SCSI
1754 tristate "Sun3 NCR5380 SCSI" 1754 tristate "Sun3 NCR5380 SCSI"
1755 depends on SUN3 && SCSI 1755 depends on SUN3 && SCSI && BROKEN
1756 help 1756 help
1757 This option will enable support for the OBIO (onboard io) NCR5380 1757 This option will enable support for the OBIO (onboard io) NCR5380
1758 SCSI controller found in the Sun 3/50 and 3/60, as well as for 1758 SCSI controller found in the Sun 3/50 and 3/60, as well as for
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 54c52349adc5..3be546439252 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -665,15 +665,6 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
665 return ata_pci_init_one(pdev, port_info, n_ports); 665 return ata_pci_init_one(pdev, port_info, n_ports);
666} 666}
667 667
668/**
669 * piix_init -
670 *
671 * LOCKING:
672 *
673 * RETURNS:
674 *
675 */
676
677static int __init piix_init(void) 668static int __init piix_init(void)
678{ 669{
679 int rc; 670 int rc;
@@ -689,13 +680,6 @@ static int __init piix_init(void)
689 return 0; 680 return 0;
690} 681}
691 682
692/**
693 * piix_exit -
694 *
695 * LOCKING:
696 *
697 */
698
699static void __exit piix_exit(void) 683static void __exit piix_exit(void)
700{ 684{
701 pci_unregister_driver(&piix_pci_driver); 685 pci_unregister_driver(&piix_pci_driver);
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 30a88f0e7bd6..9e58f134f68b 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -186,6 +186,28 @@ static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf)
186 ata_wait_idle(ap); 186 ata_wait_idle(ap);
187} 187}
188 188
189
190/**
191 * ata_tf_load - send taskfile registers to host controller
192 * @ap: Port to which output is sent
193 * @tf: ATA taskfile register set
194 *
195 * Outputs ATA taskfile to standard ATA host controller using MMIO
196 * or PIO as indicated by the ATA_FLAG_MMIO flag.
197 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
198 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
199 * hob_lbal, hob_lbam, and hob_lbah.
200 *
201 * This function waits for idle (!BUSY and !DRQ) after writing
202 * registers. If the control register has a new value, this
203 * function also waits for idle after writing control and before
204 * writing the remaining registers.
205 *
206 * May be used as the tf_load() entry in ata_port_operations.
207 *
208 * LOCKING:
209 * Inherited from caller.
210 */
189void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) 211void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
190{ 212{
191 if (ap->flags & ATA_FLAG_MMIO) 213 if (ap->flags & ATA_FLAG_MMIO)
@@ -195,11 +217,11 @@ void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)
195} 217}
196 218
197/** 219/**
198 * ata_exec_command - issue ATA command to host controller 220 * ata_exec_command_pio - issue ATA command to host controller
199 * @ap: port to which command is being issued 221 * @ap: port to which command is being issued
200 * @tf: ATA taskfile register set 222 * @tf: ATA taskfile register set
201 * 223 *
202 * Issues PIO/MMIO write to ATA command register, with proper 224 * Issues PIO write to ATA command register, with proper
203 * synchronization with interrupt handler / other threads. 225 * synchronization with interrupt handler / other threads.
204 * 226 *
205 * LOCKING: 227 * LOCKING:
@@ -235,6 +257,18 @@ static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf)
235 ata_pause(ap); 257 ata_pause(ap);
236} 258}
237 259
260
261/**
262 * ata_exec_command - issue ATA command to host controller
263 * @ap: port to which command is being issued
264 * @tf: ATA taskfile register set
265 *
266 * Issues PIO/MMIO write to ATA command register, with proper
267 * synchronization with interrupt handler / other threads.
268 *
269 * LOCKING:
270 * spin_lock_irqsave(host_set lock)
271 */
238void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) 272void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)
239{ 273{
240 if (ap->flags & ATA_FLAG_MMIO) 274 if (ap->flags & ATA_FLAG_MMIO)
@@ -305,7 +339,7 @@ void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf)
305} 339}
306 340
307/** 341/**
308 * ata_tf_read - input device's ATA taskfile shadow registers 342 * ata_tf_read_pio - input device's ATA taskfile shadow registers
309 * @ap: Port from which input is read 343 * @ap: Port from which input is read
310 * @tf: ATA taskfile register set for storing input 344 * @tf: ATA taskfile register set for storing input
311 * 345 *
@@ -368,6 +402,23 @@ static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
368 } 402 }
369} 403}
370 404
405
406/**
407 * ata_tf_read - input device's ATA taskfile shadow registers
408 * @ap: Port from which input is read
409 * @tf: ATA taskfile register set for storing input
410 *
411 * Reads ATA taskfile registers for currently-selected device
412 * into @tf.
413 *
414 * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48
415 * is set, also reads the hob registers.
416 *
417 * May be used as the tf_read() entry in ata_port_operations.
418 *
419 * LOCKING:
420 * Inherited from caller.
421 */
371void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 422void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
372{ 423{
373 if (ap->flags & ATA_FLAG_MMIO) 424 if (ap->flags & ATA_FLAG_MMIO)
@@ -381,7 +432,7 @@ void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
381 * @ap: port where the device is 432 * @ap: port where the device is
382 * 433 *
383 * Reads ATA taskfile status register for currently-selected device 434 * Reads ATA taskfile status register for currently-selected device
384 * and return it's value. This also clears pending interrupts 435 * and return its value. This also clears pending interrupts
385 * from this device 436 * from this device
386 * 437 *
387 * LOCKING: 438 * LOCKING:
@@ -397,7 +448,7 @@ static u8 ata_check_status_pio(struct ata_port *ap)
397 * @ap: port where the device is 448 * @ap: port where the device is
398 * 449 *
399 * Reads ATA taskfile status register for currently-selected device 450 * Reads ATA taskfile status register for currently-selected device
400 * via MMIO and return it's value. This also clears pending interrupts 451 * via MMIO and return its value. This also clears pending interrupts
401 * from this device 452 * from this device
402 * 453 *
403 * LOCKING: 454 * LOCKING:
@@ -408,6 +459,20 @@ static u8 ata_check_status_mmio(struct ata_port *ap)
408 return readb((void __iomem *) ap->ioaddr.status_addr); 459 return readb((void __iomem *) ap->ioaddr.status_addr);
409} 460}
410 461
462
463/**
464 * ata_check_status - Read device status reg & clear interrupt
465 * @ap: port where the device is
466 *
467 * Reads ATA taskfile status register for currently-selected device
468 * and return its value. This also clears pending interrupts
469 * from this device
470 *
471 * May be used as the check_status() entry in ata_port_operations.
472 *
473 * LOCKING:
474 * Inherited from caller.
475 */
411u8 ata_check_status(struct ata_port *ap) 476u8 ata_check_status(struct ata_port *ap)
412{ 477{
413 if (ap->flags & ATA_FLAG_MMIO) 478 if (ap->flags & ATA_FLAG_MMIO)
@@ -415,6 +480,20 @@ u8 ata_check_status(struct ata_port *ap)
415 return ata_check_status_pio(ap); 480 return ata_check_status_pio(ap);
416} 481}
417 482
483
484/**
485 * ata_altstatus - Read device alternate status reg
486 * @ap: port where the device is
487 *
488 * Reads ATA taskfile alternate status register for
489 * currently-selected device and return its value.
490 *
491 * Note: may NOT be used as the check_altstatus() entry in
492 * ata_port_operations.
493 *
494 * LOCKING:
495 * Inherited from caller.
496 */
418u8 ata_altstatus(struct ata_port *ap) 497u8 ata_altstatus(struct ata_port *ap)
419{ 498{
420 if (ap->ops->check_altstatus) 499 if (ap->ops->check_altstatus)
@@ -425,6 +504,20 @@ u8 ata_altstatus(struct ata_port *ap)
425 return inb(ap->ioaddr.altstatus_addr); 504 return inb(ap->ioaddr.altstatus_addr);
426} 505}
427 506
507
508/**
509 * ata_chk_err - Read device error reg
510 * @ap: port where the device is
511 *
512 * Reads ATA taskfile error register for
513 * currently-selected device and return its value.
514 *
515 * Note: may NOT be used as the check_err() entry in
516 * ata_port_operations.
517 *
518 * LOCKING:
519 * Inherited from caller.
520 */
428u8 ata_chk_err(struct ata_port *ap) 521u8 ata_chk_err(struct ata_port *ap)
429{ 522{
430 if (ap->ops->check_err) 523 if (ap->ops->check_err)
@@ -873,10 +966,24 @@ void ata_dev_id_string(u16 *id, unsigned char *s,
873 } 966 }
874} 967}
875 968
969
970/**
971 * ata_noop_dev_select - Select device 0/1 on ATA bus
972 * @ap: ATA channel to manipulate
973 * @device: ATA device (numbered from zero) to select
974 *
975 * This function performs no actual function.
976 *
977 * May be used as the dev_select() entry in ata_port_operations.
978 *
979 * LOCKING:
980 * caller.
981 */
876void ata_noop_dev_select (struct ata_port *ap, unsigned int device) 982void ata_noop_dev_select (struct ata_port *ap, unsigned int device)
877{ 983{
878} 984}
879 985
986
880/** 987/**
881 * ata_std_dev_select - Select device 0/1 on ATA bus 988 * ata_std_dev_select - Select device 0/1 on ATA bus
882 * @ap: ATA channel to manipulate 989 * @ap: ATA channel to manipulate
@@ -884,7 +991,9 @@ void ata_noop_dev_select (struct ata_port *ap, unsigned int device)
884 * 991 *
885 * Use the method defined in the ATA specification to 992 * Use the method defined in the ATA specification to
886 * make either device 0, or device 1, active on the 993 * make either device 0, or device 1, active on the
887 * ATA channel. 994 * ATA channel. Works with both PIO and MMIO.
995 *
996 * May be used as the dev_select() entry in ata_port_operations.
888 * 997 *
889 * LOCKING: 998 * LOCKING:
890 * caller. 999 * caller.
@@ -1190,7 +1299,12 @@ err_out:
1190 * ata_bus_probe - Reset and probe ATA bus 1299 * ata_bus_probe - Reset and probe ATA bus
1191 * @ap: Bus to probe 1300 * @ap: Bus to probe
1192 * 1301 *
1302 * Master ATA bus probing function. Initiates a hardware-dependent
1303 * bus reset, then attempts to identify any devices found on
1304 * the bus.
1305 *
1193 * LOCKING: 1306 * LOCKING:
1307 * PCI/etc. bus probe sem.
1194 * 1308 *
1195 * RETURNS: 1309 * RETURNS:
1196 * Zero on success, non-zero on error. 1310 * Zero on success, non-zero on error.
@@ -1229,10 +1343,14 @@ err_out:
1229} 1343}
1230 1344
1231/** 1345/**
1232 * ata_port_probe - 1346 * ata_port_probe - Mark port as enabled
1233 * @ap: 1347 * @ap: Port for which we indicate enablement
1234 * 1348 *
1235 * LOCKING: 1349 * Modify @ap data structure such that the system
1350 * thinks that the entire port is enabled.
1351 *
1352 * LOCKING: host_set lock, or some other form of
1353 * serialization.
1236 */ 1354 */
1237 1355
1238void ata_port_probe(struct ata_port *ap) 1356void ata_port_probe(struct ata_port *ap)
@@ -1241,10 +1359,15 @@ void ata_port_probe(struct ata_port *ap)
1241} 1359}
1242 1360
1243/** 1361/**
1244 * __sata_phy_reset - 1362 * __sata_phy_reset - Wake/reset a low-level SATA PHY
1245 * @ap: 1363 * @ap: SATA port associated with target SATA PHY.
1364 *
1365 * This function issues commands to standard SATA Sxxx
1366 * PHY registers, to wake up the phy (and device), and
1367 * clear any reset condition.
1246 * 1368 *
1247 * LOCKING: 1369 * LOCKING:
1370 * PCI/etc. bus probe sem.
1248 * 1371 *
1249 */ 1372 */
1250void __sata_phy_reset(struct ata_port *ap) 1373void __sata_phy_reset(struct ata_port *ap)
@@ -1289,10 +1412,14 @@ void __sata_phy_reset(struct ata_port *ap)
1289} 1412}
1290 1413
1291/** 1414/**
1292 * __sata_phy_reset - 1415 * sata_phy_reset - Reset SATA bus.
1293 * @ap: 1416 * @ap: SATA port associated with target SATA PHY.
1417 *
1418 * This function resets the SATA bus, and then probes
1419 * the bus for devices.
1294 * 1420 *
1295 * LOCKING: 1421 * LOCKING:
1422 * PCI/etc. bus probe sem.
1296 * 1423 *
1297 */ 1424 */
1298void sata_phy_reset(struct ata_port *ap) 1425void sata_phy_reset(struct ata_port *ap)
@@ -1304,10 +1431,16 @@ void sata_phy_reset(struct ata_port *ap)
1304} 1431}
1305 1432
1306/** 1433/**
1307 * ata_port_disable - 1434 * ata_port_disable - Disable port.
1308 * @ap: 1435 * @ap: Port to be disabled.
1309 * 1436 *
1310 * LOCKING: 1437 * Modify @ap data structure such that the system
1438 * thinks that the entire port is disabled, and should
1439 * never attempt to probe or communicate with devices
1440 * on this port.
1441 *
1442 * LOCKING: host_set lock, or some other form of
1443 * serialization.
1311 */ 1444 */
1312 1445
1313void ata_port_disable(struct ata_port *ap) 1446void ata_port_disable(struct ata_port *ap)
@@ -1416,7 +1549,10 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode,
1416 * ata_set_mode - Program timings and issue SET FEATURES - XFER 1549 * ata_set_mode - Program timings and issue SET FEATURES - XFER
1417 * @ap: port on which timings will be programmed 1550 * @ap: port on which timings will be programmed
1418 * 1551 *
1552 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.).
1553 *
1419 * LOCKING: 1554 * LOCKING:
1555 * PCI/etc. bus probe sem.
1420 * 1556 *
1421 */ 1557 */
1422static void ata_set_mode(struct ata_port *ap) 1558static void ata_set_mode(struct ata_port *ap)
@@ -1467,7 +1603,10 @@ err_out:
1467 * @tmout_pat: impatience timeout 1603 * @tmout_pat: impatience timeout
1468 * @tmout: overall timeout 1604 * @tmout: overall timeout
1469 * 1605 *
1470 * LOCKING: 1606 * Sleep until ATA Status register bit BSY clears,
1607 * or a timeout occurs.
1608 *
1609 * LOCKING: None.
1471 * 1610 *
1472 */ 1611 */
1473 1612
@@ -1553,10 +1692,14 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
1553} 1692}
1554 1693
1555/** 1694/**
1556 * ata_bus_edd - 1695 * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.
1557 * @ap: 1696 * @ap: Port to reset and probe
1697 *
1698 * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and
1699 * probe the bus. Not often used these days.
1558 * 1700 *
1559 * LOCKING: 1701 * LOCKING:
1702 * PCI/etc. bus probe sem.
1560 * 1703 *
1561 */ 1704 */
1562 1705
@@ -1633,8 +1776,8 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
1633 * the device is ATA or ATAPI. 1776 * the device is ATA or ATAPI.
1634 * 1777 *
1635 * LOCKING: 1778 * LOCKING:
1636 * Inherited from caller. Some functions called by this function 1779 * PCI/etc. bus probe sem.
1637 * obtain the host_set lock. 1780 * Obtains host_set lock.
1638 * 1781 *
1639 * SIDE EFFECTS: 1782 * SIDE EFFECTS:
1640 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. 1783 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails.
@@ -1876,7 +2019,11 @@ static int fgb(u32 bitmap)
1876 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code 2019 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code
1877 * @xfer_shift_out: (output) bit shift that selects this mode 2020 * @xfer_shift_out: (output) bit shift that selects this mode
1878 * 2021 *
2022 * Based on host and device capabilities, determine the
2023 * maximum transfer mode that is amenable to all.
2024 *
1879 * LOCKING: 2025 * LOCKING:
2026 * PCI/etc. bus probe sem.
1880 * 2027 *
1881 * RETURNS: 2028 * RETURNS:
1882 * Zero on success, negative on error. 2029 * Zero on success, negative on error.
@@ -1909,7 +2056,11 @@ static int ata_choose_xfer_mode(struct ata_port *ap,
1909 * @ap: Port associated with device @dev 2056 * @ap: Port associated with device @dev
1910 * @dev: Device to which command will be sent 2057 * @dev: Device to which command will be sent
1911 * 2058 *
2059 * Issue SET FEATURES - XFER MODE command to device @dev
2060 * on port @ap.
2061 *
1912 * LOCKING: 2062 * LOCKING:
2063 * PCI/etc. bus probe sem.
1913 */ 2064 */
1914 2065
1915static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) 2066static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
@@ -1947,10 +2098,13 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
1947} 2098}
1948 2099
1949/** 2100/**
1950 * ata_sg_clean - 2101 * ata_sg_clean - Unmap DMA memory associated with command
1951 * @qc: 2102 * @qc: Command containing DMA memory to be released
2103 *
2104 * Unmap all mapped DMA memory associated with this command.
1952 * 2105 *
1953 * LOCKING: 2106 * LOCKING:
2107 * spin_lock_irqsave(host_set lock)
1954 */ 2108 */
1955 2109
1956static void ata_sg_clean(struct ata_queued_cmd *qc) 2110static void ata_sg_clean(struct ata_queued_cmd *qc)
@@ -1981,7 +2135,11 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
1981 * ata_fill_sg - Fill PCI IDE PRD table 2135 * ata_fill_sg - Fill PCI IDE PRD table
1982 * @qc: Metadata associated with taskfile to be transferred 2136 * @qc: Metadata associated with taskfile to be transferred
1983 * 2137 *
2138 * Fill PCI IDE PRD (scatter-gather) table with segments
2139 * associated with the current disk command.
2140 *
1984 * LOCKING: 2141 * LOCKING:
2142 * spin_lock_irqsave(host_set lock)
1985 * 2143 *
1986 */ 2144 */
1987static void ata_fill_sg(struct ata_queued_cmd *qc) 2145static void ata_fill_sg(struct ata_queued_cmd *qc)
@@ -2028,7 +2186,13 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
2028 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported 2186 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported
2029 * @qc: Metadata associated with taskfile to check 2187 * @qc: Metadata associated with taskfile to check
2030 * 2188 *
2189 * Allow low-level driver to filter ATA PACKET commands, returning
2190 * a status indicating whether or not it is OK to use DMA for the
2191 * supplied PACKET command.
2192 *
2031 * LOCKING: 2193 * LOCKING:
2194 * spin_lock_irqsave(host_set lock)
2195 *
2032 * RETURNS: 0 when ATAPI DMA can be used 2196 * RETURNS: 0 when ATAPI DMA can be used
2033 * nonzero otherwise 2197 * nonzero otherwise
2034 */ 2198 */
@@ -2046,6 +2210,8 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
2046 * ata_qc_prep - Prepare taskfile for submission 2210 * ata_qc_prep - Prepare taskfile for submission
2047 * @qc: Metadata associated with taskfile to be prepared 2211 * @qc: Metadata associated with taskfile to be prepared
2048 * 2212 *
2213 * Prepare ATA taskfile for submission.
2214 *
2049 * LOCKING: 2215 * LOCKING:
2050 * spin_lock_irqsave(host_set lock) 2216 * spin_lock_irqsave(host_set lock)
2051 */ 2217 */
@@ -2057,6 +2223,32 @@ void ata_qc_prep(struct ata_queued_cmd *qc)
2057 ata_fill_sg(qc); 2223 ata_fill_sg(qc);
2058} 2224}
2059 2225
2226/**
2227 * ata_sg_init_one - Associate command with memory buffer
2228 * @qc: Command to be associated
2229 * @buf: Memory buffer
2230 * @buflen: Length of memory buffer, in bytes.
2231 *
2232 * Initialize the data-related elements of queued_cmd @qc
2233 * to point to a single memory buffer, @buf of byte length @buflen.
2234 *
2235 * LOCKING:
2236 * spin_lock_irqsave(host_set lock)
2237 */
2238
2239
2240
2241/**
2242 * ata_sg_init_one - Prepare a one-entry scatter-gather list.
2243 * @qc: Queued command
2244 * @buf: transfer buffer
2245 * @buflen: length of buf
2246 *
2247 * Builds a single-entry scatter-gather list to initiate a
2248 * transfer utilizing the specified buffer.
2249 *
2250 * LOCKING:
2251 */
2060void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) 2252void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2061{ 2253{
2062 struct scatterlist *sg; 2254 struct scatterlist *sg;
@@ -2074,6 +2266,32 @@ void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
2074 sg->length = buflen; 2266 sg->length = buflen;
2075} 2267}
2076 2268
2269/**
2270 * ata_sg_init - Associate command with scatter-gather table.
2271 * @qc: Command to be associated
2272 * @sg: Scatter-gather table.
2273 * @n_elem: Number of elements in s/g table.
2274 *
2275 * Initialize the data-related elements of queued_cmd @qc
2276 * to point to a scatter-gather table @sg, containing @n_elem
2277 * elements.
2278 *
2279 * LOCKING:
2280 * spin_lock_irqsave(host_set lock)
2281 */
2282
2283
2284/**
2285 * ata_sg_init - Assign a scatter gather list to a queued command
2286 * @qc: Queued command
2287 * @sg: Scatter-gather list
2288 * @n_elem: length of sg list
2289 *
2290 * Attaches a scatter-gather list to a queued command.
2291 *
2292 * LOCKING:
2293 */
2294
2077void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, 2295void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
2078 unsigned int n_elem) 2296 unsigned int n_elem)
2079{ 2297{
@@ -2083,14 +2301,16 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
2083} 2301}
2084 2302
2085/** 2303/**
2086 * ata_sg_setup_one - 2304 * ata_sg_setup_one - DMA-map the memory buffer associated with a command.
2087 * @qc: 2305 * @qc: Command with memory buffer to be mapped.
2306 *
2307 * DMA-map the memory buffer associated with queued_cmd @qc.
2088 * 2308 *
2089 * LOCKING: 2309 * LOCKING:
2090 * spin_lock_irqsave(host_set lock) 2310 * spin_lock_irqsave(host_set lock)
2091 * 2311 *
2092 * RETURNS: 2312 * RETURNS:
2093 * 2313 * Zero on success, negative on error.
2094 */ 2314 */
2095 2315
2096static int ata_sg_setup_one(struct ata_queued_cmd *qc) 2316static int ata_sg_setup_one(struct ata_queued_cmd *qc)
@@ -2115,13 +2335,16 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2115} 2335}
2116 2336
2117/** 2337/**
2118 * ata_sg_setup - 2338 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
2119 * @qc: 2339 * @qc: Command with scatter-gather table to be mapped.
2340 *
2341 * DMA-map the scatter-gather table associated with queued_cmd @qc.
2120 * 2342 *
2121 * LOCKING: 2343 * LOCKING:
2122 * spin_lock_irqsave(host_set lock) 2344 * spin_lock_irqsave(host_set lock)
2123 * 2345 *
2124 * RETURNS: 2346 * RETURNS:
2347 * Zero on success, negative on error.
2125 * 2348 *
2126 */ 2349 */
2127 2350
@@ -2151,6 +2374,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
2151 * @ap: 2374 * @ap:
2152 * 2375 *
2153 * LOCKING: 2376 * LOCKING:
2377 * None. (executing in kernel thread context)
2154 * 2378 *
2155 * RETURNS: 2379 * RETURNS:
2156 * 2380 *
@@ -2198,6 +2422,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap)
2198 * @ap: 2422 * @ap:
2199 * 2423 *
2200 * LOCKING: 2424 * LOCKING:
2425 * None. (executing in kernel thread context)
2201 */ 2426 */
2202 2427
2203static void ata_pio_complete (struct ata_port *ap) 2428static void ata_pio_complete (struct ata_port *ap)
@@ -2240,6 +2465,18 @@ static void ata_pio_complete (struct ata_port *ap)
2240 ata_qc_complete(qc, drv_stat); 2465 ata_qc_complete(qc, drv_stat);
2241} 2466}
2242 2467
2468
2469/**
2470 * swap_buf_le16 -
2471 * @buf: Buffer to swap
2472 * @buf_words: Number of 16-bit words in buffer.
2473 *
2474 * Swap halves of 16-bit words if needed to convert from
2475 * little-endian byte order to native cpu byte order, or
2476 * vice-versa.
2477 *
2478 * LOCKING:
2479 */
2243void swap_buf_le16(u16 *buf, unsigned int buf_words) 2480void swap_buf_le16(u16 *buf, unsigned int buf_words)
2244{ 2481{
2245#ifdef __BIG_ENDIAN 2482#ifdef __BIG_ENDIAN
@@ -2340,7 +2577,6 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
2340next_sg: 2577next_sg:
2341 sg = &qc->sg[qc->cursg]; 2578 sg = &qc->sg[qc->cursg];
2342 2579
2343next_page:
2344 page = sg->page; 2580 page = sg->page;
2345 offset = sg->offset + qc->cursg_ofs; 2581 offset = sg->offset + qc->cursg_ofs;
2346 2582
@@ -2348,6 +2584,7 @@ next_page:
2348 page = nth_page(page, (offset >> PAGE_SHIFT)); 2584 page = nth_page(page, (offset >> PAGE_SHIFT));
2349 offset %= PAGE_SIZE; 2585 offset %= PAGE_SIZE;
2350 2586
2587 /* don't overrun current sg */
2351 count = min(sg->length - qc->cursg_ofs, bytes); 2588 count = min(sg->length - qc->cursg_ofs, bytes);
2352 2589
2353 /* don't cross page boundaries */ 2590 /* don't cross page boundaries */
@@ -2372,8 +2609,6 @@ next_page:
2372 kunmap(page); 2609 kunmap(page);
2373 2610
2374 if (bytes) { 2611 if (bytes) {
2375 if (qc->cursg_ofs < sg->length)
2376 goto next_page;
2377 goto next_sg; 2612 goto next_sg;
2378 } 2613 }
2379} 2614}
@@ -2415,6 +2650,7 @@ err_out:
2415 * @ap: 2650 * @ap:
2416 * 2651 *
2417 * LOCKING: 2652 * LOCKING:
2653 * None. (executing in kernel thread context)
2418 */ 2654 */
2419 2655
2420static void ata_pio_block(struct ata_port *ap) 2656static void ata_pio_block(struct ata_port *ap)
@@ -2583,6 +2819,7 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
2583 * transaction completed successfully. 2819 * transaction completed successfully.
2584 * 2820 *
2585 * LOCKING: 2821 * LOCKING:
2822 * Inherited from SCSI layer (none, can sleep)
2586 */ 2823 */
2587 2824
2588static void ata_qc_timeout(struct ata_queued_cmd *qc) 2825static void ata_qc_timeout(struct ata_queued_cmd *qc)
@@ -2692,6 +2929,7 @@ out:
2692 * @dev: Device from whom we request an available command structure 2929 * @dev: Device from whom we request an available command structure
2693 * 2930 *
2694 * LOCKING: 2931 * LOCKING:
2932 * None.
2695 */ 2933 */
2696 2934
2697static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) 2935static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
@@ -2717,6 +2955,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
2717 * @dev: Device from whom we request an available command structure 2955 * @dev: Device from whom we request an available command structure
2718 * 2956 *
2719 * LOCKING: 2957 * LOCKING:
2958 * None.
2720 */ 2959 */
2721 2960
2722struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, 2961struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
@@ -2781,6 +3020,7 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc)
2781 * in case something prevents using it. 3020 * in case something prevents using it.
2782 * 3021 *
2783 * LOCKING: 3022 * LOCKING:
3023 * spin_lock_irqsave(host_set lock)
2784 * 3024 *
2785 */ 3025 */
2786void ata_qc_free(struct ata_queued_cmd *qc) 3026void ata_qc_free(struct ata_queued_cmd *qc)
@@ -2794,9 +3034,13 @@ void ata_qc_free(struct ata_queued_cmd *qc)
2794/** 3034/**
2795 * ata_qc_complete - Complete an active ATA command 3035 * ata_qc_complete - Complete an active ATA command
2796 * @qc: Command to complete 3036 * @qc: Command to complete
2797 * @drv_stat: ATA status register contents 3037 * @drv_stat: ATA Status register contents
3038 *
3039 * Indicate to the mid and upper layers that an ATA
3040 * command has completed, with either an ok or not-ok status.
2798 * 3041 *
2799 * LOCKING: 3042 * LOCKING:
3043 * spin_lock_irqsave(host_set lock)
2800 * 3044 *
2801 */ 3045 */
2802 3046
@@ -2892,6 +3136,7 @@ err_out:
2892 return -1; 3136 return -1;
2893} 3137}
2894 3138
3139
2895/** 3140/**
2896 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner 3141 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
2897 * @qc: command to issue to device 3142 * @qc: command to issue to device
@@ -2901,6 +3146,8 @@ err_out:
2901 * classes called "protocols", and issuing each type of protocol 3146 * classes called "protocols", and issuing each type of protocol
2902 * is slightly different. 3147 * is slightly different.
2903 * 3148 *
3149 * May be used as the qc_issue() entry in ata_port_operations.
3150 *
2904 * LOCKING: 3151 * LOCKING:
2905 * spin_lock_irqsave(host_set lock) 3152 * spin_lock_irqsave(host_set lock)
2906 * 3153 *
@@ -2958,7 +3205,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc)
2958} 3205}
2959 3206
2960/** 3207/**
2961 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction 3208 * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction
2962 * @qc: Info associated with this ATA transaction. 3209 * @qc: Info associated with this ATA transaction.
2963 * 3210 *
2964 * LOCKING: 3211 * LOCKING:
@@ -3065,6 +3312,18 @@ static void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
3065 ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 3312 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
3066} 3313}
3067 3314
3315
3316/**
3317 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
3318 * @qc: Info associated with this ATA transaction.
3319 *
3320 * Writes the ATA_DMA_START flag to the DMA command register.
3321 *
3322 * May be used as the bmdma_start() entry in ata_port_operations.
3323 *
3324 * LOCKING:
3325 * spin_lock_irqsave(host_set lock)
3326 */
3068void ata_bmdma_start(struct ata_queued_cmd *qc) 3327void ata_bmdma_start(struct ata_queued_cmd *qc)
3069{ 3328{
3070 if (qc->ap->flags & ATA_FLAG_MMIO) 3329 if (qc->ap->flags & ATA_FLAG_MMIO)
@@ -3073,6 +3332,20 @@ void ata_bmdma_start(struct ata_queued_cmd *qc)
3073 ata_bmdma_start_pio(qc); 3332 ata_bmdma_start_pio(qc);
3074} 3333}
3075 3334
3335
3336/**
3337 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
3338 * @qc: Info associated with this ATA transaction.
3339 *
3340 * Writes address of PRD table to device's PRD Table Address
3341 * register, sets the DMA control register, and calls
3342 * ops->exec_command() to start the transfer.
3343 *
3344 * May be used as the bmdma_setup() entry in ata_port_operations.
3345 *
3346 * LOCKING:
3347 * spin_lock_irqsave(host_set lock)
3348 */
3076void ata_bmdma_setup(struct ata_queued_cmd *qc) 3349void ata_bmdma_setup(struct ata_queued_cmd *qc)
3077{ 3350{
3078 if (qc->ap->flags & ATA_FLAG_MMIO) 3351 if (qc->ap->flags & ATA_FLAG_MMIO)
@@ -3081,6 +3354,19 @@ void ata_bmdma_setup(struct ata_queued_cmd *qc)
3081 ata_bmdma_setup_pio(qc); 3354 ata_bmdma_setup_pio(qc);
3082} 3355}
3083 3356
3357
3358/**
3359 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
3360 * @ap: Port associated with this ATA transaction.
3361 *
3362 * Clear interrupt and error flags in DMA status register.
3363 *
3364 * May be used as the irq_clear() entry in ata_port_operations.
3365 *
3366 * LOCKING:
3367 * spin_lock_irqsave(host_set lock)
3368 */
3369
3084void ata_bmdma_irq_clear(struct ata_port *ap) 3370void ata_bmdma_irq_clear(struct ata_port *ap)
3085{ 3371{
3086 if (ap->flags & ATA_FLAG_MMIO) { 3372 if (ap->flags & ATA_FLAG_MMIO) {
@@ -3093,6 +3379,19 @@ void ata_bmdma_irq_clear(struct ata_port *ap)
3093 3379
3094} 3380}
3095 3381
3382
3383/**
3384 * ata_bmdma_status - Read PCI IDE BMDMA status
3385 * @ap: Port associated with this ATA transaction.
3386 *
3387 * Read and return BMDMA status register.
3388 *
3389 * May be used as the bmdma_status() entry in ata_port_operations.
3390 *
3391 * LOCKING:
3392 * spin_lock_irqsave(host_set lock)
3393 */
3394
3096u8 ata_bmdma_status(struct ata_port *ap) 3395u8 ata_bmdma_status(struct ata_port *ap)
3097{ 3396{
3098 u8 host_stat; 3397 u8 host_stat;
@@ -3104,6 +3403,19 @@ u8 ata_bmdma_status(struct ata_port *ap)
3104 return host_stat; 3403 return host_stat;
3105} 3404}
3106 3405
3406
3407/**
3408 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
3409 * @ap: Port associated with this ATA transaction.
3410 *
3411 * Clears the ATA_DMA_START flag in the dma control register
3412 *
3413 * May be used as the bmdma_stop() entry in ata_port_operations.
3414 *
3415 * LOCKING:
3416 * spin_lock_irqsave(host_set lock)
3417 */
3418
3107void ata_bmdma_stop(struct ata_port *ap) 3419void ata_bmdma_stop(struct ata_port *ap)
3108{ 3420{
3109 if (ap->flags & ATA_FLAG_MMIO) { 3421 if (ap->flags & ATA_FLAG_MMIO) {
@@ -3203,13 +3515,18 @@ idle_irq:
3203 3515
3204/** 3516/**
3205 * ata_interrupt - Default ATA host interrupt handler 3517 * ata_interrupt - Default ATA host interrupt handler
3206 * @irq: irq line 3518 * @irq: irq line (unused)
3207 * @dev_instance: pointer to our host information structure 3519 * @dev_instance: pointer to our ata_host_set information structure
3208 * @regs: unused 3520 * @regs: unused
3209 * 3521 *
3522 * Default interrupt handler for PCI IDE devices. Calls
3523 * ata_host_intr() for each port that is not disabled.
3524 *
3210 * LOCKING: 3525 * LOCKING:
3526 * Obtains host_set lock during operation.
3211 * 3527 *
3212 * RETURNS: 3528 * RETURNS:
3529 * IRQ_NONE or IRQ_HANDLED.
3213 * 3530 *
3214 */ 3531 */
3215 3532
@@ -3302,6 +3619,19 @@ err_out:
3302 ata_qc_complete(qc, ATA_ERR); 3619 ata_qc_complete(qc, ATA_ERR);
3303} 3620}
3304 3621
3622
3623/**
3624 * ata_port_start - Set port up for dma.
3625 * @ap: Port to initialize
3626 *
3627 * Called just after data structures for each port are
3628 * initialized. Allocates space for PRD table.
3629 *
3630 * May be used as the port_start() entry in ata_port_operations.
3631 *
3632 * LOCKING:
3633 */
3634
3305int ata_port_start (struct ata_port *ap) 3635int ata_port_start (struct ata_port *ap)
3306{ 3636{
3307 struct device *dev = ap->host_set->dev; 3637 struct device *dev = ap->host_set->dev;
@@ -3315,6 +3645,18 @@ int ata_port_start (struct ata_port *ap)
3315 return 0; 3645 return 0;
3316} 3646}
3317 3647
3648
3649/**
3650 * ata_port_stop - Undo ata_port_start()
3651 * @ap: Port to shut down
3652 *
3653 * Frees the PRD table.
3654 *
3655 * May be used as the port_stop() entry in ata_port_operations.
3656 *
3657 * LOCKING:
3658 */
3659
3318void ata_port_stop (struct ata_port *ap) 3660void ata_port_stop (struct ata_port *ap)
3319{ 3661{
3320 struct device *dev = ap->host_set->dev; 3662 struct device *dev = ap->host_set->dev;
@@ -3357,7 +3699,11 @@ static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister)
3357 * @ent: Probe information provided by low-level driver 3699 * @ent: Probe information provided by low-level driver
3358 * @port_no: Port number associated with this ata_port 3700 * @port_no: Port number associated with this ata_port
3359 * 3701 *
3702 * Initialize a new ata_port structure, and its associated
3703 * scsi_host.
3704 *
3360 * LOCKING: 3705 * LOCKING:
3706 * Inherited from caller.
3361 * 3707 *
3362 */ 3708 */
3363 3709
@@ -3412,9 +3758,13 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
3412 * @host_set: Collections of ports to which we add 3758 * @host_set: Collections of ports to which we add
3413 * @port_no: Port number associated with this host 3759 * @port_no: Port number associated with this host
3414 * 3760 *
3761 * Attach low-level ATA driver to system.
3762 *
3415 * LOCKING: 3763 * LOCKING:
3764 * PCI/etc. bus probe sem.
3416 * 3765 *
3417 * RETURNS: 3766 * RETURNS:
3767 * New ata_port on success, for NULL on error.
3418 * 3768 *
3419 */ 3769 */
3420 3770
@@ -3447,12 +3797,22 @@ err_out:
3447} 3797}
3448 3798
3449/** 3799/**
3450 * ata_device_add - 3800 * ata_device_add - Register hardware device with ATA and SCSI layers
3451 * @ent: 3801 * @ent: Probe information describing hardware device to be registered
3802 *
3803 * This function processes the information provided in the probe
3804 * information struct @ent, allocates the necessary ATA and SCSI
3805 * host information structures, initializes them, and registers
3806 * everything with requisite kernel subsystems.
3807 *
3808 * This function requests irqs, probes the ATA bus, and probes
3809 * the SCSI bus.
3452 * 3810 *
3453 * LOCKING: 3811 * LOCKING:
3812 * PCI/etc. bus probe sem.
3454 * 3813 *
3455 * RETURNS: 3814 * RETURNS:
3815 * Number of ports registered. Zero on error (no ports registered).
3456 * 3816 *
3457 */ 3817 */
3458 3818
@@ -3604,7 +3964,15 @@ int ata_scsi_release(struct Scsi_Host *host)
3604/** 3964/**
3605 * ata_std_ports - initialize ioaddr with standard port offsets. 3965 * ata_std_ports - initialize ioaddr with standard port offsets.
3606 * @ioaddr: IO address structure to be initialized 3966 * @ioaddr: IO address structure to be initialized
3967 *
3968 * Utility function which initializes data_addr, error_addr,
3969 * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
3970 * device_addr, status_addr, and command_addr to standard offsets
3971 * relative to cmd_addr.
3972 *
3973 * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
3607 */ 3974 */
3975
3608void ata_std_ports(struct ata_ioports *ioaddr) 3976void ata_std_ports(struct ata_ioports *ioaddr)
3609{ 3977{
3610 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; 3978 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;
@@ -3646,6 +4014,20 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port)
3646 return probe_ent; 4014 return probe_ent;
3647} 4015}
3648 4016
4017
4018
4019/**
4020 * ata_pci_init_native_mode - Initialize native-mode driver
4021 * @pdev: pci device to be initialized
4022 * @port: array[2] of pointers to port info structures.
4023 *
4024 * Utility function which allocates and initializes an
4025 * ata_probe_ent structure for a standard dual-port
4026 * PIO-based IDE controller. The returned ata_probe_ent
4027 * structure can be passed to ata_device_add(). The returned
4028 * ata_probe_ent structure should then be freed with kfree().
4029 */
4030
3649#ifdef CONFIG_PCI 4031#ifdef CONFIG_PCI
3650struct ata_probe_ent * 4032struct ata_probe_ent *
3651ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) 4033ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port)
@@ -3727,10 +4109,19 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port,
3727 * @port_info: Information from low-level host driver 4109 * @port_info: Information from low-level host driver
3728 * @n_ports: Number of ports attached to host controller 4110 * @n_ports: Number of ports attached to host controller
3729 * 4111 *
4112 * This is a helper function which can be called from a driver's
4113 * xxx_init_one() probe function if the hardware uses traditional
4114 * IDE taskfile registers.
4115 *
4116 * This function calls pci_enable_device(), reserves its register
4117 * regions, sets the dma mask, enables bus master mode, and calls
4118 * ata_device_add()
4119 *
3730 * LOCKING: 4120 * LOCKING:
3731 * Inherited from PCI layer (may sleep). 4121 * Inherited from PCI layer (may sleep).
3732 * 4122 *
3733 * RETURNS: 4123 * RETURNS:
4124 * Zero on success, negative on errno-based value on error.
3734 * 4125 *
3735 */ 4126 */
3736 4127
@@ -3949,15 +4340,6 @@ int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits)
3949#endif /* CONFIG_PCI */ 4340#endif /* CONFIG_PCI */
3950 4341
3951 4342
3952/**
3953 * ata_init -
3954 *
3955 * LOCKING:
3956 *
3957 * RETURNS:
3958 *
3959 */
3960
3961static int __init ata_init(void) 4343static int __init ata_init(void)
3962{ 4344{
3963 ata_wq = create_workqueue("ata"); 4345 ata_wq = create_workqueue("ata");
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 416ba67ba9ee..7a4adc4c8f09 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -947,7 +947,7 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
947} 947}
948 948
949/** 949/**
950 * ata_scsiop_noop - 950 * ata_scsiop_noop - Command handler that simply returns success.
951 * @args: device IDENTIFY data / SCSI command of interest. 951 * @args: device IDENTIFY data / SCSI command of interest.
952 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. 952 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.
953 * @buflen: Response buffer length. 953 * @buflen: Response buffer length.
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 579448222d69..3c97aa45772d 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -507,6 +507,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
507 int ret, i; 507 int ret, i;
508 unsigned int id, lun; 508 unsigned int id, lun;
509 unsigned long serial; 509 unsigned long serial;
510 unsigned long flags;
510 511
511 if (!CMD_SP(cmd)) 512 if (!CMD_SP(cmd))
512 return FAILED; 513 return FAILED;
@@ -519,7 +520,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
519 520
520 /* Check active list for command command. */ 521 /* Check active list for command command. */
521 spin_unlock_irq(ha->host->host_lock); 522 spin_unlock_irq(ha->host->host_lock);
522 spin_lock(&ha->hardware_lock); 523 spin_lock_irqsave(&ha->hardware_lock, flags);
523 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { 524 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
524 sp = ha->outstanding_cmds[i]; 525 sp = ha->outstanding_cmds[i];
525 526
@@ -534,7 +535,7 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
534 sp->state)); 535 sp->state));
535 DEBUG3(qla2x00_print_scsi_cmd(cmd);) 536 DEBUG3(qla2x00_print_scsi_cmd(cmd);)
536 537
537 spin_unlock(&ha->hardware_lock); 538 spin_unlock_irqrestore(&ha->hardware_lock, flags);
538 if (qla2x00_abort_command(ha, sp)) { 539 if (qla2x00_abort_command(ha, sp)) {
539 DEBUG2(printk("%s(%ld): abort_command " 540 DEBUG2(printk("%s(%ld): abort_command "
540 "mbx failed.\n", __func__, ha->host_no)); 541 "mbx failed.\n", __func__, ha->host_no));
@@ -543,20 +544,19 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
543 "mbx success.\n", __func__, ha->host_no)); 544 "mbx success.\n", __func__, ha->host_no));
544 ret = SUCCESS; 545 ret = SUCCESS;
545 } 546 }
546 spin_lock(&ha->hardware_lock); 547 spin_lock_irqsave(&ha->hardware_lock, flags);
547 548
548 break; 549 break;
549 } 550 }
551 spin_unlock_irqrestore(&ha->hardware_lock, flags);
550 552
551 /* Wait for the command to be returned. */ 553 /* Wait for the command to be returned. */
552 if (ret == SUCCESS) { 554 if (ret == SUCCESS) {
553 spin_unlock(&ha->hardware_lock);
554 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) { 555 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) {
555 qla_printk(KERN_ERR, ha, 556 qla_printk(KERN_ERR, ha,
556 "scsi(%ld:%d:%d): Abort handler timed out -- %lx " 557 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
557 "%x.\n", ha->host_no, id, lun, serial, ret); 558 "%x.\n", ha->host_no, id, lun, serial, ret);
558 } 559 }
559 spin_lock(&ha->hardware_lock);
560 } 560 }
561 spin_lock_irq(ha->host->host_lock); 561 spin_lock_irq(ha->host->host_lock);
562 562
@@ -588,6 +588,7 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
588 int status; 588 int status;
589 srb_t *sp; 589 srb_t *sp;
590 struct scsi_cmnd *cmd; 590 struct scsi_cmnd *cmd;
591 unsigned long flags;
591 592
592 status = 0; 593 status = 0;
593 594
@@ -596,11 +597,11 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
596 * array 597 * array
597 */ 598 */
598 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 599 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
599 spin_lock(&ha->hardware_lock); 600 spin_lock_irqsave(&ha->hardware_lock, flags);
600 sp = ha->outstanding_cmds[cnt]; 601 sp = ha->outstanding_cmds[cnt];
601 if (sp) { 602 if (sp) {
602 cmd = sp->cmd; 603 cmd = sp->cmd;
603 spin_unlock(&ha->hardware_lock); 604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
604 if (cmd->device->id == t) { 605 if (cmd->device->id == t) {
605 if (!qla2x00_eh_wait_on_command(ha, cmd)) { 606 if (!qla2x00_eh_wait_on_command(ha, cmd)) {
606 status = 1; 607 status = 1;
@@ -608,7 +609,7 @@ qla2x00_eh_wait_for_pending_target_commands(scsi_qla_host_t *ha, unsigned int t)
608 } 609 }
609 } 610 }
610 } else { 611 } else {
611 spin_unlock(&ha->hardware_lock); 612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
612 } 613 }
613 } 614 }
614 return (status); 615 return (status);
@@ -740,6 +741,7 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
740 int status; 741 int status;
741 srb_t *sp; 742 srb_t *sp;
742 struct scsi_cmnd *cmd; 743 struct scsi_cmnd *cmd;
744 unsigned long flags;
743 745
744 status = 1; 746 status = 1;
745 747
@@ -748,17 +750,17 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha)
748 * array 750 * array
749 */ 751 */
750 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 752 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
751 spin_lock(&ha->hardware_lock); 753 spin_lock_irqsave(&ha->hardware_lock, flags);
752 sp = ha->outstanding_cmds[cnt]; 754 sp = ha->outstanding_cmds[cnt];
753 if (sp) { 755 if (sp) {
754 cmd = sp->cmd; 756 cmd = sp->cmd;
755 spin_unlock(&ha->hardware_lock); 757 spin_unlock_irqrestore(&ha->hardware_lock, flags);
756 status = qla2x00_eh_wait_on_command(ha, cmd); 758 status = qla2x00_eh_wait_on_command(ha, cmd);
757 if (status == 0) 759 if (status == 0)
758 break; 760 break;
759 } 761 }
760 else { 762 else {
761 spin_unlock(&ha->hardware_lock); 763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
762 } 764 }
763 } 765 }
764 return (status); 766 return (status);
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 238580d244e6..49ed557a4b66 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -432,7 +432,13 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
432 writeb(cls, mmio_base + SIL_FIFO_R0); 432 writeb(cls, mmio_base + SIL_FIFO_R0);
433 writeb(cls, mmio_base + SIL_FIFO_W0); 433 writeb(cls, mmio_base + SIL_FIFO_W0);
434 writeb(cls, mmio_base + SIL_FIFO_R1); 434 writeb(cls, mmio_base + SIL_FIFO_R1);
435 writeb(cls, mmio_base + SIL_FIFO_W2); 435 writeb(cls, mmio_base + SIL_FIFO_W1);
436 if (ent->driver_data == sil_3114) {
437 writeb(cls, mmio_base + SIL_FIFO_R2);
438 writeb(cls, mmio_base + SIL_FIFO_W2);
439 writeb(cls, mmio_base + SIL_FIFO_R3);
440 writeb(cls, mmio_base + SIL_FIFO_W3);
441 }
436 } else 442 } else
437 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n", 443 printk(KERN_WARNING DRV_NAME "(%s): cache line size not set. Driver may not function\n",
438 pci_name(pdev)); 444 pci_name(pdev));
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index cca772624ae7..8d0d302844a1 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1197,6 +1197,7 @@ struct scsi_device *__scsi_add_device(struct Scsi_Host *shost, uint channel,
1197 if (!starget) 1197 if (!starget)
1198 return ERR_PTR(-ENOMEM); 1198 return ERR_PTR(-ENOMEM);
1199 1199
1200 get_device(&starget->dev);
1200 down(&shost->scan_mutex); 1201 down(&shost->scan_mutex);
1201 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata); 1202 res = scsi_probe_and_add_lun(starget, lun, NULL, &sdev, 1, hostdata);
1202 if (res != SCSI_SCAN_LUN_PRESENT) 1203 if (res != SCSI_SCAN_LUN_PRESENT)
diff --git a/drivers/serial/sa1100.c b/drivers/serial/sa1100.c
index 22565a67a57c..98641c3f5ab9 100644
--- a/drivers/serial/sa1100.c
+++ b/drivers/serial/sa1100.c
@@ -197,7 +197,7 @@ static void
197sa1100_rx_chars(struct sa1100_port *sport, struct pt_regs *regs) 197sa1100_rx_chars(struct sa1100_port *sport, struct pt_regs *regs)
198{ 198{
199 struct tty_struct *tty = sport->port.info->tty; 199 struct tty_struct *tty = sport->port.info->tty;
200 unsigned int status, ch, flg, ignored = 0; 200 unsigned int status, ch, flg;
201 201
202 status = UTSR1_TO_SM(UART_GET_UTSR1(sport)) | 202 status = UTSR1_TO_SM(UART_GET_UTSR1(sport)) |
203 UTSR0_TO_SM(UART_GET_UTSR0(sport)); 203 UTSR0_TO_SM(UART_GET_UTSR0(sport));
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index 5d2ceb623e6f..1f985327b0d4 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -234,7 +234,7 @@ static inline const char *siu_type_name(struct uart_port *port)
234 return "DSIU"; 234 return "DSIU";
235 } 235 }
236 236
237 return "unknown"; 237 return NULL;
238} 238}
239 239
240static unsigned int siu_tx_empty(struct uart_port *port) 240static unsigned int siu_tx_empty(struct uart_port *port)
@@ -482,9 +482,6 @@ static irqreturn_t siu_interrupt(int irq, void *dev_id, struct pt_regs *regs)
482 struct uart_port *port; 482 struct uart_port *port;
483 uint8_t iir, lsr; 483 uint8_t iir, lsr;
484 484
485 if (dev_id == NULL)
486 return IRQ_NONE;
487
488 port = (struct uart_port *)dev_id; 485 port = (struct uart_port *)dev_id;
489 486
490 iir = siu_read(port, UART_IIR); 487 iir = siu_read(port, UART_IIR);
@@ -507,6 +504,9 @@ static int siu_startup(struct uart_port *port)
507{ 504{
508 int retval; 505 int retval;
509 506
507 if (port->membase == NULL)
508 return -ENODEV;
509
510 siu_clear_fifo(port); 510 siu_clear_fifo(port);
511 511
512 (void)siu_read(port, UART_LSR); 512 (void)siu_read(port, UART_LSR);
@@ -545,9 +545,6 @@ static void siu_shutdown(struct uart_port *port)
545 unsigned long flags; 545 unsigned long flags;
546 uint8_t lcr; 546 uint8_t lcr;
547 547
548 if (port->membase == NULL)
549 return;
550
551 siu_write(port, UART_IER, 0); 548 siu_write(port, UART_IER, 0);
552 549
553 spin_lock_irqsave(&port->lock, flags); 550 spin_lock_irqsave(&port->lock, flags);
@@ -802,53 +799,6 @@ static int siu_init_ports(void)
802 799
803#ifdef CONFIG_SERIAL_VR41XX_CONSOLE 800#ifdef CONFIG_SERIAL_VR41XX_CONSOLE
804 801
805static void early_set_termios(struct uart_port *port, struct termios *new,
806 struct termios *old)
807{
808 tcflag_t c_cflag;
809 uint8_t lcr;
810 unsigned int baud, quot;
811
812 c_cflag = new->c_cflag;
813 switch (c_cflag & CSIZE) {
814 case CS5:
815 lcr = UART_LCR_WLEN5;
816 break;
817 case CS6:
818 lcr = UART_LCR_WLEN6;
819 break;
820 case CS7:
821 lcr = UART_LCR_WLEN7;
822 break;
823 default:
824 lcr = UART_LCR_WLEN8;
825 break;
826 }
827
828 if (c_cflag & CSTOPB)
829 lcr |= UART_LCR_STOP;
830 if (c_cflag & PARENB)
831 lcr |= UART_LCR_PARITY;
832 if ((c_cflag & PARODD) != PARODD)
833 lcr |= UART_LCR_EPAR;
834 if (c_cflag & CMSPAR)
835 lcr |= UART_LCR_SPAR;
836
837 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk/16);
838 quot = uart_get_divisor(port, baud);
839
840 siu_write(port, UART_LCR, lcr | UART_LCR_DLAB);
841
842 siu_write(port, UART_DLL, (uint8_t)quot);
843 siu_write(port, UART_DLM, (uint8_t)(quot >> 8));
844
845 siu_write(port, UART_LCR, lcr);
846}
847
848static struct uart_ops early_uart_ops = {
849 .set_termios = early_set_termios,
850};
851
852#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 802#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
853 803
854static void wait_for_xmitr(struct uart_port *port) 804static void wait_for_xmitr(struct uart_port *port)
@@ -915,7 +865,7 @@ static int siu_console_setup(struct console *con, char *options)
915 if (port->membase == NULL) { 865 if (port->membase == NULL) {
916 if (port->mapbase == 0) 866 if (port->mapbase == 0)
917 return -ENODEV; 867 return -ENODEV;
918 port->membase = (unsigned char __iomem *)KSEG1ADDR(port->mapbase); 868 port->membase = ioremap(port->mapbase, siu_port_size(port));
919 } 869 }
920 870
921 vr41xx_select_siu_interface(SIU_INTERFACE_RS232C); 871 vr41xx_select_siu_interface(SIU_INTERFACE_RS232C);
@@ -949,7 +899,7 @@ static int __devinit siu_console_init(void)
949 899
950 for (i = 0; i < num; i++) { 900 for (i = 0; i < num; i++) {
951 port = &siu_uart_ports[i]; 901 port = &siu_uart_ports[i];
952 port->ops = &early_uart_ops; 902 port->ops = &siu_uart_ops;
953 } 903 }
954 904
955 register_console(&siu_console); 905 register_console(&siu_console);
@@ -994,8 +944,10 @@ static int siu_probe(struct device *dev)
994 port->dev = dev; 944 port->dev = dev;
995 945
996 retval = uart_add_one_port(&siu_uart_driver, port); 946 retval = uart_add_one_port(&siu_uart_driver, port);
997 if (retval) 947 if (retval < 0) {
948 port->dev = NULL;
998 break; 949 break;
950 }
999 } 951 }
1000 952
1001 if (i == 0 && retval < 0) { 953 if (i == 0 && retval < 0) {
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 4ab50009291d..4d0c9e65cd03 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -290,32 +290,30 @@ static ssize_t show_modalias(struct device *dev, char *buf)
290{ 290{
291 struct usb_interface *intf; 291 struct usb_interface *intf;
292 struct usb_device *udev; 292 struct usb_device *udev;
293 int len;
293 294
294 intf = to_usb_interface(dev); 295 intf = to_usb_interface(dev);
295 udev = interface_to_usbdev(intf); 296 udev = interface_to_usbdev(intf);
296 if (udev->descriptor.bDeviceClass == 0) {
297 struct usb_host_interface *alt = intf->cur_altsetting;
298 297
299 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X\n", 298 len = sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic",
300 le16_to_cpu(udev->descriptor.idVendor), 299 le16_to_cpu(udev->descriptor.idVendor),
301 le16_to_cpu(udev->descriptor.idProduct), 300 le16_to_cpu(udev->descriptor.idProduct),
302 le16_to_cpu(udev->descriptor.bcdDevice), 301 le16_to_cpu(udev->descriptor.bcdDevice),
303 udev->descriptor.bDeviceClass, 302 udev->descriptor.bDeviceClass,
304 udev->descriptor.bDeviceSubClass, 303 udev->descriptor.bDeviceSubClass,
305 udev->descriptor.bDeviceProtocol, 304 udev->descriptor.bDeviceProtocol);
305 buf += len;
306
307 if (udev->descriptor.bDeviceClass == 0) {
308 struct usb_host_interface *alt = intf->cur_altsetting;
309
310 return len + sprintf(buf, "%02Xisc%02Xip%02X\n",
306 alt->desc.bInterfaceClass, 311 alt->desc.bInterfaceClass,
307 alt->desc.bInterfaceSubClass, 312 alt->desc.bInterfaceSubClass,
308 alt->desc.bInterfaceProtocol); 313 alt->desc.bInterfaceProtocol);
309 } else { 314 } else {
310 return sprintf(buf, "usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic*isc*ip*\n", 315 return len + sprintf(buf, "*isc*ip*\n");
311 le16_to_cpu(udev->descriptor.idVendor),
312 le16_to_cpu(udev->descriptor.idProduct),
313 le16_to_cpu(udev->descriptor.bcdDevice),
314 udev->descriptor.bDeviceClass,
315 udev->descriptor.bDeviceSubClass,
316 udev->descriptor.bDeviceProtocol);
317 } 316 }
318
319} 317}
320static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); 318static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
321 319
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 429330bc38de..d7b4f7939ded 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -439,9 +439,12 @@ static int ehci_hub_control (
439 /* force reset to complete */ 439 /* force reset to complete */
440 writel (temp & ~PORT_RESET, 440 writel (temp & ~PORT_RESET,
441 &ehci->regs->port_status [wIndex]); 441 &ehci->regs->port_status [wIndex]);
442 /* REVISIT: some hardware needs 550+ usec to clear
443 * this bit; seems too long to spin routinely...
444 */
442 retval = handshake ( 445 retval = handshake (
443 &ehci->regs->port_status [wIndex], 446 &ehci->regs->port_status [wIndex],
444 PORT_RESET, 0, 500); 447 PORT_RESET, 0, 750);
445 if (retval != 0) { 448 if (retval != 0) {
446 ehci_err (ehci, "port %d reset error %d\n", 449 ehci_err (ehci, "port %d reset error %d\n",
447 wIndex + 1, retval); 450 wIndex + 1, retval);
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 869ff73690ac..2d8bd9dcc6ed 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1315,6 +1315,8 @@ void hid_init_reports(struct hid_device *hid)
1315#define USB_DEVICE_ID_WACOM_INTUOS2 0x0040 1315#define USB_DEVICE_ID_WACOM_INTUOS2 0x0040
1316#define USB_DEVICE_ID_WACOM_VOLITO 0x0060 1316#define USB_DEVICE_ID_WACOM_VOLITO 0x0060
1317#define USB_DEVICE_ID_WACOM_PTU 0x0003 1317#define USB_DEVICE_ID_WACOM_PTU 0x0003
1318#define USB_DEVICE_ID_WACOM_INTUOS3 0x00B0
1319#define USB_DEVICE_ID_WACOM_CINTIQ 0x003F
1318 1320
1319#define USB_VENDOR_ID_KBGEAR 0x084e 1321#define USB_VENDOR_ID_KBGEAR 0x084e
1320#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001 1322#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
@@ -1401,6 +1403,7 @@ void hid_init_reports(struct hid_device *hid)
1401 1403
1402#define USB_VENDOR_ID_DELORME 0x1163 1404#define USB_VENDOR_ID_DELORME 0x1163
1403#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100 1405#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
1406#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
1404 1407
1405#define USB_VENDOR_ID_MCC 0x09db 1408#define USB_VENDOR_ID_MCC 0x09db
1406#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 1409#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
@@ -1412,6 +1415,12 @@ void hid_init_reports(struct hid_device *hid)
1412#define USB_VENDOR_ID_BTC 0x046e 1415#define USB_VENDOR_ID_BTC 0x046e
1413#define USB_DEVICE_ID_BTC_KEYBOARD 0x5303 1416#define USB_DEVICE_ID_BTC_KEYBOARD 0x5303
1414 1417
1418#define USB_VENDOR_ID_VERNIER 0x08f7
1419#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
1420#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
1421#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
1422#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1423
1415 1424
1416/* 1425/*
1417 * Alphabetically sorted blacklist by quirk type. 1426 * Alphabetically sorted blacklist by quirk type.
@@ -1437,6 +1446,7 @@ static struct hid_blacklist {
1437 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE }, 1446 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
1438 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, 1447 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
1439 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, 1448 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
1449 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
1440 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, 1450 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
1441 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, 1451 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
1442 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE }, 1452 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
@@ -1456,6 +1466,10 @@ static struct hid_blacklist {
1456 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE }, 1466 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
1457 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE }, 1467 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
1458 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE }, 1468 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE },
1469 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE },
1470 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
1471 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
1472 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
1459 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PENPARTNER, HID_QUIRK_IGNORE }, 1473 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PENPARTNER, HID_QUIRK_IGNORE },
1460 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE, HID_QUIRK_IGNORE }, 1474 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE, HID_QUIRK_IGNORE },
1461 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 1, HID_QUIRK_IGNORE }, 1475 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE + 1, HID_QUIRK_IGNORE },
@@ -1481,6 +1495,10 @@ static struct hid_blacklist {
1481 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 7, HID_QUIRK_IGNORE }, 1495 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS2 + 7, HID_QUIRK_IGNORE },
1482 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO, HID_QUIRK_IGNORE }, 1496 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_VOLITO, HID_QUIRK_IGNORE },
1483 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PTU, HID_QUIRK_IGNORE }, 1497 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_PTU, HID_QUIRK_IGNORE },
1498 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3, HID_QUIRK_IGNORE },
1499 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 1, HID_QUIRK_IGNORE },
1500 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 2, HID_QUIRK_IGNORE },
1501 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_CINTIQ, HID_QUIRK_IGNORE },
1484 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1502 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1485 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1503 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1486 1504
diff --git a/drivers/usb/media/pwc/ChangeLog b/drivers/usb/media/pwc/ChangeLog
deleted file mode 100644
index b2eb71a9afb5..000000000000
--- a/drivers/usb/media/pwc/ChangeLog
+++ /dev/null
@@ -1,143 +0,0 @@
19.0.2
2
3* Adding #ifdef to compile PWC before and after 2.6.5
4
59.0.1
6
79.0
8
9
108.12
11
12* Implement motorized pan/tilt feature for Logitech QuickCam Orbit/Spere.
13
148.11.1
15
16* Fix for PCVC720/40, would not be able to set videomode
17* Fix for Samsung MPC models, appearantly they are based on a newer chipset
18
198.11
20
21* 20 dev_hints (per request)
22* Hot unplugging should be better, no more dangling pointers or memory leaks
23* Added reserved Logitech webcam IDs
24* Device now remembers size & fps between close()/open()
25* Removed palette stuff altogether
26
278.10.1
28
29* Added IDs for PCVC720K/40 and Creative Labs Webcam Pro
30
318.10
32
33* Fixed ID for QuickCam Notebook pro
34* Added GREALSIZE ioctl() call
35* Fixed bug in case PWCX was not loaded and invalid size was set
36
378.9
38
39* Merging with kernel 2.5.49
40* Adding IDs for QuickCam Zoom & QuickCam Notebook
41
428.8
43
44* Fixing 'leds' parameter
45* Adding IDs for Logitech QuickCam Pro 4000
46* Making URB init/cleanup a little nicer
47
488.7
49
50* Incorporating changes in ioctl() parameter passing
51* Also changes to URB mechanism
52
538.6
54
55* Added ID's for Visionite VCS UM100 and UC300
56* Removed YUV420-interlaced palette altogether (was confusing)
57* Removed MIRROR stuff as it didn't work anyway
58* Fixed a problem with the 'leds' parameter (wouldn't blink)
59* Added ioctl()s for advanced features: 'extended' whitebalance ioctl()s,
60 CONTOUR, BACKLIGHT, FLICKER, DYNNOISE.
61* VIDIOCGCAP.name now contains real camera model name instead of
62 'Philips xxx webcam'
63* Added PROBE ioctl (see previous point & API doc)
64
658.5
66
67* Adding IDs for Creative Labs Webcam 5
68* Adding IDs for SOTEC CMS-001 webcam
69* Solving possible hang in VIDIOCSYNC when unplugging the cam
70* Forgot to return structure in VIDIOCPWCGAWB, oops
71* Time interval for the LEDs are now in milliseconds
72
738.4
74
75* Fixing power_save option for Vesta range
76* Handling new error codes in ISOC callback
77* Adding dev_hint module parameter, to specify /dev/videoX device nodes
78
798.3
80
81* Adding Samsung C10 and C30 cameras
82* Removing palette module parameter
83* Fixed typo in ID of QuickCam 3000 Pro
84* Adding LED settings (blinking while in use) for ToUCam cameras.
85* Turns LED off when camera is not in use.
86
878.2
88
89* Making module more silent when trace = 0
90* Adding QuickCam 3000 Pro IDs
91* Chrominance control for the Vesta cameras
92* Hopefully fixed problems on machines with BIGMEM and > 1GB of RAM
93* Included Oliver Neukem's lock_kernel() patch
94* Allocates less memory for image buffers
95* Adds ioctl()s for the whitebalancing
96
978.1
98
99* Adding support for 750
100* Adding V4L GAUDIO/SAUDIO/UNIT ioctl() calls
101
1028.0
103* 'damage control' after inclusion in 2.4.5.
104* Changed wait-queue mechanism in read/mmap/poll according to the book.
105* Included YUV420P palette.
106* Changed interface to decompressor module.
107* Cleaned up pwc structure a bit.
108
1097.0
110
111* Fixed bug in vcvt_420i_yuyv; extra variables on stack were misaligned.
112* There is now a clear error message when an image size is selected that
113 is only supported using the decompressor, and the decompressor isn't
114 loaded.
115* When the decompressor wasn't loaded, selecting large image size
116 would create skewed or double images.
117
1186.3
119
120* Introduced spinlocks for the buffer pointer manipulation; a number of
121 reports seem to suggest the down()/up() semaphores were the cause of
122 lockups, since they are not suitable for interrupt/user locking.
123* Separated decompressor and core code into 2 modules.
124
1256.2
126
127* Non-integral image sizes are now padded with gray or black.
128* Added SHUTTERSPEED ioctl().
129* Fixed buglet in VIDIOCPWCSAGC; the function would always return an error,
130 even though the call succeeded.
131* Added hotplug support for 2.4.*.
132* Memory: the 645/646 uses less memory now.
133
1346.1
135
136* VIDIOCSPICT returns -EINVAL with invalid palettes.
137* Added saturation control.
138* Split decompressors from rest.
139* Fixed bug that would reset the framerate to the default framerate if
140 the rate field was set to 0 (which is not what I intended, nl. do not
141 change the framerate!).
142* VIDIOCPWCSCQUAL (setting compression quality) now takes effect immediately.
143* Workaround for a bug in the 730 sensor.
diff --git a/drivers/usb/media/pwc/pwc-if.c b/drivers/usb/media/pwc/pwc-if.c
index 5429ff3b9753..b77e65c03659 100644
--- a/drivers/usb/media/pwc/pwc-if.c
+++ b/drivers/usb/media/pwc/pwc-if.c
@@ -332,10 +332,6 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
332#endif 332#endif
333 ; 333 ;
334 } 334 }
335 if (kbuf == NULL) {
336 Err("Failed to allocate decompress table.\n");
337 return -ENOMEM;
338 }
339 pdev->decompress_data = kbuf; 335 pdev->decompress_data = kbuf;
340 336
341 /* Allocate image buffer; double buffer for mmap() */ 337 /* Allocate image buffer; double buffer for mmap() */
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index a9a7cf4a38eb..fd6ff4cb2c62 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -520,7 +520,7 @@ static void int_callback(struct urb *u, struct pt_regs *regs)
520 520
521 /* we check the link state to report changes */ 521 /* we check the link state to report changes */
522 if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) { 522 if (kaweth->linkstate != (act_state = ( kaweth->intbuffer[STATE_OFFSET] | STATE_MASK) >> STATE_SHIFT)) {
523 if (!act_state) 523 if (act_state)
524 netif_carrier_on(kaweth->net); 524 netif_carrier_on(kaweth->net);
525 else 525 else
526 netif_carrier_off(kaweth->net); 526 netif_carrier_off(kaweth->net);
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index 85476e76b244..4cbb408af727 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -2765,7 +2765,7 @@ static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
2765 } 2765 }
2766 /* expect bcdVersion 1.0, ignore */ 2766 /* expect bcdVersion 1.0, ignore */
2767 if (memcmp(&desc->bGUID, blan_guid, 16) 2767 if (memcmp(&desc->bGUID, blan_guid, 16)
2768 && memcmp(&desc->bGUID, blan_guid, 16) ) { 2768 && memcmp(&desc->bGUID, safe_guid, 16) ) {
2769 /* hey, this one might _really_ be MDLM! */ 2769 /* hey, this one might _really_ be MDLM! */
2770 dev_dbg (&intf->dev, "MDLM guid\n"); 2770 dev_dbg (&intf->dev, "MDLM guid\n");
2771 goto bad_desc; 2771 goto bad_desc;
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index bc798edf0358..9438909e87a5 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -455,6 +455,17 @@ config USB_SERIAL_XIRCOM
455 To compile this driver as a module, choose M here: the 455 To compile this driver as a module, choose M here: the
456 module will be called keyspan_pda. 456 module will be called keyspan_pda.
457 457
458config USB_SERIAL_OPTION
459 tristate "USB Option PCMCIA serial driver"
460 depends on USB_SERIAL && USB_OHCI_HCD && PCCARD
461 help
462 Say Y here if you want to use an Option card. This is a
463 GSM card, controlled by three serial ports which are connected
464 via an OHCI adapter located on a PC card.
465
466 To compile this driver as a module, choose M here: the
467 module will be called option.
468
458config USB_SERIAL_OMNINET 469config USB_SERIAL_OMNINET
459 tristate "USB ZyXEL omni.net LCD Plus Driver (EXPERIMENTAL)" 470 tristate "USB ZyXEL omni.net LCD Plus Driver (EXPERIMENTAL)"
460 depends on USB_SERIAL && EXPERIMENTAL 471 depends on USB_SERIAL && EXPERIMENTAL
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index d56ff6d86cce..6c7cdcc99a9e 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_USB_SERIAL_KLSI) += kl5kusb105.o
32obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o 32obj-$(CONFIG_USB_SERIAL_KOBIL_SCT) += kobil_sct.o
33obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o 33obj-$(CONFIG_USB_SERIAL_MCT_U232) += mct_u232.o
34obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o 34obj-$(CONFIG_USB_SERIAL_OMNINET) += omninet.o
35obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
35obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 36obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
36obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 37obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
37obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 38obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 7e9bb63eb466..4ace9964fc6b 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -7,6 +7,14 @@
7 * modify it under the terms of the GNU General Public License version 7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation. 8 * 2 as published by the Free Software Foundation.
9 * 9 *
10 * Support to set flow control line levels using TIOCMGET and TIOCMSET
11 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow
12 * control thanks to Munir Nassar nassarmu@real-time.com
13 *
14 * Outstanding Issues:
15 * Buffers are not flushed when the port is opened.
16 * Multiple calls to write() may fail with "Resource temporarily unavailable"
17 *
10 */ 18 */
11 19
12#include <linux/config.h> 20#include <linux/config.h>
@@ -24,7 +32,7 @@
24/* 32/*
25 * Version Information 33 * Version Information
26 */ 34 */
27#define DRIVER_VERSION "v0.03" 35#define DRIVER_VERSION "v0.04"
28#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 36#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver"
29 37
30/* 38/*
@@ -35,6 +43,9 @@ static void cp2101_cleanup(struct usb_serial_port*);
35static void cp2101_close(struct usb_serial_port*, struct file*); 43static void cp2101_close(struct usb_serial_port*, struct file*);
36static void cp2101_get_termios(struct usb_serial_port*); 44static void cp2101_get_termios(struct usb_serial_port*);
37static void cp2101_set_termios(struct usb_serial_port*, struct termios*); 45static void cp2101_set_termios(struct usb_serial_port*, struct termios*);
46static int cp2101_tiocmget (struct usb_serial_port *, struct file *);
47static int cp2101_tiocmset (struct usb_serial_port *, struct file *,
48 unsigned int, unsigned int);
38static void cp2101_break_ctl(struct usb_serial_port*, int); 49static void cp2101_break_ctl(struct usb_serial_port*, int);
39static int cp2101_startup (struct usb_serial *); 50static int cp2101_startup (struct usb_serial *);
40static void cp2101_shutdown(struct usb_serial*); 51static void cp2101_shutdown(struct usb_serial*);
@@ -43,9 +54,10 @@ static void cp2101_shutdown(struct usb_serial*);
43static int debug; 54static int debug;
44 55
45static struct usb_device_id id_table [] = { 56static struct usb_device_id id_table [] = {
46 {USB_DEVICE(0x10c4, 0xea60) }, /*Silicon labs factory default*/ 57 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
47 {USB_DEVICE(0x10ab, 0x10c5) }, /*Siemens MC60 Cable*/ 58 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
48 { } /* Terminating Entry*/ 59 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
60 { } /* Terminating Entry */
49}; 61};
50 62
51MODULE_DEVICE_TABLE (usb, id_table); 63MODULE_DEVICE_TABLE (usb, id_table);
@@ -70,32 +82,35 @@ static struct usb_serial_device_type cp2101_device = {
70 .close = cp2101_close, 82 .close = cp2101_close,
71 .break_ctl = cp2101_break_ctl, 83 .break_ctl = cp2101_break_ctl,
72 .set_termios = cp2101_set_termios, 84 .set_termios = cp2101_set_termios,
85 .tiocmget = cp2101_tiocmget,
86 .tiocmset = cp2101_tiocmset,
73 .attach = cp2101_startup, 87 .attach = cp2101_startup,
74 .shutdown = cp2101_shutdown, 88 .shutdown = cp2101_shutdown,
75}; 89};
76 90
77/*Config request types*/ 91/* Config request types */
78#define REQTYPE_HOST_TO_DEVICE 0x41 92#define REQTYPE_HOST_TO_DEVICE 0x41
79#define REQTYPE_DEVICE_TO_HOST 0xc1 93#define REQTYPE_DEVICE_TO_HOST 0xc1
80 94
81/*Config SET requests. To GET, add 1 to the request number*/ 95/* Config SET requests. To GET, add 1 to the request number */
82#define CP2101_UART 0x00 /*Enable / Disable*/ 96#define CP2101_UART 0x00 /* Enable / Disable */
83#define CP2101_BAUDRATE 0x01 /*(BAUD_RATE_GEN_FREQ / baudrate)*/ 97#define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */
84#define CP2101_BITS 0x03 /*0x(0)(data bits)(parity)(stop bits)*/ 98#define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */
85#define CP2101_BREAK 0x05 /*On / Off*/ 99#define CP2101_BREAK 0x05 /* On / Off */
86#define CP2101_DTRRTS 0x07 /*101 / 202 ???*/ 100#define CP2101_CONTROL 0x07 /* Flow control line states */
87#define CP2101_CONFIG_16 0x13 /*16 bytes of config data ???*/ 101#define CP2101_MODEMCTL 0x13 /* Modem controls */
88#define CP2101_CONFIG_6 0x19 /*6 bytes of config data ???*/ 102#define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */
89 103
90/*CP2101_UART*/ 104/* CP2101_UART */
91#define UART_ENABLE 0x0001 105#define UART_ENABLE 0x0001
92#define UART_DISABLE 0x0000 106#define UART_DISABLE 0x0000
93 107
94/*CP2101_BAUDRATE*/ 108/* CP2101_BAUDRATE */
95#define BAUD_RATE_GEN_FREQ 0x384000 109#define BAUD_RATE_GEN_FREQ 0x384000
96 110
97/*CP2101_BITS*/ 111/* CP2101_BITS */
98#define BITS_DATA_MASK 0X0f00 112#define BITS_DATA_MASK 0X0f00
113#define BITS_DATA_5 0X0500
99#define BITS_DATA_6 0X0600 114#define BITS_DATA_6 0X0600
100#define BITS_DATA_7 0X0700 115#define BITS_DATA_7 0X0700
101#define BITS_DATA_8 0X0800 116#define BITS_DATA_8 0X0800
@@ -112,64 +127,137 @@ static struct usb_serial_device_type cp2101_device = {
112#define BITS_STOP_1 0x0000 127#define BITS_STOP_1 0x0000
113#define BITS_STOP_1_5 0x0001 128#define BITS_STOP_1_5 0x0001
114#define BITS_STOP_2 0x0002 129#define BITS_STOP_2 0x0002
130
131/* CP2101_BREAK */
115#define BREAK_ON 0x0000 132#define BREAK_ON 0x0000
116#define BREAK_OFF 0x0001 133#define BREAK_OFF 0x0001
117 134
135/* CP2101_CONTROL */
136#define CONTROL_DTR 0x0001
137#define CONTROL_RTS 0x0002
138#define CONTROL_CTS 0x0010
139#define CONTROL_DSR 0x0020
140#define CONTROL_RING 0x0040
141#define CONTROL_DCD 0x0080
142#define CONTROL_WRITE_DTR 0x0100
143#define CONTROL_WRITE_RTS 0x0200
118 144
119static int cp2101_get_config(struct usb_serial_port* port, u8 request) 145/*
146 * cp2101_get_config
147 * Reads from the CP2101 configuration registers
148 * 'size' is specified in bytes.
149 * 'data' is a pointer to a pre-allocated array of integers large
150 * enough to hold 'size' bytes (with 4 bytes to each integer)
151 */
152static int cp2101_get_config(struct usb_serial_port* port, u8 request,
153 unsigned int *data, int size)
120{ 154{
121 struct usb_serial *serial = port->serial; 155 struct usb_serial *serial = port->serial;
122 unsigned char buf[4]; 156 u32 *buf;
123 unsigned int value; 157 int result, i, length;
124 int result, i; 158
159 /* Number of integers required to contain the array */
160 length = (((size - 1) | 3) + 1)/4;
161
162 buf = kmalloc (length * sizeof(u32), GFP_KERNEL);
163 memset(buf, 0, length * sizeof(u32));
164
165 if (!buf) {
166 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
167 return -ENOMEM;
168 }
125 169
126 /*For get requests, the request number must be incremented*/ 170 /* For get requests, the request number must be incremented */
127 request++; 171 request++;
128 172
129 /*Issue the request, attempting to read 4 bytes*/ 173 /* Issue the request, attempting to read 'size' bytes */
130 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), 174 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0),
131 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 175 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
132 0, buf, 4, 300); 176 0, buf, size, 300);
133 177
134 if (result < 0) { 178 /* Convert data into an array of integers */
135 dev_err(&port->dev, "%s - Unable to send config request, " 179 for (i=0; i<length; i++)
136 "request=0x%x result=%d\n", 180 data[i] = le32_to_cpu(buf[i]);
137 __FUNCTION__, request, result);
138 return result;
139 }
140 181
141 /*Assemble each byte read into an integer value*/ 182 kfree(buf);
142 value = 0;
143 for (i=0; i<4 && i<result; i++)
144 value |= (buf[i] << (i * 8));
145 183
146 dbg( " %s - request=0x%x result=%d value=0x%x", 184 if (result != size) {
147 __FUNCTION__, request, result, value); 185 dev_err(&port->dev, "%s - Unable to send config request, "
186 "request=0x%x size=%d result=%d\n",
187 __FUNCTION__, request, size, result);
188 return -EPROTO;
189 }
148 190
149 return value; 191 return 0;
150} 192}
151 193
152static int cp2101_set_config(struct usb_serial_port* port, u8 request, u16 value) 194/*
195 * cp2101_set_config
196 * Writes to the CP2101 configuration registers
197 * Values less than 16 bits wide are sent directly
198 * 'size' is specified in bytes.
199 */
200static int cp2101_set_config(struct usb_serial_port* port, u8 request,
201 unsigned int *data, int size)
153{ 202{
154 struct usb_serial *serial = port->serial; 203 struct usb_serial *serial = port->serial;
155 int result; 204 u32 *buf;
156 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), 205 int result, i, length;
157 request, REQTYPE_HOST_TO_DEVICE, value,
158 0, NULL, 0, 300);
159 206
160 if (result <0) { 207 /* Number of integers required to contain the array */
161 dev_err(&port->dev, "%s - Unable to send config request, " 208 length = (((size - 1) | 3) + 1)/4;
162 "request=0x%x value=0x%x result=%d\n", 209
163 __FUNCTION__, request, value, result); 210 buf = kmalloc(length * sizeof(u32), GFP_KERNEL);
164 return result; 211 if (!buf) {
212 dev_err(&port->dev, "%s - out of memory.\n",
213 __FUNCTION__);
214 return -ENOMEM;
215 }
216
217 /* Array of integers into bytes */
218 for (i = 0; i < length; i++)
219 buf[i] = cpu_to_le32(data[i]);
220
221 if (size > 2) {
222 result = usb_control_msg (serial->dev,
223 usb_sndctrlpipe(serial->dev, 0),
224 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
225 0, buf, size, 300);
226 } else {
227 result = usb_control_msg (serial->dev,
228 usb_sndctrlpipe(serial->dev, 0),
229 request, REQTYPE_HOST_TO_DEVICE, data[0],
230 0, NULL, 0, 300);
165 } 231 }
166 232
167 dbg(" %s - request=0x%x value=0x%x result=%d", 233 kfree(buf);
168 __FUNCTION__, request, value, result); 234
235 if ((size > 2 && result != size) || result < 0) {
236 dev_err(&port->dev, "%s - Unable to send request, "
237 "request=0x%x size=%d result=%d\n",
238 __FUNCTION__, request, size, result);
239 return -EPROTO;
240 }
169 241
242 /* Single data value */
243 result = usb_control_msg (serial->dev,
244 usb_sndctrlpipe(serial->dev, 0),
245 request, REQTYPE_HOST_TO_DEVICE, data[0],
246 0, NULL, 0, 300);
170 return 0; 247 return 0;
171} 248}
172 249
250/*
251 * cp2101_set_config_single
252 * Convenience function for calling cp2101_set_config on single data values
253 * without requiring an integer pointer
254 */
255static inline int cp2101_set_config_single(struct usb_serial_port* port,
256 u8 request, unsigned int data)
257{
258 return cp2101_set_config(port, request, &data, 2);
259}
260
173static int cp2101_open (struct usb_serial_port *port, struct file *filp) 261static int cp2101_open (struct usb_serial_port *port, struct file *filp)
174{ 262{
175 struct usb_serial *serial = port->serial; 263 struct usb_serial *serial = port->serial;
@@ -177,7 +265,7 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
177 265
178 dbg("%s - port %d", __FUNCTION__, port->number); 266 dbg("%s - port %d", __FUNCTION__, port->number);
179 267
180 if (cp2101_set_config(port, CP2101_UART, UART_ENABLE)) { 268 if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) {
181 dev_err(&port->dev, "%s - Unable to enable UART\n", 269 dev_err(&port->dev, "%s - Unable to enable UART\n",
182 __FUNCTION__); 270 __FUNCTION__);
183 return -EPROTO; 271 return -EPROTO;
@@ -198,9 +286,12 @@ static int cp2101_open (struct usb_serial_port *port, struct file *filp)
198 return result; 286 return result;
199 } 287 }
200 288
201 /*Configure the termios structure*/ 289 /* Configure the termios structure */
202 cp2101_get_termios(port); 290 cp2101_get_termios(port);
203 291
292 /* Set the DTR and RTS pins low */
293 cp2101_tiocmset(port, NULL, TIOCM_DTR | TIOCM_RTS, 0);
294
204 return 0; 295 return 0;
205} 296}
206 297
@@ -228,16 +319,18 @@ static void cp2101_close (struct usb_serial_port *port, struct file * filp)
228 usb_kill_urb(port->write_urb); 319 usb_kill_urb(port->write_urb);
229 usb_kill_urb(port->read_urb); 320 usb_kill_urb(port->read_urb);
230 321
231 cp2101_set_config(port, CP2101_UART, UART_DISABLE); 322 cp2101_set_config_single(port, CP2101_UART, UART_DISABLE);
232} 323}
233 324
234/* cp2101_get_termios*/ 325/*
235/* Reads the baud rate, data bits, parity and stop bits from the device*/ 326 * cp2101_get_termios
236/* Corrects any unsupported values*/ 327 * Reads the baud rate, data bits, parity, stop bits and flow control mode
237/* Configures the termios structure to reflect the state of the device*/ 328 * from the device, corrects any unsupported values, and configures the
329 * termios structure to reflect the state of the device
330 */
238static void cp2101_get_termios (struct usb_serial_port *port) 331static void cp2101_get_termios (struct usb_serial_port *port)
239{ 332{
240 unsigned int cflag; 333 unsigned int cflag, modem_ctl[4];
241 int baud; 334 int baud;
242 int bits; 335 int bits;
243 336
@@ -249,15 +342,16 @@ static void cp2101_get_termios (struct usb_serial_port *port)
249 } 342 }
250 cflag = port->tty->termios->c_cflag; 343 cflag = port->tty->termios->c_cflag;
251 344
252 baud = cp2101_get_config(port, CP2101_BAUDRATE); 345 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
253 /*Convert to baudrate*/ 346 /* Convert to baudrate */
254 if (baud) 347 if (baud)
255 baud = BAUD_RATE_GEN_FREQ / baud; 348 baud = BAUD_RATE_GEN_FREQ / baud;
256 349
257 dbg("%s - baud rate = %d", __FUNCTION__, baud); 350 dbg("%s - baud rate = %d", __FUNCTION__, baud);
258 cflag &= ~CBAUD; 351 cflag &= ~CBAUD;
259 switch (baud) { 352 switch (baud) {
260 /* The baud rates which are commented out below 353 /*
354 * The baud rates which are commented out below
261 * appear to be supported by the device 355 * appear to be supported by the device
262 * but are non-standard 356 * but are non-standard
263 */ 357 */
@@ -284,14 +378,18 @@ static void cp2101_get_termios (struct usb_serial_port *port)
284 dbg("%s - Baud rate is not supported, " 378 dbg("%s - Baud rate is not supported, "
285 "using 9600 baud", __FUNCTION__); 379 "using 9600 baud", __FUNCTION__);
286 cflag |= B9600; 380 cflag |= B9600;
287 cp2101_set_config(port, CP2101_BAUDRATE, 381 cp2101_set_config_single(port, CP2101_BAUDRATE,
288 (BAUD_RATE_GEN_FREQ/9600)); 382 (BAUD_RATE_GEN_FREQ/9600));
289 break; 383 break;
290 } 384 }
291 385
292 bits = cp2101_get_config(port, CP2101_BITS); 386 cp2101_get_config(port, CP2101_BITS, &bits, 2);
293 cflag &= ~CSIZE; 387 cflag &= ~CSIZE;
294 switch(bits & BITS_DATA_MASK) { 388 switch(bits & BITS_DATA_MASK) {
389 case BITS_DATA_5:
390 dbg("%s - data bits = 5", __FUNCTION__);
391 cflag |= CS5;
392 break;
295 case BITS_DATA_6: 393 case BITS_DATA_6:
296 dbg("%s - data bits = 6", __FUNCTION__); 394 dbg("%s - data bits = 6", __FUNCTION__);
297 cflag |= CS6; 395 cflag |= CS6;
@@ -310,7 +408,7 @@ static void cp2101_get_termios (struct usb_serial_port *port)
310 cflag |= CS8; 408 cflag |= CS8;
311 bits &= ~BITS_DATA_MASK; 409 bits &= ~BITS_DATA_MASK;
312 bits |= BITS_DATA_8; 410 bits |= BITS_DATA_8;
313 cp2101_set_config(port, CP2101_BITS, bits); 411 cp2101_set_config(port, CP2101_BITS, &bits, 2);
314 break; 412 break;
315 default: 413 default:
316 dbg("%s - Unknown number of data bits, " 414 dbg("%s - Unknown number of data bits, "
@@ -318,7 +416,7 @@ static void cp2101_get_termios (struct usb_serial_port *port)
318 cflag |= CS8; 416 cflag |= CS8;
319 bits &= ~BITS_DATA_MASK; 417 bits &= ~BITS_DATA_MASK;
320 bits |= BITS_DATA_8; 418 bits |= BITS_DATA_8;
321 cp2101_set_config(port, CP2101_BITS, bits); 419 cp2101_set_config(port, CP2101_BITS, &bits, 2);
322 break; 420 break;
323 } 421 }
324 422
@@ -341,21 +439,21 @@ static void cp2101_get_termios (struct usb_serial_port *port)
341 "disabling parity)", __FUNCTION__); 439 "disabling parity)", __FUNCTION__);
342 cflag &= ~PARENB; 440 cflag &= ~PARENB;
343 bits &= ~BITS_PARITY_MASK; 441 bits &= ~BITS_PARITY_MASK;
344 cp2101_set_config(port, CP2101_BITS, bits); 442 cp2101_set_config(port, CP2101_BITS, &bits, 2);
345 break; 443 break;
346 case BITS_PARITY_SPACE: 444 case BITS_PARITY_SPACE:
347 dbg("%s - parity = SPACE (not supported, " 445 dbg("%s - parity = SPACE (not supported, "
348 "disabling parity)", __FUNCTION__); 446 "disabling parity)", __FUNCTION__);
349 cflag &= ~PARENB; 447 cflag &= ~PARENB;
350 bits &= ~BITS_PARITY_MASK; 448 bits &= ~BITS_PARITY_MASK;
351 cp2101_set_config(port, CP2101_BITS, bits); 449 cp2101_set_config(port, CP2101_BITS, &bits, 2);
352 break; 450 break;
353 default: 451 default:
354 dbg("%s - Unknown parity mode, " 452 dbg("%s - Unknown parity mode, "
355 "disabling parity", __FUNCTION__); 453 "disabling parity", __FUNCTION__);
356 cflag &= ~PARENB; 454 cflag &= ~PARENB;
357 bits &= ~BITS_PARITY_MASK; 455 bits &= ~BITS_PARITY_MASK;
358 cp2101_set_config(port, CP2101_BITS, bits); 456 cp2101_set_config(port, CP2101_BITS, &bits, 2);
359 break; 457 break;
360 } 458 }
361 459
@@ -366,9 +464,9 @@ static void cp2101_get_termios (struct usb_serial_port *port)
366 break; 464 break;
367 case BITS_STOP_1_5: 465 case BITS_STOP_1_5:
368 dbg("%s - stop bits = 1.5 (not supported, " 466 dbg("%s - stop bits = 1.5 (not supported, "
369 "using 1 stop bit", __FUNCTION__); 467 "using 1 stop bit)", __FUNCTION__);
370 bits &= ~BITS_STOP_MASK; 468 bits &= ~BITS_STOP_MASK;
371 cp2101_set_config(port, CP2101_BITS, bits); 469 cp2101_set_config(port, CP2101_BITS, &bits, 2);
372 break; 470 break;
373 case BITS_STOP_2: 471 case BITS_STOP_2:
374 dbg("%s - stop bits = 2", __FUNCTION__); 472 dbg("%s - stop bits = 2", __FUNCTION__);
@@ -378,10 +476,19 @@ static void cp2101_get_termios (struct usb_serial_port *port)
378 dbg("%s - Unknown number of stop bits, " 476 dbg("%s - Unknown number of stop bits, "
379 "using 1 stop bit", __FUNCTION__); 477 "using 1 stop bit", __FUNCTION__);
380 bits &= ~BITS_STOP_MASK; 478 bits &= ~BITS_STOP_MASK;
381 cp2101_set_config(port, CP2101_BITS, bits); 479 cp2101_set_config(port, CP2101_BITS, &bits, 2);
382 break; 480 break;
383 } 481 }
384 482
483 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
484 if (modem_ctl[0] & 0x0008) {
485 dbg("%s - flow control = CRTSCTS", __FUNCTION__);
486 cflag |= CRTSCTS;
487 } else {
488 dbg("%s - flow control = NONE", __FUNCTION__);
489 cflag &= ~CRTSCTS;
490 }
491
385 port->tty->termios->c_cflag = cflag; 492 port->tty->termios->c_cflag = cflag;
386} 493}
387 494
@@ -389,8 +496,8 @@ static void cp2101_set_termios (struct usb_serial_port *port,
389 struct termios *old_termios) 496 struct termios *old_termios)
390{ 497{
391 unsigned int cflag, old_cflag=0; 498 unsigned int cflag, old_cflag=0;
392 int baud=0; 499 int baud=0, bits;
393 int bits; 500 unsigned int modem_ctl[4];
394 501
395 dbg("%s - port %d", __FUNCTION__, port->number); 502 dbg("%s - port %d", __FUNCTION__, port->number);
396 503
@@ -400,7 +507,7 @@ static void cp2101_set_termios (struct usb_serial_port *port,
400 } 507 }
401 cflag = port->tty->termios->c_cflag; 508 cflag = port->tty->termios->c_cflag;
402 509
403 /* check that they really want us to change something */ 510 /* Check that they really want us to change something */
404 if (old_termios) { 511 if (old_termios) {
405 if ((cflag == old_termios->c_cflag) && 512 if ((cflag == old_termios->c_cflag) &&
406 (RELEVANT_IFLAG(port->tty->termios->c_iflag) 513 (RELEVANT_IFLAG(port->tty->termios->c_iflag)
@@ -415,7 +522,8 @@ static void cp2101_set_termios (struct usb_serial_port *port,
415 /* If the baud rate is to be updated*/ 522 /* If the baud rate is to be updated*/
416 if ((cflag & CBAUD) != (old_cflag & CBAUD)) { 523 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
417 switch (cflag & CBAUD) { 524 switch (cflag & CBAUD) {
418 /* The baud rates which are commented out below 525 /*
526 * The baud rates which are commented out below
419 * appear to be supported by the device 527 * appear to be supported by the device
420 * but are non-standard 528 * but are non-standard
421 */ 529 */
@@ -448,18 +556,22 @@ static void cp2101_set_termios (struct usb_serial_port *port,
448 if (baud) { 556 if (baud) {
449 dbg("%s - Setting baud rate to %d baud", __FUNCTION__, 557 dbg("%s - Setting baud rate to %d baud", __FUNCTION__,
450 baud); 558 baud);
451 if (cp2101_set_config(port, CP2101_BAUDRATE, 559 if (cp2101_set_config_single(port, CP2101_BAUDRATE,
452 (BAUD_RATE_GEN_FREQ / baud))) 560 (BAUD_RATE_GEN_FREQ / baud)))
453 dev_err(&port->dev, "Baud rate requested not " 561 dev_err(&port->dev, "Baud rate requested not "
454 "supported by device\n"); 562 "supported by device\n");
455 } 563 }
456 } 564 }
457 565
458 /*If the number of data bits is to be updated*/ 566 /* If the number of data bits is to be updated */
459 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 567 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
460 bits = cp2101_get_config(port, CP2101_BITS); 568 cp2101_get_config(port, CP2101_BITS, &bits, 2);
461 bits &= ~BITS_DATA_MASK; 569 bits &= ~BITS_DATA_MASK;
462 switch (cflag & CSIZE) { 570 switch (cflag & CSIZE) {
571 case CS5:
572 bits |= BITS_DATA_5;
573 dbg("%s - data bits = 5", __FUNCTION__);
574 break;
463 case CS6: 575 case CS6:
464 bits |= BITS_DATA_6; 576 bits |= BITS_DATA_6;
465 dbg("%s - data bits = 6", __FUNCTION__); 577 dbg("%s - data bits = 6", __FUNCTION__);
@@ -483,13 +595,13 @@ static void cp2101_set_termios (struct usb_serial_port *port,
483 bits |= BITS_DATA_8; 595 bits |= BITS_DATA_8;
484 break; 596 break;
485 } 597 }
486 if (cp2101_set_config(port, CP2101_BITS, bits)) 598 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
487 dev_err(&port->dev, "Number of data bits requested " 599 dev_err(&port->dev, "Number of data bits requested "
488 "not supported by device\n"); 600 "not supported by device\n");
489 } 601 }
490 602
491 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { 603 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) {
492 bits = cp2101_get_config(port, CP2101_BITS); 604 cp2101_get_config(port, CP2101_BITS, &bits, 2);
493 bits &= ~BITS_PARITY_MASK; 605 bits &= ~BITS_PARITY_MASK;
494 if (cflag & PARENB) { 606 if (cflag & PARENB) {
495 if (cflag & PARODD) { 607 if (cflag & PARODD) {
@@ -500,13 +612,13 @@ static void cp2101_set_termios (struct usb_serial_port *port,
500 dbg("%s - parity = EVEN", __FUNCTION__); 612 dbg("%s - parity = EVEN", __FUNCTION__);
501 } 613 }
502 } 614 }
503 if (cp2101_set_config(port, CP2101_BITS, bits)) 615 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
504 dev_err(&port->dev, "Parity mode not supported " 616 dev_err(&port->dev, "Parity mode not supported "
505 "by device\n"); 617 "by device\n");
506 } 618 }
507 619
508 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 620 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
509 bits = cp2101_get_config(port, CP2101_BITS); 621 cp2101_get_config(port, CP2101_BITS, &bits, 2);
510 bits &= ~BITS_STOP_MASK; 622 bits &= ~BITS_STOP_MASK;
511 if (cflag & CSTOPB) { 623 if (cflag & CSTOPB) {
512 bits |= BITS_STOP_2; 624 bits |= BITS_STOP_2;
@@ -515,15 +627,90 @@ static void cp2101_set_termios (struct usb_serial_port *port,
515 bits |= BITS_STOP_1; 627 bits |= BITS_STOP_1;
516 dbg("%s - stop bits = 1", __FUNCTION__); 628 dbg("%s - stop bits = 1", __FUNCTION__);
517 } 629 }
518 if (cp2101_set_config(port, CP2101_BITS, bits)) 630 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
519 dev_err(&port->dev, "Number of stop bits requested " 631 dev_err(&port->dev, "Number of stop bits requested "
520 "not supported by device\n"); 632 "not supported by device\n");
521 } 633 }
634
635 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
636 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
637 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
638 __FUNCTION__, modem_ctl[0], modem_ctl[1],
639 modem_ctl[2], modem_ctl[3]);
640
641 if (cflag & CRTSCTS) {
642 modem_ctl[0] &= ~0x7B;
643 modem_ctl[0] |= 0x09;
644 modem_ctl[1] = 0x80;
645 dbg("%s - flow control = CRTSCTS", __FUNCTION__);
646 } else {
647 modem_ctl[0] &= ~0x7B;
648 modem_ctl[0] |= 0x01;
649 modem_ctl[1] |= 0x40;
650 dbg("%s - flow control = NONE", __FUNCTION__);
651 }
652
653 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
654 __FUNCTION__, modem_ctl[0], modem_ctl[1],
655 modem_ctl[2], modem_ctl[3]);
656 cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16);
657 }
658
659}
660
661static int cp2101_tiocmset (struct usb_serial_port *port, struct file *file,
662 unsigned int set, unsigned int clear)
663{
664 int control = 0;
665
666 dbg("%s - port %d", __FUNCTION__, port->number);
667
668 if (set & TIOCM_RTS) {
669 control |= CONTROL_RTS;
670 control |= CONTROL_WRITE_RTS;
671 }
672 if (set & TIOCM_DTR) {
673 control |= CONTROL_DTR;
674 control |= CONTROL_WRITE_DTR;
675 }
676 if (clear & TIOCM_RTS) {
677 control &= ~CONTROL_RTS;
678 control |= CONTROL_WRITE_RTS;
679 }
680 if (clear & TIOCM_DTR) {
681 control &= ~CONTROL_DTR;
682 control |= CONTROL_WRITE_DTR;
683 }
684
685 dbg("%s - control = 0x%.4x", __FUNCTION__, control);
686
687 return cp2101_set_config(port, CP2101_CONTROL, &control, 2);
688
689}
690
691static int cp2101_tiocmget (struct usb_serial_port *port, struct file *file)
692{
693 int control, result;
694
695 dbg("%s - port %d", __FUNCTION__, port->number);
696
697 cp2101_get_config(port, CP2101_CONTROL, &control, 1);
698
699 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
700 |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
701 |((control & CONTROL_CTS) ? TIOCM_CTS : 0)
702 |((control & CONTROL_DSR) ? TIOCM_DSR : 0)
703 |((control & CONTROL_RING)? TIOCM_RI : 0)
704 |((control & CONTROL_DCD) ? TIOCM_CD : 0);
705
706 dbg("%s - control = 0x%.2x", __FUNCTION__, control);
707
708 return result;
522} 709}
523 710
524static void cp2101_break_ctl (struct usb_serial_port *port, int break_state) 711static void cp2101_break_ctl (struct usb_serial_port *port, int break_state)
525{ 712{
526 u16 state; 713 int state;
527 714
528 dbg("%s - port %d", __FUNCTION__, port->number); 715 dbg("%s - port %d", __FUNCTION__, port->number);
529 if (break_state == 0) 716 if (break_state == 0)
@@ -532,12 +719,12 @@ static void cp2101_break_ctl (struct usb_serial_port *port, int break_state)
532 state = BREAK_ON; 719 state = BREAK_ON;
533 dbg("%s - turning break %s", __FUNCTION__, 720 dbg("%s - turning break %s", __FUNCTION__,
534 state==BREAK_OFF ? "off" : "on"); 721 state==BREAK_OFF ? "off" : "on");
535 cp2101_set_config(port, CP2101_BREAK, state); 722 cp2101_set_config(port, CP2101_BREAK, &state, 2);
536} 723}
537 724
538static int cp2101_startup (struct usb_serial *serial) 725static int cp2101_startup (struct usb_serial *serial)
539{ 726{
540 /*CP2101 buffers behave strangely unless device is reset*/ 727 /* CP2101 buffers behave strangely unless device is reset */
541 usb_reset_device(serial->dev); 728 usb_reset_device(serial->dev);
542 return 0; 729 return 0;
543} 730}
@@ -548,7 +735,7 @@ static void cp2101_shutdown (struct usb_serial *serial)
548 735
549 dbg("%s", __FUNCTION__); 736 dbg("%s", __FUNCTION__);
550 737
551 /* stop reads and writes on all ports */ 738 /* Stop reads and writes on all ports */
552 for (i=0; i < serial->num_ports; ++i) { 739 for (i=0; i < serial->num_ports; ++i) {
553 cp2101_cleanup(serial->port[i]); 740 cp2101_cleanup(serial->port[i]);
554 } 741 }
@@ -560,16 +747,16 @@ static int __init cp2101_init (void)
560 747
561 retval = usb_serial_register(&cp2101_device); 748 retval = usb_serial_register(&cp2101_device);
562 if (retval) 749 if (retval)
563 return retval; /*Failed to register*/ 750 return retval; /* Failed to register */
564 751
565 retval = usb_register(&cp2101_driver); 752 retval = usb_register(&cp2101_driver);
566 if (retval) { 753 if (retval) {
567 /*Failed to register*/ 754 /* Failed to register */
568 usb_serial_deregister(&cp2101_device); 755 usb_serial_deregister(&cp2101_device);
569 return retval; 756 return retval;
570 } 757 }
571 758
572 /*Success*/ 759 /* Success */
573 info(DRIVER_DESC " " DRIVER_VERSION); 760 info(DRIVER_DESC " " DRIVER_VERSION);
574 return 0; 761 return 0;
575} 762}
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 051c3a77b41b..3bfcc7b9f861 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -264,7 +264,7 @@
264/* 264/*
265 * Version Information 265 * Version Information
266 */ 266 */
267#define DRIVER_VERSION "v1.4.1" 267#define DRIVER_VERSION "v1.4.2"
268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>" 268#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>"
269#define DRIVER_DESC "USB FTDI Serial Converters Driver" 269#define DRIVER_DESC "USB FTDI Serial Converters Driver"
270 270
@@ -687,6 +687,8 @@ struct ftdi_private {
687 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 687 char prev_status, diff_status; /* Used for TIOCMIWAIT */
688 __u8 rx_flags; /* receive state flags (throttling) */ 688 __u8 rx_flags; /* receive state flags (throttling) */
689 spinlock_t rx_lock; /* spinlock for receive state */ 689 spinlock_t rx_lock; /* spinlock for receive state */
690 struct work_struct rx_work;
691 int rx_processed;
690 692
691 __u16 interface; /* FT2232C port interface (0 for FT232/245) */ 693 __u16 interface; /* FT2232C port interface (0 for FT232/245) */
692 694
@@ -717,7 +719,7 @@ static int ftdi_write_room (struct usb_serial_port *port);
717static int ftdi_chars_in_buffer (struct usb_serial_port *port); 719static int ftdi_chars_in_buffer (struct usb_serial_port *port);
718static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs); 720static void ftdi_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
719static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs); 721static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
720static void ftdi_process_read (struct usb_serial_port *port); 722static void ftdi_process_read (void *param);
721static void ftdi_set_termios (struct usb_serial_port *port, struct termios * old); 723static void ftdi_set_termios (struct usb_serial_port *port, struct termios * old);
722static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file); 724static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file);
723static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear); 725static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear);
@@ -1387,6 +1389,8 @@ static int ftdi_common_startup (struct usb_serial *serial)
1387 port->read_urb->transfer_buffer_length = BUFSZ; 1389 port->read_urb->transfer_buffer_length = BUFSZ;
1388 } 1390 }
1389 1391
1392 INIT_WORK(&priv->rx_work, ftdi_process_read, port);
1393
1390 /* Free port's existing write urb and transfer buffer. */ 1394 /* Free port's existing write urb and transfer buffer. */
1391 if (port->write_urb) { 1395 if (port->write_urb) {
1392 usb_free_urb (port->write_urb); 1396 usb_free_urb (port->write_urb);
@@ -1617,6 +1621,7 @@ static int ftdi_open (struct usb_serial_port *port, struct file *filp)
1617 spin_unlock_irqrestore(&priv->rx_lock, flags); 1621 spin_unlock_irqrestore(&priv->rx_lock, flags);
1618 1622
1619 /* Start reading from the device */ 1623 /* Start reading from the device */
1624 priv->rx_processed = 0;
1620 usb_fill_bulk_urb(port->read_urb, dev, 1625 usb_fill_bulk_urb(port->read_urb, dev,
1621 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), 1626 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1622 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 1627 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
@@ -1667,6 +1672,10 @@ static void ftdi_close (struct usb_serial_port *port, struct file *filp)
1667 err("Error from RTS LOW urb"); 1672 err("Error from RTS LOW urb");
1668 } 1673 }
1669 } /* Note change no line if hupcl is off */ 1674 } /* Note change no line if hupcl is off */
1675
1676 /* cancel any scheduled reading */
1677 cancel_delayed_work(&priv->rx_work);
1678 flush_scheduled_work();
1670 1679
1671 /* shutdown our bulk read */ 1680 /* shutdown our bulk read */
1672 if (port->read_urb) 1681 if (port->read_urb)
@@ -1862,23 +1871,14 @@ static void ftdi_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1862 return; 1871 return;
1863 } 1872 }
1864 1873
1865 /* If throttled, delay receive processing until unthrottled. */
1866 spin_lock(&priv->rx_lock);
1867 if (priv->rx_flags & THROTTLED) {
1868 dbg("Deferring read urb processing until unthrottled");
1869 priv->rx_flags |= ACTUALLY_THROTTLED;
1870 spin_unlock(&priv->rx_lock);
1871 return;
1872 }
1873 spin_unlock(&priv->rx_lock);
1874
1875 ftdi_process_read(port); 1874 ftdi_process_read(port);
1876 1875
1877} /* ftdi_read_bulk_callback */ 1876} /* ftdi_read_bulk_callback */
1878 1877
1879 1878
1880static void ftdi_process_read (struct usb_serial_port *port) 1879static void ftdi_process_read (void *param)
1881{ /* ftdi_process_read */ 1880{ /* ftdi_process_read */
1881 struct usb_serial_port *port = (struct usb_serial_port*)param;
1882 struct urb *urb; 1882 struct urb *urb;
1883 struct tty_struct *tty; 1883 struct tty_struct *tty;
1884 struct ftdi_private *priv; 1884 struct ftdi_private *priv;
@@ -1889,6 +1889,7 @@ static void ftdi_process_read (struct usb_serial_port *port)
1889 int result; 1889 int result;
1890 int need_flip; 1890 int need_flip;
1891 int packet_offset; 1891 int packet_offset;
1892 unsigned long flags;
1892 1893
1893 dbg("%s - port %d", __FUNCTION__, port->number); 1894 dbg("%s - port %d", __FUNCTION__, port->number);
1894 1895
@@ -1915,12 +1916,18 @@ static void ftdi_process_read (struct usb_serial_port *port)
1915 1916
1916 data = urb->transfer_buffer; 1917 data = urb->transfer_buffer;
1917 1918
1918 /* The first two bytes of every read packet are status */ 1919 if (priv->rx_processed) {
1919 if (urb->actual_length > 2) { 1920 dbg("%s - already processed: %d bytes, %d remain", __FUNCTION__,
1920 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); 1921 priv->rx_processed,
1922 urb->actual_length - priv->rx_processed);
1921 } else { 1923 } else {
1922 dbg("Status only: %03oo %03oo",data[0],data[1]); 1924 /* The first two bytes of every read packet are status */
1923 } 1925 if (urb->actual_length > 2) {
1926 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
1927 } else {
1928 dbg("Status only: %03oo %03oo",data[0],data[1]);
1929 }
1930 }
1924 1931
1925 1932
1926 /* TO DO -- check for hung up line and handle appropriately: */ 1933 /* TO DO -- check for hung up line and handle appropriately: */
@@ -1929,8 +1936,12 @@ static void ftdi_process_read (struct usb_serial_port *port)
1929 /* if CD is dropped and the line is not CLOCAL then we should hangup */ 1936 /* if CD is dropped and the line is not CLOCAL then we should hangup */
1930 1937
1931 need_flip = 0; 1938 need_flip = 0;
1932 for (packet_offset=0; packet_offset < urb->actual_length; packet_offset += PKTSZ) { 1939 for (packet_offset = priv->rx_processed; packet_offset < urb->actual_length; packet_offset += PKTSZ) {
1940 int length;
1941
1933 /* Compare new line status to the old one, signal if different */ 1942 /* Compare new line status to the old one, signal if different */
1943 /* N.B. packet may be processed more than once, but differences
1944 * are only processed once. */
1934 if (priv != NULL) { 1945 if (priv != NULL) {
1935 char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK; 1946 char new_status = data[packet_offset+0] & FTDI_STATUS_B0_MASK;
1936 if (new_status != priv->prev_status) { 1947 if (new_status != priv->prev_status) {
@@ -1940,6 +1951,35 @@ static void ftdi_process_read (struct usb_serial_port *port)
1940 } 1951 }
1941 } 1952 }
1942 1953
1954 length = min(PKTSZ, urb->actual_length-packet_offset)-2;
1955 if (length < 0) {
1956 err("%s - bad packet length: %d", __FUNCTION__, length+2);
1957 length = 0;
1958 }
1959
1960 /* have to make sure we don't overflow the buffer
1961 with tty_insert_flip_char's */
1962 if (tty->flip.count+length > TTY_FLIPBUF_SIZE) {
1963 tty_flip_buffer_push(tty);
1964 need_flip = 0;
1965
1966 if (tty->flip.count != 0) {
1967 /* flip didn't work, this happens when ftdi_process_read() is
1968 * called from ftdi_unthrottle, because TTY_DONT_FLIP is set */
1969 dbg("%s - flip buffer push failed", __FUNCTION__);
1970 break;
1971 }
1972 }
1973 if (priv->rx_flags & THROTTLED) {
1974 dbg("%s - throttled", __FUNCTION__);
1975 break;
1976 }
1977 if (tty->ldisc.receive_room(tty)-tty->flip.count < length) {
1978 /* break out & wait for throttling/unthrottling to happen */
1979 dbg("%s - receive room low", __FUNCTION__);
1980 break;
1981 }
1982
1943 /* Handle errors and break */ 1983 /* Handle errors and break */
1944 error_flag = TTY_NORMAL; 1984 error_flag = TTY_NORMAL;
1945 /* Although the device uses a bitmask and hence can have multiple */ 1985 /* Although the device uses a bitmask and hence can have multiple */
@@ -1962,13 +2002,8 @@ static void ftdi_process_read (struct usb_serial_port *port)
1962 error_flag = TTY_FRAME; 2002 error_flag = TTY_FRAME;
1963 dbg("FRAMING error"); 2003 dbg("FRAMING error");
1964 } 2004 }
1965 if (urb->actual_length > packet_offset + 2) { 2005 if (length > 0) {
1966 for (i = 2; (i < PKTSZ) && ((i+packet_offset) < urb->actual_length); ++i) { 2006 for (i = 2; i < length+2; i++) {
1967 /* have to make sure we don't overflow the buffer
1968 with tty_insert_flip_char's */
1969 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
1970 tty_flip_buffer_push(tty);
1971 }
1972 /* Note that the error flag is duplicated for 2007 /* Note that the error flag is duplicated for
1973 every character received since we don't know 2008 every character received since we don't know
1974 which character it applied to */ 2009 which character it applied to */
@@ -2005,6 +2040,35 @@ static void ftdi_process_read (struct usb_serial_port *port)
2005 tty_flip_buffer_push(tty); 2040 tty_flip_buffer_push(tty);
2006 } 2041 }
2007 2042
2043 if (packet_offset < urb->actual_length) {
2044 /* not completely processed - record progress */
2045 priv->rx_processed = packet_offset;
2046 dbg("%s - incomplete, %d bytes processed, %d remain",
2047 __FUNCTION__, packet_offset,
2048 urb->actual_length - packet_offset);
2049 /* check if we were throttled while processing */
2050 spin_lock_irqsave(&priv->rx_lock, flags);
2051 if (priv->rx_flags & THROTTLED) {
2052 priv->rx_flags |= ACTUALLY_THROTTLED;
2053 spin_unlock_irqrestore(&priv->rx_lock, flags);
2054 dbg("%s - deferring remainder until unthrottled",
2055 __FUNCTION__);
2056 return;
2057 }
2058 spin_unlock_irqrestore(&priv->rx_lock, flags);
2059 /* if the port is closed stop trying to read */
2060 if (port->open_count > 0){
2061 /* delay processing of remainder */
2062 schedule_delayed_work(&priv->rx_work, 1);
2063 } else {
2064 dbg("%s - port is closed", __FUNCTION__);
2065 }
2066 return;
2067 }
2068
2069 /* urb is completely processed */
2070 priv->rx_processed = 0;
2071
2008 /* if the port is closed stop trying to read */ 2072 /* if the port is closed stop trying to read */
2009 if (port->open_count > 0){ 2073 if (port->open_count > 0){
2010 /* Continue trying to always read */ 2074 /* Continue trying to always read */
@@ -2444,7 +2508,7 @@ static void ftdi_unthrottle (struct usb_serial_port *port)
2444 spin_unlock_irqrestore(&priv->rx_lock, flags); 2508 spin_unlock_irqrestore(&priv->rx_lock, flags);
2445 2509
2446 if (actually_throttled) 2510 if (actually_throttled)
2447 ftdi_process_read(port); 2511 schedule_work(&priv->rx_work);
2448} 2512}
2449 2513
2450static int __init ftdi_init (void) 2514static int __init ftdi_init (void)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
new file mode 100644
index 000000000000..b722175f108f
--- /dev/null
+++ b/drivers/usb/serial/option.c
@@ -0,0 +1,729 @@
1/*
2 Option Card (PCMCIA to) USB to Serial Driver
3
4 Copyright (C) 2005 Matthias Urlichs <smurf@smurf.noris.de>
5
6 This driver is free software; you can redistribute it and/or modify
7 it under the terms of Version 2 of the GNU General Public License as
8 published by the Free Software Foundation.
9
10 Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
11
12 History:
13
14 2005-05-19 v0.1 Initial version, based on incomplete docs
15 and analysis of misbehavior of the standard driver
16 2005-05-20 v0.2 Extended the input buffer to avoid losing
17 random 64-byte chunks of data
18 2005-05-21 v0.3 implemented chars_in_buffer()
19 turned on low_latency
20 simplified the code somewhat
21*/
22#define DRIVER_VERSION "v0.3"
23#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
24#define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver"
25
26#include <linux/config.h>
27#include <linux/kernel.h>
28#include <linux/jiffies.h>
29#include <linux/errno.h>
30#include <linux/tty.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/usb.h>
34#include "usb-serial.h"
35
36/* Function prototypes */
37static int option_open (struct usb_serial_port *port, struct file *filp);
38static void option_close (struct usb_serial_port *port, struct file *filp);
39static int option_startup (struct usb_serial *serial);
40static void option_shutdown (struct usb_serial *serial);
41static void option_rx_throttle (struct usb_serial_port *port);
42static void option_rx_unthrottle (struct usb_serial_port *port);
43static int option_write_room (struct usb_serial_port *port);
44
45static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
46
47
48static int option_write (struct usb_serial_port *port,
49 const unsigned char *buf, int count);
50
51static int option_chars_in_buffer (struct usb_serial_port *port);
52static int option_ioctl (struct usb_serial_port *port, struct file *file,
53 unsigned int cmd, unsigned long arg);
54static void option_set_termios (struct usb_serial_port *port,
55 struct termios *old);
56static void option_break_ctl (struct usb_serial_port *port, int break_state);
57static int option_tiocmget (struct usb_serial_port *port, struct file *file);
58static int option_tiocmset (struct usb_serial_port *port, struct file *file,
59 unsigned int set, unsigned int clear);
60static int option_send_setup (struct usb_serial_port *port);
61
62/* Vendor and product IDs */
63#define OPTION_VENDOR_ID 0x0AF0
64
65#define OPTION_PRODUCT_OLD 0x5000
66#define OPTION_PRODUCT_WLAN 0x6000
67
68static struct usb_device_id option_ids[] = {
69 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
70 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_WLAN) },
71 { } /* Terminating entry */
72};
73
74MODULE_DEVICE_TABLE(usb, option_ids);
75
76static struct usb_driver option_driver = {
77 .owner = THIS_MODULE,
78 .name = "option",
79 .probe = usb_serial_probe,
80 .disconnect = usb_serial_disconnect,
81 .id_table = option_ids,
82};
83
84/* The card has three separate interfaces, wich the serial driver
85 * recognizes separately, thus num_port=1.
86 */
87static struct usb_serial_device_type option_3port_device = {
88 .owner = THIS_MODULE,
89 .name = "Option 3-port card",
90 .short_name = "option",
91 .id_table = option_ids,
92 .num_interrupt_in = NUM_DONT_CARE,
93 .num_bulk_in = NUM_DONT_CARE,
94 .num_bulk_out = NUM_DONT_CARE,
95 .num_ports = 1, /* 3 */
96 .open = option_open,
97 .close = option_close,
98 .write = option_write,
99 .write_room = option_write_room,
100 .chars_in_buffer = option_chars_in_buffer,
101 .throttle = option_rx_throttle,
102 .unthrottle = option_rx_unthrottle,
103 .ioctl = option_ioctl,
104 .set_termios = option_set_termios,
105 .break_ctl = option_break_ctl,
106 .tiocmget = option_tiocmget,
107 .tiocmset = option_tiocmset,
108 .attach = option_startup,
109 .shutdown = option_shutdown,
110 .read_int_callback = option_instat_callback,
111};
112
113static int debug;
114
115/* per port private data */
116
117#define N_IN_URB 4
118#define N_OUT_URB 1
119#define IN_BUFLEN 1024
120#define OUT_BUFLEN 1024
121
122struct option_port_private {
123 /* Input endpoints and buffer for this port */
124 struct urb *in_urbs[N_IN_URB];
125 char in_buffer[N_IN_URB][IN_BUFLEN];
126 /* Output endpoints and buffer for this port */
127 struct urb *out_urbs[N_OUT_URB];
128 char out_buffer[N_OUT_URB][OUT_BUFLEN];
129
130 /* Settings for the port */
131 int rts_state; /* Handshaking pins (outputs) */
132 int dtr_state;
133 int cts_state; /* Handshaking pins (inputs) */
134 int dsr_state;
135 int dcd_state;
136 int ri_state;
137 // int break_on;
138
139 unsigned long tx_start_time[N_OUT_URB];
140};
141
142
143/* Functions used by new usb-serial code. */
144static int __init
145option_init (void)
146{
147 int retval;
148 retval = usb_serial_register(&option_3port_device);
149 if (retval)
150 goto failed_3port_device_register;
151 retval = usb_register(&option_driver);
152 if (retval)
153 goto failed_driver_register;
154
155 info(DRIVER_DESC ": " DRIVER_VERSION);
156
157 return 0;
158
159failed_driver_register:
160 usb_serial_deregister (&option_3port_device);
161failed_3port_device_register:
162 return retval;
163}
164
165static void __exit
166option_exit (void)
167{
168 usb_deregister (&option_driver);
169 usb_serial_deregister (&option_3port_device);
170}
171
172module_init(option_init);
173module_exit(option_exit);
174
175static void
176option_rx_throttle (struct usb_serial_port *port)
177{
178 dbg("%s", __FUNCTION__);
179}
180
181
182static void
183option_rx_unthrottle (struct usb_serial_port *port)
184{
185 dbg("%s", __FUNCTION__);
186}
187
188
189static void
190option_break_ctl (struct usb_serial_port *port, int break_state)
191{
192 /* Unfortunately, I don't know how to send a break */
193 dbg("%s", __FUNCTION__);
194}
195
196
197static void
198option_set_termios (struct usb_serial_port *port,
199 struct termios *old_termios)
200{
201 dbg("%s", __FUNCTION__);
202
203 option_send_setup(port);
204}
205
206static int
207option_tiocmget(struct usb_serial_port *port, struct file *file)
208{
209 unsigned int value;
210 struct option_port_private *portdata;
211
212 portdata = usb_get_serial_port_data(port);
213
214 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
215 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
216 ((portdata->cts_state) ? TIOCM_CTS : 0) |
217 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
218 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
219 ((portdata->ri_state) ? TIOCM_RNG : 0);
220
221 return value;
222}
223
224static int
225option_tiocmset (struct usb_serial_port *port, struct file *file,
226 unsigned int set, unsigned int clear)
227{
228 struct option_port_private *portdata;
229
230 portdata = usb_get_serial_port_data(port);
231
232 if (set & TIOCM_RTS)
233 portdata->rts_state = 1;
234 if (set & TIOCM_DTR)
235 portdata->dtr_state = 1;
236
237 if (clear & TIOCM_RTS)
238 portdata->rts_state = 0;
239 if (clear & TIOCM_DTR)
240 portdata->dtr_state = 0;
241 return option_send_setup(port);
242}
243
244static int
245option_ioctl (struct usb_serial_port *port, struct file *file,
246 unsigned int cmd, unsigned long arg)
247{
248 return -ENOIOCTLCMD;
249}
250
251/* Write */
252static int
253option_write(struct usb_serial_port *port,
254 const unsigned char *buf, int count)
255{
256 struct option_port_private *portdata;
257 int i;
258 int left, todo;
259 struct urb *this_urb = NULL; /* spurious */
260 int err;
261
262 portdata = usb_get_serial_port_data(port);
263
264 dbg("%s: write (%d chars)", __FUNCTION__, count);
265
266#if 0
267 spin_lock(&port->lock);
268 if (port->write_urb_busy) {
269 spin_unlock(&port->lock);
270 dbg("%s: already writing", __FUNCTION__);
271 return 0;
272 }
273 port->write_urb_busy = 1;
274 spin_unlock(&port->lock);
275#endif
276
277 i = 0;
278 left = count;
279 while (left>0) {
280 todo = left;
281 if (todo > OUT_BUFLEN)
282 todo = OUT_BUFLEN;
283
284 for (;i < N_OUT_URB; i++) {
285 /* Check we have a valid urb/endpoint before we use it... */
286 this_urb = portdata->out_urbs[i];
287 if (this_urb->status != -EINPROGRESS)
288 break;
289 if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
290 continue;
291 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ))
292 continue;
293 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
294 usb_unlink_urb(this_urb);
295 }
296
297 if (i == N_OUT_URB) {
298 /* no bulk out free! */
299 dbg("%s: no output urb -- left %d", __FUNCTION__,count-left);
300#if 0
301 port->write_urb_busy = 0;
302#endif
303 return count-left;
304 }
305
306 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i);
307
308 memcpy (this_urb->transfer_buffer, buf, todo);
309
310 /* send the data out the bulk port */
311 this_urb->transfer_buffer_length = todo;
312
313 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
314 this_urb->dev = port->serial->dev;
315 err = usb_submit_urb(this_urb, GFP_ATOMIC);
316 if (err) {
317 dbg("usb_submit_urb %p (write bulk) failed (%d,, has %d)", this_urb, err, this_urb->status);
318 continue;
319 }
320 portdata->tx_start_time[i] = jiffies;
321 buf += todo;
322 left -= todo;
323 }
324
325 count -= left;
326#if 0
327 port->write_urb_busy = 0;
328#endif
329 dbg("%s: wrote (did %d)", __FUNCTION__, count);
330 return count;
331}
332
333static void
334option_indat_callback (struct urb *urb, struct pt_regs *regs)
335{
336 int i, err;
337 int endpoint;
338 struct usb_serial_port *port;
339 struct tty_struct *tty;
340 unsigned char *data = urb->transfer_buffer;
341
342 dbg("%s: %p", __FUNCTION__, urb);
343
344 endpoint = usb_pipeendpoint(urb->pipe);
345 port = (struct usb_serial_port *) urb->context;
346
347 if (urb->status) {
348 dbg("%s: nonzero status: %d on endpoint %02x.",
349 __FUNCTION__, urb->status, endpoint);
350 } else {
351 tty = port->tty;
352 if (urb->actual_length) {
353 for (i = 0; i < urb->actual_length ; ++i) {
354 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
355 tty_flip_buffer_push(tty);
356 tty_insert_flip_char(tty, data[i], 0);
357 }
358 tty_flip_buffer_push(tty);
359 } else {
360 dbg("%s: empty read urb received", __FUNCTION__);
361 }
362
363 /* Resubmit urb so we continue receiving */
364 if (port->open_count && urb->status != -ESHUTDOWN) {
365 err = usb_submit_urb(urb, GFP_ATOMIC);
366 if (err)
367 printk(KERN_ERR "%s: resubmit read urb failed. (%d)", __FUNCTION__, err);
368 }
369 }
370 return;
371}
372
373static void
374option_outdat_callback (struct urb *urb, struct pt_regs *regs)
375{
376 struct usb_serial_port *port;
377
378 dbg("%s", __FUNCTION__);
379
380 port = (struct usb_serial_port *) urb->context;
381
382 if (port->open_count)
383 schedule_work(&port->work);
384}
385
386static void
387option_instat_callback (struct urb *urb, struct pt_regs *regs)
388{
389 int err;
390 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
391 struct option_port_private *portdata = usb_get_serial_port_data(port);
392 struct usb_serial *serial = port->serial;
393
394 dbg("%s", __FUNCTION__);
395 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
396
397 if (urb->status == 0) {
398 struct usb_ctrlrequest *req_pkt =
399 (struct usb_ctrlrequest *)urb->transfer_buffer;
400
401 if (!req_pkt) {
402 dbg("%s: NULL req_pkt\n", __FUNCTION__);
403 return;
404 }
405 if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) {
406 int old_dcd_state;
407 unsigned char signals = *((unsigned char *)
408 urb->transfer_buffer + sizeof(struct usb_ctrlrequest));
409
410 dbg("%s: signal x%x", __FUNCTION__, signals);
411
412 old_dcd_state = portdata->dcd_state;
413 portdata->cts_state = 1;
414 portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
415 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
416 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
417
418 if (port->tty && !C_CLOCAL(port->tty)
419 && old_dcd_state && !portdata->dcd_state) {
420 tty_hangup(port->tty);
421 }
422 } else
423 dbg("%s: type %x req %x", __FUNCTION__, req_pkt->bRequestType,req_pkt->bRequest);
424 } else
425 dbg("%s: error %d", __FUNCTION__, urb->status);
426
427 /* Resubmit urb so we continue receiving IRQ data */
428 if (urb->status != -ESHUTDOWN) {
429 urb->dev = serial->dev;
430 err = usb_submit_urb(urb, GFP_ATOMIC);
431 if (err)
432 dbg("%s: resubmit intr urb failed. (%d)", __FUNCTION__, err);
433 }
434}
435
436
437static int
438option_write_room (struct usb_serial_port *port)
439{
440 struct option_port_private *portdata;
441 int i;
442 int data_len = 0;
443 struct urb *this_urb;
444
445 portdata = usb_get_serial_port_data(port);
446
447 for (i=0; i < N_OUT_URB; i++)
448 this_urb = portdata->out_urbs[i];
449 if (this_urb && this_urb->status != -EINPROGRESS)
450 data_len += OUT_BUFLEN;
451
452 dbg("%s: %d", __FUNCTION__, data_len);
453 return data_len;
454}
455
456
457static int
458option_chars_in_buffer (struct usb_serial_port *port)
459{
460 struct option_port_private *portdata;
461 int i;
462 int data_len = 0;
463 struct urb *this_urb;
464
465 portdata = usb_get_serial_port_data(port);
466
467 for (i=0; i < N_OUT_URB; i++)
468 this_urb = portdata->out_urbs[i];
469 if (this_urb && this_urb->status == -EINPROGRESS)
470 data_len += this_urb->transfer_buffer_length;
471
472 dbg("%s: %d", __FUNCTION__, data_len);
473 return data_len;
474}
475
476
477static int
478option_open (struct usb_serial_port *port, struct file *filp)
479{
480 struct option_port_private *portdata;
481 struct usb_serial *serial = port->serial;
482 int i, err;
483 struct urb *urb;
484
485 portdata = usb_get_serial_port_data(port);
486
487 dbg("%s", __FUNCTION__);
488
489 /* Set some sane defaults */
490 portdata->rts_state = 1;
491 portdata->dtr_state = 1;
492
493 /* Reset low level data toggle and start reading from endpoints */
494 for (i = 0; i < N_IN_URB; i++) {
495 urb = portdata->in_urbs[i];
496 if (! urb)
497 continue;
498 if (urb->dev != serial->dev) {
499 dbg("%s: dev %p != %p", __FUNCTION__, urb->dev, serial->dev);
500 continue;
501 }
502
503 /* make sure endpoint data toggle is synchronized with the device */
504
505 usb_clear_halt(urb->dev, urb->pipe);
506
507 err = usb_submit_urb(urb, GFP_KERNEL);
508 if (err) {
509 dbg("%s: submit urb %d failed (%d) %d", __FUNCTION__, i, err,
510 urb->transfer_buffer_length);
511 }
512 }
513
514 /* Reset low level data toggle on out endpoints */
515 for (i = 0; i < N_OUT_URB; i++) {
516 urb = portdata->out_urbs[i];
517 if (! urb)
518 continue;
519 urb->dev = serial->dev;
520 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */
521 }
522
523 port->tty->low_latency = 1;
524
525 option_send_setup(port);
526
527 return (0);
528}
529
530static inline void
531stop_urb(struct urb *urb)
532{
533 if (urb && urb->status == -EINPROGRESS) {
534 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
535 usb_kill_urb(urb);
536 }
537}
538
539static void
540option_close(struct usb_serial_port *port, struct file *filp)
541{
542 int i;
543 struct usb_serial *serial = port->serial;
544 struct option_port_private *portdata;
545
546 dbg("%s", __FUNCTION__);
547 portdata = usb_get_serial_port_data(port);
548
549 portdata->rts_state = 0;
550 portdata->dtr_state = 0;
551
552 if (serial->dev) {
553 option_send_setup(port);
554
555 /* Stop reading/writing urbs */
556 for (i = 0; i < N_IN_URB; i++)
557 stop_urb(portdata->in_urbs[i]);
558 for (i = 0; i < N_OUT_URB; i++)
559 stop_urb(portdata->out_urbs[i]);
560 }
561 port->tty = NULL;
562}
563
564
565/* Helper functions used by option_setup_urbs */
566static struct urb *
567option_setup_urb (struct usb_serial *serial, int endpoint,
568 int dir, void *ctx, char *buf, int len,
569 void (*callback)(struct urb *, struct pt_regs *regs))
570{
571 struct urb *urb;
572
573 if (endpoint == -1)
574 return NULL; /* endpoint not needed */
575
576 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
577 if (urb == NULL) {
578 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
579 return NULL;
580 }
581
582 /* Fill URB using supplied data. */
583 usb_fill_bulk_urb(urb, serial->dev,
584 usb_sndbulkpipe(serial->dev, endpoint) | dir,
585 buf, len, callback, ctx);
586
587 return urb;
588}
589
590/* Setup urbs */
591static void
592option_setup_urbs(struct usb_serial *serial)
593{
594 int j;
595 struct usb_serial_port *port;
596 struct option_port_private *portdata;
597
598 dbg("%s", __FUNCTION__);
599
600 port = serial->port[0];
601 portdata = usb_get_serial_port_data(port);
602
603 /* Do indat endpoints first */
604 for (j = 0; j <= N_IN_URB; ++j) {
605 portdata->in_urbs[j] = option_setup_urb (serial,
606 port->bulk_in_endpointAddress, USB_DIR_IN, port,
607 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
608 }
609
610 /* outdat endpoints */
611 for (j = 0; j <= N_OUT_URB; ++j) {
612 portdata->out_urbs[j] = option_setup_urb (serial,
613 port->bulk_out_endpointAddress, USB_DIR_OUT, port,
614 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
615 }
616}
617
618
619static int
620option_send_setup(struct usb_serial_port *port)
621{
622 struct usb_serial *serial = port->serial;
623 struct option_port_private *portdata;
624
625 dbg("%s", __FUNCTION__);
626
627 portdata = usb_get_serial_port_data(port);
628
629 if (port->tty) {
630 int val = 0;
631 if (portdata->dtr_state)
632 val |= 0x01;
633 if (portdata->rts_state)
634 val |= 0x02;
635
636 return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
637 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
638 }
639
640 return 0;
641}
642
643
644static int
645option_startup (struct usb_serial *serial)
646{
647 int i, err;
648 struct usb_serial_port *port;
649 struct option_port_private *portdata;
650
651 dbg("%s", __FUNCTION__);
652
653 /* Now setup per port private data */
654 for (i = 0; i < serial->num_ports; i++) {
655 port = serial->port[i];
656 portdata = kmalloc(sizeof(struct option_port_private), GFP_KERNEL);
657 if (!portdata) {
658 dbg("%s: kmalloc for option_port_private (%d) failed!.", __FUNCTION__, i);
659 return (1);
660 }
661 memset(portdata, 0, sizeof(struct option_port_private));
662
663 usb_set_serial_port_data(port, portdata);
664
665 if (! port->interrupt_in_urb)
666 continue;
667 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
668 if (err)
669 dbg("%s: submit irq_in urb failed %d", __FUNCTION__, err);
670 }
671
672 option_setup_urbs(serial);
673
674 return (0);
675}
676
677static void
678option_shutdown (struct usb_serial *serial)
679{
680 int i, j;
681 struct usb_serial_port *port;
682 struct option_port_private *portdata;
683
684 dbg("%s", __FUNCTION__);
685
686 /* Stop reading/writing urbs */
687 for (i = 0; i < serial->num_ports; ++i) {
688 port = serial->port[i];
689 portdata = usb_get_serial_port_data(port);
690 for (j = 0; j < N_IN_URB; j++)
691 stop_urb(portdata->in_urbs[j]);
692 for (j = 0; j < N_OUT_URB; j++)
693 stop_urb(portdata->out_urbs[j]);
694 }
695
696 /* Now free them */
697 for (i = 0; i < serial->num_ports; ++i) {
698 port = serial->port[i];
699 portdata = usb_get_serial_port_data(port);
700
701 for (j = 0; j < N_IN_URB; j++) {
702 if (portdata->in_urbs[j]) {
703 usb_free_urb(portdata->in_urbs[j]);
704 portdata->in_urbs[j] = NULL;
705 }
706 }
707 for (j = 0; j < N_OUT_URB; j++) {
708 if (portdata->out_urbs[j]) {
709 usb_free_urb(portdata->out_urbs[j]);
710 portdata->out_urbs[j] = NULL;
711 }
712 }
713 }
714
715 /* Now free per port private data */
716 for (i = 0; i < serial->num_ports; i++) {
717 port = serial->port[i];
718 kfree(usb_get_serial_port_data(port));
719 }
720}
721
722MODULE_AUTHOR(DRIVER_AUTHOR);
723MODULE_DESCRIPTION(DRIVER_DESC);
724MODULE_VERSION(DRIVER_VERSION);
725MODULE_LICENSE("GPL");
726
727module_param(debug, bool, S_IRUGO | S_IWUSR);
728MODULE_PARM_DESC(debug, "Debug messages");
729
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index d2891f475793..9fcc7bd1fbe4 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -862,6 +862,15 @@ UNUSUAL_DEV( 0x090a, 0x1001, 0x0100, 0x0100,
862 US_SC_DEVICE, US_PR_BULK, NULL, 862 US_SC_DEVICE, US_PR_BULK, NULL,
863 US_FL_NEED_OVERRIDE ), 863 US_FL_NEED_OVERRIDE ),
864 864
865/* Reported by Filippo Bardelli <filibard@libero.it>
866 * The device reports a subclass of RBC, which is wrong.
867 */
868UNUSUAL_DEV( 0x090a, 0x1050, 0x0100, 0x0100,
869 "Trumpion Microelectronics, Inc.",
870 "33520 USB Digital Voice Recorder",
871 US_SC_UFI, US_PR_DEVICE, NULL,
872 0),
873
865/* Trumpion Microelectronics MP3 player (felipe_alfaro@linuxmail.org) */ 874/* Trumpion Microelectronics MP3 player (felipe_alfaro@linuxmail.org) */
866UNUSUAL_DEV( 0x090a, 0x1200, 0x0000, 0x9999, 875UNUSUAL_DEV( 0x090a, 0x1200, 0x0000, 0x9999,
867 "Trumpion", 876 "Trumpion",
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index ee25b9e8db60..47a6b12bc968 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -2374,10 +2374,9 @@ static int radeonfb_pci_register (struct pci_dev *pdev,
2374 } while ( rinfo->fb_base == 0 && 2374 } while ( rinfo->fb_base == 0 &&
2375 ((rinfo->mapped_vram /=2) >= MIN_MAPPED_VRAM) ); 2375 ((rinfo->mapped_vram /=2) >= MIN_MAPPED_VRAM) );
2376 2376
2377 if (rinfo->fb_base) 2377 if (rinfo->fb_base == NULL) {
2378 memset_io(rinfo->fb_base, 0, rinfo->mapped_vram); 2378 printk (KERN_ERR "radeonfb (%s): cannot map FB\n",
2379 else { 2379 pci_name(rinfo->pdev));
2380 printk (KERN_ERR "radeonfb (%s): cannot map FB\n", pci_name(rinfo->pdev));
2381 ret = -EIO; 2380 ret = -EIO;
2382 goto err_unmap_rom; 2381 goto err_unmap_rom;
2383 } 2382 }
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index c78a2c5961d3..277d733c6d00 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -241,7 +241,7 @@ static ssize_t show_virtual(struct class_device *class_device, char *buf)
241 struct fb_info *fb_info = 241 struct fb_info *fb_info =
242 (struct fb_info *)class_get_devdata(class_device); 242 (struct fb_info *)class_get_devdata(class_device);
243 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual, 243 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xres_virtual,
244 fb_info->var.xres_virtual); 244 fb_info->var.yres_virtual);
245} 245}
246 246
247static ssize_t store_cmap(struct class_device *class_device, const char * buf, 247static ssize_t store_cmap(struct class_device *class_device, const char * buf,
diff --git a/drivers/video/macmodes.c b/drivers/video/macmodes.c
index de5a0f383600..2fc71081f7e7 100644
--- a/drivers/video/macmodes.c
+++ b/drivers/video/macmodes.c
@@ -387,3 +387,4 @@ int __init mac_find_mode(struct fb_var_screeninfo *var, struct fb_info *info,
387} 387}
388EXPORT_SYMBOL(mac_find_mode); 388EXPORT_SYMBOL(mac_find_mode);
389 389
390MODULE_LICENSE("GPL");