cfdbgl.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Author: Sjur Brendeland
  4. * License terms: GNU General Public License (GPL) version 2
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ":%s(): " fmt, __func__
  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>
  12. #define container_obj(layr) ((struct cfsrvl *) layr)
  13. static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt);
  14. static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt);
  15. struct cflayer *cfdbgl_create(u8 channel_id, struct dev_info *dev_info)
  16. {
  17. struct cfsrvl *dbg = kzalloc(sizeof(struct cfsrvl), GFP_ATOMIC);
  18. if (!dbg)
  19. return NULL;
  20. caif_assert(offsetof(struct cfsrvl, layer) == 0);
  21. cfsrvl_init(dbg, channel_id, dev_info, false);
  22. dbg->layer.receive = cfdbgl_receive;
  23. dbg->layer.transmit = cfdbgl_transmit;
  24. snprintf(dbg->layer.name, CAIF_LAYER_NAME_SZ - 1, "dbg%d", channel_id);
  25. return &dbg->layer;
  26. }
  27. static int cfdbgl_receive(struct cflayer *layr, struct cfpkt *pkt)
  28. {
  29. return layr->up->receive(layr->up, pkt);
  30. }
  31. static int cfdbgl_transmit(struct cflayer *layr, struct cfpkt *pkt)
  32. {
  33. struct cfsrvl *service = container_obj(layr);
  34. struct caif_payload_info *info;
  35. int ret;
  36. if (!cfsrvl_ready(service, &ret)) {
  37. cfpkt_destroy(pkt);
  38. return ret;
  39. }
  40. /* Add info for MUX-layer to route the packet out */
  41. info = cfpkt_info(pkt);
  42. info->channel_id = service->layer.id;
  43. info->dev_info = &service->dev_info;
  44. return layr->dn->transmit(layr->dn, pkt);
  45. }