| .. | .. |
|---|
| 46 | 46 | #include "usnic_ib_sysfs.h" |
|---|
| 47 | 47 | #include "usnic_log.h" |
|---|
| 48 | 48 | |
|---|
| 49 | | -static ssize_t usnic_ib_show_board(struct device *device, |
|---|
| 50 | | - struct device_attribute *attr, |
|---|
| 51 | | - char *buf) |
|---|
| 49 | +static ssize_t board_id_show(struct device *device, |
|---|
| 50 | + struct device_attribute *attr, char *buf) |
|---|
| 52 | 51 | { |
|---|
| 53 | 52 | struct usnic_ib_dev *us_ibdev = |
|---|
| 54 | | - container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 53 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 55 | 54 | unsigned short subsystem_device_id; |
|---|
| 56 | 55 | |
|---|
| 57 | 56 | mutex_lock(&us_ibdev->usdev_lock); |
|---|
| .. | .. |
|---|
| 60 | 59 | |
|---|
| 61 | 60 | return scnprintf(buf, PAGE_SIZE, "%hu\n", subsystem_device_id); |
|---|
| 62 | 61 | } |
|---|
| 62 | +static DEVICE_ATTR_RO(board_id); |
|---|
| 63 | 63 | |
|---|
| 64 | 64 | /* |
|---|
| 65 | 65 | * Report the configuration for this PF |
|---|
| 66 | 66 | */ |
|---|
| 67 | 67 | static ssize_t |
|---|
| 68 | | -usnic_ib_show_config(struct device *device, struct device_attribute *attr, |
|---|
| 69 | | - char *buf) |
|---|
| 68 | +config_show(struct device *device, struct device_attribute *attr, char *buf) |
|---|
| 70 | 69 | { |
|---|
| 71 | | - struct usnic_ib_dev *us_ibdev; |
|---|
| 70 | + struct usnic_ib_dev *us_ibdev = |
|---|
| 71 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 72 | 72 | char *ptr; |
|---|
| 73 | 73 | unsigned left; |
|---|
| 74 | 74 | unsigned n; |
|---|
| 75 | 75 | enum usnic_vnic_res_type res_type; |
|---|
| 76 | | - |
|---|
| 77 | | - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 78 | 76 | |
|---|
| 79 | 77 | /* Buffer space limit is 1 page */ |
|---|
| 80 | 78 | ptr = buf; |
|---|
| .. | .. |
|---|
| 94 | 92 | |
|---|
| 95 | 93 | n = scnprintf(ptr, left, |
|---|
| 96 | 94 | "%s: %s:%d.%d, %s, %pM, %u VFs\n Per VF:", |
|---|
| 97 | | - us_ibdev->ib_dev.name, |
|---|
| 95 | + dev_name(&us_ibdev->ib_dev.dev), |
|---|
| 98 | 96 | busname, |
|---|
| 99 | 97 | PCI_SLOT(us_ibdev->pdev->devfn), |
|---|
| 100 | 98 | PCI_FUNC(us_ibdev->pdev->devfn), |
|---|
| .. | .. |
|---|
| 119 | 117 | UPDATE_PTR_LEFT(n, ptr, left); |
|---|
| 120 | 118 | } else { |
|---|
| 121 | 119 | n = scnprintf(ptr, left, "%s: no VFs\n", |
|---|
| 122 | | - us_ibdev->ib_dev.name); |
|---|
| 120 | + dev_name(&us_ibdev->ib_dev.dev)); |
|---|
| 123 | 121 | UPDATE_PTR_LEFT(n, ptr, left); |
|---|
| 124 | 122 | } |
|---|
| 125 | 123 | mutex_unlock(&us_ibdev->usdev_lock); |
|---|
| 126 | 124 | |
|---|
| 127 | 125 | return ptr - buf; |
|---|
| 128 | 126 | } |
|---|
| 127 | +static DEVICE_ATTR_RO(config); |
|---|
| 129 | 128 | |
|---|
| 130 | 129 | static ssize_t |
|---|
| 131 | | -usnic_ib_show_iface(struct device *device, struct device_attribute *attr, |
|---|
| 132 | | - char *buf) |
|---|
| 130 | +iface_show(struct device *device, struct device_attribute *attr, char *buf) |
|---|
| 133 | 131 | { |
|---|
| 134 | | - struct usnic_ib_dev *us_ibdev; |
|---|
| 135 | | - |
|---|
| 136 | | - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 132 | + struct usnic_ib_dev *us_ibdev = |
|---|
| 133 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 137 | 134 | |
|---|
| 138 | 135 | return scnprintf(buf, PAGE_SIZE, "%s\n", |
|---|
| 139 | 136 | netdev_name(us_ibdev->netdev)); |
|---|
| 140 | 137 | } |
|---|
| 138 | +static DEVICE_ATTR_RO(iface); |
|---|
| 141 | 139 | |
|---|
| 142 | 140 | static ssize_t |
|---|
| 143 | | -usnic_ib_show_max_vf(struct device *device, struct device_attribute *attr, |
|---|
| 144 | | - char *buf) |
|---|
| 141 | +max_vf_show(struct device *device, struct device_attribute *attr, char *buf) |
|---|
| 145 | 142 | { |
|---|
| 146 | | - struct usnic_ib_dev *us_ibdev; |
|---|
| 147 | | - |
|---|
| 148 | | - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 143 | + struct usnic_ib_dev *us_ibdev = |
|---|
| 144 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 149 | 145 | |
|---|
| 150 | 146 | return scnprintf(buf, PAGE_SIZE, "%u\n", |
|---|
| 151 | 147 | kref_read(&us_ibdev->vf_cnt)); |
|---|
| 152 | 148 | } |
|---|
| 149 | +static DEVICE_ATTR_RO(max_vf); |
|---|
| 153 | 150 | |
|---|
| 154 | 151 | static ssize_t |
|---|
| 155 | | -usnic_ib_show_qp_per_vf(struct device *device, struct device_attribute *attr, |
|---|
| 156 | | - char *buf) |
|---|
| 152 | +qp_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) |
|---|
| 157 | 153 | { |
|---|
| 158 | | - struct usnic_ib_dev *us_ibdev; |
|---|
| 154 | + struct usnic_ib_dev *us_ibdev = |
|---|
| 155 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 159 | 156 | int qp_per_vf; |
|---|
| 160 | 157 | |
|---|
| 161 | | - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 162 | 158 | qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ], |
|---|
| 163 | 159 | us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]); |
|---|
| 164 | 160 | |
|---|
| 165 | 161 | return scnprintf(buf, PAGE_SIZE, |
|---|
| 166 | 162 | "%d\n", qp_per_vf); |
|---|
| 167 | 163 | } |
|---|
| 164 | +static DEVICE_ATTR_RO(qp_per_vf); |
|---|
| 168 | 165 | |
|---|
| 169 | 166 | static ssize_t |
|---|
| 170 | | -usnic_ib_show_cq_per_vf(struct device *device, struct device_attribute *attr, |
|---|
| 171 | | - char *buf) |
|---|
| 167 | +cq_per_vf_show(struct device *device, struct device_attribute *attr, char *buf) |
|---|
| 172 | 168 | { |
|---|
| 173 | | - struct usnic_ib_dev *us_ibdev; |
|---|
| 174 | | - |
|---|
| 175 | | - us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); |
|---|
| 169 | + struct usnic_ib_dev *us_ibdev = |
|---|
| 170 | + rdma_device_to_drv_device(device, struct usnic_ib_dev, ib_dev); |
|---|
| 176 | 171 | |
|---|
| 177 | 172 | return scnprintf(buf, PAGE_SIZE, "%d\n", |
|---|
| 178 | 173 | us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ]); |
|---|
| 179 | 174 | } |
|---|
| 175 | +static DEVICE_ATTR_RO(cq_per_vf); |
|---|
| 180 | 176 | |
|---|
| 181 | | -static DEVICE_ATTR(board_id, S_IRUGO, usnic_ib_show_board, NULL); |
|---|
| 182 | | -static DEVICE_ATTR(config, S_IRUGO, usnic_ib_show_config, NULL); |
|---|
| 183 | | -static DEVICE_ATTR(iface, S_IRUGO, usnic_ib_show_iface, NULL); |
|---|
| 184 | | -static DEVICE_ATTR(max_vf, S_IRUGO, usnic_ib_show_max_vf, NULL); |
|---|
| 185 | | -static DEVICE_ATTR(qp_per_vf, S_IRUGO, usnic_ib_show_qp_per_vf, NULL); |
|---|
| 186 | | -static DEVICE_ATTR(cq_per_vf, S_IRUGO, usnic_ib_show_cq_per_vf, NULL); |
|---|
| 177 | +static struct attribute *usnic_class_attributes[] = { |
|---|
| 178 | + &dev_attr_board_id.attr, |
|---|
| 179 | + &dev_attr_config.attr, |
|---|
| 180 | + &dev_attr_iface.attr, |
|---|
| 181 | + &dev_attr_max_vf.attr, |
|---|
| 182 | + &dev_attr_qp_per_vf.attr, |
|---|
| 183 | + &dev_attr_cq_per_vf.attr, |
|---|
| 184 | + NULL |
|---|
| 185 | +}; |
|---|
| 187 | 186 | |
|---|
| 188 | | -static struct device_attribute *usnic_class_attributes[] = { |
|---|
| 189 | | - &dev_attr_board_id, |
|---|
| 190 | | - &dev_attr_config, |
|---|
| 191 | | - &dev_attr_iface, |
|---|
| 192 | | - &dev_attr_max_vf, |
|---|
| 193 | | - &dev_attr_qp_per_vf, |
|---|
| 194 | | - &dev_attr_cq_per_vf, |
|---|
| 187 | +const struct attribute_group usnic_attr_group = { |
|---|
| 188 | + .attrs = usnic_class_attributes, |
|---|
| 195 | 189 | }; |
|---|
| 196 | 190 | |
|---|
| 197 | 191 | struct qpn_attribute { |
|---|
| .. | .. |
|---|
| 278 | 272 | |
|---|
| 279 | 273 | int usnic_ib_sysfs_register_usdev(struct usnic_ib_dev *us_ibdev) |
|---|
| 280 | 274 | { |
|---|
| 281 | | - int i; |
|---|
| 282 | | - int err; |
|---|
| 283 | | - for (i = 0; i < ARRAY_SIZE(usnic_class_attributes); ++i) { |
|---|
| 284 | | - err = device_create_file(&us_ibdev->ib_dev.dev, |
|---|
| 285 | | - usnic_class_attributes[i]); |
|---|
| 286 | | - if (err) { |
|---|
| 287 | | - usnic_err("Failed to create device file %d for %s eith err %d", |
|---|
| 288 | | - i, us_ibdev->ib_dev.name, err); |
|---|
| 289 | | - return -EINVAL; |
|---|
| 290 | | - } |
|---|
| 291 | | - } |
|---|
| 292 | | - |
|---|
| 293 | 275 | /* create kernel object for looking at individual QPs */ |
|---|
| 294 | 276 | kobject_get(&us_ibdev->ib_dev.dev.kobj); |
|---|
| 295 | 277 | us_ibdev->qpn_kobj = kobject_create_and_add("qpn", |
|---|
| .. | .. |
|---|
| 304 | 286 | |
|---|
| 305 | 287 | void usnic_ib_sysfs_unregister_usdev(struct usnic_ib_dev *us_ibdev) |
|---|
| 306 | 288 | { |
|---|
| 307 | | - int i; |
|---|
| 308 | | - for (i = 0; i < ARRAY_SIZE(usnic_class_attributes); ++i) { |
|---|
| 309 | | - device_remove_file(&us_ibdev->ib_dev.dev, |
|---|
| 310 | | - usnic_class_attributes[i]); |
|---|
| 311 | | - } |
|---|
| 312 | | - |
|---|
| 313 | 289 | kobject_put(us_ibdev->qpn_kobj); |
|---|
| 314 | 290 | } |
|---|
| 315 | 291 | |
|---|