cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
port_table.cpp
Go to the documentation of this file.
1 
17 
43 
56 #include "port_table.hpp"
57 
58 using namespace hls;
59 
60 
64 #ifndef __SYNTHESIS__
65  extern bool gTraceEvent;
66 #endif
67 
68 #define THIS_NAME "TOE/PRt"
69 
70 #define TRACE_OFF 0x0000
71 #define TRACE_IRR 1 << 1
72 #define TRACE_ORM 1 << 2
73 #define TRACE_LPT 1 << 3
74 #define TRACE_FPT 1 << 4
75 #define TRACE_RDY 1 << 5
76 #define TRACE_ALL 0xFFFF
77 
78 #define DEBUG_LEVEL (TRACE_OFF)
79 
80 
81 
84 template<class T> void pAnd2(
85  T &pi1,
86  T &pi2,
87  T &po)
88 {
89  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
90  #pragma HLS INLINE off
91 
92  po = pi1 & pi2;
93 }
94 
95 
106 void pReady(
107  StsBool &piLpt_Ready,
108  StsBool &piFpt_Ready,
109  StsBool &poTOE_Ready)
110 {
111  const char *myName = concat3(THIS_NAME, "/", "Rdy");
112 
113  poTOE_Ready = piLpt_Ready and piFpt_Ready;
114 
115  if (DEBUG_LEVEL & TRACE_RDY) {
116  if (poTOE_Ready)
117  printInfo(myName, "Process [PRt] is ready.\n");
118  }
119 }
120 
121 
142  StsBool &poRdy_Ready,
143  stream<TcpPort> &siRAi_OpenLsnPortReq,
144  stream<RepBit> &soRAi_OpenLsnPortRep,
145  stream<TcpStaPort> &siIrr_GetPortStateCmd,
146  stream<RspBit> &soOrm_GetPortStateRsp)
147 {
148  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
149  #pragma HLS PIPELINE II=1 enable_flush
150  #pragma HLS INLINE off
151 
152  const char *myName = concat3(THIS_NAME, "/", "Lpt");
153 
154  //-- STATIC ARRAYS ---------------------------------------------------------
155  static PortState LISTEN_PORT_TABLE[0x8000];
156  #pragma HLS RESOURCE variable=LISTEN_PORT_TABLE core=RAM_T2P_BRAM
157  #pragma HLS DEPENDENCE variable=LISTEN_PORT_TABLE inter false
158 
159  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
160  static bool lpt_isLPtInit=false;
161  #pragma HLS reset variable=lpt_isLPtInit
162  static TcpPort lpt_lsnPortNum=0;
163  #pragma HLS reset variable=lpt_lsnPortNum
164 
165  // This table must be cleared upon reset
166  if (!lpt_isLPtInit) {
167  LISTEN_PORT_TABLE[lpt_lsnPortNum(14, 0)] = STS_CLOSED;
168  lpt_lsnPortNum += 1;
169  if (lpt_lsnPortNum == 0x8000) {
170  lpt_isLPtInit = true;
171  if (DEBUG_LEVEL & TRACE_LPT) {
172  printInfo(myName, "Done with initialization of LISTEN_PORT_TABLE.\n");
173  }
174  }
175  }
176  else {
177  if (!siRAi_OpenLsnPortReq.empty() and !soRAi_OpenLsnPortRep.full()) {
178  siRAi_OpenLsnPortReq.read(lpt_lsnPortNum);
179  // [TODO] Let's add a specific bit to specifically open/close a port.
180  if (lpt_lsnPortNum < 0x8000) {
181  // Listening port number falls in the range [0..32,767]
182  // We can set the listening port table entry to true
183  LISTEN_PORT_TABLE[lpt_lsnPortNum] = STS_OPENED;
184  // Sent reply to RAi
185  soRAi_OpenLsnPortRep.write(STS_OPENED);
186  if (DEBUG_LEVEL & TRACE_LPT)
187  printInfo(myName, "[RAi] is requesting to open port #%d in listen mode.\n",
188  lpt_lsnPortNum.to_uint());
189  }
190  else {
191  soRAi_OpenLsnPortRep.write(STS_CLOSED);
192  }
193  }
194  else if (!siIrr_GetPortStateCmd.empty()) {
195  // Warning: Cannot add "and !soOrm_GetPortStateRsp.full()" here because
196  // it increases the task interval from 1 to 2!
197  TcpStaPort staticPortNum = siIrr_GetPortStateCmd.read();
198  // Sent status of that portNum to Orm
199  soOrm_GetPortStateRsp.write(LISTEN_PORT_TABLE[staticPortNum]);
200  if (DEBUG_LEVEL & TRACE_LPT)
201  printInfo(myName, "[RXe] is querying the state of listen port #%d \n",
202  staticPortNum.to_uint());
203  }
204  }
205  //-- ALWAYS
206  poRdy_Ready = lpt_isLPtInit;
207 }
208 
209 
233  StsBool &poRdy_Ready,
234  stream<TcpPort> &siSLc_CloseActPortCmd,
235  stream<TcpDynPort> &siIrr_GetPortStateCmd,
236  stream<RspBit> &soOrm_GetPortStateRsp,
237  stream<ReqBit> &siTAi_GetFreePortReq,
238  stream<TcpPort> &soTAi_GetFreePortRep)
239 
240 {
241  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
242  #pragma HLS PIPELINE II=1 enable_flush
243  #pragma HLS INLINE off
244 
245  const char *myName = concat3(THIS_NAME, "/", "Fpt");
246 
247  //-- STATIC ARRAYS ---------------------------------------------------------
248  static PortRange ACTIVE_PORT_TABLE[0x8000];
249  #pragma HLS RESOURCE variable=ACTIVE_PORT_TABLE core=RAM_T2P_BRAM
250  #pragma HLS DEPENDENCE variable=ACTIVE_PORT_TABLE inter false
251 
252  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
253  static bool fpt_isFPtInit=false;
254  #pragma HLS reset variable=fpt_isFPtInit
255  static bool fpt_searching=false;
256  #pragma HLS reset variable=fpt_searching
257  static bool fpt_eval=false;
258  #pragma HLS reset variable=fpt_eval
259  static TcpDynPort fpt_dynPortNum=0x7FFF;
260  #pragma HLS reset variable=fpt_dynPortNum
261 
262  //-- STATIC DATAFLOW VARIABLES ---------------------------------------------
263  static bool portState = ACT_USED_PORT;
264  #pragma HLS DEPENDENCE variable=portState inter false
265 
266  // The table is a free list that must be initialized upon reset
267  if (!fpt_isFPtInit) {
268  ACTIVE_PORT_TABLE[fpt_dynPortNum] = ACT_FREE_PORT;
269  fpt_dynPortNum -= 1;
270  if (fpt_dynPortNum == 0) {
271  fpt_isFPtInit = true;
272  if (DEBUG_LEVEL & TRACE_FPT) {
273  printInfo(myName, "Done with initialization of ACTIVE_PORT_TABLE.\n");
274  }
275  }
276  }
277  else {
278  if (fpt_searching) {
279  portState = ACTIVE_PORT_TABLE[fpt_dynPortNum];
280  fpt_searching = false;
281  fpt_eval = true;
282  }
283  else if (fpt_eval) {
284  if (portState == ACT_FREE_PORT) {
285  // Found a free entry port in the table
286  if (!soTAi_GetFreePortRep.full()) {
287  // Stop evaluating. Set port number to USED and forward to [TAi]
288  fpt_eval = false;
289  ACTIVE_PORT_TABLE[fpt_dynPortNum] = ACT_USED_PORT;
290  // Add 0x8000 before sending back
291  soTAi_GetFreePortRep.write(0x8000 + fpt_dynPortNum);
292  }
293  }
294  else {
295  // Continue searching
296  fpt_searching = true;
297  }
298  fpt_dynPortNum++;
299  }
300  else if (!siIrr_GetPortStateCmd.empty()) {
301  // Warning: Cannot add "and !soOrm_GetPortStateRsp.full()" here because
302  // it increases the task interval from 1 to 2!
303  TcpDynPort portNum = siIrr_GetPortStateCmd.read();
304  soOrm_GetPortStateRsp.write(ACTIVE_PORT_TABLE[portNum]);
305  }
306  else if (!siTAi_GetFreePortReq.empty()) {
307  siTAi_GetFreePortReq.read();
308  fpt_searching = true;
309  }
310  else if (!siSLc_CloseActPortCmd.empty()) {
311  TcpPort tcpPort = siSLc_CloseActPortCmd.read();
312  if (tcpPort.bit(15) == 1) {
313  // Assess that port number >= 0x8000
314  ACTIVE_PORT_TABLE[tcpPort.range(14, 0)] = ACT_FREE_PORT;
315  }
316  #ifndef __SYNTHESIS__
317  else {
318  printError(myName, "SLc is not allowed to release a static port.\n");
319  exit(1);
320  }
321  #endif
322  }
323  }
324  // ALWAYS
325  poRdy_Ready = fpt_isFPtInit;
326 }
327 
328 
344  stream<TcpPort> &siRXe_GetPortStateCmd,
345  stream<TcpStaPort> &soLpt_GetLsnPortStateCmd,
346  stream<TcpDynPort> &soFpt_GetActPortStateCmd,
347  stream<PortRange> &soOrm_QueryRange)
348 {
349  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
350  #pragma HLS PIPELINE II=1 enable_flush
351  #pragma HLS INLINE off
352 
353  const char *myName = concat3(THIS_NAME, "/", "Irr");
354 
355  // Forward request according to port number,
356  if (!siRXe_GetPortStateCmd.empty()) {
357  TcpPort portToCheck = siRXe_GetPortStateCmd.read();
358  if (DEBUG_LEVEL & TRACE_IRR) {
359  printInfo(myName, "[RXe] is requesting the state of port #%d.\n", portToCheck.to_int());
360  }
361  if (portToCheck < 0x8000) {
362  // Listening ports are in the range [0x0000..0x7FFF]
363  soLpt_GetLsnPortStateCmd.write(portToCheck.range(14, 0));
364  soOrm_QueryRange.write(LISTEN_PORT);
365  }
366  else {
367  // Active ports are in the range [0x8000..0xFFFF]
368  soFpt_GetActPortStateCmd.write(portToCheck.range(14, 0));
369  soOrm_QueryRange.write(ACTIVE_PORT);
370  }
371  }
372 }
373 
374 
375 
388  stream<PortRange> &siIrr_QueryRange,
389  stream<RspBit> &siLpt_GetLsnPortStateRsp,
390  stream<RspBit> &siFpt_GetActPortStateRsp,
391  stream<RspBit> &soRXe_GetPortStateRsp)
392 {
393  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
394  #pragma HLS PIPELINE II=1 enable_flush
395  #pragma HLS INLINE off
396 
397  //-- STATIC CONTROL VARIABLES (with RESET) ---------------------------------
398  static enum FsmStates { ORM_WAIT_FOR_QUERY_FROM_Irr=0,
399  ORM_FORWARD_LSN_PORT_STATE_RSP,
400  ORM_FORWARD_ACT_PORT_STATE_RSP } orm_fsmState=ORM_WAIT_FOR_QUERY_FROM_Irr;
401 
402  // Read out responses from tables in order and merge them
403  switch (orm_fsmState) {
404  case ORM_WAIT_FOR_QUERY_FROM_Irr:
405  if (!siIrr_QueryRange.empty()) {
406  PortRange qryType = siIrr_QueryRange.read();
407  if (qryType == LISTEN_PORT)
408  orm_fsmState = ORM_FORWARD_LSN_PORT_STATE_RSP;
409  else
410  orm_fsmState = ORM_FORWARD_ACT_PORT_STATE_RSP;
411  }
412  break;
413  case ORM_FORWARD_LSN_PORT_STATE_RSP:
414  if (!siLpt_GetLsnPortStateRsp.empty() and !soRXe_GetPortStateRsp.full()) {
415  soRXe_GetPortStateRsp.write(siLpt_GetLsnPortStateRsp.read());
416  orm_fsmState = ORM_WAIT_FOR_QUERY_FROM_Irr;
417  }
418  break;
419  case ORM_FORWARD_ACT_PORT_STATE_RSP:
420  if (!siFpt_GetActPortStateRsp.empty() and !soRXe_GetPortStateRsp.full()) {
421  soRXe_GetPortStateRsp.write(siFpt_GetActPortStateRsp.read());
422  orm_fsmState = ORM_WAIT_FOR_QUERY_FROM_Irr;
423  }
424  break;
425  }
426 }
427 
428 
454  StsBool &poTOE_Ready,
455  stream<TcpPort> &siRXe_GetPortStateReq,
456  stream<RepBit> &soRXe_GetPortStateRep,
457  stream<TcpPort> &siRAi_OpenLsnPortReq,
458  stream<AckBit> &soRAi_OpenLsnPortAck,
459  stream<ReqBit> &siTAi_GetFreePortReq,
460  stream<TcpPort> &soTAi_GetFreePortRep,
461  stream<TcpPort> &siSLc_CloseActPortCmd)
462 {
463 
464  //-- DIRECTIVES FOR THIS PROCESS -------------------------------------------
465  #pragma HLS INLINE
466 
467  //--------------------------------------------------------------------------
468  //-- LOCAL SIGNALS AND STREAMS
469  //-- (Sorted by the name of the modules which generate them)
470  //--------------------------------------------------------------------------
471 
472  //-- Input Request Router (Irr)
473  static stream<TcpStaPort> ssIrrToLpt_GetLsnPortStateCmd ("ssIrrToLpt_GetLsnPortStateCmd");
474  #pragma HLS STREAM variable=ssIrrToLpt_GetLsnPortStateCmd depth=2
475 
476  static stream<TcpDynPort> ssIrrToFpt_GetActPortStateCmd ("ssIrrToFpt_GetActPortStateCmd");
477  #pragma HLS STREAM variable=ssIrrToFpt_GetActPortStateCmd depth=2
478 
479  static stream<bool> ssIrrToOrm_QueryRange ("ssIrrToOrm_QueryRange");
480  #pragma HLS STREAM variable=ssIrrToOrm_QueryRange depth=4
481 
482  //-- Listening Port Table (Lpt)
483  StsBool sLptToAnd2_Ready;
484  static stream<RspBit> ssLptToOrm_GetLsnPortStateRsp ("ssLptToOrm_GetLsnPortStateRsp");
485  #pragma HLS STREAM variable=ssLptToOrm_GetLsnPortStateRsp depth=2
486 
487  //-- Free Port Table (Fpt)
488  StsBool sFptToAnd2_Ready;
489  static stream<RspBit> ssFptToOrm_GetActPortStateRsp ("ssFptToOrm_GetActPortStateRsp");
490  #pragma HLS STREAM variable=ssFptToOrm_GetActPortStateRsp depth=2
491 
492  //--------------------------------------------------------------------------
493  //-- PROCESS FUNCTIONS
494  //--------------------------------------------------------------------------
495 
497  sLptToAnd2_Ready,
498  siRAi_OpenLsnPortReq,
499  soRAi_OpenLsnPortAck,
500  ssIrrToLpt_GetLsnPortStateCmd,
501  ssLptToOrm_GetLsnPortStateRsp);
502 
504  sFptToAnd2_Ready,
505  siSLc_CloseActPortCmd,
506  ssIrrToFpt_GetActPortStateCmd,
507  ssFptToOrm_GetActPortStateRsp,
508  siTAi_GetFreePortReq,
509  soTAi_GetFreePortRep);
510 
511  // Routes the input requests
513  siRXe_GetPortStateReq,
514  ssIrrToLpt_GetLsnPortStateCmd,
515  ssIrrToFpt_GetActPortStateCmd,
516  ssIrrToOrm_QueryRange);
517 
519  ssIrrToOrm_QueryRange,
520  ssLptToOrm_GetLsnPortStateRsp,
521  ssFptToOrm_GetActPortStateRsp,
522  soRXe_GetPortStateRep);
523 
524  pReady(
525  sLptToAnd2_Ready,
526  sFptToAnd2_Ready,
527  poTOE_Ready);
528 
529 }
530 
bool StsBool
Definition: nal.hpp:246
void pOutputReplyMultiplexer(stream< bool > &siIrr_QueryRange, stream< RspBit > &siLpt_GetLsnPortStateRsp, stream< RspBit > &siFpt_GetActPortStateRsp, stream< RspBit > &soRXe_GetPortStateRsp)
Output Reply Multiplexer (Orm)
Definition: port_table.cpp:387
#define ACTIVE_PORT
Definition: port_table.hpp:69
AckBit PortState
Definition: port_table.hpp:65
#define TRACE_IRR
Definition: port_table.cpp:71
#define PortRange
Definition: port_table.hpp:72
#define LISTEN_PORT
Definition: port_table.hpp:70
void pListeningPortTable(StsBool &poRdy_Ready, stream< TcpPort > &siRAi_OpenLsnPortReq, stream< RepBit > &soRAi_OpenLsnPortRep, stream< TcpStaPort > &siIrr_GetPortStateCmd, stream< RspBit > &soOrm_GetPortStateRsp)
Listening Port Table (Lpt)
Definition: port_table.cpp:141
void port_table(StsBool &poTOE_Ready, stream< TcpPort > &siRXe_GetPortStateReq, stream< RepBit > &soRXe_GetPortStateRep, stream< TcpPort > &siRAi_OpenLsnPortReq, stream< AckBit > &soRAi_OpenLsnPortAck, stream< ReqBit > &siTAi_GetFreePortReq, stream< TcpPort > &soTAi_GetFreePortRep, stream< TcpPort > &siSLc_CloseActPortCmd)
Port Table (PRt)
Definition: port_table.cpp:453
#define ACT_USED_PORT
Definition: port_table.hpp:67
#define ACT_FREE_PORT
Definition: port_table.hpp:66
#define TRACE_RDY
Definition: port_table.cpp:75
ap_uint< 15 > TcpStaPort
Definition: toe.hpp:284
void pReady(StsBool &piLpt_Ready, StsBool &piFpt_Ready, StsBool &poTOE_Ready)
Ready Logic (Rdy)
Definition: port_table.cpp:106
#define TRACE_FPT
Definition: port_table.cpp:74
bool gTraceEvent
Definition: tb_nal.cpp:151
#define THIS_NAME
Definition: port_table.cpp:68
void pAnd2(T &pi1, T &pi2, T &po)
A two inputs 'AND' gate.
Definition: port_table.cpp:84
void pInputRequestRouter(stream< TcpPort > &siRXe_GetPortStateCmd, stream< TcpStaPort > &soLpt_GetLsnPortStateCmd, stream< TcpDynPort > &soFpt_GetActPortStateCmd, stream< bool > &soOrm_QueryRange)
Input Request Router (Irr)
Definition: port_table.cpp:343
#define DEBUG_LEVEL
Definition: port_table.cpp:78
#define TRACE_LPT
Definition: port_table.cpp:73
void pFreePortTable(StsBool &poRdy_Ready, stream< TcpPort > &siSLc_CloseActPortCmd, stream< TcpDynPort > &siIrr_GetPortStateCmd, stream< RspBit > &soOrm_GetPortStateRsp, stream< ReqBit > &siTAi_GetFreePortReq, stream< TcpPort > &soTAi_GetFreePortRep)
Free Port Table (Fpt)
Definition: port_table.cpp:232
ap_uint< 15 > TcpDynPort
Definition: toe.hpp:285
#define printError(callerName, format,...)
A macro to print an error message.
Definition: nts_utils.hpp:195
#define STS_CLOSED
Definition: nts_types.hpp:82
ap_uint< 16 > TcpPort
Definition: AxisTcp.hpp:105
#define STS_OPENED
Definition: nts_types.hpp:81
#define printInfo(callerName, format,...)
A macro to print an information message.
Definition: nts_utils.hpp:169
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
Definition: nts_utils.hpp:161
: Port Table (PRt) of the TCP Offload Engine (TOE)