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 
22 int cudbg_get_buff(struct cudbg_buffer *pdbg_buff, u32 size,
23 		   struct cudbg_buffer *pin_buff)
24 {
25 	u32 offset;
26 
27 	offset = pdbg_buff->offset;
28 	if (offset + size > pdbg_buff->size)
29 		return CUDBG_STATUS_NO_MEM;
30 
31 	pin_buff->data = (char *)pdbg_buff->data + offset;
32 	pin_buff->offset = offset;
33 	pin_buff->size = size;
34 	pdbg_buff->size -= size;
35 	return 0;
36 }
37 
38 void cudbg_put_buff(struct cudbg_buffer *pin_buff,
39 		    struct cudbg_buffer *pdbg_buff)
40 {
41 	pdbg_buff->size += pin_buff->size;
42 	pin_buff->data = NULL;
43 	pin_buff->offset = 0;
44 	pin_buff->size = 0;
45 }
46 
47 void cudbg_update_buff(struct cudbg_buffer *pin_buff,
48 		       struct cudbg_buffer *pout_buff)
49 {
50 	/* We already write to buffer provided by ethool, so just
51 	 * increment offset to next free space.
52 	 */
53 	pout_buff->offset += pin_buff->size;
54 }
55