18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) ST-Ericsson AB 2010 48c2ecf20Sopenharmony_ci * Author: Sjur Brendeland 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/stddef.h> 108c2ecf20Sopenharmony_ci#include <linux/slab.h> 118c2ecf20Sopenharmony_ci#include <net/caif/caif_layer.h> 128c2ecf20Sopenharmony_ci#include <net/caif/cfsrvl.h> 138c2ecf20Sopenharmony_ci#include <net/caif/cfpkt.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define container_obj(layr) ((struct cfsrvl *) layr) 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistatic int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt); 188c2ecf20Sopenharmony_cistatic int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct cflayer *cfdbgl_create(u8 channel_id, struct dev_info *dev_info) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci struct cfsrvl *dbg = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC); 238c2ecf20Sopenharmony_ci if (!dbg) 248c2ecf20Sopenharmony_ci return NULL; 258c2ecf20Sopenharmony_ci caif_assert(offsetof(struct cfsrvl, layer) == 0); 268c2ecf20Sopenharmony_ci cfsrvl_init(dbg, channel_id, dev_info, false); 278c2ecf20Sopenharmony_ci dbg->layer.receive = cfdbgl_receive; 288c2ecf20Sopenharmony_ci dbg->layer.transmit = cfdbgl_transmit; 298c2ecf20Sopenharmony_ci snprintf(dbg->layer.name, CAIF_LAYER_NAME_SZ, "dbg%d", channel_id); 308c2ecf20Sopenharmony_ci return &dbg->layer; 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci return layr->up->receive(layr->up, pkt); 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci struct cfsrvl *service = container_obj(layr); 418c2ecf20Sopenharmony_ci struct caif_payload_info *info; 428c2ecf20Sopenharmony_ci int ret; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci if (!cfsrvl_ready(service, &ret)) { 458c2ecf20Sopenharmony_ci cfpkt_destroy(pkt); 468c2ecf20Sopenharmony_ci return ret; 478c2ecf20Sopenharmony_ci } 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci /* Add info for MUX-layer to route the packet out */ 508c2ecf20Sopenharmony_ci info = cfpkt_info(pkt); 518c2ecf20Sopenharmony_ci info->channel_id = service->layer.id; 528c2ecf20Sopenharmony_ci info->dev_info = &service->dev_info; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci return layr->dn->transmit(layr->dn, pkt); 558c2ecf20Sopenharmony_ci} 56