claw.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331
  1. /*
  2. * drivers/s390/net/claw.c
  3. * ESCON CLAW network driver
  4. *
  5. * Linux for zSeries version
  6. * Copyright (C) 2002,2005 IBM Corporation
  7. * Author(s) Original code written by:
  8. * Kazuo Iimura (iimura@jp.ibm.com)
  9. * Rewritten by
  10. * Andy Richter (richtera@us.ibm.com)
  11. * Marc Price (mwprice@us.ibm.com)
  12. *
  13. * sysfs parms:
  14. * group x.x.rrrr,x.x.wwww
  15. * read_buffer nnnnnnn
  16. * write_buffer nnnnnn
  17. * host_name aaaaaaaa
  18. * adapter_name aaaaaaaa
  19. * api_type aaaaaaaa
  20. *
  21. * eg.
  22. * group 0.0.0200 0.0.0201
  23. * read_buffer 25
  24. * write_buffer 20
  25. * host_name LINUX390
  26. * adapter_name RS6K
  27. * api_type TCPIP
  28. *
  29. * where
  30. *
  31. * The device id is decided by the order entries
  32. * are added to the group the first is claw0 the second claw1
  33. * up to CLAW_MAX_DEV
  34. *
  35. * rrrr - the first of 2 consecutive device addresses used for the
  36. * CLAW protocol.
  37. * The specified address is always used as the input (Read)
  38. * channel and the next address is used as the output channel.
  39. *
  40. * wwww - the second of 2 consecutive device addresses used for
  41. * the CLAW protocol.
  42. * The specified address is always used as the output
  43. * channel and the previous address is used as the input channel.
  44. *
  45. * read_buffer - specifies number of input buffers to allocate.
  46. * write_buffer - specifies number of output buffers to allocate.
  47. * host_name - host name
  48. * adaptor_name - adaptor name
  49. * api_type - API type TCPIP or API will be sent and expected
  50. * as ws_name
  51. *
  52. * Note the following requirements:
  53. * 1) host_name must match the configured adapter_name on the remote side
  54. * 2) adaptor_name must match the configured host name on the remote side
  55. *
  56. * Change History
  57. * 1.00 Initial release shipped
  58. * 1.10 Changes for Buffer allocation
  59. * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
  60. * 1.25 Added Packing support
  61. * 1.5
  62. */
  63. #include <asm/ccwdev.h>
  64. #include <asm/ccwgroup.h>
  65. #include <asm/debug.h>
  66. #include <asm/idals.h>
  67. #include <asm/io.h>
  68. #include <linux/bitops.h>
  69. #include <linux/ctype.h>
  70. #include <linux/delay.h>
  71. #include <linux/errno.h>
  72. #include <linux/if_arp.h>
  73. #include <linux/init.h>
  74. #include <linux/interrupt.h>
  75. #include <linux/ip.h>
  76. #include <linux/kernel.h>
  77. #include <linux/module.h>
  78. #include <linux/netdevice.h>
  79. #include <linux/etherdevice.h>
  80. #include <linux/proc_fs.h>
  81. #include <linux/sched.h>
  82. #include <linux/signal.h>
  83. #include <linux/skbuff.h>
  84. #include <linux/slab.h>
  85. #include <linux/string.h>
  86. #include <linux/tcp.h>
  87. #include <linux/timer.h>
  88. #include <linux/types.h>
  89. #include "cu3088.h"
  90. #include "claw.h"
  91. /*
  92. CLAW uses the s390dbf file system see claw_trace and claw_setup
  93. */
  94. static char debug_buffer[255];
  95. /**
  96. * Debug Facility Stuff
  97. */
  98. static debug_info_t *claw_dbf_setup;
  99. static debug_info_t *claw_dbf_trace;
  100. /**
  101. * CLAW Debug Facility functions
  102. */
  103. static void
  104. claw_unregister_debug_facility(void)
  105. {
  106. if (claw_dbf_setup)
  107. debug_unregister(claw_dbf_setup);
  108. if (claw_dbf_trace)
  109. debug_unregister(claw_dbf_trace);
  110. }
  111. static int
  112. claw_register_debug_facility(void)
  113. {
  114. claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
  115. claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
  116. if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
  117. claw_unregister_debug_facility();
  118. return -ENOMEM;
  119. }
  120. debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
  121. debug_set_level(claw_dbf_setup, 2);
  122. debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
  123. debug_set_level(claw_dbf_trace, 2);
  124. return 0;
  125. }
  126. static inline void
  127. claw_set_busy(struct net_device *dev)
  128. {
  129. ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
  130. eieio();
  131. }
  132. static inline void
  133. claw_clear_busy(struct net_device *dev)
  134. {
  135. clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
  136. netif_wake_queue(dev);
  137. eieio();
  138. }
  139. static inline int
  140. claw_check_busy(struct net_device *dev)
  141. {
  142. eieio();
  143. return ((struct claw_privbk *) dev->ml_priv)->tbusy;
  144. }
  145. static inline void
  146. claw_setbit_busy(int nr,struct net_device *dev)
  147. {
  148. netif_stop_queue(dev);
  149. set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
  150. }
  151. static inline void
  152. claw_clearbit_busy(int nr,struct net_device *dev)
  153. {
  154. clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
  155. netif_wake_queue(dev);
  156. }
  157. static inline int
  158. claw_test_and_setbit_busy(int nr,struct net_device *dev)
  159. {
  160. netif_stop_queue(dev);
  161. return test_and_set_bit(nr,
  162. (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
  163. }
  164. /* Functions for the DEV methods */
  165. static int claw_probe(struct ccwgroup_device *cgdev);
  166. static void claw_remove_device(struct ccwgroup_device *cgdev);
  167. static void claw_purge_skb_queue(struct sk_buff_head *q);
  168. static int claw_new_device(struct ccwgroup_device *cgdev);
  169. static int claw_shutdown_device(struct ccwgroup_device *cgdev);
  170. static int claw_tx(struct sk_buff *skb, struct net_device *dev);
  171. static int claw_change_mtu( struct net_device *dev, int new_mtu);
  172. static int claw_open(struct net_device *dev);
  173. static void claw_irq_handler(struct ccw_device *cdev,
  174. unsigned long intparm, struct irb *irb);
  175. static void claw_irq_tasklet ( unsigned long data );
  176. static int claw_release(struct net_device *dev);
  177. static void claw_write_retry ( struct chbk * p_ch );
  178. static void claw_write_next ( struct chbk * p_ch );
  179. static void claw_timer ( struct chbk * p_ch );
  180. /* Functions */
  181. static int add_claw_reads(struct net_device *dev,
  182. struct ccwbk* p_first, struct ccwbk* p_last);
  183. static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
  184. static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
  185. static int find_link(struct net_device *dev, char *host_name, char *ws_name );
  186. static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
  187. static int init_ccw_bk(struct net_device *dev);
  188. static void probe_error( struct ccwgroup_device *cgdev);
  189. static struct net_device_stats *claw_stats(struct net_device *dev);
  190. static int pages_to_order_of_mag(int num_of_pages);
  191. static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
  192. /* sysfs Functions */
  193. static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
  194. static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
  195. const char *buf, size_t count);
  196. static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
  197. static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
  198. const char *buf, size_t count);
  199. static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
  200. static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
  201. const char *buf, size_t count);
  202. static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  203. static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
  204. const char *buf, size_t count);
  205. static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
  206. static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
  207. const char *buf, size_t count);
  208. static int claw_add_files(struct device *dev);
  209. static void claw_remove_files(struct device *dev);
  210. /* Functions for System Validate */
  211. static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
  212. static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  213. __u8 correlator, __u8 rc , char *local_name, char *remote_name);
  214. static int claw_snd_conn_req(struct net_device *dev, __u8 link);
  215. static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
  216. static int claw_snd_sys_validate_rsp(struct net_device *dev,
  217. struct clawctl * p_ctl, __u32 return_code);
  218. static int claw_strt_conn_req(struct net_device *dev );
  219. static void claw_strt_read(struct net_device *dev, int lock);
  220. static void claw_strt_out_IO(struct net_device *dev);
  221. static void claw_free_wrt_buf(struct net_device *dev);
  222. /* Functions for unpack reads */
  223. static void unpack_read(struct net_device *dev);
  224. /* ccwgroup table */
  225. static struct ccwgroup_driver claw_group_driver = {
  226. .owner = THIS_MODULE,
  227. .name = "claw",
  228. .max_slaves = 2,
  229. .driver_id = 0xC3D3C1E6,
  230. .probe = claw_probe,
  231. .remove = claw_remove_device,
  232. .set_online = claw_new_device,
  233. .set_offline = claw_shutdown_device,
  234. };
  235. /*
  236. * Key functions
  237. */
  238. /*----------------------------------------------------------------*
  239. * claw_probe *
  240. * this function is called for each CLAW device. *
  241. *----------------------------------------------------------------*/
  242. static int
  243. claw_probe(struct ccwgroup_device *cgdev)
  244. {
  245. int rc;
  246. struct claw_privbk *privptr=NULL;
  247. CLAW_DBF_TEXT(2, setup, "probe");
  248. if (!get_device(&cgdev->dev))
  249. return -ENODEV;
  250. privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
  251. cgdev->dev.driver_data = privptr;
  252. if (privptr == NULL) {
  253. probe_error(cgdev);
  254. put_device(&cgdev->dev);
  255. CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
  256. return -ENOMEM;
  257. }
  258. privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
  259. privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
  260. if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
  261. probe_error(cgdev);
  262. put_device(&cgdev->dev);
  263. CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
  264. return -ENOMEM;
  265. }
  266. memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
  267. memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
  268. memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
  269. privptr->p_env->packing = 0;
  270. privptr->p_env->write_buffers = 5;
  271. privptr->p_env->read_buffers = 5;
  272. privptr->p_env->read_size = CLAW_FRAME_SIZE;
  273. privptr->p_env->write_size = CLAW_FRAME_SIZE;
  274. rc = claw_add_files(&cgdev->dev);
  275. if (rc) {
  276. probe_error(cgdev);
  277. put_device(&cgdev->dev);
  278. printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
  279. dev_name(&cgdev->cdev[0]->dev), __func__, __LINE__);
  280. CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
  281. return rc;
  282. }
  283. privptr->p_env->p_priv = privptr;
  284. cgdev->cdev[0]->handler = claw_irq_handler;
  285. cgdev->cdev[1]->handler = claw_irq_handler;
  286. CLAW_DBF_TEXT(2, setup, "prbext 0");
  287. return 0;
  288. } /* end of claw_probe */
  289. /*-------------------------------------------------------------------*
  290. * claw_tx *
  291. *-------------------------------------------------------------------*/
  292. static int
  293. claw_tx(struct sk_buff *skb, struct net_device *dev)
  294. {
  295. int rc;
  296. struct claw_privbk *privptr = dev->ml_priv;
  297. unsigned long saveflags;
  298. struct chbk *p_ch;
  299. CLAW_DBF_TEXT(4, trace, "claw_tx");
  300. p_ch=&privptr->channel[WRITE];
  301. if (skb == NULL) {
  302. privptr->stats.tx_dropped++;
  303. privptr->stats.tx_errors++;
  304. CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO);
  305. return -EIO;
  306. }
  307. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  308. rc=claw_hw_tx( skb, dev, 1 );
  309. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  310. CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
  311. return rc;
  312. } /* end of claw_tx */
  313. /*------------------------------------------------------------------*
  314. * pack the collect queue into an skb and return it *
  315. * If not packing just return the top skb from the queue *
  316. *------------------------------------------------------------------*/
  317. static struct sk_buff *
  318. claw_pack_skb(struct claw_privbk *privptr)
  319. {
  320. struct sk_buff *new_skb,*held_skb;
  321. struct chbk *p_ch = &privptr->channel[WRITE];
  322. struct claw_env *p_env = privptr->p_env;
  323. int pkt_cnt,pk_ind,so_far;
  324. new_skb = NULL; /* assume no dice */
  325. pkt_cnt = 0;
  326. CLAW_DBF_TEXT(4, trace, "PackSKBe");
  327. if (!skb_queue_empty(&p_ch->collect_queue)) {
  328. /* some data */
  329. held_skb = skb_dequeue(&p_ch->collect_queue);
  330. if (held_skb)
  331. dev_kfree_skb_any(held_skb);
  332. else
  333. return NULL;
  334. if (p_env->packing != DO_PACKED)
  335. return held_skb;
  336. /* get a new SKB we will pack at least one */
  337. new_skb = dev_alloc_skb(p_env->write_size);
  338. if (new_skb == NULL) {
  339. atomic_inc(&held_skb->users);
  340. skb_queue_head(&p_ch->collect_queue,held_skb);
  341. return NULL;
  342. }
  343. /* we have packed packet and a place to put it */
  344. pk_ind = 1;
  345. so_far = 0;
  346. new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
  347. while ((pk_ind) && (held_skb != NULL)) {
  348. if (held_skb->len+so_far <= p_env->write_size-8) {
  349. memcpy(skb_put(new_skb,held_skb->len),
  350. held_skb->data,held_skb->len);
  351. privptr->stats.tx_packets++;
  352. so_far += held_skb->len;
  353. pkt_cnt++;
  354. dev_kfree_skb_any(held_skb);
  355. held_skb = skb_dequeue(&p_ch->collect_queue);
  356. if (held_skb)
  357. atomic_dec(&held_skb->users);
  358. } else {
  359. pk_ind = 0;
  360. atomic_inc(&held_skb->users);
  361. skb_queue_head(&p_ch->collect_queue,held_skb);
  362. }
  363. }
  364. }
  365. CLAW_DBF_TEXT(4, trace, "PackSKBx");
  366. return new_skb;
  367. }
  368. /*-------------------------------------------------------------------*
  369. * claw_change_mtu *
  370. * *
  371. *-------------------------------------------------------------------*/
  372. static int
  373. claw_change_mtu(struct net_device *dev, int new_mtu)
  374. {
  375. struct claw_privbk *privptr = dev->ml_priv;
  376. int buff_size;
  377. CLAW_DBF_TEXT(4, trace, "setmtu");
  378. buff_size = privptr->p_env->write_size;
  379. if ((new_mtu < 60) || (new_mtu > buff_size)) {
  380. return -EINVAL;
  381. }
  382. dev->mtu = new_mtu;
  383. return 0;
  384. } /* end of claw_change_mtu */
  385. /*-------------------------------------------------------------------*
  386. * claw_open *
  387. * *
  388. *-------------------------------------------------------------------*/
  389. static int
  390. claw_open(struct net_device *dev)
  391. {
  392. int rc;
  393. int i;
  394. unsigned long saveflags=0;
  395. unsigned long parm;
  396. struct claw_privbk *privptr;
  397. DECLARE_WAITQUEUE(wait, current);
  398. struct timer_list timer;
  399. struct ccwbk *p_buf;
  400. CLAW_DBF_TEXT(4, trace, "open");
  401. privptr = (struct claw_privbk *)dev->ml_priv;
  402. /* allocate and initialize CCW blocks */
  403. if (privptr->buffs_alloc == 0) {
  404. rc=init_ccw_bk(dev);
  405. if (rc) {
  406. CLAW_DBF_TEXT(2, trace, "openmem");
  407. return -ENOMEM;
  408. }
  409. }
  410. privptr->system_validate_comp=0;
  411. privptr->release_pend=0;
  412. if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  413. privptr->p_env->read_size=DEF_PACK_BUFSIZE;
  414. privptr->p_env->write_size=DEF_PACK_BUFSIZE;
  415. privptr->p_env->packing=PACKING_ASK;
  416. } else {
  417. privptr->p_env->packing=0;
  418. privptr->p_env->read_size=CLAW_FRAME_SIZE;
  419. privptr->p_env->write_size=CLAW_FRAME_SIZE;
  420. }
  421. claw_set_busy(dev);
  422. tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
  423. (unsigned long) &privptr->channel[READ]);
  424. for ( i = 0; i < 2; i++) {
  425. CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
  426. init_waitqueue_head(&privptr->channel[i].wait);
  427. /* skb_queue_head_init(&p_ch->io_queue); */
  428. if (i == WRITE)
  429. skb_queue_head_init(
  430. &privptr->channel[WRITE].collect_queue);
  431. privptr->channel[i].flag_a = 0;
  432. privptr->channel[i].IO_active = 0;
  433. privptr->channel[i].flag &= ~CLAW_TIMER;
  434. init_timer(&timer);
  435. timer.function = (void *)claw_timer;
  436. timer.data = (unsigned long)(&privptr->channel[i]);
  437. timer.expires = jiffies + 15*HZ;
  438. add_timer(&timer);
  439. spin_lock_irqsave(get_ccwdev_lock(
  440. privptr->channel[i].cdev), saveflags);
  441. parm = (unsigned long) &privptr->channel[i];
  442. privptr->channel[i].claw_state = CLAW_START_HALT_IO;
  443. rc = 0;
  444. add_wait_queue(&privptr->channel[i].wait, &wait);
  445. rc = ccw_device_halt(
  446. (struct ccw_device *)privptr->channel[i].cdev,parm);
  447. set_current_state(TASK_INTERRUPTIBLE);
  448. spin_unlock_irqrestore(
  449. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  450. schedule();
  451. set_current_state(TASK_RUNNING);
  452. remove_wait_queue(&privptr->channel[i].wait, &wait);
  453. if(rc != 0)
  454. ccw_check_return_code(privptr->channel[i].cdev, rc);
  455. if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
  456. del_timer(&timer);
  457. }
  458. if ((((privptr->channel[READ].last_dstat |
  459. privptr->channel[WRITE].last_dstat) &
  460. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
  461. (((privptr->channel[READ].flag |
  462. privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
  463. printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
  464. CLAW_DBF_TEXT(2, trace, "notrdy");
  465. for ( i = 0; i < 2; i++) {
  466. spin_lock_irqsave(
  467. get_ccwdev_lock(privptr->channel[i].cdev),
  468. saveflags);
  469. parm = (unsigned long) &privptr->channel[i];
  470. privptr->channel[i].claw_state = CLAW_STOP;
  471. rc = ccw_device_halt(
  472. (struct ccw_device *)&privptr->channel[i].cdev,
  473. parm);
  474. spin_unlock_irqrestore(
  475. get_ccwdev_lock(privptr->channel[i].cdev),
  476. saveflags);
  477. if (rc != 0) {
  478. ccw_check_return_code(
  479. privptr->channel[i].cdev, rc);
  480. }
  481. }
  482. free_pages((unsigned long)privptr->p_buff_ccw,
  483. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  484. if (privptr->p_env->read_size < PAGE_SIZE) {
  485. free_pages((unsigned long)privptr->p_buff_read,
  486. (int)pages_to_order_of_mag(
  487. privptr->p_buff_read_num));
  488. }
  489. else {
  490. p_buf=privptr->p_read_active_first;
  491. while (p_buf!=NULL) {
  492. free_pages((unsigned long)p_buf->p_buffer,
  493. (int)pages_to_order_of_mag(
  494. privptr->p_buff_pages_perread ));
  495. p_buf=p_buf->next;
  496. }
  497. }
  498. if (privptr->p_env->write_size < PAGE_SIZE ) {
  499. free_pages((unsigned long)privptr->p_buff_write,
  500. (int)pages_to_order_of_mag(
  501. privptr->p_buff_write_num));
  502. }
  503. else {
  504. p_buf=privptr->p_write_active_first;
  505. while (p_buf!=NULL) {
  506. free_pages((unsigned long)p_buf->p_buffer,
  507. (int)pages_to_order_of_mag(
  508. privptr->p_buff_pages_perwrite ));
  509. p_buf=p_buf->next;
  510. }
  511. }
  512. privptr->buffs_alloc = 0;
  513. privptr->channel[READ].flag= 0x00;
  514. privptr->channel[WRITE].flag = 0x00;
  515. privptr->p_buff_ccw=NULL;
  516. privptr->p_buff_read=NULL;
  517. privptr->p_buff_write=NULL;
  518. claw_clear_busy(dev);
  519. CLAW_DBF_TEXT(2, trace, "open EIO");
  520. return -EIO;
  521. }
  522. /* Send SystemValidate command */
  523. claw_clear_busy(dev);
  524. CLAW_DBF_TEXT(4, trace, "openok");
  525. return 0;
  526. } /* end of claw_open */
  527. /*-------------------------------------------------------------------*
  528. * *
  529. * claw_irq_handler *
  530. * *
  531. *--------------------------------------------------------------------*/
  532. static void
  533. claw_irq_handler(struct ccw_device *cdev,
  534. unsigned long intparm, struct irb *irb)
  535. {
  536. struct chbk *p_ch = NULL;
  537. struct claw_privbk *privptr = NULL;
  538. struct net_device *dev = NULL;
  539. struct claw_env *p_env;
  540. struct chbk *p_ch_r=NULL;
  541. CLAW_DBF_TEXT(4, trace, "clawirq");
  542. /* Bypass all 'unsolicited interrupts' */
  543. if (!cdev->dev.driver_data) {
  544. printk(KERN_WARNING "claw: unsolicited interrupt for device:"
  545. "%s received c-%02x d-%02x\n",
  546. dev_name(&cdev->dev), irb->scsw.cmd.cstat,
  547. irb->scsw.cmd.dstat);
  548. CLAW_DBF_TEXT(2, trace, "badirq");
  549. return;
  550. }
  551. privptr = (struct claw_privbk *)cdev->dev.driver_data;
  552. /* Try to extract channel from driver data. */
  553. if (privptr->channel[READ].cdev == cdev)
  554. p_ch = &privptr->channel[READ];
  555. else if (privptr->channel[WRITE].cdev == cdev)
  556. p_ch = &privptr->channel[WRITE];
  557. else {
  558. printk(KERN_WARNING "claw: Can't determine channel for "
  559. "interrupt, device %s\n", dev_name(&cdev->dev));
  560. CLAW_DBF_TEXT(2, trace, "badchan");
  561. return;
  562. }
  563. CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
  564. dev = (struct net_device *) (p_ch->ndev);
  565. p_env=privptr->p_env;
  566. /* Copy interruption response block. */
  567. memcpy(p_ch->irb, irb, sizeof(struct irb));
  568. /* Check for good subchannel return code, otherwise info message */
  569. if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
  570. printk(KERN_INFO "%s: subchannel check for device: %04x -"
  571. " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
  572. dev->name, p_ch->devno,
  573. irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
  574. irb->scsw.cmd.cpa);
  575. CLAW_DBF_TEXT(2, trace, "chanchk");
  576. /* return; */
  577. }
  578. /* Check the reason-code of a unit check */
  579. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
  580. ccw_check_unit_check(p_ch, irb->ecw[0]);
  581. /* State machine to bring the connection up, down and to restart */
  582. p_ch->last_dstat = irb->scsw.cmd.dstat;
  583. switch (p_ch->claw_state) {
  584. case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
  585. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  586. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  587. (p_ch->irb->scsw.cmd.stctl ==
  588. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
  589. return;
  590. wake_up(&p_ch->wait); /* wake up claw_release */
  591. CLAW_DBF_TEXT(4, trace, "stop");
  592. return;
  593. case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
  594. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  595. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  596. (p_ch->irb->scsw.cmd.stctl ==
  597. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  598. CLAW_DBF_TEXT(4, trace, "haltio");
  599. return;
  600. }
  601. if (p_ch->flag == CLAW_READ) {
  602. p_ch->claw_state = CLAW_START_READ;
  603. wake_up(&p_ch->wait); /* wake claw_open (READ)*/
  604. } else if (p_ch->flag == CLAW_WRITE) {
  605. p_ch->claw_state = CLAW_START_WRITE;
  606. /* send SYSTEM_VALIDATE */
  607. claw_strt_read(dev, LOCK_NO);
  608. claw_send_control(dev,
  609. SYSTEM_VALIDATE_REQUEST,
  610. 0, 0, 0,
  611. p_env->host_name,
  612. p_env->adapter_name);
  613. } else {
  614. printk(KERN_WARNING "claw: unsolicited "
  615. "interrupt for device:"
  616. "%s received c-%02x d-%02x\n",
  617. dev_name(&cdev->dev),
  618. irb->scsw.cmd.cstat,
  619. irb->scsw.cmd.dstat);
  620. return;
  621. }
  622. CLAW_DBF_TEXT(4, trace, "haltio");
  623. return;
  624. case CLAW_START_READ:
  625. CLAW_DBF_TEXT(4, trace, "ReadIRQ");
  626. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  627. clear_bit(0, (void *)&p_ch->IO_active);
  628. if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
  629. (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
  630. (p_ch->irb->ecw[0]) == 0) {
  631. privptr->stats.rx_errors++;
  632. printk(KERN_INFO "%s: Restart is "
  633. "required after remote "
  634. "side recovers \n",
  635. dev->name);
  636. }
  637. CLAW_DBF_TEXT(4, trace, "notrdy");
  638. return;
  639. }
  640. if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
  641. (p_ch->irb->scsw.cmd.dstat == 0)) {
  642. if (test_and_set_bit(CLAW_BH_ACTIVE,
  643. (void *)&p_ch->flag_a) == 0)
  644. tasklet_schedule(&p_ch->tasklet);
  645. else
  646. CLAW_DBF_TEXT(4, trace, "PCINoBH");
  647. CLAW_DBF_TEXT(4, trace, "PCI_read");
  648. return;
  649. }
  650. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  651. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  652. (p_ch->irb->scsw.cmd.stctl ==
  653. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  654. CLAW_DBF_TEXT(4, trace, "SPend_rd");
  655. return;
  656. }
  657. clear_bit(0, (void *)&p_ch->IO_active);
  658. claw_clearbit_busy(TB_RETRY, dev);
  659. if (test_and_set_bit(CLAW_BH_ACTIVE,
  660. (void *)&p_ch->flag_a) == 0)
  661. tasklet_schedule(&p_ch->tasklet);
  662. else
  663. CLAW_DBF_TEXT(4, trace, "RdBHAct");
  664. CLAW_DBF_TEXT(4, trace, "RdIRQXit");
  665. return;
  666. case CLAW_START_WRITE:
  667. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  668. printk(KERN_INFO "%s: Unit Check Occured in "
  669. "write channel\n", dev->name);
  670. clear_bit(0, (void *)&p_ch->IO_active);
  671. if (p_ch->irb->ecw[0] & 0x80) {
  672. printk(KERN_INFO "%s: Resetting Event "
  673. "occurred:\n", dev->name);
  674. init_timer(&p_ch->timer);
  675. p_ch->timer.function =
  676. (void *)claw_write_retry;
  677. p_ch->timer.data = (unsigned long)p_ch;
  678. p_ch->timer.expires = jiffies + 10*HZ;
  679. add_timer(&p_ch->timer);
  680. printk(KERN_INFO "%s: write connection "
  681. "restarting\n", dev->name);
  682. }
  683. CLAW_DBF_TEXT(4, trace, "rstrtwrt");
  684. return;
  685. }
  686. if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
  687. clear_bit(0, (void *)&p_ch->IO_active);
  688. printk(KERN_INFO "%s: Unit Exception "
  689. "Occured in write channel\n",
  690. dev->name);
  691. }
  692. if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
  693. (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
  694. (p_ch->irb->scsw.cmd.stctl ==
  695. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
  696. CLAW_DBF_TEXT(4, trace, "writeUE");
  697. return;
  698. }
  699. clear_bit(0, (void *)&p_ch->IO_active);
  700. if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
  701. claw_write_next(p_ch);
  702. claw_clearbit_busy(TB_TX, dev);
  703. claw_clear_busy(dev);
  704. }
  705. p_ch_r = (struct chbk *)&privptr->channel[READ];
  706. if (test_and_set_bit(CLAW_BH_ACTIVE,
  707. (void *)&p_ch_r->flag_a) == 0)
  708. tasklet_schedule(&p_ch_r->tasklet);
  709. CLAW_DBF_TEXT(4, trace, "StWtExit");
  710. return;
  711. default:
  712. printk(KERN_WARNING "%s: wrong selection code - irq "
  713. "state=%d\n", dev->name, p_ch->claw_state);
  714. CLAW_DBF_TEXT(2, trace, "badIRQ");
  715. return;
  716. }
  717. } /* end of claw_irq_handler */
  718. /*-------------------------------------------------------------------*
  719. * claw_irq_tasklet *
  720. * *
  721. *--------------------------------------------------------------------*/
  722. static void
  723. claw_irq_tasklet ( unsigned long data )
  724. {
  725. struct chbk * p_ch;
  726. struct net_device *dev;
  727. struct claw_privbk * privptr;
  728. p_ch = (struct chbk *) data;
  729. dev = (struct net_device *)p_ch->ndev;
  730. CLAW_DBF_TEXT(4, trace, "IRQtask");
  731. privptr = (struct claw_privbk *)dev->ml_priv;
  732. unpack_read(dev);
  733. clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
  734. CLAW_DBF_TEXT(4, trace, "TskletXt");
  735. return;
  736. } /* end of claw_irq_bh */
  737. /*-------------------------------------------------------------------*
  738. * claw_release *
  739. * *
  740. *--------------------------------------------------------------------*/
  741. static int
  742. claw_release(struct net_device *dev)
  743. {
  744. int rc;
  745. int i;
  746. unsigned long saveflags;
  747. unsigned long parm;
  748. struct claw_privbk *privptr;
  749. DECLARE_WAITQUEUE(wait, current);
  750. struct ccwbk* p_this_ccw;
  751. struct ccwbk* p_buf;
  752. if (!dev)
  753. return 0;
  754. privptr = (struct claw_privbk *)dev->ml_priv;
  755. if (!privptr)
  756. return 0;
  757. CLAW_DBF_TEXT(4, trace, "release");
  758. privptr->release_pend=1;
  759. claw_setbit_busy(TB_STOP,dev);
  760. for ( i = 1; i >=0 ; i--) {
  761. spin_lock_irqsave(
  762. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  763. /* del_timer(&privptr->channel[READ].timer); */
  764. privptr->channel[i].claw_state = CLAW_STOP;
  765. privptr->channel[i].IO_active = 0;
  766. parm = (unsigned long) &privptr->channel[i];
  767. if (i == WRITE)
  768. claw_purge_skb_queue(
  769. &privptr->channel[WRITE].collect_queue);
  770. rc = ccw_device_halt (privptr->channel[i].cdev, parm);
  771. if (privptr->system_validate_comp==0x00) /* never opened? */
  772. init_waitqueue_head(&privptr->channel[i].wait);
  773. add_wait_queue(&privptr->channel[i].wait, &wait);
  774. set_current_state(TASK_INTERRUPTIBLE);
  775. spin_unlock_irqrestore(
  776. get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
  777. schedule();
  778. set_current_state(TASK_RUNNING);
  779. remove_wait_queue(&privptr->channel[i].wait, &wait);
  780. if (rc != 0) {
  781. ccw_check_return_code(privptr->channel[i].cdev, rc);
  782. }
  783. }
  784. if (privptr->pk_skb != NULL) {
  785. dev_kfree_skb_any(privptr->pk_skb);
  786. privptr->pk_skb = NULL;
  787. }
  788. if(privptr->buffs_alloc != 1) {
  789. CLAW_DBF_TEXT(4, trace, "none2fre");
  790. return 0;
  791. }
  792. CLAW_DBF_TEXT(4, trace, "freebufs");
  793. if (privptr->p_buff_ccw != NULL) {
  794. free_pages((unsigned long)privptr->p_buff_ccw,
  795. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  796. }
  797. CLAW_DBF_TEXT(4, trace, "freeread");
  798. if (privptr->p_env->read_size < PAGE_SIZE) {
  799. if (privptr->p_buff_read != NULL) {
  800. free_pages((unsigned long)privptr->p_buff_read,
  801. (int)pages_to_order_of_mag(privptr->p_buff_read_num));
  802. }
  803. }
  804. else {
  805. p_buf=privptr->p_read_active_first;
  806. while (p_buf!=NULL) {
  807. free_pages((unsigned long)p_buf->p_buffer,
  808. (int)pages_to_order_of_mag(
  809. privptr->p_buff_pages_perread ));
  810. p_buf=p_buf->next;
  811. }
  812. }
  813. CLAW_DBF_TEXT(4, trace, "freewrit");
  814. if (privptr->p_env->write_size < PAGE_SIZE ) {
  815. free_pages((unsigned long)privptr->p_buff_write,
  816. (int)pages_to_order_of_mag(privptr->p_buff_write_num));
  817. }
  818. else {
  819. p_buf=privptr->p_write_active_first;
  820. while (p_buf!=NULL) {
  821. free_pages((unsigned long)p_buf->p_buffer,
  822. (int)pages_to_order_of_mag(
  823. privptr->p_buff_pages_perwrite ));
  824. p_buf=p_buf->next;
  825. }
  826. }
  827. CLAW_DBF_TEXT(4, trace, "clearptr");
  828. privptr->buffs_alloc = 0;
  829. privptr->p_buff_ccw=NULL;
  830. privptr->p_buff_read=NULL;
  831. privptr->p_buff_write=NULL;
  832. privptr->system_validate_comp=0;
  833. privptr->release_pend=0;
  834. /* Remove any writes that were pending and reset all reads */
  835. p_this_ccw=privptr->p_read_active_first;
  836. while (p_this_ccw!=NULL) {
  837. p_this_ccw->header.length=0xffff;
  838. p_this_ccw->header.opcode=0xff;
  839. p_this_ccw->header.flag=0x00;
  840. p_this_ccw=p_this_ccw->next;
  841. }
  842. while (privptr->p_write_active_first!=NULL) {
  843. p_this_ccw=privptr->p_write_active_first;
  844. p_this_ccw->header.flag=CLAW_PENDING;
  845. privptr->p_write_active_first=p_this_ccw->next;
  846. p_this_ccw->next=privptr->p_write_free_chain;
  847. privptr->p_write_free_chain=p_this_ccw;
  848. ++privptr->write_free_count;
  849. }
  850. privptr->p_write_active_last=NULL;
  851. privptr->mtc_logical_link = -1;
  852. privptr->mtc_skipping = 1;
  853. privptr->mtc_offset=0;
  854. if (((privptr->channel[READ].last_dstat |
  855. privptr->channel[WRITE].last_dstat) &
  856. ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
  857. printk(KERN_WARNING "%s: channel problems during close - "
  858. "read: %02x - write: %02x\n",
  859. dev->name,
  860. privptr->channel[READ].last_dstat,
  861. privptr->channel[WRITE].last_dstat);
  862. CLAW_DBF_TEXT(2, trace, "badclose");
  863. }
  864. CLAW_DBF_TEXT(4, trace, "rlsexit");
  865. return 0;
  866. } /* end of claw_release */
  867. /*-------------------------------------------------------------------*
  868. * claw_write_retry *
  869. * *
  870. *--------------------------------------------------------------------*/
  871. static void
  872. claw_write_retry ( struct chbk *p_ch )
  873. {
  874. struct net_device *dev=p_ch->ndev;
  875. CLAW_DBF_TEXT(4, trace, "w_retry");
  876. if (p_ch->claw_state == CLAW_STOP) {
  877. return;
  878. }
  879. claw_strt_out_IO( dev );
  880. CLAW_DBF_TEXT(4, trace, "rtry_xit");
  881. return;
  882. } /* end of claw_write_retry */
  883. /*-------------------------------------------------------------------*
  884. * claw_write_next *
  885. * *
  886. *--------------------------------------------------------------------*/
  887. static void
  888. claw_write_next ( struct chbk * p_ch )
  889. {
  890. struct net_device *dev;
  891. struct claw_privbk *privptr=NULL;
  892. struct sk_buff *pk_skb;
  893. int rc;
  894. CLAW_DBF_TEXT(4, trace, "claw_wrt");
  895. if (p_ch->claw_state == CLAW_STOP)
  896. return;
  897. dev = (struct net_device *) p_ch->ndev;
  898. privptr = (struct claw_privbk *) dev->ml_priv;
  899. claw_free_wrt_buf( dev );
  900. if ((privptr->write_free_count > 0) &&
  901. !skb_queue_empty(&p_ch->collect_queue)) {
  902. pk_skb = claw_pack_skb(privptr);
  903. while (pk_skb != NULL) {
  904. rc = claw_hw_tx( pk_skb, dev,1);
  905. if (privptr->write_free_count > 0) {
  906. pk_skb = claw_pack_skb(privptr);
  907. } else
  908. pk_skb = NULL;
  909. }
  910. }
  911. if (privptr->p_write_active_first!=NULL) {
  912. claw_strt_out_IO(dev);
  913. }
  914. return;
  915. } /* end of claw_write_next */
  916. /*-------------------------------------------------------------------*
  917. * *
  918. * claw_timer *
  919. *--------------------------------------------------------------------*/
  920. static void
  921. claw_timer ( struct chbk * p_ch )
  922. {
  923. CLAW_DBF_TEXT(4, trace, "timer");
  924. p_ch->flag |= CLAW_TIMER;
  925. wake_up(&p_ch->wait);
  926. return;
  927. } /* end of claw_timer */
  928. /*
  929. *
  930. * functions
  931. */
  932. /*-------------------------------------------------------------------*
  933. * *
  934. * pages_to_order_of_mag *
  935. * *
  936. * takes a number of pages from 1 to 512 and returns the *
  937. * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
  938. * of magnitude get_free_pages() has an upper order of 9 *
  939. *--------------------------------------------------------------------*/
  940. static int
  941. pages_to_order_of_mag(int num_of_pages)
  942. {
  943. int order_of_mag=1; /* assume 2 pages */
  944. int nump=2;
  945. CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
  946. if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
  947. /* 512 pages = 2Meg on 4k page systems */
  948. if (num_of_pages >= 512) {return 9; }
  949. /* we have two or more pages order is at least 1 */
  950. for (nump=2 ;nump <= 512;nump*=2) {
  951. if (num_of_pages <= nump)
  952. break;
  953. order_of_mag +=1;
  954. }
  955. if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
  956. CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
  957. return order_of_mag;
  958. }
  959. /*-------------------------------------------------------------------*
  960. * *
  961. * add_claw_reads *
  962. * *
  963. *--------------------------------------------------------------------*/
  964. static int
  965. add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
  966. struct ccwbk* p_last)
  967. {
  968. struct claw_privbk *privptr;
  969. struct ccw1 temp_ccw;
  970. struct endccw * p_end;
  971. CLAW_DBF_TEXT(4, trace, "addreads");
  972. privptr = dev->ml_priv;
  973. p_end = privptr->p_end_ccw;
  974. /* first CCW and last CCW contains a new set of read channel programs
  975. * to apend the running channel programs
  976. */
  977. if ( p_first==NULL) {
  978. CLAW_DBF_TEXT(4, trace, "addexit");
  979. return 0;
  980. }
  981. /* set up ending CCW sequence for this segment */
  982. if (p_end->read1) {
  983. p_end->read1=0x00; /* second ending CCW is now active */
  984. /* reset ending CCWs and setup TIC CCWs */
  985. p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  986. p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  987. p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
  988. p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
  989. p_end->read2_nop2.cda=0;
  990. p_end->read2_nop2.count=1;
  991. }
  992. else {
  993. p_end->read1=0x01; /* first ending CCW is now active */
  994. /* reset ending CCWs and setup TIC CCWs */
  995. p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  996. p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  997. p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
  998. p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
  999. p_end->read1_nop2.cda=0;
  1000. p_end->read1_nop2.count=1;
  1001. }
  1002. if ( privptr-> p_read_active_first ==NULL ) {
  1003. privptr-> p_read_active_first= p_first; /* set new first */
  1004. privptr-> p_read_active_last = p_last; /* set new last */
  1005. }
  1006. else {
  1007. /* set up TIC ccw */
  1008. temp_ccw.cda= (__u32)__pa(&p_first->read);
  1009. temp_ccw.count=0;
  1010. temp_ccw.flags=0;
  1011. temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
  1012. if (p_end->read1) {
  1013. /* first set of CCW's is chained to the new read */
  1014. /* chain, so the second set is chained to the active chain. */
  1015. /* Therefore modify the second set to point to the new */
  1016. /* read chain set up TIC CCWs */
  1017. /* make sure we update the CCW so channel doesn't fetch it */
  1018. /* when it's only half done */
  1019. memcpy( &p_end->read2_nop2, &temp_ccw ,
  1020. sizeof(struct ccw1));
  1021. privptr->p_read_active_last->r_TIC_1.cda=
  1022. (__u32)__pa(&p_first->read);
  1023. privptr->p_read_active_last->r_TIC_2.cda=
  1024. (__u32)__pa(&p_first->read);
  1025. }
  1026. else {
  1027. /* make sure we update the CCW so channel doesn't */
  1028. /* fetch it when it is only half done */
  1029. memcpy( &p_end->read1_nop2, &temp_ccw ,
  1030. sizeof(struct ccw1));
  1031. privptr->p_read_active_last->r_TIC_1.cda=
  1032. (__u32)__pa(&p_first->read);
  1033. privptr->p_read_active_last->r_TIC_2.cda=
  1034. (__u32)__pa(&p_first->read);
  1035. }
  1036. /* chain in new set of blocks */
  1037. privptr->p_read_active_last->next = p_first;
  1038. privptr->p_read_active_last=p_last;
  1039. } /* end of if ( privptr-> p_read_active_first ==NULL) */
  1040. CLAW_DBF_TEXT(4, trace, "addexit");
  1041. return 0;
  1042. } /* end of add_claw_reads */
  1043. /*-------------------------------------------------------------------*
  1044. * ccw_check_return_code *
  1045. * *
  1046. *-------------------------------------------------------------------*/
  1047. static void
  1048. ccw_check_return_code(struct ccw_device *cdev, int return_code)
  1049. {
  1050. CLAW_DBF_TEXT(4, trace, "ccwret");
  1051. if (return_code != 0) {
  1052. switch (return_code) {
  1053. case -EBUSY: /* BUSY is a transient state no action needed */
  1054. break;
  1055. case -ENODEV:
  1056. printk(KERN_EMERG "%s: Missing device called "
  1057. "for IO ENODEV\n", dev_name(&cdev->dev));
  1058. break;
  1059. case -EIO:
  1060. printk(KERN_EMERG "%s: Status pending... EIO \n",
  1061. dev_name(&cdev->dev));
  1062. break;
  1063. case -EINVAL:
  1064. printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
  1065. dev_name(&cdev->dev));
  1066. break;
  1067. default:
  1068. printk(KERN_EMERG "%s: Unknown error in "
  1069. "Do_IO %d\n", dev_name(&cdev->dev),
  1070. return_code);
  1071. }
  1072. }
  1073. CLAW_DBF_TEXT(4, trace, "ccwret");
  1074. } /* end of ccw_check_return_code */
  1075. /*-------------------------------------------------------------------*
  1076. * ccw_check_unit_check *
  1077. *--------------------------------------------------------------------*/
  1078. static void
  1079. ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
  1080. {
  1081. struct net_device *ndev = p_ch->ndev;
  1082. CLAW_DBF_TEXT(4, trace, "unitchek");
  1083. printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
  1084. ndev->name, sense);
  1085. if (sense & 0x40) {
  1086. if (sense & 0x01) {
  1087. printk(KERN_WARNING "%s: Interface disconnect or "
  1088. "Selective reset "
  1089. "occurred (remote side)\n", ndev->name);
  1090. }
  1091. else {
  1092. printk(KERN_WARNING "%s: System reset occured"
  1093. " (remote side)\n", ndev->name);
  1094. }
  1095. }
  1096. else if (sense & 0x20) {
  1097. if (sense & 0x04) {
  1098. printk(KERN_WARNING "%s: Data-streaming "
  1099. "timeout)\n", ndev->name);
  1100. }
  1101. else {
  1102. printk(KERN_WARNING "%s: Data-transfer parity"
  1103. " error\n", ndev->name);
  1104. }
  1105. }
  1106. else if (sense & 0x10) {
  1107. if (sense & 0x20) {
  1108. printk(KERN_WARNING "%s: Hardware malfunction "
  1109. "(remote side)\n", ndev->name);
  1110. }
  1111. else {
  1112. printk(KERN_WARNING "%s: read-data parity error "
  1113. "(remote side)\n", ndev->name);
  1114. }
  1115. }
  1116. } /* end of ccw_check_unit_check */
  1117. /*-------------------------------------------------------------------*
  1118. * find_link *
  1119. *--------------------------------------------------------------------*/
  1120. static int
  1121. find_link(struct net_device *dev, char *host_name, char *ws_name )
  1122. {
  1123. struct claw_privbk *privptr;
  1124. struct claw_env *p_env;
  1125. int rc=0;
  1126. CLAW_DBF_TEXT(2, setup, "findlink");
  1127. privptr = dev->ml_priv;
  1128. p_env=privptr->p_env;
  1129. switch (p_env->packing)
  1130. {
  1131. case PACKING_ASK:
  1132. if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
  1133. (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
  1134. rc = EINVAL;
  1135. break;
  1136. case DO_PACKED:
  1137. case PACK_SEND:
  1138. if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
  1139. (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
  1140. rc = EINVAL;
  1141. break;
  1142. default:
  1143. if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
  1144. (memcmp(p_env->api_type , ws_name, 8)!=0))
  1145. rc = EINVAL;
  1146. break;
  1147. }
  1148. return 0;
  1149. } /* end of find_link */
  1150. /*-------------------------------------------------------------------*
  1151. * claw_hw_tx *
  1152. * *
  1153. * *
  1154. *-------------------------------------------------------------------*/
  1155. static int
  1156. claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
  1157. {
  1158. int rc=0;
  1159. struct claw_privbk *privptr;
  1160. struct ccwbk *p_this_ccw;
  1161. struct ccwbk *p_first_ccw;
  1162. struct ccwbk *p_last_ccw;
  1163. __u32 numBuffers;
  1164. signed long len_of_data;
  1165. unsigned long bytesInThisBuffer;
  1166. unsigned char *pDataAddress;
  1167. struct endccw *pEnd;
  1168. struct ccw1 tempCCW;
  1169. struct chbk *p_ch;
  1170. struct claw_env *p_env;
  1171. int lock;
  1172. struct clawph *pk_head;
  1173. struct chbk *ch;
  1174. CLAW_DBF_TEXT(4, trace, "hw_tx");
  1175. privptr = (struct claw_privbk *)(dev->ml_priv);
  1176. p_ch=(struct chbk *)&privptr->channel[WRITE];
  1177. p_env =privptr->p_env;
  1178. claw_free_wrt_buf(dev); /* Clean up free chain if posible */
  1179. /* scan the write queue to free any completed write packets */
  1180. p_first_ccw=NULL;
  1181. p_last_ccw=NULL;
  1182. if ((p_env->packing >= PACK_SEND) &&
  1183. (skb->cb[1] != 'P')) {
  1184. skb_push(skb,sizeof(struct clawph));
  1185. pk_head=(struct clawph *)skb->data;
  1186. pk_head->len=skb->len-sizeof(struct clawph);
  1187. if (pk_head->len%4) {
  1188. pk_head->len+= 4-(pk_head->len%4);
  1189. skb_pad(skb,4-(pk_head->len%4));
  1190. skb_put(skb,4-(pk_head->len%4));
  1191. }
  1192. if (p_env->packing == DO_PACKED)
  1193. pk_head->link_num = linkid;
  1194. else
  1195. pk_head->link_num = 0;
  1196. pk_head->flag = 0x00;
  1197. skb_pad(skb,4);
  1198. skb->cb[1] = 'P';
  1199. }
  1200. if (linkid == 0) {
  1201. if (claw_check_busy(dev)) {
  1202. if (privptr->write_free_count!=0) {
  1203. claw_clear_busy(dev);
  1204. }
  1205. else {
  1206. claw_strt_out_IO(dev );
  1207. claw_free_wrt_buf( dev );
  1208. if (privptr->write_free_count==0) {
  1209. ch = &privptr->channel[WRITE];
  1210. atomic_inc(&skb->users);
  1211. skb_queue_tail(&ch->collect_queue, skb);
  1212. goto Done;
  1213. }
  1214. else {
  1215. claw_clear_busy(dev);
  1216. }
  1217. }
  1218. }
  1219. /* tx lock */
  1220. if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
  1221. ch = &privptr->channel[WRITE];
  1222. atomic_inc(&skb->users);
  1223. skb_queue_tail(&ch->collect_queue, skb);
  1224. claw_strt_out_IO(dev );
  1225. rc=-EBUSY;
  1226. goto Done2;
  1227. }
  1228. }
  1229. /* See how many write buffers are required to hold this data */
  1230. numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
  1231. /* If that number of buffers isn't available, give up for now */
  1232. if (privptr->write_free_count < numBuffers ||
  1233. privptr->p_write_free_chain == NULL ) {
  1234. claw_setbit_busy(TB_NOBUFFER,dev);
  1235. ch = &privptr->channel[WRITE];
  1236. atomic_inc(&skb->users);
  1237. skb_queue_tail(&ch->collect_queue, skb);
  1238. CLAW_DBF_TEXT(2, trace, "clawbusy");
  1239. goto Done2;
  1240. }
  1241. pDataAddress=skb->data;
  1242. len_of_data=skb->len;
  1243. while (len_of_data > 0) {
  1244. p_this_ccw=privptr->p_write_free_chain; /* get a block */
  1245. if (p_this_ccw == NULL) { /* lost the race */
  1246. ch = &privptr->channel[WRITE];
  1247. atomic_inc(&skb->users);
  1248. skb_queue_tail(&ch->collect_queue, skb);
  1249. goto Done2;
  1250. }
  1251. privptr->p_write_free_chain=p_this_ccw->next;
  1252. p_this_ccw->next=NULL;
  1253. --privptr->write_free_count; /* -1 */
  1254. bytesInThisBuffer=len_of_data;
  1255. memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
  1256. len_of_data-=bytesInThisBuffer;
  1257. pDataAddress+=(unsigned long)bytesInThisBuffer;
  1258. /* setup write CCW */
  1259. p_this_ccw->write.cmd_code = (linkid * 8) +1;
  1260. if (len_of_data>0) {
  1261. p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
  1262. }
  1263. p_this_ccw->write.count=bytesInThisBuffer;
  1264. /* now add to end of this chain */
  1265. if (p_first_ccw==NULL) {
  1266. p_first_ccw=p_this_ccw;
  1267. }
  1268. if (p_last_ccw!=NULL) {
  1269. p_last_ccw->next=p_this_ccw;
  1270. /* set up TIC ccws */
  1271. p_last_ccw->w_TIC_1.cda=
  1272. (__u32)__pa(&p_this_ccw->write);
  1273. }
  1274. p_last_ccw=p_this_ccw; /* save new last block */
  1275. }
  1276. /* FirstCCW and LastCCW now contain a new set of write channel
  1277. * programs to append to the running channel program
  1278. */
  1279. if (p_first_ccw!=NULL) {
  1280. /* setup ending ccw sequence for this segment */
  1281. pEnd=privptr->p_end_ccw;
  1282. if (pEnd->write1) {
  1283. pEnd->write1=0x00; /* second end ccw is now active */
  1284. /* set up Tic CCWs */
  1285. p_last_ccw->w_TIC_1.cda=
  1286. (__u32)__pa(&pEnd->write2_nop1);
  1287. pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1288. pEnd->write2_nop2.flags =
  1289. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1290. pEnd->write2_nop2.cda=0;
  1291. pEnd->write2_nop2.count=1;
  1292. }
  1293. else { /* end of if (pEnd->write1)*/
  1294. pEnd->write1=0x01; /* first end ccw is now active */
  1295. /* set up Tic CCWs */
  1296. p_last_ccw->w_TIC_1.cda=
  1297. (__u32)__pa(&pEnd->write1_nop1);
  1298. pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1299. pEnd->write1_nop2.flags =
  1300. CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1301. pEnd->write1_nop2.cda=0;
  1302. pEnd->write1_nop2.count=1;
  1303. } /* end if if (pEnd->write1) */
  1304. if (privptr->p_write_active_first==NULL ) {
  1305. privptr->p_write_active_first=p_first_ccw;
  1306. privptr->p_write_active_last=p_last_ccw;
  1307. }
  1308. else {
  1309. /* set up Tic CCWs */
  1310. tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
  1311. tempCCW.count=0;
  1312. tempCCW.flags=0;
  1313. tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
  1314. if (pEnd->write1) {
  1315. /*
  1316. * first set of ending CCW's is chained to the new write
  1317. * chain, so the second set is chained to the active chain
  1318. * Therefore modify the second set to point the new write chain.
  1319. * make sure we update the CCW atomically
  1320. * so channel does not fetch it when it's only half done
  1321. */
  1322. memcpy( &pEnd->write2_nop2, &tempCCW ,
  1323. sizeof(struct ccw1));
  1324. privptr->p_write_active_last->w_TIC_1.cda=
  1325. (__u32)__pa(&p_first_ccw->write);
  1326. }
  1327. else {
  1328. /*make sure we update the CCW atomically
  1329. *so channel does not fetch it when it's only half done
  1330. */
  1331. memcpy(&pEnd->write1_nop2, &tempCCW ,
  1332. sizeof(struct ccw1));
  1333. privptr->p_write_active_last->w_TIC_1.cda=
  1334. (__u32)__pa(&p_first_ccw->write);
  1335. } /* end if if (pEnd->write1) */
  1336. privptr->p_write_active_last->next=p_first_ccw;
  1337. privptr->p_write_active_last=p_last_ccw;
  1338. }
  1339. } /* endif (p_first_ccw!=NULL) */
  1340. dev_kfree_skb_any(skb);
  1341. if (linkid==0) {
  1342. lock=LOCK_NO;
  1343. }
  1344. else {
  1345. lock=LOCK_YES;
  1346. }
  1347. claw_strt_out_IO(dev );
  1348. /* if write free count is zero , set NOBUFFER */
  1349. if (privptr->write_free_count==0) {
  1350. claw_setbit_busy(TB_NOBUFFER,dev);
  1351. }
  1352. Done2:
  1353. claw_clearbit_busy(TB_TX,dev);
  1354. Done:
  1355. return(rc);
  1356. } /* end of claw_hw_tx */
  1357. /*-------------------------------------------------------------------*
  1358. * *
  1359. * init_ccw_bk *
  1360. * *
  1361. *--------------------------------------------------------------------*/
  1362. static int
  1363. init_ccw_bk(struct net_device *dev)
  1364. {
  1365. __u32 ccw_blocks_required;
  1366. __u32 ccw_blocks_perpage;
  1367. __u32 ccw_pages_required;
  1368. __u32 claw_reads_perpage=1;
  1369. __u32 claw_read_pages;
  1370. __u32 claw_writes_perpage=1;
  1371. __u32 claw_write_pages;
  1372. void *p_buff=NULL;
  1373. struct ccwbk*p_free_chain;
  1374. struct ccwbk*p_buf;
  1375. struct ccwbk*p_last_CCWB;
  1376. struct ccwbk*p_first_CCWB;
  1377. struct endccw *p_endccw=NULL;
  1378. addr_t real_address;
  1379. struct claw_privbk *privptr = dev->ml_priv;
  1380. struct clawh *pClawH=NULL;
  1381. addr_t real_TIC_address;
  1382. int i,j;
  1383. CLAW_DBF_TEXT(4, trace, "init_ccw");
  1384. /* initialize statistics field */
  1385. privptr->active_link_ID=0;
  1386. /* initialize ccwbk pointers */
  1387. privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
  1388. privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
  1389. privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
  1390. privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
  1391. privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
  1392. privptr->p_end_ccw=NULL; /* pointer to ending ccw */
  1393. privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
  1394. privptr->buffs_alloc = 0;
  1395. memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
  1396. memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
  1397. /* initialize free write ccwbk counter */
  1398. privptr->write_free_count=0; /* number of free bufs on write chain */
  1399. p_last_CCWB = NULL;
  1400. p_first_CCWB= NULL;
  1401. /*
  1402. * We need 1 CCW block for each read buffer, 1 for each
  1403. * write buffer, plus 1 for ClawSignalBlock
  1404. */
  1405. ccw_blocks_required =
  1406. privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
  1407. /*
  1408. * compute number of CCW blocks that will fit in a page
  1409. */
  1410. ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
  1411. ccw_pages_required=
  1412. DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
  1413. /*
  1414. * read and write sizes are set by 2 constants in claw.h
  1415. * 4k and 32k. Unpacked values other than 4k are not going to
  1416. * provide good performance. With packing buffers support 32k
  1417. * buffers are used.
  1418. */
  1419. if (privptr->p_env->read_size < PAGE_SIZE) {
  1420. claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
  1421. claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
  1422. claw_reads_perpage);
  1423. }
  1424. else { /* > or equal */
  1425. privptr->p_buff_pages_perread =
  1426. DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
  1427. claw_read_pages = privptr->p_env->read_buffers *
  1428. privptr->p_buff_pages_perread;
  1429. }
  1430. if (privptr->p_env->write_size < PAGE_SIZE) {
  1431. claw_writes_perpage =
  1432. PAGE_SIZE / privptr->p_env->write_size;
  1433. claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
  1434. claw_writes_perpage);
  1435. }
  1436. else { /* > or equal */
  1437. privptr->p_buff_pages_perwrite =
  1438. DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
  1439. claw_write_pages = privptr->p_env->write_buffers *
  1440. privptr->p_buff_pages_perwrite;
  1441. }
  1442. /*
  1443. * allocate ccw_pages_required
  1444. */
  1445. if (privptr->p_buff_ccw==NULL) {
  1446. privptr->p_buff_ccw=
  1447. (void *)__get_free_pages(__GFP_DMA,
  1448. (int)pages_to_order_of_mag(ccw_pages_required ));
  1449. if (privptr->p_buff_ccw==NULL) {
  1450. return -ENOMEM;
  1451. }
  1452. privptr->p_buff_ccw_num=ccw_pages_required;
  1453. }
  1454. memset(privptr->p_buff_ccw, 0x00,
  1455. privptr->p_buff_ccw_num * PAGE_SIZE);
  1456. /*
  1457. * obtain ending ccw block address
  1458. *
  1459. */
  1460. privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
  1461. real_address = (__u32)__pa(privptr->p_end_ccw);
  1462. /* Initialize ending CCW block */
  1463. p_endccw=privptr->p_end_ccw;
  1464. p_endccw->real=real_address;
  1465. p_endccw->write1=0x00;
  1466. p_endccw->read1=0x00;
  1467. /* write1_nop1 */
  1468. p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1469. p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1470. p_endccw->write1_nop1.count = 1;
  1471. p_endccw->write1_nop1.cda = 0;
  1472. /* write1_nop2 */
  1473. p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1474. p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1475. p_endccw->write1_nop2.count = 1;
  1476. p_endccw->write1_nop2.cda = 0;
  1477. /* write2_nop1 */
  1478. p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1479. p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1480. p_endccw->write2_nop1.count = 1;
  1481. p_endccw->write2_nop1.cda = 0;
  1482. /* write2_nop2 */
  1483. p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1484. p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1485. p_endccw->write2_nop2.count = 1;
  1486. p_endccw->write2_nop2.cda = 0;
  1487. /* read1_nop1 */
  1488. p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1489. p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1490. p_endccw->read1_nop1.count = 1;
  1491. p_endccw->read1_nop1.cda = 0;
  1492. /* read1_nop2 */
  1493. p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1494. p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1495. p_endccw->read1_nop2.count = 1;
  1496. p_endccw->read1_nop2.cda = 0;
  1497. /* read2_nop1 */
  1498. p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
  1499. p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1500. p_endccw->read2_nop1.count = 1;
  1501. p_endccw->read2_nop1.cda = 0;
  1502. /* read2_nop2 */
  1503. p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
  1504. p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
  1505. p_endccw->read2_nop2.count = 1;
  1506. p_endccw->read2_nop2.cda = 0;
  1507. /*
  1508. * Build a chain of CCWs
  1509. *
  1510. */
  1511. p_buff=privptr->p_buff_ccw;
  1512. p_free_chain=NULL;
  1513. for (i=0 ; i < ccw_pages_required; i++ ) {
  1514. real_address = (__u32)__pa(p_buff);
  1515. p_buf=p_buff;
  1516. for (j=0 ; j < ccw_blocks_perpage ; j++) {
  1517. p_buf->next = p_free_chain;
  1518. p_free_chain = p_buf;
  1519. p_buf->real=(__u32)__pa(p_buf);
  1520. ++p_buf;
  1521. }
  1522. p_buff+=PAGE_SIZE;
  1523. }
  1524. /*
  1525. * Initialize ClawSignalBlock
  1526. *
  1527. */
  1528. if (privptr->p_claw_signal_blk==NULL) {
  1529. privptr->p_claw_signal_blk=p_free_chain;
  1530. p_free_chain=p_free_chain->next;
  1531. pClawH=(struct clawh *)privptr->p_claw_signal_blk;
  1532. pClawH->length=0xffff;
  1533. pClawH->opcode=0xff;
  1534. pClawH->flag=CLAW_BUSY;
  1535. }
  1536. /*
  1537. * allocate write_pages_required and add to free chain
  1538. */
  1539. if (privptr->p_buff_write==NULL) {
  1540. if (privptr->p_env->write_size < PAGE_SIZE) {
  1541. privptr->p_buff_write=
  1542. (void *)__get_free_pages(__GFP_DMA,
  1543. (int)pages_to_order_of_mag(claw_write_pages ));
  1544. if (privptr->p_buff_write==NULL) {
  1545. privptr->p_buff_ccw=NULL;
  1546. return -ENOMEM;
  1547. }
  1548. /*
  1549. * Build CLAW write free chain
  1550. *
  1551. */
  1552. memset(privptr->p_buff_write, 0x00,
  1553. ccw_pages_required * PAGE_SIZE);
  1554. privptr->p_write_free_chain=NULL;
  1555. p_buff=privptr->p_buff_write;
  1556. for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
  1557. p_buf = p_free_chain; /* get a CCW */
  1558. p_free_chain = p_buf->next;
  1559. p_buf->next =privptr->p_write_free_chain;
  1560. privptr->p_write_free_chain = p_buf;
  1561. p_buf-> p_buffer = (struct clawbuf *)p_buff;
  1562. p_buf-> write.cda = (__u32)__pa(p_buff);
  1563. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1564. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1565. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1566. p_buf-> w_read_FF.count = 1;
  1567. p_buf-> w_read_FF.cda =
  1568. (__u32)__pa(&p_buf-> header.flag);
  1569. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1570. p_buf-> w_TIC_1.flags = 0;
  1571. p_buf-> w_TIC_1.count = 0;
  1572. if (((unsigned long)p_buff+privptr->p_env->write_size) >=
  1573. ((unsigned long)(p_buff+2*
  1574. (privptr->p_env->write_size) -1) & PAGE_MASK)) {
  1575. p_buff= p_buff+privptr->p_env->write_size;
  1576. }
  1577. }
  1578. }
  1579. else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
  1580. {
  1581. privptr->p_write_free_chain=NULL;
  1582. for (i = 0; i< privptr->p_env->write_buffers ; i++) {
  1583. p_buff=(void *)__get_free_pages(__GFP_DMA,
  1584. (int)pages_to_order_of_mag(
  1585. privptr->p_buff_pages_perwrite) );
  1586. if (p_buff==NULL) {
  1587. free_pages((unsigned long)privptr->p_buff_ccw,
  1588. (int)pages_to_order_of_mag(
  1589. privptr->p_buff_ccw_num));
  1590. privptr->p_buff_ccw=NULL;
  1591. p_buf=privptr->p_buff_write;
  1592. while (p_buf!=NULL) {
  1593. free_pages((unsigned long)
  1594. p_buf->p_buffer,
  1595. (int)pages_to_order_of_mag(
  1596. privptr->p_buff_pages_perwrite));
  1597. p_buf=p_buf->next;
  1598. }
  1599. return -ENOMEM;
  1600. } /* Error on get_pages */
  1601. memset(p_buff, 0x00, privptr->p_env->write_size );
  1602. p_buf = p_free_chain;
  1603. p_free_chain = p_buf->next;
  1604. p_buf->next = privptr->p_write_free_chain;
  1605. privptr->p_write_free_chain = p_buf;
  1606. privptr->p_buff_write = p_buf;
  1607. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1608. p_buf-> write.cda = (__u32)__pa(p_buff);
  1609. p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1610. p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1611. p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1612. p_buf-> w_read_FF.count = 1;
  1613. p_buf-> w_read_FF.cda =
  1614. (__u32)__pa(&p_buf-> header.flag);
  1615. p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1616. p_buf-> w_TIC_1.flags = 0;
  1617. p_buf-> w_TIC_1.count = 0;
  1618. } /* for all write_buffers */
  1619. } /* else buffers are PAGE_SIZE or bigger */
  1620. }
  1621. privptr->p_buff_write_num=claw_write_pages;
  1622. privptr->write_free_count=privptr->p_env->write_buffers;
  1623. /*
  1624. * allocate read_pages_required and chain to free chain
  1625. */
  1626. if (privptr->p_buff_read==NULL) {
  1627. if (privptr->p_env->read_size < PAGE_SIZE) {
  1628. privptr->p_buff_read=
  1629. (void *)__get_free_pages(__GFP_DMA,
  1630. (int)pages_to_order_of_mag(claw_read_pages) );
  1631. if (privptr->p_buff_read==NULL) {
  1632. free_pages((unsigned long)privptr->p_buff_ccw,
  1633. (int)pages_to_order_of_mag(
  1634. privptr->p_buff_ccw_num));
  1635. /* free the write pages size is < page size */
  1636. free_pages((unsigned long)privptr->p_buff_write,
  1637. (int)pages_to_order_of_mag(
  1638. privptr->p_buff_write_num));
  1639. privptr->p_buff_ccw=NULL;
  1640. privptr->p_buff_write=NULL;
  1641. return -ENOMEM;
  1642. }
  1643. memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
  1644. privptr->p_buff_read_num=claw_read_pages;
  1645. /*
  1646. * Build CLAW read free chain
  1647. *
  1648. */
  1649. p_buff=privptr->p_buff_read;
  1650. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  1651. p_buf = p_free_chain;
  1652. p_free_chain = p_buf->next;
  1653. if (p_last_CCWB==NULL) {
  1654. p_buf->next=NULL;
  1655. real_TIC_address=0;
  1656. p_last_CCWB=p_buf;
  1657. }
  1658. else {
  1659. p_buf->next=p_first_CCWB;
  1660. real_TIC_address=
  1661. (__u32)__pa(&p_first_CCWB -> read );
  1662. }
  1663. p_first_CCWB=p_buf;
  1664. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1665. /* initialize read command */
  1666. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  1667. p_buf-> read.cda = (__u32)__pa(p_buff);
  1668. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1669. p_buf-> read.count = privptr->p_env->read_size;
  1670. /* initialize read_h command */
  1671. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  1672. p_buf-> read_h.cda =
  1673. (__u32)__pa(&(p_buf->header));
  1674. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1675. p_buf-> read_h.count = sizeof(struct clawh);
  1676. /* initialize Signal command */
  1677. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  1678. p_buf-> signal.cda =
  1679. (__u32)__pa(&(pClawH->flag));
  1680. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1681. p_buf-> signal.count = 1;
  1682. /* initialize r_TIC_1 command */
  1683. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1684. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  1685. p_buf-> r_TIC_1.flags = 0;
  1686. p_buf-> r_TIC_1.count = 0;
  1687. /* initialize r_read_FF command */
  1688. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1689. p_buf-> r_read_FF.cda =
  1690. (__u32)__pa(&(pClawH->flag));
  1691. p_buf-> r_read_FF.flags =
  1692. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  1693. p_buf-> r_read_FF.count = 1;
  1694. /* initialize r_TIC_2 */
  1695. memcpy(&p_buf->r_TIC_2,
  1696. &p_buf->r_TIC_1, sizeof(struct ccw1));
  1697. /* initialize Header */
  1698. p_buf->header.length=0xffff;
  1699. p_buf->header.opcode=0xff;
  1700. p_buf->header.flag=CLAW_PENDING;
  1701. if (((unsigned long)p_buff+privptr->p_env->read_size) >=
  1702. ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
  1703. & PAGE_MASK) ) {
  1704. p_buff= p_buff+privptr->p_env->read_size;
  1705. }
  1706. else {
  1707. p_buff=
  1708. (void *)((unsigned long)
  1709. (p_buff+2*(privptr->p_env->read_size) -1)
  1710. & PAGE_MASK) ;
  1711. }
  1712. } /* for read_buffers */
  1713. } /* read_size < PAGE_SIZE */
  1714. else { /* read Size >= PAGE_SIZE */
  1715. for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
  1716. p_buff = (void *)__get_free_pages(__GFP_DMA,
  1717. (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
  1718. if (p_buff==NULL) {
  1719. free_pages((unsigned long)privptr->p_buff_ccw,
  1720. (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
  1721. /* free the write pages */
  1722. p_buf=privptr->p_buff_write;
  1723. while (p_buf!=NULL) {
  1724. free_pages((unsigned long)p_buf->p_buffer,
  1725. (int)pages_to_order_of_mag(
  1726. privptr->p_buff_pages_perwrite ));
  1727. p_buf=p_buf->next;
  1728. }
  1729. /* free any read pages already alloc */
  1730. p_buf=privptr->p_buff_read;
  1731. while (p_buf!=NULL) {
  1732. free_pages((unsigned long)p_buf->p_buffer,
  1733. (int)pages_to_order_of_mag(
  1734. privptr->p_buff_pages_perread ));
  1735. p_buf=p_buf->next;
  1736. }
  1737. privptr->p_buff_ccw=NULL;
  1738. privptr->p_buff_write=NULL;
  1739. return -ENOMEM;
  1740. }
  1741. memset(p_buff, 0x00, privptr->p_env->read_size);
  1742. p_buf = p_free_chain;
  1743. privptr->p_buff_read = p_buf;
  1744. p_free_chain = p_buf->next;
  1745. if (p_last_CCWB==NULL) {
  1746. p_buf->next=NULL;
  1747. real_TIC_address=0;
  1748. p_last_CCWB=p_buf;
  1749. }
  1750. else {
  1751. p_buf->next=p_first_CCWB;
  1752. real_TIC_address=
  1753. (addr_t)__pa(
  1754. &p_first_CCWB -> read );
  1755. }
  1756. p_first_CCWB=p_buf;
  1757. /* save buff address */
  1758. p_buf->p_buffer=(struct clawbuf *)p_buff;
  1759. /* initialize read command */
  1760. p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
  1761. p_buf-> read.cda = (__u32)__pa(p_buff);
  1762. p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1763. p_buf-> read.count = privptr->p_env->read_size;
  1764. /* initialize read_h command */
  1765. p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
  1766. p_buf-> read_h.cda =
  1767. (__u32)__pa(&(p_buf->header));
  1768. p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1769. p_buf-> read_h.count = sizeof(struct clawh);
  1770. /* initialize Signal command */
  1771. p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
  1772. p_buf-> signal.cda =
  1773. (__u32)__pa(&(pClawH->flag));
  1774. p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
  1775. p_buf-> signal.count = 1;
  1776. /* initialize r_TIC_1 command */
  1777. p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
  1778. p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
  1779. p_buf-> r_TIC_1.flags = 0;
  1780. p_buf-> r_TIC_1.count = 0;
  1781. /* initialize r_read_FF command */
  1782. p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
  1783. p_buf-> r_read_FF.cda =
  1784. (__u32)__pa(&(pClawH->flag));
  1785. p_buf-> r_read_FF.flags =
  1786. CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
  1787. p_buf-> r_read_FF.count = 1;
  1788. /* initialize r_TIC_2 */
  1789. memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
  1790. sizeof(struct ccw1));
  1791. /* initialize Header */
  1792. p_buf->header.length=0xffff;
  1793. p_buf->header.opcode=0xff;
  1794. p_buf->header.flag=CLAW_PENDING;
  1795. } /* For read_buffers */
  1796. } /* read_size >= PAGE_SIZE */
  1797. } /* pBuffread = NULL */
  1798. add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
  1799. privptr->buffs_alloc = 1;
  1800. return 0;
  1801. } /* end of init_ccw_bk */
  1802. /*-------------------------------------------------------------------*
  1803. * *
  1804. * probe_error *
  1805. * *
  1806. *--------------------------------------------------------------------*/
  1807. static void
  1808. probe_error( struct ccwgroup_device *cgdev)
  1809. {
  1810. struct claw_privbk *privptr;
  1811. CLAW_DBF_TEXT(4, trace, "proberr");
  1812. privptr = (struct claw_privbk *) cgdev->dev.driver_data;
  1813. if (privptr != NULL) {
  1814. cgdev->dev.driver_data = NULL;
  1815. kfree(privptr->p_env);
  1816. kfree(privptr->p_mtc_envelope);
  1817. kfree(privptr);
  1818. }
  1819. } /* probe_error */
  1820. /*-------------------------------------------------------------------*
  1821. * claw_process_control *
  1822. * *
  1823. * *
  1824. *--------------------------------------------------------------------*/
  1825. static int
  1826. claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
  1827. {
  1828. struct clawbuf *p_buf;
  1829. struct clawctl ctlbk;
  1830. struct clawctl *p_ctlbk;
  1831. char temp_host_name[8];
  1832. char temp_ws_name[8];
  1833. struct claw_privbk *privptr;
  1834. struct claw_env *p_env;
  1835. struct sysval *p_sysval;
  1836. struct conncmd *p_connect=NULL;
  1837. int rc;
  1838. struct chbk *p_ch = NULL;
  1839. struct device *tdev;
  1840. CLAW_DBF_TEXT(2, setup, "clw_cntl");
  1841. udelay(1000); /* Wait a ms for the control packets to
  1842. *catch up to each other */
  1843. privptr = dev->ml_priv;
  1844. p_env=privptr->p_env;
  1845. tdev = &privptr->channel[READ].cdev->dev;
  1846. memcpy( &temp_host_name, p_env->host_name, 8);
  1847. memcpy( &temp_ws_name, p_env->adapter_name , 8);
  1848. printk(KERN_INFO "%s: CLAW device %.8s: "
  1849. "Received Control Packet\n",
  1850. dev->name, temp_ws_name);
  1851. if (privptr->release_pend==1) {
  1852. return 0;
  1853. }
  1854. p_buf=p_ccw->p_buffer;
  1855. p_ctlbk=&ctlbk;
  1856. if (p_env->packing == DO_PACKED) { /* packing in progress?*/
  1857. memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
  1858. } else {
  1859. memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
  1860. }
  1861. switch (p_ctlbk->command)
  1862. {
  1863. case SYSTEM_VALIDATE_REQUEST:
  1864. if (p_ctlbk->version != CLAW_VERSION_ID) {
  1865. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1866. CLAW_RC_WRONG_VERSION);
  1867. printk("%s: %d is wrong version id. "
  1868. "Expected %d\n",
  1869. dev->name, p_ctlbk->version,
  1870. CLAW_VERSION_ID);
  1871. }
  1872. p_sysval = (struct sysval *)&(p_ctlbk->data);
  1873. printk("%s: Recv Sys Validate Request: "
  1874. "Vers=%d,link_id=%d,Corr=%d,WS name=%."
  1875. "8s,Host name=%.8s\n",
  1876. dev->name, p_ctlbk->version,
  1877. p_ctlbk->linkid,
  1878. p_ctlbk->correlator,
  1879. p_sysval->WS_name,
  1880. p_sysval->host_name);
  1881. if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
  1882. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1883. CLAW_RC_NAME_MISMATCH);
  1884. CLAW_DBF_TEXT(2, setup, "HSTBAD");
  1885. CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
  1886. CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
  1887. printk(KERN_INFO "%s: Host name mismatch\n",
  1888. dev->name);
  1889. printk(KERN_INFO "%s: Received :%s: "
  1890. "expected :%s: \n",
  1891. dev->name,
  1892. p_sysval->host_name,
  1893. temp_host_name);
  1894. }
  1895. if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
  1896. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1897. CLAW_RC_NAME_MISMATCH);
  1898. CLAW_DBF_TEXT(2, setup, "WSNBAD");
  1899. CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
  1900. CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
  1901. printk(KERN_INFO "%s: WS name mismatch\n",
  1902. dev->name);
  1903. printk(KERN_INFO "%s: Received :%s: "
  1904. "expected :%s: \n",
  1905. dev->name,
  1906. p_sysval->WS_name,
  1907. temp_ws_name);
  1908. }
  1909. if ((p_sysval->write_frame_size < p_env->write_size) &&
  1910. (p_env->packing == 0)) {
  1911. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1912. CLAW_RC_HOST_RCV_TOO_SMALL);
  1913. printk(KERN_INFO "%s: host write size is too "
  1914. "small\n", dev->name);
  1915. CLAW_DBF_TEXT(2, setup, "wrtszbad");
  1916. }
  1917. if ((p_sysval->read_frame_size < p_env->read_size) &&
  1918. (p_env->packing == 0)) {
  1919. claw_snd_sys_validate_rsp(dev, p_ctlbk,
  1920. CLAW_RC_HOST_RCV_TOO_SMALL);
  1921. printk(KERN_INFO "%s: host read size is too "
  1922. "small\n", dev->name);
  1923. CLAW_DBF_TEXT(2, setup, "rdsizbad");
  1924. }
  1925. claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
  1926. printk(KERN_INFO "%s: CLAW device %.8s: System validate "
  1927. "completed.\n", dev->name, temp_ws_name);
  1928. printk("%s: sys Validate Rsize:%d Wsize:%d\n", dev->name,
  1929. p_sysval->read_frame_size, p_sysval->write_frame_size);
  1930. privptr->system_validate_comp = 1;
  1931. if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
  1932. p_env->packing = PACKING_ASK;
  1933. claw_strt_conn_req(dev);
  1934. break;
  1935. case SYSTEM_VALIDATE_RESPONSE:
  1936. p_sysval = (struct sysval *)&(p_ctlbk->data);
  1937. printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
  1938. "WS name=%.8s,Host name=%.8s\n",
  1939. dev->name,
  1940. p_ctlbk->version,
  1941. p_ctlbk->correlator,
  1942. p_ctlbk->rc,
  1943. p_sysval->WS_name,
  1944. p_sysval->host_name);
  1945. switch (p_ctlbk->rc) {
  1946. case 0:
  1947. printk(KERN_INFO "%s: CLAW device "
  1948. "%.8s: System validate "
  1949. "completed.\n",
  1950. dev->name, temp_ws_name);
  1951. if (privptr->system_validate_comp == 0)
  1952. claw_strt_conn_req(dev);
  1953. privptr->system_validate_comp = 1;
  1954. break;
  1955. case CLAW_RC_NAME_MISMATCH:
  1956. printk(KERN_INFO "%s: Sys Validate "
  1957. "Resp : Host, WS name is "
  1958. "mismatch\n",
  1959. dev->name);
  1960. break;
  1961. case CLAW_RC_WRONG_VERSION:
  1962. printk(KERN_INFO "%s: Sys Validate "
  1963. "Resp : Wrong version\n",
  1964. dev->name);
  1965. break;
  1966. case CLAW_RC_HOST_RCV_TOO_SMALL:
  1967. printk(KERN_INFO "%s: Sys Validate "
  1968. "Resp : bad frame size\n",
  1969. dev->name);
  1970. break;
  1971. default:
  1972. printk(KERN_INFO "%s: Sys Validate "
  1973. "error code=%d \n",
  1974. dev->name, p_ctlbk->rc);
  1975. break;
  1976. }
  1977. break;
  1978. case CONNECTION_REQUEST:
  1979. p_connect = (struct conncmd *)&(p_ctlbk->data);
  1980. printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
  1981. "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
  1982. dev->name,
  1983. p_ctlbk->version,
  1984. p_ctlbk->linkid,
  1985. p_ctlbk->correlator,
  1986. p_connect->host_name,
  1987. p_connect->WS_name);
  1988. if (privptr->active_link_ID != 0) {
  1989. claw_snd_disc(dev, p_ctlbk);
  1990. printk(KERN_INFO "%s: Conn Req error : "
  1991. "already logical link is active \n",
  1992. dev->name);
  1993. }
  1994. if (p_ctlbk->linkid != 1) {
  1995. claw_snd_disc(dev, p_ctlbk);
  1996. printk(KERN_INFO "%s: Conn Req error : "
  1997. "req logical link id is not 1\n",
  1998. dev->name);
  1999. }
  2000. rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
  2001. if (rc != 0) {
  2002. claw_snd_disc(dev, p_ctlbk);
  2003. printk(KERN_INFO "%s: Conn Resp error: "
  2004. "req appl name does not match\n",
  2005. dev->name);
  2006. }
  2007. claw_send_control(dev,
  2008. CONNECTION_CONFIRM, p_ctlbk->linkid,
  2009. p_ctlbk->correlator,
  2010. 0, p_connect->host_name,
  2011. p_connect->WS_name);
  2012. if (p_env->packing == PACKING_ASK) {
  2013. p_env->packing = PACK_SEND;
  2014. claw_snd_conn_req(dev, 0);
  2015. }
  2016. printk(KERN_INFO "%s: CLAW device %.8s: Connection "
  2017. "completed link_id=%d.\n",
  2018. dev->name, temp_ws_name,
  2019. p_ctlbk->linkid);
  2020. privptr->active_link_ID = p_ctlbk->linkid;
  2021. p_ch = &privptr->channel[WRITE];
  2022. wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
  2023. break;
  2024. case CONNECTION_RESPONSE:
  2025. p_connect = (struct conncmd *)&(p_ctlbk->data);
  2026. printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
  2027. "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
  2028. dev->name,
  2029. p_ctlbk->version,
  2030. p_ctlbk->linkid,
  2031. p_ctlbk->correlator,
  2032. p_ctlbk->rc,
  2033. p_connect->host_name,
  2034. p_connect->WS_name);
  2035. if (p_ctlbk->rc != 0) {
  2036. printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
  2037. dev->name, p_ctlbk->rc);
  2038. return 1;
  2039. }
  2040. rc = find_link(dev,
  2041. p_connect->host_name, p_connect->WS_name);
  2042. if (rc != 0) {
  2043. claw_snd_disc(dev, p_ctlbk);
  2044. printk(KERN_INFO "%s: Conn Resp error: "
  2045. "req appl name does not match\n",
  2046. dev->name);
  2047. }
  2048. /* should be until CONNECTION_CONFIRM */
  2049. privptr->active_link_ID = -(p_ctlbk->linkid);
  2050. break;
  2051. case CONNECTION_CONFIRM:
  2052. p_connect = (struct conncmd *)&(p_ctlbk->data);
  2053. printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
  2054. "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
  2055. dev->name,
  2056. p_ctlbk->version,
  2057. p_ctlbk->linkid,
  2058. p_ctlbk->correlator,
  2059. p_connect->host_name,
  2060. p_connect->WS_name);
  2061. if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
  2062. privptr->active_link_ID = p_ctlbk->linkid;
  2063. if (p_env->packing > PACKING_ASK) {
  2064. printk(KERN_INFO "%s: Confirmed Now packing\n",
  2065. dev->name);
  2066. p_env->packing = DO_PACKED;
  2067. }
  2068. p_ch = &privptr->channel[WRITE];
  2069. wake_up(&p_ch->wait);
  2070. } else {
  2071. printk(KERN_INFO "%s: Conn confirm: "
  2072. "unexpected linkid=%d \n",
  2073. dev->name, p_ctlbk->linkid);
  2074. claw_snd_disc(dev, p_ctlbk);
  2075. }
  2076. break;
  2077. case DISCONNECT:
  2078. printk(KERN_INFO "%s: Disconnect: "
  2079. "Vers=%d,link_id=%d,Corr=%d\n",
  2080. dev->name, p_ctlbk->version,
  2081. p_ctlbk->linkid, p_ctlbk->correlator);
  2082. if ((p_ctlbk->linkid == 2) &&
  2083. (p_env->packing == PACK_SEND)) {
  2084. privptr->active_link_ID = 1;
  2085. p_env->packing = DO_PACKED;
  2086. } else
  2087. privptr->active_link_ID = 0;
  2088. break;
  2089. case CLAW_ERROR:
  2090. printk(KERN_INFO "%s: CLAW ERROR detected\n",
  2091. dev->name);
  2092. break;
  2093. default:
  2094. printk(KERN_INFO "%s: Unexpected command code=%d \n",
  2095. dev->name, p_ctlbk->command);
  2096. break;
  2097. }
  2098. return 0;
  2099. } /* end of claw_process_control */
  2100. /*-------------------------------------------------------------------*
  2101. * claw_send_control *
  2102. * *
  2103. *--------------------------------------------------------------------*/
  2104. static int
  2105. claw_send_control(struct net_device *dev, __u8 type, __u8 link,
  2106. __u8 correlator, __u8 rc, char *local_name, char *remote_name)
  2107. {
  2108. struct claw_privbk *privptr;
  2109. struct clawctl *p_ctl;
  2110. struct sysval *p_sysval;
  2111. struct conncmd *p_connect;
  2112. struct sk_buff *skb;
  2113. CLAW_DBF_TEXT(2, setup, "sndcntl");
  2114. privptr = dev->ml_priv;
  2115. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2116. p_ctl->command=type;
  2117. p_ctl->version=CLAW_VERSION_ID;
  2118. p_ctl->linkid=link;
  2119. p_ctl->correlator=correlator;
  2120. p_ctl->rc=rc;
  2121. p_sysval=(struct sysval *)&p_ctl->data;
  2122. p_connect=(struct conncmd *)&p_ctl->data;
  2123. switch (p_ctl->command) {
  2124. case SYSTEM_VALIDATE_REQUEST:
  2125. case SYSTEM_VALIDATE_RESPONSE:
  2126. memcpy(&p_sysval->host_name, local_name, 8);
  2127. memcpy(&p_sysval->WS_name, remote_name, 8);
  2128. if (privptr->p_env->packing > 0) {
  2129. p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
  2130. p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
  2131. } else {
  2132. /* how big is the biggest group of packets */
  2133. p_sysval->read_frame_size=privptr->p_env->read_size;
  2134. p_sysval->write_frame_size=privptr->p_env->write_size;
  2135. }
  2136. memset(&p_sysval->reserved, 0x00, 4);
  2137. break;
  2138. case CONNECTION_REQUEST:
  2139. case CONNECTION_RESPONSE:
  2140. case CONNECTION_CONFIRM:
  2141. case DISCONNECT:
  2142. memcpy(&p_sysval->host_name, local_name, 8);
  2143. memcpy(&p_sysval->WS_name, remote_name, 8);
  2144. if (privptr->p_env->packing > 0) {
  2145. /* How big is the biggest packet */
  2146. p_connect->reserved1[0]=CLAW_FRAME_SIZE;
  2147. p_connect->reserved1[1]=CLAW_FRAME_SIZE;
  2148. } else {
  2149. memset(&p_connect->reserved1, 0x00, 4);
  2150. memset(&p_connect->reserved2, 0x00, 4);
  2151. }
  2152. break;
  2153. default:
  2154. break;
  2155. }
  2156. /* write Control Record to the device */
  2157. skb = dev_alloc_skb(sizeof(struct clawctl));
  2158. if (!skb) {
  2159. return -ENOMEM;
  2160. }
  2161. memcpy(skb_put(skb, sizeof(struct clawctl)),
  2162. p_ctl, sizeof(struct clawctl));
  2163. if (privptr->p_env->packing >= PACK_SEND)
  2164. claw_hw_tx(skb, dev, 1);
  2165. else
  2166. claw_hw_tx(skb, dev, 0);
  2167. return 0;
  2168. } /* end of claw_send_control */
  2169. /*-------------------------------------------------------------------*
  2170. * claw_snd_conn_req *
  2171. * *
  2172. *--------------------------------------------------------------------*/
  2173. static int
  2174. claw_snd_conn_req(struct net_device *dev, __u8 link)
  2175. {
  2176. int rc;
  2177. struct claw_privbk *privptr = dev->ml_priv;
  2178. struct clawctl *p_ctl;
  2179. CLAW_DBF_TEXT(2, setup, "snd_conn");
  2180. rc = 1;
  2181. p_ctl=(struct clawctl *)&privptr->ctl_bk;
  2182. p_ctl->linkid = link;
  2183. if ( privptr->system_validate_comp==0x00 ) {
  2184. return rc;
  2185. }
  2186. if (privptr->p_env->packing == PACKING_ASK )
  2187. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2188. WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
  2189. if (privptr->p_env->packing == PACK_SEND) {
  2190. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2191. WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
  2192. }
  2193. if (privptr->p_env->packing == 0)
  2194. rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
  2195. HOST_APPL_NAME, privptr->p_env->api_type);
  2196. return rc;
  2197. } /* end of claw_snd_conn_req */
  2198. /*-------------------------------------------------------------------*
  2199. * claw_snd_disc *
  2200. * *
  2201. *--------------------------------------------------------------------*/
  2202. static int
  2203. claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
  2204. {
  2205. int rc;
  2206. struct conncmd * p_connect;
  2207. CLAW_DBF_TEXT(2, setup, "snd_dsc");
  2208. p_connect=(struct conncmd *)&p_ctl->data;
  2209. rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
  2210. p_ctl->correlator, 0,
  2211. p_connect->host_name, p_connect->WS_name);
  2212. return rc;
  2213. } /* end of claw_snd_disc */
  2214. /*-------------------------------------------------------------------*
  2215. * claw_snd_sys_validate_rsp *
  2216. * *
  2217. *--------------------------------------------------------------------*/
  2218. static int
  2219. claw_snd_sys_validate_rsp(struct net_device *dev,
  2220. struct clawctl *p_ctl, __u32 return_code)
  2221. {
  2222. struct claw_env * p_env;
  2223. struct claw_privbk *privptr;
  2224. int rc;
  2225. CLAW_DBF_TEXT(2, setup, "chkresp");
  2226. privptr = dev->ml_priv;
  2227. p_env=privptr->p_env;
  2228. rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
  2229. p_ctl->linkid,
  2230. p_ctl->correlator,
  2231. return_code,
  2232. p_env->host_name,
  2233. p_env->adapter_name );
  2234. return rc;
  2235. } /* end of claw_snd_sys_validate_rsp */
  2236. /*-------------------------------------------------------------------*
  2237. * claw_strt_conn_req *
  2238. * *
  2239. *--------------------------------------------------------------------*/
  2240. static int
  2241. claw_strt_conn_req(struct net_device *dev )
  2242. {
  2243. int rc;
  2244. CLAW_DBF_TEXT(2, setup, "conn_req");
  2245. rc=claw_snd_conn_req(dev, 1);
  2246. return rc;
  2247. } /* end of claw_strt_conn_req */
  2248. /*-------------------------------------------------------------------*
  2249. * claw_stats *
  2250. *-------------------------------------------------------------------*/
  2251. static struct
  2252. net_device_stats *claw_stats(struct net_device *dev)
  2253. {
  2254. struct claw_privbk *privptr;
  2255. CLAW_DBF_TEXT(4, trace, "stats");
  2256. privptr = dev->ml_priv;
  2257. return &privptr->stats;
  2258. } /* end of claw_stats */
  2259. /*-------------------------------------------------------------------*
  2260. * unpack_read *
  2261. * *
  2262. *--------------------------------------------------------------------*/
  2263. static void
  2264. unpack_read(struct net_device *dev )
  2265. {
  2266. struct sk_buff *skb;
  2267. struct claw_privbk *privptr;
  2268. struct claw_env *p_env;
  2269. struct ccwbk *p_this_ccw;
  2270. struct ccwbk *p_first_ccw;
  2271. struct ccwbk *p_last_ccw;
  2272. struct clawph *p_packh;
  2273. void *p_packd;
  2274. struct clawctl *p_ctlrec=NULL;
  2275. struct device *p_dev;
  2276. __u32 len_of_data;
  2277. __u32 pack_off;
  2278. __u8 link_num;
  2279. __u8 mtc_this_frm=0;
  2280. __u32 bytes_to_mov;
  2281. int i=0;
  2282. int p=0;
  2283. CLAW_DBF_TEXT(4, trace, "unpkread");
  2284. p_first_ccw=NULL;
  2285. p_last_ccw=NULL;
  2286. p_packh=NULL;
  2287. p_packd=NULL;
  2288. privptr = dev->ml_priv;
  2289. p_dev = &privptr->channel[READ].cdev->dev;
  2290. p_env = privptr->p_env;
  2291. p_this_ccw=privptr->p_read_active_first;
  2292. i=0;
  2293. while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
  2294. pack_off = 0;
  2295. p = 0;
  2296. p_this_ccw->header.flag=CLAW_PENDING;
  2297. privptr->p_read_active_first=p_this_ccw->next;
  2298. p_this_ccw->next=NULL;
  2299. p_packh = (struct clawph *)p_this_ccw->p_buffer;
  2300. if ((p_env->packing == PACK_SEND) &&
  2301. (p_packh->len == 32) &&
  2302. (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
  2303. p_packh++; /* peek past pack header */
  2304. p_ctlrec = (struct clawctl *)p_packh;
  2305. p_packh--; /* un peek */
  2306. if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
  2307. (p_ctlrec->command == CONNECTION_CONFIRM))
  2308. p_env->packing = DO_PACKED;
  2309. }
  2310. if (p_env->packing == DO_PACKED)
  2311. link_num=p_packh->link_num;
  2312. else
  2313. link_num=p_this_ccw->header.opcode / 8;
  2314. if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
  2315. mtc_this_frm=1;
  2316. if (p_this_ccw->header.length!=
  2317. privptr->p_env->read_size ) {
  2318. printk(KERN_INFO " %s: Invalid frame detected "
  2319. "length is %02x\n" ,
  2320. dev->name, p_this_ccw->header.length);
  2321. }
  2322. }
  2323. if (privptr->mtc_skipping) {
  2324. /*
  2325. * We're in the mode of skipping past a
  2326. * multi-frame message
  2327. * that we can't process for some reason or other.
  2328. * The first frame without the More-To-Come flag is
  2329. * the last frame of the skipped message.
  2330. */
  2331. /* in case of More-To-Come not set in this frame */
  2332. if (mtc_this_frm==0) {
  2333. privptr->mtc_skipping=0; /* Ok, the end */
  2334. privptr->mtc_logical_link=-1;
  2335. }
  2336. goto NextFrame;
  2337. }
  2338. if (link_num==0) {
  2339. claw_process_control(dev, p_this_ccw);
  2340. CLAW_DBF_TEXT(4, trace, "UnpkCntl");
  2341. goto NextFrame;
  2342. }
  2343. unpack_next:
  2344. if (p_env->packing == DO_PACKED) {
  2345. if (pack_off > p_env->read_size)
  2346. goto NextFrame;
  2347. p_packd = p_this_ccw->p_buffer+pack_off;
  2348. p_packh = (struct clawph *) p_packd;
  2349. if ((p_packh->len == 0) || /* all done with this frame? */
  2350. (p_packh->flag != 0))
  2351. goto NextFrame;
  2352. bytes_to_mov = p_packh->len;
  2353. pack_off += bytes_to_mov+sizeof(struct clawph);
  2354. p++;
  2355. } else {
  2356. bytes_to_mov=p_this_ccw->header.length;
  2357. }
  2358. if (privptr->mtc_logical_link<0) {
  2359. /*
  2360. * if More-To-Come is set in this frame then we don't know
  2361. * length of entire message, and hence have to allocate
  2362. * large buffer */
  2363. /* We are starting a new envelope */
  2364. privptr->mtc_offset=0;
  2365. privptr->mtc_logical_link=link_num;
  2366. }
  2367. if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
  2368. /* error */
  2369. privptr->stats.rx_frame_errors++;
  2370. goto NextFrame;
  2371. }
  2372. if (p_env->packing == DO_PACKED) {
  2373. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  2374. p_packd+sizeof(struct clawph), bytes_to_mov);
  2375. } else {
  2376. memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
  2377. p_this_ccw->p_buffer, bytes_to_mov);
  2378. }
  2379. if (mtc_this_frm==0) {
  2380. len_of_data=privptr->mtc_offset+bytes_to_mov;
  2381. skb=dev_alloc_skb(len_of_data);
  2382. if (skb) {
  2383. memcpy(skb_put(skb,len_of_data),
  2384. privptr->p_mtc_envelope,
  2385. len_of_data);
  2386. skb->dev=dev;
  2387. skb_reset_mac_header(skb);
  2388. skb->protocol=htons(ETH_P_IP);
  2389. skb->ip_summed=CHECKSUM_UNNECESSARY;
  2390. privptr->stats.rx_packets++;
  2391. privptr->stats.rx_bytes+=len_of_data;
  2392. netif_rx(skb);
  2393. }
  2394. else {
  2395. privptr->stats.rx_dropped++;
  2396. printk(KERN_WARNING "%s: %s() low on memory\n",
  2397. dev->name,__func__);
  2398. }
  2399. privptr->mtc_offset=0;
  2400. privptr->mtc_logical_link=-1;
  2401. }
  2402. else {
  2403. privptr->mtc_offset+=bytes_to_mov;
  2404. }
  2405. if (p_env->packing == DO_PACKED)
  2406. goto unpack_next;
  2407. NextFrame:
  2408. /*
  2409. * Remove ThisCCWblock from active read queue, and add it
  2410. * to queue of free blocks to be reused.
  2411. */
  2412. i++;
  2413. p_this_ccw->header.length=0xffff;
  2414. p_this_ccw->header.opcode=0xff;
  2415. /*
  2416. * add this one to the free queue for later reuse
  2417. */
  2418. if (p_first_ccw==NULL) {
  2419. p_first_ccw = p_this_ccw;
  2420. }
  2421. else {
  2422. p_last_ccw->next = p_this_ccw;
  2423. }
  2424. p_last_ccw = p_this_ccw;
  2425. /*
  2426. * chain to next block on active read queue
  2427. */
  2428. p_this_ccw = privptr->p_read_active_first;
  2429. CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
  2430. } /* end of while */
  2431. /* check validity */
  2432. CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
  2433. add_claw_reads(dev, p_first_ccw, p_last_ccw);
  2434. claw_strt_read(dev, LOCK_YES);
  2435. return;
  2436. } /* end of unpack_read */
  2437. /*-------------------------------------------------------------------*
  2438. * claw_strt_read *
  2439. * *
  2440. *--------------------------------------------------------------------*/
  2441. static void
  2442. claw_strt_read (struct net_device *dev, int lock )
  2443. {
  2444. int rc = 0;
  2445. __u32 parm;
  2446. unsigned long saveflags = 0;
  2447. struct claw_privbk *privptr = dev->ml_priv;
  2448. struct ccwbk*p_ccwbk;
  2449. struct chbk *p_ch;
  2450. struct clawh *p_clawh;
  2451. p_ch=&privptr->channel[READ];
  2452. CLAW_DBF_TEXT(4, trace, "StRdNter");
  2453. p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
  2454. p_clawh->flag=CLAW_IDLE; /* 0x00 */
  2455. if ((privptr->p_write_active_first!=NULL &&
  2456. privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
  2457. (privptr->p_read_active_first!=NULL &&
  2458. privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
  2459. p_clawh->flag=CLAW_BUSY; /* 0xff */
  2460. }
  2461. if (lock==LOCK_YES) {
  2462. spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
  2463. }
  2464. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  2465. CLAW_DBF_TEXT(4, trace, "HotRead");
  2466. p_ccwbk=privptr->p_read_active_first;
  2467. parm = (unsigned long) p_ch;
  2468. rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
  2469. 0xff, 0);
  2470. if (rc != 0) {
  2471. ccw_check_return_code(p_ch->cdev, rc);
  2472. }
  2473. }
  2474. else {
  2475. CLAW_DBF_TEXT(2, trace, "ReadAct");
  2476. }
  2477. if (lock==LOCK_YES) {
  2478. spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
  2479. }
  2480. CLAW_DBF_TEXT(4, trace, "StRdExit");
  2481. return;
  2482. } /* end of claw_strt_read */
  2483. /*-------------------------------------------------------------------*
  2484. * claw_strt_out_IO *
  2485. * *
  2486. *--------------------------------------------------------------------*/
  2487. static void
  2488. claw_strt_out_IO( struct net_device *dev )
  2489. {
  2490. int rc = 0;
  2491. unsigned long parm;
  2492. struct claw_privbk *privptr;
  2493. struct chbk *p_ch;
  2494. struct ccwbk *p_first_ccw;
  2495. if (!dev) {
  2496. return;
  2497. }
  2498. privptr = (struct claw_privbk *)dev->ml_priv;
  2499. p_ch=&privptr->channel[WRITE];
  2500. CLAW_DBF_TEXT(4, trace, "strt_io");
  2501. p_first_ccw=privptr->p_write_active_first;
  2502. if (p_ch->claw_state == CLAW_STOP)
  2503. return;
  2504. if (p_first_ccw == NULL) {
  2505. return;
  2506. }
  2507. if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
  2508. parm = (unsigned long) p_ch;
  2509. CLAW_DBF_TEXT(2, trace, "StWrtIO");
  2510. rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
  2511. 0xff, 0);
  2512. if (rc != 0) {
  2513. ccw_check_return_code(p_ch->cdev, rc);
  2514. }
  2515. }
  2516. dev->trans_start = jiffies;
  2517. return;
  2518. } /* end of claw_strt_out_IO */
  2519. /*-------------------------------------------------------------------*
  2520. * Free write buffers *
  2521. * *
  2522. *--------------------------------------------------------------------*/
  2523. static void
  2524. claw_free_wrt_buf( struct net_device *dev )
  2525. {
  2526. struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
  2527. struct ccwbk*p_first_ccw;
  2528. struct ccwbk*p_last_ccw;
  2529. struct ccwbk*p_this_ccw;
  2530. struct ccwbk*p_next_ccw;
  2531. CLAW_DBF_TEXT(4, trace, "freewrtb");
  2532. /* scan the write queue to free any completed write packets */
  2533. p_first_ccw=NULL;
  2534. p_last_ccw=NULL;
  2535. p_this_ccw=privptr->p_write_active_first;
  2536. while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
  2537. {
  2538. p_next_ccw = p_this_ccw->next;
  2539. if (((p_next_ccw!=NULL) &&
  2540. (p_next_ccw->header.flag!=CLAW_PENDING)) ||
  2541. ((p_this_ccw == privptr->p_write_active_last) &&
  2542. (p_this_ccw->header.flag!=CLAW_PENDING))) {
  2543. /* The next CCW is OK or this is */
  2544. /* the last CCW...free it @A1A */
  2545. privptr->p_write_active_first=p_this_ccw->next;
  2546. p_this_ccw->header.flag=CLAW_PENDING;
  2547. p_this_ccw->next=privptr->p_write_free_chain;
  2548. privptr->p_write_free_chain=p_this_ccw;
  2549. ++privptr->write_free_count;
  2550. privptr->stats.tx_bytes+= p_this_ccw->write.count;
  2551. p_this_ccw=privptr->p_write_active_first;
  2552. privptr->stats.tx_packets++;
  2553. }
  2554. else {
  2555. break;
  2556. }
  2557. }
  2558. if (privptr->write_free_count!=0) {
  2559. claw_clearbit_busy(TB_NOBUFFER,dev);
  2560. }
  2561. /* whole chain removed? */
  2562. if (privptr->p_write_active_first==NULL) {
  2563. privptr->p_write_active_last=NULL;
  2564. }
  2565. CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
  2566. return;
  2567. }
  2568. /*-------------------------------------------------------------------*
  2569. * claw free netdevice *
  2570. * *
  2571. *--------------------------------------------------------------------*/
  2572. static void
  2573. claw_free_netdevice(struct net_device * dev, int free_dev)
  2574. {
  2575. struct claw_privbk *privptr;
  2576. CLAW_DBF_TEXT(2, setup, "free_dev");
  2577. if (!dev)
  2578. return;
  2579. CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
  2580. privptr = dev->ml_priv;
  2581. if (dev->flags & IFF_RUNNING)
  2582. claw_release(dev);
  2583. if (privptr) {
  2584. privptr->channel[READ].ndev = NULL; /* say it's free */
  2585. }
  2586. dev->ml_priv = NULL;
  2587. #ifdef MODULE
  2588. if (free_dev) {
  2589. free_netdev(dev);
  2590. }
  2591. #endif
  2592. CLAW_DBF_TEXT(2, setup, "free_ok");
  2593. }
  2594. /**
  2595. * Claw init netdevice
  2596. * Initialize everything of the net device except the name and the
  2597. * channel structs.
  2598. */
  2599. static void
  2600. claw_init_netdevice(struct net_device * dev)
  2601. {
  2602. CLAW_DBF_TEXT(2, setup, "init_dev");
  2603. CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
  2604. dev->mtu = CLAW_DEFAULT_MTU_SIZE;
  2605. dev->hard_start_xmit = claw_tx;
  2606. dev->open = claw_open;
  2607. dev->stop = claw_release;
  2608. dev->get_stats = claw_stats;
  2609. dev->change_mtu = claw_change_mtu;
  2610. dev->hard_header_len = 0;
  2611. dev->addr_len = 0;
  2612. dev->type = ARPHRD_SLIP;
  2613. dev->tx_queue_len = 1300;
  2614. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  2615. CLAW_DBF_TEXT(2, setup, "initok");
  2616. return;
  2617. }
  2618. /**
  2619. * Init a new channel in the privptr->channel[i].
  2620. *
  2621. * @param cdev The ccw_device to be added.
  2622. *
  2623. * @return 0 on success, !0 on error.
  2624. */
  2625. static int
  2626. add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
  2627. {
  2628. struct chbk *p_ch;
  2629. struct ccw_dev_id dev_id;
  2630. CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
  2631. privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
  2632. p_ch = &privptr->channel[i];
  2633. p_ch->cdev = cdev;
  2634. snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
  2635. ccw_device_get_id(cdev, &dev_id);
  2636. p_ch->devno = dev_id.devno;
  2637. if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
  2638. return -ENOMEM;
  2639. }
  2640. return 0;
  2641. }
  2642. /**
  2643. *
  2644. * Setup an interface.
  2645. *
  2646. * @param cgdev Device to be setup.
  2647. *
  2648. * @returns 0 on success, !0 on failure.
  2649. */
  2650. static int
  2651. claw_new_device(struct ccwgroup_device *cgdev)
  2652. {
  2653. struct claw_privbk *privptr;
  2654. struct claw_env *p_env;
  2655. struct net_device *dev;
  2656. int ret;
  2657. struct ccw_dev_id dev_id;
  2658. printk(KERN_INFO "claw: add for %s\n",
  2659. dev_name(&cgdev->cdev[READ]->dev));
  2660. CLAW_DBF_TEXT(2, setup, "new_dev");
  2661. privptr = cgdev->dev.driver_data;
  2662. cgdev->cdev[READ]->dev.driver_data = privptr;
  2663. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  2664. if (!privptr)
  2665. return -ENODEV;
  2666. p_env = privptr->p_env;
  2667. ccw_device_get_id(cgdev->cdev[READ], &dev_id);
  2668. p_env->devno[READ] = dev_id.devno;
  2669. ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
  2670. p_env->devno[WRITE] = dev_id.devno;
  2671. ret = add_channel(cgdev->cdev[0],0,privptr);
  2672. if (ret == 0)
  2673. ret = add_channel(cgdev->cdev[1],1,privptr);
  2674. if (ret != 0) {
  2675. printk(KERN_WARNING
  2676. "add channel failed with ret = %d\n", ret);
  2677. goto out;
  2678. }
  2679. ret = ccw_device_set_online(cgdev->cdev[READ]);
  2680. if (ret != 0) {
  2681. printk(KERN_WARNING
  2682. "claw: ccw_device_set_online %s READ failed "
  2683. "with ret = %d\n", dev_name(&cgdev->cdev[READ]->dev),
  2684. ret);
  2685. goto out;
  2686. }
  2687. ret = ccw_device_set_online(cgdev->cdev[WRITE]);
  2688. if (ret != 0) {
  2689. printk(KERN_WARNING
  2690. "claw: ccw_device_set_online %s WRITE failed "
  2691. "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev),
  2692. ret);
  2693. goto out;
  2694. }
  2695. dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
  2696. if (!dev) {
  2697. printk(KERN_WARNING "%s:alloc_netdev failed\n",__func__);
  2698. goto out;
  2699. }
  2700. dev->ml_priv = privptr;
  2701. cgdev->dev.driver_data = privptr;
  2702. cgdev->cdev[READ]->dev.driver_data = privptr;
  2703. cgdev->cdev[WRITE]->dev.driver_data = privptr;
  2704. /* sysfs magic */
  2705. SET_NETDEV_DEV(dev, &cgdev->dev);
  2706. if (register_netdev(dev) != 0) {
  2707. claw_free_netdevice(dev, 1);
  2708. CLAW_DBF_TEXT(2, trace, "regfail");
  2709. goto out;
  2710. }
  2711. dev->flags &=~IFF_RUNNING;
  2712. if (privptr->buffs_alloc == 0) {
  2713. ret=init_ccw_bk(dev);
  2714. if (ret !=0) {
  2715. unregister_netdev(dev);
  2716. claw_free_netdevice(dev,1);
  2717. CLAW_DBF_TEXT(2, trace, "ccwmem");
  2718. goto out;
  2719. }
  2720. }
  2721. privptr->channel[READ].ndev = dev;
  2722. privptr->channel[WRITE].ndev = dev;
  2723. privptr->p_env->ndev = dev;
  2724. printk(KERN_INFO "%s:readsize=%d writesize=%d "
  2725. "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
  2726. dev->name, p_env->read_size,
  2727. p_env->write_size, p_env->read_buffers,
  2728. p_env->write_buffers, p_env->devno[READ],
  2729. p_env->devno[WRITE]);
  2730. printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
  2731. ":%.8s api_type: %.8s\n",
  2732. dev->name, p_env->host_name,
  2733. p_env->adapter_name , p_env->api_type);
  2734. return 0;
  2735. out:
  2736. ccw_device_set_offline(cgdev->cdev[1]);
  2737. ccw_device_set_offline(cgdev->cdev[0]);
  2738. return -ENODEV;
  2739. }
  2740. static void
  2741. claw_purge_skb_queue(struct sk_buff_head *q)
  2742. {
  2743. struct sk_buff *skb;
  2744. CLAW_DBF_TEXT(4, trace, "purgque");
  2745. while ((skb = skb_dequeue(q))) {
  2746. atomic_dec(&skb->users);
  2747. dev_kfree_skb_any(skb);
  2748. }
  2749. }
  2750. /**
  2751. * Shutdown an interface.
  2752. *
  2753. * @param cgdev Device to be shut down.
  2754. *
  2755. * @returns 0 on success, !0 on failure.
  2756. */
  2757. static int
  2758. claw_shutdown_device(struct ccwgroup_device *cgdev)
  2759. {
  2760. struct claw_privbk *priv;
  2761. struct net_device *ndev;
  2762. int ret;
  2763. CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
  2764. priv = cgdev->dev.driver_data;
  2765. if (!priv)
  2766. return -ENODEV;
  2767. ndev = priv->channel[READ].ndev;
  2768. if (ndev) {
  2769. /* Close the device */
  2770. printk(KERN_INFO
  2771. "%s: shuting down \n",ndev->name);
  2772. if (ndev->flags & IFF_RUNNING)
  2773. ret = claw_release(ndev);
  2774. ndev->flags &=~IFF_RUNNING;
  2775. unregister_netdev(ndev);
  2776. ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
  2777. claw_free_netdevice(ndev, 1);
  2778. priv->channel[READ].ndev = NULL;
  2779. priv->channel[WRITE].ndev = NULL;
  2780. priv->p_env->ndev = NULL;
  2781. }
  2782. ccw_device_set_offline(cgdev->cdev[1]);
  2783. ccw_device_set_offline(cgdev->cdev[0]);
  2784. return 0;
  2785. }
  2786. static void
  2787. claw_remove_device(struct ccwgroup_device *cgdev)
  2788. {
  2789. struct claw_privbk *priv;
  2790. BUG_ON(!cgdev);
  2791. CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
  2792. priv = cgdev->dev.driver_data;
  2793. BUG_ON(!priv);
  2794. printk(KERN_INFO "claw: %s() called %s will be removed.\n",
  2795. __func__, dev_name(&cgdev->cdev[0]->dev));
  2796. if (cgdev->state == CCWGROUP_ONLINE)
  2797. claw_shutdown_device(cgdev);
  2798. claw_remove_files(&cgdev->dev);
  2799. kfree(priv->p_mtc_envelope);
  2800. priv->p_mtc_envelope=NULL;
  2801. kfree(priv->p_env);
  2802. priv->p_env=NULL;
  2803. kfree(priv->channel[0].irb);
  2804. priv->channel[0].irb=NULL;
  2805. kfree(priv->channel[1].irb);
  2806. priv->channel[1].irb=NULL;
  2807. kfree(priv);
  2808. cgdev->dev.driver_data=NULL;
  2809. cgdev->cdev[READ]->dev.driver_data = NULL;
  2810. cgdev->cdev[WRITE]->dev.driver_data = NULL;
  2811. put_device(&cgdev->dev);
  2812. return;
  2813. }
  2814. /*
  2815. * sysfs attributes
  2816. */
  2817. static ssize_t
  2818. claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2819. {
  2820. struct claw_privbk *priv;
  2821. struct claw_env * p_env;
  2822. priv = dev->driver_data;
  2823. if (!priv)
  2824. return -ENODEV;
  2825. p_env = priv->p_env;
  2826. return sprintf(buf, "%s\n",p_env->host_name);
  2827. }
  2828. static ssize_t
  2829. claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2830. {
  2831. struct claw_privbk *priv;
  2832. struct claw_env * p_env;
  2833. priv = dev->driver_data;
  2834. if (!priv)
  2835. return -ENODEV;
  2836. p_env = priv->p_env;
  2837. if (count > MAX_NAME_LEN+1)
  2838. return -EINVAL;
  2839. memset(p_env->host_name, 0x20, MAX_NAME_LEN);
  2840. strncpy(p_env->host_name,buf, count);
  2841. p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
  2842. p_env->host_name[MAX_NAME_LEN] = 0x00;
  2843. CLAW_DBF_TEXT(2, setup, "HstnSet");
  2844. CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
  2845. return count;
  2846. }
  2847. static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
  2848. static ssize_t
  2849. claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2850. {
  2851. struct claw_privbk *priv;
  2852. struct claw_env * p_env;
  2853. priv = dev->driver_data;
  2854. if (!priv)
  2855. return -ENODEV;
  2856. p_env = priv->p_env;
  2857. return sprintf(buf, "%s\n", p_env->adapter_name);
  2858. }
  2859. static ssize_t
  2860. claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2861. {
  2862. struct claw_privbk *priv;
  2863. struct claw_env * p_env;
  2864. priv = dev->driver_data;
  2865. if (!priv)
  2866. return -ENODEV;
  2867. p_env = priv->p_env;
  2868. if (count > MAX_NAME_LEN+1)
  2869. return -EINVAL;
  2870. memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
  2871. strncpy(p_env->adapter_name,buf, count);
  2872. p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
  2873. p_env->adapter_name[MAX_NAME_LEN] = 0x00;
  2874. CLAW_DBF_TEXT(2, setup, "AdnSet");
  2875. CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
  2876. return count;
  2877. }
  2878. static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
  2879. static ssize_t
  2880. claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
  2881. {
  2882. struct claw_privbk *priv;
  2883. struct claw_env * p_env;
  2884. priv = dev->driver_data;
  2885. if (!priv)
  2886. return -ENODEV;
  2887. p_env = priv->p_env;
  2888. return sprintf(buf, "%s\n",
  2889. p_env->api_type);
  2890. }
  2891. static ssize_t
  2892. claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2893. {
  2894. struct claw_privbk *priv;
  2895. struct claw_env * p_env;
  2896. priv = dev->driver_data;
  2897. if (!priv)
  2898. return -ENODEV;
  2899. p_env = priv->p_env;
  2900. if (count > MAX_NAME_LEN+1)
  2901. return -EINVAL;
  2902. memset(p_env->api_type, 0x20, MAX_NAME_LEN);
  2903. strncpy(p_env->api_type,buf, count);
  2904. p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
  2905. p_env->api_type[MAX_NAME_LEN] = 0x00;
  2906. if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
  2907. p_env->read_size=DEF_PACK_BUFSIZE;
  2908. p_env->write_size=DEF_PACK_BUFSIZE;
  2909. p_env->packing=PACKING_ASK;
  2910. CLAW_DBF_TEXT(2, setup, "PACKING");
  2911. }
  2912. else {
  2913. p_env->packing=0;
  2914. p_env->read_size=CLAW_FRAME_SIZE;
  2915. p_env->write_size=CLAW_FRAME_SIZE;
  2916. CLAW_DBF_TEXT(2, setup, "ApiSet");
  2917. }
  2918. CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
  2919. return count;
  2920. }
  2921. static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
  2922. static ssize_t
  2923. claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  2924. {
  2925. struct claw_privbk *priv;
  2926. struct claw_env * p_env;
  2927. priv = dev->driver_data;
  2928. if (!priv)
  2929. return -ENODEV;
  2930. p_env = priv->p_env;
  2931. return sprintf(buf, "%d\n", p_env->write_buffers);
  2932. }
  2933. static ssize_t
  2934. claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2935. {
  2936. struct claw_privbk *priv;
  2937. struct claw_env * p_env;
  2938. int nnn,max;
  2939. priv = dev->driver_data;
  2940. if (!priv)
  2941. return -ENODEV;
  2942. p_env = priv->p_env;
  2943. sscanf(buf, "%i", &nnn);
  2944. if (p_env->packing) {
  2945. max = 64;
  2946. }
  2947. else {
  2948. max = 512;
  2949. }
  2950. if ((nnn > max ) || (nnn < 2))
  2951. return -EINVAL;
  2952. p_env->write_buffers = nnn;
  2953. CLAW_DBF_TEXT(2, setup, "Wbufset");
  2954. CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
  2955. return count;
  2956. }
  2957. static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
  2958. static ssize_t
  2959. claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
  2960. {
  2961. struct claw_privbk *priv;
  2962. struct claw_env * p_env;
  2963. priv = dev->driver_data;
  2964. if (!priv)
  2965. return -ENODEV;
  2966. p_env = priv->p_env;
  2967. return sprintf(buf, "%d\n", p_env->read_buffers);
  2968. }
  2969. static ssize_t
  2970. claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2971. {
  2972. struct claw_privbk *priv;
  2973. struct claw_env *p_env;
  2974. int nnn,max;
  2975. priv = dev->driver_data;
  2976. if (!priv)
  2977. return -ENODEV;
  2978. p_env = priv->p_env;
  2979. sscanf(buf, "%i", &nnn);
  2980. if (p_env->packing) {
  2981. max = 64;
  2982. }
  2983. else {
  2984. max = 512;
  2985. }
  2986. if ((nnn > max ) || (nnn < 2))
  2987. return -EINVAL;
  2988. p_env->read_buffers = nnn;
  2989. CLAW_DBF_TEXT(2, setup, "Rbufset");
  2990. CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
  2991. return count;
  2992. }
  2993. static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
  2994. static struct attribute *claw_attr[] = {
  2995. &dev_attr_read_buffer.attr,
  2996. &dev_attr_write_buffer.attr,
  2997. &dev_attr_adapter_name.attr,
  2998. &dev_attr_api_type.attr,
  2999. &dev_attr_host_name.attr,
  3000. NULL,
  3001. };
  3002. static struct attribute_group claw_attr_group = {
  3003. .attrs = claw_attr,
  3004. };
  3005. static int
  3006. claw_add_files(struct device *dev)
  3007. {
  3008. CLAW_DBF_TEXT(2, setup, "add_file");
  3009. return sysfs_create_group(&dev->kobj, &claw_attr_group);
  3010. }
  3011. static void
  3012. claw_remove_files(struct device *dev)
  3013. {
  3014. CLAW_DBF_TEXT(2, setup, "rem_file");
  3015. sysfs_remove_group(&dev->kobj, &claw_attr_group);
  3016. }
  3017. /*--------------------------------------------------------------------*
  3018. * claw_init and cleanup *
  3019. *---------------------------------------------------------------------*/
  3020. static void __exit
  3021. claw_cleanup(void)
  3022. {
  3023. unregister_cu3088_discipline(&claw_group_driver);
  3024. claw_unregister_debug_facility();
  3025. printk(KERN_INFO "claw: Driver unloaded\n");
  3026. }
  3027. /**
  3028. * Initialize module.
  3029. * This is called just after the module is loaded.
  3030. *
  3031. * @return 0 on success, !0 on error.
  3032. */
  3033. static int __init
  3034. claw_init(void)
  3035. {
  3036. int ret = 0;
  3037. printk(KERN_INFO "claw: starting driver\n");
  3038. ret = claw_register_debug_facility();
  3039. if (ret) {
  3040. printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
  3041. __func__,ret);
  3042. return ret;
  3043. }
  3044. CLAW_DBF_TEXT(2, setup, "init_mod");
  3045. ret = register_cu3088_discipline(&claw_group_driver);
  3046. if (ret) {
  3047. CLAW_DBF_TEXT(2, setup, "init_bad");
  3048. claw_unregister_debug_facility();
  3049. printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
  3050. __func__,ret);
  3051. }
  3052. return ret;
  3053. }
  3054. module_init(claw_init);
  3055. module_exit(claw_cleanup);
  3056. MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
  3057. MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
  3058. "Copyright 2000,2008 IBM Corporation\n");
  3059. MODULE_LICENSE("GPL");