qeth_core_sys.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. * Copyright IBM Corp. 2007
  3. * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
  4. * Frank Pavlic <fpavlic@de.ibm.com>,
  5. * Thomas Spatzier <tspat@de.ibm.com>,
  6. * Frank Blaschka <frank.blaschka@de.ibm.com>
  7. */
  8. #define KMSG_COMPONENT "qeth"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/list.h>
  11. #include <linux/rwsem.h>
  12. #include <asm/ebcdic.h>
  13. #include "qeth_core.h"
  14. static ssize_t qeth_dev_state_show(struct device *dev,
  15. struct device_attribute *attr, char *buf)
  16. {
  17. struct qeth_card *card = dev_get_drvdata(dev);
  18. if (!card)
  19. return -EINVAL;
  20. switch (card->state) {
  21. case CARD_STATE_DOWN:
  22. return sprintf(buf, "DOWN\n");
  23. case CARD_STATE_HARDSETUP:
  24. return sprintf(buf, "HARDSETUP\n");
  25. case CARD_STATE_SOFTSETUP:
  26. return sprintf(buf, "SOFTSETUP\n");
  27. case CARD_STATE_UP:
  28. if (card->lan_online)
  29. return sprintf(buf, "UP (LAN ONLINE)\n");
  30. else
  31. return sprintf(buf, "UP (LAN OFFLINE)\n");
  32. case CARD_STATE_RECOVER:
  33. return sprintf(buf, "RECOVER\n");
  34. default:
  35. return sprintf(buf, "UNKNOWN\n");
  36. }
  37. }
  38. static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
  39. static ssize_t qeth_dev_chpid_show(struct device *dev,
  40. struct device_attribute *attr, char *buf)
  41. {
  42. struct qeth_card *card = dev_get_drvdata(dev);
  43. if (!card)
  44. return -EINVAL;
  45. return sprintf(buf, "%02X\n", card->info.chpid);
  46. }
  47. static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
  48. static ssize_t qeth_dev_if_name_show(struct device *dev,
  49. struct device_attribute *attr, char *buf)
  50. {
  51. struct qeth_card *card = dev_get_drvdata(dev);
  52. if (!card)
  53. return -EINVAL;
  54. return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
  55. }
  56. static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
  57. static ssize_t qeth_dev_card_type_show(struct device *dev,
  58. struct device_attribute *attr, char *buf)
  59. {
  60. struct qeth_card *card = dev_get_drvdata(dev);
  61. if (!card)
  62. return -EINVAL;
  63. return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
  64. }
  65. static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
  66. static inline const char *qeth_get_bufsize_str(struct qeth_card *card)
  67. {
  68. if (card->qdio.in_buf_size == 16384)
  69. return "16k";
  70. else if (card->qdio.in_buf_size == 24576)
  71. return "24k";
  72. else if (card->qdio.in_buf_size == 32768)
  73. return "32k";
  74. else if (card->qdio.in_buf_size == 40960)
  75. return "40k";
  76. else
  77. return "64k";
  78. }
  79. static ssize_t qeth_dev_inbuf_size_show(struct device *dev,
  80. struct device_attribute *attr, char *buf)
  81. {
  82. struct qeth_card *card = dev_get_drvdata(dev);
  83. if (!card)
  84. return -EINVAL;
  85. return sprintf(buf, "%s\n", qeth_get_bufsize_str(card));
  86. }
  87. static DEVICE_ATTR(inbuf_size, 0444, qeth_dev_inbuf_size_show, NULL);
  88. static ssize_t qeth_dev_portno_show(struct device *dev,
  89. struct device_attribute *attr, char *buf)
  90. {
  91. struct qeth_card *card = dev_get_drvdata(dev);
  92. if (!card)
  93. return -EINVAL;
  94. return sprintf(buf, "%i\n", card->info.portno);
  95. }
  96. static ssize_t qeth_dev_portno_store(struct device *dev,
  97. struct device_attribute *attr, const char *buf, size_t count)
  98. {
  99. struct qeth_card *card = dev_get_drvdata(dev);
  100. char *tmp;
  101. unsigned int portno, limit;
  102. int rc = 0;
  103. if (!card)
  104. return -EINVAL;
  105. mutex_lock(&card->conf_mutex);
  106. if ((card->state != CARD_STATE_DOWN) &&
  107. (card->state != CARD_STATE_RECOVER)) {
  108. rc = -EPERM;
  109. goto out;
  110. }
  111. portno = simple_strtoul(buf, &tmp, 16);
  112. if (portno > QETH_MAX_PORTNO) {
  113. rc = -EINVAL;
  114. goto out;
  115. }
  116. limit = (card->ssqd.pcnt ? card->ssqd.pcnt - 1 : card->ssqd.pcnt);
  117. if (portno > limit) {
  118. rc = -EINVAL;
  119. goto out;
  120. }
  121. card->info.portno = portno;
  122. out:
  123. mutex_unlock(&card->conf_mutex);
  124. return rc ? rc : count;
  125. }
  126. static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
  127. static ssize_t qeth_dev_portname_show(struct device *dev,
  128. struct device_attribute *attr, char *buf)
  129. {
  130. return sprintf(buf, "no portname required\n");
  131. }
  132. static ssize_t qeth_dev_portname_store(struct device *dev,
  133. struct device_attribute *attr, const char *buf, size_t count)
  134. {
  135. struct qeth_card *card = dev_get_drvdata(dev);
  136. dev_warn_once(&card->gdev->dev,
  137. "portname is deprecated and is ignored\n");
  138. return count;
  139. }
  140. static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
  141. qeth_dev_portname_store);
  142. static ssize_t qeth_dev_prioqing_show(struct device *dev,
  143. struct device_attribute *attr, char *buf)
  144. {
  145. struct qeth_card *card = dev_get_drvdata(dev);
  146. if (!card)
  147. return -EINVAL;
  148. switch (card->qdio.do_prio_queueing) {
  149. case QETH_PRIO_Q_ING_PREC:
  150. return sprintf(buf, "%s\n", "by precedence");
  151. case QETH_PRIO_Q_ING_TOS:
  152. return sprintf(buf, "%s\n", "by type of service");
  153. case QETH_PRIO_Q_ING_SKB:
  154. return sprintf(buf, "%s\n", "by skb-priority");
  155. case QETH_PRIO_Q_ING_VLAN:
  156. return sprintf(buf, "%s\n", "by VLAN headers");
  157. default:
  158. return sprintf(buf, "always queue %i\n",
  159. card->qdio.default_out_queue);
  160. }
  161. }
  162. static ssize_t qeth_dev_prioqing_store(struct device *dev,
  163. struct device_attribute *attr, const char *buf, size_t count)
  164. {
  165. struct qeth_card *card = dev_get_drvdata(dev);
  166. int rc = 0;
  167. if (!card)
  168. return -EINVAL;
  169. mutex_lock(&card->conf_mutex);
  170. if ((card->state != CARD_STATE_DOWN) &&
  171. (card->state != CARD_STATE_RECOVER)) {
  172. rc = -EPERM;
  173. goto out;
  174. }
  175. /* check if 1920 devices are supported ,
  176. * if though we have to permit priority queueing
  177. */
  178. if (card->qdio.no_out_queues == 1) {
  179. card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
  180. rc = -EPERM;
  181. goto out;
  182. }
  183. if (sysfs_streq(buf, "prio_queueing_prec")) {
  184. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
  185. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  186. } else if (sysfs_streq(buf, "prio_queueing_skb")) {
  187. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_SKB;
  188. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  189. } else if (sysfs_streq(buf, "prio_queueing_tos")) {
  190. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
  191. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  192. } else if (sysfs_streq(buf, "prio_queueing_vlan")) {
  193. if (!card->options.layer2) {
  194. rc = -ENOTSUPP;
  195. goto out;
  196. }
  197. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_VLAN;
  198. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  199. } else if (sysfs_streq(buf, "no_prio_queueing:0")) {
  200. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  201. card->qdio.default_out_queue = 0;
  202. } else if (sysfs_streq(buf, "no_prio_queueing:1")) {
  203. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  204. card->qdio.default_out_queue = 1;
  205. } else if (sysfs_streq(buf, "no_prio_queueing:2")) {
  206. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  207. card->qdio.default_out_queue = 2;
  208. } else if (sysfs_streq(buf, "no_prio_queueing:3")) {
  209. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  210. card->qdio.default_out_queue = 3;
  211. } else if (sysfs_streq(buf, "no_prio_queueing")) {
  212. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  213. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  214. } else
  215. rc = -EINVAL;
  216. out:
  217. mutex_unlock(&card->conf_mutex);
  218. return rc ? rc : count;
  219. }
  220. static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
  221. qeth_dev_prioqing_store);
  222. static ssize_t qeth_dev_bufcnt_show(struct device *dev,
  223. struct device_attribute *attr, char *buf)
  224. {
  225. struct qeth_card *card = dev_get_drvdata(dev);
  226. if (!card)
  227. return -EINVAL;
  228. return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
  229. }
  230. static ssize_t qeth_dev_bufcnt_store(struct device *dev,
  231. struct device_attribute *attr, const char *buf, size_t count)
  232. {
  233. struct qeth_card *card = dev_get_drvdata(dev);
  234. char *tmp;
  235. int cnt, old_cnt;
  236. int rc = 0;
  237. if (!card)
  238. return -EINVAL;
  239. mutex_lock(&card->conf_mutex);
  240. if ((card->state != CARD_STATE_DOWN) &&
  241. (card->state != CARD_STATE_RECOVER)) {
  242. rc = -EPERM;
  243. goto out;
  244. }
  245. old_cnt = card->qdio.in_buf_pool.buf_count;
  246. cnt = simple_strtoul(buf, &tmp, 10);
  247. cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
  248. ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
  249. if (old_cnt != cnt) {
  250. rc = qeth_realloc_buffer_pool(card, cnt);
  251. }
  252. out:
  253. mutex_unlock(&card->conf_mutex);
  254. return rc ? rc : count;
  255. }
  256. static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
  257. qeth_dev_bufcnt_store);
  258. static ssize_t qeth_dev_recover_store(struct device *dev,
  259. struct device_attribute *attr, const char *buf, size_t count)
  260. {
  261. struct qeth_card *card = dev_get_drvdata(dev);
  262. char *tmp;
  263. int i;
  264. if (!card)
  265. return -EINVAL;
  266. if (card->state != CARD_STATE_UP)
  267. return -EPERM;
  268. i = simple_strtoul(buf, &tmp, 16);
  269. if (i == 1)
  270. qeth_schedule_recovery(card);
  271. return count;
  272. }
  273. static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
  274. static ssize_t qeth_dev_performance_stats_show(struct device *dev,
  275. struct device_attribute *attr, char *buf)
  276. {
  277. struct qeth_card *card = dev_get_drvdata(dev);
  278. if (!card)
  279. return -EINVAL;
  280. return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
  281. }
  282. static ssize_t qeth_dev_performance_stats_store(struct device *dev,
  283. struct device_attribute *attr, const char *buf, size_t count)
  284. {
  285. struct qeth_card *card = dev_get_drvdata(dev);
  286. char *tmp;
  287. int i, rc = 0;
  288. if (!card)
  289. return -EINVAL;
  290. mutex_lock(&card->conf_mutex);
  291. i = simple_strtoul(buf, &tmp, 16);
  292. if ((i == 0) || (i == 1)) {
  293. if (i == card->options.performance_stats)
  294. goto out;
  295. card->options.performance_stats = i;
  296. if (i == 0)
  297. memset(&card->perf_stats, 0,
  298. sizeof(struct qeth_perf_stats));
  299. card->perf_stats.initial_rx_packets = card->stats.rx_packets;
  300. card->perf_stats.initial_tx_packets = card->stats.tx_packets;
  301. } else
  302. rc = -EINVAL;
  303. out:
  304. mutex_unlock(&card->conf_mutex);
  305. return rc ? rc : count;
  306. }
  307. static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
  308. qeth_dev_performance_stats_store);
  309. static ssize_t qeth_dev_layer2_show(struct device *dev,
  310. struct device_attribute *attr, char *buf)
  311. {
  312. struct qeth_card *card = dev_get_drvdata(dev);
  313. if (!card)
  314. return -EINVAL;
  315. return sprintf(buf, "%i\n", card->options.layer2);
  316. }
  317. static ssize_t qeth_dev_layer2_store(struct device *dev,
  318. struct device_attribute *attr, const char *buf, size_t count)
  319. {
  320. struct qeth_card *card = dev_get_drvdata(dev);
  321. char *tmp;
  322. int i, rc = 0;
  323. enum qeth_discipline_id newdis;
  324. if (!card)
  325. return -EINVAL;
  326. mutex_lock(&card->discipline_mutex);
  327. if (card->state != CARD_STATE_DOWN) {
  328. rc = -EPERM;
  329. goto out;
  330. }
  331. i = simple_strtoul(buf, &tmp, 16);
  332. switch (i) {
  333. case 0:
  334. newdis = QETH_DISCIPLINE_LAYER3;
  335. break;
  336. case 1:
  337. newdis = QETH_DISCIPLINE_LAYER2;
  338. break;
  339. default:
  340. rc = -EINVAL;
  341. goto out;
  342. }
  343. if (card->options.layer2 == newdis)
  344. goto out;
  345. if (card->info.type == QETH_CARD_TYPE_OSM) {
  346. /* fixed layer, can't switch */
  347. rc = -EOPNOTSUPP;
  348. goto out;
  349. }
  350. card->info.mac_bits = 0;
  351. if (card->discipline) {
  352. card->discipline->remove(card->gdev);
  353. qeth_core_free_discipline(card);
  354. card->options.layer2 = -1;
  355. }
  356. rc = qeth_core_load_discipline(card, newdis);
  357. if (rc)
  358. goto out;
  359. rc = card->discipline->setup(card->gdev);
  360. if (rc)
  361. qeth_core_free_discipline(card);
  362. out:
  363. mutex_unlock(&card->discipline_mutex);
  364. return rc ? rc : count;
  365. }
  366. static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
  367. qeth_dev_layer2_store);
  368. #define ATTR_QETH_ISOLATION_NONE ("none")
  369. #define ATTR_QETH_ISOLATION_FWD ("forward")
  370. #define ATTR_QETH_ISOLATION_DROP ("drop")
  371. static ssize_t qeth_dev_isolation_show(struct device *dev,
  372. struct device_attribute *attr, char *buf)
  373. {
  374. struct qeth_card *card = dev_get_drvdata(dev);
  375. if (!card)
  376. return -EINVAL;
  377. switch (card->options.isolation) {
  378. case ISOLATION_MODE_NONE:
  379. return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_NONE);
  380. case ISOLATION_MODE_FWD:
  381. return snprintf(buf, 9, "%s\n", ATTR_QETH_ISOLATION_FWD);
  382. case ISOLATION_MODE_DROP:
  383. return snprintf(buf, 6, "%s\n", ATTR_QETH_ISOLATION_DROP);
  384. default:
  385. return snprintf(buf, 5, "%s\n", "N/A");
  386. }
  387. }
  388. static ssize_t qeth_dev_isolation_store(struct device *dev,
  389. struct device_attribute *attr, const char *buf, size_t count)
  390. {
  391. struct qeth_card *card = dev_get_drvdata(dev);
  392. enum qeth_ipa_isolation_modes isolation;
  393. int rc = 0;
  394. if (!card)
  395. return -EINVAL;
  396. mutex_lock(&card->conf_mutex);
  397. /* check for unknown, too, in case we do not yet know who we are */
  398. if (card->info.type != QETH_CARD_TYPE_OSD &&
  399. card->info.type != QETH_CARD_TYPE_OSX &&
  400. card->info.type != QETH_CARD_TYPE_UNKNOWN) {
  401. rc = -EOPNOTSUPP;
  402. dev_err(&card->gdev->dev, "Adapter does not "
  403. "support QDIO data connection isolation\n");
  404. goto out;
  405. }
  406. /* parse input into isolation mode */
  407. if (sysfs_streq(buf, ATTR_QETH_ISOLATION_NONE)) {
  408. isolation = ISOLATION_MODE_NONE;
  409. } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_FWD)) {
  410. isolation = ISOLATION_MODE_FWD;
  411. } else if (sysfs_streq(buf, ATTR_QETH_ISOLATION_DROP)) {
  412. isolation = ISOLATION_MODE_DROP;
  413. } else {
  414. rc = -EINVAL;
  415. goto out;
  416. }
  417. rc = count;
  418. /* defer IP assist if device is offline (until discipline->set_online)*/
  419. card->options.prev_isolation = card->options.isolation;
  420. card->options.isolation = isolation;
  421. if (qeth_card_hw_is_reachable(card)) {
  422. int ipa_rc = qeth_set_access_ctrl_online(card, 1);
  423. if (ipa_rc != 0)
  424. rc = ipa_rc;
  425. }
  426. out:
  427. mutex_unlock(&card->conf_mutex);
  428. return rc;
  429. }
  430. static DEVICE_ATTR(isolation, 0644, qeth_dev_isolation_show,
  431. qeth_dev_isolation_store);
  432. static ssize_t qeth_dev_switch_attrs_show(struct device *dev,
  433. struct device_attribute *attr, char *buf)
  434. {
  435. struct qeth_card *card = dev_get_drvdata(dev);
  436. struct qeth_switch_info sw_info;
  437. int rc = 0;
  438. if (!card)
  439. return -EINVAL;
  440. if (!qeth_card_hw_is_reachable(card))
  441. return sprintf(buf, "n/a\n");
  442. rc = qeth_query_switch_attributes(card, &sw_info);
  443. if (rc)
  444. return rc;
  445. if (!sw_info.capabilities)
  446. rc = sprintf(buf, "unknown");
  447. if (sw_info.capabilities & QETH_SWITCH_FORW_802_1)
  448. rc = sprintf(buf, (sw_info.settings & QETH_SWITCH_FORW_802_1 ?
  449. "[802.1]" : "802.1"));
  450. if (sw_info.capabilities & QETH_SWITCH_FORW_REFL_RELAY)
  451. rc += sprintf(buf + rc,
  452. (sw_info.settings & QETH_SWITCH_FORW_REFL_RELAY ?
  453. " [rr]" : " rr"));
  454. rc += sprintf(buf + rc, "\n");
  455. return rc;
  456. }
  457. static DEVICE_ATTR(switch_attrs, 0444,
  458. qeth_dev_switch_attrs_show, NULL);
  459. static ssize_t qeth_hw_trap_show(struct device *dev,
  460. struct device_attribute *attr, char *buf)
  461. {
  462. struct qeth_card *card = dev_get_drvdata(dev);
  463. if (!card)
  464. return -EINVAL;
  465. if (card->info.hwtrap)
  466. return snprintf(buf, 5, "arm\n");
  467. else
  468. return snprintf(buf, 8, "disarm\n");
  469. }
  470. static ssize_t qeth_hw_trap_store(struct device *dev,
  471. struct device_attribute *attr, const char *buf, size_t count)
  472. {
  473. struct qeth_card *card = dev_get_drvdata(dev);
  474. int rc = 0;
  475. int state = 0;
  476. if (!card)
  477. return -EINVAL;
  478. mutex_lock(&card->conf_mutex);
  479. if (qeth_card_hw_is_reachable(card))
  480. state = 1;
  481. if (sysfs_streq(buf, "arm") && !card->info.hwtrap) {
  482. if (state) {
  483. if (qeth_is_diagass_supported(card,
  484. QETH_DIAGS_CMD_TRAP)) {
  485. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM);
  486. if (!rc)
  487. card->info.hwtrap = 1;
  488. } else
  489. rc = -EINVAL;
  490. } else
  491. card->info.hwtrap = 1;
  492. } else if (sysfs_streq(buf, "disarm") && card->info.hwtrap) {
  493. if (state) {
  494. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
  495. if (!rc)
  496. card->info.hwtrap = 0;
  497. } else
  498. card->info.hwtrap = 0;
  499. } else if (sysfs_streq(buf, "trap") && state && card->info.hwtrap)
  500. rc = qeth_hw_trap(card, QETH_DIAGS_TRAP_CAPTURE);
  501. else
  502. rc = -EINVAL;
  503. mutex_unlock(&card->conf_mutex);
  504. return rc ? rc : count;
  505. }
  506. static DEVICE_ATTR(hw_trap, 0644, qeth_hw_trap_show,
  507. qeth_hw_trap_store);
  508. static ssize_t qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value)
  509. {
  510. if (!card)
  511. return -EINVAL;
  512. return sprintf(buf, "%i\n", value);
  513. }
  514. static ssize_t qeth_dev_blkt_store(struct qeth_card *card,
  515. const char *buf, size_t count, int *value, int max_value)
  516. {
  517. char *tmp;
  518. int i, rc = 0;
  519. if (!card)
  520. return -EINVAL;
  521. mutex_lock(&card->conf_mutex);
  522. if ((card->state != CARD_STATE_DOWN) &&
  523. (card->state != CARD_STATE_RECOVER)) {
  524. rc = -EPERM;
  525. goto out;
  526. }
  527. i = simple_strtoul(buf, &tmp, 10);
  528. if (i <= max_value)
  529. *value = i;
  530. else
  531. rc = -EINVAL;
  532. out:
  533. mutex_unlock(&card->conf_mutex);
  534. return rc ? rc : count;
  535. }
  536. static ssize_t qeth_dev_blkt_total_show(struct device *dev,
  537. struct device_attribute *attr, char *buf)
  538. {
  539. struct qeth_card *card = dev_get_drvdata(dev);
  540. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  541. }
  542. static ssize_t qeth_dev_blkt_total_store(struct device *dev,
  543. struct device_attribute *attr, const char *buf, size_t count)
  544. {
  545. struct qeth_card *card = dev_get_drvdata(dev);
  546. return qeth_dev_blkt_store(card, buf, count,
  547. &card->info.blkt.time_total, 5000);
  548. }
  549. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  550. qeth_dev_blkt_total_store);
  551. static ssize_t qeth_dev_blkt_inter_show(struct device *dev,
  552. struct device_attribute *attr, char *buf)
  553. {
  554. struct qeth_card *card = dev_get_drvdata(dev);
  555. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  556. }
  557. static ssize_t qeth_dev_blkt_inter_store(struct device *dev,
  558. struct device_attribute *attr, const char *buf, size_t count)
  559. {
  560. struct qeth_card *card = dev_get_drvdata(dev);
  561. return qeth_dev_blkt_store(card, buf, count,
  562. &card->info.blkt.inter_packet, 1000);
  563. }
  564. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  565. qeth_dev_blkt_inter_store);
  566. static ssize_t qeth_dev_blkt_inter_jumbo_show(struct device *dev,
  567. struct device_attribute *attr, char *buf)
  568. {
  569. struct qeth_card *card = dev_get_drvdata(dev);
  570. return qeth_dev_blkt_show(buf, card,
  571. card->info.blkt.inter_packet_jumbo);
  572. }
  573. static ssize_t qeth_dev_blkt_inter_jumbo_store(struct device *dev,
  574. struct device_attribute *attr, const char *buf, size_t count)
  575. {
  576. struct qeth_card *card = dev_get_drvdata(dev);
  577. return qeth_dev_blkt_store(card, buf, count,
  578. &card->info.blkt.inter_packet_jumbo, 1000);
  579. }
  580. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  581. qeth_dev_blkt_inter_jumbo_store);
  582. static struct attribute *qeth_blkt_device_attrs[] = {
  583. &dev_attr_total.attr,
  584. &dev_attr_inter.attr,
  585. &dev_attr_inter_jumbo.attr,
  586. NULL,
  587. };
  588. const struct attribute_group qeth_device_blkt_group = {
  589. .name = "blkt",
  590. .attrs = qeth_blkt_device_attrs,
  591. };
  592. EXPORT_SYMBOL_GPL(qeth_device_blkt_group);
  593. static struct attribute *qeth_device_attrs[] = {
  594. &dev_attr_state.attr,
  595. &dev_attr_chpid.attr,
  596. &dev_attr_if_name.attr,
  597. &dev_attr_card_type.attr,
  598. &dev_attr_inbuf_size.attr,
  599. &dev_attr_portno.attr,
  600. &dev_attr_portname.attr,
  601. &dev_attr_priority_queueing.attr,
  602. &dev_attr_buffer_count.attr,
  603. &dev_attr_recover.attr,
  604. &dev_attr_performance_stats.attr,
  605. &dev_attr_layer2.attr,
  606. &dev_attr_isolation.attr,
  607. &dev_attr_hw_trap.attr,
  608. &dev_attr_switch_attrs.attr,
  609. NULL,
  610. };
  611. const struct attribute_group qeth_device_attr_group = {
  612. .attrs = qeth_device_attrs,
  613. };
  614. EXPORT_SYMBOL_GPL(qeth_device_attr_group);
  615. const struct attribute_group *qeth_generic_attr_groups[] = {
  616. &qeth_device_attr_group,
  617. &qeth_device_blkt_group,
  618. NULL,
  619. };
  620. static struct attribute *qeth_osn_device_attrs[] = {
  621. &dev_attr_state.attr,
  622. &dev_attr_chpid.attr,
  623. &dev_attr_if_name.attr,
  624. &dev_attr_card_type.attr,
  625. &dev_attr_buffer_count.attr,
  626. &dev_attr_recover.attr,
  627. NULL,
  628. };
  629. static struct attribute_group qeth_osn_device_attr_group = {
  630. .attrs = qeth_osn_device_attrs,
  631. };
  632. const struct attribute_group *qeth_osn_attr_groups[] = {
  633. &qeth_osn_device_attr_group,
  634. NULL,
  635. };