···1/*2- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.3- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.4- * Copyright (c) 2004 Intel Corporation. All rights reserved.5- * Copyright (c) 2004 Topspin Corporation. All rights reserved.6- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.07 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU···4142#include <asm/bug.h>4344-#include <ib_smi.h>4546#include "smi.h"47#include "agent_priv.h"
···1/*2+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.3+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.4+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.5+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.6+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.7+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.8 *9 * This software is available to you under a choice of one of two10 * licenses. You may choose to be licensed under the terms of the GNU···4041#include <asm/bug.h>4243+#include <rdma/ib_smi.h>4445#include "smi.h"46#include "agent_priv.h"
+5-5
drivers/infiniband/core/agent_priv.h
···1/*2- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.3- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.4- * Copyright (c) 2004 Intel Corporation. All rights reserved.5- * Copyright (c) 2004 Topspin Corporation. All rights reserved.6- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.7 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.3+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.4+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.5+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.6+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.7 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU
+4-2
drivers/infiniband/core/cache.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.0003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···35 * $Id: cache.c 1349 2004-12-16 21:09:43Z roland $36 */3738-#include <linux/version.h>39#include <linux/module.h>40#include <linux/errno.h>41#include <linux/slab.h>4243-#include <ib_cache.h>4445#include "core_priv.h"46
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Intel Corporation. All rights reserved.4+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.6 *7 * This software is available to you under a choice of one of two8 * licenses. You may choose to be licensed under the terms of the GNU···32 * $Id: cache.c 1349 2004-12-16 21:09:43Z roland $33 */34035#include <linux/module.h>36#include <linux/errno.h>37#include <linux/slab.h>3839+#include <rdma/ib_cache.h>4041#include "core_priv.h"42
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2 * Copyright (c) 2004 Topspin Corporation. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···33 * $Id: packer.c 1349 2004-12-16 21:09:43Z roland $34 */3536-#include <ib_pack.h>3738static u64 value_read(int offset, int size, void *structure)39{
···1/*2 * Copyright (c) 2004 Topspin Corporation. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···32 * $Id: packer.c 1349 2004-12-16 21:09:43Z roland $33 */3435+#include <rdma/ib_pack.h>3637static u64 value_read(int offset, int size, void *structure)38{
+3-3
drivers/infiniband/core/sa_query.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3- * Copyright (c) 2005 Voltaire, Inc. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···44#include <linux/kref.h>45#include <linux/idr.h>4647-#include <ib_pack.h>48-#include <ib_sa.h>4950MODULE_AUTHOR("Roland Dreier");51MODULE_DESCRIPTION("InfiniBand subnet administration query support");
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···44#include <linux/kref.h>45#include <linux/idr.h>4647+#include <rdma/ib_pack.h>48+#include <rdma/ib_sa.h>4950MODULE_AUTHOR("Roland Dreier");51MODULE_DESCRIPTION("InfiniBand subnet administration query support");
+7-6
drivers/infiniband/core/smi.c
···1/*2- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.3- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.4- * Copyright (c) 2004 Intel Corporation. All rights reserved.5- * Copyright (c) 2004 Topspin Corporation. All rights reserved.6- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.07 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU···37 * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $38 */3940-#include <ib_smi.h>41#include "smi.h"4243/*
···1/*2+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.3+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.4+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.5+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.6+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.7+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.8 *9 * This software is available to you under a choice of one of two10 * licenses. You may choose to be licensed under the terms of the GNU···36 * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $37 */3839+#include <rdma/ib_smi.h>40#include "smi.h"4142/*
+21-19
drivers/infiniband/core/sysfs.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···3637#include "core_priv.h"3839-#include <ib_mad.h>4041struct ib_port {42 struct kobject kobj;···255 return ret;256257 return sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",258- be16_to_cpu(((u16 *) gid.raw)[0]),259- be16_to_cpu(((u16 *) gid.raw)[1]),260- be16_to_cpu(((u16 *) gid.raw)[2]),261- be16_to_cpu(((u16 *) gid.raw)[3]),262- be16_to_cpu(((u16 *) gid.raw)[4]),263- be16_to_cpu(((u16 *) gid.raw)[5]),264- be16_to_cpu(((u16 *) gid.raw)[6]),265- be16_to_cpu(((u16 *) gid.raw)[7]));266}267268static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,···334 break;335 case 16:336 ret = sprintf(buf, "%u\n",337- be16_to_cpup((u16 *)(out_mad->data + 40 + offset / 8)));338 break;339 case 32:340 ret = sprintf(buf, "%u\n",341- be32_to_cpup((u32 *)(out_mad->data + 40 + offset / 8)));342 break;343 default:344 ret = 0;···600 return ret;601602 return sprintf(buf, "%04x:%04x:%04x:%04x\n",603- be16_to_cpu(((u16 *) &attr.sys_image_guid)[0]),604- be16_to_cpu(((u16 *) &attr.sys_image_guid)[1]),605- be16_to_cpu(((u16 *) &attr.sys_image_guid)[2]),606- be16_to_cpu(((u16 *) &attr.sys_image_guid)[3]));607}608609static ssize_t show_node_guid(struct class_device *cdev, char *buf)···617 return ret;618619 return sprintf(buf, "%04x:%04x:%04x:%04x\n",620- be16_to_cpu(((u16 *) &attr.node_guid)[0]),621- be16_to_cpu(((u16 *) &attr.node_guid)[1]),622- be16_to_cpu(((u16 *) &attr.node_guid)[2]),623- be16_to_cpu(((u16 *) &attr.node_guid)[3]));624}625626static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.4+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···3435#include "core_priv.h"3637+#include <rdma/ib_mad.h>3839struct ib_port {40 struct kobject kobj;···253 return ret;254255 return sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",256+ be16_to_cpu(((__be16 *) gid.raw)[0]),257+ be16_to_cpu(((__be16 *) gid.raw)[1]),258+ be16_to_cpu(((__be16 *) gid.raw)[2]),259+ be16_to_cpu(((__be16 *) gid.raw)[3]),260+ be16_to_cpu(((__be16 *) gid.raw)[4]),261+ be16_to_cpu(((__be16 *) gid.raw)[5]),262+ be16_to_cpu(((__be16 *) gid.raw)[6]),263+ be16_to_cpu(((__be16 *) gid.raw)[7]));264}265266static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,···332 break;333 case 16:334 ret = sprintf(buf, "%u\n",335+ be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8)));336 break;337 case 32:338 ret = sprintf(buf, "%u\n",339+ be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8)));340 break;341 default:342 ret = 0;···598 return ret;599600 return sprintf(buf, "%04x:%04x:%04x:%04x\n",601+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[0]),602+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[1]),603+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[2]),604+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));605}606607static ssize_t show_node_guid(struct class_device *cdev, char *buf)···615 return ret;616617 return sprintf(buf, "%04x:%04x:%04x:%04x\n",618+ be16_to_cpu(((__be16 *) &attr.node_guid)[0]),619+ be16_to_cpu(((__be16 *) &attr.node_guid)[1]),620+ be16_to_cpu(((__be16 *) &attr.node_guid)[2]),621+ be16_to_cpu(((__be16 *) &attr.node_guid)[3]));622}623624static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
+157-307
drivers/infiniband/core/ucm.c
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···74static struct idr ctx_id_table;75static int ctx_id_rover = 0;7677-static struct ib_ucm_context *ib_ucm_ctx_get(int id)78{79 struct ib_ucm_context *ctx;8081 down(&ctx_id_mutex);82 ctx = idr_find(&ctx_id_table, id);83- if (ctx)84- ctx->ref++;000085 up(&ctx_id_mutex);8687 return ctx;···9394static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)95{000000096 struct ib_ucm_event *uevent;9798 down(&ctx_id_mutex);99-100- ctx->ref--;101- if (!ctx->ref)000102 idr_remove(&ctx_id_table, ctx->id);103-104 up(&ctx_id_mutex);105106- if (ctx->ref)107- return;108109- down(&ctx->file->mutex);0110000000111 list_del(&ctx->file_list);112 while (!list_empty(&ctx->events)) {113···138139 kfree(uevent);140 }0141142- up(&ctx->file->mutex);143-144- ucm_dbg("Destroyed CM ID <%d>\n", ctx->id);145-146- ib_destroy_cm_id(ctx->cm_id);147 kfree(ctx);0148}149150static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)···153 if (!ctx)154 return NULL;155156- ctx->ref = 1; /* user reference */0157 ctx->file = file;158159 INIT_LIST_HEAD(&ctx->events);160- init_MUTEX(&ctx->mutex);161162 list_add_tail(&ctx->file_list, &file->ctxs);163···195 if (!kpath || !upath)196 return;197198- memcpy(upath->dgid, kpath->dgid.raw, sizeof(union ib_gid));199- memcpy(upath->sgid, kpath->sgid.raw, sizeof(union ib_gid));200201 upath->dlid = kpath->dlid;202 upath->slid = kpath->slid;···219 kpath->packet_life_time_selector;220}221222-static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,0223 struct ib_cm_req_event_param *kreq)224{225- ureq->listen_id = (long)kreq->listen_id->context;226227 ureq->remote_ca_guid = kreq->remote_ca_guid;228 ureq->remote_qkey = kreq->remote_qkey;···259 urep->srq = krep->srq;260}261262-static void ib_ucm_event_rej_get(struct ib_ucm_rej_event_resp *urej,263- struct ib_cm_rej_event_param *krej)264-{265- urej->reason = krej->reason;266-}267-268-static void ib_ucm_event_mra_get(struct ib_ucm_mra_event_resp *umra,269- struct ib_cm_mra_event_param *kmra)270-{271- umra->timeout = kmra->service_timeout;272-}273-274-static void ib_ucm_event_lap_get(struct ib_ucm_lap_event_resp *ulap,275- struct ib_cm_lap_event_param *klap)276-{277- ib_ucm_event_path_get(&ulap->path, klap->alternate_path);278-}279-280-static void ib_ucm_event_apr_get(struct ib_ucm_apr_event_resp *uapr,281- struct ib_cm_apr_event_param *kapr)282-{283- uapr->status = kapr->ap_status;284-}285-286-static void ib_ucm_event_sidr_req_get(struct ib_ucm_sidr_req_event_resp *ureq,287 struct ib_cm_sidr_req_event_param *kreq)288{289- ureq->listen_id = (long)kreq->listen_id->context;290 ureq->pkey = kreq->pkey;291}292···275 urep->qpn = krep->qpn;276};277278-static int ib_ucm_event_process(struct ib_cm_event *evt,0279 struct ib_ucm_event *uvt)280{281 void *info = NULL;282- int result;283284 switch (evt->event) {285 case IB_CM_REQ_RECEIVED:286- ib_ucm_event_req_get(&uvt->resp.u.req_resp,287 &evt->param.req_rcvd);288 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;289- uvt->resp.present |= (evt->param.req_rcvd.primary_path ?290- IB_UCM_PRES_PRIMARY : 0);291 uvt->resp.present |= (evt->param.req_rcvd.alternate_path ?292 IB_UCM_PRES_ALTERNATE : 0);293 break;···294 ib_ucm_event_rep_get(&uvt->resp.u.rep_resp,295 &evt->param.rep_rcvd);296 uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE;297-298 break;299 case IB_CM_RTU_RECEIVED:300 uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE;301 uvt->resp.u.send_status = evt->param.send_status;302-303 break;304 case IB_CM_DREQ_RECEIVED:305 uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE;306 uvt->resp.u.send_status = evt->param.send_status;307-308 break;309 case IB_CM_DREP_RECEIVED:310 uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE;311 uvt->resp.u.send_status = evt->param.send_status;312-313 break;314 case IB_CM_MRA_RECEIVED:315- ib_ucm_event_mra_get(&uvt->resp.u.mra_resp,316- &evt->param.mra_rcvd);317 uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE;318-319 break;320 case IB_CM_REJ_RECEIVED:321- ib_ucm_event_rej_get(&uvt->resp.u.rej_resp,322- &evt->param.rej_rcvd);323 uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE;324 uvt->info_len = evt->param.rej_rcvd.ari_length;325 info = evt->param.rej_rcvd.ari;326-327 break;328 case IB_CM_LAP_RECEIVED:329- ib_ucm_event_lap_get(&uvt->resp.u.lap_resp,330- &evt->param.lap_rcvd);331 uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE;332- uvt->resp.present |= (evt->param.lap_rcvd.alternate_path ?333- IB_UCM_PRES_ALTERNATE : 0);334 break;335 case IB_CM_APR_RECEIVED:336- ib_ucm_event_apr_get(&uvt->resp.u.apr_resp,337- &evt->param.apr_rcvd);338 uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE;339 uvt->info_len = evt->param.apr_rcvd.info_len;340 info = evt->param.apr_rcvd.apr_info;341-342 break;343 case IB_CM_SIDR_REQ_RECEIVED:344- ib_ucm_event_sidr_req_get(&uvt->resp.u.sidr_req_resp,345 &evt->param.sidr_req_rcvd);346 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;347-348 break;349 case IB_CM_SIDR_REP_RECEIVED:350 ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp,···341 uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE;342 uvt->info_len = evt->param.sidr_rep_rcvd.info_len;343 info = evt->param.sidr_rep_rcvd.info;344-345 break;346 default:347 uvt->resp.u.send_status = evt->param.send_status;348-349 break;350 }351352- if (uvt->data_len && evt->private_data) {353-354 uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);355- if (!uvt->data) {356- result = -ENOMEM;357- goto error;358- }359360 memcpy(uvt->data, evt->private_data, uvt->data_len);361 uvt->resp.present |= IB_UCM_PRES_DATA;362 }363364- if (uvt->info_len && info) {365-366 uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);367- if (!uvt->info) {368- result = -ENOMEM;369- goto error;370- }371372 memcpy(uvt->info, info, uvt->info_len);373 uvt->resp.present |= IB_UCM_PRES_INFO;374 }375-376 return 0;377-error:378- kfree(uvt->info);379 kfree(uvt->data);380- return result;0381}382383static int ib_ucm_event_handler(struct ib_cm_id *cm_id,···379 struct ib_ucm_context *ctx;380 int result = 0;381 int id;382- /*383- * lookup correct context based on event type.384- */385- switch (event->event) {386- case IB_CM_REQ_RECEIVED:387- id = (long)event->param.req_rcvd.listen_id->context;388- break;389- case IB_CM_SIDR_REQ_RECEIVED:390- id = (long)event->param.sidr_req_rcvd.listen_id->context;391- break;392- default:393- id = (long)cm_id->context;394- break;395- }396397- ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event);398-399- ctx = ib_ucm_ctx_get(id);400- if (!ctx)401- return -ENOENT;402403 if (event->event == IB_CM_REQ_RECEIVED ||404 event->event == IB_CM_SIDR_REQ_RECEIVED)405 id = IB_UCM_CM_ID_INVALID;00406407 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL);408- if (!uevent) {409- result = -ENOMEM;410- goto done;411- }412413 memset(uevent, 0, sizeof(*uevent));414-415 uevent->resp.id = id;416 uevent->resp.event = event->event;417418- result = ib_ucm_event_process(event, uevent);419 if (result)420- goto done;421422 uevent->ctx = ctx;423- uevent->cm_id = ((event->event == IB_CM_REQ_RECEIVED ||424- event->event == IB_CM_SIDR_REQ_RECEIVED ) ?425- cm_id : NULL);426427 down(&ctx->file->mutex);428-429 list_add_tail(&uevent->file_list, &ctx->file->events);430 list_add_tail(&uevent->ctx_list, &ctx->events);431-432 wake_up_interruptible(&ctx->file->poll_wait);433-434 up(&ctx->file->mutex);435-done:436- ctx->error = result;437- ib_ucm_ctx_put(ctx); /* func reference */438- return result;000439}440441static ssize_t ib_ucm_event(struct ib_ucm_file *file,···472 goto done;473 }474475- ctx->cm_id = uevent->cm_id;476- ctx->cm_id->cm_handler = ib_ucm_event_handler;477- ctx->cm_id->context = (void *)(unsigned long)ctx->id;478479 uevent->resp.id = ctx->id;480···539 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))540 return -EFAULT;5410542 ctx = ib_ucm_ctx_alloc(file);0543 if (!ctx)544 return -ENOMEM;545546- ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler,547- (void *)(unsigned long)ctx->id);548- if (!ctx->cm_id) {549- result = -ENOMEM;550- goto err_cm;551 }552553 resp.id = ctx->id;554 if (copy_to_user((void __user *)(unsigned long)cmd.response,555 &resp, sizeof(resp))) {556 result = -EFAULT;557- goto err_ret;558 }559560 return 0;561-err_ret:562- ib_destroy_cm_id(ctx->cm_id);563-err_cm:564- ib_ucm_ctx_put(ctx); /* user reference */56500566 return result;567}568···570 int in_len, int out_len)571{572 struct ib_ucm_destroy_id cmd;573- struct ib_ucm_context *ctx;574575 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))576 return -EFAULT;577578- ctx = ib_ucm_ctx_get(cmd.id);579- if (!ctx)580- return -ENOENT;581-582- ib_ucm_ctx_put(ctx); /* user reference */583- ib_ucm_ctx_put(ctx); /* func reference */584-585- return 0;586}587588static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,···592 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))593 return -EFAULT;594595- ctx = ib_ucm_ctx_get(cmd.id);596- if (!ctx)597- return -ENOENT;598-599- down(&ctx->file->mutex);600- if (ctx->file != file) {601- result = -EINVAL;602- goto done;603- }604605 resp.service_id = ctx->cm_id->service_id;606 resp.service_mask = ctx->cm_id->service_mask;···605 &resp, sizeof(resp)))606 result = -EFAULT;607608-done:609- up(&ctx->file->mutex);610- ib_ucm_ctx_put(ctx); /* func reference */611 return result;612}613···620 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))621 return -EFAULT;622623- ctx = ib_ucm_ctx_get(cmd.id);624- if (!ctx)625- return -ENOENT;626627- down(&ctx->file->mutex);628- if (ctx->file != file)629- result = -EINVAL;630- else631- result = ib_cm_listen(ctx->cm_id, cmd.service_id,632- cmd.service_mask);633-634- up(&ctx->file->mutex);635- ib_ucm_ctx_put(ctx); /* func reference */636 return result;637}638···640 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))641 return -EFAULT;642643- ctx = ib_ucm_ctx_get(cmd.id);644- if (!ctx)645- return -ENOENT;646647- down(&ctx->file->mutex);648- if (ctx->file != file)649- result = -EINVAL;650- else651- result = ib_cm_establish(ctx->cm_id);652-653- up(&ctx->file->mutex);654- ib_ucm_ctx_put(ctx); /* func reference */655 return result;656}657···692 return -EFAULT;693 }694695- memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof(union ib_gid));696- memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof(union ib_gid));697698 sa_path->dlid = ucm_path.dlid;699 sa_path->slid = ucm_path.slid;···763 param.max_cm_retries = cmd.max_cm_retries;764 param.srq = cmd.srq;765766- ctx = ib_ucm_ctx_get(cmd.id);767- if (!ctx) {768- result = -ENOENT;769- goto done;770- }771-772- down(&ctx->file->mutex);773- if (ctx->file != file)774- result = -EINVAL;775- else776 result = ib_send_cm_req(ctx->cm_id, ¶m);000777778- up(&ctx->file->mutex);779- ib_ucm_ctx_put(ctx); /* func reference */780done:781 kfree(param.private_data);782 kfree(param.primary_path);783 kfree(param.alternate_path);784-785 return result;786}787···806 param.rnr_retry_count = cmd.rnr_retry_count;807 param.srq = cmd.srq;808809- ctx = ib_ucm_ctx_get(cmd.id);810- if (!ctx) {811- result = -ENOENT;812- goto done;813- }814-815- down(&ctx->file->mutex);816- if (ctx->file != file)817- result = -EINVAL;818- else819 result = ib_send_cm_rep(ctx->cm_id, ¶m);000820821- up(&ctx->file->mutex);822- ib_ucm_ctx_put(ctx); /* func reference */823-done:824 kfree(param.private_data);825-826 return result;827}828···835 if (result)836 return result;837838- ctx = ib_ucm_ctx_get(cmd.id);839- if (!ctx) {840- result = -ENOENT;841- goto done;842- }843-844- down(&ctx->file->mutex);845- if (ctx->file != file)846- result = -EINVAL;847- else848 result = func(ctx->cm_id, private_data, cmd.len);000849850- up(&ctx->file->mutex);851- ib_ucm_ctx_put(ctx); /* func reference */852-done:853 kfree(private_data);854-855 return result;856}857···893 if (result)894 goto done;895896- ctx = ib_ucm_ctx_get(cmd.id);897- if (!ctx) {898- result = -ENOENT;899- goto done;900- }901-902- down(&ctx->file->mutex);903- if (ctx->file != file)904- result = -EINVAL;905- else906- result = func(ctx->cm_id, cmd.status,907- info, cmd.info_len,908 data, cmd.data_len);000909910- up(&ctx->file->mutex);911- ib_ucm_ctx_put(ctx); /* func reference */912done:913 kfree(data);914 kfree(info);915-916 return result;917}918···937 if (result)938 return result;939940- ctx = ib_ucm_ctx_get(cmd.id);941- if (!ctx) {942- result = -ENOENT;943- goto done;944- }0945946- down(&ctx->file->mutex);947- if (ctx->file != file)948- result = -EINVAL;949- else950- result = ib_send_cm_mra(ctx->cm_id, cmd.timeout,951- data, cmd.len);952-953- up(&ctx->file->mutex);954- ib_ucm_ctx_put(ctx); /* func reference */955-done:956 kfree(data);957-958 return result;959}960···969 if (result)970 goto done;971972- ctx = ib_ucm_ctx_get(cmd.id);973- if (!ctx) {974- result = -ENOENT;975- goto done;976- }977-978- down(&ctx->file->mutex);979- if (ctx->file != file)980- result = -EINVAL;981- else982 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len);000983984- up(&ctx->file->mutex);985- ib_ucm_ctx_put(ctx); /* func reference */986done:987 kfree(data);988 kfree(path);989-990 return result;991}992···1011 param.max_cm_retries = cmd.max_cm_retries;1012 param.pkey = cmd.pkey;10131014- ctx = ib_ucm_ctx_get(cmd.id);1015- if (!ctx) {1016- result = -ENOENT;1017- goto done;1018- }1019-1020- down(&ctx->file->mutex);1021- if (ctx->file != file)1022- result = -EINVAL;1023- else1024 result = ib_send_cm_sidr_req(ctx->cm_id, ¶m);00010251026- up(&ctx->file->mutex);1027- ib_ucm_ctx_put(ctx); /* func reference */1028done:1029 kfree(param.private_data);1030 kfree(param.path);1031-1032 return result;1033}1034···1047 if (result)1048 goto done;10491050- param.qp_num = cmd.qpn;1051- param.qkey = cmd.qkey;1052- param.status = cmd.status;1053- param.info_length = cmd.info_len;1054- param.private_data_len = cmd.data_len;10551056- ctx = ib_ucm_ctx_get(cmd.id);1057- if (!ctx) {1058- result = -ENOENT;1059- goto done;1060- }1061-1062- down(&ctx->file->mutex);1063- if (ctx->file != file)1064- result = -EINVAL;1065- else1066 result = ib_send_cm_sidr_rep(ctx->cm_id, ¶m);00010671068- up(&ctx->file->mutex);1069- ib_ucm_ctx_put(ctx); /* func reference */1070done:1071 kfree(param.private_data);1072 kfree(param.info);1073-1074 return result;1075}1076···1160 struct ib_ucm_context *ctx;11611162 down(&file->mutex);1163-1164 while (!list_empty(&file->ctxs)) {11651166 ctx = list_entry(file->ctxs.next,1167 struct ib_ucm_context, file_list);11681169- up(&ctx->file->mutex);1170- ib_ucm_ctx_put(ctx); /* user reference */1171 down(&file->mutex);1172 }1173-1174 up(&file->mutex);1175-1176 kfree(file);1177-1178- ucm_dbg("Deleted struct\n");1179 return 0;1180}1181
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Intel Corporation. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···73static struct idr ctx_id_table;74static int ctx_id_rover = 0;7576+static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)77{78 struct ib_ucm_context *ctx;7980 down(&ctx_id_mutex);81 ctx = idr_find(&ctx_id_table, id);82+ if (!ctx)83+ ctx = ERR_PTR(-ENOENT);84+ else if (ctx->file != file)85+ ctx = ERR_PTR(-EINVAL);86+ else87+ atomic_inc(&ctx->ref);88 up(&ctx_id_mutex);8990 return ctx;···8889static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)90{91+ if (atomic_dec_and_test(&ctx->ref))92+ wake_up(&ctx->wait);93+}94+95+static ssize_t ib_ucm_destroy_ctx(struct ib_ucm_file *file, int id)96+{97+ struct ib_ucm_context *ctx;98 struct ib_ucm_event *uevent;99100 down(&ctx_id_mutex);101+ ctx = idr_find(&ctx_id_table, id);102+ if (!ctx)103+ ctx = ERR_PTR(-ENOENT);104+ else if (ctx->file != file)105+ ctx = ERR_PTR(-EINVAL);106+ else107 idr_remove(&ctx_id_table, ctx->id);0108 up(&ctx_id_mutex);109110+ if (IS_ERR(ctx))111+ return PTR_ERR(ctx);112113+ atomic_dec(&ctx->ref);114+ wait_event(ctx->wait, !atomic_read(&ctx->ref));115116+ /* No new events will be generated after destroying the cm_id. */117+ if (!IS_ERR(ctx->cm_id))118+ ib_destroy_cm_id(ctx->cm_id);119+120+ /* Cleanup events not yet reported to the user. */121+ down(&file->mutex);122 list_del(&ctx->file_list);123 while (!list_empty(&ctx->events)) {124···117118 kfree(uevent);119 }120+ up(&file->mutex);12100000122 kfree(ctx);123+ return 0;124}125126static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)···135 if (!ctx)136 return NULL;137138+ atomic_set(&ctx->ref, 1);139+ init_waitqueue_head(&ctx->wait);140 ctx->file = file;141142 INIT_LIST_HEAD(&ctx->events);0143144 list_add_tail(&ctx->file_list, &file->ctxs);145···177 if (!kpath || !upath)178 return;179180+ memcpy(upath->dgid, kpath->dgid.raw, sizeof *upath->dgid);181+ memcpy(upath->sgid, kpath->sgid.raw, sizeof *upath->sgid);182183 upath->dlid = kpath->dlid;184 upath->slid = kpath->slid;···201 kpath->packet_life_time_selector;202}203204+static void ib_ucm_event_req_get(struct ib_ucm_context *ctx,205+ struct ib_ucm_req_event_resp *ureq,206 struct ib_cm_req_event_param *kreq)207{208+ ureq->listen_id = ctx->id;209210 ureq->remote_ca_guid = kreq->remote_ca_guid;211 ureq->remote_qkey = kreq->remote_qkey;···240 urep->srq = krep->srq;241}242243+static void ib_ucm_event_sidr_req_get(struct ib_ucm_context *ctx,244+ struct ib_ucm_sidr_req_event_resp *ureq,00000000000000000000000245 struct ib_cm_sidr_req_event_param *kreq)246{247+ ureq->listen_id = ctx->id;248 ureq->pkey = kreq->pkey;249}250···279 urep->qpn = krep->qpn;280};281282+static int ib_ucm_event_process(struct ib_ucm_context *ctx,283+ struct ib_cm_event *evt,284 struct ib_ucm_event *uvt)285{286 void *info = NULL;0287288 switch (evt->event) {289 case IB_CM_REQ_RECEIVED:290+ ib_ucm_event_req_get(ctx, &uvt->resp.u.req_resp,291 &evt->param.req_rcvd);292 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;293+ uvt->resp.present = IB_UCM_PRES_PRIMARY;0294 uvt->resp.present |= (evt->param.req_rcvd.alternate_path ?295 IB_UCM_PRES_ALTERNATE : 0);296 break;···299 ib_ucm_event_rep_get(&uvt->resp.u.rep_resp,300 &evt->param.rep_rcvd);301 uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE;0302 break;303 case IB_CM_RTU_RECEIVED:304 uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE;305 uvt->resp.u.send_status = evt->param.send_status;0306 break;307 case IB_CM_DREQ_RECEIVED:308 uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE;309 uvt->resp.u.send_status = evt->param.send_status;0310 break;311 case IB_CM_DREP_RECEIVED:312 uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE;313 uvt->resp.u.send_status = evt->param.send_status;0314 break;315 case IB_CM_MRA_RECEIVED:316+ uvt->resp.u.mra_resp.timeout =317+ evt->param.mra_rcvd.service_timeout;318 uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE;0319 break;320 case IB_CM_REJ_RECEIVED:321+ uvt->resp.u.rej_resp.reason = evt->param.rej_rcvd.reason;0322 uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE;323 uvt->info_len = evt->param.rej_rcvd.ari_length;324 info = evt->param.rej_rcvd.ari;0325 break;326 case IB_CM_LAP_RECEIVED:327+ ib_ucm_event_path_get(&uvt->resp.u.lap_resp.path,328+ evt->param.lap_rcvd.alternate_path);329 uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE;330+ uvt->resp.present = IB_UCM_PRES_ALTERNATE;0331 break;332 case IB_CM_APR_RECEIVED:333+ uvt->resp.u.apr_resp.status = evt->param.apr_rcvd.ap_status;0334 uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE;335 uvt->info_len = evt->param.apr_rcvd.info_len;336 info = evt->param.apr_rcvd.apr_info;0337 break;338 case IB_CM_SIDR_REQ_RECEIVED:339+ ib_ucm_event_sidr_req_get(ctx, &uvt->resp.u.sidr_req_resp,340 &evt->param.sidr_req_rcvd);341 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;0342 break;343 case IB_CM_SIDR_REP_RECEIVED:344 ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp,···357 uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE;358 uvt->info_len = evt->param.sidr_rep_rcvd.info_len;359 info = evt->param.sidr_rep_rcvd.info;0360 break;361 default:362 uvt->resp.u.send_status = evt->param.send_status;0363 break;364 }365366+ if (uvt->data_len) {0367 uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);368+ if (!uvt->data)369+ goto err1;00370371 memcpy(uvt->data, evt->private_data, uvt->data_len);372 uvt->resp.present |= IB_UCM_PRES_DATA;373 }374375+ if (uvt->info_len) {0376 uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);377+ if (!uvt->info)378+ goto err2;00379380 memcpy(uvt->info, info, uvt->info_len);381 uvt->resp.present |= IB_UCM_PRES_INFO;382 }0383 return 0;384+385+err2:386 kfree(uvt->data);387+err1:388+ return -ENOMEM;389}390391static int ib_ucm_event_handler(struct ib_cm_id *cm_id,···403 struct ib_ucm_context *ctx;404 int result = 0;405 int id;00000000000000406407+ ctx = cm_id->context;0000408409 if (event->event == IB_CM_REQ_RECEIVED ||410 event->event == IB_CM_SIDR_REQ_RECEIVED)411 id = IB_UCM_CM_ID_INVALID;412+ else413+ id = ctx->id;414415 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL);416+ if (!uevent)417+ goto err1;00418419 memset(uevent, 0, sizeof(*uevent));0420 uevent->resp.id = id;421 uevent->resp.event = event->event;422423+ result = ib_ucm_event_process(ctx, event, uevent);424 if (result)425+ goto err2;426427 uevent->ctx = ctx;428+ uevent->cm_id = (id == IB_UCM_CM_ID_INVALID) ? cm_id : NULL;00429430 down(&ctx->file->mutex);0431 list_add_tail(&uevent->file_list, &ctx->file->events);432 list_add_tail(&uevent->ctx_list, &ctx->events);0433 wake_up_interruptible(&ctx->file->poll_wait);0434 up(&ctx->file->mutex);435+ return 0;436+437+err2:438+ kfree(uevent);439+err1:440+ /* Destroy new cm_id's */441+ return (id == IB_UCM_CM_ID_INVALID);442}443444static ssize_t ib_ucm_event(struct ib_ucm_file *file,···517 goto done;518 }519520+ ctx->cm_id = uevent->cm_id;521+ ctx->cm_id->context = ctx;0522523 uevent->resp.id = ctx->id;524···585 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))586 return -EFAULT;587588+ down(&file->mutex);589 ctx = ib_ucm_ctx_alloc(file);590+ up(&file->mutex);591 if (!ctx)592 return -ENOMEM;593594+ ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx);595+ if (IS_ERR(ctx->cm_id)) {596+ result = PTR_ERR(ctx->cm_id);597+ goto err;0598 }599600 resp.id = ctx->id;601 if (copy_to_user((void __user *)(unsigned long)cmd.response,602 &resp, sizeof(resp))) {603 result = -EFAULT;604+ goto err;605 }606607 return 0;0000608609+err:610+ ib_ucm_destroy_ctx(file, ctx->id);611 return result;612}613···617 int in_len, int out_len)618{619 struct ib_ucm_destroy_id cmd;0620621 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))622 return -EFAULT;623624+ return ib_ucm_destroy_ctx(file, cmd.id);0000000625}626627static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,···647 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))648 return -EFAULT;649650+ ctx = ib_ucm_ctx_get(file, cmd.id);651+ if (IS_ERR(ctx))652+ return PTR_ERR(ctx);000000653654 resp.service_id = ctx->cm_id->service_id;655 resp.service_mask = ctx->cm_id->service_mask;···666 &resp, sizeof(resp)))667 result = -EFAULT;668669+ ib_ucm_ctx_put(ctx);00670 return result;671}672···683 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))684 return -EFAULT;685686+ ctx = ib_ucm_ctx_get(file, cmd.id);687+ if (IS_ERR(ctx))688+ return PTR_ERR(ctx);689690+ result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask);691+ ib_ucm_ctx_put(ctx);0000000692 return result;693}694···710 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))711 return -EFAULT;712713+ ctx = ib_ucm_ctx_get(file, cmd.id);714+ if (IS_ERR(ctx))715+ return PTR_ERR(ctx);716717+ result = ib_cm_establish(ctx->cm_id);718+ ib_ucm_ctx_put(ctx);000000719 return result;720}721···768 return -EFAULT;769 }770771+ memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof sa_path->dgid);772+ memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof sa_path->sgid);773774 sa_path->dlid = ucm_path.dlid;775 sa_path->slid = ucm_path.slid;···839 param.max_cm_retries = cmd.max_cm_retries;840 param.srq = cmd.srq;841842+ ctx = ib_ucm_ctx_get(file, cmd.id);843+ if (!IS_ERR(ctx)) {00000000844 result = ib_send_cm_req(ctx->cm_id, ¶m);845+ ib_ucm_ctx_put(ctx);846+ } else847+ result = PTR_ERR(ctx);84800849done:850 kfree(param.private_data);851 kfree(param.primary_path);852 kfree(param.alternate_path);0853 return result;854}855···890 param.rnr_retry_count = cmd.rnr_retry_count;891 param.srq = cmd.srq;892893+ ctx = ib_ucm_ctx_get(file, cmd.id);894+ if (!IS_ERR(ctx)) {00000000895 result = ib_send_cm_rep(ctx->cm_id, ¶m);896+ ib_ucm_ctx_put(ctx);897+ } else898+ result = PTR_ERR(ctx);899000900 kfree(param.private_data);0901 return result;902}903···928 if (result)929 return result;930931+ ctx = ib_ucm_ctx_get(file, cmd.id);932+ if (!IS_ERR(ctx)) {00000000933 result = func(ctx->cm_id, private_data, cmd.len);934+ ib_ucm_ctx_put(ctx);935+ } else936+ result = PTR_ERR(ctx);937000938 kfree(private_data);0939 return result;940}941···995 if (result)996 goto done;997998+ ctx = ib_ucm_ctx_get(file, cmd.id);999+ if (!IS_ERR(ctx)) {1000+ result = func(ctx->cm_id, cmd.status, info, cmd.info_len,0000000001001 data, cmd.data_len);1002+ ib_ucm_ctx_put(ctx);1003+ } else1004+ result = PTR_ERR(ctx);1005001006done:1007 kfree(data);1008 kfree(info);01009 return result;1010}1011···1048 if (result)1049 return result;10501051+ ctx = ib_ucm_ctx_get(file, cmd.id);1052+ if (!IS_ERR(ctx)) {1053+ result = ib_send_cm_mra(ctx->cm_id, cmd.timeout, data, cmd.len);1054+ ib_ucm_ctx_put(ctx);1055+ } else1056+ result = PTR_ERR(ctx);105700000000001058 kfree(data);01059 return result;1060}1061···1090 if (result)1091 goto done;10921093+ ctx = ib_ucm_ctx_get(file, cmd.id);1094+ if (!IS_ERR(ctx)) {000000001095 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len);1096+ ib_ucm_ctx_put(ctx);1097+ } else1098+ result = PTR_ERR(ctx);1099001100done:1101 kfree(data);1102 kfree(path);01103 return result;1104}1105···1140 param.max_cm_retries = cmd.max_cm_retries;1141 param.pkey = cmd.pkey;11421143+ ctx = ib_ucm_ctx_get(file, cmd.id);1144+ if (!IS_ERR(ctx)) {000000001145 result = ib_send_cm_sidr_req(ctx->cm_id, ¶m);1146+ ib_ucm_ctx_put(ctx);1147+ } else1148+ result = PTR_ERR(ctx);1149001150done:1151 kfree(param.private_data);1152 kfree(param.path);01153 return result;1154}1155···1184 if (result)1185 goto done;11861187+ param.qp_num = cmd.qpn;1188+ param.qkey = cmd.qkey;1189+ param.status = cmd.status;1190+ param.info_length = cmd.info_len;1191+ param.private_data_len = cmd.data_len;11921193+ ctx = ib_ucm_ctx_get(file, cmd.id);1194+ if (!IS_ERR(ctx)) {000000001195 result = ib_send_cm_sidr_rep(ctx->cm_id, ¶m);1196+ ib_ucm_ctx_put(ctx);1197+ } else1198+ result = PTR_ERR(ctx);1199001200done:1201 kfree(param.private_data);1202 kfree(param.info);01203 return result;1204}1205···1305 struct ib_ucm_context *ctx;13061307 down(&file->mutex);01308 while (!list_empty(&file->ctxs)) {13091310 ctx = list_entry(file->ctxs.next,1311 struct ib_ucm_context, file_list);13121313+ up(&file->mutex);1314+ ib_ucm_destroy_ctx(file, ctx->id);1315 down(&file->mutex);1316 }01317 up(&file->mutex);01318 kfree(file);001319 return 0;1320}1321
+5-8
drivers/infiniband/core/ucm.h
···40#include <linux/cdev.h>41#include <linux/idr.h>4243-#include <ib_cm.h>44-#include <ib_user_cm.h>4546#define IB_UCM_CM_ID_INVALID 0xffffffff4748struct ib_ucm_file {49 struct semaphore mutex;50 struct file *filp;51- /*52- * list of pending events53- */54 struct list_head ctxs; /* list of active connections */55 struct list_head events; /* list of pending events */56 wait_queue_head_t poll_wait;···5657struct ib_ucm_context {58 int id;59- int ref;60- int error;6162 struct ib_ucm_file *file;63 struct ib_cm_id *cm_id;64- struct semaphore mutex;6566 struct list_head events; /* list of pending events. */67 struct list_head file_list; /* member in file ctx list */
···40#include <linux/cdev.h>41#include <linux/idr.h>4243+#include <rdma/ib_cm.h>44+#include <rdma/ib_user_cm.h>4546#define IB_UCM_CM_ID_INVALID 0xffffffff4748struct ib_ucm_file {49 struct semaphore mutex;50 struct file *filp;51+0052 struct list_head ctxs; /* list of active connections */53 struct list_head events; /* list of pending events */54 wait_queue_head_t poll_wait;···5859struct ib_ucm_context {60 int id;61+ wait_queue_head_t wait;62+ atomic_t ref;6364 struct ib_ucm_file *file;65 struct ib_cm_id *cm_id;06667 struct list_head events; /* list of pending events. */68 struct list_head file_list; /* member in file ctx list */
+6-5
drivers/infiniband/core/ud_header.c
···1/*2 * Copyright (c) 2004 Topspin Corporation. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···3536#include <linux/errno.h>3738-#include <ib_pack.h>3940#define STRUCT_FIELD(header, field) \41 .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \···195 struct ib_ud_header *header)196{197 int header_len;0198199 memset(header, 0, sizeof *header);200···210 header->lrh.link_version = 0;211 header->lrh.link_next_header =212 grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL;213- header->lrh.packet_length = (IB_LRH_BYTES +214 IB_BTH_BYTES +215 IB_DETH_BYTES +216 payload_bytes +···219220 header->grh_present = grh_present;221 if (grh_present) {222- header->lrh.packet_length += IB_GRH_BYTES / 4;223-224 header->grh.ip_version = 6;225 header->grh.payload_length =226 cpu_to_be16((IB_BTH_BYTES +···230 header->grh.next_header = 0x1b;231 }232233- cpu_to_be16s(&header->lrh.packet_length);234235 if (header->immediate_present)236 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
···1/*2 * Copyright (c) 2004 Topspin Corporation. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···3435#include <linux/errno.h>3637+#include <rdma/ib_pack.h>3839#define STRUCT_FIELD(header, field) \40 .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \···194 struct ib_ud_header *header)195{196 int header_len;197+ u16 packet_length;198199 memset(header, 0, sizeof *header);200···208 header->lrh.link_version = 0;209 header->lrh.link_next_header =210 grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL;211+ packet_length = (IB_LRH_BYTES +212 IB_BTH_BYTES +213 IB_DETH_BYTES +214 payload_bytes +···217218 header->grh_present = grh_present;219 if (grh_present) {220+ packet_length += IB_GRH_BYTES / 4;0221 header->grh.ip_version = 6;222 header->grh.payload_length =223 cpu_to_be16((IB_BTH_BYTES +···229 header->grh.next_header = 0x1b;230 }231232+ header->lrh.packet_length = cpu_to_be16(packet_length);233234 if (header->immediate_present)235 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
+5-5
drivers/infiniband/core/user_mad.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3- * Copyright (c) 2005 Voltaire, Inc. All rights reserved.4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two···49#include <asm/uaccess.h>50#include <asm/semaphore.h>5152-#include <ib_mad.h>53-#include <ib_user_mad.h>5455MODULE_AUTHOR("Roland Dreier");56MODULE_DESCRIPTION("InfiniBand userspace MAD packet access");···271 struct ib_send_wr *bad_wr;272 struct ib_rmpp_mad *rmpp_mad;273 u8 method;274- u64 *tid;275 int ret, length, hdr_len, data_len, rmpp_hdr_size;276 int rmpp_active = 0;277···316 if (packet->mad.hdr.grh_present) {317 ah_attr.ah_flags = IB_AH_GRH;318 memcpy(ah_attr.grh.dgid.raw, packet->mad.hdr.gid, 16);319- ah_attr.grh.flow_label = packet->mad.hdr.flow_label;320 ah_attr.grh.hop_limit = packet->mad.hdr.hop_limit;321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class;322 }
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two···49#include <asm/uaccess.h>50#include <asm/semaphore.h>5152+#include <rdma/ib_mad.h>53+#include <rdma/ib_user_mad.h>5455MODULE_AUTHOR("Roland Dreier");56MODULE_DESCRIPTION("InfiniBand userspace MAD packet access");···271 struct ib_send_wr *bad_wr;272 struct ib_rmpp_mad *rmpp_mad;273 u8 method;274+ __be64 *tid;275 int ret, length, hdr_len, data_len, rmpp_hdr_size;276 int rmpp_active = 0;277···316 if (packet->mad.hdr.grh_present) {317 ah_attr.ah_flags = IB_AH_GRH;318 memcpy(ah_attr.grh.dgid.raw, packet->mad.hdr.gid, 16);319+ ah_attr.grh.flow_label = be32_to_cpu(packet->mad.hdr.flow_label);320 ah_attr.grh.hop_limit = packet->mad.hdr.hop_limit;321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class;322 }
+9-2
drivers/infiniband/core/uverbs.h
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.004 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···45#include <linux/kref.h>46#include <linux/idr.h>4748-#include <ib_verbs.h>49-#include <ib_user_verbs.h>5051struct ib_uverbs_device {52 int devnum;···99extern struct idr ib_uverbs_ah_idr;100extern struct idr ib_uverbs_cq_idr;101extern struct idr ib_uverbs_qp_idr;0102103void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);104void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);105void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);0106107int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,108 void *addr, size_t size, int write);···133IB_UVERBS_DECLARE_CMD(destroy_qp);134IB_UVERBS_DECLARE_CMD(attach_mcast);135IB_UVERBS_DECLARE_CMD(detach_mcast);000136137#endif /* UVERBS_H */
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.6 *7 * This software is available to you under a choice of one of two8 * licenses. You may choose to be licensed under the terms of the GNU···43#include <linux/kref.h>44#include <linux/idr.h>4546+#include <rdma/ib_verbs.h>47+#include <rdma/ib_user_verbs.h>4849struct ib_uverbs_device {50 int devnum;···97extern struct idr ib_uverbs_ah_idr;98extern struct idr ib_uverbs_cq_idr;99extern struct idr ib_uverbs_qp_idr;100+extern struct idr ib_uverbs_srq_idr;101102void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);103void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);104void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);105+void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);106107int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,108 void *addr, size_t size, int write);···129IB_UVERBS_DECLARE_CMD(destroy_qp);130IB_UVERBS_DECLARE_CMD(attach_mcast);131IB_UVERBS_DECLARE_CMD(detach_mcast);132+IB_UVERBS_DECLARE_CMD(create_srq);133+IB_UVERBS_DECLARE_CMD(modify_srq);134+IB_UVERBS_DECLARE_CMD(destroy_srq);135136#endif /* UVERBS_H */
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.004 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···69DEFINE_IDR(ib_uverbs_ah_idr);70DEFINE_IDR(ib_uverbs_cq_idr);71DEFINE_IDR(ib_uverbs_qp_idr);07273static spinlock_t map_lock;74static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);···94 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,95 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast,96 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,00097};9899static struct vfsmount *uverbs_event_mnt;···131 kfree(uobj);132 }133134- /* XXX Free SRQs */0000000135 /* XXX Free MWs */136137 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {···354{355 ib_uverbs_async_handler(context_ptr,356 event->element.qp->uobject->user_handle,0000000357 event->event);358}359
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.6 *7 * This software is available to you under a choice of one of two8 * licenses. You may choose to be licensed under the terms of the GNU···67DEFINE_IDR(ib_uverbs_ah_idr);68DEFINE_IDR(ib_uverbs_cq_idr);69DEFINE_IDR(ib_uverbs_qp_idr);70+DEFINE_IDR(ib_uverbs_srq_idr);7172static spinlock_t map_lock;73static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);···91 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,92 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast,93 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,94+ [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq,95+ [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq,96+ [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,97};9899static struct vfsmount *uverbs_event_mnt;···125 kfree(uobj);126 }127128+ list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) {129+ struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id);130+ idr_remove(&ib_uverbs_srq_idr, uobj->id);131+ ib_destroy_srq(srq);132+ list_del(&uobj->list);133+ kfree(uobj);134+ }135+136 /* XXX Free MWs */137138 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {···341{342 ib_uverbs_async_handler(context_ptr,343 event->element.qp->uobject->user_handle,344+ event->event);345+}346+347+void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr)348+{349+ ib_uverbs_async_handler(context_ptr,350+ event->element.srq->uobject->user_handle,351 event->event);352}353
+1
drivers/infiniband/core/uverbs_mem.c
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2 * Copyright (c) 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU
+63-2
drivers/infiniband/core/verbs.c
···4 * Copyright (c) 2004 Intel Corporation. All rights reserved.5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.07 * Copyright (c) 2005 Cisco Systems. All rights reserved.8 *9 * This software is available to you under a choice of one of two···41#include <linux/errno.h>42#include <linux/err.h>4344-#include <ib_verbs.h>45-#include <ib_cache.h>4647/* Protection domains */48···153 return ret;154}155EXPORT_SYMBOL(ib_destroy_ah);000000000000000000000000000000000000000000000000000000000000156157/* Queue pairs */158
···4 * Copyright (c) 2004 Intel Corporation. All rights reserved.5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.7+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.8 * Copyright (c) 2005 Cisco Systems. All rights reserved.9 *10 * This software is available to you under a choice of one of two···40#include <linux/errno.h>41#include <linux/err.h>4243+#include <rdma/ib_verbs.h>44+#include <rdma/ib_cache.h>4546/* Protection domains */47···152 return ret;153}154EXPORT_SYMBOL(ib_destroy_ah);155+156+/* Shared receive queues */157+158+struct ib_srq *ib_create_srq(struct ib_pd *pd,159+ struct ib_srq_init_attr *srq_init_attr)160+{161+ struct ib_srq *srq;162+163+ if (!pd->device->create_srq)164+ return ERR_PTR(-ENOSYS);165+166+ srq = pd->device->create_srq(pd, srq_init_attr, NULL);167+168+ if (!IS_ERR(srq)) {169+ srq->device = pd->device;170+ srq->pd = pd;171+ srq->uobject = NULL;172+ srq->event_handler = srq_init_attr->event_handler;173+ srq->srq_context = srq_init_attr->srq_context;174+ atomic_inc(&pd->usecnt);175+ atomic_set(&srq->usecnt, 0);176+ }177+178+ return srq;179+}180+EXPORT_SYMBOL(ib_create_srq);181+182+int ib_modify_srq(struct ib_srq *srq,183+ struct ib_srq_attr *srq_attr,184+ enum ib_srq_attr_mask srq_attr_mask)185+{186+ return srq->device->modify_srq(srq, srq_attr, srq_attr_mask);187+}188+EXPORT_SYMBOL(ib_modify_srq);189+190+int ib_query_srq(struct ib_srq *srq,191+ struct ib_srq_attr *srq_attr)192+{193+ return srq->device->query_srq ?194+ srq->device->query_srq(srq, srq_attr) : -ENOSYS;195+}196+EXPORT_SYMBOL(ib_query_srq);197+198+int ib_destroy_srq(struct ib_srq *srq)199+{200+ struct ib_pd *pd;201+ int ret;202+203+ if (atomic_read(&srq->usecnt))204+ return -EBUSY;205+206+ pd = srq->pd;207+208+ ret = srq->device->destroy_srq(srq);209+ if (!ret)210+ atomic_dec(&pd->usecnt);211+212+ return ret;213+}214+EXPORT_SYMBOL(ib_destroy_srq);215216/* Queue pairs */217
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···36#include <linux/pci.h>37#include <linux/errno.h>38#include <asm/io.h>39+#include <rdma/ib_mad.h>4041#include "mthca_dev.h"42#include "mthca_config_reg.h"···108 CMD_SW2HW_SRQ = 0x35,109 CMD_HW2SW_SRQ = 0x36,110 CMD_QUERY_SRQ = 0x37,111+ CMD_ARM_SRQ = 0x40,112113 /* QP/EE commands */114 CMD_RST2INIT_QPEE = 0x19,···219 * (and some architectures such as ia64 implement memcpy_toio220 * in terms of writeb).221 */222+ __raw_writel((__force u32) cpu_to_be32(in_param >> 32), dev->hcr + 0 * 4);223+ __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), dev->hcr + 1 * 4);224+ __raw_writel((__force u32) cpu_to_be32(in_modifier), dev->hcr + 2 * 4);225+ __raw_writel((__force u32) cpu_to_be32(out_param >> 32), dev->hcr + 3 * 4);226+ __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), dev->hcr + 4 * 4);227+ __raw_writel((__force u32) cpu_to_be32(token << 16), dev->hcr + 5 * 4);228229 /* __raw_writel may not order writes. */230 wmb();231232+ __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |233+ (event ? (1 << HCA_E_BIT) : 0) |234+ (op_modifier << HCR_OPMOD_SHIFT) |235+ op), dev->hcr + 6 * 4);236237out:238 up(&dev->cmd.hcr_sem);···273 goto out;274 }275276+ if (out_is_imm)277+ *out_param = 278+ (u64) be32_to_cpu((__force __be32)279+ __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET)) << 32 |280+ (u64) be32_to_cpu((__force __be32)281+ __raw_readl(dev->hcr + HCR_OUT_PARAM_OFFSET + 4));282283+ *status = be32_to_cpu((__force __be32) __raw_readl(dev->hcr + HCR_STATUS_OFFSET)) >> 24;284285out:286 up(&dev->cmd.poll_sem);···10291030 mthca_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",1031 dev_lim->max_qps, dev_lim->reserved_qps, dev_lim->qpc_entry_sz);1032+ mthca_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",1033+ dev_lim->max_srqs, dev_lim->reserved_srqs, dev_lim->srq_entry_sz);1034 mthca_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",1035 dev_lim->max_cqs, dev_lim->reserved_cqs, dev_lim->cqc_entry_sz);1036 mthca_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n",···1082 return err;1083}10841085+static void get_board_id(void *vsd, char *board_id)1086+{1087+ int i;1088+1089+#define VSD_OFFSET_SIG1 0x001090+#define VSD_OFFSET_SIG2 0xde1091+#define VSD_OFFSET_MLX_BOARD_ID 0xd01092+#define VSD_OFFSET_TS_BOARD_ID 0x201093+1094+#define VSD_SIGNATURE_TOPSPIN 0x5ad1095+1096+ memset(board_id, 0, MTHCA_BOARD_ID_LEN);1097+1098+ if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN &&1099+ be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) {1100+ strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MTHCA_BOARD_ID_LEN);1101+ } else {1102+ /*1103+ * The board ID is a string but the firmware byte1104+ * swaps each 4-byte word before passing it back to1105+ * us. Therefore we need to swab it before printing.1106+ */1107+ for (i = 0; i < 4; ++i)1108+ ((u32 *) board_id)[i] =1109+ swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4));1110+ }1111+}1112+1113int mthca_QUERY_ADAPTER(struct mthca_dev *dev,1114 struct mthca_adapter *adapter, u8 *status)1115{···1094#define QUERY_ADAPTER_DEVICE_ID_OFFSET 0x041095#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x081096#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x101097+#define QUERY_ADAPTER_VSD_OFFSET 0x2010981099 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);1100 if (IS_ERR(mailbox))···1111 MTHCA_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);1112 MTHCA_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);11131114+ get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,1115+ adapter->board_id);1116+1117out:1118 mthca_free_mailbox(dev, mailbox);1119 return err;···1121 u8 *status)1122{1123 struct mthca_mailbox *mailbox;1124+ __be32 *inbox;1125 int err;11261127#define INIT_HCA_IN_SIZE 0x200···1247#define INIT_IB_FLAG_SIG (1 << 18)1248#define INIT_IB_FLAG_NG (1 << 17)1249#define INIT_IB_FLAG_G0 (1 << 16)0001250#define INIT_IB_VL_SHIFT 41251+#define INIT_IB_PORT_WIDTH_SHIFT 81252#define INIT_IB_MTU_SHIFT 121253#define INIT_IB_MAX_GID_OFFSET 0x061254#define INIT_IB_MAX_PKEY_OFFSET 0x0a···1266 memset(inbox, 0, INIT_IB_IN_SIZE);12671268 flags = 0;001269 flags |= param->set_guid0 ? INIT_IB_FLAG_G0 : 0;1270 flags |= param->set_node_guid ? INIT_IB_FLAG_NG : 0;1271 flags |= param->set_si_guid ? INIT_IB_FLAG_SIG : 0;1272 flags |= param->vl_cap << INIT_IB_VL_SHIFT;1273+ flags |= param->port_width << INIT_IB_PORT_WIDTH_SHIFT;1274 flags |= param->mtu_cap << INIT_IB_MTU_SHIFT;1275 MTHCA_PUT(inbox, flags, INIT_IB_FLAGS_OFFSET);1276···1342int mthca_MAP_ICM_page(struct mthca_dev *dev, u64 dma_addr, u64 virt, u8 *status)1343{1344 struct mthca_mailbox *mailbox;1345+ __be64 *inbox;1346 int err;13471348 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);···1468 CMD_TIME_CLASS_A, status);1469}14701471+int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,1472+ int srq_num, u8 *status)1473+{1474+ return mthca_cmd(dev, mailbox->dma, srq_num, 0, CMD_SW2HW_SRQ,1475+ CMD_TIME_CLASS_A, status);1476+}1477+1478+int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,1479+ int srq_num, u8 *status)1480+{1481+ return mthca_cmd_box(dev, 0, mailbox->dma, srq_num, 0,1482+ CMD_HW2SW_SRQ,1483+ CMD_TIME_CLASS_A, status);1484+}1485+1486+int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status)1487+{1488+ return mthca_cmd(dev, limit, srq_num, 0, CMD_ARM_SRQ,1489+ CMD_TIME_CLASS_B, status);1490+}1491+1492int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,1493 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,1494 u8 *status)···1513 if (i % 8 == 0)1514 printk(" [%02x] ", i * 4);1515 printk(" %08x",1516+ be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));1517 if ((i + 1) % 8 == 0)1518 printk("\n");1519 }···1533 if (i % 8 == 0)1534 printk("[%02x] ", i * 4);1535 printk(" %08x",1536+ be32_to_cpu(((__be32 *) mailbox->buf)[i + 2]));1537 if ((i + 1) % 8 == 0)1538 printk("\n");1539 }
+13-7
drivers/infiniband/hw/mthca/mthca_cmd.h
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···36#ifndef MTHCA_CMD_H37#define MTHCA_CMD_H3839-#include <ib_verbs.h>4041#define MTHCA_MAILBOX_SIZE 409642···184};185186struct mthca_adapter {187- u32 vendor_id;188- u32 device_id;189- u32 revision_id;190- u8 inta_pin;0191};192193struct mthca_init_hca_param {···220};221222struct mthca_init_ib_param {223- int enable_1x;224- int enable_4x;225 int vl_cap;226 int mtu_cap;227 u16 gid_cap;···298 int cq_num, u8 *status);299int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,300 int cq_num, u8 *status);00000301int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,302 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,303 u8 *status);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···35#ifndef MTHCA_CMD_H36#define MTHCA_CMD_H3738+#include <rdma/ib_verbs.h>3940#define MTHCA_MAILBOX_SIZE 409641···183};184185struct mthca_adapter {186+ u32 vendor_id;187+ u32 device_id;188+ u32 revision_id;189+ char board_id[MTHCA_BOARD_ID_LEN];190+ u8 inta_pin;191};192193struct mthca_init_hca_param {···218};219220struct mthca_init_ib_param {221+ int port_width;0222 int vl_cap;223 int mtu_cap;224 u16 gid_cap;···297 int cq_num, u8 *status);298int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,299 int cq_num, u8 *status);300+int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,301+ int srq_num, u8 *status);302+int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,303+ int srq_num, u8 *status);304+int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status);305int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,306 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,307 u8 *status);
+1
drivers/infiniband/hw/mthca/mthca_config_reg.h
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU
+81-175
drivers/infiniband/hw/mthca/mthca_cq.c
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved.005 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···39#include <linux/init.h>40#include <linux/hardirq.h>4142-#include <ib_pack.h>4344#include "mthca_dev.h"45#include "mthca_cmd.h"···57 * Must be packed because start is 64 bits but only aligned to 32 bits.58 */59struct mthca_cq_context {60- u32 flags;61- u64 start;62- u32 logsize_usrpage;63- u32 error_eqn; /* Tavor only */64- u32 comp_eqn;65- u32 pd;66- u32 lkey;67- u32 last_notified_index;68- u32 solicit_producer_index;69- u32 consumer_index;70- u32 producer_index;71- u32 cqn;72- u32 ci_db; /* Arbel only */73- u32 state_db; /* Arbel only */74- u32 reserved;75} __attribute__((packed));7677#define MTHCA_CQ_STATUS_OK ( 0 << 28)···110};111112struct mthca_cqe {113- u32 my_qpn;114- u32 my_ee;115- u32 rqpn;116- u16 sl_g_mlpath;117- u16 rlid;118- u32 imm_etype_pkey_eec;119- u32 byte_cnt;120- u32 wqe;121- u8 opcode;122- u8 is_send;123- u8 reserved;124- u8 owner;125};126127struct mthca_err_cqe {128- u32 my_qpn;129- u32 reserved1[3];130- u8 syndrome;131- u8 reserved2;132- u16 db_cnt;133- u32 reserved3;134- u32 wqe;135- u8 opcode;136- u8 reserved4[2];137- u8 owner;138};139140#define MTHCA_CQ_ENTRY_OWNER_SW (0 << 7)···193static inline void update_cons_index(struct mthca_dev *dev, struct mthca_cq *cq,194 int incr)195{196- u32 doorbell[2];197198 if (mthca_is_memfree(dev)) {199 *cq->set_ci_db = cpu_to_be32(cq->cons_index);···224 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);225}226227-void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn)0228{229 struct mthca_cq *cq;230 struct mthca_cqe *cqe;···266 */267 while (prod_index > cq->cons_index) {268 cqe = get_cqe(cq, (prod_index - 1) & cq->ibcq.cqe);269- if (cqe->my_qpn == cpu_to_be32(qpn))00270 ++nfreed;0271 else if (nfreed)272 memcpy(get_cqe(cq, (prod_index - 1 + nfreed) &273 cq->ibcq.cqe),···297{298 int err;299 int dbd;300- u32 new_wqe;301302 if (cqe->syndrome == SYNDROME_LOCAL_QP_OP_ERR) {303 mthca_dbg(dev, "local QP operation err "···371 break;372 }3730000000374 err = mthca_free_err_wqe(dev, qp, is_send, wqe_index, &dbd, &new_wqe);375 if (err)376 return err;···386 * If we're at the end of the WQE chain, or we've used up our387 * doorbell count, free the CQE. Otherwise just update it for388 * the next poll operation.389- *390- * This does not apply to mem-free HCAs: they don't use the391- * doorbell count field, and so we should always free the CQE.392 */393- if (mthca_is_memfree(dev) ||394- !(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))395 return 0;396397 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd);···459 >> wq->wqe_shift);460 entry->wr_id = (*cur_qp)->wrid[wqe_index +461 (*cur_qp)->rq.max];0000000462 } else {463 wq = &(*cur_qp)->rq;464 wqe_index = be32_to_cpu(cqe->wqe) >> wq->wqe_shift;465 entry->wr_id = (*cur_qp)->wrid[wqe_index];466 }467468- if (wq->last_comp < wqe_index)469- wq->tail += wqe_index - wq->last_comp;470- else471- wq->tail += wqe_index + wq->max - wq->last_comp;0472473- wq->last_comp = wqe_index;474-475- if (0)476- mthca_dbg(dev, "%s completion for QP %06x, index %d (nr %d)\n",477- is_send ? "Send" : "Receive",478- (*cur_qp)->qpn, wqe_index, wq->max);479480 if (is_error) {481 err = handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send,···597598int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify)599{600- u32 doorbell[2];601602 doorbell[0] = cpu_to_be32((notify == IB_CQ_SOLICITED ?603 MTHCA_TAVOR_CQ_DB_REQ_NOT_SOL :604 MTHCA_TAVOR_CQ_DB_REQ_NOT) |605 to_mcq(cq)->cqn);606- doorbell[1] = 0xffffffff;607608 mthca_write64(doorbell,609 to_mdev(cq->device)->kar + MTHCA_CQ_DOORBELL,···615int mthca_arbel_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)616{617 struct mthca_cq *cq = to_mcq(ibcq);618- u32 doorbell[2];619 u32 sn;620- u32 ci;621622 sn = cq->arm_sn & 3;623 ci = cpu_to_be32(cq->cons_index);···650651static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)652{653- int i;654- int size;655-656- if (cq->is_direct)657- dma_free_coherent(&dev->pdev->dev,658- (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,659- cq->queue.direct.buf,660- pci_unmap_addr(&cq->queue.direct,661- mapping));662- else {663- size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE;664- for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i)665- if (cq->queue.page_list[i].buf)666- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,667- cq->queue.page_list[i].buf,668- pci_unmap_addr(&cq->queue.page_list[i],669- mapping));670-671- kfree(cq->queue.page_list);672- }673-}674-675-static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,676- struct mthca_cq *cq)677-{678- int err = -ENOMEM;679- int npages, shift;680- u64 *dma_list = NULL;681- dma_addr_t t;682- int i;683-684- if (size <= MTHCA_MAX_DIRECT_CQ_SIZE) {685- cq->is_direct = 1;686- npages = 1;687- shift = get_order(size) + PAGE_SHIFT;688-689- cq->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev,690- size, &t, GFP_KERNEL);691- if (!cq->queue.direct.buf)692- return -ENOMEM;693-694- pci_unmap_addr_set(&cq->queue.direct, mapping, t);695-696- memset(cq->queue.direct.buf, 0, size);697-698- while (t & ((1 << shift) - 1)) {699- --shift;700- npages *= 2;701- }702-703- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);704- if (!dma_list)705- goto err_free;706-707- for (i = 0; i < npages; ++i)708- dma_list[i] = t + i * (1 << shift);709- } else {710- cq->is_direct = 0;711- npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;712- shift = PAGE_SHIFT;713-714- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);715- if (!dma_list)716- return -ENOMEM;717-718- cq->queue.page_list = kmalloc(npages * sizeof *cq->queue.page_list,719- GFP_KERNEL);720- if (!cq->queue.page_list)721- goto err_out;722-723- for (i = 0; i < npages; ++i)724- cq->queue.page_list[i].buf = NULL;725-726- for (i = 0; i < npages; ++i) {727- cq->queue.page_list[i].buf =728- dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,729- &t, GFP_KERNEL);730- if (!cq->queue.page_list[i].buf)731- goto err_free;732-733- dma_list[i] = t;734- pci_unmap_addr_set(&cq->queue.page_list[i], mapping, t);735-736- memset(cq->queue.page_list[i].buf, 0, PAGE_SIZE);737- }738- }739-740- err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,741- dma_list, shift, npages,742- 0, size,743- MTHCA_MPT_FLAG_LOCAL_WRITE |744- MTHCA_MPT_FLAG_LOCAL_READ,745- &cq->mr);746- if (err)747- goto err_free;748-749- kfree(dma_list);750-751- return 0;752-753-err_free:754- mthca_free_cq_buf(dev, cq);755-756-err_out:757- kfree(dma_list);758-759- return err;760}761762int mthca_init_cq(struct mthca_dev *dev, int nent,···703 cq_context = mailbox->buf;704705 if (cq->is_kernel) {706- err = mthca_alloc_cq_buf(dev, size, cq);00707 if (err)708 goto err_out_mailbox;709···721 cq_context->flags = cpu_to_be32(MTHCA_CQ_STATUS_OK |722 MTHCA_CQ_STATE_DISARMED |723 MTHCA_CQ_FLAG_TR);724- cq_context->start = cpu_to_be64(0);725 cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24);726 if (ctx)727 cq_context->logsize_usrpage |= cpu_to_be32(ctx->uar.index);···766 return 0;767768err_out_free_mr:769- if (cq->is_kernel) {770- mthca_free_mr(dev, &cq->mr);771 mthca_free_cq_buf(dev, cq);772- }773774err_out_mailbox:775 mthca_free_mailbox(dev, mailbox);···811 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);812813 if (0) {814- u32 *ctx = mailbox->buf;815 int j;816817 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",···835 wait_event(cq->wait, !atomic_read(&cq->refcount));836837 if (cq->is_kernel) {838- mthca_free_mr(dev, &cq->mr);839 mthca_free_cq_buf(dev, cq);840 if (mthca_is_memfree(dev)) {841 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved.5+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.6+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.7 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU···37#include <linux/init.h>38#include <linux/hardirq.h>3940+#include <rdma/ib_pack.h>4142#include "mthca_dev.h"43#include "mthca_cmd.h"···55 * Must be packed because start is 64 bits but only aligned to 32 bits.56 */57struct mthca_cq_context {58+ __be32 flags;59+ __be64 start;60+ __be32 logsize_usrpage;61+ __be32 error_eqn; /* Tavor only */62+ __be32 comp_eqn;63+ __be32 pd;64+ __be32 lkey;65+ __be32 last_notified_index;66+ __be32 solicit_producer_index;67+ __be32 consumer_index;68+ __be32 producer_index;69+ __be32 cqn;70+ __be32 ci_db; /* Arbel only */71+ __be32 state_db; /* Arbel only */72+ u32 reserved;73} __attribute__((packed));7475#define MTHCA_CQ_STATUS_OK ( 0 << 28)···108};109110struct mthca_cqe {111+ __be32 my_qpn;112+ __be32 my_ee;113+ __be32 rqpn;114+ __be16 sl_g_mlpath;115+ __be16 rlid;116+ __be32 imm_etype_pkey_eec;117+ __be32 byte_cnt;118+ __be32 wqe;119+ u8 opcode;120+ u8 is_send;121+ u8 reserved;122+ u8 owner;123};124125struct mthca_err_cqe {126+ __be32 my_qpn;127+ u32 reserved1[3];128+ u8 syndrome;129+ u8 reserved2;130+ __be16 db_cnt;131+ u32 reserved3;132+ __be32 wqe;133+ u8 opcode;134+ u8 reserved4[2];135+ u8 owner;136};137138#define MTHCA_CQ_ENTRY_OWNER_SW (0 << 7)···191static inline void update_cons_index(struct mthca_dev *dev, struct mthca_cq *cq,192 int incr)193{194+ __be32 doorbell[2];195196 if (mthca_is_memfree(dev)) {197 *cq->set_ci_db = cpu_to_be32(cq->cons_index);···222 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);223}224225+void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,226+ struct mthca_srq *srq)227{228 struct mthca_cq *cq;229 struct mthca_cqe *cqe;···263 */264 while (prod_index > cq->cons_index) {265 cqe = get_cqe(cq, (prod_index - 1) & cq->ibcq.cqe);266+ if (cqe->my_qpn == cpu_to_be32(qpn)) {267+ if (srq)268+ mthca_free_srq_wqe(srq, be32_to_cpu(cqe->wqe));269 ++nfreed;270+ }271 else if (nfreed)272 memcpy(get_cqe(cq, (prod_index - 1 + nfreed) &273 cq->ibcq.cqe),···291{292 int err;293 int dbd;294+ __be32 new_wqe;295296 if (cqe->syndrome == SYNDROME_LOCAL_QP_OP_ERR) {297 mthca_dbg(dev, "local QP operation err "···365 break;366 }367368+ /*369+ * Mem-free HCAs always generate one CQE per WQE, even in the370+ * error case, so we don't have to check the doorbell count, etc.371+ */372+ if (mthca_is_memfree(dev))373+ return 0;374+375 err = mthca_free_err_wqe(dev, qp, is_send, wqe_index, &dbd, &new_wqe);376 if (err)377 return err;···373 * If we're at the end of the WQE chain, or we've used up our374 * doorbell count, free the CQE. Otherwise just update it for375 * the next poll operation.000376 */377+ if (!(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))0378 return 0;379380 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd);···450 >> wq->wqe_shift);451 entry->wr_id = (*cur_qp)->wrid[wqe_index +452 (*cur_qp)->rq.max];453+ } else if ((*cur_qp)->ibqp.srq) {454+ struct mthca_srq *srq = to_msrq((*cur_qp)->ibqp.srq);455+ u32 wqe = be32_to_cpu(cqe->wqe);456+ wq = NULL;457+ wqe_index = wqe >> srq->wqe_shift;458+ entry->wr_id = srq->wrid[wqe_index];459+ mthca_free_srq_wqe(srq, wqe);460 } else {461 wq = &(*cur_qp)->rq;462 wqe_index = be32_to_cpu(cqe->wqe) >> wq->wqe_shift;463 entry->wr_id = (*cur_qp)->wrid[wqe_index];464 }465466+ if (wq) {467+ if (wq->last_comp < wqe_index)468+ wq->tail += wqe_index - wq->last_comp;469+ else470+ wq->tail += wqe_index + wq->max - wq->last_comp;471472+ wq->last_comp = wqe_index;473+ }0000474475 if (is_error) {476 err = handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send,···584585int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify)586{587+ __be32 doorbell[2];588589 doorbell[0] = cpu_to_be32((notify == IB_CQ_SOLICITED ?590 MTHCA_TAVOR_CQ_DB_REQ_NOT_SOL :591 MTHCA_TAVOR_CQ_DB_REQ_NOT) |592 to_mcq(cq)->cqn);593+ doorbell[1] = (__force __be32) 0xffffffff;594595 mthca_write64(doorbell,596 to_mdev(cq->device)->kar + MTHCA_CQ_DOORBELL,···602int mthca_arbel_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)603{604 struct mthca_cq *cq = to_mcq(ibcq);605+ __be32 doorbell[2];606 u32 sn;607+ __be32 ci;608609 sn = cq->arm_sn & 3;610 ci = cpu_to_be32(cq->cons_index);···637638static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)639{640+ mthca_buf_free(dev, (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,641+ &cq->queue, cq->is_direct, &cq->mr);000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000642}643644int mthca_init_cq(struct mthca_dev *dev, int nent,···795 cq_context = mailbox->buf;796797 if (cq->is_kernel) {798+ err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_CQ_SIZE,799+ &cq->queue, &cq->is_direct,800+ &dev->driver_pd, 1, &cq->mr);801 if (err)802 goto err_out_mailbox;803···811 cq_context->flags = cpu_to_be32(MTHCA_CQ_STATUS_OK |812 MTHCA_CQ_STATE_DISARMED |813 MTHCA_CQ_FLAG_TR);0814 cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24);815 if (ctx)816 cq_context->logsize_usrpage |= cpu_to_be32(ctx->uar.index);···857 return 0;858859err_out_free_mr:860+ if (cq->is_kernel)0861 mthca_free_cq_buf(dev, cq);0862863err_out_mailbox:864 mthca_free_mailbox(dev, mailbox);···904 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);905906 if (0) {907+ __be32 *ctx = mailbox->buf;908 int j;909910 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",···928 wait_event(cq->wait, !atomic_read(&cq->refcount));929930 if (cq->is_kernel) {0931 mthca_free_cq_buf(dev, cq);932 if (mthca_is_memfree(dev)) {933 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
+43-9
drivers/infiniband/hw/mthca/mthca_dev.h
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems. All rights reserved.005 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···6667enum {68 MTHCA_MAX_PORTS = 2000069};7071enum {···148 int reserved_mcgs;149 int num_pds;150 int reserved_pds;0151};152153struct mthca_alloc {···218 struct mthca_icm_table *table;219};2200000000221struct mthca_qp_table {222 struct mthca_alloc alloc;223 u32 rdb_base;···260 unsigned long device_cap_flags;261262 u32 rev_id;0263264 /* firmware info */265 u64 fw_ver;···306 struct mthca_mr_table mr_table;307 struct mthca_eq_table eq_table;308 struct mthca_cq_table cq_table;0309 struct mthca_qp_table qp_table;310 struct mthca_av_table av_table;311 struct mthca_mcg_table mcg_table;···347348#define MTHCA_PUT(dest, source, offset) \349 do { \350- __typeof__(source) *__p = \351- (__typeof__(source) *) ((char *) (dest) + (offset)); \352 switch (sizeof(source)) { \353- case 1: *__p = (source); break; \354- case 2: *__p = cpu_to_be16(source); break; \355- case 4: *__p = cpu_to_be32(source); break; \356- case 8: *__p = cpu_to_be64(source); break; \357- default: __buggy_use_of_MTHCA_PUT(); \358 } \359 } while (0)360···369void mthca_array_clear(struct mthca_array *array, int index);370int mthca_array_init(struct mthca_array *array, int nent);371void mthca_array_cleanup(struct mthca_array *array, int nent);00000372373int mthca_init_uar_table(struct mthca_dev *dev);374int mthca_init_pd_table(struct mthca_dev *dev);375int mthca_init_mr_table(struct mthca_dev *dev);376int mthca_init_eq_table(struct mthca_dev *dev);377int mthca_init_cq_table(struct mthca_dev *dev);0378int mthca_init_qp_table(struct mthca_dev *dev);379int mthca_init_av_table(struct mthca_dev *dev);380int mthca_init_mcg_table(struct mthca_dev *dev);···390void mthca_cleanup_mr_table(struct mthca_dev *dev);391void mthca_cleanup_eq_table(struct mthca_dev *dev);392void mthca_cleanup_cq_table(struct mthca_dev *dev);0393void mthca_cleanup_qp_table(struct mthca_dev *dev);394void mthca_cleanup_av_table(struct mthca_dev *dev);395void mthca_cleanup_mcg_table(struct mthca_dev *dev);···441void mthca_free_cq(struct mthca_dev *dev,442 struct mthca_cq *cq);443void mthca_cq_event(struct mthca_dev *dev, u32 cqn);444-void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn);000000000000445446void mthca_qp_event(struct mthca_dev *dev, u32 qpn,447 enum ib_event_type event_type);···467int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,468 struct ib_recv_wr **bad_wr);469int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,470- int index, int *dbd, u32 *new_wqe);471int mthca_alloc_qp(struct mthca_dev *dev,472 struct mthca_pd *pd,473 struct mthca_cq *send_cq,
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems. All rights reserved.5+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.6+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.7 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU···6465enum {66 MTHCA_MAX_PORTS = 267+};68+69+enum {70+ MTHCA_BOARD_ID_LEN = 6471};7273enum {···142 int reserved_mcgs;143 int num_pds;144 int reserved_pds;145+ u8 port_width_cap;146};147148struct mthca_alloc {···211 struct mthca_icm_table *table;212};213214+struct mthca_srq_table {215+ struct mthca_alloc alloc;216+ spinlock_t lock;217+ struct mthca_array srq;218+ struct mthca_icm_table *table;219+};220+221struct mthca_qp_table {222 struct mthca_alloc alloc;223 u32 rdb_base;···246 unsigned long device_cap_flags;247248 u32 rev_id;249+ char board_id[MTHCA_BOARD_ID_LEN];250251 /* firmware info */252 u64 fw_ver;···291 struct mthca_mr_table mr_table;292 struct mthca_eq_table eq_table;293 struct mthca_cq_table cq_table;294+ struct mthca_srq_table srq_table;295 struct mthca_qp_table qp_table;296 struct mthca_av_table av_table;297 struct mthca_mcg_table mcg_table;···331332#define MTHCA_PUT(dest, source, offset) \333 do { \334+ void *__d = ((char *) (dest) + (offset)); \0335 switch (sizeof(source)) { \336+ case 1: *(u8 *) __d = (source); break; \337+ case 2: *(__be16 *) __d = cpu_to_be16(source); break; \338+ case 4: *(__be32 *) __d = cpu_to_be32(source); break; \339+ case 8: *(__be64 *) __d = cpu_to_be64(source); break; \340+ default: __buggy_use_of_MTHCA_PUT(); \341 } \342 } while (0)343···354void mthca_array_clear(struct mthca_array *array, int index);355int mthca_array_init(struct mthca_array *array, int nent);356void mthca_array_cleanup(struct mthca_array *array, int nent);357+int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,358+ union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,359+ int hca_write, struct mthca_mr *mr);360+void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,361+ int is_direct, struct mthca_mr *mr);362363int mthca_init_uar_table(struct mthca_dev *dev);364int mthca_init_pd_table(struct mthca_dev *dev);365int mthca_init_mr_table(struct mthca_dev *dev);366int mthca_init_eq_table(struct mthca_dev *dev);367int mthca_init_cq_table(struct mthca_dev *dev);368+int mthca_init_srq_table(struct mthca_dev *dev);369int mthca_init_qp_table(struct mthca_dev *dev);370int mthca_init_av_table(struct mthca_dev *dev);371int mthca_init_mcg_table(struct mthca_dev *dev);···369void mthca_cleanup_mr_table(struct mthca_dev *dev);370void mthca_cleanup_eq_table(struct mthca_dev *dev);371void mthca_cleanup_cq_table(struct mthca_dev *dev);372+void mthca_cleanup_srq_table(struct mthca_dev *dev);373void mthca_cleanup_qp_table(struct mthca_dev *dev);374void mthca_cleanup_av_table(struct mthca_dev *dev);375void mthca_cleanup_mcg_table(struct mthca_dev *dev);···419void mthca_free_cq(struct mthca_dev *dev,420 struct mthca_cq *cq);421void mthca_cq_event(struct mthca_dev *dev, u32 cqn);422+void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,423+ struct mthca_srq *srq);424+425+int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,426+ struct ib_srq_attr *attr, struct mthca_srq *srq);427+void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);428+void mthca_srq_event(struct mthca_dev *dev, u32 srqn,429+ enum ib_event_type event_type);430+void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);431+int mthca_tavor_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,432+ struct ib_recv_wr **bad_wr);433+int mthca_arbel_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,434+ struct ib_recv_wr **bad_wr);435436void mthca_qp_event(struct mthca_dev *dev, u32 qpn,437 enum ib_event_type event_type);···433int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,434 struct ib_recv_wr **bad_wr);435int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,436+ int index, int *dbd, __be32 *new_wqe);437int mthca_alloc_qp(struct mthca_dev *dev,438 struct mthca_pd *pd,439 struct mthca_cq *send_cq,
+7-6
drivers/infiniband/hw/mthca/mthca_doorbell.h
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···58 __raw_writeq((__force u64) val, dest);59}6061-static inline void mthca_write64(u32 val[2], void __iomem *dest,62 spinlock_t *doorbell_lock)63{64 __raw_writeq(*(u64 *) val, dest);65}6667-static inline void mthca_write_db_rec(u32 val[2], u32 *db)68{69 *(u64 *) db = *(u64 *) val;70}···87 __raw_writel(((__force u32 *) &val)[1], dest + 4);88}8990-static inline void mthca_write64(u32 val[2], void __iomem *dest,91 spinlock_t *doorbell_lock)92{93 unsigned long flags;9495 spin_lock_irqsave(doorbell_lock, flags);96- __raw_writel(val[0], dest);97- __raw_writel(val[1], dest + 4);98 spin_unlock_irqrestore(doorbell_lock, flags);99}100101-static inline void mthca_write_db_rec(u32 val[2], u32 *db)102{103 db[0] = val[0];104 wmb();
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···57 __raw_writeq((__force u64) val, dest);58}5960+static inline void mthca_write64(__be32 val[2], void __iomem *dest,61 spinlock_t *doorbell_lock)62{63 __raw_writeq(*(u64 *) val, dest);64}6566+static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)67{68 *(u64 *) db = *(u64 *) val;69}···86 __raw_writel(((__force u32 *) &val)[1], dest + 4);87}8889+static inline void mthca_write64(__be32 val[2], void __iomem *dest,90 spinlock_t *doorbell_lock)91{92 unsigned long flags;9394 spin_lock_irqsave(doorbell_lock, flags);95+ __raw_writel((__force u32) val[0], dest);96+ __raw_writel((__force u32) val[1], dest + 4);97 spin_unlock_irqrestore(doorbell_lock, flags);98}99100+static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)101{102 db[0] = val[0];103 wmb();
+32-31
drivers/infiniband/hw/mthca/mthca_eq.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···52 * Must be packed because start is 64 bits but only aligned to 32 bits.53 */54struct mthca_eq_context {55- u32 flags;56- u64 start;57- u32 logsize_usrpage;58- u32 tavor_pd; /* reserved for Arbel */59- u8 reserved1[3];60- u8 intr;61- u32 arbel_pd; /* lost_count for Tavor */62- u32 lkey;63- u32 reserved2[2];64- u32 consumer_index;65- u32 producer_index;66- u32 reserved3[4];67} __attribute__((packed));6869#define MTHCA_EQ_STATUS_OK ( 0 << 28)···128 union {129 u32 raw[6];130 struct {131- u32 cqn;132 } __attribute__((packed)) comp;133 struct {134- u16 reserved1;135- u16 token;136- u32 reserved2;137- u8 reserved3[3];138- u8 status;139- u64 out_param;140 } __attribute__((packed)) cmd;141 struct {142- u32 qpn;143 } __attribute__((packed)) qp;144 struct {145- u32 cqn;146- u32 reserved1;147- u8 reserved2[3];148- u8 syndrome;149 } __attribute__((packed)) cq_err;150 struct {151- u32 reserved1[2];152- u32 port;153 } __attribute__((packed)) port_change;154 } event;155 u8 reserved3[3];···168169static inline void tavor_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)170{171- u32 doorbell[2];172173 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_SET_CI | eq->eqn);174 doorbell[1] = cpu_to_be32(ci & (eq->nent - 1));···191{192 /* See comment in tavor_set_eq_ci() above. */193 wmb();194- __raw_writel(cpu_to_be32(ci), dev->eq_regs.arbel.eq_set_ci_base +195- eq->eqn * 8);196 /* We still want ordering, just not swabbing, so add a barrier */197 mb();198}···207208static inline void tavor_eq_req_not(struct mthca_dev *dev, int eqn)209{210- u32 doorbell[2];211212 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_REQ_NOT | eqn);213 doorbell[1] = 0;···225static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)226{227 if (!mthca_is_memfree(dev)) {228- u32 doorbell[2];229230 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);231 doorbell[1] = cpu_to_be32(cqn);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···51 * Must be packed because start is 64 bits but only aligned to 32 bits.52 */53struct mthca_eq_context {54+ __be32 flags;55+ __be64 start;56+ __be32 logsize_usrpage;57+ __be32 tavor_pd; /* reserved for Arbel */58+ u8 reserved1[3];59+ u8 intr;60+ __be32 arbel_pd; /* lost_count for Tavor */61+ __be32 lkey;62+ u32 reserved2[2];63+ __be32 consumer_index;64+ __be32 producer_index;65+ u32 reserved3[4];66} __attribute__((packed));6768#define MTHCA_EQ_STATUS_OK ( 0 << 28)···127 union {128 u32 raw[6];129 struct {130+ __be32 cqn;131 } __attribute__((packed)) comp;132 struct {133+ u16 reserved1;134+ __be16 token;135+ u32 reserved2;136+ u8 reserved3[3];137+ u8 status;138+ __be64 out_param;139 } __attribute__((packed)) cmd;140 struct {141+ __be32 qpn;142 } __attribute__((packed)) qp;143 struct {144+ __be32 cqn;145+ u32 reserved1;146+ u8 reserved2[3];147+ u8 syndrome;148 } __attribute__((packed)) cq_err;149 struct {150+ u32 reserved1[2];151+ __be32 port;152 } __attribute__((packed)) port_change;153 } event;154 u8 reserved3[3];···167168static inline void tavor_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)169{170+ __be32 doorbell[2];171172 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_SET_CI | eq->eqn);173 doorbell[1] = cpu_to_be32(ci & (eq->nent - 1));···190{191 /* See comment in tavor_set_eq_ci() above. */192 wmb();193+ __raw_writel((__force u32) cpu_to_be32(ci),194+ dev->eq_regs.arbel.eq_set_ci_base + eq->eqn * 8);195 /* We still want ordering, just not swabbing, so add a barrier */196 mb();197}···206207static inline void tavor_eq_req_not(struct mthca_dev *dev, int eqn)208{209+ __be32 doorbell[2];210211 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_REQ_NOT | eqn);212 doorbell[1] = 0;···224static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)225{226 if (!mthca_is_memfree(dev)) {227+ __be32 doorbell[2];228229 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);230 doorbell[1] = cpu_to_be32(cqn);
+6-4
drivers/infiniband/hw/mthca/mthca_mad.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···34 * $Id: mthca_mad.c 1349 2004-12-16 21:09:43Z roland $35 */3637-#include <ib_verbs.h>38-#include <ib_mad.h>39-#include <ib_smi.h>4041#include "mthca_dev.h"42#include "mthca_cmd.h"···194{195 int err;196 u8 status;197- u16 slid = in_wc ? in_wc->slid : IB_LID_PERMISSIVE;198199 /* Forward locally generated traps to the SM */200 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP &&
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···32 * $Id: mthca_mad.c 1349 2004-12-16 21:09:43Z roland $33 */3435+#include <rdma/ib_verbs.h>36+#include <rdma/ib_mad.h>37+#include <rdma/ib_smi.h>3839#include "mthca_dev.h"40#include "mthca_cmd.h"···192{193 int err;194 u8 status;195+ u16 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);196197 /* Forward locally generated traps to the SM */198 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP &&
+106-73
drivers/infiniband/hw/mthca/mthca_main.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···35 */3637#include <linux/config.h>38-#include <linux/version.h>39#include <linux/module.h>40#include <linux/init.h>41#include <linux/errno.h>···171 mdev->limits.reserved_mrws = dev_lim->reserved_mrws;172 mdev->limits.reserved_uars = dev_lim->reserved_uars;173 mdev->limits.reserved_pds = dev_lim->reserved_pds;0174175 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.176 May be doable since hardware supports it for SRQ.···213 struct mthca_dev_lim dev_lim;214 struct mthca_profile profile;215 struct mthca_init_hca_param init_hca;216- struct mthca_adapter adapter;217218 err = mthca_SYS_EN(mdev, &status);219 if (err) {···253 profile = default_profile;254 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;255 profile.uarc_size = 0;00256257 err = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);258 if (err < 0)···272 goto err_disable;273 }274275- err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);276- if (err) {277- mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");278- goto err_close;279- }280- if (status) {281- mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "282- "aborting.\n", status);283- err = -EINVAL;284- goto err_close;285- }286-287- mdev->eq_table.inta_pin = adapter.inta_pin;288- mdev->rev_id = adapter.revision_id;289-290 return 0;291-292-err_close:293- mthca_CLOSE_HCA(mdev, 0, &status);294295err_disable:296 mthca_SYS_DIS(mdev, &status);···426 }427428 mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,429- dev_lim->cqc_entry_sz,430- mdev->limits.num_cqs,431- mdev->limits.reserved_cqs, 0);432 if (!mdev->cq_table.table) {433 mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");434 err = -ENOMEM;435 goto err_unmap_rdb;00000000000000436 }437438 /*···464 if (!mdev->mcg_table.table) {465 mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");466 err = -ENOMEM;467- goto err_unmap_cq;468 }469470 return 0;0000471472err_unmap_cq:473 mthca_free_icm_table(mdev, mdev->cq_table.table);···508 struct mthca_dev_lim dev_lim;509 struct mthca_profile profile;510 struct mthca_init_hca_param init_hca;511- struct mthca_adapter adapter;512 u64 icm_size;513 u8 status;514 int err;···552 profile = default_profile;553 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;554 profile.num_udav = 0;00555556 icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);557 if ((int) icm_size < 0) {···577 goto err_free_icm;578 }579580- err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);581- if (err) {582- mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");583- goto err_free_icm;584- }585- if (status) {586- mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "587- "aborting.\n", status);588- err = -EINVAL;589- goto err_free_icm;590- }591-592- mdev->eq_table.inta_pin = adapter.inta_pin;593- mdev->rev_id = adapter.revision_id;594-595 return 0;596597err_free_icm:00598 mthca_free_icm_table(mdev, mdev->cq_table.table);599 mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);600 mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);···604 return err;605}60600000000000000000000000000000607static int __devinit mthca_init_hca(struct mthca_dev *mdev)608{0000609 if (mthca_is_memfree(mdev))610- return mthca_init_arbel(mdev);611 else612- return mthca_init_tavor(mdev);0000000000000000000000000613}614615static int __devinit mthca_setup_hca(struct mthca_dev *dev)···757 goto err_cmd_poll;758 }7590000000760 err = mthca_init_qp_table(dev);761 if (err) {762 mthca_err(dev, "Failed to initialize "763 "queue pair table, aborting.\n");764- goto err_cq_table_free;765 }766767 err = mthca_init_av_table(dev);···792793err_qp_table_free:794 mthca_cleanup_qp_table(dev);000795796err_cq_table_free:797 mthca_cleanup_cq_table(dev);···902 return 0;903}904905-static void mthca_close_hca(struct mthca_dev *mdev)906-{907- u8 status;908-909- mthca_CLOSE_HCA(mdev, 0, &status);910-911- if (mthca_is_memfree(mdev)) {912- mthca_free_icm_table(mdev, mdev->cq_table.table);913- mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);914- mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);915- mthca_free_icm_table(mdev, mdev->qp_table.qp_table);916- mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);917- mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);918- mthca_unmap_eq_icm(mdev);919-920- mthca_UNMAP_ICM_AUX(mdev, &status);921- mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);922-923- mthca_UNMAP_FA(mdev, &status);924- mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);925-926- if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))927- mthca_DISABLE_LAM(mdev, &status);928- } else929- mthca_SYS_DIS(mdev, &status);930-}931-932/* Types of supported HCA */933enum {934 TAVOR, /* MT23108 */···918 int is_memfree;919 int is_pcie;920} mthca_hca_table[] = {921- [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 3, 2), .is_memfree = 0, .is_pcie = 0 },922- [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 6, 2), .is_memfree = 0, .is_pcie = 1 },923- [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 0, 1), .is_memfree = 1, .is_pcie = 1 },924 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 1), .is_memfree = 1, .is_pcie = 1 }925};926···1082 mthca_cleanup_mcg_table(mdev);1083 mthca_cleanup_av_table(mdev);1084 mthca_cleanup_qp_table(mdev);01085 mthca_cleanup_cq_table(mdev);1086 mthca_cmd_use_polling(mdev);1087 mthca_cleanup_eq_table(mdev);···1132 mthca_cleanup_mcg_table(mdev);1133 mthca_cleanup_av_table(mdev);1134 mthca_cleanup_qp_table(mdev);01135 mthca_cleanup_cq_table(mdev);1136 mthca_cmd_use_polling(mdev);1137 mthca_cleanup_eq_table(mdev);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···34 */3536#include <linux/config.h>037#include <linux/module.h>38#include <linux/init.h>39#include <linux/errno.h>···171 mdev->limits.reserved_mrws = dev_lim->reserved_mrws;172 mdev->limits.reserved_uars = dev_lim->reserved_uars;173 mdev->limits.reserved_pds = dev_lim->reserved_pds;174+ mdev->limits.port_width_cap = dev_lim->max_port_width;175176 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.177 May be doable since hardware supports it for SRQ.···212 struct mthca_dev_lim dev_lim;213 struct mthca_profile profile;214 struct mthca_init_hca_param init_hca;0215216 err = mthca_SYS_EN(mdev, &status);217 if (err) {···253 profile = default_profile;254 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;255 profile.uarc_size = 0;256+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)257+ profile.num_srq = dev_lim.max_srqs;258259 err = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);260 if (err < 0)···270 goto err_disable;271 }272000000000000000273 return 0;000274275err_disable:276 mthca_SYS_DIS(mdev, &status);···442 }443444 mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,445+ dev_lim->cqc_entry_sz,446+ mdev->limits.num_cqs,447+ mdev->limits.reserved_cqs, 0);448 if (!mdev->cq_table.table) {449 mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");450 err = -ENOMEM;451 goto err_unmap_rdb;452+ }453+454+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ) {455+ mdev->srq_table.table =456+ mthca_alloc_icm_table(mdev, init_hca->srqc_base,457+ dev_lim->srq_entry_sz,458+ mdev->limits.num_srqs,459+ mdev->limits.reserved_srqs, 0);460+ if (!mdev->srq_table.table) {461+ mthca_err(mdev, "Failed to map SRQ context memory, "462+ "aborting.\n");463+ err = -ENOMEM;464+ goto err_unmap_cq;465+ }466 }467468 /*···466 if (!mdev->mcg_table.table) {467 mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");468 err = -ENOMEM;469+ goto err_unmap_srq;470 }471472 return 0;473+474+err_unmap_srq:475+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)476+ mthca_free_icm_table(mdev, mdev->srq_table.table);477478err_unmap_cq:479 mthca_free_icm_table(mdev, mdev->cq_table.table);···506 struct mthca_dev_lim dev_lim;507 struct mthca_profile profile;508 struct mthca_init_hca_param init_hca;0509 u64 icm_size;510 u8 status;511 int err;···551 profile = default_profile;552 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;553 profile.num_udav = 0;554+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)555+ profile.num_srq = dev_lim.max_srqs;556557 icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);558 if ((int) icm_size < 0) {···574 goto err_free_icm;575 }576000000000000000577 return 0;578579err_free_icm:580+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)581+ mthca_free_icm_table(mdev, mdev->srq_table.table);582 mthca_free_icm_table(mdev, mdev->cq_table.table);583 mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);584 mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);···614 return err;615}616617+static void mthca_close_hca(struct mthca_dev *mdev)618+{619+ u8 status;620+621+ mthca_CLOSE_HCA(mdev, 0, &status);622+623+ if (mthca_is_memfree(mdev)) {624+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)625+ mthca_free_icm_table(mdev, mdev->srq_table.table);626+ mthca_free_icm_table(mdev, mdev->cq_table.table);627+ mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);628+ mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);629+ mthca_free_icm_table(mdev, mdev->qp_table.qp_table);630+ mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);631+ mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);632+ mthca_unmap_eq_icm(mdev);633+634+ mthca_UNMAP_ICM_AUX(mdev, &status);635+ mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);636+637+ mthca_UNMAP_FA(mdev, &status);638+ mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);639+640+ if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))641+ mthca_DISABLE_LAM(mdev, &status);642+ } else643+ mthca_SYS_DIS(mdev, &status);644+}645+646static int __devinit mthca_init_hca(struct mthca_dev *mdev)647{648+ u8 status;649+ int err;650+ struct mthca_adapter adapter;651+652 if (mthca_is_memfree(mdev))653+ err = mthca_init_arbel(mdev);654 else655+ err = mthca_init_tavor(mdev);656+657+ if (err)658+ return err;659+660+ err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);661+ if (err) {662+ mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");663+ goto err_close;664+ }665+ if (status) {666+ mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "667+ "aborting.\n", status);668+ err = -EINVAL;669+ goto err_close;670+ }671+672+ mdev->eq_table.inta_pin = adapter.inta_pin;673+ mdev->rev_id = adapter.revision_id;674+ memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);675+676+ return 0;677+678+err_close:679+ mthca_close_hca(mdev);680+ return err;681}682683static int __devinit mthca_setup_hca(struct mthca_dev *dev)···709 goto err_cmd_poll;710 }711712+ err = mthca_init_srq_table(dev);713+ if (err) {714+ mthca_err(dev, "Failed to initialize "715+ "shared receive queue table, aborting.\n");716+ goto err_cq_table_free;717+ }718+719 err = mthca_init_qp_table(dev);720 if (err) {721 mthca_err(dev, "Failed to initialize "722 "queue pair table, aborting.\n");723+ goto err_srq_table_free;724 }725726 err = mthca_init_av_table(dev);···737738err_qp_table_free:739 mthca_cleanup_qp_table(dev);740+741+err_srq_table_free:742+ mthca_cleanup_srq_table(dev);743744err_cq_table_free:745 mthca_cleanup_cq_table(dev);···844 return 0;845}846000000000000000000000000000847/* Types of supported HCA */848enum {849 TAVOR, /* MT23108 */···887 int is_memfree;888 int is_pcie;889} mthca_hca_table[] = {890+ [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 3, 3), .is_memfree = 0, .is_pcie = 0 },891+ [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 0), .is_memfree = 0, .is_pcie = 1 },892+ [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0), .is_memfree = 1, .is_pcie = 1 },893 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 1), .is_memfree = 1, .is_pcie = 1 }894};895···1051 mthca_cleanup_mcg_table(mdev);1052 mthca_cleanup_av_table(mdev);1053 mthca_cleanup_qp_table(mdev);1054+ mthca_cleanup_srq_table(mdev);1055 mthca_cleanup_cq_table(mdev);1056 mthca_cmd_use_polling(mdev);1057 mthca_cleanup_eq_table(mdev);···1100 mthca_cleanup_mcg_table(mdev);1101 mthca_cleanup_av_table(mdev);1102 mthca_cleanup_qp_table(mdev);1103+ mthca_cleanup_srq_table(mdev);1104 mthca_cleanup_cq_table(mdev);1105 mthca_cmd_use_polling(mdev);1106 mthca_cleanup_eq_table(mdev);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···286{287 struct mthca_icm_table *table;288 int num_icm;0289 int i;290 u8 status;291···307 table->icm[i] = NULL;308309 for (i = 0; i * MTHCA_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) {310- table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT,0000311 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) |312 __GFP_NOWARN);313 if (!table->icm[i])···487 }488}489490-int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db)491{492 int group;493 int start, end, dir;···570571 page->db_rec[j] = cpu_to_be64((qn << 8) | (type << 5));572573- *db = (u32 *) &page->db_rec[j];574575out:576 up(&dev->db_tab->mutex);
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···285{286 struct mthca_icm_table *table;287 int num_icm;288+ unsigned chunk_size;289 int i;290 u8 status;291···305 table->icm[i] = NULL;306307 for (i = 0; i * MTHCA_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) {308+ chunk_size = MTHCA_TABLE_CHUNK_SIZE;309+ if ((i + 1) * MTHCA_TABLE_CHUNK_SIZE > nobj * obj_size)310+ chunk_size = nobj * obj_size - i * MTHCA_TABLE_CHUNK_SIZE;311+312+ table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT,313 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) |314 __GFP_NOWARN);315 if (!table->icm[i])···481 }482}483484+int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db)485{486 int group;487 int start, end, dir;···564565 page->db_rec[j] = cpu_to_be64((qn << 8) | (type << 5));566567+ *db = (__be32 *) &page->db_rec[j];568569out:570 up(&dev->db_tab->mutex);
+3-2
drivers/infiniband/hw/mthca/mthca_memfree.h
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···138139struct mthca_db_page {140 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE);141- u64 *db_rec;142 dma_addr_t mapping;143};144···173174int mthca_init_db_tab(struct mthca_dev *dev);175void mthca_cleanup_db_tab(struct mthca_dev *dev);176-int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db);177void mthca_free_db(struct mthca_dev *dev, int type, int db_index);178179#endif /* MTHCA_MEMFREE_H */
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···137138struct mthca_db_page {139 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE);140+ __be64 *db_rec;141 dma_addr_t mapping;142};143···172173int mthca_init_db_tab(struct mthca_dev *dev);174void mthca_cleanup_db_tab(struct mthca_dev *dev);175+int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db);176void mthca_free_db(struct mthca_dev *dev, int type, int db_index);177178#endif /* MTHCA_MEMFREE_H */
+18-17
drivers/infiniband/hw/mthca/mthca_mr.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···51 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.52 */53struct mthca_mpt_entry {54- u32 flags;55- u32 page_size;56- u32 key;57- u32 pd;58- u64 start;59- u64 length;60- u32 lkey;61- u32 window_count;62- u32 window_count_limit;63- u64 mtt_seg;64- u32 mtt_sz; /* Arbel only */65- u32 reserved[2];66} __attribute__((packed));6768#define MTHCA_MPT_FLAG_SW_OWNS (0xfUL << 28)···248 int start_index, u64 *buffer_list, int list_len)249{250 struct mthca_mailbox *mailbox;251- u64 *mtt_entry;252 int err = 0;253 u8 status;254 int i;···390 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {391 if (i % 4 == 0)392 printk("[%02x] ", i * 4);393- printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));394 if ((i + 1) % 4 == 0)395 printk("\n");396 }···459static void mthca_free_region(struct mthca_dev *dev, u32 lkey)460{461 mthca_table_put(dev, dev->mr_table.mpt_table,462- arbel_key_to_hw_index(lkey));463464 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey));465}···563 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {564 if (i % 4 == 0)565 printk("[%02x] ", i * 4);566- printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));567 if ((i + 1) % 4 == 0)568 printk("\n");569 }···670 mpt_entry.length = cpu_to_be64(list_len * (1ull << fmr->attr.page_size));671 mpt_entry.start = cpu_to_be64(iova);672673- writel(mpt_entry.lkey, &fmr->mem.tavor.mpt->key);674 memcpy_toio(&fmr->mem.tavor.mpt->start, &mpt_entry.start,675 offsetof(struct mthca_mpt_entry, window_count) -676 offsetof(struct mthca_mpt_entry, start));
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···50 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.51 */52struct mthca_mpt_entry {53+ __be32 flags;54+ __be32 page_size;55+ __be32 key;56+ __be32 pd;57+ __be64 start;58+ __be64 length;59+ __be32 lkey;60+ __be32 window_count;61+ __be32 window_count_limit;62+ __be64 mtt_seg;63+ __be32 mtt_sz; /* Arbel only */64+ u32 reserved[2];65} __attribute__((packed));6667#define MTHCA_MPT_FLAG_SW_OWNS (0xfUL << 28)···247 int start_index, u64 *buffer_list, int list_len)248{249 struct mthca_mailbox *mailbox;250+ __be64 *mtt_entry;251 int err = 0;252 u8 status;253 int i;···389 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {390 if (i % 4 == 0)391 printk("[%02x] ", i * 4);392+ printk(" %08x", be32_to_cpu(((__be32 *) mpt_entry)[i]));393 if ((i + 1) % 4 == 0)394 printk("\n");395 }···458static void mthca_free_region(struct mthca_dev *dev, u32 lkey)459{460 mthca_table_put(dev, dev->mr_table.mpt_table,461+ key_to_hw_index(dev, lkey));462463 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey));464}···562 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {563 if (i % 4 == 0)564 printk("[%02x] ", i * 4);565+ printk(" %08x", be32_to_cpu(((__be32 *) mpt_entry)[i]));566 if ((i + 1) % 4 == 0)567 printk("\n");568 }···669 mpt_entry.length = cpu_to_be64(list_len * (1ull << fmr->attr.page_size));670 mpt_entry.start = cpu_to_be64(iova);671672+ __raw_writel((__force u32) mpt_entry.lkey, &fmr->mem.tavor.mpt->key);673 memcpy_toio(&fmr->mem.tavor.mpt->start, &mpt_entry.start,674 offsetof(struct mthca_mpt_entry, window_count) -675 offsetof(struct mthca_mpt_entry, start));
+1
drivers/infiniband/hw/mthca/mthca_pd.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU
+2
drivers/infiniband/hw/mthca/mthca_profile.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···102 profile[MTHCA_RES_UARC].size = request->uarc_size;103104 profile[MTHCA_RES_QP].num = request->num_qp;0105 profile[MTHCA_RES_EQP].num = request->num_qp;106 profile[MTHCA_RES_RDB].num = request->num_qp * request->rdb_per_qp;107 profile[MTHCA_RES_CQ].num = request->num_cq;
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···101 profile[MTHCA_RES_UARC].size = request->uarc_size;102103 profile[MTHCA_RES_QP].num = request->num_qp;104+ profile[MTHCA_RES_SRQ].num = request->num_srq;105 profile[MTHCA_RES_EQP].num = request->num_qp;106 profile[MTHCA_RES_RDB].num = request->num_qp * request->rdb_per_qp;107 profile[MTHCA_RES_CQ].num = request->num_cq;
+2
drivers/infiniband/hw/mthca/mthca_profile.h
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···42struct mthca_profile {43 int num_qp;44 int rdb_per_qp;045 int num_cq;46 int num_mcg;47 int num_mpt;
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···41struct mthca_profile {42 int num_qp;43 int rdb_per_qp;44+ int num_srq;45 int num_cq;46 int num_mcg;47 int num_mpt;
+105-10
drivers/infiniband/hw/mthca/mthca_provider.c
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems. All rights reserved.005 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···36 * $Id: mthca_provider.c 1397 2004-12-28 05:09:00Z roland $37 */3839-#include <ib_smi.h>40#include <linux/mm.h>4142#include "mthca_dev.h"···81 }8283 props->device_cap_flags = mdev->device_cap_flags;84- props->vendor_id = be32_to_cpup((u32 *) (out_mad->data + 36)) &85 0xffffff;86- props->vendor_part_id = be16_to_cpup((u16 *) (out_mad->data + 30));87- props->hw_ver = be16_to_cpup((u16 *) (out_mad->data + 32));88 memcpy(&props->sys_image_guid, out_mad->data + 4, 8);89 memcpy(&props->node_guid, out_mad->data + 12, 8);90···120 if (!in_mad || !out_mad)121 goto out;12200123 memset(in_mad, 0, sizeof *in_mad);124 in_mad->base_version = 1;125 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;···140 goto out;141 }142143- props->lid = be16_to_cpup((u16 *) (out_mad->data + 16));144 props->lmc = out_mad->data[34] & 0x7;145- props->sm_lid = be16_to_cpup((u16 *) (out_mad->data + 18));146 props->sm_sl = out_mad->data[36] & 0xf;147 props->state = out_mad->data[32] & 0xf;148 props->phys_state = out_mad->data[33] >> 4;149- props->port_cap_flags = be32_to_cpup((u32 *) (out_mad->data + 20));150 props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len;0151 props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len;152- props->qkey_viol_cntr = be16_to_cpup((u16 *) (out_mad->data + 48));153 props->active_width = out_mad->data[31] & 0xf;154 props->active_speed = out_mad->data[35] >> 4;155···226 goto out;227 }228229- *pkey = be16_to_cpu(((u16 *) out_mad->data)[index % 32]);230231 out:232 kfree(in_mad);···421{422 mthca_destroy_ah(to_mdev(ah->device), to_mah(ah));423 kfree(ah);00000000000000000000000000000000000000000000000000000000000000000000000424425 return 0;426}···1032 }1033}10340000001035static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);1036static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);1037static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);010381039static struct class_device_attribute *mthca_class_attributes[] = {1040 &class_device_attr_hw_rev,1041 &class_device_attr_fw_ver,1042- &class_device_attr_hca_type01043};10441045int mthca_register_device(struct mthca_dev *dev)···1074 dev->ib_dev.dealloc_pd = mthca_dealloc_pd;1075 dev->ib_dev.create_ah = mthca_ah_create;1076 dev->ib_dev.destroy_ah = mthca_ah_destroy;000000000001077 dev->ib_dev.create_qp = mthca_create_qp;1078 dev->ib_dev.modify_qp = mthca_modify_qp;1079 dev->ib_dev.destroy_qp = mthca_destroy_qp;
···2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4 * Copyright (c) 2005 Cisco Systems. All rights reserved.5+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.6+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.7 *8 * This software is available to you under a choice of one of two9 * licenses. You may choose to be licensed under the terms of the GNU···34 * $Id: mthca_provider.c 1397 2004-12-28 05:09:00Z roland $35 */3637+#include <rdma/ib_smi.h>38#include <linux/mm.h>3940#include "mthca_dev.h"···79 }8081 props->device_cap_flags = mdev->device_cap_flags;82+ props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) &83 0xffffff;84+ props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30));85+ props->hw_ver = be16_to_cpup((__be16 *) (out_mad->data + 32));86 memcpy(&props->sys_image_guid, out_mad->data + 4, 8);87 memcpy(&props->node_guid, out_mad->data + 12, 8);88···118 if (!in_mad || !out_mad)119 goto out;120121+ memset(props, 0, sizeof *props);122+123 memset(in_mad, 0, sizeof *in_mad);124 in_mad->base_version = 1;125 in_mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;···136 goto out;137 }138139+ props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16));140 props->lmc = out_mad->data[34] & 0x7;141+ props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18));142 props->sm_sl = out_mad->data[36] & 0xf;143 props->state = out_mad->data[32] & 0xf;144 props->phys_state = out_mad->data[33] >> 4;145+ props->port_cap_flags = be32_to_cpup((__be32 *) (out_mad->data + 20));146 props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len;147+ props->max_msg_sz = 0x80000000;148 props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len;149+ props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48));150 props->active_width = out_mad->data[31] & 0xf;151 props->active_speed = out_mad->data[35] >> 4;152···221 goto out;222 }223224+ *pkey = be16_to_cpu(((__be16 *) out_mad->data)[index % 32]);225226 out:227 kfree(in_mad);···416{417 mthca_destroy_ah(to_mdev(ah->device), to_mah(ah));418 kfree(ah);419+420+ return 0;421+}422+423+static struct ib_srq *mthca_create_srq(struct ib_pd *pd,424+ struct ib_srq_init_attr *init_attr,425+ struct ib_udata *udata)426+{427+ struct mthca_create_srq ucmd;428+ struct mthca_ucontext *context = NULL;429+ struct mthca_srq *srq;430+ int err;431+432+ srq = kmalloc(sizeof *srq, GFP_KERNEL);433+ if (!srq)434+ return ERR_PTR(-ENOMEM);435+436+ if (pd->uobject) {437+ context = to_mucontext(pd->uobject->context);438+439+ if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))440+ return ERR_PTR(-EFAULT);441+442+ err = mthca_map_user_db(to_mdev(pd->device), &context->uar,443+ context->db_tab, ucmd.db_index,444+ ucmd.db_page);445+446+ if (err)447+ goto err_free;448+449+ srq->mr.ibmr.lkey = ucmd.lkey;450+ srq->db_index = ucmd.db_index;451+ }452+453+ err = mthca_alloc_srq(to_mdev(pd->device), to_mpd(pd),454+ &init_attr->attr, srq);455+456+ if (err && pd->uobject)457+ mthca_unmap_user_db(to_mdev(pd->device), &context->uar,458+ context->db_tab, ucmd.db_index);459+460+ if (err)461+ goto err_free;462+463+ if (context && ib_copy_to_udata(udata, &srq->srqn, sizeof (__u32))) {464+ mthca_free_srq(to_mdev(pd->device), srq);465+ err = -EFAULT;466+ goto err_free;467+ }468+469+ return &srq->ibsrq;470+471+err_free:472+ kfree(srq);473+474+ return ERR_PTR(err);475+}476+477+static int mthca_destroy_srq(struct ib_srq *srq)478+{479+ struct mthca_ucontext *context;480+481+ if (srq->uobject) {482+ context = to_mucontext(srq->uobject->context);483+484+ mthca_unmap_user_db(to_mdev(srq->device), &context->uar,485+ context->db_tab, to_msrq(srq)->db_index);486+ }487+488+ mthca_free_srq(to_mdev(srq->device), to_msrq(srq));489+ kfree(srq);490491 return 0;492}···956 }957}958959+static ssize_t show_board(struct class_device *cdev, char *buf)960+{961+ struct mthca_dev *dev = container_of(cdev, struct mthca_dev, ib_dev.class_dev);962+ return sprintf(buf, "%.*s\n", MTHCA_BOARD_ID_LEN, dev->board_id);963+}964+965static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);966static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);967static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);968+static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);969970static struct class_device_attribute *mthca_class_attributes[] = {971 &class_device_attr_hw_rev,972 &class_device_attr_fw_ver,973+ &class_device_attr_hca_type,974+ &class_device_attr_board_id975};976977int mthca_register_device(struct mthca_dev *dev)···990 dev->ib_dev.dealloc_pd = mthca_dealloc_pd;991 dev->ib_dev.create_ah = mthca_ah_create;992 dev->ib_dev.destroy_ah = mthca_ah_destroy;993+994+ if (dev->mthca_flags & MTHCA_FLAG_SRQ) {995+ dev->ib_dev.create_srq = mthca_create_srq;996+ dev->ib_dev.destroy_srq = mthca_destroy_srq;997+998+ if (mthca_is_memfree(dev))999+ dev->ib_dev.post_srq_recv = mthca_arbel_post_srq_recv;1000+ else1001+ dev->ib_dev.post_srq_recv = mthca_tavor_post_srq_recv;1002+ }1003+1004 dev->ib_dev.create_qp = mthca_create_qp;1005 dev->ib_dev.modify_qp = mthca_modify_qp;1006 dev->ib_dev.destroy_qp = mthca_destroy_qp;
+41-13
drivers/infiniband/hw/mthca/mthca_provider.h
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.04 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···37#ifndef MTHCA_PROVIDER_H38#define MTHCA_PROVIDER_H3940-#include <ib_verbs.h>41-#include <ib_pack.h>4243#define MTHCA_MPT_FLAG_ATOMIC (1 << 14)44#define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)···49struct mthca_buf_list {50 void *buf;51 DECLARE_PCI_UNMAP_ADDR(mapping)0000052};5354struct mthca_uar {···187188 /* Next fields are Arbel only */189 int set_ci_db_index;190- u32 *set_ci_db;191 int arm_db_index;192- u32 *arm_db;193 int arm_sn;194195- union {196- struct mthca_buf_list direct;197- struct mthca_buf_list *page_list;198- } queue;199 struct mthca_mr mr;200 wait_queue_head_t wait;00000000000000000000000201};202203struct mthca_wq {···232 int wqe_shift;233234 int db_index; /* Arbel only */235- u32 *db;236};237238struct mthca_qp {···253 int send_wqe_offset;254255 u64 *wrid;256- union {257- struct mthca_buf_list direct;258- struct mthca_buf_list *page_list;259- } queue;260261 wait_queue_head_t wait;262};···298static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)299{300 return container_of(ibcq, struct mthca_cq, ibcq);00000301}302303static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···36#ifndef MTHCA_PROVIDER_H37#define MTHCA_PROVIDER_H3839+#include <rdma/ib_verbs.h>40+#include <rdma/ib_pack.h>4142#define MTHCA_MPT_FLAG_ATOMIC (1 << 14)43#define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)···48struct mthca_buf_list {49 void *buf;50 DECLARE_PCI_UNMAP_ADDR(mapping)51+};52+53+union mthca_buf {54+ struct mthca_buf_list direct;55+ struct mthca_buf_list *page_list;56};5758struct mthca_uar {···181182 /* Next fields are Arbel only */183 int set_ci_db_index;184+ __be32 *set_ci_db;185 int arm_db_index;186+ __be32 *arm_db;187 int arm_sn;188189+ union mthca_buf queue;000190 struct mthca_mr mr;191 wait_queue_head_t wait;192+};193+194+struct mthca_srq {195+ struct ib_srq ibsrq;196+ spinlock_t lock;197+ atomic_t refcount;198+ int srqn;199+ int max;200+ int max_gs;201+ int wqe_shift;202+ int first_free;203+ int last_free;204+ u16 counter; /* Arbel only */205+ int db_index; /* Arbel only */206+ __be32 *db; /* Arbel only */207+ void *last;208+209+ int is_direct;210+ u64 *wrid;211+ union mthca_buf queue;212+ struct mthca_mr mr;213+214+ wait_queue_head_t wait;215};216217struct mthca_wq {···206 int wqe_shift;207208 int db_index; /* Arbel only */209+ __be32 *db;210};211212struct mthca_qp {···227 int send_wqe_offset;228229 u64 *wrid;230+ union mthca_buf queue;000231232 wait_queue_head_t wait;233};···275static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)276{277 return container_of(ibcq, struct mthca_cq, ibcq);278+}279+280+static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq)281+{282+ return container_of(ibsrq, struct mthca_srq, ibsrq);283}284285static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)
+105-257
drivers/infiniband/hw/mthca/mthca_qp.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.004 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···3738#include <linux/init.h>3940-#include <ib_verbs.h>41-#include <ib_cache.h>42-#include <ib_pack.h>4344#include "mthca_dev.h"45#include "mthca_cmd.h"46#include "mthca_memfree.h"04748enum {49 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,···98};99100struct mthca_qp_path {101- u32 port_pkey;102- u8 rnr_retry;103- u8 g_mylmc;104- u16 rlid;105- u8 ackto;106- u8 mgid_index;107- u8 static_rate;108- u8 hop_limit;109- u32 sl_tclass_flowlabel;110- u8 rgid[16];111} __attribute__((packed));112113struct mthca_qp_context {114- u32 flags;115- u32 tavor_sched_queue; /* Reserved on Arbel */116- u8 mtu_msgmax;117- u8 rq_size_stride; /* Reserved on Tavor */118- u8 sq_size_stride; /* Reserved on Tavor */119- u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */120- u32 usr_page;121- u32 local_qpn;122- u32 remote_qpn;123- u32 reserved1[2];124 struct mthca_qp_path pri_path;125 struct mthca_qp_path alt_path;126- u32 rdd;127- u32 pd;128- u32 wqe_base;129- u32 wqe_lkey;130- u32 params1;131- u32 reserved2;132- u32 next_send_psn;133- u32 cqn_snd;134- u32 snd_wqe_base_l; /* Next send WQE on Tavor */135- u32 snd_db_index; /* (debugging only entries) */136- u32 last_acked_psn;137- u32 ssn;138- u32 params2;139- u32 rnr_nextrecvpsn;140- u32 ra_buff_indx;141- u32 cqn_rcv;142- u32 rcv_wqe_base_l; /* Next recv WQE on Tavor */143- u32 rcv_db_index; /* (debugging only entries) */144- u32 qkey;145- u32 srqn;146- u32 rmsn;147- u16 rq_wqe_counter; /* reserved on Tavor */148- u16 sq_wqe_counter; /* reserved on Tavor */149- u32 reserved3[18];150} __attribute__((packed));151152struct mthca_qp_param {153- u32 opt_param_mask;154- u32 reserved1;155 struct mthca_qp_context context;156- u32 reserved2[62];157} __attribute__((packed));158159enum {···174 MTHCA_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,175 MTHCA_QP_OPTPAR_RNR_RETRY = 1 << 15,176 MTHCA_QP_OPTPAR_SCHED_QUEUE = 1 << 16177-};178-179-enum {180- MTHCA_NEXT_DBD = 1 << 7,181- MTHCA_NEXT_FENCE = 1 << 6,182- MTHCA_NEXT_CQ_UPDATE = 1 << 3,183- MTHCA_NEXT_EVENT_GEN = 1 << 2,184- MTHCA_NEXT_SOLICIT = 1 << 1,185-186- MTHCA_MLX_VL15 = 1 << 17,187- MTHCA_MLX_SLR = 1 << 16188-};189-190-enum {191- MTHCA_INVAL_LKEY = 0x100192-};193-194-struct mthca_next_seg {195- u32 nda_op; /* [31:6] next WQE [4:0] next opcode */196- u32 ee_nds; /* [31:8] next EE [7] DBD [6] F [5:0] next WQE size */197- u32 flags; /* [3] CQ [2] Event [1] Solicit */198- u32 imm; /* immediate data */199-};200-201-struct mthca_tavor_ud_seg {202- u32 reserved1;203- u32 lkey;204- u64 av_addr;205- u32 reserved2[4];206- u32 dqpn;207- u32 qkey;208- u32 reserved3[2];209-};210-211-struct mthca_arbel_ud_seg {212- u32 av[8];213- u32 dqpn;214- u32 qkey;215- u32 reserved[2];216-};217-218-struct mthca_bind_seg {219- u32 flags; /* [31] Atomic [30] rem write [29] rem read */220- u32 reserved;221- u32 new_rkey;222- u32 lkey;223- u64 addr;224- u64 length;225-};226-227-struct mthca_raddr_seg {228- u64 raddr;229- u32 rkey;230- u32 reserved;231-};232-233-struct mthca_atomic_seg {234- u64 swap_add;235- u64 compare;236-};237-238-struct mthca_data_seg {239- u32 byte_count;240- u32 lkey;241- u64 addr;242-};243-244-struct mthca_mlx_seg {245- u32 nda_op;246- u32 nds;247- u32 flags; /* [17] VL15 [16] SLR [14:12] static rate248- [11:8] SL [3] C [2] E */249- u16 rlid;250- u16 vcrc;251};252253static const u8 mthca_opcode[] = {···502503 memset(¶m, 0, sizeof param);504505- param.enable_1x = 1;506- param.enable_4x = 1;507- param.vl_cap = dev->limits.vl_cap;508- param.mtu_cap = dev->limits.mtu_cap;509- param.gid_cap = dev->limits.gid_table_len;510- param.pkey_cap = dev->limits.pkey_table_len;511512 err = mthca_INIT_IB(dev, ¶m, port, &status);513 if (err)···612 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;613614 if (mthca_is_memfree(dev)) {615- qp_context->rq_size_stride =616- ((ffs(qp->rq.max) - 1) << 3) | (qp->rq.wqe_shift - 4);617- qp_context->sq_size_stride =618- ((ffs(qp->sq.max) - 1) << 3) | (qp->sq.wqe_shift - 4);000619 }620621 /* leave arbel_sched_queue as 0 */···787788 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);789000790 if (attr_mask & IB_QP_MIN_RNR_TIMER) {791 qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);792 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_TIMEOUT);···811 qp_context->qkey = cpu_to_be32(attr->qkey);812 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_Q_KEY);813 }0000814815 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,816 qp->qpn, 0, mailbox, 0, &status);···863 struct mthca_qp *qp)864{865 int size;866- int i;867- int npages, shift;868- dma_addr_t t;869- u64 *dma_list = NULL;870 int err = -ENOMEM;871872 size = sizeof (struct mthca_next_seg) +···912 if (!qp->wrid)913 goto err_out;914915- if (size <= MTHCA_MAX_DIRECT_QP_SIZE) {916- qp->is_direct = 1;917- npages = 1;918- shift = get_order(size) + PAGE_SHIFT;919-920- if (0)921- mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n",922- size, shift);923-924- qp->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev, size,925- &t, GFP_KERNEL);926- if (!qp->queue.direct.buf)927- goto err_out;928-929- pci_unmap_addr_set(&qp->queue.direct, mapping, t);930-931- memset(qp->queue.direct.buf, 0, size);932-933- while (t & ((1 << shift) - 1)) {934- --shift;935- npages *= 2;936- }937-938- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);939- if (!dma_list)940- goto err_out_free;941-942- for (i = 0; i < npages; ++i)943- dma_list[i] = t + i * (1 << shift);944- } else {945- qp->is_direct = 0;946- npages = size / PAGE_SIZE;947- shift = PAGE_SHIFT;948-949- if (0)950- mthca_dbg(dev, "Creating indirect QP with %d pages\n", npages);951-952- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);953- if (!dma_list)954- goto err_out;955-956- qp->queue.page_list = kmalloc(npages *957- sizeof *qp->queue.page_list,958- GFP_KERNEL);959- if (!qp->queue.page_list)960- goto err_out;961-962- for (i = 0; i < npages; ++i) {963- qp->queue.page_list[i].buf =964- dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,965- &t, GFP_KERNEL);966- if (!qp->queue.page_list[i].buf)967- goto err_out_free;968-969- memset(qp->queue.page_list[i].buf, 0, PAGE_SIZE);970-971- pci_unmap_addr_set(&qp->queue.page_list[i], mapping, t);972- dma_list[i] = t;973- }974- }975-976- err = mthca_mr_alloc_phys(dev, pd->pd_num, dma_list, shift,977- npages, 0, size,978- MTHCA_MPT_FLAG_LOCAL_READ,979- &qp->mr);980 if (err)981- goto err_out_free;982983- kfree(dma_list);984 return 0;985986- err_out_free:987- if (qp->is_direct) {988- dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,989- pci_unmap_addr(&qp->queue.direct, mapping));990- } else991- for (i = 0; i < npages; ++i) {992- if (qp->queue.page_list[i].buf)993- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,994- qp->queue.page_list[i].buf,995- pci_unmap_addr(&qp->queue.page_list[i],996- mapping));997-998- }999-1000- err_out:1001 kfree(qp->wrid);1002- kfree(dma_list);1003 return err;1004}10051006static void mthca_free_wqe_buf(struct mthca_dev *dev,1007 struct mthca_qp *qp)1008{1009- int i;1010- int size = PAGE_ALIGN(qp->send_wqe_offset +1011- (qp->sq.max << qp->sq.wqe_shift));1012-1013- if (qp->is_direct) {1014- dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,1015- pci_unmap_addr(&qp->queue.direct, mapping));1016- } else {1017- for (i = 0; i < size / PAGE_SIZE; ++i) {1018- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,1019- qp->queue.page_list[i].buf,1020- pci_unmap_addr(&qp->queue.page_list[i],1021- mapping));1022- }1023- }1024-1025 kfree(qp->wrid);1026}1027···1270 * unref the mem-free tables and free the QPN in our table.1271 */1272 if (!qp->ibqp.uobject) {1273- mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn);01274 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)1275- mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn);012761277- mthca_free_mr(dev, &qp->mr);1278 mthca_free_memfree(dev, qp);1279 mthca_free_wqe_buf(dev, qp);1280 }···1300{1301 int header_size;1302 int err;013031304 ib_ud_header_init(256, /* assume a MAD */1305 sqp->ud_header.grh_present,···1311 return err;1312 mlx->flags &= ~cpu_to_be32(MTHCA_NEXT_SOLICIT | 1);1313 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MTHCA_MLX_VL15 : 0) |1314- (sqp->ud_header.lrh.destination_lid == 0xffff ?1315- MTHCA_MLX_SLR : 0) |1316 (sqp->ud_header.lrh.service_level << 8));1317 mlx->rlid = sqp->ud_header.lrh.destination_lid;1318 mlx->vcrc = 0;···1332 }13331334 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;1335- if (sqp->ud_header.lrh.destination_lid == 0xffff)1336- sqp->ud_header.lrh.source_lid = 0xffff;1337 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);1338 if (!sqp->qp.ibqp.qp_num)1339 ib_get_cached_pkey(&dev->ib_dev, sqp->port,1340- sqp->pkey_index,1341- &sqp->ud_header.bth.pkey);1342 else1343 ib_get_cached_pkey(&dev->ib_dev, sqp->port,1344- wr->wr.ud.pkey_index,1345- &sqp->ud_header.bth.pkey);1346- cpu_to_be16s(&sqp->ud_header.bth.pkey);1347 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);1348 sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));1349 sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?···15841585out:1586 if (likely(nreq)) {1587- u32 doorbell[2];15881589 doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +1590 qp->send_wqe_offset) | f0 | op0);···16851686out:1687 if (likely(nreq)) {1688- u32 doorbell[2];16891690 doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);1691 doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);···19061907out:1908 if (likely(nreq)) {1909- u32 doorbell[2];19101911 doorbell[0] = cpu_to_be32((nreq << 24) |1912 ((qp->sq.head & 0xffff) << 8) |···2016}20172018int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,2019- int index, int *dbd, u32 *new_wqe)2020{2021 struct mthca_next_seg *next;00000000020222023 if (is_send)2024 next = get_send_wqe(qp, index);2025 else2026 next = get_recv_wqe(qp, index);20272028- if (mthca_is_memfree(dev))2029- *dbd = 1;2030- else2031- *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));2032 if (next->ee_nds & cpu_to_be32(0x3f))2033 *new_wqe = (next->nda_op & cpu_to_be32(~0x3f)) |2034 (next->ee_nds & cpu_to_be32(0x3f));
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3 * Copyright (c) 2005 Cisco Systems. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 6 *7 * This software is available to you under a choice of one of two8 * licenses. You may choose to be licensed under the terms of the GNU···3536#include <linux/init.h>3738+#include <rdma/ib_verbs.h>39+#include <rdma/ib_cache.h>40+#include <rdma/ib_pack.h>4142#include "mthca_dev.h"43#include "mthca_cmd.h"44#include "mthca_memfree.h"45+#include "mthca_wqe.h"4647enum {48 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,···95};9697struct mthca_qp_path {98+ __be32 port_pkey;99+ u8 rnr_retry;100+ u8 g_mylmc;101+ __be16 rlid;102+ u8 ackto;103+ u8 mgid_index;104+ u8 static_rate;105+ u8 hop_limit;106+ __be32 sl_tclass_flowlabel;107+ u8 rgid[16];108} __attribute__((packed));109110struct mthca_qp_context {111+ __be32 flags;112+ __be32 tavor_sched_queue; /* Reserved on Arbel */113+ u8 mtu_msgmax;114+ u8 rq_size_stride; /* Reserved on Tavor */115+ u8 sq_size_stride; /* Reserved on Tavor */116+ u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */117+ __be32 usr_page;118+ __be32 local_qpn;119+ __be32 remote_qpn;120+ u32 reserved1[2];121 struct mthca_qp_path pri_path;122 struct mthca_qp_path alt_path;123+ __be32 rdd;124+ __be32 pd;125+ __be32 wqe_base;126+ __be32 wqe_lkey;127+ __be32 params1;128+ __be32 reserved2;129+ __be32 next_send_psn;130+ __be32 cqn_snd;131+ __be32 snd_wqe_base_l; /* Next send WQE on Tavor */132+ __be32 snd_db_index; /* (debugging only entries) */133+ __be32 last_acked_psn;134+ __be32 ssn;135+ __be32 params2;136+ __be32 rnr_nextrecvpsn;137+ __be32 ra_buff_indx;138+ __be32 cqn_rcv;139+ __be32 rcv_wqe_base_l; /* Next recv WQE on Tavor */140+ __be32 rcv_db_index; /* (debugging only entries) */141+ __be32 qkey;142+ __be32 srqn;143+ __be32 rmsn;144+ __be16 rq_wqe_counter; /* reserved on Tavor */145+ __be16 sq_wqe_counter; /* reserved on Tavor */146+ u32 reserved3[18];147} __attribute__((packed));148149struct mthca_qp_param {150+ __be32 opt_param_mask;151+ u32 reserved1;152 struct mthca_qp_context context;153+ u32 reserved2[62];154} __attribute__((packed));155156enum {···171 MTHCA_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,172 MTHCA_QP_OPTPAR_RNR_RETRY = 1 << 15,173 MTHCA_QP_OPTPAR_SCHED_QUEUE = 1 << 1600000000000000000000000000000000000000000000000000000000000000000000000000174};175176static const u8 mthca_opcode[] = {···573574 memset(¶m, 0, sizeof param);575576+ param.port_width = dev->limits.port_width_cap;577+ param.vl_cap = dev->limits.vl_cap;578+ param.mtu_cap = dev->limits.mtu_cap;579+ param.gid_cap = dev->limits.gid_table_len;580+ param.pkey_cap = dev->limits.pkey_table_len;0581582 err = mthca_INIT_IB(dev, ¶m, port, &status);583 if (err)···684 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;685686 if (mthca_is_memfree(dev)) {687+ if (qp->rq.max)688+ qp_context->rq_size_stride = long_log2(qp->rq.max) << 3;689+ qp_context->rq_size_stride |= qp->rq.wqe_shift - 4;690+691+ if (qp->sq.max)692+ qp_context->sq_size_stride = long_log2(qp->sq.max) << 3;693+ qp_context->sq_size_stride |= qp->sq.wqe_shift - 4;694 }695696 /* leave arbel_sched_queue as 0 */···856857 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);858859+ if (ibqp->srq)860+ qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RIC);861+862 if (attr_mask & IB_QP_MIN_RNR_TIMER) {863 qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);864 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_TIMEOUT);···877 qp_context->qkey = cpu_to_be32(attr->qkey);878 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_Q_KEY);879 }880+881+ if (ibqp->srq)882+ qp_context->srqn = cpu_to_be32(1 << 24 |883+ to_msrq(ibqp->srq)->srqn);884885 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,886 qp->qpn, 0, mailbox, 0, &status);···925 struct mthca_qp *qp)926{927 int size;0000928 int err = -ENOMEM;929930 size = sizeof (struct mthca_next_seg) +···978 if (!qp->wrid)979 goto err_out;980981+ err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_QP_SIZE,982+ &qp->queue, &qp->is_direct, pd, 0, &qp->mr);000000000000000000000000000000000000000000000000000000000000000983 if (err)984+ goto err_out;9850986 return 0;987988+err_out:00000000000000989 kfree(qp->wrid);0990 return err;991}992993static void mthca_free_wqe_buf(struct mthca_dev *dev,994 struct mthca_qp *qp)995{996+ mthca_buf_free(dev, PAGE_ALIGN(qp->send_wqe_offset +997+ (qp->sq.max << qp->sq.wqe_shift)),998+ &qp->queue, qp->is_direct, &qp->mr);0000000000000999 kfree(qp->wrid);1000}1001···1428 * unref the mem-free tables and free the QPN in our table.1429 */1430 if (!qp->ibqp.uobject) {1431+ mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,1432+ qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);1433 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)1434+ mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn,1435+ qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);143601437 mthca_free_memfree(dev, qp);1438 mthca_free_wqe_buf(dev, qp);1439 }···1457{1458 int header_size;1459 int err;1460+ u16 pkey;14611462 ib_ud_header_init(256, /* assume a MAD */1463 sqp->ud_header.grh_present,···1467 return err;1468 mlx->flags &= ~cpu_to_be32(MTHCA_NEXT_SOLICIT | 1);1469 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MTHCA_MLX_VL15 : 0) |1470+ (sqp->ud_header.lrh.destination_lid ==1471+ IB_LID_PERMISSIVE ? MTHCA_MLX_SLR : 0) |1472 (sqp->ud_header.lrh.service_level << 8));1473 mlx->rlid = sqp->ud_header.lrh.destination_lid;1474 mlx->vcrc = 0;···1488 }14891490 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;1491+ if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)1492+ sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;1493 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);1494 if (!sqp->qp.ibqp.qp_num)1495 ib_get_cached_pkey(&dev->ib_dev, sqp->port,1496+ sqp->pkey_index, &pkey);01497 else1498 ib_get_cached_pkey(&dev->ib_dev, sqp->port,1499+ wr->wr.ud.pkey_index, &pkey);1500+ sqp->ud_header.bth.pkey = cpu_to_be16(pkey);01501 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);1502 sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));1503 sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?···17421743out:1744 if (likely(nreq)) {1745+ __be32 doorbell[2];17461747 doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +1748 qp->send_wqe_offset) | f0 | op0);···18431844out:1845 if (likely(nreq)) {1846+ __be32 doorbell[2];18471848 doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);1849 doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);···20642065out:2066 if (likely(nreq)) {2067+ __be32 doorbell[2];20682069 doorbell[0] = cpu_to_be32((nreq << 24) |2070 ((qp->sq.head & 0xffff) << 8) |···2174}21752176int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,2177+ int index, int *dbd, __be32 *new_wqe)2178{2179 struct mthca_next_seg *next;2180+2181+ /*2182+ * For SRQs, all WQEs generate a CQE, so we're always at the2183+ * end of the doorbell chain.2184+ */2185+ if (qp->ibqp.srq) {2186+ *new_wqe = 0;2187+ return 0;2188+ }21892190 if (is_send)2191 next = get_send_wqe(qp, index);2192 else2193 next = get_recv_wqe(qp, index);21942195+ *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));0002196 if (next->ee_nds & cpu_to_be32(0x3f))2197 *new_wqe = (next->nda_op & cpu_to_be32(~0x3f)) |2198 (next->ee_nds & cpu_to_be32(0x3f));
···1+/*2+ * Copyright (c) 2005 Cisco Systems. All rights reserved.3+ *4+ * This software is available to you under a choice of one of two5+ * licenses. You may choose to be licensed under the terms of the GNU6+ * General Public License (GPL) Version 2, available from the file7+ * COPYING in the main directory of this source tree, or the8+ * OpenIB.org BSD license below:9+ *10+ * Redistribution and use in source and binary forms, with or11+ * without modification, are permitted provided that the following12+ * conditions are met:13+ *14+ * - Redistributions of source code must retain the above15+ * copyright notice, this list of conditions and the following16+ * disclaimer.17+ *18+ * - Redistributions in binary form must reproduce the above19+ * copyright notice, this list of conditions and the following20+ * disclaimer in the documentation and/or other materials21+ * provided with the distribution.22+ *23+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30+ * SOFTWARE.31+ *32+ * $Id: mthca_wqe.h 3047 2005-08-10 03:59:35Z roland $33+ */34+35+#ifndef MTHCA_WQE_H36+#define MTHCA_WQE_H37+38+#include <linux/types.h>39+40+enum {41+ MTHCA_NEXT_DBD = 1 << 7,42+ MTHCA_NEXT_FENCE = 1 << 6,43+ MTHCA_NEXT_CQ_UPDATE = 1 << 3,44+ MTHCA_NEXT_EVENT_GEN = 1 << 2,45+ MTHCA_NEXT_SOLICIT = 1 << 1,46+47+ MTHCA_MLX_VL15 = 1 << 17,48+ MTHCA_MLX_SLR = 1 << 1649+};50+51+enum {52+ MTHCA_INVAL_LKEY = 0x10053+};54+55+struct mthca_next_seg {56+ __be32 nda_op; /* [31:6] next WQE [4:0] next opcode */57+ __be32 ee_nds; /* [31:8] next EE [7] DBD [6] F [5:0] next WQE size */58+ __be32 flags; /* [3] CQ [2] Event [1] Solicit */59+ __be32 imm; /* immediate data */60+};61+62+struct mthca_tavor_ud_seg {63+ u32 reserved1;64+ __be32 lkey;65+ __be64 av_addr;66+ u32 reserved2[4];67+ __be32 dqpn;68+ __be32 qkey;69+ u32 reserved3[2];70+};71+72+struct mthca_arbel_ud_seg {73+ __be32 av[8];74+ __be32 dqpn;75+ __be32 qkey;76+ u32 reserved[2];77+};78+79+struct mthca_bind_seg {80+ __be32 flags; /* [31] Atomic [30] rem write [29] rem read */81+ u32 reserved;82+ __be32 new_rkey;83+ __be32 lkey;84+ __be64 addr;85+ __be64 length;86+};87+88+struct mthca_raddr_seg {89+ __be64 raddr;90+ __be32 rkey;91+ u32 reserved;92+};93+94+struct mthca_atomic_seg {95+ __be64 swap_add;96+ __be64 compare;97+};98+99+struct mthca_data_seg {100+ __be32 byte_count;101+ __be32 lkey;102+ __be64 addr;103+};104+105+struct mthca_mlx_seg {106+ __be32 nda_op;107+ __be32 nds;108+ __be32 flags; /* [17] VL15 [16] SLR [14:12] static rate109+ [11:8] SL [3] C [2] E */110+ __be16 rlid;111+ __be16 vcrc;112+};113+114+#endif /* MTHCA_WQE_H */
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···37#ifndef _IB_CACHE_H38#define _IB_CACHE_H3940-#include <ib_verbs.h>4142/**43 * ib_get_cached_gid - Returns a cached GID table entry
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Intel Corporation. All rights reserved.4+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···35#ifndef _IB_CACHE_H36#define _IB_CACHE_H3738+#include <rdma/ib_verbs.h>3940/**41 * ib_get_cached_gid - Returns a cached GID table entry
···4 * Copyright (c) 2004 Intel Corporation. All rights reserved.5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.07 * Copyright (c) 2005 Cisco Systems. All rights reserved.8 *9 * This software is available to you under a choice of one of two···51union ib_gid {52 u8 raw[16];53 struct {54- u64 subnet_prefix;55- u64 interface_id;56 } global;57};58···8889struct ib_device_attr {90 u64 fw_ver;91- u64 node_guid;92- u64 sys_image_guid;93 u64 max_mr_size;94 u64 page_size_cap;95 u32 vendor_id;···256 IB_EVENT_PORT_ERR,257 IB_EVENT_LID_CHANGE,258 IB_EVENT_PKEY_CHANGE,259- IB_EVENT_SM_CHANGE000260};261262struct ib_event {···267 union {268 struct ib_cq *cq;269 struct ib_qp *qp;0270 u8 port_num;271 } element;272 enum ib_event_type event;···295};296297struct ib_grh {298- u32 version_tclass_flow;299- u16 paylen;300 u8 next_hdr;301 u8 hop_limit;302 union ib_gid sgid;···306enum {307 IB_MULTICAST_QPN = 0xffffff308};00309310enum ib_ah_flags {311 IB_AH_GRH = 1···388enum ib_cq_notify {389 IB_CQ_SOLICITED,390 IB_CQ_NEXT_COMP00000000000000000391};392393struct ib_qp_cap {···734};735736struct ib_srq {737- struct ib_device *device;738- struct ib_uobject *uobject;739- struct ib_pd *pd;740- void *srq_context;0741 atomic_t usecnt;742};743···852 int (*query_ah)(struct ib_ah *ah,853 struct ib_ah_attr *ah_attr);854 int (*destroy_ah)(struct ib_ah *ah);000000000000855 struct ib_qp * (*create_qp)(struct ib_pd *pd,856 struct ib_qp_init_attr *qp_init_attr,857 struct ib_udata *udata);···1074 * @ah: The address handle to destroy.1075 */1076int ib_destroy_ah(struct ib_ah *ah);0000000000000000000000000000000000000000000000000000000000010771078/**1079 * ib_create_qp - Creates a QP associated with the specified protection
···4 * Copyright (c) 2004 Intel Corporation. All rights reserved.5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.7+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.8 * Copyright (c) 2005 Cisco Systems. All rights reserved.9 *10 * This software is available to you under a choice of one of two···50union ib_gid {51 u8 raw[16];52 struct {53+ __be64 subnet_prefix;54+ __be64 interface_id;55 } global;56};57···8788struct ib_device_attr {89 u64 fw_ver;90+ __be64 node_guid;91+ __be64 sys_image_guid;92 u64 max_mr_size;93 u64 page_size_cap;94 u32 vendor_id;···255 IB_EVENT_PORT_ERR,256 IB_EVENT_LID_CHANGE,257 IB_EVENT_PKEY_CHANGE,258+ IB_EVENT_SM_CHANGE,259+ IB_EVENT_SRQ_ERR,260+ IB_EVENT_SRQ_LIMIT_REACHED,261+ IB_EVENT_QP_LAST_WQE_REACHED262};263264struct ib_event {···263 union {264 struct ib_cq *cq;265 struct ib_qp *qp;266+ struct ib_srq *srq;267 u8 port_num;268 } element;269 enum ib_event_type event;···290};291292struct ib_grh {293+ __be32 version_tclass_flow;294+ __be16 paylen;295 u8 next_hdr;296 u8 hop_limit;297 union ib_gid sgid;···301enum {302 IB_MULTICAST_QPN = 0xffffff303};304+305+#define IB_LID_PERMISSIVE __constant_htons(0xFFFF)306307enum ib_ah_flags {308 IB_AH_GRH = 1···381enum ib_cq_notify {382 IB_CQ_SOLICITED,383 IB_CQ_NEXT_COMP384+};385+386+enum ib_srq_attr_mask {387+ IB_SRQ_MAX_WR = 1 << 0,388+ IB_SRQ_LIMIT = 1 << 1,389+};390+391+struct ib_srq_attr {392+ u32 max_wr;393+ u32 max_sge;394+ u32 srq_limit;395+};396+397+struct ib_srq_init_attr {398+ void (*event_handler)(struct ib_event *, void *);399+ void *srq_context;400+ struct ib_srq_attr attr;401};402403struct ib_qp_cap {···710};711712struct ib_srq {713+ struct ib_device *device;714+ struct ib_pd *pd;715+ struct ib_uobject *uobject;716+ void (*event_handler)(struct ib_event *, void *);717+ void *srq_context;718 atomic_t usecnt;719};720···827 int (*query_ah)(struct ib_ah *ah,828 struct ib_ah_attr *ah_attr);829 int (*destroy_ah)(struct ib_ah *ah);830+ struct ib_srq * (*create_srq)(struct ib_pd *pd,831+ struct ib_srq_init_attr *srq_init_attr,832+ struct ib_udata *udata);833+ int (*modify_srq)(struct ib_srq *srq,834+ struct ib_srq_attr *srq_attr,835+ enum ib_srq_attr_mask srq_attr_mask);836+ int (*query_srq)(struct ib_srq *srq,837+ struct ib_srq_attr *srq_attr);838+ int (*destroy_srq)(struct ib_srq *srq);839+ int (*post_srq_recv)(struct ib_srq *srq,840+ struct ib_recv_wr *recv_wr,841+ struct ib_recv_wr **bad_recv_wr);842 struct ib_qp * (*create_qp)(struct ib_pd *pd,843 struct ib_qp_init_attr *qp_init_attr,844 struct ib_udata *udata);···1037 * @ah: The address handle to destroy.1038 */1039int ib_destroy_ah(struct ib_ah *ah);1040+1041+/**1042+ * ib_create_srq - Creates a SRQ associated with the specified protection1043+ * domain.1044+ * @pd: The protection domain associated with the SRQ.1045+ * @srq_init_attr: A list of initial attributes required to create the SRQ.1046+ *1047+ * srq_attr->max_wr and srq_attr->max_sge are read the determine the1048+ * requested size of the SRQ, and set to the actual values allocated1049+ * on return. If ib_create_srq() succeeds, then max_wr and max_sge1050+ * will always be at least as large as the requested values.1051+ */1052+struct ib_srq *ib_create_srq(struct ib_pd *pd,1053+ struct ib_srq_init_attr *srq_init_attr);1054+1055+/**1056+ * ib_modify_srq - Modifies the attributes for the specified SRQ.1057+ * @srq: The SRQ to modify.1058+ * @srq_attr: On input, specifies the SRQ attributes to modify. On output,1059+ * the current values of selected SRQ attributes are returned.1060+ * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ1061+ * are being modified.1062+ *1063+ * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or1064+ * IB_SRQ_LIMIT to set the SRQ's limit and request notification when1065+ * the number of receives queued drops below the limit.1066+ */1067+int ib_modify_srq(struct ib_srq *srq,1068+ struct ib_srq_attr *srq_attr,1069+ enum ib_srq_attr_mask srq_attr_mask);1070+1071+/**1072+ * ib_query_srq - Returns the attribute list and current values for the1073+ * specified SRQ.1074+ * @srq: The SRQ to query.1075+ * @srq_attr: The attributes of the specified SRQ.1076+ */1077+int ib_query_srq(struct ib_srq *srq,1078+ struct ib_srq_attr *srq_attr);1079+1080+/**1081+ * ib_destroy_srq - Destroys the specified SRQ.1082+ * @srq: The SRQ to destroy.1083+ */1084+int ib_destroy_srq(struct ib_srq *srq);1085+1086+/**1087+ * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.1088+ * @srq: The SRQ to post the work request on.1089+ * @recv_wr: A list of work requests to post on the receive queue.1090+ * @bad_recv_wr: On an immediate failure, this parameter will reference1091+ * the work request that failed to be posted on the QP.1092+ */1093+static inline int ib_post_srq_recv(struct ib_srq *srq,1094+ struct ib_recv_wr *recv_wr,1095+ struct ib_recv_wr **bad_recv_wr)1096+{1097+ return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);1098+}10991100/**1101 * ib_create_qp - Creates a QP associated with the specified protection
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···51#include <asm/atomic.h>52#include <asm/semaphore.h>5354-#include <ib_verbs.h>55-#include <ib_pack.h>56-#include <ib_sa.h>5758/* constants */59···90/* structs */9192struct ipoib_header {93- u16 proto;94- u16 reserved;95};9697struct ipoib_pseudoheader {
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···49#include <asm/atomic.h>50#include <asm/semaphore.h>5152+#include <rdma/ib_verbs.h>53+#include <rdma/ib_pack.h>54+#include <rdma/ib_sa.h>5556/* constants */57···88/* structs */8990struct ipoib_header {91+ __be16 proto;92+ u16 reserved;93};9495struct ipoib_pseudoheader {
+1-1
drivers/infiniband/ulp/ipoib/ipoib_fs.c
···9798 for (n = 0, i = 0; i < sizeof mgid / 2; ++i) {99 n += sprintf(gid_buf + n, "%x",100- be16_to_cpu(((u16 *)mgid.raw)[i]));101 if (i < sizeof mgid / 2 - 1)102 gid_buf[n++] = ':';103 }
···9798 for (n = 0, i = 0; i < sizeof mgid / 2; ++i) {99 n += sprintf(gid_buf + n, "%x",100+ be16_to_cpu(((__be16 *) mgid.raw)[i]));101 if (i < sizeof mgid / 2 - 1)102 gid_buf[n++] = ':';103 }
+4-1
drivers/infiniband/ulp/ipoib/ipoib_ib.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.0003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···38#include <linux/delay.h>39#include <linux/dma-mapping.h>4041-#include <ib_cache.h>4243#include "ipoib.h"44
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.5+ * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.6 *7 * This software is available to you under a choice of one of two8 * licenses. You may choose to be licensed under the terms of the GNU···35#include <linux/delay.h>36#include <linux/dma-mapping.h>3738+#include <rdma/ib_cache.h>3940#include "ipoib.h"41
+21-12
drivers/infiniband/ulp/ipoib/ipoib_main.c
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···3637#include "ipoib.h"3839-#include <linux/version.h>40#include <linux/module.h>4142#include <linux/init.h>···608 ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x "609 IPOIB_GID_FMT "\n",610 skb->dst ? "neigh" : "dst",611- be16_to_cpup((u16 *) skb->data),612- be32_to_cpup((u32 *) phdr->hwaddr),613 IPOIB_GID_ARG(*(union ib_gid *) (phdr->hwaddr + 4)));614 dev_kfree_skb_any(skb);615 ++priv->stats.tx_dropped;···672{673 struct ipoib_dev_priv *priv = netdev_priv(dev);674675- schedule_work(&priv->restart_task);676}677678static void ipoib_neigh_destructor(struct neighbour *n)···781782 ipoib_ib_dev_cleanup(dev);783784- if (priv->rx_ring) {785- kfree(priv->rx_ring);786- priv->rx_ring = NULL;787- }788789- if (priv->tx_ring) {790- kfree(priv->tx_ring);791- priv->tx_ring = NULL;792- }793}794795static void ipoib_setup(struct net_device *dev)···883 if (pkey < 0 || pkey > 0xffff)884 return -EINVAL;885000000886 ret = ipoib_vlan_add(container_of(cdev, struct net_device, class_dev),887 pkey);888···940 hca->name, port, result);941 goto alloc_mem_failed;942 }000000943944 priv->dev->broadcast[8] = priv->pkey >> 8;945 priv->dev->broadcast[9] = priv->pkey & 0xff;
···1/*2 * Copyright (c) 2004 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···3435#include "ipoib.h"36037#include <linux/module.h>3839#include <linux/init.h>···607 ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x "608 IPOIB_GID_FMT "\n",609 skb->dst ? "neigh" : "dst",610+ be16_to_cpup((__be16 *) skb->data),611+ be32_to_cpup((__be32 *) phdr->hwaddr),612 IPOIB_GID_ARG(*(union ib_gid *) (phdr->hwaddr + 4)));613 dev_kfree_skb_any(skb);614 ++priv->stats.tx_dropped;···671{672 struct ipoib_dev_priv *priv = netdev_priv(dev);673674+ queue_work(ipoib_workqueue, &priv->restart_task);675}676677static void ipoib_neigh_destructor(struct neighbour *n)···780781 ipoib_ib_dev_cleanup(dev);782783+ kfree(priv->rx_ring);784+ kfree(priv->tx_ring);00785786+ priv->rx_ring = NULL;787+ priv->tx_ring = NULL;00788}789790static void ipoib_setup(struct net_device *dev)···886 if (pkey < 0 || pkey > 0xffff)887 return -EINVAL;888889+ /*890+ * Set the full membership bit, so that we join the right891+ * broadcast group, etc.892+ */893+ pkey |= 0x8000;894+895 ret = ipoib_vlan_add(container_of(cdev, struct net_device, class_dev),896 pkey);897···937 hca->name, port, result);938 goto alloc_mem_failed;939 }940+941+ /*942+ * Set the full membership bit, so that we join the right943+ * broadcast group, etc.944+ */945+ priv->pkey |= 0x8000;946947 priv->dev->broadcast[8] = priv->pkey >> 8;948 priv->dev->broadcast[9] = priv->pkey & 0xff;
+5-3
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.003 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···359360 rec.mgid = mcast->mcmember.mgid;361 rec.port_gid = priv->local_gid;362- rec.pkey = be16_to_cpu(priv->pkey);363364 ret = ib_sa_mcmember_rec_set(priv->ca, priv->port, &rec,365 IB_SA_MCMEMBER_REC_MGID |···459460 rec.mgid = mcast->mcmember.mgid;461 rec.port_gid = priv->local_gid;462- rec.pkey = be16_to_cpu(priv->pkey);463464 comp_mask =465 IB_SA_MCMEMBER_REC_MGID |···648649 rec.mgid = mcast->mcmember.mgid;650 rec.port_gid = priv->local_gid;651- rec.pkey = be16_to_cpu(priv->pkey);652653 /* Remove ourselves from the multicast group */654 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.4+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.5 *6 * This software is available to you under a choice of one of two7 * licenses. You may choose to be licensed under the terms of the GNU···357358 rec.mgid = mcast->mcmember.mgid;359 rec.port_gid = priv->local_gid;360+ rec.pkey = cpu_to_be16(priv->pkey);361362 ret = ib_sa_mcmember_rec_set(priv->ca, priv->port, &rec,363 IB_SA_MCMEMBER_REC_MGID |···457458 rec.mgid = mcast->mcmember.mgid;459 rec.port_gid = priv->local_gid;460+ rec.pkey = cpu_to_be16(priv->pkey);461462 comp_mask =463 IB_SA_MCMEMBER_REC_MGID |···646647 rec.mgid = mcast->mcmember.mgid;648 rec.port_gid = priv->local_gid;649+ rec.pkey = cpu_to_be16(priv->pkey);650651 /* Remove ourselves from the multicast group */652 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
+2-1
drivers/infiniband/ulp/ipoib/ipoib_verbs.c
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.03 *4 * This software is available to you under a choice of one of two5 * licenses. You may choose to be licensed under the terms of the GNU···33 * $Id: ipoib_verbs.c 1349 2004-12-16 21:09:43Z roland $34 */3536-#include <ib_cache.h>3738#include "ipoib.h"39
···1/*2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.3+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.4 *5 * This software is available to you under a choice of one of two6 * licenses. You may choose to be licensed under the terms of the GNU···32 * $Id: ipoib_verbs.c 1349 2004-12-16 21:09:43Z roland $33 */3435+#include <rdma/ib_cache.h>3637#include "ipoib.h"38