patch-2.3.14 linux/drivers/usb/uhci.c

Next file: linux/drivers/usb/uhci.h
Previous file: linux/drivers/usb/proc_usb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.13/linux/drivers/usb/uhci.c linux/drivers/usb/uhci.c
@@ -63,7 +63,10 @@
 #define UHCI_DEBUG
 
 /*
- * Map status to standard result codes
+ * Map status to standard result codes.
+ *
+ * <status> is ((td->status >> 16) & 0xff) [a.k.a. uhci_status_bits(td->status)]
+ * <dir_out> is True for output TDs and False for input TDs.
  */
 static int uhci_map_status(int status, int dir_out)
 {
@@ -109,19 +112,19 @@
 	/* locate the first failing td, if any */
 
 	do {
-		status = (tmp->status >> 16) & 0xff;
+		status = uhci_status_bits(tmp->status);
 		if (status) {
 			/* must reset the toggle on first error */
     			if (uhci_debug) {
 				printk(KERN_DEBUG "Set toggle from %x rval %ld\n",
 					(unsigned int)tmp, rval ? *rval : 0);
 			}
-			usb_settoggle(dev->usb, usb_pipeendpoint(tmp->info),
-				usb_pipeout(tmp->info), (tmp->info >> 19) & 1);
+			usb_settoggle(dev->usb, uhci_endpoint(tmp->info),
+				uhci_packetout(tmp->info), uhci_toggle(tmp->info));
 			break;
 		} else {
 		    if (rval)
-			*rval += (tmp->status & 0x3ff) + 1;
+			*rval += uhci_actual_length(tmp->status);
 		}
 		if ((tmp->link & UHCI_PTR_TERM) ||
 		    (tmp->link & UHCI_PTR_QH))
@@ -153,7 +156,8 @@
 
 	if (status & 0x40) {
 		/* endpoint has stalled - mark it halted */
-		usb_endpoint_halt(dev->usb, usb_pipeendpoint(tmp->info));
+		usb_endpoint_halt(dev->usb, uhci_endpoint(tmp->info),
+	    			uhci_packetout(tmp->info));
 		return USB_ST_STALL;
 	}
 
@@ -162,7 +166,7 @@
 		if (!rval)
 			return USB_ST_DATAUNDERRUN;
 	}
-	return uhci_map_status(status, usb_pipeout(tmp->info));		
+	return uhci_map_status(status, uhci_packetout(tmp->info));
 }
 
 /*
@@ -431,9 +435,8 @@
 
 	td->link = UHCI_PTR_TERM;		/* Terminate */
 	td->status = status;			/* In */
