9a597eb
From fe6623803d1135fd382146faa847bcdf5dc6abc3 Mon Sep 17 00:00:00 2001
9a597eb
From: Lalit Chandivade <lalit.chandivade@qlogic.com>
9a597eb
Date: Fri, 22 Nov 2013 05:46:13 -0500
9a597eb
Subject: [PATCH] iscsi_tool: Add offload host statistics support.
9a597eb
9a597eb
Signed-off-by: Lalit Chandivade <lalit.chandivade@qlogic.com>
9a597eb
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
9a597eb
---
9a597eb
 include/iscsi_if.h | 116 ++++++++++++++++++++++++-
9a597eb
 usr/iscsi_ipc.h    |   2 +
9a597eb
 usr/iscsiadm.c     | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
9a597eb
 usr/netlink.c      |  47 +++++++++++
9a597eb
 4 files changed, 406 insertions(+), 3 deletions(-)
9a597eb
9a597eb
diff --git a/include/iscsi_if.h b/include/iscsi_if.h
9a597eb
index e59bcd0..9d15811 100644
9a597eb
--- a/include/iscsi_if.h
9a597eb
+++ b/include/iscsi_if.h
9a597eb
@@ -75,8 +75,8 @@ enum iscsi_uevent_e {
9a597eb
 	ISCSI_UEVENT_LOGOUT_FLASHNODE	= UEVENT_BASE + 29,
9a597eb
 	ISCSI_UEVENT_LOGOUT_FLASHNODE_SID	= UEVENT_BASE + 30,
9a597eb
 	ISCSI_UEVENT_SET_CHAP		= UEVENT_BASE + 31,
9a597eb
-
9a597eb
-	ISCSI_UEVENT_MAX		= ISCSI_UEVENT_SET_CHAP,
9a597eb
+	ISCSI_UEVENT_GET_HOST_STATS	= UEVENT_BASE + 32,
9a597eb
+	ISCSI_UEVENT_MAX		= ISCSI_UEVENT_GET_HOST_STATS,
9a597eb
 
9a597eb
 	/* up events */
9a597eb
 	ISCSI_KEVENT_RECV_PDU		= KEVENT_BASE + 1,
9a597eb
@@ -251,6 +251,10 @@ struct iscsi_uevent {
9a597eb
 			uint32_t	host_no;
9a597eb
 			uint32_t	sid;
9a597eb
 		} logout_flashnode_sid;
9a597eb
+		struct msg_get_host_stats {
9a597eb
+			uint32_t	host_no;
9a597eb
+		} get_host_stats;
9a597eb
+
9a597eb
 	} u;
