2 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
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.
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
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
20 #include "cudbg_lib_common.h"
22 int cudbg_get_buff(struct cudbg_init *pdbg_init,
23 struct cudbg_buffer *pdbg_buff, u32 size,
24 struct cudbg_buffer *pin_buff)
28 offset = pdbg_buff->offset;
29 if (offset + size > pdbg_buff->size)
30 return CUDBG_STATUS_NO_MEM;
32 if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) {
33 if (size > pdbg_init->compress_buff_size)
34 return CUDBG_STATUS_NO_MEM;
36 pin_buff->data = (char *)pdbg_init->compress_buff;
38 pin_buff->size = size;
42 pin_buff->data = (char *)pdbg_buff->data + offset;
43 pin_buff->offset = offset;
44 pin_buff->size = size;
48 void cudbg_put_buff(struct cudbg_init *pdbg_init,
49 struct cudbg_buffer *pin_buff)
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);
56 pin_buff->data = NULL;
61 void cudbg_update_buff(struct cudbg_buffer *pin_buff,
62 struct cudbg_buffer *pout_buff)
64 /* We already write to buffer provided by ethool, so just
65 * increment offset to next free space.
67 pout_buff->offset += pin_buff->size;