···11/*22- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.33- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.44- * Copyright (c) 2004 Intel Corporation. All rights reserved.55- * Copyright (c) 2004 Topspin Corporation. All rights reserved.66- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.22+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.33+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.44+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.55+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.66+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.77+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.78 *89 * This software is available to you under a choice of one of two910 * licenses. You may choose to be licensed under the terms of the GNU···41404241#include <asm/bug.h>43424444-#include <ib_smi.h>4343+#include <rdma/ib_smi.h>45444645#include "smi.h"4746#include "agent_priv.h"
+5-5
drivers/infiniband/core/agent_priv.h
···11/*22- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.33- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.44- * Copyright (c) 2004 Intel Corporation. All rights reserved.55- * Copyright (c) 2004 Topspin Corporation. All rights reserved.66- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.22+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.33+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.44+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.55+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.66+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.77 *88 * This software is available to you under a choice of one of two99 * licenses. You may choose to be licensed under the terms of the GNU
+4-2
drivers/infiniband/core/cache.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Intel Corporation. All rights reserved.44+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.55+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.36 *47 * This software is available to you under a choice of one of two58 * licenses. You may choose to be licensed under the terms of the GNU···3532 * $Id: cache.c 1349 2004-12-16 21:09:43Z roland $3633 */37343838-#include <linux/version.h>3935#include <linux/module.h>4036#include <linux/errno.h>4137#include <linux/slab.h>42384343-#include <ib_cache.h>3939+#include <rdma/ib_cache.h>44404541#include "core_priv.h"4642
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU
···11/*22 * Copyright (c) 2004 Topspin Corporation. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···3332 * $Id: packer.c 1349 2004-12-16 21:09:43Z roland $3433 */35343636-#include <ib_pack.h>3535+#include <rdma/ib_pack.h>37363837static u64 value_read(int offset, int size, void *structure)3938{
+3-3
drivers/infiniband/core/sa_query.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33- * Copyright (c) 2005 Voltaire, Inc. All rights reserved.33+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.44 *55 * This software is available to you under a choice of one of two66 * licenses. You may choose to be licensed under the terms of the GNU···4444#include <linux/kref.h>4545#include <linux/idr.h>46464747-#include <ib_pack.h>4848-#include <ib_sa.h>4747+#include <rdma/ib_pack.h>4848+#include <rdma/ib_sa.h>49495050MODULE_AUTHOR("Roland Dreier");5151MODULE_DESCRIPTION("InfiniBand subnet administration query support");
+7-6
drivers/infiniband/core/smi.c
···11/*22- * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.33- * Copyright (c) 2004 Infinicon Corporation. All rights reserved.44- * Copyright (c) 2004 Intel Corporation. All rights reserved.55- * Copyright (c) 2004 Topspin Corporation. All rights reserved.66- * Copyright (c) 2004 Voltaire Corporation. All rights reserved.22+ * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved.33+ * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved.44+ * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.55+ * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved.66+ * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.77+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.78 *89 * This software is available to you under a choice of one of two910 * licenses. You may choose to be licensed under the terms of the GNU···3736 * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $3837 */39384040-#include <ib_smi.h>3939+#include <rdma/ib_smi.h>4140#include "smi.h"42414342/*
+21-19
drivers/infiniband/core/sysfs.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.44+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···36343735#include "core_priv.h"38363939-#include <ib_mad.h>3737+#include <rdma/ib_mad.h>40384139struct ib_port {4240 struct kobject kobj;···255253 return ret;256254257255 return sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",258258- be16_to_cpu(((u16 *) gid.raw)[0]),259259- be16_to_cpu(((u16 *) gid.raw)[1]),260260- be16_to_cpu(((u16 *) gid.raw)[2]),261261- be16_to_cpu(((u16 *) gid.raw)[3]),262262- be16_to_cpu(((u16 *) gid.raw)[4]),263263- be16_to_cpu(((u16 *) gid.raw)[5]),264264- be16_to_cpu(((u16 *) gid.raw)[6]),265265- be16_to_cpu(((u16 *) gid.raw)[7]));256256+ be16_to_cpu(((__be16 *) gid.raw)[0]),257257+ be16_to_cpu(((__be16 *) gid.raw)[1]),258258+ be16_to_cpu(((__be16 *) gid.raw)[2]),259259+ be16_to_cpu(((__be16 *) gid.raw)[3]),260260+ be16_to_cpu(((__be16 *) gid.raw)[4]),261261+ be16_to_cpu(((__be16 *) gid.raw)[5]),262262+ be16_to_cpu(((__be16 *) gid.raw)[6]),263263+ be16_to_cpu(((__be16 *) gid.raw)[7]));266264}267265268266static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,···334332 break;335333 case 16:336334 ret = sprintf(buf, "%u\n",337337- be16_to_cpup((u16 *)(out_mad->data + 40 + offset / 8)));335335+ be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8)));338336 break;339337 case 32:340338 ret = sprintf(buf, "%u\n",341341- be32_to_cpup((u32 *)(out_mad->data + 40 + offset / 8)));339339+ be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8)));342340 break;343341 default:344342 ret = 0;···600598 return ret;601599602600 return sprintf(buf, "%04x:%04x:%04x:%04x\n",603603- be16_to_cpu(((u16 *) &attr.sys_image_guid)[0]),604604- be16_to_cpu(((u16 *) &attr.sys_image_guid)[1]),605605- be16_to_cpu(((u16 *) &attr.sys_image_guid)[2]),606606- be16_to_cpu(((u16 *) &attr.sys_image_guid)[3]));601601+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[0]),602602+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[1]),603603+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[2]),604604+ be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));607605}608606609607static ssize_t show_node_guid(struct class_device *cdev, char *buf)···617615 return ret;618616619617 return sprintf(buf, "%04x:%04x:%04x:%04x\n",620620- be16_to_cpu(((u16 *) &attr.node_guid)[0]),621621- be16_to_cpu(((u16 *) &attr.node_guid)[1]),622622- be16_to_cpu(((u16 *) &attr.node_guid)[2]),623623- be16_to_cpu(((u16 *) &attr.node_guid)[3]));618618+ be16_to_cpu(((__be16 *) &attr.node_guid)[0]),619619+ be16_to_cpu(((__be16 *) &attr.node_guid)[1]),620620+ be16_to_cpu(((__be16 *) &attr.node_guid)[2]),621621+ be16_to_cpu(((__be16 *) &attr.node_guid)[3]));624622}625623626624static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
+157-307
drivers/infiniband/core/ucm.c
···11/*22 * Copyright (c) 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Intel Corporation. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···7473static struct idr ctx_id_table;7574static int ctx_id_rover = 0;76757777-static struct ib_ucm_context *ib_ucm_ctx_get(int id)7676+static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)7877{7978 struct ib_ucm_context *ctx;80798180 down(&ctx_id_mutex);8281 ctx = idr_find(&ctx_id_table, id);8383- if (ctx)8484- ctx->ref++;8282+ if (!ctx)8383+ ctx = ERR_PTR(-ENOENT);8484+ else if (ctx->file != file)8585+ ctx = ERR_PTR(-EINVAL);8686+ else8787+ atomic_inc(&ctx->ref);8588 up(&ctx_id_mutex);86898790 return ctx;···93889489static void ib_ucm_ctx_put(struct ib_ucm_context *ctx)9590{9191+ if (atomic_dec_and_test(&ctx->ref))9292+ wake_up(&ctx->wait);9393+}9494+9595+static ssize_t ib_ucm_destroy_ctx(struct ib_ucm_file *file, int id)9696+{9797+ struct ib_ucm_context *ctx;9698 struct ib_ucm_event *uevent;979998100 down(&ctx_id_mutex);9999-100100- ctx->ref--;101101- if (!ctx->ref)101101+ ctx = idr_find(&ctx_id_table, id);102102+ if (!ctx)103103+ ctx = ERR_PTR(-ENOENT);104104+ else if (ctx->file != file)105105+ ctx = ERR_PTR(-EINVAL);106106+ else102107 idr_remove(&ctx_id_table, ctx->id);103103-104108 up(&ctx_id_mutex);105109106106- if (ctx->ref)107107- return;110110+ if (IS_ERR(ctx))111111+ return PTR_ERR(ctx);108112109109- down(&ctx->file->mutex);113113+ atomic_dec(&ctx->ref);114114+ wait_event(ctx->wait, !atomic_read(&ctx->ref));110115116116+ /* No new events will be generated after destroying the cm_id. */117117+ if (!IS_ERR(ctx->cm_id))118118+ ib_destroy_cm_id(ctx->cm_id);119119+120120+ /* Cleanup events not yet reported to the user. */121121+ down(&file->mutex);111122 list_del(&ctx->file_list);112123 while (!list_empty(&ctx->events)) {113124···138117139118 kfree(uevent);140119 }120120+ up(&file->mutex);141121142142- up(&ctx->file->mutex);143143-144144- ucm_dbg("Destroyed CM ID <%d>\n", ctx->id);145145-146146- ib_destroy_cm_id(ctx->cm_id);147122 kfree(ctx);123123+ return 0;148124}149125150126static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)···153135 if (!ctx)154136 return NULL;155137156156- ctx->ref = 1; /* user reference */138138+ atomic_set(&ctx->ref, 1);139139+ init_waitqueue_head(&ctx->wait);157140 ctx->file = file;158141159142 INIT_LIST_HEAD(&ctx->events);160160- init_MUTEX(&ctx->mutex);161143162144 list_add_tail(&ctx->file_list, &file->ctxs);163145···195177 if (!kpath || !upath)196178 return;197179198198- memcpy(upath->dgid, kpath->dgid.raw, sizeof(union ib_gid));199199- memcpy(upath->sgid, kpath->sgid.raw, sizeof(union ib_gid));180180+ memcpy(upath->dgid, kpath->dgid.raw, sizeof *upath->dgid);181181+ memcpy(upath->sgid, kpath->sgid.raw, sizeof *upath->sgid);200182201183 upath->dlid = kpath->dlid;202184 upath->slid = kpath->slid;···219201 kpath->packet_life_time_selector;220202}221203222222-static void ib_ucm_event_req_get(struct ib_ucm_req_event_resp *ureq,204204+static void ib_ucm_event_req_get(struct ib_ucm_context *ctx,205205+ struct ib_ucm_req_event_resp *ureq,223206 struct ib_cm_req_event_param *kreq)224207{225225- ureq->listen_id = (long)kreq->listen_id->context;208208+ ureq->listen_id = ctx->id;226209227210 ureq->remote_ca_guid = kreq->remote_ca_guid;228211 ureq->remote_qkey = kreq->remote_qkey;···259240 urep->srq = krep->srq;260241}261242262262-static void ib_ucm_event_rej_get(struct ib_ucm_rej_event_resp *urej,263263- struct ib_cm_rej_event_param *krej)264264-{265265- urej->reason = krej->reason;266266-}267267-268268-static void ib_ucm_event_mra_get(struct ib_ucm_mra_event_resp *umra,269269- struct ib_cm_mra_event_param *kmra)270270-{271271- umra->timeout = kmra->service_timeout;272272-}273273-274274-static void ib_ucm_event_lap_get(struct ib_ucm_lap_event_resp *ulap,275275- struct ib_cm_lap_event_param *klap)276276-{277277- ib_ucm_event_path_get(&ulap->path, klap->alternate_path);278278-}279279-280280-static void ib_ucm_event_apr_get(struct ib_ucm_apr_event_resp *uapr,281281- struct ib_cm_apr_event_param *kapr)282282-{283283- uapr->status = kapr->ap_status;284284-}285285-286286-static void ib_ucm_event_sidr_req_get(struct ib_ucm_sidr_req_event_resp *ureq,243243+static void ib_ucm_event_sidr_req_get(struct ib_ucm_context *ctx,244244+ struct ib_ucm_sidr_req_event_resp *ureq,287245 struct ib_cm_sidr_req_event_param *kreq)288246{289289- ureq->listen_id = (long)kreq->listen_id->context;247247+ ureq->listen_id = ctx->id;290248 ureq->pkey = kreq->pkey;291249}292250···275279 urep->qpn = krep->qpn;276280};277281278278-static int ib_ucm_event_process(struct ib_cm_event *evt,282282+static int ib_ucm_event_process(struct ib_ucm_context *ctx,283283+ struct ib_cm_event *evt,279284 struct ib_ucm_event *uvt)280285{281286 void *info = NULL;282282- int result;283287284288 switch (evt->event) {285289 case IB_CM_REQ_RECEIVED:286286- ib_ucm_event_req_get(&uvt->resp.u.req_resp,290290+ ib_ucm_event_req_get(ctx, &uvt->resp.u.req_resp,287291 &evt->param.req_rcvd);288292 uvt->data_len = IB_CM_REQ_PRIVATE_DATA_SIZE;289289- uvt->resp.present |= (evt->param.req_rcvd.primary_path ?290290- IB_UCM_PRES_PRIMARY : 0);293293+ uvt->resp.present = IB_UCM_PRES_PRIMARY;291294 uvt->resp.present |= (evt->param.req_rcvd.alternate_path ?292295 IB_UCM_PRES_ALTERNATE : 0);293296 break;···294299 ib_ucm_event_rep_get(&uvt->resp.u.rep_resp,295300 &evt->param.rep_rcvd);296301 uvt->data_len = IB_CM_REP_PRIVATE_DATA_SIZE;297297-298302 break;299303 case IB_CM_RTU_RECEIVED:300304 uvt->data_len = IB_CM_RTU_PRIVATE_DATA_SIZE;301305 uvt->resp.u.send_status = evt->param.send_status;302302-303306 break;304307 case IB_CM_DREQ_RECEIVED:305308 uvt->data_len = IB_CM_DREQ_PRIVATE_DATA_SIZE;306309 uvt->resp.u.send_status = evt->param.send_status;307307-308310 break;309311 case IB_CM_DREP_RECEIVED:310312 uvt->data_len = IB_CM_DREP_PRIVATE_DATA_SIZE;311313 uvt->resp.u.send_status = evt->param.send_status;312312-313314 break;314315 case IB_CM_MRA_RECEIVED:315315- ib_ucm_event_mra_get(&uvt->resp.u.mra_resp,316316- &evt->param.mra_rcvd);316316+ uvt->resp.u.mra_resp.timeout =317317+ evt->param.mra_rcvd.service_timeout;317318 uvt->data_len = IB_CM_MRA_PRIVATE_DATA_SIZE;318318-319319 break;320320 case IB_CM_REJ_RECEIVED:321321- ib_ucm_event_rej_get(&uvt->resp.u.rej_resp,322322- &evt->param.rej_rcvd);321321+ uvt->resp.u.rej_resp.reason = evt->param.rej_rcvd.reason;323322 uvt->data_len = IB_CM_REJ_PRIVATE_DATA_SIZE;324323 uvt->info_len = evt->param.rej_rcvd.ari_length;325324 info = evt->param.rej_rcvd.ari;326326-327325 break;328326 case IB_CM_LAP_RECEIVED:329329- ib_ucm_event_lap_get(&uvt->resp.u.lap_resp,330330- &evt->param.lap_rcvd);327327+ ib_ucm_event_path_get(&uvt->resp.u.lap_resp.path,328328+ evt->param.lap_rcvd.alternate_path);331329 uvt->data_len = IB_CM_LAP_PRIVATE_DATA_SIZE;332332- uvt->resp.present |= (evt->param.lap_rcvd.alternate_path ?333333- IB_UCM_PRES_ALTERNATE : 0);330330+ uvt->resp.present = IB_UCM_PRES_ALTERNATE;334331 break;335332 case IB_CM_APR_RECEIVED:336336- ib_ucm_event_apr_get(&uvt->resp.u.apr_resp,337337- &evt->param.apr_rcvd);333333+ uvt->resp.u.apr_resp.status = evt->param.apr_rcvd.ap_status;338334 uvt->data_len = IB_CM_APR_PRIVATE_DATA_SIZE;339335 uvt->info_len = evt->param.apr_rcvd.info_len;340336 info = evt->param.apr_rcvd.apr_info;341341-342337 break;343338 case IB_CM_SIDR_REQ_RECEIVED:344344- ib_ucm_event_sidr_req_get(&uvt->resp.u.sidr_req_resp,339339+ ib_ucm_event_sidr_req_get(ctx, &uvt->resp.u.sidr_req_resp,345340 &evt->param.sidr_req_rcvd);346341 uvt->data_len = IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE;347347-348342 break;349343 case IB_CM_SIDR_REP_RECEIVED:350344 ib_ucm_event_sidr_rep_get(&uvt->resp.u.sidr_rep_resp,···341357 uvt->data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE;342358 uvt->info_len = evt->param.sidr_rep_rcvd.info_len;343359 info = evt->param.sidr_rep_rcvd.info;344344-345360 break;346361 default:347362 uvt->resp.u.send_status = evt->param.send_status;348348-349363 break;350364 }351365352352- if (uvt->data_len && evt->private_data) {353353-366366+ if (uvt->data_len) {354367 uvt->data = kmalloc(uvt->data_len, GFP_KERNEL);355355- if (!uvt->data) {356356- result = -ENOMEM;357357- goto error;358358- }368368+ if (!uvt->data)369369+ goto err1;359370360371 memcpy(uvt->data, evt->private_data, uvt->data_len);361372 uvt->resp.present |= IB_UCM_PRES_DATA;362373 }363374364364- if (uvt->info_len && info) {365365-375375+ if (uvt->info_len) {366376 uvt->info = kmalloc(uvt->info_len, GFP_KERNEL);367367- if (!uvt->info) {368368- result = -ENOMEM;369369- goto error;370370- }377377+ if (!uvt->info)378378+ goto err2;371379372380 memcpy(uvt->info, info, uvt->info_len);373381 uvt->resp.present |= IB_UCM_PRES_INFO;374382 }375375-376383 return 0;377377-error:378378- kfree(uvt->info);384384+385385+err2:379386 kfree(uvt->data);380380- return result;387387+err1:388388+ return -ENOMEM;381389}382390383391static int ib_ucm_event_handler(struct ib_cm_id *cm_id,···379403 struct ib_ucm_context *ctx;380404 int result = 0;381405 int id;382382- /*383383- * lookup correct context based on event type.384384- */385385- switch (event->event) {386386- case IB_CM_REQ_RECEIVED:387387- id = (long)event->param.req_rcvd.listen_id->context;388388- break;389389- case IB_CM_SIDR_REQ_RECEIVED:390390- id = (long)event->param.sidr_req_rcvd.listen_id->context;391391- break;392392- default:393393- id = (long)cm_id->context;394394- break;395395- }396406397397- ucm_dbg("Event. CM ID <%d> event <%d>\n", id, event->event);398398-399399- ctx = ib_ucm_ctx_get(id);400400- if (!ctx)401401- return -ENOENT;407407+ ctx = cm_id->context;402408403409 if (event->event == IB_CM_REQ_RECEIVED ||404410 event->event == IB_CM_SIDR_REQ_RECEIVED)405411 id = IB_UCM_CM_ID_INVALID;412412+ else413413+ id = ctx->id;406414407415 uevent = kmalloc(sizeof(*uevent), GFP_KERNEL);408408- if (!uevent) {409409- result = -ENOMEM;410410- goto done;411411- }416416+ if (!uevent)417417+ goto err1;412418413419 memset(uevent, 0, sizeof(*uevent));414414-415420 uevent->resp.id = id;416421 uevent->resp.event = event->event;417422418418- result = ib_ucm_event_process(event, uevent);423423+ result = ib_ucm_event_process(ctx, event, uevent);419424 if (result)420420- goto done;425425+ goto err2;421426422427 uevent->ctx = ctx;423423- uevent->cm_id = ((event->event == IB_CM_REQ_RECEIVED ||424424- event->event == IB_CM_SIDR_REQ_RECEIVED ) ?425425- cm_id : NULL);428428+ uevent->cm_id = (id == IB_UCM_CM_ID_INVALID) ? cm_id : NULL;426429427430 down(&ctx->file->mutex);428428-429431 list_add_tail(&uevent->file_list, &ctx->file->events);430432 list_add_tail(&uevent->ctx_list, &ctx->events);431431-432433 wake_up_interruptible(&ctx->file->poll_wait);433433-434434 up(&ctx->file->mutex);435435-done:436436- ctx->error = result;437437- ib_ucm_ctx_put(ctx); /* func reference */438438- return result;435435+ return 0;436436+437437+err2:438438+ kfree(uevent);439439+err1:440440+ /* Destroy new cm_id's */441441+ return (id == IB_UCM_CM_ID_INVALID);439442}440443441444static ssize_t ib_ucm_event(struct ib_ucm_file *file,···472517 goto done;473518 }474519475475- ctx->cm_id = uevent->cm_id;476476- ctx->cm_id->cm_handler = ib_ucm_event_handler;477477- ctx->cm_id->context = (void *)(unsigned long)ctx->id;520520+ ctx->cm_id = uevent->cm_id;521521+ ctx->cm_id->context = ctx;478522479523 uevent->resp.id = ctx->id;480524···539585 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))540586 return -EFAULT;541587588588+ down(&file->mutex);542589 ctx = ib_ucm_ctx_alloc(file);590590+ up(&file->mutex);543591 if (!ctx)544592 return -ENOMEM;545593546546- ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler,547547- (void *)(unsigned long)ctx->id);548548- if (!ctx->cm_id) {549549- result = -ENOMEM;550550- goto err_cm;594594+ ctx->cm_id = ib_create_cm_id(ib_ucm_event_handler, ctx);595595+ if (IS_ERR(ctx->cm_id)) {596596+ result = PTR_ERR(ctx->cm_id);597597+ goto err;551598 }552599553600 resp.id = ctx->id;554601 if (copy_to_user((void __user *)(unsigned long)cmd.response,555602 &resp, sizeof(resp))) {556603 result = -EFAULT;557557- goto err_ret;604604+ goto err;558605 }559606560607 return 0;561561-err_ret:562562- ib_destroy_cm_id(ctx->cm_id);563563-err_cm:564564- ib_ucm_ctx_put(ctx); /* user reference */565608609609+err:610610+ ib_ucm_destroy_ctx(file, ctx->id);566611 return result;567612}568613···570617 int in_len, int out_len)571618{572619 struct ib_ucm_destroy_id cmd;573573- struct ib_ucm_context *ctx;574620575621 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))576622 return -EFAULT;577623578578- ctx = ib_ucm_ctx_get(cmd.id);579579- if (!ctx)580580- return -ENOENT;581581-582582- ib_ucm_ctx_put(ctx); /* user reference */583583- ib_ucm_ctx_put(ctx); /* func reference */584584-585585- return 0;624624+ return ib_ucm_destroy_ctx(file, cmd.id);586625}587626588627static ssize_t ib_ucm_attr_id(struct ib_ucm_file *file,···592647 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))593648 return -EFAULT;594649595595- ctx = ib_ucm_ctx_get(cmd.id);596596- if (!ctx)597597- return -ENOENT;598598-599599- down(&ctx->file->mutex);600600- if (ctx->file != file) {601601- result = -EINVAL;602602- goto done;603603- }650650+ ctx = ib_ucm_ctx_get(file, cmd.id);651651+ if (IS_ERR(ctx))652652+ return PTR_ERR(ctx);604653605654 resp.service_id = ctx->cm_id->service_id;606655 resp.service_mask = ctx->cm_id->service_mask;···605666 &resp, sizeof(resp)))606667 result = -EFAULT;607668608608-done:609609- up(&ctx->file->mutex);610610- ib_ucm_ctx_put(ctx); /* func reference */669669+ ib_ucm_ctx_put(ctx);611670 return result;612671}613672···620683 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))621684 return -EFAULT;622685623623- ctx = ib_ucm_ctx_get(cmd.id);624624- if (!ctx)625625- return -ENOENT;686686+ ctx = ib_ucm_ctx_get(file, cmd.id);687687+ if (IS_ERR(ctx))688688+ return PTR_ERR(ctx);626689627627- down(&ctx->file->mutex);628628- if (ctx->file != file)629629- result = -EINVAL;630630- else631631- result = ib_cm_listen(ctx->cm_id, cmd.service_id,632632- cmd.service_mask);633633-634634- up(&ctx->file->mutex);635635- ib_ucm_ctx_put(ctx); /* func reference */690690+ result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask);691691+ ib_ucm_ctx_put(ctx);636692 return result;637693}638694···640710 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))641711 return -EFAULT;642712643643- ctx = ib_ucm_ctx_get(cmd.id);644644- if (!ctx)645645- return -ENOENT;713713+ ctx = ib_ucm_ctx_get(file, cmd.id);714714+ if (IS_ERR(ctx))715715+ return PTR_ERR(ctx);646716647647- down(&ctx->file->mutex);648648- if (ctx->file != file)649649- result = -EINVAL;650650- else651651- result = ib_cm_establish(ctx->cm_id);652652-653653- up(&ctx->file->mutex);654654- ib_ucm_ctx_put(ctx); /* func reference */717717+ result = ib_cm_establish(ctx->cm_id);718718+ ib_ucm_ctx_put(ctx);655719 return result;656720}657721···692768 return -EFAULT;693769 }694770695695- memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof(union ib_gid));696696- memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof(union ib_gid));771771+ memcpy(sa_path->dgid.raw, ucm_path.dgid, sizeof sa_path->dgid);772772+ memcpy(sa_path->sgid.raw, ucm_path.sgid, sizeof sa_path->sgid);697773698774 sa_path->dlid = ucm_path.dlid;699775 sa_path->slid = ucm_path.slid;···763839 param.max_cm_retries = cmd.max_cm_retries;764840 param.srq = cmd.srq;765841766766- ctx = ib_ucm_ctx_get(cmd.id);767767- if (!ctx) {768768- result = -ENOENT;769769- goto done;770770- }771771-772772- down(&ctx->file->mutex);773773- if (ctx->file != file)774774- result = -EINVAL;775775- else842842+ ctx = ib_ucm_ctx_get(file, cmd.id);843843+ if (!IS_ERR(ctx)) {776844 result = ib_send_cm_req(ctx->cm_id, ¶m);845845+ ib_ucm_ctx_put(ctx);846846+ } else847847+ result = PTR_ERR(ctx);777848778778- up(&ctx->file->mutex);779779- ib_ucm_ctx_put(ctx); /* func reference */780849done:781850 kfree(param.private_data);782851 kfree(param.primary_path);783852 kfree(param.alternate_path);784784-785853 return result;786854}787855···806890 param.rnr_retry_count = cmd.rnr_retry_count;807891 param.srq = cmd.srq;808892809809- ctx = ib_ucm_ctx_get(cmd.id);810810- if (!ctx) {811811- result = -ENOENT;812812- goto done;813813- }814814-815815- down(&ctx->file->mutex);816816- if (ctx->file != file)817817- result = -EINVAL;818818- else893893+ ctx = ib_ucm_ctx_get(file, cmd.id);894894+ if (!IS_ERR(ctx)) {819895 result = ib_send_cm_rep(ctx->cm_id, ¶m);896896+ ib_ucm_ctx_put(ctx);897897+ } else898898+ result = PTR_ERR(ctx);820899821821- up(&ctx->file->mutex);822822- ib_ucm_ctx_put(ctx); /* func reference */823823-done:824900 kfree(param.private_data);825825-826901 return result;827902}828903···835928 if (result)836929 return result;837930838838- ctx = ib_ucm_ctx_get(cmd.id);839839- if (!ctx) {840840- result = -ENOENT;841841- goto done;842842- }843843-844844- down(&ctx->file->mutex);845845- if (ctx->file != file)846846- result = -EINVAL;847847- else931931+ ctx = ib_ucm_ctx_get(file, cmd.id);932932+ if (!IS_ERR(ctx)) {848933 result = func(ctx->cm_id, private_data, cmd.len);934934+ ib_ucm_ctx_put(ctx);935935+ } else936936+ result = PTR_ERR(ctx);849937850850- up(&ctx->file->mutex);851851- ib_ucm_ctx_put(ctx); /* func reference */852852-done:853938 kfree(private_data);854854-855939 return result;856940}857941···893995 if (result)894996 goto done;895997896896- ctx = ib_ucm_ctx_get(cmd.id);897897- if (!ctx) {898898- result = -ENOENT;899899- goto done;900900- }901901-902902- down(&ctx->file->mutex);903903- if (ctx->file != file)904904- result = -EINVAL;905905- else906906- result = func(ctx->cm_id, cmd.status,907907- info, cmd.info_len,998998+ ctx = ib_ucm_ctx_get(file, cmd.id);999999+ if (!IS_ERR(ctx)) {10001000+ result = func(ctx->cm_id, cmd.status, info, cmd.info_len,9081001 data, cmd.data_len);10021002+ ib_ucm_ctx_put(ctx);10031003+ } else10041004+ result = PTR_ERR(ctx);9091005910910- up(&ctx->file->mutex);911911- ib_ucm_ctx_put(ctx); /* func reference */9121006done:9131007 kfree(data);9141008 kfree(info);915915-9161009 return result;9171010}9181011···9371048 if (result)9381049 return result;9391050940940- ctx = ib_ucm_ctx_get(cmd.id);941941- if (!ctx) {942942- result = -ENOENT;943943- goto done;944944- }10511051+ ctx = ib_ucm_ctx_get(file, cmd.id);10521052+ if (!IS_ERR(ctx)) {10531053+ result = ib_send_cm_mra(ctx->cm_id, cmd.timeout, data, cmd.len);10541054+ ib_ucm_ctx_put(ctx);10551055+ } else10561056+ result = PTR_ERR(ctx);9451057946946- down(&ctx->file->mutex);947947- if (ctx->file != file)948948- result = -EINVAL;949949- else950950- result = ib_send_cm_mra(ctx->cm_id, cmd.timeout,951951- data, cmd.len);952952-953953- up(&ctx->file->mutex);954954- ib_ucm_ctx_put(ctx); /* func reference */955955-done:9561058 kfree(data);957957-9581059 return result;9591060}9601061···9691090 if (result)9701091 goto done;9711092972972- ctx = ib_ucm_ctx_get(cmd.id);973973- if (!ctx) {974974- result = -ENOENT;975975- goto done;976976- }977977-978978- down(&ctx->file->mutex);979979- if (ctx->file != file)980980- result = -EINVAL;981981- else10931093+ ctx = ib_ucm_ctx_get(file, cmd.id);10941094+ if (!IS_ERR(ctx)) {9821095 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len);10961096+ ib_ucm_ctx_put(ctx);10971097+ } else10981098+ result = PTR_ERR(ctx);9831099984984- up(&ctx->file->mutex);985985- ib_ucm_ctx_put(ctx); /* func reference */9861100done:9871101 kfree(data);9881102 kfree(path);989989-9901103 return result;9911104}9921105···10111140 param.max_cm_retries = cmd.max_cm_retries;10121141 param.pkey = cmd.pkey;1013114210141014- ctx = ib_ucm_ctx_get(cmd.id);10151015- if (!ctx) {10161016- result = -ENOENT;10171017- goto done;10181018- }10191019-10201020- down(&ctx->file->mutex);10211021- if (ctx->file != file)10221022- result = -EINVAL;10231023- else11431143+ ctx = ib_ucm_ctx_get(file, cmd.id);11441144+ if (!IS_ERR(ctx)) {10241145 result = ib_send_cm_sidr_req(ctx->cm_id, ¶m);11461146+ ib_ucm_ctx_put(ctx);11471147+ } else11481148+ result = PTR_ERR(ctx);1025114910261026- up(&ctx->file->mutex);10271027- ib_ucm_ctx_put(ctx); /* func reference */10281150done:10291151 kfree(param.private_data);10301152 kfree(param.path);10311031-10321153 return result;10331154}10341155···10471184 if (result)10481185 goto done;1049118610501050- param.qp_num = cmd.qpn;10511051- param.qkey = cmd.qkey;10521052- param.status = cmd.status;10531053- param.info_length = cmd.info_len;10541054- param.private_data_len = cmd.data_len;11871187+ param.qp_num = cmd.qpn;11881188+ param.qkey = cmd.qkey;11891189+ param.status = cmd.status;11901190+ param.info_length = cmd.info_len;11911191+ param.private_data_len = cmd.data_len;1055119210561056- ctx = ib_ucm_ctx_get(cmd.id);10571057- if (!ctx) {10581058- result = -ENOENT;10591059- goto done;10601060- }10611061-10621062- down(&ctx->file->mutex);10631063- if (ctx->file != file)10641064- result = -EINVAL;10651065- else11931193+ ctx = ib_ucm_ctx_get(file, cmd.id);11941194+ if (!IS_ERR(ctx)) {10661195 result = ib_send_cm_sidr_rep(ctx->cm_id, ¶m);11961196+ ib_ucm_ctx_put(ctx);11971197+ } else11981198+ result = PTR_ERR(ctx);1067119910681068- up(&ctx->file->mutex);10691069- ib_ucm_ctx_put(ctx); /* func reference */10701200done:10711201 kfree(param.private_data);10721202 kfree(param.info);10731073-10741203 return result;10751204}10761205···11601305 struct ib_ucm_context *ctx;1161130611621307 down(&file->mutex);11631163-11641308 while (!list_empty(&file->ctxs)) {1165130911661310 ctx = list_entry(file->ctxs.next,11671311 struct ib_ucm_context, file_list);1168131211691169- up(&ctx->file->mutex);11701170- ib_ucm_ctx_put(ctx); /* user reference */13131313+ up(&file->mutex);13141314+ ib_ucm_destroy_ctx(file, ctx->id);11711315 down(&file->mutex);11721316 }11731173-11741317 up(&file->mutex);11751175-11761318 kfree(file);11771177-11781178- ucm_dbg("Deleted struct\n");11791319 return 0;11801320}11811321
+5-8
drivers/infiniband/core/ucm.h
···4040#include <linux/cdev.h>4141#include <linux/idr.h>42424343-#include <ib_cm.h>4444-#include <ib_user_cm.h>4343+#include <rdma/ib_cm.h>4444+#include <rdma/ib_user_cm.h>45454646#define IB_UCM_CM_ID_INVALID 0xffffffff47474848struct ib_ucm_file {4949 struct semaphore mutex;5050 struct file *filp;5151- /*5252- * list of pending events5353- */5151+5452 struct list_head ctxs; /* list of active connections */5553 struct list_head events; /* list of pending events */5654 wait_queue_head_t poll_wait;···56585759struct ib_ucm_context {5860 int id;5959- int ref;6060- int error;6161+ wait_queue_head_t wait;6262+ atomic_t ref;61636264 struct ib_ucm_file *file;6365 struct ib_cm_id *cm_id;6464- struct semaphore mutex;65666667 struct list_head events; /* list of pending events. */6768 struct list_head file_list; /* member in file ctx list */
+6-5
drivers/infiniband/core/ud_header.c
···11/*22 * Copyright (c) 2004 Topspin Corporation. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···35343635#include <linux/errno.h>37363838-#include <ib_pack.h>3737+#include <rdma/ib_pack.h>39384039#define STRUCT_FIELD(header, field) \4140 .struct_offset_bytes = offsetof(struct ib_unpacked_ ## header, field), \···195194 struct ib_ud_header *header)196195{197196 int header_len;197197+ u16 packet_length;198198199199 memset(header, 0, sizeof *header);200200···210208 header->lrh.link_version = 0;211209 header->lrh.link_next_header =212210 grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL;213213- header->lrh.packet_length = (IB_LRH_BYTES +211211+ packet_length = (IB_LRH_BYTES +214212 IB_BTH_BYTES +215213 IB_DETH_BYTES +216214 payload_bytes +···219217220218 header->grh_present = grh_present;221219 if (grh_present) {222222- header->lrh.packet_length += IB_GRH_BYTES / 4;223223-220220+ packet_length += IB_GRH_BYTES / 4;224221 header->grh.ip_version = 6;225222 header->grh.payload_length =226223 cpu_to_be16((IB_BTH_BYTES +···230229 header->grh.next_header = 0x1b;231230 }232231233233- cpu_to_be16s(&header->lrh.packet_length);232232+ header->lrh.packet_length = cpu_to_be16(packet_length);234233235234 if (header->immediate_present)236235 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
+5-5
drivers/infiniband/core/user_mad.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33- * Copyright (c) 2005 Voltaire, Inc. All rights reserved.33+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 44 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.55 *66 * This software is available to you under a choice of one of two···4949#include <asm/uaccess.h>5050#include <asm/semaphore.h>51515252-#include <ib_mad.h>5353-#include <ib_user_mad.h>5252+#include <rdma/ib_mad.h>5353+#include <rdma/ib_user_mad.h>54545555MODULE_AUTHOR("Roland Dreier");5656MODULE_DESCRIPTION("InfiniBand userspace MAD packet access");···271271 struct ib_send_wr *bad_wr;272272 struct ib_rmpp_mad *rmpp_mad;273273 u8 method;274274- u64 *tid;274274+ __be64 *tid;275275 int ret, length, hdr_len, data_len, rmpp_hdr_size;276276 int rmpp_active = 0;277277···316316 if (packet->mad.hdr.grh_present) {317317 ah_attr.ah_flags = IB_AH_GRH;318318 memcpy(ah_attr.grh.dgid.raw, packet->mad.hdr.gid, 16);319319- ah_attr.grh.flow_label = packet->mad.hdr.flow_label;319319+ ah_attr.grh.flow_label = be32_to_cpu(packet->mad.hdr.flow_label);320320 ah_attr.grh.hop_limit = packet->mad.hdr.hop_limit;321321 ah_attr.grh.traffic_class = packet->mad.hdr.traffic_class;322322 }
+9-2
drivers/infiniband/core/uverbs.h
···11/*22 * Copyright (c) 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.55+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.46 *57 * This software is available to you under a choice of one of two68 * licenses. You may choose to be licensed under the terms of the GNU···4543#include <linux/kref.h>4644#include <linux/idr.h>47454848-#include <ib_verbs.h>4949-#include <ib_user_verbs.h>4646+#include <rdma/ib_verbs.h>4747+#include <rdma/ib_user_verbs.h>50485149struct ib_uverbs_device {5250 int devnum;···9997extern struct idr ib_uverbs_ah_idr;10098extern struct idr ib_uverbs_cq_idr;10199extern struct idr ib_uverbs_qp_idr;100100+extern struct idr ib_uverbs_srq_idr;102101103102void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context);104103void ib_uverbs_cq_event_handler(struct ib_event *event, void *context_ptr);105104void ib_uverbs_qp_event_handler(struct ib_event *event, void *context_ptr);105105+void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);106106107107int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,108108 void *addr, size_t size, int write);···133129IB_UVERBS_DECLARE_CMD(destroy_qp);134130IB_UVERBS_DECLARE_CMD(attach_mcast);135131IB_UVERBS_DECLARE_CMD(detach_mcast);132132+IB_UVERBS_DECLARE_CMD(create_srq);133133+IB_UVERBS_DECLARE_CMD(modify_srq);134134+IB_UVERBS_DECLARE_CMD(destroy_srq);136135137136#endif /* UVERBS_H */
···11/*22 * Copyright (c) 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.55+ * Copyright (c) 2005 Voltaire, Inc. All rights reserved.46 *57 * This software is available to you under a choice of one of two68 * licenses. You may choose to be licensed under the terms of the GNU···6967DEFINE_IDR(ib_uverbs_ah_idr);7068DEFINE_IDR(ib_uverbs_cq_idr);7169DEFINE_IDR(ib_uverbs_qp_idr);7070+DEFINE_IDR(ib_uverbs_srq_idr);72717372static spinlock_t map_lock;7473static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);···9491 [IB_USER_VERBS_CMD_DESTROY_QP] = ib_uverbs_destroy_qp,9592 [IB_USER_VERBS_CMD_ATTACH_MCAST] = ib_uverbs_attach_mcast,9693 [IB_USER_VERBS_CMD_DETACH_MCAST] = ib_uverbs_detach_mcast,9494+ [IB_USER_VERBS_CMD_CREATE_SRQ] = ib_uverbs_create_srq,9595+ [IB_USER_VERBS_CMD_MODIFY_SRQ] = ib_uverbs_modify_srq,9696+ [IB_USER_VERBS_CMD_DESTROY_SRQ] = ib_uverbs_destroy_srq,9797};98989999static struct vfsmount *uverbs_event_mnt;···131125 kfree(uobj);132126 }133127134134- /* XXX Free SRQs */128128+ list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) {129129+ struct ib_srq *srq = idr_find(&ib_uverbs_srq_idr, uobj->id);130130+ idr_remove(&ib_uverbs_srq_idr, uobj->id);131131+ ib_destroy_srq(srq);132132+ list_del(&uobj->list);133133+ kfree(uobj);134134+ }135135+135136 /* XXX Free MWs */136137137138 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {···354341{355342 ib_uverbs_async_handler(context_ptr,356343 event->element.qp->uobject->user_handle,344344+ event->event);345345+}346346+347347+void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr)348348+{349349+ ib_uverbs_async_handler(context_ptr,350350+ event->element.srq->uobject->user_handle,357351 event->event);358352}359353
+1
drivers/infiniband/core/uverbs_mem.c
···11/*22 * Copyright (c) 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU
+63-2
drivers/infiniband/core/verbs.c
···44 * Copyright (c) 2004 Intel Corporation. All rights reserved.55 * Copyright (c) 2004 Topspin Corporation. All rights reserved.66 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.77+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.78 * Copyright (c) 2005 Cisco Systems. All rights reserved.89 *910 * This software is available to you under a choice of one of two···4140#include <linux/errno.h>4241#include <linux/err.h>43424444-#include <ib_verbs.h>4545-#include <ib_cache.h>4343+#include <rdma/ib_verbs.h>4444+#include <rdma/ib_cache.h>46454746/* Protection domains */4847···153152 return ret;154153}155154EXPORT_SYMBOL(ib_destroy_ah);155155+156156+/* Shared receive queues */157157+158158+struct ib_srq *ib_create_srq(struct ib_pd *pd,159159+ struct ib_srq_init_attr *srq_init_attr)160160+{161161+ struct ib_srq *srq;162162+163163+ if (!pd->device->create_srq)164164+ return ERR_PTR(-ENOSYS);165165+166166+ srq = pd->device->create_srq(pd, srq_init_attr, NULL);167167+168168+ if (!IS_ERR(srq)) {169169+ srq->device = pd->device;170170+ srq->pd = pd;171171+ srq->uobject = NULL;172172+ srq->event_handler = srq_init_attr->event_handler;173173+ srq->srq_context = srq_init_attr->srq_context;174174+ atomic_inc(&pd->usecnt);175175+ atomic_set(&srq->usecnt, 0);176176+ }177177+178178+ return srq;179179+}180180+EXPORT_SYMBOL(ib_create_srq);181181+182182+int ib_modify_srq(struct ib_srq *srq,183183+ struct ib_srq_attr *srq_attr,184184+ enum ib_srq_attr_mask srq_attr_mask)185185+{186186+ return srq->device->modify_srq(srq, srq_attr, srq_attr_mask);187187+}188188+EXPORT_SYMBOL(ib_modify_srq);189189+190190+int ib_query_srq(struct ib_srq *srq,191191+ struct ib_srq_attr *srq_attr)192192+{193193+ return srq->device->query_srq ?194194+ srq->device->query_srq(srq, srq_attr) : -ENOSYS;195195+}196196+EXPORT_SYMBOL(ib_query_srq);197197+198198+int ib_destroy_srq(struct ib_srq *srq)199199+{200200+ struct ib_pd *pd;201201+ int ret;202202+203203+ if (atomic_read(&srq->usecnt))204204+ return -EBUSY;205205+206206+ pd = srq->pd;207207+208208+ ret = srq->device->destroy_srq(srq);209209+ if (!ret)210210+ atomic_dec(&pd->usecnt);211211+212212+ return ret;213213+}214214+EXPORT_SYMBOL(ib_destroy_srq);156215157216/* Queue pairs */158217
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···3635#ifndef MTHCA_CMD_H3736#define MTHCA_CMD_H38373939-#include <ib_verbs.h>3838+#include <rdma/ib_verbs.h>40394140#define MTHCA_MAILBOX_SIZE 40964241···184183};185184186185struct mthca_adapter {187187- u32 vendor_id;188188- u32 device_id;189189- u32 revision_id;190190- u8 inta_pin;186186+ u32 vendor_id;187187+ u32 device_id;188188+ u32 revision_id;189189+ char board_id[MTHCA_BOARD_ID_LEN];190190+ u8 inta_pin;191191};192192193193struct mthca_init_hca_param {···220218};221219222220struct mthca_init_ib_param {223223- int enable_1x;224224- int enable_4x;221221+ int port_width;225222 int vl_cap;226223 int mtu_cap;227224 u16 gid_cap;···298297 int cq_num, u8 *status);299298int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,300299 int cq_num, u8 *status);300300+int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,301301+ int srq_num, u8 *status);302302+int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,303303+ int srq_num, u8 *status);304304+int mthca_ARM_SRQ(struct mthca_dev *dev, int srq_num, int limit, u8 *status);301305int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,302306 int is_ee, struct mthca_mailbox *mailbox, u32 optmask,303307 u8 *status);
+1
drivers/infiniband/hw/mthca/mthca_config_reg.h
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU
+81-175
drivers/infiniband/hw/mthca/mthca_cq.c
···22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44 * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved.55+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.66+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.57 *68 * This software is available to you under a choice of one of two79 * licenses. You may choose to be licensed under the terms of the GNU···3937#include <linux/init.h>4038#include <linux/hardirq.h>41394242-#include <ib_pack.h>4040+#include <rdma/ib_pack.h>43414442#include "mthca_dev.h"4543#include "mthca_cmd.h"···5755 * Must be packed because start is 64 bits but only aligned to 32 bits.5856 */5957struct mthca_cq_context {6060- u32 flags;6161- u64 start;6262- u32 logsize_usrpage;6363- u32 error_eqn; /* Tavor only */6464- u32 comp_eqn;6565- u32 pd;6666- u32 lkey;6767- u32 last_notified_index;6868- u32 solicit_producer_index;6969- u32 consumer_index;7070- u32 producer_index;7171- u32 cqn;7272- u32 ci_db; /* Arbel only */7373- u32 state_db; /* Arbel only */7474- u32 reserved;5858+ __be32 flags;5959+ __be64 start;6060+ __be32 logsize_usrpage;6161+ __be32 error_eqn; /* Tavor only */6262+ __be32 comp_eqn;6363+ __be32 pd;6464+ __be32 lkey;6565+ __be32 last_notified_index;6666+ __be32 solicit_producer_index;6767+ __be32 consumer_index;6868+ __be32 producer_index;6969+ __be32 cqn;7070+ __be32 ci_db; /* Arbel only */7171+ __be32 state_db; /* Arbel only */7272+ u32 reserved;7573} __attribute__((packed));76747775#define MTHCA_CQ_STATUS_OK ( 0 << 28)···110108};111109112110struct mthca_cqe {113113- u32 my_qpn;114114- u32 my_ee;115115- u32 rqpn;116116- u16 sl_g_mlpath;117117- u16 rlid;118118- u32 imm_etype_pkey_eec;119119- u32 byte_cnt;120120- u32 wqe;121121- u8 opcode;122122- u8 is_send;123123- u8 reserved;124124- u8 owner;111111+ __be32 my_qpn;112112+ __be32 my_ee;113113+ __be32 rqpn;114114+ __be16 sl_g_mlpath;115115+ __be16 rlid;116116+ __be32 imm_etype_pkey_eec;117117+ __be32 byte_cnt;118118+ __be32 wqe;119119+ u8 opcode;120120+ u8 is_send;121121+ u8 reserved;122122+ u8 owner;125123};126124127125struct mthca_err_cqe {128128- u32 my_qpn;129129- u32 reserved1[3];130130- u8 syndrome;131131- u8 reserved2;132132- u16 db_cnt;133133- u32 reserved3;134134- u32 wqe;135135- u8 opcode;136136- u8 reserved4[2];137137- u8 owner;126126+ __be32 my_qpn;127127+ u32 reserved1[3];128128+ u8 syndrome;129129+ u8 reserved2;130130+ __be16 db_cnt;131131+ u32 reserved3;132132+ __be32 wqe;133133+ u8 opcode;134134+ u8 reserved4[2];135135+ u8 owner;138136};139137140138#define MTHCA_CQ_ENTRY_OWNER_SW (0 << 7)···193191static inline void update_cons_index(struct mthca_dev *dev, struct mthca_cq *cq,194192 int incr)195193{196196- u32 doorbell[2];194194+ __be32 doorbell[2];197195198196 if (mthca_is_memfree(dev)) {199197 *cq->set_ci_db = cpu_to_be32(cq->cons_index);···224222 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);225223}226224227227-void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn)225225+void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,226226+ struct mthca_srq *srq)228227{229228 struct mthca_cq *cq;230229 struct mthca_cqe *cqe;···266263 */267264 while (prod_index > cq->cons_index) {268265 cqe = get_cqe(cq, (prod_index - 1) & cq->ibcq.cqe);269269- if (cqe->my_qpn == cpu_to_be32(qpn))266266+ if (cqe->my_qpn == cpu_to_be32(qpn)) {267267+ if (srq)268268+ mthca_free_srq_wqe(srq, be32_to_cpu(cqe->wqe));270269 ++nfreed;270270+ }271271 else if (nfreed)272272 memcpy(get_cqe(cq, (prod_index - 1 + nfreed) &273273 cq->ibcq.cqe),···297291{298292 int err;299293 int dbd;300300- u32 new_wqe;294294+ __be32 new_wqe;301295302296 if (cqe->syndrome == SYNDROME_LOCAL_QP_OP_ERR) {303297 mthca_dbg(dev, "local QP operation err "···371365 break;372366 }373367368368+ /*369369+ * Mem-free HCAs always generate one CQE per WQE, even in the370370+ * error case, so we don't have to check the doorbell count, etc.371371+ */372372+ if (mthca_is_memfree(dev))373373+ return 0;374374+374375 err = mthca_free_err_wqe(dev, qp, is_send, wqe_index, &dbd, &new_wqe);375376 if (err)376377 return err;···386373 * If we're at the end of the WQE chain, or we've used up our387374 * doorbell count, free the CQE. Otherwise just update it for388375 * the next poll operation.389389- *390390- * This does not apply to mem-free HCAs: they don't use the391391- * doorbell count field, and so we should always free the CQE.392376 */393393- if (mthca_is_memfree(dev) ||394394- !(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))377377+ if (!(new_wqe & cpu_to_be32(0x3f)) || (!cqe->db_cnt && dbd))395378 return 0;396379397380 cqe->db_cnt = cpu_to_be16(be16_to_cpu(cqe->db_cnt) - dbd);···459450 >> wq->wqe_shift);460451 entry->wr_id = (*cur_qp)->wrid[wqe_index +461452 (*cur_qp)->rq.max];453453+ } else if ((*cur_qp)->ibqp.srq) {454454+ struct mthca_srq *srq = to_msrq((*cur_qp)->ibqp.srq);455455+ u32 wqe = be32_to_cpu(cqe->wqe);456456+ wq = NULL;457457+ wqe_index = wqe >> srq->wqe_shift;458458+ entry->wr_id = srq->wrid[wqe_index];459459+ mthca_free_srq_wqe(srq, wqe);462460 } else {463461 wq = &(*cur_qp)->rq;464462 wqe_index = be32_to_cpu(cqe->wqe) >> wq->wqe_shift;465463 entry->wr_id = (*cur_qp)->wrid[wqe_index];466464 }467465468468- if (wq->last_comp < wqe_index)469469- wq->tail += wqe_index - wq->last_comp;470470- else471471- wq->tail += wqe_index + wq->max - wq->last_comp;466466+ if (wq) {467467+ if (wq->last_comp < wqe_index)468468+ wq->tail += wqe_index - wq->last_comp;469469+ else470470+ wq->tail += wqe_index + wq->max - wq->last_comp;472471473473- wq->last_comp = wqe_index;474474-475475- if (0)476476- mthca_dbg(dev, "%s completion for QP %06x, index %d (nr %d)\n",477477- is_send ? "Send" : "Receive",478478- (*cur_qp)->qpn, wqe_index, wq->max);472472+ wq->last_comp = wqe_index;473473+ }479474480475 if (is_error) {481476 err = handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send,···597584598585int mthca_tavor_arm_cq(struct ib_cq *cq, enum ib_cq_notify notify)599586{600600- u32 doorbell[2];587587+ __be32 doorbell[2];601588602589 doorbell[0] = cpu_to_be32((notify == IB_CQ_SOLICITED ?603590 MTHCA_TAVOR_CQ_DB_REQ_NOT_SOL :604591 MTHCA_TAVOR_CQ_DB_REQ_NOT) |605592 to_mcq(cq)->cqn);606606- doorbell[1] = 0xffffffff;593593+ doorbell[1] = (__force __be32) 0xffffffff;607594608595 mthca_write64(doorbell,609596 to_mdev(cq->device)->kar + MTHCA_CQ_DOORBELL,···615602int mthca_arbel_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)616603{617604 struct mthca_cq *cq = to_mcq(ibcq);618618- u32 doorbell[2];605605+ __be32 doorbell[2];619606 u32 sn;620620- u32 ci;607607+ __be32 ci;621608622609 sn = cq->arm_sn & 3;623610 ci = cpu_to_be32(cq->cons_index);···650637651638static void mthca_free_cq_buf(struct mthca_dev *dev, struct mthca_cq *cq)652639{653653- int i;654654- int size;655655-656656- if (cq->is_direct)657657- dma_free_coherent(&dev->pdev->dev,658658- (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,659659- cq->queue.direct.buf,660660- pci_unmap_addr(&cq->queue.direct,661661- mapping));662662- else {663663- size = (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE;664664- for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i)665665- if (cq->queue.page_list[i].buf)666666- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,667667- cq->queue.page_list[i].buf,668668- pci_unmap_addr(&cq->queue.page_list[i],669669- mapping));670670-671671- kfree(cq->queue.page_list);672672- }673673-}674674-675675-static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,676676- struct mthca_cq *cq)677677-{678678- int err = -ENOMEM;679679- int npages, shift;680680- u64 *dma_list = NULL;681681- dma_addr_t t;682682- int i;683683-684684- if (size <= MTHCA_MAX_DIRECT_CQ_SIZE) {685685- cq->is_direct = 1;686686- npages = 1;687687- shift = get_order(size) + PAGE_SHIFT;688688-689689- cq->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev,690690- size, &t, GFP_KERNEL);691691- if (!cq->queue.direct.buf)692692- return -ENOMEM;693693-694694- pci_unmap_addr_set(&cq->queue.direct, mapping, t);695695-696696- memset(cq->queue.direct.buf, 0, size);697697-698698- while (t & ((1 << shift) - 1)) {699699- --shift;700700- npages *= 2;701701- }702702-703703- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);704704- if (!dma_list)705705- goto err_free;706706-707707- for (i = 0; i < npages; ++i)708708- dma_list[i] = t + i * (1 << shift);709709- } else {710710- cq->is_direct = 0;711711- npages = (size + PAGE_SIZE - 1) / PAGE_SIZE;712712- shift = PAGE_SHIFT;713713-714714- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);715715- if (!dma_list)716716- return -ENOMEM;717717-718718- cq->queue.page_list = kmalloc(npages * sizeof *cq->queue.page_list,719719- GFP_KERNEL);720720- if (!cq->queue.page_list)721721- goto err_out;722722-723723- for (i = 0; i < npages; ++i)724724- cq->queue.page_list[i].buf = NULL;725725-726726- for (i = 0; i < npages; ++i) {727727- cq->queue.page_list[i].buf =728728- dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,729729- &t, GFP_KERNEL);730730- if (!cq->queue.page_list[i].buf)731731- goto err_free;732732-733733- dma_list[i] = t;734734- pci_unmap_addr_set(&cq->queue.page_list[i], mapping, t);735735-736736- memset(cq->queue.page_list[i].buf, 0, PAGE_SIZE);737737- }738738- }739739-740740- err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,741741- dma_list, shift, npages,742742- 0, size,743743- MTHCA_MPT_FLAG_LOCAL_WRITE |744744- MTHCA_MPT_FLAG_LOCAL_READ,745745- &cq->mr);746746- if (err)747747- goto err_free;748748-749749- kfree(dma_list);750750-751751- return 0;752752-753753-err_free:754754- mthca_free_cq_buf(dev, cq);755755-756756-err_out:757757- kfree(dma_list);758758-759759- return err;640640+ mthca_buf_free(dev, (cq->ibcq.cqe + 1) * MTHCA_CQ_ENTRY_SIZE,641641+ &cq->queue, cq->is_direct, &cq->mr);760642}761643762644int mthca_init_cq(struct mthca_dev *dev, int nent,···703795 cq_context = mailbox->buf;704796705797 if (cq->is_kernel) {706706- err = mthca_alloc_cq_buf(dev, size, cq);798798+ err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_CQ_SIZE,799799+ &cq->queue, &cq->is_direct,800800+ &dev->driver_pd, 1, &cq->mr);707801 if (err)708802 goto err_out_mailbox;709803···721811 cq_context->flags = cpu_to_be32(MTHCA_CQ_STATUS_OK |722812 MTHCA_CQ_STATE_DISARMED |723813 MTHCA_CQ_FLAG_TR);724724- cq_context->start = cpu_to_be64(0);725814 cq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24);726815 if (ctx)727816 cq_context->logsize_usrpage |= cpu_to_be32(ctx->uar.index);···766857 return 0;767858768859err_out_free_mr:769769- if (cq->is_kernel) {770770- mthca_free_mr(dev, &cq->mr);860860+ if (cq->is_kernel)771861 mthca_free_cq_buf(dev, cq);772772- }773862774863err_out_mailbox:775864 mthca_free_mailbox(dev, mailbox);···811904 mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);812905813906 if (0) {814814- u32 *ctx = mailbox->buf;907907+ __be32 *ctx = mailbox->buf;815908 int j;816909817910 printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",···835928 wait_event(cq->wait, !atomic_read(&cq->refcount));836929837930 if (cq->is_kernel) {838838- mthca_free_mr(dev, &cq->mr);839931 mthca_free_cq_buf(dev, cq);840932 if (mthca_is_memfree(dev)) {841933 mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
+43-9
drivers/infiniband/hw/mthca/mthca_dev.h
···22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44 * Copyright (c) 2005 Cisco Systems. All rights reserved.55+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.66+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.57 *68 * This software is available to you under a choice of one of two79 * licenses. You may choose to be licensed under the terms of the GNU···66646765enum {6866 MTHCA_MAX_PORTS = 26767+};6868+6969+enum {7070+ MTHCA_BOARD_ID_LEN = 646971};70727173enum {···148142 int reserved_mcgs;149143 int num_pds;150144 int reserved_pds;145145+ u8 port_width_cap;151146};152147153148struct mthca_alloc {···218211 struct mthca_icm_table *table;219212};220213214214+struct mthca_srq_table {215215+ struct mthca_alloc alloc;216216+ spinlock_t lock;217217+ struct mthca_array srq;218218+ struct mthca_icm_table *table;219219+};220220+221221struct mthca_qp_table {222222 struct mthca_alloc alloc;223223 u32 rdb_base;···260246 unsigned long device_cap_flags;261247262248 u32 rev_id;249249+ char board_id[MTHCA_BOARD_ID_LEN];263250264251 /* firmware info */265252 u64 fw_ver;···306291 struct mthca_mr_table mr_table;307292 struct mthca_eq_table eq_table;308293 struct mthca_cq_table cq_table;294294+ struct mthca_srq_table srq_table;309295 struct mthca_qp_table qp_table;310296 struct mthca_av_table av_table;311297 struct mthca_mcg_table mcg_table;···347331348332#define MTHCA_PUT(dest, source, offset) \349333 do { \350350- __typeof__(source) *__p = \351351- (__typeof__(source) *) ((char *) (dest) + (offset)); \334334+ void *__d = ((char *) (dest) + (offset)); \352335 switch (sizeof(source)) { \353353- case 1: *__p = (source); break; \354354- case 2: *__p = cpu_to_be16(source); break; \355355- case 4: *__p = cpu_to_be32(source); break; \356356- case 8: *__p = cpu_to_be64(source); break; \357357- default: __buggy_use_of_MTHCA_PUT(); \336336+ case 1: *(u8 *) __d = (source); break; \337337+ case 2: *(__be16 *) __d = cpu_to_be16(source); break; \338338+ case 4: *(__be32 *) __d = cpu_to_be32(source); break; \339339+ case 8: *(__be64 *) __d = cpu_to_be64(source); break; \340340+ default: __buggy_use_of_MTHCA_PUT(); \358341 } \359342 } while (0)360343···369354void mthca_array_clear(struct mthca_array *array, int index);370355int mthca_array_init(struct mthca_array *array, int nent);371356void mthca_array_cleanup(struct mthca_array *array, int nent);357357+int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,358358+ union mthca_buf *buf, int *is_direct, struct mthca_pd *pd,359359+ int hca_write, struct mthca_mr *mr);360360+void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,361361+ int is_direct, struct mthca_mr *mr);372362373363int mthca_init_uar_table(struct mthca_dev *dev);374364int mthca_init_pd_table(struct mthca_dev *dev);375365int mthca_init_mr_table(struct mthca_dev *dev);376366int mthca_init_eq_table(struct mthca_dev *dev);377367int mthca_init_cq_table(struct mthca_dev *dev);368368+int mthca_init_srq_table(struct mthca_dev *dev);378369int mthca_init_qp_table(struct mthca_dev *dev);379370int mthca_init_av_table(struct mthca_dev *dev);380371int mthca_init_mcg_table(struct mthca_dev *dev);···390369void mthca_cleanup_mr_table(struct mthca_dev *dev);391370void mthca_cleanup_eq_table(struct mthca_dev *dev);392371void mthca_cleanup_cq_table(struct mthca_dev *dev);372372+void mthca_cleanup_srq_table(struct mthca_dev *dev);393373void mthca_cleanup_qp_table(struct mthca_dev *dev);394374void mthca_cleanup_av_table(struct mthca_dev *dev);395375void mthca_cleanup_mcg_table(struct mthca_dev *dev);···441419void mthca_free_cq(struct mthca_dev *dev,442420 struct mthca_cq *cq);443421void mthca_cq_event(struct mthca_dev *dev, u32 cqn);444444-void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn);422422+void mthca_cq_clean(struct mthca_dev *dev, u32 cqn, u32 qpn,423423+ struct mthca_srq *srq);424424+425425+int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,426426+ struct ib_srq_attr *attr, struct mthca_srq *srq);427427+void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);428428+void mthca_srq_event(struct mthca_dev *dev, u32 srqn,429429+ enum ib_event_type event_type);430430+void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);431431+int mthca_tavor_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,432432+ struct ib_recv_wr **bad_wr);433433+int mthca_arbel_post_srq_recv(struct ib_srq *srq, struct ib_recv_wr *wr,434434+ struct ib_recv_wr **bad_wr);445435446436void mthca_qp_event(struct mthca_dev *dev, u32 qpn,447437 enum ib_event_type event_type);···467433int mthca_arbel_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,468434 struct ib_recv_wr **bad_wr);469435int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,470470- int index, int *dbd, u32 *new_wqe);436436+ int index, int *dbd, __be32 *new_wqe);471437int mthca_alloc_qp(struct mthca_dev *dev,472438 struct mthca_pd *pd,473439 struct mthca_cq *send_cq,
+7-6
drivers/infiniband/hw/mthca/mthca_doorbell.h
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU···5857 __raw_writeq((__force u64) val, dest);5958}60596161-static inline void mthca_write64(u32 val[2], void __iomem *dest,6060+static inline void mthca_write64(__be32 val[2], void __iomem *dest,6261 spinlock_t *doorbell_lock)6362{6463 __raw_writeq(*(u64 *) val, dest);6564}66656767-static inline void mthca_write_db_rec(u32 val[2], u32 *db)6666+static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)6867{6968 *(u64 *) db = *(u64 *) val;7069}···8786 __raw_writel(((__force u32 *) &val)[1], dest + 4);8887}89889090-static inline void mthca_write64(u32 val[2], void __iomem *dest,8989+static inline void mthca_write64(__be32 val[2], void __iomem *dest,9190 spinlock_t *doorbell_lock)9291{9392 unsigned long flags;94939594 spin_lock_irqsave(doorbell_lock, flags);9696- __raw_writel(val[0], dest);9797- __raw_writel(val[1], dest + 4);9595+ __raw_writel((__force u32) val[0], dest);9696+ __raw_writel((__force u32) val[1], dest + 4);9897 spin_unlock_irqrestore(doorbell_lock, flags);9998}10099101101-static inline void mthca_write_db_rec(u32 val[2], u32 *db)100100+static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)102101{103102 db[0] = val[0];104103 wmb();
+32-31
drivers/infiniband/hw/mthca/mthca_eq.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···5251 * Must be packed because start is 64 bits but only aligned to 32 bits.5352 */5453struct mthca_eq_context {5555- u32 flags;5656- u64 start;5757- u32 logsize_usrpage;5858- u32 tavor_pd; /* reserved for Arbel */5959- u8 reserved1[3];6060- u8 intr;6161- u32 arbel_pd; /* lost_count for Tavor */6262- u32 lkey;6363- u32 reserved2[2];6464- u32 consumer_index;6565- u32 producer_index;6666- u32 reserved3[4];5454+ __be32 flags;5555+ __be64 start;5656+ __be32 logsize_usrpage;5757+ __be32 tavor_pd; /* reserved for Arbel */5858+ u8 reserved1[3];5959+ u8 intr;6060+ __be32 arbel_pd; /* lost_count for Tavor */6161+ __be32 lkey;6262+ u32 reserved2[2];6363+ __be32 consumer_index;6464+ __be32 producer_index;6565+ u32 reserved3[4];6766} __attribute__((packed));68676968#define MTHCA_EQ_STATUS_OK ( 0 << 28)···128127 union {129128 u32 raw[6];130129 struct {131131- u32 cqn;130130+ __be32 cqn;132131 } __attribute__((packed)) comp;133132 struct {134134- u16 reserved1;135135- u16 token;136136- u32 reserved2;137137- u8 reserved3[3];138138- u8 status;139139- u64 out_param;133133+ u16 reserved1;134134+ __be16 token;135135+ u32 reserved2;136136+ u8 reserved3[3];137137+ u8 status;138138+ __be64 out_param;140139 } __attribute__((packed)) cmd;141140 struct {142142- u32 qpn;141141+ __be32 qpn;143142 } __attribute__((packed)) qp;144143 struct {145145- u32 cqn;146146- u32 reserved1;147147- u8 reserved2[3];148148- u8 syndrome;144144+ __be32 cqn;145145+ u32 reserved1;146146+ u8 reserved2[3];147147+ u8 syndrome;149148 } __attribute__((packed)) cq_err;150149 struct {151151- u32 reserved1[2];152152- u32 port;150150+ u32 reserved1[2];151151+ __be32 port;153152 } __attribute__((packed)) port_change;154153 } event;155154 u8 reserved3[3];···168167169168static inline void tavor_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)170169{171171- u32 doorbell[2];170170+ __be32 doorbell[2];172171173172 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_SET_CI | eq->eqn);174173 doorbell[1] = cpu_to_be32(ci & (eq->nent - 1));···191190{192191 /* See comment in tavor_set_eq_ci() above. */193192 wmb();194194- __raw_writel(cpu_to_be32(ci), dev->eq_regs.arbel.eq_set_ci_base +195195- eq->eqn * 8);193193+ __raw_writel((__force u32) cpu_to_be32(ci),194194+ dev->eq_regs.arbel.eq_set_ci_base + eq->eqn * 8);196195 /* We still want ordering, just not swabbing, so add a barrier */197196 mb();198197}···207206208207static inline void tavor_eq_req_not(struct mthca_dev *dev, int eqn)209208{210210- u32 doorbell[2];209209+ __be32 doorbell[2];211210212211 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_REQ_NOT | eqn);213212 doorbell[1] = 0;···225224static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)226225{227226 if (!mthca_is_memfree(dev)) {228228- u32 doorbell[2];227227+ __be32 doorbell[2];229228230229 doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);231230 doorbell[1] = cpu_to_be32(cqn);
+6-4
drivers/infiniband/hw/mthca/mthca_mad.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.44+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···3432 * $Id: mthca_mad.c 1349 2004-12-16 21:09:43Z roland $3533 */36343737-#include <ib_verbs.h>3838-#include <ib_mad.h>3939-#include <ib_smi.h>3535+#include <rdma/ib_verbs.h>3636+#include <rdma/ib_mad.h>3737+#include <rdma/ib_smi.h>40384139#include "mthca_dev.h"4240#include "mthca_cmd.h"···194192{195193 int err;196194 u8 status;197197- u16 slid = in_wc ? in_wc->slid : IB_LID_PERMISSIVE;195195+ u16 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);198196199197 /* Forward locally generated traps to the SM */200198 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP &&
+106-73
drivers/infiniband/hw/mthca/mthca_main.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU···3534 */36353736#include <linux/config.h>3838-#include <linux/version.h>3937#include <linux/module.h>4038#include <linux/init.h>4139#include <linux/errno.h>···171171 mdev->limits.reserved_mrws = dev_lim->reserved_mrws;172172 mdev->limits.reserved_uars = dev_lim->reserved_uars;173173 mdev->limits.reserved_pds = dev_lim->reserved_pds;174174+ mdev->limits.port_width_cap = dev_lim->max_port_width;174175175176 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.176177 May be doable since hardware supports it for SRQ.···213212 struct mthca_dev_lim dev_lim;214213 struct mthca_profile profile;215214 struct mthca_init_hca_param init_hca;216216- struct mthca_adapter adapter;217215218216 err = mthca_SYS_EN(mdev, &status);219217 if (err) {···253253 profile = default_profile;254254 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;255255 profile.uarc_size = 0;256256+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)257257+ profile.num_srq = dev_lim.max_srqs;256258257259 err = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);258260 if (err < 0)···272270 goto err_disable;273271 }274272275275- err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);276276- if (err) {277277- mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");278278- goto err_close;279279- }280280- if (status) {281281- mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "282282- "aborting.\n", status);283283- err = -EINVAL;284284- goto err_close;285285- }286286-287287- mdev->eq_table.inta_pin = adapter.inta_pin;288288- mdev->rev_id = adapter.revision_id;289289-290273 return 0;291291-292292-err_close:293293- mthca_CLOSE_HCA(mdev, 0, &status);294274295275err_disable:296276 mthca_SYS_DIS(mdev, &status);···426442 }427443428444 mdev->cq_table.table = mthca_alloc_icm_table(mdev, init_hca->cqc_base,429429- dev_lim->cqc_entry_sz,430430- mdev->limits.num_cqs,431431- mdev->limits.reserved_cqs, 0);445445+ dev_lim->cqc_entry_sz,446446+ mdev->limits.num_cqs,447447+ mdev->limits.reserved_cqs, 0);432448 if (!mdev->cq_table.table) {433449 mthca_err(mdev, "Failed to map CQ context memory, aborting.\n");434450 err = -ENOMEM;435451 goto err_unmap_rdb;452452+ }453453+454454+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ) {455455+ mdev->srq_table.table =456456+ mthca_alloc_icm_table(mdev, init_hca->srqc_base,457457+ dev_lim->srq_entry_sz,458458+ mdev->limits.num_srqs,459459+ mdev->limits.reserved_srqs, 0);460460+ if (!mdev->srq_table.table) {461461+ mthca_err(mdev, "Failed to map SRQ context memory, "462462+ "aborting.\n");463463+ err = -ENOMEM;464464+ goto err_unmap_cq;465465+ }436466 }437467438468 /*···464466 if (!mdev->mcg_table.table) {465467 mthca_err(mdev, "Failed to map MCG context memory, aborting.\n");466468 err = -ENOMEM;467467- goto err_unmap_cq;469469+ goto err_unmap_srq;468470 }469471470472 return 0;473473+474474+err_unmap_srq:475475+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)476476+ mthca_free_icm_table(mdev, mdev->srq_table.table);471477472478err_unmap_cq:473479 mthca_free_icm_table(mdev, mdev->cq_table.table);···508506 struct mthca_dev_lim dev_lim;509507 struct mthca_profile profile;510508 struct mthca_init_hca_param init_hca;511511- struct mthca_adapter adapter;512509 u64 icm_size;513510 u8 status;514511 int err;···552551 profile = default_profile;553552 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;554553 profile.num_udav = 0;554554+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)555555+ profile.num_srq = dev_lim.max_srqs;555556556557 icm_size = mthca_make_profile(mdev, &profile, &dev_lim, &init_hca);557558 if ((int) icm_size < 0) {···577574 goto err_free_icm;578575 }579576580580- err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);581581- if (err) {582582- mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");583583- goto err_free_icm;584584- }585585- if (status) {586586- mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "587587- "aborting.\n", status);588588- err = -EINVAL;589589- goto err_free_icm;590590- }591591-592592- mdev->eq_table.inta_pin = adapter.inta_pin;593593- mdev->rev_id = adapter.revision_id;594594-595577 return 0;596578597579err_free_icm:580580+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)581581+ mthca_free_icm_table(mdev, mdev->srq_table.table);598582 mthca_free_icm_table(mdev, mdev->cq_table.table);599583 mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);600584 mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);···604614 return err;605615}606616617617+static void mthca_close_hca(struct mthca_dev *mdev)618618+{619619+ u8 status;620620+621621+ mthca_CLOSE_HCA(mdev, 0, &status);622622+623623+ if (mthca_is_memfree(mdev)) {624624+ if (mdev->mthca_flags & MTHCA_FLAG_SRQ)625625+ mthca_free_icm_table(mdev, mdev->srq_table.table);626626+ mthca_free_icm_table(mdev, mdev->cq_table.table);627627+ mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);628628+ mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);629629+ mthca_free_icm_table(mdev, mdev->qp_table.qp_table);630630+ mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);631631+ mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);632632+ mthca_unmap_eq_icm(mdev);633633+634634+ mthca_UNMAP_ICM_AUX(mdev, &status);635635+ mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);636636+637637+ mthca_UNMAP_FA(mdev, &status);638638+ mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);639639+640640+ if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))641641+ mthca_DISABLE_LAM(mdev, &status);642642+ } else643643+ mthca_SYS_DIS(mdev, &status);644644+}645645+607646static int __devinit mthca_init_hca(struct mthca_dev *mdev)608647{648648+ u8 status;649649+ int err;650650+ struct mthca_adapter adapter;651651+609652 if (mthca_is_memfree(mdev))610610- return mthca_init_arbel(mdev);653653+ err = mthca_init_arbel(mdev);611654 else612612- return mthca_init_tavor(mdev);655655+ err = mthca_init_tavor(mdev);656656+657657+ if (err)658658+ return err;659659+660660+ err = mthca_QUERY_ADAPTER(mdev, &adapter, &status);661661+ if (err) {662662+ mthca_err(mdev, "QUERY_ADAPTER command failed, aborting.\n");663663+ goto err_close;664664+ }665665+ if (status) {666666+ mthca_err(mdev, "QUERY_ADAPTER returned status 0x%02x, "667667+ "aborting.\n", status);668668+ err = -EINVAL;669669+ goto err_close;670670+ }671671+672672+ mdev->eq_table.inta_pin = adapter.inta_pin;673673+ mdev->rev_id = adapter.revision_id;674674+ memcpy(mdev->board_id, adapter.board_id, sizeof mdev->board_id);675675+676676+ return 0;677677+678678+err_close:679679+ mthca_close_hca(mdev);680680+ return err;613681}614682615683static int __devinit mthca_setup_hca(struct mthca_dev *dev)···757709 goto err_cmd_poll;758710 }759711712712+ err = mthca_init_srq_table(dev);713713+ if (err) {714714+ mthca_err(dev, "Failed to initialize "715715+ "shared receive queue table, aborting.\n");716716+ goto err_cq_table_free;717717+ }718718+760719 err = mthca_init_qp_table(dev);761720 if (err) {762721 mthca_err(dev, "Failed to initialize "763722 "queue pair table, aborting.\n");764764- goto err_cq_table_free;723723+ goto err_srq_table_free;765724 }766725767726 err = mthca_init_av_table(dev);···792737793738err_qp_table_free:794739 mthca_cleanup_qp_table(dev);740740+741741+err_srq_table_free:742742+ mthca_cleanup_srq_table(dev);795743796744err_cq_table_free:797745 mthca_cleanup_cq_table(dev);···902844 return 0;903845}904846905905-static void mthca_close_hca(struct mthca_dev *mdev)906906-{907907- u8 status;908908-909909- mthca_CLOSE_HCA(mdev, 0, &status);910910-911911- if (mthca_is_memfree(mdev)) {912912- mthca_free_icm_table(mdev, mdev->cq_table.table);913913- mthca_free_icm_table(mdev, mdev->qp_table.rdb_table);914914- mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);915915- mthca_free_icm_table(mdev, mdev->qp_table.qp_table);916916- mthca_free_icm_table(mdev, mdev->mr_table.mpt_table);917917- mthca_free_icm_table(mdev, mdev->mr_table.mtt_table);918918- mthca_unmap_eq_icm(mdev);919919-920920- mthca_UNMAP_ICM_AUX(mdev, &status);921921- mthca_free_icm(mdev, mdev->fw.arbel.aux_icm);922922-923923- mthca_UNMAP_FA(mdev, &status);924924- mthca_free_icm(mdev, mdev->fw.arbel.fw_icm);925925-926926- if (!(mdev->mthca_flags & MTHCA_FLAG_NO_LAM))927927- mthca_DISABLE_LAM(mdev, &status);928928- } else929929- mthca_SYS_DIS(mdev, &status);930930-}931931-932847/* Types of supported HCA */933848enum {934849 TAVOR, /* MT23108 */···918887 int is_memfree;919888 int is_pcie;920889} mthca_hca_table[] = {921921- [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 3, 2), .is_memfree = 0, .is_pcie = 0 },922922- [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 6, 2), .is_memfree = 0, .is_pcie = 1 },923923- [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 0, 1), .is_memfree = 1, .is_pcie = 1 },890890+ [TAVOR] = { .latest_fw = MTHCA_FW_VER(3, 3, 3), .is_memfree = 0, .is_pcie = 0 },891891+ [ARBEL_COMPAT] = { .latest_fw = MTHCA_FW_VER(4, 7, 0), .is_memfree = 0, .is_pcie = 1 },892892+ [ARBEL_NATIVE] = { .latest_fw = MTHCA_FW_VER(5, 1, 0), .is_memfree = 1, .is_pcie = 1 },924893 [SINAI] = { .latest_fw = MTHCA_FW_VER(1, 0, 1), .is_memfree = 1, .is_pcie = 1 }925894};926895···10821051 mthca_cleanup_mcg_table(mdev);10831052 mthca_cleanup_av_table(mdev);10841053 mthca_cleanup_qp_table(mdev);10541054+ mthca_cleanup_srq_table(mdev);10851055 mthca_cleanup_cq_table(mdev);10861056 mthca_cmd_use_polling(mdev);10871057 mthca_cleanup_eq_table(mdev);···11321100 mthca_cleanup_mcg_table(mdev);11331101 mthca_cleanup_av_table(mdev);11341102 mthca_cleanup_qp_table(mdev);11031103+ mthca_cleanup_srq_table(mdev);11351104 mthca_cleanup_cq_table(mdev);11361105 mthca_cmd_use_polling(mdev);11371106 mthca_cleanup_eq_table(mdev);
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU···286285{287286 struct mthca_icm_table *table;288287 int num_icm;288288+ unsigned chunk_size;289289 int i;290290 u8 status;291291···307305 table->icm[i] = NULL;308306309307 for (i = 0; i * MTHCA_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) {310310- table->icm[i] = mthca_alloc_icm(dev, MTHCA_TABLE_CHUNK_SIZE >> PAGE_SHIFT,308308+ chunk_size = MTHCA_TABLE_CHUNK_SIZE;309309+ if ((i + 1) * MTHCA_TABLE_CHUNK_SIZE > nobj * obj_size)310310+ chunk_size = nobj * obj_size - i * MTHCA_TABLE_CHUNK_SIZE;311311+312312+ table->icm[i] = mthca_alloc_icm(dev, chunk_size >> PAGE_SHIFT,311313 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) |312314 __GFP_NOWARN);313315 if (!table->icm[i])···487481 }488482}489483490490-int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db)484484+int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db)491485{492486 int group;493487 int start, end, dir;···570564571565 page->db_rec[j] = cpu_to_be64((qn << 8) | (type << 5));572566573573- *db = (u32 *) &page->db_rec[j];567567+ *db = (__be32 *) &page->db_rec[j];574568575569out:576570 up(&dev->db_tab->mutex);
+3-2
drivers/infiniband/hw/mthca/mthca_memfree.h
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU···138137139138struct mthca_db_page {140139 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE);141141- u64 *db_rec;140140+ __be64 *db_rec;142141 dma_addr_t mapping;143142};144143···173172174173int mthca_init_db_tab(struct mthca_dev *dev);175174void mthca_cleanup_db_tab(struct mthca_dev *dev);176176-int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, u32 **db);175175+int mthca_alloc_db(struct mthca_dev *dev, int type, u32 qn, __be32 **db);177176void mthca_free_db(struct mthca_dev *dev, int type, int db_index);178177179178#endif /* MTHCA_MEMFREE_H */
+18-17
drivers/infiniband/hw/mthca/mthca_mr.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···5150 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.5251 */5352struct mthca_mpt_entry {5454- u32 flags;5555- u32 page_size;5656- u32 key;5757- u32 pd;5858- u64 start;5959- u64 length;6060- u32 lkey;6161- u32 window_count;6262- u32 window_count_limit;6363- u64 mtt_seg;6464- u32 mtt_sz; /* Arbel only */6565- u32 reserved[2];5353+ __be32 flags;5454+ __be32 page_size;5555+ __be32 key;5656+ __be32 pd;5757+ __be64 start;5858+ __be64 length;5959+ __be32 lkey;6060+ __be32 window_count;6161+ __be32 window_count_limit;6262+ __be64 mtt_seg;6363+ __be32 mtt_sz; /* Arbel only */6464+ u32 reserved[2];6665} __attribute__((packed));67666867#define MTHCA_MPT_FLAG_SW_OWNS (0xfUL << 28)···248247 int start_index, u64 *buffer_list, int list_len)249248{250249 struct mthca_mailbox *mailbox;251251- u64 *mtt_entry;250250+ __be64 *mtt_entry;252251 int err = 0;253252 u8 status;254253 int i;···390389 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {391390 if (i % 4 == 0)392391 printk("[%02x] ", i * 4);393393- printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));392392+ printk(" %08x", be32_to_cpu(((__be32 *) mpt_entry)[i]));394393 if ((i + 1) % 4 == 0)395394 printk("\n");396395 }···459458static void mthca_free_region(struct mthca_dev *dev, u32 lkey)460459{461460 mthca_table_put(dev, dev->mr_table.mpt_table,462462- arbel_key_to_hw_index(lkey));461461+ key_to_hw_index(dev, lkey));463462464463 mthca_free(&dev->mr_table.mpt_alloc, key_to_hw_index(dev, lkey));465464}···563562 for (i = 0; i < sizeof (struct mthca_mpt_entry) / 4; ++i) {564563 if (i % 4 == 0)565564 printk("[%02x] ", i * 4);566566- printk(" %08x", be32_to_cpu(((u32 *) mpt_entry)[i]));565565+ printk(" %08x", be32_to_cpu(((__be32 *) mpt_entry)[i]));567566 if ((i + 1) % 4 == 0)568567 printk("\n");569568 }···670669 mpt_entry.length = cpu_to_be64(list_len * (1ull << fmr->attr.page_size));671670 mpt_entry.start = cpu_to_be64(iova);672671673673- writel(mpt_entry.lkey, &fmr->mem.tavor.mpt->key);672672+ __raw_writel((__force u32) mpt_entry.lkey, &fmr->mem.tavor.mpt->key);674673 memcpy_toio(&fmr->mem.tavor.mpt->start, &mpt_entry.start,675674 offsetof(struct mthca_mpt_entry, window_count) -676675 offsetof(struct mthca_mpt_entry, start));
+1
drivers/infiniband/hw/mthca/mthca_pd.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU
+2
drivers/infiniband/hw/mthca/mthca_profile.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···102101 profile[MTHCA_RES_UARC].size = request->uarc_size;103102104103 profile[MTHCA_RES_QP].num = request->num_qp;104104+ profile[MTHCA_RES_SRQ].num = request->num_srq;105105 profile[MTHCA_RES_EQP].num = request->num_qp;106106 profile[MTHCA_RES_RDB].num = request->num_qp * request->rdb_per_qp;107107 profile[MTHCA_RES_CQ].num = request->num_cq;
+2
drivers/infiniband/hw/mthca/mthca_profile.h
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···4241struct mthca_profile {4342 int num_qp;4443 int rdb_per_qp;4444+ int num_srq;4545 int num_cq;4646 int num_mcg;4747 int num_mpt;
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.45 *56 * This software is available to you under a choice of one of two67 * licenses. You may choose to be licensed under the terms of the GNU···3736#ifndef MTHCA_PROVIDER_H3837#define MTHCA_PROVIDER_H39384040-#include <ib_verbs.h>4141-#include <ib_pack.h>3939+#include <rdma/ib_verbs.h>4040+#include <rdma/ib_pack.h>42414342#define MTHCA_MPT_FLAG_ATOMIC (1 << 14)4443#define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)···4948struct mthca_buf_list {5049 void *buf;5150 DECLARE_PCI_UNMAP_ADDR(mapping)5151+};5252+5353+union mthca_buf {5454+ struct mthca_buf_list direct;5555+ struct mthca_buf_list *page_list;5256};53575458struct mthca_uar {···187181188182 /* Next fields are Arbel only */189183 int set_ci_db_index;190190- u32 *set_ci_db;184184+ __be32 *set_ci_db;191185 int arm_db_index;192192- u32 *arm_db;186186+ __be32 *arm_db;193187 int arm_sn;194188195195- union {196196- struct mthca_buf_list direct;197197- struct mthca_buf_list *page_list;198198- } queue;189189+ union mthca_buf queue;199190 struct mthca_mr mr;200191 wait_queue_head_t wait;192192+};193193+194194+struct mthca_srq {195195+ struct ib_srq ibsrq;196196+ spinlock_t lock;197197+ atomic_t refcount;198198+ int srqn;199199+ int max;200200+ int max_gs;201201+ int wqe_shift;202202+ int first_free;203203+ int last_free;204204+ u16 counter; /* Arbel only */205205+ int db_index; /* Arbel only */206206+ __be32 *db; /* Arbel only */207207+ void *last;208208+209209+ int is_direct;210210+ u64 *wrid;211211+ union mthca_buf queue;212212+ struct mthca_mr mr;213213+214214+ wait_queue_head_t wait;201215};202216203217struct mthca_wq {···232206 int wqe_shift;233207234208 int db_index; /* Arbel only */235235- u32 *db;209209+ __be32 *db;236210};237211238212struct mthca_qp {···253227 int send_wqe_offset;254228255229 u64 *wrid;256256- union {257257- struct mthca_buf_list direct;258258- struct mthca_buf_list *page_list;259259- } queue;230230+ union mthca_buf queue;260231261232 wait_queue_head_t wait;262233};···298275static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)299276{300277 return container_of(ibcq, struct mthca_cq, ibcq);278278+}279279+280280+static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq)281281+{282282+ return container_of(ibsrq, struct mthca_srq, ibsrq);301283}302284303285static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)
+105-257
drivers/infiniband/hw/mthca/mthca_qp.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33 * Copyright (c) 2005 Cisco Systems. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.55+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved. 46 *57 * This software is available to you under a choice of one of two68 * licenses. You may choose to be licensed under the terms of the GNU···37353836#include <linux/init.h>39374040-#include <ib_verbs.h>4141-#include <ib_cache.h>4242-#include <ib_pack.h>3838+#include <rdma/ib_verbs.h>3939+#include <rdma/ib_cache.h>4040+#include <rdma/ib_pack.h>43414442#include "mthca_dev.h"4543#include "mthca_cmd.h"4644#include "mthca_memfree.h"4545+#include "mthca_wqe.h"47464847enum {4948 MTHCA_MAX_DIRECT_QP_SIZE = 4 * PAGE_SIZE,···9895};999610097struct mthca_qp_path {101101- u32 port_pkey;102102- u8 rnr_retry;103103- u8 g_mylmc;104104- u16 rlid;105105- u8 ackto;106106- u8 mgid_index;107107- u8 static_rate;108108- u8 hop_limit;109109- u32 sl_tclass_flowlabel;110110- u8 rgid[16];9898+ __be32 port_pkey;9999+ u8 rnr_retry;100100+ u8 g_mylmc;101101+ __be16 rlid;102102+ u8 ackto;103103+ u8 mgid_index;104104+ u8 static_rate;105105+ u8 hop_limit;106106+ __be32 sl_tclass_flowlabel;107107+ u8 rgid[16];111108} __attribute__((packed));112109113110struct mthca_qp_context {114114- u32 flags;115115- u32 tavor_sched_queue; /* Reserved on Arbel */116116- u8 mtu_msgmax;117117- u8 rq_size_stride; /* Reserved on Tavor */118118- u8 sq_size_stride; /* Reserved on Tavor */119119- u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */120120- u32 usr_page;121121- u32 local_qpn;122122- u32 remote_qpn;123123- u32 reserved1[2];111111+ __be32 flags;112112+ __be32 tavor_sched_queue; /* Reserved on Arbel */113113+ u8 mtu_msgmax;114114+ u8 rq_size_stride; /* Reserved on Tavor */115115+ u8 sq_size_stride; /* Reserved on Tavor */116116+ u8 rlkey_arbel_sched_queue; /* Reserved on Tavor */117117+ __be32 usr_page;118118+ __be32 local_qpn;119119+ __be32 remote_qpn;120120+ u32 reserved1[2];124121 struct mthca_qp_path pri_path;125122 struct mthca_qp_path alt_path;126126- u32 rdd;127127- u32 pd;128128- u32 wqe_base;129129- u32 wqe_lkey;130130- u32 params1;131131- u32 reserved2;132132- u32 next_send_psn;133133- u32 cqn_snd;134134- u32 snd_wqe_base_l; /* Next send WQE on Tavor */135135- u32 snd_db_index; /* (debugging only entries) */136136- u32 last_acked_psn;137137- u32 ssn;138138- u32 params2;139139- u32 rnr_nextrecvpsn;140140- u32 ra_buff_indx;141141- u32 cqn_rcv;142142- u32 rcv_wqe_base_l; /* Next recv WQE on Tavor */143143- u32 rcv_db_index; /* (debugging only entries) */144144- u32 qkey;145145- u32 srqn;146146- u32 rmsn;147147- u16 rq_wqe_counter; /* reserved on Tavor */148148- u16 sq_wqe_counter; /* reserved on Tavor */149149- u32 reserved3[18];123123+ __be32 rdd;124124+ __be32 pd;125125+ __be32 wqe_base;126126+ __be32 wqe_lkey;127127+ __be32 params1;128128+ __be32 reserved2;129129+ __be32 next_send_psn;130130+ __be32 cqn_snd;131131+ __be32 snd_wqe_base_l; /* Next send WQE on Tavor */132132+ __be32 snd_db_index; /* (debugging only entries) */133133+ __be32 last_acked_psn;134134+ __be32 ssn;135135+ __be32 params2;136136+ __be32 rnr_nextrecvpsn;137137+ __be32 ra_buff_indx;138138+ __be32 cqn_rcv;139139+ __be32 rcv_wqe_base_l; /* Next recv WQE on Tavor */140140+ __be32 rcv_db_index; /* (debugging only entries) */141141+ __be32 qkey;142142+ __be32 srqn;143143+ __be32 rmsn;144144+ __be16 rq_wqe_counter; /* reserved on Tavor */145145+ __be16 sq_wqe_counter; /* reserved on Tavor */146146+ u32 reserved3[18];150147} __attribute__((packed));151148152149struct mthca_qp_param {153153- u32 opt_param_mask;154154- u32 reserved1;150150+ __be32 opt_param_mask;151151+ u32 reserved1;155152 struct mthca_qp_context context;156156- u32 reserved2[62];153153+ u32 reserved2[62];157154} __attribute__((packed));158155159156enum {···174171 MTHCA_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,175172 MTHCA_QP_OPTPAR_RNR_RETRY = 1 << 15,176173 MTHCA_QP_OPTPAR_SCHED_QUEUE = 1 << 16177177-};178178-179179-enum {180180- MTHCA_NEXT_DBD = 1 << 7,181181- MTHCA_NEXT_FENCE = 1 << 6,182182- MTHCA_NEXT_CQ_UPDATE = 1 << 3,183183- MTHCA_NEXT_EVENT_GEN = 1 << 2,184184- MTHCA_NEXT_SOLICIT = 1 << 1,185185-186186- MTHCA_MLX_VL15 = 1 << 17,187187- MTHCA_MLX_SLR = 1 << 16188188-};189189-190190-enum {191191- MTHCA_INVAL_LKEY = 0x100192192-};193193-194194-struct mthca_next_seg {195195- u32 nda_op; /* [31:6] next WQE [4:0] next opcode */196196- u32 ee_nds; /* [31:8] next EE [7] DBD [6] F [5:0] next WQE size */197197- u32 flags; /* [3] CQ [2] Event [1] Solicit */198198- u32 imm; /* immediate data */199199-};200200-201201-struct mthca_tavor_ud_seg {202202- u32 reserved1;203203- u32 lkey;204204- u64 av_addr;205205- u32 reserved2[4];206206- u32 dqpn;207207- u32 qkey;208208- u32 reserved3[2];209209-};210210-211211-struct mthca_arbel_ud_seg {212212- u32 av[8];213213- u32 dqpn;214214- u32 qkey;215215- u32 reserved[2];216216-};217217-218218-struct mthca_bind_seg {219219- u32 flags; /* [31] Atomic [30] rem write [29] rem read */220220- u32 reserved;221221- u32 new_rkey;222222- u32 lkey;223223- u64 addr;224224- u64 length;225225-};226226-227227-struct mthca_raddr_seg {228228- u64 raddr;229229- u32 rkey;230230- u32 reserved;231231-};232232-233233-struct mthca_atomic_seg {234234- u64 swap_add;235235- u64 compare;236236-};237237-238238-struct mthca_data_seg {239239- u32 byte_count;240240- u32 lkey;241241- u64 addr;242242-};243243-244244-struct mthca_mlx_seg {245245- u32 nda_op;246246- u32 nds;247247- u32 flags; /* [17] VL15 [16] SLR [14:12] static rate248248- [11:8] SL [3] C [2] E */249249- u16 rlid;250250- u16 vcrc;251174};252175253176static const u8 mthca_opcode[] = {···502573503574 memset(¶m, 0, sizeof param);504575505505- param.enable_1x = 1;506506- param.enable_4x = 1;507507- param.vl_cap = dev->limits.vl_cap;508508- param.mtu_cap = dev->limits.mtu_cap;509509- param.gid_cap = dev->limits.gid_table_len;510510- param.pkey_cap = dev->limits.pkey_table_len;576576+ param.port_width = dev->limits.port_width_cap;577577+ param.vl_cap = dev->limits.vl_cap;578578+ param.mtu_cap = dev->limits.mtu_cap;579579+ param.gid_cap = dev->limits.gid_table_len;580580+ param.pkey_cap = dev->limits.pkey_table_len;511581512582 err = mthca_INIT_IB(dev, ¶m, port, &status);513583 if (err)···612684 qp_context->mtu_msgmax = (attr->path_mtu << 5) | 31;613685614686 if (mthca_is_memfree(dev)) {615615- qp_context->rq_size_stride =616616- ((ffs(qp->rq.max) - 1) << 3) | (qp->rq.wqe_shift - 4);617617- qp_context->sq_size_stride =618618- ((ffs(qp->sq.max) - 1) << 3) | (qp->sq.wqe_shift - 4);687687+ if (qp->rq.max)688688+ qp_context->rq_size_stride = long_log2(qp->rq.max) << 3;689689+ qp_context->rq_size_stride |= qp->rq.wqe_shift - 4;690690+691691+ if (qp->sq.max)692692+ qp_context->sq_size_stride = long_log2(qp->sq.max) << 3;693693+ qp_context->sq_size_stride |= qp->sq.wqe_shift - 4;619694 }620695621696 /* leave arbel_sched_queue as 0 */···787856788857 qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RSC);789858859859+ if (ibqp->srq)860860+ qp_context->params2 |= cpu_to_be32(MTHCA_QP_BIT_RIC);861861+790862 if (attr_mask & IB_QP_MIN_RNR_TIMER) {791863 qp_context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);792864 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_RNR_TIMEOUT);···811877 qp_context->qkey = cpu_to_be32(attr->qkey);812878 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_Q_KEY);813879 }880880+881881+ if (ibqp->srq)882882+ qp_context->srqn = cpu_to_be32(1 << 24 |883883+ to_msrq(ibqp->srq)->srqn);814884815885 err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,816886 qp->qpn, 0, mailbox, 0, &status);···863925 struct mthca_qp *qp)864926{865927 int size;866866- int i;867867- int npages, shift;868868- dma_addr_t t;869869- u64 *dma_list = NULL;870928 int err = -ENOMEM;871929872930 size = sizeof (struct mthca_next_seg) +···912978 if (!qp->wrid)913979 goto err_out;914980915915- if (size <= MTHCA_MAX_DIRECT_QP_SIZE) {916916- qp->is_direct = 1;917917- npages = 1;918918- shift = get_order(size) + PAGE_SHIFT;919919-920920- if (0)921921- mthca_dbg(dev, "Creating direct QP of size %d (shift %d)\n",922922- size, shift);923923-924924- qp->queue.direct.buf = dma_alloc_coherent(&dev->pdev->dev, size,925925- &t, GFP_KERNEL);926926- if (!qp->queue.direct.buf)927927- goto err_out;928928-929929- pci_unmap_addr_set(&qp->queue.direct, mapping, t);930930-931931- memset(qp->queue.direct.buf, 0, size);932932-933933- while (t & ((1 << shift) - 1)) {934934- --shift;935935- npages *= 2;936936- }937937-938938- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);939939- if (!dma_list)940940- goto err_out_free;941941-942942- for (i = 0; i < npages; ++i)943943- dma_list[i] = t + i * (1 << shift);944944- } else {945945- qp->is_direct = 0;946946- npages = size / PAGE_SIZE;947947- shift = PAGE_SHIFT;948948-949949- if (0)950950- mthca_dbg(dev, "Creating indirect QP with %d pages\n", npages);951951-952952- dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);953953- if (!dma_list)954954- goto err_out;955955-956956- qp->queue.page_list = kmalloc(npages *957957- sizeof *qp->queue.page_list,958958- GFP_KERNEL);959959- if (!qp->queue.page_list)960960- goto err_out;961961-962962- for (i = 0; i < npages; ++i) {963963- qp->queue.page_list[i].buf =964964- dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,965965- &t, GFP_KERNEL);966966- if (!qp->queue.page_list[i].buf)967967- goto err_out_free;968968-969969- memset(qp->queue.page_list[i].buf, 0, PAGE_SIZE);970970-971971- pci_unmap_addr_set(&qp->queue.page_list[i], mapping, t);972972- dma_list[i] = t;973973- }974974- }975975-976976- err = mthca_mr_alloc_phys(dev, pd->pd_num, dma_list, shift,977977- npages, 0, size,978978- MTHCA_MPT_FLAG_LOCAL_READ,979979- &qp->mr);981981+ err = mthca_buf_alloc(dev, size, MTHCA_MAX_DIRECT_QP_SIZE,982982+ &qp->queue, &qp->is_direct, pd, 0, &qp->mr);980983 if (err)981981- goto err_out_free;984984+ goto err_out;982985983983- kfree(dma_list);984986 return 0;985987986986- err_out_free:987987- if (qp->is_direct) {988988- dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,989989- pci_unmap_addr(&qp->queue.direct, mapping));990990- } else991991- for (i = 0; i < npages; ++i) {992992- if (qp->queue.page_list[i].buf)993993- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,994994- qp->queue.page_list[i].buf,995995- pci_unmap_addr(&qp->queue.page_list[i],996996- mapping));997997-998998- }999999-10001000- err_out:988988+err_out:1001989 kfree(qp->wrid);10021002- kfree(dma_list);1003990 return err;1004991}10059921006993static void mthca_free_wqe_buf(struct mthca_dev *dev,1007994 struct mthca_qp *qp)1008995{10091009- int i;10101010- int size = PAGE_ALIGN(qp->send_wqe_offset +10111011- (qp->sq.max << qp->sq.wqe_shift));10121012-10131013- if (qp->is_direct) {10141014- dma_free_coherent(&dev->pdev->dev, size, qp->queue.direct.buf,10151015- pci_unmap_addr(&qp->queue.direct, mapping));10161016- } else {10171017- for (i = 0; i < size / PAGE_SIZE; ++i) {10181018- dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,10191019- qp->queue.page_list[i].buf,10201020- pci_unmap_addr(&qp->queue.page_list[i],10211021- mapping));10221022- }10231023- }10241024-996996+ mthca_buf_free(dev, PAGE_ALIGN(qp->send_wqe_offset +997997+ (qp->sq.max << qp->sq.wqe_shift)),998998+ &qp->queue, qp->is_direct, &qp->mr);1025999 kfree(qp->wrid);10261000}10271001···12701428 * unref the mem-free tables and free the QPN in our table.12711429 */12721430 if (!qp->ibqp.uobject) {12731273- mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn);14311431+ mthca_cq_clean(dev, to_mcq(qp->ibqp.send_cq)->cqn, qp->qpn,14321432+ qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);12741433 if (qp->ibqp.send_cq != qp->ibqp.recv_cq)12751275- mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn);14341434+ mthca_cq_clean(dev, to_mcq(qp->ibqp.recv_cq)->cqn, qp->qpn,14351435+ qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL);1276143612771277- mthca_free_mr(dev, &qp->mr);12781437 mthca_free_memfree(dev, qp);12791438 mthca_free_wqe_buf(dev, qp);12801439 }···13001457{13011458 int header_size;13021459 int err;14601460+ u16 pkey;1303146113041462 ib_ud_header_init(256, /* assume a MAD */13051463 sqp->ud_header.grh_present,···13111467 return err;13121468 mlx->flags &= ~cpu_to_be32(MTHCA_NEXT_SOLICIT | 1);13131469 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MTHCA_MLX_VL15 : 0) |13141314- (sqp->ud_header.lrh.destination_lid == 0xffff ?13151315- MTHCA_MLX_SLR : 0) |14701470+ (sqp->ud_header.lrh.destination_lid ==14711471+ IB_LID_PERMISSIVE ? MTHCA_MLX_SLR : 0) |13161472 (sqp->ud_header.lrh.service_level << 8));13171473 mlx->rlid = sqp->ud_header.lrh.destination_lid;13181474 mlx->vcrc = 0;···13321488 }1333148913341490 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;13351335- if (sqp->ud_header.lrh.destination_lid == 0xffff)13361336- sqp->ud_header.lrh.source_lid = 0xffff;14911491+ if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)14921492+ sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;13371493 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);13381494 if (!sqp->qp.ibqp.qp_num)13391495 ib_get_cached_pkey(&dev->ib_dev, sqp->port,13401340- sqp->pkey_index,13411341- &sqp->ud_header.bth.pkey);14961496+ sqp->pkey_index, &pkey);13421497 else13431498 ib_get_cached_pkey(&dev->ib_dev, sqp->port,13441344- wr->wr.ud.pkey_index,13451345- &sqp->ud_header.bth.pkey);13461346- cpu_to_be16s(&sqp->ud_header.bth.pkey);14991499+ wr->wr.ud.pkey_index, &pkey);15001500+ sqp->ud_header.bth.pkey = cpu_to_be16(pkey);13471501 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);13481502 sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));13491503 sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?···1584174215851743out:15861744 if (likely(nreq)) {15871587- u32 doorbell[2];17451745+ __be32 doorbell[2];1588174615891747 doorbell[0] = cpu_to_be32(((qp->sq.next_ind << qp->sq.wqe_shift) +15901748 qp->send_wqe_offset) | f0 | op0);···1685184316861844out:16871845 if (likely(nreq)) {16881688- u32 doorbell[2];18461846+ __be32 doorbell[2];1689184716901848 doorbell[0] = cpu_to_be32((qp->rq.next_ind << qp->rq.wqe_shift) | size0);16911849 doorbell[1] = cpu_to_be32((qp->qpn << 8) | nreq);···1906206419072065out:19082066 if (likely(nreq)) {19091909- u32 doorbell[2];20672067+ __be32 doorbell[2];1910206819112069 doorbell[0] = cpu_to_be32((nreq << 24) |19122070 ((qp->sq.head & 0xffff) << 8) |···20162174}2017217520182176int mthca_free_err_wqe(struct mthca_dev *dev, struct mthca_qp *qp, int is_send,20192019- int index, int *dbd, u32 *new_wqe)21772177+ int index, int *dbd, __be32 *new_wqe)20202178{20212179 struct mthca_next_seg *next;21802180+21812181+ /*21822182+ * For SRQs, all WQEs generate a CQE, so we're always at the21832183+ * end of the doorbell chain.21842184+ */21852185+ if (qp->ibqp.srq) {21862186+ *new_wqe = 0;21872187+ return 0;21882188+ }2022218920232190 if (is_send)20242191 next = get_send_wqe(qp, index);20252192 else20262193 next = get_recv_wqe(qp, index);2027219420282028- if (mthca_is_memfree(dev))20292029- *dbd = 1;20302030- else20312031- *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));21952195+ *dbd = !!(next->ee_nds & cpu_to_be32(MTHCA_NEXT_DBD));20322196 if (next->ee_nds & cpu_to_be32(0x3f))20332197 *new_wqe = (next->nda_op & cpu_to_be32(~0x3f)) |20342198 (next->ee_nds & cpu_to_be32(0x3f));
+591
drivers/infiniband/hw/mthca/mthca_srq.c
···11+/*22+ * Copyright (c) 2005 Cisco Systems. All rights reserved.33+ *44+ * This software is available to you under a choice of one of two55+ * licenses. You may choose to be licensed under the terms of the GNU66+ * General Public License (GPL) Version 2, available from the file77+ * COPYING in the main directory of this source tree, or the88+ * OpenIB.org BSD license below:99+ *1010+ * Redistribution and use in source and binary forms, with or1111+ * without modification, are permitted provided that the following1212+ * conditions are met:1313+ *1414+ * - Redistributions of source code must retain the above1515+ * copyright notice, this list of conditions and the following1616+ * disclaimer.1717+ *1818+ * - Redistributions in binary form must reproduce the above1919+ * copyright notice, this list of conditions and the following2020+ * disclaimer in the documentation and/or other materials2121+ * provided with the distribution.2222+ *2323+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,2424+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF2525+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND2626+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS2727+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN2828+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN2929+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE3030+ * SOFTWARE.3131+ *3232+ * $Id: mthca_srq.c 3047 2005-08-10 03:59:35Z roland $3333+ */3434+3535+#include "mthca_dev.h"3636+#include "mthca_cmd.h"3737+#include "mthca_memfree.h"3838+#include "mthca_wqe.h"3939+4040+enum {4141+ MTHCA_MAX_DIRECT_SRQ_SIZE = 4 * PAGE_SIZE4242+};4343+4444+struct mthca_tavor_srq_context {4545+ __be64 wqe_base_ds; /* low 6 bits is descriptor size */4646+ __be32 state_pd;4747+ __be32 lkey;4848+ __be32 uar;4949+ __be32 wqe_cnt;5050+ u32 reserved[2];5151+};5252+5353+struct mthca_arbel_srq_context {5454+ __be32 state_logsize_srqn;5555+ __be32 lkey;5656+ __be32 db_index;5757+ __be32 logstride_usrpage;5858+ __be64 wqe_base;5959+ __be32 eq_pd;6060+ __be16 limit_watermark;6161+ __be16 wqe_cnt;6262+ u16 reserved1;6363+ __be16 wqe_counter;6464+ u32 reserved2[3];6565+};6666+6767+static void *get_wqe(struct mthca_srq *srq, int n)6868+{6969+ if (srq->is_direct)7070+ return srq->queue.direct.buf + (n << srq->wqe_shift);7171+ else7272+ return srq->queue.page_list[(n << srq->wqe_shift) >> PAGE_SHIFT].buf +7373+ ((n << srq->wqe_shift) & (PAGE_SIZE - 1));7474+}7575+7676+/*7777+ * Return a pointer to the location within a WQE that we're using as a7878+ * link when the WQE is in the free list. We use an offset of 47979+ * because in the Tavor case, posting a WQE may overwrite the first8080+ * four bytes of the previous WQE. The offset avoids corrupting our8181+ * free list if the WQE has already completed and been put on the free8282+ * list when we post the next WQE.8383+ */8484+static inline int *wqe_to_link(void *wqe)8585+{8686+ return (int *) (wqe + 4);8787+}8888+8989+static void mthca_tavor_init_srq_context(struct mthca_dev *dev,9090+ struct mthca_pd *pd,9191+ struct mthca_srq *srq,9292+ struct mthca_tavor_srq_context *context)9393+{9494+ memset(context, 0, sizeof *context);9595+9696+ context->wqe_base_ds = cpu_to_be64(1 << (srq->wqe_shift - 4));9797+ context->state_pd = cpu_to_be32(pd->pd_num);9898+ context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);9999+100100+ if (pd->ibpd.uobject)101101+ context->uar =102102+ cpu_to_be32(to_mucontext(pd->ibpd.uobject->context)->uar.index);103103+ else104104+ context->uar = cpu_to_be32(dev->driver_uar.index);105105+}106106+107107+static void mthca_arbel_init_srq_context(struct mthca_dev *dev,108108+ struct mthca_pd *pd,109109+ struct mthca_srq *srq,110110+ struct mthca_arbel_srq_context *context)111111+{112112+ int logsize;113113+114114+ memset(context, 0, sizeof *context);115115+116116+ logsize = long_log2(srq->max) + srq->wqe_shift;117117+ context->state_logsize_srqn = cpu_to_be32(logsize << 24 | srq->srqn);118118+ context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);119119+ context->db_index = cpu_to_be32(srq->db_index);120120+ context->logstride_usrpage = cpu_to_be32((srq->wqe_shift - 4) << 29);121121+ if (pd->ibpd.uobject)122122+ context->logstride_usrpage |=123123+ cpu_to_be32(to_mucontext(pd->ibpd.uobject->context)->uar.index);124124+ else125125+ context->logstride_usrpage |= cpu_to_be32(dev->driver_uar.index);126126+ context->eq_pd = cpu_to_be32(MTHCA_EQ_ASYNC << 24 | pd->pd_num);127127+}128128+129129+static void mthca_free_srq_buf(struct mthca_dev *dev, struct mthca_srq *srq)130130+{131131+ mthca_buf_free(dev, srq->max << srq->wqe_shift, &srq->queue,132132+ srq->is_direct, &srq->mr);133133+ kfree(srq->wrid);134134+}135135+136136+static int mthca_alloc_srq_buf(struct mthca_dev *dev, struct mthca_pd *pd,137137+ struct mthca_srq *srq)138138+{139139+ struct mthca_data_seg *scatter;140140+ void *wqe;141141+ int err;142142+ int i;143143+144144+ if (pd->ibpd.uobject)145145+ return 0;146146+147147+ srq->wrid = kmalloc(srq->max * sizeof (u64), GFP_KERNEL);148148+ if (!srq->wrid)149149+ return -ENOMEM;150150+151151+ err = mthca_buf_alloc(dev, srq->max << srq->wqe_shift,152152+ MTHCA_MAX_DIRECT_SRQ_SIZE,153153+ &srq->queue, &srq->is_direct, pd, 1, &srq->mr);154154+ if (err) {155155+ kfree(srq->wrid);156156+ return err;157157+ }158158+159159+ /*160160+ * Now initialize the SRQ buffer so that all of the WQEs are161161+ * linked into the list of free WQEs. In addition, set the162162+ * scatter list L_Keys to the sentry value of 0x100.163163+ */164164+ for (i = 0; i < srq->max; ++i) {165165+ wqe = get_wqe(srq, i);166166+167167+ *wqe_to_link(wqe) = i < srq->max - 1 ? i + 1 : -1;168168+169169+ for (scatter = wqe + sizeof (struct mthca_next_seg);170170+ (void *) scatter < wqe + (1 << srq->wqe_shift);171171+ ++scatter)172172+ scatter->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);173173+ }174174+175175+ return 0;176176+}177177+178178+int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,179179+ struct ib_srq_attr *attr, struct mthca_srq *srq)180180+{181181+ struct mthca_mailbox *mailbox;182182+ u8 status;183183+ int ds;184184+ int err;185185+186186+ /* Sanity check SRQ size before proceeding */187187+ if (attr->max_wr > 16 << 20 || attr->max_sge > 64)188188+ return -EINVAL;189189+190190+ srq->max = attr->max_wr;191191+ srq->max_gs = attr->max_sge;192192+ srq->last = NULL;193193+ srq->counter = 0;194194+195195+ if (mthca_is_memfree(dev))196196+ srq->max = roundup_pow_of_two(srq->max + 1);197197+198198+ ds = min(64UL,199199+ roundup_pow_of_two(sizeof (struct mthca_next_seg) +200200+ srq->max_gs * sizeof (struct mthca_data_seg)));201201+ srq->wqe_shift = long_log2(ds);202202+203203+ srq->srqn = mthca_alloc(&dev->srq_table.alloc);204204+ if (srq->srqn == -1)205205+ return -ENOMEM;206206+207207+ if (mthca_is_memfree(dev)) {208208+ err = mthca_table_get(dev, dev->srq_table.table, srq->srqn);209209+ if (err)210210+ goto err_out;211211+212212+ if (!pd->ibpd.uobject) {213213+ srq->db_index = mthca_alloc_db(dev, MTHCA_DB_TYPE_SRQ,214214+ srq->srqn, &srq->db);215215+ if (srq->db_index < 0) {216216+ err = -ENOMEM;217217+ goto err_out_icm;218218+ }219219+ }220220+ }221221+222222+ mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);223223+ if (IS_ERR(mailbox)) {224224+ err = PTR_ERR(mailbox);225225+ goto err_out_db;226226+ }227227+228228+ err = mthca_alloc_srq_buf(dev, pd, srq);229229+ if (err)230230+ goto err_out_mailbox;231231+232232+ spin_lock_init(&srq->lock);233233+ atomic_set(&srq->refcount, 1);234234+ init_waitqueue_head(&srq->wait);235235+236236+ if (mthca_is_memfree(dev))237237+ mthca_arbel_init_srq_context(dev, pd, srq, mailbox->buf);238238+ else239239+ mthca_tavor_init_srq_context(dev, pd, srq, mailbox->buf);240240+241241+ err = mthca_SW2HW_SRQ(dev, mailbox, srq->srqn, &status);242242+243243+ if (err) {244244+ mthca_warn(dev, "SW2HW_SRQ failed (%d)\n", err);245245+ goto err_out_free_buf;246246+ }247247+ if (status) {248248+ mthca_warn(dev, "SW2HW_SRQ returned status 0x%02x\n",249249+ status);250250+ err = -EINVAL;251251+ goto err_out_free_buf;252252+ }253253+254254+ spin_lock_irq(&dev->srq_table.lock);255255+ if (mthca_array_set(&dev->srq_table.srq,256256+ srq->srqn & (dev->limits.num_srqs - 1),257257+ srq)) {258258+ spin_unlock_irq(&dev->srq_table.lock);259259+ goto err_out_free_srq;260260+ }261261+ spin_unlock_irq(&dev->srq_table.lock);262262+263263+ mthca_free_mailbox(dev, mailbox);264264+265265+ srq->first_free = 0;266266+ srq->last_free = srq->max - 1;267267+268268+ return 0;269269+270270+err_out_free_srq:271271+ err = mthca_HW2SW_SRQ(dev, mailbox, srq->srqn, &status);272272+ if (err)273273+ mthca_warn(dev, "HW2SW_SRQ failed (%d)\n", err);274274+ else if (status)275275+ mthca_warn(dev, "HW2SW_SRQ returned status 0x%02x\n", status);276276+277277+err_out_free_buf:278278+ if (!pd->ibpd.uobject)279279+ mthca_free_srq_buf(dev, srq);280280+281281+err_out_mailbox:282282+ mthca_free_mailbox(dev, mailbox);283283+284284+err_out_db:285285+ if (!pd->ibpd.uobject && mthca_is_memfree(dev))286286+ mthca_free_db(dev, MTHCA_DB_TYPE_SRQ, srq->db_index);287287+288288+err_out_icm:289289+ mthca_table_put(dev, dev->srq_table.table, srq->srqn);290290+291291+err_out:292292+ mthca_free(&dev->srq_table.alloc, srq->srqn);293293+294294+ return err;295295+}296296+297297+void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq)298298+{299299+ struct mthca_mailbox *mailbox;300300+ int err;301301+ u8 status;302302+303303+ mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);304304+ if (IS_ERR(mailbox)) {305305+ mthca_warn(dev, "No memory for mailbox to free SRQ.\n");306306+ return;307307+ }308308+309309+ err = mthca_HW2SW_SRQ(dev, mailbox, srq->srqn, &status);310310+ if (err)311311+ mthca_warn(dev, "HW2SW_SRQ failed (%d)\n", err);312312+ else if (status)313313+ mthca_warn(dev, "HW2SW_SRQ returned status 0x%02x\n", status);314314+315315+ spin_lock_irq(&dev->srq_table.lock);316316+ mthca_array_clear(&dev->srq_table.srq,317317+ srq->srqn & (dev->limits.num_srqs - 1));318318+ spin_unlock_irq(&dev->srq_table.lock);319319+320320+ atomic_dec(&srq->refcount);321321+ wait_event(srq->wait, !atomic_read(&srq->refcount));322322+323323+ if (!srq->ibsrq.uobject) {324324+ mthca_free_srq_buf(dev, srq);325325+ if (mthca_is_memfree(dev))326326+ mthca_free_db(dev, MTHCA_DB_TYPE_SRQ, srq->db_index);327327+ }328328+329329+ mthca_table_put(dev, dev->srq_table.table, srq->srqn);330330+ mthca_free(&dev->srq_table.alloc, srq->srqn);331331+ mthca_free_mailbox(dev, mailbox);332332+}333333+334334+void mthca_srq_event(struct mthca_dev *dev, u32 srqn,335335+ enum ib_event_type event_type)336336+{337337+ struct mthca_srq *srq;338338+ struct ib_event event;339339+340340+ spin_lock(&dev->srq_table.lock);341341+ srq = mthca_array_get(&dev->srq_table.srq, srqn & (dev->limits.num_srqs - 1));342342+ if (srq)343343+ atomic_inc(&srq->refcount);344344+ spin_unlock(&dev->srq_table.lock);345345+346346+ if (!srq) {347347+ mthca_warn(dev, "Async event for bogus SRQ %08x\n", srqn);348348+ return;349349+ }350350+351351+ if (!srq->ibsrq.event_handler)352352+ goto out;353353+354354+ event.device = &dev->ib_dev;355355+ event.event = event_type;356356+ event.element.srq = &srq->ibsrq;357357+ srq->ibsrq.event_handler(&event, srq->ibsrq.srq_context);358358+359359+out:360360+ if (atomic_dec_and_test(&srq->refcount))361361+ wake_up(&srq->wait);362362+}363363+364364+/*365365+ * This function must be called with IRQs disabled.366366+ */367367+void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr)368368+{369369+ int ind;370370+371371+ ind = wqe_addr >> srq->wqe_shift;372372+373373+ spin_lock(&srq->lock);374374+375375+ if (likely(srq->first_free >= 0))376376+ *wqe_to_link(get_wqe(srq, srq->last_free)) = ind;377377+ else378378+ srq->first_free = ind;379379+380380+ *wqe_to_link(get_wqe(srq, ind)) = -1;381381+ srq->last_free = ind;382382+383383+ spin_unlock(&srq->lock);384384+}385385+386386+int mthca_tavor_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,387387+ struct ib_recv_wr **bad_wr)388388+{389389+ struct mthca_dev *dev = to_mdev(ibsrq->device);390390+ struct mthca_srq *srq = to_msrq(ibsrq);391391+ unsigned long flags;392392+ int err = 0;393393+ int first_ind;394394+ int ind;395395+ int next_ind;396396+ int nreq;397397+ int i;398398+ void *wqe;399399+ void *prev_wqe;400400+401401+ spin_lock_irqsave(&srq->lock, flags);402402+403403+ first_ind = srq->first_free;404404+405405+ for (nreq = 0; wr; ++nreq, wr = wr->next) {406406+ ind = srq->first_free;407407+408408+ if (ind < 0) {409409+ mthca_err(dev, "SRQ %06x full\n", srq->srqn);410410+ err = -ENOMEM;411411+ *bad_wr = wr;412412+ return nreq;413413+ }414414+415415+ wqe = get_wqe(srq, ind);416416+ next_ind = *wqe_to_link(wqe);417417+ prev_wqe = srq->last;418418+ srq->last = wqe;419419+420420+ ((struct mthca_next_seg *) wqe)->nda_op = 0;421421+ ((struct mthca_next_seg *) wqe)->ee_nds = 0;422422+ /* flags field will always remain 0 */423423+424424+ wqe += sizeof (struct mthca_next_seg);425425+426426+ if (unlikely(wr->num_sge > srq->max_gs)) {427427+ err = -EINVAL;428428+ *bad_wr = wr;429429+ srq->last = prev_wqe;430430+ return nreq;431431+ }432432+433433+ for (i = 0; i < wr->num_sge; ++i) {434434+ ((struct mthca_data_seg *) wqe)->byte_count =435435+ cpu_to_be32(wr->sg_list[i].length);436436+ ((struct mthca_data_seg *) wqe)->lkey =437437+ cpu_to_be32(wr->sg_list[i].lkey);438438+ ((struct mthca_data_seg *) wqe)->addr =439439+ cpu_to_be64(wr->sg_list[i].addr);440440+ wqe += sizeof (struct mthca_data_seg);441441+ }442442+443443+ if (i < srq->max_gs) {444444+ ((struct mthca_data_seg *) wqe)->byte_count = 0;445445+ ((struct mthca_data_seg *) wqe)->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);446446+ ((struct mthca_data_seg *) wqe)->addr = 0;447447+ }448448+449449+ if (likely(prev_wqe)) {450450+ ((struct mthca_next_seg *) prev_wqe)->nda_op =451451+ cpu_to_be32((ind << srq->wqe_shift) | 1);452452+ wmb();453453+ ((struct mthca_next_seg *) prev_wqe)->ee_nds =454454+ cpu_to_be32(MTHCA_NEXT_DBD);455455+ }456456+457457+ srq->wrid[ind] = wr->wr_id;458458+ srq->first_free = next_ind;459459+ }460460+461461+ return nreq;462462+463463+ if (likely(nreq)) {464464+ __be32 doorbell[2];465465+466466+ doorbell[0] = cpu_to_be32(first_ind << srq->wqe_shift);467467+ doorbell[1] = cpu_to_be32((srq->srqn << 8) | nreq);468468+469469+ /*470470+ * Make sure that descriptors are written before471471+ * doorbell is rung.472472+ */473473+ wmb();474474+475475+ mthca_write64(doorbell,476476+ dev->kar + MTHCA_RECEIVE_DOORBELL,477477+ MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));478478+ }479479+480480+ spin_unlock_irqrestore(&srq->lock, flags);481481+ return err;482482+}483483+484484+int mthca_arbel_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,485485+ struct ib_recv_wr **bad_wr)486486+{487487+ struct mthca_dev *dev = to_mdev(ibsrq->device);488488+ struct mthca_srq *srq = to_msrq(ibsrq);489489+ unsigned long flags;490490+ int err = 0;491491+ int ind;492492+ int next_ind;493493+ int nreq;494494+ int i;495495+ void *wqe;496496+497497+ spin_lock_irqsave(&srq->lock, flags);498498+499499+ for (nreq = 0; wr; ++nreq, wr = wr->next) {500500+ ind = srq->first_free;501501+502502+ if (ind < 0) {503503+ mthca_err(dev, "SRQ %06x full\n", srq->srqn);504504+ err = -ENOMEM;505505+ *bad_wr = wr;506506+ return nreq;507507+ }508508+509509+ wqe = get_wqe(srq, ind);510510+ next_ind = *wqe_to_link(wqe);511511+512512+ ((struct mthca_next_seg *) wqe)->nda_op =513513+ cpu_to_be32((next_ind << srq->wqe_shift) | 1);514514+ ((struct mthca_next_seg *) wqe)->ee_nds = 0;515515+ /* flags field will always remain 0 */516516+517517+ wqe += sizeof (struct mthca_next_seg);518518+519519+ if (unlikely(wr->num_sge > srq->max_gs)) {520520+ err = -EINVAL;521521+ *bad_wr = wr;522522+ return nreq;523523+ }524524+525525+ for (i = 0; i < wr->num_sge; ++i) {526526+ ((struct mthca_data_seg *) wqe)->byte_count =527527+ cpu_to_be32(wr->sg_list[i].length);528528+ ((struct mthca_data_seg *) wqe)->lkey =529529+ cpu_to_be32(wr->sg_list[i].lkey);530530+ ((struct mthca_data_seg *) wqe)->addr =531531+ cpu_to_be64(wr->sg_list[i].addr);532532+ wqe += sizeof (struct mthca_data_seg);533533+ }534534+535535+ if (i < srq->max_gs) {536536+ ((struct mthca_data_seg *) wqe)->byte_count = 0;537537+ ((struct mthca_data_seg *) wqe)->lkey = cpu_to_be32(MTHCA_INVAL_LKEY);538538+ ((struct mthca_data_seg *) wqe)->addr = 0;539539+ }540540+541541+ srq->wrid[ind] = wr->wr_id;542542+ srq->first_free = next_ind;543543+ }544544+545545+ if (likely(nreq)) {546546+ srq->counter += nreq;547547+548548+ /*549549+ * Make sure that descriptors are written before550550+ * we write doorbell record.551551+ */552552+ wmb();553553+ *srq->db = cpu_to_be32(srq->counter);554554+ }555555+556556+ spin_unlock_irqrestore(&srq->lock, flags);557557+ return err;558558+}559559+560560+int __devinit mthca_init_srq_table(struct mthca_dev *dev)561561+{562562+ int err;563563+564564+ if (!(dev->mthca_flags & MTHCA_FLAG_SRQ))565565+ return 0;566566+567567+ spin_lock_init(&dev->srq_table.lock);568568+569569+ err = mthca_alloc_init(&dev->srq_table.alloc,570570+ dev->limits.num_srqs,571571+ dev->limits.num_srqs - 1,572572+ dev->limits.reserved_srqs);573573+ if (err)574574+ return err;575575+576576+ err = mthca_array_init(&dev->srq_table.srq,577577+ dev->limits.num_srqs);578578+ if (err)579579+ mthca_alloc_cleanup(&dev->srq_table.alloc);580580+581581+ return err;582582+}583583+584584+void __devexit mthca_cleanup_srq_table(struct mthca_dev *dev)585585+{586586+ if (!(dev->mthca_flags & MTHCA_FLAG_SRQ))587587+ return;588588+589589+ mthca_array_cleanup(&dev->srq_table.srq, dev->limits.num_srqs);590590+ mthca_alloc_cleanup(&dev->srq_table.alloc);591591+}
···11+/*22+ * Copyright (c) 2005 Cisco Systems. All rights reserved.33+ *44+ * This software is available to you under a choice of one of two55+ * licenses. You may choose to be licensed under the terms of the GNU66+ * General Public License (GPL) Version 2, available from the file77+ * COPYING in the main directory of this source tree, or the88+ * OpenIB.org BSD license below:99+ *1010+ * Redistribution and use in source and binary forms, with or1111+ * without modification, are permitted provided that the following1212+ * conditions are met:1313+ *1414+ * - Redistributions of source code must retain the above1515+ * copyright notice, this list of conditions and the following1616+ * disclaimer.1717+ *1818+ * - Redistributions in binary form must reproduce the above1919+ * copyright notice, this list of conditions and the following2020+ * disclaimer in the documentation and/or other materials2121+ * provided with the distribution.2222+ *2323+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,2424+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF2525+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND2626+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS2727+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN2828+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN2929+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE3030+ * SOFTWARE.3131+ *3232+ * $Id: mthca_wqe.h 3047 2005-08-10 03:59:35Z roland $3333+ */3434+3535+#ifndef MTHCA_WQE_H3636+#define MTHCA_WQE_H3737+3838+#include <linux/types.h>3939+4040+enum {4141+ MTHCA_NEXT_DBD = 1 << 7,4242+ MTHCA_NEXT_FENCE = 1 << 6,4343+ MTHCA_NEXT_CQ_UPDATE = 1 << 3,4444+ MTHCA_NEXT_EVENT_GEN = 1 << 2,4545+ MTHCA_NEXT_SOLICIT = 1 << 1,4646+4747+ MTHCA_MLX_VL15 = 1 << 17,4848+ MTHCA_MLX_SLR = 1 << 164949+};5050+5151+enum {5252+ MTHCA_INVAL_LKEY = 0x1005353+};5454+5555+struct mthca_next_seg {5656+ __be32 nda_op; /* [31:6] next WQE [4:0] next opcode */5757+ __be32 ee_nds; /* [31:8] next EE [7] DBD [6] F [5:0] next WQE size */5858+ __be32 flags; /* [3] CQ [2] Event [1] Solicit */5959+ __be32 imm; /* immediate data */6060+};6161+6262+struct mthca_tavor_ud_seg {6363+ u32 reserved1;6464+ __be32 lkey;6565+ __be64 av_addr;6666+ u32 reserved2[4];6767+ __be32 dqpn;6868+ __be32 qkey;6969+ u32 reserved3[2];7070+};7171+7272+struct mthca_arbel_ud_seg {7373+ __be32 av[8];7474+ __be32 dqpn;7575+ __be32 qkey;7676+ u32 reserved[2];7777+};7878+7979+struct mthca_bind_seg {8080+ __be32 flags; /* [31] Atomic [30] rem write [29] rem read */8181+ u32 reserved;8282+ __be32 new_rkey;8383+ __be32 lkey;8484+ __be64 addr;8585+ __be64 length;8686+};8787+8888+struct mthca_raddr_seg {8989+ __be64 raddr;9090+ __be32 rkey;9191+ u32 reserved;9292+};9393+9494+struct mthca_atomic_seg {9595+ __be64 swap_add;9696+ __be64 compare;9797+};9898+9999+struct mthca_data_seg {100100+ __be32 byte_count;101101+ __be32 lkey;102102+ __be64 addr;103103+};104104+105105+struct mthca_mlx_seg {106106+ __be32 nda_op;107107+ __be32 nds;108108+ __be32 flags; /* [17] VL15 [16] SLR [14:12] static rate109109+ [11:8] SL [3] C [2] E */110110+ __be16 rlid;111111+ __be16 vcrc;112112+};113113+114114+#endif /* MTHCA_WQE_H */
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Intel Corporation. All rights reserved.44+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···3735#ifndef _IB_CACHE_H3836#define _IB_CACHE_H39374040-#include <ib_verbs.h>3838+#include <rdma/ib_verbs.h>41394240/**4341 * ib_get_cached_gid - Returns a cached GID table entry
···44 * Copyright (c) 2004 Intel Corporation. All rights reserved.55 * Copyright (c) 2004 Topspin Corporation. All rights reserved.66 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.77+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.78 * Copyright (c) 2005 Cisco Systems. All rights reserved.89 *910 * This software is available to you under a choice of one of two···5150union ib_gid {5251 u8 raw[16];5352 struct {5454- u64 subnet_prefix;5555- u64 interface_id;5353+ __be64 subnet_prefix;5454+ __be64 interface_id;5655 } global;5756};5857···88878988struct ib_device_attr {9089 u64 fw_ver;9191- u64 node_guid;9292- u64 sys_image_guid;9090+ __be64 node_guid;9191+ __be64 sys_image_guid;9392 u64 max_mr_size;9493 u64 page_size_cap;9594 u32 vendor_id;···256255 IB_EVENT_PORT_ERR,257256 IB_EVENT_LID_CHANGE,258257 IB_EVENT_PKEY_CHANGE,259259- IB_EVENT_SM_CHANGE258258+ IB_EVENT_SM_CHANGE,259259+ IB_EVENT_SRQ_ERR,260260+ IB_EVENT_SRQ_LIMIT_REACHED,261261+ IB_EVENT_QP_LAST_WQE_REACHED260262};261263262264struct ib_event {···267263 union {268264 struct ib_cq *cq;269265 struct ib_qp *qp;266266+ struct ib_srq *srq;270267 u8 port_num;271268 } element;272269 enum ib_event_type event;···295290};296291297292struct ib_grh {298298- u32 version_tclass_flow;299299- u16 paylen;293293+ __be32 version_tclass_flow;294294+ __be16 paylen;300295 u8 next_hdr;301296 u8 hop_limit;302297 union ib_gid sgid;···306301enum {307302 IB_MULTICAST_QPN = 0xffffff308303};304304+305305+#define IB_LID_PERMISSIVE __constant_htons(0xFFFF)309306310307enum ib_ah_flags {311308 IB_AH_GRH = 1···388381enum ib_cq_notify {389382 IB_CQ_SOLICITED,390383 IB_CQ_NEXT_COMP384384+};385385+386386+enum ib_srq_attr_mask {387387+ IB_SRQ_MAX_WR = 1 << 0,388388+ IB_SRQ_LIMIT = 1 << 1,389389+};390390+391391+struct ib_srq_attr {392392+ u32 max_wr;393393+ u32 max_sge;394394+ u32 srq_limit;395395+};396396+397397+struct ib_srq_init_attr {398398+ void (*event_handler)(struct ib_event *, void *);399399+ void *srq_context;400400+ struct ib_srq_attr attr;391401};392402393403struct ib_qp_cap {···734710};735711736712struct ib_srq {737737- struct ib_device *device;738738- struct ib_uobject *uobject;739739- struct ib_pd *pd;740740- void *srq_context;713713+ struct ib_device *device;714714+ struct ib_pd *pd;715715+ struct ib_uobject *uobject;716716+ void (*event_handler)(struct ib_event *, void *);717717+ void *srq_context;741718 atomic_t usecnt;742719};743720···852827 int (*query_ah)(struct ib_ah *ah,853828 struct ib_ah_attr *ah_attr);854829 int (*destroy_ah)(struct ib_ah *ah);830830+ struct ib_srq * (*create_srq)(struct ib_pd *pd,831831+ struct ib_srq_init_attr *srq_init_attr,832832+ struct ib_udata *udata);833833+ int (*modify_srq)(struct ib_srq *srq,834834+ struct ib_srq_attr *srq_attr,835835+ enum ib_srq_attr_mask srq_attr_mask);836836+ int (*query_srq)(struct ib_srq *srq,837837+ struct ib_srq_attr *srq_attr);838838+ int (*destroy_srq)(struct ib_srq *srq);839839+ int (*post_srq_recv)(struct ib_srq *srq,840840+ struct ib_recv_wr *recv_wr,841841+ struct ib_recv_wr **bad_recv_wr);855842 struct ib_qp * (*create_qp)(struct ib_pd *pd,856843 struct ib_qp_init_attr *qp_init_attr,857844 struct ib_udata *udata);···10741037 * @ah: The address handle to destroy.10751038 */10761039int ib_destroy_ah(struct ib_ah *ah);10401040+10411041+/**10421042+ * ib_create_srq - Creates a SRQ associated with the specified protection10431043+ * domain.10441044+ * @pd: The protection domain associated with the SRQ.10451045+ * @srq_init_attr: A list of initial attributes required to create the SRQ.10461046+ *10471047+ * srq_attr->max_wr and srq_attr->max_sge are read the determine the10481048+ * requested size of the SRQ, and set to the actual values allocated10491049+ * on return. If ib_create_srq() succeeds, then max_wr and max_sge10501050+ * will always be at least as large as the requested values.10511051+ */10521052+struct ib_srq *ib_create_srq(struct ib_pd *pd,10531053+ struct ib_srq_init_attr *srq_init_attr);10541054+10551055+/**10561056+ * ib_modify_srq - Modifies the attributes for the specified SRQ.10571057+ * @srq: The SRQ to modify.10581058+ * @srq_attr: On input, specifies the SRQ attributes to modify. On output,10591059+ * the current values of selected SRQ attributes are returned.10601060+ * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ10611061+ * are being modified.10621062+ *10631063+ * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or10641064+ * IB_SRQ_LIMIT to set the SRQ's limit and request notification when10651065+ * the number of receives queued drops below the limit.10661066+ */10671067+int ib_modify_srq(struct ib_srq *srq,10681068+ struct ib_srq_attr *srq_attr,10691069+ enum ib_srq_attr_mask srq_attr_mask);10701070+10711071+/**10721072+ * ib_query_srq - Returns the attribute list and current values for the10731073+ * specified SRQ.10741074+ * @srq: The SRQ to query.10751075+ * @srq_attr: The attributes of the specified SRQ.10761076+ */10771077+int ib_query_srq(struct ib_srq *srq,10781078+ struct ib_srq_attr *srq_attr);10791079+10801080+/**10811081+ * ib_destroy_srq - Destroys the specified SRQ.10821082+ * @srq: The SRQ to destroy.10831083+ */10841084+int ib_destroy_srq(struct ib_srq *srq);10851085+10861086+/**10871087+ * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.10881088+ * @srq: The SRQ to post the work request on.10891089+ * @recv_wr: A list of work requests to post on the receive queue.10901090+ * @bad_recv_wr: On an immediate failure, this parameter will reference10911091+ * the work request that failed to be posted on the QP.10921092+ */10931093+static inline int ib_post_srq_recv(struct ib_srq *srq,10941094+ struct ib_recv_wr *recv_wr,10951095+ struct ib_recv_wr **bad_recv_wr)10961096+{10971097+ return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);10981098+}1077109910781100/**10791101 * ib_create_qp - Creates a QP associated with the specified protection
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···5149#include <asm/atomic.h>5250#include <asm/semaphore.h>53515454-#include <ib_verbs.h>5555-#include <ib_pack.h>5656-#include <ib_sa.h>5252+#include <rdma/ib_verbs.h>5353+#include <rdma/ib_pack.h>5454+#include <rdma/ib_sa.h>57555856/* constants */5957···9088/* structs */91899290struct ipoib_header {9393- u16 proto;9494- u16 reserved;9191+ __be16 proto;9292+ u16 reserved;9593};96949795struct ipoib_pseudoheader {
+1-1
drivers/infiniband/ulp/ipoib/ipoib_fs.c
···97979898 for (n = 0, i = 0; i < sizeof mgid / 2; ++i) {9999 n += sprintf(gid_buf + n, "%x",100100- be16_to_cpu(((u16 *)mgid.raw)[i]));100100+ be16_to_cpu(((__be16 *) mgid.raw)[i]));101101 if (i < sizeof mgid / 2 - 1)102102 gid_buf[n++] = ':';103103 }
+4-1
drivers/infiniband/ulp/ipoib/ipoib_ib.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.55+ * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.36 *47 * This software is available to you under a choice of one of two58 * licenses. You may choose to be licensed under the terms of the GNU···3835#include <linux/delay.h>3936#include <linux/dma-mapping.h>40374141-#include <ib_cache.h>3838+#include <rdma/ib_cache.h>42394340#include "ipoib.h"4441
+21-12
drivers/infiniband/ulp/ipoib/ipoib_main.c
···11/*22 * Copyright (c) 2004 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···36343735#include "ipoib.h"38363939-#include <linux/version.h>4037#include <linux/module.h>41384239#include <linux/init.h>···608607 ipoib_warn(priv, "Unicast, no %s: type %04x, QPN %06x "609608 IPOIB_GID_FMT "\n",610609 skb->dst ? "neigh" : "dst",611611- be16_to_cpup((u16 *) skb->data),612612- be32_to_cpup((u32 *) phdr->hwaddr),610610+ be16_to_cpup((__be16 *) skb->data),611611+ be32_to_cpup((__be32 *) phdr->hwaddr),613612 IPOIB_GID_ARG(*(union ib_gid *) (phdr->hwaddr + 4)));614613 dev_kfree_skb_any(skb);615614 ++priv->stats.tx_dropped;···672671{673672 struct ipoib_dev_priv *priv = netdev_priv(dev);674673675675- schedule_work(&priv->restart_task);674674+ queue_work(ipoib_workqueue, &priv->restart_task);676675}677676678677static void ipoib_neigh_destructor(struct neighbour *n)···781780782781 ipoib_ib_dev_cleanup(dev);783782784784- if (priv->rx_ring) {785785- kfree(priv->rx_ring);786786- priv->rx_ring = NULL;787787- }783783+ kfree(priv->rx_ring);784784+ kfree(priv->tx_ring);788785789789- if (priv->tx_ring) {790790- kfree(priv->tx_ring);791791- priv->tx_ring = NULL;792792- }786786+ priv->rx_ring = NULL;787787+ priv->tx_ring = NULL;793788}794789795790static void ipoib_setup(struct net_device *dev)···883886 if (pkey < 0 || pkey > 0xffff)884887 return -EINVAL;885888889889+ /*890890+ * Set the full membership bit, so that we join the right891891+ * broadcast group, etc.892892+ */893893+ pkey |= 0x8000;894894+886895 ret = ipoib_vlan_add(container_of(cdev, struct net_device, class_dev),887896 pkey);888897···940937 hca->name, port, result);941938 goto alloc_mem_failed;942939 }940940+941941+ /*942942+ * Set the full membership bit, so that we join the right943943+ * broadcast group, etc.944944+ */945945+ priv->pkey |= 0x8000;943946944947 priv->dev->broadcast[8] = priv->pkey >> 8;945948 priv->dev->broadcast[9] = priv->pkey & 0xff;
+5-3
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.44+ * Copyright (c) 2004 Voltaire, Inc. All rights reserved.35 *46 * This software is available to you under a choice of one of two57 * licenses. You may choose to be licensed under the terms of the GNU···359357360358 rec.mgid = mcast->mcmember.mgid;361359 rec.port_gid = priv->local_gid;362362- rec.pkey = be16_to_cpu(priv->pkey);360360+ rec.pkey = cpu_to_be16(priv->pkey);363361364362 ret = ib_sa_mcmember_rec_set(priv->ca, priv->port, &rec,365363 IB_SA_MCMEMBER_REC_MGID |···459457460458 rec.mgid = mcast->mcmember.mgid;461459 rec.port_gid = priv->local_gid;462462- rec.pkey = be16_to_cpu(priv->pkey);460460+ rec.pkey = cpu_to_be16(priv->pkey);463461464462 comp_mask =465463 IB_SA_MCMEMBER_REC_MGID |···648646649647 rec.mgid = mcast->mcmember.mgid;650648 rec.port_gid = priv->local_gid;651651- rec.pkey = be16_to_cpu(priv->pkey);649649+ rec.pkey = cpu_to_be16(priv->pkey);652650653651 /* Remove ourselves from the multicast group */654652 ret = ipoib_mcast_detach(dev, be16_to_cpu(mcast->mcmember.mlid),
+2-1
drivers/infiniband/ulp/ipoib/ipoib_verbs.c
···11/*22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.33+ * Copyright (c) 2005 Mellanox Technologies. All rights reserved.34 *45 * This software is available to you under a choice of one of two56 * licenses. You may choose to be licensed under the terms of the GNU···3332 * $Id: ipoib_verbs.c 1349 2004-12-16 21:09:43Z roland $3433 */35343636-#include <ib_cache.h>3535+#include <rdma/ib_cache.h>37363837#include "ipoib.h"3938