From patchwork Thu Feb 18 17:25:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Cohen X-Patchwork-Id: 80366 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1IHP1QU001005 for ; Thu, 18 Feb 2010 17:25:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758555Ab0BRRZR (ORCPT ); Thu, 18 Feb 2010 12:25:17 -0500 Received: from mail.mellanox.co.il ([194.90.237.43]:40321 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758524Ab0BRRZQ (ORCPT ); Thu, 18 Feb 2010 12:25:16 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from eli@mellanox.co.il) with SMTP; 18 Feb 2010 19:25:14 +0200 Received: from localhost ([10.4.1.30]) by mtlexch01.mtl.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 18 Feb 2010 19:25:13 +0200 Date: Thu, 18 Feb 2010 19:25:21 +0200 From: Eli Cohen To: Roland Dreier Cc: Linux RDMA list , ewg Subject: [PATCHv8 1/2] libmlx4: Add IBoE support Message-ID: <20100218172521.GQ12286@mtls03> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-OriginalArrivalTime: 18 Feb 2010 17:25:13.0826 (UTC) FILETIME=[549C6C20:01CAB0BF] X-TM-AS-Product-Ver: SMEX-8.0.0.1181-6.000.1038-17202.000 X-TM-AS-Result: No--10.354000-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 18 Feb 2010 17:25:18 +0000 (UTC) diff --git a/src/mlx4.h b/src/mlx4.h index 4445998..4b12456 100644 --- a/src/mlx4.h +++ b/src/mlx4.h @@ -236,11 +236,15 @@ struct mlx4_av { uint8_t hop_limit; uint32_t sl_tclass_flowlabel; uint8_t dgid[16]; + uint8_t mac[8]; }; struct mlx4_ah { struct ibv_ah ibv_ah; struct mlx4_av av; + uint16_t vlan; + uint8_t mac[6]; + uint8_t tagged; }; static inline unsigned long align(unsigned long val, unsigned long align) diff --git a/src/qp.c b/src/qp.c index d194ae3..fa70889 100644 --- a/src/qp.c +++ b/src/qp.c @@ -143,6 +143,8 @@ static void set_datagram_seg(struct mlx4_wqe_datagram_seg *dseg, memcpy(dseg->av, &to_mah(wr->wr.ud.ah)->av, sizeof (struct mlx4_av)); dseg->dqpn = htonl(wr->wr.ud.remote_qpn); dseg->qkey = htonl(wr->wr.ud.remote_qkey); + dseg->vlan = htons(to_mah(wr->wr.ud.ah)->vlan); + memcpy(dseg->mac, to_mah(wr->wr.ud.ah)->mac, 6); } static void __set_data_seg(struct mlx4_wqe_data_seg *dseg, struct ibv_sge *sg) @@ -281,6 +283,10 @@ int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, set_datagram_seg(wqe, wr); wqe += sizeof (struct mlx4_wqe_datagram_seg); size += sizeof (struct mlx4_wqe_datagram_seg) / 16; + if (to_mah(wr->wr.ud.ah)->tagged) { + ctrl->ins_vlan = 1 << 6; + ctrl->vlan_tag = htons(to_mah(wr->wr.ud.ah)->vlan); + } break; default: @@ -393,7 +399,7 @@ out: if (nreq == 1 && inl && size > 1 && size < ctx->bf_buf_size / 16) { ctrl->owner_opcode |= htonl((qp->sq.head & 0xffff) << 8); - *(uint32_t *) ctrl->reserved |= qp->doorbell_qpn; + *(uint32_t *) (&ctrl->vlan_tag) |= qp->doorbell_qpn; /* * Make sure that descriptor is written to memory * before writing to BlueFlame page. diff --git a/src/verbs.c b/src/verbs.c index 1ac1362..48731a7 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -614,9 +614,21 @@ int mlx4_destroy_qp(struct ibv_qp *ibqp) return 0; } +static int mcast_mac(uint8_t *mac) +{ + int i; + uint8_t val = 0xff; + + for (i = 0; i < 6; ++i) + val &= mac[i]; + + return val == 0xff; +} + struct ibv_ah *mlx4_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr) { struct mlx4_ah *ah; + struct ibv_port_attr port_attr; ah = malloc(sizeof *ah); if (!ah) @@ -642,7 +654,29 @@ struct ibv_ah *mlx4_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr) memcpy(ah->av.dgid, attr->grh.dgid.raw, 16); } + if (ibv_query_port(pd->context, attr->port_num, &port_attr)) + goto err; + + if (port_attr.link_layer == IBV_LINK_LAYER_ETHERNET) { + if (ibv_cmd_get_eth_l2_addr(pd, attr->port_num, + (const union ibv_gid *)ah->av.dgid, + attr->grh.sgid_index, + ah->mac, &ah->vlan, &ah->tagged)) + goto err; + + if (mcast_mac(ah->mac)) + ah->av.dlid = htons(0xc000); + if (ah->tagged) { + ah->av.port_pd |= htonl(1 << 29); + ah->vlan |= (attr->sl & 7) << 13; + } + } + + return &ah->ibv_ah; +err: + free(ah); + return NULL; } int mlx4_destroy_ah(struct ibv_ah *ah) diff --git a/src/wqe.h b/src/wqe.h index 6f7f309..1e6159c 100644 --- a/src/wqe.h +++ b/src/wqe.h @@ -54,7 +54,8 @@ enum { struct mlx4_wqe_ctrl_seg { uint32_t owner_opcode; - uint8_t reserved[3]; + uint16_t vlan_tag; + uint8_t ins_vlan; uint8_t fence_size; /* * High 24 bits are SRC remote buffer; low 8 bits are flags: @@ -78,7 +79,8 @@ struct mlx4_wqe_datagram_seg { uint32_t av[8]; uint32_t dqpn; uint32_t qkey; - uint32_t reserved[2]; + uint16_t vlan; + uint8_t mac[6]; }; struct mlx4_wqe_data_seg {