-	td->info = destination | ((usb_maxpacket(usb_dev, pipe) - 1) << 21) |
-		(usb_gettoggle(usb_dev, usb_pipeendpoint(pipe),
-		usb_pipeout(pipe)) << 19);
+	td->info = destination | ((usb_maxpacket(usb_dev, pipe, usb_pipeout(pipe)) - 1) << 21) |
+  		(usb_gettoggle(usb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << TD_TOKEN_TOGGLE);
 	td->buffer = virt_to_bus(dev->data);
 	td->qh = qh;
 	td->dev = dev;
@@ -463,7 +466,7 @@
  *
  * This function can NOT be called from an interrupt.
  */
-int uhci_release_irq(void *handle)
+int uhci_release_irq(struct usb_device *usb, void *handle)
 {
 	struct uhci_td *td;
 	struct uhci_qh *qh;
@@ -506,14 +509,14 @@
 	for (i = 0; i < isodesc->num; i++) {
 		struct uhci_td *td = &isodesc->td[i];
 		char *cdata = uhci_ptr_to_virt(td->buffer);
-		int n = (td->status + 1) & 0x7FF;
+		int n = uhci_actual_length(td->status);
 
 		if ((cdata != data) && (n))
 			memmove(data, cdata, n);
 
 #ifdef UHCI_DEBUG
 		/* Debugging */
-		if ((td->status >> 16) & 0xFF)
+		if (uhci_status_bits(td->status))
 			printk(KERN_DEBUG "error: %d %X\n", i,
 				(td->status >> 16));
 #endif
@@ -782,15 +785,15 @@
 	struct uhci_td *first, *td, *prevtd;
 	unsigned long destination, status;
 	int ret, count;
-	int maxsze = usb_maxpacket(usb_dev, pipe);
+	int maxsze = usb_maxpacket(usb_dev, pipe, usb_pipeout(pipe));
 	__u32 nextlink;
 
 	first = td = uhci_td_alloc(dev);
 	if (!td)
 		return -ENOMEM;
 
-	/* The "pipe" thing contains the destination in bits 8--18, 0x2D is SETUP */
-	destination = (pipe & PIPE_DEVEP_MASK) | 0x2D;
+	/* The "pipe" thing contains the destination in bits 8--18. */
+	destination = (pipe & PIPE_DEVEP_MASK) | USB_PID_SETUP;
 
 	/* 3 errors */
 	status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_SPD | (3 << 27);
@@ -804,11 +807,11 @@
 
 	/*
 	 * If direction is "send", change the frame from SETUP (0x2D)
-	 * to OUT (0xE1). Else change it from SETUP to IN (0x69)
+	 * to OUT (0xE1). Else change it from SETUP to IN (0x69).
 	 */
-	destination ^= (0x2D ^ 0x69);			/* SETUP -> IN */
+	destination ^= (USB_PID_SETUP ^ USB_PID_IN);		/* SETUP -> IN */
 	if (usb_pipeout(pipe))
-		destination ^= (0xE1 ^ 0x69);		/* IN -> OUT */
+		destination ^= (USB_PID_OUT ^ USB_PID_IN);	/* IN -> OUT */
 
 	prevtd = td;
 	td = uhci_td_alloc(dev);
@@ -828,7 +831,7 @@
 			pktsze = maxsze;
 
 		/* Alternate Data0/1 (start with Data1) */
-		destination ^= 1 << 19;
+		destination ^= 1 << TD_TOKEN_TOGGLE;
 	
 		td->status = status;					/* Status */
 		td->info = destination | ((pktsze - 1) << 21);		/* pktsze bytes of data */
@@ -848,8 +851,8 @@
 	/*
 	 * Build the final TD for control status 
 	 */
-	destination ^= (0xE1 ^ 0x69);			/* OUT -> IN */
-	destination |= 1 << 19;				/* End in Data1 */
+	destination ^= (USB_PID_OUT ^ USB_PID_IN);	/* OUT -> IN */
+	destination |= 1 << TD_TOKEN_TOGGLE;		/* End in Data1 */
 
 	td->status = status | TD_CTRL_IOC;			/* no limit on errors on final packet */
 	td->info = destination | (UHCI_NULL_DATA_SIZE << 21);	/* 0 bytes of data */
@@ -962,13 +965,13 @@
 	struct uhci_td *first, *td, *prevtd;
 	unsigned long destination, status;
 	int ret;
-	int maxsze = usb_maxpacket(usb_dev, pipe);
+	int maxsze = usb_maxpacket(usb_dev, pipe, usb_pipeout(pipe));
 
-	if (usb_endpoint_halted(usb_dev, usb_pipeendpoint(pipe)) &&
-	    usb_clear_halt(usb_dev, usb_pipeendpoint(pipe) | (pipe & 0x80)))
+	if (usb_endpoint_halted(usb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) &&
+	    usb_clear_halt(usb_dev, usb_pipeendpoint(pipe) | (pipe & USB_DIR_IN)))
 		return USB_ST_STALL;
 
-	/* The "pipe" thing contains the destination in bits 8--18 */
+	/* The "pipe" thing contains the destination in bits 8--18. */
 	destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid (pipe);
 
 	/* 3 errors */
@@ -991,7 +994,8 @@
 
 		td->status = status;					/* Status */
 		td->info = destination | ((pktsze-1) << 21) |
-			 (usb_gettoggle(usb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << 19); /* pktsze bytes of data */
+			(usb_gettoggle(usb_dev, usb_pipeendpoint(pipe),
+				usb_pipeout(pipe)) << TD_TOKEN_TOGGLE); /* pktsze bytes of data */
 		td->buffer = virt_to_bus(data);
 		td->backptr = &prevtd->link;
 
@@ -1049,10 +1053,10 @@
 	struct uhci_td *first, *td, *prevtd;
 	struct uhci_qh *bulk_qh = uhci_qh_alloc(dev);
 	unsigned long destination, status;
-	int maxsze = usb_maxpacket(usb_dev, pipe);
+	int maxsze = usb_maxpacket(usb_dev, pipe, usb_pipeout(pipe));
 
-	/* The "pipe" thing contains the destination in bits 8--18, 0x69 is IN */
-	destination = (pipe & 0x0007ff00) | usb_packetid(pipe);
+	/* The "pipe" thing contains the destination in bits 8--18. */
+	destination = (pipe & PIPE_DEVEP_MASK) | usb_packetid(pipe);
 
 	/* Infinite errors is 0 */
 	status = (pipe & TD_CTRL_LS) | TD_CTRL_ACTIVE | TD_CTRL_SPD;
@@ -1069,7 +1073,7 @@
 
 		td->status = status;                                    /* Status */
 		td->info = destination | ((pktsze-1) << 21) |
-			(usb_gettoggle(usb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << 19); /* pktsze bytes of data */
+			(usb_gettoggle(usb_dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)) << TD_TOKEN_TOGGLE); /* pktsze bytes of data */
 		td->buffer = virt_to_bus(data);
 		td->backptr = &prevtd->link;
 		td->qh = bulk_qh;
@@ -1336,7 +1340,7 @@
 		list_del(&td->irq_list);
 		INIT_LIST_HEAD(&td->irq_list);
 
-		if (td->completed(uhci_map_status(status, 0),
+		if (td->completed(uhci_map_status(uhci_status_bits(status), uhci_packetout(td->info)),
 		    bus_to_virt(td->buffer), -1, td->dev_id)) {
 			list_add(&td->irq_list, &uhci->interrupt_list);
 
@@ -1344,11 +1348,12 @@
 			if (!(td->status & TD_CTRL_IOS)) {
 				struct usb_device *usb_dev = td->dev->usb;
 
-				usb_dotoggle(usb_dev, usb_pipeendpoint(td->info), usb_pipeout(td->info));
-				td->info &= ~(1 << 19); /* clear data toggle */
-				td->info |= usb_gettoggle(usb_dev, usb_pipeendpoint(td->info), usb_pipeout(td->info)) << 19; /* toggle between data0 and data1 */
+				usb_dotoggle(usb_dev, uhci_endpoint(td->info), uhci_packetout(td->info));
+				td->info &= ~(1 << TD_TOKEN_TOGGLE); /* clear data toggle */
+				td->info |= usb_gettoggle(usb_dev, uhci_endpoint(td->info),
+					uhci_packetout(td->info)) << TD_TOKEN_TOGGLE; /* toggle between data0 and data1 */
 				td->status = (td->status & 0x2F000000) | TD_CTRL_ACTIVE | TD_CTRL_IOC;
-				/* The HC removes it, so readd it */
+				/* The HC removes it, so re-add it */
 				uhci_insert_td_in_qh(td->qh, td);
 			}
 		} else if (td->flags & UHCI_TD_REMOVE) {
@@ -1356,7 +1361,7 @@
 
 			/* marked for removal */
 			td->flags &= ~UHCI_TD_REMOVE;
-			usb_dotoggle(usb_dev, usb_pipeendpoint(td->info), usb_pipeout(td->info));
+			usb_dotoggle(usb_dev, uhci_endpoint(td->info), uhci_packetout(td->info));
 			uhci_remove_qh(td->qh->skel, td->qh);
 			uhci_qh_free(td->qh);
 			uhci_td_free(td);
@@ -1433,7 +1438,7 @@
 	/* Don't clobber the frame */
 	td->link = uhci->fl->frame[0];
 	td->status = TD_CTRL_IOC;
-	td->info = (15 << 21) | 0x7f69;				/* (ignored) input packet, 16 bytes, device 127 */
+	td->info = (15 << 21) | (0x7f << 8) | USB_PID_IN;	/* (ignored) input packet, 16 bytes, device 127 */
 	td->buffer = 0;
 	td->qh = NULL;
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)