Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fae3c158 authored by Ricardo Ribalda Delgado's avatar Ricardo Ribalda Delgado Committed by Felipe Balbi
Browse files

usb: gadget: net2280: Pass checkpacth.pl test



Fix Code Style using checkpatch.pl criteria

Signed-off-by: default avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent a27f37a1
Loading
Loading
Loading
Loading
+557 −562
Original line number Diff line number Diff line
@@ -62,9 +62,9 @@
#include <linux/usb/ch9.h>
#include <linux/usb/gadget.h>
#include <linux/prefetch.h>
#include <linux/io.h>

#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/unaligned.h>

@@ -108,7 +108,7 @@ module_param(use_msi, bool, S_IRUGO);
 * mode 1 == ep-{a,b} 2K fifo each, ep-{c,d} unavailable
 * mode 2 == ep-a 2K fifo, ep-{b,c} 1K each, ep-d unavailable
 */
static ushort fifo_mode = 0;
static ushort fifo_mode;

/* "modprobe net2280 fifo_mode=1" etc */
module_param (fifo_mode, ushort, 0644);
@@ -130,7 +130,6 @@ MODULE_PARM_DESC(full_speed, "force full-speed mode -- for testing only!");

#define	DIR_STRING(bAddress) (((bAddress) & USB_DIR_IN) ? "in" : "out")

#if defined(CONFIG_USB_GADGET_DEBUG_FILES) || defined (DEBUG)
static char *type_string(u8 bmAttributes)
{
	switch ((bmAttributes) & USB_ENDPOINT_XFERTYPE_MASK) {
@@ -140,7 +139,6 @@ static char *type_string (u8 bmAttributes)
	}
	return "control";
}
#endif

#include "net2280.h"

