/* * Copyright (c) 2006 Oracle. 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. * */ #include #include #include "rds.h" #include "rdma.h" #include "ib.h" /* * This is stored as mr->r_trans_private. */ struct rds_ib_mr { struct rds_ib_device *device; struct rds_ib_mr_pool *pool; struct ib_fmr *fmr; struct list_head list; unsigned int remap_count; struct scatterlist *sg; unsigned int sg_len; u64 *dma; int sg_dma_len; }; /* * Our own little FMR pool */ struct rds_ib_mr_pool { struct mutex flush_lock; /* serialize fmr invalidate */ struct work_struct flush_worker; /* flush worker */ spinlock_t list_lock; /* protect variables below */ atomic_t item_count; /* total # of MRs */ atomic_t dirty_count; /* # dirty of MRs */ struct list_head drop_list; /* MRs that have reached their max_maps limit */ struct list_head free_list; /* unused MRs */ struct list_head clean_list; /* unused & unamapped MRs */ atomic_t free_pinned; /* memory pinned by free MRs */ unsigned long max_items; unsigned long max_items_soft; unsigned long max_free_pinned; struct ib_fmr_attr fmr_attr; }; static int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool, int free_all); static void rds_ib_teardown_mr(struct rds_ib_mr *ibmr); static void rds_ib_mr_pool_flush_worker(struct work_struct *work); static struct rds_ib_device *rds_ib_get_device(__be32 ipaddr) { struct rds_ib_device *rds_ibdev; struct rds_ib_ipaddr *i_ipaddr; list_for_each_entry(rds_ibdev, &rds_ib_devices, list) { spin_lock_irq(&rds_ibdev->spinlock); list_for_each_entry(i_ipaddr, &rds_ibdev->ipaddr_list, list) { if (i_ipaddr->ipaddr == ipaddr) { spin_unlock_irq(&rds_ibdev->spinlock); return rds_ibdev; } } spin_unlock_irq(&rds_ibdev->spinlock); } return NULL; } static int rds_ib_add_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr) { struct rds_ib_ipaddr *i_ipaddr; i_ipaddr = kmalloc(sizeof *i_ipaddr, GFP_KERNEL); if (!i_ipaddr) return -ENOMEM; i_ipaddr->ipaddr = ipaddr; spin_lock_irq(&rds_ibdev->spinlock); list_add_tail(&i_ipaddr->list, &rds_ibdev->ipaddr_list); spin_unlock_irq(&rds_ibdev->spinlock); return 0; } static void rds_ib_remove_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr) { struct rds_ib_ipaddr *i_ipaddr, *next; spin_lock_irq(&rds_ibdev->spinlock); list_for_each_entry_safe(i_ipaddr, next, &rds_ibdev->ipaddr_list, list) { if (i_ipaddr->ipaddr == ipaddr) { list_del(&i_ipaddr->list); kfree(i_ipaddr); break; } } spin_unlock_irq(&rds_ibdev->spinlock); } int rds_ib_update_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr) { struct rds_ib_device *rds_ibdev_old; rds_ibdev_old = rds_ib_get_device(ipaddr); if (rds_ibdev_old) rds_ib_remove_ipaddr(rds_ibdev_old, ipaddr); return rds_ib_add_ipaddr(rds_ibdev, ipaddr); } void rds_ib_add_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn) { struct rds_ib_connection *ic = conn->c_transport_data; /* conn was previously on the nodev_conns_list */ spin_lock_irq(&ib_nodev_conns_lock); BUG_ON(list_empty(&ib_nodev_conns)); BUG_ON(list_empty(&ic->ib_node)); list_del(&ic->ib_node); spin_lock_irq(&rds_ibdev->spinlock); list_add_tail(&ic->ib_node, &rds_ibdev->conn_list); spin_unlock_irq(&rds_ibdev->spinlock); spin_unlock_irq(&ib_nodev_conns_lock); ic->rds_ibdev = rds_ibdev; } void rds_ib_remove_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn) { struct rds_ib_connection *ic = conn->c_transport_data; /* place conn on nodev_conns_list */ spin_lock(&ib_nodev_conns_lock); spin_lock_irq(&rds_ibdev->spinlock); BUG_ON(list_empty(&ic->ib_node)); list_del(&ic->ib_node); spin_unlock_irq(&rds_ibdev->spinlock); list_add_tail(&ic->ib_node, &ib_nodev_conns); spin_unlock(&ib_nodev_conns_lock); ic->rds_ibdev = NULL; } void __rds_ib_destroy_conns(struct list_head *list, spinlock_t *list_lock) { struct rds_ib_connection *ic, *_ic; LIST_HEAD(tmp_list); /* avoid calling conn_destroy with irqs off */ spin_lock_irq(list_lock); list_splice(list, &tmp_list); INIT_LIST_HEAD(list); spin_unlock_irq(list_lock); list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node) rds_conn_destroy(ic->conn); } struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev) { struct rds_ib_mr_pool *pool; pool = kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&pool->free_list); INIT_LIST_HEAD(&pool->drop_list); INIT_LIST_HEAD(&pool->clean_list); mutex_init(&pool->flush_lock); spin_lock_init(&pool->list_lock); INIT_WORK(&pool->flush_worker, rds_ib_mr_pool_flush_worker); pool->fmr_attr.max_pages = fmr_message_size; pool->fmr_attr.max_maps = rds_ibdev->fmr_max_remaps; pool->fmr_attr.page_shift = PAGE_SHIFT; pool->max_free_pinned = rds_ibdev->max_fmrs * fmr_message_size / 4; /* We never allow more than max_items MRs to be allocated. * When we exceed more than max_items_soft, we start freeing * items more aggressively. * Make sure that max_items > max_items_soft > max_items / 2 */ pool->max_items_soft = rds_ibdev->max_fmrs * 3 / 4; pool->max_items = rds_ibdev->max_fmrs; return pool; } void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, struct rds_info_rdma_connection *iinfo) { struct rds_ib_mr_pool *pool = rds_ibdev->mr_pool; iinfo->rdma_mr_max = pool->max_items; iinfo->rdma_mr_size = pool->fmr_attr.max_pages; } void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *pool) { flush_workqueue(rds_wq); rds_ib_flush_mr_pool(pool, 1); WARN_ON(atomic_read(&pool->item_count)); WARN_ON(atomic_read(&pool->free_pinned)); kfree(pool); } static inline struct rds_ib_mr *rds_ib_reuse_fmr(struct rds_ib_mr_pool *pool) { struct rds_ib_mr *ibmr = NULL; unsigned long flags; spin_lock_irqsave(&pool->list_lock, flags); if (!list_empty(&pool->clean_list)) { ibmr = list_entry(pool->clean_list.next, struct rds_ib_mr, list); list_del_init(&ibmr->list); } spin_unlock_irqrestore(&pool->list_lock, flags); return ibmr; } static struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *rds_ibdev) { struct rds_ib_mr_pool *pool = rds_ibdev->mr_pool; struct rds_ib_mr *ibmr = NULL; int err = 0, iter = 0; while (1) { ibmr = rds_ib_reuse_fmr(pool); if (ibmr) return ibmr; /* No clean MRs - now we have the choice of either * allocating a fresh MR up to the limit imposed by the * driver, or flush any dirty unused MRs. * We try to avoid stalling in the send path if possible, * so we allocate as long as we're allowed to. * * We're fussy with enforcing the FMR limit, though. If the driver * tells us we can't use more than N fmrs, we shouldn't start * arguing with it */ if (atomic_inc_return(&pool->item_count) <= pool->max_items) break; atomic_dec(&pool->item_count); if (++iter > 2) { rds_ib_stats_inc(s_ib_rdma_mr_pool_depleted); return ERR_PTR(-EAGAIN); } /* We do have some empty MRs. Flush them out. */ rds_ib_stats_inc(s_ib_rdma_mr_pool_wait); rds_ib_flush_mr_pool(pool, 0); } ibmr = kzalloc(sizeof(*ibmr), GFP_KERNEL); if (!ibmr) { err = -ENOMEM; goto out_no_cigar; } ibmr->fmr = ib_alloc_fmr(rds_ibdev->pd, (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_READ | IB_ACCESS_REMOTE_WRITE), &pool->fmr_attr); if (IS_ERR(ibmr->fmr)) { err = PTR_ERR(ibmr->fmr); ibmr->fmr = NULL; printk(KERN_WARNING "RDS/IB: ib_alloc_fmr failed (err=%d)\n", err); goto out_no_cigar; } rds_ib_stats_inc(s_ib_rdma_mr_alloc); return ibmr; out_no_cigar: if (ibmr) { if (ibmr->fmr) ib_dealloc_fmr(ibmr->fmr); kfree(ibmr); } atomic_dec(&pool->item_count); return ERR_PTR(err); } static int rds_ib_map_fmr(struct rds_ib_device *rds_ibde
#ifndef LLC_C_AC_H
#define LLC_C_AC_H
/*
 * Copyright (c) 1997 by Procom Technology,Inc.
 * 		 2001 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
 *
 * This program can be redistributed or modified under the terms of the
 * GNU General Public License as published by the Free Software Foundation.
 * This program is distributed without any warranty or implied warranty
 * of merchantability or fitness for a particular purpose.
 *
 * See the GNU General Public License for more details.
 */
