Revert "Use small lock to protect usbdev and endpoint in arch mips"

This reverts commit ac2b495945.
This commit is contained in:
Xiang Xiao
2025-02-06 23:04:17 +08:00
committed by archer
parent a488b22b22
commit 556a81d8e4
+20 -42
View File
@@ -44,10 +44,8 @@
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <sched.h>
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include <nuttx/wdog.h>
#include <nuttx/kmalloc.h>
#include <nuttx/usb/usb.h>
@@ -409,10 +407,6 @@ struct pic32mx_usbdev_s
/* The endpoint list */
struct pic32mx_ep_s eplist[PIC32MX_NENDPOINTS];
/* Spinlock */
spinlock_t lock;
};
/****************************************************************************
@@ -803,9 +797,9 @@ static void pic32mx_reqcomplete(struct pic32mx_ep_s *privep, int16_t result)
* request list.
*/
flags = spin_lock_irqsave(&privep->dev->lock);
flags = enter_critical_section();
privreq = pic32mx_remfirst(&privep->active);
spin_unlock_irqrestore(&privep->dev->lock, flags);
leave_critical_section(flags);
if (privreq)
{
@@ -3009,7 +3003,7 @@ static void pic32mx_resume(struct pic32mx_usbdev_s *priv)
irqstate_t flags;
uint16_t regval;
flags = spin_lock_irqsave(&priv->lock);
flags = enter_critical_section();
/* Start RESUME signaling */
@@ -3057,7 +3051,7 @@ static void pic32mx_resume(struct pic32mx_usbdev_s *priv)
CLASS_RESUME(priv->driver, &priv->usbdev);
}
spin_unlock_irqrestore(&priv->lock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@@ -3075,7 +3069,7 @@ pic32mx_epreserve(struct pic32mx_usbdev_s *priv, uint8_t epset)
irqstate_t flags;
int epndx = 0;
flags = spin_lock_irqsave(&priv->lock);
flags = enter_critical_section();
epset &= priv->epavail;
if (epset)
{
@@ -3100,7 +3094,7 @@ pic32mx_epreserve(struct pic32mx_usbdev_s *priv, uint8_t epset)
}
}
spin_unlock_irqrestore(&priv->lock, flags);
leave_critical_section(flags);
return privep;
}
@@ -3112,9 +3106,9 @@ static inline void
pic32mx_epunreserve(struct pic32mx_usbdev_s *priv,
struct pic32mx_ep_s *privep)
{
irqstate_t flags = spin_lock_irqsave(&priv->lock);
irqstate_t flags = enter_critical_section();
priv->epavail |= PIC32MX_ENDP_BIT(USB_EPNO(privep->ep.eplog));
spin_unlock_irqrestore(&priv->lock, flags);
leave_critical_section(flags);
}
/****************************************************************************
@@ -3334,8 +3328,7 @@ static int pic32mx_epdisable(struct usbdev_ep_s *ep)
/* Cancel any ongoing activity */
flags = spin_lock_irqsave(&privep->dev->lock);
sched_lock();
flags = enter_critical_section();
pic32mx_cancelrequests(privep, -ESHUTDOWN);
/* Disable the endpoint */
@@ -3352,8 +3345,7 @@ static int pic32mx_epdisable(struct usbdev_ep_s *ep)
*ptr++ = 0;
}
spin_unlock_irqrestore(&privep->dev->lock, flags);
sched_unlock();
leave_critical_section(flags);
return OK;
}
@@ -3453,8 +3445,7 @@ static int pic32mx_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
#ifndef CONFIG_USBDEV_NOWRITEAHEAD
privreq->inflight[1] = 0;
#endif
flags = spin_lock_irqsave(&priv->lock);
sched_lock();
flags = enter_critical_section();
/* Add the new request to the request queue for the OUT endpoint */
@@ -3498,8 +3489,7 @@ static int pic32mx_epsubmit(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
}
}
spin_unlock_irqrestore(&priv->lock, flags);
sched_unlock();
leave_critical_section(flags);
return ret;
}
@@ -3522,11 +3512,9 @@ static int pic32mx_epcancel(struct usbdev_ep_s *ep, struct usbdev_req_s *req)
usbtrace(TRACE_EPCANCEL, USB_EPNO(ep->eplog));
flags = spin_lock_irqsave(&privep->dev->lock);
sched_lock();
flags = enter_critical_section();
pic32mx_cancelrequests(privep, -EAGAIN);
spin_unlock_irqrestore(&privep->dev->lock, flags);
sched_unlock();
leave_critical_section(flags);
return OK;
}
@@ -3717,8 +3705,7 @@ static int pic32mx_epstall(struct usbdev_ep_s *ep, bool resume)
/* STALL or RESUME the endpoint */
flags = spin_lock_irqsave(&privep->dev->lock);
sched_lock();
flags = enter_critical_section();
/* Special case EP0. When we stall EP0 we have to stall both the IN and
* OUT BDTs.
@@ -3747,8 +3734,7 @@ static int pic32mx_epstall(struct usbdev_ep_s *ep, bool resume)
ret = pic32mx_epbdtstall(ep, resume, USB_ISEPIN(ep->eplog));
}
spin_unlock_irqrestore(&privep->dev->lock, flags);
sched_unlock();
leave_critical_section(flags);
return ret;
}
@@ -4350,10 +4336,6 @@ void mips_usbinitialize(void)
usbtrace(TRACE_DEVINIT, 0);
/* Initialize driver lock */
spin_lock_init(&priv->lock);
/* Initialize the driver state structure */
pic32mx_stateinit(priv);
@@ -4401,8 +4383,7 @@ void mips_usbuninitialize(void)
struct pic32mx_usbdev_s *priv = &g_usbdev;
irqstate_t flags;
flags = spin_lock_irqsave(&priv->lock);
sched_lock();
flags = enter_critical_section();
usbtrace(TRACE_DEVUNINIT, 0);
/* Disable and detach the USB IRQs */
@@ -4419,8 +4400,7 @@ void mips_usbuninitialize(void)
/* Put the hardware in an inactive state */
pic32mx_hwshutdown(priv);
spin_unlock_irqrestore(&priv->lock, flags);
sched_unlock();
leave_critical_section(flags);
}
/****************************************************************************
@@ -4524,8 +4504,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
* the hardware back into its initial, unconnected state.
*/
flags = spin_lock_irqsave(&priv->lock);
sched_lock();
flags = enter_critical_section();
pic32mx_swreset(priv);
pic32mx_hwreset(priv);
@@ -4548,8 +4527,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver)
/* Unhook the driver */
priv->driver = NULL;
spin_unlock_irqrestore(&priv->lock, flags);
sched_unlock();
leave_critical_section(flags);
return OK;
}