Commit | Line | Data |
---|---|---|
85b84133 HM |
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 | ||
17 | ||
18 | #include <linux/types.h> | |
19 | #include <linux/slab.h> | |
20 | #include <linux/netdevice.h> | |
21 | ||
22 | #include <brcmu_wifi.h> | |
122d3d04 | 23 | #include "core.h" |
d14f78b9 | 24 | #include "bus.h" |
a8e8ed34 | 25 | #include "debug.h" |
85b84133 HM |
26 | #include "proto.h" |
27 | #include "bcdc.h" | |
9a1bb602 | 28 | #include "msgbuf.h" |
85b84133 HM |
29 | |
30 | ||
31 | int brcmf_proto_attach(struct brcmf_pub *drvr) | |
32 | { | |
33 | struct brcmf_proto *proto; | |
34 | ||
8851cce0 HM |
35 | brcmf_dbg(TRACE, "Enter\n"); |
36 | ||
85b84133 HM |
37 | proto = kzalloc(sizeof(*proto), GFP_ATOMIC); |
38 | if (!proto) | |
39 | goto fail; | |
40 | ||
41 | drvr->proto = proto; | |
85b84133 | 42 | |
9a1bb602 HM |
43 | if (drvr->bus_if->proto_type == BRCMF_PROTO_BCDC) { |
44 | if (brcmf_proto_bcdc_attach(drvr)) | |
45 | goto fail; | |
46 | } else if (drvr->bus_if->proto_type == BRCMF_PROTO_MSGBUF) { | |
47 | if (brcmf_proto_msgbuf_attach(drvr)) | |
48 | goto fail; | |
49 | } else { | |
50 | brcmf_err("Unsupported proto type %d\n", | |
51 | drvr->bus_if->proto_type); | |
52 | goto fail; | |
53 | } | |
7b8a466e | 54 | if ((proto->txdata == NULL) || (proto->hdrpull == NULL) || |
8851cce0 HM |
55 | (proto->query_dcmd == NULL) || (proto->set_dcmd == NULL) || |
56 | (proto->configure_addr_mode == NULL) || | |
70b7d94b | 57 | (proto->delete_peer == NULL) || (proto->add_tdls_peer == NULL)) { |
85b84133 HM |
58 | brcmf_err("Not all proto handlers have been installed\n"); |
59 | goto fail; | |
60 | } | |
61 | return 0; | |
62 | ||
63 | fail: | |
64 | kfree(proto); | |
65 | drvr->proto = NULL; | |
66 | return -ENOMEM; | |
67 | } | |
68 | ||
69 | void brcmf_proto_detach(struct brcmf_pub *drvr) | |
70 | { | |
8851cce0 HM |
71 | brcmf_dbg(TRACE, "Enter\n"); |
72 | ||
85b84133 | 73 | if (drvr->proto) { |
9a1bb602 HM |
74 | if (drvr->bus_if->proto_type == BRCMF_PROTO_BCDC) |
75 | brcmf_proto_bcdc_detach(drvr); | |
76 | else if (drvr->bus_if->proto_type == BRCMF_PROTO_MSGBUF) | |
77 | brcmf_proto_msgbuf_detach(drvr); | |
85b84133 HM |
78 | kfree(drvr->proto); |
79 | drvr->proto = NULL; | |
80 | } | |
81 | } |