Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson AB 2010 |
| 3 | * Author: Sjur Brendeland/sjur.brandeland@stericsson.com |
| 4 | * License terms: GNU General Public License (GPL) version 2 |
| 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 | { |
| 24 | struct cfsrvl *vid = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC); |
| 25 | if (!vid) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame^] | 26 | pr_warn("Out of memory\n"); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 27 | return NULL; |
| 28 | } |
| 29 | caif_assert(offsetof(struct cfsrvl, layer) == 0); |
| 30 | |
| 31 | memset(vid, 0, sizeof(struct cfsrvl)); |
Sjur Braendeland | b1c7424 | 2010-06-17 06:55:38 +0000 | [diff] [blame] | 32 | cfsrvl_init(vid, channel_id, dev_info, false); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 33 | vid->layer.receive = cfvidl_receive; |
| 34 | vid->layer.transmit = cfvidl_transmit; |
| 35 | snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ - 1, "vid1"); |
| 36 | return &vid->layer; |
| 37 | } |
| 38 | |
| 39 | static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt) |
| 40 | { |
| 41 | u32 videoheader; |
| 42 | if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) { |
Joe Perches | b31fa5b | 2010-09-05 21:31:11 +0000 | [diff] [blame^] | 43 | pr_err("Packet is erroneous!\n"); |
Sjur Braendeland | b482cd2 | 2010-03-30 13:56:23 +0000 | [diff] [blame] | 44 | cfpkt_destroy(pkt); |
| 45 | return -EPROTO; |
| 46 | } |
| 47 | return layr->up->receive(layr->up, pkt); |
| 48 | } |
| 49 | |
| 50 | static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt) |
| 51 | { |
| 52 | struct cfsrvl *service = container_obj(layr); |
| 53 | struct caif_payload_info *info; |
| 54 | u32 videoheader = 0; |
| 55 | int ret; |
| 56 | if (!cfsrvl_ready(service, &ret)) |
| 57 | return ret; |
| 58 | cfpkt_add_head(pkt, &videoheader, 4); |
| 59 | /* Add info for MUX-layer to route the packet out */ |
| 60 | info = cfpkt_info(pkt); |
| 61 | info->channel_id = service->layer.id; |
| 62 | info->dev_info = &service->dev_info; |
| 63 | ret = layr->dn->transmit(layr->dn, pkt); |
| 64 | if (ret < 0) |
| 65 | cfpkt_extr_head(pkt, &videoheader, 4); |
| 66 | return ret; |
| 67 | } |