9a597eb
 	union {
9a597eb
 		/* messages k -> u */
9a597eb
@@ -854,4 +858,112 @@ struct iscsi_chap_rec {
9a597eb
 	uint8_t password_length;
9a597eb
 };
9a597eb
 
9a597eb
+#define ISCSI_HOST_STATS_CUSTOM_MAX		32
9a597eb
+#define ISCSI_HOST_STATS_CUSTOM_DESC_MAX	64
9a597eb
+struct iscsi_host_stats_custom {
9a597eb
+	char desc[ISCSI_HOST_STATS_CUSTOM_DESC_MAX];
9a597eb
+	uint64_t value;
9a597eb
+};
9a597eb
+
9a597eb
+/* struct iscsi_offload_host_stats: Host statistics,
9a597eb
+ * Include statistics for MAC, IP, TCP & iSCSI.
9a597eb
+ */
9a597eb
+struct iscsi_offload_host_stats {
9a597eb
+	/* MAC */
9a597eb
+	uint64_t mactx_frames;
9a597eb
+	uint64_t mactx_bytes;
9a597eb
+	uint64_t mactx_multicast_frames;
9a597eb
+	uint64_t mactx_broadcast_frames;
9a597eb
+	uint64_t mactx_pause_frames;
9a597eb
+	uint64_t mactx_control_frames;
9a597eb
+	uint64_t mactx_deferral;
9a597eb
+	uint64_t mactx_excess_deferral;
9a597eb
+	uint64_t mactx_late_collision;
9a597eb
+	uint64_t mactx_abort;
9a597eb
+	uint64_t mactx_single_collision;
9a597eb
+	uint64_t mactx_multiple_collision;
9a597eb
+	uint64_t mactx_collision;
9a597eb
+	uint64_t mactx_frames_dropped;
9a597eb
+	uint64_t mactx_jumbo_frames;
9a597eb
+	uint64_t macrx_frames;
9a597eb
+	uint64_t macrx_bytes;
9a597eb
+	uint64_t macrx_unknown_control_frames;
9a597eb
+	uint64_t macrx_pause_frames;
9a597eb
+	uint64_t macrx_control_frames;
9a597eb
+	uint64_t macrx_dribble;
9a597eb
+	uint64_t macrx_frame_length_error;
9a597eb
+	uint64_t macrx_jabber;
9a597eb
+	uint64_t macrx_carrier_sense_error;
9a597eb
+	uint64_t macrx_frame_discarded;
9a597eb
+	uint64_t macrx_frames_dropped;
9a597eb
+	uint64_t mac_crc_error;
9a597eb
+	uint64_t mac_encoding_error;
9a597eb
+	uint64_t macrx_length_error_large;
9a597eb
+	uint64_t macrx_length_error_small;
9a597eb
+	uint64_t macrx_multicast_frames;
9a597eb
+	uint64_t macrx_broadcast_frames;
9a597eb
+	/* IP */
9a597eb
+	uint64_t iptx_packets;
9a597eb
+	uint64_t iptx_bytes;
9a597eb
+	uint64_t iptx_fragments;
9a597eb
+	uint64_t iprx_packets;
9a597eb
+	uint64_t iprx_bytes;
9a597eb
+	uint64_t iprx_fragments;
9a597eb
+	uint64_t ip_datagram_reassembly;
9a597eb
+	uint64_t ip_invalid_address_error;
9a597eb
+	uint64_t ip_error_packets;
9a597eb
+	uint64_t ip_fragrx_overlap;
9a597eb
+	uint64_t ip_fragrx_outoforder;
9a597eb
+	uint64_t ip_datagram_reassembly_timeout;
9a597eb
+	uint64_t ipv6tx_packets;
9a597eb
+	uint64_t ipv6tx_bytes;
9a597eb
+	uint64_t ipv6tx_fragments;
9a597eb
+	uint64_t ipv6rx_packets;
9a597eb
+	uint64_t ipv6rx_bytes;
9a597eb
+	uint64_t ipv6rx_fragments;
9a597eb
+	uint64_t ipv6_datagram_reassembly;
9a597eb
+	uint64_t ipv6_invalid_address_error;
9a597eb
+	uint64_t ipv6_error_packets;
9a597eb
+	uint64_t ipv6_fragrx_overlap;
9a597eb
+	uint64_t ipv6_fragrx_outoforder;
9a597eb
+	uint64_t ipv6_datagram_reassembly_timeout;
9a597eb
+	/* TCP */
9a597eb
+	uint64_t tcptx_segments;
9a597eb
+	uint64_t tcptx_bytes;
9a597eb
+	uint64_t tcprx_segments;
9a597eb
+	uint64_t tcprx_byte;
9a597eb
+	uint64_t tcp_duplicate_ack_retx;
9a597eb
+	uint64_t tcp_retx_timer_expired;
9a597eb
+	uint64_t tcprx_duplicate_ack;
9a597eb
+	uint64_t tcprx_pure_ackr;
9a597eb
+	uint64_t tcptx_delayed_ack;
9a597eb
+	uint64_t tcptx_pure_ack;
9a597eb
+	uint64_t tcprx_segment_error;
9a597eb
+	uint64_t tcprx_segment_outoforder;
9a597eb
+	uint64_t tcprx_window_probe;
9a597eb
+	uint64_t tcprx_window_update;
9a597eb
+	uint64_t tcptx_window_probe_persist;
9a597eb
+	/* ECC */
9a597eb
+	uint64_t ecc_error_correction;
9a597eb
+	/* iSCSI */
9a597eb
+	uint64_t iscsi_pdu_tx;
9a597eb
+	uint64_t iscsi_data_bytes_tx;
9a597eb
+	uint64_t iscsi_pdu_rx;
9a597eb
+	uint64_t iscsi_data_bytes_rx;
9a597eb
+	uint64_t iscsi_io_completed;
9a597eb
+	uint64_t iscsi_unexpected_io_rx;
9a597eb
+	uint64_t iscsi_format_error;
9a597eb
+	uint64_t iscsi_hdr_digest_error;
9a597eb
+	uint64_t iscsi_data_digest_error;
9a597eb
+	uint64_t iscsi_sequence_error;
9a597eb
+	/*
9a597eb
+	 * iSCSI Custom Host Statistics support, i.e. Transport could
9a597eb
+	 * extend existing host statistics with its own specific statistics
9a597eb
+	 * up to ISCSI_HOST_STATS_CUSTOM_MAX
9a597eb
+	 */
9a597eb
+	uint32_t custom_length;
9a597eb
+	struct iscsi_host_stats_custom custom[0]
9a597eb
+		 __attribute__ ((aligned (sizeof(uint64_t))));
9a597eb
+};
9a597eb
+
9a597eb
 #endif
9a597eb
diff --git a/usr/iscsi_ipc.h b/usr/iscsi_ipc.h
9a597eb
index a32da1c..9d26d54 100644
9a597eb
--- a/usr/iscsi_ipc.h
9a597eb
+++ b/usr/iscsi_ipc.h
9a597eb
@@ -161,6 +161,8 @@ struct iscsi_ipc {
9a597eb
 				  uint32_t flashnode_idx);
9a597eb
 	int (*logout_flash_node_sid) (uint64_t transport_handle,
9a597eb
 				      uint32_t host_no, uint32_t sid);
9a597eb
+	int (*get_host_stats) (uint64_t transport_handle, uint32_t host_no,
9a597eb
+			 char *host_stats);
9a597eb
 };
