⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ehci-q.c

📁 一个2.4.21版本的嵌入式linux内核
💻 C
📖 第 1 页 / 共 2 页
字号:
			qtd_fill (qtd, 0, 0, token, 0);		}	}	/* by default, enable interrupt on urb completion */	if (likely (!(urb->transfer_flags & URB_NO_INTERRUPT)))		qtd->hw_token |= __constant_cpu_to_le32 (QTD_IOC);	return head;cleanup:	qtd_list_free (ehci, urb, head);	return 0;}/*-------------------------------------------------------------------------*//* * Hardware maintains data toggle (like OHCI) ... here we (re)initialize * the hardware data toggle in the QH, and set the pseudo-toggle in udev * so we can see if usb_clear_halt() was called.  NOP for control, since * we set up qh->hw_info1 to always use the QTD toggle bits.  */static inline voidclear_toggle (struct usb_device *udev, int ep, int is_out, struct ehci_qh *qh){	vdbg ("clear toggle, dev %d ep 0x%x-%s",		udev->devnum, ep, is_out ? "out" : "in");	qh->hw_token &= ~__constant_cpu_to_le32 (QTD_TOGGLE);	usb_settoggle (udev, ep, is_out, 1);}// Would be best to create all qh's from config descriptors,// when each interface/altsetting is established.  Unlink// any previous qh and cancel its urbs first; endpoints are// implicitly reset then (data toggle too).// That'd mean updating how usbcore talks to HCDs. (2.5?)// high bandwidth multiplier, as encoded in highspeed endpoint descriptors#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))// ... and packet size, for any kind of endpoint descriptor#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x03ff)/* * Each QH holds a qtd list; a QH is used for everything except iso. * * For interrupt urbs, the scheduler must set the microframe scheduling * mask(s) each time the QH gets scheduled.  For highspeed, that's * just one microframe in the s-mask.  For split interrupt transactions * there are additional complications: c-mask, maybe FSTNs. */static struct ehci_qh *qh_make (	struct ehci_hcd		*ehci,	struct urb		*urb,	int			flags) {	struct ehci_qh		*qh = ehci_qh_alloc (ehci, flags);	u32			info1 = 0, info2 = 0;	int			is_input, type;	int			maxp = 0;	if (!qh)		return qh;	/*	 * init endpoint/device data for this QH	 */	info1 |= usb_pipeendpoint (urb->pipe) << 8;	info1 |= usb_pipedevice (urb->pipe) << 0;	is_input = usb_pipein (urb->pipe);	type = usb_pipetype (urb->pipe);	maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);	/* Compute interrupt scheduling parameters just once, and save.	 * - allowing for high bandwidth, how many nsec/uframe are used?	 * - split transactions need a second CSPLIT uframe; same question	 * - splits also need a schedule gap (for full/low speed I/O)	 * - qh has a polling interval	 *	 * For control/bulk requests, the HC or TT handles these.	 */	if (type == PIPE_INTERRUPT) {		qh->usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0,				hb_mult (maxp) * max_packet (maxp));		qh->start = NO_FRAME;		if (urb->dev->speed == USB_SPEED_HIGH) {			qh->c_usecs = 0;			qh->gap_uf = 0;			/* FIXME handle HS periods of less than 1 frame. */			qh->period = urb->interval >> 3;			if (qh->period < 1) {				dbg ("intr period %d uframes, NYET!",						urb->interval);				goto done;			}		} else {			/* gap is f(FS/LS transfer times) */			qh->gap_uf = 1 + usb_calc_bus_time (urb->dev->speed,					is_input, 0, maxp) / (125 * 1000);			/* FIXME this just approximates SPLIT/CSPLIT times */			if (is_input) {		// SPLIT, gap, CSPLIT+DATA				qh->c_usecs = qh->usecs + HS_USECS (0);				qh->usecs = HS_USECS (1);			} else {		// SPLIT+DATA, gap, CSPLIT				qh->usecs += HS_USECS (1);				qh->c_usecs = HS_USECS (0);			}			qh->period = urb->interval;		}	}	/* using TT? */	switch (urb->dev->speed) {	case USB_SPEED_LOW:		info1 |= (1 << 12);	/* EPS "low" */		/* FALL THROUGH */	case USB_SPEED_FULL:		/* EPS 0 means "full" */		if (type != PIPE_INTERRUPT)			info1 |= (EHCI_TUNE_RL_TT << 28);		if (type == PIPE_CONTROL) {			info1 |= (1 << 27);	/* for TT */			info1 |= 1 << 14;	/* toggle from qtd */		}		info1 |= maxp << 16;		info2 |= (EHCI_TUNE_MULT_TT << 30);		info2 |= urb->dev->ttport << 23;		info2 |= urb->dev->tt->hub->devnum << 16;		/* NOTE:  if (PIPE_INTERRUPT) { scheduler sets c-mask } */		break;	case USB_SPEED_HIGH:		/* no TT involved */		info1 |= (2 << 12);	/* EPS "high" */		if (type == PIPE_CONTROL) {			info1 |= (EHCI_TUNE_RL_HS << 28);			info1 |= 64 << 16;	/* usb2 fixed maxpacket */			info1 |= 1 << 14;	/* toggle from qtd */			info2 |= (EHCI_TUNE_MULT_HS << 30);		} else if (type == PIPE_BULK) {			info1 |= (EHCI_TUNE_RL_HS << 28);			info1 |= 512 << 16;	/* usb2 fixed maxpacket */			info2 |= (EHCI_TUNE_MULT_HS << 30);		} else {		/* PIPE_INTERRUPT */			info1 |= max_packet (maxp) << 16;			info2 |= hb_mult (maxp) << 30;		}		break;	default: 		dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed);done:		qh_put (ehci, qh);		return 0;	}	/* NOTE:  if (PIPE_INTERRUPT) { scheduler sets s-mask } */	/* init as halted, toggle clear, advance to dummy */	qh->qh_state = QH_STATE_IDLE;	qh->hw_info1 = cpu_to_le32 (info1);	qh->hw_info2 = cpu_to_le32 (info2);	qh_update (ehci, qh, qh->dummy);	qh->hw_token = cpu_to_le32 (QTD_STS_HALT);	usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);	return qh;}#undef hb_mult#undef hb_packet/*-------------------------------------------------------------------------*//* move qh (and its qtds) onto async queue; maybe enable queue.  */static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh){	u32		dma = QH_NEXT (qh->qh_dma);	struct ehci_qh	*head;	/* (re)start the async schedule? */	head = ehci->async;	if (ehci->async_idle)		del_timer (&ehci->watchdog);	if (!head->qh_next.qh) {		u32	cmd = readl (&ehci->regs->command);		if (!(cmd & CMD_ASE)) {			/* in case a clear of CMD_ASE didn't take yet */			(void) handshake (&ehci->regs->status, STS_ASS, 0, 150);			/* force async head to be valid */			writel ((u32)ehci->async->qh_dma,					&ehci->regs->async_next);			cmd |= CMD_ASE | CMD_RUN;			writel (cmd, &ehci->regs->command);			ehci->hcd.state = USB_STATE_RUNNING;			/* posted write need not be known to HC yet ... */		}	}	qh->hw_token &= ~__constant_cpu_to_le32 (QTD_STS_HALT);	/* splice right after start */	qh->qh_next = head->qh_next;	qh->hw_next = head->hw_next;	wmb ();	head->qh_next.qh = qh;	head->hw_next = dma;	qh->qh_state = QH_STATE_LINKED;	/* qtd completions reported later by interrupt */	ehci->async_idle = 0;}/*-------------------------------------------------------------------------*//* * For control/bulk/interrupt, return QH with these TDs appended. * Allocates and initializes the QH if necessary. * Returns null if it can't allocate a QH it needs to. * If the QH has TDs (urbs) already, that's great. */static struct ehci_qh *qh_append_tds (	struct ehci_hcd		*ehci,	struct urb		*urb,	struct list_head	*qtd_list,	int			epnum,	void			**ptr){	struct ehci_qh		*qh = 0;	qh = (struct ehci_qh *) *ptr;	if (unlikely (qh == 0)) {		/* can't sleep here, we have ehci->lock... */		qh = qh_make (ehci, urb, SLAB_ATOMIC);		*ptr = qh;	}	if (likely (qh != 0)) {		struct ehci_qtd	*qtd;		if (unlikely (list_empty (qtd_list)))			qtd = 0;		else			qtd = list_entry (qtd_list->next, struct ehci_qtd,					qtd_list);		/* control qh may need patching after enumeration */		if (unlikely (epnum == 0)) {			/* set_address changes the address */			if (le32_to_cpu (qh->hw_info1 & 0x7f) == 0)				qh->hw_info1 |= cpu_to_le32 (						usb_pipedevice (urb->pipe));			/* for full speed, ep0 maxpacket can grow */			else if (!(qh->hw_info1 & cpu_to_le32 (0x3 << 12))) {				u32	info, max;				info = le32_to_cpu (qh->hw_info1);				max = urb->dev->descriptor.bMaxPacketSize0;				if (max > (0x07ff & (info >> 16))) {					info &= ~(0x07ff << 16);					info |= max << 16;					qh->hw_info1 = cpu_to_le32 (info);				}			}		}		/* FIXME:  changing config or interface setting is not		 * supported yet.  preferred fix is for usbcore to tell		 * us to clear out each endpoint's state, but...		 */		/* usb_clear_halt() means qh data toggle gets reset */		if (unlikely (!usb_gettoggle (urb->dev,					(epnum & 0x0f), !(epnum & 0x10)))				&& !usb_pipecontrol (urb->pipe)) {			/* "never happens": drivers do stall cleanup right */			if (qh->qh_state != QH_STATE_IDLE					&& !list_empty (&qh->qtd_list)					&& qh->qh_state != QH_STATE_COMPLETING)				ehci_warn (ehci, "clear toggle dev%d "						"ep%d%s: not idle\n",						usb_pipedevice (urb->pipe),						epnum & 0x0f,						usb_pipein (urb->pipe)							? "in" : "out");			/* else we know this overlay write is safe */			clear_toggle (urb->dev,				epnum & 0x0f, !(epnum & 0x10), qh);		}		/* just one way to queue requests: swap with the dummy qtd.		 * only hc or qh_completions() usually modify the overlay.		 */		if (likely (qtd != 0)) {			struct ehci_qtd		*dummy;			dma_addr_t		dma;			u32			token;			/* to avoid racing the HC, use the dummy td instead of			 * the first td of our list (becomes new dummy).  both			 * tds stay deactivated until we're done, when the			 * HC is allowed to fetch the old dummy (4.10.2).			 */			token = qtd->hw_token;			qtd->hw_token = cpu_to_le32 (QTD_STS_HALT);			wmb ();			dummy = qh->dummy;			dma = dummy->qtd_dma;			*dummy = *qtd;			dummy->qtd_dma = dma;			list_del (&qtd->qtd_list);			list_add (&dummy->qtd_list, qtd_list);			__list_splice (qtd_list, qh->qtd_list.prev);			ehci_qtd_init (qtd, qtd->qtd_dma);			qh->dummy = qtd;			/* hc must see the new dummy at list end */			dma = qtd->qtd_dma;			qtd = list_entry (qh->qtd_list.prev,					struct ehci_qtd, qtd_list);			qtd->hw_next = QTD_NEXT (dma);			/* let the hc process these next qtds */			wmb ();			dummy->hw_token = token;			urb->hcpriv = qh_get (qh);		}	}	return qh;}/*-------------------------------------------------------------------------*/static intsubmit_async (	struct ehci_hcd		*ehci,	struct urb		*urb,	struct list_head	*qtd_list,	int			mem_flags) {	struct ehci_qtd		*qtd;	struct hcd_dev		*dev;	int			epnum;	unsigned long		flags;	struct ehci_qh		*qh = 0;	qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);	dev = (struct hcd_dev *)urb->dev->hcpriv;	epnum = usb_pipeendpoint (urb->pipe);	if (usb_pipein (urb->pipe) && !usb_pipecontrol (urb->pipe))		epnum |= 0x10;	ehci_vdbg (ehci, "submit_async urb %p len %d ep%d%s qtd %p [qh %p]\n",		urb, urb->transfer_buffer_length,		epnum & 0x0f, (epnum & 0x10) ? "in" : "out",		qtd, dev ? dev->ep [epnum] : (void *)~0);	spin_lock_irqsave (&ehci->lock, flags);	qh = qh_append_tds (ehci, urb, qtd_list, epnum, &dev->ep [epnum]);	/* Control/bulk operations through TTs don't need scheduling,	 * the HC and TT handle it when the TT has a buffer ready.	 */	if (likely (qh != 0)) {		if (likely (qh->qh_state == QH_STATE_IDLE))			qh_link_async (ehci, qh_get (qh));	}	spin_unlock_irqrestore (&ehci->lock, flags);	if (unlikely (qh == 0)) {		qtd_list_free (ehci, urb, qtd_list);		return -ENOMEM;	}	return 0;}/*-------------------------------------------------------------------------*//* the async qh for the qtds being reclaimed are now unlinked from the HC */static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh);static void end_unlink_async (struct ehci_hcd *ehci, struct pt_regs *regs){	struct ehci_qh		*qh = ehci->reclaim;	struct ehci_qh		*next;	del_timer (&ehci->watchdog);	// qh->hw_next = cpu_to_le32 (qh->qh_dma);	qh->qh_state = QH_STATE_IDLE;	qh->qh_next.qh = 0;	qh_put (ehci, qh);			// refcount from reclaim 	ehci->reclaim = 0;	ehci->reclaim_ready = 0;	/* other unlink(s) may be pending (in QH_STATE_UNLINK_WAIT) */	next = qh->reclaim;	qh->reclaim = 0;	qh_completions (ehci, qh, regs);	if (!list_empty (&qh->qtd_list)			&& HCD_IS_RUNNING (ehci->hcd.state))		qh_link_async (ehci, qh);	else {		qh_put (ehci, qh);		// refcount from async list		/* it's not free to turn the async schedule on/off; leave it		 * active but idle for a while once it empties.		 */		if (HCD_IS_RUNNING (ehci->hcd.state)				&& ehci->async->qh_next.qh == 0				&& !timer_pending (&ehci->watchdog)) {			ehci->async_idle = 1;			mod_timer (&ehci->watchdog,					jiffies + EHCI_ASYNC_JIFFIES);		}	}	if (next)		start_unlink_async (ehci, next);}/* makes sure the async qh will become idle *//* caller must own ehci->lock */static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh){	int		cmd = readl (&ehci->regs->command);	struct ehci_qh	*prev;#ifdef DEBUG	if (ehci->reclaim			|| (qh->qh_state != QH_STATE_LINKED				&& qh->qh_state != QH_STATE_UNLINK_WAIT)#ifdef CONFIG_SMP// this macro lies except on SMP compiles			|| !spin_is_locked (&ehci->lock)#endif			)		BUG ();#endif	/* stop async schedule right now? */	if (unlikely (qh == ehci->async)) {		/* can't get here without STS_ASS set */		if (ehci->hcd.state != USB_STATE_HALT) {			writel (cmd & ~CMD_ASE, &ehci->regs->command);			wmb ();			// handshake later, if we need to		}		return;	} 	qh->qh_state = QH_STATE_UNLINK;	ehci->reclaim = qh = qh_get (qh);	prev = ehci->async;	while (prev->qh_next.qh != qh)		prev = prev->qh_next.qh;	prev->hw_next = qh->hw_next;	prev->qh_next = qh->qh_next;	wmb ();	if (unlikely (ehci->hcd.state == USB_STATE_HALT)) {		/* if (unlikely (qh->reclaim != 0))		 * 	this will recurse, probably not much		 */		end_unlink_async (ehci, NULL);		return;	}	ehci->reclaim_ready = 0;	cmd |= CMD_IAAD;	writel (cmd, &ehci->regs->command);	/* posted write need not be known to HC yet ... */	mod_timer (&ehci->watchdog, jiffies + EHCI_WATCHDOG_JIFFIES);}/*-------------------------------------------------------------------------*/static voidscan_async (struct ehci_hcd *ehci, struct pt_regs *regs){	struct ehci_qh		*qh;	int			unlink_delay = 0;	if (!++(ehci->stamp))		ehci->stamp++;rescan:	qh = ehci->async->qh_next.qh;	if (likely (qh != 0)) {		do {			/* clean any finished work for this qh */			if (!list_empty (&qh->qtd_list)					&& qh->stamp != ehci->stamp) {				int temp;				/* unlinks could happen here; completion				 * reporting drops the lock.  rescan using				 * the latest schedule, but don't rescan				 * qhs we already finished (no looping).				 */				qh = qh_get (qh);				qh->stamp = ehci->stamp;				temp = qh_completions (ehci, qh, regs);				qh_put (ehci, qh);				if (temp != 0) {					goto rescan;				}			}			/* unlink idle entries, reducing HC PCI usage as well			 * as HCD schedule-scanning costs.  delay for any qh			 * we just scanned, there's a not-unusual case that it			 * doesn't stay idle for long.			 * (plus, avoids some kind of re-activation race.)			 */			if (list_empty (&qh->qtd_list)) {				if (qh->stamp == ehci->stamp)					unlink_delay = 1;				else if (!ehci->reclaim) {					start_unlink_async (ehci, qh);					unlink_delay = 0;				}			}			qh = qh->qh_next.qh;		} while (qh);	}	if (unlink_delay && !timer_pending (&ehci->watchdog))		mod_timer (&ehci->watchdog, jiffies + EHCI_WATCHDOG_JIFFIES/2);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -