Lines Matching refs:ep
50 struct snd_usb_midi2_endpoint *ep; member
105 static void do_submit_urbs_locked(struct snd_usb_midi2_endpoint *ep, in do_submit_urbs_locked() argument
112 if (ep->disconnected) in do_submit_urbs_locked()
115 while (ep->urb_free) { in do_submit_urbs_locked()
116 index = find_first_bit(&ep->urb_free, ep->num_urbs); in do_submit_urbs_locked()
117 if (index >= ep->num_urbs) in do_submit_urbs_locked()
119 ctx = &ep->urbs[index]; in do_submit_urbs_locked()
120 err = prepare(ep, ctx->urb); in do_submit_urbs_locked()
125 ctx->urb->dev = ep->dev; in do_submit_urbs_locked()
128 dev_dbg(&ep->dev->dev, in do_submit_urbs_locked()
132 clear_bit(index, &ep->urb_free); in do_submit_urbs_locked()
137 static int prepare_output_urb(struct snd_usb_midi2_endpoint *ep, in prepare_output_urb() argument
142 count = snd_ump_transmit(ep->ump, urb->transfer_buffer, in prepare_output_urb()
143 ep->packets); in prepare_output_urb()
145 dev_dbg(&ep->dev->dev, "rawmidi transmit error %d\n", count); in prepare_output_urb()
153 static void submit_output_urbs_locked(struct snd_usb_midi2_endpoint *ep) in submit_output_urbs_locked() argument
155 do_submit_urbs_locked(ep, prepare_output_urb); in submit_output_urbs_locked()
162 struct snd_usb_midi2_endpoint *ep = ctx->ep; in output_urb_complete() local
165 spin_lock_irqsave(&ep->lock, flags); in output_urb_complete()
166 set_bit(ctx->index, &ep->urb_free); in output_urb_complete()
167 if (urb->status >= 0 && atomic_read(&ep->running)) in output_urb_complete()
168 submit_output_urbs_locked(ep); in output_urb_complete()
169 if (ep->urb_free == ep->urb_free_mask) in output_urb_complete()
170 wake_up(&ep->wait); in output_urb_complete()
171 spin_unlock_irqrestore(&ep->lock, flags); in output_urb_complete()
175 static int prepare_input_urb(struct snd_usb_midi2_endpoint *ep, in prepare_input_urb() argument
178 urb->transfer_buffer_length = ep->packets; in prepare_input_urb()
182 static void submit_input_urbs_locked(struct snd_usb_midi2_endpoint *ep) in submit_input_urbs_locked() argument
184 do_submit_urbs_locked(ep, prepare_input_urb); in submit_input_urbs_locked()
191 struct snd_usb_midi2_endpoint *ep = ctx->ep; in input_urb_complete() local
195 spin_lock_irqsave(&ep->lock, flags); in input_urb_complete()
196 if (ep->disconnected || urb->status < 0) in input_urb_complete()
200 if (len > ep->packets) in input_urb_complete()
201 len = ep->packets; in input_urb_complete()
204 snd_ump_receive(ep->ump, (u32 *)urb->transfer_buffer, len); in input_urb_complete()
207 set_bit(ctx->index, &ep->urb_free); in input_urb_complete()
208 submit_input_urbs_locked(ep); in input_urb_complete()
209 if (ep->urb_free == ep->urb_free_mask) in input_urb_complete()
210 wake_up(&ep->wait); in input_urb_complete()
211 spin_unlock_irqrestore(&ep->lock, flags); in input_urb_complete()
215 static void submit_io_urbs(struct snd_usb_midi2_endpoint *ep) in submit_io_urbs() argument
219 if (!ep) in submit_io_urbs()
221 spin_lock_irqsave(&ep->lock, flags); in submit_io_urbs()
222 if (ep->direction == STR_IN) in submit_io_urbs()
223 submit_input_urbs_locked(ep); in submit_io_urbs()
225 submit_output_urbs_locked(ep); in submit_io_urbs()
226 spin_unlock_irqrestore(&ep->lock, flags); in submit_io_urbs()
230 static void kill_midi_urbs(struct snd_usb_midi2_endpoint *ep, bool suspending) in kill_midi_urbs() argument
234 if (!ep) in kill_midi_urbs()
237 ep->suspended = ep->running; in kill_midi_urbs()
238 atomic_set(&ep->running, 0); in kill_midi_urbs()
239 for (i = 0; i < ep->num_urbs; i++) { in kill_midi_urbs()
240 if (!ep->urbs[i].urb) in kill_midi_urbs()
242 usb_kill_urb(ep->urbs[i].urb); in kill_midi_urbs()
247 static void drain_urb_queue(struct snd_usb_midi2_endpoint *ep) in drain_urb_queue() argument
249 if (!ep) in drain_urb_queue()
251 spin_lock_irq(&ep->lock); in drain_urb_queue()
252 atomic_set(&ep->running, 0); in drain_urb_queue()
253 wait_event_lock_irq_timeout(ep->wait, in drain_urb_queue()
254 ep->disconnected || in drain_urb_queue()
255 ep->urb_free == ep->urb_free_mask, in drain_urb_queue()
256 ep->lock, msecs_to_jiffies(500)); in drain_urb_queue()
257 spin_unlock_irq(&ep->lock); in drain_urb_queue()
261 static void free_midi_urbs(struct snd_usb_midi2_endpoint *ep) in free_midi_urbs() argument
266 if (!ep) in free_midi_urbs()
269 ctx = &ep->urbs[i]; in free_midi_urbs()
272 usb_free_coherent(ep->dev, ep->packets, in free_midi_urbs()
278 ep->num_urbs = 0; in free_midi_urbs()
283 static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep) in alloc_midi_urbs() argument
291 endpoint = ep->endpoint; in alloc_midi_urbs()
292 len = ep->packets; in alloc_midi_urbs()
293 if (ep->direction == STR_IN) in alloc_midi_urbs()
298 ep->num_urbs = 0; in alloc_midi_urbs()
299 ep->urb_free = ep->urb_free_mask = 0; in alloc_midi_urbs()
301 ctx = &ep->urbs[i]; in alloc_midi_urbs()
305 dev_err(&ep->dev->dev, "URB alloc failed\n"); in alloc_midi_urbs()
308 ctx->ep = ep; in alloc_midi_urbs()
309 buffer = usb_alloc_coherent(ep->dev, len, GFP_KERNEL, in alloc_midi_urbs()
312 dev_err(&ep->dev->dev, in alloc_midi_urbs()
316 if (ep->interval) in alloc_midi_urbs()
317 usb_fill_int_urb(ctx->urb, ep->dev, ep->pipe, in alloc_midi_urbs()
318 buffer, len, comp, ctx, ep->interval); in alloc_midi_urbs()
320 usb_fill_bulk_urb(ctx->urb, ep->dev, ep->pipe, in alloc_midi_urbs()
324 dev_err(&ep->dev->dev, "invalid MIDI EP %x\n", in alloc_midi_urbs()
329 ep->num_urbs++; in alloc_midi_urbs()
331 ep->urb_free = ep->urb_free_mask = GENMASK(ep->num_urbs - 1, 0); in alloc_midi_urbs()
346 struct snd_usb_midi2_endpoint *ep = ump_to_endpoint(ump, dir); in snd_usb_midi_v2_open() local
349 if (!ep || !ep->endpoint) in snd_usb_midi_v2_open()
351 if (ep->disconnected) in snd_usb_midi_v2_open()
353 if (ep->direction == STR_OUT) { in snd_usb_midi_v2_open()
354 err = alloc_midi_urbs(ep); in snd_usb_midi_v2_open()
356 free_midi_urbs(ep); in snd_usb_midi_v2_open()
366 struct snd_usb_midi2_endpoint *ep = ump_to_endpoint(ump, dir); in snd_usb_midi_v2_close() local
368 if (ep->direction == STR_OUT) { in snd_usb_midi_v2_close()
369 kill_midi_urbs(ep, false); in snd_usb_midi_v2_close()
370 drain_urb_queue(ep); in snd_usb_midi_v2_close()
371 free_midi_urbs(ep); in snd_usb_midi_v2_close()
379 struct snd_usb_midi2_endpoint *ep = ump_to_endpoint(ump, dir); in snd_usb_midi_v2_trigger() local
381 atomic_set(&ep->running, up); in snd_usb_midi_v2_trigger()
382 if (up && ep->direction == STR_OUT && !ep->disconnected) in snd_usb_midi_v2_trigger()
383 submit_io_urbs(ep); in snd_usb_midi_v2_trigger()
389 struct snd_usb_midi2_endpoint *ep = ump_to_endpoint(ump, dir); in snd_usb_midi_v2_drain() local
391 drain_urb_queue(ep); in snd_usb_midi_v2_drain()
397 struct snd_usb_midi2_endpoint *ep; in start_input_streams() local
400 list_for_each_entry(ep, &umidi->ep_list, list) { in start_input_streams()
401 if (ep->direction == STR_IN) { in start_input_streams()
402 err = alloc_midi_urbs(ep); in start_input_streams()
408 list_for_each_entry(ep, &umidi->ep_list, list) { in start_input_streams()
409 if (ep->direction == STR_IN) in start_input_streams()
410 submit_io_urbs(ep); in start_input_streams()
416 list_for_each_entry(ep, &umidi->ep_list, list) { in start_input_streams()
417 if (ep->direction == STR_IN) in start_input_streams()
418 free_midi_urbs(ep); in start_input_streams()
436 struct snd_usb_midi2_endpoint *ep; in create_midi2_endpoint() local
443 ep = kzalloc(sizeof(*ep), GFP_KERNEL); in create_midi2_endpoint()
444 if (!ep) in create_midi2_endpoint()
447 spin_lock_init(&ep->lock); in create_midi2_endpoint()
448 init_waitqueue_head(&ep->wait); in create_midi2_endpoint()
449 ep->dev = umidi->chip->dev; in create_midi2_endpoint()
453 ep->endpoint = endpoint; in create_midi2_endpoint()
454 ep->direction = dir; in create_midi2_endpoint()
455 ep->ms_ep = ms_ep; in create_midi2_endpoint()
457 ep->interval = hostep->desc.bInterval; in create_midi2_endpoint()
459 ep->interval = 0; in create_midi2_endpoint()
461 if (ep->interval) in create_midi2_endpoint()
462 ep->pipe = usb_rcvintpipe(ep->dev, endpoint); in create_midi2_endpoint()
464 ep->pipe = usb_rcvbulkpipe(ep->dev, endpoint); in create_midi2_endpoint()
466 if (ep->interval) in create_midi2_endpoint()
467 ep->pipe = usb_sndintpipe(ep->dev, endpoint); in create_midi2_endpoint()
469 ep->pipe = usb_sndbulkpipe(ep->dev, endpoint); in create_midi2_endpoint()
471 ep->packets = usb_maxpacket(ep->dev, ep->pipe); in create_midi2_endpoint()
472 list_add_tail(&ep->list, &umidi->ep_list); in create_midi2_endpoint()
478 static void free_midi2_endpoint(struct snd_usb_midi2_endpoint *ep) in free_midi2_endpoint() argument
480 list_del(&ep->list); in free_midi2_endpoint()
481 free_midi_urbs(ep); in free_midi2_endpoint()
482 kfree(ep); in free_midi2_endpoint()
488 struct snd_usb_midi2_endpoint *ep; in free_all_midi2_endpoints() local
491 ep = list_first_entry(&umidi->ep_list, in free_all_midi2_endpoints()
493 free_midi2_endpoint(ep); in free_all_midi2_endpoints()
772 struct snd_usb_midi2_endpoint *ep, in find_matching_ep_partner() argument
779 ep->endpoint); in find_matching_ep_partner()
790 return create_midi2_ump(umidi, ep, pair_ep, blk_id); in find_matching_ep_partner()
943 struct snd_usb_midi2_endpoint *ep; in parse_midi_2_0() local
960 list_for_each_entry(ep, &umidi->ep_list, list) { in parse_midi_2_0()
962 if (ep->direction != STR_IN) in parse_midi_2_0()
964 for (blk = 0; blk < ep->ms_ep->bNumGrpTrmBlock; blk++) { in parse_midi_2_0()
965 id = ep->ms_ep->baAssoGrpTrmBlkID[blk]; in parse_midi_2_0()
966 err = find_matching_ep_partner(umidi, ep, id); in parse_midi_2_0()
976 list_for_each_entry(ep, &umidi->ep_list, list) { in parse_midi_2_0()
977 if (ep->rmidi) in parse_midi_2_0()
979 for (blk = 0; blk < ep->ms_ep->bNumGrpTrmBlock; blk++) { in parse_midi_2_0()
980 id = ep->ms_ep->baAssoGrpTrmBlkID[blk]; in parse_midi_2_0()
985 ep->endpoint, id); in parse_midi_2_0()
986 if (ep->direction == STR_IN) in parse_midi_2_0()
987 err = create_midi2_ump(umidi, ep, NULL, id); in parse_midi_2_0()
989 err = create_midi2_ump(umidi, NULL, ep, id); in parse_midi_2_0()
1175 static void suspend_midi2_endpoint(struct snd_usb_midi2_endpoint *ep) in suspend_midi2_endpoint() argument
1177 kill_midi_urbs(ep, true); in suspend_midi2_endpoint()
1178 drain_urb_queue(ep); in suspend_midi2_endpoint()
1184 struct snd_usb_midi2_endpoint *ep; in snd_usb_midi_v2_suspend_all() local
1187 list_for_each_entry(ep, &umidi->ep_list, list) in snd_usb_midi_v2_suspend_all()
1188 suspend_midi2_endpoint(ep); in snd_usb_midi_v2_suspend_all()
1192 static void resume_midi2_endpoint(struct snd_usb_midi2_endpoint *ep) in resume_midi2_endpoint() argument
1194 ep->running = ep->suspended; in resume_midi2_endpoint()
1195 if (ep->direction == STR_IN) in resume_midi2_endpoint()
1196 submit_io_urbs(ep); in resume_midi2_endpoint()
1203 struct snd_usb_midi2_endpoint *ep; in snd_usb_midi_v2_resume_all() local
1207 list_for_each_entry(ep, &umidi->ep_list, list) in snd_usb_midi_v2_resume_all()
1208 resume_midi2_endpoint(ep); in snd_usb_midi_v2_resume_all()
1215 struct snd_usb_midi2_endpoint *ep; in snd_usb_midi_v2_disconnect_all() local
1219 list_for_each_entry(ep, &umidi->ep_list, list) { in snd_usb_midi_v2_disconnect_all()
1220 ep->disconnected = 1; in snd_usb_midi_v2_disconnect_all()
1221 kill_midi_urbs(ep, false); in snd_usb_midi_v2_disconnect_all()
1222 drain_urb_queue(ep); in snd_usb_midi_v2_disconnect_all()