qeth_sys.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. /*
  2. *
  3. * linux/drivers/s390/net/qeth_sys.c
  4. *
  5. * Linux on zSeries OSA Express and HiperSockets support
  6. * This file contains code related to sysfs.
  7. *
  8. * Copyright 2000,2003 IBM Corporation
  9. *
  10. * Author(s): Thomas Spatzier <tspat@de.ibm.com>
  11. * Frank Pavlic <fpavlic@de.ibm.com>
  12. *
  13. */
  14. #include <linux/list.h>
  15. #include <linux/rwsem.h>
  16. #include <asm/ebcdic.h>
  17. #include "qeth.h"
  18. #include "qeth_mpc.h"
  19. #include "qeth_fs.h"
  20. /*****************************************************************************/
  21. /* */
  22. /* /sys-fs stuff UNDER DEVELOPMENT !!! */
  23. /* */
  24. /*****************************************************************************/
  25. //low/high watermark
  26. static ssize_t
  27. qeth_dev_state_show(struct device *dev, struct device_attribute *attr, char *buf)
  28. {
  29. struct qeth_card *card = dev->driver_data;
  30. if (!card)
  31. return -EINVAL;
  32. switch (card->state) {
  33. case CARD_STATE_DOWN:
  34. return sprintf(buf, "DOWN\n");
  35. case CARD_STATE_HARDSETUP:
  36. return sprintf(buf, "HARDSETUP\n");
  37. case CARD_STATE_SOFTSETUP:
  38. return sprintf(buf, "SOFTSETUP\n");
  39. case CARD_STATE_UP:
  40. if (card->lan_online)
  41. return sprintf(buf, "UP (LAN ONLINE)\n");
  42. else
  43. return sprintf(buf, "UP (LAN OFFLINE)\n");
  44. case CARD_STATE_RECOVER:
  45. return sprintf(buf, "RECOVER\n");
  46. default:
  47. return sprintf(buf, "UNKNOWN\n");
  48. }
  49. }
  50. static DEVICE_ATTR(state, 0444, qeth_dev_state_show, NULL);
  51. static ssize_t
  52. qeth_dev_chpid_show(struct device *dev, struct device_attribute *attr, char *buf)
  53. {
  54. struct qeth_card *card = dev->driver_data;
  55. if (!card)
  56. return -EINVAL;
  57. return sprintf(buf, "%02X\n", card->info.chpid);
  58. }
  59. static DEVICE_ATTR(chpid, 0444, qeth_dev_chpid_show, NULL);
  60. static ssize_t
  61. qeth_dev_if_name_show(struct device *dev, struct device_attribute *attr, char *buf)
  62. {
  63. struct qeth_card *card = dev->driver_data;
  64. if (!card)
  65. return -EINVAL;
  66. return sprintf(buf, "%s\n", QETH_CARD_IFNAME(card));
  67. }
  68. static DEVICE_ATTR(if_name, 0444, qeth_dev_if_name_show, NULL);
  69. static ssize_t
  70. qeth_dev_card_type_show(struct device *dev, struct device_attribute *attr, char *buf)
  71. {
  72. struct qeth_card *card = dev->driver_data;
  73. if (!card)
  74. return -EINVAL;
  75. return sprintf(buf, "%s\n", qeth_get_cardname_short(card));
  76. }
  77. static DEVICE_ATTR(card_type, 0444, qeth_dev_card_type_show, NULL);
  78. static ssize_t
  79. qeth_dev_portno_show(struct device *dev, struct device_attribute *attr, char *buf)
  80. {
  81. struct qeth_card *card = dev->driver_data;
  82. if (!card)
  83. return -EINVAL;
  84. return sprintf(buf, "%i\n", card->info.portno);
  85. }
  86. static ssize_t
  87. qeth_dev_portno_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  88. {
  89. struct qeth_card *card = dev->driver_data;
  90. char *tmp;
  91. unsigned int portno;
  92. if (!card)
  93. return -EINVAL;
  94. if ((card->state != CARD_STATE_DOWN) &&
  95. (card->state != CARD_STATE_RECOVER))
  96. return -EPERM;
  97. portno = simple_strtoul(buf, &tmp, 16);
  98. if (portno > MAX_PORTNO){
  99. PRINT_WARN("portno 0x%X is out of range\n", portno);
  100. return -EINVAL;
  101. }
  102. card->info.portno = portno;
  103. return count;
  104. }
  105. static DEVICE_ATTR(portno, 0644, qeth_dev_portno_show, qeth_dev_portno_store);
  106. static ssize_t
  107. qeth_dev_portname_show(struct device *dev, struct device_attribute *attr, char *buf)
  108. {
  109. struct qeth_card *card = dev->driver_data;
  110. char portname[9] = {0, };
  111. if (!card)
  112. return -EINVAL;
  113. if (card->info.portname_required) {
  114. memcpy(portname, card->info.portname + 1, 8);
  115. EBCASC(portname, 8);
  116. return sprintf(buf, "%s\n", portname);
  117. } else
  118. return sprintf(buf, "no portname required\n");
  119. }
  120. static ssize_t
  121. qeth_dev_portname_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  122. {
  123. struct qeth_card *card = dev->driver_data;
  124. char *tmp;
  125. int i;
  126. if (!card)
  127. return -EINVAL;
  128. if ((card->state != CARD_STATE_DOWN) &&
  129. (card->state != CARD_STATE_RECOVER))
  130. return -EPERM;
  131. tmp = strsep((char **) &buf, "\n");
  132. if ((strlen(tmp) > 8) || (strlen(tmp) == 0))
  133. return -EINVAL;
  134. card->info.portname[0] = strlen(tmp);
  135. /* for beauty reasons */
  136. for (i = 1; i < 9; i++)
  137. card->info.portname[i] = ' ';
  138. strcpy(card->info.portname + 1, tmp);
  139. ASCEBC(card->info.portname + 1, 8);
  140. return count;
  141. }
  142. static DEVICE_ATTR(portname, 0644, qeth_dev_portname_show,
  143. qeth_dev_portname_store);
  144. static ssize_t
  145. qeth_dev_checksum_show(struct device *dev, struct device_attribute *attr, char *buf)
  146. {
  147. struct qeth_card *card = dev->driver_data;
  148. if (!card)
  149. return -EINVAL;
  150. return sprintf(buf, "%s checksumming\n", qeth_get_checksum_str(card));
  151. }
  152. static ssize_t
  153. qeth_dev_checksum_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  154. {
  155. struct qeth_card *card = dev->driver_data;
  156. char *tmp;
  157. if (!card)
  158. return -EINVAL;
  159. if ((card->state != CARD_STATE_DOWN) &&
  160. (card->state != CARD_STATE_RECOVER))
  161. return -EPERM;
  162. tmp = strsep((char **) &buf, "\n");
  163. if (!strcmp(tmp, "sw_checksumming"))
  164. card->options.checksum_type = SW_CHECKSUMMING;
  165. else if (!strcmp(tmp, "hw_checksumming"))
  166. card->options.checksum_type = HW_CHECKSUMMING;
  167. else if (!strcmp(tmp, "no_checksumming"))
  168. card->options.checksum_type = NO_CHECKSUMMING;
  169. else {
  170. PRINT_WARN("Unknown checksumming type '%s'\n", tmp);
  171. return -EINVAL;
  172. }
  173. return count;
  174. }
  175. static DEVICE_ATTR(checksumming, 0644, qeth_dev_checksum_show,
  176. qeth_dev_checksum_store);
  177. static ssize_t
  178. qeth_dev_prioqing_show(struct device *dev, struct device_attribute *attr, char *buf)
  179. {
  180. struct qeth_card *card = dev->driver_data;
  181. if (!card)
  182. return -EINVAL;
  183. switch (card->qdio.do_prio_queueing) {
  184. case QETH_PRIO_Q_ING_PREC:
  185. return sprintf(buf, "%s\n", "by precedence");
  186. case QETH_PRIO_Q_ING_TOS:
  187. return sprintf(buf, "%s\n", "by type of service");
  188. default:
  189. return sprintf(buf, "always queue %i\n",
  190. card->qdio.default_out_queue);
  191. }
  192. }
  193. static ssize_t
  194. qeth_dev_prioqing_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  195. {
  196. struct qeth_card *card = dev->driver_data;
  197. char *tmp;
  198. if (!card)
  199. return -EINVAL;
  200. if ((card->state != CARD_STATE_DOWN) &&
  201. (card->state != CARD_STATE_RECOVER))
  202. return -EPERM;
  203. /* check if 1920 devices are supported ,
  204. * if though we have to permit priority queueing
  205. */
  206. if (card->qdio.no_out_queues == 1) {
  207. PRINT_WARN("Priority queueing disabled due "
  208. "to hardware limitations!\n");
  209. card->qdio.do_prio_queueing = QETH_PRIOQ_DEFAULT;
  210. return -EPERM;
  211. }
  212. tmp = strsep((char **) &buf, "\n");
  213. if (!strcmp(tmp, "prio_queueing_prec"))
  214. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_PREC;
  215. else if (!strcmp(tmp, "prio_queueing_tos"))
  216. card->qdio.do_prio_queueing = QETH_PRIO_Q_ING_TOS;
  217. else if (!strcmp(tmp, "no_prio_queueing:0")) {
  218. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  219. card->qdio.default_out_queue = 0;
  220. } else if (!strcmp(tmp, "no_prio_queueing:1")) {
  221. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  222. card->qdio.default_out_queue = 1;
  223. } else if (!strcmp(tmp, "no_prio_queueing:2")) {
  224. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  225. card->qdio.default_out_queue = 2;
  226. } else if (!strcmp(tmp, "no_prio_queueing:3")) {
  227. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  228. card->qdio.default_out_queue = 3;
  229. } else if (!strcmp(tmp, "no_prio_queueing")) {
  230. card->qdio.do_prio_queueing = QETH_NO_PRIO_QUEUEING;
  231. card->qdio.default_out_queue = QETH_DEFAULT_QUEUE;
  232. } else {
  233. PRINT_WARN("Unknown queueing type '%s'\n", tmp);
  234. return -EINVAL;
  235. }
  236. return count;
  237. }
  238. static DEVICE_ATTR(priority_queueing, 0644, qeth_dev_prioqing_show,
  239. qeth_dev_prioqing_store);
  240. static ssize_t
  241. qeth_dev_bufcnt_show(struct device *dev, struct device_attribute *attr, char *buf)
  242. {
  243. struct qeth_card *card = dev->driver_data;
  244. if (!card)
  245. return -EINVAL;
  246. return sprintf(buf, "%i\n", card->qdio.in_buf_pool.buf_count);
  247. }
  248. static ssize_t
  249. qeth_dev_bufcnt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  250. {
  251. struct qeth_card *card = dev->driver_data;
  252. char *tmp;
  253. int cnt, old_cnt;
  254. int rc;
  255. if (!card)
  256. return -EINVAL;
  257. if ((card->state != CARD_STATE_DOWN) &&
  258. (card->state != CARD_STATE_RECOVER))
  259. return -EPERM;
  260. old_cnt = card->qdio.in_buf_pool.buf_count;
  261. cnt = simple_strtoul(buf, &tmp, 10);
  262. cnt = (cnt < QETH_IN_BUF_COUNT_MIN) ? QETH_IN_BUF_COUNT_MIN :
  263. ((cnt > QETH_IN_BUF_COUNT_MAX) ? QETH_IN_BUF_COUNT_MAX : cnt);
  264. if (old_cnt != cnt) {
  265. if ((rc = qeth_realloc_buffer_pool(card, cnt)))
  266. PRINT_WARN("Error (%d) while setting "
  267. "buffer count.\n", rc);
  268. }
  269. return count;
  270. }
  271. static DEVICE_ATTR(buffer_count, 0644, qeth_dev_bufcnt_show,
  272. qeth_dev_bufcnt_store);
  273. static ssize_t
  274. qeth_dev_route_show(struct qeth_card *card, struct qeth_routing_info *route,
  275. char *buf)
  276. {
  277. switch (route->type) {
  278. case PRIMARY_ROUTER:
  279. return sprintf(buf, "%s\n", "primary router");
  280. case SECONDARY_ROUTER:
  281. return sprintf(buf, "%s\n", "secondary router");
  282. case MULTICAST_ROUTER:
  283. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  284. return sprintf(buf, "%s\n", "multicast router+");
  285. else
  286. return sprintf(buf, "%s\n", "multicast router");
  287. case PRIMARY_CONNECTOR:
  288. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  289. return sprintf(buf, "%s\n", "primary connector+");
  290. else
  291. return sprintf(buf, "%s\n", "primary connector");
  292. case SECONDARY_CONNECTOR:
  293. if (card->info.broadcast_capable == QETH_BROADCAST_WITHOUT_ECHO)
  294. return sprintf(buf, "%s\n", "secondary connector+");
  295. else
  296. return sprintf(buf, "%s\n", "secondary connector");
  297. default:
  298. return sprintf(buf, "%s\n", "no");
  299. }
  300. }
  301. static ssize_t
  302. qeth_dev_route4_show(struct device *dev, struct device_attribute *attr, char *buf)
  303. {
  304. struct qeth_card *card = dev->driver_data;
  305. if (!card)
  306. return -EINVAL;
  307. return qeth_dev_route_show(card, &card->options.route4, buf);
  308. }
  309. static ssize_t
  310. qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
  311. enum qeth_prot_versions prot, const char *buf, size_t count)
  312. {
  313. enum qeth_routing_types old_route_type = route->type;
  314. char *tmp;
  315. int rc;
  316. tmp = strsep((char **) &buf, "\n");
  317. if (!strcmp(tmp, "no_router")){
  318. route->type = NO_ROUTER;
  319. } else if (!strcmp(tmp, "primary_connector")) {
  320. route->type = PRIMARY_CONNECTOR;
  321. } else if (!strcmp(tmp, "secondary_connector")) {
  322. route->type = SECONDARY_CONNECTOR;
  323. } else if (!strcmp(tmp, "primary_router")) {
  324. route->type = PRIMARY_ROUTER;
  325. } else if (!strcmp(tmp, "secondary_router")) {
  326. route->type = SECONDARY_ROUTER;
  327. } else if (!strcmp(tmp, "multicast_router")) {
  328. route->type = MULTICAST_ROUTER;
  329. } else {
  330. PRINT_WARN("Invalid routing type '%s'.\n", tmp);
  331. return -EINVAL;
  332. }
  333. if (((card->state == CARD_STATE_SOFTSETUP) ||
  334. (card->state == CARD_STATE_UP)) &&
  335. (old_route_type != route->type)){
  336. if (prot == QETH_PROT_IPV4)
  337. rc = qeth_setrouting_v4(card);
  338. else if (prot == QETH_PROT_IPV6)
  339. rc = qeth_setrouting_v6(card);
  340. }
  341. return count;
  342. }
  343. static ssize_t
  344. qeth_dev_route4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  345. {
  346. struct qeth_card *card = dev->driver_data;
  347. if (!card)
  348. return -EINVAL;
  349. return qeth_dev_route_store(card, &card->options.route4,
  350. QETH_PROT_IPV4, buf, count);
  351. }
  352. static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
  353. #ifdef CONFIG_QETH_IPV6
  354. static ssize_t
  355. qeth_dev_route6_show(struct device *dev, struct device_attribute *attr, char *buf)
  356. {
  357. struct qeth_card *card = dev->driver_data;
  358. if (!card)
  359. return -EINVAL;
  360. if (!qeth_is_supported(card, IPA_IPV6))
  361. return sprintf(buf, "%s\n", "n/a");
  362. return qeth_dev_route_show(card, &card->options.route6, buf);
  363. }
  364. static ssize_t
  365. qeth_dev_route6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  366. {
  367. struct qeth_card *card = dev->driver_data;
  368. if (!card)
  369. return -EINVAL;
  370. if (!qeth_is_supported(card, IPA_IPV6)){
  371. PRINT_WARN("IPv6 not supported for interface %s.\n"
  372. "Routing status no changed.\n",
  373. QETH_CARD_IFNAME(card));
  374. return -ENOTSUPP;
  375. }
  376. return qeth_dev_route_store(card, &card->options.route6,
  377. QETH_PROT_IPV6, buf, count);
  378. }
  379. static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
  380. #endif
  381. static ssize_t
  382. qeth_dev_add_hhlen_show(struct device *dev, struct device_attribute *attr, char *buf)
  383. {
  384. struct qeth_card *card = dev->driver_data;
  385. if (!card)
  386. return -EINVAL;
  387. return sprintf(buf, "%i\n", card->options.add_hhlen);
  388. }
  389. static ssize_t
  390. qeth_dev_add_hhlen_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  391. {
  392. struct qeth_card *card = dev->driver_data;
  393. char *tmp;
  394. int i;
  395. if (!card)
  396. return -EINVAL;
  397. if ((card->state != CARD_STATE_DOWN) &&
  398. (card->state != CARD_STATE_RECOVER))
  399. return -EPERM;
  400. i = simple_strtoul(buf, &tmp, 10);
  401. if ((i < 0) || (i > MAX_ADD_HHLEN)) {
  402. PRINT_WARN("add_hhlen out of range\n");
  403. return -EINVAL;
  404. }
  405. card->options.add_hhlen = i;
  406. return count;
  407. }
  408. static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
  409. qeth_dev_add_hhlen_store);
  410. static ssize_t
  411. qeth_dev_fake_ll_show(struct device *dev, struct device_attribute *attr, char *buf)
  412. {
  413. struct qeth_card *card = dev->driver_data;
  414. if (!card)
  415. return -EINVAL;
  416. return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
  417. }
  418. static ssize_t
  419. qeth_dev_fake_ll_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  420. {
  421. struct qeth_card *card = dev->driver_data;
  422. char *tmp;
  423. int i;
  424. if (!card)
  425. return -EINVAL;
  426. if ((card->state != CARD_STATE_DOWN) &&
  427. (card->state != CARD_STATE_RECOVER))
  428. return -EPERM;
  429. i = simple_strtoul(buf, &tmp, 16);
  430. if ((i != 0) && (i != 1)) {
  431. PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
  432. return -EINVAL;
  433. }
  434. card->options.fake_ll = i;
  435. return count;
  436. }
  437. static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
  438. qeth_dev_fake_ll_store);
  439. static ssize_t
  440. qeth_dev_fake_broadcast_show(struct device *dev, struct device_attribute *attr, char *buf)
  441. {
  442. struct qeth_card *card = dev->driver_data;
  443. if (!card)
  444. return -EINVAL;
  445. return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
  446. }
  447. static ssize_t
  448. qeth_dev_fake_broadcast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  449. {
  450. struct qeth_card *card = dev->driver_data;
  451. char *tmp;
  452. int i;
  453. if (!card)
  454. return -EINVAL;
  455. if ((card->state != CARD_STATE_DOWN) &&
  456. (card->state != CARD_STATE_RECOVER))
  457. return -EPERM;
  458. i = simple_strtoul(buf, &tmp, 16);
  459. if ((i == 0) || (i == 1))
  460. card->options.fake_broadcast = i;
  461. else {
  462. PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
  463. return -EINVAL;
  464. }
  465. return count;
  466. }
  467. static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
  468. qeth_dev_fake_broadcast_store);
  469. static ssize_t
  470. qeth_dev_recover_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  471. {
  472. struct qeth_card *card = dev->driver_data;
  473. char *tmp;
  474. int i;
  475. if (!card)
  476. return -EINVAL;
  477. if (card->state != CARD_STATE_UP)
  478. return -EPERM;
  479. i = simple_strtoul(buf, &tmp, 16);
  480. if (i == 1)
  481. qeth_schedule_recovery(card);
  482. return count;
  483. }
  484. static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
  485. static ssize_t
  486. qeth_dev_broadcast_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  487. {
  488. struct qeth_card *card = dev->driver_data;
  489. if (!card)
  490. return -EINVAL;
  491. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  492. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  493. return sprintf(buf, "n/a\n");
  494. return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
  495. QETH_TR_BROADCAST_ALLRINGS)?
  496. "all rings":"local");
  497. }
  498. static ssize_t
  499. qeth_dev_broadcast_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  500. {
  501. struct qeth_card *card = dev->driver_data;
  502. char *tmp;
  503. if (!card)
  504. return -EINVAL;
  505. if ((card->state != CARD_STATE_DOWN) &&
  506. (card->state != CARD_STATE_RECOVER))
  507. return -EPERM;
  508. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  509. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  510. PRINT_WARN("Device is not a tokenring device!\n");
  511. return -EINVAL;
  512. }
  513. tmp = strsep((char **) &buf, "\n");
  514. if (!strcmp(tmp, "local")){
  515. card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
  516. return count;
  517. } else if (!strcmp(tmp, "all_rings")) {
  518. card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
  519. return count;
  520. } else {
  521. PRINT_WARN("broadcast_mode: invalid mode %s!\n",
  522. tmp);
  523. return -EINVAL;
  524. }
  525. return count;
  526. }
  527. static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
  528. qeth_dev_broadcast_mode_store);
  529. static ssize_t
  530. qeth_dev_canonical_macaddr_show(struct device *dev, struct device_attribute *attr, char *buf)
  531. {
  532. struct qeth_card *card = dev->driver_data;
  533. if (!card)
  534. return -EINVAL;
  535. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  536. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  537. return sprintf(buf, "n/a\n");
  538. return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
  539. QETH_TR_MACADDR_CANONICAL)? 1:0);
  540. }
  541. static ssize_t
  542. qeth_dev_canonical_macaddr_store(struct device *dev, struct device_attribute *attr, const char *buf,
  543. size_t count)
  544. {
  545. struct qeth_card *card = dev->driver_data;
  546. char *tmp;
  547. int i;
  548. if (!card)
  549. return -EINVAL;
  550. if ((card->state != CARD_STATE_DOWN) &&
  551. (card->state != CARD_STATE_RECOVER))
  552. return -EPERM;
  553. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  554. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  555. PRINT_WARN("Device is not a tokenring device!\n");
  556. return -EINVAL;
  557. }
  558. i = simple_strtoul(buf, &tmp, 16);
  559. if ((i == 0) || (i == 1))
  560. card->options.macaddr_mode = i?
  561. QETH_TR_MACADDR_CANONICAL :
  562. QETH_TR_MACADDR_NONCANONICAL;
  563. else {
  564. PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
  565. return -EINVAL;
  566. }
  567. return count;
  568. }
  569. static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
  570. qeth_dev_canonical_macaddr_store);
  571. static ssize_t
  572. qeth_dev_layer2_show(struct device *dev, struct device_attribute *attr, char *buf)
  573. {
  574. struct qeth_card *card = dev->driver_data;
  575. if (!card)
  576. return -EINVAL;
  577. return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
  578. }
  579. static ssize_t
  580. qeth_dev_layer2_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  581. {
  582. struct qeth_card *card = dev->driver_data;
  583. char *tmp;
  584. int i;
  585. if (!card)
  586. return -EINVAL;
  587. if (card->info.type == QETH_CARD_TYPE_IQD) {
  588. PRINT_WARN("Layer2 on Hipersockets is not supported! \n");
  589. return -EPERM;
  590. }
  591. if (((card->state != CARD_STATE_DOWN) &&
  592. (card->state != CARD_STATE_RECOVER)))
  593. return -EPERM;
  594. i = simple_strtoul(buf, &tmp, 16);
  595. if ((i == 0) || (i == 1))
  596. card->options.layer2 = i;
  597. else {
  598. PRINT_WARN("layer2: write 0 or 1 to this file!\n");
  599. return -EINVAL;
  600. }
  601. return count;
  602. }
  603. static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
  604. qeth_dev_layer2_store);
  605. static ssize_t
  606. qeth_dev_performance_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
  607. {
  608. struct qeth_card *card = dev->driver_data;
  609. if (!card)
  610. return -EINVAL;
  611. return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
  612. }
  613. static ssize_t
  614. qeth_dev_performance_stats_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  615. {
  616. struct qeth_card *card = dev->driver_data;
  617. char *tmp;
  618. int i;
  619. if (!card)
  620. return -EINVAL;
  621. i = simple_strtoul(buf, &tmp, 16);
  622. if ((i == 0) || (i == 1)) {
  623. if (i == card->options.performance_stats)
  624. return count;
  625. card->options.performance_stats = i;
  626. if (i == 0)
  627. memset(&card->perf_stats, 0,
  628. sizeof(struct qeth_perf_stats));
  629. card->perf_stats.initial_rx_packets = card->stats.rx_packets;
  630. card->perf_stats.initial_tx_packets = card->stats.tx_packets;
  631. } else {
  632. PRINT_WARN("performance_stats: write 0 or 1 to this file!\n");
  633. return -EINVAL;
  634. }
  635. return count;
  636. }
  637. static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
  638. qeth_dev_performance_stats_store);
  639. static ssize_t
  640. qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
  641. {
  642. struct qeth_card *card = dev->driver_data;
  643. if (!card)
  644. return -EINVAL;
  645. switch (card->options.large_send) {
  646. case QETH_LARGE_SEND_NO:
  647. return sprintf(buf, "%s\n", "no");
  648. case QETH_LARGE_SEND_EDDP:
  649. return sprintf(buf, "%s\n", "EDDP");
  650. case QETH_LARGE_SEND_TSO:
  651. return sprintf(buf, "%s\n", "TSO");
  652. default:
  653. return sprintf(buf, "%s\n", "N/A");
  654. }
  655. }
  656. static ssize_t
  657. qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  658. {
  659. struct qeth_card *card = dev->driver_data;
  660. enum qeth_large_send_types type;
  661. int rc = 0;
  662. char *tmp;
  663. if (!card)
  664. return -EINVAL;
  665. tmp = strsep((char **) &buf, "\n");
  666. if (!strcmp(tmp, "no")){
  667. type = QETH_LARGE_SEND_NO;
  668. } else if (!strcmp(tmp, "EDDP")) {
  669. type = QETH_LARGE_SEND_EDDP;
  670. } else if (!strcmp(tmp, "TSO")) {
  671. type = QETH_LARGE_SEND_TSO;
  672. } else {
  673. PRINT_WARN("large_send: invalid mode %s!\n", tmp);
  674. return -EINVAL;
  675. }
  676. if (card->options.large_send == type)
  677. return count;
  678. if ((rc = qeth_set_large_send(card, type)))
  679. return rc;
  680. return count;
  681. }
  682. static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
  683. qeth_dev_large_send_store);
  684. static ssize_t
  685. qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
  686. {
  687. if (!card)
  688. return -EINVAL;
  689. return sprintf(buf, "%i\n", value);
  690. }
  691. static ssize_t
  692. qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
  693. int *value, int max_value)
  694. {
  695. char *tmp;
  696. int i;
  697. if (!card)
  698. return -EINVAL;
  699. if ((card->state != CARD_STATE_DOWN) &&
  700. (card->state != CARD_STATE_RECOVER))
  701. return -EPERM;
  702. i = simple_strtoul(buf, &tmp, 10);
  703. if (i <= max_value) {
  704. *value = i;
  705. } else {
  706. PRINT_WARN("blkt total time: write values between"
  707. " 0 and %d to this file!\n", max_value);
  708. return -EINVAL;
  709. }
  710. return count;
  711. }
  712. static ssize_t
  713. qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
  714. {
  715. struct qeth_card *card = dev->driver_data;
  716. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  717. }
  718. static ssize_t
  719. qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  720. {
  721. struct qeth_card *card = dev->driver_data;
  722. return qeth_dev_blkt_store(card, buf, count,
  723. &card->info.blkt.time_total,1000);
  724. }
  725. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  726. qeth_dev_blkt_total_store);
  727. static ssize_t
  728. qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
  729. {
  730. struct qeth_card *card = dev->driver_data;
  731. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  732. }
  733. static ssize_t
  734. qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  735. {
  736. struct qeth_card *card = dev->driver_data;
  737. return qeth_dev_blkt_store(card, buf, count,
  738. &card->info.blkt.inter_packet,100);
  739. }
  740. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  741. qeth_dev_blkt_inter_store);
  742. static ssize_t
  743. qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
  744. {
  745. struct qeth_card *card = dev->driver_data;
  746. return qeth_dev_blkt_show(buf, card,
  747. card->info.blkt.inter_packet_jumbo);
  748. }
  749. static ssize_t
  750. qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  751. {
  752. struct qeth_card *card = dev->driver_data;
  753. return qeth_dev_blkt_store(card, buf, count,
  754. &card->info.blkt.inter_packet_jumbo,100);
  755. }
  756. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  757. qeth_dev_blkt_inter_jumbo_store);
  758. static struct device_attribute * qeth_blkt_device_attrs[] = {
  759. &dev_attr_total,
  760. &dev_attr_inter,
  761. &dev_attr_inter_jumbo,
  762. NULL,
  763. };
  764. static struct attribute_group qeth_device_blkt_group = {
  765. .name = "blkt",
  766. .attrs = (struct attribute **)qeth_blkt_device_attrs,
  767. };
  768. static struct device_attribute * qeth_device_attrs[] = {
  769. &dev_attr_state,
  770. &dev_attr_chpid,
  771. &dev_attr_if_name,
  772. &dev_attr_card_type,
  773. &dev_attr_portno,
  774. &dev_attr_portname,
  775. &dev_attr_checksumming,
  776. &dev_attr_priority_queueing,
  777. &dev_attr_buffer_count,
  778. &dev_attr_route4,
  779. #ifdef CONFIG_QETH_IPV6
  780. &dev_attr_route6,
  781. #endif
  782. &dev_attr_add_hhlen,
  783. &dev_attr_fake_ll,
  784. &dev_attr_fake_broadcast,
  785. &dev_attr_recover,
  786. &dev_attr_broadcast_mode,
  787. &dev_attr_canonical_macaddr,
  788. &dev_attr_layer2,
  789. &dev_attr_large_send,
  790. &dev_attr_performance_stats,
  791. NULL,
  792. };
  793. static struct attribute_group qeth_device_attr_group = {
  794. .attrs = (struct attribute **)qeth_device_attrs,
  795. };
  796. static struct device_attribute * qeth_osn_device_attrs[] = {
  797. &dev_attr_state,
  798. &dev_attr_chpid,
  799. &dev_attr_if_name,
  800. &dev_attr_card_type,
  801. &dev_attr_buffer_count,
  802. &dev_attr_recover,
  803. NULL,
  804. };
  805. static struct attribute_group qeth_osn_device_attr_group = {
  806. .attrs = (struct attribute **)qeth_osn_device_attrs,
  807. };
  808. #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
  809. struct device_attribute dev_attr_##_id = { \
  810. .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
  811. .show = _show, \
  812. .store = _store, \
  813. };
  814. static int
  815. qeth_check_layer2(struct qeth_card *card)
  816. {
  817. if (card->options.layer2)
  818. return -EPERM;
  819. return 0;
  820. }
  821. static ssize_t
  822. qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
  823. {
  824. struct qeth_card *card = dev->driver_data;
  825. if (!card)
  826. return -EINVAL;
  827. if (qeth_check_layer2(card))
  828. return -EPERM;
  829. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  830. }
  831. static ssize_t
  832. qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  833. {
  834. struct qeth_card *card = dev->driver_data;
  835. char *tmp;
  836. if (!card)
  837. return -EINVAL;
  838. if ((card->state != CARD_STATE_DOWN) &&
  839. (card->state != CARD_STATE_RECOVER))
  840. return -EPERM;
  841. if (qeth_check_layer2(card))
  842. return -EPERM;
  843. tmp = strsep((char **) &buf, "\n");
  844. if (!strcmp(tmp, "toggle")){
  845. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  846. } else if (!strcmp(tmp, "1")){
  847. card->ipato.enabled = 1;
  848. } else if (!strcmp(tmp, "0")){
  849. card->ipato.enabled = 0;
  850. } else {
  851. PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
  852. "this file\n");
  853. return -EINVAL;
  854. }
  855. return count;
  856. }
  857. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  858. qeth_dev_ipato_enable_show,
  859. qeth_dev_ipato_enable_store);
  860. static ssize_t
  861. qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
  862. {
  863. struct qeth_card *card = dev->driver_data;
  864. if (!card)
  865. return -EINVAL;
  866. if (qeth_check_layer2(card))
  867. return -EPERM;
  868. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  869. }
  870. static ssize_t
  871. qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  872. {
  873. struct qeth_card *card = dev->driver_data;
  874. char *tmp;
  875. if (!card)
  876. return -EINVAL;
  877. if (qeth_check_layer2(card))
  878. return -EPERM;
  879. tmp = strsep((char **) &buf, "\n");
  880. if (!strcmp(tmp, "toggle")){
  881. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  882. } else if (!strcmp(tmp, "1")){
  883. card->ipato.invert4 = 1;
  884. } else if (!strcmp(tmp, "0")){
  885. card->ipato.invert4 = 0;
  886. } else {
  887. PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
  888. "this file\n");
  889. return -EINVAL;
  890. }
  891. return count;
  892. }
  893. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  894. qeth_dev_ipato_invert4_show,
  895. qeth_dev_ipato_invert4_store);
  896. static ssize_t
  897. qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
  898. enum qeth_prot_versions proto)
  899. {
  900. struct qeth_ipato_entry *ipatoe;
  901. unsigned long flags;
  902. char addr_str[40];
  903. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  904. int i = 0;
  905. if (qeth_check_layer2(card))
  906. return -EPERM;
  907. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  908. /* add strlen for "/<mask>\n" */
  909. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  910. spin_lock_irqsave(&card->ip_lock, flags);
  911. list_for_each_entry(ipatoe, &card->ipato.entries, entry){
  912. if (ipatoe->proto != proto)
  913. continue;
  914. /* String must not be longer than PAGE_SIZE. So we check if
  915. * string length gets near PAGE_SIZE. Then we can savely display
  916. * the next IPv6 address (worst case, compared to IPv4) */
  917. if ((PAGE_SIZE - i) <= entry_len)
  918. break;
  919. qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  920. i += snprintf(buf + i, PAGE_SIZE - i,
  921. "%s/%i\n", addr_str, ipatoe->mask_bits);
  922. }
  923. spin_unlock_irqrestore(&card->ip_lock, flags);
  924. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  925. return i;
  926. }
  927. static ssize_t
  928. qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  929. {
  930. struct qeth_card *card = dev->driver_data;
  931. if (!card)
  932. return -EINVAL;
  933. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  934. }
  935. static int
  936. qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
  937. u8 *addr, int *mask_bits)
  938. {
  939. const char *start, *end;
  940. char *tmp;
  941. char buffer[40] = {0, };
  942. start = buf;
  943. /* get address string */
  944. end = strchr(start, '/');
  945. if (!end || (end - start >= 40)){
  946. PRINT_WARN("Invalid format for ipato_addx/delx. "
  947. "Use <ip addr>/<mask bits>\n");
  948. return -EINVAL;
  949. }
  950. strncpy(buffer, start, end - start);
  951. if (qeth_string_to_ipaddr(buffer, proto, addr)){
  952. PRINT_WARN("Invalid IP address format!\n");
  953. return -EINVAL;
  954. }
  955. start = end + 1;
  956. *mask_bits = simple_strtoul(start, &tmp, 10);
  957. if (!strlen(start) ||
  958. (tmp == start) ||
  959. (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
  960. PRINT_WARN("Invalid mask bits for ipato_addx/delx !\n");
  961. return -EINVAL;
  962. }
  963. return 0;
  964. }
  965. static ssize_t
  966. qeth_dev_ipato_add_store(const char *buf, size_t count,
  967. struct qeth_card *card, enum qeth_prot_versions proto)
  968. {
  969. struct qeth_ipato_entry *ipatoe;
  970. u8 addr[16];
  971. int mask_bits;
  972. int rc;
  973. if (qeth_check_layer2(card))
  974. return -EPERM;
  975. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  976. return rc;
  977. if (!(ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
  978. PRINT_WARN("No memory to allocate ipato entry\n");
  979. return -ENOMEM;
  980. }
  981. ipatoe->proto = proto;
  982. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  983. ipatoe->mask_bits = mask_bits;
  984. if ((rc = qeth_add_ipato_entry(card, ipatoe))){
  985. kfree(ipatoe);
  986. return rc;
  987. }
  988. return count;
  989. }
  990. static ssize_t
  991. qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  992. {
  993. struct qeth_card *card = dev->driver_data;
  994. if (!card)
  995. return -EINVAL;
  996. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  997. }
  998. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  999. qeth_dev_ipato_add4_show,
  1000. qeth_dev_ipato_add4_store);
  1001. static ssize_t
  1002. qeth_dev_ipato_del_store(const char *buf, size_t count,
  1003. struct qeth_card *card, enum qeth_prot_versions proto)
  1004. {
  1005. u8 addr[16];
  1006. int mask_bits;
  1007. int rc;
  1008. if (qeth_check_layer2(card))
  1009. return -EPERM;
  1010. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  1011. return rc;
  1012. qeth_del_ipato_entry(card, proto, addr, mask_bits);
  1013. return count;
  1014. }
  1015. static ssize_t
  1016. qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1017. {
  1018. struct qeth_card *card = dev->driver_data;
  1019. if (!card)
  1020. return -EINVAL;
  1021. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  1022. }
  1023. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  1024. qeth_dev_ipato_del4_store);
  1025. #ifdef CONFIG_QETH_IPV6
  1026. static ssize_t
  1027. qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1028. {
  1029. struct qeth_card *card = dev->driver_data;
  1030. if (!card)
  1031. return -EINVAL;
  1032. if (qeth_check_layer2(card))
  1033. return -EPERM;
  1034. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  1035. }
  1036. static ssize_t
  1037. qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1038. {
  1039. struct qeth_card *card = dev->driver_data;
  1040. char *tmp;
  1041. if (!card)
  1042. return -EINVAL;
  1043. if (qeth_check_layer2(card))
  1044. return -EPERM;
  1045. tmp = strsep((char **) &buf, "\n");
  1046. if (!strcmp(tmp, "toggle")){
  1047. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  1048. } else if (!strcmp(tmp, "1")){
  1049. card->ipato.invert6 = 1;
  1050. } else if (!strcmp(tmp, "0")){
  1051. card->ipato.invert6 = 0;
  1052. } else {
  1053. PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
  1054. "this file\n");
  1055. return -EINVAL;
  1056. }
  1057. return count;
  1058. }
  1059. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  1060. qeth_dev_ipato_invert6_show,
  1061. qeth_dev_ipato_invert6_store);
  1062. static ssize_t
  1063. qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1064. {
  1065. struct qeth_card *card = dev->driver_data;
  1066. if (!card)
  1067. return -EINVAL;
  1068. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  1069. }
  1070. static ssize_t
  1071. qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1072. {
  1073. struct qeth_card *card = dev->driver_data;
  1074. if (!card)
  1075. return -EINVAL;
  1076. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  1077. }
  1078. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  1079. qeth_dev_ipato_add6_show,
  1080. qeth_dev_ipato_add6_store);
  1081. static ssize_t
  1082. qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1083. {
  1084. struct qeth_card *card = dev->driver_data;
  1085. if (!card)
  1086. return -EINVAL;
  1087. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  1088. }
  1089. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  1090. qeth_dev_ipato_del6_store);
  1091. #endif /* CONFIG_QETH_IPV6 */
  1092. static struct device_attribute * qeth_ipato_device_attrs[] = {
  1093. &dev_attr_ipato_enable,
  1094. &dev_attr_ipato_invert4,
  1095. &dev_attr_ipato_add4,
  1096. &dev_attr_ipato_del4,
  1097. #ifdef CONFIG_QETH_IPV6
  1098. &dev_attr_ipato_invert6,
  1099. &dev_attr_ipato_add6,
  1100. &dev_attr_ipato_del6,
  1101. #endif
  1102. NULL,
  1103. };
  1104. static struct attribute_group qeth_device_ipato_group = {
  1105. .name = "ipa_takeover",
  1106. .attrs = (struct attribute **)qeth_ipato_device_attrs,
  1107. };
  1108. static ssize_t
  1109. qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
  1110. enum qeth_prot_versions proto)
  1111. {
  1112. struct qeth_ipaddr *ipaddr;
  1113. char addr_str[40];
  1114. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1115. unsigned long flags;
  1116. int i = 0;
  1117. if (qeth_check_layer2(card))
  1118. return -EPERM;
  1119. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1120. entry_len += 2; /* \n + terminator */
  1121. spin_lock_irqsave(&card->ip_lock, flags);
  1122. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1123. if (ipaddr->proto != proto)
  1124. continue;
  1125. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  1126. continue;
  1127. /* String must not be longer than PAGE_SIZE. So we check if
  1128. * string length gets near PAGE_SIZE. Then we can savely display
  1129. * the next IPv6 address (worst case, compared to IPv4) */
  1130. if ((PAGE_SIZE - i) <= entry_len)
  1131. break;
  1132. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1133. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1134. }
  1135. spin_unlock_irqrestore(&card->ip_lock, flags);
  1136. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1137. return i;
  1138. }
  1139. static ssize_t
  1140. qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1141. {
  1142. struct qeth_card *card = dev->driver_data;
  1143. if (!card)
  1144. return -EINVAL;
  1145. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  1146. }
  1147. static int
  1148. qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
  1149. u8 *addr)
  1150. {
  1151. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1152. PRINT_WARN("Invalid IP address format!\n");
  1153. return -EINVAL;
  1154. }
  1155. return 0;
  1156. }
  1157. static ssize_t
  1158. qeth_dev_vipa_add_store(const char *buf, size_t count,
  1159. struct qeth_card *card, enum qeth_prot_versions proto)
  1160. {
  1161. u8 addr[16] = {0, };
  1162. int rc;
  1163. if (qeth_check_layer2(card))
  1164. return -EPERM;
  1165. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1166. return rc;
  1167. if ((rc = qeth_add_vipa(card, proto, addr)))
  1168. return rc;
  1169. return count;
  1170. }
  1171. static ssize_t
  1172. qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1173. {
  1174. struct qeth_card *card = dev->driver_data;
  1175. if (!card)
  1176. return -EINVAL;
  1177. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  1178. }
  1179. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  1180. qeth_dev_vipa_add4_show,
  1181. qeth_dev_vipa_add4_store);
  1182. static ssize_t
  1183. qeth_dev_vipa_del_store(const char *buf, size_t count,
  1184. struct qeth_card *card, enum qeth_prot_versions proto)
  1185. {
  1186. u8 addr[16];
  1187. int rc;
  1188. if (qeth_check_layer2(card))
  1189. return -EPERM;
  1190. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1191. return rc;
  1192. qeth_del_vipa(card, proto, addr);
  1193. return count;
  1194. }
  1195. static ssize_t
  1196. qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1197. {
  1198. struct qeth_card *card = dev->driver_data;
  1199. if (!card)
  1200. return -EINVAL;
  1201. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  1202. }
  1203. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  1204. qeth_dev_vipa_del4_store);
  1205. #ifdef CONFIG_QETH_IPV6
  1206. static ssize_t
  1207. qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1208. {
  1209. struct qeth_card *card = dev->driver_data;
  1210. if (!card)
  1211. return -EINVAL;
  1212. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  1213. }
  1214. static ssize_t
  1215. qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1216. {
  1217. struct qeth_card *card = dev->driver_data;
  1218. if (!card)
  1219. return -EINVAL;
  1220. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  1221. }
  1222. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  1223. qeth_dev_vipa_add6_show,
  1224. qeth_dev_vipa_add6_store);
  1225. static ssize_t
  1226. qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1227. {
  1228. struct qeth_card *card = dev->driver_data;
  1229. if (!card)
  1230. return -EINVAL;
  1231. if (qeth_check_layer2(card))
  1232. return -EPERM;
  1233. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  1234. }
  1235. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  1236. qeth_dev_vipa_del6_store);
  1237. #endif /* CONFIG_QETH_IPV6 */
  1238. static struct device_attribute * qeth_vipa_device_attrs[] = {
  1239. &dev_attr_vipa_add4,
  1240. &dev_attr_vipa_del4,
  1241. #ifdef CONFIG_QETH_IPV6
  1242. &dev_attr_vipa_add6,
  1243. &dev_attr_vipa_del6,
  1244. #endif
  1245. NULL,
  1246. };
  1247. static struct attribute_group qeth_device_vipa_group = {
  1248. .name = "vipa",
  1249. .attrs = (struct attribute **)qeth_vipa_device_attrs,
  1250. };
  1251. static ssize_t
  1252. qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
  1253. enum qeth_prot_versions proto)
  1254. {
  1255. struct qeth_ipaddr *ipaddr;
  1256. char addr_str[40];
  1257. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1258. unsigned long flags;
  1259. int i = 0;
  1260. if (qeth_check_layer2(card))
  1261. return -EPERM;
  1262. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1263. entry_len += 2; /* \n + terminator */
  1264. spin_lock_irqsave(&card->ip_lock, flags);
  1265. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1266. if (ipaddr->proto != proto)
  1267. continue;
  1268. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  1269. continue;
  1270. /* String must not be longer than PAGE_SIZE. So we check if
  1271. * string length gets near PAGE_SIZE. Then we can savely display
  1272. * the next IPv6 address (worst case, compared to IPv4) */
  1273. if ((PAGE_SIZE - i) <= entry_len)
  1274. break;
  1275. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1276. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1277. }
  1278. spin_unlock_irqrestore(&card->ip_lock, flags);
  1279. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1280. return i;
  1281. }
  1282. static ssize_t
  1283. qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1284. {
  1285. struct qeth_card *card = dev->driver_data;
  1286. if (!card)
  1287. return -EINVAL;
  1288. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  1289. }
  1290. static int
  1291. qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
  1292. u8 *addr)
  1293. {
  1294. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1295. PRINT_WARN("Invalid IP address format!\n");
  1296. return -EINVAL;
  1297. }
  1298. return 0;
  1299. }
  1300. static ssize_t
  1301. qeth_dev_rxip_add_store(const char *buf, size_t count,
  1302. struct qeth_card *card, enum qeth_prot_versions proto)
  1303. {
  1304. u8 addr[16] = {0, };
  1305. int rc;
  1306. if (qeth_check_layer2(card))
  1307. return -EPERM;
  1308. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1309. return rc;
  1310. if ((rc = qeth_add_rxip(card, proto, addr)))
  1311. return rc;
  1312. return count;
  1313. }
  1314. static ssize_t
  1315. qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1316. {
  1317. struct qeth_card *card = dev->driver_data;
  1318. if (!card)
  1319. return -EINVAL;
  1320. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  1321. }
  1322. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  1323. qeth_dev_rxip_add4_show,
  1324. qeth_dev_rxip_add4_store);
  1325. static ssize_t
  1326. qeth_dev_rxip_del_store(const char *buf, size_t count,
  1327. struct qeth_card *card, enum qeth_prot_versions proto)
  1328. {
  1329. u8 addr[16];
  1330. int rc;
  1331. if (qeth_check_layer2(card))
  1332. return -EPERM;
  1333. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1334. return rc;
  1335. qeth_del_rxip(card, proto, addr);
  1336. return count;
  1337. }
  1338. static ssize_t
  1339. qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1340. {
  1341. struct qeth_card *card = dev->driver_data;
  1342. if (!card)
  1343. return -EINVAL;
  1344. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  1345. }
  1346. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  1347. qeth_dev_rxip_del4_store);
  1348. #ifdef CONFIG_QETH_IPV6
  1349. static ssize_t
  1350. qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1351. {
  1352. struct qeth_card *card = dev->driver_data;
  1353. if (!card)
  1354. return -EINVAL;
  1355. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  1356. }
  1357. static ssize_t
  1358. qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1359. {
  1360. struct qeth_card *card = dev->driver_data;
  1361. if (!card)
  1362. return -EINVAL;
  1363. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  1364. }
  1365. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  1366. qeth_dev_rxip_add6_show,
  1367. qeth_dev_rxip_add6_store);
  1368. static ssize_t
  1369. qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1370. {
  1371. struct qeth_card *card = dev->driver_data;
  1372. if (!card)
  1373. return -EINVAL;
  1374. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  1375. }
  1376. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  1377. qeth_dev_rxip_del6_store);
  1378. #endif /* CONFIG_QETH_IPV6 */
  1379. static struct device_attribute * qeth_rxip_device_attrs[] = {
  1380. &dev_attr_rxip_add4,
  1381. &dev_attr_rxip_del4,
  1382. #ifdef CONFIG_QETH_IPV6
  1383. &dev_attr_rxip_add6,
  1384. &dev_attr_rxip_del6,
  1385. #endif
  1386. NULL,
  1387. };
  1388. static struct attribute_group qeth_device_rxip_group = {
  1389. .name = "rxip",
  1390. .attrs = (struct attribute **)qeth_rxip_device_attrs,
  1391. };
  1392. int
  1393. qeth_create_device_attributes(struct device *dev)
  1394. {
  1395. int ret;
  1396. struct qeth_card *card = dev->driver_data;
  1397. if (card->info.type == QETH_CARD_TYPE_OSN)
  1398. return sysfs_create_group(&dev->kobj,
  1399. &qeth_osn_device_attr_group);
  1400. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
  1401. return ret;
  1402. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
  1403. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1404. return ret;
  1405. }
  1406. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
  1407. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1408. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1409. return ret;
  1410. }
  1411. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
  1412. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1413. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1414. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1415. return ret;
  1416. }
  1417. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group))){
  1418. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1419. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1420. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1421. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1422. return ret;
  1423. }
  1424. return 0;
  1425. }
  1426. void
  1427. qeth_remove_device_attributes(struct device *dev)
  1428. {
  1429. struct qeth_card *card = dev->driver_data;
  1430. if (card->info.type == QETH_CARD_TYPE_OSN)
  1431. return sysfs_remove_group(&dev->kobj,
  1432. &qeth_osn_device_attr_group);
  1433. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1434. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1435. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1436. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1437. sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
  1438. }
  1439. /**********************/
  1440. /* DRIVER ATTRIBUTES */
  1441. /**********************/
  1442. static ssize_t
  1443. qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
  1444. size_t count)
  1445. {
  1446. const char *start, *end;
  1447. char bus_ids[3][BUS_ID_SIZE], *argv[3];
  1448. int i;
  1449. int err;
  1450. start = buf;
  1451. for (i = 0; i < 3; i++) {
  1452. static const char delim[] = { ',', ',', '\n' };
  1453. int len;
  1454. if (!(end = strchr(start, delim[i])))
  1455. return -EINVAL;
  1456. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
  1457. strncpy(bus_ids[i], start, len);
  1458. bus_ids[i][len] = '\0';
  1459. start = end + 1;
  1460. argv[i] = bus_ids[i];
  1461. }
  1462. err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
  1463. &qeth_ccw_driver, 3, argv);
  1464. if (err)
  1465. return err;
  1466. else
  1467. return count;
  1468. }
  1469. static DRIVER_ATTR(group, 0200, NULL, qeth_driver_group_store);
  1470. static ssize_t
  1471. qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
  1472. size_t count)
  1473. {
  1474. int rc;
  1475. int signum;
  1476. char *tmp, *tmp2;
  1477. tmp = strsep((char **) &buf, "\n");
  1478. if (!strncmp(tmp, "unregister", 10)){
  1479. if ((rc = qeth_notifier_unregister(current)))
  1480. return rc;
  1481. return count;
  1482. }
  1483. signum = simple_strtoul(tmp, &tmp2, 10);
  1484. if ((signum < 0) || (signum > 32)){
  1485. PRINT_WARN("Signal number %d is out of range\n", signum);
  1486. return -EINVAL;
  1487. }
  1488. if ((rc = qeth_notifier_register(current, signum)))
  1489. return rc;
  1490. return count;
  1491. }
  1492. static DRIVER_ATTR(notifier_register, 0200, NULL,
  1493. qeth_driver_notifier_register_store);
  1494. int
  1495. qeth_create_driver_attributes(void)
  1496. {
  1497. int rc;
  1498. if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
  1499. &driver_attr_group)))
  1500. return rc;
  1501. return driver_create_file(&qeth_ccwgroup_driver.driver,
  1502. &driver_attr_notifier_register);
  1503. }
  1504. void
  1505. qeth_remove_driver_attributes(void)
  1506. {
  1507. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1508. &driver_attr_group);
  1509. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1510. &driver_attr_notifier_register);
  1511. }