9a597eb
 
9a597eb
 #endif /* ISCSI_IPC_H */
9a597eb
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
9a597eb
index 045259b..ed2c0c3 100644
9a597eb
--- a/usr/iscsiadm.c
9a597eb
+++ b/usr/iscsiadm.c
9a597eb
@@ -69,7 +69,8 @@ enum iscsiadm_mode {
9a597eb
 	MODE_FW,
9a597eb
 	MODE_PING,
9a597eb
 	MODE_CHAP,
9a597eb
-	MODE_FLASHNODE
9a597eb
+	MODE_FLASHNODE,
9a597eb
+	MODE_HOST_STATS
9a597eb
 };
9a597eb
 
9a597eb
 enum iscsiadm_op {
9a597eb
@@ -137,6 +138,7 @@ iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid
9a597eb
 iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o  operation  ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]\n\
9a597eb
 iscsiadm -m fw [ -d debug_level ] [ -l ]\n\
9a597eb
 iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -x chap_tbl_idx ] ] | [ -C flashnode [ -A portal_type ] [ -x flashnode_idx ] ] ] [ [ -o operation ] [ -n name ] [ -v value ] ] \n\
9a597eb
+iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -o operation ] [ -v chap_tbl_idx ] ] | [ -C flashnode [ -o operation ] [ -A portal_type ] [ -x flashnode_idx ] [ -n name ] [ -v value ] ] | [ -C stats ] ]\n\
9a597eb
 iscsiadm -k priority\n");
9a597eb
 	}
9a597eb
 	exit(status);
9a597eb
@@ -207,6 +209,9 @@ str_to_submode(char *str)
9a597eb
 		sub_mode = MODE_CHAP;
9a597eb
 	else if (!strcmp("flashnode", str))
9a597eb
 		sub_mode = MODE_FLASHNODE;
9a597eb
+	else if (!strcmp("stats", str))
9a597eb
+		sub_mode = MODE_HOST_STATS;
9a597eb
+
9a597eb
 	else
9a597eb
 		sub_mode = -1;
9a597eb
 
9a597eb
@@ -2025,6 +2030,232 @@ exit_flashnode_op:
9a597eb
 	return rc;
9a597eb
 }
9a597eb
 
