forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/usb/host/xhci-dbgcap.c
....@@ -1,5 +1,5 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/**
2
+/*
33 * xhci-dbgcap.c - xHCI debug capability support
44 *
55 * Copyright (C) 2017 Intel Corporation
....@@ -14,25 +14,27 @@
1414 #include "xhci-trace.h"
1515 #include "xhci-dbgcap.h"
1616
17
-static inline void *
18
-dbc_dma_alloc_coherent(struct xhci_hcd *xhci, size_t size,
19
- dma_addr_t *dma_handle, gfp_t flags)
17
+static void dbc_free_ctx(struct device *dev, struct xhci_container_ctx *ctx)
2018 {
21
- void *vaddr;
22
-
23
- vaddr = dma_alloc_coherent(xhci_to_hcd(xhci)->self.sysdev,
24
- size, dma_handle, flags);
25
- memset(vaddr, 0, size);
26
- return vaddr;
19
+ if (!ctx)
20
+ return;
21
+ dma_free_coherent(dev, ctx->size, ctx->bytes, ctx->dma);
22
+ kfree(ctx);
2723 }
2824
29
-static inline void
30
-dbc_dma_free_coherent(struct xhci_hcd *xhci, size_t size,
31
- void *cpu_addr, dma_addr_t dma_handle)
25
+/* we use only one segment for DbC rings */
26
+static void dbc_ring_free(struct device *dev, struct xhci_ring *ring)
3227 {
33
- if (cpu_addr)
34
- dma_free_coherent(xhci_to_hcd(xhci)->self.sysdev,
35
- size, cpu_addr, dma_handle);
28
+ if (!ring)
29
+ return;
30
+
31
+ if (ring->first_seg && ring->first_seg->trbs) {
32
+ dma_free_coherent(dev, TRB_SEGMENT_SIZE,
33
+ ring->first_seg->trbs,
34
+ ring->first_seg->dma);
35
+ kfree(ring->first_seg);
36
+ }
37
+ kfree(ring);
3638 }
3739
3840 static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
....@@ -84,16 +86,14 @@
8486 return string_length;
8587 }
8688
87
-static void xhci_dbc_init_contexts(struct xhci_hcd *xhci, u32 string_length)
89
+static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
8890 {
89
- struct xhci_dbc *dbc;
9091 struct dbc_info_context *info;
9192 struct xhci_ep_ctx *ep_ctx;
9293 u32 dev_info;
9394 dma_addr_t deq, dma;
9495 unsigned int max_burst;
9596
96
- dbc = xhci->dbc;
9797 if (!dbc)
9898 return;
9999
....@@ -122,7 +122,7 @@
122122 ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
123123
124124 /* Set DbC context and info registers: */
125
- xhci_write_64(xhci, dbc->ctx->dma, &dbc->regs->dccp);
125
+ lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp);
126126
127127 dev_info = cpu_to_le32((DBC_VENDOR_ID << 16) | DBC_PROTOCOL);
128128 writel(dev_info, &dbc->regs->devinfo1);
....@@ -135,10 +135,8 @@
135135 __releases(&dbc->lock)
136136 __acquires(&dbc->lock)
137137 {
138
- struct dbc_ep *dep = req->dep;
139
- struct xhci_dbc *dbc = dep->dbc;
140
- struct xhci_hcd *xhci = dbc->xhci;
141
- struct device *dev = xhci_to_hcd(dbc->xhci)->self.sysdev;
138
+ struct xhci_dbc *dbc = req->dbc;
139
+ struct device *dev = dbc->dev;
142140
143141 list_del_init(&req->list_pending);
144142 req->trb_dma = 0;
....@@ -152,11 +150,11 @@
152150 dma_unmap_single(dev,
153151 req->dma,
154152 req->length,
155
- dbc_ep_dma_direction(dep));
153
+ dbc_ep_dma_direction(req));
156154
157155 /* Give back the transfer request: */
158156 spin_unlock(&dbc->lock);
159
- req->complete(xhci, req);
157
+ req->complete(dbc, req);
160158 spin_lock(&dbc->lock);
161159 }
162160
....@@ -181,25 +179,32 @@
181179 xhci_dbc_flush_single_request(req);
182180 }
183181
184
-static void xhci_dbc_flush_reqests(struct xhci_dbc *dbc)
182
+static void xhci_dbc_flush_requests(struct xhci_dbc *dbc)
185183 {
186184 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_OUT]);
187185 xhci_dbc_flush_endpoint_requests(&dbc->eps[BULK_IN]);
188186 }
189187
190188 struct dbc_request *
191
-dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags)
189
+dbc_alloc_request(struct xhci_dbc *dbc, unsigned int direction, gfp_t flags)
192190 {
193191 struct dbc_request *req;
194192
195
- req = kzalloc(sizeof(*req), gfp_flags);
193
+ if (direction != BULK_IN &&
194
+ direction != BULK_OUT)
195
+ return NULL;
196
+
197
+ if (!dbc)
198
+ return NULL;
199
+
200
+ req = kzalloc(sizeof(*req), flags);
196201 if (!req)
197202 return NULL;
198203
199
- req->dep = dep;
204
+ req->dbc = dbc;
200205 INIT_LIST_HEAD(&req->list_pending);
201206 INIT_LIST_HEAD(&req->list_pool);
202
- req->direction = dep->direction;
207
+ req->direction = direction;
203208
204209 trace_xhci_dbc_alloc_request(req);
205210
....@@ -207,7 +212,7 @@
207212 }
208213
209214 void
210
-dbc_free_request(struct dbc_ep *dep, struct dbc_request *req)
215
+dbc_free_request(struct dbc_request *req)
211216 {
212217 trace_xhci_dbc_free_request(req);
213218
....@@ -243,7 +248,7 @@
243248 u64 addr;
244249 union xhci_trb *trb;
245250 unsigned int num_trbs;
246
- struct xhci_dbc *dbc = dep->dbc;
251
+ struct xhci_dbc *dbc = req->dbc;
247252 struct xhci_ring *ring = dep->ring;
248253 u32 length, control, cycle;
249254
....@@ -287,14 +292,12 @@
287292 }
288293
289294 static int
290
-dbc_ep_do_queue(struct dbc_ep *dep, struct dbc_request *req)
295
+dbc_ep_do_queue(struct dbc_request *req)
291296 {
292297 int ret;
293
- struct device *dev;
294
- struct xhci_dbc *dbc = dep->dbc;
295
- struct xhci_hcd *xhci = dbc->xhci;
296
-
297
- dev = xhci_to_hcd(xhci)->self.sysdev;
298
+ struct xhci_dbc *dbc = req->dbc;
299
+ struct device *dev = dbc->dev;
300
+ struct dbc_ep *dep = &dbc->eps[req->direction];
298301
299302 if (!req->length || !req->buf)
300303 return -EINVAL;
....@@ -307,13 +310,13 @@
307310 req->length,
308311 dbc_ep_dma_direction(dep));
309312 if (dma_mapping_error(dev, req->dma)) {
310
- xhci_err(xhci, "failed to map buffer\n");
313
+ dev_err(dbc->dev, "failed to map buffer\n");
311314 return -EFAULT;
312315 }
313316
314317 ret = xhci_dbc_queue_bulk_tx(dep, req);
315318 if (ret) {
316
- xhci_err(xhci, "failed to queue trbs\n");
319
+ dev_err(dbc->dev, "failed to queue trbs\n");
317320 dma_unmap_single(dev,
318321 req->dma,
319322 req->length,
....@@ -326,16 +329,22 @@
326329 return 0;
327330 }
328331
329
-int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req,
330
- gfp_t gfp_flags)
332
+int dbc_ep_queue(struct dbc_request *req)
331333 {
332334 unsigned long flags;
333
- struct xhci_dbc *dbc = dep->dbc;
335
+ struct xhci_dbc *dbc = req->dbc;
334336 int ret = -ESHUTDOWN;
337
+
338
+ if (!dbc)
339
+ return -ENODEV;
340
+
341
+ if (req->direction != BULK_IN &&
342
+ req->direction != BULK_OUT)
343
+ return -EINVAL;
335344
336345 spin_lock_irqsave(&dbc->lock, flags);
337346 if (dbc->state == DS_CONFIGURED)
338
- ret = dbc_ep_do_queue(dep, req);
347
+ ret = dbc_ep_do_queue(req);
339348 spin_unlock_irqrestore(&dbc->lock, flags);
340349
341350 mod_delayed_work(system_wq, &dbc->event_work, 0);
....@@ -345,10 +354,9 @@
345354 return ret;
346355 }
347356
348
-static inline void xhci_dbc_do_eps_init(struct xhci_hcd *xhci, bool direction)
357
+static inline void xhci_dbc_do_eps_init(struct xhci_dbc *dbc, bool direction)
349358 {
350359 struct dbc_ep *dep;
351
- struct xhci_dbc *dbc = xhci->dbc;
352360
353361 dep = &dbc->eps[direction];
354362 dep->dbc = dbc;
....@@ -358,127 +366,205 @@
358366 INIT_LIST_HEAD(&dep->list_pending);
359367 }
360368
361
-static void xhci_dbc_eps_init(struct xhci_hcd *xhci)
369
+static void xhci_dbc_eps_init(struct xhci_dbc *dbc)
362370 {
363
- xhci_dbc_do_eps_init(xhci, BULK_OUT);
364
- xhci_dbc_do_eps_init(xhci, BULK_IN);
371
+ xhci_dbc_do_eps_init(dbc, BULK_OUT);
372
+ xhci_dbc_do_eps_init(dbc, BULK_IN);
365373 }
366374
367
-static void xhci_dbc_eps_exit(struct xhci_hcd *xhci)
375
+static void xhci_dbc_eps_exit(struct xhci_dbc *dbc)
368376 {
369
- struct xhci_dbc *dbc = xhci->dbc;
370
-
371377 memset(dbc->eps, 0, sizeof(struct dbc_ep) * ARRAY_SIZE(dbc->eps));
372378 }
373379
374
-static int xhci_dbc_mem_init(struct xhci_hcd *xhci, gfp_t flags)
380
+static int dbc_erst_alloc(struct device *dev, struct xhci_ring *evt_ring,
381
+ struct xhci_erst *erst, gfp_t flags)
382
+{
383
+ erst->entries = dma_alloc_coherent(dev, sizeof(struct xhci_erst_entry),
384
+ &erst->erst_dma_addr, flags);
385
+ if (!erst->entries)
386
+ return -ENOMEM;
387
+
388
+ erst->num_entries = 1;
389
+ erst->entries[0].seg_addr = cpu_to_le64(evt_ring->first_seg->dma);
390
+ erst->entries[0].seg_size = cpu_to_le32(TRBS_PER_SEGMENT);
391
+ erst->entries[0].rsvd = 0;
392
+ return 0;
393
+}
394
+
395
+static void dbc_erst_free(struct device *dev, struct xhci_erst *erst)
396
+{
397
+ if (erst->entries)
398
+ dma_free_coherent(dev, sizeof(struct xhci_erst_entry),
399
+ erst->entries, erst->erst_dma_addr);
400
+ erst->entries = NULL;
401
+}
402
+
403
+static struct xhci_container_ctx *
404
+dbc_alloc_ctx(struct device *dev, gfp_t flags)
405
+{
406
+ struct xhci_container_ctx *ctx;
407
+
408
+ ctx = kzalloc(sizeof(*ctx), flags);
409
+ if (!ctx)
410
+ return NULL;
411
+
412
+ /* xhci 7.6.9, all three contexts; info, ep-out and ep-in. Each 64 bytes*/
413
+ ctx->size = 3 * DBC_CONTEXT_SIZE;
414
+ ctx->bytes = dma_alloc_coherent(dev, ctx->size, &ctx->dma, flags);
415
+ if (!ctx->bytes) {
416
+ kfree(ctx);
417
+ return NULL;
418
+ }
419
+ return ctx;
420
+}
421
+
422
+static struct xhci_ring *
423
+xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
424
+{
425
+ struct xhci_ring *ring;
426
+ struct xhci_segment *seg;
427
+ dma_addr_t dma;
428
+
429
+ ring = kzalloc(sizeof(*ring), flags);
430
+ if (!ring)
431
+ return NULL;
432
+
433
+ ring->num_segs = 1;
434
+ ring->type = type;
435
+
436
+ seg = kzalloc(sizeof(*seg), flags);
437
+ if (!seg)
438
+ goto seg_fail;
439
+
440
+ ring->first_seg = seg;
441
+ ring->last_seg = seg;
442
+ seg->next = seg;
443
+
444
+ seg->trbs = dma_alloc_coherent(dev, TRB_SEGMENT_SIZE, &dma, flags);
445
+ if (!seg->trbs)
446
+ goto dma_fail;
447
+
448
+ seg->dma = dma;
449
+
450
+ /* Only event ring does not use link TRB */
451
+ if (type != TYPE_EVENT) {
452
+ union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
453
+
454
+ trb->link.segment_ptr = cpu_to_le64(dma);
455
+ trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
456
+ }
457
+ INIT_LIST_HEAD(&ring->td_list);
458
+ xhci_initialize_ring_info(ring, 1);
459
+ return ring;
460
+dma_fail:
461
+ kfree(seg);
462
+seg_fail:
463
+ kfree(ring);
464
+ return NULL;
465
+}
466
+
467
+static int xhci_dbc_mem_init(struct xhci_dbc *dbc, gfp_t flags)
375468 {
376469 int ret;
377470 dma_addr_t deq;
378471 u32 string_length;
379
- struct xhci_dbc *dbc = xhci->dbc;
472
+ struct device *dev = dbc->dev;
380473
381474 /* Allocate various rings for events and transfers: */
382
- dbc->ring_evt = xhci_ring_alloc(xhci, 1, 1, TYPE_EVENT, 0, flags);
475
+ dbc->ring_evt = xhci_dbc_ring_alloc(dev, TYPE_EVENT, flags);
383476 if (!dbc->ring_evt)
384477 goto evt_fail;
385478
386
- dbc->ring_in = xhci_ring_alloc(xhci, 1, 1, TYPE_BULK, 0, flags);
479
+ dbc->ring_in = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
387480 if (!dbc->ring_in)
388481 goto in_fail;
389482
390
- dbc->ring_out = xhci_ring_alloc(xhci, 1, 1, TYPE_BULK, 0, flags);
483
+ dbc->ring_out = xhci_dbc_ring_alloc(dev, TYPE_BULK, flags);
391484 if (!dbc->ring_out)
392485 goto out_fail;
393486
394487 /* Allocate and populate ERST: */
395
- ret = xhci_alloc_erst(xhci, dbc->ring_evt, &dbc->erst, flags);
488
+ ret = dbc_erst_alloc(dev, dbc->ring_evt, &dbc->erst, flags);
396489 if (ret)
397490 goto erst_fail;
398491
399492 /* Allocate context data structure: */
400
- dbc->ctx = xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_DEVICE, flags);
493
+ dbc->ctx = dbc_alloc_ctx(dev, flags); /* was sysdev, and is still */
401494 if (!dbc->ctx)
402495 goto ctx_fail;
403496
404497 /* Allocate the string table: */
405498 dbc->string_size = sizeof(struct dbc_str_descs);
406
- dbc->string = dbc_dma_alloc_coherent(xhci,
407
- dbc->string_size,
408
- &dbc->string_dma,
409
- flags);
499
+ dbc->string = dma_alloc_coherent(dev, dbc->string_size,
500
+ &dbc->string_dma, flags);
410501 if (!dbc->string)
411502 goto string_fail;
412503
413504 /* Setup ERST register: */
414505 writel(dbc->erst.erst_size, &dbc->regs->ersts);
415
- xhci_write_64(xhci, dbc->erst.erst_dma_addr, &dbc->regs->erstba);
506
+
507
+ lo_hi_writeq(dbc->erst.erst_dma_addr, &dbc->regs->erstba);
416508 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
417509 dbc->ring_evt->dequeue);
418
- xhci_write_64(xhci, deq, &dbc->regs->erdp);
510
+ lo_hi_writeq(deq, &dbc->regs->erdp);
419511
420512 /* Setup strings and contexts: */
421513 string_length = xhci_dbc_populate_strings(dbc->string);
422
- xhci_dbc_init_contexts(xhci, string_length);
514
+ xhci_dbc_init_contexts(dbc, string_length);
423515
424
- mmiowb();
425
-
426
- xhci_dbc_eps_init(xhci);
516
+ xhci_dbc_eps_init(dbc);
427517 dbc->state = DS_INITIALIZED;
428518
429519 return 0;
430520
431521 string_fail:
432
- xhci_free_container_ctx(xhci, dbc->ctx);
522
+ dbc_free_ctx(dev, dbc->ctx);
433523 dbc->ctx = NULL;
434524 ctx_fail:
435
- xhci_free_erst(xhci, &dbc->erst);
525
+ dbc_erst_free(dev, &dbc->erst);
436526 erst_fail:
437
- xhci_ring_free(xhci, dbc->ring_out);
527
+ dbc_ring_free(dev, dbc->ring_out);
438528 dbc->ring_out = NULL;
439529 out_fail:
440
- xhci_ring_free(xhci, dbc->ring_in);
530
+ dbc_ring_free(dev, dbc->ring_in);
441531 dbc->ring_in = NULL;
442532 in_fail:
443
- xhci_ring_free(xhci, dbc->ring_evt);
533
+ dbc_ring_free(dev, dbc->ring_evt);
444534 dbc->ring_evt = NULL;
445535 evt_fail:
446536 return -ENOMEM;
447537 }
448538
449
-static void xhci_dbc_mem_cleanup(struct xhci_hcd *xhci)
539
+static void xhci_dbc_mem_cleanup(struct xhci_dbc *dbc)
450540 {
451
- struct xhci_dbc *dbc = xhci->dbc;
452
-
453541 if (!dbc)
454542 return;
455543
456
- xhci_dbc_eps_exit(xhci);
544
+ xhci_dbc_eps_exit(dbc);
457545
458546 if (dbc->string) {
459
- dbc_dma_free_coherent(xhci,
460
- dbc->string_size,
461
- dbc->string, dbc->string_dma);
547
+ dma_free_coherent(dbc->dev, dbc->string_size,
548
+ dbc->string, dbc->string_dma);
462549 dbc->string = NULL;
463550 }
464551
465
- xhci_free_container_ctx(xhci, dbc->ctx);
552
+ dbc_free_ctx(dbc->dev, dbc->ctx);
466553 dbc->ctx = NULL;
467554
468
- xhci_free_erst(xhci, &dbc->erst);
469
- xhci_ring_free(xhci, dbc->ring_out);
470
- xhci_ring_free(xhci, dbc->ring_in);
471
- xhci_ring_free(xhci, dbc->ring_evt);
555
+ dbc_erst_free(dbc->dev, &dbc->erst);
556
+ dbc_ring_free(dbc->dev, dbc->ring_out);
557
+ dbc_ring_free(dbc->dev, dbc->ring_in);
558
+ dbc_ring_free(dbc->dev, dbc->ring_evt);
472559 dbc->ring_in = NULL;
473560 dbc->ring_out = NULL;
474561 dbc->ring_evt = NULL;
475562 }
476563
477
-static int xhci_do_dbc_start(struct xhci_hcd *xhci)
564
+static int xhci_do_dbc_start(struct xhci_dbc *dbc)
478565 {
479566 int ret;
480567 u32 ctrl;
481
- struct xhci_dbc *dbc = xhci->dbc;
482568
483569 if (dbc->state != DS_DISABLED)
484570 return -EINVAL;
....@@ -490,7 +576,7 @@
490576 if (ret)
491577 return ret;
492578
493
- ret = xhci_dbc_mem_init(xhci, GFP_ATOMIC);
579
+ ret = xhci_dbc_mem_init(dbc, GFP_ATOMIC);
494580 if (ret)
495581 return ret;
496582
....@@ -508,10 +594,8 @@
508594 return 0;
509595 }
510596
511
-static int xhci_do_dbc_stop(struct xhci_hcd *xhci)
597
+static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
512598 {
513
- struct xhci_dbc *dbc = xhci->dbc;
514
-
515599 if (dbc->state == DS_DISABLED)
516600 return -1;
517601
....@@ -521,76 +605,81 @@
521605 return 0;
522606 }
523607
524
-static int xhci_dbc_start(struct xhci_hcd *xhci)
608
+static int xhci_dbc_start(struct xhci_dbc *dbc)
525609 {
526610 int ret;
527611 unsigned long flags;
528
- struct xhci_dbc *dbc = xhci->dbc;
529612
530613 WARN_ON(!dbc);
531614
532
- pm_runtime_get_sync(xhci_to_hcd(xhci)->self.controller);
615
+ pm_runtime_get_sync(dbc->dev); /* note this was self.controller */
533616
534617 spin_lock_irqsave(&dbc->lock, flags);
535
- ret = xhci_do_dbc_start(xhci);
618
+ ret = xhci_do_dbc_start(dbc);
536619 spin_unlock_irqrestore(&dbc->lock, flags);
537620
538621 if (ret) {
539
- pm_runtime_put(xhci_to_hcd(xhci)->self.controller);
622
+ pm_runtime_put(dbc->dev); /* note this was self.controller */
540623 return ret;
541624 }
542625
543626 return mod_delayed_work(system_wq, &dbc->event_work, 1);
544627 }
545628
546
-static void xhci_dbc_stop(struct xhci_hcd *xhci)
629
+static void xhci_dbc_stop(struct xhci_dbc *dbc)
547630 {
548631 int ret;
549632 unsigned long flags;
550
- struct xhci_dbc *dbc = xhci->dbc;
551
- struct dbc_port *port = &dbc->port;
552633
553634 WARN_ON(!dbc);
554635
636
+ switch (dbc->state) {
637
+ case DS_DISABLED:
638
+ return;
639
+ case DS_CONFIGURED:
640
+ case DS_STALLED:
641
+ if (dbc->driver->disconnect)
642
+ dbc->driver->disconnect(dbc);
643
+ break;
644
+ default:
645
+ break;
646
+ }
647
+
555648 cancel_delayed_work_sync(&dbc->event_work);
556649
557
- if (port->registered)
558
- xhci_dbc_tty_unregister_device(xhci);
559
-
560650 spin_lock_irqsave(&dbc->lock, flags);
561
- ret = xhci_do_dbc_stop(xhci);
651
+ ret = xhci_do_dbc_stop(dbc);
562652 spin_unlock_irqrestore(&dbc->lock, flags);
563653
564654 if (!ret) {
565
- xhci_dbc_mem_cleanup(xhci);
566
- pm_runtime_put_sync(xhci_to_hcd(xhci)->self.controller);
655
+ xhci_dbc_mem_cleanup(dbc);
656
+ pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
567657 }
568658 }
569659
570660 static void
571
-dbc_handle_port_status(struct xhci_hcd *xhci, union xhci_trb *event)
661
+dbc_handle_port_status(struct xhci_dbc *dbc, union xhci_trb *event)
572662 {
573663 u32 portsc;
574
- struct xhci_dbc *dbc = xhci->dbc;
575664
576665 portsc = readl(&dbc->regs->portsc);
577666 if (portsc & DBC_PORTSC_CONN_CHANGE)
578
- xhci_info(xhci, "DbC port connect change\n");
667
+ dev_info(dbc->dev, "DbC port connect change\n");
579668
580669 if (portsc & DBC_PORTSC_RESET_CHANGE)
581
- xhci_info(xhci, "DbC port reset change\n");
670
+ dev_info(dbc->dev, "DbC port reset change\n");
582671
583672 if (portsc & DBC_PORTSC_LINK_CHANGE)
584
- xhci_info(xhci, "DbC port link status change\n");
673
+ dev_info(dbc->dev, "DbC port link status change\n");
585674
586675 if (portsc & DBC_PORTSC_CONFIG_CHANGE)
587
- xhci_info(xhci, "DbC config error change\n");
676
+ dev_info(dbc->dev, "DbC config error change\n");
588677
589678 /* Port reset change bit will be cleared in other place: */
590679 writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc);
591680 }
592681
593
-static void dbc_handle_xfer_event(struct xhci_hcd *xhci, union xhci_trb *event)
682
+static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
594683 {
595684 struct dbc_ep *dep;
596685 struct xhci_ring *ring;
....@@ -604,13 +693,13 @@
604693 remain_length = EVENT_TRB_LEN(le32_to_cpu(event->generic.field[2]));
605694 ep_id = TRB_TO_EP_ID(le32_to_cpu(event->generic.field[3]));
606695 dep = (ep_id == EPID_OUT) ?
607
- get_out_ep(xhci) : get_in_ep(xhci);
696
+ get_out_ep(dbc) : get_in_ep(dbc);
608697 ring = dep->ring;
609698
610699 switch (comp_code) {
611700 case COMP_SUCCESS:
612701 remain_length = 0;
613
- /* FALLTHROUGH */
702
+ fallthrough;
614703 case COMP_SHORT_PACKET:
615704 status = 0;
616705 break;
....@@ -618,11 +707,11 @@
618707 case COMP_BABBLE_DETECTED_ERROR:
619708 case COMP_USB_TRANSACTION_ERROR:
620709 case COMP_STALL_ERROR:
621
- xhci_warn(xhci, "tx error %d detected\n", comp_code);
710
+ dev_warn(dbc->dev, "tx error %d detected\n", comp_code);
622711 status = -comp_code;
623712 break;
624713 default:
625
- xhci_err(xhci, "unknown tx error %d\n", comp_code);
714
+ dev_err(dbc->dev, "unknown tx error %d\n", comp_code);
626715 status = -comp_code;
627716 break;
628717 }
....@@ -636,7 +725,7 @@
636725 }
637726
638727 if (!req) {
639
- xhci_warn(xhci, "no matched request\n");
728
+ dev_warn(dbc->dev, "no matched request\n");
640729 return;
641730 }
642731
....@@ -647,13 +736,23 @@
647736 xhci_dbc_giveback(req, status);
648737 }
649738
739
+static void inc_evt_deq(struct xhci_ring *ring)
740
+{
741
+ /* If on the last TRB of the segment go back to the beginning */
742
+ if (ring->dequeue == &ring->deq_seg->trbs[TRBS_PER_SEGMENT - 1]) {
743
+ ring->cycle_state ^= 1;
744
+ ring->dequeue = ring->deq_seg->trbs;
745
+ return;
746
+ }
747
+ ring->dequeue++;
748
+}
749
+
650750 static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
651751 {
652752 dma_addr_t deq;
653753 struct dbc_ep *dep;
654754 union xhci_trb *evt;
655755 u32 ctrl, portsc;
656
- struct xhci_hcd *xhci = dbc->xhci;
657756 bool update_erdp = false;
658757
659758 /* DbC state machine: */
....@@ -666,7 +765,7 @@
666765 portsc = readl(&dbc->regs->portsc);
667766 if (portsc & DBC_PORTSC_CONN_STATUS) {
668767 dbc->state = DS_CONNECTED;
669
- xhci_info(xhci, "DbC connected\n");
768
+ dev_info(dbc->dev, "DbC connected\n");
670769 }
671770
672771 return EVT_DONE;
....@@ -674,7 +773,7 @@
674773 ctrl = readl(&dbc->regs->control);
675774 if (ctrl & DBC_CTRL_DBC_RUN) {
676775 dbc->state = DS_CONFIGURED;
677
- xhci_info(xhci, "DbC configured\n");
776
+ dev_info(dbc->dev, "DbC configured\n");
678777 portsc = readl(&dbc->regs->portsc);
679778 writel(portsc, &dbc->regs->portsc);
680779 return EVT_GSER;
....@@ -686,19 +785,19 @@
686785 portsc = readl(&dbc->regs->portsc);
687786 if (!(portsc & DBC_PORTSC_PORT_ENABLED) &&
688787 !(portsc & DBC_PORTSC_CONN_STATUS)) {
689
- xhci_info(xhci, "DbC cable unplugged\n");
788
+ dev_info(dbc->dev, "DbC cable unplugged\n");
690789 dbc->state = DS_ENABLED;
691
- xhci_dbc_flush_reqests(dbc);
790
+ xhci_dbc_flush_requests(dbc);
692791
693792 return EVT_DISC;
694793 }
695794
696795 /* Handle debug port reset event: */
697796 if (portsc & DBC_PORTSC_RESET_CHANGE) {
698
- xhci_info(xhci, "DbC port reset\n");
797
+ dev_info(dbc->dev, "DbC port reset\n");
699798 writel(portsc, &dbc->regs->portsc);
700799 dbc->state = DS_ENABLED;
701
- xhci_dbc_flush_reqests(dbc);
800
+ xhci_dbc_flush_requests(dbc);
702801
703802 return EVT_DISC;
704803 }
....@@ -707,16 +806,16 @@
707806 ctrl = readl(&dbc->regs->control);
708807 if ((ctrl & DBC_CTRL_HALT_IN_TR) ||
709808 (ctrl & DBC_CTRL_HALT_OUT_TR)) {
710
- xhci_info(xhci, "DbC Endpoint stall\n");
809
+ dev_info(dbc->dev, "DbC Endpoint stall\n");
711810 dbc->state = DS_STALLED;
712811
713812 if (ctrl & DBC_CTRL_HALT_IN_TR) {
714
- dep = get_in_ep(xhci);
813
+ dep = get_in_ep(dbc);
715814 xhci_dbc_flush_endpoint_requests(dep);
716815 }
717816
718817 if (ctrl & DBC_CTRL_HALT_OUT_TR) {
719
- dep = get_out_ep(xhci);
818
+ dep = get_out_ep(dbc);
720819 xhci_dbc_flush_endpoint_requests(dep);
721820 }
722821
....@@ -741,7 +840,7 @@
741840
742841 return EVT_DONE;
743842 default:
744
- xhci_err(xhci, "Unknown DbC state %d\n", dbc->state);
843
+ dev_err(dbc->dev, "Unknown DbC state %d\n", dbc->state);
745844 break;
746845 }
747846
....@@ -759,16 +858,17 @@
759858
760859 switch (le32_to_cpu(evt->event_cmd.flags) & TRB_TYPE_BITMASK) {
761860 case TRB_TYPE(TRB_PORT_STATUS):
762
- dbc_handle_port_status(xhci, evt);
861
+ dbc_handle_port_status(dbc, evt);
763862 break;
764863 case TRB_TYPE(TRB_TRANSFER):
765
- dbc_handle_xfer_event(xhci, evt);
864
+ dbc_handle_xfer_event(dbc, evt);
766865 break;
767866 default:
768867 break;
769868 }
770869
771
- inc_deq(xhci, dbc->ring_evt);
870
+ inc_evt_deq(dbc->ring_evt);
871
+
772872 evt = dbc->ring_evt->dequeue;
773873 update_erdp = true;
774874 }
....@@ -777,7 +877,7 @@
777877 if (update_erdp) {
778878 deq = xhci_trb_virt_to_dma(dbc->ring_evt->deq_seg,
779879 dbc->ring_evt->dequeue);
780
- xhci_write_64(xhci, deq, &dbc->regs->erdp);
880
+ lo_hi_writeq(deq, &dbc->regs->erdp);
781881 }
782882
783883 return EVT_DONE;
....@@ -785,14 +885,11 @@
785885
786886 static void xhci_dbc_handle_events(struct work_struct *work)
787887 {
788
- int ret;
789888 enum evtreturn evtr;
790889 struct xhci_dbc *dbc;
791890 unsigned long flags;
792
- struct xhci_hcd *xhci;
793891
794892 dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
795
- xhci = dbc->xhci;
796893
797894 spin_lock_irqsave(&dbc->lock, flags);
798895 evtr = xhci_dbc_do_handle_events(dbc);
....@@ -800,21 +897,17 @@
800897
801898 switch (evtr) {
802899 case EVT_GSER:
803
- ret = xhci_dbc_tty_register_device(xhci);
804
- if (ret) {
805
- xhci_err(xhci, "failed to alloc tty device\n");
806
- break;
807
- }
808
-
809
- xhci_info(xhci, "DbC now attached to /dev/ttyDBC0\n");
900
+ if (dbc->driver->configure)
901
+ dbc->driver->configure(dbc);
810902 break;
811903 case EVT_DISC:
812
- xhci_dbc_tty_unregister_device(xhci);
904
+ if (dbc->driver->disconnect)
905
+ dbc->driver->disconnect(dbc);
813906 break;
814907 case EVT_DONE:
815908 break;
816909 default:
817
- xhci_info(xhci, "stop handling dbc events\n");
910
+ dev_info(dbc->dev, "stop handling dbc events\n");
818911 return;
819912 }
820913
....@@ -867,6 +960,7 @@
867960 spin_unlock_irqrestore(&xhci->lock, flags);
868961
869962 dbc->xhci = xhci;
963
+ dbc->dev = xhci_to_hcd(xhci)->self.sysdev;
870964 INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
871965 spin_lock_init(&dbc->lock);
872966
....@@ -915,13 +1009,15 @@
9151009 const char *buf, size_t count)
9161010 {
9171011 struct xhci_hcd *xhci;
1012
+ struct xhci_dbc *dbc;
9181013
9191014 xhci = hcd_to_xhci(dev_get_drvdata(dev));
1015
+ dbc = xhci->dbc;
9201016
9211017 if (!strncmp(buf, "enable", 6))
922
- xhci_dbc_start(xhci);
1018
+ xhci_dbc_start(dbc);
9231019 else if (!strncmp(buf, "disable", 7))
924
- xhci_dbc_stop(xhci);
1020
+ xhci_dbc_stop(dbc);
9251021 else
9261022 return -EINVAL;
9271023
....@@ -939,7 +1035,7 @@
9391035 if (ret)
9401036 goto init_err3;
9411037
942
- ret = xhci_dbc_tty_register_driver(xhci);
1038
+ ret = xhci_dbc_tty_probe(xhci);
9431039 if (ret)
9441040 goto init_err2;
9451041
....@@ -950,7 +1046,7 @@
9501046 return 0;
9511047
9521048 init_err1:
953
- xhci_dbc_tty_unregister_driver();
1049
+ xhci_dbc_tty_remove(xhci->dbc);
9541050 init_err2:
9551051 xhci_do_dbc_exit(xhci);
9561052 init_err3:
....@@ -965,8 +1061,8 @@
9651061 return;
9661062
9671063 device_remove_file(dev, &dev_attr_dbc);
968
- xhci_dbc_tty_unregister_driver();
969
- xhci_dbc_stop(xhci);
1064
+ xhci_dbc_tty_remove(xhci->dbc);
1065
+ xhci_dbc_stop(xhci->dbc);
9701066 xhci_do_dbc_exit(xhci);
9711067 }
9721068
....@@ -981,7 +1077,7 @@
9811077 if (dbc->state == DS_CONFIGURED)
9821078 dbc->resume_required = 1;
9831079
984
- xhci_dbc_stop(xhci);
1080
+ xhci_dbc_stop(dbc);
9851081
9861082 return 0;
9871083 }
....@@ -996,7 +1092,7 @@
9961092
9971093 if (dbc->resume_required) {
9981094 dbc->resume_required = 0;
999
- xhci_dbc_start(xhci);
1095
+ xhci_dbc_start(dbc);
10001096 }
10011097
10021098 return ret;