net: mvpp2: Add big-endian support
Subsystems (3)
cover net: mvpp2: Add big-endian support
This series allows to use PPv2 on system built as big endian.
The first patch fixes the way we represent TX and RX descriptors, so that they used fixed little endianness as expected by the PPv2 controller.
The second reworks the way we handle the software representation of the Header Parser entries, so that we don't use a union of arrays.
The last two patches fixes some incorrect byte swapping logic, that wen't un-noticed on little-endian.
This whole series doesn't fix any existing bug for little-endian systems, and since big-endian never worked for this driver, I didn't include 'fixes' tags.
This was tested on MacchiatoBin (Armada 8040).
Maxime Chevallier (4):
net: mvpp2: Make TX / RX descriptors little-endian
net: mvpp2: prs: Drop unions representing TCAM and SRAM entries
net: mvpp2: prs: Drop unnecessary swab16 in vlan detection
net: mvpp2: Use htons when checking protocol info
drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 58 ++++----- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 43 ++++--- drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 155 +++++++++++------------- drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h | 41 +++---- 4 files changed, 141 insertions(+), 156 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/4 net: mvpp2: Make TX / RX descriptors little-endian
The PPv2 controller always expect descriptors to be in little endian. We must therefore force descriptors to use that format, and convert to the host endianness when necessary.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 56 ++++++++++++------------- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 41 +++++++++--------- 2 files changed, 50 insertions(+), 47 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2.h +28 -28
@@ -831,52 +831,52 @@ struct mvpp2_port {/* HW TX descriptor for PPv2.1 */ struct mvpp21_tx_desc { -u32 command;/* Options used by HW for packet transmitting.*/ +__le32 command;/* Options used by HW for packet transmitting.*/ u8 packet_offset;/* the offset from the buffer beginning */ u8 phys_txq;/* destination queue ID */ -u16 data_size;/* data size of transmitted packet in bytes */ -u32 buf_dma_addr;/* physical addr of transmitted buffer */ -u32 buf_cookie;/* cookie for access to TX buffer in tx path */ -u32 reserved1[3 ];/* hw_cmd (for future use, BM, PON, PNC) */ -u32 reserved2;/* reserved (for future use) */ +__le16 data_size;/* data size of transmitted packet in bytes */ +__le32 buf_dma_addr;/* physical addr of transmitted buffer */ +__le32 buf_cookie;/* cookie for access to TX buffer in tx path */ +__le32 reserved1[3 ];/* hw_cmd (for future use, BM, PON, PNC) */ +__le32 reserved2;/* reserved (for future use) */ };/* HW RX descriptor for PPv2.1 */ struct mvpp21_rx_desc { -u32 status;/* info about received packet */ -u16 reserved1;/* parser_info (for future use, PnC) */ -u16 data_size;/* size of received packet in bytes */ -u32 buf_dma_addr;/* physical address of the buffer */ -u32 buf_cookie;/* cookie for access to RX buffer in rx path */ -u16 reserved2;/* gem_port_id (for future use, PON) */ -u16 reserved3;/* csum_l4 (for future use, PnC) */ +__le32 status;/* info about received packet */ +__le16 reserved1;/* parser_info (for future use, PnC) */ +__le16 data_size;/* size of received packet in bytes */ +__le32 buf_dma_addr;/* physical address of the buffer */ +__le32 buf_cookie;/* cookie for access to RX buffer in rx path */ +__le16 reserved2;/* gem_port_id (for future use, PON) */ +__le16 reserved3;/* csum_l4 (for future use, PnC) */ u8 reserved4;/* bm_qset (for future use, BM) */ u8 reserved5; -u16 reserved6;/* classify_info (for future use, PnC) */ -u32 reserved7;/* flow_id (for future use, PnC) */ -u32 reserved8; +__le16 reserved6;/* classify_info (for future use, PnC) */ +__le32 reserved7;/* flow_id (for future use, PnC) */ +__le32 reserved8; };/* HW TX descriptor for PPv2.2 */ struct mvpp22_tx_desc { -u32 command; +__le32 command;u8 packet_offset;u8 phys_txq; -u16 data_size; -u64 reserved1; -u64 buf_dma_addr_ptp; -u64 buf_cookie_misc; +__le16 data_size; +__le64 reserved1; +__le64 buf_dma_addr_ptp; +__le64 buf_cookie_misc; };/* HW RX descriptor for PPv2.2 */ struct mvpp22_rx_desc { -u32 status; -u16 reserved1; -u16 data_size; -u32 reserved2; -u32 reserved3; -u64 buf_dma_addr_key_hash; -u64 buf_cookie_misc; +__le32 status; +__le16 reserved1; +__le16 data_size; +__le32 reserved2; +__le32 reserved3; +__le64 buf_dma_addr_key_hash; +__le64 buf_cookie_misc; };/* Opaque type used by the driver to manipulate the HW TX and RX
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +22 -19
106 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 2/4 net: mvpp2: prs: Drop unions representing TCAM and SRAM entries
In reply to Maxime ChevallierPPv2's Header Parser use some large TCAM and SRAM entries, that are duplicated in software so that we can write them to hardware only when we are done modifying them.
Currently, PPv2 uses a union containing arrays of u32 and u8 to represent these entries, to facilitate byte per byte access. This representation is broken when we want to support big endian, and this makes the code confusing to read.
This patch drops the union, and simply stores the TCAM and SRAM entries as u32 arrays, each entry corresponding to a 32-bit register.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 2 + drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 149 +++++++++++-------------- drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h | 41 ++++--- 3 files changed, 87 insertions(+), 105 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2.h +2 -0
@@ -553,6 +553,8 @@ ((total_size) - NET_SKB_PAD - MVPP2_SKB_SHINFO_SIZE)#define MVPP2_BIT_TO_BYTE (bit) ((bit) / 8) +#define MVPP2_BIT_TO_WORD (bit) ((bit) / 32) +#define MVPP2_BIT_IN_WORD (bit) ((bit) % 32)/* IPv6 max L3 address size */ #define MVPP2_MAX_L3_ADDR_SIZE 16
drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c +65 -84
332 lines not on this page · raw message
drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h +20 -21
63 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 3/4 net: mvpp2: prs: Drop unnecessary swab16 in vlan detection
In reply to Maxime ChevallierVlan IDs must not be swapped when creating Header Parser entries. This has no effect on little-endian systems, but is wrong for big-endian.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c +3 -3
@@ -647,7 +647,7 @@ static int mvpp2_prs_vlan_find(struct mvpp2 *priv, unsigned short tpid, int ai)continue ;mvpp2_prs_init_from_hw (priv, &pe, tid); - match =mvpp2_prs_tcam_data_cmp (&pe,0 ,swab16 (tpid)); + match =mvpp2_prs_tcam_data_cmp (&pe,0 , tpid);if (!match)continue ;
@@ -775,8 +775,8 @@ static int mvpp2_prs_double_vlan_find(struct mvpp2 *priv, unsigned short tpid1,mvpp2_prs_init_from_hw (priv, &pe, tid); - match =mvpp2_prs_tcam_data_cmp (&pe,0 ,swab16 (tpid1)) && -mvpp2_prs_tcam_data_cmp (&pe,4 ,swab16 (tpid2)); + match =mvpp2_prs_tcam_data_cmp (&pe,0 , tpid1) && +mvpp2_prs_tcam_data_cmp (&pe,4 , tpid2);if (!match)continue ;
Signature · 1 line
2.11.0
PATCH 4/4 net: mvpp2: Use htons when checking protocol info
In reply to Maxime ChevallierWhen checking the skb->protocol field, we have to make sure we use the proper endianness using htons, and not swab16.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +1 -1
@@ -1738,7 +1738,7 @@ static u32 mvpp2_txq_desc_csum(int l3_offs, int l3_proto, command |= (ip_hdr_len <<MVPP2_TXD_IP_HLEN_SHIFT ); command |=MVPP2_TXD_IP_CSUM_DISABLE ; -if (l3_proto ==swab16 (ETH_P_IP )) { +if (l3_proto ==htons (ETH_P_IP )) { command &= ~MVPP2_TXD_IP_CSUM_DISABLE ;/* enable IPv4 csum */ command &= ~MVPP2_TXD_L3_IP6 ;/* enable IPv4 */ }else {
Signature · 1 line
2.11.0