Thomas Gleixner | af873fc | 2019-05-28 09:57:21 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) ST-Ericsson AB 2010 |
sjur.brandeland@stericsson.com | 26ee65e | 2013-04-22 23:57:01 +0000 | [diff] [blame] | 4 | * Author: Sjur Brendeland |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__ |
| 8 | |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 9 | #include <linux/kernel.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <net/caif/caif_layer.h> |
| 14 | #include <net/caif/cfsrvl.h> |
| 15 | #include <net/caif/cfpkt.h> |
| 16 | |
| 17 | #define container_obj(layr) ((struct cfsrvl *) layr) |
| 18 | |
| 19 | static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt); |
| 20 | static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt); |
| 21 | |
| 22 | struct cflayer *cfvidl_create(u8 channel_id, struct dev_info *dev_info) |
| 23 | { |
Joe Perches | 7ac2ed0 | 2011-08-25 13:22:24 +0000 | [diff] [blame] | 24 | struct cfsrvl *vid = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC); |
| 25 | if (!vid) |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 26 | return NULL; |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 27 | caif_assert(offsetof(struct cfsrvl, layer) == 0); |
| 28 | |
Sjur Braendeland | b1c7424 | 2010-06-17 06:55:38 +0000 | [diff] [blame] | 29 | cfsrvl_init(vid, channel_id, dev_info, false); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 30 | vid->layer.receive = cfvidl_receive; |
| 31 | vid->layer.transmit = cfvidl_transmit; |
swkhack | 34dcf6a | 2019-05-17 15:59:22 +0800 | [diff] [blame] | 32 | snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ, "vid1"); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 33 | return &vid->layer; |
| 34 | } |
| 35 | |
| 36 | static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt) |
| 37 | { |
| 38 | u32 videoheader; |
| 39 | if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame] | 40 | pr_err("Packet is erroneous!\n"); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 41 | cfpkt_destroy(pkt); |
| 42 | return -EPROTO; |
| 43 | } |
| 44 | return layr->up->receive(layr->up, pkt); |
| 45 | } |
| 46 | |
| 47 | static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt) |
| 48 | { |
| 49 | struct cfsrvl *service = container_obj(layr); |
| 50 | struct caif_payload_info *info; |
| 51 | u32 videoheader = 0; |
| 52 | int ret; |
Dmitry Tarnyagin | 374458b | 2012-03-11 10:28:31 +0000 | [diff] [blame] | 53 | |
| 54 | if (!cfsrvl_ready(service, &ret)) { |
| 55 | cfpkt_destroy(pkt); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 56 | return ret; |
Dmitry Tarnyagin | 374458b | 2012-03-11 10:28:31 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 59 | cfpkt_add_head(pkt, &videoheader, 4); |
| 60 | /* Add info for MUX-layer to route the packet out */ |
| 61 | info = cfpkt_info(pkt); |
| 62 | info->channel_id = service->layer.id; |
| 63 | info->dev_info = &service->dev_info; |
Sjur Brændeland | 4dd820c | 2011-04-11 10:43:51 +0000 | [diff] [blame] | 64 | return layr->dn->transmit(layr->dn, pkt); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 65 | } |