9a597eb
+static void print_host_stats(struct iscsi_offload_host_stats *host_stats)
9a597eb
+{
9a597eb
+	/* MAC */
9a597eb
+	printf("Host Statistics:\n"
9a597eb
+	       "\tmactx_frames: %lld\n"
9a597eb
+	       "\tmactx_bytes: %lld\n"
9a597eb
+	       "\tmactx_multicast_frames: %lld\n"
9a597eb
+	       "\tmactx_broadcast_frames: %lld\n"
9a597eb
+	       "\tmactx_pause_frames: %lld\n"
9a597eb
+	       "\tmactx_control_frames: %lld\n"
9a597eb
+	       "\tmactx_deferral: %lld\n"
9a597eb
+	       "\tmactx_excess_deferral: %lld\n"
9a597eb
+	       "\tmactx_late_collision: %lld\n"
9a597eb
+	       "\tmactx_abort: %lld\n"
9a597eb
+	       "\tmactx_single_collision: %lld\n"
9a597eb
+	       "\tmactx_multiple_collision: %lld\n"
9a597eb
+	       "\tmactx_collision: %lld\n"
9a597eb
+	       "\tmactx_frames_dropped: %lld\n"
9a597eb
+	       "\tmactx_jumbo_frames: %lld\n"
9a597eb
+	       "\tmacrx_frames: %lld\n"
9a597eb
+	       "\tmacrx_bytes: %lld\n"
9a597eb
+	       "\tmacrx_unknown_control_frames: %lld\n"
9a597eb
+	       "\tmacrx_pause_frames: %lld\n"
9a597eb
+	       "\tmacrx_control_frames: %lld\n"
9a597eb
+	       "\tmacrx_dribble: %lld\n"
9a597eb
+	       "\tmacrx_frame_length_error: %lld\n"
9a597eb
+	       "\tmacrx_jabber: %lld\n"
9a597eb
+	       "\tmacrx_carrier_sense_error: %lld\n"
9a597eb
+	       "\tmacrx_frame_discarded: %lld\n"
9a597eb
+	       "\tmacrx_frames_dropped: %lld\n"
9a597eb
+	       "\tmac_crc_error: %lld\n"
9a597eb
+	       "\tmac_encoding_error: %lld\n"
9a597eb
+	       "\tmacrx_length_error_large: %lld\n"
9a597eb
+	       "\tmacrx_length_error_small: %lld\n"
9a597eb
+	       "\tmacrx_multicast_frames: %lld\n"
9a597eb
+	       "\tmacrx_broadcast_frames: %lld\n"
9a597eb
+	       /* IP */
9a597eb
+	       "\tiptx_packets: %lld\n"
9a597eb
+	       "\tiptx_bytes: %lld\n"
9a597eb
+	       "\tiptx_fragments: %lld\n"
9a597eb
+	       "\tiprx_packets: %lld\n"
9a597eb
+	       "\tiprx_bytes: %lld\n"
9a597eb
+	       "\tiprx_fragments: %lld\n"
9a597eb
+	       "\tip_datagram_reassembly: %lld\n"
9a597eb
+	       "\tip_invalid_address_error: %lld\n"
9a597eb
+	       "\tip_error_packets: %lld\n"
9a597eb
+	       "\tip_fragrx_overlap: %lld\n"
9a597eb
+	       "\tip_fragrx_outoforder: %lld\n"
9a597eb
+	       "\tip_datagram_reassembly_timeout: %lld\n"
9a597eb
+	       "\tipv6tx_packets: %lld\n"
9a597eb
+	       "\tipv6tx_bytes: %lld\n"
9a597eb
+	       "\tipv6tx_fragments: %lld\n"
9a597eb
+	       "\tipv6rx_packets: %lld\n"
9a597eb
+	       "\tipv6rx_bytes: %lld\n"
9a597eb
+	       "\tipv6rx_fragments: %lld\n"
9a597eb
+	       "\tipv6_datagram_reassembly: %lld\n"
9a597eb
+	       "\tipv6_invalid_address_error: %lld\n"
9a597eb
+	       "\tipv6_error_packets: %lld\n"
9a597eb
+	       "\tipv6_fragrx_overlap: %lld\n"
9a597eb
+	       "\tipv6_fragrx_outoforder: %lld\n"
9a597eb
+	       "\tipv6_datagram_reassembly_timeout: %lld\n"
9a597eb
+	       /* TCP */
9a597eb
+	       "\ttcptx_segments: %lld\n"
9a597eb
+	       "\ttcptx_bytes: %lld\n"
9a597eb
+	       "\ttcprx_segments: %lld\n"
9a597eb
+	       "\ttcprx_byte: %lld\n"
9a597eb
+	       "\ttcp_duplicate_ack_retx: %lld\n"
9a597eb
+	       "\ttcp_retx_timer_expired: %lld\n"
9a597eb
+	       "\ttcprx_duplicate_ack: %lld\n"
9a597eb
+	       "\ttcprx_pure_ackr: %lld\n"
9a597eb
+	       "\ttcptx_delayed_ack: %lld\n"
9a597eb
+	       "\ttcptx_pure_ack: %lld\n"
9a597eb
+	       "\ttcprx_segment_error: %lld\n"
9a597eb
+	       "\ttcprx_segment_outoforder: %lld\n"
9a597eb
+	       "\ttcprx_window_probe: %lld\n"
9a597eb
+	       "\ttcprx_window_update: %lld\n"
9a597eb
+	       "\ttcptx_window_probe_persist: %lld\n"
9a597eb
+	       /* ECC */
9a597eb
+	       "\tecc_error_correction: %lld\n"
9a597eb
+	       /* iSCSI */
9a597eb
+	       "\tiscsi_pdu_tx: %lld\n"
9a597eb
+	       "\tiscsi_data_bytes_tx: %lld\n"
9a597eb
+	       "\tiscsi_pdu_rx: %lld\n"
9a597eb
+	       "\tiscsi_data_bytes_rx: %lld\n"
9a597eb
+	       "\tiscsi_io_completed: %lld\n"
9a597eb
+	       "\tiscsi_unexpected_io_rx: %lld\n"
9a597eb
+	       "\tiscsi_format_error: %lld\n"
9a597eb
+	       "\tiscsi_hdr_digest_error: %lld\n"
9a597eb
+	       "\tiscsi_data_digest_error: %lld\n"
9a597eb
+	       "\tiscsi_sequence_error: %lld\n",
9a597eb
+	       /* MAC */
9a597eb
+	       (unsigned long long)host_stats->mactx_frames,
9a597eb
+	       (unsigned long long)host_stats->mactx_bytes,
9a597eb
+	       (unsigned long long)host_stats->mactx_multicast_frames,
9a597eb
+	       (unsigned long long)host_stats->mactx_broadcast_frames,
9a597eb
+	       (unsigned long long)host_stats->mactx_pause_frames,
9a597eb
+	       (unsigned long long)host_stats->mactx_control_frames,
9a597eb
+	       (unsigned long long)host_stats->mactx_deferral,
9a597eb
+	       (unsigned long long)host_stats->mactx_excess_deferral,
9a597eb
+	       (unsigned long long)host_stats->mactx_late_collision,
9a597eb
+	       (unsigned long long)host_stats->mactx_abort,
9a597eb
+	       (unsigned long long)host_stats->mactx_single_collision,
9a597eb
+	       (unsigned long long)host_stats->mactx_multiple_collision,
9a597eb
+	       (unsigned long long)host_stats->mactx_collision,
9a597eb
+	       (unsigned long long)host_stats->mactx_frames_dropped,
9a597eb
+	       (unsigned long long)host_stats->mactx_jumbo_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_bytes,
9a597eb
+	       (unsigned long long)host_stats->macrx_unknown_control_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_pause_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_control_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_dribble,
9a597eb
+	       (unsigned long long)host_stats->macrx_frame_length_error,
9a597eb
+	       (unsigned long long)host_stats->macrx_jabber,
9a597eb
+	       (unsigned long long)host_stats->macrx_carrier_sense_error,
9a597eb
+	       (unsigned long long)host_stats->macrx_frame_discarded,
9a597eb
+	       (unsigned long long)host_stats->macrx_frames_dropped,
9a597eb
+	       (unsigned long long)host_stats->mac_crc_error,
9a597eb
+	       (unsigned long long)host_stats->mac_encoding_error,
9a597eb
+	       (unsigned long long)host_stats->macrx_length_error_large,
9a597eb
+	       (unsigned long long)host_stats->macrx_length_error_small,
9a597eb
+	       (unsigned long long)host_stats->macrx_multicast_frames,
9a597eb
+	       (unsigned long long)host_stats->macrx_broadcast_frames,
9a597eb
+	       /* IP */
9a597eb
+	       (unsigned long long)host_stats->iptx_packets,
9a597eb
+	       (unsigned long long)host_stats->iptx_bytes,
9a597eb
+	       (unsigned long long)host_stats->iptx_fragments,
9a597eb
+	       (unsigned long long)host_stats->iprx_packets,
9a597eb
+	       (unsigned long long)host_stats->iprx_bytes,
9a597eb
+	       (unsigned long long)host_stats->iprx_fragments,
9a597eb
+	       (unsigned long long)host_stats->ip_datagram_reassembly,
9a597eb
+	       (unsigned long long)host_stats->ip_invalid_address_error,
9a597eb
+	       (unsigned long long)host_stats->ip_error_packets,
9a597eb
+	       (unsigned long long)host_stats->ip_fragrx_overlap,
9a597eb
+	       (unsigned long long)host_stats->ip_fragrx_outoforder,
9a597eb
+	       (unsigned long long)host_stats->ip_datagram_reassembly_timeout,
9a597eb
+	       (unsigned long long)host_stats->ipv6tx_packets,
9a597eb
+	       (unsigned long long)host_stats->ipv6tx_bytes,
9a597eb
+	       (unsigned long long)host_stats->ipv6tx_fragments,
9a597eb
+	       (unsigned long long)host_stats->ipv6rx_packets,
9a597eb
+	       (unsigned long long)host_stats->ipv6rx_bytes,
9a597eb
+	       (unsigned long long)host_stats->ipv6rx_fragments,
9a597eb
+	       (unsigned long long)host_stats->ipv6_datagram_reassembly,
9a597eb
+	       (unsigned long long)host_stats->ipv6_invalid_address_error,
9a597eb
+	       (unsigned long long)host_stats->ipv6_error_packets,
9a597eb
+	       (unsigned long long)host_stats->ipv6_fragrx_overlap,
9a597eb
+	       (unsigned long long)host_stats->ipv6_fragrx_outoforder,
9a597eb
+	       (unsigned long long)host_stats->ipv6_datagram_reassembly_timeout,
9a597eb
+	       /* TCP */
9a597eb
+	       (unsigned long long)host_stats->tcptx_segments,
9a597eb
+	       (unsigned long long)host_stats->tcptx_bytes,
9a597eb
+	       (unsigned long long)host_stats->tcprx_segments,
9a597eb
+	       (unsigned long long)host_stats->tcprx_byte,
9a597eb
+	       (unsigned long long)host_stats->tcp_duplicate_ack_retx,
9a597eb
+	       (unsigned long long)host_stats->tcp_retx_timer_expired,
9a597eb
+	       (unsigned long long)host_stats->tcprx_duplicate_ack,
9a597eb
+	       (unsigned long long)host_stats->tcprx_pure_ackr,
9a597eb
+	       (unsigned long long)host_stats->tcptx_delayed_ack,
9a597eb
+	       (unsigned long long)host_stats->tcptx_pure_ack,
9a597eb
+	       (unsigned long long)host_stats->tcprx_segment_error,
9a597eb
+	       (unsigned long long)host_stats->tcprx_segment_outoforder,
9a597eb
+	       (unsigned long long)host_stats->tcprx_window_probe,
9a597eb
+	       (unsigned long long)host_stats->tcprx_window_update,
9a597eb
+	       (unsigned long long)host_stats->tcptx_window_probe_persist,
9a597eb
+	       /* ECC */
9a597eb
+	       (unsigned long long)host_stats->ecc_error_correction,
9a597eb
+	       /* iSCSI */
9a597eb
+	       (unsigned long long)host_stats->iscsi_pdu_tx,
9a597eb
+	       (unsigned long long)host_stats->iscsi_data_bytes_tx,
9a597eb
+	       (unsigned long long)host_stats->iscsi_pdu_rx,
9a597eb
+	       (unsigned long long)host_stats->iscsi_data_bytes_rx,
9a597eb
+	       (unsigned long long)host_stats->iscsi_io_completed,
9a597eb
+	       (unsigned long long)host_stats->iscsi_unexpected_io_rx,
9a597eb
+	       (unsigned long long)host_stats->iscsi_format_error,
9a597eb
+	       (unsigned long long)host_stats->iscsi_hdr_digest_error,
9a597eb
+	       (unsigned long long)host_stats->iscsi_data_digest_error,
9a597eb
+	       (unsigned long long)host_stats->iscsi_sequence_error);
9a597eb
+}
9a597eb
+
9a597eb
+static int exec_host_stats_op(int op, int info_level, uint32_t host_no)
9a597eb
+{
9a597eb
+	struct iscsi_transport *t = NULL;
9a597eb
+	char *req_buf;
9a597eb
+	int rc = ISCSI_SUCCESS;
9a597eb
+	int fd = 0, buf_size = 0;
9a597eb
+
9a597eb
+	t = iscsi_sysfs_get_transport_by_hba(host_no);
9a597eb
+	if (!t) {
9a597eb
+		log_error("Could not match hostno %u to transport.", host_no);
9a597eb
+		rc = ISCSI_ERR_TRANS_NOT_FOUND;
9a597eb
+		goto exit_host_stats;
9a597eb
+	}
9a597eb
+
9a597eb
+	buf_size = sizeof(struct iscsi_offload_host_stats) +
9a597eb
+		   sizeof(struct iscsi_uevent);
9a597eb
+	req_buf = calloc(1, buf_size);
9a597eb
+	if (!req_buf) {
9a597eb
+		log_error("Could not allocate memory for host stats request.");
9a597eb
+		rc = ISCSI_ERR_NOMEM;
9a597eb
+		goto exit_host_stats;
9a597eb
+	}
9a597eb
+
9a597eb
+	fd = ipc->ctldev_open();
9a597eb
+	if (fd < 0) {
9a597eb
+		rc = ISCSI_ERR_INTERNAL;
9a597eb
+		log_error("Netlink open failed.");
9a597eb
+		goto exit_host_stats;
9a597eb
+	}
9a597eb
+
9a597eb
+	rc = ipc->get_host_stats(t->handle, host_no, req_buf);
9a597eb
+	if (rc < 0) {
9a597eb
+		log_error("get_host_stats failed. errno=%d", errno);
9a597eb
+		rc = ISCSI_ERR;
9a597eb
+		goto exit_host_stats;
9a597eb
+	}
9a597eb
+
9a597eb
+	print_host_stats(req_buf + sizeof(struct iscsi_uevent));
9a597eb
+
9a597eb
+	ipc->ctldev_close();
9a597eb
+
9a597eb
+exit_host_stats:
9a597eb
+	if (req_buf)
9a597eb
+		free(req_buf);
9a597eb
+	return rc;
9a597eb
+}
9a597eb
+
9a597eb
 static int verify_iface_params(struct list_head *params, struct node_rec *rec)
