^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/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/caif/caif_layer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/caif/cfpkt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/caif/cfctrl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define container_obj(layr) container_of(layr, struct cfctrl, serv.layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define UTILITY_NAME_LENGTH 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define CFPKT_CTRL_PKT_LEN 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #ifdef CAIF_NO_LOOP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int handle_loop(struct cfctrl *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int cmd, struct cfpkt *pkt){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int handle_loop(struct cfctrl *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int cmd, struct cfpkt *pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int cfctrl_recv(struct cflayer *layr, struct cfpkt *pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void cfctrl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct cflayer *cfctrl_create(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct dev_info dev_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct cfctrl *this =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) kzalloc(sizeof(struct cfctrl), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (!this)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) caif_assert(offsetof(struct cfctrl, serv.layer) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) memset(&dev_info, 0, sizeof(dev_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) dev_info.id = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) cfsrvl_init(&this->serv, 0, &dev_info, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) atomic_set(&this->req_seq_no, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) atomic_set(&this->rsp_seq_no, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) this->serv.layer.receive = cfctrl_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) sprintf(this->serv.layer.name, "ctrl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #ifndef CAIF_NO_LOOP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) spin_lock_init(&this->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) this->loop_linkid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) spin_lock_init(&this->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) INIT_LIST_HEAD(&this->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return &this->serv.layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void cfctrl_remove(struct cflayer *layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct cfctrl_request_info *p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct cfctrl *ctrl = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) spin_lock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) list_for_each_entry_safe(p, tmp, &ctrl->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) list_del(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spin_unlock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) kfree(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static bool param_eq(const struct cfctrl_link_param *p1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct cfctrl_link_param *p2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) bool eq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) p1->linktype == p2->linktype &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) p1->priority == p2->priority &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) p1->phyid == p2->phyid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) p1->endpoint == p2->endpoint && p1->chtype == p2->chtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!eq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) switch (p1->linktype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) case CFCTRL_SRV_VEI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) case CFCTRL_SRV_DATAGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return p1->u.datagram.connid == p2->u.datagram.connid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) case CFCTRL_SRV_RFM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) p1->u.rfm.connid == p2->u.rfm.connid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) strcmp(p1->u.rfm.volume, p2->u.rfm.volume) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) case CFCTRL_SRV_UTIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) p1->u.utility.fifosize_kb == p2->u.utility.fifosize_kb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) && p1->u.utility.fifosize_bufs ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) p2->u.utility.fifosize_bufs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) && strcmp(p1->u.utility.name, p2->u.utility.name) == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) && p1->u.utility.paramlen == p2->u.utility.paramlen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) && memcmp(p1->u.utility.params, p2->u.utility.params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) p1->u.utility.paramlen) == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) case CFCTRL_SRV_VIDEO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return p1->u.video.connid == p2->u.video.connid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) case CFCTRL_SRV_DBG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case CFCTRL_SRV_DECM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static bool cfctrl_req_eq(const struct cfctrl_request_info *r1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) const struct cfctrl_request_info *r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (r1->cmd != r2->cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (r1->cmd == CFCTRL_CMD_LINK_SETUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return param_eq(&r1->param, &r2->param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return r1->channel_id == r2->channel_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Insert request at the end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void cfctrl_insert_req(struct cfctrl *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct cfctrl_request_info *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) spin_lock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) atomic_inc(&ctrl->req_seq_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) req->sequence_no = atomic_read(&ctrl->req_seq_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) list_add_tail(&req->list, &ctrl->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) spin_unlock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* Compare and remove request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct cfctrl_request_info *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct cfctrl_request_info *p, *tmp, *first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) first = list_first_entry(&ctrl->list, struct cfctrl_request_info, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) list_for_each_entry_safe(p, tmp, &ctrl->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (cfctrl_req_eq(req, p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (p != first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pr_warn("Requests are not received in order\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) atomic_set(&ctrl->rsp_seq_no,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) p->sequence_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) list_del(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct cfctrl_rsp *cfctrl_get_respfuncs(struct cflayer *layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct cfctrl *this = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return &this->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void init_info(struct caif_payload_info *info, struct cfctrl *cfctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) info->hdr_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) info->channel_id = cfctrl->serv.layer.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) info->dev_info = &cfctrl->serv.dev_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) void cfctrl_enum_req(struct cflayer *layer, u8 physlinkid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct cfpkt *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct cfctrl *cfctrl = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct cflayer *dn = cfctrl->serv.layer.dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!dn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pr_debug("not able to send enum request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) caif_assert(offsetof(struct cfctrl, serv.layer) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) init_info(cfpkt_info(pkt), cfctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cfpkt_info(pkt)->dev_info->id = physlinkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) cfctrl->serv.dev_info.id = physlinkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) cfpkt_addbdy(pkt, CFCTRL_CMD_ENUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) cfpkt_addbdy(pkt, physlinkid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dn->transmit(dn, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int cfctrl_linkup_request(struct cflayer *layer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct cfctrl_link_param *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct cflayer *user_layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct cfctrl *cfctrl = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u32 tmp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u16 tmp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u8 tmp8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct cfctrl_request_info *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) char utility_name[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct cfpkt *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct cflayer *dn = cfctrl->serv.layer.dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!dn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pr_debug("not able to send linkup request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (cfctrl_cancel_req(layer, user_layer) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Slight Paranoia, check if already connecting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) pr_err("Duplicate connect request for same client\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_SETUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) cfpkt_addbdy(pkt, (param->chtype << 4) | param->linktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) cfpkt_addbdy(pkt, (param->priority << 3) | param->phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) cfpkt_addbdy(pkt, param->endpoint & 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) switch (param->linktype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case CFCTRL_SRV_VEI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) case CFCTRL_SRV_VIDEO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cfpkt_addbdy(pkt, (u8) param->u.video.connid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case CFCTRL_SRV_DBG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case CFCTRL_SRV_DATAGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) tmp32 = cpu_to_le32(param->u.datagram.connid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) cfpkt_add_body(pkt, &tmp32, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case CFCTRL_SRV_RFM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* Construct a frame, convert DatagramConnectionID to network
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * format long and copy it out...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) tmp32 = cpu_to_le32(param->u.rfm.connid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) cfpkt_add_body(pkt, &tmp32, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Add volume name, including zero termination... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) cfpkt_add_body(pkt, param->u.rfm.volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) strlen(param->u.rfm.volume) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) case CFCTRL_SRV_UTIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) tmp16 = cpu_to_le16(param->u.utility.fifosize_kb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) cfpkt_add_body(pkt, &tmp16, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) tmp16 = cpu_to_le16(param->u.utility.fifosize_bufs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) cfpkt_add_body(pkt, &tmp16, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) memset(utility_name, 0, sizeof(utility_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) strlcpy(utility_name, param->u.utility.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) UTILITY_NAME_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) cfpkt_add_body(pkt, utility_name, UTILITY_NAME_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) tmp8 = param->u.utility.paramlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) cfpkt_add_body(pkt, &tmp8, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) cfpkt_add_body(pkt, param->u.utility.params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) param->u.utility.paramlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pr_warn("Request setup of bad link type = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) param->linktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) req = kzalloc(sizeof(*req), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) req->client_layer = user_layer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) req->cmd = CFCTRL_CMD_LINK_SETUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) req->param = *param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) cfctrl_insert_req(cfctrl, req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) init_info(cfpkt_info(pkt), cfctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * NOTE:Always send linkup and linkdown request on the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * device as the payload. Otherwise old queued up payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * might arrive with the newly allocated channel ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) cfpkt_info(pkt)->dev_info->id = param->phyid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) dn->transmit(dn, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) count = cfctrl_cancel_req(&cfctrl->serv.layer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) user_layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (count != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) pr_err("Could not remove request (%d)", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int cfctrl_linkdown_req(struct cflayer *layer, u8 channelid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct cflayer *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct cfpkt *pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct cfctrl *cfctrl = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct cflayer *dn = cfctrl->serv.layer.dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (!dn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) pr_debug("not able to send link-down request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_DESTROY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) cfpkt_addbdy(pkt, channelid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) init_info(cfpkt_info(pkt), cfctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) cfpkt_set_prio(pkt, TC_PRIO_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) dn->transmit(dn, pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #ifndef CAIF_NO_LOOP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) cfctrl->loop_linkused[channelid] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int cfctrl_cancel_req(struct cflayer *layr, struct cflayer *adap_layer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct cfctrl_request_info *p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct cfctrl *ctrl = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) spin_lock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) list_for_each_entry_safe(p, tmp, &ctrl->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (p->client_layer == adap_layer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) list_del(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) spin_unlock_bh(&ctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int cfctrl_recv(struct cflayer *layer, struct cfpkt *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) u8 cmdrsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) u8 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) u8 param[255];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) u8 linkid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct cfctrl *cfctrl = container_obj(layer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct cfctrl_request_info rsp, *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) cmdrsp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) cmd = cmdrsp & CFCTRL_CMD_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (cmd != CFCTRL_CMD_LINK_ERR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) && CFCTRL_RSP_BIT != (CFCTRL_RSP_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) && CFCTRL_ERR_BIT != (CFCTRL_ERR_BIT & cmdrsp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (handle_loop(cfctrl, cmd, pkt) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) cmdrsp |= CFCTRL_ERR_BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) case CFCTRL_CMD_LINK_SETUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) enum cfctrl_srv serv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) enum cfctrl_srv servtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) u8 endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) u8 physlinkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) u8 prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) u8 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) u8 *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct cfctrl_link_param linkparam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) memset(&linkparam, 0, sizeof(linkparam));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) serv = tmp & CFCTRL_SRV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) linkparam.linktype = serv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) servtype = tmp >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) linkparam.chtype = servtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) physlinkid = tmp & 0x07;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) prio = tmp >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) linkparam.priority = prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) linkparam.phyid = physlinkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) endpoint = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) linkparam.endpoint = endpoint & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) switch (serv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) case CFCTRL_SRV_VEI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case CFCTRL_SRV_DBG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (CFCTRL_ERR_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Link ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) case CFCTRL_SRV_VIDEO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) linkparam.u.video.connid = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (CFCTRL_ERR_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /* Link ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) case CFCTRL_SRV_DATAGRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) linkparam.u.datagram.connid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) cfpkt_extr_head_u32(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) if (CFCTRL_ERR_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Link ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) case CFCTRL_SRV_RFM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Construct a frame, convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * DatagramConnectionID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * to network format long and copy it out...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) linkparam.u.rfm.connid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) cfpkt_extr_head_u32(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) cp = (u8 *) linkparam.u.rfm.volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) for (tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) cfpkt_more(pkt) && tmp != '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) tmp = cfpkt_extr_head_u8(pkt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) *cp++ = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) *cp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (CFCTRL_ERR_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /* Link ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) case CFCTRL_SRV_UTIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* Construct a frame, convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * DatagramConnectionID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * to network format long and copy it out...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Fifosize KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) linkparam.u.utility.fifosize_kb =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) cfpkt_extr_head_u16(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* Fifosize bufs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) linkparam.u.utility.fifosize_bufs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) cfpkt_extr_head_u16(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) cp = (u8 *) linkparam.u.utility.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) caif_assert(sizeof(linkparam.u.utility.name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) >= UTILITY_NAME_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) for (i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) i < UTILITY_NAME_LENGTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) && cfpkt_more(pkt); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) *cp++ = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) len = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) linkparam.u.utility.paramlen = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* Param Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) cp = linkparam.u.utility.params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) while (cfpkt_more(pkt) && len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) tmp = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) *cp++ = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (CFCTRL_ERR_BIT & cmdrsp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* Link ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /* Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) len = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* Param Data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) cfpkt_extr_head(pkt, ¶m, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) pr_warn("Request setup, invalid type (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) serv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) rsp.cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) rsp.param = linkparam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) spin_lock_bh(&cfctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) req = cfctrl_remove_req(cfctrl, &rsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (CFCTRL_ERR_BIT == (CFCTRL_ERR_BIT & cmdrsp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) cfpkt_erroneous(pkt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) pr_err("Invalid O/E bit or parse error "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) "on CAIF control channel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) cfctrl->res.reject_rsp(cfctrl->serv.layer.up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) req ? req->client_layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) cfctrl->res.linksetup_rsp(cfctrl->serv.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) layer.up, linkid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) serv, physlinkid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) req ? req->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) client_layer : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) spin_unlock_bh(&cfctrl->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) case CFCTRL_CMD_LINK_DESTROY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) linkid = cfpkt_extr_head_u8(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) cfctrl->res.linkdestroy_rsp(cfctrl->serv.layer.up, linkid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) case CFCTRL_CMD_LINK_ERR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) pr_err("Frame Error Indication received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) cfctrl->res.linkerror_ind();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) case CFCTRL_CMD_ENUM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) cfctrl->res.enum_rsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) case CFCTRL_CMD_SLEEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) cfctrl->res.sleep_rsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) case CFCTRL_CMD_WAKE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) cfctrl->res.wake_rsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) case CFCTRL_CMD_LINK_RECONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) cfctrl->res.restart_rsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) case CFCTRL_CMD_RADIO_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) cfctrl->res.radioset_rsp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) pr_err("Unrecognized Control Frame\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) cfpkt_destroy(pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static void cfctrl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) int phyid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct cfctrl *this = container_obj(layr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) switch (ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) case _CAIF_CTRLCMD_PHYIF_FLOW_OFF_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) case CAIF_CTRLCMD_FLOW_OFF_IND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) spin_lock_bh(&this->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (!list_empty(&this->list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) pr_debug("Received flow off in control layer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) spin_unlock_bh(&this->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) case _CAIF_CTRLCMD_PHYIF_DOWN_IND: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct cfctrl_request_info *p, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Find all connect request and report failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) spin_lock_bh(&this->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) list_for_each_entry_safe(p, tmp, &this->list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (p->param.phyid == phyid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) list_del(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) p->client_layer->ctrlcmd(p->client_layer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) CAIF_CTRLCMD_INIT_FAIL_RSP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) phyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) spin_unlock_bh(&this->info_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #ifndef CAIF_NO_LOOP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static int handle_loop(struct cfctrl *ctrl, int cmd, struct cfpkt *pkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static int last_linkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static int dec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) u8 linkid, linktype, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) case CFCTRL_CMD_LINK_SETUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) spin_lock_bh(&ctrl->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (!dec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) for (linkid = last_linkid + 1; linkid < 254; linkid++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (!ctrl->loop_linkused[linkid])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dec = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) for (linkid = last_linkid - 1; linkid > 1; linkid--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (!ctrl->loop_linkused[linkid])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) spin_unlock_bh(&ctrl->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (linkid < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) dec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (!ctrl->loop_linkused[linkid])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ctrl->loop_linkused[linkid] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) last_linkid = linkid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) cfpkt_add_trail(pkt, &linkid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) spin_unlock_bh(&ctrl->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) cfpkt_peek_head(pkt, &linktype, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (linktype == CFCTRL_SRV_UTIL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) tmp = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) cfpkt_add_trail(pkt, &tmp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) cfpkt_add_trail(pkt, &tmp, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) case CFCTRL_CMD_LINK_DESTROY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) spin_lock_bh(&ctrl->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) cfpkt_peek_head(pkt, &linkid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) ctrl->loop_linkused[linkid] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) spin_unlock_bh(&ctrl->loop_linkid_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) #endif