Linux 3.2.4
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / caif / cfvidl.c
blobe3f37db40ac39df501abc1e717d7e06a9a932b64
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 */
7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
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>
17 #define container_obj(layr) ((struct cfsrvl *) layr)
19 static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt);
20 static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt);
22 struct cflayer *cfvidl_create(u8 channel_id, struct dev_info *dev_info)
24 struct cfsrvl *vid = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
25 if (!vid)
26 return NULL;
27 caif_assert(offsetof(struct cfsrvl, layer) == 0);
29 cfsrvl_init(vid, channel_id, dev_info, false);
30 vid->layer.receive = cfvidl_receive;
31 vid->layer.transmit = cfvidl_transmit;
32 snprintf(vid->layer.name, CAIF_LAYER_NAME_SZ - 1, "vid1");
33 return &vid->layer;
36 static int cfvidl_receive(struct cflayer *layr, struct cfpkt *pkt)
38 u32 videoheader;
39 if (cfpkt_extr_head(pkt, &videoheader, 4) < 0) {
40 pr_err("Packet is erroneous!\n");
41 cfpkt_destroy(pkt);
42 return -EPROTO;
44 return layr->up->receive(layr->up, pkt);
47 static int cfvidl_transmit(struct cflayer *layr, struct cfpkt *pkt)
49 struct cfsrvl *service = container_obj(layr);
50 struct caif_payload_info *info;
51 u32 videoheader = 0;
52 int ret;
53 if (!cfsrvl_ready(service, &ret))
54 return ret;
55 cfpkt_add_head(pkt, &videoheader, 4);
56 /* Add info for MUX-layer to route the packet out */
57 info = cfpkt_info(pkt);
58 info->channel_id = service->layer.id;
59 info->dev_info = &service->dev_info;
60 return layr->dn->transmit(layr->dn, pkt);