/* Connection component state transition actions */
/*
 * Connection state transition actions
 * (Fb = F bit; Pb = P bit; Xb = X bit)
 */
#define LLC_CONN_AC_CLR_REMOTE_BUSY			 1
#define LLC_CONN_AC_CONN_IND				 2
#define LLC_CONN_AC_CONN_CONFIRM			 3
#define LLC_CONN_AC_DATA_IND				 4
#define LLC_CONN_AC_DISC_IND				 5
#define LLC_CONN_AC_RESET_IND				 6
#define LLC_CONN_AC_RESET_CONFIRM			 7
#define LLC_CONN_AC_REPORT_STATUS			 8
#define LLC_CONN_AC_CLR_REMOTE_BUSY_IF_Fb_EQ_1		 9
#define LLC_CONN_AC_STOP_REJ_TMR_IF_DATA_FLAG_EQ_2	10
#define LLC_CONN_AC_SEND_DISC_CMD_Pb_SET_X		11
#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_Pb		12
#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_1		13
#define LLC_CONN_AC_SEND_DM_RSP_Fb_SET_F_FLAG		14
#define LLC_CONN_AC_SEND_FRMR_RSP_Fb_SET_X		15
#define LLC_CONN_AC_RESEND_FRMR_RSP_Fb_SET_0		16</