Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* usb-urb.c is part of the DVB USB library.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@posteo.de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * see dvb-usb-init.c for copyright information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This file keeps functions for initializing and handling the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * BULK and ISOC USB data transfers in a generic way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Can be used for DVB-only and also, that's the plan, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Hybrid USB devices (analog and DVB).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "dvb-usb-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /* URB stuff for streaming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static void usb_urb_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct usb_data_stream *stream = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	int ptype = usb_pipetype(urb->pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	u8 *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	deb_uxfer("'%s' urb completed. status: %d, length: %d/%d, pack_num: %d, errors: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 		ptype == PIPE_ISOCHRONOUS ? "isoc" : "bulk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		urb->status,urb->actual_length,urb->transfer_buffer_length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		urb->number_of_packets,urb->error_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	switch (urb->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		case 0:         /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		case -ETIMEDOUT:    /* NAK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		case -ECONNRESET:   /* kill */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		default:        /* error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			deb_ts("urb completion error %d.\n", urb->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	b = (u8 *) urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	switch (ptype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		case PIPE_ISOCHRONOUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			for (i = 0; i < urb->number_of_packets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 				if (urb->iso_frame_desc[i].status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 					deb_ts("iso frame descriptor has an error: %d\n",urb->iso_frame_desc[i].status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				else if (urb->iso_frame_desc[i].actual_length > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 					stream->complete(stream, b + urb->iso_frame_desc[i].offset, urb->iso_frame_desc[i].actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				urb->iso_frame_desc[i].status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				urb->iso_frame_desc[i].actual_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			debug_dump(b,20,deb_uxfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		case PIPE_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			if (urb->actual_length > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 				stream->complete(stream, b, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			err("unknown endpoint type in completion handler.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	usb_submit_urb(urb,GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) int usb_urb_kill(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	for (i = 0; i < stream->urbs_submitted; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		deb_ts("killing URB no. %d.\n",i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		/* stop the URB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		usb_kill_urb(stream->urb_list[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	stream->urbs_submitted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) int usb_urb_submit(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int i,ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	for (i = 0; i < stream->urbs_initialized; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		deb_ts("submitting URB no. %d\n",i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if ((ret = usb_submit_urb(stream->urb_list[i],GFP_ATOMIC))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			err("could not submit URB no. %d - get them all back",i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			usb_urb_kill(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		stream->urbs_submitted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static int usb_free_stream_buffers(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (stream->state & USB_STATE_URB_BUF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		while (stream->buf_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			stream->buf_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			deb_mem("freeing buffer %d\n",stream->buf_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			usb_free_coherent(stream->udev, stream->buf_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 					  stream->buf_list[stream->buf_num],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 					  stream->dma_addr[stream->buf_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	stream->state &= ~USB_STATE_URB_BUF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int usb_allocate_stream_buffers(struct usb_data_stream *stream, int num, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	stream->buf_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	stream->buf_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	deb_mem("all in all I will use %lu bytes for streaming\n",num*size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		deb_mem("allocating buffer %d\n",stream->buf_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (( stream->buf_list[stream->buf_num] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					usb_alloc_coherent(stream->udev, size, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					&stream->dma_addr[stream->buf_num]) ) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			deb_mem("not enough memory for urb-buffer allocation.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			usb_free_stream_buffers(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		deb_mem("buffer %d: %p (dma: %Lu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			stream->buf_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) stream->buf_list[stream->buf_num], (long long)stream->dma_addr[stream->buf_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		memset(stream->buf_list[stream->buf_num],0,size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		stream->state |= USB_STATE_URB_BUF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	deb_mem("allocation successful\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int usb_bulk_urb_init(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if ((i = usb_allocate_stream_buffers(stream,stream->props.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 					stream->props.u.bulk.buffersize)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* allocate the URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	for (i = 0; i < stream->props.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		stream->urb_list[i] = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (!stream->urb_list[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			deb_mem("not enough memory for urb_alloc_urb!.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				usb_free_urb(stream->urb_list[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		usb_fill_bulk_urb( stream->urb_list[i], stream->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				usb_rcvbulkpipe(stream->udev,stream->props.endpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				stream->buf_list[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				stream->props.u.bulk.buffersize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				usb_urb_complete, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		stream->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		stream->urb_list[i]->transfer_dma = stream->dma_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		stream->urbs_initialized++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static int usb_isoc_urb_init(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int i,j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if ((i = usb_allocate_stream_buffers(stream,stream->props.count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 					stream->props.u.isoc.framesize*stream->props.u.isoc.framesperurb)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* allocate the URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	for (i = 0; i < stream->props.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		int frame_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		stream->urb_list[i] = usb_alloc_urb(stream->props.u.isoc.framesperurb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (!stream->urb_list[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			deb_mem("not enough memory for urb_alloc_urb!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				usb_free_urb(stream->urb_list[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		urb = stream->urb_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		urb->dev = stream->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		urb->context = stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		urb->complete = usb_urb_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		urb->pipe = usb_rcvisocpipe(stream->udev,stream->props.endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		urb->interval = stream->props.u.isoc.interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		urb->number_of_packets = stream->props.u.isoc.framesperurb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		urb->transfer_buffer_length = stream->buf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		urb->transfer_buffer = stream->buf_list[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		urb->transfer_dma = stream->dma_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		for (j = 0; j < stream->props.u.isoc.framesperurb; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			urb->iso_frame_desc[j].offset = frame_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			urb->iso_frame_desc[j].length = stream->props.u.isoc.framesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			frame_offset += stream->props.u.isoc.framesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		stream->urbs_initialized++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int usb_urb_init(struct usb_data_stream *stream, struct usb_data_stream_properties *props)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (stream == NULL || props == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	memcpy(&stream->props, props, sizeof(*props));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	usb_clear_halt(stream->udev,usb_rcvbulkpipe(stream->udev,stream->props.endpoint));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (stream->complete == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		err("there is no data callback - this doesn't make sense.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	switch (stream->props.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		case USB_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			return usb_bulk_urb_init(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		case USB_ISOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			return usb_isoc_urb_init(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			err("unknown URB-type for data transfer.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int usb_urb_exit(struct usb_data_stream *stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	usb_urb_kill(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	for (i = 0; i < stream->urbs_initialized; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (stream->urb_list[i] != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			deb_mem("freeing URB no. %d.\n",i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			/* free the URBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			usb_free_urb(stream->urb_list[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	stream->urbs_initialized = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	usb_free_stream_buffers(stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }