1b482cd20SSjur Braendeland /* 2b482cd20SSjur Braendeland * Copyright (C) ST-Ericsson AB 2010 3b482cd20SSjur Braendeland * Author: Sjur Brendeland/sjur.brandeland@stericsson.com 4b482cd20SSjur Braendeland * License terms: GNU General Public License (GPL) version 2 5b482cd20SSjur Braendeland */ 6b482cd20SSjur Braendeland 7b31fa5baSJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ 8b31fa5baSJoe Perches 9b482cd20SSjur Braendeland #include <linux/kernel.h> 10b482cd20SSjur Braendeland #include <linux/types.h> 11b482cd20SSjur Braendeland #include <linux/slab.h> 12b482cd20SSjur Braendeland #include <linux/errno.h> 13b482cd20SSjur Braendeland #include <net/caif/caif_layer.h> 14b482cd20SSjur Braendeland #include <net/caif/cfsrvl.h> 15b482cd20SSjur Braendeland #include <net/caif/cfpkt.h> 16b482cd20SSjur Braendeland 17b482cd20SSjur Braendeland #define container_obj(layr) ((struct cfsrvl *) layr) 18b482cd20SSjur Braendeland 19b482cd20SSjur Braendeland static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt); 20b482cd20SSjur Braendeland static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt); 21b482cd20SSjur Braendeland 22b482cd20SSjur Braendeland struct cflayer *cfvidl_create(u8 channel_id, struct dev_info *dev_info) 23b482cd20SSjur Braendeland { 24*7ac2ed0cSJoe Perches struct cfsrvl *vid = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC); 25*7ac2ed0cSJoe Perches if (!vid) 26b482cd20SSjur Braendeland return NULL; 27b482cd20SSjur Braendeland caif_assert(offsetof(struct cfsrvl, layer) == 0); 28b482cd20SSjur Braendeland 29b1c74247SSjur Braendeland cfsrvl_init(vid, channel_id, dev_info, false); 30b482cd20SSjur Braendeland vid->layer.receive = cfvidl_receive; 31b482cd20SSjur Braendeland vid->layer.transmit = cfvidl_transmit; 32b482cd20SSjur Braendeland snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ - 1, "vid1"); 33b482cd20SSjur Braendeland return &vid->layer; 34b482cd20SSjur Braendeland } 35b482cd20SSjur Braendeland 36b482cd20SSjur Braendeland static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt) 37b482cd20SSjur Braendeland { 38b482cd20SSjur Braendeland u32 videoheader; 39b482cd20SSjur Braendeland if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) { 40b31fa5baSJoe Perches pr_err("Packet is erroneous!\n"); 41b482cd20SSjur Braendeland cfpkt_destroy(pkt); 42b482cd20SSjur Braendeland return -EPROTO; 43b482cd20SSjur Braendeland } 44b482cd20SSjur Braendeland return layr->up->receive(layr->up, pkt); 45b482cd20SSjur Braendeland } 46b482cd20SSjur Braendeland 47b482cd20SSjur Braendeland static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt) 48b482cd20SSjur Braendeland { 49b482cd20SSjur Braendeland struct cfsrvl *service = container_obj(layr); 50b482cd20SSjur Braendeland struct caif_payload_info *info; 51b482cd20SSjur Braendeland u32 videoheader = 0; 52b482cd20SSjur Braendeland int ret; 53b482cd20SSjur Braendeland if (!cfsrvl_ready(service, &ret)) 54b482cd20SSjur Braendeland return ret; 55b482cd20SSjur Braendeland cfpkt_add_head(pkt, &videoheader, 4); 56b482cd20SSjur Braendeland /* Add info for MUX-layer to route the packet out */ 57b482cd20SSjur Braendeland info = cfpkt_info(pkt); 58b482cd20SSjur Braendeland info->channel_id = service->layer.id; 59b482cd20SSjur Braendeland info->dev_info = &service->dev_info; 604dd820c0SSjur Brændeland return layr->dn->transmit(layr->dn, pkt); 61b482cd20SSjur Braendeland } 62