StorageLdpcRetryController constructor

StorageLdpcRetryController({
  1. required Logic clk,
  2. required Logic reset,
  3. required LdpcCode code,
  4. required int llrWidth,
  5. required int maxRetries,
  6. required int requestIdWidth,
  7. required int blockAddressWidth,
  8. required LdpcDecoderFunctor decoderFunctor,
  9. required ReadyValidInterface<StorageLdpcDecodeRequest> requests,
  10. required ReadyValidInterface<StorageLdpcReadRequest> mediaRequests,
  11. required ReadyValidInterface<StorageLdpcSoftReadResponse> softResponses,
  12. required ReadyValidInterface<StorageLdpcDecodeResult> results,
  13. String name = 'storage_ldpc_retry_controller',
})

Creates a storage LDPC read-retry controller.

Implementation

StorageLdpcRetryController({
  required Logic clk,
  required Logic reset,
  required this.code,
  required this.llrWidth,
  required this.maxRetries,
  required this.requestIdWidth,
  required this.blockAddressWidth,
  required this.decoderFunctor,
  required ReadyValidInterface<StorageLdpcDecodeRequest> requests,
  required ReadyValidInterface<StorageLdpcReadRequest> mediaRequests,
  required ReadyValidInterface<StorageLdpcSoftReadResponse> softResponses,
  required ReadyValidInterface<StorageLdpcDecodeResult> results,
  super.name = 'storage_ldpc_retry_controller',
})  : retryLevelWidth = max(1, (maxRetries + 1).log2Ceil),
      iterationWidth = max(
        1,
        (decoderFunctor.contract.maximumIterations + 1).log2Ceil,
      ),
      super(
        definitionName: schemaQualifiedDefinitionName(
          'StorageLdpcRetryController_'
          'N${code.length}_K${code.messageBits}_Q${llrWidth}_'
          'R${maxRetries}_ID${requestIdWidth}_A${blockAddressWidth}_'
          '${decoderFunctor.identity}_${code.configurationSignature}_',
          [softResponses.data],
        ),
      ) {
  if (maxRetries < 0) {
    throw ArgumentError.value(
        maxRetries, 'maxRetries', 'Must be non-negative.');
  }
  if (requestIdWidth < 1 || blockAddressWidth < 1) {
    throw ArgumentError(
      'Request identifier and block address widths must be positive.',
    );
  }
  _validateInterfaces(requests, mediaRequests, softResponses, results);

  final localClk = addInput('clk', clk);
  final localReset = addInput('reset', reset);
  this.requests = addPairInterfacePorts(
    requests,
    PairRole.consumer,
    uniquify: (original) => 'request_$original',
  );
  this.mediaRequests = addPairInterfacePorts(
    mediaRequests,
    PairRole.provider,
    uniquify: (original) => 'media_request_$original',
  );
  this.softResponses = addPairInterfacePorts(
    softResponses,
    PairRole.consumer,
    uniquify: (original) => 'soft_response_$original',
  );
  this.results = addPairInterfacePorts(
    results,
    PairRole.provider,
    uniquify: (original) => 'result_$original',
  );
  final busyOutput = addOutput('busy');
  final retryIssuedOutput = addOutput('retryIssued');
  final protocolErrorOutput = addOutput('protocolError');

  const idle = 0;
  const issueRead = 1;
  const waitForSoftRead = 2;
  const submitDecode = 3;
  const waitForDecode = 4;
  const retainResult = 5;
  const stateWidth = 3;
  final state = Logic(name: '${name}_state', width: stateWidth);
  final requestId = Logic(name: '${name}_request_id', width: requestIdWidth);
  final blockAddress =
      Logic(name: '${name}_block_address', width: blockAddressWidth);
  final retryLevel =
      Logic(name: '${name}_retry_level', width: retryLevelWidth);
  final softLlrs = cloneTypedPayload(
    this.softResponses.data.logLikelihoodRatios,
    name: '${name}_soft_llrs',
  );
  final retryPulse = Logic(name: '${name}_retry_pulse');
  final protocolErrorPulse = Logic(name: '${name}_protocol_error_pulse');

  final resultMessage =
      Logic(name: '${name}_result_message', width: code.messageBits);
  final resultCodeword =
      Logic(name: '${name}_result_codeword', width: code.length);
  final resultSyndrome =
      Logic(name: '${name}_result_syndrome', width: code.parityBits);
  final resultIterations = Logic(
    name: '${name}_result_iterations',
    width: iterationWidth,
  );
  final resultCorrected = Logic(name: '${name}_result_corrected');
  final resultUncorrectable = Logic(name: '${name}_result_uncorrectable');
  final resultMediaFailure = Logic(name: '${name}_result_media_failure');

  final decoderInput = ReadyValidCodecInterface(
    decoderFunctor.supportsTypedPayloads
        ? cloneTypedPayload(softLlrs, name: '${name}_decoder_llrs')
        : Logic(width: code.length * llrWidth, name: '${name}_decoder_llrs'),
  );
  final decoderOutput = ReadyValidCodecInterface(
    Logic(width: code.messageBits, name: '${name}_decoder_message'),
  );
  final decoder = decoderFunctor(
    clk: localClk,
    reset: localReset,
    code: code,
    llrWidth: llrWidth,
    upstream: decoderInput,
    downstream: decoderOutput,
    name: '${name}_decoder',
  );
  final idleState = state.eq(idle);
  final issueReadState = state.eq(issueRead);
  final waitForSoftReadState = state.eq(waitForSoftRead);
  final submitDecodeState = state.eq(submitDecode);
  final waitForDecodeState = state.eq(waitForDecode);
  final retainResultState = state.eq(retainResult);
  final responseMatches = this.softResponses.data.requestId.eq(requestId) &
      this.softResponses.data.retryLevel.eq(retryLevel);
  final canRetry = retryLevel.lt(maxRetries);
  final mediaRequestAccepted = this.mediaRequests.accepted;
  final softResponseAccepted = this.softResponses.accepted;
  final decoderInputAccepted = decoderInput.accepted;
  final decoderOutputAccepted = decoderOutput.accepted;
  final resultAccepted = this.results.accepted;

  this.requests.ready <= idleState;
  this.mediaRequests.valid <= issueReadState;
  this.mediaRequests.data.requestId <= requestId;
  this.mediaRequests.data.blockAddress <= blockAddress;
  this.mediaRequests.data.retryLevel <= retryLevel;
  this.softResponses.ready <= waitForSoftReadState;
  decoderInput.valid <= submitDecodeState;
  connectPackedPayload(decoderInput.data.data, softLlrs.packed);
  decoderInput.data.start <= Const(1);
  decoderInput.data.last <= Const(1);
  decoderOutput.ready <= waitForDecodeState;
  this.results.valid <= retainResultState;
  this.results.data.requestId <= requestId;
  this.results.data.blockAddress <= blockAddress;
  this.results.data.message <= resultMessage;
  this.results.data.codeword <= resultCodeword;
  this.results.data.syndrome <= resultSyndrome;
  this.results.data.retryLevelUsed <= retryLevel;
  this.results.data.iterationsUsed <= resultIterations;
  this.results.data.retried <= retryLevel.neq(0);
  this.results.data.corrected <= resultCorrected;
  this.results.data.uncorrectable <= resultUncorrectable;
  this.results.data.mediaFailure <= resultMediaFailure;
  busyOutput <= ~idleState;
  retryIssuedOutput <= retryPulse;
  protocolErrorOutput <= protocolErrorPulse;

  Sequential(localClk, reset: localReset, resetValues: {
    state: idle,
    requestId: 0,
    blockAddress: 0,
    retryLevel: 0,
    softLlrs: 0,
    retryPulse: 0,
    protocolErrorPulse: 0,
    resultMessage: 0,
    resultCodeword: 0,
    resultSyndrome: 0,
    resultIterations: 0,
    resultCorrected: 0,
    resultUncorrectable: 0,
    resultMediaFailure: 0,
  }, [
    retryPulse < 0,
    protocolErrorPulse < 0,
    If(this.requests.accepted, then: [
      requestId < this.requests.data.requestId,
      blockAddress < this.requests.data.blockAddress,
      retryLevel < 0,
      state < issueRead,
    ]),
    If(mediaRequestAccepted, then: [
      state < waitForSoftRead,
    ]),
    If(softResponseAccepted, then: [
      If(responseMatches, then: [
        If(this.softResponses.data.mediaError, then: [
          If(canRetry, then: [
            retryLevel < retryLevel + 1,
            retryPulse < 1,
            state < issueRead,
          ], orElse: [
            resultMessage < 0,
            resultCodeword < 0,
            resultSyndrome < 0,
            resultIterations < 0,
            resultCorrected < 0,
            resultUncorrectable < 1,
            resultMediaFailure < 1,
            state < retainResult,
          ]),
        ], orElse: [
          softLlrs < this.softResponses.data.logLikelihoodRatios,
          state < submitDecode,
        ]),
      ], orElse: [
        protocolErrorPulse < 1,
      ]),
    ]),
    If(decoderInputAccepted, then: [
      state < waitForDecode,
    ]),
    If(decoderOutputAccepted, then: [
      If(decoder.status.uncorrectable & canRetry, then: [
        retryLevel < retryLevel + 1,
        retryPulse < 1,
        state < issueRead,
      ], orElse: [
        resultMessage < decoderOutput.data.data,
        resultCodeword < decoder.decodedCodeword,
        resultSyndrome < decoder.syndrome,
        resultIterations < decoder.status.iterationCount,
        resultCorrected < decoder.status.corrected,
        resultUncorrectable < decoder.status.uncorrectable,
        resultMediaFailure < 0,
        state < retainResult,
      ]),
    ]),
    If(resultAccepted, then: [
      state < idle,
    ]),
  ]);
}