1/* 2 This software is available to you under a choice of one of two 3 licenses. You may choose to be licensed under the terms of the GNU 4 General Public License (GPL) Version 2, available at 5 <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD 6 license, available in the LICENSE.TXT file accompanying this 7 software. These details are also available at 8 <http://openib.org/license.html>. 9 10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 11 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 12 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 13 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 14 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 15 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 SOFTWARE. 18 19 Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved. 20*/ 21 22#ifndef H_MEMTRACK_H 23#define H_MEMTRACK_H 24 25enum memtrack_memtype_t { 26 MEMTRACK_KMALLOC, 27 MEMTRACK_VMALLOC, 28 MEMTRACK_KMEM_OBJ, 29 MEMTRACK_IOREMAP, /* IO-RE/UN-MAP */ 30 MEMTRACK_WORK_QUEUE, /* Handle work-queue create & destroy */ 31 MEMTRACK_PAGE_ALLOC, /* Handle page allocation and free */ 32 MEMTRACK_DMA_MAP_SINGLE,/* Handle ib_dma_single map and unmap */ 33 MEMTRACK_DMA_MAP_PAGE, /* Handle ib_dma_page map and unmap */ 34 MEMTRACK_DMA_MAP_SG, /* Handle ib_dma_sg map and unmap with and without attributes */ 35 MEMTRACK_NUM_OF_MEMTYPES 36}; 37 38/* Invoke on memory allocation */ 39void memtrack_alloc(enum memtrack_memtype_t memtype, unsigned long dev, 40 unsigned long addr, unsigned long size, unsigned long addr2, 41 int direction, const char *filename, 42 const unsigned long line_num, int alloc_flags); 43 44/* Invoke on memory free */ 45void memtrack_free(enum memtrack_memtype_t memtype, unsigned long dev, 46 unsigned long addr, unsigned long size, int direction, 47 const char *filename, const unsigned long line_num); 48 49/* 50 * This function recognizes allocations which 51 * may be released by kernel (e.g. skb & vnic) and 52 * therefore not trackable by memtrack. 53 * The allocations are recognized by the name 54 * of their calling function. 55 */ 56int is_non_trackable_alloc_func(const char *func_name); 57/* 58 * In some cases we need to free a memory 59 * we defined as "non trackable" (see 60 * is_non_trackable_alloc_func). 61 * This function recognizes such releases 62 * by the name of their calling function. 63 */ 64int is_non_trackable_free_func(const char *func_name); 65 66/* WA - In this function handles confirm 67 the function name is 68 '__ib_umem_release' or 'ib_umem_get' 69 In this case we won't track the 70 memory there because the kernel 71 was the one who allocated it. 72 Return value: 73 1 - if the function name is match, else 0 */ 74int is_umem_put_page(const char *func_name); 75 76/* Check page order size 77 When Freeing a page allocation it checks whether 78 we are trying to free the same amount of pages 79 we ask to allocate (In log2(order)). 80 In case an error if found it will print 81 an error msg */ 82int memtrack_check_size(enum memtrack_memtype_t memtype, unsigned long addr, 83 unsigned long size, const char *filename, 84 const unsigned long line_num); 85 86/* Search for a specific addr whether it exist in the 87 current data-base. 88 If not it will print an error msg, 89 Return value: 0 - if addr exist, else 1 */ 90int memtrack_is_new_addr(enum memtrack_memtype_t memtype, unsigned long addr, int expect_exist, 91 const char *filename, const unsigned long line_num); 92 93/* Return current page reference counter */ 94int memtrack_get_page_ref_count(unsigned long addr); 95 96/* Report current allocations status (for all memory types) */ 97/* we do not export this function since it is used by cleanup_module only */ 98/* void memtrack_report(void); */ 99 100/* Allow support of error injections */ 101int memtrack_inject_error(void); 102 103/* randomize allocated memory */ 104int memtrack_randomize_mem(void); 105 106#endif 107