qeth_sys.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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 inline 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 inline 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, "multicast_router")) {
  324. route->type = MULTICAST_ROUTER;
  325. } else if (!strcmp(tmp, "primary_router")) {
  326. route->type = PRIMARY_ROUTER;
  327. } else if (!strcmp(tmp, "secondary_router")) {
  328. route->type = SECONDARY_ROUTER;
  329. } else if (!strcmp(tmp, "multicast_router")) {
  330. route->type = MULTICAST_ROUTER;
  331. } else {
  332. PRINT_WARN("Invalid routing type '%s'.\n", tmp);
  333. return -EINVAL;
  334. }
  335. if (((card->state == CARD_STATE_SOFTSETUP) ||
  336. (card->state == CARD_STATE_UP)) &&
  337. (old_route_type != route->type)){
  338. if (prot == QETH_PROT_IPV4)
  339. rc = qeth_setrouting_v4(card);
  340. else if (prot == QETH_PROT_IPV6)
  341. rc = qeth_setrouting_v6(card);
  342. }
  343. return count;
  344. }
  345. static ssize_t
  346. qeth_dev_route4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  347. {
  348. struct qeth_card *card = dev->driver_data;
  349. if (!card)
  350. return -EINVAL;
  351. return qeth_dev_route_store(card, &card->options.route4,
  352. QETH_PROT_IPV4, buf, count);
  353. }
  354. static DEVICE_ATTR(route4, 0644, qeth_dev_route4_show, qeth_dev_route4_store);
  355. #ifdef CONFIG_QETH_IPV6
  356. static ssize_t
  357. qeth_dev_route6_show(struct device *dev, struct device_attribute *attr, char *buf)
  358. {
  359. struct qeth_card *card = dev->driver_data;
  360. if (!card)
  361. return -EINVAL;
  362. if (!qeth_is_supported(card, IPA_IPV6))
  363. return sprintf(buf, "%s\n", "n/a");
  364. return qeth_dev_route_show(card, &card->options.route6, buf);
  365. }
  366. static ssize_t
  367. qeth_dev_route6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  368. {
  369. struct qeth_card *card = dev->driver_data;
  370. if (!card)
  371. return -EINVAL;
  372. if (!qeth_is_supported(card, IPA_IPV6)){
  373. PRINT_WARN("IPv6 not supported for interface %s.\n"
  374. "Routing status no changed.\n",
  375. QETH_CARD_IFNAME(card));
  376. return -ENOTSUPP;
  377. }
  378. return qeth_dev_route_store(card, &card->options.route6,
  379. QETH_PROT_IPV6, buf, count);
  380. }
  381. static DEVICE_ATTR(route6, 0644, qeth_dev_route6_show, qeth_dev_route6_store);
  382. #endif
  383. static ssize_t
  384. qeth_dev_add_hhlen_show(struct device *dev, struct device_attribute *attr, char *buf)
  385. {
  386. struct qeth_card *card = dev->driver_data;
  387. if (!card)
  388. return -EINVAL;
  389. return sprintf(buf, "%i\n", card->options.add_hhlen);
  390. }
  391. static ssize_t
  392. qeth_dev_add_hhlen_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  393. {
  394. struct qeth_card *card = dev->driver_data;
  395. char *tmp;
  396. int i;
  397. if (!card)
  398. return -EINVAL;
  399. if ((card->state != CARD_STATE_DOWN) &&
  400. (card->state != CARD_STATE_RECOVER))
  401. return -EPERM;
  402. i = simple_strtoul(buf, &tmp, 10);
  403. if ((i < 0) || (i > MAX_ADD_HHLEN)) {
  404. PRINT_WARN("add_hhlen out of range\n");
  405. return -EINVAL;
  406. }
  407. card->options.add_hhlen = i;
  408. return count;
  409. }
  410. static DEVICE_ATTR(add_hhlen, 0644, qeth_dev_add_hhlen_show,
  411. qeth_dev_add_hhlen_store);
  412. static ssize_t
  413. qeth_dev_fake_ll_show(struct device *dev, struct device_attribute *attr, char *buf)
  414. {
  415. struct qeth_card *card = dev->driver_data;
  416. if (!card)
  417. return -EINVAL;
  418. return sprintf(buf, "%i\n", card->options.fake_ll? 1:0);
  419. }
  420. static ssize_t
  421. qeth_dev_fake_ll_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  422. {
  423. struct qeth_card *card = dev->driver_data;
  424. char *tmp;
  425. int i;
  426. if (!card)
  427. return -EINVAL;
  428. if ((card->state != CARD_STATE_DOWN) &&
  429. (card->state != CARD_STATE_RECOVER))
  430. return -EPERM;
  431. i = simple_strtoul(buf, &tmp, 16);
  432. if ((i != 0) && (i != 1)) {
  433. PRINT_WARN("fake_ll: write 0 or 1 to this file!\n");
  434. return -EINVAL;
  435. }
  436. card->options.fake_ll = i;
  437. return count;
  438. }
  439. static DEVICE_ATTR(fake_ll, 0644, qeth_dev_fake_ll_show,
  440. qeth_dev_fake_ll_store);
  441. static ssize_t
  442. qeth_dev_fake_broadcast_show(struct device *dev, struct device_attribute *attr, char *buf)
  443. {
  444. struct qeth_card *card = dev->driver_data;
  445. if (!card)
  446. return -EINVAL;
  447. return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
  448. }
  449. static ssize_t
  450. qeth_dev_fake_broadcast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  451. {
  452. struct qeth_card *card = dev->driver_data;
  453. char *tmp;
  454. int i;
  455. if (!card)
  456. return -EINVAL;
  457. if ((card->state != CARD_STATE_DOWN) &&
  458. (card->state != CARD_STATE_RECOVER))
  459. return -EPERM;
  460. i = simple_strtoul(buf, &tmp, 16);
  461. if ((i == 0) || (i == 1))
  462. card->options.fake_broadcast = i;
  463. else {
  464. PRINT_WARN("fake_broadcast: write 0 or 1 to this file!\n");
  465. return -EINVAL;
  466. }
  467. return count;
  468. }
  469. static DEVICE_ATTR(fake_broadcast, 0644, qeth_dev_fake_broadcast_show,
  470. qeth_dev_fake_broadcast_store);
  471. static ssize_t
  472. qeth_dev_recover_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  473. {
  474. struct qeth_card *card = dev->driver_data;
  475. char *tmp;
  476. int i;
  477. if (!card)
  478. return -EINVAL;
  479. if (card->state != CARD_STATE_UP)
  480. return -EPERM;
  481. i = simple_strtoul(buf, &tmp, 16);
  482. if (i == 1)
  483. qeth_schedule_recovery(card);
  484. return count;
  485. }
  486. static DEVICE_ATTR(recover, 0200, NULL, qeth_dev_recover_store);
  487. static ssize_t
  488. qeth_dev_broadcast_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  489. {
  490. struct qeth_card *card = dev->driver_data;
  491. if (!card)
  492. return -EINVAL;
  493. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  494. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  495. return sprintf(buf, "n/a\n");
  496. return sprintf(buf, "%s\n", (card->options.broadcast_mode ==
  497. QETH_TR_BROADCAST_ALLRINGS)?
  498. "all rings":"local");
  499. }
  500. static ssize_t
  501. qeth_dev_broadcast_mode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  502. {
  503. struct qeth_card *card = dev->driver_data;
  504. char *tmp;
  505. if (!card)
  506. return -EINVAL;
  507. if ((card->state != CARD_STATE_DOWN) &&
  508. (card->state != CARD_STATE_RECOVER))
  509. return -EPERM;
  510. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  511. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  512. PRINT_WARN("Device is not a tokenring device!\n");
  513. return -EINVAL;
  514. }
  515. tmp = strsep((char **) &buf, "\n");
  516. if (!strcmp(tmp, "local")){
  517. card->options.broadcast_mode = QETH_TR_BROADCAST_LOCAL;
  518. return count;
  519. } else if (!strcmp(tmp, "all_rings")) {
  520. card->options.broadcast_mode = QETH_TR_BROADCAST_ALLRINGS;
  521. return count;
  522. } else {
  523. PRINT_WARN("broadcast_mode: invalid mode %s!\n",
  524. tmp);
  525. return -EINVAL;
  526. }
  527. return count;
  528. }
  529. static DEVICE_ATTR(broadcast_mode, 0644, qeth_dev_broadcast_mode_show,
  530. qeth_dev_broadcast_mode_store);
  531. static ssize_t
  532. qeth_dev_canonical_macaddr_show(struct device *dev, struct device_attribute *attr, char *buf)
  533. {
  534. struct qeth_card *card = dev->driver_data;
  535. if (!card)
  536. return -EINVAL;
  537. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  538. (card->info.link_type == QETH_LINK_TYPE_LANE_TR)))
  539. return sprintf(buf, "n/a\n");
  540. return sprintf(buf, "%i\n", (card->options.macaddr_mode ==
  541. QETH_TR_MACADDR_CANONICAL)? 1:0);
  542. }
  543. static ssize_t
  544. qeth_dev_canonical_macaddr_store(struct device *dev, struct device_attribute *attr, const char *buf,
  545. size_t count)
  546. {
  547. struct qeth_card *card = dev->driver_data;
  548. char *tmp;
  549. int i;
  550. if (!card)
  551. return -EINVAL;
  552. if ((card->state != CARD_STATE_DOWN) &&
  553. (card->state != CARD_STATE_RECOVER))
  554. return -EPERM;
  555. if (!((card->info.link_type == QETH_LINK_TYPE_HSTR) ||
  556. (card->info.link_type == QETH_LINK_TYPE_LANE_TR))){
  557. PRINT_WARN("Device is not a tokenring device!\n");
  558. return -EINVAL;
  559. }
  560. i = simple_strtoul(buf, &tmp, 16);
  561. if ((i == 0) || (i == 1))
  562. card->options.macaddr_mode = i?
  563. QETH_TR_MACADDR_CANONICAL :
  564. QETH_TR_MACADDR_NONCANONICAL;
  565. else {
  566. PRINT_WARN("canonical_macaddr: write 0 or 1 to this file!\n");
  567. return -EINVAL;
  568. }
  569. return count;
  570. }
  571. static DEVICE_ATTR(canonical_macaddr, 0644, qeth_dev_canonical_macaddr_show,
  572. qeth_dev_canonical_macaddr_store);
  573. static ssize_t
  574. qeth_dev_layer2_show(struct device *dev, struct device_attribute *attr, char *buf)
  575. {
  576. struct qeth_card *card = dev->driver_data;
  577. if (!card)
  578. return -EINVAL;
  579. return sprintf(buf, "%i\n", card->options.layer2 ? 1:0);
  580. }
  581. static ssize_t
  582. qeth_dev_layer2_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  583. {
  584. struct qeth_card *card = dev->driver_data;
  585. char *tmp;
  586. int i;
  587. if (!card)
  588. return -EINVAL;
  589. if (card->info.type == QETH_CARD_TYPE_IQD) {
  590. PRINT_WARN("Layer2 on Hipersockets is not supported! \n");
  591. return -EPERM;
  592. }
  593. if (((card->state != CARD_STATE_DOWN) &&
  594. (card->state != CARD_STATE_RECOVER)))
  595. return -EPERM;
  596. i = simple_strtoul(buf, &tmp, 16);
  597. if ((i == 0) || (i == 1))
  598. card->options.layer2 = i;
  599. else {
  600. PRINT_WARN("layer2: write 0 or 1 to this file!\n");
  601. return -EINVAL;
  602. }
  603. return count;
  604. }
  605. static DEVICE_ATTR(layer2, 0644, qeth_dev_layer2_show,
  606. qeth_dev_layer2_store);
  607. static ssize_t
  608. qeth_dev_performance_stats_show(struct device *dev, struct device_attribute *attr, char *buf)
  609. {
  610. struct qeth_card *card = dev->driver_data;
  611. if (!card)
  612. return -EINVAL;
  613. return sprintf(buf, "%i\n", card->options.performance_stats ? 1:0);
  614. }
  615. static ssize_t
  616. qeth_dev_performance_stats_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  617. {
  618. struct qeth_card *card = dev->driver_data;
  619. char *tmp;
  620. int i;
  621. if (!card)
  622. return -EINVAL;
  623. i = simple_strtoul(buf, &tmp, 16);
  624. if ((i == 0) || (i == 1)) {
  625. if (i == card->options.performance_stats)
  626. return count;
  627. card->options.performance_stats = i;
  628. if (i == 0)
  629. memset(&card->perf_stats, 0,
  630. sizeof(struct qeth_perf_stats));
  631. card->perf_stats.initial_rx_packets = card->stats.rx_packets;
  632. card->perf_stats.initial_tx_packets = card->stats.tx_packets;
  633. } else {
  634. PRINT_WARN("performance_stats: write 0 or 1 to this file!\n");
  635. return -EINVAL;
  636. }
  637. return count;
  638. }
  639. static DEVICE_ATTR(performance_stats, 0644, qeth_dev_performance_stats_show,
  640. qeth_dev_performance_stats_store);
  641. static ssize_t
  642. qeth_dev_large_send_show(struct device *dev, struct device_attribute *attr, char *buf)
  643. {
  644. struct qeth_card *card = dev->driver_data;
  645. if (!card)
  646. return -EINVAL;
  647. switch (card->options.large_send) {
  648. case QETH_LARGE_SEND_NO:
  649. return sprintf(buf, "%s\n", "no");
  650. case QETH_LARGE_SEND_EDDP:
  651. return sprintf(buf, "%s\n", "EDDP");
  652. case QETH_LARGE_SEND_TSO:
  653. return sprintf(buf, "%s\n", "TSO");
  654. default:
  655. return sprintf(buf, "%s\n", "N/A");
  656. }
  657. }
  658. static ssize_t
  659. qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  660. {
  661. struct qeth_card *card = dev->driver_data;
  662. enum qeth_large_send_types type;
  663. int rc = 0;
  664. char *tmp;
  665. if (!card)
  666. return -EINVAL;
  667. tmp = strsep((char **) &buf, "\n");
  668. if (!strcmp(tmp, "no")){
  669. type = QETH_LARGE_SEND_NO;
  670. } else if (!strcmp(tmp, "EDDP")) {
  671. type = QETH_LARGE_SEND_EDDP;
  672. } else if (!strcmp(tmp, "TSO")) {
  673. type = QETH_LARGE_SEND_TSO;
  674. } else {
  675. PRINT_WARN("large_send: invalid mode %s!\n", tmp);
  676. return -EINVAL;
  677. }
  678. if (card->options.large_send == type)
  679. return count;
  680. if ((rc = qeth_set_large_send(card, type)))
  681. return rc;
  682. return count;
  683. }
  684. static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
  685. qeth_dev_large_send_store);
  686. static ssize_t
  687. qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
  688. {
  689. if (!card)
  690. return -EINVAL;
  691. return sprintf(buf, "%i\n", value);
  692. }
  693. static ssize_t
  694. qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
  695. int *value, int max_value)
  696. {
  697. char *tmp;
  698. int i;
  699. if (!card)
  700. return -EINVAL;
  701. if ((card->state != CARD_STATE_DOWN) &&
  702. (card->state != CARD_STATE_RECOVER))
  703. return -EPERM;
  704. i = simple_strtoul(buf, &tmp, 10);
  705. if (i <= max_value) {
  706. *value = i;
  707. } else {
  708. PRINT_WARN("blkt total time: write values between"
  709. " 0 and %d to this file!\n", max_value);
  710. return -EINVAL;
  711. }
  712. return count;
  713. }
  714. static ssize_t
  715. qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
  716. {
  717. struct qeth_card *card = dev->driver_data;
  718. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  719. }
  720. static ssize_t
  721. qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  722. {
  723. struct qeth_card *card = dev->driver_data;
  724. return qeth_dev_blkt_store(card, buf, count,
  725. &card->info.blkt.time_total,1000);
  726. }
  727. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  728. qeth_dev_blkt_total_store);
  729. static ssize_t
  730. qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
  731. {
  732. struct qeth_card *card = dev->driver_data;
  733. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  734. }
  735. static ssize_t
  736. qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  737. {
  738. struct qeth_card *card = dev->driver_data;
  739. return qeth_dev_blkt_store(card, buf, count,
  740. &card->info.blkt.inter_packet,100);
  741. }
  742. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  743. qeth_dev_blkt_inter_store);
  744. static ssize_t
  745. qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
  746. {
  747. struct qeth_card *card = dev->driver_data;
  748. return qeth_dev_blkt_show(buf, card,
  749. card->info.blkt.inter_packet_jumbo);
  750. }
  751. static ssize_t
  752. qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  753. {
  754. struct qeth_card *card = dev->driver_data;
  755. return qeth_dev_blkt_store(card, buf, count,
  756. &card->info.blkt.inter_packet_jumbo,100);
  757. }
  758. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  759. qeth_dev_blkt_inter_jumbo_store);
  760. static struct device_attribute * qeth_blkt_device_attrs[] = {
  761. &dev_attr_total,
  762. &dev_attr_inter,
  763. &dev_attr_inter_jumbo,
  764. NULL,
  765. };
  766. static struct attribute_group qeth_device_blkt_group = {
  767. .name = "blkt",
  768. .attrs = (struct attribute **)qeth_blkt_device_attrs,
  769. };
  770. static struct device_attribute * qeth_device_attrs[] = {
  771. &dev_attr_state,
  772. &dev_attr_chpid,
  773. &dev_attr_if_name,
  774. &dev_attr_card_type,
  775. &dev_attr_portno,
  776. &dev_attr_portname,
  777. &dev_attr_checksumming,
  778. &dev_attr_priority_queueing,
  779. &dev_attr_buffer_count,
  780. &dev_attr_route4,
  781. #ifdef CONFIG_QETH_IPV6
  782. &dev_attr_route6,
  783. #endif
  784. &dev_attr_add_hhlen,
  785. &dev_attr_fake_ll,
  786. &dev_attr_fake_broadcast,
  787. &dev_attr_recover,
  788. &dev_attr_broadcast_mode,
  789. &dev_attr_canonical_macaddr,
  790. &dev_attr_layer2,
  791. &dev_attr_large_send,
  792. &dev_attr_performance_stats,
  793. NULL,
  794. };
  795. static struct attribute_group qeth_device_attr_group = {
  796. .attrs = (struct attribute **)qeth_device_attrs,
  797. };
  798. static struct device_attribute * qeth_osn_device_attrs[] = {
  799. &dev_attr_state,
  800. &dev_attr_chpid,
  801. &dev_attr_if_name,
  802. &dev_attr_card_type,
  803. &dev_attr_buffer_count,
  804. &dev_attr_recover,
  805. NULL,
  806. };
  807. static struct attribute_group qeth_osn_device_attr_group = {
  808. .attrs = (struct attribute **)qeth_osn_device_attrs,
  809. };
  810. #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
  811. struct device_attribute dev_attr_##_id = { \
  812. .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
  813. .show = _show, \
  814. .store = _store, \
  815. };
  816. int
  817. qeth_check_layer2(struct qeth_card *card)
  818. {
  819. if (card->options.layer2)
  820. return -EPERM;
  821. return 0;
  822. }
  823. static ssize_t
  824. qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
  825. {
  826. struct qeth_card *card = dev->driver_data;
  827. if (!card)
  828. return -EINVAL;
  829. if (qeth_check_layer2(card))
  830. return -EPERM;
  831. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  832. }
  833. static ssize_t
  834. qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  835. {
  836. struct qeth_card *card = dev->driver_data;
  837. char *tmp;
  838. if (!card)
  839. return -EINVAL;
  840. if ((card->state != CARD_STATE_DOWN) &&
  841. (card->state != CARD_STATE_RECOVER))
  842. return -EPERM;
  843. if (qeth_check_layer2(card))
  844. return -EPERM;
  845. tmp = strsep((char **) &buf, "\n");
  846. if (!strcmp(tmp, "toggle")){
  847. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  848. } else if (!strcmp(tmp, "1")){
  849. card->ipato.enabled = 1;
  850. } else if (!strcmp(tmp, "0")){
  851. card->ipato.enabled = 0;
  852. } else {
  853. PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
  854. "this file\n");
  855. return -EINVAL;
  856. }
  857. return count;
  858. }
  859. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  860. qeth_dev_ipato_enable_show,
  861. qeth_dev_ipato_enable_store);
  862. static ssize_t
  863. qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
  864. {
  865. struct qeth_card *card = dev->driver_data;
  866. if (!card)
  867. return -EINVAL;
  868. if (qeth_check_layer2(card))
  869. return -EPERM;
  870. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  871. }
  872. static ssize_t
  873. qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  874. {
  875. struct qeth_card *card = dev->driver_data;
  876. char *tmp;
  877. if (!card)
  878. return -EINVAL;
  879. if (qeth_check_layer2(card))
  880. return -EPERM;
  881. tmp = strsep((char **) &buf, "\n");
  882. if (!strcmp(tmp, "toggle")){
  883. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  884. } else if (!strcmp(tmp, "1")){
  885. card->ipato.invert4 = 1;
  886. } else if (!strcmp(tmp, "0")){
  887. card->ipato.invert4 = 0;
  888. } else {
  889. PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
  890. "this file\n");
  891. return -EINVAL;
  892. }
  893. return count;
  894. }
  895. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  896. qeth_dev_ipato_invert4_show,
  897. qeth_dev_ipato_invert4_store);
  898. static inline ssize_t
  899. qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
  900. enum qeth_prot_versions proto)
  901. {
  902. struct qeth_ipato_entry *ipatoe;
  903. unsigned long flags;
  904. char addr_str[40];
  905. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  906. int i = 0;
  907. if (qeth_check_layer2(card))
  908. return -EPERM;
  909. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  910. /* add strlen for "/<mask>\n" */
  911. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  912. spin_lock_irqsave(&card->ip_lock, flags);
  913. list_for_each_entry(ipatoe, &card->ipato.entries, entry){
  914. if (ipatoe->proto != proto)
  915. continue;
  916. /* String must not be longer than PAGE_SIZE. So we check if
  917. * string length gets near PAGE_SIZE. Then we can savely display
  918. * the next IPv6 address (worst case, compared to IPv4) */
  919. if ((PAGE_SIZE - i) <= entry_len)
  920. break;
  921. qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  922. i += snprintf(buf + i, PAGE_SIZE - i,
  923. "%s/%i\n", addr_str, ipatoe->mask_bits);
  924. }
  925. spin_unlock_irqrestore(&card->ip_lock, flags);
  926. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  927. return i;
  928. }
  929. static ssize_t
  930. qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  931. {
  932. struct qeth_card *card = dev->driver_data;
  933. if (!card)
  934. return -EINVAL;
  935. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  936. }
  937. static inline int
  938. qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
  939. u8 *addr, int *mask_bits)
  940. {
  941. const char *start, *end;
  942. char *tmp;
  943. char buffer[40] = {0, };
  944. start = buf;
  945. /* get address string */
  946. end = strchr(start, '/');
  947. if (!end || (end - start >= 40)){
  948. PRINT_WARN("Invalid format for ipato_addx/delx. "
  949. "Use <ip addr>/<mask bits>\n");
  950. return -EINVAL;
  951. }
  952. strncpy(buffer, start, end - start);
  953. if (qeth_string_to_ipaddr(buffer, proto, addr)){
  954. PRINT_WARN("Invalid IP address format!\n");
  955. return -EINVAL;
  956. }
  957. start = end + 1;
  958. *mask_bits = simple_strtoul(start, &tmp, 10);
  959. if (!strlen(start) ||
  960. (tmp == start) ||
  961. (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
  962. PRINT_WARN("Invalid mask bits for ipato_addx/delx !\n");
  963. return -EINVAL;
  964. }
  965. return 0;
  966. }
  967. static inline ssize_t
  968. qeth_dev_ipato_add_store(const char *buf, size_t count,
  969. struct qeth_card *card, enum qeth_prot_versions proto)
  970. {
  971. struct qeth_ipato_entry *ipatoe;
  972. u8 addr[16];
  973. int mask_bits;
  974. int rc;
  975. if (qeth_check_layer2(card))
  976. return -EPERM;
  977. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  978. return rc;
  979. if (!(ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
  980. PRINT_WARN("No memory to allocate ipato entry\n");
  981. return -ENOMEM;
  982. }
  983. ipatoe->proto = proto;
  984. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  985. ipatoe->mask_bits = mask_bits;
  986. if ((rc = qeth_add_ipato_entry(card, ipatoe))){
  987. kfree(ipatoe);
  988. return rc;
  989. }
  990. return count;
  991. }
  992. static ssize_t
  993. qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  994. {
  995. struct qeth_card *card = dev->driver_data;
  996. if (!card)
  997. return -EINVAL;
  998. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  999. }
  1000. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  1001. qeth_dev_ipato_add4_show,
  1002. qeth_dev_ipato_add4_store);
  1003. static inline ssize_t
  1004. qeth_dev_ipato_del_store(const char *buf, size_t count,
  1005. struct qeth_card *card, enum qeth_prot_versions proto)
  1006. {
  1007. u8 addr[16];
  1008. int mask_bits;
  1009. int rc;
  1010. if (qeth_check_layer2(card))
  1011. return -EPERM;
  1012. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  1013. return rc;
  1014. qeth_del_ipato_entry(card, proto, addr, mask_bits);
  1015. return count;
  1016. }
  1017. static ssize_t
  1018. qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1019. {
  1020. struct qeth_card *card = dev->driver_data;
  1021. if (!card)
  1022. return -EINVAL;
  1023. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  1024. }
  1025. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  1026. qeth_dev_ipato_del4_store);
  1027. #ifdef CONFIG_QETH_IPV6
  1028. static ssize_t
  1029. qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1030. {
  1031. struct qeth_card *card = dev->driver_data;
  1032. if (!card)
  1033. return -EINVAL;
  1034. if (qeth_check_layer2(card))
  1035. return -EPERM;
  1036. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  1037. }
  1038. static ssize_t
  1039. qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1040. {
  1041. struct qeth_card *card = dev->driver_data;
  1042. char *tmp;
  1043. if (!card)
  1044. return -EINVAL;
  1045. if (qeth_check_layer2(card))
  1046. return -EPERM;
  1047. tmp = strsep((char **) &buf, "\n");
  1048. if (!strcmp(tmp, "toggle")){
  1049. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  1050. } else if (!strcmp(tmp, "1")){
  1051. card->ipato.invert6 = 1;
  1052. } else if (!strcmp(tmp, "0")){
  1053. card->ipato.invert6 = 0;
  1054. } else {
  1055. PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
  1056. "this file\n");
  1057. return -EINVAL;
  1058. }
  1059. return count;
  1060. }
  1061. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  1062. qeth_dev_ipato_invert6_show,
  1063. qeth_dev_ipato_invert6_store);
  1064. static ssize_t
  1065. qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1066. {
  1067. struct qeth_card *card = dev->driver_data;
  1068. if (!card)
  1069. return -EINVAL;
  1070. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  1071. }
  1072. static ssize_t
  1073. qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1074. {
  1075. struct qeth_card *card = dev->driver_data;
  1076. if (!card)
  1077. return -EINVAL;
  1078. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  1079. }
  1080. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  1081. qeth_dev_ipato_add6_show,
  1082. qeth_dev_ipato_add6_store);
  1083. static ssize_t
  1084. qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1085. {
  1086. struct qeth_card *card = dev->driver_data;
  1087. if (!card)
  1088. return -EINVAL;
  1089. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  1090. }
  1091. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  1092. qeth_dev_ipato_del6_store);
  1093. #endif /* CONFIG_QETH_IPV6 */
  1094. static struct device_attribute * qeth_ipato_device_attrs[] = {
  1095. &dev_attr_ipato_enable,
  1096. &dev_attr_ipato_invert4,
  1097. &dev_attr_ipato_add4,
  1098. &dev_attr_ipato_del4,
  1099. #ifdef CONFIG_QETH_IPV6
  1100. &dev_attr_ipato_invert6,
  1101. &dev_attr_ipato_add6,
  1102. &dev_attr_ipato_del6,
  1103. #endif
  1104. NULL,
  1105. };
  1106. static struct attribute_group qeth_device_ipato_group = {
  1107. .name = "ipa_takeover",
  1108. .attrs = (struct attribute **)qeth_ipato_device_attrs,
  1109. };
  1110. static inline ssize_t
  1111. qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
  1112. enum qeth_prot_versions proto)
  1113. {
  1114. struct qeth_ipaddr *ipaddr;
  1115. char addr_str[40];
  1116. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1117. unsigned long flags;
  1118. int i = 0;
  1119. if (qeth_check_layer2(card))
  1120. return -EPERM;
  1121. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1122. entry_len += 2; /* \n + terminator */
  1123. spin_lock_irqsave(&card->ip_lock, flags);
  1124. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1125. if (ipaddr->proto != proto)
  1126. continue;
  1127. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  1128. continue;
  1129. /* String must not be longer than PAGE_SIZE. So we check if
  1130. * string length gets near PAGE_SIZE. Then we can savely display
  1131. * the next IPv6 address (worst case, compared to IPv4) */
  1132. if ((PAGE_SIZE - i) <= entry_len)
  1133. break;
  1134. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1135. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1136. }
  1137. spin_unlock_irqrestore(&card->ip_lock, flags);
  1138. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1139. return i;
  1140. }
  1141. static ssize_t
  1142. qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1143. {
  1144. struct qeth_card *card = dev->driver_data;
  1145. if (!card)
  1146. return -EINVAL;
  1147. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  1148. }
  1149. static inline int
  1150. qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
  1151. u8 *addr)
  1152. {
  1153. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1154. PRINT_WARN("Invalid IP address format!\n");
  1155. return -EINVAL;
  1156. }
  1157. return 0;
  1158. }
  1159. static inline ssize_t
  1160. qeth_dev_vipa_add_store(const char *buf, size_t count,
  1161. struct qeth_card *card, enum qeth_prot_versions proto)
  1162. {
  1163. u8 addr[16] = {0, };
  1164. int rc;
  1165. if (qeth_check_layer2(card))
  1166. return -EPERM;
  1167. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1168. return rc;
  1169. if ((rc = qeth_add_vipa(card, proto, addr)))
  1170. return rc;
  1171. return count;
  1172. }
  1173. static ssize_t
  1174. qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1175. {
  1176. struct qeth_card *card = dev->driver_data;
  1177. if (!card)
  1178. return -EINVAL;
  1179. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  1180. }
  1181. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  1182. qeth_dev_vipa_add4_show,
  1183. qeth_dev_vipa_add4_store);
  1184. static inline ssize_t
  1185. qeth_dev_vipa_del_store(const char *buf, size_t count,
  1186. struct qeth_card *card, enum qeth_prot_versions proto)
  1187. {
  1188. u8 addr[16];
  1189. int rc;
  1190. if (qeth_check_layer2(card))
  1191. return -EPERM;
  1192. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1193. return rc;
  1194. qeth_del_vipa(card, proto, addr);
  1195. return count;
  1196. }
  1197. static ssize_t
  1198. qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1199. {
  1200. struct qeth_card *card = dev->driver_data;
  1201. if (!card)
  1202. return -EINVAL;
  1203. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  1204. }
  1205. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  1206. qeth_dev_vipa_del4_store);
  1207. #ifdef CONFIG_QETH_IPV6
  1208. static ssize_t
  1209. qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1210. {
  1211. struct qeth_card *card = dev->driver_data;
  1212. if (!card)
  1213. return -EINVAL;
  1214. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  1215. }
  1216. static ssize_t
  1217. qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1218. {
  1219. struct qeth_card *card = dev->driver_data;
  1220. if (!card)
  1221. return -EINVAL;
  1222. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  1223. }
  1224. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  1225. qeth_dev_vipa_add6_show,
  1226. qeth_dev_vipa_add6_store);
  1227. static ssize_t
  1228. qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1229. {
  1230. struct qeth_card *card = dev->driver_data;
  1231. if (!card)
  1232. return -EINVAL;
  1233. if (qeth_check_layer2(card))
  1234. return -EPERM;
  1235. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  1236. }
  1237. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  1238. qeth_dev_vipa_del6_store);
  1239. #endif /* CONFIG_QETH_IPV6 */
  1240. static struct device_attribute * qeth_vipa_device_attrs[] = {
  1241. &dev_attr_vipa_add4,
  1242. &dev_attr_vipa_del4,
  1243. #ifdef CONFIG_QETH_IPV6
  1244. &dev_attr_vipa_add6,
  1245. &dev_attr_vipa_del6,
  1246. #endif
  1247. NULL,
  1248. };
  1249. static struct attribute_group qeth_device_vipa_group = {
  1250. .name = "vipa",
  1251. .attrs = (struct attribute **)qeth_vipa_device_attrs,
  1252. };
  1253. static inline ssize_t
  1254. qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
  1255. enum qeth_prot_versions proto)
  1256. {
  1257. struct qeth_ipaddr *ipaddr;
  1258. char addr_str[40];
  1259. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1260. unsigned long flags;
  1261. int i = 0;
  1262. if (qeth_check_layer2(card))
  1263. return -EPERM;
  1264. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1265. entry_len += 2; /* \n + terminator */
  1266. spin_lock_irqsave(&card->ip_lock, flags);
  1267. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1268. if (ipaddr->proto != proto)
  1269. continue;
  1270. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  1271. continue;
  1272. /* String must not be longer than PAGE_SIZE. So we check if
  1273. * string length gets near PAGE_SIZE. Then we can savely display
  1274. * the next IPv6 address (worst case, compared to IPv4) */
  1275. if ((PAGE_SIZE - i) <= entry_len)
  1276. break;
  1277. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1278. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1279. }
  1280. spin_unlock_irqrestore(&card->ip_lock, flags);
  1281. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1282. return i;
  1283. }
  1284. static ssize_t
  1285. qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1286. {
  1287. struct qeth_card *card = dev->driver_data;
  1288. if (!card)
  1289. return -EINVAL;
  1290. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  1291. }
  1292. static inline int
  1293. qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
  1294. u8 *addr)
  1295. {
  1296. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1297. PRINT_WARN("Invalid IP address format!\n");
  1298. return -EINVAL;
  1299. }
  1300. return 0;
  1301. }
  1302. static inline ssize_t
  1303. qeth_dev_rxip_add_store(const char *buf, size_t count,
  1304. struct qeth_card *card, enum qeth_prot_versions proto)
  1305. {
  1306. u8 addr[16] = {0, };
  1307. int rc;
  1308. if (qeth_check_layer2(card))
  1309. return -EPERM;
  1310. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1311. return rc;
  1312. if ((rc = qeth_add_rxip(card, proto, addr)))
  1313. return rc;
  1314. return count;
  1315. }
  1316. static ssize_t
  1317. qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1318. {
  1319. struct qeth_card *card = dev->driver_data;
  1320. if (!card)
  1321. return -EINVAL;
  1322. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  1323. }
  1324. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  1325. qeth_dev_rxip_add4_show,
  1326. qeth_dev_rxip_add4_store);
  1327. static inline ssize_t
  1328. qeth_dev_rxip_del_store(const char *buf, size_t count,
  1329. struct qeth_card *card, enum qeth_prot_versions proto)
  1330. {
  1331. u8 addr[16];
  1332. int rc;
  1333. if (qeth_check_layer2(card))
  1334. return -EPERM;
  1335. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1336. return rc;
  1337. qeth_del_rxip(card, proto, addr);
  1338. return count;
  1339. }
  1340. static ssize_t
  1341. qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1342. {
  1343. struct qeth_card *card = dev->driver_data;
  1344. if (!card)
  1345. return -EINVAL;
  1346. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  1347. }
  1348. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  1349. qeth_dev_rxip_del4_store);
  1350. #ifdef CONFIG_QETH_IPV6
  1351. static ssize_t
  1352. qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1353. {
  1354. struct qeth_card *card = dev->driver_data;
  1355. if (!card)
  1356. return -EINVAL;
  1357. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  1358. }
  1359. static ssize_t
  1360. qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1361. {
  1362. struct qeth_card *card = dev->driver_data;
  1363. if (!card)
  1364. return -EINVAL;
  1365. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  1366. }
  1367. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  1368. qeth_dev_rxip_add6_show,
  1369. qeth_dev_rxip_add6_store);
  1370. static ssize_t
  1371. qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1372. {
  1373. struct qeth_card *card = dev->driver_data;
  1374. if (!card)
  1375. return -EINVAL;
  1376. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  1377. }
  1378. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  1379. qeth_dev_rxip_del6_store);
  1380. #endif /* CONFIG_QETH_IPV6 */
  1381. static struct device_attribute * qeth_rxip_device_attrs[] = {
  1382. &dev_attr_rxip_add4,
  1383. &dev_attr_rxip_del4,
  1384. #ifdef CONFIG_QETH_IPV6
  1385. &dev_attr_rxip_add6,
  1386. &dev_attr_rxip_del6,
  1387. #endif
  1388. NULL,
  1389. };
  1390. static struct attribute_group qeth_device_rxip_group = {
  1391. .name = "rxip",
  1392. .attrs = (struct attribute **)qeth_rxip_device_attrs,
  1393. };
  1394. int
  1395. qeth_create_device_attributes(struct device *dev)
  1396. {
  1397. int ret;
  1398. struct qeth_card *card = dev->driver_data;
  1399. if (card->info.type == QETH_CARD_TYPE_OSN)
  1400. return sysfs_create_group(&dev->kobj,
  1401. &qeth_osn_device_attr_group);
  1402. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
  1403. return ret;
  1404. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
  1405. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1406. return ret;
  1407. }
  1408. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
  1409. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1410. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1411. return ret;
  1412. }
  1413. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
  1414. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1415. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1416. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1417. return ret;
  1418. }
  1419. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group))){
  1420. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1421. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1422. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1423. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1424. return ret;
  1425. }
  1426. return 0;
  1427. }
  1428. void
  1429. qeth_remove_device_attributes(struct device *dev)
  1430. {
  1431. struct qeth_card *card = dev->driver_data;
  1432. if (card->info.type == QETH_CARD_TYPE_OSN)
  1433. return sysfs_remove_group(&dev->kobj,
  1434. &qeth_osn_device_attr_group);
  1435. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1436. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1437. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1438. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1439. sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
  1440. }
  1441. /**********************/
  1442. /* DRIVER ATTRIBUTES */
  1443. /**********************/
  1444. static ssize_t
  1445. qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
  1446. size_t count)
  1447. {
  1448. const char *start, *end;
  1449. char bus_ids[3][BUS_ID_SIZE], *argv[3];
  1450. int i;
  1451. int err;
  1452. start = buf;
  1453. for (i = 0; i < 3; i++) {
  1454. static const char delim[] = { ',', ',', '\n' };
  1455. int len;
  1456. if (!(end = strchr(start, delim[i])))
  1457. return -EINVAL;
  1458. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
  1459. strncpy(bus_ids[i], start, len);
  1460. bus_ids[i][len] = '\0';
  1461. start = end + 1;
  1462. argv[i] = bus_ids[i];
  1463. }
  1464. err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
  1465. &qeth_ccw_driver, 3, argv);
  1466. if (err)
  1467. return err;
  1468. else
  1469. return count;
  1470. }
  1471. static DRIVER_ATTR(group, 0200, NULL, qeth_driver_group_store);
  1472. static ssize_t
  1473. qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
  1474. size_t count)
  1475. {
  1476. int rc;
  1477. int signum;
  1478. char *tmp, *tmp2;
  1479. tmp = strsep((char **) &buf, "\n");
  1480. if (!strncmp(tmp, "unregister", 10)){
  1481. if ((rc = qeth_notifier_unregister(current)))
  1482. return rc;
  1483. return count;
  1484. }
  1485. signum = simple_strtoul(tmp, &tmp2, 10);
  1486. if ((signum < 0) || (signum > 32)){
  1487. PRINT_WARN("Signal number %d is out of range\n", signum);
  1488. return -EINVAL;
  1489. }
  1490. if ((rc = qeth_notifier_register(current, signum)))
  1491. return rc;
  1492. return count;
  1493. }
  1494. static DRIVER_ATTR(notifier_register, 0200, NULL,
  1495. qeth_driver_notifier_register_store);
  1496. int
  1497. qeth_create_driver_attributes(void)
  1498. {
  1499. int rc;
  1500. if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
  1501. &driver_attr_group)))
  1502. return rc;
  1503. return driver_create_file(&qeth_ccwgroup_driver.driver,
  1504. &driver_attr_notifier_register);
  1505. }
  1506. void
  1507. qeth_remove_driver_attributes(void)
  1508. {
  1509. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1510. &driver_attr_group);
  1511. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1512. &driver_attr_notifier_register);
  1513. }