diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c deleted file mode 100644 index 489930a746b2..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c +++ /dev/null @@ -1,299 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include - -static int iwch_mod_load(void); -static int iwch_mod_unload(void); -static int iwch_activate(struct adapter *); -static int iwch_deactivate(struct adapter *); - -static struct uld_info iwch_uld_info = { - .uld_id = ULD_IWARP, - .activate = iwch_activate, - .deactivate = iwch_deactivate, -}; - -static void -rnic_init(struct iwch_dev *rnicp) -{ - - idr_init(&rnicp->cqidr); - idr_init(&rnicp->qpidr); - idr_init(&rnicp->mmidr); - mtx_init(&rnicp->lock, "iwch rnic lock", NULL, MTX_DEF|MTX_DUPOK); - - rnicp->attr.vendor_id = 0x168; - rnicp->attr.vendor_part_id = 7; - rnicp->attr.max_qps = T3_MAX_NUM_QP - 32; - rnicp->attr.max_wrs = T3_MAX_QP_DEPTH; - rnicp->attr.max_sge_per_wr = T3_MAX_SGE; - rnicp->attr.max_sge_per_rdma_write_wr = T3_MAX_SGE; - rnicp->attr.max_cqs = T3_MAX_NUM_CQ - 1; - rnicp->attr.max_cqes_per_cq = T3_MAX_CQ_DEPTH; - rnicp->attr.max_mem_regs = cxio_num_stags(&rnicp->rdev); - rnicp->attr.max_phys_buf_entries = T3_MAX_PBL_SIZE; - rnicp->attr.max_pds = T3_MAX_NUM_PD - 1; - rnicp->attr.mem_pgsizes_bitmask = T3_PAGESIZE_MASK; - rnicp->attr.max_mr_size = T3_MAX_MR_SIZE; - rnicp->attr.can_resize_wq = 0; - rnicp->attr.max_rdma_reads_per_qp = 8; - rnicp->attr.max_rdma_read_resources = - rnicp->attr.max_rdma_reads_per_qp * rnicp->attr.max_qps; - rnicp->attr.max_rdma_read_qp_depth = 8; /* IRD */ - rnicp->attr.max_rdma_read_depth = - rnicp->attr.max_rdma_read_qp_depth * rnicp->attr.max_qps; - rnicp->attr.rq_overflow_handled = 0; - rnicp->attr.can_modify_ird = 0; - rnicp->attr.can_modify_ord = 0; - rnicp->attr.max_mem_windows = rnicp->attr.max_mem_regs - 1; - rnicp->attr.stag0_value = 1; - rnicp->attr.zbva_support = 1; - rnicp->attr.local_invalidate_fence = 1; - rnicp->attr.cq_overflow_detection = 1; - - return; -} - -static void -rnic_uninit(struct iwch_dev *rnicp) -{ - idr_destroy(&rnicp->cqidr); - idr_destroy(&rnicp->qpidr); - idr_destroy(&rnicp->mmidr); - mtx_destroy(&rnicp->lock); -} - -static int -iwch_activate(struct adapter *sc) -{ - struct iwch_dev *rnicp; - int rc; - - KASSERT(!isset(&sc->offload_map, MAX_NPORTS), - ("%s: iWARP already activated on %s", __func__, - device_get_nameunit(sc->dev))); - - rnicp = (struct iwch_dev *)ib_alloc_device(sizeof(*rnicp)); - if (rnicp == NULL) - return (ENOMEM); - - sc->iwarp_softc = rnicp; - rnicp->rdev.adap = sc; - - cxio_hal_init(sc); - iwch_cm_init_cpl(sc); - - rc = cxio_rdev_open(&rnicp->rdev); - if (rc != 0) { - printf("Unable to open CXIO rdev\n"); - goto err1; - } - - rnic_init(rnicp); - - rc = iwch_register_device(rnicp); - if (rc != 0) { - printf("Unable to register device\n"); - goto err2; - } - - return (0); - -err2: - rnic_uninit(rnicp); - cxio_rdev_close(&rnicp->rdev); -err1: - cxio_hal_uninit(sc); - iwch_cm_term_cpl(sc); - sc->iwarp_softc = NULL; - - return (rc); -} - -static int -iwch_deactivate(struct adapter *sc) -{ - struct iwch_dev *rnicp; - - rnicp = sc->iwarp_softc; - - iwch_unregister_device(rnicp); - rnic_uninit(rnicp); - cxio_rdev_close(&rnicp->rdev); - cxio_hal_uninit(sc); - iwch_cm_term_cpl(sc); - ib_dealloc_device(&rnicp->ibdev); - - sc->iwarp_softc = NULL; - - return (0); -} - -static void -iwch_activate_all(struct adapter *sc, void *arg __unused) -{ - ADAPTER_LOCK(sc); - if ((sc->open_device_map & sc->offload_map) != 0 && - t3_activate_uld(sc, ULD_IWARP) == 0) - setbit(&sc->offload_map, MAX_NPORTS); - ADAPTER_UNLOCK(sc); -} - -static void -iwch_deactivate_all(struct adapter *sc, void *arg __unused) -{ - ADAPTER_LOCK(sc); - if (isset(&sc->offload_map, MAX_NPORTS) && - t3_deactivate_uld(sc, ULD_IWARP) == 0) - clrbit(&sc->offload_map, MAX_NPORTS); - ADAPTER_UNLOCK(sc); -} - -static int -iwch_mod_load(void) -{ - int rc; - - rc = iwch_cm_init(); - if (rc != 0) - return (rc); - - rc = t3_register_uld(&iwch_uld_info); - if (rc != 0) { - iwch_cm_term(); - return (rc); - } - - t3_iterate(iwch_activate_all, NULL); - - return (rc); -} - -static int -iwch_mod_unload(void) -{ - t3_iterate(iwch_deactivate_all, NULL); - - iwch_cm_term(); - - if (t3_unregister_uld(&iwch_uld_info) == EBUSY) - return (EBUSY); - - return (0); -} -#endif /* TCP_OFFLOAD */ - -static int -iwch_modevent(module_t mod, int cmd, void *arg) -{ - int rc = 0; - -#ifdef TCP_OFFLOAD - switch (cmd) { - case MOD_LOAD: - rc = iwch_mod_load(); - if(rc) - printf("iw_cxgb: Chelsio T3 RDMA Driver failed to load\n"); - else - printf("iw_cxgb: Chelsio T3 RDMA Driver loaded\n"); - break; - - case MOD_UNLOAD: - rc = iwch_mod_unload(); - if(rc) - printf("iw_cxgb: Chelsio T3 RDMA Driver failed to unload\n"); - else - printf("iw_cxgb: Chelsio T3 RDMA Driver unloaded\n"); - break; - - default: - rc = EINVAL; - } -#else - printf("iw_cxgb: compiled without TCP_OFFLOAD support.\n"); - rc = EOPNOTSUPP; -#endif - return (rc); -} - -static moduledata_t iwch_mod_data = { - "iw_cxgb", - iwch_modevent, - 0 -}; - -MODULE_VERSION(iw_cxgb, 1); -DECLARE_MODULE(iw_cxgb, iwch_mod_data, SI_SUB_EXEC, SI_ORDER_ANY); -MODULE_DEPEND(t3_tom, cxgbc, 1, 1, 1); -MODULE_DEPEND(iw_cxgb, toecore, 1, 1, 1); -MODULE_DEPEND(iw_cxgb, t3_tom, 1, 1, 1); -MODULE_DEPEND(iw_cxgb, ibcore, 1, 1, 1); -MODULE_DEPEND(iw_cxgb, linuxkpi, 1, 1, 1); - diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.h deleted file mode 100644 index 81f305fad5e4..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.h +++ /dev/null @@ -1,178 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ - -#ifndef __IWCH_H__ -#define __IWCH_H__ - -struct iwch_pd; -struct iwch_cq; -struct iwch_qp; -struct iwch_mr; - -enum t3ctype { - T3A = 0, - T3B, - T3C -}; - -#define PAGE_MASK_IWARP (~(PAGE_SIZE-1)) - -struct iwch_rnic_attributes { - u32 vendor_id; - u32 vendor_part_id; - u32 max_qps; - u32 max_wrs; /* Max for any SQ/RQ */ - u32 max_sge_per_wr; - u32 max_sge_per_rdma_write_wr; /* for RDMA Write WR */ - u32 max_cqs; - u32 max_cqes_per_cq; - u32 max_mem_regs; - u32 max_phys_buf_entries; /* for phys buf list */ - u32 max_pds; - - /* - * The memory page sizes supported by this RNIC. - * Bit position i in bitmap indicates page of - * size (4k)^i. Phys block list mode unsupported. - */ - u32 mem_pgsizes_bitmask; - u64 max_mr_size; - u8 can_resize_wq; - - /* - * The maximum number of RDMA Reads that can be outstanding - * per QP with this RNIC as the target. - */ - u32 max_rdma_reads_per_qp; - - /* - * The maximum number of resources used for RDMA Reads - * by this RNIC with this RNIC as the target. - */ - u32 max_rdma_read_resources; - - /* - * The max depth per QP for initiation of RDMA Read - * by this RNIC. - */ - u32 max_rdma_read_qp_depth; - - /* - * The maximum depth for initiation of RDMA Read - * operations by this RNIC on all QPs - */ - u32 max_rdma_read_depth; - u8 rq_overflow_handled; - u32 can_modify_ird; - u32 can_modify_ord; - u32 max_mem_windows; - u32 stag0_value; - u8 zbva_support; - u8 local_invalidate_fence; - u32 cq_overflow_detection; -}; - -struct iwch_dev { - struct ib_device ibdev; - struct cxio_rdev rdev; - u32 device_cap_flags; - struct iwch_rnic_attributes attr; - struct idr cqidr; - struct idr qpidr; - struct idr mmidr; - struct mtx lock; - TAILQ_ENTRY(iwch_dev) entry; -}; - -#ifndef container_of -#define container_of(p, stype, field) ((stype *)(((uint8_t *)(p)) - offsetof(stype, field))) -#endif - -static inline struct iwch_dev *to_iwch_dev(struct ib_device *ibdev) -{ - return container_of(ibdev, struct iwch_dev, ibdev); -} - -static inline int t3b_device(const struct iwch_dev *rhp __unused) -{ - return (0); -} - -static inline int t3a_device(const struct iwch_dev *rhp __unused) -{ - return (0); -} - -static inline struct iwch_cq *get_chp(struct iwch_dev *rhp, u32 cqid) -{ - return idr_find(&rhp->cqidr, cqid); -} - -static inline struct iwch_qp *get_qhp(struct iwch_dev *rhp, u32 qpid) -{ - return idr_find(&rhp->qpidr, qpid); -} - -static inline struct iwch_mr *get_mhp(struct iwch_dev *rhp, u32 mmid) -{ - return idr_find(&rhp->mmidr, mmid); -} - -static inline int insert_handle(struct iwch_dev *rhp, struct idr *idr, - void *handle, u32 id) -{ - int ret; - u32 newid; - - do { - if (!idr_pre_get(idr, GFP_KERNEL)) { - return -ENOMEM; - } - mtx_lock(&rhp->lock); - ret = idr_get_new_above(idr, handle, id, &newid); - WARN_ON(ret != 0); - WARN_ON(!ret && newid != id); - mtx_unlock(&rhp->lock); - } while (ret == -EAGAIN); - - return ret; -} - -static inline void remove_handle(struct iwch_dev *rhp, struct idr *idr, u32 id) -{ - mtx_lock(&rhp->lock); - idr_remove(idr, id); - mtx_unlock(&rhp->lock); -} - -void iwch_ev_dispatch(struct iwch_dev *, struct mbuf *); -void process_newconn(struct iw_cm_id *parent_cm_id, struct socket *child_so); -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c deleted file mode 100644 index 5a838194538b..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c +++ /dev/null @@ -1,1685 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef KTR -static char *states[] = { - "idle", - "listen", - "connecting", - "mpa_wait_req", - "mpa_req_sent", - "mpa_req_rcvd", - "mpa_rep_sent", - "fpdu_mode", - "aborting", - "closing", - "moribund", - "dead", - NULL, -}; -#endif - -SYSCTL_NODE(_hw, OID_AUTO, iw_cxgb, CTLFLAG_RD, 0, "iw_cxgb driver parameters"); - -static int ep_timeout_secs = 60; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, ep_timeout_secs, CTLFLAG_RWTUN, &ep_timeout_secs, 0, - "CM Endpoint operation timeout in seconds (default=60)"); - -static int mpa_rev = 1; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, mpa_rev, CTLFLAG_RWTUN, &mpa_rev, 0, - "MPA Revision, 0 supports amso1100, 1 is spec compliant. (default=1)"); - -static int markers_enabled = 0; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, markers_enabled, CTLFLAG_RWTUN, &markers_enabled, 0, - "Enable MPA MARKERS (default(0)=disabled)"); - -static int crc_enabled = 1; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, crc_enabled, CTLFLAG_RWTUN, &crc_enabled, 0, - "Enable MPA CRC (default(1)=enabled)"); - -static int rcv_win = 256 * 1024; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, rcv_win, CTLFLAG_RWTUN, &rcv_win, 0, - "TCP receive window in bytes (default=256KB)"); - -static int snd_win = 32 * 1024; -SYSCTL_INT(_hw_iw_cxgb, OID_AUTO, snd_win, CTLFLAG_RWTUN, &snd_win, 0, - "TCP send window in bytes (default=32KB)"); - -static unsigned int nocong = 0; -SYSCTL_UINT(_hw_iw_cxgb, OID_AUTO, nocong, CTLFLAG_RWTUN, &nocong, 0, - "Turn off congestion control (default=0)"); - -static unsigned int cong_flavor = 1; -SYSCTL_UINT(_hw_iw_cxgb, OID_AUTO, cong_flavor, CTLFLAG_RWTUN, &cong_flavor, 0, - "TCP Congestion control flavor (default=1)"); - -static void ep_timeout(void *arg); -static void connect_reply_upcall(struct iwch_ep *ep, int status); -static int iwch_so_upcall(struct socket *so, void *arg, int waitflag); - -/* - * Cruft to offload socket upcalls onto thread. - */ -static struct mtx req_lock; -static TAILQ_HEAD(iwch_ep_list, iwch_ep_common) req_list; -static struct task iw_cxgb_task; -static struct taskqueue *iw_cxgb_taskq; -static void process_req(void *ctx, int pending); - -static void -start_ep_timer(struct iwch_ep *ep) -{ - CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep); - if (callout_pending(&ep->timer)) { - CTR2(KTR_IW_CXGB, "%s stopped / restarted timer ep %p", __FUNCTION__, ep); - callout_deactivate(&ep->timer); - callout_drain(&ep->timer); - } else { - /* - * XXX this looks racy - */ - get_ep(&ep->com); - callout_init(&ep->timer, 1); - } - callout_reset(&ep->timer, ep_timeout_secs * hz, ep_timeout, ep); -} - -static void -stop_ep_timer(struct iwch_ep *ep) -{ - CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep); - if (!callout_pending(&ep->timer)) { - CTR3(KTR_IW_CXGB, "%s timer stopped when its not running! ep %p state %u\n", - __func__, ep, ep->com.state); - return; - } - callout_drain(&ep->timer); - put_ep(&ep->com); -} - -static int -set_tcpinfo(struct iwch_ep *ep) -{ - struct socket *so = ep->com.so; - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp; - struct toepcb *toep; - int rc = 0; - - INP_WLOCK(inp); - tp = intotcpcb(inp); - - if ((tp->t_flags & TF_TOE) == 0) { - rc = EINVAL; - printf("%s: connection NOT OFFLOADED!\n", __func__); - goto done; - } - toep = tp->t_toe; - - ep->hwtid = toep->tp_tid; - ep->snd_seq = tp->snd_nxt; - ep->rcv_seq = tp->rcv_nxt; - ep->emss = tp->t_maxseg; - if (ep->emss < 128) - ep->emss = 128; -done: - INP_WUNLOCK(inp); - return (rc); - -} - -static enum iwch_ep_state -state_read(struct iwch_ep_common *epc) -{ - enum iwch_ep_state state; - - mtx_lock(&epc->lock); - state = epc->state; - mtx_unlock(&epc->lock); - return state; -} - -static void -__state_set(struct iwch_ep_common *epc, enum iwch_ep_state new) -{ - epc->state = new; -} - -static void -state_set(struct iwch_ep_common *epc, enum iwch_ep_state new) -{ - - mtx_lock(&epc->lock); - CTR3(KTR_IW_CXGB, "%s - %s -> %s", __FUNCTION__, states[epc->state], states[new]); - __state_set(epc, new); - mtx_unlock(&epc->lock); - return; -} - -static void * -alloc_ep(int size, int flags) -{ - struct iwch_ep_common *epc; - - epc = malloc(size, M_DEVBUF, flags); - if (epc) { - memset(epc, 0, size); - refcount_init(&epc->refcount, 1); - mtx_init(&epc->lock, "iwch_epc lock", NULL, MTX_DEF|MTX_DUPOK); - cv_init(&epc->waitq, "iwch_epc cv"); - } - CTR2(KTR_IW_CXGB, "%s alloc ep %p", __FUNCTION__, epc); - return epc; -} - -void __free_ep(struct iwch_ep_common *epc) -{ - CTR3(KTR_IW_CXGB, "%s ep %p state %s", __FUNCTION__, epc, states[state_read(epc)]); - KASSERT(!epc->entry.tqe_prev, ("%s epc %p still on req list!\n", __FUNCTION__, epc)); - free(epc, M_DEVBUF); -} - -static int -find_route(__be32 local_ip, __be32 peer_ip, __be16 local_port, - __be16 peer_port, u8 tos, struct nhop4_extended *pnh4) -{ - struct in_addr addr; - - addr.s_addr = peer_ip; - return (fib4_lookup_nh_ext(RT_DEFAULT_FIB, addr, NHR_REF, 0, pnh4)); -} - -static void -close_socket(struct iwch_ep_common *epc, int close) -{ - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, epc, epc->so, states[epc->state]); - SOCK_LOCK(epc->so); - soupcall_clear(epc->so, SO_RCV); - SOCK_UNLOCK(epc->so); - if (close) - soclose(epc->so); - else - soshutdown(epc->so, SHUT_WR|SHUT_RD); - epc->so = NULL; -} - -static void -shutdown_socket(struct iwch_ep_common *epc) -{ - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, epc, epc->so, states[epc->state]); - soshutdown(epc->so, SHUT_WR); -} - -static void -abort_socket(struct iwch_ep *ep) -{ - struct sockopt sopt; - int err; - struct linger l; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - l.l_onoff = 1; - l.l_linger = 0; - - /* linger_time of 0 forces RST to be sent */ - sopt.sopt_dir = SOPT_SET; - sopt.sopt_level = SOL_SOCKET; - sopt.sopt_name = SO_LINGER; - sopt.sopt_val = (caddr_t)&l; - sopt.sopt_valsize = sizeof l; - sopt.sopt_td = NULL; - err = sosetopt(ep->com.so, &sopt); - if (err) - printf("%s can't set linger to 0, no RST! err %d\n", __FUNCTION__, err); -} - -static void -send_mpa_req(struct iwch_ep *ep) -{ - int mpalen; - struct mpa_message *mpa; - struct mbuf *m; - int err; - - CTR3(KTR_IW_CXGB, "%s ep %p pd_len %d", __FUNCTION__, ep, ep->plen); - - mpalen = sizeof(*mpa) + ep->plen; - m = m_gethdr(mpalen, M_NOWAIT); - if (m == NULL) { - connect_reply_upcall(ep, -ENOMEM); - return; - } - mpa = mtod(m, struct mpa_message *); - m->m_len = mpalen; - m->m_pkthdr.len = mpalen; - memset(mpa, 0, sizeof(*mpa)); - memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)); - mpa->flags = (crc_enabled ? MPA_CRC : 0) | - (markers_enabled ? MPA_MARKERS : 0); - mpa->private_data_size = htons(ep->plen); - mpa->revision = mpa_rev; - if (ep->plen) - memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen); - - err = sosend(ep->com.so, NULL, NULL, m, NULL, MSG_DONTWAIT, ep->com.thread); - if (err) { - m_freem(m); - connect_reply_upcall(ep, -ENOMEM); - return; - } - - start_ep_timer(ep); - state_set(&ep->com, MPA_REQ_SENT); - return; -} - -static int -send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen) -{ - int mpalen; - struct mpa_message *mpa; - struct mbuf *m; - int err; - - CTR3(KTR_IW_CXGB, "%s ep %p plen %d", __FUNCTION__, ep, plen); - - mpalen = sizeof(*mpa) + plen; - - m = m_gethdr(mpalen, M_NOWAIT); - if (m == NULL) { - printf("%s - cannot alloc mbuf!\n", __FUNCTION__); - return (-ENOMEM); - } - mpa = mtod(m, struct mpa_message *); - m->m_len = mpalen; - m->m_pkthdr.len = mpalen; - memset(mpa, 0, sizeof(*mpa)); - memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); - mpa->flags = MPA_REJECT; - mpa->revision = mpa_rev; - mpa->private_data_size = htons(plen); - if (plen) - memcpy(mpa->private_data, pdata, plen); - err = sosend(ep->com.so, NULL, NULL, m, NULL, MSG_DONTWAIT, ep->com.thread); - PANIC_IF(err); - return 0; -} - -static int -send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen) -{ - int mpalen; - struct mpa_message *mpa; - struct mbuf *m; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p plen %d", __FUNCTION__, ep, ep->com.so, plen); - - mpalen = sizeof(*mpa) + plen; - - m = m_gethdr(mpalen, M_NOWAIT); - if (m == NULL) { - printf("%s - cannot alloc mbuf!\n", __FUNCTION__); - return (-ENOMEM); - } - mpa = mtod(m, struct mpa_message *); - m->m_len = mpalen; - m->m_pkthdr.len = mpalen; - memset(mpa, 0, sizeof(*mpa)); - memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); - mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) | - (markers_enabled ? MPA_MARKERS : 0); - mpa->revision = mpa_rev; - mpa->private_data_size = htons(plen); - if (plen) - memcpy(mpa->private_data, pdata, plen); - - state_set(&ep->com, MPA_REP_SENT); - return sosend(ep->com.so, NULL, NULL, m, NULL, MSG_DONTWAIT, - ep->com.thread); -} - -static void -close_complete_upcall(struct iwch_ep *ep) -{ - struct iw_cm_event event; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_CLOSE; - if (ep->com.cm_id) { - CTR3(KTR_IW_CXGB, "close complete delivered ep %p cm_id %p tid %d", - ep, ep->com.cm_id, ep->hwtid); - ep->com.cm_id->event_handler(ep->com.cm_id, &event); - ep->com.cm_id->rem_ref(ep->com.cm_id); - ep->com.cm_id = NULL; - ep->com.qp = NULL; - } -} - -static void -abort_connection(struct iwch_ep *ep) -{ - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - state_set(&ep->com, ABORTING); - abort_socket(ep); - close_socket(&ep->com, 0); - close_complete_upcall(ep); - state_set(&ep->com, DEAD); - put_ep(&ep->com); -} - -static void -peer_close_upcall(struct iwch_ep *ep) -{ - struct iw_cm_event event; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_DISCONNECT; - if (ep->com.cm_id) { - CTR3(KTR_IW_CXGB, "peer close delivered ep %p cm_id %p tid %d", - ep, ep->com.cm_id, ep->hwtid); - ep->com.cm_id->event_handler(ep->com.cm_id, &event); - } -} - -static void -peer_abort_upcall(struct iwch_ep *ep) -{ - struct iw_cm_event event; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_CLOSE; - event.status = ECONNRESET; - if (ep->com.cm_id) { - CTR3(KTR_IW_CXGB, "abort delivered ep %p cm_id %p tid %d", ep, - ep->com.cm_id, ep->hwtid); - ep->com.cm_id->event_handler(ep->com.cm_id, &event); - ep->com.cm_id->rem_ref(ep->com.cm_id); - ep->com.cm_id = NULL; - ep->com.qp = NULL; - } -} - -static void -connect_reply_upcall(struct iwch_ep *ep, int status) -{ - struct iw_cm_event event; - - CTR5(KTR_IW_CXGB, "%s ep %p so %p state %s status %d", __FUNCTION__, ep, ep->com.so, states[ep->com.state], status); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_CONNECT_REPLY; - event.status = status; - event.local_addr = ep->com.local_addr; - event.remote_addr = ep->com.remote_addr; - - if ((status == 0) || (status == ECONNREFUSED)) { - event.private_data_len = ep->plen; - event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); - } - if (ep->com.cm_id) { - CTR4(KTR_IW_CXGB, "%s ep %p tid %d status %d", __FUNCTION__, ep, - ep->hwtid, status); - ep->com.cm_id->event_handler(ep->com.cm_id, &event); - } - if (status < 0) { - ep->com.cm_id->rem_ref(ep->com.cm_id); - ep->com.cm_id = NULL; - ep->com.qp = NULL; - } -} - -static void -connect_request_upcall(struct iwch_ep *ep) -{ - struct iw_cm_event event; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_CONNECT_REQUEST; - event.local_addr = ep->com.local_addr; - event.remote_addr = ep->com.remote_addr; - event.private_data_len = ep->plen; - event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); - event.provider_data = ep; - event.so = ep->com.so; - if (state_read(&ep->parent_ep->com) != DEAD) { - get_ep(&ep->com); - ep->parent_ep->com.cm_id->event_handler( - ep->parent_ep->com.cm_id, - &event); - } - put_ep(&ep->parent_ep->com); -} - -static void -established_upcall(struct iwch_ep *ep) -{ - struct iw_cm_event event; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - memset(&event, 0, sizeof(event)); - event.event = IW_CM_EVENT_ESTABLISHED; - if (ep->com.cm_id) { - CTR3(KTR_IW_CXGB, "%s ep %p tid %d", __FUNCTION__, ep, ep->hwtid); - ep->com.cm_id->event_handler(ep->com.cm_id, &event); - } -} - -static void -process_mpa_reply(struct iwch_ep *ep) -{ - struct mpa_message *mpa; - u16 plen; - struct iwch_qp_attributes attrs; - enum iwch_qp_attr_mask mask; - int err; - struct mbuf *top, *m; - int flags = MSG_DONTWAIT; - struct uio uio; - int len; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - - /* - * Stop mpa timer. If it expired, then the state has - * changed and we bail since ep_timeout already aborted - * the connection. - */ - stop_ep_timer(ep); - if (state_read(&ep->com) != MPA_REQ_SENT) - return; - - uio.uio_resid = len = 1000000; - uio.uio_td = ep->com.thread; - err = soreceive(ep->com.so, NULL, &uio, &top, NULL, &flags); - if (err) { - if (err == EWOULDBLOCK) { - start_ep_timer(ep); - return; - } - err = -err; - goto err; - } - - if (ep->com.so->so_rcv.sb_mb) { - printf("%s data after soreceive called! so %p sb_mb %p top %p\n", - __FUNCTION__, ep->com.so, ep->com.so->so_rcv.sb_mb, top); - } - - m = top; - do { - /* - * If we get more than the supported amount of private data - * then we must fail this connection. - */ - if (ep->mpa_pkt_len + m->m_len > sizeof(ep->mpa_pkt)) { - err = (-EINVAL); - goto err; - } - - /* - * copy the new data into our accumulation buffer. - */ - m_copydata(m, 0, m->m_len, &(ep->mpa_pkt[ep->mpa_pkt_len])); - ep->mpa_pkt_len += m->m_len; - if (!m->m_next) - m = m->m_nextpkt; - else - m = m->m_next; - } while (m); - - m_freem(top); - - /* - * if we don't even have the mpa message, then bail. - */ - if (ep->mpa_pkt_len < sizeof(*mpa)) - return; - mpa = (struct mpa_message *)ep->mpa_pkt; - - /* Validate MPA header. */ - if (mpa->revision != mpa_rev) { - CTR2(KTR_IW_CXGB, "%s bad mpa rev %d", __FUNCTION__, mpa->revision); - err = EPROTO; - goto err; - } - if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) { - CTR2(KTR_IW_CXGB, "%s bad mpa key |%16s|", __FUNCTION__, mpa->key); - err = EPROTO; - goto err; - } - - plen = ntohs(mpa->private_data_size); - - /* - * Fail if there's too much private data. - */ - if (plen > MPA_MAX_PRIVATE_DATA) { - CTR2(KTR_IW_CXGB, "%s plen too big %d", __FUNCTION__, plen); - err = EPROTO; - goto err; - } - - /* - * If plen does not account for pkt size - */ - if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { - CTR2(KTR_IW_CXGB, "%s pkt too big %d", __FUNCTION__, ep->mpa_pkt_len); - err = EPROTO; - goto err; - } - - ep->plen = (u8) plen; - - /* - * If we don't have all the pdata yet, then bail. - * We'll continue process when more data arrives. - */ - if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) - return; - - if (mpa->flags & MPA_REJECT) { - err = ECONNREFUSED; - goto err; - } - - /* - * If we get here we have accumulated the entire mpa - * start reply message including private data. And - * the MPA header is valid. - */ - CTR1(KTR_IW_CXGB, "%s mpa rpl looks good!", __FUNCTION__); - state_set(&ep->com, FPDU_MODE); - ep->mpa_attr.initiator = 1; - ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; - ep->mpa_attr.recv_marker_enabled = markers_enabled; - ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; - ep->mpa_attr.version = mpa_rev; - if (set_tcpinfo(ep)) { - printf("%s set_tcpinfo error\n", __FUNCTION__); - goto err; - } - CTR5(KTR_IW_CXGB, "%s - crc_enabled=%d, recv_marker_enabled=%d, " - "xmit_marker_enabled=%d, version=%d", __FUNCTION__, - ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, - ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version); - - attrs.mpa_attr = ep->mpa_attr; - attrs.max_ird = ep->ird; - attrs.max_ord = ep->ord; - attrs.llp_stream_handle = ep; - attrs.next_state = IWCH_QP_STATE_RTS; - - mask = IWCH_QP_ATTR_NEXT_STATE | - IWCH_QP_ATTR_LLP_STREAM_HANDLE | IWCH_QP_ATTR_MPA_ATTR | - IWCH_QP_ATTR_MAX_IRD | IWCH_QP_ATTR_MAX_ORD; - - /* bind QP and TID with INIT_WR */ - err = iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, mask, &attrs, 1); - if (!err) - goto out; -err: - abort_connection(ep); -out: - connect_reply_upcall(ep, err); - return; -} - -static void -process_mpa_request(struct iwch_ep *ep) -{ - struct mpa_message *mpa; - u16 plen; - int flags = MSG_DONTWAIT; - struct mbuf *top, *m; - int err; - struct uio uio; - int len; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - - /* - * Stop mpa timer. If it expired, then the state has - * changed and we bail since ep_timeout already aborted - * the connection. - */ - stop_ep_timer(ep); - if (state_read(&ep->com) != MPA_REQ_WAIT) - return; - - uio.uio_resid = len = 1000000; - uio.uio_td = ep->com.thread; - err = soreceive(ep->com.so, NULL, &uio, &top, NULL, &flags); - if (err) { - if (err == EWOULDBLOCK) { - start_ep_timer(ep); - return; - } - err = -err; - goto err; - } - - m = top; - do { - - /* - * If we get more than the supported amount of private data - * then we must fail this connection. - */ - if (ep->mpa_pkt_len + m->m_len > sizeof(ep->mpa_pkt)) { - CTR2(KTR_IW_CXGB, "%s mpa message too big %d", __FUNCTION__, - ep->mpa_pkt_len + m->m_len); - goto err; - } - - - /* - * Copy the new data into our accumulation buffer. - */ - m_copydata(m, 0, m->m_len, &(ep->mpa_pkt[ep->mpa_pkt_len])); - ep->mpa_pkt_len += m->m_len; - - if (!m->m_next) - m = m->m_nextpkt; - else - m = m->m_next; - } while (m); - - m_freem(top); - - /* - * If we don't even have the mpa message, then bail. - * We'll continue process when more data arrives. - */ - if (ep->mpa_pkt_len < sizeof(*mpa)) { - start_ep_timer(ep); - CTR2(KTR_IW_CXGB, "%s not enough header %d...waiting...", __FUNCTION__, - ep->mpa_pkt_len); - return; - } - mpa = (struct mpa_message *) ep->mpa_pkt; - - /* - * Validate MPA Header. - */ - if (mpa->revision != mpa_rev) { - CTR2(KTR_IW_CXGB, "%s bad mpa rev %d", __FUNCTION__, mpa->revision); - goto err; - } - - if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) { - CTR2(KTR_IW_CXGB, "%s bad mpa key |%16s|", __FUNCTION__, mpa->key); - goto err; - } - - plen = ntohs(mpa->private_data_size); - - /* - * Fail if there's too much private data. - */ - if (plen > MPA_MAX_PRIVATE_DATA) { - CTR2(KTR_IW_CXGB, "%s plen too big %d", __FUNCTION__, plen); - goto err; - } - - /* - * If plen does not account for pkt size - */ - if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { - CTR2(KTR_IW_CXGB, "%s more data after private data %d", __FUNCTION__, - ep->mpa_pkt_len); - goto err; - } - ep->plen = (u8) plen; - - /* - * If we don't have all the pdata yet, then bail. - */ - if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) { - start_ep_timer(ep); - CTR2(KTR_IW_CXGB, "%s more mpa msg to come %d", __FUNCTION__, - ep->mpa_pkt_len); - return; - } - - /* - * If we get here we have accumulated the entire mpa - * start reply message including private data. - */ - ep->mpa_attr.initiator = 0; - ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; - ep->mpa_attr.recv_marker_enabled = markers_enabled; - ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; - ep->mpa_attr.version = mpa_rev; - if (set_tcpinfo(ep)) { - printf("%s set_tcpinfo error\n", __FUNCTION__); - goto err; - } - CTR5(KTR_IW_CXGB, "%s - crc_enabled=%d, recv_marker_enabled=%d, " - "xmit_marker_enabled=%d, version=%d", __FUNCTION__, - ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, - ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version); - - state_set(&ep->com, MPA_REQ_RCVD); - - /* drive upcall */ - connect_request_upcall(ep); - return; -err: - abort_connection(ep); - return; -} - -static void -process_peer_close(struct iwch_ep *ep) -{ - struct iwch_qp_attributes attrs; - int disconnect = 1; - int release = 0; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - - mtx_lock(&ep->com.lock); - switch (ep->com.state) { - case MPA_REQ_WAIT: - __state_set(&ep->com, CLOSING); - break; - case MPA_REQ_SENT: - __state_set(&ep->com, CLOSING); - connect_reply_upcall(ep, -ECONNRESET); - break; - case MPA_REQ_RCVD: - - /* - * We're gonna mark this puppy DEAD, but keep - * the reference on it until the ULP accepts or - * rejects the CR. - */ - __state_set(&ep->com, CLOSING); - break; - case MPA_REP_SENT: - __state_set(&ep->com, CLOSING); - break; - case FPDU_MODE: - start_ep_timer(ep); - __state_set(&ep->com, CLOSING); - attrs.next_state = IWCH_QP_STATE_CLOSING; - iwch_modify_qp(ep->com.qp->rhp, ep->com.qp, - IWCH_QP_ATTR_NEXT_STATE, &attrs, 1); - peer_close_upcall(ep); - break; - case ABORTING: - disconnect = 0; - break; - case CLOSING: - __state_set(&ep->com, MORIBUND); - disconnect = 0; - break; - case MORIBUND: - stop_ep_timer(ep); - if (ep->com.cm_id && ep->com.qp) { - attrs.next_state = IWCH_QP_STATE_IDLE; - iwch_modify_qp(ep->com.qp->rhp, ep->com.qp, - IWCH_QP_ATTR_NEXT_STATE, &attrs, 1); - } - close_socket(&ep->com, 0); - close_complete_upcall(ep); - __state_set(&ep->com, DEAD); - release = 1; - disconnect = 0; - break; - case DEAD: - disconnect = 0; - break; - default: - PANIC_IF(1); - } - mtx_unlock(&ep->com.lock); - if (disconnect) - iwch_ep_disconnect(ep, 0, M_NOWAIT); - if (release) - put_ep(&ep->com); - return; -} - -static void -process_conn_error(struct iwch_ep *ep) -{ - struct iwch_qp_attributes attrs; - int ret; - - mtx_lock(&ep->com.lock); - CTR3(KTR_IW_CXGB, "%s ep %p state %u", __func__, ep, ep->com.state); - switch (ep->com.state) { - case MPA_REQ_WAIT: - stop_ep_timer(ep); - break; - case MPA_REQ_SENT: - stop_ep_timer(ep); - connect_reply_upcall(ep, -ECONNRESET); - break; - case MPA_REP_SENT: - ep->com.rpl_err = ECONNRESET; - CTR1(KTR_IW_CXGB, "waking up ep %p", ep); - break; - case MPA_REQ_RCVD: - - /* - * We're gonna mark this puppy DEAD, but keep - * the reference on it until the ULP accepts or - * rejects the CR. - */ - break; - case MORIBUND: - case CLOSING: - stop_ep_timer(ep); - /*FALLTHROUGH*/ - case FPDU_MODE: - if (ep->com.cm_id && ep->com.qp) { - attrs.next_state = IWCH_QP_STATE_ERROR; - ret = iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, - &attrs, 1); - if (ret) - log(LOG_ERR, - "%s - qp <- error failed!\n", - __FUNCTION__); - } - peer_abort_upcall(ep); - break; - case ABORTING: - break; - case DEAD: - mtx_unlock(&ep->com.lock); - CTR2(KTR_IW_CXGB, "%s so_error %d IN DEAD STATE!!!!", __FUNCTION__, - ep->com.so->so_error); - return; - default: - PANIC_IF(1); - break; - } - - if (ep->com.state != ABORTING) { - close_socket(&ep->com, 0); - __state_set(&ep->com, DEAD); - put_ep(&ep->com); - } - mtx_unlock(&ep->com.lock); - return; -} - -static void -process_close_complete(struct iwch_ep *ep) -{ - struct iwch_qp_attributes attrs; - int release = 0; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - PANIC_IF(!ep); - - /* The cm_id may be null if we failed to connect */ - mtx_lock(&ep->com.lock); - switch (ep->com.state) { - case CLOSING: - __state_set(&ep->com, MORIBUND); - break; - case MORIBUND: - stop_ep_timer(ep); - if ((ep->com.cm_id) && (ep->com.qp)) { - attrs.next_state = IWCH_QP_STATE_IDLE; - iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, - IWCH_QP_ATTR_NEXT_STATE, - &attrs, 1); - } - if (ep->parent_ep) - close_socket(&ep->com, 1); - else - close_socket(&ep->com, 0); - close_complete_upcall(ep); - __state_set(&ep->com, DEAD); - release = 1; - break; - case ABORTING: - break; - case DEAD: - default: - PANIC_IF(1); - break; - } - mtx_unlock(&ep->com.lock); - if (release) - put_ep(&ep->com); - return; -} - -/* - * T3A does 3 things when a TERM is received: - * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet - * 2) generate an async event on the QP with the TERMINATE opcode - * 3) post a TERMINATE opcde cqe into the associated CQ. - * - * For (1), we save the message in the qp for later consumer consumption. - * For (2), we move the QP into TERMINATE, post a QP event and disconnect. - * For (3), we toss the CQE in cxio_poll_cq(). - * - * terminate() handles case (1)... - */ -static int -terminate(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - uint32_t hash = *((uint32_t *)r + 1); - unsigned int tid = ntohl(hash) >> 8 & 0xfffff; - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct socket *so = toep->tp_inp->inp_socket; - struct iwch_ep *ep = so->so_rcv.sb_upcallarg; - - if (state_read(&ep->com) != FPDU_MODE) - goto done; - - m_adj(m, sizeof(struct cpl_rdma_terminate)); - - CTR4(KTR_IW_CXGB, "%s: tid %u, ep %p, saved %d bytes", - __func__, tid, ep, m->m_len); - - m_copydata(m, 0, m->m_len, ep->com.qp->attr.terminate_buffer); - ep->com.qp->attr.terminate_msg_len = m->m_len; - ep->com.qp->attr.is_terminate_local = 0; - -done: - m_freem(m); - return (0); -} - -static int -ec_status(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_rdma_ec_status *rep = mtod(m, void *); - unsigned int tid = GET_TID(rep); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct socket *so = toep->tp_inp->inp_socket; - struct iwch_ep *ep = so->so_rcv.sb_upcallarg; - - if (rep->status) { - struct iwch_qp_attributes attrs; - - CTR1(KTR_IW_CXGB, "%s BAD CLOSE - Aborting", __FUNCTION__); - stop_ep_timer(ep); - attrs.next_state = IWCH_QP_STATE_ERROR; - iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, - IWCH_QP_ATTR_NEXT_STATE, - &attrs, 1); - abort_connection(ep); - } - - m_freem(m); - return (0); -} - -static void -ep_timeout(void *arg) -{ - struct iwch_ep *ep = (struct iwch_ep *)arg; - struct iwch_qp_attributes attrs; - int err = 0; - int abort = 1; - - mtx_lock(&ep->com.lock); - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - switch (ep->com.state) { - case MPA_REQ_SENT: - __state_set(&ep->com, ABORTING); - connect_reply_upcall(ep, -ETIMEDOUT); - break; - case MPA_REQ_WAIT: - __state_set(&ep->com, ABORTING); - break; - case CLOSING: - case MORIBUND: - if (ep->com.cm_id && ep->com.qp) - err = 1; - __state_set(&ep->com, ABORTING); - break; - default: - CTR3(KTR_IW_CXGB, "%s unexpected state ep %p state %u\n", - __func__, ep, ep->com.state); - abort = 0; - } - mtx_unlock(&ep->com.lock); - if (err){ - attrs.next_state = IWCH_QP_STATE_ERROR; - iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, - &attrs, 1); - } - if (abort) - abort_connection(ep); - put_ep(&ep->com); -} - -int -iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) -{ - int err; - struct iwch_ep *ep = to_ep(cm_id); - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - - if (state_read(&ep->com) == DEAD) { - put_ep(&ep->com); - return (-ECONNRESET); - } - PANIC_IF(state_read(&ep->com) != MPA_REQ_RCVD); - if (mpa_rev == 0) { - abort_connection(ep); - } else { - err = send_mpa_reject(ep, pdata, pdata_len); - err = soshutdown(ep->com.so, 3); - } - put_ep(&ep->com); - return 0; -} - -int -iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) -{ - int err; - struct iwch_qp_attributes attrs; - enum iwch_qp_attr_mask mask; - struct iwch_ep *ep = to_ep(cm_id); - struct iwch_dev *h = to_iwch_dev(cm_id->device); - struct iwch_qp *qp = get_qhp(h, conn_param->qpn); - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - if (state_read(&ep->com) == DEAD) { - err = -ECONNRESET; - goto err; - } - - PANIC_IF(state_read(&ep->com) != MPA_REQ_RCVD); - PANIC_IF(!qp); - - if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) || - (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) { - abort_connection(ep); - err = -EINVAL; - goto err; - } - - cm_id->add_ref(cm_id); - ep->com.cm_id = cm_id; - ep->com.qp = qp; - - ep->com.rpl_err = 0; - ep->com.rpl_done = 0; - ep->ird = conn_param->ird; - ep->ord = conn_param->ord; - CTR3(KTR_IW_CXGB, "%s ird %d ord %d", __FUNCTION__, ep->ird, ep->ord); - - /* bind QP to EP and move to RTS */ - attrs.mpa_attr = ep->mpa_attr; - attrs.max_ird = ep->ird; - attrs.max_ord = ep->ord; - attrs.llp_stream_handle = ep; - attrs.next_state = IWCH_QP_STATE_RTS; - - /* bind QP and TID with INIT_WR */ - mask = IWCH_QP_ATTR_NEXT_STATE | - IWCH_QP_ATTR_LLP_STREAM_HANDLE | - IWCH_QP_ATTR_MPA_ATTR | - IWCH_QP_ATTR_MAX_IRD | - IWCH_QP_ATTR_MAX_ORD; - - err = iwch_modify_qp(ep->com.qp->rhp, - ep->com.qp, mask, &attrs, 1); - - if (err) - goto err1; - - err = send_mpa_reply(ep, conn_param->private_data, - conn_param->private_data_len); - if (err) - goto err1; - state_set(&ep->com, FPDU_MODE); - established_upcall(ep); - put_ep(&ep->com); - return 0; -err1: - ep->com.cm_id = NULL; - ep->com.qp = NULL; - cm_id->rem_ref(cm_id); -err: - put_ep(&ep->com); - return err; -} - -static int init_sock(struct iwch_ep_common *epc) -{ - int err; - struct sockopt sopt; - int on=1; - - SOCK_LOCK(epc->so); - soupcall_set(epc->so, SO_RCV, iwch_so_upcall, epc); - epc->so->so_state |= SS_NBIO; - SOCK_UNLOCK(epc->so); - sopt.sopt_dir = SOPT_SET; - sopt.sopt_level = IPPROTO_TCP; - sopt.sopt_name = TCP_NODELAY; - sopt.sopt_val = (caddr_t)&on; - sopt.sopt_valsize = sizeof on; - sopt.sopt_td = NULL; - err = sosetopt(epc->so, &sopt); - if (err) - printf("%s can't set TCP_NODELAY err %d\n", __FUNCTION__, err); - - return 0; -} - -static int -is_loopback_dst(struct iw_cm_id *cm_id) -{ - uint16_t port = cm_id->remote_addr.sin_port; - int ifa_present; - - cm_id->remote_addr.sin_port = 0; - ifa_present = ifa_ifwithaddr_check( - (struct sockaddr *)&cm_id->remote_addr); - cm_id->remote_addr.sin_port = port; - return (ifa_present); -} - -int -iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) -{ - int err = 0; - struct iwch_dev *h = to_iwch_dev(cm_id->device); - struct iwch_ep *ep; - struct nhop4_extended nh4; - struct toedev *tdev; - - if (is_loopback_dst(cm_id)) { - err = -ENOSYS; - goto out; - } - - ep = alloc_ep(sizeof(*ep), M_NOWAIT); - if (!ep) { - printf("%s - cannot alloc ep.\n", __FUNCTION__); - err = (-ENOMEM); - goto out; - } - callout_init(&ep->timer, 1); - ep->plen = conn_param->private_data_len; - if (ep->plen) - memcpy(ep->mpa_pkt + sizeof(struct mpa_message), - conn_param->private_data, ep->plen); - ep->ird = conn_param->ird; - ep->ord = conn_param->ord; - - cm_id->add_ref(cm_id); - ep->com.cm_id = cm_id; - ep->com.qp = get_qhp(h, conn_param->qpn); - ep->com.thread = curthread; - PANIC_IF(!ep->com.qp); - CTR4(KTR_IW_CXGB, "%s qpn 0x%x qp %p cm_id %p", __FUNCTION__, conn_param->qpn, - ep->com.qp, cm_id); - - ep->com.so = cm_id->so; - err = init_sock(&ep->com); - if (err) - goto fail2; - - /* find a route */ - err = find_route(cm_id->local_addr.sin_addr.s_addr, - cm_id->remote_addr.sin_addr.s_addr, - cm_id->local_addr.sin_port, - cm_id->remote_addr.sin_port, IPTOS_LOWDELAY, &nh4); - if (err) { - printf("%s - cannot find route.\n", __FUNCTION__); - err = EHOSTUNREACH; - goto fail2; - } - - if (!(nh4.nh_ifp->if_flags & IFCAP_TOE)) { - printf("%s - interface not TOE capable.\n", __FUNCTION__); - fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); - goto fail2; - } - tdev = TOEDEV(nh4.nh_ifp); - if (tdev == NULL) { - printf("%s - No toedev for interface.\n", __FUNCTION__); - fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); - goto fail2; - } - fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4); - - state_set(&ep->com, CONNECTING); - ep->com.local_addr = cm_id->local_addr; - ep->com.remote_addr = cm_id->remote_addr; - err = soconnect(ep->com.so, (struct sockaddr *)&ep->com.remote_addr, - ep->com.thread); - if (!err) - goto out; -fail2: - put_ep(&ep->com); -out: - return err; -} - -int -iwch_create_listen_ep(struct iw_cm_id *cm_id, int backlog) -{ - int err = 0; - struct iwch_listen_ep *ep; - - ep = alloc_ep(sizeof(*ep), M_NOWAIT); - if (!ep) { - printf("%s - cannot alloc ep.\n", __FUNCTION__); - err = ENOMEM; - goto out; - } - CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep); - cm_id->add_ref(cm_id); - ep->com.cm_id = cm_id; - ep->backlog = backlog; - ep->com.local_addr = cm_id->local_addr; - ep->com.thread = curthread; - state_set(&ep->com, LISTEN); - - ep->com.so = cm_id->so; - cm_id->provider_data = ep; -out: - return err; -} - -void -iwch_destroy_listen_ep(struct iw_cm_id *cm_id) -{ - struct iwch_listen_ep *ep = to_listen_ep(cm_id); - - CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep); - - state_set(&ep->com, DEAD); - cm_id->rem_ref(cm_id); - put_ep(&ep->com); - return; -} - -int -iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, int flags) -{ - int close = 0; - - mtx_lock(&ep->com.lock); - - PANIC_IF(!ep); - PANIC_IF(!ep->com.so); - - CTR5(KTR_IW_CXGB, "%s ep %p so %p state %s, abrupt %d", __FUNCTION__, ep, - ep->com.so, states[ep->com.state], abrupt); - - switch (ep->com.state) { - case MPA_REQ_WAIT: - case MPA_REQ_SENT: - case MPA_REQ_RCVD: - case MPA_REP_SENT: - case FPDU_MODE: - close = 1; - if (abrupt) - ep->com.state = ABORTING; - else { - ep->com.state = CLOSING; - start_ep_timer(ep); - } - break; - case CLOSING: - close = 1; - if (abrupt) { - stop_ep_timer(ep); - ep->com.state = ABORTING; - } else - ep->com.state = MORIBUND; - break; - case MORIBUND: - case ABORTING: - case DEAD: - CTR3(KTR_IW_CXGB, "%s ignoring disconnect ep %p state %u\n", - __func__, ep, ep->com.state); - break; - default: - panic("unknown state: %d\n", ep->com.state); - break; - } - - mtx_unlock(&ep->com.lock); - if (close) { - if (abrupt) - abort_connection(ep); - else { - if (!ep->parent_ep) - __state_set(&ep->com, MORIBUND); - shutdown_socket(&ep->com); - } - } - return 0; -} - -static void -process_data(struct iwch_ep *ep) -{ - struct sockaddr_in *local, *remote; - - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - - switch (state_read(&ep->com)) { - case MPA_REQ_SENT: - process_mpa_reply(ep); - break; - case MPA_REQ_WAIT: - - /* - * XXX - * Set local and remote addrs here because when we - * dequeue the newly accepted socket, they aren't set - * yet in the pcb! - */ - in_getsockaddr(ep->com.so, (struct sockaddr **)&local); - in_getpeeraddr(ep->com.so, (struct sockaddr **)&remote); - CTR3(KTR_IW_CXGB, "%s local 0x%08x remote 0x%08x", __FUNCTION__, - ntohl(local->sin_addr.s_addr), - ntohl(remote->sin_addr.s_addr)); - ep->com.local_addr = *local; - ep->com.remote_addr = *remote; - free(local, M_SONAME); - free(remote, M_SONAME); - process_mpa_request(ep); - break; - default: - if (sbavail(&ep->com.so->so_rcv)) - printf("%s Unexpected streaming data." - " ep %p state %d so %p so_state %x so_rcv.sb_cc %u so_rcv.sb_mb %p\n", - __FUNCTION__, ep, state_read(&ep->com), ep->com.so, ep->com.so->so_state, - sbavail(&ep->com.so->so_rcv), ep->com.so->so_rcv.sb_mb); - break; - } - return; -} - -static void -process_connected(struct iwch_ep *ep) -{ - CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, ep, ep->com.so, states[ep->com.state]); - if ((ep->com.so->so_state & SS_ISCONNECTED) && !ep->com.so->so_error) { - send_mpa_req(ep); - } else { - connect_reply_upcall(ep, -ep->com.so->so_error); - close_socket(&ep->com, 0); - state_set(&ep->com, DEAD); - put_ep(&ep->com); - } -} - -void -process_newconn(struct iw_cm_id *parent_cm_id, struct socket *child_so) -{ - struct iwch_ep *child_ep; - struct sockaddr_in *local; - struct sockaddr_in *remote; - struct iwch_ep *parent_ep = parent_cm_id->provider_data; - - CTR3(KTR_IW_CXGB, "%s parent ep %p so %p", __FUNCTION__, parent_ep, parent_ep->com.so); - if (!child_so) { - log(LOG_ERR, "%s - invalid child socket!\n", __func__); - return; - } - child_ep = alloc_ep(sizeof(*child_ep), M_NOWAIT); - if (!child_ep) { - log(LOG_ERR, "%s - failed to allocate ep entry!\n", - __FUNCTION__); - return; - } - SOCKBUF_LOCK(&child_so->so_rcv); - soupcall_set(child_so, SO_RCV, iwch_so_upcall, child_ep); - SOCKBUF_UNLOCK(&child_so->so_rcv); - - in_getsockaddr(child_so, (struct sockaddr **)&local); - in_getpeeraddr(child_so, (struct sockaddr **)&remote); - - CTR3(KTR_IW_CXGB, "%s remote addr 0x%08x port %d", __FUNCTION__, - ntohl(remote->sin_addr.s_addr), ntohs(remote->sin_port)); - child_ep->com.tdev = parent_ep->com.tdev; - child_ep->com.local_addr.sin_family = parent_ep->com.local_addr.sin_family; - child_ep->com.local_addr.sin_port = parent_ep->com.local_addr.sin_port; - child_ep->com.local_addr.sin_addr.s_addr = parent_ep->com.local_addr.sin_addr.s_addr; - child_ep->com.local_addr.sin_len = parent_ep->com.local_addr.sin_len; - child_ep->com.remote_addr.sin_family = remote->sin_family; - child_ep->com.remote_addr.sin_port = remote->sin_port; - child_ep->com.remote_addr.sin_addr.s_addr = remote->sin_addr.s_addr; - child_ep->com.remote_addr.sin_len = remote->sin_len; - child_ep->com.so = child_so; - child_ep->com.cm_id = NULL; - child_ep->com.thread = parent_ep->com.thread; - child_ep->parent_ep = parent_ep; - - free(local, M_SONAME); - free(remote, M_SONAME); - get_ep(&parent_ep->com); - callout_init(&child_ep->timer, 1); - state_set(&child_ep->com, MPA_REQ_WAIT); - start_ep_timer(child_ep); - - /* maybe the request has already been queued up on the socket... */ - process_mpa_request(child_ep); -} - -static int -iwch_so_upcall(struct socket *so, void *arg, int waitflag) -{ - struct iwch_ep *ep = arg; - - CTR6(KTR_IW_CXGB, "%s so %p so state %x ep %p ep state(%d)=%s", __FUNCTION__, so, so->so_state, ep, ep->com.state, states[ep->com.state]); - mtx_lock(&req_lock); - if (ep && ep->com.so && !ep->com.entry.tqe_prev) { - get_ep(&ep->com); - TAILQ_INSERT_TAIL(&req_list, &ep->com, entry); - taskqueue_enqueue(iw_cxgb_taskq, &iw_cxgb_task); - } - mtx_unlock(&req_lock); - return (SU_OK); -} - -static void -process_socket_event(struct iwch_ep *ep) -{ - int state = state_read(&ep->com); - struct socket *so = ep->com.so; - - CTR6(KTR_IW_CXGB, "%s so %p so state %x ep %p ep state(%d)=%s", __FUNCTION__, so, so->so_state, ep, ep->com.state, states[ep->com.state]); - if (state == CONNECTING) { - process_connected(ep); - return; - } - - if (state == LISTEN) { - /* socket listening events are handled at IWCM */ - CTR3(KTR_IW_CXGB, "%s Invalid ep state:%u, ep:%p", __func__, - ep->com.state, ep); - BUG(); - return; - } - - /* connection error */ - if (so->so_error) { - process_conn_error(ep); - return; - } - - /* peer close */ - if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) && state < CLOSING) { - process_peer_close(ep); - return; - } - - /* close complete */ - if (so->so_state & (SS_ISDISCONNECTED)) { - process_close_complete(ep); - return; - } - - /* rx data */ - process_data(ep); - return; -} - -static void -process_req(void *ctx, int pending) -{ - struct iwch_ep_common *epc; - - CTR1(KTR_IW_CXGB, "%s enter", __FUNCTION__); - mtx_lock(&req_lock); - while (!TAILQ_EMPTY(&req_list)) { - epc = TAILQ_FIRST(&req_list); - TAILQ_REMOVE(&req_list, epc, entry); - epc->entry.tqe_prev = NULL; - mtx_unlock(&req_lock); - if (epc->so) - process_socket_event((struct iwch_ep *)epc); - put_ep(epc); - mtx_lock(&req_lock); - } - mtx_unlock(&req_lock); -} - -int -iwch_cm_init(void) -{ - TAILQ_INIT(&req_list); - mtx_init(&req_lock, "iw_cxgb req_list lock", NULL, MTX_DEF); - iw_cxgb_taskq = taskqueue_create("iw_cxgb_taskq", M_NOWAIT, - taskqueue_thread_enqueue, &iw_cxgb_taskq); - if (iw_cxgb_taskq == NULL) { - printf("failed to allocate iw_cxgb taskqueue\n"); - return (ENOMEM); - } - taskqueue_start_threads(&iw_cxgb_taskq, 1, PI_NET, "iw_cxgb taskq"); - TASK_INIT(&iw_cxgb_task, 0, process_req, NULL); - return (0); -} - -void -iwch_cm_term(void) -{ - - taskqueue_drain(iw_cxgb_taskq, &iw_cxgb_task); - taskqueue_free(iw_cxgb_taskq); -} - -void -iwch_cm_init_cpl(struct adapter *sc) -{ - - t3_register_cpl_handler(sc, CPL_RDMA_TERMINATE, terminate); - t3_register_cpl_handler(sc, CPL_RDMA_EC_STATUS, ec_status); -} - -void -iwch_cm_term_cpl(struct adapter *sc) -{ - - t3_register_cpl_handler(sc, CPL_RDMA_TERMINATE, NULL); - t3_register_cpl_handler(sc, CPL_RDMA_EC_STATUS, NULL); -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.h deleted file mode 100644 index 241106bf7dc6..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.h +++ /dev/null @@ -1,248 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ - -#ifndef _IWCH_CM_H_ -#define _IWCH_CM_H_ -#include -#include -#include -#include -#include - - -#define MPA_KEY_REQ "MPA ID Req Frame" -#define MPA_KEY_REP "MPA ID Rep Frame" - -#define MPA_MAX_PRIVATE_DATA 256 -#define MPA_REV 0 /* XXX - amso1100 uses rev 0 ! */ -#define MPA_REJECT 0x20 -#define MPA_CRC 0x40 -#define MPA_MARKERS 0x80 -#define MPA_FLAGS_MASK 0xE0 - -#define put_ep(ep) { \ - CTR4(KTR_IW_CXGB, "put_ep (via %s:%u) ep %p refcnt %d", __FUNCTION__, __LINE__, \ - ep, atomic_load_acq_int(&((ep)->refcount))); \ - if (refcount_release(&((ep)->refcount))) \ - __free_ep(ep); \ -} - -#define get_ep(ep) { \ - CTR4(KTR_IW_CXGB, "get_ep (via %s:%u) ep %p, refcnt %d", __FUNCTION__, __LINE__, \ - ep, atomic_load_acq_int(&((ep)->refcount))); \ - refcount_acquire(&((ep)->refcount)); \ -} - -struct mpa_message { - u8 key[16]; - u8 flags; - u8 revision; - __be16 private_data_size; - u8 private_data[0]; -}; - -struct terminate_message { - u8 layer_etype; - u8 ecode; - __be16 hdrct_rsvd; - u8 len_hdrs[0]; -}; - -#define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28) - -enum iwch_layers_types { - LAYER_RDMAP = 0x00, - LAYER_DDP = 0x10, - LAYER_MPA = 0x20, - RDMAP_LOCAL_CATA = 0x00, - RDMAP_REMOTE_PROT = 0x01, - RDMAP_REMOTE_OP = 0x02, - DDP_LOCAL_CATA = 0x00, - DDP_TAGGED_ERR = 0x01, - DDP_UNTAGGED_ERR = 0x02, - DDP_LLP = 0x03 -}; - -enum iwch_rdma_ecodes { - RDMAP_INV_STAG = 0x00, - RDMAP_BASE_BOUNDS = 0x01, - RDMAP_ACC_VIOL = 0x02, - RDMAP_STAG_NOT_ASSOC = 0x03, - RDMAP_TO_WRAP = 0x04, - RDMAP_INV_VERS = 0x05, - RDMAP_INV_OPCODE = 0x06, - RDMAP_STREAM_CATA = 0x07, - RDMAP_GLOBAL_CATA = 0x08, - RDMAP_CANT_INV_STAG = 0x09, - RDMAP_UNSPECIFIED = 0xff -}; - -enum iwch_ddp_ecodes { - DDPT_INV_STAG = 0x00, - DDPT_BASE_BOUNDS = 0x01, - DDPT_STAG_NOT_ASSOC = 0x02, - DDPT_TO_WRAP = 0x03, - DDPT_INV_VERS = 0x04, - DDPU_INV_QN = 0x01, - DDPU_INV_MSN_NOBUF = 0x02, - DDPU_INV_MSN_RANGE = 0x03, - DDPU_INV_MO = 0x04, - DDPU_MSG_TOOBIG = 0x05, - DDPU_INV_VERS = 0x06 -}; - -enum iwch_mpa_ecodes { - MPA_CRC_ERR = 0x02, - MPA_MARKER_ERR = 0x03 -}; - -enum iwch_ep_state { - IDLE = 0, - LISTEN, - CONNECTING, - MPA_REQ_WAIT, - MPA_REQ_SENT, - MPA_REQ_RCVD, - MPA_REP_SENT, - FPDU_MODE, - ABORTING, - CLOSING, - MORIBUND, - DEAD, -}; - -enum iwch_ep_flags { - PEER_ABORT_IN_PROGRESS = (1 << 0), - ABORT_REQ_IN_PROGRESS = (1 << 1), -}; - -struct iwch_ep_common { - TAILQ_ENTRY(iwch_ep_common) entry; - struct iw_cm_id *cm_id; - struct iwch_qp *qp; - struct toedev *tdev; - enum iwch_ep_state state; - u_int refcount; - struct cv waitq; - struct mtx lock; - struct sockaddr_in local_addr; - struct sockaddr_in remote_addr; - int rpl_err; - int rpl_done; - struct thread *thread; - struct socket *so; -}; - -struct iwch_listen_ep { - struct iwch_ep_common com; - unsigned int stid; - int backlog; -}; - -struct iwch_ep { - struct iwch_ep_common com; - struct iwch_ep *parent_ep; - struct callout timer; - unsigned int atid; - u32 hwtid; - u32 snd_seq; - u32 rcv_seq; - struct l2t_entry *l2t; - struct mbuf *mpa_mbuf; - struct iwch_mpa_attributes mpa_attr; - unsigned int mpa_pkt_len; - u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA]; - u8 tos; - u16 emss; - u16 plen; - u32 ird; - u32 ord; - u32 flags; -}; - -static inline struct iwch_ep *to_ep(struct iw_cm_id *cm_id) -{ - return cm_id->provider_data; -} - -static inline struct iwch_listen_ep *to_listen_ep(struct iw_cm_id *cm_id) -{ - return cm_id->provider_data; -} - -static inline int compute_wscale(int win) -{ - int wscale = 0; - - while (wscale < 14 && (65535< -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Get one cq entry from cxio and map it to openib. - * - * Returns: - * 0 cqe returned - * -ENOBUFS EMPTY; - * -EAGAIN caller must try again - * any other neg errno fatal error - */ -static int iwch_poll_cq_one(struct iwch_dev *rhp, struct iwch_cq *chp, - struct ib_wc *wc) -{ - struct iwch_qp *qhp = NULL; - struct t3_cqe cqe, *rd_cqe; - struct t3_wq *wq; - u32 credit = 0; - u8 cqe_flushed; - u64 cookie; - int ret = 1; - - rd_cqe = cxio_next_cqe(&chp->cq); - - if (!rd_cqe) - return 0; - - qhp = get_qhp(rhp, CQE_QPID(*rd_cqe)); - if (!qhp) - wq = NULL; - else { - mtx_lock(&qhp->lock); - wq = &(qhp->wq); - } - ret = cxio_poll_cq(wq, &(chp->cq), &cqe, &cqe_flushed, &cookie, - &credit); - if (t3a_device(chp->rhp) && credit) { - CTR3(KTR_IW_CXGB, "%s updating %d cq credits on id %d", __FUNCTION__, - credit, chp->cq.cqid); - cxio_hal_cq_op(&rhp->rdev, &chp->cq, CQ_CREDIT_UPDATE, credit); - } - - if (ret) { - ret = -EAGAIN; - goto out; - } - ret = 1; - - wc->wr_id = cookie; - wc->qp = &qhp->ibqp; - wc->vendor_err = CQE_STATUS(cqe); - - CTR4(KTR_IW_CXGB, "iwch_poll_cq_one qpid 0x%x type %d opcode %d status 0x%x", - CQE_QPID(cqe), CQE_TYPE(cqe), - CQE_OPCODE(cqe), CQE_STATUS(cqe)); - CTR3(KTR_IW_CXGB, "wrid hi 0x%x lo 0x%x cookie 0x%llx", - CQE_WRID_HI(cqe), CQE_WRID_LOW(cqe), (unsigned long long) cookie); - - if (CQE_TYPE(cqe) == 0) { - if (!CQE_STATUS(cqe)) - wc->byte_len = CQE_LEN(cqe); - else - wc->byte_len = 0; - wc->opcode = IB_WC_RECV; - } else { - switch (CQE_OPCODE(cqe)) { - case T3_RDMA_WRITE: - wc->opcode = IB_WC_RDMA_WRITE; - break; - case T3_READ_REQ: - wc->opcode = IB_WC_RDMA_READ; - wc->byte_len = CQE_LEN(cqe); - break; - case T3_SEND: - case T3_SEND_WITH_SE: - wc->opcode = IB_WC_SEND; - break; - case T3_BIND_MW: - wc->opcode = IB_WC_BIND_MW; - break; - - /* these aren't supported yet */ - case T3_SEND_WITH_INV: - case T3_SEND_WITH_SE_INV: - case T3_LOCAL_INV: - case T3_FAST_REGISTER: - default: - log(LOG_ERR, "Unexpected opcode %d " - "in the CQE received for QPID=0x%0x\n", - CQE_OPCODE(cqe), CQE_QPID(cqe)); - ret = -EINVAL; - goto out; - } - } - - if (cqe_flushed) - wc->status = IB_WC_WR_FLUSH_ERR; - else { - - switch (CQE_STATUS(cqe)) { - case TPT_ERR_SUCCESS: - wc->status = IB_WC_SUCCESS; - break; - case TPT_ERR_STAG: - wc->status = IB_WC_LOC_ACCESS_ERR; - break; - case TPT_ERR_PDID: - wc->status = IB_WC_LOC_PROT_ERR; - break; - case TPT_ERR_QPID: - case TPT_ERR_ACCESS: - wc->status = IB_WC_LOC_ACCESS_ERR; - break; - case TPT_ERR_WRAP: - wc->status = IB_WC_GENERAL_ERR; - break; - case TPT_ERR_BOUND: - wc->status = IB_WC_LOC_LEN_ERR; - break; - case TPT_ERR_INVALIDATE_SHARED_MR: - case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND: - wc->status = IB_WC_MW_BIND_ERR; - break; - case TPT_ERR_CRC: - case TPT_ERR_MARKER: - case TPT_ERR_PDU_LEN_ERR: - case TPT_ERR_OUT_OF_RQE: - case TPT_ERR_DDP_VERSION: - case TPT_ERR_RDMA_VERSION: - case TPT_ERR_DDP_QUEUE_NUM: - case TPT_ERR_MSN: - case TPT_ERR_TBIT: - case TPT_ERR_MO: - case TPT_ERR_MSN_RANGE: - case TPT_ERR_IRD_OVERFLOW: - case TPT_ERR_OPCODE: - wc->status = IB_WC_FATAL_ERR; - break; - case TPT_ERR_SWFLUSH: - wc->status = IB_WC_WR_FLUSH_ERR; - break; - default: - log(LOG_ERR, "Unexpected cqe_status 0x%x for " - "QPID=0x%0x\n", CQE_STATUS(cqe), CQE_QPID(cqe)); - ret = -EINVAL; - } - } -out: - if (wq) - mtx_unlock(&qhp->lock); - return ret; -} - -int iwch_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc) -{ - struct iwch_dev *rhp; - struct iwch_cq *chp; - int npolled; - int err = 0; - - chp = to_iwch_cq(ibcq); - rhp = chp->rhp; - - mtx_lock(&chp->lock); - for (npolled = 0; npolled < num_entries; ++npolled) { -#ifdef DEBUG - int i=0; -#endif - - /* - * Because T3 can post CQEs that are _not_ associated - * with a WR, we might have to poll again after removing - * one of these. - */ - do { - err = iwch_poll_cq_one(rhp, chp, wc + npolled); -#ifdef DEBUG - PANIC_IF(++i > 1000); -#endif - } while (err == -EAGAIN); - if (err <= 0) - break; - } - mtx_unlock(&chp->lock); - - if (err < 0) { - return err; - } else { - return npolled; - } -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c deleted file mode 100644 index b7002b3f8763..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_dbg.c +++ /dev/null @@ -1,277 +0,0 @@ - -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#if defined(INVARIANTS) && defined(TCP_OFFLOAD) -#include -#include -#include -#include -#include -#include -#include -#include - -static int -cxio_rdma_get_mem(struct cxio_rdev *rdev, struct ch_mem_range *m) -{ - struct adapter *sc = rdev->adap; - struct mc7 *mem; - - if ((m->addr & 7) || (m->len & 7)) - return (EINVAL); - if (m->mem_id == MEM_CM) - mem = &sc->cm; - else if (m->mem_id == MEM_PMRX) - mem = &sc->pmrx; - else if (m->mem_id == MEM_PMTX) - mem = &sc->pmtx; - else - return (EINVAL); - - return (t3_mc7_bd_read(mem, m->addr/8, m->len/8, (u64 *)m->buf)); -} - -void cxio_dump_tpt(struct cxio_rdev *rdev, uint32_t stag) -{ - struct ch_mem_range m; - u64 *data; - u32 addr; - int rc; - int size = 32; - - m.buf = malloc(size, M_DEVBUF, M_NOWAIT); - if (m.buf == NULL) { - CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__); - return; - } - m.mem_id = MEM_PMRX; - m.addr = (stag >> 8) * 32 + rdev->rnic_info.tpt_base; - m.len = size; - CTR3(KTR_IW_CXGB, "%s TPT addr 0x%x len %d", __FUNCTION__, m.addr, m.len); - - rc = cxio_rdma_get_mem(rdev, &m); - if (rc) { - CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc); - free(m.buf, M_DEVBUF); - return; - } - - data = (u64 *)m.buf; - addr = m.addr; - while (size > 0) { - CTR2(KTR_IW_CXGB, "TPT %08x: %016llx", addr, (unsigned long long) *data); - size -= 8; - data++; - addr += 8; - } - free(m.buf, M_DEVBUF); -} - -void cxio_dump_pbl(struct cxio_rdev *rdev, uint32_t pbl_addr, uint32_t len, u8 shift) -{ - struct ch_mem_range m; - u64 *data; - u32 addr; - int rc; - int size, npages; - - shift += 12; - npages = (len + (1ULL << shift) - 1) >> shift; - size = npages * sizeof(u64); - m.buf = malloc(size, M_DEVBUF, M_NOWAIT); - if (m.buf == NULL) { - CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__); - return; - } - m.mem_id = MEM_PMRX; - m.addr = pbl_addr; - m.len = size; - CTR4(KTR_IW_CXGB, "%s PBL addr 0x%x len %d depth %d", - __FUNCTION__, m.addr, m.len, npages); - - rc = cxio_rdma_get_mem(rdev, &m); - if (rc) { - CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc); - free(m.buf, M_DEVBUF); - return; - } - - data = (u64 *)m.buf; - addr = m.addr; - while (size > 0) { - CTR2(KTR_IW_CXGB, "PBL %08x: %016llx", addr, (unsigned long long) *data); - size -= 8; - data++; - addr += 8; - } - free(m.buf, M_DEVBUF); -} - -void cxio_dump_wqe(union t3_wr *wqe) -{ - uint64_t *data = (uint64_t *)wqe; - uint32_t size = (uint32_t)(be64toh(*data) & 0xff); - - if (size == 0) - size = 8; - while (size > 0) { - CTR2(KTR_IW_CXGB, "WQE %p: %016llx", data, - (unsigned long long) be64toh(*data)); - size--; - data++; - } -} - -void cxio_dump_wce(struct t3_cqe *wce) -{ - uint64_t *data = (uint64_t *)wce; - int size = sizeof(*wce); - - while (size > 0) { - CTR2(KTR_IW_CXGB, "WCE %p: %016llx", data, - (unsigned long long) be64toh(*data)); - size -= 8; - data++; - } -} - -void cxio_dump_rqt(struct cxio_rdev *rdev, uint32_t hwtid, int nents) -{ - struct ch_mem_range m; - int size = nents * 64; - u64 *data; - u32 addr; - int rc; - - m.buf = malloc(size, M_DEVBUF, M_NOWAIT); - if (m.buf == NULL) { - CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__); - return; - } - m.mem_id = MEM_PMRX; - m.addr = ((hwtid)<<10) + rdev->rnic_info.rqt_base; - m.len = size; - CTR3(KTR_IW_CXGB, "%s RQT addr 0x%x len %d", __FUNCTION__, m.addr, m.len); - - rc = cxio_rdma_get_mem(rdev, &m); - if (rc) { - CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc); - free(m.buf, M_DEVBUF); - return; - } - - data = (u64 *)m.buf; - addr = m.addr; - while (size > 0) { - CTR2(KTR_IW_CXGB, "RQT %08x: %016llx", addr, (unsigned long long) *data); - size -= 8; - data++; - addr += 8; - } - free(m.buf, M_DEVBUF); -} - -void cxio_dump_tcb(struct cxio_rdev *rdev, uint32_t hwtid) -{ - struct ch_mem_range m; - int size = TCB_SIZE; - uint32_t *data; - uint32_t addr; - int rc; - - m.buf = malloc(size, M_DEVBUF, M_NOWAIT); - if (m.buf == NULL) { - CTR1(KTR_IW_CXGB, "%s couldn't allocate memory.", __FUNCTION__); - return; - } - m.mem_id = MEM_CM; - m.addr = hwtid * size; - m.len = size; - CTR3(KTR_IW_CXGB, "%s TCB %d len %d", __FUNCTION__, m.addr, m.len); - - rc = cxio_rdma_get_mem(rdev, &m); - if (rc) { - CTR2(KTR_IW_CXGB, "%s toectl returned error %d", __FUNCTION__, rc); - free(m.buf, M_DEVBUF); - return; - } - - data = (uint32_t *)m.buf; - addr = m.addr; - while (size > 0) { - printf("%2u: %08x %08x %08x %08x %08x %08x %08x %08x\n", - addr, - *(data+2), *(data+3), *(data),*(data+1), - *(data+6), *(data+7), *(data+4), *(data+5)); - size -= 32; - data += 8; - addr += 32; - } - free(m.buf, M_DEVBUF); -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ev.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ev.c deleted file mode 100644 index 0b1c3bd326a3..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ev.c +++ /dev/null @@ -1,261 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static void -post_qp_event(struct iwch_dev *rnicp, struct iwch_qp *qhp, struct iwch_cq *chp, - struct respQ_msg_t *rsp_msg, - enum ib_event_type ib_event, - int send_term) -{ - struct ib_event event; - struct iwch_qp_attributes attrs; - - mtx_lock(&rnicp->lock); - - if (!qhp) { - CTR3(KTR_IW_CXGB, "%s unaffiliated error 0x%x qpid 0x%x\n", - __func__, CQE_STATUS(rsp_msg->cqe), - CQE_QPID(rsp_msg->cqe)); - mtx_unlock(&rnicp->lock); - return; - } - - if ((qhp->attr.state == IWCH_QP_STATE_ERROR) || - (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) { - CTR4(KTR_IW_CXGB, "%s AE received after RTS - " - "qp state %d qpid 0x%x status 0x%x", __FUNCTION__, - qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe)); - mtx_unlock(&rnicp->lock); - return; - } - - log(LOG_ERR, "%s - AE qpid 0x%x opcode %d status 0x%x " - "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __FUNCTION__, - CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe), - CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe), - CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe)); - - mtx_unlock(&rnicp->lock); - - if (qhp->attr.state == IWCH_QP_STATE_RTS) { - attrs.next_state = IWCH_QP_STATE_TERMINATE; - iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, - &attrs, 1); - if (send_term) - iwch_post_terminate(qhp, rsp_msg); - } - - event.event = ib_event; - event.device = chp->ibcq.device; - if (ib_event == IB_EVENT_CQ_ERR) - event.element.cq = &chp->ibcq; - else - event.element.qp = &qhp->ibqp; - - if (qhp->ibqp.event_handler) - (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context); - - (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context); -} - -void -iwch_ev_dispatch(struct iwch_dev *rnicp, struct mbuf *m) -{ - struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) m->m_data; - struct iwch_cq *chp; - struct iwch_qp *qhp; - u32 cqid = RSPQ_CQID(rsp_msg); - - mtx_lock(&rnicp->lock); - chp = get_chp(rnicp, cqid); - qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe)); - if (!chp || !qhp) { - log(LOG_ERR,"BAD AE cqid 0x%x qpid 0x%x opcode %d " - "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x \n", - cqid, CQE_QPID(rsp_msg->cqe), - CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe), - CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe), - CQE_WRID_LOW(rsp_msg->cqe)); - mtx_unlock(&rnicp->lock); - return; - } - iwch_qp_add_ref(&qhp->ibqp); - mtx_lock(&chp->lock); - ++chp->refcnt; - mtx_unlock(&chp->lock); - mtx_unlock(&rnicp->lock); - - /* - * 1) completion of our sending a TERMINATE. - * 2) incoming TERMINATE message. - */ - if ((CQE_OPCODE(rsp_msg->cqe) == T3_TERMINATE) && - (CQE_STATUS(rsp_msg->cqe) == 0)) { - if (SQ_TYPE(rsp_msg->cqe)) { - CTR3(KTR_IW_CXGB, "%s QPID 0x%x ep %p disconnecting", - __FUNCTION__, qhp->wq.qpid, qhp->ep); - iwch_ep_disconnect(qhp->ep, 0, M_NOWAIT); - } else { - CTR2(KTR_IW_CXGB, "%s post REQ_ERR AE QPID 0x%x", __FUNCTION__, - qhp->wq.qpid); - post_qp_event(rnicp, qhp, chp, rsp_msg, - IB_EVENT_QP_REQ_ERR, 0); - iwch_ep_disconnect(qhp->ep, 0, M_NOWAIT); - } - goto done; - } - - /* Bad incoming Read request */ - if (SQ_TYPE(rsp_msg->cqe) && - (CQE_OPCODE(rsp_msg->cqe) == T3_READ_RESP)) { - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1); - goto done; - } - - /* Bad incoming write */ - if (RQ_TYPE(rsp_msg->cqe) && - (CQE_OPCODE(rsp_msg->cqe) == T3_RDMA_WRITE)) { - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1); - goto done; - } - - switch (CQE_STATUS(rsp_msg->cqe)) { - - /* Completion Events */ - case TPT_ERR_SUCCESS: -#if 0 - /* - * Confirm the destination entry if this is a RECV completion. - */ - if (qhp->ep && SQ_TYPE(rsp_msg->cqe)) - dst_confirm(qhp->ep->dst); -#endif - (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context); - break; - - case TPT_ERR_STAG: - case TPT_ERR_PDID: - case TPT_ERR_QPID: - case TPT_ERR_ACCESS: - case TPT_ERR_WRAP: - case TPT_ERR_BOUND: - case TPT_ERR_INVALIDATE_SHARED_MR: - case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND: - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1); - break; - - /* Device Fatal Errors */ - case TPT_ERR_ECC: - case TPT_ERR_ECC_PSTAG: - case TPT_ERR_INTERNAL_ERR: - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_DEVICE_FATAL, 1); - break; - - /* QP Fatal Errors */ - case TPT_ERR_OUT_OF_RQE: - case TPT_ERR_PBL_ADDR_BOUND: - case TPT_ERR_CRC: - case TPT_ERR_MARKER: - case TPT_ERR_PDU_LEN_ERR: - case TPT_ERR_DDP_VERSION: - case TPT_ERR_RDMA_VERSION: - case TPT_ERR_OPCODE: - case TPT_ERR_DDP_QUEUE_NUM: - case TPT_ERR_MSN: - case TPT_ERR_TBIT: - case TPT_ERR_MO: - case TPT_ERR_MSN_GAP: - case TPT_ERR_MSN_RANGE: - case TPT_ERR_RQE_ADDR_BOUND: - case TPT_ERR_IRD_OVERFLOW: - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1); - break; - - default: - log(LOG_ERR,"Unknown T3 status 0x%x QPID 0x%x\n", - CQE_STATUS(rsp_msg->cqe), qhp->wq.qpid); - post_qp_event(rnicp, qhp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1); - break; - } -done: - mtx_lock(&chp->lock); - if (--chp->refcnt == 0) - wakeup(chp); - mtx_unlock(&chp->lock); - iwch_qp_rem_ref(&qhp->ibqp); -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.c deleted file mode 100644 index 5e741fa02918..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.c +++ /dev/null @@ -1,1338 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Response queue used for RDMA events. */ -#define ASYNC_NOTIF_RSPQ 0 -static inline int -cxio_rdma_cq_setup(struct cxio_rdev *rdev_p, unsigned id, uint64_t base_addr, - unsigned size, unsigned ovfl_mode, unsigned credits, unsigned credit_thres) -{ - struct adapter *sc = rdev_p->adap; - int rc; - - mtx_lock_spin(&sc->sge.reg_lock); - rc = -t3_sge_init_cqcntxt(sc, id, base_addr, size, ASYNC_NOTIF_RSPQ, - ovfl_mode, credits, credit_thres); - mtx_unlock_spin(&sc->sge.reg_lock); - - return (rc); -} - -int -cxio_hal_cq_op(struct cxio_rdev *rdev_p, struct t3_cq *cq, - enum t3_cq_opcode op, u32 credit) -{ - int ret; - struct t3_cqe *cqe; - u32 rptr; - struct adapter *sc = rdev_p->adap; - - if (op != CQ_CREDIT_UPDATE) - credit = 0; - - mtx_lock_spin(&sc->sge.reg_lock); - ret = t3_sge_cqcntxt_op(sc, cq->cqid, op, credit); - mtx_unlock_spin(&sc->sge.reg_lock); - - if ((ret < 0) || (op == CQ_CREDIT_UPDATE)) - return (ret); - - /* - * If the rearm returned an index other than our current index, - * then there might be CQE's in flight (being DMA'd). We must wait - * here for them to complete or the consumer can miss a notification. - */ - if (Q_PTR2IDX((cq->rptr), cq->size_log2) != ret) { - int i=0; - - rptr = cq->rptr; - - /* - * Keep the generation correct by bumping rptr until it - * matches the index returned by the rearm - 1. - */ - while (Q_PTR2IDX((rptr+1), cq->size_log2) != ret) - rptr++; - - /* - * Now rptr is the index for the (last) cqe that was - * in-flight at the time the HW rearmed the CQ. We - * spin until that CQE is valid. - */ - cqe = cq->queue + Q_PTR2IDX(rptr, cq->size_log2); - while (!CQ_VLD_ENTRY(rptr, cq->size_log2, cqe)) { - DELAY(1); - if (i++ > 1000000) { - struct adapter *sc = rdev_p->adap; - - log(LOG_ERR, "%s: stalled rnic\n", - device_get_nameunit(sc->dev)); - PANIC_IF(1); - return (-EIO); - } - } - - return (1); - } - - return (0); -} - -static int -cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid) -{ - - return (cxio_rdma_cq_setup(rdev_p, cqid, 0, 0, 0, 0, 0)); -} - -static int -cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev_p, u32 qpid) -{ - u64 sge_cmd; - struct t3_modify_qp_wr *wqe; - struct mbuf *m; - - m = M_GETHDR_OFLD(0, CPL_PRIORITY_CONTROL, wqe); - if (m == NULL) { - CTR1(KTR_IW_CXGB, "%s m_gethdr failed", __FUNCTION__); - return (-ENOMEM); - } - wqe = mtod(m, struct t3_modify_qp_wr *); - memset(wqe, 0, sizeof(*wqe)); - build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD, 3, 0, qpid, 7); - wqe->flags = htobe32(MODQP_WRITE_EC); - sge_cmd = qpid << 8 | 3; - wqe->sge_cmd = htobe64(sge_cmd); - return t3_offload_tx(rdev_p->adap, m); -} - -int -cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq, int kernel) -{ - int size = (1UL << (cq->size_log2)) * sizeof(struct t3_cqe); - - size += 1; /* one extra page for storing cq-in-err state */ - cq->cqid = cxio_hal_get_cqid(rdev_p->rscp); - if (!cq->cqid) - return (-ENOMEM); - if (kernel) { - cq->sw_queue = malloc(size, M_DEVBUF, M_NOWAIT|M_ZERO); - if (!cq->sw_queue) - return (-ENOMEM); - } - - cq->queue = contigmalloc(size, - M_DEVBUF, M_NOWAIT, 0ul, ~0ul, 4096, 0); - if (cq->queue) - cq->dma_addr = vtophys(cq->queue); - else { - free(cq->sw_queue, M_DEVBUF); - return (-ENOMEM); - } - memset(cq->queue, 0, size); - - return (cxio_rdma_cq_setup(rdev_p, cq->cqid, cq->dma_addr, - 1UL << cq->size_log2, 0, 65535, 1)); -} - -static u32 -get_qpid(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) -{ - struct cxio_qpid *entry; - u32 qpid; - int i; - - mtx_lock(&uctx->lock); - if (!TAILQ_EMPTY(&uctx->qpids)) { - - entry = TAILQ_FIRST(&uctx->qpids); - TAILQ_REMOVE(&uctx->qpids, entry, entry); - qpid = entry->qpid; - free(entry, M_DEVBUF); - } else { - qpid = cxio_hal_get_qpid(rdev_p->rscp); - if (!qpid) - goto out; - for (i = qpid+1; i & rdev_p->qpmask; i++) { - entry = malloc(sizeof *entry, M_DEVBUF, M_NOWAIT); - if (!entry) - break; - entry->qpid = i; - TAILQ_INSERT_TAIL(&uctx->qpids, entry, entry); - } - } -out: - mtx_unlock(&uctx->lock); - CTR2(KTR_IW_CXGB, "%s qpid 0x%x", __FUNCTION__, qpid); - return qpid; -} - -static void -put_qpid(struct cxio_rdev *rdev_p, u32 qpid, - struct cxio_ucontext *uctx) -{ - struct cxio_qpid *entry; - - entry = malloc(sizeof *entry, M_DEVBUF, M_NOWAIT); - CTR2(KTR_IW_CXGB, "%s qpid 0x%x", __FUNCTION__, qpid); - entry->qpid = qpid; - mtx_lock(&uctx->lock); - TAILQ_INSERT_TAIL(&uctx->qpids, entry, entry); - mtx_unlock(&uctx->lock); -} - -void -cxio_release_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) -{ - struct cxio_qpid *pos, *tmp; - - mtx_lock(&uctx->lock); - TAILQ_FOREACH_SAFE(pos, &uctx->qpids, entry, tmp) { - TAILQ_REMOVE(&uctx->qpids, pos, entry); - if (!(pos->qpid & rdev_p->qpmask)) - cxio_hal_put_qpid(rdev_p->rscp, pos->qpid); - free(pos, M_DEVBUF); - } - mtx_unlock(&uctx->lock); -} - -void -cxio_init_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx) -{ - TAILQ_INIT(&uctx->qpids); - mtx_init(&uctx->lock, "cxio uctx", NULL, MTX_DEF|MTX_DUPOK); -} - -int -cxio_create_qp(struct cxio_rdev *rdev_p, u32 kernel_domain, - struct t3_wq *wq, struct cxio_ucontext *uctx) -{ - int depth = 1UL << wq->size_log2; - int rqsize = 1UL << wq->rq_size_log2; - - wq->qpid = get_qpid(rdev_p, uctx); - if (!wq->qpid) - return (-ENOMEM); - - wq->rq = malloc(depth * sizeof(struct t3_swrq), M_DEVBUF, M_NOWAIT|M_ZERO); - if (!wq->rq) - goto err1; - - wq->rq_addr = cxio_hal_rqtpool_alloc(rdev_p, rqsize); - if (!wq->rq_addr) - goto err2; - - wq->sq = malloc(depth * sizeof(struct t3_swsq), M_DEVBUF, M_NOWAIT|M_ZERO); - if (!wq->sq) - goto err3; - wq->queue = contigmalloc(depth *sizeof(union t3_wr), - M_DEVBUF, M_NOWAIT, 0ul, ~0ul, 4096, 0); - if (wq->queue) - wq->dma_addr = vtophys(wq->queue); - else - goto err4; - - memset(wq->queue, 0, depth * sizeof(union t3_wr)); - wq->doorbell = rdev_p->rnic_info.kdb_addr; - if (!kernel_domain) - wq->udb = (u64)rdev_p->rnic_info.udbell_physbase + - (wq->qpid << rdev_p->qpshift); - wq->rdev = rdev_p; - CTR4(KTR_IW_CXGB, "%s qpid 0x%x doorbell 0x%p udb 0x%llx", __FUNCTION__, - wq->qpid, wq->doorbell, (unsigned long long) wq->udb); - return 0; -err4: - free(wq->sq, M_DEVBUF); -err3: - cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, rqsize); -err2: - free(wq->rq, M_DEVBUF); -err1: - put_qpid(rdev_p, wq->qpid, uctx); - return (-ENOMEM); -} - -int -cxio_destroy_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq) -{ - int err; - err = cxio_hal_clear_cq_ctx(rdev_p, cq->cqid); - free(cq->sw_queue, M_DEVBUF); -#if 0 - dma_free_coherent(&(rdev_p->rnic_info.pdev), - (1UL << (cq->size_log2)) - * sizeof(struct t3_cqe), cq->queue, - /* pci_unmap_addr(cq, mapping)*/ 0); -#else - contigfree(cq->queue,(1UL << (cq->size_log2)) - * sizeof(struct t3_cqe), M_DEVBUF); -#endif - cxio_hal_put_cqid(rdev_p->rscp, cq->cqid); - return err; -} - -int -cxio_destroy_qp(struct cxio_rdev *rdev_p, struct t3_wq *wq, - struct cxio_ucontext *uctx) -{ - -#if 0 - dma_free_coherent(&(rdev_p->rnic_info.pdev), - (1UL << (wq->size_log2)) - * sizeof(union t3_wr), wq->queue, - /* pci_unmap_addr(wq, mapping)*/ 0); -#else - contigfree(wq->queue, (1UL << (wq->size_log2)) - * sizeof(union t3_wr), M_DEVBUF); -#endif - free(wq->sq, M_DEVBUF); - cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, (1UL << wq->rq_size_log2)); - free(wq->rq, M_DEVBUF); - put_qpid(rdev_p, wq->qpid, uctx); - return 0; -} - -static void -insert_recv_cqe(struct t3_wq *wq, struct t3_cq *cq) -{ - struct t3_cqe cqe; - - CTR5(KTR_IW_CXGB, "%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x", __FUNCTION__, - wq, cq, cq->sw_rptr, cq->sw_wptr); - memset(&cqe, 0, sizeof(cqe)); - cqe.header = htobe32(V_CQE_STATUS(TPT_ERR_SWFLUSH) | - V_CQE_OPCODE(T3_SEND) | - V_CQE_TYPE(0) | - V_CQE_SWCQE(1) | - V_CQE_QPID(wq->qpid) | - V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr, - cq->size_log2))); - *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe; - cq->sw_wptr++; -} - -int -cxio_flush_rq(struct t3_wq *wq, struct t3_cq *cq, int count) -{ - u32 ptr; - int flushed = 0; - - CTR3(KTR_IW_CXGB, "%s wq %p cq %p", __FUNCTION__, wq, cq); - - /* flush RQ */ - CTR4(KTR_IW_CXGB, "%s rq_rptr %u rq_wptr %u skip count %u", __FUNCTION__, - wq->rq_rptr, wq->rq_wptr, count); - ptr = wq->rq_rptr + count; - while (ptr++ != wq->rq_wptr) { - insert_recv_cqe(wq, cq); - flushed++; - } - return flushed; -} - -static void -insert_sq_cqe(struct t3_wq *wq, struct t3_cq *cq, - struct t3_swsq *sqp) -{ - struct t3_cqe cqe; - - CTR5(KTR_IW_CXGB, "%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x", __FUNCTION__, - wq, cq, cq->sw_rptr, cq->sw_wptr); - memset(&cqe, 0, sizeof(cqe)); - cqe.header = htobe32(V_CQE_STATUS(TPT_ERR_SWFLUSH) | - V_CQE_OPCODE(sqp->opcode) | - V_CQE_TYPE(1) | - V_CQE_SWCQE(1) | - V_CQE_QPID(wq->qpid) | - V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr, - cq->size_log2))); - cqe.u.scqe.wrid_hi = sqp->sq_wptr; - - *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe; - cq->sw_wptr++; -} - -int -cxio_flush_sq(struct t3_wq *wq, struct t3_cq *cq, int count) -{ - __u32 ptr; - int flushed = 0; - struct t3_swsq *sqp = wq->sq + Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2); - - ptr = wq->sq_rptr + count; - sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); - while (ptr != wq->sq_wptr) { - insert_sq_cqe(wq, cq, sqp); - ptr++; - sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); - flushed++; - } - return flushed; -} - -/* - * Move all CQEs from the HWCQ into the SWCQ. - */ -void -cxio_flush_hw_cq(struct t3_cq *cq) -{ - struct t3_cqe *cqe, *swcqe; - - CTR3(KTR_IW_CXGB, "%s cq %p cqid 0x%x", __FUNCTION__, cq, cq->cqid); - cqe = cxio_next_hw_cqe(cq); - while (cqe) { - CTR3(KTR_IW_CXGB, "%s flushing hwcq rptr 0x%x to swcq wptr 0x%x", - __FUNCTION__, cq->rptr, cq->sw_wptr); - swcqe = cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2); - *swcqe = *cqe; - swcqe->header |= htobe32(V_CQE_SWCQE(1)); - cq->sw_wptr++; - cq->rptr++; - cqe = cxio_next_hw_cqe(cq); - } -} - -static int cqe_completes_wr(struct t3_cqe *cqe, struct t3_wq *wq) -{ - if (CQE_OPCODE(*cqe) == T3_TERMINATE) - return 0; - - if ((CQE_OPCODE(*cqe) == T3_RDMA_WRITE) && RQ_TYPE(*cqe)) - return 0; - - if ((CQE_OPCODE(*cqe) == T3_READ_RESP) && SQ_TYPE(*cqe)) - return 0; - - if (CQE_OPCODE(*cqe) && RQ_TYPE(*cqe) && - Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) - return 0; - - return 1; -} - -void -cxio_count_scqes(struct t3_cq *cq, struct t3_wq *wq, int *count) -{ - struct t3_cqe *cqe; - u32 ptr; - - *count = 0; - ptr = cq->sw_rptr; - while (!Q_EMPTY(ptr, cq->sw_wptr)) { - cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2)); - if ((SQ_TYPE(*cqe) || (CQE_OPCODE(*cqe) == T3_READ_RESP)) && - (CQE_QPID(*cqe) == wq->qpid)) - (*count)++; - ptr++; - } - CTR3(KTR_IW_CXGB, "%s cq %p count %d", __FUNCTION__, cq, *count); -} - -void -cxio_count_rcqes(struct t3_cq *cq, struct t3_wq *wq, int *count) -{ - struct t3_cqe *cqe; - u32 ptr; - - *count = 0; - CTR2(KTR_IW_CXGB, "%s count zero %d", __FUNCTION__, *count); - ptr = cq->sw_rptr; - while (!Q_EMPTY(ptr, cq->sw_wptr)) { - cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2)); - if (RQ_TYPE(*cqe) && (CQE_OPCODE(*cqe) != T3_READ_RESP) && - (CQE_QPID(*cqe) == wq->qpid) && cqe_completes_wr(cqe, wq)) - (*count)++; - ptr++; - } - CTR3(KTR_IW_CXGB, "%s cq %p count %d", __FUNCTION__, cq, *count); -} - -static int -cxio_hal_init_ctrl_cq(struct cxio_rdev *rdev_p) -{ - - return (cxio_rdma_cq_setup(rdev_p, 0, 0, 1, 1, 0, 0)); -} - -static int -cxio_hal_init_ctrl_qp(struct cxio_rdev *rdev_p) -{ - int err; - u64 sge_cmd, ctx0, ctx1; - u64 base_addr; - struct t3_modify_qp_wr *wqe; - struct mbuf *m; - - m = M_GETHDR_OFLD(0, CPL_PRIORITY_CONTROL, wqe); - if (m == NULL) { - CTR1(KTR_IW_CXGB, "%s m_gethdr failed", __FUNCTION__); - return (ENOMEM); - } - err = cxio_hal_init_ctrl_cq(rdev_p); - if (err) { - CTR2(KTR_IW_CXGB, "%s err %d initializing ctrl_cq", __FUNCTION__, err); - goto err; - } - - rdev_p->ctrl_qp.workq = contigmalloc((1 << T3_CTRL_QP_SIZE_LOG2) - *sizeof(union t3_wr), M_DEVBUF, M_NOWAIT, 0ul, ~0ul, 4096, 0); - if (rdev_p->ctrl_qp.workq) - rdev_p->ctrl_qp.dma_addr = vtophys(rdev_p->ctrl_qp.workq); - else { - CTR1(KTR_IW_CXGB, "%s dma_alloc_coherent failed", __FUNCTION__); - err = ENOMEM; - goto err; - } - - rdev_p->ctrl_qp.doorbell = rdev_p->rnic_info.kdb_addr; - memset(rdev_p->ctrl_qp.workq, 0, - (1 << T3_CTRL_QP_SIZE_LOG2) * sizeof(union t3_wr)); - - mtx_init(&rdev_p->ctrl_qp.lock, "ctl-qp lock", NULL, MTX_DEF|MTX_DUPOK); - - /* update HW Ctrl QP context */ - base_addr = rdev_p->ctrl_qp.dma_addr; - base_addr >>= 12; - ctx0 = (V_EC_SIZE((1 << T3_CTRL_QP_SIZE_LOG2)) | - V_EC_BASE_LO((u32) base_addr & 0xffff)); - ctx0 <<= 32; - ctx0 |= V_EC_CREDITS(FW_WR_NUM); - base_addr >>= 16; - ctx1 = (u32) base_addr; - base_addr >>= 32; - ctx1 |= ((u64) (V_EC_BASE_HI((u32) base_addr & 0xf) | V_EC_RESPQ(0) | - V_EC_TYPE(0) | V_EC_GEN(1) | - V_EC_UP_TOKEN(T3_CTL_QP_TID) | F_EC_VALID)) << 32; - memset(wqe, 0, sizeof(*wqe)); - build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD, 0, 0, - T3_CTL_QP_TID, 7); - wqe->flags = htobe32(MODQP_WRITE_EC); - sge_cmd = (3ULL << 56) | FW_RI_SGEEC_START << 8 | 3; - wqe->sge_cmd = htobe64(sge_cmd); - wqe->ctx1 = htobe64(ctx1); - wqe->ctx0 = htobe64(ctx0); - CTR3(KTR_IW_CXGB, "CtrlQP dma_addr 0x%llx workq %p size %d", - (unsigned long long) rdev_p->ctrl_qp.dma_addr, - rdev_p->ctrl_qp.workq, 1 << T3_CTRL_QP_SIZE_LOG2); - return t3_offload_tx(rdev_p->adap, m); -err: - m_freem(m); - return err; -} - -static int -cxio_hal_destroy_ctrl_qp(struct cxio_rdev *rdev_p) -{ -#if 0 - - dma_free_coherent(&(rdev_p->rnic_info.pdev), - (1UL << T3_CTRL_QP_SIZE_LOG2) - * sizeof(union t3_wr), rdev_p->ctrl_qp.workq, - /* pci_unmap_addr(&rdev_p->ctrl_qp, mapping)*/ 0); -#else - contigfree(rdev_p->ctrl_qp.workq,(1UL << T3_CTRL_QP_SIZE_LOG2) - * sizeof(union t3_wr), M_DEVBUF); -#endif - return cxio_hal_clear_qp_ctx(rdev_p, T3_CTRL_QP_ID); -} - -/* write len bytes of data into addr (32B aligned address) - * If data is NULL, clear len byte of memory to zero. - * caller aquires the ctrl_qp lock before the call - */ -static int -cxio_hal_ctrl_qp_write_mem(struct cxio_rdev *rdev_p, u32 addr, - u32 len, void *data) -{ - u32 i, nr_wqe, copy_len; - u8 *copy_data; - u8 wr_len, utx_len; /* length in 8 byte flit */ - enum t3_wr_flags flag; - __be64 *wqe; - u64 utx_cmd; - addr &= 0x7FFFFFF; - nr_wqe = len % 96 ? len / 96 + 1 : len / 96; /* 96B max per WQE */ - CTR6(KTR_IW_CXGB, "cxio_hal_ctrl_qp_write_mem wptr 0x%x rptr 0x%x len %d, nr_wqe %d data %p addr 0x%0x", - rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, len, - nr_wqe, data, addr); - utx_len = 3; /* in 32B unit */ - for (i = 0; i < nr_wqe; i++) { - if (Q_FULL(rdev_p->ctrl_qp.rptr, rdev_p->ctrl_qp.wptr, - T3_CTRL_QP_SIZE_LOG2)) { - CTR4(KTR_IW_CXGB, "%s ctrl_qp full wtpr 0x%0x rptr 0x%0x, " - "wait for more space i %d", __FUNCTION__, - rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, i); - if (cxio_wait(&rdev_p->ctrl_qp, - &rdev_p->ctrl_qp.lock, - !Q_FULL(rdev_p->ctrl_qp.rptr, - rdev_p->ctrl_qp.wptr, - T3_CTRL_QP_SIZE_LOG2))) { - CTR1(KTR_IW_CXGB, "%s ctrl_qp workq interrupted", - __FUNCTION__); - return (-ERESTART); - } - CTR2(KTR_IW_CXGB, "%s ctrl_qp wakeup, continue posting work request " - "i %d", __FUNCTION__, i); - } - wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr % - (1 << T3_CTRL_QP_SIZE_LOG2))); - flag = 0; - if (i == (nr_wqe - 1)) { - /* last WQE */ - flag = T3_COMPLETION_FLAG; - if (len % 32) - utx_len = len / 32 + 1; - else - utx_len = len / 32; - } - - /* - * Force a CQE to return the credit to the workq in case - * we posted more than half the max QP size of WRs - */ - if ((i != 0) && - (i % (((1 << T3_CTRL_QP_SIZE_LOG2)) >> 1) == 0)) { - flag = T3_COMPLETION_FLAG; - CTR2(KTR_IW_CXGB, "%s force completion at i %d", __FUNCTION__, i); - } - - /* build the utx mem command */ - wqe += (sizeof(struct t3_bypass_wr) >> 3); - utx_cmd = (T3_UTX_MEM_WRITE << 28) | (addr + i * 3); - utx_cmd <<= 32; - utx_cmd |= (utx_len << 28) | ((utx_len << 2) + 1); - *wqe = htobe64(utx_cmd); - wqe++; - copy_data = (u8 *) data + i * 96; - copy_len = len > 96 ? 96 : len; - - /* clear memory content if data is NULL */ - if (data) - memcpy(wqe, copy_data, copy_len); - else - memset(wqe, 0, copy_len); - if (copy_len % 32) - memset(((u8 *) wqe) + copy_len, 0, - 32 - (copy_len % 32)); - wr_len = ((sizeof(struct t3_bypass_wr)) >> 3) + 1 + - (utx_len << 2); - wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr % - (1 << T3_CTRL_QP_SIZE_LOG2))); - - /* wptr in the WRID[31:0] */ - ((union t3_wrid *)(wqe+1))->id0.low = rdev_p->ctrl_qp.wptr; - - /* - * This must be the last write with a memory barrier - * for the genbit - */ - build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_BP, flag, - Q_GENBIT(rdev_p->ctrl_qp.wptr, - T3_CTRL_QP_SIZE_LOG2), T3_CTRL_QP_ID, - wr_len); - if (flag == T3_COMPLETION_FLAG) - ring_doorbell(rdev_p->ctrl_qp.doorbell, T3_CTRL_QP_ID); - - len -= 96; - rdev_p->ctrl_qp.wptr++; - } - return 0; -} - -/* IN: stag key, pdid, perm, zbva, to, len, page_size, pbl, and pbl_size - * OUT: stag index, actual pbl_size, pbl_addr allocated. - * TBD: shared memory region support - */ -static int -__cxio_tpt_op(struct cxio_rdev *rdev_p, u32 reset_tpt_entry, - u32 *stag, u8 stag_state, u32 pdid, - enum tpt_mem_type type, enum tpt_mem_perm perm, - u32 zbva, u64 to, u32 len, u8 page_size, - u32 pbl_size, u32 pbl_addr) -{ - int err; - struct tpt_entry tpt; - u32 stag_idx; - u32 wptr; - - stag_state = stag_state > 0; - stag_idx = (*stag) >> 8; - - if ((!reset_tpt_entry) && !(*stag != T3_STAG_UNSET)) { - stag_idx = cxio_hal_get_stag(rdev_p->rscp); - if (!stag_idx) - return (-ENOMEM); - *stag = (stag_idx << 8) | ((*stag) & 0xFF); - } - CTR5(KTR_IW_CXGB, "%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x", - __FUNCTION__, stag_state, type, pdid, stag_idx); - - mtx_lock(&rdev_p->ctrl_qp.lock); - - /* write TPT entry */ - if (reset_tpt_entry) - memset(&tpt, 0, sizeof(tpt)); - else { - tpt.valid_stag_pdid = htobe32(F_TPT_VALID | - V_TPT_STAG_KEY((*stag) & M_TPT_STAG_KEY) | - V_TPT_STAG_STATE(stag_state) | - V_TPT_STAG_TYPE(type) | V_TPT_PDID(pdid)); - PANIC_IF(page_size >= 28); - tpt.flags_pagesize_qpid = htobe32(V_TPT_PERM(perm) | - F_TPT_MW_BIND_ENABLE | - V_TPT_ADDR_TYPE((zbva ? TPT_ZBTO : TPT_VATO)) | - V_TPT_PAGE_SIZE(page_size)); - tpt.rsvd_pbl_addr = reset_tpt_entry ? 0 : - htobe32(V_TPT_PBL_ADDR(PBL_OFF(rdev_p, pbl_addr)>>3)); - tpt.len = htobe32(len); - tpt.va_hi = htobe32((u32) (to >> 32)); - tpt.va_low_or_fbo = htobe32((u32) (to & 0xFFFFFFFFULL)); - tpt.rsvd_bind_cnt_or_pstag = 0; - tpt.rsvd_pbl_size = reset_tpt_entry ? 0 : - htobe32(V_TPT_PBL_SIZE((pbl_size) >> 2)); - } - err = cxio_hal_ctrl_qp_write_mem(rdev_p, - stag_idx + - (rdev_p->rnic_info.tpt_base >> 5), - sizeof(tpt), &tpt); - - /* release the stag index to free pool */ - if (reset_tpt_entry) - cxio_hal_put_stag(rdev_p->rscp, stag_idx); - - wptr = rdev_p->ctrl_qp.wptr; - mtx_unlock(&rdev_p->ctrl_qp.lock); - if (!err) - if (cxio_wait(&rdev_p->ctrl_qp, - &rdev_p->ctrl_qp.lock, - SEQ32_GE(rdev_p->ctrl_qp.rptr, wptr))) - return (-ERESTART); - return err; -} - -int cxio_write_pbl(struct cxio_rdev *rdev_p, __be64 *pbl, - u32 pbl_addr, u32 pbl_size) -{ - u32 wptr; - int err; - - CTR4(KTR_IW_CXGB, "%s *pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d", - __func__, pbl_addr, rdev_p->rnic_info.pbl_base, - pbl_size); - - mtx_lock(&rdev_p->ctrl_qp.lock); - err = cxio_hal_ctrl_qp_write_mem(rdev_p, pbl_addr >> 5, pbl_size << 3, - pbl); - wptr = rdev_p->ctrl_qp.wptr; - mtx_unlock(&rdev_p->ctrl_qp.lock); - if (err) - return err; - - if (cxio_wait(&rdev_p->ctrl_qp, - &rdev_p->ctrl_qp.lock, - SEQ32_GE(rdev_p->ctrl_qp.rptr, wptr))) - return ERESTART; - - return 0; -} - -int -cxio_register_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, - enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, - u8 page_size, u32 pbl_size, u32 pbl_addr) -{ - *stag = T3_STAG_UNSET; - return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm, - zbva, to, len, page_size, pbl_size, pbl_addr); -} - -int -cxio_reregister_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, - enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, - u8 page_size, u32 pbl_size, u32 pbl_addr) -{ - return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm, - zbva, to, len, page_size, pbl_size, pbl_addr); -} - -int -cxio_dereg_mem(struct cxio_rdev *rdev_p, u32 stag, u32 pbl_size, - u32 pbl_addr) -{ - return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0, - pbl_size, pbl_addr); -} - -int -cxio_allocate_window(struct cxio_rdev *rdev_p, u32 * stag, u32 pdid) -{ - *stag = T3_STAG_UNSET; - return __cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_MW, 0, 0, 0ULL, 0, 0, - 0, 0); -} - -int -cxio_deallocate_window(struct cxio_rdev *rdev_p, u32 stag) -{ - return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0, - 0, 0); -} - -int -cxio_rdma_init(struct cxio_rdev *rdev_p, struct t3_rdma_init_attr *attr, - struct socket *so) -{ - struct t3_rdma_init_wr *wqe; - struct mbuf *m; - struct ofld_hdr *oh; - int rc; - struct tcpcb *tp; - struct inpcb *inp; - struct toepcb *toep; - - m = M_GETHDR_OFLD(0, CPL_PRIORITY_DATA, wqe); - if (m == NULL) - return (-ENOMEM); - CTR2(KTR_IW_CXGB, "%s rdev_p %p", __FUNCTION__, rdev_p); - wqe->wrh.op_seop_flags = htobe32(V_FW_RIWR_OP(T3_WR_INIT)); - wqe->wrh.gen_tid_len = htobe32(V_FW_RIWR_TID(attr->tid) | - V_FW_RIWR_LEN(sizeof(*wqe) >> 3)); - wqe->wrid.id1 = 0; - wqe->qpid = htobe32(attr->qpid); - wqe->pdid = htobe32(attr->pdid); - wqe->scqid = htobe32(attr->scqid); - wqe->rcqid = htobe32(attr->rcqid); - wqe->rq_addr = htobe32(attr->rq_addr - rdev_p->rnic_info.rqt_base); - wqe->rq_size = htobe32(attr->rq_size); - wqe->mpaattrs = attr->mpaattrs; - wqe->qpcaps = attr->qpcaps; - wqe->ulpdu_size = htobe16(attr->tcp_emss); - wqe->rqe_count = htobe16(attr->rqe_count); - wqe->flags_rtr_type = htobe16(attr->flags | - V_RTR_TYPE(attr->rtr_type) | - V_CHAN(attr->chan)); - wqe->ord = htobe32(attr->ord); - wqe->ird = htobe32(attr->ird); - wqe->qp_dma_addr = htobe64(attr->qp_dma_addr); - wqe->qp_dma_size = htobe32(attr->qp_dma_size); - wqe->irs = htobe32(attr->irs); - - /* XXX: bad form, fix later */ - inp = sotoinpcb(so); - INP_WLOCK(inp); - tp = intotcpcb(inp); - toep = tp->t_toe; - oh = mtod(m, struct ofld_hdr *); - oh->plen = 0; - oh->flags |= F_HDR_DF; - enqueue_wr(toep, m); - toep->tp_wr_avail--; - toep->tp_wr_unacked++; - rc = t3_offload_tx(rdev_p->adap, m); - INP_WUNLOCK(inp); - - return (rc); -} - -static int -cxio_hal_ev_handler(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct iwch_dev *rnicp = sc->iwarp_softc; - struct cxio_rdev *rdev_p = &rnicp->rdev; - struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) m->m_data; - int qpid = CQE_QPID(rsp_msg->cqe); - - CTR6(KTR_IW_CXGB, "%s cq_id 0x%x cq_ptr 0x%x genbit %0x overflow %0x an %0x", - __FUNCTION__, RSPQ_CQID(rsp_msg), RSPQ_CQPTR(rsp_msg), - RSPQ_GENBIT(rsp_msg), RSPQ_OVERFLOW(rsp_msg), RSPQ_AN(rsp_msg)); - CTR4(KTR_IW_CXGB, "se %0x notify %0x cqbranch %0x creditth %0x", - RSPQ_SE(rsp_msg), RSPQ_NOTIFY(rsp_msg), RSPQ_CQBRANCH(rsp_msg), - RSPQ_CREDIT_THRESH(rsp_msg)); - CTR4(KTR_IW_CXGB, "CQE: QPID 0x%0x type 0x%0x status 0x%0x opcode %d", - qpid, CQE_TYPE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe), - CQE_OPCODE(rsp_msg->cqe)); - CTR3(KTR_IW_CXGB, "len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x", - CQE_LEN(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe)); - - switch(qpid) { - case T3_CTRL_QP_ID: - mtx_lock(&rdev_p->ctrl_qp.lock); - rdev_p->ctrl_qp.rptr = CQE_WRID_LOW(rsp_msg->cqe) + 1; - wakeup(&rdev_p->ctrl_qp); - mtx_unlock(&rdev_p->ctrl_qp.lock); - break; - case 0xfff8: - break; - default: - iwch_ev_dispatch(rnicp, m); - } - - m_freem(m); - return (0); -} - -/* Caller takes care of locking if needed */ -int -cxio_rdev_open(struct cxio_rdev *rdev_p) -{ - int err = 0; - struct rdma_info *ri = &rdev_p->rnic_info; - struct adapter *sc = rdev_p->adap; - - KASSERT(rdev_p->adap, ("%s: adap is NULL", __func__)); - - memset(&rdev_p->ctrl_qp, 0, sizeof(rdev_p->ctrl_qp)); - - ri->udbell_physbase = rman_get_start(sc->udbs_res); - ri->udbell_len = rman_get_size(sc->udbs_res); - ri->tpt_base = t3_read_reg(sc, A_ULPTX_TPT_LLIMIT); - ri->tpt_top = t3_read_reg(sc, A_ULPTX_TPT_ULIMIT); - ri->pbl_base = t3_read_reg(sc, A_ULPTX_PBL_LLIMIT); - ri->pbl_top = t3_read_reg(sc, A_ULPTX_PBL_ULIMIT); - ri->rqt_base = t3_read_reg(sc, A_ULPRX_RQ_LLIMIT); - ri->rqt_top = t3_read_reg(sc, A_ULPRX_RQ_ULIMIT); - ri->kdb_addr = (void *)((unsigned long) - rman_get_virtual(sc->regs_res) + A_SG_KDOORBELL); - - /* - * qpshift is the number of bits to shift the qpid left in order - * to get the correct address of the doorbell for that qp. - */ - cxio_init_ucontext(rdev_p, &rdev_p->uctx); - rdev_p->qpshift = PAGE_SHIFT - - ilog2(65536 >> - ilog2(rdev_p->rnic_info.udbell_len >> - PAGE_SHIFT)); - rdev_p->qpnr = rdev_p->rnic_info.udbell_len >> PAGE_SHIFT; - rdev_p->qpmask = (65536 >> ilog2(rdev_p->qpnr)) - 1; - CTR4(KTR_IW_CXGB, "cxio_rdev_open rnic %p info: tpt_base 0x%0x tpt_top 0x%0x num stags %d", - rdev_p->adap, rdev_p->rnic_info.tpt_base, - rdev_p->rnic_info.tpt_top, cxio_num_stags(rdev_p)); - CTR4(KTR_IW_CXGB, "pbl_base 0x%0x pbl_top 0x%0x rqt_base 0x%0x, rqt_top 0x%0x", - rdev_p->rnic_info.pbl_base, - rdev_p->rnic_info.pbl_top, rdev_p->rnic_info.rqt_base, - rdev_p->rnic_info.rqt_top); - CTR6(KTR_IW_CXGB, "udbell_len 0x%0x udbell_physbase 0x%lx kdb_addr %p qpshift %lu " - "qpnr %d qpmask 0x%x", - rdev_p->rnic_info.udbell_len, - rdev_p->rnic_info.udbell_physbase, rdev_p->rnic_info.kdb_addr, - rdev_p->qpshift, rdev_p->qpnr, rdev_p->qpmask); - - err = cxio_hal_init_ctrl_qp(rdev_p); - if (err) { - log(LOG_ERR, "%s error %d initializing ctrl_qp.\n", - __FUNCTION__, err); - goto err1; - } - err = cxio_hal_init_resource(rdev_p, cxio_num_stags(rdev_p), 0, - 0, T3_MAX_NUM_QP, T3_MAX_NUM_CQ, - T3_MAX_NUM_PD); - if (err) { - log(LOG_ERR, "%s error %d initializing hal resources.\n", - __FUNCTION__, err); - goto err2; - } - err = cxio_hal_pblpool_create(rdev_p); - if (err) { - log(LOG_ERR, "%s error %d initializing pbl mem pool.\n", - __FUNCTION__, err); - goto err3; - } - err = cxio_hal_rqtpool_create(rdev_p); - if (err) { - log(LOG_ERR, "%s error %d initializing rqt mem pool.\n", - __FUNCTION__, err); - goto err4; - } - return 0; -err4: - cxio_hal_pblpool_destroy(rdev_p); -err3: - cxio_hal_destroy_resource(rdev_p->rscp); -err2: - cxio_hal_destroy_ctrl_qp(rdev_p); -err1: - return err; -} - -void -cxio_rdev_close(struct cxio_rdev *rdev_p) -{ - cxio_hal_pblpool_destroy(rdev_p); - cxio_hal_rqtpool_destroy(rdev_p); - cxio_hal_destroy_ctrl_qp(rdev_p); - cxio_hal_destroy_resource(rdev_p->rscp); -} - -int -cxio_hal_init(struct adapter *sc) -{ -#ifdef needed - if (cxio_hal_init_rhdl_resource(T3_MAX_NUM_RI)) - return (ENOMEM); -#endif - t3_register_cpl_handler(sc, CPL_ASYNC_NOTIF, cxio_hal_ev_handler); - - return (0); -} - -void -cxio_hal_uninit(struct adapter *sc) -{ - t3_register_cpl_handler(sc, CPL_ASYNC_NOTIF, NULL); -#ifdef needed - cxio_hal_destroy_rhdl_resource(); -#endif -} - -static void -flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq) -{ - struct t3_swsq *sqp; - __u32 ptr = wq->sq_rptr; - int count = Q_COUNT(wq->sq_rptr, wq->sq_wptr); - - sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); - while (count--) - if (!sqp->signaled) { - ptr++; - sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2); - } else if (sqp->complete) { - - /* - * Insert this completed cqe into the swcq. - */ - CTR3(KTR_IW_CXGB, "%s moving cqe into swcq sq idx %ld cq idx %ld", - __FUNCTION__, Q_PTR2IDX(ptr, wq->sq_size_log2), - Q_PTR2IDX(cq->sw_wptr, cq->size_log2)); - sqp->cqe.header |= htonl(V_CQE_SWCQE(1)); - *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) - = sqp->cqe; - cq->sw_wptr++; - sqp->signaled = 0; - break; - } else - break; -} - -static void -create_read_req_cqe(struct t3_wq *wq, struct t3_cqe *hw_cqe, - struct t3_cqe *read_cqe) -{ - read_cqe->u.scqe.wrid_hi = wq->oldest_read->sq_wptr; - read_cqe->len = wq->oldest_read->read_len; - read_cqe->header = htonl(V_CQE_QPID(CQE_QPID(*hw_cqe)) | - V_CQE_SWCQE(SW_CQE(*hw_cqe)) | - V_CQE_OPCODE(T3_READ_REQ) | - V_CQE_TYPE(1)); -} - -/* - * Return a ptr to the next read wr in the SWSQ or NULL. - */ -static void -advance_oldest_read(struct t3_wq *wq) -{ - - u32 rptr = wq->oldest_read - wq->sq + 1; - u32 wptr = Q_PTR2IDX(wq->sq_wptr, wq->sq_size_log2); - - while (Q_PTR2IDX(rptr, wq->sq_size_log2) != wptr) { - wq->oldest_read = wq->sq + Q_PTR2IDX(rptr, wq->sq_size_log2); - - if (wq->oldest_read->opcode == T3_READ_REQ) - return; - rptr++; - } - wq->oldest_read = NULL; -} - -/* - * cxio_poll_cq - * - * Caller must: - * check the validity of the first CQE, - * supply the wq assicated with the qpid. - * - * credit: cq credit to return to sge. - * cqe_flushed: 1 iff the CQE is flushed. - * cqe: copy of the polled CQE. - * - * return value: - * 0 CQE returned, - * -1 CQE skipped, try again. - */ -int -cxio_poll_cq(struct t3_wq *wq, struct t3_cq *cq, struct t3_cqe *cqe, - u8 *cqe_flushed, u64 *cookie, u32 *credit) -{ - int ret = 0; - struct t3_cqe *hw_cqe, read_cqe; - - *cqe_flushed = 0; - *credit = 0; - hw_cqe = cxio_next_cqe(cq); - - CTR5(KTR_IW_CXGB, "cxio_poll_cq CQE OOO %d qpid 0x%0x genbit %d type %d status 0x%0x", - CQE_OOO(*hw_cqe), CQE_QPID(*hw_cqe), - CQE_GENBIT(*hw_cqe), CQE_TYPE(*hw_cqe), CQE_STATUS(*hw_cqe)); - CTR4(KTR_IW_CXGB, "opcode 0x%0x len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x", - CQE_OPCODE(*hw_cqe), CQE_LEN(*hw_cqe), CQE_WRID_HI(*hw_cqe), - CQE_WRID_LOW(*hw_cqe)); - - /* - * skip cqe's not affiliated with a QP. - */ - if (wq == NULL) { - ret = -1; - goto skip_cqe; - } - - /* - * Gotta tweak READ completions: - * 1) the cqe doesn't contain the sq_wptr from the wr. - * 2) opcode not reflected from the wr. - * 3) read_len not reflected from the wr. - * 4) cq_type is RQ_TYPE not SQ_TYPE. - */ - if (RQ_TYPE(*hw_cqe) && (CQE_OPCODE(*hw_cqe) == T3_READ_RESP)) { - - /* - * Don't write to the HWCQ, so create a new read req CQE - * in local memory. - */ - create_read_req_cqe(wq, hw_cqe, &read_cqe); - hw_cqe = &read_cqe; - advance_oldest_read(wq); - } - - /* - * T3A: Discard TERMINATE CQEs. - */ - if (CQE_OPCODE(*hw_cqe) == T3_TERMINATE) { - ret = -1; - wq->error = 1; - goto skip_cqe; - } - - if (CQE_STATUS(*hw_cqe) || wq->error) { - *cqe_flushed = wq->error; - wq->error = 1; - - /* - * T3A inserts errors into the CQE. We cannot return - * these as work completions. - */ - /* incoming write failures */ - if ((CQE_OPCODE(*hw_cqe) == T3_RDMA_WRITE) - && RQ_TYPE(*hw_cqe)) { - ret = -1; - goto skip_cqe; - } - /* incoming read request failures */ - if ((CQE_OPCODE(*hw_cqe) == T3_READ_RESP) && SQ_TYPE(*hw_cqe)) { - ret = -1; - goto skip_cqe; - } - - /* incoming SEND with no receive posted failures */ - if (CQE_OPCODE(*hw_cqe) && RQ_TYPE(*hw_cqe) && - Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) { - ret = -1; - goto skip_cqe; - } - PANIC_IF((*cqe_flushed == 0) && !SW_CQE(*hw_cqe)); - goto proc_cqe; - } - - /* - * RECV completion. - */ - if (RQ_TYPE(*hw_cqe)) { - - /* - * HW only validates 4 bits of MSN. So we must validate that - * the MSN in the SEND is the next expected MSN. If its not, - * then we complete this with TPT_ERR_MSN and mark the wq in - * error. - */ - - if (Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) { - wq->error = 1; - ret = -1; - goto skip_cqe; - } - - if (__predict_false((CQE_WRID_MSN(*hw_cqe) != (wq->rq_rptr + 1)))) { - wq->error = 1; - hw_cqe->header |= htonl(V_CQE_STATUS(TPT_ERR_MSN)); - goto proc_cqe; - } - goto proc_cqe; - } - - /* - * If we get here its a send completion. - * - * Handle out of order completion. These get stuffed - * in the SW SQ. Then the SW SQ is walked to move any - * now in-order completions into the SW CQ. This handles - * 2 cases: - * 1) reaping unsignaled WRs when the first subsequent - * signaled WR is completed. - * 2) out of order read completions. - */ - if (!SW_CQE(*hw_cqe) && (CQE_WRID_SQ_WPTR(*hw_cqe) != wq->sq_rptr)) { - struct t3_swsq *sqp; - - CTR2(KTR_IW_CXGB, "%s out of order completion going in swsq at idx %ld", - __FUNCTION__, - Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2)); - sqp = wq->sq + - Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2); - sqp->cqe = *hw_cqe; - sqp->complete = 1; - ret = -1; - goto flush_wq; - } - -proc_cqe: - *cqe = *hw_cqe; - - /* - * Reap the associated WR(s) that are freed up with this - * completion. - */ - if (SQ_TYPE(*hw_cqe)) { - wq->sq_rptr = CQE_WRID_SQ_WPTR(*hw_cqe); - CTR2(KTR_IW_CXGB, "%s completing sq idx %ld", __FUNCTION__, - Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2)); - *cookie = wq->sq[Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2)].wr_id; - wq->sq_rptr++; - } else { - CTR2(KTR_IW_CXGB, "%s completing rq idx %ld", __FUNCTION__, - Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)); - *cookie = wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].wr_id; - if (wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].pbl_addr) - cxio_hal_pblpool_free(wq->rdev, - wq->rq[Q_PTR2IDX(wq->rq_rptr, - wq->rq_size_log2)].pbl_addr, T3_STAG0_PBL_SIZE); - PANIC_IF(Q_EMPTY(wq->rq_rptr, wq->rq_wptr)); - wq->rq_rptr++; - } - -flush_wq: - /* - * Flush any completed cqes that are now in-order. - */ - flush_completed_wrs(wq, cq); - -skip_cqe: - if (SW_CQE(*hw_cqe)) { - CTR4(KTR_IW_CXGB, "%s cq %p cqid 0x%x skip sw cqe sw_rptr 0x%x", - __FUNCTION__, cq, cq->cqid, cq->sw_rptr); - ++cq->sw_rptr; - } else { - CTR4(KTR_IW_CXGB, "%s cq %p cqid 0x%x skip hw cqe rptr 0x%x", - __FUNCTION__, cq, cq->cqid, cq->rptr); - ++cq->rptr; - - /* - * T3A: compute credits. - */ - if (((cq->rptr - cq->wptr) > (1 << (cq->size_log2 - 1))) - || ((cq->rptr - cq->wptr) >= 128)) { - *credit = cq->rptr - cq->wptr; - cq->wptr = cq->rptr; - } - } - return ret; -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.h deleted file mode 100644 index 6b5f94820d78..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_hal.h +++ /dev/null @@ -1,274 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ -#ifndef __CXIO_HAL_H__ -#define __CXIO_HAL_H__ -#include -#include - -#define T3_CTRL_QP_ID FW_RI_SGEEC_START -#define T3_CTL_QP_TID FW_RI_TID_START -#define T3_CTRL_QP_SIZE_LOG2 8 -#define T3_CTRL_CQ_ID 0 - -/* TBD */ -#define T3_MAX_NUM_RI (1<<15) -#define T3_MAX_NUM_QP (1<<15) -#define T3_MAX_NUM_CQ (1<<15) -#define T3_MAX_NUM_PD (1<<15) -#define T3_MAX_PBL_SIZE 256 -#define T3_MAX_RQ_SIZE 1024 -#define T3_MAX_QP_DEPTH (T3_MAX_RQ_SIZE-1) -#define T3_MAX_CQ_DEPTH 65536 -#define T3_MAX_NUM_STAG (1<<15) -#define T3_MAX_MR_SIZE 0x100000000ULL -#define T3_PAGESIZE_MASK 0xffff000 /* 4KB-128MB */ - -#define T3_STAG_UNSET 0xffffffff - -#define T3_MAX_DEV_NAME_LEN 32 - -struct cxio_hal_ctrl_qp { - u32 wptr; - u32 rptr; - struct mtx lock; /* for the wtpr, can sleep */ - union t3_wr *workq; /* the work request queue */ - bus_addr_t dma_addr; /* pci bus address of the workq */ - void *doorbell; -}; - -struct cxio_hal_resource { - struct buf_ring *tpt_fifo; - struct mtx tpt_fifo_lock; - struct buf_ring *qpid_fifo; - struct mtx qpid_fifo_lock; - struct buf_ring *cqid_fifo; - struct mtx cqid_fifo_lock; - struct buf_ring *pdid_fifo; - struct mtx pdid_fifo_lock; -}; - -struct cxio_qpid { - TAILQ_ENTRY(cxio_qpid) entry; - u32 qpid; -}; - -struct cxio_ucontext { - TAILQ_HEAD(, cxio_qpid) qpids; - struct mtx lock; -}; - -struct cxio_rdev { - struct adapter *adap; - struct rdma_info rnic_info; - struct cxio_hal_resource *rscp; - struct cxio_hal_ctrl_qp ctrl_qp; - unsigned long qpshift; - u32 qpnr; - u32 qpmask; - struct cxio_ucontext uctx; - struct gen_pool *pbl_pool; - struct gen_pool *rqt_pool; - struct ifnet *ifp; - TAILQ_ENTRY(cxio_rdev) entry; -}; - -static __inline int -cxio_num_stags(struct cxio_rdev *rdev_p) -{ - return min((int)T3_MAX_NUM_STAG, (int)((rdev_p->rnic_info.tpt_top - rdev_p->rnic_info.tpt_base) >> 5)); -} - -typedef void (*cxio_hal_ev_callback_func_t) (struct cxio_rdev * rdev_p, - struct mbuf * m); - -#define RSPQ_CQID(rsp) (be32toh(rsp->cq_ptrid) & 0xffff) -#define RSPQ_CQPTR(rsp) ((be32toh(rsp->cq_ptrid) >> 16) & 0xffff) -#define RSPQ_GENBIT(rsp) ((be32toh(rsp->flags) >> 16) & 1) -#define RSPQ_OVERFLOW(rsp) ((be32toh(rsp->flags) >> 17) & 1) -#define RSPQ_AN(rsp) ((be32toh(rsp->flags) >> 18) & 1) -#define RSPQ_SE(rsp) ((be32toh(rsp->flags) >> 19) & 1) -#define RSPQ_NOTIFY(rsp) ((be32toh(rsp->flags) >> 20) & 1) -#define RSPQ_CQBRANCH(rsp) ((be32toh(rsp->flags) >> 21) & 1) -#define RSPQ_CREDIT_THRESH(rsp) ((be32toh(rsp->flags) >> 22) & 1) - -struct respQ_msg_t { - __be32 flags; /* flit 0 */ - __be32 cq_ptrid; - __be64 rsvd; /* flit 1 */ - struct t3_cqe cqe; /* flits 2-3 */ -}; - -enum t3_cq_opcode { - CQ_ARM_AN = 0x2, - CQ_ARM_SE = 0x6, - CQ_FORCE_AN = 0x3, - CQ_CREDIT_UPDATE = 0x7 -}; - -int cxio_rdev_open(struct cxio_rdev *rdev); -void cxio_rdev_close(struct cxio_rdev *rdev); -int cxio_hal_cq_op(struct cxio_rdev *rdev, struct t3_cq *cq, - enum t3_cq_opcode op, u32 credit); -int cxio_create_cq(struct cxio_rdev *rdev, struct t3_cq *cq, int kernel); -int cxio_destroy_cq(struct cxio_rdev *rdev, struct t3_cq *cq); -void cxio_release_ucontext(struct cxio_rdev *rdev, struct cxio_ucontext *uctx); -void cxio_init_ucontext(struct cxio_rdev *rdev, struct cxio_ucontext *uctx); -int cxio_create_qp(struct cxio_rdev *rdev, u32 kernel_domain, struct t3_wq *wq, - struct cxio_ucontext *uctx); -int cxio_destroy_qp(struct cxio_rdev *rdev, struct t3_wq *wq, - struct cxio_ucontext *uctx); -int cxio_peek_cq(struct t3_wq *wr, struct t3_cq *cq, int opcode); -int cxio_write_pbl(struct cxio_rdev *rdev_p, __be64 *pbl, - u32 pbl_addr, u32 pbl_size); -int cxio_register_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid, - enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, - u8 page_size, u32 pbl_size, u32 pbl_addr); -int cxio_reregister_phys_mem(struct cxio_rdev *rdev, u32 * stag, u32 pdid, - enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len, - u8 page_size, u32 pbl_size, u32 pbl_addr); -int cxio_dereg_mem(struct cxio_rdev *rdev, u32 stag, u32 pbl_size, - u32 pbl_addr); -int cxio_allocate_window(struct cxio_rdev *rdev, u32 * stag, u32 pdid); -int cxio_deallocate_window(struct cxio_rdev *rdev, u32 stag); -int cxio_rdma_init(struct cxio_rdev *rdev, struct t3_rdma_init_attr *attr, - struct socket *so); -u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp); -void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid); -int cxio_hal_init(struct adapter *); -void cxio_hal_uninit(struct adapter *); -void cxio_hal_exit(void); -int cxio_flush_rq(struct t3_wq *wq, struct t3_cq *cq, int count); -int cxio_flush_sq(struct t3_wq *wq, struct t3_cq *cq, int count); -void cxio_count_rcqes(struct t3_cq *cq, struct t3_wq *wq, int *count); -void cxio_count_scqes(struct t3_cq *cq, struct t3_wq *wq, int *count); -void cxio_flush_hw_cq(struct t3_cq *cq); -int cxio_poll_cq(struct t3_wq *wq, struct t3_cq *cq, struct t3_cqe *cqe, - u8 *cqe_flushed, u64 *cookie, u32 *credit); - -#define MOD "iw_cxgb: " - -#ifdef INVARIANTS -void cxio_dump_tpt(struct cxio_rdev *rev, u32 stag); -void cxio_dump_pbl(struct cxio_rdev *rev, u32 pbl_addr, uint32_t len, u8 shift); -void cxio_dump_wqe(union t3_wr *wqe); -void cxio_dump_wce(struct t3_cqe *wce); -void cxio_dump_rqt(struct cxio_rdev *rdev, u32 hwtid, int nents); -void cxio_dump_tcb(struct cxio_rdev *rdev, u32 hwtid); -#endif - -#define cxfree(a) free((a), M_DEVBUF); - -#include -struct gen_pool { - blist_t gen_list; - daddr_t gen_base; - int gen_chunk_shift; - struct mtx gen_lock; -}; - -static __inline struct gen_pool * -gen_pool_create(daddr_t base, u_int chunk_shift, u_int len) -{ - struct gen_pool *gp; - - gp = malloc(sizeof(struct gen_pool), M_DEVBUF, M_NOWAIT); - if (gp == NULL) - return (NULL); - - memset(gp, 0, sizeof(struct gen_pool)); - gp->gen_list = blist_create(len >> chunk_shift, M_NOWAIT); - if (gp->gen_list == NULL) { - free(gp, M_DEVBUF); - return (NULL); - } - blist_free(gp->gen_list, 0, len >> chunk_shift); - gp->gen_base = base; - gp->gen_chunk_shift = chunk_shift; - mtx_init(&gp->gen_lock, "genpool", NULL, MTX_DUPOK|MTX_DEF); - - return (gp); -} - -static __inline unsigned long -gen_pool_alloc(struct gen_pool *gp, int size) -{ - int chunks; - daddr_t blkno; - - chunks = (size + (1<gen_chunk_shift) - 1) >> gp->gen_chunk_shift; - mtx_lock(&gp->gen_lock); - blkno = blist_alloc(gp->gen_list, chunks); - mtx_unlock(&gp->gen_lock); - - if (blkno == SWAPBLK_NONE) - return (0); - - return (gp->gen_base + ((1 << gp->gen_chunk_shift) * blkno)); -} - -static __inline void -gen_pool_free(struct gen_pool *gp, daddr_t address, int size) -{ - int chunks; - daddr_t blkno; - - chunks = (size + (1<gen_chunk_shift) - 1) >> gp->gen_chunk_shift; - blkno = (address - gp->gen_base) / (1 << gp->gen_chunk_shift); - mtx_lock(&gp->gen_lock); - blist_free(gp->gen_list, blkno, chunks); - mtx_unlock(&gp->gen_lock); -} - -static __inline void -gen_pool_destroy(struct gen_pool *gp) -{ - blist_destroy(gp->gen_list); - free(gp, M_DEVBUF); -} - -#define cxio_wait(ctx, lockp, cond) \ -({ \ - int __ret = 0; \ - mtx_lock(lockp); \ - while (!cond) { \ - msleep(ctx, lockp, 0, "cxio_wait", hz); \ - if (SIGPENDING(curthread)) { \ - __ret = ERESTART; \ - break; \ - } \ - } \ - mtx_unlock(lockp); \ - __ret; \ -}) - -#define KTR_IW_CXGB KTR_SPARE3 - -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ib_intfc.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ib_intfc.h deleted file mode 100644 index 7c7cd241a131..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_ib_intfc.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __IB_INTFC_H__ -#define __IB_INTFC_H__ - -/* $FreeBSD$ */ - -#undef prefetch -#undef WARN_ON -#undef max_t -#undef udelay -#undef le32_to_cpu -#undef le16_to_cpu -#undef cpu_to_le32 -#undef swab32 -#undef container_of - -#undef LIST_HEAD -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ -} - -#endif /* __IB_INTFC_H__ */ diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_mem.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_mem.c deleted file mode 100644 index 8b82b230cfc0..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_mem.c +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static int iwch_finish_mem_reg(struct iwch_mr *mhp, u32 stag) -{ - u32 mmid; - - mhp->attr.state = 1; - mhp->attr.stag = stag; - mmid = stag >> 8; - mhp->ibmr.rkey = mhp->ibmr.lkey = stag; - CTR3(KTR_IW_CXGB, "%s mmid 0x%x mhp %p", __func__, mmid, mhp); - return insert_handle(mhp->rhp, &mhp->rhp->mmidr, mhp, mmid); -} - -int iwch_register_mem(struct iwch_dev *rhp, struct iwch_pd *php, - struct iwch_mr *mhp, - int shift) -{ - u32 stag; - int ret; - - if (cxio_register_phys_mem(&rhp->rdev, - &stag, mhp->attr.pdid, - mhp->attr.perms, - mhp->attr.zbva, - mhp->attr.va_fbo, - mhp->attr.len, - shift - 12, - mhp->attr.pbl_size, mhp->attr.pbl_addr)) - return (-ENOMEM); - - ret = iwch_finish_mem_reg(mhp, stag); - if (ret) - cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, - mhp->attr.pbl_addr); - return ret; -} - -int iwch_reregister_mem(struct iwch_dev *rhp, struct iwch_pd *php, - struct iwch_mr *mhp, - int shift, - int npages) -{ - u32 stag; - int ret; - - /* We could support this... */ - if (npages > mhp->attr.pbl_size) - return (-ENOMEM); - - stag = mhp->attr.stag; - if (cxio_reregister_phys_mem(&rhp->rdev, - &stag, mhp->attr.pdid, - mhp->attr.perms, - mhp->attr.zbva, - mhp->attr.va_fbo, - mhp->attr.len, - shift - 12, - mhp->attr.pbl_size, mhp->attr.pbl_addr)) - return (-ENOMEM); - - ret = iwch_finish_mem_reg(mhp, stag); - if (ret) - cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, - mhp->attr.pbl_addr); - return ret; -} - -int iwch_alloc_pbl(struct iwch_mr *mhp, int npages) -{ - mhp->attr.pbl_addr = cxio_hal_pblpool_alloc(&mhp->rhp->rdev, - npages << 3); - - if (!mhp->attr.pbl_addr) - return -ENOMEM; - - mhp->attr.pbl_size = npages; - - return 0; - } - -void iwch_free_pbl(struct iwch_mr *mhp) -{ - cxio_hal_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr, - mhp->attr.pbl_size << 3); -} - -int iwch_write_pbl(struct iwch_mr *mhp, __be64 *pages, int npages, int offset) -{ - return cxio_write_pbl(&mhp->rhp->rdev, pages, - mhp->attr.pbl_addr + (offset << 3), npages); -} - -int build_phys_page_list(struct ib_phys_buf *buffer_list, - int num_phys_buf, - u64 *iova_start, - u64 *total_size, - int *npages, - int *shift, - __be64 **page_list) -{ - u64 mask; - int i, j, n; - - mask = 0; - *total_size = 0; - for (i = 0; i < num_phys_buf; ++i) { - if (i != 0 && buffer_list[i].addr & ~PAGE_MASK) - return (-EINVAL); - if (i != 0 && i != num_phys_buf - 1 && - (buffer_list[i].size & ~PAGE_MASK)) - return (-EINVAL); - *total_size += buffer_list[i].size; - if (i > 0) - mask |= buffer_list[i].addr; - else - mask |= buffer_list[i].addr & PAGE_MASK; - if (i != num_phys_buf - 1) - mask |= buffer_list[i].addr + buffer_list[i].size; - else - mask |= (buffer_list[i].addr + buffer_list[i].size + - PAGE_SIZE - 1) & PAGE_MASK; - } - - if (*total_size > 0xFFFFFFFFULL) - return (-ENOMEM); - - /* Find largest page shift we can use to cover buffers */ - for (*shift = PAGE_SHIFT; *shift < 27; ++(*shift)) - if ((1ULL << *shift) & mask) - break; - - buffer_list[0].size += buffer_list[0].addr & ((1ULL << *shift) - 1); - buffer_list[0].addr &= ~0ull << *shift; - - *npages = 0; - for (i = 0; i < num_phys_buf; ++i) - *npages += (buffer_list[i].size + - (1ULL << *shift) - 1) >> *shift; - - if (!*npages) - return (-EINVAL); - - *page_list = kmalloc(sizeof(u64) * *npages, M_NOWAIT); - if (!*page_list) - return (-ENOMEM); - - n = 0; - for (i = 0; i < num_phys_buf; ++i) - for (j = 0; - j < (buffer_list[i].size + (1ULL << *shift) - 1) >> *shift; - ++j) - (*page_list)[n++] = htobe64(buffer_list[i].addr + - ((u64) j << *shift)); - - CTR6(KTR_IW_CXGB, "%s va 0x%llx mask 0x%llx shift %d len %lld pbl_size %d", - __FUNCTION__, (unsigned long long) *iova_start, - (unsigned long long) mask, *shift, (unsigned long long) *total_size, - *npages); - - return 0; - -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.c deleted file mode 100644 index 0b0e5f4f46ba..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.c +++ /dev/null @@ -1,1167 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -#include -#include - -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include -#include - -static int -iwch_modify_port(struct ib_device *ibdev, - u8 port, int port_modify_mask, - struct ib_port_modify *props) -{ - return (-ENOSYS); -} - -static struct ib_ah * -iwch_ah_create(struct ib_pd *pd, - struct ib_ah_attr *ah_attr) -{ - return ERR_PTR(-ENOSYS); -} - -static int -iwch_ah_destroy(struct ib_ah *ah) -{ - return (-ENOSYS); -} - -static int iwch_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) -{ - return (-ENOSYS); -} - -static int -iwch_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) -{ - return (-ENOSYS); -} - -static int -iwch_process_mad(struct ib_device *ibdev, - int mad_flags, - u8 port_num, - struct ib_wc *in_wc, - struct ib_grh *in_grh, - struct ib_mad *in_mad, struct ib_mad *out_mad) -{ - return (-ENOSYS); -} - -static int -iwch_dealloc_ucontext(struct ib_ucontext *context) -{ - struct iwch_dev *rhp = to_iwch_dev(context->device); - struct iwch_ucontext *ucontext = to_iwch_ucontext(context); - struct iwch_mm_entry *mm, *tmp; - - CTR2(KTR_IW_CXGB, "%s context %p", __FUNCTION__, context); - TAILQ_FOREACH_SAFE(mm, &ucontext->mmaps, entry, tmp) { - TAILQ_REMOVE(&ucontext->mmaps, mm, entry); - cxfree(mm); - } - cxio_release_ucontext(&rhp->rdev, &ucontext->uctx); - cxfree(ucontext); - return 0; -} - -static struct ib_ucontext * -iwch_alloc_ucontext(struct ib_device *ibdev, struct ib_udata *udata) -{ - struct iwch_ucontext *context; - struct iwch_dev *rhp = to_iwch_dev(ibdev); - - CTR2(KTR_IW_CXGB, "%s ibdev %p", __FUNCTION__, ibdev); - context = malloc(sizeof(*context), M_DEVBUF, M_ZERO|M_NOWAIT); - if (!context) - return ERR_PTR(-ENOMEM); - cxio_init_ucontext(&rhp->rdev, &context->uctx); - TAILQ_INIT(&context->mmaps); - mtx_init(&context->mmap_lock, "ucontext mmap", NULL, MTX_DEF); - return &context->ibucontext; -} - -static int -iwch_destroy_cq(struct ib_cq *ib_cq) -{ - struct iwch_cq *chp; - - CTR2(KTR_IW_CXGB, "%s ib_cq %p", __FUNCTION__, ib_cq); - chp = to_iwch_cq(ib_cq); - - remove_handle(chp->rhp, &chp->rhp->cqidr, chp->cq.cqid); - mtx_lock(&chp->lock); - if (--chp->refcnt) - msleep(chp, &chp->lock, 0, "iwch_destroy_cq", 0); - mtx_unlock(&chp->lock); - - cxio_destroy_cq(&chp->rhp->rdev, &chp->cq); - cxfree(chp); - return 0; -} - -static struct ib_cq * -iwch_create_cq(struct ib_device *ibdev, struct ib_cq_init_attr *attr, - struct ib_ucontext *ib_context, - struct ib_udata *udata) -{ - struct iwch_dev *rhp; - struct iwch_cq *chp; - struct iwch_create_cq_resp uresp; - struct iwch_create_cq_req ureq; - struct iwch_ucontext *ucontext = NULL; - static int warned; - size_t resplen; - int entries = attr->cqe; - - CTR3(KTR_IW_CXGB, "%s ib_dev %p entries %d", __FUNCTION__, ibdev, entries); - rhp = to_iwch_dev(ibdev); - chp = malloc(sizeof(*chp), M_DEVBUF, M_NOWAIT|M_ZERO); - if (!chp) { - return ERR_PTR(-ENOMEM); - } - if (ib_context) { - ucontext = to_iwch_ucontext(ib_context); - if (!t3a_device(rhp)) { - if (ib_copy_from_udata(&ureq, udata, sizeof (ureq))) { - cxfree(chp); - return ERR_PTR(-EFAULT); - } - chp->user_rptr_addr = (u32 /*__user */*)(unsigned long)ureq.user_rptr_addr; - } - } - - if (t3a_device(rhp)) { - - /* - * T3A: Add some fluff to handle extra CQEs inserted - * for various errors. - * Additional CQE possibilities: - * TERMINATE, - * incoming RDMA WRITE Failures - * incoming RDMA READ REQUEST FAILUREs - * NOTE: We cannot ensure the CQ won't overflow. - */ - entries += 16; - } - entries = roundup_pow_of_two(entries); - chp->cq.size_log2 = ilog2(entries); - - if (cxio_create_cq(&rhp->rdev, &chp->cq, !ucontext)) { - cxfree(chp); - return ERR_PTR(-ENOMEM); - } - chp->rhp = rhp; - chp->ibcq.cqe = 1 << chp->cq.size_log2; - mtx_init(&chp->lock, "cxgb cq", NULL, MTX_DEF|MTX_DUPOK); - chp->refcnt = 1; - if (insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid)) { - cxio_destroy_cq(&chp->rhp->rdev, &chp->cq); - cxfree(chp); - return ERR_PTR(-ENOMEM); - } - - if (ucontext) { - struct iwch_mm_entry *mm; - - mm = kmalloc(sizeof *mm, M_NOWAIT); - if (!mm) { - iwch_destroy_cq(&chp->ibcq); - return ERR_PTR(-ENOMEM); - } - uresp.cqid = chp->cq.cqid; - uresp.size_log2 = chp->cq.size_log2; - mtx_lock(&ucontext->mmap_lock); - uresp.key = ucontext->key; - ucontext->key += PAGE_SIZE; - mtx_unlock(&ucontext->mmap_lock); - mm->key = uresp.key; - mm->addr = vtophys(chp->cq.queue); - if (udata->outlen < sizeof uresp) { - if (!warned++) - CTR1(KTR_IW_CXGB, "%s Warning - " - "downlevel libcxgb3 (non-fatal).\n", - __func__); - mm->len = PAGE_ALIGN((1UL << uresp.size_log2) * - sizeof(struct t3_cqe)); - resplen = sizeof(struct iwch_create_cq_resp_v0); - } else { - mm->len = PAGE_ALIGN(((1UL << uresp.size_log2) + 1) * - sizeof(struct t3_cqe)); - uresp.memsize = mm->len; - resplen = sizeof uresp; - } - if (ib_copy_to_udata(udata, &uresp, resplen)) { - cxfree(mm); - iwch_destroy_cq(&chp->ibcq); - return ERR_PTR(-EFAULT); - } - insert_mmap(ucontext, mm); - } - CTR4(KTR_IW_CXGB, "created cqid 0x%0x chp %p size 0x%0x, dma_addr 0x%0llx", - chp->cq.cqid, chp, (1 << chp->cq.size_log2), - (unsigned long long) chp->cq.dma_addr); - return &chp->ibcq; -} - -static int -iwch_resize_cq(struct ib_cq *cq __unused, int cqe __unused, - struct ib_udata *udata __unused) -{ - - return (-ENOSYS); -} - -static int -iwch_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags) -{ - struct iwch_dev *rhp; - struct iwch_cq *chp; - enum t3_cq_opcode cq_op; - int err; - u32 rptr; - - chp = to_iwch_cq(ibcq); - rhp = chp->rhp; - if ((flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED) - cq_op = CQ_ARM_SE; - else - cq_op = CQ_ARM_AN; - if (chp->user_rptr_addr) { - if (copyin(chp->user_rptr_addr, &rptr, sizeof(rptr))) - return (-EFAULT); - mtx_lock(&chp->lock); - chp->cq.rptr = rptr; - } else - mtx_lock(&chp->lock); - CTR2(KTR_IW_CXGB, "%s rptr 0x%x", __FUNCTION__, chp->cq.rptr); - err = cxio_hal_cq_op(&rhp->rdev, &chp->cq, cq_op, 0); - mtx_unlock(&chp->lock); - if (err < 0) - log(LOG_ERR, "Error %d rearming CQID 0x%x\n", err, - chp->cq.cqid); - if (err > 0 && !(flags & IB_CQ_REPORT_MISSED_EVENTS)) - err = 0; - return err; -} - -static int -iwch_mmap(struct ib_ucontext *context __unused, struct vm_area_struct *vma __unused) -{ - - return (-ENOSYS); -} - -static int iwch_deallocate_pd(struct ib_pd *pd) -{ - struct iwch_dev *rhp; - struct iwch_pd *php; - - php = to_iwch_pd(pd); - rhp = php->rhp; - CTR3(KTR_IW_CXGB, "%s ibpd %p pdid 0x%x", __FUNCTION__, pd, php->pdid); - cxio_hal_put_pdid(rhp->rdev.rscp, php->pdid); - cxfree(php); - return 0; -} - -static struct ib_pd *iwch_allocate_pd(struct ib_device *ibdev, - struct ib_ucontext *context, - struct ib_udata *udata) -{ - struct iwch_pd *php; - u32 pdid; - struct iwch_dev *rhp; - - CTR2(KTR_IW_CXGB, "%s ibdev %p", __FUNCTION__, ibdev); - rhp = (struct iwch_dev *) ibdev; - pdid = cxio_hal_get_pdid(rhp->rdev.rscp); - if (!pdid) - return ERR_PTR(-EINVAL); - php = malloc(sizeof(*php), M_DEVBUF, M_ZERO|M_NOWAIT); - if (!php) { - cxio_hal_put_pdid(rhp->rdev.rscp, pdid); - return ERR_PTR(-ENOMEM); - } - php->pdid = pdid; - php->rhp = rhp; - if (context) { - if (ib_copy_to_udata(udata, &php->pdid, sizeof (__u32))) { - iwch_deallocate_pd(&php->ibpd); - return ERR_PTR(-EFAULT); - } - } - CTR3(KTR_IW_CXGB, "%s pdid 0x%0x ptr 0x%p", __FUNCTION__, pdid, php); - return &php->ibpd; -} - -static int iwch_dereg_mr(struct ib_mr *ib_mr) -{ - struct iwch_dev *rhp; - struct iwch_mr *mhp; - u32 mmid; - - CTR2(KTR_IW_CXGB, "%s ib_mr %p", __FUNCTION__, ib_mr); - /* There can be no memory windows */ - if (atomic_load_acq_int(&ib_mr->usecnt.counter)) - return (-EINVAL); - - mhp = to_iwch_mr(ib_mr); - rhp = mhp->rhp; - mmid = mhp->attr.stag >> 8; - cxio_dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size, - mhp->attr.pbl_addr); - iwch_free_pbl(mhp); - remove_handle(rhp, &rhp->mmidr, mmid); - if (mhp->kva) - cxfree((void *) (unsigned long) mhp->kva); - if (mhp->umem) - ib_umem_release(mhp->umem); - CTR3(KTR_IW_CXGB, "%s mmid 0x%x ptr %p", __FUNCTION__, mmid, mhp); - cxfree(mhp); - return 0; -} - -static struct ib_mr *iwch_register_phys_mem(struct ib_pd *pd, - struct ib_phys_buf *buffer_list, - int num_phys_buf, - int acc, - u64 *iova_start) -{ - __be64 *page_list; - int shift; - u64 total_size; - int npages; - struct iwch_dev *rhp; - struct iwch_pd *php; - struct iwch_mr *mhp; - int ret; - - CTR2(KTR_IW_CXGB, "%s ib_pd %p", __FUNCTION__, pd); - php = to_iwch_pd(pd); - rhp = php->rhp; - - mhp = malloc(sizeof(*mhp), M_DEVBUF, M_ZERO|M_NOWAIT); - if (!mhp) - return ERR_PTR(-ENOMEM); - - mhp->rhp = rhp; - - /* First check that we have enough alignment */ - if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) { - ret = -EINVAL; - goto err; - } - - if (num_phys_buf > 1 && - ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK)) { - ret = -EINVAL; - goto err; - } - - ret = build_phys_page_list(buffer_list, num_phys_buf, iova_start, - &total_size, &npages, &shift, &page_list); - if (ret) - goto err; - - ret = iwch_alloc_pbl(mhp, npages); - if (ret) { - cxfree(page_list); - goto err_pbl; - } - - ret = iwch_write_pbl(mhp, page_list, npages, 0); - cxfree(page_list); - if (ret) - goto err; - - mhp->attr.pdid = php->pdid; - mhp->attr.zbva = 0; - - mhp->attr.perms = iwch_ib_to_tpt_access(acc); - mhp->attr.va_fbo = *iova_start; - mhp->attr.page_size = shift - 12; - - mhp->attr.len = (u32) total_size; - mhp->attr.pbl_size = npages; - ret = iwch_register_mem(rhp, php, mhp, shift); - if (ret) - goto err_pbl; - - return &mhp->ibmr; - -err_pbl: - iwch_free_pbl(mhp); - -err: - cxfree(mhp); - return ERR_PTR(ret); - -} - -static int iwch_reregister_phys_mem(struct ib_mr *mr, - int mr_rereg_mask, - struct ib_pd *pd, - struct ib_phys_buf *buffer_list, - int num_phys_buf, - int acc, u64 * iova_start) -{ - - struct iwch_mr mh, *mhp; - struct iwch_pd *php; - struct iwch_dev *rhp; - __be64 *page_list = NULL; - int shift = 0; - u64 total_size; - int npages = 0; - int ret; - - CTR3(KTR_IW_CXGB, "%s ib_mr %p ib_pd %p", __FUNCTION__, mr, pd); - - /* There can be no memory windows */ - if (atomic_load_acq_int(&mr->usecnt.counter)) - return (-EINVAL); - - mhp = to_iwch_mr(mr); - rhp = mhp->rhp; - php = to_iwch_pd(mr->pd); - - /* make sure we are on the same adapter */ - if (rhp != php->rhp) - return (-EINVAL); - - memcpy(&mh, mhp, sizeof *mhp); - - if (mr_rereg_mask & IB_MR_REREG_PD) - php = to_iwch_pd(pd); - if (mr_rereg_mask & IB_MR_REREG_ACCESS) - mh.attr.perms = iwch_ib_to_tpt_access(acc); - if (mr_rereg_mask & IB_MR_REREG_TRANS) { - ret = build_phys_page_list(buffer_list, num_phys_buf, - iova_start, - &total_size, &npages, - &shift, &page_list); - if (ret) - return ret; - } - - ret = iwch_reregister_mem(rhp, php, &mh, shift, npages); - cxfree(page_list); - if (ret) { - return ret; - } - if (mr_rereg_mask & IB_MR_REREG_PD) - mhp->attr.pdid = php->pdid; - if (mr_rereg_mask & IB_MR_REREG_ACCESS) - mhp->attr.perms = iwch_ib_to_tpt_access(acc); - if (mr_rereg_mask & IB_MR_REREG_TRANS) { - mhp->attr.zbva = 0; - mhp->attr.va_fbo = *iova_start; - mhp->attr.page_size = shift - 12; - mhp->attr.len = (u32) total_size; - mhp->attr.pbl_size = npages; - } - - return 0; -} - - -static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, - u64 virt, int acc, struct ib_udata *udata, - int mr_id) -{ - __be64 *pages; - int shift, n, len; - int i, k, entry; - int err = 0; - struct iwch_dev *rhp; - struct iwch_pd *php; - struct iwch_mr *mhp; - struct iwch_reg_user_mr_resp uresp; - struct scatterlist *sg; - - CTR2(KTR_IW_CXGB, "%s ib_pd %p", __FUNCTION__, pd); - - php = to_iwch_pd(pd); - rhp = php->rhp; - mhp = malloc(sizeof(*mhp), M_DEVBUF, M_NOWAIT|M_ZERO); - if (!mhp) - return ERR_PTR(-ENOMEM); - - mhp->rhp = rhp; - - mhp->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0); - if (IS_ERR(mhp->umem)) { - err = PTR_ERR(mhp->umem); - cxfree(mhp); - return ERR_PTR(-err); - } - - shift = ffs(mhp->umem->page_size) - 1; - - n = mhp->umem->nmap; - - err = iwch_alloc_pbl(mhp, n); - if (err) - goto err; - - pages = (__be64 *) kmalloc(n * sizeof(u64), M_NOWAIT); - if (!pages) { - err = -ENOMEM; - goto err_pbl; - } - - i = n = 0; - - for_each_sg(mhp->umem->sg_head.sgl, sg, mhp->umem->nmap, entry) { - len = sg_dma_len(sg) >> shift; - for (k = 0; k < len; ++k) { - pages[i++] = cpu_to_be64(sg_dma_address(sg) + - mhp->umem->page_size * k); - if (i == PAGE_SIZE / sizeof *pages) { - err = iwch_write_pbl(mhp, pages, i, n); - if (err) - goto pbl_done; - n += i; - i = 0; - } - } - } -#if 0 - TAILQ_FOREACH(chunk, &mhp->umem->chunk_list, entry) - for (j = 0; j < chunk->nmap; ++j) { - len = sg_dma_len(&chunk->page_list[j]) >> shift; - for (k = 0; k < len; ++k) { - pages[i++] = htobe64(sg_dma_address( - &chunk->page_list[j]) + - mhp->umem->page_size * k); - if (i == PAGE_SIZE / sizeof *pages) { - err = iwch_write_pbl(mhp, pages, i, n); - if (err) - goto pbl_done; - n += i; - i = 0; - } - } - } -#endif - - if (i) - err = iwch_write_pbl(mhp, pages, i, n); -pbl_done: - cxfree(pages); - if (err) - goto err_pbl; - - mhp->attr.pdid = php->pdid; - mhp->attr.zbva = 0; - mhp->attr.perms = iwch_ib_to_tpt_access(acc); - mhp->attr.va_fbo = virt; - mhp->attr.page_size = shift - 12; - mhp->attr.len = (u32) length; - - err = iwch_register_mem(rhp, php, mhp, shift); - if (err) - goto err_pbl; - - if (udata && !t3a_device(rhp)) { - uresp.pbl_addr = (mhp->attr.pbl_addr - - rhp->rdev.rnic_info.pbl_base) >> 3; - CTR2(KTR_IW_CXGB, "%s user resp pbl_addr 0x%x", __FUNCTION__, - uresp.pbl_addr); - - if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) { - iwch_dereg_mr(&mhp->ibmr); - err = EFAULT; - goto err; - } - } - - return &mhp->ibmr; - -err_pbl: - iwch_free_pbl(mhp); - -err: - ib_umem_release(mhp->umem); - cxfree(mhp); - return ERR_PTR(-err); -} - -static struct ib_mr *iwch_get_dma_mr(struct ib_pd *pd, int acc) -{ - struct ib_phys_buf bl; - u64 kva; - struct ib_mr *ibmr; - - CTR2(KTR_IW_CXGB, "%s ib_pd %p", __FUNCTION__, pd); - - /* - * T3 only supports 32 bits of size. - */ - bl.size = 0xffffffff; - bl.addr = 0; - kva = 0; - ibmr = iwch_register_phys_mem(pd, &bl, 1, acc, &kva); - return ibmr; -} - -static struct ib_mw *iwch_alloc_mw(struct ib_pd *pd, enum ib_mw_type type) -{ - struct iwch_dev *rhp; - struct iwch_pd *php; - struct iwch_mw *mhp; - u32 mmid; - u32 stag = 0; - int ret; - - php = to_iwch_pd(pd); - rhp = php->rhp; - mhp = malloc(sizeof(*mhp), M_DEVBUF, M_ZERO|M_NOWAIT); - if (!mhp) - return ERR_PTR(-ENOMEM); - ret = cxio_allocate_window(&rhp->rdev, &stag, php->pdid); - if (ret) { - cxfree(mhp); - return ERR_PTR(-ret); - } - mhp->rhp = rhp; - mhp->attr.pdid = php->pdid; - mhp->attr.type = TPT_MW; - mhp->attr.stag = stag; - mmid = (stag) >> 8; - mhp->ibmw.rkey = stag; - if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) { - cxio_deallocate_window(&rhp->rdev, mhp->attr.stag); - cxfree(mhp); - return ERR_PTR(-ENOMEM); - } - CTR4(KTR_IW_CXGB, "%s mmid 0x%x mhp %p stag 0x%x", __FUNCTION__, mmid, mhp, stag); - return &(mhp->ibmw); -} - -static int iwch_dealloc_mw(struct ib_mw *mw) -{ - struct iwch_dev *rhp; - struct iwch_mw *mhp; - u32 mmid; - - mhp = to_iwch_mw(mw); - rhp = mhp->rhp; - mmid = (mw->rkey) >> 8; - cxio_deallocate_window(&rhp->rdev, mhp->attr.stag); - remove_handle(rhp, &rhp->mmidr, mmid); - cxfree(mhp); - CTR4(KTR_IW_CXGB, "%s ib_mw %p mmid 0x%x ptr %p", __FUNCTION__, mw, mmid, mhp); - return 0; -} - -static int iwch_destroy_qp(struct ib_qp *ib_qp) -{ - struct iwch_dev *rhp; - struct iwch_qp *qhp; - struct iwch_qp_attributes attrs; - struct iwch_ucontext *ucontext; - - qhp = to_iwch_qp(ib_qp); - rhp = qhp->rhp; - - attrs.next_state = IWCH_QP_STATE_ERROR; - iwch_modify_qp(rhp, qhp, IWCH_QP_ATTR_NEXT_STATE, &attrs, 0); - mtx_lock(&qhp->lock); - if (qhp->ep) - msleep(qhp, &qhp->lock, 0, "iwch_destroy_qp1", 0); - mtx_unlock(&qhp->lock); - - remove_handle(rhp, &rhp->qpidr, qhp->wq.qpid); - - mtx_lock(&qhp->lock); - if (--qhp->refcnt) - msleep(qhp, &qhp->lock, 0, "iwch_destroy_qp2", 0); - mtx_unlock(&qhp->lock); - - ucontext = ib_qp->uobject ? to_iwch_ucontext(ib_qp->uobject->context) - : NULL; - cxio_destroy_qp(&rhp->rdev, &qhp->wq, - ucontext ? &ucontext->uctx : &rhp->rdev.uctx); - - CTR4(KTR_IW_CXGB, "%s ib_qp %p qpid 0x%0x qhp %p", __FUNCTION__, - ib_qp, qhp->wq.qpid, qhp); - cxfree(qhp); - return 0; -} - -static struct ib_qp *iwch_create_qp(struct ib_pd *pd, - struct ib_qp_init_attr *attrs, - struct ib_udata *udata) -{ - struct iwch_dev *rhp; - struct iwch_qp *qhp; - struct iwch_pd *php; - struct iwch_cq *schp; - struct iwch_cq *rchp; - struct iwch_create_qp_resp uresp; - int wqsize, sqsize, rqsize; - struct iwch_ucontext *ucontext; - - CTR2(KTR_IW_CXGB, "%s ib_pd %p", __FUNCTION__, pd); - if (attrs->qp_type != IB_QPT_RC) - return ERR_PTR(-EINVAL); - php = to_iwch_pd(pd); - rhp = php->rhp; - schp = get_chp(rhp, ((struct iwch_cq *) attrs->send_cq)->cq.cqid); - rchp = get_chp(rhp, ((struct iwch_cq *) attrs->recv_cq)->cq.cqid); - if (!schp || !rchp) - return ERR_PTR(-EINVAL); - - /* The RQT size must be # of entries + 1 rounded up to a power of two */ - rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr); - if (rqsize == attrs->cap.max_recv_wr) - rqsize = roundup_pow_of_two(attrs->cap.max_recv_wr+1); - - /* T3 doesn't support RQT depth < 16 */ - if (rqsize < 16) - rqsize = 16; - - if (rqsize > T3_MAX_RQ_SIZE) - return ERR_PTR(-EINVAL); - - if (attrs->cap.max_inline_data > T3_MAX_INLINE) - return ERR_PTR(-EINVAL); - - /* - * NOTE: The SQ and total WQ sizes don't need to be - * a power of two. However, all the code assumes - * they are. EG: Q_FREECNT() and friends. - */ - sqsize = roundup_pow_of_two(attrs->cap.max_send_wr); - wqsize = roundup_pow_of_two(rqsize + sqsize); - CTR4(KTR_IW_CXGB, "%s wqsize %d sqsize %d rqsize %d", __FUNCTION__, - wqsize, sqsize, rqsize); - qhp = malloc(sizeof(*qhp), M_DEVBUF, M_ZERO|M_NOWAIT); - if (!qhp) - return ERR_PTR(-ENOMEM); - qhp->wq.size_log2 = ilog2(wqsize); - qhp->wq.rq_size_log2 = ilog2(rqsize); - qhp->wq.sq_size_log2 = ilog2(sqsize); - ucontext = pd->uobject ? to_iwch_ucontext(pd->uobject->context) : NULL; - if (cxio_create_qp(&rhp->rdev, !udata, &qhp->wq, - ucontext ? &ucontext->uctx : &rhp->rdev.uctx)) { - cxfree(qhp); - return ERR_PTR(-ENOMEM); - } - - attrs->cap.max_recv_wr = rqsize - 1; - attrs->cap.max_send_wr = sqsize; - attrs->cap.max_inline_data = T3_MAX_INLINE; - - qhp->rhp = rhp; - qhp->attr.pd = php->pdid; - qhp->attr.scq = ((struct iwch_cq *) attrs->send_cq)->cq.cqid; - qhp->attr.rcq = ((struct iwch_cq *) attrs->recv_cq)->cq.cqid; - qhp->attr.sq_num_entries = attrs->cap.max_send_wr; - qhp->attr.rq_num_entries = attrs->cap.max_recv_wr; - qhp->attr.sq_max_sges = attrs->cap.max_send_sge; - qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge; - qhp->attr.rq_max_sges = attrs->cap.max_recv_sge; - qhp->attr.state = IWCH_QP_STATE_IDLE; - qhp->attr.next_state = IWCH_QP_STATE_IDLE; - - /* - * XXX - These don't get passed in from the openib user - * at create time. The CM sets them via a QP modify. - * Need to fix... I think the CM should - */ - qhp->attr.enable_rdma_read = 1; - qhp->attr.enable_rdma_write = 1; - qhp->attr.enable_bind = 1; - qhp->attr.max_ord = 1; - qhp->attr.max_ird = 1; - - mtx_init(&qhp->lock, "cxgb qp", NULL, MTX_DEF|MTX_DUPOK); - qhp->refcnt = 1; - - if (insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.qpid)) { - cxio_destroy_qp(&rhp->rdev, &qhp->wq, - ucontext ? &ucontext->uctx : &rhp->rdev.uctx); - cxfree(qhp); - return ERR_PTR(-ENOMEM); - } - - if (udata) { - - struct iwch_mm_entry *mm1, *mm2; - - mm1 = kmalloc(sizeof *mm1, M_NOWAIT); - if (!mm1) { - iwch_destroy_qp(&qhp->ibqp); - return ERR_PTR(-ENOMEM); - } - - mm2 = kmalloc(sizeof *mm2, M_NOWAIT); - if (!mm2) { - cxfree(mm1); - iwch_destroy_qp(&qhp->ibqp); - return ERR_PTR(-ENOMEM); - } - - uresp.qpid = qhp->wq.qpid; - uresp.size_log2 = qhp->wq.size_log2; - uresp.sq_size_log2 = qhp->wq.sq_size_log2; - uresp.rq_size_log2 = qhp->wq.rq_size_log2; - mtx_lock(&ucontext->mmap_lock); - uresp.key = ucontext->key; - ucontext->key += PAGE_SIZE; - uresp.db_key = ucontext->key; - ucontext->key += PAGE_SIZE; - mtx_unlock(&ucontext->mmap_lock); - if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) { - cxfree(mm1); - cxfree(mm2); - iwch_destroy_qp(&qhp->ibqp); - return ERR_PTR(-EFAULT); - } - mm1->key = uresp.key; - mm1->addr = vtophys(qhp->wq.queue); - mm1->len = PAGE_ALIGN(wqsize * sizeof (union t3_wr)); - insert_mmap(ucontext, mm1); - mm2->key = uresp.db_key; - mm2->addr = qhp->wq.udb & PAGE_MASK; - mm2->len = PAGE_SIZE; - insert_mmap(ucontext, mm2); - } - qhp->ibqp.qp_num = qhp->wq.qpid; - callout_init(&(qhp->timer), 1); - CTR6(KTR_IW_CXGB, "sq_num_entries %d, rq_num_entries %d " - "qpid 0x%0x qhp %p dma_addr 0x%llx size %d", - qhp->attr.sq_num_entries, qhp->attr.rq_num_entries, - qhp->wq.qpid, qhp, (unsigned long long) qhp->wq.dma_addr, - 1 << qhp->wq.size_log2); - return &qhp->ibqp; -} - -static int iwch_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, - int attr_mask, struct ib_udata *udata) -{ - struct iwch_dev *rhp; - struct iwch_qp *qhp; - enum iwch_qp_attr_mask mask = 0; - struct iwch_qp_attributes attrs; - - CTR2(KTR_IW_CXGB, "%s ib_qp %p", __FUNCTION__, ibqp); - - /* iwarp does not support the RTR state */ - if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR)) - attr_mask &= ~IB_QP_STATE; - - /* Make sure we still have something left to do */ - if (!attr_mask) - return 0; - - memset(&attrs, 0, sizeof attrs); - qhp = to_iwch_qp(ibqp); - rhp = qhp->rhp; - - attrs.next_state = iwch_convert_state(attr->qp_state); - attrs.enable_rdma_read = (attr->qp_access_flags & - IB_ACCESS_REMOTE_READ) ? 1 : 0; - attrs.enable_rdma_write = (attr->qp_access_flags & - IB_ACCESS_REMOTE_WRITE) ? 1 : 0; - attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0; - - - mask |= (attr_mask & IB_QP_STATE) ? IWCH_QP_ATTR_NEXT_STATE : 0; - mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ? - (IWCH_QP_ATTR_ENABLE_RDMA_READ | - IWCH_QP_ATTR_ENABLE_RDMA_WRITE | - IWCH_QP_ATTR_ENABLE_RDMA_BIND) : 0; - - return iwch_modify_qp(rhp, qhp, mask, &attrs, 0); -} - -void iwch_qp_add_ref(struct ib_qp *qp) -{ - CTR2(KTR_IW_CXGB, "%s ib_qp %p", __FUNCTION__, qp); - mtx_lock(&to_iwch_qp(qp)->lock); - to_iwch_qp(qp)->refcnt++; - mtx_unlock(&to_iwch_qp(qp)->lock); -} - -void iwch_qp_rem_ref(struct ib_qp *qp) -{ - CTR2(KTR_IW_CXGB, "%s ib_qp %p", __FUNCTION__, qp); - mtx_lock(&to_iwch_qp(qp)->lock); - if (--to_iwch_qp(qp)->refcnt == 0) - wakeup(to_iwch_qp(qp)); - mtx_unlock(&to_iwch_qp(qp)->lock); -} - -static struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn) -{ - CTR3(KTR_IW_CXGB, "%s ib_dev %p qpn 0x%x", __FUNCTION__, dev, qpn); - return (struct ib_qp *)get_qhp(to_iwch_dev(dev), qpn); -} - - -static int iwch_query_pkey(struct ib_device *ibdev, - u8 port, u16 index, u16 * pkey) -{ - CTR2(KTR_IW_CXGB, "%s ibdev %p", __FUNCTION__, ibdev); - *pkey = 0; - return 0; -} - -static int iwch_query_gid(struct ib_device *ibdev, u8 port, - int index, union ib_gid *gid) -{ - struct iwch_dev *dev; - struct port_info *pi; - struct adapter *sc; - - CTR5(KTR_IW_CXGB, "%s ibdev %p, port %d, index %d, gid %p", - __FUNCTION__, ibdev, port, index, gid); - dev = to_iwch_dev(ibdev); - sc = dev->rdev.adap; - PANIC_IF(port == 0 || port > 2); - pi = &sc->port[port - 1]; - memset(&(gid->raw[0]), 0, sizeof(gid->raw)); - memcpy(&(gid->raw[0]), pi->hw_addr, 6); - return 0; -} - -static int iwch_query_device(struct ib_device *ibdev, - struct ib_device_attr *props) -{ - struct iwch_dev *dev; - struct adapter *sc; - - CTR2(KTR_IW_CXGB, "%s ibdev %p", __FUNCTION__, ibdev); - - dev = to_iwch_dev(ibdev); - sc = dev->rdev.adap; - memset(props, 0, sizeof *props); - memcpy(&props->sys_image_guid, sc->port[0].hw_addr, 6); - props->device_cap_flags = dev->device_cap_flags; - props->page_size_cap = dev->attr.mem_pgsizes_bitmask; - props->vendor_id = pci_get_vendor(sc->dev); - props->vendor_part_id = pci_get_device(sc->dev); - props->max_mr_size = dev->attr.max_mr_size; - props->max_qp = dev->attr.max_qps; - props->max_qp_wr = dev->attr.max_wrs; - props->max_sge = dev->attr.max_sge_per_wr; - props->max_sge_rd = 1; - props->max_qp_rd_atom = dev->attr.max_rdma_reads_per_qp; - props->max_qp_init_rd_atom = dev->attr.max_rdma_reads_per_qp; - props->max_cq = dev->attr.max_cqs; - props->max_cqe = dev->attr.max_cqes_per_cq; - props->max_mr = dev->attr.max_mem_regs; - props->max_pd = dev->attr.max_pds; - props->local_ca_ack_delay = 0; - - return 0; -} - -static int iwch_query_port(struct ib_device *ibdev, - u8 port, struct ib_port_attr *props) -{ - CTR2(KTR_IW_CXGB, "%s ibdev %p", __FUNCTION__, ibdev); - memset(props, 0, sizeof(struct ib_port_attr)); - props->max_mtu = IB_MTU_4096; - props->active_mtu = IB_MTU_2048; - props->state = IB_PORT_ACTIVE; - props->port_cap_flags = - IB_PORT_CM_SUP | - IB_PORT_SNMP_TUNNEL_SUP | - IB_PORT_REINIT_SUP | - IB_PORT_DEVICE_MGMT_SUP | - IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; - props->gid_tbl_len = 1; - props->pkey_tbl_len = 1; - props->active_width = 2; - props->active_speed = 2; - props->max_msg_sz = -1; - - return 0; -} - -int iwch_register_device(struct iwch_dev *dev) -{ - int ret; - struct adapter *sc = dev->rdev.adap; - - CTR2(KTR_IW_CXGB, "%s iwch_dev %p", __FUNCTION__, dev); - strlcpy(dev->ibdev.name, "cxgb3_%d", IB_DEVICE_NAME_MAX); - memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); - memcpy(&dev->ibdev.node_guid, sc->port[0].hw_addr, 6); - dev->device_cap_flags = - (IB_DEVICE_LOCAL_DMA_LKEY | - IB_DEVICE_MEM_WINDOW); - - dev->ibdev.uverbs_cmd_mask = - (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | - (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | - (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | - (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | - (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | - (1ull << IB_USER_VERBS_CMD_REG_MR) | - (1ull << IB_USER_VERBS_CMD_DEREG_MR) | - (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | - (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | - (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | - (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | - (1ull << IB_USER_VERBS_CMD_CREATE_QP) | - (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | - (1ull << IB_USER_VERBS_CMD_POLL_CQ) | - (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | - (1ull << IB_USER_VERBS_CMD_POST_SEND) | - (1ull << IB_USER_VERBS_CMD_POST_RECV); - dev->ibdev.node_type = RDMA_NODE_RNIC; - memcpy(dev->ibdev.node_desc, IWCH_NODE_DESC, sizeof(IWCH_NODE_DESC)); - dev->ibdev.phys_port_cnt = sc->params.nports; - dev->ibdev.num_comp_vectors = 1; - dev->ibdev.dma_device = NULL; - dev->ibdev.query_device = iwch_query_device; - dev->ibdev.query_port = iwch_query_port; - dev->ibdev.modify_port = iwch_modify_port; - dev->ibdev.query_pkey = iwch_query_pkey; - dev->ibdev.query_gid = iwch_query_gid; - dev->ibdev.alloc_ucontext = iwch_alloc_ucontext; - dev->ibdev.dealloc_ucontext = iwch_dealloc_ucontext; - dev->ibdev.mmap = iwch_mmap; - dev->ibdev.alloc_pd = iwch_allocate_pd; - dev->ibdev.dealloc_pd = iwch_deallocate_pd; - dev->ibdev.create_ah = iwch_ah_create; - dev->ibdev.destroy_ah = iwch_ah_destroy; - dev->ibdev.create_qp = iwch_create_qp; - dev->ibdev.modify_qp = iwch_ib_modify_qp; - dev->ibdev.destroy_qp = iwch_destroy_qp; - dev->ibdev.create_cq = iwch_create_cq; - dev->ibdev.destroy_cq = iwch_destroy_cq; - dev->ibdev.resize_cq = iwch_resize_cq; - dev->ibdev.poll_cq = iwch_poll_cq; - dev->ibdev.get_dma_mr = iwch_get_dma_mr; - dev->ibdev.reg_phys_mr = iwch_register_phys_mem; - dev->ibdev.rereg_phys_mr = iwch_reregister_phys_mem; - dev->ibdev.reg_user_mr = iwch_reg_user_mr; - dev->ibdev.dereg_mr = iwch_dereg_mr; - dev->ibdev.alloc_mw = iwch_alloc_mw; - dev->ibdev.bind_mw = iwch_bind_mw; - dev->ibdev.dealloc_mw = iwch_dealloc_mw; - - dev->ibdev.attach_mcast = iwch_multicast_attach; - dev->ibdev.detach_mcast = iwch_multicast_detach; - dev->ibdev.process_mad = iwch_process_mad; - - dev->ibdev.req_notify_cq = iwch_arm_cq; - dev->ibdev.post_send = iwch_post_send; - dev->ibdev.post_recv = iwch_post_receive; - dev->ibdev.uverbs_abi_ver = IWCH_UVERBS_ABI_VERSION; - - dev->ibdev.iwcm = - kmalloc(sizeof(struct iw_cm_verbs), M_NOWAIT); - if (!dev->ibdev.iwcm) - return (ENOMEM); - - dev->ibdev.iwcm->connect = iwch_connect; - dev->ibdev.iwcm->accept = iwch_accept_cr; - dev->ibdev.iwcm->reject = iwch_reject_cr; - dev->ibdev.iwcm->create_listen_ep = iwch_create_listen_ep; - dev->ibdev.iwcm->destroy_listen_ep = iwch_destroy_listen_ep; - dev->ibdev.iwcm->newconn = process_newconn; - dev->ibdev.iwcm->add_ref = iwch_qp_add_ref; - dev->ibdev.iwcm->rem_ref = iwch_qp_rem_ref; - dev->ibdev.iwcm->get_qp = iwch_get_qp; - - ret = ib_register_device(&dev->ibdev, NULL); - if (ret) - goto bail1; - - return (0); - -bail1: - cxfree(dev->ibdev.iwcm); - return (ret); -} - -void iwch_unregister_device(struct iwch_dev *dev) -{ - - ib_unregister_device(&dev->ibdev); - cxfree(dev->ibdev.iwcm); - return; -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.h deleted file mode 100644 index 2e012fd28342..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_provider.h +++ /dev/null @@ -1,362 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ -#ifndef __IWCH_PROVIDER_H__ -#define __IWCH_PROVIDER_H__ - -#include - -struct iwch_pd { - struct ib_pd ibpd; - u32 pdid; - struct iwch_dev *rhp; -}; - -#ifndef container_of -#define container_of(p, stype, field) ((stype *)(((uint8_t *)(p)) - offsetof(stype, field))) -#endif -static __inline struct iwch_pd * -to_iwch_pd(struct ib_pd *ibpd) -{ - return container_of(ibpd, struct iwch_pd, ibpd); -} - -struct tpt_attributes { - u32 stag; - u32 state:1; - u32 type:2; - u32 rsvd:1; - enum tpt_mem_perm perms; - u32 remote_invaliate_disable:1; - u32 zbva:1; - u32 mw_bind_enable:1; - u32 page_size:5; - - u32 pdid; - u32 qpid; - u32 pbl_addr; - u32 len; - u64 va_fbo; - u32 pbl_size; -}; - -struct iwch_mr { - struct ib_mr ibmr; - struct ib_umem *umem; - struct iwch_dev *rhp; - u64 kva; - struct tpt_attributes attr; -}; - -typedef struct iwch_mw iwch_mw_handle; - -static __inline struct iwch_mr * -to_iwch_mr(struct ib_mr *ibmr) -{ - return container_of(ibmr, struct iwch_mr, ibmr); -} - -struct iwch_mw { - struct ib_mw ibmw; - struct iwch_dev *rhp; - u64 kva; - struct tpt_attributes attr; -}; - -static __inline struct iwch_mw * -to_iwch_mw(struct ib_mw *ibmw) -{ - return container_of(ibmw, struct iwch_mw, ibmw); -} - -struct iwch_cq { - struct ib_cq ibcq; - struct iwch_dev *rhp; - struct t3_cq cq; - struct mtx lock; - int refcnt; - u32 /* __user */ *user_rptr_addr; -}; - -static __inline struct iwch_cq * -to_iwch_cq(struct ib_cq *ibcq) -{ - return container_of(ibcq, struct iwch_cq, ibcq); -} - -enum IWCH_QP_FLAGS { - QP_QUIESCED = 0x01 -}; - -struct iwch_mpa_attributes { - u8 initiator; - u8 recv_marker_enabled; - u8 xmit_marker_enabled; /* iWARP: enable inbound Read Resp. */ - u8 crc_enabled; - u8 version; /* 0 or 1 */ -}; - -struct iwch_qp_attributes { - u32 scq; - u32 rcq; - u32 sq_num_entries; - u32 rq_num_entries; - u32 sq_max_sges; - u32 sq_max_sges_rdma_write; - u32 rq_max_sges; - u32 state; - u8 enable_rdma_read; - u8 enable_rdma_write; /* enable inbound Read Resp. */ - u8 enable_bind; - u8 enable_mmid0_fastreg; /* Enable STAG0 + Fast-register */ - /* - * Next QP state. If specify the current state, only the - * QP attributes will be modified. - */ - u32 max_ord; - u32 max_ird; - u32 pd; /* IN */ - u32 next_state; - char terminate_buffer[52]; - u32 terminate_msg_len; - u8 is_terminate_local; - struct iwch_mpa_attributes mpa_attr; /* IN-OUT */ - struct iwch_ep *llp_stream_handle; - char *stream_msg_buf; /* Last stream msg. before Idle -> RTS */ - u32 stream_msg_buf_len; /* Only on Idle -> RTS */ -}; - -struct iwch_qp { - struct ib_qp ibqp; - struct iwch_dev *rhp; - struct iwch_ep *ep; - struct iwch_qp_attributes attr; - struct t3_wq wq; - struct mtx lock; - int refcnt; - enum IWCH_QP_FLAGS flags; - struct callout timer; -}; - -static __inline int -qp_quiesced(struct iwch_qp *qhp) -{ - return qhp->flags & QP_QUIESCED; -} - -static __inline struct iwch_qp * -to_iwch_qp(struct ib_qp *ibqp) -{ - return container_of(ibqp, struct iwch_qp, ibqp); -} - -void iwch_qp_add_ref(struct ib_qp *qp); -void iwch_qp_rem_ref(struct ib_qp *qp); - -struct iwch_ucontext { - struct ib_ucontext ibucontext; - struct cxio_ucontext uctx; - u32 key; - struct mtx mmap_lock; - TAILQ_HEAD( ,iwch_mm_entry) mmaps; -}; - -static __inline struct iwch_ucontext * -to_iwch_ucontext(struct ib_ucontext *c) -{ - return container_of(c, struct iwch_ucontext, ibucontext); -} - -struct iwch_mm_entry { - TAILQ_ENTRY(iwch_mm_entry) entry; - u64 addr; - u32 key; - unsigned len; -}; - -static __inline struct iwch_mm_entry * -remove_mmap(struct iwch_ucontext *ucontext, - u32 key, unsigned len) -{ - struct iwch_mm_entry *tmp, *mm; - - mtx_lock(&ucontext->mmap_lock); - TAILQ_FOREACH_SAFE(mm, &ucontext->mmaps, entry, tmp) { - if (mm->key == key && mm->len == len) { - TAILQ_REMOVE(&ucontext->mmaps, mm, entry); - mtx_unlock(&ucontext->mmap_lock); - CTR4(KTR_IW_CXGB, "%s key 0x%x addr 0x%llx len %d\n", __FUNCTION__, - key, (unsigned long long) mm->addr, mm->len); - return mm; - } - } - mtx_unlock(&ucontext->mmap_lock); - - return NULL; -} - -static __inline void -insert_mmap(struct iwch_ucontext *ucontext, - struct iwch_mm_entry *mm) -{ - mtx_lock(&ucontext->mmap_lock); - CTR4(KTR_IW_CXGB, "%s key 0x%x addr 0x%llx len %d\n", __FUNCTION__, - mm->key, (unsigned long long) mm->addr, mm->len); - TAILQ_INSERT_TAIL(&ucontext->mmaps, mm, entry); - mtx_unlock(&ucontext->mmap_lock); -} - -enum iwch_qp_attr_mask { - IWCH_QP_ATTR_NEXT_STATE = 1 << 0, - IWCH_QP_ATTR_ENABLE_RDMA_READ = 1 << 7, - IWCH_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8, - IWCH_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9, - IWCH_QP_ATTR_MAX_ORD = 1 << 11, - IWCH_QP_ATTR_MAX_IRD = 1 << 12, - IWCH_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22, - IWCH_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23, - IWCH_QP_ATTR_MPA_ATTR = 1 << 24, - IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25, - IWCH_QP_ATTR_VALID_MODIFY = (IWCH_QP_ATTR_ENABLE_RDMA_READ | - IWCH_QP_ATTR_ENABLE_RDMA_WRITE | - IWCH_QP_ATTR_MAX_ORD | - IWCH_QP_ATTR_MAX_IRD | - IWCH_QP_ATTR_LLP_STREAM_HANDLE | - IWCH_QP_ATTR_STREAM_MSG_BUFFER | - IWCH_QP_ATTR_MPA_ATTR | - IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE) -}; - -int iwch_modify_qp(struct iwch_dev *rhp, - struct iwch_qp *qhp, - enum iwch_qp_attr_mask mask, - struct iwch_qp_attributes *attrs, - int internal); - -enum iwch_qp_state { - IWCH_QP_STATE_IDLE, - IWCH_QP_STATE_RTS, - IWCH_QP_STATE_ERROR, - IWCH_QP_STATE_TERMINATE, - IWCH_QP_STATE_CLOSING, - IWCH_QP_STATE_TOT -}; - -static __inline int -iwch_convert_state(enum ib_qp_state ib_state) -{ - switch (ib_state) { - case IB_QPS_RESET: - case IB_QPS_INIT: - return IWCH_QP_STATE_IDLE; - case IB_QPS_RTS: - return IWCH_QP_STATE_RTS; - case IB_QPS_SQD: - return IWCH_QP_STATE_CLOSING; - case IB_QPS_SQE: - return IWCH_QP_STATE_TERMINATE; - case IB_QPS_ERR: - return IWCH_QP_STATE_ERROR; - default: - return -1; - } -} - -static __inline u32 -iwch_ib_to_tpt_access(int acc) -{ - return (acc & IB_ACCESS_REMOTE_WRITE ? TPT_REMOTE_WRITE : 0) | - (acc & IB_ACCESS_REMOTE_READ ? TPT_REMOTE_READ : 0) | - (acc & IB_ACCESS_LOCAL_WRITE ? TPT_LOCAL_WRITE : 0) | - TPT_LOCAL_READ; -} - -static __inline u32 -iwch_ib_to_mwbind_access(int acc) -{ - return (acc & IB_ACCESS_REMOTE_WRITE ? T3_MEM_ACCESS_REM_WRITE : 0) | - (acc & IB_ACCESS_REMOTE_READ ? T3_MEM_ACCESS_REM_READ : 0) | - (acc & IB_ACCESS_LOCAL_WRITE ? T3_MEM_ACCESS_LOCAL_WRITE : 0) | - T3_MEM_ACCESS_LOCAL_READ; -} - -enum iwch_mmid_state { - IWCH_STAG_STATE_VALID, - IWCH_STAG_STATE_INVALID -}; - -enum iwch_qp_query_flags { - IWCH_QP_QUERY_CONTEXT_NONE = 0x0, /* No ctx; Only attrs */ - IWCH_QP_QUERY_CONTEXT_GET = 0x1, /* Get ctx + attrs */ - IWCH_QP_QUERY_CONTEXT_SUSPEND = 0x2, /* Not Supported */ - - /* - * Quiesce QP context; Consumer - * will NOT replay outstanding WR - */ - IWCH_QP_QUERY_CONTEXT_QUIESCE = 0x4, - IWCH_QP_QUERY_CONTEXT_REMOVE = 0x8, - IWCH_QP_QUERY_TEST_USERWRITE = 0x32 /* Test special */ -}; - -int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, - struct ib_send_wr **bad_wr); -int iwch_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, - struct ib_recv_wr **bad_wr); -int iwch_bind_mw(struct ib_qp *qp, - struct ib_mw *mw, - struct ib_mw_bind *mw_bind); -int iwch_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc); -int iwch_post_terminate(struct iwch_qp *qhp, struct respQ_msg_t *rsp_msg); -int iwch_register_device(struct iwch_dev *dev); -void iwch_unregister_device(struct iwch_dev *dev); -void stop_read_rep_timer(struct iwch_qp *qhp); -int iwch_register_mem(struct iwch_dev *rhp, struct iwch_pd *php, - struct iwch_mr *mhp, - int shift); -int iwch_reregister_mem(struct iwch_dev *rhp, struct iwch_pd *php, - struct iwch_mr *mhp, - int shift, - int npages); -int iwch_alloc_pbl(struct iwch_mr *mhp, int npages); -void iwch_free_pbl(struct iwch_mr *mhp); -int iwch_write_pbl(struct iwch_mr *mhp, __be64 *pages, int npages, int offset); -int build_phys_page_list(struct ib_phys_buf *buffer_list, - int num_phys_buf, - u64 *iova_start, - u64 *total_size, - int *npages, - int *shift, - __be64 **page_list); - - -#define IWCH_NODE_DESC "cxgb3 Chelsio Communications" - -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_qp.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_qp.c deleted file mode 100644 index 9d36f3c4cab0..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_qp.c +++ /dev/null @@ -1,1105 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NO_SUPPORT -1 - -static int build_rdma_send(union t3_wr *wqe, struct ib_send_wr *wr, - u8 * flit_cnt) -{ - int i; - u32 plen; - - switch (wr->opcode) { - case IB_WR_SEND: - if (wr->send_flags & IB_SEND_SOLICITED) - wqe->send.rdmaop = T3_SEND_WITH_SE; - else - wqe->send.rdmaop = T3_SEND; - wqe->send.rem_stag = 0; - break; - case IB_WR_SEND_WITH_IMM: - if (wr->send_flags & IB_SEND_SOLICITED) - wqe->send.rdmaop = T3_SEND_WITH_SE_INV; - else - wqe->send.rdmaop = T3_SEND_WITH_INV; - wqe->send.rem_stag = 0; - break; - default: - return -EINVAL; - } - if (wr->num_sge > T3_MAX_SGE) - return (-EINVAL); - wqe->send.reserved[0] = 0; - wqe->send.reserved[1] = 0; - wqe->send.reserved[2] = 0; - plen = 0; - for (i = 0; i < wr->num_sge; i++) { - if ((plen + wr->sg_list[i].length) < plen) { - return (-EMSGSIZE); - } - plen += wr->sg_list[i].length; - wqe->send.sgl[i].stag = - htobe32(wr->sg_list[i].lkey); - wqe->send.sgl[i].len = - htobe32(wr->sg_list[i].length); - wqe->send.sgl[i].to = htobe64(wr->sg_list[i].addr); - } - wqe->send.num_sgle = htobe32(wr->num_sge); - *flit_cnt = 4 + ((wr->num_sge) << 1); - wqe->send.plen = htobe32(plen); - return 0; -} - -static int build_rdma_write(union t3_wr *wqe, struct ib_send_wr *wr, - u8 *flit_cnt) -{ - int i; - u32 plen; - - if (wr->num_sge > T3_MAX_SGE) - return (-EINVAL); - wqe->write.rdmaop = T3_RDMA_WRITE; - wqe->write.reserved[0] = 0; - wqe->write.reserved[1] = 0; - wqe->write.reserved[2] = 0; - wqe->write.stag_sink = htobe32(wr->wr.rdma.rkey); - wqe->write.to_sink = htobe64(wr->wr.rdma.remote_addr); - - if (wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) { - plen = 4; - wqe->write.sgl[0].stag = wr->ex.imm_data; - wqe->write.sgl[0].len = 0; - wqe->write.num_sgle = 0; - *flit_cnt = 6; - } else { - plen = 0; - for (i = 0; i < wr->num_sge; i++) { - if ((plen + wr->sg_list[i].length) < plen) { - return (-EMSGSIZE); - } - plen += wr->sg_list[i].length; - wqe->write.sgl[i].stag = - htobe32(wr->sg_list[i].lkey); - wqe->write.sgl[i].len = - htobe32(wr->sg_list[i].length); - wqe->write.sgl[i].to = - htobe64(wr->sg_list[i].addr); - } - wqe->write.num_sgle = htobe32(wr->num_sge); - *flit_cnt = 5 + ((wr->num_sge) << 1); - } - wqe->write.plen = htobe32(plen); - return 0; -} - -static int build_rdma_read(union t3_wr *wqe, struct ib_send_wr *wr, - u8 *flit_cnt) -{ - if (wr->num_sge > 1) - return (-EINVAL); - wqe->read.rdmaop = T3_READ_REQ; - wqe->read.reserved[0] = 0; - wqe->read.reserved[1] = 0; - wqe->read.reserved[2] = 0; - wqe->read.rem_stag = htobe32(wr->wr.rdma.rkey); - wqe->read.rem_to = htobe64(wr->wr.rdma.remote_addr); - wqe->read.local_stag = htobe32(wr->sg_list[0].lkey); - wqe->read.local_len = htobe32(wr->sg_list[0].length); - wqe->read.local_to = htobe64(wr->sg_list[0].addr); - *flit_cnt = sizeof(struct t3_rdma_read_wr) >> 3; - return 0; -} - -static int iwch_sgl2pbl_map(struct iwch_dev *rhp, struct ib_sge *sg_list, - u32 num_sgle, u32 * pbl_addr, u8 * page_size) -{ - int i; - struct iwch_mr *mhp; - u64 offset; - for (i = 0; i < num_sgle; i++) { - - mhp = get_mhp(rhp, (sg_list[i].lkey) >> 8); - if (!mhp) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EIO); - } - if (!mhp->attr.state) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EIO); - } - if (mhp->attr.zbva) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EIO); - } - - if (sg_list[i].addr < mhp->attr.va_fbo) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EINVAL); - } - if (sg_list[i].addr + ((u64) sg_list[i].length) < - sg_list[i].addr) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EINVAL); - } - if (sg_list[i].addr + ((u64) sg_list[i].length) > - mhp->attr.va_fbo + ((u64) mhp->attr.len)) { - CTR2(KTR_IW_CXGB, "%s %d", __FUNCTION__, __LINE__); - return (-EINVAL); - } - offset = sg_list[i].addr - mhp->attr.va_fbo; - offset += mhp->attr.va_fbo & - ((1UL << (12 + mhp->attr.page_size)) - 1); - pbl_addr[i] = ((mhp->attr.pbl_addr - - rhp->rdev.rnic_info.pbl_base) >> 3) + - (offset >> (12 + mhp->attr.page_size)); - page_size[i] = mhp->attr.page_size; - } - return 0; -} - -static int build_rdma_recv(struct iwch_qp *qhp, union t3_wr *wqe, - struct ib_recv_wr *wr) -{ - int i, err = 0; - u32 pbl_addr[T3_MAX_SGE]; - u8 page_size[T3_MAX_SGE]; - - if (wr->num_sge > T3_MAX_SGE) - return (-EINVAL); - - - err = iwch_sgl2pbl_map(qhp->rhp, wr->sg_list, wr->num_sge, pbl_addr, - page_size); - if (err) - return err; - wqe->recv.pagesz[0] = page_size[0]; - wqe->recv.pagesz[1] = page_size[1]; - wqe->recv.pagesz[2] = page_size[2]; - wqe->recv.pagesz[3] = page_size[3]; - wqe->recv.num_sgle = htobe32(wr->num_sge); - - for (i = 0; i < wr->num_sge; i++) { - wqe->recv.sgl[i].stag = htobe32(wr->sg_list[i].lkey); - wqe->recv.sgl[i].len = htobe32(wr->sg_list[i].length); - wqe->recv.sgl[i].to = htobe64(((u32)wr->sg_list[i].addr) & - ((1UL << (12 + page_size[i])) - 1)); - /* pbl_addr is the adapters address in the PBL */ - wqe->recv.pbl_addr[i] = cpu_to_be32(pbl_addr[i]); - } - for (; i < T3_MAX_SGE; i++) { - wqe->recv.sgl[i].stag = 0; - wqe->recv.sgl[i].len = 0; - wqe->recv.sgl[i].to = 0; - wqe->recv.pbl_addr[i] = 0; - } - - qhp->wq.rq[Q_PTR2IDX(qhp->wq.rq_wptr, - qhp->wq.rq_size_log2)].wr_id = wr->wr_id; - qhp->wq.rq[Q_PTR2IDX(qhp->wq.rq_wptr, - qhp->wq.rq_size_log2)].pbl_addr = 0; - - return 0; -} - -static int build_zero_stag_recv(struct iwch_qp *qhp, union t3_wr *wqe, - struct ib_recv_wr *wr) -{ - int i; - u32 pbl_addr; - u32 pbl_offset; - - - /* - * The T3 HW requires the PBL in the HW recv descriptor to reference - * a PBL entry. So we allocate the max needed PBL memory here and pass - * it to the uP in the recv WR. The uP will build the PBL and setup - * the HW recv descriptor. - */ - pbl_addr = cxio_hal_pblpool_alloc(&qhp->rhp->rdev, T3_STAG0_PBL_SIZE); - if (!pbl_addr) - return -ENOMEM; - - /* - * Compute the 8B aligned offset. - */ - pbl_offset = (pbl_addr - qhp->rhp->rdev.rnic_info.pbl_base) >> 3; - - wqe->recv.num_sgle = cpu_to_be32(wr->num_sge); - - for (i = 0; i < wr->num_sge; i++) { - - /* - * Use a 128MB page size. This and an imposed 128MB - * sge length limit allows us to require only a 2-entry HW - * PBL for each SGE. This restriction is acceptable since - * since it is not possible to allocate 128MB of contiguous - * DMA coherent memory! - */ - if (wr->sg_list[i].length > T3_STAG0_MAX_PBE_LEN) - return -EINVAL; - wqe->recv.pagesz[i] = T3_STAG0_PAGE_SHIFT; - - /* - * T3 restricts a recv to all zero-stag or all non-zero-stag. - */ - if (wr->sg_list[i].lkey != 0) - return -EINVAL; - wqe->recv.sgl[i].stag = 0; - wqe->recv.sgl[i].len = htobe32(wr->sg_list[i].length); - wqe->recv.sgl[i].to = htobe64(wr->sg_list[i].addr); - wqe->recv.pbl_addr[i] = htobe32(pbl_offset); - pbl_offset += 2; - } - for (; i < T3_MAX_SGE; i++) { - wqe->recv.pagesz[i] = 0; - wqe->recv.sgl[i].stag = 0; - wqe->recv.sgl[i].len = 0; - wqe->recv.sgl[i].to = 0; - wqe->recv.pbl_addr[i] = 0; - } - qhp->wq.rq[Q_PTR2IDX(qhp->wq.rq_wptr, - qhp->wq.rq_size_log2)].wr_id = wr->wr_id; - qhp->wq.rq[Q_PTR2IDX(qhp->wq.rq_wptr, - qhp->wq.rq_size_log2)].pbl_addr = pbl_addr; - return 0; -} - -int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, - struct ib_send_wr **bad_wr) -{ - int err = 0; - u8 t3_wr_flit_cnt = 0; - enum t3_wr_opcode t3_wr_opcode = 0; - enum t3_wr_flags t3_wr_flags; - struct iwch_qp *qhp; - u32 idx; - union t3_wr *wqe; - u32 num_wrs; - struct t3_swsq *sqp; - - qhp = to_iwch_qp(ibqp); - mtx_lock(&qhp->lock); - if (qhp->attr.state > IWCH_QP_STATE_RTS) { - mtx_unlock(&qhp->lock); - err = -EINVAL; - goto out; - } - num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr, - qhp->wq.sq_size_log2); - if (num_wrs == 0) { - mtx_unlock(&qhp->lock); - err = -EINVAL; - goto out; - } - while (wr) { - if (num_wrs == 0) { - err = -ENOMEM; - break; - } - idx = Q_PTR2IDX(qhp->wq.wptr, qhp->wq.size_log2); - wqe = (union t3_wr *) (qhp->wq.queue + idx); - t3_wr_flags = 0; - if (wr->send_flags & IB_SEND_SOLICITED) - t3_wr_flags |= T3_SOLICITED_EVENT_FLAG; - if (wr->send_flags & IB_SEND_FENCE) - t3_wr_flags |= T3_READ_FENCE_FLAG; - if (wr->send_flags & IB_SEND_SIGNALED) - t3_wr_flags |= T3_COMPLETION_FLAG; - sqp = qhp->wq.sq + - Q_PTR2IDX(qhp->wq.sq_wptr, qhp->wq.sq_size_log2); - switch (wr->opcode) { - case IB_WR_SEND: - case IB_WR_SEND_WITH_IMM: - t3_wr_opcode = T3_WR_SEND; - err = build_rdma_send(wqe, wr, &t3_wr_flit_cnt); - break; - case IB_WR_RDMA_WRITE: - case IB_WR_RDMA_WRITE_WITH_IMM: - t3_wr_opcode = T3_WR_WRITE; - err = build_rdma_write(wqe, wr, &t3_wr_flit_cnt); - break; - case IB_WR_RDMA_READ: - t3_wr_opcode = T3_WR_READ; - t3_wr_flags = 0; /* T3 reads are always signaled */ - err = build_rdma_read(wqe, wr, &t3_wr_flit_cnt); - if (err) - break; - sqp->read_len = wqe->read.local_len; - if (!qhp->wq.oldest_read) - qhp->wq.oldest_read = sqp; - break; - default: - CTR2(KTR_IW_CXGB, "%s post of type=%d TBD!", __FUNCTION__, - wr->opcode); - err = -EINVAL; - } - if (err) - break; - - wqe->send.wrid.id0.hi = qhp->wq.sq_wptr; - sqp->wr_id = wr->wr_id; - sqp->opcode = wr2opcode(t3_wr_opcode); - sqp->sq_wptr = qhp->wq.sq_wptr; - sqp->complete = 0; - sqp->signaled = (wr->send_flags & IB_SEND_SIGNALED); - - build_fw_riwrh((void *) wqe, t3_wr_opcode, t3_wr_flags, - Q_GENBIT(qhp->wq.wptr, qhp->wq.size_log2), - 0, t3_wr_flit_cnt); - CTR5(KTR_IW_CXGB, "%s cookie 0x%llx wq idx 0x%x swsq idx %ld opcode %d", - __FUNCTION__, (unsigned long long) wr->wr_id, idx, - Q_PTR2IDX(qhp->wq.sq_wptr, qhp->wq.sq_size_log2), - sqp->opcode); - wr = wr->next; - num_wrs--; - ++(qhp->wq.wptr); - ++(qhp->wq.sq_wptr); - } - mtx_unlock(&qhp->lock); - ring_doorbell(qhp->wq.doorbell, qhp->wq.qpid); -out: - if (err) - *bad_wr = wr; - return err; -} - -int iwch_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr, - struct ib_recv_wr **bad_wr) -{ - int err = 0; - struct iwch_qp *qhp; - u32 idx; - union t3_wr *wqe; - u32 num_wrs; - - qhp = to_iwch_qp(ibqp); - mtx_lock(&qhp->lock); - if (qhp->attr.state > IWCH_QP_STATE_RTS) { - mtx_unlock(&qhp->lock); - err = -EINVAL; - goto out; - } - num_wrs = Q_FREECNT(qhp->wq.rq_rptr, qhp->wq.rq_wptr, - qhp->wq.rq_size_log2) - 1; - if (!wr) { - mtx_unlock(&qhp->lock); - err = -EINVAL; - goto out; - } - - while (wr) { - if (wr->num_sge > T3_MAX_SGE) { - err = -EINVAL; - break; - } - - idx = Q_PTR2IDX(qhp->wq.wptr, qhp->wq.size_log2); - wqe = (union t3_wr *) (qhp->wq.queue + idx); - if (num_wrs) { - if (wr->sg_list[0].lkey) - err = build_rdma_recv(qhp, wqe, wr); - else - err = build_zero_stag_recv(qhp, wqe, wr); - } else - err = -ENOMEM; - if (err) - break; - - build_fw_riwrh((void *) wqe, T3_WR_RCV, T3_COMPLETION_FLAG, - Q_GENBIT(qhp->wq.wptr, qhp->wq.size_log2), - 0, sizeof(struct t3_receive_wr) >> 3); - CTR6(KTR_IW_CXGB, "%s cookie 0x%llx idx 0x%x rq_wptr 0x%x rw_rptr 0x%x " - "wqe %p ", __FUNCTION__, (unsigned long long) wr->wr_id, - idx, qhp->wq.rq_wptr, qhp->wq.rq_rptr, wqe); - ++(qhp->wq.rq_wptr); - ++(qhp->wq.wptr); - wr = wr->next; - num_wrs--; - } - mtx_unlock(&qhp->lock); - ring_doorbell(qhp->wq.doorbell, qhp->wq.qpid); -out: - if (err) - *bad_wr = wr; - return err; -} - -int iwch_bind_mw(struct ib_qp *qp, - struct ib_mw *mw, - struct ib_mw_bind *mw_bind) -{ - struct iwch_dev *rhp; - struct iwch_mw *mhp; - struct iwch_qp *qhp; - union t3_wr *wqe; - u32 pbl_addr; - u8 page_size; - u32 num_wrs; - struct ib_sge sgl; - int err=0; - enum t3_wr_flags t3_wr_flags; - u32 idx; - struct t3_swsq *sqp; - - qhp = to_iwch_qp(qp); - mhp = to_iwch_mw(mw); - rhp = qhp->rhp; - - mtx_lock(&qhp->lock); - if (qhp->attr.state > IWCH_QP_STATE_RTS) { - mtx_unlock(&qhp->lock); - return (-EINVAL); - } - num_wrs = Q_FREECNT(qhp->wq.sq_rptr, qhp->wq.sq_wptr, - qhp->wq.sq_size_log2); - if ((num_wrs) == 0) { - mtx_unlock(&qhp->lock); - return (-ENOMEM); - } - idx = Q_PTR2IDX(qhp->wq.wptr, qhp->wq.size_log2); - CTR4(KTR_IW_CXGB, "%s: idx 0x%0x, mw 0x%p, mw_bind 0x%p", __FUNCTION__, idx, - mw, mw_bind); - wqe = (union t3_wr *) (qhp->wq.queue + idx); - - t3_wr_flags = 0; - if (mw_bind->send_flags & IB_SEND_SIGNALED) - t3_wr_flags = T3_COMPLETION_FLAG; - - sgl.addr = mw_bind->bind_info.addr; - sgl.lkey = mw_bind->bind_info.mr->lkey; - sgl.length = mw_bind->bind_info.length; - wqe->bind.reserved = 0; - wqe->bind.type = T3_VA_BASED_TO; - - /* TBD: check perms */ - wqe->bind.perms = iwch_ib_to_mwbind_access(mw_bind->bind_info.mw_access_flags); - wqe->bind.mr_stag = htobe32(mw_bind->bind_info.mr->lkey); - wqe->bind.mw_stag = htobe32(mw->rkey); - wqe->bind.mw_len = htobe32(mw_bind->bind_info.length); - wqe->bind.mw_va = htobe64(mw_bind->bind_info.addr); - err = iwch_sgl2pbl_map(rhp, &sgl, 1, &pbl_addr, &page_size); - if (err) { - mtx_unlock(&qhp->lock); - return (err); - } - wqe->send.wrid.id0.hi = qhp->wq.sq_wptr; - sqp = qhp->wq.sq + Q_PTR2IDX(qhp->wq.sq_wptr, qhp->wq.sq_size_log2); - sqp->wr_id = mw_bind->wr_id; - sqp->opcode = T3_BIND_MW; - sqp->sq_wptr = qhp->wq.sq_wptr; - sqp->complete = 0; - sqp->signaled = (mw_bind->send_flags & IB_SEND_SIGNALED); - wqe->bind.mr_pbl_addr = htobe32(pbl_addr); - wqe->bind.mr_pagesz = page_size; - wqe->flit[T3_SQ_COOKIE_FLIT] = mw_bind->wr_id; - build_fw_riwrh((void *)wqe, T3_WR_BIND, t3_wr_flags, - Q_GENBIT(qhp->wq.wptr, qhp->wq.size_log2), 0, - sizeof(struct t3_bind_mw_wr) >> 3); - ++(qhp->wq.wptr); - ++(qhp->wq.sq_wptr); - mtx_unlock(&qhp->lock); - - ring_doorbell(qhp->wq.doorbell, qhp->wq.qpid); - - return err; -} - -static void build_term_codes(struct respQ_msg_t *rsp_msg, - u8 *layer_type, u8 *ecode) -{ - int status = TPT_ERR_INTERNAL_ERR; - int tagged = 0; - int opcode = -1; - int rqtype = 0; - int send_inv = 0; - - if (rsp_msg) { - status = CQE_STATUS(rsp_msg->cqe); - opcode = CQE_OPCODE(rsp_msg->cqe); - rqtype = RQ_TYPE(rsp_msg->cqe); - send_inv = (opcode == T3_SEND_WITH_INV) || - (opcode == T3_SEND_WITH_SE_INV); - tagged = (opcode == T3_RDMA_WRITE) || - (rqtype && (opcode == T3_READ_RESP)); - } - - switch (status) { - case TPT_ERR_STAG: - if (send_inv) { - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; - *ecode = RDMAP_CANT_INV_STAG; - } else { - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - *ecode = RDMAP_INV_STAG; - } - break; - case TPT_ERR_PDID: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - if ((opcode == T3_SEND_WITH_INV) || - (opcode == T3_SEND_WITH_SE_INV)) - *ecode = RDMAP_CANT_INV_STAG; - else - *ecode = RDMAP_STAG_NOT_ASSOC; - break; - case TPT_ERR_QPID: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - *ecode = RDMAP_STAG_NOT_ASSOC; - break; - case TPT_ERR_ACCESS: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - *ecode = RDMAP_ACC_VIOL; - break; - case TPT_ERR_WRAP: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - *ecode = RDMAP_TO_WRAP; - break; - case TPT_ERR_BOUND: - if (tagged) { - *layer_type = LAYER_DDP|DDP_TAGGED_ERR; - *ecode = DDPT_BASE_BOUNDS; - } else { - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT; - *ecode = RDMAP_BASE_BOUNDS; - } - break; - case TPT_ERR_INVALIDATE_SHARED_MR: - case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; - *ecode = RDMAP_CANT_INV_STAG; - break; - case TPT_ERR_ECC: - case TPT_ERR_ECC_PSTAG: - case TPT_ERR_INTERNAL_ERR: - *layer_type = LAYER_RDMAP|RDMAP_LOCAL_CATA; - *ecode = 0; - break; - case TPT_ERR_OUT_OF_RQE: - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_INV_MSN_NOBUF; - break; - case TPT_ERR_PBL_ADDR_BOUND: - *layer_type = LAYER_DDP|DDP_TAGGED_ERR; - *ecode = DDPT_BASE_BOUNDS; - break; - case TPT_ERR_CRC: - *layer_type = LAYER_MPA|DDP_LLP; - *ecode = MPA_CRC_ERR; - break; - case TPT_ERR_MARKER: - *layer_type = LAYER_MPA|DDP_LLP; - *ecode = MPA_MARKER_ERR; - break; - case TPT_ERR_PDU_LEN_ERR: - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_MSG_TOOBIG; - break; - case TPT_ERR_DDP_VERSION: - if (tagged) { - *layer_type = LAYER_DDP|DDP_TAGGED_ERR; - *ecode = DDPT_INV_VERS; - } else { - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_INV_VERS; - } - break; - case TPT_ERR_RDMA_VERSION: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; - *ecode = RDMAP_INV_VERS; - break; - case TPT_ERR_OPCODE: - *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP; - *ecode = RDMAP_INV_OPCODE; - break; - case TPT_ERR_DDP_QUEUE_NUM: - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_INV_QN; - break; - case TPT_ERR_MSN: - case TPT_ERR_MSN_GAP: - case TPT_ERR_MSN_RANGE: - case TPT_ERR_IRD_OVERFLOW: - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_INV_MSN_RANGE; - break; - case TPT_ERR_TBIT: - *layer_type = LAYER_DDP|DDP_LOCAL_CATA; - *ecode = 0; - break; - case TPT_ERR_MO: - *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR; - *ecode = DDPU_INV_MO; - break; - default: - *layer_type = LAYER_RDMAP|DDP_LOCAL_CATA; - *ecode = 0; - break; - } -} - -/* - * This posts a TERMINATE with layer=RDMA, type=catastrophic. - */ -int iwch_post_terminate(struct iwch_qp *qhp, struct respQ_msg_t *rsp_msg) -{ - union t3_wr *wqe; - struct terminate_message *term; - struct mbuf *m; - struct ofld_hdr *oh; - - CTR3(KTR_IW_CXGB, "%s: tid %u, %p", __func__, qhp->ep->hwtid, rsp_msg); - m = m_gethdr(M_NOWAIT, MT_DATA); - if (m == NULL) { - log(LOG_ERR, "%s cannot send TERMINATE!\n", __FUNCTION__); - return (-ENOMEM); - } - oh = mtod(m, struct ofld_hdr *); - m->m_pkthdr.len = m->m_len = sizeof(*oh) + 40; - oh->flags = V_HDR_NDESC(1) | V_HDR_CTRL(CPL_PRIORITY_DATA) | V_HDR_QSET(0); - wqe = (void *)(oh + 1); - memset(wqe, 0, 40); - wqe->send.rdmaop = T3_TERMINATE; - - /* immediate data length */ - wqe->send.plen = htonl(4); - - /* immediate data starts here. */ - term = (struct terminate_message *)wqe->send.sgl; - build_term_codes(rsp_msg, &term->layer_etype, &term->ecode); - wqe->send.wrh.op_seop_flags = htobe32(V_FW_RIWR_OP(T3_WR_SEND) | - V_FW_RIWR_FLAGS(T3_COMPLETION_FLAG | T3_NOTIFY_FLAG)); - wqe->send.wrh.gen_tid_len = htobe32(V_FW_RIWR_TID(qhp->ep->hwtid)); - - return t3_offload_tx(qhp->rhp->rdev.adap, m); -} - -/* - * Assumes qhp lock is held. - */ -static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp, - struct iwch_cq *schp) -{ - int count; - int flushed; - - CTR4(KTR_IW_CXGB, "%s qhp %p rchp %p schp %p", __FUNCTION__, qhp, rchp, schp); - /* take a ref on the qhp since we must release the lock */ - qhp->refcnt++; - mtx_unlock(&qhp->lock); - - /* locking hierarchy: cq lock first, then qp lock. */ - mtx_lock(&rchp->lock); - mtx_lock(&qhp->lock); - cxio_flush_hw_cq(&rchp->cq); - cxio_count_rcqes(&rchp->cq, &qhp->wq, &count); - flushed = cxio_flush_rq(&qhp->wq, &rchp->cq, count); - mtx_unlock(&qhp->lock); - mtx_unlock(&rchp->lock); - if (flushed) - (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context); - - /* locking hierarchy: cq lock first, then qp lock. */ - mtx_lock(&schp->lock); - mtx_lock(&qhp->lock); - cxio_flush_hw_cq(&schp->cq); - cxio_count_scqes(&schp->cq, &qhp->wq, &count); - flushed = cxio_flush_sq(&qhp->wq, &schp->cq, count); - mtx_unlock(&qhp->lock); - mtx_unlock(&schp->lock); - if (flushed) - (*schp->ibcq.comp_handler)(&schp->ibcq, schp->ibcq.cq_context); - - /* deref */ - mtx_lock(&qhp->lock); - if (--qhp->refcnt == 0) - wakeup(qhp); -} - -static void flush_qp(struct iwch_qp *qhp) -{ - struct iwch_cq *rchp, *schp; - - rchp = get_chp(qhp->rhp, qhp->attr.rcq); - schp = get_chp(qhp->rhp, qhp->attr.scq); - - if (qhp->ibqp.uobject) { - cxio_set_wq_in_error(&qhp->wq); - cxio_set_cq_in_error(&rchp->cq); - (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context); - if (schp != rchp) { - cxio_set_cq_in_error(&schp->cq); - (*schp->ibcq.comp_handler)(&schp->ibcq, - schp->ibcq.cq_context); - } - return; - } - __flush_qp(qhp, rchp, schp); -} - - -/* - * Return non zero if at least one RECV was pre-posted. - */ -static int rqes_posted(struct iwch_qp *qhp) -{ - union t3_wr *wqe = qhp->wq.queue; - u16 count = 0; - while ((count+1) != 0 && fw_riwrh_opcode((struct fw_riwrh *)wqe) == T3_WR_RCV) { - count++; - wqe++; - } - return count; -} - -static int rdma_init(struct iwch_dev *rhp, struct iwch_qp *qhp, - enum iwch_qp_attr_mask mask, - struct iwch_qp_attributes *attrs) -{ - struct t3_rdma_init_attr init_attr; - int ret; - struct socket *so = qhp->ep->com.so; - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp; - struct toepcb *toep; - - init_attr.tid = qhp->ep->hwtid; - init_attr.qpid = qhp->wq.qpid; - init_attr.pdid = qhp->attr.pd; - init_attr.scqid = qhp->attr.scq; - init_attr.rcqid = qhp->attr.rcq; - init_attr.rq_addr = qhp->wq.rq_addr; - init_attr.rq_size = 1 << qhp->wq.rq_size_log2; - init_attr.mpaattrs = uP_RI_MPA_IETF_ENABLE | - qhp->attr.mpa_attr.recv_marker_enabled | - (qhp->attr.mpa_attr.xmit_marker_enabled << 1) | - (qhp->attr.mpa_attr.crc_enabled << 2); - - init_attr.qpcaps = uP_RI_QP_RDMA_READ_ENABLE | - uP_RI_QP_RDMA_WRITE_ENABLE | - uP_RI_QP_BIND_ENABLE; - if (!qhp->ibqp.uobject) - init_attr.qpcaps |= uP_RI_QP_STAG0_ENABLE; - init_attr.tcp_emss = qhp->ep->emss; - init_attr.ord = qhp->attr.max_ord; - init_attr.ird = qhp->attr.max_ird; - init_attr.qp_dma_addr = qhp->wq.dma_addr; - init_attr.qp_dma_size = (1UL << qhp->wq.size_log2); - init_attr.rqe_count = rqes_posted(qhp); - init_attr.flags = qhp->attr.mpa_attr.initiator ? MPA_INITIATOR : 0; - init_attr.rtr_type = 0; - tp = intotcpcb(inp); - toep = tp->t_toe; - init_attr.chan = toep->tp_l2t->smt_idx; - init_attr.irs = qhp->ep->rcv_seq; - CTR5(KTR_IW_CXGB, "%s init_attr.rq_addr 0x%x init_attr.rq_size = %d " - "flags 0x%x qpcaps 0x%x", __FUNCTION__, - init_attr.rq_addr, init_attr.rq_size, - init_attr.flags, init_attr.qpcaps); - ret = cxio_rdma_init(&rhp->rdev, &init_attr, qhp->ep->com.so); - CTR2(KTR_IW_CXGB, "%s ret %d", __FUNCTION__, ret); - return ret; -} - -int iwch_modify_qp(struct iwch_dev *rhp, struct iwch_qp *qhp, - enum iwch_qp_attr_mask mask, - struct iwch_qp_attributes *attrs, - int internal) -{ - int ret = 0; - struct iwch_qp_attributes newattr = qhp->attr; - int disconnect = 0; - int terminate = 0; - int abort = 0; - int free = 0; - struct iwch_ep *ep = NULL; - - CTR6(KTR_IW_CXGB, "%s qhp %p qpid 0x%x ep %p state %d -> %d", __FUNCTION__, - qhp, qhp->wq.qpid, qhp->ep, qhp->attr.state, - (mask & IWCH_QP_ATTR_NEXT_STATE) ? attrs->next_state : -1); - - mtx_lock(&qhp->lock); - - /* Process attr changes if in IDLE */ - if (mask & IWCH_QP_ATTR_VALID_MODIFY) { - if (qhp->attr.state != IWCH_QP_STATE_IDLE) { - ret = -EIO; - goto out; - } - if (mask & IWCH_QP_ATTR_ENABLE_RDMA_READ) - newattr.enable_rdma_read = attrs->enable_rdma_read; - if (mask & IWCH_QP_ATTR_ENABLE_RDMA_WRITE) - newattr.enable_rdma_write = attrs->enable_rdma_write; - if (mask & IWCH_QP_ATTR_ENABLE_RDMA_BIND) - newattr.enable_bind = attrs->enable_bind; - if (mask & IWCH_QP_ATTR_MAX_ORD) { - if (attrs->max_ord > - rhp->attr.max_rdma_read_qp_depth) { - ret = -EINVAL; - goto out; - } - newattr.max_ord = attrs->max_ord; - } - if (mask & IWCH_QP_ATTR_MAX_IRD) { - if (attrs->max_ird > - rhp->attr.max_rdma_reads_per_qp) { - ret = -EINVAL; - goto out; - } - newattr.max_ird = attrs->max_ird; - } - qhp->attr = newattr; - } - - if (!(mask & IWCH_QP_ATTR_NEXT_STATE)) - goto out; - if (qhp->attr.state == attrs->next_state) - goto out; - - switch (qhp->attr.state) { - case IWCH_QP_STATE_IDLE: - switch (attrs->next_state) { - case IWCH_QP_STATE_RTS: - if (!(mask & IWCH_QP_ATTR_LLP_STREAM_HANDLE)) { - ret = -EINVAL; - goto out; - } - if (!(mask & IWCH_QP_ATTR_MPA_ATTR)) { - ret = -EINVAL; - goto out; - } - qhp->attr.mpa_attr = attrs->mpa_attr; - qhp->attr.llp_stream_handle = attrs->llp_stream_handle; - qhp->ep = qhp->attr.llp_stream_handle; - qhp->attr.state = IWCH_QP_STATE_RTS; - - /* - * Ref the endpoint here and deref when we - * disassociate the endpoint from the QP. This - * happens in CLOSING->IDLE transition or *->ERROR - * transition. - */ - get_ep(&qhp->ep->com); - mtx_unlock(&qhp->lock); - ret = rdma_init(rhp, qhp, mask, attrs); - mtx_lock(&qhp->lock); - if (ret) - goto err; - break; - case IWCH_QP_STATE_ERROR: - qhp->attr.state = IWCH_QP_STATE_ERROR; - flush_qp(qhp); - break; - default: - ret = -EINVAL; - goto out; - } - break; - case IWCH_QP_STATE_RTS: - switch (attrs->next_state) { - case IWCH_QP_STATE_CLOSING: - PANIC_IF(atomic_load_acq_int(&qhp->ep->com.refcount) < 2); - qhp->attr.state = IWCH_QP_STATE_CLOSING; - if (!internal) { - abort=0; - disconnect = 1; - ep = qhp->ep; - get_ep(&ep->com); - } - break; - case IWCH_QP_STATE_TERMINATE: - qhp->attr.state = IWCH_QP_STATE_TERMINATE; - if (qhp->ibqp.uobject) - cxio_set_wq_in_error(&qhp->wq); - if (!internal) - terminate = 1; - break; - case IWCH_QP_STATE_ERROR: - qhp->attr.state = IWCH_QP_STATE_ERROR; - if (!internal) { - abort=1; - disconnect = 1; - ep = qhp->ep; - get_ep(&ep->com); - } - goto err; - break; - default: - ret = -EINVAL; - goto out; - } - break; - case IWCH_QP_STATE_CLOSING: - if (!internal) { - ret = -EINVAL; - goto out; - } - switch (attrs->next_state) { - case IWCH_QP_STATE_IDLE: - flush_qp(qhp); - qhp->attr.state = IWCH_QP_STATE_IDLE; - qhp->attr.llp_stream_handle = NULL; - put_ep(&qhp->ep->com); - qhp->ep = NULL; - wakeup(qhp); - break; - case IWCH_QP_STATE_ERROR: - goto err; - default: - ret = -EINVAL; - goto err; - } - break; - case IWCH_QP_STATE_ERROR: - if (attrs->next_state != IWCH_QP_STATE_IDLE) { - ret = -EINVAL; - goto out; - } - - if (!Q_EMPTY(qhp->wq.sq_rptr, qhp->wq.sq_wptr) || - !Q_EMPTY(qhp->wq.rq_rptr, qhp->wq.rq_wptr)) { - ret = -EINVAL; - goto out; - } - qhp->attr.state = IWCH_QP_STATE_IDLE; - memset(&qhp->attr, 0, sizeof(qhp->attr)); - break; - case IWCH_QP_STATE_TERMINATE: - if (!internal) { - ret = -EINVAL; - goto out; - } - goto err; - break; - default: - log(LOG_ERR, "%s in a bad state %d\n", - __FUNCTION__, qhp->attr.state); - ret = -EINVAL; - goto err; - break; - } - goto out; -err: - CTR3(KTR_IW_CXGB, "%s disassociating ep %p qpid 0x%x", __FUNCTION__, qhp->ep, - qhp->wq.qpid); - - /* disassociate the LLP connection */ - qhp->attr.llp_stream_handle = NULL; - ep = qhp->ep; - qhp->ep = NULL; - qhp->attr.state = IWCH_QP_STATE_ERROR; - free=1; - wakeup(qhp); - PANIC_IF(!ep); - flush_qp(qhp); -out: - mtx_unlock(&qhp->lock); - - if (terminate) - iwch_post_terminate(qhp, NULL); - - - /* - * If disconnect is 1, then we need to initiate a disconnect - * on the EP. This can be a normal close (RTS->CLOSING) or - * an abnormal close (RTS/CLOSING->ERROR). - */ - if (disconnect) { - iwch_ep_disconnect(ep, abort, M_NOWAIT); - put_ep(&ep->com); - } - - /* - * If free is 1, then we've disassociated the EP from the QP - * and we need to dereference the EP. - */ - if (free) - put_ep(&ep->com); - - CTR2(KTR_IW_CXGB, "%s exit state %d", __FUNCTION__, qhp->attr.state); - return ret; -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.c b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.c deleted file mode 100644 index 407649ca4219..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.c +++ /dev/null @@ -1,375 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef needed -static struct buf_ring *rhdl_fifo; -static struct mtx rhdl_fifo_lock; -#endif - -#define RANDOM_SIZE 16 - -static int __cxio_init_resource_fifo(struct buf_ring **fifo, - struct mtx *fifo_lock, - u32 nr, u32 skip_low, - u32 skip_high, - int randomize) -{ - u32 i, j, idx; - u32 random_bytes; - u32 rarray[16]; - mtx_init(fifo_lock, "cxio fifo", NULL, MTX_DEF|MTX_DUPOK); - - *fifo = buf_ring_alloc(nr, M_DEVBUF, M_NOWAIT, fifo_lock); - if (*fifo == NULL) - return (-ENOMEM); -#if 0 - for (i = 0; i < skip_low + skip_high; i++) { - u32 entry = 0; - - buf_ring_enqueue(*fifo, (uintptr_t) entry); - } -#endif - if (randomize) { - j = 0; - random_bytes = random(); - for (i = 0; i < RANDOM_SIZE; i++) - rarray[i] = i + skip_low; - for (i = skip_low + RANDOM_SIZE; i < nr - skip_high; i++) { - if (j >= RANDOM_SIZE) { - j = 0; - random_bytes = random(); - } - idx = (random_bytes >> (j * 2)) & 0xF; - buf_ring_enqueue(*fifo, (void *)(uintptr_t)rarray[idx]); - rarray[idx] = i; - j++; - } - for (i = 0; i < RANDOM_SIZE; i++) - buf_ring_enqueue(*fifo, (void *) (uintptr_t)rarray[i]); - } else - for (i = skip_low; i < nr - skip_high; i++) - buf_ring_enqueue(*fifo, (void *) (uintptr_t)i); -#if 0 - for (i = 0; i < skip_low + skip_high; i++) - buf_ring_dequeue_sc(*fifo); -#endif - return 0; -} - -static int cxio_init_resource_fifo(struct buf_ring **fifo, struct mtx * fifo_lock, - u32 nr, u32 skip_low, u32 skip_high) -{ - return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low, - skip_high, 0)); -} - -static int cxio_init_resource_fifo_random(struct buf_ring **fifo, - struct mtx * fifo_lock, - u32 nr, u32 skip_low, u32 skip_high) -{ - - return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low, - skip_high, 1)); -} - -static int cxio_init_qpid_fifo(struct cxio_rdev *rdev_p) -{ - u32 i; - - mtx_init(&rdev_p->rscp->qpid_fifo_lock, "qpid fifo", NULL, MTX_DEF); - - rdev_p->rscp->qpid_fifo = buf_ring_alloc(T3_MAX_NUM_QP, M_DEVBUF, - M_NOWAIT, &rdev_p->rscp->qpid_fifo_lock); - if (rdev_p->rscp->qpid_fifo == NULL) - return (-ENOMEM); - - for (i = 16; i < T3_MAX_NUM_QP; i++) - if (!(i & rdev_p->qpmask)) - buf_ring_enqueue(rdev_p->rscp->qpid_fifo, (void *) (uintptr_t)i); - return 0; -} - -#ifdef needed -int cxio_hal_init_rhdl_resource(u32 nr_rhdl) -{ - return cxio_init_resource_fifo(&rhdl_fifo, &rhdl_fifo_lock, nr_rhdl, 1, - 0); -} - -void cxio_hal_destroy_rhdl_resource(void) -{ - buf_ring_free(rhdl_fifo, M_DEVBUF); -} -#endif - -/* nr_* must be power of 2 */ -int cxio_hal_init_resource(struct cxio_rdev *rdev_p, - u32 nr_tpt, u32 nr_pbl, - u32 nr_rqt, u32 nr_qpid, u32 nr_cqid, u32 nr_pdid) -{ - int err = 0; - struct cxio_hal_resource *rscp; - - rscp = malloc(sizeof(*rscp), M_DEVBUF, M_NOWAIT|M_ZERO); - if (!rscp) - return (-ENOMEM); - rdev_p->rscp = rscp; - err = cxio_init_resource_fifo_random(&rscp->tpt_fifo, - &rscp->tpt_fifo_lock, - nr_tpt, 1, 0); - if (err) - goto tpt_err; - err = cxio_init_qpid_fifo(rdev_p); - if (err) - goto qpid_err; - err = cxio_init_resource_fifo(&rscp->cqid_fifo, &rscp->cqid_fifo_lock, - nr_cqid, 1, 0); - if (err) - goto cqid_err; - err = cxio_init_resource_fifo(&rscp->pdid_fifo, &rscp->pdid_fifo_lock, - nr_pdid, 1, 0); - if (err) - goto pdid_err; - return 0; -pdid_err: - buf_ring_free(rscp->cqid_fifo, M_DEVBUF); -cqid_err: - buf_ring_free(rscp->qpid_fifo, M_DEVBUF); -qpid_err: - buf_ring_free(rscp->tpt_fifo, M_DEVBUF); -tpt_err: - return (-ENOMEM); -} - -/* - * returns 0 if no resource available - */ -static u32 cxio_hal_get_resource(struct buf_ring *fifo, struct mtx *lock) -{ - u32 entry; - - mtx_lock(lock); - entry = (u32)(uintptr_t)buf_ring_dequeue_sc(fifo); - mtx_unlock(lock); - return entry; -} - -static void cxio_hal_put_resource(struct buf_ring *fifo, u32 entry, struct mtx *lock) -{ - mtx_lock(lock); - buf_ring_enqueue(fifo, (void *) (uintptr_t)entry); - mtx_unlock(lock); -} - -u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp) -{ - return cxio_hal_get_resource(rscp->tpt_fifo, &rscp->tpt_fifo_lock); -} - -void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag) -{ - cxio_hal_put_resource(rscp->tpt_fifo, stag, &rscp->tpt_fifo_lock); -} - -u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp) -{ - u32 qpid = cxio_hal_get_resource(rscp->qpid_fifo, &rscp->qpid_fifo_lock); - CTR2(KTR_IW_CXGB, "%s qpid 0x%x", __FUNCTION__, qpid); - return qpid; -} - -void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid) -{ - CTR2(KTR_IW_CXGB, "%s qpid 0x%x", __FUNCTION__, qpid); - cxio_hal_put_resource(rscp->qpid_fifo, qpid, &rscp->qpid_fifo_lock); -} - -u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp) -{ - return cxio_hal_get_resource(rscp->cqid_fifo, &rscp->cqid_fifo_lock); -} - -void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid) -{ - cxio_hal_put_resource(rscp->cqid_fifo, cqid, &rscp->cqid_fifo_lock); -} - -u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp) -{ - return cxio_hal_get_resource(rscp->pdid_fifo, &rscp->pdid_fifo_lock); -} - -void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid) -{ - cxio_hal_put_resource(rscp->pdid_fifo, pdid, &rscp->pdid_fifo_lock); -} - -void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp) -{ - buf_ring_free(rscp->tpt_fifo, M_DEVBUF); - buf_ring_free(rscp->cqid_fifo, M_DEVBUF); - buf_ring_free(rscp->qpid_fifo, M_DEVBUF); - buf_ring_free(rscp->pdid_fifo, M_DEVBUF); - free(rscp, M_DEVBUF); -} - -/* - * PBL Memory Manager. Uses Linux generic allocator. - */ - -#define MIN_PBL_SHIFT 8 /* 256B == min PBL size (32 entries) */ -#define PBL_CHUNK 2*1024*1024 - -u32 cxio_hal_pblpool_alloc(struct cxio_rdev *rdev_p, int size) -{ - unsigned long addr = gen_pool_alloc(rdev_p->pbl_pool, size); - CTR3(KTR_IW_CXGB, "%s addr 0x%x size %d", __FUNCTION__, (u32)addr, size); - return (u32)addr; -} - -void cxio_hal_pblpool_free(struct cxio_rdev *rdev_p, u32 addr, int size) -{ - CTR3(KTR_IW_CXGB, "%s addr 0x%x size %d", __FUNCTION__, addr, size); - gen_pool_free(rdev_p->pbl_pool, (unsigned long)addr, size); -} - -int cxio_hal_pblpool_create(struct cxio_rdev *rdev_p) -{ - - rdev_p->pbl_pool = gen_pool_create(rdev_p->rnic_info.pbl_base, MIN_PBL_SHIFT, - rdev_p->rnic_info.pbl_top - rdev_p->rnic_info.pbl_base); -#if 0 - if (rdev_p->pbl_pool) { - - unsigned long i; - for (i = rdev_p->rnic_info.pbl_base; - i <= rdev_p->rnic_info.pbl_top - PBL_CHUNK + 1; - i += PBL_CHUNK) - gen_pool_add(rdev_p->pbl_pool, i, PBL_CHUNK, -1); - } -#endif - return rdev_p->pbl_pool ? 0 : (-ENOMEM); -} - -void cxio_hal_pblpool_destroy(struct cxio_rdev *rdev_p) -{ - gen_pool_destroy(rdev_p->pbl_pool); -} - -/* - * RQT Memory Manager. Uses Linux generic allocator. - */ - -#define MIN_RQT_SHIFT 10 /* 1KB == mini RQT size (16 entries) */ -#define RQT_CHUNK 2*1024*1024 - -u32 cxio_hal_rqtpool_alloc(struct cxio_rdev *rdev_p, int size) -{ - unsigned long addr = gen_pool_alloc(rdev_p->rqt_pool, size << 6); - CTR3(KTR_IW_CXGB, "%s addr 0x%x size %d", __FUNCTION__, (u32)addr, size << 6); - return (u32)addr; -} - -void cxio_hal_rqtpool_free(struct cxio_rdev *rdev_p, u32 addr, int size) -{ - CTR3(KTR_IW_CXGB, "%s addr 0x%x size %d", __FUNCTION__, addr, size << 6); - gen_pool_free(rdev_p->rqt_pool, (unsigned long)addr, size << 6); -} - -int cxio_hal_rqtpool_create(struct cxio_rdev *rdev_p) -{ - - rdev_p->rqt_pool = gen_pool_create(rdev_p->rnic_info.rqt_base, - MIN_RQT_SHIFT, rdev_p->rnic_info.rqt_top - rdev_p->rnic_info.rqt_base); -#if 0 - if (rdev_p->rqt_pool) { - unsigned long i; - - for (i = rdev_p->rnic_info.rqt_base; - i <= rdev_p->rnic_info.rqt_top - RQT_CHUNK + 1; - i += RQT_CHUNK) - gen_pool_add(rdev_p->rqt_pool, i, RQT_CHUNK, -1); - } -#endif - return rdev_p->rqt_pool ? 0 : (-ENOMEM); -} - -void cxio_hal_rqtpool_destroy(struct cxio_rdev *rdev_p) -{ - gen_pool_destroy(rdev_p->rqt_pool); -} -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.h deleted file mode 100644 index e0282a345302..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_resource.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ -#ifndef __CXIO_RESOURCE_H__ -#define __CXIO_RESOURCE_H__ - -extern int cxio_hal_init_rhdl_resource(u32 nr_rhdl); -extern void cxio_hal_destroy_rhdl_resource(void); -extern int cxio_hal_init_resource(struct cxio_rdev *rdev_p, - u32 nr_tpt, u32 nr_pbl, - u32 nr_rqt, u32 nr_qpid, u32 nr_cqid, - u32 nr_pdid); -extern u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp); -extern void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag); -extern u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp); -extern void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid); -extern u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp); -extern void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid); -extern void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp); - -#define PBL_OFF(rdev_p, a) ( (a) - (rdev_p)->rnic_info.pbl_base ) -extern int cxio_hal_pblpool_create(struct cxio_rdev *rdev_p); -extern void cxio_hal_pblpool_destroy(struct cxio_rdev *rdev_p); -extern u32 cxio_hal_pblpool_alloc(struct cxio_rdev *rdev_p, int size); -extern void cxio_hal_pblpool_free(struct cxio_rdev *rdev_p, u32 addr, int size); - -#define RQT_OFF(rdev_p, a) ( (a) - (rdev_p)->rnic_info.rqt_base ) -extern int cxio_hal_rqtpool_create(struct cxio_rdev *rdev_p); -extern void cxio_hal_rqtpool_destroy(struct cxio_rdev *rdev_p); -extern u32 cxio_hal_rqtpool_alloc(struct cxio_rdev *rdev_p, int size); -extern void cxio_hal_rqtpool_free(struct cxio_rdev *rdev_p, u32 addr, int size); -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_user.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_user.h deleted file mode 100644 index 55a1006bbb1c..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_user.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2007, 2008 Chelsio, Inc. All rights reserved. - * - * This software is available to you under a choice of one of two - * licenses. You may choose to be licensed under the terms of the GNU - * General Public License (GPL) Version 2, available from the file - * COPYING in the main directory of this source tree, or the - * OpenIB.org BSD license below: - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * $FreeBSD$ - */ -#ifndef __IWCH_USER_H__ -#define __IWCH_USER_H__ - -#define IWCH_UVERBS_ABI_VERSION 1 - -/* - * Make sure that all structs defined in this file remain laid out so - * that they pack the same way on 32-bit and 64-bit architectures (to - * avoid incompatibility between 32-bit userspace and 64-bit kernels). - * In particular do not use pointer types -- pass pointers in uint64_t - * instead. - */ -struct iwch_create_cq_req { - uint64_t user_rptr_addr; -}; - -struct iwch_create_cq_resp_v0 { - __u64 key; - __u32 cqid; - __u32 size_log2; -}; - -struct iwch_create_cq_resp { - uint64_t key; - uint32_t cqid; - uint32_t size_log2; - __u32 memsize; - __u32 reserved; -}; - -struct iwch_create_qp_resp { - uint64_t key; - uint64_t db_key; - uint32_t qpid; - uint32_t size_log2; - uint32_t sq_size_log2; - uint32_t rq_size_log2; -}; - -struct iwch_reg_user_mr_resp { - uint32_t pbl_addr; -}; -#endif diff --git a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_wr.h b/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_wr.h deleted file mode 100644 index 57690a266839..000000000000 --- a/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_wr.h +++ /dev/null @@ -1,729 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2008 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ -#ifndef __CXIO_WR_H__ -#define __CXIO_WR_H__ -#define T3_MAX_SGE 4 -#define T3_MAX_INLINE 64 -#define T3_STAG0_PBL_SIZE (2 * T3_MAX_SGE << 3) -#define T3_STAG0_MAX_PBE_LEN (128 * 1024 * 1024) -#define T3_STAG0_PAGE_SHIFT 15 - -#define Q_EMPTY(rptr,wptr) ((rptr)==(wptr)) -#define Q_FULL(rptr,wptr,size_log2) ( (((wptr)-(rptr))>>(size_log2)) && \ - ((rptr)!=(wptr)) ) -#define Q_GENBIT(ptr,size_log2) (!(((ptr)>>size_log2)&0x1)) -#define Q_FREECNT(rptr,wptr,size_log2) ((1UL<> S_FW_RIWR_OP)) & M_FW_RIWR_OP) - -#define S_FW_RIWR_SOPEOP 22 -#define M_FW_RIWR_SOPEOP 0x3 -#define V_FW_RIWR_SOPEOP(x) ((x) << S_FW_RIWR_SOPEOP) - -#define S_FW_RIWR_FLAGS 8 -#define M_FW_RIWR_FLAGS 0x3fffff -#define V_FW_RIWR_FLAGS(x) ((x) << S_FW_RIWR_FLAGS) -#define G_FW_RIWR_FLAGS(x) ((((x) >> S_FW_RIWR_FLAGS)) & M_FW_RIWR_FLAGS) - -#define S_FW_RIWR_TID 8 -#define V_FW_RIWR_TID(x) ((x) << S_FW_RIWR_TID) - -#define S_FW_RIWR_LEN 0 -#define V_FW_RIWR_LEN(x) ((x) << S_FW_RIWR_LEN) - -#define S_FW_RIWR_GEN 31 -#define V_FW_RIWR_GEN(x) ((x) << S_FW_RIWR_GEN) - -struct t3_sge { - __be32 stag; - __be32 len; - __be64 to; -}; - -/* If num_sgle is zero, flit 5+ contains immediate data.*/ -struct t3_send_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - - u8 rdmaop; /* 2 */ - u8 reserved[3]; - __be32 rem_stag; - __be32 plen; /* 3 */ - __be32 num_sgle; - struct t3_sge sgl[T3_MAX_SGE]; /* 4+ */ -}; - -struct t3_local_inv_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - __be32 stag; /* 2 */ - __be32 reserved3; -}; - -struct t3_rdma_write_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - u8 rdmaop; /* 2 */ - u8 reserved[3]; - __be32 stag_sink; - __be64 to_sink; /* 3 */ - __be32 plen; /* 4 */ - __be32 num_sgle; - struct t3_sge sgl[T3_MAX_SGE]; /* 5+ */ -}; - -struct t3_rdma_read_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - u8 rdmaop; /* 2 */ - u8 reserved[3]; - __be32 rem_stag; - __be64 rem_to; /* 3 */ - __be32 local_stag; /* 4 */ - __be32 local_len; - __be64 local_to; /* 5 */ -}; - -enum t3_addr_type { - T3_VA_BASED_TO = 0x0, - T3_ZERO_BASED_TO = 0x1 -} __attribute__ ((packed)); - -enum t3_mem_perms { - T3_MEM_ACCESS_LOCAL_READ = 0x1, - T3_MEM_ACCESS_LOCAL_WRITE = 0x2, - T3_MEM_ACCESS_REM_READ = 0x4, - T3_MEM_ACCESS_REM_WRITE = 0x8 -} __attribute__ ((packed)); - -struct t3_bind_mw_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - u16 reserved; /* 2 */ - u8 type; - u8 perms; - __be32 mr_stag; - __be32 mw_stag; /* 3 */ - __be32 mw_len; - __be64 mw_va; /* 4 */ - __be32 mr_pbl_addr; /* 5 */ - u8 reserved2[3]; - u8 mr_pagesz; -}; - -struct t3_receive_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - u8 pagesz[T3_MAX_SGE]; - __be32 num_sgle; /* 2 */ - struct t3_sge sgl[T3_MAX_SGE]; /* 3+ */ - __be32 pbl_addr[T3_MAX_SGE]; -}; - -struct t3_bypass_wr { - struct fw_riwrh wrh; - union t3_wrid wrid; /* 1 */ -}; - -struct t3_modify_qp_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - __be32 flags; /* 2 */ - __be32 quiesce; /* 2 */ - __be32 max_ird; /* 3 */ - __be32 max_ord; /* 3 */ - __be64 sge_cmd; /* 4 */ - __be64 ctx1; /* 5 */ - __be64 ctx0; /* 6 */ -}; - -enum t3_modify_qp_flags { - MODQP_QUIESCE = 0x01, - MODQP_MAX_IRD = 0x02, - MODQP_MAX_ORD = 0x04, - MODQP_WRITE_EC = 0x08, - MODQP_READ_EC = 0x10, -}; - - -enum t3_mpa_attrs { - uP_RI_MPA_RX_MARKER_ENABLE = 0x1, - uP_RI_MPA_TX_MARKER_ENABLE = 0x2, - uP_RI_MPA_CRC_ENABLE = 0x4, - uP_RI_MPA_IETF_ENABLE = 0x8 -} __attribute__ ((packed)); - -enum t3_qp_caps { - uP_RI_QP_RDMA_READ_ENABLE = 0x01, - uP_RI_QP_RDMA_WRITE_ENABLE = 0x02, - uP_RI_QP_BIND_ENABLE = 0x04, - uP_RI_QP_FAST_REGISTER_ENABLE = 0x08, - uP_RI_QP_STAG0_ENABLE = 0x10 -} __attribute__ ((packed)); - -enum rdma_init_rtr_types { - RTR_READ = 1, - RTR_WRITE = 2, - RTR_SEND = 3, -}; - -#define S_RTR_TYPE 2 -#define M_RTR_TYPE 0x3 -#define V_RTR_TYPE(x) ((x) << S_RTR_TYPE) -#define G_RTR_TYPE(x) ((((x) >> S_RTR_TYPE)) & M_RTR_TYPE) - -#define S_CHAN 4 -#define M_CHAN 0x3 -#define V_CHAN(x) ((x) << S_CHAN) -#define G_CHAN(x) ((((x) >> S_CHAN)) & M_CHAN) - -struct t3_rdma_init_attr { - u32 tid; - u32 qpid; - u32 pdid; - u32 scqid; - u32 rcqid; - u32 rq_addr; - u32 rq_size; - enum t3_mpa_attrs mpaattrs; - enum t3_qp_caps qpcaps; - u16 tcp_emss; - u32 ord; - u32 ird; - u64 qp_dma_addr; - u32 qp_dma_size; - enum rdma_init_rtr_types rtr_type; - u16 flags; - u16 rqe_count; - u32 irs; - u32 chan; -}; - -struct t3_rdma_init_wr { - struct fw_riwrh wrh; /* 0 */ - union t3_wrid wrid; /* 1 */ - __be32 qpid; /* 2 */ - __be32 pdid; - __be32 scqid; /* 3 */ - __be32 rcqid; - __be32 rq_addr; /* 4 */ - __be32 rq_size; - u8 mpaattrs; /* 5 */ - u8 qpcaps; - __be16 ulpdu_size; - __be16 flags_rtr_type; - __be16 rqe_count; - __be32 ord; /* 6 */ - __be32 ird; - __be64 qp_dma_addr; /* 7 */ - __be32 qp_dma_size; /* 8 */ - __be32 irs; -}; - -struct t3_genbit { - u64 flit[15]; - __be64 genbit; -}; - -enum rdma_init_wr_flags { - MPA_INITIATOR = (1<<0), - PRIV_QP = (1<<1), -}; - -union t3_wr { - struct t3_send_wr send; - struct t3_rdma_write_wr write; - struct t3_rdma_read_wr read; - struct t3_receive_wr recv; - struct t3_local_inv_wr local_inv; - struct t3_bind_mw_wr bind; - struct t3_bypass_wr bypass; - struct t3_rdma_init_wr init; - struct t3_modify_qp_wr qp_mod; - struct t3_genbit genbit; - u64 flit[16]; -}; - -#define T3_SQ_CQE_FLIT 13 -#define T3_SQ_COOKIE_FLIT 14 - -#define T3_RQ_COOKIE_FLIT 13 -#define T3_RQ_CQE_FLIT 14 - -static inline enum t3_wr_opcode fw_riwrh_opcode(struct fw_riwrh *wqe) -{ - return G_FW_RIWR_OP(be32toh(wqe->op_seop_flags)); -} - -static inline void build_fw_riwrh(struct fw_riwrh *wqe, enum t3_wr_opcode op, - enum t3_wr_flags flags, u8 genbit, u32 tid, - u8 len) -{ - wqe->op_seop_flags = htobe32(V_FW_RIWR_OP(op) | - V_FW_RIWR_SOPEOP(M_FW_RIWR_SOPEOP) | - V_FW_RIWR_FLAGS(flags)); - wmb(); - wqe->gen_tid_len = htobe32(V_FW_RIWR_GEN(genbit) | - V_FW_RIWR_TID(tid) | - V_FW_RIWR_LEN(len)); - /* 2nd gen bit... */ - ((union t3_wr *)wqe)->genbit.genbit = htobe64(genbit); -} - -/* - * T3 ULP2_TX commands - */ -enum t3_utx_mem_op { - T3_UTX_MEM_READ = 2, - T3_UTX_MEM_WRITE = 3 -}; - -/* T3 MC7 RDMA TPT entry format */ - -enum tpt_mem_type { - TPT_NON_SHARED_MR = 0x0, - TPT_SHARED_MR = 0x1, - TPT_MW = 0x2, - TPT_MW_RELAXED_PROTECTION = 0x3 -}; - -enum tpt_addr_type { - TPT_ZBTO = 0, - TPT_VATO = 1 -}; - -enum tpt_mem_perm { - TPT_LOCAL_READ = 0x8, - TPT_LOCAL_WRITE = 0x4, - TPT_REMOTE_READ = 0x2, - TPT_REMOTE_WRITE = 0x1 -}; - -struct tpt_entry { - __be32 valid_stag_pdid; - __be32 flags_pagesize_qpid; - - __be32 rsvd_pbl_addr; - __be32 len; - __be32 va_hi; - __be32 va_low_or_fbo; - - __be32 rsvd_bind_cnt_or_pstag; - __be32 rsvd_pbl_size; -}; - -#define S_TPT_VALID 31 -#define V_TPT_VALID(x) ((x) << S_TPT_VALID) -#define F_TPT_VALID V_TPT_VALID(1U) - -#define S_TPT_STAG_KEY 23 -#define M_TPT_STAG_KEY 0xFF -#define V_TPT_STAG_KEY(x) ((x) << S_TPT_STAG_KEY) -#define G_TPT_STAG_KEY(x) (((x) >> S_TPT_STAG_KEY) & M_TPT_STAG_KEY) - -#define S_TPT_STAG_STATE 22 -#define V_TPT_STAG_STATE(x) ((x) << S_TPT_STAG_STATE) -#define F_TPT_STAG_STATE V_TPT_STAG_STATE(1U) - -#define S_TPT_STAG_TYPE 20 -#define M_TPT_STAG_TYPE 0x3 -#define V_TPT_STAG_TYPE(x) ((x) << S_TPT_STAG_TYPE) -#define G_TPT_STAG_TYPE(x) (((x) >> S_TPT_STAG_TYPE) & M_TPT_STAG_TYPE) - -#define S_TPT_PDID 0 -#define M_TPT_PDID 0xFFFFF -#define V_TPT_PDID(x) ((x) << S_TPT_PDID) -#define G_TPT_PDID(x) (((x) >> S_TPT_PDID) & M_TPT_PDID) - -#define S_TPT_PERM 28 -#define M_TPT_PERM 0xF -#define V_TPT_PERM(x) ((x) << S_TPT_PERM) -#define G_TPT_PERM(x) (((x) >> S_TPT_PERM) & M_TPT_PERM) - -#define S_TPT_REM_INV_DIS 27 -#define V_TPT_REM_INV_DIS(x) ((x) << S_TPT_REM_INV_DIS) -#define F_TPT_REM_INV_DIS V_TPT_REM_INV_DIS(1U) - -#define S_TPT_ADDR_TYPE 26 -#define V_TPT_ADDR_TYPE(x) ((x) << S_TPT_ADDR_TYPE) -#define F_TPT_ADDR_TYPE V_TPT_ADDR_TYPE(1U) - -#define S_TPT_MW_BIND_ENABLE 25 -#define V_TPT_MW_BIND_ENABLE(x) ((x) << S_TPT_MW_BIND_ENABLE) -#define F_TPT_MW_BIND_ENABLE V_TPT_MW_BIND_ENABLE(1U) - -#define S_TPT_PAGE_SIZE 20 -#define M_TPT_PAGE_SIZE 0x1F -#define V_TPT_PAGE_SIZE(x) ((x) << S_TPT_PAGE_SIZE) -#define G_TPT_PAGE_SIZE(x) (((x) >> S_TPT_PAGE_SIZE) & M_TPT_PAGE_SIZE) - -#define S_TPT_PBL_ADDR 0 -#define M_TPT_PBL_ADDR 0x1FFFFFFF -#define V_TPT_PBL_ADDR(x) ((x) << S_TPT_PBL_ADDR) -#define G_TPT_PBL_ADDR(x) (((x) >> S_TPT_PBL_ADDR) & M_TPT_PBL_ADDR) - -#define S_TPT_QPID 0 -#define M_TPT_QPID 0xFFFFF -#define V_TPT_QPID(x) ((x) << S_TPT_QPID) -#define G_TPT_QPID(x) (((x) >> S_TPT_QPID) & M_TPT_QPID) - -#define S_TPT_PSTAG 0 -#define M_TPT_PSTAG 0xFFFFFF -#define V_TPT_PSTAG(x) ((x) << S_TPT_PSTAG) -#define G_TPT_PSTAG(x) (((x) >> S_TPT_PSTAG) & M_TPT_PSTAG) - -#define S_TPT_PBL_SIZE 0 -#define M_TPT_PBL_SIZE 0xFFFFF -#define V_TPT_PBL_SIZE(x) ((x) << S_TPT_PBL_SIZE) -#define G_TPT_PBL_SIZE(x) (((x) >> S_TPT_PBL_SIZE) & M_TPT_PBL_SIZE) - -/* - * CQE defs - */ -struct t3_cqe { - __be32 header; - __be32 len; - union { - struct { - __be32 stag; - __be32 msn; - } rcqe; - struct { - u32 wrid_hi; - u32 wrid_low; - } scqe; - } u; -}; - -#define S_CQE_OOO 31 -#define M_CQE_OOO 0x1 -#define G_CQE_OOO(x) ((((x) >> S_CQE_OOO)) & M_CQE_OOO) -#define V_CEQ_OOO(x) ((x)<> S_CQE_QPID)) & M_CQE_QPID) -#define V_CQE_QPID(x) ((x)<> S_CQE_SWCQE)) & M_CQE_SWCQE) -#define V_CQE_SWCQE(x) ((x)<> S_CQE_GENBIT) & M_CQE_GENBIT) -#define V_CQE_GENBIT(x) ((x)<> S_CQE_STATUS)) & M_CQE_STATUS) -#define V_CQE_STATUS(x) ((x)<> S_CQE_TYPE)) & M_CQE_TYPE) -#define V_CQE_TYPE(x) ((x)<> S_CQE_OPCODE)) & M_CQE_OPCODE) -#define V_CQE_OPCODE(x) ((x)<queue[1 << cq->size_log2])->cq_err; -} - -static inline void cxio_set_cq_in_error(struct t3_cq *cq) -{ - ((struct t3_cq_status_page *) - &cq->queue[1 << cq->size_log2])->cq_err = 1; -} - -static inline void cxio_set_wq_in_error(struct t3_wq *wq) -{ - wq->queue->flit[13] = 1; -} - -static inline struct t3_cqe *cxio_next_hw_cqe(struct t3_cq *cq) -{ - struct t3_cqe *cqe; - - cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2)); - if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe)) - return cqe; - return NULL; -} - -static inline struct t3_cqe *cxio_next_sw_cqe(struct t3_cq *cq) -{ - struct t3_cqe *cqe; - - if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) { - cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2)); - return cqe; - } - return NULL; -} - -static inline struct t3_cqe *cxio_next_cqe(struct t3_cq *cq) -{ - struct t3_cqe *cqe; - - if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) { - cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2)); - return cqe; - } - cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2)); - if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe)) - return cqe; - return NULL; -} - -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c b/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c deleted file mode 100644 index f80f2f950241..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c +++ /dev/null @@ -1,1811 +0,0 @@ -/*- - * Copyright (c) 2012 Chelsio Communications, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#define TCPSTATES -#include -#include -#include -#include -#include -#include - -#include "cxgb_include.h" -#include "ulp/tom/cxgb_l2t.h" -#include "ulp/tom/cxgb_tom.h" -#include "ulp/tom/cxgb_toepcb.h" - -VNET_DECLARE(int, tcp_do_autosndbuf); -#define V_tcp_do_autosndbuf VNET(tcp_do_autosndbuf) -VNET_DECLARE(int, tcp_autosndbuf_inc); -#define V_tcp_autosndbuf_inc VNET(tcp_autosndbuf_inc) -VNET_DECLARE(int, tcp_autosndbuf_max); -#define V_tcp_autosndbuf_max VNET(tcp_autosndbuf_max) -VNET_DECLARE(int, tcp_do_autorcvbuf); -#define V_tcp_do_autorcvbuf VNET(tcp_do_autorcvbuf) -VNET_DECLARE(int, tcp_autorcvbuf_inc); -#define V_tcp_autorcvbuf_inc VNET(tcp_autorcvbuf_inc) -VNET_DECLARE(int, tcp_autorcvbuf_max); -#define V_tcp_autorcvbuf_max VNET(tcp_autorcvbuf_max) -extern int always_keepalive; - -/* - * For ULP connections HW may add headers, e.g., for digests, that aren't part - * of the messages sent by the host but that are part of the TCP payload and - * therefore consume TCP sequence space. Tx connection parameters that - * operate in TCP sequence space are affected by the HW additions and need to - * compensate for them to accurately track TCP sequence numbers. This array - * contains the compensating extra lengths for ULP packets. It is indexed by - * a packet's ULP submode. - */ -const unsigned int t3_ulp_extra_len[] = {0, 4, 4, 8}; - -/* - * Max receive window supported by HW in bytes. Only a small part of it can - * be set through option0, the rest needs to be set through RX_DATA_ACK. - */ -#define MAX_RCV_WND ((1U << 27) - 1) - -/* - * Min receive window. We want it to be large enough to accommodate receive - * coalescing, handle jumbo frames, and not trigger sender SWS avoidance. - */ -#define MIN_RCV_WND (24 * 1024U) -#define INP_TOS(inp) ((inp_ip_tos_get(inp) >> 2) & M_TOS) - -static void t3_release_offload_resources(struct toepcb *); -static void send_reset(struct toepcb *toep); - -/* - * Called after the last CPL for the toepcb has been received. - * - * The inp must be wlocked on entry and is unlocked (or maybe destroyed) by the - * time this function exits. - */ -static int -toepcb_release(struct toepcb *toep) -{ - struct inpcb *inp = toep->tp_inp; - struct toedev *tod = toep->tp_tod; - struct tom_data *td = t3_tomdata(tod); - int rc; - - INP_WLOCK_ASSERT(inp); - KASSERT(!(toep->tp_flags & TP_CPL_DONE), - ("%s: double release?", __func__)); - - CTR2(KTR_CXGB, "%s: tid %d", __func__, toep->tp_tid); - - toep->tp_flags |= TP_CPL_DONE; - toep->tp_inp = NULL; - - mtx_lock(&td->toep_list_lock); - TAILQ_REMOVE(&td->toep_list, toep, link); - mtx_unlock(&td->toep_list_lock); - - if (!(toep->tp_flags & TP_ATTACHED)) - t3_release_offload_resources(toep); - - rc = in_pcbrele_wlocked(inp); - if (!rc) - INP_WUNLOCK(inp); - return (rc); -} - -/* - * One sided detach. The tcpcb is going away and we need to unhook the toepcb - * hanging off it. If the TOE driver is also done with the toepcb we'll release - * all offload resources. - */ -static void -toepcb_detach(struct inpcb *inp) -{ - struct toepcb *toep; - struct tcpcb *tp; - - KASSERT(inp, ("%s: inp is NULL", __func__)); - INP_WLOCK_ASSERT(inp); - - tp = intotcpcb(inp); - toep = tp->t_toe; - - KASSERT(toep != NULL, ("%s: toep is NULL", __func__)); - KASSERT(toep->tp_flags & TP_ATTACHED, ("%s: not attached", __func__)); - - CTR6(KTR_CXGB, "%s: %s %u, toep %p, inp %p, tp %p", __func__, - tp->t_state == TCPS_SYN_SENT ? "atid" : "tid", toep->tp_tid, - toep, inp, tp); - - tp->t_toe = NULL; - tp->t_flags &= ~TF_TOE; - toep->tp_flags &= ~TP_ATTACHED; - - if (toep->tp_flags & TP_CPL_DONE) - t3_release_offload_resources(toep); -} - -void -t3_pcb_detach(struct toedev *tod __unused, struct tcpcb *tp) -{ - - toepcb_detach(tp->t_inpcb); -} - -static int -alloc_atid(struct tid_info *t, void *ctx) -{ - int atid = -1; - - mtx_lock(&t->atid_lock); - if (t->afree) { - union active_open_entry *p = t->afree; - - atid = (p - t->atid_tab) + t->atid_base; - t->afree = p->next; - p->ctx = ctx; - t->atids_in_use++; - } - mtx_unlock(&t->atid_lock); - - return (atid); -} - -static void -free_atid(struct tid_info *t, int atid) -{ - union active_open_entry *p = atid2entry(t, atid); - - mtx_lock(&t->atid_lock); - p->next = t->afree; - t->afree = p; - t->atids_in_use--; - mtx_unlock(&t->atid_lock); -} - -void -insert_tid(struct tom_data *td, void *ctx, unsigned int tid) -{ - struct tid_info *t = &td->tid_maps; - - t->tid_tab[tid] = ctx; - atomic_add_int(&t->tids_in_use, 1); -} - -void -update_tid(struct tom_data *td, void *ctx, unsigned int tid) -{ - struct tid_info *t = &td->tid_maps; - - t->tid_tab[tid] = ctx; -} - -void -remove_tid(struct tom_data *td, unsigned int tid) -{ - struct tid_info *t = &td->tid_maps; - - t->tid_tab[tid] = NULL; - atomic_add_int(&t->tids_in_use, -1); -} - -/* use ctx as a next pointer in the tid release list */ -void -queue_tid_release(struct toedev *tod, unsigned int tid) -{ - struct tom_data *td = t3_tomdata(tod); - void **p = &td->tid_maps.tid_tab[tid]; - struct adapter *sc = tod->tod_softc; - - mtx_lock(&td->tid_release_lock); - *p = td->tid_release_list; - td->tid_release_list = p; - if (!*p) - taskqueue_enqueue(sc->tq, &td->tid_release_task); - mtx_unlock(&td->tid_release_lock); -} - -/* - * Populate a TID_RELEASE WR. - */ -static inline void -mk_tid_release(struct cpl_tid_release *cpl, unsigned int tid) -{ - - cpl->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid)); -} - -void -release_tid(struct toedev *tod, unsigned int tid, int qset) -{ - struct tom_data *td = t3_tomdata(tod); - struct adapter *sc = tod->tod_softc; - struct mbuf *m; - struct cpl_tid_release *cpl; -#ifdef INVARIANTS - struct tid_info *t = &td->tid_maps; -#endif - - KASSERT(tid < t->ntids, - ("%s: tid=%d, ntids=%d", __func__, tid, t->ntids)); - - m = M_GETHDR_OFLD(qset, CPL_PRIORITY_CONTROL, cpl); - if (m) { - mk_tid_release(cpl, tid); - t3_offload_tx(sc, m); - remove_tid(td, tid); - } else - queue_tid_release(tod, tid); - -} - -void -t3_process_tid_release_list(void *data, int pending) -{ - struct mbuf *m; - struct tom_data *td = data; - struct adapter *sc = td->tod.tod_softc; - - mtx_lock(&td->tid_release_lock); - while (td->tid_release_list) { - void **p = td->tid_release_list; - unsigned int tid = p - td->tid_maps.tid_tab; - struct cpl_tid_release *cpl; - - td->tid_release_list = (void **)*p; - m = M_GETHDR_OFLD(0, CPL_PRIORITY_CONTROL, cpl); /* qs 0 here */ - if (m == NULL) - break; /* XXX: who reschedules the release task? */ - mtx_unlock(&td->tid_release_lock); - mk_tid_release(cpl, tid); - t3_offload_tx(sc, m); - remove_tid(td, tid); - mtx_lock(&td->tid_release_lock); - } - mtx_unlock(&td->tid_release_lock); -} - -static void -close_conn(struct adapter *sc, struct toepcb *toep) -{ - struct mbuf *m; - struct cpl_close_con_req *req; - - if (toep->tp_flags & TP_FIN_SENT) - return; - - m = M_GETHDR_OFLD(toep->tp_qset, CPL_PRIORITY_DATA, req); - if (m == NULL) - CXGB_UNIMPLEMENTED(); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON)); - req->wr.wrh_lo = htonl(V_WR_TID(toep->tp_tid)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, toep->tp_tid)); - req->rsvd = 0; - - toep->tp_flags |= TP_FIN_SENT; - t3_offload_tx(sc, m); -} - -static inline void -make_tx_data_wr(struct socket *so, struct tx_data_wr *req, int len, - struct mbuf *tail) -{ - struct tcpcb *tp = so_sototcpcb(so); - struct toepcb *toep = tp->t_toe; - struct sockbuf *snd; - - inp_lock_assert(tp->t_inpcb); - snd = so_sockbuf_snd(so); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)); - req->wr.wrh_lo = htonl(V_WR_TID(toep->tp_tid)); - /* len includes the length of any HW ULP additions */ - req->len = htonl(len); - req->param = htonl(V_TX_PORT(toep->tp_l2t->smt_idx)); - /* V_TX_ULP_SUBMODE sets both the mode and submode */ - req->flags = htonl(V_TX_ULP_SUBMODE(toep->tp_ulp_mode) | V_TX_URG(0) | - V_TX_SHOVE(!(tp->t_flags & TF_MORETOCOME) && (tail ? 0 : 1))); - req->sndseq = htonl(tp->snd_nxt); - if (__predict_false((toep->tp_flags & TP_DATASENT) == 0)) { - struct adapter *sc = toep->tp_tod->tod_softc; - int cpu_idx = sc->rrss_map[toep->tp_qset]; - - req->flags |= htonl(V_TX_ACK_PAGES(2) | F_TX_INIT | - V_TX_CPU_IDX(cpu_idx)); - - /* Sendbuffer is in units of 32KB. */ - if (V_tcp_do_autosndbuf && snd->sb_flags & SB_AUTOSIZE) - req->param |= htonl(V_TX_SNDBUF(VNET(tcp_autosndbuf_max) >> 15)); - else - req->param |= htonl(V_TX_SNDBUF(snd->sb_hiwat >> 15)); - - toep->tp_flags |= TP_DATASENT; - } -} - -/* - * TOM_XXX_DUPLICATION sgl_len, calc_tx_descs, calc_tx_descs_ofld, mbuf_wrs, etc. - * TOM_XXX_MOVE to some common header file. - */ -/* - * IMM_LEN: # of bytes that can be tx'd as immediate data. There are 16 flits - * in a tx desc; subtract 3 for tx_data_wr (including the WR header), and 1 more - * for the second gen bit flit. This leaves us with 12 flits. - * - * descs_to_sgllen: # of SGL entries that can fit into the given # of tx descs. - * The first desc has a tx_data_wr (which includes the WR header), the rest have - * the WR header only. All descs have the second gen bit flit. - * - * sgllen_to_descs: # of tx descs used up by an sgl of given length. The first - * desc has a tx_data_wr (which includes the WR header), the rest have the WR - * header only. All descs have the second gen bit flit. - * - * flits_to_sgllen: # of SGL entries that can be fit in the given # of flits. - * - */ -#define IMM_LEN 96 -static int descs_to_sgllen[TX_MAX_DESC + 1] = {0, 8, 17, 26, 35}; -static int sgllen_to_descs[TX_MAX_SEGS] = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, /* 0 - 9 */ - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, /* 10 - 19 */ - 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, /* 20 - 29 */ - 4, 4, 4, 4, 4, 4 /* 30 - 35 */ -}; -#if 0 -static int flits_to_sgllen[TX_DESC_FLITS + 1] = { - 0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10 -}; -#endif -#if SGE_NUM_GENBITS != 2 -#error "SGE_NUM_GENBITS really must be 2" -#endif - -int -t3_push_frames(struct socket *so, int req_completion) -{ - struct tcpcb *tp = so_sototcpcb(so); - struct toepcb *toep = tp->t_toe; - struct mbuf *m0, *sndptr, *m; - struct toedev *tod = toep->tp_tod; - struct adapter *sc = tod->tod_softc; - int bytes, ndesc, total_bytes = 0, mlen; - struct sockbuf *snd; - struct sglist *sgl; - struct ofld_hdr *oh; - caddr_t dst; - struct tx_data_wr *wr; - - inp_lock_assert(tp->t_inpcb); - - snd = so_sockbuf_snd(so); - SOCKBUF_LOCK(snd); - - /* - * Autosize the send buffer. - */ - if (snd->sb_flags & SB_AUTOSIZE && VNET(tcp_do_autosndbuf)) { - if (sbused(snd) >= (snd->sb_hiwat / 8 * 7) && - sbused(snd) < VNET(tcp_autosndbuf_max)) { - if (!sbreserve_locked(snd, min(snd->sb_hiwat + - VNET(tcp_autosndbuf_inc), VNET(tcp_autosndbuf_max)), - so, curthread)) - snd->sb_flags &= ~SB_AUTOSIZE; - } - } - - if (toep->tp_m_last && toep->tp_m_last == snd->sb_sndptr) - sndptr = toep->tp_m_last->m_next; - else - sndptr = snd->sb_sndptr ? snd->sb_sndptr : snd->sb_mb; - - /* Nothing to send or no WRs available for sending data */ - if (toep->tp_wr_avail == 0 || sndptr == NULL) - goto out; - - /* Something to send and at least 1 WR available */ - while (toep->tp_wr_avail && sndptr != NULL) { - - m0 = m_gethdr(M_NOWAIT, MT_DATA); - if (m0 == NULL) - break; - oh = mtod(m0, struct ofld_hdr *); - wr = (void *)(oh + 1); - dst = (void *)(wr + 1); - - m0->m_pkthdr.len = m0->m_len = sizeof(*oh) + sizeof(*wr); - oh->flags = V_HDR_CTRL(CPL_PRIORITY_DATA) | F_HDR_DF | - V_HDR_QSET(toep->tp_qset); - - /* - * Try to construct an immediate data WR if possible. Stuff as - * much data into it as possible, one whole mbuf at a time. - */ - mlen = sndptr->m_len; - ndesc = bytes = 0; - while (mlen <= IMM_LEN - bytes) { - bcopy(sndptr->m_data, dst, mlen); - bytes += mlen; - dst += mlen; - - if (!(sndptr = sndptr->m_next)) - break; - mlen = sndptr->m_len; - } - - if (bytes) { - - /* Was able to fit 'bytes' bytes in an immediate WR */ - - ndesc = 1; - make_tx_data_wr(so, wr, bytes, sndptr); - - m0->m_len += bytes; - m0->m_pkthdr.len = m0->m_len; - - } else { - int wr_avail = min(toep->tp_wr_avail, TX_MAX_DESC); - - /* Need to make an SGL */ - - sgl = sglist_alloc(descs_to_sgllen[wr_avail], M_NOWAIT); - if (sgl == NULL) - break; - - for (m = sndptr; m != NULL; m = m->m_next) { - if ((mlen = m->m_len) > 0) { - if (sglist_append(sgl, m->m_data, mlen)) - break; - } - bytes += mlen; - } - sndptr = m; - if (bytes == 0) { - sglist_free(sgl); - break; - } - ndesc = sgllen_to_descs[sgl->sg_nseg]; - oh->flags |= F_HDR_SGL; - oh->sgl = sgl; - make_tx_data_wr(so, wr, bytes, sndptr); - } - - oh->flags |= V_HDR_NDESC(ndesc); - oh->plen = bytes; - - snd->sb_sndptr = sndptr; - snd->sb_sndptroff += bytes; - if (sndptr == NULL) { - snd->sb_sndptr = snd->sb_mbtail; - snd->sb_sndptroff -= snd->sb_mbtail->m_len; - toep->tp_m_last = snd->sb_mbtail; - } else - toep->tp_m_last = NULL; - - total_bytes += bytes; - - toep->tp_wr_avail -= ndesc; - toep->tp_wr_unacked += ndesc; - - if ((req_completion && toep->tp_wr_unacked == ndesc) || - toep->tp_wr_unacked >= toep->tp_wr_max / 2) { - wr->wr.wrh_hi |= htonl(F_WR_COMPL); - toep->tp_wr_unacked = 0; - } - - enqueue_wr(toep, m0); - l2t_send(sc, m0, toep->tp_l2t); - } -out: - SOCKBUF_UNLOCK(snd); - - if (sndptr == NULL && (toep->tp_flags & TP_SEND_FIN)) - close_conn(sc, toep); - - return (total_bytes); -} - -static int -send_rx_credits(struct adapter *sc, struct toepcb *toep, int credits) -{ - struct mbuf *m; - struct cpl_rx_data_ack *req; - uint32_t dack = F_RX_DACK_CHANGE | V_RX_DACK_MODE(1); - - m = M_GETHDR_OFLD(toep->tp_qset, CPL_PRIORITY_CONTROL, req); - if (m == NULL) - return (0); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - req->wr.wrh_lo = 0; - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK, toep->tp_tid)); - req->credit_dack = htonl(dack | V_RX_CREDITS(credits)); - t3_offload_tx(sc, m); - return (credits); -} - -void -t3_rcvd(struct toedev *tod, struct tcpcb *tp) -{ - struct adapter *sc = tod->tod_softc; - struct inpcb *inp = tp->t_inpcb; - struct socket *so = inp->inp_socket; - struct sockbuf *so_rcv = &so->so_rcv; - struct toepcb *toep = tp->t_toe; - int must_send; - - INP_WLOCK_ASSERT(inp); - - SOCKBUF_LOCK(so_rcv); - KASSERT(toep->tp_enqueued >= sbused(so_rcv), - ("%s: sbused(so_rcv) > enqueued", __func__)); - toep->tp_rx_credits += toep->tp_enqueued - sbused(so_rcv); - toep->tp_enqueued = sbused(so_rcv); - SOCKBUF_UNLOCK(so_rcv); - - must_send = toep->tp_rx_credits + 16384 >= tp->rcv_wnd; - if (must_send || toep->tp_rx_credits >= 15 * 1024) { - int credits; - - credits = send_rx_credits(sc, toep, toep->tp_rx_credits); - toep->tp_rx_credits -= credits; - tp->rcv_wnd += credits; - tp->rcv_adv += credits; - } -} - -static int -do_rx_urg_notify(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_rx_urg_notify *hdr = mtod(m, void *); - unsigned int tid = GET_TID(hdr); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - - log(LOG_ERR, "%s: tid %u inp %p", __func__, tid, toep->tp_inp); - - m_freem(m); - return (0); -} - -int -t3_send_fin(struct toedev *tod, struct tcpcb *tp) -{ - struct toepcb *toep = tp->t_toe; - struct inpcb *inp = tp->t_inpcb; - struct socket *so = inp_inpcbtosocket(inp); -#if defined(KTR) - unsigned int tid = toep->tp_tid; -#endif - - INP_INFO_RLOCK_ASSERT(&V_tcbinfo); - INP_WLOCK_ASSERT(inp); - - CTR4(KTR_CXGB, "%s: tid %d, toep %p, flags %x", __func__, tid, toep, - toep->tp_flags); - - toep->tp_flags |= TP_SEND_FIN; - t3_push_frames(so, 1); - - return (0); -} - -int -t3_tod_output(struct toedev *tod, struct tcpcb *tp) -{ - struct inpcb *inp = tp->t_inpcb; - struct socket *so = inp->inp_socket; - - t3_push_frames(so, 1); - return (0); -} - -/* What mtu_idx to use, given a 4-tuple and/or an MSS cap */ -int -find_best_mtu_idx(struct adapter *sc, struct in_conninfo *inc, int pmss) -{ - unsigned short *mtus = &sc->params.mtus[0]; - int i = 0, mss; - - KASSERT(inc != NULL || pmss > 0, - ("%s: at least one of inc/pmss must be specified", __func__)); - - mss = inc ? tcp_mssopt(inc) : pmss; - if (pmss > 0 && mss > pmss) - mss = pmss; - - while (i < NMTUS - 1 && mtus[i + 1] <= mss + 40) - ++i; - - return (i); -} - -static inline void -purge_wr_queue(struct toepcb *toep) -{ - struct mbuf *m; - struct ofld_hdr *oh; - - while ((m = mbufq_dequeue(&toep->wr_list)) != NULL) { - oh = mtod(m, struct ofld_hdr *); - if (oh->flags & F_HDR_SGL) - sglist_free(oh->sgl); - m_freem(m); - } -} - -/* - * Release cxgb(4) and T3 resources held by an offload connection (TID, L2T - * entry, etc.) - */ -static void -t3_release_offload_resources(struct toepcb *toep) -{ - struct toedev *tod = toep->tp_tod; - struct tom_data *td = t3_tomdata(tod); - - /* - * The TOM explicitly detaches its toepcb from the system's inp before - * it releases the offload resources. - */ - if (toep->tp_inp) { - panic("%s: inp %p still attached to toepcb %p", - __func__, toep->tp_inp, toep); - } - - if (toep->tp_wr_avail != toep->tp_wr_max) - purge_wr_queue(toep); - - if (toep->tp_l2t) { - l2t_release(td->l2t, toep->tp_l2t); - toep->tp_l2t = NULL; - } - - if (toep->tp_tid >= 0) - release_tid(tod, toep->tp_tid, toep->tp_qset); - - toepcb_free(toep); -} - -/* - * Determine the receive window size for a socket. - */ -unsigned long -select_rcv_wnd(struct socket *so) -{ - unsigned long wnd; - - SOCKBUF_LOCK_ASSERT(&so->so_rcv); - - wnd = sbspace(&so->so_rcv); - if (wnd < MIN_RCV_WND) - wnd = MIN_RCV_WND; - - return min(wnd, MAX_RCV_WND); -} - -int -select_rcv_wscale(void) -{ - int wscale = 0; - unsigned long space = sb_max; - - if (space > MAX_RCV_WND) - space = MAX_RCV_WND; - - while (wscale < TCP_MAX_WINSHIFT && (TCP_MAXWIN << wscale) < space) - wscale++; - - return (wscale); -} - - -/* - * Set up the socket for TCP offload. - */ -void -offload_socket(struct socket *so, struct toepcb *toep) -{ - struct toedev *tod = toep->tp_tod; - struct tom_data *td = t3_tomdata(tod); - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp = intotcpcb(inp); - - INP_WLOCK_ASSERT(inp); - - /* Update socket */ - SOCKBUF_LOCK(&so->so_snd); - so_sockbuf_snd(so)->sb_flags |= SB_NOCOALESCE; - SOCKBUF_UNLOCK(&so->so_snd); - SOCKBUF_LOCK(&so->so_rcv); - so_sockbuf_rcv(so)->sb_flags |= SB_NOCOALESCE; - SOCKBUF_UNLOCK(&so->so_rcv); - - /* Update TCP PCB */ - tp->tod = toep->tp_tod; - tp->t_toe = toep; - tp->t_flags |= TF_TOE; - - /* Install an extra hold on inp */ - toep->tp_inp = inp; - toep->tp_flags |= TP_ATTACHED; - in_pcbref(inp); - - /* Add the TOE PCB to the active list */ - mtx_lock(&td->toep_list_lock); - TAILQ_INSERT_HEAD(&td->toep_list, toep, link); - mtx_unlock(&td->toep_list_lock); -} - -/* This is _not_ the normal way to "unoffload" a socket. */ -void -undo_offload_socket(struct socket *so) -{ - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp = intotcpcb(inp); - struct toepcb *toep = tp->t_toe; - struct toedev *tod = toep->tp_tod; - struct tom_data *td = t3_tomdata(tod); - - INP_WLOCK_ASSERT(inp); - - so_sockbuf_snd(so)->sb_flags &= ~SB_NOCOALESCE; - so_sockbuf_rcv(so)->sb_flags &= ~SB_NOCOALESCE; - - tp->tod = NULL; - tp->t_toe = NULL; - tp->t_flags &= ~TF_TOE; - - toep->tp_inp = NULL; - toep->tp_flags &= ~TP_ATTACHED; - if (in_pcbrele_wlocked(inp)) - panic("%s: inp freed.", __func__); - - mtx_lock(&td->toep_list_lock); - TAILQ_REMOVE(&td->toep_list, toep, link); - mtx_unlock(&td->toep_list_lock); -} - -/* - * Socket could be a listening socket, and we may not have a toepcb at all at - * this time. - */ -uint32_t -calc_opt0h(struct socket *so, int mtu_idx, int rscale, struct l2t_entry *e) -{ - uint32_t opt0h = F_TCAM_BYPASS | V_WND_SCALE(rscale) | - V_MSS_IDX(mtu_idx); - - if (so != NULL) { - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp = intotcpcb(inp); - int keepalive = always_keepalive || - so_options_get(so) & SO_KEEPALIVE; - - opt0h |= V_NAGLE((tp->t_flags & TF_NODELAY) == 0); - opt0h |= V_KEEP_ALIVE(keepalive != 0); - } - - if (e != NULL) - opt0h |= V_L2T_IDX(e->idx) | V_TX_CHANNEL(e->smt_idx); - - return (htobe32(opt0h)); -} - -uint32_t -calc_opt0l(struct socket *so, int rcv_bufsize) -{ - uint32_t opt0l = V_ULP_MODE(ULP_MODE_NONE) | V_RCV_BUFSIZ(rcv_bufsize); - - KASSERT(rcv_bufsize <= M_RCV_BUFSIZ, - ("%s: rcv_bufsize (%d) is too high", __func__, rcv_bufsize)); - - if (so != NULL) /* optional because no one cares about IP TOS */ - opt0l |= V_TOS(INP_TOS(sotoinpcb(so))); - - return (htobe32(opt0l)); -} - -/* - * Convert an ACT_OPEN_RPL status to an errno. - */ -static int -act_open_rpl_status_to_errno(int status) -{ - switch (status) { - case CPL_ERR_CONN_RESET: - return (ECONNREFUSED); - case CPL_ERR_ARP_MISS: - return (EHOSTUNREACH); - case CPL_ERR_CONN_TIMEDOUT: - return (ETIMEDOUT); - case CPL_ERR_TCAM_FULL: - return (EAGAIN); - case CPL_ERR_CONN_EXIST: - log(LOG_ERR, "ACTIVE_OPEN_RPL: 4-tuple in use\n"); - return (EAGAIN); - default: - return (EIO); - } -} - -/* - * Return whether a failed active open has allocated a TID - */ -static inline int -act_open_has_tid(int status) -{ - return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST && - status != CPL_ERR_ARP_MISS; -} - -/* - * Active open failed. - */ -static int -do_act_open_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - struct cpl_act_open_rpl *rpl = mtod(m, void *); - unsigned int atid = G_TID(ntohl(rpl->atid)); - struct toepcb *toep = lookup_atid(&td->tid_maps, atid); - struct inpcb *inp = toep->tp_inp; - int s = rpl->status, rc; - - CTR3(KTR_CXGB, "%s: atid %u, status %u ", __func__, atid, s); - - free_atid(&td->tid_maps, atid); - toep->tp_tid = -1; - - if (act_open_has_tid(s)) - queue_tid_release(tod, GET_TID(rpl)); - - rc = act_open_rpl_status_to_errno(s); - if (rc != EAGAIN) - INP_INFO_RLOCK(&V_tcbinfo); - INP_WLOCK(inp); - toe_connect_failed(tod, inp, rc); - toepcb_release(toep); /* unlocks inp */ - if (rc != EAGAIN) - INP_INFO_RUNLOCK(&V_tcbinfo); - - m_freem(m); - return (0); -} - -/* - * Send an active open request. - * - * State of affairs on entry: - * soisconnecting (so_state |= SS_ISCONNECTING) - * tcbinfo not locked (this has changed - used to be WLOCKed) - * inp WLOCKed - * tp->t_state = TCPS_SYN_SENT - * rtalloc1, RT_UNLOCK on rt. - */ -int -t3_connect(struct toedev *tod, struct socket *so, - struct rtentry *rt, struct sockaddr *nam) -{ - struct mbuf *m = NULL; - struct l2t_entry *e = NULL; - struct tom_data *td = t3_tomdata(tod); - struct adapter *sc = tod->tod_softc; - struct cpl_act_open_req *cpl; - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp = intotcpcb(inp); - struct toepcb *toep; - int atid = -1, mtu_idx, rscale, cpu_idx, qset; - struct sockaddr *gw; - struct ifnet *ifp = rt->rt_ifp; - struct port_info *pi = ifp->if_softc; /* XXX wrong for VLAN etc. */ - - INP_WLOCK_ASSERT(inp); - - toep = toepcb_alloc(tod); - if (toep == NULL) - goto failed; - - atid = alloc_atid(&td->tid_maps, toep); - if (atid < 0) - goto failed; - - qset = pi->first_qset + (arc4random() % pi->nqsets); - - m = M_GETHDR_OFLD(qset, CPL_PRIORITY_CONTROL, cpl); - if (m == NULL) - goto failed; - - gw = rt->rt_flags & RTF_GATEWAY ? rt->rt_gateway : nam; - e = t3_l2t_get(pi, ifp, gw); - if (e == NULL) - goto failed; - - toep->tp_l2t = e; - toep->tp_tid = atid; /* used to double check response */ - toep->tp_qset = qset; - - SOCKBUF_LOCK(&so->so_rcv); - /* opt0 rcv_bufsiz initially, assumes its normal meaning later */ - toep->tp_rx_credits = min(select_rcv_wnd(so) >> 10, M_RCV_BUFSIZ); - SOCKBUF_UNLOCK(&so->so_rcv); - - offload_socket(so, toep); - - /* - * The kernel sets request_r_scale based on sb_max whereas we need to - * take hardware's MAX_RCV_WND into account too. This is normally a - * no-op as MAX_RCV_WND is much larger than the default sb_max. - */ - if (tp->t_flags & TF_REQ_SCALE) - rscale = tp->request_r_scale = select_rcv_wscale(); - else - rscale = 0; - mtu_idx = find_best_mtu_idx(sc, &inp->inp_inc, 0); - cpu_idx = sc->rrss_map[qset]; - - cpl->wr.wrh_hi = htobe32(V_WR_OP(FW_WROPCODE_FORWARD)); - cpl->wr.wrh_lo = 0; - OPCODE_TID(cpl) = htobe32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, atid)); - inp_4tuple_get(inp, &cpl->local_ip, &cpl->local_port, &cpl->peer_ip, - &cpl->peer_port); - cpl->opt0h = calc_opt0h(so, mtu_idx, rscale, e); - cpl->opt0l = calc_opt0l(so, toep->tp_rx_credits); - cpl->params = 0; - cpl->opt2 = calc_opt2(cpu_idx); - - CTR5(KTR_CXGB, "%s: atid %u (%s), toep %p, inp %p", __func__, - toep->tp_tid, tcpstates[tp->t_state], toep, inp); - - if (l2t_send(sc, m, e) == 0) - return (0); - - undo_offload_socket(so); - -failed: - CTR5(KTR_CXGB, "%s: FAILED, atid %d, toep %p, l2te %p, mbuf %p", - __func__, atid, toep, e, m); - - if (atid >= 0) - free_atid(&td->tid_maps, atid); - - if (e) - l2t_release(td->l2t, e); - - if (toep) - toepcb_free(toep); - - m_freem(m); - - return (ENOMEM); -} - -/* - * Send an ABORT_REQ message. Cannot fail. This routine makes sure we do not - * send multiple ABORT_REQs for the same connection and also that we do not try - * to send a message after the connection has closed. - */ -static void -send_reset(struct toepcb *toep) -{ - - struct cpl_abort_req *req; - unsigned int tid = toep->tp_tid; - struct inpcb *inp = toep->tp_inp; - struct socket *so = inp->inp_socket; - struct tcpcb *tp = intotcpcb(inp); - struct toedev *tod = toep->tp_tod; - struct adapter *sc = tod->tod_softc; - struct mbuf *m; - - INP_INFO_RLOCK_ASSERT(&V_tcbinfo); - INP_WLOCK_ASSERT(inp); - - CTR4(KTR_CXGB, "%s: tid %d, toep %p (%x)", __func__, tid, toep, - toep->tp_flags); - - if (toep->tp_flags & TP_ABORT_SHUTDOWN) - return; - - toep->tp_flags |= (TP_ABORT_RPL_PENDING | TP_ABORT_SHUTDOWN); - - /* Purge the send queue */ - sbflush(so_sockbuf_snd(so)); - purge_wr_queue(toep); - - m = M_GETHDR_OFLD(toep->tp_qset, CPL_PRIORITY_DATA, req); - if (m == NULL) - CXGB_UNIMPLEMENTED(); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ)); - req->wr.wrh_lo = htonl(V_WR_TID(tid)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, tid)); - req->rsvd0 = htonl(tp->snd_nxt); - req->rsvd1 = !(toep->tp_flags & TP_DATASENT); - req->cmd = CPL_ABORT_SEND_RST; - - if (tp->t_state == TCPS_SYN_SENT) - (void )mbufq_enqueue(&toep->out_of_order_queue, m); /* defer */ - else - l2t_send(sc, m, toep->tp_l2t); -} - -int -t3_send_rst(struct toedev *tod __unused, struct tcpcb *tp) -{ - - send_reset(tp->t_toe); - return (0); -} - -/* - * Handler for RX_DATA CPL messages. - */ -static int -do_rx_data(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_rx_data *hdr = mtod(m, void *); - unsigned int tid = GET_TID(hdr); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct inpcb *inp = toep->tp_inp; - struct tcpcb *tp; - struct socket *so; - struct sockbuf *so_rcv; - - /* Advance over CPL */ - m_adj(m, sizeof(*hdr)); - - /* XXX: revisit. This comes from the T4 TOM */ - if (__predict_false(inp == NULL)) { - /* - * do_pass_establish failed and must be attempting to abort the - * connection. Meanwhile, the T4 has sent us data for such a - * connection. - */ -#ifdef notyet - KASSERT(toepcb_flag(toep, TPF_ABORT_SHUTDOWN), - ("%s: inp NULL and tid isn't being aborted", __func__)); -#endif - m_freem(m); - return (0); - } - - INP_WLOCK(inp); - if (inp->inp_flags & (INP_DROPPED | INP_TIMEWAIT)) { - CTR4(KTR_CXGB, "%s: tid %u, rx (%d bytes), inp_flags 0x%x", - __func__, tid, m->m_pkthdr.len, inp->inp_flags); - INP_WUNLOCK(inp); - m_freem(m); - return (0); - } - - if (__predict_false(hdr->dack_mode != toep->tp_delack_mode)) - toep->tp_delack_mode = hdr->dack_mode; - - tp = intotcpcb(inp); - -#ifdef INVARIANTS - if (__predict_false(tp->rcv_nxt != be32toh(hdr->seq))) { - log(LOG_ERR, - "%s: unexpected seq# %x for TID %u, rcv_nxt %x\n", - __func__, be32toh(hdr->seq), toep->tp_tid, tp->rcv_nxt); - } -#endif - tp->rcv_nxt += m->m_pkthdr.len; - KASSERT(tp->rcv_wnd >= m->m_pkthdr.len, - ("%s: negative window size", __func__)); - tp->rcv_wnd -= m->m_pkthdr.len; - tp->t_rcvtime = ticks; - - so = inp->inp_socket; - so_rcv = &so->so_rcv; - SOCKBUF_LOCK(so_rcv); - - if (__predict_false(so_rcv->sb_state & SBS_CANTRCVMORE)) { - CTR3(KTR_CXGB, "%s: tid %u, excess rx (%d bytes)", - __func__, tid, m->m_pkthdr.len); - SOCKBUF_UNLOCK(so_rcv); - INP_WUNLOCK(inp); - - INP_INFO_RLOCK(&V_tcbinfo); - INP_WLOCK(inp); - tp = tcp_drop(tp, ECONNRESET); - if (tp) - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - - m_freem(m); - return (0); - } - - /* receive buffer autosize */ - if (so_rcv->sb_flags & SB_AUTOSIZE && - V_tcp_do_autorcvbuf && - so_rcv->sb_hiwat < V_tcp_autorcvbuf_max && - (m->m_pkthdr.len > (sbspace(so_rcv) / 8 * 7) || tp->rcv_wnd < 32768)) { - unsigned int hiwat = so_rcv->sb_hiwat; - unsigned int newsize = min(hiwat + V_tcp_autorcvbuf_inc, - V_tcp_autorcvbuf_max); - - if (!sbreserve_locked(so_rcv, newsize, so, NULL)) - so_rcv->sb_flags &= ~SB_AUTOSIZE; - else - toep->tp_rx_credits += newsize - hiwat; - } - - toep->tp_enqueued += m->m_pkthdr.len; - sbappendstream_locked(so_rcv, m, 0); - sorwakeup_locked(so); - SOCKBUF_UNLOCK_ASSERT(so_rcv); - - INP_WUNLOCK(inp); - return (0); -} - -/* - * Handler for PEER_CLOSE CPL messages. - */ -static int -do_peer_close(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - const struct cpl_peer_close *hdr = mtod(m, void *); - unsigned int tid = GET_TID(hdr); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct inpcb *inp = toep->tp_inp; - struct tcpcb *tp; - struct socket *so; - - INP_INFO_RLOCK(&V_tcbinfo); - INP_WLOCK(inp); - tp = intotcpcb(inp); - - CTR5(KTR_CXGB, "%s: tid %u (%s), toep_flags 0x%x, inp %p", __func__, - tid, tp ? tcpstates[tp->t_state] : "no tp" , toep->tp_flags, inp); - - if (toep->tp_flags & TP_ABORT_RPL_PENDING) - goto done; - - so = inp_inpcbtosocket(inp); - - socantrcvmore(so); - tp->rcv_nxt++; - - switch (tp->t_state) { - case TCPS_SYN_RECEIVED: - tp->t_starttime = ticks; - /* FALLTHROUGH */ - case TCPS_ESTABLISHED: - tp->t_state = TCPS_CLOSE_WAIT; - break; - case TCPS_FIN_WAIT_1: - tp->t_state = TCPS_CLOSING; - break; - case TCPS_FIN_WAIT_2: - tcp_twstart(tp); - INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */ - INP_INFO_RUNLOCK(&V_tcbinfo); - - INP_WLOCK(inp); - toepcb_release(toep); /* no more CPLs expected */ - - m_freem(m); - return (0); - default: - log(LOG_ERR, "%s: TID %u received PEER_CLOSE in bad state %d\n", - __func__, toep->tp_tid, tp->t_state); - } - -done: - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - - m_freem(m); - return (0); -} - -/* - * Handler for CLOSE_CON_RPL CPL messages. peer ACK to our FIN received. - */ -static int -do_close_con_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - const struct cpl_close_con_rpl *rpl = mtod(m, void *); - unsigned int tid = GET_TID(rpl); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct inpcb *inp = toep->tp_inp; - struct tcpcb *tp; - struct socket *so; - - INP_INFO_RLOCK(&V_tcbinfo); - INP_WLOCK(inp); - tp = intotcpcb(inp); - - CTR4(KTR_CXGB, "%s: tid %u (%s), toep_flags 0x%x", __func__, tid, - tp ? tcpstates[tp->t_state] : "no tp", toep->tp_flags); - - if ((toep->tp_flags & TP_ABORT_RPL_PENDING)) - goto done; - - so = inp_inpcbtosocket(inp); - tp->snd_una = ntohl(rpl->snd_nxt) - 1; /* exclude FIN */ - - switch (tp->t_state) { - case TCPS_CLOSING: - tcp_twstart(tp); -release: - INP_UNLOCK_ASSERT(inp); /* safe, we have a ref on the inp */ - INP_INFO_RUNLOCK(&V_tcbinfo); - - INP_WLOCK(inp); - toepcb_release(toep); /* no more CPLs expected */ - - m_freem(m); - return (0); - case TCPS_LAST_ACK: - if (tcp_close(tp)) - INP_WUNLOCK(inp); - goto release; - - case TCPS_FIN_WAIT_1: - if (so->so_rcv.sb_state & SBS_CANTRCVMORE) - soisdisconnected(so); - tp->t_state = TCPS_FIN_WAIT_2; - break; - default: - log(LOG_ERR, - "%s: TID %u received CLOSE_CON_RPL in bad state %d\n", - __func__, toep->tp_tid, tp->t_state); - } - -done: - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - - m_freem(m); - return (0); -} - -static int -do_smt_write_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct cpl_smt_write_rpl *rpl = mtod(m, void *); - - if (rpl->status != CPL_ERR_NONE) { - log(LOG_ERR, - "Unexpected SMT_WRITE_RPL status %u for entry %u\n", - rpl->status, GET_TID(rpl)); - } - - m_freem(m); - return (0); -} - -static int -do_set_tcb_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct cpl_set_tcb_rpl *rpl = mtod(m, void *); - - if (rpl->status != CPL_ERR_NONE) { - log(LOG_ERR, "Unexpected SET_TCB_RPL status %u for tid %u\n", - rpl->status, GET_TID(rpl)); - } - - m_freem(m); - return (0); -} - -/* - * Handle an ABORT_RPL_RSS CPL message. - */ -static int -do_abort_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - const struct cpl_abort_rpl_rss *rpl = mtod(m, void *); - unsigned int tid = GET_TID(rpl); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct inpcb *inp; - - /* - * Ignore replies to post-close aborts indicating that the abort was - * requested too late. These connections are terminated when we get - * PEER_CLOSE or CLOSE_CON_RPL and by the time the abort_rpl_rss - * arrives the TID is either no longer used or it has been recycled. - */ - if (rpl->status == CPL_ERR_ABORT_FAILED) { - m_freem(m); - return (0); - } - - if (toep->tp_flags & TP_IS_A_SYNQ_ENTRY) - return (do_abort_rpl_synqe(qs, r, m)); - - CTR4(KTR_CXGB, "%s: tid %d, toep %p, status %d", __func__, tid, toep, - rpl->status); - - inp = toep->tp_inp; - INP_WLOCK(inp); - - if (toep->tp_flags & TP_ABORT_RPL_PENDING) { - if (!(toep->tp_flags & TP_ABORT_RPL_RCVD)) { - toep->tp_flags |= TP_ABORT_RPL_RCVD; - INP_WUNLOCK(inp); - } else { - toep->tp_flags &= ~TP_ABORT_RPL_RCVD; - toep->tp_flags &= TP_ABORT_RPL_PENDING; - toepcb_release(toep); /* no more CPLs expected */ - } - } - - m_freem(m); - return (0); -} - -/* - * Convert the status code of an ABORT_REQ into a FreeBSD error code. - */ -static int -abort_status_to_errno(struct tcpcb *tp, int abort_reason) -{ - switch (abort_reason) { - case CPL_ERR_BAD_SYN: - case CPL_ERR_CONN_RESET: - return (tp->t_state == TCPS_CLOSE_WAIT ? EPIPE : ECONNRESET); - case CPL_ERR_XMIT_TIMEDOUT: - case CPL_ERR_PERSIST_TIMEDOUT: - case CPL_ERR_FINWAIT2_TIMEDOUT: - case CPL_ERR_KEEPALIVE_TIMEDOUT: - return (ETIMEDOUT); - default: - return (EIO); - } -} - -/* - * Returns whether an ABORT_REQ_RSS message is a negative advice. - */ -static inline int -is_neg_adv_abort(unsigned int status) -{ - return status == CPL_ERR_RTX_NEG_ADVICE || - status == CPL_ERR_PERSIST_NEG_ADVICE; -} - -void -send_abort_rpl(struct toedev *tod, int tid, int qset) -{ - struct mbuf *reply; - struct cpl_abort_rpl *rpl; - struct adapter *sc = tod->tod_softc; - - reply = M_GETHDR_OFLD(qset, CPL_PRIORITY_DATA, rpl); - if (!reply) - CXGB_UNIMPLEMENTED(); - - rpl->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL)); - rpl->wr.wrh_lo = htonl(V_WR_TID(tid)); - OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, tid)); - rpl->cmd = CPL_ABORT_NO_RST; - - t3_offload_tx(sc, reply); -} - -/* - * Handle an ABORT_REQ_RSS CPL message. If we're waiting for an ABORT_RPL we - * ignore this request except that we need to reply to it. - */ -static int -do_abort_req(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - const struct cpl_abort_req_rss *req = mtod(m, void *); - unsigned int tid = GET_TID(req); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - struct inpcb *inp; - struct tcpcb *tp; - struct socket *so; - int qset = toep->tp_qset; - - if (is_neg_adv_abort(req->status)) { - CTR4(KTR_CXGB, "%s: negative advice %d for tid %u (%x)", - __func__, req->status, tid, toep->tp_flags); - m_freem(m); - return (0); - } - - if (toep->tp_flags & TP_IS_A_SYNQ_ENTRY) - return (do_abort_req_synqe(qs, r, m)); - - inp = toep->tp_inp; - INP_INFO_RLOCK(&V_tcbinfo); /* for tcp_close */ - INP_WLOCK(inp); - - tp = intotcpcb(inp); - so = inp->inp_socket; - - CTR6(KTR_CXGB, "%s: tid %u (%s), toep %p (%x), status %d", - __func__, tid, tcpstates[tp->t_state], toep, toep->tp_flags, - req->status); - - if (!(toep->tp_flags & TP_ABORT_REQ_RCVD)) { - toep->tp_flags |= TP_ABORT_REQ_RCVD; - toep->tp_flags |= TP_ABORT_SHUTDOWN; - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - m_freem(m); - return (0); - } - toep->tp_flags &= ~TP_ABORT_REQ_RCVD; - - /* - * If we'd sent a reset on this toep, we'll ignore this and clean up in - * the T3's reply to our reset instead. - */ - if (toep->tp_flags & TP_ABORT_RPL_PENDING) { - toep->tp_flags |= TP_ABORT_RPL_SENT; - INP_WUNLOCK(inp); - } else { - so_error_set(so, abort_status_to_errno(tp, req->status)); - tp = tcp_close(tp); - if (tp == NULL) - INP_WLOCK(inp); /* re-acquire */ - toepcb_release(toep); /* no more CPLs expected */ - } - INP_INFO_RUNLOCK(&V_tcbinfo); - - send_abort_rpl(tod, tid, qset); - m_freem(m); - return (0); -} - -static void -assign_rxopt(struct tcpcb *tp, uint16_t tcpopt) -{ - struct toepcb *toep = tp->t_toe; - struct adapter *sc = toep->tp_tod->tod_softc; - - tp->t_maxseg = sc->params.mtus[G_TCPOPT_MSS(tcpopt)] - 40; - - if (G_TCPOPT_TSTAMP(tcpopt)) { - tp->t_flags |= TF_RCVD_TSTMP; - tp->t_flags |= TF_REQ_TSTMP; /* forcibly set */ - tp->ts_recent = 0; /* XXX */ - tp->ts_recent_age = tcp_ts_getticks(); - } - - if (G_TCPOPT_SACK(tcpopt)) - tp->t_flags |= TF_SACK_PERMIT; - else - tp->t_flags &= ~TF_SACK_PERMIT; - - if (G_TCPOPT_WSCALE_OK(tcpopt)) - tp->t_flags |= TF_RCVD_SCALE; - - if ((tp->t_flags & (TF_RCVD_SCALE | TF_REQ_SCALE)) == - (TF_RCVD_SCALE | TF_REQ_SCALE)) { - tp->rcv_scale = tp->request_r_scale; - tp->snd_scale = G_TCPOPT_SND_WSCALE(tcpopt); - } - -} - -/* - * The ISS and IRS are from after the exchange of SYNs and are off by 1. - */ -void -make_established(struct socket *so, uint32_t cpl_iss, uint32_t cpl_irs, - uint16_t cpl_tcpopt) -{ - struct inpcb *inp = sotoinpcb(so); - struct tcpcb *tp = intotcpcb(inp); - struct toepcb *toep = tp->t_toe; - long bufsize; - uint32_t iss = be32toh(cpl_iss) - 1; /* true ISS */ - uint32_t irs = be32toh(cpl_irs) - 1; /* true IRS */ - uint16_t tcpopt = be16toh(cpl_tcpopt); - - INP_WLOCK_ASSERT(inp); - - tp->t_state = TCPS_ESTABLISHED; - tp->t_starttime = ticks; - TCPSTAT_INC(tcps_connects); - - CTR4(KTR_CXGB, "%s tid %u, toep %p, inp %p", tcpstates[tp->t_state], - toep->tp_tid, toep, inp); - - tp->irs = irs; - tcp_rcvseqinit(tp); - tp->rcv_wnd = toep->tp_rx_credits << 10; - tp->rcv_adv += tp->rcv_wnd; - tp->last_ack_sent = tp->rcv_nxt; - - /* - * If we were unable to send all rx credits via opt0, save the remainder - * in rx_credits so that they can be handed over with the next credit - * update. - */ - SOCKBUF_LOCK(&so->so_rcv); - bufsize = select_rcv_wnd(so); - SOCKBUF_UNLOCK(&so->so_rcv); - toep->tp_rx_credits = bufsize - tp->rcv_wnd; - - tp->iss = iss; - tcp_sendseqinit(tp); - tp->snd_una = iss + 1; - tp->snd_nxt = iss + 1; - tp->snd_max = iss + 1; - - assign_rxopt(tp, tcpopt); - soisconnected(so); -} - -/* - * Fill in the right TID for CPL messages waiting in the out-of-order queue - * and send them to the TOE. - */ -static void -fixup_and_send_ofo(struct toepcb *toep) -{ - struct mbuf *m; - struct toedev *tod = toep->tp_tod; - struct adapter *sc = tod->tod_softc; - unsigned int tid = toep->tp_tid; - - inp_lock_assert(toep->tp_inp); - - while ((m = mbufq_dequeue(&toep->out_of_order_queue)) != NULL) { - struct ofld_hdr *oh = mtod(m, void *); - /* - * A variety of messages can be waiting but the fields we'll - * be touching are common to all so any message type will do. - */ - struct cpl_close_con_req *p = (void *)(oh + 1); - - p->wr.wrh_lo = htonl(V_WR_TID(tid)); - OPCODE_TID(p) = htonl(MK_OPCODE_TID(p->ot.opcode, tid)); - t3_offload_tx(sc, m); - } -} - -/* - * Process a CPL_ACT_ESTABLISH message. - */ -static int -do_act_establish(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_act_establish *req = mtod(m, void *); - unsigned int tid = GET_TID(req); - unsigned int atid = G_PASS_OPEN_TID(ntohl(req->tos_tid)); - struct toepcb *toep = lookup_atid(&td->tid_maps, atid); - struct inpcb *inp = toep->tp_inp; - struct tcpcb *tp; - struct socket *so; - - CTR3(KTR_CXGB, "%s: atid %u, tid %u", __func__, atid, tid); - - free_atid(&td->tid_maps, atid); - - INP_WLOCK(inp); - tp = intotcpcb(inp); - - KASSERT(toep->tp_qset == qs->idx, - ("%s qset mismatch %d %d", __func__, toep->tp_qset, qs->idx)); - KASSERT(toep->tp_tid == atid, - ("%s atid mismatch %d %d", __func__, toep->tp_tid, atid)); - - toep->tp_tid = tid; - insert_tid(td, toep, tid); - - if (inp->inp_flags & INP_DROPPED) { - /* socket closed by the kernel before hw told us it connected */ - send_reset(toep); - goto done; - } - - KASSERT(tp->t_state == TCPS_SYN_SENT, - ("TID %u expected TCPS_SYN_SENT, found %d.", tid, tp->t_state)); - - so = inp->inp_socket; - make_established(so, req->snd_isn, req->rcv_isn, req->tcp_opt); - - /* - * Now that we finally have a TID send any CPL messages that we had to - * defer for lack of a TID. - */ - if (mbufq_len(&toep->out_of_order_queue)) - fixup_and_send_ofo(toep); - -done: - INP_WUNLOCK(inp); - m_freem(m); - return (0); -} - -/* - * Process an acknowledgment of WR completion. Advance snd_una and send the - * next batch of work requests from the write queue. - */ -static void -wr_ack(struct toepcb *toep, struct mbuf *m) -{ - struct inpcb *inp = toep->tp_inp; - struct tcpcb *tp; - struct cpl_wr_ack *hdr = mtod(m, void *); - struct socket *so; - unsigned int credits = ntohs(hdr->credits); - u32 snd_una = ntohl(hdr->snd_una); - int bytes = 0; - struct sockbuf *snd; - struct mbuf *p; - struct ofld_hdr *oh; - - inp_wlock(inp); - tp = intotcpcb(inp); - so = inp->inp_socket; - toep->tp_wr_avail += credits; - if (toep->tp_wr_unacked > toep->tp_wr_max - toep->tp_wr_avail) - toep->tp_wr_unacked = toep->tp_wr_max - toep->tp_wr_avail; - - while (credits) { - p = peek_wr(toep); - - if (__predict_false(!p)) { - CTR5(KTR_CXGB, "%s: %u extra WR_ACK credits, " - "tid %u, state %u, wr_avail %u", __func__, credits, - toep->tp_tid, tp->t_state, toep->tp_wr_avail); - - log(LOG_ERR, "%u WR_ACK credits for TID %u with " - "nothing pending, state %u wr_avail=%u\n", - credits, toep->tp_tid, tp->t_state, toep->tp_wr_avail); - break; - } - - oh = mtod(p, struct ofld_hdr *); - - KASSERT(credits >= G_HDR_NDESC(oh->flags), - ("%s: partial credits? %d %d", __func__, credits, - G_HDR_NDESC(oh->flags))); - - dequeue_wr(toep); - credits -= G_HDR_NDESC(oh->flags); - bytes += oh->plen; - - if (oh->flags & F_HDR_SGL) - sglist_free(oh->sgl); - m_freem(p); - } - - if (__predict_false(SEQ_LT(snd_una, tp->snd_una))) - goto out_free; - - if (tp->snd_una != snd_una) { - tp->snd_una = snd_una; - tp->ts_recent_age = tcp_ts_getticks(); - if (tp->snd_una == tp->snd_nxt) - toep->tp_flags &= ~TP_TX_WAIT_IDLE; - } - - snd = so_sockbuf_snd(so); - if (bytes) { - SOCKBUF_LOCK(snd); - sbdrop_locked(snd, bytes); - so_sowwakeup_locked(so); - } - - if (snd->sb_sndptroff < sbused(snd)) - t3_push_frames(so, 0); - -out_free: - inp_wunlock(tp->t_inpcb); - m_freem(m); -} - -/* - * Handler for TX_DATA_ACK CPL messages. - */ -static int -do_wr_ack(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_wr_ack *hdr = mtod(m, void *); - unsigned int tid = GET_TID(hdr); - struct toepcb *toep = lookup_tid(&td->tid_maps, tid); - - /* XXX bad race */ - if (toep) - wr_ack(toep, m); - - return (0); -} - -void -t3_init_cpl_io(struct adapter *sc) -{ - t3_register_cpl_handler(sc, CPL_ACT_ESTABLISH, do_act_establish); - t3_register_cpl_handler(sc, CPL_ACT_OPEN_RPL, do_act_open_rpl); - t3_register_cpl_handler(sc, CPL_RX_URG_NOTIFY, do_rx_urg_notify); - t3_register_cpl_handler(sc, CPL_RX_DATA, do_rx_data); - t3_register_cpl_handler(sc, CPL_TX_DMA_ACK, do_wr_ack); - t3_register_cpl_handler(sc, CPL_PEER_CLOSE, do_peer_close); - t3_register_cpl_handler(sc, CPL_ABORT_REQ_RSS, do_abort_req); - t3_register_cpl_handler(sc, CPL_ABORT_RPL_RSS, do_abort_rpl); - t3_register_cpl_handler(sc, CPL_CLOSE_CON_RPL, do_close_con_rpl); - t3_register_cpl_handler(sc, CPL_SMT_WRITE_RPL, do_smt_write_rpl); - t3_register_cpl_handler(sc, CPL_SET_TCB_RPL, do_set_tcb_rpl); -} -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_l2t.c b/sys/dev/cxgb/ulp/tom/cxgb_l2t.c deleted file mode 100644 index c2390ae2f93d..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_l2t.c +++ /dev/null @@ -1,460 +0,0 @@ -/*- - * Copyright (c) 2012 Chelsio Communications, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cxgb_include.h" -#include "ulp/tom/cxgb_tom.h" -#include "ulp/tom/cxgb_l2t.h" - -#define VLAN_NONE 0xfff -#define SA(x) ((struct sockaddr *)(x)) -#define SIN(x) ((struct sockaddr_in *)(x)) -#define SINADDR(x) (SIN(x)->sin_addr.s_addr) - -/* - * Module locking notes: There is a RW lock protecting the L2 table as a - * whole plus a mutex per L2T entry. Entry lookups and allocations happen - * under the protection of the table lock, individual entry changes happen - * while holding that entry's mutex. The table lock nests outside the - * entry locks. Allocations of new entries take the table lock as writers so - * no other lookups can happen while allocating new entries. Entry updates - * take the table lock as readers so multiple entries can be updated in - * parallel. An L2T entry can be dropped by decrementing its reference count - * and therefore can happen in parallel with entry allocation but no entry - * can change state or increment its ref count during allocation as both of - * these perform lookups. - * - * When acquiring multiple locks, the order is llentry -> L2 table -> L2 entry. - */ - -static inline unsigned int -arp_hash(u32 key, int ifindex, const struct l2t_data *d) -{ - return jhash_2words(key, ifindex, 0) & (d->nentries - 1); -} - -/* - * Set up an L2T entry and send any packets waiting in the arp queue. Must be - * called with the entry locked. - */ -static int -setup_l2e_send_pending(struct adapter *sc, struct l2t_entry *e) -{ - struct mbuf *m; - struct cpl_l2t_write_req *req; - struct port_info *pi = &sc->port[e->smt_idx]; /* smt_idx is port_id */ - - mtx_assert(&e->lock, MA_OWNED); - - m = M_GETHDR_OFLD(pi->first_qset, CPL_PRIORITY_CONTROL, req); - if (m == NULL) { - log(LOG_ERR, "%s: no mbuf, can't setup L2 entry at index %d\n", - __func__, e->idx); - return (ENOMEM); - } - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_L2T_WRITE_REQ, e->idx)); - req->params = htonl(V_L2T_W_IDX(e->idx) | V_L2T_W_IFF(e->smt_idx) | - V_L2T_W_VLAN(e->vlan & EVL_VLID_MASK) | - V_L2T_W_PRIO(EVL_PRIOFTAG(e->vlan))); - memcpy(req->dst_mac, e->dmac, sizeof(req->dst_mac)); - - t3_offload_tx(sc, m); - - /* - * XXX: We used pi->first_qset to send the L2T_WRITE_REQ. If any mbuf - * on the arpq is going out via another queue set associated with the - * port then it has a bad race with the L2T_WRITE_REQ. Ideally we - * should wait till the reply to the write before draining the arpq. - */ - while (e->arpq_head) { - m = e->arpq_head; - e->arpq_head = m->m_next; - m->m_next = NULL; - t3_offload_tx(sc, m); - } - e->arpq_tail = NULL; - - return (0); -} - -/* - * Add a packet to the an L2T entry's queue of packets awaiting resolution. - * Must be called with the entry's lock held. - */ -static inline void -arpq_enqueue(struct l2t_entry *e, struct mbuf *m) -{ - mtx_assert(&e->lock, MA_OWNED); - - m->m_next = NULL; - if (e->arpq_head) - e->arpq_tail->m_next = m; - else - e->arpq_head = m; - e->arpq_tail = m; -} - -static void -resolution_failed_mbuf(struct mbuf *m) -{ - log(LOG_ERR, "%s: leaked mbuf %p, CPL at %p", - __func__, m, mtod(m, void *)); -} - -static void -resolution_failed(struct l2t_entry *e) -{ - struct mbuf *m; - - mtx_assert(&e->lock, MA_OWNED); - - while (e->arpq_head) { - m = e->arpq_head; - e->arpq_head = m->m_next; - m->m_next = NULL; - resolution_failed_mbuf(m); - } - e->arpq_tail = NULL; -} - -static void -update_entry(struct adapter *sc, struct l2t_entry *e, uint8_t *lladdr, - uint16_t vtag) -{ - - mtx_assert(&e->lock, MA_OWNED); - - /* - * The entry may be in active use (e->refcount > 0) or not. We update - * it even when it's not as this simplifies the case where we decide to - * reuse the entry later. - */ - - if (lladdr == NULL && - (e->state == L2T_STATE_RESOLVING || e->state == L2T_STATE_FAILED)) { - /* - * Never got a valid L2 address for this one. Just mark it as - * failed instead of removing it from the hash (for which we'd - * need to wlock the table). - */ - e->state = L2T_STATE_FAILED; - resolution_failed(e); - return; - - } else if (lladdr == NULL) { - - /* Valid or already-stale entry was deleted (or expired) */ - - KASSERT(e->state == L2T_STATE_VALID || - e->state == L2T_STATE_STALE, - ("%s: lladdr NULL, state %d", __func__, e->state)); - - e->state = L2T_STATE_STALE; - - } else { - - if (e->state == L2T_STATE_RESOLVING || - e->state == L2T_STATE_FAILED || - memcmp(e->dmac, lladdr, ETHER_ADDR_LEN)) { - - /* unresolved -> resolved; or dmac changed */ - - memcpy(e->dmac, lladdr, ETHER_ADDR_LEN); - e->vlan = vtag; - setup_l2e_send_pending(sc, e); - } - e->state = L2T_STATE_VALID; - } -} - -static int -resolve_entry(struct adapter *sc, struct l2t_entry *e) -{ - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - struct sockaddr_in sin = {0}; - uint8_t dmac[ETHER_HDR_LEN]; - uint16_t vtag = EVL_VLID_MASK; - int rc; - - sin.sin_family = AF_INET; - sin.sin_len = sizeof(struct sockaddr_in); - SINADDR(&sin) = e->addr; - - rc = toe_l2_resolve(tod, e->ifp, SA(&sin), dmac, &vtag); - if (rc == EWOULDBLOCK) - return (rc); - - mtx_lock(&e->lock); - update_entry(sc, e, rc == 0 ? dmac : NULL, vtag); - mtx_unlock(&e->lock); - - return (rc); -} - -int -t3_l2t_send_slow(struct adapter *sc, struct mbuf *m, struct l2t_entry *e) -{ - -again: - switch (e->state) { - case L2T_STATE_STALE: /* entry is stale, kick off revalidation */ - - if (resolve_entry(sc, e) != EWOULDBLOCK) - goto again; /* entry updated, re-examine state */ - - /* Fall through */ - - case L2T_STATE_VALID: /* fast-path, send the packet on */ - - return (t3_offload_tx(sc, m)); - - case L2T_STATE_RESOLVING: - mtx_lock(&e->lock); - if (e->state != L2T_STATE_RESOLVING) { - mtx_unlock(&e->lock); - goto again; - } - arpq_enqueue(e, m); - mtx_unlock(&e->lock); - - if (resolve_entry(sc, e) == EWOULDBLOCK) - break; - - mtx_lock(&e->lock); - if (e->state == L2T_STATE_VALID && e->arpq_head) - setup_l2e_send_pending(sc, e); - if (e->state == L2T_STATE_FAILED) - resolution_failed(e); - mtx_unlock(&e->lock); - break; - - case L2T_STATE_FAILED: - resolution_failed_mbuf(m); - return (EHOSTUNREACH); - } - - return (0); -} - -/* - * Allocate a free L2T entry. Must be called with l2t_data.lock held. - */ -static struct l2t_entry * -alloc_l2e(struct l2t_data *d) -{ - struct l2t_entry *end, *e, **p; - - rw_assert(&d->lock, RA_WLOCKED); - - if (!atomic_load_acq_int(&d->nfree)) - return (NULL); - - /* there's definitely a free entry */ - for (e = d->rover, end = &d->l2tab[d->nentries]; e != end; ++e) { - if (atomic_load_acq_int(&e->refcnt) == 0) - goto found; - } - - for (e = &d->l2tab[1]; atomic_load_acq_int(&e->refcnt); ++e) - continue; -found: - d->rover = e + 1; - atomic_add_int(&d->nfree, -1); - - /* - * The entry we found may be an inactive entry that is - * presently in the hash table. We need to remove it. - */ - if (e->state != L2T_STATE_UNUSED) { - int hash = arp_hash(e->addr, e->ifp->if_index, d); - - for (p = &d->l2tab[hash].first; *p; p = &(*p)->next) { - if (*p == e) { - *p = e->next; - break; - } - } - e->state = L2T_STATE_UNUSED; - } - - return (e); -} - -struct l2t_entry * -t3_l2t_get(struct port_info *pi, struct ifnet *ifp, struct sockaddr *sa) -{ - struct tom_data *td = pi->adapter->tom_softc; - struct l2t_entry *e; - struct l2t_data *d = td->l2t; - uint32_t addr = SINADDR(sa); - int hash = arp_hash(addr, ifp->if_index, d); - unsigned int smt_idx = pi->port_id; - - rw_wlock(&d->lock); - for (e = d->l2tab[hash].first; e; e = e->next) { - if (e->addr == addr && e->ifp == ifp && e->smt_idx == smt_idx) { - l2t_hold(d, e); - goto done; - } - } - - /* Need to allocate a new entry */ - e = alloc_l2e(d); - if (e) { - mtx_lock(&e->lock); /* avoid race with t3_l2t_free */ - e->next = d->l2tab[hash].first; - d->l2tab[hash].first = e; - - e->state = L2T_STATE_RESOLVING; - e->addr = addr; - e->ifp = ifp; - e->smt_idx = smt_idx; - atomic_store_rel_int(&e->refcnt, 1); - - KASSERT(ifp->if_vlantrunk == NULL, ("TOE+VLAN unimplemented.")); - e->vlan = VLAN_NONE; - - mtx_unlock(&e->lock); - } - -done: - rw_wunlock(&d->lock); - - return (e); -} - -void -t3_l2_update(struct toedev *tod, struct ifnet *ifp, struct sockaddr *sa, - uint8_t *lladdr, uint16_t vtag) -{ - struct tom_data *td = t3_tomdata(tod); - struct adapter *sc = tod->tod_softc; - struct l2t_entry *e; - struct l2t_data *d = td->l2t; - u32 addr = *(u32 *) &SIN(sa)->sin_addr; - int hash = arp_hash(addr, ifp->if_index, d); - - rw_rlock(&d->lock); - for (e = d->l2tab[hash].first; e; e = e->next) - if (e->addr == addr && e->ifp == ifp) { - mtx_lock(&e->lock); - goto found; - } - rw_runlock(&d->lock); - - /* - * This is of no interest to us. We've never had an offloaded - * connection to this destination, and we aren't attempting one right - * now. - */ - return; - -found: - rw_runlock(&d->lock); - - KASSERT(e->state != L2T_STATE_UNUSED, - ("%s: unused entry in the hash.", __func__)); - - update_entry(sc, e, lladdr, vtag); - mtx_unlock(&e->lock); -} - -struct l2t_data * -t3_init_l2t(unsigned int l2t_capacity) -{ - struct l2t_data *d; - int i, size = sizeof(*d) + l2t_capacity * sizeof(struct l2t_entry); - - d = malloc(size, M_CXGB, M_NOWAIT | M_ZERO); - if (!d) - return (NULL); - - d->nentries = l2t_capacity; - d->rover = &d->l2tab[1]; /* entry 0 is not used */ - atomic_store_rel_int(&d->nfree, l2t_capacity - 1); - rw_init(&d->lock, "L2T"); - - for (i = 0; i < l2t_capacity; ++i) { - d->l2tab[i].idx = i; - d->l2tab[i].state = L2T_STATE_UNUSED; - mtx_init(&d->l2tab[i].lock, "L2T_E", NULL, MTX_DEF); - atomic_store_rel_int(&d->l2tab[i].refcnt, 0); - } - return (d); -} - -void -t3_free_l2t(struct l2t_data *d) -{ - int i; - - rw_destroy(&d->lock); - for (i = 0; i < d->nentries; ++i) - mtx_destroy(&d->l2tab[i].lock); - - free(d, M_CXGB); -} - -static int -do_l2t_write_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct cpl_l2t_write_rpl *rpl = mtod(m, void *); - - if (rpl->status != CPL_ERR_NONE) - log(LOG_ERR, - "Unexpected L2T_WRITE_RPL status %u for entry %u\n", - rpl->status, GET_TID(rpl)); - - m_freem(m); - return (0); -} - -void -t3_init_l2t_cpl_handlers(struct adapter *sc) -{ - t3_register_cpl_handler(sc, CPL_L2T_WRITE_RPL, do_l2t_write_rpl); -} -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_l2t.h b/sys/dev/cxgb/ulp/tom/cxgb_l2t.h deleted file mode 100644 index d3ddf9d50bf3..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_l2t.h +++ /dev/null @@ -1,114 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007-2009, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -$FreeBSD$ - -***************************************************************************/ -#ifndef _CHELSIO_L2T_H -#define _CHELSIO_L2T_H - -#include -#include - -enum { - L2T_SIZE = 2048 -}; - -enum { - L2T_STATE_VALID, /* entry is up to date */ - L2T_STATE_STALE, /* entry may be used but needs revalidation */ - L2T_STATE_RESOLVING, /* entry needs address resolution */ - L2T_STATE_FAILED, /* failed to resolve */ - L2T_STATE_UNUSED /* entry not in use */ -}; - -/* - * Each L2T entry plays multiple roles. First of all, it keeps state for the - * corresponding entry of the HW L2 table and maintains a queue of offload - * packets awaiting address resolution. Second, it is a node of a hash table - * chain, where the nodes of the chain are linked together through their next - * pointer. Finally, each node is a bucket of a hash table, pointing to the - * first element in its chain through its first pointer. - */ -struct l2t_entry { - uint16_t state; /* entry state */ - uint16_t idx; /* entry index */ - uint32_t addr; /* nexthop IP address */ - struct ifnet *ifp; /* outgoing interface */ - uint16_t smt_idx; /* SMT index */ - uint16_t vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */ - struct l2t_entry *first; /* start of hash chain */ - struct l2t_entry *next; /* next l2t_entry on chain */ - struct mbuf *arpq_head; /* queue of packets awaiting resolution */ - struct mbuf *arpq_tail; - struct mtx lock; - volatile uint32_t refcnt; /* entry reference count */ - uint8_t dmac[ETHER_ADDR_LEN]; /* nexthop's MAC address */ -}; - -struct l2t_data { - unsigned int nentries; /* number of entries */ - struct l2t_entry *rover; /* starting point for next allocation */ - volatile uint32_t nfree; /* number of free entries */ - struct rwlock lock; - struct l2t_entry l2tab[0]; -}; - -void t3_l2e_free(struct l2t_data *, struct l2t_entry *e); -void t3_l2_update(struct toedev *tod, struct ifnet *ifp, struct sockaddr *sa, - uint8_t *lladdr, uint16_t vtag); -struct l2t_entry *t3_l2t_get(struct port_info *, struct ifnet *, - struct sockaddr *); -int t3_l2t_send_slow(struct adapter *, struct mbuf *, struct l2t_entry *); -struct l2t_data *t3_init_l2t(unsigned int); -void t3_free_l2t(struct l2t_data *); -void t3_init_l2t_cpl_handlers(struct adapter *); - -static inline int -l2t_send(struct adapter *sc, struct mbuf *m, struct l2t_entry *e) -{ - if (__predict_true(e->state == L2T_STATE_VALID)) - return t3_offload_tx(sc, m); - else - return t3_l2t_send_slow(sc, m, e); -} - -static inline void -l2t_release(struct l2t_data *d, struct l2t_entry *e) -{ - if (atomic_fetchadd_int(&e->refcnt, -1) == 1) /* 1 -> 0 transition */ - atomic_add_int(&d->nfree, 1); -} - -static inline void -l2t_hold(struct l2t_data *d, struct l2t_entry *e) -{ - if (atomic_fetchadd_int(&e->refcnt, 1) == 0) /* 0 -> 1 transition */ - atomic_add_int(&d->nfree, -1); -} - -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_listen.c b/sys/dev/cxgb/ulp/tom/cxgb_listen.c deleted file mode 100644 index 9df592b4de68..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_listen.c +++ /dev/null @@ -1,1133 +0,0 @@ -/*- - * Copyright (c) 2012 Chelsio Communications, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#ifdef TCP_OFFLOAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define TCPSTATES -#include -#include -#include - -#include "cxgb_include.h" -#include "ulp/tom/cxgb_tom.h" -#include "ulp/tom/cxgb_l2t.h" -#include "ulp/tom/cxgb_toepcb.h" - -static void t3_send_reset_synqe(struct toedev *, struct synq_entry *); - -static int -alloc_stid(struct tid_info *t, void *ctx) -{ - int stid = -1; - - mtx_lock(&t->stid_lock); - if (t->sfree) { - union listen_entry *p = t->sfree; - - stid = (p - t->stid_tab) + t->stid_base; - t->sfree = p->next; - p->ctx = ctx; - t->stids_in_use++; - } - mtx_unlock(&t->stid_lock); - return (stid); -} - -static void -free_stid(struct tid_info *t, int stid) -{ - union listen_entry *p = stid2entry(t, stid); - - mtx_lock(&t->stid_lock); - p->next = t->sfree; - t->sfree = p; - t->stids_in_use--; - mtx_unlock(&t->stid_lock); -} - -static struct listen_ctx * -alloc_lctx(struct tom_data *td, struct inpcb *inp, int qset) -{ - struct listen_ctx *lctx; - - INP_WLOCK_ASSERT(inp); - - lctx = malloc(sizeof(struct listen_ctx), M_CXGB, M_NOWAIT | M_ZERO); - if (lctx == NULL) - return (NULL); - - lctx->stid = alloc_stid(&td->tid_maps, lctx); - if (lctx->stid < 0) { - free(lctx, M_CXGB); - return (NULL); - } - - lctx->inp = inp; - in_pcbref(inp); - - lctx->qset = qset; - refcount_init(&lctx->refcnt, 1); - TAILQ_INIT(&lctx->synq); - - return (lctx); -} - -/* Don't call this directly, use release_lctx instead */ -static int -free_lctx(struct tom_data *td, struct listen_ctx *lctx) -{ - struct inpcb *inp = lctx->inp; - - INP_WLOCK_ASSERT(inp); - KASSERT(lctx->refcnt == 0, - ("%s: refcnt %d", __func__, lctx->refcnt)); - KASSERT(TAILQ_EMPTY(&lctx->synq), - ("%s: synq not empty.", __func__)); - KASSERT(lctx->stid >= 0, ("%s: bad stid %d.", __func__, lctx->stid)); - - CTR4(KTR_CXGB, "%s: stid %u, lctx %p, inp %p", - __func__, lctx->stid, lctx, lctx->inp); - - free_stid(&td->tid_maps, lctx->stid); - free(lctx, M_CXGB); - - return in_pcbrele_wlocked(inp); -} - -static void -hold_lctx(struct listen_ctx *lctx) -{ - - refcount_acquire(&lctx->refcnt); -} - -static inline uint32_t -listen_hashfn(void *key, u_long mask) -{ - - return (fnv_32_buf(&key, sizeof(key), FNV1_32_INIT) & mask); -} - -/* - * Add a listen_ctx entry to the listen hash table. - */ -static void -listen_hash_add(struct tom_data *td, struct listen_ctx *lctx) -{ - int bucket = listen_hashfn(lctx->inp, td->listen_mask); - - mtx_lock(&td->lctx_hash_lock); - LIST_INSERT_HEAD(&td->listen_hash[bucket], lctx, link); - td->lctx_count++; - mtx_unlock(&td->lctx_hash_lock); -} - -/* - * Look for the listening socket's context entry in the hash and return it. - */ -static struct listen_ctx * -listen_hash_find(struct tom_data *td, struct inpcb *inp) -{ - int bucket = listen_hashfn(inp, td->listen_mask); - struct listen_ctx *lctx; - - mtx_lock(&td->lctx_hash_lock); - LIST_FOREACH(lctx, &td->listen_hash[bucket], link) { - if (lctx->inp == inp) - break; - } - mtx_unlock(&td->lctx_hash_lock); - - return (lctx); -} - -/* - * Removes the listen_ctx structure for inp from the hash and returns it. - */ -static struct listen_ctx * -listen_hash_del(struct tom_data *td, struct inpcb *inp) -{ - int bucket = listen_hashfn(inp, td->listen_mask); - struct listen_ctx *lctx, *l; - - mtx_lock(&td->lctx_hash_lock); - LIST_FOREACH_SAFE(lctx, &td->listen_hash[bucket], link, l) { - if (lctx->inp == inp) { - LIST_REMOVE(lctx, link); - td->lctx_count--; - break; - } - } - mtx_unlock(&td->lctx_hash_lock); - - return (lctx); -} - -/* - * Releases a hold on the lctx. Must be called with the listening socket's inp - * locked. The inp may be freed by this function and it returns NULL to - * indicate this. - */ -static struct inpcb * -release_lctx(struct tom_data *td, struct listen_ctx *lctx) -{ - struct inpcb *inp = lctx->inp; - int inp_freed = 0; - - INP_WLOCK_ASSERT(inp); - if (refcount_release(&lctx->refcnt)) - inp_freed = free_lctx(td, lctx); - - return (inp_freed ? NULL : inp); -} - -static int -create_server(struct adapter *sc, struct listen_ctx *lctx) -{ - struct mbuf *m; - struct cpl_pass_open_req *req; - struct inpcb *inp = lctx->inp; - - m = M_GETHDR_OFLD(lctx->qset, CPL_PRIORITY_CONTROL, req); - if (m == NULL) - return (ENOMEM); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, lctx->stid)); - req->local_port = inp->inp_lport; - memcpy(&req->local_ip, &inp->inp_laddr, 4); - req->peer_port = 0; - req->peer_ip = 0; - req->peer_netmask = 0; - req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS); - req->opt0l = htonl(V_RCV_BUFSIZ(16)); - req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK)); - - t3_offload_tx(sc, m); - - return (0); -} - -static int -destroy_server(struct adapter *sc, struct listen_ctx *lctx) -{ - struct mbuf *m; - struct cpl_close_listserv_req *req; - - m = M_GETHDR_OFLD(lctx->qset, CPL_PRIORITY_CONTROL, req); - if (m == NULL) - return (ENOMEM); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, - lctx->stid)); - req->cpu_idx = 0; - - t3_offload_tx(sc, m); - - return (0); -} - -/* - * Process a CPL_CLOSE_LISTSRV_RPL message. If the status is good we release - * the STID. - */ -static int -do_close_server_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_close_listserv_rpl *rpl = mtod(m, void *); - unsigned int stid = GET_TID(rpl); - struct listen_ctx *lctx = lookup_stid(&td->tid_maps, stid); - struct inpcb *inp = lctx->inp; - - CTR3(KTR_CXGB, "%s: stid %u, status %u", __func__, stid, rpl->status); - - if (rpl->status != CPL_ERR_NONE) { - log(LOG_ERR, "%s: failed (%u) to close listener for stid %u", - __func__, rpl->status, stid); - } else { - INP_WLOCK(inp); - KASSERT(listen_hash_del(td, lctx->inp) == NULL, - ("%s: inp %p still in listen hash", __func__, inp)); - if (release_lctx(td, lctx) != NULL) - INP_WUNLOCK(inp); - } - - m_freem(m); - return (0); -} - -/* - * Process a CPL_PASS_OPEN_RPL message. Remove the lctx from the listen hash - * table and free it if there was any error, otherwise nothing to do. - */ -static int -do_pass_open_rpl(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_pass_open_rpl *rpl = mtod(m, void *); - int stid = GET_TID(rpl); - struct listen_ctx *lctx; - struct inpcb *inp; - - /* - * We get these replies also when setting up HW filters. Just throw - * those away. - */ - if (stid >= td->tid_maps.stid_base + td->tid_maps.nstids) - goto done; - - lctx = lookup_stid(&td->tid_maps, stid); - inp = lctx->inp; - - INP_WLOCK(inp); - - CTR4(KTR_CXGB, "%s: stid %u, status %u, flags 0x%x", - __func__, stid, rpl->status, lctx->flags); - - lctx->flags &= ~LCTX_RPL_PENDING; - - if (rpl->status != CPL_ERR_NONE) { - log(LOG_ERR, "%s: %s: hw listen (stid %d) failed: %d\n", - __func__, device_get_nameunit(sc->dev), stid, rpl->status); - } - -#ifdef INVARIANTS - /* - * If the inp has been dropped (listening socket closed) then - * listen_stop must have run and taken the inp out of the hash. - */ - if (inp->inp_flags & INP_DROPPED) { - KASSERT(listen_hash_del(td, inp) == NULL, - ("%s: inp %p still in listen hash", __func__, inp)); - } -#endif - - if (inp->inp_flags & INP_DROPPED && rpl->status != CPL_ERR_NONE) { - if (release_lctx(td, lctx) != NULL) - INP_WUNLOCK(inp); - goto done; - } - - /* - * Listening socket stopped listening earlier and now the chip tells us - * it has started the hardware listener. Stop it; the lctx will be - * released in do_close_server_rpl. - */ - if (inp->inp_flags & INP_DROPPED) { - destroy_server(sc, lctx); - INP_WUNLOCK(inp); - goto done; - } - - /* - * Failed to start hardware listener. Take inp out of the hash and - * release our reference on it. An error message has been logged - * already. - */ - if (rpl->status != CPL_ERR_NONE) { - listen_hash_del(td, inp); - if (release_lctx(td, lctx) != NULL) - INP_WUNLOCK(inp); - goto done; - } - - /* hardware listener open for business */ - - INP_WUNLOCK(inp); -done: - m_freem(m); - return (0); -} - -static void -pass_accept_req_to_protohdrs(const struct cpl_pass_accept_req *cpl, - struct in_conninfo *inc, struct tcphdr *th, struct tcpopt *to) -{ - const struct tcp_options *t3opt = &cpl->tcp_options; - - bzero(inc, sizeof(*inc)); - inc->inc_faddr.s_addr = cpl->peer_ip; - inc->inc_laddr.s_addr = cpl->local_ip; - inc->inc_fport = cpl->peer_port; - inc->inc_lport = cpl->local_port; - - bzero(th, sizeof(*th)); - th->th_sport = cpl->peer_port; - th->th_dport = cpl->local_port; - th->th_seq = be32toh(cpl->rcv_isn); /* as in tcp_fields_to_host */ - th->th_flags = TH_SYN; - - bzero(to, sizeof(*to)); - if (t3opt->mss) { - to->to_flags |= TOF_MSS; - to->to_mss = be16toh(t3opt->mss); - } - if (t3opt->wsf) { - to->to_flags |= TOF_SCALE; - to->to_wscale = t3opt->wsf; - } - if (t3opt->tstamp) - to->to_flags |= TOF_TS; - if (t3opt->sack) - to->to_flags |= TOF_SACKPERM; -} - -static inline void -hold_synqe(struct synq_entry *synqe) -{ - - refcount_acquire(&synqe->refcnt); -} - -static inline void -release_synqe(struct synq_entry *synqe) -{ - - if (refcount_release(&synqe->refcnt)) - m_freem(synqe->m); -} - -/* - * Use the trailing space in the mbuf in which the PASS_ACCEPT_REQ arrived to - * store some state temporarily. There will be enough room in the mbuf's - * trailing space as the CPL is not that large. - * - * XXX: bad hack. - */ -static struct synq_entry * -mbuf_to_synq_entry(struct mbuf *m) -{ - int len = roundup(sizeof (struct synq_entry), 8); - - if (__predict_false(M_TRAILINGSPACE(m) < len)) { - panic("%s: no room for synq_entry (%td, %d)\n", __func__, - M_TRAILINGSPACE(m), len); - } - - return ((void *)(M_START(m) + M_SIZE(m) - len)); -} - -#ifdef KTR -#define REJECT_PASS_ACCEPT() do { \ - reject_reason = __LINE__; \ - goto reject; \ -} while (0) -#else -#define REJECT_PASS_ACCEPT() do { goto reject; } while (0) -#endif - -/* - * The context associated with a tid entry via insert_tid could be a synq_entry - * or a toepcb. The only way CPL handlers can tell is via a bit in these flags. - */ -CTASSERT(offsetof(struct toepcb, tp_flags) == offsetof(struct synq_entry, flags)); - -/* - * Handle a CPL_PASS_ACCEPT_REQ message. - */ -static int -do_pass_accept_req(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - const struct cpl_pass_accept_req *req = mtod(m, void *); - unsigned int stid = G_PASS_OPEN_TID(ntohl(req->tos_tid)); - unsigned int tid = GET_TID(req); - struct listen_ctx *lctx = lookup_stid(&td->tid_maps, stid); - struct l2t_entry *e = NULL; - struct nhop4_basic nh4; - struct sockaddr_in nam; - struct inpcb *inp; - struct socket *so; - struct port_info *pi; - struct ifnet *ifp; - struct in_conninfo inc; - struct tcphdr th; - struct tcpopt to; - struct synq_entry *synqe = NULL; - int i; -#ifdef KTR - int reject_reason; -#endif - - CTR4(KTR_CXGB, "%s: stid %u, tid %u, lctx %p", __func__, stid, tid, - lctx); - - pass_accept_req_to_protohdrs(req, &inc, &th, &to); - - /* - * Don't offload if the interface that received the SYN doesn't have - * IFCAP_TOE enabled. - */ - pi = NULL; - for_each_port(sc, i) { - if (memcmp(sc->port[i].hw_addr, req->dst_mac, ETHER_ADDR_LEN)) - continue; - pi = &sc->port[i]; - break; - } - if (pi == NULL) - REJECT_PASS_ACCEPT(); - ifp = pi->ifp; - if ((ifp->if_capenable & IFCAP_TOE4) == 0) - REJECT_PASS_ACCEPT(); - - /* - * Don't offload if the outgoing interface for the route back to the - * peer is not the same as the interface that received the SYN. - */ - bzero(&nam, sizeof(nam)); - nam.sin_len = sizeof(nam); - nam.sin_family = AF_INET; - nam.sin_addr = inc.inc_faddr; - if (fib4_lookup_nh_basic(RT_DEFAULT_FIB, nam.sin_addr, 0, 0, &nh4) != 0) - REJECT_PASS_ACCEPT(); - else { - nam.sin_addr = nh4.nh_addr; - if (nh4.nh_ifp == ifp) - e = t3_l2t_get(pi, ifp, (struct sockaddr *)&nam); - if (e == NULL) - REJECT_PASS_ACCEPT(); /* no l2te, or ifp mismatch */ - } - - INP_INFO_RLOCK(&V_tcbinfo); - - /* Don't offload if the 4-tuple is already in use */ - if (toe_4tuple_check(&inc, &th, ifp) != 0) { - INP_INFO_RUNLOCK(&V_tcbinfo); - REJECT_PASS_ACCEPT(); - } - - inp = lctx->inp; /* listening socket (not owned by the TOE) */ - INP_WLOCK(inp); - if (__predict_false(inp->inp_flags & INP_DROPPED)) { - /* - * The listening socket has closed. The reply from the TOE to - * our CPL_CLOSE_LISTSRV_REQ will ultimately release all - * resources tied to this listen context. - */ - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - REJECT_PASS_ACCEPT(); - } - so = inp->inp_socket; - - /* Reuse the mbuf that delivered the CPL to us */ - synqe = mbuf_to_synq_entry(m); - synqe->flags = TP_IS_A_SYNQ_ENTRY; - synqe->m = m; - synqe->lctx = lctx; - synqe->tid = tid; - synqe->e = e; - synqe->opt0h = calc_opt0h(so, 0, 0, e); - synqe->qset = pi->first_qset + (arc4random() % pi->nqsets); - SOCKBUF_LOCK(&so->so_rcv); - synqe->rx_credits = min(select_rcv_wnd(so) >> 10, M_RCV_BUFSIZ); - SOCKBUF_UNLOCK(&so->so_rcv); - refcount_init(&synqe->refcnt, 1); - atomic_store_rel_int(&synqe->reply, RPL_OK); - - insert_tid(td, synqe, tid); - TAILQ_INSERT_TAIL(&lctx->synq, synqe, link); - hold_synqe(synqe); - hold_lctx(lctx); - - /* syncache_add releases both pcbinfo and pcb locks */ - toe_syncache_add(&inc, &to, &th, inp, tod, synqe); - INP_UNLOCK_ASSERT(inp); - INP_INFO_UNLOCK_ASSERT(&V_tcbinfo); - - /* - * If we replied during syncache_add (reply is RPL_DONE), good. - * Otherwise (reply is unchanged - RPL_OK) it's no longer ok to reply. - * The mbuf will stick around as long as the entry is in the syncache. - * The kernel is free to retry syncache_respond but we'll ignore it due - * to RPL_DONT. - */ - if (atomic_cmpset_int(&synqe->reply, RPL_OK, RPL_DONT)) { - - INP_WLOCK(inp); - if (__predict_false(inp->inp_flags & INP_DROPPED)) { - /* listener closed. synqe must have been aborted. */ - KASSERT(synqe->flags & TP_ABORT_SHUTDOWN, - ("%s: listener %p closed but synqe %p not aborted", - __func__, inp, synqe)); - - CTR5(KTR_CXGB, - "%s: stid %u, tid %u, lctx %p, synqe %p, ABORTED", - __func__, stid, tid, lctx, synqe); - INP_WUNLOCK(inp); - release_synqe(synqe); - return (__LINE__); - } - - KASSERT(!(synqe->flags & TP_ABORT_SHUTDOWN), - ("%s: synqe %p aborted, but listener %p not dropped.", - __func__, synqe, inp)); - - TAILQ_REMOVE(&lctx->synq, synqe, link); - release_synqe(synqe); /* removed from synq list */ - inp = release_lctx(td, lctx); - if (inp) - INP_WUNLOCK(inp); - - release_synqe(synqe); /* about to exit function */ - REJECT_PASS_ACCEPT(); - } - - KASSERT(synqe->reply == RPL_DONE, - ("%s: reply %d", __func__, synqe->reply)); - - CTR3(KTR_CXGB, "%s: stid %u, tid %u, OK", __func__, stid, tid); - release_synqe(synqe); - return (0); - -reject: - CTR4(KTR_CXGB, "%s: stid %u, tid %u, REJECT (%d)", __func__, stid, tid, - reject_reason); - - if (synqe == NULL) - m_freem(m); - if (e) - l2t_release(td->l2t, e); - queue_tid_release(tod, tid); - - return (0); -} - -static void -pass_establish_to_protohdrs(const struct cpl_pass_establish *cpl, - struct in_conninfo *inc, struct tcphdr *th, struct tcpopt *to) -{ - uint16_t tcp_opt = be16toh(cpl->tcp_opt); - - bzero(inc, sizeof(*inc)); - inc->inc_faddr.s_addr = cpl->peer_ip; - inc->inc_laddr.s_addr = cpl->local_ip; - inc->inc_fport = cpl->peer_port; - inc->inc_lport = cpl->local_port; - - bzero(th, sizeof(*th)); - th->th_sport = cpl->peer_port; - th->th_dport = cpl->local_port; - th->th_flags = TH_ACK; - th->th_seq = be32toh(cpl->rcv_isn); /* as in tcp_fields_to_host */ - th->th_ack = be32toh(cpl->snd_isn); /* ditto */ - - bzero(to, sizeof(*to)); - if (G_TCPOPT_TSTAMP(tcp_opt)) - to->to_flags |= TOF_TS; -} - -/* - * Process a CPL_PASS_ESTABLISH message. The T3 has already established a - * connection and we need to do the software side setup. - */ -static int -do_pass_establish(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct cpl_pass_establish *cpl = mtod(m, void *); - struct toedev *tod = &td->tod; - unsigned int tid = GET_TID(cpl); - struct synq_entry *synqe = lookup_tid(&td->tid_maps, tid); - struct toepcb *toep; - struct socket *so; - struct listen_ctx *lctx = synqe->lctx; - struct inpcb *inp = lctx->inp, *new_inp; - struct tcpopt to; - struct tcphdr th; - struct in_conninfo inc; -#ifdef KTR - int stid = G_PASS_OPEN_TID(ntohl(cpl->tos_tid)); -#endif - - CTR5(KTR_CXGB, "%s: stid %u, tid %u, lctx %p, inp_flags 0x%x", - __func__, stid, tid, lctx, inp->inp_flags); - - KASSERT(qs->idx == synqe->qset, - ("%s qset mismatch %d %d", __func__, qs->idx, synqe->qset)); - - INP_INFO_RLOCK(&V_tcbinfo); /* for syncache_expand */ - INP_WLOCK(inp); - - if (__predict_false(inp->inp_flags & INP_DROPPED)) { - /* - * The listening socket has closed. The TOM must have aborted - * all the embryonic connections (including this one) that were - * on the lctx's synq. do_abort_rpl for the tid is responsible - * for cleaning up. - */ - KASSERT(synqe->flags & TP_ABORT_SHUTDOWN, - ("%s: listen socket dropped but tid %u not aborted.", - __func__, tid)); - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - m_freem(m); - return (0); - } - - pass_establish_to_protohdrs(cpl, &inc, &th, &to); - - /* Lie in order to pass the checks in syncache_expand */ - to.to_tsecr = synqe->ts; - th.th_ack = synqe->iss + 1; - - toep = toepcb_alloc(tod); - if (toep == NULL) { -reset: - t3_send_reset_synqe(tod, synqe); - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - m_freem(m); - return (0); - } - toep->tp_qset = qs->idx; - toep->tp_l2t = synqe->e; - toep->tp_tid = tid; - toep->tp_rx_credits = synqe->rx_credits; - - synqe->toep = toep; - synqe->cpl = cpl; - - so = inp->inp_socket; - if (!toe_syncache_expand(&inc, &to, &th, &so) || so == NULL) { - toepcb_free(toep); - goto reset; - } - - /* New connection inpcb is already locked by syncache_expand(). */ - new_inp = sotoinpcb(so); - INP_WLOCK_ASSERT(new_inp); - - if (__predict_false(!(synqe->flags & TP_SYNQE_EXPANDED))) { - tcp_timer_activate(intotcpcb(new_inp), TT_KEEP, 0); - t3_offload_socket(tod, synqe, so); - } - - INP_WUNLOCK(new_inp); - - /* Remove the synq entry and release its reference on the lctx */ - TAILQ_REMOVE(&lctx->synq, synqe, link); - inp = release_lctx(td, lctx); - if (inp) - INP_WUNLOCK(inp); - INP_INFO_RUNLOCK(&V_tcbinfo); - release_synqe(synqe); - - m_freem(m); - return (0); -} - -void -t3_init_listen_cpl_handlers(struct adapter *sc) -{ - t3_register_cpl_handler(sc, CPL_PASS_OPEN_RPL, do_pass_open_rpl); - t3_register_cpl_handler(sc, CPL_CLOSE_LISTSRV_RPL, do_close_server_rpl); - t3_register_cpl_handler(sc, CPL_PASS_ACCEPT_REQ, do_pass_accept_req); - t3_register_cpl_handler(sc, CPL_PASS_ESTABLISH, do_pass_establish); -} - -/* - * Start a listening server by sending a passive open request to HW. - * - * Can't take adapter lock here and access to sc->flags, sc->open_device_map, - * sc->offload_map, if_capenable are all race prone. - */ -int -t3_listen_start(struct toedev *tod, struct tcpcb *tp) -{ - struct tom_data *td = t3_tomdata(tod); - struct adapter *sc = tod->tod_softc; - struct port_info *pi; - struct inpcb *inp = tp->t_inpcb; - struct listen_ctx *lctx; - int i; - - INP_WLOCK_ASSERT(inp); - - if ((inp->inp_vflag & INP_IPV4) == 0) - return (0); - -#ifdef notyet - ADAPTER_LOCK(sc); - if (IS_BUSY(sc)) { - log(LOG_ERR, "%s: listen request ignored, %s is busy", - __func__, device_get_nameunit(sc->dev)); - goto done; - } - - KASSERT(sc->flags & TOM_INIT_DONE, - ("%s: TOM not initialized", __func__)); -#endif - - if ((sc->open_device_map & sc->offload_map) == 0) - goto done; /* no port that's UP with IFCAP_TOE enabled */ - - /* - * Find a running port with IFCAP_TOE4. We'll use the first such port's - * queues to send the passive open and receive the reply to it. - * - * XXX: need a way to mark an port in use by offload. if_cxgbe should - * then reject any attempt to bring down such a port (and maybe reject - * attempts to disable IFCAP_TOE on that port too?). - */ - for_each_port(sc, i) { - if (isset(&sc->open_device_map, i) && - sc->port[i].ifp->if_capenable & IFCAP_TOE4) - break; - } - KASSERT(i < sc->params.nports, - ("%s: no running port with TOE capability enabled.", __func__)); - pi = &sc->port[i]; - - if (listen_hash_find(td, inp) != NULL) - goto done; /* already setup */ - - lctx = alloc_lctx(td, inp, pi->first_qset); - if (lctx == NULL) { - log(LOG_ERR, - "%s: listen request ignored, %s couldn't allocate lctx\n", - __func__, device_get_nameunit(sc->dev)); - goto done; - } - listen_hash_add(td, lctx); - - CTR5(KTR_CXGB, "%s: stid %u (%s), lctx %p, inp %p", __func__, - lctx->stid, tcpstates[tp->t_state], lctx, inp); - - if (create_server(sc, lctx) != 0) { - log(LOG_ERR, "%s: %s failed to create hw listener.\n", __func__, - device_get_nameunit(sc->dev)); - (void) listen_hash_del(td, inp); - inp = release_lctx(td, lctx); - /* can't be freed, host stack has a reference */ - KASSERT(inp != NULL, ("%s: inp freed", __func__)); - goto done; - } - lctx->flags |= LCTX_RPL_PENDING; -done: -#ifdef notyet - ADAPTER_UNLOCK(sc); -#endif - return (0); -} - -/* - * Stop a listening server by sending a close_listsvr request to HW. - * The server TID is freed when we get the reply. - */ -int -t3_listen_stop(struct toedev *tod, struct tcpcb *tp) -{ - struct listen_ctx *lctx; - struct adapter *sc = tod->tod_softc; - struct tom_data *td = t3_tomdata(tod); - struct inpcb *inp = tp->t_inpcb; - struct synq_entry *synqe; - - INP_WLOCK_ASSERT(inp); - - lctx = listen_hash_del(td, inp); - if (lctx == NULL) - return (ENOENT); /* no hardware listener for this inp */ - - CTR4(KTR_CXGB, "%s: stid %u, lctx %p, flags %x", __func__, lctx->stid, - lctx, lctx->flags); - - /* - * If the reply to the PASS_OPEN is still pending we'll wait for it to - * arrive and clean up when it does. - */ - if (lctx->flags & LCTX_RPL_PENDING) { - KASSERT(TAILQ_EMPTY(&lctx->synq), - ("%s: synq not empty.", __func__)); - return (EINPROGRESS); - } - - /* - * The host stack will abort all the connections on the listening - * socket's so_comp. It doesn't know about the connections on the synq - * so we need to take care of those. - */ - TAILQ_FOREACH(synqe, &lctx->synq, link) { - KASSERT(synqe->lctx == lctx, ("%s: synq corrupt", __func__)); - t3_send_reset_synqe(tod, synqe); - } - - destroy_server(sc, lctx); - return (0); -} - -void -t3_syncache_added(struct toedev *tod __unused, void *arg) -{ - struct synq_entry *synqe = arg; - - hold_synqe(synqe); -} - -void -t3_syncache_removed(struct toedev *tod __unused, void *arg) -{ - struct synq_entry *synqe = arg; - - release_synqe(synqe); -} - -int -t3_syncache_respond(struct toedev *tod, void *arg, struct mbuf *m) -{ - struct adapter *sc = tod->tod_softc; - struct synq_entry *synqe = arg; - struct l2t_entry *e = synqe->e; - struct ip *ip = mtod(m, struct ip *); - struct tcphdr *th = (void *)(ip + 1); - struct cpl_pass_accept_rpl *rpl; - struct mbuf *r; - struct listen_ctx *lctx = synqe->lctx; - struct tcpopt to; - int mtu_idx, cpu_idx; - - /* - * The first time we run it's during the call to syncache_add. That's - * the only one we care about. - */ - if (atomic_cmpset_int(&synqe->reply, RPL_OK, RPL_DONE) == 0) - goto done; /* reply to the CPL only if it's ok to do so */ - - r = M_GETHDR_OFLD(lctx->qset, CPL_PRIORITY_CONTROL, rpl); - if (r == NULL) - goto done; - - /* - * Use only the provided mbuf (with ip and tcp headers) and what's in - * synqe. Avoid looking at the listening socket (lctx->inp) here. - * - * XXX: if the incoming SYN had the TCP timestamp option but the kernel - * decides it doesn't want to use TCP timestamps we have no way of - * relaying this info to the chip on a per-tid basis (all we have is a - * global knob). - */ - bzero(&to, sizeof(to)); - tcp_dooptions(&to, (void *)(th + 1), (th->th_off << 2) - sizeof(*th), - TO_SYN); - - /* stash them for later */ - synqe->iss = be32toh(th->th_seq); - synqe->ts = to.to_tsval; - - mtu_idx = find_best_mtu_idx(sc, NULL, to.to_mss); - cpu_idx = sc->rrss_map[synqe->qset]; - - rpl->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - rpl->wr.wrh_lo = 0; - OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, synqe->tid)); - rpl->opt2 = calc_opt2(cpu_idx); - rpl->rsvd = rpl->opt2; /* workaround for HW bug */ - rpl->peer_ip = ip->ip_dst.s_addr; - rpl->opt0h = synqe->opt0h | - calc_opt0h(NULL, mtu_idx, to.to_wscale, NULL); - rpl->opt0l_status = htobe32(CPL_PASS_OPEN_ACCEPT) | - calc_opt0l(NULL, synqe->rx_credits); - - l2t_send(sc, r, e); -done: - m_freem(m); - return (0); -} - -int -do_abort_req_synqe(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - const struct cpl_abort_req_rss *req = mtod(m, void *); - unsigned int tid = GET_TID(req); - struct synq_entry *synqe = lookup_tid(&td->tid_maps, tid); - struct listen_ctx *lctx = synqe->lctx; - struct inpcb *inp = lctx->inp; - - KASSERT(synqe->flags & TP_IS_A_SYNQ_ENTRY, - ("%s: !SYNQ_ENTRY", __func__)); - - CTR6(KTR_CXGB, "%s: tid %u, synqe %p (%x), lctx %p, status %d", - __func__, tid, synqe, synqe->flags, synqe->lctx, req->status); - - INP_WLOCK(inp); - - if (!(synqe->flags & TP_ABORT_REQ_RCVD)) { - synqe->flags |= TP_ABORT_REQ_RCVD; - synqe->flags |= TP_ABORT_SHUTDOWN; - INP_WUNLOCK(inp); - m_freem(m); - return (0); - } - synqe->flags &= ~TP_ABORT_REQ_RCVD; - - /* - * If we'd sent a reset on this synqe, we'll ignore this and clean up in - * the T3's reply to our reset instead. - */ - if (synqe->flags & TP_ABORT_RPL_PENDING) { - synqe->flags |= TP_ABORT_RPL_SENT; - INP_WUNLOCK(inp); - } else { - TAILQ_REMOVE(&lctx->synq, synqe, link); - inp = release_lctx(td, lctx); - if (inp) - INP_WUNLOCK(inp); - release_tid(tod, tid, qs->idx); - l2t_release(td->l2t, synqe->e); - release_synqe(synqe); - } - - send_abort_rpl(tod, tid, qs->idx); - m_freem(m); - return (0); -} - -int -do_abort_rpl_synqe(struct sge_qset *qs, struct rsp_desc *r, struct mbuf *m) -{ - struct adapter *sc = qs->adap; - struct tom_data *td = sc->tom_softc; - struct toedev *tod = &td->tod; - const struct cpl_abort_rpl_rss *rpl = mtod(m, void *); - unsigned int tid = GET_TID(rpl); - struct synq_entry *synqe = lookup_tid(&td->tid_maps, tid); - struct listen_ctx *lctx = synqe->lctx; - struct inpcb *inp = lctx->inp; - - CTR3(KTR_CXGB, "%s: tid %d, synqe %p, status %d", tid, synqe, - rpl->status); - - INP_WLOCK(inp); - - if (synqe->flags & TP_ABORT_RPL_PENDING) { - if (!(synqe->flags & TP_ABORT_RPL_RCVD)) { - synqe->flags |= TP_ABORT_RPL_RCVD; - INP_WUNLOCK(inp); - } else { - synqe->flags &= ~TP_ABORT_RPL_RCVD; - synqe->flags &= TP_ABORT_RPL_PENDING; - - TAILQ_REMOVE(&lctx->synq, synqe, link); - inp = release_lctx(td, lctx); - if (inp) - INP_WUNLOCK(inp); - release_tid(tod, tid, qs->idx); - l2t_release(td->l2t, synqe->e); - release_synqe(synqe); - } - } - - m_freem(m); - return (0); -} - -static void -t3_send_reset_synqe(struct toedev *tod, struct synq_entry *synqe) -{ - struct cpl_abort_req *req; - unsigned int tid = synqe->tid; - struct adapter *sc = tod->tod_softc; - struct mbuf *m; -#ifdef INVARIANTS - struct listen_ctx *lctx = synqe->lctx; - struct inpcb *inp = lctx->inp; -#endif - - INP_WLOCK_ASSERT(inp); - - CTR4(KTR_CXGB, "%s: tid %d, synqe %p (%x)", __func__, tid, synqe, - synqe->flags); - - if (synqe->flags & TP_ABORT_SHUTDOWN) - return; - - synqe->flags |= (TP_ABORT_RPL_PENDING | TP_ABORT_SHUTDOWN); - - m = M_GETHDR_OFLD(synqe->qset, CPL_PRIORITY_DATA, req); - if (m == NULL) - CXGB_UNIMPLEMENTED(); - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ)); - req->wr.wrh_lo = htonl(V_WR_TID(tid)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, tid)); - req->rsvd0 = 0; - req->rsvd1 = !(synqe->flags & TP_DATASENT); - req->cmd = CPL_ABORT_SEND_RST; - - l2t_send(sc, m, synqe->e); -} - -void -t3_offload_socket(struct toedev *tod, void *arg, struct socket *so) -{ - struct adapter *sc = tod->tod_softc; - struct tom_data *td = sc->tom_softc; - struct synq_entry *synqe = arg; -#ifdef INVARIANTS - struct inpcb *inp = sotoinpcb(so); -#endif - struct cpl_pass_establish *cpl = synqe->cpl; - struct toepcb *toep = synqe->toep; - - INP_INFO_RLOCK_ASSERT(&V_tcbinfo); /* prevents bad race with accept() */ - INP_WLOCK_ASSERT(inp); - - offload_socket(so, toep); - make_established(so, cpl->snd_isn, cpl->rcv_isn, cpl->tcp_opt); - update_tid(td, toep, synqe->tid); - synqe->flags |= TP_SYNQE_EXPANDED; -} -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_toepcb.h b/sys/dev/cxgb/ulp/tom/cxgb_toepcb.h deleted file mode 100644 index 167e36deb97d..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_toepcb.h +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * Copyright (c) 2007-2009, Chelsio Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Neither the name of the Chelsio Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ -#ifndef CXGB_TOEPCB_H_ -#define CXGB_TOEPCB_H_ -#include -#include -#include - -#define TP_DATASENT (1 << 0) -#define TP_TX_WAIT_IDLE (1 << 1) -#define TP_FIN_SENT (1 << 2) -#define TP_ABORT_RPL_PENDING (1 << 3) -#define TP_ABORT_SHUTDOWN (1 << 4) -#define TP_ABORT_RPL_RCVD (1 << 5) -#define TP_ABORT_REQ_RCVD (1 << 6) -#define TP_ATTACHED (1 << 7) -#define TP_CPL_DONE (1 << 8) -#define TP_IS_A_SYNQ_ENTRY (1 << 9) -#define TP_ABORT_RPL_SENT (1 << 10) -#define TP_SEND_FIN (1 << 11) -#define TP_SYNQE_EXPANDED (1 << 12) - -struct toepcb { - TAILQ_ENTRY(toepcb) link; /* toep_list */ - int tp_flags; - struct toedev *tp_tod; - struct l2t_entry *tp_l2t; - int tp_tid; - int tp_wr_max; - int tp_wr_avail; - int tp_wr_unacked; - int tp_delack_mode; - int tp_ulp_mode; - int tp_qset; - int tp_enqueued; - int tp_rx_credits; - - struct inpcb *tp_inp; - struct mbuf *tp_m_last; - - struct mbufq wr_list; - struct mbufq out_of_order_queue; -}; - -static inline void -reset_wr_list(struct toepcb *toep) -{ - mbufq_init(&toep->wr_list, INT_MAX); /* XXX: sane limit needed */ -} - -static inline void -enqueue_wr(struct toepcb *toep, struct mbuf *m) -{ - (void )mbufq_enqueue(&toep->wr_list, m); -} - -static inline struct mbuf * -peek_wr(const struct toepcb *toep) -{ - return (mbufq_first(&toep->wr_list)); -} - -static inline struct mbuf * -dequeue_wr(struct toepcb *toep) -{ - return (mbufq_dequeue(&toep->wr_list)); -} - -#endif diff --git a/sys/dev/cxgb/ulp/tom/cxgb_tom.c b/sys/dev/cxgb/ulp/tom/cxgb_tom.c deleted file mode 100644 index 8f0dd25ba01c..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_tom.c +++ /dev/null @@ -1,396 +0,0 @@ -/*- - * Copyright (c) 2012 Chelsio Communications, Inc. - * All rights reserved. - * Written by: Navdeep Parhar - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "opt_inet.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef TCP_OFFLOAD -#include "cxgb_include.h" -#include "ulp/tom/cxgb_tom.h" -#include "ulp/tom/cxgb_l2t.h" -#include "ulp/tom/cxgb_toepcb.h" - -MALLOC_DEFINE(M_CXGB, "cxgb", "Chelsio T3 Offload services"); - -/* Module ops */ -static int t3_tom_mod_load(void); -static int t3_tom_mod_unload(void); -static int t3_tom_modevent(module_t, int, void *); - -/* ULD ops and helpers */ -static int t3_tom_activate(struct adapter *); -static int t3_tom_deactivate(struct adapter *); - -static int alloc_tid_tabs(struct tid_info *, u_int, u_int, u_int, u_int, u_int); -static void free_tid_tabs(struct tid_info *); -static int write_smt_entry(struct adapter *, int); -static void free_tom_data(struct tom_data *); - -static struct uld_info tom_uld_info = { - .uld_id = ULD_TOM, - .activate = t3_tom_activate, - .deactivate = t3_tom_deactivate, -}; - -struct toepcb * -toepcb_alloc(struct toedev *tod) -{ - struct toepcb *toep; - - toep = malloc(sizeof(struct toepcb), M_CXGB, M_NOWAIT | M_ZERO); - if (toep == NULL) - return (NULL); - - toep->tp_tod = tod; - toep->tp_wr_max = toep->tp_wr_avail = 15; - toep->tp_wr_unacked = 0; - toep->tp_delack_mode = 0; - - return (toep); -} - -void -toepcb_free(struct toepcb *toep) -{ - free(toep, M_CXGB); -} - -static int -alloc_tid_tabs(struct tid_info *t, u_int ntids, u_int natids, u_int nstids, - u_int atid_base, u_int stid_base) -{ - unsigned long size = ntids * sizeof(*t->tid_tab) + - natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab); - - t->tid_tab = malloc(size, M_CXGB, M_NOWAIT | M_ZERO); - if (!t->tid_tab) - return (ENOMEM); - - t->stid_tab = (union listen_entry *)&t->tid_tab[ntids]; - t->atid_tab = (union active_open_entry *)&t->stid_tab[nstids]; - t->ntids = ntids; - t->nstids = nstids; - t->stid_base = stid_base; - t->sfree = NULL; - t->natids = natids; - t->atid_base = atid_base; - t->afree = NULL; - t->stids_in_use = t->atids_in_use = 0; - t->tids_in_use = 0; - mtx_init(&t->stid_lock, "stid", NULL, MTX_DEF); - mtx_init(&t->atid_lock, "atid", NULL, MTX_DEF); - - /* - * Setup the free lists for stid_tab and atid_tab. - */ - if (nstids) { - while (--nstids) - t->stid_tab[nstids - 1].next = &t->stid_tab[nstids]; - t->sfree = t->stid_tab; - } - if (natids) { - while (--natids) - t->atid_tab[natids - 1].next = &t->atid_tab[natids]; - t->afree = t->atid_tab; - } - return (0); -} - -static void -free_tid_tabs(struct tid_info *t) -{ - if (mtx_initialized(&t->stid_lock)) - mtx_destroy(&t->stid_lock); - if (mtx_initialized(&t->atid_lock)) - mtx_destroy(&t->atid_lock); - free(t->tid_tab, M_CXGB); -} - -static int -write_smt_entry(struct adapter *sc, int idx) -{ - struct port_info *pi = &sc->port[idx]; - struct cpl_smt_write_req *req; - struct mbuf *m; - - m = M_GETHDR_OFLD(0, CPL_PRIORITY_CONTROL, req); - if (m == NULL) { - log(LOG_ERR, "%s: no mbuf, can't write SMT entry for %d\n", - __func__, idx); - return (ENOMEM); - } - - req->wr.wrh_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); - OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SMT_WRITE_REQ, idx)); - req->mtu_idx = NMTUS - 1; /* should be 0 but there's a T3 bug */ - req->iff = idx; - memset(req->src_mac1, 0, sizeof(req->src_mac1)); - memcpy(req->src_mac0, pi->hw_addr, ETHER_ADDR_LEN); - - t3_offload_tx(sc, m); - - return (0); -} - -static void -free_tom_data(struct tom_data *td) -{ - KASSERT(TAILQ_EMPTY(&td->toep_list), - ("%s: toep_list not empty", __func__)); - - if (td->listen_mask != 0) - hashdestroy(td->listen_hash, M_CXGB, td->listen_mask); - - if (mtx_initialized(&td->toep_list_lock)) - mtx_destroy(&td->toep_list_lock); - if (mtx_initialized(&td->lctx_hash_lock)) - mtx_destroy(&td->lctx_hash_lock); - if (mtx_initialized(&td->tid_release_lock)) - mtx_destroy(&td->tid_release_lock); - if (td->l2t) - t3_free_l2t(td->l2t); - free_tid_tabs(&td->tid_maps); - free(td, M_CXGB); -} - -/* - * Ground control to Major TOM - * Commencing countdown, engines on - */ -static int -t3_tom_activate(struct adapter *sc) -{ - struct tom_data *td; - struct toedev *tod; - int i, rc = 0; - struct mc5_params *mc5 = &sc->params.mc5; - u_int ntids, natids, mtus; - - ADAPTER_LOCK_ASSERT_OWNED(sc); /* for sc->flags */ - - /* per-adapter softc for TOM */ - td = malloc(sizeof(*td), M_CXGB, M_ZERO | M_NOWAIT); - if (td == NULL) - return (ENOMEM); - - /* List of TOE PCBs and associated lock */ - mtx_init(&td->toep_list_lock, "PCB list lock", NULL, MTX_DEF); - TAILQ_INIT(&td->toep_list); - - /* Listen context */ - mtx_init(&td->lctx_hash_lock, "lctx hash lock", NULL, MTX_DEF); - td->listen_hash = hashinit_flags(LISTEN_HASH_SIZE, M_CXGB, - &td->listen_mask, HASH_NOWAIT); - - /* TID release task */ - TASK_INIT(&td->tid_release_task, 0 , t3_process_tid_release_list, td); - mtx_init(&td->tid_release_lock, "tid release", NULL, MTX_DEF); - - /* L2 table */ - td->l2t = t3_init_l2t(L2T_SIZE); - if (td->l2t == NULL) { - rc = ENOMEM; - goto done; - } - - /* TID tables */ - ntids = t3_mc5_size(&sc->mc5) - mc5->nroutes - mc5->nfilters - - mc5->nservers; - natids = min(ntids / 2, 64 * 1024); - rc = alloc_tid_tabs(&td->tid_maps, ntids, natids, mc5->nservers, - 0x100000 /* ATID_BASE */, ntids); - if (rc != 0) - goto done; - - /* CPL handlers */ - t3_init_listen_cpl_handlers(sc); - t3_init_l2t_cpl_handlers(sc); - t3_init_cpl_io(sc); - - /* toedev ops */ - tod = &td->tod; - init_toedev(tod); - tod->tod_softc = sc; - tod->tod_connect = t3_connect; - tod->tod_listen_start = t3_listen_start; - tod->tod_listen_stop = t3_listen_stop; - tod->tod_rcvd = t3_rcvd; - tod->tod_output = t3_tod_output; - tod->tod_send_rst = t3_send_rst; - tod->tod_send_fin = t3_send_fin; - tod->tod_pcb_detach = t3_pcb_detach; - tod->tod_l2_update = t3_l2_update; - tod->tod_syncache_added = t3_syncache_added; - tod->tod_syncache_removed = t3_syncache_removed; - tod->tod_syncache_respond = t3_syncache_respond; - tod->tod_offload_socket = t3_offload_socket; - - /* port MTUs */ - mtus = sc->port[0].ifp->if_mtu; - if (sc->params.nports > 1) - mtus |= sc->port[1].ifp->if_mtu << 16; - t3_write_reg(sc, A_TP_MTU_PORT_TABLE, mtus); - t3_load_mtus(sc, sc->params.mtus, sc->params.a_wnd, sc->params.b_wnd, - sc->params.rev == 0 ? sc->port[0].ifp->if_mtu : 0xffff); - - /* SMT entry for each port */ - for_each_port(sc, i) { - write_smt_entry(sc, i); - TOEDEV(sc->port[i].ifp) = &td->tod; - } - - /* Switch TP to offload mode */ - t3_tp_set_offload_mode(sc, 1); - - sc->tom_softc = td; - sc->flags |= TOM_INIT_DONE; - register_toedev(tod); - -done: - if (rc != 0) - free_tom_data(td); - - return (rc); -} - -static int -t3_tom_deactivate(struct adapter *sc) -{ - int rc = 0; - struct tom_data *td = sc->tom_softc; - - ADAPTER_LOCK_ASSERT_OWNED(sc); /* for sc->flags */ - - if (td == NULL) - return (0); /* XXX. KASSERT? */ - - if (sc->offload_map != 0) - return (EBUSY); /* at least one port has IFCAP_TOE enabled */ - - mtx_lock(&td->toep_list_lock); - if (!TAILQ_EMPTY(&td->toep_list)) - rc = EBUSY; - mtx_unlock(&td->toep_list_lock); - - mtx_lock(&td->lctx_hash_lock); - if (td->lctx_count > 0) - rc = EBUSY; - mtx_unlock(&td->lctx_hash_lock); - - if (rc == 0) { - unregister_toedev(&td->tod); - t3_tp_set_offload_mode(sc, 0); - free_tom_data(td); - sc->tom_softc = NULL; - sc->flags &= ~TOM_INIT_DONE; - } - - return (rc); -} - -static int -t3_tom_mod_load(void) -{ - int rc; - - rc = t3_register_uld(&tom_uld_info); - if (rc != 0) - t3_tom_mod_unload(); - - return (rc); -} - -static void -tom_uninit(struct adapter *sc, void *arg __unused) -{ - /* Try to free resources (works only if no port has IFCAP_TOE) */ - ADAPTER_LOCK(sc); - if (sc->flags & TOM_INIT_DONE) - t3_deactivate_uld(sc, ULD_TOM); - ADAPTER_UNLOCK(sc); -} - -static int -t3_tom_mod_unload(void) -{ - t3_iterate(tom_uninit, NULL); - - if (t3_unregister_uld(&tom_uld_info) == EBUSY) - return (EBUSY); - - return (0); -} -#endif /* ifdef TCP_OFFLOAD */ - -static int -t3_tom_modevent(module_t mod, int cmd, void *arg) -{ - int rc = 0; - -#ifdef TCP_OFFLOAD - switch (cmd) { - case MOD_LOAD: - rc = t3_tom_mod_load(); - break; - - case MOD_UNLOAD: - rc = t3_tom_mod_unload(); - break; - - default: - rc = EINVAL; - } -#else - rc = EOPNOTSUPP; -#endif - return (rc); -} - -static moduledata_t t3_tom_moddata= { - "t3_tom", - t3_tom_modevent, - 0 -}; - -MODULE_VERSION(t3_tom, 1); -MODULE_DEPEND(t3_tom, toecore, 1, 1, 1); -MODULE_DEPEND(t3_tom, cxgbc, 1, 1, 1); -DECLARE_MODULE(t3_tom, t3_tom_moddata, SI_SUB_EXEC, SI_ORDER_ANY); diff --git a/sys/dev/cxgb/ulp/tom/cxgb_tom.h b/sys/dev/cxgb/ulp/tom/cxgb_tom.h deleted file mode 100644 index 1698a364946d..000000000000 --- a/sys/dev/cxgb/ulp/tom/cxgb_tom.h +++ /dev/null @@ -1,280 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007, 2009 Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -$FreeBSD$ - -***************************************************************************/ -#ifndef CXGB_TOM_H_ -#define CXGB_TOM_H_ -#include -#include - -MALLOC_DECLARE(M_CXGB); - -#define KTR_CXGB KTR_SPARE3 - -#define LISTEN_HASH_SIZE 32 - -/* - * Holds the size, base address, free list start, etc of the TID, server TID, - * and active-open TID tables for a offload device. - * The tables themselves are allocated dynamically. - */ -struct tid_info { - void **tid_tab; - unsigned int ntids; - volatile unsigned int tids_in_use; - - union listen_entry *stid_tab; - unsigned int nstids; - unsigned int stid_base; - - union active_open_entry *atid_tab; - unsigned int natids; - unsigned int atid_base; - - /* - * The following members are accessed R/W so we put them in their own - * cache lines. TOM_XXX: actually do what is said here. - * - * XXX We could combine the atid fields above with the lock here since - * atids are use once (unlike other tids). OTOH the above fields are - * usually in cache due to tid_tab. - */ - struct mtx atid_lock; - union active_open_entry *afree; - unsigned int atids_in_use; - - struct mtx stid_lock; - union listen_entry *sfree; - unsigned int stids_in_use; -}; - -struct tom_data { - struct toedev tod; - - /* - * toepcb's associated with this TOE device are either on the - * toep list or in the synq of a listening socket in lctx hash. - */ - struct mtx toep_list_lock; - TAILQ_HEAD(, toepcb) toep_list; - - struct l2t_data *l2t; - struct tid_info tid_maps; - - /* - * The next two locks listen_lock, and tid_release_lock are used rarely - * so we let them potentially share a cacheline. - */ - - LIST_HEAD(, listen_ctx) *listen_hash; - u_long listen_mask; - int lctx_count; /* # of lctx in the hash table */ - struct mtx lctx_hash_lock; - - void **tid_release_list; - struct mtx tid_release_lock; - struct task tid_release_task; -}; - -struct synq_entry { - TAILQ_ENTRY(synq_entry) link; /* listen_ctx's synq link */ - int flags; /* same as toepcb's tp_flags */ - int tid; - struct mbuf *m; /* backpointer to containing mbuf */ - struct listen_ctx *lctx; /* backpointer to listen ctx */ - struct cpl_pass_establish *cpl; - struct toepcb *toep; - struct l2t_entry *e; - uint32_t iss; - uint32_t ts; - uint32_t opt0h; - uint32_t qset; - int rx_credits; - volatile u_int refcnt; - -#define RPL_OK 0 /* ok to reply */ -#define RPL_DONE 1 /* replied already */ -#define RPL_DONT 2 /* don't reply */ - volatile u_int reply; /* see above. */ -}; - -#define LCTX_RPL_PENDING 1 /* waiting for CPL_PASS_OPEN_RPL */ - -struct listen_ctx { - LIST_ENTRY(listen_ctx) link; /* listen hash linkage */ - volatile int refcnt; - int stid; - int flags; - struct inpcb *inp; /* listening socket's inp */ - int qset; - TAILQ_HEAD(, synq_entry) synq; -}; - -void t3_process_tid_release_list(void *data, int pending); - -static inline struct tom_data * -t3_tomdata(struct toedev *tod) -{ - - return (__containerof(tod, struct tom_data, tod)); -} - -union listen_entry { - void *ctx; - union listen_entry *next; -}; - -union active_open_entry { - void *ctx; - union active_open_entry *next; -}; - -/* - * Map an ATID or STID to their entries in the corresponding TID tables. - */ -static inline union active_open_entry *atid2entry(const struct tid_info *t, - unsigned int atid) -{ - return &t->atid_tab[atid - t->atid_base]; -} - - -static inline union listen_entry *stid2entry(const struct tid_info *t, - unsigned int stid) -{ - return &t->stid_tab[stid - t->stid_base]; -} - -/* - * Find the connection corresponding to a TID. - */ -static inline void *lookup_tid(const struct tid_info *t, unsigned int tid) -{ - void *p; - - if (tid >= t->ntids) - return (NULL); - - p = t->tid_tab[tid]; - if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) - return (p); - - return (NULL); -} - -/* - * Find the connection corresponding to a server TID. - */ -static inline void *lookup_stid(const struct tid_info *t, unsigned int tid) -{ - void *p; - - if (tid < t->stid_base || tid >= t->stid_base + t->nstids) - return (NULL); - - p = stid2entry(t, tid)->ctx; - if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) - return (p); - - return (NULL); -} - -/* - * Find the connection corresponding to an active-open TID. - */ -static inline void *lookup_atid(const struct tid_info *t, unsigned int tid) -{ - void *p; - - if (tid < t->atid_base || tid >= t->atid_base + t->natids) - return (NULL); - - p = atid2entry(t, tid)->ctx; - if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) - return (p); - - return (NULL); -} - -static inline uint32_t -calc_opt2(int cpu_idx) -{ - uint32_t opt2 = F_CPU_INDEX_VALID | V_CPU_INDEX(cpu_idx); - - /* 3 = highspeed CC algorithm */ - opt2 |= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(3) | - V_PACING_FLAVOR(1); - - /* coalesce and push bit semantics */ - opt2 |= F_RX_COALESCE_VALID | V_RX_COALESCE(3); - - return (htobe32(opt2)); -} - -/* cxgb_tom.c */ -struct toepcb *toepcb_alloc(struct toedev *); -void toepcb_free(struct toepcb *); - -/* cxgb_cpl_io.c */ -void t3_init_cpl_io(struct adapter *); -int t3_push_frames(struct socket *, int); -int t3_connect(struct toedev *, struct socket *, struct rtentry *, - struct sockaddr *); -int t3_tod_output(struct toedev *, struct tcpcb *); -int t3_send_rst(struct toedev *, struct tcpcb *); -int t3_send_fin(struct toedev *, struct tcpcb *); -void insert_tid(struct tom_data *, void *, unsigned int); -void update_tid(struct tom_data *, void *, unsigned int); -void remove_tid(struct tom_data *, unsigned int); -uint32_t calc_opt0h(struct socket *, int, int, struct l2t_entry *); -uint32_t calc_opt0l(struct socket *, int); -void queue_tid_release(struct toedev *, unsigned int); -void offload_socket(struct socket *, struct toepcb *); -void undo_offload_socket(struct socket *); -int select_rcv_wscale(void); -unsigned long select_rcv_wnd(struct socket *); -int find_best_mtu_idx(struct adapter *, struct in_conninfo *, int); -void make_established(struct socket *, uint32_t, uint32_t, uint16_t); -void t3_rcvd(struct toedev *, struct tcpcb *); -void t3_pcb_detach(struct toedev *, struct tcpcb *); -void send_abort_rpl(struct toedev *, int, int); -void release_tid(struct toedev *, unsigned int, int); - -/* cxgb_listen.c */ -void t3_init_listen_cpl_handlers(struct adapter *); -int t3_listen_start(struct toedev *, struct tcpcb *); -int t3_listen_stop(struct toedev *, struct tcpcb *); -void t3_syncache_added(struct toedev *, void *); -void t3_syncache_removed(struct toedev *, void *); -int t3_syncache_respond(struct toedev *, void *, struct mbuf *); -int do_abort_req_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *); -int do_abort_rpl_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *); -void t3_offload_socket(struct toedev *, void *, struct socket *); -#endif diff --git a/sys/modules/cxgb/Makefile b/sys/modules/cxgb/Makefile index f286b79a8dd3..11ea23649baf 100644 --- a/sys/modules/cxgb/Makefile +++ b/sys/modules/cxgb/Makefile @@ -5,14 +5,5 @@ SYSDIR?=${SRCTOP}/sys SUBDIR= cxgb SUBDIR+= cxgb_t3fw -SUBDIR+= ${_tom} -SUBDIR+= ${_iw_cxgb} - -.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" -_tom= tom -.if ${MK_OFED} != "no" || defined(ALL_MODULES) -_iw_cxgb= iw_cxgb -.endif -.endif .include diff --git a/sys/modules/cxgb/iw_cxgb/Makefile b/sys/modules/cxgb/iw_cxgb/Makefile deleted file mode 100644 index fc95ec4dff03..000000000000 --- a/sys/modules/cxgb/iw_cxgb/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $FreeBSD$ - -CXGB = ${SRCTOP}/sys/dev/cxgb -.PATH: ${CXGB}/ulp/iw_cxgb - -KMOD= iw_cxgb -SRCS= iw_cxgb.c iw_cxgb_cm.c iw_cxgb_hal.c -SRCS+= iw_cxgb_provider.c iw_cxgb_qp.c iw_cxgb_resource.c -SRCS+= iw_cxgb_ev.c iw_cxgb_mem.c iw_cxgb_dbg.c iw_cxgb_cq.c -SRCS+= bus_if.h device_if.h opt_sched.h pci_if.h pcib_if.h opt_ktr.h -SRCS+= opt_inet.h opt_ofed.h vnode_if.h -CFLAGS+= -I${CXGB} -I${SRCTOP}/sys/ofed/include -DLINUX_TYPES_DEFINED -CFLAGS+= -I${SRCTOP}/sys/compat/linuxkpi/common/include - -.include diff --git a/sys/modules/cxgb/tom/Makefile b/sys/modules/cxgb/tom/Makefile deleted file mode 100644 index fdf12e70dd93..000000000000 --- a/sys/modules/cxgb/tom/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $FreeBSD$ - -CXGB = ${SRCTOP}/sys/dev/cxgb -.PATH: ${CXGB}/ulp/tom - -KMOD= t3_tom -SRCS= cxgb_tom.c cxgb_cpl_io.c cxgb_listen.c cxgb_l2t.c -SRCS+= opt_compat.h opt_inet.h opt_inet6.h opt_ipsec.h -SRCS+= opt_tcpdebug.h opt_ddb.h opt_sched.h opt_ktr.h -SRCS+= device_if.h bus_if.h pci_if.h -CFLAGS+= -g -I${CXGB} - -#CFLAGS+= -DDEBUG_PRINT -DDEBUG - -.include