@@ -415,13 +415,14 @@ static void gsi_evt_ring_de_alloc_command(struct gsi *gsi, u32 evt_ring_id)
415
415
evt_ring -> state );
416
416
}
417
417
418
- /* Return the hardware's notion of the current state of a channel */
419
- static enum gsi_channel_state
420
- gsi_channel_state (struct gsi * gsi , u32 channel_id )
418
+ /* Fetch the current state of a channel from hardware */
419
+ static enum gsi_channel_state gsi_channel_state (struct gsi_channel * channel )
421
420
{
421
+ u32 channel_id = gsi_channel_id (channel );
422
+ void * virt = channel -> gsi -> virt ;
422
423
u32 val ;
423
424
424
- val = ioread32 (gsi -> virt + GSI_CH_C_CNTXT_0_OFFSET (channel_id ));
425
+ val = ioread32 (virt + GSI_CH_C_CNTXT_0_OFFSET (channel_id ));
425
426
426
427
return u32_get_bits (val , CHSTATE_FMASK );
427
428
}
@@ -432,16 +433,18 @@ gsi_channel_command(struct gsi_channel *channel, enum gsi_ch_cmd_opcode opcode)
432
433
{
433
434
struct completion * completion = & channel -> completion ;
434
435
u32 channel_id = gsi_channel_id (channel );
436
+ struct gsi * gsi = channel -> gsi ;
435
437
u32 val ;
436
438
437
439
val = u32_encode_bits (channel_id , CH_CHID_FMASK );
438
440
val |= u32_encode_bits (opcode , CH_OPCODE_FMASK );
439
441
440
- if (gsi_command (channel -> gsi , GSI_CH_CMD_OFFSET , val , completion ))
442
+ if (gsi_command (gsi , GSI_CH_CMD_OFFSET , val , completion ))
441
443
return 0 ; /* Success! */
442
444
443
- dev_err (channel -> gsi -> dev , "GSI command %u to channel %u timed out "
444
- "(state is %u)\n" , opcode , channel_id , channel -> state );
445
+ dev_err (gsi -> dev ,
446
+ "GSI command %u to channel %u timed out (state is %u)\n" ,
447
+ opcode , channel_id , gsi_channel_state (channel ));
445
448
446
449
return - ETIMEDOUT ;
447
450
}
@@ -450,18 +453,21 @@ gsi_channel_command(struct gsi_channel *channel, enum gsi_ch_cmd_opcode opcode)
450
453
static int gsi_channel_alloc_command (struct gsi * gsi , u32 channel_id )
451
454
{
452
455
struct gsi_channel * channel = & gsi -> channel [channel_id ];
456
+ enum gsi_channel_state state ;
453
457
int ret ;
454
458
455
459
/* Get initial channel state */
456
- channel -> state = gsi_channel_state (gsi , channel_id );
457
-
458
- if (channel -> state != GSI_CHANNEL_STATE_NOT_ALLOCATED )
460
+ state = gsi_channel_state (channel );
461
+ if (state != GSI_CHANNEL_STATE_NOT_ALLOCATED )
459
462
return - EINVAL ;
460
463
461
464
ret = gsi_channel_command (channel , GSI_CH_ALLOCATE );
462
- if (!ret && channel -> state != GSI_CHANNEL_STATE_ALLOCATED ) {
465
+
466
+ /* Channel state will normally have been updated */
467
+ state = gsi_channel_state (channel );
468
+ if (!ret && state != GSI_CHANNEL_STATE_ALLOCATED ) {
463
469
dev_err (gsi -> dev , "bad channel state (%u) after alloc\n" ,
464
- channel -> state );
470
+ state );
465
471
ret = - EIO ;
466
472
}
467
473
@@ -471,18 +477,21 @@ static int gsi_channel_alloc_command(struct gsi *gsi, u32 channel_id)
471
477
/* Start an ALLOCATED channel */
472
478
static int gsi_channel_start_command (struct gsi_channel * channel )
473
479
{
474
- enum gsi_channel_state state = channel -> state ;
480
+ enum gsi_channel_state state ;
475
481
int ret ;
476
482
483
+ state = gsi_channel_state (channel );
477
484
if (state != GSI_CHANNEL_STATE_ALLOCATED &&
478
485
state != GSI_CHANNEL_STATE_STOPPED )
479
486
return - EINVAL ;
480
487
481
488
ret = gsi_channel_command (channel , GSI_CH_START );
482
- if (!ret && channel -> state != GSI_CHANNEL_STATE_STARTED ) {
489
+
490
+ /* Channel state will normally have been updated */
491
+ state = gsi_channel_state (channel );
492
+ if (!ret && state != GSI_CHANNEL_STATE_STARTED ) {
483
493
dev_err (channel -> gsi -> dev ,
484
- "bad channel state (%u) after start\n" ,
485
- channel -> state );
494
+ "bad channel state (%u) after start\n" , state );
486
495
ret = - EIO ;
487
496
}
488
497
@@ -492,65 +501,77 @@ static int gsi_channel_start_command(struct gsi_channel *channel)
492
501
/* Stop a GSI channel in STARTED state */
493
502
static int gsi_channel_stop_command (struct gsi_channel * channel )
494
503
{
495
- enum gsi_channel_state state = channel -> state ;
504
+ enum gsi_channel_state state ;
496
505
int ret ;
497
506
507
+ state = gsi_channel_state (channel );
498
508
if (state != GSI_CHANNEL_STATE_STARTED &&
499
509
state != GSI_CHANNEL_STATE_STOP_IN_PROC )
500
510
return - EINVAL ;
501
511
502
512
ret = gsi_channel_command (channel , GSI_CH_STOP );
503
- if (ret || channel -> state == GSI_CHANNEL_STATE_STOPPED )
513
+
514
+ /* Channel state will normally have been updated */
515
+ state = gsi_channel_state (channel );
516
+ if (ret || state == GSI_CHANNEL_STATE_STOPPED )
504
517
return ret ;
505
518
506
519
/* We may have to try again if stop is in progress */
507
- if (channel -> state == GSI_CHANNEL_STATE_STOP_IN_PROC )
520
+ if (state == GSI_CHANNEL_STATE_STOP_IN_PROC )
508
521
return - EAGAIN ;
509
522
510
- dev_err (channel -> gsi -> dev , "bad channel state (%u) after stop\n" ,
511
- channel -> state );
523
+ dev_err (channel -> gsi -> dev ,
524
+ "bad channel state (%u) after stop\n" , state );
512
525
513
526
return - EIO ;
514
527
}
515
528
516
529
/* Reset a GSI channel in ALLOCATED or ERROR state. */
517
530
static void gsi_channel_reset_command (struct gsi_channel * channel )
518
531
{
532
+ enum gsi_channel_state state ;
519
533
int ret ;
520
534
521
535
msleep (1 ); /* A short delay is required before a RESET command */
522
536
523
- if (channel -> state != GSI_CHANNEL_STATE_STOPPED &&
524
- channel -> state != GSI_CHANNEL_STATE_ERROR ) {
537
+ state = gsi_channel_state (channel );
538
+ if (state != GSI_CHANNEL_STATE_STOPPED &&
539
+ state != GSI_CHANNEL_STATE_ERROR ) {
525
540
dev_err (channel -> gsi -> dev ,
526
- "bad channel state (%u) before reset\n" ,
527
- channel -> state );
541
+ "bad channel state (%u) before reset\n" , state );
528
542
return ;
529
543
}
530
544
531
545
ret = gsi_channel_command (channel , GSI_CH_RESET );
532
- if (!ret && channel -> state != GSI_CHANNEL_STATE_ALLOCATED )
546
+
547
+ /* Channel state will normally have been updated */
548
+ state = gsi_channel_state (channel );
549
+ if (!ret && state != GSI_CHANNEL_STATE_ALLOCATED )
533
550
dev_err (channel -> gsi -> dev ,
534
- "bad channel state (%u) after reset\n" ,
535
- channel -> state );
551
+ "bad channel state (%u) after reset\n" , state );
536
552
}
537
553
538
554
/* Deallocate an ALLOCATED GSI channel */
539
555
static void gsi_channel_de_alloc_command (struct gsi * gsi , u32 channel_id )
540
556
{
541
557
struct gsi_channel * channel = & gsi -> channel [channel_id ];
558
+ enum gsi_channel_state state ;
542
559
int ret ;
543
560
544
- if (channel -> state != GSI_CHANNEL_STATE_ALLOCATED ) {
545
- dev_err (gsi -> dev , "bad channel state (%u) before dealloc\n" ,
546
- channel -> state );
561
+ state = gsi_channel_state (channel );
562
+ if (state != GSI_CHANNEL_STATE_ALLOCATED ) {
563
+ dev_err (gsi -> dev ,
564
+ "bad channel state (%u) before dealloc\n" , state );
547
565
return ;
548
566
}
549
567
550
568
ret = gsi_channel_command (channel , GSI_CH_DE_ALLOC );
551
- if (!ret && channel -> state != GSI_CHANNEL_STATE_NOT_ALLOCATED )
552
- dev_err (gsi -> dev , "bad channel state (%u) after dealloc\n" ,
553
- channel -> state );
569
+
570
+ /* Channel state will normally have been updated */
571
+ state = gsi_channel_state (channel );
572
+ if (!ret && state != GSI_CHANNEL_STATE_NOT_ALLOCATED )
573
+ dev_err (gsi -> dev ,
574
+ "bad channel state (%u) after dealloc\n" , state );
554
575
}
555
576
556
577
/* Ring an event ring doorbell, reporting the last entry processed by the AP.
@@ -777,6 +798,7 @@ int gsi_channel_start(struct gsi *gsi, u32 channel_id)
777
798
int gsi_channel_stop (struct gsi * gsi , u32 channel_id )
778
799
{
779
800
struct gsi_channel * channel = & gsi -> channel [channel_id ];
801
+ enum gsi_channel_state state ;
780
802
u32 retries ;
781
803
int ret ;
782
804
@@ -786,7 +808,8 @@ int gsi_channel_stop(struct gsi *gsi, u32 channel_id)
786
808
* STOP command timed out. We won't stop a channel if stopping it
787
809
* was successful previously (so we still want the freeze above).
788
810
*/
789
- if (channel -> state == GSI_CHANNEL_STATE_STOPPED )
811
+ state = gsi_channel_state (channel );
812
+ if (state == GSI_CHANNEL_STATE_STOPPED )
790
813
return 0 ;
791
814
792
815
/* RX channels might require a little time to enter STOPPED state */
@@ -940,7 +963,6 @@ static void gsi_isr_chan_ctrl(struct gsi *gsi)
940
963
channel_mask ^= BIT (channel_id );
941
964
942
965
channel = & gsi -> channel [channel_id ];
943
- channel -> state = gsi_channel_state (gsi , channel_id );
944
966
945
967
complete (& channel -> completion );
946
968
}
0 commit comments