1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/kernel.h>
17#include "as102_drv.h"
18#include "as10x_cmd.h"
19
20
21
22
23
24
25
26
27
28
29
30
31
32int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
33 uint32_t *pvalue)
34{
35 int error;
36 struct as10x_cmd_t *pcmd, *prsp;
37
38 pcmd = adap->cmd;
39 prsp = adap->rsp;
40
41
42 as10x_cmd_build(pcmd, (++adap->cmd_xid),
43 sizeof(pcmd->body.context.req));
44
45
46 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
47 pcmd->body.context.req.tag = cpu_to_le16(tag);
48 pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
49
50
51 if (adap->ops->xfer_cmd) {
52 error = adap->ops->xfer_cmd(adap,
53 (uint8_t *) pcmd,
54 sizeof(pcmd->body.context.req)
55 + HEADER_SIZE,
56 (uint8_t *) prsp,
57 sizeof(prsp->body.context.rsp)
58 + HEADER_SIZE);
59 } else {
60 error = AS10X_CMD_ERROR;
61 }
62
63 if (error < 0)
64 goto out;
65
66
67
68 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
69
70 if (error == 0) {
71
72 *pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
73
74 }
75
76out:
77 return error;
78}
79
80
81
82
83
84
85
86
87
88int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
89 uint32_t value)
90{
91 int error;
92 struct as10x_cmd_t *pcmd, *prsp;
93
94 pcmd = adap->cmd;
95 prsp = adap->rsp;
96
97
98 as10x_cmd_build(pcmd, (++adap->cmd_xid),
99 sizeof(pcmd->body.context.req));
100
101
102 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
103
104 pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
105 pcmd->body.context.req.tag = cpu_to_le16(tag);
106 pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
107
108
109 if (adap->ops->xfer_cmd) {
110 error = adap->ops->xfer_cmd(adap,
111 (uint8_t *) pcmd,
112 sizeof(pcmd->body.context.req)
113 + HEADER_SIZE,
114 (uint8_t *) prsp,
115 sizeof(prsp->body.context.rsp)
116 + HEADER_SIZE);
117 } else {
118 error = AS10X_CMD_ERROR;
119 }
120
121 if (error < 0)
122 goto out;
123
124
125
126 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
127
128out:
129 return error;
130}
131
132
133
134
135
136
137
138
139
140
141
142
143int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
144{
145 int error;
146 struct as10x_cmd_t *pcmd, *prsp;
147
148 pcmd = adap->cmd;
149 prsp = adap->rsp;
150
151
152 as10x_cmd_build(pcmd, (++adap->cmd_xid),
153 sizeof(pcmd->body.cfg_change_mode.req));
154
155
156 pcmd->body.cfg_change_mode.req.proc_id =
157 cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
158 pcmd->body.cfg_change_mode.req.mode = mode;
159
160
161 if (adap->ops->xfer_cmd) {
162 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
163 sizeof(pcmd->body.cfg_change_mode.req)
164 + HEADER_SIZE, (uint8_t *) prsp,
165 sizeof(prsp->body.cfg_change_mode.rsp)
166 + HEADER_SIZE);
167 } else {
168 error = AS10X_CMD_ERROR;
169 }
170
171 if (error < 0)
172 goto out;
173
174
175 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
176
177out:
178 return error;
179}
180
181
182
183
184
185
186
187
188
189
190int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
191{
192 int err;
193
194 err = prsp->body.context.rsp.error;
195
196 if ((err == 0) &&
197 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
198 return 0;
199 }
200 return AS10X_CMD_ERROR;
201}
202