Skip to content

Commit 4476481

Browse files
edmitardavem330
authored andcommitted
caif: set traffic class for caif packets
Set traffic class for CAIF packets, based on socket priority, CAIF protocol type, or type of message. Traffic class mapping for different packet types: - control: TC_PRIO_CONTROL; - flow control: TC_PRIO_CONTROL; - at: TC_PRIO_CONTROL; - rfm: TC_PRIO_INTERACTIVE_BULK; - other sockets: equals to socket's TC; - network data: no change. Signed-off-by: Dmitry Tarnyagin <dmitry.tarnyagin@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e65ac4d commit 4476481

5 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎include/net/caif/cfpkt.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,18 @@ struct cfpkt *cfpkt_fromnative(enum caif_direction dir, void *nativepkt);
188188
*/
189189
void *cfpkt_tonative(struct cfpkt *pkt);
190190

191-
192191
/*
193192
* Returns packet information for a packet.
194193
* pkt Packet to get info from;
195194
* @return Packet information
196195
*/
197196
struct caif_payload_info *cfpkt_info(struct cfpkt *pkt);
197+
198+
/** cfpkt_set_prio - set priority for a CAIF packet.
199+
*
200+
* @pkt: The CAIF packet to be adjusted.
201+
* @prio: one of TC_PRIO_ constants.
202+
*/
203+
void cfpkt_set_prio(struct cfpkt *pkt, int prio);
204+
198205
#endif /* CFPKT_H_ */

‎net/caif/caif_socket.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <linux/uaccess.h>
2020
#include <linux/debugfs.h>
2121
#include <linux/caif/caif_socket.h>
22-
#include <linux/atomic.h>
22+
#include <linux/pkt_sched.h>
2323
#include <net/sock.h>
2424
#include <net/tcp_states.h>
2525
#include <net/caif/caif_layer.h>
@@ -505,6 +505,7 @@ static int transmit_skb(struct sk_buff *skb, struct caifsock *cf_sk,
505505

506506
pkt = cfpkt_fromnative(CAIF_DIR_OUT, skb);
507507
memset(skb->cb, 0, sizeof(struct caif_payload_info));
508+
cfpkt_set_prio(pkt, cf_sk->sk.sk_priority);
508509

509510
if (cf_sk->layer.dn == NULL) {
510511
kfree_skb(skb);
@@ -1062,6 +1063,18 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
10621063
/* Store the protocol */
10631064
sk->sk_protocol = (unsigned char) protocol;
10641065

1066+
/* Initialize default priority for well-known cases */
1067+
switch (protocol) {
1068+
case CAIFPROTO_AT:
1069+
sk->sk_priority = TC_PRIO_CONTROL;
1070+
break;
1071+
case CAIFPROTO_RFM:
1072+
sk->sk_priority = TC_PRIO_INTERACTIVE_BULK;
1073+
break;
1074+
default:
1075+
sk->sk_priority = TC_PRIO_BESTEFFORT;
1076+
}
1077+
10651078
/*
10661079
* Lock in order to try to stop someone from opening the socket
10671080
* too early.
@@ -1081,7 +1094,6 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
10811094
set_rx_flow_on(cf_sk);
10821095

10831096
/* Set default options on configuration */
1084-
cf_sk->sk.sk_priority = CAIF_PRIO_NORMAL;
10851097
cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY;
10861098
cf_sk->conn_req.protocol = protocol;
10871099
release_sock(&cf_sk->sk);

‎net/caif/cfctrl.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/stddef.h>
1010
#include <linux/spinlock.h>
1111
#include <linux/slab.h>
12+
#include <linux/pkt_sched.h>
1213
#include <net/caif/caif_layer.h>
1314
#include <net/caif/cfpkt.h>
1415
#include <net/caif/cfctrl.h>
@@ -189,6 +190,7 @@ void cfctrl_enum_req(struct cflayer *layer, u8 physlinkid)
189190
cfctrl->serv.dev_info.id = physlinkid;
190191
cfpkt_addbdy(pkt, CFCTRL_CMD_ENUM);
191192
cfpkt_addbdy(pkt, physlinkid);
193+
cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
192194
dn->transmit(dn, pkt);
193195
}
194196

@@ -281,6 +283,7 @@ int cfctrl_linkup_request(struct cflayer *layer,
281283
* might arrive with the newly allocated channel ID.
282284
*/
283285
cfpkt_info(pkt)->dev_info->id = param->phyid;
286+
cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
284287
ret =
285288
dn->transmit(dn, pkt);
286289
if (ret < 0) {
@@ -314,6 +317,7 @@ int cfctrl_linkdown_req(struct cflayer *layer, u8 channelid,
314317
cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_DESTROY);
315318
cfpkt_addbdy(pkt, channelid);
316319
init_info(cfpkt_info(pkt), cfctrl);
320+
cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
317321
ret =
318322
dn->transmit(dn, pkt);
319323
#ifndef CAIF_NO_LOOP

‎net/caif/cfpkt_skbuff.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ struct cfpkt *cfpkt_split(struct cfpkt *pkt, u16 pos)
381381
memcpy(skb2->data, split, len2nd);
382382
skb2->tail += len2nd;
383383
skb2->len += len2nd;
384+
skb2->priority = skb->priority;
384385
return skb_to_pkt(skb2);
385386
}
386387

@@ -394,3 +395,9 @@ struct caif_payload_info *cfpkt_info(struct cfpkt *pkt)
394395
return (struct caif_payload_info *)&pkt_to_skb(pkt)->cb;
395396
}
396397
EXPORT_SYMBOL(cfpkt_info);
398+
399+
void cfpkt_set_prio(struct cfpkt *pkt, int prio)
400+
{
401+
pkt_to_skb(pkt)->priority = prio;
402+
}
403+
EXPORT_SYMBOL(cfpkt_set_prio);

‎net/caif/cfsrvl.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/errno.h>
1212
#include <linux/slab.h>
1313
#include <linux/module.h>
14+
#include <linux/pkt_sched.h>
1415
#include <net/caif/caif_layer.h>
1516
#include <net/caif/cfsrvl.h>
1617
#include <net/caif/cfpkt.h>
@@ -120,6 +121,7 @@ static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl)
120121
info->channel_id = service->layer.id;
121122
info->hdr_len = 1;
122123
info->dev_info = &service->dev_info;
124+
cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
123125
return layr->dn->transmit(layr->dn, pkt);
124126
}
125127
case CAIF_MODEMCMD_FLOW_OFF_REQ:
@@ -140,6 +142,7 @@ static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl)
140142
info->channel_id = service->layer.id;
141143
info->hdr_len = 1;
142144
info->dev_info = &service->dev_info;
145+
cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
143146
return layr->dn->transmit(layr->dn, pkt);
144147
}
145148
default:

0 commit comments

Comments
 (0)