intel-gtt: generic (insert|remove)_entries for g33/i965
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / caif / cfveil.c
blob77cc09faac9a305cfa4a05554ad95bea6d52e08e
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 #include <linux/stddef.h>
8 #include <linux/slab.h>
9 #include <net/caif/caif_layer.h>
10 #include <net/caif/cfsrvl.h>
11 #include <net/caif/cfpkt.h>
13 #define VEI_PAYLOAD 0x00
14 #define VEI_CMD_BIT 0x80
15 #define VEI_FLOW_OFF 0x81
16 #define VEI_FLOW_ON 0x80
17 #define VEI_SET_PIN 0x82
18 #define VEI_CTRL_PKT_SIZE 1
19 #define container_obj(layr) container_of(layr, struct cfsrvl, layer)
21 static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt);
22 static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt);
24 struct cflayer *cfvei_create(u8 channel_id, struct dev_info *dev_info)
26 struct cfsrvl *vei = kmalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
27 if (!vei) {
28 pr_warning("CAIF: %s(): Out of memory\n", __func__);
29 return NULL;
31 caif_assert(offsetof(struct cfsrvl, layer) == 0);
32 memset(vei, 0, sizeof(struct cfsrvl));
33 cfsrvl_init(vei, channel_id, dev_info, true);
34 vei->layer.receive = cfvei_receive;
35 vei->layer.transmit = cfvei_transmit;
36 snprintf(vei->layer.name, CAIF_LAYER_NAME_SZ - 1, "vei%d", channel_id);
37 return &vei->layer;
40 static int cfvei_receive(struct cflayer *layr, struct cfpkt *pkt)
42 u8 cmd;
43 int ret;
44 caif_assert(layr->up != NULL);
45 caif_assert(layr->receive != NULL);
46 caif_assert(layr->ctrlcmd != NULL);
49 if (cfpkt_extr_head(pkt, &cmd, 1) < 0) {
50 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__);
51 cfpkt_destroy(pkt);
52 return -EPROTO;
54 switch (cmd) {
55 case VEI_PAYLOAD:
56 ret = layr->up->receive(layr->up, pkt);
57 return ret;
58 case VEI_FLOW_OFF:
59 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_OFF_IND, 0);
60 cfpkt_destroy(pkt);
61 return 0;
62 case VEI_FLOW_ON:
63 layr->ctrlcmd(layr, CAIF_CTRLCMD_FLOW_ON_IND, 0);
64 cfpkt_destroy(pkt);
65 return 0;
66 case VEI_SET_PIN: /* SET RS232 PIN */
67 cfpkt_destroy(pkt);
68 return 0;
69 default: /* SET RS232 PIN */
70 pr_warning("CAIF: %s():Unknown VEI control packet %d (0x%x)!\n",
71 __func__, cmd, cmd);
72 cfpkt_destroy(pkt);
73 return -EPROTO;
77 static int cfvei_transmit(struct cflayer *layr, struct cfpkt *pkt)
79 u8 tmp = 0;
80 struct caif_payload_info *info;
81 int ret;
82 struct cfsrvl *service = container_obj(layr);
83 if (!cfsrvl_ready(service, &ret))
84 return ret;
85 caif_assert(layr->dn != NULL);
86 caif_assert(layr->dn->transmit != NULL);
88 if (cfpkt_add_head(pkt, &tmp, 1) < 0) {
89 pr_err("CAIF: %s(): Packet is erroneous!\n", __func__);
90 return -EPROTO;
93 /* Add info-> for MUX-layer to route the packet out. */
94 info = cfpkt_info(pkt);
95 info->channel_id = service->layer.id;
96 info->hdr_len = 1;
97 info->dev_info = &service->dev_info;
98 ret = layr->dn->transmit(layr->dn, pkt);
99 if (ret < 0)
100 cfpkt_extr_head(pkt, &tmp, 1);
101 return ret;