Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/ntb/test/ntb_tool.c
Show First 20 Lines • Show All 613 Lines • ▼ Show 20 Lines | tool_mw_write_fn(struct sysctl_oid *oidp, struct sysctl_req *req, | ||||
else if (cmd == 'W') | else if (cmd == 'W') | ||||
goto write; | goto write; | ||||
else | else | ||||
goto out; | goto out; | ||||
write: | write: | ||||
data_buf_size = *buf_size; | data_buf_size = *buf_size; | ||||
data_buf = malloc(data_buf_size, M_NTB_TOOL, M_WAITOK | M_ZERO); | data_buf = malloc(data_buf_size, M_NTB_TOOL, M_WAITOK | M_ZERO); | ||||
if (!data_buf) { | |||||
rc = ENOMEM; | |||||
goto out; | |||||
} | |||||
if (s_pflag) | if (s_pflag) | ||||
memset(data_buf, pattern, data_buf_size); | memset(data_buf, pattern, data_buf_size); | ||||
else | else | ||||
arc4rand(data_buf, data_buf_size, 1); | arc4rand(data_buf, data_buf_size, 1); | ||||
memcpy(write_buf + *buf_offset, data_buf, data_buf_size); | memcpy(write_buf + *buf_offset, data_buf, data_buf_size); | ||||
Show All 38 Lines | if (rc) | ||||
device_printf(tc->dev, "Local port sysctl set failed with err=" | device_printf(tc->dev, "Local port sysctl set failed with err=" | ||||
"(%d).\n", rc); | "(%d).\n", rc); | ||||
else | else | ||||
tc->port_no = local_port; | tc->port_no = local_port; | ||||
return (rc); | return (rc); | ||||
} | } | ||||
static int | static void | ||||
tool_init_peers(struct tool_ctx *tc) | tool_init_peers(struct tool_ctx *tc) | ||||
{ | { | ||||
int pidx; | int pidx; | ||||
tc->peer_cnt = ntb_peer_port_count(tc->dev); | tc->peer_cnt = ntb_peer_port_count(tc->dev); | ||||
tc->peers = malloc(tc->peer_cnt * sizeof(*tc->peers), M_NTB_TOOL, | tc->peers = malloc(tc->peer_cnt * sizeof(*tc->peers), M_NTB_TOOL, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
if (tc->peers == NULL) | |||||
return (ENOMEM); | |||||
for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | ||||
tc->peers[pidx].pidx = pidx; | tc->peers[pidx].pidx = pidx; | ||||
tc->peers[pidx].tc = tc; | tc->peers[pidx].tc = tc; | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
static void | static void | ||||
tool_clear_peers(struct tool_ctx *tc) | tool_clear_peers(struct tool_ctx *tc) | ||||
{ | { | ||||
free(tc->peers, M_NTB_TOOL); | free(tc->peers, M_NTB_TOOL); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 307 Lines • ▼ Show 20 Lines | tool_init_mws(struct tool_ctx *tc) | ||||
int widx, pidx, rc; | int widx, pidx, rc; | ||||
/* Initialize inbound memory windows and outbound MWs wrapper */ | /* Initialize inbound memory windows and outbound MWs wrapper */ | ||||
for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | ||||
tc->peers[pidx].inmw_cnt = ntb_mw_count(tc->dev); | tc->peers[pidx].inmw_cnt = ntb_mw_count(tc->dev); | ||||
tc->peers[pidx].inmws = malloc(tc->peers[pidx].inmw_cnt * | tc->peers[pidx].inmws = malloc(tc->peers[pidx].inmw_cnt * | ||||
sizeof(*tc->peers[pidx].inmws), M_NTB_TOOL, | sizeof(*tc->peers[pidx].inmws), M_NTB_TOOL, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
if (tc->peers[pidx].inmws == NULL) | |||||
return (ENOMEM); | |||||
for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) { | for (widx = 0; widx < tc->peers[pidx].inmw_cnt; widx++) { | ||||
mw = &tc->peers[pidx].inmws[widx]; | mw = &tc->peers[pidx].inmws[widx]; | ||||
memset((void *)mw, 0, sizeof(*mw)); | memset((void *)mw, 0, sizeof(*mw)); | ||||
mw->tc = tc; | mw->tc = tc; | ||||
mw->widx = widx; | mw->widx = widx; | ||||
mw->pidx = pidx; | mw->pidx = pidx; | ||||
mw->mw_buf_offset = DEFAULT_MW_OFF; | mw->mw_buf_offset = DEFAULT_MW_OFF; | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | sysctl_peer_spad_handle(SYSCTL_HANDLER_ARGS) | ||||
if (rc == 0) { | if (rc == 0) { | ||||
sscanf(buf, "%i", &bits); | sscanf(buf, "%i", &bits); | ||||
return ntb_peer_spad_write(tc->dev, sidx, bits); | return ntb_peer_spad_write(tc->dev, sidx, bits); | ||||
} | } | ||||
return (rc); | return (rc); | ||||
} | } | ||||
static int | static void | ||||
tool_init_spads(struct tool_ctx *tc) | tool_init_spads(struct tool_ctx *tc) | ||||
{ | { | ||||
int sidx, pidx; | int sidx, pidx; | ||||
/* Initialize inbound scratchpad structures */ | /* Initialize inbound scratchpad structures */ | ||||
tc->inspad_cnt = ntb_spad_count(tc->dev); | tc->inspad_cnt = ntb_spad_count(tc->dev); | ||||
tc->inspads = malloc(tc->inspad_cnt * sizeof(*tc->inspads), M_NTB_TOOL, | tc->inspads = malloc(tc->inspad_cnt * sizeof(*tc->inspads), M_NTB_TOOL, | ||||
M_WAITOK | M_ZERO); | M_WAITOK | M_ZERO); | ||||
if (tc->inspads == NULL) | |||||
return (ENOMEM); | |||||
for (sidx = 0; sidx < tc->inspad_cnt; sidx++) { | for (sidx = 0; sidx < tc->inspad_cnt; sidx++) { | ||||
tc->inspads[sidx].sidx = sidx; | tc->inspads[sidx].sidx = sidx; | ||||
tc->inspads[sidx].pidx = -1; | tc->inspads[sidx].pidx = -1; | ||||
tc->inspads[sidx].tc = tc; | tc->inspads[sidx].tc = tc; | ||||
} | } | ||||
/* Initialize outbound scratchpad structures */ | /* Initialize outbound scratchpad structures */ | ||||
for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | for (pidx = 0; pidx < tc->peer_cnt; pidx++) { | ||||
tc->peers[pidx].outspad_cnt = ntb_spad_count(tc->dev); | tc->peers[pidx].outspad_cnt = ntb_spad_count(tc->dev); | ||||
tc->peers[pidx].outspads = malloc(tc->peers[pidx].outspad_cnt * | tc->peers[pidx].outspads = malloc(tc->peers[pidx].outspad_cnt * | ||||
sizeof(*tc->peers[pidx].outspads), M_NTB_TOOL, M_WAITOK | | sizeof(*tc->peers[pidx].outspads), M_NTB_TOOL, M_WAITOK | | ||||
M_ZERO); | M_ZERO); | ||||
if (tc->peers[pidx].outspads == NULL) | |||||
return (ENOMEM); | |||||
for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) { | for (sidx = 0; sidx < tc->peers[pidx].outspad_cnt; sidx++) { | ||||
tc->peers[pidx].outspads[sidx].sidx = sidx; | tc->peers[pidx].outspads[sidx].sidx = sidx; | ||||
tc->peers[pidx].outspads[sidx].pidx = pidx; | tc->peers[pidx].outspads[sidx].pidx = pidx; | ||||
tc->peers[pidx].outspads[sidx].tc = tc; | tc->peers[pidx].outspads[sidx].tc = tc; | ||||
} | } | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
static void | static void | ||||
tool_clear_spads(struct tool_ctx *tc) | tool_clear_spads(struct tool_ctx *tc) | ||||
{ | { | ||||
int pidx; | int pidx; | ||||
/* Free local inspads. */ | /* Free local inspads. */ | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | ntb_tool_attach(device_t dev) | ||||
struct tool_ctx *tc = device_get_softc(dev); | struct tool_ctx *tc = device_get_softc(dev); | ||||
int rc = 0; | int rc = 0; | ||||
tc->dev = dev; | tc->dev = dev; | ||||
rc = tool_check_ntb(tc); | rc = tool_check_ntb(tc); | ||||
if (rc) | if (rc) | ||||
goto out; | goto out; | ||||
rc = tool_init_peers(tc); | tool_init_peers(tc); | ||||
if (rc) | |||||
goto err_clear_data; | |||||
rc = tool_init_mws(tc); | rc = tool_init_mws(tc); | ||||
if (rc) | if (rc) | ||||
goto err_clear_data; | goto err_clear_data; | ||||
rc = tool_init_spads(tc); | tool_init_spads(tc); | ||||
if (rc) | |||||
goto err_clear_mws; | |||||
rc = tool_init_ntb(tc); | rc = tool_init_ntb(tc); | ||||
if (rc) | if (rc) | ||||
goto err_clear_spads; | goto err_clear_spads; | ||||
tool_setup_sysctl(tc); | tool_setup_sysctl(tc); | ||||
return (0); | return (0); | ||||
err_clear_spads: | err_clear_spads: | ||||
tool_clear_spads(tc); | tool_clear_spads(tc); | ||||
err_clear_mws: | |||||
tool_clear_mws(tc); | tool_clear_mws(tc); | ||||
tool_clear_peers(tc); | tool_clear_peers(tc); | ||||
err_clear_data: | err_clear_data: | ||||
tool_clear_data(tc); | tool_clear_data(tc); | ||||
out: | out: | ||||
device_printf(dev, "ntb_tool attached failed with err=(%d).\n", rc); | device_printf(dev, "ntb_tool attached failed with err=(%d).\n", rc); | ||||
return (rc); | return (rc); | ||||
} | } | ||||
Show All 33 Lines |