162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2017 Chelsio Communications. All rights reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include "cxgb4.h" 762306a36Sopenharmony_ci#include "cudbg_if.h" 862306a36Sopenharmony_ci#include "cudbg_lib_common.h" 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciint cudbg_get_buff(struct cudbg_init *pdbg_init, 1162306a36Sopenharmony_ci struct cudbg_buffer *pdbg_buff, u32 size, 1262306a36Sopenharmony_ci struct cudbg_buffer *pin_buff) 1362306a36Sopenharmony_ci{ 1462306a36Sopenharmony_ci u32 offset; 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci offset = pdbg_buff->offset; 1762306a36Sopenharmony_ci if (offset + size > pdbg_buff->size) 1862306a36Sopenharmony_ci return CUDBG_STATUS_NO_MEM; 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) { 2162306a36Sopenharmony_ci if (size > pdbg_init->compress_buff_size) 2262306a36Sopenharmony_ci return CUDBG_STATUS_NO_MEM; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci pin_buff->data = (char *)pdbg_init->compress_buff; 2562306a36Sopenharmony_ci pin_buff->offset = 0; 2662306a36Sopenharmony_ci pin_buff->size = size; 2762306a36Sopenharmony_ci return 0; 2862306a36Sopenharmony_ci } 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci pin_buff->data = (char *)pdbg_buff->data + offset; 3162306a36Sopenharmony_ci pin_buff->offset = offset; 3262306a36Sopenharmony_ci pin_buff->size = size; 3362306a36Sopenharmony_ci return 0; 3462306a36Sopenharmony_ci} 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_civoid cudbg_put_buff(struct cudbg_init *pdbg_init, 3762306a36Sopenharmony_ci struct cudbg_buffer *pin_buff) 3862306a36Sopenharmony_ci{ 3962306a36Sopenharmony_ci /* Clear compression buffer for re-use */ 4062306a36Sopenharmony_ci if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) 4162306a36Sopenharmony_ci memset(pdbg_init->compress_buff, 0, 4262306a36Sopenharmony_ci pdbg_init->compress_buff_size); 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci pin_buff->data = NULL; 4562306a36Sopenharmony_ci pin_buff->offset = 0; 4662306a36Sopenharmony_ci pin_buff->size = 0; 4762306a36Sopenharmony_ci} 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_civoid cudbg_update_buff(struct cudbg_buffer *pin_buff, 5062306a36Sopenharmony_ci struct cudbg_buffer *pout_buff) 5162306a36Sopenharmony_ci{ 5262306a36Sopenharmony_ci /* We already write to buffer provided by ethool, so just 5362306a36Sopenharmony_ci * increment offset to next free space. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ci pout_buff->offset += pin_buff->size; 5662306a36Sopenharmony_ci} 57