#include "h/types.h"
#include "h/fddi.h"
#include "h/smc.h"
#include "h/smt_p.h"
#ifndef SLIM_SMT
#ifdef ESS
#ifndef lint
#define LINT_USE(x)
#else
#define LINT_USE(x) (x)=(x)
#endif
#define MS2BCLK(x) ((x)*12500L)
static const u_short plist_raf_alc_res[] = { SMT_P0012, SMT_P320B, SMT_P320F,
SMT_P3210, SMT_P0019, SMT_P001A,
SMT_P001D, 0 } ;
static const u_short plist_raf_chg_req[] = { SMT_P320B, SMT_P320F, SMT_P3210,
SMT_P001A, 0 } ;
static const struct fddi_addr smt_sba_da = {{0x80,0x01,0x43,0x00,0x80,0x0C}} ;
static const struct fddi_addr null_addr = {{0,0,0,0,0,0}} ;
static void ess_send_response(struct s_smc *smc, struct smt_header *sm,
int sba_cmd);
static void ess_config_fifo(struct s_smc *smc);
static void ess_send_alc_req(struct s_smc *smc);
static void ess_send_frame(struct s_smc *smc, SMbuf *mb);
void ess_timer_poll(struct s_smc *smc);
void ess_para_change(struct s_smc *smc);
int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
int fs);
static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead);
int ess_raf_received_pack(struct s_smc *smc, SMbuf *mb, struct smt_header *sm,
int fs)
{
void *p ;
struct smt_p_0016 *cmd ;
SMbuf *db ;
u_long msg_res_type ;
u_long payload, overhead ;
int local ;
int i ;
local = ((fs & L_INDICATOR) != 0) ;
if (!(p = (void *) sm_to_para(smc,sm,SMT_P0015))) {
DB_ESS("ESS: RAF frame error, parameter type not found");
return fs;
}
msg_res_type = ((struct smt_p_0015 *)p)->res_type ;
if (!(cmd = (struct smt_p_0016 *) sm_to_para(smc,sm,SMT_P0016))) {
DB_ESS("ESS: RAF frame error, parameter command not found");
return fs;
}
DB_ESSN(2, "fc %x ft %x", sm->smt_class, sm->smt_type);
DB_ESSN(2, "ver %x tran %x", sm->smt_version, sm->smt_tid);
DB_ESSN(2, "stn_id %pM", &sm->smt_source);
DB_ESSN(2, "infolen %x res %lx", sm->smt_len, msg_res_type);
DB_ESSN(2, "sbacmd %x", cmd->sba_cmd);
switch (cmd->sba_cmd) {
case REQUEST_ALLOCATION :
if (sm->smt_type == SMT_REQUEST) {
if (!local || smc->mib.fddiESSPayload)
return fs;
p = (void *) sm_to_para(smc,sm,SMT_P0019) ;
for (i = 0; i < 5; i++) {
if (((struct smt_p_0019 *)p)->alloc_addr.a[i]) {
return fs;
}
}
smc->ess.alloc_trans_id = sm->smt_tid ;
DB_ESS("ESS: save Alloc Req Trans ID %x", sm->smt_tid);
p = (void *) sm_to_para(smc,sm,SMT_P320F) ;
((struct smt_p_320f *)p)->mib_payload =
smc->mib.a[PATH0].fddiPATHSbaPayload ;
p = (void *) sm_to_para(smc,sm,SMT_P3210) ;
((struct smt_p_3210 *)p)->mib_overhead =
smc->mib.a[PATH0].fddiPATHSbaOverhead ;
sm->smt_dest = smt_sba_da ;
if (smc->ess.local_sba_active)
return fs | I_INDICATOR;
if (!(db = smt_get_mbuf(smc)))
return fs;
db->sm_len = mb->sm_len ;
db->sm_off = mb->sm_off ;
memcpy(((char *)(db->sm_data+db->sm_off)),(char *)sm,
(int)db->sm_len) ;
dump_smt(smc,
(struct smt_header *)(db->sm_data+db->sm_off),
"RAF") ;
smt_send_frame(smc,db,FC_SMT_INFO,0) ;
return fs;
}
if (smt_check_para(smc,sm,plist_raf_alc_res)) {
DB_ESS("ESS: RAF with para problem, ignoring");
return fs;
}
if ((((struct smt_p_320b *)sm_to_para(smc,sm,SMT_P320B))->path_index
!= PRIMARY_RING) ||
(msg_res_type != SYNC_BW) ||
(((struct smt_p_reason *)sm_to_para(smc,sm,SMT_P0012))->rdf_reason
!= SMT_RDF_SUCCESS) ||
(sm->smt_tid != smc->ess.alloc_trans_id)) {
DB_ESS("ESS: Allocation Response not accepted");
return fs;
}
p = (void *) sm_to_para(smc,sm,SMT_P320F) ;
if (!p) {
printk(KERN_ERR "ESS: sm_to_para failed");
return fs;
}
payload = ((struct smt_p_320f *)p)->mib_payload ;
p = (void *) sm_to_para(smc,sm,SMT_P3210) ;
if (!p) {
printk(KERN_ERR "ESS: sm_to_para failed");
return fs;
}
overhead = ((struct smt_p_3210 *)p)->mib_overhead ;
DB_ESSN(2, "payload= %lx overhead= %lx",
payload, overhead);
(void)process_bw_alloc(smc,(long)payload,(long)overhead) ;
return fs;
case CHANGE_ALLOCATION :
if (sm->smt_type != SMT_REQUEST) {
DB_ESS("ESS: Do not process Change Responses");
return fs;
}
if (smt_check_para(smc,sm,plist_raf_chg_req)) {
DB_ESS("ESS: RAF with para problem, ignoring");
return fs;
}
if ((((struct smt_p_320b *)sm_to_para(smc,sm,SMT_P320B))->path_index
!= PRIMARY_RING) || (msg_res_type != SYNC_BW)) {
DB_ESS("ESS: RAF frame with para problem, ignoring");
return fs;
}
p = (void *) sm_to_para(smc,sm,SMT_P320F) ;
payload = ((struct smt_p_320f *)p)->mib_payload ;
p = (void *) sm_to_para(smc,sm,SMT_P3210) ;
overhead = ((struct smt_p_3210 *)p)->mib_overhead ;
DB_ESSN(2, "ESS: Change Request from %pM",
&sm->smt_source);
DB_ESSN(2, "payload= %lx overhead= %lx",
payload, overhead);
if(!process_bw_alloc(smc,(long)payload,(long)overhead))
return fs;
ess_send_response(smc,sm,CHANGE_ALLOCATION) ;
return fs;
case REPORT_ALLOCATION :
if (sm->smt_type != SMT_REQUEST) {
DB_ESS("ESS: Do not process a Report Reply");
return fs;
}
DB_ESSN(2, "ESS: Report Request from %pM",
&sm->smt_source);
if (msg_res_type != SYNC_BW) {
DB_ESS("ESS: ignoring RAF with para problem");
return fs;
}
ess_send_response(smc,sm,REPORT_ALLOCATION) ;
return fs;
default:
DB_ESS("ESS: ignoring RAF with bad sba_cmd");
break ;
}
return fs;
}
static int process_bw_alloc(struct s_smc *smc, long int payload, long int overhead)
{
if (payload > MAX_PAYLOAD || overhead > 5000) {
DB_ESS("ESS: payload / overhead not accepted");
return FALSE;
}
if (smc->mib.fddiESSPayload &&
((u_long)payload != smc->mib.fddiESSPayload ||
(u_long)overhead != smc->mib.fddiESSOverhead)) {
smc->ess.raf_act_timer_poll = TRUE ;
smc->ess.timer_count = 0 ;
}
if (payload) {
DB_ESSN(2, "ESS: turn SMT_ST_SYNC_SERVICE bit on");
smc->ess.sync_bw_available = TRUE ;
smc->ess.sync_bw = overhead -
(long)smc->mib.m[MAC0].fddiMACT_Neg *
payload / 1562 ;
}
else {
DB_ESSN(2, "ESS: turn SMT_ST_SYNC_SERVICE bit off");
smc->ess.sync_bw_available = FALSE ;
smc->ess.sync_bw = 0 ;
overhead = 0 ;
}
smc->mib.a[PATH0].fddiPATHSbaPayload = payload ;
smc->mib.a[PATH0].fddiPATHSbaOverhead = overhead ;
DB_ESSN(2, "tsync = %lx", smc->ess.sync_bw);
ess_config_fifo(smc) ;
set_formac_tsync(smc,smc->ess.sync_bw) ;
return TRUE;
}
static void ess_send_response(struct s_smc *smc, struct smt_header *sm,
int sba_cmd)
{
struct smt_sba_chg *chg ;
SMbuf *mb ;
void *p ;
if (sba_cmd == CHANGE_ALLOCATION) {
if (!(mb=smt_build_frame(smc,SMT_RAF,SMT_REPLY,
sizeof(struct smt_sba_chg))))
return ;
}
else {
if (!(mb=smt_build_frame(smc,SMT_RAF,SMT_REPLY,
sizeof(struct smt_sba_rep_res))))
return ;
}
chg = smtod(mb,struct smt_sba_chg *) ;
chg->smt.smt_tid = sm->smt_tid ;
chg->smt.smt_dest = sm->smt_source ;
chg->s_type.para.p_type = SMT_P0015 ;
chg->s_type.para.p_len = sizeof(struct smt_p_0015) - PARA_LEN ;
chg->s_type.res_type = SYNC_BW ;
chg->cmd.para.p_type = SMT_P0016 ;
chg->cmd.para.p_len = sizeof(struct smt_p_0016) - PARA_LEN ;
chg->cmd.sba_cmd = sba_cmd ;
chg->path.para.p_type = SMT_P320B ;
chg->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
chg->path.mib_index = SBAPATHINDEX ;
chg->path.path_pad = 0;
chg->path.path_index = PRIMARY_RING ;
chg->payload.para.p_type = SMT_P320F ;
chg->payload.para.p_len = sizeof(struct smt_p_320f) - PARA_LEN ;
chg->payload.mib_index = SBAPATHINDEX ;
chg->payload.mib_payload = smc->mib.a[PATH0].fddiPATHSbaPayload ;
chg->overhead.para.p_type = SMT_P3210 ;
chg->overhead.para.p_len = sizeof(struct smt_p_3210) - PARA_LEN ;
chg->overhead.mib_index = SBAPATHINDEX ;
chg->overhead.mib_overhead = smc->mib.a[PATH0].fddiPATHSbaOverhead ;
if (sba_cmd == CHANGE_ALLOCATION) {
chg->cat.para.p_type = SMT_P001A ;
chg->cat.para.p_len = sizeof(struct smt_p_001a) - PARA_LEN ;
p = (void *) sm_to_para(smc,sm,SMT_P001A) ;
chg->cat.category = ((struct smt_p_001a *)p)->category ;
}
dump_smt(smc,(struct smt_header *)chg,"RAF") ;
ess_send_frame(smc,mb) ;
}
void ess_timer_poll(struct s_smc *smc)
{
if (!smc->ess.raf_act_timer_poll)
return ;
DB_ESSN(2, "ESS: timer_poll");
smc->ess.timer_count++ ;
if (smc->ess.timer_count == 10) {
smc->ess.timer_count = 0 ;
ess_send_alc_req(smc) ;
}
}
static void ess_send_alc_req(struct s_smc *smc)
{
struct smt_sba_alc_req *req ;
SMbuf *mb ;
if (!smc->mib.fddiESSPayload) {
smc->mib.fddiESSOverhead = 0 ;
}
else {
if (!smc->mib.fddiESSOverhead)
smc->mib.fddiESSOverhead = DEFAULT_OV ;
}
if (smc->mib.fddiESSOverhead ==
smc->mib.a[PATH0].fddiPATHSbaOverhead &&
smc->mib.fddiESSPayload ==
smc->mib.a[PATH0].fddiPATHSbaPayload){
smc->ess.raf_act_timer_poll = FALSE ;
smc->ess.timer_count = 7 ;
return ;
}
if (!(mb=smt_build_frame(smc,SMT_RAF,SMT_REQUEST,
sizeof(struct smt_sba_alc_req))))
return ;
req = smtod(mb,struct smt_sba_alc_req *) ;
req->smt.smt_tid = smc->ess.alloc_trans_id = smt_get_tid(smc) ;
req->smt.smt_dest = smt_sba_da ;
req->s_type.para.p_type = SMT_P0015 ;
req->s_type.para.p_len = sizeof(struct smt_p_0015) - PARA_LEN ;
req->s_type.res_type = SYNC_BW ;
req->cmd.para.p_type = SMT_P0016 ;
req->cmd.para.p_len = sizeof(struct smt_p_0016) - PARA_LEN ;
req->cmd.sba_cmd = REQUEST_ALLOCATION ;
req->path.para.p_type = SMT_P320B ;
req->path.para.p_len = sizeof(struct smt_p_320b) - PARA_LEN ;
req->path.mib_index = SBAPATHINDEX ;
req->path.path_pad = 0;
req->path.path_index = PRIMARY_RING ;
req->pl_req.para.p_type = SMT_P0017 ;
req->pl_req.para.p_len = sizeof(struct smt_p_0017) - PARA_LEN ;
req->pl_req.sba_pl_req = smc->mib.fddiESSPayload -
smc->mib.a[PATH0].fddiPATHSbaPayload ;
req->ov_req.para.p_type = SMT_P0018 ;
req->ov_req.para.p_len = sizeof(struct smt_p_0018) - PARA_LEN ;
req->ov_req.sba_ov_req = smc->mib.fddiESSOverhead -
smc->mib.a[PATH0].fddiPATHSbaOverhead ;
req->payload.para.p_type = SMT_P320F ;
req->payload.para.p_len = sizeof(struct smt_p_320f) - PARA_LEN ;
req->payload.mib_index = SBAPATHINDEX ;
req->payload.mib_payload = smc->mib.a[PATH0].fddiPATHSbaPayload ;
req->overhead.para.p_type = SMT_P3210 ;
req->overhead.para.p_len = sizeof(struct smt_p_3210) - PARA_LEN ;
req->overhead.mib_index = SBAPATHINDEX ;
req->overhead.mib_overhead = smc->mib.a[PATH0].fddiPATHSbaOverhead ;
req->a_addr.para.p_type = SMT_P0019 ;
req->a_addr.para.p_len = sizeof(struct smt_p_0019) - PARA_LEN ;
req->a_addr.sba_pad = 0;
req->a_addr.alloc_addr = null_addr ;
req->cat.para.p_type = SMT_P001A ;
req->cat.para.p_len = sizeof(struct smt_p_001a) - PARA_LEN ;
req->cat.category = smc->mib.fddiESSCategory ;
req->tneg.para.p_type = SMT_P001B ;
req->tneg.para.p_len = sizeof(struct smt_p_001b) - PARA_LEN ;
req->tneg.max_t_neg = smc->mib.fddiESSMaxTNeg ;
req->segm.para.p_type = SMT_P001C ;
req->segm.para.p_len = sizeof(struct smt_p_001c) - PARA_LEN ;
req->segm.min_seg_siz = smc->mib.fddiESSMinSegmentSize ;
dump_smt(smc,(struct smt_header *)req,"RAF") ;
ess_send_frame(smc,mb) ;
}
static void ess_send_frame(struct s_smc *smc, SMbuf *mb)
{
if (smc->ess.local_sba_active) {
DB_ESS("ESS:Send to the local SBA");
if (!smc->ess.sba_reply_pend)
smc->ess.sba_reply_pend = mb ;
else {
DB_ESS("Frame is lost - another frame was pending");
smt_free_mbuf(smc,mb) ;
}
}
else {
DB_ESS("ESS:Send to the network");
smt_send_frame(smc,mb,FC_SMT_INFO,0) ;
}
}
void ess_para_change(struct s_smc *smc)
{
(void)process_bw_alloc(smc,(long)smc->mib.a[PATH0].fddiPATHSbaPayload,
(long)smc->mib.a[PATH0].fddiPATHSbaOverhead) ;
}
static void ess_config_fifo(struct s_smc *smc)
{
if (smc->mib.a[PATH0].fddiPATHSbaPayload) {
if (smc->hw.fp.fifo.fifo_config_mode & SYNC_TRAFFIC_ON &&
(smc->hw.fp.fifo.fifo_config_mode&SEND_ASYNC_AS_SYNC) ==
smc->mib.fddiESSSynchTxMode) {
return ;
}
}
else {
if (!(smc->hw.fp.fifo.fifo_config_mode & SYNC_TRAFFIC_ON)) {
return ;
}
}
formac_reinit_tx(smc) ;
}
#endif /* ESS */
#endif /* no SLIM_SMT */