sysfs.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
  4. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include "core_priv.h"
  35. #include <linux/slab.h>
  36. #include <linux/stat.h>
  37. #include <linux/string.h>
  38. #include <linux/netdevice.h>
  39. #include <rdma/ib_mad.h>
  40. #include <rdma/ib_pma.h>
  41. struct ib_port;
  42. struct gid_attr_group {
  43. struct ib_port *port;
  44. struct kobject kobj;
  45. struct attribute_group ndev;
  46. struct attribute_group type;
  47. };
  48. struct ib_port {
  49. struct kobject kobj;
  50. struct ib_device *ibdev;
  51. struct gid_attr_group *gid_attr_group;
  52. struct attribute_group gid_group;
  53. struct attribute_group pkey_group;
  54. u8 port_num;
  55. struct attribute_group *pma_table;
  56. };
  57. struct port_attribute {
  58. struct attribute attr;
  59. ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
  60. ssize_t (*store)(struct ib_port *, struct port_attribute *,
  61. const char *buf, size_t count);
  62. };
  63. #define PORT_ATTR(_name, _mode, _show, _store) \
  64. struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
  65. #define PORT_ATTR_RO(_name) \
  66. struct port_attribute port_attr_##_name = __ATTR_RO(_name)
  67. struct port_table_attribute {
  68. struct port_attribute attr;
  69. char name[8];
  70. int index;
  71. int attr_id;
  72. };
  73. static ssize_t port_attr_show(struct kobject *kobj,
  74. struct attribute *attr, char *buf)
  75. {
  76. struct port_attribute *port_attr =
  77. container_of(attr, struct port_attribute, attr);
  78. struct ib_port *p = container_of(kobj, struct ib_port, kobj);
  79. if (!port_attr->show)
  80. return -EIO;
  81. return port_attr->show(p, port_attr, buf);
  82. }
  83. static const struct sysfs_ops port_sysfs_ops = {
  84. .show = port_attr_show
  85. };
  86. static ssize_t gid_attr_show(struct kobject *kobj,
  87. struct attribute *attr, char *buf)
  88. {
  89. struct port_attribute *port_attr =
  90. container_of(attr, struct port_attribute, attr);
  91. struct ib_port *p = container_of(kobj, struct gid_attr_group,
  92. kobj)->port;
  93. if (!port_attr->show)
  94. return -EIO;
  95. return port_attr->show(p, port_attr, buf);
  96. }
  97. static const struct sysfs_ops gid_attr_sysfs_ops = {
  98. .show = gid_attr_show
  99. };
  100. static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
  101. char *buf)
  102. {
  103. struct ib_port_attr attr;
  104. ssize_t ret;
  105. static const char *state_name[] = {
  106. [IB_PORT_NOP] = "NOP",
  107. [IB_PORT_DOWN] = "DOWN",
  108. [IB_PORT_INIT] = "INIT",
  109. [IB_PORT_ARMED] = "ARMED",
  110. [IB_PORT_ACTIVE] = "ACTIVE",
  111. [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
  112. };
  113. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  114. if (ret)
  115. return ret;
  116. return sprintf(buf, "%d: %s\n", attr.state,
  117. attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
  118. state_name[attr.state] : "UNKNOWN");
  119. }
  120. static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
  121. char *buf)
  122. {
  123. struct ib_port_attr attr;
  124. ssize_t ret;
  125. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  126. if (ret)
  127. return ret;
  128. return sprintf(buf, "0x%x\n", attr.lid);
  129. }
  130. static ssize_t lid_mask_count_show(struct ib_port *p,
  131. struct port_attribute *unused,
  132. char *buf)
  133. {
  134. struct ib_port_attr attr;
  135. ssize_t ret;
  136. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  137. if (ret)
  138. return ret;
  139. return sprintf(buf, "%d\n", attr.lmc);
  140. }
  141. static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
  142. char *buf)
  143. {
  144. struct ib_port_attr attr;
  145. ssize_t ret;
  146. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  147. if (ret)
  148. return ret;
  149. return sprintf(buf, "0x%x\n", attr.sm_lid);
  150. }
  151. static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
  152. char *buf)
  153. {
  154. struct ib_port_attr attr;
  155. ssize_t ret;
  156. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  157. if (ret)
  158. return ret;
  159. return sprintf(buf, "%d\n", attr.sm_sl);
  160. }
  161. static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
  162. char *buf)
  163. {
  164. struct ib_port_attr attr;
  165. ssize_t ret;
  166. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  167. if (ret)
  168. return ret;
  169. return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
  170. }
  171. static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
  172. char *buf)
  173. {
  174. struct ib_port_attr attr;
  175. char *speed = "";
  176. int rate; /* in deci-Gb/sec */
  177. ssize_t ret;
  178. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  179. if (ret)
  180. return ret;
  181. switch (attr.active_speed) {
  182. case IB_SPEED_DDR:
  183. speed = " DDR";
  184. rate = 50;
  185. break;
  186. case IB_SPEED_QDR:
  187. speed = " QDR";
  188. rate = 100;
  189. break;
  190. case IB_SPEED_FDR10:
  191. speed = " FDR10";
  192. rate = 100;
  193. break;
  194. case IB_SPEED_FDR:
  195. speed = " FDR";
  196. rate = 140;
  197. break;
  198. case IB_SPEED_EDR:
  199. speed = " EDR";
  200. rate = 250;
  201. break;
  202. case IB_SPEED_SDR:
  203. default: /* default to SDR for invalid rates */
  204. rate = 25;
  205. break;
  206. }
  207. rate *= ib_width_enum_to_int(attr.active_width);
  208. if (rate < 0)
  209. return -EINVAL;
  210. return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
  211. rate / 10, rate % 10 ? ".5" : "",
  212. ib_width_enum_to_int(attr.active_width), speed);
  213. }
  214. static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
  215. char *buf)
  216. {
  217. struct ib_port_attr attr;
  218. ssize_t ret;
  219. ret = ib_query_port(p->ibdev, p->port_num, &attr);
  220. if (ret)
  221. return ret;
  222. switch (attr.phys_state) {
  223. case 1: return sprintf(buf, "1: Sleep\n");
  224. case 2: return sprintf(buf, "2: Polling\n");
  225. case 3: return sprintf(buf, "3: Disabled\n");
  226. case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
  227. case 5: return sprintf(buf, "5: LinkUp\n");
  228. case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
  229. case 7: return sprintf(buf, "7: Phy Test\n");
  230. default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
  231. }
  232. }
  233. static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
  234. char *buf)
  235. {
  236. switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
  237. case IB_LINK_LAYER_INFINIBAND:
  238. return sprintf(buf, "%s\n", "InfiniBand");
  239. case IB_LINK_LAYER_ETHERNET:
  240. return sprintf(buf, "%s\n", "Ethernet");
  241. default:
  242. return sprintf(buf, "%s\n", "Unknown");
  243. }
  244. }
  245. static PORT_ATTR_RO(state);
  246. static PORT_ATTR_RO(lid);
  247. static PORT_ATTR_RO(lid_mask_count);
  248. static PORT_ATTR_RO(sm_lid);
  249. static PORT_ATTR_RO(sm_sl);
  250. static PORT_ATTR_RO(cap_mask);
  251. static PORT_ATTR_RO(rate);
  252. static PORT_ATTR_RO(phys_state);
  253. static PORT_ATTR_RO(link_layer);
  254. static struct attribute *port_default_attrs[] = {
  255. &port_attr_state.attr,
  256. &port_attr_lid.attr,
  257. &port_attr_lid_mask_count.attr,
  258. &port_attr_sm_lid.attr,
  259. &port_attr_sm_sl.attr,
  260. &port_attr_cap_mask.attr,
  261. &port_attr_rate.attr,
  262. &port_attr_phys_state.attr,
  263. &port_attr_link_layer.attr,
  264. NULL
  265. };
  266. static size_t print_ndev(struct ib_gid_attr *gid_attr, char *buf)
  267. {
  268. if (!gid_attr->ndev)
  269. return -EINVAL;
  270. return sprintf(buf, "%s\n", gid_attr->ndev->name);
  271. }
  272. static size_t print_gid_type(struct ib_gid_attr *gid_attr, char *buf)
  273. {
  274. return sprintf(buf, "%s\n", ib_cache_gid_type_str(gid_attr->gid_type));
  275. }
  276. static ssize_t _show_port_gid_attr(struct ib_port *p,
  277. struct port_attribute *attr,
  278. char *buf,
  279. size_t (*print)(struct ib_gid_attr *gid_attr,
  280. char *buf))
  281. {
  282. struct port_table_attribute *tab_attr =
  283. container_of(attr, struct port_table_attribute, attr);
  284. union ib_gid gid;
  285. struct ib_gid_attr gid_attr = {};
  286. ssize_t ret;
  287. va_list args;
  288. ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid,
  289. &gid_attr);
  290. if (ret)
  291. goto err;
  292. ret = print(&gid_attr, buf);
  293. err:
  294. if (gid_attr.ndev)
  295. dev_put(gid_attr.ndev);
  296. va_end(args);
  297. return ret;
  298. }
  299. static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
  300. char *buf)
  301. {
  302. struct port_table_attribute *tab_attr =
  303. container_of(attr, struct port_table_attribute, attr);
  304. union ib_gid gid;
  305. ssize_t ret;
  306. ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid, NULL);
  307. if (ret)
  308. return ret;
  309. return sprintf(buf, "%pI6\n", gid.raw);
  310. }
  311. static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
  312. struct port_attribute *attr, char *buf)
  313. {
  314. return _show_port_gid_attr(p, attr, buf, print_ndev);
  315. }
  316. static ssize_t show_port_gid_attr_gid_type(struct ib_port *p,
  317. struct port_attribute *attr,
  318. char *buf)
  319. {
  320. return _show_port_gid_attr(p, attr, buf, print_gid_type);
  321. }
  322. static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
  323. char *buf)
  324. {
  325. struct port_table_attribute *tab_attr =
  326. container_of(attr, struct port_table_attribute, attr);
  327. u16 pkey;
  328. ssize_t ret;
  329. ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
  330. if (ret)
  331. return ret;
  332. return sprintf(buf, "0x%04x\n", pkey);
  333. }
  334. #define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
  335. struct port_table_attribute port_pma_attr_##_name = { \
  336. .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
  337. .index = (_offset) | ((_width) << 16) | ((_counter) << 24), \
  338. .attr_id = IB_PMA_PORT_COUNTERS , \
  339. }
  340. #define PORT_PMA_ATTR_EXT(_name, _width, _offset) \
  341. struct port_table_attribute port_pma_attr_ext_##_name = { \
  342. .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
  343. .index = (_offset) | ((_width) << 16), \
  344. .attr_id = IB_PMA_PORT_COUNTERS_EXT , \
  345. }
  346. /*
  347. * Get a Perfmgmt MAD block of data.
  348. * Returns error code or the number of bytes retrieved.
  349. */
  350. static int get_perf_mad(struct ib_device *dev, int port_num, int attr,
  351. void *data, int offset, size_t size)
  352. {
  353. struct ib_mad *in_mad;
  354. struct ib_mad *out_mad;
  355. size_t mad_size = sizeof(*out_mad);
  356. u16 out_mad_pkey_index = 0;
  357. ssize_t ret;
  358. if (!dev->process_mad)
  359. return -ENOSYS;
  360. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  361. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  362. if (!in_mad || !out_mad) {
  363. ret = -ENOMEM;
  364. goto out;
  365. }
  366. in_mad->mad_hdr.base_version = 1;
  367. in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
  368. in_mad->mad_hdr.class_version = 1;
  369. in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
  370. in_mad->mad_hdr.attr_id = attr;
  371. in_mad->data[41] = port_num; /* PortSelect field */
  372. if ((dev->process_mad(dev, IB_MAD_IGNORE_MKEY,
  373. port_num, NULL, NULL,
  374. (const struct ib_mad_hdr *)in_mad, mad_size,
  375. (struct ib_mad_hdr *)out_mad, &mad_size,
  376. &out_mad_pkey_index) &
  377. (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
  378. (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
  379. ret = -EINVAL;
  380. goto out;
  381. }
  382. memcpy(data, out_mad->data + offset, size);
  383. ret = size;
  384. out:
  385. kfree(in_mad);
  386. kfree(out_mad);
  387. return ret;
  388. }
  389. static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
  390. char *buf)
  391. {
  392. struct port_table_attribute *tab_attr =
  393. container_of(attr, struct port_table_attribute, attr);
  394. int offset = tab_attr->index & 0xffff;
  395. int width = (tab_attr->index >> 16) & 0xff;
  396. ssize_t ret;
  397. u8 data[8];
  398. ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data,
  399. 40 + offset / 8, sizeof(data));
  400. if (ret < 0)
  401. return sprintf(buf, "N/A (no PMA)\n");
  402. switch (width) {
  403. case 4:
  404. ret = sprintf(buf, "%u\n", (*data >>
  405. (4 - (offset % 8))) & 0xf);
  406. break;
  407. case 8:
  408. ret = sprintf(buf, "%u\n", *data);
  409. break;
  410. case 16:
  411. ret = sprintf(buf, "%u\n",
  412. be16_to_cpup((__be16 *)data));
  413. break;
  414. case 32:
  415. ret = sprintf(buf, "%u\n",
  416. be32_to_cpup((__be32 *)data));
  417. break;
  418. case 64:
  419. ret = sprintf(buf, "%llu\n",
  420. be64_to_cpup((__be64 *)data));
  421. break;
  422. default:
  423. ret = 0;
  424. }
  425. return ret;
  426. }
  427. static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
  428. static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
  429. static PORT_PMA_ATTR(link_downed , 2, 8, 56);
  430. static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
  431. static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
  432. static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
  433. static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
  434. static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
  435. static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
  436. static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
  437. static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
  438. static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
  439. static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
  440. static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
  441. static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
  442. static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
  443. /*
  444. * Counters added by extended set
  445. */
  446. static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64);
  447. static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128);
  448. static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192);
  449. static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256);
  450. static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320);
  451. static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384);
  452. static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448);
  453. static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512);
  454. static struct attribute *pma_attrs[] = {
  455. &port_pma_attr_symbol_error.attr.attr,
  456. &port_pma_attr_link_error_recovery.attr.attr,
  457. &port_pma_attr_link_downed.attr.attr,
  458. &port_pma_attr_port_rcv_errors.attr.attr,
  459. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  460. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  461. &port_pma_attr_port_xmit_discards.attr.attr,
  462. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  463. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  464. &port_pma_attr_local_link_integrity_errors.attr.attr,
  465. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  466. &port_pma_attr_VL15_dropped.attr.attr,
  467. &port_pma_attr_port_xmit_data.attr.attr,
  468. &port_pma_attr_port_rcv_data.attr.attr,
  469. &port_pma_attr_port_xmit_packets.attr.attr,
  470. &port_pma_attr_port_rcv_packets.attr.attr,
  471. NULL
  472. };
  473. static struct attribute *pma_attrs_ext[] = {
  474. &port_pma_attr_symbol_error.attr.attr,
  475. &port_pma_attr_link_error_recovery.attr.attr,
  476. &port_pma_attr_link_downed.attr.attr,
  477. &port_pma_attr_port_rcv_errors.attr.attr,
  478. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  479. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  480. &port_pma_attr_port_xmit_discards.attr.attr,
  481. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  482. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  483. &port_pma_attr_local_link_integrity_errors.attr.attr,
  484. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  485. &port_pma_attr_VL15_dropped.attr.attr,
  486. &port_pma_attr_ext_port_xmit_data.attr.attr,
  487. &port_pma_attr_ext_port_rcv_data.attr.attr,
  488. &port_pma_attr_ext_port_xmit_packets.attr.attr,
  489. &port_pma_attr_ext_port_rcv_packets.attr.attr,
  490. &port_pma_attr_ext_unicast_rcv_packets.attr.attr,
  491. &port_pma_attr_ext_unicast_xmit_packets.attr.attr,
  492. &port_pma_attr_ext_multicast_rcv_packets.attr.attr,
  493. &port_pma_attr_ext_multicast_xmit_packets.attr.attr,
  494. NULL
  495. };
  496. static struct attribute *pma_attrs_noietf[] = {
  497. &port_pma_attr_symbol_error.attr.attr,
  498. &port_pma_attr_link_error_recovery.attr.attr,
  499. &port_pma_attr_link_downed.attr.attr,
  500. &port_pma_attr_port_rcv_errors.attr.attr,
  501. &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
  502. &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
  503. &port_pma_attr_port_xmit_discards.attr.attr,
  504. &port_pma_attr_port_xmit_constraint_errors.attr.attr,
  505. &port_pma_attr_port_rcv_constraint_errors.attr.attr,
  506. &port_pma_attr_local_link_integrity_errors.attr.attr,
  507. &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
  508. &port_pma_attr_VL15_dropped.attr.attr,
  509. &port_pma_attr_ext_port_xmit_data.attr.attr,
  510. &port_pma_attr_ext_port_rcv_data.attr.attr,
  511. &port_pma_attr_ext_port_xmit_packets.attr.attr,
  512. &port_pma_attr_ext_port_rcv_packets.attr.attr,
  513. NULL
  514. };
  515. static struct attribute_group pma_group = {
  516. .name = "counters",
  517. .attrs = pma_attrs
  518. };
  519. static struct attribute_group pma_group_ext = {
  520. .name = "counters",
  521. .attrs = pma_attrs_ext
  522. };
  523. static struct attribute_group pma_group_noietf = {
  524. .name = "counters",
  525. .attrs = pma_attrs_noietf
  526. };
  527. static void ib_port_release(struct kobject *kobj)
  528. {
  529. struct ib_port *p = container_of(kobj, struct ib_port, kobj);
  530. struct attribute *a;
  531. int i;
  532. if (p->gid_group.attrs) {
  533. for (i = 0; (a = p->gid_group.attrs[i]); ++i)
  534. kfree(a);
  535. kfree(p->gid_group.attrs);
  536. }
  537. if (p->pkey_group.attrs) {
  538. for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
  539. kfree(a);
  540. kfree(p->pkey_group.attrs);
  541. }
  542. kfree(p);
  543. }
  544. static void ib_port_gid_attr_release(struct kobject *kobj)
  545. {
  546. struct gid_attr_group *g = container_of(kobj, struct gid_attr_group,
  547. kobj);
  548. struct attribute *a;
  549. int i;
  550. if (g->ndev.attrs) {
  551. for (i = 0; (a = g->ndev.attrs[i]); ++i)
  552. kfree(a);
  553. kfree(g->ndev.attrs);
  554. }
  555. if (g->type.attrs) {
  556. for (i = 0; (a = g->type.attrs[i]); ++i)
  557. kfree(a);
  558. kfree(g->type.attrs);
  559. }
  560. kfree(g);
  561. }
  562. static struct kobj_type port_type = {
  563. .release = ib_port_release,
  564. .sysfs_ops = &port_sysfs_ops,
  565. .default_attrs = port_default_attrs
  566. };
  567. static struct kobj_type gid_attr_type = {
  568. .sysfs_ops = &gid_attr_sysfs_ops,
  569. .release = ib_port_gid_attr_release
  570. };
  571. static struct attribute **
  572. alloc_group_attrs(ssize_t (*show)(struct ib_port *,
  573. struct port_attribute *, char *buf),
  574. int len)
  575. {
  576. struct attribute **tab_attr;
  577. struct port_table_attribute *element;
  578. int i;
  579. tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
  580. if (!tab_attr)
  581. return NULL;
  582. for (i = 0; i < len; i++) {
  583. element = kzalloc(sizeof(struct port_table_attribute),
  584. GFP_KERNEL);
  585. if (!element)
  586. goto err;
  587. if (snprintf(element->name, sizeof(element->name),
  588. "%d", i) >= sizeof(element->name)) {
  589. kfree(element);
  590. goto err;
  591. }
  592. element->attr.attr.name = element->name;
  593. element->attr.attr.mode = S_IRUGO;
  594. element->attr.show = show;
  595. element->index = i;
  596. sysfs_attr_init(&element->attr.attr);
  597. tab_attr[i] = &element->attr.attr;
  598. }
  599. return tab_attr;
  600. err:
  601. while (--i >= 0)
  602. kfree(tab_attr[i]);
  603. kfree(tab_attr);
  604. return NULL;
  605. }
  606. /*
  607. * Figure out which counter table to use depending on
  608. * the device capabilities.
  609. */
  610. static struct attribute_group *get_counter_table(struct ib_device *dev)
  611. {
  612. struct ib_class_port_info cpi;
  613. if (get_perf_mad(dev, 0, IB_PMA_CLASS_PORT_INFO,
  614. &cpi, 40, sizeof(cpi)) >= 0) {
  615. if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH)
  616. /* We have extended counters */
  617. return &pma_group_ext;
  618. if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF)
  619. /* But not the IETF ones */
  620. return &pma_group_noietf;
  621. }
  622. /* Fall back to normal counters */
  623. return &pma_group;
  624. }
  625. static int add_port(struct ib_device *device, int port_num,
  626. int (*port_callback)(struct ib_device *,
  627. u8, struct kobject *))
  628. {
  629. struct ib_port *p;
  630. struct ib_port_attr attr;
  631. int i;
  632. int ret;
  633. ret = ib_query_port(device, port_num, &attr);
  634. if (ret)
  635. return ret;
  636. p = kzalloc(sizeof *p, GFP_KERNEL);
  637. if (!p)
  638. return -ENOMEM;
  639. p->ibdev = device;
  640. p->port_num = port_num;
  641. ret = kobject_init_and_add(&p->kobj, &port_type,
  642. device->ports_parent,
  643. "%d", port_num);
  644. if (ret) {
  645. kfree(p);
  646. return ret;
  647. }
  648. p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL);
  649. if (!p->gid_attr_group) {
  650. ret = -ENOMEM;
  651. goto err_put;
  652. }
  653. p->gid_attr_group->port = p;
  654. ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type,
  655. &p->kobj, "gid_attrs");
  656. if (ret) {
  657. kfree(p->gid_attr_group);
  658. goto err_put;
  659. }
  660. p->pma_table = get_counter_table(device);
  661. ret = sysfs_create_group(&p->kobj, p->pma_table);
  662. if (ret)
  663. goto err_put_gid_attrs;
  664. p->gid_group.name = "gids";
  665. p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
  666. if (!p->gid_group.attrs) {
  667. ret = -ENOMEM;
  668. goto err_remove_pma;
  669. }
  670. ret = sysfs_create_group(&p->kobj, &p->gid_group);
  671. if (ret)
  672. goto err_free_gid;
  673. p->gid_attr_group->ndev.name = "ndevs";
  674. p->gid_attr_group->ndev.attrs = alloc_group_attrs(show_port_gid_attr_ndev,
  675. attr.gid_tbl_len);
  676. if (!p->gid_attr_group->ndev.attrs) {
  677. ret = -ENOMEM;
  678. goto err_remove_gid;
  679. }
  680. ret = sysfs_create_group(&p->gid_attr_group->kobj,
  681. &p->gid_attr_group->ndev);
  682. if (ret)
  683. goto err_free_gid_ndev;
  684. p->gid_attr_group->type.name = "types";
  685. p->gid_attr_group->type.attrs = alloc_group_attrs(show_port_gid_attr_gid_type,
  686. attr.gid_tbl_len);
  687. if (!p->gid_attr_group->type.attrs) {
  688. ret = -ENOMEM;
  689. goto err_remove_gid_ndev;
  690. }
  691. ret = sysfs_create_group(&p->gid_attr_group->kobj,
  692. &p->gid_attr_group->type);
  693. if (ret)
  694. goto err_free_gid_type;
  695. p->pkey_group.name = "pkeys";
  696. p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
  697. attr.pkey_tbl_len);
  698. if (!p->pkey_group.attrs) {
  699. ret = -ENOMEM;
  700. goto err_remove_gid_type;
  701. }
  702. ret = sysfs_create_group(&p->kobj, &p->pkey_group);
  703. if (ret)
  704. goto err_free_pkey;
  705. if (port_callback) {
  706. ret = port_callback(device, port_num, &p->kobj);
  707. if (ret)
  708. goto err_remove_pkey;
  709. }
  710. list_add_tail(&p->kobj.entry, &device->port_list);
  711. kobject_uevent(&p->kobj, KOBJ_ADD);
  712. return 0;
  713. err_remove_pkey:
  714. sysfs_remove_group(&p->kobj, &p->pkey_group);
  715. err_free_pkey:
  716. for (i = 0; i < attr.pkey_tbl_len; ++i)
  717. kfree(p->pkey_group.attrs[i]);
  718. kfree(p->pkey_group.attrs);
  719. p->pkey_group.attrs = NULL;
  720. err_remove_gid_type:
  721. sysfs_remove_group(&p->gid_attr_group->kobj,
  722. &p->gid_attr_group->type);
  723. err_free_gid_type:
  724. for (i = 0; i < attr.gid_tbl_len; ++i)
  725. kfree(p->gid_attr_group->type.attrs[i]);
  726. kfree(p->gid_attr_group->type.attrs);
  727. p->gid_attr_group->type.attrs = NULL;
  728. err_remove_gid_ndev:
  729. sysfs_remove_group(&p->gid_attr_group->kobj,
  730. &p->gid_attr_group->ndev);
  731. err_free_gid_ndev:
  732. for (i = 0; i < attr.gid_tbl_len; ++i)
  733. kfree(p->gid_attr_group->ndev.attrs[i]);
  734. kfree(p->gid_attr_group->ndev.attrs);
  735. p->gid_attr_group->ndev.attrs = NULL;
  736. err_remove_gid:
  737. sysfs_remove_group(&p->kobj, &p->gid_group);
  738. err_free_gid:
  739. for (i = 0; i < attr.gid_tbl_len; ++i)
  740. kfree(p->gid_group.attrs[i]);
  741. kfree(p->gid_group.attrs);
  742. p->gid_group.attrs = NULL;
  743. err_remove_pma:
  744. sysfs_remove_group(&p->kobj, p->pma_table);
  745. err_put_gid_attrs:
  746. kobject_put(&p->gid_attr_group->kobj);
  747. err_put:
  748. kobject_put(&p->kobj);
  749. return ret;
  750. }
  751. static ssize_t show_node_type(struct device *device,
  752. struct device_attribute *attr, char *buf)
  753. {
  754. struct ib_device *dev = container_of(device, struct ib_device, dev);
  755. switch (dev->node_type) {
  756. case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
  757. case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
  758. case RDMA_NODE_USNIC: return sprintf(buf, "%d: usNIC\n", dev->node_type);
  759. case RDMA_NODE_USNIC_UDP: return sprintf(buf, "%d: usNIC UDP\n", dev->node_type);
  760. case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
  761. case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
  762. default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
  763. }
  764. }
  765. static ssize_t show_sys_image_guid(struct device *device,
  766. struct device_attribute *dev_attr, char *buf)
  767. {
  768. struct ib_device *dev = container_of(device, struct ib_device, dev);
  769. return sprintf(buf, "%04x:%04x:%04x:%04x\n",
  770. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[0]),
  771. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[1]),
  772. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[2]),
  773. be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[3]));
  774. }
  775. static ssize_t show_node_guid(struct device *device,
  776. struct device_attribute *attr, char *buf)
  777. {
  778. struct ib_device *dev = container_of(device, struct ib_device, dev);
  779. return sprintf(buf, "%04x:%04x:%04x:%04x\n",
  780. be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
  781. be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
  782. be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
  783. be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
  784. }
  785. static ssize_t show_node_desc(struct device *device,
  786. struct device_attribute *attr, char *buf)
  787. {
  788. struct ib_device *dev = container_of(device, struct ib_device, dev);
  789. return sprintf(buf, "%.64s\n", dev->node_desc);
  790. }
  791. static ssize_t set_node_desc(struct device *device,
  792. struct device_attribute *attr,
  793. const char *buf, size_t count)
  794. {
  795. struct ib_device *dev = container_of(device, struct ib_device, dev);
  796. struct ib_device_modify desc = {};
  797. int ret;
  798. if (!dev->modify_device)
  799. return -EIO;
  800. memcpy(desc.node_desc, buf, min_t(int, count, 64));
  801. ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
  802. if (ret)
  803. return ret;
  804. return count;
  805. }
  806. static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
  807. static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
  808. static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
  809. static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
  810. static struct device_attribute *ib_class_attributes[] = {
  811. &dev_attr_node_type,
  812. &dev_attr_sys_image_guid,
  813. &dev_attr_node_guid,
  814. &dev_attr_node_desc
  815. };
  816. /* Show a given an attribute in the statistics group */
  817. static ssize_t show_protocol_stat(const struct device *device,
  818. struct device_attribute *attr, char *buf,
  819. unsigned offset)
  820. {
  821. struct ib_device *dev = container_of(device, struct ib_device, dev);
  822. union rdma_protocol_stats stats;
  823. ssize_t ret;
  824. ret = dev->get_protocol_stats(dev, &stats);
  825. if (ret)
  826. return ret;
  827. return sprintf(buf, "%llu\n",
  828. (unsigned long long) ((u64 *) &stats)[offset]);
  829. }
  830. /* generate a read-only iwarp statistics attribute */
  831. #define IW_STATS_ENTRY(name) \
  832. static ssize_t show_##name(struct device *device, \
  833. struct device_attribute *attr, char *buf) \
  834. { \
  835. return show_protocol_stat(device, attr, buf, \
  836. offsetof(struct iw_protocol_stats, name) / \
  837. sizeof (u64)); \
  838. } \
  839. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
  840. IW_STATS_ENTRY(ipInReceives);
  841. IW_STATS_ENTRY(ipInHdrErrors);
  842. IW_STATS_ENTRY(ipInTooBigErrors);
  843. IW_STATS_ENTRY(ipInNoRoutes);
  844. IW_STATS_ENTRY(ipInAddrErrors);
  845. IW_STATS_ENTRY(ipInUnknownProtos);
  846. IW_STATS_ENTRY(ipInTruncatedPkts);
  847. IW_STATS_ENTRY(ipInDiscards);
  848. IW_STATS_ENTRY(ipInDelivers);
  849. IW_STATS_ENTRY(ipOutForwDatagrams);
  850. IW_STATS_ENTRY(ipOutRequests);
  851. IW_STATS_ENTRY(ipOutDiscards);
  852. IW_STATS_ENTRY(ipOutNoRoutes);
  853. IW_STATS_ENTRY(ipReasmTimeout);
  854. IW_STATS_ENTRY(ipReasmReqds);
  855. IW_STATS_ENTRY(ipReasmOKs);
  856. IW_STATS_ENTRY(ipReasmFails);
  857. IW_STATS_ENTRY(ipFragOKs);
  858. IW_STATS_ENTRY(ipFragFails);
  859. IW_STATS_ENTRY(ipFragCreates);
  860. IW_STATS_ENTRY(ipInMcastPkts);
  861. IW_STATS_ENTRY(ipOutMcastPkts);
  862. IW_STATS_ENTRY(ipInBcastPkts);
  863. IW_STATS_ENTRY(ipOutBcastPkts);
  864. IW_STATS_ENTRY(tcpRtoAlgorithm);
  865. IW_STATS_ENTRY(tcpRtoMin);
  866. IW_STATS_ENTRY(tcpRtoMax);
  867. IW_STATS_ENTRY(tcpMaxConn);
  868. IW_STATS_ENTRY(tcpActiveOpens);
  869. IW_STATS_ENTRY(tcpPassiveOpens);
  870. IW_STATS_ENTRY(tcpAttemptFails);
  871. IW_STATS_ENTRY(tcpEstabResets);
  872. IW_STATS_ENTRY(tcpCurrEstab);
  873. IW_STATS_ENTRY(tcpInSegs);
  874. IW_STATS_ENTRY(tcpOutSegs);
  875. IW_STATS_ENTRY(tcpRetransSegs);
  876. IW_STATS_ENTRY(tcpInErrs);
  877. IW_STATS_ENTRY(tcpOutRsts);
  878. static struct attribute *iw_proto_stats_attrs[] = {
  879. &dev_attr_ipInReceives.attr,
  880. &dev_attr_ipInHdrErrors.attr,
  881. &dev_attr_ipInTooBigErrors.attr,
  882. &dev_attr_ipInNoRoutes.attr,
  883. &dev_attr_ipInAddrErrors.attr,
  884. &dev_attr_ipInUnknownProtos.attr,
  885. &dev_attr_ipInTruncatedPkts.attr,
  886. &dev_attr_ipInDiscards.attr,
  887. &dev_attr_ipInDelivers.attr,
  888. &dev_attr_ipOutForwDatagrams.attr,
  889. &dev_attr_ipOutRequests.attr,
  890. &dev_attr_ipOutDiscards.attr,
  891. &dev_attr_ipOutNoRoutes.attr,
  892. &dev_attr_ipReasmTimeout.attr,
  893. &dev_attr_ipReasmReqds.attr,
  894. &dev_attr_ipReasmOKs.attr,
  895. &dev_attr_ipReasmFails.attr,
  896. &dev_attr_ipFragOKs.attr,
  897. &dev_attr_ipFragFails.attr,
  898. &dev_attr_ipFragCreates.attr,
  899. &dev_attr_ipInMcastPkts.attr,
  900. &dev_attr_ipOutMcastPkts.attr,
  901. &dev_attr_ipInBcastPkts.attr,
  902. &dev_attr_ipOutBcastPkts.attr,
  903. &dev_attr_tcpRtoAlgorithm.attr,
  904. &dev_attr_tcpRtoMin.attr,
  905. &dev_attr_tcpRtoMax.attr,
  906. &dev_attr_tcpMaxConn.attr,
  907. &dev_attr_tcpActiveOpens.attr,
  908. &dev_attr_tcpPassiveOpens.attr,
  909. &dev_attr_tcpAttemptFails.attr,
  910. &dev_attr_tcpEstabResets.attr,
  911. &dev_attr_tcpCurrEstab.attr,
  912. &dev_attr_tcpInSegs.attr,
  913. &dev_attr_tcpOutSegs.attr,
  914. &dev_attr_tcpRetransSegs.attr,
  915. &dev_attr_tcpInErrs.attr,
  916. &dev_attr_tcpOutRsts.attr,
  917. NULL
  918. };
  919. static struct attribute_group iw_stats_group = {
  920. .name = "proto_stats",
  921. .attrs = iw_proto_stats_attrs,
  922. };
  923. static void free_port_list_attributes(struct ib_device *device)
  924. {
  925. struct kobject *p, *t;
  926. list_for_each_entry_safe(p, t, &device->port_list, entry) {
  927. struct ib_port *port = container_of(p, struct ib_port, kobj);
  928. list_del(&p->entry);
  929. sysfs_remove_group(p, port->pma_table);
  930. sysfs_remove_group(p, &port->pkey_group);
  931. sysfs_remove_group(p, &port->gid_group);
  932. sysfs_remove_group(&port->gid_attr_group->kobj,
  933. &port->gid_attr_group->ndev);
  934. sysfs_remove_group(&port->gid_attr_group->kobj,
  935. &port->gid_attr_group->type);
  936. kobject_put(&port->gid_attr_group->kobj);
  937. kobject_put(p);
  938. }
  939. kobject_put(device->ports_parent);
  940. }
  941. int ib_device_register_sysfs(struct ib_device *device,
  942. int (*port_callback)(struct ib_device *,
  943. u8, struct kobject *))
  944. {
  945. struct device *class_dev = &device->dev;
  946. int ret;
  947. int i;
  948. device->dev.parent = device->dma_device;
  949. ret = dev_set_name(class_dev, "%s", device->name);
  950. if (ret)
  951. return ret;
  952. ret = device_add(class_dev);
  953. if (ret)
  954. goto err;
  955. for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
  956. ret = device_create_file(class_dev, ib_class_attributes[i]);
  957. if (ret)
  958. goto err_unregister;
  959. }
  960. device->ports_parent = kobject_create_and_add("ports",
  961. &class_dev->kobj);
  962. if (!device->ports_parent) {
  963. ret = -ENOMEM;
  964. goto err_put;
  965. }
  966. if (rdma_cap_ib_switch(device)) {
  967. ret = add_port(device, 0, port_callback);
  968. if (ret)
  969. goto err_put;
  970. } else {
  971. for (i = 1; i <= device->phys_port_cnt; ++i) {
  972. ret = add_port(device, i, port_callback);
  973. if (ret)
  974. goto err_put;
  975. }
  976. }
  977. if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
  978. ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
  979. if (ret)
  980. goto err_put;
  981. }
  982. return 0;
  983. err_put:
  984. free_port_list_attributes(device);
  985. err_unregister:
  986. device_unregister(class_dev);
  987. err:
  988. return ret;
  989. }
  990. void ib_device_unregister_sysfs(struct ib_device *device)
  991. {
  992. /* Hold kobject until ib_dealloc_device() */
  993. struct kobject *kobj_dev = kobject_get(&device->dev.kobj);
  994. int i;
  995. if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats)
  996. sysfs_remove_group(kobj_dev, &iw_stats_group);
  997. free_port_list_attributes(device);
  998. for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i)
  999. device_remove_file(&device->dev, ib_class_attributes[i]);
  1000. device_unregister(&device->dev);
  1001. }