caif_socket.c (57b8628bb0ac4e47c806e45c5bbd89282e93869b) caif_socket.c (e87cc4728f0e2fb663e592a1141742b1d6c63256)
1/*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Author: Sjur Brendeland sjur.brandeland@stericsson.com
4 * License terms: GNU General Public License (GPL) version 2
5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8

--- 5 unchanged lines hidden (view full) ---

14#include <linux/mutex.h>
15#include <linux/list.h>
16#include <linux/wait.h>
17#include <linux/poll.h>
18#include <linux/tcp.h>
19#include <linux/uaccess.h>
20#include <linux/debugfs.h>
21#include <linux/caif/caif_socket.h>
1/*
2 * Copyright (C) ST-Ericsson AB 2010
3 * Author: Sjur Brendeland sjur.brandeland@stericsson.com
4 * License terms: GNU General Public License (GPL) version 2
5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
8

--- 5 unchanged lines hidden (view full) ---

14#include <linux/mutex.h>
15#include <linux/list.h>
16#include <linux/wait.h>
17#include <linux/poll.h>
18#include <linux/tcp.h>
19#include <linux/uaccess.h>
20#include <linux/debugfs.h>
21#include <linux/caif/caif_socket.h>
22#include <linux/atomic.h>
22#include <linux/pkt_sched.h>
23#include <net/sock.h>
24#include <net/tcp_states.h>
25#include <net/caif/caif_layer.h>
26#include <net/caif/caif_dev.h>
27#include <net/caif/cfpkt.h>
28
29MODULE_LICENSE("GPL");
30MODULE_ALIAS_NETPROTO(AF_CAIF);

--- 94 unchanged lines hidden (view full) ---

125{
126 int err;
127 int skb_len;
128 unsigned long flags;
129 struct sk_buff_head *list = &sk->sk_receive_queue;
130 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk);
131
132 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
23#include <net/sock.h>
24#include <net/tcp_states.h>
25#include <net/caif/caif_layer.h>
26#include <net/caif/caif_dev.h>
27#include <net/caif/cfpkt.h>
28
29MODULE_LICENSE("GPL");
30MODULE_ALIAS_NETPROTO(AF_CAIF);

--- 94 unchanged lines hidden (view full) ---

125{
126 int err;
127 int skb_len;
128 unsigned long flags;
129 struct sk_buff_head *list = &sk->sk_receive_queue;
130 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk);
131
132 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
133 (unsigned)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) {
134 if (net_ratelimit())
135 pr_debug("sending flow OFF (queue len = %d %d)\n",
136 atomic_read(&cf_sk->sk.sk_rmem_alloc),
137 sk_rcvbuf_lowwater(cf_sk));
133 (unsigned int)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) {
134 net_dbg_ratelimited("sending flow OFF (queue len = %d %d)\n",
135 atomic_read(&cf_sk->sk.sk_rmem_alloc),
136 sk_rcvbuf_lowwater(cf_sk));
138 set_rx_flow_off(cf_sk);
139 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
140 }
141
142 err = sk_filter(sk, skb);
143 if (err)
144 return err;
145 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
146 set_rx_flow_off(cf_sk);
137 set_rx_flow_off(cf_sk);
138 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
139 }
140
141 err = sk_filter(sk, skb);
142 if (err)
143 return err;
144 if (!sk_rmem_schedule(sk, skb->truesize) && rx_flow_is_on(cf_sk)) {
145 set_rx_flow_off(cf_sk);
147 if (net_ratelimit())
148 pr_debug("sending flow OFF due to rmem_schedule\n");
146 net_dbg_ratelimited("sending flow OFF due to rmem_schedule\n");
149 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
150 }
151 skb->dev = NULL;
152 skb_set_owner_r(skb, sk);
153 /* Cache the SKB length before we tack it onto the receive
154 * queue. Once it is added it no longer belongs to us and
155 * may be freed by other threads of control pulling packets
156 * from the queue.

--- 343 unchanged lines hidden (view full) ---

500 */
501static int transmit_skb(struct sk_buff *skb, struct caifsock *cf_sk,
502 int noblock, long timeo)
503{
504 struct cfpkt *pkt;
505
506 pkt = cfpkt_fromnative(CAIF_DIR_OUT, skb);
507 memset(skb->cb, 0, sizeof(struct caif_payload_info));
147 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
148 }
149 skb->dev = NULL;
150 skb_set_owner_r(skb, sk);
151 /* Cache the SKB length before we tack it onto the receive
152 * queue. Once it is added it no longer belongs to us and
153 * may be freed by other threads of control pulling packets
154 * from the queue.

--- 343 unchanged lines hidden (view full) ---

498 */
499static int transmit_skb(struct sk_buff *skb, struct caifsock *cf_sk,
500 int noblock, long timeo)
501{
502 struct cfpkt *pkt;
503
504 pkt = cfpkt_fromnative(CAIF_DIR_OUT, skb);
505 memset(skb->cb, 0, sizeof(struct caif_payload_info));
506 cfpkt_set_prio(pkt, cf_sk->sk.sk_priority);
508
509 if (cf_sk->layer.dn == NULL) {
510 kfree_skb(skb);
511 return -EINVAL;
512 }
513
514 return cf_sk->layer.dn->transmit(cf_sk->layer.dn, pkt);
515}

