[lldp-devel] [PATCH] vdp22 remove pcp and ps from structure definition

Thomas Richter tmricht at linux.vnet.ibm.com
Tue Nov 12 12:48:41 UTC 2013


Remove the Priority code point (PCP) and PCP Significant (PS)
members from the structure fid22. Both members are now stored
in the upper bits in the vlan identifier. This is the same format
as in the TLV definition.

Compare MAC address and group identifiers in the filter
data only when the filter information format indicates
valid data.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 include/qbg_vdp22.h | 30 ++++++++++++++++++++++--
 qbg/vdp22.c         | 34 +++++++++++++++------------
 qbg/vdp22sm.c       | 66 ++++++++++++++---------------------------------------
 3 files changed, 64 insertions(+), 66 deletions(-)

diff --git a/include/qbg_vdp22.h b/include/qbg_vdp22.h
index 8368aae..aa3d5c5 100644
--- a/include/qbg_vdp22.h
+++ b/include/qbg_vdp22.h
@@ -96,8 +96,6 @@ struct fid22 {				/* Filter data: GROUP,MAC,VLAN entry */
 	unsigned long grpid;		/* Group identifier */
 	unsigned char mac[ETH_ALEN];	/* MAC address */
 	unsigned short vlan;		/* VLAN idenfier */
-	unsigned char ps;		/* PS field */
-	unsigned char pcp;		/* PCP valid when PS true */
 	struct vsi_origin requestor;
 };
 
@@ -177,4 +175,32 @@ struct vsi22 *vdp22_copy_vsi(struct vsi22 *);
 void vdp22_listdel_vsi(struct vsi22 *);
 int vdp22br_resources(struct vsi22 *, int *);
 int vdp22_local2str(const u8 *, char *, size_t);
+
+/*
+ * Functions to get and set vlan identifier and qos.
+ */
+static inline unsigned short vdp22_get_ps(unsigned short x)
+{
+	return (x >> 15) & 0x1;
+}
+
+static inline unsigned short vdp22_get_qos(unsigned short x)
+{
+	return (x >> 12) & 0xf;
+}
+
+static inline unsigned short vdp22_set_qos(unsigned short x)
+{
+	return (x & 0xf) << 12;
+}
+
+static inline unsigned short vdp22_get_vlanid(unsigned short x)
+{
+	return x & 0xfff;
+}
+
+static inline unsigned short vdp22_set_vlanid(unsigned short x)
+{
+	return (x & 0xfff);
+}
 #endif
