claw.c 115 KB

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