^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) ST-Ericsson AB 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Sjur Brendeland
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/caif/cfpkt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/caif/cfmuxl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/caif/cfsrvl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <net/caif/cffrml.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define container_obj(layr) container_of(layr, struct cfmuxl, layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define CAIF_CTRL_CHANNEL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define UP_CACHE_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define DN_CACHE_SIZE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct cfmuxl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct cflayer layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct list_head srvl_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct list_head frml_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct cflayer *up_cache[UP_CACHE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct cflayer *dn_cache[DN_CACHE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Set when inserting or removing downwards layers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) spinlock_t transmit_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Set when inserting or removing upwards layers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) spinlock_t receive_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int cfmuxl_transmit(struct cflayer *layr, struct cfpkt *pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void cfmuxl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct cflayer *get_up(struct cfmuxl *muxl, u16 id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct cflayer *cfmuxl_create(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct cfmuxl *this = kzalloc(sizeof(struct cfmuxl), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (!this)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) this->layer.receive = cfmuxl_receive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) this->layer.transmit = cfmuxl_transmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) this->layer.ctrlcmd = cfmuxl_ctrlcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) INIT_LIST_HEAD(&this->srvl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) INIT_LIST_HEAD(&this->frml_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) spin_lock_init(&this->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) spin_lock_init(&this->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) snprintf(this->layer.name, CAIF_LAYER_NAME_SZ, "mux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return &this->layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int cfmuxl_set_dnlayer(struct cflayer *layr, struct cflayer *dn, u8 phyid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct cfmuxl *muxl = (struct cfmuxl *) layr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) spin_lock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) list_add_rcu(&dn->node, &muxl->frml_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) spin_unlock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static struct cflayer *get_from_id(struct list_head *list, u16 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct cflayer *lyr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) list_for_each_entry_rcu(lyr, list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (lyr->id == id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return lyr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct cflayer *old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) spin_lock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* Two entries with same id is wrong, so remove old layer from mux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) old = get_from_id(&muxl->srvl_list, linkid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (old != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) list_del_rcu(&old->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) list_add_rcu(&up->node, &muxl->srvl_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) spin_unlock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct cflayer *cfmuxl_remove_dnlayer(struct cflayer *layr, u8 phyid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct cflayer *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int idx = phyid % DN_CACHE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spin_lock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) RCU_INIT_POINTER(muxl->dn_cache[idx], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dn = get_from_id(&muxl->frml_list, phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (dn == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) list_del_rcu(&dn->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) caif_assert(dn != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) spin_unlock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct cflayer *get_up(struct cfmuxl *muxl, u16 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct cflayer *up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int idx = id % UP_CACHE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) up = rcu_dereference(muxl->up_cache[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (up == NULL || up->id != id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_lock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) up = get_from_id(&muxl->srvl_list, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) rcu_assign_pointer(muxl->up_cache[idx], up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) spin_unlock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static struct cflayer *get_dn(struct cfmuxl *muxl, struct dev_info *dev_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct cflayer *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int idx = dev_info->id % DN_CACHE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dn = rcu_dereference(muxl->dn_cache[idx]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (dn == NULL || dn->id != dev_info->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) spin_lock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dn = get_from_id(&muxl->frml_list, dev_info->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) rcu_assign_pointer(muxl->dn_cache[idx], dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) spin_unlock_bh(&muxl->transmit_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct cflayer *up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int idx = id % UP_CACHE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (id == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_warn("Trying to remove control layer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) spin_lock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) up = get_from_id(&muxl->srvl_list, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (up == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) RCU_INIT_POINTER(muxl->up_cache[idx], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) list_del_rcu(&up->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) spin_unlock_bh(&muxl->receive_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u8 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct cflayer *up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (cfpkt_extr_head(pkt, &id, 1) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pr_err("erroneous Caif Packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) cfpkt_destroy(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return -EPROTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) up = get_up(muxl, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (up == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pr_debug("Received data on unknown link ID = %d (0x%x)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) " up == NULL", id, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cfpkt_destroy(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Don't return ERROR, since modem misbehaves and sends out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * flow on before linksetup response.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return /* CFGLU_EPROT; */ 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* We can't hold rcu_lock during receive, so take a ref count instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) cfsrvl_get(up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) ret = up->receive(up, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cfsrvl_put(up);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static int cfmuxl_transmit(struct cflayer *layr, struct cfpkt *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u8 linkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct cflayer *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct caif_payload_info *info = cfpkt_info(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) BUG_ON(!info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) dn = get_dn(muxl, info->dev_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (dn == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pr_debug("Send data on unknown phy ID = %d (0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) info->dev_info->id, info->dev_info->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) cfpkt_destroy(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) info->hdr_len += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) linkid = info->channel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cfpkt_add_head(pkt, &linkid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* We can't hold rcu_lock during receive, so take a ref count instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cffrml_hold(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) err = dn->transmit(dn, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) cffrml_put(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static void cfmuxl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int phyid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct cfmuxl *muxl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct cflayer *layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) list_for_each_entry_rcu(layer, &muxl->srvl_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (cfsrvl_phyid_match(layer, phyid) && layer->ctrlcmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if ((ctrl == _CAIF_CTRLCMD_PHYIF_DOWN_IND ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ctrl == CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) layer->id != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) cfmuxl_remove_uplayer(layr, layer->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* NOTE: ctrlcmd is not allowed to block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) layer->ctrlcmd(layer, ctrl, phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }