18c2ecf20Sopenharmony_ci#ifndef _HFI1_EXP_RCV_H 28c2ecf20Sopenharmony_ci#define _HFI1_EXP_RCV_H 38c2ecf20Sopenharmony_ci/* 48c2ecf20Sopenharmony_ci * Copyright(c) 2017 Intel Corporation. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 78c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 128c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 138c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 168c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 178c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 188c2ecf20Sopenharmony_ci * General Public License for more details. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * BSD LICENSE 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 238c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 248c2ecf20Sopenharmony_ci * are met: 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above copyright 278c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 288c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright 298c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 308c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 318c2ecf20Sopenharmony_ci * distribution. 328c2ecf20Sopenharmony_ci * - Neither the name of Intel Corporation nor the names of its 338c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived 348c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 378c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 388c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 398c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 408c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 418c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 428c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 438c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 448c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 458c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 468c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci */ 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#include "hfi.h" 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define EXP_TID_SET_EMPTY(set) (set.count == 0 && list_empty(&set.list)) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define EXP_TID_TIDLEN_MASK 0x7FFULL 558c2ecf20Sopenharmony_ci#define EXP_TID_TIDLEN_SHIFT 0 568c2ecf20Sopenharmony_ci#define EXP_TID_TIDCTRL_MASK 0x3ULL 578c2ecf20Sopenharmony_ci#define EXP_TID_TIDCTRL_SHIFT 20 588c2ecf20Sopenharmony_ci#define EXP_TID_TIDIDX_MASK 0x3FFULL 598c2ecf20Sopenharmony_ci#define EXP_TID_TIDIDX_SHIFT 22 608c2ecf20Sopenharmony_ci#define EXP_TID_GET(tid, field) \ 618c2ecf20Sopenharmony_ci (((tid) >> EXP_TID_TID##field##_SHIFT) & EXP_TID_TID##field##_MASK) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define EXP_TID_SET(field, value) \ 648c2ecf20Sopenharmony_ci (((value) & EXP_TID_TID##field##_MASK) << \ 658c2ecf20Sopenharmony_ci EXP_TID_TID##field##_SHIFT) 668c2ecf20Sopenharmony_ci#define EXP_TID_CLEAR(tid, field) ({ \ 678c2ecf20Sopenharmony_ci (tid) &= ~(EXP_TID_TID##field##_MASK << \ 688c2ecf20Sopenharmony_ci EXP_TID_TID##field##_SHIFT); \ 698c2ecf20Sopenharmony_ci }) 708c2ecf20Sopenharmony_ci#define EXP_TID_RESET(tid, field, value) do { \ 718c2ecf20Sopenharmony_ci EXP_TID_CLEAR(tid, field); \ 728c2ecf20Sopenharmony_ci (tid) |= EXP_TID_SET(field, (value)); \ 738c2ecf20Sopenharmony_ci } while (0) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* 768c2ecf20Sopenharmony_ci * Define fields in the KDETH header so we can update the header 778c2ecf20Sopenharmony_ci * template. 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci#define KDETH_OFFSET_SHIFT 0 808c2ecf20Sopenharmony_ci#define KDETH_OFFSET_MASK 0x7fff 818c2ecf20Sopenharmony_ci#define KDETH_OM_SHIFT 15 828c2ecf20Sopenharmony_ci#define KDETH_OM_MASK 0x1 838c2ecf20Sopenharmony_ci#define KDETH_TID_SHIFT 16 848c2ecf20Sopenharmony_ci#define KDETH_TID_MASK 0x3ff 858c2ecf20Sopenharmony_ci#define KDETH_TIDCTRL_SHIFT 26 868c2ecf20Sopenharmony_ci#define KDETH_TIDCTRL_MASK 0x3 878c2ecf20Sopenharmony_ci#define KDETH_INTR_SHIFT 28 888c2ecf20Sopenharmony_ci#define KDETH_INTR_MASK 0x1 898c2ecf20Sopenharmony_ci#define KDETH_SH_SHIFT 29 908c2ecf20Sopenharmony_ci#define KDETH_SH_MASK 0x1 918c2ecf20Sopenharmony_ci#define KDETH_KVER_SHIFT 30 928c2ecf20Sopenharmony_ci#define KDETH_KVER_MASK 0x3 938c2ecf20Sopenharmony_ci#define KDETH_JKEY_SHIFT 0x0 948c2ecf20Sopenharmony_ci#define KDETH_JKEY_MASK 0xff 958c2ecf20Sopenharmony_ci#define KDETH_HCRC_UPPER_SHIFT 16 968c2ecf20Sopenharmony_ci#define KDETH_HCRC_UPPER_MASK 0xff 978c2ecf20Sopenharmony_ci#define KDETH_HCRC_LOWER_SHIFT 24 988c2ecf20Sopenharmony_ci#define KDETH_HCRC_LOWER_MASK 0xff 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define KDETH_GET(val, field) \ 1018c2ecf20Sopenharmony_ci (((le32_to_cpu((val))) >> KDETH_##field##_SHIFT) & KDETH_##field##_MASK) 1028c2ecf20Sopenharmony_ci#define KDETH_SET(dw, field, val) do { \ 1038c2ecf20Sopenharmony_ci u32 dwval = le32_to_cpu(dw); \ 1048c2ecf20Sopenharmony_ci dwval &= ~(KDETH_##field##_MASK << KDETH_##field##_SHIFT); \ 1058c2ecf20Sopenharmony_ci dwval |= (((val) & KDETH_##field##_MASK) << \ 1068c2ecf20Sopenharmony_ci KDETH_##field##_SHIFT); \ 1078c2ecf20Sopenharmony_ci dw = cpu_to_le32(dwval); \ 1088c2ecf20Sopenharmony_ci } while (0) 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#define KDETH_RESET(dw, field, val) ({ dw = 0; KDETH_SET(dw, field, val); }) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* KDETH OM multipliers and switch over point */ 1138c2ecf20Sopenharmony_ci#define KDETH_OM_SMALL 4 1148c2ecf20Sopenharmony_ci#define KDETH_OM_SMALL_SHIFT 2 1158c2ecf20Sopenharmony_ci#define KDETH_OM_LARGE 64 1168c2ecf20Sopenharmony_ci#define KDETH_OM_LARGE_SHIFT 6 1178c2ecf20Sopenharmony_ci#define KDETH_OM_MAX_SIZE (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1)) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistruct tid_group { 1208c2ecf20Sopenharmony_ci struct list_head list; 1218c2ecf20Sopenharmony_ci u32 base; 1228c2ecf20Sopenharmony_ci u8 size; 1238c2ecf20Sopenharmony_ci u8 used; 1248c2ecf20Sopenharmony_ci u8 map; 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* 1288c2ecf20Sopenharmony_ci * Write an "empty" RcvArray entry. 1298c2ecf20Sopenharmony_ci * This function exists so the TID registaration code can use it 1308c2ecf20Sopenharmony_ci * to write to unused/unneeded entries and still take advantage 1318c2ecf20Sopenharmony_ci * of the WC performance improvements. The HFI will ignore this 1328c2ecf20Sopenharmony_ci * write to the RcvArray entry. 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistatic inline void rcv_array_wc_fill(struct hfi1_devdata *dd, u32 index) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci /* 1378c2ecf20Sopenharmony_ci * Doing the WC fill writes only makes sense if the device is 1388c2ecf20Sopenharmony_ci * present and the RcvArray has been mapped as WC memory. 1398c2ecf20Sopenharmony_ci */ 1408c2ecf20Sopenharmony_ci if ((dd->flags & HFI1_PRESENT) && dd->rcvarray_wc) { 1418c2ecf20Sopenharmony_ci writeq(0, dd->rcvarray_wc + (index * 8)); 1428c2ecf20Sopenharmony_ci if ((index & 3) == 3) 1438c2ecf20Sopenharmony_ci flush_wc(); 1448c2ecf20Sopenharmony_ci } 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistatic inline void tid_group_add_tail(struct tid_group *grp, 1488c2ecf20Sopenharmony_ci struct exp_tid_set *set) 1498c2ecf20Sopenharmony_ci{ 1508c2ecf20Sopenharmony_ci list_add_tail(&grp->list, &set->list); 1518c2ecf20Sopenharmony_ci set->count++; 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic inline void tid_group_remove(struct tid_group *grp, 1558c2ecf20Sopenharmony_ci struct exp_tid_set *set) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci list_del_init(&grp->list); 1588c2ecf20Sopenharmony_ci set->count--; 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic inline void tid_group_move(struct tid_group *group, 1628c2ecf20Sopenharmony_ci struct exp_tid_set *s1, 1638c2ecf20Sopenharmony_ci struct exp_tid_set *s2) 1648c2ecf20Sopenharmony_ci{ 1658c2ecf20Sopenharmony_ci tid_group_remove(group, s1); 1668c2ecf20Sopenharmony_ci tid_group_add_tail(group, s2); 1678c2ecf20Sopenharmony_ci} 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistatic inline struct tid_group *tid_group_pop(struct exp_tid_set *set) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci struct tid_group *grp = 1728c2ecf20Sopenharmony_ci list_first_entry(&set->list, struct tid_group, list); 1738c2ecf20Sopenharmony_ci list_del_init(&grp->list); 1748c2ecf20Sopenharmony_ci set->count--; 1758c2ecf20Sopenharmony_ci return grp; 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic inline u32 rcventry2tidinfo(u32 rcventry) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci u32 pair = rcventry & ~0x1; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci return EXP_TID_SET(IDX, pair >> 1) | 1838c2ecf20Sopenharmony_ci EXP_TID_SET(CTRL, 1 << (rcventry - pair)); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/** 1878c2ecf20Sopenharmony_ci * hfi1_tid_group_to_idx - convert an index to a group 1888c2ecf20Sopenharmony_ci * @rcd - the receive context 1898c2ecf20Sopenharmony_ci * @grp - the group pointer 1908c2ecf20Sopenharmony_ci */ 1918c2ecf20Sopenharmony_cistatic inline u16 1928c2ecf20Sopenharmony_cihfi1_tid_group_to_idx(struct hfi1_ctxtdata *rcd, struct tid_group *grp) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci return grp - &rcd->groups[0]; 1958c2ecf20Sopenharmony_ci} 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/** 1988c2ecf20Sopenharmony_ci * hfi1_idx_to_tid_group - convert a group to an index 1998c2ecf20Sopenharmony_ci * @rcd - the receive context 2008c2ecf20Sopenharmony_ci * @idx - the index 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_cistatic inline struct tid_group * 2038c2ecf20Sopenharmony_cihfi1_idx_to_tid_group(struct hfi1_ctxtdata *rcd, u16 idx) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci return &rcd->groups[idx]; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ciint hfi1_alloc_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd); 2098c2ecf20Sopenharmony_civoid hfi1_free_ctxt_rcv_groups(struct hfi1_ctxtdata *rcd); 2108c2ecf20Sopenharmony_civoid hfi1_exp_tid_group_init(struct hfi1_ctxtdata *rcd); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#endif /* _HFI1_EXP_RCV_H */ 213