Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
x393_sata
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
x393_sata
Commits
428626df
Commit
428626df
authored
Jan 11, 2016
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started fsm for the to ahci module
parent
bd53b296
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
392 additions
and
99 deletions
+392
-99
ahci_fis_receive.v
ahci/ahci_fis_receive.v
+10
-6
ahci_fsm.v
ahci/ahci_fsm.v
+126
-0
ahci_top.v
ahci/ahci_top.v
+175
-87
axi_ahci_regs.v
ahci/axi_ahci_regs.v
+81
-6
No files found.
ahci/ahci_fis_receive.v
View file @
428626df
...
@@ -35,6 +35,7 @@ module ahci_fis_receive#(
...
@@ -35,6 +35,7 @@ module ahci_fis_receive#(
input
hba_rst
,
// @posedge mclk - sync reset
input
hba_rst
,
// @posedge mclk - sync reset
input
mclk
,
// for command/status
input
mclk
,
// for command/status
// Control Interface
// Control Interface
output
reg
fis_first_vld
,
// fis_first contains valid FIS header, reset by get_*
// Receiving FIS
// Receiving FIS
input
get_sig
,
// update signature
input
get_sig
,
// update signature
input
get_dsfis
,
input
get_dsfis
,
...
@@ -44,8 +45,8 @@ module ahci_fis_receive#(
...
@@ -44,8 +45,8 @@ module ahci_fis_receive#(
input
get_ufis
,
input
get_ufis
,
input
get_data_fis
,
input
get_data_fis
,
input
get_ignore
,
// ignore whatever FIS (use for DMA activate too?)
input
get_ignore
,
// ignore whatever FIS (use for DMA activate too?)
output
reg
get_fis_busy
,
// busy processing FIS
output
get_fis_busy
,
// busy processing FIS
output
reg
fis_first_vld
,
// fis_first contains valid FIS header, reset by get_*
output
reg
get_fis_done
,
// done processing FIS (see fis_ok, fis_err, fis_ferr)
output
reg
fis_ok
,
// FIS done, checksum OK reset by starting a new get FIS
output
reg
fis_ok
,
// FIS done, checksum OK reset by starting a new get FIS
output
reg
fis_err
,
// FIS done, checksum ERROR reset by starting a new get FIS
output
reg
fis_err
,
// FIS done, checksum ERROR reset by starting a new get FIS
output
fis_ferr
,
// FIS done, fatal error - FIS too long
output
fis_ferr
,
// FIS done, fatal error - FIS too long
...
@@ -169,6 +170,7 @@ localparam DATA_TYPE_ERR = 3;
...
@@ -169,6 +170,7 @@ localparam DATA_TYPE_ERR = 3;
reg
[
15
:
0
]
tf_err_sts
;
reg
[
15
:
0
]
tf_err_sts
;
reg
update_err_sts_r
;
reg
update_err_sts_r
;
reg
update_prdbc_r
;
reg
update_prdbc_r
;
reg
get_fis_busy_r
;
// Forward data to DMA (dev->mem) engine
// Forward data to DMA (dev->mem) engine
assign
dma_in_valid
=
dma_in_ready
&&
(
hba_data_in_type
==
DATA_TYPE_DMA
)
&&
data_in_ready
&&
!
too_long_err
;
assign
dma_in_valid
=
dma_in_ready
&&
(
hba_data_in_type
==
DATA_TYPE_DMA
)
&&
data_in_ready
&&
!
too_long_err
;
...
@@ -186,7 +188,7 @@ localparam DATA_TYPE_ERR = 3;
...
@@ -186,7 +188,7 @@ localparam DATA_TYPE_ERR = 3;
assign
tfd_err
=
tf_err_sts
[
15
:
8
]
;
assign
tfd_err
=
tf_err_sts
[
15
:
8
]
;
assign
xfer_cntr
=
xfer_cntr_r
[
31
:
2
]
;
assign
xfer_cntr
=
xfer_cntr_r
[
31
:
2
]
;
assign
get_fis_busy
=
get_fis_busy_r
;
always
@
(
posedge
mclk
)
begin
always
@
(
posedge
mclk
)
begin
if
(
hba_rst
||
dma_in_stop
)
dma_in
<=
0
;
if
(
hba_rst
||
dma_in_stop
)
dma_in
<=
0
;
...
@@ -247,9 +249,11 @@ localparam DATA_TYPE_ERR = 3;
...
@@ -247,9 +249,11 @@ localparam DATA_TYPE_ERR = 3;
fis_end_r
<=
{
fis_end_r
[
0
]
,
fis_end_w
};
fis_end_r
<=
{
fis_end_r
[
0
]
,
fis_end_w
};
if
(
hba_rst
)
get_fis_busy
<=
0
;
if
(
hba_rst
)
get_fis_busy_r
<=
0
;
else
if
(
get_fis
)
get_fis_busy
<=
1
;
else
if
(
get_fis
)
get_fis_busy_r
<=
1
;
else
if
(
too_long_err
||
fis_end_w
)
get_fis_busy
<=
0
;
else
if
(
too_long_err
||
fis_end_w
)
get_fis_busy_r
<=
0
;
get_fis_done
<=
get_fis_busy_r
&&
(
too_long_err
||
fis_end_w
)
;
if
(
hba_rst
||
get_fis
)
fis_first_vld
<=
0
;
if
(
hba_rst
||
get_fis
)
fis_first_vld
<=
0
;
else
if
(
is_FIS_HEAD
)
fis_first_vld
<=
1
;
else
if
(
is_FIS_HEAD
)
fis_first_vld
<=
1
;
...
...
ahci/ahci_fsm.v
0 → 100644
View file @
428626df
/*******************************************************************************
* Module: ahci_fsm
* Date:2016-01-10
* Author: andrey
* Description: AHCI host+port0 state machine
*
* Copyright (c) 2016 Elphel, Inc .
* ahci_fsm.v is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ahci_fsm.v is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/> .
*******************************************************************************/
`timescale
1
ns
/
1
ps
module
ahci_fsm
#(
// parameter PREFETCH_ALWAYS = 0,
parameter
READ_REG_LATENCY
=
2
,
// 0 if reg_rdata is available with reg_re/reg_addr, 2 with re/regen
// parameter READ_CT_LATENCY = 1, // 0 if ct_rdata is available with reg_re/reg_addr, 2 with re/regen
parameter
ADDRESS_BITS
=
10
// number of memory address bits - now fixed. Low half - RO/RW/RWC,RW1 (2-cycle write), 2-nd just RW (single-cycle)
)(
input
hba_rst
,
// @posedge mclk
input
mclk
,
// for command/status
// notification from axi_ahci_regs that software has written data to register
input
[
ADDRESS_BITS
-
1
:
0
]
soft_write_addr
,
// register address written by software
input
[
31
:
0
]
soft_write_data
,
// register data written (after applying wstb and type (RO, RW, RWC, RW1)
input
soft_write_en
,
// write enable for data write
// input soft_arst, // reset SATA PHY not relying on SATA clock
// R/W access to AXI/AHCI registers, shared with ahci_fis_receive and ahci_fis_transmit modules
output
[
ADDRESS_BITS
-
1
:
0
]
regs_addr
,
output
regs_we
,
// output [3:0] regs_wstb, Needed?
output
[
1
:
0
]
regs_re
,
// [0] - re, [1] - regen
output
[
31
:
0
]
regs_din
,
input
[
31
:
0
]
regs_dout
,
// direct communication with transposrt, link and phy layers
input
phy_ready
,
// goes up after comreset,cominit, align, ...
// Other signals....
// Communication with ahci_fis_receive (some are unused
input
fis_first_vld
,
// fis_first contains valid FIS header, reset by get_*
// Receiving FIS
output
get_sig
,
// update signature
output
get_dsfis
,
output
get_psfis
,
output
get_rfis
,
output
get_sdbfis
,
output
get_ufis
,
output
get_data_fis
,
output
get_ignore
,
// ignore whatever FIS (use for DMA activate too?)
input
get_fis_busy
,
// busy processing FIS
input
get_fis_done
,
// done processing FIS (see fis_ok, fis_err, fis_ferr)
input
fis_ok
,
// FIS done, checksum OK reset by starting a new get FIS
input
fis_err
,
// FIS done, checksum ERROR reset by starting a new get FIS
input
fis_ferr
,
// FIS done, fatal error - FIS too long
// next commands use register address/data/we for 1 clock cycle - after next to command (commnd - t0, we - t2)
output
update_err_sts
,
// update PxTFD.STS and PxTFD.ERR from the last received regs d2h
output
update_prdbc
,
// update PRDBC in registers
output
clear_bsy_drq
,
// clear PxTFD.STS.BSY and PxTFD.STS.DRQ, update
output
set_bsy
,
// set PxTFD.STS.BSY, update
output
set_sts_7f
,
// set PxTFD.STS = 0x7f, update
output
set_sts_80
,
// set PxTFD.STS = 0x80 (may be combined with set_sts_7f), update
output
decr_dwc
,
// decrement DMA Xfer counter // need pulse to 'update_prdbc' to write to registers
output
[
11
:
2
]
decr_DXC_dw
,
// decrement value (in DWORDs)
input
[
7
:
0
]
tfd_sts
,
// Current PxTFD status field (updated after regFIS and SDB - certain fields)
// tfd_sts[7] - BSY, tfd_sts[4] - DRQ, tfd_sts[0] - ERR
input
[
7
:
0
]
tfd_err
,
// Current PxTFD error field (updated after regFIS and SDB)
input
fis_i
,
// value of "I" field in received regsD2H or SDB FIS
input
sdb_n
,
// value of "N" field in received SDB FIS
input
dma_a
,
// value of "A" field in received DMA Setup FIS
input
dma_d
,
// value of "D" field in received DMA Setup FIS
input
pio_i
,
// value of "I" field in received PIO Setup FIS
input
pio_d
,
// value of "D" field in received PIO Setup FIS
input
[
7
:
0
]
pio_es
,
// value of PIO E_Status
// Using even word count (will be rounded up), partial DWORD (last) will be handled by PRD length if needed
input
[
31
:
2
]
xfer_cntr
,
// transfer counter in words for both DMA (31 bit) and PIO (lower 15 bits), updated after decr_dwc
input
xfer_cntr_zero
,
// valid next cycle
// Communication with ahci_fis_transmit
// Command pulses to execute states
output
fetch_cmd
,
// Enter p:FetchCmd, fetch command header (from the register memory, prefetch command FIS)
// wait for either fetch_cmd_busy == 0 or pCmdToIssue ==1 after fetch_cmd
output
cfis_xmit
,
// transmit command (wait for dma_ct_busy == 0)
output
dx_transmit
,
// send FIS header DWORD, (just 0x46), then forward DMA data
// transmit until error, 2048DWords or pDmaXferCnt
output
atapi_xmit
,
// tarsmit ATAPI command FIS
input
done
,
input
busy
,
output
clearCmdToIssue
,
// From CFIS:SUCCESS
input
pCmdToIssue
,
// AHCI port variable
// output dmaCntrZero, // DMA counter is zero - would be a duplicate to the one in receive module and dwords_sent output
input
fetch_cmd_busy
,
// does not include prefetching CT
output
syncesc_recv
,
// These two inputs interrupt transmit
output
xmit_err
,
//
input
[
1
:
0
]
dx_err
,
// bit 0 - syncesc_recv, 1 - xmit_err (valid @ xmit_err and later, reset by new command)
input
[
15
:
0
]
ch_prdtl
,
// Physical region descriptor table length (in entries, 0 is 0)
input
ch_c
,
// Clear busy upon R_OK for this FIS
input
ch_b
,
// Built-in self test command
input
ch_r
,
// reset - may need to send SYNC escape before this command
input
ch_p
,
// prefetchable - only used with non-zero PRDTL or ATAPI bit set
input
ch_w
,
// Write: system memory -> device
input
ch_a
,
// ATAPI: 1 means device should send PIO setup FIS for ATAPI command
input
[
4
:
0
]
ch_cfl
,
// length of the command FIS in DW, 0 means none. 0 and 1 - illegal,
// maximal is 16 (0x10)
input
[
11
:
2
]
dwords_sent
// number of DWORDs transmitted (up to 2048)
)
;
`include
"includes/ahci_localparams.vh"
// @SuppressThisWarning VEditor : Unused localparams
/*
Notes:
Implement sync esc request/ackn in TL (available in LL)
*/
endmodule
ahci/ahci_top.v
View file @
428626df
This diff is collapsed.
Click to expand it.
ahci/axi_ahci_regs.v
View file @
428626df
...
@@ -39,7 +39,8 @@
...
@@ -39,7 +39,8 @@
module
axi_ahci_regs
#(
module
axi_ahci_regs
#(
// parameter ADDRESS_BITS = 8 // number of memory address bits
// parameter ADDRESS_BITS = 8 // number of memory address bits
parameter
ADDRESS_BITS
=
10
// number of memory address bits - now fixed. Low half - RO/RW/RWC,RW1 (2-cycle write), 2-nd just RW (single-cycle)
parameter
ADDRESS_BITS
=
10
,
// number of memory address bits - now fixed. Low half - RO/RW/RWC,RW1 (2-cycle write), 2-nd just RW (single-cycle)
parameter
HBA_RESET_BITS
=
9
// duration of HBA reset in aclk periods (9: ~10usec)
)(
)(
input
aclk
,
// clock - should be buffered
input
aclk
,
// clock - should be buffered
input
arst
,
// @aclk sync reset, active high
input
arst
,
// @aclk sync reset, active high
...
@@ -84,12 +85,13 @@ module axi_ahci_regs#(
...
@@ -84,12 +85,13 @@ module axi_ahci_regs#(
// 1. Notification of data written @ hba_clk
// 1. Notification of data written @ hba_clk
output
[
ADDRESS_BITS
-
1
:
0
]
soft_write_addr
,
// register address written by software
output
[
ADDRESS_BITS
-
1
:
0
]
soft_write_addr
,
// register address written by software
output
[
31
:
0
]
soft_write_data
,
// register data written (after applying wstb and type (RO, RW, RWC, RW1)
output
[
31
:
0
]
soft_write_data
,
// register data written (after applying wstb and type (RO, RW, RWC, RW1)
output
soft_write_en
,
// write enable for data write
output
soft_write_en
,
// write enable for data write
output
soft_arst
,
// reset SATA PHY not relying on SATA clock
output
hba_arst
,
// hba async reset (currently does ~ the same as port reset)
// TODO: Decode from {bram_addr, ahci_regs_di}, bram_wen_d
output
port_arst
,
// port0 async reset by software
// 2. HBA R/W registers, use hba clock
// 2. HBA R/W registers, use hba clock
input
hba_clk
,
input
hba_clk
,
// SATA clock, now 75MHz
input
hba_rst
,
input
hba_rst
,
// when PLL locked, SATA PHY reset is over, this signal is released
input
[
ADDRESS_BITS
-
1
:
0
]
hba_addr
,
input
[
ADDRESS_BITS
-
1
:
0
]
hba_addr
,
input
hba_we
,
input
hba_we
,
// input [3:0] hba_wstb, Needed?
// input [3:0] hba_wstb, Needed?
...
@@ -97,6 +99,18 @@ module axi_ahci_regs#(
...
@@ -97,6 +99,18 @@ module axi_ahci_regs#(
input
[
31
:
0
]
hba_din
,
input
[
31
:
0
]
hba_din
,
output
[
31
:
0
]
hba_dout
output
[
31
:
0
]
hba_dout
)
;
)
;
`include
"includes/ahci_localparams.vh"
// @SuppressThisWarning VEditor : Unused localparams
/*
localparam GHC__GHC__HR__ADDR = 'h1;
localparam GHC__GHC__HR__MASK = 'h1;
localparam GHC__GHC__HR__DFLT = 'h0;
// RO: Device Detection Initialization
localparam HBA_PORT__PxSCTL__DET__ADDR = 'h4b;
localparam HBA_PORT__PxSCTL__DET__MASK = 'hf;
localparam HBA_PORT__PxSCTL__DET__DFLT = 'h0;
*/
wire
[
ADDRESS_BITS
-
1
:
0
]
bram_waddr
;
wire
[
ADDRESS_BITS
-
1
:
0
]
bram_waddr
;
// wire [ADDRESS_BITS-1:0] pre_awaddr;
// wire [ADDRESS_BITS-1:0] pre_awaddr;
wire
[
ADDRESS_BITS
-
1
:
0
]
bram_raddr
;
wire
[
ADDRESS_BITS
-
1
:
0
]
bram_raddr
;
...
@@ -123,9 +137,19 @@ module axi_ahci_regs#(
...
@@ -123,9 +137,19 @@ module axi_ahci_regs#(
// wire [31:0] wmask = {{8{bram_wstb[3]}},{8{bram_wstb[2]}},{8{bram_wstb[1]}},{8{bram_wstb[0]}}};
// wire [31:0] wmask = {{8{bram_wstb[3]}},{8{bram_wstb[2]}},{8{bram_wstb[1]}},{8{bram_wstb[0]}}};
wire
[
31
:
0
]
wmask
=
{{
8
{
bram_wstb_r
[
3
]
}},{
8
{
bram_wstb_r
[
2
]
}},{
8
{
bram_wstb_r
[
1
]
}},{
8
{
bram_wstb_r
[
0
]
}}};
wire
[
31
:
0
]
wmask
=
{{
8
{
bram_wstb_r
[
3
]
}},{
8
{
bram_wstb_r
[
2
]
}},{
8
{
bram_wstb_r
[
1
]
}},{
8
{
bram_wstb_r
[
0
]
}}};
reg
[
ADDRESS_BITS
-
1
:
0
]
bram_waddr_r
;
reg
[
ADDRESS_BITS
-
1
:
0
]
bram_waddr_r
;
reg
[
HBA_RESET_BITS
-
1
:
0
]
hba_reset_cntr
=
1
;
// time to keep hba_reset_r active after writing to GHC.HR
reg
hba_nrst_r
;
// hba _reset (currently does ~ the same as port reset)
reg
port_nrst_r
;
// port _reset by software
wire
high_sel
=
bram_waddr_r
[
ADDRESS_BITS
-
1
]
;
// high addresses - use single-cycle writes without read-modify-write
wire
high_sel
=
bram_waddr_r
[
ADDRESS_BITS
-
1
]
;
// high addresses - use single-cycle writes without read-modify-write
// assign bram_addr = bram_ren[0] ? bram_raddr : (bram_wen ? bram_waddr : pre_awaddr);
// assign bram_addr = bram_ren[0] ? bram_raddr : (bram_wen ? bram_waddr : pre_awaddr);
assign
bram_addr
=
bram_ren
[
0
]
?
bram_raddr
:
(
bram_wen_r
?
bram_waddr_r
:
bram_waddr
)
;
assign
bram_addr
=
bram_ren
[
0
]
?
bram_raddr
:
(
bram_wen_r
?
bram_waddr_r
:
bram_waddr
)
;
assign
hba_arst
=
!
hba_nrst_r
;
// hba _reset (currently does ~ the same as port reset)
assign
port_arst
=
!
port_nrst_r
;
// port _reset by software
always
@
(
posedge
aclk
)
begin
always
@
(
posedge
aclk
)
begin
if
(
arst
)
write_busy_r
<=
0
;
if
(
arst
)
write_busy_r
<=
0
;
else
if
(
write_start_burst
)
write_busy_r
<=
1
;
else
if
(
write_start_burst
)
write_busy_r
<=
1
;
...
@@ -156,6 +180,57 @@ module axi_ahci_regs#(
...
@@ -156,6 +180,57 @@ module axi_ahci_regs#(
end
end
endgenerate
endgenerate
always
@
(
posedge
aclk
)
begin
if
(
arst
)
hba_reset_cntr
<=
1
;
else
if
(
bram_wen_r
&&
!
high_sel
&&
(
bram_addr
==
GHC__GHC__HR__ADDR
)
&&
(
ahci_regs_di
&
GHC__GHC__HR__MASK
))
hba_reset_cntr
<=
{
HBA_RESET_BITS
{
1'b1
}};
else
if
(
|
hba_reset_cntr
)
hba_reset_cntr
<=
hba_reset_cntr
-
1
;
hba_nrst_r
<=
hba_reset_cntr
==
0
;
if
(
arst
)
port_nrst_r
<=
0
;
else
if
(
bram_wen_r
&&
!
high_sel
&&
(
bram_addr
==
HBA_PORT__PxSCTL__DET__ADDR
)
&&
((
ahci_regs_di
&
HBA_PORT__PxSCTL__DET__MASK
|
1
)
==
HBA_PORT__PxSCTL__DET__MASK
))
port_nrst_r
<=
!
ahci_regs_di
[
0
]
;
// write "1" - reset on, write 0 - reset off
end
/*
Will generate async reset on both HBA reset(for some time) and port reset (until released)
until it is more clear about GTX reset options. Such reset will be applied to both PLL and GTX,
sata_phy_rst_out will be released after the sata clock is stable
output soft_arst, // reset SATA PHY not relying on SATA clock
// TODO: Decode from {bram_addr, ahci_regs_di}, bram_wen_d
input sata_phy_rst_out, // when PLL locked, SATA PHY reset is over, this signal is released
localparam GHC__GHC__HR__ADDR = 'h1;
localparam GHC__GHC__HR__MASK = 'h1;
localparam GHC__GHC__HR__DFLT = 'h0;
reg [HBA_RESET_BITS-1:0] hba_reset_cntr; // time to keep hba_reset_r active after writing to GHC.HR
reg hba_rst_r; // hba reset (currently does ~ the same as port reset)
reg port_rst_r; // port reset by software
.rst (1'b0), // input
.rrst (hba_rst), // input
.wrst (arst), // input
.rclk (hba_clk), // input
.wclk (aclk), // input
.we (bram_wen_r && !high_sel), // input
.re (soft_write_en), // input
.data_in ({bram_addr, ahci_regs_di}), // input[15:0]
.data_out ({soft_write_addr,soft_write_data}), // output[15:0]
.nempty (soft_write_en), // output
.half_empty () // output
// RO: Device Detection Initialization
localparam HBA_PORT__PxSCTL__DET__ADDR = 'h4b;
localparam HBA_PORT__PxSCTL__DET__MASK = 'hf;
localparam HBA_PORT__PxSCTL__DET__DFLT = 'h0;
*/
axibram_write
#(
axibram_write
#(
.
ADDRESS_BITS
(
ADDRESS_BITS
)
.
ADDRESS_BITS
(
ADDRESS_BITS
)
)
axibram_write_i
(
)
axibram_write_i
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment