treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 290
[linux-block.git] / drivers / net / ethernet / chelsio / cxgb4 / cudbg_common.c
CommitLineData
a7975a2f
RL
1/*
2 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 */
17
18#include "cxgb4.h"
19#include "cudbg_if.h"
20#include "cudbg_lib_common.h"
21
56cf2635
RL
22int cudbg_get_buff(struct cudbg_init *pdbg_init,
23 struct cudbg_buffer *pdbg_buff, u32 size,
a7975a2f
RL
24 struct cudbg_buffer *pin_buff)
25{
26 u32 offset;
27
28 offset = pdbg_buff->offset;
29 if (offset + size > pdbg_buff->size)
30 return CUDBG_STATUS_NO_MEM;
31
56cf2635
RL
32 if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) {
33 if (size > pdbg_init->compress_buff_size)
34 return CUDBG_STATUS_NO_MEM;
35
36 pin_buff->data = (char *)pdbg_init->compress_buff;
37 pin_buff->offset = 0;
38 pin_buff->size = size;
39 return 0;
40 }
41
a7975a2f
RL
42 pin_buff->data = (char *)pdbg_buff->data + offset;
43 pin_buff->offset = offset;
44 pin_buff->size = size;
a7975a2f
RL
45 return 0;
46}
47
56cf2635
RL
48void cudbg_put_buff(struct cudbg_init *pdbg_init,
49 struct cudbg_buffer *pin_buff)
a7975a2f 50{
56cf2635
RL
51 /* Clear compression buffer for re-use */
52 if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE)
53 memset(pdbg_init->compress_buff, 0,
54 pdbg_init->compress_buff_size);
55
a7975a2f
RL
56 pin_buff->data = NULL;
57 pin_buff->offset = 0;
58 pin_buff->size = 0;
59}
60
61void cudbg_update_buff(struct cudbg_buffer *pin_buff,
62 struct cudbg_buffer *pout_buff)
63{
64 /* We already write to buffer provided by ethool, so just
65 * increment offset to next free space.
66 */
67 pout_buff->offset += pin_buff->size;
68}