18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Chelsio Communications. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "cxgb4.h" 78c2ecf20Sopenharmony_ci#include "cudbg_if.h" 88c2ecf20Sopenharmony_ci#include "cudbg_lib_common.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciint cudbg_get_buff(struct cudbg_init *pdbg_init, 118c2ecf20Sopenharmony_ci struct cudbg_buffer *pdbg_buff, u32 size, 128c2ecf20Sopenharmony_ci struct cudbg_buffer *pin_buff) 138c2ecf20Sopenharmony_ci{ 148c2ecf20Sopenharmony_ci u32 offset; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci offset = pdbg_buff->offset; 178c2ecf20Sopenharmony_ci if (offset + size > pdbg_buff->size) 188c2ecf20Sopenharmony_ci return CUDBG_STATUS_NO_MEM; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) { 218c2ecf20Sopenharmony_ci if (size > pdbg_init->compress_buff_size) 228c2ecf20Sopenharmony_ci return CUDBG_STATUS_NO_MEM; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci pin_buff->data = (char *)pdbg_init->compress_buff; 258c2ecf20Sopenharmony_ci pin_buff->offset = 0; 268c2ecf20Sopenharmony_ci pin_buff->size = size; 278c2ecf20Sopenharmony_ci return 0; 288c2ecf20Sopenharmony_ci } 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci pin_buff->data = (char *)pdbg_buff->data + offset; 318c2ecf20Sopenharmony_ci pin_buff->offset = offset; 328c2ecf20Sopenharmony_ci pin_buff->size = size; 338c2ecf20Sopenharmony_ci return 0; 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_civoid cudbg_put_buff(struct cudbg_init *pdbg_init, 378c2ecf20Sopenharmony_ci struct cudbg_buffer *pin_buff) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci /* Clear compression buffer for re-use */ 408c2ecf20Sopenharmony_ci if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) 418c2ecf20Sopenharmony_ci memset(pdbg_init->compress_buff, 0, 428c2ecf20Sopenharmony_ci pdbg_init->compress_buff_size); 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci pin_buff->data = NULL; 458c2ecf20Sopenharmony_ci pin_buff->offset = 0; 468c2ecf20Sopenharmony_ci pin_buff->size = 0; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_civoid cudbg_update_buff(struct cudbg_buffer *pin_buff, 508c2ecf20Sopenharmony_ci struct cudbg_buffer *pout_buff) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci /* We already write to buffer provided by ethool, so just 538c2ecf20Sopenharmony_ci * increment offset to next free space. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci pout_buff->offset += pin_buff->size; 568c2ecf20Sopenharmony_ci} 57