qeth_sys.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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_large_send_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. switch (card->options.large_send) {
  614. case QETH_LARGE_SEND_NO:
  615. return sprintf(buf, "%s\n", "no");
  616. case QETH_LARGE_SEND_EDDP:
  617. return sprintf(buf, "%s\n", "EDDP");
  618. case QETH_LARGE_SEND_TSO:
  619. return sprintf(buf, "%s\n", "TSO");
  620. default:
  621. return sprintf(buf, "%s\n", "N/A");
  622. }
  623. }
  624. static ssize_t
  625. qeth_dev_large_send_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  626. {
  627. struct qeth_card *card = dev->driver_data;
  628. enum qeth_large_send_types type;
  629. int rc = 0;
  630. char *tmp;
  631. if (!card)
  632. return -EINVAL;
  633. tmp = strsep((char **) &buf, "\n");
  634. if (!strcmp(tmp, "no")){
  635. type = QETH_LARGE_SEND_NO;
  636. } else if (!strcmp(tmp, "EDDP")) {
  637. type = QETH_LARGE_SEND_EDDP;
  638. } else if (!strcmp(tmp, "TSO")) {
  639. type = QETH_LARGE_SEND_TSO;
  640. } else {
  641. PRINT_WARN("large_send: invalid mode %s!\n", tmp);
  642. return -EINVAL;
  643. }
  644. if (card->options.large_send == type)
  645. return count;
  646. if ((rc = qeth_set_large_send(card, type)))
  647. return rc;
  648. return count;
  649. }
  650. static DEVICE_ATTR(large_send, 0644, qeth_dev_large_send_show,
  651. qeth_dev_large_send_store);
  652. static ssize_t
  653. qeth_dev_blkt_show(char *buf, struct qeth_card *card, int value )
  654. {
  655. if (!card)
  656. return -EINVAL;
  657. return sprintf(buf, "%i\n", value);
  658. }
  659. static ssize_t
  660. qeth_dev_blkt_store(struct qeth_card *card, const char *buf, size_t count,
  661. int *value, int max_value)
  662. {
  663. char *tmp;
  664. int i;
  665. if (!card)
  666. return -EINVAL;
  667. if ((card->state != CARD_STATE_DOWN) &&
  668. (card->state != CARD_STATE_RECOVER))
  669. return -EPERM;
  670. i = simple_strtoul(buf, &tmp, 10);
  671. if (i <= max_value) {
  672. *value = i;
  673. } else {
  674. PRINT_WARN("blkt total time: write values between"
  675. " 0 and %d to this file!\n", max_value);
  676. return -EINVAL;
  677. }
  678. return count;
  679. }
  680. static ssize_t
  681. qeth_dev_blkt_total_show(struct device *dev, struct device_attribute *attr, char *buf)
  682. {
  683. struct qeth_card *card = dev->driver_data;
  684. return qeth_dev_blkt_show(buf, card, card->info.blkt.time_total);
  685. }
  686. static ssize_t
  687. qeth_dev_blkt_total_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  688. {
  689. struct qeth_card *card = dev->driver_data;
  690. return qeth_dev_blkt_store(card, buf, count,
  691. &card->info.blkt.time_total,1000);
  692. }
  693. static DEVICE_ATTR(total, 0644, qeth_dev_blkt_total_show,
  694. qeth_dev_blkt_total_store);
  695. static ssize_t
  696. qeth_dev_blkt_inter_show(struct device *dev, struct device_attribute *attr, char *buf)
  697. {
  698. struct qeth_card *card = dev->driver_data;
  699. return qeth_dev_blkt_show(buf, card, card->info.blkt.inter_packet);
  700. }
  701. static ssize_t
  702. qeth_dev_blkt_inter_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  703. {
  704. struct qeth_card *card = dev->driver_data;
  705. return qeth_dev_blkt_store(card, buf, count,
  706. &card->info.blkt.inter_packet,100);
  707. }
  708. static DEVICE_ATTR(inter, 0644, qeth_dev_blkt_inter_show,
  709. qeth_dev_blkt_inter_store);
  710. static ssize_t
  711. qeth_dev_blkt_inter_jumbo_show(struct device *dev, struct device_attribute *attr, char *buf)
  712. {
  713. struct qeth_card *card = dev->driver_data;
  714. return qeth_dev_blkt_show(buf, card,
  715. card->info.blkt.inter_packet_jumbo);
  716. }
  717. static ssize_t
  718. qeth_dev_blkt_inter_jumbo_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  719. {
  720. struct qeth_card *card = dev->driver_data;
  721. return qeth_dev_blkt_store(card, buf, count,
  722. &card->info.blkt.inter_packet_jumbo,100);
  723. }
  724. static DEVICE_ATTR(inter_jumbo, 0644, qeth_dev_blkt_inter_jumbo_show,
  725. qeth_dev_blkt_inter_jumbo_store);
  726. static struct device_attribute * qeth_blkt_device_attrs[] = {
  727. &dev_attr_total,
  728. &dev_attr_inter,
  729. &dev_attr_inter_jumbo,
  730. NULL,
  731. };
  732. static struct attribute_group qeth_device_blkt_group = {
  733. .name = "blkt",
  734. .attrs = (struct attribute **)qeth_blkt_device_attrs,
  735. };
  736. static struct device_attribute * qeth_device_attrs[] = {
  737. &dev_attr_state,
  738. &dev_attr_chpid,
  739. &dev_attr_if_name,
  740. &dev_attr_card_type,
  741. &dev_attr_portno,
  742. &dev_attr_portname,
  743. &dev_attr_checksumming,
  744. &dev_attr_priority_queueing,
  745. &dev_attr_buffer_count,
  746. &dev_attr_route4,
  747. #ifdef CONFIG_QETH_IPV6
  748. &dev_attr_route6,
  749. #endif
  750. &dev_attr_add_hhlen,
  751. &dev_attr_fake_ll,
  752. &dev_attr_fake_broadcast,
  753. &dev_attr_recover,
  754. &dev_attr_broadcast_mode,
  755. &dev_attr_canonical_macaddr,
  756. &dev_attr_layer2,
  757. &dev_attr_large_send,
  758. NULL,
  759. };
  760. static struct attribute_group qeth_device_attr_group = {
  761. .attrs = (struct attribute **)qeth_device_attrs,
  762. };
  763. static struct device_attribute * qeth_osn_device_attrs[] = {
  764. &dev_attr_state,
  765. &dev_attr_chpid,
  766. &dev_attr_if_name,
  767. &dev_attr_card_type,
  768. &dev_attr_buffer_count,
  769. &dev_attr_recover,
  770. NULL,
  771. };
  772. static struct attribute_group qeth_osn_device_attr_group = {
  773. .attrs = (struct attribute **)qeth_osn_device_attrs,
  774. };
  775. #define QETH_DEVICE_ATTR(_id,_name,_mode,_show,_store) \
  776. struct device_attribute dev_attr_##_id = { \
  777. .attr = {.name=__stringify(_name), .mode=_mode, .owner=THIS_MODULE },\
  778. .show = _show, \
  779. .store = _store, \
  780. };
  781. int
  782. qeth_check_layer2(struct qeth_card *card)
  783. {
  784. if (card->options.layer2)
  785. return -EPERM;
  786. return 0;
  787. }
  788. static ssize_t
  789. qeth_dev_ipato_enable_show(struct device *dev, struct device_attribute *attr, char *buf)
  790. {
  791. struct qeth_card *card = dev->driver_data;
  792. if (!card)
  793. return -EINVAL;
  794. if (qeth_check_layer2(card))
  795. return -EPERM;
  796. return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
  797. }
  798. static ssize_t
  799. qeth_dev_ipato_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  800. {
  801. struct qeth_card *card = dev->driver_data;
  802. char *tmp;
  803. if (!card)
  804. return -EINVAL;
  805. if ((card->state != CARD_STATE_DOWN) &&
  806. (card->state != CARD_STATE_RECOVER))
  807. return -EPERM;
  808. if (qeth_check_layer2(card))
  809. return -EPERM;
  810. tmp = strsep((char **) &buf, "\n");
  811. if (!strcmp(tmp, "toggle")){
  812. card->ipato.enabled = (card->ipato.enabled)? 0 : 1;
  813. } else if (!strcmp(tmp, "1")){
  814. card->ipato.enabled = 1;
  815. } else if (!strcmp(tmp, "0")){
  816. card->ipato.enabled = 0;
  817. } else {
  818. PRINT_WARN("ipato_enable: write 0, 1 or 'toggle' to "
  819. "this file\n");
  820. return -EINVAL;
  821. }
  822. return count;
  823. }
  824. static QETH_DEVICE_ATTR(ipato_enable, enable, 0644,
  825. qeth_dev_ipato_enable_show,
  826. qeth_dev_ipato_enable_store);
  827. static ssize_t
  828. qeth_dev_ipato_invert4_show(struct device *dev, struct device_attribute *attr, char *buf)
  829. {
  830. struct qeth_card *card = dev->driver_data;
  831. if (!card)
  832. return -EINVAL;
  833. if (qeth_check_layer2(card))
  834. return -EPERM;
  835. return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
  836. }
  837. static ssize_t
  838. qeth_dev_ipato_invert4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  839. {
  840. struct qeth_card *card = dev->driver_data;
  841. char *tmp;
  842. if (!card)
  843. return -EINVAL;
  844. if (qeth_check_layer2(card))
  845. return -EPERM;
  846. tmp = strsep((char **) &buf, "\n");
  847. if (!strcmp(tmp, "toggle")){
  848. card->ipato.invert4 = (card->ipato.invert4)? 0 : 1;
  849. } else if (!strcmp(tmp, "1")){
  850. card->ipato.invert4 = 1;
  851. } else if (!strcmp(tmp, "0")){
  852. card->ipato.invert4 = 0;
  853. } else {
  854. PRINT_WARN("ipato_invert4: write 0, 1 or 'toggle' to "
  855. "this file\n");
  856. return -EINVAL;
  857. }
  858. return count;
  859. }
  860. static QETH_DEVICE_ATTR(ipato_invert4, invert4, 0644,
  861. qeth_dev_ipato_invert4_show,
  862. qeth_dev_ipato_invert4_store);
  863. static inline ssize_t
  864. qeth_dev_ipato_add_show(char *buf, struct qeth_card *card,
  865. enum qeth_prot_versions proto)
  866. {
  867. struct qeth_ipato_entry *ipatoe;
  868. unsigned long flags;
  869. char addr_str[40];
  870. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  871. int i = 0;
  872. if (qeth_check_layer2(card))
  873. return -EPERM;
  874. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  875. /* add strlen for "/<mask>\n" */
  876. entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
  877. spin_lock_irqsave(&card->ip_lock, flags);
  878. list_for_each_entry(ipatoe, &card->ipato.entries, entry){
  879. if (ipatoe->proto != proto)
  880. continue;
  881. /* String must not be longer than PAGE_SIZE. So we check if
  882. * string length gets near PAGE_SIZE. Then we can savely display
  883. * the next IPv6 address (worst case, compared to IPv4) */
  884. if ((PAGE_SIZE - i) <= entry_len)
  885. break;
  886. qeth_ipaddr_to_string(proto, ipatoe->addr, addr_str);
  887. i += snprintf(buf + i, PAGE_SIZE - i,
  888. "%s/%i\n", addr_str, ipatoe->mask_bits);
  889. }
  890. spin_unlock_irqrestore(&card->ip_lock, flags);
  891. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  892. return i;
  893. }
  894. static ssize_t
  895. qeth_dev_ipato_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  896. {
  897. struct qeth_card *card = dev->driver_data;
  898. if (!card)
  899. return -EINVAL;
  900. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
  901. }
  902. static inline int
  903. qeth_parse_ipatoe(const char* buf, enum qeth_prot_versions proto,
  904. u8 *addr, int *mask_bits)
  905. {
  906. const char *start, *end;
  907. char *tmp;
  908. char buffer[49] = {0, };
  909. start = buf;
  910. /* get address string */
  911. end = strchr(start, '/');
  912. if (!end || (end-start >= 49)){
  913. PRINT_WARN("Invalid format for ipato_addx/delx. "
  914. "Use <ip addr>/<mask bits>\n");
  915. return -EINVAL;
  916. }
  917. strncpy(buffer, start, end - start);
  918. if (qeth_string_to_ipaddr(buffer, proto, addr)){
  919. PRINT_WARN("Invalid IP address format!\n");
  920. return -EINVAL;
  921. }
  922. start = end + 1;
  923. *mask_bits = simple_strtoul(start, &tmp, 10);
  924. return 0;
  925. }
  926. static inline ssize_t
  927. qeth_dev_ipato_add_store(const char *buf, size_t count,
  928. struct qeth_card *card, enum qeth_prot_versions proto)
  929. {
  930. struct qeth_ipato_entry *ipatoe;
  931. u8 addr[16];
  932. int mask_bits;
  933. int rc;
  934. if (qeth_check_layer2(card))
  935. return -EPERM;
  936. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  937. return rc;
  938. if (!(ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL))){
  939. PRINT_WARN("No memory to allocate ipato entry\n");
  940. return -ENOMEM;
  941. }
  942. ipatoe->proto = proto;
  943. memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
  944. ipatoe->mask_bits = mask_bits;
  945. if ((rc = qeth_add_ipato_entry(card, ipatoe))){
  946. kfree(ipatoe);
  947. return rc;
  948. }
  949. return count;
  950. }
  951. static ssize_t
  952. qeth_dev_ipato_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  953. {
  954. struct qeth_card *card = dev->driver_data;
  955. if (!card)
  956. return -EINVAL;
  957. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
  958. }
  959. static QETH_DEVICE_ATTR(ipato_add4, add4, 0644,
  960. qeth_dev_ipato_add4_show,
  961. qeth_dev_ipato_add4_store);
  962. static inline ssize_t
  963. qeth_dev_ipato_del_store(const char *buf, size_t count,
  964. struct qeth_card *card, enum qeth_prot_versions proto)
  965. {
  966. u8 addr[16];
  967. int mask_bits;
  968. int rc;
  969. if (qeth_check_layer2(card))
  970. return -EPERM;
  971. if ((rc = qeth_parse_ipatoe(buf, proto, addr, &mask_bits)))
  972. return rc;
  973. qeth_del_ipato_entry(card, proto, addr, mask_bits);
  974. return count;
  975. }
  976. static ssize_t
  977. qeth_dev_ipato_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  978. {
  979. struct qeth_card *card = dev->driver_data;
  980. if (!card)
  981. return -EINVAL;
  982. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
  983. }
  984. static QETH_DEVICE_ATTR(ipato_del4, del4, 0200, NULL,
  985. qeth_dev_ipato_del4_store);
  986. #ifdef CONFIG_QETH_IPV6
  987. static ssize_t
  988. qeth_dev_ipato_invert6_show(struct device *dev, struct device_attribute *attr, char *buf)
  989. {
  990. struct qeth_card *card = dev->driver_data;
  991. if (!card)
  992. return -EINVAL;
  993. if (qeth_check_layer2(card))
  994. return -EPERM;
  995. return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
  996. }
  997. static ssize_t
  998. qeth_dev_ipato_invert6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  999. {
  1000. struct qeth_card *card = dev->driver_data;
  1001. char *tmp;
  1002. if (!card)
  1003. return -EINVAL;
  1004. if (qeth_check_layer2(card))
  1005. return -EPERM;
  1006. tmp = strsep((char **) &buf, "\n");
  1007. if (!strcmp(tmp, "toggle")){
  1008. card->ipato.invert6 = (card->ipato.invert6)? 0 : 1;
  1009. } else if (!strcmp(tmp, "1")){
  1010. card->ipato.invert6 = 1;
  1011. } else if (!strcmp(tmp, "0")){
  1012. card->ipato.invert6 = 0;
  1013. } else {
  1014. PRINT_WARN("ipato_invert6: write 0, 1 or 'toggle' to "
  1015. "this file\n");
  1016. return -EINVAL;
  1017. }
  1018. return count;
  1019. }
  1020. static QETH_DEVICE_ATTR(ipato_invert6, invert6, 0644,
  1021. qeth_dev_ipato_invert6_show,
  1022. qeth_dev_ipato_invert6_store);
  1023. static ssize_t
  1024. qeth_dev_ipato_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1025. {
  1026. struct qeth_card *card = dev->driver_data;
  1027. if (!card)
  1028. return -EINVAL;
  1029. return qeth_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
  1030. }
  1031. static ssize_t
  1032. qeth_dev_ipato_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1033. {
  1034. struct qeth_card *card = dev->driver_data;
  1035. if (!card)
  1036. return -EINVAL;
  1037. return qeth_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
  1038. }
  1039. static QETH_DEVICE_ATTR(ipato_add6, add6, 0644,
  1040. qeth_dev_ipato_add6_show,
  1041. qeth_dev_ipato_add6_store);
  1042. static ssize_t
  1043. qeth_dev_ipato_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1044. {
  1045. struct qeth_card *card = dev->driver_data;
  1046. if (!card)
  1047. return -EINVAL;
  1048. return qeth_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
  1049. }
  1050. static QETH_DEVICE_ATTR(ipato_del6, del6, 0200, NULL,
  1051. qeth_dev_ipato_del6_store);
  1052. #endif /* CONFIG_QETH_IPV6 */
  1053. static struct device_attribute * qeth_ipato_device_attrs[] = {
  1054. &dev_attr_ipato_enable,
  1055. &dev_attr_ipato_invert4,
  1056. &dev_attr_ipato_add4,
  1057. &dev_attr_ipato_del4,
  1058. #ifdef CONFIG_QETH_IPV6
  1059. &dev_attr_ipato_invert6,
  1060. &dev_attr_ipato_add6,
  1061. &dev_attr_ipato_del6,
  1062. #endif
  1063. NULL,
  1064. };
  1065. static struct attribute_group qeth_device_ipato_group = {
  1066. .name = "ipa_takeover",
  1067. .attrs = (struct attribute **)qeth_ipato_device_attrs,
  1068. };
  1069. static inline ssize_t
  1070. qeth_dev_vipa_add_show(char *buf, struct qeth_card *card,
  1071. enum qeth_prot_versions proto)
  1072. {
  1073. struct qeth_ipaddr *ipaddr;
  1074. char addr_str[40];
  1075. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1076. unsigned long flags;
  1077. int i = 0;
  1078. if (qeth_check_layer2(card))
  1079. return -EPERM;
  1080. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1081. entry_len += 2; /* \n + terminator */
  1082. spin_lock_irqsave(&card->ip_lock, flags);
  1083. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1084. if (ipaddr->proto != proto)
  1085. continue;
  1086. if (ipaddr->type != QETH_IP_TYPE_VIPA)
  1087. continue;
  1088. /* String must not be longer than PAGE_SIZE. So we check if
  1089. * string length gets near PAGE_SIZE. Then we can savely display
  1090. * the next IPv6 address (worst case, compared to IPv4) */
  1091. if ((PAGE_SIZE - i) <= entry_len)
  1092. break;
  1093. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1094. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1095. }
  1096. spin_unlock_irqrestore(&card->ip_lock, flags);
  1097. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1098. return i;
  1099. }
  1100. static ssize_t
  1101. qeth_dev_vipa_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1102. {
  1103. struct qeth_card *card = dev->driver_data;
  1104. if (!card)
  1105. return -EINVAL;
  1106. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV4);
  1107. }
  1108. static inline int
  1109. qeth_parse_vipae(const char* buf, enum qeth_prot_versions proto,
  1110. u8 *addr)
  1111. {
  1112. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1113. PRINT_WARN("Invalid IP address format!\n");
  1114. return -EINVAL;
  1115. }
  1116. return 0;
  1117. }
  1118. static inline ssize_t
  1119. qeth_dev_vipa_add_store(const char *buf, size_t count,
  1120. struct qeth_card *card, enum qeth_prot_versions proto)
  1121. {
  1122. u8 addr[16] = {0, };
  1123. int rc;
  1124. if (qeth_check_layer2(card))
  1125. return -EPERM;
  1126. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1127. return rc;
  1128. if ((rc = qeth_add_vipa(card, proto, addr)))
  1129. return rc;
  1130. return count;
  1131. }
  1132. static ssize_t
  1133. qeth_dev_vipa_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1134. {
  1135. struct qeth_card *card = dev->driver_data;
  1136. if (!card)
  1137. return -EINVAL;
  1138. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
  1139. }
  1140. static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
  1141. qeth_dev_vipa_add4_show,
  1142. qeth_dev_vipa_add4_store);
  1143. static inline ssize_t
  1144. qeth_dev_vipa_del_store(const char *buf, size_t count,
  1145. struct qeth_card *card, enum qeth_prot_versions proto)
  1146. {
  1147. u8 addr[16];
  1148. int rc;
  1149. if (qeth_check_layer2(card))
  1150. return -EPERM;
  1151. if ((rc = qeth_parse_vipae(buf, proto, addr)))
  1152. return rc;
  1153. qeth_del_vipa(card, proto, addr);
  1154. return count;
  1155. }
  1156. static ssize_t
  1157. qeth_dev_vipa_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1158. {
  1159. struct qeth_card *card = dev->driver_data;
  1160. if (!card)
  1161. return -EINVAL;
  1162. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
  1163. }
  1164. static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
  1165. qeth_dev_vipa_del4_store);
  1166. #ifdef CONFIG_QETH_IPV6
  1167. static ssize_t
  1168. qeth_dev_vipa_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1169. {
  1170. struct qeth_card *card = dev->driver_data;
  1171. if (!card)
  1172. return -EINVAL;
  1173. return qeth_dev_vipa_add_show(buf, card, QETH_PROT_IPV6);
  1174. }
  1175. static ssize_t
  1176. qeth_dev_vipa_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1177. {
  1178. struct qeth_card *card = dev->driver_data;
  1179. if (!card)
  1180. return -EINVAL;
  1181. return qeth_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
  1182. }
  1183. static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
  1184. qeth_dev_vipa_add6_show,
  1185. qeth_dev_vipa_add6_store);
  1186. static ssize_t
  1187. qeth_dev_vipa_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1188. {
  1189. struct qeth_card *card = dev->driver_data;
  1190. if (!card)
  1191. return -EINVAL;
  1192. if (qeth_check_layer2(card))
  1193. return -EPERM;
  1194. return qeth_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
  1195. }
  1196. static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
  1197. qeth_dev_vipa_del6_store);
  1198. #endif /* CONFIG_QETH_IPV6 */
  1199. static struct device_attribute * qeth_vipa_device_attrs[] = {
  1200. &dev_attr_vipa_add4,
  1201. &dev_attr_vipa_del4,
  1202. #ifdef CONFIG_QETH_IPV6
  1203. &dev_attr_vipa_add6,
  1204. &dev_attr_vipa_del6,
  1205. #endif
  1206. NULL,
  1207. };
  1208. static struct attribute_group qeth_device_vipa_group = {
  1209. .name = "vipa",
  1210. .attrs = (struct attribute **)qeth_vipa_device_attrs,
  1211. };
  1212. static inline ssize_t
  1213. qeth_dev_rxip_add_show(char *buf, struct qeth_card *card,
  1214. enum qeth_prot_versions proto)
  1215. {
  1216. struct qeth_ipaddr *ipaddr;
  1217. char addr_str[40];
  1218. int entry_len; /* length of 1 entry string, differs between v4 and v6 */
  1219. unsigned long flags;
  1220. int i = 0;
  1221. if (qeth_check_layer2(card))
  1222. return -EPERM;
  1223. entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
  1224. entry_len += 2; /* \n + terminator */
  1225. spin_lock_irqsave(&card->ip_lock, flags);
  1226. list_for_each_entry(ipaddr, &card->ip_list, entry){
  1227. if (ipaddr->proto != proto)
  1228. continue;
  1229. if (ipaddr->type != QETH_IP_TYPE_RXIP)
  1230. continue;
  1231. /* String must not be longer than PAGE_SIZE. So we check if
  1232. * string length gets near PAGE_SIZE. Then we can savely display
  1233. * the next IPv6 address (worst case, compared to IPv4) */
  1234. if ((PAGE_SIZE - i) <= entry_len)
  1235. break;
  1236. qeth_ipaddr_to_string(proto, (const u8 *)&ipaddr->u, addr_str);
  1237. i += snprintf(buf + i, PAGE_SIZE - i, "%s\n", addr_str);
  1238. }
  1239. spin_unlock_irqrestore(&card->ip_lock, flags);
  1240. i += snprintf(buf + i, PAGE_SIZE - i, "\n");
  1241. return i;
  1242. }
  1243. static ssize_t
  1244. qeth_dev_rxip_add4_show(struct device *dev, struct device_attribute *attr, char *buf)
  1245. {
  1246. struct qeth_card *card = dev->driver_data;
  1247. if (!card)
  1248. return -EINVAL;
  1249. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV4);
  1250. }
  1251. static inline int
  1252. qeth_parse_rxipe(const char* buf, enum qeth_prot_versions proto,
  1253. u8 *addr)
  1254. {
  1255. if (qeth_string_to_ipaddr(buf, proto, addr)){
  1256. PRINT_WARN("Invalid IP address format!\n");
  1257. return -EINVAL;
  1258. }
  1259. return 0;
  1260. }
  1261. static inline ssize_t
  1262. qeth_dev_rxip_add_store(const char *buf, size_t count,
  1263. struct qeth_card *card, enum qeth_prot_versions proto)
  1264. {
  1265. u8 addr[16] = {0, };
  1266. int rc;
  1267. if (qeth_check_layer2(card))
  1268. return -EPERM;
  1269. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1270. return rc;
  1271. if ((rc = qeth_add_rxip(card, proto, addr)))
  1272. return rc;
  1273. return count;
  1274. }
  1275. static ssize_t
  1276. qeth_dev_rxip_add4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1277. {
  1278. struct qeth_card *card = dev->driver_data;
  1279. if (!card)
  1280. return -EINVAL;
  1281. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
  1282. }
  1283. static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
  1284. qeth_dev_rxip_add4_show,
  1285. qeth_dev_rxip_add4_store);
  1286. static inline ssize_t
  1287. qeth_dev_rxip_del_store(const char *buf, size_t count,
  1288. struct qeth_card *card, enum qeth_prot_versions proto)
  1289. {
  1290. u8 addr[16];
  1291. int rc;
  1292. if (qeth_check_layer2(card))
  1293. return -EPERM;
  1294. if ((rc = qeth_parse_rxipe(buf, proto, addr)))
  1295. return rc;
  1296. qeth_del_rxip(card, proto, addr);
  1297. return count;
  1298. }
  1299. static ssize_t
  1300. qeth_dev_rxip_del4_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1301. {
  1302. struct qeth_card *card = dev->driver_data;
  1303. if (!card)
  1304. return -EINVAL;
  1305. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
  1306. }
  1307. static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
  1308. qeth_dev_rxip_del4_store);
  1309. #ifdef CONFIG_QETH_IPV6
  1310. static ssize_t
  1311. qeth_dev_rxip_add6_show(struct device *dev, struct device_attribute *attr, char *buf)
  1312. {
  1313. struct qeth_card *card = dev->driver_data;
  1314. if (!card)
  1315. return -EINVAL;
  1316. return qeth_dev_rxip_add_show(buf, card, QETH_PROT_IPV6);
  1317. }
  1318. static ssize_t
  1319. qeth_dev_rxip_add6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1320. {
  1321. struct qeth_card *card = dev->driver_data;
  1322. if (!card)
  1323. return -EINVAL;
  1324. return qeth_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
  1325. }
  1326. static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
  1327. qeth_dev_rxip_add6_show,
  1328. qeth_dev_rxip_add6_store);
  1329. static ssize_t
  1330. qeth_dev_rxip_del6_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1331. {
  1332. struct qeth_card *card = dev->driver_data;
  1333. if (!card)
  1334. return -EINVAL;
  1335. return qeth_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
  1336. }
  1337. static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,
  1338. qeth_dev_rxip_del6_store);
  1339. #endif /* CONFIG_QETH_IPV6 */
  1340. static struct device_attribute * qeth_rxip_device_attrs[] = {
  1341. &dev_attr_rxip_add4,
  1342. &dev_attr_rxip_del4,
  1343. #ifdef CONFIG_QETH_IPV6
  1344. &dev_attr_rxip_add6,
  1345. &dev_attr_rxip_del6,
  1346. #endif
  1347. NULL,
  1348. };
  1349. static struct attribute_group qeth_device_rxip_group = {
  1350. .name = "rxip",
  1351. .attrs = (struct attribute **)qeth_rxip_device_attrs,
  1352. };
  1353. int
  1354. qeth_create_device_attributes(struct device *dev)
  1355. {
  1356. int ret;
  1357. struct qeth_card *card = dev->driver_data;
  1358. if (card->info.type == QETH_CARD_TYPE_OSN)
  1359. return sysfs_create_group(&dev->kobj,
  1360. &qeth_osn_device_attr_group);
  1361. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_attr_group)))
  1362. return ret;
  1363. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_ipato_group))){
  1364. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1365. return ret;
  1366. }
  1367. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_vipa_group))){
  1368. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1369. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1370. return ret;
  1371. }
  1372. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_rxip_group))){
  1373. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1374. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1375. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1376. }
  1377. if ((ret = sysfs_create_group(&dev->kobj, &qeth_device_blkt_group)))
  1378. return ret;
  1379. return ret;
  1380. }
  1381. void
  1382. qeth_remove_device_attributes(struct device *dev)
  1383. {
  1384. struct qeth_card *card = dev->driver_data;
  1385. if (card->info.type == QETH_CARD_TYPE_OSN)
  1386. return sysfs_remove_group(&dev->kobj,
  1387. &qeth_osn_device_attr_group);
  1388. sysfs_remove_group(&dev->kobj, &qeth_device_attr_group);
  1389. sysfs_remove_group(&dev->kobj, &qeth_device_ipato_group);
  1390. sysfs_remove_group(&dev->kobj, &qeth_device_vipa_group);
  1391. sysfs_remove_group(&dev->kobj, &qeth_device_rxip_group);
  1392. sysfs_remove_group(&dev->kobj, &qeth_device_blkt_group);
  1393. }
  1394. /**********************/
  1395. /* DRIVER ATTRIBUTES */
  1396. /**********************/
  1397. static ssize_t
  1398. qeth_driver_group_store(struct device_driver *ddrv, const char *buf,
  1399. size_t count)
  1400. {
  1401. const char *start, *end;
  1402. char bus_ids[3][BUS_ID_SIZE], *argv[3];
  1403. int i;
  1404. int err;
  1405. start = buf;
  1406. for (i = 0; i < 3; i++) {
  1407. static const char delim[] = { ',', ',', '\n' };
  1408. int len;
  1409. if (!(end = strchr(start, delim[i])))
  1410. return -EINVAL;
  1411. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
  1412. strncpy(bus_ids[i], start, len);
  1413. bus_ids[i][len] = '\0';
  1414. start = end + 1;
  1415. argv[i] = bus_ids[i];
  1416. }
  1417. err = ccwgroup_create(qeth_root_dev, qeth_ccwgroup_driver.driver_id,
  1418. &qeth_ccw_driver, 3, argv);
  1419. if (err)
  1420. return err;
  1421. else
  1422. return count;
  1423. }
  1424. static DRIVER_ATTR(group, 0200, 0, qeth_driver_group_store);
  1425. static ssize_t
  1426. qeth_driver_notifier_register_store(struct device_driver *ddrv, const char *buf,
  1427. size_t count)
  1428. {
  1429. int rc;
  1430. int signum;
  1431. char *tmp, *tmp2;
  1432. tmp = strsep((char **) &buf, "\n");
  1433. if (!strncmp(tmp, "unregister", 10)){
  1434. if ((rc = qeth_notifier_unregister(current)))
  1435. return rc;
  1436. return count;
  1437. }
  1438. signum = simple_strtoul(tmp, &tmp2, 10);
  1439. if ((signum < 0) || (signum > 32)){
  1440. PRINT_WARN("Signal number %d is out of range\n", signum);
  1441. return -EINVAL;
  1442. }
  1443. if ((rc = qeth_notifier_register(current, signum)))
  1444. return rc;
  1445. return count;
  1446. }
  1447. static DRIVER_ATTR(notifier_register, 0200, 0,
  1448. qeth_driver_notifier_register_store);
  1449. int
  1450. qeth_create_driver_attributes(void)
  1451. {
  1452. int rc;
  1453. if ((rc = driver_create_file(&qeth_ccwgroup_driver.driver,
  1454. &driver_attr_group)))
  1455. return rc;
  1456. return driver_create_file(&qeth_ccwgroup_driver.driver,
  1457. &driver_attr_notifier_register);
  1458. }
  1459. void
  1460. qeth_remove_driver_attributes(void)
  1461. {
  1462. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1463. &driver_attr_group);
  1464. driver_remove_file(&qeth_ccwgroup_driver.driver,
  1465. &driver_attr_notifier_register);
  1466. }