2 * Copyright (c) 2012 Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 /*#include "core_priv.h"*/
35 #include <linux/slab.h>
36 #include <linux/string.h>
37 #include <linux/stat.h>
39 #include <rdma/ib_mad.h>
40 /*show_admin_alias_guid returns the administratively assigned value of that GUID.
41 * Values returned in buf parameter string:
42 * 0 - requests opensm to assign a value.
43 * ffffffffffffffff - delete this entry.
44 * other - value assigned by administrator.
46 static ssize_t
show_admin_alias_guid(struct device
*dev
,
47 struct device_attribute
*attr
, char *buf
)
49 struct mlx4_ib_iov_sysfs_attr
*mlx4_ib_iov_dentry
=
50 container_of(attr
, struct mlx4_ib_iov_sysfs_attr
, dentry
);
51 struct mlx4_ib_iov_port
*port
= mlx4_ib_iov_dentry
->ctx
;
52 struct mlx4_ib_dev
*mdev
= port
->dev
;
53 __be64 sysadmin_ag_val
;
55 sysadmin_ag_val
= mlx4_get_admin_guid(mdev
->dev
,
56 mlx4_ib_iov_dentry
->entry_num
,
59 return sprintf(buf
, "%llx\n", be64_to_cpu(sysadmin_ag_val
));
62 /* store_admin_alias_guid stores the (new) administratively assigned value of that GUID.
63 * Values in buf parameter string:
64 * 0 - requests opensm to assign a value.
65 * 0xffffffffffffffff - delete this entry.
66 * other - guid value assigned by the administrator.
68 static ssize_t
store_admin_alias_guid(struct device
*dev
,
69 struct device_attribute
*attr
,
70 const char *buf
, size_t count
)
72 int record_num
;/*0-15*/
73 int guid_index_in_rec
; /*0 - 7*/
74 struct mlx4_ib_iov_sysfs_attr
*mlx4_ib_iov_dentry
=
75 container_of(attr
, struct mlx4_ib_iov_sysfs_attr
, dentry
);
76 struct mlx4_ib_iov_port
*port
= mlx4_ib_iov_dentry
->ctx
;
77 struct mlx4_ib_dev
*mdev
= port
->dev
;
81 record_num
= mlx4_ib_iov_dentry
->entry_num
/ 8;
82 guid_index_in_rec
= mlx4_ib_iov_dentry
->entry_num
% 8;
83 if (0 == record_num
&& 0 == guid_index_in_rec
) {
84 pr_err("GUID 0 block 0 is RO\n");
87 spin_lock_irqsave(&mdev
->sriov
.alias_guid
.ag_work_lock
, flags
);
88 sscanf(buf
, "%llx", &sysadmin_ag_val
);
89 *(__be64
*)&mdev
->sriov
.alias_guid
.ports_guid
[port
->num
- 1].
90 all_rec_per_port
[record_num
].
91 all_recs
[GUID_REC_SIZE
* guid_index_in_rec
] =
92 cpu_to_be64(sysadmin_ag_val
);
94 /* Change the state to be pending for update */
95 mdev
->sriov
.alias_guid
.ports_guid
[port
->num
- 1].all_rec_per_port
[record_num
].status
96 = MLX4_GUID_INFO_STATUS_IDLE
;
97 mlx4_set_admin_guid(mdev
->dev
, cpu_to_be64(sysadmin_ag_val
),
98 mlx4_ib_iov_dentry
->entry_num
,
101 /* set the record index */
102 mdev
->sriov
.alias_guid
.ports_guid
[port
->num
- 1].all_rec_per_port
[record_num
].guid_indexes
103 |= mlx4_ib_get_aguid_comp_mask_from_ix(guid_index_in_rec
);
105 spin_unlock_irqrestore(&mdev
->sriov
.alias_guid
.ag_work_lock
, flags
);
106 mlx4_ib_init_alias_guid_work(mdev
, port
->num
- 1);
111 static ssize_t
show_port_gid(struct device
*dev
,
112 struct device_attribute
*attr
,
115 struct mlx4_ib_iov_sysfs_attr
*mlx4_ib_iov_dentry
=
116 container_of(attr
, struct mlx4_ib_iov_sysfs_attr
, dentry
);
117 struct mlx4_ib_iov_port
*port
= mlx4_ib_iov_dentry
->ctx
;
118 struct mlx4_ib_dev
*mdev
= port
->dev
;
122 ret
= __mlx4_ib_query_gid(&mdev
->ib_dev
, port
->num
,
123 mlx4_ib_iov_dentry
->entry_num
, &gid
, 1);
126 ret
= sprintf(buf
, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
127 be16_to_cpu(((__be16
*) gid
.raw
)[0]),
128 be16_to_cpu(((__be16
*) gid
.raw
)[1]),
129 be16_to_cpu(((__be16
*) gid
.raw
)[2]),
130 be16_to_cpu(((__be16
*) gid
.raw
)[3]),
131 be16_to_cpu(((__be16
*) gid
.raw
)[4]),
132 be16_to_cpu(((__be16
*) gid
.raw
)[5]),
133 be16_to_cpu(((__be16
*) gid
.raw
)[6]),
134 be16_to_cpu(((__be16
*) gid
.raw
)[7]));
138 static ssize_t
show_phys_port_pkey(struct device
*dev
,
139 struct device_attribute
*attr
,
142 struct mlx4_ib_iov_sysfs_attr
*mlx4_ib_iov_dentry
=
143 container_of(attr
, struct mlx4_ib_iov_sysfs_attr
, dentry
);
144 struct mlx4_ib_iov_port
*port
= mlx4_ib_iov_dentry
->ctx
;
145 struct mlx4_ib_dev
*mdev
= port
->dev
;
149 ret
= __mlx4_ib_query_pkey(&mdev
->ib_dev
, port
->num
,
150 mlx4_ib_iov_dentry
->entry_num
, &pkey
, 1);
154 return sprintf(buf
, "0x%04x\n", pkey
);
157 #define DENTRY_REMOVE(_dentry) \
159 sysfs_remove_file((_dentry)->kobj, &(_dentry)->dentry.attr); \
162 static int create_sysfs_entry(void *_ctx
, struct mlx4_ib_iov_sysfs_attr
*_dentry
,
163 char *_name
, struct kobject
*_kobj
,
164 ssize_t (*show
)(struct device
*dev
,
165 struct device_attribute
*attr
,
167 ssize_t (*store
)(struct device
*dev
,
168 struct device_attribute
*attr
,
169 const char *buf
, size_t count
)
173 struct mlx4_ib_iov_sysfs_attr
*vdentry
= _dentry
;
176 vdentry
->dentry
.show
= show
;
177 vdentry
->dentry
.store
= store
;
178 sysfs_attr_init(&vdentry
->dentry
.attr
);
179 vdentry
->dentry
.attr
.name
= vdentry
->name
;
180 vdentry
->dentry
.attr
.mode
= 0;
181 vdentry
->kobj
= _kobj
;
182 snprintf(vdentry
->name
, 15, "%s", _name
);
184 if (vdentry
->dentry
.store
)
185 vdentry
->dentry
.attr
.mode
|= S_IWUSR
;
187 if (vdentry
->dentry
.show
)
188 vdentry
->dentry
.attr
.mode
|= S_IRUGO
;
190 ret
= sysfs_create_file(vdentry
->kobj
, &vdentry
->dentry
.attr
);
192 pr_err("failed to create %s\n", vdentry
->dentry
.attr
.name
);
200 int add_sysfs_port_mcg_attr(struct mlx4_ib_dev
*device
, int port_num
,
201 struct attribute
*attr
)
203 struct mlx4_ib_iov_port
*port
= &device
->iov_ports
[port_num
- 1];
206 ret
= sysfs_create_file(port
->mcgs_parent
, attr
);
208 pr_err("failed to create %s\n", attr
->name
);
213 void del_sysfs_port_mcg_attr(struct mlx4_ib_dev
*device
, int port_num
,
214 struct attribute
*attr
)
216 struct mlx4_ib_iov_port
*port
= &device
->iov_ports
[port_num
- 1];
218 sysfs_remove_file(port
->mcgs_parent
, attr
);
221 static int add_port_entries(struct mlx4_ib_dev
*device
, int port_num
)
225 struct mlx4_ib_iov_port
*port
= NULL
;
227 struct ib_port_attr attr
;
229 /* get the physical gid and pkey table sizes.*/
230 ret
= __mlx4_ib_query_port(&device
->ib_dev
, port_num
, &attr
, 1);
234 port
= &device
->iov_ports
[port_num
- 1];
236 port
->num
= port_num
;
237 /* Directory structure:
244 port
->dentr_ar
= kzalloc(sizeof (struct mlx4_ib_iov_sysfs_attr_ar
),
246 if (!port
->dentr_ar
) {
250 sprintf(buff
, "%d", port_num
);
251 port
->cur_port
= kobject_create_and_add(buff
,
252 kobject_get(device
->ports_parent
));
253 if (!port
->cur_port
) {
255 goto kobj_create_err
;
258 port
->admin_alias_parent
= kobject_create_and_add("admin_guids",
259 kobject_get(port
->cur_port
));
260 if (!port
->admin_alias_parent
) {
262 goto err_admin_guids
;
264 for (i
= 0 ; i
< attr
.gid_tbl_len
; i
++) {
265 sprintf(buff
, "%d", i
);
266 port
->dentr_ar
->dentries
[i
].entry_num
= i
;
267 ret
= create_sysfs_entry(port
, &port
->dentr_ar
->dentries
[i
],
268 buff
, port
->admin_alias_parent
,
269 show_admin_alias_guid
, store_admin_alias_guid
);
271 goto err_admin_alias_parent
;
274 /* gids subdirectory (operational gids) */
275 port
->gids_parent
= kobject_create_and_add("gids",
276 kobject_get(port
->cur_port
));
277 if (!port
->gids_parent
) {
282 for (i
= 0 ; i
< attr
.gid_tbl_len
; i
++) {
283 sprintf(buff
, "%d", i
);
284 port
->dentr_ar
->dentries
[attr
.gid_tbl_len
+ i
].entry_num
= i
;
285 ret
= create_sysfs_entry(port
,
286 &port
->dentr_ar
->dentries
[attr
.gid_tbl_len
+ i
],
288 port
->gids_parent
, show_port_gid
, NULL
);
290 goto err_gids_parent
;
293 /* physical port pkey table */
295 kobject_create_and_add("pkeys", kobject_get(port
->cur_port
));
296 if (!port
->pkeys_parent
) {
301 for (i
= 0 ; i
< attr
.pkey_tbl_len
; i
++) {
302 sprintf(buff
, "%d", i
);
303 port
->dentr_ar
->dentries
[2 * attr
.gid_tbl_len
+ i
].entry_num
= i
;
304 ret
= create_sysfs_entry(port
,
305 &port
->dentr_ar
->dentries
[2 * attr
.gid_tbl_len
+ i
],
306 buff
, port
->pkeys_parent
,
307 show_phys_port_pkey
, NULL
);
309 goto err_pkeys_parent
;
314 kobject_create_and_add("mcgs", kobject_get(port
->cur_port
));
315 if (!port
->mcgs_parent
) {
322 kobject_put(port
->cur_port
);
325 kobject_put(port
->pkeys_parent
);
328 kobject_put(port
->cur_port
);
331 kobject_put(port
->gids_parent
);
334 kobject_put(port
->cur_port
);
336 err_admin_alias_parent
:
337 kobject_put(port
->admin_alias_parent
);
340 kobject_put(port
->cur_port
);
341 kobject_put(port
->cur_port
); /* once more for create_and_add buff */
344 kobject_put(device
->ports_parent
);
345 kfree(port
->dentr_ar
);
348 pr_err("add_port_entries FAILED: for port:%d, error: %d\n",
353 static void get_name(struct mlx4_ib_dev
*dev
, char *name
, int i
, int max
)
357 /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n */
358 strlcpy(name
, pci_name(dev
->dev
->persist
->pdev
), max
);
359 strncpy(base_name
, name
, 8); /*till xxxx:yy:*/
361 /* with no ARI only 3 last bits are used so when the fn is higher than 8
362 * need to add it to the dev num, so count in the last number will be
364 sprintf(name
, "%s%.2d.%d", base_name
, (i
/8), (i
%8));
369 struct mlx4_ib_dev
*dev
;
370 struct attribute_group pkey_group
;
371 struct attribute_group gid_group
;
372 struct device_attribute enable_smi_admin
;
373 struct device_attribute smi_enabled
;
379 static void mlx4_port_release(struct kobject
*kobj
)
381 struct mlx4_port
*p
= container_of(kobj
, struct mlx4_port
, kobj
);
385 for (i
= 0; (a
= p
->pkey_group
.attrs
[i
]); ++i
)
387 kfree(p
->pkey_group
.attrs
);
388 for (i
= 0; (a
= p
->gid_group
.attrs
[i
]); ++i
)
390 kfree(p
->gid_group
.attrs
);
394 struct port_attribute
{
395 struct attribute attr
;
396 ssize_t (*show
)(struct mlx4_port
*, struct port_attribute
*, char *buf
);
397 ssize_t (*store
)(struct mlx4_port
*, struct port_attribute
*,
398 const char *buf
, size_t count
);
401 static ssize_t
port_attr_show(struct kobject
*kobj
,
402 struct attribute
*attr
, char *buf
)
404 struct port_attribute
*port_attr
=
405 container_of(attr
, struct port_attribute
, attr
);
406 struct mlx4_port
*p
= container_of(kobj
, struct mlx4_port
, kobj
);
408 if (!port_attr
->show
)
410 return port_attr
->show(p
, port_attr
, buf
);
413 static ssize_t
port_attr_store(struct kobject
*kobj
,
414 struct attribute
*attr
,
415 const char *buf
, size_t size
)
417 struct port_attribute
*port_attr
=
418 container_of(attr
, struct port_attribute
, attr
);
419 struct mlx4_port
*p
= container_of(kobj
, struct mlx4_port
, kobj
);
421 if (!port_attr
->store
)
423 return port_attr
->store(p
, port_attr
, buf
, size
);
426 static const struct sysfs_ops port_sysfs_ops
= {
427 .show
= port_attr_show
,
428 .store
= port_attr_store
,
431 static struct kobj_type port_type
= {
432 .release
= mlx4_port_release
,
433 .sysfs_ops
= &port_sysfs_ops
,
436 struct port_table_attribute
{
437 struct port_attribute attr
;
442 static ssize_t
show_port_pkey(struct mlx4_port
*p
, struct port_attribute
*attr
,
445 struct port_table_attribute
*tab_attr
=
446 container_of(attr
, struct port_table_attribute
, attr
);
447 ssize_t ret
= -ENODEV
;
449 if (p
->dev
->pkeys
.virt2phys_pkey
[p
->slave
][p
->port_num
- 1][tab_attr
->index
] >=
450 (p
->dev
->dev
->caps
.pkey_table_len
[p
->port_num
]))
451 ret
= sprintf(buf
, "none\n");
453 ret
= sprintf(buf
, "%d\n",
454 p
->dev
->pkeys
.virt2phys_pkey
[p
->slave
]
455 [p
->port_num
- 1][tab_attr
->index
]);
459 static ssize_t
store_port_pkey(struct mlx4_port
*p
, struct port_attribute
*attr
,
460 const char *buf
, size_t count
)
462 struct port_table_attribute
*tab_attr
=
463 container_of(attr
, struct port_table_attribute
, attr
);
467 /* do not allow remapping Dom0 virtual pkey table */
468 if (p
->slave
== mlx4_master_func_num(p
->dev
->dev
))
471 if (!strncasecmp(buf
, "no", 2))
472 idx
= p
->dev
->dev
->phys_caps
.pkey_phys_table_len
[p
->port_num
] - 1;
473 else if (sscanf(buf
, "%i", &idx
) != 1 ||
474 idx
>= p
->dev
->dev
->caps
.pkey_table_len
[p
->port_num
] ||
478 p
->dev
->pkeys
.virt2phys_pkey
[p
->slave
][p
->port_num
- 1]
479 [tab_attr
->index
] = idx
;
480 mlx4_sync_pkey_table(p
->dev
->dev
, p
->slave
, p
->port_num
,
481 tab_attr
->index
, idx
);
482 err
= mlx4_gen_pkey_eqe(p
->dev
->dev
, p
->slave
, p
->port_num
);
484 pr_err("mlx4_gen_pkey_eqe failed for slave %d,"
485 " port %d, index %d\n", p
->slave
, p
->port_num
, idx
);
491 static ssize_t
show_port_gid_idx(struct mlx4_port
*p
,
492 struct port_attribute
*attr
, char *buf
)
494 return sprintf(buf
, "%d\n", p
->slave
);
497 static struct attribute
**
498 alloc_group_attrs(ssize_t (*show
)(struct mlx4_port
*,
499 struct port_attribute
*, char *buf
),
500 ssize_t (*store
)(struct mlx4_port
*, struct port_attribute
*,
501 const char *buf
, size_t count
),
504 struct attribute
**tab_attr
;
505 struct port_table_attribute
*element
;
508 tab_attr
= kcalloc(1 + len
, sizeof (struct attribute
*), GFP_KERNEL
);
512 for (i
= 0; i
< len
; i
++) {
513 element
= kzalloc(sizeof (struct port_table_attribute
),
517 if (snprintf(element
->name
, sizeof (element
->name
),
518 "%d", i
) >= sizeof (element
->name
)) {
522 sysfs_attr_init(&element
->attr
.attr
);
523 element
->attr
.attr
.name
= element
->name
;
525 element
->attr
.attr
.mode
= S_IWUSR
| S_IRUGO
;
526 element
->attr
.store
= store
;
528 element
->attr
.attr
.mode
= S_IRUGO
;
530 element
->attr
.show
= show
;
532 tab_attr
[i
] = &element
->attr
.attr
;
543 static ssize_t
sysfs_show_smi_enabled(struct device
*dev
,
544 struct device_attribute
*attr
, char *buf
)
546 struct mlx4_port
*p
=
547 container_of(attr
, struct mlx4_port
, smi_enabled
);
550 if (mlx4_vf_smi_enabled(p
->dev
->dev
, p
->slave
, p
->port_num
))
551 len
= sprintf(buf
, "%d\n", 1);
553 len
= sprintf(buf
, "%d\n", 0);
558 static ssize_t
sysfs_show_enable_smi_admin(struct device
*dev
,
559 struct device_attribute
*attr
,
562 struct mlx4_port
*p
=
563 container_of(attr
, struct mlx4_port
, enable_smi_admin
);
566 if (mlx4_vf_get_enable_smi_admin(p
->dev
->dev
, p
->slave
, p
->port_num
))
567 len
= sprintf(buf
, "%d\n", 1);
569 len
= sprintf(buf
, "%d\n", 0);
574 static ssize_t
sysfs_store_enable_smi_admin(struct device
*dev
,
575 struct device_attribute
*attr
,
576 const char *buf
, size_t count
)
578 struct mlx4_port
*p
=
579 container_of(attr
, struct mlx4_port
, enable_smi_admin
);
582 if (sscanf(buf
, "%i", &enable
) != 1 ||
583 enable
< 0 || enable
> 1)
586 if (mlx4_vf_set_enable_smi_admin(p
->dev
->dev
, p
->slave
, p
->port_num
, enable
))
591 static int add_vf_smi_entries(struct mlx4_port
*p
)
593 int is_eth
= rdma_port_get_link_layer(&p
->dev
->ib_dev
, p
->port_num
) ==
594 IB_LINK_LAYER_ETHERNET
;
597 /* do not display entries if eth transport, or if master */
598 if (is_eth
|| p
->slave
== mlx4_master_func_num(p
->dev
->dev
))
601 sysfs_attr_init(&p
->smi_enabled
.attr
);
602 p
->smi_enabled
.show
= sysfs_show_smi_enabled
;
603 p
->smi_enabled
.store
= NULL
;
604 p
->smi_enabled
.attr
.name
= "smi_enabled";
605 p
->smi_enabled
.attr
.mode
= 0444;
606 ret
= sysfs_create_file(&p
->kobj
, &p
->smi_enabled
.attr
);
608 pr_err("failed to create smi_enabled\n");
612 sysfs_attr_init(&p
->enable_smi_admin
.attr
);
613 p
->enable_smi_admin
.show
= sysfs_show_enable_smi_admin
;
614 p
->enable_smi_admin
.store
= sysfs_store_enable_smi_admin
;
615 p
->enable_smi_admin
.attr
.name
= "enable_smi_admin";
616 p
->enable_smi_admin
.attr
.mode
= 0644;
617 ret
= sysfs_create_file(&p
->kobj
, &p
->enable_smi_admin
.attr
);
619 pr_err("failed to create enable_smi_admin\n");
620 sysfs_remove_file(&p
->kobj
, &p
->smi_enabled
.attr
);
626 static void remove_vf_smi_entries(struct mlx4_port
*p
)
628 int is_eth
= rdma_port_get_link_layer(&p
->dev
->ib_dev
, p
->port_num
) ==
629 IB_LINK_LAYER_ETHERNET
;
631 if (is_eth
|| p
->slave
== mlx4_master_func_num(p
->dev
->dev
))
634 sysfs_remove_file(&p
->kobj
, &p
->smi_enabled
.attr
);
635 sysfs_remove_file(&p
->kobj
, &p
->enable_smi_admin
.attr
);
638 static int add_port(struct mlx4_ib_dev
*dev
, int port_num
, int slave
)
643 int is_eth
= rdma_port_get_link_layer(&dev
->ib_dev
, port_num
) ==
644 IB_LINK_LAYER_ETHERNET
;
646 p
= kzalloc(sizeof *p
, GFP_KERNEL
);
651 p
->port_num
= port_num
;
654 ret
= kobject_init_and_add(&p
->kobj
, &port_type
,
655 kobject_get(dev
->dev_ports_parent
[slave
]),
660 p
->pkey_group
.name
= "pkey_idx";
661 p
->pkey_group
.attrs
=
662 alloc_group_attrs(show_port_pkey
,
663 is_eth
? NULL
: store_port_pkey
,
664 dev
->dev
->caps
.pkey_table_len
[port_num
]);
665 if (!p
->pkey_group
.attrs
) {
670 ret
= sysfs_create_group(&p
->kobj
, &p
->pkey_group
);
674 p
->gid_group
.name
= "gid_idx";
675 p
->gid_group
.attrs
= alloc_group_attrs(show_port_gid_idx
, NULL
, 1);
676 if (!p
->gid_group
.attrs
) {
681 ret
= sysfs_create_group(&p
->kobj
, &p
->gid_group
);
685 ret
= add_vf_smi_entries(p
);
689 list_add_tail(&p
->kobj
.entry
, &dev
->pkeys
.pkey_port_list
[slave
]);
693 kfree(p
->gid_group
.attrs
[0]);
694 kfree(p
->gid_group
.attrs
);
697 for (i
= 0; i
< dev
->dev
->caps
.pkey_table_len
[port_num
]; ++i
)
698 kfree(p
->pkey_group
.attrs
[i
]);
699 kfree(p
->pkey_group
.attrs
);
702 kobject_put(dev
->dev_ports_parent
[slave
]);
707 static int register_one_pkey_tree(struct mlx4_ib_dev
*dev
, int slave
)
712 struct kobject
*p
, *t
;
713 struct mlx4_port
*mport
;
714 struct mlx4_active_ports actv_ports
;
716 get_name(dev
, name
, slave
, sizeof name
);
718 dev
->pkeys
.device_parent
[slave
] =
719 kobject_create_and_add(name
, kobject_get(dev
->iov_parent
));
721 if (!dev
->pkeys
.device_parent
[slave
]) {
726 INIT_LIST_HEAD(&dev
->pkeys
.pkey_port_list
[slave
]);
728 dev
->dev_ports_parent
[slave
] =
729 kobject_create_and_add("ports",
730 kobject_get(dev
->pkeys
.device_parent
[slave
]));
732 if (!dev
->dev_ports_parent
[slave
]) {
737 actv_ports
= mlx4_get_active_ports(dev
->dev
, slave
);
739 for (port
= 1; port
<= dev
->dev
->caps
.num_ports
; ++port
) {
740 if (!test_bit(port
- 1, actv_ports
.ports
))
742 err
= add_port(dev
, port
, slave
);
749 list_for_each_entry_safe(p
, t
,
750 &dev
->pkeys
.pkey_port_list
[slave
],
753 mport
= container_of(p
, struct mlx4_port
, kobj
);
754 sysfs_remove_group(p
, &mport
->pkey_group
);
755 sysfs_remove_group(p
, &mport
->gid_group
);
756 remove_vf_smi_entries(mport
);
759 kobject_put(dev
->dev_ports_parent
[slave
]);
762 kobject_put(dev
->pkeys
.device_parent
[slave
]);
763 /* extra put for the device_parent create_and_add */
764 kobject_put(dev
->pkeys
.device_parent
[slave
]);
767 kobject_put(dev
->iov_parent
);
771 static int register_pkey_tree(struct mlx4_ib_dev
*device
)
775 if (!mlx4_is_master(device
->dev
))
778 for (i
= 0; i
<= device
->dev
->persist
->num_vfs
; ++i
)
779 register_one_pkey_tree(device
, i
);
784 static void unregister_pkey_tree(struct mlx4_ib_dev
*device
)
787 struct kobject
*p
, *t
;
788 struct mlx4_port
*port
;
790 if (!mlx4_is_master(device
->dev
))
793 for (slave
= device
->dev
->persist
->num_vfs
; slave
>= 0; --slave
) {
794 list_for_each_entry_safe(p
, t
,
795 &device
->pkeys
.pkey_port_list
[slave
],
798 port
= container_of(p
, struct mlx4_port
, kobj
);
799 sysfs_remove_group(p
, &port
->pkey_group
);
800 sysfs_remove_group(p
, &port
->gid_group
);
801 remove_vf_smi_entries(port
);
803 kobject_put(device
->dev_ports_parent
[slave
]);
805 kobject_put(device
->dev_ports_parent
[slave
]);
806 kobject_put(device
->pkeys
.device_parent
[slave
]);
807 kobject_put(device
->pkeys
.device_parent
[slave
]);
808 kobject_put(device
->iov_parent
);
812 int mlx4_ib_device_register_sysfs(struct mlx4_ib_dev
*dev
)
817 if (!mlx4_is_master(dev
->dev
))
821 kobject_create_and_add("iov",
822 kobject_get(dev
->ib_dev
.ports_parent
->parent
));
823 if (!dev
->iov_parent
) {
828 kobject_create_and_add("ports",
829 kobject_get(dev
->iov_parent
));
830 if (!dev
->ports_parent
) {
835 for (i
= 1; i
<= dev
->ib_dev
.phys_port_cnt
; ++i
) {
836 ret
= add_port_entries(dev
, i
);
838 goto err_add_entries
;
841 ret
= register_pkey_tree(dev
);
843 goto err_add_entries
;
847 kobject_put(dev
->ports_parent
);
850 kobject_put(dev
->iov_parent
);
852 kobject_put(dev
->ib_dev
.ports_parent
->parent
);
853 pr_err("mlx4_ib_device_register_sysfs error (%d)\n", ret
);
857 static void unregister_alias_guid_tree(struct mlx4_ib_dev
*device
)
859 struct mlx4_ib_iov_port
*p
;
862 if (!mlx4_is_master(device
->dev
))
865 for (i
= 0; i
< device
->dev
->caps
.num_ports
; i
++) {
866 p
= &device
->iov_ports
[i
];
867 kobject_put(p
->admin_alias_parent
);
868 kobject_put(p
->gids_parent
);
869 kobject_put(p
->pkeys_parent
);
870 kobject_put(p
->mcgs_parent
);
871 kobject_put(p
->cur_port
);
872 kobject_put(p
->cur_port
);
873 kobject_put(p
->cur_port
);
874 kobject_put(p
->cur_port
);
875 kobject_put(p
->cur_port
);
876 kobject_put(p
->dev
->ports_parent
);
881 void mlx4_ib_device_unregister_sysfs(struct mlx4_ib_dev
*device
)
883 unregister_alias_guid_tree(device
);
884 unregister_pkey_tree(device
);
885 kobject_put(device
->ports_parent
);
886 kobject_put(device
->iov_parent
);
887 kobject_put(device
->iov_parent
);
888 kobject_put(device
->ib_dev
.ports_parent
->parent
);