diff --git a/qbg/vdp22.c b/qbg/vdp22.c
index 30b22aa..fdb721e 100644
--- a/qbg/vdp22.c
+++ b/qbg/vdp22.c
@@ -101,31 +101,36 @@ static void showvsifid(char *txt, unsigned char fif, unsigned short no,
 	for (i = 0; i < no; ++i, ++fe) {
 		switch (fif) {
 		case VDP22_FFMT_GROUPVID:
-			LLDPAD_DBG("%s:grpid:%ld vlan:%d ps:%d pcp:%d"
+			LLDPAD_DBG("%s:grpid:%ld vlan:%d qos:%d"
 				   " pid:%d seq:%ld\n", txt, fe->grpid,
-				   fe->vlan, fe->ps, fe->pcp,
+				   vdp22_get_vlanid(fe->vlan),
+				   vdp22_get_qos(fe->vlan),
 				   fe->requestor.req_pid,
 				   fe->requestor.req_seq);
 			break;
 		case VDP22_FFMT_GROUPMACVID:
 			mac2str(fe->mac, idbuf, sizeof idbuf);
-			LLDPAD_DBG("%s:mac:%s grpid:%ld vlan:%d ps:%d"
-				   " pcp:%d pid:%d seq:%ld\n", txt, idbuf,
-				   fe->grpid, fe->vlan, fe->ps, fe->pcp,
+			LLDPAD_DBG("%s:mac:%s grpid:%ld vlan:%d"
+				   " qos:%d pid:%d seq:%ld\n", txt, idbuf,
+				   fe->grpid, vdp22_get_vlanid(fe->vlan),
+				   vdp22_get_qos(fe->vlan),
 				   fe->requestor.req_pid,
 				   fe->requestor.req_seq);
 			break;
 		case VDP22_FFMT_VID:
-			LLDPAD_DBG("%s:vlan:%d ps:%d pcp:%d pid:%d seq:%ld\n",
-				   txt, fe->vlan, fe->ps, fe->pcp,
+			LLDPAD_DBG("%s:vlan:%d qos:%d pid:%d seq:%ld\n",
+				   txt, vdp22_get_vlanid(fe->vlan),
+				   vdp22_get_qos(fe->vlan),
 				   fe->requestor.req_pid,
 				   fe->requestor.req_seq);
 			break;
 		case VDP22_FFMT_MACVID:
 			mac2str(fe->mac, idbuf, sizeof idbuf);
-			LLDPAD_DBG("%s:mac:%s vlan:%d ps:%d pcp:%d"
-				   " pid:%d seq:%ld\n", txt, idbuf, fe->vlan,
-				   fe->ps, fe->pcp, fe->requestor.req_pid,
+			LLDPAD_DBG("%s:mac:%s vlan:%d qos:%d"
+				   " pid:%d seq:%ld\n", txt, idbuf,
+				   vdp22_get_vlanid(fe->vlan),
+				   vdp22_get_qos(fe->vlan),
+				   fe->requestor.req_pid,
 				   fe->requestor.req_seq);
 			break;
 		default:
@@ -408,8 +413,6 @@ static void copy_filter(unsigned char fif, struct fid22 *fp,
 	case VDP22_FFMT_VID:
 vid:
 		fp->vlan = from->vlan;
-		fp->pcp = from->qos;
-		fp->ps = fp->pcp ? 1 : 0;
 		break;
 	}
 }
@@ -426,9 +429,11 @@ static bool check_mac(struct fid22 *fp)
 
 static bool check_vid(struct fid22 *fp)
 {
-	if (fp->vlan > 0 && (fp->vlan < 2 || fp->vlan > 4094))
+	unsigned short num = vdp22_get_vlanid(fp->vlan);
+
+	if (num > 0 && (num < 2 || num > 4094))
 		return false;
-	if (fp->pcp & ~7)
+	if (vdp22_get_qos(fp->vlan) > 15)
 		return false;
 	return true;
 }
@@ -935,7 +940,6 @@ int vdp22_nlback(struct vsi22 *vsi)
 	nl.filter_fmt = vsi->fif;
 	for (i = 0; i < nl.macsz; ++i) {
 		nlmac[i].vlan = vsi->fdata[i].vlan;
-		nlmac[i].qos = vsi->fdata[i].pcp;
 		memcpy(nlmac[i].mac, vsi->fdata[i].mac, sizeof(nlmac[i].mac));
 		nl.req_pid = vsi->fdata[i].requestor.req_pid;
 		nl.req_seq = vsi->fdata[i].requestor.req_seq;
diff --git a/qbg/vdp22sm.c b/qbg/vdp22sm.c
index e7440da..8074a6b 100644
--- a/qbg/vdp22sm.c
+++ b/qbg/vdp22sm.c
@@ -155,39 +155,6 @@ static void vdp22br_run(struct vsi22 *);
 static void vdp22_station_info(struct vsi22 *);
 
 /*
- * Functions to get and set VLAN, PS and PCP bits.
- */
-static inline unsigned short vsi22_get_pcp(unsigned short x)
-{
-	return (x >> 12) & 7;
-}
-
-static inline unsigned short vsi22_set_pcp(unsigned short x)
-{
-	return (x & 7) << 12;
-}
-
-static inline unsigned short vsi22_get_vlanid(unsigned short x)
-{
-	return x & 0xfff;
-}
-
-static inline unsigned short vsi22_set_vlanid(unsigned short x)
-{
-	return (x & 0xfff);
-}
-
-static inline unsigned short vsi22_get_ps(unsigned short x)
-{
-	return (x >> 15) & 1;
-}
-
-static inline unsigned short vsi22_set_ps(unsigned short x)
-{
-	return (x & 1) << 15;
-}
-
-/*
  * Return size of packed and unpacked VSI tlv.
  */
 static inline size_t mgr22_tlv_sz(void)
@@ -335,25 +302,23 @@ static size_t vsi22_2tlv_fdata(unsigned char *cp, struct fid22 *p,
 			       unsigned char fif)
 {
 	size_t nbytes = 0;
-	unsigned short x = vsi22_set_vlanid(p->vlan) |
-				vsi22_set_pcp(p->pcp) | vsi22_set_ps(p->ps);
 
 	switch (fif) {
 	case VDP22_FFMT_VID:
-		nbytes = append_2o(cp, x);
+		nbytes = append_2o(cp, p->vlan);
 		break;
 	case VDP22_FFMT_MACVID:
 		nbytes = append_nb(cp, p->mac, sizeof(p->mac));
-		nbytes += append_2o(cp + nbytes, x);
+		nbytes += append_2o(cp + nbytes, p->vlan);
 		break;
 	case VDP22_FFMT_GROUPVID:
 		nbytes = append_4o(cp, p->grpid);
-		nbytes += append_2o(cp + nbytes, x);
+		nbytes += append_2o(cp + nbytes, p->vlan);
 		break;
 	case VDP22_FFMT_GROUPMACVID:
 		nbytes = append_4o(cp, p->grpid);
 		nbytes += append_nb(cp + nbytes, p->mac, sizeof(p->mac));
-		nbytes += append_2o(cp + nbytes, x);
+		nbytes += append_2o(cp + nbytes, p->vlan);
 		break;
 	}
 	return nbytes;
@@ -947,15 +912,19 @@ static void vdp22_addvsi(struct vsi22 *vsip, struct vdp22 *vdp)
  * All fields are compared, even if some are not used. Unused field are
  * initialized to zeros and always match.
  */
-static bool cmp_fdata1(struct fid22 *p1, struct fid22 *p2)
+static bool cmp_fdata1(struct fid22 *p1, struct fid22 *p2, unsigned char fif)
 {
-	bool is_good = (p1->grpid == p2->grpid)
-			&& !memcmp(p1->mac, p2->mac, sizeof(p1->mac));
+	bool is_good = true;
 
+	if (fif == VDP22_FFMT_MACVID || fif == VDP22_FFMT_GROUPMACVID)
+		is_good = !memcmp(p1->mac, p2->mac, sizeof(p1->mac));
+	if (fif == VDP22_FFMT_GROUPVID || fif == VDP22_FFMT_GROUPMACVID)
+		is_good = (p1->grpid == p2->grpid);
 	if (is_good) {
-		if (p1->ps)
-			is_good = (p1->pcp == p2->pcp && p1->ps == p2->ps);
-		if (is_good && p1->vlan)
+		if (vdp22_get_vlanid(p1->vlan))
+			is_good = (vdp22_get_vlanid(p1->vlan) ==
+					vdp22_get_vlanid(p2->vlan));
+		if (is_good && vdp22_get_ps(p1->vlan))
 			is_good = (p1->vlan == p2->vlan);
 	}
 	return is_good;
@@ -971,8 +940,10 @@ static bool vdp22_cmp_fdata(struct vsi22 *p, struct vsi22 *vsip)
 		struct fid22 *p1 = &p->fdata[i];
 		struct fid22 *p2 = &vsip->fdata[i];
 
-		if (!cmp_fdata1(p1, p2))
+		if (!cmp_fdata1(p1, p2, p->fif)) {
+			p->status = VDP22_RESP_NOADDR;
 			return false;
+		}
 	}
 	return true;
 }
@@ -1158,9 +1129,6 @@ static size_t ptlv_2_fdata(struct fid22 *fidp, const unsigned char *cp,
 		offset += extract_2o(&fidp->vlan, cp + offset);
 		break;
 	}
-	fidp->pcp = vsi22_get_pcp(fidp->vlan);
-	fidp->ps = vsi22_get_ps(fidp->vlan);
-	fidp->vlan = vsi22_get_vlanid(fidp->vlan);
 	return offset;
 }
 
-- 
1.8.3.1



More information about the lldp-devel mailing list