/**
 * Dump individual input/output item pair.
 *
 * @s:   pointer to output file
 */
static void smp2p_item(struct seq_file *s, int remote_pid)
{
	struct smp2p_smem *out_ptr;
	struct smp2p_smem *in_ptr;
	struct smp2p_interrupt_config *int_cfg;
	char tmp_buff[64];
	int state;
	int entry;
	struct smp2p_entry_v1 *out_entries = NULL;
	struct smp2p_entry_v1 *in_entries = NULL;
	int out_valid = 0;
	int in_valid = 0;
	char entry_name[SMP2P_MAX_ENTRY_NAME];

	int_cfg = smp2p_get_interrupt_config();
	if (!int_cfg)
		return;
	if (!int_cfg[remote_pid].is_configured &&
			remote_pid != SMP2P_REMOTE_MOCK_PROC)
		return;

	out_ptr = smp2p_get_out_item(remote_pid, &state);
	in_ptr = smp2p_get_in_item(remote_pid);

	if (!out_ptr && !in_ptr)
		return;

	/* print item headers */
	seq_printf(s, "%s%s\n",
		" ====================================== ",
		"======================================");
	scnprintf(tmp_buff, sizeof(tmp_buff),
		"Apps(%d)->%s(%d)",
		SMP2P_APPS_PROC, int_cfg[remote_pid].name, remote_pid);
	seq_printf(s, "| %-37s", tmp_buff);

	scnprintf(tmp_buff, sizeof(tmp_buff),
		"%s(%d)->Apps(%d)",
		int_cfg[remote_pid].name, remote_pid, SMP2P_APPS_PROC);
	seq_printf(s, "| %-37s|\n", tmp_buff);
	seq_printf(s, "%s%s\n",
		" ====================================== ",
		"======================================");

	smp2p_item_header1(tmp_buff, sizeof(tmp_buff), out_ptr, state);
	seq_printf(s, "| %-37s", tmp_buff);
	smp2p_item_header1(tmp_buff, sizeof(tmp_buff), in_ptr, -1);
	seq_printf(s, "| %-37s|\n", tmp_buff);

	smp2p_item_header2(tmp_buff, sizeof(tmp_buff), out_ptr);
	seq_printf(s, "| %-37s", tmp_buff);
	smp2p_item_header2(tmp_buff, sizeof(tmp_buff), in_ptr);
	seq_printf(s, "| %-37s|\n", tmp_buff);

	smp2p_item_header3(tmp_buff, sizeof(tmp_buff), out_ptr);
	seq_printf(s, "| %-37s", tmp_buff);
	smp2p_item_header3(tmp_buff, sizeof(tmp_buff), in_ptr);
	seq_printf(s, "| %-37s|\n", tmp_buff);

	seq_printf(s, " %s%s\n",
		"-------------------------------------- ",
		"--------------------------------------");
	seq_printf(s, "| %-37s",
		"Entry Name       Value");
	seq_printf(s, "| %-37s|\n",
		"Entry Name       Value");
	seq_printf(s, " %s%s\n",
		"-------------------------------------- ",
		"--------------------------------------");

	/* print entries */
	if (out_ptr) {
		out_entries = (struct smp2p_entry_v1 *)((void *)out_ptr +
				sizeof(struct smp2p_smem));
		out_valid = SMP2P_GET_ENT_VALID(out_ptr->valid_total_ent);
	}

	if (in_ptr) {
		in_entries = (struct smp2p_entry_v1 *)((void *)in_ptr +
				sizeof(struct smp2p_smem));
		in_valid = SMP2P_GET_ENT_VALID(in_ptr->valid_total_ent);
	}

	for (entry = 0; out_entries || in_entries; ++entry) {
		if (out_entries && entry < out_valid) {
			memcpy_fromio(entry_name, out_entries->name,
							SMP2P_MAX_ENTRY_NAME);
			scnprintf(tmp_buff, sizeof(tmp_buff),
					"%-16s 0x%08x",
					entry_name,
					out_entries->entry);
			++out_entries;
		} else {
			out_entries = NULL;
			scnprintf(tmp_buff, sizeof(tmp_buff), "None");
		}
		seq_printf(s, "| %-37s", tmp_buff);

		if (in_entries && entry < in_valid) {
			memcpy_fromio(entry_name, in_entries->name,
							SMP2P_MAX_ENTRY_NAME);
			scnprintf(tmp_buff, sizeof(tmp_buff),
					"%-16s 0x%08x",
					entry_name,
					in_entries->entry);
			++in_entries;
		} else {
			in_entries = NULL;
			scnprintf(tmp_buff, sizeof(tmp_buff), "None");
		}
		seq_printf(s, "| %-37s|\n", tmp_buff);
	}
	seq_printf(s, " %s%s\n\n",
		"-------------------------------------- ",
		"--------------------------------------");
}
static void smp2p_ut_remotesubsys_ssr_ack(struct seq_file *s, uint32_t rpid,
		struct smp2p_interrupt_config *int_cfg)
{
	int failed = 0;

	seq_printf(s, "Running %s\n", __func__);
	do {
		struct smp2p_smem *rhdr;
		struct smp2p_smem *lhdr;
		int negotiation_state;
		bool ssr_ack_enabled;
		uint32_t ssr_done_start;

		lhdr = smp2p_get_out_item(rpid, &negotiation_state);
		UT_ASSERT_PTR(NULL, !=, lhdr);
		UT_ASSERT_INT(SMP2P_EDGE_STATE_OPENED, ==, negotiation_state);

		rhdr = smp2p_get_in_item(rpid);
		UT_ASSERT_PTR(NULL, !=, rhdr);

		/*                                */
		if (SMP2P_GET_FEATURES(rhdr->feature_version)
				& SMP2P_FEATURE_SSR_ACK)
			ssr_ack_enabled = true;
		else
			ssr_ack_enabled = false;

		ssr_done_start = SMP2P_GET_RESTART_DONE(rhdr->flags);
		UT_ASSERT_INT(ssr_done_start, ==,
				SMP2P_GET_RESTART_ACK(lhdr->flags));

		/*                 */
		seq_printf(s, "Restarting '%s'\n", int_cfg->name);
		subsystem_restart(int_cfg->name);
		msleep(10*1000);

		/*                      */
		if (ssr_ack_enabled) {
			ssr_done_start ^= 1;
			UT_ASSERT_INT(ssr_done_start, ==,
					SMP2P_GET_RESTART_ACK(lhdr->flags));
			UT_ASSERT_INT(ssr_done_start, ==,
					SMP2P_GET_RESTART_DONE(rhdr->flags));
			UT_ASSERT_INT(0, ==,
					SMP2P_GET_RESTART_DONE(lhdr->flags));
			seq_puts(s, "\tSSR ACK Enabled and Toggled\n");
		} else {
			UT_ASSERT_INT(0, ==,
					SMP2P_GET_RESTART_DONE(lhdr->flags));
			UT_ASSERT_INT(0, ==,
					SMP2P_GET_RESTART_ACK(lhdr->flags));

			UT_ASSERT_INT(0, ==,
					SMP2P_GET_RESTART_DONE(rhdr->flags));
			UT_ASSERT_INT(0, ==,
					SMP2P_GET_RESTART_ACK(rhdr->flags));
			seq_puts(s, "\tSSR ACK Disabled\n");
		}

		seq_puts(s, "\tOK\n");
	} while (0);