proto.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2013 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/slab.h>
  18. #include <linux/netdevice.h>
  19. #include <brcmu_wifi.h>
  20. #include "dhd.h"
  21. #include "dhd_dbg.h"
  22. #include "proto.h"
  23. #include "bcdc.h"
  24. int brcmf_proto_attach(struct brcmf_pub *drvr)
  25. {
  26. struct brcmf_proto *proto;
  27. proto = kzalloc(sizeof(*proto), GFP_ATOMIC);
  28. if (!proto)
  29. goto fail;
  30. drvr->proto = proto;
  31. /* BCDC protocol is only protocol supported for the moment */
  32. if (brcmf_proto_bcdc_attach(drvr))
  33. goto fail;
  34. if ((proto->txdata == NULL) || (proto->hdrpull == NULL) ||
  35. (proto->query_dcmd == NULL) || (proto->set_dcmd == NULL)) {
  36. brcmf_err("Not all proto handlers have been installed\n");
  37. goto fail;
  38. }
  39. return 0;
  40. fail:
  41. kfree(proto);
  42. drvr->proto = NULL;
  43. return -ENOMEM;
  44. }
  45. void brcmf_proto_detach(struct brcmf_pub *drvr)
  46. {
  47. if (drvr->proto) {
  48. brcmf_proto_bcdc_detach(drvr);
  49. kfree(drvr->proto);
  50. drvr->proto = NULL;
  51. }
  52. }