61
62
return &this->layer;
64
int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
66
struct cfmuxl *muxl = container_obj(layr);
67
spin_lock(&muxl->receive_lock);
69
list_add(&up->node, &muxl->srvl_list);
70
spin_unlock(&muxl->receive_lock);
74
bool cfmuxl_is_phy_inuse(struct cflayer *layr, u8 phyid)
76
struct list_head *node;
77
struct cflayer *layer;
78
struct cfmuxl *muxl = container_obj(layr);
80
spin_lock(&muxl->receive_lock);
82
list_for_each(node, &muxl->srvl_list) {
83
layer = list_entry(node, struct cflayer, node);
84
if (cfsrvl_phyid_match(layer, phyid)) {
90
spin_unlock(&muxl->receive_lock);
94
u8 cfmuxl_get_phyid(struct cflayer *layr, u8 channel_id)
98
struct cfmuxl *muxl = container_obj(layr);
99
spin_lock(&muxl->receive_lock);
100
up = get_up(muxl, channel_id);
102
phyid = cfsrvl_getphyid(up);
105
spin_unlock(&muxl->receive_lock);
109
65
int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *dn, u8 phyid)
111
67
struct cfmuxl *muxl = (struct cfmuxl *) layr;
112
spin_lock(&muxl->transmit_lock);
113
list_add(&dn->node, &muxl->frml_list);
114
spin_unlock(&muxl->transmit_lock);
69
spin_lock_bh(&muxl->transmit_lock);
70
list_add_rcu(&dn->node, &muxl->frml_list);
71
spin_unlock_bh(&muxl->transmit_lock);
118
75
static struct cflayer *get_from_id(struct list_head *list, u16 id)
120
struct list_head *node;
121
struct cflayer *layer;
122
list_for_each(node, list) {
123
layer = list_entry(node, struct cflayer, node);
78
list_for_each_entry_rcu(lyr, list, node) {
86
int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
88
struct cfmuxl *muxl = container_obj(layr);
91
spin_lock_bh(&muxl->receive_lock);
93
/* Two entries with same id is wrong, so remove old layer from mux */
94
old = get_from_id(&muxl->srvl_list, linkid);
96
list_del_rcu(&old->node);
98
list_add_rcu(&up->node, &muxl->srvl_list);
99
spin_unlock_bh(&muxl->receive_lock);
130
104
struct cflayer *cfmuxl_remove_dnlayer(struct cflayer *layr, u8 phyid)
132
106
struct cfmuxl *muxl = container_obj(layr);
133
107
struct cflayer *dn;
134
spin_lock(&muxl->transmit_lock);
135
memset(muxl->dn_cache, 0, sizeof(muxl->dn_cache));
108
int idx = phyid % DN_CACHE_SIZE;
110
spin_lock_bh(&muxl->transmit_lock);
111
rcu_assign_pointer(muxl->dn_cache[idx], NULL);
136
112
dn = get_from_id(&muxl->frml_list, phyid);
138
spin_unlock(&muxl->transmit_lock);
116
list_del_rcu(&dn->node);
142
117
caif_assert(dn != NULL);
143
spin_unlock(&muxl->transmit_lock);
119
spin_unlock_bh(&muxl->transmit_lock);
147
/* Invariant: lock is taken */
148
123
static struct cflayer *get_up(struct cfmuxl *muxl, u16 id)
150
125
struct cflayer *up;
151
126
int idx = id % UP_CACHE_SIZE;
152
up = muxl->up_cache[idx];
127
up = rcu_dereference(muxl->up_cache[idx]);
153
128
if (up == NULL || up->id != id) {
129
spin_lock_bh(&muxl->receive_lock);
154
130
up = get_from_id(&muxl->srvl_list, id);
155
muxl->up_cache[idx] = up;
131
rcu_assign_pointer(muxl->up_cache[idx], up);
132
spin_unlock_bh(&muxl->receive_lock);
160
/* Invariant: lock is taken */
161
137
static struct cflayer *get_dn(struct cfmuxl *muxl, struct dev_info *dev_info)
163
139
struct cflayer *dn;
164
140
int idx = dev_info->id % DN_CACHE_SIZE;
165
dn = muxl->dn_cache[idx];
141
dn = rcu_dereference(muxl->dn_cache[idx]);
166
142
if (dn == NULL || dn->id != dev_info->id) {
143
spin_lock_bh(&muxl->transmit_lock);
167
144
dn = get_from_id(&muxl->frml_list, dev_info->id);
168
muxl->dn_cache[idx] = dn;
145
rcu_assign_pointer(muxl->dn_cache[idx], dn);
146
spin_unlock_bh(&muxl->transmit_lock);
197
182
cfpkt_destroy(pkt);
186
up = get_up(muxl, id);
201
spin_lock(&muxl->receive_lock);
202
up = get_up(muxl, id);
203
spin_unlock(&muxl->receive_lock);
204
188
if (up == NULL) {
205
pr_info("Received data on unknown link ID = %d (0x%x) up == NULL",
189
pr_debug("Received data on unknown link ID = %d (0x%x)"
190
" up == NULL", id, id);
207
191
cfpkt_destroy(pkt);
209
193
* Don't return ERROR, since modem misbehaves and sends out
210
194
* flow on before linksetup response.
212
198
return /* CFGLU_EPROT; */ 0;
201
/* We can't hold rcu_lock during receive, so take a ref count instead */
215
205
ret = up->receive(up, pkt);
220
211
static int cfmuxl_transmit(struct cflayer *layr, struct cfpkt *pkt)
223
213
struct cfmuxl *muxl = container_obj(layr);
225
216
struct cflayer *dn;
226
217
struct caif_payload_info *info = cfpkt_info(pkt);
227
dn = get_dn(muxl, cfpkt_info(pkt)->dev_info);
222
dn = get_dn(muxl, info->dev_info);
228
223
if (dn == NULL) {
229
pr_warn("Send data on unknown phy ID = %d (0x%x)\n",
224
pr_debug("Send data on unknown phy ID = %d (0x%x)\n",
230
225
info->dev_info->id, info->dev_info->id);
231
228
return -ENOTCONN;
233
231
info->hdr_len += 1;
234
232
linkid = info->channel_id;
235
233
cfpkt_add_head(pkt, &linkid, 1);
236
ret = dn->transmit(dn, pkt);
237
/* Remove MUX protocol header upon error. */
239
cfpkt_extr_head(pkt, &linkid, 1);
235
/* We can't hold rcu_lock during receive, so take a ref count instead */
240
err = dn->transmit(dn, pkt);
243
246
static void cfmuxl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
246
249
struct cfmuxl *muxl = container_obj(layr);
247
struct list_head *node, *next;
248
250
struct cflayer *layer;
249
list_for_each_safe(node, next, &muxl->srvl_list) {
250
layer = list_entry(node, struct cflayer, node);
251
if (cfsrvl_phyid_match(layer, phyid))
254
list_for_each_entry_rcu(layer, &muxl->srvl_list, node) {
256
if (cfsrvl_phyid_match(layer, phyid) && layer->ctrlcmd) {
258
if ((ctrl == _CAIF_CTRLCMD_PHYIF_DOWN_IND ||
259
ctrl == CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND) &&
262
idx = layer->id % UP_CACHE_SIZE;
263
spin_lock_bh(&muxl->receive_lock);
264
rcu_assign_pointer(muxl->up_cache[idx], NULL);
265
list_del_rcu(&layer->node);
266
spin_unlock_bh(&muxl->receive_lock);
268
/* NOTE: ctrlcmd is not allowed to block */
252
269
layer->ctrlcmd(layer, ctrl, phyid);