claw.c 113 KB

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