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_init *pdbg_init, 23 struct cudbg_buffer *pdbg_buff, u32 size, 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 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 42 pin_buff->data = (char *)pdbg_buff->data + offset; 43 pin_buff->offset = offset; 44 pin_buff->size = size; 45 return 0; 46 } 47 48 void cudbg_put_buff(struct cudbg_init *pdbg_init, 49 struct cudbg_buffer *pin_buff) 50 { 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 56 pin_buff->data = NULL; 57 pin_buff->offset = 0; 58 pin_buff->size = 0; 59 } 60 61 void 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 } 69