proto.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "core.h"
  21. #include "bus.h"
  22. #include "debug.h"
  23. #include "proto.h"
  24. #include "bcdc.h"
  25. #include "msgbuf.h"
  26. int brcmf_proto_attach(struct brcmf_pub *drvr)
  27. {
  28. struct brcmf_proto *proto;
  29. brcmf_dbg(TRACE, "Enter\n");
  30. proto = kzalloc(sizeof(*proto), GFP_ATOMIC);
  31. if (!proto)
  32. goto fail;
  33. drvr->proto = proto;
  34. if (drvr->bus_if->proto_type == BRCMF_PROTO_BCDC) {
  35. if (brcmf_proto_bcdc_attach(drvr))
  36. goto fail;
  37. } else if (drvr->bus_if->proto_type == BRCMF_PROTO_MSGBUF) {
  38. if (brcmf_proto_msgbuf_attach(drvr))
  39. goto fail;
  40. } else {
  41. brcmf_err("Unsupported proto type %d\n",
  42. drvr->bus_if->proto_type);
  43. goto fail;
  44. }
  45. if (!proto->tx_queue_data || (proto->hdrpull == NULL) ||
  46. (proto->query_dcmd == NULL) || (proto->set_dcmd == NULL) ||
  47. (proto->configure_addr_mode == NULL) ||
  48. (proto->delete_peer == NULL) || (proto->add_tdls_peer == NULL) ||
  49. (proto->debugfs_create == NULL)) {
  50. brcmf_err("Not all proto handlers have been installed\n");
  51. goto fail;
  52. }
  53. return 0;
  54. fail:
  55. kfree(proto);
  56. drvr->proto = NULL;
  57. return -ENOMEM;
  58. }
  59. void brcmf_proto_detach_post_delif(struct brcmf_pub *drvr)
  60. {
  61. brcmf_dbg(TRACE, "Enter\n");
  62. if (drvr->proto) {
  63. if (drvr->bus_if->proto_type == BRCMF_PROTO_BCDC)
  64. brcmf_proto_bcdc_detach_post_delif(drvr);
  65. else if (drvr->bus_if->proto_type == BRCMF_PROTO_MSGBUF)
  66. brcmf_proto_msgbuf_detach(drvr);
  67. kfree(drvr->proto);
  68. drvr->proto = NULL;
  69. }
  70. }
  71. void brcmf_proto_detach_pre_delif(struct brcmf_pub *drvr)
  72. {
  73. if (drvr->proto && drvr->bus_if->proto_type == BRCMF_PROTO_BCDC)
  74. brcmf_proto_bcdc_detach_pre_delif(drvr);
  75. }