* [PATCH RFC 0/6] NCSI Support
@ 2015-11-09 0:10 Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 1/6] net/ncsi: Resource management Gavin Shan
` (6 more replies)
0 siblings, 7 replies; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
This series of patches are prototype requesting for comments. Please focus on
the big picture at current stage, but any comments to improve the implementaion
are welcomed.
The following figure gives an example about how NCSI is deployed: The NCSI is
specified by DSP0222, which can be downloaded from the following link here
(http://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.0.0.pdf).
* The NC-SI (aka NCSI) is defined as the interface between a (Base) Management
Controller (BMC) and one or multiple Network Controlers (NC) on host side.
The interface is responsible for providing external network connectivity
for BMC.
* Each BMC can connect to multiple packages, up to 8. Each package can have
multiple channels, up to 32. Every package and channel are identified by
3-bits and 5-bits in NCSI packet. At one moment, one channel is active to
provide service.
* NCSI packet, encapsulated in ethernet frame, has 0x88F8 in the protocol
field. The destination MAC address should be 0xFF's while the source MAC
address can be arbitrary one.
* NCSI packets are classified to command, response, AEN (Asynchronous Event
Notification). Commands are sent from BMC to host for configuration and
information retrival. Responses, corresponding to commands, are sent from
host to BMC for confirmation and requested information. One command should
have one and only one response. AEN is sent from host to BMC for notification
(e.g. link down on active channel) so that BMC can take appropriate action.
+------------------+ +----------------------------------------------+
| | | Host |
| BMC | | |
| | | +-------------------+ +-------------------+ |
| +---------+ | | | Package-A | | Package-B | |
| | | | | +---------+---------+ +-------------------+ |
| | NIC | | | | Channel | Channel | | Channel | Channel | |
+----+----+----+---+ +-+---------+---------+--+---------+---------+-+
| | |
| | |
+-----------------------------+----------------------+
The design for the patchset is highlighted as below:
* All the code included in this patchset runs on BMC side. The major target
of this patchset is to hide the NCSI details to BMC's NIC driver. The patchset
abstracts a NCSI device (struct ncsi_dev), which is created when the driver
is loaded and the BMC NIC (struct net_device) instance is created. When the
NIC is opened (ndo_open()), all available packages and channels are probed
through NCSI packets. At the same time, one active channel is selected to
provide service. It means the NIC driver can receive/transmit packets before
ndo_open().
* When NCSI device (struct ncsi_dev) is created when NIC driver is loaded,
NCSI protocl handler is added by dev_add_pack() so that the ingress NCSI
packets can be routed to the stack for further processing. On the other
hand, dev_queue_xmit_sk() is called to transmit skb that has been bound
with the BMC's NIC.
* The NCSI device is closed when the BMC's NIC is closed.
* NCSI stack should be configurable through netlink, but it's not implemented
in this patchset. It's something TBD.
* The first NIC driver that is aware of NCSI: drivers/net/ethernet/faraday/ftgmac100.c
Gavin Shan (6):
net/ncsi: Resource management
net/ncsi: Packet handler
net/ncsi: Manage NCSI device
net/faraday: Replace use_nc_si with use_ncsi
net/faraday: Enable NCSI interface
net/faraday: Enable offload checksum according to device-tree
drivers/net/ethernet/faraday/ftgmac100.c | 108 ++-
include/net/ncsi.h | 57 ++
include/uapi/linux/if_ether.h | 1 +
net/Kconfig | 1 +
net/Makefile | 1 +
net/ncsi/Kconfig | 10 +
net/ncsi/Makefile | 5 +
net/ncsi/internal.h | 313 ++++++++
net/ncsi/ncsi-aen.c | 197 +++++
net/ncsi/ncsi-cmd.c | 372 ++++++++++
net/ncsi/ncsi-manage.c | 899 +++++++++++++++++++++++
net/ncsi/ncsi-pkt.h | 391 ++++++++++
net/ncsi/ncsi-rsp.c | 1166 ++++++++++++++++++++++++++++++
13 files changed, 3490 insertions(+), 31 deletions(-)
create mode 100644 include/net/ncsi.h
create mode 100644 net/ncsi/Kconfig
create mode 100644 net/ncsi/Makefile
create mode 100644 net/ncsi/internal.h
create mode 100644 net/ncsi/ncsi-aen.c
create mode 100644 net/ncsi/ncsi-cmd.c
create mode 100644 net/ncsi/ncsi-manage.c
create mode 100644 net/ncsi/ncsi-pkt.h
create mode 100644 net/ncsi/ncsi-rsp.c
--
2.1.0
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH RFC 1/6] net/ncsi: Resource management
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 2/6] net/ncsi: Packet handler Gavin Shan
` (5 subsequent siblings)
6 siblings, 0 replies; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
NCSI spec (DSP0222) defined several objects: package, channel,
mode, filter, version and statistics etc. This defines data
structrues to represent those objects and exports interfaces
(functions) to manage them:
* The user (e.g. netdev driver) dereference NCSI device by
"struct ncsi_dev", which is embedded to "struct ncsi_dev_priv".
The later one is used by NCSI stack internally.
* Every NCSI device can have multiple packages simultaneously,
up to 8 packages. It's represented by "struct ncsi_package"
and identified by 3-bits ID.
* Every NCSI package can have multiple channels, up to 32. It's
represented by "struct ncsi_channel" and identified by 5-bits
ID.
* Every NCSI channel has version, statistics, various modes and
filters. They're represented by "struct ncsi_channel_version",
"struct ncsi_channel_stats", "struct ncsi_channel_mode" and
"struct ncsi_channel_filter" separately.
* The NCSI stack works in terms of command and response. One
command, sent over interface to target package/channel, is
expected to have a response. The same 8-bits ID are put into
the command and response. This patch abstracts the pair of
command and response by "struct ncsi_req".
* "struct ncsi_cmd_arg" is used to tell the specific command
to be sent over NCSI interface.
This also introduces CONFIG_NET_NCSI to enable NCSI stack.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
include/net/ncsi.h | 30 ++++
net/Kconfig | 1 +
net/Makefile | 1 +
net/ncsi/Kconfig | 10 ++
net/ncsi/Makefile | 4 +
net/ncsi/internal.h | 306 +++++++++++++++++++++++++++++++++++++++++
net/ncsi/ncsi-manage.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 715 insertions(+)
create mode 100644 include/net/ncsi.h
create mode 100644 net/ncsi/Kconfig
create mode 100644 net/ncsi/Makefile
create mode 100644 net/ncsi/internal.h
create mode 100644 net/ncsi/ncsi-manage.c
diff --git a/include/net/ncsi.h b/include/net/ncsi.h
new file mode 100644
index 0000000..2735f19
--- /dev/null
+++ b/include/net/ncsi.h
@@ -0,0 +1,30 @@
+#ifndef __NET_NCSI_H
+#define __NET_NCSI_H
+
+/*
+ * The NCSI device states seen from external. More NCSI device states are
+ * only visible internally (in net/ncsi/internal.h). When the NCSI device
+ * is registered, it's in ncsi_dev_state_registered state. The state
+ * ncsi_dev_state_start is used to drive to choose active package and
+ * channel. After that, its state is changed to ncsi_dev_state_functional.
+ *
+ * The state ncsi_dev_state_stop helps to shut down the currently active
+ * package and channel while ncsi_dev_state_config helps to reconfigure
+ * them.
+ */
+enum {
+ ncsi_dev_state_registered = 0x0000,
+ ncsi_dev_state_functional = 0x0100,
+ ncsi_dev_state_start = 0x0200,
+ ncsi_dev_state_config = 0x0300,
+ ncsi_dev_state_stop = 0x0400
+};
+
+struct ncsi_dev {
+ int nd_state;
+ int nd_link_up;
+ struct net_device *nd_dev;
+ void (*nd_handler)(struct ncsi_dev *ndev);
+};
+
+#endif /* __NET_NCSI_H */
diff --git a/net/Kconfig b/net/Kconfig
index 57a7c5a..a92fc73 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -232,6 +232,7 @@ source "net/netlink/Kconfig"
source "net/mpls/Kconfig"
source "net/hsr/Kconfig"
source "net/switchdev/Kconfig"
+source "net/ncsi/Kconfig"
config RPS
bool
diff --git a/net/Makefile b/net/Makefile
index 3995613..9c1d4b1 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -74,3 +74,4 @@ obj-$(CONFIG_HSR) += hsr/
ifneq ($(CONFIG_NET_SWITCHDEV),)
obj-y += switchdev/
endif
+obj-$(CONFIG_NET_NCSI) += ncsi/
diff --git a/net/ncsi/Kconfig b/net/ncsi/Kconfig
new file mode 100644
index 0000000..723f0eb
--- /dev/null
+++ b/net/ncsi/Kconfig
@@ -0,0 +1,10 @@
+#
+# Configuration for NCSI support
+#
+
+config NET_NCSI
+ bool "NCSI interface support (EXPERIMENTAL)"
+ depends on INET
+ ---help---
+ This module provides NCSI (Network Controller Sideband Interface)
+ support.
diff --git a/net/ncsi/Makefile b/net/ncsi/Makefile
new file mode 100644
index 0000000..07b5625
--- /dev/null
+++ b/net/ncsi/Makefile
@@ -0,0 +1,4 @@
+#
+# Makefile for NCSI API
+#
+obj-$(CONFIG_NET_NCSI) += ncsi-manage.o
diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
new file mode 100644
index 0000000..958fd69
--- /dev/null
+++ b/net/ncsi/internal.h
@@ -0,0 +1,306 @@
+#ifndef __NCSI_INTERNAL_H__
+#define __NCSI_INTERNAL_H__
+
+/* NCSI channel capabilities */
+enum {
+ NCSI_CAP_BASE = 0,
+ NCSI_CAP_GENERIC = 0,
+ NCSI_CAP_BC,
+ NCSI_CAP_MC,
+ NCSI_CAP_BUFFER,
+ NCSI_CAP_AEN,
+ NCSI_CAP_VLAN,
+ NCSI_CAP_MAX
+};
+
+enum {
+ NCSI_CAP_GENERIC_HWA = 0x01, /* HW arbitration */
+ NCSI_CAP_GENERIC_HDS = 0x02, /* HNC driver status change */
+ NCSI_CAP_GENERIC_FC = 0x04, /* HNC to MC flow control */
+ NCSI_CAP_GENERIC_FC1 = 0x08, /* MC to HNC flow control */
+ NCSI_CAP_GENERIC_MC = 0x10, /* Global multicast filtering */
+ NCSI_CAP_GENERIC_MASK = 0x1f,
+ NCSI_CAP_BC_ARP = 0x01, /* ARP packet filtering */
+ NCSI_CAP_BC_DHCPC = 0x02, /* DHCP client filtering */
+ NCSI_CAP_BC_DHCPS = 0x04, /* DHCP server filtering */
+ NCSI_CAP_BC_NETBIOS = 0x08, /* NetBIOS packet filtering */
+ NCSI_CAP_BC_MASK = 0x0f,
+ NCSI_CAP_MC_NEIGHBOR = 0x01, /* IPv6 neighbor filtering */
+ NCSI_CAP_MC_ROUTER = 0x02, /* IPv6 router filering */
+ NCSI_CAP_MC_DHCPv6 = 0x04, /* DHCPv6 filtering */
+ NCSI_CAP_MC_MASK = 0x07,
+ NCSI_CAP_AEN_LSC = 0x01, /* Link status change AEN */
+ NCSI_CAP_AEN_CR = 0x02, /* Configuration required AEN */
+ NCSI_CAP_AEN_HDS = 0x04, /* HNC driver status AEN */
+ NCSI_CAP_AEN_MASK = 0x07,
+ NCSI_CAP_VLAN_ONLY = 0x01, /* VLAN is supported */
+ NCSI_CAP_VLAN_NO = 0x02, /* Filter VLAN and non-VLAN */
+ NCSI_CAP_VLAN_ANY = 0x04, /* Filter Any-and-non-VLAN */
+ NCSI_CAP_VLAN_MASK = 0x07
+};
+
+/* NCSI channel mode */
+enum {
+ NCSI_MODE_BASE = 0,
+ NCSI_MODE_ENABLE = 0, /* Channel enabled or disabled */
+ NCSI_MODE_TX_ENABLE, /* Tx enabled or disabled */
+ NCSI_MODE_LINK, /* Link mode */
+ NCSI_MODE_VLAN, /* VLAN filtering mode */
+ NCSI_MODE_BC, /* Broadcom filtering mode */
+ NCSI_MODE_MC, /* Multicast filtering mode */
+ NCSI_MODE_AEN, /* AEN enabled or disabled */
+ NCSI_MODE_FC, /* Flow control mode */
+ NCSI_MODE_MAX
+};
+
+/* NCSI channel filters */
+enum {
+ NCSI_FILTER_BASE = 0,
+ NCSI_FILTER_VLAN = 0,
+ NCSI_FILTER_UC,
+ NCSI_FILTER_MC,
+ NCSI_FILTER_MIXED,
+ NCSI_FILTER_MAX
+};
+
+/* NCSI channel version */
+struct ncsi_channel_version {
+ unsigned int ncv_version; /* BCD encoded NCSI version */
+ unsigned int ncv_alpha2; /* BCD encoded NCSI version */
+ unsigned char ncv_fw_name[12]; /* Firware name string */
+ unsigned int ncv_fw_version; /* Firmware version */
+ unsigned short ncv_pci_ids[4]; /* PCI identification */
+ unsigned int ncv_mf_id; /* Manufacture ID */
+};
+
+/* NCSI channel capability */
+struct ncsi_channel_cap {
+ unsigned int ncc_cap; /* NCSI channel capability */
+};
+
+/* NCSI channel mode */
+struct ncsi_channel_mode {
+ unsigned int ncm_enable; /* Enabled or disabled */
+ unsigned int ncm_size; /* Valid entries in ncm_data[] */
+ unsigned int ncm_data[8]; /* Specific data for the mode */
+};
+
+/*
+ * NCSI channel filter. According to NCSI spec, the total number
+ * of filters can't exceed 32. So it's enough to use 32 bits to
+ * track their usage
+ */
+struct ncsi_channel_filter {
+ unsigned int ncf_total; /* Total entries in the filter table */
+ unsigned int ncf_entry_size; /* Number of bytes per entry */
+ unsigned int ncf_bitmap; /* Bitmap of valid entries */
+ unsigned char ncf_data[]; /* Data for the valid entries */
+};
+
+/* NCSI channel statistics */
+struct ncsi_channel_stats {
+ unsigned int ncs_hnc_cnt_hi; /* Counter cleared */
+ unsigned int ncs_hnc_cnt_lo; /* Counter cleared */
+ unsigned int ncs_hnc_rx_bytes; /* Rx bytes */
+ unsigned int ncs_hnc_tx_bytes; /* Tx bytes */
+ unsigned int ncs_hnc_rx_uc_pkts; /* Rx UC packets */
+ unsigned int ncs_hnc_rx_mc_pkts; /* Rx MC packets */
+ unsigned int ncs_hnc_rx_bc_pkts; /* Rx BC packets */
+ unsigned int ncs_hnc_tx_uc_pkts; /* Tx UC packets */
+ unsigned int ncs_hnc_tx_mc_pkts; /* Tx MC packets */
+ unsigned int ncs_hnc_tx_bc_pkts; /* Tx BC packets */
+ unsigned int ncs_hnc_fcs_err; /* FCS errors */
+ unsigned int ncs_hnc_align_err; /* Alignment errors */
+ unsigned int ncs_hnc_false_carrier; /* False carrier detection */
+ unsigned int ncs_hnc_runt_pkts; /* Rx runt packets */
+ unsigned int ncs_hnc_jabber_pkts; /* Rx jabber packets */
+ unsigned int ncs_hnc_rx_pause_xon; /* Rx pause XON frames */
+ unsigned int ncs_hnc_rx_pause_xoff; /* Rx XOFF frames */
+ unsigned int ncs_hnc_tx_pause_xon; /* Tx XON frames */
+ unsigned int ncs_hnc_tx_pause_xoff; /* Tx XOFF frames */
+ unsigned int ncs_hnc_tx_s_collision; /* Single collision frames */
+ unsigned int ncs_hnc_tx_m_collision; /* Multiple collision frames */
+ unsigned int ncs_hnc_l_collision; /* Late collision frames */
+ unsigned int ncs_hnc_e_collision; /* Excessive collision frames */
+ unsigned int ncs_hnc_rx_ctl_frames; /* Rx control frames */
+ unsigned int ncs_hnc_rx_64_frames; /* Rx 64-bytes frames */
+ unsigned int ncs_hnc_rx_127_frames; /* Rx 65-127 bytes frames */
+ unsigned int ncs_hnc_rx_255_frames; /* Rx 128-255 bytes frames */
+ unsigned int ncs_hnc_rx_511_frames; /* Rx 256-511 bytes frames */
+ unsigned int ncs_hnc_rx_1023_frames; /* Rx 512-1023 bytes frames */
+ unsigned int ncs_hnc_rx_1522_frames; /* Rx 1024-1522 bytes frames */
+ unsigned int ncs_hnc_rx_9022_frames; /* Rx 1523-9022 bytes frames */
+ unsigned int ncs_hnc_tx_64_frames; /* Tx 64-bytes frames */
+ unsigned int ncs_hnc_tx_127_frames; /* Tx 65-127 bytes frames */
+ unsigned int ncs_hnc_tx_255_frames; /* Tx 128-255 bytes frames */
+ unsigned int ncs_hnc_tx_511_frames; /* Tx 256-511 bytes frames */
+ unsigned int ncs_hnc_tx_1023_frames; /* Tx 512-1023 bytes frames */
+ unsigned int ncs_hnc_tx_1522_frames; /* Tx 1024-1522 bytes frames */
+ unsigned int ncs_hnc_tx_9022_frames; /* Tx 1523-9022 bytes frames */
+ unsigned int ncs_hnc_rx_valid_bytes; /* Rx valid bytes */
+ unsigned int ncs_hnc_rx_runt_pkts; /* Rx error runt packets */
+ unsigned int ncs_hnc_rx_jabber_pkts; /* Rx error jabber packets */
+ unsigned int ncs_ncsi_rx_cmds; /* Rx NCSI commands */
+ unsigned int ncs_ncsi_dropped_cmds; /* Dropped commands */
+ unsigned int ncs_ncsi_cmd_type_errs; /* Command type errors */
+ unsigned int ncs_ncsi_cmd_csum_errs; /* Command checksum errors */
+ unsigned int ncs_ncsi_rx_pkts; /* Rx NCSI packets */
+ unsigned int ncs_ncsi_tx_pkts; /* Tx NCSI packets */
+ unsigned int ncs_ncsi_tx_aen_pkts; /* Tx AEN packets */
+ unsigned int ncs_pt_tx_pkts; /* Tx packets */
+ unsigned int ncs_pt_tx_dropped; /* Tx dropped packets */
+ unsigned int ncs_pt_tx_channel_err; /* Tx channel errors */
+ unsigned int ncs_pt_tx_us_err; /* Tx undersize errors */
+ unsigned int ncs_pt_rx_pkts; /* Rx packets */
+ unsigned int ncs_pt_rx_dropped; /* Rx dropped packets */
+ unsigned int ncs_pt_rx_channel_err; /* Rx channel errors */
+ unsigned int ncs_pt_rx_us_err; /* Rx undersize errors */
+ unsigned int ncs_pt_rx_os_err; /* Rx oversize errors */
+};
+
+/* NCSI channel state */
+enum {
+ ncsi_channel_state_deselected_initial,
+ ncsi_channel_state_selected_initial,
+ ncsi_channel_state_deselected_ready,
+ ncsi_channel_state_selected_ready,
+};
+
+struct ncsi_package;
+struct ncsi_dev_priv;
+struct ncsi_channel {
+ unsigned char nc_id;
+ int nc_state;
+ struct ncsi_package *nc_package;
+ struct ncsi_channel_version nc_version;
+ struct ncsi_channel_cap nc_caps[NCSI_CAP_MAX];
+ struct ncsi_channel_mode nc_modes[NCSI_MODE_MAX];
+ struct ncsi_channel_filter *nc_filters[NCSI_FILTER_MAX];
+ struct ncsi_channel_stats nc_stats;
+ struct list_head nc_node;
+};
+
+struct ncsi_package {
+ unsigned char np_id;
+ struct ncsi_dev_priv *np_ndp;
+ atomic_t np_channel_num;
+ spinlock_t np_channel_lock;
+ struct list_head np_channels;
+ struct list_head np_node;
+};
+
+struct ncsi_req {
+ unsigned char nr_id;
+ bool nr_used;
+ struct ncsi_dev_priv *nr_ndp;
+ struct sk_buff *nr_cmd;
+ struct sk_buff *nr_rsp;
+ struct timer_list nr_timer;
+ bool nr_timer_enabled;
+};
+
+/*
+ * The NCSI device state is made up of major and minor states.
+ * The major state is driven by the public APIs. The minor states
+ * are for internal usage to complete the function in that API.
+ */
+enum {
+ ncsi_dev_state_major = 0xff00,
+ ncsi_dev_state_minor = 0x00ff,
+ ncsi_dev_state_start_deselect = 0x0201,
+ ncsi_dev_state_start_package,
+ ncsi_dev_state_start_channel,
+ ncsi_dev_state_start_sp,
+ ncsi_dev_state_start_cis,
+ ncsi_dev_state_start_gvi,
+ ncsi_dev_state_start_gc,
+ ncsi_dev_state_start_dp,
+ ncsi_dev_state_start_active,
+ ncsi_dev_state_config_sp = 0x0301,
+ ncsi_dev_state_config_cis,
+ ncsi_dev_state_config_sma,
+ ncsi_dev_state_config_ebf,
+ ncsi_dev_state_config_ecnt,
+ ncsi_dev_state_config_ec,
+ ncsi_dev_state_config_gls,
+ ncsi_dev_state_config_done,
+ ncsi_dev_state_stop_select = 0x0401,
+ ncsi_dev_state_stop_dcnt,
+ ncsi_dev_state_stop_dc,
+ ncsi_dev_state_stop_deselect,
+ ncsi_dev_state_stop_done
+};
+
+struct ncsi_dev_priv {
+ struct ncsi_dev ndp_ndev;
+#define NCSI_DEV_FLAG_CHANGE_ACTIVE 0x1
+ int ndp_flags;
+ struct ncsi_package *ndp_active_package;
+ struct ncsi_channel *ndp_active_channel;
+ atomic_t ndp_package_num;
+ spinlock_t ndp_package_lock;
+ struct list_head ndp_packages;
+ atomic_t ndp_pending_reqs;
+ atomic_t ndp_last_req_idx;
+ spinlock_t ndp_req_lock;
+#define NCSI_DEV_MAX_REQ 256
+ struct ncsi_req ndp_reqs[NCSI_DEV_MAX_REQ];
+ struct work_struct ndp_work;
+ struct packet_type ndp_ptype;
+ struct list_head ndp_node;
+};
+
+struct ncsi_cmd_arg {
+ struct ncsi_dev_priv *nca_ndp;
+ unsigned char nca_type;
+ unsigned char nca_id;
+ unsigned char nca_package;
+ unsigned char nca_channel;
+ unsigned short nca_payload;
+ unsigned int nca_portid;
+ union {
+ unsigned char nca_bytes[16];
+ unsigned short nca_words[8];
+ unsigned int nca_dwords[4];
+ };
+};
+
+extern struct net *ncsi_net;
+extern struct list_head ncsi_dev_list;
+extern spinlock_t ncsi_dev_lock;
+
+#define NCSI_PACKAGE_INDEX(c) (((c) >> 5) & 0x7)
+#define NCSI_CHANNEL_INDEX(c) ((c) & 0x1ffff)
+#define NCSI_TO_CHANNEL(p, c) ((((p) & 0x7) << 5) | ((c) & 0x1ffff))
+
+#define TO_NCSI_DEV_PRIV(nd) \
+ container_of(nd, struct ncsi_dev_priv, ndp_ndev)
+#define NCSI_FOR_EACH_DEV(ndp) \
+ list_for_each_entry_rcu(ndp, &ncsi_dev_list, ndp_node)
+#define NCSI_FOR_EACH_PACKAGE(ndp, np) \
+ list_for_each_entry_rcu(np, &ndp->ndp_packages, np_node)
+#define NCSI_FOR_EACH_CHANNEL(np, nc) \
+ list_for_each_entry_rcu(nc, &np->np_channels, nc_node)
+
+/* Resource management */
+int ncsi_find_channel_filter(struct ncsi_channel *nc, int table, void *data);
+int ncsi_add_channel_filter(struct ncsi_channel *nc, int table, void *data);
+int ncsi_del_channel_filter(struct ncsi_channel *nc, int table, int index);
+struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np,
+ unsigned char id);
+struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
+ unsigned char id);
+struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
+ unsigned char id);
+struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
+ unsigned char id);
+void ncsi_release_package(struct ncsi_package *np);
+void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
+ unsigned char id,
+ struct ncsi_package **np,
+ struct ncsi_channel **nc);
+struct ncsi_req *ncsi_alloc_req(struct ncsi_dev_priv *ndp);
+void ncsi_free_req(struct ncsi_req *nr, bool check, bool timeout);
+struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
+
+#endif /* __NCSI_INTERNAL_H__ */
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
new file mode 100644
index 0000000..eb23222
--- /dev/null
+++ b/net/ncsi/ncsi-manage.c
@@ -0,0 +1,363 @@
+/*
+ * Copyright Gavin Shan, IBM Corporation 2015.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/netlink.h>
+
+#include <net/ncsi.h>
+#include <net/net_namespace.h>
+#include <net/sock.h>
+
+#include "internal.h"
+
+LIST_HEAD(ncsi_dev_list);
+DEFINE_SPINLOCK(ncsi_dev_lock);
+
+int ncsi_find_channel_filter(struct ncsi_channel *nc, int table, void *data)
+{
+ struct ncsi_channel_filter *ncf;
+ int idx, entry_size;
+ void *bitmap;
+
+ switch (table) {
+ case NCSI_FILTER_VLAN:
+ entry_size = 2;
+ break;
+ case NCSI_FILTER_UC:
+ case NCSI_FILTER_MC:
+ case NCSI_FILTER_MIXED:
+ entry_size = 6;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* Check if the filter table has been initialized */
+ ncf = nc->nc_filters[table];
+ if (!ncf)
+ return -ENODEV;
+
+ /* Check the valid entries one by one */
+ bitmap = (void *)&ncf->ncf_bitmap;
+ idx = -1;
+ while ((idx = find_next_bit(bitmap, ncf->ncf_total, idx+1))
+ < ncf->ncf_total) {
+ if (!memcmp(ncf->ncf_data + entry_size * idx, data, entry_size))
+ return idx;
+ }
+
+ return -ENOENT;
+}
+
+int ncsi_add_channel_filter(struct ncsi_channel *nc, int table, void *data)
+{
+ struct ncsi_channel_filter *ncf;
+ int idx, entry_size;
+ void *bitmap;
+
+ /* Needn't add it if it's already existing */
+ idx = ncsi_find_channel_filter(nc, table, data);
+ if (idx >= 0)
+ return idx;
+
+ switch (table) {
+ case NCSI_FILTER_VLAN:
+ entry_size = 2;
+ break;
+ case NCSI_FILTER_UC:
+ case NCSI_FILTER_MC:
+ case NCSI_FILTER_MIXED:
+ entry_size = 6;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* Check if the filter table has been initialized */
+ ncf = nc->nc_filters[table];
+ if (!ncf)
+ return -ENODEV;
+
+ /* Propagate the filter */
+ bitmap = (void *)&ncf->ncf_bitmap;
+ do {
+ idx = find_next_zero_bit(bitmap, ncf->ncf_total, 0);
+ if (idx >= ncf->ncf_total)
+ return -ENOSPC;
+ } while (test_and_set_bit(idx, bitmap));
+
+ memcpy(ncf->ncf_data + entry_size * idx, data, entry_size);
+ return idx;
+}
+
+int ncsi_del_channel_filter(struct ncsi_channel *nc, int table, int index)
+{
+ struct ncsi_channel_filter *ncf;
+ int entry_size;
+ void *bitmap;
+
+ switch (table) {
+ case NCSI_FILTER_VLAN:
+ entry_size = 2;
+ break;
+ case NCSI_FILTER_UC:
+ case NCSI_FILTER_MC:
+ case NCSI_FILTER_MIXED:
+ entry_size = 6;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* Check if the filter table has been initialized */
+ ncf = nc->nc_filters[table];
+ if (!ncf || index >= ncf->ncf_total)
+ return -ENODEV;
+
+ /* Check if the entry is valid */
+ bitmap = (void *)&ncf->ncf_bitmap;
+ if (test_and_clear_bit(index, bitmap))
+ memset(ncf->ncf_data + entry_size * index, 0, entry_size);
+
+ return 0;
+}
+
+struct ncsi_channel *ncsi_add_channel(struct ncsi_package *np, unsigned char id)
+{
+ struct ncsi_channel *nc, *tmp;
+
+ nc = kzalloc(sizeof(*nc), GFP_ATOMIC);
+ if (!nc) {
+ pr_warn("%s: Out of memory !\n", __func__);
+ return NULL;
+ }
+
+ nc->nc_package = np;
+ nc->nc_id = id;
+
+ spin_lock(&np->np_channel_lock);
+ tmp = ncsi_find_channel(np, id);
+ if (tmp) {
+ spin_unlock(&np->np_channel_lock);
+ kfree(nc);
+ return tmp;
+ }
+ list_add_tail_rcu(&nc->nc_node, &np->np_channels);
+ spin_unlock(&np->np_channel_lock);
+
+ atomic_inc(&np->np_channel_num);
+ return nc;
+}
+
+struct ncsi_channel *ncsi_find_channel(struct ncsi_package *np,
+ unsigned char id)
+{
+ struct ncsi_channel *nc;
+
+ NCSI_FOR_EACH_CHANNEL(np, nc) {
+ if (nc->nc_id == id)
+ return nc;
+ }
+
+ return NULL;
+}
+
+static void ncsi_release_channel(struct ncsi_channel *nc)
+{
+ struct ncsi_dev_priv *ndp = nc->nc_package->np_ndp;
+ struct ncsi_package *np = nc->nc_package;
+ struct ncsi_channel_filter *ncf;
+ int i;
+
+ /* Release filters */
+ for (i = 0; i < NCSI_FILTER_MAX; i++) {
+ ncf = nc->nc_filters[i];
+ if (!ncf)
+ continue;
+
+ nc->nc_filters[i] = NULL;
+ kfree(ncf);
+ }
+
+ /* Update active channel if necessary */
+ if (ndp->ndp_active_channel == nc) {
+ ndp->ndp_active_package = NULL;
+ ndp->ndp_active_channel = NULL;
+ }
+
+ /* Remove and free channel */
+ list_del_rcu(&nc->nc_node);
+ kfree(nc);
+ BUG_ON(atomic_dec_return(&np->np_channel_num) < 0);
+}
+
+struct ncsi_package *ncsi_add_package(struct ncsi_dev_priv *ndp,
+ unsigned char id)
+{
+ struct ncsi_package *np, *tmp;
+
+ np = kzalloc(sizeof(*np), GFP_ATOMIC);
+ if (!np) {
+ pr_warn("%s: Out of memory !\n", __func__);
+ return NULL;
+ }
+
+ np->np_id = id;
+ np->np_ndp = ndp;
+ spin_lock_init(&np->np_channel_lock);
+ INIT_LIST_HEAD(&np->np_channels);
+
+ spin_lock(&ndp->ndp_package_lock);
+ tmp = ncsi_find_package(ndp, id);
+ if (tmp) {
+ spin_unlock(&ndp->ndp_package_lock);
+ kfree(np);
+ return tmp;
+ }
+ list_add_tail_rcu(&np->np_node, &ndp->ndp_packages);
+ spin_unlock(&ndp->ndp_package_lock);
+
+ atomic_inc(&ndp->ndp_package_num);
+ return np;
+}
+
+struct ncsi_package *ncsi_find_package(struct ncsi_dev_priv *ndp,
+ unsigned char id)
+{
+ struct ncsi_package *np;
+
+ NCSI_FOR_EACH_PACKAGE(ndp, np) {
+ if (np->np_id == id)
+ return np;
+ }
+
+ return NULL;
+}
+
+void ncsi_release_package(struct ncsi_package *np)
+{
+ struct ncsi_dev_priv *ndp = np->np_ndp;
+ struct ncsi_channel *nc, *tmp;
+
+ /* Release all child channels */
+ spin_lock(&np->np_channel_lock);
+ list_for_each_entry_safe(nc, tmp, &np->np_channels, nc_node)
+ ncsi_release_channel(nc);
+ spin_unlock(&np->np_channel_lock);
+
+ /* Clear active package if necessary */
+ if (ndp->ndp_active_package == np) {
+ ndp->ndp_active_package = NULL;
+ ndp->ndp_active_channel = NULL;
+ }
+
+ /* Remove and free package */
+ list_del_rcu(&np->np_node);
+ kfree(np);
+
+ /* Decrease number of packages */
+ BUG_ON(atomic_dec_return(&ndp->ndp_package_num) < 0);
+}
+
+void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
+ unsigned char id,
+ struct ncsi_package **np,
+ struct ncsi_channel **nc)
+{
+ struct ncsi_package *p;
+ struct ncsi_channel *c;
+
+ p = ncsi_find_package(ndp, NCSI_PACKAGE_INDEX(id));
+ c = p ? ncsi_find_channel(p, NCSI_CHANNEL_INDEX(id)) : NULL;
+
+ if (np)
+ *np = p;
+ if (nc)
+ *nc = c;
+}
+
+/*
+ * For two consective NCSI commands, the packet IDs shouldn't be
+ * same. Otherwise, the bogus response might be replied. So the
+ * available IDs are allocated in round-robin fasion.
+ */
+struct ncsi_req *ncsi_alloc_req(struct ncsi_dev_priv *ndp)
+{
+ struct ncsi_req *nr = NULL;
+ int idx, limit = 256;
+
+ spin_lock(&ndp->ndp_req_lock);
+
+ /* Check if there is one available request until the ceiling */
+ for (idx = atomic_read(&ndp->ndp_last_req_idx);
+ !nr && idx < limit; idx++) {
+ if (ndp->ndp_reqs[idx].nr_used)
+ continue;
+
+ ndp->ndp_reqs[idx].nr_used = true;
+ nr = &ndp->ndp_reqs[idx];
+ atomic_inc(&ndp->ndp_last_req_idx);
+ if (atomic_read(&ndp->ndp_last_req_idx) >= limit)
+ atomic_set(&ndp->ndp_last_req_idx, 0);
+ }
+
+ /* Fail back to check from the starting cursor */
+ for (idx = 0; !nr && idx < atomic_read(&ndp->ndp_last_req_idx); idx++) {
+ if (ndp->ndp_reqs[idx].nr_used)
+ continue;
+
+ ndp->ndp_reqs[idx].nr_used = true;
+ nr = &ndp->ndp_reqs[idx];
+ atomic_inc(&ndp->ndp_last_req_idx);
+ if (atomic_read(&ndp->ndp_last_req_idx) >= limit)
+ atomic_set(&ndp->ndp_last_req_idx, 0);
+ }
+
+ spin_unlock(&ndp->ndp_req_lock);
+ return nr;
+}
+
+void ncsi_free_req(struct ncsi_req *nr, bool check, bool timeout)
+{
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct sk_buff *cmd, *rsp;
+
+ if (nr->nr_timer_enabled) {
+ nr->nr_timer_enabled = false;
+ del_timer_sync(&nr->nr_timer);
+ }
+
+ spin_lock(&ndp->ndp_req_lock);
+ cmd = nr->nr_cmd;
+ rsp = nr->nr_rsp;
+ nr->nr_cmd = NULL;
+ nr->nr_rsp = NULL;
+ nr->nr_used = false;
+ spin_unlock(&ndp->ndp_req_lock);
+
+ /* Release command and response */
+ consume_skb(cmd);
+ consume_skb(rsp);
+}
+
+struct ncsi_dev *ncsi_find_dev(struct net_device *dev)
+{
+ struct ncsi_dev_priv *ndp;
+
+ NCSI_FOR_EACH_DEV(ndp) {
+ if (ndp->ndp_ndev.nd_dev == dev)
+ return &ndp->ndp_ndev;
+ }
+
+ return NULL;
+}
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH RFC 2/6] net/ncsi: Packet handler
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 1/6] net/ncsi: Resource management Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:41 ` Benjamin Herrenschmidt
2015-11-09 0:10 ` [PATCH RFC 3/6] net/ncsi: Manage NCSI device Gavin Shan
` (4 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
NCSI packet encapsulated in ethernet frame is recognized by the
protocol field (0x88F8) of the ethernet frame header. According
to NCSI spec, the destination MAC field should be 0xFF's, but the
source MAC field could be arbitrary one since channel field in NCSI
header indicates the originator of the packet.
There are 3 types of packets depending on the type field in the NCSI
packet header: command, response, Asynchronous Event Notification
(AEN). The command packets, sent from BMC to NCSI package/channel,
carries configuration or asks for status to/from the target. The
NCSI package/channel should produce response packets when receiving
command packets. Command and response packets are associated with
8-bits ID included in NCSI packets. On the other hand, AEN packets
are sent from NCSI package/channel to BMC for purpose of notificaton
so that BMC can takes corresponding actions like failover of NCSI
active channels.
This implements the functions to handle above 3 types of NCSI packets.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
include/uapi/linux/if_ether.h | 1 +
net/ncsi/Makefile | 3 +-
net/ncsi/internal.h | 6 +
net/ncsi/ncsi-aen.c | 194 +++++++
net/ncsi/ncsi-cmd.c | 372 +++++++++++++
net/ncsi/ncsi-pkt.h | 391 ++++++++++++++
net/ncsi/ncsi-rsp.c | 1166 +++++++++++++++++++++++++++++++++++++++++
7 files changed, 2132 insertions(+), 1 deletion(-)
create mode 100644 net/ncsi/ncsi-aen.c
create mode 100644 net/ncsi/ncsi-cmd.c
create mode 100644 net/ncsi/ncsi-pkt.h
create mode 100644 net/ncsi/ncsi-rsp.c
diff --git a/include/uapi/linux/if_ether.h b/include/uapi/linux/if_ether.h
index aa63ed0..db85863 100644
--- a/include/uapi/linux/if_ether.h
+++ b/include/uapi/linux/if_ether.h
@@ -85,6 +85,7 @@
#define ETH_P_8021AH 0x88E7 /* 802.1ah Backbone Service Tag */
#define ETH_P_MVRP 0x88F5 /* 802.1Q MVRP */
#define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */
+#define ETH_P_NCSI 0x88F8 /* NCSI protocol */
#define ETH_P_PRP 0x88FB /* IEC 62439-3 PRP/HSRv0 */
#define ETH_P_FCOE 0x8906 /* Fibre Channel over Ethernet */
#define ETH_P_TDLS 0x890D /* TDLS */
diff --git a/net/ncsi/Makefile b/net/ncsi/Makefile
index 07b5625..e4094c2 100644
--- a/net/ncsi/Makefile
+++ b/net/ncsi/Makefile
@@ -1,4 +1,5 @@
#
# Makefile for NCSI API
#
-obj-$(CONFIG_NET_NCSI) += ncsi-manage.o
+obj-$(CONFIG_NET_NCSI) += ncsi-cmd.o ncsi-rsp.o ncsi-aen.o \
+ ncsi-manage.o
diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index 958fd69..41e91d8 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -303,4 +303,10 @@ struct ncsi_req *ncsi_alloc_req(struct ncsi_dev_priv *ndp);
void ncsi_free_req(struct ncsi_req *nr, bool check, bool timeout);
struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
+/* Packet handlers */
+int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
+int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
+ struct packet_type *pt, struct net_device *orig_dev);
+int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb);
+
#endif /* __NCSI_INTERNAL_H__ */
diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
new file mode 100644
index 0000000..9078c3b
--- /dev/null
+++ b/net/ncsi/ncsi-aen.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright Gavin Shan, IBM Corporation 2015.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+
+#include <net/ncsi.h>
+#include <net/net_namespace.h>
+#include <net/sock.h>
+
+#include "internal.h"
+#include "ncsi-pkt.h"
+
+static int ncsi_validate_aen_pkt(struct ncsi_aen_pkt_hdr *h,
+ const unsigned short payload)
+{
+ unsigned char *stream;
+ __be32 *checksum, csum;
+ __be32 high, low;
+ int i;
+
+ if (h->common.revision != NCSI_PKT_REVISION)
+ return -EINVAL;
+ if (ntohs(h->common.length) != payload)
+ return -EINVAL;
+
+ /*
+ * Validate checksum, which might be zeroes if the
+ * sender doesn't support checksum according to NCSI
+ * specification.
+ */
+ checksum = (__be32 *)((void *)(h + 1) + payload - 4);
+ if (ntohl(*checksum) == 0)
+ return 0;
+
+ csum = 0;
+ stream = (unsigned char *)h;
+ for (i = 0; i < sizeof(*h) + payload - 4; i += 2) {
+ high = stream[i];
+ low = stream[i + 1];
+ csum += ((high << 8) | low);
+ }
+
+ csum = ~csum + 1;
+ if (*checksum != htonl(csum))
+ return -EINVAL;
+
+ return 0;
+}
+
+static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
+ struct ncsi_aen_pkt_hdr *h)
+{
+ struct ncsi_aen_lsc_pkt *lsc;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_aen_pkt(h, 12);
+ if (ret)
+ return ret;
+
+ /* Find the NCSI channel */
+ ncsi_find_package_and_channel(ndp, h->common.channel, NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update the link status */
+ ncm = &nc->nc_modes[NCSI_MODE_LINK];
+ lsc = (struct ncsi_aen_lsc_pkt *)h;
+ ncm->ncm_data[2] = ntohl(lsc->status);
+ ncm->ncm_data[4] = ntohl(lsc->oem_status);
+ if (!ndp->ndp_active_channel ||
+ ndp->ndp_active_channel != nc ||
+ ncm->ncm_data[2] & 0x1)
+ return 0;
+
+ /* If this channel is the active one and the link is down,
+ * we have to choose another channel to be active one.
+ */
+ ndp->ndp_flags |= NCSI_DEV_FLAG_CHANGE_ACTIVE;
+ /* FIXME: Stop active channel and choose another one */
+
+ return 0;
+}
+
+static int ncsi_aen_handler_cr(struct ncsi_dev_priv *ndp,
+ struct ncsi_aen_pkt_hdr *h)
+{
+ struct ncsi_channel *nc;
+ int ret;
+
+ ret = ncsi_validate_aen_pkt(h, 4);
+ if (ret)
+ return ret;
+
+ /* Find the NCSI channel */
+ ncsi_find_package_and_channel(ndp, h->common.channel, NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* If the channel is active one, we need reconfigure it */
+ if (!ndp->ndp_active_channel ||
+ ndp->ndp_active_channel != nc)
+ return 0;
+
+ /* FIXME: Reconfigure active channel */
+
+ return 0;
+}
+
+static int ncsi_aen_handler_hncdsc(struct ncsi_dev_priv *ndp,
+ struct ncsi_aen_pkt_hdr *h)
+{
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ struct ncsi_aen_hncdsc_pkt *hncdsc;
+ int ret;
+
+ ret = ncsi_validate_aen_pkt(h, 4);
+ if (ret)
+ return ret;
+
+ /* Find the NCSI channel */
+ ncsi_find_package_and_channel(ndp, h->common.channel, NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* If the channel is active one, we need reconfigure it */
+ ncm = &nc->nc_modes[NCSI_MODE_LINK];
+ hncdsc = (struct ncsi_aen_hncdsc_pkt *)h;
+ ncm->ncm_data[3] = ntohl(hncdsc->status);
+ if (ndp->ndp_active_channel != nc ||
+ ncm->ncm_data[3] & 0x1)
+ return 0;
+
+ /* If this channel is the active one and the link doesn't
+ * work, we have to choose another channel to be active one.
+ * The logic here is exactly similar to what we do when link
+ * is down on the active channel.
+ */
+ ndp->ndp_flags |= NCSI_DEV_FLAG_CHANGE_ACTIVE;
+ /* FIXME: Stop and choose another channel as active one */
+
+ return 0;
+}
+
+static struct ncsi_aen_handler {
+ unsigned char nah_type;
+ int (*nah_handler)(struct ncsi_dev_priv *ndp,
+ struct ncsi_aen_pkt_hdr *h);
+} ncsi_aen_handlers[] = {
+ { NCSI_PKT_AEN_LSC, ncsi_aen_handler_lsc },
+ { NCSI_PKT_AEN_CR, ncsi_aen_handler_cr },
+ { NCSI_PKT_AEN_HNCDSC, ncsi_aen_handler_hncdsc },
+ { 0, NULL }
+};
+
+int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb)
+{
+ struct ncsi_aen_pkt_hdr *h;
+ struct ncsi_aen_handler *nah;
+ int ret;
+
+ /* Find the handler */
+ h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb);
+ nah = ncsi_aen_handlers;
+ while (nah->nah_handler) {
+ if (nah->nah_type == h->type)
+ break;
+
+ nah++;
+ }
+
+ if (!nah->nah_handler) {
+ pr_warn("NCSI: Received unrecognized AEN packet (0x%x)\n",
+ h->type);
+ return -ENOENT;
+ }
+
+ ret = nah->nah_handler(ndp, h);
+ consume_skb(skb);
+
+ return ret;
+}
diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c
new file mode 100644
index 0000000..51ec4cd
--- /dev/null
+++ b/net/ncsi/ncsi-cmd.c
@@ -0,0 +1,372 @@
+/*
+ * Copyright Gavin Shan, IBM Corporation 2015.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+
+#include <net/ncsi.h>
+#include <net/net_namespace.h>
+#include <net/sock.h>
+
+#include "internal.h"
+#include "ncsi-pkt.h"
+
+/*
+ * This function should be called after the data area has been
+ * populated completely.
+ */
+static int ncsi_cmd_build_header(struct ncsi_pkt_hdr *h,
+ struct ncsi_cmd_arg *nca)
+{
+ __be32 csum, *checksum;
+ __be32 low, high;
+ unsigned char *stream;
+ int i;
+
+ h->mc_id = 0;
+ h->revision = NCSI_PKT_REVISION;
+ h->reserved = 0;
+ h->id = nca->nca_id;
+ h->type = nca->nca_type;
+ h->channel = NCSI_TO_CHANNEL(nca->nca_package,
+ nca->nca_channel);
+ h->length = htons(nca->nca_payload);
+ h->reserved1[0] = 0;
+ h->reserved1[1] = 0;
+
+ /* Calculate the checksum */
+ csum = 0;
+ stream = (unsigned char *)h;
+ for (i = 0; i < sizeof(*h) + nca->nca_payload; i += 2) {
+ high = stream[i];
+ low = stream[i + 1];
+ csum += ((high << 8) | low);
+ }
+
+ /* Fill with the calculated checksum */
+ checksum = (__be32 *)((void *)(h + 1) + nca->nca_payload);
+ csum = (~csum + 1);
+ *checksum = htonl(csum);
+
+ return 0;
+}
+
+static int ncsi_cmd_handler_default(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_pkt *cmd;
+
+ if (!nca)
+ return 0;
+
+ cmd = (struct ncsi_cmd_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_sp(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_sp_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_sp_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->hw_arbitration = nca->nca_bytes[0];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_dc(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_dc_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_dc_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->ald = nca->nca_bytes[0];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_rc(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_rc_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_rc_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_ae(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_ae_pkt *cmd;
+
+ if (!nca)
+ return 8;
+
+ cmd = (struct ncsi_cmd_ae_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mc_id = nca->nca_bytes[0];
+ cmd->mode = htonl(nca->nca_dwords[1]);
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_sl(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_sl_pkt *cmd;
+
+ if (!nca)
+ return 8;
+
+ cmd = (struct ncsi_cmd_sl_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mode = htonl(nca->nca_dwords[0]);
+ cmd->oem_mode = htonl(nca->nca_dwords[1]);
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_svf(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_svf_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_svf_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->vlan = htons(nca->nca_words[0]);
+ cmd->index = nca->nca_bytes[2];
+ cmd->enable = nca->nca_bytes[3];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_ev(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_ev_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_ev_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mode = nca->nca_bytes[0];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_sma(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_sma_pkt *cmd;
+ int i;
+
+ if (!nca)
+ return 8;
+
+ cmd = (struct ncsi_cmd_sma_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ for (i = 0; i < 6; i++)
+ cmd->mac[i] = nca->nca_bytes[i];
+ cmd->index = nca->nca_bytes[6];
+ cmd->at_e = nca->nca_bytes[7];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_ebf(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_ebf_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_ebf_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mode = htonl(nca->nca_dwords[0]);
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_egmf(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_egmf_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_egmf_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mode = htonl(nca->nca_dwords[0]);
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static int ncsi_cmd_handler_snfc(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_cmd_snfc_pkt *cmd;
+
+ if (!nca)
+ return 4;
+
+ cmd = (struct ncsi_cmd_snfc_pkt *)skb_put(skb, sizeof(*cmd));
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->mode = nca->nca_bytes[0];
+ return ncsi_cmd_build_header(&cmd->cmd.common, nca);
+}
+
+static struct ncsi_cmd_handler {
+ unsigned char nch_type;
+ int (*nch_handler)(struct sk_buff *skb,
+ struct ncsi_cmd_arg *nca);
+} ncsi_cmd_handlers[] = {
+ { NCSI_PKT_CMD_CIS, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_SP, ncsi_cmd_handler_sp },
+ { NCSI_PKT_CMD_DP, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_EC, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_DC, ncsi_cmd_handler_dc },
+ { NCSI_PKT_CMD_RC, ncsi_cmd_handler_rc },
+ { NCSI_PKT_CMD_ECNT, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_DCNT, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_AE, ncsi_cmd_handler_ae },
+ { NCSI_PKT_CMD_SL, ncsi_cmd_handler_sl },
+ { NCSI_PKT_CMD_GLS, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_SVF, ncsi_cmd_handler_svf },
+ { NCSI_PKT_CMD_EV, ncsi_cmd_handler_ev },
+ { NCSI_PKT_CMD_DV, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_SMA, ncsi_cmd_handler_sma },
+ { NCSI_PKT_CMD_EBF, ncsi_cmd_handler_ebf },
+ { NCSI_PKT_CMD_DBF, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_EGMF, ncsi_cmd_handler_egmf },
+ { NCSI_PKT_CMD_DGMF, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_SNFC, ncsi_cmd_handler_snfc },
+ { NCSI_PKT_CMD_GVI, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_GC, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_GP, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_GCPS, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_GNS, ncsi_cmd_handler_default },
+ { NCSI_PKT_CMD_GNPTS, ncsi_cmd_handler_default },
+ { 0, NULL }
+};
+
+static struct ncsi_req *ncsi_alloc_cmd_req(struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_dev_priv *ndp = nca->nca_ndp;
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
+ struct net_device *dev = nd->nd_dev;
+ int hlen = LL_RESERVED_SPACE(dev);
+ int tlen = dev->needed_tailroom;
+ int len = hlen + tlen;
+ struct sk_buff *skb;
+ struct ncsi_req *nr;
+
+ nr = ncsi_alloc_req(ndp);
+ if (!nr)
+ return NULL;
+
+ /* NCSI command packet has 16-bytes header, payload,
+ * 4-bytes checksum and optional padding.
+ */
+ len += sizeof(struct ncsi_cmd_pkt_hdr);
+ len += 4;
+ if (nca->nca_payload < 26)
+ len += 26;
+ else
+ len += nca->nca_payload;
+
+ /* Allocate skb */
+ skb = alloc_skb(len, GFP_ATOMIC);
+ if (!skb) {
+ ncsi_free_req(nr, false, false);
+ return NULL;
+ }
+
+ nr->nr_cmd = skb;
+ skb_reserve(skb, hlen);
+ skb_reset_network_header(skb);
+
+ skb->dev = dev;
+ skb->protocol = htons(ETH_P_NCSI);
+
+ return nr;
+}
+
+int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca)
+{
+ struct ncsi_req *nr;
+ struct ethhdr *eh;
+ struct ncsi_cmd_handler *nch;
+ int i, ret;
+
+ /* Search for the handler */
+ nch = ncsi_cmd_handlers;
+ while (nch->nch_handler) {
+ if (nch->nch_type == nca->nca_type)
+ break;
+ nch++;
+ }
+
+ if (!nch->nch_handler) {
+ pr_info("%s: Cannot send packet with type 0x%x\n",
+ __func__, nca->nca_type);
+ return -ENOENT;
+ }
+
+ /* Get packet payload length and allocate the request */
+ nca->nca_payload = nch->nch_handler(NULL, NULL);
+ nr = ncsi_alloc_cmd_req(nca);
+ if (!nr)
+ return -ENOMEM;
+
+ /* Prepare the packet */
+ nca->nca_id = nr->nr_id;
+ ret = nch->nch_handler(nr->nr_cmd, nca);
+ if (ret)
+ goto out;
+
+ /* Fill the ethernet header */
+ eh = (struct ethhdr *)skb_push(nr->nr_cmd, sizeof(*eh));
+ eh->h_proto = htons(ETH_P_NCSI);
+ for (i = 0; i < ETH_ALEN; i++) {
+ eh->h_dest[i] = 0xff;
+ eh->h_source[i] = 0xff;
+ }
+
+ /* Send NCSI packet */
+ skb_get(nr->nr_cmd);
+ ret = dev_queue_xmit_sk(NULL, nr->nr_cmd);
+ if (ret)
+ goto out;
+
+ /* Start the timer for the request that might not have
+ * corresponding response. I'm not sure 1 second delay
+ * here is enough. Anyway, NCSI is internal network, so
+ * the responsiveness should be as fast as enough.
+ */
+ nr->nr_timer_enabled = true;
+ mod_timer(&nr->nr_timer, jiffies + 1 * HZ);
+
+ return 0;
+out:
+ ncsi_free_req(nr, false, false);
+ return ret;
+}
diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h
new file mode 100644
index 0000000..646f1fc
--- /dev/null
+++ b/net/ncsi/ncsi-pkt.h
@@ -0,0 +1,391 @@
+#ifndef __NCSI_PKT_H__
+#define __NCSI_PKT_H__
+
+struct ncsi_pkt_hdr {
+ unsigned char mc_id; /* Management controller ID */
+ unsigned char revision; /* NCSI version - 0x01 */
+ unsigned char reserved; /* Reserved */
+ unsigned char id; /* Packet sequence number */
+ unsigned char type; /* Packet type */
+ unsigned char channel; /* Network controller ID */
+ __be16 length; /* Payload length */
+ __be32 reserved1[2]; /* Reserved */
+};
+
+struct ncsi_cmd_pkt_hdr {
+ struct ncsi_pkt_hdr common; /* Common NCSI packet header */
+};
+
+struct ncsi_rsp_pkt_hdr {
+ struct ncsi_pkt_hdr common; /* Common NCSI packet header */
+ __be16 code; /* Response code */
+ __be16 reason; /* Response reason */
+};
+
+struct ncsi_aen_pkt_hdr {
+ struct ncsi_pkt_hdr common; /* Common NCSI packet header */
+ unsigned char reserved2[3]; /* Reserved */
+ unsigned char type; /* AEN packet type */
+};
+
+/* NCSI common command and response packets */
+struct ncsi_cmd_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[26];
+};
+
+struct ncsi_rsp_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Select Package */
+struct ncsi_cmd_sp_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char hw_arbitration; /* HW arbitration */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Disable Channel */
+struct ncsi_cmd_dc_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char ald; /* Allow link down */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Reset Channel */
+struct ncsi_cmd_rc_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be32 reserved; /* Reserved */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* AEN Enable */
+struct ncsi_cmd_ae_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char mc_id; /* MC ID */
+ __be32 mode; /* AEN working mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[18];
+};
+
+/* Set Link */
+struct ncsi_cmd_sl_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be32 mode; /* Link working mode */
+ __be32 oem_mode; /* OEM link mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[18];
+};
+
+/* Get Link Status */
+struct ncsi_rsp_gls_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 status; /* Link status */
+ __be32 other; /* Other indications */
+ __be32 oem_status; /* OEM link status */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[10];
+};
+
+/* Set VLAN Filter */
+struct ncsi_cmd_svf_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be16 reserved; /* Reserved */
+ __be16 vlan; /* VLAN ID */
+ __be16 reserved1; /* Reserved */
+ unsigned char index; /* VLAN table index */
+ unsigned char enable; /* Enable or disable */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[14];
+};
+
+/* Enable VLAN */
+struct ncsi_cmd_ev_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char mode; /* VLAN filter mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Set MAC Address */
+struct ncsi_cmd_sma_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char mac[6]; /* MAC address */
+ unsigned char index; /* MAC table index */
+ unsigned char at_e; /* Addr type and operation */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[18];
+};
+
+/* Enable Broadcast Filter */
+struct ncsi_cmd_ebf_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be32 mode; /* Filter mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Enable Global Multicast Filter */
+struct ncsi_cmd_egmf_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ __be32 mode; /* Global MC mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Set NCSI Flow Control */
+struct ncsi_cmd_snfc_pkt {
+ struct ncsi_cmd_pkt_hdr cmd; /* Command header */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char mode; /* Flow control mode */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* Get Version ID */
+struct ncsi_rsp_gvi_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 ncsi_version; /* NCSI version */
+ unsigned char reserved[3]; /* Reserved */
+ unsigned char alpha2; /* NCSI version */
+ unsigned char fw_name[12]; /* f/w name string */
+ __be32 fw_version; /* f/w version */
+ __be16 pci_ids[4]; /* PCI IDs */
+ __be32 mf_id; /* Manufacture ID */
+ __be32 checksum;
+};
+
+/* Get Capabilities */
+struct ncsi_rsp_gc_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 cap; /* Capabilities */
+ __be32 bc_cap; /* Broadcast cap */
+ __be32 mc_cap; /* Multicast cap */
+ __be32 buf_cap; /* Buffering cap */
+ __be32 aen_cap; /* AEN cap */
+ unsigned char vlan_cnt; /* VLAN filter count */
+ unsigned char mixed_cnt; /* Mix filter count */
+ unsigned char mc_cnt; /* MC filter count */
+ unsigned char uc_cnt; /* UC filter count */
+ unsigned char reserved[2]; /* Reserved */
+ unsigned char vlan_mode; /* VLAN mode */
+ unsigned char channel_cnt; /* Channel count */
+ __be32 checksum; /* Checksum */
+};
+
+/* Get Parameters */
+struct ncsi_rsp_gp_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ unsigned char mac_cnt; /* Number of MAC addr */
+ unsigned char reserved[2]; /* Reserved */
+ unsigned char mac_enable; /* MAC addr enable flags */
+ unsigned char vlan_cnt; /* VLAN tag count */
+ unsigned char reserved1; /* Reserved */
+ __be16 vlan_enable; /* VLAN tag enable flags */
+ __be32 link_mode; /* Link setting */
+ __be32 bc_mode; /* BC filter mode */
+ __be32 valid_modes; /* Valid mode parameters */
+ unsigned char vlan_mode; /* VLAN mode */
+ unsigned char fc_mode; /* Flow control mode */
+ unsigned char reserved2[2]; /* Reserved */
+ __be32 aen_mode; /* AEN mode */
+ unsigned char mac[6]; /* Supported MAC addr */
+ __be16 vlan; /* Supported VLAN tags */
+ __be32 checksum; /* Checksum */
+};
+
+/* Get Controller Packet Statistics */
+struct ncsi_rsp_gcps_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 cnt_hi; /* Counter cleared */
+ __be32 cnt_lo; /* Counter cleared */
+ __be32 rx_bytes; /* Rx bytes */
+ __be32 tx_bytes; /* Tx bytes */
+ __be32 rx_uc_pkts; /* Rx UC packets */
+ __be32 rx_mc_pkts; /* Rx MC packets */
+ __be32 rx_bc_pkts; /* Rx BC packets */
+ __be32 tx_uc_pkts; /* Tx UC packets */
+ __be32 tx_mc_pkts; /* Tx MC packets */
+ __be32 tx_bc_pkts; /* Tx BC packets */
+ __be32 fcs_err; /* FCS errors */
+ __be32 align_err; /* Alignment errors */
+ __be32 false_carrier; /* False carrier detection */
+ __be32 runt_pkts; /* Rx runt packets */
+ __be32 jabber_pkts; /* Rx jabber packets */
+ __be32 rx_pause_xon; /* Rx pause XON frames */
+ __be32 rx_pause_xoff; /* Rx XOFF frames */
+ __be32 tx_pause_xon; /* Tx XON frames */
+ __be32 tx_pause_xoff; /* Tx XOFF frames */
+ __be32 tx_s_collision; /* Single collision frames */
+ __be32 tx_m_collision; /* Multiple collision frames */
+ __be32 l_collision; /* Late collision frames */
+ __be32 e_collision; /* Excessive collision frames */
+ __be32 rx_ctl_frames; /* Rx control frames */
+ __be32 rx_64_frames; /* Rx 64-bytes frames */
+ __be32 rx_127_frames; /* Rx 65-127 bytes frames */
+ __be32 rx_255_frames; /* Rx 128-255 bytes frames */
+ __be32 rx_511_frames; /* Rx 256-511 bytes frames */
+ __be32 rx_1023_frames; /* Rx 512-1023 bytes frames */
+ __be32 rx_1522_frames; /* Rx 1024-1522 bytes frames */
+ __be32 rx_9022_frames; /* Rx 1523-9022 bytes frames */
+ __be32 tx_64_frames; /* Tx 64-bytes frames */
+ __be32 tx_127_frames; /* Tx 65-127 bytes frames */
+ __be32 tx_255_frames; /* Tx 128-255 bytes frames */
+ __be32 tx_511_frames; /* Tx 256-511 bytes frames */
+ __be32 tx_1023_frames; /* Tx 512-1023 bytes frames */
+ __be32 tx_1522_frames; /* Tx 1024-1522 bytes frames */
+ __be32 tx_9022_frames; /* Tx 1523-9022 bytes frames */
+ __be32 rx_valid_bytes; /* Rx valid bytes */
+ __be32 rx_runt_pkts; /* Rx error runt packets */
+ __be32 rx_jabber_pkts; /* Rx error jabber packets */
+ __be32 checksum; /* Checksum */
+};
+
+/* Get NCSI Statistics */
+struct ncsi_rsp_gns_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 rx_cmds; /* Rx NCSI commands */
+ __be32 dropped_cmds; /* Dropped commands */
+ __be32 cmd_type_errs; /* Command type errors */
+ __be32 cmd_csum_errs; /* Command checksum errors */
+ __be32 rx_pkts; /* Rx NCSI packets */
+ __be32 tx_pkts; /* Tx NCSI packets */
+ __be32 tx_aen_pkts; /* Tx AEN packets */
+ __be32 checksum; /* Checksum */
+};
+
+/* Get NCSI Pass-through Statistics */
+struct ncsi_rsp_gnpts_pkt {
+ struct ncsi_rsp_pkt_hdr rsp; /* Response header */
+ __be32 tx_pkts; /* Tx packets */
+ __be32 tx_dropped; /* Tx dropped packets */
+ __be32 tx_channel_err; /* Tx channel errors */
+ __be32 tx_us_err; /* Tx undersize errors */
+ __be32 rx_pkts; /* Rx packets */
+ __be32 rx_dropped; /* Rx dropped packets */
+ __be32 rx_channel_err; /* Rx channel errors */
+ __be32 rx_us_err; /* Rx undersize errors */
+ __be32 rx_os_err; /* Rx oversize errors */
+ __be32 checksum; /* Checksum */
+};
+
+/* AEN: Link State Change */
+struct ncsi_aen_lsc_pkt {
+ struct ncsi_aen_pkt_hdr aen; /* AEN header */
+ __be32 status; /* Link status */
+ __be32 oem_status; /* OEM link status */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[14];
+};
+
+/* AEN: Configuration Required */
+struct ncsi_aen_cr_pkt {
+ struct ncsi_aen_pkt_hdr aen; /* AEN header */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[22];
+};
+
+/* AEN: Host Network Controller Driver Status Change */
+struct ncsi_aen_hncdsc_pkt {
+ struct ncsi_aen_pkt_hdr aen; /* AEN header */
+ __be32 status; /* Status */
+ __be32 checksum; /* Checksum */
+ unsigned char pad[18];
+};
+
+/* NCSI packet revision */
+#define NCSI_PKT_REVISION 0x01
+
+/* NCSI packet commands */
+#define NCSI_PKT_CMD_CIS 0x00 /* Clear Initial State */
+#define NCSI_PKT_CMD_SP 0x01 /* Select Package */
+#define NCSI_PKT_CMD_DP 0x02 /* Deselect Package */
+#define NCSI_PKT_CMD_EC 0x03 /* Enable Channel */
+#define NCSI_PKT_CMD_DC 0x04 /* Disable Channel */
+#define NCSI_PKT_CMD_RC 0x05 /* Reset Channel */
+#define NCSI_PKT_CMD_ECNT 0x06 /* Enable Channel Network Tx */
+#define NCSI_PKT_CMD_DCNT 0x07 /* Disable Channel Network Tx */
+#define NCSI_PKT_CMD_AE 0x08 /* AEN Enable */
+#define NCSI_PKT_CMD_SL 0x09 /* Set Link */
+#define NCSI_PKT_CMD_GLS 0x0a /* Get Link */
+#define NCSI_PKT_CMD_SVF 0x0b /* Set VLAN Filter */
+#define NCSI_PKT_CMD_EV 0x0c /* Enable VLAN */
+#define NCSI_PKT_CMD_DV 0x0d /* Disable VLAN */
+#define NCSI_PKT_CMD_SMA 0x0e /* Set MAC address */
+#define NCSI_PKT_CMD_EBF 0x10 /* Enable Broadcast Filter */
+#define NCSI_PKT_CMD_DBF 0x11 /* Disable Broadcast Filter */
+#define NCSI_PKT_CMD_EGMF 0x12 /* Enable Global Multicast Filter */
+#define NCSI_PKT_CMD_DGMF 0x13 /* Disable Global Multicast Filter */
+#define NCSI_PKT_CMD_SNFC 0x14 /* Set NCSI Flow Control */
+#define NCSI_PKT_CMD_GVI 0x15 /* Get Version ID */
+#define NCSI_PKT_CMD_GC 0x16 /* Get Capabilities */
+#define NCSI_PKT_CMD_GP 0x17 /* Get Parameters */
+#define NCSI_PKT_CMD_GCPS 0x18 /* Get Controller Packet Statistics */
+#define NCSI_PKT_CMD_GNS 0x19 /* Get NCSI Statistics */
+#define NCSI_PKT_CMD_GNPTS 0x1a /* Get NCSI Pass-throu Statistics */
+#define NCSI_PKT_CMD_OEM 0x50 /* OEM */
+
+/* NCSI packet responses */
+#define NCSI_PKT_RSP_CIS (NCSI_PKT_CMD_CIS + 0x80)
+#define NCSI_PKT_RSP_SP (NCSI_PKT_CMD_SP + 0x80)
+#define NCSI_PKT_RSP_DP (NCSI_PKT_CMD_DP + 0x80)
+#define NCSI_PKT_RSP_EC (NCSI_PKT_CMD_EC + 0x80)
+#define NCSI_PKT_RSP_DC (NCSI_PKT_CMD_DC + 0x80)
+#define NCSI_PKT_RSP_RC (NCSI_PKT_CMD_RC + 0x80)
+#define NCSI_PKT_RSP_ECNT (NCSI_PKT_CMD_ECNT + 0x80)
+#define NCSI_PKT_RSP_DCNT (NCSI_PKT_CMD_DCNT + 0x80)
+#define NCSI_PKT_RSP_AE (NCSI_PKT_CMD_AE + 0x80)
+#define NCSI_PKT_RSP_SL (NCSI_PKT_CMD_SL + 0x80)
+#define NCSI_PKT_RSP_GLS (NCSI_PKT_CMD_GLS + 0x80)
+#define NCSI_PKT_RSP_SVF (NCSI_PKT_CMD_SVF + 0x80)
+#define NCSI_PKT_RSP_EV (NCSI_PKT_CMD_EV + 0x80)
+#define NCSI_PKT_RSP_DV (NCSI_PKT_CMD_DV + 0x80)
+#define NCSI_PKT_RSP_SMA (NCSI_PKT_CMD_SMA + 0x80)
+#define NCSI_PKT_RSP_EBF (NCSI_PKT_CMD_EBF + 0x80)
+#define NCSI_PKT_RSP_DBF (NCSI_PKT_CMD_DBF + 0x80)
+#define NCSI_PKT_RSP_EGMF (NCSI_PKT_CMD_EGMF + 0x80)
+#define NCSI_PKT_RSP_DGMF (NCSI_PKT_CMD_DGMF + 0x80)
+#define NCSI_PKT_RSP_SNFC (NCSI_PKT_CMD_SNFC + 0x80)
+#define NCSI_PKT_RSP_GVI (NCSI_PKT_CMD_GVI + 0x80)
+#define NCSI_PKT_RSP_GC (NCSI_PKT_CMD_GC + 0x80)
+#define NCSI_PKT_RSP_GP (NCSI_PKT_CMD_GP + 0x80)
+#define NCSI_PKT_RSP_GCPS (NCSI_PKT_CMD_GCPS + 0x80)
+#define NCSI_PKT_RSP_GNS (NCSI_PKT_CMD_GNS + 0x80)
+#define NCSI_PKT_RSP_GNPTS (NCSI_PKT_CMD_GNPTS + 0x80)
+#define NCSI_PKT_RSP_OEM (NCSI_PKT_CMD_OEM + 0x80)
+
+/* NCSI packet type: AEN */
+#define NCSI_PKT_AEN 0xFF /* AEN Packet */
+#define NCSI_PKT_AEN_LSC 0x00 /* Link status change */
+#define NCSI_PKT_AEN_CR 0x01 /* Configuration required */
+#define NCSI_PKT_AEN_HNCDSC 0x02 /* HNC driver status change */
+
+/* NCSI response code/reason */
+#define NCSI_PKT_RSP_C_COMPLETED 0x0000 /* Command Completed */
+#define NCSI_PKT_RSP_C_FAILED 0x0001 /* Command Failed */
+#define NCSI_PKT_RSP_C_UNAVAILABLE 0x0002 /* Command Unavailable */
+#define NCSI_PKT_RSP_C_UNSUPPORTED 0x0003 /* Command Unsupported */
+#define NCSI_PKT_RSP_R_NO_ERROR 0x0000 /* No Error */
+#define NCSI_PKT_RSP_R_INTERFACE 0x0001 /* Interface not ready */
+#define NCSI_PKT_RSP_R_PARAM 0x0002 /* Invalid Parameter */
+#define NCSI_PKT_RSP_R_CHANNEL 0x0003 /* Channel not Ready */
+#define NCSI_PKT_RSP_R_PACKAGE 0x0004 /* Package not Ready */
+#define NCSI_PKT_RSP_R_LENGTH 0x0005 /* Invalid payload length */
+#define NCSI_PKT_RSP_R_UNKNOWN 0x7fff /* Command type unsupported */
+
+/* NCSI AEN packet type */
+#define NCSI_PKT_AEN_LSC 0x00 /* Link status change */
+#define NCSI_PKT_AEN_CR 0x01 /* Configuration required */
+#define NCSI_PKT_AEN_HNCDSC 0x02 /* Host driver status change */
+
+#endif /* __NCSI_PKT_H__ */
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
new file mode 100644
index 0000000..152de68
--- /dev/null
+++ b/net/ncsi/ncsi-rsp.c
@@ -0,0 +1,1166 @@
+/*
+ * Copyright Gavin Shan, IBM Corporation 2015.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+
+#include <net/ncsi.h>
+#include <net/net_namespace.h>
+#include <net/sock.h>
+
+#include "internal.h"
+#include "ncsi-pkt.h"
+
+static int ncsi_validate_rsp_pkt(struct ncsi_req *nr,
+ unsigned short payload)
+{
+ struct ncsi_rsp_pkt_hdr *h;
+ unsigned char *stream;
+ __be32 *checksum, csum;
+ __be32 high, low;
+ int i;
+
+ /*
+ * Check NCSI packet header. We don't need validate
+ * the packet type, which should have been checked
+ * before calling this function.
+ */
+ h = (struct ncsi_rsp_pkt_hdr *)skb_network_header(nr->nr_rsp);
+ if (h->common.revision != NCSI_PKT_REVISION)
+ return -EINVAL;
+ if (ntohs(h->common.length) != payload)
+ return -EINVAL;
+
+ /* Check on code and reason */
+ if (ntohs(h->code) != NCSI_PKT_RSP_C_COMPLETED ||
+ ntohs(h->reason) != NCSI_PKT_RSP_R_NO_ERROR)
+ return -EINVAL;
+
+ /*
+ * Validate checksum, which might be zeroes if the
+ * sender doesn't support checksum according to NCSI
+ * specification.
+ */
+ checksum = (__be32 *)((void *)(h + 1) + payload - 4);
+ if (ntohl(*checksum) == 0)
+ return 0;
+
+ csum = 0;
+ stream = (unsigned char *)h;
+ for (i = 0; i < sizeof(*h) + payload - 4; i += 2) {
+ high = stream[i];
+ low = stream[i + 1];
+ csum += ((high << 8) | low);
+ }
+
+ csum = ~csum + 1;
+ if (*checksum != htonl(csum))
+ return -EINVAL;
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_default(struct ncsi_req *nr)
+{
+ return ncsi_validate_rsp_pkt(nr, 0);
+}
+
+static int ncsi_rsp_handler_cis(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_package *np;
+ struct ncsi_channel *nc;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel, &np, &nc);
+ if (!np)
+ return -ENODEV;
+
+ /* Add the channel if necessary */
+ if (!nc)
+ nc = ncsi_add_channel(np,
+ NCSI_CHANNEL_INDEX(rsp->rsp.common.channel));
+ else if (nc->nc_state == ncsi_channel_state_deselected_initial)
+ nc->nc_state = ncsi_channel_state_deselected_ready;
+ else if (nc->nc_state == ncsi_channel_state_selected_initial)
+ nc->nc_state = ncsi_channel_state_selected_ready;
+
+ return nc ? 0 : -ENODEV;
+}
+
+static int ncsi_rsp_handler_sp(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_package *np;
+ struct ncsi_channel *nc;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /*
+ * Add the package if it's not existing. Otherwise,
+ * to change the state of its child channels.
+ */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ &np, NULL);
+ if (!np) {
+ np = ncsi_add_package(ndp,
+ NCSI_PACKAGE_INDEX(rsp->rsp.common.channel));
+ if (!np)
+ return -ENODEV;
+ }
+
+ NCSI_FOR_EACH_CHANNEL(np, nc) {
+ if (nc->nc_state == ncsi_channel_state_deselected_initial)
+ nc->nc_state = ncsi_channel_state_selected_initial;
+ else if (nc->nc_state == ncsi_channel_state_deselected_ready)
+ nc->nc_state = ncsi_channel_state_selected_ready;
+ }
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_dp(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_package *np;
+ struct ncsi_channel *nc;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ &np, NULL);
+ if (!np)
+ return -ENODEV;
+
+ /* Change state of all channels attached to the package */
+ NCSI_FOR_EACH_CHANNEL(np, nc) {
+ if (nc->nc_state == ncsi_channel_state_selected_initial)
+ nc->nc_state = ncsi_channel_state_deselected_initial;
+ else if (nc->nc_state == ncsi_channel_state_selected_ready)
+ nc->nc_state = ncsi_channel_state_deselected_ready;
+ }
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_ec(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ ncm = &nc->nc_modes[NCSI_MODE_ENABLE];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ ncm->ncm_enable = 1;
+ return 0;
+}
+
+static int ncsi_rsp_handler_dc(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp= nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ ncm = &nc->nc_modes[NCSI_MODE_ENABLE];
+ if (!ncm->ncm_enable)
+ return -EBUSY;
+
+ ncm->ncm_enable = 0;;
+ return 0;
+}
+
+static int ncsi_rsp_handler_rc(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update state for the specified channel */
+ if (nc->nc_state == ncsi_channel_state_deselected_ready)
+ nc->nc_state = ncsi_channel_state_deselected_initial;
+ else if (nc->nc_state == ncsi_channel_state_selected_ready)
+ nc->nc_state = ncsi_channel_state_selected_initial;
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_ecnt(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ ncm = &nc->nc_modes[NCSI_MODE_TX_ENABLE];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ ncm->ncm_enable = 1;
+ return 0;
+}
+
+static int ncsi_rsp_handler_dcnt(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ ncm = &nc->nc_modes[NCSI_MODE_TX_ENABLE];
+ if (!ncm->ncm_enable)
+ return -EBUSY;
+
+ ncm->ncm_enable = 1;
+ return 0;
+}
+
+static int ncsi_rsp_handler_ae(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_ae_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if the AEN has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_AEN];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to AEN configuration */
+ cmd = (struct ncsi_cmd_ae_pkt *)skb_network_header(nr->nr_cmd);
+ ncm->ncm_enable = 1;
+ ncm->ncm_data[0] = cmd->mc_id;
+ ncm->ncm_data[1] = ntohl(cmd->mode);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_sl(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_sl_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ cmd = (struct ncsi_cmd_sl_pkt *)skb_network_header(nr->nr_cmd);
+ ncm = &nc->nc_modes[NCSI_MODE_LINK];
+ ncm->ncm_data[0] = ntohl(cmd->mode);
+ ncm->ncm_data[1] = ntohl(cmd->oem_mode);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gls(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gls_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 16);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_gls_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ ncm = &nc->nc_modes[NCSI_MODE_LINK];
+ ncm->ncm_data[2] = ntohl(rsp->status);
+ ncm->ncm_data[3] = ntohl(rsp->other);
+ ncm->ncm_data[4] = ntohl(rsp->oem_status);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_svf(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_svf_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_filter *ncf;
+ unsigned short vlan;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ cmd = (struct ncsi_cmd_svf_pkt *)skb_network_header(nr->nr_cmd);
+ ncf = nc->nc_filters[NCSI_FILTER_VLAN];
+ if (!ncf)
+ return -ENOENT;
+ if (cmd->index >= ncf->ncf_total)
+ return -ERANGE;
+
+ /* Add or remove the VLAN filter */
+ if (!(cmd->enable & 0x1)) {
+ ret = ncsi_del_channel_filter(nc, NCSI_FILTER_VLAN, cmd->index);
+ } else {
+ vlan = ntohs(cmd->vlan);
+ ret = ncsi_add_channel_filter(nc, NCSI_FILTER_VLAN, &vlan);
+ }
+
+ return ret;
+}
+
+static int ncsi_rsp_handler_ev(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_ev_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if VLAN mode has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_VLAN];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to VLAN mode */
+ cmd = (struct ncsi_cmd_ev_pkt *)skb_network_header(nr->nr_cmd);
+ ncm->ncm_enable = 1;
+ ncm->ncm_data[0] = ntohl(cmd->mode);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_dv(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if VLAN mode has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_VLAN];
+ if (!ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to VLAN mode */
+ ncm->ncm_enable = 0;
+ return 0;
+}
+
+static int ncsi_rsp_handler_sma(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_sma_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_filter *ncf;
+ void *bitmap;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* According to NCSI spec 1.01, the mixed filter table
+ * isn't supported yet.
+ */
+ cmd = (struct ncsi_cmd_sma_pkt *)skb_network_header(nr->nr_cmd);
+ switch (cmd->at_e >> 5) {
+ case 0x0: /* UC address */
+ ncf = nc->nc_filters[NCSI_FILTER_UC];
+ break;
+ case 0x1: /* MC address */
+ ncf = nc->nc_filters[NCSI_FILTER_MC];
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* Sanity check on the filter */
+ if (!ncf)
+ return -ENOENT;
+ else if (cmd->index >= ncf->ncf_total)
+ return -ERANGE;
+
+ bitmap = &ncf->ncf_bitmap;
+ if (cmd->at_e & 0x1) {
+ if (test_and_set_bit(cmd->index, bitmap))
+ return -EBUSY;
+ memcpy(ncf->ncf_data + 6 * cmd->index, cmd->mac, 6);
+ } else {
+ if (!test_and_clear_bit(cmd->index, bitmap))
+ return -EBUSY;
+
+ memset(ncf->ncf_data + 6 * cmd->index, 0, 6);
+ }
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_ebf(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_ebf_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the package and channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel, NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if broadcast filter has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_BC];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to broadcast filter mode */
+ cmd = (struct ncsi_cmd_ebf_pkt *)skb_network_header(nr->nr_cmd);
+ ncm->ncm_enable = 1;
+ ncm->ncm_data[0] = ntohl(cmd->mode);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_dbf(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if broadcast filter isn't enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_BC];
+ if (!ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to broadcast filter mode */
+ ncm->ncm_enable = 0;
+ ncm->ncm_data[0] = 0;
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_egmf(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_egmf_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if multicast filter has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_MC];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to multicast filter mode */
+ cmd = (struct ncsi_cmd_egmf_pkt *)skb_network_header(nr->nr_cmd);
+ ncm->ncm_enable = 1;
+ ncm->ncm_data[0] = ntohl(cmd->mode);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_dgmf(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if multicast filter has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_MC];
+ if (!ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to multicast filter mode */
+ ncm->ncm_enable = 0;
+ ncm->ncm_data[0] = 0;
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_snfc(struct ncsi_req *nr)
+{
+ struct ncsi_cmd_snfc_pkt *cmd;
+ struct ncsi_rsp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_mode *ncm;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 4);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Check if flow control has been enabled */
+ ncm = &nc->nc_modes[NCSI_MODE_FC];
+ if (ncm->ncm_enable)
+ return -EBUSY;
+
+ /* Update to flow control mode */
+ cmd = (struct ncsi_cmd_snfc_pkt *)skb_network_header(nr->nr_cmd);
+ ncm->ncm_enable = 1;
+ ncm->ncm_data[0] = cmd->mode;
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gvi(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gvi_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_version *ncv;
+ int i, ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 36);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gvi_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update to channel's version info */
+ ncv = &nc->nc_version;
+ ncv->ncv_version = ntohl(rsp->ncsi_version);
+ ncv->ncv_alpha2 = rsp->alpha2;
+ memcpy(ncv->ncv_fw_name, rsp->fw_name, 12);
+ ncv->ncv_fw_version = ntohl(rsp->fw_version);
+ for (i = 0; i < 4; i++)
+ ncv->ncv_pci_ids[i] = ntohs(rsp->pci_ids[i]);
+ ncv->ncv_mf_id = ntohl(rsp->mf_id);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gc(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gc_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_filter *ncf;
+ size_t size, entry_size;
+ int cnt, i, ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 32);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gc_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update channel's capabilities */
+ nc->nc_caps[NCSI_CAP_GENERIC].ncc_cap = ntohl(rsp->cap) &
+ NCSI_CAP_GENERIC_MASK;
+ nc->nc_caps[NCSI_CAP_BC].ncc_cap = ntohl(rsp->bc_cap) &
+ NCSI_CAP_BC_MASK;
+ nc->nc_caps[NCSI_CAP_MC].ncc_cap = ntohl(rsp->mc_cap) &
+ NCSI_CAP_MC_MASK;
+ nc->nc_caps[NCSI_CAP_BUFFER].ncc_cap = ntohl(rsp->buf_cap);
+ nc->nc_caps[NCSI_CAP_AEN].ncc_cap = ntohl(rsp->aen_cap) &
+ NCSI_CAP_AEN_MASK;
+ nc->nc_caps[NCSI_CAP_VLAN].ncc_cap = rsp->vlan_mode &
+ NCSI_CAP_VLAN_MASK;
+
+ /* Build filters */
+ for (i = 0; i < NCSI_FILTER_MAX; i++) {
+ switch (i) {
+ case NCSI_FILTER_VLAN:
+ cnt = rsp->vlan_cnt;
+ entry_size = 2;
+ break;
+ case NCSI_FILTER_MIXED:
+ cnt = rsp->mixed_cnt;
+ entry_size = 6;
+ break;
+ case NCSI_FILTER_MC:
+ cnt = rsp->mc_cnt;
+ entry_size = 6;
+ break;
+ case NCSI_FILTER_UC:
+ cnt = rsp->uc_cnt;
+ entry_size = 6;
+ break;
+ default:
+ continue;
+ }
+
+ if (!cnt || nc->nc_filters[i])
+ continue;
+
+ size = sizeof(*ncf) + cnt * entry_size;
+ ncf = kzalloc(size, GFP_ATOMIC);
+ if (!ncf) {
+ pr_warn("%s: Cannot alloc filter table (%d)\n",
+ __func__, i);
+ return -ENOMEM;
+ }
+
+ ncf->ncf_total = cnt;
+ ncf->ncf_bitmap = 0x0ul;
+ nc->nc_filters[i] = ncf;
+ }
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gp(struct ncsi_req *nr)
+{
+ struct ncsi_pkt_hdr *h;
+ struct ncsi_rsp_gp_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ unsigned short length, enable, vlan;
+ unsigned char *pdata;
+ int table, i, ret;
+
+ /*
+ * The get parameter response packet has variable length.
+ * The payload should be figured out from the packet
+ * header, instead of the fixed one we have for other types
+ * of packets.
+ */
+ h = (struct ncsi_pkt_hdr *)skb_network_header(nr->nr_rsp);
+ length = ntohs(h->length);
+ if (length < 32)
+ return -EINVAL;
+
+ ret = ncsi_validate_rsp_pkt( nr, length);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gp_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Modes with explicit enabled indications */
+ if (ntohl(rsp->valid_modes) & 0x1) { /* BC filter mode */
+ nc->nc_modes[NCSI_MODE_BC].ncm_enable = 1;
+ nc->nc_modes[NCSI_MODE_BC].ncm_data[0] = ntohl(rsp->bc_mode);
+ }
+ if (ntohl(rsp->valid_modes) & 0x2) /* Channel enabled */
+ nc->nc_modes[NCSI_MODE_ENABLE].ncm_enable = 1;
+ if (ntohl(rsp->valid_modes) & 0x4) /* Channel Tx enabled */
+ nc->nc_modes[NCSI_MODE_TX_ENABLE].ncm_enable = 1;
+ if (ntohl(rsp->valid_modes) & 0x8) /* MC filter mode */
+ nc->nc_modes[NCSI_MODE_MC].ncm_enable = 1;
+
+ /* Modes without explicit enabled indications */
+ nc->nc_modes[NCSI_MODE_LINK].ncm_enable = 1;
+ nc->nc_modes[NCSI_MODE_LINK].ncm_data[0] = ntohl(rsp->link_mode);
+ nc->nc_modes[NCSI_MODE_VLAN].ncm_enable = 1;
+ nc->nc_modes[NCSI_MODE_VLAN].ncm_data[0] = rsp->vlan_mode;
+ nc->nc_modes[NCSI_MODE_FC].ncm_enable = 1;
+ nc->nc_modes[NCSI_MODE_FC].ncm_data[0] = rsp->fc_mode;
+ nc->nc_modes[NCSI_MODE_AEN].ncm_enable = 1;
+ nc->nc_modes[NCSI_MODE_AEN].ncm_data[0] = ntohl(rsp->aen_mode);
+
+ /* MAC addresses filter table */
+ pdata = (unsigned char *)rsp + 48;
+ enable = rsp->mac_enable;
+ for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) {
+ if (i >= (nc->nc_filters[NCSI_FILTER_UC]->ncf_total +
+ nc->nc_filters[NCSI_FILTER_MC]->ncf_total))
+ table = NCSI_FILTER_MIXED;
+ else if (i >= nc->nc_filters[NCSI_FILTER_UC]->ncf_total)
+ table = NCSI_FILTER_MC;
+ else
+ table = NCSI_FILTER_UC;
+
+ if (!(enable & (0x1 << i)))
+ continue;
+
+ if (ncsi_find_channel_filter(nc, table, pdata) >= 0)
+ continue;
+
+ ncsi_add_channel_filter(nc, table, pdata);
+ }
+
+ /* VLAN filter table */
+ enable = ntohs(rsp->vlan_enable);
+ for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) {
+ if (!(enable & (0x1 << i)))
+ continue;
+
+ vlan = ntohs(*(__be16 *)pdata);
+ if (ncsi_find_channel_filter(nc, NCSI_FILTER_VLAN, &vlan) >= 0)
+ continue;
+
+ ncsi_add_channel_filter(nc, NCSI_FILTER_VLAN, &vlan);
+ }
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gcps(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gcps_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_stats *ncs;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 172);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gcps_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update HNC's statistics */
+ ncs = &nc->nc_stats;
+ ncs->ncs_hnc_cnt_hi = ntohl(rsp->cnt_hi);
+ ncs->ncs_hnc_cnt_lo = ntohl(rsp->cnt_lo);
+ ncs->ncs_hnc_rx_bytes = ntohl(rsp->rx_bytes);
+ ncs->ncs_hnc_tx_bytes = ntohl(rsp->tx_bytes);
+ ncs->ncs_hnc_rx_uc_pkts = ntohl(rsp->rx_uc_pkts);
+ ncs->ncs_hnc_rx_mc_pkts = ntohl(rsp->rx_mc_pkts);
+ ncs->ncs_hnc_rx_bc_pkts = ntohl(rsp->rx_bc_pkts);
+ ncs->ncs_hnc_tx_uc_pkts = ntohl(rsp->tx_uc_pkts);
+ ncs->ncs_hnc_tx_mc_pkts = ntohl(rsp->tx_mc_pkts);
+ ncs->ncs_hnc_tx_bc_pkts = ntohl(rsp->tx_bc_pkts);
+ ncs->ncs_hnc_fcs_err = ntohl(rsp->fcs_err);
+ ncs->ncs_hnc_align_err = ntohl(rsp->align_err);
+ ncs->ncs_hnc_false_carrier = ntohl(rsp->false_carrier);
+ ncs->ncs_hnc_runt_pkts = ntohl(rsp->runt_pkts);
+ ncs->ncs_hnc_jabber_pkts = ntohl(rsp->jabber_pkts);
+ ncs->ncs_hnc_rx_pause_xon = ntohl(rsp->rx_pause_xon);
+ ncs->ncs_hnc_rx_pause_xoff = ntohl(rsp->rx_pause_xoff);
+ ncs->ncs_hnc_tx_pause_xon = ntohl(rsp->tx_pause_xon);
+ ncs->ncs_hnc_tx_pause_xoff = ntohl(rsp->tx_pause_xoff);
+ ncs->ncs_hnc_tx_s_collision = ntohl(rsp->tx_s_collision);
+ ncs->ncs_hnc_tx_m_collision = ntohl(rsp->tx_m_collision);
+ ncs->ncs_hnc_l_collision = ntohl(rsp->l_collision);
+ ncs->ncs_hnc_e_collision = ntohl(rsp->e_collision);
+ ncs->ncs_hnc_rx_ctl_frames = ntohl(rsp->rx_ctl_frames);
+ ncs->ncs_hnc_rx_64_frames = ntohl(rsp->rx_64_frames);
+ ncs->ncs_hnc_rx_127_frames = ntohl(rsp->rx_127_frames);
+ ncs->ncs_hnc_rx_255_frames = ntohl(rsp->rx_255_frames);
+ ncs->ncs_hnc_rx_511_frames = ntohl(rsp->rx_511_frames);
+ ncs->ncs_hnc_rx_1023_frames = ntohl(rsp->rx_1023_frames);
+ ncs->ncs_hnc_rx_1522_frames = ntohl(rsp->rx_1522_frames);
+ ncs->ncs_hnc_rx_9022_frames = ntohl(rsp->rx_9022_frames);
+ ncs->ncs_hnc_tx_64_frames = ntohl(rsp->tx_64_frames);
+ ncs->ncs_hnc_tx_127_frames = ntohl(rsp->tx_127_frames);
+ ncs->ncs_hnc_tx_255_frames = ntohl(rsp->tx_255_frames);
+ ncs->ncs_hnc_tx_511_frames = ntohl(rsp->tx_511_frames);
+ ncs->ncs_hnc_tx_1023_frames = ntohl(rsp->tx_1023_frames);
+ ncs->ncs_hnc_tx_1522_frames = ntohl(rsp->tx_1522_frames);
+ ncs->ncs_hnc_tx_9022_frames = ntohl(rsp->tx_9022_frames);
+ ncs->ncs_hnc_rx_valid_bytes = ntohl(rsp->rx_valid_bytes);
+ ncs->ncs_hnc_rx_runt_pkts = ntohl(rsp->rx_runt_pkts);
+ ncs->ncs_hnc_rx_jabber_pkts = ntohl(rsp->rx_jabber_pkts);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gns(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gns_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_stats *ncs;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 172);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gns_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update HNC's statistics */
+ ncs = &nc->nc_stats;
+ ncs->ncs_ncsi_rx_cmds = ntohl(rsp->rx_cmds);
+ ncs->ncs_ncsi_dropped_cmds = ntohl(rsp->dropped_cmds);
+ ncs->ncs_ncsi_cmd_type_errs = ntohl(rsp->cmd_type_errs);
+ ncs->ncs_ncsi_cmd_csum_errs = ntohl(rsp->cmd_csum_errs);
+ ncs->ncs_ncsi_rx_pkts = ntohl(rsp->rx_pkts);
+ ncs->ncs_ncsi_tx_pkts = ntohl(rsp->tx_pkts);
+ ncs->ncs_ncsi_tx_aen_pkts = ntohl(rsp->tx_aen_pkts);
+
+ return 0;
+}
+
+static int ncsi_rsp_handler_gnpts(struct ncsi_req *nr)
+{
+ struct ncsi_rsp_gnpts_pkt *rsp;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+ struct ncsi_channel *nc;
+ struct ncsi_channel_stats *ncs;
+ int ret;
+
+ ret = ncsi_validate_rsp_pkt( nr, 172);
+ if (ret)
+ return ret;
+
+ /* Find the channel */
+ rsp = (struct ncsi_rsp_gnpts_pkt *)skb_network_header(nr->nr_rsp);
+ ncsi_find_package_and_channel(ndp, rsp->rsp.common.channel,
+ NULL, &nc);
+ if (!nc)
+ return -ENODEV;
+
+ /* Update HNC's statistics */
+ ncs = &nc->nc_stats;
+ ncs->ncs_pt_tx_pkts = ntohl(rsp->tx_pkts);
+ ncs->ncs_pt_tx_dropped = ntohl(rsp->tx_dropped);
+ ncs->ncs_pt_tx_channel_err = ntohl(rsp->tx_channel_err);
+ ncs->ncs_pt_tx_us_err = ntohl(rsp->tx_us_err);
+ ncs->ncs_pt_rx_pkts = ntohl(rsp->rx_pkts);
+ ncs->ncs_pt_rx_dropped = ntohl(rsp->rx_dropped);
+ ncs->ncs_pt_rx_channel_err = ntohl(rsp->rx_channel_err);
+ ncs->ncs_pt_rx_us_err = ntohl(rsp->rx_us_err);
+ ncs->ncs_pt_rx_os_err = ntohl(rsp->rx_os_err);
+
+ return 0;
+}
+
+static struct ncsi_rsp_handler {
+ unsigned char nrh_type;
+ int (*nrh_handler)(struct ncsi_req *nr);
+} ncsi_rsp_handlers[] = {
+ { NCSI_PKT_RSP_CIS, ncsi_rsp_handler_cis },
+ { NCSI_PKT_RSP_SP, ncsi_rsp_handler_sp },
+ { NCSI_PKT_RSP_DP, ncsi_rsp_handler_dp },
+ { NCSI_PKT_RSP_EC, ncsi_rsp_handler_ec },
+ { NCSI_PKT_RSP_DC, ncsi_rsp_handler_dc },
+ { NCSI_PKT_RSP_RC, ncsi_rsp_handler_rc },
+ { NCSI_PKT_RSP_ECNT, ncsi_rsp_handler_ecnt },
+ { NCSI_PKT_RSP_DCNT, ncsi_rsp_handler_dcnt },
+ { NCSI_PKT_RSP_AE, ncsi_rsp_handler_ae },
+ { NCSI_PKT_RSP_SL, ncsi_rsp_handler_sl },
+ { NCSI_PKT_RSP_GLS, ncsi_rsp_handler_gls },
+ { NCSI_PKT_RSP_SVF, ncsi_rsp_handler_svf },
+ { NCSI_PKT_RSP_EV, ncsi_rsp_handler_ev },
+ { NCSI_PKT_RSP_DV, ncsi_rsp_handler_dv },
+ { NCSI_PKT_RSP_SMA, ncsi_rsp_handler_sma },
+ { NCSI_PKT_RSP_EBF, ncsi_rsp_handler_ebf },
+ { NCSI_PKT_RSP_DBF, ncsi_rsp_handler_dbf },
+ { NCSI_PKT_RSP_EGMF, ncsi_rsp_handler_egmf },
+ { NCSI_PKT_RSP_DGMF, ncsi_rsp_handler_dgmf },
+ { NCSI_PKT_RSP_SNFC, ncsi_rsp_handler_snfc },
+ { NCSI_PKT_RSP_GVI, ncsi_rsp_handler_gvi },
+ { NCSI_PKT_RSP_GC, ncsi_rsp_handler_gc },
+ { NCSI_PKT_RSP_GP, ncsi_rsp_handler_gp },
+ { NCSI_PKT_RSP_GCPS, ncsi_rsp_handler_gcps },
+ { NCSI_PKT_RSP_GNS, ncsi_rsp_handler_gns },
+ { NCSI_PKT_RSP_GNPTS, ncsi_rsp_handler_gnpts },
+ { NCSI_PKT_RSP_OEM, ncsi_rsp_handler_default },
+ { 0, NULL }
+};
+
+#if 0
+void ncsi_pkt_dump(struct sk_buff *skb)
+{
+ struct skb_shared_info *info = skb_shinfo(skb);
+ skb_frag_t *frag;
+ char *data;
+ int limit, i;
+
+ pr_info("head: 0x%p data: 0x%p tail: 0x%p end: 0x%p\n",
+ skb->head, skb->data,
+ skb_tail_pointer(skb), skb_end_pointer(skb));
+ pr_info("mac_header: 0x%p network_header: 0x%p\n",
+ skb_mac_header(skb), skb_network_header(skb));
+ pr_info("len: 0x%x data_len: 0x%x truesize: 0x%x\n",
+ skb->len, skb->data_len, skb->truesize);
+
+ for (i = 0; i < info->nr_frags; i++) {
+ frag = &info->frags[i];
+ pr_info("FRAG[%d]: 0x%p offset: 0x%x size: 0x%x\n",
+ i, frag->page.p, frag->page_offset, frag->size);
+ }
+
+ data = skb_mac_header(skb);
+ limit = skb->len + sizeof(struct ethhdr);
+ for (i = 0; i < limit; data++, i++) {
+ if (i % 16 == 0)
+ printk("\n%02x ", *data);
+ else
+ printk("%02x ", *data);
+ }
+}
+#endif
+
+int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev,
+ struct packet_type *pt, struct net_device *orig_dev)
+{
+ struct ncsi_rsp_handler *nrh = NULL;
+ struct ncsi_dev *nd;
+ struct ncsi_dev_priv *ndp;
+ struct ncsi_req *nr;
+ struct ncsi_pkt_hdr *hdr;
+ int ret;
+
+ /* Find the NCSI device */
+ nd = ncsi_find_dev(dev);
+ ndp = nd ? TO_NCSI_DEV_PRIV(nd) : NULL;
+ if (!ndp)
+ return -ENODEV;
+
+ /* Check if it's AEN packet */
+ hdr = (struct ncsi_pkt_hdr *)skb_network_header(skb);
+ if (hdr->type == NCSI_PKT_AEN)
+ return ncsi_aen_handler(ndp, skb);
+
+ /* Find the handler */
+ nrh = ncsi_rsp_handlers;
+ while (nrh->nrh_handler) {
+ if (nrh->nrh_type == hdr->type)
+ break;
+
+ nrh++;
+ }
+
+ if (!nrh->nrh_handler) {
+ pr_warn("NCSI: Received unrecognized packet (0x%x)\n",
+ hdr->type);
+ return -ENOENT;
+ }
+
+ /* Associate with the request */
+ nr = &ndp->ndp_reqs[hdr->id];
+ spin_lock(&ndp->ndp_req_lock);
+ if (!nr->nr_used) {
+ spin_unlock(&ndp->ndp_req_lock);
+ return -ENODEV;
+ }
+
+ nr->nr_rsp = skb;
+ if (!nr->nr_timer_enabled) {
+ spin_unlock(&ndp->ndp_req_lock);
+ ret = -ENOENT;
+ goto out;
+ }
+
+ /* Process the response */
+ ret = nrh->nrh_handler(nr);
+
+out:
+ ncsi_free_req(nr, true, false);
+ return ret;
+}
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH RFC 3/6] net/ncsi: Manage NCSI device
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 1/6] net/ncsi: Resource management Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 2/6] net/ncsi: Packet handler Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi Gavin Shan
` (3 subsequent siblings)
6 siblings, 0 replies; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
To the network interface that can run in NCSI mode on BMC side,
there might have multiple NCSI packages/channels. The available
NCSI packages/channels (topology) needs to be probed and one
channel should be selected as active one from the available
channels before the network interface on BMC side starts to
work. On the other hand, the active NCSI package/channel should
be disabled when the network interface on BMC is going to be
brought down. Besides, the active channel needs fail over to
another one when BMC receives AEN telling that current active
channel isn't working any more.
This introduces various state to NCSI device (struct ncsi_dev_priv)
to fulfil above tasks.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
include/net/ncsi.h | 27 +++
net/ncsi/internal.h | 1 +
net/ncsi/ncsi-aen.c | 9 +-
net/ncsi/ncsi-manage.c | 536 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 570 insertions(+), 3 deletions(-)
diff --git a/include/net/ncsi.h b/include/net/ncsi.h
index 2735f19..4d49c41 100644
--- a/include/net/ncsi.h
+++ b/include/net/ncsi.h
@@ -27,4 +27,31 @@ struct ncsi_dev {
void (*nd_handler)(struct ncsi_dev *ndev);
};
+#ifdef CONFIG_NET_NCSI
+struct ncsi_dev *ncsi_register_dev(struct net_device *dev,
+ void (*notifier)(struct ncsi_dev *nd));
+int ncsi_start_dev(struct ncsi_dev *nd);
+int ncsi_stop_dev(struct ncsi_dev *nd);
+void ncsi_unregister_dev(struct ncsi_dev *nd);
+#else /* !CONFIG_NET_NCSI */
+static inline struct ncsi_dev *ncsi_register_dev(struct net_device *dev,
+ void (*notifier)(struct ncsi_dev *nd))
+{
+ return NULL;
+}
+
+static inline int ncsi_start_dev(struct ncsi_dev *nd)
+{
+ return -ENOTTY;
+}
+
+static inline int ncsi_stop_dev(struct ncsi_dev *nd)
+{
+ return -ENOTTY;
+}
+
+void inline ncsi_unregister_dev(struct ncsi_dev *nd)
+{
+}
+#endif /* CONFIG_NET_NCSI */
#endif /* __NET_NCSI_H */
diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index 41e91d8..e9091e8 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -302,6 +302,7 @@ void ncsi_find_package_and_channel(struct ncsi_dev_priv *ndp,
struct ncsi_req *ncsi_alloc_req(struct ncsi_dev_priv *ndp);
void ncsi_free_req(struct ncsi_req *nr, bool check, bool timeout);
struct ncsi_dev *ncsi_find_dev(struct net_device *dev);
+int ncsi_config_dev(struct ncsi_dev *nd);
/* Packet handlers */
int ncsi_xmit_cmd(struct ncsi_cmd_arg *nca);
diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index 9078c3b..e1f686f 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -60,6 +60,7 @@ static int ncsi_validate_aen_pkt(struct ncsi_aen_pkt_hdr *h,
static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
struct ncsi_aen_pkt_hdr *h)
{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
struct ncsi_aen_lsc_pkt *lsc;
struct ncsi_channel *nc;
struct ncsi_channel_mode *ncm;
@@ -88,7 +89,7 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
* we have to choose another channel to be active one.
*/
ndp->ndp_flags |= NCSI_DEV_FLAG_CHANGE_ACTIVE;
- /* FIXME: Stop active channel and choose another one */
+ ncsi_stop_dev(nd);
return 0;
}
@@ -96,6 +97,7 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
static int ncsi_aen_handler_cr(struct ncsi_dev_priv *ndp,
struct ncsi_aen_pkt_hdr *h)
{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
struct ncsi_channel *nc;
int ret;
@@ -113,7 +115,7 @@ static int ncsi_aen_handler_cr(struct ncsi_dev_priv *ndp,
ndp->ndp_active_channel != nc)
return 0;
- /* FIXME: Reconfigure active channel */
+ ncsi_config_dev(nd);
return 0;
}
@@ -121,6 +123,7 @@ static int ncsi_aen_handler_cr(struct ncsi_dev_priv *ndp,
static int ncsi_aen_handler_hncdsc(struct ncsi_dev_priv *ndp,
struct ncsi_aen_pkt_hdr *h)
{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
struct ncsi_channel *nc;
struct ncsi_channel_mode *ncm;
struct ncsi_aen_hncdsc_pkt *hncdsc;
@@ -149,7 +152,7 @@ static int ncsi_aen_handler_hncdsc(struct ncsi_dev_priv *ndp,
* is down on the active channel.
*/
ndp->ndp_flags |= NCSI_DEV_FLAG_CHANGE_ACTIVE;
- /* FIXME: Stop and choose another channel as active one */
+ ncsi_stop_dev(nd);
return 0;
}
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index eb23222..50c3137 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -18,6 +18,7 @@
#include <net/net_namespace.h>
#include <net/sock.h>
+#include "ncsi-pkt.h"
#include "internal.h"
LIST_HEAD(ncsi_dev_list);
@@ -345,6 +346,8 @@ void ncsi_free_req(struct ncsi_req *nr, bool check, bool timeout)
nr->nr_used = false;
spin_unlock(&ndp->ndp_req_lock);
+ if (check && cmd && atomic_dec_return(&ndp->ndp_pending_reqs) == 0)
+ schedule_work(&ndp->ndp_work);
/* Release command and response */
consume_skb(cmd);
consume_skb(rsp);
@@ -361,3 +364,536 @@ struct ncsi_dev *ncsi_find_dev(struct net_device *dev)
return NULL;
}
+
+static int ncsi_select_active_channel(struct ncsi_dev_priv *ndp)
+{
+ struct ncsi_package *np;
+ struct ncsi_channel *nc;
+
+ /* For now, we simply choose the first valid channel as active one.
+ * There might be more factors, like the channel's capacity, can
+ * be considered to pick the active channel in future.
+ */
+ NCSI_FOR_EACH_PACKAGE(ndp, np) {
+ NCSI_FOR_EACH_CHANNEL(np, nc) {
+ ndp->ndp_active_package = np;
+ ndp->ndp_active_channel = nc;
+ return 0;
+ }
+ }
+
+ return -ENXIO;
+}
+
+static void ncsi_dev_config(struct ncsi_dev_priv *ndp)
+{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
+ struct net_device *dev = nd->nd_dev;
+ struct ncsi_package *np = ndp->ndp_active_package;
+ struct ncsi_channel *nc = ndp->ndp_active_channel;
+ struct ncsi_cmd_arg nca;
+ unsigned char index;
+ int ret;
+
+ nca.nca_ndp = ndp;
+
+ /* When we're reconfiguring the active channel, the active package
+ * should be selected and the old setting on the active channel
+ * should be cleared.
+ */
+ switch (nd->nd_state) {
+ case ncsi_dev_state_config:
+ case ncsi_dev_state_config_sp:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ /* Select the specific package */
+ nca.nca_type = NCSI_PKT_CMD_SP;
+ nca.nca_bytes[0] = 1;
+ nca.nca_package = np->np_id;
+ nca.nca_channel = 0x1f;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+
+ nd->nd_state = ncsi_dev_state_config_cis;
+ break;
+ case ncsi_dev_state_config_cis:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ /* Clear initial state */
+ nca.nca_type = NCSI_PKT_CMD_CIS;
+ nca.nca_package = np->np_id;
+ nca.nca_channel = nc->nc_id;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+
+ nd->nd_state = ncsi_dev_state_config_sma;
+ break;
+ case ncsi_dev_state_config_sma:
+ case ncsi_dev_state_config_ebf:
+ case ncsi_dev_state_config_ecnt:
+ case ncsi_dev_state_config_ec:
+ case ncsi_dev_state_config_gls:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ nca.nca_package = np->np_id;
+ nca.nca_channel = nc->nc_id;
+
+ /* Use first entry in unicast filter table. Note that
+ * the MAC filter table starts from entry 1 instead of
+ * 0.
+ */
+ if (nd->nd_state == ncsi_dev_state_config_sma) {
+ nca.nca_type = NCSI_PKT_CMD_SMA;
+ for (index = 0; index < 6; index++)
+ nca.nca_bytes[index] = dev->dev_addr[index];
+ nca.nca_bytes[6] = 0x1;
+ nca.nca_bytes[7] = 0x1;
+ nd->nd_state = ncsi_dev_state_config_ebf;
+ } else if (nd->nd_state == ncsi_dev_state_config_ebf) {
+ nca.nca_type = NCSI_PKT_CMD_EBF;
+ nca.nca_dwords[0] = nc->nc_caps[NCSI_CAP_BC].ncc_cap;
+ nd->nd_state = ncsi_dev_state_config_ecnt;
+ } else if (nd->nd_state == ncsi_dev_state_config_ecnt) {
+ nca.nca_type = NCSI_PKT_CMD_ECNT;
+ nd->nd_state = ncsi_dev_state_config_ec;
+ } else if (nd->nd_state == ncsi_dev_state_config_ec) {
+ nca.nca_type = NCSI_PKT_CMD_EC;
+ nd->nd_state = ncsi_dev_state_config_gls;
+ } else if (nd->nd_state == ncsi_dev_state_config_gls) {
+ nca.nca_type = NCSI_PKT_CMD_GLS;
+ nd->nd_state = ncsi_dev_state_config_done;
+ }
+
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+
+ break;
+ case ncsi_dev_state_config_done:
+ nd->nd_state = ncsi_dev_state_functional;
+ nd->nd_link_up = 0;
+ if (nc->nc_modes[NCSI_MODE_LINK].ncm_data[2] & 0x1)
+ nd->nd_link_up = 1;
+
+ if (!(ndp->ndp_flags & NCSI_DEV_FLAG_CHANGE_ACTIVE))
+ nd->nd_handler(nd);
+ ndp->ndp_flags &= ~NCSI_DEV_FLAG_CHANGE_ACTIVE;
+
+ break;
+ default:
+ pr_debug("%s: Unrecognized NCSI dev state 0x%x\n",
+ __func__, nd->nd_state);
+ return;
+ }
+
+ return;
+
+error:
+ nd->nd_state = ncsi_dev_state_functional;
+ nd->nd_link_up = 0;
+ ndp->ndp_flags &= ~NCSI_DEV_FLAG_CHANGE_ACTIVE;
+ nd->nd_handler(nd);
+}
+
+static void ncsi_dev_start(struct ncsi_dev_priv *ndp)
+{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
+ struct ncsi_package *np;
+ struct ncsi_channel *nc;
+ struct ncsi_cmd_arg nca;
+ unsigned char index;
+ int ret;
+
+ nca.nca_ndp = ndp;
+ switch (nd->nd_state) {
+ case ncsi_dev_state_start:
+ nd->nd_state = ncsi_dev_state_start_deselect;
+ /* Fall through */
+ case ncsi_dev_state_start_deselect:
+ atomic_set(&ndp->ndp_pending_reqs, 8);
+
+ /* Deselect all possible packages */
+ nca.nca_type = NCSI_PKT_CMD_DP;
+ nca.nca_channel = 0x1f;
+ for (index = 0; index < 8; index++) {
+ nca.nca_package = index;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+ }
+
+ nd->nd_state = ncsi_dev_state_start_package;
+ break;
+ case ncsi_dev_state_start_package:
+ atomic_set(&ndp->ndp_pending_reqs, 16);
+
+ /* Select all possible packages */
+ nca.nca_type = NCSI_PKT_CMD_SP;
+ nca.nca_bytes[0] = 1;
+ nca.nca_channel = 0x1f;
+ for (index = 0; index < 8; index++) {
+ nca.nca_package = index;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+ }
+
+ /* Disable all possible packages */
+ nca.nca_type = NCSI_PKT_CMD_DP;
+ for (index = 0; index < 8; index++) {
+ nca.nca_package = index;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+ }
+
+ nd->nd_state = ncsi_dev_state_start_channel;
+ break;
+ case ncsi_dev_state_start_channel:
+ /* The available packages should have been detected. To
+ * iterate every package to probe its channels.
+ */
+ if (!ndp->ndp_active_package) {
+ ndp->ndp_active_package = list_first_or_null_rcu(
+ &ndp->ndp_packages, struct ncsi_package,
+ np_node);
+ if (!ndp->ndp_active_package)
+ goto error;
+ } else {
+ if (list_is_last(&ndp->ndp_active_package->np_node,
+ &ndp->ndp_packages)) {
+ nd->nd_state = ncsi_dev_state_start_active;
+ goto choose_active_channel;
+ }
+
+ ndp->ndp_active_package = list_entry_rcu(
+ ndp->ndp_active_package->np_node.next,
+ struct ncsi_package, np_node);
+ }
+ /* Fall through */
+ case ncsi_dev_state_start_sp:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ /* Select the specific package */
+ nca.nca_type = NCSI_PKT_CMD_SP;
+ nca.nca_bytes[0] = 1;
+ nca.nca_package = ndp->ndp_active_package->np_id;
+ nca.nca_channel = 0x1f;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+
+ nd->nd_state = ncsi_dev_state_start_cis;
+ break;
+ case ncsi_dev_state_start_cis:
+ atomic_set(&ndp->ndp_pending_reqs, 0x20);
+
+ /* Clear initial state */
+ nca.nca_type = NCSI_PKT_CMD_CIS;
+ nca.nca_package = ndp->ndp_active_package->np_id;
+ for (index = 0; index < 0x20; index++) {
+ nca.nca_channel = index;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+ }
+
+ nd->nd_state = ncsi_dev_state_start_gvi;
+ break;
+ case ncsi_dev_state_start_gvi:
+ case ncsi_dev_state_start_gc:
+ /* The available channels of the active package should have
+ * been populated.
+ */
+ np = ndp->ndp_active_package;
+ atomic_set(&ndp->ndp_pending_reqs,
+ atomic_read(&np->np_channel_num));
+
+ /* Get version information or get capacity */
+ if (nd->nd_state == ncsi_dev_state_start_gvi)
+ nca.nca_type = NCSI_PKT_CMD_GVI;
+ else
+ nca.nca_type = NCSI_PKT_CMD_GC;
+
+ nca.nca_package = np->np_id;
+ NCSI_FOR_EACH_CHANNEL(np, nc) {
+ nca.nca_channel = nc->nc_id;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+ }
+
+ if (nd->nd_state == ncsi_dev_state_start_gvi)
+ nd->nd_state = ncsi_dev_state_start_gc;
+ else
+ nd->nd_state = ncsi_dev_state_start_dp;
+ break;
+ case ncsi_dev_state_start_dp:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ /* Deselect the active package */
+ nca.nca_type = NCSI_PKT_CMD_DP;
+ nca.nca_package = ndp->ndp_active_package->np_id;
+ nca.nca_channel = 0x1f;
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret)
+ goto error;
+
+ nd->nd_state = ncsi_dev_state_start_channel;
+ break;
+ case ncsi_dev_state_start_active:
+choose_active_channel:
+ /* All packages and channels should have been populated. Also,
+ * the information for all channels should have been retrieved.
+ */
+ ndp->ndp_active_package = NULL;
+ ncsi_select_active_channel(ndp);
+ if (!ndp->ndp_active_package ||
+ !ndp->ndp_active_channel)
+ goto error;
+
+ /* To configure the active channel */
+ nd->nd_state = ncsi_dev_state_config_sma;
+ ncsi_dev_config(ndp);
+ default:
+ pr_debug("%s: Unrecognized NCSI dev state 0x%x\n",
+ __func__, nd->nd_state);
+ }
+
+ return;
+
+error:
+ ndp->ndp_flags &= ~NCSI_DEV_FLAG_CHANGE_ACTIVE;
+ nd->nd_state = ncsi_dev_state_functional;
+ nd->nd_link_up = 0;
+ nd->nd_handler(nd);
+}
+
+static void ncsi_dev_stop(struct ncsi_dev_priv *ndp)
+{
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
+ struct ncsi_package *np, *tmp;
+ struct ncsi_channel *nc;
+ struct ncsi_cmd_arg nca;
+ int ret;
+
+ nca.nca_ndp = ndp;
+ switch (nd->nd_state) {
+ case ncsi_dev_state_stop:
+ /* If there're no active channel, we're done */
+ if (!ndp->ndp_active_channel) {
+ nd->nd_state = ncsi_dev_state_stop_done;
+ goto done;
+ }
+
+ nd->nd_state = ncsi_dev_state_stop_select;
+ /* Fall through */
+ case ncsi_dev_state_stop_select:
+ case ncsi_dev_state_stop_dcnt:
+ case ncsi_dev_state_stop_dc:
+ case ncsi_dev_state_stop_deselect:
+ atomic_set(&ndp->ndp_pending_reqs, 1);
+
+ np = ndp->ndp_active_package;
+ nc = ndp->ndp_active_channel;
+ nca.nca_package = np->np_id;
+ if (nd->nd_state == ncsi_dev_state_stop_select) {
+ nca.nca_type = NCSI_PKT_CMD_SP;
+ nca.nca_channel = 0x1f;
+ nca.nca_bytes[0] = 1;
+ nd->nd_state = ncsi_dev_state_stop_dcnt;
+ } else if (nd->nd_state == ncsi_dev_state_stop_dcnt) {
+ nca.nca_type = NCSI_PKT_CMD_DCNT;
+ nca.nca_channel = nc->nc_id;
+ nd->nd_state = ncsi_dev_state_stop_dc;
+ } else if (nd->nd_state == ncsi_dev_state_stop_dc) {
+ nca.nca_type = NCSI_PKT_CMD_DC;
+ nca.nca_channel = nc->nc_id;
+ nca.nca_bytes[0] = 1;
+ nd->nd_state = ncsi_dev_state_stop_deselect;
+ } else if (nd->nd_state == ncsi_dev_state_stop_deselect) {
+ nca.nca_type = NCSI_PKT_CMD_DP;
+ nca.nca_channel = 0x1f;
+ nd->nd_state = ncsi_dev_state_stop_done;
+ }
+
+ ret = ncsi_xmit_cmd(&nca);
+ if (ret) {
+ nd->nd_state = ncsi_dev_state_stop_done;
+ goto done;
+ }
+
+ break;
+ case ncsi_dev_state_stop_done:
+done:
+ spin_lock(&ndp->ndp_package_lock);
+ list_for_each_entry_safe(np, tmp, &ndp->ndp_packages, np_node)
+ ncsi_release_package(np);
+ spin_unlock(&ndp->ndp_package_lock);
+
+ if (!(ndp->ndp_flags & NCSI_DEV_FLAG_CHANGE_ACTIVE)) {
+ nd->nd_state = ncsi_dev_state_functional;
+ nd->nd_link_up = 0;
+ nd->nd_handler(nd);
+ } else {
+ nd->nd_state = ncsi_dev_state_start;
+ ncsi_dev_start(ndp);
+ }
+
+ break;
+ default:
+ pr_warn("%s: Unsupported NCSI dev state 0x%x\n",
+ __func__, nd->nd_state);
+ }
+}
+
+static void ncsi_dev_work(struct work_struct *work)
+{
+ struct ncsi_dev_priv *ndp = container_of(work, struct ncsi_dev_priv,
+ ndp_work);
+ struct ncsi_dev *nd = &ndp->ndp_ndev;
+
+ switch (nd->nd_state & ncsi_dev_state_major) {
+ case ncsi_dev_state_start:
+ ncsi_dev_start(ndp);
+ break;
+ case ncsi_dev_state_stop:
+ ncsi_dev_stop(ndp);
+ break;
+ case ncsi_dev_state_config:
+ ncsi_dev_config(ndp);
+ break;
+ default:
+ pr_warn("%s: Unsupported NCSI dev state 0x%x\n",
+ __func__, nd->nd_state);
+ }
+}
+
+static void ncsi_req_timeout(unsigned long data)
+{
+ struct ncsi_req *nr = (struct ncsi_req *)data;
+ struct ncsi_dev_priv *ndp = nr->nr_ndp;
+
+ /* If the request already had associated response,
+ * let the response handler to release it.
+ */
+ spin_lock(&ndp->ndp_req_lock);
+ nr->nr_timer_enabled = false;
+ if (nr->nr_rsp || !nr->nr_cmd) {
+ spin_unlock(&ndp->ndp_req_lock);
+ return;
+ }
+ spin_unlock(&ndp->ndp_req_lock);
+
+ /* Release the request */
+ ncsi_free_req(nr, true, true);
+}
+
+struct ncsi_dev *ncsi_register_dev(struct net_device *dev,
+ void (*handler)(struct ncsi_dev *ndev))
+{
+ struct ncsi_dev_priv *ndp;
+ struct ncsi_dev *nd;
+ int idx;
+
+ /* Check if the device has been registered or not */
+ nd = ncsi_find_dev(dev);
+ if (nd)
+ return nd;
+
+ /* Create NCSI device */
+ ndp = kzalloc(sizeof(*ndp), GFP_ATOMIC);
+ if (!ndp) {
+ pr_warn("%s: Out of memory !\n", __func__);
+ return NULL;
+ }
+
+ nd = &ndp->ndp_ndev;
+ nd->nd_state = ncsi_dev_state_registered;
+ nd->nd_dev = dev;
+ nd->nd_handler = handler;
+
+ /* Initialize private NCSI device */
+ spin_lock_init(&ndp->ndp_package_lock);
+ INIT_LIST_HEAD(&ndp->ndp_packages);
+ INIT_WORK(&ndp->ndp_work, ncsi_dev_work);
+ spin_lock_init(&ndp->ndp_req_lock);
+ atomic_set(&ndp->ndp_last_req_idx, 0);
+ for (idx = 0; idx < 256; idx++) {
+ ndp->ndp_reqs[idx].nr_id = idx;
+ ndp->ndp_reqs[idx].nr_ndp = ndp;
+ setup_timer(&ndp->ndp_reqs[idx].nr_timer, ncsi_req_timeout,
+ (unsigned long)&ndp->ndp_reqs[idx]);
+ }
+
+ spin_lock(&ncsi_dev_lock);
+ list_add_tail_rcu(&ndp->ndp_node, &ncsi_dev_list);
+ spin_unlock(&ncsi_dev_lock);
+
+ /* Register NCSI packet receiption handler */
+ ndp->ndp_ptype.type = cpu_to_be16(ETH_P_NCSI);
+ ndp->ndp_ptype.func = ncsi_rcv_rsp;
+ ndp->ndp_ptype.dev = dev;
+ dev_add_pack(&ndp->ndp_ptype);
+
+ return nd;
+}
+EXPORT_SYMBOL_GPL(ncsi_register_dev);
+
+int ncsi_start_dev(struct ncsi_dev *nd)
+{
+ struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd);
+
+ if (nd->nd_state != ncsi_dev_state_registered &&
+ nd->nd_state != ncsi_dev_state_functional)
+ return -ENOTTY;
+
+ nd->nd_state = ncsi_dev_state_start;
+ schedule_work(&ndp->ndp_work);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ncsi_start_dev);
+
+int ncsi_config_dev(struct ncsi_dev *nd)
+{
+ struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd);
+
+ if (nd->nd_state != ncsi_dev_state_functional)
+ return -ENOTTY;
+
+ nd->nd_state = ncsi_dev_state_config;
+ schedule_work(&ndp->ndp_work);
+
+ return 0;
+}
+
+int ncsi_stop_dev(struct ncsi_dev *nd)
+{
+ struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd);
+
+ if (nd->nd_state != ncsi_dev_state_functional)
+ return -ENOTTY;
+
+ nd->nd_state = ncsi_dev_state_stop;
+ schedule_work(&ndp->ndp_work);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ncsi_stop_dev);
+
+void ncsi_unregister_dev(struct ncsi_dev *nd)
+{
+ struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd);
+ struct ncsi_package *np, *tmp;
+
+ dev_remove_pack(&ndp->ndp_ptype);
+
+ spin_lock(&ndp->ndp_package_lock);
+ list_for_each_entry_safe(np, tmp, &ndp->ndp_packages, np_node)
+ ncsi_release_package(np);
+ spin_unlock(&ndp->ndp_package_lock);
+}
+EXPORT_SYMBOL_GPL(ncsi_unregister_dev);
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
` (2 preceding siblings ...)
2015-11-09 0:10 ` [PATCH RFC 3/6] net/ncsi: Manage NCSI device Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:30 ` Benjamin Herrenschmidt
2015-11-09 0:10 ` [PATCH RFC 5/6] net/faraday: Enable NCSI interface Gavin Shan
` (2 subsequent siblings)
6 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
This replaces variable name "use_nc_si" with "use_ncsi". No logical
changes introduced.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
drivers/net/ethernet/faraday/ftgmac100.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 08e0336..778bee8 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -75,7 +75,7 @@ struct ftgmac100 {
struct phy_device *phydev;
int old_speed;
- bool use_nc_si;
+ bool use_ncsi;
};
static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
@@ -1150,11 +1150,11 @@ static int ftgmac100_open(struct net_device *netdev)
goto err_hw;
ftgmac100_init_hw(priv);
- ftgmac100_start_hw(priv, priv->use_nc_si ? 100 : 10);
+ ftgmac100_start_hw(priv, priv->use_ncsi ? 100 : 10);
if (priv->phydev)
phy_start(priv->phydev);
- else if (priv->use_nc_si)
+ else if (priv->use_ncsi)
netif_carrier_on(priv->netdev);
napi_enable(&priv->napi);
@@ -1275,7 +1275,7 @@ err_alloc_mdiobus:
static void ftgmac100_destroy_mdio(struct ftgmac100 *priv)
{
- if (!priv->use_nc_si)
+ if (!priv->use_ncsi)
return;
phy_disconnect(priv->phydev);
mdiobus_unregister(priv->mii_bus);
@@ -1359,9 +1359,9 @@ static int ftgmac100_probe(struct platform_device *pdev)
/* Check for NC-SI mode */
if (pdev->dev.of_node &&
of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
- priv->use_nc_si = true;
+ priv->use_ncsi = true;
else
- priv->use_nc_si = false;
+ priv->use_ncsi = false;
/* If we use NC-SI, we need to set that up, which isn't implemented yet
* so we pray things were setup by the bootloader and just mark our link
@@ -1370,7 +1370,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
* Eventually, we'll have a proper NC-SI stack as a helper we can
* instanciate
*/
- if (priv->use_nc_si) {
+ if (priv->use_ncsi) {
/* XXX */
priv->phydev = NULL;
dev_info(&pdev->dev, "Using NC-SI interface\n");
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
` (3 preceding siblings ...)
2015-11-09 0:10 ` [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:32 ` Benjamin Herrenschmidt
2015-11-09 0:10 ` [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree Gavin Shan
2016-02-24 2:59 ` [PATCH RFC 0/6] NCSI Support Gavin Shan
6 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
The NIC has the possibility to connect to NCSI package and channel.
This supports NCSI enabled interface. When the network device is
registered, the accompanying NCSI device is registered. When the
interface is to be brought up, the NCSI device is started to probe
NCSI topology and choose one active channel automatically. On the
other handle, when the interface is to be brought down, the interface
will be shuted down when the NCSI device is teared down.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
drivers/net/ethernet/faraday/ftgmac100.c | 91 +++++++++++++++++++++++---------
1 file changed, 67 insertions(+), 24 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 778bee8..1b13fd4 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -31,6 +31,7 @@
#include <linux/phy.h>
#include <linux/platform_device.h>
#include <net/ip.h>
+#include <net/ncsi.h>
#include "ftgmac100.h"
@@ -68,6 +69,7 @@ struct ftgmac100 {
struct net_device *netdev;
struct device *dev;
+ struct ncsi_dev *ndev;
struct napi_struct napi;
struct mii_bus *mii_bus;
@@ -1038,7 +1040,11 @@ static irqreturn_t ftgmac100_interrupt(int irq, void *dev_id)
struct net_device *netdev = dev_id;
struct ftgmac100 *priv = netdev_priv(netdev);
- if (likely(netif_running(netdev))) {
+ /* When running in NCSI mode, the interface should be
+ * ready to receive or transmit NCSI packet before it's
+ * opened.
+ */
+ if (likely(priv->use_ncsi || netif_running(netdev))) {
/* Disable interrupts for polling */
iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
napi_schedule(&priv->napi);
@@ -1162,8 +1168,18 @@ static int ftgmac100_open(struct net_device *netdev)
/* enable all interrupts */
iowrite32(INT_MASK_ALL_ENABLED, priv->base + FTGMAC100_OFFSET_IER);
+ /* Start the NCSI device */
+ if (priv->use_ncsi){
+ err = ncsi_start_dev(priv->ndev);
+ if (err)
+ goto err_ncsi;
+ }
return 0;
+err_ncsi:
+ napi_disable(&priv->napi);
+ netif_stop_queue(netdev);
+ iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
err_hw:
free_irq(priv->irq, netdev);
err_irq:
@@ -1172,7 +1188,7 @@ err_alloc:
return err;
}
-static int ftgmac100_stop(struct net_device *netdev)
+static int ftgmac100_stop_dev(struct net_device *netdev)
{
struct ftgmac100 *priv = netdev_priv(netdev);
@@ -1191,6 +1207,18 @@ static int ftgmac100_stop(struct net_device *netdev)
return 0;
}
+static int ftgmac100_stop(struct net_device *netdev)
+{
+ struct ftgmac100 *priv = netdev_priv(netdev);
+
+ /* Stop NCSI device */
+ if (priv->use_ncsi) {
+ ncsi_stop_dev(priv->ndev);
+ return 0;
+ }
+
+ return ftgmac100_stop_dev(netdev);
+}
static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
struct net_device *netdev)
{
@@ -1291,6 +1319,21 @@ static const struct net_device_ops ftgmac100_netdev_ops = {
.ndo_do_ioctl = ftgmac100_do_ioctl,
};
+static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
+{
+ struct net_device *netdev = nd->nd_dev;
+
+ if (nd->nd_state != ncsi_dev_state_functional)
+ return;
+
+ if (nd->nd_link_up) {
+ pr_info("NCSI dev is up\n");
+ netif_start_queue(netdev);
+ } else {
+ pr_info("NCSI dev is down\n");
+ ftgmac100_stop_dev(netdev);
+ }
+}
/******************************************************************************
* struct platform_driver functions
*****************************************************************************/
@@ -1300,7 +1343,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
int irq;
struct net_device *netdev;
struct ftgmac100 *priv;
- int err;
+ int err = 0;
if (!pdev)
return -ENODEV;
@@ -1320,7 +1363,17 @@ static int ftgmac100_probe(struct platform_device *pdev)
goto err_alloc_etherdev;
}
+ /* Check for NCSI mode */
+ priv = netdev_priv(netdev);
SET_NETDEV_DEV(netdev, &pdev->dev);
+ if (pdev->dev.of_node &&
+ of_get_property(pdev->dev.of_node, "use-nc-si", NULL)) {
+ dev_info(&pdev->dev, "Using NCSI interface\n");
+ priv->phydev = NULL;
+ priv->use_ncsi = true;
+ } else {
+ priv->use_ncsi = false;
+ }
netdev->ethtool_ops = &ftgmac100_ethtool_ops;
netdev->netdev_ops = &ftgmac100_netdev_ops;
@@ -1329,7 +1382,6 @@ static int ftgmac100_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, netdev);
/* setup private data */
- priv = netdev_priv(netdev);
priv->netdev = netdev;
priv->dev = &pdev->dev;
@@ -1356,24 +1408,14 @@ static int ftgmac100_probe(struct platform_device *pdev)
priv->irq = irq;
- /* Check for NC-SI mode */
- if (pdev->dev.of_node &&
- of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
- priv->use_ncsi = true;
- else
- priv->use_ncsi = false;
+ /* Read MAC address or setup a new one */
+ ftgmac100_setup_mac(priv);
- /* If we use NC-SI, we need to set that up, which isn't implemented yet
- * so we pray things were setup by the bootloader and just mark our link
- * as up (otherwise we can't get packets through).
- *
- * Eventually, we'll have a proper NC-SI stack as a helper we can
- * instanciate
- */
+ /* Register NCSI device */
if (priv->use_ncsi) {
- /* XXX */
- priv->phydev = NULL;
- dev_info(&pdev->dev, "Using NC-SI interface\n");
+ priv->ndev = ncsi_register_dev(netdev, ftgmac100_ncsi_handler);
+ if (!priv->ndev)
+ goto err_ncsi_dev;
} else {
err = ftgmac100_setup_mdio(priv);
@@ -1384,9 +1426,6 @@ static int ftgmac100_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "Error %d setting up MDIO\n", err);
}
- /* Read MAC address or setup a new one */
- ftgmac100_setup_mac(priv);
-
/* Register network device */
err = register_netdev(netdev);
if (err) {
@@ -1399,7 +1438,11 @@ static int ftgmac100_probe(struct platform_device *pdev)
return 0;
err_register_netdev:
- ftgmac100_destroy_mdio(priv);
+ if (!priv->use_ncsi)
+ ftgmac100_destroy_mdio(priv);
+ else
+ ncsi_unregister_dev(priv->ndev);
+err_ncsi_dev:
iounmap(priv->base);
err_ioremap:
release_resource(priv->res);
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
` (4 preceding siblings ...)
2015-11-09 0:10 ` [PATCH RFC 5/6] net/faraday: Enable NCSI interface Gavin Shan
@ 2015-11-09 0:10 ` Gavin Shan
2015-11-09 0:36 ` Benjamin Herrenschmidt
2016-02-24 2:59 ` [PATCH RFC 0/6] NCSI Support Gavin Shan
6 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:10 UTC (permalink / raw)
To: netdev; +Cc: benh, davem, sergei.shtylyov, Gavin Shan
This enables IP/UDP/TCP offload checksum according to information
passed on from bootloader through device-tree. The offload doesn't
working properly when the interface works in NCSI mode.
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
drivers/net/ethernet/faraday/ftgmac100.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 1b13fd4..1e2f4d2 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1377,7 +1377,10 @@ static int ftgmac100_probe(struct platform_device *pdev)
netdev->ethtool_ops = &ftgmac100_ethtool_ops;
netdev->netdev_ops = &ftgmac100_netdev_ops;
- netdev->features = NETIF_F_IP_CSUM | NETIF_F_GRO;
+ netdev->features = NETIF_F_GRO;
+ if (pdev->dev.of_node &&
+ of_property_read_bool(pdev->dev.of_node, "no-hw-checksum"))
+ netdev->features |= NETIF_F_IP_CSUM;
platform_set_drvdata(pdev, netdev);
--
2.1.0
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi
2015-11-09 0:10 ` [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi Gavin Shan
@ 2015-11-09 0:30 ` Benjamin Herrenschmidt
2015-11-09 0:45 ` Gavin Shan
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-09 0:30 UTC (permalink / raw)
To: Gavin Shan, netdev; +Cc: davem, sergei.shtylyov
On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
> This replaces variable name "use_nc_si" with "use_ncsi". No logical
> changes introduced.
This driver patch is against an internal tree, not upstream. Please
ignore. The upstream driver doesn't have any concept of "nc_si".
Gavin, next time you respin the series, make sure it's against
upstream.
Cheers,
Ben.
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
> ---
> drivers/net/ethernet/faraday/ftgmac100.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c
> b/drivers/net/ethernet/faraday/ftgmac100.c
> index 08e0336..778bee8 100644
> --- a/drivers/net/ethernet/faraday/ftgmac100.c
> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
> @@ -75,7 +75,7 @@ struct ftgmac100 {
> struct phy_device *phydev;
> int old_speed;
>
> - bool use_nc_si;
> + bool use_ncsi;
> };
>
> static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
> @@ -1150,11 +1150,11 @@ static int ftgmac100_open(struct net_device
> *netdev)
> goto err_hw;
>
> ftgmac100_init_hw(priv);
> - ftgmac100_start_hw(priv, priv->use_nc_si ? 100 : 10);
> + ftgmac100_start_hw(priv, priv->use_ncsi ? 100 : 10);
>
> if (priv->phydev)
> phy_start(priv->phydev);
> - else if (priv->use_nc_si)
> + else if (priv->use_ncsi)
> netif_carrier_on(priv->netdev);
>
> napi_enable(&priv->napi);
> @@ -1275,7 +1275,7 @@ err_alloc_mdiobus:
>
> static void ftgmac100_destroy_mdio(struct ftgmac100 *priv)
> {
> - if (!priv->use_nc_si)
> + if (!priv->use_ncsi)
> return;
> phy_disconnect(priv->phydev);
> mdiobus_unregister(priv->mii_bus);
> @@ -1359,9 +1359,9 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> /* Check for NC-SI mode */
> if (pdev->dev.of_node &&
> of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
> - priv->use_nc_si = true;
> + priv->use_ncsi = true;
> else
> - priv->use_nc_si = false;
> + priv->use_ncsi = false;
>
> /* If we use NC-SI, we need to set that up, which isn't
> implemented yet
> * so we pray things were setup by the bootloader and just
> mark our link
> @@ -1370,7 +1370,7 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> * Eventually, we'll have a proper NC-SI stack as a helper
> we can
> * instanciate
> */
> - if (priv->use_nc_si) {
> + if (priv->use_ncsi) {
> /* XXX */
> priv->phydev = NULL;
> dev_info(&pdev->dev, "Using NC-SI interface\n");
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-09 0:10 ` [PATCH RFC 5/6] net/faraday: Enable NCSI interface Gavin Shan
@ 2015-11-09 0:32 ` Benjamin Herrenschmidt
2015-11-09 7:30 ` Gavin Shan
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-09 0:32 UTC (permalink / raw)
To: Gavin Shan, netdev; +Cc: davem, sergei.shtylyov
On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
>
> - if (likely(netif_running(netdev))) {
> + /* When running in NCSI mode, the interface should be
> + * ready to receive or transmit NCSI packet before it's
> + * opened.
> + */
No, that's not right. open/close is when a driver allocates it's data
structures, DMA ring descriptors, packet buffers etc... and request
it's interrupts.
You cannot expect packets to flow on a closed interface and you
shouldn't be getting any interrupts on a closed interface either.
> + if (likely(priv->use_ncsi || netif_running(netdev))) {
> /* Disable interrupts for polling */
> iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
> napi_schedule(&priv->napi);
> @@ -1162,8 +1168,18 @@ static int ftgmac100_open(struct net_device
> *netdev)
>
> /* enable all interrupts */
> iowrite32(INT_MASK_ALL_ENABLED, priv->base +
> FTGMAC100_OFFSET_IER);
> + /* Start the NCSI device */
> + if (priv->use_ncsi){
> + err = ncsi_start_dev(priv->ndev);
> + if (err)
> + goto err_ncsi;
> + }
> return 0;
>
> +err_ncsi:
> + napi_disable(&priv->napi);
> + netif_stop_queue(netdev);
> + iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
> err_hw:
> free_irq(priv->irq, netdev);
> err_irq:
> @@ -1172,7 +1188,7 @@ err_alloc:
> return err;
> }
>
> -static int ftgmac100_stop(struct net_device *netdev)
> +static int ftgmac100_stop_dev(struct net_device *netdev)
> {
> struct ftgmac100 *priv = netdev_priv(netdev);
>
> @@ -1191,6 +1207,18 @@ static int ftgmac100_stop(struct net_device
> *netdev)
> return 0;
> }
>
> +static int ftgmac100_stop(struct net_device *netdev)
> +{
> + struct ftgmac100 *priv = netdev_priv(netdev);
> +
> + /* Stop NCSI device */
> + if (priv->use_ncsi) {
> + ncsi_stop_dev(priv->ndev);
> + return 0;
> + }
> +
> + return ftgmac100_stop_dev(netdev);
> +}
> static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
> struct net_device *netdev)
> {
> @@ -1291,6 +1319,21 @@ static const struct net_device_ops
> ftgmac100_netdev_ops = {
> .ndo_do_ioctl = ftgmac100_do_ioctl,
> };
>
> +static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
> +{
> + struct net_device *netdev = nd->nd_dev;
> +
> + if (nd->nd_state != ncsi_dev_state_functional)
> + return;
> +
> + if (nd->nd_link_up) {
> + pr_info("NCSI dev is up\n");
> + netif_start_queue(netdev);
> + } else {
> + pr_info("NCSI dev is down\n");
> + ftgmac100_stop_dev(netdev);
> + }
> +}
> /*******************************************************************
> ***********
> * struct platform_driver functions
>
> *********************************************************************
> ********/
> @@ -1300,7 +1343,7 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> int irq;
> struct net_device *netdev;
> struct ftgmac100 *priv;
> - int err;
> + int err = 0;
>
> if (!pdev)
> return -ENODEV;
> @@ -1320,7 +1363,17 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> goto err_alloc_etherdev;
> }
>
> + /* Check for NCSI mode */
> + priv = netdev_priv(netdev);
> SET_NETDEV_DEV(netdev, &pdev->dev);
> + if (pdev->dev.of_node &&
> + of_get_property(pdev->dev.of_node, "use-nc-si", NULL)) {
> + dev_info(&pdev->dev, "Using NCSI interface\n");
> + priv->phydev = NULL;
> + priv->use_ncsi = true;
> + } else {
> + priv->use_ncsi = false;
> + }
>
> netdev->ethtool_ops = &ftgmac100_ethtool_ops;
> netdev->netdev_ops = &ftgmac100_netdev_ops;
> @@ -1329,7 +1382,6 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> platform_set_drvdata(pdev, netdev);
>
> /* setup private data */
> - priv = netdev_priv(netdev);
> priv->netdev = netdev;
> priv->dev = &pdev->dev;
>
> @@ -1356,24 +1408,14 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
>
> priv->irq = irq;
>
> - /* Check for NC-SI mode */
> - if (pdev->dev.of_node &&
> - of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
> - priv->use_ncsi = true;
> - else
> - priv->use_ncsi = false;
> + /* Read MAC address or setup a new one */
> + ftgmac100_setup_mac(priv);
>
> - /* If we use NC-SI, we need to set that up, which isn't
> implemented yet
> - * so we pray things were setup by the bootloader and just
> mark our link
> - * as up (otherwise we can't get packets through).
> - *
> - * Eventually, we'll have a proper NC-SI stack as a helper
> we can
> - * instanciate
> - */
> + /* Register NCSI device */
> if (priv->use_ncsi) {
> - /* XXX */
> - priv->phydev = NULL;
> - dev_info(&pdev->dev, "Using NC-SI interface\n");
> + priv->ndev = ncsi_register_dev(netdev,
> ftgmac100_ncsi_handler);
> + if (!priv->ndev)
> + goto err_ncsi_dev;
> } else {
> err = ftgmac100_setup_mdio(priv);
>
> @@ -1384,9 +1426,6 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> dev_warn(&pdev->dev, "Error %d setting up
> MDIO\n", err);
> }
>
> - /* Read MAC address or setup a new one */
> - ftgmac100_setup_mac(priv);
> -
> /* Register network device */
> err = register_netdev(netdev);
> if (err) {
> @@ -1399,7 +1438,11 @@ static int ftgmac100_probe(struct
> platform_device *pdev)
> return 0;
>
> err_register_netdev:
> - ftgmac100_destroy_mdio(priv);
> + if (!priv->use_ncsi)
> + ftgmac100_destroy_mdio(priv);
> + else
> + ncsi_unregister_dev(priv->ndev);
> +err_ncsi_dev:
> iounmap(priv->base);
> err_ioremap:
> release_resource(priv->res);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree
2015-11-09 0:10 ` [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree Gavin Shan
@ 2015-11-09 0:36 ` Benjamin Herrenschmidt
2015-11-09 0:45 ` Gavin Shan
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-09 0:36 UTC (permalink / raw)
To: Gavin Shan, netdev; +Cc: davem, sergei.shtylyov
On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
> This enables IP/UDP/TCP offload checksum according to information
> passed on from bootloader through device-tree. The offload doesn't
> working properly when the interface works in NCSI mode.
>
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
> ---
> drivers/net/ethernet/faraday/ftgmac100.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
> index 1b13fd4..1e2f4d2 100644
> --- a/drivers/net/ethernet/faraday/ftgmac100.c
> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
> @@ -1377,7 +1377,10 @@ static int ftgmac100_probe(struct platform_device *pdev)
>
> > > netdev->ethtool_ops = &ftgmac100_ethtool_ops;
> > > netdev->netdev_ops = &ftgmac100_netdev_ops;
> -> > netdev->features = NETIF_F_IP_CSUM | NETIF_F_GRO;
> +> > netdev->features = NETIF_F_GRO;
> +> > if (pdev->dev.of_node &&
> +> > of_property_read_bool(pdev->dev.of_node, "no-hw-checksum"))
> +> > > netdev->features |= NETIF_F_IP_CSUM;
Am I reading properly that if you put "no-hw-checksum" in the device-
tree you *enable* HW checksum ? This doesn't look right to me...
The logic should be:
if (pdev->dev.of_node &&
of_property_read_bool(pdev->dev.of_node, "no-hw-checksum"))
netdev->features &= ~NETIF_F_IP_CSUM;
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 2/6] net/ncsi: Packet handler
2015-11-09 0:10 ` [PATCH RFC 2/6] net/ncsi: Packet handler Gavin Shan
@ 2015-11-09 0:41 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-09 0:41 UTC (permalink / raw)
To: Gavin Shan, netdev; +Cc: davem, sergei.shtylyov
On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
> +
> + /* Send NCSI packet */
> + skb_get(nr->nr_cmd);
> + ret = dev_queue_xmit_sk(NULL, nr->nr_cmd);
> + if (ret)
> + goto out;
> +
Probably just dev_queue_xmit() in recent kernels
This means the queue needs to be running, which means the carrier needs
to be "on".
Dave, this is a problem actually. The NC-SI connection can be to
several NICs that may or may not have a link up. The "stack" will chose
one based on policies that we can discuss separately but basically, I
think we should reflect whether we found a NIC and it has a link up in
the "carrier" setting of our driver.
The problem with doing that is that if the carrier is "off", then
there's some code nowadays that will put a noop qdisc in and we won't
be able to send the low level NC-SI packets to communicate with the NIC
and thus find a new one or get a new carrier indication.
So at the moment, we must have the carrier of the driver appear as
"always on" when using NC-SI.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree
2015-11-09 0:36 ` Benjamin Herrenschmidt
@ 2015-11-09 0:45 ` Gavin Shan
0 siblings, 0 replies; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:45 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: Gavin Shan, netdev, davem, sergei.shtylyov
On Mon, Nov 09, 2015 at 11:36:10AM +1100, Benjamin Herrenschmidt wrote:
>On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
>> This enables IP/UDP/TCP offload checksum according to information
>> passed on from bootloader through device-tree. The offload doesn't
>> working properly when the interface works in NCSI mode.
>>
>> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>> ---
>> drivers/net/ethernet/faraday/ftgmac100.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
>> index 1b13fd4..1e2f4d2 100644
>> --- a/drivers/net/ethernet/faraday/ftgmac100.c
>> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
>> @@ -1377,7 +1377,10 @@ static int ftgmac100_probe(struct platform_device *pdev)
>>
>> > > netdev->ethtool_ops = &ftgmac100_ethtool_ops;
>> > > netdev->netdev_ops = &ftgmac100_netdev_ops;
>> -> > netdev->features = NETIF_F_IP_CSUM | NETIF_F_GRO;
>> +> > netdev->features = NETIF_F_GRO;
>> +> > if (pdev->dev.of_node &&
>> +> > of_property_read_bool(pdev->dev.of_node, "no-hw-checksum"))
>> +> > > netdev->features |= NETIF_F_IP_CSUM;
>
>Am I reading properly that if you put "no-hw-checksum" in the device-
>tree you *enable* HW checksum ? This doesn't look right to me...
>
>The logic should be:
>
> if (pdev->dev.of_node &&
> of_property_read_bool(pdev->dev.of_node, "no-hw-checksum"))
> netdev->features &= ~NETIF_F_IP_CSUM;
>
Thanks, Ben. You're right. This flag affects TCP flows and I didn't test
it with this series of patchset. I'll adjust the code accordingly in next
respin.
Thanks,
Gavin
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi
2015-11-09 0:30 ` Benjamin Herrenschmidt
@ 2015-11-09 0:45 ` Gavin Shan
0 siblings, 0 replies; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 0:45 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: Gavin Shan, netdev, davem, sergei.shtylyov
On Mon, Nov 09, 2015 at 11:30:35AM +1100, Benjamin Herrenschmidt wrote:
>On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
>> This replaces variable name "use_nc_si" with "use_ncsi". No logical
>> changes introduced.
>
>This driver patch is against an internal tree, not upstream. Please
>ignore. The upstream driver doesn't have any concept of "nc_si".
>
>Gavin, next time you respin the series, make sure it's against
>upstream.
>
Sure, Will do.
Thanks,
Gavin
>Cheers,
>Ben.
>
>> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>> ---
>> drivers/net/ethernet/faraday/ftgmac100.c | 14 +++++++-------
>> 1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c
>> b/drivers/net/ethernet/faraday/ftgmac100.c
>> index 08e0336..778bee8 100644
>> --- a/drivers/net/ethernet/faraday/ftgmac100.c
>> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
>> @@ -75,7 +75,7 @@ struct ftgmac100 {
>> struct phy_device *phydev;
>> int old_speed;
>>
>> - bool use_nc_si;
>> + bool use_ncsi;
>> };
>>
>> static int ftgmac100_alloc_rx_page(struct ftgmac100 *priv,
>> @@ -1150,11 +1150,11 @@ static int ftgmac100_open(struct net_device
>> *netdev)
>> goto err_hw;
>>
>> ftgmac100_init_hw(priv);
>> - ftgmac100_start_hw(priv, priv->use_nc_si ? 100 : 10);
>> + ftgmac100_start_hw(priv, priv->use_ncsi ? 100 : 10);
>>
>> if (priv->phydev)
>> phy_start(priv->phydev);
>> - else if (priv->use_nc_si)
>> + else if (priv->use_ncsi)
>> netif_carrier_on(priv->netdev);
>>
>> napi_enable(&priv->napi);
>> @@ -1275,7 +1275,7 @@ err_alloc_mdiobus:
>>
>> static void ftgmac100_destroy_mdio(struct ftgmac100 *priv)
>> {
>> - if (!priv->use_nc_si)
>> + if (!priv->use_ncsi)
>> return;
>> phy_disconnect(priv->phydev);
>> mdiobus_unregister(priv->mii_bus);
>> @@ -1359,9 +1359,9 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> /* Check for NC-SI mode */
>> if (pdev->dev.of_node &&
>> of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
>> - priv->use_nc_si = true;
>> + priv->use_ncsi = true;
>> else
>> - priv->use_nc_si = false;
>> + priv->use_ncsi = false;
>>
>> /* If we use NC-SI, we need to set that up, which isn't
>> implemented yet
>> * so we pray things were setup by the bootloader and just
>> mark our link
>> @@ -1370,7 +1370,7 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> * Eventually, we'll have a proper NC-SI stack as a helper
>> we can
>> * instanciate
>> */
>> - if (priv->use_nc_si) {
>> + if (priv->use_ncsi) {
>> /* XXX */
>> priv->phydev = NULL;
>> dev_info(&pdev->dev, "Using NC-SI interface\n");
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-09 0:32 ` Benjamin Herrenschmidt
@ 2015-11-09 7:30 ` Gavin Shan
2015-11-09 20:28 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-09 7:30 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: Gavin Shan, netdev, davem, sergei.shtylyov
On Mon, Nov 09, 2015 at 11:32:07AM +1100, Benjamin Herrenschmidt wrote:
>On Mon, 2015-11-09 at 11:10 +1100, Gavin Shan wrote:
>>
>> - if (likely(netif_running(netdev))) {
>> + /* When running in NCSI mode, the interface should be
>> + * ready to receive or transmit NCSI packet before it's
>> + * opened.
>> + */
>
>No, that's not right. open/close is when a driver allocates it's data
>structures, DMA ring descriptors, packet buffers etc... and request
>it's interrupts.
>
>You cannot expect packets to flow on a closed interface and you
>shouldn't be getting any interrupts on a closed interface either.
>
Yeah, It's something that I hilighed in the cover letter. I was
thinking we might need a better way to enable Tx/Rx before the
interrupt is up, but couldn't figure out one way. So I need some
advice here.
Thanks,
Gavin
>> + if (likely(priv->use_ncsi || netif_running(netdev))) {
>> /* Disable interrupts for polling */
>> iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
>> napi_schedule(&priv->napi);
>> @@ -1162,8 +1168,18 @@ static int ftgmac100_open(struct net_device
>> *netdev)
>>
>> /* enable all interrupts */
>> iowrite32(INT_MASK_ALL_ENABLED, priv->base +
>> FTGMAC100_OFFSET_IER);
>> + /* Start the NCSI device */
>> + if (priv->use_ncsi){
>> + err = ncsi_start_dev(priv->ndev);
>> + if (err)
>> + goto err_ncsi;
>> + }
>> return 0;
>>
>> +err_ncsi:
>> + napi_disable(&priv->napi);
>> + netif_stop_queue(netdev);
>> + iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
>> err_hw:
>> free_irq(priv->irq, netdev);
>> err_irq:
>> @@ -1172,7 +1188,7 @@ err_alloc:
>> return err;
>> }
>>
>> -static int ftgmac100_stop(struct net_device *netdev)
>> +static int ftgmac100_stop_dev(struct net_device *netdev)
>> {
>> struct ftgmac100 *priv = netdev_priv(netdev);
>>
>> @@ -1191,6 +1207,18 @@ static int ftgmac100_stop(struct net_device
>> *netdev)
>> return 0;
>> }
>>
>> +static int ftgmac100_stop(struct net_device *netdev)
>> +{
>> + struct ftgmac100 *priv = netdev_priv(netdev);
>> +
>> + /* Stop NCSI device */
>> + if (priv->use_ncsi) {
>> + ncsi_stop_dev(priv->ndev);
>> + return 0;
>> + }
>> +
>> + return ftgmac100_stop_dev(netdev);
>> +}
>> static int ftgmac100_hard_start_xmit(struct sk_buff *skb,
>> struct net_device *netdev)
>> {
>> @@ -1291,6 +1319,21 @@ static const struct net_device_ops
>> ftgmac100_netdev_ops = {
>> .ndo_do_ioctl = ftgmac100_do_ioctl,
>> };
>>
>> +static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
>> +{
>> + struct net_device *netdev = nd->nd_dev;
>> +
>> + if (nd->nd_state != ncsi_dev_state_functional)
>> + return;
>> +
>> + if (nd->nd_link_up) {
>> + pr_info("NCSI dev is up\n");
>> + netif_start_queue(netdev);
>> + } else {
>> + pr_info("NCSI dev is down\n");
>> + ftgmac100_stop_dev(netdev);
>> + }
>> +}
>> /*******************************************************************
>> ***********
>> * struct platform_driver functions
>>
>> *********************************************************************
>> ********/
>> @@ -1300,7 +1343,7 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> int irq;
>> struct net_device *netdev;
>> struct ftgmac100 *priv;
>> - int err;
>> + int err = 0;
>>
>> if (!pdev)
>> return -ENODEV;
>> @@ -1320,7 +1363,17 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> goto err_alloc_etherdev;
>> }
>>
>> + /* Check for NCSI mode */
>> + priv = netdev_priv(netdev);
>> SET_NETDEV_DEV(netdev, &pdev->dev);
>> + if (pdev->dev.of_node &&
>> + of_get_property(pdev->dev.of_node, "use-nc-si", NULL)) {
>> + dev_info(&pdev->dev, "Using NCSI interface\n");
>> + priv->phydev = NULL;
>> + priv->use_ncsi = true;
>> + } else {
>> + priv->use_ncsi = false;
>> + }
>>
>> netdev->ethtool_ops = &ftgmac100_ethtool_ops;
>> netdev->netdev_ops = &ftgmac100_netdev_ops;
>> @@ -1329,7 +1382,6 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> platform_set_drvdata(pdev, netdev);
>>
>> /* setup private data */
>> - priv = netdev_priv(netdev);
>> priv->netdev = netdev;
>> priv->dev = &pdev->dev;
>>
>> @@ -1356,24 +1408,14 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>>
>> priv->irq = irq;
>>
>> - /* Check for NC-SI mode */
>> - if (pdev->dev.of_node &&
>> - of_get_property(pdev->dev.of_node, "use-nc-si", NULL))
>> - priv->use_ncsi = true;
>> - else
>> - priv->use_ncsi = false;
>> + /* Read MAC address or setup a new one */
>> + ftgmac100_setup_mac(priv);
>>
>> - /* If we use NC-SI, we need to set that up, which isn't
>> implemented yet
>> - * so we pray things were setup by the bootloader and just
>> mark our link
>> - * as up (otherwise we can't get packets through).
>> - *
>> - * Eventually, we'll have a proper NC-SI stack as a helper
>> we can
>> - * instanciate
>> - */
>> + /* Register NCSI device */
>> if (priv->use_ncsi) {
>> - /* XXX */
>> - priv->phydev = NULL;
>> - dev_info(&pdev->dev, "Using NC-SI interface\n");
>> + priv->ndev = ncsi_register_dev(netdev,
>> ftgmac100_ncsi_handler);
>> + if (!priv->ndev)
>> + goto err_ncsi_dev;
>> } else {
>> err = ftgmac100_setup_mdio(priv);
>>
>> @@ -1384,9 +1426,6 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> dev_warn(&pdev->dev, "Error %d setting up
>> MDIO\n", err);
>> }
>>
>> - /* Read MAC address or setup a new one */
>> - ftgmac100_setup_mac(priv);
>> -
>> /* Register network device */
>> err = register_netdev(netdev);
>> if (err) {
>> @@ -1399,7 +1438,11 @@ static int ftgmac100_probe(struct
>> platform_device *pdev)
>> return 0;
>>
>> err_register_netdev:
>> - ftgmac100_destroy_mdio(priv);
>> + if (!priv->use_ncsi)
>> + ftgmac100_destroy_mdio(priv);
>> + else
>> + ncsi_unregister_dev(priv->ndev);
>> +err_ncsi_dev:
>> iounmap(priv->base);
>> err_ioremap:
>> release_resource(priv->res);
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-09 7:30 ` Gavin Shan
@ 2015-11-09 20:28 ` Benjamin Herrenschmidt
2015-11-10 6:12 ` Gavin Shan
0 siblings, 1 reply; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-09 20:28 UTC (permalink / raw)
To: Gavin Shan; +Cc: netdev, davem, sergei.shtylyov
On Mon, 2015-11-09 at 18:30 +1100, Gavin Shan wrote:
>
> Yeah, It's something that I hilighed in the cover letter. I was
> thinking we might need a better way to enable Tx/Rx before the
> interrupt is up, but couldn't figure out one way. So I need some
> advice here.
No, that's not right. For Tx/Rx to work the interface must be opened,
there is simply no way around that and that's perfectly fine. The
situation with an MDIO PHY is the same, most drivers can't talk to
their PHY until the interface has been opened because the chip is
basically powered down otherwise.
So we require the interface to be opened to talk, so far so good,
the NC-SI stack doesn't even need to open it itself, it's acceptable
to require userspace to do it. IE. Userspace will chose what interface
to use, open it (for DHCP etc... or whatever other reason) and *that*
will then trigger the NC-SI negociation.
Cheers,
Ben.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-09 20:28 ` Benjamin Herrenschmidt
@ 2015-11-10 6:12 ` Gavin Shan
2015-11-10 10:34 ` Benjamin Herrenschmidt
0 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2015-11-10 6:12 UTC (permalink / raw)
To: Benjamin Herrenschmidt; +Cc: Gavin Shan, netdev, davem, sergei.shtylyov
On Tue, Nov 10, 2015 at 07:28:24AM +1100, Benjamin Herrenschmidt wrote:
>On Mon, 2015-11-09 at 18:30 +1100, Gavin Shan wrote:
>>
>> Yeah, It's something that I hilighed in the cover letter. I was
>> thinking we might need a better way to enable Tx/Rx before the
>> interrupt is up, but couldn't figure out one way. So I need some
>> advice here.
>
>No, that's not right. For Tx/Rx to work the interface must be opened,
>there is simply no way around that and that's perfectly fine. The
>situation with an MDIO PHY is the same, most drivers can't talk to
>their PHY until the interface has been opened because the chip is
>basically powered down otherwise.
>
>So we require the interface to be opened to talk, so far so good,
>the NC-SI stack doesn't even need to open it itself, it's acceptable
>to require userspace to do it. IE. Userspace will chose what interface
>to use, open it (for DHCP etc... or whatever other reason) and *that*
>will then trigger the NC-SI negociation.
>
Yes, NCSI is smiliar to PHY to some extent. However, PHY's negotiation
is purly electrical procedure, no packets received from MAC for it. We
have the same situation when the NCSI/PHY is going to be brought down.
At the beginning, the NCSI packets can be received and transmitted after
the interface is opened. Before NCSI negotiation is done, no other packets
can be received and transmitted. For the Rx path (for other packets), the
NCSI link isn't enabled when NCSI negotiation isn't finished. There might
have lots of egress packets whose IP addresses can't be resolved to MAC
address as ARP resolution doesn't work before NCSI negotiation is done.
So there is a weird window: interface is up, but no packets (except NCSI
packets) can be received or transmitted.
When the interface is brought down, for example by "ifconfig eth0 down",
The NCSI interface needs to be teared down by transmitting and receiving
NCSI commands and responses. Similiarly, it introduces another weird window:
interface is down, but NCSI packets still can be transmitted and received.
>Cheers,
>Ben.
>
Thanks,
Gavin
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 5/6] net/faraday: Enable NCSI interface
2015-11-10 6:12 ` Gavin Shan
@ 2015-11-10 10:34 ` Benjamin Herrenschmidt
0 siblings, 0 replies; 19+ messages in thread
From: Benjamin Herrenschmidt @ 2015-11-10 10:34 UTC (permalink / raw)
To: Gavin Shan; +Cc: netdev, davem, sergei.shtylyov
On Tue, 2015-11-10 at 17:12 +1100, Gavin Shan wrote:
>
> > So we require the interface to be opened to talk, so far so good,
> > the NC-SI stack doesn't even need to open it itself, it's acceptable
> > to require userspace to do it. IE. Userspace will chose what interface
> > to use, open it (for DHCP etc... or whatever other reason) and *that*
> > will then trigger the NC-SI negociation.
> >
>
> Yes, NCSI is smiliar to PHY to some extent. However, PHY's negotiation
> is purly electrical procedure, no packets received from MAC for it. We
> have the same situation when the NCSI/PHY is going to be brought down.
Right but we similarily only support PHY nego once the driver is open,
at least on most drivers. The only difference really is that we only
set the netif_carrier_on() when the PHY detects a link, while for NC-SI
we currently need to keep it on always or we lose the queues, but that
can be looked at separately.
> At the beginning, the NCSI packets can be received and transmitted after
> the interface is opened.
Right.
> Before NCSI negotiation is done, no other packets
> can be received and transmitted.
The interface doesn't care. We can transmit them, they just may not go
anywhere, its not our problem. Similarily, the companion NIC may or may
not forward incoming packets before the nego is complete, we don't
actually have to care or enforce anything here.
> For the Rx path (for other packets), the
> NCSI link isn't enabled when NCSI negotiation isn't finished. There might
> have lots of egress packets whose IP addresses can't be resolved to MAC
> address as ARP resolution doesn't work before NCSI negotiation is done.
Correct, but is that a problem ? it's the same thing when we don't have
a link, though I suppose we have a faster path to drop them when the
carrier is down.
> So there is a weird window: interface is up, but no packets (except NCSI
> packets) can be received or transmitted.
Right but that's similar to what we used to do before we had
"intelligent" PHY control... our drivers didn't always know when the
link was up or even if there was a cable plugged.
I agree, it would be nicer to have the "Carrier" follow the
establishment of the NC-SI link, and we should look into fixing that
separately, possibly by establishing a special queue discipline rather
than noop when in that "limbo" mode, but that shouldn't be a blocker
for the patches and certainly doesn't require your driver change that
deals with interrupts while the interface is closed.
> When the interface is brought down, for example by "ifconfig eth0 down",
> The NCSI interface needs to be teared down by transmitting and receiving
> NCSI commands and responses.
That can be done synchronously from the close callback (With timeouts),
can't it ? If the core messes around with our state before close is
called, then we need to do something in the netdev core. However, it's
probably fine to just not do anything, worst case the companion NIC
will forward packets to a closed interface. Not a big deal and
definitely not a show stopper.
> Similiarly, it introduces another weird window:
> interface is down, but NCSI packets still can be transmitted and received.
No, when interface is down, it's down. Nothing comes in and out, we
free the rings, rx skb's, interrupt, it's all gone. We even power down
the NIC in most cases.
Ben.
> > Cheers,
> > Ben.
> >
>
> Thanks,
> Gavin
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 0/6] NCSI Support
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
` (5 preceding siblings ...)
2015-11-09 0:10 ` [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree Gavin Shan
@ 2016-02-24 2:59 ` Gavin Shan
2016-02-24 14:49 ` David Miller
6 siblings, 1 reply; 19+ messages in thread
From: Gavin Shan @ 2016-02-24 2:59 UTC (permalink / raw)
To: Gavin Shan; +Cc: netdev, benh, davem, sergei.shtylyov
On Mon, Nov 09, 2015 at 11:10:00AM +1100, Gavin Shan wrote:
Hello David, did you get time to go through this series? It has been there
for a while. Looking forward to your comments and feedback :-)
Thanks,
Gavin
>This series of patches are prototype requesting for comments. Please focus on
>the big picture at current stage, but any comments to improve the implementaion
>are welcomed.
>
>The following figure gives an example about how NCSI is deployed: The NCSI is
>specified by DSP0222, which can be downloaded from the following link here
>(http://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.0.0.pdf).
>
> * The NC-SI (aka NCSI) is defined as the interface between a (Base) Management
> Controller (BMC) and one or multiple Network Controlers (NC) on host side.
> The interface is responsible for providing external network connectivity
> for BMC.
> * Each BMC can connect to multiple packages, up to 8. Each package can have
> multiple channels, up to 32. Every package and channel are identified by
> 3-bits and 5-bits in NCSI packet. At one moment, one channel is active to
> provide service.
> * NCSI packet, encapsulated in ethernet frame, has 0x88F8 in the protocol
> field. The destination MAC address should be 0xFF's while the source MAC
> address can be arbitrary one.
> * NCSI packets are classified to command, response, AEN (Asynchronous Event
> Notification). Commands are sent from BMC to host for configuration and
> information retrival. Responses, corresponding to commands, are sent from
> host to BMC for confirmation and requested information. One command should
> have one and only one response. AEN is sent from host to BMC for notification
> (e.g. link down on active channel) so that BMC can take appropriate action.
>
> +------------------+ +----------------------------------------------+
> | | | Host |
> | BMC | | |
> | | | +-------------------+ +-------------------+ |
> | +---------+ | | | Package-A | | Package-B | |
> | | | | | +---------+---------+ +-------------------+ |
> | | NIC | | | | Channel | Channel | | Channel | Channel | |
> +----+----+----+---+ +-+---------+---------+--+---------+---------+-+
> | | |
> | | |
> +-----------------------------+----------------------+
>
>The design for the patchset is highlighted as below:
>
> * All the code included in this patchset runs on BMC side. The major target
> of this patchset is to hide the NCSI details to BMC's NIC driver. The patchset
> abstracts a NCSI device (struct ncsi_dev), which is created when the driver
> is loaded and the BMC NIC (struct net_device) instance is created. When the
> NIC is opened (ndo_open()), all available packages and channels are probed
> through NCSI packets. At the same time, one active channel is selected to
> provide service. It means the NIC driver can receive/transmit packets before
> ndo_open().
> * When NCSI device (struct ncsi_dev) is created when NIC driver is loaded,
> NCSI protocl handler is added by dev_add_pack() so that the ingress NCSI
> packets can be routed to the stack for further processing. On the other
> hand, dev_queue_xmit_sk() is called to transmit skb that has been bound
> with the BMC's NIC.
> * The NCSI device is closed when the BMC's NIC is closed.
> * NCSI stack should be configurable through netlink, but it's not implemented
> in this patchset. It's something TBD.
> * The first NIC driver that is aware of NCSI: drivers/net/ethernet/faraday/ftgmac100.c
>
>Gavin Shan (6):
> net/ncsi: Resource management
> net/ncsi: Packet handler
> net/ncsi: Manage NCSI device
> net/faraday: Replace use_nc_si with use_ncsi
> net/faraday: Enable NCSI interface
> net/faraday: Enable offload checksum according to device-tree
>
> drivers/net/ethernet/faraday/ftgmac100.c | 108 ++-
> include/net/ncsi.h | 57 ++
> include/uapi/linux/if_ether.h | 1 +
> net/Kconfig | 1 +
> net/Makefile | 1 +
> net/ncsi/Kconfig | 10 +
> net/ncsi/Makefile | 5 +
> net/ncsi/internal.h | 313 ++++++++
> net/ncsi/ncsi-aen.c | 197 +++++
> net/ncsi/ncsi-cmd.c | 372 ++++++++++
> net/ncsi/ncsi-manage.c | 899 +++++++++++++++++++++++
> net/ncsi/ncsi-pkt.h | 391 ++++++++++
> net/ncsi/ncsi-rsp.c | 1166 ++++++++++++++++++++++++++++++
> 13 files changed, 3490 insertions(+), 31 deletions(-)
> create mode 100644 include/net/ncsi.h
> create mode 100644 net/ncsi/Kconfig
> create mode 100644 net/ncsi/Makefile
> create mode 100644 net/ncsi/internal.h
> create mode 100644 net/ncsi/ncsi-aen.c
> create mode 100644 net/ncsi/ncsi-cmd.c
> create mode 100644 net/ncsi/ncsi-manage.c
> create mode 100644 net/ncsi/ncsi-pkt.h
> create mode 100644 net/ncsi/ncsi-rsp.c
>
>--
>2.1.0
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH RFC 0/6] NCSI Support
2016-02-24 2:59 ` [PATCH RFC 0/6] NCSI Support Gavin Shan
@ 2016-02-24 14:49 ` David Miller
0 siblings, 0 replies; 19+ messages in thread
From: David Miller @ 2016-02-24 14:49 UTC (permalink / raw)
To: gwshan; +Cc: netdev, benh, sergei.shtylyov
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
Date: Wed, 24 Feb 2016 13:59:50 +1100
> Hello David, did you get time to go through this series? It has been there
> for a while. Looking forward to your comments and feedback :-)
Sorry, I personally don't have the time to review it, hopefully one of the
other hundreds of networking developers will be able to do so.
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2016-02-24 14:49 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 0:10 [PATCH RFC 0/6] NCSI Support Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 1/6] net/ncsi: Resource management Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 2/6] net/ncsi: Packet handler Gavin Shan
2015-11-09 0:41 ` Benjamin Herrenschmidt
2015-11-09 0:10 ` [PATCH RFC 3/6] net/ncsi: Manage NCSI device Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 4/6] net/faraday: Replace use_nc_si with use_ncsi Gavin Shan
2015-11-09 0:30 ` Benjamin Herrenschmidt
2015-11-09 0:45 ` Gavin Shan
2015-11-09 0:10 ` [PATCH RFC 5/6] net/faraday: Enable NCSI interface Gavin Shan
2015-11-09 0:32 ` Benjamin Herrenschmidt
2015-11-09 7:30 ` Gavin Shan
2015-11-09 20:28 ` Benjamin Herrenschmidt
2015-11-10 6:12 ` Gavin Shan
2015-11-10 10:34 ` Benjamin Herrenschmidt
2015-11-09 0:10 ` [PATCH RFC 6/6] net/faraday: Enable offload checksum according to device-tree Gavin Shan
2015-11-09 0:36 ` Benjamin Herrenschmidt
2015-11-09 0:45 ` Gavin Shan
2016-02-24 2:59 ` [PATCH RFC 0/6] NCSI Support Gavin Shan
2016-02-24 14:49 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).