Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include "txgbe_type.h"
7 : : #include "txgbe_mng.h"
8 : :
9 : : /**
10 : : * txgbe_calculate_checksum - Calculate checksum for buffer
11 : : * @buffer: pointer to EEPROM
12 : : * @length: size of EEPROM to calculate a checksum for
13 : : * Calculates the checksum for some buffer on a specified length. The
14 : : * checksum calculated is returned.
15 : : **/
16 : : static u8
17 : : txgbe_calculate_checksum(u8 *buffer, u32 length)
18 : : {
19 : : u32 i;
20 : : u8 sum = 0;
21 : :
22 [ # # # # ]: 0 : for (i = 0; i < length; i++)
23 : 0 : sum += buffer[i];
24 : :
25 : 0 : return (u8)(0 - sum);
26 : : }
27 : :
28 : : /**
29 : : * txgbe_hic_unlocked - Issue command to manageability block unlocked
30 : : * @hw: pointer to the HW structure
31 : : * @buffer: command to write and where the return status will be placed
32 : : * @length: length of buffer, must be multiple of 4 bytes
33 : : * @timeout: time in ms to wait for command completion
34 : : *
35 : : * Communicates with the manageability block. On success return 0
36 : : * else returns semaphore error when encountering an error acquiring
37 : : * semaphore or TXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
38 : : *
39 : : * This function assumes that the TXGBE_MNGSEM_SWMBX semaphore is held
40 : : * by the caller.
41 : : **/
42 : : static s32
43 : 0 : txgbe_hic_unlocked(struct txgbe_hw *hw, u32 *buffer, u32 length, u32 timeout)
44 : : {
45 : : u32 value, loop;
46 : : u16 i, dword_len;
47 : :
48 [ # # ]: 0 : if (!length || length > TXGBE_PMMBX_BSIZE) {
49 : 0 : DEBUGOUT("Buffer length failure buffersize=%d.", length);
50 : 0 : return TXGBE_ERR_HOST_INTERFACE_COMMAND;
51 : : }
52 : :
53 : : /* Calculate length in DWORDs. We must be DWORD aligned */
54 [ # # ]: 0 : if (length % sizeof(u32)) {
55 : 0 : DEBUGOUT("Buffer length failure, not aligned to dword");
56 : 0 : return TXGBE_ERR_INVALID_ARGUMENT;
57 : : }
58 : :
59 : 0 : dword_len = length >> 2;
60 : :
61 : : /* The device driver writes the relevant command block
62 : : * into the ram area.
63 : : */
64 [ # # ]: 0 : for (i = 0; i < dword_len; i++) {
65 : 0 : wr32a(hw, TXGBE_MNGMBX, i, cpu_to_le32(buffer[i]));
66 : 0 : buffer[i] = rd32a(hw, TXGBE_MNGMBX, i);
67 : : }
68 : : txgbe_flush(hw);
69 : :
70 : : /* Setting this bit tells the ARC that a new command is pending. */
71 : : wr32m(hw, TXGBE_MNGMBXCTL,
72 : : TXGBE_MNGMBXCTL_SWRDY, TXGBE_MNGMBXCTL_SWRDY);
73 : :
74 : : /* Check command completion */
75 : 0 : loop = po32m(hw, TXGBE_MNGMBXCTL,
76 : : TXGBE_MNGMBXCTL_FWRDY, TXGBE_MNGMBXCTL_FWRDY,
77 : : &value, timeout, 1000);
78 [ # # # # ]: 0 : if (!loop || !(value & TXGBE_MNGMBXCTL_FWACK)) {
79 : 0 : DEBUGOUT("Command has failed with no status valid.");
80 : 0 : return TXGBE_ERR_HOST_INTERFACE_COMMAND;
81 : : }
82 : :
83 [ # # ]: 0 : if ((rd32(hw, TXGBE_MNGMBX) & 0xff0000) >> 16 == 0x80) {
84 : 0 : DEBUGOUT("It's unknown command.");
85 : 0 : return TXGBE_ERR_MNG_ACCESS_FAILED;
86 : : }
87 : :
88 : : return 0;
89 : : }
90 : :
91 : : /**
92 : : * txgbe_host_interface_command - Issue command to manageability block
93 : : * @hw: pointer to the HW structure
94 : : * @buffer: contains the command to write and where the return status will
95 : : * be placed
96 : : * @length: length of buffer, must be multiple of 4 bytes
97 : : * @timeout: time in ms to wait for command completion
98 : : * @return_data: read and return data from the buffer (true) or not (false)
99 : : * Needed because FW structures are big endian and decoding of
100 : : * these fields can be 8 bit or 16 bit based on command. Decoding
101 : : * is not easily understood without making a table of commands.
102 : : * So we will leave this up to the caller to read back the data
103 : : * in these cases.
104 : : *
105 : : * Communicates with the manageability block. On success return 0
106 : : * else returns semaphore error when encountering an error acquiring
107 : : * semaphore or TXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
108 : : **/
109 : : static s32
110 : 0 : txgbe_host_interface_command(struct txgbe_hw *hw, u32 *buffer,
111 : : u32 length, u32 timeout, bool return_data)
112 : : {
113 : : u32 hdr_size = sizeof(struct txgbe_hic_hdr);
114 : : struct txgbe_hic_hdr *resp = (struct txgbe_hic_hdr *)buffer;
115 : : u16 buf_len;
116 : : s32 err;
117 : : u32 bi;
118 : : u32 dword_len;
119 : :
120 [ # # ]: 0 : if (length == 0 || length > TXGBE_PMMBX_BSIZE) {
121 : 0 : DEBUGOUT("Buffer length failure buffersize=%d.", length);
122 : 0 : return TXGBE_ERR_HOST_INTERFACE_COMMAND;
123 : : }
124 : :
125 : : /* Take management host interface semaphore */
126 : 0 : err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWMBX);
127 [ # # ]: 0 : if (err)
128 : : return err;
129 : :
130 : 0 : err = txgbe_hic_unlocked(hw, buffer, length, timeout);
131 [ # # ]: 0 : if (err)
132 : 0 : goto rel_out;
133 : :
134 [ # # ]: 0 : if (!return_data)
135 : 0 : goto rel_out;
136 : :
137 : : /* Calculate length in DWORDs */
138 : : dword_len = hdr_size >> 2;
139 : :
140 : : /* first pull in the header so we know the buffer length */
141 [ # # ]: 0 : for (bi = 0; bi < dword_len; bi++)
142 : 0 : buffer[bi] = rd32a(hw, TXGBE_MNGMBX, bi);
143 : :
144 : 0 : buf_len = resp->buf_len;
145 [ # # ]: 0 : if (!buf_len)
146 : 0 : goto rel_out;
147 : :
148 [ # # ]: 0 : if (length < buf_len + hdr_size) {
149 : 0 : DEBUGOUT("Buffer not large enough for reply message.");
150 : : err = TXGBE_ERR_HOST_INTERFACE_COMMAND;
151 : 0 : goto rel_out;
152 : : }
153 : :
154 : : /* Calculate length in DWORDs, add 3 for odd lengths */
155 : 0 : dword_len = (buf_len + 3) >> 2;
156 : :
157 : : /* Pull in the rest of the buffer (bi is where we left off) */
158 [ # # ]: 0 : for (; bi <= dword_len; bi++)
159 : 0 : buffer[bi] = rd32a(hw, TXGBE_MNGMBX, bi);
160 : :
161 : 0 : rel_out:
162 : 0 : hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWMBX);
163 : :
164 : 0 : return err;
165 : : }
166 : :
167 : : /**
168 : : * txgbe_hic_sr_read - Read EEPROM word using a host interface cmd
169 : : * assuming that the semaphore is already obtained.
170 : : * @hw: pointer to hardware structure
171 : : * @offset: offset of word in the EEPROM to read
172 : : * @data: word read from the EEPROM
173 : : *
174 : : * Reads a 16 bit word from the EEPROM using the hostif.
175 : : **/
176 : 0 : s32 txgbe_hic_sr_read(struct txgbe_hw *hw, u32 addr, u8 *buf, int len)
177 : : {
178 : : struct txgbe_hic_read_shadow_ram command;
179 : : u32 value;
180 : : int err, i = 0, j = 0;
181 : :
182 [ # # ]: 0 : if (len > TXGBE_PMMBX_DATA_SIZE)
183 : : return TXGBE_ERR_HOST_INTERFACE_COMMAND;
184 : :
185 : : memset(&command, 0, sizeof(command));
186 : 0 : command.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
187 : : command.hdr.req.buf_lenh = 0;
188 : 0 : command.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
189 : 0 : command.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
190 [ # # ]: 0 : command.address = cpu_to_be32(addr);
191 [ # # ]: 0 : command.length = cpu_to_be16(len);
192 : :
193 : 0 : err = txgbe_hic_unlocked(hw, (u32 *)&command,
194 : : sizeof(command), TXGBE_HI_COMMAND_TIMEOUT);
195 [ # # ]: 0 : if (err)
196 : : return err;
197 : :
198 [ # # ]: 0 : while (i < (len >> 2)) {
199 : 0 : value = rd32a(hw, TXGBE_MNGMBX, FW_NVM_DATA_OFFSET + i);
200 : 0 : ((u32 *)buf)[i] = value;
201 : 0 : i++;
202 : : }
203 : :
204 : 0 : value = rd32a(hw, TXGBE_MNGMBX, FW_NVM_DATA_OFFSET + i);
205 [ # # ]: 0 : for (i <<= 2; i < len; i++)
206 : 0 : ((u8 *)buf)[i] = ((u8 *)&value)[j++];
207 : :
208 : : return 0;
209 : : }
210 : :
211 : : /**
212 : : * txgbe_hic_sr_write - Write EEPROM word using hostif
213 : : * @hw: pointer to hardware structure
214 : : * @offset: offset of word in the EEPROM to write
215 : : * @data: word write to the EEPROM
216 : : *
217 : : * Write a 16 bit word to the EEPROM using the hostif.
218 : : **/
219 : 0 : s32 txgbe_hic_sr_write(struct txgbe_hw *hw, u32 addr, u8 *buf, int len)
220 : : {
221 : : struct txgbe_hic_write_shadow_ram command;
222 : : u32 value;
223 : : int err = 0, i = 0, j = 0;
224 : :
225 [ # # ]: 0 : if (len > TXGBE_PMMBX_DATA_SIZE)
226 : : return TXGBE_ERR_HOST_INTERFACE_COMMAND;
227 : :
228 : : memset(&command, 0, sizeof(command));
229 : 0 : command.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
230 : : command.hdr.req.buf_lenh = 0;
231 : 0 : command.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
232 : 0 : command.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
233 [ # # ]: 0 : command.address = cpu_to_be32(addr);
234 [ # # ]: 0 : command.length = cpu_to_be16(len);
235 : :
236 [ # # ]: 0 : while (i < (len >> 2)) {
237 : 0 : value = ((u32 *)buf)[i];
238 : 0 : wr32a(hw, TXGBE_MNGMBX, FW_NVM_DATA_OFFSET + i, value);
239 : 0 : i++;
240 : : }
241 : :
242 [ # # ]: 0 : for (i <<= 2; i < len; i++)
243 : 0 : ((u8 *)&value)[j++] = ((u8 *)buf)[i];
244 : :
245 : 0 : wr32a(hw, TXGBE_MNGMBX, FW_NVM_DATA_OFFSET + (i >> 2), value);
246 : :
247 : : UNREFERENCED_PARAMETER(&command);
248 : :
249 : 0 : return err;
250 : : }
251 : :
252 : 0 : s32 txgbe_close_notify(struct txgbe_hw *hw)
253 : : {
254 : : u32 tmp;
255 : : s32 status;
256 : : struct txgbe_hic_write_shadow_ram buffer;
257 : :
258 : 0 : buffer.hdr.req.cmd = FW_DW_CLOSE_NOTIFY;
259 : 0 : buffer.hdr.req.buf_lenh = 0;
260 : 0 : buffer.hdr.req.buf_lenl = 0;
261 : 0 : buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
262 : :
263 : : /* one word */
264 : 0 : buffer.length = 0;
265 : 0 : buffer.address = 0;
266 : :
267 : 0 : status = txgbe_host_interface_command(hw, (u32 *)&buffer,
268 : : sizeof(buffer),
269 : : TXGBE_HI_COMMAND_TIMEOUT, false);
270 [ # # ]: 0 : if (status)
271 : : return status;
272 : :
273 : : tmp = rd32a(hw, TXGBE_MNGMBX, 1);
274 [ # # ]: 0 : if (tmp == TXGBE_CHECKSUM_CAP_ST_PASS)
275 : : status = 0;
276 : : else
277 : : status = TXGBE_ERR_EEPROM_CHECKSUM;
278 : :
279 : : return status;
280 : : }
281 : :
282 : 0 : s32 txgbe_open_notify(struct txgbe_hw *hw)
283 : : {
284 : : u32 tmp;
285 : : s32 status;
286 : : struct txgbe_hic_write_shadow_ram buffer;
287 : :
288 : 0 : buffer.hdr.req.cmd = FW_DW_OPEN_NOTIFY;
289 : 0 : buffer.hdr.req.buf_lenh = 0;
290 : 0 : buffer.hdr.req.buf_lenl = 0;
291 : 0 : buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
292 : :
293 : : /* one word */
294 : 0 : buffer.length = 0;
295 : 0 : buffer.address = 0;
296 : :
297 : 0 : status = txgbe_host_interface_command(hw, (u32 *)&buffer,
298 : : sizeof(buffer),
299 : : TXGBE_HI_COMMAND_TIMEOUT, false);
300 [ # # ]: 0 : if (status)
301 : : return status;
302 : :
303 : : tmp = rd32a(hw, TXGBE_MNGMBX, 1);
304 [ # # ]: 0 : if (tmp == TXGBE_CHECKSUM_CAP_ST_PASS)
305 : : status = 0;
306 : : else
307 : : status = TXGBE_ERR_EEPROM_CHECKSUM;
308 : :
309 : : return status;
310 : : }
311 : :
312 : : /**
313 : : * txgbe_hic_set_drv_ver - Sends driver version to firmware
314 : : * @hw: pointer to the HW structure
315 : : * @maj: driver version major number
316 : : * @min: driver version minor number
317 : : * @build: driver version build number
318 : : * @sub: driver version sub build number
319 : : * @len: unused
320 : : * @driver_ver: unused
321 : : *
322 : : * Sends driver version number to firmware through the manageability
323 : : * block. On success return 0
324 : : * else returns TXGBE_ERR_SWFW_SYNC when encountering an error acquiring
325 : : * semaphore or TXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
326 : : **/
327 : 0 : s32 txgbe_hic_set_drv_ver(struct txgbe_hw *hw, u8 maj, u8 min,
328 : : u8 build, u8 sub, u16 len,
329 : : const char *driver_ver)
330 : : {
331 : : struct txgbe_hic_drv_info fw_cmd;
332 : : int i;
333 : : s32 ret_val = 0;
334 : :
335 : : UNREFERENCED_PARAMETER(len, driver_ver);
336 : :
337 : 0 : fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
338 : 0 : fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
339 : 0 : fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
340 : 0 : fw_cmd.port_num = (u8)hw->bus.func;
341 : 0 : fw_cmd.ver_maj = maj;
342 : 0 : fw_cmd.ver_min = min;
343 : 0 : fw_cmd.ver_build = build;
344 : 0 : fw_cmd.ver_sub = sub;
345 : 0 : fw_cmd.hdr.checksum = 0;
346 : 0 : fw_cmd.pad = 0;
347 : 0 : fw_cmd.pad2 = 0;
348 : 0 : fw_cmd.hdr.checksum = txgbe_calculate_checksum((u8 *)&fw_cmd,
349 : : (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
350 : :
351 [ # # ]: 0 : for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
352 : 0 : ret_val = txgbe_host_interface_command(hw, (u32 *)&fw_cmd,
353 : : sizeof(fw_cmd),
354 : : TXGBE_HI_COMMAND_TIMEOUT,
355 : : true);
356 [ # # ]: 0 : if (ret_val != 0)
357 : : continue;
358 : :
359 [ # # ]: 0 : if (fw_cmd.hdr.cmd_or_resp.ret_status ==
360 : : FW_CEM_RESP_STATUS_SUCCESS)
361 : : ret_val = 0;
362 : : else
363 : : ret_val = TXGBE_ERR_HOST_INTERFACE_COMMAND;
364 : :
365 : : break;
366 : : }
367 : :
368 : 0 : return ret_val;
369 : : }
370 : :
371 : : /**
372 : : * txgbe_hic_reset - send reset cmd to fw
373 : : * @hw: pointer to hardware structure
374 : : *
375 : : * Sends reset cmd to firmware through the manageability
376 : : * block. On success return 0
377 : : * else returns TXGBE_ERR_SWFW_SYNC when encountering an error acquiring
378 : : * semaphore or TXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
379 : : **/
380 : : s32
381 : 0 : txgbe_hic_reset(struct txgbe_hw *hw)
382 : : {
383 : : struct txgbe_hic_reset reset_cmd;
384 : : int i;
385 : : s32 err = 0;
386 : :
387 : 0 : reset_cmd.hdr.cmd = FW_RESET_CMD;
388 : 0 : reset_cmd.hdr.buf_len = FW_RESET_LEN;
389 : 0 : reset_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
390 : 0 : reset_cmd.lan_id = hw->bus.lan_id;
391 : 0 : reset_cmd.reset_type = (u16)hw->reset_type;
392 : 0 : reset_cmd.hdr.checksum = 0;
393 : 0 : reset_cmd.hdr.checksum = txgbe_calculate_checksum((u8 *)&reset_cmd,
394 : : (FW_CEM_HDR_LEN + reset_cmd.hdr.buf_len));
395 : :
396 [ # # ]: 0 : for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
397 : 0 : err = txgbe_host_interface_command(hw, (u32 *)&reset_cmd,
398 : : sizeof(reset_cmd),
399 : : TXGBE_HI_COMMAND_TIMEOUT,
400 : : true);
401 [ # # ]: 0 : if (err != 0)
402 : : continue;
403 : :
404 [ # # ]: 0 : if (reset_cmd.hdr.cmd_or_resp.ret_status ==
405 : : FW_CEM_RESP_STATUS_SUCCESS)
406 : : err = 0;
407 : : else
408 : : err = TXGBE_ERR_HOST_INTERFACE_COMMAND;
409 : :
410 : : break;
411 : : }
412 : :
413 : 0 : return err;
414 : : }
415 : :
416 : : /**
417 : : * txgbe_mng_present - returns true when management capability is present
418 : : * @hw: pointer to hardware structure
419 : : */
420 : : bool
421 : 0 : txgbe_mng_present(struct txgbe_hw *hw)
422 : : {
423 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_unknown)
424 : : return false;
425 : :
426 : 0 : return !!rd32m(hw, TXGBE_STAT, TXGBE_STAT_MNGINIT);
427 : : }
428 : :
429 : : /**
430 : : * txgbe_mng_enabled - Is the manageability engine enabled?
431 : : * @hw: pointer to hardware structure
432 : : *
433 : : * Returns true if the manageability engine is enabled.
434 : : **/
435 : : bool
436 : 0 : txgbe_mng_enabled(struct txgbe_hw *hw)
437 : : {
438 : : UNREFERENCED_PARAMETER(hw);
439 : : /* firmware does not control laser */
440 : 0 : return false;
441 : : }
|