qeth_sys.c 44 KB

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