--- 541 unchanged lines hidden (view full) ---

1057 if (!sk)
1058 return -ENOMEM;
1059
1060 cf_sk = container_of(sk, struct caifsock, sk);
1061
1062 /* Store the protocol */
1063 sk->sk_protocol = (unsigned char) protocol;
1064
507
508 if (cf_sk->layer.dn == NULL) {
509 kfree_skb(skb);
510 return -EINVAL;
511 }
512
513 return cf_sk->layer.dn->transmit(cf_sk->layer.dn, pkt);
514}

--- 541 unchanged lines hidden (view full) ---

1056 if (!sk)
1057 return -ENOMEM;
1058
1059 cf_sk = container_of(sk, struct caifsock, sk);
1060
1061 /* Store the protocol */
1062 sk->sk_protocol = (unsigned char) protocol;
1063
1064 /* Initialize default priority for well-known cases */
1065 switch (protocol) {
1066 case CAIFPROTO_AT:
1067 sk->sk_priority = TC_PRIO_CONTROL;
1068 break;
1069 case CAIFPROTO_RFM:
1070 sk->sk_priority = TC_PRIO_INTERACTIVE_BULK;
1071 break;
1072 default:
1073 sk->sk_priority = TC_PRIO_BESTEFFORT;
1074 }
1075
1065 /*
1066 * Lock in order to try to stop someone from opening the socket
1067 * too early.
1068 */
1069 lock_sock(&(cf_sk->sk));
1070
1071 /* Initialize the nozero default sock structure data. */
1072 sock_init_data(sock, sk);
1073 sk->sk_destruct = caif_sock_destructor;
1074
1075 mutex_init(&cf_sk->readlock); /* single task reading lock */
1076 cf_sk->layer.ctrlcmd = caif_ctrl_cb;
1077 cf_sk->sk.sk_socket->state = SS_UNCONNECTED;
1078 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
1079
1080 set_tx_flow_off(cf_sk);
1081 set_rx_flow_on(cf_sk);
1082
1083 /* Set default options on configuration */
1076 /*
1077 * Lock in order to try to stop someone from opening the socket
1078 * too early.
1079 */
1080 lock_sock(&(cf_sk->sk));
1081
1082 /* Initialize the nozero default sock structure data. */
1083 sock_init_data(sock, sk);
1084 sk->sk_destruct = caif_sock_destructor;
1085
1086 mutex_init(&cf_sk->readlock); /* single task reading lock */
1087 cf_sk->layer.ctrlcmd = caif_ctrl_cb;
1088 cf_sk->sk.sk_socket->state = SS_UNCONNECTED;
1089 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
1090
1091 set_tx_flow_off(cf_sk);
1092 set_rx_flow_on(cf_sk);
1093
1094 /* Set default options on configuration */
1084 cf_sk->sk.sk_priority = CAIF_PRIO_NORMAL;
1085 cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY;
1086 cf_sk->conn_req.protocol = protocol;
1087 release_sock(&cf_sk->sk);
1088 return 0;
1089}
1090
1091
1092static struct net_proto_family caif_family_ops = {

--- 19 unchanged lines hidden ---
1095 cf_sk->conn_req.link_selector = CAIF_LINK_LOW_LATENCY;
1096 cf_sk->conn_req.protocol = protocol;
1097 release_sock(&cf_sk->sk);
1098 return 0;
1099}
1100
1101
1102static struct net_proto_family caif_family_ops = {

--- 19 unchanged lines hidden ---