RE: [PATCH 5/9] ocrdma: Driver for Emulex OneConnect RDMA adapter
> -Original Message- > From: Hefty, Sean [mailto:sean.he...@intel.com] > Sent: Thursday, March 22, 2012 6:14 AM > To: Pandit, Parav; linux-rdma@vger.kernel.org > Subject: RE: [PATCH 5/9] ocrdma: Driver for Emulex OneConnect RDMA > adapter > > > +static int ocrdma_inet6addr_event(struct notifier_block *, > > + unsigned long, void *); > > + > > +static struct notifier_block ocrdma_inet6addr_notifier = { > > + .notifier_call = ocrdma_inet6addr_event }; > > + > > +int ocrdma_get_instance(void) > > +{ > > + int instance = 0; > > + > > + /* Assign an unused number */ > > + if (!idr_pre_get(&ocrdma_dev_id, GFP_KERNEL)) > > + return -1; > > + if (idr_get_new(&ocrdma_dev_id, NULL, &instance)) > > + return -1; > > + return instance; > > +} > > + > > +void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid) { > > + u8 mac_addr[6]; > > + > > + memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN); > > + guid[0] = mac_addr[0] ^ 2; > > + guid[1] = mac_addr[1]; > > + guid[2] = mac_addr[2]; > > + guid[3] = 0xff; > > + guid[4] = 0xfe; > > + guid[5] = mac_addr[3]; > > + guid[6] = mac_addr[4]; > > + guid[7] = mac_addr[5]; > > +} > > + > > +static void ocrdma_build_sgid_mac(union ib_gid *sgid, unsigned char > > *mac_addr, > > + bool is_vlan, u16 vlan_id) > > +{ > > + sgid->global.subnet_prefix = cpu_to_be64(0xfe80LL); > > + sgid->raw[8] = mac_addr[0] ^ 2; > > + sgid->raw[9] = mac_addr[1]; > > + sgid->raw[10] = mac_addr[2]; > > + if (is_vlan) { > > + sgid->raw[11] = vlan_id >> 8; > > + sgid->raw[12] = vlan_id & 0xff; > > + } else { > > + sgid->raw[11] = 0xff; > > + sgid->raw[12] = 0xfe; > > + } > > + sgid->raw[13] = mac_addr[3]; > > + sgid->raw[14] = mac_addr[4]; > > + sgid->raw[15] = mac_addr[5]; > > +} > > + > > +static void ocrdma_add_sgid(struct ocrdma_dev *dev, unsigned char > *mac_addr, > > + bool is_vlan, u16 vlan_id) > > +{ > > + int i; > > + bool found = false; > > + union ib_gid new_sgid; > > + int free_idx = OCRDMA_MAX_SGID; > > + unsigned long flags; > > + > > + memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid)); > > ocrdma_zero_sgid should already be zeroed > Yes. Removed memset(). > Actually, can't we either use in6addr_any instead? I see that the mlx4 driver > also has a zero gid. So, if we don't want to overload the use of in6addr_any, > we can define gid_zero in ib_core. o.k. once its defined in ib_core, will remove this and provide a subsequent patch. It will be easier to handle it. > > > + > > + ocrdma_build_sgid_mac(&new_sgid, mac_addr, is_vlan, vlan_id); > > + > > + spin_lock_irqsave(&dev->sgid_lock, flags); > > + for (i = 0; i < OCRDMA_MAX_SGID; i++) { > > + if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid, > > + sizeof(union ib_gid))) { > > + /* found free entry */ > > + if (!found) { > > + free_idx = i; > > + found = true; > > + break; > > + } > > + } else if (!memcmp(&dev->sgid_tbl[i], &new_sgid, > > + sizeof(union ib_gid))) { > > + /* entry already present, no addition is required. */ > > + spin_unlock_irqrestore(&dev->sgid_lock, flags); > > + return; > > + } > > + } > > + /* if entry doesn't exist and if table has some space, add entry */ > > + if (found) > > + memcpy(&dev->sgid_tbl[free_idx], &new_sgid, > > + sizeof(union ib_gid)); > > can move memcpy into for loop and remove found flag > Yes, removed. > > + spin_unlock_irqrestore(&dev->sgid_lock, flags); } -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 5/9] ocrdma: Driver for Emulex OneConnect RDMA adapter
> +static int ocrdma_inet6addr_event(struct notifier_block *, > + unsigned long, void *); > + > +static struct notifier_block ocrdma_inet6addr_notifier = { > + .notifier_call = ocrdma_inet6addr_event > +}; > + > +int ocrdma_get_instance(void) > +{ > + int instance = 0; > + > + /* Assign an unused number */ > + if (!idr_pre_get(&ocrdma_dev_id, GFP_KERNEL)) > + return -1; > + if (idr_get_new(&ocrdma_dev_id, NULL, &instance)) > + return -1; > + return instance; > +} > + > +void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid) > +{ > + u8 mac_addr[6]; > + > + memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN); > + guid[0] = mac_addr[0] ^ 2; > + guid[1] = mac_addr[1]; > + guid[2] = mac_addr[2]; > + guid[3] = 0xff; > + guid[4] = 0xfe; > + guid[5] = mac_addr[3]; > + guid[6] = mac_addr[4]; > + guid[7] = mac_addr[5]; > +} > + > +static void ocrdma_build_sgid_mac(union ib_gid *sgid, unsigned char > *mac_addr, > + bool is_vlan, u16 vlan_id) > +{ > + sgid->global.subnet_prefix = cpu_to_be64(0xfe80LL); > + sgid->raw[8] = mac_addr[0] ^ 2; > + sgid->raw[9] = mac_addr[1]; > + sgid->raw[10] = mac_addr[2]; > + if (is_vlan) { > + sgid->raw[11] = vlan_id >> 8; > + sgid->raw[12] = vlan_id & 0xff; > + } else { > + sgid->raw[11] = 0xff; > + sgid->raw[12] = 0xfe; > + } > + sgid->raw[13] = mac_addr[3]; > + sgid->raw[14] = mac_addr[4]; > + sgid->raw[15] = mac_addr[5]; > +} > + > +static void ocrdma_add_sgid(struct ocrdma_dev *dev, unsigned char *mac_addr, > + bool is_vlan, u16 vlan_id) > +{ > + int i; > + bool found = false; > + union ib_gid new_sgid; > + int free_idx = OCRDMA_MAX_SGID; > + unsigned long flags; > + > + memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid)); ocrdma_zero_sgid should already be zeroed Actually, can't we either use in6addr_any instead? I see that the mlx4 driver also has a zero gid. So, if we don't want to overload the use of in6addr_any, we can define gid_zero in ib_core. > + > + ocrdma_build_sgid_mac(&new_sgid, mac_addr, is_vlan, vlan_id); > + > + spin_lock_irqsave(&dev->sgid_lock, flags); > + for (i = 0; i < OCRDMA_MAX_SGID; i++) { > + if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid, > + sizeof(union ib_gid))) { > + /* found free entry */ > + if (!found) { > + free_idx = i; > + found = true; > + break; > + } > + } else if (!memcmp(&dev->sgid_tbl[i], &new_sgid, > +sizeof(union ib_gid))) { > + /* entry already present, no addition is required. */ > + spin_unlock_irqrestore(&dev->sgid_lock, flags); > + return; > + } > + } > + /* if entry doesn't exist and if table has some space, add entry */ > + if (found) > + memcpy(&dev->sgid_tbl[free_idx], &new_sgid, > +sizeof(union ib_gid)); can move memcpy into for loop and remove found flag > + spin_unlock_irqrestore(&dev->sgid_lock, flags); > +} -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 5/9] ocrdma: Driver for Emulex OneConnect RDMA adapter
From: Parav Pandit Signed-off-by: Parav Pandit --- drivers/infiniband/hw/ocrdma/ocrdma_main.c | 558 1 files changed, 558 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/ocrdma/ocrdma_main.c diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c new file mode 100644 index 000..8aa3416 --- /dev/null +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c @@ -0,0 +1,558 @@ +/*** + * This file is part of the Emulex RoCE Device Driver for * + * RoCE (RDMA over Converged Ethernet) adapters. * + * Copyright (C) 2008-2012 Emulex. All rights reserved.* + * EMULEX and SLI are trademarks of Emulex.* + * www.emulex.com * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of version 2 of the GNU General * + * Public License as published by the Free Software Foundation.* + * This program is distributed in the hope that it will be useful. * + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * + * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * + * TO BE LEGALLY INVALID. See the GNU General Public License for * + * more details, a copy of which can be found in the file COPYING * + * included with this package. * + * + * Contact Information: + * linux-driv...@emulex.com + * + * Emulex + * Susan Street + * Costa Mesa, CA 92626 + ***/ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ocrdma.h" +#include "ocrdma_verbs.h" +#include "ocrdma_ah.h" +#include "be_roce.h" +#include "ocrdma_hw.h" + +MODULE_VERSION(OCRDMA_ROCE_DEV_VERSION); +MODULE_DESCRIPTION("Emulex RoCE HCA Driver"); +MODULE_AUTHOR("Emulex Corporation"); +MODULE_LICENSE("GPL"); + +static LIST_HEAD(ocrdma_dev_list); +static DEFINE_MUTEX(ocrdma_devlist_lock); +static DEFINE_IDR(ocrdma_dev_id); + +static union ib_gid ocrdma_zero_sgid; +static int ocrdma_inet6addr_event(struct notifier_block *, + unsigned long, void *); + +static struct notifier_block ocrdma_inet6addr_notifier = { + .notifier_call = ocrdma_inet6addr_event +}; + +int ocrdma_get_instance(void) +{ + int instance = 0; + + /* Assign an unused number */ + if (!idr_pre_get(&ocrdma_dev_id, GFP_KERNEL)) + return -1; + if (idr_get_new(&ocrdma_dev_id, NULL, &instance)) + return -1; + return instance; +} + +void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid) +{ + u8 mac_addr[6]; + + memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN); + guid[0] = mac_addr[0] ^ 2; + guid[1] = mac_addr[1]; + guid[2] = mac_addr[2]; + guid[3] = 0xff; + guid[4] = 0xfe; + guid[5] = mac_addr[3]; + guid[6] = mac_addr[4]; + guid[7] = mac_addr[5]; +} + +static void ocrdma_build_sgid_mac(union ib_gid *sgid, unsigned char *mac_addr, + bool is_vlan, u16 vlan_id) +{ + sgid->global.subnet_prefix = cpu_to_be64(0xfe80LL); + sgid->raw[8] = mac_addr[0] ^ 2; + sgid->raw[9] = mac_addr[1]; + sgid->raw[10] = mac_addr[2]; + if (is_vlan) { + sgid->raw[11] = vlan_id >> 8; + sgid->raw[12] = vlan_id & 0xff; + } else { + sgid->raw[11] = 0xff; + sgid->raw[12] = 0xfe; + } + sgid->raw[13] = mac_addr[3]; + sgid->raw[14] = mac_addr[4]; + sgid->raw[15] = mac_addr[5]; +} + +static void ocrdma_add_sgid(struct ocrdma_dev *dev, unsigned char *mac_addr, + bool is_vlan, u16 vlan_id) +{ + int i; + bool found = false; + union ib_gid new_sgid; + int free_idx = OCRDMA_MAX_SGID; + unsigned long flags; + + memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid)); + + ocrdma_build_sgid_mac(&new_sgid, mac_addr, is_vlan, vlan_id); + + spin_lock_irqsave(&dev->sgid_lock, flags); + for (i = 0; i < OCRDMA_MAX_SGID; i++) { + if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid, + sizeof(union ib_gid))) { + /* found free entry */ + if (!found) { + free_idx = i; + found = true; + break; + } + } else if (!memcmp(&dev->sgid_tbl[i], &new_sgid, +