@@ -236,7 +234,7 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
			return -ERANGE;
		}
	}
	ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC) ? 1 : 0;
	ep->is_iso = (tmp == USB_ENDPOINT_XFER_ISOC);
	/* Enable this endpoint */
	if (dev->pdev->vendor == PCI_VENDOR_ID_PLX_LEGACY) {
		tmp <<= ENDPOINT_TYPE;
@@ -493,8 +491,8 @@ static int net2280_disable (struct usb_ep *_ep)

/*-------------------------------------------------------------------------*/

static struct usb_request *
net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
static struct usb_request
*net2280_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
{
	struct net2280_ep	*ep;
	struct net2280_request	*req;
@@ -526,8 +524,7 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
	return &req->req;
}

static void
net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
static void net2280_free_request(struct usb_ep *_ep, struct usb_request *_req)
{
	struct net2280_ep	*ep;
	struct net2280_request	*req;
@@ -552,8 +549,7 @@ net2280_free_request (struct usb_ep *_ep, struct usb_request *_req)
 * at a time, but this code is simpler because it knows it only writes
 * one packet.  ep-a..ep-d should use dma instead.
 */
static void
write_fifo (struct net2280_ep *ep, struct usb_request *req)
static void write_fifo(struct net2280_ep *ep, struct usb_request *req)
{
	struct net2280_ep_regs	__iomem *regs = ep->regs;
	u8			*buf;
@@ -625,6 +621,7 @@ static void out_flush (struct net2280_ep *ep)
		BIT(DATA_PACKET_RECEIVED_INTERRUPT)
		, statp);
	writel(BIT(FIFO_FLUSH), statp);
	/* Make sure that stap is written */
	mb();
	tmp = readl(statp);
	if (tmp & BIT(DATA_OUT_PING_TOKEN_INTERRUPT)
@@ -646,8 +643,7 @@ static void out_flush (struct net2280_ep *ep)
 * for ep-a..ep-d this will read multiple packets out when they
 * have been accepted.
 */
static int
read_fifo (struct net2280_ep *ep, struct net2280_request *req)
static int read_fifo(struct net2280_ep *ep, struct net2280_request *req)
{
	struct net2280_ep_regs	__iomem *regs = ep->regs;
	u8			*buf = req->req.buf + req->req.actual;
@@ -735,8 +731,8 @@ read_fifo (struct net2280_ep *ep, struct net2280_request *req)
}

/* fill out dma descriptor to match a given request */
static void
fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
static void fill_dma_desc(struct net2280_ep *ep,
					struct net2280_request *req, int valid)
{
	struct net2280_dma	*td = req->td;
	u32			dmacount = req->req.length;
@@ -825,8 +821,8 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
	writel(0, &ep->dma->dmactl);

	/* previous OUT packet might have been short */
	if (!ep->is_in && ((tmp = readl (&ep->regs->ep_stat))
				& BIT(NAK_OUT_PACKETS)) != 0) {
	if (!ep->is_in && (readl(&ep->regs->ep_stat) &
				BIT(NAK_OUT_PACKETS))) {
		writel(BIT(SHORT_PACKET_TRANSFERRED_INTERRUPT),
			&ep->regs->ep_stat);

@@ -858,8 +854,8 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
	 * (zero length) unless the driver explicitly said to do that.
	 */
	if (ep->is_in) {
		if (likely ((req->req.length % ep->ep.maxpacket) != 0
				|| req->req.zero)) {
		if (likely((req->req.length % ep->ep.maxpacket) ||
							req->req.zero)){
			tmp |= BIT(DMA_FIFO_VALIDATE);
			ep->in_fifo_validate = 1;
		} else
@@ -955,8 +951,8 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
	 * always use pio (as fallback or whatever).
	 */
	req = container_of(_req, struct net2280_request, req);
	if (!_req || !_req->complete || !_req->buf
			|| !list_empty (&req->queue))
	if (!_req || !_req->complete || !_req->buf ||
				!list_empty(&req->queue))
		return -EINVAL;
	if (_req->length > (~0 & DMA_BYTE_COUNT_MASK))
		return -EDOM;
@@ -1035,12 +1031,16 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
					 * _req->status doesn't change for
					 * short reads (only _req->actual)
					 */
					if (read_fifo (ep, req)) {
					if (read_fifo(ep, req) &&
							ep->num == 0) {
						done(ep, req, 0);
						if (ep->num == 0)
						allow_status(ep);
						/* don't queue it */
						req = NULL;
					} else if (read_fifo(ep, req) &&
							ep->num != 0) {
						done(ep, req, 0);
						req = NULL;
					} else
						s = readl(&ep->regs->ep_stat);
				}
@@ -1061,8 +1061,8 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
			/* preventing magic zlps is per-engine state, not
			 * per-transfer; irq logic must recover hiccups.
			 */
			expect = likely (req->req.zero
				|| (req->req.length % ep->ep.maxpacket) != 0);
			expect = likely(req->req.zero ||
				(req->req.length % ep->ep.maxpacket));
			if (expect != ep->in_fifo_validate)
				valid = 0;
		}
@@ -1081,12 +1081,8 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
}

static inline void
dma_done (
	struct net2280_ep *ep,
	struct net2280_request *req,
	u32 dmacount,
	int status
)
dma_done(struct net2280_ep *ep,	struct net2280_request *req, u32 dmacount,
		int status)
{
	req->req.actual = req->req.length - (DMA_BYTE_COUNT_MASK & dmacount);
	done(ep, req, status);
@@ -1138,15 +1134,19 @@ static void scan_dma_completions (struct net2280_ep *ep)
				WARNING(ep->dev, "%s lost packet sync!\n",
						ep->ep.name);
				req->req.status = -EOVERFLOW;
			} else if ((tmp = readl (&ep->regs->ep_avail)) != 0) {
			} else {
				tmp = readl(&ep->regs->ep_avail);
				if (tmp) {
					/* fifo gets flushed later */
					ep->out_overflow = 1;
				DEBUG (ep->dev, "%s dma, discard %d len %d\n",
					DEBUG(ep->dev,
						"%s dma, discard %d len %d\n",
						ep->ep.name, tmp,
						req->req.length);
					req->req.status = -EOVERFLOW;
				}
			}
		}
		dma_done(ep, req, tmp, 0);
	}
}
@@ -1176,8 +1176,8 @@ static void restart_dma (struct net2280_ep *ep)
		int			reqmode, done = 0;

		DEBUG(ep->dev, "%s dma hiccup td %p\n", ep->ep.name, req->td);
		ep->in_fifo_validate = likely (req->req.zero
			|| (req->req.length % ep->ep.maxpacket) != 0);
		ep->in_fifo_validate = likely(req->req.zero ||
				(req->req.length % ep->ep.maxpacket) != 0);
		if (ep->in_fifo_validate)
			dmactl |= BIT(DMA_FIFO_VALIDATE);
		list_for_each_entry(entry, &ep->queue, queue) {
@@ -1187,9 +1187,8 @@ static void restart_dma (struct net2280_ep *ep)
				continue;
			dmacount = entry->td->dmacount;
			if (!done) {
				reqmode = likely (entry->req.zero
					|| (entry->req.length
						% ep->ep.maxpacket) != 0);
				reqmode = likely(entry->req.zero ||
				   (entry->req.length % ep->ep.maxpacket));
				if (reqmode == ep->in_fifo_validate) {
					entry->valid = 1;
					dmacount |= valid_bit;
@@ -1300,7 +1299,7 @@ static int net2280_dequeue (struct usb_ep *_ep, struct usb_request *_req)
			_req->status = -ECONNRESET;
			abort_dma(ep);
			if (likely(ep->queue.next == &req->queue)) {
				// NOTE: misreports single-transfer mode
				/* NOTE: misreports single-transfer mode*/
				req->td->dmacount = 0;	/* invalidate */
				dma_done(ep, req,
					readl(&ep->dma->dmacount),
@@ -1405,22 +1404,19 @@ net2280_set_halt_and_wedge(struct usb_ep *_ep, int value, int wedged)
	return retval;
}

static int
net2280_set_halt(struct usb_ep *_ep, int value)
static int net2280_set_halt(struct usb_ep *_ep, int value)
{
	return net2280_set_halt_and_wedge(_ep, value, 0);
}

static int
net2280_set_wedge(struct usb_ep *_ep)
static int net2280_set_wedge(struct usb_ep *_ep)
{
	if (!_ep || _ep->name == ep0name)
		return -EINVAL;
	return net2280_set_halt_and_wedge(_ep, 1, 1);
}

static int
net2280_fifo_status (struct usb_ep *_ep)
static int net2280_fifo_status(struct usb_ep *_ep)
{
	struct net2280_ep	*ep;
	u32			avail;
@@ -1439,8 +1435,7 @@ net2280_fifo_status (struct usb_ep *_ep)
	return avail;
}

static void
net2280_fifo_flush (struct usb_ep *_ep)
static void net2280_fifo_flush(struct usb_ep *_ep)
{
	struct net2280_ep	*ep;

@@ -1584,9 +1579,8 @@ static ssize_t function_show(struct device *_dev, struct device_attribute *attr,
{
	struct net2280	*dev = dev_get_drvdata(_dev);

	if (!dev->driver
			|| !dev->driver->function
			|| strlen (dev->driver->function) > PAGE_SIZE)
	if (!dev->driver || !dev->driver->function ||
			strlen(dev->driver->function) > PAGE_SIZE)
		return 0;
	return scnprintf(buf, PAGE_SIZE, "%s\n", dev->driver->function);
}
@@ -1719,8 +1713,7 @@ static ssize_t registers_show(struct device *_dev,

	}

	/* Indexed Registers */
		// none yet
	/* Indexed Registers (none yet) */

	/* Statistics */
	t = scnprintf(next, size, "\nirqs:  ");
@@ -2388,9 +2381,11 @@ static int net2280_start(struct usb_gadget *_gadget,
	dev->driver = driver;

	retval = device_create_file(&dev->pdev->dev, &dev_attr_function);
	if (retval) goto err_unbind;
	if (retval)
		goto err_unbind;
	retval = device_create_file(&dev->pdev->dev, &dev_attr_queues);
	if (retval) goto err_func;
	if (retval)
		goto err_func;

	/* Enable force-full-speed testing mode, if desired */
	if (full_speed && dev->pdev->vendor == PCI_VENDOR_ID_PLX_LEGACY)
@@ -2421,8 +2416,7 @@ static int net2280_start(struct usb_gadget *_gadget,
	return retval;
}

static void
stop_activity (struct net2280 *dev, struct usb_gadget_driver *driver)
static void stop_activity(struct net2280 *dev, struct usb_gadget_driver *driver)
{
	int			i;

@@ -2649,12 +2643,10 @@ static void handle_ep_small (struct net2280_ep *ep)
		req->req.actual += len;

		/* if we wrote it all, we're usually done */
		if (req->req.actual == req->req.length) {
			if (ep->num == 0) {
		/* send zlps until the status stage */
			} else if (!req->req.zero || len != ep->ep.maxpacket)
		if ((req->req.actual == req->req.length) &&
			(!req->req.zero || len != ep->ep.maxpacket) && ep->num)
				mode = 2;
		}

	/* there was nothing to do ...  */
	} else if (mode == 1)
@@ -2696,8 +2688,7 @@ static void handle_ep_small (struct net2280_ep *ep)
	}
}

static struct net2280_ep *
get_ep_by_addr (struct net2280 *dev, u16 wIndex)
static struct net2280_ep *get_ep_by_addr(struct net2280 *dev, u16 wIndex)
{
	struct net2280_ep	*ep;

@@ -3070,7 +3061,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
	stat &= ~BIT(INTA_ASSERTED);
	if (!stat)
		return;
	// DEBUG (dev, "irqstat0 %04x\n", stat);
	/* DEBUG(dev, "irqstat0 %04x\n", stat); */

	/* starting a control request? */
	if (unlikely(stat & BIT(SETUP_PACKET_INTERRUPT))) {
@@ -3097,7 +3088,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
						EP0_HS_MAX_PACKET_SIZE);
			}
			net2280_led_speed(dev, dev->gadget.speed);
			DEBUG(dev, "%s\n", usb_speed_string(dev->gadget.speed));
			DEBUG(dev, "%s\n",
					usb_speed_string(dev->gadget.speed));
		}

		ep = &dev->ep[0];
@@ -3190,8 +3182,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
			/* hw handles device and interface status */
			if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
				goto delegate;
			if ((e = get_ep_by_addr (dev, w_index)) == NULL
					|| w_length > 2)
			e = get_ep_by_addr(dev, w_index);
			if (!e || w_length > 2)
				goto do_stall;

			if (readl(&e->regs->ep_rsp) & BIT(SET_ENDPOINT_HALT))
@@ -3217,7 +3209,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
			if (w_value != USB_ENDPOINT_HALT
					|| w_length != 0)
				goto do_stall;
			if ((e = get_ep_by_addr (dev, w_index)) == NULL)
			e = get_ep_by_addr(dev, w_index);
			if (!e)
				goto do_stall;
			if (e->wedged) {
				VDEBUG(dev, "%s wedged, halt not cleared\n",
@@ -3243,7 +3236,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
			if (w_value != USB_ENDPOINT_HALT
					|| w_length != 0)
				goto do_stall;
			if ((e = get_ep_by_addr (dev, w_index)) == NULL)
			e = get_ep_by_addr(dev, w_index);
			if (!e)
				goto do_stall;
			if (e->ep.name == ep0name)
				goto do_stall;
@@ -3390,7 +3384,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)

	if (!stat)
		return;
	// DEBUG (dev, "irqstat1 %08x\n", stat);
	/* DEBUG(dev, "irqstat1 %08x\n", stat);*/

	/* DMA status, for ep-{a,b,c,d} */
	scratch = stat & DMA_INTERRUPTS;
@@ -3584,7 +3578,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
		use_dma_chaining = 0;

	/* alloc, and start init */
	dev = kzalloc (sizeof *dev, GFP_KERNEL);
	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (dev == NULL) {
		retval = -ENOMEM;
		goto done;
@@ -3655,7 +3649,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
		dev->plregs = (struct usb338x_pl_regs __iomem *)
							(base + 0x0800);
		usbstat = readl(&dev->usb->usbstat);
		dev->enhanced_mode = (usbstat & BIT(11)) ? 1 : 0;
		dev->enhanced_mode = !!(usbstat & BIT(11));
		dev->n_ep = (dev->enhanced_mode) ? 9 : 5;
		/* put into initial config, link up all endpoints */
		fsmvalue = get_idx_reg(dev->regs, SCRATCH) &
@@ -3684,8 +3678,8 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
		if (pci_enable_msi(pdev))
			ERROR(dev, "Failed to enable MSI mode\n");

	if (request_irq (pdev->irq, net2280_irq, IRQF_SHARED, driver_name, dev)
			!= 0) {
	if (request_irq(pdev->irq, net2280_irq, IRQF_SHARED,
							driver_name, dev)) {
		ERROR(dev, "request interrupt %d failed\n", pdev->irq);
		retval = -EBUSY;
		goto done;
@@ -3744,7 +3738,8 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
			: "disabled",
		dev->enhanced_mode ? "enhanced mode" : "legacy mode");
	retval = device_create_file(&pdev->dev, &dev_attr_registers);
	if (retval) goto done;
	if (retval)
		goto done;

	retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
			gadget_release);
+45 −45
Original line number Diff line number Diff line
@@ -25,8 +25,7 @@
 * caller must own the device lock.
 */

static inline u32
get_idx_reg (struct net2280_regs __iomem *regs, u32 index)
static inline u32 get_idx_reg(struct net2280_regs __iomem *regs, u32 index)
{
	writel(index, &regs->idxaddr);
	/* NOTE:  synchs device/cpu memory views */
@@ -81,7 +80,7 @@ struct net2280_dma {
	__le32		dmaaddr;		/* the buffer */
	__le32		dmadesc;		/* next dma descriptor */
	__le32		_reserved;
} __attribute__ ((aligned (16)));
} __aligned(16);

/*-------------------------------------------------------------------------*/

@@ -185,7 +184,7 @@ struct net2280 {
	struct usb338x_pl_regs		__iomem *plregs;

	struct pci_pool			*requests;
	// statistics...
	/* statistics...*/
};

static inline void set_halt(struct net2280_ep *ep)
@@ -290,13 +289,14 @@ static inline void net2280_led_active (struct net2280 *dev, int is_active)
{
	u32	val = readl(&dev->regs->gpioctl);

	// FIXME this LED never seems to turn on.
	/* FIXME this LED never seems to turn on.*/
	if (is_active)
		val |= GPIO2_DATA;
	else
		val &= ~GPIO2_DATA;
	writel(val, &dev->regs->gpioctl);
}

static inline void net2280_led_shutdown(struct net2280 *dev)
{
	/* turn off all four GPIO*_DATA bits */