9a597eb
 {
9a597eb
 	struct user_param *param;
9a597eb
@@ -3239,6 +3470,17 @@ main(int argc, char **argv)
9a597eb
 						       index, portal_type,
9a597eb
 						       &params);
9a597eb
 				break;
9a597eb
+			case MODE_HOST_STATS:
9a597eb
+				if (!host_no) {
9a597eb
+					log_error("STATS mode requires host no");
9a597eb
+					rc = ISCSI_ERR_INVAL;
9a597eb
+					break;
9a597eb
+				}
9a597eb
+
9a597eb
+				rc = exec_host_stats_op(op, info_level,
9a597eb
+							host_no);
9a597eb
+				break;
9a597eb
+
9a597eb
 			default:
9a597eb
 				log_error("Invalid Sub Mode");
9a597eb
 				break;
9a597eb
diff --git a/usr/netlink.c b/usr/netlink.c
9a597eb
index 151b56d..1c4b5cc 100644
9a597eb
--- a/usr/netlink.c
9a597eb
+++ b/usr/netlink.c
9a597eb
@@ -339,6 +339,10 @@ __kipc_call(struct iovec *iovp, int count)
9a597eb
 		} else if (ev->type == ISCSI_UEVENT_GET_CHAP) {
9a597eb
 			/* kget_chap() will read */
9a597eb
 			return 0;
9a597eb
+		} else if (ev->type == ISCSI_UEVENT_GET_HOST_STATS) {
9a597eb
+			/* kget_host_stats() will read */
9a597eb
+			return 0;
9a597eb
+
9a597eb
 		} else {
9a597eb
 			if ((rc = nlpayload_read(ctrl_fd, (void*)ev,
9a597eb
 						 sizeof(*ev), 0)) < 0) {
9a597eb
@@ -1439,6 +1443,48 @@ klogout_flashnode_sid(uint64_t transport_handle, uint32_t host_no,
9a597eb
 	return 0;
9a597eb
 }
9a597eb
 
9a597eb
+static int kget_host_stats(uint64_t transport_handle, uint32_t host_no,
9a597eb
+		     char *host_stats)
9a597eb
+{
9a597eb
+	int rc = 0;
9a597eb
+	int ev_size;
9a597eb
+	struct iscsi_uevent ev;
9a597eb
+	struct iovec iov[2];
9a597eb
+	char nlm_ev[NLMSG_SPACE(sizeof(struct iscsi_uevent))];
9a597eb
+	struct nlmsghdr *nlh;
9a597eb
+
9a597eb
+	memset(&ev, 0, sizeof(struct iscsi_uevent));
9a597eb
+
9a597eb
+	ev.type = ISCSI_UEVENT_GET_HOST_STATS;
9a597eb
+	ev.transport_handle = transport_handle;
9a597eb
+	ev.u.get_host_stats.host_no = host_no;
9a597eb
+
9a597eb
+	iov[1].iov_base = &ev;
9a597eb
+	iov[1].iov_len = sizeof(ev);
9a597eb
+	rc = __kipc_call(iov, 2);
9a597eb
+	if (rc < 0)
9a597eb
+		return rc;
9a597eb
+
9a597eb
+	if ((rc = nl_read(ctrl_fd, nlm_ev,
9a597eb
+			  NLMSG_SPACE(sizeof(struct iscsi_uevent)),
9a597eb
+			  MSG_PEEK)) < 0) {
9a597eb
+		log_error("can not read nlm_ev, error %d", rc);
9a597eb
+		return rc;
9a597eb
+	}
9a597eb
+
9a597eb
+	nlh = (struct nlmsghdr *)nlm_ev;
9a597eb
+	ev_size = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct nlmsghdr));
9a597eb
+
9a597eb
+	if ((rc = nlpayload_read(ctrl_fd, (void *)host_stats,
9a597eb
+				 ev_size, 0)) < 0) {
9a597eb
+		log_error("can not read from NL socket, error %d", rc);
9a597eb
+		return rc;
9a597eb
+	}
9a597eb
+
9a597eb
+	return rc;
9a597eb
+}
9a597eb
+
9a597eb
+
9a597eb
 static void drop_data(struct nlmsghdr *nlh)
9a597eb
 {
9a597eb
 	int ev_size;
9a597eb
@@ -1737,6 +1783,7 @@ struct iscsi_ipc nl_ipc = {
9a597eb
 	.login_flash_node	= klogin_flashnode,
9a597eb
 	.logout_flash_node	= klogout_flashnode,
9a597eb
 	.logout_flash_node_sid	= klogout_flashnode_sid,
9a597eb
+	.get_host_stats		= kget_host_stats,
9a597eb
 };
9a597eb
 struct iscsi_ipc *ipc = &nl_ipc;
9a597eb
 
9a597eb
-- 
9a597eb
1.8.3.1
9a597eb