Skip to content

Commit 63b53b0

Browse files
chelsiocudbgdavem330
authored andcommitted
cxgb4: fix endian conversions for L4 ports in filters
The source and destination L4 ports in filter offload need to be in CPU endian. They will finally be converted to Big Endian after all operations are done and before giving them to hardware. The L4 ports for NAT are expected to be passed as a byte stream TCB. So, treat them as such. Fixes following sparse warnings in several places: cxgb4_tc_flower.c:159:33: warning: cast from restricted __be16 cxgb4_tc_flower.c:159:33: warning: incorrect type in argument 1 (different base types) cxgb4_tc_flower.c:159:33: expected unsigned short [usertype] val cxgb4_tc_flower.c:159:33: got restricted __be16 [usertype] dst Fixes: dca4fae ("cxgb4: Add LE hash collision bug fix path in LLD driver") Fixes: 62488e4 ("cxgb4: add basic tc flower offload support") Fixes: 557ccbf ("cxgb4: add tc flower support for L3/L4 rewrite") Signed-off-by: Rahul Lakkireddy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 27f78cb commit 63b53b0

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ static void set_nat_params(struct adapter *adap, struct filter_entry *f,
165165
unsigned int tid, bool dip, bool sip, bool dp,
166166
bool sp)
167167
{
168+
u8 *nat_lp = (u8 *)&f->fs.nat_lport;
169+
u8 *nat_fp = (u8 *)&f->fs.nat_fport;
170+
168171
if (dip) {
169172
if (f->fs.type) {
170173
set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W,
@@ -236,8 +239,9 @@ static void set_nat_params(struct adapter *adap, struct filter_entry *f,
236239
}
237240

238241
set_tcb_field(adap, f, tid, TCB_PDU_HDR_LEN_W, WORD_MASK,
239-
(dp ? f->fs.nat_lport : 0) |
240-
(sp ? f->fs.nat_fport << 16 : 0), 1);
242+
(dp ? (nat_lp[1] | nat_lp[0] << 8) : 0) |
243+
(sp ? (nat_fp[1] << 16 | nat_fp[0] << 24) : 0),
244+
1);
241245
}
242246

243247
/* Validate filter spec against configuration done on the card. */
@@ -909,15 +913,18 @@ int set_filter_wr(struct adapter *adapter, int fidx)
909913
fwr->fpm = htons(f->fs.mask.fport);
910914

911915
if (adapter->params.filter2_wr_support) {
916+
u8 *nat_lp = (u8 *)&f->fs.nat_lport;
917+
u8 *nat_fp = (u8 *)&f->fs.nat_fport;
918+
912919
fwr->natmode_to_ulp_type =
913920
FW_FILTER2_WR_ULP_TYPE_V(f->fs.nat_mode ?
914921
ULP_MODE_TCPDDP :
915922
ULP_MODE_NONE) |
916923
FW_FILTER2_WR_NATMODE_V(f->fs.nat_mode);
917924
memcpy(fwr->newlip, f->fs.nat_lip, sizeof(fwr->newlip));
918925
memcpy(fwr->newfip, f->fs.nat_fip, sizeof(fwr->newfip));
919-
fwr->newlport = htons(f->fs.nat_lport);
920-
fwr->newfport = htons(f->fs.nat_fport);
926+
fwr->newlport = htons(nat_lp[1] | nat_lp[0] << 8);
927+
fwr->newfport = htons(nat_fp[1] | nat_fp[0] << 8);
921928
}
922929

923930
/* Mark the filter as "pending" and ship off the Filter Work Request.

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
26092609

26102610
/* Clear out filter specifications */
26112611
memset(&f->fs, 0, sizeof(struct ch_filter_specification));
2612-
f->fs.val.lport = cpu_to_be16(sport);
2612+
f->fs.val.lport = be16_to_cpu(sport);
26132613
f->fs.mask.lport = ~0;
26142614
val = (u8 *)&sip;
26152615
if ((val[0] | val[1] | val[2] | val[3]) != 0) {

drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ static struct ch_tc_pedit_fields pedits[] = {
5858
PEDIT_FIELDS(IP6_, DST_63_32, 4, nat_lip, 4),
5959
PEDIT_FIELDS(IP6_, DST_95_64, 4, nat_lip, 8),
6060
PEDIT_FIELDS(IP6_, DST_127_96, 4, nat_lip, 12),
61-
PEDIT_FIELDS(TCP_, SPORT, 2, nat_fport, 0),
62-
PEDIT_FIELDS(TCP_, DPORT, 2, nat_lport, 0),
63-
PEDIT_FIELDS(UDP_, SPORT, 2, nat_fport, 0),
64-
PEDIT_FIELDS(UDP_, DPORT, 2, nat_lport, 0),
6561
};
6662

6763
static struct ch_tc_flower_entry *allocate_flower_entry(void)
@@ -156,14 +152,14 @@ static void cxgb4_process_flow_match(struct net_device *dev,
156152
struct flow_match_ports match;
157153

158154
flow_rule_match_ports(rule, &match);
159-
fs->val.lport = cpu_to_be16(match.key->dst);
160-
fs->mask.lport = cpu_to_be16(match.mask->dst);
161-
fs->val.fport = cpu_to_be16(match.key->src);
162-
fs->mask.fport = cpu_to_be16(match.mask->src);
155+
fs->val.lport = be16_to_cpu(match.key->dst);
156+
fs->mask.lport = be16_to_cpu(match.mask->dst);
157+
fs->val.fport = be16_to_cpu(match.key->src);
158+
fs->mask.fport = be16_to_cpu(match.mask->src);
163159

164160
/* also initialize nat_lport/fport to same values */
165-
fs->nat_lport = cpu_to_be16(match.key->dst);
166-
fs->nat_fport = cpu_to_be16(match.key->src);
161+
fs->nat_lport = fs->val.lport;
162+
fs->nat_fport = fs->val.fport;
167163
}
168164

169165
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP)) {
@@ -354,25 +350,19 @@ static void process_pedit_field(struct ch_filter_specification *fs, u32 val,
354350
switch (offset) {
355351
case PEDIT_TCP_SPORT_DPORT:
356352
if (~mask & PEDIT_TCP_UDP_SPORT_MASK)
357-
offload_pedit(fs, cpu_to_be32(val) >> 16,
358-
cpu_to_be32(mask) >> 16,
359-
TCP_SPORT);
353+
fs->nat_fport = val;
360354
else
361-
offload_pedit(fs, cpu_to_be32(val),
362-
cpu_to_be32(mask), TCP_DPORT);
355+
fs->nat_lport = val >> 16;
363356
}
364357
fs->nat_mode = NAT_MODE_ALL;
365358
break;
366359
case FLOW_ACT_MANGLE_HDR_TYPE_UDP:
367360
switch (offset) {
368361
case PEDIT_UDP_SPORT_DPORT:
369362
if (~mask & PEDIT_TCP_UDP_SPORT_MASK)
370-
offload_pedit(fs, cpu_to_be32(val) >> 16,
371-
cpu_to_be32(mask) >> 16,
372-
UDP_SPORT);
363+
fs->nat_fport = val;
373364
else
374-
offload_pedit(fs, cpu_to_be32(val),
375-
cpu_to_be32(mask), UDP_DPORT);
365+
fs->nat_lport = val >> 16;
376366
}
377367
fs->nat_mode = NAT_MODE_ALL;
378368
}

0 commit comments

Comments
 (0)