Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init branch develop #1

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open

init branch develop #1

wants to merge 53 commits into from

Conversation

BIGWJZ
Copy link
Collaborator

@BIGWJZ BIGWJZ commented Jul 4, 2024

  1. types definition in src/pcieTypes.bsv & src/dmaTypes.bsv
  2. a test case of AXI-Stream interface

src/DmaTypes.bsv Outdated Show resolved Hide resolved
src/DmaTypes.bsv Outdated Show resolved Hide resolved
src/PcieTypes.bsv Outdated Show resolved Hide resolved
src/PcieTypes.bsv Outdated Show resolved Hide resolved
src/PcieTypes.bsv Outdated Show resolved Hide resolved
test/TestAxiStream.bsv Outdated Show resolved Hide resolved
test/TestAxiStream.bsv Outdated Show resolved Hide resolved
test/TestAxiStream.bsv Outdated Show resolved Hide resolved

endmodule

module mkTbAxisWire(AxisFifo#(keepWidth, usrWidth) ifc);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this module be replaced by mkConnection ?

Copy link
Collaborator Author

@BIGWJZ BIGWJZ Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be replaced. In fact, I planned to remove TestAxiStream because the AXIS interface already has a testbench in the blue-wrapper.

src/DmaTypes.bsv Outdated Show resolved Hide resolved
@BIGWJZ BIGWJZ closed this Jul 4, 2024
@BIGWJZ BIGWJZ reopened this Jul 4, 2024
src/PcieTypes.bsv Outdated Show resolved Hide resolved
src/PcieTypes.bsv Show resolved Hide resolved
src/DmaRequestCore.bsv Outdated Show resolved Hide resolved
inputFifo.deq;
let offset = getOffSet(request);
// firstChunkLen = offset % PCIE_TLP_BYTES
DmaMemAddr firstLen = zeroExtend(offset[valueOf(PCIE_TLP_BYTES_WIDTH)-1:0]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to read the PG213 to find out how to get the Max Payload Size(MPS) and Max Read Request Size(MRRS), those value is not const so you should do some refacrtor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MPS&MRRS are passed in the Configuration Status Interface Port . They should be parameters of my module.
image

image

test/TestDmaCore.bsv Outdated Show resolved Hide resolved
test/TestDmaCore.bsv Outdated Show resolved Hide resolved
src/DmaRequestCore.bsv Outdated Show resolved Hide resolved
src/DmaRequestCore.bsv Outdated Show resolved Hide resolved
DmaMemAddr offset = zeroExtend(fromInteger(valueOf(BUS_BOUNDARY)) - pack(request.startAddr[BUS_BOUNDARY_WIDTH-1:0]));
return offset;
// 4096 - startAddr % 4096
Bit#(BUS_BOUNDARY_WIDTH) remainder = truncate(request.startAddr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit#(BUS_BOUNDARY_WIDTH) has occured more than once, so use typedef to define a new type.
Duplicated code is a kind of bad smell in your codebase

return (highIdx > lowIdx);
endfunction

function DmaMemAddr getOffset(DmaRequestFrame request);
DmaMemAddr offset = zeroExtend(fromInteger(valueOf(BUS_BOUNDARY)) - pack(request.startAddr[BUS_BOUNDARY_WIDTH-1:0]));
return offset;
// 4096 - startAddr % 4096
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4096 is bus boundary, not tlp boundary. are you massing them up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the calculated offset is relative to BUS_BOUNDARY. The offset will be sliced to PCIE_TLP_BYES in the getFirstChunkLen rule.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need to split by BUS_BOUNDARY? If you split by PCIE_TLP_BYES , since PCIE_TLP_BYES <= BUS_BOUNDARY, any slice that aligned to PCIE_TLP_BYES won't cross BUS_BOUNDARY.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have modfied.

end
end else begin
if (isSplittingReg) begin // !isFirst
if (totalLenRemainReg <= fromInteger(valueOf(PCIE_TLP_BYTES))) begin
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous comment, I have mentioned that the TLP size is a variable, not a const. This is a very important point. You must fix this issue before moving on.

endrule

rule testFinish ;
if (testCntReg == fromInteger(valueOf(TEST_NUM))) $finish();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't write in one line.

Copy link
Collaborator

@myrfy001 myrfy001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the TLP size is a variable, not a const

src/DmaRequestCore.bsv Outdated Show resolved Hide resolved
typedef TLog#(DEFAULT_TLP_SIZE) DEFAULT_TLP_SIZE_WIDTH;
typedef 3 PCIE_TLP_SIZE_SETTING_WIDTH;
typedef Bit#(PCIE_TLP_SIZE_SETTING_WIDTH) PcieTlpSizeSetting;
typedef enum {DMA_RX, DMA_TX} TRXDirection deriving(Bits, Eq);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not write in one line.

endfunction

// Concat two DataStream frames into one. StreamA.isLast must be True, otherwise the function will return a empty frame to end the stream.
function Tuple3#(DataStream, DataStream, DataBytePtr) getConcatStream (DataStream streamA, DataStream streamB, DataBytePtr bytePtrA, DataBytePtr bytePtrB);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/DmaTypes.bsv Outdated
@@ -27,12 +21,16 @@ typedef struct {
DMACsrValue value;
} DmaCsrFrame deriving(Bits, Bounded, Eq, FShow);

typedef enum {
DMA_RX, DMA_TX
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

src/DmaTypes.bsv Outdated
@@ -27,12 +21,16 @@ typedef struct {
DMACsrValue value;
} DmaCsrFrame deriving(Bits, Bounded, Eq, FShow);

typedef enum {
DMA_RX, DMA_TX
} TRXDirection deriving(Bits, Eq);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest you deriving FShow whenever possible. It helps print debug info.

return tuple3(concatStream, remainStream, remainBytePtr);
endfunction

function Action showDataStream (DataStream stream);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make DataStreamderiving FShow, and you can simply display it anyware.

And if you insist on using showDataStream , then you may use it many place in your codebase. Why put it in this file?

Copy link
Collaborator Author

@BIGWJZ BIGWJZ Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not notice Fshow before. I will replace showDataStream funciton with it.

endaction;
endfunction

function Action checkDataStream (DataStream stream, String name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above, it's a util function, right?

ByteEn concatByteEnA = streamA.byteEn;

// Fill the high bytes by streamB data
Data concatDataB = streamB.data << bitPtrA;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align them to make the code pretty. I know there are a lot of code to change, but if you make it a habbit, then you will write beautiful code in the future.

    Data     concatDataB     = streamB.data << bitPtrA;
    ByteEn   concatByteEnB   = streamB.byteEn << bytePtrA;
    Data     concatData      = concatDataA | concatDataB;
    ByteEn   concatByteEn    = concatByteEnA | concatByteEnB;

FIFOF#(DataStream) outputFifo <- mkFIFOF;

FIFOF#(StreamWithPtr) prepareFifoA <- mkFIFOF;
FIFOF#(StreamWithPtr) prepareFifoB <- mkFIFOF;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above 5 lines of code looks good.

you may ask why we need to make code pretty. In fact, it's not a problem of pretty or not, but aligned code can make reviewer's life easy. When you will review a lot of code, you will know what it feels like. For better aligned code, you can glimpse the code and won't think much of it, if the code is badly aligned, you brain will take extra effort to "decode" the code you are reading, which will make the reviewer tired for a lot of code to review.

For example, we do not allow to write code inline, and force you to write each element in a new line in an enum or struct. This is because when you are reviewing, your eyes will first look top down, trying to find the boundary of a piece of code. For an if statement, if you write like:

if () begin
    // xxxxx
end
else begin
    // xxxxx
end

you will quickly get the boundary and with a simple glimpse you know the if statement has a else branch. But if you write

if () begin
    // xxxxx
end else begin
    // xxxxx
end

your eyes have to move right a little to find that there is a else statement. This is extra work for your brain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand. I will pay attention to the code format.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this file, and make sure it doesn't go into git commit history.

typedef 64 RQ_DESCRIPTOR_WIDTH;
typedef TDiv#(TSub#(PCIE_AXIS_DATA_WIDTH, RQ_DESCRIPTOR_WIDTH), DWORD_WIDTH) MAX_DWORD_CNT_OF_FIRST;

typedef Bit#(1) ReserveBit1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Reserved package from std lib to represent reserved values.

// Dma To Adapter DataStreams
interface Vector#(DMA_PATH_NUM, FifoIn#(DataStream)) dmaDataFifoIn;
interface Vector#(DMA_PATH_NUM, FifoIn#(SideBandByteEn)) dmaSideBandFifoIn;
// Adapter To Dma StraddleStreams, which may contains 2 TLP
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for different group of interface, add a line of space here will be better.

Reg#(Bool) roundRobinReg <- mkReg(False);

function Bool hasStraddleSpace(DataStream sdStream);
return !unpack(sdStream.byteEn[valueOf(STRADDLE_THRESH_BYTE_WIDTH)]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are functions called msb and lsb to simplify this line of code.

endfunction

function Bool isValidShiftStream(DataStream shiftStream);
Bool valid = !unpack(shiftStream.byteEn[0]) && unpack(shiftStream.byteEn[valueOf(STRADDLE_THRESH_BYTE_WIDTH)]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above.


function RawPcieAxiStreamMaster#(usrWidth) convertRawBusToRawPcieAxiStreamMaster(
RawBusMaster#(PcieAxiStream#(usrWidth)) rawBus
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pay attention to align

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants