Skip to contentSkip to conversation

bnx2x: endianness fixes

PATCH In review Michal Schmidt 3 participants 10 messages Mar 2, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover bnx2x: endianness fixes

Hello,
this fixes a VLAN crash and some SRIOV bugs in bnx2x observed on ppc64.

Michal Schmidt (7):
bnx2x: fix crash on big-endian when adding VLAN
bnx2x: fix sending VF->PF messages on big-endian
bnx2x: fix receive of VF->PF mailbox messages by the PF on big-endian
bnx2x: access cfc_del_event only if the opcode is CFC_DEL
bnx2x: define fields of struct cfc_del_event_data as little-endian
bnx2x: define event data reserved fields as little-endian
bnx2x: fix indentation in bnx2x_sp_task()

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h   | 36 ++++++++++-------------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 22 +++++++-------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 12 ++++----
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c  |  4 +--
 4 files changed, 32 insertions(+), 42 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/7 bnx2x: fix crash on big-endian when adding VLAN

bnx2x crashes during the initialization of the 8021q module on ppc64. The bug is a missing conversion from le32 in bnx2x_handle_classification_eqe() when obtaining the cid value from struct eth_event_data.

The fields in struct eth_event_data should all be declared as little-endian and conversions added where missing.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h   |  6 +++---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 13 +++++--------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c |  9 ++++-----
 3 files changed, 12 insertions(+), 16 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +3 -3
index 27aa080..90a4dba 100644
@@ -5207,9 +5207,9 @@ struct e2_integ_data {
  * set mac event data
  */
 struct eth_event_data {
-	u32 echo;
-	u32 reserved0;
-	u32 reserved1;
+	__le32 echo;
+	__le32 reserved0;
+	__le32 reserved1;
 };
 
 
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +5 -8
index 6c4e3a6..b707ba8 100644
@@ -5280,14 +5280,14 @@ static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
 {
 	unsigned long ramrod_flags = 0;
 	int rc = 0;
-	u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
+	u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
+	u32 cid = echo & BNX2X_SWCID_MASK;
 	struct bnx2x_vlan_mac_obj *vlan_mac_obj;
 
 	/* Always push next commands out, don't wait here */
 	__set_bit(RAMROD_CONT, &ramrod_flags);
 
-	switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
-			    >> BNX2X_SWCID_SHIFT) {
+	switch (echo >> BNX2X_SWCID_SHIFT) {
 	case BNX2X_FILTER_MAC_PENDING:
 		DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
 		if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
@@ -5308,8 +5308,7 @@ static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
 		bnx2x_handle_mcast_eqe(bp);
 		return;
 	default:
-		BNX2X_ERR("Unsupported classification command: %d\n",
-			  elem->message.data.eth_event.echo);
+		BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
 		return;
 	}
 
@@ -5596,10 +5595,8 @@ static void bnx2x_eq_int(struct bnx2x *bp)
 		      BNX2X_STATE_OPENING_WAIT4_PORT):
 		case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
 		      BNX2X_STATE_CLOSING_WAIT4_HALT):
-			cid = elem->message.data.eth_event.echo &
-				BNX2X_SWCID_MASK;
 			DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
-			   cid);
+			   SW_CID(elem->message.data.eth_event.echo));
 			rss_raw->clear_pending(rss_raw);
 			break;
 
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c +4 -5
index 9d02734..55fcc21 100644
@@ -1672,11 +1672,12 @@ void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
 {
 	unsigned long ramrod_flags = 0;
 	int rc = 0;
+	u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
 
 	/* Always push next commands out, don't wait here */
 	set_bit(RAMROD_CONT, &ramrod_flags);
 
-	switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
+	switch (echo >> BNX2X_SWCID_SHIFT) {
 	case BNX2X_FILTER_MAC_PENDING:
 		rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
 					   &ramrod_flags);
@@ -1686,8 +1687,7 @@ void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
 					    &ramrod_flags);
 		break;
 	default:
-		BNX2X_ERR("Unsupported classification command: %d\n",
-			  elem->message.data.eth_event.echo);
+		BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
 		return;
 	}
 	if (rc < 0)
@@ -1755,8 +1755,7 @@ int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
 	case EVENT_RING_OPCODE_MULTICAST_RULES:
 	case EVENT_RING_OPCODE_FILTERS_RULES:
 	case EVENT_RING_OPCODE_RSS_UPDATE_RULES:
-		cid = (elem->message.data.eth_event.echo &
-		       BNX2X_SWCID_MASK);
+		cid = SW_CID(elem->message.data.eth_event.echo);
 		DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
 		break;
 	case EVENT_RING_OPCODE_VF_FLR:
Signature · 1 line
2.5.0
#2 lore raw

PATCH 2/7 bnx2x: fix sending VF->PF messages on big-endian

In reply to Michal Schmidt

When a VF is sending a message to the PF, it needs to trigger the PF to tell it the message is ready.
The trigger did not work on ppc64. No interrupt appeared in the PF.

The bug is due to confusion about the layout of struct trigger_vf_zone. In bnx2x_send_msg2pf() the trigger is written using writeb(), not writel(), so the attempt to define the struct with a reversed layout on big-endian is counter-productive.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h | 6 ------
 1 file changed, 6 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +0 -6
index 90a4dba..47b13ed 100644
@@ -5114,15 +5114,9 @@ struct vf_pf_channel_zone_trigger {
  * zone that triggers the in-bound interrupt
  */
 struct trigger_vf_zone {
-#if defined(__BIG_ENDIAN)
-	u16 reserved1;
-	u8 reserved0;
-	struct vf_pf_channel_zone_trigger vf_pf_channel;
-#elif defined(__LITTLE_ENDIAN)
 	struct vf_pf_channel_zone_trigger vf_pf_channel;
 	u8 reserved0;
 	u16 reserved1;
-#endif
 	u32 reserved2;
 };
 
Signature · 1 line
2.5.0
#3 lore raw

PATCH 3/7 bnx2x: fix receive of VF->PF mailbox messages by the PF on big-endian

In reply to Michal Schmidt

On ppc64 the PF did not receive messages from VFs correctly.

Fields of struct vf_pf_event_data are little-endian.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h  | 6 +++---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c | 6 ++++--
 2 files changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +3 -3
index 47b13ed..1058591 100644
@@ -5213,9 +5213,9 @@ struct eth_event_data {
 struct vf_pf_event_data {
 	u8 vf_id;
 	u8 reserved0;
-	u16 reserved1;
-	u32 msg_addr_lo;
-	u32 msg_addr_hi;
+	__le16 reserved1;
+	__le32 msg_addr_lo;
+	__le32 msg_addr_hi;
 };
 
 /*
drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c +4 -2
index 1374e53..bfae300 100644
@@ -2187,8 +2187,10 @@ void bnx2x_vf_mbx_schedule(struct bnx2x *bp,
 
 	/* Update VFDB with current message and schedule its handling */
 	mutex_lock(&BP_VFDB(bp)->event_mutex);
-	BP_VF_MBX(bp, vf_idx)->vf_addr_hi = vfpf_event->msg_addr_hi;
-	BP_VF_MBX(bp, vf_idx)->vf_addr_lo = vfpf_event->msg_addr_lo;
+	BP_VF_MBX(bp, vf_idx)->vf_addr_hi =
+		le32_to_cpu(vfpf_event->msg_addr_hi);
+	BP_VF_MBX(bp, vf_idx)->vf_addr_lo =
+		le32_to_cpu(vfpf_event->msg_addr_lo);
 	BP_VFDB(bp)->event_occur |= (1ULL << vf_idx);
 	mutex_unlock(&BP_VFDB(bp)->event_mutex);
 
Signature · 1 line
2.5.0
#4 lore raw

PATCH 4/7 bnx2x: access cfc_del_event only if the opcode is CFC_DEL

In reply to Michal Schmidt

It's not really a bug, but it was odd that bnx2x_eq_int() read the message data as if it were a cfc_del_event regardless of the event type. It's cleaner to access only the appropriate member of union event_data after checking the event opcode.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +5 -3
index b707ba8..0e0bcbd 100644
@@ -5477,9 +5477,6 @@ static void bnx2x_eq_int(struct bnx2x *bp)
 			goto next_spqe;
 		}
 
-		/* elem CID originates from FW; actually LE */
-		cid = SW_CID((__force __le32)
-			     elem->message.data.cfc_del_event.cid);
 		opcode = elem->message.opcode;
 
 		/* handle eq element */
@@ -5502,6 +5499,11 @@ static void bnx2x_eq_int(struct bnx2x *bp)
 			 * we may want to verify here that the bp state is
 			 * HALTING
 			 */
+
+			/* elem CID originates from FW; actually LE */
+			cid = SW_CID((__force __le32)
+				     elem->message.data.cfc_del_event.cid);
+
 			DP(BNX2X_MSG_SP,
 			   "got delete ramrod for MULTI[%d]\n", cid);
 
Signature · 1 line
2.5.0
#5 lore raw

PATCH 5/7 bnx2x: define fields of struct cfc_del_event_data as little-endian

In reply to Michal Schmidt

There were no missing endianness conversions in this case, but the fields of struct cfc_del_event_data should be defined as little-endian to get rid of the ugly (__force __le32) casts.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h   | 6 +++---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 3 +--
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 3 +--
 3 files changed, 5 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +3 -3
index 1058591..a24909a 100644
@@ -4896,9 +4896,9 @@ struct c2s_pri_trans_table_entry {
  * cfc delete event data
  */
 struct cfc_del_event_data {
-	u32 cid;
-	u32 reserved0;
-	u32 reserved1;
+	__le32 cid;
+	__le32 reserved0;
+	__le32 reserved1;
 };
 
 
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1 -2
index 0e0bcbd..9f5716a 100644
@@ -5501,8 +5501,7 @@ static void bnx2x_eq_int(struct bnx2x *bp)
 			 */
 
 			/* elem CID originates from FW; actually LE */
-			cid = SW_CID((__force __le32)
-				     elem->message.data.cfc_del_event.cid);
+			cid = SW_CID(elem->message.data.cfc_del_event.cid);
 
 			DP(BNX2X_MSG_SP,
 			   "got delete ramrod for MULTI[%d]\n", cid);
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c +1 -2
index 55fcc21..632daff 100644
@@ -1747,8 +1747,7 @@ int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
 
 	switch (opcode) {
 	case EVENT_RING_OPCODE_CFC_DEL:
-		cid = SW_CID((__force __le32)
-			     elem->message.data.cfc_del_event.cid);
+		cid = SW_CID(elem->message.data.cfc_del_event.cid);
 		DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
 		break;
 	case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
Signature · 1 line
2.5.0
#6 lore raw

PATCH 6/7 bnx2x: define event data reserved fields as little-endian

In reply to Michal Schmidt

For consistency with other event data structs and to lessen the chance of a mistake should one of the reserved fields become used in the future, define the reserved fields as little-endian.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h +6 -6
index a24909a..91874d2 100644
@@ -5224,9 +5224,9 @@ struct vf_pf_event_data {
 struct vf_flr_event_data {
 	u8 vf_id;
 	u8 reserved0;
-	u16 reserved1;
-	u32 reserved2;
-	u32 reserved3;
+	__le16 reserved1;
+	__le32 reserved2;
+	__le32 reserved3;
 };
 
 /*
@@ -5235,9 +5235,9 @@ struct vf_flr_event_data {
 struct malicious_vf_event_data {
 	u8 vf_id;
 	u8 err_id;
-	u16 reserved1;
-	u32 reserved2;
-	u32 reserved3;
+	__le16 reserved1;
+	__le32 reserved2;
+	__le32 reserved3;
 };
 
 /*
Signature · 1 line
2.5.0
#7 lore raw

PATCH 7/7 bnx2x: fix indentation in bnx2x_sp_task()

In reply to Michal Schmidt

Fix a case of misleading code indentation.

---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c +1 -1
index 9f5716a..2bf9c87 100644
@@ -5682,7 +5682,7 @@ static void bnx2x_sp_task(struct work_struct *work)
 		if (status & BNX2X_DEF_SB_IDX) {
 			struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
 
-		if (FCOE_INIT(bp) &&
+			if (FCOE_INIT(bp) &&
 			    (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
 				/* Prevent local bottom-halves from running as
 				 * we are going to change the local NAPI list.
Signature · 1 line
2.5.0
Acked-by on the v1 series
#8 lore raw
In reply to Michal Schmidt
Quoted 19 lines

-----Original Message-----
From: Michal Schmidt [mailto:[email protected]]
Sent: Wednesday, March 02, 2016 2:47 PM
To: netdev <[email protected]>
Cc: Yuval Mintz <[email protected]>; Ariel Elior <[email protected]>
Subject: [PATCH net 0/7] bnx2x: endianness fixes

Hello,
this fixes a VLAN crash and some SRIOV bugs in bnx2x observed on ppc64.

Michal Schmidt (7):
bnx2x: fix crash on big-endian when adding VLAN
bnx2x: fix sending VF->PF messages on big-endian
bnx2x: fix receive of VF->PF mailbox messages by the PF on big-endian
bnx2x: access cfc_del_event only if the opcode is CFC_DEL
bnx2x: define fields of struct cfc_del_event_data as little-endian
bnx2x: define event data reserved fields as little-endian
bnx2x: fix indentation in bnx2x_sp_task()

Quoted 8 lines
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_hsi.h   | 36 ++++++++++-------------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 22 +++++++-------
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 12 ++++----
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_vfpf.c  |  4 +--
 4 files changed, 32 insertions(+), 42 deletions(-)

--
2.5.0

Hi Michal,
Thanks for making these changes!