| 1 |
/* |
| 2 |
* Copyright (c) 2006-2012. QLogic Corporation. All rights reserved. |
| 3 |
* Copyright (c) 2003-2006, PathScale, Inc. All rights reserved. |
| 4 |
* |
| 5 |
* This software is available to you under a choice of one of two |
| 6 |
* licenses. You may choose to be licensed under the terms of the GNU |
| 7 |
* General Public License (GPL) Version 2, available from the file |
| 8 |
* COPYING in the main directory of this source tree, or the |
| 9 |
* OpenIB.org BSD license below: |
| 10 |
* |
| 11 |
* Redistribution and use in source and binary forms, with or |
| 12 |
* without modification, are permitted provided that the following |
| 13 |
* conditions are met: |
| 14 |
* |
| 15 |
* - Redistributions of source code must retain the above |
| 16 |
* copyright notice, this list of conditions and the following |
| 17 |
* disclaimer. |
| 18 |
* |
| 19 |
* - Redistributions in binary form must reproduce the above |
| 20 |
* copyright notice, this list of conditions and the following |
| 21 |
* disclaimer in the documentation and/or other materials |
| 22 |
* provided with the distribution. |
| 23 |
* |
| 24 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 |
* SOFTWARE. |
| 32 |
*/ |
| 33 |
|
| 34 |
/* included header files */ |
| 35 |
|
| 36 |
#ifndef _IPS_TID_H |
| 37 |
#define _IPS_TID_H |
| 38 |
|
| 39 |
#include "psm_user.h" |
| 40 |
|
| 41 |
#define IPS_TID_MAX_TIDS 512 |
| 42 |
#define IPS_TID_ALIGNMENT 4 |
| 43 |
|
| 44 |
typedef uint64_t ips_tidmap_t[IPS_TID_MAX_TIDS/64]; |
| 45 |
|
| 46 |
struct ips_tid { |
| 47 |
const psmi_context_t *context; |
| 48 |
|
| 49 |
uint32_t tid_num_max; |
| 50 |
uint32_t tid_num_avail; |
| 51 |
uint32_t tid_pagesz; |
| 52 |
|
| 53 |
uint64_t tid_num_total; |
| 54 |
}; |
| 55 |
|
| 56 |
psm_error_t ips_tid_init(struct ips_tid *tidc, const psmi_context_t *context); |
| 57 |
psm_error_t ips_tid_fini(struct ips_tid *tidc); |
| 58 |
|
| 59 |
/* Acquiring tids. |
| 60 |
* Buffer base has to be aligned on ips_tid_page_size() boundary |
| 61 |
* Buffer base+length has to be aligned on IPS_TID_ALIGNMENT boundary |
| 62 |
*/ |
| 63 |
psm_error_t |
| 64 |
ips_tid_acquire(struct ips_tid *tidc, |
| 65 |
const void *buf, /* input buffer, aligned to page_size */ |
| 66 |
int ntids, /* input number of tids */ |
| 67 |
ips_tidmap_t tidmap, /* output tidmap */ |
| 68 |
uint16_t *tid_array); /* output tidarray, */ |
| 69 |
|
| 70 |
psm_error_t |
| 71 |
ips_tid_release(struct ips_tid *tidc, |
| 72 |
ips_tidmap_t tidmap, /* input tidmap */ |
| 73 |
int ntids); /* intput number of tids to release */ |
| 74 |
PSMI_INLINE( |
| 75 |
psm_error_t |
| 76 |
ips_tid_num_available(struct ips_tid *tidc)) |
| 77 |
{ |
| 78 |
return tidc->tid_num_avail; |
| 79 |
} |
| 80 |
|
| 81 |
PSMI_INLINE( |
| 82 |
int |
| 83 |
ips_tid_num_required(struct ips_tid *tidc, void *bufi, uint32_t length)) |
| 84 |
{ |
| 85 |
uintptr_t buf = (uintptr_t) bufi; |
| 86 |
const uint32_t page_size = tidc->tid_pagesz; |
| 87 |
|
| 88 |
return (PSMI_ALIGNUP(buf + length, page_size) - |
| 89 |
PSMI_ALIGNDOWN(buf, page_size)) / page_size; |
| 90 |
} |
| 91 |
|
| 92 |
PSMI_INLINE( |
| 93 |
uint32_t |
| 94 |
ips_tid_page_size(struct ips_tid *tidc)) |
| 95 |
{ |
| 96 |
return tidc->tid_pagesz; |
| 97 |
} |
| 98 |
|
| 99 |
#endif /* _IPS_TID_H */ |