| 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 |
#include "ips_tid.h" |
| 35 |
|
| 36 |
psm_error_t ips_ptl_handle_check_unit_status(psm_ep_t ep, int ips_rc); |
| 37 |
|
| 38 |
psm_error_t |
| 39 |
ips_tid_init(struct ips_tid *tidc, const psmi_context_t *context) |
| 40 |
{ |
| 41 |
const struct ipath_base_info *base_info = &context->base_info; |
| 42 |
struct psmi_stats_entry entries[] = { |
| 43 |
PSMI_STATS_DECL("tid update count", MPSPAWN_STATS_REDUCTION_ALL, |
| 44 |
NULL, &tidc->tid_num_total), |
| 45 |
}; |
| 46 |
|
| 47 |
tidc->context = context; |
| 48 |
tidc->tid_num_max = base_info->spi_tidcnt; |
| 49 |
tidc->tid_num_avail = base_info->spi_tidcnt; |
| 50 |
tidc->tid_pagesz = base_info->spi_tid_maxsize; |
| 51 |
|
| 52 |
tidc->tid_num_total = 0; |
| 53 |
|
| 54 |
return psmi_stats_register_type(PSMI_STATS_NO_HEADING, |
| 55 |
PSMI_STATSTYPE_TIDS, |
| 56 |
entries, |
| 57 |
PSMI_STATS_HOWMANY(entries), |
| 58 |
tidc); |
| 59 |
} |
| 60 |
|
| 61 |
psm_error_t |
| 62 |
ips_tid_fini(struct ips_tid *tidc) |
| 63 |
{ |
| 64 |
return PSM_OK; |
| 65 |
} |
| 66 |
|
| 67 |
psm_error_t |
| 68 |
ips_tid_acquire(struct ips_tid *tidc, const void *buf, |
| 69 |
int ntids, ips_tidmap_t tid_map, |
| 70 |
uint16_t *tid_array) |
| 71 |
{ |
| 72 |
psm_error_t err = PSM_OK; |
| 73 |
int rc; |
| 74 |
|
| 75 |
psmi_assert((uintptr_t)buf % tidc->tid_pagesz == 0); |
| 76 |
psmi_assert(ntids <= tidc->tid_num_avail); |
| 77 |
|
| 78 |
rc = ipath_update_tid(tidc->context->ctrl, ntids, |
| 79 |
(uint64_t)(uintptr_t) tid_array, |
| 80 |
(uint64_t)(uintptr_t) buf, |
| 81 |
(uint64_t)(uintptr_t) tid_map); |
| 82 |
|
| 83 |
if (rc != 0) { |
| 84 |
/* We're still going to fail but check unit status */ |
| 85 |
err = psmi_err_only(psmi_context_check_status(tidc->context)); |
| 86 |
if (err == PSM_OK) /* okay, but something else is still wrong */ |
| 87 |
err = psmi_handle_error(tidc->context->ep, PSM_EP_DEVICE_FAILURE, |
| 88 |
"Failed to update %d tids", |
| 89 |
ntids); |
| 90 |
goto fail; |
| 91 |
} |
| 92 |
|
| 93 |
tidc->tid_num_total += ntids; |
| 94 |
tidc->tid_num_avail -= ntids; |
| 95 |
|
| 96 |
fail: |
| 97 |
return err; |
| 98 |
} |
| 99 |
|
| 100 |
psm_error_t |
| 101 |
ips_tid_release(struct ips_tid *tidc, ips_tidmap_t tidmap, int ntids) |
| 102 |
{ |
| 103 |
psm_error_t err = PSM_OK; |
| 104 |
|
| 105 |
if (ipath_free_tid(tidc->context->ctrl, ntids, |
| 106 |
(uint64_t) (uintptr_t) tidmap)) { |
| 107 |
err = PSM_EP_DEVICE_FAILURE; |
| 108 |
goto fail; |
| 109 |
} |
| 110 |
|
| 111 |
tidc->tid_num_avail += ntids; |
| 112 |
|
| 113 |
fail: |
| 114 |
return err; |
| 115 |
} |
| 116 |
|