-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ansuel Smith says: ==================== Add support for qca8k mdio rw in Ethernet packet The main reason for this is that we notice some routing problem in the switch and it seems assisted learning is needed. Considering mdio is quite slow due to the indirect write using this Ethernet alternative way seems to be quicker. The qca8k switch supports a special way to pass mdio read/write request using specially crafted Ethernet packet. This works by putting some defined data in the Ethernet header where the mac source and dst should be placed. The Ethernet type header is set to qca header and is set to a mdio read/write type. This is used to communicate to the switch that this is a special packet and should be parsed differently. Currently we use Ethernet packet for - MIB counter - mdio read/write configuration - phy read/write for each port Current implementation of this use completion API to wait for the packet to be processed by the tagger and has a timeout that fallback to the legacy mdio way and mutex to enforce one transaction at time. We now have connect()/disconnect() ops for the tagger. They are used to allocate priv data in the dsa priv. The header still has to be put in global include to make it usable by a dsa driver. They are called when the tag is connect to the dst and the data is freed using discconect on tagger change. (if someone wonder why the bind function is put at in the general setup function it's because tag is set in the cpu port where the notifier is still not available and we require the notifier to sen the tag_proto_connect() event. We now have a tag_proto_connect() for the dsa driver used to put additional data in the tagger priv (that is actually the dsa priv). This is called using a switch event DSA_NOTIFIER_TAG_PROTO_CONNECT. Current use for this is adding handler for the Ethernet packet to keep the tagger code as dumb as possible. The tagger priv implement only the handler for the special packet. All the other stuff is placed in the qca8k_priv and the tagger has to access it under lock. We use the new API from Vladimir to track if the master port is operational or not. We had to track many thing to reach a usable state. Checking if the port is UP is not enough and tracking a NETDEV_CHANGE is also not enough since it use also for other task. The correct way was both track for interface UP and if a qdisc was assigned to the interface. That tells us the port (and the tagger indirectly) is ready to accept and process packet. I tested this with multicpu port and with port6 set as the unique port and it's sad. It seems they implemented this feature in a bad way and this is only supported with cpu port0. When cpu port6 is the unique port, the switch doesn't send ack packet. With multicpu port, packet ack are not duplicated and only cpu port0 sends them. This is the same for the MIB counter. For this reason this feature is enabled only when cpu port0 is enabled and operational. v8: - Reworked to rolling counter for the seq_num - Reworked the hi/lo cache patch - Fix multiple missing skb free and mutex lock errors - Fix some spelling mistake - Add macro build check for mgmt packet size - Change some struct naming to make them more descriptive v7: - Rebase on net-next changes - Add bulk patches to speedup this even more v6: - Fix some error in ethtool handler caused by rebase/cleanup v5: - Adapt to new API fixes - Fix a wrong logic for noop - Add additional lock for master_state change - Limit mdio Ethernet to cpu port0 (switch limitation) - Add priority to these special packet - Move mdio cache to qca8k_priv v4: - Remove duplicate patch sent by mistake. v3: - Include MIB with Ethernet packet. - Include phy read/write with Ethernet packet. - Reorganize code with new API. - Introuce master tracking by Vladimir v2: - Address all suggestion from Vladimir. Try to generilize this with connect/disconnect function from the tagger and tag_proto_connect for the driver. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
9 changed files
with
1,025 additions
and
80 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#ifndef __TAG_QCA_H | ||
#define __TAG_QCA_H | ||
|
||
#define QCA_HDR_LEN 2 | ||
#define QCA_HDR_VERSION 0x2 | ||
|
||
#define QCA_HDR_RECV_VERSION GENMASK(15, 14) | ||
#define QCA_HDR_RECV_PRIORITY GENMASK(13, 11) | ||
#define QCA_HDR_RECV_TYPE GENMASK(10, 6) | ||
#define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3) | ||
#define QCA_HDR_RECV_SOURCE_PORT GENMASK(2, 0) | ||
|
||
/* Packet type for recv */ | ||
#define QCA_HDR_RECV_TYPE_NORMAL 0x0 | ||
#define QCA_HDR_RECV_TYPE_MIB 0x1 | ||
#define QCA_HDR_RECV_TYPE_RW_REG_ACK 0x2 | ||
|
||
#define QCA_HDR_XMIT_VERSION GENMASK(15, 14) | ||
#define QCA_HDR_XMIT_PRIORITY GENMASK(13, 11) | ||
#define QCA_HDR_XMIT_CONTROL GENMASK(10, 8) | ||
#define QCA_HDR_XMIT_FROM_CPU BIT(7) | ||
#define QCA_HDR_XMIT_DP_BIT GENMASK(6, 0) | ||
|
||
/* Packet type for xmit */ | ||
#define QCA_HDR_XMIT_TYPE_NORMAL 0x0 | ||
#define QCA_HDR_XMIT_TYPE_RW_REG 0x1 | ||
|
||
/* Check code for a valid mgmt packet. Switch will ignore the packet | ||
* with this wrong. | ||
*/ | ||
#define QCA_HDR_MGMT_CHECK_CODE_VAL 0x5 | ||
|
||
/* Specific define for in-band MDIO read/write with Ethernet packet */ | ||
#define QCA_HDR_MGMT_SEQ_LEN 4 /* 4 byte for the seq */ | ||
#define QCA_HDR_MGMT_COMMAND_LEN 4 /* 4 byte for the command */ | ||
#define QCA_HDR_MGMT_DATA1_LEN 4 /* First 4 byte for the mdio data */ | ||
#define QCA_HDR_MGMT_HEADER_LEN (QCA_HDR_MGMT_SEQ_LEN + \ | ||
QCA_HDR_MGMT_COMMAND_LEN + \ | ||
QCA_HDR_MGMT_DATA1_LEN) | ||
|
||
#define QCA_HDR_MGMT_DATA2_LEN 12 /* Other 12 byte for the mdio data */ | ||
#define QCA_HDR_MGMT_PADDING_LEN 34 /* Padding to reach the min Ethernet packet */ | ||
|
||
#define QCA_HDR_MGMT_PKT_LEN (QCA_HDR_MGMT_HEADER_LEN + \ | ||
QCA_HDR_LEN + \ | ||
QCA_HDR_MGMT_DATA2_LEN + \ | ||
QCA_HDR_MGMT_PADDING_LEN) | ||
|
||
#define QCA_HDR_MGMT_SEQ_NUM GENMASK(31, 0) /* 63, 32 */ | ||
#define QCA_HDR_MGMT_CHECK_CODE GENMASK(31, 29) /* 31, 29 */ | ||
#define QCA_HDR_MGMT_CMD BIT(28) /* 28 */ | ||
#define QCA_HDR_MGMT_LENGTH GENMASK(23, 20) /* 23, 20 */ | ||
#define QCA_HDR_MGMT_ADDR GENMASK(18, 0) /* 18, 0 */ | ||
|
||
/* Special struct emulating a Ethernet header */ | ||
struct qca_mgmt_ethhdr { | ||
u32 command; /* command bit 31:0 */ | ||
u32 seq; /* seq 63:32 */ | ||
u32 mdio_data; /* first 4byte mdio */ | ||
__be16 hdr; /* qca hdr */ | ||
} __packed; | ||
|
||
enum mdio_cmd { | ||
MDIO_WRITE = 0x0, | ||
MDIO_READ | ||
}; | ||
|
||
struct mib_ethhdr { | ||
u32 data[3]; /* first 3 mib counter */ | ||
__be16 hdr; /* qca hdr */ | ||
} __packed; | ||
|
||
struct qca_tagger_data { | ||
void (*rw_reg_ack_handler)(struct dsa_switch *ds, | ||
struct sk_buff *skb); | ||
void (*mib_autocast_handler)(struct dsa_switch *ds, | ||
struct sk_buff *skb); | ||
}; | ||
|
||
#endif /* __TAG_QCA_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.