Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (c) 2012 Mellanox Technologies.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * licenses.  You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *     Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *     without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *     conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *      - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *        disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *      - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *        disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *        provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*#include "core_priv.h"*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "mlx4_ib.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <rdma/ib_mad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*show_admin_alias_guid returns the administratively assigned value of that GUID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * Values returned in buf parameter string:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *	0			- requests opensm to assign a value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *	ffffffffffffffff	- delete this entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *	other			- value assigned by administrator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static ssize_t show_admin_alias_guid(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			      struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct mlx4_ib_iov_sysfs_attr *mlx4_ib_iov_dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		container_of(attr, struct mlx4_ib_iov_sysfs_attr, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct mlx4_ib_iov_port *port = mlx4_ib_iov_dentry->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct mlx4_ib_dev *mdev = port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	__be64 sysadmin_ag_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	sysadmin_ag_val = mlx4_get_admin_guid(mdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 					      mlx4_ib_iov_dentry->entry_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 					      port->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return sprintf(buf, "%llx\n", be64_to_cpu(sysadmin_ag_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* store_admin_alias_guid stores the (new) administratively assigned value of that GUID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * Values in buf parameter string:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *	0			- requests opensm to assign a value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *	0xffffffffffffffff	- delete this entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *	other			- guid value assigned by the administrator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static ssize_t store_admin_alias_guid(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				      const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int record_num;/*0-15*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int guid_index_in_rec; /*0 - 7*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct mlx4_ib_iov_sysfs_attr *mlx4_ib_iov_dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		container_of(attr, struct mlx4_ib_iov_sysfs_attr, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct mlx4_ib_iov_port *port = mlx4_ib_iov_dentry->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct mlx4_ib_dev *mdev = port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u64 sysadmin_ag_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	record_num = mlx4_ib_iov_dentry->entry_num / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	guid_index_in_rec = mlx4_ib_iov_dentry->entry_num % 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (0 == record_num && 0 == guid_index_in_rec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		pr_err("GUID 0 block 0 is RO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spin_lock_irqsave(&mdev->sriov.alias_guid.ag_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	sscanf(buf, "%llx", &sysadmin_ag_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	*(__be64 *)&mdev->sriov.alias_guid.ports_guid[port->num - 1].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		all_rec_per_port[record_num].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		all_recs[GUID_REC_SIZE * guid_index_in_rec] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			cpu_to_be64(sysadmin_ag_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	/* Change the state to be pending for update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	mdev->sriov.alias_guid.ports_guid[port->num - 1].all_rec_per_port[record_num].status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		= MLX4_GUID_INFO_STATUS_IDLE ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	mlx4_set_admin_guid(mdev->dev, cpu_to_be64(sysadmin_ag_val),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			    mlx4_ib_iov_dentry->entry_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			    port->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* set the record index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	mdev->sriov.alias_guid.ports_guid[port->num - 1].all_rec_per_port[record_num].guid_indexes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		|= mlx4_ib_get_aguid_comp_mask_from_ix(guid_index_in_rec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	spin_unlock_irqrestore(&mdev->sriov.alias_guid.ag_work_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	mlx4_ib_init_alias_guid_work(mdev, port->num - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static ssize_t show_port_gid(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			     struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct mlx4_ib_iov_sysfs_attr *mlx4_ib_iov_dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		container_of(attr, struct mlx4_ib_iov_sysfs_attr, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct mlx4_ib_iov_port *port = mlx4_ib_iov_dentry->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct mlx4_ib_dev *mdev = port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	union ib_gid gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ret = __mlx4_ib_query_gid(&mdev->ib_dev, port->num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				  mlx4_ib_iov_dentry->entry_num, &gid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ret = sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		      be16_to_cpu(((__be16 *) gid.raw)[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		      be16_to_cpu(((__be16 *) gid.raw)[1]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		      be16_to_cpu(((__be16 *) gid.raw)[2]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		      be16_to_cpu(((__be16 *) gid.raw)[3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		      be16_to_cpu(((__be16 *) gid.raw)[4]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		      be16_to_cpu(((__be16 *) gid.raw)[5]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		      be16_to_cpu(((__be16 *) gid.raw)[6]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		      be16_to_cpu(((__be16 *) gid.raw)[7]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static ssize_t show_phys_port_pkey(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct mlx4_ib_iov_sysfs_attr *mlx4_ib_iov_dentry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		container_of(attr, struct mlx4_ib_iov_sysfs_attr, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct mlx4_ib_iov_port *port = mlx4_ib_iov_dentry->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct mlx4_ib_dev *mdev = port->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u16 pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	ret = __mlx4_ib_query_pkey(&mdev->ib_dev, port->num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				   mlx4_ib_iov_dentry->entry_num, &pkey, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return sprintf(buf, "0x%04x\n", pkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define DENTRY_REMOVE(_dentry)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) do {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	sysfs_remove_file((_dentry)->kobj, &(_dentry)->dentry.attr);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } while (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int create_sysfs_entry(void *_ctx, struct mlx4_ib_iov_sysfs_attr *_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			      char *_name, struct kobject *_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			      ssize_t (*show)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 					      struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 					      char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			      ssize_t (*store)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 					       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 					       const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			      )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct mlx4_ib_iov_sysfs_attr *vdentry = _dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	vdentry->ctx = _ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	vdentry->dentry.show = show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	vdentry->dentry.store = store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	sysfs_attr_init(&vdentry->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	vdentry->dentry.attr.name = vdentry->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	vdentry->dentry.attr.mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	vdentry->kobj = _kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	snprintf(vdentry->name, 15, "%s", _name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (vdentry->dentry.store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		vdentry->dentry.attr.mode |= S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (vdentry->dentry.show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		vdentry->dentry.attr.mode |= S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	ret = sysfs_create_file(vdentry->kobj, &vdentry->dentry.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		pr_err("failed to create %s\n", vdentry->dentry.attr.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		vdentry->ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int add_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		struct attribute *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct mlx4_ib_iov_port *port = &device->iov_ports[port_num - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	ret = sysfs_create_file(port->mcgs_parent, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		pr_err("failed to create %s\n", attr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) void del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		struct attribute *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct mlx4_ib_iov_port *port = &device->iov_ports[port_num - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	sysfs_remove_file(port->mcgs_parent, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int add_port_entries(struct mlx4_ib_dev *device, int port_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	char buff[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct mlx4_ib_iov_port *port = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int ret = 0 ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct ib_port_attr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	memset(&attr, 0, sizeof(attr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/* get the physical gid and pkey table sizes.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	ret = __mlx4_ib_query_port(&device->ib_dev, port_num, &attr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	port = &device->iov_ports[port_num - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	port->dev = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	port->num = port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Directory structure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	 * iov -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	 *   port num -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	 *	admin_guids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	 *	gids (operational)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	 *	mcg_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	port->dentr_ar = kzalloc(sizeof (struct mlx4_ib_iov_sysfs_attr_ar),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (!port->dentr_ar) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	sprintf(buff, "%d", port_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	port->cur_port = kobject_create_and_add(buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				 kobject_get(device->ports_parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!port->cur_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto kobj_create_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* admin GUIDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	port->admin_alias_parent = kobject_create_and_add("admin_guids",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 						  kobject_get(port->cur_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (!port->admin_alias_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		goto err_admin_guids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	for (i = 0 ; i < attr.gid_tbl_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		sprintf(buff, "%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		port->dentr_ar->dentries[i].entry_num = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		ret = create_sysfs_entry(port, &port->dentr_ar->dentries[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 					  buff, port->admin_alias_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 					  show_admin_alias_guid, store_admin_alias_guid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			goto err_admin_alias_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* gids subdirectory (operational gids) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	port->gids_parent = kobject_create_and_add("gids",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 						  kobject_get(port->cur_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!port->gids_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		goto err_gids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	for (i = 0 ; i < attr.gid_tbl_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		sprintf(buff, "%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		port->dentr_ar->dentries[attr.gid_tbl_len + i].entry_num = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		ret = create_sysfs_entry(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 					 &port->dentr_ar->dentries[attr.gid_tbl_len + i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					 buff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 					 port->gids_parent, show_port_gid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			goto err_gids_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* physical port pkey table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	port->pkeys_parent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		kobject_create_and_add("pkeys", kobject_get(port->cur_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (!port->pkeys_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		goto err_pkeys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	for (i = 0 ; i < attr.pkey_tbl_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		sprintf(buff, "%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		port->dentr_ar->dentries[2 * attr.gid_tbl_len + i].entry_num = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		ret = create_sysfs_entry(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 					 &port->dentr_ar->dentries[2 * attr.gid_tbl_len + i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 					 buff, port->pkeys_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 					 show_phys_port_pkey, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			goto err_pkeys_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* MCGs table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	port->mcgs_parent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		kobject_create_and_add("mcgs", kobject_get(port->cur_port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (!port->mcgs_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		goto err_mcgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) err_mcgs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	kobject_put(port->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) err_pkeys_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	kobject_put(port->pkeys_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) err_pkeys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	kobject_put(port->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) err_gids_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	kobject_put(port->gids_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) err_gids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	kobject_put(port->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) err_admin_alias_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	kobject_put(port->admin_alias_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) err_admin_guids:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	kobject_put(port->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	kobject_put(port->cur_port); /* once more for create_and_add buff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) kobj_create_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	kobject_put(device->ports_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	kfree(port->dentr_ar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	pr_err("add_port_entries FAILED: for port:%d, error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	       port_num, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static void get_name(struct mlx4_ib_dev *dev, char *name, int i, int max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	/* pci_name format is: bus:dev:func -> xxxx:yy:zz.n
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	 * with no ARI only 3 last bits are used so when the fn is higher than 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	 * need to add it to the dev num, so count in the last number will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	 * modulo 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	snprintf(name, max, "%.8s%.2d.%d", pci_name(dev->dev->persist->pdev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		 i / 8, i % 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct mlx4_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct kobject         kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	struct mlx4_ib_dev    *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	struct attribute_group pkey_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	struct attribute_group gid_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	struct device_attribute	enable_smi_admin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	struct device_attribute	smi_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int		       slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	u8                     port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static void mlx4_port_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	struct mlx4_port *p = container_of(kobj, struct mlx4_port, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct attribute *a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		kfree(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	kfree(p->pkey_group.attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	for (i = 0; (a = p->gid_group.attrs[i]); ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		kfree(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	kfree(p->gid_group.attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct port_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	struct attribute attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	ssize_t (*show)(struct mlx4_port *, struct port_attribute *, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	ssize_t (*store)(struct mlx4_port *, struct port_attribute *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			 const char *buf, size_t count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static ssize_t port_attr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			      struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct port_attribute *port_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		container_of(attr, struct port_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct mlx4_port *p = container_of(kobj, struct mlx4_port, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (!port_attr->show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	return port_attr->show(p, port_attr, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static ssize_t port_attr_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			       struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			       const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct port_attribute *port_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		container_of(attr, struct port_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct mlx4_port *p = container_of(kobj, struct mlx4_port, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	if (!port_attr->store)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	return port_attr->store(p, port_attr, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static const struct sysfs_ops port_sysfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	.show = port_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	.store = port_attr_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) static struct kobj_type port_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	.release    = mlx4_port_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	.sysfs_ops  = &port_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct port_table_attribute {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	struct port_attribute	attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	char			name[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	int			index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static ssize_t show_port_pkey(struct mlx4_port *p, struct port_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	struct port_table_attribute *tab_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		container_of(attr, struct port_table_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	ssize_t ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	if (p->dev->pkeys.virt2phys_pkey[p->slave][p->port_num - 1][tab_attr->index] >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	    (p->dev->dev->caps.pkey_table_len[p->port_num]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		ret = sprintf(buf, "none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		ret = sprintf(buf, "%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			      p->dev->pkeys.virt2phys_pkey[p->slave]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 			      [p->port_num - 1][tab_attr->index]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static ssize_t store_port_pkey(struct mlx4_port *p, struct port_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 			       const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	struct port_table_attribute *tab_attr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		container_of(attr, struct port_table_attribute, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	/* do not allow remapping Dom0 virtual pkey table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (p->slave == mlx4_master_func_num(p->dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (!strncasecmp(buf, "no", 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		idx = p->dev->dev->phys_caps.pkey_phys_table_len[p->port_num] - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	else if (sscanf(buf, "%i", &idx) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		 idx >= p->dev->dev->caps.pkey_table_len[p->port_num] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		 idx < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	p->dev->pkeys.virt2phys_pkey[p->slave][p->port_num - 1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 				    [tab_attr->index] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	mlx4_sync_pkey_table(p->dev->dev, p->slave, p->port_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			     tab_attr->index, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	err = mlx4_gen_pkey_eqe(p->dev->dev, p->slave, p->port_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		pr_err("mlx4_gen_pkey_eqe failed for slave %d,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		       " port %d, index %d\n", p->slave, p->port_num, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static ssize_t show_port_gid_idx(struct mlx4_port *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 				 struct port_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	return sprintf(buf, "%d\n", p->slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static struct attribute **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) alloc_group_attrs(ssize_t (*show)(struct mlx4_port *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 				  struct port_attribute *, char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		  ssize_t (*store)(struct mlx4_port *, struct port_attribute *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				   const char *buf, size_t count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		  int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	struct attribute **tab_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	struct port_table_attribute *element;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	tab_attr = kcalloc(1 + len, sizeof (struct attribute *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (!tab_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		element = kzalloc(sizeof (struct port_table_attribute),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 				  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		if (!element)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		if (snprintf(element->name, sizeof (element->name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			     "%d", i) >= sizeof (element->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			kfree(element);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		sysfs_attr_init(&element->attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		element->attr.attr.name  = element->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		if (store) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 			element->attr.attr.mode  = S_IWUSR | S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 			element->attr.store	 = store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			element->attr.attr.mode  = S_IRUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		element->attr.show       = show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		element->index		 = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		tab_attr[i] = &element->attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	return tab_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		kfree(tab_attr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	kfree(tab_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static ssize_t sysfs_show_smi_enabled(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 				      struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	struct mlx4_port *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		container_of(attr, struct mlx4_port, smi_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	if (mlx4_vf_smi_enabled(p->dev->dev, p->slave, p->port_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		len = sprintf(buf, "%d\n", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		len = sprintf(buf, "%d\n", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static ssize_t sysfs_show_enable_smi_admin(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 					   struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 					   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	struct mlx4_port *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		container_of(attr, struct mlx4_port, enable_smi_admin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	ssize_t len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	if (mlx4_vf_get_enable_smi_admin(p->dev->dev, p->slave, p->port_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		len = sprintf(buf, "%d\n", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		len = sprintf(buf, "%d\n", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static ssize_t sysfs_store_enable_smi_admin(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 					    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 					    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	struct mlx4_port *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		container_of(attr, struct mlx4_port, enable_smi_admin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	int enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	if (sscanf(buf, "%i", &enable) != 1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	    enable < 0 || enable > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (mlx4_vf_set_enable_smi_admin(p->dev->dev, p->slave, p->port_num, enable))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static int add_vf_smi_entries(struct mlx4_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	int is_eth = rdma_port_get_link_layer(&p->dev->ib_dev, p->port_num) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 			IB_LINK_LAYER_ETHERNET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	/* do not display entries if eth transport, or if master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	if (is_eth || p->slave == mlx4_master_func_num(p->dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	sysfs_attr_init(&p->smi_enabled.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	p->smi_enabled.show = sysfs_show_smi_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	p->smi_enabled.store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	p->smi_enabled.attr.name = "smi_enabled";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	p->smi_enabled.attr.mode = 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	ret = sysfs_create_file(&p->kobj, &p->smi_enabled.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		pr_err("failed to create smi_enabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	sysfs_attr_init(&p->enable_smi_admin.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	p->enable_smi_admin.show = sysfs_show_enable_smi_admin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	p->enable_smi_admin.store = sysfs_store_enable_smi_admin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	p->enable_smi_admin.attr.name = "enable_smi_admin";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	p->enable_smi_admin.attr.mode = 0644;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	ret = sysfs_create_file(&p->kobj, &p->enable_smi_admin.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		pr_err("failed to create enable_smi_admin\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		sysfs_remove_file(&p->kobj, &p->smi_enabled.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static void remove_vf_smi_entries(struct mlx4_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	int is_eth = rdma_port_get_link_layer(&p->dev->ib_dev, p->port_num) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 			IB_LINK_LAYER_ETHERNET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	if (is_eth || p->slave == mlx4_master_func_num(p->dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	sysfs_remove_file(&p->kobj, &p->smi_enabled.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	sysfs_remove_file(&p->kobj, &p->enable_smi_admin.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static int add_port(struct mlx4_ib_dev *dev, int port_num, int slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	struct mlx4_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	int is_eth = rdma_port_get_link_layer(&dev->ib_dev, port_num) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 			IB_LINK_LAYER_ETHERNET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	p = kzalloc(sizeof *p, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	p->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	p->port_num = port_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	p->slave = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	ret = kobject_init_and_add(&p->kobj, &port_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 				   kobject_get(dev->dev_ports_parent[slave]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 				   "%d", port_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	p->pkey_group.name  = "pkey_idx";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	p->pkey_group.attrs =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		alloc_group_attrs(show_port_pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 				  is_eth ? NULL : store_port_pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 				  dev->dev->caps.pkey_table_len[port_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	if (!p->pkey_group.attrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	ret = sysfs_create_group(&p->kobj, &p->pkey_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		goto err_free_pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	p->gid_group.name  = "gid_idx";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	p->gid_group.attrs = alloc_group_attrs(show_port_gid_idx, NULL, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	if (!p->gid_group.attrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		goto err_free_pkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	ret = sysfs_create_group(&p->kobj, &p->gid_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		goto err_free_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	ret = add_vf_smi_entries(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		goto err_free_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	list_add_tail(&p->kobj.entry, &dev->pkeys.pkey_port_list[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) err_free_gid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	kfree(p->gid_group.attrs[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	kfree(p->gid_group.attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) err_free_pkey:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	for (i = 0; i < dev->dev->caps.pkey_table_len[port_num]; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		kfree(p->pkey_group.attrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	kfree(p->pkey_group.attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	kobject_put(dev->dev_ports_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static int register_one_pkey_tree(struct mlx4_ib_dev *dev, int slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	char name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	int port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	struct kobject *p, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	struct mlx4_port *mport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	struct mlx4_active_ports actv_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	get_name(dev, name, slave, sizeof name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	dev->pkeys.device_parent[slave] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 		kobject_create_and_add(name, kobject_get(dev->iov_parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	if (!dev->pkeys.device_parent[slave]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		goto fail_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	INIT_LIST_HEAD(&dev->pkeys.pkey_port_list[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	dev->dev_ports_parent[slave] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		kobject_create_and_add("ports",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 				       kobject_get(dev->pkeys.device_parent[slave]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	if (!dev->dev_ports_parent[slave]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		goto err_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	actv_ports = mlx4_get_active_ports(dev->dev, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	for (port = 1; port <= dev->dev->caps.num_ports; ++port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 		if (!test_bit(port - 1, actv_ports.ports))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		err = add_port(dev, port, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 			goto err_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) err_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	list_for_each_entry_safe(p, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 				 &dev->pkeys.pkey_port_list[slave],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 				 entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		list_del(&p->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		mport = container_of(p, struct mlx4_port, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		sysfs_remove_group(p, &mport->pkey_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 		sysfs_remove_group(p, &mport->gid_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 		remove_vf_smi_entries(mport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		kobject_put(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	kobject_put(dev->dev_ports_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) err_ports:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	kobject_put(dev->pkeys.device_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	/* extra put for the device_parent create_and_add */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	kobject_put(dev->pkeys.device_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) fail_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	kobject_put(dev->iov_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) static int register_pkey_tree(struct mlx4_ib_dev *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	if (!mlx4_is_master(device->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	for (i = 0; i <= device->dev->persist->num_vfs; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 		register_one_pkey_tree(device, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) static void unregister_pkey_tree(struct mlx4_ib_dev *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	int slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	struct kobject *p, *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	struct mlx4_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 	if (!mlx4_is_master(device->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	for (slave = device->dev->persist->num_vfs; slave >= 0; --slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		list_for_each_entry_safe(p, t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 					 &device->pkeys.pkey_port_list[slave],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 					 entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 			list_del(&p->entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 			port = container_of(p, struct mlx4_port, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 			sysfs_remove_group(p, &port->pkey_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 			sysfs_remove_group(p, &port->gid_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 			remove_vf_smi_entries(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 			kobject_put(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 			kobject_put(device->dev_ports_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 		kobject_put(device->dev_ports_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 		kobject_put(device->pkeys.device_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		kobject_put(device->pkeys.device_parent[slave]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 		kobject_put(device->iov_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int mlx4_ib_device_register_sysfs(struct mlx4_ib_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	if (!mlx4_is_master(dev->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	dev->iov_parent = kobject_create_and_add("iov", &dev->ib_dev.dev.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	if (!dev->iov_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	dev->ports_parent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		kobject_create_and_add("ports",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 				       kobject_get(dev->iov_parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	if (!dev->ports_parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 		goto err_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	for (i = 1; i <= dev->ib_dev.phys_port_cnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		ret = add_port_entries(dev, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 			goto err_add_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	ret = register_pkey_tree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 		goto err_add_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) err_add_entries:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	kobject_put(dev->ports_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) err_ports:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	kobject_put(dev->iov_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	pr_err("mlx4_ib_device_register_sysfs error (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) static void unregister_alias_guid_tree(struct mlx4_ib_dev *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	struct mlx4_ib_iov_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	if (!mlx4_is_master(device->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	for (i = 0; i < device->dev->caps.num_ports; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 		p = &device->iov_ports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 		kobject_put(p->admin_alias_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 		kobject_put(p->gids_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 		kobject_put(p->pkeys_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 		kobject_put(p->mcgs_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 		kobject_put(p->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		kobject_put(p->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 		kobject_put(p->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 		kobject_put(p->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 		kobject_put(p->cur_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 		kobject_put(p->dev->ports_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 		kfree(p->dentr_ar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) void mlx4_ib_device_unregister_sysfs(struct mlx4_ib_dev *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	unregister_alias_guid_tree(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	unregister_pkey_tree(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 	kobject_put(device->ports_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	kobject_put(device->iov_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 	kobject_put(device->iov_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }